@kerebron/legacy-compat 0.8.4 → 0.8.5

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 CHANGED
@@ -9,8 +9,9 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require
9
9
  `))),0,0):Slice.empty;let n=e.someProp(`clipboardTextParser`,n=>n(t,a,r,e));if(n)c=n;else{let n=a.marks(),{schema:r}=e.state,o=DOMSerializer.fromSchema(r);s=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=s.appendChild(document.createElement(`p`));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),s=readHTML(n),webkit&&restoreReplacedSpaces(s);let u=s&&s.querySelector(`[data-pm-slice]`),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute(`data-pm-slice`)||``);if(d&&d[3])for(let e=+d[3];e>0;e--){let e=s.firstChild;for(;e&&e.nodeType!=1;)e=e.nextSibling;if(!e)break;s=e}if(c||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||DOMParser$1.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:a,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!inlineParents.test(e.parentNode.nodeName)?{ignore:!0}:null}}),d)c=addContext(closeSlice$1(c,+d[1],+d[2]),d[4]);else if(c=Slice.maxOpen(normalizeSiblings$1(c.content,a),!0),c.openStart||c.openEnd){let e=0,t=0;for(let t=c.content.firstChild;e<c.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=c.content.lastChild;t<c.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);c=closeSlice$1(c,e,t)}return e.someProp(`transformPasted`,t=>{c=t(c,e)}),c}var inlineParents=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function normalizeSiblings$1(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$1(t,a,e,o[o.length-1],0))o[o.length-1]=n;else{o.length&&(o[o.length-1]=closeRight$1(o[o.length-1],a.length));let n=withWrappers$1(e,t);o.push(n),r=r.matchType(n.type),a=t}}),o)return Fragment.from(o)}return e}function withWrappers$1(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$1(e,t,n,r,a){if(a<e.length&&a<t.length&&e[a]==t[a]){let o=addToSibling$1(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$1(n,e,a+1))))}}function closeRight$1(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,closeRight$1(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Fragment.empty,!0);return e.copy(n.append(r))}function closeRange$1(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$1(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$1(e,t,n){return t<e.openStart&&(e=new Slice(closeRange$1(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Slice(closeRange$1(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var wrapMap={thead:[`table`],tbody:[`table`],tfoot:[`table`],caption:[`table`],colgroup:[`table`],col:[`table`,`colgroup`],tr:[`table`,`tbody`],td:[`table`,`tbody`,`tr`],th:[`table`,`tbody`,`tr`]},_detachedDoc=null;function detachedDoc(){return _detachedDoc||=document.implementation.createHTMLDocument(`title`)}var _policy=null;function maybeWrapTrusted(e){let t=window.trustedTypes;return t?(_policy||=t.defaultPolicy||t.createPolicy(`ProseMirrorClipboard`,{createHTML:e=>e}),_policy.createHTML(e)):e}function readHTML(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=detachedDoc().createElement(`div`),r=/<([a-z][^>\s]+)/i.exec(e),a;if((a=r&&wrapMap[r[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>`</`+e+`>`).reverse().join(``)),n.innerHTML=maybeWrapTrusted(e),a)for(let e=0;e<a.length;e++)n=n.querySelector(a[e])||n;return n}function restoreReplacedSpaces(e){let t=e.querySelectorAll(chrome?`span:not([class]):not([style])`:`span.Apple-converted-space`);for(let n=0;n<t.length;n++){let r=t[n];r.childNodes.length==1&&r.textContent==`\xA0`&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(` `),r)}}function addContext(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch{return e}let{content:a,openStart:o,openEnd:s}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;a=Fragment.from(t.create(r[e+1],a)),o++,s++}return new Slice(a,o,s)}var handlers={},editHandlers={},passiveHandlers={touchstart:!0,touchmove:!0},InputState=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function initInput(e){for(let t in handlers){let n=handlers[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{eventBelongsToView(e,t)&&!runCustomHandler(e,t)&&(e.editable||!(t.type in editHandlers))&&n(e,t)},passiveHandlers[t]?{passive:!0}:void 0)}safari&&e.dom.addEventListener(`input`,()=>null),ensureListeners(e)}function setSelectionOrigin(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function destroyInput(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function ensureListeners(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>runCustomHandler(e,t))})}function runCustomHandler(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function eventBelongsToView(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function dispatchEvent(e,t){!runCustomHandler(e,t)&&handlers[t.type]&&(e.editable||!(t.type in editHandlers))&&handlers[t.type](e,t)}editHandlers.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!inOrNearComposition(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(android&&chrome&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),ios&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,keyEvent(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||captureKeyDown(e,n)?n.preventDefault():setSelectionOrigin(e,`key`)},editHandlers.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},editHandlers.keypress=(e,t)=>{let n=t;if(inOrNearComposition(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||mac$2&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof TextSelection)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),a=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,a))&&e.dispatch(a()),n.preventDefault()}};function eventCoords(e){return{left:e.clientX,top:e.clientY}}function isNear(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function runHandlerOnContext(e,t,n,r,a){if(r==-1)return!1;let o=e.state.doc.resolve(r);for(let r=o.depth+1;r>0;r--)if(e.someProp(t,t=>r>o.depth?t(e,n,o.nodeAfter,o.before(r),a,!0):t(e,n,o.node(r),o.before(r),a,!1)))return!0;return!1}function updateSelection(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);n==`pointer`&&r.setMeta(`pointer`,!0),e.dispatch(r)}function selectClickedLeaf(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&NodeSelection.isSelectable(r)?(updateSelection(e,new NodeSelection(n),`pointer`),!0):!1}function selectClickedNode(e,t){if(t==-1)return!1;let n=e.state.selection,r,a;n instanceof NodeSelection&&(r=n.node);let o=e.state.doc.resolve(t);for(let e=o.depth+1;e>0;e--){let t=e>o.depth?o.nodeAfter:o.node(e);if(NodeSelection.isSelectable(t)){a=r&&n.$from.depth>0&&e>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?o.before(n.$from.depth):o.before(e);break}}return a==null?!1:(updateSelection(e,NodeSelection.create(e.state.doc,a),`pointer`),!0)}function handleSingleClick(e,t,n,r,a){return runHandlerOnContext(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(a?selectClickedNode(e,n):selectClickedLeaf(e,n))}function handleDoubleClick(e,t,n,r){return runHandlerOnContext(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function handleTripleClick$1(e,t,n,r){return runHandlerOnContext(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||defaultTripleClick(e,n,r)}function defaultTripleClick(e,t,n){if(n.button!=0)return!1;let r=e.state.doc;if(t==-1)return r.inlineContent?(updateSelection(e,TextSelection.create(r,0,r.content.size),`pointer`),!0):!1;let a=r.resolve(t);for(let t=a.depth+1;t>0;t--){let n=t>a.depth?a.nodeAfter:a.node(t),o=a.before(t);if(n.inlineContent)updateSelection(e,TextSelection.create(r,o+1,o+1+n.content.size),`pointer`);else if(NodeSelection.isSelectable(n))updateSelection(e,NodeSelection.create(r,o),`pointer`);else continue;return!0}}function forceDOMFlush(e){return endComposition(e)}var selectNodeModifier=mac$2?`metaKey`:`ctrlKey`;handlers.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=forceDOMFlush(e),a=Date.now(),o=`singleClick`;a-e.input.lastClick.time<500&&isNear(n,e.input.lastClick)&&!n[selectNodeModifier]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?o=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(o=`tripleClick`)),e.input.lastClick={time:a,x:n.clientX,y:n.clientY,type:o,button:n.button};let s=e.posAtCoords(eventCoords(n));s&&(o==`singleClick`?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new MouseDown(e,s,n,!!r)):(o==`doubleClick`?handleDoubleClick:handleTripleClick$1)(e,s.pos,s.inside,n)?n.preventDefault():setSelectionOrigin(e,`pointer`))};var MouseDown=class{constructor(e,t,n,r){this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[selectNodeModifier],this.allowDefault=n.shiftKey;let a,o;if(t.inside>-1)a=e.state.doc.nodeAt(t.inside),o=t.inside;else{let n=e.state.doc.resolve(t.pos);a=n.parent,o=n.depth?n.before():0}let s=r?null:n.target,c=s?e.docView.nearestDesc(s,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:l}=e.state;(n.button==0&&a.type.spec.draggable&&a.type.spec.selectable!==!1||l instanceof NodeSelection&&l.from<=o&&l.to>o)&&(this.mightDrag={node:a,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&gecko&&!this.target.hasAttribute(`contentEditable`))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute(`contentEditable`,`false`)},20),this.view.domObserver.start()),e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this)),setSelectionOrigin(e,`pointer`)}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>selectionToDOM(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(eventCoords(e))),this.updateAllowDefault(e),this.allowDefault||!t?setSelectionOrigin(this.view,`pointer`):handleSingleClick(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||safari&&this.mightDrag&&!this.mightDrag.node.isAtom||chrome&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(updateSelection(this.view,Selection.near(this.view.state.doc.resolve(t.pos)),`pointer`),e.preventDefault()):setSelectionOrigin(this.view,`pointer`)}move(e){this.updateAllowDefault(e),setSelectionOrigin(this.view,`pointer`),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};handlers.touchstart=e=>{e.input.lastTouch=Date.now(),forceDOMFlush(e),setSelectionOrigin(e,`pointer`)},handlers.touchmove=e=>{e.input.lastTouch=Date.now(),setSelectionOrigin(e,`pointer`)},handlers.contextmenu=e=>forceDOMFlush(e);function inOrNearComposition(e,t){return e.composing?!0:safari&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var timeoutComposition=android?5e3:-1;editHandlers.compositionstart=editHandlers.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof TextSelection&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)))e.markCursor=e.state.storedMarks||n.marks(),endComposition(e,!0),e.markCursor=null;else if(endComposition(e,!t.selection.empty),gecko&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&n.nodeType==1&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(t.nodeType==3){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}else n=t,r=-1}}e.input.composing=!0}scheduleComposeEnd(e,timeoutComposition)},editHandlers.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,scheduleComposeEnd(e,20))};function scheduleComposeEnd(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>endComposition(e),t))}function clearComposition(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=timestampFromCustomEvent());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function findCompositionNode(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=textNodeBefore$1(t.focusNode,t.focusOffset),r=textNodeAfter$1(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,a=e.domObserver.lastChangedTextNode;if(n==a||r==a)return a;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}function timestampFromCustomEvent(){let e=document.createEvent(`Event`);return e.initEvent(`event`,!0,!0),e.timeStamp}function endComposition(e,t=!1){if(!(android&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),clearComposition(e),t||e.docView&&e.docView.dirty){let n=selectionFromDOM(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function captureCopy(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),a=document.createRange();a.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(a),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var brokenClipboardAPI=ie$1&&ie_version<15||ios&&webkit_version<604;handlers.copy=editHandlers.cut=(e,t)=>{let n=t,r=e.state.selection,a=n.type==`cut`;if(r.empty)return;let o=brokenClipboardAPI?null:n.clipboardData,{dom:s,text:c}=serializeForClipboard(e,r.content());o?(n.preventDefault(),o.clearData(),o.setData(`text/html`,s.innerHTML),o.setData(`text/plain`,c)):captureCopy(e,s),a&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function sliceSingleNode$1(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function capturePaste(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let a=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?doPaste(e,r.value,null,a,t):doPaste(e,r.textContent,r.innerHTML,a,t)},50)}function doPaste(e,t,n,r,a){let o=parseFromClipboard(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,a,o||Slice.empty)))return!0;if(!o)return!1;let s=sliceSingleNode$1(o),c=s?e.state.tr.replaceSelectionWith(s,r):e.state.tr.replaceSelection(o);return e.dispatch(c.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function getText$1(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}editHandlers.paste=(e,t)=>{let n=t;if(e.composing&&!android)return;let r=brokenClipboardAPI?null:n.clipboardData,a=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&doPaste(e,getText$1(r),r.getData(`text/html`),a,n)?n.preventDefault():capturePaste(e,n)};var Dragging=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},dragCopyModifier=mac$2?`altKey`:`ctrlKey`;function dragMoves(e,t){return e.someProp(`dragCopies`,e=>!e(t))??!t[dragCopyModifier]}handlers.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let a=e.state.selection,o=a.empty?null:e.posAtCoords(eventCoords(n)),s;if(!(o&&o.pos>=a.from&&o.pos<=(a instanceof NodeSelection?a.to-1:a.to))){if(r&&r.mightDrag)s=NodeSelection.create(e.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(s=NodeSelection.create(e.state.doc,t.posBefore))}}let{dom:c,text:l,slice:u}=serializeForClipboard(e,(s||e.state.selection).content());(!n.dataTransfer.files.length||!chrome||chrome_version>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(brokenClipboardAPI?`Text`:`text/html`,c.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,brokenClipboardAPI||n.dataTransfer.setData(`text/plain`,l),e.dragging=new Dragging(u,dragMoves(e,n),s)},handlers.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},editHandlers.dragover=editHandlers.dragenter=(e,t)=>t.preventDefault(),editHandlers.drop=(e,t)=>{let n=t,r=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let a=e.posAtCoords(eventCoords(n));if(!a)return;let o=e.state.doc.resolve(a.pos),s=r&&r.slice;s?e.someProp(`transformPasted`,t=>{s=t(s,e)}):s=parseFromClipboard(e,getText$1(n.dataTransfer),brokenClipboardAPI?null:n.dataTransfer.getData(`text/html`),!1,o);let c=!!(r&&dragMoves(e,n));if(e.someProp(`handleDrop`,t=>t(e,n,s||Slice.empty,c))){n.preventDefault();return}if(!s)return;n.preventDefault();let l=s?dropPoint(e.state.doc,o.pos,s):o.pos;l??=o.pos;let u=e.state.tr;if(c){let{node:e}=r;e?e.replace(u):u.deleteSelection()}let d=u.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,p=u.doc;if(f?u.replaceRangeWith(d,d,s.content.firstChild):u.replaceRange(d,d,s),u.doc.eq(p))return;let m=u.doc.resolve(d);if(f&&NodeSelection.isSelectable(s.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new NodeSelection(m));else{let t=u.mapping.map(l);u.mapping.maps[u.mapping.maps.length-1].forEach((e,n,r,a)=>t=a),u.setSelection(selectionBetween(e,m,u.doc.resolve(t)))}e.focus(),e.dispatch(u.setMeta(`uiEvent`,`drop`))},handlers.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&selectionToDOM(e)},20))},handlers.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},handlers.beforeinput=(e,t)=>{if(chrome&&android&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,keyEvent(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in editHandlers)handlers[e]=editHandlers[e];function compareObjs(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var WidgetType=class e{constructor(e,t){this.toDOM=e,this.spec=t||noSpec,this.side=this.spec.side||0}map(e,t,n,r){let{pos:a,deleted:o}=e.mapResult(t.from+r,this.side<0?-1:1);return o?null:new Decoration(a-n,a-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&compareObjs(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},InlineType=class e{constructor(e,t){this.attrs=e,this.spec=t||noSpec}map(e,t,n,r){let a=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return a>=o?null:new Decoration(a,o,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&compareObjs(this.attrs,t.attrs)&&compareObjs(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},NodeType=class e{constructor(e,t){this.attrs=e,this.spec=t||noSpec}map(e,t,n,r){let a=e.mapResult(t.from+r,1);if(a.deleted)return null;let o=e.mapResult(t.to+r,-1);return o.deleted||o.pos<=a.pos?null:new Decoration(a.pos-n,o.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),a;return r==t.from&&!(a=e.child(n)).isText&&r+a.nodeSize==t.to}eq(t){return this==t||t instanceof e&&compareObjs(this.attrs,t.attrs)&&compareObjs(this.spec,t.spec)}destroy(){}},Decoration=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(t,n,r){return new e(t,t,new WidgetType(n,r))}static inline(t,n,r,a){return new e(t,n,new InlineType(r,a))}static node(t,n,r,a){return new e(t,n,new NodeType(r,a))}get spec(){return this.type.spec}get inline(){return this.type instanceof InlineType}get widget(){return this.type instanceof WidgetType}},none=[],noSpec={},DecorationSet=class e{constructor(e,t){this.local=e.length?e:none,this.children=t.length?t:none}static create(e,t){return t.length?buildTree(t,e,0,noSpec):empty$1}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,a){for(let o=0;o<this.local.length;o++){let s=this.local[o];s.from<=t&&s.to>=e&&(!a||a(s.spec))&&n.push(s.copy(s.from+r,s.to+r))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let s=this.children[o]+1;this.children[o+2].findInner(e-s,t-s,n,r+s,a)}}map(e,t,n){return this==empty$1||e.maps.length==0?this:this.mapInner(e,t,0,0,n||noSpec)}mapInner(t,n,r,a,o){let s;for(let e=0;e<this.local.length;e++){let c=this.local[e].map(t,r,a);c&&c.type.valid(n,c)?(s||=[]).push(c):o.onRemove&&o.onRemove(this.local[e].spec)}return this.children.length?mapChildren(this.children,s||[],t,n,r,a,o):s?new e(s.sort(byPos),none):empty$1}add(t,n){return n.length?this==empty$1?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let a,o=0;t.forEach((e,t)=>{let s=t+r,c;if(c=takeSpansForNode(n,e,s)){for(a||=this.children.slice();o<a.length&&a[o]<t;)o+=3;a[o]==t?a[o+2]=a[o+2].addInner(e,c,s+1):a.splice(o,0,t,t+e.nodeSize,buildTree(c,e,s+1,noSpec)),o+=3}});let s=moveSpans(o?withoutNulls(n):n,-r);for(let e=0;e<s.length;e++)s[e].type.valid(t,s[e])||s.splice(e--,1);return new e(s.length?this.local.concat(s).sort(byPos):this.local,a||this.children)}remove(e){return e.length==0||this==empty$1?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,a=this.local;for(let e=0;e<r.length;e+=3){let a,o=r[e]+n,s=r[e+1]+n;for(let e=0,n;e<t.length;e++)(n=t[e])&&n.from>o&&n.to<s&&(t[e]=null,(a||=[]).push(n));if(!a)continue;r==this.children&&(r=this.children.slice());let c=r[e+2].removeInner(a,o+1);c==empty$1?(r.splice(e,3),e-=3):r[e+2]=c}if(a.length){for(let e=0,r;e<t.length;e++)if(r=t[e])for(let e=0;e<a.length;e++)a[e].eq(r,n)&&(a==this.local&&(a=this.local.slice()),a.splice(e--,1))}return r==this.children&&a==this.local?this:a.length||r.length?new e(a,r):empty$1}forChild(t,n){if(this==empty$1)return this;if(n.isLeaf)return e.empty;let r,a;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(r=this.children[e+2]);break}let o=t+1,s=o+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<s&&t.to>o&&t.type instanceof InlineType){let e=Math.max(o,t.from)-o,n=Math.min(s,t.to)-o;e<n&&(a||=[]).push(t.copy(e,n))}}if(a){let t=new e(a.sort(byPos),none);return r?new DecorationGroup([t,r]):t}return r||empty$1}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return removeOverlap(this.localsInner(e))}localsInner(e){if(this==empty$1)return none;if(e.inlineContent||!this.local.some(InlineType.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof InlineType||t.push(this.local[e]);return t}forEachSet(e){e(this)}};DecorationSet.empty=new DecorationSet([],[]),DecorationSet.removeOverlap=removeOverlap;var empty$1=DecorationSet.empty,DecorationGroup=class e{constructor(e){this.members=e}map(t,n){let r=this.members.map(e=>e.map(t,n,noSpec));return e.from(r)}forChild(t,n){if(n.isLeaf)return DecorationSet.empty;let r=[];for(let a=0;a<this.members.length;a++){let o=this.members[a].forChild(t,n);o!=empty$1&&(o instanceof e?r=r.concat(o.members):r.push(o))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let a=this.members[r].localsInner(e);if(a.length)if(!t)t=a;else{n&&=(t=t.slice(),!1);for(let e=0;e<a.length;e++)t.push(a[e])}}return t?removeOverlap(n?t:t.sort(byPos)):none}static from(t){switch(t.length){case 0:return empty$1;case 1:return t[0];default:return new e(t.every(e=>e instanceof DecorationSet)?t:t.reduce((e,t)=>e.concat(t instanceof DecorationSet?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function mapChildren(e,t,n,r,a,o,s){let c=e.slice();for(let e=0,t=o;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,a,o)=>{let s=o-a-(n-e);for(let a=0;a<c.length;a+=3){let o=c[a+1];if(o<0||e>o+t-r)continue;let l=c[a]+t-r;n>=l?c[a+1]=e<=l?-2:-1:e>=t&&s&&(c[a]+=s,c[a+1]+=s)}r+=s}),t=n.maps[e].map(t,-1)}let l=!1;for(let t=0;t<c.length;t+=3)if(c[t+1]<0){if(c[t+1]==-2){l=!0,c[t+1]=-1;continue}let u=n.map(e[t]+o),d=u-a;if(d<0||d>=r.content.size){l=!0;continue}let f=n.map(e[t+1]+o,-1)-a,{index:p,offset:m}=r.content.findIndex(d),h=r.maybeChild(p);if(h&&m==d&&m+h.nodeSize==f){let r=c[t+2].mapInner(n,h,u+1,e[t]+o+1,s);r==empty$1?(c[t+1]=-2,l=!0):(c[t]=d,c[t+1]=f,c[t+2]=r)}else l=!0}if(l){let l=buildTree(mapAndGatherRemainingDecorations(c,e,t,n,a,o,s),r,0,s);t=l.local;for(let e=0;e<c.length;e+=3)c[e+1]<0&&(c.splice(e,3),e-=3);for(let e=0,t=0;e<l.children.length;e+=3){let n=l.children[e];for(;t<c.length&&c[t]<n;)t+=3;c.splice(t,0,l.children[e],l.children[e+1],l.children[e+2])}}return new DecorationSet(t.sort(byPos),c)}function moveSpans(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let a=e[r];n.push(new Decoration(a.from+t,a.to+t,a.type))}return n}function mapAndGatherRemainingDecorations(e,t,n,r,a,o,s){function c(e,t){for(let o=0;o<e.local.length;o++){let c=e.local[o].map(r,a,t);c?n.push(c):s.onRemove&&s.onRemove(e.local[o].spec)}for(let n=0;n<e.children.length;n+=3)c(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)e[n+1]==-1&&c(e[n+2],t[n]+o+1);return n}function takeSpansForNode(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,a=null;for(let t=0,o;t<e.length;t++)(o=e[t])&&o.from>n&&o.to<r&&((a||=[]).push(o),e[t]=null);return a}function withoutNulls(e){let t=[];for(let n=0;n<e.length;n++)e[n]!=null&&t.push(e[n]);return t}function buildTree(e,t,n,r){let a=[],o=!1;t.forEach((t,s)=>{let c=takeSpansForNode(e,t,s+n);if(c){o=!0;let e=buildTree(c,t,n+s+1,r);e!=empty$1&&a.push(s,s+t.nodeSize,e)}});let s=moveSpans(o?withoutNulls(e):e,-n).sort(byPos);for(let e=0;e<s.length;e++)s[e].type.valid(t,s[e])||(r.onRemove&&r.onRemove(s[e].spec),s.splice(e--,1));return s.length||a.length?new DecorationSet(s,a):empty$1}function byPos(e,t){return e.from-t.from||e.to-t.to}function removeOverlap(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let a=n+1;a<t.length;a++){let o=t[a];if(o.from==r.from){o.to!=r.to&&(t==e&&(t=e.slice()),t[a]=o.copy(o.from,r.to),insertAhead(t,a+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,o.from),insertAhead(t,a,r.copy(o.from,r.to)));break}}}return t}function insertAhead(e,t,n){for(;t<e.length&&byPos(n,e[t])>0;)t++;e.splice(t,0,n)}function viewDecorations(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=empty$1&&t.push(r)}),e.cursorWrapper&&t.push(DecorationSet.create(e.state.doc,[e.cursorWrapper.deco])),DecorationGroup.from(t)}var observeOptions={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},useCharData=ie$1&&ie_version<=11,SelectionState=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},DOMObserver=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new SelectionState,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);ie$1&&ie_version<=11&&e.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),useCharData&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,observeOptions)),this.onCharData&&this.view.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener(`selectionchange`,this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener(`selectionchange`,this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(hasFocusAndSelection(this.view)){if(this.suppressingSelectionUpdates)return selectionToDOM(this.view);if(ie$1&&ie_version<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&isEquivalentPosition(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=parentNode(n))t.add(n);for(let r=e.anchorNode;r;r=parentNode(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&hasFocusAndSelection(e)&&!this.ignoreSelectionChange(n),a=-1,o=-1,s=!1,c=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],c);n&&(a=a<0?n.from:Math.min(n.from,a),o=o<0?n.to:Math.max(n.to,o),n.typeOver&&(s=!0))}if(gecko&&c.length){let t=c.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||blockParent(e,n)!=t)&&r.remove()}}}let l=null;a<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&selectionCollapsed(n)&&(l=selectionFromDOM(e))&&l.eq(Selection.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,selectionToDOM(e),this.currentSelection.set(n),e.scrollToSelection()):(a>-1||r)&&(a>-1&&(e.docView.markDirty(a,o),checkCSS(e)),this.handleDOMChange(a,o,s,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||selectionToDOM(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),r.nodeType==3&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,a=e.nextSibling;if(ie$1&&ie_version<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:o}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(r=n),(!o||Array.prototype.indexOf.call(e.addedNodes,o)<0)&&(a=o)}let o=r&&r.parentNode==e.target?domIndex(r)+1:0,s=n.localPosFromDOM(e.target,o,-1),c=a&&a.parentNode==e.target?domIndex(a):e.target.childNodes.length;return{from:s,to:n.localPosFromDOM(e.target,c,1)}}else if(e.type==`attributes`)return{from:n.posAtStart-n.border,to:n.posAtEnd+n.border};else return this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}}},cssChecked=new WeakMap,cssCheckWarned=!1;function checkCSS(e){if(!cssChecked.has(e)&&(cssChecked.set(e,null),[`normal`,`nowrap`,`pre-line`].indexOf(getComputedStyle(e.dom).whiteSpace)!==-1)){if(e.requiresGeckoHackNode=gecko,cssCheckWarned)return;console.warn(`ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.`),cssCheckWarned=!0}}function rangeToSelectionRange(e,t){let n=t.startContainer,r=t.startOffset,a=t.endContainer,o=t.endOffset,s=e.domAtPos(e.state.selection.anchor);return isEquivalentPosition(s.node,s.offset,a,o)&&([n,r,a,o]=[a,o,n,r]),{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:o}}function safariShadowSelectionRange(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return rangeToSelectionRange(e,n)}let n;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener(`beforeinput`,r,!0),document.execCommand(`indent`),e.dom.removeEventListener(`beforeinput`,r,!0),n?rangeToSelectionRange(e,n):null}function blockParent(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function parseBetween(e,t,n){let{node:r,fromOffset:a,toOffset:o,from:s,to:c}=e.docView.parseRange(t,n),l=e.domSelectionRange(),u,d=l.anchorNode;if(d&&e.dom.contains(d.nodeType==1?d:d.parentNode)&&(u=[{node:d,offset:l.anchorOffset}],selectionCollapsed(l)||u.push({node:l.focusNode,offset:l.focusOffset})),chrome&&e.input.lastKeyCode===8)for(let e=o;e>a;e--){let t=r.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||DOMParser$1.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(r,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace==`pre`?`full`:!0,findPositions:u,ruleFromNode,context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}function ruleFromNode(e){let t=e.pmViewDesc;if(t)return t.parseRule();if(e.nodeName==`BR`&&e.parentNode){if(safari&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}else if(e.parentNode.lastChild==e||safari&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName==`IMG`&&e.getAttribute(`mark-placeholder`))return{ignore:!0};return null}var isInline=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function readDOMChange(e,t,n,r,a){let o=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=selectionFromDOM(e,t);if(n&&!e.state.selection.eq(n)){if(chrome&&android&&e.input.lastKeyCode===13&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp(`handleKeyDown`,t=>t(e,keyEvent(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),o&&r.setMeta(`composition`,o),e.dispatch(r)}return}let s=e.state.doc.resolve(t),c=s.sharedDepth(n);t=s.before(c+1),n=e.state.doc.resolve(n).after(c+1);let l=e.state.selection,u=parseBetween(e,t,n),d=e.state.doc,f=d.slice(u.from,u.to),p,m;e.input.lastKeyCode===8&&Date.now()-100<e.input.lastKeyCodeTime?(p=e.state.selection.to,m=`end`):(p=e.state.selection.from,m=`start`),e.input.lastKeyCode=null;let h=findDiff(f.content,u.doc.content,u.from,p,m);if(h&&e.input.domChangeCount++,(ios&&e.input.lastIOSEnter>Date.now()-225||android)&&a.some(e=>e.nodeType==1&&!isInline.test(e.nodeName))&&(!h||h.endA>=h.endB)&&e.someProp(`handleKeyDown`,t=>t(e,keyEvent(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!h)if(r&&l instanceof TextSelection&&!l.empty&&l.$head.sameParent(l.$anchor)&&!e.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:l.from,endA:l.to,endB:l.to};else{if(u.sel){let t=resolveSelection(e,e.state.doc,u.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);o&&n.setMeta(`composition`,o),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&h.start==h.endB&&e.state.selection instanceof TextSelection&&(h.start>e.state.selection.from&&h.start<=e.state.selection.from+2&&e.state.selection.from>=u.from?h.start=e.state.selection.from:h.endA<e.state.selection.to&&h.endA>=e.state.selection.to-2&&e.state.selection.to<=u.to&&(h.endB+=e.state.selection.to-h.endA,h.endA=e.state.selection.to)),ie$1&&ie_version<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)==` \xA0`&&(h.start--,h.endA--,h.endB--);let g=u.doc.resolveNoCache(h.start-u.from),_=u.doc.resolveNoCache(h.endB-u.from),v=d.resolve(h.start),y=g.sameParent(_)&&g.parent.inlineContent&&v.end()>=h.endA,b;if((ios&&e.input.lastIOSEnter>Date.now()-225&&(!y||a.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!y&&g.pos<u.doc.content.size&&(!g.sameParent(_)||!g.parent.inlineContent)&&!/\S/.test(u.doc.textBetween(g.pos,_.pos,``,``))&&(b=Selection.findFrom(u.doc.resolve(g.pos+1),1,!0))&&b.head>g.pos)&&e.someProp(`handleKeyDown`,t=>t(e,keyEvent(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>h.start&&looksLikeBackspace(d,h.start,h.endA,g,_)&&e.someProp(`handleKeyDown`,t=>t(e,keyEvent(8,`Backspace`)))){android&&chrome&&e.domObserver.suppressSelectionUpdates();return}chrome&&h.endB==h.start&&(e.input.lastChromeDelete=Date.now()),android&&!y&&g.start()!=_.start()&&_.parentOffset==0&&g.depth==_.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,_=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,keyEvent(13,`Enter`))})},20));let x=h.start,S=h.endA,w=t=>{let n=t||e.state.tr.replace(x,S,u.doc.slice(h.start-u.from,h.endB-u.from));if(u.sel){let t=resolveSelection(e,n.doc,u.sel);t&&!(chrome&&e.composing&&t.empty&&(h.start!=h.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==x||t.head==n.mapping.map(S)-1)||ie$1&&t.empty&&t.head==x)&&n.setSelection(t)}return o&&n.setMeta(`composition`,o),n.scrollIntoView()},E;if(y){if(g.pos==_.pos){ie$1&&ie_version<=11&&g.parentOffset==0&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>selectionToDOM(e),20));let t=w(e.state.tr.delete(x,S)),n=d.resolve(h.start).marksAcross(d.resolve(h.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(h.endA==h.endB&&(E=isMarkChange(g.parent.content.cut(g.parentOffset,_.parentOffset),v.parent.content.cut(v.parentOffset,h.endA-v.start())))){let t=w(e.state.tr);E.type==`add`?t.addMark(x,S,E.mark):t.removeMark(x,S,E.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==_.index()-+!_.textOffset){let t=g.parent.textBetween(g.parentOffset,_.parentOffset),n=()=>w(e.state.tr.insertText(t,x,S));e.someProp(`handleTextInput`,r=>r(e,x,S,t,n))||e.dispatch(n())}}else e.dispatch(w())}function resolveSelection(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:selectionBetween(e,t.resolve(n.anchor),t.resolve(n.head))}function isMarkChange(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,a=n,o=r,s,c,l;for(let e=0;e<r.length;e++)a=r[e].removeFromSet(a);for(let e=0;e<n.length;e++)o=n[e].removeFromSet(o);if(a.length==1&&o.length==0)c=a[0],s=`add`,l=e=>e.mark(c.addToSet(e.marks));else if(a.length==0&&o.length==1)c=o[0],s=`remove`,l=e=>e.mark(c.removeFromSet(e.marks));else return null;let u=[];for(let e=0;e<t.childCount;e++)u.push(l(t.child(e)));if(Fragment.from(u).eq(e))return{mark:c,type:s}}function looksLikeBackspace(e,t,n,r,a){if(n-t<=a.pos-r.pos||skipClosingAndOpening(r,!0,!1)<a.pos)return!1;let o=e.resolve(t);if(!r.parent.isTextblock){let e=o.nodeAfter;return e!=null&&n==t+e.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=e.resolve(skipClosingAndOpening(o,!0,!0));return!s.parent.isTextblock||s.pos>n||skipClosingAndOpening(s,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(s.parent.content)}function skipClosingAndOpening(e,t,n){let r=e.depth,a=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,a++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,a++}return a}function findDiff(e,t,n,r,a){let o=e.findDiffStart(t,n);if(o==null)return null;let{a:s,b:c}=e.findDiffEnd(t,n+e.size,n+t.size);if(a==`end`){let e=Math.max(0,o-Math.min(s,c));r-=s+e-o}if(s<o&&e.size<t.size){let e=r<=o&&r>=s?o-r:0;o-=e,o&&o<t.size&&isSurrogatePair(t.textBetween(o-1,o+1))&&(o+=e?1:-1),c=o+(c-s),s=o}else if(c<o){let t=r<=o&&r>=c?o-r:0;o-=t,o&&o<e.size&&isSurrogatePair(e.textBetween(o-1,o+1))&&(o+=t?1:-1),s=o+(s-c),c=o}return{start:o,endA:s,endB:c}}function isSurrogatePair(e){if(e.length!=2)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}var EditorView=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new InputState,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(checkStateComponent$1),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement(`div`),e&&(e.appendChild?e.appendChild(this.dom):typeof e==`function`?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=getEditable$1(this),updateCursorWrapper(this),this.nodeViews=buildNodeViews$1(this),this.docView=docViewDesc(this.state.doc,computeDocDeco(this),viewDecorations(this),this.dom,this),this.domObserver=new DOMObserver(this,(e,t,n,r)=>readDOMChange(this,e,t,n,r)),this.domObserver.start(),initInput(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ensureListeners(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(checkStateComponent$1),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){var n;let r=this.state,a=!1,o=!1;e.storedMarks&&this.composing&&(clearComposition(this),o=!0),this.state=e;let s=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(s||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=buildNodeViews$1(this);changedNodeViews$1(e,this.nodeViews)&&(this.nodeViews=e,a=!0)}(s||t.handleDOMEvents!=this._props.handleDOMEvents)&&ensureListeners(this),this.editable=getEditable$1(this),updateCursorWrapper(this);let c=viewDecorations(this),l=computeDocDeco(this),u=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?`reset`:e.scrollToSelection>r.scrollToSelection?`to selection`:`preserve`,d=a||!this.docView.matchesNode(e.doc,l,c);(d||!e.selection.eq(r.selection))&&(o=!0);let f=u==`preserve`&&o&&this.dom.style.overflowAnchor==null&&storeScrollPos(this);if(o){this.domObserver.stop();let t=d&&(ie$1||chrome)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&selectionContextChanged(r.selection,e.selection);if(d){let n=chrome?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=findCompositionNode(this)),(a||!this.docView.update(e.doc,l,c,this))&&(this.docView.updateOuterDeco(l),this.docView.destroy(),this.docView=docViewDesc(e.doc,l,c,this.dom,this)),n&&!this.trackWrites&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&anchorInRightPlace(this))?selectionToDOM(this,t):(syncNodeSelection(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),this.dragging?.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),u==`reset`?this.dom.scrollTop=0:u==`to selection`?this.scrollToSelection():f&&resetScrollPos(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))&&!this.someProp(`handleScrollToSelection`,e=>e(this)))if(this.state.selection instanceof NodeSelection){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&scrollRectIntoView(this,t.getBoundingClientRect(),e)}else scrollRectIntoView(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let 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)}}updateDraggedNode(e,t){let n=e.node,r=-1;if(this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new Dragging(e.slice,e.move,r<0?void 0:NodeSelection.create(this.state.doc,r))}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(){if(ie$1){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable==`false`)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&focusPreventScroll(this.dom),selectionToDOM(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let e=this.dom.parentNode;e;e=e.parentNode)if(e.nodeType==9||e.nodeType==11&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return posAtCoords(this,e)}coordsAtPos(e,t=1){return coordsAtPos(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return endOfTextblock(this,t||this.state,e)}pasteHTML(e,t){return doPaste(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return doPaste(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return serializeForClipboard(this,e)}destroy(){this.docView&&(destroyInput(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],viewDecorations(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,clearReusedRange())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return dispatchEvent(this,e)}domSelectionRange(){let e=this.domSelection();return e?safari&&this.root.nodeType===11&&deepActiveElement(this.dom.ownerDocument)==this.dom&&safariShadowSelectionRange(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};EditorView.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function computeDocDeco(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[Decoration.node(0,e.state.doc.content.size,t)]}function updateCursorWrapper(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:Decoration.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function getEditable$1(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function selectionContextChanged(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function buildNodeViews$1(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$1(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$1(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`)}var MAX_MATCH=500,InputRule=class{regex;handler;undoable;inCode;constructor(e,t,n={}){this.regex=e,this.regex=e,this.handler=typeof t==`string`?stringHandler(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1}};function stringHandler(e){return function(t,n,r,a,o){t||=n.tr;let s=e;if(r[1]){let e=r[0].lastIndexOf(r[1]);s+=r[0].slice(e+r[1].length),a+=e;let t=a-o;t>0&&(s=r[0].slice(e-t,e)+s,a=o)}return t.insertText(s,a,o)}}var InputRulesPlugin=class extends Plugin{constructor(e){super({key:new PluginKey(`input-rules`),state:{init(){return null},apply(e,t){return e.getMeta(this)||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput(e,t,n,r){return runInputRulesRange(t,n,r)(e.state,t=>{e.dispatch(t)},e)},handleDOMEvents:{compositionend:e=>{setTimeout(()=>{let{$cursor:t}=e.state.selection;if(t)return runInputRulesRange(t.pos,t.pos,``)(e.state,t=>{e.dispatch(t)},e)})}}},rules:e,isInputRules:!0})}},runInputRulesTexts=()=>{let e=(e,t,n)=>{let r=e.plugins.find(e=>e.spec.isInputRules);if(!r)return!1;let a=r.spec.rules;if(n?.composing)return!1;let o=e.doc,s=e.tr;for(let t=0;t<a.length;t++){let n=a[t],c=[];if(o.descendants((e,t)=>{e.isText&&c.push({pos:t,node:e})}),c.length===0)return!1;for(let t=c.length-1;t>=0;t--){let{pos:a,node:l}=c[t];if(!l.isText||!l.text)continue;let u=l.text;if(l.type.spec.code){if(!n.inCode)continue}else if(n.inCode===`only`)continue;let d=n.regex.exec(u);if(!d)continue;let f=d.index,p=a+f,m=a+f+d[0].length,h=n.handler(s,e,d,p,m);h&&(s=h,o=s.doc,n.undoable&&s.setMeta(r,{transform:s,from:p,to:m,text:u}))}}return t&&t(s),s.docChanged};return e.displayName=`runInputRulesTexts`,e},runInputRulesRange=(e,t,n)=>{let r=(r,a,o)=>{let s=r.plugins.find(e=>e.spec.isInputRules);if(!s)return!1;let c=s.spec.rules;if(o?.composing)return!1;let l=r.doc.resolve(e),u=l.parent.textBetween(Math.max(0,l.parentOffset-MAX_MATCH),l.parentOffset,null,``)+n,d=r.tr;for(let a=0;a<c.length;a++){let o=c[a];if(l.parent.type.spec.code){if(!o.inCode)continue}else if(o.inCode===`only`)continue;let f=o.regex.exec(u);if(!f)continue;let p=o.handler(d,r,f,d.mapping.map(e-(f[0].length-n.length)),d.mapping.map(t));if(p){d=p,o.undoable&&d.setMeta(s,{transform:d,from:e,to:t,text:n});break}}return d.docChanged?(a?.(d),!0):!1};return r.displayName=`runInputRulesRange`,r},undoInputRuleCommand=(e,t)=>{let n=e.plugins.find(e=>e.spec.isInputRules);if(!n)return!1;let r=n.getState(e);if(!r)return!1;if(t){let n=e.tr,a=r.transform;for(let e=a.steps.length-1;e>=0;e--)n.step(a.steps[e].invert(a.docs[e]));if(r.text){let t=n.doc.resolve(r.from).marks();n.replaceWith(r.from,r.to,e.schema.text(r.text,t))}else n.delete(r.from,r.to);t(n)}return!0},base={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},shift={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},mac$1=typeof navigator<`u`&&/Mac/.test(navigator.platform),ie=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(let e=0;e<10;e++)base[48+e]=base[96+e]=String(e);for(let e=1;e<=24;e++)base[e+111]=`F`+e;for(let e=65;e<=90;e++)base[e]=String.fromCharCode(e+32),shift[e]=String.fromCharCode(e);for(let e in base)Object.prototype.hasOwnProperty.call(shift,e)||(shift[e]=base[e]);function keyName(e){let t=!(mac$1&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||ie&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?shift:base)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var mac=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator?.platform),windows=typeof navigator<`u`&&/Win/.test(navigator?.platform);function normalizeKeyName(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,a,o,s;for(let e=0;e<t.length-1;e++){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))s=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))a=!0;else if(/^s(hift)?$/i.test(n))o=!0;else if(/^mod$/i.test(n))mac?s=!0:a=!0;else throw Error(`Unrecognized modifier name: `+n)}return r&&(n=`Alt-`+n),a&&(n=`Ctrl-`+n),s&&(n=`Meta-`+n),o&&(n=`Shift-`+n),n}function normalize(e){let t=Object.create(null);for(let n in e)t[normalizeKeyName(n)]=e[n];return t}function modifiers(e,t,n=!0){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n&&t.shiftKey&&(e=`Shift-`+e),e}var KeymapPlugin=class extends Plugin{constructor(e){super({key:new PluginKey(`keymap`),props:{handleKeyDown:keydownHandler(e)}})}};function keydownHandler(e){let t=normalize(e);return function(e,n){let r=keyName(n),a,o=t[modifiers(r,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(r.length==1&&r!=` `){if(n.shiftKey){let a=t[modifiers(r,n,!1)];if(a&&a(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(windows&&n.ctrlKey&&n.altKey)&&(a=base[n.keyCode])&&a!=r){let r=t[modifiers(a,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}function firstCommand$1(...e){let t=function(t,n,r){for(let a=0;a<e.length;a++)if(e[a](t,n,r))return e[a].displayName!==`first`&&console.debug(`firstCommand: `,e[a].displayName||e[a]),!0;return!1};return t.displayName=`first`,t}function getHtmlAttributes(e,t){let n={};if(e.attributes)for(let[r,a]of Object.entries(e.attributes))t.attrs[r]===void 0?a.toDom?n[r]=a.toDom(t):n[r]=a.default:n[r]=t.attrs[r];return n}function setHtmlAttributes(e,t){let n={};if(e.attributes)for(let[r,a]of Object.entries(e.attributes))a.fromDom?n[r]=a.fromDom(t):n[r]=a.default;return n}function addAttributesToSchema(e,t){if(t.attributes){e.attrs||={};for(let[n,r]of Object.entries(t.attributes))e.attrs[n]=r,r.toDom||=e=>e.attrs[n]}}var TrackSelecionPlugin=class extends Plugin{constructor(e){super({key:new PluginKey(`track-selection`),view(t){return{update(t,n){let r=t.state,a=n.selection,o=r.selection;if(!a.eq(o)){let t=new CustomEvent(`selection`,{detail:{selection:o}});e.dispatchEvent(t)}}}}})}},yaml_exports=require_rolldown_runtime.n({fromJSON:()=>fromJSON,parse:()=>parse$1,setPathValue:()=>setPathValue,stringify:()=>stringify,toJSON:()=>toJSON}),findUnquotedColon=e=>{let t=!1,n=!1;for(let r=0;r<e.length;r++){let a=e[r];if(a===`"`&&!t)n=!n;else if(a===`'`&&!n)t=!t;else if(a===`:`&&!t&&!n)return r}return-1};function parse$1(e){let t=e.replace(/\r\n/g,`
10
10
  `).split(`
11
11
  `).filter(e=>e.trim().length>0&&!e.trim().startsWith(`#`)),n=e=>(e=e.trim(),e===``||e===`null`?null:e===`true`?!0:e===`false`?!1:isNaN(Number(e))?e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,-1):e:Number(e)),r=0,a=e=>{let o=null,s=null;for(;r<t.length;){let c=t[r],l=c.match(/^ */)?.[0].length??0;if(l<e)break;let u=c.trim();if(u.startsWith(`-`)){if(o===null&&(o=[],s=!0),s===!1)throw Error(`Mixed array/object structure`);s=!0;let e=u.slice(1).trim();if(e===``)r++,o.push(a(l+2));else{let s=findUnquotedColon(e);if(s===-1)o.push(n(e)),r++;else{let c=new Map,u=e.slice(0,s).trim(),d=e.slice(s+1).trim();for(r++,c.set(u,d===``?a(l+2):n(d));r<t.length;){let e=t[r],o=e.match(/^ */)?.[0].length??0;if(o<=l)break;let s=e.trim(),u=findUnquotedColon(s);if(u===-1)break;let d=s.slice(0,u).trim(),f=s.slice(u+1).trim();r++,c.set(d,f===``?a(o+2):n(f))}o.push(c)}}continue}let d=u.indexOf(`:`);if(d===-1)throw Error(`Invalid line: ${c}`);if(o===null&&(o=new Map,s=!1),s===!0)throw Error(`Mixed array/object structure`);let f=u.slice(0,d).trim(),p=u.slice(d+1).trim();r++,o.set(f,p===``?a(l+2):n(p))}return o??new Map};return a(0)}function stringify(e,t=2){e=fromJSON(e);let n=e=>` `.repeat(e*t),r=e=>typeof e==`object`&&!!e&&!Array.isArray(e),a=[];function o(e,t,c){let l=c===void 0?n(t):n(t)+c+`: `;if(e===null){a.push(l+`null`);return}if(typeof e==`number`||typeof e==`boolean`){a.push(l+String(e));return}if(typeof e==`string`){let t=/[:\s]/.test(e)?`"${e}"`:e;a.push(l+t);return}if(Array.isArray(e)){c!==void 0&&(a.push(n(t)+c+`:`),t++);for(let c of e)Array.isArray(c)||r(c)?(a.push(n(t)+`-`),o(c,t+1)):a.push(n(t)+`- `+s(c));return}if(r(e)){c!==void 0&&(a.push(n(t)+c+`:`),t++);for(let[n,r]of e)o(r,t,n);return}a.push(l+String(e))}function s(e){return e===null?`null`:typeof e==`string`?/[:\s]/.test(e)?`"${e}"`:e:String(e)}return o(e,0),a.join(`
12
- `)}function fromJSON(e){if(e===null)return null;if(Array.isArray(e))return e.map(fromJSON);if(typeof e==`object`){if(e instanceof Map)return e;let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,fromJSON(r));return t}if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;throw Error(`Unsupported JSON value: ${typeof e}`)}function toJSON(e){if(e instanceof Map){let t={};for(let[n,r]of e)t[n]=toJSON(r);return t}return Array.isArray(e)?e.map(toJSON):e}function setPathValue(e,t,n){let r=t.match(/[^.\[\]]+|\[\d+\]/g)?.map(e=>e.startsWith(`[`)?Number(e.slice(1,-1)):e)??[];if(r.length===0)throw Error(`empty path`);if(!(e instanceof Map)&&!Array.isArray(e))throw Error(`root must be Map or array`);let a=e;for(let e=0;e<r.length-1;e++){let n=r[e],o=typeof n==`number`?Array.isArray(a)?a[n]:void 0:a instanceof Map?a.get(n):void 0;if(!(o instanceof Map)&&!Array.isArray(o)){if(o!=null)throw console.log(`next`,o),Error(`"${n}" #${e} of "${t}" not container`);o=typeof r[e+1]==`number`?[]:new Map,typeof n==`number`?a[n]=o:a.set(n,o)}a=o}let o=r[r.length-1];if(typeof o==`number`){if(!Array.isArray(a))throw Error(`target not array`);for(;a.length<=o;)a.push(null);a[o]=n}else{if(!(a instanceof Map))throw Error(`target not map`);a.set(o,n)}}function splitExtensions(e){return{baseExtensions:Array.from(e).filter(e=>e.type===`extension`),nodeExtensions:Array.from(e).filter(e=>e.type===`node`),markExtensions:Array.from(e).filter(e=>e.type===`mark`)}}var ExtensionManager=class{editorKits;debug;extensions=new Set;plugins=[];nodeViews={};converters={};constructor(e,t=!1){this.editorKits=e,this.debug=t;let n=e.reduce((e,t)=>e.concat(t.getExtensions()),[]);this.setupExtensions(new Set(n))}initPlugins(e,t){let n=[],r=new Map,a=(t,n)=>{for(let n in t){if(!t[n])continue;let a=e.commandFactories[t[n]];if(!a){console.warn(`No command constructor: ${t[n]}`);continue}let o=a(),s=r.get(n);s?r.set(n,firstCommand$1(o,s)):r.set(n,o)}},o={};for(let r of this.extensions){if(r.setEditor(e),r.type===`node`){let s=t.nodes[r.name];n.push(...r.getInputRules(s)),this.plugins.push(...r.getProseMirrorPlugins()),e.mergeCommandFactories(r.getCommandFactories(e,s),r.name),a(r.getKeyboardShortcuts(e),r.name),o={...o,...r.getConverters(e,t)};let c=r.getNodeView(e);c&&(this.nodeViews[r.name]=c)}if(r.type===`mark`){let o=t.marks[r.name];n.push(...r.getInputRules(o)),e.mergeCommandFactories(r.getCommandFactories(e,o),r.name),a(r.getKeyboardShortcuts(e),r.name)}r.type===`extension`&&(this.plugins.push(...r.getProseMirrorPlugins()),e.mergeCommandFactories(r.getCommandFactories(e),r.name),a(r.getKeyboardShortcuts(e),r.name),o={...o,...r.getConverters(e,t)})}if(this.debug)for(let e in r){let t=r.get(e);t&&r.set(e,firstCommand$1((t,n,r)=>(console.debug(`Key: ${e}`),!0),t))}this.converters=o,this.plugins.push(new InputRulesPlugin(n)),this.plugins.push(new KeymapPlugin(Object.fromEntries(r))),this.plugins.push(new TrackSelecionPlugin(e))}setupExtensions(e){let t=new Map,n=e=>{for(let r of e){if(`name`in r){let e=t.get(r.name);if(e&&`type`in e&&r.type!==e.type)throw Error(`Duplicate mark/node: ${r.name}`);t.set(r.name,r)}if(`requires`in r){let e=Array.from(r.requires).filter(e=>typeof e!=`string`);n(new Set(e))}}};n(e);let r=new Set,a=e=>{this.debug&&console.info(`Initialize ${e.type} ${e.name}`),this.extensions.add(e)};function o(e){if(!(`name`in e&&r.has(e.name))){if(`requires`in e){let n=(e.requires||[]).map(e=>typeof e==`string`?e:`name`in e?e.name:``);for(let a of n)if(!r.has(a)){let n=t.get(a);if(!n)throw Error(`Required extension for (${`name`in e?e.name:e}) not found: ${a}`);o(n)}}`name`in e&&(a(e),r.add(e.name),t.delete(e.name))}}for(let e of t.values())o(e);if(t.size>0)throw Error(`Not all extensions initialized: `+Array.from(t.keys()).join(`, `))}getSchemaByResolvedExtensions(){let{nodeExtensions:e,markExtensions:t,baseExtensions:n}=splitExtensions(this.extensions),r={},a=``;for(let t of e){if(r[t.name]=t.getNodeSpec(),r[t.name].EMPTY_DOC){if(a)throw Error(`Multiple topNodes: ${t.name}, ${a}`);a=t.name}addAttributesToSchema(r[t.name],t)}let o={};for(let e of t)o[e.name]=e.getMarkSpec(),addAttributesToSchema(o[e.name],e);let s={topNode:a||`doc`,nodes:r,marks:o};for(let e of n)`setupSpec`in n&&e.setupSpec(s);return new Schema(s)}created(e,t){let{nodeExtensions:n,markExtensions:r,baseExtensions:a}=splitExtensions(this.extensions);for(let e of a)if(Array.isArray(e.conflicts)){for(let t of e.conflicts)if(a.find(e=>e.name===t))throw Error(`Extension conflict: ${e.name} vs ${t}`)}for(let t of a)e.ci.register(t.name,t);e.ci.register(`yaml`,yaml_exports),this.initPlugins(e,t);for(let e of this.extensions)e.created()}};function createChainableState(e,t){let{selection:n}=e,{doc:r}=e,{storedMarks:a}=e;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return n},get doc(){return r},get tr(){return n=e.selection,r=e.doc,a=e.storedMarks,e}}}var wrapInList=(e,t=null)=>function(n,r,a){let{$from:o,$to:s}=n.selection,c=o.blockRange(s);if(!c)return!1;let l=r?n.tr:null;return wrapRangeInList(l,c,e,t).apply(this,[n,r])?(r&&r(l.scrollIntoView()),!0):!1},wrapRangeInList=(e,t,n,r=null)=>()=>{let a=!1,o=t,s=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=s.resolve(t.start-2);o=new NodeRange(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new NodeRange(t.$from,s.resolve(t.$to.end(t.depth)),t.depth)),a=!0}let c=findWrapping(o,n,r,t);return c?(e&&doWrapInList(e,t,c,a,n),!0):!1};function doWrapInList(e,t,n,r,a){let o=Fragment.empty;for(let e=n.length-1;e>=0;e--)o=Fragment.from(n[e].type.create(n[e].attrs,o));e.step(new ReplaceAroundStep(t.start-(r?2:0),t.end,t.start,t.end,new Slice(o,0,0),n.length,!0));let s=0;for(let e=0;e<n.length;e++)n[e].type==a&&(s=e+1);let c=n.length-s,l=t.start+n.length-(r?2:0),u=t.parent;for(let n=t.startIndex,r=t.endIndex,a=!0;n<r;n++,a=!1)!a&&canSplit(e.doc,l,c)&&(e.split(l,c),l+=2*c),l+=u.child(n).nodeSize;return e}var deleteSelection=()=>(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function atBlockStart(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var joinBackward=()=>(e,t,n)=>{let r=atBlockStart(e,n);if(!r)return!1;let a=findCutBefore(r);if(!a){let n=r.blockRange(),a=n&&liftTarget(n);return a==null?!1:(t&&t(e.tr.lift(n,a).scrollIntoView()),!0)}let o=a.nodeBefore;if(deleteBarrier(e,a,t,-1))return!0;if(r.parent.content.size==0&&(textblockAt(o,`end`)||NodeSelection.isSelectable(o)))for(let n=r.depth;;n--){let s=replaceStep(e.doc,r.before(n),r.after(n),Slice.empty);if(s&&s.slice.size<s.to-s.from){if(t){let n=e.tr.step(s);n.setSelection(textblockAt(o,`end`)?Selection.findFrom(n.doc.resolve(n.mapping.map(a.pos,-1)),-1):NodeSelection.create(n.doc,a.pos-o.nodeSize)),t(n.scrollIntoView())}return!0}if(n==1||r.node(n-1).childCount>1)break}return o.isAtom&&a.depth==r.depth-1?(t&&t(e.tr.delete(a.pos-o.nodeSize,a.pos).scrollIntoView()),!0):!1},joinTextblockBackward=()=>(e,t,n)=>{let r=atBlockStart(e,n);if(!r)return!1;let a=findCutBefore(r);return a?joinTextblocksAround(e,a,t):!1},joinTextblockForward=()=>(e,t,n)=>{let r=atBlockEnd(e,n);if(!r)return!1;let a=findCutAfter(r);return a?joinTextblocksAround(e,a,t):!1};function joinTextblocksAround(e,t,n){let r=t.nodeBefore,a=t.pos-1;for(;!r.isTextblock;a--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let o=t.nodeAfter,s=t.pos+1;for(;!o.isTextblock;s++){if(o.type.spec.isolating)return!1;let e=o.firstChild;if(!e)return!1;o=e}let c=replaceStep(e.doc,a,s,Slice.empty);if(!c||c.from!=a||c instanceof ReplaceStep&&c.slice.size>=s-a)return!1;if(n){let t=e.tr.step(c);t.setSelection(TextSelection.create(t.doc,a)),n(t.scrollIntoView())}return!0}function textblockAt(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var selectNodeBackward=()=>(e,t,n)=>{let{$head:r,empty:a}=e.selection,o=r;if(!a)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;o=findCutBefore(r)}let s=o&&o.nodeBefore;return!s||!NodeSelection.isSelectable(s)?!1:(t&&t(e.tr.setSelection(NodeSelection.create(e.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function findCutBefore(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function atBlockEnd(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset<n.parent.content.size)?null:n}var joinForward=()=>(e,t,n)=>{let r=atBlockEnd(e,n);if(!r)return!1;let a=findCutAfter(r);if(!a)return!1;let o=a.nodeAfter;if(deleteBarrier(e,a,t,1))return!0;if(r.parent.content.size==0&&(textblockAt(o,`start`)||NodeSelection.isSelectable(o))){let n=replaceStep(e.doc,r.before(),r.after(),Slice.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(textblockAt(o,`start`)?Selection.findFrom(r.doc.resolve(r.mapping.map(a.pos)),1):NodeSelection.create(r.doc,r.mapping.map(a.pos))),t(r.scrollIntoView())}return!0}}return o.isAtom&&a.depth==r.depth-1?(t&&t(e.tr.delete(a.pos,a.pos+o.nodeSize).scrollIntoView()),!0):!1},selectNodeForward=()=>(e,t,n)=>{let{$head:r,empty:a}=e.selection,o=r;if(!a)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset<r.parent.content.size)return!1;o=findCutAfter(r)}let s=o&&o.nodeAfter;return!s||!NodeSelection.isSelectable(s)?!1:(t&&t(e.tr.setSelection(NodeSelection.create(e.doc,o.pos)).scrollIntoView()),!0)};function findCutAfter(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}var joinUp=()=>(e,t)=>{let n=e.selection,r=n instanceof NodeSelection,a;if(r){if(n.node.isTextblock||!canJoin(e.doc,n.from))return!1;a=n.from}else if(a=joinPoint(e.doc,n.from,-1),a==null)return!1;if(t){let n=e.tr.join(a);r&&n.setSelection(NodeSelection.create(n.doc,a-e.doc.resolve(a).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},joinDown=()=>(e,t)=>{let n=e.selection,r;if(n instanceof NodeSelection){if(n.node.isTextblock||!canJoin(e.doc,n.to))return!1;r=n.to}else if(r=joinPoint(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},lift=()=>(e,t)=>{let{$from:n,$to:r}=e.selection,a=n.blockRange(r),o=a&&liftTarget(a);return o==null?!1:(t&&t(e.tr.lift(a,o).scrollIntoView()),!0)},newlineInCode=()=>{let e=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(`
13
- `).scrollIntoView()),!0)};return e.displayName=`newlineInCode()`,e};function defaultBlockAt(e){console.log(`defaultBlockAt`,e);for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var exitCode=()=>(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let a=n.node(-1),o=n.indexAfter(-1),s=defaultBlockAt(a.contentMatchAt(o));if(!s||!a.canReplaceWith(o,o,s))return!1;if(t){let r=n.after(),a=e.tr.replaceWith(r,r,s.createAndFill());a.setSelection(Selection.near(a.doc.resolve(r),1)),t(a.scrollIntoView())}return!0},createParagraphNear=()=>{let e=(e,t)=>{let n=e.selection,{$from:r,$to:a}=n;if(n instanceof AllSelection||r.parent.inlineContent||a.parent.inlineContent)return!1;let o=defaultBlockAt(a.parent.contentMatchAt(a.indexAfter()));if(!o||!o.isTextblock)return!1;if(t){let n=(!r.parentOffset&&a.index()<a.parent.childCount?r:a).pos,s=e.tr.insert(n,o.createAndFill());s.setSelection(TextSelection.create(s.doc,n+1)),t(s.scrollIntoView())}return!0};return e.displayName=`createParagraphNear()`,e},liftEmptyBlock=()=>{let e=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(canSplit(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),a=r&&liftTarget(r);return a==null?!1:(t&&t(e.tr.lift(r,a).scrollIntoView()),!0)};return e.displayName=`liftEmptyBlock()`,e},splitBlockAs=e=>{let t=(t,n)=>{let{$from:r,$to:a}=t.selection;if(t.selection instanceof NodeSelection&&t.selection.node.isBlock)return!r.parentOffset||!canSplit(t.doc,r.pos)?!1:(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,c,l=!1,u=!1;for(let t=r.depth;;t--)if(r.node(t).isBlock){l=r.end(t)==r.pos+(r.depth-t),u=r.start(t)==r.pos-(r.depth-t),c=defaultBlockAt(r.node(t-1).contentMatchAt(r.indexAfter(t-1)));let n=e&&e(a.parent,l,r);o.unshift(n||(l&&c?{type:c}:null)),s=t;break}else{if(t==1)return!1;o.unshift(null)}let d=t.tr;(t.selection instanceof TextSelection||t.selection instanceof AllSelection)&&d.deleteSelection();let f=d.mapping.map(r.pos),p=canSplit(d.doc,f,o.length,o);if(p||=(o[0]=c?{type:c}:null,canSplit(d.doc,f,o.length,o)),d.split(f,o.length,o),!l&&u&&r.node(s).type!=c){let e=d.mapping.map(r.before(s)),t=d.doc.resolve(e);c&&r.node(s-1).canReplaceWith(t.index(),t.index()+1,c)&&d.setNodeMarkup(d.mapping.map(r.before(s)),c)}return n&&n(d.scrollIntoView()),!0};return t.displayName=`splitBlockAs()`,t},splitBlock=()=>splitBlockAs(),splitBlockKeepMarks=()=>(e,t)=>splitBlockAs().apply(void 0,[e,t&&(n=>{let r=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();r&&n.ensureMarks(r),t(n)})]),selectParentNode=()=>(e,t)=>{let{$from:n,to:r}=e.selection,a,o=n.sharedDepth(r);return o==0?!1:(a=n.before(o),t&&t(e.tr.setSelection(NodeSelection.create(e.doc,a))),!0)},selectAll$1=()=>(e,t)=>(t&&t(e.tr.setSelection(new AllSelection(e.doc))),!0);function joinMaybeClear(e,t,n){let r=t.nodeBefore,a=t.nodeAfter,o=t.index();return!r||!a||!r.type.compatibleContent(a.type)?!1:!r.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(o,o+1)||!(a.isTextblock||canJoin(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function deleteBarrier(e,t,n,r){let a=t.nodeBefore,o=t.nodeAfter,s,c,l=a.type.spec.isolating||o.type.spec.isolating;if(!l&&joinMaybeClear(e,t,n))return!0;let u=!l&&t.parent.canReplace(t.index(),t.index()+1);if(u&&(s=(c=a.contentMatchAt(a.childCount)).findWrapping(o.type))&&c.matchType(s[0]||o.type).validEnd){if(n){let r=t.pos+o.nodeSize,c=Fragment.empty;for(let e=s.length-1;e>=0;e--)c=Fragment.from(s[e].create(null,c));c=Fragment.from(a.copy(c));let l=e.tr.step(new ReplaceAroundStep(t.pos-1,r,t.pos,r,new Slice(c,1,0),s.length,!0)),u=l.doc.resolve(r+2*s.length);u.nodeAfter&&u.nodeAfter.type==a.type&&canJoin(l.doc,u.pos)&&l.join(u.pos),n(l.scrollIntoView())}return!0}let d=o.type.spec.isolating||r>0&&l?null:Selection.findFrom(t,1),f=d&&d.$from.blockRange(d.$to),p=f&&liftTarget(f);if(p!=null&&p>=t.depth)return n&&n(e.tr.lift(f,p).scrollIntoView()),!0;if(u&&textblockAt(o,`start`,!0)&&textblockAt(a,`end`)){let r=a,s=[];for(;s.push(r),!r.isTextblock;)r=r.lastChild;let c=o,l=1;for(;!c.isTextblock;c=c.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,c.content)){if(n){let r=Fragment.empty;for(let e=s.length-1;e>=0;e--)r=Fragment.from(s[e].copy(r));n(e.tr.step(new ReplaceAroundStep(t.pos-s.length,t.pos+o.nodeSize,t.pos+l,t.pos+o.nodeSize-l,new Slice(r,s.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function selectTextblockSide(e){return function(t,n){let r=t.selection,a=e<0?r.$from:r.$to,o=a.depth;for(;a.node(o).isInline;){if(!o)return!1;o--}return a.node(o).isTextblock?(n&&n(t.tr.setSelection(TextSelection.create(t.doc,e<0?a.start(o):a.end(o)))),!0):!1}}var wrapIn=(e,t=null)=>function(n,r){let{$from:a,$to:o}=n.selection,s=a.blockRange(o),c=s&&findWrapping(s,e,t);return c?(r&&r(n.tr.wrap(s,c).scrollIntoView()),!0):!1},setBlockType=(e,t=null)=>function(n,r){let a=!1;for(let r=0;r<n.selection.ranges.length&&!a;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];n.doc.nodesBetween(o,s,(r,o)=>{if(a)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)a=!0;else{let t=n.doc.resolve(o),r=t.index();a=t.parent.canReplaceWith(r,r+1,e)}})}if(!a)return!1;if(r){let a=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];a.setBlockType(o,s,e,t)}r(a.scrollIntoView())}return!0};function markApplies(e,t,n,r){for(let a=0;a<t.length;a++){let{$from:o,$to:s}=t[a],c=o.depth==0?e.inlineContent&&e.type.allowsMarkType(n):!1;if(e.nodesBetween(o.pos,s.pos,(e,t)=>{if(c||!r&&e.isAtom&&e.isInline&&t>=o.pos&&t+e.nodeSize<=s.pos)return!1;c=e.inlineContent&&e.type.allowsMarkType(n)}),c)return!0}return!1}function removeInlineAtoms(e){let t=[];for(let n=0;n<e.length;n++){let{$from:r,$to:a}=e[n];r.doc.nodesBetween(r.pos,a.pos,(e,n)=>{if(e.isAtom&&e.content.size&&e.isInline&&n>=r.pos&&n+e.nodeSize<=a.pos)return n+1>r.pos&&t.push(new SelectionRange(r,r.doc.resolve(n+1))),r=r.doc.resolve(n+1+e.content.size),!1}),r.pos<a.pos&&t.push(new SelectionRange(r,a))}return t}function toggleMark(e,t=null,n){let r=(n&&n.removeWhenPresent)!==!1,a=(n&&n.enterInlineAtoms)!==!1,o=!(n&&n.includeWhitespace);return function(n,s){let{empty:c,$cursor:l,ranges:u}=n.selection;if(c&&!l||!markApplies(n.doc,u,e,a))return!1;if(s)if(l)e.isInSet(n.storedMarks||l.marks())?s(n.tr.removeStoredMark(e)):s(n.tr.addStoredMark(e.create(t)));else{let c,l=n.tr;a||(u=removeInlineAtoms(u)),c=r?!u.some(t=>n.doc.rangeHasMark(t.$from.pos,t.$to.pos,e)):!u.every(t=>{let n=!1;return l.doc.nodesBetween(t.$from.pos,t.$to.pos,(r,a,o)=>{if(n)return!1;n=!e.isInSet(r.marks)&&!!o&&o.type.allowsMarkType(e)&&!(r.isText&&/^\s*$/.test(r.textBetween(Math.max(0,t.$from.pos-a),Math.min(r.nodeSize,t.$to.pos-a))))}),!n});for(let n=0;n<u.length;n++){let{$from:r,$to:a}=u[n];if(!c)l.removeMark(r.pos,a.pos,e);else{let n=r.pos,s=a.pos,c=r.nodeAfter,u=a.nodeBefore,d=o&&c&&c.isText?/^\s*/.exec(c.text)[0].length:0,f=o&&u&&u.isText?/\s*$/.exec(u.text)[0].length:0;n+d<s&&(n+=d,s-=f),l.addMark(n,s,e.create(t))}}s(l.scrollIntoView())}return!0}}var undoInputRule=()=>undoInputRuleCommand,command=e=>(...t)=>e.apply(void 0,t),baseCommandFactories={wrapInList,wrapRangeInList,deleteSelection,joinBackward,joinTextblockBackward,joinTextblockForward,joinForward,joinUp,joinDown,lift,newlineInCode,exitCode,createParagraphNear,liftEmptyBlock,splitBlockAs,splitBlock,splitBlockKeepMarks,selectAll:selectAll$1,selectParentNode,selectNodeBackward,selectNodeForward,selectTextblockStart:()=>selectTextblockSide(-1),selectTextblockEnd:()=>selectTextblockSide(1),wrapIn,setBlockType,toggleMark,undoInputRule,runInputRulesRange,runInputRulesTexts,command};function firstCommand(...e){let t=function(t,n,r){for(let a=0;a<e.length;a++)if(e[a](t,n,r))return e[a].displayName!==`first`&&console.debug(`firstCommand: `,e[a].displayName||e[a]),!0;return!1};return t.displayName=`first`,t}var backspace=firstCommand(baseCommandFactories.undoInputRule(),baseCommandFactories.deleteSelection(),baseCommandFactories.joinBackward(),baseCommandFactories.selectNodeBackward()),del=firstCommand(baseCommandFactories.deleteSelection(),baseCommandFactories.joinForward(),baseCommandFactories.selectNodeForward()),enter=firstCommand(baseCommandFactories.newlineInCode(),baseCommandFactories.createParagraphNear(),baseCommandFactories.liftEmptyBlock(),baseCommandFactories.splitBlock()),keyCommandFactories={backspace:()=>backspace,del:()=>del,enter:()=>enter},replaceRangeText=(e,t)=>(n,r)=>{let a=n.tr,o=a.mapping.map(e.from),s=a.mapping.map(e.to);if(t.length>0){let e=new Slice(Fragment.from(n.schema.text(t)),0,0);a.replace(o,s,e)}else{let e=new Slice(Fragment.from(n.schema.topNodeType.createAndFill()),0,0);a.replace(o,s,e)}return r&&r(a),!0},replaceRangeSlice=(e,t)=>(n,r)=>{let a=n.tr,o=a.mapping.map(e.from),s=a.mapping.map(e.to);return a.replace(o,s,t),r&&r(a),!0};function getTopMostBlockStartForOffset(e,t){let{doc:n}=e,r=n.resolve(t),a=r.before(r.depth);return r.depth===1?a:r.start(1)}function getTopMostBlockEndForOffset(e,t){let{doc:n}=e;return n.resolve(t).end(1)}function getAdjacentTopBlock(e,t){let{doc:n}=e;if(t<0||t>n.content.size)throw RangeError(`Offset is outside the document`);let r=n.resolve(t);return r.pos===r.start(r.depth)?getTopMostBlockStartForOffset(e,t):getTopMostBlockEndForOffset(e,t)}var insertBlockBefore=(e,t)=>(n,r)=>{let a=n.tr,o=getTopMostBlockStartForOffset(n,a.mapping.map(e));return a.insert(o,t),r&&r(a),!0},insertBlockAfter=(e,t)=>(n,r)=>{let a=n.tr,o=getTopMostBlockEndForOffset(n,a.mapping.map(e));return a.insert(o,t),r&&r(a),!0},insertBlockSmart=(e,t)=>(n,r)=>{let a=n.tr,o=getAdjacentTopBlock(n,a.mapping.map(e));return a.insert(o,t),r&&r(a),!0},replaceCommandFactories={replaceRangeText,replaceRangeSlice,insertBlockBefore,insertBlockAfter,insertBlockSmart},CommandManager=class{editor;commandFactories={};run={};debug=!0;constructor(e){this.editor=e,this.mergeCommandFactories(baseCommandFactories,`baseCommand`),this.mergeCommandFactories(keyCommandFactories,`key`),this.mergeCommandFactories(replaceCommandFactories,`replace`)}mergeCommandFactories(e,t){for(let n in e){let r=e[n];r&&this.overwriteCommandFactory(t,n,r)}}overwriteCommandFactory(e,t,n){if(this.debug){let r=(...r)=>{let a=n(...r);return(n,o,s)=>(o&&console.debug(`Command: ${e}.${t}`,...r),a.apply({editor:this.editor},[n,o,s]))};this.commandFactories[t]=r}else this.commandFactories[t]=n;this.run[t]=(...e)=>{let n=this.commandFactories[t],r=n(...e),a=this.editor.state,o=this.editor.view;return o instanceof EditorView?r.apply({editor:this.editor},[a,o.dispatch,o]):r.apply({editor:this.editor},[a,o.dispatch])}}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{commandFactories:n,editor:r}=this,a=this.editor.state,{view:o}=r,s=[],c=!!e,l=e||a.tr;l.setMeta(`isCommand`,!0);let u=createChainableState(l,a),d=()=>void 0,f={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=n(...e).apply({editor:this.editor},[u,t?d:void 0]);return s.push(r),f}])),run:()=>(!c&&t&&!l.getMeta(`preventDispatch`)&&o.dispatch(l),s.every(e=>e===!0)),chain:()=>this.createChain(l,t)};return f}createCan(e){return this.createChain(e,!1)}},SmartOutput=class{_rowPos=0;_colPos=0;_pos=0;chunks=[];metas=[];log(e,t){if(e.length===0)return;this.chunks.push(e),this.metas.push({pos:this._pos,colPos:this._colPos,rowPos:this._rowPos,item:t});let n=e.split(`
12
+ `)}function fromJSON(e){if(e===null)return null;if(Array.isArray(e))return e.map(fromJSON);if(typeof e==`object`){if(e instanceof Map)return e;let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,fromJSON(r));return t}if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;throw Error(`Unsupported JSON value: ${typeof e}`)}function toJSON(e){if(e instanceof Map){let t={};for(let[n,r]of e)t[n]=toJSON(r);return t}return Array.isArray(e)?e.map(toJSON):e}function setPathValue(e,t,n){let r=t.match(/[^.\[\]]+|\[\d+\]/g)?.map(e=>e.startsWith(`[`)?Number(e.slice(1,-1)):e)??[];if(r.length===0)throw Error(`empty path`);if(!(e instanceof Map)&&!Array.isArray(e))throw Error(`root must be Map or array`);let a=e;for(let e=0;e<r.length-1;e++){let n=r[e],o=typeof n==`number`?Array.isArray(a)?a[n]:void 0:a instanceof Map?a.get(n):void 0;if(!(o instanceof Map)&&!Array.isArray(o)){if(o!=null)throw console.log(`next`,o),Error(`"${n}" #${e} of "${t}" not container`);o=typeof r[e+1]==`number`?[]:new Map,typeof n==`number`?a[n]=o:a.set(n,o)}a=o}let o=r[r.length-1];if(typeof o==`number`){if(!Array.isArray(a))throw Error(`target not array`);for(;a.length<=o;)a.push(null);a[o]=n}else{if(!(a instanceof Map))throw Error(`target not map`);a.set(o,n)}}var SearchQuery=class{search;caseSensitive;literal;regexp;replace;valid;wholeWord;filter;impl;constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&!(this.regexp&&!validRegExp(this.search)),this.wholeWord=!!e.wholeWord,this.filter=e.filter||null,this.impl=this.valid?this.regexp?new RegExpQuery(this):new StringQuery(this):nullQuery}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}findNext(e,t=0,n=e.doc.content.size){for(;;){if(t>=n)return null;let r=this.impl.findNext(e,t,n);if(!r||this.checkResult(e,r))return r;t=r.from+1}}findPrev(e,t=e.doc.content.size,n=0){for(;;){if(t<=n)return null;let r=this.impl.findPrev(e,t,n);if(!r||this.checkResult(e,r))return r;t=r.to-1}}checkResult(e,t){return(!this.wholeWord||checkWordBoundary(e,t.from)&&checkWordBoundary(e,t.to))&&(!this.filter||this.filter(e,t))}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
13
+ `:t==`r`?`\r`:t==`t`?` `:`\\`)}getReplacements(e,t){let n=e.doc.resolve(t.from).marksAcross(e.doc.resolve(t.to)),r=[],a=Fragment.empty,o=t.from,{match:s}=t,c=s?getGroupIndices(s):[[0,t.to-t.from]],l=parseReplacement(this.unquote(this.replace)),u;for(let s of l)if(typeof s==`string`)a=a.addToEnd(e.schema.text(s,n));else if(u=c[s.group],u){let n=t.matchStart+u[0],c=t.matchStart+u[1];s.copy?a=a.append(e.doc.slice(n,c).content):((a!=Fragment.empty||n>o)&&(r.push({from:o,to:n,insert:new Slice(a,0,0)}),a=Fragment.empty),o=c)}return(a!=Fragment.empty||o<t.to)&&r.push({from:o,to:t.to,insert:new Slice(a,0,0)}),r}},nullQuery=new class{findNext(){return null}findPrev(){return null}},StringQuery=class{query;string;constructor(e){this.query=e;let t=e.unquote(e.search);e.caseSensitive||(t=t.toLowerCase()),this.string=t}findNext(e,t,n){return scanTextblocks(e.doc,t,n,(e,r)=>{let a=Math.max(t,r),o=textContent(e).slice(a-r,Math.min(e.content.size,n-r)),s=(this.query.caseSensitive?o:o.toLowerCase()).indexOf(this.string);return s<0?null:{from:a+s,to:a+s+this.string.length,match:null,matchStart:r}})}findPrev(e,t,n){return scanTextblocks(e.doc,t,n,(e,r)=>{let a=Math.max(r,n),o=textContent(e).slice(a-r,Math.min(e.content.size,t-r));this.query.caseSensitive||(o=o.toLowerCase());let s=o.lastIndexOf(this.string);return s<0?null:{from:a+s,to:a+s+this.string.length,match:null,matchStart:r}})}},baseFlags=`g`+(/x/.unicode==null?``:`u`)+(/x/.hasIndices==null?``:`d`),RegExpQuery=class{query;regexp;constructor(e){this.query=e,this.regexp=new RegExp(e.search,baseFlags+(e.caseSensitive?``:`i`))}findNext(e,t,n){return scanTextblocks(e.doc,t,n,(e,r)=>{let a=textContent(e).slice(0,Math.min(e.content.size,n-r));this.regexp.lastIndex=t-r;let o=this.regexp.exec(a);return o?{from:r+o.index,to:r+o.index+o[0].length,match:o,matchStart:r}:null})}findPrev(e,t,n){return scanTextblocks(e.doc,t,n,(e,n)=>{let r=textContent(e).slice(0,Math.min(e.content.size,t-n)),a;for(let e=0;;){this.regexp.lastIndex=e;let t=this.regexp.exec(r);if(!t)break;a=t,e=t.index+1}return a?{from:n+a.index,to:n+a.index+a[0].length,match:a,matchStart:n}:null})}};function getGroupIndices(e){if(e.indices)return e.indices;let t=[[0,e[0].length]];for(let n=1,r=0;n<e.length;n++){let a=e[n]?e[0].indexOf(e[n],r):-1;t.push(a<0?void 0:[a,r=a+e[n].length])}return t}function parseReplacement(e){let t=[],n=-1;function r(e){let n=t.length-1;n>-1&&typeof t[n]==`string`?t[n]+=e:t.push(e)}for(;e.length;){let a=/\$([$&\d+])/.exec(e);if(!a)return r(e),t;if(a.index>0&&r(e.slice(0,a.index+ +(a[1]==`$`))),a[1]!=`$`){let e=a[1]==`&`?0:+a[1];n>=e?t.push({group:e,copy:!0}):(n=e||1e3,t.push({group:e,copy:!1}))}e=e.slice(a.index+a[0].length)}return t}function validRegExp(e){try{return new RegExp(e,baseFlags),!0}catch{return!1}}var TextContentCache=new WeakMap;function textContent(e){let t=TextContentCache.get(e);if(t)return t;let n=``;for(let t=0;t<e.childCount;t++){let r=e.child(t);r.isText?n+=r.text:r.isLeaf?n+=``:n+=` `+textContent(r)+` `}return TextContentCache.set(e,n),n}function scanTextblocks(e,t,n,r,a=0){if(e.inlineContent)return r(e,a);if(!e.isLeaf)if(t>n)for(let o=e.childCount-1,s=a+e.content.size;o>=0&&s>n;o--){let a=e.child(o);if(s-=a.nodeSize,s<t){let e=scanTextblocks(a,t,n,r,s+1);if(e!=null)return e}}else for(let o=0,s=a;o<e.childCount&&s<n;o++){let a=e.child(o),c=s;if(s+=a.nodeSize,s>t){let e=scanTextblocks(a,t,n,r,c+1);if(e!=null)return e}}return null}function checkWordBoundary(e,t){let n=e.doc.resolve(t),r=n.nodeBefore,a=n.nodeAfter;return!r||!a||!r.isText||!a.isText?!0:!/\p{L}$/u.test(r.text)||!/^\p{L}/u.test(a.text)}var SearchState=class{query;range;deco;constructor(e,t,n){this.query=e,this.range=t,this.deco=n}};function buildMatchDeco(e,t,n){if(!t.valid)return DecorationSet.empty;let r=[],a=e.selection;for(let o=n?n.from:0,s=n?n.to:e.doc.content.size;;){let n=t.findNext(e,o,s);if(!n)break;let c=n.from==a.from&&n.to==a.to?`kb-active-search-match`:`kb-search-match`;r.push(Decoration.inline(n.from,n.to,{class:c})),o=n.to}return DecorationSet.create(e.doc,r)}var searchKey=new PluginKey(`search`);function createSearchPlugin(e={}){return new Plugin({key:searchKey,state:{init(t,n){let r=e.initialQuery||new SearchQuery({search:``}),a=e.initialRange||null;return new SearchState(r,a,buildMatchDeco(n,r,a))},apply(e,t,n,r){let a=e.getMeta(searchKey);if(a)return new SearchState(a.query,a.range,buildMatchDeco(r,a.query,a.range));if(e.docChanged||e.selectionSet){let n=t.range;if(n){let t=e.mapping.map(n.from,1),r=e.mapping.map(n.to,-1);n=t<r?{from:t,to:r}:null}t=new SearchState(t.query,n,buildMatchDeco(r,t.query,n))}return t}},props:{decorations:e=>searchKey.getState(e).deco}})}function setSearchState(e,t,n=null){return e.setMeta(searchKey,{query:t,range:n})}function nextMatch(e,t,n,r,a){let o=e.range||{from:0,to:t.doc.content.size},s=e.query.findNext(t,Math.max(a,o.from),o.to);return!s&&n&&(s=e.query.findNext(t,o.from,Math.min(r,o.to))),s}function prevMatch(e,t,n,r,a){let o=e.range||{from:0,to:t.doc.content.size},s=e.query.findPrev(t,Math.min(r,o.to),o.from);return!s&&n&&(s=e.query.findPrev(t,o.to,Math.max(a,o.from))),s}function findCommand(e,t){return(n,r)=>{let a=searchKey.getState(n);if(!a||!a.query.valid)return!1;let{from:o,to:s}=n.selection,c=t>0?nextMatch(a,n,e,o,s):prevMatch(a,n,e,o,s);if(!c)return!1;let l=TextSelection.create(n.doc,c.from,c.to);return r&&r(n.tr.setSelection(l).scrollIntoView()),!0}}var findNext=findCommand(!0,1),findNextNoWrap=findCommand(!1,1),findPrev=findCommand(!0,-1),findPrevNoWrap=findCommand(!1,-1);function replaceCommand(e,t){return(n,r)=>{let a=searchKey.getState(n);if(!a||!a.query.valid)return!1;let{from:o}=n.selection,s=nextMatch(a,n,e,o,o);if(!s)return!1;if(!r)return!0;if(n.selection.from==s.from&&n.selection.to==s.to){let o=n.tr,c=a.query.getReplacements(n,s);for(let e=c.length-1;e>=0;e--){let{from:t,to:n,insert:r}=c[e];o.replace(t,n,r)}let l=t&&nextMatch(a,n,e,s.from,s.to);l?o.setSelection(TextSelection.create(o.doc,o.mapping.map(l.from,1),o.mapping.map(l.to,-1))):o.setSelection(TextSelection.create(o.doc,s.from,o.mapping.map(s.to,1))),r(o.scrollIntoView())}else if(t)r(n.tr.setSelection(TextSelection.create(n.doc,s.from,s.to)).scrollIntoView());else return!1;return!0}}var replaceNext=replaceCommand(!0,!0),replaceNextNoWrap=replaceCommand(!1,!0),replaceCurrent=replaceCommand(!1,!1),replaceAll=(e,t)=>{let n=searchKey.getState(e);if(!n)return!1;let r=[],a=n.range||{from:0,to:e.doc.content.size};for(let t=a.from;;){let o=n.query.findNext(e,t,a.to);if(!o)break;r.push(o),t=o.to}if(t){let a=e.tr;for(let t=r.length-1;t>=0;t--){let o=r[t],s=n.query.getReplacements(e,o);for(let e=s.length-1;e>=0;e--){let{from:t,to:n,insert:r}=s[e];a.replace(t,n,r)}}t(a)}return!0},searchFactory=(e,t=null)=>(n,r)=>{let a=n.tr;return setSearchState(a,e,t),r&&r(a),!0},searchCommandFactories={search:searchFactory,findNext:()=>findNext,findNextNoWrap:()=>findNextNoWrap,findPrev:()=>findPrev,findPrevNoWrap:()=>findPrevNoWrap,replaceNext:()=>replaceNext,replaceNextNoWrap:()=>replaceNextNoWrap,replaceCurrent:()=>replaceCurrent,replaceAll:()=>replaceAll};function splitExtensions(e){return{baseExtensions:Array.from(e).filter(e=>e.type===`extension`),nodeExtensions:Array.from(e).filter(e=>e.type===`node`),markExtensions:Array.from(e).filter(e=>e.type===`mark`)}}var ExtensionManager=class{editorKits;debug;extensions=new Set;plugins=[];nodeViews={};converters={};constructor(e,t=!1){this.editorKits=e,this.debug=t;let n=e.reduce((e,t)=>e.concat(t.getExtensions()),[]);this.setupExtensions(new Set(n))}initPlugins(e,t){let n=[],r=new Map,a=(t,n)=>{for(let n in t){if(!t[n])continue;let a=e.commandFactories[t[n]];if(!a){console.warn(`No command constructor: ${t[n]}`);continue}let o=a(),s=r.get(n);s?r.set(n,firstCommand$1(o,s)):r.set(n,o)}},o={};for(let r of this.extensions){if(r.setEditor(e),r.type===`node`){let s=t.nodes[r.name];n.push(...r.getInputRules(s)),this.plugins.push(...r.getProseMirrorPlugins()),e.mergeCommandFactories(r.getCommandFactories(e,s),r.name),a(r.getKeyboardShortcuts(e),r.name),o={...o,...r.getConverters(e,t)};let c=r.getNodeView(e);c&&(this.nodeViews[r.name]=c)}if(r.type===`mark`){let o=t.marks[r.name];n.push(...r.getInputRules(o)),e.mergeCommandFactories(r.getCommandFactories(e,o),r.name),a(r.getKeyboardShortcuts(e),r.name)}r.type===`extension`&&(this.plugins.push(...r.getProseMirrorPlugins()),e.mergeCommandFactories(r.getCommandFactories(e),r.name),a(r.getKeyboardShortcuts(e),r.name),o={...o,...r.getConverters(e,t)})}if(this.debug)for(let e in r){let t=r.get(e);t&&r.set(e,firstCommand$1((t,n,r)=>(console.debug(`Key: ${e}`),!0),t))}this.converters=o,this.plugins.push(new InputRulesPlugin(n)),this.plugins.push(new KeymapPlugin(Object.fromEntries(r))),this.plugins.push(createSearchPlugin()),this.plugins.push(new TrackSelecionPlugin(e))}setupExtensions(e){let t=new Map,n=e=>{for(let r of e){if(`name`in r){let e=t.get(r.name);if(e&&`type`in e&&r.type!==e.type)throw Error(`Duplicate mark/node: ${r.name}`);t.set(r.name,r)}if(`requires`in r){let e=Array.from(r.requires).filter(e=>typeof e!=`string`);n(new Set(e))}}};n(e);let r=new Set,a=e=>{this.debug&&console.info(`Initialize ${e.type} ${e.name}`),this.extensions.add(e)};function o(e){if(!(`name`in e&&r.has(e.name))){if(`requires`in e){let n=(e.requires||[]).map(e=>typeof e==`string`?e:`name`in e?e.name:``);for(let a of n)if(!r.has(a)){let n=t.get(a);if(!n)throw Error(`Required extension for (${`name`in e?e.name:e}) not found: ${a}`);o(n)}}`name`in e&&(a(e),r.add(e.name),t.delete(e.name))}}for(let e of t.values())o(e);if(t.size>0)throw Error(`Not all extensions initialized: `+Array.from(t.keys()).join(`, `))}getSchemaByResolvedExtensions(){let{nodeExtensions:e,markExtensions:t,baseExtensions:n}=splitExtensions(this.extensions),r={},a=``;for(let t of e){if(r[t.name]=t.getNodeSpec(),r[t.name].EMPTY_DOC){if(a)throw Error(`Multiple topNodes: ${t.name}, ${a}`);a=t.name}addAttributesToSchema(r[t.name],t)}let o={};for(let e of t)o[e.name]=e.getMarkSpec(),addAttributesToSchema(o[e.name],e);let s={topNode:a||`doc`,nodes:r,marks:o};for(let e of n)`setupSpec`in n&&e.setupSpec(s);return new Schema(s)}created(e,t){let{nodeExtensions:n,markExtensions:r,baseExtensions:a}=splitExtensions(this.extensions);for(let e of a)if(Array.isArray(e.conflicts)){for(let t of e.conflicts)if(a.find(e=>e.name===t))throw Error(`Extension conflict: ${e.name} vs ${t}`)}for(let t of a)e.ci.register(t.name,t);e.ci.register(`yaml`,yaml_exports),this.initPlugins(e,t);for(let e of this.extensions)e.created()}};function createChainableState(e,t){let{selection:n}=e,{doc:r}=e,{storedMarks:a}=e;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return n},get doc(){return r},get tr(){return n=e.selection,r=e.doc,a=e.storedMarks,e}}}var wrapInList=(e,t=null)=>function(n,r,a){let{$from:o,$to:s}=n.selection,c=o.blockRange(s);if(!c)return!1;let l=r?n.tr:null;return wrapRangeInList(l,c,e,t).apply(this,[n,r])?(r&&r(l.scrollIntoView()),!0):!1},wrapRangeInList=(e,t,n,r=null)=>()=>{let a=!1,o=t,s=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=s.resolve(t.start-2);o=new NodeRange(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new NodeRange(t.$from,s.resolve(t.$to.end(t.depth)),t.depth)),a=!0}let c=findWrapping(o,n,r,t);return c?(e&&doWrapInList(e,t,c,a,n),!0):!1};function doWrapInList(e,t,n,r,a){let o=Fragment.empty;for(let e=n.length-1;e>=0;e--)o=Fragment.from(n[e].type.create(n[e].attrs,o));e.step(new ReplaceAroundStep(t.start-(r?2:0),t.end,t.start,t.end,new Slice(o,0,0),n.length,!0));let s=0;for(let e=0;e<n.length;e++)n[e].type==a&&(s=e+1);let c=n.length-s,l=t.start+n.length-(r?2:0),u=t.parent;for(let n=t.startIndex,r=t.endIndex,a=!0;n<r;n++,a=!1)!a&&canSplit(e.doc,l,c)&&(e.split(l,c),l+=2*c),l+=u.child(n).nodeSize;return e}var deleteSelection=()=>(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function atBlockStart(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var joinBackward=()=>(e,t,n)=>{let r=atBlockStart(e,n);if(!r)return!1;let a=findCutBefore(r);if(!a){let n=r.blockRange(),a=n&&liftTarget(n);return a==null?!1:(t&&t(e.tr.lift(n,a).scrollIntoView()),!0)}let o=a.nodeBefore;if(deleteBarrier(e,a,t,-1))return!0;if(r.parent.content.size==0&&(textblockAt(o,`end`)||NodeSelection.isSelectable(o)))for(let n=r.depth;;n--){let s=replaceStep(e.doc,r.before(n),r.after(n),Slice.empty);if(s&&s.slice.size<s.to-s.from){if(t){let n=e.tr.step(s);n.setSelection(textblockAt(o,`end`)?Selection.findFrom(n.doc.resolve(n.mapping.map(a.pos,-1)),-1):NodeSelection.create(n.doc,a.pos-o.nodeSize)),t(n.scrollIntoView())}return!0}if(n==1||r.node(n-1).childCount>1)break}return o.isAtom&&a.depth==r.depth-1?(t&&t(e.tr.delete(a.pos-o.nodeSize,a.pos).scrollIntoView()),!0):!1},joinTextblockBackward=()=>(e,t,n)=>{let r=atBlockStart(e,n);if(!r)return!1;let a=findCutBefore(r);return a?joinTextblocksAround(e,a,t):!1},joinTextblockForward=()=>(e,t,n)=>{let r=atBlockEnd(e,n);if(!r)return!1;let a=findCutAfter(r);return a?joinTextblocksAround(e,a,t):!1};function joinTextblocksAround(e,t,n){let r=t.nodeBefore,a=t.pos-1;for(;!r.isTextblock;a--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let o=t.nodeAfter,s=t.pos+1;for(;!o.isTextblock;s++){if(o.type.spec.isolating)return!1;let e=o.firstChild;if(!e)return!1;o=e}let c=replaceStep(e.doc,a,s,Slice.empty);if(!c||c.from!=a||c instanceof ReplaceStep&&c.slice.size>=s-a)return!1;if(n){let t=e.tr.step(c);t.setSelection(TextSelection.create(t.doc,a)),n(t.scrollIntoView())}return!0}function textblockAt(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var selectNodeBackward=()=>(e,t,n)=>{let{$head:r,empty:a}=e.selection,o=r;if(!a)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;o=findCutBefore(r)}let s=o&&o.nodeBefore;return!s||!NodeSelection.isSelectable(s)?!1:(t&&t(e.tr.setSelection(NodeSelection.create(e.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function findCutBefore(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function atBlockEnd(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset<n.parent.content.size)?null:n}var joinForward=()=>(e,t,n)=>{let r=atBlockEnd(e,n);if(!r)return!1;let a=findCutAfter(r);if(!a)return!1;let o=a.nodeAfter;if(deleteBarrier(e,a,t,1))return!0;if(r.parent.content.size==0&&(textblockAt(o,`start`)||NodeSelection.isSelectable(o))){let n=replaceStep(e.doc,r.before(),r.after(),Slice.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(textblockAt(o,`start`)?Selection.findFrom(r.doc.resolve(r.mapping.map(a.pos)),1):NodeSelection.create(r.doc,r.mapping.map(a.pos))),t(r.scrollIntoView())}return!0}}return o.isAtom&&a.depth==r.depth-1?(t&&t(e.tr.delete(a.pos,a.pos+o.nodeSize).scrollIntoView()),!0):!1},selectNodeForward=()=>(e,t,n)=>{let{$head:r,empty:a}=e.selection,o=r;if(!a)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset<r.parent.content.size)return!1;o=findCutAfter(r)}let s=o&&o.nodeAfter;return!s||!NodeSelection.isSelectable(s)?!1:(t&&t(e.tr.setSelection(NodeSelection.create(e.doc,o.pos)).scrollIntoView()),!0)};function findCutAfter(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}var joinUp=()=>(e,t)=>{let n=e.selection,r=n instanceof NodeSelection,a;if(r){if(n.node.isTextblock||!canJoin(e.doc,n.from))return!1;a=n.from}else if(a=joinPoint(e.doc,n.from,-1),a==null)return!1;if(t){let n=e.tr.join(a);r&&n.setSelection(NodeSelection.create(n.doc,a-e.doc.resolve(a).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},joinDown=()=>(e,t)=>{let n=e.selection,r;if(n instanceof NodeSelection){if(n.node.isTextblock||!canJoin(e.doc,n.to))return!1;r=n.to}else if(r=joinPoint(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},lift=()=>(e,t)=>{let{$from:n,$to:r}=e.selection,a=n.blockRange(r),o=a&&liftTarget(a);return o==null?!1:(t&&t(e.tr.lift(a,o).scrollIntoView()),!0)},newlineInCode=()=>{let e=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(`
14
+ `).scrollIntoView()),!0)};return e.displayName=`newlineInCode()`,e};function defaultBlockAt(e){console.log(`defaultBlockAt`,e);for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var exitCode=()=>(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let a=n.node(-1),o=n.indexAfter(-1),s=defaultBlockAt(a.contentMatchAt(o));if(!s||!a.canReplaceWith(o,o,s))return!1;if(t){let r=n.after(),a=e.tr.replaceWith(r,r,s.createAndFill());a.setSelection(Selection.near(a.doc.resolve(r),1)),t(a.scrollIntoView())}return!0},createParagraphNear=()=>{let e=(e,t)=>{let n=e.selection,{$from:r,$to:a}=n;if(n instanceof AllSelection||r.parent.inlineContent||a.parent.inlineContent)return!1;let o=defaultBlockAt(a.parent.contentMatchAt(a.indexAfter()));if(!o||!o.isTextblock)return!1;if(t){let n=(!r.parentOffset&&a.index()<a.parent.childCount?r:a).pos,s=e.tr.insert(n,o.createAndFill());s.setSelection(TextSelection.create(s.doc,n+1)),t(s.scrollIntoView())}return!0};return e.displayName=`createParagraphNear()`,e},liftEmptyBlock=()=>{let e=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(canSplit(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),a=r&&liftTarget(r);return a==null?!1:(t&&t(e.tr.lift(r,a).scrollIntoView()),!0)};return e.displayName=`liftEmptyBlock()`,e},splitBlockAs=e=>{let t=(t,n)=>{let{$from:r,$to:a}=t.selection;if(t.selection instanceof NodeSelection&&t.selection.node.isBlock)return!r.parentOffset||!canSplit(t.doc,r.pos)?!1:(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,c,l=!1,u=!1;for(let t=r.depth;;t--)if(r.node(t).isBlock){l=r.end(t)==r.pos+(r.depth-t),u=r.start(t)==r.pos-(r.depth-t),c=defaultBlockAt(r.node(t-1).contentMatchAt(r.indexAfter(t-1)));let n=e&&e(a.parent,l,r);o.unshift(n||(l&&c?{type:c}:null)),s=t;break}else{if(t==1)return!1;o.unshift(null)}let d=t.tr;(t.selection instanceof TextSelection||t.selection instanceof AllSelection)&&d.deleteSelection();let f=d.mapping.map(r.pos),p=canSplit(d.doc,f,o.length,o);if(p||=(o[0]=c?{type:c}:null,canSplit(d.doc,f,o.length,o)),d.split(f,o.length,o),!l&&u&&r.node(s).type!=c){let e=d.mapping.map(r.before(s)),t=d.doc.resolve(e);c&&r.node(s-1).canReplaceWith(t.index(),t.index()+1,c)&&d.setNodeMarkup(d.mapping.map(r.before(s)),c)}return n&&n(d.scrollIntoView()),!0};return t.displayName=`splitBlockAs()`,t},splitBlock=()=>splitBlockAs(),splitBlockKeepMarks=()=>(e,t)=>splitBlockAs().apply(void 0,[e,t&&(n=>{let r=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();r&&n.ensureMarks(r),t(n)})]),selectParentNode=()=>(e,t)=>{let{$from:n,to:r}=e.selection,a,o=n.sharedDepth(r);return o==0?!1:(a=n.before(o),t&&t(e.tr.setSelection(NodeSelection.create(e.doc,a))),!0)},selectAll$1=()=>(e,t)=>(t&&t(e.tr.setSelection(new AllSelection(e.doc))),!0);function joinMaybeClear(e,t,n){let r=t.nodeBefore,a=t.nodeAfter,o=t.index();return!r||!a||!r.type.compatibleContent(a.type)?!1:!r.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(o,o+1)||!(a.isTextblock||canJoin(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function deleteBarrier(e,t,n,r){let a=t.nodeBefore,o=t.nodeAfter,s,c,l=a.type.spec.isolating||o.type.spec.isolating;if(!l&&joinMaybeClear(e,t,n))return!0;let u=!l&&t.parent.canReplace(t.index(),t.index()+1);if(u&&(s=(c=a.contentMatchAt(a.childCount)).findWrapping(o.type))&&c.matchType(s[0]||o.type).validEnd){if(n){let r=t.pos+o.nodeSize,c=Fragment.empty;for(let e=s.length-1;e>=0;e--)c=Fragment.from(s[e].create(null,c));c=Fragment.from(a.copy(c));let l=e.tr.step(new ReplaceAroundStep(t.pos-1,r,t.pos,r,new Slice(c,1,0),s.length,!0)),u=l.doc.resolve(r+2*s.length);u.nodeAfter&&u.nodeAfter.type==a.type&&canJoin(l.doc,u.pos)&&l.join(u.pos),n(l.scrollIntoView())}return!0}let d=o.type.spec.isolating||r>0&&l?null:Selection.findFrom(t,1),f=d&&d.$from.blockRange(d.$to),p=f&&liftTarget(f);if(p!=null&&p>=t.depth)return n&&n(e.tr.lift(f,p).scrollIntoView()),!0;if(u&&textblockAt(o,`start`,!0)&&textblockAt(a,`end`)){let r=a,s=[];for(;s.push(r),!r.isTextblock;)r=r.lastChild;let c=o,l=1;for(;!c.isTextblock;c=c.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,c.content)){if(n){let r=Fragment.empty;for(let e=s.length-1;e>=0;e--)r=Fragment.from(s[e].copy(r));n(e.tr.step(new ReplaceAroundStep(t.pos-s.length,t.pos+o.nodeSize,t.pos+l,t.pos+o.nodeSize-l,new Slice(r,s.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function selectTextblockSide(e){return function(t,n){let r=t.selection,a=e<0?r.$from:r.$to,o=a.depth;for(;a.node(o).isInline;){if(!o)return!1;o--}return a.node(o).isTextblock?(n&&n(t.tr.setSelection(TextSelection.create(t.doc,e<0?a.start(o):a.end(o)))),!0):!1}}var wrapIn=(e,t=null)=>function(n,r){let{$from:a,$to:o}=n.selection,s=a.blockRange(o),c=s&&findWrapping(s,e,t);return c?(r&&r(n.tr.wrap(s,c).scrollIntoView()),!0):!1},setBlockType=(e,t=null)=>function(n,r){let a=!1;for(let r=0;r<n.selection.ranges.length&&!a;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];n.doc.nodesBetween(o,s,(r,o)=>{if(a)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)a=!0;else{let t=n.doc.resolve(o),r=t.index();a=t.parent.canReplaceWith(r,r+1,e)}})}if(!a)return!1;if(r){let a=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];a.setBlockType(o,s,e,t)}r(a.scrollIntoView())}return!0};function markApplies(e,t,n,r){for(let a=0;a<t.length;a++){let{$from:o,$to:s}=t[a],c=o.depth==0?e.inlineContent&&e.type.allowsMarkType(n):!1;if(e.nodesBetween(o.pos,s.pos,(e,t)=>{if(c||!r&&e.isAtom&&e.isInline&&t>=o.pos&&t+e.nodeSize<=s.pos)return!1;c=e.inlineContent&&e.type.allowsMarkType(n)}),c)return!0}return!1}function removeInlineAtoms(e){let t=[];for(let n=0;n<e.length;n++){let{$from:r,$to:a}=e[n];r.doc.nodesBetween(r.pos,a.pos,(e,n)=>{if(e.isAtom&&e.content.size&&e.isInline&&n>=r.pos&&n+e.nodeSize<=a.pos)return n+1>r.pos&&t.push(new SelectionRange(r,r.doc.resolve(n+1))),r=r.doc.resolve(n+1+e.content.size),!1}),r.pos<a.pos&&t.push(new SelectionRange(r,a))}return t}function toggleMark(e,t=null,n){let r=(n&&n.removeWhenPresent)!==!1,a=(n&&n.enterInlineAtoms)!==!1,o=!(n&&n.includeWhitespace);return function(n,s){let{empty:c,$cursor:l,ranges:u}=n.selection;if(c&&!l||!markApplies(n.doc,u,e,a))return!1;if(s)if(l)e.isInSet(n.storedMarks||l.marks())?s(n.tr.removeStoredMark(e)):s(n.tr.addStoredMark(e.create(t)));else{let c,l=n.tr;a||(u=removeInlineAtoms(u)),c=r?!u.some(t=>n.doc.rangeHasMark(t.$from.pos,t.$to.pos,e)):!u.every(t=>{let n=!1;return l.doc.nodesBetween(t.$from.pos,t.$to.pos,(r,a,o)=>{if(n)return!1;n=!e.isInSet(r.marks)&&!!o&&o.type.allowsMarkType(e)&&!(r.isText&&/^\s*$/.test(r.textBetween(Math.max(0,t.$from.pos-a),Math.min(r.nodeSize,t.$to.pos-a))))}),!n});for(let n=0;n<u.length;n++){let{$from:r,$to:a}=u[n];if(!c)l.removeMark(r.pos,a.pos,e);else{let n=r.pos,s=a.pos,c=r.nodeAfter,u=a.nodeBefore,d=o&&c&&c.isText?/^\s*/.exec(c.text)[0].length:0,f=o&&u&&u.isText?/\s*$/.exec(u.text)[0].length:0;n+d<s&&(n+=d,s-=f),l.addMark(n,s,e.create(t))}}s(l.scrollIntoView())}return!0}}var undoInputRule=()=>undoInputRuleCommand,command=e=>(...t)=>e.apply(void 0,t),baseCommandFactories={wrapInList,wrapRangeInList,deleteSelection,joinBackward,joinTextblockBackward,joinTextblockForward,joinForward,joinUp,joinDown,lift,newlineInCode,exitCode,createParagraphNear,liftEmptyBlock,splitBlockAs,splitBlock,splitBlockKeepMarks,selectAll:selectAll$1,selectParentNode,selectNodeBackward,selectNodeForward,selectTextblockStart:()=>selectTextblockSide(-1),selectTextblockEnd:()=>selectTextblockSide(1),wrapIn,setBlockType,toggleMark,undoInputRule,runInputRulesRange,runInputRulesTexts,command};function firstCommand(...e){let t=function(t,n,r){for(let a=0;a<e.length;a++)if(e[a](t,n,r))return e[a].displayName!==`first`&&console.debug(`firstCommand: `,e[a].displayName||e[a]),!0;return!1};return t.displayName=`first`,t}var backspace=firstCommand(baseCommandFactories.undoInputRule(),baseCommandFactories.deleteSelection(),baseCommandFactories.joinBackward(),baseCommandFactories.selectNodeBackward()),del=firstCommand(baseCommandFactories.deleteSelection(),baseCommandFactories.joinForward(),baseCommandFactories.selectNodeForward()),enter=firstCommand(baseCommandFactories.newlineInCode(),baseCommandFactories.createParagraphNear(),baseCommandFactories.liftEmptyBlock(),baseCommandFactories.splitBlock()),keyCommandFactories={backspace:()=>backspace,del:()=>del,enter:()=>enter},replaceRangeText=(e,t)=>(n,r)=>{let a=n.tr,o=a.mapping.map(e.from),s=a.mapping.map(e.to);if(t.length>0){let e=new Slice(Fragment.from(n.schema.text(t)),0,0);a.replace(o,s,e)}else{let e=new Slice(Fragment.from(n.schema.topNodeType.createAndFill()),0,0);a.replace(o,s,e)}return r&&r(a),!0},replaceRangeSlice=(e,t)=>(n,r)=>{let a=n.tr,o=a.mapping.map(e.from),s=a.mapping.map(e.to);return a.replace(o,s,t),r&&r(a),!0};function getTopMostBlockStartForOffset(e,t){let{doc:n}=e,r=n.resolve(t),a=r.before(r.depth);return r.depth===1?a:r.start(1)}function getTopMostBlockEndForOffset(e,t){let{doc:n}=e;return n.resolve(t).end(1)}function getAdjacentTopBlock(e,t){let{doc:n}=e;if(t<0||t>n.content.size)throw RangeError(`Offset is outside the document`);let r=n.resolve(t);return r.pos===r.start(r.depth)?getTopMostBlockStartForOffset(e,t):getTopMostBlockEndForOffset(e,t)}var insertBlockBefore=(e,t)=>(n,r)=>{let a=n.tr,o=getTopMostBlockStartForOffset(n,a.mapping.map(e));return a.insert(o,t),r&&r(a),!0},insertBlockAfter=(e,t)=>(n,r)=>{let a=n.tr,o=getTopMostBlockEndForOffset(n,a.mapping.map(e));return a.insert(o,t),r&&r(a),!0},insertBlockSmart=(e,t)=>(n,r)=>{let a=n.tr,o=getAdjacentTopBlock(n,a.mapping.map(e));return a.insert(o,t),r&&r(a),!0},replaceCommandFactories={replaceRangeText,replaceRangeSlice,insertBlockBefore,insertBlockAfter,insertBlockSmart},CommandManager=class{editor;commandFactories={};run={};debug=!0;constructor(e){this.editor=e,this.mergeCommandFactories(baseCommandFactories,`baseCommand`),this.mergeCommandFactories(keyCommandFactories,`key`),this.mergeCommandFactories(replaceCommandFactories,`replace`),this.mergeCommandFactories(searchCommandFactories,`search`)}mergeCommandFactories(e,t){for(let n in e){let r=e[n];r&&this.overwriteCommandFactory(t,n,r)}}overwriteCommandFactory(e,t,n){if(this.debug){let r=(...r)=>{let a=n(...r);return(n,o,s)=>(o&&console.debug(`Command: ${e}.${t}`,...r),a.apply({editor:this.editor},[n,o,s]))};this.commandFactories[t]=r}else this.commandFactories[t]=n;this.run[t]=(...e)=>{let n=this.commandFactories[t],r=n(...e),a=this.editor.state,o=this.editor.view;return o instanceof EditorView?r.apply({editor:this.editor},[a,o.dispatch,o]):r.apply({editor:this.editor},[a,o.dispatch])}}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{commandFactories:n,editor:r}=this,a=this.editor.state,{view:o}=r,s=[],c=!!e,l=e||a.tr;l.setMeta(`isCommand`,!0);let u=createChainableState(l,a),d=()=>void 0,f={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=n(...e).apply({editor:this.editor},[u,t?d:void 0]);return s.push(r),f}])),run:()=>(!c&&t&&!l.getMeta(`preventDispatch`)&&o.dispatch(l),s.every(e=>e===!0)),chain:()=>this.createChain(l,t)};return f}createCan(e){return this.createChain(e,!1)}},SmartOutput=class{_rowPos=0;_colPos=0;_pos=0;chunks=[];metas=[];log(e,t){if(e.length===0)return;this.chunks.push(e),this.metas.push({pos:this._pos,colPos:this._colPos,rowPos:this._rowPos,item:t});let n=e.split(`
14
15
  `);n.length===1?this._colPos+=n[n.length-1].length:(this._rowPos+=n.length-1,this._colPos=n[n.length-1].length),this._pos+=e.length}getMetas(){return this.metas}get chunkPos(){return this.chunks.length}rollback(e){this.chunks.splice(e),this.metas.splice(e)}get rowPos(){return this._rowPos}get colPos(){return this._colPos}get pos(){return this._pos}backspace(e){let t=[],n=[];for(;e>0&&this.chunks[0].length>0;){let r=this.metas.pop(),a=this.chunks.pop();if(!a||!r)break;let o=a.length;a=a.substring(0,Math.max(0,a.length-e)),t.unshift(r),n.unshift(a),e-=o-a.length}this.chunks.push(...n),this.metas.push(...t)}endsWith(e){return this.chunks.join(``).endsWith(e)}toString(){return this.chunks.join(``)}getSourceMap(e){let t=[],n=-1,r=-1,a=0,o=0,s=0,c=0;for(let l of this.metas){for(;l.rowPos>=t.length;)t.push([]);if(n!=l.rowPos||r!=l.colPos){let r=t[l.rowPos];n!=l.rowPos&&(c=0);let u=e(l.rowPos,l.colPos,l.pos,l.item);u&&(r.push([l.colPos-c,u.sourceNo-a,u.sourceRowPos-o,u.sourceColPos-s]),c=l.colPos,a=u.sourceNo,o=u.sourceRowPos,s=u.sourceColPos)}n=l.rowPos,r=l.colPos}return{version:3,file:``,sourceRoot:``,sources:[],sourcesContent:[],names:[],mappings:t.map(e=>e.map(e=>encode(e)).join(`,`)).join(`;`)}}},char_to_integer={},integer_to_char={};`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=`.split(``).forEach(function(e,t){char_to_integer[e]=t,integer_to_char[t]=e});function encode(e){if(typeof e==`number`)return encode_integer(e);let t=``;for(let n=0;n<e.length;n+=1)t+=encode_integer(e[n]);return t}function encode_integer(e){let t=``;e<0?e=-e<<1|1:e<<=1;do{let n=e&31;e>>>=5,e>0&&(n|=32),t+=integer_to_char[n]}while(e>0);return t}function trimText(e,t=20){return e=e.replaceAll(`
15
16
  `,`\\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+`
16
17
  `,{node:t,pos:r});let n=``;if(t.marks)for(let e of t.marks)n+=`(${e.type.name}), `;n&&e.log(a+` `+n+`
@@ -181,7 +182,7 @@ The downside of making edits easy is that .parse() doesn't really accept a funct
181
182
  `);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.rootNode),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(t,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`){let e=n.content,a=e.indexOf(`
182
183
  ---
183
184
  `,4);if(e.startsWith(`---
184
- `)&&a>-1){let n=t.yaml?.parse(e.substring(4,a))||void 0;r.attrs={...r.attrs,meta:n}}}}},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:{node:`hr`},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}}},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 PositionMapper=class{rawTextMap;rawTextArr;doc;constructor(e,t){this.rawTextMap=t,this.doc=e.state.doc,this.rawTextArr=[];for(let e of t)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 e=0;e<this.rawTextArr.length;e++){let t=e+1;t<this.rawTextArr.length?this.rawTextArr[e].maxNodeIdx=this.rawTextArr[t].nodeIdx-1:this.rawTextArr[e].maxNodeIdx=this.doc.nodeSize}}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}toRawTextLspPos(e){for(let t=0;t<this.rawTextArr.length;t++){let n=this.rawTextArr[t];if(e>=n.nodeIdx&&e<=n.maxNodeIdx)return{line:n.targetRow,character:n.targetCol+e-n.nodeIdx}}return{line:0,character: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}},MarkdownPluginState=class{editor;extensionMarkdown;capturing=!1;constructor(e,t){this.editor=e,this.extensionMarkdown=t,this.performSnapshot=debounce$1(this.performSnapshot.bind(this),800)}snapshot;async performSnapshot(){let e=this.editor,t=e.version;if(t===this.snapshot?.version)return;let n=await this.extensionMarkdown.toMarkdown(e.state.doc);e.version;let r=new PositionMapper(e,n.rawTextMap);this.snapshot={markdownResult:n,version:t,mapper:r},this.dispatchMeta({snapshot:this.snapshot})}dispatchMeta(e){let t=this.editor.state.tr;t.setMeta(`markdown`,e),this.editor.dispatchTransaction(t)}};function createMarkdownPlugin(e,t){return t.version,new Plugin({state:{init(){return new MarkdownPluginState(t,e)},apply(e,t,n,r){return e.docChanged&&t.capturing&&t.performSnapshot(),t}}})}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`],yaml:e.ci.resolve(`yaml`)},t,e),toDoc:n=>mdToPmConverter(n,{assetLoad:this.editor.config.assetLoad,...this.config,urlRewriter:this.urlFromRewriter,hooks:this.hooks[`md2pm.post`],yaml:e.ci.resolve(`yaml`)},t)}};return n[`text/markdown`]=n[`text/x-markdown`],n}toMarkdown(e){return extPmToMdConverter(e,{sourceMap:!0,yaml:this.editor.ci.resolve(`yaml`)},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)]}},SVG=`http://www.w3.org/2000/svg`,XLINK=`http://www.w3.org/1999/xlink`,prefix=`kb-icon`;function hashPath(e){let t=Array.isArray(e)?e.map(e=>typeof e==`string`?e:e.d+(e.fill||``)).join(``):e,n=0;for(let e=0;e<t.length;e++)n=(n<<5)-n+t.charCodeAt(e)|0;return n.toString(16)}function getIcon(e,t){let n=(e.nodeType==9?e:e.ownerDocument)||document,r=n.createElement(`div`);if(r.className=prefix,t.path){let{path:a,width:o,height:s}=t,c=`pm-icon-`+hashPath(a);n.getElementById(c)||buildSVG(e,c,t);let l=r.appendChild(n.createElementNS(SVG,`svg`));l.style.width=o/s+`em`,l.appendChild(n.createElementNS(SVG,`use`)).setAttributeNS(XLINK,`href`,/([^#]*)/.exec(n.location.toString())[1]+`#`+c)}else if(t.dom)r.appendChild(t.dom.cloneNode(!0));else{let{text:e,css:a}=t;r.appendChild(n.createElement(`span`)).textContent=e||``,a&&(r.firstChild.style.cssText=a)}return r}function buildSVG(e,t,n){let[r,a]=e.nodeType==9?[e,e.body]:[e.ownerDocument||document,e],o=r.getElementById(`kb-icon-collection`);o||(o=r.createElementNS(SVG,`svg`),o.id=`kb-icon-collection`,o.style.display=`none`,a.insertBefore(o,a.firstChild));let s=r.createElementNS(SVG,`symbol`);s.id=t,s.setAttribute(`viewBox`,`0 0 `+n.width+` `+n.height);let c=Array.isArray(n.path)?n.path:[n.path];for(let e of c){let t=s.appendChild(r.createElementNS(SVG,`path`));typeof e==`string`?t.setAttribute(`d`,e):(t.setAttribute(`d`,e.d),e.fill&&t.setAttribute(`fill`,e.fill))}o.appendChild(s)}var icons={join:{width:24,height:24,path:`M16 13h-3V3h-2v10H8l4 4 4-4zM4 19v2h16v-2H4z`},lift:{width:24,height:24,path:`M11 4H3v2h8V4zm0 4H3v2h8V8zm0 4H3v2h8v-2zm3-3l-3 3 3 3v-2h4v-2h-4V9zm6 6H11v2h9v-2z`},selectParentNode:{width:24,height:24,path:`M3 5h2V3c-1.1 0-2 .9-2 2zm0 8h2v-2H3v2zm4 8h2v-2H7v2zM3 9h2V7H3v2zm10-6h-2v2h2V3zm6 0v2h2c0-1.1-.9-2-2-2zM5 21v-2H3c0 1.1.9 2 2 2zm-2-4h2v-2H3v2zM9 3H7v2h2V3zm2 18h2v-2h-2v2zm8-8h2v-2h-2v2zm0 8c1.1 0 2-.9 2-2h-2v2zm0-12h2V7h-2v2zm0 8h2v-2h-2v2zm-4 4h2v-2h-2v2zm0-16h2V3h-2v2z`},undo:{width:24,height:24,path:`M12.5 8c-2.65 0-5.05 1-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z`},redo:{width:24,height:24,path:`M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z`},strong:{width:24,height:24,path:`M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z`},em:{width:24,height:24,path:`M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z`},underline:{width:24,height:24,path:`M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z`},code:{width:24,height:24,path:`M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z`},link:{width:24,height:24,path:`M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z`},bulletList:{width:24,height:24,path:`M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z`},orderedList:{width:24,height:24,path:`M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z`},taskList:{width:24,height:24,path:`M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z`},blockquote:{width:24,height:24,path:`M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z`},insert:{width:24,height:24,path:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`},type:{width:24,height:24,path:`M5 4v3h5.5v12h3V7H19V4H5z`},table:{width:24,height:24,path:`M3 3v18h18V3H3zm8 16H5v-6h6v6zm0-8H5V5h6v6zm8 8h-6v-6h6v6zm0-8h-6V5h6v6z`},image:{width:24,height:24,path:`M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z`},horizontalRule:{width:24,height:24,path:`M4 11h16v2H4z`},heading:{width:24,height:24,path:`M6 4v16h2v-7h8v7h2V4h-2v7H8V4H6z`},strike:{width:24,height:24,path:`M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z`},highlight:{width:24,height:24,path:[`M17.75 7L14 3.25l-10 10V17h3.75l10-10zm2.96-2.96a.996.996 0 0 0 0-1.41L18.37.29a.996.996 0 0 0-1.41 0L15 2.25 18.75 6l1.96-1.96z`,{d:`M2 20h20v4H2z`,fill:`#FFEB3B`}]},indent:{width:24,height:24,path:`M3 21h18v-2H3v2zM3 8v8l4-4-4-4zm8 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z`},outdent:{width:24,height:24,path:`M3 21h18v-2H3v2zM7 8v8l-4-4 4-4zm4 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z`},superscript:{width:24,height:24,path:`M22 7h-2v1h3v1h-4V7c0-.55.45-1 1-1h2V5h-3V4h3c.55 0 1 .45 1 1v1c0 .55-.45 1-1 1zM5.88 20h2.66l3.4-5.42h.12l3.4 5.42h2.66l-4.65-7.27L17.81 6h-2.68l-3.07 4.99h-.12L8.87 6H6.19l4.32 6.73L5.88 20z`},subscript:{width:24,height:24,path:`M22 18h-2v1h3v1h-4v-2c0-.55.45-1 1-1h2v-1h-3v-1h3c.55 0 1 .45 1 1v1c0 .55-.45 1-1 1zM5.88 18h2.66l3.4-5.42h.12l3.4 5.42h2.66l-4.65-7.27L17.81 4h-2.68l-3.07 4.99h-.12L8.87 4H6.19l4.32 6.73L5.88 18z`},alignLeft:{width:24,height:24,path:`M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z`},alignCenter:{width:24,height:24,path:`M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z`},alignRight:{width:24,height:24,path:`M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z`},alignJustify:{width:24,height:24,path:`M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z`},folderOpen:{width:24,height:24,path:`M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V8h16v10z`}},MenuItem=class{spec;CSS_PREFIX=`kb-menu__button`;constructor(e){this.spec=e}render(e){let t=this.spec,n=t.render?t.render(e):null;if(!n){if(n=document.createElement(`button`),n.setAttribute(`type`,`button`),n.classList.add(this.CSS_PREFIX),t.icon){let r=getIcon(e.root,t.icon);n.appendChild(r),n.classList.add(this.CSS_PREFIX+`--icon-only`)}if(t.label){let r=document.createElement(`span`);r.appendChild(document.createTextNode(translate(e,t.label))),n.appendChild(r),t.icon&&n.classList.remove(this.CSS_PREFIX+`--icon-only`)}if(!t.icon&&!t.label)throw RangeError(`MenuItem without icon or label property`)}if(t.title){let r=typeof t.title==`function`?t.title(e.state):t.title;n.setAttribute(`title`,translate(e,r)),n.setAttribute(`aria-label`,translate(e,r))}return t.class&&n.classList.add(t.class),t.css&&(n.style.cssText+=t.css),n.addEventListener(`mousedown`,r=>{r.preventDefault(),n.classList.contains(this.CSS_PREFIX+`--disabled`)||t.run(e.state,e.dispatch)}),{dom:n,update:e=>{if(t.select){let r=t.select(e);if(n.style.display=r?``:`none`,!r)return!1}let r=!0;if(t.enable&&(r=t.enable(e)||!1,setClass(n,this.CSS_PREFIX+`--disabled`,!r),n.setAttribute(`aria-disabled`,(!r).toString())),t.active){let a=r&&t.active(e)||!1;setClass(n,this.CSS_PREFIX+`--active`,a),n.setAttribute(`aria-pressed`,a.toString())}return!0}}}};function translate(e,t){return e._props.translate?e._props.translate(t):t}var lastMenuEvent={time:0,node:null};function markMenuEvent(e){lastMenuEvent.time=Date.now(),lastMenuEvent.node=e.target}function isMenuEvent(e){return Date.now()-100<lastMenuEvent.time&&lastMenuEvent.node&&e.contains(lastMenuEvent.node)}var Dropdown=class{options;CSS_PREFIX=`kb-dropdown`;content;constructor(e,t={}){this.options=t,this.options=t||{},this.content=Array.isArray(e)?e:[e]}render(e){let t=renderDropdownItems(this.content,e),n=e.dom.ownerDocument.defaultView,r=document.createElement(`button`);if(r.setAttribute(`type`,`button`),r.classList.add(this.CSS_PREFIX+`__label`),this.options.class&&r.classList.add(this.options.class),this.options.css&&r.setAttribute(`style`,this.options.css),this.options.icon){let t=getIcon(e.root,this.options.icon);r.appendChild(t)}let a=translate(e,this.options.label||``);if(a){let e=document.createElement(`span`);e.classList.add(this.CSS_PREFIX+`__label-text`),e.textContent=a,r.appendChild(e)}let o=this.options.title?translate(e,this.options.title):a;o&&(r.setAttribute(`title`,o),r.setAttribute(`aria-label`,o)),r.setAttribute(`aria-haspopup`,`true`),r.setAttribute(`aria-expanded`,`false`);let s=document.createElement(`div`);s.classList.add(this.CSS_PREFIX),s.appendChild(r);let c=null,l=null,u=()=>{c&&c.close()&&(c=null,n?.removeEventListener(`mousedown`,l))};r.addEventListener(`mousedown`,e=>{e.preventDefault(),markMenuEvent(e),c?(u(),s.classList.remove(`kb-dropdown--open`)):(c=this.expand(s,t.dom),s.classList.add(`kb-dropdown--open`),n?.addEventListener(`mousedown`,l=()=>{isMenuEvent(s)||u()}))});function d(e){let n=t.update(e);return s.style.display=n?``:`none`,n}return{dom:s,update:d}}expand(e,t){let n=document.createElement(`div`);n.classList.add(`kb-dropdown__menu`),n.setAttribute(`role`,`menu`),this.options.class&&n.classList.add(this.options.class),t.forEach(e=>n.appendChild(e));let r=!1;function a(){return r?!1:(r=!0,e.removeChild(n),!0)}return e.appendChild(n),{close:a,node:n}}};function renderDropdownItems(e,t){let n=[],r=[];for(let a=0;a<e.length;a++){let{dom:o,update:s}=e[a].render(t),c=document.createElement(`div`);c.classList.add(`kb-dropdown__item`),c.appendChild(o),n.push(c),r.push(s)}return{dom:n,update:combineUpdates(r,n)}}function combineUpdates(e,t){return n=>{let r=!1;for(let a=0;a<e.length;a++){let o=e[a](n);t[a].style.display=o?``:`none`,o&&(r=!0)}return r}}function setClass(e,t,n){n?e.classList.add(t):e.classList.remove(t)}var CSS_PREFIX$1=`kb-prompt`;function openPrompt(e){let t=document.body.appendChild(document.createElement(`div`));t.className=`kb-prompt-backdrop`;let n=document.body.appendChild(document.createElement(`div`));n.className=CSS_PREFIX$1;let r=()=>{t.parentNode&&t.parentNode.removeChild(t),n.parentNode&&n.parentNode.removeChild(n)};t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r()});let a=[];for(let t in e.fields)a.push(e.fields[t].render());let o=document.createElement(`button`);o.type=`submit`,o.className=`kb-prompt--submit`,o.textContent=`OK`;let s=document.createElement(`button`);s.type=`button`,s.className=`kb-prompt--cancel`,s.textContent=`Cancel`,s.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r()});let c=n.appendChild(document.createElement(`form`));e.title&&(c.appendChild(document.createElement(`h5`)).textContent=e.title),a.forEach(e=>{c.appendChild(document.createElement(`div`)).appendChild(e)});let l=c.appendChild(document.createElement(`div`));l.className=`kb-prompt__buttons`,l.appendChild(o),l.appendChild(document.createTextNode(` `)),l.appendChild(s);let u=n.getBoundingClientRect();n.style.top=(globalThis.innerHeight-u.height)/2+`px`,n.style.left=(globalThis.innerWidth-u.width)/2+`px`;let d=()=>{let t=getValues(e.fields,a);t&&(r(),e.callback(t))};c.addEventListener(`submit`,e=>{e.preventDefault(),d()}),c.addEventListener(`keydown`,e=>{e.keyCode==27?(e.preventDefault(),r()):e.keyCode==13&&!(e.ctrlKey||e.metaKey||e.shiftKey)?(e.preventDefault(),d()):e.keyCode==9&&globalThis.setTimeout(()=>{n.contains(document.activeElement)||r()},500)});let f=c.elements[0];f&&f.focus()}function getValues(e,t){let n=Object.create(null),r=0;for(let a in e){let o=e[a],s=t[r++],c=o.read(s),l=o.validate(c);if(l)return reportInvalid(s,l),null;n[a]=o.clean(c)}return n}function reportInvalid(e,t){let n=e.parentNode,r=n.appendChild(document.createElement(`div`));r.style.left=e.offsetLeft+e.offsetWidth+2+`px`,r.style.top=e.offsetTop-5+`px`,r.className=`kb-invalid`,r.textContent=t,setTimeout(()=>n.removeChild(r),1500)}var Field=class{options;constructor(e){this.options=e}read(e){return e.value}validateType(e){return null}validate(e){return!e&&this.options.required?`Required field`:this.validateType(e)||(this.options.validate?this.options.validate(e):null)}clean(e){return this.options.clean?this.options.clean(e):e}},TextField=class extends Field{render(){let e=document.createElement(`input`);return e.type=`text`,e.placeholder=this.options.label,e.value=this.options.value||``,e.autocomplete=`off`,e}},FileField=class extends Field{dataUrl=``;render(){let e=document.createElement(`div`);e.className=`kb-prompt__file-field`;let t=document.createElement(`input`);t.type=`file`,t.accept=this.options.accept||`image/*`,t.className=`kb-prompt__file-input`;let n=document.createElement(`label`);n.className=`kb-prompt__file-label`,n.textContent=this.options.label;let r=document.createElement(`span`);return r.className=`kb-prompt__file-name`,r.textContent=`No file selected`,this.options.value&&(this.dataUrl=this.options.value,r.textContent=`Current image`),t.addEventListener(`change`,()=>{let n=t.files?.[0];if(n){r.textContent=n.name;let t=new FileReader;t.onload=t=>{this.dataUrl=t.target?.result,e._dataUrl=this.dataUrl},t.readAsDataURL(n)}}),e.appendChild(n),e.appendChild(t),e.appendChild(r),e._dataUrl=this.dataUrl,e}read(e){return e._dataUrl||``}validateType(e){return this.options.required&&!e?`Please select a file`:null}};function canInsert(e,t){let n=e.selection.$from;for(let e=n.depth;e>=0;e--){let r=n.index(e);if(n.node(e).canReplaceWith(r,r,t))return!0}return!1}function cmdItem(e,t){let n={label:t.title,run:e};for(let e in t)n[e]=t[e];return!t.enable&&!t.select&&(n[t.enable?`enable`:`select`]=t=>e(t)),new MenuItem(n)}function markActive(e,t){let{from:n,$from:r,to:a,empty:o}=e.selection;return o?!!t.isInSet(e.storedMarks||r.marks()):e.doc.rangeHasMark(n,a,t)}function buildMenu(e,t){function n(t,n){let r={active(e){return markActive(e,t)}};for(let e in n)r[e]=n[e];return cmdItem(e.commandFactories.toggleMark(t),r)}function r(t,n){let r={run(r,a){return e.commandFactories.wrapIn(t,n.attrs).apply({editor:e},[r,a])},select(r){return e.commandFactories.wrapIn(t,n.attrs).apply({editor:e},[r])}};for(let e in n)r[e]=n[e];return new MenuItem(r)}function a(t,n){let r=e.commandFactories.setBlockType(t,n.attrs),a={run:r,enable(t){return r.apply({editor:e},[t])},active(e){let{$from:r,to:a,node:o}=e.selection;return o?o.hasMarkup(t,n.attrs):a<=r.end()&&r.parent.hasMarkup(t,n.attrs)}};for(let e in n)a[e]=n[e];return new MenuItem(a)}let o=[];o.push(new MenuItem({title:`Undo last change`,run:(t,n)=>{let r=e.commandFactories.undo?.();return r?r.apply({editor:e},[t,n]):!1},enable:t=>{let n=e.commandFactories.undo?.();return n?n.apply({editor:e},[t]):!1},icon:icons.undo})),o.push(new MenuItem({title:`Redo last undone change`,run:(t,n)=>{let r=e.commandFactories.redo?.();return r?r.apply({editor:e},[t,n]):!1},enable:t=>{let n=e.commandFactories.redo?.();return n?n.apply({editor:e},[t]):!1},icon:icons.redo}));let s=[],c=[];if(t.nodes.paragraph&&c.push(a(t.nodes.paragraph,{title:`Change to paragraph`,label:`Plain`})),t.nodes.code_block&&c.push(a(t.nodes.code_block,{title:`Change to code block`,label:`Code`})),c.length>0&&s.push(new Dropdown(c,{label:`Type`,icon:icons.type})),t.nodes.heading){let e=[];for(let n=1;n<=6;n++)e.push(a(t.nodes.heading,{title:`Change to heading `+n,label:`Heading `+n,attrs:{level:n}}));s.push(new Dropdown(e,{label:`Heading`,icon:icons.heading}))}let l=[];t.nodes.bullet_list&&l.push(cmdItem(e.commandFactories.toggleBulletList(),{title:`Wrap in bullet list`,label:`Bullet List`,icon:icons.bulletList})),t.nodes.ordered_list&&l.push(cmdItem(e.commandFactories.toggleOrderedList(),{title:`Wrap in ordered list`,label:`Ordered List`,icon:icons.orderedList})),t.nodes.task_list&&l.push(cmdItem(e.commandFactories.toggleTaskList(),{title:`Wrap in task list`,label:`Task List`,icon:icons.taskList})),l.length>0&&s.push(new Dropdown(l,{label:`Lists`,icon:icons.bulletList})),s.push(new MenuItem({title:`Lift out of enclosing block`,run:()=>e.chain().lift().run(),select:()=>e.can().lift().run(),icon:icons.outdent})),t.nodes.blockquote&&s.push(r(t.nodes.blockquote,{title:`Wrap in block quote`,icon:icons.blockquote}));let u=[];if(t.marks.strong&&u.push(new MenuItem({title:`Toggle bold`,run:()=>e.chain().toggleStrong().run(),enable:t=>e.can().toggleStrong().run(),icon:icons.strong})),t.marks.em&&u.push(new MenuItem({title:`Toggle italic`,run:()=>e.chain().toggleItalic().run(),enable:t=>e.can().toggleItalic().run(),icon:icons.em})),t.marks.strike&&u.push(n(t.marks.strike,{title:`Toggle strikethrough`,icon:icons.strike})),t.marks.code&&u.push(n(t.marks.code,{title:`Toggle code font`,icon:icons.code})),t.marks.underline&&u.push(new MenuItem({title:`Toggle underline`,run:()=>e.chain().toggleUnderline().run(),enable:t=>e.can().toggleUnderline().run(),icon:icons.underline})),t.marks.highlight&&u.push(n(t.marks.highlight,{title:`Toggle highlight`,icon:icons.highlight})),t.marks.link){let n=t.marks.link;u.push(new MenuItem({title:`Add or remove link`,icon:icons.link,active(e){return markActive(e,n)},enable(e){return!e.selection.empty},run(t,r){return markActive(t,n)?(e.commandFactories.toggleMark(n).apply({editor:e},[t,r]),!0):(openPrompt({title:`Create a link`,fields:{href:new TextField({label:`Link target`,required:!0}),title:new TextField({label:`Title`})},callback(t){e.commandFactories.toggleMark(n,t).apply({editor:e},[e.view.state,e.view.dispatch]),e.view.focus()}}),!0)}}))}let d=[];t.marks.superscript&&d.push(n(t.marks.superscript,{title:`Toggle superscript`,icon:icons.superscript})),t.marks.subscript&&d.push(n(t.marks.subscript,{title:`Toggle subscript`,icon:icons.subscript}));let f=[];t.nodes.paragraph?.spec?.attrs?.textAlign!==void 0&&(f.push(new MenuItem({title:`Align left`,icon:icons.alignLeft,run:()=>e.chain().setTextAlignLeft().run(),enable:()=>e.can().setTextAlignLeft().run()})),f.push(new MenuItem({title:`Align center`,icon:icons.alignCenter,run:()=>e.chain().setTextAlignCenter().run(),enable:()=>e.can().setTextAlignCenter().run()})),f.push(new MenuItem({title:`Align right`,icon:icons.alignRight,run:()=>e.chain().setTextAlignRight().run(),enable:()=>e.can().setTextAlignRight().run()})),f.push(new MenuItem({title:`Justify`,icon:icons.alignJustify,run:()=>e.chain().setTextAlignJustify().run(),enable:()=>e.can().setTextAlignJustify().run()})));let p=[];if(t.nodes.image){let n=t.nodes.image;p.push(new MenuItem({title:`Insert image`,icon:icons.image,enable:e=>canInsert(e,n),run(t,r){let{from:a,to:o}=t.selection,s=null;return t.selection instanceof NodeSelection&&t.selection.node.type==n&&(s=t.selection.node.attrs),openPrompt({title:`Insert image`,fields:{src:new FileField({label:`Choose image`,required:!0,value:s&&s.src}),title:new TextField({label:`Title`,value:s&&s.title}),alt:new TextField({label:`Description`,value:s?s.alt:t.doc.textBetween(a,o,` `)})},callback(t){e.view.dispatch(e.view.state.tr.replaceSelectionWith(n.createAndFill(t))),e.view.focus()}}),!0}}))}if(t.nodes.hr&&p.push(new MenuItem({title:`Insert horizontal rule`,icon:icons.horizontalRule,run:()=>e.chain().setHorizontalRule().run(),enable:t=>e.can().setHorizontalRule().run()})),t.nodes.table){let t=(t,n)=>new MenuItem({label:t,enable:()=>e.can()[n]().run(),run:()=>e.chain()[n]().run()}),n=[t(`Insert table`,`insertTable`),t(`Insert column before`,`addColumnBefore`),t(`Insert column after`,`addColumnAfter`),t(`Delete column`,`deleteColumn`),t(`Insert row before`,`addRowBefore`),t(`Insert row after`,`addRowAfter`),t(`Delete row`,`deleteRow`),t(`Delete table`,`deleteTable`),t(`Merge cells`,`mergeCells`),t(`Split cell`,`splitCell`),t(`Toggle header column`,`toggleHeaderColumn`),t(`Toggle header row`,`toggleHeaderRow`),t(`Toggle header cells`,`toggleHeaderCell`)];p.push(new Dropdown(n,{label:`Table`,icon:icons.table}))}let m=[];return m.push(new MenuItem({title:`Select parent node`,run:()=>e.chain().selectParentNode().run(),select:()=>e.can().selectParentNode().run(),icon:icons.selectParentNode})),[o,s,u,d,f,p,m].filter(e=>e.length>0)}var CSS_PREFIX=`kb-custom-menu`,STORAGE_KEY=`kb-custom-menu-order`,OVERFLOW_BUTTON_WIDTH=48,DRAG_START_DELAY=2e3,CustomMenuView=class{editorView;editor;content;wrapper;toolbar;overflowMenu;pinnedDropdownMenu=null;tools=[];root;closeOverflowHandler=null;closePinnedDropdownHandler=null;keydownHandler=null;submenuStack=[];pinnedDropdownStack=[];resizeObserver=null;draggedItem=null;dragStartTimer=null;isDragging=!1;isDraggingFromOverflow=!1;dragPlaceholder=null;dragGhost=null;dragSourceWrapper=null;currentOverflowTools=[];defaultOrder=[];constructor(e,t,n){this.editorView=e,this.editor=t,this.content=n,this.root=e.root,this.wrapper=document.createElement(`div`),this.wrapper.classList.add(`kb-custom-menu__wrapper`),this.toolbar=document.createElement(`div`),this.toolbar.classList.add(CSS_PREFIX),this.toolbar.setAttribute(`role`,`toolbar`),this.wrapper.appendChild(this.toolbar),e.dom.parentNode&&e.dom.parentNode.replaceChild(this.wrapper,e.dom),this.wrapper.appendChild(e.dom),this.overflowMenu=document.createElement(`div`),this.overflowMenu.classList.add(`kb-custom-menu__overflow-menu`),this.overflowMenu.style.display=`none`,this.wrapper.insertBefore(this.overflowMenu,e.dom),e.dom.classList.add(`kb-custom-menu__editor`),this.initializeTools(),this.loadOrderState(),this.render(),typeof ResizeObserver<`u`&&(this.resizeObserver=new ResizeObserver(()=>{this.render()}),this.resizeObserver.observe(this.toolbar)),this.setupKeyboardNavigation()}closeAllMenus(e){if(this.overflowMenu.style.display!==`none`){this.overflowMenu.style.display=`none`,this.submenuStack=[];let e=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);e&&e.setAttribute(`aria-expanded`,`false`)}this.pinnedDropdownMenu&&(this.pinnedDropdownMenu.remove(),this.pinnedDropdownMenu=null,this.pinnedDropdownStack=[]),e&&e.focus()}getToolbarButtons(){let e=[];this.toolbar.querySelectorAll(`.kb-custom-menu__item`).forEach(t=>{let n=t.querySelector(`button`);n&&e.push(n)});let t=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);return t&&e.push(t),e}setupKeyboardNavigation(){this.keydownHandler=e=>{let t=document.activeElement,n=this.toolbar.contains(t),r=this.overflowMenu.contains(t),a=this.pinnedDropdownMenu?.contains(t);if(e.key===`Escape`){if(a||this.pinnedDropdownMenu){e.preventDefault();let t=this.toolbar.querySelector(`[data-last-focused="true"]`);this.closeAllMenus(t||void 0);return}if(r||this.overflowMenu.style.display!==`none`){e.preventDefault();let t=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);this.closeAllMenus(t||void 0);return}}if(n&&!r&&!a){let n=this.getToolbarButtons(),r=n.indexOf(t);e.key===`ArrowRight`?(e.preventDefault(),n[(r+1)%n.length]?.focus()):e.key===`ArrowLeft`?(e.preventDefault(),n[(r-1+n.length)%n.length]?.focus()):e.key===`Home`?(e.preventDefault(),n[0]?.focus()):e.key===`End`&&(e.preventDefault(),n[n.length-1]?.focus())}if(r){let n=Array.from(this.overflowMenu.querySelectorAll(`button, [role="menuitem"], .kb-custom-menu__overflow-item`)),r=n.indexOf(t);e.key===`ArrowDown`?(e.preventDefault(),n[(r+1)%n.length]?.focus()):e.key===`ArrowUp`&&(e.preventDefault(),n[(r-1+n.length)%n.length]?.focus())}},document.addEventListener(`keydown`,this.keydownHandler)}initializeTools(){let e=0;this.content.forEach((t,n)=>{t.forEach(t=>{let{dom:r,update:a}=t.render(this.editorView),o,s=t;o=s.options&&s.options.label?s.options.label:this.extractLabel(r);let c=this.generateStableId(o,r);this.tools.push({id:c,label:o,element:t,order:e++,groupIndex:n})})}),this.defaultOrder=this.tools.map(e=>e.id)}generateStableId(e,t){let n=t.getAttribute(`aria-label`),r=t.getAttribute(`data-id`);if(r)return`tool-${r}`;let a=n||e,o=a.toLowerCase().trim().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return o?`tool-${o}`:`tool-${this.simpleHash(a)}`}simpleHash(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t).toString(36)}extractLabel(e){return e.querySelector(`span`)?.textContent?.trim()||e.querySelector(`.kb-dropdown__label`)?.textContent?.trim()||e.getAttribute(`aria-label`)||e.getAttribute(`title`)||e.querySelector(`svg title`)?.textContent?.trim()||`Unknown Tool`}loadOrderState(){try{let e=localStorage.getItem(STORAGE_KEY);if(e){let t=JSON.parse(e);this.tools.forEach(e=>{let n=t.indexOf(e.id);n===-1?e.order=t.length+e.order:e.order=n}),this.tools.sort((e,t)=>e.order-t.order)}}catch(e){console.error(`Failed to load order state:`,e)}}saveOrderState(){try{let e=this.tools.map(e=>e.id);localStorage.setItem(STORAGE_KEY,JSON.stringify(e))}catch(e){console.error(`Failed to save order state:`,e)}}hasCustomOrder(){let e=this.tools.map(e=>e.id);return e.length===this.defaultOrder.length?e.some((e,t)=>e!==this.defaultOrder[t]):!0}resetToDefault(){try{localStorage.removeItem(STORAGE_KEY)}catch(e){console.error(`Failed to clear order state:`,e)}this.tools.forEach(e=>{let t=this.defaultOrder.indexOf(e.id);t!==-1&&(e.order=t)}),this.tools.sort((e,t)=>e.order-t.order),this.closeAllMenus(),this.render()}createResetButton(e){let t=document.createElement(`button`);t.type=`button`,t.classList.add(`kb-custom-menu__reset-button`),e?(t.classList.add(`kb-custom-menu__reset-button--icon-only`),t.setAttribute(`role`,`button`)):t.setAttribute(`role`,`menuitem`),t.setAttribute(`tabindex`,`0`),t.setAttribute(`aria-label`,`Reset toolbar to default order`),t.title=`Reset toolbar to default order`;let n=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
185
+ `)&&a>-1){let n=t.yaml?.parse(e.substring(4,a))||void 0;r.attrs={...r.attrs,meta:n}}}}},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}}},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 PositionMapper=class{rawTextMap;rawTextArr;doc;constructor(e,t){this.rawTextMap=t,this.doc=e.state.doc,this.rawTextArr=[];for(let e of t)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 e=0;e<this.rawTextArr.length;e++){let t=e+1;t<this.rawTextArr.length?this.rawTextArr[e].maxNodeIdx=this.rawTextArr[t].nodeIdx-1:this.rawTextArr[e].maxNodeIdx=this.doc.nodeSize}}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}toRawTextLspPos(e){for(let t=0;t<this.rawTextArr.length;t++){let n=this.rawTextArr[t];if(e>=n.nodeIdx&&e<=n.maxNodeIdx)return{line:n.targetRow,character:n.targetCol+e-n.nodeIdx}}return{line:0,character: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}},MarkdownPluginState=class{editor;extensionMarkdown;capturing=!1;constructor(e,t){this.editor=e,this.extensionMarkdown=t,this.performSnapshot=debounce$1(this.performSnapshot.bind(this),800)}snapshot;async performSnapshot(){let e=this.editor,t=e.version;if(t===this.snapshot?.version)return;let n=await this.extensionMarkdown.toMarkdown(e.state.doc);e.version;let r=new PositionMapper(e,n.rawTextMap);this.snapshot={markdownResult:n,version:t,mapper:r},this.dispatchMeta({snapshot:this.snapshot})}dispatchMeta(e){let t=this.editor.state.tr;t.setMeta(`markdown`,e),this.editor.dispatchTransaction(t)}};function createMarkdownPlugin(e,t){return t.version,new Plugin({state:{init(){return new MarkdownPluginState(t,e)},apply(e,t,n,r){return e.docChanged&&t.capturing&&t.performSnapshot(),t}}})}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`],yaml:e.ci.resolve(`yaml`)},t,e),toDoc:n=>mdToPmConverter(n,{assetLoad:this.editor.config.assetLoad,...this.config,urlRewriter:this.urlFromRewriter,hooks:this.hooks[`md2pm.post`],yaml:e.ci.resolve(`yaml`)},t)}};return n[`text/markdown`]=n[`text/x-markdown`],n}toMarkdown(e){return extPmToMdConverter(e,{sourceMap:!0,yaml:this.editor.ci.resolve(`yaml`)},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)]}},SVG=`http://www.w3.org/2000/svg`,XLINK=`http://www.w3.org/1999/xlink`,prefix=`kb-icon`;function hashPath(e){let t=Array.isArray(e)?e.map(e=>typeof e==`string`?e:e.d+(e.fill||``)).join(``):e,n=0;for(let e=0;e<t.length;e++)n=(n<<5)-n+t.charCodeAt(e)|0;return n.toString(16)}function getIcon(e,t){let n=(e.nodeType==9?e:e.ownerDocument)||document,r=n.createElement(`div`);if(r.className=prefix,t.path){let{path:a,width:o,height:s}=t,c=`pm-icon-`+hashPath(a);n.getElementById(c)||buildSVG(e,c,t);let l=r.appendChild(n.createElementNS(SVG,`svg`));l.style.width=o/s+`em`,l.appendChild(n.createElementNS(SVG,`use`)).setAttributeNS(XLINK,`href`,/([^#]*)/.exec(n.location.toString())[1]+`#`+c)}else if(t.dom)r.appendChild(t.dom.cloneNode(!0));else{let{text:e,css:a}=t;r.appendChild(n.createElement(`span`)).textContent=e||``,a&&(r.firstChild.style.cssText=a)}return r}function buildSVG(e,t,n){let[r,a]=e.nodeType==9?[e,e.body]:[e.ownerDocument||document,e],o=r.getElementById(`kb-icon-collection`);o||(o=r.createElementNS(SVG,`svg`),o.id=`kb-icon-collection`,o.style.display=`none`,a.insertBefore(o,a.firstChild));let s=r.createElementNS(SVG,`symbol`);s.id=t,s.setAttribute(`viewBox`,`0 0 `+n.width+` `+n.height);let c=Array.isArray(n.path)?n.path:[n.path];for(let e of c){let t=s.appendChild(r.createElementNS(SVG,`path`));typeof e==`string`?t.setAttribute(`d`,e):(t.setAttribute(`d`,e.d),e.fill&&t.setAttribute(`fill`,e.fill))}o.appendChild(s)}var icons={join:{width:24,height:24,path:`M16 13h-3V3h-2v10H8l4 4 4-4zM4 19v2h16v-2H4z`},lift:{width:24,height:24,path:`M11 4H3v2h8V4zm0 4H3v2h8V8zm0 4H3v2h8v-2zm3-3l-3 3 3 3v-2h4v-2h-4V9zm6 6H11v2h9v-2z`},selectParentNode:{width:24,height:24,path:`M3 5h2V3c-1.1 0-2 .9-2 2zm0 8h2v-2H3v2zm4 8h2v-2H7v2zM3 9h2V7H3v2zm10-6h-2v2h2V3zm6 0v2h2c0-1.1-.9-2-2-2zM5 21v-2H3c0 1.1.9 2 2 2zm-2-4h2v-2H3v2zM9 3H7v2h2V3zm2 18h2v-2h-2v2zm8-8h2v-2h-2v2zm0 8c1.1 0 2-.9 2-2h-2v2zm0-12h2V7h-2v2zm0 8h2v-2h-2v2zm-4 4h2v-2h-2v2zm0-16h2V3h-2v2z`},undo:{width:24,height:24,path:`M12.5 8c-2.65 0-5.05 1-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z`},redo:{width:24,height:24,path:`M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z`},strong:{width:24,height:24,path:`M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z`},em:{width:24,height:24,path:`M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z`},underline:{width:24,height:24,path:`M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z`},code:{width:24,height:24,path:`M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z`},link:{width:24,height:24,path:`M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z`},bulletList:{width:24,height:24,path:`M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z`},orderedList:{width:24,height:24,path:`M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z`},taskList:{width:24,height:24,path:`M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z`},blockquote:{width:24,height:24,path:`M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z`},insert:{width:24,height:24,path:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`},type:{width:24,height:24,path:`M5 4v3h5.5v12h3V7H19V4H5z`},table:{width:24,height:24,path:`M3 3v18h18V3H3zm8 16H5v-6h6v6zm0-8H5V5h6v6zm8 8h-6v-6h6v6zm0-8h-6V5h6v6z`},image:{width:24,height:24,path:`M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z`},horizontalRule:{width:24,height:24,path:`M4 11h16v2H4z`},heading:{width:24,height:24,path:`M6 4v16h2v-7h8v7h2V4h-2v7H8V4H6z`},strike:{width:24,height:24,path:`M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z`},highlight:{width:24,height:24,path:[`M17.75 7L14 3.25l-10 10V17h3.75l10-10zm2.96-2.96a.996.996 0 0 0 0-1.41L18.37.29a.996.996 0 0 0-1.41 0L15 2.25 18.75 6l1.96-1.96z`,{d:`M2 20h20v4H2z`,fill:`#FFEB3B`}]},indent:{width:24,height:24,path:`M3 21h18v-2H3v2zM3 8v8l4-4-4-4zm8 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z`},outdent:{width:24,height:24,path:`M3 21h18v-2H3v2zM7 8v8l-4-4 4-4zm4 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z`},superscript:{width:24,height:24,path:`M22 7h-2v1h3v1h-4V7c0-.55.45-1 1-1h2V5h-3V4h3c.55 0 1 .45 1 1v1c0 .55-.45 1-1 1zM5.88 20h2.66l3.4-5.42h.12l3.4 5.42h2.66l-4.65-7.27L17.81 6h-2.68l-3.07 4.99h-.12L8.87 6H6.19l4.32 6.73L5.88 20z`},subscript:{width:24,height:24,path:`M22 18h-2v1h3v1h-4v-2c0-.55.45-1 1-1h2v-1h-3v-1h3c.55 0 1 .45 1 1v1c0 .55-.45 1-1 1zM5.88 18h2.66l3.4-5.42h.12l3.4 5.42h2.66l-4.65-7.27L17.81 4h-2.68l-3.07 4.99h-.12L8.87 4H6.19l4.32 6.73L5.88 18z`},alignLeft:{width:24,height:24,path:`M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z`},alignCenter:{width:24,height:24,path:`M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z`},alignRight:{width:24,height:24,path:`M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z`},alignJustify:{width:24,height:24,path:`M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z`},folderOpen:{width:24,height:24,path:`M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V8h16v10z`}},MenuItem=class{spec;CSS_PREFIX=`kb-menu__button`;constructor(e){this.spec=e}render(e){let t=this.spec,n=t.render?t.render(e):null;if(!n){if(n=document.createElement(`button`),n.setAttribute(`type`,`button`),n.classList.add(this.CSS_PREFIX),t.icon){let r=getIcon(e.root,t.icon);n.appendChild(r),n.classList.add(this.CSS_PREFIX+`--icon-only`)}if(t.label){let r=document.createElement(`span`);r.appendChild(document.createTextNode(translate(e,t.label))),n.appendChild(r),t.icon&&n.classList.remove(this.CSS_PREFIX+`--icon-only`)}if(!t.icon&&!t.label)throw RangeError(`MenuItem without icon or label property`)}if(t.title){let r=typeof t.title==`function`?t.title(e.state):t.title;n.setAttribute(`title`,translate(e,r)),n.setAttribute(`aria-label`,translate(e,r))}return t.class&&n.classList.add(t.class),t.css&&(n.style.cssText+=t.css),n.addEventListener(`mousedown`,r=>{r.preventDefault(),n.classList.contains(this.CSS_PREFIX+`--disabled`)||t.run(e.state,e.dispatch)}),{dom:n,update:e=>{if(t.select){let r=t.select(e);if(n.style.display=r?``:`none`,!r)return!1}let r=!0;if(t.enable&&(r=t.enable(e)||!1,setClass(n,this.CSS_PREFIX+`--disabled`,!r),n.setAttribute(`aria-disabled`,(!r).toString())),t.active){let a=r&&t.active(e)||!1;setClass(n,this.CSS_PREFIX+`--active`,a),n.setAttribute(`aria-pressed`,a.toString())}return!0}}}};function translate(e,t){return e._props.translate?e._props.translate(t):t}var lastMenuEvent={time:0,node:null};function markMenuEvent(e){lastMenuEvent.time=Date.now(),lastMenuEvent.node=e.target}function isMenuEvent(e){return Date.now()-100<lastMenuEvent.time&&lastMenuEvent.node&&e.contains(lastMenuEvent.node)}var Dropdown=class{options;CSS_PREFIX=`kb-dropdown`;content;constructor(e,t={}){this.options=t,this.options=t||{},this.content=Array.isArray(e)?e:[e]}render(e){let t=renderDropdownItems(this.content,e),n=e.dom.ownerDocument.defaultView,r=document.createElement(`button`);if(r.setAttribute(`type`,`button`),r.classList.add(this.CSS_PREFIX+`__label`),this.options.class&&r.classList.add(this.options.class),this.options.css&&r.setAttribute(`style`,this.options.css),this.options.icon){let t=getIcon(e.root,this.options.icon);r.appendChild(t)}let a=translate(e,this.options.label||``);if(a){let e=document.createElement(`span`);e.classList.add(this.CSS_PREFIX+`__label-text`),e.textContent=a,r.appendChild(e)}let o=this.options.title?translate(e,this.options.title):a;o&&(r.setAttribute(`title`,o),r.setAttribute(`aria-label`,o)),r.setAttribute(`aria-haspopup`,`true`),r.setAttribute(`aria-expanded`,`false`);let s=document.createElement(`div`);s.classList.add(this.CSS_PREFIX),s.appendChild(r);let c=null,l=null,u=()=>{c&&c.close()&&(c=null,n?.removeEventListener(`mousedown`,l))};r.addEventListener(`mousedown`,e=>{e.preventDefault(),markMenuEvent(e),c?(u(),s.classList.remove(`kb-dropdown--open`)):(c=this.expand(s,t.dom),s.classList.add(`kb-dropdown--open`),n?.addEventListener(`mousedown`,l=()=>{isMenuEvent(s)||u()}))});function d(e){let n=t.update(e);return s.style.display=n?``:`none`,n}return{dom:s,update:d}}expand(e,t){let n=document.createElement(`div`);n.classList.add(`kb-dropdown__menu`),n.setAttribute(`role`,`menu`),this.options.class&&n.classList.add(this.options.class),t.forEach(e=>n.appendChild(e));let r=!1;function a(){return r?!1:(r=!0,e.removeChild(n),!0)}return e.appendChild(n),{close:a,node:n}}};function renderDropdownItems(e,t){let n=[],r=[];for(let a=0;a<e.length;a++){let{dom:o,update:s}=e[a].render(t),c=document.createElement(`div`);c.classList.add(`kb-dropdown__item`),c.appendChild(o),n.push(c),r.push(s)}return{dom:n,update:combineUpdates(r,n)}}function combineUpdates(e,t){return n=>{let r=!1;for(let a=0;a<e.length;a++){let o=e[a](n);t[a].style.display=o?``:`none`,o&&(r=!0)}return r}}function setClass(e,t,n){n?e.classList.add(t):e.classList.remove(t)}var CSS_PREFIX$1=`kb-prompt`;function openPrompt(e){let t=document.body.appendChild(document.createElement(`div`));t.className=`kb-prompt-backdrop`;let n=document.body.appendChild(document.createElement(`div`));n.className=CSS_PREFIX$1;let r=()=>{t.parentNode&&t.parentNode.removeChild(t),n.parentNode&&n.parentNode.removeChild(n)};t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r()});let a=[];for(let t in e.fields)a.push(e.fields[t].render());let o=document.createElement(`button`);o.type=`submit`,o.className=`kb-prompt--submit`,o.textContent=`OK`;let s=document.createElement(`button`);s.type=`button`,s.className=`kb-prompt--cancel`,s.textContent=`Cancel`,s.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r()});let c=n.appendChild(document.createElement(`form`));e.title&&(c.appendChild(document.createElement(`h5`)).textContent=e.title),a.forEach(e=>{c.appendChild(document.createElement(`div`)).appendChild(e)});let l=c.appendChild(document.createElement(`div`));l.className=`kb-prompt__buttons`,l.appendChild(o),l.appendChild(document.createTextNode(` `)),l.appendChild(s);let u=n.getBoundingClientRect();n.style.top=(globalThis.innerHeight-u.height)/2+`px`,n.style.left=(globalThis.innerWidth-u.width)/2+`px`;let d=()=>{let t=getValues(e.fields,a);t&&(r(),e.callback(t))};c.addEventListener(`submit`,e=>{e.preventDefault(),d()}),c.addEventListener(`keydown`,e=>{e.keyCode==27?(e.preventDefault(),r()):e.keyCode==13&&!(e.ctrlKey||e.metaKey||e.shiftKey)?(e.preventDefault(),d()):e.keyCode==9&&globalThis.setTimeout(()=>{n.contains(document.activeElement)||r()},500)});let f=c.elements[0];f&&f.focus()}function getValues(e,t){let n=Object.create(null),r=0;for(let a in e){let o=e[a],s=t[r++],c=o.read(s),l=o.validate(c);if(l)return reportInvalid(s,l),null;n[a]=o.clean(c)}return n}function reportInvalid(e,t){let n=e.parentNode,r=n.appendChild(document.createElement(`div`));r.style.left=e.offsetLeft+e.offsetWidth+2+`px`,r.style.top=e.offsetTop-5+`px`,r.className=`kb-invalid`,r.textContent=t,setTimeout(()=>n.removeChild(r),1500)}var Field=class{options;constructor(e){this.options=e}read(e){return e.value}validateType(e){return null}validate(e){return!e&&this.options.required?`Required field`:this.validateType(e)||(this.options.validate?this.options.validate(e):null)}clean(e){return this.options.clean?this.options.clean(e):e}},TextField=class extends Field{render(){let e=document.createElement(`input`);return e.type=`text`,e.placeholder=this.options.label,e.value=this.options.value||``,e.autocomplete=`off`,e}},FileField=class extends Field{dataUrl=``;render(){let e=document.createElement(`div`);e.className=`kb-prompt__file-field`;let t=document.createElement(`input`);t.type=`file`,t.accept=this.options.accept||`image/*`,t.className=`kb-prompt__file-input`;let n=document.createElement(`label`);n.className=`kb-prompt__file-label`,n.textContent=this.options.label;let r=document.createElement(`span`);return r.className=`kb-prompt__file-name`,r.textContent=`No file selected`,this.options.value&&(this.dataUrl=this.options.value,r.textContent=`Current image`),t.addEventListener(`change`,()=>{let n=t.files?.[0];if(n){r.textContent=n.name;let t=new FileReader;t.onload=t=>{this.dataUrl=t.target?.result,e._dataUrl=this.dataUrl},t.readAsDataURL(n)}}),e.appendChild(n),e.appendChild(t),e.appendChild(r),e._dataUrl=this.dataUrl,e}read(e){return e._dataUrl||``}validateType(e){return this.options.required&&!e?`Please select a file`:null}};function canInsert(e,t){let n=e.selection.$from;for(let e=n.depth;e>=0;e--){let r=n.index(e);if(n.node(e).canReplaceWith(r,r,t))return!0}return!1}function cmdItem(e,t){let n={label:t.title,run:e};for(let e in t)n[e]=t[e];return!t.enable&&!t.select&&(n[t.enable?`enable`:`select`]=t=>e(t)),new MenuItem(n)}function markActive(e,t){let{from:n,$from:r,to:a,empty:o}=e.selection;return o?!!t.isInSet(e.storedMarks||r.marks()):e.doc.rangeHasMark(n,a,t)}function buildMenu(e,t){function n(t,n){let r={active(e){return markActive(e,t)}};for(let e in n)r[e]=n[e];return cmdItem(e.commandFactories.toggleMark(t),r)}function r(t,n){let r={run(r,a){return e.commandFactories.wrapIn(t,n.attrs).apply({editor:e},[r,a])},select(r){return e.commandFactories.wrapIn(t,n.attrs).apply({editor:e},[r])}};for(let e in n)r[e]=n[e];return new MenuItem(r)}function a(t,n){let r=e.commandFactories.setBlockType(t,n.attrs),a={run:r,enable(t){return r.apply({editor:e},[t])},active(e){let{$from:r,to:a,node:o}=e.selection;return o?o.hasMarkup(t,n.attrs):a<=r.end()&&r.parent.hasMarkup(t,n.attrs)}};for(let e in n)a[e]=n[e];return new MenuItem(a)}let o=[];o.push(new MenuItem({title:`Undo last change`,run:(t,n)=>{let r=e.commandFactories.undo?.();return r?r.apply({editor:e},[t,n]):!1},enable:t=>{let n=e.commandFactories.undo?.();return n?n.apply({editor:e},[t]):!1},icon:icons.undo})),o.push(new MenuItem({title:`Redo last undone change`,run:(t,n)=>{let r=e.commandFactories.redo?.();return r?r.apply({editor:e},[t,n]):!1},enable:t=>{let n=e.commandFactories.redo?.();return n?n.apply({editor:e},[t]):!1},icon:icons.redo}));let s=[],c=[];if(t.nodes.paragraph&&c.push(a(t.nodes.paragraph,{title:`Change to paragraph`,label:`Plain`})),t.nodes.code_block&&c.push(a(t.nodes.code_block,{title:`Change to code block`,label:`Code`})),c.length>0&&s.push(new Dropdown(c,{label:`Type`,icon:icons.type})),t.nodes.heading){let e=[];for(let n=1;n<=6;n++)e.push(a(t.nodes.heading,{title:`Change to heading `+n,label:`Heading `+n,attrs:{level:n}}));s.push(new Dropdown(e,{label:`Heading`,icon:icons.heading}))}let l=[];t.nodes.bullet_list&&l.push(cmdItem(e.commandFactories.toggleBulletList(),{title:`Wrap in bullet list`,label:`Bullet List`,icon:icons.bulletList})),t.nodes.ordered_list&&l.push(cmdItem(e.commandFactories.toggleOrderedList(),{title:`Wrap in ordered list`,label:`Ordered List`,icon:icons.orderedList})),t.nodes.task_list&&l.push(cmdItem(e.commandFactories.toggleTaskList(),{title:`Wrap in task list`,label:`Task List`,icon:icons.taskList})),l.length>0&&s.push(new Dropdown(l,{label:`Lists`,icon:icons.bulletList})),s.push(new MenuItem({title:`Lift out of enclosing block`,run:()=>e.chain().lift().run(),select:()=>e.can().lift().run(),icon:icons.outdent})),t.nodes.blockquote&&s.push(r(t.nodes.blockquote,{title:`Wrap in block quote`,icon:icons.blockquote}));let u=[];if(t.marks.strong&&u.push(new MenuItem({title:`Toggle bold`,run:()=>e.chain().toggleStrong().run(),enable:t=>e.can().toggleStrong().run(),icon:icons.strong})),t.marks.em&&u.push(new MenuItem({title:`Toggle italic`,run:()=>e.chain().toggleItalic().run(),enable:t=>e.can().toggleItalic().run(),icon:icons.em})),t.marks.strike&&u.push(n(t.marks.strike,{title:`Toggle strikethrough`,icon:icons.strike})),t.marks.code&&u.push(n(t.marks.code,{title:`Toggle code font`,icon:icons.code})),t.marks.underline&&u.push(new MenuItem({title:`Toggle underline`,run:()=>e.chain().toggleUnderline().run(),enable:t=>e.can().toggleUnderline().run(),icon:icons.underline})),t.marks.highlight&&u.push(n(t.marks.highlight,{title:`Toggle highlight`,icon:icons.highlight})),t.marks.link){let n=t.marks.link;u.push(new MenuItem({title:`Add or remove link`,icon:icons.link,active(e){return markActive(e,n)},enable(e){return!e.selection.empty},run(t,r){return markActive(t,n)?(e.commandFactories.toggleMark(n).apply({editor:e},[t,r]),!0):(openPrompt({title:`Create a link`,fields:{href:new TextField({label:`Link target`,required:!0}),title:new TextField({label:`Title`})},callback(t){e.commandFactories.toggleMark(n,t).apply({editor:e},[e.view.state,e.view.dispatch]),e.view.focus()}}),!0)}}))}let d=[];t.marks.superscript&&d.push(n(t.marks.superscript,{title:`Toggle superscript`,icon:icons.superscript})),t.marks.subscript&&d.push(n(t.marks.subscript,{title:`Toggle subscript`,icon:icons.subscript}));let f=[];t.nodes.paragraph?.spec?.attrs?.textAlign!==void 0&&(f.push(new MenuItem({title:`Align left`,icon:icons.alignLeft,run:()=>e.chain().setTextAlignLeft().run(),enable:()=>e.can().setTextAlignLeft().run()})),f.push(new MenuItem({title:`Align center`,icon:icons.alignCenter,run:()=>e.chain().setTextAlignCenter().run(),enable:()=>e.can().setTextAlignCenter().run()})),f.push(new MenuItem({title:`Align right`,icon:icons.alignRight,run:()=>e.chain().setTextAlignRight().run(),enable:()=>e.can().setTextAlignRight().run()})),f.push(new MenuItem({title:`Justify`,icon:icons.alignJustify,run:()=>e.chain().setTextAlignJustify().run(),enable:()=>e.can().setTextAlignJustify().run()})));let p=[];if(t.nodes.image){let n=t.nodes.image;p.push(new MenuItem({title:`Insert image`,icon:icons.image,enable:e=>canInsert(e,n),run(t,r){let{from:a,to:o}=t.selection,s=null;return t.selection instanceof NodeSelection&&t.selection.node.type==n&&(s=t.selection.node.attrs),openPrompt({title:`Insert image`,fields:{src:new FileField({label:`Choose image`,required:!0,value:s&&s.src}),title:new TextField({label:`Title`,value:s&&s.title}),alt:new TextField({label:`Description`,value:s?s.alt:t.doc.textBetween(a,o,` `)})},callback(t){e.view.dispatch(e.view.state.tr.replaceSelectionWith(n.createAndFill(t))),e.view.focus()}}),!0}}))}if(t.nodes.hr&&p.push(new MenuItem({title:`Insert horizontal rule`,icon:icons.horizontalRule,run:()=>e.chain().setHorizontalRule().run(),enable:t=>e.can().setHorizontalRule().run()})),t.nodes.table){let t=(t,n)=>new MenuItem({label:t,enable:()=>e.can()[n]().run(),run:()=>e.chain()[n]().run()}),n=[t(`Insert table`,`insertTable`),t(`Insert column before`,`addColumnBefore`),t(`Insert column after`,`addColumnAfter`),t(`Delete column`,`deleteColumn`),t(`Insert row before`,`addRowBefore`),t(`Insert row after`,`addRowAfter`),t(`Delete row`,`deleteRow`),t(`Delete table`,`deleteTable`),t(`Merge cells`,`mergeCells`),t(`Split cell`,`splitCell`),t(`Toggle header column`,`toggleHeaderColumn`),t(`Toggle header row`,`toggleHeaderRow`),t(`Toggle header cells`,`toggleHeaderCell`)];p.push(new Dropdown(n,{label:`Table`,icon:icons.table}))}let m=[];return m.push(new MenuItem({title:`Select parent node`,run:()=>e.chain().selectParentNode().run(),select:()=>e.can().selectParentNode().run(),icon:icons.selectParentNode})),[o,s,u,d,f,p,m].filter(e=>e.length>0)}var CSS_PREFIX=`kb-custom-menu`,STORAGE_KEY=`kb-custom-menu-order`,OVERFLOW_BUTTON_WIDTH=48,DRAG_START_DELAY=2e3,CustomMenuView=class{editorView;editor;content;wrapper;toolbar;overflowMenu;pinnedDropdownMenu=null;tools=[];root;closeOverflowHandler=null;closePinnedDropdownHandler=null;keydownHandler=null;submenuStack=[];pinnedDropdownStack=[];resizeObserver=null;draggedItem=null;dragStartTimer=null;isDragging=!1;isDraggingFromOverflow=!1;dragPlaceholder=null;dragGhost=null;dragSourceWrapper=null;currentOverflowTools=[];defaultOrder=[];constructor(e,t,n){this.editorView=e,this.editor=t,this.content=n,this.root=e.root,this.wrapper=document.createElement(`div`),this.wrapper.classList.add(`kb-custom-menu__wrapper`),this.toolbar=document.createElement(`div`),this.toolbar.classList.add(CSS_PREFIX),this.toolbar.setAttribute(`role`,`toolbar`),this.wrapper.appendChild(this.toolbar),e.dom.parentNode&&e.dom.parentNode.replaceChild(this.wrapper,e.dom),this.wrapper.appendChild(e.dom),this.overflowMenu=document.createElement(`div`),this.overflowMenu.classList.add(`kb-custom-menu__overflow-menu`),this.overflowMenu.style.display=`none`,this.wrapper.insertBefore(this.overflowMenu,e.dom),e.dom.classList.add(`kb-custom-menu__editor`),this.initializeTools(),this.loadOrderState(),this.render(),typeof ResizeObserver<`u`&&(this.resizeObserver=new ResizeObserver(()=>{this.render()}),this.resizeObserver.observe(this.toolbar)),this.setupKeyboardNavigation()}closeAllMenus(e){if(this.overflowMenu.style.display!==`none`){this.overflowMenu.style.display=`none`,this.submenuStack=[];let e=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);e&&e.setAttribute(`aria-expanded`,`false`)}this.pinnedDropdownMenu&&(this.pinnedDropdownMenu.remove(),this.pinnedDropdownMenu=null,this.pinnedDropdownStack=[]),e&&e.focus()}getToolbarButtons(){let e=[];this.toolbar.querySelectorAll(`.kb-custom-menu__item`).forEach(t=>{let n=t.querySelector(`button`);n&&e.push(n)});let t=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);return t&&e.push(t),e}setupKeyboardNavigation(){this.keydownHandler=e=>{let t=document.activeElement,n=this.toolbar.contains(t),r=this.overflowMenu.contains(t),a=this.pinnedDropdownMenu?.contains(t);if(e.key===`Escape`){if(a||this.pinnedDropdownMenu){e.preventDefault();let t=this.toolbar.querySelector(`[data-last-focused="true"]`);this.closeAllMenus(t||void 0);return}if(r||this.overflowMenu.style.display!==`none`){e.preventDefault();let t=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);this.closeAllMenus(t||void 0);return}}if(n&&!r&&!a){let n=this.getToolbarButtons(),r=n.indexOf(t);e.key===`ArrowRight`?(e.preventDefault(),n[(r+1)%n.length]?.focus()):e.key===`ArrowLeft`?(e.preventDefault(),n[(r-1+n.length)%n.length]?.focus()):e.key===`Home`?(e.preventDefault(),n[0]?.focus()):e.key===`End`&&(e.preventDefault(),n[n.length-1]?.focus())}if(r){let n=Array.from(this.overflowMenu.querySelectorAll(`button, [role="menuitem"], .kb-custom-menu__overflow-item`)),r=n.indexOf(t);e.key===`ArrowDown`?(e.preventDefault(),n[(r+1)%n.length]?.focus()):e.key===`ArrowUp`&&(e.preventDefault(),n[(r-1+n.length)%n.length]?.focus())}},document.addEventListener(`keydown`,this.keydownHandler)}initializeTools(){let e=0;this.content.forEach((t,n)=>{t.forEach(t=>{let{dom:r,update:a}=t.render(this.editorView),o,s=t;o=s.options&&s.options.label?s.options.label:this.extractLabel(r);let c=this.generateStableId(o,r);this.tools.push({id:c,label:o,element:t,order:e++,groupIndex:n})})}),this.defaultOrder=this.tools.map(e=>e.id)}generateStableId(e,t){let n=t.getAttribute(`aria-label`),r=t.getAttribute(`data-id`);if(r)return`tool-${r}`;let a=n||e,o=a.toLowerCase().trim().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return o?`tool-${o}`:`tool-${this.simpleHash(a)}`}simpleHash(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t).toString(36)}extractLabel(e){return e.querySelector(`span`)?.textContent?.trim()||e.querySelector(`.kb-dropdown__label`)?.textContent?.trim()||e.getAttribute(`aria-label`)||e.getAttribute(`title`)||e.querySelector(`svg title`)?.textContent?.trim()||`Unknown Tool`}loadOrderState(){try{let e=localStorage.getItem(STORAGE_KEY);if(e){let t=JSON.parse(e);this.tools.forEach(e=>{let n=t.indexOf(e.id);n===-1?e.order=t.length+e.order:e.order=n}),this.tools.sort((e,t)=>e.order-t.order)}}catch(e){console.error(`Failed to load order state:`,e)}}saveOrderState(){try{let e=this.tools.map(e=>e.id);localStorage.setItem(STORAGE_KEY,JSON.stringify(e))}catch(e){console.error(`Failed to save order state:`,e)}}hasCustomOrder(){let e=this.tools.map(e=>e.id);return e.length===this.defaultOrder.length?e.some((e,t)=>e!==this.defaultOrder[t]):!0}resetToDefault(){try{localStorage.removeItem(STORAGE_KEY)}catch(e){console.error(`Failed to clear order state:`,e)}this.tools.forEach(e=>{let t=this.defaultOrder.indexOf(e.id);t!==-1&&(e.order=t)}),this.tools.sort((e,t)=>e.order-t.order),this.closeAllMenus(),this.render()}createResetButton(e){let t=document.createElement(`button`);t.type=`button`,t.classList.add(`kb-custom-menu__reset-button`),e?(t.classList.add(`kb-custom-menu__reset-button--icon-only`),t.setAttribute(`role`,`button`)):t.setAttribute(`role`,`menuitem`),t.setAttribute(`tabindex`,`0`),t.setAttribute(`aria-label`,`Reset toolbar to default order`),t.title=`Reset toolbar to default order`;let n=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
185
186
  <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
186
187
  <path d="M3 3v5h5"/>
187
188
  </svg>`;return e?t.innerHTML=n:t.innerHTML=`${n}<span>Reset to Default</span>`,t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.resetToDefault()}),t.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),this.resetToDefault())}),t}showSubmenu(e){let t=e.element;if(!t.content)return;let n=t.content.map((t,n)=>{let{dom:r}=t.render(this.editorView),a,o=t;return a=o.options&&o.options.label?o.options.label:this.extractLabel(r),{id:`${e.id}-sub-${n}`,label:a,element:t,isPinned:!1}});this.submenuStack.push({title:e.label,tools:n}),this.renderOverflowMenu()}goBack(){this.submenuStack.pop(),this.renderOverflowMenu()}showPinnedDropdown(e,t){if(this.overflowMenu.style.display!==`none`){this.overflowMenu.style.display=`none`,this.submenuStack=[];let e=this.toolbar.querySelector(`.kb-custom-menu__overflow-toggle`);e&&e.setAttribute(`aria-expanded`,`false`)}this.pinnedDropdownMenu&&=(this.pinnedDropdownMenu.remove(),null),this.toolbar.querySelectorAll(`[data-last-focused]`).forEach(e=>{e.removeAttribute(`data-last-focused`)}),t.setAttribute(`data-last-focused`,`true`);let n=e.element;if(!n.content)return;let r=n.content.map((t,n)=>{let{dom:r}=t.render(this.editorView),a,o=t;return a=o.options&&o.options.label?o.options.label:this.extractLabel(r),{id:`${e.id}-sub-${n}`,label:a,element:t,isPinned:!1}});this.pinnedDropdownStack=[{title:e.label,tools:r,rootTool:e}],this.renderPinnedDropdown(t)}pinnedDropdownGoBack(){if(this.pinnedDropdownStack.pop(),this.pinnedDropdownStack.length===0){this.pinnedDropdownMenu&&=(this.pinnedDropdownMenu.remove(),null);return}let e=this.toolbar.querySelector(`[data-tool-id="${this.pinnedDropdownStack[0].rootTool.id}"]`);e&&this.renderPinnedDropdown(e)}pinnedDropdownShowSubmenu(e,t){let n=e.element;if(!n.content)return;let r=n.content.map((t,n)=>{let{dom:r}=t.render(this.editorView),a,o=t;return a=o.options&&o.options.label?o.options.label:this.extractLabel(r),{id:`${e.id}-sub-${n}`,label:a,element:t,isPinned:!1}});this.pinnedDropdownStack.push({title:e.label,tools:r,rootTool:this.pinnedDropdownStack[0].rootTool}),this.renderPinnedDropdown(t)}renderPinnedDropdown(e){this.pinnedDropdownMenu&&this.pinnedDropdownMenu.remove();let t=this.pinnedDropdownStack[this.pinnedDropdownStack.length-1],n=this.pinnedDropdownStack.length>1;this.pinnedDropdownMenu=document.createElement(`div`),this.pinnedDropdownMenu.classList.add(`kb-custom-menu__pinned-dropdown`),this.pinnedDropdownMenu.setAttribute(`role`,`menu`),this.pinnedDropdownMenu.setAttribute(`aria-label`,t.title);let r=e.getBoundingClientRect();this.pinnedDropdownMenu.style.position=`absolute`,this.pinnedDropdownMenu.style.top=`${r.bottom+4}px`,this.pinnedDropdownMenu.style.left=`${r.left}px`;let a=document.createElement(`div`);if(a.classList.add(`kb-custom-menu__overflow-content`),n){let e=document.createElement(`div`);e.classList.add(`kb-custom-menu__overflow-submenu-header`);let n=document.createElement(`button`);n.type=`button`,n.classList.add(`kb-custom-menu__overflow-back-button`),n.setAttribute(`aria-label`,`Go back to `+t.title),n.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M15 19l-7-7 7-7"/></svg>`,n.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.pinnedDropdownGoBack()});let r=document.createElement(`span`);r.classList.add(`kb-custom-menu__overflow-submenu-title`),r.textContent=t.title,e.appendChild(n),e.appendChild(r),a.appendChild(e)}t.tools.forEach(t=>{let n=t.element.content!==void 0,r=document.createElement(`div`);if(r.classList.add(`kb-custom-menu__overflow-item`),r.setAttribute(`data-tool-id`,t.id),r.setAttribute(`role`,`menuitem`),r.setAttribute(`tabindex`,`0`),n){let n=document.createElement(`span`);n.classList.add(`kb-custom-menu__overflow-item-label`),n.textContent=t.label,r.appendChild(n);let a=document.createElement(`span`);a.classList.add(`kb-custom-menu__overflow-item-chevron`),a.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 5l7 7-7 7"/></svg>`,r.appendChild(a),r.addEventListener(`click`,n=>{n.preventDefault(),n.stopPropagation(),this.pinnedDropdownShowSubmenu(t,e)})}else{let{dom:e}=t.element.render(this.editorView);e.querySelectorAll(`span`).forEach(t=>{let n=t.closest(`.kb-icon`)!==null,r=t.parentElement===e;t.textContent&&t.textContent.trim()&&!n&&r&&!t.querySelector(`svg`)&&!t.classList.contains(`kb-icon`)&&(t.style.display=`none`)});let n=document.createElement(`span`);n.classList.add(`kb-custom-menu__overflow-item-label`),n.textContent=t.label,r.appendChild(e),r.appendChild(n),r.addEventListener(`mousedown`,t=>{if(t.target!==e){t.preventDefault();let n=new MouseEvent(`mousedown`,{bubbles:!0,cancelable:!0,view:window});e.dispatchEvent(n)}this.pinnedDropdownMenu&&(this.pinnedDropdownMenu.remove(),this.pinnedDropdownMenu=null,this.pinnedDropdownStack=[])})}a.appendChild(r)}),this.pinnedDropdownMenu.appendChild(a),document.body.appendChild(this.pinnedDropdownMenu);let o=this.editorView.dom.ownerDocument||document;setTimeout(()=>{this.closePinnedDropdownHandler&&o.removeEventListener(`click`,this.closePinnedDropdownHandler),this.closePinnedDropdownHandler=t=>{let n=t.target;this.pinnedDropdownMenu&&!this.pinnedDropdownMenu.contains(n)&&!e.contains(n)&&(this.pinnedDropdownMenu.remove(),this.pinnedDropdownMenu=null,this.pinnedDropdownStack=[],this.closePinnedDropdownHandler&&o.removeEventListener(`click`,this.closePinnedDropdownHandler))},o.addEventListener(`click`,this.closePinnedDropdownHandler)},0)}renderOverflowMenu(){this.overflowMenu.innerHTML=``,this.overflowMenu.setAttribute(`role`,`menu`),this.overflowMenu.setAttribute(`aria-label`,`More tools`);let e=this.submenuStack.length>0,t=e?this.submenuStack[this.submenuStack.length-1]:null,n=document.createElement(`div`);if(n.classList.add(`kb-custom-menu__overflow-content`),e||n.classList.add(`kb-custom-menu__overflow-content--grid`),e&&t){let e=document.createElement(`div`);e.classList.add(`kb-custom-menu__overflow-submenu-header`);let r=document.createElement(`button`);r.type=`button`,r.classList.add(`kb-custom-menu__overflow-back-button`),r.setAttribute(`aria-label`,`Go back to previous menu`),r.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M15 19l-7-7 7-7"/></svg>`,r.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.goBack()});let a=document.createElement(`span`);a.classList.add(`kb-custom-menu__overflow-submenu-title`),a.textContent=t.title,e.appendChild(r),e.appendChild(a),n.appendChild(e),t.tools.forEach(e=>{let t=e.element.content!==void 0,r=document.createElement(`div`);if(r.classList.add(`kb-custom-menu__overflow-item`),r.setAttribute(`role`,`menuitem`),r.setAttribute(`tabindex`,`0`),t){r.setAttribute(`aria-haspopup`,`true`);let t=document.createElement(`span`);t.classList.add(`kb-custom-menu__overflow-item-label`),t.textContent=e.label,r.appendChild(t);let n=document.createElement(`span`);n.classList.add(`kb-custom-menu__overflow-item-chevron`),n.setAttribute(`aria-hidden`,`true`),n.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 5l7 7-7 7"/></svg>`,r.appendChild(n);let a=t=>{t.preventDefault(),t.stopPropagation(),this.showSubmenu(e)};r.addEventListener(`click`,a),r.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&a(e)})}else{let{dom:t,update:n}=e.element.render(this.editorView),a=t.querySelector(`span`);a&&(a.style.display=`none`);let o=document.createElement(`span`);o.classList.add(`kb-custom-menu__overflow-item-label`),o.textContent=e.label,r.appendChild(t),r.appendChild(o),r.addEventListener(`mousedown`,e=>{if(e.target!==t){e.preventDefault();let n=new MouseEvent(`mousedown`,{bubbles:!0,cancelable:!0,view:window});t.dispatchEvent(n)}}),r.addEventListener(`keydown`,e=>{if(e.key===`Enter`||e.key===` `){e.preventDefault();let n=new MouseEvent(`mousedown`,{bubbles:!0,cancelable:!0,view:window});t.dispatchEvent(n)}})}n.appendChild(r)})}else this.currentOverflowTools.forEach(t=>{if(!t.label||t.label.trim()===``||t.label===`Unknown Tool`)return;let r=t.element.content!==void 0,a=document.createElement(`div`);if(a.classList.add(`kb-custom-menu__overflow-item`),a.classList.add(`kb-custom-menu__overflow-item--grid`),a.setAttribute(`title`,t.label),a.setAttribute(`role`,`menuitem`),a.setAttribute(`tabindex`,`0`),a.setAttribute(`aria-label`,t.label),r){a.classList.add(`kb-custom-menu__overflow-item--dropdown`),a.setAttribute(`aria-haspopup`,`true`);let e=document.createElement(`button`);e.type=`button`,e.classList.add(`kb-menu__button`),e.setAttribute(`tabindex`,`-1`),e.setAttribute(`aria-hidden`,`true`);let n=t.element;if(n.options?.icon){let t=getIcon(this.root,n.options.icon);e.appendChild(t)}a.appendChild(e);let r=document.createElement(`span`);r.classList.add(`kb-custom-menu__overflow-item-indicator`),r.setAttribute(`aria-hidden`,`true`),a.appendChild(r),a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.showSubmenu(t)}),a.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),this.showSubmenu(t))})}else{let{dom:e,update:n}=t.element.render(this.editorView);e.querySelectorAll(`span`).forEach(e=>{e.closest(`.kb-icon`)===null&&!e.querySelector(`svg`)&&(e.style.display=`none`)}),e.style.pointerEvents=`none`,a.appendChild(e),a.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.closeAllMenus(),requestAnimationFrame(()=>{let e=t.element;e.spec&&typeof e.spec.run==`function`&&e.spec.run(this.editorView.state,this.editorView.dispatch)}))})}!e&&!r&&this.setupOverflowDragHandlers(a,t),n.appendChild(a)});if(this.overflowMenu.appendChild(n),!e&&this.hasCustomOrder()){let e=document.createElement(`div`);e.classList.add(`kb-custom-menu__overflow-footer`);let t=this.createResetButton(!1);e.appendChild(t),this.overflowMenu.appendChild(e)}}render(){if(this.isDragging)return;this.toolbar.innerHTML=``,this.overflowMenu.innerHTML=``;let e=(this.toolbar.offsetWidth||this.wrapper.offsetWidth)-OVERFLOW_BUTTON_WIDTH-16,t=[];this.tools.forEach(e=>{let n=document.createElement(`span`);if(n.classList.add(`kb-custom-menu__item`),n.setAttribute(`data-tool-id`,e.id),n.setAttribute(`draggable`,`false`),e.element.content!==void 0){let{dom:t}=e.element.render(this.editorView),r=t.querySelector(`.kb-dropdown__content`);r&&(r.style.display=`none`),n.appendChild(t)}else{let{dom:t}=e.element.render(this.editorView);n.appendChild(t)}this.toolbar.appendChild(n);let r=n.getBoundingClientRect().width;t.push({tool:e,wrapper:n,width:r})});let n=4,r=0,a,o=[],s=[];for(let n of t){let t=0;o.length>0&&(t+=4,a!==void 0&&n.tool.groupIndex!==a&&(t+=13)),r+t+n.width<=e?(o.push(n),r+=t+n.width,a=n.tool.groupIndex):s.push(n)}this.toolbar.innerHTML=``;let c;if(o.forEach(({tool:e,wrapper:t})=>{if(c!==void 0&&e.groupIndex!==c){let e=document.createElement(`div`);e.classList.add(`kb-custom-menu__separator`),this.toolbar.appendChild(e)}if(c=e.groupIndex,e.element.content!==void 0){let n=t.querySelector(`button`),r=t.querySelector(`.kb-dropdown__label`),a=n=>{if(this.isDragging){n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation();return}n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation(),this.showPinnedDropdown(e,t)},o=e=>{e.stopImmediatePropagation(),this.isDragging&&e.stopPropagation()};n&&(n.addEventListener(`click`,a,{capture:!0}),n.addEventListener(`mousedown`,o,{capture:!0})),r&&(r.addEventListener(`click`,a,{capture:!0}),r.addEventListener(`mousedown`,o,{capture:!0}))}this.setupDragHandlers(t,e),this.toolbar.appendChild(t)}),this.currentOverflowTools=s.map(e=>e.tool),this.currentOverflowTools.length>0){let e=document.createElement(`div`);e.classList.add(`kb-custom-menu__separator`),this.toolbar.appendChild(e)}if(this.currentOverflowTools.length>0){let e=document.createElement(`button`);e.type=`button`,e.className=`kb-custom-menu__overflow-toggle`,e.setAttribute(`aria-haspopup`,`menu`),e.setAttribute(`aria-expanded`,`false`),e.setAttribute(`aria-label`,`More tools`),e.title=`More tools`,e.innerHTML=`