@kerebron/legacy-compat 0.8.8 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kerebron.cjs +2 -2
- package/dist/kerebron.cjs.map +1 -1
- package/dist/kerebron.js +140 -94
- package/dist/kerebron.js.map +1 -1
- package/package.json +1 -1
package/dist/kerebron.cjs
CHANGED
|
@@ -22,7 +22,7 @@ ${this.yamlService.stringify(e)}
|
|
|
22
22
|
`,`\\n`),e.length<=t?e:e.slice(0,t)+`...`}function nodeToTreeStringOutput(e,t,n=0,r=0){let a=``;for(let e=0;e<n;e++)a+=` `;if(Array.isArray(t)){for(let o of t)e.log(a,{node:o,pos:r}),nodeToTreeStringOutput(e,o,n+1,r);return}let o=``;if(`type`in t){o+=` - [${t.type.name}] `,o+=`pos: ${r}, `,o+=`nodeSize: ${t.nodeSize}, `,o+=`epos: ${r+t.nodeSize}, `,t.content&&(o+=`fragment.size: ${t.content.size}, `),e.log(a+o+`
|
|
23
23
|
`,{node:t,pos:r});let n=``;if(t.marks)for(let e of t.marks)n+=`(${e.type.name}), `;n&&e.log(a+` `+n+`
|
|
24
24
|
`,{node:t,pos:r}),t.text&&e.log(a+` "`+trimText(t.text)+`"
|
|
25
|
-
`,{node:t,pos:r})}return t.forEach((t,a)=>{nodeToTreeStringOutput(e,t,n+1,r+a+1)}),e}function nodeToTreeString(e){let t=new SmartOutput;return nodeToTreeStringOutput(t,e),t.toString()}var DummyEditorView=class{_props;directPlugins;nodeViews;prevDirectPlugins=[];pluginViews=[];state;focused=!1;constructor(e){this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(checkStateComponent),this.dispatch=this.dispatch.bind(this),this.editable=getEditable(this),this.nodeViews=buildNodeViews(this),this.updatePluginViews()}editable;get composing(){return!1}get dom(){return{addEventListener(){},removeEventListener(){}}}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){let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(checkStateComponent),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,a=!1;if(e.storedMarks&&this.composing,this.state=e,n.plugins!=e.plugins||this._props.plugins!=t.plugins||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=buildNodeViews(this);changedNodeViews(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}this.editable=getEditable(this),r||e.selection.eq(n.selection),this.updatePluginViews(n)}scrollToSelection(){}destroyPluginViews(){let e=this.pluginViews.pop();for(;e;)e.destroy&&e.destroy(),e=this.pluginViews.pop()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let a=this.directPlugins[n].props[e];if(a!=null&&(r=t?t(a):a))return r}let a=this.state.plugins;if(a)for(let n=0;n<a.length;n++){let o=a[n].props[e];if(o!=null&&(r=t?t(o):o))return r}}hasFocus(){return this.focused}focus(){this.focused=!0}destroy(){this.destroyPluginViews()}get isDestroyed(){return!1}dispatchEvent(e){}};DummyEditorView.prototype.dispatch=function(e){let t=this.props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function getEditable(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function buildNodeViews(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function changedNodeViews(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function checkStateComponent(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}function createNodeFromObject(e,t,n){try{let r=t.nodeFromJSON(e);return n?.errorOnInvalidContent&&r.check(),r}catch(r){if(n?.errorOnInvalidContent)throw Error(`Invalid JSON content: `+r.message,{cause:r});return console.warn(`Invalid content.`,`Passed value:`,e,`Error:`,r),t.topNodeType.createAndFill(null,[])}}function defaultUi(e){return{showMessage(e){globalThis.alert(e)},showError(e){globalThis.alert(e.message),console.error(e)},focus(){},select({anchor:e,scrollIntoView:t,userEvent:n}){}}}var Container=class{items=new Map;register(e,t){this.items.set(e,t)}resolve(e){return this.items.get(e)}};function ensureDocSchema(e,t){if(e.type.schema===t)return e;let n=e.toJSON();return Node$3.fromJSON(t,n)}var CoreEditor=class e extends EventTarget{schema;extensionManager;config;commandManager;view;state;ui=defaultUi(this);linkListener;linkSource;ci=new Container;version=0;constructor(e,t,n){super(),this.schema=t,this.extensionManager=n,this.config={...e},this.commandManager=new CommandManager(this)}static create(t){let n=new ExtensionManager(t.editorKits,t.debug),r=n.getSchemaByResolvedExtensions(),a=new e(t,r,n);n.created(a,r);let o=t.content?t.content:r.topNodeType.spec.EMPTY_DOC;return a.createView(o),a.setupPlugins(),a.dispatchEvent(new CustomEvent(`ready`)),a}clone(t){let n=new ExtensionManager(this.extensionManager.editorKits,(t||this.config).debug),r=new e({assetLoad:this.config.assetLoad,...t},this.schema,n);n.created(r,this.schema);let a=this.getJSON(),o=this.state.selection;return r.createView(a,o),r.setupPlugins(),r}getExtension(e){return this.ci.resolve(e)}get run(){return this.commandManager.run}get commandFactories(){return this.commandManager.commandFactories}chain(e){return this.commandManager.createChain(e)}can(e){return this.commandManager.createCan(e)}link(e){if(e===this)throw Error(`You cannot chain editor to itself`);this.unlink(),this.state=EditorState.create({doc:e.getDocument()});let{commandFactories:t}=this.commandManager,n=[],r={...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>{let a=t(...e);return n.push(a),r}])),run:()=>{this.linkSource=e,this.linkListener=()=>{let t=e.state,r=e=>{t=t.apply(e)};for(let e of n)if(!e(t,r))return;this.state=t.reconfigure({plugins:this.extensionManager.plugins}),this.view&&this.view.updateState(this.state);let a=new CustomEvent(`changed`,{detail:{editor:this}});this.dispatchEvent(a)},e.addEventListener(`changed`,this.linkListener)}};return r}unlink(){this.linkListener&&this.linkSource&&(this.linkSource.removeEventListener(`changed`,this.linkListener),this.linkListener=void 0,this.linkSource=void 0)}createView(e,t){let n=createNodeFromObject(e,this.schema);if(this.state=EditorState.create({doc:n,selection:t}),this.config.element){let e=new EditorView(this.config.element,{state:this.state,attributes:{class:`kb-editor`},dispatchTransaction:e=>this.dispatchTransaction(e),editable:()=>!this.config.readOnly});if(this.view=e,this.config.element.parentNode){let t=new MutationObserver(n=>{for(let r of n)for(let n of r.removedNodes)if(n.contains(e.dom)){t.disconnect(),e.destroy();return}})}}else this.view=new DummyEditorView({state:this.state,dispatchTransaction:e=>this.dispatchTransaction(e)});let r=new CustomEvent(`doc:loaded`,{detail:{editor:this,doc:n}});this.dispatchEvent(r)}dispatchTransaction(e){if(this.state=this.state.apply(e),e.docChanged&&this.version++,this.view){this.view.updateState(this.state);let t=new CustomEvent(`transaction`,{detail:{editor:this,transaction:e}});this.dispatchEvent(t)}if(e.docChanged){let e=new CustomEvent(`changed`,{detail:{editor:this}});this.dispatchEvent(e)}}setupPlugins(){this.state=this.state.reconfigure({plugins:this.extensionManager.plugins}),this.view&&(this.view.updateState(this.state),this.view.setProps({nodeViews:this.extensionManager.nodeViews}))}clearDocument(){let e={type:this.schema.topNodeType.name,content:this.schema.topNodeType.spec.EMPTY_DOC.content};this.setDocument(e)}setDocument(e){let t=createNodeFromObject(e,this.schema,{errorOnInvalidContent:!0});t=ensureDocSchema(t,this.schema),this.state=EditorState.create({doc:t,plugins:this.state.plugins,storedMarks:this.state.storedMarks}),this.view&&this.view.updateState(this.state);let n=new CustomEvent(`doc:loaded`,{detail:{editor:this,doc:t}});this.dispatchEvent(n)}getConverter(e){let t=this.extensionManager.converters[e];if(!t)throw Error(`Converter not found for: `+e);return t}getDocument(){return this.state.doc}loadDocumentText(e,t){return this.loadDocument(e,new TextEncoder().encode(t))}async loadDocument(e,t){let n=await this.getConverter(e).toDoc(t),r=EditorState.create({doc:n,plugins:this.state.plugins,storedMarks:this.state.storedMarks});runInputRulesTexts()(r,e=>{r=r.apply(e)}),this.state=r,this.view&&(this.view.updateState(this.state),this.view.dispatch(this.view.state.tr));let a=new CustomEvent(`doc:loaded`,{detail:{editor:this,doc:this.state.doc}});this.dispatchEvent(a)}async saveDocument(e){let t=this.getConverter(e),n=this.state.doc.toJSON(),r=Node$3.fromJSON(this.state.schema,n);return await t.fromDoc(r)}async patchDocument(e,t){let n=await this.getConverter(e).toDoc(t),r=this.state.tr;r.replaceWith(0,this.state.doc.content.size,n.content),this.dispatchTransaction(r)}getMediaTypes(){return Object.keys(this.extensionManager.converters)}patchDocumentText(e,t){return this.patchDocument(e,new TextEncoder().encode(t))}getJSON(){return this.state.doc.toJSON()}debug(e){e||=this.state.doc,console.debug(nodeToTreeString(e))}destroy(){let e=new CustomEvent(`beforeDestroy`,{detail:{}});if(this.dispatchEvent(e),this.config.element){let e=this.config.element,t=e.cloneNode(!0);e.replaceWith(t)}this.view.destroy()}mergeCommandFactories(e,t){this.commandManager.mergeCommandFactories(e,t)}get editable(){return this.view.editable}},Extension=class{config;type=`extension`;editor;conflicts;overrides;constructor(e={}){this.config=e}setEditor(e){this.editor=e}getEditor(){return this.editor}created(){}getInputRules(){return[]}getProseMirrorPlugins(){return[]}getCommandFactories(e){return{}}getKeyboardShortcuts(e){return{}}getConverters(e,t){return{}}setupSpec(e){}},Mark=class{config;type=`mark`;name=`node`;editor;attributes={};constructor(e={}){this.config=e}setEditor(e){this.editor=e}created(){}getMarkSpec(){throw Error(`MarkSpec not defined: `+this.name)}getInputRules(e){return[]}getCommandFactories(e,t){return{}}getKeyboardShortcuts(e){return{}}},Node$2=class{config;type=`node`;name=`node`;editor;attributes={};constructor(e={}){this.config=e}setEditor(e){this.editor=e}created(){}getNodeSpec(){throw Error(`NodeSpec not defined: `+this.name)}getInputRules(e){return[]}getProseMirrorPlugins(){return[]}getCommandFactories(e,t){return{}}getKeyboardShortcuts(e){return{}}getNodeView(e){}getConverters(e,t){return{}}};function getShadowRoot(e){let t=e;for(;t;){if(t.toString()===`[object ShadowRoot]`)return t;if(t instanceof ShadowRoot&&t.host)return t.host.shadowRoot||void 0;t=t.parentElement||(t instanceof ShadowRoot?t.host:void 0)}}function debounce(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}function normalizeSiblings(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),a,o=[];if(e.forEach(e=>{if(!o)return;let t=r.findWrapping(e.type),n;if(!t)return o=null;if(n=o.length&&a.length&&addToSibling(t,a,e,o[o.length-1],0))o[o.length-1]=n;else{o.length&&(o[o.length-1]=closeRight(o[o.length-1],a.length));let n=withWrappers(e,t);o.push(n),r=r.matchType(n.type),a=t}}),o)return Fragment.from(o)}return e}function withWrappers(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Fragment.from(e));return e}function addToSibling(e,t,n,r,a){if(a<e.length&&a<t.length&&e[a]==t[a]){let o=addToSibling(e,t,n,r.lastChild,a+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(a==e.length-1?n.type:e[a+1]))return r.copy(r.content.append(Fragment.from(withWrappers(n,e,a+1))))}}function closeRight(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,closeRight(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Fragment.empty,!0);return e.copy(n.append(r))}function closeRange(e,t,n,r,a,o){let s=t<0?e.firstChild:e.lastChild,c=s.content;return e.childCount>1&&(o=0),a<r-1&&(c=closeRange(c,t,n,r,a+1,o)),a>=n&&(c=t<0?s.contentMatchAt(0).fillBefore(c,o<=a).append(c):c.append(s.contentMatchAt(s.childCount).fillBefore(Fragment.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(c))}function closeSlice(e,t,n){return t<e.openStart&&(e=new Slice(closeRange(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Slice(closeRange(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}function sliceSingleNode(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function fixSlice(e,t){if(e=Slice.maxOpen(normalizeSiblings(e.content,t),!0),e.openStart||e.openEnd){let t=0,n=0;for(let n=e.content.firstChild;t<e.openStart&&!n.type.spec.isolating;t++,n=n.firstChild);for(let t=e.content.lastChild;n<e.openEnd&&!t.type.spec.isolating;n++,t=t.lastChild);e=closeSlice(e,t,n)}return e}function sliceHasOnlyText(e){return e.content.content.every(e=>e.isInline)}var selectAll=()=>function(e,t,n){let r=e.tr.setSelection(new AllSelection(e.doc));return n&&n.dispatch(r),!0};function textPositionsToResolvedPos(e,t,n){let r=e.map(e=>-1),a=0,o=!1;function s(t,n,s,c){if(o){for(let n=0;n<e.length;n++){let o=e[n];o>=a&&o<a+c&&(r[n]=t+(o-a))}a+=c}}function c(e,t=0,r=0,a=0){t===1&&r===n&&(o=!0);let l=0;e.isText&&e.text?l=e.text?.length:e.isLeaf&&(l=1),l>0&&s(a,t,r,l),e.forEach((e,n,r)=>{c(e,t+1,r,a+n+1)})}if(c(t),o)for(let n=0;n<e.length;n++){let o=e[n];r[n]===-1&&(o<a?r[n]=1:r[n]=t.nodeSize-1)}return r.map(e=>t.resolve(e-1))}var selectText=(e,t,n=0)=>function(r,a,o){let[s,c]=textPositionsToResolvedPos([e+t,e],r.doc,n),l=r.tr.setSelection(new TextSelection(c,s));return o&&o.dispatch(l),!0},ExtensionSelection=class extends Extension{name=`selection`;extractSelection(){let e=this.editor.state,{from:t,to:n}=e.selection,r=e.doc.slice(t,n);if(sliceHasOnlyText(r)){let t=e.schema.nodes.paragraph.create(null,r.content);return e.schema.topNodeType.createAndFill(null,[t])}return e.schema.topNodeType.createAndFill(null,r.content)}replaceSelection(e){let t=!1,n=this.editor.view,r=this.editor.state,a;e.type?.name===`doc`&&(e=createNodeFromObject(e.toJSON(),this.editor.schema)),a=new Slice(e.content,1,1);let o=r.selection.$from;a=fixSlice(a,o);let s=sliceSingleNode(a),c=s?r.tr.replaceSelectionWith(s,!1):r.tr.replaceSelection(a);n.dispatch(c.scrollIntoView())}appendSelection(e){let t=this.editor.view,{state:n}=t,r;e.type?.name===`doc`&&(e=createNodeFromObject(e.toJSON(),this.editor.schema)),r=new Slice(e.content,1,1);let a=t.state.selection.$from;r=fixSlice(r,a);let o=n.tr.insert(t.state.selection.to,r.content);t.dispatch(o.scrollIntoView())}getCommandFactories(e){return this.editor=e,{selectAll:()=>selectAll(),selectText:(...e)=>selectText(...e)}}},pcBaseKeymap={"Mod-Enter":`exitCode`,Backspace:`backspace`,"Mod-Backspace":`backspace`,"Shift-Backspace":`backspace`,Delete:`del`,"Mod-Delete":`del`,"Mod-a":`selectAll`},macBaseKeymap={...pcBaseKeymap,"Ctrl-h":pcBaseKeymap.Backspace,"Alt-Backspace":pcBaseKeymap[`Mod-Backspace`],"Ctrl-d":pcBaseKeymap.Delete,"Ctrl-Alt-Backspace":pcBaseKeymap[`Mod-Delete`],"Alt-Delete":pcBaseKeymap[`Mod-Delete`],"Alt-d":pcBaseKeymap[`Mod-Delete`],"Ctrl-a":`selectTextblockStart`,"Ctrl-e":`selectTextblockEnd`},baseKeymap=/(Mac|iPhone|iPod|iPad)/i.test(navigator?.platform)?macBaseKeymap:pcBaseKeymap,ExtensionBaseKeymap=class extends Extension{name=`base-keymap`;getKeyboardShortcuts(){let e={Enter:`enter`,"Alt-ArrowUp":`joinUp`,"Alt-ArrowDown":`joinDown`,"Mod-BracketLeft":`lift`,Escape:`selectParentNode`};for(let t in baseKeymap)e[t]=baseKeymap[t];return e}};function dropCursor(e={}){return new Plugin({key:new PluginKey(`drop-cursor`),view(t){return new DropCursorView(t,e)}})}var DropCursorView=class{editorView;width;color;class;cursorPos=null;element=null;timeout=-1;handlers;constructor(e,t){this.editorView=e,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,a=r.getBoundingClientRect(),o=a.width/r.offsetWidth,s=a.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let a=e.getBoundingClientRect(),o=t?a.bottom:a.top;t&&r&&(o=(o+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let c=this.width/2*s;n={left:a.left,right:a.right,top:o-c,bottom:o+c}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*o;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let c=this.editorView.dom.offsetParent;this.element||(this.element=c.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let l,u;if(!c||c==document.body&&getComputedStyle(c).position==`static`)l=-pageXOffset,u=-pageYOffset;else{let e=c.getBoundingClientRect(),t=e.width/c.offsetWidth,n=e.height/c.offsetHeight;l=e.left-c.scrollLeft*t,u=e.top-c.scrollTop*n}this.element.style.left=(n.left-l)/o+`px`,this.element.style.top=(n.top-u)/s+`px`,this.element.style.width=(n.right-n.left)/o+`px`,this.element.style.height=(n.bottom-n.top)/s+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,a=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!a){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=dropPoint(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},ExtensionDropcursor=class extends Extension{name=`dropcursor`;options={color:`currentColor`,width:1,class:void 0};getProseMirrorPlugins(){return[dropCursor(this.options)]}},GapCursor=class e extends Selection{constructor(e){super(e,e),this.visible=!1}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):Selection.near(r)}content(){return Slice.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSONToGapCursor(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new GapBookmark(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!closedBefore(e)||!closedAfter(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let a=t.pos,o=null;for(let r=t.depth;;r--){let s=t.node(r);if(n>0?t.indexAfter(r)<s.childCount:t.index(r)>0){o=s.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;a+=n;let c=t.doc.resolve(a);if(e.valid(c))return c}for(;;){let s=n>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!NodeSelection.isSelectable(o)){t=t.doc.resolve(a+o.nodeSize*n),r=!1;continue search}break}o=s,a+=n;let c=t.doc.resolve(a);if(e.valid(c))return c}return null}}};Selection.jsonID(`gapcursor`,GapCursor);var GapBookmark=class e{pos;constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return GapCursor.valid(t)?new GapCursor(t):Selection.near(t)}};function closedBefore(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}}return!0}function closedAfter(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}}return!0}function gapCursor(){return new Plugin({key:new PluginKey(`gap-cursor`),props:{decorations:drawGapCursor,createSelectionBetween(e,t,n){return t.pos==n.pos&&GapCursor.valid(n)?new GapCursor(n):null},handleClick,handleKeyDown:handleKeyDown$1,handleDOMEvents:{beforeinput}}})}var handleKeyDown$1=keydownHandler({ArrowLeft:arrow$1(`horiz`,-1),ArrowRight:arrow$1(`horiz`,1),ArrowUp:arrow$1(`vert`,-1),ArrowDown:arrow$1(`vert`,1)});function arrow$1(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,a){let o=e.selection,s=t>0?o.$to:o.$from,c=o.empty;if(o instanceof TextSelection){if(!a.endOfTextblock(n)||s.depth==0)return!1;c=!1,s=e.doc.resolve(t>0?s.after():s.before())}let l=GapCursor.findGapCursorFrom(s,t,c);return l?(r&&r(e.tr.setSelection(new GapCursor(l))),!0):!1}}function handleClick(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!GapCursor.valid(r))return!1;let a=e.posAtCoords({left:n.clientX,top:n.clientY});return a&&a.inside>-1&&NodeSelection.isSelectable(e.state.doc.nodeAt(a.inside))?!1:(e.dispatch(e.state.tr.setSelection(new GapCursor(r))),!0)}function beforeinput(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof GapCursor))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let a=Fragment.empty;for(let e=r.length-1;e>=0;e--)a=Fragment.from(r[e].createAndFill(null,a));let o=e.state.tr.replace(n.pos,n.pos,new Slice(a,0,0));return o.setSelection(TextSelection.near(o.doc.resolve(n.pos+1))),e.dispatch(o),!1}function drawGapCursor(e){if(!(e.selection instanceof GapCursor))return null;let t=document.createElement(`div`);return t.className=`kb-gapcursor`,DecorationSet.create(e.doc,[Decoration.widget(e.selection.head,t,{key:`gapcursor`})])}var ExtensionGapcursor=class extends Extension{name=`gapcursor`;options={color:`currentColor`,width:1,class:void 0};getProseMirrorPlugins(){return[gapCursor()]}},ExtensionTextAlign=class extends Extension{name=`textAlign`;getCommandFactories(e){let t=e=>(t,n)=>{let{selection:r,tr:a}=t,{from:o,to:s}=r,c=!1;return t.doc.nodesBetween(o,s,(t,n)=>{t.isBlock&&t.type.spec.attrs&&`textAlign`in t.type.spec.attrs&&(a.setNodeMarkup(n,void 0,{...t.attrs,textAlign:e}),c=!0)}),c&&n&&n(a),c};return{setTextAlignLeft:()=>t(`left`),setTextAlignCenter:()=>t(`center`),setTextAlignRight:()=>t(`right`),setTextAlignJustify:()=>t(`justify`)}}},userColors=[{dark:`#30bced`,light:`#30bced`},{dark:`#6eeb83`,light:`#6eeb83`},{dark:`#ffbc42`,light:`#ffbc42`},{dark:`#ecd444`,light:`#ecd444`},{dark:`#ee6352`,light:`#ee6352`},{dark:`#9ac2c9`,light:`#9ac2c9`},{dark:`#8acb88`,light:`#8acb88`},{dark:`#1be7ff`,light:`#1be7ff`}];function hashString(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}var defaultColorMapper=(e,t)=>{let n=hashString(t.id),r=hashString(e.id);return n===r&&r++,userColors[r%userColors.length]};function generateBlankUser(){return{id:``,name:`User unset`}}function generateRandomUser(){let e=Math.random()*100;return{id:`random:`+e,name:`Anonymous `+Math.floor(e)}}var userPluginKey=new PluginKey(`user`),createUserPlugin=()=>new Plugin({key:userPluginKey,state:{init(){return{user:generateRandomUser()}},apply:(e,t)=>{let n=e.getMeta(`changeUser`);return n&&(t.user={...n.user}),t}}}),ExtensionUser=class extends Extension{name=`user`;getCommandFactories(){return{changeUser:e=>(t,n)=>{let r=t.tr;return r.setMeta(`changeUser`,{user:e}),n&&n(r),!0}}}getProseMirrorPlugins(){return[createUserPlugin()]}},remoteSelectionPluginKey=new PluginKey(`remote-selection`),defaultCursorBuilder=(e,t,n)=>{let r=n(e,t).light,a=document.createElement(`span`);a.classList.add(`kb-yjs__cursor`),a.setAttribute(`style`,`border-color: ${r};`);let o=document.createElement(`div`);o.setAttribute(`style`,`background-color: ${r}`),o.insertBefore(document.createTextNode(e.name),null);let s=document.createTextNode(``),c=document.createTextNode(``);return a.insertBefore(s,null),a.insertBefore(o,null),a.insertBefore(c,null),a},defaultSelectionBuilder=(e,t,n)=>({style:`background-color: ${n(e,t).light}70`,class:`kb-yjs__selection`}),createDecorations=(e,t,n,r)=>{let a=[],o=t.remoteStates;for(let s of o)if(s.cursor!=null){let o=s.user,c=s.cursor,l=c.anchor||null,u=c.head||null;if(l!==null&&u!==null){let c=Math.max(e.doc.content.size-1,0);l=Math.min(l,c),u=Math.min(u,c),a.push(Decoration.widget(u,()=>n(o,t.me,t.colorMapper),{key:s.clientId+o.id+o.name,side:10}));let d=Math.min(l,u),f=Math.max(l,u);a.push(Decoration.inline(d,f,r(o,t.me,t.colorMapper),{inclusiveEnd:!0,inclusiveStart:!1}))}}return DecorationSet.create(e.doc,a)},remoteSelectionPlugin=({cursorBuilder:e=defaultCursorBuilder,selectionBuilder:t=defaultSelectionBuilder}={})=>new Plugin({key:remoteSelectionPluginKey,state:{init(){return{remoteStates:[],me:generateBlankUser(),colorMapper:defaultColorMapper}},apply(e,t){let n=e.getMeta(`changeUser`);n&&(t.me={...n.user});let r=e.getMeta(`setColorMapper`);r&&(t.colorMapper=r.colorMapper);let a=e.getMeta(`remoteSelectionChange`);return a&&(t.remoteStates=[...a.remoteStates]),t}},props:{decorations(n){let r=this.getState(n);return r?createDecorations(n,r,e,t):DecorationSet.empty}}}),ExtensionRemoteSelection=class extends Extension{name=`remote-selection`;getProseMirrorPlugins(){return[remoteSelectionPlugin()]}};function generateId(){return String(Math.random())}function buildPairingTransaction(e,t,n){let{doc:r}=e,a=new Map,o=[];r.descendants((e,n)=>{e.type.name===t&&o.push({node:e,pos:n})});let s=!1;for(let{node:e,pos:t}of o){let r=e.attrs.content?.trim();if(!r)continue;let o=r.match(/^[^0-9a-z\/]*(\/?)[\s]*([\w]+)/i);if(!o)continue;let c=o[1]===`/`,l=o[2];if(!c)a.has(l)||a.set(l,[]),a.get(l).push({node:e,pos:t});else{let r=a.get(l);if(r&&r.length>0){let a=r.pop(),o=generateId();n.setNodeMarkup(a.pos,void 0,{...a.node.attrs,id:o,nesting:1,error:void 0}),n.setNodeMarkup(t,void 0,{...e.attrs,id:o,nesting:-1,error:void 0})}else n.setNodeMarkup(t,void 0,{...e.attrs,error:`Closing shortcode without matching opening`,nesting:-1});s=!0}}for(let[,e]of a.entries())for(let{node:t,pos:r}of e)n.setNodeMarkup(r,void 0,{...t.attrs,nesting:0,id:void 0}),s=!0;return s?n:null}var createPairingPlugin=e=>new Plugin({appendTransaction(t,n,r){let a=new Set;for(let r of t)if(r.docChanged){for(let t of r.steps)if((t instanceof ReplaceStep||t instanceof ReplaceAroundStep)&&(t.slice&&t.slice.content.descendants(t=>{e.includes(t.type.name)&&a.add(t.type.name)}),t.from!=null&&t.to!=null&&t.from!==t.to&&n.doc.nodesBetween(t.from,t.to,t=>{e.includes(t.type.name)&&a.add(t.type.name)}),a.size===e.length))break;if(a.size===e.length)break}if(a.size===0)return null;let o=r.tr;for(let e of a)buildPairingTransaction(r,e,o);return o}}),ExtensionPairing=class extends Extension{name=`pairing-nodes`;getProseMirrorPlugins(){return[createPairingPlugin([`shortcode_inline`])]}};function getHTMLFromFragment(e,t){let n=globalThis.document,r=DOMSerializer.fromSchema(t).serializeFragment(e,{document:n}),a=n.implementation.createHTMLDocument().createElement(`div`);return a.appendChild(r),a.innerHTML}var removeWhitespaces$1=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&removeWhitespaces$1(r)}return e};function elementFromString$1(e){let t=`<html lang="en"><body>${e}</body></html>`,n=new globalThis.DOMParser().parseFromString(t,`text/html`).body;return removeWhitespaces$1(n)}var ExtensionHtml=class extends Extension{name=`html`;getConverters(e,t){return{"text/html":{fromDoc:async t=>{let n=getHTMLFromFragment(t.content,e.schema);return new TextEncoder().encode(n)},toDoc:async e=>{let n=elementFromString$1(new TextDecoder().decode(e));return DOMParser$1.fromSchema(t).parse(n)}}}}},mediaUploadKey=new PluginKey(`mediaUpload`);function fileToDataURL(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})}function fileToObjectURL(e){return URL.createObjectURL(e)}function isImage(e,t){return t.some(t=>e.type.match(t))}function isVideo(e,t){return t.some(t=>e.type.match(t))}function insertImage(e,t,n,r,a){let{schema:o}=e.state,s=o.nodes.image;if(!s){console.warn(`Image node type not found in schema`);return}let c=s.create({src:n,alt:r,title:a}),l=e.state.tr.insert(t,c);e.dispatch(l)}function insertVideo(e,t,n,r,a,o){let{schema:s}=e.state,c=s.nodes.video;if(!c){console.warn(`Video node type not found in schema`);return}let l=c.create({src:n,title:r,width:a,height:o,controls:!0}),u=e.state.tr.insert(t,l);e.dispatch(u)}async function handleMediaFiles(e,t,n,r){let{maxFileSize:a=10*1024*1024,maxVideoFileSize:o=50*1024*1024,allowedImageTypes:s=[`^image/`],allowedVideoTypes:c=[`^video/`],uploadHandler:l}=r;for(let u of t){let t=isImage(u,s),d=isVideo(u,c);if(!t&&!d)continue;let f=d?o:a;if(u.size>f){console.warn(`${d?`Video`:`Image`} file "${u.name}" is too large (${(u.size/1024/1024).toFixed(2)}MB). Maximum size is ${(f/1024/1024).toFixed(2)}MB.`);continue}try{console.log(`Processing ${d?`video`:`image`}: ${u.name} (${(u.size/1024/1024).toFixed(2)}MB, ${u.type})`);let t;l?t=await l(u):d&&r.useObjectURLForVideos!==!1?(t=fileToObjectURL(u),console.log(`Using object URL for video:`,t)):(t=await fileToDataURL(u),console.log(`${d?`Video`:`Image`} converted to data URL, length: ${t.length} characters`)),d?(insertVideo(e,n,t,u.name),console.log(`Video inserted into editor`)):(insertImage(e,n,t,u.name),console.log(`Image inserted into editor`)),n+=1}catch(e){console.error(`Failed to process ${d?`video`:`image`} "${u.name}":`,e)}}}function createMediaUploadPlugin(e={}){return new Plugin({key:mediaUploadKey,state:{init(){return e},apply(e,t){return e.isGeneric?t:e.getMeta(`setMediaUploadOptions`)||t}},props:{handleDrop(e,t,n,r){if(r)return!1;let a=Array.from(t.dataTransfer?.files||[]);if(a.length===0)return!1;let o=mediaUploadKey.getState(e.state)||{},{allowedImageTypes:s=[`^image/`],allowedVideoTypes:c=[`^video/`]}=o;if(a.some(e=>isImage(e,s)||isVideo(e,c))){t.preventDefault();let n={left:t.clientX,top:t.clientY},r=e.posAtCoords(n);return r?(handleMediaFiles(e,a,r.pos,o),!0):!1}},handlePaste(t,n,r){if((n.clipboardData?.types||[]).includes(`text/html`))return;let a=Array.from(n.clipboardData?.items||[]).filter(e=>e.type.startsWith(`image/`));if(a.length>0){n.preventDefault();let r=[];for(let e of a){let t=e.getAsFile();t&&r.push(t)}if(r.length===0)return!1;let{from:o}=t.state.selection;return handleMediaFiles(t,r,o,e),!0}}}})}var ExtensionMediaUpload=class extends Extension{config;name=`mediaUpload`;constructor(e={}){super(e),this.config=e}getProseMirrorPlugins(){return[createMediaUploadPlugin(this.config)]}};function getStringByXPath(e,t){return t.ownerDocument.evaluate(e,t,null,XPathResult.STRING_TYPE,null).stringValue}function getElementsByXPath(e,t){let n=t.ownerDocument.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=[];for(let e=0;e<n.snapshotLength;e++){let t=n.snapshotItem(e);t&&r.push(t)}return r}var PasteState=class{editor;pasteRules=[];constructor(e){this.editor=e}handleCommands(e,t){if(!e)return!1;if(e.getPasteRules)return e.getPasteRules(this.pasteRules),!0;if(e.setPasteRules)return console.log(`setPasteRules`,e.setPasteRules),this.pasteRules=e.setPasteRules,!0;if(e.pasteHtml){let{from:t,html:n}=e.pasteHtml,r=elementFromString$1(n),a=this.editor,o=!1,s=[],c=a.ci.resolve(`yaml`);for(let e of this.pasteRules){if(typeof e.match==`string`){if(getElementsByXPath(e.match,r).length===0)continue}else if(!e.match(r))continue;for(let t of e.steps){let e;if(typeof t.match==`string`)switch(t.result||``){case`string`:e=getStringByXPath(t.match,r);break;default:e=getElementsByXPath(t.match,r);break}else e=t.match(r);switch(console.log(`step`,e,t),t.op){case`remove`:for(let t of e)t.parentNode?.removeChild(t);break;case`replaceTag`:for(let n of e){let e=n.ownerDocument.createElement(t.tag);e.innerHTML=n.innerHTML,n.parentNode?.replaceChild(e,n)}break;case`replaceBody`:for(let t of e)r.innerHTML=``,r.appendChild(t);break;case`console.debug`:console.debug(e);break;case`meta.set`:s.push({path:t.path,value:e});break}}o=!!e.replaceDocument;break}let l=DOMParser$1.fromSchema(this.editor.schema).parse(r);return setTimeout(async()=>{let e=this.editor.state.tr;o?e.replaceWith(0,this.editor.state.doc.content.size,l):e.insert(t,l);{let t=await new Promise(e=>this.editor.chain().getMeta(e).run())||new Map;for(let e of s)c.setPathValue(t,e.path,e.value);e.setDocAttribute(`meta`,t)}this.editor.dispatchTransaction(e)},0),!0}return!1}},PastePluginKey=new PluginKey(`paste`),ExtensionPaste=class extends Extension{name=`paste`;getProseMirrorPlugins(){let e=this.editor;return[new Plugin({key:PastePluginKey,state:{init(){return PastePluginKey.getState(e.state)||new PasteState(e)},apply(e,t,n,r){if(e.isGeneric)return t;let a=e.getMeta(PastePluginKey);return t.handleCommands(a,e),t}},props:{handleDOMEvents:{copy(t,n){if(!n.clipboardData)return!1;let r=e.clone();return n.preventDefault(),(async()=>{r.state.selection instanceof AllSelection||r.ci.register(`frontmatter`,new BlankFrontmatterServiceImpl),r.chain().keepSelection().run();let e=new TextDecoder().decode(await r.saveDocument(`text/x-markdown`)),t=new TextDecoder().decode(await r.saveDocument(`text/html`));await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([e],{type:`text/plain`}),"text/html":new Blob([t],{type:`text/html`})})])})(),!1}},handlePaste(t,n,r){let{clipboardData:a}=n;if(!a)return!1;if(a.types.includes(`text/html`)){let{from:e}=t.state.selection,r=a.getData(`text/html`);n.preventDefault();let o=t.state.tr.setMeta(PastePluginKey,{pasteHtml:{from:e,html:r}});return t.dispatch(o),!0}[...a.items].map(e=>e.getAsFile()).filter(e=>!!e);let o=Array.from(n.clipboardData?.files||[]);if(o.length===1){let t=o[0];if(e.getMediaTypes().includes(t.type))return t.bytes().then(n=>{e.loadDocument(t.type,n)}),!0}},handleDrop(t,n,r,a){let o=Array.from(n.dataTransfer?.files||[]);if(o.length===1){let t=o[0];if(e.getMediaTypes().includes(t.type))return t.bytes().then(n=>{e.loadDocument(t.type,n)}),!0}}}})]}getCommandFactories(e){return{getPasteRules:e=>(t,n)=>{let r=t.tr;return r.setMeta(PastePluginKey,{getPasteRules:e}),n&&n(r),!0},setPasteRules:e=>(t,n)=>{let r=t.tr;return r.setMeta(PastePluginKey,{setPasteRules:e}),n&&n(r),!0}}}},MarkLink=class extends Mark{name=`link`;requires=[`doc`];getMarkSpec(){return{attrs:{href:{},title:{default:void 0},origUrl:{default:void 0},mdTemplate:{default:void 0}},inclusive:!1,parseDOM:[{tag:`a[href]`,getAttrs(e){return{href:e.getAttribute(`href`),title:e.getAttribute(`title`)}}}],toDOM(e){let{href:t,title:n}=e.attrs;return[`a`,{href:t,title:n},0]}}}},MarkStrong=class extends Mark{name=`strong`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!=`normal`&&null},{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(){return[`strong`,0]}}}getCommandFactories(e,t){return{toggleStrong:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-b":`toggleStrong`,"Mod-B":`toggleStrong`}}},MarkItalic=class extends Mark{name=`em`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`i`},{tag:`em`},{style:`font-assets=italic`},{style:`font-assets=normal`,clearMark:e=>e.type.name==`em`}],toDOM(){return[`em`,0]}}}getCommandFactories(e,t){return{toggleItalic:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-i":`toggleItalic`,"Mod-I":`toggleItalic`}}},MarkUnderline=class extends Mark{name=`underline`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`u`}],toDOM(){return[`u`,0]}}}getCommandFactories(e,t){return{toggleUnderline:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-u":`toggleUnderline`,"Mod-U":`toggleUnderline`}}},MarkStrike=class extends Mark{name=`strike`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`strike`}],toDOM(){return[`strike`,0]}}}getCommandFactories(e,t){return{toggleStrike:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-s":`toggleStrike`,"Mod-S":`toggleStrike`}}},MarkCode=class extends Mark{name=`code`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`code`}],toDOM(){return[`code`,0]}}}getCommandFactories(e,t){return{toggleCode:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-`":`toggleCode`}}},MarkChange=class extends Mark{name=`change`;requires=[`doc`];getMarkSpec(){return{parseDOM:[],toDOM(){return[`change`,0]}}}},MarkBookmark=class extends Mark{name=`bookmark`;requires=[`doc`];getMarkSpec(){return{attrs:{id:{}},parseDOM:[],toDOM(e){return[`a`,{id:e.attrs.id},0]}}}},MarkTextColor=class extends Mark{name=`textColor`;getMarkSpec(){return{attrs:{color:{default:null}},parseDOM:[{tag:`span[style*="color"]`,getAttrs(e){let t=e.style.color;return t?{color:t}:!1}}],toDOM(e){let{color:t}=e.attrs;return t?[`span`,{style:`color: ${t}`},0]:[`span`,0]}}}},MarkHighlight=class extends Mark{name=`highlight`;getMarkSpec(){return{attrs:{color:{default:null}},parseDOM:[{tag:`mark`,getAttrs(e){let t=e.style.backgroundColor;return t?{color:t}:{color:`yellow`}}},{tag:`span[style*="background-color"]`,getAttrs(e){let t=e.style.backgroundColor;return t?{color:t}:!1}}],toDOM(e){let{color:t}=e.attrs;return[`mark`,{style:`background-color: ${t||`yellow`}; color: inherit;`},0]}}}},MarkSuperscript=class extends Mark{name=`superscript`;requires=[`doc`];getMarkSpec(){return{excludes:`subscript`,parseDOM:[{tag:`sup`},{style:`vertical-align`,getAttrs:e=>e===`super`&&null}],toDOM(){return[`sup`,0]}}}getCommandFactories(e,t){return{toggleSuperscript:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-Shift-.":`toggleSuperscript`}}},MarkSubscript=class extends Mark{name=`subscript`;requires=[`doc`];getMarkSpec(){return{excludes:`superscript`,parseDOM:[{tag:`sub`},{style:`vertical-align`,getAttrs:e=>e===`sub`&&null}],toDOM(){return[`sub`,0]}}}getCommandFactories(e,t){return{toggleSubscript:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-Shift-,":`toggleSubscript`}}},NodeDocument=class extends Node$2{name=`doc`;getNodeSpec(){return{content:`block+`,attrs:{meta:{default:null}},marks:`code em strong link bookmark`,EMPTY_DOC:{type:this.name,content:[{type:`paragraph`,content:[]}]}}}getCommandFactories(e,t){return{getMeta:e=>(t,n)=>(e(structuredClone(t.doc.attrs.meta)),!0),setMeta:e=>(t,n)=>{let r=t.tr;return r.setDocAttribute(`meta`,e),n&&n(r),r.docChanged},updateMeta:e=>(t,n)=>{let r=t.tr;return r.setDocAttribute(`meta`,e(t.doc.attrs.meta)),n&&n(r),r.docChanged}}}},NodeText=class extends Node$2{name=`text`;getNodeSpec(){return{group:`inline`}}};function wrappingInputRule(e,t,n=null,r){return new InputRule(e,(e,a,o,s,c)=>{e||=a.tr;let l=n instanceof Function?n(o):n;e=e.delete(s,c);let u=e.doc.resolve(s).blockRange(),d=u&&findWrapping(u,t,l);if(!d)return null;e.wrap(u,d);let f=e.doc.resolve(s-1).nodeBefore;return f&&f.type==t&&canJoin(e.doc,s-1)&&(!r||r(o,f))&&e.join(s-1),e})}function textblockTypeInputRule(e,t,n=null){return new InputRule(e,(e,r,a,o,s)=>{e||=r.tr;let c=r.doc.resolve(o),l=n instanceof Function?n(a):n;return c.node(-1).canReplaceWith(c.index(-1),c.indexAfter(-1),t)?e.delete(o,s).setBlockType(o,o,t,l):null})}function replaceInlineNode(e,t,n=null){return new InputRule(e,(e,r,a,o,s)=>{e||=r.tr;let c=n instanceof Function?n(a):n;if(r.doc.resolve(o).parent.type===r.schema.nodes.code_block)return e;let l=t.createAndFill(c),u=e.mapping.map(o),d=e.mapping.map(s);return e.replaceWith(u,d,Fragment.from(l))})}var NodeCodeBlock$1=class extends Node$2{name=`code_block`;getNodeSpec(){return{content:`text*`,marks:``,group:`block`,code:!0,defining:!0,attrs:{lang:{default:void 0}},parseDOM:[{tag:`pre`,preserveWhitespace:`full`,getAttrs(e){return{lang:e.getAttribute(`lang`)}}}],toDOM(e){let{lang:t}=e.attrs;return[`pre`,{lang:t},[`code`,0]]}}}getInputRules(e){return[textblockTypeInputRule(/^```$/,e)]}},NodeBookmark=class extends Node$2{name=`node_bookmark`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,atom:!0,attrs:{id:{},nesting:{default:0}},parseDOM:[],toDOM(e){return[`a`,{id:e.attrs.id},0]}}}},NodeParagraph=class extends Node$2{name=`paragraph`;requires=[`doc`];getNodeSpec(){return{content:`inline*`,group:`block`,attrs:{textAlign:{default:void 0}},parseDOM:[{tag:`p`,getAttrs(e){let t=e.style.textAlign;return t===`center`||t===`right`||t===`justify`?{textAlign:t}:!1}}],toDOM(e){let t=e.attrs.textAlign||`left`;return[`center`,`right`,`justify`].includes(t)?[`p`,{style:`text-align: ${t}`},0]:[`p`,0]}}}getCommandFactories(e,t){return{setParagraph:()=>e.commandFactories.setBlockType(t)}}getKeyboardShortcuts(){return{"Shift-Ctrl-0":`setParagraph`}}},NodeHardBreak=class extends Node$2{name=`br`;requires=[`doc`];options={keepMarks:!0};getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseDOM:[{tag:`br`}],toDOM(){return[`br`]}}}getCommandFactories(e,t){let n=firstCommand(e.run.exitCode);return{setHardBreak:()=>n}}getKeyboardShortcuts(){let e=typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator?.platform):!1,t={"Ctrl-Enter":`setHardBreak`};return e&&(t[`Mod-Enter`]=`setHardBreak`,t[`Shift-Enter`]=`setHardBreak`),t}},NodeSoftBreak=class extends Node$2{name=`softbreak`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,parseDOM:[{tag:`wbr`}],toDOM(){return[`wbr`]}}}},NodeHorizontalRule=class extends Node$2{name=`hr`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,parseDOM:[{tag:`hr`}],toDOM(){return[`hr`]}}}getCommandFactories(e,t){return{setHorizontalRule:()=>(e,n)=>(n&&n(e.tr.replaceSelectionWith(t.create()).scrollIntoView()),!0)}}getKeyboardShortcuts(){return{"Mod-_":`setHorizontalRule`}}},NodeImage=class extends Node$2{name=`image`;requires=[`doc`];getNodeSpec(){return{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null},width:{default:null},height:{default:null},origUrl:{default:void 0},mdTemplate:{default:void 0}},group:`inline`,draggable:!0,parseDOM:[{tag:`img[src]`,getAttrs(e){return{src:e.getAttribute(`src`),title:e.getAttribute(`title`),alt:e.getAttribute(`alt`),width:e.getAttribute(`width`)||e.style.width||null,height:e.getAttribute(`height`)||e.style.height||null}}}],toDOM(e){let{src:t,alt:n,title:r,width:a,height:o}=e.attrs,s={src:t};return n&&(s.alt=n),r&&(s.title=r),a&&(s.width=a),o&&(s.height=o),[`img`,s]}}}getNodeView(e){return(e,t,n)=>{let r=document.createElement(`span`);r.className=`kb-image-wrapper`,r.contentEditable=`false`;let a=document.createElement(`img`);a.src=e.attrs.src,e.attrs.alt&&(a.alt=e.attrs.alt),e.attrs.title&&(a.title=e.attrs.title),e.attrs.width&&(a.style.width=typeof e.attrs.width==`number`?`${e.attrs.width}px`:e.attrs.width),e.attrs.height&&(a.style.height=typeof e.attrs.height==`number`?`${e.attrs.height}px`:e.attrs.height),a.draggable=!1,r.appendChild(a);let o=[`nw`,`ne`,`sw`,`se`],s=[];for(let e of o){let t=document.createElement(`span`);t.className=`kb-image-resize-handle kb-image-resize-handle-${e}`,t.dataset.position=e,s.push(t),r.appendChild(t)}let c=!1,l=0,u=0,d=0,f=0,p=1,m=null,h=e=>{let t=e.target;if(!t.classList.contains(`kb-image-resize-handle`))return;e.preventDefault(),e.stopPropagation(),c=!0,m=t.dataset.position||null,l=e.clientX,u=e.clientY;let n=a.getBoundingClientRect();d=n.width,f=n.height,p=d/f,r.classList.add(`kb-image-resizing`),document.addEventListener(`mousemove`,g),document.addEventListener(`mouseup`,_)},g=e=>{if(!c)return;let t=e.clientX-l,n=e.clientY-u,r=d,o=f;switch(m){case`se`:r=d+t,o=e.shiftKey?f+n:r/p;break;case`sw`:r=d-t,o=e.shiftKey?f+n:r/p;break;case`ne`:r=d+t,o=e.shiftKey?f-n:r/p;break;case`nw`:r=d-t,o=e.shiftKey?f-n:r/p;break}r=Math.max(50,r),o=Math.max(50,o),a.style.width=`${Math.round(r)}px`,a.style.height=`${Math.round(o)}px`},_=()=>{if(!c)return;c=!1,m=null,r.classList.remove(`kb-image-resizing`),document.removeEventListener(`mousemove`,g),document.removeEventListener(`mouseup`,_);let o=Math.round(a.getBoundingClientRect().width),s=Math.round(a.getBoundingClientRect().height),l=n();if(typeof l==`number`){let n=t.state.tr.setNodeMarkup(l,void 0,{...e.attrs,width:`${o}px`,height:`${s}px`});t.dispatch(n)}};return r.addEventListener(`mousedown`,h),r.addEventListener(`click`,e=>{e.preventDefault();let r=n();if(typeof r==`number`){let e=t.state.doc.resolve(r),n=Selection.near(e);t.dispatch(t.state.tr.setSelection(n))}}),{dom:r,update:e=>e.type.name===`image`?(a.src=e.attrs.src,e.attrs.alt&&(a.alt=e.attrs.alt),e.attrs.title&&(a.title=e.attrs.title),e.attrs.width?a.style.width=typeof e.attrs.width==`number`?`${e.attrs.width}px`:e.attrs.width:a.style.width=``,e.attrs.height?a.style.height=typeof e.attrs.height==`number`?`${e.attrs.height}px`:e.attrs.height:a.style.height=``,!0):!1,destroy:()=>{r.removeEventListener(`mousedown`,h),document.removeEventListener(`mousemove`,g),document.removeEventListener(`mouseup`,_)},stopEvent:e=>e.type===`mousedown`&&e.target.classList.contains(`kb-image-resize-handle`),ignoreMutation:()=>!0}}}},NodeVideo=class extends Node$2{name=`video`;requires=[`doc`];getNodeSpec(){return{attrs:{src:{},title:{default:null},controls:{default:!0},width:{default:null},height:{default:null}},group:`block`,draggable:!0,parseDOM:[{tag:`video[src]`,getAttrs(e){return{src:e.getAttribute(`src`),title:e.getAttribute(`title`),controls:e.hasAttribute(`controls`),width:e.getAttribute(`width`),height:e.getAttribute(`height`)}}}],toDOM(e){let{src:t,title:n,controls:r,width:a,height:o}=e.attrs,s={src:t};return n&&(s.title=n),r&&(s.controls=``),a&&(s.width=a),o&&(s.height=o),[`video`,s]}}}},NodeBlockquote=class extends Node$2{name=`blockquote`;requires=[`doc`];getNodeSpec(){return{content:`block+`,group:`block`,defining:!0,parseDOM:[{tag:`blockquote`}],toDOM(){return[`blockquote`,0]}}}getInputRules(e){return[wrappingInputRule(/^\s*>\s$/,e)]}getCommandFactories(e,t){return{toggleBlockquote:()=>e.commandFactories.wrapInList(t)}}getKeyboardShortcuts(){return{"Ctrl->":`toggleBlockquote`}}},NodeAside=class extends Node$2{name=`aside`;requires=[`doc`];getNodeSpec(){return{content:`block+`,group:`block`,defining:!0,parseDOM:[{tag:`aside`}],toDOM(){return[`aside`,0]}}}},maxLevel=6,NodeHeading=class extends Node$2{name=`heading`;requires=[`doc`];getNodeSpec(){return{attrs:{level:{default:1}},content:`inline*`,group:`block`,defining:!0,parseDOM:[{tag:`h1`,attrs:{level:1}},{tag:`h2`,attrs:{level:2}},{tag:`h3`,attrs:{level:3}},{tag:`h4`,attrs:{level:4}},{tag:`h5`,attrs:{level:5}},{tag:`h6`,attrs:{level:6}}],toDOM(e){return[`h`+e.attrs.level,0]}}}getInputRules(e){return[textblockTypeInputRule(RegExp(`^(#{1,6})\\s$`),e,e=>({level:e[1].length}))]}getCommandFactories(e,t){let n={};for(let r=1;r<=maxLevel;r++)n[`setHeading`+r]=()=>e.commandFactories.setBlockType(t,{level:r});return n}getKeyboardShortcuts(){let e={};for(let t=1;t<=maxLevel;t++)e[`Shift-Ctrl-`+t]=`setHeading`+t;return e}},NodeMath=class extends Node$2{name=`math`;requires=[`doc`];getNodeSpec(){return{inline:!0,attrs:{lang:{default:`mathml`},content:{}},group:`inline`,draggable:!0,parseDOM:[{tag:`math`,getAttrs:e=>({lang:`mathml`,content:new XMLSerializer().serializeToString(e)})}],toDOM(e){let t=new DOMParser().parseFromString(e.attrs.content,`application/xml`);return t.getElementsByTagName(`parsererror`).length>0?[`span`,{class:`mathml-error`},`Invalid MathML`]:document.importNode(t.documentElement,!0)}}}},NodeDefinitionList=class extends Node$2{name=`dl`;requires=[`doc`];getNodeSpec(){return{content:`dt+|dd+`,group:`block`,parseDOM:[{tag:`dl`}],toDOM(){return[`dl`,0]}}}getInputRules(e){return[]}getCommandFactories(e,t){return{toggleDefinitionList:()=>e.commandFactories.wrapInList(t)}}getKeyboardShortcuts(){return{}}},NodeDefinitionTerm=class extends Node$2{name=`dt`;requires=[`dl`];getNodeSpec(){return{content:`inline*`,group:`block`,parseDOM:[{tag:`dt`}],defining:!0,toDOM(){return[`dt`,0]}}}},NodeDefinitionDesc=class extends Node$2{name=`dd`;requires=[`dl`];getNodeSpec(){return{content:`inline*`,group:`block`,parseDOM:[{tag:`dd`}],defining:!0,toDOM(){return[`dd`,0]}}}};function fixCharacters$1(e){return e.replace(/’/g,`'`).replace(/“/g,`"`).replace(/”/g,`"`).replace(/\x0b/g,` `).replace(/\u201d/g,`"`).replace(/\u201c/g,`"`)}function replaceAllNodesOfType(e,t,n,r){let a=[];t.descendants((e,t)=>{e.type===n&&a.push({node:e,pos:t})});for(let t=a.length-1;t>=0;t--){let{node:n,pos:o}=a[t],s=r(n,e.doc.type.schema);e=e.replaceWith(o,o+n.nodeSize,s)}return e}var NodeInlineShortCode=class extends Node$2{name=`shortcode_inline`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,selectable:!0,atom:!0,attrs:{id:{default:void 0},content:{default:``},nesting:{default:0},error:{default:``}},parseDOM:[{tag:`span.kb-shortcode-inline`,getAttrs:e=>({content:e.textContent||null})}],toDOM(e){return[`span`,{class:`kb-shortcode-inline`},e.attrs.content||``]}}}getInputRules(e){return[replaceInlineNode(/\{\{[^}]+\}\}/,e,e=>({content:fixCharacters$1(e[0].substring(2,e[0].length-2))}))]}getCommandFactories(e,t){return{renderShortCode:e=>(n,r)=>{let a=n.tr;return a=replaceAllNodesOfType(a,n.doc,t,e),a.docChanged&&r&&r(a),!0}}}},NodeIframe=class extends Node$2{name=`iframe`;requires=[`doc`];getNodeSpec(){return{inline:!0,attrs:{src:{},class:{default:null},alt:{default:null},title:{default:null}},group:`inline`,draggable:!0,parseDOM:[{tag:`iframe[src]`,getAttrs(e){return{src:e.getAttribute(`src`),title:e.getAttribute(`title`),alt:e.getAttribute(`alt`)}}}],toDOM(e){let{src:t,alt:n,title:r}=e.attrs;return[`iframe`,{src:t,alt:n,title:r,class:e.attrs.class}]}}}};function collectCommentAnchors(e){let t=new Map,n=new Map;return e.descendants((e,r)=>{e.type.name===`comment`&&(e.attrs.nesting===1&&t.set(e.attrs.id,r),e.attrs.nesting===-1&&n.set(e.attrs.id,r))}),{starts:t,ends:n}}function buildCommentRanges(e){let{starts:t,ends:n}=collectCommentAnchors(e),r=[];for(let[e,a]of t){let t=n.get(e);!t||t<=a||r.push({id:e,from:a+1,to:t})}return r}function buildDecorations(e){let t=buildCommentRanges(e);return DecorationSet.create(e,t.map(({id:e,from:t,to:n})=>Decoration.inline(t,n,{class:`comment-highlight`,"data-comment-id":e})))}function commentsPlugin(){return new Plugin({state:{init(e,{doc:t}){return buildDecorations(t)},apply(e,t,n,r){return e.docChanged?buildDecorations(r.doc):t}},props:{decorations(e){return this.getState(e)}}})}var addCommentBoundary=e=>(t,n)=>{let{schema:r,selection:a}=t,{from:o,to:s}=a,c=r.nodes.comment;if(!c)return!1;let l=c.create({id:e,nesting:1}),u=c.create({id:e,nesting:-1}),d=t.tr;return d.insert(s,u),d.insert(o,l),n&&n(d),!0},NodeCommentAnchor=class extends Node$2{name=`comment`;requires=[`doc`];options={keepMarks:!0};getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,atom:!0,attrs:{id:{},active:{default:!1},nesting:{default:1}},parseDOM:[{tag:`span[data-comment-id]`,getAttrs(e){return{id:e.getAttribute(`data-comment-id`),nesting:parseInt(e.getAttribute(`data-nesting`)||`1`),active:e.hasAttribute(`data-active`)}}}],toDOM:e=>[`span`,{"data-comment-id":e.attrs.id,"data-active":e.attrs.active?`true`:void 0,"data-nesting":e.attrs.nesting}]}}getCommandFactories(e,t){return{addComment:(e,t)=>addCommentBoundary(e,t)}}getProseMirrorPlugins(){return[commentsPlugin()]}};function splitListItem(e,t){let n=function(n,r){let{$from:a,$to:o,node:s}=n.selection;if(s&&s.isBlock||a.depth<2||!a.sameParent(o))return!1;let c=a.node(-1);if(c.type!=e)return!1;if(a.parent.content.size==0&&a.node(-1).childCount==a.indexAfter(-1)){if(a.depth==3||a.node(-3).type!=e||a.index(-2)!=a.node(-2).childCount-1)return!1;if(r){let t=Fragment.empty,o=a.index(-1)?1:a.index(-2)?2:3;for(let e=a.depth-o;e>=a.depth-3;e--)t=Fragment.from(a.node(e).copy(t));let s=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3;t=t.append(Fragment.from(e.createAndFill()));let c=a.before(a.depth-(o-1)),l=n.tr.replace(c,a.after(-s),new Slice(t,4-o,0)),u=-1;l.doc.nodesBetween(c,l.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&e.content.size==0&&(u=t+1)}),u>-1&&l.setSelection(Selection.near(l.doc.resolve(u))),r(l.scrollIntoView())}return!0}let l=o.pos==a.end()?c.contentMatchAt(0).defaultType:null,u=n.tr.delete(a.pos,o.pos),d=l?[t?{type:e,attrs:t}:null,{type:l}]:void 0;return canSplit(u.doc,a.pos,2,d)?(r&&r(u.split(a.pos,2,d).scrollIntoView()),!0):!1};return n.displayName=`splitListItem(${e.name})`,n}function liftListItem(e){return function(t,n){let{$from:r,$to:a}=t.selection,o=r.blockRange(a,t=>t.childCount>0&&t.firstChild.type==e);return o?n?r.node(o.depth-1).type==e?liftToOuterList(t,n,e,o):liftOutOfList(t,n,o):!0:!1}}function liftToOuterList(e,t,n,r){let a=e.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(a.step(new ReplaceAroundStep(o-1,s,o,s,new Slice(Fragment.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new NodeRange(a.doc.resolve(r.$from.pos),a.doc.resolve(s),r.depth));let c=liftTarget(r);if(c==null)return!1;a.lift(r,c);let l=a.doc.resolve(a.mapping.map(o,-1)-1);return canJoin(a.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&a.join(l.pos),t(a.scrollIntoView()),!0}function liftOutOfList(e,t,n){let r=e.tr,a=n.parent;for(let e=n.end,t=n.endIndex-1,o=n.startIndex;t>o;t--)e-=a.child(t).nodeSize,r.delete(e-1,e+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let c=n.startIndex==0,l=n.endIndex==a.childCount,u=o.node(-1),d=o.index(-1);if(!u.canReplace(d+ +!c,d+1,s.content.append(l?Fragment.empty:Fragment.from(a))))return!1;let f=o.pos,p=f+s.nodeSize;return r.step(new ReplaceAroundStep(f-+!!c,p+ +!!l,f+1,p-1,new Slice((c?Fragment.empty:Fragment.from(a.copy(Fragment.empty))).append(l?Fragment.empty:Fragment.from(a.copy(Fragment.empty))),+!c,+!l),+!c)),t(r.scrollIntoView()),!0}function sinkListItem(e){return function(t,n){let{$from:r,$to:a}=t.selection,o=r.blockRange(a,t=>t.childCount>0&&t.firstChild.type==e);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let c=o.parent,l=c.child(s-1);if(l.type!=e)return!1;if(n){let r=l.lastChild&&l.lastChild.type==c.type,a=Fragment.from(r?e.create():null),s=new Slice(Fragment.from(e.create(null,Fragment.from(c.type.create(null,a)))),r?3:1,0),u=o.start,d=o.end;n(t.tr.step(new ReplaceAroundStep(u-(r?3:1),d,u,d,s,1,!0)).scrollIntoView())}return!0}}var isList=e=>e.endsWith(`_list`),clearNodes=()=>(e,t)=>{let n=e.tr,{selection:r}=n,{ranges:a}=r;return t&&a.forEach(({$from:t,$to:r})=>{e.doc.nodesBetween(t.pos,r.pos,(e,t)=>{if(e.type.isText)return;let{doc:r,mapping:a}=n,o=r.resolve(a.map(t)),s=r.resolve(a.map(t+e.nodeSize)),c=o.blockRange(s);if(!c)return;let l=liftTarget(c);if(e.type.isTextblock){let{defaultType:e}=o.parent.contentMatchAt(o.index());n.setNodeMarkup(c.start,e)}(l||l===0)&&n.lift(c,l)})}),!0};function findParentNodeClosestToPos(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function findParentNode(e){return t=>findParentNodeClosestToPos(t.$from,e)}var joinListBackwards=(e,t)=>{let n=findParentNode(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let a=e.doc.nodeAt(r);return n.node.type===a?.type&&canJoin(e.doc,n.pos)&&e.join(n.pos),!0},joinListForwards=(e,t)=>{let n=findParentNode(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let a=e.doc.nodeAt(r);return n.node.type===a?.type&&canJoin(e.doc,r)&&e.join(r),!0},toggleList=(e,t,n,r={})=>function(a,o,s){if(!this)throw Error(`Call this with Function.apply`);let c=this.editor,l=Object.keys(a.schema.marks).filter(e=>e!==`link`),u=a.schema.nodes[e],d=a.schema.nodes[t],{selection:f,storedMarks:p}=a,{$from:m,$to:h}=f,g=m.blockRange(h),_=p||(f.$to.parentOffset?f.$from.marks():[]);if(!g)return!1;let v=findParentNode(e=>isList(e.type.name))(f),y=a.tr;if(g.depth>=1&&v&&g.depth-v.depth<=1){if(v.node.type===u)return liftListItem(d).apply(this,[a,o,s]);if(isList(v.node.type.name)&&u.validContent(v.node.content)&&o)return c.chain(y).command(()=>(y.setNodeMarkup(v.pos,u),!0)).command(()=>joinListBackwards(y,u)).command(()=>joinListForwards(y,u)).command(()=>o(y)).run()}return!n||!_||!o?c.chain(y).command(()=>c.can().wrapInList(u,r).run()?!0:c.chain(y).lift().run()).wrapInList(u,r).command(()=>joinListBackwards(y,u)).command(()=>joinListForwards(y,u)).command(()=>(o&&o(y),!0)).run():c.chain(y).command(()=>{let e=c.can().wrapInList(u,r).run(),t=_.filter(e=>l.includes(e.type.name));return y.ensureMarks(t),e?!0:(v&&y.setSelection(NodeSelection.create(a.doc,v.pos)),clearNodes().apply(this,[a,o,s]))}).wrapInList(u,r).command(()=>joinListBackwards(y,u)).command(()=>joinListForwards(y,u)).command(()=>(o&&o(y),!0)).run()},NodeOrderedList=class extends Node$2{name=`ordered_list`;requires=[`doc`];attributes={type:{default:`1`,fromDom(e){return e.hasAttribute(`type`)?e.getAttribute(`type`):`1`}},start:{default:void 0,fromDom(e){return e.hasAttribute(`start`)?+e.getAttribute(`start`):void 0}},id:{default:void 0},continue:{default:void 0},odtMarginLeft:{default:void 0}};getNodeSpec(){return{content:`list_item+`,group:`block list`,parseDOM:[{tag:`ol`,getAttrs:e=>setHtmlAttributes(this,e)}],toDOM:e=>[`ol`,getHtmlAttributes(this,e),0]}}getInputRules(e){return[wrappingInputRule(/^(\d+)\.\s$/,e,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order==+e[1])]}getCommandFactories(e,t){let n=!1;return{toggleOrderedList:()=>toggleList(`ordered_list`,`list_item`,!1)}}getKeyboardShortcuts(){return{"Shift-Ctrl-7":`toggleOrderedList`}}},NodeBulletList=class extends Node$2{name=`bullet_list`;requires=[`doc`];attributes={toc:{default:void 0},odtMarginLeft:{default:void 0}};getNodeSpec(){return{content:`list_item+`,group:`block list`,parseDOM:[{tag:`ul`}],toDOM(){return[`ul`,0]}}}getInputRules(e){return[wrappingInputRule(/^\s*([-+*])\s$/,e)]}getCommandFactories(e,t){let n=!1;return{toggleBulletList:()=>toggleList(`bullet_list`,`list_item`,!1)}}getKeyboardShortcuts(){return{"Shift-Ctrl-8":`toggleBulletList`}}},NodeListItem=class extends Node$2{name=`list_item`;requires=[`doc`];attributes={value:{default:void 0},type:{default:void 0,fromDom(e){return e.hasAttribute(`type`)?e.getAttribute(`type`):void 0},toDom(e){return e.attrs.type}}};getNodeSpec(){return{content:`paragraph block*`,defining:!0,parseDOM:[{tag:`li`,getAttrs:e=>setHtmlAttributes(this,e)}],toDOM:e=>[`li`,getHtmlAttributes(this,e),0]}}getCommandFactories(e,t){return{splitListItem:()=>splitListItem(t),liftListItem:()=>liftListItem(t),sinkListItem:()=>sinkListItem(t)}}getKeyboardShortcuts(){return{Enter:`splitListItem`,Tab:`sinkListItem`,"Shift-Tab":`liftListItem`}}},NodeTaskList=class extends Node$2{name=`task_list`;requires=[`doc`];getNodeSpec(){return{content:`task_item+`,group:`block list`,parseDOM:[{tag:`ul[data-type="${this.name}"]`}],toDOM:()=>[`ul`,{"data-type":this.name},0]}}getCommandFactories(){return{toggleTaskList:()=>toggleList(`task_list`,`task_item`)}}getKeyboardShortcuts(){return{"Shift-Ctrl-9":`toggleTaskList`}}},NodeViewTaskItem=class e{editor;dom;contentDOM;checkbox;node;view;getPos;config={};constructor(e,...t){this.editor=e,this.node=t[0],this.view=t[1],this.getPos=t[2];let n=document.createElement(`li`);this.dom=n;let r=document.createElement(`label`);r.contentEditable=`false`;let a=document.createElement(`input`);this.checkbox=a,a.type=`checkbox`,a.checked=this.node.attrs.checked,r.append(a);let o=document.createElement(`div`);this.contentDOM=o,n.append(r,o),n.dataset.checked=this.node.attrs.checked,a.addEventListener(`mousedown`,e=>e.preventDefault()),a.addEventListener(`change`,t=>{let n=this.getPos();if(typeof n!=`number`)return;this.editor.view.editable;let{checked:r}=t.target,a=e.state.tr,o=a.doc.nodeAt(n);a.setNodeMarkup(n,void 0,{...o?.attrs,checked:r}),e.dispatchTransaction(a)})}static create=(t,...n)=>new e(t,...n);update(e){return e.type.name===this.node.type.name?(this.dom.dataset.checked=e.attrs.checked,this.checkbox.checked=e.attrs.checked,!0):!1}},NodeTaskItem=class extends Node$2{config;name=`task_item`;requires=[`doc`];constructor(e={nested:!0}){super(e),this.config=e}getNodeSpec(){return{attrs:{checked:{default:!1}},content:this.config.nested?`paragraph block*`:`paragraph+`,defining:!0,parseDOM:[{tag:`li[data-checked]`,getAttrs(e){return{checked:e.getAttribute(`data-checked`)===`true`}}}],toDOM:e=>[`li`,{"data-type":this.name,"data-checked":e.attrs.checked},[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null},[`span`]],[`div`,0]]]}}getCommandFactories(e,t){return{splitListItem:()=>splitListItem(t),liftListItem:()=>liftListItem(t),sinkListItem:()=>sinkListItem(t)}}getNodeView(e){return(...t)=>NodeViewTaskItem.create(e,...t)}getKeyboardShortcuts(){return{Enter:`splitListItem`,Tab:`sinkListItem`,"Shift-Tab":`liftListItem`}}getInputRules(e){return[wrappingInputRule(/^\s*(\[([( |x])?\])\s$/,e,e=>({checked:e[e.length-1]===`x`}))]}},BasicEditorKit=class{getExtensions(){return[new ExtensionBaseKeymap,new ExtensionDropcursor,new ExtensionGapcursor,new ExtensionHtml,new ExtensionMediaUpload,new ExtensionRemoteSelection,new ExtensionSelection,new ExtensionTextAlign,new ExtensionPairing,new ExtensionUser,new ExtensionPaste,new NodeDocument,new NodeText,new NodeParagraph,new NodeHardBreak,new NodeSoftBreak,new NodeCodeBlock$1,new NodeBookmark,new NodeHorizontalRule,new NodeOrderedList,new NodeBulletList,new NodeListItem,new NodeTaskList,new NodeTaskItem,new NodeDefinitionList,new NodeDefinitionTerm,new NodeDefinitionDesc,new NodeTaskList,new NodeTaskItem,new NodeImage,new NodeVideo,new NodeBlockquote,new NodeAside,new NodeHeading,new NodeMath,new NodeInlineShortCode,new NodeIframe,new NodeCommentAnchor,new MarkLink,new MarkItalic,new MarkStrong,new MarkUnderline,new MarkStrike,new MarkCode,new MarkChange,new MarkBookmark,new MarkTextColor,new MarkHighlight,new MarkSuperscript,new MarkSubscript]}},kit=new BasicEditorKit,ExtensionBasicEditor=class extends Extension{name=`basic-editor`;requires=kit.getExtensions()},GOOD_LEAF_SIZE=200,RopeSequence=class e{append(t){return t.length?(t=e.from(t),!this.length&&t||t.length<GOOD_LEAF_SIZE&&this.leafAppend(t)||this.length<GOOD_LEAF_SIZE&&t.leafPrepend(this)||this.appendInner(t)):this}prepend(t){return t.length?e.from(t).append(this):this}appendInner(e){return new Append(this,e)}slice(e=0,t=this.length){return e>=t?emptyRopeSequence():this.sliceInner(Math.max(0,e),Math.min(this.length,t))}get(e){if(!(e<0||e>=this.length))return this.getInner(e)}forEach(e,t=0,n=this.length){t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)}map(e,t=0,n=this.length){let r=[];return this.forEach((t,n)=>(r.push(e(t,n)),t),t,n),r}static from(t){return t instanceof e?t:t&&t.length?new Leaf(t):emptyRopeSequence()}},Leaf=class e extends RopeSequence{values;constructor(e){super(),this.values=e}flatten(){return this.values}sliceInner(t,n){return t==0&&n==this.length?this:new e(this.values.slice(t,n))}getInner(e){return this.values[e]}forEachInner(e,t,n,r){for(let a=t;a<n;a++)if(e(this.values[a],r+a)===!1)return!1;return!0}forEachInvertedInner(e,t,n,r){for(let a=t-1;a>=n;a--)if(e(this.values[a],r+a)===!1)return!1;return!0}leafAppend(t){if(this.length+t.length<=GOOD_LEAF_SIZE)return new e(this.values.concat(t.flatten()))}leafPrepend(t){if(this.length+t.length<=GOOD_LEAF_SIZE)return new e(t.flatten().concat(this.values))}get length(){return this.values.length}get depth(){return 0}};function emptyRopeSequence(){return new Leaf([])}var Append=class e extends RopeSequence{left;right;depth;length;constructor(e,t){super(),this.left=e,this.right=t,this.length=e.length+t.length,this.depth=Math.max(e.depth,t.depth)+1}flatten(){return this.left.flatten().concat(this.right.flatten())}getInner(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)}forEachInner(e,t,n,r){let a=this.left.length;return!(t<a&&this.left.forEachInner(e,t,Math.min(n,a),r)===!1||n>a&&this.right.forEachInner(e,Math.max(t-a,0),Math.min(this.length,n)-a,r+a)===!1)}forEachInvertedInner(e,t,n,r){let a=this.left.length;return!(t>a&&this.right.forEachInvertedInner(e,t-a,Math.max(n,a)-a,r+a)===!1||n<a&&this.left.forEachInvertedInner(e,Math.min(t,a),n,r)===!1)}sliceInner(e,t){if(e==0&&t==this.length)return this;let n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))}leafAppend(t){let n=this.right.leafAppend(t);if(n)return new e(this.left,n)}leafPrepend(t){let n=this.left.leafPrepend(t);if(n)return new e(n,this.right)}appendInner(t){return this.left.depth>=Math.max(this.right.depth,t.depth)+1?new e(this.left,new e(this.right,t)):new e(this,t)}},max_empty_items=500,Branch=class e{items;eventCount;constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let a,o;n&&(a=this.remapping(r,this.items.length),o=a.maps.length);let s=t.tr,c,l,u=[],d=[];return this.items.forEach((t,n)=>{if(!t.step)return a||(a=this.remapping(r,n+1),o=a.maps.length),o--,d.push(t),t;if(a){d.push(new Item(t.map));let e=t.step.map(a.slice(o)),n;e&&s.maybeStep(e).doc&&(n=s.mapping.maps[s.mapping.maps.length-1],u.push(new Item(n,void 0,void 0,u.length+d.length))),o--,n&&a.appendMap(n,o)}else s.maybeStep(t.step);return t.selection?(c=a?t.selection.map(a.slice(o)):t.selection,l=new e(this.items.slice(0,r).append(d.reverse().concat(u)),this.eventCount-1),!1):t},this.items.length,0),{remaining:l,transform:s,selection:c}}addTransform(t,n,r,a){let o=[],s=this.eventCount,c=this.items,l=!a&&c.length?c.get(c.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),u=new Item(t.mapping.maps[e],r,n),d;(d=l&&l.merge(u))&&(u=d,e?o.pop():c=c.slice(0,c.length-1)),o.push(u),n&&=(s++,void 0),a||(l=u)}let u=s-r.depth;return u>DEPTH_OVERFLOW&&(c=cutOffEvents(c,u),s-=u),new e(c.append(o),s)}remapping(e,t){let n=new Mapping;return this.items.forEach((t,r)=>{let a=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;return n.appendMap(t.map,a),t},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new Item(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],a=Math.max(0,this.items.length-n),o=t.mapping,s=t.steps.length,c=this.eventCount;this.items.forEach(e=>(e.selection&&c--,e),a);let l=n;this.items.forEach(e=>{let n=o.getMirror(--l);if(n==null)return!1;s=Math.min(s,n);let a=o.maps[n];if(e.step){let s=t.steps[n].invert(t.docs[n]),u=e.selection&&e.selection.map(o.slice(l+1,n));u&&c++,r.push(new Item(a,s,u))}else r.push(new Item(a));return e},a);let u=[];for(let e=n;e<s;e++)u.push(new Item(o.maps[e]));let d=new e(this.items.slice(0,a).append(u).append(r),c);return d.emptyItemCount()>max_empty_items&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>(t.step||e++,t)),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,a=[],o=0;return this.items.forEach((e,s)=>{if(s>=t)a.push(e),e.selection&&o++;else if(e.step){let t=e.step.map(n.slice(r)),s=t&&t.getMap();if(r--,s&&n.appendMap(s,r),t){let c=e.selection&&e.selection.map(n.slice(r));c&&o++;let l=new Item(s.invert(),t,c),u,d=a.length-1;(u=a.length&&a[d].merge(l))?a[d]=u:a.push(l)}}else e.map&&r--;return e},this.items.length,0),new e(RopeSequence.from(a.reverse()),o)}static empty=new e(emptyRopeSequence(),0)};function cutOffEvents(e,t){let n;return e.forEach((e,r)=>e.selection&&t--==0?(n=r,!1):e),e.slice(n)}var Item=class e{map;step;selection;mirrorOffset;constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},HistoryState=class{done;undone;prevRanges;prevTime;prevComposition;constructor(e,t,n,r,a){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=a}},DEPTH_OVERFLOW=20;function applyTransaction(e,t,n,r){let a=n.getMeta(historyKey),o;if(a)return a.historyState;n.getMeta(closeHistoryKey)&&(e=new HistoryState(e.done,e.undone,null,0,-1));let s=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(s&&s.getMeta(historyKey))return s.getMeta(historyKey).redo?new HistoryState(e.done.addTransform(n,void 0,r,mustPreserveItems(t)),e.undone,rangesFor(n.mapping.maps),e.prevTime,e.prevComposition):new HistoryState(e.done,e.undone.addTransform(n,void 0,r,mustPreserveItems(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(s&&s.getMeta(`addToHistory`)===!1)){let a=n.getMeta(`composition`),o=e.prevTime==0||!s&&e.prevComposition!=a&&(e.prevTime<(n.time||0)-r.newGroupDelay||!isAdjacentTo(n,e.prevRanges)),c=s?mapRanges(e.prevRanges,n.mapping):rangesFor(n.mapping.maps);return new HistoryState(e.done.addTransform(n,o?t.selection.getBookmark():void 0,r,mustPreserveItems(t)),Branch.empty,c,n.time,a??e.prevComposition)}else if(o=n.getMeta(`rebased`))return new HistoryState(e.done.rebased(n,o),e.undone.rebased(n,o),mapRanges(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new HistoryState(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),mapRanges(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function isAdjacentTo(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let a=0;a<t.length;a+=2)e<=t[a+1]&&r>=t[a]&&(n=!0)}),n}function rangesFor(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,a)=>t.push(r,a));return t}function mapRanges(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let a=t.map(e[r],1),o=t.map(e[r+1],-1);a<=o&&n.push(a,o)}return n}function histTransaction(e,t,n){let r=mustPreserveItems(t),a=historyKey.get(t).spec.config,o=(n?e.undone:e.done).popEvent(t,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),c=(n?e.done:e.undone).addTransform(o.transform,t.selection.getBookmark(),a,r),l=new HistoryState(n?c:o.remaining,n?o.remaining:c,null,0,-1);return o.transform.setSelection(s).setMeta(historyKey,{redo:n,historyState:l})}var cachedPreserveItems=!1,cachedPreserveItemsPlugins=null;function mustPreserveItems(e){let t=e.plugins;if(cachedPreserveItemsPlugins!=t){cachedPreserveItems=!1,cachedPreserveItemsPlugins=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){cachedPreserveItems=!0;break}}return cachedPreserveItems}var historyKey=new PluginKey(`history`),closeHistoryKey=new PluginKey(`closeHistory`);function history$1(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Plugin({key:historyKey,state:{init(){return new HistoryState(Branch.empty,Branch.empty,null,0,-1)},apply(t,n,r){return applyTransaction(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?undo:n==`historyRedo`?redo:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function buildCommand(e,t){return(n,r)=>{let a=historyKey.getState(n);if(!a||(e?a.undone:a.done).eventCount==0)return!1;if(r){let o=histTransaction(a,n,e);o&&r(t?o.scrollIntoView():o)}return!0}}var undo=buildCommand(!1,!0),redo=buildCommand(!0,!0),undoNoScroll=buildCommand(!1,!1),redoNoScroll=buildCommand(!0,!1),ExtensionHistory$1=class extends Extension{name=`history`;options={depth:100,newGroupDelay:500};getCommandFactories(e){return{undo:()=>undo,redo:()=>redo}}getKeyboardShortcuts(){let e=typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator?.platform):!1,t={"Mod-z":`undo`,"Mod-y":`redo`};return e||(t[`Mod-y`]=`redo`),t}getProseMirrorPlugins(){return[history$1(this.options)]}},Token=class{type;tag;nesting;attrs=null;map=null;level=0;children=null;content=``;markup=``;info=``;meta=null;block=!1;hidden=!1;constructor(e,t,n){this.type=e,this.tag=t,this.nesting=n}attrIndex(e){if(!this.attrs)return-1;let t=this.attrs;for(let n=0,r=t.length;n<r;n++)if(t[n][0]===e)return n;return-1}attrPush(e){this.attrs?this.attrs.push(e):this.attrs=[e]}attrSet(e,t){let n=this.attrIndex(e),r=[e,t];n<0||!this.attrs?this.attrPush(r):this.attrs[n]=r}attrGet(e){let t=this.attrIndex(e),n=null;return t>=0&&this.attrs&&(n=this.attrs[t][1]),n}attrJoin(e,t){let n=this.attrIndex(e);n<0||!this.attrs?this.attrPush([e,t]):this.attrs[n][1]=this.attrs[n][1]+` `+t}},Brackets={left:[`(`,`[`,`{`,`|`,`‖`,`⟨`,`⌊`,`⌈`,`⌜`],right:[`)`,`]`,`}`,`|`,`‖`,`⟩`,`⌋`,`⌉`,`⌝`],isPair:function(e,t){let n=this.left.indexOf(e);return t===this.right[n]},contains:function(e){return this.isLeft(e)||this.isRight(e)},isLeft:function(e){return this.left.indexOf(e)>-1},isRight:function(e){return this.right.indexOf(e)>-1},parseLeft:function(e,t=!0){if(this.left.indexOf(e)<0)return e;let n=``;switch(e){case`(`:case`[`:case`|`:n=`\\left${e}`;break;case`‖`:n=`\\left\\|`;break;case`{`:n=`\\left\\{`;break;case`⟨`:n=`\\left\\langle `;break;case`⌊`:n=`\\left\\lfloor `;break;case`⌈`:n=`\\left\\lceil `;break;case`⌜`:n=`\\left\\ulcorner `;break}return t?n:n.replace(`\\left`,``)},parseRight:function(e,t=!0){if(this.right.indexOf(e)<0)return e;let n=``;switch(e){case`)`:case`]`:case`|`:n=`\\right${e}`;break;case`‖`:n=`\\right\\|`;break;case`}`:n=`\\right\\}`;break;case`⟩`:n=` \\right\\rangle`;break;case`⌋`:n=` \\right\\rfloor`;break;case`⌉`:n=` \\right\\rceil`;break;case`⌝`:n=` \\right\\urcorner`;break}return t?n:n.replace(`\\right`,``)}},MathSymbol={parseIdentifier:function(e){if(e.length===0)return``;if(e.length===1){let t=e.charCodeAt(0),n=this.greekLetter.decimals.indexOf(t);return n>-1?this.greekLetter.scripts[n]+` `:e}else return this.parseMathFunction(e)},parseOperator:function(e){if(e.length===0)return``;if(e.length===1){let t=e.charCodeAt(0),n=[this.bigCommand,this.relation,this.binaryOperation,this.setAndLogic,this.delimiter,this.other],r=[!1,!0,!0,!1,!1,!1];for(let e=0;e<n.length;e++){let a=n[e],o=a.decimals.indexOf(t);if(o>-1)return r[e]?[` `,a.scripts[o],` `].join(``):a.scripts[o]+` `}return e}else return this.parseMathFunction(e)},parseMathFunction:function(e){let t=T.createMarker(),n=[];return this.mathFunction.names.forEach((r,a)=>{let o=new RegExp(r,`g`);e.match(o)&&(n.push(this.mathFunction.scripts[a]),e=e.replace(o,t.next()+` `))}),t.replaceBack(e,n)},overScript:{decimals:[9182],templates:[`\\overbrace{@v}`]},underScript:{decimals:[9183],templates:[`\\underbrace{@v}`]},bigCommand:{decimals:[8721,8719,8720,10753,10754,10752,8899,8898,10756,10758,8897,8896,8747,8750,8748,8749,10764,8747],scripts:[`\\sum`,`\\prod`,`\\coprod`,`\\bigoplus`,`\\bigotimes`,`\\bigodot`,`\\bigcup`,`\\bigcap`,`\\biguplus`,`\\bigsqcup`,`\\bigvee`,`\\bigwedge`,`\\int`,`\\oint`,`\\iint`,`\\iiint`,`\\iiiint`,`\\idotsint`]},relation:{decimals:[60,62,61,8741,8742,8804,8805,8784,8781,8904,8810,8811,8801,8866,8867,8834,8835,8776,8712,8715,8838,8839,8773,8995,8994,8840,8841,8771,8872,8713,8847,8848,126,8764,8869,8739,8849,8850,8733,8826,8827,10927,10928,8800,8738,8737],scripts:`<.>.=.\\parallel.\\nparallel.\\leq.\\geq.\\doteq.\\asymp.\\bowtie.\\ll.\\gg.\\equiv.\\vdash.\\dashv.\\subset.\\supset.\\approx.\\in.\\ni.\\subseteq.\\supseteq.\\cong.\\smile.\\frown.\\nsubseteq.\\nsupseteq.\\simeq.\\models.\\notin.\\sqsubset.\\sqsupset.\\sim.\\sim.\\perp.\\mid.\\sqsubseteq.\\sqsupseteq.\\propto.\\prec.\\succ.\\preceq.\\succeq.\\neq.\\sphericalangle.\\measuredangle`.split(`.`)},binaryOperation:{decimals:[43,45,177,8745,8900,8853,8723,8746,9651,8854,215,8846,9661,8855,247,8851,9667,8856,8727,8852,9657,8857,8902,8744,9711,8728,8224,8743,8729,8726,8225,8901,8768,10815],scripts:`+.-.\\pm.\\cap.\\diamond.\\oplus.\\mp.\\cup.\\bigtriangleup.\\ominus.\\times.\\uplus.\\bigtriangledown.\\otimes.\\div.\\sqcap.\\triangleleft.\\oslash.\\ast.\\sqcup.\\triangleright.\\odot.\\star.\\vee.\\bigcirc.\\circ.\\dagger.\\wedge.\\bullet.\\setminus.\\ddagger.\\cdot.\\wr.\\amalg`.split(`.`)},setAndLogic:{decimals:[8707,8594,8594,8708,8592,8592,8704,8614,172,10233,8834,8658,10233,8835,8596,8712,10234,8713,8660,8715,8868,8743,8869,8744,8709,8709],scripts:`\\exists.\\rightarrow.\\to.\\nexists.\\leftarrow.\\gets.\\forall.\\mapsto.\\neg.\\implies.\\subset.\\Rightarrow.\\implies.\\supset.\\leftrightarrow.\\in.\\iff.\\notin.\\Leftrightarrow.\\ni.\\top.\\land.\\bot.\\lor.\\emptyset.\\varnothing`.split(`.`)},delimiter:{decimals:[124,8739,8214,47,8726,123,125,10216,10217,8593,8657,8968,8969,8595,8659,8970,8971],scripts:[`|`,`\\mid`,`\\|`,`/`,`\\backslash`,`\\{`,`\\}`,`\\langle`,`\\rangle`,`\\uparrow`,`\\Uparrow`,`\\lceil`,`\\rceil`,`\\downarrow`,`\\Downarrow`,`\\lfloor`,`\\rfloor`]},greekLetter:{decimals:[913,945,925,957,914,946,926,958,915,947,927,959,916,948,928,960,982,917,1013,949,929,961,1009,918,950,931,963,962,919,951,932,964,920,952,977,933,965,921,953,934,981,966,922,954,1008,935,967,923,955,936,968,924,956,937,969],scripts:`A.\\alpha.N.\\nu.B.\\beta.\\Xi.\\xi.\\Gamma.\\gamma.O.o.\\Delta.\\delta.\\Pi.\\pi.\\varpi.E.\\epsilon.\\varepsilon.P.\\rho.\\varrho.Z.\\zeta.\\Sigma.\\sigma.\\varsigma.H.\\eta.T.\\tau.\\Theta.\\theta.\\vartheta.\\Upsilon.\\upsilon.I.\\iota.\\Phi.\\phi.\\varphi.K.\\kappa.\\varkappa.X.\\chi.\\Lambda.\\lambda.\\Psi.\\psi.M.\\mu.\\Omega.\\omega`.split(`.`)},other:{decimals:[8706,305,8476,8711,8501,240,567,8465,9723,8502,8463,8467,8472,8734,8503],scripts:[`\\partial`,`\\imath`,`\\Re`,`\\nabla`,`\\aleph`,`\\eth`,`\\jmath`,`\\Im`,`\\Box`,`\\beth`,`\\hbar`,`\\ell`,`\\wp`,`\\infty`,`\\gimel`]},mathFunction:{names:`arcsin.sinh.sin.sec.arccos.cosh.cos.csc.arctan.tanh.tan.arccot.coth.cot.limsup.liminf.exp.ker.deg.gcd.lg.ln.Pr.sup.det.hom.lim.log.arg.dim.inf.max.min`.split(`.`),scripts:`\\arcsin.\\sinh.\\sin.\\sec.\\arccos.\\cosh.\\cos.\\csc.\\arctan.\\tanh.\\tan.\\arccot.\\coth.\\cot.\\limsup.\\liminf.\\exp.\\ker.\\deg.\\gcd.\\lg.\\ln.\\Pr.\\sup.\\det.\\hom.\\lim.\\log.\\arg.\\dim.\\inf.\\max.\\min`.split(`.`)}},T={};T.createMarker=function(){return{idx:-1,reReplace:/@\[\[(\d+)\]\]/gm,next:function(){return`@[[${++this.idx}]]`},replaceBack:function(e,t){return e.replace(this.reReplace,(e,n)=>t[parseInt(n)])}}};var root=typeof window<`u`?window:{};function canParseHTMLNatively(){let e=root.DOMParser,t=!1;try{new e().parseFromString(``,`text/html`)&&(t=!0)}catch{}return t}function createHTMLParser(){let e=function(){};return shouldUseActiveX()?e.prototype.parseFromString=function(e){let t=new window.ActiveXObject(`htmlfile`);return t.designMode=`on`,t.open(),t.write(e),t.close(),t}:e.prototype.parseFromString=function(e){let t=document.implementation.createHTMLDocument(``);return t.open(),t.write(e),t.close(),t},e}function shouldUseActiveX(){let e=!1;try{document.implementation.createHTMLDocument(``).open()}catch{window.ActiveXObject&&(e=!0)}return e}var HTMLParser=canParseHTMLNatively()?root.DOMParser:createHTMLParser(),NodeTool={parseMath:function(e){return new HTMLParser().parseFromString(e,`text/html`).querySelector(`math`)},getChildren:function(e){return e.children},getNodeName:function(e){return e.tagName.toLowerCase()},getNodeText:function(e){return e.textContent},getAttr:function(e,t,n){let r=e.getAttribute(t);return r===null?n:r},getPrevNode:function(e){return e.previousElementSibling},getNextNode:function(e){return e.nextElementSibling}};function convert(e){return toLatex(parse(NodeTool.parseMath(e)))}function toLatex(e){return e=e.replace(/\\left\(\\DELETE_BRACKET_L/g,``),e=e.replace(/\\DELETE_BRACKET_R\\right\)/g,``),e=e.replace(/\\DELETE_BRACKET_L/g,``),e=e.replace(/\\DELETE_BRACKET_R/g,``),e}function parse(e){let t=NodeTool.getChildren(e);return!t||t.length===0?parseLeaf(e):parseContainer(e,t)}function parseLeaf(e){let t=``;switch(NodeTool.getNodeName(e)){case`mi`:t=parseElementMi(e);break;case`mn`:t=parseElementMn(e);break;case`mo`:t=parseOperator(e);break;case`ms`:t=parseElementMs(e);break;case`mtext`:t=parseElementMtext(e);break;case`mglyph`:t=parseElementMglyph(e);break;case`mprescripts`:t=``;break;case`mspace`:t=parseElementMspace();case`none`:t=`\\:`;break;default:t=escapeSpecialChars(NodeTool.getNodeText(e).trim());break}return t}function parseOperator(e){let t=NodeTool.getNodeText(e).trim();return t=MathSymbol.parseOperator(t),escapeSpecialChars(t)}function parseElementMi(e){let t=NodeTool.getNodeText(e).trim();return t=MathSymbol.parseIdentifier(t),escapeSpecialChars(t)}function parseElementMn(e){return escapeSpecialChars(NodeTool.getNodeText(e).trim())}function parseElementMs(e){return[`"`,escapeSpecialChars(NodeTool.getNodeText(e).trimRight()),`"`].join(``)}function parseElementMtext(e){return`\\text{${escapeSpecialChars(NodeTool.getNodeText(e))}}`}function parseElementMglyph(e){return escapeSpecialChars([`"`,NodeTool.getAttr(e,`alt`,``),`"`].join(``))}function parseElementMspace(e){return``}function escapeSpecialChars(e){return e=e.replace(/\$|%|_|&|#|\{|\}/g,e=>`\\${e}`),e}function parseContainer(e,t){let n=getRender(e);if(n)return n(e,t);throw Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(e)}`)}function renderChildren(e){let t=[],n=[];if(Array.prototype.forEach.call(e,e=>{if(NodeTool.getNodeName(e)===`mo`){let r=NodeTool.getNodeText(e).trim();if(Brackets.contains(r)){let a=NodeTool.getAttr(e,`stretchy`,`true`);if(a=[``,`true`].indexOf(a)>-1,Brackets.isRight(r)){let e=n[n.length-1];e&&Brackets.isPair(e,r)?(t.push(Brackets.parseRight(r,a)),n.pop()):Brackets.isLeft(r)?(t.push(Brackets.parseLeft(r,a)),n.push(r)):console.error(`bracket not match`)}else t.push(Brackets.parseLeft(r,a)),n.push(r)}else t.push(parseOperator(e))}else t.push(parse(e))}),n.length>0)for(let e=0;e<n.length;e++)t.push(`\\right.`);return n=void 0,t}function getRender(e){let t;switch(NodeTool.getNodeName(e)){case`msub`:t=getRender_default(`@1_{@2}`);break;case`msup`:t=getRender_default(`@1^{@2}`);break;case`msubsup`:t=getRender_default(`@1_{@2}^{@3}`);break;case`mover`:t=renderMover;break;case`munder`:t=renderMunder;break;case`munderover`:t=getRender_default(`@1\\limits_{@2}^{@3}`);break;case`mmultiscripts`:t=renderMmultiscripts;break;case`mroot`:t=getRender_default(`\\sqrt[@2]{@1}`);break;case`msqrt`:t=getRender_joinSeparator(`\\sqrt{@content}`);break;case`mtable`:t=renderTable;break;case`mtr`:t=getRender_joinSeparator(`@content \\\\ `,` & `);break;case`mtd`:t=getRender_joinSeparator(`@content`);break;case`mfrac`:t=renderMfrac;break;case`mfenced`:t=renderMfenced;break;case`mi`:case`mn`:case`mo`:case`ms`:case`mtext`:t=getRender_joinSeparator(`@content`);break;case`mphantom`:t=renderMphantom;break;default:t=getRender_joinSeparator(`@content`);break}return t}function renderTable(e,t){return getRender_joinSeparator(`\\begin{matrix} @content \\end{matrix}`)(e,t)}function renderMfrac(e,t){let[n,r]=[NodeTool.getAttr(e,`linethickness`,`medium`),NodeTool.getAttr(e,`bevelled`,`false`)],a=null;if(r===`true`)a=getRender_default(`{}^{@1}/_{@2}`);else if([`0`,`0px`].indexOf(n)>-1){let[t,n]=[NodeTool.getPrevNode(e),NodeTool.getNextNode(e)];a=t&&NodeTool.getNodeText(t).trim()===`(`&&n&&NodeTool.getNodeText(n).trim()===`)`?getRender_default(`\\DELETE_BRACKET_L\\binom{@1}{@2}\\DELETE_BRACKET_R`):getRender_default(`{}_{@2}^{@1}`)}else a=getRender_default(`\\frac{@1}{@2}`);return a(e,t)}function renderMfenced(e,t){let[n,r,a]=[NodeTool.getAttr(e,`open`,`(`),NodeTool.getAttr(e,`close`,`)`),NodeTool.getAttr(e,`separators`,`,`)],[o,s]=[Brackets.parseLeft(n),Brackets.parseRight(r)],c=a.split(``).filter(e=>e.trim().length===1);return getRender_joinSeparators(`${o}@content${s}`,c)(e,t)}function renderMmultiscripts(e,t){if(t.length===0)return``;let n=-1,r=null;Array.prototype.forEach.call(t,e=>{NodeTool.getNodeName(e)===`mprescripts`&&(r=e)}),r&&(n=Array.prototype.indexOf.call(t,r));let a=renderChildren(t),o=(e,t)=>[e.slice(0,t),e.slice(t+1,e.length)],s=e=>{if(e.length>0){let t=[],n=[];return e.forEach((e,r)=>{(r+1)%2==0?n.push(e):t.push(e)}),[t.length>0?`_{${t.join(` `)}}`:``,n.length>0?`^{${n.join(` `)}}`:``].join(``)}else return``},c=a.shift(),l=[],u=[];return n===-1?u=a:[u,l]=o(a,n-1),[s(l),c,s(u)].join(``)}function renderMover(e,t){let n=flattenNodeTreeByNodeName(e,`mover`),r;for(let e=0;e<n.length-1;e++){r||=parse(n[e]);let t=parse(n[e+1]);r=renderTemplate(getMatchValueByChar({decimals:MathSymbol.overScript.decimals,values:MathSymbol.overScript.templates,judgeChar:t,defaultValue:`@1\\limits^{@2}`}).replace(`@v`,`@1`),[r,t])}return r}function renderMunder(e,t){let n=flattenNodeTreeByNodeName(e,`munder`),r;for(let e=0;e<n.length-1;e++){r||=parse(n[e]);let t=parse(n[e+1]);r=renderTemplate(getMatchValueByChar({decimals:MathSymbol.underScript.decimals,values:MathSymbol.underScript.templates,judgeChar:t,defaultValue:`@1\\limits_{@2}`}).replace(`@v`,`@1`),[r,t])}return r}function flattenNodeTreeByNodeName(e,t){let n=[],r=NodeTool.getChildren(e);return Array.prototype.forEach.call(r,e=>{NodeTool.getNodeName(e)===t?n=n.concat(flattenNodeTreeByNodeName(e,t)):n.push(e)}),n}function getMatchValueByChar(e){let{decimals:t,values:n,judgeChar:r,defaultValue:a=null}=e;if(r&&r.length===1){let e=t.indexOf(r.charCodeAt(0));if(e>-1)return n[e]}return a}function renderMphantom(e,t){return``}function getRender_default(e){return function(t,n){return renderTemplate(e,renderChildren(n))}}function renderTemplate(e,t){return e.replace(/\@\d+/g,e=>t[parseInt(e.substring(1,e.length))-1])}function getRender_joinSeparator(e,t=``){return function(n,r){let a=renderChildren(r);return e.replace(`@content`,a.join(t))}}function getRender_joinSeparators(e,t){return function(n,r){let a=renderChildren(r),o=``;return o=t.length===0?a.join(``):a.reduce((e,n,r)=>(e+=n,r<a.length-1&&(e+=t[r]||t[t.length-1]),e),``),e.replace(`@content`,o)}}var mathml2latex={convert};function fixCharacters(e){return e.replace(/’/g,`'`).replace(/“/g,`"`).replace(/”/g,`"`).replace(/\x0b/g,` `).replace(/\u201d/g,`"`).replace(/\u201c/g,`"`)}function numberString(e,t=`1`){return[`a`].includes(t)?String.fromCharCode(97+e-1)+`. `:[`A`].includes(t)?String.fromCharCode(65+e-1)+`. `:[`I`].includes(t)?`${romanize(e)}. `:[`i`].includes(t)?`${romanize(e).toLowerCase()}. `:([`1`].includes(t),`${e}. `)}function romanize(e){let t=[[`M`,1e3],[`CM`,900],[`D`,500],[`CD`,400],[`C`,100],[`XC`,90],[`L`,50],[`XL`,40],[`X`,10],[`IX`,9],[`V`,5],[`IV`,4],[`I`,1]],n=``;for(let[r,a]of t)for(;e>=a;)n+=r,e-=a;return n}function escapeMarkdown(e){let t=[{char:`\\`,escape:`\\\\`},{char:`#`,escape:`\\#`},{char:`<`,escape:`\\<`},{char:`…`,escape:`...`},{char:`©`,escape:`(c)`},{char:`®`,escape:`(r)`},{char:`™`,escape:`(tm)`},{char:`±`,escape:`+-`},{char:`—`,escape:`---`}],n=e.map&&e.map.length>0?e.map[0]:0;if(!n){let n=fixCharacters(e.content);for(let{char:e,escape:r}of t)n=n.replaceAll(e,r);return[[n,e]]}let r=fixCharacters(e.content).split(``),a=[],o=Object.fromEntries(t.map(e=>[e.char,e.escape])),s=0,c=``,l=``,u=()=>{if(l.length>0){let t=structuredClone(e);t.map=[n+s],a.push([l,t]),s=c.length}l=``};for(let e=0;e<r.length;e++){let t=r[e];c+=t,o[t]&&u(),l+=o[t]||t,o[t]&&u()}return u(),a}function getLinkTokensHandlers(){return{text:[(e,t)=>{t.current.meta.link_text+=e.content,e.content&&!t.current.meta.link_token_token&&(t.current.meta.link_token_token=e)}],link_close:[(e,t)=>{{let n=t.current.meta.link_open_token,r=n.attrGet(`href`)||``,a=n.attrGet(`title`)||``,o=n.attrGet(`origUrl`)||r,s=t.current.meta.link_text;o===s&&(s=r);let c=n.attrGet(`mdTemplate`);if(c){let n=r.split(`/`).pop();c=c.replaceAll(`$href`,r),c=c.replaceAll(`$basename`,n||``),c=c.replaceAll(`$label`,t.current.meta.link_text),c=c.replaceAll(`$title`,a||``),t.current.log(c,e)}else!a&&s===r?t.current.log(r,e):!a&&!r?(t.current.log(`[`,e),t.current.log(s,t.current.meta.link_token_token),t.current.log(`]${a}`,e)):(t.current.log(`[`,e),t.current.log(s,t.current.meta.link_token_token),a?t.current.log(`](${r} ${a})`,e):t.current.log(`](${r})`,e));t.unstash(`getLinkTokensHandlers.link_close`)}}],default:[(e,t)=>{}]}}function getInlineTokensHandlers(){return{text:[(e,t)=>{if(e.meta===`noEscText`)t.current.log(e.content);else for(let n of escapeMarkdown(e))t.current.log(n[0],n[1])}],entity:[(e,t)=>{t.current.log(e.content)}],strong_open:[(e,t)=>{t.current.log(e.markup||`**`,e)}],strong_close:[(e,t)=>{t.current.log(e.markup||`**`,e)}],em_open:[(e,t)=>{t.current.log(e.markup||`*`,e)}],em_close:[(e,t)=>{t.current.log(e.markup||`*`,e)}],underline_open:[(e,t)=>{t.current.log(e.markup||`_`,e)}],underline_close:[(e,t)=>{t.current.log(e.markup||`_`,e)}],strike_open:[(e,t)=>{t.current.log(e.markup||`~`,e)}],strike_close:[(e,t)=>{t.current.log(e.markup||`~`,e)}],link_open:[(e,t)=>{t.stash(`getInlineTokensHandlers.link_open`),t.current.handlers=getLinkTokensHandlers(),t.current.meta.link_open_token=e,t.current.meta.link_text=``,t.current.meta.link_token_token=null}],code_open:[(e,t)=>{t.current.log("`",e)}],code_close:[(e,t)=>{t.current.log("`",e)}],code_inline:[(e,t)=>{t.current.log("`"+e.content+"`",e)}],math:[(e,t)=>{let n=e.content;if(e.attrGet(`lang`)===`mathml`){let e=n.replace(/<annotation[\s\S]*?<\/annotation>/g,``);n=mathml2latex.convert(e)}t.current.log(`$`+n+`$`,e)}],hardbreak:[(e,t)=>{t.current.log(t.current.lineBreak+`
|
|
25
|
+
`,{node:t,pos:r})}return t.forEach((t,a)=>{nodeToTreeStringOutput(e,t,n+1,r+a+1)}),e}function nodeToTreeString(e){let t=new SmartOutput;return nodeToTreeStringOutput(t,e),t.toString()}var DummyEditorView=class{_props;directPlugins;nodeViews;prevDirectPlugins=[];pluginViews=[];state;focused=!1;constructor(e){this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(checkStateComponent),this.dispatch=this.dispatch.bind(this),this.editable=getEditable(this),this.nodeViews=buildNodeViews(this),this.updatePluginViews()}editable;get composing(){return!1}get dom(){return{addEventListener(){},removeEventListener(){}}}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){let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(checkStateComponent),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,a=!1;if(e.storedMarks&&this.composing,this.state=e,n.plugins!=e.plugins||this._props.plugins!=t.plugins||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=buildNodeViews(this);changedNodeViews(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}this.editable=getEditable(this),r||e.selection.eq(n.selection),this.updatePluginViews(n)}scrollToSelection(){}destroyPluginViews(){let e=this.pluginViews.pop();for(;e;)e.destroy&&e.destroy(),e=this.pluginViews.pop()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let a=this.directPlugins[n].props[e];if(a!=null&&(r=t?t(a):a))return r}let a=this.state.plugins;if(a)for(let n=0;n<a.length;n++){let o=a[n].props[e];if(o!=null&&(r=t?t(o):o))return r}}hasFocus(){return this.focused}focus(){this.focused=!0}destroy(){this.destroyPluginViews()}get isDestroyed(){return!1}dispatchEvent(e){}};DummyEditorView.prototype.dispatch=function(e){let t=this.props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function getEditable(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function buildNodeViews(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function changedNodeViews(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function checkStateComponent(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}function createNodeFromObject(e,t,n){try{let r=t.nodeFromJSON(e);return n?.errorOnInvalidContent&&r.check(),r}catch(r){if(n?.errorOnInvalidContent)throw Error(`Invalid JSON content: `+r.message,{cause:r});return console.warn(`Invalid content.`,`Passed value:`,e,`Error:`,r),t.topNodeType.createAndFill(null,[])}}function defaultUi(e){return{showMessage(e){globalThis.alert(e)},showError(e){globalThis.alert(e.message),console.error(e)},focus(){},select({anchor:e,scrollIntoView:t,userEvent:n}){}}}var Container=class{items=new Map;register(e,t){this.items.set(e,t)}resolve(e){return this.items.get(e)}};function ensureDocSchema(e,t){if(e.type.schema===t)return e;let n=e.toJSON();return Node$3.fromJSON(t,n)}var CoreEditor=class e extends EventTarget{schema;extensionManager;config;commandManager;view;state;ui=defaultUi(this);linkListener;linkSource;ci=new Container;version=0;constructor(e,t,n){super(),this.schema=t,this.extensionManager=n,this.config={...e},this.commandManager=new CommandManager(this)}static create(t){let n=new ExtensionManager(t.editorKits,t.debug),r=n.getSchemaByResolvedExtensions(),a=new e(t,r,n);n.created(a,r);let o=t.content?t.content:r.topNodeType.spec.EMPTY_DOC;return a.createView(o),a.setupPlugins(),a.dispatchEvent(new CustomEvent(`ready`)),a}clone(t){let n=new ExtensionManager(this.extensionManager.editorKits,(t||this.config).debug),r=new e({assetLoad:this.config.assetLoad,...t},this.schema,n);n.created(r,this.schema);let a=this.getJSON(),o=this.state.selection;r.createView(a,o),r.setupPlugins();{let e=this.state,t=r.state.tr.setMeta(`cloned`,e);r.dispatchTransaction(t)}return r}getExtension(e){return this.ci.resolve(e)}get run(){return this.commandManager.run}get commandFactories(){return this.commandManager.commandFactories}chain(e){return this.commandManager.createChain(e)}can(e){return this.commandManager.createCan(e)}link(e){if(e===this)throw Error(`You cannot chain editor to itself`);this.unlink(),this.state=EditorState.create({doc:e.getDocument()});let{commandFactories:t}=this.commandManager,n=[],r={...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>{let a=t(...e);return n.push(a),r}])),run:()=>{this.linkSource=e,this.linkListener=()=>{let t=e.state,r=e=>{t=t.apply(e)};for(let e of n)if(!e(t,r))return;this.state=t.reconfigure({plugins:this.extensionManager.plugins}),this.view&&this.view.updateState(this.state);let a=new CustomEvent(`changed`,{detail:{editor:this}});this.dispatchEvent(a)},e.addEventListener(`changed`,this.linkListener)}};return r}unlink(){this.linkListener&&this.linkSource&&(this.linkSource.removeEventListener(`changed`,this.linkListener),this.linkListener=void 0,this.linkSource=void 0)}createView(e,t){let n=createNodeFromObject(e,this.schema);if(this.state=EditorState.create({doc:n,selection:t}),this.config.element){let e=new EditorView(this.config.element,{state:this.state,attributes:{class:`kb-editor`},dispatchTransaction:e=>this.dispatchTransaction(e),editable:()=>!this.config.readOnly});if(this.view=e,this.config.element.parentNode){let t=new MutationObserver(n=>{for(let r of n)for(let n of r.removedNodes)if(n.contains(e.dom)){t.disconnect(),e.destroy();return}})}}else this.view=new DummyEditorView({state:this.state,dispatchTransaction:e=>this.dispatchTransaction(e)});let r=new CustomEvent(`doc:loaded`,{detail:{editor:this,doc:n}});this.dispatchEvent(r)}dispatchTransaction(e){if(this.state=this.state.apply(e),e.docChanged&&this.version++,this.view){this.view.updateState(this.state);let t=new CustomEvent(`transaction`,{detail:{editor:this,transaction:e}});this.dispatchEvent(t)}if(e.docChanged){let e=new CustomEvent(`changed`,{detail:{editor:this}});this.dispatchEvent(e)}}setupPlugins(){this.state=this.state.reconfigure({plugins:this.extensionManager.plugins}),this.view&&(this.view.updateState(this.state),this.view.setProps({nodeViews:this.extensionManager.nodeViews}))}clearDocument(){let e={type:this.schema.topNodeType.name,content:this.schema.topNodeType.spec.EMPTY_DOC.content};this.setDocument(e)}setDocument(e){let t=createNodeFromObject(e,this.schema,{errorOnInvalidContent:!0});t=ensureDocSchema(t,this.schema),this.state=EditorState.create({doc:t,plugins:this.state.plugins,storedMarks:this.state.storedMarks}),this.view&&this.view.updateState(this.state);let n=new CustomEvent(`doc:loaded`,{detail:{editor:this,doc:t}});this.dispatchEvent(n)}getConverter(e){let t=this.extensionManager.converters[e];if(!t)throw Error(`Converter not found for: `+e);return t}getDocument(){return this.state.doc}loadDocumentText(e,t){return this.loadDocument(e,new TextEncoder().encode(t))}async loadDocument(e,t){let n=await this.getConverter(e).toDoc(t),r=EditorState.create({doc:n,plugins:this.state.plugins,storedMarks:this.state.storedMarks}),a=e=>{r=r.apply(e)};{let e=this.state;a(r.tr.setMeta(`cloned`,e))}runInputRulesTexts()(r,a),this.state=r,this.view&&(this.view.updateState(this.state),this.view.dispatch(this.view.state.tr));let o=new CustomEvent(`doc:loaded`,{detail:{editor:this,doc:this.state.doc}});this.dispatchEvent(o)}async saveDocument(e){let t=this.getConverter(e),n=this.state.doc.toJSON(),r=Node$3.fromJSON(this.state.schema,n);return await t.fromDoc(r)}async patchDocument(e,t){let n=await this.getConverter(e).toDoc(t),r=this.state.tr;r.replaceWith(0,this.state.doc.content.size,n.content),this.dispatchTransaction(r)}getMediaTypes(){return Object.keys(this.extensionManager.converters)}patchDocumentText(e,t){return this.patchDocument(e,new TextEncoder().encode(t))}getJSON(){return this.state.doc.toJSON()}debug(e){e||=this.state.doc,console.debug(nodeToTreeString(e))}destroy(){let e=new CustomEvent(`beforeDestroy`,{detail:{}});if(this.dispatchEvent(e),this.config.element){let e=this.config.element,t=e.cloneNode(!0);e.replaceWith(t)}this.view.destroy()}mergeCommandFactories(e,t){this.commandManager.mergeCommandFactories(e,t)}get editable(){return this.view.editable}},Extension=class{config;type=`extension`;editor;conflicts;overrides;constructor(e={}){this.config=e}setEditor(e){this.editor=e}getEditor(){return this.editor}created(){}getInputRules(){return[]}getProseMirrorPlugins(){return[]}getCommandFactories(e){return{}}getKeyboardShortcuts(e){return{}}getConverters(e,t){return{}}setupSpec(e){}},Mark=class{config;type=`mark`;name=`node`;editor;attributes={};constructor(e={}){this.config=e}setEditor(e){this.editor=e}created(){}getMarkSpec(){throw Error(`MarkSpec not defined: `+this.name)}getInputRules(e){return[]}getCommandFactories(e,t){return{}}getKeyboardShortcuts(e){return{}}},Node$2=class{config;type=`node`;name=`node`;editor;attributes={};constructor(e={}){this.config=e}setEditor(e){this.editor=e}created(){}getNodeSpec(){throw Error(`NodeSpec not defined: `+this.name)}getInputRules(e){return[]}getProseMirrorPlugins(){return[]}getCommandFactories(e,t){return{}}getKeyboardShortcuts(e){return{}}getNodeView(e){}getConverters(e,t){return{}}};function getShadowRoot(e){let t=e;for(;t;){if(t.toString()===`[object ShadowRoot]`)return t;if(t instanceof ShadowRoot&&t.host)return t.host.shadowRoot||void 0;t=t.parentElement||(t instanceof ShadowRoot?t.host:void 0)}}function debounce(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}function normalizeSiblings(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),a,o=[];if(e.forEach(e=>{if(!o)return;let t=r.findWrapping(e.type),n;if(!t)return o=null;if(n=o.length&&a.length&&addToSibling(t,a,e,o[o.length-1],0))o[o.length-1]=n;else{o.length&&(o[o.length-1]=closeRight(o[o.length-1],a.length));let n=withWrappers(e,t);o.push(n),r=r.matchType(n.type),a=t}}),o)return Fragment.from(o)}return e}function withWrappers(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Fragment.from(e));return e}function addToSibling(e,t,n,r,a){if(a<e.length&&a<t.length&&e[a]==t[a]){let o=addToSibling(e,t,n,r.lastChild,a+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(a==e.length-1?n.type:e[a+1]))return r.copy(r.content.append(Fragment.from(withWrappers(n,e,a+1))))}}function closeRight(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,closeRight(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Fragment.empty,!0);return e.copy(n.append(r))}function closeRange(e,t,n,r,a,o){let s=t<0?e.firstChild:e.lastChild,c=s.content;return e.childCount>1&&(o=0),a<r-1&&(c=closeRange(c,t,n,r,a+1,o)),a>=n&&(c=t<0?s.contentMatchAt(0).fillBefore(c,o<=a).append(c):c.append(s.contentMatchAt(s.childCount).fillBefore(Fragment.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(c))}function closeSlice(e,t,n){return t<e.openStart&&(e=new Slice(closeRange(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Slice(closeRange(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}function sliceSingleNode(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function fixSlice(e,t){if(e=Slice.maxOpen(normalizeSiblings(e.content,t),!0),e.openStart||e.openEnd){let t=0,n=0;for(let n=e.content.firstChild;t<e.openStart&&!n.type.spec.isolating;t++,n=n.firstChild);for(let t=e.content.lastChild;n<e.openEnd&&!t.type.spec.isolating;n++,t=t.lastChild);e=closeSlice(e,t,n)}return e}function sliceHasOnlyText(e){return e.content.content.every(e=>e.isInline)}var selectAll=()=>function(e,t,n){let r=e.tr.setSelection(new AllSelection(e.doc));return n&&n.dispatch(r),!0};function textPositionsToResolvedPos(e,t,n){let r=e.map(e=>-1),a=0,o=!1;function s(t,n,s,c){if(o){for(let n=0;n<e.length;n++){let o=e[n];o>=a&&o<a+c&&(r[n]=t+(o-a))}a+=c}}function c(e,t=0,r=0,a=0){t===1&&r===n&&(o=!0);let l=0;e.isText&&e.text?l=e.text?.length:e.isLeaf&&(l=1),l>0&&s(a,t,r,l),e.forEach((e,n,r)=>{c(e,t+1,r,a+n+1)})}if(c(t),o)for(let n=0;n<e.length;n++){let o=e[n];r[n]===-1&&(o<a?r[n]=1:r[n]=t.nodeSize-1)}return r.map(e=>t.resolve(e-1))}var selectText=(e,t,n=0)=>function(r,a,o){let[s,c]=textPositionsToResolvedPos([e+t,e],r.doc,n),l=r.tr.setSelection(new TextSelection(c,s));return o&&o.dispatch(l),!0},ExtensionSelection=class extends Extension{name=`selection`;extractSelection(){let e=this.editor.state,{from:t,to:n}=e.selection,r=e.doc.slice(t,n);if(sliceHasOnlyText(r)){let t=e.schema.nodes.paragraph.create(null,r.content);return e.schema.topNodeType.createAndFill(null,[t])}return e.schema.topNodeType.createAndFill(null,r.content)}replaceSelection(e){let t=!1,n=this.editor.view,r=this.editor.state,a;e.type?.name===`doc`&&(e=createNodeFromObject(e.toJSON(),this.editor.schema)),a=new Slice(e.content,1,1);let o=r.selection.$from;a=fixSlice(a,o);let s=sliceSingleNode(a),c=s?r.tr.replaceSelectionWith(s,!1):r.tr.replaceSelection(a);n.dispatch(c.scrollIntoView())}appendSelection(e){let t=this.editor.view,{state:n}=t,r;e.type?.name===`doc`&&(e=createNodeFromObject(e.toJSON(),this.editor.schema)),r=new Slice(e.content,1,1);let a=t.state.selection.$from;r=fixSlice(r,a);let o=n.tr.insert(t.state.selection.to,r.content);t.dispatch(o.scrollIntoView())}getCommandFactories(e){return this.editor=e,{selectAll:()=>selectAll(),selectText:(...e)=>selectText(...e)}}},pcBaseKeymap={"Mod-Enter":`exitCode`,Backspace:`backspace`,"Mod-Backspace":`backspace`,"Shift-Backspace":`backspace`,Delete:`del`,"Mod-Delete":`del`,"Mod-a":`selectAll`},macBaseKeymap={...pcBaseKeymap,"Ctrl-h":pcBaseKeymap.Backspace,"Alt-Backspace":pcBaseKeymap[`Mod-Backspace`],"Ctrl-d":pcBaseKeymap.Delete,"Ctrl-Alt-Backspace":pcBaseKeymap[`Mod-Delete`],"Alt-Delete":pcBaseKeymap[`Mod-Delete`],"Alt-d":pcBaseKeymap[`Mod-Delete`],"Ctrl-a":`selectTextblockStart`,"Ctrl-e":`selectTextblockEnd`},baseKeymap=/(Mac|iPhone|iPod|iPad)/i.test(navigator?.platform)?macBaseKeymap:pcBaseKeymap,ExtensionBaseKeymap=class extends Extension{name=`base-keymap`;getKeyboardShortcuts(){let e={Enter:`enter`,"Alt-ArrowUp":`joinUp`,"Alt-ArrowDown":`joinDown`,"Mod-BracketLeft":`lift`,Escape:`selectParentNode`};for(let t in baseKeymap)e[t]=baseKeymap[t];return e}};function dropCursor(e={}){return new Plugin({key:new PluginKey(`drop-cursor`),view(t){return new DropCursorView(t,e)}})}var DropCursorView=class{editorView;width;color;class;cursorPos=null;element=null;timeout=-1;handlers;constructor(e,t){this.editorView=e,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,a=r.getBoundingClientRect(),o=a.width/r.offsetWidth,s=a.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let a=e.getBoundingClientRect(),o=t?a.bottom:a.top;t&&r&&(o=(o+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let c=this.width/2*s;n={left:a.left,right:a.right,top:o-c,bottom:o+c}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*o;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let c=this.editorView.dom.offsetParent;this.element||(this.element=c.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let l,u;if(!c||c==document.body&&getComputedStyle(c).position==`static`)l=-pageXOffset,u=-pageYOffset;else{let e=c.getBoundingClientRect(),t=e.width/c.offsetWidth,n=e.height/c.offsetHeight;l=e.left-c.scrollLeft*t,u=e.top-c.scrollTop*n}this.element.style.left=(n.left-l)/o+`px`,this.element.style.top=(n.top-u)/s+`px`,this.element.style.width=(n.right-n.left)/o+`px`,this.element.style.height=(n.bottom-n.top)/s+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,a=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!a){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=dropPoint(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},ExtensionDropcursor=class extends Extension{name=`dropcursor`;options={color:`currentColor`,width:1,class:void 0};getProseMirrorPlugins(){return[dropCursor(this.options)]}},GapCursor=class e extends Selection{constructor(e){super(e,e),this.visible=!1}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):Selection.near(r)}content(){return Slice.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSONToGapCursor(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new GapBookmark(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!closedBefore(e)||!closedAfter(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let a=t.pos,o=null;for(let r=t.depth;;r--){let s=t.node(r);if(n>0?t.indexAfter(r)<s.childCount:t.index(r)>0){o=s.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;a+=n;let c=t.doc.resolve(a);if(e.valid(c))return c}for(;;){let s=n>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!NodeSelection.isSelectable(o)){t=t.doc.resolve(a+o.nodeSize*n),r=!1;continue search}break}o=s,a+=n;let c=t.doc.resolve(a);if(e.valid(c))return c}return null}}};Selection.jsonID(`gapcursor`,GapCursor);var GapBookmark=class e{pos;constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return GapCursor.valid(t)?new GapCursor(t):Selection.near(t)}};function closedBefore(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}}return!0}function closedAfter(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}}return!0}function gapCursor(){return new Plugin({key:new PluginKey(`gap-cursor`),props:{decorations:drawGapCursor,createSelectionBetween(e,t,n){return t.pos==n.pos&&GapCursor.valid(n)?new GapCursor(n):null},handleClick,handleKeyDown:handleKeyDown$1,handleDOMEvents:{beforeinput}}})}var handleKeyDown$1=keydownHandler({ArrowLeft:arrow$1(`horiz`,-1),ArrowRight:arrow$1(`horiz`,1),ArrowUp:arrow$1(`vert`,-1),ArrowDown:arrow$1(`vert`,1)});function arrow$1(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,a){let o=e.selection,s=t>0?o.$to:o.$from,c=o.empty;if(o instanceof TextSelection){if(!a.endOfTextblock(n)||s.depth==0)return!1;c=!1,s=e.doc.resolve(t>0?s.after():s.before())}let l=GapCursor.findGapCursorFrom(s,t,c);return l?(r&&r(e.tr.setSelection(new GapCursor(l))),!0):!1}}function handleClick(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!GapCursor.valid(r))return!1;let a=e.posAtCoords({left:n.clientX,top:n.clientY});return a&&a.inside>-1&&NodeSelection.isSelectable(e.state.doc.nodeAt(a.inside))?!1:(e.dispatch(e.state.tr.setSelection(new GapCursor(r))),!0)}function beforeinput(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof GapCursor))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let a=Fragment.empty;for(let e=r.length-1;e>=0;e--)a=Fragment.from(r[e].createAndFill(null,a));let o=e.state.tr.replace(n.pos,n.pos,new Slice(a,0,0));return o.setSelection(TextSelection.near(o.doc.resolve(n.pos+1))),e.dispatch(o),!1}function drawGapCursor(e){if(!(e.selection instanceof GapCursor))return null;let t=document.createElement(`div`);return t.className=`kb-gapcursor`,DecorationSet.create(e.doc,[Decoration.widget(e.selection.head,t,{key:`gapcursor`})])}var ExtensionGapcursor=class extends Extension{name=`gapcursor`;options={color:`currentColor`,width:1,class:void 0};getProseMirrorPlugins(){return[gapCursor()]}},ExtensionTextAlign=class extends Extension{name=`textAlign`;getCommandFactories(e){let t=e=>(t,n)=>{let{selection:r,tr:a}=t,{from:o,to:s}=r,c=!1;return t.doc.nodesBetween(o,s,(t,n)=>{t.isBlock&&t.type.spec.attrs&&`textAlign`in t.type.spec.attrs&&(a.setNodeMarkup(n,void 0,{...t.attrs,textAlign:e}),c=!0)}),c&&n&&n(a),c};return{setTextAlignLeft:()=>t(`left`),setTextAlignCenter:()=>t(`center`),setTextAlignRight:()=>t(`right`),setTextAlignJustify:()=>t(`justify`)}}},userColors=[{dark:`#30bced`,light:`#30bced`},{dark:`#6eeb83`,light:`#6eeb83`},{dark:`#ffbc42`,light:`#ffbc42`},{dark:`#ecd444`,light:`#ecd444`},{dark:`#ee6352`,light:`#ee6352`},{dark:`#9ac2c9`,light:`#9ac2c9`},{dark:`#8acb88`,light:`#8acb88`},{dark:`#1be7ff`,light:`#1be7ff`}];function hashString(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}var defaultColorMapper=(e,t)=>{let n=hashString(t.id),r=hashString(e.id);return n===r&&r++,userColors[r%userColors.length]};function generateBlankUser(){return{id:``,name:`User unset`}}function generateRandomUser(){let e=Math.random()*100;return{id:`random:`+e,name:`Anonymous `+Math.floor(e)}}var userPluginKey=new PluginKey(`user`),createUserPlugin=()=>new Plugin({key:userPluginKey,state:{init(){return{user:generateRandomUser()}},apply:(e,t)=>{let n=e.getMeta(`changeUser`);return n&&(t.user={...n.user}),t}}}),ExtensionUser=class extends Extension{name=`user`;getCommandFactories(){return{changeUser:e=>(t,n)=>{let r=t.tr;return r.setMeta(`changeUser`,{user:e}),n&&n(r),!0}}}getProseMirrorPlugins(){return[createUserPlugin()]}},remoteSelectionPluginKey=new PluginKey(`remote-selection`),defaultCursorBuilder=(e,t,n)=>{let r=n(e,t).light,a=document.createElement(`span`);a.classList.add(`kb-yjs__cursor`),a.setAttribute(`style`,`border-color: ${r};`);let o=document.createElement(`div`);o.setAttribute(`style`,`background-color: ${r}`),o.insertBefore(document.createTextNode(e.name),null);let s=document.createTextNode(``),c=document.createTextNode(``);return a.insertBefore(s,null),a.insertBefore(o,null),a.insertBefore(c,null),a},defaultSelectionBuilder=(e,t,n)=>({style:`background-color: ${n(e,t).light}70`,class:`kb-yjs__selection`}),createDecorations=(e,t,n,r)=>{let a=[],o=t.remoteStates;for(let s of o)if(s.cursor!=null){let o=s.user,c=s.cursor,l=c.anchor||null,u=c.head||null;if(l!==null&&u!==null){let c=Math.max(e.doc.content.size-1,0);l=Math.min(l,c),u=Math.min(u,c),a.push(Decoration.widget(u,()=>n(o,t.me,t.colorMapper),{key:s.clientId+o.id+o.name,side:10}));let d=Math.min(l,u),f=Math.max(l,u);a.push(Decoration.inline(d,f,r(o,t.me,t.colorMapper),{inclusiveEnd:!0,inclusiveStart:!1}))}}return DecorationSet.create(e.doc,a)},remoteSelectionPlugin=({cursorBuilder:e=defaultCursorBuilder,selectionBuilder:t=defaultSelectionBuilder}={})=>new Plugin({key:remoteSelectionPluginKey,state:{init(){return{remoteStates:[],me:generateBlankUser(),colorMapper:defaultColorMapper}},apply(e,t){let n=e.getMeta(`changeUser`);n&&(t.me={...n.user});let r=e.getMeta(`setColorMapper`);r&&(t.colorMapper=r.colorMapper);let a=e.getMeta(`remoteSelectionChange`);return a&&(t.remoteStates=[...a.remoteStates]),t}},props:{decorations(n){let r=this.getState(n);return r?createDecorations(n,r,e,t):DecorationSet.empty}}}),ExtensionRemoteSelection=class extends Extension{name=`remote-selection`;getProseMirrorPlugins(){return[remoteSelectionPlugin()]}};function generateId(){return String(Math.random())}function buildPairingTransaction(e,t,n){let{doc:r}=e,a=new Map,o=[];r.descendants((e,n)=>{e.type.name===t&&o.push({node:e,pos:n})});let s=!1;for(let{node:e,pos:t}of o){let r=e.attrs.content?.trim();if(!r)continue;let o=r.match(/^[^0-9a-z\/]*(\/?)[\s]*([\w]+)/i);if(!o)continue;let c=o[1]===`/`,l=o[2];if(!c)a.has(l)||a.set(l,[]),a.get(l).push({node:e,pos:t});else{let r=a.get(l);if(r&&r.length>0){let a=r.pop(),o=generateId();n.setNodeMarkup(a.pos,void 0,{...a.node.attrs,id:o,nesting:1,error:void 0}),n.setNodeMarkup(t,void 0,{...e.attrs,id:o,nesting:-1,error:void 0})}else n.setNodeMarkup(t,void 0,{...e.attrs,error:`Closing shortcode without matching opening`,nesting:-1});s=!0}}for(let[,e]of a.entries())for(let{node:t,pos:r}of e)n.setNodeMarkup(r,void 0,{...t.attrs,nesting:0,id:void 0}),s=!0;return s?n:null}var createPairingPlugin=e=>new Plugin({appendTransaction(t,n,r){let a=new Set;for(let r of t)if(r.docChanged){for(let t of r.steps)if((t instanceof ReplaceStep||t instanceof ReplaceAroundStep)&&(t.slice&&t.slice.content.descendants(t=>{e.includes(t.type.name)&&a.add(t.type.name)}),t.from!=null&&t.to!=null&&t.from!==t.to&&n.doc.nodesBetween(t.from,t.to,t=>{e.includes(t.type.name)&&a.add(t.type.name)}),a.size===e.length))break;if(a.size===e.length)break}if(a.size===0)return null;let o=r.tr;for(let e of a)buildPairingTransaction(r,e,o);return o}}),ExtensionPairing=class extends Extension{name=`pairing-nodes`;getProseMirrorPlugins(){return[createPairingPlugin([`shortcode_inline`])]}};function getHTMLFromFragment(e,t){let n=globalThis.document,r=DOMSerializer.fromSchema(t).serializeFragment(e,{document:n}),a=n.implementation.createHTMLDocument().createElement(`div`);return a.appendChild(r),a.innerHTML}var removeWhitespaces$1=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&removeWhitespaces$1(r)}return e};function elementFromString$1(e){let t=`<html lang="en"><body>${e}</body></html>`,n=new globalThis.DOMParser().parseFromString(t,`text/html`).body;return removeWhitespaces$1(n)}var ExtensionHtml=class extends Extension{name=`html`;getConverters(e,t){return{"text/html":{fromDoc:async t=>{let n=getHTMLFromFragment(t.content,e.schema);return new TextEncoder().encode(n)},toDoc:async e=>{let n=elementFromString$1(new TextDecoder().decode(e));return DOMParser$1.fromSchema(t).parse(n)}}}}},mediaUploadKey=new PluginKey(`mediaUpload`);function fileToDataURL(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})}function fileToObjectURL(e){return URL.createObjectURL(e)}function isImage(e,t){return t.some(t=>e.type.match(t))}function isVideo(e,t){return t.some(t=>e.type.match(t))}function insertImage(e,t,n,r,a){let{schema:o}=e.state,s=o.nodes.image;if(!s){console.warn(`Image node type not found in schema`);return}let c=s.create({src:n,alt:r,title:a}),l=e.state.tr.insert(t,c);e.dispatch(l)}function insertVideo(e,t,n,r,a,o){let{schema:s}=e.state,c=s.nodes.video;if(!c){console.warn(`Video node type not found in schema`);return}let l=c.create({src:n,title:r,width:a,height:o,controls:!0}),u=e.state.tr.insert(t,l);e.dispatch(u)}async function handleMediaFiles(e,t,n,r){let{maxFileSize:a=10*1024*1024,maxVideoFileSize:o=50*1024*1024,allowedImageTypes:s=[`^image/`],allowedVideoTypes:c=[`^video/`],uploadHandler:l}=r;for(let u of t){let t=isImage(u,s),d=isVideo(u,c);if(!t&&!d)continue;let f=d?o:a;if(u.size>f){console.warn(`${d?`Video`:`Image`} file "${u.name}" is too large (${(u.size/1024/1024).toFixed(2)}MB). Maximum size is ${(f/1024/1024).toFixed(2)}MB.`);continue}try{console.log(`Processing ${d?`video`:`image`}: ${u.name} (${(u.size/1024/1024).toFixed(2)}MB, ${u.type})`);let t;l?t=await l(u):d&&r.useObjectURLForVideos!==!1?(t=fileToObjectURL(u),console.log(`Using object URL for video:`,t)):(t=await fileToDataURL(u),console.log(`${d?`Video`:`Image`} converted to data URL, length: ${t.length} characters`)),d?(insertVideo(e,n,t,u.name),console.log(`Video inserted into editor`)):(insertImage(e,n,t,u.name),console.log(`Image inserted into editor`)),n+=1}catch(e){console.error(`Failed to process ${d?`video`:`image`} "${u.name}":`,e)}}}function createMediaUploadPlugin(e={}){return new Plugin({key:mediaUploadKey,state:{init(){return e},apply(e,t){return e.isGeneric?t:e.getMeta(`setMediaUploadOptions`)||t}},props:{handleDrop(e,t,n,r){if(r)return!1;let a=Array.from(t.dataTransfer?.files||[]);if(a.length===0)return!1;let o=mediaUploadKey.getState(e.state)||{},{allowedImageTypes:s=[`^image/`],allowedVideoTypes:c=[`^video/`]}=o;if(a.some(e=>isImage(e,s)||isVideo(e,c))){t.preventDefault();let n={left:t.clientX,top:t.clientY},r=e.posAtCoords(n);return r?(handleMediaFiles(e,a,r.pos,o),!0):!1}},handlePaste(t,n,r){if((n.clipboardData?.types||[]).includes(`text/html`))return;let a=Array.from(n.clipboardData?.items||[]).filter(e=>e.type.startsWith(`image/`));if(a.length>0){n.preventDefault();let r=[];for(let e of a){let t=e.getAsFile();t&&r.push(t)}if(r.length===0)return!1;let{from:o}=t.state.selection;return handleMediaFiles(t,r,o,e),!0}}}})}var ExtensionMediaUpload=class extends Extension{config;name=`mediaUpload`;constructor(e={}){super(e),this.config=e}getProseMirrorPlugins(){return[createMediaUploadPlugin(this.config)]}};function getStringByXPath(e,t){return t.ownerDocument.evaluate(e,t,null,XPathResult.STRING_TYPE,null).stringValue}function getElementsByXPath(e,t){let n=t.ownerDocument.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=[];for(let e=0;e<n.snapshotLength;e++){let t=n.snapshotItem(e);t&&r.push(t)}return r}var PasteState=class{editor;pasteRules=[];constructor(e){this.editor=e}handleCommands(e,t){if(!e)return!1;if(e.getPasteRules)return e.getPasteRules(this.pasteRules),!0;if(e.setPasteRules)return console.log(`setPasteRules`,e.setPasteRules),this.pasteRules=e.setPasteRules,!0;if(e.pasteHtml){let{from:t,html:n}=e.pasteHtml,r=elementFromString$1(n),a=this.editor,o=!1,s=[],c=a.ci.resolve(`yaml`);for(let e of this.pasteRules){if(typeof e.match==`string`){if(getElementsByXPath(e.match,r).length===0)continue}else if(!e.match(r))continue;for(let t of e.steps){let e;if(typeof t.match==`string`)switch(t.result||``){case`string`:e=getStringByXPath(t.match,r);break;default:e=getElementsByXPath(t.match,r);break}else e=t.match(r);switch(console.log(`step`,e,t),t.op){case`remove`:for(let t of e)t.parentNode?.removeChild(t);break;case`replaceTag`:for(let n of e){let e=n.ownerDocument.createElement(t.tag);e.innerHTML=n.innerHTML,n.parentNode?.replaceChild(e,n)}break;case`replaceBody`:for(let t of e)r.innerHTML=``,r.appendChild(t);break;case`console.debug`:console.debug(e);break;case`meta.set`:s.push({path:t.path,value:e});break}}o=!!e.replaceDocument;break}let l=DOMParser$1.fromSchema(this.editor.schema).parse(r);return setTimeout(async()=>{let e=this.editor.state.tr;o?e.replaceWith(0,this.editor.state.doc.content.size,l):e.insert(t,l);{let t=await new Promise(e=>this.editor.chain().getMeta(e).run())||new Map;for(let e of s)c.setPathValue(t,e.path,e.value);e.setDocAttribute(`meta`,t)}this.editor.dispatchTransaction(e)},0),!0}return!1}},PastePluginKey=new PluginKey(`paste`),ExtensionPaste=class extends Extension{name=`paste`;getProseMirrorPlugins(){let e=this.editor;return[new Plugin({key:PastePluginKey,state:{init(){return new PasteState(e)},apply(e,t,n,r){if(e.isGeneric)return t;let a=e.getMeta(`cloned`);if(a){let e=PastePluginKey.getState(a);if(e)return e}let o=e.getMeta(PastePluginKey);return t.handleCommands(o,e),t}},props:{handleDOMEvents:{copy(t,n){if(!n.clipboardData)return!1;let r=e.clone();return n.preventDefault(),(async()=>{r.state.selection instanceof AllSelection||r.ci.register(`frontmatter`,new BlankFrontmatterServiceImpl),r.chain().keepSelection().run();let e=new TextDecoder().decode(await r.saveDocument(`text/x-markdown`)),t=new TextDecoder().decode(await r.saveDocument(`text/html`));await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([e],{type:`text/plain`}),"text/html":new Blob([t],{type:`text/html`})})])})(),!1}},handlePaste(t,n,r){let{clipboardData:a}=n;if(!a)return!1;if(a.types.includes(`text/html`)){let{from:e}=t.state.selection,r=a.getData(`text/html`);n.preventDefault();let o=t.state.tr.setMeta(PastePluginKey,{pasteHtml:{from:e,html:r}});return t.dispatch(o),!0}[...a.items].map(e=>e.getAsFile()).filter(e=>!!e);let o=Array.from(n.clipboardData?.files||[]);if(o.length===1){let t=o[0];if(e.getMediaTypes().includes(t.type))return t.bytes().then(n=>{e.loadDocument(t.type,n)}),!0}},handleDrop(t,n,r,a){let o=Array.from(n.dataTransfer?.files||[]);if(o.length===1){let t=o[0];if(e.getMediaTypes().includes(t.type))return t.bytes().then(n=>{e.loadDocument(t.type,n)}),!0}}}})]}getCommandFactories(e){return{getPasteRules:e=>(t,n)=>{let r=t.tr;return r.setMeta(PastePluginKey,{getPasteRules:e}),n&&n(r),!0},setPasteRules:e=>(t,n)=>{let r=t.tr;return r.setMeta(PastePluginKey,{setPasteRules:e}),n&&n(r),!0}}}},MarkLink=class extends Mark{name=`link`;requires=[`doc`];getMarkSpec(){return{attrs:{href:{},title:{default:void 0},origUrl:{default:void 0},mdTemplate:{default:void 0}},inclusive:!1,parseDOM:[{tag:`a[href]`,getAttrs(e){return{href:e.getAttribute(`href`),title:e.getAttribute(`title`)}}}],toDOM(e){let{href:t,title:n}=e.attrs;return[`a`,{href:t,title:n},0]}}}},MarkStrong=class extends Mark{name=`strong`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!=`normal`&&null},{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(){return[`strong`,0]}}}getCommandFactories(e,t){return{toggleStrong:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-b":`toggleStrong`,"Mod-B":`toggleStrong`}}},MarkItalic=class extends Mark{name=`em`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`i`},{tag:`em`},{style:`font-assets=italic`},{style:`font-assets=normal`,clearMark:e=>e.type.name==`em`}],toDOM(){return[`em`,0]}}}getCommandFactories(e,t){return{toggleItalic:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-i":`toggleItalic`,"Mod-I":`toggleItalic`}}},MarkUnderline=class extends Mark{name=`underline`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`u`}],toDOM(){return[`u`,0]}}}getCommandFactories(e,t){return{toggleUnderline:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-u":`toggleUnderline`,"Mod-U":`toggleUnderline`}}},MarkStrike=class extends Mark{name=`strike`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`strike`}],toDOM(){return[`strike`,0]}}}getCommandFactories(e,t){return{toggleStrike:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-s":`toggleStrike`,"Mod-S":`toggleStrike`}}},MarkCode=class extends Mark{name=`code`;requires=[`doc`];getMarkSpec(){return{parseDOM:[{tag:`code`}],toDOM(){return[`code`,0]}}}getCommandFactories(e,t){return{toggleCode:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-`":`toggleCode`}}},MarkChange=class extends Mark{name=`change`;requires=[`doc`];getMarkSpec(){return{parseDOM:[],toDOM(){return[`change`,0]}}}},MarkBookmark=class extends Mark{name=`bookmark`;requires=[`doc`];getMarkSpec(){return{attrs:{id:{}},parseDOM:[],toDOM(e){return[`a`,{id:e.attrs.id},0]}}}},MarkTextColor=class extends Mark{name=`textColor`;getMarkSpec(){return{attrs:{color:{default:null}},parseDOM:[{tag:`span[style*="color"]`,getAttrs(e){let t=e.style.color;return t?{color:t}:!1}}],toDOM(e){let{color:t}=e.attrs;return t?[`span`,{style:`color: ${t}`},0]:[`span`,0]}}}},MarkHighlight=class extends Mark{name=`highlight`;getMarkSpec(){return{attrs:{color:{default:null}},parseDOM:[{tag:`mark`,getAttrs(e){let t=e.style.backgroundColor;return t?{color:t}:{color:`yellow`}}},{tag:`span[style*="background-color"]`,getAttrs(e){let t=e.style.backgroundColor;return t?{color:t}:!1}}],toDOM(e){let{color:t}=e.attrs;return[`mark`,{style:`background-color: ${t||`yellow`}; color: inherit;`},0]}}}},MarkSuperscript=class extends Mark{name=`superscript`;requires=[`doc`];getMarkSpec(){return{excludes:`subscript`,parseDOM:[{tag:`sup`},{style:`vertical-align`,getAttrs:e=>e===`super`&&null}],toDOM(){return[`sup`,0]}}}getCommandFactories(e,t){return{toggleSuperscript:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-Shift-.":`toggleSuperscript`}}},MarkSubscript=class extends Mark{name=`subscript`;requires=[`doc`];getMarkSpec(){return{excludes:`superscript`,parseDOM:[{tag:`sub`},{style:`vertical-align`,getAttrs:e=>e===`sub`&&null}],toDOM(){return[`sub`,0]}}}getCommandFactories(e,t){return{toggleSubscript:()=>e.commandFactories.toggleMark(t)}}getKeyboardShortcuts(){return{"Mod-Shift-,":`toggleSubscript`}}},NodeDocument=class extends Node$2{name=`doc`;getNodeSpec(){return{content:`block+`,attrs:{meta:{default:null}},marks:`code em strong link bookmark`,EMPTY_DOC:{type:this.name,content:[{type:`paragraph`,content:[]}]}}}getCommandFactories(e,t){return{getMeta:e=>(t,n)=>(e(structuredClone(t.doc.attrs.meta)),!0),setMeta:e=>(t,n)=>{let r=t.tr;return r.setDocAttribute(`meta`,e),n&&n(r),r.docChanged},updateMeta:e=>(t,n)=>{let r=t.tr;return r.setDocAttribute(`meta`,e(t.doc.attrs.meta)),n&&n(r),r.docChanged}}}},NodeText=class extends Node$2{name=`text`;getNodeSpec(){return{group:`inline`}}};function wrappingInputRule(e,t,n=null,r){return new InputRule(e,(e,a,o,s,c)=>{e||=a.tr;let l=n instanceof Function?n(o):n;e=e.delete(s,c);let u=e.doc.resolve(s).blockRange(),d=u&&findWrapping(u,t,l);if(!d)return null;e.wrap(u,d);let f=e.doc.resolve(s-1).nodeBefore;return f&&f.type==t&&canJoin(e.doc,s-1)&&(!r||r(o,f))&&e.join(s-1),e})}function textblockTypeInputRule(e,t,n=null){return new InputRule(e,(e,r,a,o,s)=>{e||=r.tr;let c=r.doc.resolve(o),l=n instanceof Function?n(a):n;return c.node(-1).canReplaceWith(c.index(-1),c.indexAfter(-1),t)?e.delete(o,s).setBlockType(o,o,t,l):null})}function replaceInlineNode(e,t,n=null){return new InputRule(e,(e,r,a,o,s)=>{e||=r.tr;let c=n instanceof Function?n(a):n;if(r.doc.resolve(o).parent.type===r.schema.nodes.code_block)return e;let l=t.createAndFill(c),u=e.mapping.map(o),d=e.mapping.map(s);return e.replaceWith(u,d,Fragment.from(l))})}var NodeCodeBlock$1=class extends Node$2{name=`code_block`;getNodeSpec(){return{content:`text*`,marks:``,group:`block`,code:!0,defining:!0,attrs:{lang:{default:void 0}},parseDOM:[{tag:`pre`,preserveWhitespace:`full`,getAttrs(e){return{lang:e.getAttribute(`lang`)}}}],toDOM(e){let{lang:t}=e.attrs;return[`pre`,{lang:t},[`code`,0]]}}}getInputRules(e){return[textblockTypeInputRule(/^```$/,e)]}},NodeBookmark=class extends Node$2{name=`node_bookmark`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,atom:!0,attrs:{id:{},nesting:{default:0}},parseDOM:[],toDOM(e){return[`a`,{id:e.attrs.id},0]}}}},NodeParagraph=class extends Node$2{name=`paragraph`;requires=[`doc`];getNodeSpec(){return{content:`inline*`,group:`block`,attrs:{textAlign:{default:void 0}},parseDOM:[{tag:`p`,getAttrs(e){let t=e.style.textAlign;return t===`center`||t===`right`||t===`justify`?{textAlign:t}:!1}}],toDOM(e){let t=e.attrs.textAlign||`left`;return[`center`,`right`,`justify`].includes(t)?[`p`,{style:`text-align: ${t}`},0]:[`p`,0]}}}getCommandFactories(e,t){return{setParagraph:()=>e.commandFactories.setBlockType(t)}}getKeyboardShortcuts(){return{"Shift-Ctrl-0":`setParagraph`}}},NodeHardBreak=class extends Node$2{name=`br`;requires=[`doc`];options={keepMarks:!0};getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseDOM:[{tag:`br`}],toDOM(){return[`br`]}}}getCommandFactories(e,t){let n=firstCommand(e.run.exitCode);return{setHardBreak:()=>n}}getKeyboardShortcuts(){let e=typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator?.platform):!1,t={"Ctrl-Enter":`setHardBreak`};return e&&(t[`Mod-Enter`]=`setHardBreak`,t[`Shift-Enter`]=`setHardBreak`),t}},NodeSoftBreak=class extends Node$2{name=`softbreak`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,parseDOM:[{tag:`wbr`}],toDOM(){return[`wbr`]}}}},NodeHorizontalRule=class extends Node$2{name=`hr`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,parseDOM:[{tag:`hr`}],toDOM(){return[`hr`]}}}getCommandFactories(e,t){return{setHorizontalRule:()=>(e,n)=>(n&&n(e.tr.replaceSelectionWith(t.create()).scrollIntoView()),!0)}}getKeyboardShortcuts(){return{"Mod-_":`setHorizontalRule`}}},NodeImage=class extends Node$2{name=`image`;requires=[`doc`];getNodeSpec(){return{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null},width:{default:null},height:{default:null},origUrl:{default:void 0},mdTemplate:{default:void 0}},group:`inline`,draggable:!0,parseDOM:[{tag:`img[src]`,getAttrs(e){return{src:e.getAttribute(`src`),title:e.getAttribute(`title`),alt:e.getAttribute(`alt`),width:e.getAttribute(`width`)||e.style.width||null,height:e.getAttribute(`height`)||e.style.height||null}}}],toDOM(e){let{src:t,alt:n,title:r,width:a,height:o}=e.attrs,s={src:t};return n&&(s.alt=n),r&&(s.title=r),a&&(s.width=a),o&&(s.height=o),[`img`,s]}}}getNodeView(e){return(e,t,n)=>{let r=document.createElement(`span`);r.className=`kb-image-wrapper`,r.contentEditable=`false`;let a=document.createElement(`img`);a.src=e.attrs.src,e.attrs.alt&&(a.alt=e.attrs.alt),e.attrs.title&&(a.title=e.attrs.title),e.attrs.width&&(a.style.width=typeof e.attrs.width==`number`?`${e.attrs.width}px`:e.attrs.width),e.attrs.height&&(a.style.height=typeof e.attrs.height==`number`?`${e.attrs.height}px`:e.attrs.height),a.draggable=!1,r.appendChild(a);let o=[`nw`,`ne`,`sw`,`se`],s=[];for(let e of o){let t=document.createElement(`span`);t.className=`kb-image-resize-handle kb-image-resize-handle-${e}`,t.dataset.position=e,s.push(t),r.appendChild(t)}let c=!1,l=0,u=0,d=0,f=0,p=1,m=null,h=e=>{let t=e.target;if(!t.classList.contains(`kb-image-resize-handle`))return;e.preventDefault(),e.stopPropagation(),c=!0,m=t.dataset.position||null,l=e.clientX,u=e.clientY;let n=a.getBoundingClientRect();d=n.width,f=n.height,p=d/f,r.classList.add(`kb-image-resizing`),document.addEventListener(`mousemove`,g),document.addEventListener(`mouseup`,_)},g=e=>{if(!c)return;let t=e.clientX-l,n=e.clientY-u,r=d,o=f;switch(m){case`se`:r=d+t,o=e.shiftKey?f+n:r/p;break;case`sw`:r=d-t,o=e.shiftKey?f+n:r/p;break;case`ne`:r=d+t,o=e.shiftKey?f-n:r/p;break;case`nw`:r=d-t,o=e.shiftKey?f-n:r/p;break}r=Math.max(50,r),o=Math.max(50,o),a.style.width=`${Math.round(r)}px`,a.style.height=`${Math.round(o)}px`},_=()=>{if(!c)return;c=!1,m=null,r.classList.remove(`kb-image-resizing`),document.removeEventListener(`mousemove`,g),document.removeEventListener(`mouseup`,_);let o=Math.round(a.getBoundingClientRect().width),s=Math.round(a.getBoundingClientRect().height),l=n();if(typeof l==`number`){let n=t.state.tr.setNodeMarkup(l,void 0,{...e.attrs,width:`${o}px`,height:`${s}px`});t.dispatch(n)}};return r.addEventListener(`mousedown`,h),r.addEventListener(`click`,e=>{e.preventDefault();let r=n();if(typeof r==`number`){let e=t.state.doc.resolve(r),n=Selection.near(e);t.dispatch(t.state.tr.setSelection(n))}}),{dom:r,update:e=>e.type.name===`image`?(a.src=e.attrs.src,e.attrs.alt&&(a.alt=e.attrs.alt),e.attrs.title&&(a.title=e.attrs.title),e.attrs.width?a.style.width=typeof e.attrs.width==`number`?`${e.attrs.width}px`:e.attrs.width:a.style.width=``,e.attrs.height?a.style.height=typeof e.attrs.height==`number`?`${e.attrs.height}px`:e.attrs.height:a.style.height=``,!0):!1,destroy:()=>{r.removeEventListener(`mousedown`,h),document.removeEventListener(`mousemove`,g),document.removeEventListener(`mouseup`,_)},stopEvent:e=>e.type===`mousedown`&&e.target.classList.contains(`kb-image-resize-handle`),ignoreMutation:()=>!0}}}},NodeVideo=class extends Node$2{name=`video`;requires=[`doc`];getNodeSpec(){return{attrs:{src:{},title:{default:null},controls:{default:!0},width:{default:null},height:{default:null}},group:`block`,draggable:!0,parseDOM:[{tag:`video[src]`,getAttrs(e){return{src:e.getAttribute(`src`),title:e.getAttribute(`title`),controls:e.hasAttribute(`controls`),width:e.getAttribute(`width`),height:e.getAttribute(`height`)}}}],toDOM(e){let{src:t,title:n,controls:r,width:a,height:o}=e.attrs,s={src:t};return n&&(s.title=n),r&&(s.controls=``),a&&(s.width=a),o&&(s.height=o),[`video`,s]}}}},NodeBlockquote=class extends Node$2{name=`blockquote`;requires=[`doc`];getNodeSpec(){return{content:`block+`,group:`block`,defining:!0,parseDOM:[{tag:`blockquote`}],toDOM(){return[`blockquote`,0]}}}getInputRules(e){return[wrappingInputRule(/^\s*>\s$/,e)]}getCommandFactories(e,t){return{toggleBlockquote:()=>e.commandFactories.wrapInList(t)}}getKeyboardShortcuts(){return{"Ctrl->":`toggleBlockquote`}}},NodeAside=class extends Node$2{name=`aside`;requires=[`doc`];getNodeSpec(){return{content:`block+`,group:`block`,defining:!0,parseDOM:[{tag:`aside`}],toDOM(){return[`aside`,0]}}}},maxLevel=6,NodeHeading=class extends Node$2{name=`heading`;requires=[`doc`];getNodeSpec(){return{attrs:{level:{default:1}},content:`inline*`,group:`block`,defining:!0,parseDOM:[{tag:`h1`,attrs:{level:1}},{tag:`h2`,attrs:{level:2}},{tag:`h3`,attrs:{level:3}},{tag:`h4`,attrs:{level:4}},{tag:`h5`,attrs:{level:5}},{tag:`h6`,attrs:{level:6}}],toDOM(e){return[`h`+e.attrs.level,0]}}}getInputRules(e){return[textblockTypeInputRule(RegExp(`^(#{1,6})\\s$`),e,e=>({level:e[1].length}))]}getCommandFactories(e,t){let n={};for(let r=1;r<=maxLevel;r++)n[`setHeading`+r]=()=>e.commandFactories.setBlockType(t,{level:r});return n}getKeyboardShortcuts(){let e={};for(let t=1;t<=maxLevel;t++)e[`Shift-Ctrl-`+t]=`setHeading`+t;return e}},NodeMath=class extends Node$2{name=`math`;requires=[`doc`];getNodeSpec(){return{inline:!0,attrs:{lang:{default:`mathml`},content:{}},group:`inline`,draggable:!0,parseDOM:[{tag:`math`,getAttrs:e=>({lang:`mathml`,content:new XMLSerializer().serializeToString(e)})}],toDOM(e){let t=new DOMParser().parseFromString(e.attrs.content,`application/xml`);return t.getElementsByTagName(`parsererror`).length>0?[`span`,{class:`mathml-error`},`Invalid MathML`]:document.importNode(t.documentElement,!0)}}}},NodeDefinitionList=class extends Node$2{name=`dl`;requires=[`doc`];getNodeSpec(){return{content:`dt+|dd+`,group:`block`,parseDOM:[{tag:`dl`}],toDOM(){return[`dl`,0]}}}getInputRules(e){return[]}getCommandFactories(e,t){return{toggleDefinitionList:()=>e.commandFactories.wrapInList(t)}}getKeyboardShortcuts(){return{}}},NodeDefinitionTerm=class extends Node$2{name=`dt`;requires=[`dl`];getNodeSpec(){return{content:`inline*`,group:`block`,parseDOM:[{tag:`dt`}],defining:!0,toDOM(){return[`dt`,0]}}}},NodeDefinitionDesc=class extends Node$2{name=`dd`;requires=[`dl`];getNodeSpec(){return{content:`inline*`,group:`block`,parseDOM:[{tag:`dd`}],defining:!0,toDOM(){return[`dd`,0]}}}};function fixCharacters$1(e){return e.replace(/’/g,`'`).replace(/“/g,`"`).replace(/”/g,`"`).replace(/\x0b/g,` `).replace(/\u201d/g,`"`).replace(/\u201c/g,`"`)}function replaceAllNodesOfType(e,t,n,r){let a=[];t.descendants((e,t)=>{e.type===n&&a.push({node:e,pos:t})});for(let t=a.length-1;t>=0;t--){let{node:n,pos:o}=a[t],s=r(n,e.doc.type.schema);e=e.replaceWith(o,o+n.nodeSize,s)}return e}var NodeInlineShortCode=class extends Node$2{name=`shortcode_inline`;requires=[`doc`];getNodeSpec(){return{inline:!0,group:`inline`,selectable:!0,atom:!0,attrs:{id:{default:void 0},content:{default:``},nesting:{default:0},error:{default:``}},parseDOM:[{tag:`span.kb-shortcode-inline`,getAttrs:e=>({content:e.textContent||null})}],toDOM(e){return[`span`,{class:`kb-shortcode-inline`},e.attrs.content||``]}}}getInputRules(e){return[replaceInlineNode(/\{\{[^}]+\}\}/,e,e=>({content:fixCharacters$1(e[0].substring(2,e[0].length-2))}))]}getCommandFactories(e,t){return{renderShortCode:e=>(n,r)=>{let a=n.tr;return a=replaceAllNodesOfType(a,n.doc,t,e),a.docChanged&&r&&r(a),!0}}}},NodeIframe=class extends Node$2{name=`iframe`;requires=[`doc`];getNodeSpec(){return{inline:!0,attrs:{src:{},class:{default:null},alt:{default:null},title:{default:null}},group:`inline`,draggable:!0,parseDOM:[{tag:`iframe[src]`,getAttrs(e){return{src:e.getAttribute(`src`),title:e.getAttribute(`title`),alt:e.getAttribute(`alt`)}}}],toDOM(e){let{src:t,alt:n,title:r}=e.attrs;return[`iframe`,{src:t,alt:n,title:r,class:e.attrs.class}]}}}};function collectCommentAnchors(e){let t=new Map,n=new Map;return e.descendants((e,r)=>{e.type.name===`comment`&&(e.attrs.nesting===1&&t.set(e.attrs.id,r),e.attrs.nesting===-1&&n.set(e.attrs.id,r))}),{starts:t,ends:n}}function buildCommentRanges(e){let{starts:t,ends:n}=collectCommentAnchors(e),r=[];for(let[e,a]of t){let t=n.get(e);!t||t<=a||r.push({id:e,from:a+1,to:t})}return r}function buildDecorations(e){let t=buildCommentRanges(e);return DecorationSet.create(e,t.map(({id:e,from:t,to:n})=>Decoration.inline(t,n,{class:`comment-highlight`,"data-comment-id":e})))}function commentsPlugin(){return new Plugin({state:{init(e,{doc:t}){return buildDecorations(t)},apply(e,t,n,r){return e.docChanged?buildDecorations(r.doc):t}},props:{decorations(e){return this.getState(e)}}})}var addCommentBoundary=e=>(t,n)=>{let{schema:r,selection:a}=t,{from:o,to:s}=a,c=r.nodes.comment;if(!c)return!1;let l=c.create({id:e,nesting:1}),u=c.create({id:e,nesting:-1}),d=t.tr;return d.insert(s,u),d.insert(o,l),n&&n(d),!0},NodeCommentAnchor=class extends Node$2{name=`comment`;requires=[`doc`];options={keepMarks:!0};getNodeSpec(){return{inline:!0,group:`inline`,selectable:!1,atom:!0,attrs:{id:{},active:{default:!1},nesting:{default:1}},parseDOM:[{tag:`span[data-comment-id]`,getAttrs(e){return{id:e.getAttribute(`data-comment-id`),nesting:parseInt(e.getAttribute(`data-nesting`)||`1`),active:e.hasAttribute(`data-active`)}}}],toDOM:e=>[`span`,{"data-comment-id":e.attrs.id,"data-active":e.attrs.active?`true`:void 0,"data-nesting":e.attrs.nesting}]}}getCommandFactories(e,t){return{addComment:(e,t)=>addCommentBoundary(e,t)}}getProseMirrorPlugins(){return[commentsPlugin()]}};function splitListItem(e,t){let n=function(n,r){let{$from:a,$to:o,node:s}=n.selection;if(s&&s.isBlock||a.depth<2||!a.sameParent(o))return!1;let c=a.node(-1);if(c.type!=e)return!1;if(a.parent.content.size==0&&a.node(-1).childCount==a.indexAfter(-1)){if(a.depth==3||a.node(-3).type!=e||a.index(-2)!=a.node(-2).childCount-1)return!1;if(r){let t=Fragment.empty,o=a.index(-1)?1:a.index(-2)?2:3;for(let e=a.depth-o;e>=a.depth-3;e--)t=Fragment.from(a.node(e).copy(t));let s=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3;t=t.append(Fragment.from(e.createAndFill()));let c=a.before(a.depth-(o-1)),l=n.tr.replace(c,a.after(-s),new Slice(t,4-o,0)),u=-1;l.doc.nodesBetween(c,l.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&e.content.size==0&&(u=t+1)}),u>-1&&l.setSelection(Selection.near(l.doc.resolve(u))),r(l.scrollIntoView())}return!0}let l=o.pos==a.end()?c.contentMatchAt(0).defaultType:null,u=n.tr.delete(a.pos,o.pos),d=l?[t?{type:e,attrs:t}:null,{type:l}]:void 0;return canSplit(u.doc,a.pos,2,d)?(r&&r(u.split(a.pos,2,d).scrollIntoView()),!0):!1};return n.displayName=`splitListItem(${e.name})`,n}function liftListItem(e){return function(t,n){let{$from:r,$to:a}=t.selection,o=r.blockRange(a,t=>t.childCount>0&&t.firstChild.type==e);return o?n?r.node(o.depth-1).type==e?liftToOuterList(t,n,e,o):liftOutOfList(t,n,o):!0:!1}}function liftToOuterList(e,t,n,r){let a=e.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(a.step(new ReplaceAroundStep(o-1,s,o,s,new Slice(Fragment.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new NodeRange(a.doc.resolve(r.$from.pos),a.doc.resolve(s),r.depth));let c=liftTarget(r);if(c==null)return!1;a.lift(r,c);let l=a.doc.resolve(a.mapping.map(o,-1)-1);return canJoin(a.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&a.join(l.pos),t(a.scrollIntoView()),!0}function liftOutOfList(e,t,n){let r=e.tr,a=n.parent;for(let e=n.end,t=n.endIndex-1,o=n.startIndex;t>o;t--)e-=a.child(t).nodeSize,r.delete(e-1,e+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let c=n.startIndex==0,l=n.endIndex==a.childCount,u=o.node(-1),d=o.index(-1);if(!u.canReplace(d+ +!c,d+1,s.content.append(l?Fragment.empty:Fragment.from(a))))return!1;let f=o.pos,p=f+s.nodeSize;return r.step(new ReplaceAroundStep(f-+!!c,p+ +!!l,f+1,p-1,new Slice((c?Fragment.empty:Fragment.from(a.copy(Fragment.empty))).append(l?Fragment.empty:Fragment.from(a.copy(Fragment.empty))),+!c,+!l),+!c)),t(r.scrollIntoView()),!0}function sinkListItem(e){return function(t,n){let{$from:r,$to:a}=t.selection,o=r.blockRange(a,t=>t.childCount>0&&t.firstChild.type==e);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let c=o.parent,l=c.child(s-1);if(l.type!=e)return!1;if(n){let r=l.lastChild&&l.lastChild.type==c.type,a=Fragment.from(r?e.create():null),s=new Slice(Fragment.from(e.create(null,Fragment.from(c.type.create(null,a)))),r?3:1,0),u=o.start,d=o.end;n(t.tr.step(new ReplaceAroundStep(u-(r?3:1),d,u,d,s,1,!0)).scrollIntoView())}return!0}}var isList=e=>e.endsWith(`_list`),clearNodes=()=>(e,t)=>{let n=e.tr,{selection:r}=n,{ranges:a}=r;return t&&a.forEach(({$from:t,$to:r})=>{e.doc.nodesBetween(t.pos,r.pos,(e,t)=>{if(e.type.isText)return;let{doc:r,mapping:a}=n,o=r.resolve(a.map(t)),s=r.resolve(a.map(t+e.nodeSize)),c=o.blockRange(s);if(!c)return;let l=liftTarget(c);if(e.type.isTextblock){let{defaultType:e}=o.parent.contentMatchAt(o.index());n.setNodeMarkup(c.start,e)}(l||l===0)&&n.lift(c,l)})}),!0};function findParentNodeClosestToPos(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function findParentNode(e){return t=>findParentNodeClosestToPos(t.$from,e)}var joinListBackwards=(e,t)=>{let n=findParentNode(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let a=e.doc.nodeAt(r);return n.node.type===a?.type&&canJoin(e.doc,n.pos)&&e.join(n.pos),!0},joinListForwards=(e,t)=>{let n=findParentNode(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let a=e.doc.nodeAt(r);return n.node.type===a?.type&&canJoin(e.doc,r)&&e.join(r),!0},toggleList=(e,t,n,r={})=>function(a,o,s){if(!this)throw Error(`Call this with Function.apply`);let c=this.editor,l=Object.keys(a.schema.marks).filter(e=>e!==`link`),u=a.schema.nodes[e],d=a.schema.nodes[t],{selection:f,storedMarks:p}=a,{$from:m,$to:h}=f,g=m.blockRange(h),_=p||(f.$to.parentOffset?f.$from.marks():[]);if(!g)return!1;let v=findParentNode(e=>isList(e.type.name))(f),y=a.tr;if(g.depth>=1&&v&&g.depth-v.depth<=1){if(v.node.type===u)return liftListItem(d).apply(this,[a,o,s]);if(isList(v.node.type.name)&&u.validContent(v.node.content)&&o)return c.chain(y).command(()=>(y.setNodeMarkup(v.pos,u),!0)).command(()=>joinListBackwards(y,u)).command(()=>joinListForwards(y,u)).command(()=>o(y)).run()}return!n||!_||!o?c.chain(y).command(()=>c.can().wrapInList(u,r).run()?!0:c.chain(y).lift().run()).wrapInList(u,r).command(()=>joinListBackwards(y,u)).command(()=>joinListForwards(y,u)).command(()=>(o&&o(y),!0)).run():c.chain(y).command(()=>{let e=c.can().wrapInList(u,r).run(),t=_.filter(e=>l.includes(e.type.name));return y.ensureMarks(t),e?!0:(v&&y.setSelection(NodeSelection.create(a.doc,v.pos)),clearNodes().apply(this,[a,o,s]))}).wrapInList(u,r).command(()=>joinListBackwards(y,u)).command(()=>joinListForwards(y,u)).command(()=>(o&&o(y),!0)).run()},NodeOrderedList=class extends Node$2{name=`ordered_list`;requires=[`doc`];attributes={type:{default:`1`,fromDom(e){return e.hasAttribute(`type`)?e.getAttribute(`type`):`1`}},start:{default:void 0,fromDom(e){return e.hasAttribute(`start`)?+e.getAttribute(`start`):void 0}},id:{default:void 0},continue:{default:void 0},odtMarginLeft:{default:void 0}};getNodeSpec(){return{content:`list_item+`,group:`block list`,parseDOM:[{tag:`ol`,getAttrs:e=>setHtmlAttributes(this,e)}],toDOM:e=>[`ol`,getHtmlAttributes(this,e),0]}}getInputRules(e){return[wrappingInputRule(/^(\d+)\.\s$/,e,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order==+e[1])]}getCommandFactories(e,t){let n=!1;return{toggleOrderedList:()=>toggleList(`ordered_list`,`list_item`,!1)}}getKeyboardShortcuts(){return{"Shift-Ctrl-7":`toggleOrderedList`}}},NodeBulletList=class extends Node$2{name=`bullet_list`;requires=[`doc`];attributes={toc:{default:void 0},odtMarginLeft:{default:void 0}};getNodeSpec(){return{content:`list_item+`,group:`block list`,parseDOM:[{tag:`ul`}],toDOM(){return[`ul`,0]}}}getInputRules(e){return[wrappingInputRule(/^\s*([-+*])\s$/,e)]}getCommandFactories(e,t){let n=!1;return{toggleBulletList:()=>toggleList(`bullet_list`,`list_item`,!1)}}getKeyboardShortcuts(){return{"Shift-Ctrl-8":`toggleBulletList`}}},NodeListItem=class extends Node$2{name=`list_item`;requires=[`doc`];attributes={value:{default:void 0},type:{default:void 0,fromDom(e){return e.hasAttribute(`type`)?e.getAttribute(`type`):void 0},toDom(e){return e.attrs.type}}};getNodeSpec(){return{content:`paragraph block*`,defining:!0,parseDOM:[{tag:`li`,getAttrs:e=>setHtmlAttributes(this,e)}],toDOM:e=>[`li`,getHtmlAttributes(this,e),0]}}getCommandFactories(e,t){return{splitListItem:()=>splitListItem(t),liftListItem:()=>liftListItem(t),sinkListItem:()=>sinkListItem(t)}}getKeyboardShortcuts(){return{Enter:`splitListItem`,Tab:`sinkListItem`,"Shift-Tab":`liftListItem`}}},NodeTaskList=class extends Node$2{name=`task_list`;requires=[`doc`];getNodeSpec(){return{content:`task_item+`,group:`block list`,parseDOM:[{tag:`ul[data-type="${this.name}"]`}],toDOM:()=>[`ul`,{"data-type":this.name},0]}}getCommandFactories(){return{toggleTaskList:()=>toggleList(`task_list`,`task_item`)}}getKeyboardShortcuts(){return{"Shift-Ctrl-9":`toggleTaskList`}}},NodeViewTaskItem=class e{editor;dom;contentDOM;checkbox;node;view;getPos;config={};constructor(e,...t){this.editor=e,this.node=t[0],this.view=t[1],this.getPos=t[2];let n=document.createElement(`li`);this.dom=n;let r=document.createElement(`label`);r.contentEditable=`false`;let a=document.createElement(`input`);this.checkbox=a,a.type=`checkbox`,a.checked=this.node.attrs.checked,r.append(a);let o=document.createElement(`div`);this.contentDOM=o,n.append(r,o),n.dataset.checked=this.node.attrs.checked,a.addEventListener(`mousedown`,e=>e.preventDefault()),a.addEventListener(`change`,t=>{let n=this.getPos();if(typeof n!=`number`)return;this.editor.view.editable;let{checked:r}=t.target,a=e.state.tr,o=a.doc.nodeAt(n);a.setNodeMarkup(n,void 0,{...o?.attrs,checked:r}),e.dispatchTransaction(a)})}static create=(t,...n)=>new e(t,...n);update(e){return e.type.name===this.node.type.name?(this.dom.dataset.checked=e.attrs.checked,this.checkbox.checked=e.attrs.checked,!0):!1}},NodeTaskItem=class extends Node$2{config;name=`task_item`;requires=[`doc`];constructor(e={nested:!0}){super(e),this.config=e}getNodeSpec(){return{attrs:{checked:{default:!1}},content:this.config.nested?`paragraph block*`:`paragraph+`,defining:!0,parseDOM:[{tag:`li[data-checked]`,getAttrs(e){return{checked:e.getAttribute(`data-checked`)===`true`}}}],toDOM:e=>[`li`,{"data-type":this.name,"data-checked":e.attrs.checked},[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null},[`span`]],[`div`,0]]]}}getCommandFactories(e,t){return{splitListItem:()=>splitListItem(t),liftListItem:()=>liftListItem(t),sinkListItem:()=>sinkListItem(t)}}getNodeView(e){return(...t)=>NodeViewTaskItem.create(e,...t)}getKeyboardShortcuts(){return{Enter:`splitListItem`,Tab:`sinkListItem`,"Shift-Tab":`liftListItem`}}getInputRules(e){return[wrappingInputRule(/^\s*(\[([( |x])?\])\s$/,e,e=>({checked:e[e.length-1]===`x`}))]}},BasicEditorKit=class{getExtensions(){return[new ExtensionBaseKeymap,new ExtensionDropcursor,new ExtensionGapcursor,new ExtensionHtml,new ExtensionMediaUpload,new ExtensionRemoteSelection,new ExtensionSelection,new ExtensionTextAlign,new ExtensionPairing,new ExtensionUser,new ExtensionPaste,new NodeDocument,new NodeText,new NodeParagraph,new NodeHardBreak,new NodeSoftBreak,new NodeCodeBlock$1,new NodeBookmark,new NodeHorizontalRule,new NodeOrderedList,new NodeBulletList,new NodeListItem,new NodeTaskList,new NodeTaskItem,new NodeDefinitionList,new NodeDefinitionTerm,new NodeDefinitionDesc,new NodeTaskList,new NodeTaskItem,new NodeImage,new NodeVideo,new NodeBlockquote,new NodeAside,new NodeHeading,new NodeMath,new NodeInlineShortCode,new NodeIframe,new NodeCommentAnchor,new MarkLink,new MarkItalic,new MarkStrong,new MarkUnderline,new MarkStrike,new MarkCode,new MarkChange,new MarkBookmark,new MarkTextColor,new MarkHighlight,new MarkSuperscript,new MarkSubscript]}},kit=new BasicEditorKit,ExtensionBasicEditor=class extends Extension{name=`basic-editor`;requires=kit.getExtensions()},GOOD_LEAF_SIZE=200,RopeSequence=class e{append(t){return t.length?(t=e.from(t),!this.length&&t||t.length<GOOD_LEAF_SIZE&&this.leafAppend(t)||this.length<GOOD_LEAF_SIZE&&t.leafPrepend(this)||this.appendInner(t)):this}prepend(t){return t.length?e.from(t).append(this):this}appendInner(e){return new Append(this,e)}slice(e=0,t=this.length){return e>=t?emptyRopeSequence():this.sliceInner(Math.max(0,e),Math.min(this.length,t))}get(e){if(!(e<0||e>=this.length))return this.getInner(e)}forEach(e,t=0,n=this.length){t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)}map(e,t=0,n=this.length){let r=[];return this.forEach((t,n)=>(r.push(e(t,n)),t),t,n),r}static from(t){return t instanceof e?t:t&&t.length?new Leaf(t):emptyRopeSequence()}},Leaf=class e extends RopeSequence{values;constructor(e){super(),this.values=e}flatten(){return this.values}sliceInner(t,n){return t==0&&n==this.length?this:new e(this.values.slice(t,n))}getInner(e){return this.values[e]}forEachInner(e,t,n,r){for(let a=t;a<n;a++)if(e(this.values[a],r+a)===!1)return!1;return!0}forEachInvertedInner(e,t,n,r){for(let a=t-1;a>=n;a--)if(e(this.values[a],r+a)===!1)return!1;return!0}leafAppend(t){if(this.length+t.length<=GOOD_LEAF_SIZE)return new e(this.values.concat(t.flatten()))}leafPrepend(t){if(this.length+t.length<=GOOD_LEAF_SIZE)return new e(t.flatten().concat(this.values))}get length(){return this.values.length}get depth(){return 0}};function emptyRopeSequence(){return new Leaf([])}var Append=class e extends RopeSequence{left;right;depth;length;constructor(e,t){super(),this.left=e,this.right=t,this.length=e.length+t.length,this.depth=Math.max(e.depth,t.depth)+1}flatten(){return this.left.flatten().concat(this.right.flatten())}getInner(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)}forEachInner(e,t,n,r){let a=this.left.length;return!(t<a&&this.left.forEachInner(e,t,Math.min(n,a),r)===!1||n>a&&this.right.forEachInner(e,Math.max(t-a,0),Math.min(this.length,n)-a,r+a)===!1)}forEachInvertedInner(e,t,n,r){let a=this.left.length;return!(t>a&&this.right.forEachInvertedInner(e,t-a,Math.max(n,a)-a,r+a)===!1||n<a&&this.left.forEachInvertedInner(e,Math.min(t,a),n,r)===!1)}sliceInner(e,t){if(e==0&&t==this.length)return this;let n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))}leafAppend(t){let n=this.right.leafAppend(t);if(n)return new e(this.left,n)}leafPrepend(t){let n=this.left.leafPrepend(t);if(n)return new e(n,this.right)}appendInner(t){return this.left.depth>=Math.max(this.right.depth,t.depth)+1?new e(this.left,new e(this.right,t)):new e(this,t)}},max_empty_items=500,Branch=class e{items;eventCount;constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let a,o;n&&(a=this.remapping(r,this.items.length),o=a.maps.length);let s=t.tr,c,l,u=[],d=[];return this.items.forEach((t,n)=>{if(!t.step)return a||(a=this.remapping(r,n+1),o=a.maps.length),o--,d.push(t),t;if(a){d.push(new Item(t.map));let e=t.step.map(a.slice(o)),n;e&&s.maybeStep(e).doc&&(n=s.mapping.maps[s.mapping.maps.length-1],u.push(new Item(n,void 0,void 0,u.length+d.length))),o--,n&&a.appendMap(n,o)}else s.maybeStep(t.step);return t.selection?(c=a?t.selection.map(a.slice(o)):t.selection,l=new e(this.items.slice(0,r).append(d.reverse().concat(u)),this.eventCount-1),!1):t},this.items.length,0),{remaining:l,transform:s,selection:c}}addTransform(t,n,r,a){let o=[],s=this.eventCount,c=this.items,l=!a&&c.length?c.get(c.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),u=new Item(t.mapping.maps[e],r,n),d;(d=l&&l.merge(u))&&(u=d,e?o.pop():c=c.slice(0,c.length-1)),o.push(u),n&&=(s++,void 0),a||(l=u)}let u=s-r.depth;return u>DEPTH_OVERFLOW&&(c=cutOffEvents(c,u),s-=u),new e(c.append(o),s)}remapping(e,t){let n=new Mapping;return this.items.forEach((t,r)=>{let a=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;return n.appendMap(t.map,a),t},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new Item(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],a=Math.max(0,this.items.length-n),o=t.mapping,s=t.steps.length,c=this.eventCount;this.items.forEach(e=>(e.selection&&c--,e),a);let l=n;this.items.forEach(e=>{let n=o.getMirror(--l);if(n==null)return!1;s=Math.min(s,n);let a=o.maps[n];if(e.step){let s=t.steps[n].invert(t.docs[n]),u=e.selection&&e.selection.map(o.slice(l+1,n));u&&c++,r.push(new Item(a,s,u))}else r.push(new Item(a));return e},a);let u=[];for(let e=n;e<s;e++)u.push(new Item(o.maps[e]));let d=new e(this.items.slice(0,a).append(u).append(r),c);return d.emptyItemCount()>max_empty_items&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>(t.step||e++,t)),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,a=[],o=0;return this.items.forEach((e,s)=>{if(s>=t)a.push(e),e.selection&&o++;else if(e.step){let t=e.step.map(n.slice(r)),s=t&&t.getMap();if(r--,s&&n.appendMap(s,r),t){let c=e.selection&&e.selection.map(n.slice(r));c&&o++;let l=new Item(s.invert(),t,c),u,d=a.length-1;(u=a.length&&a[d].merge(l))?a[d]=u:a.push(l)}}else e.map&&r--;return e},this.items.length,0),new e(RopeSequence.from(a.reverse()),o)}static empty=new e(emptyRopeSequence(),0)};function cutOffEvents(e,t){let n;return e.forEach((e,r)=>e.selection&&t--==0?(n=r,!1):e),e.slice(n)}var Item=class e{map;step;selection;mirrorOffset;constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},HistoryState=class{done;undone;prevRanges;prevTime;prevComposition;constructor(e,t,n,r,a){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=a}},DEPTH_OVERFLOW=20;function applyTransaction(e,t,n,r){let a=n.getMeta(historyKey),o;if(a)return a.historyState;n.getMeta(closeHistoryKey)&&(e=new HistoryState(e.done,e.undone,null,0,-1));let s=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(s&&s.getMeta(historyKey))return s.getMeta(historyKey).redo?new HistoryState(e.done.addTransform(n,void 0,r,mustPreserveItems(t)),e.undone,rangesFor(n.mapping.maps),e.prevTime,e.prevComposition):new HistoryState(e.done,e.undone.addTransform(n,void 0,r,mustPreserveItems(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(s&&s.getMeta(`addToHistory`)===!1)){let a=n.getMeta(`composition`),o=e.prevTime==0||!s&&e.prevComposition!=a&&(e.prevTime<(n.time||0)-r.newGroupDelay||!isAdjacentTo(n,e.prevRanges)),c=s?mapRanges(e.prevRanges,n.mapping):rangesFor(n.mapping.maps);return new HistoryState(e.done.addTransform(n,o?t.selection.getBookmark():void 0,r,mustPreserveItems(t)),Branch.empty,c,n.time,a??e.prevComposition)}else if(o=n.getMeta(`rebased`))return new HistoryState(e.done.rebased(n,o),e.undone.rebased(n,o),mapRanges(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new HistoryState(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),mapRanges(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function isAdjacentTo(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let a=0;a<t.length;a+=2)e<=t[a+1]&&r>=t[a]&&(n=!0)}),n}function rangesFor(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,a)=>t.push(r,a));return t}function mapRanges(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let a=t.map(e[r],1),o=t.map(e[r+1],-1);a<=o&&n.push(a,o)}return n}function histTransaction(e,t,n){let r=mustPreserveItems(t),a=historyKey.get(t).spec.config,o=(n?e.undone:e.done).popEvent(t,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),c=(n?e.done:e.undone).addTransform(o.transform,t.selection.getBookmark(),a,r),l=new HistoryState(n?c:o.remaining,n?o.remaining:c,null,0,-1);return o.transform.setSelection(s).setMeta(historyKey,{redo:n,historyState:l})}var cachedPreserveItems=!1,cachedPreserveItemsPlugins=null;function mustPreserveItems(e){let t=e.plugins;if(cachedPreserveItemsPlugins!=t){cachedPreserveItems=!1,cachedPreserveItemsPlugins=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){cachedPreserveItems=!0;break}}return cachedPreserveItems}var historyKey=new PluginKey(`history`),closeHistoryKey=new PluginKey(`closeHistory`);function history$1(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Plugin({key:historyKey,state:{init(){return new HistoryState(Branch.empty,Branch.empty,null,0,-1)},apply(t,n,r){return applyTransaction(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?undo:n==`historyRedo`?redo:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function buildCommand(e,t){return(n,r)=>{let a=historyKey.getState(n);if(!a||(e?a.undone:a.done).eventCount==0)return!1;if(r){let o=histTransaction(a,n,e);o&&r(t?o.scrollIntoView():o)}return!0}}var undo=buildCommand(!1,!0),redo=buildCommand(!0,!0),undoNoScroll=buildCommand(!1,!1),redoNoScroll=buildCommand(!0,!1),ExtensionHistory$1=class extends Extension{name=`history`;options={depth:100,newGroupDelay:500};getCommandFactories(e){return{undo:()=>undo,redo:()=>redo}}getKeyboardShortcuts(){let e=typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator?.platform):!1,t={"Mod-z":`undo`,"Mod-y":`redo`};return e||(t[`Mod-y`]=`redo`),t}getProseMirrorPlugins(){return[history$1(this.options)]}},Token=class{type;tag;nesting;attrs=null;map=null;level=0;children=null;content=``;markup=``;info=``;meta=null;block=!1;hidden=!1;constructor(e,t,n){this.type=e,this.tag=t,this.nesting=n}attrIndex(e){if(!this.attrs)return-1;let t=this.attrs;for(let n=0,r=t.length;n<r;n++)if(t[n][0]===e)return n;return-1}attrPush(e){this.attrs?this.attrs.push(e):this.attrs=[e]}attrSet(e,t){let n=this.attrIndex(e),r=[e,t];n<0||!this.attrs?this.attrPush(r):this.attrs[n]=r}attrGet(e){let t=this.attrIndex(e),n=null;return t>=0&&this.attrs&&(n=this.attrs[t][1]),n}attrJoin(e,t){let n=this.attrIndex(e);n<0||!this.attrs?this.attrPush([e,t]):this.attrs[n][1]=this.attrs[n][1]+` `+t}},Brackets={left:[`(`,`[`,`{`,`|`,`‖`,`⟨`,`⌊`,`⌈`,`⌜`],right:[`)`,`]`,`}`,`|`,`‖`,`⟩`,`⌋`,`⌉`,`⌝`],isPair:function(e,t){let n=this.left.indexOf(e);return t===this.right[n]},contains:function(e){return this.isLeft(e)||this.isRight(e)},isLeft:function(e){return this.left.indexOf(e)>-1},isRight:function(e){return this.right.indexOf(e)>-1},parseLeft:function(e,t=!0){if(this.left.indexOf(e)<0)return e;let n=``;switch(e){case`(`:case`[`:case`|`:n=`\\left${e}`;break;case`‖`:n=`\\left\\|`;break;case`{`:n=`\\left\\{`;break;case`⟨`:n=`\\left\\langle `;break;case`⌊`:n=`\\left\\lfloor `;break;case`⌈`:n=`\\left\\lceil `;break;case`⌜`:n=`\\left\\ulcorner `;break}return t?n:n.replace(`\\left`,``)},parseRight:function(e,t=!0){if(this.right.indexOf(e)<0)return e;let n=``;switch(e){case`)`:case`]`:case`|`:n=`\\right${e}`;break;case`‖`:n=`\\right\\|`;break;case`}`:n=`\\right\\}`;break;case`⟩`:n=` \\right\\rangle`;break;case`⌋`:n=` \\right\\rfloor`;break;case`⌉`:n=` \\right\\rceil`;break;case`⌝`:n=` \\right\\urcorner`;break}return t?n:n.replace(`\\right`,``)}},MathSymbol={parseIdentifier:function(e){if(e.length===0)return``;if(e.length===1){let t=e.charCodeAt(0),n=this.greekLetter.decimals.indexOf(t);return n>-1?this.greekLetter.scripts[n]+` `:e}else return this.parseMathFunction(e)},parseOperator:function(e){if(e.length===0)return``;if(e.length===1){let t=e.charCodeAt(0),n=[this.bigCommand,this.relation,this.binaryOperation,this.setAndLogic,this.delimiter,this.other],r=[!1,!0,!0,!1,!1,!1];for(let e=0;e<n.length;e++){let a=n[e],o=a.decimals.indexOf(t);if(o>-1)return r[e]?[` `,a.scripts[o],` `].join(``):a.scripts[o]+` `}return e}else return this.parseMathFunction(e)},parseMathFunction:function(e){let t=T.createMarker(),n=[];return this.mathFunction.names.forEach((r,a)=>{let o=new RegExp(r,`g`);e.match(o)&&(n.push(this.mathFunction.scripts[a]),e=e.replace(o,t.next()+` `))}),t.replaceBack(e,n)},overScript:{decimals:[9182],templates:[`\\overbrace{@v}`]},underScript:{decimals:[9183],templates:[`\\underbrace{@v}`]},bigCommand:{decimals:[8721,8719,8720,10753,10754,10752,8899,8898,10756,10758,8897,8896,8747,8750,8748,8749,10764,8747],scripts:[`\\sum`,`\\prod`,`\\coprod`,`\\bigoplus`,`\\bigotimes`,`\\bigodot`,`\\bigcup`,`\\bigcap`,`\\biguplus`,`\\bigsqcup`,`\\bigvee`,`\\bigwedge`,`\\int`,`\\oint`,`\\iint`,`\\iiint`,`\\iiiint`,`\\idotsint`]},relation:{decimals:[60,62,61,8741,8742,8804,8805,8784,8781,8904,8810,8811,8801,8866,8867,8834,8835,8776,8712,8715,8838,8839,8773,8995,8994,8840,8841,8771,8872,8713,8847,8848,126,8764,8869,8739,8849,8850,8733,8826,8827,10927,10928,8800,8738,8737],scripts:`<.>.=.\\parallel.\\nparallel.\\leq.\\geq.\\doteq.\\asymp.\\bowtie.\\ll.\\gg.\\equiv.\\vdash.\\dashv.\\subset.\\supset.\\approx.\\in.\\ni.\\subseteq.\\supseteq.\\cong.\\smile.\\frown.\\nsubseteq.\\nsupseteq.\\simeq.\\models.\\notin.\\sqsubset.\\sqsupset.\\sim.\\sim.\\perp.\\mid.\\sqsubseteq.\\sqsupseteq.\\propto.\\prec.\\succ.\\preceq.\\succeq.\\neq.\\sphericalangle.\\measuredangle`.split(`.`)},binaryOperation:{decimals:[43,45,177,8745,8900,8853,8723,8746,9651,8854,215,8846,9661,8855,247,8851,9667,8856,8727,8852,9657,8857,8902,8744,9711,8728,8224,8743,8729,8726,8225,8901,8768,10815],scripts:`+.-.\\pm.\\cap.\\diamond.\\oplus.\\mp.\\cup.\\bigtriangleup.\\ominus.\\times.\\uplus.\\bigtriangledown.\\otimes.\\div.\\sqcap.\\triangleleft.\\oslash.\\ast.\\sqcup.\\triangleright.\\odot.\\star.\\vee.\\bigcirc.\\circ.\\dagger.\\wedge.\\bullet.\\setminus.\\ddagger.\\cdot.\\wr.\\amalg`.split(`.`)},setAndLogic:{decimals:[8707,8594,8594,8708,8592,8592,8704,8614,172,10233,8834,8658,10233,8835,8596,8712,10234,8713,8660,8715,8868,8743,8869,8744,8709,8709],scripts:`\\exists.\\rightarrow.\\to.\\nexists.\\leftarrow.\\gets.\\forall.\\mapsto.\\neg.\\implies.\\subset.\\Rightarrow.\\implies.\\supset.\\leftrightarrow.\\in.\\iff.\\notin.\\Leftrightarrow.\\ni.\\top.\\land.\\bot.\\lor.\\emptyset.\\varnothing`.split(`.`)},delimiter:{decimals:[124,8739,8214,47,8726,123,125,10216,10217,8593,8657,8968,8969,8595,8659,8970,8971],scripts:[`|`,`\\mid`,`\\|`,`/`,`\\backslash`,`\\{`,`\\}`,`\\langle`,`\\rangle`,`\\uparrow`,`\\Uparrow`,`\\lceil`,`\\rceil`,`\\downarrow`,`\\Downarrow`,`\\lfloor`,`\\rfloor`]},greekLetter:{decimals:[913,945,925,957,914,946,926,958,915,947,927,959,916,948,928,960,982,917,1013,949,929,961,1009,918,950,931,963,962,919,951,932,964,920,952,977,933,965,921,953,934,981,966,922,954,1008,935,967,923,955,936,968,924,956,937,969],scripts:`A.\\alpha.N.\\nu.B.\\beta.\\Xi.\\xi.\\Gamma.\\gamma.O.o.\\Delta.\\delta.\\Pi.\\pi.\\varpi.E.\\epsilon.\\varepsilon.P.\\rho.\\varrho.Z.\\zeta.\\Sigma.\\sigma.\\varsigma.H.\\eta.T.\\tau.\\Theta.\\theta.\\vartheta.\\Upsilon.\\upsilon.I.\\iota.\\Phi.\\phi.\\varphi.K.\\kappa.\\varkappa.X.\\chi.\\Lambda.\\lambda.\\Psi.\\psi.M.\\mu.\\Omega.\\omega`.split(`.`)},other:{decimals:[8706,305,8476,8711,8501,240,567,8465,9723,8502,8463,8467,8472,8734,8503],scripts:[`\\partial`,`\\imath`,`\\Re`,`\\nabla`,`\\aleph`,`\\eth`,`\\jmath`,`\\Im`,`\\Box`,`\\beth`,`\\hbar`,`\\ell`,`\\wp`,`\\infty`,`\\gimel`]},mathFunction:{names:`arcsin.sinh.sin.sec.arccos.cosh.cos.csc.arctan.tanh.tan.arccot.coth.cot.limsup.liminf.exp.ker.deg.gcd.lg.ln.Pr.sup.det.hom.lim.log.arg.dim.inf.max.min`.split(`.`),scripts:`\\arcsin.\\sinh.\\sin.\\sec.\\arccos.\\cosh.\\cos.\\csc.\\arctan.\\tanh.\\tan.\\arccot.\\coth.\\cot.\\limsup.\\liminf.\\exp.\\ker.\\deg.\\gcd.\\lg.\\ln.\\Pr.\\sup.\\det.\\hom.\\lim.\\log.\\arg.\\dim.\\inf.\\max.\\min`.split(`.`)}},T={};T.createMarker=function(){return{idx:-1,reReplace:/@\[\[(\d+)\]\]/gm,next:function(){return`@[[${++this.idx}]]`},replaceBack:function(e,t){return e.replace(this.reReplace,(e,n)=>t[parseInt(n)])}}};var root=typeof window<`u`?window:{};function canParseHTMLNatively(){let e=root.DOMParser,t=!1;try{new e().parseFromString(``,`text/html`)&&(t=!0)}catch{}return t}function createHTMLParser(){let e=function(){};return shouldUseActiveX()?e.prototype.parseFromString=function(e){let t=new window.ActiveXObject(`htmlfile`);return t.designMode=`on`,t.open(),t.write(e),t.close(),t}:e.prototype.parseFromString=function(e){let t=document.implementation.createHTMLDocument(``);return t.open(),t.write(e),t.close(),t},e}function shouldUseActiveX(){let e=!1;try{document.implementation.createHTMLDocument(``).open()}catch{window.ActiveXObject&&(e=!0)}return e}var HTMLParser=canParseHTMLNatively()?root.DOMParser:createHTMLParser(),NodeTool={parseMath:function(e){return new HTMLParser().parseFromString(e,`text/html`).querySelector(`math`)},getChildren:function(e){return e.children},getNodeName:function(e){return e.tagName.toLowerCase()},getNodeText:function(e){return e.textContent},getAttr:function(e,t,n){let r=e.getAttribute(t);return r===null?n:r},getPrevNode:function(e){return e.previousElementSibling},getNextNode:function(e){return e.nextElementSibling}};function convert(e){return toLatex(parse(NodeTool.parseMath(e)))}function toLatex(e){return e=e.replace(/\\left\(\\DELETE_BRACKET_L/g,``),e=e.replace(/\\DELETE_BRACKET_R\\right\)/g,``),e=e.replace(/\\DELETE_BRACKET_L/g,``),e=e.replace(/\\DELETE_BRACKET_R/g,``),e}function parse(e){let t=NodeTool.getChildren(e);return!t||t.length===0?parseLeaf(e):parseContainer(e,t)}function parseLeaf(e){let t=``;switch(NodeTool.getNodeName(e)){case`mi`:t=parseElementMi(e);break;case`mn`:t=parseElementMn(e);break;case`mo`:t=parseOperator(e);break;case`ms`:t=parseElementMs(e);break;case`mtext`:t=parseElementMtext(e);break;case`mglyph`:t=parseElementMglyph(e);break;case`mprescripts`:t=``;break;case`mspace`:t=parseElementMspace();case`none`:t=`\\:`;break;default:t=escapeSpecialChars(NodeTool.getNodeText(e).trim());break}return t}function parseOperator(e){let t=NodeTool.getNodeText(e).trim();return t=MathSymbol.parseOperator(t),escapeSpecialChars(t)}function parseElementMi(e){let t=NodeTool.getNodeText(e).trim();return t=MathSymbol.parseIdentifier(t),escapeSpecialChars(t)}function parseElementMn(e){return escapeSpecialChars(NodeTool.getNodeText(e).trim())}function parseElementMs(e){return[`"`,escapeSpecialChars(NodeTool.getNodeText(e).trimRight()),`"`].join(``)}function parseElementMtext(e){return`\\text{${escapeSpecialChars(NodeTool.getNodeText(e))}}`}function parseElementMglyph(e){return escapeSpecialChars([`"`,NodeTool.getAttr(e,`alt`,``),`"`].join(``))}function parseElementMspace(e){return``}function escapeSpecialChars(e){return e=e.replace(/\$|%|_|&|#|\{|\}/g,e=>`\\${e}`),e}function parseContainer(e,t){let n=getRender(e);if(n)return n(e,t);throw Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(e)}`)}function renderChildren(e){let t=[],n=[];if(Array.prototype.forEach.call(e,e=>{if(NodeTool.getNodeName(e)===`mo`){let r=NodeTool.getNodeText(e).trim();if(Brackets.contains(r)){let a=NodeTool.getAttr(e,`stretchy`,`true`);if(a=[``,`true`].indexOf(a)>-1,Brackets.isRight(r)){let e=n[n.length-1];e&&Brackets.isPair(e,r)?(t.push(Brackets.parseRight(r,a)),n.pop()):Brackets.isLeft(r)?(t.push(Brackets.parseLeft(r,a)),n.push(r)):console.error(`bracket not match`)}else t.push(Brackets.parseLeft(r,a)),n.push(r)}else t.push(parseOperator(e))}else t.push(parse(e))}),n.length>0)for(let e=0;e<n.length;e++)t.push(`\\right.`);return n=void 0,t}function getRender(e){let t;switch(NodeTool.getNodeName(e)){case`msub`:t=getRender_default(`@1_{@2}`);break;case`msup`:t=getRender_default(`@1^{@2}`);break;case`msubsup`:t=getRender_default(`@1_{@2}^{@3}`);break;case`mover`:t=renderMover;break;case`munder`:t=renderMunder;break;case`munderover`:t=getRender_default(`@1\\limits_{@2}^{@3}`);break;case`mmultiscripts`:t=renderMmultiscripts;break;case`mroot`:t=getRender_default(`\\sqrt[@2]{@1}`);break;case`msqrt`:t=getRender_joinSeparator(`\\sqrt{@content}`);break;case`mtable`:t=renderTable;break;case`mtr`:t=getRender_joinSeparator(`@content \\\\ `,` & `);break;case`mtd`:t=getRender_joinSeparator(`@content`);break;case`mfrac`:t=renderMfrac;break;case`mfenced`:t=renderMfenced;break;case`mi`:case`mn`:case`mo`:case`ms`:case`mtext`:t=getRender_joinSeparator(`@content`);break;case`mphantom`:t=renderMphantom;break;default:t=getRender_joinSeparator(`@content`);break}return t}function renderTable(e,t){return getRender_joinSeparator(`\\begin{matrix} @content \\end{matrix}`)(e,t)}function renderMfrac(e,t){let[n,r]=[NodeTool.getAttr(e,`linethickness`,`medium`),NodeTool.getAttr(e,`bevelled`,`false`)],a=null;if(r===`true`)a=getRender_default(`{}^{@1}/_{@2}`);else if([`0`,`0px`].indexOf(n)>-1){let[t,n]=[NodeTool.getPrevNode(e),NodeTool.getNextNode(e)];a=t&&NodeTool.getNodeText(t).trim()===`(`&&n&&NodeTool.getNodeText(n).trim()===`)`?getRender_default(`\\DELETE_BRACKET_L\\binom{@1}{@2}\\DELETE_BRACKET_R`):getRender_default(`{}_{@2}^{@1}`)}else a=getRender_default(`\\frac{@1}{@2}`);return a(e,t)}function renderMfenced(e,t){let[n,r,a]=[NodeTool.getAttr(e,`open`,`(`),NodeTool.getAttr(e,`close`,`)`),NodeTool.getAttr(e,`separators`,`,`)],[o,s]=[Brackets.parseLeft(n),Brackets.parseRight(r)],c=a.split(``).filter(e=>e.trim().length===1);return getRender_joinSeparators(`${o}@content${s}`,c)(e,t)}function renderMmultiscripts(e,t){if(t.length===0)return``;let n=-1,r=null;Array.prototype.forEach.call(t,e=>{NodeTool.getNodeName(e)===`mprescripts`&&(r=e)}),r&&(n=Array.prototype.indexOf.call(t,r));let a=renderChildren(t),o=(e,t)=>[e.slice(0,t),e.slice(t+1,e.length)],s=e=>{if(e.length>0){let t=[],n=[];return e.forEach((e,r)=>{(r+1)%2==0?n.push(e):t.push(e)}),[t.length>0?`_{${t.join(` `)}}`:``,n.length>0?`^{${n.join(` `)}}`:``].join(``)}else return``},c=a.shift(),l=[],u=[];return n===-1?u=a:[u,l]=o(a,n-1),[s(l),c,s(u)].join(``)}function renderMover(e,t){let n=flattenNodeTreeByNodeName(e,`mover`),r;for(let e=0;e<n.length-1;e++){r||=parse(n[e]);let t=parse(n[e+1]);r=renderTemplate(getMatchValueByChar({decimals:MathSymbol.overScript.decimals,values:MathSymbol.overScript.templates,judgeChar:t,defaultValue:`@1\\limits^{@2}`}).replace(`@v`,`@1`),[r,t])}return r}function renderMunder(e,t){let n=flattenNodeTreeByNodeName(e,`munder`),r;for(let e=0;e<n.length-1;e++){r||=parse(n[e]);let t=parse(n[e+1]);r=renderTemplate(getMatchValueByChar({decimals:MathSymbol.underScript.decimals,values:MathSymbol.underScript.templates,judgeChar:t,defaultValue:`@1\\limits_{@2}`}).replace(`@v`,`@1`),[r,t])}return r}function flattenNodeTreeByNodeName(e,t){let n=[],r=NodeTool.getChildren(e);return Array.prototype.forEach.call(r,e=>{NodeTool.getNodeName(e)===t?n=n.concat(flattenNodeTreeByNodeName(e,t)):n.push(e)}),n}function getMatchValueByChar(e){let{decimals:t,values:n,judgeChar:r,defaultValue:a=null}=e;if(r&&r.length===1){let e=t.indexOf(r.charCodeAt(0));if(e>-1)return n[e]}return a}function renderMphantom(e,t){return``}function getRender_default(e){return function(t,n){return renderTemplate(e,renderChildren(n))}}function renderTemplate(e,t){return e.replace(/\@\d+/g,e=>t[parseInt(e.substring(1,e.length))-1])}function getRender_joinSeparator(e,t=``){return function(n,r){let a=renderChildren(r);return e.replace(`@content`,a.join(t))}}function getRender_joinSeparators(e,t){return function(n,r){let a=renderChildren(r),o=``;return o=t.length===0?a.join(``):a.reduce((e,n,r)=>(e+=n,r<a.length-1&&(e+=t[r]||t[t.length-1]),e),``),e.replace(`@content`,o)}}var mathml2latex={convert};function fixCharacters(e){return e.replace(/’/g,`'`).replace(/“/g,`"`).replace(/”/g,`"`).replace(/\x0b/g,` `).replace(/\u201d/g,`"`).replace(/\u201c/g,`"`)}function numberString(e,t=`1`){return[`a`].includes(t)?String.fromCharCode(97+e-1)+`. `:[`A`].includes(t)?String.fromCharCode(65+e-1)+`. `:[`I`].includes(t)?`${romanize(e)}. `:[`i`].includes(t)?`${romanize(e).toLowerCase()}. `:([`1`].includes(t),`${e}. `)}function romanize(e){let t=[[`M`,1e3],[`CM`,900],[`D`,500],[`CD`,400],[`C`,100],[`XC`,90],[`L`,50],[`XL`,40],[`X`,10],[`IX`,9],[`V`,5],[`IV`,4],[`I`,1]],n=``;for(let[r,a]of t)for(;e>=a;)n+=r,e-=a;return n}function escapeMarkdown(e){let t=[{char:`\\`,escape:`\\\\`},{char:`#`,escape:`\\#`},{char:`<`,escape:`\\<`},{char:`…`,escape:`...`},{char:`©`,escape:`(c)`},{char:`®`,escape:`(r)`},{char:`™`,escape:`(tm)`},{char:`±`,escape:`+-`},{char:`—`,escape:`---`}],n=e.map&&e.map.length>0?e.map[0]:0;if(!n){let n=fixCharacters(e.content);for(let{char:e,escape:r}of t)n=n.replaceAll(e,r);return[[n,e]]}let r=fixCharacters(e.content).split(``),a=[],o=Object.fromEntries(t.map(e=>[e.char,e.escape])),s=0,c=``,l=``,u=()=>{if(l.length>0){let t=structuredClone(e);t.map=[n+s],a.push([l,t]),s=c.length}l=``};for(let e=0;e<r.length;e++){let t=r[e];c+=t,o[t]&&u(),l+=o[t]||t,o[t]&&u()}return u(),a}function getLinkTokensHandlers(){return{text:[(e,t)=>{t.current.meta.link_text+=e.content,e.content&&!t.current.meta.link_token_token&&(t.current.meta.link_token_token=e)}],link_close:[(e,t)=>{{let n=t.current.meta.link_open_token,r=n.attrGet(`href`)||``,a=n.attrGet(`title`)||``,o=n.attrGet(`origUrl`)||r,s=t.current.meta.link_text;o===s&&(s=r);let c=n.attrGet(`mdTemplate`);if(c){let n=r.split(`/`).pop();c=c.replaceAll(`$href`,r),c=c.replaceAll(`$basename`,n||``),c=c.replaceAll(`$label`,t.current.meta.link_text),c=c.replaceAll(`$title`,a||``),t.current.log(c,e)}else!a&&s===r?t.current.log(r,e):!a&&!r?(t.current.log(`[`,e),t.current.log(s,t.current.meta.link_token_token),t.current.log(`]${a}`,e)):(t.current.log(`[`,e),t.current.log(s,t.current.meta.link_token_token),a?t.current.log(`](${r} ${a})`,e):t.current.log(`](${r})`,e));t.unstash(`getLinkTokensHandlers.link_close`)}}],default:[(e,t)=>{}]}}function getInlineTokensHandlers(){return{text:[(e,t)=>{if(e.meta===`noEscText`)t.current.log(e.content);else for(let n of escapeMarkdown(e))t.current.log(n[0],n[1])}],entity:[(e,t)=>{t.current.log(e.content)}],strong_open:[(e,t)=>{t.current.log(e.markup||`**`,e)}],strong_close:[(e,t)=>{t.current.log(e.markup||`**`,e)}],em_open:[(e,t)=>{t.current.log(e.markup||`*`,e)}],em_close:[(e,t)=>{t.current.log(e.markup||`*`,e)}],underline_open:[(e,t)=>{t.current.log(e.markup||`_`,e)}],underline_close:[(e,t)=>{t.current.log(e.markup||`_`,e)}],strike_open:[(e,t)=>{t.current.log(e.markup||`~`,e)}],strike_close:[(e,t)=>{t.current.log(e.markup||`~`,e)}],link_open:[(e,t)=>{t.stash(`getInlineTokensHandlers.link_open`),t.current.handlers=getLinkTokensHandlers(),t.current.meta.link_open_token=e,t.current.meta.link_text=``,t.current.meta.link_token_token=null}],code_open:[(e,t)=>{t.current.log("`",e)}],code_close:[(e,t)=>{t.current.log("`",e)}],code_inline:[(e,t)=>{t.current.log("`"+e.content+"`",e)}],math:[(e,t)=>{let n=e.content;if(e.attrGet(`lang`)===`mathml`){let e=n.replace(/<annotation[\s\S]*?<\/annotation>/g,``);n=mathml2latex.convert(e)}t.current.log(`$`+n+`$`,e)}],hardbreak:[(e,t)=>{t.current.log(t.current.lineBreak+`
|
|
26
26
|
`,e)}],softbreak:[(e,t)=>{t.current.log(`
|
|
27
27
|
`,e)}],image:[(e,t)=>{{let n=e.attrGet(`src`),r=e.attrGet(`alt`)||``;if(e.children)for(let t of e.children)t.type===`text`&&(r+=t.content);let a=`![$alt]`,o=e.attrGet(`title`);n&&(o?a+=`($src $title)`:a+=`($src)`),a=e.attrGet(`mdTemplate`)||a,a=a.replaceAll(`$alt`,r),a=a.replaceAll(`$label`,r),a=a.replaceAll(`$src`,n||``),a=a.replaceAll(`$title`,o||``),t.current.log(a,e)}}],html_block:[(e,t)=>{t.current.log(e.content,e)}],footnote_ref:[(e,t)=>{e.meta.label?t.current.log(`[^${e.meta.label}]`,e):t.current.log(`[^footnote_${e.meta.id}]`,e)}],shortcode_inline:[(e,t)=>{t.current.log(`{{`+e.content+`}}`,e)}],bookmark:[(e,t)=>{t.current.log(`<a id="${e.attrGet(`id`)}"></a>`,e)}]}}function escapeHtml$1(e){return e}function getHtmlInlineFormatTokensHandlers(){return{strong_open:[(e,t)=>{let n=e.tag||`strong`;t.current.log(`<${n}>`,e)}],strong_close:[(e,t)=>{let n=e.tag||`strong`;t.current.log(`</${n}>`,e)}],em_open:[(e,t)=>{let n=e.tag||`em`;t.current.log(`<${n}>`,e)}],em_close:[(e,t)=>{let n=e.tag||`em`;t.current.log(`</${n}>`,e)}],strike_open:[(e,t)=>{let n=e.tag||`strike`;t.current.log(`<${n}>`,e)}],strike_close:[(e,t)=>{let n=e.tag||`strike`;t.current.log(`</${n}>`,e)}],underline_open:[(e,t)=>{let n=e.tag||`u`;t.current.log(`<${n}>`,e)}],underline_close:[(e,t)=>{let n=e.tag||`u`;t.current.log(`</${n}>`,e)}]}}function getHtmlInlineTokensHandlers(){return{text:[(e,t)=>{t.current.log(escapeHtml$1(e.content),e)}],entity:[(e,t)=>{t.current.log(e.content,e)}],...getHtmlInlineFormatTokensHandlers(),link_open:[(e,t)=>{t.stash(`getHtmlInlineTokensHandlers.link_open`);let n=e.attrGet(`href`)||``,r=e.attrGet(`title`);r&&``+r,t.current.log(`<a href="${n}">`,e)}],link_close:[(e,t)=>{t.current.log(`</a>`,e),t.unstash(`getHtmlInlineTokensHandlers.link_close`)}],code_open:[(e,t)=>{let n=e.tag||`code`;t.current.log(`<${n}>`,e)}],code_close:[(e,t)=>{let n=e.tag||`code`;t.current.log(`<${n}>`,e)}],math:[(e,t)=>{t.current.log(`<math xmlns="http://www.w3.org/1998/Math/MathML">`,e),t.current.log(e.content,e),t.current.log(`</math>`,e)}],hardbreak:[(e,t)=>{let n=e.tag||`br`;t.current.log(`<${n} />`,e)}],softbreak:[(e,t)=>{let n=e.tag||`wbr`;t.current.log(`<${n} />`,e)}],image:[(e,t)=>{{let n=``;if(e.children)for(let t of e.children)t.type===`text`&&(n+=t.content);let r=e.tag||`img`;t.current.log(`<${r} />`,e)}}],html_block:[(e,t)=>{t.current.log(e.content,e)}],footnote_ref:[(e,t)=>{}],shortcode_inline:[(e,t)=>{t.current.log(`{{`+e.content+`}}`,e)}],bookmark:[(e,t)=>{t.current.log(`<a id="${e.attrGet(`id`)}"></a>`,e)}]}}function getHtmlBasicTokensHandlers(){return{frontmatter:[],heading_open:[(e,t)=>{t.current.log(`<${e.tag}>`,e)}],heading_close:[(e,t)=>{t.current.log(`</${e.tag}>\n`,e)}],paragraph_open:[(e,t)=>{t.current.log(`<p>`,e)}],paragraph_close:[(e,t)=>{t.current.log(`</p>
|
|
28
28
|
`,e)}],fence:[(e,t)=>{t.current.log(`<pre>`+e.content+`</pre>
|
|
@@ -119,7 +119,7 @@ ${JSON.stringify(a,null,2)}`),Error(`Language.load failed: no language function
|
|
|
119
119
|
`);break}if(t&&t.match(/^\s+$/)){if(t.endsWith(`
|
|
120
120
|
`)){let n=new Token(`hardbreak`,`wbr`,0);n.map=e,n.meta=`noEscText`,n.content=t??``,s(n,`whitespace hardbreak`)}else{let n=new Token(`text`,`br`,0);n.map=e,n.meta=`noEscText`,n.content=t??``,s(n,`whitespace space`)}break}if(t?.trim().length>0){l(t,u);break}}break;case`shortcut_link`:{let t=`a`,n=new Token(`link_open`,`a`,1),r=u.children.find(e=>e?.type===`link_destination`);n.attrSet(`href`,o(r)||``);let a=u.children.find(e=>e?.type===`link_title`);a&&n.attrSet(`title`,o(a)||``),s(n,`shortcut_link`),u.children.filter(e=>e.type===`link_text`).forEach(t=>{let n=new Token(`text`,``,0);n.map=e,n.meta=`noEscText`,n.content=o(t)??``,s(n,`link_text`)}),s(new Token(`link_close`,`a`,-1),`/shortcut_link`)}break;case`inline_link`:{let t=`a`,n=new Token(`link_open`,`a`,1),r=u.children.find(e=>e.type===`link_destination`);n.attrSet(`href`,r?.text||``);let a=u.children.find(e=>e.type===`link_title`);a&&n.attrSet(`title`,a.text||``),s(n,`inline_link`),u.children.filter(e=>e.type===`link_text`).forEach(t=>{let n=new Token(`text`,``,0);n.map=e,n.meta=`noEscText`,n.content=o(t)??``,s(n,`inline_link_txt`)}),s(new Token(`link_close`,`a`,-1),`/inline_link`)}break;case`image`:{let e=new Token(`image`,`img`,0),t=u.children.find(e=>e.type===`image_description`);e.attrSet(`alt`,t?.text||``);let n=u.children.find(e=>e.type===`link_destination`);e.attrSet(`src`,n?.text||``);let r=u.children.find(e=>e.type===`link_title`);r&&e.attrSet(`title`,r.text||``),s(e,`image`)}break;case`strong_emphasis`:{let e=u.children.find(e=>e.type===`emphasis_delimiter`),n=e?.text===`_`?`underline`:`strong`,r=e?.text===`_`?`u`:`strong`,a=new Token(n+`_open`,r,1);e?.text===`_`&&(a.markup=`__`),s(a,`strongem`),c(u.children,t);let l=new Token(n+`_close`,r,-1);o(e)===`_`&&(l.markup=`__`),s(l,`/strongem`)}break;case`emphasis`:{let e=u.children.find(e=>e.type===`emphasis_delimiter`),n=u.children.filter(e=>e.type!==`emphasis_delimiter`),r=e?.text===`_`?`underline`:`em`,a=e?.text===`_`?`u`:`em`;s(new Token(r+`_open`,a,1),`em`),c(n.filter(e=>!!e),t),s(new Token(r+`_close`,a,-1),`/em`)}break;case`strikethrough`:{let e=`strike`;s(new Token(`strike_open`,e,1),`s`),c(u.children.filter(e=>!!e),t),s(new Token(`strike_close`,e,-1),`/s`)}break;case`code_span`:{let e=`code`;s(new Token(`code_open`,e,1),`code`),c(u.children.filter(e=>!!e),t),s(new Token(`code_close`,e,-1),`/code`)}break;case`html_tag`:{let e=new Token(`html_block`,``,0);e.content=o(u)||``,s(e,`html_block`)}break;case`hard_line_break`:{let t=new Token(`hardbreak`,`br`,0);t.map=e,t.meta=`noEscText`,t.content=o(u)??``,s(t,`hard_line_break`)}break;case`backslash_escape`:{let t=new Token(`text`,``,0);t.map=e,t.meta=`noEscText`,t.content=o(u)??``,s(t,`backslash_escape`)}break;default:{console.debug(`Unhandled inline node type: ${u.type}`,u);let t=new Token(`text`,``,0);t.map=e,t.meta=`noEscText`,t.content=`Error: Unhandled inline node type: ${u.type} ${JSON.stringify(u)}`,s(t,`backslash_escape`)}break}}},l=(e,n={tableRowType:`tbody`,cellNo:0,cellAlign:[]})=>{if(e){if(e.type===`inline`){let n=o(e);if(!n)throw Error(`!inlineText`);let r=t.parse(n);if(!r)throw Error(`!inlineTree`);let a=new ExtendedNode(r.rootNode,n);c(a.children.length>0?a.children:[a],n,e.startPosition);return}if(!e.children||e.children.length===0){if(e.type===`text`||e.type.length===1){let t=new Token(`text`,``,0);t.map=[+e.startPosition?.row,+e.endPosition?.row,+e.startPosition?.column,+e.endPosition?.column],t.meta=`noEscText`,t.content=o(e)??``,s(t,`txt2`);return}if(e.type===`whitespace`){if(a===0||(o(e)||``).match(/^\n+$/))return;let t=o(e)||``;if(t&&t.match(/^\s+$/)){let t=new Token(`text`,`br`,0);t.map=[+e.startPosition?.row,+e.endPosition?.row,+e.startPosition?.column,+e.endPosition?.column],t.meta=`noEscText`,t.content=o(e)??``,s(t,`txt3`);return}if(t.trim().length>0){let n=new Token(`text`,``,0);n.map=[+e.startPosition?.row,+e.endPosition?.row,+e.startPosition?.column,+e.endPosition?.column],n.meta=`noEscText`,n.content=t??``,s(n,`txt4`);return}}}switch(e.type){case`block_continuation`:break;case`document`:case`section`:e.children.filter(e=>!!e).forEach(e=>l(e,n));break;case`thematic_break`:{let t=new Token(`hr`,`hr`,0);t.level=a,t.map=[+e.startPosition?.row,+e.endPosition?.row,+e.startPosition?.column,+e.endPosition?.column],t.markup=o(e)||``,t.attrSet(`margin_before`,`1`),t.attrSet(`margin_after`,`1`),r.push(t)}break;case`setext_heading`:{let t=e.children.filter(e=>!!e).find(e=>e.type.startsWith(`setext_`)&&e.type.endsWith(`_underline`)),s=t?.type.substring(7,9)||`h1`,c=new Token(`heading_open`,s,1);c.level=a,c.markup=o(t)||`#`,c.attrSet(`margin_before`,`1`),r.push(c);let u=e.children.filter(e=>!!e).filter(e=>!e.type.startsWith(`setext_`));a++,u.forEach(e=>l(e,n)),a--;let d=new Token(`heading_close`,s,-1);d.level=a,d.markup=o(t)||``,d.attrSet(`margin_after`,`1`),r.push(d)}break;case`atx_heading`:{let t=e.children.filter(e=>!!e).find(e=>e.type.startsWith(`atx_`)&&e.type.endsWith(`_marker`)),s=t?.type.substring(4,6)||`h1`,c=new Token(`heading_open`,s,1);c.level=a,c.markup=o(t)||`#`,c.attrSet(`margin_before`,`1`),r.push(c);let u=[...e.children.filter(e=>!!e)];u.length>0&&u[0].type.endsWith(`_marker`)&&u.splice(0,1),u.length>0&&u[0].type===`whitespace`&&u.splice(0,1),u.length>0&&u[u.length-1].type===`whitespace`&&u.splice(u.length-1,1),a++,u.forEach(e=>l(e,n)),a--;let d=new Token(`heading_close`,s,-1);d.level=a,d.attrSet(`margin_after`,`1`),r.push(d)}break;case`minus_metadata`:{let t=new Token(`frontmatter`,`frontmatter`,0);t.level=a,t.content=o(e)||``,r.push(t)}break;case`fenced_code_block`:{let t=`fence`,n=`pre`,s=e.children.filter(e=>!!e).find(e=>e.type===`info_string`),c=new Token(`fence`,`pre`,0);c.meta=`noEscText`,c.level=a,c.markup="```",s&&c.attrSet(`lang`,o(s)||``),c.content=[...e.children.filter(e=>!!e).filter(e=>e?.type===`code_fence_content`)].map(e=>o(e)||``).join(``),c.attrSet(`margin_before`,`1`),c.attrSet(`margin_after`,`1`),r.push(c)}break;case`block_quote`:{let t=`blockquote`,o=new Token(`blockquote_open`,t,1);o.level=a,o.attrSet(`margin_before`,`1`),r.push(o),a++,e.children?.filter(e=>![`block_quote_marker`].includes(e.type)).forEach(e=>l(e,n)),a--;let s=new Token(`blockquote_close`,t,-1);s.level=a,s.attrSet(`margin_after`,`1`),r.push(s)}break;case`indented_code_block`:{let t=new Token(`code_block`,`code_block`,0);t.level=a;let n=80;`indent`in e&&(n=e.indent.length);let o=e.text.split(`
|
|
121
121
|
`);for(let e of o){if(e.trim().length===0)continue;let t=e.match(/^ +/);t?n>t[0].length&&(n=t[0].length):n=0}let s=o.map(e=>e.substring(n)).join(`
|
|
122
|
-
`);t.attrSet(`indent`,``+n),t.content=s,t.attrSet(`margin_before`,`1`),t.attrSet(`margin_after`,`1`),r.push(t)}break;case`paragraph`:{let t=`p`,o=new Token(`paragraph_open`,`p`,1);o.level=a,o.attrSet(`margin_before`,`1`),r.push(o),a++,e.children?.forEach(e=>l(e,n)),a--;let s=new Token(`paragraph_close`,`p`,-1);s.level=a,s.attrSet(`margin_after`,`1`),r.push(s)}break;case`pipe_table_cell`:{let t=n.tableRowType===`thead`?`th`:`td`,o=n.tableRowType===`thead`?`th`:`td`,c=new Token(t+`_open`,o,1);c.attrSet(`align`,n.cellAlign[n.cellNo]||`left`),c.level=a,r.push(c),a++;{let t=`p`,o=new Token(`paragraph_open`,`p`,1);o.level=a,r.push(o);let c=[...e.children];for(;c.length>0&&c[c.length-1].type===`whitespace`;)c.splice(c.length-1,1);if(c.length>0)c.forEach(e=>l(e,n));else{let t=[e.startPosition?.row,e.endPosition?.row,e.startPosition?.column,e.endPosition?.column],n=new Token(`text`,``,0);n.map=t,n.meta=`noEscText`,n.content=e.text?.replace(/\s+$/,``)??``,s(n,`txt5`)}let u=new Token(`paragraph_close`,`p`,-1);u.level=a,r.push(u)}a--;let u=new Token(t+`_close`,o,-1);u.level=a,r.push(u),n.cellNo++}break;case`pipe_table_header`:case`pipe_table_row`:{let t=`tr`,o=new Token(`tr_open`,`tr`,1);o.level=a,r.push(o),a++,e.children.filter(e=>!!e).filter(e=>e.type===`pipe_table_cell`).forEach(e=>l(e,n)),a--;let s=new Token(`tr_close`,`tr`,-1);s.level=a,r.push(s)}break;case`pipe_table`:{let t=`table`,o=new Token(`table_open`,t,1);o.level=a,o.attrSet(`margin_before`,`1`),r.push(o),a++;let s=e.children.filter(e=>!!e).filter(e=>e.type===`pipe_table_delimiter_row`),c=[];if(s.length>0){let e=s[0].children.filter(e=>!!e).filter(e=>e.type===`pipe_table_delimiter_cell`);for(let t=0;t<e.length;t++)e[t].children.filter(e=>!!e).find(e=>e.type===`pipe_table_align_right`)?c.push(`right`):c.push(`left`)}let u=e.children.filter(e=>!!e).filter(e=>e.type===`pipe_table_header`);if(u.length>0){let e=`thead`,t=new Token(`thead_open`,e,1);t.level=a,r.push(t),a++,u.forEach(e=>l(e,{...n,tableRowType:`thead`,cellNo:0,cellAlign:c})),a--;let o=new Token(`thead_close`,e,-1);o.level=a,r.push(o)}let d=e.children?.filter(e=>e?.type===`pipe_table_row`);d.length>0&&(a++,d.filter(e=>!!e).forEach(e=>l(e,{...n,tableRowType:`tbody`,cellAlign:c})),a--),a--;let f=new Token(`table_close`,t,-1);f.level=a,f.attrSet(`margin_after`,`1`),r.push(f)}break;case`list`:{let t=`bullet_list`,s=`ul`,c=``,u=e.children.filter(e=>!!e).find(e=>e.type===`list_item`);if(u){let e=u.children.filter(e=>!!e).find(e=>e.type.startsWith(`task_list_marker`)),n=u.children.filter(e=>!!e).find(e=>e.type.startsWith(`list_marker_dot`));e?(t=`task_list`,s=`ul`):n&&(t=`ordered_list`,s=`ol`,c=(o(n)||``).trim().replace(`.`,``))}let d=new Token(t+`_open`,s,1);d.level=a,d.markup=s===`ol`?`.`:`*`,d.attrSet(`symbol`,s===`ol`?`1`:`*`),c&&d.attrSet(`start`,c),d.attrSet(`margin_before`,`1`),r.push(d),a++,e.children.filter(e=>!!e).forEach(e=>l(e,n)),a--;let f=new Token(t+`_close`,s,-1);f.level=a,f.attrSet(`margin_after`,`1`),r.push(f)}break;case`list_item`:{let t=e.children.filter(e=>!!e).find(e=>e.type.startsWith(`task_list_marker_`)),s=e.children.filter(e=>!!e).find(e=>e.type.startsWith(`list_marker_`));if(!s)break;let c=t?`task_item`:`list_item`,u=`li`,d=new Token(c+`_open`,`li`,1);d.level=a,d.markup=(o(s)||``).trim(),s.type===`list_marker_dot`&&(d.info=``,d.markup=``),t&&(t.type,d.attrSet(`checked`,t.type===`task_list_marker_checked`?`checked`:``)),r.push(d),a++,l(e.children.filter(e=>!!e).find(e=>e.type===`paragraph`),n);let f=e.children.filter(e=>!!e).filter(e=>e.type===`list`);for(let e of f)l(e,n);a--;let p=new Token(c+`_close`,`li`,-1);p.level=a,r.push(p)}break;case`html_block`:{let t=new Token(`html_block`,``,0);t.level=a,t.content=o(e)??``,t.attrSet(`margin_before`,`1`),t.attrSet(`margin_after`,`1`),r.push(t)}break;case`text`:{let t=new Token(`text`,``,0);t.level=a,t.content=o(e)??``,r.push(t)}break;default:throw console.warn(`Unhandled node type: ${e.type}, children: ${e.children.map(e=>e.type).join(`, `)}`,{...e,children:void 0,_children:void 0,tree:void 0}),Error(`Unhandled node type: ${e.type}`)}}};return l(e),r}async function sitterTokenizer(e){let t=getLangTreeSitter(`markdown`),n=t.files.find(e=>e.indexOf(`_inline`)===-1),r=t.files.find(e=>e.indexOf(`_inline`)>-1),a=await e(t.dir+`/`+n),o=await e(t.dir+`/`+r),s=await createParser(a,{assetLoad:e}),c=await createParser(o,{assetLoad:e});return{parse:e=>{let t=s.parse(e);if(!t)throw Error(`Tree is null`);return treeToTokens(new ExtendedNode(t.rootNode,e),c,e)}}}function listIsTight(e,t){for(;++t<e.length;)if(e[t].type!=`list_item_open`)return e[t].hidden;return!1}async function mdToPmConverter(e,t,n){return mdToPmConverterText(new TextDecoder().decode(e),t,n)}async function mdToPmConverterText(e,t,n){if(!t.assetLoad)throw Error(`No config.assetLoad`);let r=new MarkdownParser(n,await sitterTokenizer(t.assetLoad),{frontmatter:{custom:(e,n)=>{let r=e.stack[0];if(r?.type.name===`doc`&&t.frontmatter){let e=t.frontmatter.parse(n.content)||void 0;r.attrs={...r.attrs,meta:e}}}},blockquote:{block:`blockquote`},paragraph:{block:`paragraph`},task_item:{block:`task_item`},task_list:{block:`task_list`},list_item:{block:`list_item`},bullet_list:{block:`bullet_list`,getAttrs:(e,t,n)=>({tight:listIsTight(t,n)})},ordered_list:{block:`ordered_list`,getAttrs:(e,t,n)=>({start:+e.attrGet(`start`)||1,tight:listIsTight(t,n)})},dl:{block:`dl`},dt:{block:`dt`},dd:{block:`dd`},heading:{block:`heading`,getAttrs:e=>({level:+e.tag.slice(1)})},code_block:{block:`code_block`,getAttrs:e=>({lang:e.attrGet(`lang`)||void 0}),noCloseToken:!0},fence:{block:`code_block`,getAttrs:e=>({lang:e.attrGet(`lang`)||void 0}),noCloseToken:!0},hr:{custom:(e,t,r,a)=>{e.openNode(n.nodes.paragraph,{}),e.addNode(n.nodes.hr,{}),e.closeNode()}},image:{node:`image`,getAttrs:e=>{let t=e.children?e.children[0]:void 0;return{src:e.attrGet(`src`),title:e.attrGet(`title`)||null,alt:t?.content||null}}},entity:{custom:(e,t,n,r)=>{e.addText(decodeEntity(t.content))}},hardbreak:{node:`br`},em:{mark:`em`},underline:{mark:`underline`},strong:{mark:`strong`},strike:{mark:`strike`},link:{mark:`link`,getAttrs:e=>({href:e.attrGet(`href`),title:e.attrGet(`title`)||null})},code:{mark:`code`},html_block:{custom:(e,t,r,a)=>{let o=DOMParser$1.fromSchema(n).parse(elementFromString(t.content));e.importNodes(o.children)}},footnote_ref:{block:`code_block`},table:{block:`table`},tr:{block:`table_row`},td:{block:`table_cell`},th:{block:`table_header`},thead:{ignore:!0}}).parse(e),a=[...t.hooks||[]],o=EditorState.create({doc:r}),s=e=>{o=o.apply(e)};if(a.length>0)for(let e of a)await e(o,e=>s(e));return o.doc}var addEmptyLines=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;function s(e,t,n=0,c=0){let l=0,u=!1;for(let t=0;t<e.length;t++){let d=e[t];if([`image`,`node_bookmark`].includes(d.type.name)&&t>0){let s=e[t-1];if(s.type!==o)if(s.type===a)r.setNodeMarkup(r.mapping.map(n+l-s.nodeSize),o);else{let e=o.createAndFill();e&&r.insert(r.mapping.map(n+l),e)}}if(d.type.name===`softbreak`){let a=e[t-1];e[t+1],a?.type.name===`softbreak`&&r.delete(r.mapping.map(n+l),r.mapping.map(n+l+d.nodeSize)),a?.textContent?.endsWith(` `)&&r.delete(r.mapping.map(n+l),r.mapping.map(n+l+d.nodeSize)),u||r.delete(r.mapping.map(n+l),r.mapping.map(n+l+d.nodeSize))}else u=!0;s(d.children,d,n+l+1,c+1),l+=d.nodeSize}}return s(n.children,n),t&&t(r),r.docChanged},fixIdLinks=(e,t)=>{let n=e.tr,r=e.schema.marks.link;return e.doc.descendants((e,t)=>{e.marks.forEach(a=>{if(a.type===r&&a.attrs.href.startsWith(`#`)){let o=(e.text||e.textBetween(0,e.content.size)).toLowerCase().replace(/[^\w]+/g,` `).trim().replaceAll(` `,`-`);o&&(n=n.removeMark(t,t+e.nodeSize,r).addMark(t,t+e.nodeSize,r.create({...a.attrs,href:`#`+o})))}})}),t&&t(n),n.docChanged},fixShortCodes=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;if(!a)throw Error(`No hardbreak type in schema`);if(!o)throw Error(`No softbreak type in schema`);function s(e,t=0,n=0){e.forEach((c,l,u)=>{if(c.type.name===`shortcode_inline`){if(u>1){let n=e.child(u-1);n.type===a&&(r=r.setNodeMarkup(t+l-n.nodeSize,o))}u<e.childCount-1&&e.child(u+1).type===a&&(r=r.setNodeMarkup(t+l+c.nodeSize,o))}s(c,t+l+1,n+1)})}return s(n),t&&t(r),r.steps.length>0},removeEmptyTags=(e,t)=>{let n=e.schema.nodes.paragraph,r=e.tr;return e.doc.descendants((e,t)=>{if([`paragraph`].includes(e.type.name)){let n=e.children.every(e=>e.isText&&e.textContent===``);(e.childCount===0||n)&&r.deleteRange(r.mapping.map(t),r.mapping.map(t+e.nodeSize))}else if([`heading`].includes(e.type.name)){let a=e.children.find(e=>e.type.name===`node_bookmark`),o=e.children.every(e=>e.isText&&e.textContent===``||e.type.name===`node_bookmark`);a&&o?r.setNodeMarkup(r.mapping.map(t),n):(e.childCount===0||o)&&r.deleteRange(r.mapping.map(t),r.mapping.map(t+e.nodeSize))}}),t&&t(r),r.docChanged},removeSuggest=(e,t)=>{let n={},r=e.tr,a=e.doc,o=`comment`;a.descendants((e,t)=>{if(e.type.name===`comment`&&e.attrs.id){let r=e.attrs.id;n[r]||(n[r]=[]),e.attrs.nesting===1&&(n[r][0]={node:e,pos:t}),e.attrs.nesting===-1&&(n[r][1]={node:e,pos:t})}});for(let e in n){let t=n[e][0],a=n[e][1];if(t&&a){let e=t.pos,n=a.pos+a.node.nodeSize;r.replace(r.mapping.map(e),r.mapping.map(n))}}return t&&t(r),r.docChanged},rewriteUrls=e=>async(t,n)=>{let r=e?.();if(!r)return!1;let a=t.tr,o=t.schema.marks.link,s=t.schema.nodes.image,c=[],l=[];t.doc.descendants((e,t)=>{e.marks.forEach(n=>{n.type===o&&c.push([n,t,t+e.nodeSize])}),e.type===s&&l.push([e,t])});for(let[e,n,o]of c){let s=e.attrs.href,c={},l=await r(s,{type:`A`,dest:`md`,setMeta:(e,t)=>{c[e]=t}});if(l!==s||c.mdTemplate){let r=c.mdTemplate;a.removeMark(a.mapping.map(n),a.mapping.map(o),e);let u=t.schema.mark(`link`,{...e.attrs,href:l,origUrl:s,mdTemplate:r});a.addMark(a.mapping.map(n),a.mapping.map(o),u)}}for(let[e,t]of l){let n=e.attrs.src,o={},s=await r(n,{type:`IMG`,dest:`md`,setMeta:(e,t)=>{o[e]=t}});if(s!==n||o.mdTemplate){let r=o.mdTemplate;a.setNodeMarkup(a.mapping.map(t),null,{...e.attrs,src:s,origUrl:n,mdTemplate:r})}}return n&&n(a),a.docChanged},trimLines=(e,t)=>{let n=e.doc,r=e.schema,a=e.tr,o=e.schema.nodes.br,s=e.schema.nodes.softbreak,c=e.schema.nodes.paragraph;function l(e,t,n=0,u=0){let d=0;if(t.type.name===`code_block`&&t.textContent.trim())return;function f(t,o){let s=n+o;for(let n=t-1;n>=0;n--){let t=e[n];if(t?.type.name!==`text`)break;let o=t.text||``,c=o.replace(/[ \t\u00A0]+$/,``);if(c!==o){let e=s-t.nodeSize;c.length>0?a.replaceRangeWith(a.mapping.map(e),a.mapping.map(s),r.text(c)):a.replace(a.mapping.map(e),a.mapping.map(s))}else break;s-=t.nodeSize;break}}let p=!1;for(let m=0;m<e.length;m++){let h=e[m];if(h.isText){let e=h.text||``;if(e.match(/^([ \t\u00A0]+)/)&&!p&&c!==t.type){e=e.replace(/^[ \t\u00A0]+/,``);let t=n+d,o=t+h.nodeSize;e?a.replaceRangeWith(a.mapping.map(t),a.mapping.map(o),r.text(e)):a.replace(a.mapping.map(t),a.mapping.map(o))}e&&(p=!0)}o===h.type&&(f(m,d),m+1<e.length&&(e[m+1].type===o||e[m+1].type===s)&&a.setNodeMarkup(a.mapping.map(n+d),s)),l(h.children,h,n+d+1,u+1),d+=h.nodeSize}f(e.length,d)}return l(n.children,n),t&&t(a),a.docChanged},insertToc=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;if(!a)throw Error(`No hardbreak type in schema`);if(!o)throw Error(`No softbreak type in schema`);return n.forEach((e,t,n)=>{if(e.type.name===`bullet_list`&&e.attrs.toc){let t=e.copy(Fragment.from(e.content));r.insert(0,t)}}),t&&t(r),r.steps.length>0},addEnterAfterImage=(e,t)=>{let n=e.tr,r=e.schema.nodes.image,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;function s(t,c=0,l=0){t.forEach((u,d,f)=>{if(u.type!==r)return;let p=t.nodeAt(f+1);if(p?.type===a&&p?.type===o)return;let m=c+d+u.nodeSize;n.insert(n.mapping.map(m),Fragment.from([e.schema.node(`softbreak`),e.schema.node(`softbreak`)])),s(u,c+d+1,l+1)})}return s(e.doc),t&&t(n),n.docChanged},fixParaEnding=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.paragraph;function s(e,t,n=0,c=0){if(t.type===o){let o=t.content.size;for(let t=e.length-1;t>=0;t--){let s=e[t];if(s.type!==a)break;o-=s.nodeSize;let c=n+o,l=c+s.nodeSize;r.replace(r.mapping.map(c),r.mapping.map(l))}return}let l=0;for(let t=0;t<e.length;t++){let r=e[t];s(r.children,r,n+l+1,c+1),l+=r.nodeSize}}return s(n.children,n),t&&t(r),r.docChanged};function getDefaultsPreProcessFilters(e){return[insertToc,fixShortCodes,removeSuggest,removeEmptyTags,fixIdLinks,fixParaEnding,trimLines,addEnterAfterImage,addEmptyLines,rewriteUrls(e.getUrlRewriter)]}var MarkdownContentMapper=class e{result;rawTextArr;constructor(e,t){this.result=t,this.rawTextArr=[];for(let e of t.rawTextMap)e.nodeIdx>=0&&this.rawTextArr.push({nodeIdx:e.nodeIdx,maxNodeIdx:e.nodeIdx,targetPos:e.targetPos,targetRow:e.targetRow,targetCol:e.targetCol});this.rawTextArr.sort((e,t)=>e.nodeIdx-t.nodeIdx);for(let t=0;t<this.rawTextArr.length;t++){let n=t+1;n<this.rawTextArr.length?this.rawTextArr[t].maxNodeIdx=this.rawTextArr[n].nodeIdx-1:this.rawTextArr[t].maxNodeIdx=e}}getTextContent(){return this.result.content}toRawTextPos(e){for(let t=0;t<this.rawTextArr.length;t++){let n=this.rawTextArr[t];if(e>=n.nodeIdx&&e<=n.maxNodeIdx)return n.targetPos+e-n.nodeIdx}return-1}toRawTextLineCol(e){for(let t=0;t<this.rawTextArr.length;t++){let n=this.rawTextArr[t];if(e>=n.nodeIdx&&e<=n.maxNodeIdx)return[n.targetRow,n.targetCol+e-n.nodeIdx]}return[0,0]}fromLineChar(e,t){for(let n=0;n<this.rawTextArr.length;n++){let r=this.rawTextArr[n],a=r.maxNodeIdx-r.nodeIdx+1;if(r.targetRow===e){if(t>=r.targetCol&&t<r.targetCol+a){let e=t-r.targetCol;return r.nodeIdx+e}let e=this.rawTextArr[n+1];if((!e||e.targetRow>r.targetRow)&&t>=r.targetCol+a)return r.maxNodeIdx}}return-1}static async create(t,n){let r=await extPmToMdConverter(t.doc,n,t.schema,new EventTarget);return new e(t.doc.nodeSize,r)}},MarkdownPluginState=class{editor;extensionMarkdown;capturing=!0;workspace;constructor(e,t){this.editor=e,this.extensionMarkdown=t,this.workspace=e.ci.resolve(`workspace`),this.performSnapshot=debounce(this.performSnapshot.bind(this),800)}async performSnapshot(){let e=this.editor.version,t=this.editor.config.uri;if(!t)return;let n={version:e,state:this.editor.state,materialized:void 0},r=async()=>(n.materialized||=await MarkdownContentMapper.create(n.state,{...this.extensionMarkdown.config,sourceMap:!0}),n.materialized);this.workspace.getFile(t)?this.workspace.modifyFile({uri:t,lang:`markdown`,version:e,getContentMapper:r}):this.workspace.openFile({uri:t,lang:`markdown`,version:e,getContentMapper:r})}};function createMarkdownPlugin(e,t){return new Plugin({state:{init(){return new MarkdownPluginState(t,e)},apply(e,t,n,r){return e.docChanged&&t.capturing&&t.performSnapshot(),t}},view(){return{destroy(){let e=t.config.uri;e&&t.ci.resolve(`workspace`).closeFile(e)}}}})}var ExtensionMarkdown=class extends Extension{config;name=`markdown`;hooks={};urlFromRewriter;urlToRewriter;constructor(e={}){super(e),this.config=e}getConverters(e,t){let n={"text/x-markdown":{fromDoc:n=>pmToMdConverter(n,{assetLoad:this.editor.config.assetLoad,...this.config,urlRewriter:this.urlToRewriter,hooks:this.hooks[`pm2md.pre`],frontmatter:e.ci.resolve(`frontmatter`)},t,e),toDoc:n=>mdToPmConverter(n,{assetLoad:this.editor.config.assetLoad,...this.config,urlRewriter:this.urlFromRewriter,hooks:this.hooks[`md2pm.post`],frontmatter:e.ci.resolve(`frontmatter`)},t)}};return n[`text/markdown`]=n[`text/x-markdown`],n}toMarkdown(e){return extPmToMdConverter(e,{sourceMap:!0,frontmatter:this.editor.ci.resolve(`frontmatter`)},this.editor.schema,this.editor)}async fromMarkdown(e){let t=(await mdToPmConverterText(e,{assetLoad:this.editor.config.assetLoad,...this.config},this.editor.schema)).content;if(t.content.length===1){let e=t.content[0];if(e.type.name===`paragraph`)return new Slice(e.content,0,0)}return new Slice(t,0,0)}created(){this.editor.schema.topNodeType.name===`doc`?this.hooks[`pm2md.pre`]=getDefaultsPreProcessFilters({getUrlRewriter:()=>this.urlToRewriter}):this.hooks[`pm2md.pre`]=[],this.hooks[`md2pm.post`]=[rewriteUrls(()=>this.urlFromRewriter)]}getCommandFactories(){return{getMarkdownHooks:(e,t)=>()=>(t(this.hooks[e]),!0),setMarkdownHooks:(e,t)=>()=>(this.hooks[e]=t,!0),setFromMarkdownUrlRewriter:e=>()=>(this.urlFromRewriter=e,!0),setToMarkdownUrlRewriter:e=>()=>(this.urlToRewriter=e,!0)}}getProseMirrorPlugins(){return[createMarkdownPlugin(this,this.editor)]}};async function init$1(e){let t=await Promise.resolve().then(()=>require("./odt_parser.internal-DGJtzBJe.cjs")),n=await WebAssembly.instantiate(e,{"./odt_parser.internal.js":t});return t.__wbg_set_wasm(n.instance.exports),n.instance.exports.__wbindgen_start(),t.init_debug(),n.instance,t}function inchesToMm(e){return e?e.endsWith(`pt`)?parseFloat(e.substring(0,e.length-2))*.3528:e.endsWith(`in`)?parseFloat(e.substring(0,e.length-2))*25.4:e.endsWith(`em`)?parseFloat(e.substring(0,e.length-2))/.125*25.4:0:0}function getInlineNodesHandlers(){return{$text:(e,t)=>{if(e.current.marks.length>0){let n=t.match(/^([ \t\u00A0]*)(.*)([ \t\u00A0]*)$/);n[1]&&e.current.content.push(e.schema.text(n[1]));let r=e.createText(n[2]);r&&e.current.content.push(r),n[3]&&e.current.content.push(e.schema.text(n[3]));return}let n=e.createText(t);n&&e.current.content.push(n)},s:(e,t)=>{let n=t[`@c`]||1,r=` `.repeat(n),a=e.createText(r);a&&e.current.content.push(a)},tab:(e,t)=>{let n=e.createText(` `);n&&e.current.content.push(n)},rect:(e,t)=>{t[`@rel-width`]===`100%`&&(e.openNode(),e.closeNode(`hr`))},"line-break":(e,t)=>{e.openNode(),e.closeNode(`br`)},"soft-page-break":(e,t)=>{e.openNode(),e.closeNode(`softbreak`)},bookmark:(e,t)=>{e.openNode(),e.closeNode(`node_bookmark`,{id:t[`@name`]})},"bookmark-start":(e,t)=>{},"bookmark-end":(e,t)=>{},"change-start":(e,t)=>{e.openNode(),e.closeNode(`comment`,{id:t[`@change-id`],nesting:1})},"change-end":(e,t)=>{e.openNode(),e.closeNode(`comment`,{id:t[`@change-id`],nesting:-1})}}}function getBasicNodesHandlers(){return{body:(e,t)=>{e.handle(`text`,t.text)},text:(e,t)=>{iterateChildren(t.$value,t=>e.handle(t.tag,t.value))},p:(e,t)=>{let n={},r=e.getElementStyle(t),a=r.styles.find(e=>e.startsWith(`Heading_20_`));a&&(n.level=parseInt(a.substring(11)));let o=`paragraph`;r.styles.find(e=>e.startsWith(`Heading_20_`))&&(o=`heading`),e.openNode();let s=e.styleToMarks(r);s.length>0&&(e.current.marks=[...e.current.marks,...s]),iterateChildren(t.$value,t=>{e.handle(t.tag,t.value)}),e.closeNode(o,n)},"table-of-content":(e,t)=>{let n=[],r=-1;for(let a of t[`index-body`].p){let t=e.getElementStyle(a),o=0;if(`paragraph-properties`in t&&(o=inchesToMm(t[`paragraph-properties`][`@margin-left`])),r<o)n.length>0&&e.openNode(),e.openNode(),n.push(o);else for(let t=n.length-1;t>=0&&n[t]>o;t--)e.closeNode(`bullet_list`,{odtMarginLeft:o}),t>0&&e.closeNode(`list_item`),n.pop();e.openNode(),e.handle(`p`,a),e.closeNode(`list_item`),r=o}for(let t=n.length-1;t>=0;t--){let r=n.pop();t>0?(e.closeNode(`bullet_list`,{odtMarginLeft:r}),e.closeNode(`list_item`)):e.closeNode(`bullet_list`,{odtMarginLeft:r,toc:!0})}},span:(e,t)=>{let n=e.getElementStyle(t),r=e.styleToMarks(n);r.length>0&&(e.stash(),e.current.marks=[...e.current.marks,...r]),iterateChildren(t.$value,t=>{e.handle(t.tag,t.value)}),r.length>0&&e.unstash()},a:(e,t)=>{let n={href:t[`@href`]},r=[e.schema.mark(`link`,n)];r.length>0&&(e.stash(),e.current.marks=[...e.current.marks,...r]),iterateChildren(t.$value,t=>{e.handle(t.tag,t.value)}),r.length>0&&e.unstash()}}}function processListStyle(e,t){let n=e.listTracker,r={},a=resolveListStyle(e.stylesTree,e.automaticStyles,``);for(let t=n.listStack.length-1;t>=0;t--){let r=n.listStack[t];a[`@name`]||(a=resolveListStyle(e.stylesTree,e.automaticStyles,r.styleName))}let o=`bullet_list`;if(a){let e=a[`list-level-style-number`].find(e=>parseInt(String(e[`@level`]))===t);if(e){r.type=e[`@num-format`]||`1`,e[`@start-value`]&&(r.start=String(e[`@start-value`])),o=`ordered_list`;let t=e[`list-level-properties`][`list-level-label-alignment`][`@margin-left`];t&&(r.odtMarginLeft=inchesToMm(t))}let n=a[`list-level-style-bullet`].find(e=>parseInt(String(e[`@level`]))===t);if(n){let e=n[`list-level-properties`][`list-level-label-alignment`][`@margin-left`];e&&(r.odtMarginLeft=inchesToMm(e))}}return{attrs:r,nodeTypeName:o}}function getListNodesHandlers(){return{list:(e,t)=>{let n=e.listTracker;n.pushList(t[`@xml:id`],t[`@style-name`]);let{nodeTypeName:r,attrs:a}=processListStyle(e,n.getCurrentList().level);e.current.meta.list_type=r,t[`@xml:id`]&&(a.id=t[`@xml:id`]),t[`@continue-list`]&&(a.continue=t[`@continue-list`]),t[`@continue-numbering`]&&(a.continue=`_last`),e.openNode(),iterateChildren(t[`list-item`].map(e=>({"list-item":e})),t=>{e.handle(t.tag,t.value)}),e.current.content.length===0?e.dropNode():e.closeNode(r,a),n.listStack.pop()},"list-item":(e,t)=>{e.openNode(),iterateChildren(t.$value,t=>e.handle(t.tag,t.value));let n={};n.markup=`* `,e.closeNode(`list_item`,n)}}}function getTableNodesHandlers(){return{table:(e,t)=>{e.openNode();for(let n of t[`table-row`])e.handle(`table-row`,n);e.closeNode(`table`)},"table-row":(e,t)=>{e.openNode();for(let n of t[`table-cell`])e.handle(`table-cell`,n);e.closeNode(`table_row`)},"table-cell":(e,t)=>{e.openNode(),iterateChildren(t.$value,t=>e.handle(t.tag,t.value)),e.closeNode(`table_cell`)}}}var ListNumbering=class e{id;levels={};forceStart={};constructor(e){this.id=e;for(let e=0;e<20;e++)this.levels[e]=1}clearAbove(e){for(let t=e+1;t<20;t++)this.levels[t]=1}clone(t){let n=new e(t);return n.levels=structuredClone(n.levels),n.forceStart=structuredClone(n.forceStart),n}},ListTracker=class{listStack=[];pushList(e,t=``){let n={id:e,styleName:t,level:this.listStack.length+1};return this.listStack.push(n),n}getCurrentList(){return this.listStack[this.listStack.length-1]}},COURIER_FONTS=[`Courier New`,`Courier`,`Roboto Mono`];function resolveListStyle(e,t,n){let r;return r=e.styles[`list-style`].find(e=>e[`@name`]===n),r||={"@name":n,"list-level-style-number":[],"list-level-style-bullet":[]},r}function resolveStyle(e,t,n){let r;if(r||=e.styles.style.find(e=>e[`@name`]===n),r||=t.style.find(e=>e[`@name`]===n),r||={"@name":n,styles:[]},r.styles=[n],r[`@parent-style-name`]){let n=resolveStyle(e,t,r[`@parent-style-name`]);if(n){let e=[...r.styles,...n.styles];for(let e of Object.keys(r))r[e]===void 0&&delete r[e];r={...n,...r,styles:e}}}return r}function tagEnum(e){if(typeof e==`string`)return{tag:e,value:e};if(typeof e==`object`){let t=Object.entries(e);if(t.length===1)return{tag:t[0][0],value:t[0][1]}}throw Error(`Incorrect enum: `+JSON.stringify(e))}function iterateChildren(e,t){for(let n of e)n!==`Unknown`&&t(tagEnum(n))}var OdtStashContext=class{schema;stylesTree;automaticStyles;ctxStash=[];currentCtx;listTracker=new ListTracker;constructor(e,t,n,r){this.schema=e,this.stylesTree=n,this.automaticStyles=r,this.currentCtx={handlers:t,content:[],marks:[],meta:{}},this.stash()}stash(){this.ctxStash.push(this.currentCtx);let e={},t={...this.currentCtx.handlers},n=this.currentCtx.content,r=this.currentCtx.marks;return this.currentCtx={...structuredClone({...this.currentCtx,content:void 0,marks:void 0,handlers:void 0}),...e,content:n,marks:r,handlers:t},this.ctxStash.length-1}unstash(){let e=this.ctxStash.pop();if(!e)throw Error(`Unstash failed`);this.currentCtx=e}openNode(){this.stash(),this.current.content=[]}dropNode(){this.unstash()}closeNode(e,t={},n=Mark$1.none){let r=this.createNode(e,t,n);return this.unstash(),r&&this.current.content.push(r),r}createNode(e,t={},n=Mark$1.none){let r=this.schema.nodes[e];if(!r)throw Error(`Invalid node type: `+e);let a=r.createAndFill(t,this.current.content,n);if(!a)throw Error(`Error creating node: `+e);return a}createText(e){if(!e)return;let t=uniqMarks(this.current.marks);return this.schema.text(e,t)}styleToMarks(e){let t=[],n=e&&e[`text-properties`]||{};if(COURIER_FONTS.indexOf(n[`@font-name`]||``)>-1){let e=this.schema.mark(`code`);t.push(e)}if(n[`@font-style`]===`italic`){let e=this.schema.mark(`em`);t.push(e)}if(n[`@font-weight`]===`bold`){let e=this.schema.mark(`strong`);t.push(e)}return t}handle(e,t){if(!this.current.handlers[e])throw Error(`No handler for node: `+e);if(typeof this.current.handlers[e]!=`function`)throw Error(`Invalid handler for node: `+e);this.current.handlers[e](this,t)}getElementStyle(e){return typeof e==`object`&&e[`@style-name`]?resolveStyle(this.stylesTree,this.automaticStyles,e[`@style-name`]):{styles:[]}}get current(){return this.currentCtx}},OdtParser=class{schema;config;constructor(e,t={}){this.schema=e,this.config=t}filesMap;parse(e){let t=e.contentTree,n=e.stylesTree,r={...getInlineNodesHandlers(),...getBasicNodesHandlers(),...getListNodesHandlers(),...getTableNodesHandlers(),g:()=>{let e=a.createText(`INSTEAD OF EMBEDDED DIAGRAM ABOVE USE EMBEDDED DIAGRAM FROM DRIVE AND PUT LINK TO IT IN THE DESCRIPTION. See: https://github.com/mieweb/wikiGDrive/issues/353`);e&&a.current.content.push(e)},frame:(t,n)=>{if(n.object&&n.object[`@href`]){let r=n.object[`@href`].replace(/^\.\//,``)+`/content.xml`;if(e[r]){let n=new TextDecoder().decode(e[r]);t.openNode(),t.closeNode(`math`,{lang:`mathml`,content:n});return}}if(n.image&&n.image[`@href`]){let e=n.desc?.$value||``,r=n.image[`@href`];t.openNode(),t.closeNode(`image`,{src:r,alt:e})}},annotation:()=>{},note:(e,t)=>{let n=t[`note-citation`],r=t[`note-body`];if(!(!n||!r)){e.handle(`text`,{$value:[{$text:n.$value}]});for(let t of r.p)iterateChildren(t.$value,t=>e.handle(t.tag,t.value)),e.closeNode(`paragraph`),e.openNode()}}},a=new OdtStashContext(this.schema,r,n,t[`automatic-styles`]);return a.openNode(),a.handle(`body`,t.body),a.closeNode(`doc`)}};function uniqMarks(e){let t=[];for(let n of e)[`strong`,`italic`,`underline`,`subscript`,`superscript`,`code`].includes(n.type.name)&&t.find(e=>e.type===n.type)||t.push(n);return t}var convertCodeParagraphsToCodeBlocks=(e,t)=>{let n=e.doc,r=e.schema,a=e.tr,o=r.marks.code;return n.descendants((e,t)=>{if(e.type.name===`paragraph`){let n=``,s=0,c=[];for(let t=0;t<e.childCount;t++){let r=e.child(t),a=r.marks.some(e=>e.type===o),l=r.textContent.match(/^[ \t\u00A0]+$/);if(r.type.name===`node_bookmark`){c.push(r),s+=r.nodeSize;continue}if(r.type.name===`br`){n+=`
|
|
122
|
+
`);t.attrSet(`indent`,``+n),t.content=s,t.attrSet(`margin_before`,`1`),t.attrSet(`margin_after`,`1`),r.push(t)}break;case`paragraph`:{let t=`p`,o=new Token(`paragraph_open`,`p`,1);o.level=a,o.attrSet(`margin_before`,`1`),r.push(o),a++,e.children?.forEach(e=>l(e,n)),a--;let s=new Token(`paragraph_close`,`p`,-1);s.level=a,s.attrSet(`margin_after`,`1`),r.push(s)}break;case`pipe_table_cell`:{let t=n.tableRowType===`thead`?`th`:`td`,o=n.tableRowType===`thead`?`th`:`td`,c=new Token(t+`_open`,o,1);c.attrSet(`align`,n.cellAlign[n.cellNo]||`left`),c.level=a,r.push(c),a++;{let t=`p`,o=new Token(`paragraph_open`,`p`,1);o.level=a,r.push(o);let c=[...e.children];for(;c.length>0&&c[c.length-1].type===`whitespace`;)c.splice(c.length-1,1);if(c.length>0)c.forEach(e=>l(e,n));else{let t=[e.startPosition?.row,e.endPosition?.row,e.startPosition?.column,e.endPosition?.column],n=new Token(`text`,``,0);n.map=t,n.meta=`noEscText`,n.content=e.text?.replace(/\s+$/,``)??``,s(n,`txt5`)}let u=new Token(`paragraph_close`,`p`,-1);u.level=a,r.push(u)}a--;let u=new Token(t+`_close`,o,-1);u.level=a,r.push(u),n.cellNo++}break;case`pipe_table_header`:case`pipe_table_row`:{let t=`tr`,o=new Token(`tr_open`,`tr`,1);o.level=a,r.push(o),a++,e.children.filter(e=>!!e).filter(e=>e.type===`pipe_table_cell`).forEach(e=>l(e,n)),a--;let s=new Token(`tr_close`,`tr`,-1);s.level=a,r.push(s)}break;case`pipe_table`:{let t=`table`,o=new Token(`table_open`,t,1);o.level=a,o.attrSet(`margin_before`,`1`),r.push(o),a++;let s=e.children.filter(e=>!!e).filter(e=>e.type===`pipe_table_delimiter_row`),c=[];if(s.length>0){let e=s[0].children.filter(e=>!!e).filter(e=>e.type===`pipe_table_delimiter_cell`);for(let t=0;t<e.length;t++)e[t].children.filter(e=>!!e).find(e=>e.type===`pipe_table_align_right`)?c.push(`right`):c.push(`left`)}let u=e.children.filter(e=>!!e).filter(e=>e.type===`pipe_table_header`);if(u.length>0){let e=`thead`,t=new Token(`thead_open`,e,1);t.level=a,r.push(t),a++,u.forEach(e=>l(e,{...n,tableRowType:`thead`,cellNo:0,cellAlign:c})),a--;let o=new Token(`thead_close`,e,-1);o.level=a,r.push(o)}let d=e.children?.filter(e=>e?.type===`pipe_table_row`);d.length>0&&(a++,d.filter(e=>!!e).forEach(e=>l(e,{...n,tableRowType:`tbody`,cellAlign:c})),a--),a--;let f=new Token(`table_close`,t,-1);f.level=a,f.attrSet(`margin_after`,`1`),r.push(f)}break;case`list`:{let t=`bullet_list`,s=`ul`,c=``,u=e.children.filter(e=>!!e).find(e=>e.type===`list_item`);if(u){let e=u.children.filter(e=>!!e).find(e=>e.type.startsWith(`task_list_marker`)),n=u.children.filter(e=>!!e).find(e=>e.type.startsWith(`list_marker_dot`));e?(t=`task_list`,s=`ul`):n&&(t=`ordered_list`,s=`ol`,c=(o(n)||``).trim().replace(`.`,``))}let d=new Token(t+`_open`,s,1);d.level=a,d.markup=s===`ol`?`.`:`*`,d.attrSet(`symbol`,s===`ol`?`1`:`*`),c&&d.attrSet(`start`,c),d.attrSet(`margin_before`,`1`),r.push(d),a++,e.children.filter(e=>!!e).forEach(e=>l(e,n)),a--;let f=new Token(t+`_close`,s,-1);f.level=a,f.attrSet(`margin_after`,`1`),r.push(f)}break;case`list_item`:{let t=e.children.filter(e=>!!e).find(e=>e.type.startsWith(`task_list_marker_`)),s=e.children.filter(e=>!!e).find(e=>e.type.startsWith(`list_marker_`));if(!s)break;let c=t?`task_item`:`list_item`,u=`li`,d=new Token(c+`_open`,`li`,1);d.level=a,d.markup=(o(s)||``).trim(),s.type===`list_marker_dot`&&(d.info=``,d.markup=``),t&&(t.type,d.attrSet(`checked`,t.type===`task_list_marker_checked`?`checked`:``)),r.push(d),a++,l(e.children.filter(e=>!!e).find(e=>e.type===`paragraph`),n);let f=e.children.filter(e=>!!e).filter(e=>e.type===`list`);for(let e of f)l(e,n);a--;let p=new Token(c+`_close`,`li`,-1);p.level=a,r.push(p)}break;case`html_block`:{let t=new Token(`html_block`,``,0);t.level=a,t.content=o(e)??``,t.attrSet(`margin_before`,`1`),t.attrSet(`margin_after`,`1`),r.push(t)}break;case`text`:{let t=new Token(`text`,``,0);t.level=a,t.content=o(e)??``,r.push(t)}break;default:throw console.warn(`Unhandled node type: ${e.type}, children: ${e.children.map(e=>e.type).join(`, `)}`,{...e,children:void 0,_children:void 0,tree:void 0}),Error(`Unhandled node type: ${e.type}`)}}};return l(e),r}async function sitterTokenizer(e){let t=getLangTreeSitter(`markdown`),n=t.files.find(e=>e.indexOf(`_inline`)===-1),r=t.files.find(e=>e.indexOf(`_inline`)>-1),a=await e(t.dir+`/`+n),o=await e(t.dir+`/`+r),s=await createParser(a,{assetLoad:e}),c=await createParser(o,{assetLoad:e});return{parse:e=>{let t=s.parse(e);if(!t)throw Error(`Tree is null`);return treeToTokens(new ExtendedNode(t.rootNode,e),c,e)}}}function listIsTight(e,t){for(;++t<e.length;)if(e[t].type!=`list_item_open`)return e[t].hidden;return!1}async function mdToPmConverter(e,t,n){return mdToPmConverterText(new TextDecoder().decode(e),t,n)}async function mdToPmConverterText(e,t,n){if(!t.assetLoad)throw Error(`No config.assetLoad`);let r=new MarkdownParser(n,await sitterTokenizer(t.assetLoad),{frontmatter:{custom:(e,n)=>{let r=e.stack[0];if(r?.type.name===`doc`&&t.frontmatter){let e=t.frontmatter.parse(n.content)||void 0;r.attrs={...r.attrs,meta:e}}}},blockquote:{block:`blockquote`},paragraph:{block:`paragraph`},task_item:{block:`task_item`},task_list:{block:`task_list`},list_item:{block:`list_item`},bullet_list:{block:`bullet_list`,getAttrs:(e,t,n)=>({tight:listIsTight(t,n)})},ordered_list:{block:`ordered_list`,getAttrs:(e,t,n)=>({start:+e.attrGet(`start`)||1,tight:listIsTight(t,n)})},dl:{block:`dl`},dt:{block:`dt`},dd:{block:`dd`},heading:{block:`heading`,getAttrs:e=>({level:+e.tag.slice(1)})},code_block:{block:`code_block`,getAttrs:e=>({lang:e.attrGet(`lang`)||void 0}),noCloseToken:!0},fence:{block:`code_block`,getAttrs:e=>({lang:e.attrGet(`lang`)||void 0}),noCloseToken:!0},hr:{custom:(e,t,r,a)=>{e.openNode(n.nodes.paragraph,{}),e.addNode(n.nodes.hr,{}),e.closeNode()}},image:{node:`image`,getAttrs:e=>{let t=e.children?e.children[0]:void 0;return{src:e.attrGet(`src`),title:e.attrGet(`title`)||null,alt:t?.content||null}}},entity:{custom:(e,t,n,r)=>{e.addText(decodeEntity(t.content))}},hardbreak:{node:`br`},em:{mark:`em`},underline:{mark:`underline`},strong:{mark:`strong`},strike:{mark:`strike`},link:{mark:`link`,getAttrs:e=>({href:e.attrGet(`href`),title:e.attrGet(`title`)||null})},code:{mark:`code`},html_block:{custom:(e,t,r,a)=>{let o=DOMParser$1.fromSchema(n).parse(elementFromString(t.content));e.importNodes(o.children)}},footnote_ref:{block:`code_block`},table:{block:`table`},tr:{block:`table_row`},td:{block:`table_cell`},th:{block:`table_header`},thead:{ignore:!0}}).parse(e),a=[...t.hooks||[]],o=EditorState.create({doc:r}),s=e=>{o=o.apply(e)};if(a.length>0)for(let e of a)await e(o,e=>s(e));return o.doc}var MarkdownContentMapper=class e{result;rawTextArr;constructor(e,t){this.result=t,this.rawTextArr=[];for(let e of t.rawTextMap)e.nodeIdx>=0&&this.rawTextArr.push({nodeIdx:e.nodeIdx,maxNodeIdx:e.nodeIdx,targetPos:e.targetPos,targetRow:e.targetRow,targetCol:e.targetCol});this.rawTextArr.sort((e,t)=>e.nodeIdx-t.nodeIdx);for(let t=0;t<this.rawTextArr.length;t++){let n=t+1;n<this.rawTextArr.length?this.rawTextArr[t].maxNodeIdx=this.rawTextArr[n].nodeIdx-1:this.rawTextArr[t].maxNodeIdx=e}}getTextContent(){return this.result.content}toRawTextPos(e){for(let t=0;t<this.rawTextArr.length;t++){let n=this.rawTextArr[t];if(e>=n.nodeIdx&&e<=n.maxNodeIdx)return n.targetPos+e-n.nodeIdx}return-1}toRawTextLineCol(e){for(let t=0;t<this.rawTextArr.length;t++){let n=this.rawTextArr[t];if(e>=n.nodeIdx&&e<=n.maxNodeIdx)return[n.targetRow,n.targetCol+e-n.nodeIdx]}return[0,0]}fromLineChar(e,t){for(let n=0;n<this.rawTextArr.length;n++){let r=this.rawTextArr[n],a=r.maxNodeIdx-r.nodeIdx+1;if(r.targetRow===e){if(t>=r.targetCol&&t<r.targetCol+a){let e=t-r.targetCol;return r.nodeIdx+e}let e=this.rawTextArr[n+1];if((!e||e.targetRow>r.targetRow)&&t>=r.targetCol+a)return r.maxNodeIdx}}return-1}static async create(t,n){let r=await extPmToMdConverter(t.doc,n,t.schema,new EventTarget);return new e(t.doc.nodeSize,r)}},addEmptyLines=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;function s(e,t,n=0,c=0){let l=0,u=!1;for(let t=0;t<e.length;t++){let d=e[t];if([`image`,`node_bookmark`].includes(d.type.name)&&t>0){let s=e[t-1];if(s.type!==o)if(s.type===a)r.setNodeMarkup(r.mapping.map(n+l-s.nodeSize),o);else{let e=o.createAndFill();e&&r.insert(r.mapping.map(n+l),e)}}if(d.type.name===`softbreak`){let a=e[t-1];e[t+1],a?.type.name===`softbreak`&&r.delete(r.mapping.map(n+l),r.mapping.map(n+l+d.nodeSize)),a?.textContent?.endsWith(` `)&&r.delete(r.mapping.map(n+l),r.mapping.map(n+l+d.nodeSize)),u||r.delete(r.mapping.map(n+l),r.mapping.map(n+l+d.nodeSize))}else u=!0;s(d.children,d,n+l+1,c+1),l+=d.nodeSize}}return s(n.children,n),t&&t(r),r.docChanged},fixIdLinks=(e,t)=>{let n=e.tr,r=e.schema.marks.link;return e.doc.descendants((e,t)=>{e.marks.forEach(a=>{if(a.type===r&&a.attrs.href.startsWith(`#`)){let o=(e.text||e.textBetween(0,e.content.size)).toLowerCase().replace(/[^\w]+/g,` `).trim().replaceAll(` `,`-`);o&&(n=n.removeMark(t,t+e.nodeSize,r).addMark(t,t+e.nodeSize,r.create({...a.attrs,href:`#`+o})))}})}),t&&t(n),n.docChanged},fixShortCodes=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;if(!a)throw Error(`No hardbreak type in schema`);if(!o)throw Error(`No softbreak type in schema`);function s(e,t=0,n=0){e.forEach((c,l,u)=>{if(c.type.name===`shortcode_inline`){if(u>1){let n=e.child(u-1);n.type===a&&(r=r.setNodeMarkup(t+l-n.nodeSize,o))}u<e.childCount-1&&e.child(u+1).type===a&&(r=r.setNodeMarkup(t+l+c.nodeSize,o))}s(c,t+l+1,n+1)})}return s(n),t&&t(r),r.steps.length>0},removeEmptyTags=(e,t)=>{let n=e.schema.nodes.paragraph,r=e.tr;return e.doc.descendants((e,t)=>{if([`paragraph`].includes(e.type.name)){let n=e.children.every(e=>e.isText&&e.textContent===``);(e.childCount===0||n)&&r.deleteRange(r.mapping.map(t),r.mapping.map(t+e.nodeSize))}else if([`heading`].includes(e.type.name)){let a=e.children.find(e=>e.type.name===`node_bookmark`),o=e.children.every(e=>e.isText&&e.textContent===``||e.type.name===`node_bookmark`);a&&o?r.setNodeMarkup(r.mapping.map(t),n):(e.childCount===0||o)&&r.deleteRange(r.mapping.map(t),r.mapping.map(t+e.nodeSize))}}),t&&t(r),r.docChanged},removeSuggest=(e,t)=>{let n={},r=e.tr,a=e.doc,o=`comment`;a.descendants((e,t)=>{if(e.type.name===`comment`&&e.attrs.id){let r=e.attrs.id;n[r]||(n[r]=[]),e.attrs.nesting===1&&(n[r][0]={node:e,pos:t}),e.attrs.nesting===-1&&(n[r][1]={node:e,pos:t})}});for(let e in n){let t=n[e][0],a=n[e][1];if(t&&a){let e=t.pos,n=a.pos+a.node.nodeSize;r.replace(r.mapping.map(e),r.mapping.map(n))}}return t&&t(r),r.docChanged},rewriteUrls=e=>async(t,n)=>{let r=e?.();if(!r)return!1;let a=t.tr,o=t.schema.marks.link,s=t.schema.nodes.image,c=[],l=[];t.doc.descendants((e,t)=>{e.marks.forEach(n=>{n.type===o&&c.push([n,t,t+e.nodeSize])}),e.type===s&&l.push([e,t])});for(let[e,n,o]of c){let s=e.attrs.href,c={},l=await r(s,{type:`A`,dest:`md`,setMeta:(e,t)=>{c[e]=t}});if(l!==s||c.mdTemplate){let r=c.mdTemplate;a.removeMark(a.mapping.map(n),a.mapping.map(o),e);let u=t.schema.mark(`link`,{...e.attrs,href:l,origUrl:s,mdTemplate:r});a.addMark(a.mapping.map(n),a.mapping.map(o),u)}}for(let[e,t]of l){let n=e.attrs.src,o={},s=await r(n,{type:`IMG`,dest:`md`,setMeta:(e,t)=>{o[e]=t}});if(s!==n||o.mdTemplate){let r=o.mdTemplate;a.setNodeMarkup(a.mapping.map(t),null,{...e.attrs,src:s,origUrl:n,mdTemplate:r})}}return n&&n(a),a.docChanged},trimLines=(e,t)=>{let n=e.doc,r=e.schema,a=e.tr,o=e.schema.nodes.br,s=e.schema.nodes.softbreak,c=e.schema.nodes.paragraph;function l(e,t,n=0,u=0){let d=0;if(t.type.name===`code_block`&&t.textContent.trim())return;function f(t,o){let s=n+o;for(let n=t-1;n>=0;n--){let t=e[n];if(t?.type.name!==`text`)break;let o=t.text||``,c=o.replace(/[ \t\u00A0]+$/,``);if(c!==o){let e=s-t.nodeSize;c.length>0?a.replaceRangeWith(a.mapping.map(e),a.mapping.map(s),r.text(c)):a.replace(a.mapping.map(e),a.mapping.map(s))}else break;s-=t.nodeSize;break}}let p=!1;for(let m=0;m<e.length;m++){let h=e[m];if(h.isText){let e=h.text||``;if(e.match(/^([ \t\u00A0]+)/)&&!p&&c!==t.type){e=e.replace(/^[ \t\u00A0]+/,``);let t=n+d,o=t+h.nodeSize;e?a.replaceRangeWith(a.mapping.map(t),a.mapping.map(o),r.text(e)):a.replace(a.mapping.map(t),a.mapping.map(o))}e&&(p=!0)}o===h.type&&(f(m,d),m+1<e.length&&(e[m+1].type===o||e[m+1].type===s)&&a.setNodeMarkup(a.mapping.map(n+d),s)),l(h.children,h,n+d+1,u+1),d+=h.nodeSize}f(e.length,d)}return l(n.children,n),t&&t(a),a.docChanged},insertToc=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;if(!a)throw Error(`No hardbreak type in schema`);if(!o)throw Error(`No softbreak type in schema`);return n.forEach((e,t,n)=>{if(e.type.name===`bullet_list`&&e.attrs.toc){let t=e.copy(Fragment.from(e.content));r.insert(0,t)}}),t&&t(r),r.steps.length>0},addEnterAfterImage=(e,t)=>{let n=e.tr,r=e.schema.nodes.image,a=e.schema.nodes.br,o=e.schema.nodes.softbreak;function s(t,c=0,l=0){t.forEach((u,d,f)=>{if(u.type!==r)return;let p=t.nodeAt(f+1);if(p?.type===a&&p?.type===o)return;let m=c+d+u.nodeSize;n.insert(n.mapping.map(m),Fragment.from([e.schema.node(`softbreak`),e.schema.node(`softbreak`)])),s(u,c+d+1,l+1)})}return s(e.doc),t&&t(n),n.docChanged},fixParaEnding=(e,t)=>{let n=e.doc,r=e.tr,a=e.schema.nodes.br,o=e.schema.nodes.paragraph;function s(e,t,n=0,c=0){if(t.type===o){let o=t.content.size;for(let t=e.length-1;t>=0;t--){let s=e[t];if(s.type!==a)break;o-=s.nodeSize;let c=n+o,l=c+s.nodeSize;r.replace(r.mapping.map(c),r.mapping.map(l))}return}let l=0;for(let t=0;t<e.length;t++){let r=e[t];s(r.children,r,n+l+1,c+1),l+=r.nodeSize}}return s(n.children,n),t&&t(r),r.docChanged};function getDefaultsPreProcessFilters(e){return[insertToc,fixShortCodes,removeSuggest,removeEmptyTags,fixIdLinks,fixParaEnding,trimLines,addEnterAfterImage,addEmptyLines,rewriteUrls(e.getUrlRewriter)]}var MarkdownPluginState=class{editor;extensionMarkdown;capturing=!0;workspace;hooks={};urlFromRewriter;urlToRewriter;constructor(e,t){this.editor=e,this.extensionMarkdown=t,this.workspace=e.ci.resolve(`workspace`),this.performSnapshot=debounce(this.performSnapshot.bind(this),800)}async performSnapshot(){let e=this.editor.version,t=this.editor.config.uri;if(!t)return;let n={version:e,state:this.editor.state,materialized:void 0},r=async()=>(n.materialized||=await MarkdownContentMapper.create(n.state,{...this.extensionMarkdown.config,sourceMap:!0}),n.materialized);this.workspace.getFile(t)?this.workspace.modifyFile({uri:t,lang:`markdown`,version:e,getContentMapper:r}):this.workspace.openFile({uri:t,lang:`markdown`,version:e,getContentMapper:r})}handleCommands(e,t){if(!e)return!1;if(e.setMarkdownHooks){let{type:t,hooks:n}=e.setMarkdownHooks;return this.hooks[t]=n,!0}if(e.setFromMarkdownUrlRewriter){let{urlRewriter:t}=e.setFromMarkdownUrlRewriter;return this.urlFromRewriter=t,!0}if(e.setToMarkdownUrlRewriter){let{urlRewriter:t}=e.setToMarkdownUrlRewriter;return this.urlToRewriter=t,!0}}},MarkdownPluginKey=new PluginKey(`markdown`);function createMarkdownPlugin(e,t){return new Plugin({key:MarkdownPluginKey,state:{init(n,r){let a=new MarkdownPluginState(t,e);return r.schema.topNodeType.name===`doc`?a.hooks[`pm2md.pre`]=getDefaultsPreProcessFilters({getUrlRewriter:()=>a.urlToRewriter}):a.hooks[`pm2md.pre`]=[],a.hooks[`md2pm.post`]=[rewriteUrls(()=>a.urlFromRewriter)],a},apply(e,t,n,r){let a=e.getMeta(`cloned`);if(a){let e=MarkdownPluginKey.getState(a);if(e)return e}let o=e.getMeta(MarkdownPluginKey);return t.handleCommands(o,e)||e.docChanged&&t.capturing&&t.performSnapshot(),t}},view(){return{destroy(){let e=t.config.uri;e&&t.ci.resolve(`workspace`).closeFile(e)}}}})}var ExtensionMarkdown=class extends Extension{config;name=`markdown`;constructor(e={}){super(e),this.config=e}getConverters(e,t){let n={"text/x-markdown":{fromDoc:n=>{let r=MarkdownPluginKey.getState(e.state);return pmToMdConverter(n,{assetLoad:this.editor.config.assetLoad,...this.config,urlRewriter:r.urlToRewriter,hooks:r.hooks[`pm2md.pre`],frontmatter:e.ci.resolve(`frontmatter`)},t,e)},toDoc:n=>{let r=MarkdownPluginKey.getState(e.state);return mdToPmConverter(n,{assetLoad:this.editor.config.assetLoad,...this.config,urlRewriter:r.urlFromRewriter,hooks:r.hooks[`md2pm.post`],frontmatter:e.ci.resolve(`frontmatter`)},t)}}};return n[`text/markdown`]=n[`text/x-markdown`],n}toMarkdown(e){return extPmToMdConverter(e,{sourceMap:!0,frontmatter:this.editor.ci.resolve(`frontmatter`)},this.editor.schema,this.editor)}async fromMarkdown(e){let t=(await mdToPmConverterText(e,{assetLoad:this.editor.config.assetLoad,...this.config},this.editor.schema)).content;if(t.content.length===1){let e=t.content[0];if(e.type.name===`paragraph`)return new Slice(e.content,0,0)}return new Slice(t,0,0)}getCommandFactories(){return{getMarkdownHooks:(e,t)=>(n,r)=>{let a=MarkdownPluginKey.getState(n);return t(a?a.hooks[e]:[]),!0},setMarkdownHooks:(e,t)=>(n,r)=>(r&&r(n.tr.setMeta(MarkdownPluginKey,{setMarkdownHooks:{type:e,hooks:t}})),!0),setFromMarkdownUrlRewriter:e=>(t,n)=>(n&&n(t.tr.setMeta(MarkdownPluginKey,{setFromMarkdownUrlRewriter:{urlRewriter:e}})),!0),setToMarkdownUrlRewriter:e=>(t,n)=>(n&&n(t.tr.setMeta(MarkdownPluginKey,{setToMarkdownUrlRewriter:{urlRewriter:e}})),!0)}}getProseMirrorPlugins(){return[createMarkdownPlugin(this,this.editor)]}};async function init$1(e){let t=await Promise.resolve().then(()=>require("./odt_parser.internal-DGJtzBJe.cjs")),n=await WebAssembly.instantiate(e,{"./odt_parser.internal.js":t});return t.__wbg_set_wasm(n.instance.exports),n.instance.exports.__wbindgen_start(),t.init_debug(),n.instance,t}function inchesToMm(e){return e?e.endsWith(`pt`)?parseFloat(e.substring(0,e.length-2))*.3528:e.endsWith(`in`)?parseFloat(e.substring(0,e.length-2))*25.4:e.endsWith(`em`)?parseFloat(e.substring(0,e.length-2))/.125*25.4:0:0}function getInlineNodesHandlers(){return{$text:(e,t)=>{if(e.current.marks.length>0){let n=t.match(/^([ \t\u00A0]*)(.*)([ \t\u00A0]*)$/);n[1]&&e.current.content.push(e.schema.text(n[1]));let r=e.createText(n[2]);r&&e.current.content.push(r),n[3]&&e.current.content.push(e.schema.text(n[3]));return}let n=e.createText(t);n&&e.current.content.push(n)},s:(e,t)=>{let n=t[`@c`]||1,r=` `.repeat(n),a=e.createText(r);a&&e.current.content.push(a)},tab:(e,t)=>{let n=e.createText(` `);n&&e.current.content.push(n)},rect:(e,t)=>{t[`@rel-width`]===`100%`&&(e.openNode(),e.closeNode(`hr`))},"line-break":(e,t)=>{e.openNode(),e.closeNode(`br`)},"soft-page-break":(e,t)=>{e.openNode(),e.closeNode(`softbreak`)},bookmark:(e,t)=>{e.openNode(),e.closeNode(`node_bookmark`,{id:t[`@name`]})},"bookmark-start":(e,t)=>{},"bookmark-end":(e,t)=>{},"change-start":(e,t)=>{e.openNode(),e.closeNode(`comment`,{id:t[`@change-id`],nesting:1})},"change-end":(e,t)=>{e.openNode(),e.closeNode(`comment`,{id:t[`@change-id`],nesting:-1})}}}function getBasicNodesHandlers(){return{body:(e,t)=>{e.handle(`text`,t.text)},text:(e,t)=>{iterateChildren(t.$value,t=>e.handle(t.tag,t.value))},p:(e,t)=>{let n={},r=e.getElementStyle(t),a=r.styles.find(e=>e.startsWith(`Heading_20_`));a&&(n.level=parseInt(a.substring(11)));let o=`paragraph`;r.styles.find(e=>e.startsWith(`Heading_20_`))&&(o=`heading`),e.openNode();let s=e.styleToMarks(r);s.length>0&&(e.current.marks=[...e.current.marks,...s]),iterateChildren(t.$value,t=>{e.handle(t.tag,t.value)}),e.closeNode(o,n)},"table-of-content":(e,t)=>{let n=[],r=-1;for(let a of t[`index-body`].p){let t=e.getElementStyle(a),o=0;if(`paragraph-properties`in t&&(o=inchesToMm(t[`paragraph-properties`][`@margin-left`])),r<o)n.length>0&&e.openNode(),e.openNode(),n.push(o);else for(let t=n.length-1;t>=0&&n[t]>o;t--)e.closeNode(`bullet_list`,{odtMarginLeft:o}),t>0&&e.closeNode(`list_item`),n.pop();e.openNode(),e.handle(`p`,a),e.closeNode(`list_item`),r=o}for(let t=n.length-1;t>=0;t--){let r=n.pop();t>0?(e.closeNode(`bullet_list`,{odtMarginLeft:r}),e.closeNode(`list_item`)):e.closeNode(`bullet_list`,{odtMarginLeft:r,toc:!0})}},span:(e,t)=>{let n=e.getElementStyle(t),r=e.styleToMarks(n);r.length>0&&(e.stash(),e.current.marks=[...e.current.marks,...r]),iterateChildren(t.$value,t=>{e.handle(t.tag,t.value)}),r.length>0&&e.unstash()},a:(e,t)=>{let n={href:t[`@href`]},r=[e.schema.mark(`link`,n)];r.length>0&&(e.stash(),e.current.marks=[...e.current.marks,...r]),iterateChildren(t.$value,t=>{e.handle(t.tag,t.value)}),r.length>0&&e.unstash()}}}function processListStyle(e,t){let n=e.listTracker,r={},a=resolveListStyle(e.stylesTree,e.automaticStyles,``);for(let t=n.listStack.length-1;t>=0;t--){let r=n.listStack[t];a[`@name`]||(a=resolveListStyle(e.stylesTree,e.automaticStyles,r.styleName))}let o=`bullet_list`;if(a){let e=a[`list-level-style-number`].find(e=>parseInt(String(e[`@level`]))===t);if(e){r.type=e[`@num-format`]||`1`,e[`@start-value`]&&(r.start=String(e[`@start-value`])),o=`ordered_list`;let t=e[`list-level-properties`][`list-level-label-alignment`][`@margin-left`];t&&(r.odtMarginLeft=inchesToMm(t))}let n=a[`list-level-style-bullet`].find(e=>parseInt(String(e[`@level`]))===t);if(n){let e=n[`list-level-properties`][`list-level-label-alignment`][`@margin-left`];e&&(r.odtMarginLeft=inchesToMm(e))}}return{attrs:r,nodeTypeName:o}}function getListNodesHandlers(){return{list:(e,t)=>{let n=e.listTracker;n.pushList(t[`@xml:id`],t[`@style-name`]);let{nodeTypeName:r,attrs:a}=processListStyle(e,n.getCurrentList().level);e.current.meta.list_type=r,t[`@xml:id`]&&(a.id=t[`@xml:id`]),t[`@continue-list`]&&(a.continue=t[`@continue-list`]),t[`@continue-numbering`]&&(a.continue=`_last`),e.openNode(),iterateChildren(t[`list-item`].map(e=>({"list-item":e})),t=>{e.handle(t.tag,t.value)}),e.current.content.length===0?e.dropNode():e.closeNode(r,a),n.listStack.pop()},"list-item":(e,t)=>{e.openNode(),iterateChildren(t.$value,t=>e.handle(t.tag,t.value));let n={};n.markup=`* `,e.closeNode(`list_item`,n)}}}function getTableNodesHandlers(){return{table:(e,t)=>{e.openNode();for(let n of t[`table-row`])e.handle(`table-row`,n);e.closeNode(`table`)},"table-row":(e,t)=>{e.openNode();for(let n of t[`table-cell`])e.handle(`table-cell`,n);e.closeNode(`table_row`)},"table-cell":(e,t)=>{e.openNode(),iterateChildren(t.$value,t=>e.handle(t.tag,t.value)),e.closeNode(`table_cell`)}}}var ListNumbering=class e{id;levels={};forceStart={};constructor(e){this.id=e;for(let e=0;e<20;e++)this.levels[e]=1}clearAbove(e){for(let t=e+1;t<20;t++)this.levels[t]=1}clone(t){let n=new e(t);return n.levels=structuredClone(n.levels),n.forceStart=structuredClone(n.forceStart),n}},ListTracker=class{listStack=[];pushList(e,t=``){let n={id:e,styleName:t,level:this.listStack.length+1};return this.listStack.push(n),n}getCurrentList(){return this.listStack[this.listStack.length-1]}},COURIER_FONTS=[`Courier New`,`Courier`,`Roboto Mono`];function resolveListStyle(e,t,n){let r;return r=e.styles[`list-style`].find(e=>e[`@name`]===n),r||={"@name":n,"list-level-style-number":[],"list-level-style-bullet":[]},r}function resolveStyle(e,t,n){let r;if(r||=e.styles.style.find(e=>e[`@name`]===n),r||=t.style.find(e=>e[`@name`]===n),r||={"@name":n,styles:[]},r.styles=[n],r[`@parent-style-name`]){let n=resolveStyle(e,t,r[`@parent-style-name`]);if(n){let e=[...r.styles,...n.styles];for(let e of Object.keys(r))r[e]===void 0&&delete r[e];r={...n,...r,styles:e}}}return r}function tagEnum(e){if(typeof e==`string`)return{tag:e,value:e};if(typeof e==`object`){let t=Object.entries(e);if(t.length===1)return{tag:t[0][0],value:t[0][1]}}throw Error(`Incorrect enum: `+JSON.stringify(e))}function iterateChildren(e,t){for(let n of e)n!==`Unknown`&&t(tagEnum(n))}var OdtStashContext=class{schema;stylesTree;automaticStyles;ctxStash=[];currentCtx;listTracker=new ListTracker;constructor(e,t,n,r){this.schema=e,this.stylesTree=n,this.automaticStyles=r,this.currentCtx={handlers:t,content:[],marks:[],meta:{}},this.stash()}stash(){this.ctxStash.push(this.currentCtx);let e={},t={...this.currentCtx.handlers},n=this.currentCtx.content,r=this.currentCtx.marks;return this.currentCtx={...structuredClone({...this.currentCtx,content:void 0,marks:void 0,handlers:void 0}),...e,content:n,marks:r,handlers:t},this.ctxStash.length-1}unstash(){let e=this.ctxStash.pop();if(!e)throw Error(`Unstash failed`);this.currentCtx=e}openNode(){this.stash(),this.current.content=[]}dropNode(){this.unstash()}closeNode(e,t={},n=Mark$1.none){let r=this.createNode(e,t,n);return this.unstash(),r&&this.current.content.push(r),r}createNode(e,t={},n=Mark$1.none){let r=this.schema.nodes[e];if(!r)throw Error(`Invalid node type: `+e);let a=r.createAndFill(t,this.current.content,n);if(!a)throw Error(`Error creating node: `+e);return a}createText(e){if(!e)return;let t=uniqMarks(this.current.marks);return this.schema.text(e,t)}styleToMarks(e){let t=[],n=e&&e[`text-properties`]||{};if(COURIER_FONTS.indexOf(n[`@font-name`]||``)>-1){let e=this.schema.mark(`code`);t.push(e)}if(n[`@font-style`]===`italic`){let e=this.schema.mark(`em`);t.push(e)}if(n[`@font-weight`]===`bold`){let e=this.schema.mark(`strong`);t.push(e)}return t}handle(e,t){if(!this.current.handlers[e])throw Error(`No handler for node: `+e);if(typeof this.current.handlers[e]!=`function`)throw Error(`Invalid handler for node: `+e);this.current.handlers[e](this,t)}getElementStyle(e){return typeof e==`object`&&e[`@style-name`]?resolveStyle(this.stylesTree,this.automaticStyles,e[`@style-name`]):{styles:[]}}get current(){return this.currentCtx}},OdtParser=class{schema;config;constructor(e,t={}){this.schema=e,this.config=t}filesMap;parse(e){let t=e.contentTree,n=e.stylesTree,r={...getInlineNodesHandlers(),...getBasicNodesHandlers(),...getListNodesHandlers(),...getTableNodesHandlers(),g:()=>{let e=a.createText(`INSTEAD OF EMBEDDED DIAGRAM ABOVE USE EMBEDDED DIAGRAM FROM DRIVE AND PUT LINK TO IT IN THE DESCRIPTION. See: https://github.com/mieweb/wikiGDrive/issues/353`);e&&a.current.content.push(e)},frame:(t,n)=>{if(n.object&&n.object[`@href`]){let r=n.object[`@href`].replace(/^\.\//,``)+`/content.xml`;if(e[r]){let n=new TextDecoder().decode(e[r]);t.openNode(),t.closeNode(`math`,{lang:`mathml`,content:n});return}}if(n.image&&n.image[`@href`]){let e=n.desc?.$value||``,r=n.image[`@href`];t.openNode(),t.closeNode(`image`,{src:r,alt:e})}},annotation:()=>{},note:(e,t)=>{let n=t[`note-citation`],r=t[`note-body`];if(!(!n||!r)){e.handle(`text`,{$value:[{$text:n.$value}]});for(let t of r.p)iterateChildren(t.$value,t=>e.handle(t.tag,t.value)),e.closeNode(`paragraph`),e.openNode()}}},a=new OdtStashContext(this.schema,r,n,t[`automatic-styles`]);return a.openNode(),a.handle(`body`,t.body),a.closeNode(`doc`)}};function uniqMarks(e){let t=[];for(let n of e)[`strong`,`italic`,`underline`,`subscript`,`superscript`,`code`].includes(n.type.name)&&t.find(e=>e.type===n.type)||t.push(n);return t}var convertCodeParagraphsToCodeBlocks=(e,t)=>{let n=e.doc,r=e.schema,a=e.tr,o=r.marks.code;return n.descendants((e,t)=>{if(e.type.name===`paragraph`){let n=``,s=0,c=[];for(let t=0;t<e.childCount;t++){let r=e.child(t),a=r.marks.some(e=>e.type===o),l=r.textContent.match(/^[ \t\u00A0]+$/);if(r.type.name===`node_bookmark`){c.push(r),s+=r.nodeSize;continue}if(r.type.name===`br`){n+=`
|
|
123
123
|
`,s+=r.nodeSize;continue}if(a||l){n+=r.text||r.textBetween(0,r.content.size),s+=r.nodeSize;continue}break}if(s>0){let e=a.mapping.map(t),o=a.mapping.map(t+1+s);if(n.trim()){let t=r.text(n),s=r.nodes.code_block.createAndFill(null,[t]);s&&a.replaceRangeWith(e,o,s)}else a.replace(e,o);for(let t of c)a.insert(e,t)}s>0&&(s+2,e.nodeSize)}}),t&&t(a),a.docChanged},ANY_LIST$1=[`ordered_list`,`bullet_list`],fixContinuedLists=(e,t)=>{let n=e.doc,r=e.tr,a=new Map,o=``;function s(e){let t=null;o&&a.has(o)&&(t=a.get(o));let n=e.attrs.continue;return n&&(t=a.get(n)),t||=new ListNumbering(o),a.set(o,t),{listNumbering:t}}let c=!0,l=0;function u(e,t=0,n=0){if(e.type.name===`list_item`){let n=a.get(`_current`),o=e.content.firstChild;o&&n&&(o.type.name===`paragraph`&&o.content.childCount>0?(n.forceStart[l]&&(delete n.forceStart[l],r=r.setNodeMarkup(r.mapping.map(t-1),e.type,{...e.attrs,value:n.levels[l]})),n.levels[l]++):(r=r.setNodeMarkup(r.mapping.map(t-1),e.type,{...e.attrs,type:`none`}),n.forceStart[l]=!0))}if(!ANY_LIST$1.includes(e.type.name))e.forEach((e,r)=>{u(e,t+r+1,n+1)});else{l++,l===1&&(o=e.attrs.id,c=!0);let{listNumbering:d}=s(e);a.set(`_current`,d),c||(d.levels[l]=1),e.attrs.start&&(d.levels[l]=e.attrs.start),e.type.name===`ordered_list`&&1<d.levels[l]&&(r=r.setNodeMarkup(r.mapping.map(t-1),e.type,{...e.attrs,start:d.levels[l],continue:void 0})),e.forEach((e,r)=>{u(e,t+r+1,n+1)}),l===1&&a.set(`_last`,d),l--,c=!1}}return u(n),t&&t(r),r.steps.length>0},convertMathMl=(e,t)=>{let n=e.doc,r=e.schema,a=r.nodes.math,o=r.nodes.code_block;if(!a||!o)return!1;let s=!1,c=e.tr;return n.forEach((e,t,n)=>{if(e.childCount!==1)return;let l=t,u=e.child(0);if(u.type!==a||u.attrs.content.length===0)return;let d=o.create({lang:u.attrs.lang},r.text(u.attrs.content));c.replaceWith(c.mapping.map(l),c.mapping.map(l+e.nodeSize),d),s=!0}),s?(t&&t(c),c.docChanged):!1},CODEBLOCK_START=``,CODEBLOCK_END=``,mergeCodeBlocks=(e,t)=>{let n=e.schema,r=e.tr,a=n.nodes.code_block,o=n.nodes.paragraph;e.doc.descendants((e,t)=>{[CODEBLOCK_START,CODEBLOCK_END].includes(e.textContent.trim())&&(r=r.deleteRange(r.mapping.map(t),r.mapping.map(t+e.nodeSize)))});let s=e.doc,c=0;for(let t=0;t<s.childCount;t++){let t=s.nodeAt(c);if(!t)continue;if(t.type!==a){c+=t.nodeSize;continue}let l=[],u=0;{u+=t.nodeSize;let e=t.text||t.textBetween(0,t.content.size);l.push(e.endsWith(`
|
|
124
124
|
`)?e:e+`
|
|
125
125
|
`)}let d=c+t.nodeSize;for(;;){let n=e.doc.nodeAt(d);if(!n)break;if(d+=n.nodeSize,n.type===o&&n.childCount===0){l.push(`
|