loopat 0.1.30 → 0.1.32

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.
@@ -1,4 +1,4 @@
1
- import{n as e,o as t,t as n}from"./jsx-runtime-Bt-cYkS5.js";import{a as r,d as i,f as a,h as o,i as s,l as c,m as l,n as u,o as d,r as f,s as p,u as m}from"./index-B4ZEFXCO.js";import{n as h,t as g}from"./w3c-keyname-BOAvb0qz.js";var ee={}.hasOwnProperty;function te(e,t){let n=t||{};function r(t,...n){let i=r.invalid,a=r.handlers;if(t&&ee.call(t,e)){let n=String(t[e]);i=ee.call(a,n)?a[n]:r.unknown}if(i)return i.call(this,t,...n)}return r.handlers=n.handlers||{},r.invalid=n.invalid,r.unknown=n.unknown,r}var ne={}.hasOwnProperty;function re(e,t){let n=-1,r;if(t.extensions)for(;++n<t.extensions.length;)re(e,t.extensions[n]);for(r in t)if(ne.call(t,r))switch(r){case`extensions`:break;case`unsafe`:ie(e[r],t[r]);break;case`join`:ie(e[r],t[r]);break;case`handlers`:ae(e[r],t[r]);break;default:e.options[r]=t[r]}return e}function ie(e,t){t&&e.push(...t)}function ae(e,t){t&&Object.assign(e,t)}var oe=[se];function se(e,t,n,r){if(t.type===`code`&&d(t,r)&&(e.type===`list`||e.type===t.type&&d(e,r)))return!1;if(`spread`in n&&typeof n.spread==`boolean`)return e.type===`paragraph`&&(e.type===t.type||t.type===`definition`||t.type===`heading`&&s(t,r))?void 0:+!!n.spread}var ce=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`],le=[{character:` `,after:`[\\r\\n]`,inConstruct:`phrasing`},{character:` `,before:`[\\r\\n]`,inConstruct:`phrasing`},{character:` `,inConstruct:[`codeFencedLangGraveAccent`,`codeFencedLangTilde`]},{character:`\r`,inConstruct:[`codeFencedLangGraveAccent`,`codeFencedLangTilde`,`codeFencedMetaGraveAccent`,`codeFencedMetaTilde`,`destinationLiteral`,`headingAtx`]},{character:`
1
+ import{n as e,o as t,t as n}from"./jsx-runtime-Bt-cYkS5.js";import{a as r,d as i,f as a,h as o,i as s,l as c,m as l,n as u,o as d,r as f,s as p,u as m}from"./index-BKkuSzJT.js";import{n as h,t as g}from"./w3c-keyname-BOAvb0qz.js";var ee={}.hasOwnProperty;function te(e,t){let n=t||{};function r(t,...n){let i=r.invalid,a=r.handlers;if(t&&ee.call(t,e)){let n=String(t[e]);i=ee.call(a,n)?a[n]:r.unknown}if(i)return i.call(this,t,...n)}return r.handlers=n.handlers||{},r.invalid=n.invalid,r.unknown=n.unknown,r}var ne={}.hasOwnProperty;function re(e,t){let n=-1,r;if(t.extensions)for(;++n<t.extensions.length;)re(e,t.extensions[n]);for(r in t)if(ne.call(t,r))switch(r){case`extensions`:break;case`unsafe`:ie(e[r],t[r]);break;case`join`:ie(e[r],t[r]);break;case`handlers`:ae(e[r],t[r]);break;default:e.options[r]=t[r]}return e}function ie(e,t){t&&e.push(...t)}function ae(e,t){t&&Object.assign(e,t)}var oe=[se];function se(e,t,n,r){if(t.type===`code`&&d(t,r)&&(e.type===`list`||e.type===t.type&&d(e,r)))return!1;if(`spread`in n&&typeof n.spread==`boolean`)return e.type===`paragraph`&&(e.type===t.type||t.type===`definition`||t.type===`heading`&&s(t,r))?void 0:+!!n.spread}var ce=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`],le=[{character:` `,after:`[\\r\\n]`,inConstruct:`phrasing`},{character:` `,before:`[\\r\\n]`,inConstruct:`phrasing`},{character:` `,inConstruct:[`codeFencedLangGraveAccent`,`codeFencedLangTilde`]},{character:`\r`,inConstruct:[`codeFencedLangGraveAccent`,`codeFencedLangTilde`,`codeFencedMetaGraveAccent`,`codeFencedMetaTilde`,`destinationLiteral`,`headingAtx`]},{character:`
2
2
  `,inConstruct:[`codeFencedLangGraveAccent`,`codeFencedLangTilde`,`codeFencedMetaGraveAccent`,`codeFencedMetaTilde`,`destinationLiteral`,`headingAtx`]},{character:` `,after:`[\\r\\n]`,inConstruct:`phrasing`},{character:` `,before:`[\\r\\n]`,inConstruct:`phrasing`},{character:` `,inConstruct:[`codeFencedLangGraveAccent`,`codeFencedLangTilde`]},{character:`!`,after:`\\[`,inConstruct:`phrasing`,notInConstruct:ce},{character:`"`,inConstruct:`titleQuote`},{atBreak:!0,character:`#`},{character:`#`,inConstruct:`headingAtx`,after:`(?:[\r
3
3
  ]|$)`},{character:`&`,after:`[#A-Za-z]`,inConstruct:`phrasing`},{character:`'`,inConstruct:`titleApostrophe`},{character:`(`,inConstruct:`destinationRaw`},{before:`\\]`,character:`(`,inConstruct:`phrasing`,notInConstruct:ce},{atBreak:!0,before:`\\d+`,character:`)`},{character:`)`,inConstruct:`destinationRaw`},{atBreak:!0,character:`*`,after:`(?:[ \r
4
4
  *])`},{character:`*`,inConstruct:`phrasing`,notInConstruct:ce},{atBreak:!0,character:`+`,after:`(?:[ \r
@@ -30,7 +30,7 @@ import{n as e,o as t,t as n}from"./jsx-runtime-Bt-cYkS5.js";import{a as r,d as i
30
30
  `),slice:t}}function Rs(e,t,n,r,i){let a=i.parent.type.spec.code,o,s;if(!n&&!t)return null;let c=!!t&&(r||a||!n);if(c){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return s=new w(S.from(e.state.schema.text(t.replace(/\r\n?/g,`
31
31
  `))),0,0),e.someProp(`transformPasted`,t=>{s=t(s,e,!0)}),s;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,a=fn.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=Zs(n),qa&&Qs(o);let l=o&&o.querySelector(`[data-pm-slice]`),u=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute(`data-pm-slice`)||``);if(u&&u[3])for(let e=+u[3];e>0;e--){let e=o.firstChild;for(;e&&e.nodeType!=1;)e=e.nextSibling;if(!e)break;o=e}if(s||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||Zt.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||u),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!zs.test(e.parentNode.nodeName)?{ignore:!0}:null}}),u)s=$s(Gs(s,+u[1],+u[2]),u[4]);else if(s=w.maxOpen(Bs(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e<s.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=s.content.lastChild;t<s.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);s=Gs(s,e,t)}return e.someProp(`transformPasted`,t=>{s=t(s,e,c)}),s}var zs=/^(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 Bs(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)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&Hs(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=Us(a[a.length-1],i.length));let n=Vs(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return S.from(a)}return e}function Vs(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,S.from(e));return e}function Hs(e,t,n,r,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let a=Hs(e,t,n,r.lastChild,i+1);if(a)return r.copy(r.content.replaceChild(r.childCount-1,a));if(r.contentMatchAt(r.childCount).matchType(i==e.length-1?n.type:e[i+1]))return r.copy(r.content.append(S.from(Vs(n,e,i+1))))}}function Us(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,Us(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(S.empty,!0);return e.copy(n.append(r))}function Ws(e,t,n,r,i,a){let o=t<0?e.firstChild:e.lastChild,s=o.content;return e.childCount>1&&(a=0),i<r-1&&(s=Ws(s,t,n,r,i+1,a)),i>=n&&(s=t<0?o.contentMatchAt(0).fillBefore(s,a<=i).append(s):s.append(o.contentMatchAt(o.childCount).fillBefore(S.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(s))}function Gs(e,t,n){return t<e.openStart&&(e=new w(Ws(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new w(Ws(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var Ks={thead:[`table`],tbody:[`table`],tfoot:[`table`],caption:[`table`],colgroup:[`table`],col:[`table`,`colgroup`],tr:[`table`,`tbody`],td:[`table`,`tbody`,`tr`],th:[`table`,`tbody`,`tr`]},qs=null;function Js(){return qs||=document.implementation.createHTMLDocument(`title`)}var Ys=null;function Xs(e){let t=window.trustedTypes;return t?(Ys||=t.defaultPolicy||t.createPolicy(`ProseMirrorClipboard`,{createHTML:e=>e}),Ys.createHTML(e)):e}function Zs(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=Js().createElement(`div`),r=/<([a-z][^>\s]+)/i.exec(e),i;if((i=r&&Ks[r[1].toLowerCase()])&&(e=i.map(e=>`<`+e+`>`).join(``)+e+i.map(e=>`</`+e+`>`).reverse().join(``)),n.innerHTML=Xs(e),i)for(let e=0;e<i.length;e++)n=n.querySelector(i[e])||n;return n}function Qs(e){let t=e.querySelectorAll(F?`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 $s(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:i,openStart:a,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=S.from(t.create(r[e+1],i)),a++,o++}return new w(i,a,o)}var z={},B={},ec={touchstart:!0,touchmove:!0},tc=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function nc(e){for(let t in z){let n=z[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{sc(e,t)&&!oc(e,t)&&(e.editable||!(t.type in B))&&n(e,t)},ec[t]?{passive:!0}:void 0)}I&&e.dom.addEventListener(`input`,()=>null),ac(e)}function rc(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function ic(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 ac(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>oc(e,t))})}function oc(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function sc(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 cc(e,t){!oc(e,t)&&z[t.type]&&(e.editable||!(t.type in B))&&z[t.type](e,t)}B.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Sc(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(Ka&&F&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),Wa&&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,ja(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||Is(e,n)?n.preventDefault():rc(e,`key`)},B.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},B.keypress=(e,t)=>{let n=t;if(Sc(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||L&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof O)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function lc(e){return{left:e.clientX,top:e.clientY}}function uc(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function dc(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function fc(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 pc(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&k.isSelectable(r)?(fc(e,new k(n),`pointer`),!0):!1}function mc(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof k&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(k.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i==null?!1:(fc(e,k.create(e.state.doc,i),`pointer`),!0)}function hc(e,t,n,r,i){return dc(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?mc(e,n):pc(e,n))}function gc(e,t,n,r){return dc(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function _c(e,t,n,r){return dc(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||vc(e,n,r)}function vc(e,t,n){if(n.button!=0)return!1;let r=e.state.doc;if(t==-1)return r.inlineContent?(fc(e,O.create(r,0,r.content.size),`pointer`),!0):!1;let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),a=i.before(t);if(n.inlineContent)fc(e,O.create(r,a+1,a+1+n.content.size),`pointer`);else if(k.isSelectable(n))fc(e,k.create(r,a),`pointer`);else continue;return!0}}function yc(e){return kc(e)}var bc=L?`metaKey`:`ctrlKey`;z.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=yc(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&uc(n,e.input.lastClick)&&!n[bc]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button};let o=e.posAtCoords(lc(n));o&&(a==`singleClick`?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new xc(e,o,n,!!r)):(a==`doubleClick`?gc:_c)(e,o.pos,o.inside,n)?n.preventDefault():rc(e,`pointer`))};var xc=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[bc],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&s.nodeDOM.nodeType==1?s.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof k&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Va&&!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)),rc(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(()=>is(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(lc(e))),this.updateAllowDefault(e),this.allowDefault||!t?rc(this.view,`pointer`):hc(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||I&&this.mightDrag&&!this.mightDrag.node.isAtom||F&&!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)?(fc(this.view,D.near(this.view.state.doc.resolve(t.pos)),`pointer`),e.preventDefault()):rc(this.view,`pointer`)}move(e){this.updateAllowDefault(e),rc(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)}};z.touchstart=e=>{e.input.lastTouch=Date.now(),yc(e),rc(e,`pointer`)},z.touchmove=e=>{e.input.lastTouch=Date.now(),rc(e,`pointer`)},z.contextmenu=e=>yc(e);function Sc(e,t){return e.composing?!0:I&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Cc=Ka?5e3:-1;B.compositionstart=B.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof O&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||F&&Ga&&wc(e)))e.markCursor=e.state.storedMarks||n.marks(),kc(e,!0),e.markCursor=null;else if(kc(e,!t.selection.empty),Va&&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}Tc(e,Cc)};function wc(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||t.nodeType!=1||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return r.nodeType==1&&r.contentEditable==`false`}B.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.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Tc(e,20))};function Tc(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>kc(e),t))}function Ec(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Oc());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function Dc(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Ea(t.focusNode,t.focusOffset),r=Da(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;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 Oc(){let e=document.createEvent(`Event`);return e.initEvent(`event`,!0,!0),e.timeStamp}function kc(e,t=!1){if(!(Ka&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),Ec(e),t||e.docView&&e.docView.dirty){let n=ns(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 Ac(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(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var jc=P&&Ba<15||Wa&&Ja<604;z.copy=B.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=jc?null:n.clipboardData,{dom:o,text:s}=Ls(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):Ac(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function Mc(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function Nc(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 i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Pc(e,r.value,null,i,t):Pc(e,r.textContent,r.innerHTML,i,t)},50)}function Pc(e,t,n,r,i){let a=Rs(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||w.empty)))return!0;if(!a)return!1;let o=Mc(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function Fc(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,` `):``}B.paste=(e,t)=>{let n=t;if(e.composing&&!Ka)return;let r=jc?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&Pc(e,Fc(r),r.getData(`text/html`),i,n)?n.preventDefault():Nc(e,n)};var Ic=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},Lc=L?`altKey`:`ctrlKey`;function Rc(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[Lc]:!n}z.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(lc(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof k?i.to-1:i.to))){if(r&&r.mightDrag)o=k.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&&(o=k.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=Ls(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!F||Ua>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(jc?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,jc||n.dataTransfer.setData(`text/plain`,c),e.dragging=new Ic(l,Rc(e,n),o)},z.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},B.dragover=B.dragenter=(e,t)=>t.preventDefault(),B.drop=(e,t)=>{try{zc(e,t,e.dragging)}finally{e.dragging=null}};function zc(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(lc(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=Rs(e,Fc(t.dataTransfer),jc?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&Rc(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||w.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?lr(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&k.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new k(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(ms(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}z.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())&&is(e)},20))},z.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)},z.beforeinput=(e,t)=>{if(F&&Ka&&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,ja(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 B)z[e]=B[e];function Bc(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 Vc=class e{constructor(e,t){this.toDOM=e,this.spec=t||Kc,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new Wc(i-n,i-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&&Bc(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Hc=class e{constructor(e,t){this.attrs=e,this.spec=t||Kc}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new Wc(i,a,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&Bc(this.attrs,t.attrs)&&Bc(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},Uc=class e{constructor(e,t){this.attrs=e,this.spec=t||Kc}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let a=e.mapResult(t.to+r,-1);return a.deleted||a.pos<=i.pos?null:new Wc(i.pos-n,a.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(t){return this==t||t instanceof e&&Bc(this.attrs,t.attrs)&&Bc(this.spec,t.spec)}destroy(){}},Wc=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 Vc(n,r))}static inline(t,n,r,i){return new e(t,n,new Hc(r,i))}static node(t,n,r,i){return new e(t,n,new Uc(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Hc}get widget(){return this.type instanceof Vc}},Gc=[],Kc={},V=class e{constructor(e,t){this.local=e.length?e:Gc,this.children=t.length?t:Gc}static create(e,t){return t.length?$c(t,e,0,Kc):H}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,i){for(let a=0;a<this.local.length;a++){let o=this.local[a];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;a<this.children.length;a+=3)if(this.children[a]<t&&this.children[a+1]>e){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==H||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Kc)}mapInner(t,n,r,i,a){let o;for(let e=0;e<this.local.length;e++){let s=this.local[e].map(t,r,i);s&&s.type.valid(n,s)?(o||=[]).push(s):a.onRemove&&a.onRemove(this.local[e].spec)}return this.children.length?Jc(this.children,o||[],t,n,r,i,a):o?new e(o.sort(el),Gc):H}add(t,n){return n.length?this==H?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let i,a=0;t.forEach((e,t)=>{let o=t+r,s;if(s=Zc(n,e,o)){for(i||=this.children.slice();a<i.length&&i[a]<t;)a+=3;i[a]==t?i[a+2]=i[a+2].addInner(e,s,o+1):i.splice(a,0,t,t+e.nodeSize,$c(s,e,o+1,Kc)),a+=3}});let o=Yc(a?Qc(n):n,-r);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||o.splice(e--,1);return new e(o.length?this.local.concat(o).sort(el):this.local,i||this.children)}remove(e){return e.length==0||this==H?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,i=this.local;for(let e=0;e<r.length;e+=3){let i,a=r[e]+n,o=r[e+1]+n;for(let e=0,n;e<t.length;e++)(n=t[e])&&n.from>a&&n.to<o&&(t[e]=null,(i||=[]).push(n));if(!i)continue;r==this.children&&(r=this.children.slice());let s=r[e+2].removeInner(i,a+1);s==H?(r.splice(e,3),e-=3):r[e+2]=s}if(i.length){for(let e=0,r;e<t.length;e++)if(r=t[e])for(let e=0;e<i.length;e++)i[e].eq(r,n)&&(i==this.local&&(i=this.local.slice()),i.splice(e--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new e(i,r):H}forChild(t,n){if(this==H)return this;if(n.isLeaf)return e.empty;let r,i;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 a=t+1,o=a+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>a&&t.type instanceof Hc){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;e<n&&(i||=[]).push(t.copy(e,n))}}if(i){let t=new e(i.sort(el),Gc);return r?new qc([t,r]):t}return r||H}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 tl(this.localsInner(e))}localsInner(e){if(this==H)return Gc;if(e.inlineContent||!this.local.some(Hc.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof Hc||t.push(this.local[e]);return t}forEachSet(e){e(this)}};V.empty=new V([],[]),V.removeOverlap=tl;var H=V.empty,qc=class e{constructor(e){this.members=e}map(t,n){let r=this.members.map(e=>e.map(t,n,Kc));return e.from(r)}forChild(t,n){if(n.isLeaf)return V.empty;let r=[];for(let i=0;i<this.members.length;i++){let a=this.members[i].forChild(t,n);a!=H&&(a instanceof e?r=r.concat(a.members):r.push(a))}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 i=this.members[r].localsInner(e);if(i.length)if(!t)t=i;else{n&&=(t=t.slice(),!1);for(let e=0;e<i.length;e++)t.push(i[e])}}return t?tl(n?t:t.sort(el)):Gc}static from(t){switch(t.length){case 0:return H;case 1:return t[0];default:return new e(t.every(e=>e instanceof V)?t:t.reduce((e,t)=>e.concat(t instanceof V?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Jc(e,t,n,r,i,a,o){let s=e.slice();for(let e=0,t=a;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,a)=>{let o=a-i-(n-e);for(let i=0;i<s.length;i+=3){let a=s[i+1];if(a<0||e>a+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t<s.length;t+=3)if(s[t+1]<0){if(s[t+1]==-2){c=!0,s[t+1]=-1;continue}let l=n.map(e[t]+a),u=l-i;if(u<0||u>=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==H?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=$c(Xc(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;e<s.length;e+=3)s[e+1]<0&&(s.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<s.length&&s[t]<n;)t+=3;s.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new V(t.sort(el),s)}function Yc(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new Wc(i.from+t,i.to+t,i.type))}return n}function Xc(e,t,n,r,i,a,o){function s(e,t){for(let a=0;a<e.local.length;a++){let s=e.local[a].map(r,i,t);s?n.push(s):o.onRemove&&o.onRemove(e.local[a].spec)}for(let n=0;n<e.children.length;n+=3)s(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)e[n+1]==-1&&s(e[n+2],t[n]+a+1);return n}function Zc(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,a;t<e.length;t++)(a=e[t])&&a.from>n&&a.to<r&&((i||=[]).push(a),e[t]=null);return i}function Qc(e){let t=[];for(let n=0;n<e.length;n++)e[n]!=null&&t.push(e[n]);return t}function $c(e,t,n,r){let i=[],a=!1;t.forEach((t,o)=>{let s=Zc(e,t,o+n);if(s){a=!0;let e=$c(s,t,n+o+1,r);e!=H&&i.push(o,o+t.nodeSize,e)}});let o=Yc(a?Qc(e):e,-n).sort(el);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new V(o,i):H}function el(e,t){return e.from-t.from||e.to-t.to}function tl(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let a=t[i];if(a.from==r.from){a.to!=r.to&&(t==e&&(t=e.slice()),t[i]=a.copy(a.from,r.to),nl(t,i+1,a.copy(r.to,a.to)));continue}else{a.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,a.from),nl(t,i,r.copy(a.from,r.to)));break}}}return t}function nl(e,t,n){for(;t<e.length&&el(n,e[t])>0;)t++;e.splice(t,0,n)}function rl(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=H&&t.push(r)}),e.cursorWrapper&&t.push(V.create(e.state.doc,[e.cursorWrapper.deco])),qc.from(t)}var il={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},al=P&&Ba<=11,ol=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}},sl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new ol,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);P&&Ba<=11&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():I&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),al&&(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,il)),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(hs(this.view)){if(this.suppressingSelectionUpdates)return is(this.view);if(P&&Ba<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Sa(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=va(n))t.add(n);for(let r=e.anchorNode;r;r=va(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)&&hs(e)&&!this.ignoreSelectionChange(n),i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],s);n&&(i=i<0?n.from:Math.min(n.from,i),a=a<0?n.to:Math.max(n.to,a),n.typeOver&&(o=!0))}if(s.some(e=>e.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&t.nodeType==1;){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(Va&&s.length){let t=s.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||pl(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Aa(n)&&(c=ns(e))&&c.eq(D.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,is(e),this.currentSelection.set(n),e.scrollToSelection()):(i>-1||r)&&(i>-1&&(e.docView.markDirty(i,a),ul(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,ml(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||is(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,i=e.nextSibling;if(P&&Ba<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:a}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(r=n),(!a||Array.prototype.indexOf.call(e.addedNodes,a)<0)&&(i=a)}let a=r&&r.parentNode==e.target?N(r)+1:0,o=n.localPosFromDOM(e.target,a,-1),s=i&&i.parentNode==e.target?N(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,s,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}}},cl=new WeakMap,ll=!1;function ul(e){if(!cl.has(e)&&(cl.set(e,null),[`normal`,`nowrap`,`pre-line`].indexOf(getComputedStyle(e.dom).whiteSpace)!==-1)){if(e.requiresGeckoHackNode=Va,ll)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.`),ll=!0}}function dl(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return Sa(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function fl(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return dl(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?dl(e,n):null}function pl(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 ml(e,t){let{focusNode:n,focusOffset:r}=e.domSelectionRange();for(let i of t)if(i.parentNode?.nodeName==`TR`){let t=i.nextSibling;for(;t&&t.nodeName!=`TD`&&t.nodeName!=`TH`;)t=t.nextSibling;if(t){let a=t;for(;;){let e=a.firstChild;if(!e||e.nodeType!=1||e.contentEditable==`false`||/^(BR|IMG)$/.test(e.nodeName))break;a=e}a.insertBefore(i,a.firstChild),n==i&&e.domSelection().collapse(i,r)}else i.parentNode.removeChild(i)}}function hl(e,t,n){let{node:r,fromOffset:i,toOffset:a,from:o,to:s}=e.docView.parseRange(t,n),c=e.domSelectionRange(),l,u=c.anchorNode;if(u&&e.dom.contains(u.nodeType==1?u:u.parentNode)&&(l=[{node:u,offset:c.anchorOffset}],Aa(c)||l.push({node:c.focusNode,offset:c.focusOffset})),F&&e.input.lastKeyCode===8)for(let e=a;e>i;e--){let t=r.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){a=e;break}if(!n||n.size)break}let d=e.state.doc,f=e.someProp(`domParser`)||Zt.fromSchema(e.state.schema),p=d.resolve(o),m=null,h=f.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:a,preserveWhitespace:p.parent.type.whitespace==`pre`?`full`:!0,findPositions:l,ruleFromNode:gl,context:p});if(l&&l[0].pos!=null){let e=l[0].pos,t=l[1]&&l[1].pos;t??=e,m={anchor:e+o,head:t+o}}return{doc:h,sel:m,from:o,to:s}}function gl(e){let t=e.pmViewDesc;if(t)return t.parseRule();if(e.nodeName==`BR`&&e.parentNode){if(I&&/^(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||I&&/^(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 _l=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function vl(e,t,n,r,i){let a=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=ns(e,t);if(n&&!e.state.selection.eq(n)){if(F&&Ka&&e.input.lastKeyCode===13&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp(`handleKeyDown`,t=>t(e,ja(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=hl(e,t,n),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100<e.input.lastKeyCodeTime?(f=e.state.selection.to,p=`end`):(f=e.state.selection.from,p=`start`),e.input.lastKeyCode=null;let m=Cl(d.content,l.doc.content,l.from,f,p);if(m&&e.input.domChangeCount++,(Wa&&e.input.lastIOSEnter>Date.now()-225||Ka)&&i.some(e=>e.nodeType==1&&!_l.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,ja(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m)if(r&&c instanceof O&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=yl(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof O&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),P&&Ba<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),ee=u.resolve(m.start),te=h.sameParent(g)&&h.parent.inlineContent&&ee.end()>=m.endA;if((Wa&&e.input.lastIOSEnter>Date.now()-225&&(!te||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!te&&h.pos<l.doc.content.size&&(!h.sameParent(g)||!h.parent.inlineContent)&&h.pos<g.pos&&!/\S/.test(l.doc.textBetween(h.pos,g.pos,``,``)))&&e.someProp(`handleKeyDown`,t=>t(e,ja(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&xl(u,m.start,m.endA,h,g)&&e.someProp(`handleKeyDown`,t=>t(e,ja(8,`Backspace`)))){Ka&&F&&e.domObserver.suppressSelectionUpdates();return}F&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),Ka&&!te&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,ja(13,`Enter`))})},20));let ne=m.start,re=m.endA,ie=t=>{let n=t||e.state.tr.replace(ne,re,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=yl(e,n.doc,l.sel);t&&!(F&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==ne||t.head==n.mapping.map(re)-1)||P&&t.empty&&t.head==ne)&&n.setSelection(t)}return a&&n.setMeta(`composition`,a),n.scrollIntoView()},ae;if(te)if(h.pos==g.pos){P&&Ba<=11&&h.parentOffset==0&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>is(e),20));let t=ie(e.state.tr.delete(ne,re)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(ae=bl(h.parent.content.cut(h.parentOffset,g.parentOffset),ee.parent.content.cut(ee.parentOffset,m.endA-ee.start())))){let t=ie(e.state.tr);ae.type==`add`?t.addMark(ne,re,ae.mark):t.removeMark(ne,re,ae.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>ie(e.state.tr.insertText(t,ne,re));e.someProp(`handleTextInput`,r=>r(e,ne,re,t,n))||e.dispatch(n())}else e.dispatch(ie());else e.dispatch(ie())}function yl(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:ms(e,t.resolve(n.anchor),t.resolve(n.head))}function bl(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,s,c;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)a=n[e].removeFromSet(a);if(i.length==1&&a.length==0)s=i[0],o=`add`,c=e=>e.mark(s.addToSet(e.marks));else if(i.length==0&&a.length==1)s=a[0],o=`remove`,c=e=>e.mark(s.removeFromSet(e.marks));else return null;let l=[];for(let e=0;e<t.childCount;e++)l.push(c(t.child(e)));if(S.from(l).eq(e))return{mark:s,type:o}}function xl(e,t,n,r,i){if(n-t<=i.pos-r.pos||Sl(r,!0,!1)<i.pos)return!1;let a=e.resolve(t);if(!r.parent.isTextblock){let e=a.nodeAfter;return e!=null&&n==t+e.nodeSize}if(a.parentOffset<a.parent.content.size||!a.parent.isTextblock)return!1;let o=e.resolve(Sl(a,!0,!0));return!o.parent.isTextblock||o.pos>n||Sl(o,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function Sl(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function Cl(e,t,n,r,i){let a=e.findDiffStart(t,n);if(a==null)return null;let{a:o,b:s}=e.findDiffEnd(t,n+e.size,n+t.size);if(i==`end`){let e=Math.max(0,a-Math.min(o,s));r-=o+e-a}if(o<a&&e.size<t.size){let e=r<=a&&r>=o?a-r:0;a-=e,a&&a<t.size&&wl(t.textBetween(a-1,a+1))&&(a+=e?1:-1),s=a+(s-o),o=a}else if(s<a){let t=r<=a&&r>=s?a-r:0;a-=t,a&&a<e.size&&wl(e.textBetween(a-1,a+1))&&(a+=t?1:-1),o=a+(o-s),s=a}return{start:a,endA:o,endB:s}}function wl(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 Tl=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 tc,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Ml),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=Ol(this),Dl(this),this.nodeViews=Al(this),this.docView=Io(this.state.doc,El(this),rl(this),this.dom,this),this.domObserver=new sl(this,(e,t,n,r)=>vl(this,e,t,n,r)),this.domObserver.start(),nc(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&&ac(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ml),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(Ec(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=Al(this);jl(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&ac(this),this.editable=Ol(this),Dl(this);let o=rl(this),s=El(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&$a(this);if(i){this.domObserver.stop();let t=l&&(P||F)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&kl(n.selection,e.selection);if(l){let n=F?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Dc(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=Io(e.doc,s,o,this.dom,this)),n&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&_s(this))?is(this,t):(fs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&to(u)}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 k){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Qa(this,t.getBoundingClientRect(),e)}else Qa(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(n.from<this.state.doc.content.size&&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&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new Ic(e.slice,e.move,r<0?void 0:k.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 i=this.directPlugins[n].props[e];if(i!=null&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let a=i[n].props[e];if(a!=null&&(r=t?t(a):a))return r}}hasFocus(){if(P){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&&io(this.dom),is(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 po(this,e)}coordsAtPos(e,t=1){return _o(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 Do(this,t||this.state,e)}pasteHTML(e,t){return Pc(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return Pc(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return Ls(this,e)}destroy(){this.docView&&(ic(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],rl(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,xa())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return cc(this,e)}domSelectionRange(){let e=this.domSelection();return e?I&&this.root.nodeType===11&&Ma(this.dom.ownerDocument)==this.dom&&fl(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Tl.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function El(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`,[Wc.node(0,e.state.doc.content.size,t)]}function Dl(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:Wc.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Ol(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function kl(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 Al(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 jl(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 Ml(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}function Nl(e,t){return e.meta={package:`@milkdown/core`,group:`System`,...t},e}var Pl={text:(e,t,n,r)=>{let i=e.value;return/^[^*_\\]*\s+$/.test(i)?i:n.safe(i,{...r,encode:[]})},strong:(e,t,n,r)=>{let i=e.marker||n.options.strong||`*`,a=n.enter(`strong`),o=n.createTracker(r),s=o.move(i+i);return s+=o.move(n.containerPhrasing(e,{before:s,after:i,...o.current()})),s+=o.move(i+i),a(),s},emphasis:(e,t,n,r)=>{let i=e.marker||n.options.emphasis||`*`,a=n.enter(`emphasis`),o=n.createTracker(r),s=o.move(i);return s+=o.move(n.containerPhrasing(e,{before:s,after:i,...o.current()})),s+=o.move(i),a(),s}},Fl=b({},`editorView`),Il=b({},`editorState`),Ll=b([],`initTimer`),Rl=b({},`editor`),zl=b([],`inputRules`),Bl=b([],`prosePlugins`),Vl=b([],`remarkPlugins`),Hl=b([],`nodeView`),Ul=b([],`markView`),Wl=b(c().use(l).use(Ze),`remark`),Gl=b({handlers:Pl,encode:[]},`remarkStringifyOptions`),Kl=Xe(`ConfigReady`);function ql(e){let t=t=>(t.record(Kl),async()=>(await e(t),t.done(Kl),()=>{t.clearTimer(Kl)}));return Nl(t,{displayName:`Config`}),t}var Jl=Xe(`InitReady`);function Yl(e){let t=t=>(t.inject(Rl,e).inject(Bl,[]).inject(Vl,[]).inject(zl,[]).inject(Hl,[]).inject(Ul,[]).inject(Gl,{handlers:Pl,encode:[]}).inject(Wl,c().use(l).use(Ze)).inject(Ll,[Kl]).record(Jl),async()=>{await t.waitTimers(Ll);let e=t.get(Gl);return t.set(Wl,c().use(l).use(Ze,e)),t.done(Jl),()=>{t.remove(Rl).remove(Bl).remove(Vl).remove(zl).remove(Hl).remove(Ul).remove(Gl).remove(Wl).remove(Ll).clearTimer(Jl)}});return Nl(t,{displayName:`Init`}),t}var U=Xe(`SchemaReady`),Xl=b([],`schemaTimer`),Zl=b({},`schema`),Ql=b([],`nodes`),$l=b([],`marks`);function eu(e){return{...e,parseDOM:e.parseDOM?.map(t=>({priority:e.priority,...t}))}}var tu=e=>(e.inject(Zl,{}).inject(Ql,[]).inject($l,[]).inject(Xl,[Jl]).record(U),async()=>{await e.waitTimers(Xl);let t=e.get(Wl),n=e.get(Vl).reduce((e,t)=>e.use(t.plugin,t.options),t);e.set(Wl,n);let r=new qt({nodes:Object.fromEntries(e.get(Ql).map(([e,t])=>[e,eu(t)])),marks:Object.fromEntries(e.get($l).map(([e,t])=>[e,eu(t)]))});return e.set(Zl,r),e.done(U),()=>{e.remove(Zl).remove(Ql).remove($l).remove(Xl).clearTimer(U)}});Nl(tu,{displayName:`Schema`});var nu=class{constructor(){this.#e=new He,this.#t=null,this.setCtx=e=>{this.#t=e},this.chain=()=>{if(this.#t==null)throw ze();let e=this.#t,t=[],n=this.get.bind(this),r={run:()=>{let n=Di(...t),r=e.get(Fl);return n(r.state,r.dispatch,r)},inline:e=>(t.push(e),r),pipe:i.bind(this)};function i(e,i){let a=n(e);return t.push(a(i)),r}return r}}#e;#t;get ctx(){return this.#t}create(e,t){let n=e.create(this.#e.sliceMap);return n.set(t),n}get(e){return this.#e.get(e).get()}remove(e){return this.#e.remove(e)}call(e,t){if(this.#t==null)throw ze();let n=this.get(e)(t),r=this.#t.get(Fl);return n(r.state,r.dispatch,r)}inline(e){if(this.#t==null)throw ze();let t=this.#t.get(Fl);return e(t.state,t.dispatch,t)}};function ru(e=`cmdKey`){return b((()=>()=>!1),e)}var W=b(new nu,`commands`),iu=b([U],`commandsTimer`),au=Xe(`CommandsReady`),ou=e=>{let t=new nu;return t.setCtx(e),e.inject(W,t).inject(iu,[U]).record(au),async()=>(await e.waitTimers(iu),e.done(au),()=>{e.remove(W).remove(iu).clearTimer(au)})};Nl(ou,{displayName:`Commands`});function su(e){return e.Backspace=Di(Pi,Zr,ei,ri),e}var cu=class{constructor(){this.#e=null,this.#t=[],this.setCtx=e=>{this.#e=e},this.add=e=>(this.#t.push(e),()=>{this.#t=this.#t.filter(t=>t!==e)}),this.addObjectKeymap=e=>{let t=[];return Object.entries(e).forEach(([e,n])=>{if(typeof n==`function`){let r={key:e,onRun:()=>n};this.#t.push(r),t.push(()=>{this.#t=this.#t.filter(e=>e!==r)})}else this.#t.push(n),t.push(()=>{this.#t=this.#t.filter(e=>e!==n)})}),()=>{t.forEach(e=>e())}},this.addBaseKeymap=()=>{let e=su(Mi);return this.addObjectKeymap(e)},this.build=()=>{let e={};return this.#t.forEach(t=>{e[t.key]=[...e[t.key]||[],t]}),Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.sort((e,t)=>(t.priority??50)-(e.priority??50));return[e,(e,t,r)=>{let i=this.#e;if(i==null)throw Ne();return Di(...n.map(e=>e.onRun(i)))(e,t,r)}]}))}}#e;#t;get ctx(){return this.#e}},lu=b(new cu,`keymap`),uu=b([U],`keymapTimer`),du=Xe(`KeymapReady`),fu=e=>{let t=new cu;return t.setCtx(e),e.inject(lu,t).inject(uu,[U]).record(du),async()=>(await e.waitTimers(uu),e.done(du),()=>{e.remove(lu).remove(uu).clearTimer(du)})},pu=Xe(`ParserReady`),mu=(()=>{throw Ne()}),hu=b(mu,`parser`),gu=b([],`parserTimer`),_u=e=>(e.inject(hu,mu).inject(gu,[U]).record(pu),async()=>{await e.waitTimers(gu);let t=e.get(Wl),n=e.get(Zl);return e.set(hu,ma.create(n,t)),e.done(pu),()=>{e.remove(hu).remove(gu).clearTimer(pu)}});Nl(_u,{displayName:`Parser`});var vu=Xe(`SerializerReady`),yu=b([],`serializerTimer`),bu=(()=>{throw Ne()}),xu=b(bu,`serializer`),Su=e=>(e.inject(xu,bu).inject(yu,[U]).record(vu),async()=>{await e.waitTimers(yu);let t=e.get(Wl),n=e.get(Zl);return e.set(xu,_a.create(n,t)),e.done(vu),()=>{e.remove(xu).remove(yu).clearTimer(vu)}});Nl(Su,{displayName:`Serializer`});var Cu=b(``,`defaultValue`),wu=b(e=>e,`stateOptions`),Tu=b([],`editorStateTimer`),Eu=Xe(`EditorStateReady`);function Du(e,t,n){if(typeof e==`string`)return t(e);if(e.type===`html`)return Zt.fromSchema(n).parse(e.dom);if(e.type===`json`)return St.fromJSON(n,e.value);throw Ae(e)}var Ou=new j(`MILKDOWN_STATE_TRACKER`),ku=e=>(e.inject(Cu,``).inject(Il,{}).inject(wu,e=>e).inject(Tu,[pu,vu,au,du]).record(Eu),async()=>{await e.waitTimers(Tu);let t=e.get(Zl),n=e.get(hu),r=e.get(zl),i=e.get(wu),a=e.get(Bl),o=Du(e.get(Cu),n,t),s=e.get(lu),c=s.addBaseKeymap(),l=[...a,new A({key:Ou,state:{init:()=>{},apply:(t,n,r,i)=>{e.set(Il,i)}}}),Yi({rules:r}),la(s.build())];e.set(Bl,l);let u=i({schema:t,doc:o,plugins:l}),d=qr.create(u);return e.set(Il,d),e.done(Eu),()=>{c(),e.remove(Cu).remove(Il).remove(wu).remove(Tu).clearTimer(Eu)}});Nl(ku,{displayName:`EditorState`});var Au=b([],`pasteRule`),ju=b([U],`pasteRuleTimer`),Mu=Xe(`PasteRuleReady`),Nu=e=>(e.inject(Au,[]).inject(ju,[U]).record(Mu),async()=>(await e.waitTimers(ju),e.done(Mu),()=>{e.remove(Au).remove(ju).clearTimer(Mu)}));Nl(Nu,{displayName:`PasteRule`});var Pu=Xe(`EditorViewReady`),Fu=b([],`editorViewTimer`),Iu=b({},`editorViewOptions`),Lu=b(null,`root`),Ru=b(null,`rootDOM`),zu=b({},`rootAttrs`);function Bu(e,t){let n=document.createElement(`div`);n.className=`milkdown`,e.appendChild(n),t.set(Ru,n);let r=t.get(zu);return Object.entries(r).forEach(([e,t])=>n.setAttribute(e,t)),n}function Vu(e){e.classList.add(`editor`),e.setAttribute(`role`,`textbox`)}var Hu=new j(`MILKDOWN_VIEW_CLEAR`),Uu=e=>(e.inject(Lu,document.body).inject(Fl,{}).inject(Iu,{}).inject(Ru,null).inject(zu,{}).inject(Fu,[Eu,Mu]).record(Pu),async()=>{await e.wait(Jl);let t=e.get(Lu)||document.body,n=typeof t==`string`?document.querySelector(t):t;e.update(Bl,t=>[new A({key:Hu,view:t=>{let r=n?Bu(n,e):void 0;return(()=>{if(r&&n){let e=t.dom;n.replaceChild(r,e),r.appendChild(e)}})(),{destroy:()=>{r?.parentNode&&r?.parentNode.replaceChild(t.dom,r),r?.remove()}}}}),...t]),await e.waitTimers(Fu);let r=e.get(Il),i=e.get(Iu),a=new Tl(n,{state:r,nodeViews:Object.fromEntries(e.get(Hl)),markViews:Object.fromEntries(e.get(Ul)),transformPasted:(t,n,r)=>(e.get(Au).sort((e,t)=>(t.priority??50)-(e.priority??50)).map(e=>e.run).forEach(e=>{t=e(t,n,r)}),t),...i});return Vu(a.dom),e.set(Fl,a),e.done(Pu),()=>{a?.destroy(),e.remove(Lu).remove(Fl).remove(Iu).remove(Ru).remove(zu).remove(Fu).clearTimer(Pu)}});Nl(Uu,{displayName:`EditorView`});var Wu=function(e){return e.Idle=`Idle`,e.OnCreate=`OnCreate`,e.Created=`Created`,e.OnDestroy=`OnDestroy`,e.Destroyed=`Destroyed`,e}({}),Gu=class e{constructor(){this.#e=!1,this.#t=Wu.Idle,this.#n=[],this.#r=()=>void 0,this.#i=new He,this.#a=new qe,this.#o=new Map,this.#s=new Map,this.#c=new Ke(this.#i,this.#a),this.#l=()=>{let e=ql(async e=>{await Promise.all(this.#n.map(t=>Promise.resolve(t(e))))}),t=[tu,_u,Su,ou,fu,Nu,ku,Uu,Yl(this),e];this.#u(t,this.#s)},this.#u=(e,t)=>{e.forEach(e=>{let n=this.#c.produce(this.#e?e.meta:void 0),r=e(n);t.set(e,{ctx:n,handler:r,cleanup:void 0})})},this.#d=(e,t=!1)=>Promise.all([e].flat().map(async e=>{let n=this.#o.get(e)?.cleanup;return t?this.#o.delete(e):this.#o.set(e,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof n==`function`?n():n})),this.#f=async()=>{await Promise.all([...this.#s.entries()].map(async([e,{cleanup:t}])=>typeof t==`function`?t():t)),this.#s.clear()},this.#p=e=>{this.#t=e,this.#r(e)},this.#m=e=>[...e.entries()].map(async([t,n])=>{let{ctx:r,handler:i}=n;if(!i)return;let a=await i();e.set(t,{ctx:r,handler:i,cleanup:a})}),this.enableInspector=(e=!0)=>(this.#e=e,this),this.onStatusChange=e=>(this.#r=e,this),this.config=e=>(this.#n.push(e),this),this.removeConfig=e=>(this.#n=this.#n.filter(t=>t!==e),this),this.use=e=>{let t=[e].flat();return t.flat().forEach(e=>{this.#o.set(e,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#t===Wu.Created&&this.#u(t,this.#o),this},this.remove=async e=>this.#t===Wu.OnCreate?(console.warn(`[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code.`),new Promise(t=>{setTimeout(()=>{t(this.remove(e))},50)})):(await this.#d([e].flat(),!0),this),this.create=async()=>this.#t===Wu.OnCreate?this:(this.#t===Wu.Created&&await this.destroy(),this.#p(Wu.OnCreate),this.#l(),this.#u([...this.#o.keys()],this.#o),await Promise.all([this.#m(this.#s),this.#m(this.#o)].flat()),this.#p(Wu.Created),this),this.destroy=async(e=!1)=>this.#t===Wu.Destroyed||this.#t===Wu.OnDestroy?this:this.#t===Wu.OnCreate?new Promise(t=>{setTimeout(()=>{t(this.destroy(e))},50)}):(e&&(this.#n=[]),this.#p(Wu.OnDestroy),await this.#d([...this.#o.keys()],e),await this.#f(),this.#p(Wu.Destroyed),this),this.action=e=>e(this.#c),this.inspect=()=>this.#e?[...this.#s.values(),...this.#o.values()].map(({ctx:e})=>e?.inspector?.read()).filter(e=>!!e):(console.warn("[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first."),[])}static make(){return new e}#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;get ctx(){return this.#c}get status(){return this.#t}},Ku=(0,_.createContext)({});function qu(){let{dom:e,editor:t,setLoading:n,editorFactory:r}=(0,_.useContext)(Ku),i=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let a=i.current;if(!r||!a)return;e.current=a;let o=r(a);if(o)return n(!0),o.create().then(e=>{t.current=e}).finally(()=>{n(!1)}).catch(console.error),()=>{o.destroy().catch(console.error)}},[e,t,r,n]),i}var Ju=()=>{let e=qu();return _.createElement(`div`,{"data-milkdown-root":!0,ref:e})},Yu=({children:e})=>{let t=(0,_.useRef)(void 0),[n,r]=(0,_.useState)(void 0),i=(0,_.useRef)(void 0),[a,o]=(0,_.useState)(!0),s=(0,_.useMemo)(()=>({loading:a,dom:t,editor:i,setLoading:o,editorFactory:n,setEditorFactory:r}),[a,n]);return _.createElement(Ku.Provider,{value:s},e)};function Xu(e,t=[]){let n=(0,_.useContext)(Ku),r=(0,_.useCallback)(e,t);return(0,_.useLayoutEffect)(()=>{n.setEditorFactory(()=>r)},[n,r]),{loading:n.loading,get:()=>n.editor.current}}var Zu=e=>crypto.getRandomValues(new Uint8Array(e)),Qu=(e,t,n)=>{let r=256-256%e.length;if(r===256){let r=e.length-1;return(i=t)=>{if(!i)return``;let a=``;for(;;){let t=n(i),o=i;for(;o--;)if(a+=e[t[o]&r],a.length>=i)return a}}}let i=Math.ceil(1.6*256*t/r);return(a=t)=>{if(!a)return``;let o=``;for(;;){let t=n(i),s=i;for(;s--;)if(t[s]<r&&(o+=e[t[s]%e.length],o.length>=a))return o}}};((e,t=21)=>Qu(e,t|0,Zu))(`abcedfghicklmn`,10);function G(e,t){let n=ru(e),r=i=>async()=>{r.key=n,await i.wait(au);let a=t(i);return i.get(W).create(n,a),r.run=t=>i.get(W).call(e,t),()=>{i.get(W).remove(n)}};return r}function K(e){let t=n=>async()=>{await n.wait(U);let r=e(n);return n.update(zl,e=>[...e,r]),t.inputRule=r,()=>{n.update(zl,e=>e.filter(e=>e!==r))}};return t}function $u(e){let t=n=>async()=>{await n.wait(U);let r=e(n);return n.update(Au,e=>[...e,r]),t.pasteRule=r,()=>{n.update(Au,e=>e.filter(e=>e!==r))}};return t}function ed(e,t){let n=r=>async()=>{let i=t(r);return r.update($l,t=>[...t.filter(t=>t[0]!==e),[e,i]]),n.id=e,n.schema=i,()=>{r.update($l,t=>t.filter(([t])=>t!==e))}};return n.type=t=>{let n=t.get(Zl).marks[e];if(!n)throw Ve(e);return n},n}function td(e,t){let n=r=>async()=>{let i=t(r);return r.update(Ql,t=>[...t.filter(t=>t[0]!==e),[e,i]]),n.id=e,n.schema=i,()=>{r.update(Ql,t=>t.filter(([t])=>t!==e))}};return n.type=t=>{let n=t.get(Zl).nodes[e];if(!n)throw Be(e);return n},n}function nd(e){let t,n=n=>async()=>(await n.wait(U),t=e(n),n.update(Bl,e=>[...e,t]),()=>{n.update(Bl,e=>e.filter(e=>e!==t))});return n.plugin=()=>t,n.key=()=>t.spec.key,n}function rd(e){let t=n=>async()=>{await n.wait(du);let r=n.get(lu),i=e(n),a=r.addObjectKeymap(i);return t.keymap=i,()=>{a()}};return t}function id(e,t){let n=b(e,t),r=e=>(e.inject(n),()=>()=>{e.remove(n)});return r.key=n,r}function q(e,t){let n=id(t,e),r=td(e,e=>e.get(n.key)(e)),i=[n,r];return i.id=r.id,i.node=r,i.type=e=>r.type(e),i.ctx=n,i.key=n.key,i.extendSchema=n=>q(e,n(t)),i}function ad(e,t){let n=id(t,e),r=ed(e,e=>e.get(n.key)(e)),i=[n,r];return i.id=r.id,i.mark=r,i.type=e=>r.type(e),i.ctx=n,i.key=n.key,i.extendSchema=n=>ad(e,n(t)),i}function J(e,t){let n=id(Object.fromEntries(Object.entries(t).map(([e,{shortcuts:t,priority:n}])=>[e,{shortcuts:t,priority:n}])),`${e}Keymap`),r=rd(e=>{let r=e.get(n.key),i=Object.entries(t).flatMap(([e,{command:t}])=>{let n=r[e],i=[n.shortcuts].flat(),a=n.priority;return i.map(e=>[e,{key:e,onRun:t,priority:a}])});return Object.fromEntries(i)}),i=[n,r];return i.ctx=n,i.shortcuts=r,i.key=n.key,i.keymap=r.keymap,i}var od=(e,t=()=>({}))=>id(t,`${e}Attr`),sd=(e,t=()=>({}))=>id(t,`${e}Attr`);function cd(e,t,n){let r=id(n??{},e),i=e=>async()=>{await e.wait(Jl);let n={plugin:t(e),options:e.get(r.key)};return e.update(Vl,e=>[...e,n]),()=>{e.update(Vl,e=>e.filter(e=>e!==n))}},a=[r,i];return a.id=e,a.plugin=i,a.options=r,a}function ld(e,t){return function(n,r){let{$from:i,$to:a,node:o}=n.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(a))return!1;let s=i.node(-1);if(s.type!=e)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=e||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let t=S.empty,a=i.index(-1)?1:i.index(-2)?2:3;for(let e=i.depth-a;e>=i.depth-3;e--)t=S.from(i.node(e).copy(t));let o=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;t=t.append(S.from(e.createAndFill()));let s=i.before(i.depth-(a-1)),c=n.tr.replace(s,i.after(-o),new w(t,4-a,0)),l=-1;c.doc.nodesBetween(s,c.doc.content.size,(e,t)=>{if(l>-1)return!1;e.isTextblock&&e.content.size==0&&(l=t+1)}),l>-1&&c.setSelection(D.near(c.doc.resolve(l))),r(c.scrollIntoView())}return!0}let c=a.pos==i.end()?s.contentMatchAt(0).defaultType:null,l=n.tr.delete(i.pos,a.pos),u=c?[t?{type:e,attrs:t}:null,{type:c}]:void 0;return nr(l.doc,i.pos,2,u)?(r&&r(l.split(i.pos,2,u).scrollIntoView()),!0):!1}}function ud(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);return a?n?r.node(a.depth-1).type==e?dd(t,n,e,a):fd(t,n,a):!0:!1}}function dd(e,t,n,r){let i=e.tr,a=r.end,o=r.$to.end(r.depth);a<o&&(i.step(new Rn(a-1,o,a,o,new w(S.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new bt(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let s=Wn(r);if(s==null)return!1;i.lift(r,s);let c=i.doc.resolve(i.mapping.map(a,-1)-1);return ir(i.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&i.join(c.pos),t(i.scrollIntoView()),!0}function fd(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,a=n.startIndex;t>a;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let s=n.startIndex==0,c=n.endIndex==i.childCount,l=a.node(-1),u=a.index(-1);if(!l.canReplace(u+ +!s,u+1,o.content.append(c?S.empty:S.from(i))))return!1;let d=a.pos,f=d+o.nodeSize;return r.step(new Rn(d-+!!s,f+ +!!c,d+1,f-1,new w((s?S.empty:S.from(i.copy(S.empty))).append(c?S.empty:S.from(i.copy(S.empty))),+!s,+!c),+!s)),t(r.scrollIntoView()),!0}function pd(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let s=a.parent,c=s.child(o-1);if(c.type!=e)return!1;if(n){let r=c.lastChild&&c.lastChild.type==s.type,i=S.from(r?e.create():null),o=new w(S.from(e.create(null,S.from(s.type.create(null,i)))),r?3:1,0),l=a.start,u=a.end;n(t.tr.step(new Rn(l-(r?3:1),u,l,u,o,1,!0)).scrollIntoView())}return!0}}function md(e){let t=new Map;if(!e||!e.type)throw Error(`mdast-util-definitions expected node`);return m(e,`definition`,function(e){let n=hd(e.identifier);n&&!t.get(n)&&t.set(n,e)}),n;function n(e){let n=hd(e);return t.get(n)}}function hd(e){return String(e||``).toUpperCase()}function gd(){return function(e){let t=md(e);m(e,function(e,n,r){if(e.type===`definition`&&r!==void 0&&typeof n==`number`)return r.children.splice(n,1),[i,n];if(e.type===`imageReference`||e.type===`linkReference`){let a=t(e.identifier);if(a&&r&&typeof n==`number`)return r.children[n]=e.type===`imageReference`?{type:`image`,url:a.url,title:a.title,alt:e.alt}:{type:`link`,url:a.url,title:a.title,children:e.children},[i,n]}})}}function _d(e,t){if(!(t.childCount>=1&&t.lastChild?.type.name===`hardbreak`)){e.next(t.content);return}let n=[];t.content.forEach((e,r,i)=>{i!==t.childCount-1&&n.push(e)}),e.next(S.fromArray(n))}function Y(e,t){return Object.assign(e,{meta:{package:`@milkdown/preset-commonmark`,...t}}),e}var vd=sd(`emphasis`);Y(vd,{displayName:`Attr<emphasis>`,group:`Emphasis`});var yd=ad(`emphasis`,e=>({attrs:{marker:{default:e.get(Gl).emphasis||`*`,validate:`string`}},parseDOM:[{tag:`i`},{tag:`em`},{style:`font-style`,getAttrs:e=>e===`italic`}],toDOM:t=>[`em`,e.get(vd.key)(t)],parseMarkdown:{match:e=>e.type===`emphasis`,runner:(e,t,n)=>{e.openMark(n,{marker:t.marker}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===`emphasis`,runner:(e,t)=>{e.withMark(t,`emphasis`,void 0,{marker:t.attrs.marker})}}}));Y(yd.mark,{displayName:`MarkSchema<emphasis>`,group:`Emphasis`}),Y(yd.ctx,{displayName:`MarkSchemaCtx<emphasis>`,group:`Emphasis`});var bd=G(`ToggleEmphasis`,e=>()=>Ei(yd.type(e)));Y(bd,{displayName:`Command<toggleEmphasisCommand>`,group:`Emphasis`});var xd=K(e=>Xi(/(?:^|[^*])\*([^*]+)\*$/,yd.type(e),{getAttr:()=>({marker:`*`}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith(`*`)?{}:{fullMatch:e.slice(1),start:t+1}}));Y(xd,{displayName:`InputRule<emphasis>|Star`,group:`Emphasis`});var Sd=K(e=>Xi(/\b_(?![_\s])(.*?[^_\s])_\b/,yd.type(e),{getAttr:()=>({marker:`_`}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith(`_`)?{}:{fullMatch:e.slice(1),start:t+1}}));Y(Sd,{displayName:`InputRule<emphasis>|Underscore`,group:`Emphasis`});var Cd=J(`emphasisKeymap`,{ToggleEmphasis:{shortcuts:`Mod-i`,command:e=>{let t=e.get(W);return()=>t.call(bd.key)}}});Y(Cd.ctx,{displayName:`KeymapCtx<emphasis>`,group:`Emphasis`}),Y(Cd.shortcuts,{displayName:`Keymap<emphasis>`,group:`Emphasis`});var wd=sd(`strong`);Y(wd,{displayName:`Attr<strong>`,group:`Strong`});var Td=ad(`strong`,e=>({attrs:{marker:{default:e.get(Gl).strong||`*`,validate:`string`}},parseDOM:[{tag:`b`,getAttrs:e=>e.style.fontWeight!=`normal`&&null},{tag:`strong`},{style:`font-style`,getAttrs:e=>e===`bold`},{style:`font-weight=400`,clearMark:e=>e.type.name==`strong`},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:t=>[`strong`,e.get(wd.key)(t)],parseMarkdown:{match:e=>e.type===`strong`,runner:(e,t,n)=>{e.openMark(n,{marker:t.marker}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===`strong`,runner:(e,t)=>{e.withMark(t,`strong`,void 0,{marker:t.attrs.marker})}}}));Y(Td.mark,{displayName:`MarkSchema<strong>`,group:`Strong`}),Y(Td.ctx,{displayName:`MarkSchemaCtx<strong>`,group:`Strong`});var Ed=G(`ToggleStrong`,e=>()=>Ei(Td.type(e)));Y(Ed,{displayName:`Command<toggleStrongCommand>`,group:`Strong`});var Dd=K(e=>Xi(/(?<![\w:/])(?:\*\*|__)([^*_]+?)(?:\*\*|__)(?![\w/])$/,Td.type(e),{getAttr:e=>({marker:e[0].startsWith(`*`)?`*`:`_`})}));Y(Dd,{displayName:`InputRule<strong>`,group:`Strong`});var Od=J(`strongKeymap`,{ToggleBold:{shortcuts:[`Mod-b`],command:e=>{let t=e.get(W);return()=>t.call(Ed.key)}}});Y(Od.ctx,{displayName:`KeymapCtx<strong>`,group:`Strong`}),Y(Od.shortcuts,{displayName:`Keymap<strong>`,group:`Strong`});var kd=sd(`inlineCode`);Y(kd,{displayName:`Attr<inlineCode>`,group:`InlineCode`});var Ad=ad(`inlineCode`,e=>({priority:100,code:!0,parseDOM:[{tag:`code`}],toDOM:t=>[`code`,e.get(kd.key)(t)],parseMarkdown:{match:e=>e.type===`inlineCode`,runner:(e,t,n)=>{e.openMark(n),e.addText(t.value),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===`inlineCode`,runner:(e,t,n)=>(e.withMark(t,`inlineCode`,n.text||``),!0)}}));Y(Ad.mark,{displayName:`MarkSchema<inlineCode>`,group:`InlineCode`}),Y(Ad.ctx,{displayName:`MarkSchemaCtx<inlineCode>`,group:`InlineCode`});var jd=G(`ToggleInlineCode`,e=>()=>(t,n)=>{let{selection:r,tr:i}=t;if(r.empty)return!1;let{from:a,to:o}=r;return t.doc.rangeHasMark(a,o,Ad.type(e))?(n?.(i.removeMark(a,o,Ad.type(e))),!0):(Object.keys(t.schema.marks).filter(e=>e!==Ad.type.name).map(e=>t.schema.marks[e]).forEach(e=>{i.removeMark(a,o,e)}),n?.(i.addMark(a,o,Ad.type(e).create())),!0)});Y(jd,{displayName:`Command<toggleInlineCodeCommand>`,group:`InlineCode`});var Md=K(e=>Xi(/(?:`)([^`]+)(?:`)$/,Ad.type(e)));Y(Md,{displayName:`InputRule<inlineCodeInputRule>`,group:`InlineCode`});var Nd=J(`inlineCodeKeymap`,{ToggleInlineCode:{shortcuts:`Mod-e`,command:e=>{let t=e.get(W);return()=>t.call(jd.key)}}});Y(Nd.ctx,{displayName:`KeymapCtx<inlineCode>`,group:`InlineCode`}),Y(Nd.shortcuts,{displayName:`Keymap<inlineCode>`,group:`InlineCode`});var Pd=sd(`link`);Y(Pd,{displayName:`Attr<link>`,group:`Link`});var Fd=ad(`link`,e=>({attrs:{href:{validate:`string`},title:{default:null,validate:`string|null`}},parseDOM:[{tag:`a[href]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{href:e.getAttribute(`href`),title:e.getAttribute(`title`)}}}],toDOM:t=>[`a`,{...e.get(Pd.key)(t),...t.attrs}],parseMarkdown:{match:e=>e.type===`link`,runner:(e,t,n)=>{let r=t.url,i=t.title;e.openMark(n,{href:r,title:i}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===`link`,runner:(e,t)=>{e.withMark(t,`link`,void 0,{title:t.attrs.title,url:t.attrs.href})}}}));Y(Fd.mark,{displayName:`MarkSchema<link>`,group:`Link`});var Id=G(`ToggleLink`,e=>(t={})=>Ei(Fd.type(e),t));Y(Id,{displayName:`Command<toggleLinkCommand>`,group:`Link`});var Ld=G(`UpdateLink`,e=>(t={})=>(n,r)=>{if(!r)return!1;let i,a=-1,{selection:o}=n,{from:s,to:c}=o;if(n.doc.nodesBetween(s,s===c?c+1:c,(t,n)=>{if(Fd.type(e).isInSet(t.marks))return i=t,a=n,!1}),!i)return!1;let l=i.marks.find(({type:t})=>t===Fd.type(e));if(!l)return!1;let u=a,d=a+i.nodeSize,{tr:f}=n,p=Fd.type(e).create({...l.attrs,...t});return p?(r(f.removeMark(u,d,l).addMark(u,d,p).setSelection(new O(f.selection.$anchor)).scrollIntoView()),!0):!1});Y(Ld,{displayName:`Command<updateLinkCommand>`,group:`Link`});var Rd=td(`doc`,()=>({content:`block+`,parseMarkdown:{match:({type:e})=>e===`root`,runner:(e,t,n)=>{e.injectRoot(t,n)}},toMarkdown:{match:e=>e.type.name===`doc`,runner:(e,t)=>{e.openNode(`root`),e.next(t.content)}}}));Y(Rd,{displayName:`NodeSchema<doc>`,group:`Doc`});function zd(e){return a(e,e=>e.type===`html`&&[`<br />`,`<br>`,`<br >`,`<br/>`].includes(e.value?.trim()),(e,t)=>{if(!t.length)return;let n=t[t.length-1];if(!n)return;let r=n.children.indexOf(e);r!==-1&&n.children.splice(r,1)},!0)}var Bd=cd(`remark-preserve-empty-line`,()=>()=>zd);Y(Bd.plugin,{displayName:`Remark<remarkPreserveEmptyLine>`,group:`Remark`}),Y(Bd.options,{displayName:`RemarkConfig<remarkPreserveEmptyLine>`,group:`Remark`});var Vd=od(`paragraph`);Y(Vd,{displayName:`Attr<paragraph>`,group:`Paragraph`});var Hd=q(`paragraph`,e=>({content:`inline*`,group:`block`,parseDOM:[{tag:`p`}],toDOM:t=>[`p`,e.get(Vd.key)(t),0],parseMarkdown:{match:e=>e.type===`paragraph`,runner:(e,t,n)=>{e.openNode(n),t.children?e.next(t.children):e.addText(t.value||``),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`paragraph`,runner:(t,n)=>{let r=e.get(Fl).state?.doc.lastChild;t.openNode(`paragraph`),(!n.content||n.content.size===0)&&n!==r&&Ud(e)?t.addNode(`html`,void 0,`<br />`):_d(t,n),t.closeNode()}}}));function Ud(e){let t=!1;try{e.get(Bd.id),t=!0}catch{t=!1}return t}Y(Hd.node,{displayName:`NodeSchema<paragraph>`,group:`Paragraph`}),Y(Hd.ctx,{displayName:`NodeSchemaCtx<paragraph>`,group:`Paragraph`});var Wd=G(`TurnIntoText`,e=>()=>Ci(Hd.type(e)));Y(Wd,{displayName:`Command<turnIntoTextCommand>`,group:`Paragraph`});var Gd=J(`paragraphKeymap`,{TurnIntoText:{shortcuts:`Mod-Alt-0`,command:e=>{let t=e.get(W);return()=>t.call(Wd.key)}}});Y(Gd.ctx,{displayName:`KeymapCtx<paragraph>`,group:`Paragraph`}),Y(Gd.shortcuts,{displayName:`Keymap<paragraph>`,group:`Paragraph`});var Kd=[,,,,,,].fill(0).map((e,t)=>t+1);function qd(e){return e.textContent.toLowerCase().trim().replace(/\s+/g,`-`)}var Jd=id(qd,`headingIdGenerator`);Y(Jd,{displayName:`Ctx<HeadingIdGenerator>`,group:`Heading`});var Yd=od(`heading`);Y(Yd,{displayName:`Attr<heading>`,group:`Heading`});var Xd=q(`heading`,e=>{let t=e.get(Jd.key);return{content:`inline*`,group:`block`,defining:!0,attrs:{id:{default:``,validate:`string`},level:{default:1,validate:`number`}},parseDOM:Kd.map(e=>({tag:`h${e}`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw Re(t);return{level:e,id:t.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...e.get(Yd.key)(n),id:n.attrs.id||t(n)},0],parseMarkdown:{match:({type:e})=>e===`heading`,runner:(e,t,n)=>{let r=t.depth;e.openNode(n,{level:r}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`heading`,runner:(e,t)=>{e.openNode(`heading`,void 0,{depth:t.attrs.level}),_d(e,t),e.closeNode()}}}});Y(Xd.node,{displayName:`NodeSchema<heading>`,group:`Heading`}),Y(Xd.ctx,{displayName:`NodeSchemaCtx<heading>`,group:`Heading`});var Zd=K(e=>Ii(/^(?<hashes>#+)\s$/,Xd.type(e),t=>{let n=t.groups?.hashes?.length||0,{$from:r}=e.get(Fl).state.selection,i=r.node();if(i.type.name===`heading`){let e=Number(i.attrs.level)+Number(n);return e>6&&(e=6),{level:e}}return{level:n}}));Y(Zd,{displayName:`InputRule<wrapInHeadingInputRule>`,group:`Heading`});var Qd=G(`WrapInHeading`,e=>t=>(t??=1,t<1?Ci(Hd.type(e)):Ci(Xd.type(e),{level:t})));Y(Qd,{displayName:`Command<wrapInHeadingCommand>`,group:`Heading`});var $d=G(`DowngradeHeading`,e=>()=>(t,n,r)=>{let{$from:i}=t.selection,a=i.node();if(a.type!==Xd.type(e)||!t.selection.empty||i.parentOffset!==0)return!1;let o=a.attrs.level-1;return o?(n?.(t.tr.setNodeMarkup(t.selection.$from.before(),void 0,{...a.attrs,level:o})),!0):Ci(Hd.type(e))(t,n,r)});Y($d,{displayName:`Command<downgradeHeadingCommand>`,group:`Heading`});var ef=J(`headingKeymap`,{TurnIntoH1:{shortcuts:`Mod-Alt-1`,command:e=>{let t=e.get(W);return()=>t.call(Qd.key,1)}},TurnIntoH2:{shortcuts:`Mod-Alt-2`,command:e=>{let t=e.get(W);return()=>t.call(Qd.key,2)}},TurnIntoH3:{shortcuts:`Mod-Alt-3`,command:e=>{let t=e.get(W);return()=>t.call(Qd.key,3)}},TurnIntoH4:{shortcuts:`Mod-Alt-4`,command:e=>{let t=e.get(W);return()=>t.call(Qd.key,4)}},TurnIntoH5:{shortcuts:`Mod-Alt-5`,command:e=>{let t=e.get(W);return()=>t.call(Qd.key,5)}},TurnIntoH6:{shortcuts:`Mod-Alt-6`,command:e=>{let t=e.get(W);return()=>t.call(Qd.key,6)}},DowngradeHeading:{shortcuts:[`Delete`,`Backspace`],command:e=>{let t=e.get(W);return()=>t.call($d.key)}}});Y(ef.ctx,{displayName:`KeymapCtx<heading>`,group:`Heading`}),Y(ef.shortcuts,{displayName:`Keymap<heading>`,group:`Heading`});var tf=od(`blockquote`);Y(tf,{displayName:`Attr<blockquote>`,group:`Blockquote`});var nf=q(`blockquote`,e=>({content:`block+`,group:`block`,defining:!0,parseDOM:[{tag:`blockquote`}],toDOM:t=>[`blockquote`,e.get(tf.key)(t),0],parseMarkdown:{match:({type:e})=>e===`blockquote`,runner:(e,t,n)=>{e.openNode(n).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===`blockquote`,runner:(e,t)=>{e.openNode(`blockquote`).next(t.content).closeNode()}}}));Y(nf.node,{displayName:`NodeSchema<blockquote>`,group:`Blockquote`}),Y(nf.ctx,{displayName:`NodeSchemaCtx<blockquote>`,group:`Blockquote`});var rf=K(e=>Fi(/^\s*>\s$/,nf.type(e)));Y(rf,{displayName:`InputRule<wrapInBlockquoteInputRule>`,group:`Blockquote`});var af=G(`WrapInBlockquote`,e=>()=>Si(nf.type(e)));Y(af,{displayName:`Command<wrapInBlockquoteCommand>`,group:`Blockquote`});var of=J(`blockquoteKeymap`,{WrapInBlockquote:{shortcuts:`Mod-Shift-b`,command:e=>{let t=e.get(W);return()=>t.call(af.key)}}});Y(of.ctx,{displayName:`KeymapCtx<blockquote>`,group:`Blockquote`}),Y(of.shortcuts,{displayName:`Keymap<blockquote>`,group:`Blockquote`});var sf=od(`codeBlock`,()=>({pre:{},code:{}}));Y(sf,{displayName:`Attr<codeBlock>`,group:`CodeBlock`});var cf=q(`code_block`,e=>({content:`text*`,group:`block`,marks:``,defining:!0,code:!0,attrs:{language:{default:``,validate:`string`}},parseDOM:[{tag:`pre`,preserveWhitespace:`full`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{language:e.dataset.language}}}],toDOM:t=>{let n=e.get(sf.key)(t),r=t.attrs.language,i=r&&r.length>0?{"data-language":r}:void 0;return[`pre`,{...n.pre,...i},[`code`,n.code,0]]},parseMarkdown:{match:({type:e})=>e===`code`,runner:(e,t,n)=>{let r=t.lang??``,i=t.value;e.openNode(n,{language:r}),i&&e.addText(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`code_block`,runner:(e,t)=>{e.addNode(`code`,void 0,t.content.firstChild?.text||``,{lang:t.attrs.language})}}}));Y(cf.node,{displayName:`NodeSchema<codeBlock>`,group:`CodeBlock`}),Y(cf.ctx,{displayName:`NodeSchemaCtx<codeBlock>`,group:`CodeBlock`});var lf=K(e=>Ii(/^```(?<language>[a-z]*)?[\s\n]$/,cf.type(e),e=>({language:e.groups?.language??``})));Y(lf,{displayName:`InputRule<createCodeBlockInputRule>`,group:`CodeBlock`});var uf=G(`CreateCodeBlock`,e=>(t=``)=>Ci(cf.type(e),{language:t}));Y(uf,{displayName:`Command<createCodeBlockCommand>`,group:`CodeBlock`}),Y(G(`UpdateCodeBlockLanguage`,()=>({pos:e,language:t}={pos:-1,language:``})=>(n,r)=>e>=0?(r?.(n.tr.setNodeAttribute(e,`language`,t)),!0):!1),{displayName:`Command<updateCodeBlockLanguageCommand>`,group:`CodeBlock`});var df=J(`codeBlockKeymap`,{CreateCodeBlock:{shortcuts:`Mod-Alt-c`,command:e=>{let t=e.get(W);return()=>t.call(uf.key)}}});Y(df.ctx,{displayName:`KeymapCtx<codeBlock>`,group:`CodeBlock`}),Y(df.shortcuts,{displayName:`Keymap<codeBlock>`,group:`CodeBlock`});var ff=od(`image`);Y(ff,{displayName:`Attr<image>`,group:`Image`});var pf=q(`image`,e=>({inline:!0,group:`inline`,selectable:!0,draggable:!0,marks:``,atom:!0,defining:!0,isolating:!0,attrs:{src:{default:``,validate:`string`},alt:{default:``,validate:`string`},title:{default:``,validate:`string`}},parseDOM:[{tag:`img[src]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{src:e.getAttribute(`src`)||``,alt:e.getAttribute(`alt`)||``,title:e.getAttribute(`title`)||e.getAttribute(`alt`)||``}}}],toDOM:t=>[`img`,{...e.get(ff.key)(t),...t.attrs}],parseMarkdown:{match:({type:e})=>e===`image`,runner:(e,t,n)=>{let r=t.url,i=t.alt,a=t.title;e.addNode(n,{src:r,alt:i,title:a})}},toMarkdown:{match:e=>e.type.name===`image`,runner:(e,t)=>{e.addNode(`image`,void 0,void 0,{title:t.attrs.title,url:t.attrs.src,alt:t.attrs.alt})}}}));Y(pf.node,{displayName:`NodeSchema<image>`,group:`Image`}),Y(pf.ctx,{displayName:`NodeSchemaCtx<image>`,group:`Image`});var mf=G(`InsertImage`,e=>(t={})=>(n,r)=>{if(!r)return!0;let{src:i=``,alt:a=``,title:o=``}=t,s=pf.type(e).create({src:i,alt:a,title:o});return s&&r(n.tr.replaceSelectionWith(s).scrollIntoView()),!0});Y(mf,{displayName:`Command<insertImageCommand>`,group:`Image`});var hf=G(`UpdateImage`,e=>(t={})=>(n,r)=>{let i=na(n.selection,pf.type(e));if(!i)return!1;let{node:a,pos:o}=i,s={...a.attrs},{src:c,alt:l,title:u}=t;return c!==void 0&&(s.src=c),l!==void 0&&(s.alt=l),u!==void 0&&(s.title=u),r?.(n.tr.setNodeMarkup(o,void 0,s).scrollIntoView()),!0});Y(hf,{displayName:`Command<updateImageCommand>`,group:`Image`}),Y(K(e=>new M(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(t,n,r,i)=>{let[a,o,s=``,c]=n;return a?t.tr.replaceWith(r,i,pf.type(e).create({src:s,alt:o,title:c})):null})),{displayName:`InputRule<insertImageInputRule>`,group:`Image`});var gf=od(`hardbreak`,e=>({"data-type":`hardbreak`,"data-is-inline":e.attrs.isInline}));Y(gf,{displayName:`Attr<hardbreak>`,group:`Hardbreak`});var _f=q(`hardbreak`,e=>({inline:!0,group:`inline`,attrs:{isInline:{default:!1,validate:`boolean`}},selectable:!1,parseDOM:[{tag:`br`},{tag:`span[data-type="hardbreak"]`,getAttrs:()=>({isInline:!0})}],toDOM:t=>t.attrs.isInline?[`span`,e.get(gf.key)(t),` `]:[`br`,e.get(gf.key)(t)],parseMarkdown:{match:({type:e})=>e===`break`,runner:(e,t,n)=>{e.addNode(n,{isInline:!!t.data?.isInline})}},leafText:()=>`
32
32
  `,toMarkdown:{match:e=>e.type.name===`hardbreak`,runner:(e,t)=>{t.attrs.isInline?e.addNode(`text`,void 0,`
33
- `):e.addNode(`break`)}}}));Y(_f.node,{displayName:`NodeSchema<hardbreak>`,group:`Hardbreak`}),Y(_f.ctx,{displayName:`NodeSchemaCtx<hardbreak>`,group:`Hardbreak`});var vf=G(`InsertHardbreak`,e=>()=>(t,n)=>{let{selection:r,tr:i}=t;if(!(r instanceof O))return!1;if(r.empty){let e=r.$from.node();if(e.childCount>0&&e.lastChild?.type.name===`hardbreak`)return n?.(i.replaceRangeWith(r.to-1,r.to,t.schema.node(`paragraph`)).setSelection(D.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(i.setMeta(`hardbreak`,!0).replaceSelectionWith(_f.type(e).create()).scrollIntoView()),!0});Y(vf,{displayName:`Command<insertHardbreakCommand>`,group:`Hardbreak`});var yf=J(`hardbreakKeymap`,{InsertHardbreak:{shortcuts:`Shift-Enter`,command:e=>{let t=e.get(W);return()=>t.call(vf.key)}}});Y(yf.ctx,{displayName:`KeymapCtx<hardbreak>`,group:`Hardbreak`}),Y(yf.shortcuts,{displayName:`Keymap<hardbreak>`,group:`Hardbreak`});var bf=od(`hr`);Y(bf,{displayName:`Attr<hr>`,group:`Hr`});var xf=q(`hr`,e=>({group:`block`,parseDOM:[{tag:`hr`}],toDOM:t=>[`hr`,e.get(bf.key)(t)],parseMarkdown:{match:({type:e})=>e===`thematicBreak`,runner:(e,t,n)=>{e.addNode(n)}},toMarkdown:{match:e=>e.type.name===`hr`,runner:e=>{e.addNode(`thematicBreak`)}}}));Y(xf.node,{displayName:`NodeSchema<hr>`,group:`Hr`}),Y(xf.ctx,{displayName:`NodeSchemaCtx<hr>`,group:`Hr`});var Sf=K(e=>new M(/^(?:---|___\s|\*\*\*\s)$/,(t,n,r,i)=>{let{tr:a}=t;return n[0]&&a.replaceWith(r-1,i,xf.type(e).create()),a}));Y(Sf,{displayName:`InputRule<insertHrInputRule>`,group:`Hr`});var Cf=G(`InsertHr`,e=>()=>(t,n)=>{if(!n)return!0;let r=Hd.node.type(e).create(),{tr:i,selection:a}=t,{from:o}=a,s=xf.type(e).create();if(!s)return!0;let c=i.replaceSelectionWith(s).insert(o,r),l=D.findFrom(c.doc.resolve(o),1,!0);return l&&n(c.setSelection(l).scrollIntoView()),!0});Y(Cf,{displayName:`Command<insertHrCommand>`,group:`Hr`});var wf=od(`bulletList`);Y(wf,{displayName:`Attr<bulletList>`,group:`BulletList`});var Tf=q(`bullet_list`,e=>({content:`listItem+`,group:`block`,attrs:{spread:{default:!1,validate:`boolean`}},parseDOM:[{tag:`ul`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{spread:e.dataset.spread===`true`}}}],toDOM:t=>[`ul`,{...e.get(wf.key)(t),"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e===`list`&&!t,runner:(e,t,n)=>{let r=t.spread==null?`false`:`${t.spread}`;e.openNode(n,{spread:r}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===`bullet_list`,runner:(e,t)=>{e.openNode(`list`,void 0,{ordered:!1,spread:t.attrs.spread}).next(t.content).closeNode()}}}));Y(Tf.node,{displayName:`NodeSchema<bulletList>`,group:`BulletList`}),Y(Tf.ctx,{displayName:`NodeSchemaCtx<bulletList>`,group:`BulletList`});var Ef=K(e=>Fi(/^\s*([-+*])\s$/,Tf.type(e)));Y(Ef,{displayName:`InputRule<wrapInBulletListInputRule>`,group:`BulletList`});var Df=G(`WrapInBulletList`,e=>()=>Si(Tf.type(e)));Y(Df,{displayName:`Command<wrapInBulletListCommand>`,group:`BulletList`});var Of=J(`bulletListKeymap`,{WrapInBulletList:{shortcuts:`Mod-Alt-8`,command:e=>{let t=e.get(W);return()=>t.call(Df.key)}}});Y(Of.ctx,{displayName:`KeymapCtx<bulletListKeymap>`,group:`BulletList`}),Y(Of.shortcuts,{displayName:`Keymap<bulletListKeymap>`,group:`BulletList`});var kf=od(`orderedList`);Y(kf,{displayName:`Attr<orderedList>`,group:`OrderedList`});var Af=q(`ordered_list`,e=>({content:`listItem+`,group:`block`,attrs:{order:{default:1,validate:`number`},spread:{default:!1,validate:`boolean`}},parseDOM:[{tag:`ol`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{spread:e.dataset.spread,order:e.hasAttribute(`start`)?Number(e.getAttribute(`start`)):1}}}],toDOM:t=>[`ol`,{...e.get(kf.key)(t),...t.attrs.order===1?{}:{start:t.attrs.order},"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e===`list`&&!!t,runner:(e,t,n)=>{let r=t.spread==null?`true`:`${t.spread}`;e.openNode(n,{spread:r,order:t.start??1}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===`ordered_list`,runner:(e,t)=>{e.openNode(`list`,void 0,{ordered:!0,start:t.attrs.order??1,spread:t.attrs.spread===`true`}),e.next(t.content),e.closeNode()}}}));Y(Af.node,{displayName:`NodeSchema<orderedList>`,group:`OrderedList`}),Y(Af.ctx,{displayName:`NodeSchemaCtx<orderedList>`,group:`OrderedList`});var jf=K(e=>Fi(/^\s*(\d+)\.\s$/,Af.type(e),e=>({order:Number(e[1])}),(e,t)=>t.childCount+t.attrs.order===Number(e[1])));Y(jf,{displayName:`InputRule<wrapInOrderedListInputRule>`,group:`OrderedList`});var Mf=G(`WrapInOrderedList`,e=>()=>Si(Af.type(e)));Y(Mf,{displayName:`Command<wrapInOrderedListCommand>`,group:`OrderedList`});var Nf=J(`orderedListKeymap`,{WrapInOrderedList:{shortcuts:`Mod-Alt-7`,command:e=>{let t=e.get(W);return()=>t.call(Mf.key)}}});Y(Nf.ctx,{displayName:`KeymapCtx<orderedList>`,group:`OrderedList`}),Y(Nf.shortcuts,{displayName:`Keymap<orderedList>`,group:`OrderedList`});var Pf=od(`listItem`);Y(Pf,{displayName:`Attr<listItem>`,group:`ListItem`});var Ff=q(`list_item`,e=>({group:`listItem`,content:`paragraph block*`,attrs:{label:{default:`•`,validate:`string`},listType:{default:`bullet`,validate:`string`},spread:{default:!0,validate:`boolean`}},defining:!0,parseDOM:[{tag:`li`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread===`true`}}}],toDOM:t=>[`li`,{...e.get(Pf.key)(t),"data-label":t.attrs.label,"data-list-type":t.attrs.listType,"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:e})=>e===`listItem`,runner:(e,t,n)=>{let r=t.label==null?`•`:`${t.label}.`,i=t.label==null?`bullet`:`ordered`,a=t.spread==null?`true`:`${t.spread}`;e.openNode(n,{label:r,listType:i,spread:a}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`list_item`,runner:(e,t)=>{e.openNode(`listItem`,void 0,{spread:t.attrs.spread}),e.next(t.content),e.closeNode()}}}));Y(Ff.node,{displayName:`NodeSchema<listItem>`,group:`ListItem`}),Y(Ff.ctx,{displayName:`NodeSchemaCtx<listItem>`,group:`ListItem`});var If=G(`SinkListItem`,e=>()=>pd(Ff.type(e)));Y(If,{displayName:`Command<sinkListItemCommand>`,group:`ListItem`});var Lf=G(`LiftListItem`,e=>()=>ud(Ff.type(e)));Y(Lf,{displayName:`Command<liftListItemCommand>`,group:`ListItem`});var Rf=G(`SplitListItem`,e=>()=>ld(Ff.type(e)));Y(Rf,{displayName:`Command<splitListItemCommand>`,group:`ListItem`});function zf(e){return(t,n,r)=>{let{selection:i}=t;if(!(i instanceof O))return!1;let{empty:a,$from:o}=i;return!a||o.parentOffset!==0||o.node(-1).type!==Ff.type(e)?!1:$r(t,n,r)}}var Bf=G(`LiftFirstListItem`,e=>()=>zf(e));Y(Bf,{displayName:`Command<liftFirstListItemCommand>`,group:`ListItem`});var Vf=J(`listItemKeymap`,{NextListItem:{shortcuts:`Enter`,command:e=>{let t=e.get(W);return()=>t.call(Rf.key)}},SinkListItem:{shortcuts:[`Tab`,`Mod-]`],command:e=>{let t=e.get(W);return()=>t.call(If.key)}},LiftListItem:{shortcuts:[`Shift-Tab`,`Mod-[`],command:e=>{let t=e.get(W);return()=>t.call(Lf.key)}},LiftFirstListItem:{shortcuts:[`Backspace`,`Delete`],command:e=>{let t=e.get(W);return()=>t.call(Bf.key)}}});Y(Vf.ctx,{displayName:`KeymapCtx<listItem>`,group:`ListItem`}),Y(Vf.shortcuts,{displayName:`Keymap<listItem>`,group:`ListItem`});var Hf=td(`text`,()=>({group:`inline`,parseMarkdown:{match:({type:e})=>e===`text`,runner:(e,t)=>{e.addText(t.value)}},toMarkdown:{match:e=>e.type.name===`text`,runner:(e,t)=>{e.addNode(`text`,void 0,t.text)}}}));Y(Hf,{displayName:`NodeSchema<text>`,group:`Text`});var Uf=od(`html`);Y(Uf,{displayName:`Attr<html>`,group:`Html`});var Wf=q(`html`,e=>({atom:!0,group:`inline`,inline:!0,attrs:{value:{default:``,validate:`string`}},toDOM:t=>{let n=document.createElement(`span`),r={...e.get(Uf.key)(t),"data-value":t.attrs.value,"data-type":`html`};return n.textContent=t.attrs.value,[`span`,r,t.attrs.value]},parseDOM:[{tag:`span[data-type="html"]`,getAttrs:e=>({value:e.dataset.value??``})}],parseMarkdown:{match:({type:e})=>e===`html`,runner:(e,t,n)=>{e.addNode(n,{value:t.value})}},toMarkdown:{match:e=>e.type.name===`html`,runner:(e,t)=>{e.addNode(`html`,void 0,t.attrs.value)}}}));Y(Wf.node,{displayName:`NodeSchema<html>`,group:`Html`}),Y(Wf.ctx,{displayName:`NodeSchemaCtx<html>`,group:`Html`});var Gf=[Rd,Vd,Hd,Jd,Yd,Xd,gf,_f,tf,nf,sf,cf,bf,xf,ff,pf,wf,Tf,kf,Af,Pf,Ff,vd,yd,wd,Td,kd,Ad,Pd,Fd,Uf,Wf,Hf].flat(),Kf=[rf,Ef,jf,lf,Sf,Zd].flat(),qf=[xd,Sd,Md,Dd],Jf=[Wd,af,Qd,$d,uf,vf,Cf,mf,hf,Mf,Df,If,Rf,Lf,Bf,bd,jd,Ed,Id,Ld,G(`IsMarkSelected`,()=>e=>t=>{if(!e)return!1;let{doc:n,selection:r}=t;return n.rangeHasMark(r.from,r.to,e)}),G(`IsNoteSelected`,()=>e=>t=>e?ra(t,e).hasNode:!1),G(`ClearTextInCurrentBlock`,()=>()=>(e,t)=>{let n=e.tr,{$from:r,$to:i}=n.selection,{pos:a}=r,{pos:o}=i,s=a-r.node().content.size;return s<0?!1:(n=n.deleteRange(s,o),t?.(n),!0)}),G(`SetBlockType`,()=>e=>(t,n)=>{let{nodeType:r,attrs:i=null}=e??{};if(!r)return!1;let a=t.tr,{from:o,to:s}=a.selection;try{a.setBlockType(o,s,r,i)}catch{return!1}return n?.(a),!0}),G(`WrapInBlockType`,()=>e=>(t,n)=>{let{nodeType:r,attrs:i=null}=e??{};if(!r)return!1;let a=t.tr;try{let{$from:e,$to:t}=a.selection,n=e.blockRange(t),o=n&&Kn(n,r,i);if(!o)return!1;a=a.wrap(n,o)}catch{return!1}return n?.(a),!0}),G(`AddBlockType`,()=>e=>(t,n)=>{let{nodeType:r,attrs:i=null}=e??{};if(!r)return!1;let a=t.tr;try{let e=r instanceof St?r:r.createAndFill(i);if(!e)return!1;a.replaceSelectionWith(e)}catch{return!1}return n?.(a),!0}),G(`SelectTextNearPos`,()=>e=>(t,n)=>{let{pos:r}=e??{};if(r==null)return!1;let i=(e,t,n)=>Math.min(Math.max(e,t),n),a=t.tr;try{let e=t.doc.resolve(i(r,0,t.doc.content.size));a.setSelection(O.near(e))}catch{return!1}return n?.(a.scrollIntoView()),!0})],Yf=[of,df,yf,ef,Vf,Nf,Of,Gd,Cd,Nd,Od].flat(),Xf=cd(`remarkAddOrderInList`,()=>()=>e=>{m(e,`list`,e=>{if(e.ordered){let t=e.start??1;e.children.forEach((e,n)=>{e.label=n+t})}})});Y(Xf.plugin,{displayName:`Remark<remarkAddOrderInListPlugin>`,group:`Remark`}),Y(Xf.options,{displayName:`RemarkConfig<remarkAddOrderInListPlugin>`,group:`Remark`});var Zf=cd(`remarkLineBreak`,()=>()=>e=>{let t=/[\t ]*(?:\r?\n|\r)/g;m(e,`text`,(e,n,r)=>{if(!e.value||typeof e.value!=`string`)return;let i=[],a=0;t.lastIndex=0;let o=t.exec(e.value);for(;o;){let n=o.index;a!==n&&i.push({type:`text`,value:e.value.slice(a,n)}),i.push({type:`break`,data:{isInline:!0}}),a=n+o[0].length,o=t.exec(e.value)}if(i.length>0&&r&&typeof n==`number`)return a<e.value.length&&i.push({type:`text`,value:e.value.slice(a)}),r.children.splice(n,1,...i),n+i.length})});Y(Zf.plugin,{displayName:`Remark<remarkLineBreak>`,group:`Remark`}),Y(Zf.options,{displayName:`RemarkConfig<remarkLineBreak>`,group:`Remark`});var Qf=cd(`remarkInlineLink`,()=>gd);Y(Qf.plugin,{displayName:`Remark<remarkInlineLinkPlugin>`,group:`Remark`}),Y(Qf.options,{displayName:`RemarkConfig<remarkInlineLinkPlugin>`,group:`Remark`});var $f=e=>!!e.children,ep=e=>e.type===`html`;function tp(e,t){return n(e,0,null)[0];function n(e,r,i){if($f(e)){let t=[];for(let r=0,i=e.children.length;r<i;r++){let i=e.children[r];if(i){let a=n(i,r,e);if(a)for(let e=0,n=a.length;e<n;e++){let n=a[e];n&&t.push(n)}}}e.children=t}return t(e,r,i)}}var np=[`root`,`blockquote`,`listItem`],rp=cd(`remarkHTMLTransformer`,()=>()=>e=>{tp(e,(e,t,n)=>(ep(e)&&n&&np.includes(n.type)&&(e.children=[{...e}],delete e.value,e.type=`paragraph`),[e]))});Y(rp.plugin,{displayName:`Remark<remarkHtmlTransformer>`,group:`Remark`}),Y(rp.options,{displayName:`RemarkConfig<remarkHtmlTransformer>`,group:`Remark`});var ip=cd(`remarkMarker`,()=>()=>(e,t)=>{let n=e=>t.value.charAt(e.position.start.offset);m(e,e=>[`strong`,`emphasis`].includes(e.type),e=>{e.marker=n(e)})});Y(ip.plugin,{displayName:`Remark<remarkMarker>`,group:`Remark`}),Y(ip.options,{displayName:`RemarkConfig<remarkMarker>`,group:`Remark`});var ap=nd(()=>{let e=!1,t=new A({key:new j(`MILKDOWN_INLINE_NODES_CURSOR`),state:{init(){return!1},apply(e){if(!e.selection.empty)return!1;let t=e.selection.$from,n=t.nodeBefore,r=t.nodeAfter;return!!(n&&r&&n.isInline&&!n.isText&&r.isInline&&!r.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>e?(e=!1,requestAnimationFrame(()=>{if(t.getState(n.state)){let e=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||``,e))}}),!0):!1,compositionstart:n=>(t.getState(n.state)&&(e=!0),!1),beforeinput:(n,r)=>{if(t.getState(n.state)&&r instanceof InputEvent&&r.data&&!e){let e=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||``,e)),!0}return!1}},decorations(e){if(t.getState(e)){let t=e.selection.$from.pos,n=document.createElement(`span`),r=Wc.widget(t,n,{side:-1}),i=document.createElement(`span`),a=Wc.widget(t,i);return setTimeout(()=>{n.contentEditable=`true`,i.contentEditable=`true`}),V.create(e.doc,[r,a])}return V.empty}}});return t});Y(ap,{displayName:`Prose<inlineNodesCursorPlugin>`,group:`Prose`});var op=nd(e=>new A({key:new j(`MILKDOWN_HARDBREAK_MARKS`),appendTransaction:(t,n,r)=>{if(!t.length)return;let[i]=t;if(!i)return;let[a]=i.steps;if(i.getMeta(`hardbreak`)){if(!(a instanceof Ln))return;let{from:t}=a;return r.tr.setNodeMarkup(t,_f.type(e),void 0,[])}if(a instanceof Nn){let t=r.tr,{from:n,to:i}=a;return r.doc.nodesBetween(n,i,(n,r)=>{n.type===_f.type(e)&&(t=t.setNodeMarkup(r,_f.type(e),void 0,[]))}),t}}}));Y(op,{displayName:`Prose<hardbreakClearMarkPlugin>`,group:`Prose`});var sp=id([`table`,`code_block`],`hardbreakFilterNodes`);Y(sp,{displayName:`Ctx<hardbreakFilterNodes>`,group:`Prose`});var cp=nd(e=>{let t=e.get(sp.key);return new A({key:new j(`MILKDOWN_HARDBREAK_FILTER`),filterTransaction:(e,n)=>{let r=e.getMeta(`hardbreak`),[i]=e.steps;if(r&&i){let{from:e}=i,r=n.doc.resolve(e),a=r.depth,o=!0;for(;a>0;)t.includes(r.node(a).type.name)&&(o=!1),a--;return o}return!0}})});Y(cp,{displayName:`Prose<hardbreakFilterPlugin>`,group:`Prose`});var lp=nd(e=>{let t=new j(`MILKDOWN_HEADING_ID`),n=n=>{if(n.composing)return;let r=e.get(Jd.key),i=n.state.tr.setMeta(`addToHistory`,!1),a=!1,o={};n.state.doc.descendants((n,s)=>{if(n.type===Xd.type(e)){if(n.textContent.trim().length===0)return;let e=n.attrs,c=r(n);o[c]?(o[c]+=1,c+=`-#${o[c]}`):o[c]=1,e.id!==c&&(a=!0,i.setMeta(t,!0).setNodeMarkup(s,void 0,{...e,id:c}))}}),a&&n.dispatch(i)};return new A({key:t,view:e=>(n(e),{update:(e,t)=>{e.state.doc.eq(t.doc)||n(e)}})})});Y(lp,{displayName:`Prose<syncHeadingIdPlugin>`,group:`Prose`});var up=nd(e=>new A({key:new j(`MILKDOWN_KEEP_LIST_ORDER`),appendTransaction:(t,n,r)=>{if(!r.selection||t.some(e=>e.getMeta(`addToHistory`)===!1||!e.isGeneric))return null;let i=Af.type(e),a=Tf.type(e),o=Ff.type(e),s=(e,t,n=1)=>{let r=!1,i=`${t+n}.`;return e.label!==i&&(e.label=i,r=!0),r},c=r.tr,l=!1;return r.doc.descendants((e,t,n,r)=>{if(e.type===a){let n=e.maybeChild(0);n?.type===o&&n.attrs.listType===`ordered`&&(l=!0,c.setNodeMarkup(t,i,{spread:`true`}),e.descendants((e,t,n,r)=>{if(e.type===o){let n={...e.attrs};s(n,r)&&(c=c.setNodeMarkup(t,void 0,n))}return!1}))}else if(e.type===o&&n?.type===i){let i={...e.attrs},a=!1;i.listType!==`ordered`&&(i.listType=`ordered`,a=!0),n?.maybeChild(0)&&(a=s(i,r,n?.attrs.order??1)),a&&(c=c.setNodeMarkup(t,void 0,i),l=!0)}}),l?c.setMeta(`addToHistory`,!1):null}}));Y(up,{displayName:`Prose<syncListOrderPlugin>`,group:`Prose`});var dp=[Gf,Kf,qf,Jf,Yf,[op,sp,cp,ap,Xf,Qf,Zf,rp,ip,Bd,lp,up].flat()].flat(),fp,pp;if(typeof WeakMap<`u`){let e=new WeakMap;fp=t=>e.get(t),pp=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;fp=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},pp=(n,r)=>(t==10&&(t=0),e[t++]=n,e[t++]=r)}var X=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,a=r+1,o=i+1;for(let e=1;a<this.width&&this.map[t+e]==n;e++)a++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:a,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:a,bottom:o}=this.findCell(e);return t==`horiz`?(n<0?r==0:i==this.width)?null:this.map[a*this.width+(n<0?r-1:i)]:(n<0?a==0:o==this.height)?null:this.map[r+this.width*(n<0?a-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:a}=this.findCell(e),{left:o,right:s,top:c,bottom:l}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,c),right:Math.max(r,s),bottom:Math.max(a,l)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let a=r*this.width+i,o=this.map[a];n[o]||(n[o]=!0,!(i==e.left&&i&&this.map[a-1]==o||r==e.top&&r&&this.map[a-this.width]==o)&&t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let a=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?a-1:this.map[n]}i=a}}static get(e){return fp(e)||pp(e,mp(e))}};function mp(e){if(e.type.spec.tableRole!=`table`)throw RangeError(`Not a table node: `+e.type.name);let t=hp(e),n=e.childCount,r=[],i=0,a=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let s=0,c=0;s<n;s++){let l=e.child(s);c++;for(let e=0;;e++){for(;i<r.length&&r[i]!=0;)i++;if(e==l.childCount)break;let u=l.child(e),{colspan:d,rowspan:f,colwidth:p}=u.attrs;for(let e=0;e<f;e++){if(e+s>=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;e<d;e++){r[l+e]==0?r[l+e]=c:(a||=[]).push({type:`collision`,row:s,pos:c,n:d-e});let n=p&&p[e];if(n){let r=(l+e)%t*2,i=o[r];i==null||i!=n&&o[r+1]==1?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=d,c+=u.nodeSize}let u=(s+1)*t,d=0;for(;i<u;)r[i++]==0&&d++;d&&(a||=[]).push({type:`missing`,row:s,n:d}),c++}(t===0||n===0)&&(a||=[]).push({type:`zero_sized`});let s=new X(t,n,r,a),c=!1;for(let e=0;!c&&e<o.length;e+=2)o[e]!=null&&o[e+1]<n&&(c=!0);return c&&gp(s,o,e),s}function hp(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),a=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(a+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);a+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function gp(e,t,n){e.problems||=[];let r={};for(let i=0;i<e.map.length;i++){let a=e.map[i];if(r[a])continue;r[a]=!0;let o=n.nodeAt(a);if(!o)throw RangeError(`No cell with offset ${a} found`);let s=null,c=o.attrs;for(let n=0;n<c.colspan;n++){let r=t[(i+n)%e.width*2];r!=null&&(!c.colwidth||c.colwidth[n]!=r)&&((s||=_p(c))[n]=r)}s&&e.problems.unshift({type:`colwidth mismatch`,pos:a,colwidth:s})}}function _p(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function vp(e,t){if(typeof e==`string`)return{};let n=e.getAttribute(`data-colwidth`),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(`,`).map(e=>Number(e)):null,i=Number(e.getAttribute(`colspan`)||1),a={colspan:i,rowspan:Number(e.getAttribute(`rowspan`)||1),colwidth:r&&r.length==i?r:null};for(let n in t){let r=t[n].getFromDOM,i=r&&r(e);i!=null&&(a[n]=i)}return a}function yp(e,t){let n={};e.attrs.colspan!=1&&(n.colspan=e.attrs.colspan),e.attrs.rowspan!=1&&(n.rowspan=e.attrs.rowspan),e.attrs.colwidth&&(n[`data-colwidth`]=e.attrs.colwidth.join(`,`));for(let r in t){let i=t[r].setDOMAttr;i&&i(e.attrs[r],n)}return n}function bp(e){if(e!==null){if(!Array.isArray(e))throw TypeError(`colwidth must be null or an array`);for(let t of e)if(typeof t!=`number`)throw TypeError(`colwidth must be null or an array of numbers`)}}function xp(e){let t=e.cellAttributes||{},n={colspan:{default:1,validate:`number`},rowspan:{default:1,validate:`number`},colwidth:{default:null,validate:bp}};for(let e in t)n[e]={default:t[e].default,validate:t[e].validate};return{table:{content:`table_row+`,tableRole:`table`,isolating:!0,group:e.tableGroup,parseDOM:[{tag:`table`}],toDOM(){return[`table`,[`tbody`,0]]}},table_row:{content:`(table_cell | table_header)*`,tableRole:`row`,parseDOM:[{tag:`tr`}],toDOM(){return[`tr`,0]}},table_cell:{content:e.cellContent,attrs:n,tableRole:`cell`,isolating:!0,parseDOM:[{tag:`td`,getAttrs:e=>vp(e,t)}],toDOM(e){return[`td`,yp(e,t),0]}},table_header:{content:e.cellContent,attrs:n,tableRole:`header_cell`,isolating:!0,parseDOM:[{tag:`th`,getAttrs:e=>vp(e,t)}],toDOM(e){return[`th`,yp(e,t),0]}}}}function Sp(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(let n in e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var Cp=new j(`selectingCells`);function wp(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function Tp(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function Ep(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=wp(t.$head)||Dp(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function Dp(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function Op(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function kp(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Ap(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function jp(e,t,n){let r=e.node(-1),i=X.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function Mp(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function Np(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}function Pp(e,t,n){let r=Sp(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var Z=class e extends D{constructor(e,t=e){let n=e.node(-1),r=X.get(n),i=e.start(-1),a=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),s=r.cellsInRect(a).filter(e=>e!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new Ar(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(Op(r)&&Op(i)&&Ap(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return O.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=X.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let a=n*t.width+r.left,s=r.left;s<r.right;s++,a++){let n=t.map[a];if(i[n])continue;i[n]=!0;let s=t.findCell(n),c=e.nodeAt(n);if(!c)throw RangeError(`No cell with offset ${n} found`);let l=r.left-s.left,u=s.right-r.right;if(l>0||u>0){let e=c.attrs;if(l>0&&(e=Mp(e,0,l)),u>0&&(e=Mp(e,e.colspan-u,u)),s.left<r.left){if(c=c.type.createAndFill(e),!c)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else c=c.type.create(e,c.content)}if(s.top<r.top||s.bottom>r.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top<r.top?c.type.createAndFill(e):c.type.create(e,c.content)}o.push(c)}a.push(e.child(n).copy(S.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:a;return new w(S.from(o),1,1)}replace(e,t=w.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n);e.replace(s.map(a.pos),s.map(o.pos),i?w.empty:t)}let i=D.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new w(S.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=X.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=X.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom<i.height&&(n=c.resolve(a+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=c.resolve(a+i.map[s.left])),o.bottom<i.height&&(t=c.resolve(a+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=X.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);if(Math.min(r,i)>0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=X.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right<i.width&&(n=c.resolve(a+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right<i.width&&(t=c.resolve(a+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:`cell`,anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new Fp(this.$anchorCell.pos,this.$headCell.pos)}};Z.prototype.visible=!1,D.jsonID(`cell`,Z);var Fp=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole==`row`&&n.parent.type.spec.tableRole==`row`&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&Ap(t,n)?new Z(t,n):D.near(n,1)}};function Ip(e){if(!(e.selection instanceof Z))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(Wc.node(n,n+e.nodeSize,{class:`selectedCell`}))}),V.create(e.doc,t)}function Lp({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function Rp({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function zp(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof k&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=Z.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=Z.rowSelection(e,e)}else if(!n){let e=X.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=Z.create(i,t+1,n)}}else r instanceof O&&Lp(r)?a=O.create(i,r.from):r instanceof O&&Rp(r)&&(a=O.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var Bp=new j(`fix-tables`);function Vp(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o<a;o++){let a=t.child(o);for(let t=s,r=Math.min(i,o+3);t<r;t++)if(e.child(t)==a){s=t+1,n+=a.nodeSize;continue outer}r(a,n),s<i&&e.child(s).sameMarkup(a)?Vp(e.child(s),a,n+1,r):a.nodesBetween(0,a.content.size,r,n+1),n+=a.nodeSize}}function Hp(e,t){let n,r=(t,r)=>{t.type.spec.tableRole==`table`&&(n=Up(e,t,r,n))};return t?t.doc!=e.doc&&Vp(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Up(e,t,n,r){let i=X.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e<i.height;e++)a.push(0);for(let e=0;e<i.problems.length;e++){let o=i.problems[e];if(o.type==`collision`){let e=t.nodeAt(o.pos);if(!e)continue;let i=e.attrs;for(let e=0;e<i.rowspan;e++)a[o.row+e]+=o.n;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,Mp(i,i.colspan-o.n,o.n))}else if(o.type==`missing`)a[o.row]+=o.n;else if(o.type==`overlong_rowspan`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-o.n})}else if(o.type==`colwidth mismatch`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,colwidth:o.colwidth})}else if(o.type==`zero_sized`){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}let o,s;for(let e=0;e<a.length;e++)a[e]&&(o??=e,s=e);for(let c=0,l=n+1;c<i.height;c++){let n=t.child(c),i=l+n.nodeSize,u=a[c];if(u>0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<u;n++){let n=Sp(e.schema)[t].createAndFill();n&&a.push(n)}let d=(c==0||o==c-1)&&s==c?l+1:i-1;r.insert(r.mapping.map(d),a)}l=i}return r.setMeta(Bp,{fixTables:!0})}function Wp(e){let t=X.get(e),n=[],r=t.height,i=t.width;for(let a=0;a<r;a++){let r=[];for(let n=0;n<i;n++){let o=a*i+n,s=t.map[o];if(a>0){let e=o-i;if(s===t.map[e]){r.push(null);continue}}if(n>0){let e=o-1;if(s===t.map[e]){r.push(null);continue}}r.push(e.nodeAt(s))}n.push(r)}return n}function Gp(e,t){let n=[],r=X.get(e),i=r.height,a=r.width;for(let o=0;o<i;o++){let i=e.child(o),s=[];for(let n=0;n<a;n++){let i=t[o][n];if(!i)continue;let a=r.map[o*r.width+n],c=e.nodeAt(a);if(!c)continue;let l=c.type.createChecked(i.attrs,i.content,i.marks);s.push(l)}let c=i.type.createChecked(i.attrs,s,i.marks);n.push(c)}return e.type.createChecked(e.attrs,n,e.marks)}function Kp(e,t,n,r){let i=t[0]>n[0]?-1:1,a=e.splice(t[0],t.length),o=+(a.length%2==0),s;return s=r===-1&&i===1?n[0]-1:r===1&&i===-1?n[n.length-1]-o+1:i===-1?n[0]:n[n.length-1]-o,e.splice(s,0,...a),e}function qp(e){return Jp(e=>e.type.spec.tableRole===`table`,e)}function Jp(e,t){for(let n=t.depth;n>=0;--n){let r=t.node(n);if(e(r))return{node:r,pos:n===0?0:t.before(n),start:t.start(n),depth:n}}return null}function Yp(e,t){let n=qp(t.$from);if(!n)return;let r=X.get(n.node);if(!(e<0||e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function Xp(e,t){let n=qp(t.$from);if(!n)return;let r=X.get(n.node);if(!(e<0||e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function Zp(e,t,n=t){let r=t,i=n;for(let n=t;n>=0;n--){let t=Yp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;t>=r&&(r=n),t>i&&(i=t)})}for(let n=t;n<=i;n++){let t=Yp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;e.node.attrs.colspan>1&&t>i&&(i=t)})}let a=[];for(let t=r;t<=i;t++){let n=Yp(t,e.selection);n&&n.length>0&&a.push(t)}r=a[0],i=a[a.length-1];let o=Yp(r,e.selection),s=Xp(0,e.selection);if(!o||!s)return;let c=e.doc.resolve(o[o.length-1].pos),l;for(let t=i;t>=r;t--){let n=Yp(t,e.selection);if(n&&n.length>0){for(let e=s.length-1;e>=0;e--)if(s[e].pos===n[0].pos){l=n[0];break}if(l)break}}if(l)return{$anchor:c,$head:e.doc.resolve(l.pos),indexes:a}}function Qp(e,t,n=t){let r=t,i=n;for(let n=t;n>=0;n--){let t=Xp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;t>=r&&(r=n),t>i&&(i=t)})}for(let n=t;n<=i;n++){let t=Xp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;e.node.attrs.rowspan>1&&t>i&&(i=t)})}let a=[];for(let t=r;t<=i;t++){let n=Xp(t,e.selection);n&&n.length>0&&a.push(t)}r=a[0],i=a[a.length-1];let o=Xp(r,e.selection),s=Yp(0,e.selection);if(!o||!s)return;let c=e.doc.resolve(o[o.length-1].pos),l;for(let t=i;t>=r;t--){let n=Xp(t,e.selection);if(n&&n.length>0){for(let e=s.length-1;e>=0;e--)if(s[e].pos===n[0].pos){l=n[0];break}if(l)break}}if(l)return{$anchor:c,$head:e.doc.resolve(l.pos),indexes:a}}function $p(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function em(e){let{tr:t,originIndex:n,targetIndex:r,select:i,pos:a}=e,o=qp(t.doc.resolve(a));if(!o)return!1;let s=Zp(t,n)?.indexes,c=Zp(t,r)?.indexes;if(!s||!c||s.includes(r))return!1;let l=tm(o.node,s,c,0);if(t.replaceWith(o.pos,o.pos+o.node.nodeSize,l),!i)return!0;let u=X.get(l),d=o.start,f=r,p=u.positionAt(u.height-1,f,l),m=t.doc.resolve(d+p),h=u.positionAt(0,f,l),g=t.doc.resolve(d+h);return t.setSelection(Z.colSelection(m,g)),!0}function tm(e,t,n,r){let i=$p(Wp(e));return i=Kp(i,t,n,r),i=$p(i),Gp(e,i)}function nm(e){let{tr:t,originIndex:n,targetIndex:r,select:i,pos:a}=e,o=qp(t.doc.resolve(a));if(!o)return!1;let s=Qp(t,n)?.indexes,c=Qp(t,r)?.indexes;if(!s||!c||s.includes(r))return!1;let l=rm(o.node,s,c,0);if(t.replaceWith(o.pos,o.pos+o.node.nodeSize,l),!i)return!0;let u=X.get(l),d=o.start,f=r,p=u.positionAt(f,u.width-1,l),m=t.doc.resolve(d+p),h=u.positionAt(f,0,l),g=t.doc.resolve(d+h);return t.setSelection(Z.rowSelection(m,g)),!0}function rm(e,t,n,r){let i=Wp(e);return i=Kp(i,t,n,r),Gp(e,i)}function im(e){let t=e.selection,n=Ep(e),r=n.node(-1),i=n.start(-1),a=X.get(r);return{...t instanceof Z?a.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):a.findCell(n.pos-i),tableStart:i,map:a,table:r}}function am(e,{map:t,tableStart:n,table:r},i){let a=i>0?-1:0;Pp(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o<t.height;o++){let s=o*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){let a=t.map[s],c=r.nodeAt(a);e.setNodeMarkup(e.mapping.map(n+a),null,Np(c.attrs,i-t.colCount(a))),o+=c.attrs.rowspan-1}else{let c=a==null?Sp(r.type.schema).cell:r.nodeAt(t.map[s+a]).type,l=t.positionAt(o,i,r);e.insert(e.mapping.map(n+l),c.createAndFill())}}return e}function om(e,t){if(!Tp(e))return!1;if(t){let n=im(e);t(am(e.tr,n,n.left))}return!0}function sm(e,t){if(!Tp(e))return!1;if(t){let n=im(e);t(am(e.tr,n,n.right))}return!0}function cm(e,{map:t,table:n,tableStart:r},i){let a=e.mapping.maps.length;for(let o=0;o<t.height;){let s=o*t.width+i,c=t.map[s],l=n.nodeAt(c),u=l.attrs;if(i>0&&t.map[s-1]==c||i<t.width-1&&t.map[s+1]==c)e.setNodeMarkup(e.mapping.slice(a).map(r+c),null,Mp(u,i-t.colCount(c)));else{let t=e.mapping.slice(a).map(r+c);e.delete(t,t+l.nodeSize)}o+=u.rowspan}}function lm(e,t){if(!Tp(e))return!1;if(t){let n=im(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let e=n.right-1;cm(r,n,e),e!=n.left;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=X.get(e)}t(r)}return!0}function um(e,{map:t,table:n,tableStart:r},i){let a=0;for(let e=0;e<i;e++)a+=n.child(e).nodeSize;let o=a+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(a+r,o+r);let c=new Set;for(let a=0,o=i*t.width;a<t.width;a++,o++){let l=t.map[o];if(!c.has(l)){if(c.add(l),i>0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i<t.height&&l==t.map[o+t.width]){let o=n.nodeAt(l),c=o.attrs,u=o.type.create({...c,rowspan:o.attrs.rowspan-1},o.content),d=t.positionAt(i+1,a,n);e.insert(e.mapping.slice(s).map(r+d),u),a+=c.colspan-1}}}}function dm(e,t){if(!Tp(e))return!1;if(t){let n=im(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;um(r,n,e),e!=n.top;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=X.get(n.table)}t(r)}return!0}function fm(e,t){return function(n,r){if(!Tp(n))return!1;let i=Ep(n);if(i.nodeAfter.attrs[e]===t)return!1;if(r){let a=n.tr;n.selection instanceof Z?n.selection.forEachCell((n,r)=>{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function pm(e){return function(t,n){if(!Tp(t))return!1;if(n){let r=Sp(t.schema),i=im(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)s[e].type==r.header_cell&&a.setNodeMarkup(i.tableStart+o[e],r.cell,s[e].attrs);if(a.steps.length===0)for(let e=0;e<o.length;e++)a.setNodeMarkup(i.tableStart+o[e],r.header_cell,s[e].attrs);n(a)}return!0}}function mm(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:e==`row`?t.map.width:1,bottom:e==`column`?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function hm(e,t){return t||={useDeprecatedLogic:!1},t.useDeprecatedLogic?pm(e):function(t,n){if(!Tp(t))return!1;if(n){let r=Sp(t.schema),i=im(t),a=t.tr,o=mm(`row`,i,r),s=mm(`column`,i,r),c=(e===`column`?o:e===`row`&&s)?1:0,l=e==`column`?{left:0,top:c,right:1,bottom:i.map.height}:e==`row`?{left:c,top:0,right:i.map.width,bottom:1}:i,u=e==`column`?s?r.cell:r.header_cell:e==`row`?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(l).forEach(e=>{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}hm(`row`,{useDeprecatedLogic:!0}),hm(`column`,{useDeprecatedLogic:!0}),hm(`cell`,{useDeprecatedLogic:!0});function gm(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}function _m(e){return function(t,n){if(!Tp(t))return!1;let r=gm(Ep(t),e);if(r==null)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(O.between(e,kp(e))).scrollIntoView())}return!0}}function vm(e,t){let n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function ym(e,t){let n=e.selection;if(!(n instanceof Z))return!1;if(t){let r=e.tr,i=Sp(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new w(i,0,0))}),r.docChanged&&t(r)}return!0}function bm(e){return(t,n)=>{let{from:r,to:i,select:a=!0,pos:o=t.selection.from}=e,s=t.tr;return nm({tr:s,originIndex:r,targetIndex:i,select:a,pos:o})?(n?.(s),!0):!1}}function xm(e){return(t,n)=>{let{from:r,to:i,select:a=!0,pos:o=t.selection.from}=e,s=t.tr;return em({tr:s,originIndex:r,targetIndex:i,select:a,pos:o})?(n?.(s),!0):!1}}function Sm(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,a=e?0:Math.max(0,n-1),c=e<t.childCount-1?0:Math.max(0,r-1);(a||c)&&(i=wm(Sp(o).row,new w(i,a,c)).content),s.push(i)}else if(a==`cell`||a==`header_cell`)s.push(n||r?wm(Sp(o).row,new w(t,n,r)).content:t);else return null;return Cm(o,s)}function Cm(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+a}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(S.empty),n[i]<r){let a=Sp(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(a);t[i]=t[i].append(S.from(o))}return{height:t.length,width:r,rows:t}}function wm(e,t){let n=e.createAndFill();return new Or(n).replace(0,n.content.size,t).doc}function Tm({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let a=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let s=a.child(i%a.childCount);n+s.attrs.colspan>r&&(s=s.type.createChecked(Mp(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+s.attrs.colspan}i.push(S.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,a=0;r<i;r++,a++){let o=[],s=n[a%t];for(let e=0;e<s.childCount;e++){let t=s.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(S.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function Em(e,t,n,r,i,a,o){let s=e.doc.type.schema,c=Sp(s),l,u;if(i>t.width)for(let a=0,s=0;a<t.height;a++){let d=n.child(a);s+=d.nodeSize;let f=[],p;p=d.lastChild==null||d.lastChild.type==c.cell?l||=c.cell.createAndFill():u||=c.header_cell.createAndFill();for(let e=t.width;e<i;e++)f.push(p);e.insert(e.mapping.slice(o).map(s-1+r),f)}if(a>t.height){let s=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=e>=t.width?!1:n.nodeAt(t.map[r+e]).type==c.header_cell;s.push(i?u||=c.header_cell.createAndFill():l||=c.cell.createAndFill())}let d=c.row.create(null,S.from(s)),f=[];for(let e=t.height;e<a;e++)f.push(d);e.insert(e.mapping.slice(o).map(r+n.nodeSize-2),f)}return!!(l||u)}function Dm(e,t,n,r,i,a,o,s){if(o==0||o==t.height)return!1;let c=!1;for(let l=i;l<a;l++){let i=o*t.width+l,a=t.map[i];if(t.map[i-t.width]==a){c=!0;let i=n.nodeAt(a),{top:u,left:d}=t.findCell(a);e.setNodeMarkup(e.mapping.slice(s).map(a+r),null,{...i.attrs,rowspan:o-u}),e.insert(e.mapping.slice(s).map(t.positionAt(o,d,n)),i.type.createAndFill({...i.attrs,rowspan:u+i.attrs.rowspan-o})),l+=i.attrs.colspan-1}}return c}function Om(e,t,n,r,i,a,o,s){if(o==0||o==t.width)return!1;let c=!1;for(let l=i;l<a;l++){let i=l*t.width+o,a=t.map[i];if(t.map[i-1]==a){c=!0;let i=n.nodeAt(a),u=t.colCount(a),d=e.mapping.slice(s).map(a+r);e.setNodeMarkup(d,null,Mp(i.attrs,o-u,i.attrs.colspan-(o-u))),e.insert(d+i.nodeSize,i.type.createAndFill(Mp(i.attrs,0,o-u))),l+=i.attrs.rowspan-1}}return c}function km(e,t,n,r,i){let a=n?e.doc.nodeAt(n-1):e.doc;if(!a)throw Error(`No table found`);let o=X.get(a),{top:s,left:c}=r,l=c+i.width,u=s+i.height,d=e.tr,f=0;function p(){if(a=n?d.doc.nodeAt(n-1):d.doc,!a)throw Error(`No table found`);o=X.get(a),f=d.mapping.maps.length}Em(d,o,a,n,l,u,f)&&p(),Dm(d,o,a,n,c,l,s,f)&&p(),Dm(d,o,a,n,c,l,u,f)&&p(),Om(d,o,a,n,s,u,c,f)&&p(),Om(d,o,a,n,s,u,l,f)&&p();for(let e=s;e<u;e++){let t=o.positionAt(e,c,a),r=o.positionAt(e,l,a);d.replace(d.mapping.slice(f).map(t+n),d.mapping.slice(f).map(r+n),new w(i.rows[e-s],0,0))}p(),d.setSelection(new Z(d.doc.resolve(n+o.positionAt(s,c,a)),d.doc.resolve(n+o.positionAt(u-1,l-1,a)))),t(d)}var Am=ua({ArrowLeft:Mm(`horiz`,-1),ArrowRight:Mm(`horiz`,1),ArrowUp:Mm(`vert`,-1),ArrowDown:Mm(`vert`,1),"Shift-ArrowLeft":Nm(`horiz`,-1),"Shift-ArrowRight":Nm(`horiz`,1),"Shift-ArrowUp":Nm(`vert`,-1),"Shift-ArrowDown":Nm(`vert`,1),Backspace:ym,"Mod-Backspace":ym,Delete:ym,"Mod-Delete":ym});function jm(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function Mm(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection;if(a instanceof Z)return jm(n,r,D.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=Lm(i,e,t);if(o==null)return!1;if(e==`horiz`)return jm(n,r,D.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=jp(i,e,t),s;return s=a?D.near(a,1):t<0?D.near(n.doc.resolve(i.before(-1)),-1):D.near(n.doc.resolve(i.after(-1)),1),jm(n,r,s)}}}function Nm(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof Z)o=a;else{let r=Lm(i,e,t);if(r==null)return!1;o=new Z(n.doc.resolve(r))}let s=jp(o.$headCell,e,t);return s?jm(n,r,new Z(o.$anchorCell,s)):!1}}function Pm(e,t){let n=e.state.doc,r=wp(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new Z(r))),!0):!1}function Fm(e,t,n){if(!Tp(e.state))return!1;let r=Sm(n),i=e.state.selection;if(i instanceof Z){r||={width:1,height:1,rows:[S.from(wm(Sp(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=X.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=Tm(r,o.right-o.left,o.bottom-o.top),km(e.state,e.dispatch,a,o,r),!0}else if(r){let t=Ep(e.state),n=t.start(-1);return km(e.state,e.dispatch,n,X.get(t.node(-1)).findCell(t.pos-n),r),!0}else return!1}function Im(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=Rm(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof Z)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=wp(e.state.selection.$anchor))!=null&&zm(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=zm(e,n),i=Cp.getState(e.state)==null;if(!r||!Ap(t,r))if(i)r=t;else return;let a=new Z(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(Cp,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),Cp.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(Cp,-1))}function o(r){let o=r,s=Cp.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(Rm(e,o.target)!=n&&(c=zm(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function Lm(e,t,n){if(!(e.state.selection instanceof O))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function Rm(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function zm(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&wp(e.state.doc.resolve(r))||wp(e.state.doc.resolve(i))}var Bm=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),Vm(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type?(this.node=e,Vm(e,this.colgroup,this.table,this.defaultCellMinWidth),!0):!1}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function Vm(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;e<l.childCount;e++){let{colspan:u,colwidth:d}=l.child(e).attrs;for(let e=0;e<u;e++,n++){let l=i==n?a:d&&d[e],u=l?l+`px`:``;if(o+=l||r,l||(s=!1),c)c.style.width!=u&&(c.style.width=u),c=c.nextSibling;else{let e=document.createElement(`col`);e.style.width=u,t.appendChild(e)}}}for(;c;){var u;let e=c.nextSibling;(u=c.parentNode)==null||u.removeChild(c),c=e}s?(n.style.width=o+`px`,n.style.minWidth=``):(n.style.width=``,n.style.minWidth=o+`px`)}}var Q=new j(`tableColumnResizing`);function Hm({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Bm,lastColumnResizable:i=!0}={}){let a=new A({key:Q,state:{init(e,t){var i;let o=(i=a.spec)==null||(i=i.props)==null?void 0:i.nodeViews,s=Sp(t.schema).table.name;return r&&o&&(o[s]=(e,t)=>new r(e,n,t)),new Um(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=Q.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{Wm(t,n,e,i)},mouseleave:e=>{Gm(e)},mousedown:(e,r)=>{Km(e,r,t,n)}},decorations:e=>{let t=Q.getState(e);if(t&&t.activeHandle>-1)return th(e,t.activeHandle)},nodeViews:{}}});return a}var Um=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(Q);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return Op(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function Wm(e,t,n,r){if(!e.editable)return;let i=Q.getState(e.state);if(i&&!i.dragging){let a=Jm(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=Ym(e,t,`left`,n):i-t.clientX<=n&&(o=Ym(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=X.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}Zm(e,o)}}}function Gm(e){if(!e.editable)return;let t=Q.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Zm(e,-1)}function Km(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=Q.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=qm(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(Q,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=Q.getState(e.state);r?.dragging&&(Qm(e,r.activeHandle,Xm(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(Q,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=Q.getState(e.state);if(i&&i.dragging){let a=Xm(i.dragging,t,n);$m(e,i.activeHandle,a,r)}}return $m(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function qm(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;e<n;e++)r[e]&&(o-=r[e],s--);return o/s}function Jm(e){for(;e&&e.nodeName!=`TD`&&e.nodeName!=`TH`;)e=e.classList&&e.classList.contains(`ProseMirror`)?null:e.parentNode;return e}function Ym(e,t,n,r){let i=n==`right`?-r:r,a=e.posAtCoords({left:t.clientX+i,top:t.clientY});if(!a)return-1;let{pos:o}=a,s=wp(e.state.doc.resolve(o));if(!s)return-1;if(n==`right`)return s.pos;let c=X.get(s.node(-1)),l=s.start(-1),u=c.map.indexOf(s.pos-l);return u%c.width==0?-1:l+c.map[u-1]}function Xm(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Zm(e,t){e.dispatch(e.state.tr.setMeta(Q,{setHandle:t}))}function Qm(e,t,n){let r=e.state.doc.resolve(t),i=r.node(-1),a=X.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,c=e.state.tr;for(let e=0;e<a.height;e++){let t=e*a.width+s;if(e&&a.map[t]==a.map[t-a.width])continue;let r=a.map[t],l=i.nodeAt(r).attrs,u=l.colspan==1?0:s-a.colCount(r);if(l.colwidth&&l.colwidth[u]==n)continue;let d=l.colwidth?l.colwidth.slice():eh(l.colspan);d[u]=n,c.setNodeMarkup(o+r,null,{...l,colwidth:d})}c.docChanged&&e.dispatch(c)}function $m(e,t,n,r){let i=e.state.doc.resolve(t),a=i.node(-1),o=i.start(-1),s=X.get(a).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,c=e.domAtPos(i.start(-1)).node;for(;c&&c.nodeName!=`TABLE`;)c=c.parentNode;c&&Vm(a,c.firstChild,c,r,s,n)}function eh(e){return Array(e).fill(0)}function th(e,t){let n=[],r=e.doc.resolve(t),i=r.node(-1);if(!i)return V.empty;let a=X.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;for(let t=0;t<a.height;t++){let r=s+t*a.width;if((s==a.width-1||a.map[r]!=a.map[r+1])&&(t==0||a.map[r]!=a.map[r-a.width])){let t=a.map[r],s=o+t+i.nodeAt(t).nodeSize-1,c=document.createElement(`div`);c.className=`column-resize-handle`,Q.getState(e)?.dragging&&n.push(Wc.node(o+t,o+t+i.nodeAt(t).nodeSize,{class:`column-resize-dragging`})),n.push(Wc.widget(s,c))}}return V.create(e.doc,n)}function nh({allowTableNodeSelection:e=!1}={}){return new A({key:Cp,state:{init(){return null},apply(e,t){let n=e.getMeta(Cp);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;let{deleted:r,pos:i}=e.mapping.mapResult(t);return r?null:i}},props:{decorations:Ip,handleDOMEvents:{mousedown:Im},createSelectionBetween(e){return Cp.getState(e.state)==null?null:e.state.selection},handleTripleClick:Pm,handleKeyDown:Am,handlePaste:Fm},appendTransaction(t,n,r){return zp(r,Hp(r,n),e)}})}var rh=typeof navigator<`u`?navigator:null,ih=rh&&rh.userAgent||``,ah=/Edge\/(\d+)/.exec(ih),oh=/MSIE \d/.exec(ih),sh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ih),ch=!(oh||sh||ah)&&!!rh&&/Apple Computer/.test(rh.vendor),lh=new j(`safari-ime-span`),uh=!1,dh={key:lh,props:{decorations:fh,handleDOMEvents:{compositionstart:()=>{uh=!0},compositionend:()=>{uh=!1}}}};function fh(e){let{$from:t,$to:n,to:r}=e.selection;if(uh&&t.sameParent(n)){let t=Wc.widget(r,ph,{ignoreSelection:!0,key:`safari-ime-span`});return V.create(e.doc,[t])}}function ph(e){let t=e.dom.ownerDocument.createElement(`span`);return t.className=`ProseMirror-safari-ime-span`,t}var mh=new A(ch?dh:{key:lh});function $(e,t){return Object.assign(e,{meta:{package:`@milkdown/preset-gfm`,...t}}),e}var hh=sd(`strike_through`);$(hh,{displayName:`Attr<strikethrough>`,group:`Strikethrough`});var gh=ad(`strike_through`,e=>({parseDOM:[{tag:`del`},{style:`text-decoration`,getAttrs:e=>e===`line-through`}],toDOM:t=>[`del`,e.get(hh.key)(t)],parseMarkdown:{match:e=>e.type===`delete`,runner:(e,t,n)=>{e.openMark(n),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===`strike_through`,runner:(e,t)=>{e.withMark(t,`delete`)}}}));$(gh.mark,{displayName:`MarkSchema<strikethrough>`,group:`Strikethrough`}),$(gh.ctx,{displayName:`MarkSchemaCtx<strikethrough>`,group:`Strikethrough`});var _h=G(`ToggleStrikeThrough`,e=>()=>Ei(gh.type(e)));$(_h,{displayName:`Command<ToggleStrikethrough>`,group:`Strikethrough`});var vh=K(e=>Xi(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,gh.type(e)));$(vh,{displayName:`InputRule<strikethrough>`,group:`Strikethrough`});var yh=J(`strikeThroughKeymap`,{ToggleStrikethrough:{shortcuts:`Mod-Alt-x`,command:e=>{let t=e.get(W);return()=>t.call(_h.key)}}});$(yh.ctx,{displayName:`KeymapCtx<strikethrough>`,group:`Strikethrough`}),$(yh.shortcuts,{displayName:`Keymap<strikethrough>`,group:`Strikethrough`});var bh=xp({tableGroup:`block`,cellContent:`paragraph`,cellAttributes:{alignment:{default:`left`,getFromDOM:e=>e.style.textAlign||`left`,setDOMAttr:(e,t)=>{t.style=`text-align: ${e||`left`}`}}}}),xh=q(`table`,()=>({...bh.table,content:`table_header_row table_row+`,disableDropCursor:!0,parseMarkdown:{match:e=>e.type===`table`,runner:(e,t,n)=>{let r=t.align,i=t.children.map((e,t)=>({...e,align:r,isHeader:t===0}));e.openNode(n),e.next(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table`,runner:(e,t)=>{let n=t.content.firstChild?.content;if(!n)return;let r=[];n.forEach(e=>{r.push(e.attrs.alignment)}),e.openNode(`table`,void 0,{align:r}),e.next(t.content),e.closeNode()}}}));$(xh.node,{displayName:`NodeSchema<table>`,group:`Table`}),$(xh.ctx,{displayName:`NodeSchemaCtx<table>`,group:`Table`});var Sh=q(`table_header_row`,()=>({...bh.table_row,disableDropCursor:!0,content:`(table_header)*`,parseDOM:[{tag:`tr[data-is-header]`},{tag:`tr`,getAttrs:e=>e instanceof HTMLElement&&e.querySelector(`th`)?{}:!1}],toDOM(){return[`tr`,{"data-is-header":!0},0]},parseMarkdown:{match:e=>!!(e.type===`tableRow`&&e.isHeader),runner:(e,t,n)=>{let r=t.align,i=t.children.map((e,n)=>({...e,align:r[n],isHeader:t.isHeader}));e.openNode(n),e.next(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table_header_row`,runner:(e,t)=>{t.content.size!==0&&(e.openNode(`tableRow`,void 0,{isHeader:!0}),e.next(t.content),e.closeNode())}}}));$(Sh.node,{displayName:`NodeSchema<tableHeaderRow>`,group:`Table`}),$(Sh.ctx,{displayName:`NodeSchemaCtx<tableHeaderRow>`,group:`Table`});var Ch=q(`table_row`,()=>({...bh.table_row,disableDropCursor:!0,content:`(table_cell)*`,parseMarkdown:{match:e=>e.type===`tableRow`,runner:(e,t,n)=>{let r=t.align,i=t.children.map((e,t)=>({...e,align:r[t]}));e.openNode(n),e.next(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table_row`,runner:(e,t)=>{t.content.size!==0&&(e.openNode(`tableRow`),e.next(t.content),e.closeNode())}}}));$(Ch.node,{displayName:`NodeSchema<tableRow>`,group:`Table`}),$(Ch.ctx,{displayName:`NodeSchemaCtx<tableRow>`,group:`Table`});var wh=q(`table_cell`,()=>({...bh.table_cell,disableDropCursor:!0,parseMarkdown:{match:e=>e.type===`tableCell`&&!e.isHeader,runner:(e,t,n)=>{let r=t.align;e.openNode(n,{alignment:r}).openNode(e.schema.nodes.paragraph).next(t.children).closeNode().closeNode()}},toMarkdown:{match:e=>e.type.name===`table_cell`,runner:(e,t)=>{e.openNode(`tableCell`).next(t.content).closeNode()}}}));$(wh.node,{displayName:`NodeSchema<tableCell>`,group:`Table`}),$(wh.ctx,{displayName:`NodeSchemaCtx<tableCell>`,group:`Table`});var Th=q(`table_header`,()=>({...bh.table_header,disableDropCursor:!0,parseMarkdown:{match:e=>e.type===`tableCell`&&!!e.isHeader,runner:(e,t,n)=>{let r=t.align;e.openNode(n,{alignment:r}),e.openNode(e.schema.nodes.paragraph),e.next(t.children),e.closeNode(),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table_header`,runner:(e,t)=>{e.openNode(`tableCell`),e.next(t.content),e.closeNode()}}}));$(Th.node,{displayName:`NodeSchema<tableHeader>`,group:`Table`}),$(Th.ctx,{displayName:`NodeSchemaCtx<tableHeader>`,group:`Table`});function Eh(e,t=3,n=3){let r=Array(n).fill(0).map(()=>wh.type(e).createAndFill()),i=Array(n).fill(0).map(()=>Th.type(e).createAndFill()),a=Array(t).fill(0).map((t,n)=>n===0?Sh.type(e).create(null,i):Ch.type(e).create(null,r));return xh.type(e).create(null,a)}function Dh(e){return(t,n)=>r=>{n??=r.selection.from;let i=r.doc.resolve(n),a=ta(e=>e.type.name===`table`)(i),o=a?{node:a.node,from:a.start}:void 0,s=e===`row`;if(o){let e=X.get(o.node);if(t>=0&&t<(s?e.height:e.width)){let n=e.positionAt(s?t:e.height-1,s?e.width-1:t,o.node),i=r.doc.resolve(o.from+n),a=s?Z.rowSelection:Z.colSelection,c=e.positionAt(s?t:0,s?0:t,o.node),l=r.doc.resolve(o.from+c);return Zi(r.setSelection(a(i,l)))}}return r}}var Oh=Dh(`row`),kh=Dh(`col`);function Ah(e,t,{map:n,tableStart:r,table:i},a){let o=Array(a).fill(0).reduce((e,t,n)=>e+i.child(n).nodeSize,r),s=Array(n.width).fill(0).map((t,r)=>{let a=i.nodeAt(n.map[r]);return wh.type(e).createAndFill({alignment:a?.attrs.alignment})});return t.insert(o,Ch.type(e).create(null,s)),t}function jh(e){let t=qp(e.$from);if(!t)return;let n=X.get(t.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(e=>{let n=t.node.nodeAt(e),r=e+t.start;return{pos:r,start:r+1,node:n}})}function Mh(e){let t=jh(e.selection);if(t&&t[0]){let n=e.doc.resolve(t[0].pos),r=t[t.length-1];if(r){let t=e.doc.resolve(r.pos);return Zi(e.setSelection(new Z(t,n)))}}return e}var Nh=G(`GoToPrevTableCell`,()=>()=>_m(-1));$(Nh,{displayName:`Command<goToPrevTableCellCommand>`,group:`Table`});var Ph=G(`GoToNextTableCell`,()=>()=>_m(1));$(Ph,{displayName:`Command<goToNextTableCellCommand>`,group:`Table`});var Fh=G(`ExitTable`,e=>()=>(t,n)=>{if(!Tp(t))return!1;let{$head:r}=t.selection,i=ea(r,xh.type(e));if(!i)return!1;let{to:a}=i,o=t.tr.replaceWith(a,a,Hd.type(e).createAndFill());return o.setSelection(D.near(o.doc.resolve(a),1)).scrollIntoView(),n?.(o),!0});$(Fh,{displayName:`Command<breakTableCommand>`,group:`Table`});var Ih=G(`InsertTable`,e=>({row:t,col:n}={})=>(r,i)=>{let{selection:a,tr:o}=r,{from:s}=a,c=Eh(e,t,n),l=o.replaceSelectionWith(c),u=D.findFrom(l.doc.resolve(s),1,!0);return u&&l.setSelection(u),i?.(l),!0});$(Ih,{displayName:`Command<insertTableCommand>`,group:`Table`});var Lh=G(`MoveRow`,()=>({from:e,to:t,pos:n}={})=>bm({from:e??0,to:t??0,pos:n}));$(Lh,{displayName:`Command<moveRowCommand>`,group:`Table`});var Rh=G(`MoveCol`,()=>({from:e,to:t,pos:n}={})=>xm({from:e??0,to:t??0,pos:n}));$(Rh,{displayName:`Command<moveColCommand>`,group:`Table`});var zh=G(`SelectRow`,()=>(e={index:0})=>(t,n)=>{let{tr:r}=t;return!!n?.(Oh(e.index,e.pos)(r))});$(zh,{displayName:`Command<selectRowCommand>`,group:`Table`});var Bh=G(`SelectCol`,()=>(e={index:0})=>(t,n)=>{let{tr:r}=t;return!!n?.(kh(e.index,e.pos)(r))});$(Bh,{displayName:`Command<selectColCommand>`,group:`Table`});var Vh=G(`SelectTable`,()=>()=>(e,t)=>{let{tr:n}=e;return!!t?.(Mh(n))});$(Vh,{displayName:`Command<selectTableCommand>`,group:`Table`});var Hh=G(`DeleteSelectedCells`,()=>()=>(e,t)=>{let{selection:n}=e;if(!(n instanceof Z))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?vm(e,t):i?lm(e,t):dm(e,t)});$(Hh,{displayName:`Command<deleteSelectedCellsCommand>`,group:`Table`});var Uh=G(`AddColBefore`,()=>()=>om);$(Uh,{displayName:`Command<addColBeforeCommand>`,group:`Table`});var Wh=G(`AddColAfter`,()=>()=>sm);$(Wh,{displayName:`Command<addColAfterCommand>`,group:`Table`});var Gh=G(`AddRowBefore`,e=>()=>(t,n)=>{if(!Tp(t))return!1;if(n){let r=im(t);n(Ah(e,t.tr,r,r.top))}return!0});$(Gh,{displayName:`Command<addRowBeforeCommand>`,group:`Table`});var Kh=G(`AddRowAfter`,e=>()=>(t,n)=>{if(!Tp(t))return!1;if(n){let r=im(t);n(Ah(e,t.tr,r,r.bottom))}return!0});$(Kh,{displayName:`Command<addRowAfterCommand>`,group:`Table`});var qh=G(`SetAlign`,()=>(e=`left`)=>fm(`alignment`,e));$(qh,{displayName:`Command<setAlignCommand>`,group:`Table`});var Jh=K(e=>new M(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(t,n,r,i)=>{let a=t.doc.resolve(r);if(!a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),xh.type(e)))return null;let o=Eh(e,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),s=t.tr.replaceRangeWith(r,i,o);return s.setSelection(O.create(s.doc,r+3)).scrollIntoView()}));$(Jh,{displayName:`InputRule<insertTableInputRule>`,group:`Table`});var Yh=$u(e=>({run:(t,n,r)=>{if(r)return t;function i(t){let n=t.childCount,r=t.lastChild?.childCount??0;if(n===0||r===0)return Hd.type(e).create();let i=t.firstChild;if(!(r>0&&i&&i.childCount===0))return t;if(n>=3){let r=t.child(1),a=[];for(let t=0;t<r.childCount;t++){let n=r.child(t);a.push(Th.type(e).create(n.attrs,n.content,n.marks))}let o=i.type.create(i.attrs,a),s=[];for(let e=2;e<n;e++)s.push(t.child(e));return t.type.create(t.attrs,[o,...s])}let a=Array(r).fill(0).map(()=>Th.type(e).createAndFill()),o=new w(S.from(a),0,0),s=i.replace(0,0,o);return t.replace(0,i.nodeSize,new w(S.from(s),0,0))}function a(t){let n=Ch.type(e),r=[],a=[],o=!1;function s(){if(a.length===0)return;let t=Sh.type(e).createAndFill(),n=xh.type(e).create(null,[t,...a]);r.push(i(n)),a=[]}return t.forEach(e=>{e.type===n?(o=!0,a.push(e)):(s(),r.push(e))}),s(),o?S.from(r):t}function o(t){let n=a(t),r=n!==t,s=[];return n.forEach(t=>{if(t.type===xh.type(e)){let e=i(t);e!==t&&(r=!0),s.push(e)}else if(t.childCount>0){let e=o(t.content);e===t.content?s.push(t):(r=!0,s.push(t.copy(e)))}else s.push(t)}),r?S.from(s):t}function s(t){let n=[],r=[];t.forEach(e=>r.push(e));for(let t=0;t<r.length;t++){let i=r[t],a=r[t+1];i.type===Hd.type(e)&&i.content.size===0&&a&&a.type===xh.type(e)||n.push(i)}return n.length<r.length?S.from(n):t}let c=o(t.content);return c=s(c),new w(S.from(c),t.openStart,t.openEnd)}}));$(Yh,{displayName:`PasteRule<table>`,group:`Table`});var Xh=J(`tableKeymap`,{NextCell:{priority:100,shortcuts:[`Mod-]`,`Tab`],command:e=>{let t=e.get(W);return()=>t.call(Ph.key)}},PrevCell:{shortcuts:[`Mod-[`,`Shift-Tab`],command:e=>{let t=e.get(W);return()=>t.call(Nh.key)}},ExitTable:{shortcuts:[`Mod-Enter`,`Enter`],command:e=>{let t=e.get(W);return()=>t.call(Fh.key)}}});$(Xh.ctx,{displayName:`KeymapCtx<table>`,group:`Table`}),$(Xh.shortcuts,{displayName:`Keymap<table>`,group:`Table`});var Zh=`footnote_definition`,Qh=`footnoteDefinition`,$h=q(`footnote_definition`,()=>({group:`block`,content:`block+`,defining:!0,attrs:{label:{default:``,validate:`string`}},parseDOM:[{tag:`dl[data-type="${Zh}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label}},contentElement:`dd`}],toDOM:e=>{let t=e.attrs.label;return[`dl`,{"data-label":t,"data-type":Zh},[`dt`,t],[`dd`,0]]},parseMarkdown:{match:({type:e})=>e===Qh,runner:(e,t,n)=>{e.openNode(n,{label:t.label}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===Zh,runner:(e,t)=>{e.openNode(Qh,void 0,{label:t.attrs.label,identifier:t.attrs.label}).next(t.content).closeNode()}}}));$($h.ctx,{displayName:`NodeSchemaCtx<footnodeDef>`,group:`footnote`}),$($h.node,{displayName:`NodeSchema<footnodeDef>`,group:`footnote`});var eg=`footnote_reference`,tg=q(`footnote_reference`,()=>({group:`inline`,inline:!0,atom:!0,attrs:{label:{default:``,validate:`string`}},parseDOM:[{tag:`sup[data-type="${eg}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label}}}],toDOM:e=>{let t=e.attrs.label;return[`sup`,{"data-label":t,"data-type":eg},t]},parseMarkdown:{match:({type:e})=>e===`footnoteReference`,runner:(e,t,n)=>{e.addNode(n,{label:t.label})}},toMarkdown:{match:e=>e.type.name===eg,runner:(e,t)=>{e.addNode(`footnoteReference`,void 0,void 0,{label:t.attrs.label,identifier:t.attrs.label})}}}));$(tg.ctx,{displayName:`NodeSchemaCtx<footnodeRef>`,group:`footnote`}),$(tg.node,{displayName:`NodeSchema<footnodeRef>`,group:`footnote`});var ng=Ff.extendSchema(e=>t=>{let n=e(t);return{...n,attrs:{...n.attrs,checked:{default:null,validate:`boolean|null`}},parseDOM:[{tag:`li[data-item-type="task"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread,checked:e.dataset.checked?e.dataset.checked===`true`:null}}},...n?.parseDOM||[]],toDOM:e=>n.toDOM&&e.attrs.checked==null?n.toDOM(e):[`li`,{"data-item-type":`task`,"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread,"data-checked":e.attrs.checked},0],parseMarkdown:{match:({type:e})=>e===`listItem`,runner:(e,t,r)=>{if(t.checked==null){n.parseMarkdown.runner(e,t,r);return}let i=t.label==null?`•`:`${t.label}.`,a=t.checked==null?null:!!t.checked,o=t.label==null?`bullet`:`ordered`,s=t.spread==null?`true`:`${t.spread}`;e.openNode(r,{label:i,listType:o,spread:s,checked:a}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`list_item`,runner:(e,t)=>{if(t.attrs.checked==null){n.toMarkdown.runner(e,t);return}let r=t.attrs.label,i=t.attrs.listType,a=t.attrs.spread===`true`,o=t.attrs.checked;e.openNode(`listItem`,void 0,{label:r,listType:i,spread:a,checked:o}),e.next(t.content),e.closeNode()}}}});$(ng.node,{displayName:`NodeSchema<taskListItem>`,group:`ListItem`}),$(ng.ctx,{displayName:`NodeSchemaCtx<taskListItem>`,group:`ListItem`});var rg=K(()=>new M(/^\[(?<checked>\s|x)\]\s$/,(e,t,n,r)=>{let i=e.doc.resolve(n),a=0,o=i.node(a);for(;o&&o.type.name!==`list_item`;)a--,o=i.node(a);if(!o||o.attrs.checked!=null)return null;let s=t.groups?.checked===`x`,c=i.before(a),l=e.tr;return l.deleteRange(n,r).setNodeMarkup(c,void 0,{...o.attrs,checked:s}),l}));$(rg,{displayName:`InputRule<wrapInTaskListInputRule>`,group:`ListItem`});var ig=[yh,Xh].flat(),ag=[Jh,rg],og=[vh],sg=[Yh],cg=nd(()=>mh);$(cg,{displayName:`Prose<autoInsertSpanPlugin>`,group:`Prose`}),$(nd(()=>Hm({})),{displayName:`Prose<columnResizingPlugin>`,group:`Prose`});var lg=nd(()=>nh({allowTableNodeSelection:!0}));$(lg,{displayName:`Prose<tableEditingPlugin>`,group:`Prose`});var ug=cd(`remarkGFM`,()=>u);$(ug.plugin,{displayName:`Remark<remarkGFMPlugin>`,group:`Remark`}),$(ug.options,{displayName:`RemarkConfig<remarkGFMPlugin>`,group:`Remark`});var dg=new j(`MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN`);function fg(e,t){let n=0;return t.forEach((t,r,i)=>{t===e&&(n=i)}),n}var pg=nd(()=>new A({key:dg,appendTransaction:(e,t,n)=>{let r;return t.doc!==n.doc&&n.doc.descendants((e,t)=>{if(r||=n.tr,e.type.name!==`table_cell`)return;let i=n.doc.resolve(t),a=i.node(i.depth),o=i.node(i.depth-1).firstChild;if(!o)return;let s=fg(e,a),c=o.maybeChild(s);if(!c)return;let l=c.attrs.alignment;l!==e.attrs.alignment&&r.setNodeMarkup(t,void 0,{...e.attrs,alignment:l})}),r}}));$(pg,{displayName:`Prose<keepTableAlignPlugin>`,group:`Prose`});var mg=[pg,cg,ug,lg].flat(),hg=[[ng,xh,Sh,Ch,Th,wh,$h,tg,hh,gh].flat(),ag,sg,og,ig,[Ph,Nh,Fh,Ih,Lh,Rh,zh,Bh,Vh,Hh,Gh,Kh,Uh,Wh,qh,_h],mg].flat(),gg=typeof global==`object`&&global&&global.Object===Object&&global,_g=typeof self==`object`&&self&&self.Object===Object&&self,vg=gg||_g||Function(`return this`)(),yg=vg.Symbol,bg=Object.prototype,xg=bg.hasOwnProperty,Sg=bg.toString,Cg=yg?yg.toStringTag:void 0;function wg(e){var t=xg.call(e,Cg),n=e[Cg];try{e[Cg]=void 0;var r=!0}catch{}var i=Sg.call(e);return r&&(t?e[Cg]=n:delete e[Cg]),i}var Tg=Object.prototype.toString;function Eg(e){return Tg.call(e)}var Dg=`[object Null]`,Og=`[object Undefined]`,kg=yg?yg.toStringTag:void 0;function Ag(e){return e==null?e===void 0?Og:Dg:kg&&kg in Object(e)?wg(e):Eg(e)}function jg(e){return typeof e==`object`&&!!e}var Mg=`[object Symbol]`;function Ng(e){return typeof e==`symbol`||jg(e)&&Ag(e)==Mg}var Pg=/\s/;function Fg(e){for(var t=e.length;t--&&Pg.test(e.charAt(t)););return t}var Ig=/^\s+/;function Lg(e){return e&&e.slice(0,Fg(e)+1).replace(Ig,``)}function Rg(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var zg=NaN,Bg=/^[-+]0x[0-9a-f]+$/i,Vg=/^0b[01]+$/i,Hg=/^0o[0-7]+$/i,Ug=parseInt;function Wg(e){if(typeof e==`number`)return e;if(Ng(e))return zg;if(Rg(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=Rg(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Lg(e);var n=Vg.test(e);return n||Hg.test(e)?Ug(e.slice(2),n?2:8):Bg.test(e)?zg:+e}var Gg=function(){return vg.Date.now()},Kg=`Expected a function`,qg=Math.max,Jg=Math.min;function Yg(e,t,n){var r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(Kg);t=Wg(t)||0,Rg(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?qg(Wg(n.maxWait)||0,t):a,f=`trailing`in n?!!n.trailing:f);function p(t){var n=r,a=i;return r=i=void 0,l=t,o=e.apply(a,n),o}function m(e){return l=e,s=setTimeout(ee,t),u?p(e):o}function h(e){var n=e-c,r=e-l,i=t-n;return d?Jg(i,a-r):i}function g(e){var n=e-c,r=e-l;return c===void 0||n>=t||n<0||d&&r>=a}function ee(){var e=Gg();if(g(e))return te(e);s=setTimeout(ee,h(e))}function te(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function ne(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function re(){return s===void 0?o:te(Gg())}function ie(){var e=Gg(),n=g(e);if(r=arguments,i=this,c=e,n){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(ee,t),p(c)}return s===void 0&&(s=setTimeout(ee,t)),o}return ie.cancel=ne,ie.flush=re,ie}var Xg=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=e=>(this.beforeMountedListeners.push(e),this),this.mounted=e=>(this.mountedListeners.push(e),this),this.updated=e=>(this.updatedListeners.push(e),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners,selectionUpdated:this.selectionUpdatedListeners}}markdownUpdated(e){return this.markdownUpdatedListeners.push(e),this}blur(e){return this.blurListeners.push(e),this}focus(e){return this.focusListeners.push(e),this}destroy(e){return this.destroyListeners.push(e),this}selectionUpdated(e){return this.selectionUpdatedListeners.push(e),this}},Zg=b(new Xg,`listener`),Qg=new j(`MILKDOWN_LISTENER`),$g=e=>(e.inject(Zg,new Xg),async()=>{await e.wait(Jl);let{listeners:t}=e.get(Zg);t.beforeMount.forEach(t=>t(e)),await e.wait(vu);let n=e.get(xu),r=null,i=null,a=null,o=null,s=Yg(()=>{if(!o)return;let{doc:a}=o;if(t.updated.length>0&&r&&!r.eq(a)&&t.updated.forEach(t=>{t(e,a,r)}),t.markdownUpdated.length>0&&r&&!r.eq(a)){let r=n(a);t.markdownUpdated.forEach(t=>{t(e,r,i)}),i=r}r=a,o=null},200),c=new A({key:Qg,view:()=>({destroy:()=>{t.destroy.forEach(t=>t(e))}}),props:{handleDOMEvents:{focus:()=>(t.focus.forEach(t=>t(e)),!1),blur:()=>(t.blur.forEach(t=>t(e)),!1)}},state:{init:(e,t)=>{r=t.doc,i=n(t.doc)},apply:n=>{let r=n.selection;(!a&&r||a&&!r.eq(a))&&(t.selectionUpdated.forEach(t=>{t(e,r,a)}),a=r),!(!(n.docChanged||n.storedMarksSet)||n.getMeta(`addToHistory`)===!1)&&(o=n,s())}}});e.update(Bl,e=>e.concat(c)),await e.wait(Pu),t.mounted.forEach(t=>t(e))});$g.meta={package:`@milkdown/plugin-listener`,displayName:`Listener`};var e_=n(),t_=`
33
+ `):e.addNode(`break`)}}}));Y(_f.node,{displayName:`NodeSchema<hardbreak>`,group:`Hardbreak`}),Y(_f.ctx,{displayName:`NodeSchemaCtx<hardbreak>`,group:`Hardbreak`});var vf=G(`InsertHardbreak`,e=>()=>(t,n)=>{let{selection:r,tr:i}=t;if(!(r instanceof O))return!1;if(r.empty){let e=r.$from.node();if(e.childCount>0&&e.lastChild?.type.name===`hardbreak`)return n?.(i.replaceRangeWith(r.to-1,r.to,t.schema.node(`paragraph`)).setSelection(D.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(i.setMeta(`hardbreak`,!0).replaceSelectionWith(_f.type(e).create()).scrollIntoView()),!0});Y(vf,{displayName:`Command<insertHardbreakCommand>`,group:`Hardbreak`});var yf=J(`hardbreakKeymap`,{InsertHardbreak:{shortcuts:`Shift-Enter`,command:e=>{let t=e.get(W);return()=>t.call(vf.key)}}});Y(yf.ctx,{displayName:`KeymapCtx<hardbreak>`,group:`Hardbreak`}),Y(yf.shortcuts,{displayName:`Keymap<hardbreak>`,group:`Hardbreak`});var bf=od(`hr`);Y(bf,{displayName:`Attr<hr>`,group:`Hr`});var xf=q(`hr`,e=>({group:`block`,parseDOM:[{tag:`hr`}],toDOM:t=>[`hr`,e.get(bf.key)(t)],parseMarkdown:{match:({type:e})=>e===`thematicBreak`,runner:(e,t,n)=>{e.addNode(n)}},toMarkdown:{match:e=>e.type.name===`hr`,runner:e=>{e.addNode(`thematicBreak`)}}}));Y(xf.node,{displayName:`NodeSchema<hr>`,group:`Hr`}),Y(xf.ctx,{displayName:`NodeSchemaCtx<hr>`,group:`Hr`});var Sf=K(e=>new M(/^(?:---|___\s|\*\*\*\s)$/,(t,n,r,i)=>{let{tr:a}=t;return n[0]&&a.replaceWith(r-1,i,xf.type(e).create()),a}));Y(Sf,{displayName:`InputRule<insertHrInputRule>`,group:`Hr`});var Cf=G(`InsertHr`,e=>()=>(t,n)=>{if(!n)return!0;let r=Hd.node.type(e).create(),{tr:i,selection:a}=t,{from:o}=a,s=xf.type(e).create();if(!s)return!0;let c=i.replaceSelectionWith(s).insert(o,r),l=D.findFrom(c.doc.resolve(o),1,!0);return l&&n(c.setSelection(l).scrollIntoView()),!0});Y(Cf,{displayName:`Command<insertHrCommand>`,group:`Hr`});var wf=od(`bulletList`);Y(wf,{displayName:`Attr<bulletList>`,group:`BulletList`});var Tf=q(`bullet_list`,e=>({content:`listItem+`,group:`block`,attrs:{spread:{default:!1,validate:`boolean`}},parseDOM:[{tag:`ul`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{spread:e.dataset.spread===`true`}}}],toDOM:t=>[`ul`,{...e.get(wf.key)(t),"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e===`list`&&!t,runner:(e,t,n)=>{let r=t.spread==null?`false`:`${t.spread}`;e.openNode(n,{spread:r}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===`bullet_list`,runner:(e,t)=>{e.openNode(`list`,void 0,{ordered:!1,spread:t.attrs.spread}).next(t.content).closeNode()}}}));Y(Tf.node,{displayName:`NodeSchema<bulletList>`,group:`BulletList`}),Y(Tf.ctx,{displayName:`NodeSchemaCtx<bulletList>`,group:`BulletList`});var Ef=K(e=>Fi(/^\s*([-+*])\s$/,Tf.type(e)));Y(Ef,{displayName:`InputRule<wrapInBulletListInputRule>`,group:`BulletList`});var Df=G(`WrapInBulletList`,e=>()=>Si(Tf.type(e)));Y(Df,{displayName:`Command<wrapInBulletListCommand>`,group:`BulletList`});var Of=J(`bulletListKeymap`,{WrapInBulletList:{shortcuts:`Mod-Alt-8`,command:e=>{let t=e.get(W);return()=>t.call(Df.key)}}});Y(Of.ctx,{displayName:`KeymapCtx<bulletListKeymap>`,group:`BulletList`}),Y(Of.shortcuts,{displayName:`Keymap<bulletListKeymap>`,group:`BulletList`});var kf=od(`orderedList`);Y(kf,{displayName:`Attr<orderedList>`,group:`OrderedList`});var Af=q(`ordered_list`,e=>({content:`listItem+`,group:`block`,attrs:{order:{default:1,validate:`number`},spread:{default:!1,validate:`boolean`}},parseDOM:[{tag:`ol`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{spread:e.dataset.spread,order:e.hasAttribute(`start`)?Number(e.getAttribute(`start`)):1}}}],toDOM:t=>[`ol`,{...e.get(kf.key)(t),...t.attrs.order===1?{}:{start:t.attrs.order},"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e===`list`&&!!t,runner:(e,t,n)=>{let r=t.spread==null?`true`:`${t.spread}`;e.openNode(n,{spread:r,order:t.start??1}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===`ordered_list`,runner:(e,t)=>{e.openNode(`list`,void 0,{ordered:!0,start:t.attrs.order??1,spread:t.attrs.spread===`true`}),e.next(t.content),e.closeNode()}}}));Y(Af.node,{displayName:`NodeSchema<orderedList>`,group:`OrderedList`}),Y(Af.ctx,{displayName:`NodeSchemaCtx<orderedList>`,group:`OrderedList`});var jf=K(e=>Fi(/^\s*(\d+)\.\s$/,Af.type(e),e=>({order:Number(e[1])}),(e,t)=>t.childCount+t.attrs.order===Number(e[1])));Y(jf,{displayName:`InputRule<wrapInOrderedListInputRule>`,group:`OrderedList`});var Mf=G(`WrapInOrderedList`,e=>()=>Si(Af.type(e)));Y(Mf,{displayName:`Command<wrapInOrderedListCommand>`,group:`OrderedList`});var Nf=J(`orderedListKeymap`,{WrapInOrderedList:{shortcuts:`Mod-Alt-7`,command:e=>{let t=e.get(W);return()=>t.call(Mf.key)}}});Y(Nf.ctx,{displayName:`KeymapCtx<orderedList>`,group:`OrderedList`}),Y(Nf.shortcuts,{displayName:`Keymap<orderedList>`,group:`OrderedList`});var Pf=od(`listItem`);Y(Pf,{displayName:`Attr<listItem>`,group:`ListItem`});var Ff=q(`list_item`,e=>({group:`listItem`,content:`paragraph block*`,attrs:{label:{default:`•`,validate:`string`},listType:{default:`bullet`,validate:`string`},spread:{default:!0,validate:`boolean`}},defining:!0,parseDOM:[{tag:`li`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread===`true`}}}],toDOM:t=>[`li`,{...e.get(Pf.key)(t),"data-label":t.attrs.label,"data-list-type":t.attrs.listType,"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:e})=>e===`listItem`,runner:(e,t,n)=>{let r=t.label==null?`•`:`${t.label}.`,i=t.label==null?`bullet`:`ordered`,a=t.spread==null?`true`:`${t.spread}`;e.openNode(n,{label:r,listType:i,spread:a}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`list_item`,runner:(e,t)=>{e.openNode(`listItem`,void 0,{spread:t.attrs.spread}),e.next(t.content),e.closeNode()}}}));Y(Ff.node,{displayName:`NodeSchema<listItem>`,group:`ListItem`}),Y(Ff.ctx,{displayName:`NodeSchemaCtx<listItem>`,group:`ListItem`});var If=G(`SinkListItem`,e=>()=>pd(Ff.type(e)));Y(If,{displayName:`Command<sinkListItemCommand>`,group:`ListItem`});var Lf=G(`LiftListItem`,e=>()=>ud(Ff.type(e)));Y(Lf,{displayName:`Command<liftListItemCommand>`,group:`ListItem`});var Rf=G(`SplitListItem`,e=>()=>ld(Ff.type(e)));Y(Rf,{displayName:`Command<splitListItemCommand>`,group:`ListItem`});function zf(e){return(t,n,r)=>{let{selection:i}=t;if(!(i instanceof O))return!1;let{empty:a,$from:o}=i;return!a||o.parentOffset!==0||o.node(-1).type!==Ff.type(e)?!1:$r(t,n,r)}}var Bf=G(`LiftFirstListItem`,e=>()=>zf(e));Y(Bf,{displayName:`Command<liftFirstListItemCommand>`,group:`ListItem`});var Vf=J(`listItemKeymap`,{NextListItem:{shortcuts:`Enter`,command:e=>{let t=e.get(W);return()=>t.call(Rf.key)}},SinkListItem:{shortcuts:[`Tab`,`Mod-]`],command:e=>{let t=e.get(W);return()=>t.call(If.key)}},LiftListItem:{shortcuts:[`Shift-Tab`,`Mod-[`],command:e=>{let t=e.get(W);return()=>t.call(Lf.key)}},LiftFirstListItem:{shortcuts:[`Backspace`,`Delete`],command:e=>{let t=e.get(W);return()=>t.call(Bf.key)}}});Y(Vf.ctx,{displayName:`KeymapCtx<listItem>`,group:`ListItem`}),Y(Vf.shortcuts,{displayName:`Keymap<listItem>`,group:`ListItem`});var Hf=td(`text`,()=>({group:`inline`,parseMarkdown:{match:({type:e})=>e===`text`,runner:(e,t)=>{e.addText(t.value)}},toMarkdown:{match:e=>e.type.name===`text`,runner:(e,t)=>{e.addNode(`text`,void 0,t.text)}}}));Y(Hf,{displayName:`NodeSchema<text>`,group:`Text`});var Uf=od(`html`);Y(Uf,{displayName:`Attr<html>`,group:`Html`});var Wf=q(`html`,e=>({atom:!0,group:`inline`,inline:!0,attrs:{value:{default:``,validate:`string`}},toDOM:t=>{let n=document.createElement(`span`),r={...e.get(Uf.key)(t),"data-value":t.attrs.value,"data-type":`html`};return n.textContent=t.attrs.value,[`span`,r,t.attrs.value]},parseDOM:[{tag:`span[data-type="html"]`,getAttrs:e=>({value:e.dataset.value??``})}],parseMarkdown:{match:({type:e})=>e===`html`,runner:(e,t,n)=>{e.addNode(n,{value:t.value})}},toMarkdown:{match:e=>e.type.name===`html`,runner:(e,t)=>{e.addNode(`html`,void 0,t.attrs.value)}}}));Y(Wf.node,{displayName:`NodeSchema<html>`,group:`Html`}),Y(Wf.ctx,{displayName:`NodeSchemaCtx<html>`,group:`Html`});var Gf=[Rd,Vd,Hd,Jd,Yd,Xd,gf,_f,tf,nf,sf,cf,bf,xf,ff,pf,wf,Tf,kf,Af,Pf,Ff,vd,yd,wd,Td,kd,Ad,Pd,Fd,Uf,Wf,Hf].flat(),Kf=[rf,Ef,jf,lf,Sf,Zd].flat(),qf=[xd,Sd,Md,Dd],Jf=[Wd,af,Qd,$d,uf,vf,Cf,mf,hf,Mf,Df,If,Rf,Lf,Bf,bd,jd,Ed,Id,Ld,G(`IsMarkSelected`,()=>e=>t=>{if(!e)return!1;let{doc:n,selection:r}=t;return n.rangeHasMark(r.from,r.to,e)}),G(`IsNoteSelected`,()=>e=>t=>e?ra(t,e).hasNode:!1),G(`ClearTextInCurrentBlock`,()=>()=>(e,t)=>{let n=e.tr,{$from:r,$to:i}=n.selection,{pos:a}=r,{pos:o}=i,s=a-r.node().content.size;return s<0?!1:(n=n.deleteRange(s,o),t?.(n),!0)}),G(`SetBlockType`,()=>e=>(t,n)=>{let{nodeType:r,attrs:i=null}=e??{};if(!r)return!1;let a=t.tr,{from:o,to:s}=a.selection;try{a.setBlockType(o,s,r,i)}catch{return!1}return n?.(a),!0}),G(`WrapInBlockType`,()=>e=>(t,n)=>{let{nodeType:r,attrs:i=null}=e??{};if(!r)return!1;let a=t.tr;try{let{$from:e,$to:t}=a.selection,n=e.blockRange(t),o=n&&Kn(n,r,i);if(!o)return!1;a=a.wrap(n,o)}catch{return!1}return n?.(a),!0}),G(`AddBlockType`,()=>e=>(t,n)=>{let{nodeType:r,attrs:i=null}=e??{};if(!r)return!1;let a=t.tr;try{let e=r instanceof St?r:r.createAndFill(i);if(!e)return!1;a.replaceSelectionWith(e)}catch{return!1}return n?.(a),!0}),G(`SelectTextNearPos`,()=>e=>(t,n)=>{let{pos:r}=e??{};if(r==null)return!1;let i=(e,t,n)=>Math.min(Math.max(e,t),n),a=t.tr;try{let e=t.doc.resolve(i(r,0,t.doc.content.size));a.setSelection(O.near(e))}catch{return!1}return n?.(a.scrollIntoView()),!0})],Yf=[of,df,yf,ef,Vf,Nf,Of,Gd,Cd,Nd,Od].flat(),Xf=cd(`remarkAddOrderInList`,()=>()=>e=>{m(e,`list`,e=>{if(e.ordered){let t=e.start??1;e.children.forEach((e,n)=>{e.label=n+t})}})});Y(Xf.plugin,{displayName:`Remark<remarkAddOrderInListPlugin>`,group:`Remark`}),Y(Xf.options,{displayName:`RemarkConfig<remarkAddOrderInListPlugin>`,group:`Remark`});var Zf=cd(`remarkLineBreak`,()=>()=>e=>{let t=/[\t ]*(?:\r?\n|\r)/g;m(e,`text`,(e,n,r)=>{if(!e.value||typeof e.value!=`string`)return;let i=[],a=0;t.lastIndex=0;let o=t.exec(e.value);for(;o;){let n=o.index;a!==n&&i.push({type:`text`,value:e.value.slice(a,n)}),i.push({type:`break`,data:{isInline:!0}}),a=n+o[0].length,o=t.exec(e.value)}if(i.length>0&&r&&typeof n==`number`)return a<e.value.length&&i.push({type:`text`,value:e.value.slice(a)}),r.children.splice(n,1,...i),n+i.length})});Y(Zf.plugin,{displayName:`Remark<remarkLineBreak>`,group:`Remark`}),Y(Zf.options,{displayName:`RemarkConfig<remarkLineBreak>`,group:`Remark`});var Qf=cd(`remarkInlineLink`,()=>gd);Y(Qf.plugin,{displayName:`Remark<remarkInlineLinkPlugin>`,group:`Remark`}),Y(Qf.options,{displayName:`RemarkConfig<remarkInlineLinkPlugin>`,group:`Remark`});var $f=e=>!!e.children,ep=e=>e.type===`html`;function tp(e,t){return n(e,0,null)[0];function n(e,r,i){if($f(e)){let t=[];for(let r=0,i=e.children.length;r<i;r++){let i=e.children[r];if(i){let a=n(i,r,e);if(a)for(let e=0,n=a.length;e<n;e++){let n=a[e];n&&t.push(n)}}}e.children=t}return t(e,r,i)}}var np=[`root`,`blockquote`,`listItem`],rp=cd(`remarkHTMLTransformer`,()=>()=>e=>{tp(e,(e,t,n)=>(ep(e)&&n&&np.includes(n.type)&&(e.children=[{...e}],delete e.value,e.type=`paragraph`),[e]))});Y(rp.plugin,{displayName:`Remark<remarkHtmlTransformer>`,group:`Remark`}),Y(rp.options,{displayName:`RemarkConfig<remarkHtmlTransformer>`,group:`Remark`});var ip=cd(`remarkMarker`,()=>()=>(e,t)=>{let n=e=>t.value.charAt(e.position.start.offset);m(e,e=>[`strong`,`emphasis`].includes(e.type),e=>{e.marker=n(e)})});Y(ip.plugin,{displayName:`Remark<remarkMarker>`,group:`Remark`}),Y(ip.options,{displayName:`RemarkConfig<remarkMarker>`,group:`Remark`});var ap=nd(()=>{let e=!1,t=new A({key:new j(`MILKDOWN_INLINE_NODES_CURSOR`),state:{init(){return!1},apply(e){if(!e.selection.empty)return!1;let t=e.selection.$from,n=t.nodeBefore,r=t.nodeAfter;return!!(n&&r&&n.isInline&&!n.isText&&r.isInline&&!r.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>e?(e=!1,requestAnimationFrame(()=>{if(t.getState(n.state)){let e=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||``,e))}}),!0):!1,compositionstart:n=>(t.getState(n.state)&&(e=!0),!1),beforeinput:(n,r)=>{if(t.getState(n.state)&&r instanceof InputEvent&&r.data&&!e){let e=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||``,e)),!0}return!1}},decorations(e){if(t.getState(e)){let t=e.selection.$from.pos,n=document.createElement(`span`),r=Wc.widget(t,n,{side:-1}),i=document.createElement(`span`),a=Wc.widget(t,i);return setTimeout(()=>{n.contentEditable=`true`,i.contentEditable=`true`}),V.create(e.doc,[r,a])}return V.empty}}});return t});Y(ap,{displayName:`Prose<inlineNodesCursorPlugin>`,group:`Prose`});var op=nd(e=>new A({key:new j(`MILKDOWN_HARDBREAK_MARKS`),appendTransaction:(t,n,r)=>{if(!t.length)return;let[i]=t;if(!i)return;let[a]=i.steps;if(i.getMeta(`hardbreak`)){if(!(a instanceof Ln))return;let{from:t}=a;return r.tr.setNodeMarkup(t,_f.type(e),void 0,[])}if(a instanceof Nn){let t=r.tr,{from:n,to:i}=a;return r.doc.nodesBetween(n,i,(n,r)=>{n.type===_f.type(e)&&(t=t.setNodeMarkup(r,_f.type(e),void 0,[]))}),t}}}));Y(op,{displayName:`Prose<hardbreakClearMarkPlugin>`,group:`Prose`});var sp=id([`table`,`code_block`],`hardbreakFilterNodes`);Y(sp,{displayName:`Ctx<hardbreakFilterNodes>`,group:`Prose`});var cp=nd(e=>{let t=e.get(sp.key);return new A({key:new j(`MILKDOWN_HARDBREAK_FILTER`),filterTransaction:(e,n)=>{let r=e.getMeta(`hardbreak`),[i]=e.steps;if(r&&i){let{from:e}=i,r=n.doc.resolve(e),a=r.depth,o=!0;for(;a>0;)t.includes(r.node(a).type.name)&&(o=!1),a--;return o}return!0}})});Y(cp,{displayName:`Prose<hardbreakFilterPlugin>`,group:`Prose`});var lp=nd(e=>{let t=new j(`MILKDOWN_HEADING_ID`),n=n=>{if(n.composing)return;let r=e.get(Jd.key),i=n.state.tr.setMeta(`addToHistory`,!1),a=!1,o={};n.state.doc.descendants((n,s)=>{if(n.type===Xd.type(e)){if(n.textContent.trim().length===0)return;let e=n.attrs,c=r(n);o[c]?(o[c]+=1,c+=`-#${o[c]}`):o[c]=1,e.id!==c&&(a=!0,i.setMeta(t,!0).setNodeMarkup(s,void 0,{...e,id:c}))}}),a&&n.dispatch(i)};return new A({key:t,view:e=>(n(e),{update:(e,t)=>{e.state.doc.eq(t.doc)||n(e)}})})});Y(lp,{displayName:`Prose<syncHeadingIdPlugin>`,group:`Prose`});var up=nd(e=>new A({key:new j(`MILKDOWN_KEEP_LIST_ORDER`),appendTransaction:(t,n,r)=>{if(!r.selection||t.some(e=>e.getMeta(`addToHistory`)===!1||!e.isGeneric))return null;let i=Af.type(e),a=Tf.type(e),o=Ff.type(e),s=(e,t,n=1)=>{let r=!1,i=`${t+n}.`;return e.label!==i&&(e.label=i,r=!0),r},c=r.tr,l=!1;return r.doc.descendants((e,t,n,r)=>{if(e.type===a){let n=e.maybeChild(0);n?.type===o&&n.attrs.listType===`ordered`&&(l=!0,c.setNodeMarkup(t,i,{spread:`true`}),e.descendants((e,t,n,r)=>{if(e.type===o){let n={...e.attrs};s(n,r)&&(c=c.setNodeMarkup(t,void 0,n))}return!1}))}else if(e.type===o&&n?.type===i){let i={...e.attrs},a=!1;i.listType!==`ordered`&&(i.listType=`ordered`,a=!0),n?.maybeChild(0)&&(a=s(i,r,n?.attrs.order??1)),a&&(c=c.setNodeMarkup(t,void 0,i),l=!0)}}),l?c.setMeta(`addToHistory`,!1):null}}));Y(up,{displayName:`Prose<syncListOrderPlugin>`,group:`Prose`});var dp=[Gf,Kf,qf,Jf,Yf,[op,sp,cp,ap,Xf,Qf,Zf,rp,ip,Bd,lp,up].flat()].flat(),fp,pp;if(typeof WeakMap<`u`){let e=new WeakMap;fp=t=>e.get(t),pp=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;fp=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},pp=(n,r)=>(t==10&&(t=0),e[t++]=n,e[t++]=r)}var X=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,a=r+1,o=i+1;for(let e=1;a<this.width&&this.map[t+e]==n;e++)a++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:a,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:a,bottom:o}=this.findCell(e);return t==`horiz`?(n<0?r==0:i==this.width)?null:this.map[a*this.width+(n<0?r-1:i)]:(n<0?a==0:o==this.height)?null:this.map[r+this.width*(n<0?a-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:a}=this.findCell(e),{left:o,right:s,top:c,bottom:l}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,c),right:Math.max(r,s),bottom:Math.max(a,l)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let a=r*this.width+i,o=this.map[a];n[o]||(n[o]=!0,!(i==e.left&&i&&this.map[a-1]==o||r==e.top&&r&&this.map[a-this.width]==o)&&t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let a=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?a-1:this.map[n]}i=a}}static get(e){return fp(e)||pp(e,mp(e))}};function mp(e){if(e.type.spec.tableRole!=`table`)throw RangeError(`Not a table node: `+e.type.name);let t=hp(e),n=e.childCount,r=[],i=0,a=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let s=0,c=0;s<n;s++){let l=e.child(s);c++;for(let e=0;;e++){for(;i<r.length&&r[i]!=0;)i++;if(e==l.childCount)break;let u=l.child(e),{colspan:d,rowspan:f,colwidth:p}=u.attrs;for(let e=0;e<f;e++){if(e+s>=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;e<d;e++){r[l+e]==0?r[l+e]=c:(a||=[]).push({type:`collision`,row:s,pos:c,n:d-e});let n=p&&p[e];if(n){let r=(l+e)%t*2,i=o[r];i==null||i!=n&&o[r+1]==1?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=d,c+=u.nodeSize}let u=(s+1)*t,d=0;for(;i<u;)r[i++]==0&&d++;d&&(a||=[]).push({type:`missing`,row:s,n:d}),c++}(t===0||n===0)&&(a||=[]).push({type:`zero_sized`});let s=new X(t,n,r,a),c=!1;for(let e=0;!c&&e<o.length;e+=2)o[e]!=null&&o[e+1]<n&&(c=!0);return c&&gp(s,o,e),s}function hp(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),a=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(a+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);a+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function gp(e,t,n){e.problems||=[];let r={};for(let i=0;i<e.map.length;i++){let a=e.map[i];if(r[a])continue;r[a]=!0;let o=n.nodeAt(a);if(!o)throw RangeError(`No cell with offset ${a} found`);let s=null,c=o.attrs;for(let n=0;n<c.colspan;n++){let r=t[(i+n)%e.width*2];r!=null&&(!c.colwidth||c.colwidth[n]!=r)&&((s||=_p(c))[n]=r)}s&&e.problems.unshift({type:`colwidth mismatch`,pos:a,colwidth:s})}}function _p(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function vp(e,t){if(typeof e==`string`)return{};let n=e.getAttribute(`data-colwidth`),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(`,`).map(e=>Number(e)):null,i=Number(e.getAttribute(`colspan`)||1),a={colspan:i,rowspan:Number(e.getAttribute(`rowspan`)||1),colwidth:r&&r.length==i?r:null};for(let n in t){let r=t[n].getFromDOM,i=r&&r(e);i!=null&&(a[n]=i)}return a}function yp(e,t){let n={};e.attrs.colspan!=1&&(n.colspan=e.attrs.colspan),e.attrs.rowspan!=1&&(n.rowspan=e.attrs.rowspan),e.attrs.colwidth&&(n[`data-colwidth`]=e.attrs.colwidth.join(`,`));for(let r in t){let i=t[r].setDOMAttr;i&&i(e.attrs[r],n)}return n}function bp(e){if(e!==null){if(!Array.isArray(e))throw TypeError(`colwidth must be null or an array`);for(let t of e)if(typeof t!=`number`)throw TypeError(`colwidth must be null or an array of numbers`)}}function xp(e){let t=e.cellAttributes||{},n={colspan:{default:1,validate:`number`},rowspan:{default:1,validate:`number`},colwidth:{default:null,validate:bp}};for(let e in t)n[e]={default:t[e].default,validate:t[e].validate};return{table:{content:`table_row+`,tableRole:`table`,isolating:!0,group:e.tableGroup,parseDOM:[{tag:`table`}],toDOM(){return[`table`,[`tbody`,0]]}},table_row:{content:`(table_cell | table_header)*`,tableRole:`row`,parseDOM:[{tag:`tr`}],toDOM(){return[`tr`,0]}},table_cell:{content:e.cellContent,attrs:n,tableRole:`cell`,isolating:!0,parseDOM:[{tag:`td`,getAttrs:e=>vp(e,t)}],toDOM(e){return[`td`,yp(e,t),0]}},table_header:{content:e.cellContent,attrs:n,tableRole:`header_cell`,isolating:!0,parseDOM:[{tag:`th`,getAttrs:e=>vp(e,t)}],toDOM(e){return[`th`,yp(e,t),0]}}}}function Sp(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(let n in e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var Cp=new j(`selectingCells`);function wp(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function Tp(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function Ep(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=wp(t.$head)||Dp(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function Dp(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function Op(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function kp(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Ap(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function jp(e,t,n){let r=e.node(-1),i=X.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function Mp(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function Np(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}function Pp(e,t,n){let r=Sp(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var Z=class e extends D{constructor(e,t=e){let n=e.node(-1),r=X.get(n),i=e.start(-1),a=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),s=r.cellsInRect(a).filter(e=>e!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new Ar(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(Op(r)&&Op(i)&&Ap(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return O.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=X.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let a=n*t.width+r.left,s=r.left;s<r.right;s++,a++){let n=t.map[a];if(i[n])continue;i[n]=!0;let s=t.findCell(n),c=e.nodeAt(n);if(!c)throw RangeError(`No cell with offset ${n} found`);let l=r.left-s.left,u=s.right-r.right;if(l>0||u>0){let e=c.attrs;if(l>0&&(e=Mp(e,0,l)),u>0&&(e=Mp(e,e.colspan-u,u)),s.left<r.left){if(c=c.type.createAndFill(e),!c)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else c=c.type.create(e,c.content)}if(s.top<r.top||s.bottom>r.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top<r.top?c.type.createAndFill(e):c.type.create(e,c.content)}o.push(c)}a.push(e.child(n).copy(S.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:a;return new w(S.from(o),1,1)}replace(e,t=w.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n);e.replace(s.map(a.pos),s.map(o.pos),i?w.empty:t)}let i=D.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new w(S.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=X.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=X.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom<i.height&&(n=c.resolve(a+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=c.resolve(a+i.map[s.left])),o.bottom<i.height&&(t=c.resolve(a+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=X.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);if(Math.min(r,i)>0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=X.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right<i.width&&(n=c.resolve(a+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right<i.width&&(t=c.resolve(a+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:`cell`,anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new Fp(this.$anchorCell.pos,this.$headCell.pos)}};Z.prototype.visible=!1,D.jsonID(`cell`,Z);var Fp=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole==`row`&&n.parent.type.spec.tableRole==`row`&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&Ap(t,n)?new Z(t,n):D.near(n,1)}};function Ip(e){if(!(e.selection instanceof Z))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(Wc.node(n,n+e.nodeSize,{class:`selectedCell`}))}),V.create(e.doc,t)}function Lp({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function Rp({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function zp(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof k&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=Z.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=Z.rowSelection(e,e)}else if(!n){let e=X.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=Z.create(i,t+1,n)}}else r instanceof O&&Lp(r)?a=O.create(i,r.from):r instanceof O&&Rp(r)&&(a=O.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var Bp=new j(`fix-tables`);function Vp(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o<a;o++){let a=t.child(o);for(let t=s,r=Math.min(i,o+3);t<r;t++)if(e.child(t)==a){s=t+1,n+=a.nodeSize;continue outer}r(a,n),s<i&&e.child(s).sameMarkup(a)?Vp(e.child(s),a,n+1,r):a.nodesBetween(0,a.content.size,r,n+1),n+=a.nodeSize}}function Hp(e,t){let n,r=(t,r)=>{t.type.spec.tableRole==`table`&&(n=Up(e,t,r,n))};return t?t.doc!=e.doc&&Vp(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Up(e,t,n,r){let i=X.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e<i.height;e++)a.push(0);for(let e=0;e<i.problems.length;e++){let o=i.problems[e];if(o.type==`collision`){let e=t.nodeAt(o.pos);if(!e)continue;let i=e.attrs;for(let e=0;e<i.rowspan;e++)a[o.row+e]+=o.n;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,Mp(i,i.colspan-o.n,o.n))}else if(o.type==`missing`)a[o.row]+=o.n;else if(o.type==`overlong_rowspan`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-o.n})}else if(o.type==`colwidth mismatch`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,colwidth:o.colwidth})}else if(o.type==`zero_sized`){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}let o,s;for(let e=0;e<a.length;e++)a[e]&&(o??=e,s=e);for(let c=0,l=n+1;c<i.height;c++){let n=t.child(c),i=l+n.nodeSize,u=a[c];if(u>0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<u;n++){let n=Sp(e.schema)[t].createAndFill();n&&a.push(n)}let d=(c==0||o==c-1)&&s==c?l+1:i-1;r.insert(r.mapping.map(d),a)}l=i}return r.setMeta(Bp,{fixTables:!0})}function Wp(e){let t=X.get(e),n=[],r=t.height,i=t.width;for(let a=0;a<r;a++){let r=[];for(let n=0;n<i;n++){let o=a*i+n,s=t.map[o];if(a>0){let e=o-i;if(s===t.map[e]){r.push(null);continue}}if(n>0){let e=o-1;if(s===t.map[e]){r.push(null);continue}}r.push(e.nodeAt(s))}n.push(r)}return n}function Gp(e,t){let n=[],r=X.get(e),i=r.height,a=r.width;for(let o=0;o<i;o++){let i=e.child(o),s=[];for(let n=0;n<a;n++){let i=t[o][n];if(!i)continue;let a=r.map[o*r.width+n],c=e.nodeAt(a);if(!c)continue;let l=c.type.createChecked(i.attrs,i.content,i.marks);s.push(l)}let c=i.type.createChecked(i.attrs,s,i.marks);n.push(c)}return e.type.createChecked(e.attrs,n,e.marks)}function Kp(e,t,n,r){let i=t[0]>n[0]?-1:1,a=e.splice(t[0],t.length),o=+(a.length%2==0),s;return s=r===-1&&i===1?n[0]-1:r===1&&i===-1?n[n.length-1]-o+1:i===-1?n[0]:n[n.length-1]-o,e.splice(s,0,...a),e}function qp(e){return Jp(e=>e.type.spec.tableRole===`table`,e)}function Jp(e,t){for(let n=t.depth;n>=0;--n){let r=t.node(n);if(e(r))return{node:r,pos:n===0?0:t.before(n),start:t.start(n),depth:n}}return null}function Yp(e,t){let n=qp(t.$from);if(!n)return;let r=X.get(n.node);if(!(e<0||e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function Xp(e,t){let n=qp(t.$from);if(!n)return;let r=X.get(n.node);if(!(e<0||e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function Zp(e,t,n=t){let r=t,i=n;for(let n=t;n>=0;n--){let t=Yp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;t>=r&&(r=n),t>i&&(i=t)})}for(let n=t;n<=i;n++){let t=Yp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;e.node.attrs.colspan>1&&t>i&&(i=t)})}let a=[];for(let t=r;t<=i;t++){let n=Yp(t,e.selection);n&&n.length>0&&a.push(t)}r=a[0],i=a[a.length-1];let o=Yp(r,e.selection),s=Xp(0,e.selection);if(!o||!s)return;let c=e.doc.resolve(o[o.length-1].pos),l;for(let t=i;t>=r;t--){let n=Yp(t,e.selection);if(n&&n.length>0){for(let e=s.length-1;e>=0;e--)if(s[e].pos===n[0].pos){l=n[0];break}if(l)break}}if(l)return{$anchor:c,$head:e.doc.resolve(l.pos),indexes:a}}function Qp(e,t,n=t){let r=t,i=n;for(let n=t;n>=0;n--){let t=Xp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;t>=r&&(r=n),t>i&&(i=t)})}for(let n=t;n<=i;n++){let t=Xp(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;e.node.attrs.rowspan>1&&t>i&&(i=t)})}let a=[];for(let t=r;t<=i;t++){let n=Xp(t,e.selection);n&&n.length>0&&a.push(t)}r=a[0],i=a[a.length-1];let o=Xp(r,e.selection),s=Yp(0,e.selection);if(!o||!s)return;let c=e.doc.resolve(o[o.length-1].pos),l;for(let t=i;t>=r;t--){let n=Xp(t,e.selection);if(n&&n.length>0){for(let e=s.length-1;e>=0;e--)if(s[e].pos===n[0].pos){l=n[0];break}if(l)break}}if(l)return{$anchor:c,$head:e.doc.resolve(l.pos),indexes:a}}function $p(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function em(e){let{tr:t,originIndex:n,targetIndex:r,select:i,pos:a}=e,o=qp(t.doc.resolve(a));if(!o)return!1;let s=Zp(t,n)?.indexes,c=Zp(t,r)?.indexes;if(!s||!c||s.includes(r))return!1;let l=tm(o.node,s,c,0);if(t.replaceWith(o.pos,o.pos+o.node.nodeSize,l),!i)return!0;let u=X.get(l),d=o.start,f=r,p=u.positionAt(u.height-1,f,l),m=t.doc.resolve(d+p),h=u.positionAt(0,f,l),g=t.doc.resolve(d+h);return t.setSelection(Z.colSelection(m,g)),!0}function tm(e,t,n,r){let i=$p(Wp(e));return i=Kp(i,t,n,r),i=$p(i),Gp(e,i)}function nm(e){let{tr:t,originIndex:n,targetIndex:r,select:i,pos:a}=e,o=qp(t.doc.resolve(a));if(!o)return!1;let s=Qp(t,n)?.indexes,c=Qp(t,r)?.indexes;if(!s||!c||s.includes(r))return!1;let l=rm(o.node,s,c,0);if(t.replaceWith(o.pos,o.pos+o.node.nodeSize,l),!i)return!0;let u=X.get(l),d=o.start,f=r,p=u.positionAt(f,u.width-1,l),m=t.doc.resolve(d+p),h=u.positionAt(f,0,l),g=t.doc.resolve(d+h);return t.setSelection(Z.rowSelection(m,g)),!0}function rm(e,t,n,r){let i=Wp(e);return i=Kp(i,t,n,r),Gp(e,i)}function im(e){let t=e.selection,n=Ep(e),r=n.node(-1),i=n.start(-1),a=X.get(r);return{...t instanceof Z?a.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):a.findCell(n.pos-i),tableStart:i,map:a,table:r}}function am(e,{map:t,tableStart:n,table:r},i){let a=i>0?-1:0;Pp(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o<t.height;o++){let s=o*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){let a=t.map[s],c=r.nodeAt(a);e.setNodeMarkup(e.mapping.map(n+a),null,Np(c.attrs,i-t.colCount(a))),o+=c.attrs.rowspan-1}else{let c=a==null?Sp(r.type.schema).cell:r.nodeAt(t.map[s+a]).type,l=t.positionAt(o,i,r);e.insert(e.mapping.map(n+l),c.createAndFill())}}return e}function om(e,t){if(!Tp(e))return!1;if(t){let n=im(e);t(am(e.tr,n,n.left))}return!0}function sm(e,t){if(!Tp(e))return!1;if(t){let n=im(e);t(am(e.tr,n,n.right))}return!0}function cm(e,{map:t,table:n,tableStart:r},i){let a=e.mapping.maps.length;for(let o=0;o<t.height;){let s=o*t.width+i,c=t.map[s],l=n.nodeAt(c),u=l.attrs;if(i>0&&t.map[s-1]==c||i<t.width-1&&t.map[s+1]==c)e.setNodeMarkup(e.mapping.slice(a).map(r+c),null,Mp(u,i-t.colCount(c)));else{let t=e.mapping.slice(a).map(r+c);e.delete(t,t+l.nodeSize)}o+=u.rowspan}}function lm(e,t){if(!Tp(e))return!1;if(t){let n=im(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let e=n.right-1;cm(r,n,e),e!=n.left;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=X.get(e)}t(r)}return!0}function um(e,{map:t,table:n,tableStart:r},i){let a=0;for(let e=0;e<i;e++)a+=n.child(e).nodeSize;let o=a+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(a+r,o+r);let c=new Set;for(let a=0,o=i*t.width;a<t.width;a++,o++){let l=t.map[o];if(!c.has(l)){if(c.add(l),i>0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i<t.height&&l==t.map[o+t.width]){let o=n.nodeAt(l),c=o.attrs,u=o.type.create({...c,rowspan:o.attrs.rowspan-1},o.content),d=t.positionAt(i+1,a,n);e.insert(e.mapping.slice(s).map(r+d),u),a+=c.colspan-1}}}}function dm(e,t){if(!Tp(e))return!1;if(t){let n=im(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;um(r,n,e),e!=n.top;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=X.get(n.table)}t(r)}return!0}function fm(e,t){return function(n,r){if(!Tp(n))return!1;let i=Ep(n);if(i.nodeAfter.attrs[e]===t)return!1;if(r){let a=n.tr;n.selection instanceof Z?n.selection.forEachCell((n,r)=>{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function pm(e){return function(t,n){if(!Tp(t))return!1;if(n){let r=Sp(t.schema),i=im(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)s[e].type==r.header_cell&&a.setNodeMarkup(i.tableStart+o[e],r.cell,s[e].attrs);if(a.steps.length===0)for(let e=0;e<o.length;e++)a.setNodeMarkup(i.tableStart+o[e],r.header_cell,s[e].attrs);n(a)}return!0}}function mm(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:e==`row`?t.map.width:1,bottom:e==`column`?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function hm(e,t){return t||={useDeprecatedLogic:!1},t.useDeprecatedLogic?pm(e):function(t,n){if(!Tp(t))return!1;if(n){let r=Sp(t.schema),i=im(t),a=t.tr,o=mm(`row`,i,r),s=mm(`column`,i,r),c=(e===`column`?o:e===`row`&&s)?1:0,l=e==`column`?{left:0,top:c,right:1,bottom:i.map.height}:e==`row`?{left:c,top:0,right:i.map.width,bottom:1}:i,u=e==`column`?s?r.cell:r.header_cell:e==`row`?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(l).forEach(e=>{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}hm(`row`,{useDeprecatedLogic:!0}),hm(`column`,{useDeprecatedLogic:!0}),hm(`cell`,{useDeprecatedLogic:!0});function gm(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}function _m(e){return function(t,n){if(!Tp(t))return!1;let r=gm(Ep(t),e);if(r==null)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(O.between(e,kp(e))).scrollIntoView())}return!0}}function vm(e,t){let n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function ym(e,t){let n=e.selection;if(!(n instanceof Z))return!1;if(t){let r=e.tr,i=Sp(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new w(i,0,0))}),r.docChanged&&t(r)}return!0}function bm(e){return(t,n)=>{let{from:r,to:i,select:a=!0,pos:o=t.selection.from}=e,s=t.tr;return nm({tr:s,originIndex:r,targetIndex:i,select:a,pos:o})?(n?.(s),!0):!1}}function xm(e){return(t,n)=>{let{from:r,to:i,select:a=!0,pos:o=t.selection.from}=e,s=t.tr;return em({tr:s,originIndex:r,targetIndex:i,select:a,pos:o})?(n?.(s),!0):!1}}function Sm(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,a=e?0:Math.max(0,n-1),c=e<t.childCount-1?0:Math.max(0,r-1);(a||c)&&(i=wm(Sp(o).row,new w(i,a,c)).content),s.push(i)}else if(a==`cell`||a==`header_cell`)s.push(n||r?wm(Sp(o).row,new w(t,n,r)).content:t);else return null;return Cm(o,s)}function Cm(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+a}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(S.empty),n[i]<r){let a=Sp(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(a);t[i]=t[i].append(S.from(o))}return{height:t.length,width:r,rows:t}}function wm(e,t){let n=e.createAndFill();return new Or(n).replace(0,n.content.size,t).doc}function Tm({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let a=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let s=a.child(i%a.childCount);n+s.attrs.colspan>r&&(s=s.type.createChecked(Mp(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+s.attrs.colspan}i.push(S.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,a=0;r<i;r++,a++){let o=[],s=n[a%t];for(let e=0;e<s.childCount;e++){let t=s.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(S.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function Em(e,t,n,r,i,a,o){let s=e.doc.type.schema,c=Sp(s),l,u;if(i>t.width)for(let a=0,s=0;a<t.height;a++){let d=n.child(a);s+=d.nodeSize;let f=[],p;p=d.lastChild==null||d.lastChild.type==c.cell?l||=c.cell.createAndFill():u||=c.header_cell.createAndFill();for(let e=t.width;e<i;e++)f.push(p);e.insert(e.mapping.slice(o).map(s-1+r),f)}if(a>t.height){let s=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=e>=t.width?!1:n.nodeAt(t.map[r+e]).type==c.header_cell;s.push(i?u||=c.header_cell.createAndFill():l||=c.cell.createAndFill())}let d=c.row.create(null,S.from(s)),f=[];for(let e=t.height;e<a;e++)f.push(d);e.insert(e.mapping.slice(o).map(r+n.nodeSize-2),f)}return!!(l||u)}function Dm(e,t,n,r,i,a,o,s){if(o==0||o==t.height)return!1;let c=!1;for(let l=i;l<a;l++){let i=o*t.width+l,a=t.map[i];if(t.map[i-t.width]==a){c=!0;let i=n.nodeAt(a),{top:u,left:d}=t.findCell(a);e.setNodeMarkup(e.mapping.slice(s).map(a+r),null,{...i.attrs,rowspan:o-u}),e.insert(e.mapping.slice(s).map(t.positionAt(o,d,n)),i.type.createAndFill({...i.attrs,rowspan:u+i.attrs.rowspan-o})),l+=i.attrs.colspan-1}}return c}function Om(e,t,n,r,i,a,o,s){if(o==0||o==t.width)return!1;let c=!1;for(let l=i;l<a;l++){let i=l*t.width+o,a=t.map[i];if(t.map[i-1]==a){c=!0;let i=n.nodeAt(a),u=t.colCount(a),d=e.mapping.slice(s).map(a+r);e.setNodeMarkup(d,null,Mp(i.attrs,o-u,i.attrs.colspan-(o-u))),e.insert(d+i.nodeSize,i.type.createAndFill(Mp(i.attrs,0,o-u))),l+=i.attrs.rowspan-1}}return c}function km(e,t,n,r,i){let a=n?e.doc.nodeAt(n-1):e.doc;if(!a)throw Error(`No table found`);let o=X.get(a),{top:s,left:c}=r,l=c+i.width,u=s+i.height,d=e.tr,f=0;function p(){if(a=n?d.doc.nodeAt(n-1):d.doc,!a)throw Error(`No table found`);o=X.get(a),f=d.mapping.maps.length}Em(d,o,a,n,l,u,f)&&p(),Dm(d,o,a,n,c,l,s,f)&&p(),Dm(d,o,a,n,c,l,u,f)&&p(),Om(d,o,a,n,s,u,c,f)&&p(),Om(d,o,a,n,s,u,l,f)&&p();for(let e=s;e<u;e++){let t=o.positionAt(e,c,a),r=o.positionAt(e,l,a);d.replace(d.mapping.slice(f).map(t+n),d.mapping.slice(f).map(r+n),new w(i.rows[e-s],0,0))}p(),d.setSelection(new Z(d.doc.resolve(n+o.positionAt(s,c,a)),d.doc.resolve(n+o.positionAt(u-1,l-1,a)))),t(d)}var Am=ua({ArrowLeft:Mm(`horiz`,-1),ArrowRight:Mm(`horiz`,1),ArrowUp:Mm(`vert`,-1),ArrowDown:Mm(`vert`,1),"Shift-ArrowLeft":Nm(`horiz`,-1),"Shift-ArrowRight":Nm(`horiz`,1),"Shift-ArrowUp":Nm(`vert`,-1),"Shift-ArrowDown":Nm(`vert`,1),Backspace:ym,"Mod-Backspace":ym,Delete:ym,"Mod-Delete":ym});function jm(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function Mm(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection;if(a instanceof Z)return jm(n,r,D.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=Lm(i,e,t);if(o==null)return!1;if(e==`horiz`)return jm(n,r,D.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=jp(i,e,t),s;return s=a?D.near(a,1):t<0?D.near(n.doc.resolve(i.before(-1)),-1):D.near(n.doc.resolve(i.after(-1)),1),jm(n,r,s)}}}function Nm(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof Z)o=a;else{let r=Lm(i,e,t);if(r==null)return!1;o=new Z(n.doc.resolve(r))}let s=jp(o.$headCell,e,t);return s?jm(n,r,new Z(o.$anchorCell,s)):!1}}function Pm(e,t){let n=e.state.doc,r=wp(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new Z(r))),!0):!1}function Fm(e,t,n){if(!Tp(e.state))return!1;let r=Sm(n),i=e.state.selection;if(i instanceof Z){r||={width:1,height:1,rows:[S.from(wm(Sp(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=X.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=Tm(r,o.right-o.left,o.bottom-o.top),km(e.state,e.dispatch,a,o,r),!0}else if(r){let t=Ep(e.state),n=t.start(-1);return km(e.state,e.dispatch,n,X.get(t.node(-1)).findCell(t.pos-n),r),!0}else return!1}function Im(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=Rm(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof Z)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=wp(e.state.selection.$anchor))!=null&&zm(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=zm(e,n),i=Cp.getState(e.state)==null;if(!r||!Ap(t,r))if(i)r=t;else return;let a=new Z(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(Cp,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),Cp.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(Cp,-1))}function o(r){let o=r,s=Cp.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(Rm(e,o.target)!=n&&(c=zm(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function Lm(e,t,n){if(!(e.state.selection instanceof O))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function Rm(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function zm(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&wp(e.state.doc.resolve(r))||wp(e.state.doc.resolve(i))}var Bm=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),Vm(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type?(this.node=e,Vm(e,this.colgroup,this.table,this.defaultCellMinWidth),!0):!1}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function Vm(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;e<l.childCount;e++){let{colspan:u,colwidth:d}=l.child(e).attrs;for(let e=0;e<u;e++,n++){let l=i==n?a:d&&d[e],u=l?l+`px`:``;if(o+=l||r,l||(s=!1),c)c.style.width!=u&&(c.style.width=u),c=c.nextSibling;else{let e=document.createElement(`col`);e.style.width=u,t.appendChild(e)}}}for(;c;){var u;let e=c.nextSibling;(u=c.parentNode)==null||u.removeChild(c),c=e}s?(n.style.width=o+`px`,n.style.minWidth=``):(n.style.width=``,n.style.minWidth=o+`px`)}}var Q=new j(`tableColumnResizing`);function Hm({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Bm,lastColumnResizable:i=!0}={}){let a=new A({key:Q,state:{init(e,t){var i;let o=(i=a.spec)==null||(i=i.props)==null?void 0:i.nodeViews,s=Sp(t.schema).table.name;return r&&o&&(o[s]=(e,t)=>new r(e,n,t)),new Um(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=Q.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{Wm(t,n,e,i)},mouseleave:e=>{Gm(e)},mousedown:(e,r)=>{Km(e,r,t,n)}},decorations:e=>{let t=Q.getState(e);if(t&&t.activeHandle>-1)return th(e,t.activeHandle)},nodeViews:{}}});return a}var Um=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(Q);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return Op(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function Wm(e,t,n,r){if(!e.editable)return;let i=Q.getState(e.state);if(i&&!i.dragging){let a=Jm(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=Ym(e,t,`left`,n):i-t.clientX<=n&&(o=Ym(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=X.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}Zm(e,o)}}}function Gm(e){if(!e.editable)return;let t=Q.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Zm(e,-1)}function Km(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=Q.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=qm(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(Q,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=Q.getState(e.state);r?.dragging&&(Qm(e,r.activeHandle,Xm(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(Q,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=Q.getState(e.state);if(i&&i.dragging){let a=Xm(i.dragging,t,n);$m(e,i.activeHandle,a,r)}}return $m(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function qm(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;e<n;e++)r[e]&&(o-=r[e],s--);return o/s}function Jm(e){for(;e&&e.nodeName!=`TD`&&e.nodeName!=`TH`;)e=e.classList&&e.classList.contains(`ProseMirror`)?null:e.parentNode;return e}function Ym(e,t,n,r){let i=n==`right`?-r:r,a=e.posAtCoords({left:t.clientX+i,top:t.clientY});if(!a)return-1;let{pos:o}=a,s=wp(e.state.doc.resolve(o));if(!s)return-1;if(n==`right`)return s.pos;let c=X.get(s.node(-1)),l=s.start(-1),u=c.map.indexOf(s.pos-l);return u%c.width==0?-1:l+c.map[u-1]}function Xm(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Zm(e,t){e.dispatch(e.state.tr.setMeta(Q,{setHandle:t}))}function Qm(e,t,n){let r=e.state.doc.resolve(t),i=r.node(-1),a=X.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,c=e.state.tr;for(let e=0;e<a.height;e++){let t=e*a.width+s;if(e&&a.map[t]==a.map[t-a.width])continue;let r=a.map[t],l=i.nodeAt(r).attrs,u=l.colspan==1?0:s-a.colCount(r);if(l.colwidth&&l.colwidth[u]==n)continue;let d=l.colwidth?l.colwidth.slice():eh(l.colspan);d[u]=n,c.setNodeMarkup(o+r,null,{...l,colwidth:d})}c.docChanged&&e.dispatch(c)}function $m(e,t,n,r){let i=e.state.doc.resolve(t),a=i.node(-1),o=i.start(-1),s=X.get(a).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,c=e.domAtPos(i.start(-1)).node;for(;c&&c.nodeName!=`TABLE`;)c=c.parentNode;c&&Vm(a,c.firstChild,c,r,s,n)}function eh(e){return Array(e).fill(0)}function th(e,t){let n=[],r=e.doc.resolve(t),i=r.node(-1);if(!i)return V.empty;let a=X.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;for(let t=0;t<a.height;t++){let r=s+t*a.width;if((s==a.width-1||a.map[r]!=a.map[r+1])&&(t==0||a.map[r]!=a.map[r-a.width])){let t=a.map[r],s=o+t+i.nodeAt(t).nodeSize-1,c=document.createElement(`div`);c.className=`column-resize-handle`,Q.getState(e)?.dragging&&n.push(Wc.node(o+t,o+t+i.nodeAt(t).nodeSize,{class:`column-resize-dragging`})),n.push(Wc.widget(s,c))}}return V.create(e.doc,n)}function nh({allowTableNodeSelection:e=!1}={}){return new A({key:Cp,state:{init(){return null},apply(e,t){let n=e.getMeta(Cp);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;let{deleted:r,pos:i}=e.mapping.mapResult(t);return r?null:i}},props:{decorations:Ip,handleDOMEvents:{mousedown:Im},createSelectionBetween(e){return Cp.getState(e.state)==null?null:e.state.selection},handleTripleClick:Pm,handleKeyDown:Am,handlePaste:Fm},appendTransaction(t,n,r){return zp(r,Hp(r,n),e)}})}var rh=typeof navigator<`u`?navigator:null,ih=rh&&rh.userAgent||``,ah=/Edge\/(\d+)/.exec(ih),oh=/MSIE \d/.exec(ih),sh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ih),ch=!(oh||sh||ah)&&!!rh&&/Apple Computer/.test(rh.vendor),lh=new j(`safari-ime-span`),uh=!1,dh={key:lh,props:{decorations:fh,handleDOMEvents:{compositionstart:()=>{uh=!0},compositionend:()=>{uh=!1}}}};function fh(e){let{$from:t,$to:n,to:r}=e.selection;if(uh&&t.sameParent(n)){let t=Wc.widget(r,ph,{ignoreSelection:!0,key:`safari-ime-span`});return V.create(e.doc,[t])}}function ph(e){let t=e.dom.ownerDocument.createElement(`span`);return t.className=`ProseMirror-safari-ime-span`,t}var mh=new A(ch?dh:{key:lh});function $(e,t){return Object.assign(e,{meta:{package:`@milkdown/preset-gfm`,...t}}),e}var hh=sd(`strike_through`);$(hh,{displayName:`Attr<strikethrough>`,group:`Strikethrough`});var gh=ad(`strike_through`,e=>({parseDOM:[{tag:`del`},{style:`text-decoration`,getAttrs:e=>e===`line-through`}],toDOM:t=>[`del`,e.get(hh.key)(t)],parseMarkdown:{match:e=>e.type===`delete`,runner:(e,t,n)=>{e.openMark(n),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===`strike_through`,runner:(e,t)=>{e.withMark(t,`delete`)}}}));$(gh.mark,{displayName:`MarkSchema<strikethrough>`,group:`Strikethrough`}),$(gh.ctx,{displayName:`MarkSchemaCtx<strikethrough>`,group:`Strikethrough`});var _h=G(`ToggleStrikeThrough`,e=>()=>Ei(gh.type(e)));$(_h,{displayName:`Command<ToggleStrikethrough>`,group:`Strikethrough`});var vh=K(e=>Xi(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,gh.type(e)));$(vh,{displayName:`InputRule<strikethrough>`,group:`Strikethrough`});var yh=J(`strikeThroughKeymap`,{ToggleStrikethrough:{shortcuts:`Mod-Alt-x`,command:e=>{let t=e.get(W);return()=>t.call(_h.key)}}});$(yh.ctx,{displayName:`KeymapCtx<strikethrough>`,group:`Strikethrough`}),$(yh.shortcuts,{displayName:`Keymap<strikethrough>`,group:`Strikethrough`});var bh=xp({tableGroup:`block`,cellContent:`paragraph`,cellAttributes:{alignment:{default:`left`,getFromDOM:e=>e.style.textAlign||`left`,setDOMAttr:(e,t)=>{t.style=`text-align: ${e||`left`}`}}}}),xh=q(`table`,()=>({...bh.table,content:`table_header_row table_row+`,disableDropCursor:!0,parseMarkdown:{match:e=>e.type===`table`,runner:(e,t,n)=>{let r=t.align,i=t.children.map((e,t)=>({...e,align:r,isHeader:t===0}));e.openNode(n),e.next(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table`,runner:(e,t)=>{let n=t.content.firstChild?.content;if(!n)return;let r=[];n.forEach(e=>{r.push(e.attrs.alignment)}),e.openNode(`table`,void 0,{align:r}),e.next(t.content),e.closeNode()}}}));$(xh.node,{displayName:`NodeSchema<table>`,group:`Table`}),$(xh.ctx,{displayName:`NodeSchemaCtx<table>`,group:`Table`});var Sh=q(`table_header_row`,()=>({...bh.table_row,disableDropCursor:!0,content:`(table_header)*`,parseDOM:[{tag:`tr[data-is-header]`},{tag:`tr`,getAttrs:e=>e instanceof HTMLElement&&e.querySelector(`th`)?{}:!1}],toDOM(){return[`tr`,{"data-is-header":!0},0]},parseMarkdown:{match:e=>!!(e.type===`tableRow`&&e.isHeader),runner:(e,t,n)=>{let r=t.align,i=t.children.map((e,n)=>({...e,align:r[n],isHeader:t.isHeader}));e.openNode(n),e.next(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table_header_row`,runner:(e,t)=>{t.content.size!==0&&(e.openNode(`tableRow`,void 0,{isHeader:!0}),e.next(t.content),e.closeNode())}}}));$(Sh.node,{displayName:`NodeSchema<tableHeaderRow>`,group:`Table`}),$(Sh.ctx,{displayName:`NodeSchemaCtx<tableHeaderRow>`,group:`Table`});var Ch=q(`table_row`,()=>({...bh.table_row,disableDropCursor:!0,content:`(table_cell)*`,parseMarkdown:{match:e=>e.type===`tableRow`,runner:(e,t,n)=>{let r=t.align,i=t.children.map((e,t)=>({...e,align:r[t]}));e.openNode(n),e.next(i),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table_row`,runner:(e,t)=>{t.content.size!==0&&(e.openNode(`tableRow`),e.next(t.content),e.closeNode())}}}));$(Ch.node,{displayName:`NodeSchema<tableRow>`,group:`Table`}),$(Ch.ctx,{displayName:`NodeSchemaCtx<tableRow>`,group:`Table`});var wh=q(`table_cell`,()=>({...bh.table_cell,disableDropCursor:!0,parseMarkdown:{match:e=>e.type===`tableCell`&&!e.isHeader,runner:(e,t,n)=>{let r=t.align;e.openNode(n,{alignment:r}).openNode(e.schema.nodes.paragraph).next(t.children).closeNode().closeNode()}},toMarkdown:{match:e=>e.type.name===`table_cell`,runner:(e,t)=>{e.openNode(`tableCell`).next(t.content).closeNode()}}}));$(wh.node,{displayName:`NodeSchema<tableCell>`,group:`Table`}),$(wh.ctx,{displayName:`NodeSchemaCtx<tableCell>`,group:`Table`});var Th=q(`table_header`,()=>({...bh.table_header,disableDropCursor:!0,parseMarkdown:{match:e=>e.type===`tableCell`&&!!e.isHeader,runner:(e,t,n)=>{let r=t.align;e.openNode(n,{alignment:r}),e.openNode(e.schema.nodes.paragraph),e.next(t.children),e.closeNode(),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`table_header`,runner:(e,t)=>{e.openNode(`tableCell`),e.next(t.content),e.closeNode()}}}));$(Th.node,{displayName:`NodeSchema<tableHeader>`,group:`Table`}),$(Th.ctx,{displayName:`NodeSchemaCtx<tableHeader>`,group:`Table`});function Eh(e,t=3,n=3){let r=Array(n).fill(0).map(()=>wh.type(e).createAndFill()),i=Array(n).fill(0).map(()=>Th.type(e).createAndFill()),a=Array(t).fill(0).map((t,n)=>n===0?Sh.type(e).create(null,i):Ch.type(e).create(null,r));return xh.type(e).create(null,a)}function Dh(e){return(t,n)=>r=>{n??=r.selection.from;let i=r.doc.resolve(n),a=ta(e=>e.type.name===`table`)(i),o=a?{node:a.node,from:a.start}:void 0,s=e===`row`;if(o){let e=X.get(o.node);if(t>=0&&t<(s?e.height:e.width)){let n=e.positionAt(s?t:e.height-1,s?e.width-1:t,o.node),i=r.doc.resolve(o.from+n),a=s?Z.rowSelection:Z.colSelection,c=e.positionAt(s?t:0,s?0:t,o.node),l=r.doc.resolve(o.from+c);return Zi(r.setSelection(a(i,l)))}}return r}}var Oh=Dh(`row`),kh=Dh(`col`);function Ah(e,t,{map:n,tableStart:r,table:i},a){let o=Array(a).fill(0).reduce((e,t,n)=>e+i.child(n).nodeSize,r),s=Array(n.width).fill(0).map((t,r)=>{let a=i.nodeAt(n.map[r]);return wh.type(e).createAndFill({alignment:a?.attrs.alignment})});return t.insert(o,Ch.type(e).create(null,s)),t}function jh(e){let t=qp(e.$from);if(!t)return;let n=X.get(t.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(e=>{let n=t.node.nodeAt(e),r=e+t.start;return{pos:r,start:r+1,node:n}})}function Mh(e){let t=jh(e.selection);if(t&&t[0]){let n=e.doc.resolve(t[0].pos),r=t[t.length-1];if(r){let t=e.doc.resolve(r.pos);return Zi(e.setSelection(new Z(t,n)))}}return e}var Nh=G(`GoToPrevTableCell`,()=>()=>_m(-1));$(Nh,{displayName:`Command<goToPrevTableCellCommand>`,group:`Table`});var Ph=G(`GoToNextTableCell`,()=>()=>_m(1));$(Ph,{displayName:`Command<goToNextTableCellCommand>`,group:`Table`});var Fh=G(`ExitTable`,e=>()=>(t,n)=>{if(!Tp(t))return!1;let{$head:r}=t.selection,i=ea(r,xh.type(e));if(!i)return!1;let{to:a}=i,o=t.tr.replaceWith(a,a,Hd.type(e).createAndFill());return o.setSelection(D.near(o.doc.resolve(a),1)).scrollIntoView(),n?.(o),!0});$(Fh,{displayName:`Command<breakTableCommand>`,group:`Table`});var Ih=G(`InsertTable`,e=>({row:t,col:n}={})=>(r,i)=>{let{selection:a,tr:o}=r,{from:s}=a,c=Eh(e,t,n),l=o.replaceSelectionWith(c),u=D.findFrom(l.doc.resolve(s),1,!0);return u&&l.setSelection(u),i?.(l),!0});$(Ih,{displayName:`Command<insertTableCommand>`,group:`Table`});var Lh=G(`MoveRow`,()=>({from:e,to:t,pos:n}={})=>bm({from:e??0,to:t??0,pos:n}));$(Lh,{displayName:`Command<moveRowCommand>`,group:`Table`});var Rh=G(`MoveCol`,()=>({from:e,to:t,pos:n}={})=>xm({from:e??0,to:t??0,pos:n}));$(Rh,{displayName:`Command<moveColCommand>`,group:`Table`});var zh=G(`SelectRow`,()=>(e={index:0})=>(t,n)=>{let{tr:r}=t;return!!n?.(Oh(e.index,e.pos)(r))});$(zh,{displayName:`Command<selectRowCommand>`,group:`Table`});var Bh=G(`SelectCol`,()=>(e={index:0})=>(t,n)=>{let{tr:r}=t;return!!n?.(kh(e.index,e.pos)(r))});$(Bh,{displayName:`Command<selectColCommand>`,group:`Table`});var Vh=G(`SelectTable`,()=>()=>(e,t)=>{let{tr:n}=e;return!!t?.(Mh(n))});$(Vh,{displayName:`Command<selectTableCommand>`,group:`Table`});var Hh=G(`DeleteSelectedCells`,()=>()=>(e,t)=>{let{selection:n}=e;if(!(n instanceof Z))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?vm(e,t):i?lm(e,t):dm(e,t)});$(Hh,{displayName:`Command<deleteSelectedCellsCommand>`,group:`Table`});var Uh=G(`AddColBefore`,()=>()=>om);$(Uh,{displayName:`Command<addColBeforeCommand>`,group:`Table`});var Wh=G(`AddColAfter`,()=>()=>sm);$(Wh,{displayName:`Command<addColAfterCommand>`,group:`Table`});var Gh=G(`AddRowBefore`,e=>()=>(t,n)=>{if(!Tp(t))return!1;if(n){let r=im(t);n(Ah(e,t.tr,r,r.top))}return!0});$(Gh,{displayName:`Command<addRowBeforeCommand>`,group:`Table`});var Kh=G(`AddRowAfter`,e=>()=>(t,n)=>{if(!Tp(t))return!1;if(n){let r=im(t);n(Ah(e,t.tr,r,r.bottom))}return!0});$(Kh,{displayName:`Command<addRowAfterCommand>`,group:`Table`});var qh=G(`SetAlign`,()=>(e=`left`)=>fm(`alignment`,e));$(qh,{displayName:`Command<setAlignCommand>`,group:`Table`});var Jh=K(e=>new M(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(t,n,r,i)=>{let a=t.doc.resolve(r);if(!a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),xh.type(e)))return null;let o=Eh(e,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),s=t.tr.replaceRangeWith(r,i,o);return s.setSelection(O.create(s.doc,r+3)).scrollIntoView()}));$(Jh,{displayName:`InputRule<insertTableInputRule>`,group:`Table`});var Yh=$u(e=>({run:(t,n,r)=>{if(r)return t;function i(t){let n=t.childCount,r=t.lastChild?.childCount??0;if(n===0||r===0)return Hd.type(e).create();let i=t.firstChild;if(!(r>0&&i&&i.childCount===0))return t;if(n>=3){let r=t.child(1),a=[];for(let t=0;t<r.childCount;t++){let n=r.child(t);a.push(Th.type(e).create(n.attrs,n.content,n.marks))}let o=i.type.create(i.attrs,a),s=[];for(let e=2;e<n;e++)s.push(t.child(e));return t.type.create(t.attrs,[o,...s])}let a=Array(r).fill(0).map(()=>Th.type(e).createAndFill()),o=new w(S.from(a),0,0),s=i.replace(0,0,o);return t.replace(0,i.nodeSize,new w(S.from(s),0,0))}function a(t){let n=Ch.type(e),r=[],a=[],o=!1;function s(){if(a.length===0)return;let t=Sh.type(e).createAndFill(),n=xh.type(e).create(null,[t,...a]);r.push(i(n)),a=[]}return t.forEach(e=>{e.type===n?(o=!0,a.push(e)):(s(),r.push(e))}),s(),o?S.from(r):t}function o(t){let n=a(t),r=n!==t,s=[];return n.forEach(t=>{if(t.type===xh.type(e)){let e=i(t);e!==t&&(r=!0),s.push(e)}else if(t.childCount>0){let e=o(t.content);e===t.content?s.push(t):(r=!0,s.push(t.copy(e)))}else s.push(t)}),r?S.from(s):t}function s(t){let n=[],r=[];t.forEach(e=>r.push(e));for(let t=0;t<r.length;t++){let i=r[t],a=r[t+1];i.type===Hd.type(e)&&i.content.size===0&&a&&a.type===xh.type(e)||n.push(i)}return n.length<r.length?S.from(n):t}let c=o(t.content);return c=s(c),new w(S.from(c),t.openStart,t.openEnd)}}));$(Yh,{displayName:`PasteRule<table>`,group:`Table`});var Xh=J(`tableKeymap`,{NextCell:{priority:100,shortcuts:[`Mod-]`,`Tab`],command:e=>{let t=e.get(W);return()=>t.call(Ph.key)}},PrevCell:{shortcuts:[`Mod-[`,`Shift-Tab`],command:e=>{let t=e.get(W);return()=>t.call(Nh.key)}},ExitTable:{shortcuts:[`Mod-Enter`,`Enter`],command:e=>{let t=e.get(W);return()=>t.call(Fh.key)}}});$(Xh.ctx,{displayName:`KeymapCtx<table>`,group:`Table`}),$(Xh.shortcuts,{displayName:`Keymap<table>`,group:`Table`});var Zh=`footnote_definition`,Qh=`footnoteDefinition`,$h=q(`footnote_definition`,()=>({group:`block`,content:`block+`,defining:!0,attrs:{label:{default:``,validate:`string`}},parseDOM:[{tag:`dl[data-type="${Zh}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label}},contentElement:`dd`}],toDOM:e=>{let t=e.attrs.label;return[`dl`,{"data-label":t,"data-type":Zh},[`dt`,t],[`dd`,0]]},parseMarkdown:{match:({type:e})=>e===Qh,runner:(e,t,n)=>{e.openNode(n,{label:t.label}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===Zh,runner:(e,t)=>{e.openNode(Qh,void 0,{label:t.attrs.label,identifier:t.attrs.label}).next(t.content).closeNode()}}}));$($h.ctx,{displayName:`NodeSchemaCtx<footnodeDef>`,group:`footnote`}),$($h.node,{displayName:`NodeSchema<footnodeDef>`,group:`footnote`});var eg=`footnote_reference`,tg=q(`footnote_reference`,()=>({group:`inline`,inline:!0,atom:!0,attrs:{label:{default:``,validate:`string`}},parseDOM:[{tag:`sup[data-type="${eg}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label}}}],toDOM:e=>{let t=e.attrs.label;return[`sup`,{"data-label":t,"data-type":eg},t]},parseMarkdown:{match:({type:e})=>e===`footnoteReference`,runner:(e,t,n)=>{e.addNode(n,{label:t.label})}},toMarkdown:{match:e=>e.type.name===eg,runner:(e,t)=>{e.addNode(`footnoteReference`,void 0,void 0,{label:t.attrs.label,identifier:t.attrs.label})}}}));$(tg.ctx,{displayName:`NodeSchemaCtx<footnodeRef>`,group:`footnote`}),$(tg.node,{displayName:`NodeSchema<footnodeRef>`,group:`footnote`});var ng=Ff.extendSchema(e=>t=>{let n=e(t);return{...n,attrs:{...n.attrs,checked:{default:null,validate:`boolean|null`}},parseDOM:[{tag:`li[data-item-type="task"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw Re(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread,checked:e.dataset.checked?e.dataset.checked===`true`:null}}},...n?.parseDOM||[]],toDOM:e=>n.toDOM&&e.attrs.checked==null?n.toDOM(e):[`li`,{"data-item-type":`task`,"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread,"data-checked":e.attrs.checked},0],parseMarkdown:{match:({type:e})=>e===`listItem`,runner:(e,t,r)=>{if(t.checked==null){n.parseMarkdown.runner(e,t,r);return}let i=t.label==null?`•`:`${t.label}.`,a=t.checked==null?null:!!t.checked,o=t.label==null?`bullet`:`ordered`,s=t.spread==null?`true`:`${t.spread}`;e.openNode(r,{label:i,listType:o,spread:s,checked:a}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name===`list_item`,runner:(e,t)=>{if(t.attrs.checked==null){n.toMarkdown.runner(e,t);return}let r=t.attrs.label,i=t.attrs.listType,a=t.attrs.spread===`true`,o=t.attrs.checked;e.openNode(`listItem`,void 0,{label:r,listType:i,spread:a,checked:o}),e.next(t.content),e.closeNode()}}}});$(ng.node,{displayName:`NodeSchema<taskListItem>`,group:`ListItem`}),$(ng.ctx,{displayName:`NodeSchemaCtx<taskListItem>`,group:`ListItem`});var rg=K(()=>new M(/^\[(?<checked>\s|x)\]\s$/,(e,t,n,r)=>{let i=e.doc.resolve(n),a=0,o=i.node(a);for(;o&&o.type.name!==`list_item`;)a--,o=i.node(a);if(!o||o.attrs.checked!=null)return null;let s=t.groups?.checked===`x`,c=i.before(a),l=e.tr;return l.deleteRange(n,r).setNodeMarkup(c,void 0,{...o.attrs,checked:s}),l}));$(rg,{displayName:`InputRule<wrapInTaskListInputRule>`,group:`ListItem`});var ig=[yh,Xh].flat(),ag=[Jh,rg],og=[vh],sg=[Yh],cg=nd(()=>mh);$(cg,{displayName:`Prose<autoInsertSpanPlugin>`,group:`Prose`}),$(nd(()=>Hm({})),{displayName:`Prose<columnResizingPlugin>`,group:`Prose`});var lg=nd(()=>nh({allowTableNodeSelection:!0}));$(lg,{displayName:`Prose<tableEditingPlugin>`,group:`Prose`});var ug=cd(`remarkGFM`,()=>u);$(ug.plugin,{displayName:`Remark<remarkGFMPlugin>`,group:`Remark`}),$(ug.options,{displayName:`RemarkConfig<remarkGFMPlugin>`,group:`Remark`});var dg=new j(`MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN`);function fg(e,t){let n=0;return t.forEach((t,r,i)=>{t===e&&(n=i)}),n}var pg=nd(()=>new A({key:dg,appendTransaction:(e,t,n)=>{let r;return t.doc!==n.doc&&n.doc.descendants((e,t)=>{if(r||=n.tr,e.type.name!==`table_cell`)return;let i=n.doc.resolve(t),a=i.node(i.depth),o=i.node(i.depth-1).firstChild;if(!o)return;let s=fg(e,a),c=o.maybeChild(s);if(!c)return;let l=c.attrs.alignment;l!==e.attrs.alignment&&r.setNodeMarkup(t,void 0,{...e.attrs,alignment:l})}),r}}));$(pg,{displayName:`Prose<keepTableAlignPlugin>`,group:`Prose`});var mg=[pg,cg,ug,lg].flat(),hg=[[ng,xh,Sh,Ch,Th,wh,$h,tg,hh,gh].flat(),ag,sg,og,ig,[Ph,Nh,Fh,Ih,Lh,Rh,zh,Bh,Vh,Hh,Gh,Kh,Uh,Wh,qh,_h],mg].flat(),gg=typeof global==`object`&&global&&global.Object===Object&&global,_g=typeof self==`object`&&self&&self.Object===Object&&self,vg=gg||_g||Function(`return this`)(),yg=vg.Symbol,bg=Object.prototype,xg=bg.hasOwnProperty,Sg=bg.toString,Cg=yg?yg.toStringTag:void 0;function wg(e){var t=xg.call(e,Cg),n=e[Cg];try{e[Cg]=void 0;var r=!0}catch{}var i=Sg.call(e);return r&&(t?e[Cg]=n:delete e[Cg]),i}var Tg=Object.prototype.toString;function Eg(e){return Tg.call(e)}var Dg=`[object Null]`,Og=`[object Undefined]`,kg=yg?yg.toStringTag:void 0;function Ag(e){return e==null?e===void 0?Og:Dg:kg&&kg in Object(e)?wg(e):Eg(e)}function jg(e){return typeof e==`object`&&!!e}var Mg=`[object Symbol]`;function Ng(e){return typeof e==`symbol`||jg(e)&&Ag(e)==Mg}var Pg=/\s/;function Fg(e){for(var t=e.length;t--&&Pg.test(e.charAt(t)););return t}var Ig=/^\s+/;function Lg(e){return e&&e.slice(0,Fg(e)+1).replace(Ig,``)}function Rg(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var zg=NaN,Bg=/^[-+]0x[0-9a-f]+$/i,Vg=/^0b[01]+$/i,Hg=/^0o[0-7]+$/i,Ug=parseInt;function Wg(e){if(typeof e==`number`)return e;if(Ng(e))return zg;if(Rg(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=Rg(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Lg(e);var n=Vg.test(e);return n||Hg.test(e)?Ug(e.slice(2),n?2:8):Bg.test(e)?zg:+e}var Gg=function(){return vg.Date.now()},Kg=`Expected a function`,qg=Math.max,Jg=Math.min;function Yg(e,t,n){var r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(Kg);t=Wg(t)||0,Rg(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?qg(Wg(n.maxWait)||0,t):a,f=`trailing`in n?!!n.trailing:f);function p(t){var n=r,a=i;return r=i=void 0,l=t,o=e.apply(a,n),o}function m(e){return l=e,s=setTimeout(ee,t),u?p(e):o}function h(e){var n=e-c,r=e-l,i=t-n;return d?Jg(i,a-r):i}function g(e){var n=e-c,r=e-l;return c===void 0||n>=t||n<0||d&&r>=a}function ee(){var e=Gg();if(g(e))return te(e);s=setTimeout(ee,h(e))}function te(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function ne(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function re(){return s===void 0?o:te(Gg())}function ie(){var e=Gg(),n=g(e);if(r=arguments,i=this,c=e,n){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(ee,t),p(c)}return s===void 0&&(s=setTimeout(ee,t)),o}return ie.cancel=ne,ie.flush=re,ie}var Xg=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=e=>(this.beforeMountedListeners.push(e),this),this.mounted=e=>(this.mountedListeners.push(e),this),this.updated=e=>(this.updatedListeners.push(e),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners,selectionUpdated:this.selectionUpdatedListeners}}markdownUpdated(e){return this.markdownUpdatedListeners.push(e),this}blur(e){return this.blurListeners.push(e),this}focus(e){return this.focusListeners.push(e),this}destroy(e){return this.destroyListeners.push(e),this}selectionUpdated(e){return this.selectionUpdatedListeners.push(e),this}},Zg=b(new Xg,`listener`),Qg=new j(`MILKDOWN_LISTENER`),$g=e=>(e.inject(Zg,new Xg),async()=>{await e.wait(Jl);let{listeners:t}=e.get(Zg);t.beforeMount.forEach(t=>t(e)),await e.wait(vu);let n=e.get(xu),r=null,i=null,a=null,o=null,s=Yg(()=>{if(!o)return;let{doc:a}=o;if(t.updated.length>0&&r&&!r.eq(a)&&t.updated.forEach(t=>{t(e,a,r)}),t.markdownUpdated.length>0&&r&&!r.eq(a)){let r=n(a);t.markdownUpdated.forEach(t=>{t(e,r,i)}),i=r}r=a,o=null},200),c=new A({key:Qg,view:()=>({destroy:()=>{s.cancel(),t.destroy.forEach(t=>t(e))}}),props:{handleDOMEvents:{focus:()=>(t.focus.forEach(t=>t(e)),!1),blur:()=>(t.blur.forEach(t=>t(e)),!1)}},state:{init:(e,t)=>{r=t.doc,i=n(t.doc)},apply:n=>{let r=n.selection;(!a&&r||a&&!r.eq(a))&&(t.selectionUpdated.forEach(t=>{t(e,r,a)}),a=r),!(!(n.docChanged||n.storedMarksSet)||n.getMeta(`addToHistory`)===!1)&&(o=n,s())}}});e.update(Bl,e=>e.concat(c)),await e.wait(Pu),t.mounted.forEach(t=>t(e))});$g.meta={package:`@milkdown/plugin-listener`,displayName:`Listener`};var e_=n(),t_=`
34
34
  .milkdown-editor .ProseMirror {
35
35
  min-height: 100%;
36
36
  outline: none;