diff --git a/index.html b/index.html
index 62f213c..4d206d9 100644
--- a/index.html
+++ b/index.html
@@ -244,6 +244,7 @@
@@ -439,6 +440,7 @@
Report an Issue
+
diff --git a/main.js b/main.js
index 5e1d9ff..de16571 100644
--- a/main.js
+++ b/main.js
@@ -191,6 +191,7 @@ let config = {
contentWidth: 900,
contentPadding: 20,
editorMonospace: false, // Use monospace font in editor
+ editorEngine: 'milkdown', // 'milkdown' or 'easymde' - WYSIWYG editor engine
compactTables: false, // Compact table cells (nowrap + horizontal scroll)
restoreSession: true, // Whether to restore previous session on launch
session: null, // Saved session state: { windows: [{ tabs: [{filePath, fileName}], directory: dirPath }] }
@@ -896,6 +897,7 @@ function createWindow(filePath = null) {
win.webContents.send('setting-changed', { setting: 'content-width', value: config.contentWidth });
win.webContents.send('setting-changed', { setting: 'content-padding', value: config.contentPadding });
win.webContents.send('setting-changed', { setting: 'editor-monospace', value: config.editorMonospace || false });
+ win.webContents.send('setting-changed', { setting: 'editor-engine', value: config.editorEngine || 'milkdown' });
win.webContents.send('setting-changed', { setting: 'compact-tables', value: config.compactTables || false });
win.webContents.send('setting-changed', { key: 'noos-widget', value: config.noosWidget === true });
@@ -1465,6 +1467,33 @@ function setupMenu() {
broadcastSetting('editor-monospace', menuItem.checked);
}
},
+ {
+ label: 'Rich Editor Engine',
+ submenu: [
+ {
+ label: 'Milkdown (WYSIWYG)',
+ type: 'radio',
+ id: 'editor-milkdown',
+ checked: (config.editorEngine || 'milkdown') === 'milkdown',
+ click: () => {
+ config.editorEngine = 'milkdown';
+ saveConfig();
+ broadcastSetting('editor-engine', 'milkdown');
+ }
+ },
+ {
+ label: 'EasyMDE (Markdown Preview)',
+ type: 'radio',
+ id: 'editor-easymde',
+ checked: config.editorEngine === 'easymde',
+ click: () => {
+ config.editorEngine = 'easymde';
+ saveConfig();
+ broadcastSetting('editor-engine', 'easymde');
+ }
+ }
+ ]
+ },
{
label: 'Compact Tables',
type: 'checkbox',
diff --git a/milkdown-bundle.js b/milkdown-bundle.js
new file mode 100644
index 0000000..6eeaaab
--- /dev/null
+++ b/milkdown-bundle.js
@@ -0,0 +1,59 @@
+var Milkdown=(()=>{var nm=Object.create;var Bi=Object.defineProperty;var rm=Object.getOwnPropertyDescriptor;var im=Object.getOwnPropertyNames;var om=Object.getPrototypeOf,sm=Object.prototype.hasOwnProperty;var lm=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Vu=(n,e)=>{for(var t in e)Bi(n,t,{get:e[t],enumerable:!0})},$u=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of im(e))!sm.call(n,i)&&i!==t&&Bi(n,i,{get:()=>e[i],enumerable:!(r=rm(e,i))||r.enumerable});return n};var am=(n,e,t)=>(t=n!=null?nm(om(n)):{},$u(e||!n||!n.__esModule?Bi(t,"default",{value:n,enumerable:!0}):t,n)),um=n=>$u(Bi({},"__esModule",{value:!0}),n);var mh=lm((hN,dh)=>{"use strict";var wo=Object.prototype.hasOwnProperty,ph=Object.prototype.toString,lh=Object.defineProperty,ah=Object.getOwnPropertyDescriptor,uh=function(e){return typeof Array.isArray=="function"?Array.isArray(e):ph.call(e)==="[object Array]"},ch=function(e){if(!e||ph.call(e)!=="[object Object]")return!1;var t=wo.call(e,"constructor"),r=e.constructor&&e.constructor.prototype&&wo.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!t&&!r)return!1;var i;for(i in e);return typeof i>"u"||wo.call(e,i)},fh=function(e,t){lh&&t.name==="__proto__"?lh(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},hh=function(e,t){if(t==="__proto__")if(wo.call(e,t)){if(ah)return ah(e,t).value}else return;return e[t]};dh.exports=function n(){var e,t,r,i,o,s,l=arguments[0],a=1,u=arguments.length,c=!1;for(typeof l=="boolean"&&(c=l,l=arguments[1]||{},a=2),(l==null||typeof l!="object"&&typeof l!="function")&&(l={});a
mi,callCommand:()=>ld,commonmark:()=>Oi,createMilkdownEditor:()=>J1,defaultValueCtx:()=>ar,editorViewCtx:()=>Ee,getMilkdownContent:()=>U1,history:()=>Ru,insertHrCommand:()=>ks,insertImageCommand:()=>xs,listener:()=>Ns,listenerCtx:()=>vi,redoCommand:()=>Ai,rootCtx:()=>ur,setMilkdownContent:()=>G1,toggleEmphasisCommand:()=>yi,toggleInlineCodeCommand:()=>bi,toggleStrongCommand:()=>ki,turnIntoTextCommand:()=>Si,undoCommand:()=>Ei,wrapInBlockquoteCommand:()=>Ci,wrapInBulletListCommand:()=>Ni,wrapInHeadingCommand:()=>ot,wrapInOrderedListCommand:()=>Ti});var Pe=(n=>(n.docTypeError="docTypeError",n.contextNotFound="contextNotFound",n.timerNotFound="timerNotFound",n.ctxCallOutOfScope="ctxCallOutOfScope",n.createNodeInParserFail="createNodeInParserFail",n.stackOverFlow="stackOverFlow",n.parserMatchError="parserMatchError",n.serializerMatchError="serializerMatchError",n.getAtomFromSchemaFail="getAtomFromSchemaFail",n.expectDomTypeError="expectDomTypeError",n.callCommandBeforeEditorView="callCommandBeforeEditorView",n.missingRootElement="missingRootElement",n.missingNodeInSchema="missingNodeInSchema",n.missingMarkInSchema="missingMarkInSchema",n.ctxNotBind="ctxNotBind",n.missingYjsDoc="missingYjsDoc",n))(Pe||{}),Ne=class extends Error{constructor(e,t){super(t),this.name="MilkdownError",this.code=e}},cm=(n,e)=>typeof e=="function"?"[Function]":e,Li=n=>JSON.stringify(n,cm);function Wu(n){return new Ne(Pe.docTypeError,`Doc type error, unsupported type: ${Li(n)}`)}function ju(n){return new Ne(Pe.contextNotFound,`Context "${n}" not found, do you forget to inject it?`)}function Hu(n){return new Ne(Pe.timerNotFound,`Timer "${n}" not found, do you forget to record it?`)}function On(){return new Ne(Pe.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function qu(n,e,t){let i=`Cannot create node for ${"name"in n?n.name:n}`,o=c=>{if(c==null)return"null";if(Array.isArray(c))return`[${c.map(o).join(", ")}]`;if(typeof c=="object")return"toJSON"in c&&typeof c.toJSON=="function"?JSON.stringify(c.toJSON()):"spec"in c?JSON.stringify(c.spec):JSON.stringify(c);if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")return JSON.stringify(c);if(typeof c=="function")return`[Function: ${c.name||"anonymous"}]`;try{return String(c)}catch{return"[Unserializable]"}},s=["[Description]",i],l=["[Attributes]",e],a=["[Content]",(t??[]).map(c=>c?typeof c=="object"&&"type"in c?`${c}`:o(c):"null")],u=[s,l,a].reduce((c,[f,p])=>{let h=`${f}: ${o(p)}.`;return c.concat(h)},[]);return new Ne(Pe.createNodeInParserFail,u.join(`
+`))}function Es(){return new Ne(Pe.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function Ku(n){return new Ne(Pe.parserMatchError,`Cannot match target parser for node: ${Li(n)}.`)}function Ju(n){return new Ne(Pe.serializerMatchError,`Cannot match target serializer for node: ${Li(n)}.`)}function Mt(n){return new Ne(Pe.expectDomTypeError,`Expect to be a dom, but get: ${Li(n)}.`)}function zi(){return new Ne(Pe.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function Uu(n){return new Ne(Pe.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${n}" in schema.`)}function Gu(n){return new Ne(Pe.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${n}" in schema.`)}var Cr=class{constructor(){this.sliceMap=new Map,this.get=e=>{let t=typeof e=="string"?[...this.sliceMap.values()].find(r=>r.type.name===e):this.sliceMap.get(e.id);if(!t){let r=typeof e=="string"?e:e.name;throw ju(r)}return t},this.remove=e=>{let t=typeof e=="string"?[...this.sliceMap.values()].find(r=>r.type.name===e):this.sliceMap.get(e.id);t&&this.sliceMap.delete(t.type.id)},this.has=e=>typeof e=="string"?[...this.sliceMap.values()].some(t=>t.type.name===e):this.sliceMap.has(e.id)}},As=class{constructor(e,t,r){this.#t=[],this.#r=()=>{this.#t.forEach(i=>i(this.#e))},this.set=i=>{this.#e=i,this.#r()},this.get=()=>this.#e,this.update=i=>{this.#e=i(this.#e),this.#r()},this.type=r,this.#e=t,e.set(r.id,this)}#t;#e;#r;on(e){return this.#t.push(e),()=>{this.#t=this.#t.filter(t=>t!==e)}}once(e){let t=this.on(r=>{e(r),t()});return t}off(e){this.#t=this.#t.filter(t=>t!==e)}offAll(){this.#t=[]}},Ds=class{constructor(e,t){this.id=Symbol(`Context-${t}`),this.name=t,this._defaultValue=e,this._typeInfo=()=>{throw On()}}create(e,t=this._defaultValue){return new As(e,t,this)}},V=(n,e)=>new Ds(n,e),Rs=class{constructor(e,t,r){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#i=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(i=>({name:typeof i=="string"?i:i.name,value:this.#l(i)})),consumedSlices:[...this.#s].map(i=>({name:typeof i=="string"?i:i.name,value:this.#l(i)})),recordedTimers:[...this.#o].map(([i,{duration:o}])=>({name:i.name,duration:o,status:this.#a(i)})),waitTimers:[...this.#i].map(([i,{duration:o}])=>({name:i.name,duration:o,status:this.#a(i)}))}),this.onRecord=i=>{this.#o.set(i,{start:Date.now(),duration:0})},this.onClear=i=>{this.#o.delete(i)},this.onDone=i=>{let o=this.#o.get(i);o&&(o.duration=Date.now()-o.start)},this.onWait=(i,o)=>{let s=Date.now();o.finally(()=>{this.#i.set(i,{duration:Date.now()-s})}).catch(console.error)},this.onInject=i=>{this.#n.add(i)},this.onRemove=i=>{this.#n.delete(i)},this.onUse=i=>{this.#s.add(i)},this.#l=i=>this.#e.get(i).get(),this.#a=i=>this.#r.get(i).status,this.#e=e,this.#r=t,this.#t=r}#t;#e;#r;#n;#s;#o;#i;#l;#a},Fi=class n{constructor(e,t,r){this.produce=i=>i&&Object.keys(i).length?new n(this.#t,this.#e,{...i}):this,this.inject=(i,o)=>{let s=i.create(this.#t.sliceMap);return o!=null&&s.set(o),this.#n?.onInject(i),this},this.remove=i=>(this.#t.remove(i),this.#n?.onRemove(i),this),this.record=i=>(i.create(this.#e.store),this.#n?.onRecord(i),this),this.clearTimer=i=>(this.#e.remove(i),this.#n?.onClear(i),this),this.isInjected=i=>this.#t.has(i),this.isRecorded=i=>this.#e.has(i),this.use=i=>(this.#n?.onUse(i),this.#t.get(i)),this.get=i=>this.use(i).get(),this.set=(i,o)=>this.use(i).set(o),this.update=(i,o)=>this.use(i).update(o),this.timer=i=>this.#e.get(i),this.done=i=>{this.timer(i).done(),this.#n?.onDone(i)},this.wait=i=>{let o=this.timer(i).start();return this.#n?.onWait(i,o),o},this.waitTimers=async i=>{await Promise.all(this.get(i).map(o=>this.wait(o)))},this.#t=e,this.#e=t,this.#r=r,r&&(this.#n=new Rs(e,t,r))}#t;#e;#r;#n;get meta(){return this.#r}get inspector(){return this.#n}},_i=class{constructor(){this.store=new Map,this.get=e=>{let t=this.store.get(e.id);if(!t)throw Hu(e.name);return t},this.remove=e=>{this.store.delete(e.id)},this.has=e=>this.store.has(e.id)}},vs=class{constructor(e,t){this.#t=null,this.#e=null,this.#n="pending",this.start=()=>(this.#t??=new Promise((r,i)=>{this.#e=o=>{o instanceof CustomEvent&&o.detail.id===this.#r&&(this.#n="resolved",this.#s(),o.stopImmediatePropagation(),r())},this.#o(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#s(),i(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{let r=new CustomEvent(this.type.name,{detail:{id:this.#r}});dispatchEvent(r)},this.#s=()=>{this.#e&&removeEventListener(this.type.name,this.#e)},this.#o=r=>{setTimeout(()=>{r()},this.type.timeout)},this.#r=Symbol(t.name),this.type=t,e.set(t.id,this)}#t;#e;#r;#n;get status(){return this.#n}#s;#o},Ps=class{constructor(e,t=3e3){this.create=r=>new vs(r,this),this.id=Symbol(`Timer-${e}`),this.name=e,this.timeout=t}},$e=(n,e=3e3)=>new Ps(n,e);function me(n){this.content=n}me.prototype={constructor:me,find:function(n){for(var e=0;e>1}};me.from=function(n){if(n instanceof me)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new me(e)};var Bs=me;function oc(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),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=oc(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function sc(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}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(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}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 t=0,r=0;;t++){let i=this.child(t),o=r+i.nodeSize;if(o>=e)return o==e?Vi(t+1,o):Vi(t,r);r=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(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};H.none=[];var qt=class extends Error{},T=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=ac(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(lc(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(M.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};T.empty=new T(M.empty,0,0);function lc(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(lc(o.content,e-i-1,t-i-1)))}function ac(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ac(s.content,e-o-1,t,s);return l&&n.replaceChild(i,s.copy(l))}function fm(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 uc(n,e,t,0)}function uc(n,e,t,r){let i=n.index(r),o=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 Mr(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(jt(n.nodeAfter,r),o++));for(let l=o;li&&Fs(n,e,i+1),s=r.depth>i&&Fs(t,r,i+1),l=[];return Mr(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(cc(o,s),jt(Ht(o,fc(n,e,t,r,i+1)),l)):(o&&jt(Ht(o,ji(n,e,i+1)),l),Mr(e,t,i,l),s&&jt(Ht(s,ji(t,r,i+1)),l)),Mr(r,null,i,l),new M(l)}function ji(n,e,t){let r=[];if(Mr(null,n,t,r),n.depth>t){let i=Fs(n,e,t+1);jt(Ht(i,ji(n,e,t+1)),r)}return Mr(e,null,t,r),new M(r)}function hm(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(M.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Hi=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 o=0;o0;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 Nr(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,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new n(t,r,o)}static resolveCached(e,t){let r=Qu.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.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()+")"),hc(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=M.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.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;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=M.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};Te.prototype.text=void 0;var Vs=class n extends Te{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):hc(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 hc(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var Kt=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new $s(e,t);if(r.next==null)return n.empty;let i=pc(r);r.next&&r.err("Unexpected trailing text");let o=Sm(bm(i));return wm(o,r),o}matchType(e){for(let t=0;tu.createAndFill()));for(let u=0;u=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 o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(`
+`)}};Kt.empty=new Kt(!0);var $s=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 pc(n){let e=[];do e.push(mm(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function mm(n){let e=[];do e.push(gm(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function gm(n){let e=km(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=ym(n,e);else break;return e}function Yu(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function ym(n,e){let t=Yu(n),r=t;return n.eat(",")&&(n.next!="}"?r=Yu(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function xm(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function km(n){if(n.eat("(")){let e=pc(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=xm(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 bm(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{n[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new Kt(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:gc(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Te(this,this.computeAttrs(e),M.from(t),H.setFrom(r))}createChecked(e=null,t,r){return t=M.from(t),this.checkContent(t),new Te(this,this.computeAttrs(e),t,H.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=M.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(M.empty,!0);return o?new Te(this,e,t.append(o),H.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));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 o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Cm(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var Ws=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Cm(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=xc(e,i.attrs),this.excluded=null;let o=mc(this.attrs);this.instance=o?new H(this,o):null}create(e=null){return!e&&this.instance?this.instance:new H(this,gc(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Ki=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=Bs.from(e.nodes),t.marks=Bs.from(e.marks||{}),this.nodes=qi.compile(this.spec.nodes,this),this.marks=Tr.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 o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=Kt.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Zu(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Zu(this,s.split(" "))}this.nodeFromJSON=i=>Te.fromJSON(this,i),this.markFromJSON=i=>H.fromJSON(this,i),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 qi){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 Vs(r,r.defaultAttrs,e,H.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Zu(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Mm(n){return n.tag!=null}function Im(n){return n.style!=null}var Jt=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Mm(i))this.tags.push(i);else if(Im(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Ji(this,t,!1);return r.addAll(e,H.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Ji(this,t,!0);return r.addAll(e,H.none,t.from,t.to),T.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(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=tc(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=tc(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},kc={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},Nm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},bc={ol:!0,ul:!0},Or=1,js=2,Ir=4;function ec(n,e,t){return e!=null?(e?Or:0)|(e==="full"?js:0):n&&n.whitespace=="pre"?Or|js:t&~Ir}var En=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=H.none,this.match=o||(s&Ir?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(M.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&Or)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=M.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(M.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!kc.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Ji=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=t.topNode,o,s=ec(null,t.preserveWhitespace,0)|(r?Ir:0);i?o=new En(i.type,i.attrs,H.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new En(null,null,H.none,!0,null,s):o=new En(e.schema.topNodeType,null,H.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top,o=i.options&js?"full":this.localPreserveWS||(i.options&Or)>0,{schema:s}=this.parser;if(o==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)if(o==="full")r=r.replace(/\r\n?/g,`
+`);else if(s.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(s.linebreakReplacement.create())){let l=r.split(/\r?\n|\r/);for(let a=0;a!a.clearMark(u)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let a=this.enter(s,t.attrs||null,r,t.preserveWhitespace);a&&(o=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t,r){let i,o;for(let s=this.open,l=0;s>=0;s--){let a=this.nodes[s],u=a.findWrapping(e);if(u&&(!i||i.length>u.length+l)&&(i=u,o=a,!u.length))break;if(a.solid){if(r)break;l+=2}}if(!i)return null;this.sync(o);for(let s=0;s(s.type?s.type.allowsMarkType(u.type):nc(u.type,e))?(a=u.addToSet(a),!1):!0),this.nodes.push(new En(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=Or)}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),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=t[l];if(u==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&!c.isInGroup(u))return!1;a--}}return!0};return s(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}}};function Tm(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&bc.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Om(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function tc(n){let e={};for(let t in n)e[t]=n[t];return e}function nc(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&$i(zs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return $i(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=rc(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return rc(e.marks)}};function rc(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function zs(n){return n.document||window.document}var ic=new WeakMap;function Em(n){let e=ic.get(n);return e===void 0&&ic.set(n,e=Am(n)),e}function Am(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let f in u)if(u[f]!=null){let p=f.indexOf(" ");p>0?a.setAttributeNS(f.slice(0,p),f.slice(p+1),u[f]):f=="style"&&a.style?a.style.cssText=u[f]:a.setAttribute(f,u[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:d}=$i(n,p,t,r);if(a.appendChild(h),d){if(l)throw new RangeError("Multiple content holes");l=d}}}return{dom:a,contentDOM:l}}var Cc=65535,Mc=Math.pow(2,16);function Dm(n,e){return n+e*Mc}function Sc(n){return n&Cc}function Rm(n){return(n-(n&Cc))/Mc}var Ic=1,Nc=2,Ui=4,Tc=8,Dr=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Tc)>0}get deletedBefore(){return(this.delInfo&(Ic|Ui))>0}get deletedAfter(){return(this.delInfo&(Nc|Ui))>0}get deletedAcross(){return(this.delInfo&Ui)>0}},ht=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=Sc(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let p=u?e==a?-1:e==f?1:t:t,h=a+i+(p<0?0:c);if(r)return h;let d=e==(t<0?a:f)?null:Dm(l/3,e-a),y=e==a?Nc:e==f?Ic:Ui;return(t<0?e!=a:e!=f)&&(y|=Tc),new Dr(h,y,d)}i+=c-u}return r?e+i:new Dr(e+i,0,null)}touches(e,t){let r=0,i=Sc(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=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;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ue.fromReplace(e,this.from,this.to,o)}invert(){return new Qt(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))}};oe.jsonID("addMark",Gt);var Qt=class n extends oe{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 T(Gs(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ue.fromReplace(e,this.from,this.to,r)}invert(){return new Gt(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))}};oe.jsonID("removeMark",Qt);var vr=class n extends oe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ue.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ue.fromReplace(e,this.pos,this.pos+1,new T(M.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,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(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,T.fromJSON(e,t.slice),t.insert,!!t.structure)}};oe.jsonID("replaceAround",ce);function Js(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function vm(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let p=Math.max(u,e),h=Math.min(u+a.nodeSize,t),d=r.addToSet(f);for(let y=0;yn.step(a)),o.forEach(a=>n.step(a))}function Pm(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof Tr){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Qt(s.from,s.to,s.style)))}function Qs(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let a=0;a=0;a--)n.step(s[a])}function Bm(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Rn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth,i=0,o=0;;--r){let s=n.$from.node(r),l=n.$from.index(r)+i,a=n.$to.indexAfter(r)-o;if(rt;d--)y||r.index(d)>0?(y=!0,c=M.from(r.node(d).copy(c)),f++):a--;let p=M.empty,h=0;for(let d=o,y=!1;d>t;d--)y||i.after(d+1)=0;s--){if(r.size){let l=t[s].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=M.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new ce(i,o,i,o,new T(r,0,0),t.length,!0))}function Vm(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let a=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,a)&&$m(n.doc,n.mapping.slice(o).map(l),r)){let u=null;if(r.schema.linebreakReplacement){let h=r.whitespace=="pre",d=!!r.contentMatch.matchType(r.schema.linebreakReplacement);h&&!d?u=!1:!h&&d&&(u=!0)}u===!1&&Ec(n,s,l,o),Qs(n,n.mapping.slice(o).map(l,1),r,void 0,u===null);let c=n.mapping.slice(o),f=c.map(l,1),p=c.map(l+s.nodeSize,1);return n.step(new ce(f,p,f+1,p-1,new T(M.from(r.create(a,null,s.marks)),0,0),1,!0)),u===!0&&Oc(n,s,l,o),!1}})}function Oc(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Ec(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(`
+`))}})}function $m(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Wm(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new ce(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new T(M.from(s),0,0),1,!0))}function Xt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,c=t-2;u>o;u--,c--){let f=i.node(u),p=i.index(u);if(f.type.spec.isolating)return!1;let h=f.content.cutByIndex(p,f.childCount),d=r&&r[c+1];d&&(h=h.replaceChild(0,d.type.create(d.attrs)));let y=r&&r[c]||f;if(!f.canReplace(p+1,f.childCount)||!y.type.validContent(h))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function jm(n,e,t=1,r){let i=n.doc.resolve(e),o=M.empty,s=M.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=M.from(i.node(l).copy(o));let c=r&&r[u];s=M.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new ge(e,e,new T(o.append(s),t,t),!0))}function Zt(n,e){let t=n.resolve(e),r=t.index();return qm(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Hm(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Pr(n,e,t=e,r=T.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return Dc(i,o,r)?new ge(e,t,r):new Us(i,o,r).fit()}function Dc(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Us=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=M.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=M.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new T(o,s,l);return e>-1?new ce(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new ge(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=qs(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(M.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=qs(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new T(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=qs(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new T(Er(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new T(Er(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let y=0;y1||a==0||y.content.size)&&(f=x,c.push(Rc(y.mark(p.allowedMarks(y.marks)),u==1?a:0,u==l.childCount?h:-1)))}let d=u==l.childCount;d||(h=-1),this.placed=Ar(this.placed,t,M.from(c)),this.frontier[t].match=f,d&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let y=0,x=l;y1&&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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Ks(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Ar(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ar(this.placed,this.depth,M.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(M.empty,!0);t.childCount&&(this.placed=Ar(this.placed,this.frontier.length,t))}};function Er(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Er(n.firstChild.content,e-1,t)))}function Ar(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Ar(n.lastChild.content,e-1,t)))}function qs(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Rc(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(M.empty,!0)))),n.copy(r)}function Ks(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Um(t,o.content,s)?l:null}function Um(n,e,t){for(let r=t;r0;p--,h--){let d=i.node(p).type.spec;if(d.defining||d.definingAsContext||d.isolating)break;s.indexOf(p)>-1?l=p:i.before(p)==h&&s.splice(1,0,-p)}let a=s.indexOf(l),u=[],c=r.openStart;for(let p=r.content,h=0;;h++){let d=p.firstChild;if(u.push(d),h==r.openStart)break;p=d.content}for(let p=c-1;p>=0;p--){let h=u[p],d=Gm(h.type);if(d&&!h.sameMarkup(i.node(Math.abs(l)-1)))c=p;else if(d||!h.type.isTextblock)break}for(let p=r.openStart;p>=0;p--){let h=(p+c+1)%(r.openStart+1),d=u[h];if(d)for(let y=0;y=0&&(n.replace(e,t,r),!(n.steps.length>f));p--){let h=s[p];h<0||(e=i.before(h),t=o.after(h))}}function vc(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(M.empty,!0))}return n}function Ym(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Jm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new T(M.from(r),0,0))}function Xm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Pc(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Pc(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Gi=class n extends oe{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 ue.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ue.fromReplace(e,this.pos,this.pos+1,new T(M.from(i),0,t.isLeaf?0:1))}getMap(){return ht.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)}};oe.jsonID("attr",Gi);var Qi=class n extends oe{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 ue.ok(r)}getMap(){return ht.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)}};oe.jsonID("docAttr",Qi);var Dn=class extends Error{};Dn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Dn.prototype=Object.create(Error.prototype);Dn.prototype.constructor=Dn;Dn.prototype.name="TransformError";var Yi=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 Dn(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}changedRange(){let e=1e9,t=-1e9;for(let r=0;r{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}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=T.empty){let i=Pr(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new T(M.from(r),0,0))}delete(e,t){return this.replace(e,t,T.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Qm(this,e,t,r),this}replaceRangeWith(e,t,r){return Ym(this,e,t,r),this}deleteRange(e,t){return Xm(this,e,t),this}lift(e,t){return Lm(this,e,t),this}join(e,t=1){return Km(this,e,t),this}wrap(e,t){return _m(this,e,t),this}setBlockType(e,t=e,r,i=null){return Vm(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Wm(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Gi(e,t,r)),this}setDocAttribute(e,t){return this.step(new Qi(e,t)),this}addNodeMark(e,t){return this.step(new vr(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof H)t.isInSet(r.marks)&&this.step(new An(e,t));else{let i=r.marks,o,s=[];for(;o=t.isInSet(i);)s.push(new An(e,o)),i=o.removeFromSet(i);for(let l=s.length-1;l>=0;l--)this.step(s[l])}return this}split(e,t=1,r){return jm(this,e,t,r),this}addMark(e,t,r){return vm(this,e,t,r),this}removeMark(e,t,r){return Pm(this,e,t,r),this}clearIncompatible(e,t,r){return Qs(this,e,t,r),this}};var Ys=Object.create(null),$=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Pn(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;o--){let s=t<0?vn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):vn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Be(e.node(0))}static atStart(e){return vn(e,e,0,0,1)||new Be(e)}static atEnd(e){return vn(e,e,e.content.size,e.childCount,-1)||new Be(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Ys[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 Ys)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ys[e]=t,t.prototype.jsonID=e,t}getBookmark(){return K.between(this.$anchor,this.$head).getBookmark()}};$.prototype.visible=!0;var Pn=class{constructor(e,t){this.$from=e,this.$to=t}},Bc=!1;function Lc(n){!Bc&&!n.parent.inlineContent&&(Bc=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var K=class n extends ${constructor(e,t=e){Lc(e),Lc(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 $.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=T.empty){if(super.replace(e,t),t==T.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 Zi(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 o=$.findFrom(t,r,!0)||$.findFrom(t,-r,!0);if(o)t=o.$head;else return $.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=($.findFrom(e,-r,!0)||$.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&v.isSelectable(l))return v.create(n,t-(i<0?l.nodeSize:0))}else{let a=vn(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function zc(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=c)}),n.setSelection($.near(n.doc.resolve(s),t))}var Fc=1,Xi=2,_c=4,el=class extends Yi{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|=Xi,this}ensureMarks(e){return H.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&Xi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Xi,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)||H.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),!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection($.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|=_c,this}get scrolledIntoView(){return(this.updated&_c)>0}};function Vc(n,e){return!e||!n?n:n.bind(e)}var en=class{constructor(e,t,r){this.name=e,this.init=Vc(t.init,r),this.apply=Vc(t.apply,r)}},eg=[new en("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new en("selection",{init(n,e){return n.selection||$.atStart(e.doc)},apply(n){return n.selection}}),new en("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new en("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Br=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=eg.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 en(r.key,r.spec.state,r))})}},eo=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],o=i.spec.state;o&&o.toJSON&&(t[r]=o.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 Br(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Te.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=$.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=u.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function $c(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=$c(i,e,{})),t[r]=i}return t}var ie=class{constructor(e){this.spec=e,this.props={},e.props&&$c(e.props,this,this.props),this.key=e.key?e.key.key:Wc("plugin")}getState(e){return e[this.key]}},Xs=Object.create(null);function Wc(n){return n in Xs?n+"$"+ ++Xs[n]:(Xs[n]=0,n+"$")}var se=class{constructor(e="key"){this.key=Wc(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var to=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Hc(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var nl=(n,e,t)=>{let r=Hc(n,t);if(!r)return!1;let i=il(r);if(!i){let s=r.blockRange(),l=s&&Rn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(Jc(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Bn(o,"end")||v.isSelectable(o)))for(let s=r.depth;;s--){let l=Pr(n.doc,r.before(s),r.after(s),T.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1},qc=(n,e,t)=>{let r=Hc(n,t);if(!r)return!1;let i=il(r);return i?tg(n,i,e):!1};function tg(n,e,t){let r=e.nodeBefore,i=r,o=e.pos-1;for(;!i.isTextblock;o--){if(i.type.spec.isolating)return!1;let c=i.lastChild;if(!c)return!1;i=c}let s=e.nodeAfter,l=s,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let c=l.firstChild;if(!c)return!1;l=c}let u=Pr(n.doc,o,a,T.empty);if(!u||u.from!=o||u instanceof ge&&u.slice.size>=a-o)return!1;if(t){let c=n.tr.step(u);c.setSelection(K.create(c.doc,o)),t(c.scrollIntoView())}return!0}function Bn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var rl=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=il(r)}let s=o&&o.nodeBefore;return!s||!v.isSelectable(s)?!1:(e&&e(n.tr.setSelection(v.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function il(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 ng(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=ng(n,t);if(!r)return!1;let i=Kc(r);if(!i)return!1;let o=i.nodeAfter;if(Jc(n,i,e,1))return!0;if(r.parent.content.size==0&&(Bn(o,"start")||v.isSelectable(o))){let s=Pr(n.doc,r.before(),r.after(),T.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
+`).scrollIntoView()),!0)};function ol(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),o=t.indexAfter(-1),s=ol(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection($.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},lg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Be||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=ol(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Xt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Rn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function ug(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof v&&e.selection.node.isBlock)return!r.parentOffset||!Xt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,l,a=!1,u=!1;for(let h=r.depth;;h--)if(r.node(h).isBlock){a=r.end(h)==r.pos+(r.depth-h),u=r.start(h)==r.pos-(r.depth-h),l=ol(r.node(h-1).contentMatchAt(r.indexAfter(h-1)));let y=n&&n(i.parent,a,r);o.unshift(y||(a&&l?{type:l}:null)),s=h;break}else{if(h==1)return!1;o.unshift(null)}let c=e.tr;(e.selection instanceof K||e.selection instanceof Be)&&c.deleteSelection();let f=c.mapping.map(r.pos),p=Xt(c.doc,f,o.length,o);if(p||(o[0]=l?{type:l}:null,p=Xt(c.doc,f,o.length,o)),!p)return!1;if(c.split(f,o.length,o),!a&&u&&r.node(s).type!=l){let h=c.mapping.map(r.before(s)),d=c.doc.resolve(h);l&&r.node(s-1).canReplaceWith(d.index(),d.index()+1,l)&&c.setNodeMarkup(c.mapping.map(r.before(s)),l)}return t&&t(c.scrollIntoView()),!0}}var cg=ug();var fg=(n,e)=>(e&&e(n.tr.setSelection(new Be(n.doc))),!0);function hg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||Zt(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Jc(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,a=i.type.spec.isolating||o.type.spec.isolating;if(!a&&hg(n,e,t))return!0;let u=!a&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let h=e.pos+o.nodeSize,d=M.empty;for(let k=s.length-1;k>=0;k--)d=M.from(s[k].create(null,d));d=M.from(i.copy(d));let y=n.tr.step(new ce(e.pos-1,h,e.pos,h,new T(d,1,0),s.length,!0)),x=y.doc.resolve(h+2*s.length);x.nodeAfter&&x.nodeAfter.type==i.type&&Zt(y.doc,x.pos)&&y.join(x.pos),t(y.scrollIntoView())}return!0}let c=o.type.spec.isolating||r>0&&a?null:$.findFrom(e,1),f=c&&c.$from.blockRange(c.$to),p=f&&Rn(f);if(p!=null&&p>=e.depth)return t&&t(n.tr.lift(f,p).scrollIntoView()),!0;if(u&&Bn(o,"start",!0)&&Bn(i,"end")){let h=i,d=[];for(;d.push(h),!h.isTextblock;)h=h.lastChild;let y=o,x=1;for(;!y.isTextblock;y=y.firstChild)x++;if(h.canReplace(h.childCount,h.childCount,y.content)){if(t){let k=M.empty;for(let C=d.length-1;C>=0;C--)k=M.from(d[C].copy(k));let E=n.tr.step(new ce(e.pos-d.length,e.pos+o.nodeSize,e.pos+x,e.pos+o.nodeSize-x,new T(k,d.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function Uc(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(K.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var pg=Uc(-1),dg=Uc(1);function no(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Yt(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function Ln(n,e=null){return function(t,r){let i=!1;for(let o=0;o{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let c=t.doc.resolve(u),f=c.index();i=c.parent.canReplaceWith(f,f+1,n)}})}if(!i)return!1;if(r){let o=t.tr;for(let s=0;s{if(l||!r&&a.isAtom&&a.isInline&&u>=o.pos&&u+a.nodeSize<=s.pos)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function gg(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new Pn(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poss.doc.rangeHasMark(h.$from.pos,h.$to.pos,n)):f=!c.every(h=>{let d=!1;return p.doc.nodesBetween(h.$from.pos,h.$to.pos,(y,x,k)=>{if(d)return!1;d=!n.isInSet(y.marks)&&!!k&&k.type.allowsMarkType(n)&&!(y.isText&&/^\s*$/.test(y.textBetween(Math.max(0,h.$from.pos-x),Math.min(y.nodeSize,h.$to.pos-x))))}),!d});for(let h=0;hi?0:i+e:e=e>i?i:e,t=t>0?t:0,r.length<1e4)s=Array.from(r),s.unshift(e,t),n.splice(...s);else for(t&&n.splice(e,t);o0?(fe(n,n.length,0,e),n):e}var ef={}.hasOwnProperty;function tf(n){let e={},t=-1;for(;++t13&&t<32||t>126&&t<160||t>55295&&t<57344||t>64975&&t<65008||(t&65535)===65535||(t&65535)===65534||t>1114111?"\uFFFD":String.fromCodePoint(t)}function dt(n){return n.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}var Le=It(/[A-Za-z]/),Se=It(/[\dA-Za-z]/),nf=It(/[#-'*+\--9=?A-Z^-~]/);function Lr(n){return n!==null&&(n<32||n===127)}var zr=It(/\d/),rf=It(/[\dA-Fa-f]/),of=It(/[!-/:-@[-`{-~]/);function O(n){return n!==null&&n<-2}function ee(n){return n!==null&&(n<0||n===32)}function B(n){return n===-2||n===-1||n===32}var sf=It(/\p{P}|\p{S}/u),lf=It(/\s/);function It(n){return e;function e(t){return t!==null&&t>-1&&n.test(String.fromCharCode(t))}}function z(n,e,t,r){let i=r?r-1:Number.POSITIVE_INFINITY,o=0;return s;function s(a){return B(a)?(n.enter(t),l(a)):e(a)}function l(a){return B(a)&&o++s))return;let N=e.events.length,R=N,D,Y;for(;R--;)if(e.events[R][0]==="exit"&&e.events[R][1].type==="chunkFlow"){if(D){Y=e.events[R][1].end;break}D=!0}for(k(r),b=N;bC;){let F=t[P];e.containerState=F[1],F[0].exit.call(e,n)}t.length=C}function E(){i.write([null]),o=void 0,i=void 0,e.containerState._closeFlow=void 0}}function Mg(n,e,t){return z(n,n.attempt(this.parser.constructs.document,e,t),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Fn(n){if(n===null||ee(n)||lf(n))return 1;if(sf(n))return 2}function _n(n,e,t){let r=[],i=-1;for(;++i1&&n[t][1].end.offset-n[t][1].start.offset>1?2:1;let f={...n[r][1].end},p={...n[t][1].start};ff(f,-a),ff(p,a),s={type:a>1?"strongSequence":"emphasisSequence",start:f,end:{...n[r][1].end}},l={type:a>1?"strongSequence":"emphasisSequence",start:{...n[t][1].start},end:p},o={type:a>1?"strongText":"emphasisText",start:{...n[r][1].end},end:{...n[t][1].start}},i={type:a>1?"strong":"emphasis",start:{...s.start},end:{...l.end}},n[r][1].end={...s.start},n[t][1].start={...l.end},u=[],n[r][1].end.offset-n[r][1].start.offset&&(u=be(u,[["enter",n[r][1],e],["exit",n[r][1],e]])),u=be(u,[["enter",i,e],["enter",s,e],["exit",s,e],["enter",o,e]]),u=be(u,_n(e.parser.constructs.insideSpan.null,n.slice(r+1,t),e)),u=be(u,[["exit",o,e],["enter",l,e],["exit",l,e],["exit",i,e]]),n[t][1].end.offset-n[t][1].start.offset?(c=2,u=be(u,[["enter",n[t][1],e],["exit",n[t][1],e]])):c=0,fe(n,r-1,t-r+3,u),t=r+u.length-c-2;break}}for(t=-1;++t0&&B(b)?z(n,E,"linePrefix",o+1)(b):E(b)}function E(b){return b===null||O(b)?n.check(hf,y,P)(b):(n.enter("codeFlowValue"),C(b))}function C(b){return b===null||O(b)?(n.exit("codeFlowValue"),E(b)):(n.consume(b),C)}function P(b){return n.exit("codeFenced"),e(b)}function F(b,N,R){let D=0;return Y;function Y(_){return b.enter("lineEnding"),b.consume(_),b.exit("lineEnding"),_e}function _e(_){return b.enter("codeFencedFence"),B(_)?z(b,G,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(_):G(_)}function G(_){return _===l?(b.enter("codeFencedFenceSequence"),A(_)):R(_)}function A(_){return _===l?(D++,b.consume(_),A):D>=s?(b.exit("codeFencedFenceSequence"),B(_)?z(b,j,"whitespace")(_):j(_)):R(_)}function j(_){return _===null||O(_)?(b.exit("codeFencedFence"),N(_)):R(_)}}}function Bg(n,e,t){let r=this;return i;function i(s){return s===null?t(s):(n.enter("lineEnding"),n.consume(s),n.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?t(s):e(s)}}var _r={name:"codeIndented",tokenize:zg},Lg={partial:!0,tokenize:Fg};function zg(n,e,t){let r=this;return i;function i(u){return n.enter("codeIndented"),z(n,o,"linePrefix",5)(u)}function o(u){let c=r.events[r.events.length-1];return c&&c[1].type==="linePrefix"&&c[2].sliceSerialize(c[1],!0).length>=4?s(u):t(u)}function s(u){return u===null?a(u):O(u)?n.attempt(Lg,s,a)(u):(n.enter("codeFlowValue"),l(u))}function l(u){return u===null||O(u)?(n.exit("codeFlowValue"),s(u)):(n.consume(u),l)}function a(u){return n.exit("codeIndented"),e(u)}}function Fg(n,e,t){let r=this;return i;function i(s){return r.parser.lazy[r.now().line]?t(s):O(s)?(n.enter("lineEnding"),n.consume(s),n.exit("lineEnding"),i):z(n,o,"linePrefix",5)(s)}function o(s){let l=r.events[r.events.length-1];return l&&l[1].type==="linePrefix"&&l[2].sliceSerialize(l[1],!0).length>=4?e(s):O(s)?i(s):t(s)}}var ll={name:"codeText",previous:Vg,resolve:_g,tokenize:$g};function _g(n){let e=n.length-4,t=3,r,i;if((n[t][1].type==="lineEnding"||n[t][1].type==="space")&&(n[e][1].type==="lineEnding"||n[e][1].type==="space")){for(r=t;++r=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(e,t,r){let i=t||0;this.setCursor(Math.trunc(e));let o=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Vr(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),Vr(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),Vr(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?e(s):n.interrupt(r.parser.constructs.flow,t,e)(s)}}function fo(n,e,t,r,i,o,s,l,a){let u=a||Number.POSITIVE_INFINITY,c=0;return f;function f(k){return k===60?(n.enter(r),n.enter(i),n.enter(o),n.consume(k),n.exit(o),p):k===null||k===32||k===41||Lr(k)?t(k):(n.enter(r),n.enter(s),n.enter(l),n.enter("chunkString",{contentType:"string"}),y(k))}function p(k){return k===62?(n.enter(o),n.consume(k),n.exit(o),n.exit(i),n.exit(r),e):(n.enter(l),n.enter("chunkString",{contentType:"string"}),h(k))}function h(k){return k===62?(n.exit("chunkString"),n.exit(l),p(k)):k===null||k===60||O(k)?t(k):(n.consume(k),k===92?d:h)}function d(k){return k===60||k===62||k===92?(n.consume(k),h):h(k)}function y(k){return!c&&(k===null||k===41||ee(k))?(n.exit("chunkString"),n.exit(l),n.exit(s),n.exit(r),e(k)):c999||h===null||h===91||h===93&&!a||h===94&&!l&&"_hiddenFootnoteSupport"in s.parser.constructs?t(h):h===93?(n.exit(o),n.enter(i),n.consume(h),n.exit(i),n.exit(r),e):O(h)?(n.enter("lineEnding"),n.consume(h),n.exit("lineEnding"),c):(n.enter("chunkString",{contentType:"string"}),f(h))}function f(h){return h===null||h===91||h===93||O(h)||l++>999?(n.exit("chunkString"),c(h)):(n.consume(h),a||(a=!B(h)),h===92?p:f)}function p(h){return h===91||h===92||h===93?(n.consume(h),l++,f):f(h)}}function po(n,e,t,r,i,o){let s;return l;function l(p){return p===34||p===39||p===40?(n.enter(r),n.enter(i),n.consume(p),n.exit(i),s=p===40?41:p,a):t(p)}function a(p){return p===s?(n.enter(i),n.consume(p),n.exit(i),n.exit(r),e):(n.enter(o),u(p))}function u(p){return p===s?(n.exit(o),a(s)):p===null?t(p):O(p)?(n.enter("lineEnding"),n.consume(p),n.exit("lineEnding"),z(n,u,"linePrefix")):(n.enter("chunkString",{contentType:"string"}),c(p))}function c(p){return p===s||p===null||O(p)?(n.exit("chunkString"),u(p)):(n.consume(p),p===92?f:c)}function f(p){return p===s||p===92?(n.consume(p),c):c(p)}}function rn(n,e){let t;return r;function r(i){return O(i)?(n.enter("lineEnding"),n.consume(i),n.exit("lineEnding"),t=!0,r):B(i)?z(n,r,t?"linePrefix":"lineSuffix")(i):e(i)}}var ul={name:"definition",tokenize:Ug},Jg={partial:!0,tokenize:Gg};function Ug(n,e,t){let r=this,i;return o;function o(h){return n.enter("definition"),s(h)}function s(h){return ho.call(r,n,l,t,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function l(h){return i=dt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),h===58?(n.enter("definitionMarker"),n.consume(h),n.exit("definitionMarker"),a):t(h)}function a(h){return ee(h)?rn(n,u)(h):u(h)}function u(h){return fo(n,c,t,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function c(h){return n.attempt(Jg,f,f)(h)}function f(h){return B(h)?z(n,p,"whitespace")(h):p(h)}function p(h){return h===null||O(h)?(n.exit("definition"),r.parser.defined.push(i),e(h)):t(h)}}function Gg(n,e,t){return r;function r(l){return ee(l)?rn(n,i)(l):t(l)}function i(l){return po(n,o,t,"definitionTitle","definitionTitleMarker","definitionTitleString")(l)}function o(l){return B(l)?z(n,s,"whitespace")(l):s(l)}function s(l){return l===null||O(l)?e(l):t(l)}}var cl={name:"hardBreakEscape",tokenize:Qg};function Qg(n,e,t){return r;function r(o){return n.enter("hardBreakEscape"),n.consume(o),i}function i(o){return O(o)?(n.exit("hardBreakEscape"),e(o)):t(o)}}var fl={name:"headingAtx",resolve:Yg,tokenize:Xg};function Yg(n,e){let t=n.length-2,r=3,i,o;return n[r][1].type==="whitespace"&&(r+=2),t-2>r&&n[t][1].type==="whitespace"&&(t-=2),n[t][1].type==="atxHeadingSequence"&&(r===t-1||t-4>r&&n[t-2][1].type==="whitespace")&&(t-=r+1===t?2:4),t>r&&(i={type:"atxHeadingText",start:n[r][1].start,end:n[t][1].end},o={type:"chunkText",start:n[r][1].start,end:n[t][1].end,contentType:"text"},fe(n,r,t-r+1,[["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e]])),n}function Xg(n,e,t){let r=0;return i;function i(c){return n.enter("atxHeading"),o(c)}function o(c){return n.enter("atxHeadingSequence"),s(c)}function s(c){return c===35&&r++<6?(n.consume(c),s):c===null||ee(c)?(n.exit("atxHeadingSequence"),l(c)):t(c)}function l(c){return c===35?(n.enter("atxHeadingSequence"),a(c)):c===null||O(c)?(n.exit("atxHeading"),e(c)):B(c)?z(n,l,"whitespace")(c):(n.enter("atxHeadingText"),u(c))}function a(c){return c===35?(n.consume(c),a):(n.exit("atxHeadingSequence"),l(c))}function u(c){return c===null||c===35||ee(c)?(n.exit("atxHeadingText"),l(c)):(n.consume(c),u)}}var pf=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],hl=["pre","script","style","textarea"];var pl={concrete:!0,name:"htmlFlow",resolveTo:ty,tokenize:ny},Zg={partial:!0,tokenize:iy},ey={partial:!0,tokenize:ry};function ty(n){let e=n.length;for(;e--&&!(n[e][0]==="enter"&&n[e][1].type==="htmlFlow"););return e>1&&n[e-2][1].type==="linePrefix"&&(n[e][1].start=n[e-2][1].start,n[e+1][1].start=n[e-2][1].start,n.splice(e-2,2)),n}function ny(n,e,t){let r=this,i,o,s,l,a;return u;function u(g){return c(g)}function c(g){return n.enter("htmlFlow"),n.enter("htmlFlowData"),n.consume(g),f}function f(g){return g===33?(n.consume(g),p):g===47?(n.consume(g),o=!0,y):g===63?(n.consume(g),i=3,r.interrupt?e:m):Le(g)?(n.consume(g),s=String.fromCharCode(g),x):t(g)}function p(g){return g===45?(n.consume(g),i=2,h):g===91?(n.consume(g),i=5,l=0,d):Le(g)?(n.consume(g),i=4,r.interrupt?e:m):t(g)}function h(g){return g===45?(n.consume(g),r.interrupt?e:m):t(g)}function d(g){let Re="CDATA[";return g===Re.charCodeAt(l++)?(n.consume(g),l===Re.length?r.interrupt?e:G:d):t(g)}function y(g){return Le(g)?(n.consume(g),s=String.fromCharCode(g),x):t(g)}function x(g){if(g===null||g===47||g===62||ee(g)){let Re=g===47,Vt=s.toLowerCase();return!Re&&!o&&hl.includes(Vt)?(i=1,r.interrupt?e(g):G(g)):pf.includes(s.toLowerCase())?(i=6,Re?(n.consume(g),k):r.interrupt?e(g):G(g)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?t(g):o?E(g):C(g))}return g===45||Se(g)?(n.consume(g),s+=String.fromCharCode(g),x):t(g)}function k(g){return g===62?(n.consume(g),r.interrupt?e:G):t(g)}function E(g){return B(g)?(n.consume(g),E):Y(g)}function C(g){return g===47?(n.consume(g),Y):g===58||g===95||Le(g)?(n.consume(g),P):B(g)?(n.consume(g),C):Y(g)}function P(g){return g===45||g===46||g===58||g===95||Se(g)?(n.consume(g),P):F(g)}function F(g){return g===61?(n.consume(g),b):B(g)?(n.consume(g),F):C(g)}function b(g){return g===null||g===60||g===61||g===62||g===96?t(g):g===34||g===39?(n.consume(g),a=g,N):B(g)?(n.consume(g),b):R(g)}function N(g){return g===a?(n.consume(g),a=null,D):g===null||O(g)?t(g):(n.consume(g),N)}function R(g){return g===null||g===34||g===39||g===47||g===60||g===61||g===62||g===96||ee(g)?F(g):(n.consume(g),R)}function D(g){return g===47||g===62||B(g)?C(g):t(g)}function Y(g){return g===62?(n.consume(g),_e):t(g)}function _e(g){return g===null||O(g)?G(g):B(g)?(n.consume(g),_e):t(g)}function G(g){return g===45&&i===2?(n.consume(g),Z):g===60&&i===1?(n.consume(g),re):g===62&&i===4?(n.consume(g),Ve):g===63&&i===3?(n.consume(g),m):g===93&&i===5?(n.consume(g),et):O(g)&&(i===6||i===7)?(n.exit("htmlFlowData"),n.check(Zg,at,A)(g)):g===null||O(g)?(n.exit("htmlFlowData"),A(g)):(n.consume(g),G)}function A(g){return n.check(ey,j,at)(g)}function j(g){return n.enter("lineEnding"),n.consume(g),n.exit("lineEnding"),_}function _(g){return g===null||O(g)?A(g):(n.enter("htmlFlowData"),G(g))}function Z(g){return g===45?(n.consume(g),m):G(g)}function re(g){return g===47?(n.consume(g),s="",Ue):G(g)}function Ue(g){if(g===62){let Re=s.toLowerCase();return hl.includes(Re)?(n.consume(g),Ve):G(g)}return Le(g)&&s.length<8?(n.consume(g),s+=String.fromCharCode(g),Ue):G(g)}function et(g){return g===93?(n.consume(g),m):G(g)}function m(g){return g===62?(n.consume(g),Ve):g===45&&i===2?(n.consume(g),m):G(g)}function Ve(g){return g===null||O(g)?(n.exit("htmlFlowData"),at(g)):(n.consume(g),Ve)}function at(g){return n.exit("htmlFlow"),e(g)}}function ry(n,e,t){let r=this;return i;function i(s){return O(s)?(n.enter("lineEnding"),n.consume(s),n.exit("lineEnding"),o):t(s)}function o(s){return r.parser.lazy[r.now().line]?t(s):e(s)}}function iy(n,e,t){return r;function r(i){return n.enter("lineEnding"),n.consume(i),n.exit("lineEnding"),n.attempt(Nt,e,t)}}var dl={name:"htmlText",tokenize:oy};function oy(n,e,t){let r=this,i,o,s;return l;function l(m){return n.enter("htmlText"),n.enter("htmlTextData"),n.consume(m),a}function a(m){return m===33?(n.consume(m),u):m===47?(n.consume(m),F):m===63?(n.consume(m),C):Le(m)?(n.consume(m),R):t(m)}function u(m){return m===45?(n.consume(m),c):m===91?(n.consume(m),o=0,d):Le(m)?(n.consume(m),E):t(m)}function c(m){return m===45?(n.consume(m),h):t(m)}function f(m){return m===null?t(m):m===45?(n.consume(m),p):O(m)?(s=f,re(m)):(n.consume(m),f)}function p(m){return m===45?(n.consume(m),h):f(m)}function h(m){return m===62?Z(m):m===45?p(m):f(m)}function d(m){let Ve="CDATA[";return m===Ve.charCodeAt(o++)?(n.consume(m),o===Ve.length?y:d):t(m)}function y(m){return m===null?t(m):m===93?(n.consume(m),x):O(m)?(s=y,re(m)):(n.consume(m),y)}function x(m){return m===93?(n.consume(m),k):y(m)}function k(m){return m===62?Z(m):m===93?(n.consume(m),k):y(m)}function E(m){return m===null||m===62?Z(m):O(m)?(s=E,re(m)):(n.consume(m),E)}function C(m){return m===null?t(m):m===63?(n.consume(m),P):O(m)?(s=C,re(m)):(n.consume(m),C)}function P(m){return m===62?Z(m):C(m)}function F(m){return Le(m)?(n.consume(m),b):t(m)}function b(m){return m===45||Se(m)?(n.consume(m),b):N(m)}function N(m){return O(m)?(s=N,re(m)):B(m)?(n.consume(m),N):Z(m)}function R(m){return m===45||Se(m)?(n.consume(m),R):m===47||m===62||ee(m)?D(m):t(m)}function D(m){return m===47?(n.consume(m),Z):m===58||m===95||Le(m)?(n.consume(m),Y):O(m)?(s=D,re(m)):B(m)?(n.consume(m),D):Z(m)}function Y(m){return m===45||m===46||m===58||m===95||Se(m)?(n.consume(m),Y):_e(m)}function _e(m){return m===61?(n.consume(m),G):O(m)?(s=_e,re(m)):B(m)?(n.consume(m),_e):D(m)}function G(m){return m===null||m===60||m===61||m===62||m===96?t(m):m===34||m===39?(n.consume(m),i=m,A):O(m)?(s=G,re(m)):B(m)?(n.consume(m),G):(n.consume(m),j)}function A(m){return m===i?(n.consume(m),i=void 0,_):m===null?t(m):O(m)?(s=A,re(m)):(n.consume(m),A)}function j(m){return m===null||m===34||m===39||m===60||m===61||m===96?t(m):m===47||m===62||ee(m)?D(m):(n.consume(m),j)}function _(m){return m===47||m===62||ee(m)?D(m):t(m)}function Z(m){return m===62?(n.consume(m),n.exit("htmlTextData"),n.exit("htmlText"),e):t(m)}function re(m){return n.exit("htmlTextData"),n.enter("lineEnding"),n.consume(m),n.exit("lineEnding"),Ue}function Ue(m){return B(m)?z(n,et,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(m):et(m)}function et(m){return n.enter("htmlTextData"),s(m)}}var on={name:"labelEnd",resolveAll:uy,resolveTo:cy,tokenize:fy},sy={tokenize:hy},ly={tokenize:py},ay={tokenize:dy};function uy(n){let e=-1,t=[];for(;++e=3&&(u===null||O(u))?(n.exit("thematicBreak"),e(u)):t(u)}function a(u){return u===i?(n.consume(u),r++,a):(n.exit("thematicBreakSequence"),B(u)?z(n,l,"whitespace")(u):l(u))}}var ye={continuation:{tokenize:wy},exit:My,name:"list",tokenize:Sy},ky={partial:!0,tokenize:Iy},by={partial:!0,tokenize:Cy};function Sy(n,e,t){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return l;function l(h){let d=r.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(d==="listUnordered"?!r.containerState.marker||h===r.containerState.marker:zr(h)){if(r.containerState.type||(r.containerState.type=d,n.enter(d,{_container:!0})),d==="listUnordered")return n.enter("listItemPrefix"),h===42||h===45?n.check(sn,t,u)(h):u(h);if(!r.interrupt||h===49)return n.enter("listItemPrefix"),n.enter("listItemValue"),a(h)}return t(h)}function a(h){return zr(h)&&++s<10?(n.consume(h),a):(!r.interrupt||s<2)&&(r.containerState.marker?h===r.containerState.marker:h===41||h===46)?(n.exit("listItemValue"),u(h)):t(h)}function u(h){return n.enter("listItemMarker"),n.consume(h),n.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||h,n.check(Nt,r.interrupt?t:c,n.attempt(ky,p,f))}function c(h){return r.containerState.initialBlankLine=!0,o++,p(h)}function f(h){return B(h)?(n.enter("listItemPrefixWhitespace"),n.consume(h),n.exit("listItemPrefixWhitespace"),p):t(h)}function p(h){return r.containerState.size=o+r.sliceSerialize(n.exit("listItemPrefix"),!0).length,e(h)}}function wy(n,e,t){let r=this;return r.containerState._closeFlow=void 0,n.check(Nt,i,o);function i(l){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,z(n,e,"listItemIndent",r.containerState.size+1)(l)}function o(l){return r.containerState.furtherBlankLines||!B(l)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(l)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,n.attempt(by,e,s)(l))}function s(l){return r.containerState._closeFlow=!0,r.interrupt=void 0,z(n,n.attempt(ye,e,t),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(l)}}function Cy(n,e,t){let r=this;return z(n,i,"listItemIndent",r.containerState.size+1);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===r.containerState.size?e(o):t(o)}}function My(n){n.exit(this.containerState.type)}function Iy(n,e,t){let r=this;return z(n,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(o){let s=r.events[r.events.length-1];return!B(o)&&s&&s[1].type==="listItemPrefixWhitespace"?e(o):t(o)}}var mo={name:"setextUnderline",resolveTo:Ny,tokenize:Ty};function Ny(n,e){let t=n.length,r,i,o;for(;t--;)if(n[t][0]==="enter"){if(n[t][1].type==="content"){r=t;break}n[t][1].type==="paragraph"&&(i=t)}else n[t][1].type==="content"&&n.splice(t,1),!o&&n[t][1].type==="definition"&&(o=t);let s={type:"setextHeading",start:{...n[r][1].start},end:{...n[n.length-1][1].end}};return n[i][1].type="setextHeadingText",o?(n.splice(i,0,["enter",s,e]),n.splice(o+1,0,["exit",n[r][1],e]),n[r][1].end={...n[o][1].end}):n[r][1]=s,n.push(["exit",s,e]),n}function Ty(n,e,t){let r=this,i;return o;function o(u){let c=r.events.length,f;for(;c--;)if(r.events[c][1].type!=="lineEnding"&&r.events[c][1].type!=="linePrefix"&&r.events[c][1].type!=="content"){f=r.events[c][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(n.enter("setextHeadingLine"),i=u,s(u)):t(u)}function s(u){return n.enter("setextHeadingLineSequence"),l(u)}function l(u){return u===i?(n.consume(u),l):(n.exit("setextHeadingLineSequence"),B(u)?z(n,a,"lineSuffix")(u):a(u))}function a(u){return u===null||O(u)?(n.exit("setextHeadingLine"),e(u)):t(u)}}var df={tokenize:Oy};function Oy(n){let e=this,t=n.attempt(Nt,r,n.attempt(this.parser.constructs.flowInitial,i,z(n,n.attempt(this.parser.constructs.flow,i,n.attempt(al,i)),"linePrefix")));return t;function r(o){if(o===null){n.consume(o);return}return n.enter("lineEndingBlank"),n.consume(o),n.exit("lineEndingBlank"),e.currentConstruct=void 0,t}function i(o){if(o===null){n.consume(o);return}return n.enter("lineEnding"),n.consume(o),n.exit("lineEnding"),e.currentConstruct=void 0,t}}var mf={resolveAll:kf()},gf=xf("string"),yf=xf("text");function xf(n){return{resolveAll:kf(n==="text"?Ey:void 0),tokenize:e};function e(t){let r=this,i=this.parser.constructs[n],o=t.attempt(i,s,l);return s;function s(c){return u(c)?o(c):l(c)}function l(c){if(c===null){t.consume(c);return}return t.enter("data"),t.consume(c),a}function a(c){return u(c)?(t.exit("data"),o(c)):(t.consume(c),a)}function u(c){if(c===null)return!0;let f=i[c],p=-1;if(f)for(;++pzy,contentInitial:()=>Dy,disable:()=>Fy,document:()=>Ay,flow:()=>vy,flowInitial:()=>Ry,insideSpan:()=>Ly,string:()=>Py,text:()=>By});var Ay={42:ye,43:ye,45:ye,48:ye,49:ye,50:ye,51:ye,52:ye,53:ye,54:ye,55:ye,56:ye,57:ye,62:oo},Dy={91:ul},Ry={[-2]:_r,[-1]:_r,32:_r},vy={35:fl,42:sn,45:[mo,sn],60:pl,61:mo,95:sn,96:ao,126:ao},Py={38:lo,92:so},By={[-5]:$r,[-4]:$r,[-3]:$r,33:ml,38:lo,42:Fr,60:[sl,dl],91:gl,92:[cl,so],93:on,95:Fr,96:ll},Ly={null:[Fr,mf]},zy={null:[42,95]},Fy={null:[]};function bf(n,e,t){let r={_bufferIndex:-1,_index:0,line:t&&t.line||1,column:t&&t.column||1,offset:t&&t.offset||0},i={},o=[],s=[],l=[],a=!0,u={attempt:D(N),check:D(R),consume:P,enter:F,exit:b,interrupt:D(R,{interrupt:!0})},c={code:null,containerState:{},defineSkip:k,events:[],now:x,parser:n,previous:null,sliceSerialize:d,sliceStream:y,write:h},f=e.tokenize.call(c,u),p;return e.resolveAll&&o.push(e),c;function h(A){return s=be(s,A),E(),s[s.length-1]!==null?[]:(Y(e,0),c.events=_n(o,c.events,c),c.events)}function d(A,j){return Vy(y(A),j)}function y(A){return _y(s,A)}function x(){let{_bufferIndex:A,_index:j,line:_,column:Z,offset:re}=r;return{_bufferIndex:A,_index:j,line:_,column:Z,offset:re}}function k(A){i[A.line]=A.column,G()}function E(){let A;for(;r._index-1){let l=s[0];typeof l=="string"?s[0]=l.slice(r):s.shift()}o>0&&s.push(n[i].slice(0,o))}return s}function Vy(n,e){let t=-1,r=[],i;for(;++t0){let Ge=L.tokenStack[L.tokenStack.length-1];(Ge[1]||Mf).call(L,void 0,Ge[0])}for(I.position={start:Ot(w.length>0?w[0][1].start:{line:1,column:1,offset:0}),end:Ot(w.length>0?w[w.length-2][1].end:{line:1,column:1,offset:0})},Q=-1;++Q "),o.shift(2);let s=t.indentLines(t.containerFlow(n,o.current()),Jy);return i(),s}function Jy(n,e,t){return">"+(t?"":" ")+n}function yo(n,e){return Df(n,e.inConstruct,!0)&&!Df(n,e.notInConstruct,!1)}function Df(n,e,t){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return t;let r=-1;for(;++rs&&(s=o):o=1,i=r+e.length,r=t.indexOf(e,i);return s}function Wr(n,e){return!!(e.options.fences===!1&&n.value&&!n.lang&&/[^ \r\n]/.test(n.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(n.value))}function vf(n){let e=n.options.fence||"`";if(e!=="`"&&e!=="~")throw new Error("Cannot serialize code with `"+e+"` for `options.fence`, expected `` ` `` or `~`");return e}function Pf(n,e,t,r){let i=vf(t),o=n.value||"",s=i==="`"?"GraveAccent":"Tilde";if(Wr(n,t)){let f=t.enter("codeIndented"),p=t.indentLines(o,Uy);return f(),p}let l=t.createTracker(r),a=i.repeat(Math.max(Rf(o,i)+1,3)),u=t.enter("codeFenced"),c=l.move(a);if(n.lang){let f=t.enter(`codeFencedLang${s}`);c+=l.move(t.safe(n.lang,{before:c,after:" ",encode:["`"],...l.current()})),f()}if(n.lang&&n.meta){let f=t.enter(`codeFencedMeta${s}`);c+=l.move(" "),c+=l.move(t.safe(n.meta,{before:c,after:`
+`,encode:["`"],...l.current()})),f()}return c+=l.move(`
+`),o&&(c+=l.move(o+`
+`)),c+=l.move(a),u(),c}function Uy(n,e,t){return(t?"":" ")+n}function $n(n){let e=n.options.quote||'"';if(e!=='"'&&e!=="'")throw new Error("Cannot serialize title with `"+e+"` for `options.quote`, expected `\"`, or `'`");return e}function Bf(n,e,t,r){let i=$n(t),o=i==='"'?"Quote":"Apostrophe",s=t.enter("definition"),l=t.enter("label"),a=t.createTracker(r),u=a.move("[");return u+=a.move(t.safe(t.associationId(n),{before:u,after:"]",...a.current()})),u+=a.move("]: "),l(),!n.url||/[\0- \u007F]/.test(n.url)?(l=t.enter("destinationLiteral"),u+=a.move("<"),u+=a.move(t.safe(n.url,{before:u,after:">",...a.current()})),u+=a.move(">")):(l=t.enter("destinationRaw"),u+=a.move(t.safe(n.url,{before:u,after:n.title?" ":`
+`,...a.current()}))),l(),n.title&&(l=t.enter(`title${o}`),u+=a.move(" "+i),u+=a.move(t.safe(n.title,{before:u,after:i,...a.current()})),u+=a.move(i),l()),s(),u}function Lf(n){let e=n.options.emphasis||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize emphasis with `"+e+"` for `options.emphasis`, expected `*`, or `_`");return e}function ze(n){return""+n.toString(16).toUpperCase()+";"}function Wn(n,e,t){let r=Fn(n),i=Fn(e);return r===void 0?i===void 0?t==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}Il.peek=Gy;function Il(n,e,t,r){let i=Lf(t),o=t.enter("emphasis"),s=t.createTracker(r),l=s.move(i),a=s.move(t.containerPhrasing(n,{after:i,before:l,...s.current()})),u=a.charCodeAt(0),c=Wn(r.before.charCodeAt(r.before.length-1),u,i);c.inside&&(a=ze(u)+a.slice(1));let f=a.charCodeAt(a.length-1),p=Wn(r.after.charCodeAt(0),f,i);p.inside&&(a=a.slice(0,-1)+ze(f));let h=s.move(i);return o(),t.attentionEncodeSurroundingInfo={after:p.outside,before:c.outside},l+a+h}function Gy(n,e,t){return t.options.emphasis||"*"}var jn=(function(n){if(n==null)return Zy;if(typeof n=="function")return xo(n);if(typeof n=="object")return Array.isArray(n)?Qy(n):Yy(n);if(typeof n=="string")return Xy(n);throw new Error("Expected function, string, or object as test")});function Qy(n){let e=[],t=-1;for(;++t":""))+")"})}return p;function p(){let h=zf,d,y,x;if((!e||o(a,u,c[c.length-1]||void 0))&&(h=tx(t(a,c)),h[0]===ln))return h;if("children"in a&&a.children){let k=a;if(k.children&&h[0]!==an)for(y=(r?k.children.length:-1)+s,x=c.concat(k);y>-1&&y",...a.current()})),u+=a.move(">")):(l=t.enter("destinationRaw"),u+=a.move(t.safe(n.url,{before:u,after:n.title?" ":")",...a.current()}))),l(),n.title&&(l=t.enter(`title${o}`),u+=a.move(" "+i),u+=a.move(t.safe(n.title,{before:u,after:i,...a.current()})),u+=a.move(i),l()),u+=a.move(")"),s(),u}function rx(){return"!"}Ol.peek=ix;function Ol(n,e,t,r){let i=n.referenceType,o=t.enter("imageReference"),s=t.enter("label"),l=t.createTracker(r),a=l.move("!["),u=t.safe(n.alt,{before:a,after:"]",...l.current()});a+=l.move(u+"]["),s();let c=t.stack;t.stack=[],s=t.enter("reference");let f=t.safe(t.associationId(n),{before:a,after:"]",...l.current()});return s(),t.stack=c,o(),i==="full"||!u||u!==f?a+=l.move(f+"]"):i==="shortcut"?a=a.slice(0,-1):a+=l.move("]"),a}function ix(){return"!"}El.peek=ox;function El(n,e,t){let r=n.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++o\u007F]/.test(n.url))}Dl.peek=sx;function Dl(n,e,t,r){let i=$n(t),o=i==='"'?"Quote":"Apostrophe",s=t.createTracker(r),l,a;if(Al(n,t)){let c=t.stack;t.stack=[],l=t.enter("autolink");let f=s.move("<");return f+=s.move(t.containerPhrasing(n,{before:f,after:">",...s.current()})),f+=s.move(">"),l(),t.stack=c,f}l=t.enter("link"),a=t.enter("label");let u=s.move("[");return u+=s.move(t.containerPhrasing(n,{before:u,after:"](",...s.current()})),u+=s.move("]("),a(),!n.url&&n.title||/[\0- \u007F]/.test(n.url)?(a=t.enter("destinationLiteral"),u+=s.move("<"),u+=s.move(t.safe(n.url,{before:u,after:">",...s.current()})),u+=s.move(">")):(a=t.enter("destinationRaw"),u+=s.move(t.safe(n.url,{before:u,after:n.title?" ":")",...s.current()}))),a(),n.title&&(a=t.enter(`title${o}`),u+=s.move(" "+i),u+=s.move(t.safe(n.title,{before:u,after:i,...s.current()})),u+=s.move(i),a()),u+=s.move(")"),l(),u}function sx(n,e,t){return Al(n,t)?"<":"["}Rl.peek=lx;function Rl(n,e,t,r){let i=n.referenceType,o=t.enter("linkReference"),s=t.enter("label"),l=t.createTracker(r),a=l.move("["),u=t.containerPhrasing(n,{before:a,after:"]",...l.current()});a+=l.move(u+"]["),s();let c=t.stack;t.stack=[],s=t.enter("reference");let f=t.safe(t.associationId(n),{before:a,after:"]",...l.current()});return s(),t.stack=c,o(),i==="full"||!u||u!==f?a+=l.move(f+"]"):i==="shortcut"?a=a.slice(0,-1):a+=l.move("]"),a}function lx(){return"["}function Hn(n){let e=n.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function _f(n){let e=Hn(n),t=n.options.bulletOther;if(!t)return e==="*"?"-":"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(t===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+t+"`) to be different");return t}function Vf(n){let e=n.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function So(n){let e=n.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function $f(n,e,t,r){let i=t.enter("list"),o=t.bulletCurrent,s=n.ordered?Vf(t):Hn(t),l=n.ordered?s==="."?")":".":_f(t),a=e&&t.bulletLastUsed?s===t.bulletLastUsed:!1;if(!n.ordered){let c=n.children?n.children[0]:void 0;if((s==="*"||s==="-")&&c&&(!c.children||!c.children[0])&&t.stack[t.stack.length-1]==="list"&&t.stack[t.stack.length-2]==="listItem"&&t.stack[t.stack.length-3]==="list"&&t.stack[t.stack.length-4]==="listItem"&&t.indexStack[t.indexStack.length-1]===0&&t.indexStack[t.indexStack.length-2]===0&&t.indexStack[t.indexStack.length-3]===0&&(a=!0),So(t)===s&&c){let f=-1;for(;++f-1?e.start:1)+(t.options.incrementListMarker===!1?0:e.children.indexOf(n))+o);let s=o.length+1;(i==="tab"||i==="mixed"&&(e&&e.type==="list"&&e.spread||n.spread))&&(s=Math.ceil(s/4)*4);let l=t.createTracker(r);l.move(o+" ".repeat(s-o.length)),l.shift(s);let a=t.enter("listItem"),u=t.indentLines(t.containerFlow(n,l.current()),c);return a(),u;function c(f,p,h){return p?(h?"":" ".repeat(s))+f:(h?o:o+" ".repeat(s-o.length))+f}}function Hf(n,e,t,r){let i=t.enter("paragraph"),o=t.enter("phrasing"),s=t.containerPhrasing(n,r);return o(),i(),s}var vl=jn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function qf(n,e,t,r){return(n.children.some(function(s){return vl(s)})?t.containerPhrasing:t.containerFlow).call(t,n,r)}function Kf(n){let e=n.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}Pl.peek=ax;function Pl(n,e,t,r){let i=Kf(t),o=t.enter("strong"),s=t.createTracker(r),l=s.move(i+i),a=s.move(t.containerPhrasing(n,{after:i,before:l,...s.current()})),u=a.charCodeAt(0),c=Wn(r.before.charCodeAt(r.before.length-1),u,i);c.inside&&(a=ze(u)+a.slice(1));let f=a.charCodeAt(a.length-1),p=Wn(r.after.charCodeAt(0),f,i);p.inside&&(a=a.slice(0,-1)+ze(f));let h=s.move(i+i);return o(),t.attentionEncodeSurroundingInfo={after:p.outside,before:c.outside},l+a+h}function ax(n,e,t){return t.options.strong||"*"}function Jf(n,e,t,r){return t.safe(n.value,r)}function Uf(n){let e=n.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function Gf(n,e,t){let r=(So(t)+(t.options.ruleSpaces?" ":"")).repeat(Uf(t));return t.options.ruleSpaces?r.slice(0,-1):r}var Qf={blockquote:Af,break:Ml,code:Pf,definition:Bf,emphasis:Il,hardBreak:Ml,heading:Ff,html:Nl,image:Tl,imageReference:Ol,inlineCode:El,link:Dl,linkReference:Rl,list:$f,listItem:jf,paragraph:Hf,root:qf,strong:Pl,text:Jf,thematicBreak:Gf};var Yf=[ux];function ux(n,e,t,r){if(e.type==="code"&&Wr(e,r)&&(n.type==="list"||n.type===e.type&&Wr(n,r)))return!1;if("spread"in t&&typeof t.spread=="boolean")return n.type==="paragraph"&&(n.type===e.type||e.type==="definition"||e.type==="heading"&&bo(e,r))?void 0:t.spread?1:0}var un=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],Xf=[{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:`
+`,inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"!",after:"\\[",inConstruct:"phrasing",notInConstruct:un},{character:'"',inConstruct:"titleQuote"},{atBreak:!0,character:"#"},{character:"#",inConstruct:"headingAtx",after:`(?:[\r
+]|$)`},{character:"&",after:"[#A-Za-z]",inConstruct:"phrasing"},{character:"'",inConstruct:"titleApostrophe"},{character:"(",inConstruct:"destinationRaw"},{before:"\\]",character:"(",inConstruct:"phrasing",notInConstruct:un},{atBreak:!0,before:"\\d+",character:")"},{character:")",inConstruct:"destinationRaw"},{atBreak:!0,character:"*",after:`(?:[ \r
+*])`},{character:"*",inConstruct:"phrasing",notInConstruct:un},{atBreak:!0,character:"+",after:`(?:[ \r
+])`},{atBreak:!0,character:"-",after:`(?:[ \r
+-])`},{atBreak:!0,before:"\\d+",character:".",after:`(?:[ \r
+]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:un},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:un},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:un},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:un},{atBreak:!0,character:"~"}];function Zf(n){return n.label||!n.identifier?n.label||"":go(n.identifier)}function eh(n){if(!n._compiled){let e=(n.atBreak?"[\\r\\n][\\t ]*":"")+(n.before?"(?:"+n.before+")":"");n._compiled=new RegExp((e?"("+e+")":"")+(/[|\\{}()[\]^$+*?.-]/.test(n.character)?"\\":"")+n.character+(n.after?"(?:"+n.after+")":""),"g")}return n._compiled}function th(n,e,t){let r=e.indexStack,i=n.children||[],o=[],s=-1,l=t.before,a;r.push(-1);let u=e.createTracker(t);for(;++s0&&(l==="\r"||l===`
+`)&&c.type==="html"&&(o[o.length-1]=o[o.length-1].replace(/(\r?\n|\r)$/," "),l=" ",u=e.createTracker(t),u.move(o.join("")));let p=e.handle(c,n,e,{...u.current(),after:f,before:l});a&&a===p.slice(0,1)&&(p=ze(a.charCodeAt(0))+p.slice(1));let h=e.attentionEncodeSurroundingInfo;e.attentionEncodeSurroundingInfo=void 0,a=void 0,h&&(o.length>0&&h.before&&l===o[o.length-1].slice(-1)&&(o[o.length-1]=o[o.length-1].slice(0,-1)+ze(l.charCodeAt(0))),h.after&&(a=f)),u.move(p),o.push(p),l=p.slice(-1)}return r.pop(),o.join("")}function nh(n,e,t){let r=e.indexStack,i=n.children||[],o=e.createTracker(t),s=[],l=-1;for(r.push(-1);++l
+
+`}return`
+
+`}var fx=/\r?\n|\r/g;function rh(n,e){let t=[],r=0,i=0,o;for(;o=fx.exec(n);)s(n.slice(r,o.index)),t.push(o[0]),r=o.index+o[0].length,i++;return s(n.slice(r)),t.join("");function s(l){t.push(e(l,i,!l))}}function oh(n,e,t){let r=(t.before||"")+(e||"")+(t.after||""),i=[],o=[],s={},l=-1;for(;++l=u||c+1s.length,a;l&&s.push(i);try{a=n.apply(this,s)}catch(u){let c=u;if(l&&t)throw c;return i(c)}l||(a&&a.then&&typeof a.then=="function"?a.then(o,i):a instanceof Error?i(a):o(a))}function i(s,...l){t||(t=!0,e(s,...l))}function o(s){i(null,s)}}var le=class extends Error{constructor(e,t,r){super(),typeof t=="string"&&(r=t,t=void 0);let i="",o={},s=!1;if(t&&("line"in t&&"column"in t?o={place:t}:"start"in t&&"end"in t?o={place:t}:"type"in t?o={ancestors:[t],place:t.position}:o={...t}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let a=r.indexOf(":");a===-1?o.ruleId=r:(o.source=r.slice(0,a),o.ruleId=r.slice(a+1))}if(!o.place&&o.ancestors&&o.ancestors){let a=o.ancestors[o.ancestors.length-1];a&&(o.place=a.position)}let l=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=l?l.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=l?l.line:void 0,this.name=Tt(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};le.prototype.file="";le.prototype.name="";le.prototype.reason="";le.prototype.message="";le.prototype.stack="";le.prototype.column=void 0;le.prototype.line=void 0;le.prototype.ancestors=void 0;le.prototype.cause=void 0;le.prototype.fatal=void 0;le.prototype.place=void 0;le.prototype.ruleId=void 0;le.prototype.source=void 0;var Ye={basename:kx,dirname:bx,extname:Sx,join:wx,sep:"/"};function kx(n,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');qr(n);let t=0,r=-1,i=n.length,o;if(e===void 0||e.length===0||e.length>n.length){for(;i--;)if(n.codePointAt(i)===47){if(o){t=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":n.slice(t,r)}if(e===n)return"";let s=-1,l=e.length-1;for(;i--;)if(n.codePointAt(i)===47){if(o){t=i+1;break}}else s<0&&(o=!0,s=i+1),l>-1&&(n.codePointAt(i)===e.codePointAt(l--)?l<0&&(r=i):(l=-1,r=s));return t===r?r=s:r<0&&(r=n.length),n.slice(t,r)}function bx(n){if(qr(n),n.length===0)return".";let e=-1,t=n.length,r;for(;--t;)if(n.codePointAt(t)===47){if(r){e=t;break}}else r||(r=!0);return e<0?n.codePointAt(0)===47?"/":".":e===1&&n.codePointAt(0)===47?"//":n.slice(0,e)}function Sx(n){qr(n);let e=n.length,t=-1,r=0,i=-1,o=0,s;for(;e--;){let l=n.codePointAt(e);if(l===47){if(s){r=e+1;break}continue}t<0&&(s=!0,t=e+1),l===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||t<0||o===0||o===1&&i===t-1&&i===r+1?"":n.slice(i,t)}function wx(...n){let e=-1,t;for(;++e0&&n.codePointAt(n.length-1)===47&&(t+="/"),e?"/"+t:t}function Mx(n,e){let t="",r=0,i=-1,o=0,s=-1,l,a;for(;++s<=n.length;){if(s2){if(a=t.lastIndexOf("/"),a!==t.length-1){a<0?(t="",r=0):(t=t.slice(0,a),r=t.length-1-t.lastIndexOf("/")),i=s,o=0;continue}}else if(t.length>0){t="",r=0,i=s,o=0;continue}}e&&(t=t.length>0?t+"/..":"..",r=2)}else t.length>0?t+="/"+n.slice(i+1,s):t=n.slice(i+1,s),r=s-i-1;i=s,o=0}else l===46&&o>-1?o++:o=-1}return t}function qr(n){if(typeof n!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(n))}var yh={cwd:Ix};function Ix(){return"/"}function Kn(n){return!!(n!==null&&typeof n=="object"&&"href"in n&&n.href&&"protocol"in n&&n.protocol&&n.auth===void 0)}function xh(n){if(typeof n=="string")n=new URL(n);else if(!Kn(n)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+n+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(n.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return Nx(n)}function Nx(n){if(n.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=n.pathname,t=-1;for(;++t0){let[h,...d]=c,y=r[p][1];Hr(y)&&Hr(h)&&(h=(0,Mo.default)(!0,y,h)),r[p]=[u,h,...d]}}}},Jr=new Hl().freeze();function $l(n,e){if(typeof e!="function")throw new TypeError("Cannot `"+n+"` without `parser`")}function Wl(n,e){if(typeof e!="function")throw new TypeError("Cannot `"+n+"` without `compiler`")}function jl(n,e){if(e)throw new Error("Cannot call `"+n+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Sh(n){if(!Hr(n)||typeof n.type!="string")throw new TypeError("Expected node, got `"+n+"`")}function wh(n,e,t){if(!t)throw new Error("`"+n+"` finished async. Use `"+e+"` instead")}function Co(n){return Ex(n)?n:new Kr(n)}function Ex(n){return!!(n&&typeof n=="object"&&"message"in n&&"messages"in n)}function Ax(n){return typeof n=="string"||Dx(n)}function Dx(n){return!!(n&&typeof n=="object"&&"byteLength"in n&&"byteOffset"in n)}var Mh=n=>{throw TypeError(n)},Ih=(n,e,t)=>e.has(n)||Mh("Cannot "+t),W=(n,e,t)=>(Ih(n,e,"read from private field"),t?t.call(n):e.get(n)),te=(n,e,t)=>e.has(n)?Mh("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),X=(n,e,t,r)=>(Ih(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),tt,Ur,Io,No,To,Gr,Qr,mt,Yr,Oo,Eo,Xr,Ao,Zr,Do,Ro,Jn,cn,vo,ei,Po=class{},Bo=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=e=>{this.top()?.push(e)},this.open=e=>{this.elements.push(e)},this.close=()=>{let e=this.elements.pop();if(!e)throw Es();return e}}},ql=class n extends Po{constructor(e,t,r){super(),this.type=e,this.content=t,this.attrs=r}push(e,...t){this.content.push(e,...t)}pop(){return this.content.pop()}static create(e,t,r){return new n(e,t,r)}},Kl=class extends Bo{constructor(e){super(),te(this,tt),te(this,Ur),te(this,Io),te(this,No),te(this,To),te(this,Gr),te(this,Qr),X(this,tt,H.none),X(this,Ur,t=>t.isText),X(this,Io,(t,r)=>{if(W(this,Ur).call(this,t)&&W(this,Ur).call(this,r)&&H.sameSet(t.marks,r.marks))return this.schema.text(t.text+r.text,t.marks)}),X(this,No,t=>{let r=Object.values({...this.schema.nodes,...this.schema.marks}).find(i=>i.spec.parseMarkdown.match(t));if(!r)throw Ku(t);return r}),X(this,To,t=>{let r=W(this,No).call(this,t);r.spec.parseMarkdown.runner(this,t,r)}),this.injectRoot=(t,r,i)=>(this.openNode(r,i),this.next(t.children),this),this.openNode=(t,r)=>(this.open(ql.create(t,[],r)),this),X(this,Gr,()=>{X(this,tt,H.none);let t=this.close();return W(this,Qr).call(this,t.type,t.attrs,t.content)}),this.closeNode=()=>{try{W(this,Gr).call(this)}catch(t){console.error(t)}return this},X(this,Qr,(t,r,i)=>{let o=t.createAndFill(r,i,W(this,tt));if(!o)throw qu(t,r,i);return this.push(o),o}),this.addNode=(t,r,i)=>{try{W(this,Qr).call(this,t,r,i)}catch(o){console.error(o)}return this},this.openMark=(t,r)=>{let i=t.create(r);return X(this,tt,i.addToSet(W(this,tt))),this},this.closeMark=t=>(X(this,tt,t.removeFromSet(W(this,tt))),this),this.addText=t=>{try{let r=this.top();if(!r)throw Es();let i=r.pop(),o=this.schema.text(t,W(this,tt));if(!i)return r.push(o),this;let s=W(this,Io).call(this,i,o);return s?(r.push(s),this):(r.push(i,o),this)}catch(r){return console.error(r),this}},this.build=()=>{let t;do t=W(this,Gr).call(this);while(this.size());return t},this.next=(t=[])=>([t].flat().forEach(r=>W(this,To).call(this,r)),this),this.toDoc=()=>this.build(),this.run=(t,r)=>{let i=t.runSync(t.parse(r),r);return this.next(i),this},this.schema=e}};tt=new WeakMap;Ur=new WeakMap;Io=new WeakMap;No=new WeakMap;To=new WeakMap;Gr=new WeakMap;Qr=new WeakMap;Kl.create=(n,e)=>{let t=new Kl(n);return r=>(t.run(e,r),t.toDoc())};var Nh=Kl,Jl=class extends Po{constructor(e,t,r,i={}){super(),this.type=e,this.children=t,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}};Jl.create=(n,e,t,r={})=>new Jl(n,e,t,r);var Ch=Jl,Rx=n=>Object.prototype.hasOwnProperty.call(n,"size"),Ul=class extends Bo{constructor(e){super(),te(this,mt),te(this,Yr),te(this,Oo),te(this,Eo),te(this,Xr),te(this,Ao),te(this,Zr),te(this,Do),te(this,Ro),te(this,Jn),te(this,cn),te(this,vo),te(this,ei),X(this,mt,H.none),X(this,Yr,t=>{let r=Object.values({...this.schema.nodes,...this.schema.marks}).find(i=>i.spec.toMarkdown.match(t));if(!r)throw Ju(t.type);return r}),X(this,Oo,t=>W(this,Yr).call(this,t).spec.toMarkdown.runner(this,t)),X(this,Eo,(t,r)=>W(this,Yr).call(this,t).spec.toMarkdown.runner(this,t,r)),X(this,Xr,t=>{let{marks:r}=t,i=l=>l.type.spec.priority??50;[...r].sort((l,a)=>i(l)-i(a)).every(l=>!W(this,Eo).call(this,l,t))&&W(this,Oo).call(this,t),r.forEach(l=>W(this,ei).call(this,l))}),X(this,Ao,(t,r)=>{if(t.type===r||t.children?.length!==1)return t;let i=a=>{if(a.type===r)return a;if(a.children?.length!==1)return null;let[u]=a.children;return u?i(u):null},o=i(t);if(!o)return t;let s=o.children?[...o.children]:void 0,l={...t,children:s};return l.children=s,o.children=[l],o}),X(this,Zr,t=>{let{children:r}=t;return r&&(t.children=r.reduce((i,o,s)=>{if(s===0)return[o];let l=i.at(-1);if(l&&l.isMark&&o.isMark){o=W(this,Ao).call(this,o,l.type);let{children:a,...u}=o,{children:c,...f}=l;if(o.type===l.type&&a&&c&&JSON.stringify(u)===JSON.stringify(f)){let p={...f,children:[...c,...a]};return i.slice(0,-1).concat(W(this,Zr).call(this,p))}}return i.concat(o)},[])),t}),X(this,Do,t=>{let r={...t.props,type:t.type};return t.children&&(r.children=t.children),t.value&&(r.value=t.value),r}),this.openNode=(t,r,i)=>(this.open(Ch.create(t,void 0,r,i)),this),X(this,Ro,(t,r)=>{let i="",o="",s=t.children,l=-1,a=-1,u=f=>{f&&f.forEach((p,h)=>{p.type==="text"&&p.value&&(l<0&&(l=h),a=h)})};if(s){u(s);let f=s?.[a],p=s?.[l];if(f&&f.value.endsWith(" ")){let h=f.value,d=h.trimEnd();o=h.slice(d.length),f.value=d}if(p&&p.value.startsWith(" ")){let h=p.value,d=h.trimStart();i=h.slice(0,h.length-d.length),p.value=d}}i.length&&W(this,cn).call(this,"text",void 0,i);let c=r();return o.length&&W(this,cn).call(this,"text",void 0,o),c}),X(this,Jn,(t=!1)=>{let r=this.close(),i=()=>W(this,cn).call(this,r.type,r.children,r.value,r.props);return t?W(this,Ro).call(this,r,i):i()}),this.closeNode=()=>(W(this,Jn).call(this),this),X(this,cn,(t,r,i,o)=>{let s=Ch.create(t,r,i,o),l=W(this,Zr).call(this,W(this,Do).call(this,s));return this.push(l),l}),this.addNode=(t,r,i,o)=>(W(this,cn).call(this,t,r,i,o),this),X(this,vo,(t,r,i,o)=>t.isInSet(W(this,mt))?this:(X(this,mt,t.addToSet(W(this,mt))),this.openNode(r,i,{...o,isMark:!0}))),X(this,ei,t=>{t.isInSet(W(this,mt))&&(X(this,mt,t.type.removeFromSet(W(this,mt))),W(this,Jn).call(this,!0))}),this.withMark=(t,r,i,o)=>(W(this,vo).call(this,t,r,i,o),this),this.closeMark=t=>(W(this,ei).call(this,t),this),this.build=()=>{let t=null;do t=W(this,Jn).call(this);while(this.size());return t},this.next=t=>Rx(t)?(t.forEach(r=>{W(this,Xr).call(this,r)}),this):(W(this,Xr).call(this,t),this),this.toString=t=>t.stringify(this.build()),this.run=t=>(this.next(t),this),this.schema=e}};mt=new WeakMap;Yr=new WeakMap;Oo=new WeakMap;Eo=new WeakMap;Xr=new WeakMap;Ao=new WeakMap;Zr=new WeakMap;Do=new WeakMap;Ro=new WeakMap;Jn=new WeakMap;cn=new WeakMap;vo=new WeakMap;ei=new WeakMap;Ul.create=(n,e)=>{let t=new Ul(n);return r=>(t.run(r),t.toString(e))};var Th=Ul;var we=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?vx(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function vx(n){return function(e,t,r,i){let o=n;if(t[1]){let s=t[0].lastIndexOf(t[1]);o+=t[0].slice(s+t[1].length),r+=s;let l=r-i;l>0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Oh=(n,e)=>{let t=n.plugins;for(let r=0;r=0;a--)s.step(l.steps[a].invert(l.docs[a]));if(o.text){let a=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,a))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},QN=new we(/--$/,"\u2014",{inCodeMark:!1}),YN=new we(/\.\.\.$/,"\u2026",{inCodeMark:!1}),XN=new we(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),ZN=new we(/"$/,"\u201D",{inCodeMark:!1}),eT=new we(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),tT=new we(/'$/,"\u2019",{inCodeMark:!1});function Lo(n,e,t=null,r){return new we(n,(i,o,s,l)=>{let a=t instanceof Function?t(o):t,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),p=f&&Yt(f,e,a);if(!p)return null;u.wrap(f,p);let h=u.doc.resolve(s-1).nodeBefore;return h&&h.type==e&&Zt(u.doc,s-1)&&(!r||r(o,h))&&u.join(s-1),u})}function Gl(n,e,t=null){return new we(n,(r,i,o,s)=>{let l=r.doc.resolve(o),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,a):null})}var Et=typeof navigator<"u"?navigator:null,Eh=typeof document<"u"?document:null,At=Et&&Et.userAgent||"",Yl=/Edge\/(\d+)/.exec(At),Dh=/MSIE \d/.exec(At),Xl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(At),Zl=!!(Dh||Xl||Yl),oT=Dh?document.documentMode:Xl?+Xl[1]:Yl?+Yl[1]:0,Px=!Zl&&/gecko\/(\d+)/i.test(At),sT=Px&&+(/Firefox\/(\d+)/.exec(At)||[0,0])[1],Ah=!Zl&&/Chrome\/(\d+)/.exec(At);var lT=Ah?+Ah[1]:0,Bx=!Zl&&!!Et&&/Apple Computer/.test(Et.vendor),Lx=Bx&&(/Mobile\/\w+/.test(At)||!!Et&&Et.maxTouchPoints>2),aT=Lx||(Et?/Mac/.test(Et.platform):!1),uT=/Android \d/.test(At),zx=!!Eh&&"webkitFontSmoothing"in Eh.documentElement.style,cT=zx?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ql(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e);if(l.parent.type.spec.code)return!1;let a=l.parent.textBetween(Math.max(0,l.parentOffset-500),l.parentOffset,void 0,"\uFFFC")+r;for(let u of i){let c=u,f=c.match.exec(a),p=f&&f[0]&&c.handler(s,f,e-(f[0].length-r.length),t);if(p)return c.undoable!==!1&&p.setMeta(o,{transform:p,from:e,to:t,text:r}),n.dispatch(p),!0}return!1}var Fx=new se("MILKDOWN_CUSTOM_INPUTRULES");function Rh({rules:n}){let e=new ie({key:Fx,isInputRules:!0,state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Ql(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>(setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Ql(t,r.pos,r.pos,"",n,e)}),!1)},handleKeyDown(t,r){if(r.key!=="Enter")return!1;let{$cursor:i}=t.state.selection;return i?Ql(t,i.pos,i.pos,`
+`,n,e):!1}}});return e}function ti(n,e,t={}){return new we(n,(r,i,o,s)=>{var l,a,u,c;let{tr:f}=r,p=i.length,h=i[p-1],d=i[0],y=[],x=s,k={group:h,fullMatch:d,start:o,end:s},E=(l=t.updateCaptured)==null?void 0:l.call(t,k);if(Object.assign(k,E),{group:h,fullMatch:d,start:o,end:s}=k,d===null||h?.trim()==="")return null;if(h){let C=d.search(/\S/),P=o+d.indexOf(h),F=P+h.length;y=(a=f.storedMarks)!=null?a:[],Fo&&f.delete(o+C,P),x=o+C+h.length;let b=(u=t.getAttr)==null?void 0:u.call(t,i);f.addMark(o,x,e.create(b)),f.setStoredMarks(y),(c=t.beforeDispatch)==null||c.call(t,{match:i,start:o,end:s,tr:f})}return f})}function _x(n,e){return Array.isArray(n)&&n.includes(e.type)||e.type===n}function vh(n,e){if(!(n instanceof v))return;let{node:t,$from:r}=n;if(_x(e,t))return{node:t,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Ph=(n,e)=>{let{selection:t,doc:r}=n;if(t instanceof v)return{hasNode:t.node.type===e,pos:t.from,target:t.node};let{from:i,to:o}=t,s=!1,l=-1,a=null;return r.nodesBetween(i,o,(u,c)=>a?!1:u.type===e?(s=!0,l=c,a=u,!1):!0),{hasNode:s,pos:l,target:a}};var gt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Fo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Vx=typeof navigator<"u"&&/Mac/.test(navigator.platform),$x=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(ne=0;ne<10;ne++)gt[48+ne]=gt[96+ne]=String(ne);var ne;for(ne=1;ne<=24;ne++)gt[ne+111]="F"+ne;var ne;for(ne=65;ne<=90;ne++)gt[ne]=String.fromCharCode(ne+32),Fo[ne]=String.fromCharCode(ne);var ne;for(zo in gt)Fo.hasOwnProperty(zo)||(Fo[zo]=gt[zo]);var zo;function Bh(n){var e=Vx&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||$x&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Fo:gt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var Wx=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),jx=typeof navigator<"u"&&/Win/.test(navigator.platform);function Hx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=je(n)}else if(n.parentNode&&!ui(n))e=he(n),n=n.parentNode;else return null}}function Qx(n,e){for(;;){if(n.nodeType==3&&e2),We=Zn||(nt?/Mac/.test(nt.platform):!1),xp=nt?/Win/.test(nt.platform):!1,kt=/Android \d/.test(Lt),ci=!!Fh&&"webkitFontSmoothing"in Fh.documentElement.style,ek=ci?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function tk(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 yt(n,e){return typeof n=="number"?n:n[e]}function nk(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 _h(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;){if(s.nodeType!=1){s=Xn(s);continue}let l=s,a=l==o.body,u=a?tk(o):nk(l),c=0,f=0;if(e.topu.bottom-yt(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+yt(i,"top")-u.top:e.bottom-u.bottom+yt(i,"bottom")),e.leftu.right-yt(r,"right")&&(c=e.right-u.right+yt(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let h=l.scrollLeft,d=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let y=l.scrollLeft-h,x=l.scrollTop-d;e={left:e.left-y,top:e.top-x,right:e.right-y,bottom:e.bottom-x}}let p=a?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(p))break;s=p=="absolute"?s.offsetParent:Xn(s)}}function rk(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:kp(n.dom)}}function kp(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Xn(r));return e}function ik({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;bp(t,r==0?0:r-e)}function bp(n,e){for(let t=0;t=l){s=Math.max(d.bottom,s),l=Math.min(d.top,l);let y=d.left>e.left?d.left-e.left:d.right=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!a&&d.left<=e.left&&d.right>=e.left&&(a=c,u={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top});!t&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=u,r=0),t&&t.nodeType==3?sk(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Sp(t,i)}function sk(n,e){let t=n.nodeValue.length,r=document.createRange(),i;for(let o=0;o=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:n,offset:0}}function Ma(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function lk(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function uk(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function wp(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let u;ci&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.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=uk(n,r,i,e))}l==null&&(l=ak(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Vh(n){return n.top=0&&i==r.nodeValue.length?(a--,c=1):t<0?a--:u++,ni(Dt(xt(r,a,u),c),c<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==je(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return ta(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==je(r))){let a=r.childNodes[i-1],u=a.nodeType==3?xt(a,je(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return ni(Dt(u,1),!1)}if(o==null&&i=0)}function ni(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 ta(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 Mp(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 hk(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Mp(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Cp(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=xt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(t=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}var pk=/[\u0590-\u08ac]/;function dk(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!pk.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Mp(n,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=n.domSelectionRange(),p=l.caretBidiLevel;l.modify("move",t,"character");let h=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:d,focusOffset:y}=n.domSelectionRange(),x=d&&!h.contains(d.nodeType==1?d:d.parentNode)||a==d&&u==y;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return p!=null&&(l.caretBidiLevel=p),x}):r.pos==r.start()||r.pos==r.end()}var $h=null,Wh=null,jh=!1;function mk(n,e,t){return $h==e&&Wh==t?jh:($h=e,Wh=t,jh=t=="up"||t=="down"?hk(n,e,t):dk(n,e,t))}var qe=0,Hh=1,hn=2,rt=3,xn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=qe,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;the(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 o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.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 o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}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 o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof $o){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof _o&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?he(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){let p=this.children[f-1];if(p.size&&p.dom.parentNode==this.contentDOM&&!p.emptyChildAt(1)){i=he(p.dom)+1;break}e-=p.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;cd&&st){let d=l;l=a,a=d}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(h)}}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+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?hn:Hh,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=rt:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?hn:rt}r=s}this.dirty=hn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?hn:Hh;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==qe&&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 ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},ca=class extends xn{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}},er=class n extends xn{constructor(e,t,r,i,o){super(e,[],r,i),this.mark=t,this.spec=o}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=Ut.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&rt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=rt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=qe){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=da(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=Ut.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let p=c;return c=Tp(c,r,t),u?a=new fa(e,t,r,i,c,f||null,p,u,o,s+1):t.isText?new Vo(e,t,r,i,c,p,o):new n(e,t,r,i,c,f||null,p,o,s+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=()=>M.empty)}return e}matchesNode(e,t,r){return this.dirty==qe&&e.eq(this.node)&&Wo(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new pa(this,s&&s.node,e);kk(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e,c):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?H.none:this.node.child(c).marks,r,e,c),a.placeWidget(u,e,i)},(u,c,f,p)=>{a.syncToMarks(u.marks,r,e,p);let h;a.findNodeMatch(u,c,f,p)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,h,e)||a.updateNextNode(u,c,f,e,p,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==hn)&&(s&&this.protectLocalComposition(e,s),Ip(this.contentDOM,this.children,e),Zn&&bk(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof K)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Sk(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new ca(this,o,t,i);e.input.compositionNodes.push(s),this.children=da(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==rt||!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=qe}updateOuterDeco(e){if(Wo(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Np(this.dom,this.nodeDOM,ha(this.outerDeco,this.node,t),ha(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.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function qh(n,e,t,r,i){Tp(r,e,n);let o=new Bt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var Vo=class n extends Bt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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==rt||this.dirty!=qe&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=qe||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=qe,!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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=rt)}get domAtom(){return!1}isText(e){return this.node.text==e}},$o=class extends xn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==qe&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},fa=class extends Bt{constructor(e,t,r,i,o,s,l,a,u,c){super(e,t,r,i,o,s,l,u,c),this.spec=a}update(e,t,r,i){if(this.dirty==rt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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.root):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 Ip(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,l=Math.min(s,e.length);for(;o-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let c=er.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 o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=t.children[r-1];if(u instanceof er)t=u,r=u.children.length;else{l=u,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function xk(n,e){return n.type.side-e.type.side}function kk(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+p.nodeSize;if(p.isText){let x=d;s!x.inline):l.slice();r(p,y,e.forChild(o,p),h),o=d}}function bk(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 Sk(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=t)return l+u;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function da(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||c<=e?o.push(a):(ut&&o.push(a.slice(t-u,a.size,r)))}return o}function Ia(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(Go(t)){for(a=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&v.isSelectable(f)&&i.parent&&!(f.isInline&&Yx(t.focusNode,t.focusOffset,i.dom))){let p=i.posBefore;u=new v(s==p?l:r.resolve(p))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,p=s;for(let h=0;h{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Op(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ck(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,r=t.nodeName=="IMG";r?e.collapse(t.parentNode,he(t)+1):e.collapse(t,0),!r&&!n.state.selection.visible&&Oe&&Pt<=11&&(t.disabled=!0,t.disabled=!1)}function Ep(n,e){if(e instanceof v){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Qh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Qh(n)}function Qh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Na(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||K.between(e,t,r)}function Yh(n){return n.editable&&!n.hasFocus()?!1:Ap(n)}function Ap(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 Mk(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return yn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function ma(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&$.findFrom(o,e)}function Rt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Xh(n,e,t){let r=n.state.selection;if(r instanceof K)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Rt(n,new K(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=ma(n.state,e);return i&&i instanceof v?Rt(n,i):!1}else if(!(We&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?v.isSelectable(o)?Rt(n,new v(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):ci?Rt(n,new K(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof v&&r.node.isInline)return Rt(n,new K(e>0?r.$to:r.$from));{let i=ma(n.state,e);return i?Rt(n,i):!1}}}function jo(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ii(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Gn(n,e){return e<0?Ik(n):Nk(n)}function Ik(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(He&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(ii(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Dp(t))break;{let l=t.previousSibling;for(;l&&ii(l,-1);)i=t.parentNode,o=he(l),l=l.previousSibling;if(l)t=l,r=jo(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?ga(n,t,r):i&&ga(n,i,o)}function Nk(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=jo(t),o,s;for(;;)if(r{n.state==i&&bt(n)},50)}function Zh(n,e){let t=n.state.doc.resolve(e);if(!(pe||xp)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ep(n,e,t){let r=n.state.selection;if(r instanceof K&&!r.empty||t.indexOf("s")>-1||We&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=ma(n.state,e);if(s&&s instanceof v)return Rt(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Be?$.near(s,e):$.findFrom(s,e);return l?Rt(n,l):!1}return!1}function tp(n,e){if(!(n.state.selection instanceof K))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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function np(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Ek(n){if(!ke||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;np(n,r,"true"),setTimeout(()=>np(n,r,"false"),20)}return!1}function Ak(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Dk(n,e){let t=e.keyCode,r=Ak(e);if(t==8||We&&t==72&&r=="c")return tp(n,-1)||Gn(n,-1);if(t==46&&!e.shiftKey||We&&t==68&&r=="c")return tp(n,1)||Gn(n,1);if(t==13||t==27)return!0;if(t==37||We&&t==66&&r=="c"){let i=t==37?Zh(n,n.state.selection.from)=="ltr"?-1:1:-1;return Xh(n,i,r)||Gn(n,i)}else if(t==39||We&&t==70&&r=="c"){let i=t==39?Zh(n,n.state.selection.from)=="ltr"?1:-1:1;return Xh(n,i,r)||Gn(n,i)}else{if(t==38||We&&t==80&&r=="c")return ep(n,-1,r)||Gn(n,-1);if(t==40||We&&t==78&&r=="c")return Ek(n)||ep(n,1,r)||Gn(n,1);if(r==(We?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ta(n,e){n.someProp("transformCopied",h=>{e=h(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let h=r.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let s=n.someProp("clipboardSerializer")||Ut.fromSchema(n.state.schema),l=zp(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=Lp[u.nodeName.toLowerCase()]);){for(let h=c.length-1;h>=0;h--){let d=l.createElement(c[h]);for(;a.firstChild;)d.appendChild(a.firstChild);a.appendChild(d),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let p=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,`
+
+`);return{dom:a,text:p,slice:e}}function Rp(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=!!e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",p=>{e=p(e,o||r,n)}),o)return l=new T(M.from(n.state.schema.text(e.replace(/\r\n?/g,`
+`))),0,0),n.someProp("transformPasted",p=>{l=p(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",p=>p(e,i,r,n));if(f)l=f;else{let p=i.marks(),{schema:h}=n.state,d=Ut.fromSchema(h);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(y=>{let x=s.appendChild(document.createElement("p"));y&&x.appendChild(d.serializeNode(h.text(y,p)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=Bk(t),ci&&Lk(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let p=s.firstChild;for(;p&&p.nodeType!=1;)p=p.nextSibling;if(!p)break;s=p}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Jt.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(p){return p.nodeName=="BR"&&!p.nextSibling&&p.parentNode&&!Rk.test(p.parentNode.nodeName)?{ignore:!0}:null}})),c)l=zk(rp(l,+c[1],+c[2]),c[4]);else if(l=T.maxOpen(vk(l.content,i),!0),l.openStart||l.openEnd){let f=0,p=0;for(let h=l.content.firstChild;f{l=f(l,n,a)}),l}var Rk=/^(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 vk(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&Pp(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=Bp(s[s.length-1],o.length));let c=vp(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return M.from(s)}return n}function vp(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,M.from(n));return n}function Pp(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(M.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function rp(n,e,t){return et})),ra.createHTML(n)):n}function Bk(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=zp().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Lp[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>""+o+">").reverse().join("")),t.innerHTML=Pk(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=M.from(a.create(r[l+1],i)),o++,s++}return new T(i,o,s)}var Me={},Ie={},Fk={touchstart:!0,touchmove:!0},xa=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function _k(n){for(let e in Me){let t=Me[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{$k(n,r)&&!Oa(n,r)&&(n.editable||!(r.type in Ie))&&t(n,r)},Fk[e]?{passive:!0}:void 0)}ke&&n.dom.addEventListener("input",()=>null),ka(n)}function vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Vk(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 ka(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Oa(n,r))})}function Oa(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function $k(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 Wk(n,e){!Oa(n,e)&&Me[e.type]&&(n.editable||!(e.type in Ie))&&Me[e.type](n,e)}Ie.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!_p(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(kt&&pe&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Zn&&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,fn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Dk(n,t)?t.preventDefault():vt(n,"key")};Ie.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Ie.keypress=(n,e)=>{let t=e;if(_p(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||We&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof K)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),o=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i,o))&&n.dispatch(o()),t.preventDefault()}};function Qo(n){return{left:n.clientX,top:n.clientY}}function jk(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Ea(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Yn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Hk(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&v.isSelectable(r)?(Yn(n,new v(t),"pointer"),!0):!1}function qk(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof v&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(v.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Yn(n,v.create(n.state.doc,i),"pointer"),!0):!1}function Kk(n,e,t,r,i){return Ea(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?qk(n,t):Hk(n,t))}function Jk(n,e,t,r){return Ea(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Uk(n,e,t,r){return Ea(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Gk(n,t,r)}function Gk(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Yn(n,K.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Yn(n,K.create(r,l+1,l+1+s.content.size),"pointer");else if(v.isSelectable(s))Yn(n,v.create(r,l),"pointer");else continue;return!0}}function Aa(n){return Ho(n)}var Fp=We?"metaKey":"ctrlKey";Me.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Aa(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&jk(t,n.input.lastClick)&&!t[Fp]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o,button:t.button};let s=n.posAtCoords(Qo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new ba(n,s,t,!!r)):(o=="doubleClick"?Jk:Uk)(n,s.pos,s.inside,t)?t.preventDefault():vt(n,"pointer"))};var ba=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[Fp],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let c=e.state.doc.resolve(t.pos);o=c.parent,s=c.depth?c.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof v&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&He&&!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(()=>bt(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(Qo(e))),this.updateAllowDefault(e),this.allowDefault||!t?vt(this.view,"pointer"):Kk(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ke&&this.mightDrag&&!this.mightDrag.node.isAtom||pe&&!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)?(Yn(this.view,$.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(),Aa(n),vt(n,"pointer")};Me.touchmove=n=>{n.input.lastTouch=Date.now(),vt(n,"pointer")};Me.contextmenu=n=>Aa(n);function _p(n,e){return n.composing?!0:ke&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var Qk=kt?5e3:-1;Ie.compositionstart=Ie.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof K&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||pe&&xp&&Yk(n)))n.markCursor=n.state.storedMarks||t.marks(),Ho(n,!0),n.markCursor=null;else if(Ho(n,!e.selection.empty),He&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Vp(n,Qk)};function Yk(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let r=e.childNodes[t];return r.nodeType==1&&r.contentEditable=="false"}Ie.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.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Vp(n,20))};function Vp(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Ho(n),e))}function $p(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Zk());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Xk(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Gx(e.focusNode,e.focusOffset),r=Qx(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;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 Zk(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Ho(n,e=!1){if(!(kt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),$p(n),e||n.docView&&n.docView.dirty){let t=Ia(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function eb(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 oi=Oe&&Pt<15||Zn&&ek<604;Me.copy=Ie.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=oi?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Ta(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):eb(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function tb(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function nb(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?si(n,r.value,null,i,e):si(n,r.textContent,r.innerHTML,i,e)},50)}function si(n,e,t,r,i){let o=Rp(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||T.empty)))return!0;if(!o)return!1;let s=tb(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Wp(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," "):""}Ie.paste=(n,e)=>{let t=e;if(n.composing&&!kt)return;let r=oi?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&si(n,Wp(r),r.getData("text/html"),i,t)?t.preventDefault():nb(n,t)};var qo=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},rb=We?"altKey":"ctrlKey";function jp(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[rb]}Me.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(Qo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof v?i.to-1:i.to))){if(r&&r.mightDrag)s=v.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=v.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:u,slice:c}=Ta(n,l);(!t.dataTransfer.files.length||!pe||yp>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(oi?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",oi||t.dataTransfer.setData("text/plain",u),n.dragging=new qo(c,jp(n,t),s)};Me.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Ie.dragover=Ie.dragenter=(n,e)=>e.preventDefault();Ie.drop=(n,e)=>{try{ib(n,e,n.dragging)}finally{n.dragging=null}};function ib(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(Qo(e));if(!r)return;let i=n.state.doc.resolve(r.pos),o=t&&t.slice;o?n.someProp("transformPasted",h=>{o=h(o,n,!1)}):o=Rp(n,Wp(e.dataTransfer),oi?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(t&&jp(n,e));if(n.someProp("handleDrop",h=>h(n,e,o||T.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let l=o?Ac(n.state.doc,i.pos,o):i.pos;l==null&&(l=i.pos);let a=n.state.tr;if(s){let{node:h}=t;h?h.replace(a):a.deleteSelection()}let u=a.mapping.map(l),c=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(c?a.replaceRangeWith(u,u,o.content.firstChild):a.replaceRange(u,u,o),a.doc.eq(f))return;let p=a.doc.resolve(u);if(c&&v.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new v(p));else{let h=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((d,y,x,k)=>h=k),a.setSelection(Na(n,p,a.doc.resolve(h)))}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())&&bt(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(pe&&kt&&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",o=>o(n,fn(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 Ie)Me[n]=Ie[n];function li(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 Ko=class n{constructor(e,t){this.toDOM=e,this.spec=t||mn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Xe(o-r,o-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&&li(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},dn=class n{constructor(e,t){this.attrs=e,this.spec=t||mn}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new Xe(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==xe||e.maps.length==0?this:this.mapInner(e,t,0,0,r||mn)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=qp(t,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof dn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,t,mn));return n.from(r)}forChild(e,t){if(t.isLeaf)return Ce.empty;let r=[];for(let i=0;it instanceof Ce)?e:e.reduce((t,r)=>t.concat(r instanceof Ce?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let x=y-d-(h-p);for(let k=0;kE+c-f)continue;let C=l[k]+c-f;h>=C?l[k+1]=p<=C?-2:-1:p>=c&&x&&(l[k]+=x,l[k+1]+=x)}f+=x}),c=t.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let p=t.map(n[u+1]+o,-1),h=p-i,{index:d,offset:y}=r.content.findIndex(f),x=r.maybeChild(d);if(x&&y==f&&y+x.nodeSize==h){let k=l[u+2].mapInner(t,x,c+1,n[u]+o+1,s);k!=xe?(l[u]=f,l[u+1]=h,l[u+2]=k):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=sb(l,n,e,t,i,o,s),c=Uo(u,r,0,s);e=c.local;for(let f=0;ft&&s.to{let u=qp(n,l,a+t);if(u){o=!0;let c=Uo(u,l,t+a+1,r);c!=xe&&i.push(a,a+l.nodeSize,c)}});let s=Hp(o?Kp(n):n,-t).sort(gn);for(let l=0;l0;)e++;n.splice(e,0,t)}function ia(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=xe&&e.push(r)}),n.cursorWrapper&&e.push(Ce.create(n.state.doc,[n.cursorWrapper.deco])),Jo.from(e)}var lb={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ab=Oe&&Pt<=11,wa=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}},Ca=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new wa,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,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():ke&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),ab&&(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,lb)),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(Yh(this.view)){if(this.suppressingSelectionUpdates)return bt(this.view);if(Oe&&Pt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&yn(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 o=e.focusNode;o;o=Xn(o))t.add(o);for(let o=e.anchorNode;o;o=Xn(o))if(t.has(o)){r=o;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)&&Yh(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;cc.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let c of a)if(c.nodeName=="BR"&&c.parentNode){let f=c.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&c.parentNode.removeChild(c)}}else if(He&&a.length){let c=a.filter(f=>f.nodeName=="BR");if(c.length==2){let[f,p]=c;f.parentNode&&f.parentNode.parentNode==p.parentNode?p.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let p of c){let h=p.parentNode;h&&h.nodeName=="LI"&&(!f||fb(e,f)!=h)&&p.remove()}}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),ub(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,hb(e,a)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||bt(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 c=0;ci;x--){let k=r.childNodes[x-1],E=k.pmViewDesc;if(k.nodeName=="BR"&&!E){o=x;break}if(!E||E.size)break}let f=n.state.doc,p=n.someProp("domParser")||Jt.fromSchema(n.state.schema),h=f.resolve(s),d=null,y=p.parse(r,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:o,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:db,context:h});if(u&&u[0].pos!=null){let x=u[0].pos,k=u[1]&&u[1].pos;k==null&&(k=x),d={anchor:x+s,head:k+s}}return{doc:y,sel:d,from:s,to:l}}function db(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(ke&&/^(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||ke&&/^(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 mb=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function gb(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let N=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,R=Ia(n,N);if(R&&!n.state.selection.eq(R)){if(pe&&kt&&n.input.lastKeyCode===13&&Date.now()-100Y(n,fn(13,"Enter"))))return;let D=n.state.tr.setSelection(R);N=="pointer"?D.setMeta("pointer",!0):N=="key"&&D.scrollIntoView(),o&&D.setMeta("composition",o),n.dispatch(D)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,u=pb(n,e,t),c=n.state.doc,f=c.slice(u.from,u.to),p,h;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||kt)&&i.some(N=>N.nodeType==1&&!mb.test(N.nodeName))&&(!d||d.endA>=d.endB)&&n.someProp("handleKeyDown",N=>N(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!d)if(r&&a instanceof K&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))d={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let N=up(n,n.state.doc,u.sel);if(N&&!N.eq(n.state.selection)){let R=n.state.tr.setSelection(N);o&&R.setMeta("composition",o),n.dispatch(R)}}return}n.state.selection.fromn.state.selection.from&&d.start<=n.state.selection.from+2&&n.state.selection.from>=u.from?d.start=n.state.selection.from:d.endA=n.state.selection.to-2&&n.state.selection.to<=u.to&&(d.endB+=n.state.selection.to-d.endA,d.endA=n.state.selection.to)),Oe&&Pt<=11&&d.endB==d.start+1&&d.endA==d.start&&d.start>u.from&&u.doc.textBetween(d.start-u.from-1,d.start-u.from+1)==" \xA0"&&(d.start--,d.endA--,d.endB--);let y=u.doc.resolveNoCache(d.start-u.from),x=u.doc.resolveNoCache(d.endB-u.from),k=c.resolve(d.start),E=y.sameParent(x)&&y.parent.inlineContent&&k.end()>=d.endA;if((Zn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(N=>N.nodeName=="DIV"||N.nodeName=="P"))||!E&&y.posN(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>d.start&&xb(c,d.start,d.endA,y,x)&&n.someProp("handleKeyDown",N=>N(n,fn(8,"Backspace")))){kt&&pe&&n.domObserver.suppressSelectionUpdates();return}pe&&d.endB==d.start&&(n.input.lastChromeDelete=Date.now()),kt&&!E&&y.start()!=x.start()&&x.parentOffset==0&&y.depth==x.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==d.endA&&(d.endB-=2,x=u.doc.resolveNoCache(d.endB-u.from),setTimeout(()=>{n.someProp("handleKeyDown",function(N){return N(n,fn(13,"Enter"))})},20));let C=d.start,P=d.endA,F=N=>{let R=N||n.state.tr.replace(C,P,u.doc.slice(d.start-u.from,d.endB-u.from));if(u.sel){let D=up(n,R.doc,u.sel);D&&!(pe&&n.composing&&D.empty&&(d.start!=d.endB||n.input.lastChromeDeletebt(n),20));let N=F(n.state.tr.delete(C,P)),R=c.resolve(d.start).marksAcross(c.resolve(d.endA));R&&N.ensureMarks(R),n.dispatch(N)}else if(d.endA==d.endB&&(b=yb(y.parent.content.cut(y.parentOffset,x.parentOffset),k.parent.content.cut(k.parentOffset,d.endA-k.start())))){let N=F(n.state.tr);b.type=="add"?N.addMark(C,P,b.mark):N.removeMark(C,P,b.mark),n.dispatch(N)}else if(y.parent.child(y.index()).isText&&y.index()==x.index()-(x.textOffset?0:1)){let N=y.parent.textBetween(y.parentOffset,x.parentOffset),R=()=>F(n.state.tr.insertText(N,C,P));n.someProp("handleTextInput",D=>D(n,C,P,N,R))||n.dispatch(R())}else n.dispatch(F());else n.dispatch(F())}function up(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Na(n,e.resolve(t.anchor),e.resolve(t.head))}function yb(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;ct||oa(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function kb(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var ai=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 xa,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(mp),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=pp(this),hp(this),this.nodeViews=dp(this),this.docView=qh(this.state.doc,fp(this),ia(this),this.dom,this),this.domObserver=new Ca(this,(r,i,o,s)=>gb(this,r,i,o,s)),this.domObserver.start(),_k(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&&ka(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(mp),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,o=!1,s=!1;e.storedMarks&&this.composing&&($p(this),s=!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 h=dp(this);Sb(h,this.nodeViews)&&(this.nodeViews=h,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ka(this),this.editable=pp(this),hp(this);let a=ia(this),u=fp(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let p=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&rk(this);if(s){this.domObserver.stop();let h=f&&(Oe||pe)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&bb(i.selection,e.selection);if(f){let d=pe?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Xk(this)),(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=qh(e.doc,u,a,this.dom,this)),d&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Mk(this))?bt(this,h):(Ep(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),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():p&&ik(p)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof v){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&_h(this,t.getBoundingClientRect(),e)}else _h(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(o))==r.node&&(i=o)}this.dragging=new qo(e.slice,e.move,i<0?void 0:v.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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ck(this,e)}coordsAtPos(e,t=1){return Cp(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 mk(this,t||this.state,e)}pasteHTML(e,t){return si(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return si(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Ta(this,e)}destroy(){this.docView&&(Vk(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],ia(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Jx())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Wk(this,e)}domSelectionRange(){let e=this.domSelection();return e?ke&&this.root.nodeType===11&&Xx(this.dom.ownerDocument)==this.dom&&cb(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};ai.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function fp(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"),[Xe.node(0,n.state.doc.content.size,e)]}function hp(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:Xe.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function pp(n){return!n.someProp("editable",e=>e(n.state)===!1)}function bb(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 dp(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 Sb(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 mp(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")}function Ct(n,e){return n.meta={package:"@milkdown/core",group:"System",...e},n}var Gp={text:(n,e,t,r)=>{let i=n.value;return/^[^*_\\]*\s+$/.test(i)?i:t.safe(i,{...r,encode:[]})},strong:(n,e,t,r)=>{let i=n.marker||t.options.strong||"*",o=t.enter("strong"),s=t.createTracker(r),l=s.move(i+i);return l+=s.move(t.containerPhrasing(n,{before:l,after:i,...s.current()})),l+=s.move(i+i),o(),l},emphasis:(n,e,t,r)=>{let i=n.marker||t.options.emphasis||"*",o=t.enter("emphasis"),s=t.createTracker(r),l=s.move(i);return l+=s.move(t.containerPhrasing(n,{before:l,after:i,...s.current()})),l+=s.move(i),o(),l}},Ee=V({},"editorView"),fi=V({},"editorState"),Ra=V([],"initTimer"),Jp=V({},"editor"),cr=V([],"inputRules"),it=V([],"prosePlugins"),fr=V([],"remarkPlugins"),as=V([],"nodeView"),us=V([],"markView"),kn=V(Jr().use(Vn).use(qn),"remark"),tr=V({handlers:Gp,encode:[]},"remarkStringifyOptions"),Yo=$e("ConfigReady");function wb(n){let e=t=>(t.record(Yo),async()=>(await n(t),t.done(Yo),()=>{t.clearTimer(Yo)}));return Ct(e,{displayName:"Config"}),e}var St=$e("InitReady");function Cb(n){let e=t=>(t.inject(Jp,n).inject(it,[]).inject(fr,[]).inject(cr,[]).inject(as,[]).inject(us,[]).inject(tr,{handlers:Gp,encode:[]}).inject(kn,Jr().use(Vn).use(qn)).inject(Ra,[Yo]).record(St),async()=>{await t.waitTimers(Ra);let r=t.get(tr);return t.set(kn,Jr().use(Vn).use(qn,r)),t.done(St),()=>{t.remove(Jp).remove(it).remove(fr).remove(cr).remove(as).remove(us).remove(tr).remove(kn).remove(Ra).clearTimer(St)}});return Ct(e,{displayName:"Init"}),e}var Ae=$e("SchemaReady"),Xo=V([],"schemaTimer"),wt=V({},"schema"),nr=V([],"nodes"),rr=V([],"marks");function Up(n){return{...n,parseDOM:n.parseDOM?.map(e=>({priority:n.priority,...e}))}}var Qp=n=>(n.inject(wt,{}).inject(nr,[]).inject(rr,[]).inject(Xo,[St]).record(Ae),async()=>{await n.waitTimers(Xo);let e=n.get(kn),r=n.get(fr).reduce((l,a)=>l.use(a.plugin,a.options),e);n.set(kn,r);let i=Object.fromEntries(n.get(nr).map(([l,a])=>[l,Up(a)])),o=Object.fromEntries(n.get(rr).map(([l,a])=>[l,Up(a)])),s=new Ki({nodes:i,marks:o});return n.set(wt,s),n.done(Ae),()=>{n.remove(wt).remove(nr).remove(rr).remove(Xo).clearTimer(Ae)}});Ct(Qp,{displayName:"Schema"});var cs=class{constructor(){this.#t=new Cr,this.#e=null,this.setCtx=e=>{this.#e=e},this.chain=()=>{if(this.#e==null)throw zi();let e=this.#e,t=[],r=this.get.bind(this),i={run:()=>{let s=tn(...t),l=e.get(Ee);return s(l.state,l.dispatch,l)},inline:s=>(t.push(s),i),pipe:o.bind(this)};function o(s,l){let a=r(s);return t.push(a(l)),i}return i}}#t;#e;get ctx(){return this.#e}create(e,t){let r=e.create(this.#t.sliceMap);return r.set(t),r}get(e){return this.#t.get(e).get()}remove(e){return this.#t.remove(e)}call(e,t){if(this.#e==null)throw zi();let i=this.get(e)(t),o=this.#e.get(Ee);return i(o.state,o.dispatch,o)}inline(e){if(this.#e==null)throw zi();let t=this.#e.get(Ee);return e(t.state,t.dispatch,t)}};function Yp(n="cmdKey"){return V((()=>()=>!1),n)}var U=V(new cs,"commands"),Zo=V([Ae],"commandsTimer"),ir=$e("CommandsReady"),Xp=n=>{let e=new cs;return e.setCtx(n),n.inject(U,e).inject(Zo,[Ae]).record(ir),async()=>(await n.waitTimers(Zo),n.done(ir),()=>{n.remove(U).remove(Zo).clearTimer(ir)})};Ct(Xp,{displayName:"Commands"});function Mb(n){let e=tn(Oh,to,qc,rl);return n.Backspace=e,n}var fs=class{constructor(){this.#t=null,this.#e=[],this.setCtx=e=>{this.#t=e},this.add=e=>(this.#e.push(e),()=>{this.#e=this.#e.filter(t=>t!==e)}),this.addObjectKeymap=e=>{let t=[];return Object.entries(e).forEach(([r,i])=>{if(typeof i=="function"){let o={key:r,onRun:()=>i};this.#e.push(o),t.push(()=>{this.#e=this.#e.filter(s=>s!==o)})}else this.#e.push(i),t.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}),()=>{t.forEach(r=>r())}},this.addBaseKeymap=()=>{let e=Mb(Qc);return this.addObjectKeymap(e)},this.build=()=>{let e={};return this.#e.forEach(r=>{e[r.key]=[...e[r.key]||[],r]}),Object.fromEntries(Object.entries(e).map(([r,i])=>{let o=i.sort((l,a)=>(a.priority??50)-(l.priority??50));return[r,(l,a,u)=>{let c=this.#t;if(c==null)throw On();let f=o.map(h=>h.onRun(c));return tn(...f)(l,a,u)}]}))}}#t;#e;get ctx(){return this.#t}},di=V(new fs,"keymap"),va=V([Ae],"keymapTimer"),or=$e("KeymapReady"),Ib=n=>{let e=new fs;return e.setCtx(n),n.inject(di,e).inject(va,[Ae]).record(or),async()=>(await n.waitTimers(va),n.done(or),()=>{n.remove(di).remove(va).clearTimer(or)})},es=$e("ParserReady"),Zp=(()=>{throw On()}),hi=V(Zp,"parser"),Pa=V([],"parserTimer"),ed=n=>(n.inject(hi,Zp).inject(Pa,[Ae]).record(es),async()=>{await n.waitTimers(Pa);let e=n.get(kn),t=n.get(wt);return n.set(hi,Nh.create(t,e)),n.done(es),()=>{n.remove(hi).remove(Pa).clearTimer(es)}});Ct(ed,{displayName:"Parser"});var sr=$e("SerializerReady"),Ba=V([],"serializerTimer"),td=(()=>{throw On()}),lr=V(td,"serializer"),nd=n=>(n.inject(lr,td).inject(Ba,[Ae]).record(sr),async()=>{await n.waitTimers(Ba);let e=n.get(kn),t=n.get(wt);return n.set(lr,Th.create(t,e)),n.done(sr),()=>{n.remove(lr).remove(Ba).clearTimer(sr)}});Ct(nd,{displayName:"Serializer"});var ar=V("","defaultValue"),ts=V(n=>n,"stateOptions"),ns=V([],"editorStateTimer"),rs=$e("EditorStateReady");function Nb(n,e,t){if(typeof n=="string")return e(n);if(n.type==="html")return Jt.fromSchema(t).parse(n.dom);if(n.type==="json")return Te.fromJSON(t,n.value);throw Wu(n)}var Tb=new se("MILKDOWN_STATE_TRACKER"),rd=n=>(n.inject(ar,"").inject(fi,{}).inject(ts,e=>e).inject(ns,[es,sr,ir,or]).record(rs),async()=>{await n.waitTimers(ns);let e=n.get(wt),t=n.get(hi),r=n.get(cr),i=n.get(ts),o=n.get(it),s=n.get(ar),l=Nb(s,t,e),a=n.get(di),u=a.addBaseKeymap(),c=[...o,new ie({key:Tb,state:{init:()=>{},apply:(h,d,y,x)=>{n.set(fi,x)}}}),Rh({rules:r}),Lh(a.build())];n.set(it,c);let f=i({schema:e,doc:l,plugins:c}),p=eo.create(f);return n.set(fi,p),n.done(rs),()=>{u(),n.remove(ar).remove(fi).remove(ts).remove(ns).clearTimer(rs)}});Ct(rd,{displayName:"EditorState"});var hs=V([],"pasteRule"),is=V([Ae],"pasteRuleTimer"),ss=$e("PasteRuleReady"),id=n=>(n.inject(hs,[]).inject(is,[Ae]).record(ss),async()=>(await n.waitTimers(is),n.done(ss),()=>{n.remove(hs).remove(is).clearTimer(ss)}));Ct(id,{displayName:"PasteRule"});var pi=$e("EditorViewReady"),ls=V([],"editorViewTimer"),La=V({},"editorViewOptions"),ur=V(null,"root"),za=V(null,"rootDOM"),Fa=V({},"rootAttrs");function Ob(n,e){let t=document.createElement("div");t.className="milkdown",n.appendChild(t),e.set(za,t);let r=e.get(Fa);return Object.entries(r).forEach(([i,o])=>t.setAttribute(i,o)),t}function Eb(n){n.classList.add("editor"),n.setAttribute("role","textbox")}var Ab=new se("MILKDOWN_VIEW_CLEAR"),od=n=>(n.inject(ur,document.body).inject(Ee,{}).inject(La,{}).inject(za,null).inject(Fa,{}).inject(ls,[rs,ss]).record(pi),async()=>{await n.wait(St);let e=n.get(ur)||document.body,t=typeof e=="string"?document.querySelector(e):e;n.update(it,a=>[new ie({key:Ab,view:u=>{let c=t?Ob(t,n):void 0;return(()=>{if(c&&t){let p=u.dom;t.replaceChild(c,p),c.appendChild(p)}})(),{destroy:()=>{c?.parentNode&&c?.parentNode.replaceChild(u.dom,c),c?.remove()}}}}),...a]),await n.waitTimers(ls);let r=n.get(fi),i=n.get(La),o=Object.fromEntries(n.get(as)),s=Object.fromEntries(n.get(us)),l=new ai(t,{state:r,nodeViews:o,markViews:s,transformPasted:(a,u,c)=>(n.get(hs).sort((f,p)=>(p.priority??50)-(f.priority??50)).map(f=>f.run).forEach(f=>{a=f(a,u,c)}),a),...i});return Eb(l.dom),n.set(Ee,l),n.done(pi),()=>{l?.destroy(),n.remove(ur).remove(Ee).remove(La).remove(za).remove(Fa).remove(ls).clearTimer(pi)}});Ct(od,{displayName:"EditorView"});var mi=class n{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Cr,this.#o=new _i,this.#i=new Map,this.#l=new Map,this.#a=new Fi(this.#s,this.#o),this.#p=()=>{let e=wb(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),t=[Qp,ed,nd,Xp,Ib,id,rd,od,Cb(this),e];this.#c(t,this.#l)},this.#c=(e,t)=>{e.forEach(r=>{let i=this.#a.produce(this.#t?r.meta:void 0),o=r(i);t.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#f=(e,t=!1)=>Promise.all([e].flat().map(async r=>{let o=this.#i.get(r)?.cleanup;return t?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof o=="function"?o():o})),this.#d=async()=>{await Promise.all([...this.#l.entries()].map(async([e,{cleanup:t}])=>typeof t=="function"?t():t)),this.#l.clear()},this.#u=e=>{this.#e=e,this.#n(e)},this.#h=e=>[...e.entries()].map(async([t,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(t,{ctx:i,handler:o,cleanup:s})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#r.push(e),this),this.removeConfig=e=>(this.#r=this.#r.filter(t=>t!==e),this),this.use=e=>{let t=[e].flat();return t.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(t,this.#i),this},this.remove=async e=>this.#e==="OnCreate"?(console.warn("[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code."),new Promise(t=>{setTimeout(()=>{t(this.remove(e))},50)})):(await this.#f([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#u("OnCreate"),this.#p(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#h(this.#l),this.#h(this.#i)].flat()),this.#u("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(t=>{setTimeout(()=>{t(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#u("OnDestroy"),await this.#f([...this.#i.keys()],e),await this.#d(),this.#u("Destroyed"),this),this.action=e=>e(this.#a),this.inspect=()=>this.#t?[...this.#l.values(),...this.#i.values()].map(({ctx:e})=>e?.inspector?.read()).filter(e=>!!e):(console.warn("[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first."),[])}static make(){return new n}#t;#e;#r;#n;#s;#o;#i;#l;#a;#p;#c;#f;#d;#u;#h;get ctx(){return this.#a}get status(){return this.#e}};var Db=n=>crypto.getRandomValues(new Uint8Array(n)),Rb=(n,e,t)=>{let r=(2<{let s="";for(;;){let l=t(i),a=i|0;for(;a--;)if(s+=n[l[a]&r]||"",s.length>=o)return s}}},sd=(n,e=21)=>Rb(n,e|0,Db);var _T=sd("abcedfghicklmn",10);function J(n,e){let t=Yp(n),r=i=>async()=>{r.key=t,await i.wait(ir);let o=e(i);return i.get(U).create(t,o),r.run=s=>i.get(U).call(n,s),()=>{i.get(U).remove(t)}};return r}function Ke(n){let e=t=>async()=>{await t.wait(Ae);let r=n(t);return t.update(cr,i=>[...i,r]),e.inputRule=r,()=>{t.update(cr,i=>i.filter(o=>o!==r))}};return e}function vb(n,e){let t=r=>async()=>{let i=e(r);return r.update(rr,o=>[...o.filter(s=>s[0]!==n),[n,i]]),t.id=n,t.schema=i,()=>{r.update(rr,o=>o.filter(([s])=>s!==n))}};return t.type=r=>{let i=r.get(wt).marks[n];if(!i)throw Gu(n);return i},t}function ps(n,e){let t=r=>async()=>{let i=e(r);return r.update(nr,o=>[...o.filter(s=>s[0]!==n),[n,i]]),t.id=n,t.schema=i,()=>{r.update(nr,o=>o.filter(([s])=>s!==n))}};return t.type=r=>{let i=r.get(wt).nodes[n];if(!i)throw Uu(n);return i},t}function zt(n){let e,t=r=>async()=>(await r.wait(Ae),e=n(r),r.update(it,i=>[...i,e]),()=>{r.update(it,i=>i.filter(o=>o!==e))});return t.plugin=()=>e,t.key=()=>e.spec.key,t}function Pb(n){let e=t=>async()=>{await t.wait(or);let r=t.get(di),i=n(t),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function Ze(n,e){let t=V(n,e),r=i=>(i.inject(t),()=>()=>{i.remove(t)});return r.key=t,r}function Fe(n,e){let t=Ze(e,n),r=ps(n,o=>o.get(t.key)(o)),i=[t,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=t,i.key=t.key,i.extendSchema=o=>{let s=o(e);return Fe(n,s)},i}function hr(n,e){let t=Ze(e,n),r=vb(n,o=>o.get(t.key)(o)),i=[t,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=t,i.key=t.key,i.extendSchema=o=>{let s=o(e);return hr(n,s)},i}function De(n,e){let t=Object.fromEntries(Object.entries(e).map(([s,{shortcuts:l,priority:a}])=>[s,{shortcuts:l,priority:a}])),r=Ze(t,`${n}Keymap`),i=Pb(s=>{let l=s.get(r.key),a=Object.entries(e).flatMap(([u,{command:c}])=>{let f=l[u],p=[f.shortcuts].flat(),h=f.priority;return p.map(d=>[d,{key:d,onRun:c,priority:h}])});return Object.fromEntries(a)}),o=[r,i];return o.ctx=r,o.shortcuts=i,o.key=r.key,o.keymap=i.keymap,o}var Je=(n,e=()=>({}))=>Ze(e,`${n}Attr`),gi=(n,e=()=>({}))=>Ze(e,`${n}Attr`);function bn(n,e,t){let r=Ze(t??{},n),i=s=>async()=>{await s.wait(St);let a={plugin:e(s),options:s.get(r.key)};return s.update(fr,u=>[...u,a]),()=>{s.update(fr,u=>u.filter(c=>c!==a))}},o=[r,i];return o.id=n,o.plugin=i,o.options=r,o}function ld(n,e){return t=>t.get(U).call(n,e)}function ad(n,e){return function(t,r){let{$from:i,$to:o,node:s}=t.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let l=i.node(-1);if(l.type!=n)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=n||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=M.empty,p=i.index(-1)?1:i.index(-2)?2:3;for(let k=i.depth-p;k>=i.depth-3;k--)f=M.from(i.node(k).copy(f));let h=i.indexAfter(-1){if(x>-1)return!1;k.isTextblock&&k.content.size==0&&(x=E+1)}),x>-1&&y.setSelection($.near(y.doc.resolve(x))),r(y.scrollIntoView())}return!0}let a=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,u=t.tr.delete(i.pos,o.pos),c=a?[e?{type:n,attrs:e}:null,{type:a}]:void 0;return Xt(u.doc,i.pos,2,c)?(r&&r(u.split(i.pos,2,c).scrollIntoView()),!0):!1}}function ud(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?Bb(e,t,n,o):Lb(e,t,o):!0:!1}}function Bb(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);oy;d--)h-=i.child(d).nodeSize,r.delete(h-1,h+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,u=o.node(-1),c=o.index(-1);if(!u.canReplace(c+(l?0:1),c+1,s.content.append(a?M.empty:M.from(i))))return!1;let f=o.pos,p=f+s.nodeSize;return r.step(new ce(f-(l?1:0),p+(a?1:0),f+1,p-1,new T((l?M.empty:M.from(i.copy(M.empty))).append(a?M.empty:M.from(i.copy(M.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function cd(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,u=>u.childCount>0&&u.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,a=l.child(s-1);if(a.type!=n)return!1;if(t){let u=a.lastChild&&a.lastChild.type==l.type,c=M.from(u?n.create():null),f=new T(M.from(n.create(null,M.from(l.type.create(null,c)))),u?3:1,0),p=o.start,h=o.end;t(e.tr.step(new ce(p-(u?3:1),h,p,h,f,1,!0)).scrollIntoView())}return!0}}function _a(n){let e=new Map;if(!n||!n.type)throw new Error("mdast-util-definitions expected node");return Qe(n,"definition",function(r){let i=fd(r.identifier);i&&!e.get(i)&&e.set(i,r)}),t;function t(r){let i=fd(r);return e.get(i)}}function fd(n){return String(n||"").toUpperCase()}function ds(){return function(n){let e=_a(n);Qe(n,function(t,r,i){if(t.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[an,r];if(t.type==="imageReference"||t.type==="linkReference"){let o=e(t.identifier);if(o&&i&&typeof r=="number")return i.children[r]=t.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:t.alt}:{type:"link",url:o.url,title:o.title,children:t.children},[an,r]}})}}function hd(n,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){n.next(e.content);return}let r=[];e.content.forEach((i,o,s)=>{s!==e.childCount-1&&r.push(i)}),n.next(M.fromArray(r))}function S(n,e){return Object.assign(n,{meta:{package:"@milkdown/preset-commonmark",...e}}),n}var Va=gi("emphasis");S(Va,{displayName:"Attr",group:"Emphasis"});var dr=hr("emphasis",n=>({attrs:{marker:{default:n.get(tr).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",n.get(Va.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,t,r)=>{e.openMark(r,{marker:t.marker}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,t)=>{e.withMark(t,"emphasis",void 0,{marker:t.attrs.marker})}}}));S(dr.mark,{displayName:"MarkSchema",group:"Emphasis"});S(dr.ctx,{displayName:"MarkSchemaCtx",group:"Emphasis"});var yi=J("ToggleEmphasis",n=>()=>ro(dr.type(n)));S(yi,{displayName:"Command",group:"Emphasis"});var pd=Ke(n=>ti(/(?:^|[^*])\*([^*]+)\*$/,dr.type(n),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:t+1}}));S(pd,{displayName:"InputRule|Star",group:"Emphasis"});var dd=Ke(n=>ti(/\b_(?![_\s])(.*?[^_\s])_\b/,dr.type(n),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:t+1}}));S(dd,{displayName:"InputRule|Underscore",group:"Emphasis"});var $a=De("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:n=>{let e=n.get(U);return()=>e.call(yi.key)}}});S($a.ctx,{displayName:"KeymapCtx",group:"Emphasis"});S($a.shortcuts,{displayName:"Keymap",group:"Emphasis"});var Wa=gi("strong");S(Wa,{displayName:"Attr",group:"Strong"});var xi=hr("strong",n=>({attrs:{marker:{default:n.get(tr).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:e=>e.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:e=>e==="bold"},{style:"font-weight=400",clearMark:e=>e.type.name=="strong"},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:e=>["strong",n.get(Wa.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,t,r)=>{e.openMark(r,{marker:t.marker}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,t)=>{e.withMark(t,"strong",void 0,{marker:t.attrs.marker})}}}));S(xi.mark,{displayName:"MarkSchema",group:"Strong"});S(xi.ctx,{displayName:"MarkSchemaCtx",group:"Strong"});var ki=J("ToggleStrong",n=>()=>ro(xi.type(n)));S(ki,{displayName:"Command",group:"Strong"});var md=Ke(n=>ti(new RegExp("(?({marker:e[0].startsWith("*")?"*":"_"})}));S(md,{displayName:"InputRule",group:"Strong"});var ja=De("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:n=>{let e=n.get(U);return()=>e.call(ki.key)}}});S(ja.ctx,{displayName:"KeymapCtx",group:"Strong"});S(ja.shortcuts,{displayName:"Keymap",group:"Strong"});var Ha=gi("inlineCode");S(Ha,{displayName:"Attr",group:"InlineCode"});var Ft=hr("inlineCode",n=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",n.get(Ha.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,t,r)=>{e.openMark(r),e.addText(t.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,t,r)=>{e.withMark(t,"inlineCode",r.text||"")}}}));S(Ft.mark,{displayName:"MarkSchema",group:"InlineCode"});S(Ft.ctx,{displayName:"MarkSchemaCtx",group:"InlineCode"});var bi=J("ToggleInlineCode",n=>()=>(e,t)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,Ft.type(n))?(t?.(i.removeMark(o,s,Ft.type(n))),!0):(Object.keys(e.schema.marks).filter(u=>u!==Ft.type.name).map(u=>e.schema.marks[u]).forEach(u=>{i.removeMark(o,s,u)}),t?.(i.addMark(o,s,Ft.type(n).create())),!0)});S(bi,{displayName:"Command",group:"InlineCode"});var gd=Ke(n=>ti(/(?:`)([^`]+)(?:`)$/,Ft.type(n)));S(gd,{displayName:"InputRule",group:"InlineCode"});var qa=De("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:n=>{let e=n.get(U);return()=>e.call(bi.key)}}});S(qa.ctx,{displayName:"KeymapCtx",group:"InlineCode"});S(qa.shortcuts,{displayName:"Keymap",group:"InlineCode"});var Ka=gi("link");S(Ka,{displayName:"Attr",group:"Link"});var pr=hr("link",n=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Mt(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...n.get(Ka.key)(e),...e.attrs}],parseMarkdown:{match:e=>e.type==="link",runner:(e,t,r)=>{let i=t.url,o=t.title;e.openMark(r,{href:i,title:o}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,t)=>{e.withMark(t,"link",void 0,{title:t.attrs.title,url:t.attrs.href})}}}));S(pr.mark,{displayName:"MarkSchema",group:"Link"});var yd=J("ToggleLink",n=>(e={})=>ro(pr.type(n),e));S(yd,{displayName:"Command",group:"Link"});var xd=J("UpdateLink",n=>(e={})=>(t,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=t,{from:l,to:a}=s;if(t.doc.nodesBetween(l,l===a?a+1:a,(d,y)=>{if(pr.type(n).isInSet(d.marks))return i=d,o=y,!1}),!i)return!1;let u=i.marks.find(({type:d})=>d===pr.type(n));if(!u)return!1;let c=o,f=o+i.nodeSize,{tr:p}=t,h=pr.type(n).create({...u.attrs,...e});return h?(r(p.removeMark(c,f,u).addMark(c,f,h).setSelection(new K(p.selection.$anchor)).scrollIntoView()),!0):!1});S(xd,{displayName:"Command",group:"Link"});var kd=ps("doc",()=>({content:"block+",parseMarkdown:{match:({type:n})=>n==="root",runner:(n,e,t)=>{n.injectRoot(e,t)}},toMarkdown:{match:n=>n.type.name==="doc",runner:(n,e)=>{n.openNode("root"),n.next(e.content)}}}));S(kd,{displayName:"NodeSchema",group:"Doc"});function zb(n){return jr(n,e=>e.type==="html"&&["
","
","
","
"].includes(e.value?.trim()),(e,t)=>{if(!t.length)return;let r=t[t.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var gs=bn("remark-preserve-empty-line",()=>()=>zb);S(gs.plugin,{displayName:"Remark",group:"Remark"});S(gs.options,{displayName:"RemarkConfig",group:"Remark"});var Ja=Je("paragraph");S(Ja,{displayName:"Attr",group:"Paragraph"});var wn=Fe("paragraph",n=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",n.get(Ja.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,t,r)=>{e.openNode(r),t.children?e.next(t.children):e.addText(t.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,t)=>{let i=n.get(Ee).state?.doc.lastChild;e.openNode("paragraph"),(!t.content||t.content.size===0)&&t!==i&&Fb(n)?e.addNode("html",void 0,"
"):hd(e,t),e.closeNode()}}}));function Fb(n){let e=!1;try{n.get(gs.id),e=!0}catch{e=!1}return e}S(wn.node,{displayName:"NodeSchema",group:"Paragraph"});S(wn.ctx,{displayName:"NodeSchemaCtx",group:"Paragraph"});var Si=J("TurnIntoText",n=>()=>Ln(wn.type(n)));S(Si,{displayName:"Command",group:"Paragraph"});var Ua=De("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:n=>{let e=n.get(U);return()=>e.call(Si.key)}}});S(Ua.ctx,{displayName:"KeymapCtx",group:"Paragraph"});S(Ua.shortcuts,{displayName:"Keymap",group:"Paragraph"});var _b=Array(6).fill(0).map((n,e)=>e+1);function Vb(n){return n.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var ys=Ze(Vb,"headingIdGenerator");S(ys,{displayName:"Ctx",group:"Heading"});var Ga=Je("heading");S(Ga,{displayName:"Attr",group:"Heading"});var Cn=Fe("heading",n=>{let e=n.get(ys.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:_b.map(t=>({tag:`h${t}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw Mt(r);return{level:t,id:r.id}}})),toDOM:t=>[`h${t.attrs.level}`,{...n.get(Ga.key)(t),id:t.attrs.id||e(t)},0],parseMarkdown:{match:({type:t})=>t==="heading",runner:(t,r,i)=>{let o=r.depth;t.openNode(i,{level:o}),t.next(r.children),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="heading",runner:(t,r)=>{t.openNode("heading",void 0,{depth:r.attrs.level}),hd(t,r),t.closeNode()}}}});S(Cn.node,{displayName:"NodeSchema",group:"Heading"});S(Cn.ctx,{displayName:"NodeSchemaCtx",group:"Heading"});var bd=Ke(n=>Gl(/^(?#+)\s$/,Cn.type(n),e=>{let t=e.groups?.hashes?.length||0,r=n.get(Ee),{$from:i}=r.state.selection,o=i.node();if(o.type.name==="heading"){let s=Number(o.attrs.level)+Number(t);return s>6&&(s=6),{level:s}}return{level:t}}));S(bd,{displayName:"InputRule",group:"Heading"});var ot=J("WrapInHeading",n=>e=>(e??=1,e<1?Ln(wn.type(n)):Ln(Cn.type(n),{level:e})));S(ot,{displayName:"Command",group:"Heading"});var Qa=J("DowngradeHeading",n=>()=>(e,t,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==Cn.type(n)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(t?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):Ln(wn.type(n))(e,t,r)});S(Qa,{displayName:"Command",group:"Heading"});var Ya=De("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:n=>{let e=n.get(U);return()=>e.call(ot.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:n=>{let e=n.get(U);return()=>e.call(ot.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:n=>{let e=n.get(U);return()=>e.call(ot.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:n=>{let e=n.get(U);return()=>e.call(ot.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:n=>{let e=n.get(U);return()=>e.call(ot.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:n=>{let e=n.get(U);return()=>e.call(ot.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:n=>{let e=n.get(U);return()=>e.call(Qa.key)}}});S(Ya.ctx,{displayName:"KeymapCtx",group:"Heading"});S(Ya.shortcuts,{displayName:"Keymap",group:"Heading"});var Xa=Je("blockquote");S(Xa,{displayName:"Attr",group:"Blockquote"});var wi=Fe("blockquote",n=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",n.get(Xa.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,t,r)=>{e.openNode(r).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,t)=>{e.openNode("blockquote").next(t.content).closeNode()}}}));S(wi.node,{displayName:"NodeSchema",group:"Blockquote"});S(wi.ctx,{displayName:"NodeSchemaCtx",group:"Blockquote"});var Sd=Ke(n=>Lo(/^\s*>\s$/,wi.type(n)));S(Sd,{displayName:"InputRule",group:"Blockquote"});var Ci=J("WrapInBlockquote",n=>()=>no(wi.type(n)));S(Ci,{displayName:"Command",group:"Blockquote"});var Za=De("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:n=>{let e=n.get(U);return()=>e.call(Ci.key)}}});S(Za.ctx,{displayName:"KeymapCtx",group:"Blockquote"});S(Za.shortcuts,{displayName:"Keymap",group:"Blockquote"});var eu=Je("codeBlock",()=>({pre:{},code:{}}));S(eu,{displayName:"Attr",group:"CodeBlock"});var Mi=Fe("code_block",n=>({content:"text*",group:"block",marks:"",defining:!0,code:!0,attrs:{language:{default:"",validate:"string"}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Mt(e);return{language:e.dataset.language}}}],toDOM:e=>{let t=n.get(eu.key)(e),r=e.attrs.language,i=r&&r.length>0?{"data-language":r}:void 0;return["pre",{...t.pre,...i},["code",t.code,0]]},parseMarkdown:{match:({type:e})=>e==="code",runner:(e,t,r)=>{let i=t.lang??"",o=t.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,t)=>{e.addNode("code",void 0,t.content.firstChild?.text||"",{lang:t.attrs.language})}}}));S(Mi.node,{displayName:"NodeSchema",group:"CodeBlock"});S(Mi.ctx,{displayName:"NodeSchemaCtx",group:"CodeBlock"});var wd=Ke(n=>Gl(/^```(?[a-z]*)?[\s\n]$/,Mi.type(n),e=>({language:e.groups?.language??""})));S(wd,{displayName:"InputRule",group:"CodeBlock"});var tu=J("CreateCodeBlock",n=>(e="")=>Ln(Mi.type(n),{language:e}));S(tu,{displayName:"Command",group:"CodeBlock"});var $b=J("UpdateCodeBlockLanguage",()=>({pos:n,language:e}={pos:-1,language:""})=>(t,r)=>n>=0?(r?.(t.tr.setNodeAttribute(n,"language",e)),!0):!1);S($b,{displayName:"Command",group:"CodeBlock"});var nu=De("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:n=>{let e=n.get(U);return()=>e.call(tu.key)}}});S(nu.ctx,{displayName:"KeymapCtx",group:"CodeBlock"});S(nu.shortcuts,{displayName:"Keymap",group:"CodeBlock"});var ru=Je("image");S(ru,{displayName:"Attr",group:"Image"});var mr=Fe("image",n=>({inline:!0,group:"inline",selectable:!0,draggable:!0,marks:"",atom:!0,defining:!0,isolating:!0,attrs:{src:{default:"",validate:"string"},alt:{default:"",validate:"string"},title:{default:"",validate:"string"}},parseDOM:[{tag:"img[src]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Mt(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...n.get(ru.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,t,r)=>{let i=t.url,o=t.alt,s=t.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,t)=>{e.addNode("image",void 0,void 0,{title:t.attrs.title,url:t.attrs.src,alt:t.attrs.alt})}}}));S(mr.node,{displayName:"NodeSchema",group:"Image"});S(mr.ctx,{displayName:"NodeSchemaCtx",group:"Image"});var xs=J("InsertImage",n=>(e={})=>(t,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,l=mr.type(n).create({src:i,alt:o,title:s});return l&&r(t.tr.replaceSelectionWith(l).scrollIntoView()),!0});S(xs,{displayName:"Command",group:"Image"});var Cd=J("UpdateImage",n=>(e={})=>(t,r)=>{let i=vh(t.selection,mr.type(n));if(!i)return!1;let{node:o,pos:s}=i,l={...o.attrs},{src:a,alt:u,title:c}=e;return a!==void 0&&(l.src=a),u!==void 0&&(l.alt=u),c!==void 0&&(l.title=c),r?.(t.tr.setNodeMarkup(s,void 0,l).scrollIntoView()),!0});S(Cd,{displayName:"Command