diff --git a/Sources/WeiBei/Resources/Editor/editor-entry.js b/Sources/WeiBei/Resources/Editor/editor-entry.js index eaf81fe46..8f8b5a2d7 100644 --- a/Sources/WeiBei/Resources/Editor/editor-entry.js +++ b/Sources/WeiBei/Resources/Editor/editor-entry.js @@ -1,96 +1,96 @@ -"use strict";(()=>{var I1=Object.create;var _l=Object.defineProperty;var N1=Object.getOwnPropertyDescriptor;var R1=Object.getOwnPropertyNames;var O1=Object.getPrototypeOf,D1=Object.prototype.hasOwnProperty;var L1=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},B1=(t,e)=>{for(var n in e)_l(t,n,{get:e[n],enumerable:!0})},P1=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R1(e))!D1.call(t,i)&&i!==n&&_l(t,i,{get:()=>e[i],enumerable:!(r=N1(e,i))||r.enumerable});return t};var F1=(t,e,n)=>(n=t!=null?I1(O1(t)):{},P1(e||!t||!t.__esModule?_l(n,"default",{value:t,enumerable:!0}):n,t));var Cm=L1((N_,wm)=>{"use strict";var Ys=Object.prototype.hasOwnProperty,xm=Object.prototype.toString,hm=Object.defineProperty,mm=Object.getOwnPropertyDescriptor,gm=function(e){return typeof Array.isArray=="function"?Array.isArray(e):xm.call(e)==="[object Array]"},ym=function(e){if(!e||xm.call(e)!=="[object Object]")return!1;var n=Ys.call(e,"constructor"),r=e.constructor&&e.constructor.prototype&&Ys.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!n&&!r)return!1;var i;for(i in e);return typeof i>"u"||Ys.call(e,i)},km=function(e,n){hm&&n.name==="__proto__"?hm(e,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):e[n.name]=n.newValue},bm=function(e,n){if(n==="__proto__")if(Ys.call(e,n)){if(mm)return mm(e,n).value}else return;return e[n]};wm.exports=function t(){var e,n,r,i,o,s,a=arguments[0],l=1,c=arguments.length,u=!1;for(typeof a=="boolean"&&(u=a,a=arguments[1]||{},l=2),(a==null||typeof a!="object"&&typeof a!="function")&&(a={});ltypeof e=="function"?"[Function]":e,Is=t=>JSON.stringify(t,z1);function Zp(t){return new ut(ct.docTypeError,`Doc type error, unsupported type: ${Is(t)}`)}function eh(t){return new ut(ct.contextNotFound,`Context "${t}" not found, do you forget to inject it?`)}function th(t){return new ut(ct.timerNotFound,`Timer "${t}" not found, do you forget to record it?`)}function Qr(){return new ut(ct.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function nh(t,e,n){let r=`Cannot create node for ${"name"in t?t.name:t}`,i=s=>{if(s==null)return"null";if(Array.isArray(s))return`[${s.map(i).join(", ")}]`;if(typeof s=="object")return"toJSON"in s&&typeof s.toJSON=="function"?JSON.stringify(s.toJSON()):"spec"in s?JSON.stringify(s.spec):JSON.stringify(s);if(typeof s=="string"||typeof s=="number"||typeof s=="boolean")return JSON.stringify(s);if(typeof s=="function")return`[Function: ${s.name||"anonymous"}]`;try{return String(s)}catch{return"[Unserializable]"}},o=[["[Description]",r],["[Attributes]",e],["[Content]",(n??[]).map(s=>s?typeof s=="object"&&"type"in s?`${s}`:i(s):"null")]].reduce((s,[a,l])=>{let c=`${a}: ${i(l)}.`;return s.concat(c)},[]);return new ut(ct.createNodeInParserFail,o.join(` -`))}function Hl(){return new ut(ct.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function rh(t){return new ut(ct.parserMatchError,`Cannot match target parser for node: ${Is(t)}.`)}function ih(t){return new ut(ct.serializerMatchError,`Cannot match target serializer for node: ${Is(t)}.`)}function oh(t,e){return new ut(ct.getAtomFromSchemaFail,`Cannot get ${t}: ${e} from schema.`)}function ft(t){return new ut(ct.expectDomTypeError,`Expect to be a dom, but get: ${Is(t)}.`)}function Ns(){return new ut(ct.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function Rs(t){return new ut(ct.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${t}" in schema.`)}function sh(t){return new ut(ct.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${t}" in schema.`)}var Wl=class{constructor(){this.sliceMap=new Map,this.get=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);if(!e)throw eh(typeof t=="string"?t:t.name);return e},this.remove=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);e&&this.sliceMap.delete(e.type.id)},this.has=t=>typeof t=="string"?[...this.sliceMap.values()].some(e=>e.type.name===t):this.sliceMap.has(t.id)}},$1=class{#t;#e;#r;constructor(t,e,n){this.#t=[],this.#r=()=>{this.#t.forEach(r=>r(this.#e))},this.set=r=>{this.#e=r,this.#r()},this.get=()=>this.#e,this.update=r=>{this.#e=r(this.#e),this.#r()},this.type=n,this.#e=e,t.set(n.id,this)}on(t){return this.#t.push(t),()=>{this.#t=this.#t.filter(e=>e!==t)}}once(t){let e=this.on(n=>{t(n),e()});return e}off(t){this.#t=this.#t.filter(e=>e!==t)}offAll(){this.#t=[]}},_1=class{constructor(t,e){this.id=Symbol(`Context-${e}`),this.name=e,this._defaultValue=t,this._typeInfo=()=>{throw Qr()}}create(t,e=this._defaultValue){return new $1(t,e,this)}},Y=(t,e)=>new _1(t,e),H1=class{#t;#e;#r;#n;#s;#o;#i;constructor(t,e,n){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#i=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),consumedSlices:[...this.#s].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),recordedTimers:[...this.#o].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)})),waitTimers:[...this.#i].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)}))}),this.onRecord=r=>{this.#o.set(r,{start:Date.now(),duration:0})},this.onClear=r=>{this.#o.delete(r)},this.onDone=r=>{let i=this.#o.get(r);i&&(i.duration=Date.now()-i.start)},this.onWait=(r,i)=>{let o=Date.now();i.finally(()=>{this.#i.set(r,{duration:Date.now()-o})}).catch(console.error)},this.onInject=r=>{this.#n.add(r)},this.onRemove=r=>{this.#n.delete(r)},this.onUse=r=>{this.#s.add(r)},this.#a=r=>this.#e.get(r).get(),this.#l=r=>this.#r.get(r).status,this.#e=t,this.#r=e,this.#t=n}#a;#l},ah=class lh{#t;#e;#r;#n;constructor(e,n,r){this.produce=i=>i&&Object.keys(i).length?new lh(this.#t,this.#e,{...i}):this,this.inject=(i,o)=>{let s=i.create(this.#t.sliceMap);return o!=null&&s.set(o),this.#n?.onInject(i),this},this.remove=i=>(this.#t.remove(i),this.#n?.onRemove(i),this),this.record=i=>(i.create(this.#e.store),this.#n?.onRecord(i),this),this.clearTimer=i=>(this.#e.remove(i),this.#n?.onClear(i),this),this.isInjected=i=>this.#t.has(i),this.isRecorded=i=>this.#e.has(i),this.use=i=>(this.#n?.onUse(i),this.#t.get(i)),this.get=i=>this.use(i).get(),this.set=(i,o)=>this.use(i).set(o),this.update=(i,o)=>this.use(i).update(o),this.timer=i=>this.#e.get(i),this.done=i=>{this.timer(i).done(),this.#n?.onDone(i)},this.wait=i=>{let o=this.timer(i).start();return this.#n?.onWait(i,o),o},this.waitTimers=async i=>{await Promise.all(this.get(i).map(o=>this.wait(o)))},this.#t=e,this.#e=n,this.#r=r,r&&(this.#n=new H1(e,n,r))}get meta(){return this.#r}get inspector(){return this.#n}},ch=class{constructor(){this.store=new Map,this.get=t=>{let e=this.store.get(t.id);if(!e)throw th(t.name);return e},this.remove=t=>{this.store.delete(t.id)},this.has=t=>this.store.has(t.id)}},W1=class{#t;#e;#r;#n;constructor(t,e){this.#t=null,this.#e=null,this.#n="pending",this.start=()=>(this.#t??=new Promise((n,r)=>{this.#e=i=>{i instanceof CustomEvent&&i.detail.id===this.#r&&(this.#n="resolved",this.#s(),i.stopImmediatePropagation(),n())},this.#o(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#s(),r(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{let n=new CustomEvent(this.type.name,{detail:{id:this.#r}});dispatchEvent(n)},this.#s=()=>{this.#e&&removeEventListener(this.type.name,this.#e)},this.#o=n=>{setTimeout(()=>{n()},this.type.timeout)},this.#r=Symbol(e.name),this.type=e,t.set(e.id,this)}get status(){return this.#n}#s;#o},j1=class{constructor(t,e=3e3){this.create=n=>new W1(n,this),this.id=Symbol(`Timer-${t}`),this.name=t,this.timeout=e}},bt=(t,e=3e3)=>new j1(t,e);var V1={};function Zn(t,e){let n=e||V1,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return fh(t,r,i)}function fh(t,e,n){if(q1(t)){if("value"in t)return t.type==="html"&&!n?"":t.value;if(e&&"alt"in t&&t.alt)return t.alt;if("children"in t)return uh(t.children,e,n)}return Array.isArray(t)?uh(t,e,n):""}function uh(t,e,n){let r=[],i=-1;for(;++ii?0:i+e:e=e>i?i:e,n=n>0?n:0,r.length<1e4)s=Array.from(r),s.unshift(e,n),t.splice(...s);else for(n&&t.splice(e,n);o0?(ke(t,t.length,0,e),t):e}var ph={}.hasOwnProperty;function Os(t){let e={},n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"\uFFFD":String.fromCodePoint(n)}function Ve(t){return t.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}var Ee=Tn(/[A-Za-z]/),Te=Tn(/[\dA-Za-z]/),hh=Tn(/[#-'*+\--9=?A-Z^-~]/);function er(t){return t!==null&&(t<32||t===127)}var oo=Tn(/\d/),mh=Tn(/[\dA-Fa-f]/),gh=Tn(/[!-/:-@[-`{-~]/);function D(t){return t!==null&&t<-2}function Z(t){return t!==null&&(t<0||t===32)}function j(t){return t===-2||t===-1||t===32}var tr=Tn(/\p{P}|\p{S}/u),Ht=Tn(/\s/);function Tn(t){return e;function e(n){return n!==null&&n>-1&&t.test(String.fromCharCode(n))}}function $(t,e,n,r){let i=r?r-1:Number.POSITIVE_INFINITY,o=0;return s;function s(l){return j(l)?(t.enter(n),a(l)):e(l)}function a(l){return j(l)&&o++s))return;let N=e.events.length,B=N,O,S;for(;B--;)if(e.events[B][0]==="exit"&&e.events[B][1].type==="chunkFlow"){if(O){S=e.events[B][1].end;break}O=!0}for(y(r),w=N;wC;){let A=n[v];e.containerState=A[1],A[0].exit.call(e,t)}n.length=C}function x(){i.write([null]),o=void 0,i=void 0,e.containerState._closeFlow=void 0}}function X1(t,e,n){return $(t,t.attempt(this.parser.constructs.document,e,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function rn(t){if(t===null||Z(t)||Ht(t))return 1;if(tr(t))return 2}function vn(t,e,n){let r=[],i=-1;for(;++i1&&t[n][1].end.offset-t[n][1].start.offset>1?2:1;let f={...t[r][1].end},d={...t[n][1].start};xh(f,-l),xh(d,l),s={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...t[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...t[n][1].start},end:d},o={type:l>1?"strongText":"emphasisText",start:{...t[r][1].end},end:{...t[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...s.start},end:{...a.end}},t[r][1].end={...s.start},t[n][1].start={...a.end},c=[],t[r][1].end.offset-t[r][1].start.offset&&(c=Ge(c,[["enter",t[r][1],e],["exit",t[r][1],e]])),c=Ge(c,[["enter",i,e],["enter",s,e],["exit",s,e],["enter",o,e]]),c=Ge(c,vn(e.parser.constructs.insideSpan.null,t.slice(r+1,n),e)),c=Ge(c,[["exit",o,e],["enter",a,e],["exit",a,e],["exit",i,e]]),t[n][1].end.offset-t[n][1].start.offset?(u=2,c=Ge(c,[["enter",t[n][1],e],["exit",t[n][1],e]])):u=0,ke(t,r-1,n-r+3,c),n=r+c.length-u-2;break}}for(n=-1;++n0&&j(w)?$(t,x,"linePrefix",o+1)(w):x(w)}function x(w){return w===null||D(w)?t.check(wh,m,v)(w):(t.enter("codeFlowValue"),C(w))}function C(w){return w===null||D(w)?(t.exit("codeFlowValue"),x(w)):(t.consume(w),C)}function v(w){return t.exit("codeFenced"),e(w)}function A(w,N,B){let O=0;return S;function S(V){return w.enter("lineEnding"),w.consume(V),w.exit("lineEnding"),me}function me(V){return w.enter("codeFencedFence"),j(V)?$(w,te,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(V):te(V)}function te(V){return V===a?(w.enter("codeFencedFenceSequence"),F(V)):B(V)}function F(V){return V===a?(O++,w.consume(V),F):O>=s?(w.exit("codeFencedFenceSequence"),j(V)?$(w,W,"whitespace")(V):W(V)):B(V)}function W(V){return V===null||D(V)?(w.exit("codeFencedFence"),N(V)):B(V)}}}function aC(t,e,n){let r=this;return i;function i(s){return s===null?n(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}var ao={name:"codeIndented",tokenize:cC},lC={partial:!0,tokenize:uC};function cC(t,e,n){let r=this;return i;function i(c){return t.enter("codeIndented"),$(t,o,"linePrefix",5)(c)}function o(c){let u=r.events[r.events.length-1];return u&&u[1].type==="linePrefix"&&u[2].sliceSerialize(u[1],!0).length>=4?s(c):n(c)}function s(c){return c===null?l(c):D(c)?t.attempt(lC,s,l)(c):(t.enter("codeFlowValue"),a(c))}function a(c){return c===null||D(c)?(t.exit("codeFlowValue"),s(c)):(t.consume(c),a)}function l(c){return t.exit("codeIndented"),e(c)}}function uC(t,e,n){let r=this;return i;function i(s){return r.parser.lazy[r.now().line]?n(s):D(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),i):$(t,o,"linePrefix",5)(s)}function o(s){let a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(s):D(s)?i(s):n(s)}}var Vl={name:"codeText",previous:dC,resolve:fC,tokenize:pC};function fC(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(e,n,r){let i=n||0;this.setCursor(Math.trunc(e));let o=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&lo(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),lo(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),lo(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?e(s):t.interrupt(r.parser.constructs.flow,n,e)(s)}}function _s(t,e,n,r,i,o,s,a,l){let c=l||Number.POSITIVE_INFINITY,u=0;return f;function f(y){return y===60?(t.enter(r),t.enter(i),t.enter(o),t.consume(y),t.exit(o),d):y===null||y===32||y===41||er(y)?n(y):(t.enter(r),t.enter(s),t.enter(a),t.enter("chunkString",{contentType:"string"}),m(y))}function d(y){return y===62?(t.enter(o),t.consume(y),t.exit(o),t.exit(i),t.exit(r),e):(t.enter(a),t.enter("chunkString",{contentType:"string"}),p(y))}function p(y){return y===62?(t.exit("chunkString"),t.exit(a),d(y)):y===null||y===60||D(y)?n(y):(t.consume(y),y===92?h:p)}function h(y){return y===60||y===62||y===92?(t.consume(y),p):p(y)}function m(y){return!u&&(y===null||y===41||Z(y))?(t.exit("chunkString"),t.exit(a),t.exit(s),t.exit(r),e(y)):u999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in s.parser.constructs?n(p):p===93?(t.exit(o),t.enter(i),t.consume(p),t.exit(i),t.exit(r),e):D(p)?(t.enter("lineEnding"),t.consume(p),t.exit("lineEnding"),u):(t.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||D(p)||a++>999?(t.exit("chunkString"),u(p)):(t.consume(p),l||(l=!j(p)),p===92?d:f)}function d(p){return p===91||p===92||p===93?(t.consume(p),a++,f):f(p)}}function Ws(t,e,n,r,i,o){let s;return a;function a(d){return d===34||d===39||d===40?(t.enter(r),t.enter(i),t.consume(d),t.exit(i),s=d===40?41:d,l):n(d)}function l(d){return d===s?(t.enter(i),t.consume(d),t.exit(i),t.exit(r),e):(t.enter(o),c(d))}function c(d){return d===s?(t.exit(o),l(s)):d===null?n(d):D(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),$(t,c,"linePrefix")):(t.enter("chunkString",{contentType:"string"}),u(d))}function u(d){return d===s||d===null||D(d)?(t.exit("chunkString"),c(d)):(t.consume(d),d===92?f:u)}function f(d){return d===s||d===92?(t.consume(d),u):u(d)}}function nr(t,e){let n;return r;function r(i){return D(i)?(t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),n=!0,r):j(i)?$(t,r,n?"linePrefix":"lineSuffix")(i):e(i)}}var Kl={name:"definition",tokenize:xC},bC={partial:!0,tokenize:wC};function xC(t,e,n){let r=this,i;return o;function o(p){return t.enter("definition"),s(p)}function s(p){return Hs.call(r,t,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Ve(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(t.enter("definitionMarker"),t.consume(p),t.exit("definitionMarker"),l):n(p)}function l(p){return Z(p)?nr(t,c)(p):c(p)}function c(p){return _s(t,u,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function u(p){return t.attempt(bC,f,f)(p)}function f(p){return j(p)?$(t,d,"whitespace")(p):d(p)}function d(p){return p===null||D(p)?(t.exit("definition"),r.parser.defined.push(i),e(p)):n(p)}}function wC(t,e,n){return r;function r(a){return Z(a)?nr(t,i)(a):n(a)}function i(a){return Ws(t,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function o(a){return j(a)?$(t,s,"whitespace")(a):s(a)}function s(a){return a===null||D(a)?e(a):n(a)}}var Ul={name:"hardBreakEscape",tokenize:CC};function CC(t,e,n){return r;function r(o){return t.enter("hardBreakEscape"),t.consume(o),i}function i(o){return D(o)?(t.exit("hardBreakEscape"),e(o)):n(o)}}var Jl={name:"headingAtx",resolve:SC,tokenize:MC};function SC(t,e){let n=t.length-2,r=3,i,o;return t[r][1].type==="whitespace"&&(r+=2),n-2>r&&t[n][1].type==="whitespace"&&(n-=2),t[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&t[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:t[r][1].start,end:t[n][1].end},o={type:"chunkText",start:t[r][1].start,end:t[n][1].end,contentType:"text"},ke(t,r,n-r+1,[["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e]])),t}function MC(t,e,n){let r=0;return i;function i(u){return t.enter("atxHeading"),o(u)}function o(u){return t.enter("atxHeadingSequence"),s(u)}function s(u){return u===35&&r++<6?(t.consume(u),s):u===null||Z(u)?(t.exit("atxHeadingSequence"),a(u)):n(u)}function a(u){return u===35?(t.enter("atxHeadingSequence"),l(u)):u===null||D(u)?(t.exit("atxHeading"),e(u)):j(u)?$(t,a,"whitespace")(u):(t.enter("atxHeadingText"),c(u))}function l(u){return u===35?(t.consume(u),l):(t.exit("atxHeadingSequence"),a(u))}function c(u){return u===null||u===35||Z(u)?(t.exit("atxHeadingText"),a(u)):(t.consume(u),c)}}var Ch=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Gl=["pre","script","style","textarea"];var Xl={concrete:!0,name:"htmlFlow",resolveTo:vC,tokenize:AC},EC={partial:!0,tokenize:NC},TC={partial:!0,tokenize:IC};function vC(t){let e=t.length;for(;e--&&!(t[e][0]==="enter"&&t[e][1].type==="htmlFlow"););return e>1&&t[e-2][1].type==="linePrefix"&&(t[e][1].start=t[e-2][1].start,t[e+1][1].start=t[e-2][1].start,t.splice(e-2,2)),t}function AC(t,e,n){let r=this,i,o,s,a,l;return c;function c(b){return u(b)}function u(b){return t.enter("htmlFlow"),t.enter("htmlFlowData"),t.consume(b),f}function f(b){return b===33?(t.consume(b),d):b===47?(t.consume(b),o=!0,m):b===63?(t.consume(b),i=3,r.interrupt?e:k):Ee(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function d(b){return b===45?(t.consume(b),i=2,p):b===91?(t.consume(b),i=5,a=0,h):Ee(b)?(t.consume(b),i=4,r.interrupt?e:k):n(b)}function p(b){return b===45?(t.consume(b),r.interrupt?e:k):n(b)}function h(b){let at="CDATA[";return b===at.charCodeAt(a++)?(t.consume(b),a===at.length?r.interrupt?e:te:h):n(b)}function m(b){return Ee(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function g(b){if(b===null||b===47||b===62||Z(b)){let at=b===47,Xn=s.toLowerCase();return!at&&!o&&Gl.includes(Xn)?(i=1,r.interrupt?e(b):te(b)):Ch.includes(s.toLowerCase())?(i=6,at?(t.consume(b),y):r.interrupt?e(b):te(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):o?x(b):C(b))}return b===45||Te(b)?(t.consume(b),s+=String.fromCharCode(b),g):n(b)}function y(b){return b===62?(t.consume(b),r.interrupt?e:te):n(b)}function x(b){return j(b)?(t.consume(b),x):S(b)}function C(b){return b===47?(t.consume(b),S):b===58||b===95||Ee(b)?(t.consume(b),v):j(b)?(t.consume(b),C):S(b)}function v(b){return b===45||b===46||b===58||b===95||Te(b)?(t.consume(b),v):A(b)}function A(b){return b===61?(t.consume(b),w):j(b)?(t.consume(b),A):C(b)}function w(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(t.consume(b),l=b,N):j(b)?(t.consume(b),w):B(b)}function N(b){return b===l?(t.consume(b),l=null,O):b===null||D(b)?n(b):(t.consume(b),N)}function B(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Z(b)?A(b):(t.consume(b),B)}function O(b){return b===47||b===62||j(b)?C(b):n(b)}function S(b){return b===62?(t.consume(b),me):n(b)}function me(b){return b===null||D(b)?te(b):j(b)?(t.consume(b),me):n(b)}function te(b){return b===45&&i===2?(t.consume(b),se):b===60&&i===1?(t.consume(b),fe):b===62&&i===4?(t.consume(b),kt):b===63&&i===3?(t.consume(b),k):b===93&&i===5?(t.consume(b),Me):D(b)&&(i===6||i===7)?(t.exit("htmlFlowData"),t.check(EC,Zt,F)(b)):b===null||D(b)?(t.exit("htmlFlowData"),F(b)):(t.consume(b),te)}function F(b){return t.check(TC,W,Zt)(b)}function W(b){return t.enter("lineEnding"),t.consume(b),t.exit("lineEnding"),V}function V(b){return b===null||D(b)?F(b):(t.enter("htmlFlowData"),te(b))}function se(b){return b===45?(t.consume(b),k):te(b)}function fe(b){return b===47?(t.consume(b),s="",ye):te(b)}function ye(b){if(b===62){let at=s.toLowerCase();return Gl.includes(at)?(t.consume(b),kt):te(b)}return Ee(b)&&s.length<8?(t.consume(b),s+=String.fromCharCode(b),ye):te(b)}function Me(b){return b===93?(t.consume(b),k):te(b)}function k(b){return b===62?(t.consume(b),kt):b===45&&i===2?(t.consume(b),k):te(b)}function kt(b){return b===null||D(b)?(t.exit("htmlFlowData"),Zt(b)):(t.consume(b),kt)}function Zt(b){return t.exit("htmlFlow"),e(b)}}function IC(t,e,n){let r=this;return i;function i(s){return D(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o):n(s)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function NC(t,e,n){return r;function r(i){return t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),t.attempt(Wt,e,n)}}var Yl={name:"htmlText",tokenize:RC};function RC(t,e,n){let r=this,i,o,s;return a;function a(k){return t.enter("htmlText"),t.enter("htmlTextData"),t.consume(k),l}function l(k){return k===33?(t.consume(k),c):k===47?(t.consume(k),A):k===63?(t.consume(k),C):Ee(k)?(t.consume(k),B):n(k)}function c(k){return k===45?(t.consume(k),u):k===91?(t.consume(k),o=0,h):Ee(k)?(t.consume(k),x):n(k)}function u(k){return k===45?(t.consume(k),p):n(k)}function f(k){return k===null?n(k):k===45?(t.consume(k),d):D(k)?(s=f,fe(k)):(t.consume(k),f)}function d(k){return k===45?(t.consume(k),p):f(k)}function p(k){return k===62?se(k):k===45?d(k):f(k)}function h(k){let kt="CDATA[";return k===kt.charCodeAt(o++)?(t.consume(k),o===kt.length?m:h):n(k)}function m(k){return k===null?n(k):k===93?(t.consume(k),g):D(k)?(s=m,fe(k)):(t.consume(k),m)}function g(k){return k===93?(t.consume(k),y):m(k)}function y(k){return k===62?se(k):k===93?(t.consume(k),y):m(k)}function x(k){return k===null||k===62?se(k):D(k)?(s=x,fe(k)):(t.consume(k),x)}function C(k){return k===null?n(k):k===63?(t.consume(k),v):D(k)?(s=C,fe(k)):(t.consume(k),C)}function v(k){return k===62?se(k):C(k)}function A(k){return Ee(k)?(t.consume(k),w):n(k)}function w(k){return k===45||Te(k)?(t.consume(k),w):N(k)}function N(k){return D(k)?(s=N,fe(k)):j(k)?(t.consume(k),N):se(k)}function B(k){return k===45||Te(k)?(t.consume(k),B):k===47||k===62||Z(k)?O(k):n(k)}function O(k){return k===47?(t.consume(k),se):k===58||k===95||Ee(k)?(t.consume(k),S):D(k)?(s=O,fe(k)):j(k)?(t.consume(k),O):se(k)}function S(k){return k===45||k===46||k===58||k===95||Te(k)?(t.consume(k),S):me(k)}function me(k){return k===61?(t.consume(k),te):D(k)?(s=me,fe(k)):j(k)?(t.consume(k),me):O(k)}function te(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(t.consume(k),i=k,F):D(k)?(s=te,fe(k)):j(k)?(t.consume(k),te):(t.consume(k),W)}function F(k){return k===i?(t.consume(k),i=void 0,V):k===null?n(k):D(k)?(s=F,fe(k)):(t.consume(k),F)}function W(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||Z(k)?O(k):(t.consume(k),W)}function V(k){return k===47||k===62||Z(k)?O(k):n(k)}function se(k){return k===62?(t.consume(k),t.exit("htmlTextData"),t.exit("htmlText"),e):n(k)}function fe(k){return t.exit("htmlTextData"),t.enter("lineEnding"),t.consume(k),t.exit("lineEnding"),ye}function ye(k){return j(k)?$(t,Me,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):Me(k)}function Me(k){return t.enter("htmlTextData"),s(k)}}var rr={name:"labelEnd",resolveAll:BC,resolveTo:PC,tokenize:FC},OC={tokenize:zC},DC={tokenize:$C},LC={tokenize:_C};function BC(t){let e=-1,n=[];for(;++e=3&&(c===null||D(c))?(t.exit("thematicBreak"),e(c)):n(c)}function l(c){return c===i?(t.consume(c),r++,l):(t.exit("thematicBreakSequence"),j(c)?$(t,a,"whitespace")(c):a(c))}}var qe={continuation:{tokenize:JC},exit:XC,name:"list",tokenize:UC},qC={partial:!0,tokenize:YC},KC={partial:!0,tokenize:GC};function UC(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(p){let h=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(h==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:oo(p)){if(r.containerState.type||(r.containerState.type=h,t.enter(h,{_container:!0})),h==="listUnordered")return t.enter("listItemPrefix"),p===42||p===45?t.check(ir,n,c)(p):c(p);if(!r.interrupt||p===49)return t.enter("listItemPrefix"),t.enter("listItemValue"),l(p)}return n(p)}function l(p){return oo(p)&&++s<10?(t.consume(p),l):(!r.interrupt||s<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(t.exit("listItemValue"),c(p)):n(p)}function c(p){return t.enter("listItemMarker"),t.consume(p),t.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,t.check(Wt,r.interrupt?n:u,t.attempt(qC,d,f))}function u(p){return r.containerState.initialBlankLine=!0,o++,d(p)}function f(p){return j(p)?(t.enter("listItemPrefixWhitespace"),t.consume(p),t.exit("listItemPrefixWhitespace"),d):n(p)}function d(p){return r.containerState.size=o+r.sliceSerialize(t.exit("listItemPrefix"),!0).length,e(p)}}function JC(t,e,n){let r=this;return r.containerState._closeFlow=void 0,t.check(Wt,i,o);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,$(t,e,"listItemIndent",r.containerState.size+1)(a)}function o(a){return r.containerState.furtherBlankLines||!j(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,t.attempt(KC,e,s)(a))}function s(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,$(t,t.attempt(qe,e,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function GC(t,e,n){let r=this;return $(t,i,"listItemIndent",r.containerState.size+1);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===r.containerState.size?e(o):n(o)}}function XC(t){t.exit(this.containerState.type)}function YC(t,e,n){let r=this;return $(t,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(o){let s=r.events[r.events.length-1];return!j(o)&&s&&s[1].type==="listItemPrefixWhitespace"?e(o):n(o)}}var js={name:"setextUnderline",resolveTo:QC,tokenize:ZC};function QC(t,e){let n=t.length,r,i,o;for(;n--;)if(t[n][0]==="enter"){if(t[n][1].type==="content"){r=n;break}t[n][1].type==="paragraph"&&(i=n)}else t[n][1].type==="content"&&t.splice(n,1),!o&&t[n][1].type==="definition"&&(o=n);let s={type:"setextHeading",start:{...t[r][1].start},end:{...t[t.length-1][1].end}};return t[i][1].type="setextHeadingText",o?(t.splice(i,0,["enter",s,e]),t.splice(o+1,0,["exit",t[r][1],e]),t[r][1].end={...t[o][1].end}):t[r][1]=s,t.push(["exit",s,e]),t}function ZC(t,e,n){let r=this,i;return o;function o(c){let u=r.events.length,f;for(;u--;)if(r.events[u][1].type!=="lineEnding"&&r.events[u][1].type!=="linePrefix"&&r.events[u][1].type!=="content"){f=r.events[u][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(t.enter("setextHeadingLine"),i=c,s(c)):n(c)}function s(c){return t.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===i?(t.consume(c),a):(t.exit("setextHeadingLineSequence"),j(c)?$(t,l,"lineSuffix")(c):l(c))}function l(c){return c===null||D(c)?(t.exit("setextHeadingLine"),e(c)):n(c)}}var Sh={tokenize:eS};function eS(t){let e=this,n=t.attempt(Wt,r,t.attempt(this.parser.constructs.flowInitial,i,$(t,t.attempt(this.parser.constructs.flow,i,t.attempt(ql,i)),"linePrefix")));return n;function r(o){if(o===null){t.consume(o);return}return t.enter("lineEndingBlank"),t.consume(o),t.exit("lineEndingBlank"),e.currentConstruct=void 0,n}function i(o){if(o===null){t.consume(o);return}return t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),e.currentConstruct=void 0,n}}var Mh={resolveAll:Ah()},Eh=vh("string"),Th=vh("text");function vh(t){return{resolveAll:Ah(t==="text"?tS:void 0),tokenize:e};function e(n){let r=this,i=this.parser.constructs[t],o=n.attempt(i,s,a);return s;function s(u){return c(u)?o(u):a(u)}function a(u){if(u===null){n.consume(u);return}return n.enter("data"),n.consume(u),l}function l(u){return c(u)?(n.exit("data"),o(u)):(n.consume(u),l)}function c(u){if(u===null)return!0;let f=i[u],d=-1;if(f)for(;++dcS,contentInitial:()=>rS,disable:()=>uS,document:()=>nS,flow:()=>oS,flowInitial:()=>iS,insideSpan:()=>lS,string:()=>sS,text:()=>aS});var nS={42:qe,43:qe,45:qe,48:qe,49:qe,50:qe,51:qe,52:qe,53:qe,54:qe,55:qe,56:qe,57:qe,62:Ls},rS={91:Kl},iS={[-2]:ao,[-1]:ao,32:ao},oS={35:Jl,42:ir,45:[js,ir],60:Xl,61:js,95:ir,96:Fs,126:Fs},sS={38:Ps,92:Bs},aS={[-5]:co,[-4]:co,[-3]:co,33:Ql,38:Ps,42:so,60:[jl,Yl],91:Zl,92:[Ul,Bs],93:rr,95:so,96:Vl},lS={null:[so,Mh]},cS={null:[42,95]},uS={null:[]};function Ih(t,e,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},o=[],s=[],a=[],l=!0,c={attempt:O(N),check:O(B),consume:v,enter:A,exit:w,interrupt:O(B,{interrupt:!0})},u={code:null,containerState:{},defineSkip:y,events:[],now:g,parser:t,previous:null,sliceSerialize:h,sliceStream:m,write:p},f=e.tokenize.call(u,c),d;return e.resolveAll&&o.push(e),u;function p(F){return s=Ge(s,F),x(),s[s.length-1]!==null?[]:(S(e,0),u.events=vn(o,u.events,u),u.events)}function h(F,W){return dS(m(F),W)}function m(F){return fS(s,F)}function g(){let{_bufferIndex:F,_index:W,line:V,column:se,offset:fe}=r;return{_bufferIndex:F,_index:W,line:V,column:se,offset:fe}}function y(F){i[F.line]=F.column,te()}function x(){let F;for(;r._index-1){let a=s[0];typeof a=="string"?s[0]=a.slice(r):s.shift()}o>0&&s.push(t[i].slice(0,o))}return s}function dS(t,e){let n=-1,r=[],i;for(;++n{var N1=Object.create;var _l=Object.defineProperty;var R1=Object.getOwnPropertyDescriptor;var O1=Object.getOwnPropertyNames;var D1=Object.getPrototypeOf,L1=Object.prototype.hasOwnProperty;var B1=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},P1=(t,e)=>{for(var n in e)_l(t,n,{get:e[n],enumerable:!0})},F1=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of O1(e))!L1.call(t,i)&&i!==n&&_l(t,i,{get:()=>e[i],enumerable:!(r=R1(e,i))||r.enumerable});return t};var z1=(t,e,n)=>(n=t!=null?N1(D1(t)):{},F1(e||!t||!t.__esModule?_l(n,"default",{value:t,enumerable:!0}):n,t));var Sm=B1((N_,Cm)=>{"use strict";var Ys=Object.prototype.hasOwnProperty,wm=Object.prototype.toString,mm=Object.defineProperty,gm=Object.getOwnPropertyDescriptor,ym=function(e){return typeof Array.isArray=="function"?Array.isArray(e):wm.call(e)==="[object Array]"},km=function(e){if(!e||wm.call(e)!=="[object Object]")return!1;var n=Ys.call(e,"constructor"),r=e.constructor&&e.constructor.prototype&&Ys.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!n&&!r)return!1;var i;for(i in e);return typeof i>"u"||Ys.call(e,i)},bm=function(e,n){mm&&n.name==="__proto__"?mm(e,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):e[n.name]=n.newValue},xm=function(e,n){if(n==="__proto__")if(Ys.call(e,n)){if(gm)return gm(e,n).value}else return;return e[n]};Cm.exports=function t(){var e,n,r,i,o,s,a=arguments[0],l=1,c=arguments.length,u=!1;for(typeof a=="boolean"&&(u=a,a=arguments[1]||{},l=2),(a==null||typeof a!="object"&&typeof a!="function")&&(a={});ltypeof e=="function"?"[Function]":e,Is=t=>JSON.stringify(t,$1);function eh(t){return new ut(ct.docTypeError,`Doc type error, unsupported type: ${Is(t)}`)}function th(t){return new ut(ct.contextNotFound,`Context "${t}" not found, do you forget to inject it?`)}function nh(t){return new ut(ct.timerNotFound,`Timer "${t}" not found, do you forget to record it?`)}function Qr(){return new ut(ct.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function rh(t,e,n){let r=`Cannot create node for ${"name"in t?t.name:t}`,i=s=>{if(s==null)return"null";if(Array.isArray(s))return`[${s.map(i).join(", ")}]`;if(typeof s=="object")return"toJSON"in s&&typeof s.toJSON=="function"?JSON.stringify(s.toJSON()):"spec"in s?JSON.stringify(s.spec):JSON.stringify(s);if(typeof s=="string"||typeof s=="number"||typeof s=="boolean")return JSON.stringify(s);if(typeof s=="function")return`[Function: ${s.name||"anonymous"}]`;try{return String(s)}catch{return"[Unserializable]"}},o=[["[Description]",r],["[Attributes]",e],["[Content]",(n??[]).map(s=>s?typeof s=="object"&&"type"in s?`${s}`:i(s):"null")]].reduce((s,[a,l])=>{let c=`${a}: ${i(l)}.`;return s.concat(c)},[]);return new ut(ct.createNodeInParserFail,o.join(` +`))}function Hl(){return new ut(ct.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function ih(t){return new ut(ct.parserMatchError,`Cannot match target parser for node: ${Is(t)}.`)}function oh(t){return new ut(ct.serializerMatchError,`Cannot match target serializer for node: ${Is(t)}.`)}function sh(t,e){return new ut(ct.getAtomFromSchemaFail,`Cannot get ${t}: ${e} from schema.`)}function ft(t){return new ut(ct.expectDomTypeError,`Expect to be a dom, but get: ${Is(t)}.`)}function Ns(){return new ut(ct.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function Rs(t){return new ut(ct.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${t}" in schema.`)}function ah(t){return new ut(ct.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${t}" in schema.`)}var Wl=class{constructor(){this.sliceMap=new Map,this.get=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);if(!e)throw th(typeof t=="string"?t:t.name);return e},this.remove=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);e&&this.sliceMap.delete(e.type.id)},this.has=t=>typeof t=="string"?[...this.sliceMap.values()].some(e=>e.type.name===t):this.sliceMap.has(t.id)}},_1=class{#t;#e;#r;constructor(t,e,n){this.#t=[],this.#r=()=>{this.#t.forEach(r=>r(this.#e))},this.set=r=>{this.#e=r,this.#r()},this.get=()=>this.#e,this.update=r=>{this.#e=r(this.#e),this.#r()},this.type=n,this.#e=e,t.set(n.id,this)}on(t){return this.#t.push(t),()=>{this.#t=this.#t.filter(e=>e!==t)}}once(t){let e=this.on(n=>{t(n),e()});return e}off(t){this.#t=this.#t.filter(e=>e!==t)}offAll(){this.#t=[]}},H1=class{constructor(t,e){this.id=Symbol(`Context-${e}`),this.name=e,this._defaultValue=t,this._typeInfo=()=>{throw Qr()}}create(t,e=this._defaultValue){return new _1(t,e,this)}},Y=(t,e)=>new H1(t,e),W1=class{#t;#e;#r;#n;#s;#o;#i;constructor(t,e,n){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#i=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),consumedSlices:[...this.#s].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),recordedTimers:[...this.#o].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)})),waitTimers:[...this.#i].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)}))}),this.onRecord=r=>{this.#o.set(r,{start:Date.now(),duration:0})},this.onClear=r=>{this.#o.delete(r)},this.onDone=r=>{let i=this.#o.get(r);i&&(i.duration=Date.now()-i.start)},this.onWait=(r,i)=>{let o=Date.now();i.finally(()=>{this.#i.set(r,{duration:Date.now()-o})}).catch(console.error)},this.onInject=r=>{this.#n.add(r)},this.onRemove=r=>{this.#n.delete(r)},this.onUse=r=>{this.#s.add(r)},this.#a=r=>this.#e.get(r).get(),this.#l=r=>this.#r.get(r).status,this.#e=t,this.#r=e,this.#t=n}#a;#l},lh=class ch{#t;#e;#r;#n;constructor(e,n,r){this.produce=i=>i&&Object.keys(i).length?new ch(this.#t,this.#e,{...i}):this,this.inject=(i,o)=>{let s=i.create(this.#t.sliceMap);return o!=null&&s.set(o),this.#n?.onInject(i),this},this.remove=i=>(this.#t.remove(i),this.#n?.onRemove(i),this),this.record=i=>(i.create(this.#e.store),this.#n?.onRecord(i),this),this.clearTimer=i=>(this.#e.remove(i),this.#n?.onClear(i),this),this.isInjected=i=>this.#t.has(i),this.isRecorded=i=>this.#e.has(i),this.use=i=>(this.#n?.onUse(i),this.#t.get(i)),this.get=i=>this.use(i).get(),this.set=(i,o)=>this.use(i).set(o),this.update=(i,o)=>this.use(i).update(o),this.timer=i=>this.#e.get(i),this.done=i=>{this.timer(i).done(),this.#n?.onDone(i)},this.wait=i=>{let o=this.timer(i).start();return this.#n?.onWait(i,o),o},this.waitTimers=async i=>{await Promise.all(this.get(i).map(o=>this.wait(o)))},this.#t=e,this.#e=n,this.#r=r,r&&(this.#n=new W1(e,n,r))}get meta(){return this.#r}get inspector(){return this.#n}},uh=class{constructor(){this.store=new Map,this.get=t=>{let e=this.store.get(t.id);if(!e)throw nh(t.name);return e},this.remove=t=>{this.store.delete(t.id)},this.has=t=>this.store.has(t.id)}},j1=class{#t;#e;#r;#n;constructor(t,e){this.#t=null,this.#e=null,this.#n="pending",this.start=()=>(this.#t??=new Promise((n,r)=>{this.#e=i=>{i instanceof CustomEvent&&i.detail.id===this.#r&&(this.#n="resolved",this.#s(),i.stopImmediatePropagation(),n())},this.#o(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#s(),r(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{let n=new CustomEvent(this.type.name,{detail:{id:this.#r}});dispatchEvent(n)},this.#s=()=>{this.#e&&removeEventListener(this.type.name,this.#e)},this.#o=n=>{setTimeout(()=>{n()},this.type.timeout)},this.#r=Symbol(e.name),this.type=e,t.set(e.id,this)}get status(){return this.#n}#s;#o},V1=class{constructor(t,e=3e3){this.create=n=>new j1(n,this),this.id=Symbol(`Timer-${t}`),this.name=t,this.timeout=e}},bt=(t,e=3e3)=>new V1(t,e);var q1={};function Zn(t,e){let n=e||q1,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return dh(t,r,i)}function dh(t,e,n){if(K1(t)){if("value"in t)return t.type==="html"&&!n?"":t.value;if(e&&"alt"in t&&t.alt)return t.alt;if("children"in t)return fh(t.children,e,n)}return Array.isArray(t)?fh(t,e,n):""}function fh(t,e,n){let r=[],i=-1;for(;++ii?0:i+e:e=e>i?i:e,n=n>0?n:0,r.length<1e4)s=Array.from(r),s.unshift(e,n),t.splice(...s);else for(n&&t.splice(e,n);o0?(ke(t,t.length,0,e),t):e}var hh={}.hasOwnProperty;function Os(t){let e={},n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"\uFFFD":String.fromCodePoint(n)}function Ve(t){return t.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}var Ee=Tn(/[A-Za-z]/),Te=Tn(/[\dA-Za-z]/),mh=Tn(/[#-'*+\--9=?A-Z^-~]/);function er(t){return t!==null&&(t<32||t===127)}var oo=Tn(/\d/),gh=Tn(/[\dA-Fa-f]/),yh=Tn(/[!-/:-@[-`{-~]/);function D(t){return t!==null&&t<-2}function Z(t){return t!==null&&(t<0||t===32)}function j(t){return t===-2||t===-1||t===32}var tr=Tn(/\p{P}|\p{S}/u),Ht=Tn(/\s/);function Tn(t){return e;function e(n){return n!==null&&n>-1&&t.test(String.fromCharCode(n))}}function $(t,e,n,r){let i=r?r-1:Number.POSITIVE_INFINITY,o=0;return s;function s(l){return j(l)?(t.enter(n),a(l)):e(l)}function a(l){return j(l)&&o++s))return;let N=e.events.length,B=N,O,S;for(;B--;)if(e.events[B][0]==="exit"&&e.events[B][1].type==="chunkFlow"){if(O){S=e.events[B][1].end;break}O=!0}for(y(r),w=N;wC;){let A=n[v];e.containerState=A[1],A[0].exit.call(e,t)}n.length=C}function x(){i.write([null]),o=void 0,i=void 0,e.containerState._closeFlow=void 0}}function Y1(t,e,n){return $(t,t.attempt(this.parser.constructs.document,e,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function rn(t){if(t===null||Z(t)||Ht(t))return 1;if(tr(t))return 2}function vn(t,e,n){let r=[],i=-1;for(;++i1&&t[n][1].end.offset-t[n][1].start.offset>1?2:1;let f={...t[r][1].end},d={...t[n][1].start};wh(f,-l),wh(d,l),s={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...t[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...t[n][1].start},end:d},o={type:l>1?"strongText":"emphasisText",start:{...t[r][1].end},end:{...t[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...s.start},end:{...a.end}},t[r][1].end={...s.start},t[n][1].start={...a.end},c=[],t[r][1].end.offset-t[r][1].start.offset&&(c=Ge(c,[["enter",t[r][1],e],["exit",t[r][1],e]])),c=Ge(c,[["enter",i,e],["enter",s,e],["exit",s,e],["enter",o,e]]),c=Ge(c,vn(e.parser.constructs.insideSpan.null,t.slice(r+1,n),e)),c=Ge(c,[["exit",o,e],["enter",a,e],["exit",a,e],["exit",i,e]]),t[n][1].end.offset-t[n][1].start.offset?(u=2,c=Ge(c,[["enter",t[n][1],e],["exit",t[n][1],e]])):u=0,ke(t,r-1,n-r+3,c),n=r+c.length-u-2;break}}for(n=-1;++n0&&j(w)?$(t,x,"linePrefix",o+1)(w):x(w)}function x(w){return w===null||D(w)?t.check(Ch,m,v)(w):(t.enter("codeFlowValue"),C(w))}function C(w){return w===null||D(w)?(t.exit("codeFlowValue"),x(w)):(t.consume(w),C)}function v(w){return t.exit("codeFenced"),e(w)}function A(w,N,B){let O=0;return S;function S(V){return w.enter("lineEnding"),w.consume(V),w.exit("lineEnding"),me}function me(V){return w.enter("codeFencedFence"),j(V)?$(w,te,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(V):te(V)}function te(V){return V===a?(w.enter("codeFencedFenceSequence"),F(V)):B(V)}function F(V){return V===a?(O++,w.consume(V),F):O>=s?(w.exit("codeFencedFenceSequence"),j(V)?$(w,W,"whitespace")(V):W(V)):B(V)}function W(V){return V===null||D(V)?(w.exit("codeFencedFence"),N(V)):B(V)}}}function lC(t,e,n){let r=this;return i;function i(s){return s===null?n(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}var ao={name:"codeIndented",tokenize:uC},cC={partial:!0,tokenize:fC};function uC(t,e,n){let r=this;return i;function i(c){return t.enter("codeIndented"),$(t,o,"linePrefix",5)(c)}function o(c){let u=r.events[r.events.length-1];return u&&u[1].type==="linePrefix"&&u[2].sliceSerialize(u[1],!0).length>=4?s(c):n(c)}function s(c){return c===null?l(c):D(c)?t.attempt(cC,s,l)(c):(t.enter("codeFlowValue"),a(c))}function a(c){return c===null||D(c)?(t.exit("codeFlowValue"),s(c)):(t.consume(c),a)}function l(c){return t.exit("codeIndented"),e(c)}}function fC(t,e,n){let r=this;return i;function i(s){return r.parser.lazy[r.now().line]?n(s):D(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),i):$(t,o,"linePrefix",5)(s)}function o(s){let a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(s):D(s)?i(s):n(s)}}var Vl={name:"codeText",previous:pC,resolve:dC,tokenize:hC};function dC(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(e,n,r){let i=n||0;this.setCursor(Math.trunc(e));let o=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&lo(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),lo(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),lo(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?e(s):t.interrupt(r.parser.constructs.flow,n,e)(s)}}function _s(t,e,n,r,i,o,s,a,l){let c=l||Number.POSITIVE_INFINITY,u=0;return f;function f(y){return y===60?(t.enter(r),t.enter(i),t.enter(o),t.consume(y),t.exit(o),d):y===null||y===32||y===41||er(y)?n(y):(t.enter(r),t.enter(s),t.enter(a),t.enter("chunkString",{contentType:"string"}),m(y))}function d(y){return y===62?(t.enter(o),t.consume(y),t.exit(o),t.exit(i),t.exit(r),e):(t.enter(a),t.enter("chunkString",{contentType:"string"}),p(y))}function p(y){return y===62?(t.exit("chunkString"),t.exit(a),d(y)):y===null||y===60||D(y)?n(y):(t.consume(y),y===92?h:p)}function h(y){return y===60||y===62||y===92?(t.consume(y),p):p(y)}function m(y){return!u&&(y===null||y===41||Z(y))?(t.exit("chunkString"),t.exit(a),t.exit(s),t.exit(r),e(y)):u999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in s.parser.constructs?n(p):p===93?(t.exit(o),t.enter(i),t.consume(p),t.exit(i),t.exit(r),e):D(p)?(t.enter("lineEnding"),t.consume(p),t.exit("lineEnding"),u):(t.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||D(p)||a++>999?(t.exit("chunkString"),u(p)):(t.consume(p),l||(l=!j(p)),p===92?d:f)}function d(p){return p===91||p===92||p===93?(t.consume(p),a++,f):f(p)}}function Ws(t,e,n,r,i,o){let s;return a;function a(d){return d===34||d===39||d===40?(t.enter(r),t.enter(i),t.consume(d),t.exit(i),s=d===40?41:d,l):n(d)}function l(d){return d===s?(t.enter(i),t.consume(d),t.exit(i),t.exit(r),e):(t.enter(o),c(d))}function c(d){return d===s?(t.exit(o),l(s)):d===null?n(d):D(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),$(t,c,"linePrefix")):(t.enter("chunkString",{contentType:"string"}),u(d))}function u(d){return d===s||d===null||D(d)?(t.exit("chunkString"),c(d)):(t.consume(d),d===92?f:u)}function f(d){return d===s||d===92?(t.consume(d),u):u(d)}}function nr(t,e){let n;return r;function r(i){return D(i)?(t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),n=!0,r):j(i)?$(t,r,n?"linePrefix":"lineSuffix")(i):e(i)}}var Kl={name:"definition",tokenize:wC},xC={partial:!0,tokenize:CC};function wC(t,e,n){let r=this,i;return o;function o(p){return t.enter("definition"),s(p)}function s(p){return Hs.call(r,t,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Ve(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(t.enter("definitionMarker"),t.consume(p),t.exit("definitionMarker"),l):n(p)}function l(p){return Z(p)?nr(t,c)(p):c(p)}function c(p){return _s(t,u,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function u(p){return t.attempt(xC,f,f)(p)}function f(p){return j(p)?$(t,d,"whitespace")(p):d(p)}function d(p){return p===null||D(p)?(t.exit("definition"),r.parser.defined.push(i),e(p)):n(p)}}function CC(t,e,n){return r;function r(a){return Z(a)?nr(t,i)(a):n(a)}function i(a){return Ws(t,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function o(a){return j(a)?$(t,s,"whitespace")(a):s(a)}function s(a){return a===null||D(a)?e(a):n(a)}}var Ul={name:"hardBreakEscape",tokenize:SC};function SC(t,e,n){return r;function r(o){return t.enter("hardBreakEscape"),t.consume(o),i}function i(o){return D(o)?(t.exit("hardBreakEscape"),e(o)):n(o)}}var Jl={name:"headingAtx",resolve:MC,tokenize:EC};function MC(t,e){let n=t.length-2,r=3,i,o;return t[r][1].type==="whitespace"&&(r+=2),n-2>r&&t[n][1].type==="whitespace"&&(n-=2),t[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&t[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:t[r][1].start,end:t[n][1].end},o={type:"chunkText",start:t[r][1].start,end:t[n][1].end,contentType:"text"},ke(t,r,n-r+1,[["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e]])),t}function EC(t,e,n){let r=0;return i;function i(u){return t.enter("atxHeading"),o(u)}function o(u){return t.enter("atxHeadingSequence"),s(u)}function s(u){return u===35&&r++<6?(t.consume(u),s):u===null||Z(u)?(t.exit("atxHeadingSequence"),a(u)):n(u)}function a(u){return u===35?(t.enter("atxHeadingSequence"),l(u)):u===null||D(u)?(t.exit("atxHeading"),e(u)):j(u)?$(t,a,"whitespace")(u):(t.enter("atxHeadingText"),c(u))}function l(u){return u===35?(t.consume(u),l):(t.exit("atxHeadingSequence"),a(u))}function c(u){return u===null||u===35||Z(u)?(t.exit("atxHeadingText"),a(u)):(t.consume(u),c)}}var Sh=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Gl=["pre","script","style","textarea"];var Xl={concrete:!0,name:"htmlFlow",resolveTo:AC,tokenize:IC},TC={partial:!0,tokenize:RC},vC={partial:!0,tokenize:NC};function AC(t){let e=t.length;for(;e--&&!(t[e][0]==="enter"&&t[e][1].type==="htmlFlow"););return e>1&&t[e-2][1].type==="linePrefix"&&(t[e][1].start=t[e-2][1].start,t[e+1][1].start=t[e-2][1].start,t.splice(e-2,2)),t}function IC(t,e,n){let r=this,i,o,s,a,l;return c;function c(b){return u(b)}function u(b){return t.enter("htmlFlow"),t.enter("htmlFlowData"),t.consume(b),f}function f(b){return b===33?(t.consume(b),d):b===47?(t.consume(b),o=!0,m):b===63?(t.consume(b),i=3,r.interrupt?e:k):Ee(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function d(b){return b===45?(t.consume(b),i=2,p):b===91?(t.consume(b),i=5,a=0,h):Ee(b)?(t.consume(b),i=4,r.interrupt?e:k):n(b)}function p(b){return b===45?(t.consume(b),r.interrupt?e:k):n(b)}function h(b){let at="CDATA[";return b===at.charCodeAt(a++)?(t.consume(b),a===at.length?r.interrupt?e:te:h):n(b)}function m(b){return Ee(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function g(b){if(b===null||b===47||b===62||Z(b)){let at=b===47,Xn=s.toLowerCase();return!at&&!o&&Gl.includes(Xn)?(i=1,r.interrupt?e(b):te(b)):Sh.includes(s.toLowerCase())?(i=6,at?(t.consume(b),y):r.interrupt?e(b):te(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):o?x(b):C(b))}return b===45||Te(b)?(t.consume(b),s+=String.fromCharCode(b),g):n(b)}function y(b){return b===62?(t.consume(b),r.interrupt?e:te):n(b)}function x(b){return j(b)?(t.consume(b),x):S(b)}function C(b){return b===47?(t.consume(b),S):b===58||b===95||Ee(b)?(t.consume(b),v):j(b)?(t.consume(b),C):S(b)}function v(b){return b===45||b===46||b===58||b===95||Te(b)?(t.consume(b),v):A(b)}function A(b){return b===61?(t.consume(b),w):j(b)?(t.consume(b),A):C(b)}function w(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(t.consume(b),l=b,N):j(b)?(t.consume(b),w):B(b)}function N(b){return b===l?(t.consume(b),l=null,O):b===null||D(b)?n(b):(t.consume(b),N)}function B(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Z(b)?A(b):(t.consume(b),B)}function O(b){return b===47||b===62||j(b)?C(b):n(b)}function S(b){return b===62?(t.consume(b),me):n(b)}function me(b){return b===null||D(b)?te(b):j(b)?(t.consume(b),me):n(b)}function te(b){return b===45&&i===2?(t.consume(b),ae):b===60&&i===1?(t.consume(b),fe):b===62&&i===4?(t.consume(b),kt):b===63&&i===3?(t.consume(b),k):b===93&&i===5?(t.consume(b),Me):D(b)&&(i===6||i===7)?(t.exit("htmlFlowData"),t.check(TC,Zt,F)(b)):b===null||D(b)?(t.exit("htmlFlowData"),F(b)):(t.consume(b),te)}function F(b){return t.check(vC,W,Zt)(b)}function W(b){return t.enter("lineEnding"),t.consume(b),t.exit("lineEnding"),V}function V(b){return b===null||D(b)?F(b):(t.enter("htmlFlowData"),te(b))}function ae(b){return b===45?(t.consume(b),k):te(b)}function fe(b){return b===47?(t.consume(b),s="",ye):te(b)}function ye(b){if(b===62){let at=s.toLowerCase();return Gl.includes(at)?(t.consume(b),kt):te(b)}return Ee(b)&&s.length<8?(t.consume(b),s+=String.fromCharCode(b),ye):te(b)}function Me(b){return b===93?(t.consume(b),k):te(b)}function k(b){return b===62?(t.consume(b),kt):b===45&&i===2?(t.consume(b),k):te(b)}function kt(b){return b===null||D(b)?(t.exit("htmlFlowData"),Zt(b)):(t.consume(b),kt)}function Zt(b){return t.exit("htmlFlow"),e(b)}}function NC(t,e,n){let r=this;return i;function i(s){return D(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o):n(s)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function RC(t,e,n){return r;function r(i){return t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),t.attempt(Wt,e,n)}}var Yl={name:"htmlText",tokenize:OC};function OC(t,e,n){let r=this,i,o,s;return a;function a(k){return t.enter("htmlText"),t.enter("htmlTextData"),t.consume(k),l}function l(k){return k===33?(t.consume(k),c):k===47?(t.consume(k),A):k===63?(t.consume(k),C):Ee(k)?(t.consume(k),B):n(k)}function c(k){return k===45?(t.consume(k),u):k===91?(t.consume(k),o=0,h):Ee(k)?(t.consume(k),x):n(k)}function u(k){return k===45?(t.consume(k),p):n(k)}function f(k){return k===null?n(k):k===45?(t.consume(k),d):D(k)?(s=f,fe(k)):(t.consume(k),f)}function d(k){return k===45?(t.consume(k),p):f(k)}function p(k){return k===62?ae(k):k===45?d(k):f(k)}function h(k){let kt="CDATA[";return k===kt.charCodeAt(o++)?(t.consume(k),o===kt.length?m:h):n(k)}function m(k){return k===null?n(k):k===93?(t.consume(k),g):D(k)?(s=m,fe(k)):(t.consume(k),m)}function g(k){return k===93?(t.consume(k),y):m(k)}function y(k){return k===62?ae(k):k===93?(t.consume(k),y):m(k)}function x(k){return k===null||k===62?ae(k):D(k)?(s=x,fe(k)):(t.consume(k),x)}function C(k){return k===null?n(k):k===63?(t.consume(k),v):D(k)?(s=C,fe(k)):(t.consume(k),C)}function v(k){return k===62?ae(k):C(k)}function A(k){return Ee(k)?(t.consume(k),w):n(k)}function w(k){return k===45||Te(k)?(t.consume(k),w):N(k)}function N(k){return D(k)?(s=N,fe(k)):j(k)?(t.consume(k),N):ae(k)}function B(k){return k===45||Te(k)?(t.consume(k),B):k===47||k===62||Z(k)?O(k):n(k)}function O(k){return k===47?(t.consume(k),ae):k===58||k===95||Ee(k)?(t.consume(k),S):D(k)?(s=O,fe(k)):j(k)?(t.consume(k),O):ae(k)}function S(k){return k===45||k===46||k===58||k===95||Te(k)?(t.consume(k),S):me(k)}function me(k){return k===61?(t.consume(k),te):D(k)?(s=me,fe(k)):j(k)?(t.consume(k),me):O(k)}function te(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(t.consume(k),i=k,F):D(k)?(s=te,fe(k)):j(k)?(t.consume(k),te):(t.consume(k),W)}function F(k){return k===i?(t.consume(k),i=void 0,V):k===null?n(k):D(k)?(s=F,fe(k)):(t.consume(k),F)}function W(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||Z(k)?O(k):(t.consume(k),W)}function V(k){return k===47||k===62||Z(k)?O(k):n(k)}function ae(k){return k===62?(t.consume(k),t.exit("htmlTextData"),t.exit("htmlText"),e):n(k)}function fe(k){return t.exit("htmlTextData"),t.enter("lineEnding"),t.consume(k),t.exit("lineEnding"),ye}function ye(k){return j(k)?$(t,Me,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):Me(k)}function Me(k){return t.enter("htmlTextData"),s(k)}}var rr={name:"labelEnd",resolveAll:PC,resolveTo:FC,tokenize:zC},DC={tokenize:$C},LC={tokenize:_C},BC={tokenize:HC};function PC(t){let e=-1,n=[];for(;++e=3&&(c===null||D(c))?(t.exit("thematicBreak"),e(c)):n(c)}function l(c){return c===i?(t.consume(c),r++,l):(t.exit("thematicBreakSequence"),j(c)?$(t,a,"whitespace")(c):a(c))}}var qe={continuation:{tokenize:GC},exit:YC,name:"list",tokenize:JC},KC={partial:!0,tokenize:QC},UC={partial:!0,tokenize:XC};function JC(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(p){let h=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(h==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:oo(p)){if(r.containerState.type||(r.containerState.type=h,t.enter(h,{_container:!0})),h==="listUnordered")return t.enter("listItemPrefix"),p===42||p===45?t.check(ir,n,c)(p):c(p);if(!r.interrupt||p===49)return t.enter("listItemPrefix"),t.enter("listItemValue"),l(p)}return n(p)}function l(p){return oo(p)&&++s<10?(t.consume(p),l):(!r.interrupt||s<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(t.exit("listItemValue"),c(p)):n(p)}function c(p){return t.enter("listItemMarker"),t.consume(p),t.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,t.check(Wt,r.interrupt?n:u,t.attempt(KC,d,f))}function u(p){return r.containerState.initialBlankLine=!0,o++,d(p)}function f(p){return j(p)?(t.enter("listItemPrefixWhitespace"),t.consume(p),t.exit("listItemPrefixWhitespace"),d):n(p)}function d(p){return r.containerState.size=o+r.sliceSerialize(t.exit("listItemPrefix"),!0).length,e(p)}}function GC(t,e,n){let r=this;return r.containerState._closeFlow=void 0,t.check(Wt,i,o);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,$(t,e,"listItemIndent",r.containerState.size+1)(a)}function o(a){return r.containerState.furtherBlankLines||!j(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,t.attempt(UC,e,s)(a))}function s(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,$(t,t.attempt(qe,e,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function XC(t,e,n){let r=this;return $(t,i,"listItemIndent",r.containerState.size+1);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===r.containerState.size?e(o):n(o)}}function YC(t){t.exit(this.containerState.type)}function QC(t,e,n){let r=this;return $(t,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(o){let s=r.events[r.events.length-1];return!j(o)&&s&&s[1].type==="listItemPrefixWhitespace"?e(o):n(o)}}var js={name:"setextUnderline",resolveTo:ZC,tokenize:eS};function ZC(t,e){let n=t.length,r,i,o;for(;n--;)if(t[n][0]==="enter"){if(t[n][1].type==="content"){r=n;break}t[n][1].type==="paragraph"&&(i=n)}else t[n][1].type==="content"&&t.splice(n,1),!o&&t[n][1].type==="definition"&&(o=n);let s={type:"setextHeading",start:{...t[r][1].start},end:{...t[t.length-1][1].end}};return t[i][1].type="setextHeadingText",o?(t.splice(i,0,["enter",s,e]),t.splice(o+1,0,["exit",t[r][1],e]),t[r][1].end={...t[o][1].end}):t[r][1]=s,t.push(["exit",s,e]),t}function eS(t,e,n){let r=this,i;return o;function o(c){let u=r.events.length,f;for(;u--;)if(r.events[u][1].type!=="lineEnding"&&r.events[u][1].type!=="linePrefix"&&r.events[u][1].type!=="content"){f=r.events[u][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(t.enter("setextHeadingLine"),i=c,s(c)):n(c)}function s(c){return t.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===i?(t.consume(c),a):(t.exit("setextHeadingLineSequence"),j(c)?$(t,l,"lineSuffix")(c):l(c))}function l(c){return c===null||D(c)?(t.exit("setextHeadingLine"),e(c)):n(c)}}var Mh={tokenize:tS};function tS(t){let e=this,n=t.attempt(Wt,r,t.attempt(this.parser.constructs.flowInitial,i,$(t,t.attempt(this.parser.constructs.flow,i,t.attempt(ql,i)),"linePrefix")));return n;function r(o){if(o===null){t.consume(o);return}return t.enter("lineEndingBlank"),t.consume(o),t.exit("lineEndingBlank"),e.currentConstruct=void 0,n}function i(o){if(o===null){t.consume(o);return}return t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),e.currentConstruct=void 0,n}}var Eh={resolveAll:Ih()},Th=Ah("string"),vh=Ah("text");function Ah(t){return{resolveAll:Ih(t==="text"?nS:void 0),tokenize:e};function e(n){let r=this,i=this.parser.constructs[t],o=n.attempt(i,s,a);return s;function s(u){return c(u)?o(u):a(u)}function a(u){if(u===null){n.consume(u);return}return n.enter("data"),n.consume(u),l}function l(u){return c(u)?(n.exit("data"),o(u)):(n.consume(u),l)}function c(u){if(u===null)return!0;let f=i[u],d=-1;if(f)for(;++duS,contentInitial:()=>iS,disable:()=>fS,document:()=>rS,flow:()=>sS,flowInitial:()=>oS,insideSpan:()=>cS,string:()=>aS,text:()=>lS});var rS={42:qe,43:qe,45:qe,48:qe,49:qe,50:qe,51:qe,52:qe,53:qe,54:qe,55:qe,56:qe,57:qe,62:Ls},iS={91:Kl},oS={[-2]:ao,[-1]:ao,32:ao},sS={35:Jl,42:ir,45:[js,ir],60:Xl,61:js,95:ir,96:Fs,126:Fs},aS={38:Ps,92:Bs},lS={[-5]:co,[-4]:co,[-3]:co,33:Ql,38:Ps,42:so,60:[jl,Yl],91:Zl,92:[Ul,Bs],93:rr,95:so,96:Vl},cS={null:[so,Eh]},uS={null:[42,95]},fS={null:[]};function Nh(t,e,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},o=[],s=[],a=[],l=!0,c={attempt:O(N),check:O(B),consume:v,enter:A,exit:w,interrupt:O(B,{interrupt:!0})},u={code:null,containerState:{},defineSkip:y,events:[],now:g,parser:t,previous:null,sliceSerialize:h,sliceStream:m,write:p},f=e.tokenize.call(u,c),d;return e.resolveAll&&o.push(e),u;function p(F){return s=Ge(s,F),x(),s[s.length-1]!==null?[]:(S(e,0),u.events=vn(o,u.events,u),u.events)}function h(F,W){return pS(m(F),W)}function m(F){return dS(s,F)}function g(){let{_bufferIndex:F,_index:W,line:V,column:ae,offset:fe}=r;return{_bufferIndex:F,_index:W,line:V,column:ae,offset:fe}}function y(F){i[F.line]=F.column,te()}function x(){let F;for(;r._index-1){let a=s[0];typeof a=="string"?s[0]=a.slice(r):s.shift()}o>0&&s.push(t[i].slice(0,o))}return s}function pS(t,e){let n=-1,r=[],i;for(;++n0){let It=J.tokenStack[J.tokenStack.length-1];(It[1]||Dh).call(J,void 0,It[0])}for(L.position={start:In(T.length>0?T[0][1].start:{line:1,column:1,offset:0}),end:In(T.length>0?T[T.length-2][1].end:{line:1,column:1,offset:0})},de=-1;++de "),o.shift(2);let s=n.indentLines(n.containerFlow(t,o.current()),bS);return i(),s}function bS(t,e,n){return">"+(n?"":" ")+t}function qs(t,e){return _h(t,e.inConstruct,!0)&&!_h(t,e.notInConstruct,!1)}function _h(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++r0){let It=J.tokenStack[J.tokenStack.length-1];(It[1]||Lh).call(J,void 0,It[0])}for(L.position={start:In(T.length>0?T[0][1].start:{line:1,column:1,offset:0}),end:In(T.length>0?T[T.length-2][1].end:{line:1,column:1,offset:0})},de=-1;++de "),o.shift(2);let s=n.indentLines(n.containerFlow(t,o.current()),xS);return i(),s}function xS(t,e,n){return">"+(n?"":" ")+t}function qs(t,e){return Hh(t,e.inConstruct,!0)&&!Hh(t,e.notInConstruct,!1)}function Hh(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++rs&&(s=o):o=1,i=r+e.length,r=n.indexOf(e,i);return s}function uo(t,e){return!!(e.options.fences===!1&&t.value&&!t.lang&&/[^ \r\n]/.test(t.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(t.value))}function Hh(t){let e=t.options.fence||"`";if(e!=="`"&&e!=="~")throw new Error("Cannot serialize code with `"+e+"` for `options.fence`, expected `` ` `` or `~`");return e}function Wh(t,e,n,r){let i=Hh(n),o=t.value||"",s=i==="`"?"GraveAccent":"Tilde";if(uo(t,n)){let f=n.enter("codeIndented"),d=n.indentLines(o,xS);return f(),d}let a=n.createTracker(r),l=i.repeat(Math.max(Ks(o,i)+1,3)),c=n.enter("codeFenced"),u=a.move(l);if(t.lang){let f=n.enter(`codeFencedLang${s}`);u+=a.move(n.safe(t.lang,{before:u,after:" ",encode:["`"],...a.current()})),f()}if(t.lang&&t.meta){let f=n.enter(`codeFencedMeta${s}`);u+=a.move(" "),u+=a.move(n.safe(t.meta,{before:u,after:` +`}function Ks(t,e){let n=String(t),r=n.indexOf(e),i=r,o=0,s=0;if(typeof e!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++o>s&&(s=o):o=1,i=r+e.length,r=n.indexOf(e,i);return s}function uo(t,e){return!!(e.options.fences===!1&&t.value&&!t.lang&&/[^ \r\n]/.test(t.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(t.value))}function Wh(t){let e=t.options.fence||"`";if(e!=="`"&&e!=="~")throw new Error("Cannot serialize code with `"+e+"` for `options.fence`, expected `` ` `` or `~`");return e}function jh(t,e,n,r){let i=Wh(n),o=t.value||"",s=i==="`"?"GraveAccent":"Tilde";if(uo(t,n)){let f=n.enter("codeIndented"),d=n.indentLines(o,wS);return f(),d}let a=n.createTracker(r),l=i.repeat(Math.max(Ks(o,i)+1,3)),c=n.enter("codeFenced"),u=a.move(l);if(t.lang){let f=n.enter(`codeFencedLang${s}`);u+=a.move(n.safe(t.lang,{before:u,after:" ",encode:["`"],...a.current()})),f()}if(t.lang&&t.meta){let f=n.enter(`codeFencedMeta${s}`);u+=a.move(" "),u+=a.move(n.safe(t.meta,{before:u,after:` `,encode:["`"],...a.current()})),f()}return u+=a.move(` `),o&&(u+=a.move(o+` -`)),u+=a.move(l),c(),u}function xS(t,e,n){return(n?"":" ")+t}function ti(t){let e=t.options.quote||'"';if(e!=='"'&&e!=="'")throw new Error("Cannot serialize title with `"+e+"` for `options.quote`, expected `\"`, or `'`");return e}function jh(t,e,n,r){let i=ti(n),o=i==='"'?"Quote":"Apostrophe",s=n.enter("definition"),a=n.enter("label"),l=n.createTracker(r),c=l.move("[");return c+=l.move(n.safe(n.associationId(t),{before:c,after:"]",...l.current()})),c+=l.move("]: "),a(),!t.url||/[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":` -`,...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),s(),c}function Vh(t){let e=t.options.emphasis||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize emphasis with `"+e+"` for `options.emphasis`, expected `*`, or `_`");return e}function dt(t){return"&#x"+t.toString(16).toUpperCase()+";"}function ni(t,e,n){let r=rn(t),i=rn(e);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}lc.peek=wS;function lc(t,e,n,r){let i=Vh(n),o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=ni(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=dt(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=ni(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+dt(f));let p=s.move(i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function wS(t,e,n){return n.options.emphasis||"*"}var Nn=(function(t){if(t==null)return ES;if(typeof t=="function")return Us(t);if(typeof t=="object")return Array.isArray(t)?CS(t):SS(t);if(typeof t=="string")return MS(t);throw new Error("Expected function, string, or object as test")});function CS(t){let e=[],n=-1;for(;++n":""))+")"})}return d;function d(){let p=qh,h,m,g;if((!e||o(l,c,u[u.length-1]||void 0))&&(p=vS(n(l,u)),p[0]===or))return p;if("children"in l&&l.children){let y=l;if(y.children&&p[0]!==sr)for(m=(r?y.children.length:-1)+s,g=u.concat(y);m>-1&&m",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":` +`,...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),s(),c}function qh(t){let e=t.options.emphasis||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize emphasis with `"+e+"` for `options.emphasis`, expected `*`, or `_`");return e}function dt(t){return"&#x"+t.toString(16).toUpperCase()+";"}function ni(t,e,n){let r=rn(t),i=rn(e);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}lc.peek=CS;function lc(t,e,n,r){let i=qh(n),o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=ni(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=dt(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=ni(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+dt(f));let p=s.move(i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function CS(t,e,n){return n.options.emphasis||"*"}var Nn=(function(t){if(t==null)return TS;if(typeof t=="function")return Us(t);if(typeof t=="object")return Array.isArray(t)?SS(t):MS(t);if(typeof t=="string")return ES(t);throw new Error("Expected function, string, or object as test")});function SS(t){let e=[],n=-1;for(;++n":""))+")"})}return d;function d(){let p=Kh,h,m,g;if((!e||o(l,c,u[u.length-1]||void 0))&&(p=AS(n(l,u)),p[0]===or))return p;if("children"in l&&l.children){let y=l;if(y.children&&p[0]!==sr)for(m=(r?y.children.length:-1)+s,g=u.concat(y);m>-1&&m",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":")",...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),c+=l.move(")"),s(),c}function IS(){return"!"}fc.peek=NS;function fc(t,e,n,r){let i=t.referenceType,o=n.enter("imageReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("!["),c=n.safe(t.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function NS(){return"!"}dc.peek=RS;function dc(t,e,n){let r=t.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++o\u007F]/.test(t.url))}hc.peek=OS;function hc(t,e,n,r){let i=ti(n),o=i==='"'?"Quote":"Apostrophe",s=n.createTracker(r),a,l;if(pc(t,n)){let u=n.stack;n.stack=[],a=n.enter("autolink");let f=s.move("<");return f+=s.move(n.containerPhrasing(t,{before:f,after:">",...s.current()})),f+=s.move(">"),a(),n.stack=u,f}a=n.enter("link"),l=n.enter("label");let c=s.move("[");return c+=s.move(n.containerPhrasing(t,{before:c,after:"](",...s.current()})),c+=s.move("]("),l(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(l=n.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(n.safe(t.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=n.enter("destinationRaw"),c+=s.move(n.safe(t.url,{before:c,after:t.title?" ":")",...s.current()}))),l(),t.title&&(l=n.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(n.safe(t.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),c+=s.move(")"),a(),c}function OS(t,e,n){return pc(t,n)?"<":"["}mc.peek=DS;function mc(t,e,n,r){let i=t.referenceType,o=n.enter("linkReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("["),c=n.containerPhrasing(t,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function DS(){return"["}function ri(t){let e=t.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function Uh(t){let e=ri(t),n=t.options.bulletOther;if(!n)return e==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Jh(t){let e=t.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function Xs(t){let e=t.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function Gh(t,e,n,r){let i=n.enter("list"),o=n.bulletCurrent,s=t.ordered?Jh(n):ri(n),a=t.ordered?s==="."?")":".":Uh(n),l=e&&n.bulletLastUsed?s===n.bulletLastUsed:!1;if(!t.ordered){let u=t.children?t.children[0]:void 0;if((s==="*"||s==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),Xs(n)===s&&u){let f=-1;for(;++f-1?e.start:1)+(n.options.incrementListMarker===!1?0:e.children.indexOf(t))+o);let s=o.length+1;(i==="tab"||i==="mixed"&&(e&&e.type==="list"&&e.spread||t.spread))&&(s=Math.ceil(s/4)*4);let a=n.createTracker(r);a.move(o+" ".repeat(s-o.length)),a.shift(s);let l=n.enter("listItem"),c=n.indentLines(n.containerFlow(t,a.current()),u);return l(),c;function u(f,d,p){return d?(p?"":" ".repeat(s))+f:(p?o:o+" ".repeat(s-o.length))+f}}function Qh(t,e,n,r){let i=n.enter("paragraph"),o=n.enter("phrasing"),s=n.containerPhrasing(t,r);return o(),i(),s}var gc=Nn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function Zh(t,e,n,r){return(t.children.some(function(s){return gc(s)})?n.containerPhrasing:n.containerFlow).call(n,t,r)}function em(t){let e=t.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}yc.peek=LS;function yc(t,e,n,r){let i=em(n),o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=ni(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=dt(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=ni(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+dt(f));let p=s.move(i+i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function LS(t,e,n){return n.options.strong||"*"}function tm(t,e,n,r){return n.safe(t.value,r)}function nm(t){let e=t.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function rm(t,e,n){let r=(Xs(n)+(n.options.ruleSpaces?" ":"")).repeat(nm(n));return n.options.ruleSpaces?r.slice(0,-1):r}var lr={blockquote:$h,break:ac,code:Wh,definition:jh,emphasis:lc,hardBreak:ac,heading:Kh,html:cc,image:uc,imageReference:fc,inlineCode:dc,link:hc,linkReference:mc,list:Gh,listItem:Yh,paragraph:Qh,root:Zh,strong:yc,text:tm,thematicBreak:rm};var im=[BS];function BS(t,e,n,r){if(e.type==="code"&&uo(e,r)&&(t.type==="list"||t.type===e.type&&uo(t,r)))return!1;if("spread"in n&&typeof n.spread=="boolean")return t.type==="paragraph"&&(t.type===e.type||e.type==="definition"||e.type==="heading"&&Gs(e,r))?void 0:n.spread?1:0}var cr=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],om=[{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:` +`,...o.current()});return/^[\t ]/.test(c)&&(c=dt(c.charCodeAt(0))+c.slice(1)),c=c?s+" "+c:s,n.options.closeAtx&&(c+=" "+s),l(),a(),c}cc.peek=IS;function cc(t){return t.value||""}function IS(){return"<"}uc.peek=NS;function uc(t,e,n,r){let i=ti(n),o=i==='"'?"Quote":"Apostrophe",s=n.enter("image"),a=n.enter("label"),l=n.createTracker(r),c=l.move("![");return c+=l.move(n.safe(t.alt,{before:c,after:"]",...l.current()})),c+=l.move("]("),a(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":")",...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),c+=l.move(")"),s(),c}function NS(){return"!"}fc.peek=RS;function fc(t,e,n,r){let i=t.referenceType,o=n.enter("imageReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("!["),c=n.safe(t.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function RS(){return"!"}dc.peek=OS;function dc(t,e,n){let r=t.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++o\u007F]/.test(t.url))}hc.peek=DS;function hc(t,e,n,r){let i=ti(n),o=i==='"'?"Quote":"Apostrophe",s=n.createTracker(r),a,l;if(pc(t,n)){let u=n.stack;n.stack=[],a=n.enter("autolink");let f=s.move("<");return f+=s.move(n.containerPhrasing(t,{before:f,after:">",...s.current()})),f+=s.move(">"),a(),n.stack=u,f}a=n.enter("link"),l=n.enter("label");let c=s.move("[");return c+=s.move(n.containerPhrasing(t,{before:c,after:"](",...s.current()})),c+=s.move("]("),l(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(l=n.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(n.safe(t.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=n.enter("destinationRaw"),c+=s.move(n.safe(t.url,{before:c,after:t.title?" ":")",...s.current()}))),l(),t.title&&(l=n.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(n.safe(t.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),c+=s.move(")"),a(),c}function DS(t,e,n){return pc(t,n)?"<":"["}mc.peek=LS;function mc(t,e,n,r){let i=t.referenceType,o=n.enter("linkReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("["),c=n.containerPhrasing(t,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function LS(){return"["}function ri(t){let e=t.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function Jh(t){let e=ri(t),n=t.options.bulletOther;if(!n)return e==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Gh(t){let e=t.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function Xs(t){let e=t.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function Xh(t,e,n,r){let i=n.enter("list"),o=n.bulletCurrent,s=t.ordered?Gh(n):ri(n),a=t.ordered?s==="."?")":".":Jh(n),l=e&&n.bulletLastUsed?s===n.bulletLastUsed:!1;if(!t.ordered){let u=t.children?t.children[0]:void 0;if((s==="*"||s==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),Xs(n)===s&&u){let f=-1;for(;++f-1?e.start:1)+(n.options.incrementListMarker===!1?0:e.children.indexOf(t))+o);let s=o.length+1;(i==="tab"||i==="mixed"&&(e&&e.type==="list"&&e.spread||t.spread))&&(s=Math.ceil(s/4)*4);let a=n.createTracker(r);a.move(o+" ".repeat(s-o.length)),a.shift(s);let l=n.enter("listItem"),c=n.indentLines(n.containerFlow(t,a.current()),u);return l(),c;function u(f,d,p){return d?(p?"":" ".repeat(s))+f:(p?o:o+" ".repeat(s-o.length))+f}}function Zh(t,e,n,r){let i=n.enter("paragraph"),o=n.enter("phrasing"),s=n.containerPhrasing(t,r);return o(),i(),s}var gc=Nn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function em(t,e,n,r){return(t.children.some(function(s){return gc(s)})?n.containerPhrasing:n.containerFlow).call(n,t,r)}function tm(t){let e=t.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}yc.peek=BS;function yc(t,e,n,r){let i=tm(n),o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=ni(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=dt(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=ni(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+dt(f));let p=s.move(i+i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function BS(t,e,n){return n.options.strong||"*"}function nm(t,e,n,r){return n.safe(t.value,r)}function rm(t){let e=t.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function im(t,e,n){let r=(Xs(n)+(n.options.ruleSpaces?" ":"")).repeat(rm(n));return n.options.ruleSpaces?r.slice(0,-1):r}var lr={blockquote:_h,break:ac,code:jh,definition:Vh,emphasis:lc,hardBreak:ac,heading:Uh,html:cc,image:uc,imageReference:fc,inlineCode:dc,link:hc,linkReference:mc,list:Xh,listItem:Qh,paragraph:Zh,root:em,strong:yc,text:nm,thematicBreak:im};var om=[PS];function PS(t,e,n,r){if(e.type==="code"&&uo(e,r)&&(t.type==="list"||t.type===e.type&&uo(t,r)))return!1;if("spread"in n&&typeof n.spread=="boolean")return t.type==="paragraph"&&(t.type===e.type||e.type==="definition"||e.type==="heading"&&Gs(e,r))?void 0:n.spread?1:0}var cr=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],sm=[{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:` `,inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"!",after:"\\[",inConstruct:"phrasing",notInConstruct:cr},{character:'"',inConstruct:"titleQuote"},{atBreak:!0,character:"#"},{character:"#",inConstruct:"headingAtx",after:`(?:[\r ]|$)`},{character:"&",after:"[#A-Za-z]",inConstruct:"phrasing"},{character:"'",inConstruct:"titleApostrophe"},{character:"(",inConstruct:"destinationRaw"},{before:"\\]",character:"(",inConstruct:"phrasing",notInConstruct:cr},{atBreak:!0,before:"\\d+",character:")"},{character:")",inConstruct:"destinationRaw"},{atBreak:!0,character:"*",after:`(?:[ \r *])`},{character:"*",inConstruct:"phrasing",notInConstruct:cr},{atBreak:!0,character:"+",after:`(?:[ \r ])`},{atBreak:!0,character:"-",after:`(?:[ \r -])`},{atBreak:!0,before:"\\d+",character:".",after:`(?:[ \r -]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:cr},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:cr},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:cr},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:cr},{atBreak:!0,character:"~"}];function sm(t){return t.label||!t.identifier?t.label||"":Vs(t.identifier)}function am(t){if(!t._compiled){let e=(t.atBreak?"[\\r\\n][\\t ]*":"")+(t.before?"(?:"+t.before+")":"");t._compiled=new RegExp((e?"("+e+")":"")+(/[|\\{}()[\]^$+*?.-]/.test(t.character)?"\\":"")+t.character+(t.after?"(?:"+t.after+")":""),"g")}return t._compiled}function lm(t,e,n){let r=e.indexStack,i=t.children||[],o=[],s=-1,a=n.before,l;r.push(-1);let c=e.createTracker(n);for(;++s0&&(a==="\r"||a===` -`)&&u.type==="html"&&(o[o.length-1]=o[o.length-1].replace(/(\r?\n|\r)$/," "),a=" ",c=e.createTracker(n),c.move(o.join("")));let d=e.handle(u,t,e,{...c.current(),after:f,before:a});l&&l===d.slice(0,1)&&(d=dt(l.charCodeAt(0))+d.slice(1));let p=e.attentionEncodeSurroundingInfo;e.attentionEncodeSurroundingInfo=void 0,l=void 0,p&&(o.length>0&&p.before&&a===o[o.length-1].slice(-1)&&(o[o.length-1]=o[o.length-1].slice(0,-1)+dt(a.charCodeAt(0))),p.after&&(l=f)),c.move(d),o.push(d),a=d.slice(-1)}return r.pop(),o.join("")}function cm(t,e,n){let r=e.indexStack,i=t.children||[],o=e.createTracker(n),s=[],a=-1;for(r.push(-1);++a"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:cr},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:cr},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:cr},{atBreak:!0,character:"~"}];function am(t){return t.label||!t.identifier?t.label||"":Vs(t.identifier)}function lm(t){if(!t._compiled){let e=(t.atBreak?"[\\r\\n][\\t ]*":"")+(t.before?"(?:"+t.before+")":"");t._compiled=new RegExp((e?"("+e+")":"")+(/[|\\{}()[\]^$+*?.-]/.test(t.character)?"\\":"")+t.character+(t.after?"(?:"+t.after+")":""),"g")}return t._compiled}function cm(t,e,n){let r=e.indexStack,i=t.children||[],o=[],s=-1,a=n.before,l;r.push(-1);let c=e.createTracker(n);for(;++s0&&(a==="\r"||a===` +`)&&u.type==="html"&&(o[o.length-1]=o[o.length-1].replace(/(\r?\n|\r)$/," "),a=" ",c=e.createTracker(n),c.move(o.join("")));let d=e.handle(u,t,e,{...c.current(),after:f,before:a});l&&l===d.slice(0,1)&&(d=dt(l.charCodeAt(0))+d.slice(1));let p=e.attentionEncodeSurroundingInfo;e.attentionEncodeSurroundingInfo=void 0,l=void 0,p&&(o.length>0&&p.before&&a===o[o.length-1].slice(-1)&&(o[o.length-1]=o[o.length-1].slice(0,-1)+dt(a.charCodeAt(0))),p.after&&(l=f)),c.move(d),o.push(d),a=d.slice(-1)}return r.pop(),o.join("")}function um(t,e,n){let r=e.indexStack,i=t.children||[],o=e.createTracker(n),s=[],a=-1;for(r.push(-1);++a `}return` -`}var FS=/\r?\n|\r/g;function um(t,e){let n=[],r=0,i=0,o;for(;o=FS.exec(t);)s(t.slice(r,o.index)),n.push(o[0]),r=o.index+o[0].length,i++;return s(t.slice(r)),n.join("");function s(a){n.push(e(a,i,!a))}}function dm(t,e,n){let r=(n.before||"")+(e||"")+(n.after||""),i=[],o=[],s={},a=-1;for(;++a=c||u+1=c||u+1s.length,l;a&&s.push(i);try{l=t.apply(this,s)}catch(c){let u=c;if(a&&n)throw u;return i(u)}a||(l&&l.then&&typeof l.then=="function"?l.then(o,i):l instanceof Error?i(l):o(l))}function i(s,...a){n||(n=!0,e(s,...a))}function o(s){i(null,s)}}var Ae=class extends Error{constructor(e,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",o={},s=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let l=r.indexOf(":");l===-1?o.ruleId=r:(o.source=r.slice(0,l),o.ruleId=r.slice(l+1))}if(!o.place&&o.ancestors&&o.ancestors){let l=o.ancestors[o.ancestors.length-1];l&&(o.place=l.position)}let a=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=An(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};Ae.prototype.file="";Ae.prototype.name="";Ae.prototype.reason="";Ae.prototype.message="";Ae.prototype.stack="";Ae.prototype.column=void 0;Ae.prototype.line=void 0;Ae.prototype.ancestors=void 0;Ae.prototype.cause=void 0;Ae.prototype.fatal=void 0;Ae.prototype.place=void 0;Ae.prototype.ruleId=void 0;Ae.prototype.source=void 0;var Rt={basename:qS,dirname:KS,extname:US,join:JS,sep:"/"};function qS(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');po(t);let n=0,r=-1,i=t.length,o;if(e===void 0||e.length===0||e.length>t.length){for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":t.slice(n,r)}if(e===t)return"";let s=-1,a=e.length-1;for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else s<0&&(o=!0,s=i+1),a>-1&&(t.codePointAt(i)===e.codePointAt(a--)?a<0&&(r=i):(a=-1,r=s));return n===r?r=s:r<0&&(r=t.length),t.slice(n,r)}function KS(t){if(po(t),t.length===0)return".";let e=-1,n=t.length,r;for(;--n;)if(t.codePointAt(n)===47){if(r){e=n;break}}else r||(r=!0);return e<0?t.codePointAt(0)===47?"/":".":e===1&&t.codePointAt(0)===47?"//":t.slice(0,e)}function US(t){po(t);let e=t.length,n=-1,r=0,i=-1,o=0,s;for(;e--;){let a=t.codePointAt(e);if(a===47){if(s){r=e+1;break}continue}n<0&&(s=!0,n=e+1),a===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||n<0||o===0||o===1&&i===n-1&&i===r+1?"":t.slice(i,n)}function JS(...t){let e=-1,n;for(;++e0&&t.codePointAt(t.length-1)===47&&(n+="/"),e?"/"+n:n}function XS(t,e){let n="",r=0,i=-1,o=0,s=-1,a,l;for(;++s<=t.length;){if(s2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=s,o=0;continue}}else if(n.length>0){n="",r=0,i=s,o=0;continue}}e&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+t.slice(i+1,s):n=t.slice(i+1,s),r=s-i-1;i=s,o=0}else a===46&&o>-1?o++:o=-1}return n}function po(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}var Mm={cwd:YS};function YS(){return"/"}function oi(t){return!!(t!==null&&typeof t=="object"&&"href"in t&&t.href&&"protocol"in t&&t.protocol&&t.auth===void 0)}function Em(t){if(typeof t=="string")t=new URL(t);else if(!oi(t)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+t+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(t.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return QS(t)}function QS(t){if(t.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=t.pathname,n=-1;for(;++n0){let[p,...h]=u,m=r[d][1];fo(m)&&fo(p)&&(p=(0,Zs.default)(!0,m,p)),r[d]=[c,p,...h]}}}},mo=new vc().freeze();function Mc(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `parser`")}function Ec(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `compiler`")}function Tc(t,e){if(e)throw new Error("Cannot call `"+t+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Am(t){if(!fo(t)||typeof t.type!="string")throw new TypeError("Expected node, got `"+t+"`")}function Im(t,e,n){if(!n)throw new Error("`"+t+"` finished async. Use `"+e+"` instead")}function Qs(t){return tM(t)?t:new ho(t)}function tM(t){return!!(t&&typeof t=="object"&&"message"in t&&"messages"in t)}function nM(t){return typeof t=="string"||rM(t)}function rM(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}function Ke(t){this.content=t}Ke.prototype={constructor:Ke,find:function(t){for(var e=0;e>1}};Ke.from=function(t){if(t instanceof Ke)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ke(e)};var Ac=Ke;function $m(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){let s=i.text,a=o.text,l=0;for(;s[l]==a[l];l++)n++;return l&&l0&&d>0&&c[f-1]==u[d-1];)f--,d--,n--,r--;return f&&d&&f=56320&&t<57344}function Wm(t){return t>=55296&&t<56320}var M=class t{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;re&&r(l,i+a,o||null,s)!==!1&&l.content.size){let u=a+1;l.nodesBetween(Math.max(0,e-u),Math.min(l.content.size,n-u),r,i+u)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(a,l)=>{let c=a.isText?a.text.slice(Math.max(e,l)-l,n-l):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&c||a.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);oe)for(let o=0,s=0;se&&((sn)&&(a.isText?a=a.cut(Math.max(0,e-s),Math.min(a.text.length,n-s)):a=a.cut(Math.max(0,e-s-1),Math.min(a.content.size,n-s-1))),r.push(a),i+=a.nodeSize),s=l}return new t(r,i)}cutByIndex(e,n){return e==n?t.empty:e==0&&n==this.content.length?this:new t(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new t(i,o)}addToStart(e){return new t([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new t(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),o=r+i.nodeSize;if(o>=e)return o==e?ea(n+1,o):ea(n,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return t.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return t.fromArray(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return t.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};ne.none=[];var Rn=class extends Error{},R=class t{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Vm(this.content,e+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new t(r,this.openStart,this.openEnd)}removeBetween(e,n){return new t(jm(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return t.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new t(M.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new t(e,r,i)}};R.empty=new R(M.empty,0,0);function jm(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:a}=t.findIndex(n);if(i==e||o.isText){if(a!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(jm(o.content,e-i-1,n-i-1)))}function Vm(t,e,n,r,i,o){let{index:s,offset:a}=t.findIndex(e),l=t.maybeChild(s);if(a==e||l.isText)return o&&r<=0&&i<=0&&!o.canReplace(s,s,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=Vm(l.content,e-a-1,n,s==0?r-1:0,s==t.childCount-1?i-1:0,l);return c&&t.replaceChild(s,l.copy(c))}function iM(t,e,n){if(n.openStart>t.depth)throw new Rn("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Rn("Inconsistent open depths");return qm(t,e,n,0)}function qm(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function go(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(ur(t.nodeAfter,r),o++));for(let a=o;ai&&Nc(t,e,i+1),s=r.depth>i&&Nc(n,r,i+1),a=[];return go(null,t,i,a),o&&s&&e.index(i)==n.index(i)?(Km(o,s),ur(fr(o,Um(t,e,n,r,i+1)),a)):(o&&ur(fr(o,ia(t,e,i+1)),a),go(e,n,i,a),s&&ur(fr(s,ia(n,r,i+1)),a)),go(r,null,i,a),new M(a)}function ia(t,e,n){let r=[];if(go(null,t,n,r),t.depth>n){let i=Nc(t,e,n+1);ur(fr(i,ia(t,e,n+1)),r)}return go(e,null,n,r),new M(r)}function oM(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(M.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}var oa=class t{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new ko(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:a,offset:l}=s.content.findIndex(o),c=o-l;if(r.push(s,a,i+l),!c||(s=s.child(a),s.isText))break;o=c-1,i+=l+1}return new t(n,r,o)}static resolveCached(e,n){let r=Nm.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Jm(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=M.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),a=s&&s.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let l=i;ln.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=M.fromJSON(e,n.content),o=e.nodeType(n.type).create(n.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};nt.prototype.text=void 0;var Oc=class t extends nt{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Jm(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new t(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new t(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Jm(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}var dr=class t{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new Dc(e,n);if(r.next==null)return t.empty;let i=Gm(r);r.next&&r.err("Unexpected trailing text");let o=hM(pM(i));return mM(o,r),o}matchType(e){for(let n=0;nc.createAndFill()));for(let c=0;c=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}};dr.empty=new dr(!0);var Dc=class{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Gm(t){let e=[];do e.push(lM(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function lM(t){let e=[];do e.push(cM(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function cM(t){let e=dM(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=uM(t,e);else break;return e}function Rm(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function uM(t,e){let n=Rm(t),r=n;return t.eat(",")&&(t.next!="}"?r=Rm(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function fM(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function dM(t){if(t.eat("(")){let e=Gm(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=fM(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function pM(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,a,l){let c={term:l,to:a};return e[s].push(c),c}function i(s,a){s.forEach(l=>l.to=a)}function o(s,a){if(s.type=="choice")return s.exprs.reduce((l,c)=>l.concat(o(c,a)),[]);if(s.type=="seq")for(let l=0;;l++){let c=o(s.exprs[l],a);if(l==s.exprs.length-1)return c;i(c,a=n())}else if(s.type=="star"){let l=n();return r(a,l),i(o(s.expr,l),l),[r(l)]}else if(s.type=="plus"){let l=n();return i(o(s.expr,a),l),i(o(s.expr,l),l),[r(l)]}else{if(s.type=="opt")return[r(a)].concat(o(s.expr,a));if(s.type=="range"){let l=a;for(let c=0;c{t[s].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let u=0;u{c||i.push([a,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let o=e[r.join(",")]=new dr(r.indexOf(t.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Qm(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new nt(this,this.computeAttrs(e),M.from(n),ne.setFrom(r))}createChecked(e=null,n,r){return n=M.from(n),this.checkContent(n),new nt(this,this.computeAttrs(e),n,ne.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=M.from(n),n.size){let s=this.contentMatch.fillBefore(n);if(!s)return null;n=s.append(n)}let i=this.contentMatch.matchFragment(n),o=i&&i.fillBefore(M.empty,!0);return o?new nt(this,e,n.append(o),ne.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[o]=new t(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function gM(t,e,n){let r=n.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${o}`)}}var Lc=class{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?gM(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}},xo=class t{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=eg(e,i.attrs),this.excluded=null;let o=Ym(this.attrs);this.instance=o?new ne(this,o):null}create(e=null){return!e&&this.instance?this.instance:new ne(this,Qm(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new t(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}},sa=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=Ac.from(e.nodes),n.marks=Ac.from(e.marks||{}),this.nodes=bo.compile(this.spec.nodes,this),this.marks=xo.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",a=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=dr.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=a=="_"?null:a?Dm(this,a.split(" ")):a==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Dm(this,s.split(" "))}this.nodeFromJSON=i=>nt.fromJSON(this,i),this.markFromJSON=i=>ne.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof bo){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new Oc(r,r.defaultAttrs,e,ne.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}};function Dm(t,e){let n=[];for(let r=0;r-1)&&n.push(s=l)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function yM(t){return t.tag!=null}function kM(t){return t.style!=null}var xt=class t{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(yM(i))this.tags.push(i);else if(kM(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,n={}){let r=new aa(this,n,!1);return r.addAll(e,ne.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new aa(this,n,!0);return r.addAll(e,ne.none,n.from,n.to),R.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(s.getAttrs){let l=s.getAttrs(n);if(l===!1)continue;s.attrs=l||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Bm(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Bm(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new t(e,t.schemaRules(e)))}},tg={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},bM={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ng={ol:!0,ul:!0},wo=1,Bc=2,yo=4;function Lm(t,e,n){return e!=null?(e?wo:0)|(e==="full"?Bc:0):t&&t.whitespace=="pre"?wo|Bc:n&~yo}var si=class{constructor(e,n,r,i,o,s){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=ne.none,this.match=o||(s&yo?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(M.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&wo)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=M.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(M.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!tg.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},aa=class{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,o,s=Lm(null,n.preserveWhitespace,0)|(r?yo:0);i?o=new si(i.type,i.attrs,ne.none,!0,n.topMatch||i.type.contentMatch,s):r?o=new si(null,null,ne.none,!0,null,s):o=new si(e.schema.topNodeType,null,ne.none,!0,null,s),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,o=i.options&Bc?"full":this.localPreserveWS||(i.options&wo)>0,{schema:s}=this.parser;if(o==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)if(o==="full")r=r.replace(/\r\n?/g,` -`);else if(s.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(s.linebreakReplacement.create())){let a=r.split(/\r?\n|\r/);for(let l=0;l!l.clearMark(c)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return n}addElementByRule(e,n,r,i){let o,s;if(n.node)if(s=this.parser.schema.nodes[n.node],s.isLeaf)this.insertNode(s.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(s,n.attrs||null,r,n.preserveWhitespace);l&&(o=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let a=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}o&&this.sync(a)&&this.open--}addAll(e,n,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,a=i==null?null:e.childNodes[i];s!=a;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,n);this.findAtPoint(e,o)}findPlace(e,n,r){let i,o;for(let s=this.open,a=0;s>=0;s--){let l=this.nodes[s],c=l.findWrapping(e);if(c&&(!i||i.length>c.length+a)&&(i=c,o=l,!c.length))break;if(l.solid){if(r)break;a+=2}}if(!i)return null;this.sync(o);for(let s=0;s(s.type?s.type.allowsMarkType(c.type):Pm(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new si(e,n,l,i,null,a)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=wo)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(a,l)=>{for(;a>=0;a--){let c=n[a];if(c==""){if(a==n.length-1||a==0)continue;for(;l>=o;l--)if(s(a-1,l))return!0;return!1}else{let u=l>0||l==0&&i?this.nodes[l].type:r&&l>=o?r.node(l-o).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;l--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}};function xM(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ng.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function wM(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Bm(t){let e={};for(let n in t)e[n]=t[n];return e}function Pm(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=a=>{o.push(a);for(let l=0;l{if(o.length||s.marks.length){let a=0,l=0;for(;a=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&na(ta(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return typeof n=="string"?{dom:e.createTextNode(n)}:na(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new t(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Fm(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Fm(e.marks)}};function Fm(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function ta(t){return t.document||window.document}var zm=new WeakMap;function CM(t){let e=zm.get(t);return e===void 0&&zm.set(t,e=SM(t)),e}function SM(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let a,l=n?t.createElementNS(n,i):t.createElement(i),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let f in c)if(c[f]!=null){let d=f.indexOf(" ");d>0?l.setAttributeNS(f.slice(0,d),f.slice(d+1),c[f]):f=="style"&&l.style?l.style.cssText=c[f]:l.setAttribute(f,c[f])}}for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else if(typeof d=="string")l.appendChild(t.createTextNode(d));else{let{dom:p,contentDOM:h}=na(t,d,n,r);if(l.appendChild(p),h){if(a)throw new RangeError("Multiple content holes");a=h}}}return{dom:l,contentDOM:a}}var og=65535,sg=Math.pow(2,16);function MM(t,e){return t+e*sg}function rg(t){return t&og}function EM(t){return(t-(t&og))/sg}var ag=1,lg=2,la=4,cg=8,Mo=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&cg)>0}get deletedBefore(){return(this.delInfo&(ag|la))>0}get deletedAfter(){return(this.delInfo&(lg|la))>0}get deletedAcross(){return(this.delInfo&la)>0}},on=class t{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&t.empty)return t.empty}recover(e){let n=0,r=rg(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[a+o],u=this.ranges[a+s],f=l+c;if(e<=f){let d=c?e==l?-1:e==f?1:n:n,p=l+i+(d<0?0:u);if(r)return p;let h=e==(n<0?l:f)?null:MM(a/3,e-l),m=e==l?lg:e==f?ag:la;return(n<0?e!=l:e!=f)&&(m|=cg),new Mo(p,m,h)}i+=u-c}return r?e+i:new Mo(e+i,0,null)}touches(e,n){let r=0,i=rg(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;ae)break;let c=this.ranges[a+o],u=l+c;if(e<=u&&a==i*3)return!0;r+=this.ranges[a+s]-c}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new t;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&l!s.isAtom||!a.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Pe.fromReplace(e,this.from,this.to,o)}invert(){return new hr(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};Ie.jsonID("addMark",pr);var hr=class t extends Ie{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new R(Hc(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Pe.fromReplace(e,this.from,this.to,r)}invert(){return new pr(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};Ie.jsonID("removeMark",hr);var To=class t extends Ie{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Pe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Pe.fromReplace(e,this.pos,this.pos+1,new R(M.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new t(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new t(n.from,n.to,n.gapFrom,n.gapTo,R.fromJSON(e,n.slice),n.insert,!!n.structure)}};Ie.jsonID("replaceAround",Fe);function $c(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function TM(t,e,n,r){let i=[],o=[],s,a;t.doc.nodesBetween(e,n,(l,c,u)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+l.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(l)),o.forEach(l=>t.step(l))}function vM(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,a)=>{if(!s.isInline)return;o++;let l=null;if(r instanceof xo){let c=s.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(s.marks)&&(l=[r]):l=s.marks;if(l&&l.length){let c=Math.min(a+s.nodeSize,n);for(let u=0;ut.step(new hr(s.from,s.to,s.style)))}function Wc(t,e,n,r=n.contentMatch,i=!0){let o=t.doc.nodeAt(e),s=[],a=e+1;for(let l=0;l=0;l--)t.step(s[l])}function AM(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function mr(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,o=0;;--r){let s=t.$from.node(r),a=t.$from.index(r)+i,l=t.$to.indexAfter(r)-o;if(rn;h--)m||r.index(h)>0?(m=!0,u=M.from(r.node(h).copy(u)),f++):l--;let d=M.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)=0;s--){if(r.size){let a=n[s].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=M.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new Fe(i,o,i,o,new R(r,0,0),n.length,!0))}function DM(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,a)=>{let l=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,l)&&LM(t.doc,t.mapping.slice(o).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!h?c=!1:!p&&h&&(c=!0)}c===!1&&fg(t,s,a,o),Wc(t,t.mapping.slice(o).map(a,1),r,void 0,c===null);let u=t.mapping.slice(o),f=u.map(a,1),d=u.map(a+s.nodeSize,1);return t.step(new Fe(f,d,f+1,d-1,new R(M.from(r.create(l,null,s.marks)),0,0),1,!0)),c===!0&&ug(t,s,a,o),!1}})}function ug(t,e,n,r){e.forEach((i,o)=>{if(i.isText){let s,a=/\r?\n|\r/g;for(;s=a.exec(i.text);){let l=t.mapping.slice(r).map(n+1+o+s.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function fg(t,e,n,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(n+1+o);t.replaceWith(s,s+1,e.type.schema.text(` -`))}})}function LM(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function BM(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Fe(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new R(M.from(s),0,0),1,!0))}function yr(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,u=n-2;c>o;c--,u--){let f=i.node(c),d=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[u+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=r&&r[u]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(p))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function PM(t,e,n=1,r){let i=t.doc.resolve(e),o=M.empty,s=M.empty;for(let a=i.depth,l=i.depth-n,c=n-1;a>l;a--,c--){o=M.from(i.node(a).copy(o));let u=r&&r[c];s=M.from(u?u.type.create(u.attrs,s):i.node(a).copy(s))}t.step(new xe(e,e,new R(o.append(s),n,n),!0))}function kr(t,e){let n=t.resolve(e),r=n.index();return zM(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function FM(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o=0;s--){let a=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,l=r.index(s)+(a>0?1:0),c=r.node(s),u=!1;if(o==1)u=c.canReplace(l,l,i);else{let f=c.contentMatchAt(l).findWrapping(i.firstChild.type);u=f&&c.canReplaceWith(l,l,f[0])}if(u)return a==0?r.pos:a<0?r.before(s+1):r.after(s+1)}return null}function vo(t,e,n=e,r=R.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return pg(i,o,r)?new xe(e,n,r):new _c(i,o,r).fit()}function pg(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}var _c=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=M.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=M.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,a=i.depth;for(;s&&a&&o.childCount==1;)o=o.firstChild.content,s--,a--;let l=new R(o,s,a);return e>-1?new Fe(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new xe(r.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Fc(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],u,f=null;if(n==1&&(s?c.matchType(s.type)||(f=c.fillBefore(M.from(s),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:a,parent:o,inject:f};if(n==2&&s&&(u=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:a,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Fc(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new R(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Fc(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new R(Co(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new R(Co(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m1||l==0||m.content.size)&&(f=g,u.push(hg(m.mark(d.allowedMarks(m.marks)),c==1?l:0,c==a.childCount?p:-1)))}let h=c==a.childCount;h||(p=-1),this.placed=So(this.placed,n,M.from(u)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=a;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;a--){let{match:l,type:c}=this.frontier[a],u=zc(e,a,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=So(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=So(this.placed,this.depth,M.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(M.empty,!0);n.childCount&&(this.placed=So(this.placed,this.frontier.length,n))}};function Co(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Co(t.firstChild.content,e-1,n)))}function So(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(So(t.lastChild.content,e-1,n)))}function Fc(t,e){for(let n=0;n1&&(r=r.replaceChild(0,hg(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(M.empty,!0)))),t.copy(r)}function zc(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!HM(n,o.content,s)?a:null}function HM(t,e,n){for(let r=n;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?a=d:i.before(d)==p&&s.splice(1,0,-d)}let l=s.indexOf(a),c=[],u=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(c.push(h),p==r.openStart)break;d=h.content}for(let d=u-1;d>=0;d--){let p=c[d],h=WM(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(a)-1)))u=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+u+1)%(r.openStart+1),h=c[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function mg(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(M.empty,!0))}return t}function VM(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=_M(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new R(M.from(r),0,0))}function qM(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let s=r.sharedDepth(n),a=!1;for(let l=r.depth;l>s;l--)r.node(l).type.spec.isolating&&(a=!0);for(let l=i.depth;l>s;l--)i.node(l).type.spec.isolating&&(a=!0);if(!a){for(let l=r.depth;l>0&&e==r.start(l);l--)e=r.before(l);for(let l=i.depth;l>0&&n==i.start(l);l--)n=i.before(l);r=t.doc.resolve(e),i=t.doc.resolve(n)}}let o=gg(r,i);for(let s=0;s0&&(l||r.node(a-1).canReplace(r.index(a-1),i.indexAfter(a-1))))return t.delete(r.before(a),i.after(a))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return t.delete(r.before(s),n);t.delete(e,n)}function gg(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}var ca=class t extends Ie{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Pe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Pe.fromReplace(e,this.pos,this.pos+1,new R(M.from(i),0,n.isLeaf?0:1))}getMap(){return on.empty}invert(e){return new t(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new t(n.pos,n.attr,n.value)}};Ie.jsonID("attr",ca);var ua=class t extends Ie{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Pe.ok(r)}getMap(){return on.empty}invert(e){return new t(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new t(n.attr,n.value)}};Ie.jsonID("docAttr",ua);var li=class extends Error{};li=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};li.prototype=Object.create(Error.prototype);li.prototype.constructor=li;li.prototype.name="TransformError";var ci=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Eo}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new li(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r{e=Math.min(e,a),n=Math.max(n,l)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=R.empty){let i=vo(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new R(M.from(r),0,0))}delete(e,n){return this.replace(e,n,R.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return jM(this,e,n,r),this}replaceRangeWith(e,n,r){return VM(this,e,n,r),this}deleteRange(e,n){return qM(this,e,n),this}lift(e,n){return IM(this,e,n),this}join(e,n=1){return $M(this,e,n),this}wrap(e,n){return OM(this,e,n),this}setBlockType(e,n=e,r,i=null){return DM(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return BM(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new ca(e,n,r)),this}setDocAttribute(e,n){return this.step(new ua(e,n)),this}addNodeMark(e,n){return this.step(new To(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof ne)n.isInSet(r.marks)&&this.step(new ai(e,n));else{let i=r.marks,o,s=[];for(;o=n.isInSet(i);)s.push(new ai(e,o)),i=o.removeFromSet(i);for(let a=s.length-1;a>=0;a--)this.step(s[a])}return this}split(e,n=1,r){return PM(this,e,n,r),this}addMark(e,n,r){return TM(this,e,n,r),this}removeMark(e,n,r){return vM(this,e,n,r),this}clearIncompatible(e,n,r){return Wc(this,e,n,r),this}};var jc=Object.create(null),_=class{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new On(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;o--){let s=n<0?ui(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):ui(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new pt(e.node(0))}static atStart(e){return ui(e,e,0,0,1)||new pt(e)}static atEnd(e){return ui(e,e,e.content.size,e.childCount,-1)||new pt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=jc[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in jc)throw new RangeError("Duplicate use of selection JSON ID "+e);return jc[e]=n,n.prototype.jsonID=e,n}getBookmark(){return P.between(this.$anchor,this.$head).getBookmark()}};_.prototype.visible=!0;var On=class{constructor(e,n){this.$from=e,this.$to=n}},yg=!1;function kg(t){!yg&&!t.parent.inlineContent&&(yg=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}var P=class t extends _{constructor(e,n=e){kg(e),kg(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return _.near(r);let i=e.resolve(n.map(this.anchor));return new t(i.parent.inlineContent?i:r,r)}replace(e,n=R.empty){if(super.replace(e,n),n==R.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof t&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new da(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new t(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=_.findFrom(n,r,!0)||_.findFrom(n,-r,!0);if(o)n=o.$head;else return _.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(_.findFrom(e,-r,!0)||_.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let a=e.child(s);if(a.isAtom){if(!o&&H.isSelectable(a))return H.create(t,n-(i<0?a.nodeSize:0))}else{let l=ui(t,a,n+i,i<0?a.childCount:0,i,o);if(l)return l}n+=a.nodeSize*i}return null}function bg(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=u)}),t.setSelection(_.near(t.doc.resolve(s),n))}var xg=1,fa=2,wg=4,Kc=class extends ci{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=fa,this}ensureMarks(e){return ne.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&fa)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~fa,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||ne.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(_.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=wg,this}get scrolledIntoView(){return(this.updated&wg)>0}};function Cg(t,e){return!e||!t?t:t.bind(e)}var br=class{constructor(e,n,r){this.name=e,this.init=Cg(n.init,r),this.apply=Cg(n.apply,r)}},UM=[new br("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new br("selection",{init(t,e){return t.selection||_.atStart(e.doc)},apply(t){return t.selection}}),new br("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new br("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})],Ao=class{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=UM.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new br(r.key,r.spec.state,r))})}},fi=class t{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Ao(e.schema,e.plugins),o=new t(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=nt.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=_.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let l=r[a],c=l.spec.state;if(l.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){o[s.name]=c.fromJSON.call(l,e,n[a],o);return}}o[s.name]=s.init(e,o)}}),o}};function Sg(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Sg(i,e,{})),n[r]=i}return n}var X=class{constructor(e){this.spec=e,this.props={},e.props&&Sg(e.props,this,this.props),this.key=e.key?e.key.key:Mg("plugin")}getState(e){return e[this.key]}},Vc=Object.create(null);function Mg(t){return t in Vc?t+"$"+ ++Vc[t]:(Vc[t]=0,t+"$")}var ee=class{constructor(e="key"){this.key=Mg(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var pa=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function Tg(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}var Jc=(t,e,n)=>{let r=Tg(t,n);if(!r)return!1;let i=Xc(r);if(!i){let s=r.blockRange(),a=s&&mr(s);return a==null?!1:(e&&e(t.tr.lift(s,a).scrollIntoView()),!0)}let o=i.nodeBefore;if(Ng(t,i,e,-1))return!0;if(r.parent.content.size==0&&(di(o,"end")||H.isSelectable(o)))for(let s=r.depth;;s--){let a=vo(t.doc,r.before(s),r.after(s),R.empty);if(a&&a.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1},vg=(t,e,n)=>{let r=Tg(t,n);if(!r)return!1;let i=Xc(r);return i?JM(t,i,e):!1};function JM(t,e,n){let r=e.nodeBefore,i=r,o=e.pos-1;for(;!i.isTextblock;o--){if(i.type.spec.isolating)return!1;let u=i.lastChild;if(!u)return!1;i=u}let s=e.nodeAfter,a=s,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let u=a.firstChild;if(!u)return!1;a=u}let c=vo(t.doc,o,l,R.empty);if(!c||c.from!=o||c instanceof xe&&c.slice.size>=l-o)return!1;if(n){let u=t.tr.step(c);u.setSelection(P.create(u.doc,o)),n(u.scrollIntoView())}return!0}function di(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Gc=(t,e,n)=>{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;o=Xc(r)}let s=o&&o.nodeBefore;return!s||!H.isSelectable(s)?!1:(e&&e(t.tr.setSelection(H.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Xc(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function GM(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=GM(t,n);if(!r)return!1;let i=Ag(r);if(!i)return!1;let o=i.nodeAfter;if(Ng(t,i,e,1))return!0;if(r.parent.content.size==0&&(di(o,"start")||H.isSelectable(o))){let s=vo(t.doc,r.before(),r.after(),R.empty);if(s&&s.slice.size{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let{$from:n,$to:r}=t.selection,i=n.blockRange(r),o=i&&mr(i);return o==null?!1:(e&&e(t.tr.lift(i,o).scrollIntoView()),!0)},QM=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` -`).scrollIntoView()),!0)};function Yc(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=Yc(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let a=n.after(),l=t.tr.replaceWith(a,a,s.createAndFill());l.setSelection(_.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},ZM=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof pt||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Yc(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if(yr(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&mr(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function tE(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof H&&e.selection.node.isBlock)return!r.parentOffset||!yr(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,a,l=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){l=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),a=Yc(r.node(p-1).contentMatchAt(r.indexAfter(p-1)));let m=t&&t(i.parent,l,r);o.unshift(m||(l&&a?{type:a}:null)),s=p;break}else{if(p==1)return!1;o.unshift(null)}let u=e.tr;(e.selection instanceof P||e.selection instanceof pt)&&u.deleteSelection();let f=u.mapping.map(r.pos),d=yr(u.doc,f,o.length,o);if(d||(o[0]=a?{type:a}:null,d=yr(u.doc,f,o.length,o)),!d)return!1;if(u.split(f,o.length,o),!l&&c&&r.node(s).type!=a){let p=u.mapping.map(r.before(s)),h=u.doc.resolve(p);a&&r.node(s-1).canReplaceWith(h.index(),h.index()+1,a)&&u.setNodeMarkup(u.mapping.map(r.before(s)),a)}return n&&n(u.scrollIntoView()),!0}}var nE=tE();var rE=(t,e)=>(e&&e(t.tr.setSelection(new pt(t.doc))),!0);function iE(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||kr(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function Ng(t,e,n,r){let i=e.nodeBefore,o=e.nodeAfter,s,a,l=i.type.spec.isolating||o.type.spec.isolating;if(!l&&iE(t,e,n))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(s=(a=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&a.matchType(s[0]||o.type).validEnd){if(n){let p=e.pos+o.nodeSize,h=M.empty;for(let y=s.length-1;y>=0;y--)h=M.from(s[y].create(null,h));h=M.from(i.copy(h));let m=t.tr.step(new Fe(e.pos-1,p,e.pos,p,new R(h,1,0),s.length,!0)),g=m.doc.resolve(p+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&kr(m.doc,g.pos)&&m.join(g.pos),n(m.scrollIntoView())}return!0}let u=o.type.spec.isolating||r>0&&l?null:_.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),d=f&&mr(f);if(d!=null&&d>=e.depth)return n&&n(t.tr.lift(f,d).scrollIntoView()),!0;if(c&&di(o,"start",!0)&&di(i,"end")){let p=i,h=[];for(;h.push(p),!p.isTextblock;)p=p.lastChild;let m=o,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(n){let y=M.empty;for(let C=h.length-1;C>=0;C--)y=M.from(h[C].copy(y));let x=t.tr.step(new Fe(e.pos-h.length,e.pos+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new R(y,h.length,0),0,!0));n(x.scrollIntoView())}return!0}}return!1}function Rg(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(n&&n(e.tr.setSelection(P.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}var oE=Rg(-1),sE=Rg(1);function pi(t,e=null){return function(n,r){let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=s&&gr(s,t,e);return a?(r&&r(n.tr.wrap(s,a).scrollIntoView()),!0):!1}}function Dn(t,e=null){return function(n,r){let i=!1;for(let o=0;o{if(i)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)i=!0;else{let u=n.doc.resolve(c),f=u.index();i=u.parent.canReplaceWith(f,f+1,t)}})}if(!i)return!1;if(r){let o=n.tr;for(let s=0;s{if(a||!r&&l.isAtom&&l.isInline&&c>=o.pos&&c+l.nodeSize<=s.pos)return!1;a=l.inlineContent&&l.type.allowsMarkType(n)}),a)return!0}return!1}function lE(t){let e=[];for(let n=0;n{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new On(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poss.doc.rangeHasMark(p.$from.pos,p.$to.pos,t)):f=!u.every(p=>{let h=!1;return d.doc.nodesBetween(p.$from.pos,p.$to.pos,(m,g,y)=>{if(h)return!1;h=!t.isInSet(m.marks)&&!!y&&y.type.allowsMarkType(t)&&!(m.isText&&/^\s*$/.test(m.textBetween(Math.max(0,p.$from.pos-g),Math.min(m.nodeSize,p.$to.pos-g))))}),!h});for(let p=0;p0&&(o=n[0].slice(s-a,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Lg=(t,e)=>{let n=t.plugins;for(let r=0;r=0;l--)s.step(a.steps[l].invert(a.docs[l]));if(o.text){let l=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,t.schema.text(o.text,l))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},C2=new be(/--$/,"\u2014",{inCodeMark:!1}),S2=new be(/\.\.\.$/,"\u2026",{inCodeMark:!1}),M2=new be(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),E2=new be(/"$/,"\u201D",{inCodeMark:!1}),T2=new be(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),v2=new be(/'$/,"\u2019",{inCodeMark:!1});function ha(t,e,n=null,r){return new be(t,(i,o,s,a)=>{let l=n instanceof Function?n(o):n,c=i.tr.delete(s,a),u=c.doc.resolve(s),f=u.blockRange(),d=f&&gr(f,e,l);if(!d)return null;c.wrap(f,d);let p=c.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&kr(c.doc,s-1)&&(!r||r(o,p))&&c.join(s-1),c})}function Zc(t,e,n=null){return new be(t,(r,i,o,s)=>{let a=r.doc.resolve(o),l=n instanceof Function?n(i):n;return a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,l):null})}var Bn=typeof navigator<"u"?navigator:null,Bg=typeof document<"u"?document:null,Pn=Bn&&Bn.userAgent||"",tu=/Edge\/(\d+)/.exec(Pn),$g=/MSIE \d/.exec(Pn),nu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Pn),iu=!!($g||nu||tu),D2=$g?document.documentMode:nu?+nu[1]:tu?+tu[1]:0,fE=!iu&&/gecko\/(\d+)/i.test(Pn),L2=fE&&+(/Firefox\/(\d+)/.exec(Pn)||[0,0])[1],ru=!iu&&/Chrome\/(\d+)/.exec(Pn),dE=!!ru,B2=ru?+ru[1]:0,pE=!iu&&!!Bn&&/Apple Computer/.test(Bn.vendor),hE=pE&&(/Mobile\/\w+/.test(Pn)||!!Bn&&Bn.maxTouchPoints>2),P2=hE||(Bn?/Mac/.test(Bn.platform):!1),mE=/Android \d/.test(Pn),gE=!!Bg&&"webkitFontSmoothing"in Bg.documentElement.style,F2=gE?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function eu(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,a=s.doc.resolve(e);if(a.parent.type.spec.code)return!1;let l=a.parent.textBetween(Math.max(0,a.parentOffset-500),a.parentOffset,void 0,"\uFFFC")+r;for(let c of i){let u=c,f=u.match.exec(l),d=f&&f[0]&&u.handler(s,f,e-(f[0].length-r.length),n);if(d)return u.undoable!==!1&&d.setMeta(o,{transform:d,from:e,to:n,text:r}),t.dispatch(d),!0}return!1}var yE=new ee("MILKDOWN_CUSTOM_INPUTRULES");function _g({rules:t}){let e=new X({key:yE,isInputRules:!0,state:{init(){return null},apply(n,r){let i=n.getMeta(this);return i||(n.selectionSet||n.docChanged?null:r)}},props:{handleTextInput(n,r,i,o){return eu(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>(setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&eu(n,r.pos,r.pos,"",t,e)}),!1),keydown:(n,r)=>!(mE&&dE&&r.key==="Enter")||n.composing?!1:n.someProp("handleKeyDown",i=>i(n,r))?(r.preventDefault(),!0):!1},handleKeyDown(n,r){if(r.key!=="Enter")return!1;let{$cursor:i}=n.state.selection;return i?eu(n,i.pos,i.pos,` -`,t,e):!1}}});return e}function an(t,e,n={}){return new be(t,(r,i,o,s)=>{var a,l,c,u;let{tr:f}=r,d=i.length,p=i[d-1],h=i[0],m=[],g,y={group:p,fullMatch:h,start:o,end:s},x=(a=n.updateCaptured)==null?void 0:a.call(n,y);if(Object.assign(y,x),{group:p,fullMatch:h,start:o,end:s}=y,h===null||p?.trim()==="")return null;if(p){let C=h.search(/\S/),v=o+h.indexOf(p),A=v+p.length;m=(l=f.storedMarks)!=null?l:[],Ao&&f.delete(o+C,v),g=o+C+p.length;let w=(c=n.getAttr)==null?void 0:c.call(n,i);f.addMark(o,g,e.create(w)),f.setStoredMarks(m),(u=n.beforeDispatch)==null||u.call(n,{match:i,start:o,end:s,tr:f})}return f})}function hi(t,e,n={}){return new be(t,(r,i,o,s)=>{var a,l,c;let{tr:u}=r,f=i[1],d=i[0],p={group:f,fullMatch:d,start:o,end:s},h=(a=n.updateCaptured)==null?void 0:a.call(n,p);if(Object.assign(p,h),{group:f,fullMatch:d,start:o,end:s}=p,d===null||!f||f.trim()==="")return null;let m=(l=n.getAttr)==null?void 0:l.call(n,i),g=e.createAndFill(m);return g&&(u.replaceRangeWith(e.isBlock?u.doc.resolve(o).before():o,s,g),(c=n.beforeDispatch)==null||c.call(n,{match:[d,f],start:o,end:s,tr:u})),u})}var kE=Object.defineProperty,bE=Object.defineProperties,xE=Object.getOwnPropertyDescriptors,Pg=Object.getOwnPropertySymbols,wE=Object.prototype.hasOwnProperty,CE=Object.prototype.propertyIsEnumerable,Fg=(t,e,n)=>e in t?kE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,SE=(t,e)=>{for(var n in e||(e={}))wE.call(e,n)&&Fg(t,n,e[n]);if(Pg)for(var n of Pg(e))CE.call(e,n)&&Fg(t,n,e[n]);return t},ME=(t,e)=>bE(t,xE(e));function zg(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Hg(t,e,n){let i=t.state.doc.content.size,o=zg(e,0,i),s=zg(n,0,i),a=t.coordsAtPos(o),l=t.coordsAtPos(s,-1),c=Math.min(a.top,l.top),u=Math.max(a.bottom,l.bottom),f=Math.min(a.left,l.left),d=Math.max(a.right,l.right),p=d-f,h=u-c,y={top:c,bottom:u,left:f,right:d,width:p,height:h,x:f,y:c};return ME(SE({},y),{toJSON:()=>y})}function ou(t){return Object.assign(Object.create(t),t).setTime(Date.now())}function EE(t,e){return Array.isArray(t)&&t.includes(e.type)||e.type===t}function ma(t){if(t.content.childCount===1){let e=t.content.firstChild;if(e?.type.name==="text"&&e.marks.length===0)return e;if(e?.type.name==="paragraph"&&e.childCount===1){let n=e.firstChild;if(n?.type.name==="text"&&n.marks.length===0)return n}}return!1}function TE(t){return e=>{for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r)){let i=e.before(n),o=e.after(n);return{from:i,to:o,node:r}}}}}function Wg(t,e){return TE(n=>n.type===e)(t)}function jg(t,e){let n=e.nodes[t];if(!n)throw oh("node",t);return n}function su(t){return e=>{for(let n=e.depth;n>0;n--){let r=e.node(n);if(t(r))return{pos:e.before(n),start:e.start(n),depth:n,node:r}}}}function Vg(t){return e=>su(t)(e.$from)}function qg(t,e){if(!(t instanceof H))return;let{node:n,$from:r}=t;if(EE(e,n))return{node:n,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Kg=(t,e)=>{let{selection:n,doc:r}=t;if(n instanceof H)return{hasNode:n.node.type===e,pos:n.from,target:n.node};let{from:i,to:o}=n,s=!1,a=-1,l=null;return r.nodesBetween(i,o,(c,u)=>l?!1:c.type===e?(s=!0,a=u,l=c,!1):!0),{hasNode:s,pos:a,target:l}};var ln={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ya={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},vE=typeof navigator<"u"&&/Mac/.test(navigator.platform),AE=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(we=0;we<10;we++)ln[48+we]=ln[96+we]=String(we);var we;for(we=1;we<=24;we++)ln[we+111]="F"+we;var we;for(we=65;we<=90;we++)ln[we]=String.fromCharCode(we+32),ya[we]=String.fromCharCode(we);var we;for(ga in ln)ya.hasOwnProperty(ga)||(ya[ga]=ln[ga]);var ga;function Ug(t){var e=vE&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||AE&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?ya:ln)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var IE=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),NE=typeof navigator<"u"&&/Win/.test(navigator.platform);function RE(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let a=0;athis.elements.length,this.top=()=>this.elements.at(-1),this.push=t=>{this.top()?.push(t)},this.open=t=>{this.elements.push(t)},this.close=()=>{let t=this.elements.pop();if(!t)throw Hl();return t}}},DE=class Qg extends Xg{constructor(e,n,r){super(),this.type=e,this.content=n,this.attrs=r}push(e,...n){this.content.push(e,...n)}pop(){return this.content.pop()}static create(e,n,r){return new Qg(e,n,r)}},Zg=class extends Yg{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(e,r),n.toDoc())}}constructor(t){super(),this.#t=ne.none,this.#e=e=>e.isText,this.#r=(e,n)=>{if(this.#e(e)&&this.#e(n)&&ne.sameSet(e.marks,n.marks))return this.schema.text(e.text+n.text,e.marks)},this.#n=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.parseMarkdown.match(e));if(!n)throw rh(e);return n},this.#s=e=>{let n=this.#n(e);n.spec.parseMarkdown.runner(this,e,n)},this.injectRoot=(e,n,r)=>(this.openNode(n,r),this.next(e.children),this),this.openNode=(e,n)=>(this.open(DE.create(e,[],n)),this),this.#o=()=>{this.#t=ne.none;let e=this.close();return this.#i(e.type,e.attrs,e.content)},this.closeNode=()=>{try{this.#o()}catch(e){console.error(e)}return this},this.#i=(e,n,r)=>{let i=e.createAndFill(n,r,this.#t);if(!i)throw nh(e,n,r);return this.push(i),i},this.addNode=(e,n,r)=>{try{this.#i(e,n,r)}catch(i){console.error(i)}return this},this.openMark=(e,n)=>{let r=e.create(n);return this.#t=r.addToSet(this.#t),this},this.closeMark=e=>(this.#t=e.removeFromSet(this.#t),this),this.addText=e=>{try{let n=this.top();if(!n)throw Hl();let r=n.pop(),i=this.schema.text(e,this.#t);if(!r)return n.push(i),this;let o=this.#r(r,i);return o?(n.push(o),this):(n.push(r,i),this)}catch(n){return console.error(n),this}},this.build=()=>{let e;do e=this.#o();while(this.size());return e},this.next=(e=[])=>([e].flat().forEach(n=>this.#s(n)),this),this.toDoc=()=>this.build(),this.run=(e,n)=>{let r=e.runSync(e.parse(n),n);return this.next(r),this},this.schema=t}#e;#r;#n;#s;#o;#i},Gg=class ey extends Xg{constructor(e,n,r,i={}){super(),this.type=e,this.children=n,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}static{this.create=(e,n,r,i={})=>new ey(e,n,r,i)}},LE=t=>Object.prototype.hasOwnProperty.call(t,"size"),ty=class extends Yg{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(r),n.toString(e))}}constructor(t){super(),this.#t=[],this.#e=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.toMarkdown.match(e));if(!n)throw ih(e.type);return n},this.#r=e=>this.#e(e).spec.toMarkdown.runner(this,e),this.#n=(e,n)=>this.#e(e).spec.toMarkdown.runner(this,e,n),this.#s=e=>{let n=o=>o.type.spec.priority??50,r=[...e].sort((o,s)=>n(o)-n(s)),i=[];return this.#t.forEach(({mark:o})=>{let s=r.findIndex(a=>a.eq(o));s>=0&&i.push(...r.splice(s,1))}),i.concat(r)},this.#o=e=>{let n=e?.marks,r=0;for(;rs.eq(i)))r++;else break}for(let i=this.#t.length-1;i>=r;i--)this.#f(this.#t[i].mark)},this.#i=(e,n)=>{this.#s(e.marks).every(r=>!this.#n(r,e))&&this.#r(e),this.#o(n)},this.#a=e=>{let{children:n}=e;return n&&(e.children=n.reduce((r,i,o)=>{if(o===0)return[i];let s=r.at(-1);if(s&&s.isMark&&i.isMark){let{children:a,...l}=i,{children:c,...u}=s;if(i.type===s.type&&a&&c&&JSON.stringify(l)===JSON.stringify(u)){let f={...u,children:[...c,...a]};return r.slice(0,-1).concat(this.#a(f))}}return r.concat(i)},[])),e},this.#l=e=>{let n={...e.props,type:e.type};return e.children&&(n.children=e.children),e.value&&(n.value=e.value),n},this.openNode=(e,n,r)=>(this.open(Gg.create(e,void 0,n,r)),this),this.#d=(e,n)=>{let r="",i="",o=e.children;if(o){let a=o[0],l=o.at(-1);if(l&&l.type==="text"&&l.value.endsWith(" ")){let c=l.value,u=c.trimEnd();i=c.slice(u.length),l.value=u}if(a&&a.type==="text"&&a.value.startsWith(" ")){let c=a.value,u=c.trimStart();r=c.slice(0,c.length-u.length),a.value=u}}r.length&&this.#u("text",void 0,r);let s=n();return i.length&&this.#u("text",void 0,i),s},this.#c=(e=!1)=>{let n=this.close(),r=()=>this.#u(n.type,n.children,n.value,n.props);return e?this.#d(n,r):r()},this.closeNode=()=>(this.#c(),this),this.#u=(e,n,r,i)=>{let o=Gg.create(e,n,r,i),s=this.#a(this.#l(o));return this.push(s),s},this.addNode=(e,n,r,i)=>(this.#u(e,n,r,i),this),this.#p=(e,n,r,i)=>this.#t.some(o=>o.mark.eq(e))?this:(this.#t.push({mark:e,spanning:r==null}),this.openNode(n,r,{...i,isMark:!0})),this.#f=e=>{let n=-1;for(let r=this.#t.length-1;r>=0;r--)if(this.#t[r].mark.eq(e)){n=r;break}n<0||(this.#t.splice(n,1),this.#c(!0))},this.withMark=(e,n,r,i)=>(this.#p(e,n,r,i),this),this.closeMark=e=>(this.#f(e),this),this.build=()=>{let e=null;do e=this.#c();while(this.size());return e},this.next=e=>LE(e)?(e.forEach((n,r,i)=>{this.#i(n,e.maybeChild(i+1)??void 0)}),this):(this.#i(e),this),this.toString=e=>e.stringify(this.build()),this.run=e=>(this.#t=[],this.next(e),this),this.schema=t}#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f};var ze=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},ki=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},hu=null,un=function(t,e,n){let r=hu||(hu=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},BE=function(){hu=null},Ar=function(t,e,n,r){return n&&(ny(t,e,n,r,-1)||ny(t,e,n,r,1))},PE=/^(img|br|input|textarea|hr)$/i;function ny(t,e,n,r,i){for(var o;;){if(t==n&&e==r)return!0;if(e==(i<0?0:St(t))){let s=t.parentNode;if(!s||s.nodeType!=1||Po(t)||PE.test(t.nodeName)||t.contentEditable=="false")return!1;e=ze(t)+(i<0?0:1),t=s}else if(t.nodeType==1){let s=t.childNodes[e+(i<0?-1:0)];if(s.nodeType==1&&s.contentEditable=="false")if(!((o=s.pmViewDesc)===null||o===void 0)&&o.ignoreForSelection)e+=i;else return!1;else t=s,e=i<0?St(t):0}else return!1}}function St(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function FE(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=St(t)}else if(t.parentNode&&!Po(t))e=ze(t),t=t.parentNode;else return null}}function zE(t,e){for(;;){if(t.nodeType==3&&e2),Ct=bi||(jt?/Mac/.test(jt.platform):!1),Ly=jt?/Win/.test(jt.platform):!1,fn=/Android \d/.test(Hn),Fo=!!ry&&"webkitFontSmoothing"in ry.documentElement.style,WE=Fo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function jE(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function cn(t,e){return typeof t=="number"?t:t[e]}function VE(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function iy(t,e,n){if(!ku(e)&&e.left==0)return;let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;){if(s.nodeType!=1){s=ki(s);continue}let a=s,l=a==o.body,c=l?jE(o):VE(a),u=0,f=0;if(e.topc.bottom-cn(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+cn(i,"top")-c.top:e.bottom-c.bottom+cn(i,"bottom")),e.leftc.right-cn(r,"right")&&(u=e.right-c.right+cn(i,"right")),u||f)if(l)o.defaultView.scrollBy(u,f);else{let p=a.scrollLeft,h=a.scrollTop;f&&(a.scrollTop+=f),u&&(a.scrollLeft+=u);let m=a.scrollLeft-p,g=a.scrollTop-h;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=l?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:ki(s)}}function qE(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s=n-20){r=a,i=l.top;break}}return{refDOM:r,refTop:i,stack:By(t.dom)}}function By(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=ki(r));return e}function KE({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Py(n,r==0?0:r-e)}function Py(t,e){for(let n=0;n=a){s=Math.max(h.bottom,s),a=Math.min(h.top,a);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!l&&h.left<=e.left&&h.right>=e.left&&(l=u,c={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!n&&l&&(n=l,i=c,r=0),n&&n.nodeType==3?JE(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Fy(n,i)}function JE(t,e){let n=t.nodeValue.length,r=document.createRange(),i;for(let o=0;o=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}function Lu(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function GE(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function YE(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let a=t.docView.nearestDesc(o,!0),l;if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)&&((l=a.dom.getBoundingClientRect()).width||l.height)&&(a.node.isBlock&&a.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(a.dom.nodeName)&&(!s&&l.left>r.left||l.top>r.top?i=a.posBefore:(!s&&l.right-1?i:t.docView.posFromDOM(e,n,-1)}function zy(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let c;Fo&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(a=YE(t,r,i,e))}a==null&&(a=XE(t,s,e));let l=t.docView.nearestDesc(s,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function ku(t){return t.top=0&&i==r.nodeValue.length?(l--,u=1):n<0?l--:c++,Io(Fn(un(r,l,c),u),u<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==St(r))){let l=r.childNodes[i-1];if(l.nodeType==1)return cu(l.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==St(r))){let l=r.childNodes[i-1],c=l.nodeType==3?un(l,St(l)-(s?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return Io(Fn(c,1),!1)}if(o==null&&i=0)}function Io(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function cu(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function _y(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function eT(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return _y(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(o,!0);if(!a)break;if(a.node.isBlock){o=a.contentDOM||a.dom;break}o=a.dom.parentNode}let s=$y(t,i.pos,1);for(let a=o.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=un(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;cu.top+1&&(n=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var tT=/[\u0590-\u08ac]/;function nT(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,a=t.domSelection();return a?!tT.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?o:s:_y(t,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:u,anchorOffset:f}=t.domSelectionRange(),d=a.caretBidiLevel;a.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||l==h&&c==m;try{a.collapse(u,f),l&&(l!=u||c!=f)&&a.extend&&a.extend(l,c)}catch{}return d!=null&&(a.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var oy=null,sy=null,ay=!1;function rT(t,e,n){return oy==e&&sy==n?ay:(oy=e,sy=n,ay=n=="up"||n=="down"?eT(t,e,n):nT(t,e,n))}var Et=0,ly=1,Cr=2,Ot=3,Ir=class{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=Et,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nze(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof xa){i=e-o;break}o=a}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof ka&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?ze(o.dom)+1:0}}else{let o,s=!0;for(;o=r=u&&n<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,n,u);e=s;for(let f=a;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ze(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>n||a==this.children.length-1)){n=c;for(let u=a+1;uh&&sn){let h=a;a=l,l=h}let p=document.createRange();p.setEnd(l.node,l.offset),p.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let a=r+o.border,l=s-o.border;if(e>=a&&n<=l){this.dirty=e==r||n==s?Cr:ly,e==a&&n==l&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ot:o.markDirty(e-a,n-a);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Cr:Ot}r=s}this.dirty=Cr}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Cr:ly;n.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let a=document.createElement("span");a.appendChild(s),s=a}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==Et&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},bu=class extends Ir{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Mr=class t extends Ir{constructor(e,n,r,i,o){super(e,[],r,i),this.mark=n,this.spec=o}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=wt.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new t(e,n,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&Ot||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ot&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=Et){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Su(o,0,e,r));for(let a=0;a{if(!l)return s;if(l.parent)return l.parent.posBeforeChild(l)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=wt.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),n.type.spec.draggable&&(u.draggable=!0));let d=u;return u=jy(u,r,n),c?l=new xu(e,n,r,i,u,f||null,d,c):n.isText?new ba(e,n,r,i,u,d):new t(e,n,r,i,u,f||null,d)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>M.empty)}return e}matchesNode(e,n,r){return this.dirty==Et&&e.eq(this.node)&&wa(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,a=o&&o.pos<0,l=new Cu(this,s&&s.node,e);aT(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&l.syncToMarks(u==this.node.childCount?ne.none:this.node.child(u).marks,r,e,u),l.placeWidget(c,e,i)},(c,u,f,d)=>{l.syncToMarks(c.marks,r,e,d);let p;l.findNodeMatch(c,u,f,d)||a&&e.state.selection.from>i&&e.state.selection.to-1&&l.updateNodeAt(c,u,f,p,e)||l.updateNextNode(c,u,f,e,d,i)||l.addNode(c,u,f,e,i),i+=c.nodeSize}),l.syncToMarks([],r,e,0),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==Cr)&&(s&&this.protectLocalComposition(e,s),Hy(this.contentDOM,this.children,e),bi&&lT(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof P)||rn+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,a=cT(this.node.content,s,r-n,i-n);return a<0?null:{node:o,pos:a,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new bu(this,o,n,i);e.input.compositionNodes.push(s),this.children=Su(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==Ot||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Et}updateOuterDeco(e){if(wa(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Wy(this.dom,this.nodeDOM,wu(this.outerDeco,this.node,n),wu(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function cy(t,e,n,r,i){jy(r,e,t);let o=new _n(void 0,t,e,n,r,r,r);return o.contentDOM&&o.updateChildren(i,0),o}var ba=class t extends _n{constructor(e,n,r,i,o,s){super(e,n,r,i,o,null,s)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Ot||this.dirty!=Et&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=Et||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Et,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new t(this.parent,i,this.outerDeco,this.innerDeco,o,o)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Ot)}get domAtom(){return!1}isText(e){return this.node.text==e}},xa=class extends Ir{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Et&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},xu=class extends _n{constructor(e,n,r,i,o,s,a,l){super(e,n,r,i,o,s,a),this.spec=l}update(e,n,r,i){if(this.dirty==Ot)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Hy(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o>1,a=Math.min(s,e.length);for(;o-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let u=Mr.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let a=this.index,l=Math.min(this.top.children.length,a+5);a0;){let a;for(;;)if(r){let c=n.children[r-1];if(c instanceof Mr)n=c,r=c.children.length;else{a=c,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=t.child(i-1))break;--i,o.set(a,i),s.push(a)}}return{index:i,matched:o,matches:s.reverse()}}function sT(t,e){return t.type.side-e.type.side}function aT(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let c=0;co;)a.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let g=h;s!g.inline):a.slice();r(d,m,e.forChild(o,d),p),o=h}}function lT(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function cT(t,e,n,r){for(let i=0,o=0;i=n){if(o>=r&&l.slice(r-e.length-a,r-a)==e)return r-e.length;let c=a=0&&c+e.length+a>=n)return a+c;if(n==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}function Su(t,e,n,r,i){let o=[];for(let s=0,a=0;s=n||u<=e?o.push(l):(cn&&o.push(l.slice(n-c,l.size,r)))}return o}function Bu(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a=r.resolve(s),l,c;if(Ia(n)){for(l=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&H.isSelectable(f)&&i.parent&&!(f.isInline&&$E(n.focusNode,n.focusOffset,i.dom))){let d=i.posBefore;c=new H(s==d?a:r.resolve(d))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=s,d=s;for(let p=0;p{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Vy(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function fT(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,ze(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&rt&&$n<=11&&(n.disabled=!0,n.disabled=!1)}function qy(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(hy(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else hy(t)}function hy(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Pu(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||P.between(e,n,r)}function my(t){return t.editable&&!t.hasFocus()?!1:Ky(t)}function Ky(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function dT(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Ar(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Mu(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&_.findFrom(o,e)}function zn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function gy(t,e,n){let r=t.state.selection;if(r instanceof P)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return zn(t,new P(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=Mu(t.state,e);return i&&i instanceof H?zn(t,i):!1}else if(!(Ct&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let a=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(a))&&!s.contentDOM?H.isSelectable(o)?zn(t,new H(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):Fo?zn(t,new P(t.state.doc.resolve(e<0?a:a+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof H&&r.node.isInline)return zn(t,new P(e>0?r.$to:r.$from));{let i=Mu(t.state,e);return i?zn(t,i):!1}}}function Ca(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Ro(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function gi(t,e){return e<0?pT(t):hT(t)}function pT(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(Mt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(Ro(a,-1))i=n,o=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if(Uy(n))break;{let a=n.previousSibling;for(;a&&Ro(a,-1);)i=n.parentNode,o=ze(a),a=a.previousSibling;if(a)n=a,r=Ca(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?Eu(t,n,r):i&&Eu(t,i,o)}function hT(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Ca(n),o,s;for(;;)if(r{t.state==i&&pn(t)},50)}function yy(t,e){let n=t.state.doc.resolve(e);if(!(Ne||Ly)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function ky(t,e,n){let r=t.state.selection;if(r instanceof P&&!r.empty||n.indexOf("s")>-1||Ct&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=Mu(t.state,e);if(s&&s instanceof H)return zn(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,a=r instanceof pt?_.near(s,e):_.findFrom(s,e);return a?zn(t,a):!1}return!1}function by(t,e){if(!(t.state.selection instanceof P))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function xy(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function yT(t){if(!Je||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;xy(t,r,"true"),setTimeout(()=>xy(t,r,"false"),20)}return!1}function kT(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function bT(t,e){let n=e.keyCode,r=kT(e);if(n==8||Ct&&n==72&&r=="c")return by(t,-1)||gi(t,-1);if(n==46&&!e.shiftKey||Ct&&n==68&&r=="c")return by(t,1)||gi(t,1);if(n==13||n==27)return!0;if(n==37||Ct&&n==66&&r=="c"){let i=n==37?yy(t,t.state.selection.from)=="ltr"?-1:1:-1;return gy(t,i,r)||gi(t,i)}else if(n==39||Ct&&n==70&&r=="c"){let i=n==39?yy(t,t.state.selection.from)=="ltr"?1:-1:1;return gy(t,i,r)||gi(t,i)}else{if(n==38||Ct&&n==80&&r=="c")return ky(t,-1,r)||gi(t,-1);if(n==40||Ct&&n==78&&r=="c")return yT(t)||ky(t,1,r)||gi(t,1);if(r==(Ct?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function Fu(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=t.someProp("clipboardSerializer")||wt.fromSchema(t.state.schema),a=Zy(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c=l.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Qy[c.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let h=a.createElement(u[p]);for(;l.firstChild;)h.appendChild(l.firstChild);l.appendChild(h),f++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(n)}`);let d=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,` +`),i;function o(s){return r.stack.push(s),a;function a(){r.stack.pop()}}}function _S(t){throw new Error("Cannot handle value `"+t+"`, expected node")}function HS(t){let e=t;throw new Error("Cannot handle unknown node `"+e.type+"`")}function WS(t,e){if(t.type==="definition"&&t.type===e.type)return 0}function jS(t,e){return cm(t,this,e)}function VS(t,e){return um(t,this,e)}function qS(t,e){return pm(this,t,e)}function ii(t){let e=this;e.compiler=n;function n(r){return kc(r,{...e.data("settings"),...t,extensions:e.data("toMarkdownExtensions")||[]})}}function bc(t){if(t)throw t}var Zs=z1(Sm(),1);function fo(t){if(typeof t!="object"||t===null)return!1;let e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function xc(){let t=[],e={run:n,use:r};return e;function n(...i){let o=-1,s=i.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);a(null,...i);function a(l,...c){let u=t[++o],f=-1;if(l){s(l);return}for(;++fs.length,l;a&&s.push(i);try{l=t.apply(this,s)}catch(c){let u=c;if(a&&n)throw u;return i(u)}a||(l&&l.then&&typeof l.then=="function"?l.then(o,i):l instanceof Error?i(l):o(l))}function i(s,...a){n||(n=!0,e(s,...a))}function o(s){i(null,s)}}var Ae=class extends Error{constructor(e,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",o={},s=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let l=r.indexOf(":");l===-1?o.ruleId=r:(o.source=r.slice(0,l),o.ruleId=r.slice(l+1))}if(!o.place&&o.ancestors&&o.ancestors){let l=o.ancestors[o.ancestors.length-1];l&&(o.place=l.position)}let a=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=An(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};Ae.prototype.file="";Ae.prototype.name="";Ae.prototype.reason="";Ae.prototype.message="";Ae.prototype.stack="";Ae.prototype.column=void 0;Ae.prototype.line=void 0;Ae.prototype.ancestors=void 0;Ae.prototype.cause=void 0;Ae.prototype.fatal=void 0;Ae.prototype.place=void 0;Ae.prototype.ruleId=void 0;Ae.prototype.source=void 0;var Rt={basename:KS,dirname:US,extname:JS,join:GS,sep:"/"};function KS(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');po(t);let n=0,r=-1,i=t.length,o;if(e===void 0||e.length===0||e.length>t.length){for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":t.slice(n,r)}if(e===t)return"";let s=-1,a=e.length-1;for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else s<0&&(o=!0,s=i+1),a>-1&&(t.codePointAt(i)===e.codePointAt(a--)?a<0&&(r=i):(a=-1,r=s));return n===r?r=s:r<0&&(r=t.length),t.slice(n,r)}function US(t){if(po(t),t.length===0)return".";let e=-1,n=t.length,r;for(;--n;)if(t.codePointAt(n)===47){if(r){e=n;break}}else r||(r=!0);return e<0?t.codePointAt(0)===47?"/":".":e===1&&t.codePointAt(0)===47?"//":t.slice(0,e)}function JS(t){po(t);let e=t.length,n=-1,r=0,i=-1,o=0,s;for(;e--;){let a=t.codePointAt(e);if(a===47){if(s){r=e+1;break}continue}n<0&&(s=!0,n=e+1),a===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||n<0||o===0||o===1&&i===n-1&&i===r+1?"":t.slice(i,n)}function GS(...t){let e=-1,n;for(;++e0&&t.codePointAt(t.length-1)===47&&(n+="/"),e?"/"+n:n}function YS(t,e){let n="",r=0,i=-1,o=0,s=-1,a,l;for(;++s<=t.length;){if(s2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=s,o=0;continue}}else if(n.length>0){n="",r=0,i=s,o=0;continue}}e&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+t.slice(i+1,s):n=t.slice(i+1,s),r=s-i-1;i=s,o=0}else a===46&&o>-1?o++:o=-1}return n}function po(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}var Em={cwd:QS};function QS(){return"/"}function oi(t){return!!(t!==null&&typeof t=="object"&&"href"in t&&t.href&&"protocol"in t&&t.protocol&&t.auth===void 0)}function Tm(t){if(typeof t=="string")t=new URL(t);else if(!oi(t)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+t+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(t.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return ZS(t)}function ZS(t){if(t.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=t.pathname,n=-1;for(;++n0){let[p,...h]=u,m=r[d][1];fo(m)&&fo(p)&&(p=(0,Zs.default)(!0,m,p)),r[d]=[c,p,...h]}}}},mo=new vc().freeze();function Mc(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `parser`")}function Ec(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `compiler`")}function Tc(t,e){if(e)throw new Error("Cannot call `"+t+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Im(t){if(!fo(t)||typeof t.type!="string")throw new TypeError("Expected node, got `"+t+"`")}function Nm(t,e,n){if(!n)throw new Error("`"+t+"` finished async. Use `"+e+"` instead")}function Qs(t){return nM(t)?t:new ho(t)}function nM(t){return!!(t&&typeof t=="object"&&"message"in t&&"messages"in t)}function rM(t){return typeof t=="string"||iM(t)}function iM(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}function Ke(t){this.content=t}Ke.prototype={constructor:Ke,find:function(t){for(var e=0;e>1}};Ke.from=function(t){if(t instanceof Ke)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ke(e)};var Ac=Ke;function _m(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){let s=i.text,a=o.text,l=0;for(;s[l]==a[l];l++)n++;return l&&l0&&d>0&&c[f-1]==u[d-1];)f--,d--,n--,r--;return f&&d&&f=56320&&t<57344}function jm(t){return t>=55296&&t<56320}var M=class t{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;re&&r(l,i+a,o||null,s)!==!1&&l.content.size){let u=a+1;l.nodesBetween(Math.max(0,e-u),Math.min(l.content.size,n-u),r,i+u)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(a,l)=>{let c=a.isText?a.text.slice(Math.max(e,l)-l,n-l):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&c||a.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);oe)for(let o=0,s=0;se&&((sn)&&(a.isText?a=a.cut(Math.max(0,e-s),Math.min(a.text.length,n-s)):a=a.cut(Math.max(0,e-s-1),Math.min(a.content.size,n-s-1))),r.push(a),i+=a.nodeSize),s=l}return new t(r,i)}cutByIndex(e,n){return e==n?t.empty:e==0&&n==this.content.length?this:new t(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new t(i,o)}addToStart(e){return new t([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new t(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),o=r+i.nodeSize;if(o>=e)return o==e?ea(n+1,o):ea(n,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return t.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return t.fromArray(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return t.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};ne.none=[];var Rn=class extends Error{},R=class t{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=qm(this.content,e+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new t(r,this.openStart,this.openEnd)}removeBetween(e,n){return new t(Vm(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return t.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new t(M.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new t(e,r,i)}};R.empty=new R(M.empty,0,0);function Vm(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:a}=t.findIndex(n);if(i==e||o.isText){if(a!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(Vm(o.content,e-i-1,n-i-1)))}function qm(t,e,n,r,i,o){let{index:s,offset:a}=t.findIndex(e),l=t.maybeChild(s);if(a==e||l.isText)return o&&r<=0&&i<=0&&!o.canReplace(s,s,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=qm(l.content,e-a-1,n,s==0?r-1:0,s==t.childCount-1?i-1:0,l);return c&&t.replaceChild(s,l.copy(c))}function oM(t,e,n){if(n.openStart>t.depth)throw new Rn("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Rn("Inconsistent open depths");return Km(t,e,n,0)}function Km(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function go(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(ur(t.nodeAfter,r),o++));for(let a=o;ai&&Nc(t,e,i+1),s=r.depth>i&&Nc(n,r,i+1),a=[];return go(null,t,i,a),o&&s&&e.index(i)==n.index(i)?(Um(o,s),ur(fr(o,Jm(t,e,n,r,i+1)),a)):(o&&ur(fr(o,ia(t,e,i+1)),a),go(e,n,i,a),s&&ur(fr(s,ia(n,r,i+1)),a)),go(r,null,i,a),new M(a)}function ia(t,e,n){let r=[];if(go(null,t,n,r),t.depth>n){let i=Nc(t,e,n+1);ur(fr(i,ia(t,e,n+1)),r)}return go(e,null,n,r),new M(r)}function sM(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(M.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}var oa=class t{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new ko(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:a,offset:l}=s.content.findIndex(o),c=o-l;if(r.push(s,a,i+l),!c||(s=s.child(a),s.isText))break;o=c-1,i+=l+1}return new t(n,r,o)}static resolveCached(e,n){let r=Rm.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Gm(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=M.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),a=s&&s.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let l=i;ln.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=M.fromJSON(e,n.content),o=e.nodeType(n.type).create(n.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};nt.prototype.text=void 0;var Oc=class t extends nt{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Gm(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new t(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new t(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Gm(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}var dr=class t{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new Dc(e,n);if(r.next==null)return t.empty;let i=Xm(r);r.next&&r.err("Unexpected trailing text");let o=mM(hM(i));return gM(o,r),o}matchType(e){for(let n=0;nc.createAndFill()));for(let c=0;c=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}};dr.empty=new dr(!0);var Dc=class{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Xm(t){let e=[];do e.push(cM(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function cM(t){let e=[];do e.push(uM(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function uM(t){let e=pM(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=fM(t,e);else break;return e}function Om(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function fM(t,e){let n=Om(t),r=n;return t.eat(",")&&(t.next!="}"?r=Om(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function dM(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function pM(t){if(t.eat("(")){let e=Xm(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=dM(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function hM(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,a,l){let c={term:l,to:a};return e[s].push(c),c}function i(s,a){s.forEach(l=>l.to=a)}function o(s,a){if(s.type=="choice")return s.exprs.reduce((l,c)=>l.concat(o(c,a)),[]);if(s.type=="seq")for(let l=0;;l++){let c=o(s.exprs[l],a);if(l==s.exprs.length-1)return c;i(c,a=n())}else if(s.type=="star"){let l=n();return r(a,l),i(o(s.expr,l),l),[r(l)]}else if(s.type=="plus"){let l=n();return i(o(s.expr,a),l),i(o(s.expr,l),l),[r(l)]}else{if(s.type=="opt")return[r(a)].concat(o(s.expr,a));if(s.type=="range"){let l=a;for(let c=0;c{t[s].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let u=0;u{c||i.push([a,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let o=e[r.join(",")]=new dr(r.indexOf(t.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Zm(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new nt(this,this.computeAttrs(e),M.from(n),ne.setFrom(r))}createChecked(e=null,n,r){return n=M.from(n),this.checkContent(n),new nt(this,this.computeAttrs(e),n,ne.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=M.from(n),n.size){let s=this.contentMatch.fillBefore(n);if(!s)return null;n=s.append(n)}let i=this.contentMatch.matchFragment(n),o=i&&i.fillBefore(M.empty,!0);return o?new nt(this,e,n.append(o),ne.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[o]=new t(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function yM(t,e,n){let r=n.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${o}`)}}var Lc=class{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?yM(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}},xo=class t{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=tg(e,i.attrs),this.excluded=null;let o=Qm(this.attrs);this.instance=o?new ne(this,o):null}create(e=null){return!e&&this.instance?this.instance:new ne(this,Zm(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new t(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}},sa=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=Ac.from(e.nodes),n.marks=Ac.from(e.marks||{}),this.nodes=bo.compile(this.spec.nodes,this),this.marks=xo.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",a=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=dr.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=a=="_"?null:a?Lm(this,a.split(" ")):a==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Lm(this,s.split(" "))}this.nodeFromJSON=i=>nt.fromJSON(this,i),this.markFromJSON=i=>ne.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof bo){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new Oc(r,r.defaultAttrs,e,ne.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}};function Lm(t,e){let n=[];for(let r=0;r-1)&&n.push(s=l)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function kM(t){return t.tag!=null}function bM(t){return t.style!=null}var xt=class t{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(kM(i))this.tags.push(i);else if(bM(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,n={}){let r=new aa(this,n,!1);return r.addAll(e,ne.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new aa(this,n,!0);return r.addAll(e,ne.none,n.from,n.to),R.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(s.getAttrs){let l=s.getAttrs(n);if(l===!1)continue;s.attrs=l||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Pm(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Pm(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new t(e,t.schemaRules(e)))}},ng={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},xM={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},rg={ol:!0,ul:!0},wo=1,Bc=2,yo=4;function Bm(t,e,n){return e!=null?(e?wo:0)|(e==="full"?Bc:0):t&&t.whitespace=="pre"?wo|Bc:n&~yo}var si=class{constructor(e,n,r,i,o,s){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=ne.none,this.match=o||(s&yo?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(M.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&wo)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=M.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(M.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!ng.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},aa=class{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,o,s=Bm(null,n.preserveWhitespace,0)|(r?yo:0);i?o=new si(i.type,i.attrs,ne.none,!0,n.topMatch||i.type.contentMatch,s):r?o=new si(null,null,ne.none,!0,null,s):o=new si(e.schema.topNodeType,null,ne.none,!0,null,s),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,o=i.options&Bc?"full":this.localPreserveWS||(i.options&wo)>0,{schema:s}=this.parser;if(o==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)if(o==="full")r=r.replace(/\r\n?/g,` +`);else if(s.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(s.linebreakReplacement.create())){let a=r.split(/\r?\n|\r/);for(let l=0;l!l.clearMark(c)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return n}addElementByRule(e,n,r,i){let o,s;if(n.node)if(s=this.parser.schema.nodes[n.node],s.isLeaf)this.insertNode(s.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(s,n.attrs||null,r,n.preserveWhitespace);l&&(o=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let a=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}o&&this.sync(a)&&this.open--}addAll(e,n,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,a=i==null?null:e.childNodes[i];s!=a;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,n);this.findAtPoint(e,o)}findPlace(e,n,r){let i,o;for(let s=this.open,a=0;s>=0;s--){let l=this.nodes[s],c=l.findWrapping(e);if(c&&(!i||i.length>c.length+a)&&(i=c,o=l,!c.length))break;if(l.solid){if(r)break;a+=2}}if(!i)return null;this.sync(o);for(let s=0;s(s.type?s.type.allowsMarkType(c.type):Fm(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new si(e,n,l,i,null,a)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=wo)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(a,l)=>{for(;a>=0;a--){let c=n[a];if(c==""){if(a==n.length-1||a==0)continue;for(;l>=o;l--)if(s(a-1,l))return!0;return!1}else{let u=l>0||l==0&&i?this.nodes[l].type:r&&l>=o?r.node(l-o).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;l--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}};function wM(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&rg.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function CM(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Pm(t){let e={};for(let n in t)e[n]=t[n];return e}function Fm(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=a=>{o.push(a);for(let l=0;l{if(o.length||s.marks.length){let a=0,l=0;for(;a=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&na(ta(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return typeof n=="string"?{dom:e.createTextNode(n)}:na(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new t(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=zm(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return zm(e.marks)}};function zm(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function ta(t){return t.document||window.document}var $m=new WeakMap;function SM(t){let e=$m.get(t);return e===void 0&&$m.set(t,e=MM(t)),e}function MM(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let a,l=n?t.createElementNS(n,i):t.createElement(i),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let f in c)if(c[f]!=null){let d=f.indexOf(" ");d>0?l.setAttributeNS(f.slice(0,d),f.slice(d+1),c[f]):f=="style"&&l.style?l.style.cssText=c[f]:l.setAttribute(f,c[f])}}for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else if(typeof d=="string")l.appendChild(t.createTextNode(d));else{let{dom:p,contentDOM:h}=na(t,d,n,r);if(l.appendChild(p),h){if(a)throw new RangeError("Multiple content holes");a=h}}}return{dom:l,contentDOM:a}}var sg=65535,ag=Math.pow(2,16);function EM(t,e){return t+e*ag}function ig(t){return t&sg}function TM(t){return(t-(t&sg))/ag}var lg=1,cg=2,la=4,ug=8,Mo=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&ug)>0}get deletedBefore(){return(this.delInfo&(lg|la))>0}get deletedAfter(){return(this.delInfo&(cg|la))>0}get deletedAcross(){return(this.delInfo&la)>0}},on=class t{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&t.empty)return t.empty}recover(e){let n=0,r=ig(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[a+o],u=this.ranges[a+s],f=l+c;if(e<=f){let d=c?e==l?-1:e==f?1:n:n,p=l+i+(d<0?0:u);if(r)return p;let h=e==(n<0?l:f)?null:EM(a/3,e-l),m=e==l?cg:e==f?lg:la;return(n<0?e!=l:e!=f)&&(m|=ug),new Mo(p,m,h)}i+=u-c}return r?e+i:new Mo(e+i,0,null)}touches(e,n){let r=0,i=ig(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;ae)break;let c=this.ranges[a+o],u=l+c;if(e<=u&&a==i*3)return!0;r+=this.ranges[a+s]-c}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new t;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&l!s.isAtom||!a.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Pe.fromReplace(e,this.from,this.to,o)}invert(){return new hr(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};Ie.jsonID("addMark",pr);var hr=class t extends Ie{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new R(Hc(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Pe.fromReplace(e,this.from,this.to,r)}invert(){return new pr(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};Ie.jsonID("removeMark",hr);var To=class t extends Ie{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Pe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Pe.fromReplace(e,this.pos,this.pos+1,new R(M.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new t(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new t(n.from,n.to,n.gapFrom,n.gapTo,R.fromJSON(e,n.slice),n.insert,!!n.structure)}};Ie.jsonID("replaceAround",Fe);function $c(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function vM(t,e,n,r){let i=[],o=[],s,a;t.doc.nodesBetween(e,n,(l,c,u)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+l.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(l)),o.forEach(l=>t.step(l))}function AM(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,a)=>{if(!s.isInline)return;o++;let l=null;if(r instanceof xo){let c=s.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(s.marks)&&(l=[r]):l=s.marks;if(l&&l.length){let c=Math.min(a+s.nodeSize,n);for(let u=0;ut.step(new hr(s.from,s.to,s.style)))}function Wc(t,e,n,r=n.contentMatch,i=!0){let o=t.doc.nodeAt(e),s=[],a=e+1;for(let l=0;l=0;l--)t.step(s[l])}function IM(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function mr(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,o=0;;--r){let s=t.$from.node(r),a=t.$from.index(r)+i,l=t.$to.indexAfter(r)-o;if(rn;h--)m||r.index(h)>0?(m=!0,u=M.from(r.node(h).copy(u)),f++):l--;let d=M.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)=0;s--){if(r.size){let a=n[s].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=M.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new Fe(i,o,i,o,new R(r,0,0),n.length,!0))}function LM(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,a)=>{let l=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,l)&&BM(t.doc,t.mapping.slice(o).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!h?c=!1:!p&&h&&(c=!0)}c===!1&&dg(t,s,a,o),Wc(t,t.mapping.slice(o).map(a,1),r,void 0,c===null);let u=t.mapping.slice(o),f=u.map(a,1),d=u.map(a+s.nodeSize,1);return t.step(new Fe(f,d,f+1,d-1,new R(M.from(r.create(l,null,s.marks)),0,0),1,!0)),c===!0&&fg(t,s,a,o),!1}})}function fg(t,e,n,r){e.forEach((i,o)=>{if(i.isText){let s,a=/\r?\n|\r/g;for(;s=a.exec(i.text);){let l=t.mapping.slice(r).map(n+1+o+s.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function dg(t,e,n,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(n+1+o);t.replaceWith(s,s+1,e.type.schema.text(` +`))}})}function BM(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function PM(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Fe(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new R(M.from(s),0,0),1,!0))}function yr(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,u=n-2;c>o;c--,u--){let f=i.node(c),d=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[u+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=r&&r[u]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(p))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function FM(t,e,n=1,r){let i=t.doc.resolve(e),o=M.empty,s=M.empty;for(let a=i.depth,l=i.depth-n,c=n-1;a>l;a--,c--){o=M.from(i.node(a).copy(o));let u=r&&r[c];s=M.from(u?u.type.create(u.attrs,s):i.node(a).copy(s))}t.step(new xe(e,e,new R(o.append(s),n,n),!0))}function kr(t,e){let n=t.resolve(e),r=n.index();return $M(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function zM(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o=0;s--){let a=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,l=r.index(s)+(a>0?1:0),c=r.node(s),u=!1;if(o==1)u=c.canReplace(l,l,i);else{let f=c.contentMatchAt(l).findWrapping(i.firstChild.type);u=f&&c.canReplaceWith(l,l,f[0])}if(u)return a==0?r.pos:a<0?r.before(s+1):r.after(s+1)}return null}function vo(t,e,n=e,r=R.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return hg(i,o,r)?new xe(e,n,r):new _c(i,o,r).fit()}function hg(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}var _c=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=M.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=M.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,a=i.depth;for(;s&&a&&o.childCount==1;)o=o.firstChild.content,s--,a--;let l=new R(o,s,a);return e>-1?new Fe(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new xe(r.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Fc(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],u,f=null;if(n==1&&(s?c.matchType(s.type)||(f=c.fillBefore(M.from(s),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:a,parent:o,inject:f};if(n==2&&s&&(u=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:a,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Fc(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new R(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Fc(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new R(Co(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new R(Co(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m1||l==0||m.content.size)&&(f=g,u.push(mg(m.mark(d.allowedMarks(m.marks)),c==1?l:0,c==a.childCount?p:-1)))}let h=c==a.childCount;h||(p=-1),this.placed=So(this.placed,n,M.from(u)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=a;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;a--){let{match:l,type:c}=this.frontier[a],u=zc(e,a,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=So(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=So(this.placed,this.depth,M.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(M.empty,!0);n.childCount&&(this.placed=So(this.placed,this.frontier.length,n))}};function Co(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Co(t.firstChild.content,e-1,n)))}function So(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(So(t.lastChild.content,e-1,n)))}function Fc(t,e){for(let n=0;n1&&(r=r.replaceChild(0,mg(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(M.empty,!0)))),t.copy(r)}function zc(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!WM(n,o.content,s)?a:null}function WM(t,e,n){for(let r=n;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?a=d:i.before(d)==p&&s.splice(1,0,-d)}let l=s.indexOf(a),c=[],u=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(c.push(h),p==r.openStart)break;d=h.content}for(let d=u-1;d>=0;d--){let p=c[d],h=jM(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(a)-1)))u=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+u+1)%(r.openStart+1),h=c[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function gg(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(M.empty,!0))}return t}function qM(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=HM(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new R(M.from(r),0,0))}function KM(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let s=r.sharedDepth(n),a=!1;for(let l=r.depth;l>s;l--)r.node(l).type.spec.isolating&&(a=!0);for(let l=i.depth;l>s;l--)i.node(l).type.spec.isolating&&(a=!0);if(!a){for(let l=r.depth;l>0&&e==r.start(l);l--)e=r.before(l);for(let l=i.depth;l>0&&n==i.start(l);l--)n=i.before(l);r=t.doc.resolve(e),i=t.doc.resolve(n)}}let o=yg(r,i);for(let s=0;s0&&(l||r.node(a-1).canReplace(r.index(a-1),i.indexAfter(a-1))))return t.delete(r.before(a),i.after(a))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return t.delete(r.before(s),n);t.delete(e,n)}function yg(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}var ca=class t extends Ie{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Pe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Pe.fromReplace(e,this.pos,this.pos+1,new R(M.from(i),0,n.isLeaf?0:1))}getMap(){return on.empty}invert(e){return new t(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new t(n.pos,n.attr,n.value)}};Ie.jsonID("attr",ca);var ua=class t extends Ie{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Pe.ok(r)}getMap(){return on.empty}invert(e){return new t(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new t(n.attr,n.value)}};Ie.jsonID("docAttr",ua);var li=class extends Error{};li=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};li.prototype=Object.create(Error.prototype);li.prototype.constructor=li;li.prototype.name="TransformError";var ci=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Eo}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new li(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r{e=Math.min(e,a),n=Math.max(n,l)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=R.empty){let i=vo(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new R(M.from(r),0,0))}delete(e,n){return this.replace(e,n,R.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return VM(this,e,n,r),this}replaceRangeWith(e,n,r){return qM(this,e,n,r),this}deleteRange(e,n){return KM(this,e,n),this}lift(e,n){return NM(this,e,n),this}join(e,n=1){return _M(this,e,n),this}wrap(e,n){return DM(this,e,n),this}setBlockType(e,n=e,r,i=null){return LM(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return PM(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new ca(e,n,r)),this}setDocAttribute(e,n){return this.step(new ua(e,n)),this}addNodeMark(e,n){return this.step(new To(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof ne)n.isInSet(r.marks)&&this.step(new ai(e,n));else{let i=r.marks,o,s=[];for(;o=n.isInSet(i);)s.push(new ai(e,o)),i=o.removeFromSet(i);for(let a=s.length-1;a>=0;a--)this.step(s[a])}return this}split(e,n=1,r){return FM(this,e,n,r),this}addMark(e,n,r){return vM(this,e,n,r),this}removeMark(e,n,r){return AM(this,e,n,r),this}clearIncompatible(e,n,r){return Wc(this,e,n,r),this}};var jc=Object.create(null),_=class{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new On(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;o--){let s=n<0?ui(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):ui(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new pt(e.node(0))}static atStart(e){return ui(e,e,0,0,1)||new pt(e)}static atEnd(e){return ui(e,e,e.content.size,e.childCount,-1)||new pt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=jc[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in jc)throw new RangeError("Duplicate use of selection JSON ID "+e);return jc[e]=n,n.prototype.jsonID=e,n}getBookmark(){return P.between(this.$anchor,this.$head).getBookmark()}};_.prototype.visible=!0;var On=class{constructor(e,n){this.$from=e,this.$to=n}},kg=!1;function bg(t){!kg&&!t.parent.inlineContent&&(kg=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}var P=class t extends _{constructor(e,n=e){bg(e),bg(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return _.near(r);let i=e.resolve(n.map(this.anchor));return new t(i.parent.inlineContent?i:r,r)}replace(e,n=R.empty){if(super.replace(e,n),n==R.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof t&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new da(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new t(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=_.findFrom(n,r,!0)||_.findFrom(n,-r,!0);if(o)n=o.$head;else return _.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(_.findFrom(e,-r,!0)||_.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let a=e.child(s);if(a.isAtom){if(!o&&H.isSelectable(a))return H.create(t,n-(i<0?a.nodeSize:0))}else{let l=ui(t,a,n+i,i<0?a.childCount:0,i,o);if(l)return l}n+=a.nodeSize*i}return null}function xg(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=u)}),t.setSelection(_.near(t.doc.resolve(s),n))}var wg=1,fa=2,Cg=4,Kc=class extends ci{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=fa,this}ensureMarks(e){return ne.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&fa)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~fa,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||ne.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(_.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Cg,this}get scrolledIntoView(){return(this.updated&Cg)>0}};function Sg(t,e){return!e||!t?t:t.bind(e)}var br=class{constructor(e,n,r){this.name=e,this.init=Sg(n.init,r),this.apply=Sg(n.apply,r)}},JM=[new br("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new br("selection",{init(t,e){return t.selection||_.atStart(e.doc)},apply(t){return t.selection}}),new br("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new br("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})],Ao=class{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=JM.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new br(r.key,r.spec.state,r))})}},fi=class t{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Ao(e.schema,e.plugins),o=new t(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=nt.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=_.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let l=r[a],c=l.spec.state;if(l.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){o[s.name]=c.fromJSON.call(l,e,n[a],o);return}}o[s.name]=s.init(e,o)}}),o}};function Mg(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Mg(i,e,{})),n[r]=i}return n}var X=class{constructor(e){this.spec=e,this.props={},e.props&&Mg(e.props,this,this.props),this.key=e.key?e.key.key:Eg("plugin")}getState(e){return e[this.key]}},Vc=Object.create(null);function Eg(t){return t in Vc?t+"$"+ ++Vc[t]:(Vc[t]=0,t+"$")}var ee=class{constructor(e="key"){this.key=Eg(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var pa=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function vg(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}var Jc=(t,e,n)=>{let r=vg(t,n);if(!r)return!1;let i=Xc(r);if(!i){let s=r.blockRange(),a=s&&mr(s);return a==null?!1:(e&&e(t.tr.lift(s,a).scrollIntoView()),!0)}let o=i.nodeBefore;if(Rg(t,i,e,-1))return!0;if(r.parent.content.size==0&&(di(o,"end")||H.isSelectable(o)))for(let s=r.depth;;s--){let a=vo(t.doc,r.before(s),r.after(s),R.empty);if(a&&a.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1},Ag=(t,e,n)=>{let r=vg(t,n);if(!r)return!1;let i=Xc(r);return i?GM(t,i,e):!1};function GM(t,e,n){let r=e.nodeBefore,i=r,o=e.pos-1;for(;!i.isTextblock;o--){if(i.type.spec.isolating)return!1;let u=i.lastChild;if(!u)return!1;i=u}let s=e.nodeAfter,a=s,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let u=a.firstChild;if(!u)return!1;a=u}let c=vo(t.doc,o,l,R.empty);if(!c||c.from!=o||c instanceof xe&&c.slice.size>=l-o)return!1;if(n){let u=t.tr.step(c);u.setSelection(P.create(u.doc,o)),n(u.scrollIntoView())}return!0}function di(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Gc=(t,e,n)=>{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;o=Xc(r)}let s=o&&o.nodeBefore;return!s||!H.isSelectable(s)?!1:(e&&e(t.tr.setSelection(H.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Xc(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function XM(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=XM(t,n);if(!r)return!1;let i=Ig(r);if(!i)return!1;let o=i.nodeAfter;if(Rg(t,i,e,1))return!0;if(r.parent.content.size==0&&(di(o,"start")||H.isSelectable(o))){let s=vo(t.doc,r.before(),r.after(),R.empty);if(s&&s.slice.size{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let{$from:n,$to:r}=t.selection,i=n.blockRange(r),o=i&&mr(i);return o==null?!1:(e&&e(t.tr.lift(i,o).scrollIntoView()),!0)},ZM=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` +`).scrollIntoView()),!0)};function Yc(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=Yc(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let a=n.after(),l=t.tr.replaceWith(a,a,s.createAndFill());l.setSelection(_.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},eE=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof pt||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Yc(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if(yr(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&mr(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function nE(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof H&&e.selection.node.isBlock)return!r.parentOffset||!yr(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,a,l=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){l=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),a=Yc(r.node(p-1).contentMatchAt(r.indexAfter(p-1)));let m=t&&t(i.parent,l,r);o.unshift(m||(l&&a?{type:a}:null)),s=p;break}else{if(p==1)return!1;o.unshift(null)}let u=e.tr;(e.selection instanceof P||e.selection instanceof pt)&&u.deleteSelection();let f=u.mapping.map(r.pos),d=yr(u.doc,f,o.length,o);if(d||(o[0]=a?{type:a}:null,d=yr(u.doc,f,o.length,o)),!d)return!1;if(u.split(f,o.length,o),!l&&c&&r.node(s).type!=a){let p=u.mapping.map(r.before(s)),h=u.doc.resolve(p);a&&r.node(s-1).canReplaceWith(h.index(),h.index()+1,a)&&u.setNodeMarkup(u.mapping.map(r.before(s)),a)}return n&&n(u.scrollIntoView()),!0}}var rE=nE();var iE=(t,e)=>(e&&e(t.tr.setSelection(new pt(t.doc))),!0);function oE(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||kr(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function Rg(t,e,n,r){let i=e.nodeBefore,o=e.nodeAfter,s,a,l=i.type.spec.isolating||o.type.spec.isolating;if(!l&&oE(t,e,n))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(s=(a=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&a.matchType(s[0]||o.type).validEnd){if(n){let p=e.pos+o.nodeSize,h=M.empty;for(let y=s.length-1;y>=0;y--)h=M.from(s[y].create(null,h));h=M.from(i.copy(h));let m=t.tr.step(new Fe(e.pos-1,p,e.pos,p,new R(h,1,0),s.length,!0)),g=m.doc.resolve(p+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&kr(m.doc,g.pos)&&m.join(g.pos),n(m.scrollIntoView())}return!0}let u=o.type.spec.isolating||r>0&&l?null:_.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),d=f&&mr(f);if(d!=null&&d>=e.depth)return n&&n(t.tr.lift(f,d).scrollIntoView()),!0;if(c&&di(o,"start",!0)&&di(i,"end")){let p=i,h=[];for(;h.push(p),!p.isTextblock;)p=p.lastChild;let m=o,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(n){let y=M.empty;for(let C=h.length-1;C>=0;C--)y=M.from(h[C].copy(y));let x=t.tr.step(new Fe(e.pos-h.length,e.pos+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new R(y,h.length,0),0,!0));n(x.scrollIntoView())}return!0}}return!1}function Og(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(n&&n(e.tr.setSelection(P.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}var sE=Og(-1),aE=Og(1);function pi(t,e=null){return function(n,r){let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=s&&gr(s,t,e);return a?(r&&r(n.tr.wrap(s,a).scrollIntoView()),!0):!1}}function Dn(t,e=null){return function(n,r){let i=!1;for(let o=0;o{if(i)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)i=!0;else{let u=n.doc.resolve(c),f=u.index();i=u.parent.canReplaceWith(f,f+1,t)}})}if(!i)return!1;if(r){let o=n.tr;for(let s=0;s{if(a||!r&&l.isAtom&&l.isInline&&c>=o.pos&&c+l.nodeSize<=s.pos)return!1;a=l.inlineContent&&l.type.allowsMarkType(n)}),a)return!0}return!1}function cE(t){let e=[];for(let n=0;n{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new On(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poss.doc.rangeHasMark(p.$from.pos,p.$to.pos,t)):f=!u.every(p=>{let h=!1;return d.doc.nodesBetween(p.$from.pos,p.$to.pos,(m,g,y)=>{if(h)return!1;h=!t.isInSet(m.marks)&&!!y&&y.type.allowsMarkType(t)&&!(m.isText&&/^\s*$/.test(m.textBetween(Math.max(0,p.$from.pos-g),Math.min(m.nodeSize,p.$to.pos-g))))}),!h});for(let p=0;p0&&(o=n[0].slice(s-a,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Bg=(t,e)=>{let n=t.plugins;for(let r=0;r=0;l--)s.step(a.steps[l].invert(a.docs[l]));if(o.text){let l=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,t.schema.text(o.text,l))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},C2=new be(/--$/,"\u2014",{inCodeMark:!1}),S2=new be(/\.\.\.$/,"\u2026",{inCodeMark:!1}),M2=new be(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),E2=new be(/"$/,"\u201D",{inCodeMark:!1}),T2=new be(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),v2=new be(/'$/,"\u2019",{inCodeMark:!1});function ha(t,e,n=null,r){return new be(t,(i,o,s,a)=>{let l=n instanceof Function?n(o):n,c=i.tr.delete(s,a),u=c.doc.resolve(s),f=u.blockRange(),d=f&&gr(f,e,l);if(!d)return null;c.wrap(f,d);let p=c.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&kr(c.doc,s-1)&&(!r||r(o,p))&&c.join(s-1),c})}function Zc(t,e,n=null){return new be(t,(r,i,o,s)=>{let a=r.doc.resolve(o),l=n instanceof Function?n(i):n;return a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,l):null})}var Bn=typeof navigator<"u"?navigator:null,Pg=typeof document<"u"?document:null,Pn=Bn&&Bn.userAgent||"",tu=/Edge\/(\d+)/.exec(Pn),_g=/MSIE \d/.exec(Pn),nu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Pn),iu=!!(_g||nu||tu),D2=_g?document.documentMode:nu?+nu[1]:tu?+tu[1]:0,dE=!iu&&/gecko\/(\d+)/i.test(Pn),L2=dE&&+(/Firefox\/(\d+)/.exec(Pn)||[0,0])[1],ru=!iu&&/Chrome\/(\d+)/.exec(Pn),pE=!!ru,B2=ru?+ru[1]:0,hE=!iu&&!!Bn&&/Apple Computer/.test(Bn.vendor),mE=hE&&(/Mobile\/\w+/.test(Pn)||!!Bn&&Bn.maxTouchPoints>2),P2=mE||(Bn?/Mac/.test(Bn.platform):!1),gE=/Android \d/.test(Pn),yE=!!Pg&&"webkitFontSmoothing"in Pg.documentElement.style,F2=yE?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function eu(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,a=s.doc.resolve(e);if(a.parent.type.spec.code)return!1;let l=a.parent.textBetween(Math.max(0,a.parentOffset-500),a.parentOffset,void 0,"\uFFFC")+r;for(let c of i){let u=c,f=u.match.exec(l),d=f&&f[0]&&u.handler(s,f,e-(f[0].length-r.length),n);if(d)return u.undoable!==!1&&d.setMeta(o,{transform:d,from:e,to:n,text:r}),t.dispatch(d),!0}return!1}var kE=new ee("MILKDOWN_CUSTOM_INPUTRULES");function Hg({rules:t}){let e=new X({key:kE,isInputRules:!0,state:{init(){return null},apply(n,r){let i=n.getMeta(this);return i||(n.selectionSet||n.docChanged?null:r)}},props:{handleTextInput(n,r,i,o){return eu(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>(setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&eu(n,r.pos,r.pos,"",t,e)}),!1),keydown:(n,r)=>!(gE&&pE&&r.key==="Enter")||n.composing?!1:n.someProp("handleKeyDown",i=>i(n,r))?(r.preventDefault(),!0):!1},handleKeyDown(n,r){if(r.key!=="Enter")return!1;let{$cursor:i}=n.state.selection;return i?eu(n,i.pos,i.pos,` +`,t,e):!1}}});return e}function an(t,e,n={}){return new be(t,(r,i,o,s)=>{var a,l,c,u;let{tr:f}=r,d=i.length,p=i[d-1],h=i[0],m=[],g,y={group:p,fullMatch:h,start:o,end:s},x=(a=n.updateCaptured)==null?void 0:a.call(n,y);if(Object.assign(y,x),{group:p,fullMatch:h,start:o,end:s}=y,h===null||p?.trim()==="")return null;if(p){let C=h.search(/\S/),v=o+h.indexOf(p),A=v+p.length;m=(l=f.storedMarks)!=null?l:[],Ao&&f.delete(o+C,v),g=o+C+p.length;let w=(c=n.getAttr)==null?void 0:c.call(n,i);f.addMark(o,g,e.create(w)),f.setStoredMarks(m),(u=n.beforeDispatch)==null||u.call(n,{match:i,start:o,end:s,tr:f})}return f})}function hi(t,e,n={}){return new be(t,(r,i,o,s)=>{var a,l,c;let{tr:u}=r,f=i[1],d=i[0],p={group:f,fullMatch:d,start:o,end:s},h=(a=n.updateCaptured)==null?void 0:a.call(n,p);if(Object.assign(p,h),{group:f,fullMatch:d,start:o,end:s}=p,d===null||!f||f.trim()==="")return null;let m=(l=n.getAttr)==null?void 0:l.call(n,i),g=e.createAndFill(m);return g&&(u.replaceRangeWith(e.isBlock?u.doc.resolve(o).before():o,s,g),(c=n.beforeDispatch)==null||c.call(n,{match:[d,f],start:o,end:s,tr:u})),u})}var bE=Object.defineProperty,xE=Object.defineProperties,wE=Object.getOwnPropertyDescriptors,Fg=Object.getOwnPropertySymbols,CE=Object.prototype.hasOwnProperty,SE=Object.prototype.propertyIsEnumerable,zg=(t,e,n)=>e in t?bE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ME=(t,e)=>{for(var n in e||(e={}))CE.call(e,n)&&zg(t,n,e[n]);if(Fg)for(var n of Fg(e))SE.call(e,n)&&zg(t,n,e[n]);return t},EE=(t,e)=>xE(t,wE(e));function $g(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Wg(t,e,n){let i=t.state.doc.content.size,o=$g(e,0,i),s=$g(n,0,i),a=t.coordsAtPos(o),l=t.coordsAtPos(s,-1),c=Math.min(a.top,l.top),u=Math.max(a.bottom,l.bottom),f=Math.min(a.left,l.left),d=Math.max(a.right,l.right),p=d-f,h=u-c,y={top:c,bottom:u,left:f,right:d,width:p,height:h,x:f,y:c};return EE(ME({},y),{toJSON:()=>y})}function ou(t){return Object.assign(Object.create(t),t).setTime(Date.now())}function TE(t,e){return Array.isArray(t)&&t.includes(e.type)||e.type===t}function ma(t){if(t.content.childCount===1){let e=t.content.firstChild;if(e?.type.name==="text"&&e.marks.length===0)return e;if(e?.type.name==="paragraph"&&e.childCount===1){let n=e.firstChild;if(n?.type.name==="text"&&n.marks.length===0)return n}}return!1}function vE(t){return e=>{for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r)){let i=e.before(n),o=e.after(n);return{from:i,to:o,node:r}}}}}function jg(t,e){return vE(n=>n.type===e)(t)}function Vg(t,e){let n=e.nodes[t];if(!n)throw sh("node",t);return n}function su(t){return e=>{for(let n=e.depth;n>0;n--){let r=e.node(n);if(t(r))return{pos:e.before(n),start:e.start(n),depth:n,node:r}}}}function qg(t){return e=>su(t)(e.$from)}function Kg(t,e){if(!(t instanceof H))return;let{node:n,$from:r}=t;if(TE(e,n))return{node:n,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Ug=(t,e)=>{let{selection:n,doc:r}=t;if(n instanceof H)return{hasNode:n.node.type===e,pos:n.from,target:n.node};let{from:i,to:o}=n,s=!1,a=-1,l=null;return r.nodesBetween(i,o,(c,u)=>l?!1:c.type===e?(s=!0,a=u,l=c,!1):!0),{hasNode:s,pos:a,target:l}};var ln={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ya={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},AE=typeof navigator<"u"&&/Mac/.test(navigator.platform),IE=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(we=0;we<10;we++)ln[48+we]=ln[96+we]=String(we);var we;for(we=1;we<=24;we++)ln[we+111]="F"+we;var we;for(we=65;we<=90;we++)ln[we]=String.fromCharCode(we+32),ya[we]=String.fromCharCode(we);var we;for(ga in ln)ya.hasOwnProperty(ga)||(ya[ga]=ln[ga]);var ga;function Jg(t){var e=AE&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||IE&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?ya:ln)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var NE=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),RE=typeof navigator<"u"&&/Win/.test(navigator.platform);function OE(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let a=0;athis.elements.length,this.top=()=>this.elements.at(-1),this.push=t=>{this.top()?.push(t)},this.open=t=>{this.elements.push(t)},this.close=()=>{let t=this.elements.pop();if(!t)throw Hl();return t}}},LE=class Zg extends Yg{constructor(e,n,r){super(),this.type=e,this.content=n,this.attrs=r}push(e,...n){this.content.push(e,...n)}pop(){return this.content.pop()}static create(e,n,r){return new Zg(e,n,r)}},ey=class extends Qg{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(e,r),n.toDoc())}}constructor(t){super(),this.#t=ne.none,this.#e=e=>e.isText,this.#r=(e,n)=>{if(this.#e(e)&&this.#e(n)&&ne.sameSet(e.marks,n.marks))return this.schema.text(e.text+n.text,e.marks)},this.#n=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.parseMarkdown.match(e));if(!n)throw ih(e);return n},this.#s=e=>{let n=this.#n(e);n.spec.parseMarkdown.runner(this,e,n)},this.injectRoot=(e,n,r)=>(this.openNode(n,r),this.next(e.children),this),this.openNode=(e,n)=>(this.open(LE.create(e,[],n)),this),this.#o=()=>{this.#t=ne.none;let e=this.close();return this.#i(e.type,e.attrs,e.content)},this.closeNode=()=>{try{this.#o()}catch(e){console.error(e)}return this},this.#i=(e,n,r)=>{let i=e.createAndFill(n,r,this.#t);if(!i)throw rh(e,n,r);return this.push(i),i},this.addNode=(e,n,r)=>{try{this.#i(e,n,r)}catch(i){console.error(i)}return this},this.openMark=(e,n)=>{let r=e.create(n);return this.#t=r.addToSet(this.#t),this},this.closeMark=e=>(this.#t=e.removeFromSet(this.#t),this),this.addText=e=>{try{let n=this.top();if(!n)throw Hl();let r=n.pop(),i=this.schema.text(e,this.#t);if(!r)return n.push(i),this;let o=this.#r(r,i);return o?(n.push(o),this):(n.push(r,i),this)}catch(n){return console.error(n),this}},this.build=()=>{let e;do e=this.#o();while(this.size());return e},this.next=(e=[])=>([e].flat().forEach(n=>this.#s(n)),this),this.toDoc=()=>this.build(),this.run=(e,n)=>{let r=e.runSync(e.parse(n),n);return this.next(r),this},this.schema=t}#e;#r;#n;#s;#o;#i},Xg=class ty extends Yg{constructor(e,n,r,i={}){super(),this.type=e,this.children=n,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}static{this.create=(e,n,r,i={})=>new ty(e,n,r,i)}},BE=t=>Object.prototype.hasOwnProperty.call(t,"size"),ny=class extends Qg{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(r),n.toString(e))}}constructor(t){super(),this.#t=[],this.#e=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.toMarkdown.match(e));if(!n)throw oh(e.type);return n},this.#r=e=>this.#e(e).spec.toMarkdown.runner(this,e),this.#n=(e,n)=>this.#e(e).spec.toMarkdown.runner(this,e,n),this.#s=e=>{let n=o=>o.type.spec.priority??50,r=[...e].sort((o,s)=>n(o)-n(s)),i=[];return this.#t.forEach(({mark:o})=>{let s=r.findIndex(a=>a.eq(o));s>=0&&i.push(...r.splice(s,1))}),i.concat(r)},this.#o=e=>{let n=e?.marks,r=0;for(;rs.eq(i)))r++;else break}for(let i=this.#t.length-1;i>=r;i--)this.#f(this.#t[i].mark)},this.#i=(e,n)=>{this.#s(e.marks).every(r=>!this.#n(r,e))&&this.#r(e),this.#o(n)},this.#a=e=>{let{children:n}=e;return n&&(e.children=n.reduce((r,i,o)=>{if(o===0)return[i];let s=r.at(-1);if(s&&s.isMark&&i.isMark){let{children:a,...l}=i,{children:c,...u}=s;if(i.type===s.type&&a&&c&&JSON.stringify(l)===JSON.stringify(u)){let f={...u,children:[...c,...a]};return r.slice(0,-1).concat(this.#a(f))}}return r.concat(i)},[])),e},this.#l=e=>{let n={...e.props,type:e.type};return e.children&&(n.children=e.children),e.value&&(n.value=e.value),n},this.openNode=(e,n,r)=>(this.open(Xg.create(e,void 0,n,r)),this),this.#d=(e,n)=>{let r="",i="",o=e.children;if(o){let a=o[0],l=o.at(-1);if(l&&l.type==="text"&&l.value.endsWith(" ")){let c=l.value,u=c.trimEnd();i=c.slice(u.length),l.value=u}if(a&&a.type==="text"&&a.value.startsWith(" ")){let c=a.value,u=c.trimStart();r=c.slice(0,c.length-u.length),a.value=u}}r.length&&this.#u("text",void 0,r);let s=n();return i.length&&this.#u("text",void 0,i),s},this.#c=(e=!1)=>{let n=this.close(),r=()=>this.#u(n.type,n.children,n.value,n.props);return e?this.#d(n,r):r()},this.closeNode=()=>(this.#c(),this),this.#u=(e,n,r,i)=>{let o=Xg.create(e,n,r,i),s=this.#a(this.#l(o));return this.push(s),s},this.addNode=(e,n,r,i)=>(this.#u(e,n,r,i),this),this.#p=(e,n,r,i)=>this.#t.some(o=>o.mark.eq(e))?this:(this.#t.push({mark:e,spanning:r==null}),this.openNode(n,r,{...i,isMark:!0})),this.#f=e=>{let n=-1;for(let r=this.#t.length-1;r>=0;r--)if(this.#t[r].mark.eq(e)){n=r;break}n<0||(this.#t.splice(n,1),this.#c(!0))},this.withMark=(e,n,r,i)=>(this.#p(e,n,r,i),this),this.closeMark=e=>(this.#f(e),this),this.build=()=>{let e=null;do e=this.#c();while(this.size());return e},this.next=e=>BE(e)?(e.forEach((n,r,i)=>{this.#i(n,e.maybeChild(i+1)??void 0)}),this):(this.#i(e),this),this.toString=e=>e.stringify(this.build()),this.run=e=>(this.#t=[],this.next(e),this),this.schema=t}#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f};var ze=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},ki=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},hu=null,un=function(t,e,n){let r=hu||(hu=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},PE=function(){hu=null},Ar=function(t,e,n,r){return n&&(ry(t,e,n,r,-1)||ry(t,e,n,r,1))},FE=/^(img|br|input|textarea|hr)$/i;function ry(t,e,n,r,i){for(var o;;){if(t==n&&e==r)return!0;if(e==(i<0?0:St(t))){let s=t.parentNode;if(!s||s.nodeType!=1||Po(t)||FE.test(t.nodeName)||t.contentEditable=="false")return!1;e=ze(t)+(i<0?0:1),t=s}else if(t.nodeType==1){let s=t.childNodes[e+(i<0?-1:0)];if(s.nodeType==1&&s.contentEditable=="false")if(!((o=s.pmViewDesc)===null||o===void 0)&&o.ignoreForSelection)e+=i;else return!1;else t=s,e=i<0?St(t):0}else return!1}}function St(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function zE(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=St(t)}else if(t.parentNode&&!Po(t))e=ze(t),t=t.parentNode;else return null}}function $E(t,e){for(;;){if(t.nodeType==3&&e2),Ct=bi||(jt?/Mac/.test(jt.platform):!1),By=jt?/Win/.test(jt.platform):!1,fn=/Android \d/.test(Hn),Fo=!!iy&&"webkitFontSmoothing"in iy.documentElement.style,jE=Fo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function VE(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function cn(t,e){return typeof t=="number"?t:t[e]}function qE(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function oy(t,e,n){if(!ku(e)&&e.left==0)return;let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;){if(s.nodeType!=1){s=ki(s);continue}let a=s,l=a==o.body,c=l?VE(o):qE(a),u=0,f=0;if(e.topc.bottom-cn(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+cn(i,"top")-c.top:e.bottom-c.bottom+cn(i,"bottom")),e.leftc.right-cn(r,"right")&&(u=e.right-c.right+cn(i,"right")),u||f)if(l)o.defaultView.scrollBy(u,f);else{let p=a.scrollLeft,h=a.scrollTop;f&&(a.scrollTop+=f),u&&(a.scrollLeft+=u);let m=a.scrollLeft-p,g=a.scrollTop-h;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=l?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:ki(s)}}function KE(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s=n-20){r=a,i=l.top;break}}return{refDOM:r,refTop:i,stack:Py(t.dom)}}function Py(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=ki(r));return e}function UE({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Fy(n,r==0?0:r-e)}function Fy(t,e){for(let n=0;n=a){s=Math.max(h.bottom,s),a=Math.min(h.top,a);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!l&&h.left<=e.left&&h.right>=e.left&&(l=u,c={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!n&&l&&(n=l,i=c,r=0),n&&n.nodeType==3?GE(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:zy(n,i)}function GE(t,e){let n=t.nodeValue.length,r=document.createRange(),i;for(let o=0;o=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}function Lu(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function XE(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function QE(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let a=t.docView.nearestDesc(o,!0),l;if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)&&((l=a.dom.getBoundingClientRect()).width||l.height)&&(a.node.isBlock&&a.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(a.dom.nodeName)&&(!s&&l.left>r.left||l.top>r.top?i=a.posBefore:(!s&&l.right-1?i:t.docView.posFromDOM(e,n,-1)}function $y(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let c;Fo&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(a=QE(t,r,i,e))}a==null&&(a=YE(t,s,e));let l=t.docView.nearestDesc(s,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function ku(t){return t.top=0&&i==r.nodeValue.length?(l--,u=1):n<0?l--:c++,Io(Fn(un(r,l,c),u),u<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==St(r))){let l=r.childNodes[i-1];if(l.nodeType==1)return cu(l.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==St(r))){let l=r.childNodes[i-1],c=l.nodeType==3?un(l,St(l)-(s?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return Io(Fn(c,1),!1)}if(o==null&&i=0)}function Io(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function cu(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Hy(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function tT(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Hy(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(o,!0);if(!a)break;if(a.node.isBlock){o=a.contentDOM||a.dom;break}o=a.dom.parentNode}let s=_y(t,i.pos,1);for(let a=o.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=un(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;cu.top+1&&(n=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var nT=/[\u0590-\u08ac]/;function rT(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,a=t.domSelection();return a?!nT.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?o:s:Hy(t,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:u,anchorOffset:f}=t.domSelectionRange(),d=a.caretBidiLevel;a.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||l==h&&c==m;try{a.collapse(u,f),l&&(l!=u||c!=f)&&a.extend&&a.extend(l,c)}catch{}return d!=null&&(a.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var sy=null,ay=null,ly=!1;function iT(t,e,n){return sy==e&&ay==n?ly:(sy=e,ay=n,ly=n=="up"||n=="down"?tT(t,e,n):rT(t,e,n))}var Et=0,cy=1,Cr=2,Ot=3,Ir=class{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=Et,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nze(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof xa){i=e-o;break}o=a}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof ka&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?ze(o.dom)+1:0}}else{let o,s=!0;for(;o=r=u&&n<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,n,u);e=s;for(let f=a;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ze(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>n||a==this.children.length-1)){n=c;for(let u=a+1;uh&&sn){let h=a;a=l,l=h}let p=document.createRange();p.setEnd(l.node,l.offset),p.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let a=r+o.border,l=s-o.border;if(e>=a&&n<=l){this.dirty=e==r||n==s?Cr:cy,e==a&&n==l&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ot:o.markDirty(e-a,n-a);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Cr:Ot}r=s}this.dirty=Cr}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Cr:cy;n.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let a=document.createElement("span");a.appendChild(s),s=a}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==Et&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},bu=class extends Ir{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Mr=class t extends Ir{constructor(e,n,r,i,o){super(e,[],r,i),this.mark=n,this.spec=o}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=wt.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new t(e,n,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&Ot||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ot&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=Et){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Su(o,0,e,r));for(let a=0;a{if(!l)return s;if(l.parent)return l.parent.posBeforeChild(l)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=wt.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),n.type.spec.draggable&&(u.draggable=!0));let d=u;return u=Vy(u,r,n),c?l=new xu(e,n,r,i,u,f||null,d,c):n.isText?new ba(e,n,r,i,u,d):new t(e,n,r,i,u,f||null,d)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>M.empty)}return e}matchesNode(e,n,r){return this.dirty==Et&&e.eq(this.node)&&wa(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,a=o&&o.pos<0,l=new Cu(this,s&&s.node,e);lT(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&l.syncToMarks(u==this.node.childCount?ne.none:this.node.child(u).marks,r,e,u),l.placeWidget(c,e,i)},(c,u,f,d)=>{l.syncToMarks(c.marks,r,e,d);let p;l.findNodeMatch(c,u,f,d)||a&&e.state.selection.from>i&&e.state.selection.to-1&&l.updateNodeAt(c,u,f,p,e)||l.updateNextNode(c,u,f,e,d,i)||l.addNode(c,u,f,e,i),i+=c.nodeSize}),l.syncToMarks([],r,e,0),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==Cr)&&(s&&this.protectLocalComposition(e,s),Wy(this.contentDOM,this.children,e),bi&&cT(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof P)||rn+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,a=uT(this.node.content,s,r-n,i-n);return a<0?null:{node:o,pos:a,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new bu(this,o,n,i);e.input.compositionNodes.push(s),this.children=Su(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==Ot||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Et}updateOuterDeco(e){if(wa(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=jy(this.dom,this.nodeDOM,wu(this.outerDeco,this.node,n),wu(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function uy(t,e,n,r,i){Vy(r,e,t);let o=new _n(void 0,t,e,n,r,r,r);return o.contentDOM&&o.updateChildren(i,0),o}var ba=class t extends _n{constructor(e,n,r,i,o,s){super(e,n,r,i,o,null,s)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Ot||this.dirty!=Et&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=Et||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Et,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new t(this.parent,i,this.outerDeco,this.innerDeco,o,o)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Ot)}get domAtom(){return!1}isText(e){return this.node.text==e}},xa=class extends Ir{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Et&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},xu=class extends _n{constructor(e,n,r,i,o,s,a,l){super(e,n,r,i,o,s,a),this.spec=l}update(e,n,r,i){if(this.dirty==Ot)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Wy(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o>1,a=Math.min(s,e.length);for(;o-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let u=Mr.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let a=this.index,l=Math.min(this.top.children.length,a+5);a0;){let a;for(;;)if(r){let c=n.children[r-1];if(c instanceof Mr)n=c,r=c.children.length;else{a=c,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=t.child(i-1))break;--i,o.set(a,i),s.push(a)}}return{index:i,matched:o,matches:s.reverse()}}function aT(t,e){return t.type.side-e.type.side}function lT(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let c=0;co;)a.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let g=h;s!g.inline):a.slice();r(d,m,e.forChild(o,d),p),o=h}}function cT(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function uT(t,e,n,r){for(let i=0,o=0;i=n){if(o>=r&&l.slice(r-e.length-a,r-a)==e)return r-e.length;let c=a=0&&c+e.length+a>=n)return a+c;if(n==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}function Su(t,e,n,r,i){let o=[];for(let s=0,a=0;s=n||u<=e?o.push(l):(cn&&o.push(l.slice(n-c,l.size,r)))}return o}function Bu(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a=r.resolve(s),l,c;if(Ia(n)){for(l=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&H.isSelectable(f)&&i.parent&&!(f.isInline&&_E(n.focusNode,n.focusOffset,i.dom))){let d=i.posBefore;c=new H(s==d?a:r.resolve(d))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=s,d=s;for(let p=0;p{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!qy(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function dT(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,ze(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&rt&&$n<=11&&(n.disabled=!0,n.disabled=!1)}function Ky(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(my(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else my(t)}function my(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Pu(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||P.between(e,n,r)}function gy(t){return t.editable&&!t.hasFocus()?!1:Uy(t)}function Uy(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function pT(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Ar(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Mu(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&_.findFrom(o,e)}function zn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function yy(t,e,n){let r=t.state.selection;if(r instanceof P)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return zn(t,new P(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=Mu(t.state,e);return i&&i instanceof H?zn(t,i):!1}else if(!(Ct&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let a=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(a))&&!s.contentDOM?H.isSelectable(o)?zn(t,new H(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):Fo?zn(t,new P(t.state.doc.resolve(e<0?a:a+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof H&&r.node.isInline)return zn(t,new P(e>0?r.$to:r.$from));{let i=Mu(t.state,e);return i?zn(t,i):!1}}}function Ca(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Ro(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function gi(t,e){return e<0?hT(t):mT(t)}function hT(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(Mt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(Ro(a,-1))i=n,o=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if(Jy(n))break;{let a=n.previousSibling;for(;a&&Ro(a,-1);)i=n.parentNode,o=ze(a),a=a.previousSibling;if(a)n=a,r=Ca(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?Eu(t,n,r):i&&Eu(t,i,o)}function mT(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Ca(n),o,s;for(;;)if(r{t.state==i&&pn(t)},50)}function ky(t,e){let n=t.state.doc.resolve(e);if(!(Ne||By)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function by(t,e,n){let r=t.state.selection;if(r instanceof P&&!r.empty||n.indexOf("s")>-1||Ct&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=Mu(t.state,e);if(s&&s instanceof H)return zn(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,a=r instanceof pt?_.near(s,e):_.findFrom(s,e);return a?zn(t,a):!1}return!1}function xy(t,e){if(!(t.state.selection instanceof P))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function wy(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function kT(t){if(!Je||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;wy(t,r,"true"),setTimeout(()=>wy(t,r,"false"),20)}return!1}function bT(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function xT(t,e){let n=e.keyCode,r=bT(e);if(n==8||Ct&&n==72&&r=="c")return xy(t,-1)||gi(t,-1);if(n==46&&!e.shiftKey||Ct&&n==68&&r=="c")return xy(t,1)||gi(t,1);if(n==13||n==27)return!0;if(n==37||Ct&&n==66&&r=="c"){let i=n==37?ky(t,t.state.selection.from)=="ltr"?-1:1:-1;return yy(t,i,r)||gi(t,i)}else if(n==39||Ct&&n==70&&r=="c"){let i=n==39?ky(t,t.state.selection.from)=="ltr"?1:-1:1;return yy(t,i,r)||gi(t,i)}else{if(n==38||Ct&&n==80&&r=="c")return by(t,-1,r)||gi(t,-1);if(n==40||Ct&&n==78&&r=="c")return kT(t)||by(t,1,r)||gi(t,1);if(r==(Ct?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function Fu(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=t.someProp("clipboardSerializer")||wt.fromSchema(t.state.schema),a=ek(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c=l.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Zy[c.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let h=a.createElement(u[p]);for(;l.firstChild;)h.appendChild(l.firstChild);l.appendChild(h),f++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(n)}`);let d=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,` -`);return{dom:l,text:d,slice:e}}function Jy(t,e,n,r,i){let o=i.parent.type.spec.code,s,a;if(!n&&!e)return null;let l=!!e&&(r||o||!n);if(l){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return a=new R(M.from(t.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0),t.someProp("transformPasted",d=>{a=d(a,t,!0)}),a;let f=t.someProp("clipboardTextParser",d=>d(e,i,r,t));if(f)a=f;else{let d=i.marks(),{schema:p}=t.state,h=wt.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,d)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),s=ST(n),Fo&&MT(s);let c=s&&s.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||xt.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!xT.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)a=ET(wy(a,+u[1],+u[2]),u[4]);else if(a=R.maxOpen(wT(a.content,i),!0),a.openStart||a.openEnd){let f=0,d=0;for(let p=a.content.firstChild;f{a=f(a,t,l)}),a}var xT=/^(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 wT(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),o,s=[];if(t.forEach(a=>{if(!s)return;let l=i.findWrapping(a.type),c;if(!l)return s=null;if(c=s.length&&o.length&&Xy(l,o,a,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Yy(s[s.length-1],o.length));let u=Gy(a,l);s.push(u),i=i.matchType(u.type),o=l}}),s)return M.from(s)}return t}function Gy(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,M.from(t));return t}function Xy(t,e,n,r,i){if(i1&&(o=0),i=n&&(a=e<0?s.contentMatchAt(0).fillBefore(a,o<=i).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(M.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(a))}function wy(t,e,n){return en})),fu.createHTML(t)):t}function ST(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Zy(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(t),o;if((o=i&&Qy[i[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"").reverse().join("")),r.innerHTML=CT(t),o)for(let s=0;s=0;a-=2){let l=n.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;i=M.from(l.create(r[a+1],i)),o++,s++}return new R(i,o,s)}var Xe={},Ye={},TT={touchstart:!0,touchmove:!0},vu=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 vT(t){for(let e in Xe){let n=Xe[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{IT(t,r)&&!zu(t,r)&&(t.editable||!(r.type in Ye))&&n(t,r)},TT[e]?{passive:!0}:void 0)}Je&&t.dom.addEventListener("input",()=>null),Au(t)}function dn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function AT(t){t.input.mouseDown&&t.input.mouseDown.done(),t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function Au(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>zu(t,r))})}function zu(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function IT(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function NT(t,e){!zu(t,e)&&Xe[e.type]&&(t.editable||!(e.type in Ye))&&Xe[e.type](t,e)}Ye.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!nk(t)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(fn&&Ne&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),bi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,wr(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||bT(t,n)?n.preventDefault():dn(t,"key")};Ye.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Ye.keypress=(t,e)=>{let n=e;if(nk(t)||!n.charCode||n.ctrlKey&&!n.altKey||Ct&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof P)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode),o=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",s=>s(t,r.$from.pos,r.$to.pos,i,o))&&t.dispatch(o()),n.preventDefault()}};function zo(t){return{left:t.clientX,top:t.clientY}}function RT(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function $u(t,e,n,r,i){if(r==-1)return!1;let o=t.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,a=>s>o.depth?a(t,n,o.nodeAfter,o.before(s),i,!0):a(t,n,o.node(s),o.before(s),i,!1)))return!0;return!1}function $o(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function OT(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&H.isSelectable(r)?($o(t,new H(n),"pointer"),!0):!1}function DT(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof H&&(r=n.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let a=s>o.depth?o.nodeAfter:o.node(s);if(H.isSelectable(a)){r&&n.$from.depth>0&&s>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?i=o.before(n.$from.depth):i=o.before(s);break}}return i!=null?($o(t,H.create(t.state.doc,i),"pointer"),!0):!1}function LT(t,e,n,r,i){return $u(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?DT(t,n):OT(t,n))}function BT(t,e,n,r){return $u(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function PT(t,e,n,r){return $u(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||FT(t,n,r)}function FT(t,e,n){if(n.button!=0)return!1;let r=ek(t,e,!0),i=t.state.doc;return r?($o(t,r,"pointer"),r instanceof P&&i.eq(t.state.doc)&&(t.input.mouseDown=new Nu(t,r)),!0):!1}function ek(t,e,n){let r=t.state.doc;if(e==-1)return r.inlineContent?P.create(r,0,r.content.size):null;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),a=i.before(o);if(s.inlineContent)return P.create(r,a+1,a+1+s.content.size);if(n&&H.isSelectable(s))return H.create(r,a)}return null}function _u(t){return Ma(t)}var tk=Ct?"metaKey":"ctrlKey";Xe.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=_u(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&RT(n,t.input.lastClick)&&!n[tk]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o,button:n.button},t.input.mouseDown&&t.input.mouseDown.done();let s=t.posAtCoords(zo(n));s&&(o=="singleClick"?t.input.mouseDown=new Iu(t,s,n,!!r):(o=="doubleClick"?BT:PT)(t,s.pos,s.inside,n)?n.preventDefault():dn(t,"pointer"))};var Sa=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},Iu=class extends Sa{constructor(e,n,r,i){super(e),this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!r[tk],this.allowDefault=r.shiftKey;let o,s;if(n.inside>-1)o=e.state.doc.nodeAt(n.inside),s=n.inside;else{let u=e.state.doc.resolve(n.pos);o=u.parent,s=u.depth?u.before():0}let a=i?null:r.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:c}=e.state;r.button==0&&(o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof H&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Mt&&!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()),dn(e,"pointer")}done(){super.done(),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(()=>{this.view.isDestroyed||pn(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(zo(e))),this.updateAllowDefault(e),this.allowDefault||!n?dn(this.view,"pointer"):LT(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Je&&this.mightDrag&&!this.mightDrag.node.isAtom||Ne&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?($o(this.view,_.near(this.view.state.doc.resolve(n.pos)),"pointer"),e.preventDefault()):dn(this.view,"pointer")}move(e){this.updateAllowDefault(e),dn(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Nu=class extends Sa{constructor(e,n){super(e),this.startSelection=n,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),dn(this.view,"pointer");let n=this.view.posAtCoords(zo(e)),r=n&&ek(this.view,n.inside,!1);if(!r)return;let{doc:i}=this.view.state,o=this.startSelection,[s,a]=r.from{t.input.lastTouch=Date.now(),_u(t),dn(t,"pointer")};Xe.touchmove=t=>{t.input.lastTouch=Date.now(),dn(t,"pointer")};Xe.contextmenu=t=>_u(t);function nk(t,e){return t.composing?!0:Je&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var zT=fn?5e3:-1;Ye.compositionstart=Ye.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof P&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||Ne&&Ly&&$T(t)))t.markCursor=t.state.storedMarks||n.marks(),Ma(t,!0),t.markCursor=null;else if(Ma(t,!e.selection.empty),Mt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let a=t.domSelection();a&&a.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}t.input.composing=!0}rk(t,zT)};function $T(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}Ye.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now(),t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,rk(t,20))};function rk(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Ma(t),e))}function ik(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function _T(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=FE(e.focusNode,e.focusOffset),r=zE(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,o=t.domObserver.lastChangedTextNode;if(n==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let s=n.pmViewDesc;if(!(!s||!s.isText(n.nodeValue)))return r}}return n||r}function Ma(t,e=!1){if(!(fn&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),ik(t),e||t.docView&&t.docView.dirty){let n=Bu(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function HT(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}var Oo=rt&&$n<15||bi&&WE<604;Xe.copy=Ye.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=Oo?null:n.clipboardData,s=r.content(),{dom:a,text:l}=Fu(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):HT(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function WT(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function jT(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.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=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Do(t,r.value,null,i,e):Do(t,r.textContent,r.innerHTML,i,e)},50)}function Do(t,e,n,r,i){let o=Jy(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,i,o||R.empty)))return!0;if(!o)return!1;let s=WT(o),a=s?t.state.tr.replaceSelectionWith(s,r):t.state.tr.replaceSelection(o);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ok(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Ye.paste=(t,e)=>{let n=e;if(t.composing&&!fn)return;let r=Oo?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&Do(t,ok(r),r.getData("text/html"),i,n)?n.preventDefault():jT(t,n)};var Ea=class{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}},VT=Ct?"altKey":"ctrlKey";function sk(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[VT]}Xe.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,o=i.empty?null:t.posAtCoords(zo(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof H?i.to-1:i.to))){if(r&&r.mightDrag)s=H.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(s=H.create(t.state.doc,f.posBefore))}}let a=(s||t.state.selection).content(),{dom:l,text:c,slice:u}=Fu(t,a);(!n.dataTransfer.files.length||!Ne||Dy>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Oo?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",Oo||n.dataTransfer.setData("text/plain",c),t.dragging=new Ea(u,sk(t,n),s)};Xe.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Ye.dragover=Ye.dragenter=(t,e)=>e.preventDefault();Ye.drop=(t,e)=>{try{qT(t,e,t.dragging)}finally{t.dragging=null}};function qT(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(zo(e));if(!r)return;let i=t.state.doc.resolve(r.pos),o=n&&n.slice;o?t.someProp("transformPasted",p=>{o=p(o,t,!1)}):o=Jy(t,ok(e.dataTransfer),Oo?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(n&&sk(t,e));if(t.someProp("handleDrop",p=>p(t,e,o||R.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let a=o?dg(t.state.doc,i.pos,o):i.pos;a==null&&(a=i.pos);let l=t.state.tr;if(s){let{node:p}=n;p?p.replace(l):l.deleteSelection()}let c=l.mapping.map(a),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=l.doc;if(u?l.replaceRangeWith(c,c,o.content.firstChild):l.replaceRange(c,c,o),l.doc.eq(f))return;let d=l.doc.resolve(c);if(u&&H.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))l.setSelection(new H(d));else{let p=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((h,m,g,y)=>p=y),l.setSelection(Pu(t,d,l.doc.resolve(p)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}Xe.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&pn(t)},20))};Xe.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Xe.beforeinput=(t,e)=>{if(Ne&&fn&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,wr(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Ye)Xe[t]=Ye[t];function Lo(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}var Ta=class t{constructor(e,n){this.toDOM=e,this.spec=n||Tr,this.side=this.spec.side||0}map(e,n,r,i){let{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new le(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof t&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Lo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Er=class t{constructor(e,n){this.attrs=e,this.spec=n||Tr}map(e,n,r,i){let o=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new le(o,s,this)}valid(e,n){return n.from=e&&(!o||o(a.spec))&&r.push(a.copy(a.from+i,a.to+i))}for(let s=0;se){let a=this.children[s]+1;this.children[s+2].findInner(e-a,n-a,r,i+a,o)}}map(e,n,r){return this==Ue||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Tr)}mapInner(e,n,r,i,o){let s;for(let a=0;a{let c=l+r,u;if(u=lk(n,a,c)){for(i||(i=this.children.slice());oa&&f.to=e){this.children[a]==e&&(r=this.children[a+2]);break}let o=e+1,s=o+n.content.size;for(let a=0;ao&&l.type instanceof Er){let c=Math.max(o,l.from)-o,u=Math.min(s,l.to)-o;ci.map(e,n,Tr));return t.from(r)}forChild(e,n){if(n.isLeaf)return ae.empty;let r=[];for(let i=0;in instanceof ae)?e:e.reduce((n,r)=>n.concat(r instanceof ae?r:r.members),[]))}}forEachSet(e){for(let n=0;n{let g=m-h-(p-d);for(let y=0;yx+u-f)continue;let C=a[y]+u-f;p>=C?a[y+1]=d<=C?-2:-1:d>=u&&g&&(a[y]+=g,a[y+1]+=g)}f+=g}),u=n.maps[c].map(u,-1)}let l=!1;for(let c=0;c=r.content.size){l=!0;continue}let d=n.map(t[c+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),g=r.maybeChild(h);if(g&&m==f&&m+g.nodeSize==p){let y=a[c+2].mapInner(n,g,u+1,t[c]+o+1,s);y!=Ue?(a[c]=f,a[c+1]=p,a[c+2]=y):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=UT(a,t,e,n,i,o,s),u=Aa(c,r,0,s);e=u.local;for(let f=0;fn&&s.to{let c=lk(t,a,l+n);if(c){o=!0;let u=Aa(c,a,n+l+1,r);u!=Ue&&i.push(l,l+a.nodeSize,u)}});let s=ak(o?ck(t):t,-n).sort(vr);for(let a=0;a0;)e++;t.splice(e,0,n)}function du(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=Ue&&e.push(r)}),t.cursorWrapper&&e.push(ae.create(t.state.doc,[t.cursorWrapper.deco])),va.from(e)}var JT={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},GT=rt&&$n<=11,Ou=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}},Du=class{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Ou,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():Je&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),GT&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,JT)),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 n=0;nthis.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(my(this.view)){if(this.suppressingSelectionUpdates)return pn(this.view);if(rt&&$n<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ar(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 n=new Set,r;for(let o=e.focusNode;o;o=ki(o))n.add(o);for(let o=e.anchorNode;o;o=ki(o))if(n.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&my(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,a=!1,l=[];if(e.editable)for(let u=0;uu.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||Ne&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&n.some(u=>u.type=="childList"&&u.removedNodes.length))){for(let u of l)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;for(;f&&f.nodeType==1;){if(f.contentEditable=="false"){u.parentNode.removeChild(u);break}f=f.firstChild}}}else if(Mt&&l.length){let u=l.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,d]=u;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of u){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||QT(e,f)!=p)&&d.remove()}}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),XT(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,ZT(e,l)),this.handleDOMChange(o,s,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||pn(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;ui;g--){let y=r.childNodes[g-1],x=y.pmViewDesc;if(y.nodeName=="BR"&&!x){o=g;break}if(!x||x.size)break}let f=t.state.doc,d=t.someProp("domParser")||xt.fromSchema(t.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:tv,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),h={anchor:g+s,head:y+s}}return{doc:m,sel:h,from:s,to:a}}function tv(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Je&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Je&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}var nv=/^(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 rv(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let N=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,B=Bu(t,N);if(B&&!t.state.selection.eq(B)){if(Ne&&fn&&t.input.lastKeyCode===13&&Date.now()-100S(t,wr(13,"Enter"))))return;let O=t.state.tr.setSelection(B);N=="pointer"?O.setMeta("pointer",!0):N=="key"&&O.scrollIntoView(),o&&O.setMeta("composition",o),t.dispatch(O)}return}let s=t.state.doc.resolve(e),a=s.sharedDepth(n);e=s.before(a+1),n=t.state.doc.resolve(n).after(a+1);let l=t.state.selection,c=ev(t,e,n),u=t.state.doc,f=u.slice(c.from,c.to),d,p;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||fn)&&i.some(N=>N.nodeType==1&&!nv.test(N.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",N=>N(t,wr(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&l instanceof P&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let N=Ty(t,t.state.doc,c.sel);if(N&&!N.eq(t.state.selection)){let B=t.state.tr.setSelection(N);o&&B.setMeta("composition",o),t.dispatch(B)}}return}t.state.selection.fromt.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=c.from?h.start=t.state.selection.from:h.endA=t.state.selection.to-2&&t.state.selection.to<=c.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),rt&&$n<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>c.from&&c.doc.textBetween(h.start-c.from-1,h.start-c.from+1)==" \xA0"&&(h.start--,h.endA--,h.endB--);let m=c.doc.resolveNoCache(h.start-c.from),g=c.doc.resolveNoCache(h.endB-c.from),y=u.resolve(h.start),x=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=h.endA;if((bi&&t.input.lastIOSEnter>Date.now()-225&&(!x||i.some(N=>N.nodeName=="DIV"||N.nodeName=="P"))||!x&&m.posN(t,wr(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&ov(u,h.start,h.endA,m,g)&&t.someProp("handleKeyDown",N=>N(t,wr(8,"Backspace")))){fn&&Ne&&t.domObserver.suppressSelectionUpdates();return}Ne&&h.endB==h.start&&(t.input.lastChromeDelete=Date.now()),fn&&!x&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==h.endA&&(h.endB-=2,g=c.doc.resolveNoCache(h.endB-c.from),setTimeout(()=>{t.someProp("handleKeyDown",function(N){return N(t,wr(13,"Enter"))})},20));let C=h.start,v=h.endA,A=N=>{let B=N||t.state.tr.replace(C,v,c.doc.slice(h.start-c.from,h.endB-c.from));if(c.sel){let O=Ty(t,B.doc,c.sel);O&&!(Ne&&t.composing&&O.empty&&(h.start!=h.endB||t.input.lastChromeDeletepn(t),20));let N=A(t.state.tr.delete(C,v)),B=u.resolve(h.start).marksAcross(u.resolve(h.endA));B&&N.ensureMarks(B),t.dispatch(N)}else if(h.endA==h.endB&&(w=iv(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,h.endA-y.start())))){let N=A(t.state.tr);w.type=="add"?N.addMark(C,v,w.mark):N.removeMark(C,v,w.mark),t.dispatch(N)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let N=m.parent.textBetween(m.parentOffset,g.parentOffset),B=()=>A(t.state.tr.insertText(N,C,v));t.someProp("handleTextInput",O=>O(t,C,v,N,B))||t.dispatch(B())}else t.dispatch(A());else t.dispatch(A())}function Ty(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:Pu(t,e.resolve(n.anchor),e.resolve(n.head))}function iv(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,a,l;for(let u=0;uu.mark(a.addToSet(u.marks));else if(i.length==0&&o.length==1)a=o[0],s="remove",l=u=>u.mark(a.removeFromSet(u.marks));else return null;let c=[];for(let u=0;un||pu(s,!0,!1)0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let o=t.node(r).maybeChild(t.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function sv(t,e,n,r,i){let o=t.findDiffStart(e,n),s=n+t.size,a=n+e.size;if(o==null)return null;let{a:l,b:c}=t.findDiffEnd(e,s,a);if(i=="end"){let u=Math.max(0,o-Math.min(l,c));r-=l+u-o}if(l=l?o-r:0;o-=u,c=o+(c-l),l=o}else if(c=c?o-r:0;o-=u,l=o+(l-c),c=o}return{start:o,endA:l,endB:c}}var Bo=class{constructor(e,n){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 vu,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(Ry),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=Iy(this),Ay(this),this.nodeViews=Ny(this),this.docView=cy(this.state.doc,vy(this),du(this),this.dom,this),this.domObserver=new Du(this,(r,i,o,s)=>rv(this,r,i,o,s)),this.domObserver.start(),vT(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Au(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ry),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(ik(this),s=!0),this.state=e;let a=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(a||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=Ny(this);lv(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&Au(this),this.editable=Iy(this),Ay(this);let l=du(this),c=vy(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,c,l);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&qE(this);if(s){this.domObserver.stop();let p=f&&(rt||Ne)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&av(i.selection,e.selection);if(f){let m=Ne?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=_T(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=cy(e.doc,c,l,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let h=this.input.mouseDown;p||!(h&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&dT(this)&&h.delaySelUpdate())?pn(this,p):(qy(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():d&&KE(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof H){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&iy(this,n.getBoundingClientRect(),e)}else iy(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 n=0;n0&&on.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return QE(this,e)}coordsAtPos(e,n=1){return $y(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return rT(this,n||this.state,e)}pasteHTML(e,n){return Do(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return Do(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return Fu(this,e)}destroy(){this.docView&&(AT(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],du(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,BE())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return NT(this,e)}domSelectionRange(){let e=this.domSelection();return e?Je&&this.root.nodeType===11&&_E(this.dom.ownerDocument)==this.dom&&YT(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Bo.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function vy(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[le.node(0,t.state.doc.content.size,e)]}function Ay(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:le.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Iy(t){return!t.someProp("editable",e=>e(t.state)===!1)}function av(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Ny(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function lv(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function Ry(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function gn(t,e){return t.meta={package:"@milkdown/core",group:"System",...e},t}var dk={text:(t,e,n,r)=>{let i=t.value;return/^[^*_\\]*\s+$/.test(i)?i:n.safe(i,{...r,encode:[]})},strong:(t,e,n,r)=>{let i=t.marker||n.options.strong||"*",o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i+i),o(),a},emphasis:(t,e,n,r)=>{let i=t.marker||n.options.emphasis||"*",o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i),o(),a}},U=Y({},"editorView"),_o=Y({},"editorState"),Wu=Y([],"initTimer"),uk=Y({},"editor"),Ti=Y([],"inputRules"),Dt=Y([],"prosePlugins"),vi=Y([],"remarkPlugins"),$a=Y([],"nodeView"),_a=Y([],"markView"),Nr=Y(mo().use(ei).use(ii),"remark"),xi=Y({handlers:dk,encode:[]},"remarkStringifyOptions"),Na=bt("ConfigReady");function cv(t){let e=n=>(n.record(Na),async()=>(await t(n),n.done(Na),()=>{n.clearTimer(Na)}));return gn(e,{displayName:"Config"}),e}var hn=bt("InitReady");function uv(t){let e=n=>(n.inject(uk,t).inject(Dt,[]).inject(vi,[]).inject(Ti,[]).inject($a,[]).inject(_a,[]).inject(xi,{handlers:dk,encode:[]}).inject(Nr,mo().use(ei).use(ii)).inject(Wu,[Na]).record(hn),async()=>{await n.waitTimers(Wu);let r=n.get(xi);return n.set(Nr,mo().use(ei).use(ii,r)),n.done(hn),()=>{n.remove(uk).remove(Dt).remove(vi).remove(Ti).remove($a).remove(_a).remove(xi).remove(Nr).remove(Wu).clearTimer(hn)}});return gn(e,{displayName:"Init"}),e}var Qe=bt("SchemaReady"),Ra=Y([],"schemaTimer"),$e=Y({},"schema"),wi=Y([],"nodes"),Ci=Y([],"marks");function fk(t){return{...t,parseDOM:t.parseDOM?.map(e=>({priority:t.priority,...e}))}}var pk=t=>(t.inject($e,{}).inject(wi,[]).inject(Ci,[]).inject(Ra,[hn]).record(Qe),async()=>{await t.waitTimers(Ra);let e=t.get(Nr),n=t.get(vi).reduce((i,o)=>i.use(o.plugin,o.options),e);t.set(Nr,n);let r=new sa({nodes:Object.fromEntries(t.get(wi).map(([i,o])=>[i,fk(o)])),marks:Object.fromEntries(t.get(Ci).map(([i,o])=>[i,fk(o)]))});return t.set($e,r),t.done(Qe),()=>{t.remove($e).remove(wi).remove(Ci).remove(Ra).clearTimer(Qe)}});gn(pk,{displayName:"Schema"});var hk=class{constructor(){this.#t=new Wl,this.#e=null,this.setCtx=t=>{this.#e=t},this.chain=()=>{if(this.#e==null)throw Ns();let t=this.#e,e=[],n=this.get.bind(this),r={run:()=>{let o=xr(...e),s=t.get(U);return o(s.state,s.dispatch,s)},inline:o=>(e.push(o),r),pipe:i.bind(this)};function i(o,s){let a=n(o);return e.push(a(s)),r}return r}}#t;#e;get ctx(){return this.#e}create(t,e){let n=t.create(this.#t.sliceMap);return n.set(e),n}get(t){return this.#t.get(t).get()}remove(t){return this.#t.remove(t)}call(t,e){if(this.#e==null)throw Ns();let n=this.get(t)(e),r=this.#e.get(U);return n(r.state,r.dispatch,r)}inline(t){if(this.#e==null)throw Ns();let e=this.#e.get(U);return t(e.state,e.dispatch,e)}};function mk(t="cmdKey"){return Y((()=>()=>!1),t)}var Q=Y(new hk,"commands"),Oa=Y([Qe],"commandsTimer"),Si=bt("CommandsReady"),gk=t=>{let e=new hk;return e.setCtx(t),t.inject(Q,e).inject(Oa,[Qe]).record(Si),async()=>(await t.waitTimers(Oa),t.done(Si),()=>{t.remove(Q).remove(Oa).clearTimer(Si)})};gn(gk,{displayName:"Commands"});function fv(t){return t.Backspace=xr(Lg,pa,vg,Gc),t}var yk=class{constructor(){this.#t=null,this.#e=[],this.setCtx=t=>{this.#t=t},this.add=t=>(this.#e.push(t),()=>{this.#e=this.#e.filter(e=>e!==t)}),this.addObjectKeymap=t=>{let e=[];return Object.entries(t).forEach(([n,r])=>{if(typeof r=="function"){let i={key:n,onRun:()=>r};this.#e.push(i),e.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}else this.#e.push(r),e.push(()=>{this.#e=this.#e.filter(i=>i!==r)})}),()=>{e.forEach(n=>n())}},this.addBaseKeymap=()=>{let t=fv(Dg);return this.addObjectKeymap(t)},this.build=()=>{let t={};return this.#e.forEach(e=>{t[e.key]=[...t[e.key]||[],e]}),Object.fromEntries(Object.entries(t).map(([e,n])=>{let r=n.sort((o,s)=>(s.priority??50)-(o.priority??50));return[e,(o,s,a)=>{let l=this.#t;if(l==null)throw Qr();return xr(...r.map(c=>c.onRun(l)))(o,s,a)}]}))}}#t;#e;get ctx(){return this.#t}},qo=Y(new yk,"keymap"),ju=Y([Qe],"keymapTimer"),Mi=bt("KeymapReady"),dv=t=>{let e=new yk;return e.setCtx(t),t.inject(qo,e).inject(ju,[Qe]).record(Mi),async()=>(await t.waitTimers(ju),t.done(Mi),()=>{t.remove(qo).remove(ju).clearTimer(Mi)})},Da=bt("ParserReady"),kk=(()=>{throw Qr()}),_e=Y(kk,"parser"),Vu=Y([],"parserTimer"),bk=t=>(t.inject(_e,kk).inject(Vu,[Qe]).record(Da),async()=>{await t.waitTimers(Vu);let e=t.get(Nr),n=t.get($e);return t.set(_e,Zg.create(n,e)),t.done(Da),()=>{t.remove(_e).remove(Vu).clearTimer(Da)}});gn(bk,{displayName:"Parser"});var Ei=bt("SerializerReady"),qu=Y([],"serializerTimer"),xk=(()=>{throw Qr()}),mn=Y(xk,"serializer"),wk=t=>(t.inject(mn,xk).inject(qu,[Qe]).record(Ei),async()=>{await t.waitTimers(qu);let e=t.get(Nr),n=t.get($e);return t.set(mn,ty.create(n,e)),t.done(Ei),()=>{t.remove(mn).remove(qu).clearTimer(Ei)}});gn(wk,{displayName:"Serializer"});var Ho=Y("","defaultValue"),Wo=Y(t=>t,"stateOptions"),La=Y([],"editorStateTimer"),Ba=bt("EditorStateReady");function pv(t,e,n){if(typeof t=="string")return e(t);if(t.type==="html")return xt.fromSchema(n).parse(t.dom);if(t.type==="json")return nt.fromJSON(n,t.value);throw Zp(t)}var hv=new ee("MILKDOWN_STATE_TRACKER"),Ck=t=>(t.inject(Ho,"").inject(_o,{}).inject(Wo,e=>e).inject(La,[Da,Ei,Si,Mi]).record(Ba),async()=>{await t.waitTimers(La);let e=t.get($e),n=t.get(_e),r=t.get(Ti),i=t.get(Wo),o=t.get(Dt),s=pv(t.get(Ho),n,e),a=t.get(qo),l=a.addBaseKeymap(),c=[...o,new X({key:hv,state:{init:()=>{},apply:(d,p,h,m)=>{t.set(_o,m)}}}),_g({rules:r}),Jg(a.build())];t.set(Dt,c);let u=i({schema:e,doc:s,plugins:c}),f=fi.create(u);return t.set(_o,f),t.done(Ba),()=>{l(),t.remove(Ho).remove(_o).remove(Wo).remove(La).clearTimer(Ba)}});gn(Ck,{displayName:"EditorState"});var Ai=Y([],"pasteRule"),Pa=Y([Qe],"pasteRuleTimer"),Fa=bt("PasteRuleReady"),Sk=t=>(t.inject(Ai,[]).inject(Pa,[Qe]).record(Fa),async()=>(await t.waitTimers(Pa),t.done(Fa),()=>{t.remove(Ai).remove(Pa).clearTimer(Fa)}));gn(Sk,{displayName:"PasteRule"});var jo=bt("EditorViewReady"),za=Y([],"editorViewTimer"),Rr=Y({},"editorViewOptions"),Vo=Y(null,"root"),Ku=Y(null,"rootDOM"),Uu=Y({},"rootAttrs");function mv(t,e){let n=document.createElement("div");n.className="milkdown",t.appendChild(n),e.set(Ku,n);let r=e.get(Uu);return Object.entries(r).forEach(([i,o])=>n.setAttribute(i,o)),n}function gv(t){t.classList.add("editor"),t.setAttribute("role","textbox")}var yv=new ee("MILKDOWN_VIEW_CLEAR"),Mk=t=>(t.inject(Vo,document.body).inject(U,{}).inject(Rr,{}).inject(Ku,null).inject(Uu,{}).inject(za,[Ba,Fa]).record(jo),async()=>{await t.wait(hn);let e=t.get(Vo)||document.body,n=typeof e=="string"?document.querySelector(e):e;t.update(Dt,s=>[new X({key:yv,view:a=>{let l=n?mv(n,t):void 0;return(()=>{if(l&&n){let u=a.dom;n.replaceChild(l,u),l.appendChild(u)}})(),{destroy:()=>{l?.parentNode&&l?.parentNode.replaceChild(a.dom,l),l?.remove()}}}}),...s]),await t.waitTimers(za);let r=t.get(_o),i=t.get(Rr),o=new Bo(n,{state:r,nodeViews:Object.fromEntries(t.get($a)),markViews:Object.fromEntries(t.get(_a)),transformPasted:(s,a,l)=>(t.get(Ai).sort((c,u)=>(u.priority??50)-(c.priority??50)).map(c=>c.run).forEach(c=>{s=c(s,a,l)}),s),...i});return gv(o.dom),t.set(U,o),t.done(jo),()=>{o?.destroy(),t.remove(Vo).remove(U).remove(Rr).remove(Ku).remove(Uu).remove(za).clearTimer(jo)}});gn(Mk,{displayName:"EditorView"});var Ek=class Tk{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Wl,this.#o=new ch,this.#i=new Map,this.#a=new Map,this.#l=new ah(this.#s,this.#o),this.#d=()=>{let e=cv(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),n=[pk,bk,wk,gk,dv,Sk,Ck,Mk,uv(this),e];this.#c(n,this.#a)},this.#c=(e,n)=>{e.forEach(r=>{let i=this.#l.produce(this.#t?r.meta:void 0),o=r(i);n.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#u=(e,n=!1)=>Promise.all([e].flat().map(async r=>{let i=this.#i.get(r)?.cleanup;return n?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof i=="function"?i():i})),this.#p=async()=>{await Promise.all([...this.#a.entries()].map(async([e,{cleanup:n}])=>typeof n=="function"?n():n)),this.#a.clear()},this.#f=e=>{this.#e=e,this.#n(e)},this.#h=e=>[...e.entries()].map(async([n,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(n,{ctx:i,handler:o,cleanup:s})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#r.push(e),this),this.removeConfig=e=>(this.#r=this.#r.filter(n=>n!==e),this),this.use=e=>{let n=[e].flat();return n.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(n,this.#i),this},this.remove=async e=>this.#e==="OnCreate"?(console.warn("[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code."),new Promise(n=>{setTimeout(()=>{n(this.remove(e))},50)})):(await this.#u([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#f("OnCreate"),this.#d(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#h(this.#a),this.#h(this.#i)].flat()),this.#f("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(n=>{setTimeout(()=>{n(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#f("OnDestroy"),await this.#u([...this.#i.keys()],e),await this.#p(),this.#f("Destroyed"),this),this.action=e=>e(this.#l),this.inspect=()=>this.#t?[...this.#a.values(),...this.#i.values()].map(({ctx:e})=>e?.inspector?.read()).filter(e=>!!e):(console.warn("[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first."),[])}static make(){return new Tk}#t;#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f;#h;get ctx(){return this.#l}get status(){return this.#e}};var kv=t=>crypto.getRandomValues(new Uint8Array(t)),bv=(t,e,n)=>{let r=256-256%t.length;if(r===256){let o=t.length-1;return(s=e)=>{if(!s)return"";let a="";for(;;){let l=n(s),c=s;for(;c--;)if(a+=t[l[c]&o],a.length>=s)return a}}}let i=Math.ceil(1.6*256*e/r);return(o=e)=>{if(!o)return"";let s="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]=o))return s}}},vk=(t,e=21)=>bv(t,e|0,kv);var MH=vk("abcedfghicklmn",10);function z(t,e){let n=mk(t),r=i=>async()=>{r.key=n,await i.wait(Si);let o=e(i);return i.get(Q).create(n,o),r.run=s=>i.get(Q).call(t,s),()=>{i.get(Q).remove(n)}};return r}function ge(t){let e=n=>async()=>{await n.wait(Qe);let r=t(n);return n.update(Ti,i=>[...i,r]),e.inputRule=r,()=>{n.update(Ti,i=>i.filter(o=>o!==r))}};return e}function Ak(t){let e=n=>async()=>{await n.wait(Qe);let r=t(n);return n.update(Ai,i=>[...i,r]),e.pasteRule=r,()=>{n.update(Ai,i=>i.filter(o=>o!==r))}};return e}function xv(t,e){let n=r=>async()=>{let i=e(r);return r.update(Ci,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(Ci,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get($e).marks[t];if(!i)throw sh(t);return i},n}function Ha(t,e){let n=r=>async()=>{let i=e(r);return r.update(wi,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(wi,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get($e).nodes[t];if(!i)throw Rs(t);return i},n}function pe(t){let e,n=r=>async()=>(await r.wait(Qe),e=t(r),r.update(Dt,i=>[...i,e]),()=>{r.update(Dt,i=>i.filter(o=>o!==e))});return n.plugin=()=>e,n.key=()=>e.spec.key,n}function wv(t){let e=n=>async()=>{await n.wait(Mi);let r=n.get(qo),i=t(n),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function ve(t,e){let n=Y(t,e),r=i=>(i.inject(n),()=>()=>{i.remove(n)});return r.key=n,r}function ce(t,e){let n=ve(e,t),r=Ha(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>ce(t,o(e)),i}function Lt(t,e){let n=ve(e,t),r=xv(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>Lt(t,o(e)),i}function He(t,e){let n=ve(Object.fromEntries(Object.entries(e).map(([o,{shortcuts:s,priority:a}])=>[o,{shortcuts:s,priority:a}])),`${t}Keymap`),r=wv(o=>{let s=o.get(n.key),a=Object.entries(e).flatMap(([l,{command:c}])=>{let u=s[l],f=[u.shortcuts].flat(),d=u.priority;return f.map(p=>[p,{key:p,onRun:c,priority:d}])});return Object.fromEntries(a)}),i=[n,r];return i.ctx=n,i.shortcuts=r,i.key=n.key,i.keymap=r.keymap,i}var Tt=(t,e=()=>({}))=>ve(e,`${t}Attr`),Or=(t,e=()=>({}))=>ve(e,`${t}Attr`);function ht(t,e,n){let r=ve(n??{},t),i=s=>async()=>{await s.wait(hn);let a={plugin:e(s),options:s.get(r.key)};return s.update(vi,l=>[...l,a]),()=>{s.update(vi,l=>l.filter(c=>c!==a))}},o=[r,i];return o.id=t,o.plugin=i,o.options=r,o}function Ik(t){return e=>{let n=e.get(U),r=e.get($e),i=e.get(mn);if(!t)return i(n.state.doc);let o=n.state.doc.slice(t.from,t.to,!0),s=r.topNodeType.createAndFill(null,o.content);return s?i(s):(console.error("No document found"),"")}}function Ju(t,e=!1){return n=>{let r=n.get(U),i=n.get(_e)(t);if(!i)return;if(!e){let c=r.state.selection.content();return r.dispatch(r.state.tr.replaceSelection(new R(i.content,c.openStart,c.openEnd)).scrollIntoView())}let o=n.get($e),s=wt.fromSchema(o).serializeFragment(i.content),a=xt.fromSchema(o).parseSlice(s),l=ma(a);if(l){r.dispatch(r.state.tr.replaceSelectionWith(l,!0));return}r.dispatch(r.state.tr.replaceSelection(a))}}function Nk(t,e=!1){return n=>{let r=n.get(U),i=n.get(_e)(t);if(!i)return;if(!e){let{state:l}=r;return r.dispatch(l.tr.replace(0,l.doc.content.size,new R(i.content,0,0)))}let o=n.get($e),s=n.get(Wo)({schema:o,doc:i,plugins:n.get(Dt)}),a=fi.create(s);r.updateState(a)}}function Cv(t){return e=>{let n=e.get(_e)(t),r=e.get($e),i=wt.fromSchema(r).serializeFragment(n.content);return xt.fromSchema(r).parseSlice(i)}}function Gu(t,e){return n=>{let r=n.get(U),i=Cv(t)(n);r.dispatch(r.state.tr.replace(e.from,e.to,i))}}function Rk(t,e){return function(n,r){let{$from:i,$to:o,node:s}=n.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let a=i.node(-1);if(a.type!=t)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=t||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=M.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let y=i.depth-d;y>=i.depth-3;y--)f=M.from(i.node(y).copy(f));let p=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=x+1)}),g>-1&&m.setSelection(_.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let l=o.pos==i.end()?a.contentMatchAt(0).defaultType:null,c=n.tr.delete(i.pos,o.pos),u=l?[e?{type:t,attrs:e}:null,{type:l}]:void 0;return yr(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function Wa(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==t);return o?n?r.node(o.depth-1).type==t?Sv(e,n,t,o):Mv(e,n,o):!0:!1}}function Sv(t,e,n,r){let i=t.tr,o=r.end,s=r.$to.end(r.depth);om;h--)p-=i.child(h).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let a=n.startIndex==0,l=n.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(a?0:1),u+1,s.content.append(l?M.empty:M.from(i))))return!1;let f=o.pos,d=f+s.nodeSize;return r.step(new Fe(f-(a?1:0),d+(l?1:0),f+1,d-1,new R((a?M.empty:M.from(i.copy(M.empty))).append(l?M.empty:M.from(i.copy(M.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function Ok(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==t);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let a=o.parent,l=a.child(s-1);if(l.type!=t)return!1;if(n){let c=l.lastChild&&l.lastChild.type==a.type,u=M.from(c?t.create():null),f=new R(M.from(t.create(null,M.from(a.type.create(null,u)))),c?3:1,0),d=o.start,p=o.end;n(e.tr.step(new Fe(d-(c?3:1),p,d,p,f,1,!0)).scrollIntoView())}return!0}}function Xu(t){let e=new Map;if(!t||!t.type)throw new Error("mdast-util-definitions expected node");return Nt(t,"definition",function(r){let i=Dk(r.identifier);i&&!e.get(i)&&e.set(i,r)}),n;function n(r){let i=Dk(r);return e.get(i)}}function Dk(t){return String(t||"").toUpperCase()}function ja(){return function(t){let e=Xu(t);Nt(t,function(n,r,i){if(n.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[sr,r];if(n.type==="imageReference"||n.type==="linkReference"){let o=e(n.identifier);if(o&&i&&typeof r=="number")return i.children[r]=n.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:n.alt}:{type:"link",url:o.url,title:o.title,children:n.children},[sr,r]}})}}function Lk(t,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){t.next(e.content);return}let n=[];e.content.forEach((r,i,o)=>{o!==e.childCount-1&&n.push(r)}),t.next(M.fromArray(n))}function E(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-commonmark",...e}}),t}var Yu=Or("emphasis");E(Yu,{displayName:"Attr",group:"Emphasis"});var Ni=Lt("emphasis",t=>({attrs:{marker:{default:t.get(xi).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",t.get(Yu.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,n)=>{e.withMark(n,"emphasis",void 0,{marker:n.attrs.marker})}}}));E(Ni.mark,{displayName:"MarkSchema",group:"Emphasis"});E(Ni.ctx,{displayName:"MarkSchemaCtx",group:"Emphasis"});var Qu=z("ToggleEmphasis",t=>()=>Ln(Ni.type(t)));E(Qu,{displayName:"Command",group:"Emphasis"});var Bk=ge(t=>an(/(?:^|[^*])\*([^*]+)\*$/,Ni.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:n+1}}));E(Bk,{displayName:"InputRule|Star",group:"Emphasis"});var Pk=ge(t=>an(/\b_(?![_\s])(.*?[^_\s])_\b/,Ni.type(t),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:n+1}}));E(Pk,{displayName:"InputRule|Underscore",group:"Emphasis"});var Zu=He("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:t=>{let e=t.get(Q);return()=>e.call(Qu.key)}}});E(Zu.ctx,{displayName:"KeymapCtx",group:"Emphasis"});E(Zu.shortcuts,{displayName:"Keymap",group:"Emphasis"});var ef=Or("strong");E(ef,{displayName:"Attr",group:"Strong"});var Ko=Lt("strong",t=>({attrs:{marker:{default:t.get(xi).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:e=>e.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:e=>e==="bold"},{style:"font-weight=400",clearMark:e=>e.type.name=="strong"},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:e=>["strong",t.get(ef.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,n)=>{e.withMark(n,"strong",void 0,{marker:n.attrs.marker})}}}));E(Ko.mark,{displayName:"MarkSchema",group:"Strong"});E(Ko.ctx,{displayName:"MarkSchemaCtx",group:"Strong"});var tf=z("ToggleStrong",t=>()=>Ln(Ko.type(t)));E(tf,{displayName:"Command",group:"Strong"});var Fk=ge(t=>an(/(?({marker:e[0].startsWith("*")?"*":"_"})}));E(Fk,{displayName:"InputRule",group:"Strong"});var nf=He("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:t=>{let e=t.get(Q);return()=>e.call(tf.key)}}});E(nf.ctx,{displayName:"KeymapCtx",group:"Strong"});E(nf.shortcuts,{displayName:"Keymap",group:"Strong"});var rf=Or("inlineCode");E(rf,{displayName:"Attr",group:"InlineCode"});var jn=Lt("inlineCode",t=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",t.get(rf.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,n,r)=>{e.openMark(r),e.addText(n.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,n,r)=>(e.withMark(n,"inlineCode",r.text||""),!0)}}));E(jn.mark,{displayName:"MarkSchema",group:"InlineCode"});E(jn.ctx,{displayName:"MarkSchemaCtx",group:"InlineCode"});var of=z("ToggleInlineCode",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,jn.type(t))?(n?.(i.removeMark(o,s,jn.type(t))),!0):(Object.keys(e.schema.marks).filter(a=>a!==jn.type.name).map(a=>e.schema.marks[a]).forEach(a=>{i.removeMark(o,s,a)}),n?.(i.addMark(o,s,jn.type(t).create())),!0)});E(of,{displayName:"Command",group:"InlineCode"});var zk=ge(t=>an(/(?:`)([^`]+)(?:`)$/,jn.type(t)));E(zk,{displayName:"InputRule",group:"InlineCode"});var sf=He("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:t=>{let e=t.get(Q);return()=>e.call(of.key)}}});E(sf.ctx,{displayName:"KeymapCtx",group:"InlineCode"});E(sf.shortcuts,{displayName:"Keymap",group:"InlineCode"});var Ev=new Set(["http:","https:","mailto:","tel:","ftp:"]);function Tv(t){return t<=32||t>=127&&t<=160||t>=8203&&t<=8205||t===8232||t===8233||t===65279}function vv(t){let e="";for(let n of t)Tv(n.codePointAt(0)??0)||(e+=n);return e}function Av(t){if(typeof t!="string")return"";let e=t.trim();if(!e)return"";let n=vv(e),r=/^([a-z][a-z0-9+.-]*):/i.exec(n)?.[1];return!r||Ev.has(`${r.toLowerCase()}:`)?e:""}var af=Or("link");E(af,{displayName:"Attr",group:"Link"});var Ii=Lt("link",t=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw ft(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...t.get(af.key)(e),...e.attrs,href:Av(e.attrs.href)}],parseMarkdown:{match:e=>e.type==="link",runner:(e,n,r)=>{let i=n.url,o=n.title;e.openMark(r,{href:i,title:o}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,n)=>{e.withMark(n,"link",void 0,{title:n.attrs.title,url:n.attrs.href})}}}));E(Ii.mark,{displayName:"MarkSchema",group:"Link"});var $k=z("ToggleLink",t=>(e={})=>Ln(Ii.type(t),e));E($k,{displayName:"Command",group:"Link"});var _k=z("UpdateLink",t=>(e={})=>(n,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=n,{from:a,to:l}=s;if(n.doc.nodesBetween(a,a===l?l+1:l,(h,m)=>{if(Ii.type(t).isInSet(h.marks))return i=h,o=m,!1}),!i)return!1;let c=i.marks.find(({type:h})=>h===Ii.type(t));if(!c)return!1;let u=o,f=o+i.nodeSize,{tr:d}=n,p=Ii.type(t).create({...c.attrs,...e});return p?(r(d.removeMark(u,f,c).addMark(u,f,p).setSelection(new P(d.selection.$anchor)).scrollIntoView()),!0):!1});E(_k,{displayName:"Command",group:"Link"});var Hk=Ha("doc",()=>({content:"block+",parseMarkdown:{match:({type:t})=>t==="root",runner:(t,e,n)=>{t.injectRoot(e,n)}},toMarkdown:{match:t=>t.type.name==="doc",runner:(t,e)=>{t.openNode("root"),t.next(e.content)}}}));E(Hk,{displayName:"NodeSchema",group:"Doc"});function Iv(t){return ar(t,e=>e.type==="html"&&["
","
","
","
"].includes(e.value?.trim()),(e,n)=>{if(!n.length)return;let r=n[n.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var qa=ht("remark-preserve-empty-line",()=>()=>Iv);E(qa.plugin,{displayName:"Remark",group:"Remark"});E(qa.options,{displayName:"RemarkConfig",group:"Remark"});var lf=Tt("paragraph");E(lf,{displayName:"Attr",group:"Paragraph"});var Bt=ce("paragraph",t=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",t.get(lf.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,n,r)=>{e.openNode(r),n.children?e.next(n.children):e.addText(n.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,n)=>{let r=t.get(U).state?.doc.lastChild;e.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&Nv(t)?e.addNode("html",void 0,"
"):Lk(e,n),e.closeNode()}}}));function Nv(t){let e=!1;try{t.get(qa.id),e=!0}catch{e=!1}return e}E(Bt.node,{displayName:"NodeSchema",group:"Paragraph"});E(Bt.ctx,{displayName:"NodeSchemaCtx",group:"Paragraph"});var cf=z("TurnIntoText",t=>()=>Dn(Bt.type(t)));E(cf,{displayName:"Command",group:"Paragraph"});var uf=He("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:t=>{let e=t.get(Q);return()=>e.call(cf.key)}}});E(uf.ctx,{displayName:"KeymapCtx",group:"Paragraph"});E(uf.shortcuts,{displayName:"Keymap",group:"Paragraph"});var Rv=Array(6).fill(0).map((t,e)=>e+1);function Ov(t){return t.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Ka=ve(Ov,"headingIdGenerator");E(Ka,{displayName:"Ctx",group:"Heading"});var ff=Tt("heading");E(ff,{displayName:"Attr",group:"Heading"});var Lr=ce("heading",t=>{let e=t.get(Ka.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:Rv.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw ft(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...t.get(ff.key)(n),id:n.attrs.id||e(n)},0],parseMarkdown:{match:({type:n})=>n==="heading",runner:(n,r,i)=>{let o=r.depth;n.openNode(i,{level:o}),n.next(r.children),n.closeNode()}},toMarkdown:{match:n=>n.type.name==="heading",runner:(n,r)=>{n.openNode("heading",void 0,{depth:r.attrs.level}),Lk(n,r),n.closeNode()}}}});E(Lr.node,{displayName:"NodeSchema",group:"Heading"});E(Lr.ctx,{displayName:"NodeSchemaCtx",group:"Heading"});var Wk=ge(t=>Zc(/^(?#+)\s$/,Lr.type(t),e=>{let n=e.groups?.hashes?.length||0,{$from:r}=t.get(U).state.selection,i=r.node();if(i.type.name==="heading"){let o=Number(i.attrs.level)+Number(n);return o>6&&(o=6),{level:o}}return{level:n}}));E(Wk,{displayName:"InputRule",group:"Heading"});var Wn=z("WrapInHeading",t=>e=>(e??=1,e<1?Dn(Bt.type(t)):Dn(Lr.type(t),{level:e})));E(Wn,{displayName:"Command",group:"Heading"});var df=z("DowngradeHeading",t=>()=>(e,n,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==Lr.type(t)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(n?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):Dn(Bt.type(t))(e,n,r)});E(df,{displayName:"Command",group:"Heading"});var pf=He("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:t=>{let e=t.get(Q);return()=>e.call(df.key)}}});E(pf.ctx,{displayName:"KeymapCtx",group:"Heading"});E(pf.shortcuts,{displayName:"Keymap",group:"Heading"});var hf=Tt("blockquote");E(hf,{displayName:"Attr
",group:"Blockquote"});var Uo=ce("blockquote",t=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",t.get(hf.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,n,r)=>{e.openNode(r).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,n)=>{e.openNode("blockquote").next(n.content).closeNode()}}}));E(Uo.node,{displayName:"NodeSchema
",group:"Blockquote"});E(Uo.ctx,{displayName:"NodeSchemaCtx
",group:"Blockquote"});var jk=ge(t=>ha(/^\s*>\s$/,Uo.type(t)));E(jk,{displayName:"InputRule",group:"Blockquote"});var mf=z("WrapInBlockquote",t=>()=>pi(Uo.type(t)));E(mf,{displayName:"Command",group:"Blockquote"});var gf=He("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:t=>{let e=t.get(Q);return()=>e.call(mf.key)}}});E(gf.ctx,{displayName:"KeymapCtx
",group:"Blockquote"});E(gf.shortcuts,{displayName:"Keymap
",group:"Blockquote"});var yf=Tt("codeBlock",()=>({pre:{},code:{}}));E(yf,{displayName:"Attr",group:"CodeBlock"});var Jo=ce("code_block",t=>({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 ft(e);return{language:e.dataset.language}}}],toDOM:e=>{let n=t.get(yf.key)(e),r=e.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,n,r)=>{let i=n.lang??"",o=n.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,n)=>{e.addNode("code",void 0,n.content.firstChild?.text||"",{lang:n.attrs.language})}}}));E(Jo.node,{displayName:"NodeSchema",group:"CodeBlock"});E(Jo.ctx,{displayName:"NodeSchemaCtx",group:"CodeBlock"});var Vk=ge(t=>Zc(/^```(?[a-z]*)?[\s\n]$/,Jo.type(t),e=>({language:e.groups?.language??""})));E(Vk,{displayName:"InputRule",group:"CodeBlock"});var kf=z("CreateCodeBlock",t=>(e="")=>Dn(Jo.type(t),{language:e}));E(kf,{displayName:"Command",group:"CodeBlock"});var Dv=z("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(n,r)=>t>=0?(r?.(n.tr.setNodeAttribute(t,"language",e)),!0):!1);E(Dv,{displayName:"Command",group:"CodeBlock"});var bf=He("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:t=>{let e=t.get(Q);return()=>e.call(kf.key)}}});E(bf.ctx,{displayName:"KeymapCtx",group:"CodeBlock"});E(bf.shortcuts,{displayName:"Keymap",group:"CodeBlock"});var xf=Tt("image");E(xf,{displayName:"Attr",group:"Image"});var Ri=ce("image",t=>({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 ft(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...t.get(xf.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,n,r)=>{let i=n.url,o=n.alt,s=n.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,n)=>{e.addNode("image",void 0,void 0,{title:n.attrs.title,url:n.attrs.src,alt:n.attrs.alt})}}}));E(Ri.node,{displayName:"NodeSchema",group:"Image"});E(Ri.ctx,{displayName:"NodeSchemaCtx",group:"Image"});var qk=z("InsertImage",t=>(e={})=>(n,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,a=Ri.type(t).create({src:i,alt:o,title:s});return a&&r(n.tr.replaceSelectionWith(a).scrollIntoView()),!0});E(qk,{displayName:"Command",group:"Image"});var Kk=z("UpdateImage",t=>(e={})=>(n,r)=>{let i=qg(n.selection,Ri.type(t));if(!i)return!1;let{node:o,pos:s}=i,a={...o.attrs},{src:l,alt:c,title:u}=e;return l!==void 0&&(a.src=l),c!==void 0&&(a.alt=c),u!==void 0&&(a.title=u),r?.(n.tr.setNodeMarkup(s,void 0,a).scrollIntoView()),!0});E(Kk,{displayName:"Command",group:"Image"});var Lv=ge(t=>new be(/!\[(?.*?)]\((?.*?)\s*(?="|\))"?(?[^"]+)?"?\)/,(e,n,r,i)=>{let[o,s,a="",l]=n;return o?e.tr.replaceWith(r,i,Ri.type(t).create({src:a,alt:s,title:l})):null}));E(Lv,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Va=Tt("hardbreak",t=>({"data-type":"hardbreak","data-is-inline":t.attrs.isInline}));E(Va,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Dr=ce("hardbreak",t=>({inline:!0,group:"inline",attrs:{isInline:{default:!1,validate:"boolean"}},selectable:!1,parseDOM:[{tag:"br"},{tag:'span[data-type="hardbreak"]',getAttrs:()=>({isInline:!0})}],toDOM:e=>e.attrs.isInline?["span",t.get(Va.key)(e)," "]:["br",t.get(Va.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,n,r)=>{e.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>` +`);return{dom:l,text:d,slice:e}}function Gy(t,e,n,r,i){let o=i.parent.type.spec.code,s,a;if(!n&&!e)return null;let l=!!e&&(r||o||!n);if(l){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return a=new R(M.from(t.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0),t.someProp("transformPasted",d=>{a=d(a,t,!0)}),a;let f=t.someProp("clipboardTextParser",d=>d(e,i,r,t));if(f)a=f;else{let d=i.marks(),{schema:p}=t.state,h=wt.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,d)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),s=MT(n),Fo&&ET(s);let c=s&&s.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||xt.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!wT.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)a=TT(Cy(a,+u[1],+u[2]),u[4]);else if(a=R.maxOpen(CT(a.content,i),!0),a.openStart||a.openEnd){let f=0,d=0;for(let p=a.content.firstChild;f<a.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=a.content.lastChild;d<a.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);a=Cy(a,f,d)}return t.someProp("transformPasted",f=>{a=f(a,t,l)}),a}var wT=/^(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 CT(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),o,s=[];if(t.forEach(a=>{if(!s)return;let l=i.findWrapping(a.type),c;if(!l)return s=null;if(c=s.length&&o.length&&Yy(l,o,a,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Qy(s[s.length-1],o.length));let u=Xy(a,l);s.push(u),i=i.matchType(u.type),o=l}}),s)return M.from(s)}return t}function Xy(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,M.from(t));return t}function Yy(t,e,n,r,i){if(i<t.length&&i<e.length&&t[i]==e[i]){let o=Yy(t,e,n,r.lastChild,i+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(i==t.length-1?n.type:t[i+1]))return r.copy(r.content.append(M.from(Xy(n,t,i+1))))}}function Qy(t,e){if(e==0)return t;let n=t.content.replaceChild(t.childCount-1,Qy(t.lastChild,e-1)),r=t.contentMatchAt(t.childCount).fillBefore(M.empty,!0);return t.copy(n.append(r))}function Tu(t,e,n,r,i,o){let s=e<0?t.firstChild:t.lastChild,a=s.content;return t.childCount>1&&(o=0),i<r-1&&(a=Tu(a,e,n,r,i+1,o)),i>=n&&(a=e<0?s.contentMatchAt(0).fillBefore(a,o<=i).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(M.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(a))}function Cy(t,e,n){return e<t.openStart&&(t=new R(Tu(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),n<t.openEnd&&(t=new R(Tu(t.content,1,n,t.openEnd,0,0),t.openStart,n)),t}var Zy={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function ek(){return document.implementation.createHTMLDocument("title")}var fu=null;function ST(t){let e=window.trustedTypes;return e?(fu||(fu=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:n=>n})),fu.createHTML(t)):t}function MT(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=ek(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(t),o;if((o=i&&Zy[i[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"</"+s+">").reverse().join("")),r.innerHTML=ST(t),o)for(let s=0;s<o.length;s++)r=r.querySelector(o[s])||r;for(let s=0;s<n.styleSheets.length;s++){let a=n.styleSheets[s];for(let l=0;l<a.rules.length;l++){let c=a.rules[l];if(c instanceof CSSStyleRule){let u=r.querySelectorAll(c.selectorText);for(let f=0;f<u.length;f++)u[f].style.cssText+=c.style.cssText}}}return r}function ET(t){let e=t.querySelectorAll(Ne?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<e.length;n++){let r=e[n];r.childNodes.length==1&&r.textContent=="\xA0"&&r.parentNode&&r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),r)}}function TT(t,e){if(!t.size)return t;let n=t.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return t}let{content:i,openStart:o,openEnd:s}=t;for(let a=r.length-2;a>=0;a-=2){let l=n.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;i=M.from(l.create(r[a+1],i)),o++,s++}return new R(i,o,s)}var Xe={},Ye={},vT={touchstart:!0,touchmove:!0},vu=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 AT(t){for(let e in Xe){let n=Xe[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{NT(t,r)&&!zu(t,r)&&(t.editable||!(r.type in Ye))&&n(t,r)},vT[e]?{passive:!0}:void 0)}Je&&t.dom.addEventListener("input",()=>null),Au(t)}function dn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function IT(t){t.input.mouseDown&&t.input.mouseDown.done(),t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function Au(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>zu(t,r))})}function zu(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function NT(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function RT(t,e){!zu(t,e)&&Xe[e.type]&&(t.editable||!(e.type in Ye))&&Xe[e.type](t,e)}Ye.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!rk(t)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(fn&&Ne&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),bi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,wr(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||xT(t,n)?n.preventDefault():dn(t,"key")};Ye.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Ye.keypress=(t,e)=>{let n=e;if(rk(t)||!n.charCode||n.ctrlKey&&!n.altKey||Ct&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof P)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode),o=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",s=>s(t,r.$from.pos,r.$to.pos,i,o))&&t.dispatch(o()),n.preventDefault()}};function zo(t){return{left:t.clientX,top:t.clientY}}function OT(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function $u(t,e,n,r,i){if(r==-1)return!1;let o=t.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,a=>s>o.depth?a(t,n,o.nodeAfter,o.before(s),i,!0):a(t,n,o.node(s),o.before(s),i,!1)))return!0;return!1}function $o(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function DT(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&H.isSelectable(r)?($o(t,new H(n),"pointer"),!0):!1}function LT(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof H&&(r=n.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let a=s>o.depth?o.nodeAfter:o.node(s);if(H.isSelectable(a)){r&&n.$from.depth>0&&s>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?i=o.before(n.$from.depth):i=o.before(s);break}}return i!=null?($o(t,H.create(t.state.doc,i),"pointer"),!0):!1}function BT(t,e,n,r,i){return $u(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?LT(t,n):DT(t,n))}function PT(t,e,n,r){return $u(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function FT(t,e,n,r){return $u(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||zT(t,n,r)}function zT(t,e,n){if(n.button!=0)return!1;let r=tk(t,e,!0),i=t.state.doc;return r?($o(t,r,"pointer"),r instanceof P&&i.eq(t.state.doc)&&(t.input.mouseDown=new Nu(t,r)),!0):!1}function tk(t,e,n){let r=t.state.doc;if(e==-1)return r.inlineContent?P.create(r,0,r.content.size):null;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),a=i.before(o);if(s.inlineContent)return P.create(r,a+1,a+1+s.content.size);if(n&&H.isSelectable(s))return H.create(r,a)}return null}function _u(t){return Ma(t)}var nk=Ct?"metaKey":"ctrlKey";Xe.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=_u(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&OT(n,t.input.lastClick)&&!n[nk]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o,button:n.button},t.input.mouseDown&&t.input.mouseDown.done();let s=t.posAtCoords(zo(n));s&&(o=="singleClick"?t.input.mouseDown=new Iu(t,s,n,!!r):(o=="doubleClick"?PT:FT)(t,s.pos,s.inside,n)?n.preventDefault():dn(t,"pointer"))};var Sa=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},Iu=class extends Sa{constructor(e,n,r,i){super(e),this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!r[nk],this.allowDefault=r.shiftKey;let o,s;if(n.inside>-1)o=e.state.doc.nodeAt(n.inside),s=n.inside;else{let u=e.state.doc.resolve(n.pos);o=u.parent,s=u.depth?u.before():0}let a=i?null:r.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:c}=e.state;r.button==0&&(o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof H&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Mt&&!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()),dn(e,"pointer")}done(){super.done(),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(()=>{this.view.isDestroyed||pn(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(zo(e))),this.updateAllowDefault(e),this.allowDefault||!n?dn(this.view,"pointer"):BT(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Je&&this.mightDrag&&!this.mightDrag.node.isAtom||Ne&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?($o(this.view,_.near(this.view.state.doc.resolve(n.pos)),"pointer"),e.preventDefault()):dn(this.view,"pointer")}move(e){this.updateAllowDefault(e),dn(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Nu=class extends Sa{constructor(e,n){super(e),this.startSelection=n,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),dn(this.view,"pointer");let n=this.view.posAtCoords(zo(e)),r=n&&tk(this.view,n.inside,!1);if(!r)return;let{doc:i}=this.view.state,o=this.startSelection,[s,a]=r.from<o.from?[o.to,r.from]:[o.from,r.to];$o(this.view,P.create(i,s,a),"pointer")}};Xe.touchstart=t=>{t.input.lastTouch=Date.now(),_u(t),dn(t,"pointer")};Xe.touchmove=t=>{t.input.lastTouch=Date.now(),dn(t,"pointer")};Xe.contextmenu=t=>_u(t);function rk(t,e){return t.composing?!0:Je&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var $T=fn?5e3:-1;Ye.compositionstart=Ye.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof P&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||Ne&&By&&_T(t)))t.markCursor=t.state.storedMarks||n.marks(),Ma(t,!0),t.markCursor=null;else if(Ma(t,!e.selection.empty),Mt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let a=t.domSelection();a&&a.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}t.input.composing=!0}ik(t,$T)};function _T(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}Ye.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now(),t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,ik(t,20))};function ik(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Ma(t),e))}function ok(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function HT(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=zE(e.focusNode,e.focusOffset),r=$E(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,o=t.domObserver.lastChangedTextNode;if(n==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let s=n.pmViewDesc;if(!(!s||!s.isText(n.nodeValue)))return r}}return n||r}function Ma(t,e=!1){if(!(fn&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),ok(t),e||t.docView&&t.docView.dirty){let n=Bu(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function WT(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}var Oo=rt&&$n<15||bi&&jE<604;Xe.copy=Ye.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=Oo?null:n.clipboardData,s=r.content(),{dom:a,text:l}=Fu(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):WT(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function jT(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function VT(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.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=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Do(t,r.value,null,i,e):Do(t,r.textContent,r.innerHTML,i,e)},50)}function Do(t,e,n,r,i){let o=Gy(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,i,o||R.empty)))return!0;if(!o)return!1;let s=jT(o),a=s?t.state.tr.replaceSelectionWith(s,r):t.state.tr.replaceSelection(o);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function sk(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Ye.paste=(t,e)=>{let n=e;if(t.composing&&!fn)return;let r=Oo?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&Do(t,sk(r),r.getData("text/html"),i,n)?n.preventDefault():VT(t,n)};var Ea=class{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}},qT=Ct?"altKey":"ctrlKey";function ak(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[qT]}Xe.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,o=i.empty?null:t.posAtCoords(zo(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof H?i.to-1:i.to))){if(r&&r.mightDrag)s=H.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(s=H.create(t.state.doc,f.posBefore))}}let a=(s||t.state.selection).content(),{dom:l,text:c,slice:u}=Fu(t,a);(!n.dataTransfer.files.length||!Ne||Ly>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Oo?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",Oo||n.dataTransfer.setData("text/plain",c),t.dragging=new Ea(u,ak(t,n),s)};Xe.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Ye.dragover=Ye.dragenter=(t,e)=>e.preventDefault();Ye.drop=(t,e)=>{try{KT(t,e,t.dragging)}finally{t.dragging=null}};function KT(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(zo(e));if(!r)return;let i=t.state.doc.resolve(r.pos),o=n&&n.slice;o?t.someProp("transformPasted",p=>{o=p(o,t,!1)}):o=Gy(t,sk(e.dataTransfer),Oo?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(n&&ak(t,e));if(t.someProp("handleDrop",p=>p(t,e,o||R.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let a=o?pg(t.state.doc,i.pos,o):i.pos;a==null&&(a=i.pos);let l=t.state.tr;if(s){let{node:p}=n;p?p.replace(l):l.deleteSelection()}let c=l.mapping.map(a),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=l.doc;if(u?l.replaceRangeWith(c,c,o.content.firstChild):l.replaceRange(c,c,o),l.doc.eq(f))return;let d=l.doc.resolve(c);if(u&&H.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))l.setSelection(new H(d));else{let p=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((h,m,g,y)=>p=y),l.setSelection(Pu(t,d,l.doc.resolve(p)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}Xe.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&pn(t)},20))};Xe.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Xe.beforeinput=(t,e)=>{if(Ne&&fn&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,wr(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Ye)Xe[t]=Ye[t];function Lo(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}var Ta=class t{constructor(e,n){this.toDOM=e,this.spec=n||Tr,this.side=this.spec.side||0}map(e,n,r,i){let{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new le(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof t&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Lo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Er=class t{constructor(e,n){this.attrs=e,this.spec=n||Tr}map(e,n,r,i){let o=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new le(o,s,this)}valid(e,n){return n.from<n.to}eq(e){return this==e||e instanceof t&&Lo(this.attrs,e.attrs)&&Lo(this.spec,e.spec)}static is(e){return e.type instanceof t}destroy(){}},Ru=class t{constructor(e,n){this.attrs=e,this.spec=n||Tr}map(e,n,r,i){let o=e.mapResult(n.from+i,1);if(o.deleted)return null;let s=e.mapResult(n.to+i,-1);return s.deleted||s.pos<=o.pos?null:new le(o.pos-r,s.pos-r,this)}valid(e,n){let{index:r,offset:i}=e.content.findIndex(n.from),o;return i==n.from&&!(o=e.child(r)).isText&&i+o.nodeSize==n.to}eq(e){return this==e||e instanceof t&&Lo(this.attrs,e.attrs)&&Lo(this.spec,e.spec)}destroy(){}},le=class t{constructor(e,n,r){this.from=e,this.to=n,this.type=r}copy(e,n){return new t(e,n,this.type)}eq(e,n=0){return this.type.eq(e.type)&&this.from+n==e.from&&this.to+n==e.to}map(e,n,r){return this.type.map(e,this,n,r)}static widget(e,n,r){return new t(e,e,new Ta(n,r))}static inline(e,n,r,i){return new t(e,n,new Er(r,i))}static node(e,n,r,i){return new t(e,n,new Ru(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Er}get widget(){return this.type instanceof Ta}},yi=[],Tr={},oe=class t{constructor(e,n){this.local=e.length?e:yi,this.children=n.length?n:yi}static create(e,n){return n.length?Aa(n,e,0,Tr):Ue}find(e,n,r){let i=[];return this.findInner(e??0,n??1e9,i,0,r),i}findInner(e,n,r,i,o){for(let s=0;s<this.local.length;s++){let a=this.local[s];a.from<=n&&a.to>=e&&(!o||o(a.spec))&&r.push(a.copy(a.from+i,a.to+i))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<n&&this.children[s+1]>e){let a=this.children[s]+1;this.children[s+2].findInner(e-a,n-a,r,i+a,o)}}map(e,n,r){return this==Ue||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Tr)}mapInner(e,n,r,i,o){let s;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,r,i);l&&l.type.valid(n,l)?(s||(s=[])).push(l):o.onRemove&&o.onRemove(this.local[a].spec)}return this.children.length?UT(this.children,s||[],e,n,r,i,o):s?new t(s.sort(vr),yi):Ue}add(e,n){return n.length?this==Ue?t.create(e,n):this.addInner(e,n,0):this}addInner(e,n,r){let i,o=0;e.forEach((a,l)=>{let c=l+r,u;if(u=ck(n,a,c)){for(i||(i=this.children.slice());o<i.length&&i[o]<l;)o+=3;i[o]==l?i[o+2]=i[o+2].addInner(a,u,c+1):i.splice(o,0,l,l+a.nodeSize,Aa(u,a,c+1,Tr)),o+=3}});let s=lk(o?uk(n):n,-r);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||s.splice(a--,1);return new t(s.length?this.local.concat(s).sort(vr):this.local,i||this.children)}remove(e){return e.length==0||this==Ue?this:this.removeInner(e,0)}removeInner(e,n){let r=this.children,i=this.local;for(let o=0;o<r.length;o+=3){let s,a=r[o]+n,l=r[o+1]+n;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>a&&f.to<l&&(e[u]=null,(s||(s=[])).push(f));if(!s)continue;r==this.children&&(r=this.children.slice());let c=r[o+2].removeInner(s,a+1);c!=Ue?r[o+2]=c:(r.splice(o,3),o-=3)}if(i.length){for(let o=0,s;o<e.length;o++)if(s=e[o])for(let a=0;a<i.length;a++)i[a].eq(s,n)&&(i==this.local&&(i=this.local.slice()),i.splice(a--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new t(i,r):Ue}forChild(e,n){if(this==Ue)return this;if(n.isLeaf)return t.empty;let r,i;for(let a=0;a<this.children.length;a+=3)if(this.children[a]>=e){this.children[a]==e&&(r=this.children[a+2]);break}let o=e+1,s=o+n.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<s&&l.to>o&&l.type instanceof Er){let c=Math.max(o,l.from)-o,u=Math.min(s,l.to)-o;c<u&&(i||(i=[])).push(l.copy(c,u))}}if(i){let a=new t(i.sort(vr),yi);return r?new va([a,r]):a}return r||Ue}eq(e){if(this==e)return!0;if(!(e instanceof t)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let n=0;n<this.local.length;n++)if(!this.local[n].eq(e.local[n]))return!1;for(let n=0;n<this.children.length;n+=3)if(this.children[n]!=e.children[n]||this.children[n+1]!=e.children[n+1]||!this.children[n+2].eq(e.children[n+2]))return!1;return!0}locals(e){return Hu(this.localsInner(e))}localsInner(e){if(this==Ue)return yi;if(e.inlineContent||!this.local.some(Er.is))return this.local;let n=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Er||n.push(this.local[r]);return n}forEachSet(e){e(this)}};oe.empty=new oe([],[]);oe.removeOverlap=Hu;var Ue=oe.empty,va=class t{constructor(e){this.members=e}map(e,n){let r=this.members.map(i=>i.map(e,n,Tr));return t.from(r)}forChild(e,n){if(n.isLeaf)return oe.empty;let r=[];for(let i=0;i<this.members.length;i++){let o=this.members[i].forChild(e,n);o!=Ue&&(o instanceof t?r=r.concat(o.members):r.push(o))}return t.from(r)}eq(e){if(!(e instanceof t)||e.members.length!=this.members.length)return!1;for(let n=0;n<this.members.length;n++)if(!this.members[n].eq(e.members[n]))return!1;return!0}locals(e){let n,r=!0;for(let i=0;i<this.members.length;i++){let o=this.members[i].localsInner(e);if(o.length)if(!n)n=o;else{r&&(n=n.slice(),r=!1);for(let s=0;s<o.length;s++)n.push(o[s])}}return n?Hu(r?n:n.sort(vr)):yi}static from(e){switch(e.length){case 0:return Ue;case 1:return e[0];default:return new t(e.every(n=>n instanceof oe)?e:e.reduce((n,r)=>n.concat(r instanceof oe?r:r.members),[]))}}forEachSet(e){for(let n=0;n<this.members.length;n++)this.members[n].forEachSet(e)}};function UT(t,e,n,r,i,o,s){let a=t.slice();for(let c=0,u=o;c<n.maps.length;c++){let f=0;n.maps[c].forEach((d,p,h,m)=>{let g=m-h-(p-d);for(let y=0;y<a.length;y+=3){let x=a[y+1];if(x<0||d>x+u-f)continue;let C=a[y]+u-f;p>=C?a[y+1]=d<=C?-2:-1:d>=u&&g&&(a[y]+=g,a[y+1]+=g)}f+=g}),u=n.maps[c].map(u,-1)}let l=!1;for(let c=0;c<a.length;c+=3)if(a[c+1]<0){if(a[c+1]==-2){l=!0,a[c+1]=-1;continue}let u=n.map(t[c]+o),f=u-i;if(f<0||f>=r.content.size){l=!0;continue}let d=n.map(t[c+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),g=r.maybeChild(h);if(g&&m==f&&m+g.nodeSize==p){let y=a[c+2].mapInner(n,g,u+1,t[c]+o+1,s);y!=Ue?(a[c]=f,a[c+1]=p,a[c+2]=y):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=JT(a,t,e,n,i,o,s),u=Aa(c,r,0,s);e=u.local;for(let f=0;f<a.length;f+=3)a[f+1]<0&&(a.splice(f,3),f-=3);for(let f=0,d=0;f<u.children.length;f+=3){let p=u.children[f];for(;d<a.length&&a[d]<p;)d+=3;a.splice(d,0,u.children[f],u.children[f+1],u.children[f+2])}}return new oe(e.sort(vr),a)}function lk(t,e){if(!e||!t.length)return t;let n=[];for(let r=0;r<t.length;r++){let i=t[r];n.push(new le(i.from+e,i.to+e,i.type))}return n}function JT(t,e,n,r,i,o,s){function a(l,c){for(let u=0;u<l.local.length;u++){let f=l.local[u].map(r,i,c);f?n.push(f):s.onRemove&&s.onRemove(l.local[u].spec)}for(let u=0;u<l.children.length;u+=3)a(l.children[u+2],l.children[u]+c+1)}for(let l=0;l<t.length;l+=3)t[l+1]==-1&&a(t[l+2],e[l]+o+1);return n}function ck(t,e,n){if(e.isLeaf)return null;let r=n+e.nodeSize,i=null;for(let o=0,s;o<t.length;o++)(s=t[o])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),t[o]=null);return i}function uk(t){let e=[];for(let n=0;n<t.length;n++)t[n]!=null&&e.push(t[n]);return e}function Aa(t,e,n,r){let i=[],o=!1;e.forEach((a,l)=>{let c=ck(t,a,l+n);if(c){o=!0;let u=Aa(c,a,n+l+1,r);u!=Ue&&i.push(l,l+a.nodeSize,u)}});let s=lk(o?uk(t):t,-n).sort(vr);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||(r.onRemove&&r.onRemove(s[a].spec),s.splice(a--,1));return s.length||i.length?new oe(s,i):Ue}function vr(t,e){return t.from-e.from||t.to-e.to}function Hu(t){let e=t;for(let n=0;n<e.length-1;n++){let r=e[n];if(r.from!=r.to)for(let i=n+1;i<e.length;i++){let o=e[i];if(o.from==r.from){o.to!=r.to&&(e==t&&(e=t.slice()),e[i]=o.copy(o.from,r.to),Sy(e,i+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(e==t&&(e=t.slice()),e[n]=r.copy(r.from,o.from),Sy(e,i,r.copy(o.from,r.to)));break}}}return e}function Sy(t,e,n){for(;e<t.length&&vr(n,t[e])>0;)e++;t.splice(e,0,n)}function du(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=Ue&&e.push(r)}),t.cursorWrapper&&e.push(oe.create(t.state.doc,[t.cursorWrapper.deco])),va.from(e)}var GT={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},XT=rt&&$n<=11,Ou=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}},Du=class{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Ou,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;i<r.length;i++)this.queue.push(r[i]);rt&&$n<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():Je&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),XT&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,GT)),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 n=0;n<e.length;n++)this.queue.push(e[n]);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(gy(this.view)){if(this.suppressingSelectionUpdates)return pn(this.view);if(rt&&$n<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ar(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 n=new Set,r;for(let o=e.focusNode;o;o=ki(o))n.add(o);for(let o=e.anchorNode;o;o=ki(o))if(n.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&gy(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,a=!1,l=[];if(e.editable)for(let u=0;u<n.length;u++){let f=this.registerMutation(n[u],l);f&&(o=o<0?f.from:Math.min(f.from,o),s=s<0?f.to:Math.max(f.to,s),f.typeOver&&(a=!0))}if(l.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||Ne&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&n.some(u=>u.type=="childList"&&u.removedNodes.length))){for(let u of l)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;for(;f&&f.nodeType==1;){if(f.contentEditable=="false"){u.parentNode.removeChild(u);break}f=f.firstChild}}}else if(Mt&&l.length){let u=l.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,d]=u;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of u){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||ZT(e,f)!=p)&&d.remove()}}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ia(r)&&(c=Bu(e))&&c.eq(_.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,pn(e),this.currentSelection.set(r),e.scrollToSelection()):(o>-1||i)&&(o>-1&&(e.docView.markDirty(o,s),YT(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,ev(e,l)),this.handleDOMChange(o,s,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||pn(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];n.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let i=e.previousSibling,o=e.nextSibling;if(rt&&$n<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:d}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(o=d)}let s=i&&i.parentNode==e.target?ze(i)+1:0,a=r.localPosFromDOM(e.target,s,-1),l=o&&o.parentNode==e.target?ze(o):e.target.childNodes.length,c=r.localPosFromDOM(e.target,l,1);return{from:a,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},My=new WeakMap,Ey=!1;function YT(t){if(!My.has(t)&&(My.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=Mt,Ey)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."),Ey=!0}}function Ty(t,e){let n=e.startContainer,r=e.startOffset,i=e.endContainer,o=e.endOffset,s=t.domAtPos(t.state.selection.anchor);return Ar(s.node,s.offset,i,o)&&([n,r,i,o]=[i,o,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:o}}function QT(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return Ty(t,i)}let n;function r(i){i.preventDefault(),i.stopImmediatePropagation(),n=i.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",r,!0),n?Ty(t,n):null}function ZT(t,e){for(let n=e.parentNode;n&&n!=t.dom;n=n.parentNode){let r=t.docView.nearestDesc(n,!0);if(r&&r.node.isBlock)return n}return null}function ev(t,e){var n;let{focusNode:r,focusOffset:i}=t.domSelectionRange();for(let o of e)if(((n=o.parentNode)===null||n===void 0?void 0:n.nodeName)=="TR"){let s=o.nextSibling;for(;s&&s.nodeName!="TD"&&s.nodeName!="TH";)s=s.nextSibling;if(s){let a=s;for(;;){let l=a.firstChild;if(!l||l.nodeType!=1||l.contentEditable=="false"||/^(BR|IMG)$/.test(l.nodeName))break;a=l}a.insertBefore(o,a.firstChild),r==o&&t.domSelection().collapse(o,i)}else o.parentNode.removeChild(o)}}function tv(t,e,n){let{node:r,fromOffset:i,toOffset:o,from:s,to:a}=t.docView.parseRange(e,n),l=t.domSelectionRange(),c,u=l.anchorNode;if(u&&t.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:l.anchorOffset}],Ia(l)||c.push({node:l.focusNode,offset:l.focusOffset})),Ne&&t.input.lastKeyCode===8)for(let g=o;g>i;g--){let y=r.childNodes[g-1],x=y.pmViewDesc;if(y.nodeName=="BR"&&!x){o=g;break}if(!x||x.size)break}let f=t.state.doc,d=t.someProp("domParser")||xt.fromSchema(t.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:nv,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),h={anchor:g+s,head:y+s}}return{doc:m,sel:h,from:s,to:a}}function nv(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Je&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Je&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}var rv=/^(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 iv(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let N=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,B=Bu(t,N);if(B&&!t.state.selection.eq(B)){if(Ne&&fn&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",S=>S(t,wr(13,"Enter"))))return;let O=t.state.tr.setSelection(B);N=="pointer"?O.setMeta("pointer",!0):N=="key"&&O.scrollIntoView(),o&&O.setMeta("composition",o),t.dispatch(O)}return}let s=t.state.doc.resolve(e),a=s.sharedDepth(n);e=s.before(a+1),n=t.state.doc.resolve(n).after(a+1);let l=t.state.selection,c=tv(t,e,n),u=t.state.doc,f=u.slice(c.from,c.to),d,p;t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime?(d=t.state.selection.to,p="end"):(d=t.state.selection.from,p="start"),t.input.lastKeyCode=null;let h=av(f.content,c.doc.content,c.from,d,p);if(h&&t.input.domChangeCount++,(bi&&t.input.lastIOSEnter>Date.now()-225||fn)&&i.some(N=>N.nodeType==1&&!rv.test(N.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",N=>N(t,wr(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&l instanceof P&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let N=vy(t,t.state.doc,c.sel);if(N&&!N.eq(t.state.selection)){let B=t.state.tr.setSelection(N);o&&B.setMeta("composition",o),t.dispatch(B)}}return}t.state.selection.from<t.state.selection.to&&h.start==h.endB&&t.state.selection instanceof P&&(h.start>t.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=c.from?h.start=t.state.selection.from:h.endA<t.state.selection.to&&h.endA>=t.state.selection.to-2&&t.state.selection.to<=c.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),rt&&$n<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>c.from&&c.doc.textBetween(h.start-c.from-1,h.start-c.from+1)==" \xA0"&&(h.start--,h.endA--,h.endB--);let m=c.doc.resolveNoCache(h.start-c.from),g=c.doc.resolveNoCache(h.endB-c.from),y=u.resolve(h.start),x=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=h.endA;if((bi&&t.input.lastIOSEnter>Date.now()-225&&(!x||i.some(N=>N.nodeName=="DIV"||N.nodeName=="P"))||!x&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(c.doc.textBetween(m.pos,g.pos,"","")))&&t.someProp("handleKeyDown",N=>N(t,wr(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&sv(u,h.start,h.endA,m,g)&&t.someProp("handleKeyDown",N=>N(t,wr(8,"Backspace")))){fn&&Ne&&t.domObserver.suppressSelectionUpdates();return}Ne&&h.endB==h.start&&(t.input.lastChromeDelete=Date.now()),fn&&!x&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==h.endA&&(h.endB-=2,g=c.doc.resolveNoCache(h.endB-c.from),setTimeout(()=>{t.someProp("handleKeyDown",function(N){return N(t,wr(13,"Enter"))})},20));let C=h.start,v=h.endA,A=N=>{let B=N||t.state.tr.replace(C,v,c.doc.slice(h.start-c.from,h.endB-c.from));if(c.sel){let O=vy(t,B.doc,c.sel);O&&!(Ne&&t.composing&&O.empty&&(h.start!=h.endB||t.input.lastChromeDelete<Date.now()-100)&&(O.head==C||O.head==B.mapping.map(v)-1)||rt&&O.empty&&O.head==C)&&B.setSelection(O)}return o&&B.setMeta("composition",o),B.scrollIntoView()},w;if(x)if(m.pos==g.pos){rt&&$n<=11&&m.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>pn(t),20));let N=A(t.state.tr.delete(C,v)),B=u.resolve(h.start).marksAcross(u.resolve(h.endA));B&&N.ensureMarks(B),t.dispatch(N)}else if(h.endA==h.endB&&(w=ov(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,h.endA-y.start())))){let N=A(t.state.tr);w.type=="add"?N.addMark(C,v,w.mark):N.removeMark(C,v,w.mark),t.dispatch(N)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let N=m.parent.textBetween(m.parentOffset,g.parentOffset),B=()=>A(t.state.tr.insertText(N,C,v));t.someProp("handleTextInput",O=>O(t,C,v,N,B))||t.dispatch(B())}else t.dispatch(A());else t.dispatch(A())}function vy(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:Pu(t,e.resolve(n.anchor),e.resolve(n.head))}function ov(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,a,l;for(let u=0;u<r.length;u++)i=r[u].removeFromSet(i);for(let u=0;u<n.length;u++)o=n[u].removeFromSet(o);if(i.length==1&&o.length==0)a=i[0],s="add",l=u=>u.mark(a.addToSet(u.marks));else if(i.length==0&&o.length==1)a=o[0],s="remove",l=u=>u.mark(a.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(l(e.child(u)));if(M.from(c).eq(t))return{mark:a,type:s}}function sv(t,e,n,r,i){if(n-e<=i.pos-r.pos||pu(r,!0,!1)<i.pos)return!1;let o=t.resolve(e);if(!r.parent.isTextblock){let a=o.nodeAfter;return a!=null&&n==e+a.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=t.resolve(pu(o,!0,!0));return!s.parent.isTextblock||s.pos>n||pu(s,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(s.parent.content)}function pu(t,e,n){let r=t.depth,i=e?t.end():t.pos;for(;r>0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let o=t.node(r).maybeChild(t.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function av(t,e,n,r,i){let o=t.findDiffStart(e,n),s=n+t.size,a=n+e.size;if(o==null)return null;let{a:l,b:c}=t.findDiffEnd(e,s,a);if(i=="end"){let u=Math.max(0,o-Math.min(l,c));r-=l+u-o}if(l<o&&s<a){let u=r<=o&&r>=l?o-r:0;o-=u,c=o+(c-l),l=o}else if(c<o){let u=r<=o&&r>=c?o-r:0;o-=u,l=o+(l-c),c=o}return{start:o,endA:l,endB:c}}var Bo=class{constructor(e,n){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 vu,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(Oy),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=Ny(this),Iy(this),this.nodeViews=Ry(this),this.docView=uy(this.state.doc,Ay(this),du(this),this.dom,this),this.domObserver=new Du(this,(r,i,o,s)=>iv(this,r,i,o,s)),this.domObserver.start(),AT(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Au(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Oy),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(ok(this),s=!0),this.state=e;let a=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(a||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=Ry(this);cv(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&Au(this),this.editable=Ny(this),Iy(this);let l=du(this),c=Ay(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,c,l);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&KE(this);if(s){this.domObserver.stop();let p=f&&(rt||Ne)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&lv(i.selection,e.selection);if(f){let m=Ne?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=HT(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=uy(e.doc,c,l,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let h=this.input.mouseDown;p||!(h&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&pT(this)&&h.delaySelUpdate())?pn(this,p):(Ky(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():d&&UE(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof H){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&oy(this,n.getBoundingClientRect(),e)}else oy(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 n=0;n<this.directPlugins.length;n++){let r=this.directPlugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let n=0;n<this.state.plugins.length;n++){let r=this.state.plugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let n=0;n<this.pluginViews.length;n++){let r=this.pluginViews[n];r.update&&r.update(this,e)}}updateDraggedNode(e,n){let r=e.node,i=-1;if(r.from<this.state.doc.content.size&&this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let o=r.from+(this.state.doc.content.size-n.doc.content.size);(o>0&&o<this.state.doc.content.size&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new Ea(e.slice,e.move,i<0?void 0:H.create(this.state.doc,i))}someProp(e,n){let r=this._props&&this._props[e],i;if(r!=null&&(i=n?n(r):r))return i;for(let s=0;s<this.directPlugins.length;s++){let a=this.directPlugins[s].props[e];if(a!=null&&(i=n?n(a):a))return i}let o=this.state.plugins;if(o)for(let s=0;s<o.length;s++){let a=o[s].props[e];if(a!=null&&(i=n?n(a):a))return i}}hasFocus(){if(rt){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&&JE(this.dom),pn(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let n=this.dom.parentNode;n;n=n.parentNode)if(n.nodeType==9||n.nodeType==11&&n.host)return n.getSelection||(Object.getPrototypeOf(n).getSelection=()=>n.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ZE(this,e)}coordsAtPos(e,n=1){return _y(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return iT(this,n||this.state,e)}pasteHTML(e,n){return Do(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return Do(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return Fu(this,e)}destroy(){this.docView&&(IT(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],du(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,PE())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return RT(this,e)}domSelectionRange(){let e=this.domSelection();return e?Je&&this.root.nodeType===11&&HE(this.dom.ownerDocument)==this.dom&&QT(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Bo.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function Ay(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[le.node(0,t.state.doc.content.size,e)]}function Iy(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:le.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Ny(t){return!t.someProp("editable",e=>e(t.state)===!1)}function lv(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Ry(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function cv(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function Oy(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function gn(t,e){return t.meta={package:"@milkdown/core",group:"System",...e},t}var pk={text:(t,e,n,r)=>{let i=t.value;return/^[^*_\\]*\s+$/.test(i)?i:n.safe(i,{...r,encode:[]})},strong:(t,e,n,r)=>{let i=t.marker||n.options.strong||"*",o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i+i),o(),a},emphasis:(t,e,n,r)=>{let i=t.marker||n.options.emphasis||"*",o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i),o(),a}},U=Y({},"editorView"),_o=Y({},"editorState"),Wu=Y([],"initTimer"),fk=Y({},"editor"),Ti=Y([],"inputRules"),Dt=Y([],"prosePlugins"),vi=Y([],"remarkPlugins"),$a=Y([],"nodeView"),_a=Y([],"markView"),Nr=Y(mo().use(ei).use(ii),"remark"),xi=Y({handlers:pk,encode:[]},"remarkStringifyOptions"),Na=bt("ConfigReady");function uv(t){let e=n=>(n.record(Na),async()=>(await t(n),n.done(Na),()=>{n.clearTimer(Na)}));return gn(e,{displayName:"Config"}),e}var hn=bt("InitReady");function fv(t){let e=n=>(n.inject(fk,t).inject(Dt,[]).inject(vi,[]).inject(Ti,[]).inject($a,[]).inject(_a,[]).inject(xi,{handlers:pk,encode:[]}).inject(Nr,mo().use(ei).use(ii)).inject(Wu,[Na]).record(hn),async()=>{await n.waitTimers(Wu);let r=n.get(xi);return n.set(Nr,mo().use(ei).use(ii,r)),n.done(hn),()=>{n.remove(fk).remove(Dt).remove(vi).remove(Ti).remove($a).remove(_a).remove(xi).remove(Nr).remove(Wu).clearTimer(hn)}});return gn(e,{displayName:"Init"}),e}var Qe=bt("SchemaReady"),Ra=Y([],"schemaTimer"),$e=Y({},"schema"),wi=Y([],"nodes"),Ci=Y([],"marks");function dk(t){return{...t,parseDOM:t.parseDOM?.map(e=>({priority:t.priority,...e}))}}var hk=t=>(t.inject($e,{}).inject(wi,[]).inject(Ci,[]).inject(Ra,[hn]).record(Qe),async()=>{await t.waitTimers(Ra);let e=t.get(Nr),n=t.get(vi).reduce((i,o)=>i.use(o.plugin,o.options),e);t.set(Nr,n);let r=new sa({nodes:Object.fromEntries(t.get(wi).map(([i,o])=>[i,dk(o)])),marks:Object.fromEntries(t.get(Ci).map(([i,o])=>[i,dk(o)]))});return t.set($e,r),t.done(Qe),()=>{t.remove($e).remove(wi).remove(Ci).remove(Ra).clearTimer(Qe)}});gn(hk,{displayName:"Schema"});var mk=class{constructor(){this.#t=new Wl,this.#e=null,this.setCtx=t=>{this.#e=t},this.chain=()=>{if(this.#e==null)throw Ns();let t=this.#e,e=[],n=this.get.bind(this),r={run:()=>{let o=xr(...e),s=t.get(U);return o(s.state,s.dispatch,s)},inline:o=>(e.push(o),r),pipe:i.bind(this)};function i(o,s){let a=n(o);return e.push(a(s)),r}return r}}#t;#e;get ctx(){return this.#e}create(t,e){let n=t.create(this.#t.sliceMap);return n.set(e),n}get(t){return this.#t.get(t).get()}remove(t){return this.#t.remove(t)}call(t,e){if(this.#e==null)throw Ns();let n=this.get(t)(e),r=this.#e.get(U);return n(r.state,r.dispatch,r)}inline(t){if(this.#e==null)throw Ns();let e=this.#e.get(U);return t(e.state,e.dispatch,e)}};function gk(t="cmdKey"){return Y((()=>()=>!1),t)}var Q=Y(new mk,"commands"),Oa=Y([Qe],"commandsTimer"),Si=bt("CommandsReady"),yk=t=>{let e=new mk;return e.setCtx(t),t.inject(Q,e).inject(Oa,[Qe]).record(Si),async()=>(await t.waitTimers(Oa),t.done(Si),()=>{t.remove(Q).remove(Oa).clearTimer(Si)})};gn(yk,{displayName:"Commands"});function dv(t){return t.Backspace=xr(Bg,pa,Ag,Gc),t}var kk=class{constructor(){this.#t=null,this.#e=[],this.setCtx=t=>{this.#t=t},this.add=t=>(this.#e.push(t),()=>{this.#e=this.#e.filter(e=>e!==t)}),this.addObjectKeymap=t=>{let e=[];return Object.entries(t).forEach(([n,r])=>{if(typeof r=="function"){let i={key:n,onRun:()=>r};this.#e.push(i),e.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}else this.#e.push(r),e.push(()=>{this.#e=this.#e.filter(i=>i!==r)})}),()=>{e.forEach(n=>n())}},this.addBaseKeymap=()=>{let t=dv(Lg);return this.addObjectKeymap(t)},this.build=()=>{let t={};return this.#e.forEach(e=>{t[e.key]=[...t[e.key]||[],e]}),Object.fromEntries(Object.entries(t).map(([e,n])=>{let r=n.sort((o,s)=>(s.priority??50)-(o.priority??50));return[e,(o,s,a)=>{let l=this.#t;if(l==null)throw Qr();return xr(...r.map(c=>c.onRun(l)))(o,s,a)}]}))}}#t;#e;get ctx(){return this.#t}},qo=Y(new kk,"keymap"),ju=Y([Qe],"keymapTimer"),Mi=bt("KeymapReady"),pv=t=>{let e=new kk;return e.setCtx(t),t.inject(qo,e).inject(ju,[Qe]).record(Mi),async()=>(await t.waitTimers(ju),t.done(Mi),()=>{t.remove(qo).remove(ju).clearTimer(Mi)})},Da=bt("ParserReady"),bk=(()=>{throw Qr()}),_e=Y(bk,"parser"),Vu=Y([],"parserTimer"),xk=t=>(t.inject(_e,bk).inject(Vu,[Qe]).record(Da),async()=>{await t.waitTimers(Vu);let e=t.get(Nr),n=t.get($e);return t.set(_e,ey.create(n,e)),t.done(Da),()=>{t.remove(_e).remove(Vu).clearTimer(Da)}});gn(xk,{displayName:"Parser"});var Ei=bt("SerializerReady"),qu=Y([],"serializerTimer"),wk=(()=>{throw Qr()}),mn=Y(wk,"serializer"),Ck=t=>(t.inject(mn,wk).inject(qu,[Qe]).record(Ei),async()=>{await t.waitTimers(qu);let e=t.get(Nr),n=t.get($e);return t.set(mn,ny.create(n,e)),t.done(Ei),()=>{t.remove(mn).remove(qu).clearTimer(Ei)}});gn(Ck,{displayName:"Serializer"});var Ho=Y("","defaultValue"),Wo=Y(t=>t,"stateOptions"),La=Y([],"editorStateTimer"),Ba=bt("EditorStateReady");function hv(t,e,n){if(typeof t=="string")return e(t);if(t.type==="html")return xt.fromSchema(n).parse(t.dom);if(t.type==="json")return nt.fromJSON(n,t.value);throw eh(t)}var mv=new ee("MILKDOWN_STATE_TRACKER"),Sk=t=>(t.inject(Ho,"").inject(_o,{}).inject(Wo,e=>e).inject(La,[Da,Ei,Si,Mi]).record(Ba),async()=>{await t.waitTimers(La);let e=t.get($e),n=t.get(_e),r=t.get(Ti),i=t.get(Wo),o=t.get(Dt),s=hv(t.get(Ho),n,e),a=t.get(qo),l=a.addBaseKeymap(),c=[...o,new X({key:mv,state:{init:()=>{},apply:(d,p,h,m)=>{t.set(_o,m)}}}),Hg({rules:r}),Gg(a.build())];t.set(Dt,c);let u=i({schema:e,doc:s,plugins:c}),f=fi.create(u);return t.set(_o,f),t.done(Ba),()=>{l(),t.remove(Ho).remove(_o).remove(Wo).remove(La).clearTimer(Ba)}});gn(Sk,{displayName:"EditorState"});var Ai=Y([],"pasteRule"),Pa=Y([Qe],"pasteRuleTimer"),Fa=bt("PasteRuleReady"),Mk=t=>(t.inject(Ai,[]).inject(Pa,[Qe]).record(Fa),async()=>(await t.waitTimers(Pa),t.done(Fa),()=>{t.remove(Ai).remove(Pa).clearTimer(Fa)}));gn(Mk,{displayName:"PasteRule"});var jo=bt("EditorViewReady"),za=Y([],"editorViewTimer"),Rr=Y({},"editorViewOptions"),Vo=Y(null,"root"),Ku=Y(null,"rootDOM"),Uu=Y({},"rootAttrs");function gv(t,e){let n=document.createElement("div");n.className="milkdown",t.appendChild(n),e.set(Ku,n);let r=e.get(Uu);return Object.entries(r).forEach(([i,o])=>n.setAttribute(i,o)),n}function yv(t){t.classList.add("editor"),t.setAttribute("role","textbox")}var kv=new ee("MILKDOWN_VIEW_CLEAR"),Ek=t=>(t.inject(Vo,document.body).inject(U,{}).inject(Rr,{}).inject(Ku,null).inject(Uu,{}).inject(za,[Ba,Fa]).record(jo),async()=>{await t.wait(hn);let e=t.get(Vo)||document.body,n=typeof e=="string"?document.querySelector(e):e;t.update(Dt,s=>[new X({key:kv,view:a=>{let l=n?gv(n,t):void 0;return(()=>{if(l&&n){let u=a.dom;n.replaceChild(l,u),l.appendChild(u)}})(),{destroy:()=>{l?.parentNode&&l?.parentNode.replaceChild(a.dom,l),l?.remove()}}}}),...s]),await t.waitTimers(za);let r=t.get(_o),i=t.get(Rr),o=new Bo(n,{state:r,nodeViews:Object.fromEntries(t.get($a)),markViews:Object.fromEntries(t.get(_a)),transformPasted:(s,a,l)=>(t.get(Ai).sort((c,u)=>(u.priority??50)-(c.priority??50)).map(c=>c.run).forEach(c=>{s=c(s,a,l)}),s),...i});return yv(o.dom),t.set(U,o),t.done(jo),()=>{o?.destroy(),t.remove(Vo).remove(U).remove(Rr).remove(Ku).remove(Uu).remove(za).clearTimer(jo)}});gn(Ek,{displayName:"EditorView"});var Tk=class vk{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Wl,this.#o=new uh,this.#i=new Map,this.#a=new Map,this.#l=new lh(this.#s,this.#o),this.#d=()=>{let e=uv(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),n=[hk,xk,Ck,yk,pv,Mk,Sk,Ek,fv(this),e];this.#c(n,this.#a)},this.#c=(e,n)=>{e.forEach(r=>{let i=this.#l.produce(this.#t?r.meta:void 0),o=r(i);n.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#u=(e,n=!1)=>Promise.all([e].flat().map(async r=>{let i=this.#i.get(r)?.cleanup;return n?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof i=="function"?i():i})),this.#p=async()=>{await Promise.all([...this.#a.entries()].map(async([e,{cleanup:n}])=>typeof n=="function"?n():n)),this.#a.clear()},this.#f=e=>{this.#e=e,this.#n(e)},this.#h=e=>[...e.entries()].map(async([n,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(n,{ctx:i,handler:o,cleanup:s})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#r.push(e),this),this.removeConfig=e=>(this.#r=this.#r.filter(n=>n!==e),this),this.use=e=>{let n=[e].flat();return n.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(n,this.#i),this},this.remove=async e=>this.#e==="OnCreate"?(console.warn("[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code."),new Promise(n=>{setTimeout(()=>{n(this.remove(e))},50)})):(await this.#u([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#f("OnCreate"),this.#d(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#h(this.#a),this.#h(this.#i)].flat()),this.#f("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(n=>{setTimeout(()=>{n(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#f("OnDestroy"),await this.#u([...this.#i.keys()],e),await this.#p(),this.#f("Destroyed"),this),this.action=e=>e(this.#l),this.inspect=()=>this.#t?[...this.#a.values(),...this.#i.values()].map(({ctx:e})=>e?.inspector?.read()).filter(e=>!!e):(console.warn("[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first."),[])}static make(){return new vk}#t;#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f;#h;get ctx(){return this.#l}get status(){return this.#e}};var bv=t=>crypto.getRandomValues(new Uint8Array(t)),xv=(t,e,n)=>{let r=256-256%t.length;if(r===256){let o=t.length-1;return(s=e)=>{if(!s)return"";let a="";for(;;){let l=n(s),c=s;for(;c--;)if(a+=t[l[c]&o],a.length>=s)return a}}}let i=Math.ceil(1.6*256*e/r);return(o=e)=>{if(!o)return"";let s="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]<r&&(s+=t[a[l]%t.length],s.length>=o))return s}}},Ak=(t,e=21)=>xv(t,e|0,bv);var MH=Ak("abcedfghicklmn",10);function z(t,e){let n=gk(t),r=i=>async()=>{r.key=n,await i.wait(Si);let o=e(i);return i.get(Q).create(n,o),r.run=s=>i.get(Q).call(t,s),()=>{i.get(Q).remove(n)}};return r}function ge(t){let e=n=>async()=>{await n.wait(Qe);let r=t(n);return n.update(Ti,i=>[...i,r]),e.inputRule=r,()=>{n.update(Ti,i=>i.filter(o=>o!==r))}};return e}function Ik(t){let e=n=>async()=>{await n.wait(Qe);let r=t(n);return n.update(Ai,i=>[...i,r]),e.pasteRule=r,()=>{n.update(Ai,i=>i.filter(o=>o!==r))}};return e}function wv(t,e){let n=r=>async()=>{let i=e(r);return r.update(Ci,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(Ci,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get($e).marks[t];if(!i)throw ah(t);return i},n}function Ha(t,e){let n=r=>async()=>{let i=e(r);return r.update(wi,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(wi,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get($e).nodes[t];if(!i)throw Rs(t);return i},n}function pe(t){let e,n=r=>async()=>(await r.wait(Qe),e=t(r),r.update(Dt,i=>[...i,e]),()=>{r.update(Dt,i=>i.filter(o=>o!==e))});return n.plugin=()=>e,n.key=()=>e.spec.key,n}function Cv(t){let e=n=>async()=>{await n.wait(Mi);let r=n.get(qo),i=t(n),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function ve(t,e){let n=Y(t,e),r=i=>(i.inject(n),()=>()=>{i.remove(n)});return r.key=n,r}function ce(t,e){let n=ve(e,t),r=Ha(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>ce(t,o(e)),i}function Lt(t,e){let n=ve(e,t),r=wv(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>Lt(t,o(e)),i}function He(t,e){let n=ve(Object.fromEntries(Object.entries(e).map(([o,{shortcuts:s,priority:a}])=>[o,{shortcuts:s,priority:a}])),`${t}Keymap`),r=Cv(o=>{let s=o.get(n.key),a=Object.entries(e).flatMap(([l,{command:c}])=>{let u=s[l],f=[u.shortcuts].flat(),d=u.priority;return f.map(p=>[p,{key:p,onRun:c,priority:d}])});return Object.fromEntries(a)}),i=[n,r];return i.ctx=n,i.shortcuts=r,i.key=n.key,i.keymap=r.keymap,i}var Tt=(t,e=()=>({}))=>ve(e,`${t}Attr`),Or=(t,e=()=>({}))=>ve(e,`${t}Attr`);function ht(t,e,n){let r=ve(n??{},t),i=s=>async()=>{await s.wait(hn);let a={plugin:e(s),options:s.get(r.key)};return s.update(vi,l=>[...l,a]),()=>{s.update(vi,l=>l.filter(c=>c!==a))}},o=[r,i];return o.id=t,o.plugin=i,o.options=r,o}function Nk(t){return e=>{let n=e.get(U),r=e.get($e),i=e.get(mn);if(!t)return i(n.state.doc);let o=n.state.doc.slice(t.from,t.to,!0),s=r.topNodeType.createAndFill(null,o.content);return s?i(s):(console.error("No document found"),"")}}function Ju(t,e=!1){return n=>{let r=n.get(U),i=n.get(_e)(t);if(!i)return;if(!e){let c=r.state.selection.content();return r.dispatch(r.state.tr.replaceSelection(new R(i.content,c.openStart,c.openEnd)).scrollIntoView())}let o=n.get($e),s=wt.fromSchema(o).serializeFragment(i.content),a=xt.fromSchema(o).parseSlice(s),l=ma(a);if(l){r.dispatch(r.state.tr.replaceSelectionWith(l,!0));return}r.dispatch(r.state.tr.replaceSelection(a))}}function Rk(t,e=!1){return n=>{let r=n.get(U),i=n.get(_e)(t);if(!i)return;if(!e){let{state:l}=r;return r.dispatch(l.tr.replace(0,l.doc.content.size,new R(i.content,0,0)))}let o=n.get($e),s=n.get(Wo)({schema:o,doc:i,plugins:n.get(Dt)}),a=fi.create(s);r.updateState(a)}}function Sv(t){return e=>{let n=e.get(_e)(t),r=e.get($e),i=wt.fromSchema(r).serializeFragment(n.content);return xt.fromSchema(r).parseSlice(i)}}function Gu(t,e){return n=>{let r=n.get(U),i=Sv(t)(n);r.dispatch(r.state.tr.replace(e.from,e.to,i))}}function Ok(t,e){return function(n,r){let{$from:i,$to:o,node:s}=n.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let a=i.node(-1);if(a.type!=t)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=t||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=M.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let y=i.depth-d;y>=i.depth-3;y--)f=M.from(i.node(y).copy(f));let p=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(M.from(t.createAndFill()));let h=i.before(i.depth-(d-1)),m=n.tr.replace(h,i.after(-p),new R(f,4-d,0)),g=-1;m.doc.nodesBetween(h,m.doc.content.size,(y,x)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=x+1)}),g>-1&&m.setSelection(_.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let l=o.pos==i.end()?a.contentMatchAt(0).defaultType:null,c=n.tr.delete(i.pos,o.pos),u=l?[e?{type:t,attrs:e}:null,{type:l}]:void 0;return yr(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function Wa(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==t);return o?n?r.node(o.depth-1).type==t?Mv(e,n,t,o):Ev(e,n,o):!0:!1}}function Mv(t,e,n,r){let i=t.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(i.step(new Fe(o-1,s,o,s,new R(M.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new ko(i.doc.resolve(r.$from.pos),i.doc.resolve(s),r.depth));let a=mr(r);if(a==null)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(o,-1)-1);return kr(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),e(i.scrollIntoView()),!0}function Ev(t,e,n){let r=t.tr,i=n.parent;for(let p=n.end,h=n.endIndex-1,m=n.startIndex;h>m;h--)p-=i.child(h).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let a=n.startIndex==0,l=n.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(a?0:1),u+1,s.content.append(l?M.empty:M.from(i))))return!1;let f=o.pos,d=f+s.nodeSize;return r.step(new Fe(f-(a?1:0),d+(l?1:0),f+1,d-1,new R((a?M.empty:M.from(i.copy(M.empty))).append(l?M.empty:M.from(i.copy(M.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function Dk(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==t);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let a=o.parent,l=a.child(s-1);if(l.type!=t)return!1;if(n){let c=l.lastChild&&l.lastChild.type==a.type,u=M.from(c?t.create():null),f=new R(M.from(t.create(null,M.from(a.type.create(null,u)))),c?3:1,0),d=o.start,p=o.end;n(e.tr.step(new Fe(d-(c?3:1),p,d,p,f,1,!0)).scrollIntoView())}return!0}}function Xu(t){let e=new Map;if(!t||!t.type)throw new Error("mdast-util-definitions expected node");return Nt(t,"definition",function(r){let i=Lk(r.identifier);i&&!e.get(i)&&e.set(i,r)}),n;function n(r){let i=Lk(r);return e.get(i)}}function Lk(t){return String(t||"").toUpperCase()}function ja(){return function(t){let e=Xu(t);Nt(t,function(n,r,i){if(n.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[sr,r];if(n.type==="imageReference"||n.type==="linkReference"){let o=e(n.identifier);if(o&&i&&typeof r=="number")return i.children[r]=n.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:n.alt}:{type:"link",url:o.url,title:o.title,children:n.children},[sr,r]}})}}function Bk(t,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){t.next(e.content);return}let n=[];e.content.forEach((r,i,o)=>{o!==e.childCount-1&&n.push(r)}),t.next(M.fromArray(n))}function E(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-commonmark",...e}}),t}var Yu=Or("emphasis");E(Yu,{displayName:"Attr<emphasis>",group:"Emphasis"});var Ni=Lt("emphasis",t=>({attrs:{marker:{default:t.get(xi).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",t.get(Yu.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,n)=>{e.withMark(n,"emphasis",void 0,{marker:n.attrs.marker})}}}));E(Ni.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});E(Ni.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Qu=z("ToggleEmphasis",t=>()=>Ln(Ni.type(t)));E(Qu,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var Pk=ge(t=>an(/(?:^|[^*])\*([^*]+)\*$/,Ni.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:n+1}}));E(Pk,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var Fk=ge(t=>an(/\b_(?![_\s])(.*?[^_\s])_\b/,Ni.type(t),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:n+1}}));E(Fk,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var Zu=He("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:t=>{let e=t.get(Q);return()=>e.call(Qu.key)}}});E(Zu.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});E(Zu.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var ef=Or("strong");E(ef,{displayName:"Attr<strong>",group:"Strong"});var Ko=Lt("strong",t=>({attrs:{marker:{default:t.get(xi).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:e=>e.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:e=>e==="bold"},{style:"font-weight=400",clearMark:e=>e.type.name=="strong"},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:e=>["strong",t.get(ef.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,n)=>{e.withMark(n,"strong",void 0,{marker:n.attrs.marker})}}}));E(Ko.mark,{displayName:"MarkSchema<strong>",group:"Strong"});E(Ko.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var tf=z("ToggleStrong",t=>()=>Ln(Ko.type(t)));E(tf,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var zk=ge(t=>an(/(?<![\w:/])(?:\*\*|__)([^*_]+?)(?:\*\*|__)(?![\w/])$/,Ko.type(t),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));E(zk,{displayName:"InputRule<strong>",group:"Strong"});var nf=He("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:t=>{let e=t.get(Q);return()=>e.call(tf.key)}}});E(nf.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});E(nf.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var rf=Or("inlineCode");E(rf,{displayName:"Attr<inlineCode>",group:"InlineCode"});var jn=Lt("inlineCode",t=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",t.get(rf.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,n,r)=>{e.openMark(r),e.addText(n.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,n,r)=>(e.withMark(n,"inlineCode",r.text||""),!0)}}));E(jn.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});E(jn.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var of=z("ToggleInlineCode",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,jn.type(t))?(n?.(i.removeMark(o,s,jn.type(t))),!0):(Object.keys(e.schema.marks).filter(a=>a!==jn.type.name).map(a=>e.schema.marks[a]).forEach(a=>{i.removeMark(o,s,a)}),n?.(i.addMark(o,s,jn.type(t).create())),!0)});E(of,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var $k=ge(t=>an(/(?:`)([^`]+)(?:`)$/,jn.type(t)));E($k,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var sf=He("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:t=>{let e=t.get(Q);return()=>e.call(of.key)}}});E(sf.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});E(sf.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var Tv=new Set(["http:","https:","mailto:","tel:","ftp:"]);function vv(t){return t<=32||t>=127&&t<=160||t>=8203&&t<=8205||t===8232||t===8233||t===65279}function Av(t){let e="";for(let n of t)vv(n.codePointAt(0)??0)||(e+=n);return e}function Iv(t){if(typeof t!="string")return"";let e=t.trim();if(!e)return"";let n=Av(e),r=/^([a-z][a-z0-9+.-]*):/i.exec(n)?.[1];return!r||Tv.has(`${r.toLowerCase()}:`)?e:""}var af=Or("link");E(af,{displayName:"Attr<link>",group:"Link"});var Ii=Lt("link",t=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw ft(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...t.get(af.key)(e),...e.attrs,href:Iv(e.attrs.href)}],parseMarkdown:{match:e=>e.type==="link",runner:(e,n,r)=>{let i=n.url,o=n.title;e.openMark(r,{href:i,title:o}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,n)=>{e.withMark(n,"link",void 0,{title:n.attrs.title,url:n.attrs.href})}}}));E(Ii.mark,{displayName:"MarkSchema<link>",group:"Link"});var _k=z("ToggleLink",t=>(e={})=>Ln(Ii.type(t),e));E(_k,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Hk=z("UpdateLink",t=>(e={})=>(n,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=n,{from:a,to:l}=s;if(n.doc.nodesBetween(a,a===l?l+1:l,(h,m)=>{if(Ii.type(t).isInSet(h.marks))return i=h,o=m,!1}),!i)return!1;let c=i.marks.find(({type:h})=>h===Ii.type(t));if(!c)return!1;let u=o,f=o+i.nodeSize,{tr:d}=n,p=Ii.type(t).create({...c.attrs,...e});return p?(r(d.removeMark(u,f,c).addMark(u,f,p).setSelection(new P(d.selection.$anchor)).scrollIntoView()),!0):!1});E(Hk,{displayName:"Command<updateLinkCommand>",group:"Link"});var Wk=Ha("doc",()=>({content:"block+",parseMarkdown:{match:({type:t})=>t==="root",runner:(t,e,n)=>{t.injectRoot(e,n)}},toMarkdown:{match:t=>t.type.name==="doc",runner:(t,e)=>{t.openNode("root"),t.next(e.content)}}}));E(Wk,{displayName:"NodeSchema<doc>",group:"Doc"});function Nv(t){return ar(t,e=>e.type==="html"&&["<br />","<br>","<br >","<br/>"].includes(e.value?.trim()),(e,n)=>{if(!n.length)return;let r=n[n.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var qa=ht("remark-preserve-empty-line",()=>()=>Nv);E(qa.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});E(qa.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var lf=Tt("paragraph");E(lf,{displayName:"Attr<paragraph>",group:"Paragraph"});var Bt=ce("paragraph",t=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",t.get(lf.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,n,r)=>{e.openNode(r),n.children?e.next(n.children):e.addText(n.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,n)=>{let r=t.get(U).state?.doc.lastChild;e.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&Rv(t)?e.addNode("html",void 0,"<br />"):Bk(e,n),e.closeNode()}}}));function Rv(t){let e=!1;try{t.get(qa.id),e=!0}catch{e=!1}return e}E(Bt.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});E(Bt.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var cf=z("TurnIntoText",t=>()=>Dn(Bt.type(t)));E(cf,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var uf=He("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:t=>{let e=t.get(Q);return()=>e.call(cf.key)}}});E(uf.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});E(uf.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var Ov=Array(6).fill(0).map((t,e)=>e+1);function Dv(t){return t.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Ka=ve(Dv,"headingIdGenerator");E(Ka,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var ff=Tt("heading");E(ff,{displayName:"Attr<heading>",group:"Heading"});var Lr=ce("heading",t=>{let e=t.get(Ka.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:Ov.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw ft(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...t.get(ff.key)(n),id:n.attrs.id||e(n)},0],parseMarkdown:{match:({type:n})=>n==="heading",runner:(n,r,i)=>{let o=r.depth;n.openNode(i,{level:o}),n.next(r.children),n.closeNode()}},toMarkdown:{match:n=>n.type.name==="heading",runner:(n,r)=>{n.openNode("heading",void 0,{depth:r.attrs.level}),Bk(n,r),n.closeNode()}}}});E(Lr.node,{displayName:"NodeSchema<heading>",group:"Heading"});E(Lr.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var jk=ge(t=>Zc(/^(?<hashes>#+)\s$/,Lr.type(t),e=>{let n=e.groups?.hashes?.length||0,{$from:r}=t.get(U).state.selection,i=r.node();if(i.type.name==="heading"){let o=Number(i.attrs.level)+Number(n);return o>6&&(o=6),{level:o}}return{level:n}}));E(jk,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var Wn=z("WrapInHeading",t=>e=>(e??=1,e<1?Dn(Bt.type(t)):Dn(Lr.type(t),{level:e})));E(Wn,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var df=z("DowngradeHeading",t=>()=>(e,n,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==Lr.type(t)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(n?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):Dn(Bt.type(t))(e,n,r)});E(df,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var pf=He("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:t=>{let e=t.get(Q);return()=>e.call(Wn.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:t=>{let e=t.get(Q);return()=>e.call(df.key)}}});E(pf.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});E(pf.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var hf=Tt("blockquote");E(hf,{displayName:"Attr<blockquote>",group:"Blockquote"});var Uo=ce("blockquote",t=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",t.get(hf.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,n,r)=>{e.openNode(r).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,n)=>{e.openNode("blockquote").next(n.content).closeNode()}}}));E(Uo.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});E(Uo.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var Vk=ge(t=>ha(/^\s*>\s$/,Uo.type(t)));E(Vk,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var mf=z("WrapInBlockquote",t=>()=>pi(Uo.type(t)));E(mf,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var gf=He("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:t=>{let e=t.get(Q);return()=>e.call(mf.key)}}});E(gf.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});E(gf.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var yf=Tt("codeBlock",()=>({pre:{},code:{}}));E(yf,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var Jo=ce("code_block",t=>({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 ft(e);return{language:e.dataset.language}}}],toDOM:e=>{let n=t.get(yf.key)(e),r=e.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,n,r)=>{let i=n.lang??"",o=n.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,n)=>{e.addNode("code",void 0,n.content.firstChild?.text||"",{lang:n.attrs.language})}}}));E(Jo.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});E(Jo.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var qk=ge(t=>Zc(/^```(?<language>[a-z]*)?[\s\n]$/,Jo.type(t),e=>({language:e.groups?.language??""})));E(qk,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var kf=z("CreateCodeBlock",t=>(e="")=>Dn(Jo.type(t),{language:e}));E(kf,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var Lv=z("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(n,r)=>t>=0?(r?.(n.tr.setNodeAttribute(t,"language",e)),!0):!1);E(Lv,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var bf=He("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:t=>{let e=t.get(Q);return()=>e.call(kf.key)}}});E(bf.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});E(bf.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var xf=Tt("image");E(xf,{displayName:"Attr<image>",group:"Image"});var Ri=ce("image",t=>({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 ft(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...t.get(xf.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,n,r)=>{let i=n.url,o=n.alt,s=n.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,n)=>{e.addNode("image",void 0,void 0,{title:n.attrs.title,url:n.attrs.src,alt:n.attrs.alt})}}}));E(Ri.node,{displayName:"NodeSchema<image>",group:"Image"});E(Ri.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var Kk=z("InsertImage",t=>(e={})=>(n,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,a=Ri.type(t).create({src:i,alt:o,title:s});return a&&r(n.tr.replaceSelectionWith(a).scrollIntoView()),!0});E(Kk,{displayName:"Command<insertImageCommand>",group:"Image"});var Uk=z("UpdateImage",t=>(e={})=>(n,r)=>{let i=Kg(n.selection,Ri.type(t));if(!i)return!1;let{node:o,pos:s}=i,a={...o.attrs},{src:l,alt:c,title:u}=e;return l!==void 0&&(a.src=l),c!==void 0&&(a.alt=c),u!==void 0&&(a.title=u),r?.(n.tr.setNodeMarkup(s,void 0,a).scrollIntoView()),!0});E(Uk,{displayName:"Command<updateImageCommand>",group:"Image"});var Bv=ge(t=>new be(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,n,r,i)=>{let[o,s,a="",l]=n;return o?e.tr.replaceWith(r,i,Ri.type(t).create({src:a,alt:s,title:l})):null}));E(Bv,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Va=Tt("hardbreak",t=>({"data-type":"hardbreak","data-is-inline":t.attrs.isInline}));E(Va,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Dr=ce("hardbreak",t=>({inline:!0,group:"inline",attrs:{isInline:{default:!1,validate:"boolean"}},selectable:!1,parseDOM:[{tag:"br"},{tag:'span[data-type="hardbreak"]',getAttrs:()=>({isInline:!0})}],toDOM:e=>e.attrs.isInline?["span",t.get(Va.key)(e)," "]:["br",t.get(Va.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,n,r)=>{e.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>` `,toMarkdown:{match:e=>e.type.name==="hardbreak",runner:(e,n)=>{n.attrs.isInline?e.addNode("text",void 0,` -`):e.addNode("break")}}}));E(Dr.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});E(Dr.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var wf=z("InsertHardbreak",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(!(r instanceof P))return!1;if(r.empty){let o=r.$from.node();if(o.childCount>0&&o.lastChild?.type.name==="hardbreak")return n?.(i.replaceRangeWith(r.to-1,r.to,e.schema.node("paragraph")).setSelection(_.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(i.setMeta("hardbreak",!0).replaceSelectionWith(Dr.type(t).create()).scrollIntoView()),!0});E(wf,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Cf=He("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:t=>{let e=t.get(Q);return()=>e.call(wf.key)}}});E(Cf.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});E(Cf.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Sf=Tt("hr");E(Sf,{displayName:"Attr<hr>",group:"Hr"});var Go=ce("hr",t=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",t.get(Sf.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,n,r)=>{e.addNode(r)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));E(Go.node,{displayName:"NodeSchema<hr>",group:"Hr"});E(Go.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var Uk=ge(t=>new be(/^(?:---|___\s|\*\*\*\s)$/,(e,n,r,i)=>{let{tr:o}=e;return n[0]&&o.replaceWith(r-1,i,Go.type(t).create()),o}));E(Uk,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var Jk=z("InsertHr",t=>()=>(e,n)=>{if(!n)return!0;let r=Bt.node.type(t).create(),{tr:i,selection:o}=e,{from:s}=o,a=Go.type(t).create();if(!a)return!0;let l=i.replaceSelectionWith(a).insert(s,r),c=_.findFrom(l.doc.resolve(s),1,!0);return c&&n(l.setSelection(c).scrollIntoView()),!0});E(Jk,{displayName:"Command<insertHrCommand>",group:"Hr"});var Mf=Tt("bulletList");E(Mf,{displayName:"Attr<bulletList>",group:"BulletList"});var Oi=ce("bullet_list",t=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw ft(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...t.get(Mf.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"false";e.openNode(r,{spread:i}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!1,spread:n.attrs.spread}).next(n.content).closeNode()}}}));E(Oi.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});E(Oi.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var Gk=ge(t=>ha(/^\s*([-+*])\s$/,Oi.type(t)));E(Gk,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var Ef=z("WrapInBulletList",t=>()=>pi(Oi.type(t)));E(Ef,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Tf=He("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:t=>{let e=t.get(Q);return()=>e.call(Ef.key)}}});E(Tf.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});E(Tf.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var vf=Tt("orderedList");E(vf,{displayName:"Attr<orderedList>",group:"OrderedList"});var Di=ce("ordered_list",t=>({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 ft(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...t.get(vf.key)(e),...e.attrs.order===1?{}:{start:e.attrs.order},"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{spread:i,order:n.start??1}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!0,start:n.attrs.order??1,spread:n.attrs.spread==="true"}),e.next(n.content),e.closeNode()}}}));E(Di.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});E(Di.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var Xk=ge(t=>ha(/^\s*(\d+)\.\s$/,Di.type(t),e=>({order:Number(e[1])}),(e,n)=>n.childCount+n.attrs.order===Number(e[1])));E(Xk,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Af=z("WrapInOrderedList",t=>()=>pi(Di.type(t)));E(Af,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var If=He("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:t=>{let e=t.get(Q);return()=>e.call(Af.key)}}});E(If.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});E(If.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Nf=Tt("listItem");E(Nf,{displayName:"Attr<listItem>",group:"ListItem"});var Vt=ce("list_item",t=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"\u2022",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw ft(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...t.get(Nf.key)(e),"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e})=>e==="listItem",runner:(e,n,r)=>{let i=n.label!=null?`${n.label}.`:"\u2022",o=n.label!=null?"ordered":"bullet",s=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{label:i,listType:o,spread:s}),e.next(n.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,n)=>{e.openNode("listItem",void 0,{spread:n.attrs.spread}),e.next(n.content),e.closeNode()}}}));E(Vt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});E(Vt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Rf=z("SinkListItem",t=>()=>Ok(Vt.type(t)));E(Rf,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Of=z("LiftListItem",t=>()=>Wa(Vt.type(t)));E(Of,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var Df=z("SplitListItem",t=>()=>Rk(Vt.type(t)));E(Df,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Bv(t){return(e,n,r)=>{let{selection:i}=e;if(!(i instanceof P))return!1;let{empty:o,$from:s}=i;return!o||s.parentOffset!==0||s.node(-1).type!==Vt.type(t)?!1:Jc(e,n,r)}}var Lf=z("LiftFirstListItem",t=>()=>Bv(t));E(Lf,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Bf=He("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:t=>{let e=t.get(Q);return()=>e.call(Df.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:t=>{let e=t.get(Q);return()=>e.call(Rf.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:t=>{let e=t.get(Q);return()=>e.call(Of.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:t=>{let e=t.get(Q);return()=>e.call(Lf.key)}}});E(Bf.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});E(Bf.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var Yk=Ha("text",()=>({group:"inline",parseMarkdown:{match:({type:t})=>t==="text",runner:(t,e)=>{t.addText(e.value)}},toMarkdown:{match:t=>t.type.name==="text",runner:(t,e)=>{t.addNode("text",void 0,e.text)}}}));E(Yk,{displayName:"NodeSchema<text>",group:"Text"});var Pf=Tt("html");E(Pf,{displayName:"Attr<html>",group:"Html"});var Ff=ce("html",t=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{let n=document.createElement("span"),r={...t.get(Pf.key)(e),"data-value":e.attrs.value,"data-type":"html"};return n.textContent=e.attrs.value,["span",r,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,n,r)=>{e.addNode(r,{value:n.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,n)=>{e.addNode("html",void 0,n.attrs.value)}}}));E(Ff.node,{displayName:"NodeSchema<html>",group:"Html"});E(Ff.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var Pv=[Hk,lf,Bt,Ka,ff,Lr,Va,Dr,hf,Uo,yf,Jo,Sf,Go,xf,Ri,Mf,Oi,vf,Di,Nf,Vt,Yu,Ni,ef,Ko,rf,jn,af,Ii,Pf,Ff,Yk].flat(),Fv=[jk,Gk,Xk,Vk,Uk,Wk].flat(),zv=[Bk,Pk,zk,Fk],$v=z("IsMarkSelected",()=>t=>e=>{if(!t)return!1;let{doc:n,selection:r}=e;return n.rangeHasMark(r.from,r.to,t)}),_v=z("IsNoteSelected",()=>t=>e=>t?Kg(e,t).hasNode:!1),Hv=z("ClearTextInCurrentBlock",()=>()=>(t,e)=>{let n=t.tr,{$from:r,$to:i}=n.selection,{pos:o}=r,{pos:s}=i,a=o-r.node().content.size;return a<0?!1:(n=n.deleteRange(a,s),e?.(n),!0)}),Wv=z("SetBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr,{from:s,to:a}=o.selection;try{o.setBlockType(s,a,r,i)}catch{return!1}return n?.(o),!0}),jv=z("WrapInBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let{$from:s,$to:a}=o.selection,l=s.blockRange(a),c=l&&gr(l,r,i);if(!c)return!1;o=o.wrap(l,c)}catch{return!1}return n?.(o),!0}),Vv=z("AddBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let s=r instanceof nt?r:r.createAndFill(i);if(!s)return!1;o.replaceSelectionWith(s)}catch{return!1}return n?.(o),!0}),qv=z("SelectTextNearPos",()=>t=>(e,n)=>{let{pos:r}=t??{};if(r==null)return!1;let i=(s,a,l)=>Math.min(Math.max(s,a),l),o=e.tr;try{let s=e.doc.resolve(i(r,0,e.doc.content.size));o.setSelection(P.near(s))}catch{return!1}return n?.(o.scrollIntoView()),!0}),Kv=[cf,mf,Wn,df,kf,wf,Jk,qk,Kk,Af,Ef,Rf,Df,Of,Lf,Qu,of,tf,$k,_k,$v,_v,Hv,Wv,jv,Vv,qv],Uv=[gf,bf,Cf,pf,Bf,If,Tf,uf,Zu,sf,nf].flat(),zf=ht("remarkAddOrderInList",()=>()=>t=>{Nt(t,"list",e=>{if(e.ordered){let n=e.start??1;e.children.forEach((r,i)=>{r.label=i+n})}})});E(zf.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});E(zf.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var $f=ht("remarkLineBreak",()=>()=>t=>{let e=/[\t ]*(?:\r?\n|\r)/g;Nt(t,"text",(n,r,i)=>{if(!n.value||typeof n.value!="string")return;let o=[],s=0;e.lastIndex=0;let a=e.exec(n.value);for(;a;){let l=a.index;s!==l&&o.push({type:"text",value:n.value.slice(s,l)}),o.push({type:"break",data:{isInline:!0}}),s=l+a[0].length,a=e.exec(n.value)}if(o.length>0&&i&&typeof r=="number")return s<n.value.length&&o.push({type:"text",value:n.value.slice(s)}),i.children.splice(r,1,...o),r+o.length})});E($f.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});E($f.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var _f=ht("remarkInlineLink",()=>ja);E(_f.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});E(_f.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var Jv=t=>!!t.children,Gv=t=>t.type==="html";function Xv(t,e){return n(t,0,null)[0];function n(r,i,o){if(Jv(r)){let s=[];for(let a=0,l=r.children.length;a<l;a++){let c=r.children[a];if(c){let u=n(c,a,r);if(u)for(let f=0,d=u.length;f<d;f++){let p=u[f];p&&s.push(p)}}}r.children=s}return e(r,i,o)}}var Yv=["root","blockquote","listItem"],Hf=ht("remarkHTMLTransformer",()=>()=>t=>{Xv(t,(e,n,r)=>Gv(e)?(r&&Yv.includes(r.type)&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});E(Hf.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});E(Hf.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var Wf=ht("remarkMarker",()=>()=>(t,e)=>{let n=r=>e.value.charAt(r.position.start.offset);Nt(t,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});E(Wf.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});E(Wf.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var Qk=pe(()=>{let t=!1,e=new X({key:new ee("MILKDOWN_INLINE_NODES_CURSOR"),state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;let r=n.selection.$from,i=r.nodeBefore,o=r.nodeAfter;return!!(i&&o&&i.isInline&&!i.isText&&o.isInline&&!o.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>t?(t=!1,requestAnimationFrame(()=>{if(e.getState(n.state)){let i=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i))}}),!0):!1,compositionstart:n=>(e.getState(n.state)&&(t=!0),!1),beforeinput:(n,r)=>{if(e.getState(n.state)&&r instanceof InputEvent&&r.data&&!t){let i=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i)),!0}return!1}},decorations(n){if(e.getState(n)){let r=n.selection.$from.pos,i=document.createElement("span"),o=le.widget(r,i,{side:-1}),s=document.createElement("span"),a=le.widget(r,s);return setTimeout(()=>{i.contentEditable="true",s.contentEditable="true"}),ae.create(n.doc,[o,a])}return ae.empty}}});return e});E(Qk,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Zk=pe(t=>new X({key:new ee("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,n,r)=>{if(!e.length)return;let[i]=e;if(!i)return;let[o]=i.steps;if(i.getMeta("hardbreak")){if(!(o instanceof xe))return;let{from:s}=o;return r.tr.setNodeMarkup(s,Dr.type(t),void 0,[])}if(o instanceof pr){let s=r.tr,{from:a,to:l}=o;return r.doc.nodesBetween(a,l,(c,u)=>{c.type===Dr.type(t)&&(s=s.setNodeMarkup(u,Dr.type(t),void 0,[]))}),s}}}));E(Zk,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var jf=ve(["table","code_block"],"hardbreakFilterNodes");E(jf,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var eb=pe(t=>{let e=t.get(jf.key);return new X({key:new ee("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(n,r)=>{let i=n.getMeta("hardbreak"),[o]=n.steps;if(i&&o){let{from:s}=o,a=r.doc.resolve(s),l=a.depth,c=!0;for(;l>0;)e.includes(a.node(l).type.name)&&(c=!1),l--;return c}return!0}})});E(eb,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var tb=pe(t=>{let e=new ee("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;let i=t.get(Ka.key),o=r.state.tr.setMeta("addToHistory",!1),s=!1,a={};r.state.doc.descendants((l,c)=>{if(l.type===Lr.type(t)){if(l.textContent.trim().length===0)return;let u=l.attrs,f=i(l);a[f]?(a[f]+=1,f+=`-#${a[f]}`):a[f]=1,u.id!==f&&(s=!0,o.setMeta(e,!0).setNodeMarkup(c,void 0,{...u,id:f}))}}),s&&r.dispatch(o)};return new X({key:e,view:r=>(n(r),{update:(i,o)=>{i.state.doc.eq(o.doc)||n(i)}})})});E(tb,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var nb=pe(t=>{let e=(n,r,i)=>{if(!i.selection||n.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;let o=Di.type(t),s=Oi.type(t),a=Vt.type(t),l=(f,d,p=1)=>{let h=!1,m=`${d+p}.`;return f.label!==m&&(f.label=m,h=!0),h},c=i.tr,u=!1;return i.doc.descendants((f,d,p,h)=>{if(f.type===s){let m=f.maybeChild(0);m?.type===a&&m.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(d,o,{spread:"true"}),f.descendants((g,y,x,C)=>{if(g.type===a){let v={...g.attrs};l(v,C)&&(c=c.setNodeMarkup(y,void 0,v))}return!1}))}else if(f.type===a&&p?.type===o){let m={...f.attrs},g=!1;m.listType!=="ordered"&&(m.listType="ordered",g=!0),p?.maybeChild(0)&&(g=l(m,h,p?.attrs.order??1)),g&&(c=c.setNodeMarkup(d,void 0,m),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new X({key:new ee("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});E(nb,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Qv=[Zk,jf,eb,Qk,zf,_f,$f,Hf,Wf,qa,tb,nb].flat(),rb=[Pv,Fv,zv,Kv,Uv,Qv].flat();var qf,Kf;if(typeof WeakMap<"u"){let t=new WeakMap;qf=e=>t.get(e),Kf=(e,n)=>(t.set(e,n),n)}else{let t=[],n=0;qf=r=>{for(let i=0;i<t.length;i+=2)if(t[i]==r)return t[i+1]},Kf=(r,i)=>(n==10&&(n=0),t[n++]=r,t[n++]=i)}var oe=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e<this.map.length;e++){let n=this.map[e];if(n!=t)continue;let r=e%this.width,i=e/this.width|0,o=r+1,s=i+1;for(let a=1;o<this.width&&this.map[e+a]==n;a++)o++;for(let a=1;s<this.height&&this.map[e+this.width*a]==n;a++)s++;return{left:r,top:i,right:o,bottom:s}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){let{left:r,right:i,top:o,bottom:s}=this.findCell(t);return e=="horiz"?(n<0?r==0:i==this.width)?null:this.map[o*this.width+(n<0?r-1:i)]:(n<0?o==0:s==this.height)?null:this.map[r+this.width*(n<0?o-1:s)]}rectBetween(t,e){let{left:n,right:r,top:i,bottom:o}=this.findCell(t),{left:s,right:a,top:l,bottom:c}=this.findCell(e);return{left:Math.min(n,s),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(o,c)}}cellsInRect(t){let e=[],n={};for(let r=t.top;r<t.bottom;r++)for(let i=t.left;i<t.right;i++){let o=r*this.width+i,s=this.map[o];n[s]||(n[s]=!0,!(i==t.left&&i&&this.map[o-1]==s||r==t.top&&r&&this.map[o-this.width]==s)&&e.push(s))}return e}positionAt(t,e,n){for(let r=0,i=0;;r++){let o=i+n.child(r).nodeSize;if(r==t){let s=e+t*this.width,a=(t+1)*this.width;for(;s<a&&this.map[s]<i;)s++;return s==a?o-1:this.map[s]}i=o}}static get(t){return qf(t)||Kf(t,Zv(t))}};function Zv(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);let e=eA(t),n=t.childCount,r=[],i=0,o=null,s=[];for(let c=0,u=e*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){let f=t.child(c);u++;for(let h=0;;h++){for(;i<r.length&&r[i]!=0;)i++;if(h==f.childCount)break;let m=f.child(h),{colspan:g,rowspan:y,colwidth:x}=m.attrs;for(let C=0;C<y;C++){if(C+c>=n){(o||(o=[])).push({type:"overlong_rowspan",pos:u,n:y-C});break}let v=i+C*e;for(let A=0;A<g;A++){r[v+A]==0?r[v+A]=u:(o||(o=[])).push({type:"collision",row:c,pos:u,n:g-A});let w=x&&x[A];if(w){let N=(v+A)%e*2,B=s[N];B==null||B!=w&&s[N+1]==1?(s[N]=w,s[N+1]=1):B==w&&s[N+1]++}}}i+=g,u+=m.nodeSize}let d=(c+1)*e,p=0;for(;i<d;)r[i++]==0&&p++;p&&(o||(o=[])).push({type:"missing",row:c,n:p}),u++}(e===0||n===0)&&(o||(o=[])).push({type:"zero_sized"});let a=new oe(e,n,r,o),l=!1;for(let c=0;!l&&c<s.length;c+=2)s[c]!=null&&s[c+1]<n&&(l=!0);return l&&tA(a,s,t),a}function eA(t){let e=-1,n=!1;for(let r=0;r<t.childCount;r++){let i=t.child(r),o=0;if(n)for(let s=0;s<r;s++){let a=t.child(s);for(let l=0;l<a.childCount;l++){let c=a.child(l);s+c.attrs.rowspan>r&&(o+=c.attrs.colspan)}}for(let s=0;s<i.childCount;s++){let a=i.child(s);o+=a.attrs.colspan,a.attrs.rowspan>1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function tA(t,e,n){t.problems||(t.problems=[]);let r={};for(let i=0;i<t.map.length;i++){let o=t.map[i];if(r[o])continue;r[o]=!0;let s=n.nodeAt(o);if(!s)throw new RangeError(`No cell with offset ${o} found`);let a=null,l=s.attrs;for(let c=0;c<l.colspan;c++){let u=e[(i+c)%t.width*2];u!=null&&(!l.colwidth||l.colwidth[c]!=u)&&((a||(a=nA(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function nA(t){if(t.colwidth)return t.colwidth.slice();let e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function ib(t,e){if(typeof t=="string")return{};let n=t.getAttribute("data-colwidth"),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(s=>Number(s)):null,i=Number(t.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let a=e[s].getFromDOM,l=a&&a(t);l!=null&&(o[s]=l)}return o}function ob(t,e){let n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan),t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan),t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(t.attrs[r],n)}return n}function rA(t){if(t!==null){if(!Array.isArray(t))throw new TypeError("colwidth must be null or an array");for(let e of t)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function yb(t){let e=t.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:rA}};for(let r in e)n[r]={default:e[r].default,validate:e[r].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:t.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:t.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>ib(r,e)}],toDOM(r){return["td",ob(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ib(r,e)}],toDOM(r){return["th",ob(r,e),0]}}}}function Ze(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(let n in t.nodes){let r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Vn=new ee("selectingCells");function Pi(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function Re(t){let e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function Qa(t){let e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let n=Pi(e.$head)||iA(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function iA(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function Uf(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function oA(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function Xf(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function kb(t,e,n){let r=t.node(-1),i=oe.get(r),o=t.start(-1),s=i.nextCell(t.pos-o,e,n);return s==null?null:t.node(0).resolve(o+s)}function Br(t,e,n=1){let r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function sA(t,e,n=1){let r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(e,0,0)}return r}function aA(t,e,n){let r=Ze(e.type.schema).header_cell;for(let i=0;i<t.height;i++)if(e.nodeAt(t.map[n+i*t.width]).type!=r)return!1;return!0}var he=class yn extends _{constructor(e,n=e){let r=e.node(-1),i=oe.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,n.pos-o),a=e.node(0),l=i.cellsInRect(s).filter(u=>u!=n.pos-o);l.unshift(n.pos-o);let c=l.map(u=>{let f=r.nodeAt(u);if(!f)throw new RangeError(`No cell with offset ${u} found`);let d=o+u+1;return new On(a.resolve(d),a.resolve(d+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){let r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(Uf(r)&&Uf(i)&&Xf(r,i)){let o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?yn.rowSelection(r,i):o&&this.isColSelection()?yn.colSelection(r,i):new yn(r,i)}return P.between(r,i)}content(){let e=this.$anchorCell.node(-1),n=oe.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let l=i.top;l<i.bottom;l++){let c=[];for(let u=l*n.width+i.left,f=i.left;f<i.right;f++,u++){let d=n.map[u];if(o[d])continue;o[d]=!0;let p=n.findCell(d),h=e.nodeAt(d);if(!h)throw new RangeError(`No cell with offset ${d} found`);let m=i.left-p.left,g=p.right-i.right;if(m>0||g>0){let y=h.attrs;if(m>0&&(y=Br(y,0,m)),g>0&&(y=Br(y,y.colspan-g,g)),p.left<i.left){if(h=h.type.createAndFill(y),!h)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else h=h.type.create(y,h.content)}if(p.top<i.top||p.bottom>i.bottom){let y={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top<i.top?h=h.type.createAndFill(y):h=h.type.create(y,h.content)}c.push(h)}s.push(e.child(l).copy(M.from(c)))}let a=this.isColSelection()&&this.isRowSelection()?e:s;return new R(M.from(a),1,1)}replace(e,n=R.empty){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:a,$to:l}=i[s],c=e.mapping.slice(r);e.replace(c.map(a.pos),c.map(l.pos),s?R.empty:n)}let o=_.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);o&&e.setSelection(o)}replaceWith(e,n){this.replace(e,new R(M.from(n),0,0))}forEachCell(e){let n=this.$anchorCell.node(-1),r=oe.get(n),i=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let s=0;s<o.length;s++)e(n.nodeAt(o[s]),i+o[s])}isColSelection(){let e=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(e,n)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){let r=e.node(-1),i=oe.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.top<=a.top?(s.top>0&&(e=l.resolve(o+i.map[s.left])),a.bottom<i.height&&(n=l.resolve(o+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(o+i.map[a.left])),s.bottom<i.height&&(e=l.resolve(o+i.map[i.width*(i.height-1)+s.right-1]))),new yn(e,n)}isRowSelection(){let e=this.$anchorCell.node(-1),n=oe.get(e),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),o=n.colCount(this.$headCell.pos-r);if(Math.min(i,o)>0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,a=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,a)==n.width}eq(e){return e instanceof yn&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){let r=e.node(-1),i=oe.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.left<=a.left?(s.left>0&&(e=l.resolve(o+i.map[s.top*i.width])),a.right<i.width&&(n=l.resolve(o+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(o+i.map[a.top*i.width])),s.right<i.width&&(e=l.resolve(o+i.map[i.width*(s.top+1)-1]))),new yn(e,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,n){return new yn(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){return new yn(e.resolve(n),e.resolve(r))}getBookmark(){return new lA(this.$anchorCell.pos,this.$headCell.pos)}};he.prototype.visible=!1;_.jsonID("cell",he);var lA=class bb{constructor(e,n){this.anchor=e,this.head=n}map(e){return new bb(e.map(this.anchor),e.map(this.head))}resolve(e){let n=e.resolve(this.anchor),r=e.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&Xf(n,r)?new he(n,r):_.near(r,1)}};function cA(t){if(!(t.selection instanceof he))return null;let e=[];return t.selection.forEachCell((n,r)=>{e.push(le.node(r,r+n.nodeSize,{class:"selectedCell"}))}),ae.create(t.doc,e)}function uA({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let n=t.pos,r=e.pos,i=t.depth;for(;i>=0&&!(t.after(i+1)<t.end(i));i--,n++);for(let o=e.depth;o>=0&&!(e.before(o+1)>e.start(o));o--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function fA({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){let o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&e.parentOffset===0}function dA(t,e,n){let r=(e||t).selection,i=(e||t).doc,o,s;if(r instanceof H&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=he.create(i,r.from);else if(s=="row"){let a=i.resolve(r.from+1);o=he.rowSelection(a,a)}else if(!n){let a=oe.get(r.node),l=r.from+1,c=l+a.map[a.width*a.height-1];o=he.create(i,l+1,c)}}else r instanceof P&&uA(r)?o=P.create(i,r.from):r instanceof P&&fA(r)&&(o=P.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var pA=new ee("fix-tables");function xb(t,e,n,r){let i=t.childCount,o=e.childCount;e:for(let s=0,a=0;s<o;s++){let l=e.child(s);for(let c=a,u=Math.min(i,s+3);c<u;c++)if(t.child(c)==l){a=c+1,n+=l.nodeSize;continue e}r(l,n),a<i&&t.child(a).sameMarkup(l)?xb(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function hA(t,e){let n,r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=mA(t,i,o,n))};return e?e.doc!=t.doc&&xb(e.doc,t.doc,0,r):t.doc.descendants(r),n}function mA(t,e,n,r){let i=oe.get(e);if(!i.problems)return r;r||(r=t.tr);let o=[];for(let l=0;l<i.height;l++)o.push(0);for(let l=0;l<i.problems.length;l++){let c=i.problems[l];if(c.type=="collision"){let u=e.nodeAt(c.pos);if(!u)continue;let f=u.attrs;for(let d=0;d<f.rowspan;d++)o[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,Br(f,f.colspan-c.n,c.n))}else if(c.type=="missing")o[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){let u=r.mapping.map(n);r.delete(u,u+e.nodeSize)}}let s,a;for(let l=0;l<o.length;l++)o[l]&&(s==null&&(s=l),a=l);for(let l=0,c=n+1;l<i.height;l++){let u=e.child(l),f=c+u.nodeSize,d=o[l];if(d>0){let p="cell";u.firstChild&&(p=u.firstChild.type.spec.tableRole);let h=[];for(let g=0;g<d;g++){let y=Ze(t.schema)[p].createAndFill();y&&h.push(y)}let m=(l==0||s==l-1)&&a==l?c+1:f-1;r.insert(r.mapping.map(m),h)}c=f}return r.setMeta(pA,{fixTables:!0})}function wb(t){let e=oe.get(t),n=[],r=e.height,i=e.width;for(let o=0;o<r;o++){let s=[];for(let a=0;a<i;a++){let l=o*i+a,c=e.map[l];if(o>0){let u=l-i;if(c===e.map[u]){s.push(null);continue}}if(a>0){let u=l-1;if(c===e.map[u]){s.push(null);continue}}s.push(t.nodeAt(c))}n.push(s)}return n}function Cb(t,e){let n=[],r=oe.get(t),i=r.height,o=r.width;for(let s=0;s<i;s++){let a=t.child(s),l=[];for(let u=0;u<o;u++){let f=e[s][u];if(!f)continue;let d=r.map[s*r.width+u],p=t.nodeAt(d);if(!p)continue;let h=p.type.createChecked(f.attrs,f.content,f.marks);l.push(h)}let c=a.type.createChecked(a.attrs,l,a.marks);n.push(c)}return t.type.createChecked(t.attrs,n,t.marks)}function Sb(t,e,n,r){let i=e[0]>n[0]?-1:1,o=t.splice(e[0],e.length),s=o.length%2===0?1:0,a;return r===-1&&i===1?a=n[0]-1:r===1&&i===-1?a=n[n.length-1]-s+1:a=i===-1?n[0]:n[n.length-1]-s,t.splice(a,0,...o),t}function Fi(t){return gA(e=>e.type.spec.tableRole==="table",t)}function gA(t,e){for(let n=e.depth;n>=0;n-=1){let r=e.node(n);if(t(r))return{node:r,pos:n===0?0:e.before(n),start:e.start(n),depth:n}}return null}function Li(t,e){let n=Fi(e.$from);if(!n)return;let r=oe.get(n.node);if(!(t<0||t>r.width-1))return r.cellsInRect({left:t,right:t+1,top:0,bottom:r.height}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function Bi(t,e){let n=Fi(e.$from);if(!n)return;let r=oe.get(n.node);if(!(t<0||t>r.height-1))return r.cellsInRect({left:0,right:r.width,top:t,bottom:t+1}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function sb(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Li(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Li(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;d.node.attrs.colspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Li(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Li(r,t.selection),a=Bi(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Li(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function ab(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Bi(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Bi(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;d.node.attrs.rowspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Bi(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Bi(r,t.selection),a=Li(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Bi(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function lb(t){return t[0].map((e,n)=>t.map(r=>r[n]))}function yA(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Fi(r.doc.resolve(a));if(!l)return!1;let c=(e=sb(r,i))===null||e===void 0?void 0:e.indexes,u=(n=sb(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=kA(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=oe.get(f),p=l.start,h=o,m=d.positionAt(d.height-1,h,f),g=r.doc.resolve(p+m),y=d.positionAt(0,h,f),x=r.doc.resolve(p+y);return r.setSelection(he.colSelection(g,x)),!0}function kA(t,e,n,r){let i=lb(wb(t));return i=Sb(i,e,n,r),i=lb(i),Cb(t,i)}function bA(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Fi(r.doc.resolve(a));if(!l)return!1;let c=(e=ab(r,i))===null||e===void 0?void 0:e.indexes,u=(n=ab(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=xA(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=oe.get(f),p=l.start,h=o,m=d.positionAt(h,d.width-1,f),g=r.doc.resolve(p+m),y=d.positionAt(h,0,f),x=r.doc.resolve(p+y);return r.setSelection(he.rowSelection(g,x)),!0}function xA(t,e,n,r){let i=wb(t);return i=Sb(i,e,n,r),Cb(t,i)}function vt(t){let e=t.selection,n=Qa(t),r=n.node(-1),i=n.start(-1),o=oe.get(r);return{...e instanceof he?o.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o.findCell(n.pos-i),tableStart:i,map:o,table:r}}function Mb(t,{map:e,tableStart:n,table:r},i){let o=i>0?-1:0;aA(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s<e.height;s++){let a=s*e.width+i;if(i>0&&i<e.width&&e.map[a-1]==e.map[a]){let l=e.map[a],c=r.nodeAt(l);t.setNodeMarkup(t.mapping.map(n+l),null,sA(c.attrs,i-e.colCount(l))),s+=c.attrs.rowspan-1}else{let l=o==null?Ze(r.type.schema).cell:r.nodeAt(e.map[a+o]).type,c=e.positionAt(s,i,r);t.insert(t.mapping.map(n+c),l.createAndFill())}}return t}function Eb(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(Mb(t.tr,n,n.left))}return!0}function Za(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(Mb(t.tr,n,n.right))}return!0}function wA(t,{map:e,table:n,tableStart:r},i){let o=t.mapping.maps.length;for(let s=0;s<e.height;){let a=s*e.width+i,l=e.map[a],c=n.nodeAt(l),u=c.attrs;if(i>0&&e.map[a-1]==l||i<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(o).map(r+l),null,Br(u,i-e.colCount(l)));else{let f=t.mapping.slice(o).map(r+l);t.delete(f,f+c.nodeSize)}s+=u.rowspan}}function el(t,e){if(!Re(t))return!1;if(e){let n=vt(t),r=t.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;wA(r,n,i),i!=n.left;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=oe.get(o)}e(r)}return!0}function CA(t,e,n){var r;let i=Ze(e.type.schema).header_cell;for(let o=0;o<t.width;o++)if(((r=e.nodeAt(t.map[o+n*t.width]))===null||r===void 0?void 0:r.type)!=i)return!1;return!0}function SA(t,{map:e,tableStart:n,table:r},i){let o=n;for(let c=0;c<i;c++)o+=r.child(c).nodeSize;let s=[],a=i>0?-1:0;CA(e,r,i+a)&&(a=i==0||i==e.height?null:0);for(let c=0,u=e.width*i;c<e.width;c++,u++)if(i>0&&i<e.height&&e.map[u]==e.map[u-e.width]){let f=e.map[u],d=r.nodeAt(f).attrs;t.setNodeMarkup(n+f,null,{...d,rowspan:d.rowspan+1}),c+=d.colspan-1}else{var l;let f=a==null?Ze(r.type.schema).cell:(l=r.nodeAt(e.map[u+a*e.width]))===null||l===void 0?void 0:l.type,d=f?.createAndFill();d&&s.push(d)}return t.insert(o,Ze(r.type.schema).row.create(null,s)),t}function Yf(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(SA(t.tr,n,n.bottom))}return!0}function MA(t,{map:e,table:n,tableStart:r},i){let o=0;for(let c=0;c<i;c++)o+=n.child(c).nodeSize;let s=o+n.child(i).nodeSize,a=t.mapping.maps.length;t.delete(o+r,s+r);let l=new Set;for(let c=0,u=i*e.width;c<e.width;c++,u++){let f=e.map[u];if(!l.has(f)){if(l.add(f),i>0&&f==e.map[u-e.width]){let d=n.nodeAt(f).attrs;t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d,rowspan:d.rowspan-1}),c+=d.colspan-1}else if(i<e.height&&f==e.map[u+e.width]){let d=n.nodeAt(f),p=d.attrs,h=d.type.create({...p,rowspan:d.attrs.rowspan-1},d.content),m=e.positionAt(i+1,c,n);t.insert(t.mapping.slice(a).map(r+m),h),c+=p.colspan-1}}}}function tl(t,e){if(!Re(t))return!1;if(e){let n=vt(t),r=t.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;MA(r,n,i),i!=n.top;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=oe.get(n.table)}e(r)}return!0}function Tb(t,e){return function(n,r){if(!Re(n))return!1;let i=Qa(n);if(i.nodeAfter.attrs[t]===e)return!1;if(r){let o=n.tr;n.selection instanceof he?n.selection.forEachCell((s,a)=>{s.attrs[t]!==e&&o.setNodeMarkup(a,null,{...s.attrs,[t]:e})}):o.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[t]:e}),r(o)}return!0}}function EA(t){return function(e,n){if(!Re(e))return!1;if(n){let r=Ze(e.schema),i=vt(e),o=e.tr,s=i.map.cellsInRect(t=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:t=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=s.map(l=>i.table.nodeAt(l));for(let l=0;l<s.length;l++)a[l].type==r.header_cell&&o.setNodeMarkup(i.tableStart+s[l],r.cell,a[l].attrs);if(o.steps.length===0)for(let l=0;l<s.length;l++)o.setNodeMarkup(i.tableStart+s[l],r.header_cell,a[l].attrs);n(o)}return!0}}function cb(t,e,n){let r=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let i=0;i<r.length;i++){let o=e.table.nodeAt(r[i]);if(o&&o.type!==n.header_cell)return!1}return!0}function Qf(t,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?EA(t):function(n,r){if(!Re(n))return!1;if(r){let i=Ze(n.schema),o=vt(n),s=n.tr,a=cb("row",o,i),l=cb("column",o,i),c=(t==="column"?a:t==="row"&&l)?1:0,u=t=="column"?{left:0,top:c,right:1,bottom:o.map.height}:t=="row"?{left:c,top:0,right:o.map.width,bottom:1}:o,f=t=="column"?l?i.cell:i.header_cell:t=="row"?a?i.cell:i.header_cell:i.cell;o.map.cellsInRect(u).forEach(d=>{let p=d+o.tableStart,h=s.doc.nodeAt(p);h&&s.setNodeMarkup(p,f,h.attrs)}),r(s)}return!0}}var oW=Qf("row",{useDeprecatedLogic:!0}),sW=Qf("column",{useDeprecatedLogic:!0}),aW=Qf("cell",{useDeprecatedLogic:!0});function TA(t,e){if(e<0){let n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,i=t.before();r>=0;r--){let o=t.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;let n=t.node(-1);for(let r=t.indexAfter(-1),i=t.after();r<n.childCount;r++){let o=n.child(r);if(o.childCount)return i+1;i+=o.nodeSize}}return null}function Xo(t){return function(e,n){if(!Re(e))return!1;let r=TA(Qa(e),t);if(r==null)return!1;if(n){let i=e.doc.resolve(r);n(e.tr.setSelection(P.between(i,oA(i))).scrollIntoView())}return!0}}function vb(t,e){let n=t.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function Ua(t,e){let n=t.selection;if(!(n instanceof he))return!1;if(e){let r=t.tr,i=Ze(t.schema).cell.createAndFill().content;n.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new R(i,0,0))}),r.docChanged&&e(r)}return!0}function Ab(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return bA({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function Ib(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return yA({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function vA(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;let i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,a=[];if(o=="row")for(let l=0;l<e.childCount;l++){let c=e.child(l).content,u=l?0:Math.max(0,n-1),f=l<e.childCount-1?0:Math.max(0,r-1);(u||f)&&(c=Jf(Ze(s).row,new R(c,u,f)).content),a.push(c)}else if(o=="cell"||o=="header_cell")a.push(n||r?Jf(Ze(s).row,new R(e,n,r)).content:e);else return null;return AA(s,a)}function AA(t,e){let n=[];for(let i=0;i<e.length;i++){let o=e[i];for(let s=o.childCount-1;s>=0;s--){let{rowspan:a,colspan:l}=o.child(s).attrs;for(let c=i;c<i+a;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=e.length&&e.push(M.empty),n[i]<r){let o=Ze(t).cell.createAndFill(),s=[];for(let a=n[i];a<r;a++)s.push(o);e[i]=e[i].append(M.from(s))}return{height:e.length,width:r,rows:e}}function Jf(t,e){let n=t.createAndFill();return new ci(n).replace(0,n.content.size,e).doc}function IA({width:t,height:e,rows:n},r,i){if(t!=r){let o=[],s=[];for(let a=0;a<n.length;a++){let l=n[a],c=[];for(let u=o[a]||0,f=0;u<r;f++){let d=l.child(f%l.childCount);u+d.attrs.colspan>r&&(d=d.type.createChecked(Br(d.attrs,d.attrs.colspan,u+d.attrs.colspan-r),d.content)),c.push(d),u+=d.attrs.colspan;for(let p=1;p<d.attrs.rowspan;p++)o[a+p]=(o[a+p]||0)+d.attrs.colspan}s.push(M.from(c))}n=s,t=r}if(e!=i){let o=[];for(let s=0,a=0;s<i;s++,a++){let l=[],c=n[a%e];for(let u=0;u<c.childCount;u++){let f=c.child(u);s+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),l.push(f)}o.push(M.from(l))}n=o,e=i}return{width:t,height:e,rows:n}}function NA(t,e,n,r,i,o,s){let a=t.doc.type.schema,l=Ze(a),c,u;if(i>e.width)for(let f=0,d=0;f<e.height;f++){let p=n.child(f);d+=p.nodeSize;let h=[],m;p.lastChild==null||p.lastChild.type==l.cell?m=c||(c=l.cell.createAndFill()):m=u||(u=l.header_cell.createAndFill());for(let g=e.width;g<i;g++)h.push(m);t.insert(t.mapping.slice(s).map(d-1+r),h)}if(o>e.height){let f=[];for(let h=0,m=(e.height-1)*e.width;h<Math.max(e.width,i);h++){let g=h>=e.width?!1:n.nodeAt(e.map[m+h]).type==l.header_cell;f.push(g?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}let d=l.row.create(null,M.from(f)),p=[];for(let h=e.height;h<o;h++)p.push(d);t.insert(t.mapping.slice(s).map(r+n.nodeSize-2),p)}return!!(c||u)}function ub(t,e,n,r,i,o,s,a){if(s==0||s==e.height)return!1;let l=!1;for(let c=i;c<o;c++){let u=s*e.width+c,f=e.map[u];if(e.map[u-e.width]==f){l=!0;let d=n.nodeAt(f),{top:p,left:h}=e.findCell(f);t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d.attrs,rowspan:s-p}),t.insert(t.mapping.slice(a).map(e.positionAt(s,h,n)),d.type.createAndFill({...d.attrs,rowspan:p+d.attrs.rowspan-s})),c+=d.attrs.colspan-1}}return l}function fb(t,e,n,r,i,o,s,a){if(s==0||s==e.width)return!1;let l=!1;for(let c=i;c<o;c++){let u=c*e.width+s,f=e.map[u];if(e.map[u-1]==f){l=!0;let d=n.nodeAt(f),p=e.colCount(f),h=t.mapping.slice(a).map(f+r);t.setNodeMarkup(h,null,Br(d.attrs,s-p,d.attrs.colspan-(s-p))),t.insert(h+d.nodeSize,d.type.createAndFill(Br(d.attrs,0,s-p))),c+=d.attrs.rowspan-1}}return l}function db(t,e,n,r,i){let o=n?t.doc.nodeAt(n-1):t.doc;if(!o)throw new Error("No table found");let s=oe.get(o),{top:a,left:l}=r,c=l+i.width,u=a+i.height,f=t.tr,d=0;function p(){if(o=n?f.doc.nodeAt(n-1):f.doc,!o)throw new Error("No table found");s=oe.get(o),d=f.mapping.maps.length}NA(f,s,o,n,c,u,d)&&p(),ub(f,s,o,n,l,c,a,d)&&p(),ub(f,s,o,n,l,c,u,d)&&p(),fb(f,s,o,n,a,u,l,d)&&p(),fb(f,s,o,n,a,u,c,d)&&p();for(let h=a;h<u;h++){let m=s.positionAt(h,l,o),g=s.positionAt(h,c,o);f.replace(f.mapping.slice(d).map(m+n),f.mapping.slice(d).map(g+n),new R(i.rows[h-a],0,0))}p(),f.setSelection(new he(f.doc.resolve(n+s.positionAt(a,l,o)),f.doc.resolve(n+s.positionAt(u-1,c-1,o)))),e(f)}var RA=lu({ArrowLeft:Ja("horiz",-1),ArrowRight:Ja("horiz",1),ArrowUp:Ja("vert",-1),ArrowDown:Ja("vert",1),"Shift-ArrowLeft":Ga("horiz",-1),"Shift-ArrowRight":Ga("horiz",1),"Shift-ArrowUp":Ga("vert",-1),"Shift-ArrowDown":Ga("vert",1),Backspace:Ua,"Mod-Backspace":Ua,Delete:Ua,"Mod-Delete":Ua});function Xa(t,e,n){return n.eq(t.selection)?!1:(e&&e(t.tr.setSelection(n).scrollIntoView()),!0)}function Ja(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection;if(o instanceof he)return Xa(n,r,_.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;let s=Nb(i,t,e);if(s==null)return!1;if(t=="horiz")return Xa(n,r,_.near(n.doc.resolve(o.head+e),e));{let a=n.doc.resolve(s),l=kb(a,t,e),c;return l?c=_.near(l,1):e<0?c=_.near(n.doc.resolve(a.before(-1)),-1):c=_.near(n.doc.resolve(a.after(-1)),1),Xa(n,r,c)}}}function Ga(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection,s;if(o instanceof he)s=o;else{let l=Nb(i,t,e);if(l==null)return!1;s=new he(n.doc.resolve(l))}let a=kb(s.$headCell,t,e);return a?Xa(n,r,new he(s.$anchorCell,a)):!1}}function OA(t,e){let n=t.state.doc,r=Pi(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new he(r))),!0):!1}function DA(t,e,n){if(!Re(t.state))return!1;let r=vA(n),i=t.state.selection;if(i instanceof he){r||(r={width:1,height:1,rows:[M.from(Jf(Ze(t.state.schema).cell,n))]});let o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),a=oe.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=IA(r,a.right-a.left,a.bottom-a.top),db(t.state,t.dispatch,s,a,r),!0}else if(r){let o=Qa(t.state),s=o.start(-1);return db(t.state,t.dispatch,s,oe.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function LA(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;let r=pb(t,e.target),i;if(e.shiftKey&&t.state.selection instanceof he)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Pi(t.state.selection.$anchor))!=null&&((n=Vf(t,e))===null||n===void 0?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(l,c){let u=Vf(t,c),f=Vn.getState(t.state)==null;if(!u||!Xf(l,u))if(f)u=l;else return;let d=new he(l,u);if(f||!t.state.selection.eq(d)){let p=t.state.tr.setSelection(d);f&&p.setMeta(Vn,l.pos),t.dispatch(p)}}function s(){t.root.removeEventListener("mouseup",s),t.root.removeEventListener("dragstart",s),t.root.removeEventListener("mousemove",a),Vn.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(Vn,-1))}function a(l){let c=l,u=Vn.getState(t.state),f;if(u!=null)f=t.state.doc.resolve(u);else if(pb(t,c.target)!=r&&(f=Vf(t,e),!f))return s();f&&o(f,c)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",a)}function Nb(t,e,n){if(!(t.state.selection instanceof P))return null;let{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){let o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){let s=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?s:null}}return null}function pb(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Vf(t,e){let n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Pi(t.state.doc.resolve(r))||Pi(t.state.doc.resolve(i))}var BA=class{constructor(t,e){this.node=t,this.defaultCellMinWidth=e,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",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Gf(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,Gf(t,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Gf(t,e,n,r,i,o){let s=0,a=!0,l=e.firstChild,c=t.firstChild;if(c){for(let f=0,d=0;f<c.childCount;f++){let{colspan:p,colwidth:h}=c.child(f).attrs;for(let m=0;m<p;m++,d++){let g=i==d?o:h&&h[m],y=g?g+"px":"";if(s+=g||r,g||(a=!1),l)l.style.width!=y&&(l.style.width=y),l=l.nextSibling;else{let x=document.createElement("col");x.style.width=y,e.appendChild(x)}}}for(;l;){var u;let f=l.nextSibling;(u=l.parentNode)===null||u===void 0||u.removeChild(l),l=f}a?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}var mt=new ee("tableColumnResizing");function Rb({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=BA,lastColumnResizable:i=!0}={}){let o=new X({key:mt,state:{init(s,a){var l;let c=(l=o.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews,u=Ze(a.schema).table.name;return r&&c&&(c[u]=(f,d)=>new r(f,n,d)),new PA(-1,!1)},apply(s,a){return a.apply(s)}},props:{attributes:s=>{let a=mt.getState(s);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,a)=>{FA(s,a,t,i)},mouseleave:s=>{zA(s)},mousedown:(s,a)=>{$A(s,a,e,n)}},decorations:s=>{let a=mt.getState(s);if(a&&a.activeHandle>-1)return VA(s,a.activeHandle)},nodeViews:{}}});return o}var PA=class Ya{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){let n=this,r=e.getMeta(mt);if(r&&r.setHandle!=null)return new Ya(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ya(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return Uf(e.doc.resolve(i))||(i=-1),new Ya(i,n.dragging)}return n}};function FA(t,e,n,r){if(!t.editable)return;let i=mt.getState(t.state);if(i&&!i.dragging){let o=HA(e.target),s=-1;if(o){let{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=n?s=hb(t,e,"left",n):l-e.clientX<=n&&(s=hb(t,e,"right",n))}if(s!=i.activeHandle){if(!r&&s!==-1){let a=t.state.doc.resolve(s),l=a.node(-1),c=oe.get(l),u=a.start(-1);if(c.colCount(a.pos-u)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Ob(t,s)}}}function zA(t){if(!t.editable)return;let e=mt.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Ob(t,-1)}function $A(t,e,n,r){var i;if(!t.editable)return!1;let o=(i=t.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,s=mt.getState(t.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let a=t.state.doc.nodeAt(s.activeHandle),l=_A(t,s.activeHandle,a.attrs);t.dispatch(t.state.tr.setMeta(mt,{setDragging:{startX:e.clientX,startWidth:l}}));function c(f){o.removeEventListener("mouseup",c),o.removeEventListener("mousemove",u);let d=mt.getState(t.state);d?.dragging&&(WA(t,d.activeHandle,mb(d.dragging,f,n)),t.dispatch(t.state.tr.setMeta(mt,{setDragging:null})))}function u(f){if(!f.which)return c(f);let d=mt.getState(t.state);if(d&&d.dragging){let p=mb(d.dragging,f,n);gb(t,d.activeHandle,p,r)}}return gb(t,s.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),e.preventDefault(),!0}function _A(t,e,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=t.domAtPos(e),s=o.node.childNodes[o.offset].offsetWidth,a=n;if(r)for(let l=0;l<n;l++)r[l]&&(s-=r[l],a--);return s/a}function HA(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function hb(t,e,n,r){let i=n=="right"?-r:r,o=t.posAtCoords({left:e.clientX+i,top:e.clientY});if(!o)return-1;let{pos:s}=o,a=Pi(t.state.doc.resolve(s));if(!a)return-1;if(n=="right")return a.pos;let l=oe.get(a.node(-1)),c=a.start(-1),u=l.map.indexOf(a.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function mb(t,e,n){let r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function Ob(t,e){t.dispatch(t.state.tr.setMeta(mt,{setHandle:e}))}function WA(t,e,n){let r=t.state.doc.resolve(e),i=r.node(-1),o=oe.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let c=0;c<o.height;c++){let u=c*o.width+a;if(c&&o.map[u]==o.map[u-o.width])continue;let f=o.map[u],d=i.nodeAt(f).attrs,p=d.colspan==1?0:a-o.colCount(f);if(d.colwidth&&d.colwidth[p]==n)continue;let h=d.colwidth?d.colwidth.slice():jA(d.colspan);h[p]=n,l.setNodeMarkup(s+f,null,{...d,colwidth:h})}l.docChanged&&t.dispatch(l)}function gb(t,e,n,r){let i=t.state.doc.resolve(e),o=i.node(-1),s=i.start(-1),a=oe.get(o).colCount(i.pos-s)+i.nodeAfter.attrs.colspan-1,l=t.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&Gf(o,l.firstChild,l,r,a,n)}function jA(t){return Array(t).fill(0)}function VA(t,e){let n=[],r=t.doc.resolve(e),i=r.node(-1);if(!i)return ae.empty;let o=oe.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<o.height;c++){let u=a+c*o.width;if((a==o.width-1||o.map[u]!=o.map[u+1])&&(c==0||o.map[u]!=o.map[u-o.width])){var l;let f=o.map[u],d=s+f+i.nodeAt(f).nodeSize-1,p=document.createElement("div");p.className="column-resize-handle",!((l=mt.getState(t))===null||l===void 0)&&l.dragging&&n.push(le.node(s+f,s+f+i.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),n.push(le.widget(d,p))}}return ae.create(t.doc,n)}function Db({allowTableNodeSelection:t=!1}={}){return new X({key:Vn,state:{init(){return null},apply(e,n){let r=e.getMeta(Vn);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;let{deleted:i,pos:o}=e.mapping.mapResult(n);return i?null:o}},props:{decorations:cA,handleDOMEvents:{mousedown:LA},createSelectionBetween(e){return Vn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:OA,handleKeyDown:RA,handlePaste:DA},appendTransaction(e,n,r){return dA(r,hA(r,n),t)}})}var nl=typeof navigator<"u"?navigator:null,ed=nl&&nl.userAgent||"",qA=/Edge\/(\d+)/.exec(ed),KA=/MSIE \d/.exec(ed),UA=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ed),JA=!!(KA||UA||qA),GA=!JA&&!!nl&&/Apple Computer/.test(nl.vendor),Lb=new ee("safari-ime-span"),Zf=!1,XA={key:Lb,props:{decorations:YA,handleDOMEvents:{compositionstart:()=>{Zf=!0},compositionend:()=>{Zf=!1}}}};function YA(t){let{$from:e,$to:n,to:r}=t.selection;if(Zf&&e.sameParent(n)){let i=le.widget(r,QA,{ignoreSelection:!0,key:"safari-ime-span"});return ae.create(t.doc,[i])}}function QA(t){let e=t.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var Bb=new X(GA?XA:{key:Lb});function td(t,e){let n=String(t);if(typeof e!="string")throw new TypeError("Expected character");let r=0,i=n.indexOf(e);for(;i!==-1;)r++,i=n.indexOf(e,i+e.length);return r}function nd(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function rd(t,e,n){let i=Nn((n||{}).ignore||[]),o=ZA(e),s=-1;for(;++s<o.length;)ar(t,"text",a);function a(c,u){let f=-1,d;for(;++f<u.length;){let p=u[f],h=d?d.children:void 0;if(i(p,h?h.indexOf(p):void 0,d))return;d=p}if(d)return l(c,u)}function l(c,u){let f=u[u.length-1],d=o[s][0],p=o[s][1],h=0,g=f.children.indexOf(c),y=!1,x=[];d.lastIndex=0;let C=d.exec(c.value);for(;C;){let v=C.index,A={index:C.index,input:C.input,stack:[...u,c]},w=p(...C,A);if(typeof w=="string"&&(w=w.length>0?{type:"text",value:w}:void 0),w===!1?d.lastIndex=v+1:(h!==v&&x.push({type:"text",value:c.value.slice(h,v)}),Array.isArray(w)?x.push(...w):w&&x.push(w),h=v+C[0].length,y=!0),!d.global)break;C=d.exec(c.value)}return y?(h<c.value.length&&x.push({type:"text",value:c.value.slice(h)}),f.children.splice(g,1,...x)):x=[c],g+x.length}}function ZA(t){let e=[];if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");let n=!t[0]||Array.isArray(t[0])?t:[t],r=-1;for(;++r<n.length;){let i=n[r];e.push([eI(i[0]),tI(i[1])])}return e}function eI(t){return typeof t=="string"?new RegExp(nd(t),"g"):t}function tI(t){return typeof t=="function"?t:function(){return t}}var id="phrasing",od=["autolink","link","image","label"];function ad(){return{transforms:[aI],enter:{literalAutolink:nI,literalAutolinkEmail:sd,literalAutolinkHttp:sd,literalAutolinkWww:sd},exit:{literalAutolink:sI,literalAutolinkEmail:oI,literalAutolinkHttp:rI,literalAutolinkWww:iI}}}function ld(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:id,notInConstruct:od},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:id,notInConstruct:od},{character:":",before:"[ps]",after:"\\/",inConstruct:id,notInConstruct:od}]}}function nI(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function sd(t){this.config.enter.autolinkProtocol.call(this,t)}function rI(t){this.config.exit.autolinkProtocol.call(this,t)}function iI(t){this.config.exit.data.call(this,t);let e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function oI(t){this.config.exit.autolinkEmail.call(this,t)}function sI(t){this.exit(t)}function aI(t){rd(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,lI],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,cI]],{ignore:["link","linkReference"]})}function lI(t,e,n,r,i){let o="";if(!Pb(i)||(/^w/i.test(e)&&(n=e+n,e="",o="http://"),!uI(n)))return!1;let s=fI(n+r);if(!s[0])return!1;let a={type:"link",title:null,url:o+e+s[0],children:[{type:"text",value:e+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function cI(t,e,n,r){return!Pb(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function uI(t){let e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function fI(t){let e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let n=e[0],r=n.indexOf(")"),i=td(t,"("),o=td(t,")");for(;r!==-1&&i>o;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),o++;return[t,n]}function Pb(t,e){let n=t.input.charCodeAt(t.index-1);return(t.index===0||Ht(n)||tr(n))&&(!e||n!==47)}Fb.peek=xI;function dI(){this.buffer()}function pI(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function hI(){this.buffer()}function mI(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function gI(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ve(this.sliceSerialize(t)).toLowerCase(),n.label=e}function yI(t){this.exit(t)}function kI(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ve(this.sliceSerialize(t)).toLowerCase(),n.label=e}function bI(t){this.exit(t)}function xI(){return"["}function Fb(t,e,n,r){let i=n.createTracker(r),o=i.move("[^"),s=n.enter("footnoteReference"),a=n.enter("reference");return o+=i.move(n.safe(n.associationId(t),{after:"]",before:o})),a(),s(),o+=i.move("]"),o}function cd(){return{enter:{gfmFootnoteCallString:dI,gfmFootnoteCall:pI,gfmFootnoteDefinitionLabelString:hI,gfmFootnoteDefinition:mI},exit:{gfmFootnoteCallString:gI,gfmFootnoteCall:yI,gfmFootnoteDefinitionLabelString:kI,gfmFootnoteDefinition:bI}}}function ud(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:Fb},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,o,s){let a=o.createTracker(s),l=a.move("[^"),c=o.enter("footnoteDefinition"),u=o.enter("label");return l+=a.move(o.safe(o.associationId(r),{before:l,after:"]"})),u(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((e?` -`:" ")+o.indentLines(o.containerFlow(r,a.current()),e?zb:wI))),c(),l}}function wI(t,e,n){return e===0?t:zb(t,e,n)}function zb(t,e,n){return(n?"":" ")+t}var CI=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];$b.peek=EI;function fd(){return{canContainEols:["delete"],enter:{strikethrough:SI},exit:{strikethrough:MI}}}function dd(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:CI}],handlers:{delete:$b}}}function SI(t){this.enter({type:"delete",children:[]},t)}function MI(t){this.exit(t)}function $b(t,e,n,r){let i=n.createTracker(r),o=n.enter("strikethrough"),s=i.move("~~");return s+=n.containerPhrasing(t,{...i.current(),before:s,after:"~"}),s+=i.move("~~"),o(),s}function EI(){return"~"}function TI(t){return t.length}function Hb(t,e){let n=e||{},r=(n.align||[]).concat(),i=n.stringLength||TI,o=[],s=[],a=[],l=[],c=0,u=-1;for(;++u<t.length;){let m=[],g=[],y=-1;for(t[u].length>c&&(c=t[u].length);++y<t[u].length;){let x=vI(t[u][y]);if(n.alignDelimiters!==!1){let C=i(x);g[y]=C,(l[y]===void 0||C>l[y])&&(l[y]=C)}m.push(x)}s[u]=m,a[u]=g}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<c;)o[f]=_b(r[f]);else{let m=_b(r);for(;++f<c;)o[f]=m}f=-1;let d=[],p=[];for(;++f<c;){let m=o[f],g="",y="";m===99?(g=":",y=":"):m===108?g=":":m===114&&(y=":");let x=n.alignDelimiters===!1?1:Math.max(1,l[f]-g.length-y.length),C=g+"-".repeat(x)+y;n.alignDelimiters!==!1&&(x=g.length+x+y.length,x>l[f]&&(l[f]=x),p[f]=x),d[f]=C}s.splice(1,0,d),a.splice(1,0,p),u=-1;let h=[];for(;++u<s.length;){let m=s[u],g=a[u];f=-1;let y=[];for(;++f<c;){let x=m[f]||"",C="",v="";if(n.alignDelimiters!==!1){let A=l[f]-(g[f]||0),w=o[f];w===114?C=" ".repeat(A):w===99?A%2?(C=" ".repeat(A/2+.5),v=" ".repeat(A/2-.5)):(C=" ".repeat(A/2),v=C):v=" ".repeat(A)}n.delimiterStart!==!1&&!f&&y.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&x==="")&&(n.delimiterStart!==!1||f)&&y.push(" "),n.alignDelimiters!==!1&&y.push(C),y.push(x),n.alignDelimiters!==!1&&y.push(v),n.padding!==!1&&y.push(" "),(n.delimiterEnd!==!1||f!==c-1)&&y.push("|")}h.push(n.delimiterEnd===!1?y.join("").replace(/ +$/,""):y.join(""))}return h.join(` -`)}function vI(t){return t==null?"":String(t)}function _b(t){let e=typeof t=="string"?t.codePointAt(0):0;return e===67||e===99?99:e===76||e===108?108:e===82||e===114?114:0}function hd(){return{enter:{table:AI,tableData:Wb,tableHeader:Wb,tableRow:NI},exit:{codeText:RI,table:II,tableData:pd,tableHeader:pd,tableRow:pd}}}function AI(t){let e=t._align;this.enter({type:"table",align:e.map(function(n){return n==="none"?null:n}),children:[]},t),this.data.inTable=!0}function II(t){this.exit(t),this.data.inTable=void 0}function NI(t){this.enter({type:"tableRow",children:[]},t)}function pd(t){this.exit(t)}function Wb(t){this.enter({type:"tableCell",children:[]},t)}function RI(t){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,OI));let n=this.stack[this.stack.length-1];n.type,n.value=e,this.exit(t)}function OI(t,e){return e==="|"?e:t}function md(t){let e=t||{},n=e.tableCellPadding,r=e.tablePipeAlign,i=e.stringLength,o=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:` +`):e.addNode("break")}}}));E(Dr.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});E(Dr.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var wf=z("InsertHardbreak",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(!(r instanceof P))return!1;if(r.empty){let o=r.$from.node();if(o.childCount>0&&o.lastChild?.type.name==="hardbreak")return n?.(i.replaceRangeWith(r.to-1,r.to,e.schema.node("paragraph")).setSelection(_.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(i.setMeta("hardbreak",!0).replaceSelectionWith(Dr.type(t).create()).scrollIntoView()),!0});E(wf,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Cf=He("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:t=>{let e=t.get(Q);return()=>e.call(wf.key)}}});E(Cf.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});E(Cf.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Sf=Tt("hr");E(Sf,{displayName:"Attr<hr>",group:"Hr"});var Go=ce("hr",t=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",t.get(Sf.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,n,r)=>{e.addNode(r)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));E(Go.node,{displayName:"NodeSchema<hr>",group:"Hr"});E(Go.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var Jk=ge(t=>new be(/^(?:---|___\s|\*\*\*\s)$/,(e,n,r,i)=>{let{tr:o}=e;return n[0]&&o.replaceWith(r-1,i,Go.type(t).create()),o}));E(Jk,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var Gk=z("InsertHr",t=>()=>(e,n)=>{if(!n)return!0;let r=Bt.node.type(t).create(),{tr:i,selection:o}=e,{from:s}=o,a=Go.type(t).create();if(!a)return!0;let l=i.replaceSelectionWith(a).insert(s,r),c=_.findFrom(l.doc.resolve(s),1,!0);return c&&n(l.setSelection(c).scrollIntoView()),!0});E(Gk,{displayName:"Command<insertHrCommand>",group:"Hr"});var Mf=Tt("bulletList");E(Mf,{displayName:"Attr<bulletList>",group:"BulletList"});var Oi=ce("bullet_list",t=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw ft(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...t.get(Mf.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"false";e.openNode(r,{spread:i}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!1,spread:n.attrs.spread}).next(n.content).closeNode()}}}));E(Oi.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});E(Oi.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var Xk=ge(t=>ha(/^\s*([-+*])\s$/,Oi.type(t)));E(Xk,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var Ef=z("WrapInBulletList",t=>()=>pi(Oi.type(t)));E(Ef,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Tf=He("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:t=>{let e=t.get(Q);return()=>e.call(Ef.key)}}});E(Tf.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});E(Tf.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var vf=Tt("orderedList");E(vf,{displayName:"Attr<orderedList>",group:"OrderedList"});var Di=ce("ordered_list",t=>({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 ft(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...t.get(vf.key)(e),...e.attrs.order===1?{}:{start:e.attrs.order},"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{spread:i,order:n.start??1}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!0,start:n.attrs.order??1,spread:n.attrs.spread==="true"}),e.next(n.content),e.closeNode()}}}));E(Di.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});E(Di.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var Yk=ge(t=>ha(/^\s*(\d+)\.\s$/,Di.type(t),e=>({order:Number(e[1])}),(e,n)=>n.childCount+n.attrs.order===Number(e[1])));E(Yk,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Af=z("WrapInOrderedList",t=>()=>pi(Di.type(t)));E(Af,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var If=He("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:t=>{let e=t.get(Q);return()=>e.call(Af.key)}}});E(If.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});E(If.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Nf=Tt("listItem");E(Nf,{displayName:"Attr<listItem>",group:"ListItem"});var Vt=ce("list_item",t=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"\u2022",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw ft(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...t.get(Nf.key)(e),"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e})=>e==="listItem",runner:(e,n,r)=>{let i=n.label!=null?`${n.label}.`:"\u2022",o=n.label!=null?"ordered":"bullet",s=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{label:i,listType:o,spread:s}),e.next(n.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,n)=>{e.openNode("listItem",void 0,{spread:n.attrs.spread}),e.next(n.content),e.closeNode()}}}));E(Vt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});E(Vt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Rf=z("SinkListItem",t=>()=>Dk(Vt.type(t)));E(Rf,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Of=z("LiftListItem",t=>()=>Wa(Vt.type(t)));E(Of,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var Df=z("SplitListItem",t=>()=>Ok(Vt.type(t)));E(Df,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Pv(t){return(e,n,r)=>{let{selection:i}=e;if(!(i instanceof P))return!1;let{empty:o,$from:s}=i;return!o||s.parentOffset!==0||s.node(-1).type!==Vt.type(t)?!1:Jc(e,n,r)}}var Lf=z("LiftFirstListItem",t=>()=>Pv(t));E(Lf,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Bf=He("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:t=>{let e=t.get(Q);return()=>e.call(Df.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:t=>{let e=t.get(Q);return()=>e.call(Rf.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:t=>{let e=t.get(Q);return()=>e.call(Of.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:t=>{let e=t.get(Q);return()=>e.call(Lf.key)}}});E(Bf.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});E(Bf.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var Qk=Ha("text",()=>({group:"inline",parseMarkdown:{match:({type:t})=>t==="text",runner:(t,e)=>{t.addText(e.value)}},toMarkdown:{match:t=>t.type.name==="text",runner:(t,e)=>{t.addNode("text",void 0,e.text)}}}));E(Qk,{displayName:"NodeSchema<text>",group:"Text"});var Pf=Tt("html");E(Pf,{displayName:"Attr<html>",group:"Html"});var Ff=ce("html",t=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{let n=document.createElement("span"),r={...t.get(Pf.key)(e),"data-value":e.attrs.value,"data-type":"html"};return n.textContent=e.attrs.value,["span",r,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,n,r)=>{e.addNode(r,{value:n.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,n)=>{e.addNode("html",void 0,n.attrs.value)}}}));E(Ff.node,{displayName:"NodeSchema<html>",group:"Html"});E(Ff.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var Fv=[Wk,lf,Bt,Ka,ff,Lr,Va,Dr,hf,Uo,yf,Jo,Sf,Go,xf,Ri,Mf,Oi,vf,Di,Nf,Vt,Yu,Ni,ef,Ko,rf,jn,af,Ii,Pf,Ff,Qk].flat(),zv=[Vk,Xk,Yk,qk,Jk,jk].flat(),$v=[Pk,Fk,$k,zk],_v=z("IsMarkSelected",()=>t=>e=>{if(!t)return!1;let{doc:n,selection:r}=e;return n.rangeHasMark(r.from,r.to,t)}),Hv=z("IsNoteSelected",()=>t=>e=>t?Ug(e,t).hasNode:!1),Wv=z("ClearTextInCurrentBlock",()=>()=>(t,e)=>{let n=t.tr,{$from:r,$to:i}=n.selection,{pos:o}=r,{pos:s}=i,a=o-r.node().content.size;return a<0?!1:(n=n.deleteRange(a,s),e?.(n),!0)}),jv=z("SetBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr,{from:s,to:a}=o.selection;try{o.setBlockType(s,a,r,i)}catch{return!1}return n?.(o),!0}),Vv=z("WrapInBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let{$from:s,$to:a}=o.selection,l=s.blockRange(a),c=l&&gr(l,r,i);if(!c)return!1;o=o.wrap(l,c)}catch{return!1}return n?.(o),!0}),qv=z("AddBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let s=r instanceof nt?r:r.createAndFill(i);if(!s)return!1;o.replaceSelectionWith(s)}catch{return!1}return n?.(o),!0}),Kv=z("SelectTextNearPos",()=>t=>(e,n)=>{let{pos:r}=t??{};if(r==null)return!1;let i=(s,a,l)=>Math.min(Math.max(s,a),l),o=e.tr;try{let s=e.doc.resolve(i(r,0,e.doc.content.size));o.setSelection(P.near(s))}catch{return!1}return n?.(o.scrollIntoView()),!0}),Uv=[cf,mf,Wn,df,kf,wf,Gk,Kk,Uk,Af,Ef,Rf,Df,Of,Lf,Qu,of,tf,_k,Hk,_v,Hv,Wv,jv,Vv,qv,Kv],Jv=[gf,bf,Cf,pf,Bf,If,Tf,uf,Zu,sf,nf].flat(),zf=ht("remarkAddOrderInList",()=>()=>t=>{Nt(t,"list",e=>{if(e.ordered){let n=e.start??1;e.children.forEach((r,i)=>{r.label=i+n})}})});E(zf.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});E(zf.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var $f=ht("remarkLineBreak",()=>()=>t=>{let e=/[\t ]*(?:\r?\n|\r)/g;Nt(t,"text",(n,r,i)=>{if(!n.value||typeof n.value!="string")return;let o=[],s=0;e.lastIndex=0;let a=e.exec(n.value);for(;a;){let l=a.index;s!==l&&o.push({type:"text",value:n.value.slice(s,l)}),o.push({type:"break",data:{isInline:!0}}),s=l+a[0].length,a=e.exec(n.value)}if(o.length>0&&i&&typeof r=="number")return s<n.value.length&&o.push({type:"text",value:n.value.slice(s)}),i.children.splice(r,1,...o),r+o.length})});E($f.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});E($f.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var _f=ht("remarkInlineLink",()=>ja);E(_f.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});E(_f.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var Gv=t=>!!t.children,Xv=t=>t.type==="html";function Yv(t,e){return n(t,0,null)[0];function n(r,i,o){if(Gv(r)){let s=[];for(let a=0,l=r.children.length;a<l;a++){let c=r.children[a];if(c){let u=n(c,a,r);if(u)for(let f=0,d=u.length;f<d;f++){let p=u[f];p&&s.push(p)}}}r.children=s}return e(r,i,o)}}var Qv=["root","blockquote","listItem"],Hf=ht("remarkHTMLTransformer",()=>()=>t=>{Yv(t,(e,n,r)=>Xv(e)?(r&&Qv.includes(r.type)&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});E(Hf.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});E(Hf.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var Wf=ht("remarkMarker",()=>()=>(t,e)=>{let n=r=>e.value.charAt(r.position.start.offset);Nt(t,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});E(Wf.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});E(Wf.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var Zk=pe(()=>{let t=!1,e=new X({key:new ee("MILKDOWN_INLINE_NODES_CURSOR"),state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;let r=n.selection.$from,i=r.nodeBefore,o=r.nodeAfter;return!!(i&&o&&i.isInline&&!i.isText&&o.isInline&&!o.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>t?(t=!1,requestAnimationFrame(()=>{if(e.getState(n.state)){let i=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i))}}),!0):!1,compositionstart:n=>(e.getState(n.state)&&(t=!0),!1),beforeinput:(n,r)=>{if(e.getState(n.state)&&r instanceof InputEvent&&r.data&&!t){let i=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i)),!0}return!1}},decorations(n){if(e.getState(n)){let r=n.selection.$from.pos,i=document.createElement("span"),o=le.widget(r,i,{side:-1}),s=document.createElement("span"),a=le.widget(r,s);return setTimeout(()=>{i.contentEditable="true",s.contentEditable="true"}),oe.create(n.doc,[o,a])}return oe.empty}}});return e});E(Zk,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var eb=pe(t=>new X({key:new ee("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,n,r)=>{if(!e.length)return;let[i]=e;if(!i)return;let[o]=i.steps;if(i.getMeta("hardbreak")){if(!(o instanceof xe))return;let{from:s}=o;return r.tr.setNodeMarkup(s,Dr.type(t),void 0,[])}if(o instanceof pr){let s=r.tr,{from:a,to:l}=o;return r.doc.nodesBetween(a,l,(c,u)=>{c.type===Dr.type(t)&&(s=s.setNodeMarkup(u,Dr.type(t),void 0,[]))}),s}}}));E(eb,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var jf=ve(["table","code_block"],"hardbreakFilterNodes");E(jf,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var tb=pe(t=>{let e=t.get(jf.key);return new X({key:new ee("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(n,r)=>{let i=n.getMeta("hardbreak"),[o]=n.steps;if(i&&o){let{from:s}=o,a=r.doc.resolve(s),l=a.depth,c=!0;for(;l>0;)e.includes(a.node(l).type.name)&&(c=!1),l--;return c}return!0}})});E(tb,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var nb=pe(t=>{let e=new ee("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;let i=t.get(Ka.key),o=r.state.tr.setMeta("addToHistory",!1),s=!1,a={};r.state.doc.descendants((l,c)=>{if(l.type===Lr.type(t)){if(l.textContent.trim().length===0)return;let u=l.attrs,f=i(l);a[f]?(a[f]+=1,f+=`-#${a[f]}`):a[f]=1,u.id!==f&&(s=!0,o.setMeta(e,!0).setNodeMarkup(c,void 0,{...u,id:f}))}}),s&&r.dispatch(o)};return new X({key:e,view:r=>(n(r),{update:(i,o)=>{i.state.doc.eq(o.doc)||n(i)}})})});E(nb,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var rb=pe(t=>{let e=(n,r,i)=>{if(!i.selection||n.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;let o=Di.type(t),s=Oi.type(t),a=Vt.type(t),l=(f,d,p=1)=>{let h=!1,m=`${d+p}.`;return f.label!==m&&(f.label=m,h=!0),h},c=i.tr,u=!1;return i.doc.descendants((f,d,p,h)=>{if(f.type===s){let m=f.maybeChild(0);m?.type===a&&m.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(d,o,{spread:"true"}),f.descendants((g,y,x,C)=>{if(g.type===a){let v={...g.attrs};l(v,C)&&(c=c.setNodeMarkup(y,void 0,v))}return!1}))}else if(f.type===a&&p?.type===o){let m={...f.attrs},g=!1;m.listType!=="ordered"&&(m.listType="ordered",g=!0),p?.maybeChild(0)&&(g=l(m,h,p?.attrs.order??1)),g&&(c=c.setNodeMarkup(d,void 0,m),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new X({key:new ee("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});E(rb,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Zv=[eb,jf,tb,Zk,zf,_f,$f,Hf,Wf,qa,nb,rb].flat(),ib=[Fv,zv,$v,Uv,Jv,Zv].flat();var qf,Kf;if(typeof WeakMap<"u"){let t=new WeakMap;qf=e=>t.get(e),Kf=(e,n)=>(t.set(e,n),n)}else{let t=[],n=0;qf=r=>{for(let i=0;i<t.length;i+=2)if(t[i]==r)return t[i+1]},Kf=(r,i)=>(n==10&&(n=0),t[n++]=r,t[n++]=i)}var se=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e<this.map.length;e++){let n=this.map[e];if(n!=t)continue;let r=e%this.width,i=e/this.width|0,o=r+1,s=i+1;for(let a=1;o<this.width&&this.map[e+a]==n;a++)o++;for(let a=1;s<this.height&&this.map[e+this.width*a]==n;a++)s++;return{left:r,top:i,right:o,bottom:s}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){let{left:r,right:i,top:o,bottom:s}=this.findCell(t);return e=="horiz"?(n<0?r==0:i==this.width)?null:this.map[o*this.width+(n<0?r-1:i)]:(n<0?o==0:s==this.height)?null:this.map[r+this.width*(n<0?o-1:s)]}rectBetween(t,e){let{left:n,right:r,top:i,bottom:o}=this.findCell(t),{left:s,right:a,top:l,bottom:c}=this.findCell(e);return{left:Math.min(n,s),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(o,c)}}cellsInRect(t){let e=[],n={};for(let r=t.top;r<t.bottom;r++)for(let i=t.left;i<t.right;i++){let o=r*this.width+i,s=this.map[o];n[s]||(n[s]=!0,!(i==t.left&&i&&this.map[o-1]==s||r==t.top&&r&&this.map[o-this.width]==s)&&e.push(s))}return e}positionAt(t,e,n){for(let r=0,i=0;;r++){let o=i+n.child(r).nodeSize;if(r==t){let s=e+t*this.width,a=(t+1)*this.width;for(;s<a&&this.map[s]<i;)s++;return s==a?o-1:this.map[s]}i=o}}static get(t){return qf(t)||Kf(t,eA(t))}};function eA(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);let e=tA(t),n=t.childCount,r=[],i=0,o=null,s=[];for(let c=0,u=e*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){let f=t.child(c);u++;for(let h=0;;h++){for(;i<r.length&&r[i]!=0;)i++;if(h==f.childCount)break;let m=f.child(h),{colspan:g,rowspan:y,colwidth:x}=m.attrs;for(let C=0;C<y;C++){if(C+c>=n){(o||(o=[])).push({type:"overlong_rowspan",pos:u,n:y-C});break}let v=i+C*e;for(let A=0;A<g;A++){r[v+A]==0?r[v+A]=u:(o||(o=[])).push({type:"collision",row:c,pos:u,n:g-A});let w=x&&x[A];if(w){let N=(v+A)%e*2,B=s[N];B==null||B!=w&&s[N+1]==1?(s[N]=w,s[N+1]=1):B==w&&s[N+1]++}}}i+=g,u+=m.nodeSize}let d=(c+1)*e,p=0;for(;i<d;)r[i++]==0&&p++;p&&(o||(o=[])).push({type:"missing",row:c,n:p}),u++}(e===0||n===0)&&(o||(o=[])).push({type:"zero_sized"});let a=new se(e,n,r,o),l=!1;for(let c=0;!l&&c<s.length;c+=2)s[c]!=null&&s[c+1]<n&&(l=!0);return l&&nA(a,s,t),a}function tA(t){let e=-1,n=!1;for(let r=0;r<t.childCount;r++){let i=t.child(r),o=0;if(n)for(let s=0;s<r;s++){let a=t.child(s);for(let l=0;l<a.childCount;l++){let c=a.child(l);s+c.attrs.rowspan>r&&(o+=c.attrs.colspan)}}for(let s=0;s<i.childCount;s++){let a=i.child(s);o+=a.attrs.colspan,a.attrs.rowspan>1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function nA(t,e,n){t.problems||(t.problems=[]);let r={};for(let i=0;i<t.map.length;i++){let o=t.map[i];if(r[o])continue;r[o]=!0;let s=n.nodeAt(o);if(!s)throw new RangeError(`No cell with offset ${o} found`);let a=null,l=s.attrs;for(let c=0;c<l.colspan;c++){let u=e[(i+c)%t.width*2];u!=null&&(!l.colwidth||l.colwidth[c]!=u)&&((a||(a=rA(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function rA(t){if(t.colwidth)return t.colwidth.slice();let e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function ob(t,e){if(typeof t=="string")return{};let n=t.getAttribute("data-colwidth"),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(s=>Number(s)):null,i=Number(t.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let a=e[s].getFromDOM,l=a&&a(t);l!=null&&(o[s]=l)}return o}function sb(t,e){let n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan),t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan),t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(t.attrs[r],n)}return n}function iA(t){if(t!==null){if(!Array.isArray(t))throw new TypeError("colwidth must be null or an array");for(let e of t)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function kb(t){let e=t.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:iA}};for(let r in e)n[r]={default:e[r].default,validate:e[r].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:t.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:t.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>ob(r,e)}],toDOM(r){return["td",sb(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ob(r,e)}],toDOM(r){return["th",sb(r,e),0]}}}}function Ze(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(let n in t.nodes){let r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Vn=new ee("selectingCells");function Pi(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function Re(t){let e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function Qa(t){let e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let n=Pi(e.$head)||oA(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function oA(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function Uf(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function sA(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function Xf(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function bb(t,e,n){let r=t.node(-1),i=se.get(r),o=t.start(-1),s=i.nextCell(t.pos-o,e,n);return s==null?null:t.node(0).resolve(o+s)}function Br(t,e,n=1){let r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function aA(t,e,n=1){let r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(e,0,0)}return r}function lA(t,e,n){let r=Ze(e.type.schema).header_cell;for(let i=0;i<t.height;i++)if(e.nodeAt(t.map[n+i*t.width]).type!=r)return!1;return!0}var he=class yn extends _{constructor(e,n=e){let r=e.node(-1),i=se.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,n.pos-o),a=e.node(0),l=i.cellsInRect(s).filter(u=>u!=n.pos-o);l.unshift(n.pos-o);let c=l.map(u=>{let f=r.nodeAt(u);if(!f)throw new RangeError(`No cell with offset ${u} found`);let d=o+u+1;return new On(a.resolve(d),a.resolve(d+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){let r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(Uf(r)&&Uf(i)&&Xf(r,i)){let o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?yn.rowSelection(r,i):o&&this.isColSelection()?yn.colSelection(r,i):new yn(r,i)}return P.between(r,i)}content(){let e=this.$anchorCell.node(-1),n=se.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let l=i.top;l<i.bottom;l++){let c=[];for(let u=l*n.width+i.left,f=i.left;f<i.right;f++,u++){let d=n.map[u];if(o[d])continue;o[d]=!0;let p=n.findCell(d),h=e.nodeAt(d);if(!h)throw new RangeError(`No cell with offset ${d} found`);let m=i.left-p.left,g=p.right-i.right;if(m>0||g>0){let y=h.attrs;if(m>0&&(y=Br(y,0,m)),g>0&&(y=Br(y,y.colspan-g,g)),p.left<i.left){if(h=h.type.createAndFill(y),!h)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else h=h.type.create(y,h.content)}if(p.top<i.top||p.bottom>i.bottom){let y={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top<i.top?h=h.type.createAndFill(y):h=h.type.create(y,h.content)}c.push(h)}s.push(e.child(l).copy(M.from(c)))}let a=this.isColSelection()&&this.isRowSelection()?e:s;return new R(M.from(a),1,1)}replace(e,n=R.empty){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:a,$to:l}=i[s],c=e.mapping.slice(r);e.replace(c.map(a.pos),c.map(l.pos),s?R.empty:n)}let o=_.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);o&&e.setSelection(o)}replaceWith(e,n){this.replace(e,new R(M.from(n),0,0))}forEachCell(e){let n=this.$anchorCell.node(-1),r=se.get(n),i=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let s=0;s<o.length;s++)e(n.nodeAt(o[s]),i+o[s])}isColSelection(){let e=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(e,n)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){let r=e.node(-1),i=se.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.top<=a.top?(s.top>0&&(e=l.resolve(o+i.map[s.left])),a.bottom<i.height&&(n=l.resolve(o+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(o+i.map[a.left])),s.bottom<i.height&&(e=l.resolve(o+i.map[i.width*(i.height-1)+s.right-1]))),new yn(e,n)}isRowSelection(){let e=this.$anchorCell.node(-1),n=se.get(e),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),o=n.colCount(this.$headCell.pos-r);if(Math.min(i,o)>0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,a=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,a)==n.width}eq(e){return e instanceof yn&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){let r=e.node(-1),i=se.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.left<=a.left?(s.left>0&&(e=l.resolve(o+i.map[s.top*i.width])),a.right<i.width&&(n=l.resolve(o+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(o+i.map[a.top*i.width])),s.right<i.width&&(e=l.resolve(o+i.map[i.width*(s.top+1)-1]))),new yn(e,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,n){return new yn(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){return new yn(e.resolve(n),e.resolve(r))}getBookmark(){return new cA(this.$anchorCell.pos,this.$headCell.pos)}};he.prototype.visible=!1;_.jsonID("cell",he);var cA=class xb{constructor(e,n){this.anchor=e,this.head=n}map(e){return new xb(e.map(this.anchor),e.map(this.head))}resolve(e){let n=e.resolve(this.anchor),r=e.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&Xf(n,r)?new he(n,r):_.near(r,1)}};function uA(t){if(!(t.selection instanceof he))return null;let e=[];return t.selection.forEachCell((n,r)=>{e.push(le.node(r,r+n.nodeSize,{class:"selectedCell"}))}),oe.create(t.doc,e)}function fA({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let n=t.pos,r=e.pos,i=t.depth;for(;i>=0&&!(t.after(i+1)<t.end(i));i--,n++);for(let o=e.depth;o>=0&&!(e.before(o+1)>e.start(o));o--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function dA({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){let o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&e.parentOffset===0}function pA(t,e,n){let r=(e||t).selection,i=(e||t).doc,o,s;if(r instanceof H&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=he.create(i,r.from);else if(s=="row"){let a=i.resolve(r.from+1);o=he.rowSelection(a,a)}else if(!n){let a=se.get(r.node),l=r.from+1,c=l+a.map[a.width*a.height-1];o=he.create(i,l+1,c)}}else r instanceof P&&fA(r)?o=P.create(i,r.from):r instanceof P&&dA(r)&&(o=P.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var hA=new ee("fix-tables");function wb(t,e,n,r){let i=t.childCount,o=e.childCount;e:for(let s=0,a=0;s<o;s++){let l=e.child(s);for(let c=a,u=Math.min(i,s+3);c<u;c++)if(t.child(c)==l){a=c+1,n+=l.nodeSize;continue e}r(l,n),a<i&&t.child(a).sameMarkup(l)?wb(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function mA(t,e){let n,r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=gA(t,i,o,n))};return e?e.doc!=t.doc&&wb(e.doc,t.doc,0,r):t.doc.descendants(r),n}function gA(t,e,n,r){let i=se.get(e);if(!i.problems)return r;r||(r=t.tr);let o=[];for(let l=0;l<i.height;l++)o.push(0);for(let l=0;l<i.problems.length;l++){let c=i.problems[l];if(c.type=="collision"){let u=e.nodeAt(c.pos);if(!u)continue;let f=u.attrs;for(let d=0;d<f.rowspan;d++)o[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,Br(f,f.colspan-c.n,c.n))}else if(c.type=="missing")o[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){let u=r.mapping.map(n);r.delete(u,u+e.nodeSize)}}let s,a;for(let l=0;l<o.length;l++)o[l]&&(s==null&&(s=l),a=l);for(let l=0,c=n+1;l<i.height;l++){let u=e.child(l),f=c+u.nodeSize,d=o[l];if(d>0){let p="cell";u.firstChild&&(p=u.firstChild.type.spec.tableRole);let h=[];for(let g=0;g<d;g++){let y=Ze(t.schema)[p].createAndFill();y&&h.push(y)}let m=(l==0||s==l-1)&&a==l?c+1:f-1;r.insert(r.mapping.map(m),h)}c=f}return r.setMeta(hA,{fixTables:!0})}function Cb(t){let e=se.get(t),n=[],r=e.height,i=e.width;for(let o=0;o<r;o++){let s=[];for(let a=0;a<i;a++){let l=o*i+a,c=e.map[l];if(o>0){let u=l-i;if(c===e.map[u]){s.push(null);continue}}if(a>0){let u=l-1;if(c===e.map[u]){s.push(null);continue}}s.push(t.nodeAt(c))}n.push(s)}return n}function Sb(t,e){let n=[],r=se.get(t),i=r.height,o=r.width;for(let s=0;s<i;s++){let a=t.child(s),l=[];for(let u=0;u<o;u++){let f=e[s][u];if(!f)continue;let d=r.map[s*r.width+u],p=t.nodeAt(d);if(!p)continue;let h=p.type.createChecked(f.attrs,f.content,f.marks);l.push(h)}let c=a.type.createChecked(a.attrs,l,a.marks);n.push(c)}return t.type.createChecked(t.attrs,n,t.marks)}function Mb(t,e,n,r){let i=e[0]>n[0]?-1:1,o=t.splice(e[0],e.length),s=o.length%2===0?1:0,a;return r===-1&&i===1?a=n[0]-1:r===1&&i===-1?a=n[n.length-1]-s+1:a=i===-1?n[0]:n[n.length-1]-s,t.splice(a,0,...o),t}function Fi(t){return yA(e=>e.type.spec.tableRole==="table",t)}function yA(t,e){for(let n=e.depth;n>=0;n-=1){let r=e.node(n);if(t(r))return{node:r,pos:n===0?0:e.before(n),start:e.start(n),depth:n}}return null}function Li(t,e){let n=Fi(e.$from);if(!n)return;let r=se.get(n.node);if(!(t<0||t>r.width-1))return r.cellsInRect({left:t,right:t+1,top:0,bottom:r.height}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function Bi(t,e){let n=Fi(e.$from);if(!n)return;let r=se.get(n.node);if(!(t<0||t>r.height-1))return r.cellsInRect({left:0,right:r.width,top:t,bottom:t+1}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function ab(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Li(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Li(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;d.node.attrs.colspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Li(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Li(r,t.selection),a=Bi(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Li(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function lb(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Bi(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Bi(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;d.node.attrs.rowspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Bi(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Bi(r,t.selection),a=Li(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Bi(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function cb(t){return t[0].map((e,n)=>t.map(r=>r[n]))}function kA(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Fi(r.doc.resolve(a));if(!l)return!1;let c=(e=ab(r,i))===null||e===void 0?void 0:e.indexes,u=(n=ab(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=bA(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=se.get(f),p=l.start,h=o,m=d.positionAt(d.height-1,h,f),g=r.doc.resolve(p+m),y=d.positionAt(0,h,f),x=r.doc.resolve(p+y);return r.setSelection(he.colSelection(g,x)),!0}function bA(t,e,n,r){let i=cb(Cb(t));return i=Mb(i,e,n,r),i=cb(i),Sb(t,i)}function xA(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Fi(r.doc.resolve(a));if(!l)return!1;let c=(e=lb(r,i))===null||e===void 0?void 0:e.indexes,u=(n=lb(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=wA(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=se.get(f),p=l.start,h=o,m=d.positionAt(h,d.width-1,f),g=r.doc.resolve(p+m),y=d.positionAt(h,0,f),x=r.doc.resolve(p+y);return r.setSelection(he.rowSelection(g,x)),!0}function wA(t,e,n,r){let i=Cb(t);return i=Mb(i,e,n,r),Sb(t,i)}function vt(t){let e=t.selection,n=Qa(t),r=n.node(-1),i=n.start(-1),o=se.get(r);return{...e instanceof he?o.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o.findCell(n.pos-i),tableStart:i,map:o,table:r}}function Eb(t,{map:e,tableStart:n,table:r},i){let o=i>0?-1:0;lA(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s<e.height;s++){let a=s*e.width+i;if(i>0&&i<e.width&&e.map[a-1]==e.map[a]){let l=e.map[a],c=r.nodeAt(l);t.setNodeMarkup(t.mapping.map(n+l),null,aA(c.attrs,i-e.colCount(l))),s+=c.attrs.rowspan-1}else{let l=o==null?Ze(r.type.schema).cell:r.nodeAt(e.map[a+o]).type,c=e.positionAt(s,i,r);t.insert(t.mapping.map(n+c),l.createAndFill())}}return t}function Tb(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(Eb(t.tr,n,n.left))}return!0}function Za(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(Eb(t.tr,n,n.right))}return!0}function CA(t,{map:e,table:n,tableStart:r},i){let o=t.mapping.maps.length;for(let s=0;s<e.height;){let a=s*e.width+i,l=e.map[a],c=n.nodeAt(l),u=c.attrs;if(i>0&&e.map[a-1]==l||i<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(o).map(r+l),null,Br(u,i-e.colCount(l)));else{let f=t.mapping.slice(o).map(r+l);t.delete(f,f+c.nodeSize)}s+=u.rowspan}}function el(t,e){if(!Re(t))return!1;if(e){let n=vt(t),r=t.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;CA(r,n,i),i!=n.left;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=se.get(o)}e(r)}return!0}function SA(t,e,n){var r;let i=Ze(e.type.schema).header_cell;for(let o=0;o<t.width;o++)if(((r=e.nodeAt(t.map[o+n*t.width]))===null||r===void 0?void 0:r.type)!=i)return!1;return!0}function MA(t,{map:e,tableStart:n,table:r},i){let o=n;for(let c=0;c<i;c++)o+=r.child(c).nodeSize;let s=[],a=i>0?-1:0;SA(e,r,i+a)&&(a=i==0||i==e.height?null:0);for(let c=0,u=e.width*i;c<e.width;c++,u++)if(i>0&&i<e.height&&e.map[u]==e.map[u-e.width]){let f=e.map[u],d=r.nodeAt(f).attrs;t.setNodeMarkup(n+f,null,{...d,rowspan:d.rowspan+1}),c+=d.colspan-1}else{var l;let f=a==null?Ze(r.type.schema).cell:(l=r.nodeAt(e.map[u+a*e.width]))===null||l===void 0?void 0:l.type,d=f?.createAndFill();d&&s.push(d)}return t.insert(o,Ze(r.type.schema).row.create(null,s)),t}function Yf(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(MA(t.tr,n,n.bottom))}return!0}function EA(t,{map:e,table:n,tableStart:r},i){let o=0;for(let c=0;c<i;c++)o+=n.child(c).nodeSize;let s=o+n.child(i).nodeSize,a=t.mapping.maps.length;t.delete(o+r,s+r);let l=new Set;for(let c=0,u=i*e.width;c<e.width;c++,u++){let f=e.map[u];if(!l.has(f)){if(l.add(f),i>0&&f==e.map[u-e.width]){let d=n.nodeAt(f).attrs;t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d,rowspan:d.rowspan-1}),c+=d.colspan-1}else if(i<e.height&&f==e.map[u+e.width]){let d=n.nodeAt(f),p=d.attrs,h=d.type.create({...p,rowspan:d.attrs.rowspan-1},d.content),m=e.positionAt(i+1,c,n);t.insert(t.mapping.slice(a).map(r+m),h),c+=p.colspan-1}}}}function tl(t,e){if(!Re(t))return!1;if(e){let n=vt(t),r=t.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;EA(r,n,i),i!=n.top;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=se.get(n.table)}e(r)}return!0}function vb(t,e){return function(n,r){if(!Re(n))return!1;let i=Qa(n);if(i.nodeAfter.attrs[t]===e)return!1;if(r){let o=n.tr;n.selection instanceof he?n.selection.forEachCell((s,a)=>{s.attrs[t]!==e&&o.setNodeMarkup(a,null,{...s.attrs,[t]:e})}):o.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[t]:e}),r(o)}return!0}}function TA(t){return function(e,n){if(!Re(e))return!1;if(n){let r=Ze(e.schema),i=vt(e),o=e.tr,s=i.map.cellsInRect(t=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:t=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=s.map(l=>i.table.nodeAt(l));for(let l=0;l<s.length;l++)a[l].type==r.header_cell&&o.setNodeMarkup(i.tableStart+s[l],r.cell,a[l].attrs);if(o.steps.length===0)for(let l=0;l<s.length;l++)o.setNodeMarkup(i.tableStart+s[l],r.header_cell,a[l].attrs);n(o)}return!0}}function ub(t,e,n){let r=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let i=0;i<r.length;i++){let o=e.table.nodeAt(r[i]);if(o&&o.type!==n.header_cell)return!1}return!0}function Qf(t,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?TA(t):function(n,r){if(!Re(n))return!1;if(r){let i=Ze(n.schema),o=vt(n),s=n.tr,a=ub("row",o,i),l=ub("column",o,i),c=(t==="column"?a:t==="row"&&l)?1:0,u=t=="column"?{left:0,top:c,right:1,bottom:o.map.height}:t=="row"?{left:c,top:0,right:o.map.width,bottom:1}:o,f=t=="column"?l?i.cell:i.header_cell:t=="row"?a?i.cell:i.header_cell:i.cell;o.map.cellsInRect(u).forEach(d=>{let p=d+o.tableStart,h=s.doc.nodeAt(p);h&&s.setNodeMarkup(p,f,h.attrs)}),r(s)}return!0}}var oW=Qf("row",{useDeprecatedLogic:!0}),sW=Qf("column",{useDeprecatedLogic:!0}),aW=Qf("cell",{useDeprecatedLogic:!0});function vA(t,e){if(e<0){let n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,i=t.before();r>=0;r--){let o=t.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;let n=t.node(-1);for(let r=t.indexAfter(-1),i=t.after();r<n.childCount;r++){let o=n.child(r);if(o.childCount)return i+1;i+=o.nodeSize}}return null}function Xo(t){return function(e,n){if(!Re(e))return!1;let r=vA(Qa(e),t);if(r==null)return!1;if(n){let i=e.doc.resolve(r);n(e.tr.setSelection(P.between(i,sA(i))).scrollIntoView())}return!0}}function Ab(t,e){let n=t.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function Ua(t,e){let n=t.selection;if(!(n instanceof he))return!1;if(e){let r=t.tr,i=Ze(t.schema).cell.createAndFill().content;n.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new R(i,0,0))}),r.docChanged&&e(r)}return!0}function Ib(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return xA({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function Nb(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return kA({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function AA(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;let i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,a=[];if(o=="row")for(let l=0;l<e.childCount;l++){let c=e.child(l).content,u=l?0:Math.max(0,n-1),f=l<e.childCount-1?0:Math.max(0,r-1);(u||f)&&(c=Jf(Ze(s).row,new R(c,u,f)).content),a.push(c)}else if(o=="cell"||o=="header_cell")a.push(n||r?Jf(Ze(s).row,new R(e,n,r)).content:e);else return null;return IA(s,a)}function IA(t,e){let n=[];for(let i=0;i<e.length;i++){let o=e[i];for(let s=o.childCount-1;s>=0;s--){let{rowspan:a,colspan:l}=o.child(s).attrs;for(let c=i;c<i+a;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=e.length&&e.push(M.empty),n[i]<r){let o=Ze(t).cell.createAndFill(),s=[];for(let a=n[i];a<r;a++)s.push(o);e[i]=e[i].append(M.from(s))}return{height:e.length,width:r,rows:e}}function Jf(t,e){let n=t.createAndFill();return new ci(n).replace(0,n.content.size,e).doc}function NA({width:t,height:e,rows:n},r,i){if(t!=r){let o=[],s=[];for(let a=0;a<n.length;a++){let l=n[a],c=[];for(let u=o[a]||0,f=0;u<r;f++){let d=l.child(f%l.childCount);u+d.attrs.colspan>r&&(d=d.type.createChecked(Br(d.attrs,d.attrs.colspan,u+d.attrs.colspan-r),d.content)),c.push(d),u+=d.attrs.colspan;for(let p=1;p<d.attrs.rowspan;p++)o[a+p]=(o[a+p]||0)+d.attrs.colspan}s.push(M.from(c))}n=s,t=r}if(e!=i){let o=[];for(let s=0,a=0;s<i;s++,a++){let l=[],c=n[a%e];for(let u=0;u<c.childCount;u++){let f=c.child(u);s+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),l.push(f)}o.push(M.from(l))}n=o,e=i}return{width:t,height:e,rows:n}}function RA(t,e,n,r,i,o,s){let a=t.doc.type.schema,l=Ze(a),c,u;if(i>e.width)for(let f=0,d=0;f<e.height;f++){let p=n.child(f);d+=p.nodeSize;let h=[],m;p.lastChild==null||p.lastChild.type==l.cell?m=c||(c=l.cell.createAndFill()):m=u||(u=l.header_cell.createAndFill());for(let g=e.width;g<i;g++)h.push(m);t.insert(t.mapping.slice(s).map(d-1+r),h)}if(o>e.height){let f=[];for(let h=0,m=(e.height-1)*e.width;h<Math.max(e.width,i);h++){let g=h>=e.width?!1:n.nodeAt(e.map[m+h]).type==l.header_cell;f.push(g?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}let d=l.row.create(null,M.from(f)),p=[];for(let h=e.height;h<o;h++)p.push(d);t.insert(t.mapping.slice(s).map(r+n.nodeSize-2),p)}return!!(c||u)}function fb(t,e,n,r,i,o,s,a){if(s==0||s==e.height)return!1;let l=!1;for(let c=i;c<o;c++){let u=s*e.width+c,f=e.map[u];if(e.map[u-e.width]==f){l=!0;let d=n.nodeAt(f),{top:p,left:h}=e.findCell(f);t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d.attrs,rowspan:s-p}),t.insert(t.mapping.slice(a).map(e.positionAt(s,h,n)),d.type.createAndFill({...d.attrs,rowspan:p+d.attrs.rowspan-s})),c+=d.attrs.colspan-1}}return l}function db(t,e,n,r,i,o,s,a){if(s==0||s==e.width)return!1;let l=!1;for(let c=i;c<o;c++){let u=c*e.width+s,f=e.map[u];if(e.map[u-1]==f){l=!0;let d=n.nodeAt(f),p=e.colCount(f),h=t.mapping.slice(a).map(f+r);t.setNodeMarkup(h,null,Br(d.attrs,s-p,d.attrs.colspan-(s-p))),t.insert(h+d.nodeSize,d.type.createAndFill(Br(d.attrs,0,s-p))),c+=d.attrs.rowspan-1}}return l}function pb(t,e,n,r,i){let o=n?t.doc.nodeAt(n-1):t.doc;if(!o)throw new Error("No table found");let s=se.get(o),{top:a,left:l}=r,c=l+i.width,u=a+i.height,f=t.tr,d=0;function p(){if(o=n?f.doc.nodeAt(n-1):f.doc,!o)throw new Error("No table found");s=se.get(o),d=f.mapping.maps.length}RA(f,s,o,n,c,u,d)&&p(),fb(f,s,o,n,l,c,a,d)&&p(),fb(f,s,o,n,l,c,u,d)&&p(),db(f,s,o,n,a,u,l,d)&&p(),db(f,s,o,n,a,u,c,d)&&p();for(let h=a;h<u;h++){let m=s.positionAt(h,l,o),g=s.positionAt(h,c,o);f.replace(f.mapping.slice(d).map(m+n),f.mapping.slice(d).map(g+n),new R(i.rows[h-a],0,0))}p(),f.setSelection(new he(f.doc.resolve(n+s.positionAt(a,l,o)),f.doc.resolve(n+s.positionAt(u-1,c-1,o)))),e(f)}var OA=lu({ArrowLeft:Ja("horiz",-1),ArrowRight:Ja("horiz",1),ArrowUp:Ja("vert",-1),ArrowDown:Ja("vert",1),"Shift-ArrowLeft":Ga("horiz",-1),"Shift-ArrowRight":Ga("horiz",1),"Shift-ArrowUp":Ga("vert",-1),"Shift-ArrowDown":Ga("vert",1),Backspace:Ua,"Mod-Backspace":Ua,Delete:Ua,"Mod-Delete":Ua});function Xa(t,e,n){return n.eq(t.selection)?!1:(e&&e(t.tr.setSelection(n).scrollIntoView()),!0)}function Ja(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection;if(o instanceof he)return Xa(n,r,_.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;let s=Rb(i,t,e);if(s==null)return!1;if(t=="horiz")return Xa(n,r,_.near(n.doc.resolve(o.head+e),e));{let a=n.doc.resolve(s),l=bb(a,t,e),c;return l?c=_.near(l,1):e<0?c=_.near(n.doc.resolve(a.before(-1)),-1):c=_.near(n.doc.resolve(a.after(-1)),1),Xa(n,r,c)}}}function Ga(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection,s;if(o instanceof he)s=o;else{let l=Rb(i,t,e);if(l==null)return!1;s=new he(n.doc.resolve(l))}let a=bb(s.$headCell,t,e);return a?Xa(n,r,new he(s.$anchorCell,a)):!1}}function DA(t,e){let n=t.state.doc,r=Pi(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new he(r))),!0):!1}function LA(t,e,n){if(!Re(t.state))return!1;let r=AA(n),i=t.state.selection;if(i instanceof he){r||(r={width:1,height:1,rows:[M.from(Jf(Ze(t.state.schema).cell,n))]});let o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),a=se.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=NA(r,a.right-a.left,a.bottom-a.top),pb(t.state,t.dispatch,s,a,r),!0}else if(r){let o=Qa(t.state),s=o.start(-1);return pb(t.state,t.dispatch,s,se.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function BA(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;let r=hb(t,e.target),i;if(e.shiftKey&&t.state.selection instanceof he)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Pi(t.state.selection.$anchor))!=null&&((n=Vf(t,e))===null||n===void 0?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(l,c){let u=Vf(t,c),f=Vn.getState(t.state)==null;if(!u||!Xf(l,u))if(f)u=l;else return;let d=new he(l,u);if(f||!t.state.selection.eq(d)){let p=t.state.tr.setSelection(d);f&&p.setMeta(Vn,l.pos),t.dispatch(p)}}function s(){t.root.removeEventListener("mouseup",s),t.root.removeEventListener("dragstart",s),t.root.removeEventListener("mousemove",a),Vn.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(Vn,-1))}function a(l){let c=l,u=Vn.getState(t.state),f;if(u!=null)f=t.state.doc.resolve(u);else if(hb(t,c.target)!=r&&(f=Vf(t,e),!f))return s();f&&o(f,c)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",a)}function Rb(t,e,n){if(!(t.state.selection instanceof P))return null;let{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){let o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){let s=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?s:null}}return null}function hb(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Vf(t,e){let n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Pi(t.state.doc.resolve(r))||Pi(t.state.doc.resolve(i))}var PA=class{constructor(t,e){this.node=t,this.defaultCellMinWidth=e,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",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Gf(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,Gf(t,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Gf(t,e,n,r,i,o){let s=0,a=!0,l=e.firstChild,c=t.firstChild;if(c){for(let f=0,d=0;f<c.childCount;f++){let{colspan:p,colwidth:h}=c.child(f).attrs;for(let m=0;m<p;m++,d++){let g=i==d?o:h&&h[m],y=g?g+"px":"";if(s+=g||r,g||(a=!1),l)l.style.width!=y&&(l.style.width=y),l=l.nextSibling;else{let x=document.createElement("col");x.style.width=y,e.appendChild(x)}}}for(;l;){var u;let f=l.nextSibling;(u=l.parentNode)===null||u===void 0||u.removeChild(l),l=f}a?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}var mt=new ee("tableColumnResizing");function Ob({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=PA,lastColumnResizable:i=!0}={}){let o=new X({key:mt,state:{init(s,a){var l;let c=(l=o.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews,u=Ze(a.schema).table.name;return r&&c&&(c[u]=(f,d)=>new r(f,n,d)),new FA(-1,!1)},apply(s,a){return a.apply(s)}},props:{attributes:s=>{let a=mt.getState(s);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,a)=>{zA(s,a,t,i)},mouseleave:s=>{$A(s)},mousedown:(s,a)=>{_A(s,a,e,n)}},decorations:s=>{let a=mt.getState(s);if(a&&a.activeHandle>-1)return qA(s,a.activeHandle)},nodeViews:{}}});return o}var FA=class Ya{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){let n=this,r=e.getMeta(mt);if(r&&r.setHandle!=null)return new Ya(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ya(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return Uf(e.doc.resolve(i))||(i=-1),new Ya(i,n.dragging)}return n}};function zA(t,e,n,r){if(!t.editable)return;let i=mt.getState(t.state);if(i&&!i.dragging){let o=WA(e.target),s=-1;if(o){let{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=n?s=mb(t,e,"left",n):l-e.clientX<=n&&(s=mb(t,e,"right",n))}if(s!=i.activeHandle){if(!r&&s!==-1){let a=t.state.doc.resolve(s),l=a.node(-1),c=se.get(l),u=a.start(-1);if(c.colCount(a.pos-u)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Db(t,s)}}}function $A(t){if(!t.editable)return;let e=mt.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Db(t,-1)}function _A(t,e,n,r){var i;if(!t.editable)return!1;let o=(i=t.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,s=mt.getState(t.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let a=t.state.doc.nodeAt(s.activeHandle),l=HA(t,s.activeHandle,a.attrs);t.dispatch(t.state.tr.setMeta(mt,{setDragging:{startX:e.clientX,startWidth:l}}));function c(f){o.removeEventListener("mouseup",c),o.removeEventListener("mousemove",u);let d=mt.getState(t.state);d?.dragging&&(jA(t,d.activeHandle,gb(d.dragging,f,n)),t.dispatch(t.state.tr.setMeta(mt,{setDragging:null})))}function u(f){if(!f.which)return c(f);let d=mt.getState(t.state);if(d&&d.dragging){let p=gb(d.dragging,f,n);yb(t,d.activeHandle,p,r)}}return yb(t,s.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),e.preventDefault(),!0}function HA(t,e,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=t.domAtPos(e),s=o.node.childNodes[o.offset].offsetWidth,a=n;if(r)for(let l=0;l<n;l++)r[l]&&(s-=r[l],a--);return s/a}function WA(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function mb(t,e,n,r){let i=n=="right"?-r:r,o=t.posAtCoords({left:e.clientX+i,top:e.clientY});if(!o)return-1;let{pos:s}=o,a=Pi(t.state.doc.resolve(s));if(!a)return-1;if(n=="right")return a.pos;let l=se.get(a.node(-1)),c=a.start(-1),u=l.map.indexOf(a.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function gb(t,e,n){let r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function Db(t,e){t.dispatch(t.state.tr.setMeta(mt,{setHandle:e}))}function jA(t,e,n){let r=t.state.doc.resolve(e),i=r.node(-1),o=se.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let c=0;c<o.height;c++){let u=c*o.width+a;if(c&&o.map[u]==o.map[u-o.width])continue;let f=o.map[u],d=i.nodeAt(f).attrs,p=d.colspan==1?0:a-o.colCount(f);if(d.colwidth&&d.colwidth[p]==n)continue;let h=d.colwidth?d.colwidth.slice():VA(d.colspan);h[p]=n,l.setNodeMarkup(s+f,null,{...d,colwidth:h})}l.docChanged&&t.dispatch(l)}function yb(t,e,n,r){let i=t.state.doc.resolve(e),o=i.node(-1),s=i.start(-1),a=se.get(o).colCount(i.pos-s)+i.nodeAfter.attrs.colspan-1,l=t.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&Gf(o,l.firstChild,l,r,a,n)}function VA(t){return Array(t).fill(0)}function qA(t,e){let n=[],r=t.doc.resolve(e),i=r.node(-1);if(!i)return oe.empty;let o=se.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<o.height;c++){let u=a+c*o.width;if((a==o.width-1||o.map[u]!=o.map[u+1])&&(c==0||o.map[u]!=o.map[u-o.width])){var l;let f=o.map[u],d=s+f+i.nodeAt(f).nodeSize-1,p=document.createElement("div");p.className="column-resize-handle",!((l=mt.getState(t))===null||l===void 0)&&l.dragging&&n.push(le.node(s+f,s+f+i.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),n.push(le.widget(d,p))}}return oe.create(t.doc,n)}function Lb({allowTableNodeSelection:t=!1}={}){return new X({key:Vn,state:{init(){return null},apply(e,n){let r=e.getMeta(Vn);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;let{deleted:i,pos:o}=e.mapping.mapResult(n);return i?null:o}},props:{decorations:uA,handleDOMEvents:{mousedown:BA},createSelectionBetween(e){return Vn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:DA,handleKeyDown:OA,handlePaste:LA},appendTransaction(e,n,r){return pA(r,mA(r,n),t)}})}var nl=typeof navigator<"u"?navigator:null,ed=nl&&nl.userAgent||"",KA=/Edge\/(\d+)/.exec(ed),UA=/MSIE \d/.exec(ed),JA=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ed),GA=!!(UA||JA||KA),XA=!GA&&!!nl&&/Apple Computer/.test(nl.vendor),Bb=new ee("safari-ime-span"),Zf=!1,YA={key:Bb,props:{decorations:QA,handleDOMEvents:{compositionstart:()=>{Zf=!0},compositionend:()=>{Zf=!1}}}};function QA(t){let{$from:e,$to:n,to:r}=t.selection;if(Zf&&e.sameParent(n)){let i=le.widget(r,ZA,{ignoreSelection:!0,key:"safari-ime-span"});return oe.create(t.doc,[i])}}function ZA(t){let e=t.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var Pb=new X(XA?YA:{key:Bb});function td(t,e){let n=String(t);if(typeof e!="string")throw new TypeError("Expected character");let r=0,i=n.indexOf(e);for(;i!==-1;)r++,i=n.indexOf(e,i+e.length);return r}function nd(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function rd(t,e,n){let i=Nn((n||{}).ignore||[]),o=eI(e),s=-1;for(;++s<o.length;)ar(t,"text",a);function a(c,u){let f=-1,d;for(;++f<u.length;){let p=u[f],h=d?d.children:void 0;if(i(p,h?h.indexOf(p):void 0,d))return;d=p}if(d)return l(c,u)}function l(c,u){let f=u[u.length-1],d=o[s][0],p=o[s][1],h=0,g=f.children.indexOf(c),y=!1,x=[];d.lastIndex=0;let C=d.exec(c.value);for(;C;){let v=C.index,A={index:C.index,input:C.input,stack:[...u,c]},w=p(...C,A);if(typeof w=="string"&&(w=w.length>0?{type:"text",value:w}:void 0),w===!1?d.lastIndex=v+1:(h!==v&&x.push({type:"text",value:c.value.slice(h,v)}),Array.isArray(w)?x.push(...w):w&&x.push(w),h=v+C[0].length,y=!0),!d.global)break;C=d.exec(c.value)}return y?(h<c.value.length&&x.push({type:"text",value:c.value.slice(h)}),f.children.splice(g,1,...x)):x=[c],g+x.length}}function eI(t){let e=[];if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");let n=!t[0]||Array.isArray(t[0])?t:[t],r=-1;for(;++r<n.length;){let i=n[r];e.push([tI(i[0]),nI(i[1])])}return e}function tI(t){return typeof t=="string"?new RegExp(nd(t),"g"):t}function nI(t){return typeof t=="function"?t:function(){return t}}var id="phrasing",od=["autolink","link","image","label"];function ad(){return{transforms:[lI],enter:{literalAutolink:rI,literalAutolinkEmail:sd,literalAutolinkHttp:sd,literalAutolinkWww:sd},exit:{literalAutolink:aI,literalAutolinkEmail:sI,literalAutolinkHttp:iI,literalAutolinkWww:oI}}}function ld(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:id,notInConstruct:od},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:id,notInConstruct:od},{character:":",before:"[ps]",after:"\\/",inConstruct:id,notInConstruct:od}]}}function rI(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function sd(t){this.config.enter.autolinkProtocol.call(this,t)}function iI(t){this.config.exit.autolinkProtocol.call(this,t)}function oI(t){this.config.exit.data.call(this,t);let e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function sI(t){this.config.exit.autolinkEmail.call(this,t)}function aI(t){this.exit(t)}function lI(t){rd(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,cI],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,uI]],{ignore:["link","linkReference"]})}function cI(t,e,n,r,i){let o="";if(!Fb(i)||(/^w/i.test(e)&&(n=e+n,e="",o="http://"),!fI(n)))return!1;let s=dI(n+r);if(!s[0])return!1;let a={type:"link",title:null,url:o+e+s[0],children:[{type:"text",value:e+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function uI(t,e,n,r){return!Fb(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function fI(t){let e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function dI(t){let e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let n=e[0],r=n.indexOf(")"),i=td(t,"("),o=td(t,")");for(;r!==-1&&i>o;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),o++;return[t,n]}function Fb(t,e){let n=t.input.charCodeAt(t.index-1);return(t.index===0||Ht(n)||tr(n))&&(!e||n!==47)}zb.peek=wI;function pI(){this.buffer()}function hI(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function mI(){this.buffer()}function gI(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function yI(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ve(this.sliceSerialize(t)).toLowerCase(),n.label=e}function kI(t){this.exit(t)}function bI(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ve(this.sliceSerialize(t)).toLowerCase(),n.label=e}function xI(t){this.exit(t)}function wI(){return"["}function zb(t,e,n,r){let i=n.createTracker(r),o=i.move("[^"),s=n.enter("footnoteReference"),a=n.enter("reference");return o+=i.move(n.safe(n.associationId(t),{after:"]",before:o})),a(),s(),o+=i.move("]"),o}function cd(){return{enter:{gfmFootnoteCallString:pI,gfmFootnoteCall:hI,gfmFootnoteDefinitionLabelString:mI,gfmFootnoteDefinition:gI},exit:{gfmFootnoteCallString:yI,gfmFootnoteCall:kI,gfmFootnoteDefinitionLabelString:bI,gfmFootnoteDefinition:xI}}}function ud(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:zb},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,o,s){let a=o.createTracker(s),l=a.move("[^"),c=o.enter("footnoteDefinition"),u=o.enter("label");return l+=a.move(o.safe(o.associationId(r),{before:l,after:"]"})),u(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((e?` +`:" ")+o.indentLines(o.containerFlow(r,a.current()),e?$b:CI))),c(),l}}function CI(t,e,n){return e===0?t:$b(t,e,n)}function $b(t,e,n){return(n?"":" ")+t}var SI=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];_b.peek=TI;function fd(){return{canContainEols:["delete"],enter:{strikethrough:MI},exit:{strikethrough:EI}}}function dd(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:SI}],handlers:{delete:_b}}}function MI(t){this.enter({type:"delete",children:[]},t)}function EI(t){this.exit(t)}function _b(t,e,n,r){let i=n.createTracker(r),o=n.enter("strikethrough"),s=i.move("~~");return s+=n.containerPhrasing(t,{...i.current(),before:s,after:"~"}),s+=i.move("~~"),o(),s}function TI(){return"~"}function vI(t){return t.length}function Wb(t,e){let n=e||{},r=(n.align||[]).concat(),i=n.stringLength||vI,o=[],s=[],a=[],l=[],c=0,u=-1;for(;++u<t.length;){let m=[],g=[],y=-1;for(t[u].length>c&&(c=t[u].length);++y<t[u].length;){let x=AI(t[u][y]);if(n.alignDelimiters!==!1){let C=i(x);g[y]=C,(l[y]===void 0||C>l[y])&&(l[y]=C)}m.push(x)}s[u]=m,a[u]=g}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<c;)o[f]=Hb(r[f]);else{let m=Hb(r);for(;++f<c;)o[f]=m}f=-1;let d=[],p=[];for(;++f<c;){let m=o[f],g="",y="";m===99?(g=":",y=":"):m===108?g=":":m===114&&(y=":");let x=n.alignDelimiters===!1?1:Math.max(1,l[f]-g.length-y.length),C=g+"-".repeat(x)+y;n.alignDelimiters!==!1&&(x=g.length+x+y.length,x>l[f]&&(l[f]=x),p[f]=x),d[f]=C}s.splice(1,0,d),a.splice(1,0,p),u=-1;let h=[];for(;++u<s.length;){let m=s[u],g=a[u];f=-1;let y=[];for(;++f<c;){let x=m[f]||"",C="",v="";if(n.alignDelimiters!==!1){let A=l[f]-(g[f]||0),w=o[f];w===114?C=" ".repeat(A):w===99?A%2?(C=" ".repeat(A/2+.5),v=" ".repeat(A/2-.5)):(C=" ".repeat(A/2),v=C):v=" ".repeat(A)}n.delimiterStart!==!1&&!f&&y.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&x==="")&&(n.delimiterStart!==!1||f)&&y.push(" "),n.alignDelimiters!==!1&&y.push(C),y.push(x),n.alignDelimiters!==!1&&y.push(v),n.padding!==!1&&y.push(" "),(n.delimiterEnd!==!1||f!==c-1)&&y.push("|")}h.push(n.delimiterEnd===!1?y.join("").replace(/ +$/,""):y.join(""))}return h.join(` +`)}function AI(t){return t==null?"":String(t)}function Hb(t){let e=typeof t=="string"?t.codePointAt(0):0;return e===67||e===99?99:e===76||e===108?108:e===82||e===114?114:0}function hd(){return{enter:{table:II,tableData:jb,tableHeader:jb,tableRow:RI},exit:{codeText:OI,table:NI,tableData:pd,tableHeader:pd,tableRow:pd}}}function II(t){let e=t._align;this.enter({type:"table",align:e.map(function(n){return n==="none"?null:n}),children:[]},t),this.data.inTable=!0}function NI(t){this.exit(t),this.data.inTable=void 0}function RI(t){this.enter({type:"tableRow",children:[]},t)}function pd(t){this.exit(t)}function jb(t){this.enter({type:"tableCell",children:[]},t)}function OI(t){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,DI));let n=this.stack[this.stack.length-1];n.type,n.value=e,this.exit(t)}function DI(t,e){return e==="|"?e:t}function md(t){let e=t||{},n=e.tableCellPadding,r=e.tablePipeAlign,i=e.stringLength,o=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:` `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:d,table:s,tableCell:l,tableRow:a}};function s(p,h,m,g){return c(u(p,m,g),p.align)}function a(p,h,m,g){let y=f(p,m,g),x=c([y]);return x.slice(0,x.indexOf(` -`))}function l(p,h,m,g){let y=m.enter("tableCell"),x=m.enter("phrasing"),C=m.containerPhrasing(p,{...g,before:o,after:o});return x(),y(),C}function c(p,h){return Hb(p,{align:h,alignDelimiters:r,padding:n,stringLength:i})}function u(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("table");for(;++y<g.length;)x[y]=f(g[y],h,m);return C(),x}function f(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("tableRow");for(;++y<g.length;)x[y]=l(g[y],p,h,m);return C(),x}function d(p,h,m){let g=lr.inlineCode(p,h,m);return m.stack.includes("tableCell")&&(g=g.replace(/\|/g,"\\$&")),g}}function gd(){return{exit:{taskListCheckValueChecked:jb,taskListCheckValueUnchecked:jb,paragraph:DI}}}function yd(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:LI}}}function jb(t){let e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function DI(t){let e=this.stack[this.stack.length-2];if(e&&e.type==="listItem"&&typeof e.checked=="boolean"){let n=this.stack[this.stack.length-1];n.type;let r=n.children[0];if(r&&r.type==="text"){let i=e.children,o=-1,s;for(;++o<i.length;){let a=i[o];if(a.type==="paragraph"){s=a;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(t)}function LI(t,e,n,r){let i=t.children[0],o=typeof t.checked=="boolean"&&i&&i.type==="paragraph",s="["+(t.checked?"x":" ")+"] ",a=n.createTracker(r);o&&a.move(s);let l=lr.listItem(t,e,n,{...r,...a.current()});return o&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+s}}function kd(){return[ad(),cd(),fd(),hd(),gd()]}function bd(t){return{extensions:[ld(),ud(t),dd(),md(t),yd()]}}var BI={tokenize:_I,partial:!0},Vb={tokenize:HI,partial:!0},qb={tokenize:WI,partial:!0},Kb={tokenize:jI,partial:!0},PI={tokenize:VI,partial:!0},Ub={name:"wwwAutolink",tokenize:zI,previous:Gb},Jb={name:"protocolAutolink",tokenize:$I,previous:Xb},kn={name:"emailAutolink",tokenize:FI,previous:Yb},qt={};function wd(){return{text:qt}}var Pr=48;for(;Pr<123;)qt[Pr]=kn,Pr++,Pr===58?Pr=65:Pr===91&&(Pr=97);qt[43]=kn;qt[45]=kn;qt[46]=kn;qt[95]=kn;qt[72]=[kn,Jb];qt[104]=[kn,Jb];qt[87]=[kn,Ub];qt[119]=[kn,Ub];function FI(t,e,n){let r=this,i,o;return s;function s(f){return!xd(f)||!Yb.call(r,r.previous)||Cd(r.events)?n(f):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(f))}function a(f){return xd(f)?(t.consume(f),a):f===64?(t.consume(f),l):n(f)}function l(f){return f===46?t.check(PI,u,c)(f):f===45||f===95||Te(f)?(o=!0,t.consume(f),l):u(f)}function c(f){return t.consume(f),i=!0,l}function u(f){return o&&i&&Ee(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(f)):n(f)}}function zI(t,e,n){let r=this;return i;function i(s){return s!==87&&s!==119||!Gb.call(r,r.previous)||Cd(r.events)?n(s):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(BI,t.attempt(Vb,t.attempt(qb,o),n),n)(s))}function o(s){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(s)}}function $I(t,e,n){let r=this,i="",o=!1;return s;function s(f){return(f===72||f===104)&&Xb.call(r,r.previous)&&!Cd(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),t.consume(f),a):n(f)}function a(f){if(Ee(f)&&i.length<5)return i+=String.fromCodePoint(f),t.consume(f),a;if(f===58){let d=i.toLowerCase();if(d==="http"||d==="https")return t.consume(f),l}return n(f)}function l(f){return f===47?(t.consume(f),o?c:(o=!0,l)):n(f)}function c(f){return f===null||er(f)||Z(f)||Ht(f)||tr(f)?n(f):t.attempt(Vb,t.attempt(qb,u),n)(f)}function u(f){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(f)}}function _I(t,e,n){let r=0;return i;function i(s){return(s===87||s===119)&&r<3?(r++,t.consume(s),i):s===46&&r===3?(t.consume(s),o):n(s)}function o(s){return s===null?n(s):e(s)}}function HI(t,e,n){let r,i,o;return s;function s(c){return c===46||c===95?t.check(Kb,l,a)(c):c===null||Z(c)||Ht(c)||c!==45&&tr(c)?l(c):(o=!0,t.consume(c),s)}function a(c){return c===95?r=!0:(i=r,r=void 0),t.consume(c),s}function l(c){return i||r||!o?n(c):e(c)}}function WI(t,e){let n=0,r=0;return i;function i(s){return s===40?(n++,t.consume(s),i):s===41&&r<n?o(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?t.check(Kb,e,o)(s):s===null||Z(s)||Ht(s)?e(s):(t.consume(s),i)}function o(s){return s===41&&r++,t.consume(s),i}}function jI(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),o):a===93?(t.consume(a),i):a===60||a===null||Z(a)||Ht(a)?e(a):n(a)}function i(a){return a===null||a===40||a===91||Z(a)||Ht(a)?e(a):r(a)}function o(a){return Ee(a)?s(a):n(a)}function s(a){return a===59?(t.consume(a),r):Ee(a)?(t.consume(a),s):n(a)}}function VI(t,e,n){return r;function r(o){return t.consume(o),i}function i(o){return Te(o)?n(o):e(o)}}function Gb(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||Z(t)}function Xb(t){return!Ee(t)}function Yb(t){return!(t===47||xd(t))}function xd(t){return t===43||t===45||t===46||t===95||Te(t)}function Cd(t){let e=t.length,n=!1;for(;e--;){let r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var qI={tokenize:QI,partial:!0};function Sd(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:GI,continuation:{tokenize:XI},exit:YI}},text:{91:{name:"gfmFootnoteCall",tokenize:JI},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:KI,resolveTo:UI}}}}function KI(t,e,n){let r=this,i=r.events.length,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),s;for(;i--;){let l=r.events[i][1];if(l.type==="labelImage"){s=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!s||!s._balanced)return n(l);let c=Ve(r.sliceSerialize({start:s.end,end:r.now()}));return c.codePointAt(0)!==94||!o.includes(c.slice(1))?n(l):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(l),t.exit("gfmFootnoteCallLabelMarker"),e(l))}}function UI(t,e){let n=t.length,r;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){r=t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";let i={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;let s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},t[t.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},l=[t[n+1],t[n+2],["enter",i,e],t[n+3],t[n+4],["enter",o,e],["exit",o,e],["enter",s,e],["enter",a,e],["exit",a,e],["exit",s,e],t[t.length-2],t[t.length-1],["exit",i,e]];return t.splice(n,t.length-n+1,...l),t}function JI(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o=0,s;return a;function a(f){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(t.enter("gfmFootnoteCallMarker"),t.consume(f),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",c)}function c(f){if(o>999||f===93&&!s||f===null||f===91||Z(f))return n(f);if(f===93){t.exit("chunkString");let d=t.exit("gfmFootnoteCallString");return i.includes(Ve(r.sliceSerialize(d)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(f)}return Z(f)||(s=!0),o++,t.consume(f),f===92?u:c}function u(f){return f===91||f===92||f===93?(t.consume(f),o++,c):c(f)}}function GI(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o,s=0,a;return l;function l(h){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(h){return h===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",u):n(h)}function u(h){if(s>999||h===93&&!a||h===null||h===91||Z(h))return n(h);if(h===93){t.exit("chunkString");let m=t.exit("gfmFootnoteDefinitionLabelString");return o=Ve(r.sliceSerialize(m)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),d}return Z(h)||(a=!0),s++,t.consume(h),h===92?f:u}function f(h){return h===91||h===92||h===93?(t.consume(h),s++,u):u(h)}function d(h){return h===58?(t.enter("definitionMarker"),t.consume(h),t.exit("definitionMarker"),i.includes(o)||i.push(o),$(t,p,"gfmFootnoteDefinitionWhitespace")):n(h)}function p(h){return e(h)}}function XI(t,e,n){return t.check(Wt,e,t.attempt(qI,e,n))}function YI(t){t.exit("gfmFootnoteDefinition")}function QI(t,e,n){let r=this;return $(t,i,"gfmFootnoteDefinitionIndent",5);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?e(o):n(o)}}function Md(t){let n=(t||{}).singleTilde,r={name:"strikethrough",tokenize:o,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(s,a){let l=-1;for(;++l<s.length;)if(s[l][0]==="enter"&&s[l][1].type==="strikethroughSequenceTemporary"&&s[l][1]._close){let c=l;for(;c--;)if(s[c][0]==="exit"&&s[c][1].type==="strikethroughSequenceTemporary"&&s[c][1]._open&&s[l][1].end.offset-s[l][1].start.offset===s[c][1].end.offset-s[c][1].start.offset){s[l][1].type="strikethroughSequence",s[c][1].type="strikethroughSequence";let u={type:"strikethrough",start:Object.assign({},s[c][1].start),end:Object.assign({},s[l][1].end)},f={type:"strikethroughText",start:Object.assign({},s[c][1].end),end:Object.assign({},s[l][1].start)},d=[["enter",u,a],["enter",s[c][1],a],["exit",s[c][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&ke(d,d.length,0,vn(p,s.slice(c+1,l),a)),ke(d,d.length,0,[["exit",f,a],["enter",s[l][1],a],["exit",s[l][1],a],["exit",u,a]]),ke(s,c-1,l-c+3,d),l=c+d.length-2;break}}for(l=-1;++l<s.length;)s[l][1].type==="strikethroughSequenceTemporary"&&(s[l][1].type="data");return s}function o(s,a,l){let c=this.previous,u=this.events,f=0;return d;function d(h){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(h):(s.enter("strikethroughSequenceTemporary"),p(h))}function p(h){let m=rn(c);if(h===126)return f>1?l(h):(s.consume(h),f++,p);if(f<2&&!n)return l(h);let g=s.exit("strikethroughSequenceTemporary"),y=rn(h);return g._open=!y||y===2&&!!m,g._close=!m||m===2&&!!y,a(h)}}}var rl=class{constructor(){this.map=[]}add(e,n,r){ZI(this,e,n,r)}consume(e){if(this.map.sort(function(o,s){return o[0]-s[0]}),this.map.length===0)return;let n=this.map.length,r=[];for(;n>0;)n-=1,r.push(e.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),e.length=this.map[n][0];r.push(e.slice()),e.length=0;let i=r.pop();for(;i;){for(let o of i)e.push(o);i=r.pop()}this.map.length=0}};function ZI(t,e,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<t.map.length;){if(t.map[i][0]===e){t.map[i][1]+=n,t.map[i][2].push(...r);return}i+=1}t.map.push([e,n,r])}}function Qb(t,e){let n=!1,r=[];for(;e<t.length;){let i=t[e];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(t[e+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(t[e-1][1].type==="tableDelimiterMarker"){let o=r.length-1;r[o]=r[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);e+=1}return r}function Ed(){return{flow:{null:{name:"table",tokenize:eN,resolveAll:tN}}}}function eN(t,e,n){let r=this,i=0,o=0,s;return a;function a(S){let me=r.events.length-1;for(;me>-1;){let W=r.events[me][1].type;if(W==="lineEnding"||W==="linePrefix")me--;else break}let te=me>-1?r.events[me][1].type:null,F=te==="tableHead"||te==="tableRow"?w:l;return F===w&&r.parser.lazy[r.now().line]?n(S):F(S)}function l(S){return t.enter("tableHead"),t.enter("tableRow"),c(S)}function c(S){return S===124||(s=!0,o+=1),u(S)}function u(S){return S===null?n(S):D(S)?o>1?(o=0,r.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(S),t.exit("lineEnding"),p):n(S):j(S)?$(t,u,"whitespace")(S):(o+=1,s&&(s=!1,i+=1),S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),s=!0,u):(t.enter("data"),f(S)))}function f(S){return S===null||S===124||Z(S)?(t.exit("data"),u(S)):(t.consume(S),S===92?d:f)}function d(S){return S===92||S===124?(t.consume(S),f):f(S)}function p(S){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(S):(t.enter("tableDelimiterRow"),s=!1,j(S)?$(t,h,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):h(S))}function h(S){return S===45||S===58?g(S):S===124?(s=!0,t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),m):A(S)}function m(S){return j(S)?$(t,g,"whitespace")(S):g(S)}function g(S){return S===58?(o+=1,s=!0,t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),y):S===45?(o+=1,y(S)):S===null||D(S)?v(S):A(S)}function y(S){return S===45?(t.enter("tableDelimiterFiller"),x(S)):A(S)}function x(S){return S===45?(t.consume(S),x):S===58?(s=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),C):(t.exit("tableDelimiterFiller"),C(S))}function C(S){return j(S)?$(t,v,"whitespace")(S):v(S)}function v(S){return S===124?h(S):S===null||D(S)?!s||i!==o?A(S):(t.exit("tableDelimiterRow"),t.exit("tableHead"),e(S)):A(S)}function A(S){return n(S)}function w(S){return t.enter("tableRow"),N(S)}function N(S){return S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),N):S===null||D(S)?(t.exit("tableRow"),e(S)):j(S)?$(t,N,"whitespace")(S):(t.enter("data"),B(S))}function B(S){return S===null||S===124||Z(S)?(t.exit("data"),N(S)):(t.consume(S),S===92?O:B)}function O(S){return S===92||S===124?(t.consume(S),B):B(S)}}function tN(t,e){let n=-1,r=!0,i=0,o=[0,0,0,0],s=[0,0,0,0],a=!1,l=0,c,u,f,d=new rl;for(;++n<t.length;){let p=t[n],h=p[1];p[0]==="enter"?h.type==="tableHead"?(a=!1,l!==0&&(Zb(d,e,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",c,e]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(r=!0,f=void 0,o=[0,0,0,0],s=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",u,e]])),i=h.type==="tableDelimiterRow"?2:u?3:1):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(o[1]!==0&&(s[0]=s[1],f=il(d,e,o,i,void 0,f),o=[0,0,0,0]),s[2]=n)):h.type==="tableCellDivider"&&(r?r=!1:(o[1]!==0&&(s[0]=s[1],f=il(d,e,o,i,void 0,f)),o=s,s=[o[1],n,0,0])):h.type==="tableHead"?(a=!0,l=n):h.type==="tableRow"||h.type==="tableDelimiterRow"?(l=n,o[1]!==0?(s[0]=s[1],f=il(d,e,o,i,n,f)):s[1]!==0&&(f=il(d,e,s,i,n,f)),i=0):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(s[3]=n)}for(l!==0&&Zb(d,e,l,c,u),d.consume(e.events),n=-1;++n<e.events.length;){let p=e.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Qb(e.events,n))}return t}function il(t,e,n,r,i,o){let s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(o.end=Object.assign({},zi(e.events,n[0])),t.add(n[0],0,[["exit",o,e]]));let l=zi(e.events,n[1]);if(o={type:s,start:Object.assign({},l),end:Object.assign({},l)},t.add(n[1],0,[["enter",o,e]]),n[2]!==0){let c=zi(e.events,n[2]),u=zi(e.events,n[3]),f={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(t.add(n[2],0,[["enter",f,e]]),r!==2){let d=e.events[n[2]],p=e.events[n[3]];if(d[1].end=Object.assign({},p[1].end),d[1].type="chunkText",d[1].contentType="text",n[3]>n[2]+1){let h=n[2]+1,m=n[3]-n[2]-1;t.add(h,m,[])}}t.add(n[3]+1,0,[["exit",f,e]])}return i!==void 0&&(o.end=Object.assign({},zi(e.events,i)),t.add(i,0,[["exit",o,e]]),o=void 0),o}function Zb(t,e,n,r,i){let o=[],s=zi(e.events,n);i&&(i.end=Object.assign({},s),o.push(["exit",i,e])),r.end=Object.assign({},s),o.push(["exit",r,e]),t.add(n+1,0,o)}function zi(t,e){let n=t[e],r=n[0]==="enter"?"start":"end";return n[1][r]}var nN={name:"tasklistCheck",tokenize:rN};function Td(){return{text:{91:nN}}}function rN(t,e,n){let r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),o)}function o(l){return Z(l)?(t.enter("taskListCheckValueUnchecked"),t.consume(l),t.exit("taskListCheckValueUnchecked"),s):l===88||l===120?(t.enter("taskListCheckValueChecked"),t.consume(l),t.exit("taskListCheckValueChecked"),s):n(l)}function s(l){return l===93?(t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),a):n(l)}function a(l){return D(l)?e(l):j(l)?t.check({tokenize:iN},e,n)(l):n(l)}}function iN(t,e,n){return $(t,r,"whitespace");function r(i){return i===null?n(i):e(i)}}function ex(t){return Os([wd(),Sd(),Md(t),Ed(),Td()])}var oN={};function ol(t){let e=this,n=t||oN,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(ex(n)),o.push(kd()),s.push(bd(n))}function q(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-gfm",...e}}),t}var Id=Or("strike_through");q(Id,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var Yo=Lt("strike_through",t=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:e=>e==="line-through"}],toDOM:e=>["del",t.get(Id.key)(e)],parseMarkdown:{match:e=>e.type==="delete",runner:(e,n,r)=>{e.openMark(r),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strike_through",runner:(e,n)=>{e.withMark(n,"delete")}}}));q(Yo.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});q(Yo.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var Nd=z("ToggleStrikeThrough",t=>()=>Ln(Yo.type(t)));q(Nd,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var nx=ge(t=>an(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,Yo.type(t)));q(nx,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var Rd=He("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:t=>{let e=t.get(Q);return()=>e.call(Nd.key)}}});q(Rd.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});q(Rd.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var Qo=yb({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:t=>t.style.textAlign||"left",setDOMAttr:(t,e)=>{e.style=`text-align: ${t||"left"}`}}}}),bn=ce("table",()=>({...Qo.table,content:"table_header_row table_row+",disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="table",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r,isHeader:s===0}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table",runner:(t,e)=>{let n=e.content.firstChild?.content;if(!n)return;let r=[];n.forEach(i=>{r.push(i.attrs.alignment)}),t.openNode("table",void 0,{align:r}),t.next(e.content),t.closeNode()}}}));q(bn.node,{displayName:"NodeSchema<table>",group:"Table"});q(bn.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var Zo=ce("table_header_row",()=>({...Qo.table_row,disableDropCursor:!0,content:"(table_header)*",parseDOM:[{tag:"tr[data-is-header]"},{tag:"tr",getAttrs:t=>t instanceof HTMLElement&&t.querySelector("th")?{}:!1}],toDOM(){return["tr",{"data-is-header":!0},0]},parseMarkdown:{match:t=>!!(t.type==="tableRow"&&t.isHeader),runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s],isHeader:e.isHeader}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow",void 0,{isHeader:!0}),t.next(e.content),t.closeNode())}}}));q(Zo.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});q(Zo.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var _i=ce("table_row",()=>({...Qo.table_row,disableDropCursor:!0,content:"(table_cell)*",parseMarkdown:{match:t=>t.type==="tableRow",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s]}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow"),t.next(e.content),t.closeNode())}}}));q(_i.node,{displayName:"NodeSchema<tableRow>",group:"Table"});q(_i.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var es=ce("table_cell",()=>({...Qo.table_cell,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}).openNode(t.schema.nodes.paragraph).next(e.children).closeNode().closeNode()}},toMarkdown:{match:t=>t.type.name==="table_cell",runner:(t,e)=>{t.openNode("tableCell").next(e.content).closeNode()}}}));q(es.node,{displayName:"NodeSchema<tableCell>",group:"Table"});q(es.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var $i=ce("table_header",()=>({...Qo.table_header,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}),t.openNode(t.schema.nodes.paragraph),t.next(e.children),t.closeNode(),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header",runner:(t,e)=>{t.openNode("tableCell"),t.next(e.content),t.closeNode()}}}));q($i.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});q($i.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function rx(t,e=3,n=3){let r=Array(n).fill(0).map(()=>es.type(t).createAndFill()),i=Array(n).fill(0).map(()=>$i.type(t).createAndFill()),o=Array(e).fill(0).map((s,a)=>a===0?Zo.type(t).create(null,i):_i.type(t).create(null,r));return bn.type(t).create(null,o)}function ix(t){return(e,n)=>r=>{n=n??r.selection.from;let i=r.doc.resolve(n),o=su(l=>l.type.name==="table")(i),s=o?{node:o.node,from:o.start}:void 0,a=t==="row";if(s){let l=oe.get(s.node);if(e>=0&&e<(a?l.height:l.width)){let c=l.positionAt(a?e:l.height-1,a?l.width-1:e,s.node),u=r.doc.resolve(s.from+c),f=a?he.rowSelection:he.colSelection,d=l.positionAt(a?e:0,a?0:e,s.node),p=r.doc.resolve(s.from+d);return ou(r.setSelection(f(u,p)))}}return r}}var sN=ix("row"),aN=ix("col");function ox(t,e,{map:n,tableStart:r,table:i},o){let s=Array(o).fill(0).reduce((l,c,u)=>l+i.child(u).nodeSize,r),a=Array(n.width).fill(0).map((l,c)=>{let u=i.nodeAt(n.map[c]);return es.type(t).createAndFill({alignment:u?.attrs.alignment})});return e.insert(s,_i.type(t).create(null,a)),e}function lN(t){let e=Fi(t.$from);if(!e)return;let n=oe.get(e.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(r=>{let i=e.node.nodeAt(r),o=r+e.start;return{pos:o,start:o+1,node:i}})}function cN(t){let e=lN(t.selection);if(e&&e[0]){let n=t.doc.resolve(e[0].pos),r=e[e.length-1];if(r){let i=t.doc.resolve(r.pos);return ou(t.setSelection(new he(i,n)))}}return t}var Od=z("GoToPrevTableCell",()=>()=>Xo(-1));q(Od,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var Dd=z("GoToNextTableCell",()=>()=>Xo(1));q(Dd,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var Ld=z("ExitTable",t=>()=>(e,n)=>{if(!Re(e))return!1;let{$head:r}=e.selection,i=Wg(r,bn.type(t));if(!i)return!1;let{to:o}=i,s=e.tr.replaceWith(o,o,Bt.type(t).createAndFill());return s.setSelection(_.near(s.doc.resolve(o),1)).scrollIntoView(),n?.(s),!0});q(Ld,{displayName:"Command<breakTableCommand>",group:"Table"});var sx=z("InsertTable",t=>({row:e,col:n}={})=>(r,i)=>{let{selection:o,tr:s}=r,{from:a}=o,l=rx(t,e,n),c=s.replaceSelectionWith(l),u=_.findFrom(c.doc.resolve(a),1,!0);return u&&c.setSelection(u),i?.(c),!0});q(sx,{displayName:"Command<insertTableCommand>",group:"Table"});var ax=z("MoveRow",()=>({from:t,to:e,pos:n}={})=>Ab({from:t??0,to:e??0,pos:n}));q(ax,{displayName:"Command<moveRowCommand>",group:"Table"});var lx=z("MoveCol",()=>({from:t,to:e,pos:n}={})=>Ib({from:t??0,to:e??0,pos:n}));q(lx,{displayName:"Command<moveColCommand>",group:"Table"});var cx=z("SelectRow",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(sN(t.index,t.pos)(r))});q(cx,{displayName:"Command<selectRowCommand>",group:"Table"});var ux=z("SelectCol",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(aN(t.index,t.pos)(r))});q(ux,{displayName:"Command<selectColCommand>",group:"Table"});var fx=z("SelectTable",()=>()=>(t,e)=>{let{tr:n}=t;return!!e?.(cN(n))});q(fx,{displayName:"Command<selectTableCommand>",group:"Table"});var dx=z("DeleteSelectedCells",()=>()=>(t,e)=>{let{selection:n}=t;if(!(n instanceof he))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?vb(t,e):i?el(t,e):tl(t,e)});q(dx,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var px=z("AddColBefore",()=>()=>Eb);q(px,{displayName:"Command<addColBeforeCommand>",group:"Table"});var hx=z("AddColAfter",()=>()=>Za);q(hx,{displayName:"Command<addColAfterCommand>",group:"Table"});var mx=z("AddRowBefore",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(ox(t,e.tr,r,r.top))}return!0});q(mx,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var gx=z("AddRowAfter",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(ox(t,e.tr,r,r.bottom))}return!0});q(gx,{displayName:"Command<addRowAfterCommand>",group:"Table"});var yx=z("SetAlign",()=>(t="left")=>Tb("alignment",t));q(yx,{displayName:"Command<setAlignCommand>",group:"Table"});var kx=ge(t=>new be(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(e,n,r,i)=>{let o=e.doc.resolve(r);if(!o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),bn.type(t)))return null;let s=rx(t,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),a=e.tr.replaceRangeWith(r,i,s);return a.setSelection(P.create(a.doc,r+3)).scrollIntoView()}));q(kx,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var bx=Ak(t=>({run:(e,n,r)=>{if(r)return e;function i(c){let u=c.childCount,f=c.lastChild?.childCount??0;if(u===0||f===0)return Bt.type(t).create();let d=c.firstChild;if(!(f>0&&d&&d.childCount===0))return c;if(u>=3){let g=c.child(1),y=[];for(let v=0;v<g.childCount;v++){let A=g.child(v);y.push($i.type(t).create(A.attrs,A.content,A.marks))}let x=d.type.create(d.attrs,y),C=[];for(let v=2;v<u;v++)C.push(c.child(v));return c.type.create(c.attrs,[x,...C])}let p=Array(f).fill(0).map(()=>$i.type(t).createAndFill()),h=new R(M.from(p),0,0),m=d.replace(0,0,h);return c.replace(0,d.nodeSize,new R(M.from(m),0,0))}function o(c){let u=_i.type(t),f=[],d=[],p=!1;function h(){if(d.length===0)return;let m=Zo.type(t).createAndFill(),g=bn.type(t).create(null,[m,...d]);f.push(i(g)),d=[]}return c.forEach(m=>{m.type===u?(p=!0,d.push(m)):(h(),f.push(m))}),h(),p?M.from(f):c}function s(c){let u=o(c),f=u!==c,d=[];return u.forEach(p=>{if(p.type===bn.type(t)){let h=i(p);h!==p&&(f=!0),d.push(h)}else if(p.childCount>0){let h=s(p.content);h!==p.content?(f=!0,d.push(p.copy(h))):d.push(p)}else d.push(p)}),f?M.from(d):c}function a(c){let u=[],f=[];c.forEach(d=>f.push(d));for(let d=0;d<f.length;d++){let p=f[d],h=f[d+1];p.type===Bt.type(t)&&p.content.size===0&&h&&h.type===bn.type(t)||u.push(p)}return u.length<f.length?M.from(u):c}let l=s(e.content);return l=a(l),new R(M.from(l),e.openStart,e.openEnd)}}));q(bx,{displayName:"PasteRule<table>",group:"Table"});var Bd=He("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:t=>{let e=t.get(Q);return()=>e.call(Dd.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:t=>{let e=t.get(Q);return()=>e.call(Od.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:t=>{let e=t.get(Q);return()=>e.call(Ld.key)}}});q(Bd.ctx,{displayName:"KeymapCtx<table>",group:"Table"});q(Bd.shortcuts,{displayName:"Keymap<table>",group:"Table"});var vd="footnote_definition",tx="footnoteDefinition",Pd=ce("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${vd}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw ft(t);return{label:t.dataset.label}},contentElement:"dd"}],toDOM:t=>{let e=t.attrs.label;return["dl",{"data-label":e,"data-type":vd},["dt",e],["dd",0]]},parseMarkdown:{match:({type:t})=>t===tx,runner:(t,e,n)=>{t.openNode(n,{label:e.label}).next(e.children).closeNode()}},toMarkdown:{match:t=>t.type.name===vd,runner:(t,e)=>{t.openNode(tx,void 0,{label:e.attrs.label,identifier:e.attrs.label}).next(e.content).closeNode()}}}));q(Pd.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});q(Pd.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var Ad="footnote_reference",Fd=ce("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${Ad}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw ft(t);return{label:t.dataset.label}}}],toDOM:t=>{let e=t.attrs.label;return["sup",{"data-label":e,"data-type":Ad},e]},parseMarkdown:{match:({type:t})=>t==="footnoteReference",runner:(t,e,n)=>{t.addNode(n,{label:e.label})}},toMarkdown:{match:t=>t.type.name===Ad,runner:(t,e)=>{t.addNode("footnoteReference",void 0,void 0,{label:e.attrs.label,identifier:e.attrs.label})}}}));q(Fd.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});q(Fd.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var zd=Vt.extendSchema(t=>e=>{let n=t(e);return{...n,attrs:{...n.attrs,checked:{default:null,validate:"boolean|null"}},parseDOM:[{tag:'li[data-item-type="task"]',getAttrs:r=>{if(!(r instanceof HTMLElement))throw ft(r);return{label:r.dataset.label,listType:r.dataset.listType,spread:r.dataset.spread,checked:r.dataset.checked?r.dataset.checked==="true":null}}},...n?.parseDOM||[]],toDOM:r=>n.toDOM&&r.attrs.checked==null?n.toDOM(r):["li",{"data-item-type":"task","data-label":r.attrs.label,"data-list-type":r.attrs.listType,"data-spread":r.attrs.spread,"data-checked":r.attrs.checked},0],parseMarkdown:{match:({type:r})=>r==="listItem",runner:(r,i,o)=>{if(i.checked==null){n.parseMarkdown.runner(r,i,o);return}let s=i.label!=null?`${i.label}.`:"\u2022",a=i.checked!=null?!!i.checked:null,l=i.label!=null?"ordered":"bullet",c=i.spread!=null?`${i.spread}`:"true";r.openNode(o,{label:s,listType:l,spread:c,checked:a}),r.next(i.children),r.closeNode()}},toMarkdown:{match:r=>r.type.name==="list_item",runner:(r,i)=>{if(i.attrs.checked==null){n.toMarkdown.runner(r,i);return}let o=i.attrs.label,s=i.attrs.listType,a=i.attrs.spread==="true",l=i.attrs.checked;r.openNode("listItem",void 0,{label:o,listType:s,spread:a,checked:l}),r.next(i.content),r.closeNode()}}}});q(zd.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});q(zd.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var xx=ge(()=>new be(/^\[(?<checked>\s|x)\]\s$/,(t,e,n,r)=>{let i=t.doc.resolve(n),o=0,s=i.node(o);for(;s&&s.type.name!=="list_item";)o--,s=i.node(o);if(!s||s.attrs.checked!=null)return null;let a=e.groups?.checked==="x",l=i.before(o),c=t.tr;return c.deleteRange(n,r).setNodeMarkup(l,void 0,{...s.attrs,checked:a}),c}));q(xx,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var uN=[Rd,Bd].flat(),fN=[kx,xx],dN=[nx],pN=[bx],wx=pe(()=>Bb);q(wx,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var hN=pe(()=>Rb({}));q(hN,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var Cx=pe(()=>Db({allowTableNodeSelection:!0}));q(Cx,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var $d=ht("remarkGFM",()=>ol);q($d.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});q($d.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var mN=new ee("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function gN(t,e){let n=0;return e.forEach((r,i,o)=>{r===t&&(n=o)}),n}var Sx=pe(()=>new X({key:mN,appendTransaction:(t,e,n)=>{let r,i=(o,s)=>{if(r||(r=n.tr),o.type.name!=="table_cell")return;let a=n.doc.resolve(s),l=a.node(a.depth),c=a.node(a.depth-1).firstChild;if(!c)return;let u=gN(o,l),f=c.maybeChild(u);if(!f)return;let d=f.attrs.alignment;d!==o.attrs.alignment&&r.setNodeMarkup(s,void 0,{...o.attrs,alignment:d})};return e.doc!==n.doc&&n.doc.descendants(i),r}}));q(Sx,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var yN=[Sx,wx,$d,Cx].flat(),kN=[zd,bn,Zo,_i,$i,es,Pd,Fd,Id,Yo].flat(),bN=[Dd,Od,Ld,sx,ax,lx,cx,ux,fx,dx,mx,gx,px,hx,yx,Nd],Mx=[kN,fN,pN,dN,uN,bN,yN].flat();var xN=typeof global=="object"&&global&&global.Object===Object&&global,Ex=xN;var wN=typeof self=="object"&&self&&self.Object===Object&&self,CN=Ex||wN||Function("return this")(),sl=CN;var SN=sl.Symbol,Hi=SN;var Tx=Object.prototype,MN=Tx.hasOwnProperty,EN=Tx.toString,ts=Hi?Hi.toStringTag:void 0;function TN(t){var e=MN.call(t,ts),n=t[ts];try{t[ts]=void 0;var r=!0}catch{}var i=EN.call(t);return r&&(e?t[ts]=n:delete t[ts]),i}var vx=TN;var vN=Object.prototype,AN=vN.toString;function IN(t){return AN.call(t)}var Ax=IN;var NN="[object Null]",RN="[object Undefined]",Ix=Hi?Hi.toStringTag:void 0;function ON(t){return t==null?t===void 0?RN:NN:Ix&&Ix in Object(t)?vx(t):Ax(t)}var Nx=ON;function DN(t){return t!=null&&typeof t=="object"}var Rx=DN;var LN="[object Symbol]";function BN(t){return typeof t=="symbol"||Rx(t)&&Nx(t)==LN}var Ox=BN;var PN=/\s/;function FN(t){for(var e=t.length;e--&&PN.test(t.charAt(e)););return e}var Dx=FN;var zN=/^\s+/;function $N(t){return t&&t.slice(0,Dx(t)+1).replace(zN,"")}var Lx=$N;function _N(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var ns=_N;var Bx=NaN,HN=/^[-+]0x[0-9a-f]+$/i,WN=/^0b[01]+$/i,jN=/^0o[0-7]+$/i,VN=parseInt;function qN(t){if(typeof t=="number")return t;if(Ox(t))return Bx;if(ns(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=ns(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=Lx(t);var n=WN.test(t);return n||jN.test(t)?VN(t.slice(2),n?2:8):HN.test(t)?Bx:+t}var _d=qN;var KN=function(){return sl.Date.now()},al=KN;var UN="Expected a function",JN=Math.max,GN=Math.min;function XN(t,e,n){var r,i,o,s,a,l,c=0,u=!1,f=!1,d=!0;if(typeof t!="function")throw new TypeError(UN);e=_d(e)||0,ns(n)&&(u=!!n.leading,f="maxWait"in n,o=f?JN(_d(n.maxWait)||0,e):o,d="trailing"in n?!!n.trailing:d);function p(w){var N=r,B=i;return r=i=void 0,c=w,s=t.apply(B,N),s}function h(w){return c=w,a=setTimeout(y,e),u?p(w):s}function m(w){var N=w-l,B=w-c,O=e-N;return f?GN(O,o-B):O}function g(w){var N=w-l,B=w-c;return l===void 0||N>=e||N<0||f&&B>=o}function y(){var w=al();if(g(w))return x(w);a=setTimeout(y,m(w))}function x(w){return a=void 0,d&&r?p(w):(r=i=void 0,s)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=i=a=void 0}function v(){return a===void 0?s:x(al())}function A(){var w=al(),N=g(w);if(r=arguments,i=this,l=w,N){if(a===void 0)return h(l);if(f)return clearTimeout(a),a=setTimeout(y,e),p(l)}return a===void 0&&(a=setTimeout(y,e)),s}return A.cancel=C,A.flush=v,A}var rs=XN;var Px=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=t=>(this.beforeMountedListeners.push(t),this),this.mounted=t=>(this.mountedListeners.push(t),this),this.updated=t=>(this.updatedListeners.push(t),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(t){return this.markdownUpdatedListeners.push(t),this}blur(t){return this.blurListeners.push(t),this}focus(t){return this.focusListeners.push(t),this}destroy(t){return this.destroyListeners.push(t),this}selectionUpdated(t){return this.selectionUpdatedListeners.push(t),this}},ll=Y(new Px,"listener"),YN=new ee("MILKDOWN_LISTENER"),Hd=t=>(t.inject(ll,new Px),async()=>{await t.wait(hn);let{listeners:e}=t.get(ll);e.beforeMount.forEach(c=>c(t)),await t.wait(Ei);let n=t.get(mn),r=null,i=null,o=null,s=null,a=rs(()=>{if(!s)return;let{doc:c}=s;if(e.updated.length>0&&r&&!r.eq(c)&&e.updated.forEach(u=>{u(t,c,r)}),e.markdownUpdated.length>0&&r&&!r.eq(c)){let u=n(c);e.markdownUpdated.forEach(f=>{f(t,u,i)}),i=u}r=c,s=null},200),l=new X({key:YN,view:()=>({destroy:()=>{a.cancel(),e.destroy.forEach(c=>c(t))}}),props:{handleDOMEvents:{focus:()=>(e.focus.forEach(c=>c(t)),!1),blur:()=>(e.blur.forEach(c=>c(t)),!1)}},state:{init:(c,u)=>{r=u.doc,i=n(u.doc)},apply:c=>{let u=c.selection;(!o&&u||o&&!u.eq(o))&&(e.selectionUpdated.forEach(f=>{f(t,u,o)}),o=u),!(!(c.docChanged||c.storedMarksSet)||c.getMeta("addToHistory")===!1)&&(s=c,a())}}});t.update(Dt,c=>c.concat(l)),await t.wait(jo),e.mounted.forEach(c=>c(t))});Hd.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var cl=200,We=function(){};We.prototype.append=function(e){return e.length?(e=We.from(e),!this.length&&e||e.length<cl&&this.leafAppend(e)||this.length<cl&&e.leafPrepend(this)||this.appendInner(e)):this};We.prototype.prepend=function(e){return e.length?We.from(e).append(this):this};We.prototype.appendInner=function(e){return new QN(this,e)};We.prototype.slice=function(e,n){return e===void 0&&(e=0),n===void 0&&(n=this.length),e>=n?We.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,n))};We.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};We.prototype.forEach=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length),n<=r?this.forEachInner(e,n,r,0):this.forEachInvertedInner(e,n,r,0)};We.prototype.map=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},n,r),i};We.from=function(e){return e instanceof We?e:e&&e.length?new Fx(e):We.empty};var Fx=(function(t){function e(r){t.call(this),this.values=r}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,a){for(var l=o;l<s;l++)if(i(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,a){for(var l=o-1;l>=s;l--)if(i(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=cl)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=cl)return new e(i.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e})(We);We.empty=new Fx([]);var QN=(function(t){function e(n,r){t.call(this),this.left=n,this.right=r,this.length=n.length+r.length,this.depth=Math.max(n.depth,r.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,i,o,s){var a=this.left.length;if(i<a&&this.left.forEachInner(r,i,Math.min(o,a),s)===!1||o>a&&this.right.forEachInner(r,Math.max(i-a,0),Math.min(this.length,o)-a,s+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var a=this.left.length;if(i>a&&this.right.forEachInvertedInner(r,i-a,Math.max(o,a)-a,s+a)===!1||o<a&&this.left.forEachInvertedInner(r,Math.min(i,a),o,s)===!1)return!1},e.prototype.sliceInner=function(r,i){if(r==0&&i==this.length)return this;var o=this.left.length;return i<=o?this.left.slice(r,i):r>=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e})(We),Wd=We;var ZN=500,zr=class t{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;n&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,a,l,c=[],u=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),o=i.maps.length),o--,u.push(f);return}if(i){u.push(new Kt(f.map));let p=f.step.map(i.slice(o)),h;p&&s.maybeStep(p).doc&&(h=s.mapping.maps[s.mapping.maps.length-1],c.push(new Kt(h,void 0,void 0,c.length+u.length))),o--,h&&i.appendMap(h,o)}else s.maybeStep(f.step);if(f.selection)return a=i?f.selection.map(i.slice(o)):f.selection,l=new t(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:s,selection:a}}addTransform(e,n,r,i){let o=[],s=this.eventCount,a=this.items,l=!i&&a.length?a.get(a.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),d=new Kt(e.mapping.maps[u],f,n),p;(p=l&&l.merge(d))&&(d=p,u?o.pop():a=a.slice(0,a.length-1)),o.push(d),n&&(s++,n=void 0),i||(l=d)}let c=s-r.depth;return c>tR&&(a=eR(a,c),s-=c),new t(a.append(o),s)}remapping(e,n){let r=new Eo;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,n),r}addMaps(e){return this.eventCount==0?this:new t(this.items.append(e.map(n=>new Kt(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),o=e.mapping,s=e.steps.length,a=this.eventCount;this.items.forEach(d=>{d.selection&&a--},i);let l=n;this.items.forEach(d=>{let p=o.getMirror(--l);if(p==null)return;s=Math.min(s,p);let h=o.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(o.slice(l+1,p));g&&a++,r.push(new Kt(h,m,g))}else r.push(new Kt(h))},i);let c=[];for(let d=n;d<s;d++)c.push(new Kt(o.maps[d]));let u=this.items.slice(0,i).append(c).append(r),f=new t(u,a);return f.emptyItemCount()>ZN&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),r=n.maps.length,i=[],o=0;return this.items.forEach((s,a)=>{if(a>=e)i.push(s),s.selection&&o++;else if(s.step){let l=s.step.map(n.slice(r)),c=l&&l.getMap();if(r--,c&&n.appendMap(c,r),l){let u=s.selection&&s.selection.map(n.slice(r));u&&o++;let f=new Kt(c.invert(),l,u),d,p=i.length-1;(d=i.length&&i[p].merge(f))?i[p]=d:i.push(f)}}else s.map&&r--},this.items.length,0),new t(Wd.from(i.reverse()),o)}};zr.empty=new zr(Wd.empty,0);function eR(t,e){let n;return t.forEach((r,i)=>{if(r.selection&&e--==0)return n=i,!1}),t.slice(n)}var Kt=class t{constructor(e,n,r,i){this.map=e,this.step=n,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new t(n.getMap().invert(),n,this.selection)}}},Ut=class{constructor(e,n,r,i,o){this.done=e,this.undone=n,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},tR=20;function nR(t,e,n,r){let i=n.getMeta(Fr),o;if(i)return i.historyState;n.getMeta(_x)&&(t=new Ut(t.done,t.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(s&&s.getMeta(Fr))return s.getMeta(Fr).redo?new Ut(t.done.addTransform(n,void 0,r,ul(e)),t.undone,zx(n.mapping.maps),t.prevTime,t.prevComposition):new Ut(t.done,t.undone.addTransform(n,void 0,r,ul(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let a=n.getMeta("composition"),l=t.prevTime==0||!s&&t.prevComposition!=a&&(t.prevTime<(n.time||0)-r.newGroupDelay||!rR(n,t.prevRanges)),c=s?jd(t.prevRanges,n.mapping):zx(n.mapping.maps);return new Ut(t.done.addTransform(n,l?e.selection.getBookmark():void 0,r,ul(e)),zr.empty,c,n.time,a??t.prevComposition)}else return(o=n.getMeta("rebased"))?new Ut(t.done.rebased(n,o),t.undone.rebased(n,o),jd(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new Ut(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),jd(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function rR(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((r,i)=>{for(let o=0;o<e.length;o+=2)r<=e[o+1]&&i>=e[o]&&(n=!0)}),n}function zx(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((r,i,o,s)=>e.push(o,s));return e}function jd(t,e){if(!t)return null;let n=[];for(let r=0;r<t.length;r+=2){let i=e.map(t[r],1),o=e.map(t[r+1],-1);i<=o&&n.push(i,o)}return n}function iR(t,e,n){let r=ul(e),i=Fr.get(e).spec.config,o=(n?t.undone:t.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),a=(n?t.done:t.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),l=new Ut(n?a:o.remaining,n?o.remaining:a,null,0,-1);return o.transform.setSelection(s).setMeta(Fr,{redo:n,historyState:l})}var Vd=!1,$x=null;function ul(t){let e=t.plugins;if($x!=e){Vd=!1,$x=e;for(let n=0;n<e.length;n++)if(e[n].spec.historyPreserveItems){Vd=!0;break}}return Vd}function is(t){return t.setMeta(_x,!0)}var Fr=new ee("history"),_x=new ee("closeHistory");function Hx(t={}){return t={depth:t.depth||100,newGroupDelay:t.newGroupDelay||500},new X({key:Fr,state:{init(){return new Ut(zr.empty,zr.empty,null,0,-1)},apply(e,n,r){return nR(n,r,e,t)}},config:t,props:{handleDOMEvents:{beforeinput(e,n){let r=n.inputType,i=r=="historyUndo"?ss:r=="historyRedo"?as:null;return!i||!e.editable?!1:(n.preventDefault(),i(e.state,e.dispatch))}}}})}function fl(t,e){return(n,r)=>{let i=Fr.getState(n);if(!i||(t?i.undone:i.done).eventCount==0)return!1;if(r){let o=iR(i,n,t);o&&r(e?o.scrollIntoView():o)}return!0}}var ss=fl(!1,!0),as=fl(!0,!0),GV=fl(!1,!1),XV=fl(!0,!1);function Wi(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-history",...e}}),t}var qd=z("Undo",()=>()=>ss);Wi(qd,{displayName:"Command<undo>"});var Kd=z("Redo",()=>()=>as);Wi(Kd,{displayName:"Command<redo>"});var Ud=ve({},"historyProviderConfig");Wi(Ud,{displayName:"Ctx<historyProviderConfig>"});var Wx=pe(t=>Hx(t.get(Ud.key)));Wi(Wx,{displayName:"Ctx<historyProviderPlugin>"});var Jd=He("historyKeymap",{Undo:{shortcuts:"Mod-z",command:t=>{let e=t.get(Q);return()=>e.call(qd.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:t=>{let e=t.get(Q);return()=>e.call(Kd.key)}}});Wi(Jd.ctx,{displayName:"KeymapCtx<history>"});Wi(Jd.shortcuts,{displayName:"Keymap<history>"});var jx=[Ud,Wx,Jd,qd,Kd].flat();function Gd(t){if(!t)return!1;if(Array.isArray(t))return t.length>1?!1:Gd(t[0]);let e=t.content;return e?Gd(e):t.type==="text"}function oR(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-clipboard",...e}}),t}function Vx(t,e){let n=ma(e);if(n)return t.dispatch(t.state.tr.replaceSelectionWith(n,!0)),!0;try{return t.dispatch(t.state.tr.replaceSelection(e)),!0}catch{return!1}}var Xd=pe(t=>{let e=t.get($e);return t.update(Rr,n=>({...n,editable:n.editable??(()=>!0),transformPastedHTML:(r,i)=>{let o=n.transformPastedHTML;return o&&(r=o(r,i)),r.includes("docs-internal-guid")&&(r=r.replace(/<b[^>]*id="docs-internal-guid[^"]*"[^>]*>([\s\S]*)<\/b>/,"$1"),r=r.replace(/<div[^>]*>(<table[\s\S]*?<\/table>)<\/div>/g,"$1")),r}})),new X({key:new ee("MILKDOWN_CLIPBOARD"),props:{handlePaste:(n,r,i)=>{let o=t.get(_e),s=n.props.editable?.(n.state),{clipboardData:a}=r;if(!s||!a||n.state.selection.$from.node().type.spec.code)return!1;let l=a.getData("text/plain"),c=a.getData("vscode-editor-data");if(c){let p=JSON.parse(c)?.mode;if(l&&p){let{tr:h}=n.state,m=jg("code_block",e);return h.replaceSelectionWith(m.create({language:p})).setSelection(P.near(h.doc.resolve(Math.max(0,h.selection.from-2)))).insertText(l.replace(/\r\n?/g,` -`)),n.dispatch(h),!0}}let u=a.getData("text/html");if(u.length===0&&l.length===0)return!1;if(u.length>0&&i)return Vx(n,i);let f=xt.fromSchema(e),d;if(u.length===0){let p=o(l);if(!p||typeof p=="string")return!1;d=wt.fromSchema(e).serializeFragment(p.content)}else{let p=document.createElement("template");p.innerHTML=u,d=p.content.cloneNode(!0),p.remove()}return Vx(n,f.parseSlice(d))},clipboardTextSerializer:n=>{let r=t.get(mn);if(Gd(n.content.toJSON()))return n.content.textBetween(0,n.content.size,` +`))}function l(p,h,m,g){let y=m.enter("tableCell"),x=m.enter("phrasing"),C=m.containerPhrasing(p,{...g,before:o,after:o});return x(),y(),C}function c(p,h){return Wb(p,{align:h,alignDelimiters:r,padding:n,stringLength:i})}function u(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("table");for(;++y<g.length;)x[y]=f(g[y],h,m);return C(),x}function f(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("tableRow");for(;++y<g.length;)x[y]=l(g[y],p,h,m);return C(),x}function d(p,h,m){let g=lr.inlineCode(p,h,m);return m.stack.includes("tableCell")&&(g=g.replace(/\|/g,"\\$&")),g}}function gd(){return{exit:{taskListCheckValueChecked:Vb,taskListCheckValueUnchecked:Vb,paragraph:LI}}}function yd(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:BI}}}function Vb(t){let e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function LI(t){let e=this.stack[this.stack.length-2];if(e&&e.type==="listItem"&&typeof e.checked=="boolean"){let n=this.stack[this.stack.length-1];n.type;let r=n.children[0];if(r&&r.type==="text"){let i=e.children,o=-1,s;for(;++o<i.length;){let a=i[o];if(a.type==="paragraph"){s=a;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(t)}function BI(t,e,n,r){let i=t.children[0],o=typeof t.checked=="boolean"&&i&&i.type==="paragraph",s="["+(t.checked?"x":" ")+"] ",a=n.createTracker(r);o&&a.move(s);let l=lr.listItem(t,e,n,{...r,...a.current()});return o&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+s}}function kd(){return[ad(),cd(),fd(),hd(),gd()]}function bd(t){return{extensions:[ld(),ud(t),dd(),md(t),yd()]}}var PI={tokenize:HI,partial:!0},qb={tokenize:WI,partial:!0},Kb={tokenize:jI,partial:!0},Ub={tokenize:VI,partial:!0},FI={tokenize:qI,partial:!0},Jb={name:"wwwAutolink",tokenize:$I,previous:Xb},Gb={name:"protocolAutolink",tokenize:_I,previous:Yb},kn={name:"emailAutolink",tokenize:zI,previous:Qb},qt={};function wd(){return{text:qt}}var Pr=48;for(;Pr<123;)qt[Pr]=kn,Pr++,Pr===58?Pr=65:Pr===91&&(Pr=97);qt[43]=kn;qt[45]=kn;qt[46]=kn;qt[95]=kn;qt[72]=[kn,Gb];qt[104]=[kn,Gb];qt[87]=[kn,Jb];qt[119]=[kn,Jb];function zI(t,e,n){let r=this,i,o;return s;function s(f){return!xd(f)||!Qb.call(r,r.previous)||Cd(r.events)?n(f):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(f))}function a(f){return xd(f)?(t.consume(f),a):f===64?(t.consume(f),l):n(f)}function l(f){return f===46?t.check(FI,u,c)(f):f===45||f===95||Te(f)?(o=!0,t.consume(f),l):u(f)}function c(f){return t.consume(f),i=!0,l}function u(f){return o&&i&&Ee(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(f)):n(f)}}function $I(t,e,n){let r=this;return i;function i(s){return s!==87&&s!==119||!Xb.call(r,r.previous)||Cd(r.events)?n(s):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(PI,t.attempt(qb,t.attempt(Kb,o),n),n)(s))}function o(s){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(s)}}function _I(t,e,n){let r=this,i="",o=!1;return s;function s(f){return(f===72||f===104)&&Yb.call(r,r.previous)&&!Cd(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),t.consume(f),a):n(f)}function a(f){if(Ee(f)&&i.length<5)return i+=String.fromCodePoint(f),t.consume(f),a;if(f===58){let d=i.toLowerCase();if(d==="http"||d==="https")return t.consume(f),l}return n(f)}function l(f){return f===47?(t.consume(f),o?c:(o=!0,l)):n(f)}function c(f){return f===null||er(f)||Z(f)||Ht(f)||tr(f)?n(f):t.attempt(qb,t.attempt(Kb,u),n)(f)}function u(f){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(f)}}function HI(t,e,n){let r=0;return i;function i(s){return(s===87||s===119)&&r<3?(r++,t.consume(s),i):s===46&&r===3?(t.consume(s),o):n(s)}function o(s){return s===null?n(s):e(s)}}function WI(t,e,n){let r,i,o;return s;function s(c){return c===46||c===95?t.check(Ub,l,a)(c):c===null||Z(c)||Ht(c)||c!==45&&tr(c)?l(c):(o=!0,t.consume(c),s)}function a(c){return c===95?r=!0:(i=r,r=void 0),t.consume(c),s}function l(c){return i||r||!o?n(c):e(c)}}function jI(t,e){let n=0,r=0;return i;function i(s){return s===40?(n++,t.consume(s),i):s===41&&r<n?o(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?t.check(Ub,e,o)(s):s===null||Z(s)||Ht(s)?e(s):(t.consume(s),i)}function o(s){return s===41&&r++,t.consume(s),i}}function VI(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),o):a===93?(t.consume(a),i):a===60||a===null||Z(a)||Ht(a)?e(a):n(a)}function i(a){return a===null||a===40||a===91||Z(a)||Ht(a)?e(a):r(a)}function o(a){return Ee(a)?s(a):n(a)}function s(a){return a===59?(t.consume(a),r):Ee(a)?(t.consume(a),s):n(a)}}function qI(t,e,n){return r;function r(o){return t.consume(o),i}function i(o){return Te(o)?n(o):e(o)}}function Xb(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||Z(t)}function Yb(t){return!Ee(t)}function Qb(t){return!(t===47||xd(t))}function xd(t){return t===43||t===45||t===46||t===95||Te(t)}function Cd(t){let e=t.length,n=!1;for(;e--;){let r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var KI={tokenize:ZI,partial:!0};function Sd(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:XI,continuation:{tokenize:YI},exit:QI}},text:{91:{name:"gfmFootnoteCall",tokenize:GI},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:UI,resolveTo:JI}}}}function UI(t,e,n){let r=this,i=r.events.length,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),s;for(;i--;){let l=r.events[i][1];if(l.type==="labelImage"){s=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!s||!s._balanced)return n(l);let c=Ve(r.sliceSerialize({start:s.end,end:r.now()}));return c.codePointAt(0)!==94||!o.includes(c.slice(1))?n(l):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(l),t.exit("gfmFootnoteCallLabelMarker"),e(l))}}function JI(t,e){let n=t.length,r;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){r=t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";let i={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;let s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},t[t.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},l=[t[n+1],t[n+2],["enter",i,e],t[n+3],t[n+4],["enter",o,e],["exit",o,e],["enter",s,e],["enter",a,e],["exit",a,e],["exit",s,e],t[t.length-2],t[t.length-1],["exit",i,e]];return t.splice(n,t.length-n+1,...l),t}function GI(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o=0,s;return a;function a(f){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(t.enter("gfmFootnoteCallMarker"),t.consume(f),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",c)}function c(f){if(o>999||f===93&&!s||f===null||f===91||Z(f))return n(f);if(f===93){t.exit("chunkString");let d=t.exit("gfmFootnoteCallString");return i.includes(Ve(r.sliceSerialize(d)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(f)}return Z(f)||(s=!0),o++,t.consume(f),f===92?u:c}function u(f){return f===91||f===92||f===93?(t.consume(f),o++,c):c(f)}}function XI(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o,s=0,a;return l;function l(h){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(h){return h===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",u):n(h)}function u(h){if(s>999||h===93&&!a||h===null||h===91||Z(h))return n(h);if(h===93){t.exit("chunkString");let m=t.exit("gfmFootnoteDefinitionLabelString");return o=Ve(r.sliceSerialize(m)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),d}return Z(h)||(a=!0),s++,t.consume(h),h===92?f:u}function f(h){return h===91||h===92||h===93?(t.consume(h),s++,u):u(h)}function d(h){return h===58?(t.enter("definitionMarker"),t.consume(h),t.exit("definitionMarker"),i.includes(o)||i.push(o),$(t,p,"gfmFootnoteDefinitionWhitespace")):n(h)}function p(h){return e(h)}}function YI(t,e,n){return t.check(Wt,e,t.attempt(KI,e,n))}function QI(t){t.exit("gfmFootnoteDefinition")}function ZI(t,e,n){let r=this;return $(t,i,"gfmFootnoteDefinitionIndent",5);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?e(o):n(o)}}function Md(t){let n=(t||{}).singleTilde,r={name:"strikethrough",tokenize:o,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(s,a){let l=-1;for(;++l<s.length;)if(s[l][0]==="enter"&&s[l][1].type==="strikethroughSequenceTemporary"&&s[l][1]._close){let c=l;for(;c--;)if(s[c][0]==="exit"&&s[c][1].type==="strikethroughSequenceTemporary"&&s[c][1]._open&&s[l][1].end.offset-s[l][1].start.offset===s[c][1].end.offset-s[c][1].start.offset){s[l][1].type="strikethroughSequence",s[c][1].type="strikethroughSequence";let u={type:"strikethrough",start:Object.assign({},s[c][1].start),end:Object.assign({},s[l][1].end)},f={type:"strikethroughText",start:Object.assign({},s[c][1].end),end:Object.assign({},s[l][1].start)},d=[["enter",u,a],["enter",s[c][1],a],["exit",s[c][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&ke(d,d.length,0,vn(p,s.slice(c+1,l),a)),ke(d,d.length,0,[["exit",f,a],["enter",s[l][1],a],["exit",s[l][1],a],["exit",u,a]]),ke(s,c-1,l-c+3,d),l=c+d.length-2;break}}for(l=-1;++l<s.length;)s[l][1].type==="strikethroughSequenceTemporary"&&(s[l][1].type="data");return s}function o(s,a,l){let c=this.previous,u=this.events,f=0;return d;function d(h){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(h):(s.enter("strikethroughSequenceTemporary"),p(h))}function p(h){let m=rn(c);if(h===126)return f>1?l(h):(s.consume(h),f++,p);if(f<2&&!n)return l(h);let g=s.exit("strikethroughSequenceTemporary"),y=rn(h);return g._open=!y||y===2&&!!m,g._close=!m||m===2&&!!y,a(h)}}}var rl=class{constructor(){this.map=[]}add(e,n,r){eN(this,e,n,r)}consume(e){if(this.map.sort(function(o,s){return o[0]-s[0]}),this.map.length===0)return;let n=this.map.length,r=[];for(;n>0;)n-=1,r.push(e.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),e.length=this.map[n][0];r.push(e.slice()),e.length=0;let i=r.pop();for(;i;){for(let o of i)e.push(o);i=r.pop()}this.map.length=0}};function eN(t,e,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<t.map.length;){if(t.map[i][0]===e){t.map[i][1]+=n,t.map[i][2].push(...r);return}i+=1}t.map.push([e,n,r])}}function Zb(t,e){let n=!1,r=[];for(;e<t.length;){let i=t[e];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(t[e+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(t[e-1][1].type==="tableDelimiterMarker"){let o=r.length-1;r[o]=r[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);e+=1}return r}function Ed(){return{flow:{null:{name:"table",tokenize:tN,resolveAll:nN}}}}function tN(t,e,n){let r=this,i=0,o=0,s;return a;function a(S){let me=r.events.length-1;for(;me>-1;){let W=r.events[me][1].type;if(W==="lineEnding"||W==="linePrefix")me--;else break}let te=me>-1?r.events[me][1].type:null,F=te==="tableHead"||te==="tableRow"?w:l;return F===w&&r.parser.lazy[r.now().line]?n(S):F(S)}function l(S){return t.enter("tableHead"),t.enter("tableRow"),c(S)}function c(S){return S===124||(s=!0,o+=1),u(S)}function u(S){return S===null?n(S):D(S)?o>1?(o=0,r.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(S),t.exit("lineEnding"),p):n(S):j(S)?$(t,u,"whitespace")(S):(o+=1,s&&(s=!1,i+=1),S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),s=!0,u):(t.enter("data"),f(S)))}function f(S){return S===null||S===124||Z(S)?(t.exit("data"),u(S)):(t.consume(S),S===92?d:f)}function d(S){return S===92||S===124?(t.consume(S),f):f(S)}function p(S){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(S):(t.enter("tableDelimiterRow"),s=!1,j(S)?$(t,h,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):h(S))}function h(S){return S===45||S===58?g(S):S===124?(s=!0,t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),m):A(S)}function m(S){return j(S)?$(t,g,"whitespace")(S):g(S)}function g(S){return S===58?(o+=1,s=!0,t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),y):S===45?(o+=1,y(S)):S===null||D(S)?v(S):A(S)}function y(S){return S===45?(t.enter("tableDelimiterFiller"),x(S)):A(S)}function x(S){return S===45?(t.consume(S),x):S===58?(s=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),C):(t.exit("tableDelimiterFiller"),C(S))}function C(S){return j(S)?$(t,v,"whitespace")(S):v(S)}function v(S){return S===124?h(S):S===null||D(S)?!s||i!==o?A(S):(t.exit("tableDelimiterRow"),t.exit("tableHead"),e(S)):A(S)}function A(S){return n(S)}function w(S){return t.enter("tableRow"),N(S)}function N(S){return S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),N):S===null||D(S)?(t.exit("tableRow"),e(S)):j(S)?$(t,N,"whitespace")(S):(t.enter("data"),B(S))}function B(S){return S===null||S===124||Z(S)?(t.exit("data"),N(S)):(t.consume(S),S===92?O:B)}function O(S){return S===92||S===124?(t.consume(S),B):B(S)}}function nN(t,e){let n=-1,r=!0,i=0,o=[0,0,0,0],s=[0,0,0,0],a=!1,l=0,c,u,f,d=new rl;for(;++n<t.length;){let p=t[n],h=p[1];p[0]==="enter"?h.type==="tableHead"?(a=!1,l!==0&&(ex(d,e,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",c,e]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(r=!0,f=void 0,o=[0,0,0,0],s=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",u,e]])),i=h.type==="tableDelimiterRow"?2:u?3:1):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(o[1]!==0&&(s[0]=s[1],f=il(d,e,o,i,void 0,f),o=[0,0,0,0]),s[2]=n)):h.type==="tableCellDivider"&&(r?r=!1:(o[1]!==0&&(s[0]=s[1],f=il(d,e,o,i,void 0,f)),o=s,s=[o[1],n,0,0])):h.type==="tableHead"?(a=!0,l=n):h.type==="tableRow"||h.type==="tableDelimiterRow"?(l=n,o[1]!==0?(s[0]=s[1],f=il(d,e,o,i,n,f)):s[1]!==0&&(f=il(d,e,s,i,n,f)),i=0):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(s[3]=n)}for(l!==0&&ex(d,e,l,c,u),d.consume(e.events),n=-1;++n<e.events.length;){let p=e.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Zb(e.events,n))}return t}function il(t,e,n,r,i,o){let s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(o.end=Object.assign({},zi(e.events,n[0])),t.add(n[0],0,[["exit",o,e]]));let l=zi(e.events,n[1]);if(o={type:s,start:Object.assign({},l),end:Object.assign({},l)},t.add(n[1],0,[["enter",o,e]]),n[2]!==0){let c=zi(e.events,n[2]),u=zi(e.events,n[3]),f={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(t.add(n[2],0,[["enter",f,e]]),r!==2){let d=e.events[n[2]],p=e.events[n[3]];if(d[1].end=Object.assign({},p[1].end),d[1].type="chunkText",d[1].contentType="text",n[3]>n[2]+1){let h=n[2]+1,m=n[3]-n[2]-1;t.add(h,m,[])}}t.add(n[3]+1,0,[["exit",f,e]])}return i!==void 0&&(o.end=Object.assign({},zi(e.events,i)),t.add(i,0,[["exit",o,e]]),o=void 0),o}function ex(t,e,n,r,i){let o=[],s=zi(e.events,n);i&&(i.end=Object.assign({},s),o.push(["exit",i,e])),r.end=Object.assign({},s),o.push(["exit",r,e]),t.add(n+1,0,o)}function zi(t,e){let n=t[e],r=n[0]==="enter"?"start":"end";return n[1][r]}var rN={name:"tasklistCheck",tokenize:iN};function Td(){return{text:{91:rN}}}function iN(t,e,n){let r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),o)}function o(l){return Z(l)?(t.enter("taskListCheckValueUnchecked"),t.consume(l),t.exit("taskListCheckValueUnchecked"),s):l===88||l===120?(t.enter("taskListCheckValueChecked"),t.consume(l),t.exit("taskListCheckValueChecked"),s):n(l)}function s(l){return l===93?(t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),a):n(l)}function a(l){return D(l)?e(l):j(l)?t.check({tokenize:oN},e,n)(l):n(l)}}function oN(t,e,n){return $(t,r,"whitespace");function r(i){return i===null?n(i):e(i)}}function tx(t){return Os([wd(),Sd(),Md(t),Ed(),Td()])}var sN={};function ol(t){let e=this,n=t||sN,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(tx(n)),o.push(kd()),s.push(bd(n))}function q(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-gfm",...e}}),t}var Id=Or("strike_through");q(Id,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var Yo=Lt("strike_through",t=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:e=>e==="line-through"}],toDOM:e=>["del",t.get(Id.key)(e)],parseMarkdown:{match:e=>e.type==="delete",runner:(e,n,r)=>{e.openMark(r),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strike_through",runner:(e,n)=>{e.withMark(n,"delete")}}}));q(Yo.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});q(Yo.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var Nd=z("ToggleStrikeThrough",t=>()=>Ln(Yo.type(t)));q(Nd,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var rx=ge(t=>an(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,Yo.type(t)));q(rx,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var Rd=He("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:t=>{let e=t.get(Q);return()=>e.call(Nd.key)}}});q(Rd.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});q(Rd.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var Qo=kb({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:t=>t.style.textAlign||"left",setDOMAttr:(t,e)=>{e.style=`text-align: ${t||"left"}`}}}}),bn=ce("table",()=>({...Qo.table,content:"table_header_row table_row+",disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="table",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r,isHeader:s===0}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table",runner:(t,e)=>{let n=e.content.firstChild?.content;if(!n)return;let r=[];n.forEach(i=>{r.push(i.attrs.alignment)}),t.openNode("table",void 0,{align:r}),t.next(e.content),t.closeNode()}}}));q(bn.node,{displayName:"NodeSchema<table>",group:"Table"});q(bn.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var Zo=ce("table_header_row",()=>({...Qo.table_row,disableDropCursor:!0,content:"(table_header)*",parseDOM:[{tag:"tr[data-is-header]"},{tag:"tr",getAttrs:t=>t instanceof HTMLElement&&t.querySelector("th")?{}:!1}],toDOM(){return["tr",{"data-is-header":!0},0]},parseMarkdown:{match:t=>!!(t.type==="tableRow"&&t.isHeader),runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s],isHeader:e.isHeader}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow",void 0,{isHeader:!0}),t.next(e.content),t.closeNode())}}}));q(Zo.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});q(Zo.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var _i=ce("table_row",()=>({...Qo.table_row,disableDropCursor:!0,content:"(table_cell)*",parseMarkdown:{match:t=>t.type==="tableRow",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s]}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow"),t.next(e.content),t.closeNode())}}}));q(_i.node,{displayName:"NodeSchema<tableRow>",group:"Table"});q(_i.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var es=ce("table_cell",()=>({...Qo.table_cell,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}).openNode(t.schema.nodes.paragraph).next(e.children).closeNode().closeNode()}},toMarkdown:{match:t=>t.type.name==="table_cell",runner:(t,e)=>{t.openNode("tableCell").next(e.content).closeNode()}}}));q(es.node,{displayName:"NodeSchema<tableCell>",group:"Table"});q(es.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var $i=ce("table_header",()=>({...Qo.table_header,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}),t.openNode(t.schema.nodes.paragraph),t.next(e.children),t.closeNode(),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header",runner:(t,e)=>{t.openNode("tableCell"),t.next(e.content),t.closeNode()}}}));q($i.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});q($i.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function ix(t,e=3,n=3){let r=Array(n).fill(0).map(()=>es.type(t).createAndFill()),i=Array(n).fill(0).map(()=>$i.type(t).createAndFill()),o=Array(e).fill(0).map((s,a)=>a===0?Zo.type(t).create(null,i):_i.type(t).create(null,r));return bn.type(t).create(null,o)}function ox(t){return(e,n)=>r=>{n=n??r.selection.from;let i=r.doc.resolve(n),o=su(l=>l.type.name==="table")(i),s=o?{node:o.node,from:o.start}:void 0,a=t==="row";if(s){let l=se.get(s.node);if(e>=0&&e<(a?l.height:l.width)){let c=l.positionAt(a?e:l.height-1,a?l.width-1:e,s.node),u=r.doc.resolve(s.from+c),f=a?he.rowSelection:he.colSelection,d=l.positionAt(a?e:0,a?0:e,s.node),p=r.doc.resolve(s.from+d);return ou(r.setSelection(f(u,p)))}}return r}}var aN=ox("row"),lN=ox("col");function sx(t,e,{map:n,tableStart:r,table:i},o){let s=Array(o).fill(0).reduce((l,c,u)=>l+i.child(u).nodeSize,r),a=Array(n.width).fill(0).map((l,c)=>{let u=i.nodeAt(n.map[c]);return es.type(t).createAndFill({alignment:u?.attrs.alignment})});return e.insert(s,_i.type(t).create(null,a)),e}function cN(t){let e=Fi(t.$from);if(!e)return;let n=se.get(e.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(r=>{let i=e.node.nodeAt(r),o=r+e.start;return{pos:o,start:o+1,node:i}})}function uN(t){let e=cN(t.selection);if(e&&e[0]){let n=t.doc.resolve(e[0].pos),r=e[e.length-1];if(r){let i=t.doc.resolve(r.pos);return ou(t.setSelection(new he(i,n)))}}return t}var Od=z("GoToPrevTableCell",()=>()=>Xo(-1));q(Od,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var Dd=z("GoToNextTableCell",()=>()=>Xo(1));q(Dd,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var Ld=z("ExitTable",t=>()=>(e,n)=>{if(!Re(e))return!1;let{$head:r}=e.selection,i=jg(r,bn.type(t));if(!i)return!1;let{to:o}=i,s=e.tr.replaceWith(o,o,Bt.type(t).createAndFill());return s.setSelection(_.near(s.doc.resolve(o),1)).scrollIntoView(),n?.(s),!0});q(Ld,{displayName:"Command<breakTableCommand>",group:"Table"});var ax=z("InsertTable",t=>({row:e,col:n}={})=>(r,i)=>{let{selection:o,tr:s}=r,{from:a}=o,l=ix(t,e,n),c=s.replaceSelectionWith(l),u=_.findFrom(c.doc.resolve(a),1,!0);return u&&c.setSelection(u),i?.(c),!0});q(ax,{displayName:"Command<insertTableCommand>",group:"Table"});var lx=z("MoveRow",()=>({from:t,to:e,pos:n}={})=>Ib({from:t??0,to:e??0,pos:n}));q(lx,{displayName:"Command<moveRowCommand>",group:"Table"});var cx=z("MoveCol",()=>({from:t,to:e,pos:n}={})=>Nb({from:t??0,to:e??0,pos:n}));q(cx,{displayName:"Command<moveColCommand>",group:"Table"});var ux=z("SelectRow",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(aN(t.index,t.pos)(r))});q(ux,{displayName:"Command<selectRowCommand>",group:"Table"});var fx=z("SelectCol",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(lN(t.index,t.pos)(r))});q(fx,{displayName:"Command<selectColCommand>",group:"Table"});var dx=z("SelectTable",()=>()=>(t,e)=>{let{tr:n}=t;return!!e?.(uN(n))});q(dx,{displayName:"Command<selectTableCommand>",group:"Table"});var px=z("DeleteSelectedCells",()=>()=>(t,e)=>{let{selection:n}=t;if(!(n instanceof he))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?Ab(t,e):i?el(t,e):tl(t,e)});q(px,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var hx=z("AddColBefore",()=>()=>Tb);q(hx,{displayName:"Command<addColBeforeCommand>",group:"Table"});var mx=z("AddColAfter",()=>()=>Za);q(mx,{displayName:"Command<addColAfterCommand>",group:"Table"});var gx=z("AddRowBefore",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(sx(t,e.tr,r,r.top))}return!0});q(gx,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var yx=z("AddRowAfter",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(sx(t,e.tr,r,r.bottom))}return!0});q(yx,{displayName:"Command<addRowAfterCommand>",group:"Table"});var kx=z("SetAlign",()=>(t="left")=>vb("alignment",t));q(kx,{displayName:"Command<setAlignCommand>",group:"Table"});var bx=ge(t=>new be(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(e,n,r,i)=>{let o=e.doc.resolve(r);if(!o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),bn.type(t)))return null;let s=ix(t,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),a=e.tr.replaceRangeWith(r,i,s);return a.setSelection(P.create(a.doc,r+3)).scrollIntoView()}));q(bx,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var xx=Ik(t=>({run:(e,n,r)=>{if(r)return e;function i(c){let u=c.childCount,f=c.lastChild?.childCount??0;if(u===0||f===0)return Bt.type(t).create();let d=c.firstChild;if(!(f>0&&d&&d.childCount===0))return c;if(u>=3){let g=c.child(1),y=[];for(let v=0;v<g.childCount;v++){let A=g.child(v);y.push($i.type(t).create(A.attrs,A.content,A.marks))}let x=d.type.create(d.attrs,y),C=[];for(let v=2;v<u;v++)C.push(c.child(v));return c.type.create(c.attrs,[x,...C])}let p=Array(f).fill(0).map(()=>$i.type(t).createAndFill()),h=new R(M.from(p),0,0),m=d.replace(0,0,h);return c.replace(0,d.nodeSize,new R(M.from(m),0,0))}function o(c){let u=_i.type(t),f=[],d=[],p=!1;function h(){if(d.length===0)return;let m=Zo.type(t).createAndFill(),g=bn.type(t).create(null,[m,...d]);f.push(i(g)),d=[]}return c.forEach(m=>{m.type===u?(p=!0,d.push(m)):(h(),f.push(m))}),h(),p?M.from(f):c}function s(c){let u=o(c),f=u!==c,d=[];return u.forEach(p=>{if(p.type===bn.type(t)){let h=i(p);h!==p&&(f=!0),d.push(h)}else if(p.childCount>0){let h=s(p.content);h!==p.content?(f=!0,d.push(p.copy(h))):d.push(p)}else d.push(p)}),f?M.from(d):c}function a(c){let u=[],f=[];c.forEach(d=>f.push(d));for(let d=0;d<f.length;d++){let p=f[d],h=f[d+1];p.type===Bt.type(t)&&p.content.size===0&&h&&h.type===bn.type(t)||u.push(p)}return u.length<f.length?M.from(u):c}let l=s(e.content);return l=a(l),new R(M.from(l),e.openStart,e.openEnd)}}));q(xx,{displayName:"PasteRule<table>",group:"Table"});var Bd=He("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:t=>{let e=t.get(Q);return()=>e.call(Dd.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:t=>{let e=t.get(Q);return()=>e.call(Od.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:t=>{let e=t.get(Q);return()=>e.call(Ld.key)}}});q(Bd.ctx,{displayName:"KeymapCtx<table>",group:"Table"});q(Bd.shortcuts,{displayName:"Keymap<table>",group:"Table"});var vd="footnote_definition",nx="footnoteDefinition",Pd=ce("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${vd}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw ft(t);return{label:t.dataset.label}},contentElement:"dd"}],toDOM:t=>{let e=t.attrs.label;return["dl",{"data-label":e,"data-type":vd},["dt",e],["dd",0]]},parseMarkdown:{match:({type:t})=>t===nx,runner:(t,e,n)=>{t.openNode(n,{label:e.label}).next(e.children).closeNode()}},toMarkdown:{match:t=>t.type.name===vd,runner:(t,e)=>{t.openNode(nx,void 0,{label:e.attrs.label,identifier:e.attrs.label}).next(e.content).closeNode()}}}));q(Pd.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});q(Pd.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var Ad="footnote_reference",Fd=ce("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${Ad}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw ft(t);return{label:t.dataset.label}}}],toDOM:t=>{let e=t.attrs.label;return["sup",{"data-label":e,"data-type":Ad},e]},parseMarkdown:{match:({type:t})=>t==="footnoteReference",runner:(t,e,n)=>{t.addNode(n,{label:e.label})}},toMarkdown:{match:t=>t.type.name===Ad,runner:(t,e)=>{t.addNode("footnoteReference",void 0,void 0,{label:e.attrs.label,identifier:e.attrs.label})}}}));q(Fd.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});q(Fd.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var zd=Vt.extendSchema(t=>e=>{let n=t(e);return{...n,attrs:{...n.attrs,checked:{default:null,validate:"boolean|null"}},parseDOM:[{tag:'li[data-item-type="task"]',getAttrs:r=>{if(!(r instanceof HTMLElement))throw ft(r);return{label:r.dataset.label,listType:r.dataset.listType,spread:r.dataset.spread,checked:r.dataset.checked?r.dataset.checked==="true":null}}},...n?.parseDOM||[]],toDOM:r=>n.toDOM&&r.attrs.checked==null?n.toDOM(r):["li",{"data-item-type":"task","data-label":r.attrs.label,"data-list-type":r.attrs.listType,"data-spread":r.attrs.spread,"data-checked":r.attrs.checked},0],parseMarkdown:{match:({type:r})=>r==="listItem",runner:(r,i,o)=>{if(i.checked==null){n.parseMarkdown.runner(r,i,o);return}let s=i.label!=null?`${i.label}.`:"\u2022",a=i.checked!=null?!!i.checked:null,l=i.label!=null?"ordered":"bullet",c=i.spread!=null?`${i.spread}`:"true";r.openNode(o,{label:s,listType:l,spread:c,checked:a}),r.next(i.children),r.closeNode()}},toMarkdown:{match:r=>r.type.name==="list_item",runner:(r,i)=>{if(i.attrs.checked==null){n.toMarkdown.runner(r,i);return}let o=i.attrs.label,s=i.attrs.listType,a=i.attrs.spread==="true",l=i.attrs.checked;r.openNode("listItem",void 0,{label:o,listType:s,spread:a,checked:l}),r.next(i.content),r.closeNode()}}}});q(zd.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});q(zd.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var wx=ge(()=>new be(/^\[(?<checked>\s|x)\]\s$/,(t,e,n,r)=>{let i=t.doc.resolve(n),o=0,s=i.node(o);for(;s&&s.type.name!=="list_item";)o--,s=i.node(o);if(!s||s.attrs.checked!=null)return null;let a=e.groups?.checked==="x",l=i.before(o),c=t.tr;return c.deleteRange(n,r).setNodeMarkup(l,void 0,{...s.attrs,checked:a}),c}));q(wx,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var fN=[Rd,Bd].flat(),dN=[bx,wx],pN=[rx],hN=[xx],Cx=pe(()=>Pb);q(Cx,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var mN=pe(()=>Ob({}));q(mN,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var Sx=pe(()=>Lb({allowTableNodeSelection:!0}));q(Sx,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var $d=ht("remarkGFM",()=>ol);q($d.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});q($d.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var gN=new ee("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function yN(t,e){let n=0;return e.forEach((r,i,o)=>{r===t&&(n=o)}),n}var Mx=pe(()=>new X({key:gN,appendTransaction:(t,e,n)=>{let r,i=(o,s)=>{if(r||(r=n.tr),o.type.name!=="table_cell")return;let a=n.doc.resolve(s),l=a.node(a.depth),c=a.node(a.depth-1).firstChild;if(!c)return;let u=yN(o,l),f=c.maybeChild(u);if(!f)return;let d=f.attrs.alignment;d!==o.attrs.alignment&&r.setNodeMarkup(s,void 0,{...o.attrs,alignment:d})};return e.doc!==n.doc&&n.doc.descendants(i),r}}));q(Mx,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var kN=[Mx,Cx,$d,Sx].flat(),bN=[zd,bn,Zo,_i,$i,es,Pd,Fd,Id,Yo].flat(),xN=[Dd,Od,Ld,ax,lx,cx,ux,fx,dx,px,gx,yx,hx,mx,kx,Nd],Ex=[bN,dN,hN,pN,fN,xN,kN].flat();var wN=typeof global=="object"&&global&&global.Object===Object&&global,Tx=wN;var CN=typeof self=="object"&&self&&self.Object===Object&&self,SN=Tx||CN||Function("return this")(),sl=SN;var MN=sl.Symbol,Hi=MN;var vx=Object.prototype,EN=vx.hasOwnProperty,TN=vx.toString,ts=Hi?Hi.toStringTag:void 0;function vN(t){var e=EN.call(t,ts),n=t[ts];try{t[ts]=void 0;var r=!0}catch{}var i=TN.call(t);return r&&(e?t[ts]=n:delete t[ts]),i}var Ax=vN;var AN=Object.prototype,IN=AN.toString;function NN(t){return IN.call(t)}var Ix=NN;var RN="[object Null]",ON="[object Undefined]",Nx=Hi?Hi.toStringTag:void 0;function DN(t){return t==null?t===void 0?ON:RN:Nx&&Nx in Object(t)?Ax(t):Ix(t)}var Rx=DN;function LN(t){return t!=null&&typeof t=="object"}var Ox=LN;var BN="[object Symbol]";function PN(t){return typeof t=="symbol"||Ox(t)&&Rx(t)==BN}var Dx=PN;var FN=/\s/;function zN(t){for(var e=t.length;e--&&FN.test(t.charAt(e)););return e}var Lx=zN;var $N=/^\s+/;function _N(t){return t&&t.slice(0,Lx(t)+1).replace($N,"")}var Bx=_N;function HN(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var ns=HN;var Px=NaN,WN=/^[-+]0x[0-9a-f]+$/i,jN=/^0b[01]+$/i,VN=/^0o[0-7]+$/i,qN=parseInt;function KN(t){if(typeof t=="number")return t;if(Dx(t))return Px;if(ns(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=ns(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=Bx(t);var n=jN.test(t);return n||VN.test(t)?qN(t.slice(2),n?2:8):WN.test(t)?Px:+t}var _d=KN;var UN=function(){return sl.Date.now()},al=UN;var JN="Expected a function",GN=Math.max,XN=Math.min;function YN(t,e,n){var r,i,o,s,a,l,c=0,u=!1,f=!1,d=!0;if(typeof t!="function")throw new TypeError(JN);e=_d(e)||0,ns(n)&&(u=!!n.leading,f="maxWait"in n,o=f?GN(_d(n.maxWait)||0,e):o,d="trailing"in n?!!n.trailing:d);function p(w){var N=r,B=i;return r=i=void 0,c=w,s=t.apply(B,N),s}function h(w){return c=w,a=setTimeout(y,e),u?p(w):s}function m(w){var N=w-l,B=w-c,O=e-N;return f?XN(O,o-B):O}function g(w){var N=w-l,B=w-c;return l===void 0||N>=e||N<0||f&&B>=o}function y(){var w=al();if(g(w))return x(w);a=setTimeout(y,m(w))}function x(w){return a=void 0,d&&r?p(w):(r=i=void 0,s)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=i=a=void 0}function v(){return a===void 0?s:x(al())}function A(){var w=al(),N=g(w);if(r=arguments,i=this,l=w,N){if(a===void 0)return h(l);if(f)return clearTimeout(a),a=setTimeout(y,e),p(l)}return a===void 0&&(a=setTimeout(y,e)),s}return A.cancel=C,A.flush=v,A}var rs=YN;var Fx=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=t=>(this.beforeMountedListeners.push(t),this),this.mounted=t=>(this.mountedListeners.push(t),this),this.updated=t=>(this.updatedListeners.push(t),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(t){return this.markdownUpdatedListeners.push(t),this}blur(t){return this.blurListeners.push(t),this}focus(t){return this.focusListeners.push(t),this}destroy(t){return this.destroyListeners.push(t),this}selectionUpdated(t){return this.selectionUpdatedListeners.push(t),this}},ll=Y(new Fx,"listener"),QN=new ee("MILKDOWN_LISTENER"),Hd=t=>(t.inject(ll,new Fx),async()=>{await t.wait(hn);let{listeners:e}=t.get(ll);e.beforeMount.forEach(c=>c(t)),await t.wait(Ei);let n=t.get(mn),r=null,i=null,o=null,s=null,a=rs(()=>{if(!s)return;let{doc:c}=s;if(e.updated.length>0&&r&&!r.eq(c)&&e.updated.forEach(u=>{u(t,c,r)}),e.markdownUpdated.length>0&&r&&!r.eq(c)){let u=n(c);e.markdownUpdated.forEach(f=>{f(t,u,i)}),i=u}r=c,s=null},200),l=new X({key:QN,view:()=>({destroy:()=>{a.cancel(),e.destroy.forEach(c=>c(t))}}),props:{handleDOMEvents:{focus:()=>(e.focus.forEach(c=>c(t)),!1),blur:()=>(e.blur.forEach(c=>c(t)),!1)}},state:{init:(c,u)=>{r=u.doc,i=n(u.doc)},apply:c=>{let u=c.selection;(!o&&u||o&&!u.eq(o))&&(e.selectionUpdated.forEach(f=>{f(t,u,o)}),o=u),!(!(c.docChanged||c.storedMarksSet)||c.getMeta("addToHistory")===!1)&&(s=c,a())}}});t.update(Dt,c=>c.concat(l)),await t.wait(jo),e.mounted.forEach(c=>c(t))});Hd.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var cl=200,We=function(){};We.prototype.append=function(e){return e.length?(e=We.from(e),!this.length&&e||e.length<cl&&this.leafAppend(e)||this.length<cl&&e.leafPrepend(this)||this.appendInner(e)):this};We.prototype.prepend=function(e){return e.length?We.from(e).append(this):this};We.prototype.appendInner=function(e){return new ZN(this,e)};We.prototype.slice=function(e,n){return e===void 0&&(e=0),n===void 0&&(n=this.length),e>=n?We.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,n))};We.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};We.prototype.forEach=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length),n<=r?this.forEachInner(e,n,r,0):this.forEachInvertedInner(e,n,r,0)};We.prototype.map=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},n,r),i};We.from=function(e){return e instanceof We?e:e&&e.length?new zx(e):We.empty};var zx=(function(t){function e(r){t.call(this),this.values=r}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,a){for(var l=o;l<s;l++)if(i(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,a){for(var l=o-1;l>=s;l--)if(i(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=cl)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=cl)return new e(i.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e})(We);We.empty=new zx([]);var ZN=(function(t){function e(n,r){t.call(this),this.left=n,this.right=r,this.length=n.length+r.length,this.depth=Math.max(n.depth,r.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,i,o,s){var a=this.left.length;if(i<a&&this.left.forEachInner(r,i,Math.min(o,a),s)===!1||o>a&&this.right.forEachInner(r,Math.max(i-a,0),Math.min(this.length,o)-a,s+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var a=this.left.length;if(i>a&&this.right.forEachInvertedInner(r,i-a,Math.max(o,a)-a,s+a)===!1||o<a&&this.left.forEachInvertedInner(r,Math.min(i,a),o,s)===!1)return!1},e.prototype.sliceInner=function(r,i){if(r==0&&i==this.length)return this;var o=this.left.length;return i<=o?this.left.slice(r,i):r>=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e})(We),Wd=We;var eR=500,zr=class t{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;n&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,a,l,c=[],u=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),o=i.maps.length),o--,u.push(f);return}if(i){u.push(new Kt(f.map));let p=f.step.map(i.slice(o)),h;p&&s.maybeStep(p).doc&&(h=s.mapping.maps[s.mapping.maps.length-1],c.push(new Kt(h,void 0,void 0,c.length+u.length))),o--,h&&i.appendMap(h,o)}else s.maybeStep(f.step);if(f.selection)return a=i?f.selection.map(i.slice(o)):f.selection,l=new t(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:s,selection:a}}addTransform(e,n,r,i){let o=[],s=this.eventCount,a=this.items,l=!i&&a.length?a.get(a.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),d=new Kt(e.mapping.maps[u],f,n),p;(p=l&&l.merge(d))&&(d=p,u?o.pop():a=a.slice(0,a.length-1)),o.push(d),n&&(s++,n=void 0),i||(l=d)}let c=s-r.depth;return c>nR&&(a=tR(a,c),s-=c),new t(a.append(o),s)}remapping(e,n){let r=new Eo;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,n),r}addMaps(e){return this.eventCount==0?this:new t(this.items.append(e.map(n=>new Kt(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),o=e.mapping,s=e.steps.length,a=this.eventCount;this.items.forEach(d=>{d.selection&&a--},i);let l=n;this.items.forEach(d=>{let p=o.getMirror(--l);if(p==null)return;s=Math.min(s,p);let h=o.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(o.slice(l+1,p));g&&a++,r.push(new Kt(h,m,g))}else r.push(new Kt(h))},i);let c=[];for(let d=n;d<s;d++)c.push(new Kt(o.maps[d]));let u=this.items.slice(0,i).append(c).append(r),f=new t(u,a);return f.emptyItemCount()>eR&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),r=n.maps.length,i=[],o=0;return this.items.forEach((s,a)=>{if(a>=e)i.push(s),s.selection&&o++;else if(s.step){let l=s.step.map(n.slice(r)),c=l&&l.getMap();if(r--,c&&n.appendMap(c,r),l){let u=s.selection&&s.selection.map(n.slice(r));u&&o++;let f=new Kt(c.invert(),l,u),d,p=i.length-1;(d=i.length&&i[p].merge(f))?i[p]=d:i.push(f)}}else s.map&&r--},this.items.length,0),new t(Wd.from(i.reverse()),o)}};zr.empty=new zr(Wd.empty,0);function tR(t,e){let n;return t.forEach((r,i)=>{if(r.selection&&e--==0)return n=i,!1}),t.slice(n)}var Kt=class t{constructor(e,n,r,i){this.map=e,this.step=n,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new t(n.getMap().invert(),n,this.selection)}}},Ut=class{constructor(e,n,r,i,o){this.done=e,this.undone=n,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},nR=20;function rR(t,e,n,r){let i=n.getMeta(Fr),o;if(i)return i.historyState;n.getMeta(Hx)&&(t=new Ut(t.done,t.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(s&&s.getMeta(Fr))return s.getMeta(Fr).redo?new Ut(t.done.addTransform(n,void 0,r,ul(e)),t.undone,$x(n.mapping.maps),t.prevTime,t.prevComposition):new Ut(t.done,t.undone.addTransform(n,void 0,r,ul(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let a=n.getMeta("composition"),l=t.prevTime==0||!s&&t.prevComposition!=a&&(t.prevTime<(n.time||0)-r.newGroupDelay||!iR(n,t.prevRanges)),c=s?jd(t.prevRanges,n.mapping):$x(n.mapping.maps);return new Ut(t.done.addTransform(n,l?e.selection.getBookmark():void 0,r,ul(e)),zr.empty,c,n.time,a??t.prevComposition)}else return(o=n.getMeta("rebased"))?new Ut(t.done.rebased(n,o),t.undone.rebased(n,o),jd(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new Ut(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),jd(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function iR(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((r,i)=>{for(let o=0;o<e.length;o+=2)r<=e[o+1]&&i>=e[o]&&(n=!0)}),n}function $x(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((r,i,o,s)=>e.push(o,s));return e}function jd(t,e){if(!t)return null;let n=[];for(let r=0;r<t.length;r+=2){let i=e.map(t[r],1),o=e.map(t[r+1],-1);i<=o&&n.push(i,o)}return n}function oR(t,e,n){let r=ul(e),i=Fr.get(e).spec.config,o=(n?t.undone:t.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),a=(n?t.done:t.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),l=new Ut(n?a:o.remaining,n?o.remaining:a,null,0,-1);return o.transform.setSelection(s).setMeta(Fr,{redo:n,historyState:l})}var Vd=!1,_x=null;function ul(t){let e=t.plugins;if(_x!=e){Vd=!1,_x=e;for(let n=0;n<e.length;n++)if(e[n].spec.historyPreserveItems){Vd=!0;break}}return Vd}function is(t){return t.setMeta(Hx,!0)}var Fr=new ee("history"),Hx=new ee("closeHistory");function Wx(t={}){return t={depth:t.depth||100,newGroupDelay:t.newGroupDelay||500},new X({key:Fr,state:{init(){return new Ut(zr.empty,zr.empty,null,0,-1)},apply(e,n,r){return rR(n,r,e,t)}},config:t,props:{handleDOMEvents:{beforeinput(e,n){let r=n.inputType,i=r=="historyUndo"?ss:r=="historyRedo"?as:null;return!i||!e.editable?!1:(n.preventDefault(),i(e.state,e.dispatch))}}}})}function fl(t,e){return(n,r)=>{let i=Fr.getState(n);if(!i||(t?i.undone:i.done).eventCount==0)return!1;if(r){let o=oR(i,n,t);o&&r(e?o.scrollIntoView():o)}return!0}}var ss=fl(!1,!0),as=fl(!0,!0),GV=fl(!1,!1),XV=fl(!0,!1);function Wi(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-history",...e}}),t}var qd=z("Undo",()=>()=>ss);Wi(qd,{displayName:"Command<undo>"});var Kd=z("Redo",()=>()=>as);Wi(Kd,{displayName:"Command<redo>"});var Ud=ve({},"historyProviderConfig");Wi(Ud,{displayName:"Ctx<historyProviderConfig>"});var jx=pe(t=>Wx(t.get(Ud.key)));Wi(jx,{displayName:"Ctx<historyProviderPlugin>"});var Jd=He("historyKeymap",{Undo:{shortcuts:"Mod-z",command:t=>{let e=t.get(Q);return()=>e.call(qd.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:t=>{let e=t.get(Q);return()=>e.call(Kd.key)}}});Wi(Jd.ctx,{displayName:"KeymapCtx<history>"});Wi(Jd.shortcuts,{displayName:"Keymap<history>"});var Vx=[Ud,jx,Jd,qd,Kd].flat();function Gd(t){if(!t)return!1;if(Array.isArray(t))return t.length>1?!1:Gd(t[0]);let e=t.content;return e?Gd(e):t.type==="text"}function sR(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-clipboard",...e}}),t}function qx(t,e){let n=ma(e);if(n)return t.dispatch(t.state.tr.replaceSelectionWith(n,!0)),!0;try{return t.dispatch(t.state.tr.replaceSelection(e)),!0}catch{return!1}}var Xd=pe(t=>{let e=t.get($e);return t.update(Rr,n=>({...n,editable:n.editable??(()=>!0),transformPastedHTML:(r,i)=>{let o=n.transformPastedHTML;return o&&(r=o(r,i)),r.includes("docs-internal-guid")&&(r=r.replace(/<b[^>]*id="docs-internal-guid[^"]*"[^>]*>([\s\S]*)<\/b>/,"$1"),r=r.replace(/<div[^>]*>(<table[\s\S]*?<\/table>)<\/div>/g,"$1")),r}})),new X({key:new ee("MILKDOWN_CLIPBOARD"),props:{handlePaste:(n,r,i)=>{let o=t.get(_e),s=n.props.editable?.(n.state),{clipboardData:a}=r;if(!s||!a||n.state.selection.$from.node().type.spec.code)return!1;let l=a.getData("text/plain"),c=a.getData("vscode-editor-data");if(c){let p=JSON.parse(c)?.mode;if(l&&p){let{tr:h}=n.state,m=Vg("code_block",e);return h.replaceSelectionWith(m.create({language:p})).setSelection(P.near(h.doc.resolve(Math.max(0,h.selection.from-2)))).insertText(l.replace(/\r\n?/g,` +`)),n.dispatch(h),!0}}let u=a.getData("text/html");if(u.length===0&&l.length===0)return!1;if(u.length>0&&i)return qx(n,i);let f=xt.fromSchema(e),d;if(u.length===0){let p=o(l);if(!p||typeof p=="string")return!1;d=wt.fromSchema(e).serializeFragment(p.content)}else{let p=document.createElement("template");p.innerHTML=u,d=p.content.cloneNode(!0),p.remove()}return qx(n,f.parseSlice(d))},clipboardTextSerializer:n=>{let r=t.get(mn);if(Gd(n.content.toJSON()))return n.content.textBetween(0,n.content.size,` -`);let i=e.topNodeType.createAndFill(void 0,n.content);return i?r(i):""}}})});oR(Xd,{displayName:"Prose<clipboard>"});function sR(t){let e=t.schema.cached.changeSetIDs||(t.schema.cached.changeSetIDs=Object.create(null)),n=e[t.name];return n==null&&(e[t.name]=n=Object.keys(t.schema.nodes).indexOf(t.name)+1),n}var Ux={encodeCharacter:t=>t,encodeNodeStart:t=>t.type.name,encodeNodeEnd:t=>-sR(t.type),compareTokens:(t,e)=>t===e};function Yd(t,e,n,r,i){for(let o=0,s=0;o<t.childCount;o++){let a=t.child(o),l=s+a.nodeSize,c=Math.max(s,n),u=Math.min(l,r);if(c<u)if(a.isText)for(let f=c;f<u;f++)i.push(e.encodeCharacter(a.text.charCodeAt(f-s),a.marks));else a.isLeaf?i.push(e.encodeNodeStart(a)):(c==s&&i.push(e.encodeNodeStart(a)),Yd(a.content,e,Math.max(s+1,c)-s-1,Math.min(l-1,u)-s-1,i),u==l&&i.push(e.encodeNodeEnd(a)));s=l}return i}var aR=5e3;function lR(t,e){return Math.min(15,Math.max(2,Math.floor(Math.max(t,e)/10)))}function Jx(t,e,n,r=Ux){let i=Yd(t,r,n.fromA,n.toA,[]),o=Yd(e,r,n.fromB,n.toB,[]),s=0,a=i.length,l=o.length,c=r.compareTokens;for(;s<i.length&&s<o.length&&c(i[s],o[s]);)s++;if(s==i.length&&s==o.length)return[];for(;a>s&&l>s&&c(i[a-1],o[l-1]);)a--,l--;if(a==s||l==s||a==l&&a==s+1)return[n.slice(s,a,s,l)];let u=a-s,f=l-s,d=Math.min(aR,u+f),p=d+1,h=[],m=[];for(let g=p*2,y=0;y<g;y++)m[y]=-1;for(let g=0;g<=d;g++){for(let y=-g;y<=g;y+=2){let x=m[y+1+d],C=m[y-1+d],v=x<C?C:x+1,A=v+y;for(;v<u&&A<f&&c(i[s+v],o[s+A]);)v++,A++;if(m[y+d]=v,v>=u&&A>=f){let w=[],N=lR(a-s,l-s),B=-1,O=-1,S=-1,me=-1,te=(F,W,V,se)=>{B>-1&&B<W+N?(B=F,S=V):(B>-1&&w.push(n.slice(B,O,S,me)),B=F,O=W,S=V,me=se)};for(let F=g-1;F>=0;F--){let W=m[y+1+d],V=m[y-1+d];W<V?(y--,v=V+s,A=v+y,te(v,v,A,A+1)):(y++,v=W+s,A=v+y,te(v,v+1,A,A)),m=h[F>>1]}return B>-1&&w.push(n.slice(B,O,S,me)),w.reverse()}}g%2==0&&h.push(m.slice())}return[n.slice(s,a,s,l)]}var Ce=class t{constructor(e,n){this.length=e,this.data=n}cut(e){return e==this.length?this:new t(e,this.data)}static slice(e,n,r){if(n==r)return t.none;if(n==0&&r==t.len(e))return e;let i=[];for(let o=0,s=0;s<r;o++){let a=e[o],l=s+a.length,c=Math.min(r,l)-Math.max(n,s);c>0&&i.push(a.cut(c)),s=l}return i}static join(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=r(e[e.length-1].data,n[0].data);if(i==null)return e.concat(n);let o=e.slice(0,e.length-1);o.push(new t(e[e.length-1].length+n[0].length,i));for(let s=1;s<n.length;s++)o.push(n[s]);return o}static len(e){let n=0;for(let r=0;r<e.length;r++)n+=e[r].length;return n}};Ce.none=[];var Jt=class t{constructor(e,n,r,i,o,s){this.fromA=e,this.toA=n,this.fromB=r,this.toB=i,this.deleted=o,this.inserted=s}get lenA(){return this.toA-this.fromA}get lenB(){return this.toB-this.fromB}slice(e,n,r,i){return e==0&&r==0&&n==this.toA-this.fromA&&i==this.toB-this.fromB?this:new t(this.fromA+e,this.fromA+n,this.fromB+r,this.fromB+i,Ce.slice(this.deleted,e,n),Ce.slice(this.inserted,r,i))}static merge(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=[];for(let o=0,s=0,a=e[0],l=n[0];;){if(!a&&!l)return i;if(a&&(!l||a.toB<l.fromA)){let c=s?n[s-1].toB-n[s-1].toA:0;i.push(c==0?a:new t(a.fromA,a.toA,a.fromB+c,a.toB+c,a.deleted,a.inserted)),a=o++==e.length?null:e[o]}else if(l&&(!a||l.toA<a.fromB)){let c=o?e[o-1].toB-e[o-1].toA:0;i.push(c==0?l:new t(l.fromA-c,l.toA-c,l.fromB,l.toB,l.deleted,l.inserted)),l=s++==n.length?null:n[s]}else{let c=Math.min(a.fromB,l.fromA),u=Math.min(a.fromA,l.fromA-(o?e[o-1].toB-e[o-1].toA:0)),f=u,d=Math.min(l.fromB,a.fromB+(s?n[s-1].toB-n[s-1].toA:0)),p=d,h=Ce.none,m=Ce.none,g=!1,y=!1;for(;;){let x=a?c>=a.fromB?a.toB:a.fromB:2e8,C=l?c>=l.fromA?l.toA:l.fromA:2e8,v=Math.min(x,C),A=a&&c>=a.fromB,w=l&&c>=l.fromA;if(!A&&!w)break;A&&c==a.fromB&&!g&&(h=Ce.join(h,a.deleted,r),f+=a.lenA,g=!0),A&&!w&&(m=Ce.join(m,Ce.slice(a.inserted,c-a.fromB,v-a.fromB),r),p+=v-c),w&&c==l.fromA&&!y&&(m=Ce.join(m,l.inserted,r),p+=l.lenB,y=!0),w&&!A&&(h=Ce.join(h,Ce.slice(l.deleted,c-l.fromA,v-l.fromA),r),f+=v-c),A&&v==a.toB&&(a=o++==e.length?null:e[o],g=!1),w&&v==l.toA&&(l=s++==n.length?null:n[s],y=!1),c=v}(u<f||d<p)&&i.push(new t(u,f,d,p,h,m))}}}static fromJSON(e){return new t(e.fromA,e.toA,e.fromB,e.toB,e.deleted.map(n=>new Ce(n.length,n.data)),e.inserted.map(n=>new Ce(n.length,n.data)))}toJSON(){return this}},cR;try{cR=new RegExp("[\\p{Alphabetic}_]","u")}catch{}var ji=class t{constructor(e,n){this.config=e,this.changes=n}addSteps(e,n,r){let i=[];for(let l=0;l<n.length;l++){let c=Array.isArray(r)?r[l]:r,u=0;n[l].forEach((f,d,p,h)=>{i.push(new Jt(f+u,d+u,p,h,f==d?Ce.none:[new Ce(d-f,c)],p==h?Ce.none:[new Ce(h-p,c)])),u=h-p-(d-f)})}if(i.length==0)return this;let o=Qd(i,this.config.combine),s=Jt.merge(this.changes,o,this.config.combine),a=s;for(let l=0;l<a.length;l++){let c=a[l];if(c.fromA==c.toA||c.fromB==c.toB||!o.some(f=>f.toB>c.fromB&&f.fromB<c.toB))continue;let u=Jx(this.config.doc.content,e.content,c,this.config.encoder);u.length==1&&u[0].fromB==0&&u[0].toB==c.toB-c.fromB||(a==s&&(a=s.slice()),u.length==1?a[l]=u[0]:(a.splice(l,1,...u),l+=u.length-1))}return new t(this.config,a)}get startDoc(){return this.config.doc}map(e){let n=r=>{let i=e(r);return i===r.data?r:new Ce(r.length,i)};return new t(this.config,this.changes.map(r=>new Jt(r.fromA,r.toA,r.fromB,r.toB,r.deleted.map(n),r.inserted.map(n))))}changedRange(e,n){if(e==this)return null;let r=n&&uR(n),i=r?r.toB-r.fromB-(r.toA-r.fromA):0;function o(f){return!r||f<=r.fromA?f:f+i}let s=r?r.fromB:2e8,a=r?r.toB:-2e8;function l(f,d=f){s=Math.min(f,s),a=Math.max(d,a)}let c=this.changes,u=e.changes;for(let f=0,d=0;f<c.length&&d<u.length;){let p=c[f],h=u[d];p&&h&&fR(p,h,o)?(f++,d++):h&&(!p||o(p.fromB)>=h.fromB)?(l(h.fromB,h.toB),d++):(l(o(p.fromB),o(p.toB)),f++)}return s<=a?{from:s,to:a}:null}static create(e,n=(o,s)=>o===s?o:null,r=Ux,i=[]){return new t({combine:n,doc:e,encoder:r},i)}};ji.computeDiff=Jx;function Qd(t,e,n=0,r=t.length){if(r==n+1)return[t[n]];let i=n+r>>1;return Jt.merge(Qd(t,e,n,i),Qd(t,e,i,r),e)}function qx(t){let e=2e8,n=-2e8;for(let r=0;r<t.length;r++){let i=t[r];e!=2e8&&(e=i.map(e,-1),n=i.map(n,1)),i.forEach((o,s,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==2e8?null:{from:e,to:n}}function uR(t){let e=qx(t);if(!e)return null;let n=qx(t.map(r=>r.invert()).reverse());return{fromA:n.from,toA:n.to,fromB:e.from,toB:e.to}}function fR(t,e,n){return n(t.fromB)==e.fromB&&n(t.toB)==e.toB&&Kx(t.deleted,e.deleted)&&Kx(t.inserted,e.inserted)}function Kx(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n].length!=e[n].length||t[n].data!==e[n].data)return!1;return!0}function Gt(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-diff",...e}}),t}var Gx=500;function dR(t={}){let e=new WeakMap,n=new WeakMap;function r(i){let o=e.get(i);if(o!=null)return o;let s=i.attrs,a=s?Object.keys(s).filter(l=>s[l]!=null).sort():[];if(a.length===0)o=i.type.name;else{let l={};for(let c of a)l[c]=s[c];o=`${i.type.name}:${JSON.stringify(l)}`}return e.set(i,o),o}return{encodeCharacter:(i,o)=>{if(o.length===0)return i;let s=n.get(o);return s==null&&(s=o.map(r).join(","),n.set(o,s)),`${i}:${s}`},encodeNodeStart:i=>{let o=i.attrs;if(o&&Object.keys(o).length>0){let s=t[i.type.name]??[],a=Object.keys(o).filter(l=>{if(s.includes(l))return!1;let c=i.type.spec.attrs?.[l]?.default;return o[l]!==c});if(a.length>0){let l={};for(let c of a.sort())l[c]=o[c];return`${i.type.name}:${JSON.stringify(l)}`}}return i.type.name},encodeNodeEnd:i=>{let o=i.type.schema,s=o.cached.changeSetIDs||(o.cached.changeSetIDs=Object.create(null)),a=s[i.type.name];return a==null&&(s[i.type.name]=a=Object.keys(o.nodes).indexOf(i.type.name)+1),-a},compareTokens:(i,o)=>i===o}}function Zx(t,e,n){let r=n.get(t);if(r!=null)return r;let i=[String(e.encodeNodeStart(t))];if(t.isText){let s=t.text;for(let a=0;a<s.length;a++)i.push(":"+String(e.encodeCharacter(s.charCodeAt(a),t.marks)))}else t.content.forEach(s=>{i.push("/"+Zx(s,e,n))});i.push("\\"+String(e.encodeNodeEnd(t)));let o=i.join("");return n.set(t,o),o}function Xx(t,e,n){let r=[],i=0;return t.content.forEach(o=>{r.push({node:o,offset:i,size:o.nodeSize,signature:Zx(o,n.encoder,n.sigCache)}),i+=o.nodeSize}),{node:t,contentStart:e,content:r}}function pR(t,e){let n=t.length,r=e.length,i=Array.from({length:n+1},()=>Array.from({length:r+1},()=>0));for(let l=n-1;l>=0;l--)for(let c=r-1;c>=0;c--)t[l].signature===e[c].signature?i[l][c]=i[l+1][c+1]+1:i[l][c]=Math.max(i[l+1][c],i[l][c+1]);let o=[],s=0,a=0;for(;s<n&&a<r;)t[s].signature===e[a].signature?(o.push([s,a]),s++,a++):i[s+1][a]>=i[s][a+1]?s++:a++;return o}function hR(t,e){if(t.type!==e.type)return!1;let n=t.type;return!(n.isTextblock||n.isAtom||n.spec.code===!0||!n.isBlock)}function ew(t,e,n){return Jt.fromJSON({fromA:t.fromA+e,toA:t.toA+e,fromB:t.fromB+n,toB:t.toB+n,deleted:t.deleted.map(r=>({length:r.length,data:r.data})),inserted:t.inserted.map(r=>({length:r.length,data:r.data}))})}function mR(t,e,n){let r=t.parent.copy(M.from(t.node)),i=e.parent.copy(M.from(e.node)),o=new xe(0,r.content.size,new R(i.content,0,0));return ji.create(r,void 0,n.encoder).addSteps(i,[o.getMap()],null).changes.map(s=>ew(s,t.abs,e.abs))}function Yx(t,e){let n=t.content;if(e<n.length)return t.contentStart+n[e].offset;if(e>0){let r=n[e-1];return t.contentStart+r.offset+r.size}return t.contentStart+t.node.content.size}function gR(t,e,n){return Jt.fromJSON({fromA:e,toA:e+t.size,fromB:n,toB:n,deleted:[{length:t.size,data:null}],inserted:[]})}function yR(t,e,n){return Jt.fromJSON({fromA:e,toA:e,fromB:n,toB:n+t.size,deleted:[],inserted:[{length:t.size,data:null}]})}function kR(t,e,n,r,i){let o=new xe(0,t.content.size,new R(e.content,0,0));return ji.create(t,void 0,i.encoder).addSteps(e,[o.getMap()],null).changes.map(s=>ew(s,n,r))}function dl(t,e,n,r,i){if(t.childCount>Gx||e.childCount>Gx)return kR(t,e,n,r,i);let o=Xx(t,n,i),s=Xx(e,r,i),a=pR(o.content,s.content),l=[],c=0,u=0;for(let[f,d]of a)Qx(o,s,{oldStart:c,oldEnd:f,newStart:u,newEnd:d},i,l),c=f+1,u=d+1;return Qx(o,s,{oldStart:c,oldEnd:o.content.length,newStart:u,newEnd:s.content.length},i,l),l}function Qx(t,e,n,r,i){let o=t.content,s=e.content,a=n.oldStart,l=n.newStart;for(;a<n.oldEnd||l<n.newEnd;){let c=a<n.oldEnd?o[a]:null,u=l<n.newEnd?s[l]:null,f=c&&u&&c.node.type===u.node.type;if(c&&u&&f){i.push(...bR(t,e,c,u,r)),a++,l++;continue}if(c&&(!u||!f)){let d=t.contentStart+c.offset;i.push(gR(c,d,Yx(e,l))),a++;continue}if(u){let d=e.contentStart+u.offset;i.push(yR(u,Yx(t,a),d)),l++}}}function bR(t,e,n,r,i){let o=t.contentStart+n.offset,s=e.contentStart+r.offset;return hR(n.node,r.node)&&xR(n.node,r.node,i.encoder)?dl(n.node,r.node,o+1,s+1,i):mR({node:n.node,parent:t.node,abs:o},{node:r.node,parent:e.node,abs:s},i)}function xR(t,e,n){return n.encodeNodeStart(t)===n.encodeNodeStart(e)}function wR(t,e,n,r,i){let o=t.resolve(n),s=t.resolve(r),a=e.resolve(n),l=e.resolve(r),c=o.sharedDepth(r);if(a.sharedDepth(r)!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) resolves to different sharedDepth in old and new docs`);for(let m=0;m<=c;m++){if(i.encodeNodeStart(o.node(m))!==i.encodeNodeStart(a.node(m)))throw new RangeError(`computeDocDiff: ancestor at depth ${m} differs in type or non-ignored attrs along the path to the shared ancestor`);if(o.start(m)!==a.start(m))throw new RangeError(`computeDocDiff: ancestor at depth ${m} starts at different absolute positions in old and new docs (content before the range differs in size)`)}let u=o.node(c);if(u.isTextblock)throw new RangeError(`computeDocDiff: range [${n}, ${r}) lands inside a textblock; widen the range to a block boundary`);if(o.depth!==c||s.depth!==c||a.depth!==c||l.depth!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) endpoints must be aligned to child boundaries of the shared ancestor`);let f=a.node(c),d=o.start(c),p=n-d,h=r-d;return{oldCut:u.copy(u.content.cut(p,h)),newCut:f.copy(f.content.cut(p,h)),cutAbsStart:n}}function ls(t,e,n){let r=dR(n?.ignoreAttrs),i={encoder:r,sigCache:new WeakMap},o=t.content.size,s=e.content.size,a=n?.range;if(a==null)return dl(t,e,0,0,i);let l=Math.min(o,s),c=Math.max(0,Math.min(a.from??0,l)),u=Math.max(c,Math.min(a.to??l,l));if(c===u)return[];if(c===0&&u===l&&o===s)return dl(t,e,0,0,i);let f=wR(t,e,c,u,r);return dl(f.oldCut,f.newCut,f.cutAbsStart,f.cutAbsStart,i)}var tw=ve({ignoreAttrs:{heading:["id"]}},"diffConfig");Gt(tw,{displayName:"Ctx<diffConfig>",group:"Diff"});var Oe=new ee("MILKDOWN_DIFF");function CR(t,e,n){let r=ls(t,e.newDoc,n);return{...e,changes:r}}function SR(t,e){return e.some(n=>t.fromB<n.toB&&t.toB>n.fromB)}function pl(t){return t.changes.filter(e=>!SR(e,t.rejectedRanges))}var MR=pe(t=>{let e=t.get(tw.key);return new X({key:Oe,state:{init:()=>null,apply(n,r,i,o){let s=n.getMeta(Oe);if(!r){if(s?.type==="start"){let c=ls(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}return null}let a=r;if(n.docChanged&&a.active&&(a=CR(o.doc,a,{ignoreAttrs:e.ignoreAttrs})),!s)return a;let l;switch(s.type){case"start":{let c=ls(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}case"accept":case"acceptRange":l=a;break;case"reject":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.fromB,toB:s.toB}]};break;case"rejectRange":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.range.fromB,toB:s.range.toB}]};break;case"acceptAll":case"clear":return null;default:return a}return l.active&&pl(l).length===0?null:l}},filterTransaction(n,r){return!Oe.getState(r)?.active||n.getMeta(Oe)?!0:!n.docChanged}})});Gt(MR,{displayName:"Prose<diff>",group:"Diff"});function ER(t,e){let n=pl(e);for(let r=n.length-1;r>=0;r--){let i=n[r],o=e.newDoc.slice(i.fromB,i.toB);t=t.replace(i.fromA,i.toA,o)}return t}var TR=z("StartDiffReview",t=>e=>(n,r)=>{if(e==null)return!1;let i=t.get(_e)(e);return i?(r&&r(n.tr.setMeta(Oe,{type:"start",newDoc:i})),!0):!1});Gt(TR,{displayName:"Command<startDiffReview>",group:"Diff"});var Zd=z("StartDiffReviewFromDoc",()=>t=>(e,n)=>!t||t.type!==e.doc.type?!1:(n&&n(e.tr.setMeta(Oe,{type:"start",newDoc:t})),!0));Gt(Zd,{displayName:"Command<startDiffReviewFromDoc>",group:"Diff"});var vR=z("AcceptDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Oe.getState(e);if(!r)return!1;let i=pl(r)[t];if(!i)return!1;if(n){let o=r.newDoc.slice(i.fromB,i.toB),s=e.tr.replace(i.fromA,i.toA,o);s=s.setMeta(Oe,{type:"accept",changeIndex:t}),n(s)}return!0});Gt(vR,{displayName:"Command<acceptDiffChunk>",group:"Diff"});var AR=z("RejectDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Oe.getState(e);if(!r)return!1;let i=pl(r)[t];return i?(n&&n(e.tr.setMeta(Oe,{type:"reject",fromB:i.fromB,toB:i.toB})),!0):!1});Gt(AR,{displayName:"Command<rejectDiffChunk>",group:"Diff"});var IR=z("AcceptDiffRange",()=>t=>(e,n)=>{if(!t)return!1;let r=Oe.getState(e);if(!r)return!1;if(n){let i=r.newDoc.slice(t.fromB,t.toB),o=e.tr.replace(t.fromA,t.toA,i);o=o.setMeta(Oe,{type:"acceptRange",range:t}),n(o)}return!0});Gt(IR,{displayName:"Command<acceptDiffRange>",group:"Diff"});var NR=z("RejectDiffRange",()=>t=>(e,n)=>!t||!Oe.getState(e)?!1:(n&&n(e.tr.setMeta(Oe,{type:"rejectRange",range:t})),!0));Gt(NR,{displayName:"Command<rejectDiffRange>",group:"Diff"});var RR=z("AcceptAllDiffs",()=>()=>(t,e)=>{let n=Oe.getState(t);return n?(e&&e((n.rejectedRanges.length===0?t.tr.replaceWith(0,t.doc.content.size,n.newDoc.content):ER(t.tr,n)).setMeta(Oe,{type:"acceptAll"})),!0):!1});Gt(RR,{displayName:"Command<acceptAllDiffs>",group:"Diff"});var OR=z("ClearDiffReview",()=>()=>(t,e)=>Oe.getState(t)?(e&&e(t.tr.setMeta(Oe,{type:"clear"})),!0):!1);Gt(OR,{displayName:"Command<clearDiffReview>",group:"Diff"});function Vi(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-streaming",...e}}),t}var qn=ve({throttleMs:100,scrollFollow:!0,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}},"streamingConfig");Vi(qn,{displayName:"Ctx<streamingConfig>",group:"Streaming"});function DR(t,e,n){let r=t.get(_e)(n);if(!r)return{tr:e,newDoc:null};let i=t.get(qn.key).ignoreAttrs,o=ls(e.doc,r,i?{ignoreAttrs:i}:void 0);for(let s=o.length-1;s>=0;s--){let a=o[s],l=r.slice(a.fromB,a.toB);e=e.replace(a.fromA,a.toA,l)}return{tr:e,newDoc:r}}function LR(t){if(t.parent.type.spec.code)return{type:"plain-text",preserveNewlines:!0};for(let e=t.depth;e>0;e--)if(t.node(e).type.name==="table")return{type:"plain-text",preserveNewlines:!1};return t.depth>=1?{type:"split-block"}:{type:"block"}}function nw(t){if(t.childCount===0)return t;let e=t.lastChild;return e.type.name==="paragraph"&&e.content.size===0?t.cut(0,t.size-e.nodeSize):t}function BR(t,e,n){let{insertPos:r,currentEndPos:i}=n,o=n.buffer.replace(/\r\n?/g,` -`);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=e.doc.content.size,a=Math.max(0,Math.min(r,s)),l=Math.max(a,Math.min(i,s)),c=e.doc.resolve(a),u=(t.get(qn.key).insertStrategy??LR)(c),f={ctx:t,tr:e,buffer:o,from:a,to:l,resolved:c};switch(u.type){case"plain-text":return PR(f,u.preserveNewlines??!1);case"split-block":return zR(f);case"block":return $R(f)}}function PR({tr:t,buffer:e,from:n,to:r},i){let o=i?e:e.replace(/\n/g," "),s=t.doc.type.schema.text(o);return t=t.replaceWith(n,r,s),{tr:t,applied:!0,insertEndPos:n+o.length}}var FR=/[*_~`[\\<]/;function ep(t,e,n){if(!n)return M.empty;if(!FR.test(n))return M.from(e.text(n));let r=t.get(_e)(n)?.firstChild;if(r?.type.name!=="paragraph"||r.content.size===0)return M.from(e.text(n));let i=!1;if(r.content.forEach(l=>{(!l.isText||l.marks.length>0)&&(i=!0)}),!i)return M.from(e.text(n));let o=r.content,s=/^\s+/.exec(n)?.[0];s&&((o.firstChild?.isText?o.firstChild.text??"":"").startsWith(s)||(o=M.from(e.text(s)).append(o)));let a=/\s+$/.exec(n)?.[0];return a&&((o.lastChild?.isText?o.lastChild.text??"":"").endsWith(a)||(o=o.append(M.from(e.text(a))))),o}function zR({ctx:t,tr:e,buffer:n,from:r,to:i,resolved:o}){let s=e.doc.type.schema,a=n.indexOf(` -`);if(a<0){let A=ep(t,s,n);return e=e.replaceWith(r,i,A),{tr:e,applied:!0,insertEndPos:r+A.size}}let l=n.substring(0,a),c=n.substring(a+1),u=t.get(_e),f=c.trim()?u(c):null,d=f?nw(f.content):M.empty;if(d.childCount===0){let A=ep(t,s,n.replace(/\n/g," "));return e=e.replaceWith(r,i,A),{tr:e,applied:!0,insertEndPos:r+A.size}}let p=o.depth,h=ep(t,s,l);for(let A=p;A>0;A--)h=M.from(o.node(A).copy(h));let m=h.append(d),g=new R(m,p,0),y=e.doc.content.size,x=e.doc.resolve(Math.min(i,y)),C=i;p>0&&x.depth===p&&x.parentOffset===x.parent.content.size&&(C=x.after(p)),e=e.replace(r,C,g);let v=m.size-p;return{tr:e,applied:!0,insertEndPos:r+v}}function $R({ctx:t,tr:e,buffer:n,from:r,to:i}){let o=t.get(_e)(n);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=nw(o.content);return s.size===0?{tr:e,applied:!1,insertEndPos:i}:(e=e.replace(r,i,new R(s,0,0)),{tr:e,applied:!0,insertEndPos:r+s.size})}function tp(t,e,n){if(n.insertPos!=null){let r=n.insertPos,i=BR(t,e,{buffer:n.buffer,insertPos:r,currentEndPos:n.insertEndPos??r});return{tr:i.tr,newDoc:i.applied?i.tr.doc:null,insertEndPos:i.insertEndPos}}return DR(t,e,n.buffer)}var et=new ee("MILKDOWN_STREAMING");function _R(t,e){if(!t&&e?.type!=="start")return null;if(!e)return t;switch(e.type){case"start":return{buffer:"",originalDoc:e.originalDoc,active:!0,lastApplyTime:e.lastApplyTime,insertPos:e.insertPos??null,insertEndPos:e.insertEndPos??e.insertPos??null};case"push":return t?{...t,buffer:t.buffer+e.token}:null;case"apply":return t?{...t,lastApplyTime:e.lastApplyTime,insertEndPos:e.insertEndPos??t.insertEndPos}:null;case"end":case"abort":return null;default:return t}}var rw=pe(t=>{let e=t.get(qn.key);return new X({key:et,state:{init:()=>null,apply(n,r){return _R(r,n.getMeta(et))}},filterTransaction(n,r){return!et.getState(r)?.active||n.getMeta(et)?!0:!n.docChanged},view(){return HR(t,e)}})});Vi(rw,{displayName:"Prose<streaming>",group:"Streaming"});function HR(t,e){let n=null,r=-1,i=null;function o(){if(!i)return;let a=et.getState(i.state);if(!a?.active||a.buffer.length===r)return;r=a.buffer.length;let l=tp(t,i.state.tr,a);if(!l.newDoc)return;let c=l.tr;!c.docChanged&&l.insertEndPos==null||(c=c.setMeta(et,{type:"apply",lastApplyTime:Date.now(),insertEndPos:l.insertEndPos}),e.scrollFollow&&(c=c.scrollIntoView()),i.dispatch(c))}function s(){n!=null&&clearTimeout(n),n=setTimeout(o,e.throttleMs)}return{update(a){i=a;let l=et.getState(a.state);if(!l?.active){n!=null&&(clearTimeout(n),n=null),r=-1;return}l.buffer.length!==r&&(Date.now()-l.lastApplyTime>=e.throttleMs?o():s())},destroy(){n!=null&&(clearTimeout(n),n=null),i=null}}}var cs=z("StartStreaming",()=>t=>(e,n)=>{if(et.getState(e)?.active)return!1;if(n){let r,i;if(t?.insertAt!=null)if(t.insertAt==="selection"){if(r=e.selection.from,i=e.selection.to,e.selection.empty){let o=e.doc.resolve(r);o.parent.isTextblock&&!o.parent.type.spec.code&&o.parent.content.size===0&&o.depth===1&&(r=o.before(o.depth),i=o.after(o.depth))}}else{let o=t.insertAt==="cursor"?e.selection.head:t.insertAt;if(!Number.isFinite(o))return!1;r=Math.max(0,Math.min(Math.round(o),e.doc.content.size));let s=e.doc.resolve(r);s.parent.isTextblock&&!s.parent.type.spec.code&&s.parent.content.size===0&&s.depth===1&&(r=s.before(s.depth),i=s.after(s.depth))}n(e.tr.setMeta(et,{type:"start",originalDoc:e.doc,insertPos:r,insertEndPos:i,lastApplyTime:Date.now()}))}return!0});Vi(cs,{displayName:"Command<startStreaming>",group:"Streaming"});var hl=z("PushChunk",()=>t=>(e,n)=>t==null||!et.getState(e)?.active?!1:(n&&n(e.tr.setMeta(et,{type:"push",token:t})),!0));Vi(hl,{displayName:"Command<pushChunk>",group:"Streaming"});var us=z("EndStreaming",t=>e=>(n,r)=>{let i=et.getState(n);if(!i?.active)return!1;if(r){let o=t.get(qn.key),s=e?.diffReview??o.diffReviewOnEnd,a=tp(t,n.tr,i),l=a.tr;if(l=l.setMeta(et,{type:"end"}),s&&a.newDoc){let c=l.doc;l=l.replace(0,l.doc.content.size,new R(i.originalDoc.content,0,0)),r(l);try{t.get(Q).call(Zd.key,c)}catch(u){console.warn("[milkdown/streaming] diff review handoff skipped:",u)}return!0}r(l)}return!0});Vi(us,{displayName:"Command<endStreaming>",group:"Streaming"});var ml=z("AbortStreaming",t=>e=>(n,r)=>{let i=et.getState(n);if(!i?.active)return!1;if(r){let o=e?.keep??!1,s=n.tr;o?s=tp(t,s,i).tr:s=s.replace(0,n.doc.content.size,new R(i.originalDoc.content,0,0)),s=s.setMeta(et,{type:"abort"}),r(s)}return!0});Vi(ml,{displayName:"Command<abortStreaming>",group:"Streaming"});var iw=[qn,rw,cs,hl,us,ml];var ow=new ee("weibeiStreamingAppearance"),WR={class:"wb-stream-in"},jR={side:1},VR=260,qR=400,KR=24;function UR(){let t=document.createElement("span");return t.className="wb-stream-caret",t}function sw(t){return new X({key:ow,state:{init:()=>({fades:[],caretPosition:null,caretExpiresAt:0,set:ae.empty}),apply(e,n){let r=Date.now(),i=[];for(let l of n.fades){let c=e.mapping.map(l.from),u=e.mapping.map(l.to);c>=u||r>=l.expiresAt||e.doc.resolve(c).parent===e.doc.resolve(u).parent&&i.push({from:c,to:u,expiresAt:l.expiresAt})}let o=n.caretPosition===null?null:e.mapping.map(n.caretPosition),s=n.caretExpiresAt;e.docChanged&&t()&&e.steps.forEach((l,c)=>{let u=e.mapping.slice(c+1);e.mapping.maps[c].forEach((f,d,p,h)=>{if(h<=p)return;let m=u.map(p),g=u.map(h);if(g-m>KR)return;let y=e.doc.resolve(m);y.parent===e.doc.resolve(g).parent&&y.parent.isTextblock&&(i.push({from:m,to:g,expiresAt:r+VR}),o=g,s=r+qR)})}),o!==null&&r>=s&&(o=null);let a=i.map(l=>le.inline(l.from,l.to,WR));return o!==null&&a.push(le.widget(o,UR,jR)),{fades:i,caretPosition:o,caretExpiresAt:s,set:ae.create(e.doc,a)}}},props:{decorations(e){let n=ow.getState(e);return!n||!t()?ae.empty:n.set}}})}var yl=Math.min,$r=Math.max,ds=Math.round;var Xt=t=>({x:t,y:t}),JR={left:"right",right:"left",bottom:"top",top:"bottom"};function kl(t,e){return typeof t=="function"?t(e):t}function _r(t){return t.split("-")[0]}function ps(t){return t.split("-")[1]}function cw(t){return t==="x"?"y":"x"}function np(t){return t==="y"?"height":"width"}function Kn(t){let e=t[0];return e==="t"||e==="b"?"y":"x"}function rp(t){return cw(Kn(t))}function uw(t,e,n){n===void 0&&(n=!1);let r=ps(t),i=rp(t),o=np(i),s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(s=fs(s)),[s,fs(s)]}function fw(t){let e=fs(t);return[gl(t),e,gl(e)]}function gl(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}var aw=["left","right"],lw=["right","left"],GR=["top","bottom"],XR=["bottom","top"];function YR(t,e,n){switch(t){case"top":case"bottom":return n?e?lw:aw:e?aw:lw;case"left":case"right":return e?GR:XR;default:return[]}}function dw(t,e,n,r){let i=ps(t),o=YR(_r(t),n==="start",r);return i&&(o=o.map(s=>s+"-"+i),e&&(o=o.concat(o.map(gl)))),o}function fs(t){let e=_r(t);return JR[e]+t.slice(e.length)}function QR(t){var e,n,r,i;return{top:(e=t.top)!=null?e:0,right:(n=t.right)!=null?n:0,bottom:(r=t.bottom)!=null?r:0,left:(i=t.left)!=null?i:0}}function pw(t){return typeof t!="number"?QR(t):{top:t,right:t,bottom:t,left:t}}function Hr(t){let{x:e,y:n,width:r,height:i}=t;return{width:r,height:i,top:n,left:e,right:e+r,bottom:n+i,x:e,y:n}}function hw(t,e,n){let{reference:r,floating:i}=t,o=Kn(e),s=rp(e),a=np(s),l=_r(e),c=o==="y",u=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,d=r[a]/2-i[a]/2,p;switch(l){case"top":p={x:u,y:r.y-i.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-i.width,y:f};break;default:p={x:r.x,y:r.y}}let h=ps(e);return h&&(p[s]+=d*(h==="end"?1:-1)*(n&&c?-1:1)),p}async function mw(t,e){var n;e===void 0&&(e={});let{x:r,y:i,platform:o,rects:s,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:p=0}=kl(e,t),h=pw(p),g=a[d?f==="floating"?"reference":"floating":f],y=Hr(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(g)))==null||n?g:g.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),x=f==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,C=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),v=await(o.isElement==null?void 0:o.isElement(C))&&await(o.getScale==null?void 0:o.getScale(C))||{x:1,y:1},A=Hr(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:x,offsetParent:C,strategy:l}):x);return{top:(y.top-A.top+h.top)/v.y,bottom:(A.bottom-y.bottom+h.bottom)/v.y,left:(y.left-A.left+h.left)/v.x,right:(A.right-y.right+h.right)/v.x}}var ZR=50,gw=async(t,e,n)=>{let{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:s}=n,a=s.detectOverflow?s:{...s,detectOverflow:mw},l=await(s.isRTL==null?void 0:s.isRTL(e)),c=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:f}=hw(c,r,l),d=r,p=0,h={};for(let m=0;m<o.length;m++){let g=o[m];if(!g)continue;let{name:y,fn:x}=g,{x:C,y:v,data:A,reset:w}=await x({x:u,y:f,initialPlacement:r,placement:d,strategy:i,middlewareData:h,rects:c,platform:a,elements:{reference:t,floating:e}});u=C??u,f=v??f,h[y]={...h[y],...A},w&&p<ZR&&(p++,typeof w=="object"&&(w.placement&&(d=w.placement),w.rects&&(c=w.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):w.rects),{x:u,y:f}=hw(c,d,l)),m=-1)}return{x:u,y:f,placement:d,strategy:i,middlewareData:h}};var yw=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;let{placement:i,middlewareData:o,rects:s,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:h="none",flipAlignment:m=!0,...g}=kl(t,e);if((n=o.arrow)!=null&&n.alignmentOffset)return{};let y=_r(i),x=Kn(a),C=_r(a)===a,v=await(l.isRTL==null?void 0:l.isRTL(c.floating)),A=d||(C||!m?[fs(a)]:fw(a)),w=h!=="none";!d&&w&&A.push(...dw(a,m,h,v));let N=[a,...A],B=await l.detectOverflow(e,g),O=[],S=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&O.push(B[y]),f){let W=uw(i,s,v);O.push(B[W[0]],B[W[1]])}if(S=[...S,{placement:i,overflows:O}],!O.every(W=>W<=0)){var me,te;let W=(((me=o.flip)==null?void 0:me.index)||0)+1,V=N[W];if(V&&(!(f==="alignment"?x!==Kn(V):!1)||S.every(ye=>Kn(ye.placement)===x?ye.overflows[0]>0:!0)))return{data:{index:W,overflows:S},reset:{placement:V}};let se=(te=S.filter(fe=>fe.overflows[0]<=0).sort((fe,ye)=>fe.overflows[1]-ye.overflows[1])[0])==null?void 0:te.placement;if(!se)switch(p){case"bestFit":{var F;let fe=(F=S.filter(ye=>{if(w){let Me=Kn(ye.placement);return Me===x||Me==="y"}return!0}).map(ye=>[ye.placement,ye.overflows.filter(Me=>Me>0).reduce((Me,k)=>Me+k,0)]).sort((ye,Me)=>ye[1]-Me[1])[0])==null?void 0:F[0];fe&&(se=fe);break}case"initialPlacement":se=a;break}if(i!==se)return{reset:{placement:se}}}return{}}}};var eO=new Set(["left","top"]);async function tO(t,e){let{placement:n,platform:r,elements:i}=t,o=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=_r(n),a=ps(n),l=Kn(n)==="y",c=eO.has(s)?-1:1,u=o&&l?-1:1,f=kl(e,t),{mainAxis:d,crossAxis:p,alignmentAxis:h}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof h=="number"&&(p=a==="end"?h*-1:h),l?{x:p*u,y:d*c}:{x:d*c,y:p*u}}var kw=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;let{x:i,y:o,placement:s,middlewareData:a}=e,l=await tO(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:i+l.x,y:o+l.y,data:{...l,placement:s}}}}};function xl(){return typeof window<"u"}function jr(t){return xw(t)?(t.nodeName||"").toLowerCase():"#document"}function it(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function xn(t){var e;return(e=(xw(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function xw(t){return xl()?t instanceof Node||t instanceof it(t).Node:!1}function Pt(t){return xl()?t instanceof Element||t instanceof it(t).Element:!1}function wn(t){return xl()?t instanceof HTMLElement||t instanceof it(t).HTMLElement:!1}function bw(t){return!xl()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof it(t).ShadowRoot}function hs(t){let{overflow:e,overflowX:n,overflowY:r,display:i}=Ft(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&i!=="inline"&&i!=="contents"}function ww(t){return/^(table|td|th)$/.test(jr(t))}function ms(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}var nO=/transform|translate|scale|rotate|perspective|filter/,rO=/paint|layout|strict|content/,Wr=t=>!!t&&t!=="none",ip;function wl(t){let e=Pt(t)?Ft(t):t;return Wr(e.transform)||Wr(e.translate)||Wr(e.scale)||Wr(e.rotate)||Wr(e.perspective)||!Cl()&&(Wr(e.backdropFilter)||Wr(e.filter))||nO.test(e.willChange||"")||rO.test(e.contain||"")}function Cw(t){let e=Un(t);for(;wn(e)&&!qi(e);){if(wl(e))return e;if(ms(e))return null;e=Un(e)}return null}function Cl(){return ip==null&&(ip=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),ip}function qi(t){return/^(html|body|#document)$/.test(jr(t))}function Ft(t){return it(t).getComputedStyle(t)}function gs(t){return Pt(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Un(t){if(jr(t)==="html")return t;let e=t.assignedSlot||t.parentNode||bw(t)&&t.host||xn(t);return bw(e)?e.host:e}function Sw(t){let e=Un(t);return qi(e)?(t.ownerDocument||t).body:wn(e)&&hs(e)?e:Sw(e)}function bl(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=Sw(t),o=i===((r=t.ownerDocument)==null?void 0:r.body),s=it(i);if(o){let a=Sl(s);return e.concat(s,s.visualViewport||[],hs(i)?i:[],a&&n?bl(a):[])}else return e.concat(i,bl(i,[],n))}function Sl(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Tw(t){let e=Ft(t),n=parseFloat(e.width)||0,r=parseFloat(e.height)||0,i=wn(t),o=i?t.offsetWidth:n,s=i?t.offsetHeight:r,a=ds(n)!==o||ds(r)!==s;return a&&(n=o,r=s),{width:n,height:r,$:a}}function vw(t){return Pt(t)?t:t.contextElement}function Ki(t){let e=vw(t);if(!wn(e))return Xt(1);let n=e.getBoundingClientRect(),{width:r,height:i,$:o}=Tw(e),s=(o?ds(n.width):n.width)/r,a=(o?ds(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var iO=Xt(0);function Aw(t){let e=it(t);return!Cl()||!e.visualViewport?iO:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function oO(t,e,n){return e===void 0&&(e=!1),!!n&&e&&n===it(t)}function ys(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),o=vw(t),s=Xt(1);e&&(r?Pt(r)&&(s=Ki(r)):s=Ki(t));let a=oO(o,n,r)?Aw(o):Xt(0),l=(i.left+a.x)/s.x,c=(i.top+a.y)/s.y,u=i.width/s.x,f=i.height/s.y;if(o&&r){let d=it(o),p=Pt(r)?it(r):r,h=d,m=Sl(h);for(;m&&p!==h;){let g=Ki(m),y=m.getBoundingClientRect(),x=Ft(m),C=y.left+(m.clientLeft+parseFloat(x.paddingLeft))*g.x,v=y.top+(m.clientTop+parseFloat(x.paddingTop))*g.y;l*=g.x,c*=g.y,u*=g.x,f*=g.y,l+=C,c+=v,h=it(m),m=Sl(h)}}return Hr({width:u,height:f,x:l,y:c})}function Ml(t,e){let n=gs(t).scrollLeft;return e?e.left+n:ys(xn(t)).left+n}function Iw(t,e){let n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-Ml(t,n),i=n.top+e.scrollTop;return{x:r,y:i}}function sO(t){let{elements:e,rect:n,offsetParent:r,strategy:i}=t,o=i==="fixed",s=xn(r),a=e?ms(e.floating):!1;if(r===s||a&&o)return n;let l={scrollLeft:0,scrollTop:0},c=Xt(1),u=Xt(0),f=wn(r);if((f||!o)&&((jr(r)!=="body"||hs(s))&&(l=gs(r)),f)){let p=ys(r);c=Ki(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}let d=s&&!f&&!o?Iw(s,l):Xt(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+d.x,y:n.y*c.y-l.scrollTop*c.y+u.y+d.y}}function aO(t){return t.getClientRects?Array.from(t.getClientRects()):[]}function lO(t){let e=gs(t),n=t.ownerDocument.body,r=$r(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),i=$r(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight),o=-e.scrollLeft+Ml(t),s=-e.scrollTop;return Ft(n).direction==="rtl"&&(o+=$r(t.clientWidth,n.clientWidth)-r),{width:r,height:i,x:o,y:s}}var cO=25;function uO(t,e,n){n===void 0&&(n="viewport");let r=n==="layoutViewport",i=it(t),o=xn(t),s=i.visualViewport,a=o.clientWidth,l=o.clientHeight,c=0,u=0;if(s){let d=!Cl()||e==="fixed";r?d||(c=-s.offsetLeft,u=-s.offsetTop):(a=s.width,l=s.height,d&&(c=s.offsetLeft,u=s.offsetTop))}if(Ml(o)<=0){let d=o.ownerDocument,p=d.body,h=getComputedStyle(p),m=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,g=Math.abs(o.clientWidth-p.clientWidth-m),y=getComputedStyle(o).scrollbarGutter==="stable both-edges"?g/2:g;y<=cO&&(a-=y)}return{width:a,height:l,x:c,y:u}}function fO(t,e){let n=ys(t,!0,e==="fixed"),r=n.top+t.clientTop,i=n.left+t.clientLeft,o=Ki(t),s=t.clientWidth*o.x,a=t.clientHeight*o.y,l=i*o.x,c=r*o.y;return{width:s,height:a,x:l,y:c}}function Mw(t,e,n){let r;if(e==="viewport"||e==="layoutViewport")r=uO(t,n,e);else if(e==="document")r=lO(xn(t));else if(Pt(e))r=fO(e,n);else{let i=Aw(t);r={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return Hr(r)}function dO(t,e){let n=e.get(t);if(n)return n;let r=bl(t,[],!1).filter(a=>Pt(a)&&jr(a)!=="body"),i=null,o=Ft(t).position==="fixed",s=o?Un(t):t;for(;Pt(s)&&!qi(s);){let a=Ft(s),l=wl(s),c=i?i.position:o?"fixed":"";!l&&(c==="fixed"||c==="absolute"&&a.position==="static")?r=r.filter(f=>f!==s):i=a,s=Un(s)}return e.set(t,r),r}function pO(t){let{element:e,boundary:n,rootBoundary:r,strategy:i}=t,s=[...n==="clippingAncestors"?ms(e)?[]:dO(e,this._c):[].concat(n),r],a=Mw(e,s[0],i),l=a.top,c=a.right,u=a.bottom,f=a.left;for(let d=1;d<s.length;d++){let p=Mw(e,s[d],i);l=$r(p.top,l),c=yl(p.right,c),u=yl(p.bottom,u),f=$r(p.left,f)}return{width:c-f,height:u-l,x:f,y:l}}function hO(t){let{width:e,height:n}=Tw(t);return{width:e,height:n}}function mO(t,e,n){let r=wn(e),i=xn(e),o=n==="fixed",s=ys(t,!0,o,e),a={scrollLeft:0,scrollTop:0},l=Xt(0);if((r||!o)&&((jr(e)!=="body"||hs(i))&&(a=gs(e)),r)){let d=ys(e,!0,o,e);l.x=d.x+e.clientLeft,l.y=d.y+e.clientTop}!r&&i&&(l.x=Ml(i));let c=i&&!r&&!o?Iw(i,a):Xt(0),u=s.left+a.scrollLeft-l.x-c.x,f=s.top+a.scrollTop-l.y-c.y;return{x:u,y:f,width:s.width,height:s.height}}function op(t){return Ft(t).position==="static"}function Ew(t,e){if(!wn(t)||Ft(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return xn(t)===n&&(n=n.ownerDocument.body),n}function Nw(t,e){let n=it(t);if(ms(t))return n;if(!wn(t)){let i=Un(t);for(;i&&!qi(i);){if(Pt(i)&&!op(i))return i;i=Un(i)}return n}let r=Ew(t,e);for(;r&&ww(r)&&op(r);)r=Ew(r,e);return r&&qi(r)&&op(r)&&!wl(r)?n:r||Cw(t)||n}var gO=async function(t){let e=this.getOffsetParent||Nw,n=this.getDimensions,r=await n(t.floating);return{reference:mO(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function yO(t){return Ft(t).direction==="rtl"}var kO={convertOffsetParentRelativeRectToViewportRelativeRect:sO,getDocumentElement:xn,getClippingRect:pO,getOffsetParent:Nw,getElementRects:gO,getClientRects:aO,getDimensions:hO,getScale:Ki,isElement:Pt,isRTL:yO};var Rw=kw;var Ow=yw;var Dw=(t,e,n)=>{let r=new Map,i=n??{},o={...kO,...i.platform,_c:r};return gw(t,e,{...i,platform:o})};function Lw(t){let e=ve({},`${t}_SLASH_SPEC`),n=pe(i=>{let o=i.get(e.key);return new X({key:new ee(`${t}_SLASH`),...o})}),r=[e,n];return r.key=e.key,r.pluginKey=n.key,e.meta={package:"@milkdown/plugin-slash",displayName:`Ctx<slashSpec>|${t}`},n.meta={package:"@milkdown/plugin-slash",displayName:`Prose<slash>|${t}`},r}var Bw=class{#t;#e;#r;#n;#s;#o;#i;#a;#l;constructor(t){this.#t=!1,this.onShow=()=>{},this.onHide=()=>{},this.#d=(e,n)=>{let{state:r,composing:i}=e,{selection:o,doc:s}=r,{ranges:a}=o,l=Math.min(...a.map(f=>f.$from.pos)),c=Math.max(...a.map(f=>f.$to.pos)),u=n&&n.doc.eq(s)&&n.selection.eq(o);if(this.#t||((this.#n??e.dom.parentElement??document.body).appendChild(this.element),this.#t=!0),!(i||u)){if(!this.#i(e,n)){this.hide();return}Dw({getBoundingClientRect:()=>Hg(e,l,c)},this.element,{placement:"bottom-start",middleware:[Ow(),Rw(this.#l),...this.#e],...this.#r}).then(({x:f,y:d})=>{Object.assign(this.element.style,{left:`${f}px`,top:`${d}px`})}).catch(console.error),this.show()}},this.#c=e=>{let n=this.getContent(e);if(!n)return!1;let r=n.at(-1);return r?Array.isArray(this.#o)?this.#o.includes(r):this.#o===r:!1},this.update=(e,n)=>{this.#a(e,n)},this.getContent=(e,n=r=>r.type.name==="paragraph")=>{let{selection:r}=e.state,{empty:i,$from:o}=r,s=e.state.selection instanceof P;if(typeof document>"u")return;let a=this.element.contains(document.activeElement),l=!e.hasFocus()&&!a,c=!e.editable,u=!Vg(n)(e.state.selection);if(!(l||c||!i||!s||u))return o.parent.textBetween(Math.max(0,o.parentOffset-500),o.parentOffset,void 0,"\uFFFC")},this.destroy=()=>{this.#a.cancel()},this.show=()=>{this.element.dataset.show="true",this.onShow()},this.hide=()=>{this.element.dataset.show="false",this.onHide()},this.element=t.content,this.#s=t.debounce??200,this.#i=t.shouldShow??this.#c,this.#o=t.trigger??"/",this.#l=t.offset,this.#e=t.middleware??[],this.#r=t.floatingUIOptions??{},this.#n=t.root,this.#a=rs(this.#d,this.#s)}#d;#c};function sp(t){return new Promise(e=>{let n=new FileReader;n.addEventListener("load",()=>{e({alt:t.name,src:n.result})},!1),n.readAsDataURL(t)})}var bO=async(t,e)=>{let n=[];for(let i=0;i<t.length;i++){let o=t.item(i);o&&o.type.includes("image")&&n.push(o)}let{image:r}=e.nodes;if(!r)throw Rs("image");return(await Promise.all(n.map(i=>sp(i)))).map(({alt:i,src:o})=>r.createAndFill({src:o,alt:i}))},Vr=ve({uploader:bO,enableHtmlFileUploader:!1,uploadWidgetFactory:(t,e)=>{let n=document.createElement("span");return n.textContent="Upload in progress...",le.widget(t,n,e)}},"uploadConfig");Vr.meta={package:"@milkdown/plugin-upload",displayName:"Ctx<uploadConfig>"};var Pw=pe(t=>{let e=new ee("MILKDOWN_UPLOAD"),n=(i,o)=>{let s=e.getState(i);if(!s)return-1;let a=s.find(void 0,void 0,l=>l.id===o);return a.length?a[0]?.from??-1:-1},r=(i,o,s)=>{if(!s||s.length<=0)return!1;let a=Symbol("upload symbol"),l=t.get($e),{uploader:c,getInsertPos:u}=t.get(Vr.key),{tr:f}=i.state,d=o instanceof DragEvent?i.posAtCoords({left:o.clientX,top:o.clientY})?.pos??f.selection.from:f.selection.from,p=typeof u=="function"?u(o,t,d):d;return i.dispatch(f.setMeta(e,{add:{id:a,pos:p}})),c(s,l,t,p).then(h=>{let m=n(i.state,a);m<0||i.dispatch(i.state.tr.replaceWith(m,m,h).setMeta(e,{remove:{id:a}}))}).catch(h=>{console.error(h)}),!0};return new X({key:e,state:{init(){return ae.empty},apply(i,o){let s=o.map(i.mapping,i.doc),a=i.getMeta(this);if(!a)return s;if(a.add){let{uploadWidgetFactory:l}=t.get(Vr.key),c=l(a.add.pos,{id:a.add.id});return s.add(i.doc,[c])}if(a.remove){let l=s.find(void 0,void 0,c=>c.id===a.remove.id);return s.remove(l)}return s}},props:{decorations(i){return this.getState(i)},handlePaste:(i,o)=>{let{enableHtmlFileUploader:s}=t.get(Vr.key);return!(o instanceof ClipboardEvent)||!s&&o.clipboardData?.getData("text/html")?!1:r(i,o,o.clipboardData?.files)},handleDrop:(i,o)=>o instanceof DragEvent?r(i,o,o.dataTransfer?.files):!1}})});Pw.meta={package:"@milkdown/plugin-upload",displayName:"Prose<upload>"};var Fw=[Vr,Pw];function ap(){return{enter:{mathFlow:t,mathFlowFenceMeta:e,mathText:o},exit:{mathFlow:i,mathFlowFence:r,mathFlowFenceMeta:n,mathFlowValue:a,mathText:s,mathTextData:a}};function t(l){let c={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[c]}},l)}function e(){this.buffer()}function n(){let l=this.resume(),c=this.stack[this.stack.length-1];c.type,c.meta=l}function r(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function i(l){let c=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c;let f=u.data.hChildren[0];f.type,f.tagName,f.children.push({type:"text",value:c}),this.data.mathFlowInside=void 0}function o(l){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},l),this.buffer()}function s(l){let c=this.resume(),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c,u.data.hChildren.push({type:"text",value:c})}function a(l){this.config.enter.data.call(this,l),this.config.exit.data.call(this,l)}}function lp(t){let e=(t||{}).singleDollarTextMath;return e==null&&(e=!0),r.peek=i,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:` +`);let i=e.topNodeType.createAndFill(void 0,n.content);return i?r(i):""}}})});sR(Xd,{displayName:"Prose<clipboard>"});function aR(t){let e=t.schema.cached.changeSetIDs||(t.schema.cached.changeSetIDs=Object.create(null)),n=e[t.name];return n==null&&(e[t.name]=n=Object.keys(t.schema.nodes).indexOf(t.name)+1),n}var Jx={encodeCharacter:t=>t,encodeNodeStart:t=>t.type.name,encodeNodeEnd:t=>-aR(t.type),compareTokens:(t,e)=>t===e};function Yd(t,e,n,r,i){for(let o=0,s=0;o<t.childCount;o++){let a=t.child(o),l=s+a.nodeSize,c=Math.max(s,n),u=Math.min(l,r);if(c<u)if(a.isText)for(let f=c;f<u;f++)i.push(e.encodeCharacter(a.text.charCodeAt(f-s),a.marks));else a.isLeaf?i.push(e.encodeNodeStart(a)):(c==s&&i.push(e.encodeNodeStart(a)),Yd(a.content,e,Math.max(s+1,c)-s-1,Math.min(l-1,u)-s-1,i),u==l&&i.push(e.encodeNodeEnd(a)));s=l}return i}var lR=5e3;function cR(t,e){return Math.min(15,Math.max(2,Math.floor(Math.max(t,e)/10)))}function Gx(t,e,n,r=Jx){let i=Yd(t,r,n.fromA,n.toA,[]),o=Yd(e,r,n.fromB,n.toB,[]),s=0,a=i.length,l=o.length,c=r.compareTokens;for(;s<i.length&&s<o.length&&c(i[s],o[s]);)s++;if(s==i.length&&s==o.length)return[];for(;a>s&&l>s&&c(i[a-1],o[l-1]);)a--,l--;if(a==s||l==s||a==l&&a==s+1)return[n.slice(s,a,s,l)];let u=a-s,f=l-s,d=Math.min(lR,u+f),p=d+1,h=[],m=[];for(let g=p*2,y=0;y<g;y++)m[y]=-1;for(let g=0;g<=d;g++){for(let y=-g;y<=g;y+=2){let x=m[y+1+d],C=m[y-1+d],v=x<C?C:x+1,A=v+y;for(;v<u&&A<f&&c(i[s+v],o[s+A]);)v++,A++;if(m[y+d]=v,v>=u&&A>=f){let w=[],N=cR(a-s,l-s),B=-1,O=-1,S=-1,me=-1,te=(F,W,V,ae)=>{B>-1&&B<W+N?(B=F,S=V):(B>-1&&w.push(n.slice(B,O,S,me)),B=F,O=W,S=V,me=ae)};for(let F=g-1;F>=0;F--){let W=m[y+1+d],V=m[y-1+d];W<V?(y--,v=V+s,A=v+y,te(v,v,A,A+1)):(y++,v=W+s,A=v+y,te(v,v+1,A,A)),m=h[F>>1]}return B>-1&&w.push(n.slice(B,O,S,me)),w.reverse()}}g%2==0&&h.push(m.slice())}return[n.slice(s,a,s,l)]}var Ce=class t{constructor(e,n){this.length=e,this.data=n}cut(e){return e==this.length?this:new t(e,this.data)}static slice(e,n,r){if(n==r)return t.none;if(n==0&&r==t.len(e))return e;let i=[];for(let o=0,s=0;s<r;o++){let a=e[o],l=s+a.length,c=Math.min(r,l)-Math.max(n,s);c>0&&i.push(a.cut(c)),s=l}return i}static join(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=r(e[e.length-1].data,n[0].data);if(i==null)return e.concat(n);let o=e.slice(0,e.length-1);o.push(new t(e[e.length-1].length+n[0].length,i));for(let s=1;s<n.length;s++)o.push(n[s]);return o}static len(e){let n=0;for(let r=0;r<e.length;r++)n+=e[r].length;return n}};Ce.none=[];var Jt=class t{constructor(e,n,r,i,o,s){this.fromA=e,this.toA=n,this.fromB=r,this.toB=i,this.deleted=o,this.inserted=s}get lenA(){return this.toA-this.fromA}get lenB(){return this.toB-this.fromB}slice(e,n,r,i){return e==0&&r==0&&n==this.toA-this.fromA&&i==this.toB-this.fromB?this:new t(this.fromA+e,this.fromA+n,this.fromB+r,this.fromB+i,Ce.slice(this.deleted,e,n),Ce.slice(this.inserted,r,i))}static merge(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=[];for(let o=0,s=0,a=e[0],l=n[0];;){if(!a&&!l)return i;if(a&&(!l||a.toB<l.fromA)){let c=s?n[s-1].toB-n[s-1].toA:0;i.push(c==0?a:new t(a.fromA,a.toA,a.fromB+c,a.toB+c,a.deleted,a.inserted)),a=o++==e.length?null:e[o]}else if(l&&(!a||l.toA<a.fromB)){let c=o?e[o-1].toB-e[o-1].toA:0;i.push(c==0?l:new t(l.fromA-c,l.toA-c,l.fromB,l.toB,l.deleted,l.inserted)),l=s++==n.length?null:n[s]}else{let c=Math.min(a.fromB,l.fromA),u=Math.min(a.fromA,l.fromA-(o?e[o-1].toB-e[o-1].toA:0)),f=u,d=Math.min(l.fromB,a.fromB+(s?n[s-1].toB-n[s-1].toA:0)),p=d,h=Ce.none,m=Ce.none,g=!1,y=!1;for(;;){let x=a?c>=a.fromB?a.toB:a.fromB:2e8,C=l?c>=l.fromA?l.toA:l.fromA:2e8,v=Math.min(x,C),A=a&&c>=a.fromB,w=l&&c>=l.fromA;if(!A&&!w)break;A&&c==a.fromB&&!g&&(h=Ce.join(h,a.deleted,r),f+=a.lenA,g=!0),A&&!w&&(m=Ce.join(m,Ce.slice(a.inserted,c-a.fromB,v-a.fromB),r),p+=v-c),w&&c==l.fromA&&!y&&(m=Ce.join(m,l.inserted,r),p+=l.lenB,y=!0),w&&!A&&(h=Ce.join(h,Ce.slice(l.deleted,c-l.fromA,v-l.fromA),r),f+=v-c),A&&v==a.toB&&(a=o++==e.length?null:e[o],g=!1),w&&v==l.toA&&(l=s++==n.length?null:n[s],y=!1),c=v}(u<f||d<p)&&i.push(new t(u,f,d,p,h,m))}}}static fromJSON(e){return new t(e.fromA,e.toA,e.fromB,e.toB,e.deleted.map(n=>new Ce(n.length,n.data)),e.inserted.map(n=>new Ce(n.length,n.data)))}toJSON(){return this}},uR;try{uR=new RegExp("[\\p{Alphabetic}_]","u")}catch{}var ji=class t{constructor(e,n){this.config=e,this.changes=n}addSteps(e,n,r){let i=[];for(let l=0;l<n.length;l++){let c=Array.isArray(r)?r[l]:r,u=0;n[l].forEach((f,d,p,h)=>{i.push(new Jt(f+u,d+u,p,h,f==d?Ce.none:[new Ce(d-f,c)],p==h?Ce.none:[new Ce(h-p,c)])),u=h-p-(d-f)})}if(i.length==0)return this;let o=Qd(i,this.config.combine),s=Jt.merge(this.changes,o,this.config.combine),a=s;for(let l=0;l<a.length;l++){let c=a[l];if(c.fromA==c.toA||c.fromB==c.toB||!o.some(f=>f.toB>c.fromB&&f.fromB<c.toB))continue;let u=Gx(this.config.doc.content,e.content,c,this.config.encoder);u.length==1&&u[0].fromB==0&&u[0].toB==c.toB-c.fromB||(a==s&&(a=s.slice()),u.length==1?a[l]=u[0]:(a.splice(l,1,...u),l+=u.length-1))}return new t(this.config,a)}get startDoc(){return this.config.doc}map(e){let n=r=>{let i=e(r);return i===r.data?r:new Ce(r.length,i)};return new t(this.config,this.changes.map(r=>new Jt(r.fromA,r.toA,r.fromB,r.toB,r.deleted.map(n),r.inserted.map(n))))}changedRange(e,n){if(e==this)return null;let r=n&&fR(n),i=r?r.toB-r.fromB-(r.toA-r.fromA):0;function o(f){return!r||f<=r.fromA?f:f+i}let s=r?r.fromB:2e8,a=r?r.toB:-2e8;function l(f,d=f){s=Math.min(f,s),a=Math.max(d,a)}let c=this.changes,u=e.changes;for(let f=0,d=0;f<c.length&&d<u.length;){let p=c[f],h=u[d];p&&h&&dR(p,h,o)?(f++,d++):h&&(!p||o(p.fromB)>=h.fromB)?(l(h.fromB,h.toB),d++):(l(o(p.fromB),o(p.toB)),f++)}return s<=a?{from:s,to:a}:null}static create(e,n=(o,s)=>o===s?o:null,r=Jx,i=[]){return new t({combine:n,doc:e,encoder:r},i)}};ji.computeDiff=Gx;function Qd(t,e,n=0,r=t.length){if(r==n+1)return[t[n]];let i=n+r>>1;return Jt.merge(Qd(t,e,n,i),Qd(t,e,i,r),e)}function Kx(t){let e=2e8,n=-2e8;for(let r=0;r<t.length;r++){let i=t[r];e!=2e8&&(e=i.map(e,-1),n=i.map(n,1)),i.forEach((o,s,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==2e8?null:{from:e,to:n}}function fR(t){let e=Kx(t);if(!e)return null;let n=Kx(t.map(r=>r.invert()).reverse());return{fromA:n.from,toA:n.to,fromB:e.from,toB:e.to}}function dR(t,e,n){return n(t.fromB)==e.fromB&&n(t.toB)==e.toB&&Ux(t.deleted,e.deleted)&&Ux(t.inserted,e.inserted)}function Ux(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n].length!=e[n].length||t[n].data!==e[n].data)return!1;return!0}function Gt(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-diff",...e}}),t}var Xx=500;function pR(t={}){let e=new WeakMap,n=new WeakMap;function r(i){let o=e.get(i);if(o!=null)return o;let s=i.attrs,a=s?Object.keys(s).filter(l=>s[l]!=null).sort():[];if(a.length===0)o=i.type.name;else{let l={};for(let c of a)l[c]=s[c];o=`${i.type.name}:${JSON.stringify(l)}`}return e.set(i,o),o}return{encodeCharacter:(i,o)=>{if(o.length===0)return i;let s=n.get(o);return s==null&&(s=o.map(r).join(","),n.set(o,s)),`${i}:${s}`},encodeNodeStart:i=>{let o=i.attrs;if(o&&Object.keys(o).length>0){let s=t[i.type.name]??[],a=Object.keys(o).filter(l=>{if(s.includes(l))return!1;let c=i.type.spec.attrs?.[l]?.default;return o[l]!==c});if(a.length>0){let l={};for(let c of a.sort())l[c]=o[c];return`${i.type.name}:${JSON.stringify(l)}`}}return i.type.name},encodeNodeEnd:i=>{let o=i.type.schema,s=o.cached.changeSetIDs||(o.cached.changeSetIDs=Object.create(null)),a=s[i.type.name];return a==null&&(s[i.type.name]=a=Object.keys(o.nodes).indexOf(i.type.name)+1),-a},compareTokens:(i,o)=>i===o}}function ew(t,e,n){let r=n.get(t);if(r!=null)return r;let i=[String(e.encodeNodeStart(t))];if(t.isText){let s=t.text;for(let a=0;a<s.length;a++)i.push(":"+String(e.encodeCharacter(s.charCodeAt(a),t.marks)))}else t.content.forEach(s=>{i.push("/"+ew(s,e,n))});i.push("\\"+String(e.encodeNodeEnd(t)));let o=i.join("");return n.set(t,o),o}function Yx(t,e,n){let r=[],i=0;return t.content.forEach(o=>{r.push({node:o,offset:i,size:o.nodeSize,signature:ew(o,n.encoder,n.sigCache)}),i+=o.nodeSize}),{node:t,contentStart:e,content:r}}function hR(t,e){let n=t.length,r=e.length,i=Array.from({length:n+1},()=>Array.from({length:r+1},()=>0));for(let l=n-1;l>=0;l--)for(let c=r-1;c>=0;c--)t[l].signature===e[c].signature?i[l][c]=i[l+1][c+1]+1:i[l][c]=Math.max(i[l+1][c],i[l][c+1]);let o=[],s=0,a=0;for(;s<n&&a<r;)t[s].signature===e[a].signature?(o.push([s,a]),s++,a++):i[s+1][a]>=i[s][a+1]?s++:a++;return o}function mR(t,e){if(t.type!==e.type)return!1;let n=t.type;return!(n.isTextblock||n.isAtom||n.spec.code===!0||!n.isBlock)}function tw(t,e,n){return Jt.fromJSON({fromA:t.fromA+e,toA:t.toA+e,fromB:t.fromB+n,toB:t.toB+n,deleted:t.deleted.map(r=>({length:r.length,data:r.data})),inserted:t.inserted.map(r=>({length:r.length,data:r.data}))})}function gR(t,e,n){let r=t.parent.copy(M.from(t.node)),i=e.parent.copy(M.from(e.node)),o=new xe(0,r.content.size,new R(i.content,0,0));return ji.create(r,void 0,n.encoder).addSteps(i,[o.getMap()],null).changes.map(s=>tw(s,t.abs,e.abs))}function Qx(t,e){let n=t.content;if(e<n.length)return t.contentStart+n[e].offset;if(e>0){let r=n[e-1];return t.contentStart+r.offset+r.size}return t.contentStart+t.node.content.size}function yR(t,e,n){return Jt.fromJSON({fromA:e,toA:e+t.size,fromB:n,toB:n,deleted:[{length:t.size,data:null}],inserted:[]})}function kR(t,e,n){return Jt.fromJSON({fromA:e,toA:e,fromB:n,toB:n+t.size,deleted:[],inserted:[{length:t.size,data:null}]})}function bR(t,e,n,r,i){let o=new xe(0,t.content.size,new R(e.content,0,0));return ji.create(t,void 0,i.encoder).addSteps(e,[o.getMap()],null).changes.map(s=>tw(s,n,r))}function dl(t,e,n,r,i){if(t.childCount>Xx||e.childCount>Xx)return bR(t,e,n,r,i);let o=Yx(t,n,i),s=Yx(e,r,i),a=hR(o.content,s.content),l=[],c=0,u=0;for(let[f,d]of a)Zx(o,s,{oldStart:c,oldEnd:f,newStart:u,newEnd:d},i,l),c=f+1,u=d+1;return Zx(o,s,{oldStart:c,oldEnd:o.content.length,newStart:u,newEnd:s.content.length},i,l),l}function Zx(t,e,n,r,i){let o=t.content,s=e.content,a=n.oldStart,l=n.newStart;for(;a<n.oldEnd||l<n.newEnd;){let c=a<n.oldEnd?o[a]:null,u=l<n.newEnd?s[l]:null,f=c&&u&&c.node.type===u.node.type;if(c&&u&&f){i.push(...xR(t,e,c,u,r)),a++,l++;continue}if(c&&(!u||!f)){let d=t.contentStart+c.offset;i.push(yR(c,d,Qx(e,l))),a++;continue}if(u){let d=e.contentStart+u.offset;i.push(kR(u,Qx(t,a),d)),l++}}}function xR(t,e,n,r,i){let o=t.contentStart+n.offset,s=e.contentStart+r.offset;return mR(n.node,r.node)&&wR(n.node,r.node,i.encoder)?dl(n.node,r.node,o+1,s+1,i):gR({node:n.node,parent:t.node,abs:o},{node:r.node,parent:e.node,abs:s},i)}function wR(t,e,n){return n.encodeNodeStart(t)===n.encodeNodeStart(e)}function CR(t,e,n,r,i){let o=t.resolve(n),s=t.resolve(r),a=e.resolve(n),l=e.resolve(r),c=o.sharedDepth(r);if(a.sharedDepth(r)!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) resolves to different sharedDepth in old and new docs`);for(let m=0;m<=c;m++){if(i.encodeNodeStart(o.node(m))!==i.encodeNodeStart(a.node(m)))throw new RangeError(`computeDocDiff: ancestor at depth ${m} differs in type or non-ignored attrs along the path to the shared ancestor`);if(o.start(m)!==a.start(m))throw new RangeError(`computeDocDiff: ancestor at depth ${m} starts at different absolute positions in old and new docs (content before the range differs in size)`)}let u=o.node(c);if(u.isTextblock)throw new RangeError(`computeDocDiff: range [${n}, ${r}) lands inside a textblock; widen the range to a block boundary`);if(o.depth!==c||s.depth!==c||a.depth!==c||l.depth!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) endpoints must be aligned to child boundaries of the shared ancestor`);let f=a.node(c),d=o.start(c),p=n-d,h=r-d;return{oldCut:u.copy(u.content.cut(p,h)),newCut:f.copy(f.content.cut(p,h)),cutAbsStart:n}}function ls(t,e,n){let r=pR(n?.ignoreAttrs),i={encoder:r,sigCache:new WeakMap},o=t.content.size,s=e.content.size,a=n?.range;if(a==null)return dl(t,e,0,0,i);let l=Math.min(o,s),c=Math.max(0,Math.min(a.from??0,l)),u=Math.max(c,Math.min(a.to??l,l));if(c===u)return[];if(c===0&&u===l&&o===s)return dl(t,e,0,0,i);let f=CR(t,e,c,u,r);return dl(f.oldCut,f.newCut,f.cutAbsStart,f.cutAbsStart,i)}var nw=ve({ignoreAttrs:{heading:["id"]}},"diffConfig");Gt(nw,{displayName:"Ctx<diffConfig>",group:"Diff"});var Oe=new ee("MILKDOWN_DIFF");function SR(t,e,n){let r=ls(t,e.newDoc,n);return{...e,changes:r}}function MR(t,e){return e.some(n=>t.fromB<n.toB&&t.toB>n.fromB)}function pl(t){return t.changes.filter(e=>!MR(e,t.rejectedRanges))}var ER=pe(t=>{let e=t.get(nw.key);return new X({key:Oe,state:{init:()=>null,apply(n,r,i,o){let s=n.getMeta(Oe);if(!r){if(s?.type==="start"){let c=ls(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}return null}let a=r;if(n.docChanged&&a.active&&(a=SR(o.doc,a,{ignoreAttrs:e.ignoreAttrs})),!s)return a;let l;switch(s.type){case"start":{let c=ls(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}case"accept":case"acceptRange":l=a;break;case"reject":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.fromB,toB:s.toB}]};break;case"rejectRange":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.range.fromB,toB:s.range.toB}]};break;case"acceptAll":case"clear":return null;default:return a}return l.active&&pl(l).length===0?null:l}},filterTransaction(n,r){return!Oe.getState(r)?.active||n.getMeta(Oe)?!0:!n.docChanged}})});Gt(ER,{displayName:"Prose<diff>",group:"Diff"});function TR(t,e){let n=pl(e);for(let r=n.length-1;r>=0;r--){let i=n[r],o=e.newDoc.slice(i.fromB,i.toB);t=t.replace(i.fromA,i.toA,o)}return t}var vR=z("StartDiffReview",t=>e=>(n,r)=>{if(e==null)return!1;let i=t.get(_e)(e);return i?(r&&r(n.tr.setMeta(Oe,{type:"start",newDoc:i})),!0):!1});Gt(vR,{displayName:"Command<startDiffReview>",group:"Diff"});var Zd=z("StartDiffReviewFromDoc",()=>t=>(e,n)=>!t||t.type!==e.doc.type?!1:(n&&n(e.tr.setMeta(Oe,{type:"start",newDoc:t})),!0));Gt(Zd,{displayName:"Command<startDiffReviewFromDoc>",group:"Diff"});var AR=z("AcceptDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Oe.getState(e);if(!r)return!1;let i=pl(r)[t];if(!i)return!1;if(n){let o=r.newDoc.slice(i.fromB,i.toB),s=e.tr.replace(i.fromA,i.toA,o);s=s.setMeta(Oe,{type:"accept",changeIndex:t}),n(s)}return!0});Gt(AR,{displayName:"Command<acceptDiffChunk>",group:"Diff"});var IR=z("RejectDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Oe.getState(e);if(!r)return!1;let i=pl(r)[t];return i?(n&&n(e.tr.setMeta(Oe,{type:"reject",fromB:i.fromB,toB:i.toB})),!0):!1});Gt(IR,{displayName:"Command<rejectDiffChunk>",group:"Diff"});var NR=z("AcceptDiffRange",()=>t=>(e,n)=>{if(!t)return!1;let r=Oe.getState(e);if(!r)return!1;if(n){let i=r.newDoc.slice(t.fromB,t.toB),o=e.tr.replace(t.fromA,t.toA,i);o=o.setMeta(Oe,{type:"acceptRange",range:t}),n(o)}return!0});Gt(NR,{displayName:"Command<acceptDiffRange>",group:"Diff"});var RR=z("RejectDiffRange",()=>t=>(e,n)=>!t||!Oe.getState(e)?!1:(n&&n(e.tr.setMeta(Oe,{type:"rejectRange",range:t})),!0));Gt(RR,{displayName:"Command<rejectDiffRange>",group:"Diff"});var OR=z("AcceptAllDiffs",()=>()=>(t,e)=>{let n=Oe.getState(t);return n?(e&&e((n.rejectedRanges.length===0?t.tr.replaceWith(0,t.doc.content.size,n.newDoc.content):TR(t.tr,n)).setMeta(Oe,{type:"acceptAll"})),!0):!1});Gt(OR,{displayName:"Command<acceptAllDiffs>",group:"Diff"});var DR=z("ClearDiffReview",()=>()=>(t,e)=>Oe.getState(t)?(e&&e(t.tr.setMeta(Oe,{type:"clear"})),!0):!1);Gt(DR,{displayName:"Command<clearDiffReview>",group:"Diff"});function Vi(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-streaming",...e}}),t}var qn=ve({throttleMs:100,scrollFollow:!0,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}},"streamingConfig");Vi(qn,{displayName:"Ctx<streamingConfig>",group:"Streaming"});function LR(t,e,n){let r=t.get(_e)(n);if(!r)return{tr:e,newDoc:null};let i=t.get(qn.key).ignoreAttrs,o=ls(e.doc,r,i?{ignoreAttrs:i}:void 0);for(let s=o.length-1;s>=0;s--){let a=o[s],l=r.slice(a.fromB,a.toB);e=e.replace(a.fromA,a.toA,l)}return{tr:e,newDoc:r}}function BR(t){if(t.parent.type.spec.code)return{type:"plain-text",preserveNewlines:!0};for(let e=t.depth;e>0;e--)if(t.node(e).type.name==="table")return{type:"plain-text",preserveNewlines:!1};return t.depth>=1?{type:"split-block"}:{type:"block"}}function rw(t){if(t.childCount===0)return t;let e=t.lastChild;return e.type.name==="paragraph"&&e.content.size===0?t.cut(0,t.size-e.nodeSize):t}function PR(t,e,n){let{insertPos:r,currentEndPos:i}=n,o=n.buffer.replace(/\r\n?/g,` +`);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=e.doc.content.size,a=Math.max(0,Math.min(r,s)),l=Math.max(a,Math.min(i,s)),c=e.doc.resolve(a),u=(t.get(qn.key).insertStrategy??BR)(c),f={ctx:t,tr:e,buffer:o,from:a,to:l,resolved:c};switch(u.type){case"plain-text":return FR(f,u.preserveNewlines??!1);case"split-block":return $R(f);case"block":return _R(f)}}function FR({tr:t,buffer:e,from:n,to:r},i){let o=i?e:e.replace(/\n/g," "),s=t.doc.type.schema.text(o);return t=t.replaceWith(n,r,s),{tr:t,applied:!0,insertEndPos:n+o.length}}var zR=/[*_~`[\\<]/;function ep(t,e,n){if(!n)return M.empty;if(!zR.test(n))return M.from(e.text(n));let r=t.get(_e)(n)?.firstChild;if(r?.type.name!=="paragraph"||r.content.size===0)return M.from(e.text(n));let i=!1;if(r.content.forEach(l=>{(!l.isText||l.marks.length>0)&&(i=!0)}),!i)return M.from(e.text(n));let o=r.content,s=/^\s+/.exec(n)?.[0];s&&((o.firstChild?.isText?o.firstChild.text??"":"").startsWith(s)||(o=M.from(e.text(s)).append(o)));let a=/\s+$/.exec(n)?.[0];return a&&((o.lastChild?.isText?o.lastChild.text??"":"").endsWith(a)||(o=o.append(M.from(e.text(a))))),o}function $R({ctx:t,tr:e,buffer:n,from:r,to:i,resolved:o}){let s=e.doc.type.schema,a=n.indexOf(` +`);if(a<0){let A=ep(t,s,n);return e=e.replaceWith(r,i,A),{tr:e,applied:!0,insertEndPos:r+A.size}}let l=n.substring(0,a),c=n.substring(a+1),u=t.get(_e),f=c.trim()?u(c):null,d=f?rw(f.content):M.empty;if(d.childCount===0){let A=ep(t,s,n.replace(/\n/g," "));return e=e.replaceWith(r,i,A),{tr:e,applied:!0,insertEndPos:r+A.size}}let p=o.depth,h=ep(t,s,l);for(let A=p;A>0;A--)h=M.from(o.node(A).copy(h));let m=h.append(d),g=new R(m,p,0),y=e.doc.content.size,x=e.doc.resolve(Math.min(i,y)),C=i;p>0&&x.depth===p&&x.parentOffset===x.parent.content.size&&(C=x.after(p)),e=e.replace(r,C,g);let v=m.size-p;return{tr:e,applied:!0,insertEndPos:r+v}}function _R({ctx:t,tr:e,buffer:n,from:r,to:i}){let o=t.get(_e)(n);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=rw(o.content);return s.size===0?{tr:e,applied:!1,insertEndPos:i}:(e=e.replace(r,i,new R(s,0,0)),{tr:e,applied:!0,insertEndPos:r+s.size})}function tp(t,e,n){if(n.insertPos!=null){let r=n.insertPos,i=PR(t,e,{buffer:n.buffer,insertPos:r,currentEndPos:n.insertEndPos??r});return{tr:i.tr,newDoc:i.applied?i.tr.doc:null,insertEndPos:i.insertEndPos}}return LR(t,e,n.buffer)}var et=new ee("MILKDOWN_STREAMING");function HR(t,e){if(!t&&e?.type!=="start")return null;if(!e)return t;switch(e.type){case"start":return{buffer:"",originalDoc:e.originalDoc,active:!0,lastApplyTime:e.lastApplyTime,insertPos:e.insertPos??null,insertEndPos:e.insertEndPos??e.insertPos??null};case"push":return t?{...t,buffer:t.buffer+e.token}:null;case"apply":return t?{...t,lastApplyTime:e.lastApplyTime,insertEndPos:e.insertEndPos??t.insertEndPos}:null;case"end":case"abort":return null;default:return t}}var iw=pe(t=>{let e=t.get(qn.key);return new X({key:et,state:{init:()=>null,apply(n,r){return HR(r,n.getMeta(et))}},filterTransaction(n,r){return!et.getState(r)?.active||n.getMeta(et)?!0:!n.docChanged},view(){return WR(t,e)}})});Vi(iw,{displayName:"Prose<streaming>",group:"Streaming"});function WR(t,e){let n=null,r=-1,i=null;function o(){if(!i)return;let a=et.getState(i.state);if(!a?.active||a.buffer.length===r)return;r=a.buffer.length;let l=tp(t,i.state.tr,a);if(!l.newDoc)return;let c=l.tr;!c.docChanged&&l.insertEndPos==null||(c=c.setMeta(et,{type:"apply",lastApplyTime:Date.now(),insertEndPos:l.insertEndPos}),e.scrollFollow&&(c=c.scrollIntoView()),i.dispatch(c))}function s(){n!=null&&clearTimeout(n),n=setTimeout(o,e.throttleMs)}return{update(a){i=a;let l=et.getState(a.state);if(!l?.active){n!=null&&(clearTimeout(n),n=null),r=-1;return}l.buffer.length!==r&&(Date.now()-l.lastApplyTime>=e.throttleMs?o():s())},destroy(){n!=null&&(clearTimeout(n),n=null),i=null}}}var cs=z("StartStreaming",()=>t=>(e,n)=>{if(et.getState(e)?.active)return!1;if(n){let r,i;if(t?.insertAt!=null)if(t.insertAt==="selection"){if(r=e.selection.from,i=e.selection.to,e.selection.empty){let o=e.doc.resolve(r);o.parent.isTextblock&&!o.parent.type.spec.code&&o.parent.content.size===0&&o.depth===1&&(r=o.before(o.depth),i=o.after(o.depth))}}else{let o=t.insertAt==="cursor"?e.selection.head:t.insertAt;if(!Number.isFinite(o))return!1;r=Math.max(0,Math.min(Math.round(o),e.doc.content.size));let s=e.doc.resolve(r);s.parent.isTextblock&&!s.parent.type.spec.code&&s.parent.content.size===0&&s.depth===1&&(r=s.before(s.depth),i=s.after(s.depth))}n(e.tr.setMeta(et,{type:"start",originalDoc:e.doc,insertPos:r,insertEndPos:i,lastApplyTime:Date.now()}))}return!0});Vi(cs,{displayName:"Command<startStreaming>",group:"Streaming"});var hl=z("PushChunk",()=>t=>(e,n)=>t==null||!et.getState(e)?.active?!1:(n&&n(e.tr.setMeta(et,{type:"push",token:t})),!0));Vi(hl,{displayName:"Command<pushChunk>",group:"Streaming"});var us=z("EndStreaming",t=>e=>(n,r)=>{let i=et.getState(n);if(!i?.active)return!1;if(r){let o=t.get(qn.key),s=e?.diffReview??o.diffReviewOnEnd,a=tp(t,n.tr,i),l=a.tr;if(l=l.setMeta(et,{type:"end"}),s&&a.newDoc){let c=l.doc;l=l.replace(0,l.doc.content.size,new R(i.originalDoc.content,0,0)),r(l);try{t.get(Q).call(Zd.key,c)}catch(u){console.warn("[milkdown/streaming] diff review handoff skipped:",u)}return!0}r(l)}return!0});Vi(us,{displayName:"Command<endStreaming>",group:"Streaming"});var ml=z("AbortStreaming",t=>e=>(n,r)=>{let i=et.getState(n);if(!i?.active)return!1;if(r){let o=e?.keep??!1,s=n.tr;o?s=tp(t,s,i).tr:s=s.replace(0,n.doc.content.size,new R(i.originalDoc.content,0,0)),s=s.setMeta(et,{type:"abort"}),r(s)}return!0});Vi(ml,{displayName:"Command<abortStreaming>",group:"Streaming"});var ow=[qn,iw,cs,hl,us,ml];var sw=new ee("weibeiStreamingAppearance"),aw={class:"wb-stream-in"},jR={side:1},VR=260,qR=400,KR=24;function UR(){let t=document.createElement("span");return t.className="wb-stream-caret",t}function lw(t){return new X({key:sw,state:{init:()=>({fades:[],caretPosition:null,caretExpiresAt:0,set:oe.empty}),apply(e,n){let r=Date.now(),i=[];for(let l of n.fades){let c=e.mapping.map(l.from),u=e.mapping.map(l.to);c>=u||r>=l.expiresAt||e.doc.resolve(c).parent===e.doc.resolve(u).parent&&i.push({from:c,to:u,expiresAt:l.expiresAt})}let o=n.caretPosition===null?null:e.mapping.map(n.caretPosition),s=n.caretExpiresAt;e.docChanged&&t()&&e.steps.forEach((l,c)=>{let u=e.mapping.slice(c+1);e.mapping.maps[c].forEach((f,d,p,h)=>{if(h<=p)return;let m=u.map(p),g=u.map(h);if(g-m>KR)return;let y=e.doc.resolve(m);y.parent===e.doc.resolve(g).parent&&y.parent.isTextblock&&(i.push({from:m,to:g,expiresAt:r+VR}),o=g,s=r+qR)})}),o!==null&&r>=s&&(o=null);let a=i.map(l=>le.inline(l.from,l.to,aw));return o!==null&&a.push(le.widget(o,UR,jR)),{fades:i,caretPosition:o,caretExpiresAt:s,set:oe.create(e.doc,a)}}},props:{decorations(e){let n=sw.getState(e);if(!n)return oe.empty;if(!t()){let r=Date.now(),i=n.fades.filter(o=>r<o.expiresAt);return i.length===0?oe.empty:oe.create(e.doc,i.map(o=>le.inline(o.from,o.to,aw)))}return n.set}}})}var yl=Math.min,$r=Math.max,ds=Math.round;var Xt=t=>({x:t,y:t}),JR={left:"right",right:"left",bottom:"top",top:"bottom"};function kl(t,e){return typeof t=="function"?t(e):t}function _r(t){return t.split("-")[0]}function ps(t){return t.split("-")[1]}function fw(t){return t==="x"?"y":"x"}function np(t){return t==="y"?"height":"width"}function Kn(t){let e=t[0];return e==="t"||e==="b"?"y":"x"}function rp(t){return fw(Kn(t))}function dw(t,e,n){n===void 0&&(n=!1);let r=ps(t),i=rp(t),o=np(i),s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(s=fs(s)),[s,fs(s)]}function pw(t){let e=fs(t);return[gl(t),e,gl(e)]}function gl(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}var cw=["left","right"],uw=["right","left"],GR=["top","bottom"],XR=["bottom","top"];function YR(t,e,n){switch(t){case"top":case"bottom":return n?e?uw:cw:e?cw:uw;case"left":case"right":return e?GR:XR;default:return[]}}function hw(t,e,n,r){let i=ps(t),o=YR(_r(t),n==="start",r);return i&&(o=o.map(s=>s+"-"+i),e&&(o=o.concat(o.map(gl)))),o}function fs(t){let e=_r(t);return JR[e]+t.slice(e.length)}function QR(t){var e,n,r,i;return{top:(e=t.top)!=null?e:0,right:(n=t.right)!=null?n:0,bottom:(r=t.bottom)!=null?r:0,left:(i=t.left)!=null?i:0}}function mw(t){return typeof t!="number"?QR(t):{top:t,right:t,bottom:t,left:t}}function Hr(t){let{x:e,y:n,width:r,height:i}=t;return{width:r,height:i,top:n,left:e,right:e+r,bottom:n+i,x:e,y:n}}function gw(t,e,n){let{reference:r,floating:i}=t,o=Kn(e),s=rp(e),a=np(s),l=_r(e),c=o==="y",u=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,d=r[a]/2-i[a]/2,p;switch(l){case"top":p={x:u,y:r.y-i.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-i.width,y:f};break;default:p={x:r.x,y:r.y}}let h=ps(e);return h&&(p[s]+=d*(h==="end"?1:-1)*(n&&c?-1:1)),p}async function yw(t,e){var n;e===void 0&&(e={});let{x:r,y:i,platform:o,rects:s,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:p=0}=kl(e,t),h=mw(p),g=a[d?f==="floating"?"reference":"floating":f],y=Hr(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(g)))==null||n?g:g.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),x=f==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,C=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),v=await(o.isElement==null?void 0:o.isElement(C))&&await(o.getScale==null?void 0:o.getScale(C))||{x:1,y:1},A=Hr(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:x,offsetParent:C,strategy:l}):x);return{top:(y.top-A.top+h.top)/v.y,bottom:(A.bottom-y.bottom+h.bottom)/v.y,left:(y.left-A.left+h.left)/v.x,right:(A.right-y.right+h.right)/v.x}}var ZR=50,kw=async(t,e,n)=>{let{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:s}=n,a=s.detectOverflow?s:{...s,detectOverflow:yw},l=await(s.isRTL==null?void 0:s.isRTL(e)),c=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:f}=gw(c,r,l),d=r,p=0,h={};for(let m=0;m<o.length;m++){let g=o[m];if(!g)continue;let{name:y,fn:x}=g,{x:C,y:v,data:A,reset:w}=await x({x:u,y:f,initialPlacement:r,placement:d,strategy:i,middlewareData:h,rects:c,platform:a,elements:{reference:t,floating:e}});u=C??u,f=v??f,h[y]={...h[y],...A},w&&p<ZR&&(p++,typeof w=="object"&&(w.placement&&(d=w.placement),w.rects&&(c=w.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):w.rects),{x:u,y:f}=gw(c,d,l)),m=-1)}return{x:u,y:f,placement:d,strategy:i,middlewareData:h}};var bw=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;let{placement:i,middlewareData:o,rects:s,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:h="none",flipAlignment:m=!0,...g}=kl(t,e);if((n=o.arrow)!=null&&n.alignmentOffset)return{};let y=_r(i),x=Kn(a),C=_r(a)===a,v=await(l.isRTL==null?void 0:l.isRTL(c.floating)),A=d||(C||!m?[fs(a)]:pw(a)),w=h!=="none";!d&&w&&A.push(...hw(a,m,h,v));let N=[a,...A],B=await l.detectOverflow(e,g),O=[],S=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&O.push(B[y]),f){let W=dw(i,s,v);O.push(B[W[0]],B[W[1]])}if(S=[...S,{placement:i,overflows:O}],!O.every(W=>W<=0)){var me,te;let W=(((me=o.flip)==null?void 0:me.index)||0)+1,V=N[W];if(V&&(!(f==="alignment"?x!==Kn(V):!1)||S.every(ye=>Kn(ye.placement)===x?ye.overflows[0]>0:!0)))return{data:{index:W,overflows:S},reset:{placement:V}};let ae=(te=S.filter(fe=>fe.overflows[0]<=0).sort((fe,ye)=>fe.overflows[1]-ye.overflows[1])[0])==null?void 0:te.placement;if(!ae)switch(p){case"bestFit":{var F;let fe=(F=S.filter(ye=>{if(w){let Me=Kn(ye.placement);return Me===x||Me==="y"}return!0}).map(ye=>[ye.placement,ye.overflows.filter(Me=>Me>0).reduce((Me,k)=>Me+k,0)]).sort((ye,Me)=>ye[1]-Me[1])[0])==null?void 0:F[0];fe&&(ae=fe);break}case"initialPlacement":ae=a;break}if(i!==ae)return{reset:{placement:ae}}}return{}}}};var eO=new Set(["left","top"]);async function tO(t,e){let{placement:n,platform:r,elements:i}=t,o=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=_r(n),a=ps(n),l=Kn(n)==="y",c=eO.has(s)?-1:1,u=o&&l?-1:1,f=kl(e,t),{mainAxis:d,crossAxis:p,alignmentAxis:h}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof h=="number"&&(p=a==="end"?h*-1:h),l?{x:p*u,y:d*c}:{x:d*c,y:p*u}}var xw=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;let{x:i,y:o,placement:s,middlewareData:a}=e,l=await tO(e,t);return s===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:i+l.x,y:o+l.y,data:{...l,placement:s}}}}};function xl(){return typeof window<"u"}function jr(t){return Cw(t)?(t.nodeName||"").toLowerCase():"#document"}function it(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function xn(t){var e;return(e=(Cw(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Cw(t){return xl()?t instanceof Node||t instanceof it(t).Node:!1}function Pt(t){return xl()?t instanceof Element||t instanceof it(t).Element:!1}function wn(t){return xl()?t instanceof HTMLElement||t instanceof it(t).HTMLElement:!1}function ww(t){return!xl()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof it(t).ShadowRoot}function hs(t){let{overflow:e,overflowX:n,overflowY:r,display:i}=Ft(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&i!=="inline"&&i!=="contents"}function Sw(t){return/^(table|td|th)$/.test(jr(t))}function ms(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}var nO=/transform|translate|scale|rotate|perspective|filter/,rO=/paint|layout|strict|content/,Wr=t=>!!t&&t!=="none",ip;function wl(t){let e=Pt(t)?Ft(t):t;return Wr(e.transform)||Wr(e.translate)||Wr(e.scale)||Wr(e.rotate)||Wr(e.perspective)||!Cl()&&(Wr(e.backdropFilter)||Wr(e.filter))||nO.test(e.willChange||"")||rO.test(e.contain||"")}function Mw(t){let e=Un(t);for(;wn(e)&&!qi(e);){if(wl(e))return e;if(ms(e))return null;e=Un(e)}return null}function Cl(){return ip==null&&(ip=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),ip}function qi(t){return/^(html|body|#document)$/.test(jr(t))}function Ft(t){return it(t).getComputedStyle(t)}function gs(t){return Pt(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Un(t){if(jr(t)==="html")return t;let e=t.assignedSlot||t.parentNode||ww(t)&&t.host||xn(t);return ww(e)?e.host:e}function Ew(t){let e=Un(t);return qi(e)?(t.ownerDocument||t).body:wn(e)&&hs(e)?e:Ew(e)}function bl(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=Ew(t),o=i===((r=t.ownerDocument)==null?void 0:r.body),s=it(i);if(o){let a=Sl(s);return e.concat(s,s.visualViewport||[],hs(i)?i:[],a&&n?bl(a):[])}else return e.concat(i,bl(i,[],n))}function Sl(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Aw(t){let e=Ft(t),n=parseFloat(e.width)||0,r=parseFloat(e.height)||0,i=wn(t),o=i?t.offsetWidth:n,s=i?t.offsetHeight:r,a=ds(n)!==o||ds(r)!==s;return a&&(n=o,r=s),{width:n,height:r,$:a}}function Iw(t){return Pt(t)?t:t.contextElement}function Ki(t){let e=Iw(t);if(!wn(e))return Xt(1);let n=e.getBoundingClientRect(),{width:r,height:i,$:o}=Aw(e),s=(o?ds(n.width):n.width)/r,a=(o?ds(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}var iO=Xt(0);function Nw(t){let e=it(t);return!Cl()||!e.visualViewport?iO:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function oO(t,e,n){return e===void 0&&(e=!1),!!n&&e&&n===it(t)}function ys(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),o=Iw(t),s=Xt(1);e&&(r?Pt(r)&&(s=Ki(r)):s=Ki(t));let a=oO(o,n,r)?Nw(o):Xt(0),l=(i.left+a.x)/s.x,c=(i.top+a.y)/s.y,u=i.width/s.x,f=i.height/s.y;if(o&&r){let d=it(o),p=Pt(r)?it(r):r,h=d,m=Sl(h);for(;m&&p!==h;){let g=Ki(m),y=m.getBoundingClientRect(),x=Ft(m),C=y.left+(m.clientLeft+parseFloat(x.paddingLeft))*g.x,v=y.top+(m.clientTop+parseFloat(x.paddingTop))*g.y;l*=g.x,c*=g.y,u*=g.x,f*=g.y,l+=C,c+=v,h=it(m),m=Sl(h)}}return Hr({width:u,height:f,x:l,y:c})}function Ml(t,e){let n=gs(t).scrollLeft;return e?e.left+n:ys(xn(t)).left+n}function Rw(t,e){let n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-Ml(t,n),i=n.top+e.scrollTop;return{x:r,y:i}}function sO(t){let{elements:e,rect:n,offsetParent:r,strategy:i}=t,o=i==="fixed",s=xn(r),a=e?ms(e.floating):!1;if(r===s||a&&o)return n;let l={scrollLeft:0,scrollTop:0},c=Xt(1),u=Xt(0),f=wn(r);if((f||!o)&&((jr(r)!=="body"||hs(s))&&(l=gs(r)),f)){let p=ys(r);c=Ki(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}let d=s&&!f&&!o?Rw(s,l):Xt(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+d.x,y:n.y*c.y-l.scrollTop*c.y+u.y+d.y}}function aO(t){return t.getClientRects?Array.from(t.getClientRects()):[]}function lO(t){let e=gs(t),n=t.ownerDocument.body,r=$r(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),i=$r(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight),o=-e.scrollLeft+Ml(t),s=-e.scrollTop;return Ft(n).direction==="rtl"&&(o+=$r(t.clientWidth,n.clientWidth)-r),{width:r,height:i,x:o,y:s}}var cO=25;function uO(t,e,n){n===void 0&&(n="viewport");let r=n==="layoutViewport",i=it(t),o=xn(t),s=i.visualViewport,a=o.clientWidth,l=o.clientHeight,c=0,u=0;if(s){let d=!Cl()||e==="fixed";r?d||(c=-s.offsetLeft,u=-s.offsetTop):(a=s.width,l=s.height,d&&(c=s.offsetLeft,u=s.offsetTop))}if(Ml(o)<=0){let d=o.ownerDocument,p=d.body,h=getComputedStyle(p),m=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,g=Math.abs(o.clientWidth-p.clientWidth-m),y=getComputedStyle(o).scrollbarGutter==="stable both-edges"?g/2:g;y<=cO&&(a-=y)}return{width:a,height:l,x:c,y:u}}function fO(t,e){let n=ys(t,!0,e==="fixed"),r=n.top+t.clientTop,i=n.left+t.clientLeft,o=Ki(t),s=t.clientWidth*o.x,a=t.clientHeight*o.y,l=i*o.x,c=r*o.y;return{width:s,height:a,x:l,y:c}}function Tw(t,e,n){let r;if(e==="viewport"||e==="layoutViewport")r=uO(t,n,e);else if(e==="document")r=lO(xn(t));else if(Pt(e))r=fO(e,n);else{let i=Nw(t);r={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return Hr(r)}function dO(t,e){let n=e.get(t);if(n)return n;let r=bl(t,[],!1).filter(a=>Pt(a)&&jr(a)!=="body"),i=null,o=Ft(t).position==="fixed",s=o?Un(t):t;for(;Pt(s)&&!qi(s);){let a=Ft(s),l=wl(s),c=i?i.position:o?"fixed":"";!l&&(c==="fixed"||c==="absolute"&&a.position==="static")?r=r.filter(f=>f!==s):i=a,s=Un(s)}return e.set(t,r),r}function pO(t){let{element:e,boundary:n,rootBoundary:r,strategy:i}=t,s=[...n==="clippingAncestors"?ms(e)?[]:dO(e,this._c):[].concat(n),r],a=Tw(e,s[0],i),l=a.top,c=a.right,u=a.bottom,f=a.left;for(let d=1;d<s.length;d++){let p=Tw(e,s[d],i);l=$r(p.top,l),c=yl(p.right,c),u=yl(p.bottom,u),f=$r(p.left,f)}return{width:c-f,height:u-l,x:f,y:l}}function hO(t){let{width:e,height:n}=Aw(t);return{width:e,height:n}}function mO(t,e,n){let r=wn(e),i=xn(e),o=n==="fixed",s=ys(t,!0,o,e),a={scrollLeft:0,scrollTop:0},l=Xt(0);if((r||!o)&&((jr(e)!=="body"||hs(i))&&(a=gs(e)),r)){let d=ys(e,!0,o,e);l.x=d.x+e.clientLeft,l.y=d.y+e.clientTop}!r&&i&&(l.x=Ml(i));let c=i&&!r&&!o?Rw(i,a):Xt(0),u=s.left+a.scrollLeft-l.x-c.x,f=s.top+a.scrollTop-l.y-c.y;return{x:u,y:f,width:s.width,height:s.height}}function op(t){return Ft(t).position==="static"}function vw(t,e){if(!wn(t)||Ft(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return xn(t)===n&&(n=n.ownerDocument.body),n}function Ow(t,e){let n=it(t);if(ms(t))return n;if(!wn(t)){let i=Un(t);for(;i&&!qi(i);){if(Pt(i)&&!op(i))return i;i=Un(i)}return n}let r=vw(t,e);for(;r&&Sw(r)&&op(r);)r=vw(r,e);return r&&qi(r)&&op(r)&&!wl(r)?n:r||Mw(t)||n}var gO=async function(t){let e=this.getOffsetParent||Ow,n=this.getDimensions,r=await n(t.floating);return{reference:mO(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function yO(t){return Ft(t).direction==="rtl"}var kO={convertOffsetParentRelativeRectToViewportRelativeRect:sO,getDocumentElement:xn,getClippingRect:pO,getOffsetParent:Ow,getElementRects:gO,getClientRects:aO,getDimensions:hO,getScale:Ki,isElement:Pt,isRTL:yO};var Dw=xw;var Lw=bw;var Bw=(t,e,n)=>{let r=new Map,i=n??{},o={...kO,...i.platform,_c:r};return kw(t,e,{...i,platform:o})};function Pw(t){let e=ve({},`${t}_SLASH_SPEC`),n=pe(i=>{let o=i.get(e.key);return new X({key:new ee(`${t}_SLASH`),...o})}),r=[e,n];return r.key=e.key,r.pluginKey=n.key,e.meta={package:"@milkdown/plugin-slash",displayName:`Ctx<slashSpec>|${t}`},n.meta={package:"@milkdown/plugin-slash",displayName:`Prose<slash>|${t}`},r}var Fw=class{#t;#e;#r;#n;#s;#o;#i;#a;#l;constructor(t){this.#t=!1,this.onShow=()=>{},this.onHide=()=>{},this.#d=(e,n)=>{let{state:r,composing:i}=e,{selection:o,doc:s}=r,{ranges:a}=o,l=Math.min(...a.map(f=>f.$from.pos)),c=Math.max(...a.map(f=>f.$to.pos)),u=n&&n.doc.eq(s)&&n.selection.eq(o);if(this.#t||((this.#n??e.dom.parentElement??document.body).appendChild(this.element),this.#t=!0),!(i||u)){if(!this.#i(e,n)){this.hide();return}Bw({getBoundingClientRect:()=>Wg(e,l,c)},this.element,{placement:"bottom-start",middleware:[Lw(),Dw(this.#l),...this.#e],...this.#r}).then(({x:f,y:d})=>{Object.assign(this.element.style,{left:`${f}px`,top:`${d}px`})}).catch(console.error),this.show()}},this.#c=e=>{let n=this.getContent(e);if(!n)return!1;let r=n.at(-1);return r?Array.isArray(this.#o)?this.#o.includes(r):this.#o===r:!1},this.update=(e,n)=>{this.#a(e,n)},this.getContent=(e,n=r=>r.type.name==="paragraph")=>{let{selection:r}=e.state,{empty:i,$from:o}=r,s=e.state.selection instanceof P;if(typeof document>"u")return;let a=this.element.contains(document.activeElement),l=!e.hasFocus()&&!a,c=!e.editable,u=!qg(n)(e.state.selection);if(!(l||c||!i||!s||u))return o.parent.textBetween(Math.max(0,o.parentOffset-500),o.parentOffset,void 0,"\uFFFC")},this.destroy=()=>{this.#a.cancel()},this.show=()=>{this.element.dataset.show="true",this.onShow()},this.hide=()=>{this.element.dataset.show="false",this.onHide()},this.element=t.content,this.#s=t.debounce??200,this.#i=t.shouldShow??this.#c,this.#o=t.trigger??"/",this.#l=t.offset,this.#e=t.middleware??[],this.#r=t.floatingUIOptions??{},this.#n=t.root,this.#a=rs(this.#d,this.#s)}#d;#c};function sp(t){return new Promise(e=>{let n=new FileReader;n.addEventListener("load",()=>{e({alt:t.name,src:n.result})},!1),n.readAsDataURL(t)})}var bO=async(t,e)=>{let n=[];for(let i=0;i<t.length;i++){let o=t.item(i);o&&o.type.includes("image")&&n.push(o)}let{image:r}=e.nodes;if(!r)throw Rs("image");return(await Promise.all(n.map(i=>sp(i)))).map(({alt:i,src:o})=>r.createAndFill({src:o,alt:i}))},Vr=ve({uploader:bO,enableHtmlFileUploader:!1,uploadWidgetFactory:(t,e)=>{let n=document.createElement("span");return n.textContent="Upload in progress...",le.widget(t,n,e)}},"uploadConfig");Vr.meta={package:"@milkdown/plugin-upload",displayName:"Ctx<uploadConfig>"};var zw=pe(t=>{let e=new ee("MILKDOWN_UPLOAD"),n=(i,o)=>{let s=e.getState(i);if(!s)return-1;let a=s.find(void 0,void 0,l=>l.id===o);return a.length?a[0]?.from??-1:-1},r=(i,o,s)=>{if(!s||s.length<=0)return!1;let a=Symbol("upload symbol"),l=t.get($e),{uploader:c,getInsertPos:u}=t.get(Vr.key),{tr:f}=i.state,d=o instanceof DragEvent?i.posAtCoords({left:o.clientX,top:o.clientY})?.pos??f.selection.from:f.selection.from,p=typeof u=="function"?u(o,t,d):d;return i.dispatch(f.setMeta(e,{add:{id:a,pos:p}})),c(s,l,t,p).then(h=>{let m=n(i.state,a);m<0||i.dispatch(i.state.tr.replaceWith(m,m,h).setMeta(e,{remove:{id:a}}))}).catch(h=>{console.error(h)}),!0};return new X({key:e,state:{init(){return oe.empty},apply(i,o){let s=o.map(i.mapping,i.doc),a=i.getMeta(this);if(!a)return s;if(a.add){let{uploadWidgetFactory:l}=t.get(Vr.key),c=l(a.add.pos,{id:a.add.id});return s.add(i.doc,[c])}if(a.remove){let l=s.find(void 0,void 0,c=>c.id===a.remove.id);return s.remove(l)}return s}},props:{decorations(i){return this.getState(i)},handlePaste:(i,o)=>{let{enableHtmlFileUploader:s}=t.get(Vr.key);return!(o instanceof ClipboardEvent)||!s&&o.clipboardData?.getData("text/html")?!1:r(i,o,o.clipboardData?.files)},handleDrop:(i,o)=>o instanceof DragEvent?r(i,o,o.dataTransfer?.files):!1}})});zw.meta={package:"@milkdown/plugin-upload",displayName:"Prose<upload>"};var $w=[Vr,zw];function ap(){return{enter:{mathFlow:t,mathFlowFenceMeta:e,mathText:o},exit:{mathFlow:i,mathFlowFence:r,mathFlowFenceMeta:n,mathFlowValue:a,mathText:s,mathTextData:a}};function t(l){let c={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[c]}},l)}function e(){this.buffer()}function n(){let l=this.resume(),c=this.stack[this.stack.length-1];c.type,c.meta=l}function r(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function i(l){let c=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c;let f=u.data.hChildren[0];f.type,f.tagName,f.children.push({type:"text",value:c}),this.data.mathFlowInside=void 0}function o(l){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},l),this.buffer()}function s(l){let c=this.resume(),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c,u.data.hChildren.push({type:"text",value:c})}function a(l){this.config.enter.data.call(this,l),this.config.exit.data.call(this,l)}}function lp(t){let e=(t||{}).singleDollarTextMath;return e==null&&(e=!0),r.peek=i,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:` `,inConstruct:"mathFlowMeta"},{character:"$",after:e?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:n,inlineMath:r}};function n(o,s,a,l){let c=o.value||"",u=a.createTracker(l),f="$".repeat(Math.max(Ks(c,"$")+1,2)),d=a.enter("mathFlow"),p=u.move(f);if(o.meta){let h=a.enter("mathFlowMeta");p+=u.move(a.safe(o.meta,{after:` `,before:p,encode:["$"],...u.current()})),h()}return p+=u.move(` `),c&&(p+=u.move(c+` -`)),p+=u.move(f),d(),p}function r(o,s,a){let l=o.value||"",c=1;for(e||c++;new RegExp("(^|[^$])"+"\\$".repeat(c)+"([^$]|$)").test(l);)c++;let u="$".repeat(c);/[^ \r\n]/.test(l)&&(/^[ \r\n]/.test(l)&&/[ \r\n]$/.test(l)||/^\$|\$$/.test(l))&&(l=" "+l+" ");let f=-1;for(;++f<a.unsafe.length;){let d=a.unsafe[f];if(!d.atBreak)continue;let p=a.compilePattern(d),h;for(;h=p.exec(l);){let m=h.index;l.codePointAt(m)===10&&l.codePointAt(m-1)===13&&m--,l=l.slice(0,m)+" "+l.slice(h.index+1)}}return u+l+u}function i(){return"$"}}var $w={tokenize:xO,concrete:!0,name:"mathFlow"},zw={tokenize:wO,partial:!0};function xO(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(x){return t.enter("mathFlow"),t.enter("mathFlowFence"),t.enter("mathFlowFenceSequence"),l(x)}function l(x){return x===36?(t.consume(x),s++,l):s<2?n(x):(t.exit("mathFlowFenceSequence"),$(t,c,"whitespace")(x))}function c(x){return x===null||D(x)?f(x):(t.enter("mathFlowFenceMeta"),t.enter("chunkString",{contentType:"string"}),u(x))}function u(x){return x===null||D(x)?(t.exit("chunkString"),t.exit("mathFlowFenceMeta"),f(x)):x===36?n(x):(t.consume(x),u)}function f(x){return t.exit("mathFlowFence"),r.interrupt?e(x):t.attempt(zw,d,g)(x)}function d(x){return t.attempt({tokenize:y,partial:!0},g,p)(x)}function p(x){return(o?$(t,h,"linePrefix",o+1):h)(x)}function h(x){return x===null?g(x):D(x)?t.attempt(zw,d,g)(x):(t.enter("mathFlowValue"),m(x))}function m(x){return x===null||D(x)?(t.exit("mathFlowValue"),h(x)):(t.consume(x),m)}function g(x){return t.exit("mathFlow"),e(x)}function y(x,C,v){let A=0;return $(x,w,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function w(O){return x.enter("mathFlowFence"),x.enter("mathFlowFenceSequence"),N(O)}function N(O){return O===36?(A++,x.consume(O),N):A<s?v(O):(x.exit("mathFlowFenceSequence"),$(x,B,"whitespace")(O))}function B(O){return O===null||D(O)?(x.exit("mathFlowFence"),C(O)):v(O)}}}function wO(t,e,n){let r=this;return i;function i(s){return s===null?e(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function _w(t){let n=(t||{}).singleDollarTextMath;return n==null&&(n=!0),{tokenize:r,resolve:CO,previous:SO,name:"mathText"};function r(i,o,s){let a=this,l=0,c,u;return f;function f(g){return i.enter("mathText"),i.enter("mathTextSequence"),d(g)}function d(g){return g===36?(i.consume(g),l++,d):l<2&&!n?s(g):(i.exit("mathTextSequence"),p(g))}function p(g){return g===null?s(g):g===36?(u=i.enter("mathTextSequence"),c=0,m(g)):g===32?(i.enter("space"),i.consume(g),i.exit("space"),p):D(g)?(i.enter("lineEnding"),i.consume(g),i.exit("lineEnding"),p):(i.enter("mathTextData"),h(g))}function h(g){return g===null||g===32||g===36||D(g)?(i.exit("mathTextData"),p(g)):(i.consume(g),h)}function m(g){return g===36?(i.consume(g),c++,m):c===l?(i.exit("mathTextSequence"),i.exit("mathText"),o(g)):(u.type="mathTextData",h(g))}}}function CO(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="mathTextData"){t[e][1].type="mathTextPadding",t[n][1].type="mathTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)i===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(i=r):(r===e||t[r][1].type==="lineEnding")&&(t[i][1].type="mathTextData",r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),e-=r-i-2,r=i+2),i=void 0);return t}function SO(t){return t!==36||this.events[this.events.length-1][1].type==="characterEscape"}function cp(t){return{flow:{36:$w},text:{36:_w(t)}}}var MO={};function El(t){let e=this,n=t||MO,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(cp(n)),o.push(ap()),s.push(lp(n))}var Hw=ht("weiBeiRemarkMath",()=>El),up=ce("math_inline",()=>({group:"inline",content:"text*",inline:!0,atom:!0,parseDOM:[{tag:'span[data-type="math_inline"]',getContent:(t,e)=>M.from(e.text(t.dataset.value||""))}],toDOM:t=>["span",{"data-type":"math_inline","data-value":t.textContent},t.textContent],parseMarkdown:{match:t=>t.type==="inlineMath",runner:(t,e,n)=>t.openNode(n).addText(e.value).closeNode()},toMarkdown:{match:t=>t.type.name==="math_inline",runner:(t,e)=>t.addNode("inlineMath",void 0,e.textContent)}})),Tl=ce("math_block",()=>({content:"text*",group:"block",marks:"",defining:!0,atom:!0,isolating:!0,attrs:{value:{default:""}},parseDOM:[{tag:'div[data-type="math_block"]',preserveWhitespace:"full",getAttrs:t=>({value:t.dataset.value||""})}],toDOM:t=>["div",{"data-type":"math_block","data-value":t.attrs.value},t.attrs.value],parseMarkdown:{match:t=>t.type==="math",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="math_block",runner:(t,e)=>t.addNode("math",void 0,e.attrs.value)}})),Ww=ge(t=>new be(/^\$\$\s$/,(e,n,r,i)=>{let o=e.doc.resolve(r);return o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),Tl.type(t))?e.tr.delete(r,i).setBlockType(r,r,Tl.type(t)):null}));var jw=new Map,fp=t=>{let e=jw.get(t);if(e)return e;let n=new Promise((r,i)=>{let o=document.createElement("script");o.src=new URL(t,document.baseURI).href,o.onload=()=>r(),o.onerror=()=>i(new Error(`Unable to load local editor runtime: ${t}`)),document.head.appendChild(o)});return jw.set(t,n),n},Vw=()=>fp("katex-runtime.js").then(()=>window.WeiBeiKaTeX),qw=()=>window.WeiBeiKaTeX,Kw=()=>fp("mermaid-runtime.js").then(()=>window.WeiBeiMermaid),Uw=()=>fp("prism-runtime.js").then(()=>window.WeiBeiPrism);var dp="[A-Za-z][A-Za-z0-9_-]*",EO=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},Jw=(t,e,n)=>{let r=t.indexOf(e,n);for(;r>=0&&EO(t,r);)r=t.indexOf(e,r+e.length);return r},TO=(t,e)=>{let n=String(t||""),r="",i=0;for(;i<n.length;){let o=Jw(n,"`",i);if(o<0){r+=e(n.slice(i));break}r+=e(n.slice(i,o));let s=n.slice(o).match(/^`+/)?.[0]||"`",a=Jw(n,s,o+s.length);if(a<0){r+=e(n.slice(o));break}r+=n.slice(o,a+s.length),i=a+s.length}return r},vO=t=>String(t||"").replace(/(?<!\\)`/g,"\\`").replace(/\\\[\\\[/g,"[[").replace(/\\\]\\\]/g,"]]").replace(/\\=\\=([^=\n]+?)\\=\\=/g,"==$1==").replace(/\^\\\[/g,"^[").replace(/(^|\s)\\#(?=[\p{L}\p{N}_/-])/gu,"$1#").replace(/\\\$(?=\d)/g,"$").replace(new RegExp(`^(\\s*(?:>\\s*)*)\\\\(\\[!(?:${dp})\\])`,"gim"),"$1$2"),ks=(t,e)=>{let n=String(t||"").split(/(\r?\n)/),r=!1,i="",o=0,s="";for(let a=0;a<n.length;a+=2){let l=n[a]||"",c=n[a+1]||"",u=l.match(/^\s*(?:>\s*)*(`{3,}|~{3,})/);if(u){r?u[1][0]===i&&u[1].length>=o&&(r=!1,o=0):(r=!0,i=u[1][0],o=u[1].length),s+=l+c;continue}if(r){s+=l+c;continue}let f=TO(l,e);s+=f,f.endsWith(` +`)),p+=u.move(f),d(),p}function r(o,s,a){let l=o.value||"",c=1;for(e||c++;new RegExp("(^|[^$])"+"\\$".repeat(c)+"([^$]|$)").test(l);)c++;let u="$".repeat(c);/[^ \r\n]/.test(l)&&(/^[ \r\n]/.test(l)&&/[ \r\n]$/.test(l)||/^\$|\$$/.test(l))&&(l=" "+l+" ");let f=-1;for(;++f<a.unsafe.length;){let d=a.unsafe[f];if(!d.atBreak)continue;let p=a.compilePattern(d),h;for(;h=p.exec(l);){let m=h.index;l.codePointAt(m)===10&&l.codePointAt(m-1)===13&&m--,l=l.slice(0,m)+" "+l.slice(h.index+1)}}return u+l+u}function i(){return"$"}}var Hw={tokenize:xO,concrete:!0,name:"mathFlow"},_w={tokenize:wO,partial:!0};function xO(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(x){return t.enter("mathFlow"),t.enter("mathFlowFence"),t.enter("mathFlowFenceSequence"),l(x)}function l(x){return x===36?(t.consume(x),s++,l):s<2?n(x):(t.exit("mathFlowFenceSequence"),$(t,c,"whitespace")(x))}function c(x){return x===null||D(x)?f(x):(t.enter("mathFlowFenceMeta"),t.enter("chunkString",{contentType:"string"}),u(x))}function u(x){return x===null||D(x)?(t.exit("chunkString"),t.exit("mathFlowFenceMeta"),f(x)):x===36?n(x):(t.consume(x),u)}function f(x){return t.exit("mathFlowFence"),r.interrupt?e(x):t.attempt(_w,d,g)(x)}function d(x){return t.attempt({tokenize:y,partial:!0},g,p)(x)}function p(x){return(o?$(t,h,"linePrefix",o+1):h)(x)}function h(x){return x===null?g(x):D(x)?t.attempt(_w,d,g)(x):(t.enter("mathFlowValue"),m(x))}function m(x){return x===null||D(x)?(t.exit("mathFlowValue"),h(x)):(t.consume(x),m)}function g(x){return t.exit("mathFlow"),e(x)}function y(x,C,v){let A=0;return $(x,w,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function w(O){return x.enter("mathFlowFence"),x.enter("mathFlowFenceSequence"),N(O)}function N(O){return O===36?(A++,x.consume(O),N):A<s?v(O):(x.exit("mathFlowFenceSequence"),$(x,B,"whitespace")(O))}function B(O){return O===null||D(O)?(x.exit("mathFlowFence"),C(O)):v(O)}}}function wO(t,e,n){let r=this;return i;function i(s){return s===null?e(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function Ww(t){let n=(t||{}).singleDollarTextMath;return n==null&&(n=!0),{tokenize:r,resolve:CO,previous:SO,name:"mathText"};function r(i,o,s){let a=this,l=0,c,u;return f;function f(g){return i.enter("mathText"),i.enter("mathTextSequence"),d(g)}function d(g){return g===36?(i.consume(g),l++,d):l<2&&!n?s(g):(i.exit("mathTextSequence"),p(g))}function p(g){return g===null?s(g):g===36?(u=i.enter("mathTextSequence"),c=0,m(g)):g===32?(i.enter("space"),i.consume(g),i.exit("space"),p):D(g)?(i.enter("lineEnding"),i.consume(g),i.exit("lineEnding"),p):(i.enter("mathTextData"),h(g))}function h(g){return g===null||g===32||g===36||D(g)?(i.exit("mathTextData"),p(g)):(i.consume(g),h)}function m(g){return g===36?(i.consume(g),c++,m):c===l?(i.exit("mathTextSequence"),i.exit("mathText"),o(g)):(u.type="mathTextData",h(g))}}}function CO(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="mathTextData"){t[e][1].type="mathTextPadding",t[n][1].type="mathTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)i===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(i=r):(r===e||t[r][1].type==="lineEnding")&&(t[i][1].type="mathTextData",r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),e-=r-i-2,r=i+2),i=void 0);return t}function SO(t){return t!==36||this.events[this.events.length-1][1].type==="characterEscape"}function cp(t){return{flow:{36:Hw},text:{36:Ww(t)}}}var MO={};function El(t){let e=this,n=t||MO,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(cp(n)),o.push(ap()),s.push(lp(n))}var jw=ht("weiBeiRemarkMath",()=>El),up=ce("math_inline",()=>({group:"inline",content:"text*",inline:!0,atom:!0,parseDOM:[{tag:'span[data-type="math_inline"]',getContent:(t,e)=>M.from(e.text(t.dataset.value||""))}],toDOM:t=>["span",{"data-type":"math_inline","data-value":t.textContent},t.textContent],parseMarkdown:{match:t=>t.type==="inlineMath",runner:(t,e,n)=>t.openNode(n).addText(e.value).closeNode()},toMarkdown:{match:t=>t.type.name==="math_inline",runner:(t,e)=>t.addNode("inlineMath",void 0,e.textContent)}})),Tl=ce("math_block",()=>({content:"text*",group:"block",marks:"",defining:!0,atom:!0,isolating:!0,attrs:{value:{default:""}},parseDOM:[{tag:'div[data-type="math_block"]',preserveWhitespace:"full",getAttrs:t=>({value:t.dataset.value||""})}],toDOM:t=>["div",{"data-type":"math_block","data-value":t.attrs.value},t.attrs.value],parseMarkdown:{match:t=>t.type==="math",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="math_block",runner:(t,e)=>t.addNode("math",void 0,e.attrs.value)}})),Vw=ge(t=>new be(/^\$\$\s$/,(e,n,r,i)=>{let o=e.doc.resolve(r);return o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),Tl.type(t))?e.tr.delete(r,i).setBlockType(r,r,Tl.type(t)):null}));var qw=new Map,fp=t=>{let e=qw.get(t);if(e)return e;let n=new Promise((r,i)=>{let o=document.createElement("script");o.src=new URL(t,document.baseURI).href,o.onload=()=>r(),o.onerror=()=>i(new Error(`Unable to load local editor runtime: ${t}`)),document.head.appendChild(o)});return qw.set(t,n),n},Kw=()=>fp("katex-runtime.js").then(()=>window.WeiBeiKaTeX),Uw=()=>window.WeiBeiKaTeX,Jw=()=>fp("mermaid-runtime.js").then(()=>window.WeiBeiMermaid),Gw=()=>fp("prism-runtime.js").then(()=>window.WeiBeiPrism);var dp="[A-Za-z][A-Za-z0-9_-]*",EO=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},Xw=(t,e,n)=>{let r=t.indexOf(e,n);for(;r>=0&&EO(t,r);)r=t.indexOf(e,r+e.length);return r},TO=(t,e)=>{let n=String(t||""),r="",i=0;for(;i<n.length;){let o=Xw(n,"`",i);if(o<0){r+=e(n.slice(i));break}r+=e(n.slice(i,o));let s=n.slice(o).match(/^`+/)?.[0]||"`",a=Xw(n,s,o+s.length);if(a<0){r+=e(n.slice(o));break}r+=n.slice(o,a+s.length),i=a+s.length}return r},vO=t=>String(t||"").replace(/(?<!\\)`/g,"\\`").replace(/\\\[\\\[/g,"[[").replace(/\\\]\\\]/g,"]]").replace(/\\=\\=([^=\n]+?)\\=\\=/g,"==$1==").replace(/\^\\\[/g,"^[").replace(/(^|\s)\\#(?=[\p{L}\p{N}_/-])/gu,"$1#").replace(/\\\$(?=\d)/g,"$").replace(new RegExp(`^(\\s*(?:>\\s*)*)\\\\(\\[!(?:${dp})\\])`,"gim"),"$1$2"),ks=(t,e)=>{let n=String(t||"").split(/(\r?\n)/),r=!1,i="",o=0,s="";for(let a=0;a<n.length;a+=2){let l=n[a]||"",c=n[a+1]||"",u=l.match(/^\s*(?:>\s*)*(`{3,}|~{3,})/);if(u){r?u[1][0]===i&&u[1].length>=o&&(r=!1,o=0):(r=!0,i=u[1][0],o=u[1].length),s+=l+c;continue}if(r){s+=l+c;continue}let f=TO(l,e);s+=f,f.endsWith(` `)&&c||(s+=c)}return s},AO=t=>ks(t,vO),IO=t=>/^\s*(?:>\s*)*<br\s*\/?>\s*$/i.test(t)?t:String(t||"").replace(/<br\s*\/?>[ \t]*/gi,` -`.padStart(3)),NO=t=>ks(t,IO),Gw=/(?<!\\)\$((?!\d)[^$\n]+)\$$/,RO=t=>String(t||"").replace(/(^|[^\\])\$(?=\d)/g,"$1\\$"),OO=t=>ks(t,RO),DO=t=>ks(t,e=>e.replace(/\\\[([\s\S]*?)\\\]/g,(n,r)=>`$$ +`.padStart(3)),NO=t=>ks(t,IO),Yw=/(?<!\\)\$((?!\d)[^$\n]+)\$$/,RO=t=>String(t||"").replace(/(^|[^\\])\$(?=\d)/g,"$1\\$"),OO=t=>ks(t,RO),DO=t=>ks(t,e=>e.replace(/\\\[([\s\S]*?)\\\]/g,(n,r)=>`$$ ${String(r).trim()} $$`).replace(/\\\(([^\n]*?)\\\)/g,(n,r)=>`$${String(r).trim()}$`)),LO=t=>ks(t,e=>e.replace(/^[ \t]*\[\s*([^\n\]]*?\\[A-Za-z]+[^\n\]]*?)\s*\][ \t]*$/gm,(n,r)=>`$$ ${String(r).trim()} $$`).replace(/^[ \t]*\$\$([^$\n]+)\$\$[ \t]*$/gm,(n,r)=>`$$ ${String(r).trim()} -$$`).replace(/\\hat\s+(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}").replace(/\\hat(?!\{)(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}")),qr=(t,e)=>{let n=NO(t);return(e==="userPaste"||e==="agentGenerated")&&(n=DO(n)),e==="agentGenerated"&&(n=LO(n)),OO(n)},vl=t=>{let e=t||"",n=e.match(/^(---\n[\s\S]*?\n---)(?:\n+|$)/);return n?{frontmatter:n[1],body:e.slice(n[0].length)}:{frontmatter:"",body:e}},Xw=(t,e)=>{let n=AO(e),r=t?n.replace(/^\n+/,""):n;return t?`${t} +$$`).replace(/\\hat\s+(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}").replace(/\\hat(?!\{)(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}")),qr=(t,e)=>{let n=NO(t);return(e==="userPaste"||e==="agentGenerated")&&(n=DO(n)),e==="agentGenerated"&&(n=LO(n)),OO(n)},vl=t=>{let e=t||"",n=e.match(/^(---\n[\s\S]*?\n---)(?:\n+|$)/);return n?{frontmatter:n[1],body:e.slice(n[0].length)}:{frontmatter:"",body:e}},Qw=(t,e)=>{let n=AO(e),r=t?n.replace(/^\n+/,""):n;return t?`${t} -${r}`:r};var Yw=["transactions","fullSerializations","bridgeMessages","bridgeBytes","decorationNodes","decorationCacheHits","katexRenders","mermaidRenders","imageScans","imageNodeUpdates","codeTokenizations","outlineReports"],Qw=()=>Object.fromEntries(Yw.map(t=>[t,0])),At=(t,e,n=1)=>{t&&(t[e]+=n)},Zw=t=>{if(t)for(let e of Yw)t[e]=0};var e0=t=>JSON.stringify(t.map(({level:e,title:n})=>[e,n]));var BO=["loadDocument","requestSnapshot","setTheme","setLanguage","setEditable","focus","scrollToHeading","applyMarkdownFragment","replaceSelection","executeSelectionCommand","insertStructuredBlock","restoreCheckpoint"],t0=t=>Number.isInteger(t)&&Number(t)>=0,pp=t=>typeof t=="string"&&t.length>0,n0=t=>{if(!t||typeof t!="object")return null;let e=t;return e.protocolVersion!==2||!pp(e.commandID)||typeof e.documentID!="string"||!t0(e.documentGeneration)||!BO.includes(e.type)||!e.payload||typeof e.payload!="object"||Array.isArray(e.payload)||e.minimumRevision!==void 0&&!t0(e.minimumRevision)||e.requestID!==void 0&&!pp(e.requestID)||e.type==="requestSnapshot"&&!pp(e.requestID)?null:e},r0=(t,e)=>t.type==="loadDocument"?t.documentGeneration>e.documentGeneration||t.documentGeneration===e.documentGeneration&&(!e.documentID||t.documentID===e.documentID):t.documentID===e.documentID&&t.documentGeneration===e.documentGeneration&&(t.minimumRevision===void 0||t.minimumRevision<=e.revision),i0=(t,e)=>e?{revision:t.revision+1,dirty:!0,changed:!0}:{...t,changed:!1},o0=(t,e)=>({...e,protocolVersion:2,documentID:t.documentID,documentGeneration:t.documentGeneration,revision:t.revision});var PO=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},s0=t=>{let e=[],n=/!\[\[([^\]\n]+)\]\]|\[\[([^\]\n]+)\]\]|==([^=\n]+)==|\^\[([^\]\n]+)\]/g,r=0;for(let i of t.matchAll(n)){let o=i.index||0;if(PO(t,o))continue;o>r&&e.push({type:"text",value:t.slice(r,o)});let s=i[1]??i[2];if(s!==void 0){let a=s.indexOf("|"),l=(a<0?s:s.slice(0,a)).trim(),c=(a<0?"":s.slice(a+1)).trim();e.push({type:i[1]===void 0?"wikiLink":"embed",raw:s,target:l,label:c})}else i[3]!==void 0?e.push({type:"highlight",value:i[3]}):e.push({type:"inlineFootnote",value:i[4]});r=o+i[0].length}return r<t.length&&e.push({type:"text",value:t.slice(r)}),e.length?e:[{type:"text",value:t}]};var a0=t=>{let e=t.match(/^\[!([A-Za-z][A-Za-z0-9_-]*)\]([+-]?)(?:[ \t]+(.+))?$/);return e?{calloutType:e[1].toLowerCase(),fold:e[2]||"",title:(e[3]||"").trim()}:null},l0=t=>`[!${t.calloutType}]${t.fold}${t.title?` ${t.title}`:""}`;var hp=new Set(["system","serif","literary"]),FO=t=>{let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],i=r.type==="html"?String(r.value||"").match(/^<span data-weibei-font="(system|serif|literary)">$/):null;if(!i){e.push(r);continue}let o=t.findIndex((s,a)=>a>n&&s.type==="html"&&String(s.value||"")==="</span>");if(o<0){e.push(r);continue}e.push({type:"writingFont",font:i[1],children:t.slice(n+1,o)}),n=o}return e},zO=t=>t.type==="text"?{type:"text",value:t.value}:t.type==="highlight"?{type:"highlight",children:[{type:"text",value:t.value}]}:t.type==="inlineFootnote"?{type:"inlineFootnote",value:t.value}:{type:t.type,raw:t.raw,target:t.target,label:t.label},c0=t=>{if(!t.children||["code","inlineCode","html"].includes(t.type))return;if(t.type==="blockquote"){let n=t.children[0],r=n?.type==="paragraph"&&n.children?.length===1&&n.children[0].type==="text"?String(n.children[0].value||""):"",i=a0(r);if(i){t.type="callout",t.calloutType=i.calloutType,t.fold=i.fold,t.title=i.title,t.children=t.children.slice(1),t.children.length===0&&t.children.push({type:"paragraph",children:[]});let o=t.children[0]?.type==="paragraph"?t.children[0].children?.[0]:null;o?.type==="text"&&(o.value=String(o.value||"").replace(/^\[![A-Za-z][A-Za-z0-9_-]*\][+-]?[ \t]*/,""))}}let e=t.children.flatMap(n=>n.type!=="text"?(c0(n),[n]):s0(String(n.value||"")).map(zO));t.children=FO(e)},$O=ht("weiBeiStructuredMarkdown",()=>(function(){let e=this.data();return(e.toMarkdownExtensions||(e.toMarkdownExtensions=[])).push({handlers:{wikiLink:(r,i,o,s)=>`[[${o.safe(r.raw,{...s,before:"[[",after:"]]"})}]]`,embed:(r,i,o,s)=>`![[${o.safe(r.raw,{...s,before:"![[",after:"]]"})}]]`,inlineFootnote:(r,i,o,s)=>`^[${o.safe(r.value,{...s,before:"^[",after:"]"})}]`,highlight:(r,i,o,s)=>`==${o.containerPhrasing(r,{...s,before:"==",after:"=="})}==`,writingFont:(r,i,o,s)=>{let a=hp.has(r.font)?r.font:"serif",l=o.containerPhrasing(r,{...s,before:">",after:"<"});return`<span data-weibei-font="${a}">${l}</span>`},callout:(r,i,o,s)=>{let l={type:"blockquote",children:[{type:"paragraph",children:[{type:"text",value:l0({calloutType:r.calloutType,fold:r.fold||"",title:r.title||""})}]},...r.children||[]]},c=o.enter("blockquote"),u=o.createTracker(s);u.move("> "),u.shift(2);let f=o.indentLines(o.containerFlow(l,u.current()),(d,p,h)=>`>${h?"":" "}${d}`);return c(),f}}}),r=>c0(r)})),u0=ce("wiki_link",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="wiki_link"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"wiki_link","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-wikilink weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="wikiLink",runner:(t,e,n)=>{t.addNode(n,{raw:e.raw,target:e.target,label:e.label})}},toMarkdown:{match:t=>t.type.name==="wiki_link",runner:(t,e)=>t.addNode("wikiLink",void 0,void 0,e.attrs)}})),f0=ce("embed",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="embed"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"embed","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-embed-note weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="embed",runner:(t,e,n)=>t.addNode(n,{raw:e.raw,target:e.target,label:e.label})},toMarkdown:{match:t=>t.type.name==="embed",runner:(t,e)=>t.addNode("embed",void 0,void 0,e.attrs)}})),d0=ce("inline_footnote",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{value:{default:""}},parseDOM:[{tag:'span[data-type="inline_footnote"]',getAttrs:t=>t instanceof HTMLElement?{value:t.dataset.value||""}:!1}],toDOM:t=>["span",{"data-type":"inline_footnote","data-value":t.attrs.value,class:"weibei-inline-footnote weibei-structured-node"},t.attrs.value],parseMarkdown:{match:t=>t.type==="inlineFootnote",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="inline_footnote",runner:(t,e)=>t.addNode("inlineFootnote",void 0,void 0,{value:e.attrs.value})}})),_O=ge(t=>hi(/!\[\[([^\]\n]+)\]\]$/,f0.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),HO=ge(t=>hi(/(?<!!)\[\[([^\]\n]+)\]\]$/,u0.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),WO=ge(t=>hi(/\^\[([^\]\n]+)\]$/,d0.type(t),{getAttr:e=>({value:e[1]||""})})),p0=Lt("highlight",()=>({parseDOM:[{tag:"mark.weibei-highlight"}],toDOM:()=>["mark",{class:"weibei-highlight"},0],parseMarkdown:{match:t=>t.type==="highlight",runner:(t,e,n)=>t.openMark(n).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="highlight",runner:(t,e)=>{t.withMark(e,"highlight")}}})),jO=Lt("writing_font",()=>({attrs:{font:{default:"serif"}},excludes:"writing_font",priority:10,parseDOM:[{tag:"span[data-weibei-font]",getAttrs:t=>{let e=t instanceof HTMLElement?t.dataset.weibeiFont:"";return e&&hp.has(e)?{font:e}:!1}}],toDOM:t=>["span",{"data-weibei-font":hp.has(t.attrs.font)?t.attrs.font:"serif"},0],parseMarkdown:{match:t=>t.type==="writingFont",runner:(t,e,n)=>t.openMark(n,{font:e.font}).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="writing_font",runner:(t,e)=>{t.withMark(e,"writingFont",void 0,{font:e.attrs.font})}}})),VO=ge(t=>an(/(?:^|[^\\=])==([^=\n]+)==$/,p0.type(t))),qO=ce("callout",()=>({content:"block+",group:"block",defining:!0,selectable:!0,attrs:{calloutType:{default:"note"},title:{default:""},fold:{default:""}},parseDOM:[{tag:'blockquote[data-type="callout"]',getAttrs:t=>t instanceof HTMLElement?{calloutType:t.dataset.callout||"note",title:t.dataset.calloutTitle||"",fold:t.dataset.calloutFold||""}:!1}],toDOM:t=>["blockquote",{"data-type":"callout","data-callout":t.attrs.calloutType,"data-callout-title":t.attrs.title,"data-callout-fold":t.attrs.fold,class:`weibei-callout weibei-callout-${t.attrs.calloutType}`},0],parseMarkdown:{match:t=>t.type==="callout",runner:(t,e,n)=>t.openNode(n,{calloutType:e.calloutType,title:e.title,fold:e.fold}).next(e.children).closeNode()},toMarkdown:{match:t=>t.type.name==="callout",runner:(t,e)=>{t.openNode("callout",void 0,e.attrs).next(e.content).closeNode()}}})),h0=[$O,u0,f0,d0,jO,p0,VO,qO,_O,HO,WO].flat();var z0=window.webkit?.messageHandlers,st=window.weiBeiEditorCheckMode?Qw():null,K,to="",Dl=null,xs=null,Nl=!1,Qt=null,Ui={text:null,rectKey:null,detailKey:null},vs="",ie=window.weiBeiMarkdownEditable!==!1,Ll=window.weiBeiMarkdownCompactPreview===!0,tt=window.weiBeiDocumentID||"",je=window.weiBeiDocumentGeneration||0,Mn={revision:0,dirty:!1},Cp=!1,$0=!1,Sp=0,_0=window.weiBeiMarkdownBaseURL||"",UO=window.weiBeiLocalImageScheme||"weibeiimage",Dp=0,JO=0,m0=0,Ji=0,Jn=new Map,zt=new Map,H0=Lw("WEIBEI_BLOCK_COMMAND"),GO=ge(t=>hi(Gw,up.type(t),{beforeDispatch:({tr:e,match:n,start:r})=>e.insertText(n[1]||"",r+1)})),XO=[Hw,up,Tl,Ww,GO].flat(),Gn=0,yt=null,Cn=null,Bl=null,Mp=[],Yi=0,g0="{{WEIBEI_CURSOR}}",mp="{{WEIBEI_SELECT_START}}",y0="{{WEIBEI_SELECT_END}}",gp=new Set(["note","tip","important","warning","caution","summary","abstract","quote","question","example","info","success","failure","danger","bug","todo"]);var W0=t=>t==="en"?"en":"zh-Hans",Kr=W0(window.weiBeiInterfaceLanguage),k0={"zh-Hans":{note:"\u672D\u8BB0",tip:"\u63D0\u793A",important:"\u91CD\u70B9",warning:"\u7559\u5FC3",caution:"\u8C28\u614E",summary:"\u63D0\u8981",abstract:"\u6458\u8981",quote:"\u5F15\u6587",question:"\u95EE\u9898",example:"\u4F8B\u5B50",info:"\u4FE1\u606F",success:"\u53EF\u884C",failure:"\u5931\u8D25",danger:"\u98CE\u9669",bug:"\u95EE\u9898",todo:"\u5F85\u529E"},en:{note:"Note",tip:"Tip",important:"Important",warning:"Warning",caution:"Caution",summary:"Summary",abstract:"Abstract",quote:"Quote",question:"Question",example:"Example",info:"Info",success:"Success",failure:"Failure",danger:"Danger",bug:"Bug",todo:"Todo"}},b0=t=>k0[Kr]?.[t]||k0["zh-Hans"][t]||t,Rl={"zh-Hans":{properties:"\u5C5E\u6027",bootFailed:"Milkdown \u521D\u59CB\u5316\u5931\u8D25",imageMissing:"\u56FE\u7247\u672A\u627E\u5230",inlineFootnote:"\u884C\u5185\u811A\u6CE8\uFF1A{value}",openOrCreateNote:"\u6253\u5F00\u6216\u521B\u5EFA\u7B14\u8BB0\uFF1A{value}",openSource:"\u6253\u5F00\u6765\u6E90\uFF1A{value}",embed:"\u5D4C\u5165\uFF1A{value}",mermaidRendering:"\u6B63\u5728\u6E32\u67D3 Mermaid \u56FE\u8868...",mermaidFailed:`Mermaid \u56FE\u8868\u672A\u89E3\u6790 +${r}`:r};var Zw=["transactions","fullSerializations","bridgeMessages","bridgeBytes","decorationNodes","decorationCacheHits","katexRenders","mermaidRenders","imageScans","imageNodeUpdates","codeTokenizations","outlineReports"],e0=()=>Object.fromEntries(Zw.map(t=>[t,0])),At=(t,e,n=1)=>{t&&(t[e]+=n)},t0=t=>{if(t)for(let e of Zw)t[e]=0};var n0=t=>JSON.stringify(t.map(({level:e,title:n})=>[e,n]));var BO=["loadDocument","requestSnapshot","setTheme","setLanguage","setEditable","focus","scrollToHeading","applyMarkdownFragment","replaceSelection","executeSelectionCommand","insertStructuredBlock","restoreCheckpoint"],r0=t=>Number.isInteger(t)&&Number(t)>=0,pp=t=>typeof t=="string"&&t.length>0,i0=t=>{if(!t||typeof t!="object")return null;let e=t;return e.protocolVersion!==2||!pp(e.commandID)||typeof e.documentID!="string"||!r0(e.documentGeneration)||!BO.includes(e.type)||!e.payload||typeof e.payload!="object"||Array.isArray(e.payload)||e.minimumRevision!==void 0&&!r0(e.minimumRevision)||e.requestID!==void 0&&!pp(e.requestID)||e.type==="requestSnapshot"&&!pp(e.requestID)?null:e},o0=(t,e)=>t.type==="loadDocument"?t.documentGeneration>e.documentGeneration||t.documentGeneration===e.documentGeneration&&(!e.documentID||t.documentID===e.documentID):t.documentID===e.documentID&&t.documentGeneration===e.documentGeneration&&(t.minimumRevision===void 0||t.minimumRevision<=e.revision),s0=(t,e)=>e?{revision:t.revision+1,dirty:!0,changed:!0}:{...t,changed:!1},a0=(t,e)=>({...e,protocolVersion:2,documentID:t.documentID,documentGeneration:t.documentGeneration,revision:t.revision});var PO=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},l0=t=>{let e=[],n=/!\[\[([^\]\n]+)\]\]|\[\[([^\]\n]+)\]\]|==([^=\n]+)==|\^\[([^\]\n]+)\]/g,r=0;for(let i of t.matchAll(n)){let o=i.index||0;if(PO(t,o))continue;o>r&&e.push({type:"text",value:t.slice(r,o)});let s=i[1]??i[2];if(s!==void 0){let a=s.indexOf("|"),l=(a<0?s:s.slice(0,a)).trim(),c=(a<0?"":s.slice(a+1)).trim();e.push({type:i[1]===void 0?"wikiLink":"embed",raw:s,target:l,label:c})}else i[3]!==void 0?e.push({type:"highlight",value:i[3]}):e.push({type:"inlineFootnote",value:i[4]});r=o+i[0].length}return r<t.length&&e.push({type:"text",value:t.slice(r)}),e.length?e:[{type:"text",value:t}]};var c0=t=>{let e=t.match(/^\[!([A-Za-z][A-Za-z0-9_-]*)\]([+-]?)(?:[ \t]+(.+))?$/);return e?{calloutType:e[1].toLowerCase(),fold:e[2]||"",title:(e[3]||"").trim()}:null},u0=t=>`[!${t.calloutType}]${t.fold}${t.title?` ${t.title}`:""}`;var hp=new Set(["system","serif","literary"]),FO=t=>{let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],i=r.type==="html"?String(r.value||"").match(/^<span data-weibei-font="(system|serif|literary)">$/):null;if(!i){e.push(r);continue}let o=t.findIndex((s,a)=>a>n&&s.type==="html"&&String(s.value||"")==="</span>");if(o<0){e.push(r);continue}e.push({type:"writingFont",font:i[1],children:t.slice(n+1,o)}),n=o}return e},zO=t=>t.type==="text"?{type:"text",value:t.value}:t.type==="highlight"?{type:"highlight",children:[{type:"text",value:t.value}]}:t.type==="inlineFootnote"?{type:"inlineFootnote",value:t.value}:{type:t.type,raw:t.raw,target:t.target,label:t.label},f0=t=>{if(!t.children||["code","inlineCode","html"].includes(t.type))return;if(t.type==="blockquote"){let n=t.children[0],r=n?.type==="paragraph"&&n.children?.length===1&&n.children[0].type==="text"?String(n.children[0].value||""):"",i=c0(r);if(i){t.type="callout",t.calloutType=i.calloutType,t.fold=i.fold,t.title=i.title,t.children=t.children.slice(1),t.children.length===0&&t.children.push({type:"paragraph",children:[]});let o=t.children[0]?.type==="paragraph"?t.children[0].children?.[0]:null;o?.type==="text"&&(o.value=String(o.value||"").replace(/^\[![A-Za-z][A-Za-z0-9_-]*\][+-]?[ \t]*/,""))}}let e=t.children.flatMap(n=>n.type!=="text"?(f0(n),[n]):l0(String(n.value||"")).map(zO));t.children=FO(e)},$O=ht("weiBeiStructuredMarkdown",()=>(function(){let e=this.data();return(e.toMarkdownExtensions||(e.toMarkdownExtensions=[])).push({handlers:{wikiLink:(r,i,o,s)=>`[[${o.safe(r.raw,{...s,before:"[[",after:"]]"})}]]`,embed:(r,i,o,s)=>`![[${o.safe(r.raw,{...s,before:"![[",after:"]]"})}]]`,inlineFootnote:(r,i,o,s)=>`^[${o.safe(r.value,{...s,before:"^[",after:"]"})}]`,highlight:(r,i,o,s)=>`==${o.containerPhrasing(r,{...s,before:"==",after:"=="})}==`,writingFont:(r,i,o,s)=>{let a=hp.has(r.font)?r.font:"serif",l=o.containerPhrasing(r,{...s,before:">",after:"<"});return`<span data-weibei-font="${a}">${l}</span>`},callout:(r,i,o,s)=>{let l={type:"blockquote",children:[{type:"paragraph",children:[{type:"text",value:u0({calloutType:r.calloutType,fold:r.fold||"",title:r.title||""})}]},...r.children||[]]},c=o.enter("blockquote"),u=o.createTracker(s);u.move("> "),u.shift(2);let f=o.indentLines(o.containerFlow(l,u.current()),(d,p,h)=>`>${h?"":" "}${d}`);return c(),f}}}),r=>f0(r)})),d0=ce("wiki_link",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="wiki_link"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"wiki_link","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-wikilink weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="wikiLink",runner:(t,e,n)=>{t.addNode(n,{raw:e.raw,target:e.target,label:e.label})}},toMarkdown:{match:t=>t.type.name==="wiki_link",runner:(t,e)=>t.addNode("wikiLink",void 0,void 0,e.attrs)}})),p0=ce("embed",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="embed"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"embed","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-embed-note weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="embed",runner:(t,e,n)=>t.addNode(n,{raw:e.raw,target:e.target,label:e.label})},toMarkdown:{match:t=>t.type.name==="embed",runner:(t,e)=>t.addNode("embed",void 0,void 0,e.attrs)}})),h0=ce("inline_footnote",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{value:{default:""}},parseDOM:[{tag:'span[data-type="inline_footnote"]',getAttrs:t=>t instanceof HTMLElement?{value:t.dataset.value||""}:!1}],toDOM:t=>["span",{"data-type":"inline_footnote","data-value":t.attrs.value,class:"weibei-inline-footnote weibei-structured-node"},t.attrs.value],parseMarkdown:{match:t=>t.type==="inlineFootnote",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="inline_footnote",runner:(t,e)=>t.addNode("inlineFootnote",void 0,void 0,{value:e.attrs.value})}})),_O=ge(t=>hi(/!\[\[([^\]\n]+)\]\]$/,p0.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),HO=ge(t=>hi(/(?<!!)\[\[([^\]\n]+)\]\]$/,d0.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),WO=ge(t=>hi(/\^\[([^\]\n]+)\]$/,h0.type(t),{getAttr:e=>({value:e[1]||""})})),m0=Lt("highlight",()=>({parseDOM:[{tag:"mark.weibei-highlight"}],toDOM:()=>["mark",{class:"weibei-highlight"},0],parseMarkdown:{match:t=>t.type==="highlight",runner:(t,e,n)=>t.openMark(n).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="highlight",runner:(t,e)=>{t.withMark(e,"highlight")}}})),jO=Lt("writing_font",()=>({attrs:{font:{default:"serif"}},excludes:"writing_font",priority:10,parseDOM:[{tag:"span[data-weibei-font]",getAttrs:t=>{let e=t instanceof HTMLElement?t.dataset.weibeiFont:"";return e&&hp.has(e)?{font:e}:!1}}],toDOM:t=>["span",{"data-weibei-font":hp.has(t.attrs.font)?t.attrs.font:"serif"},0],parseMarkdown:{match:t=>t.type==="writingFont",runner:(t,e,n)=>t.openMark(n,{font:e.font}).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="writing_font",runner:(t,e)=>{t.withMark(e,"writingFont",void 0,{font:e.attrs.font})}}})),VO=ge(t=>an(/(?:^|[^\\=])==([^=\n]+)==$/,m0.type(t))),qO=ce("callout",()=>({content:"block+",group:"block",defining:!0,selectable:!0,attrs:{calloutType:{default:"note"},title:{default:""},fold:{default:""}},parseDOM:[{tag:'blockquote[data-type="callout"]',getAttrs:t=>t instanceof HTMLElement?{calloutType:t.dataset.callout||"note",title:t.dataset.calloutTitle||"",fold:t.dataset.calloutFold||""}:!1}],toDOM:t=>["blockquote",{"data-type":"callout","data-callout":t.attrs.calloutType,"data-callout-title":t.attrs.title,"data-callout-fold":t.attrs.fold,class:`weibei-callout weibei-callout-${t.attrs.calloutType}`},0],parseMarkdown:{match:t=>t.type==="callout",runner:(t,e,n)=>t.openNode(n,{calloutType:e.calloutType,title:e.title,fold:e.fold}).next(e.children).closeNode()},toMarkdown:{match:t=>t.type.name==="callout",runner:(t,e)=>{t.openNode("callout",void 0,e.attrs).next(e.content).closeNode()}}})),g0=[$O,d0,p0,h0,jO,m0,VO,qO,_O,HO,WO].flat();var $0=window.webkit?.messageHandlers,st=window.weiBeiEditorCheckMode?e0():null,K,to="",Dl=null,xs=null,Nl=!1,Qt=null,Ui={text:null,rectKey:null,detailKey:null},vs="",ie=window.weiBeiMarkdownEditable!==!1,Ll=window.weiBeiMarkdownCompactPreview===!0,tt=window.weiBeiDocumentID||"",je=window.weiBeiDocumentGeneration||0,Mn={revision:0,dirty:!1},Cp=!1,_0=!1,Sp=0,H0=window.weiBeiMarkdownBaseURL||"",UO=window.weiBeiLocalImageScheme||"weibeiimage",Lp=0,JO=0,y0=0,Ji=0,Jn=new Map,zt=new Map,W0=Pw("WEIBEI_BLOCK_COMMAND"),GO=ge(t=>hi(Yw,up.type(t),{beforeDispatch:({tr:e,match:n,start:r})=>e.insertText(n[1]||"",r+1)})),XO=[jw,up,Tl,Vw,GO].flat(),Gn=0,yt=null,Cn=null,Bl=null,Mp=[],Yi=0,k0="{{WEIBEI_CURSOR}}",mp="{{WEIBEI_SELECT_START}}",b0="{{WEIBEI_SELECT_END}}",gp=new Set(["note","tip","important","warning","caution","summary","abstract","quote","question","example","info","success","failure","danger","bug","todo"]);var j0=t=>t==="en"?"en":"zh-Hans",Kr=j0(window.weiBeiInterfaceLanguage),x0={"zh-Hans":{note:"\u672D\u8BB0",tip:"\u63D0\u793A",important:"\u91CD\u70B9",warning:"\u7559\u5FC3",caution:"\u8C28\u614E",summary:"\u63D0\u8981",abstract:"\u6458\u8981",quote:"\u5F15\u6587",question:"\u95EE\u9898",example:"\u4F8B\u5B50",info:"\u4FE1\u606F",success:"\u53EF\u884C",failure:"\u5931\u8D25",danger:"\u98CE\u9669",bug:"\u95EE\u9898",todo:"\u5F85\u529E"},en:{note:"Note",tip:"Tip",important:"Important",warning:"Warning",caution:"Caution",summary:"Summary",abstract:"Abstract",quote:"Quote",question:"Question",example:"Example",info:"Info",success:"Success",failure:"Failure",danger:"Danger",bug:"Bug",todo:"Todo"}},w0=t=>x0[Kr]?.[t]||x0["zh-Hans"][t]||t,Rl={"zh-Hans":{properties:"\u5C5E\u6027",bootFailed:"Milkdown \u521D\u59CB\u5316\u5931\u8D25",imageMissing:"\u56FE\u7247\u672A\u627E\u5230",inlineFootnote:"\u884C\u5185\u811A\u6CE8\uFF1A{value}",openOrCreateNote:"\u6253\u5F00\u6216\u521B\u5EFA\u7B14\u8BB0\uFF1A{value}",openSource:"\u6253\u5F00\u6765\u6E90\uFF1A{value}",embed:"\u5D4C\u5165\uFF1A{value}",mermaidRendering:"\u6B63\u5728\u6E32\u67D3 Mermaid \u56FE\u8868...",mermaidFailed:`Mermaid \u56FE\u8868\u672A\u89E3\u6790 {value}`,uploadingImage:"\u6B63\u5728\u6536\u7EB3\u56FE\u7247...",emptyNotePlaceholder:"\u4ECE\u8FD9\u91CC\u5F00\u59CB\u5199\u4E0B\u7B2C\u4E00\u53E5\u2026",slashNoResults:"\u6CA1\u6709\u5339\u914D\u547D\u4EE4",slashStructure:"\u7ED3\u6784",slashLists:"\u5217\u8868",slashContent:"\u5185\u5BB9",slashRichContent:"\u4E30\u5BCC\u5185\u5BB9",slashFonts:"\u5B57\u4F53",slashHeading1:"\u4E00\u7EA7\u6807\u9898",slashHeading2:"\u4E8C\u7EA7\u6807\u9898",slashHeading3:"\u4E09\u7EA7\u6807\u9898",slashHeading4:"\u56DB\u7EA7\u6807\u9898",slashHeading5:"\u4E94\u7EA7\u6807\u9898",slashHeading6:"\u516D\u7EA7\u6807\u9898",slashBulletList:"\u65E0\u5E8F\u5217\u8868",slashOrderedList:"\u6709\u5E8F\u5217\u8868",slashTaskList:"\u5F85\u529E\u5217\u8868",slashQuote:"\u5F15\u7528",slashCallout:"\u63D0\u793A\u5757",slashCode:"\u4EE3\u7801\u5757",slashDivider:"\u5206\u9694\u7EBF",slashTable:"\u8868\u683C",slashImage:"\u56FE\u7247",slashMermaid:"Mermaid \u56FE\u8868",slashLink:"\u94FE\u63A5",slashWikiLink:"\u7B14\u8BB0\u94FE\u63A5",slashFootnote:"\u811A\u6CE8",slashInlineMath:"\u884C\u5185\u516C\u5F0F",slashBlockMath:"\u5757\u7EA7\u516C\u5F0F",slashFontSystem:"\u5B57\u4F53\uFF1ASF Pro / PingFang SC",slashFontSerif:"\u5B57\u4F53\uFF1ASongti SC",slashFontLiterary:"\u5B57\u4F53\uFF1AWeiBeiStele",slashRows:"\u884C",slashColumns:"\u5217",slashInsertTable:"\u63D2\u5165\u8868\u683C",slashImageFailed:"\u56FE\u7247\u8BFB\u53D6\u6216\u4FDD\u5B58\u5931\u8D25",tableAddRow:"\uFF0B\u884C",tableDeleteRow:"\u2212\u884C",tableAddColumn:"\uFF0B\u5217",tableDeleteColumn:"\u2212\u5217",tableHeader:"\u8868\u5934",linkPlaceholder:"\u94FE\u63A5\u6587\u5B57",wikiLinkPlaceholder:"\u7B14\u8BB0\u6807\u9898",footnotePlaceholder:"\u811A\u6CE8\u5185\u5BB9",codeLanguage:"\u4EE3\u7801\u8BED\u8A00",codeLanguagePlaceholder:"text"},en:{properties:"Properties",bootFailed:"Milkdown failed to initialize",imageMissing:"Image not found",inlineFootnote:"Inline footnote: {value}",openOrCreateNote:"Open or create note: {value}",openSource:"Open source: {value}",embed:"Embed: {value}",mermaidRendering:"Rendering Mermaid diagram...",mermaidFailed:`Mermaid diagram did not parse -{value}`,uploadingImage:"Saving image...",emptyNotePlaceholder:"Start writing here\u2026",slashNoResults:"No matching commands",slashStructure:"Structure",slashLists:"Lists",slashContent:"Content",slashRichContent:"Rich content",slashFonts:"Fonts",slashHeading1:"Heading 1",slashHeading2:"Heading 2",slashHeading3:"Heading 3",slashHeading4:"Heading 4",slashHeading5:"Heading 5",slashHeading6:"Heading 6",slashBulletList:"Bulleted list",slashOrderedList:"Numbered list",slashTaskList:"To-do list",slashQuote:"Quote",slashCallout:"Callout",slashCode:"Code block",slashDivider:"Divider",slashTable:"Table",slashImage:"Image",slashMermaid:"Mermaid diagram",slashLink:"Link",slashWikiLink:"Note link",slashFootnote:"Footnote",slashInlineMath:"Inline formula",slashBlockMath:"Block formula",slashFontSystem:"Font: SF Pro / PingFang SC",slashFontSerif:"Font: Songti SC",slashFontLiterary:"Font: WeiBeiStele",slashRows:"Rows",slashColumns:"Columns",slashInsertTable:"Insert table",slashImageFailed:"Image could not be read or saved",tableAddRow:"+ Row",tableDeleteRow:"\u2212 Row",tableAddColumn:"+ Column",tableDeleteColumn:"\u2212 Column",tableHeader:"Header",linkPlaceholder:"Link text",wikiLinkPlaceholder:"Note title",footnotePlaceholder:"Footnote",codeLanguage:"Code language",codeLanguagePlaceholder:"text"}},ue=(t,e={})=>{let n=Rl[Kr]?.[t]||Rl["zh-Hans"][t]||t;for(let[r,i]of Object.entries(e))n=n.split(`{${r}}`).join(String(i));return n},YO=()=>ue("properties"),QO=new RegExp(`(^|\\n)\\s*(?:>\\s*)*\\\\?\\[!(?:${dp})\\][+-]?[ \\t]*`,"gi"),ZO=/<br\s*\/?>/gi,j0=t=>String(t||"").replace(ZO,` -`).replace(/%%[\s\S]*?%%\n?/g,"").replace(/!\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=xD(n);return r.label||r.target}).replace(/\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=r1(n);return r.display||r.target}).replace(/!\[([^\]\n]*)\]\([^\)\n]+\)/g,(e,n)=>Ol(n).alt||"").replace(/\[([^\]\n]+)\]\([^\)\n]+\)/g,"$1").replace(/==([^=\n]+)==/g,"$1").replace(/~~([^~\n]+)~~/g,"$1").replace(/`([^`\n]+)`/g,"$1").replace(/\^\[([^\]\n]+)\]/g,"$1").replace(QO,"$1").replace(/(^|\n)\s*>\s?/g,"$1").replace(/(^|\n)\s*[-*+]\s+\[[ xX]\]\s*/g,"$1").replace(/[ \t]+\n/g,` +{value}`,uploadingImage:"Saving image...",emptyNotePlaceholder:"Start writing here\u2026",slashNoResults:"No matching commands",slashStructure:"Structure",slashLists:"Lists",slashContent:"Content",slashRichContent:"Rich content",slashFonts:"Fonts",slashHeading1:"Heading 1",slashHeading2:"Heading 2",slashHeading3:"Heading 3",slashHeading4:"Heading 4",slashHeading5:"Heading 5",slashHeading6:"Heading 6",slashBulletList:"Bulleted list",slashOrderedList:"Numbered list",slashTaskList:"To-do list",slashQuote:"Quote",slashCallout:"Callout",slashCode:"Code block",slashDivider:"Divider",slashTable:"Table",slashImage:"Image",slashMermaid:"Mermaid diagram",slashLink:"Link",slashWikiLink:"Note link",slashFootnote:"Footnote",slashInlineMath:"Inline formula",slashBlockMath:"Block formula",slashFontSystem:"Font: SF Pro / PingFang SC",slashFontSerif:"Font: Songti SC",slashFontLiterary:"Font: WeiBeiStele",slashRows:"Rows",slashColumns:"Columns",slashInsertTable:"Insert table",slashImageFailed:"Image could not be read or saved",tableAddRow:"+ Row",tableDeleteRow:"\u2212 Row",tableAddColumn:"+ Column",tableDeleteColumn:"\u2212 Column",tableHeader:"Header",linkPlaceholder:"Link text",wikiLinkPlaceholder:"Note title",footnotePlaceholder:"Footnote",codeLanguage:"Code language",codeLanguagePlaceholder:"text"}},ue=(t,e={})=>{let n=Rl[Kr]?.[t]||Rl["zh-Hans"][t]||t;for(let[r,i]of Object.entries(e))n=n.split(`{${r}}`).join(String(i));return n},YO=()=>ue("properties"),QO=new RegExp(`(^|\\n)\\s*(?:>\\s*)*\\\\?\\[!(?:${dp})\\][+-]?[ \\t]*`,"gi"),ZO=/<br\s*\/?>/gi,V0=t=>String(t||"").replace(ZO,` +`).replace(/%%[\s\S]*?%%\n?/g,"").replace(/!\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=xD(n);return r.label||r.target}).replace(/\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=i1(n);return r.display||r.target}).replace(/!\[([^\]\n]*)\]\([^\)\n]+\)/g,(e,n)=>Ol(n).alt||"").replace(/\[([^\]\n]+)\]\([^\)\n]+\)/g,"$1").replace(/==([^=\n]+)==/g,"$1").replace(/~~([^~\n]+)~~/g,"$1").replace(/`([^`\n]+)`/g,"$1").replace(/\^\[([^\]\n]+)\]/g,"$1").replace(QO,"$1").replace(/(^|\n)\s*>\s?/g,"$1").replace(/(^|\n)\s*[-*+]\s+\[[ xX]\]\s*/g,"$1").replace(/[ \t]+\n/g,` `).replace(/\n{2,}/g,` -`).trim(),V0=t=>t==="glassLight"||t==="glassMist"?"xuan":t==="glassDark"||t==="glassSlate"?"stele":t==="xuan"||t==="inkstone"||t==="stele"||t==="paper"?t:"paper",eD=t=>["glassLight","glassDark","glassMist","glassSlate"].includes(t)?t:"",Gi=V0(window.weiBeiTheme),tD=()=>{switch(Gi){case"inkstone":return{background:"#151515",primaryColor:"#1c1c1c",primaryTextColor:"#d7cbb0",primaryBorderColor:"#3a3328",lineColor:"#8b5e3c",secondaryColor:"#222222",tertiaryColor:"#171717",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"stele":return{background:"#1e2228",primaryColor:"#252a32",primaryTextColor:"#d2d6dc",primaryBorderColor:"#3a414c",lineColor:"#8a7a5c",secondaryColor:"#2a3038",tertiaryColor:"#1a1e24",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"xuan":return{background:"#f7f4ef",primaryColor:"#fcfbf8",primaryTextColor:"#25231f",primaryBorderColor:"#d8d2c6",lineColor:"#6e634f",secondaryColor:"#ebe6dc",tertiaryColor:"#f7f4ef",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};default:return{background:"#fbf5e8",primaryColor:"#f6eddc",primaryTextColor:"#2e261f",primaryBorderColor:"#cbb79b",lineColor:"#7a6250",secondaryColor:"#efe4d2",tertiaryColor:"#f8f0e1",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'}}},nD=t=>{t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:tD()})},q0=t=>{Gi=V0(t);let e=eD(t);document.documentElement.dataset.weibeiTheme=Gi,document.body&&(document.body.dataset.weibeiTheme=Gi),e?(document.documentElement.dataset.weibeiGlass=e,document.body&&(document.body.dataset.weibeiGlass=e)):(delete document.documentElement.dataset.weibeiGlass,document.body&&delete document.body.dataset.weibeiGlass),Ji+=1};q0(window.weiBeiTheme);var Qi=t=>{if(window.WeiBeiEditorBootFailed){window.WeiBeiEditorBootFailed(t);return}let e=document.querySelector("#editor");e&&(e.innerHTML=`<pre style="white-space:pre-wrap;color:#9f3427;padding:24px;font:13px/1.5 SFMono-Regular,Menlo,monospace;">${ue("bootFailed")} -${String(t?.stack||t)}</pre>`)};window.addEventListener("error",t=>Qi(t.error||t.message));window.addEventListener("unhandledrejection",t=>Qi(t.reason));var Le=(t,e={})=>{let n=z0?.[t];if(!n)return;let r=o0({documentID:tt,documentGeneration:je,revision:Mn.revision},e);typeof r.markdown=="string"&&(Sp+=1),At(st,"bridgeMessages"),st&&At(st,"bridgeBytes",new TextEncoder().encode(JSON.stringify(r)).byteLength),n.postMessage(r)},G=document.createElement("div"),Ur=document.createElement("div"),ot=document.createElement("button"),Se=document.createElement("div");G.className="weibei-slash-menu",G.dataset.show="false",G.dataset.state="closed",G.setAttribute("role","listbox"),G.setAttribute("aria-label","Slash commands"),Ur.className="weibei-visually-hidden",Ur.setAttribute("role","status"),Ur.setAttribute("aria-live","polite"),ot.type="button",ot.className="weibei-line-plus",ot.textContent="\uFF0B",ot.setAttribute("aria-label","\u63D2\u5165\u5185\u5BB9"),ot.hidden=!0,Se.className="weibei-table-toolbar",Se.dataset.state="closed",Se.setAttribute("aria-hidden","true"),Se.setAttribute("role","toolbar");for(let[t,e]of[["addRow","tableAddRow"],["deleteRow","tableDeleteRow"],["addColumn","tableAddColumn"],["deleteColumn","tableDeleteColumn"],["header","tableHeader"]]){let n=document.createElement("button");n.type="button",n.dataset.action=t,n.dataset.label=e,Se.append(n)}var Cs=null,rD=[{id:"structure",label:"slashStructure"},{id:"lists",label:"slashLists"},{id:"content",label:"slashContent"},{id:"rich",label:"slashRichContent"},{id:"fonts",label:"slashFonts"}],iD=[{id:"heading1",group:"structure",label:"slashHeading1",aliases:["h1","heading_1","yjbt","yijibiaoti","\u4E00\u7EA7","\u6807\u98981"]},{id:"heading2",group:"structure",label:"slashHeading2",aliases:["h2","heading_2","ejbt","erjibiaoti","\u4E8C\u7EA7","\u6807\u98982"]},{id:"heading3",group:"structure",label:"slashHeading3",aliases:["h3","heading_3","sjbt","sanjibiaoti","\u4E09\u7EA7","\u6807\u98983"]},{id:"heading4",group:"structure",label:"slashHeading4",aliases:["h4","heading_4","sijbt","sijibiaoti","\u56DB\u7EA7","\u6807\u98984"]},{id:"heading5",group:"structure",label:"slashHeading5",aliases:["h5","heading_5","wjbt","wujibiaoti","\u4E94\u7EA7","\u6807\u98985"]},{id:"heading6",group:"structure",label:"slashHeading6",aliases:["h6","heading_6","ljbt","liujibiaoti","\u516D\u7EA7","\u6807\u98986"]},{id:"bulletList",group:"lists",label:"slashBulletList",aliases:["bullet_list","bullet","ul","wxlb","wuxuliebiao","\u65E0\u5E8F","\u9879\u76EE\u7B26\u53F7"]},{id:"orderedList",group:"lists",label:"slashOrderedList",aliases:["ordered_list","ol","yxlb","youxuliebiao","\u6709\u5E8F","\u7F16\u53F7"]},{id:"taskList",group:"lists",label:"slashTaskList",aliases:["task_list","todo","task","checklist","dblb","daibanliebiao","\u5F85\u529E","\u4EFB\u52A1"]},{id:"quote",group:"lists",label:"slashQuote",aliases:["quote","blockquote","yy","yinyong","\u5F15\u7528"]},{id:"callout",group:"content",label:"slashCallout",aliases:["callout","note","tsk","tishikuai","\u63D0\u793A","\u672D\u8BB0"]},{id:"code",group:"content",label:"slashCode",aliases:["code","code_block","dmk","daimakuai","\u4EE3\u7801"]},{id:"divider",group:"content",label:"slashDivider",aliases:["divider","horizontal_rule","hr","fgx","fengexian","\u5206\u9694","\u6A2A\u7EBF"]},{id:"link",group:"content",label:"slashLink",aliases:["link","url","lj","lianjie","\u94FE\u63A5","\u7F51\u5740"]},{id:"wikiLink",group:"content",label:"slashWikiLink",aliases:["wiki","note_link","bjl","bijilianjie","\u7B14\u8BB0","\u53CC\u94FE"]},{id:"footnote",group:"content",label:"slashFootnote",aliases:["footnote","note_ref","jz","jiaozhu","\u811A\u6CE8","\u6CE8\u91CA"]},{id:"table",group:"rich",label:"slashTable",aliases:["table","grid","bg","biaoge","\u8868\u683C"]},{id:"image",group:"rich",label:"slashImage",aliases:["image","photo","picture","tp","tupian","\u56FE\u7247","\u7167\u7247"]},{id:"mermaid",group:"rich",label:"slashMermaid",aliases:["mermaid","diagram","flowchart","lct","liuchengtu","\u56FE\u8868","\u6D41\u7A0B\u56FE"]},{id:"inlineMath",group:"rich",label:"slashInlineMath",aliases:["math","formula","inline_math","hngs","hangneigongshi","\u516C\u5F0F","\u884C\u5185"]},{id:"blockMath",group:"rich",label:"slashBlockMath",aliases:["display_math","equation","block_math","kjgs","kuaijigongshi","\u65B9\u7A0B","\u5757\u7EA7"]},{id:"fontSystem",group:"fonts",label:"slashFontSystem",aliases:["font","system","sf pro","pingfang sc","ziti","\u5B57\u4F53","\u82F9\u65B9"]},{id:"fontSerif",group:"fonts",label:"slashFontSerif",aliases:["font","serif","songti sc","ziti","\u5B57\u4F53","\u5B8B\u4F53"]},{id:"fontLiterary",group:"fonts",label:"slashFontLiterary",aliases:["font","weibeistele","wei bei stele","ziti","\u5B57\u4F53","\u9B4F\u7891"]}],K0=new Set(["system","serif","literary"]),Ep={fontSystem:"system",fontSerif:"serif",fontLiterary:"literary"},I={provider:null,view:null,context:null,commands:[],activeIndex:0,dismissedContext:"",activationContext:"",tableOpen:!1,tableFocus:"rows",tableRows:3,tableColumns:3,tableMenuBaseLeft:"",error:""},U0=new Set(["list_item","task_list_item","table","table_row","table_header_row","table_cell","table_header","code_block","math_block"]),De={state:"closed",generation:0,timer:0,frame:0},Tp=()=>document.documentElement.dataset.weibeiReduceMotion==="true",J0=t=>{document.documentElement.dataset.weibeiReduceMotion=t===!0||t==="true"?"true":"false"},G0=t=>{let e=Number(t),n=Number.isFinite(e)&&e>0?e:1;document.documentElement.style.setProperty("--weibei-text-scale",String(n))},Zi=t=>{if(!ie||t.composing)return null;let{selection:e}=t.state;if(!(e instanceof P)||!e.empty)return null;let{$from:n}=e;if(n.parent.type.name!=="paragraph")return null;for(let u=n.depth;u>0;u-=1)if(U0.has(n.node(u).type.name))return null;let r=n.parent.textBetween(0,n.parentOffset,"\uFFFC","\uFFFC"),i=r.lastIndexOf("/");if(i<0)return null;let o=r.slice(i+1);if(/[\s/]/u.test(o))return null;let s=/^[\u200B\uFEFF]*$/u.test(r.slice(0,i))?0:i,a=n.depth,l=n.before(a),c=n.start(a)+s;return{query:o,parent:n.parent,triggerFrom:c,triggerTo:n.pos,triggerStartOffset:s,triggerEndOffset:n.parentOffset,blockFrom:l,blockTo:n.after(a),index:n.index(a-1),container:n.node(a-1),key:`${c}:${o}`}},X0=t=>{if(!ie||t.composing)return null;let{selection:e}=t.state;if(!(e instanceof P)||!e.empty||e.$from.parent.type.name!=="paragraph"||e.$from.parent.content.size!==0)return null;for(let n=e.$from.depth;n>0;n-=1)if(U0.has(e.$from.node(n).type.name))return null;return e.$from},x0=t=>{let e=X0(t);if(ot.hidden=!e,!e)return;let n=t.coordsAtPos(e.pos);ot.style.left=`${Math.max(6,n.left-30)}px`,ot.style.top=`${Math.max(6,n.top-2)}px`},Lp=(t,e,n={})=>{let r=e.nodes.paragraph;if(!r)return null;if(t.startsWith("heading")){let i=e.nodes.heading;return i?{content:M.from(i.create({level:Number(t.at(-1))})),selectionOffset:1}:null}if(["bulletList","orderedList","taskList"].includes(t)){let i=t==="orderedList"?e.nodes.ordered_list:e.nodes.bullet_list,o=e.nodes.list_item?.createAndFill(t==="taskList"?{checked:!1}:null,r.create()),s=o&&i?.createAndFill(null,o);return s?{content:M.from(s),selectionOffset:3}:null}if(t==="callout"){let o=e.nodes.callout?.create({calloutType:"note",title:"",fold:""},r.create());return o?{content:M.from(o),selectionOffset:2}:null}if(t==="quote"){let i=e.nodes.blockquote||e.nodes.block_quote;if(!i)return null;let o=i.create(null,r.create());return{content:M.from(o),selectionOffset:2}}if(t==="code"||t==="mermaid"){let i=e.nodes.code_block;if(!i)return null;let o=t==="mermaid"?`graph TD - A --> B`:"";return{content:M.from(i.create({language:t==="mermaid"?"mermaid":""},o?e.text(o):null)),selectionOffset:o.length+1}}if(t==="inlineMath"){let o=e.nodes.math_inline?.create(null,e.text("x"));return o?{content:M.from(r.create(null,o)),selectionOffset:1}:null}if(t==="link"){let i=e.marks.link,o=ue("linkPlaceholder"),s=i?r.create(null,e.text(o,[i.create({href:""})])):null;return s?{content:M.from(s),selectionFromOffset:1,selectionToOffset:o.length+1}:null}if(t==="wikiLink"){let i=e.nodes.wiki_link,o=ue("wikiLinkPlaceholder"),s=i?.create({raw:o,target:o,label:""});return s?{content:M.from(r.create(null,s)),selectionOffset:1,activateEvent:"weibei-edit-structured"}:null}if(t==="footnote"){let o=e.nodes.inline_footnote?.create({value:ue("footnotePlaceholder")});return o?{content:M.from(r.create(null,o)),selectionOffset:1,activateEvent:"weibei-edit-structured"}:null}if(t==="blockMath"){let o=e.nodes.math_block?.create({value:"x"});return o?{content:M.from(o),selectionOffset:0}:null}if(t==="divider"){let o=(e.nodes.hr||e.nodes.horizontal_rule)?.create();return o?{content:M.from([o,r.create()]),selectionOffset:o.nodeSize+1}:null}if(t==="table"){let{table:i,table_header_row:o,table_row:s,table_header:a,table_cell:l}=e.nodes,c=Math.min(20,Math.max(1,Number(n.rows)||3)),u=Math.min(12,Math.max(1,Number(n.columns)||3));if(!i||!o||!s||!a||!l)return null;let f=Array.from({length:u},()=>a.createAndFill()),d=Array.from({length:c-1},()=>s.create(null,Array.from({length:u},()=>l.createAndFill())));return f.some(p=>!p)||d.some(p=>!p)?null:{content:M.from(i.create(null,[o.create(null,f),...d])),selectionOffset:4}}if(t==="image"){let i=e.nodes.image;return i&&n.src?{content:M.from(r.create(null,i.create({src:n.src,alt:n.alt||"image"}))),selectionOffset:2}:null}return null},Y0=(t,e)=>{let n=e?.content?.firstChild;if(!t||!n)return null;if(e.content.childCount===1&&n.type===t.parent.type){let a=t.parent.content.cut(0,t.triggerStartOffset).append(n.content).append(t.parent.content.cut(t.triggerEndOffset));return{content:M.from(t.parent.type.create(t.parent.attrs,a,t.parent.marks)),selectionBase:t.triggerFrom-1}}let r=[],i=t.parent.content.cut(0,t.triggerStartOffset),o=t.parent.content.cut(t.triggerEndOffset);i.size&&r.push(t.parent.type.create(t.parent.attrs,i,t.parent.marks));let s=t.blockFrom+r.reduce((a,l)=>a+l.nodeSize,0);return e.content.forEach(a=>r.push(a)),o.size&&r.push(t.parent.type.create(t.parent.attrs,o,t.parent.marks)),{content:M.from(r),selectionBase:s}},oD=(t,e,n)=>{if(!e)return!1;if(Ep[t.id])return!!n.marks.writing_font;if(t.id==="image")return!!n.nodes.image;let r=Lp(t.id,n,{rows:3,columns:3}),i=Y0(e,r);return!!(i&&e.container.canReplace(e.index,e.index+1,i.content))},sD=(t,e,n)=>{let r=String(t||"").toLocaleLowerCase();return iD.filter(i=>oD(i,e,n)&&(!r||[Rl["zh-Hans"][i.label],Rl.en[i.label],...i.aliases].some(o=>String(o).toLocaleLowerCase().includes(r))))},Q0=(t,e,n)=>{if(!e||!n)return!1;let r=t.state.doc.nodeAt(e.blockFrom),i=Y0(e,n);if(!r?.eq(e.parent)||!i||!e.container.canReplace(e.index,e.index+1,i.content))return!1;let o=is(t.state.tr.replaceWith(e.blockFrom,e.blockTo,i.content)),s=n.activateEvent?H.create(o.doc,i.selectionBase+n.selectionOffset):Number.isInteger(n.selectionFromOffset)&&Number.isInteger(n.selectionToOffset)?P.create(o.doc,i.selectionBase+n.selectionFromOffset,i.selectionBase+n.selectionToOffset):_.findFrom(o.doc.resolve(Math.min(i.selectionBase+n.selectionOffset,o.doc.content.size)),1,!0);return s&&o.setSelection(s),t.dispatch(o.scrollIntoView()),I.dismissedContext="",I.provider?.hide(),t.focus(),n.activateEvent&&s&&window.requestAnimationFrame(()=>{t.nodeDOM(s.from)?.dispatchEvent(new CustomEvent(n.activateEvent))}),window.requestAnimationFrame(Xi),!0},aD=(t,e)=>{let n=`image-picker-${Date.now()}-${Dp+=1}`;zt.set(n,{mode:"insert",view:t,context:e,documentID:tt,documentGeneration:je}),I.dismissedContext=e.key,I.provider?.hide(),Le("imagePickerRequested",{id:n})},lD=(t,e,n)=>{let r=t.state.schema.marks.writing_font;if(!r||!K0.has(n))return!1;let i=t.state.storedMarks||t.state.selection.$from.marks(),o=is(t.state.tr.delete(e.triggerFrom,e.triggerTo));return o.setSelection(P.create(o.doc,e.triggerFrom)),o.setStoredMarks([...i.filter(s=>s.type!==r),r.create({font:n})]),t.dispatch(o.scrollIntoView()),I.dismissedContext="",I.provider?.hide(),t.focus(),window.requestAnimationFrame(Xi),!0},Jr=t=>{let e=I.view,n=e&&Zi(e);return!e||!n?!1:t==="image"?(aD(e,n),!0):Ep[t]?lD(e,n,Ep[t]):Q0(e,n,Lp(t,e.state.schema,{rows:I.tableRows,columns:I.tableColumns}))},Bp=()=>{let t=I.view?.dom,e=I.commands[I.activeIndex];if(!t||G.dataset.show!=="true"||!e){t?.removeAttribute("aria-controls"),t?.removeAttribute("aria-expanded"),t?.removeAttribute("aria-activedescendant");return}G.id="weibei-slash-menu",t.setAttribute("aria-controls",G.id),t.setAttribute("aria-expanded","true"),t.setAttribute("aria-activedescendant",`weibei-slash-command-${e.id}`),G.setAttribute("aria-activedescendant",`weibei-slash-command-${e.id}`),Ur.textContent=`${ue(e.label)}\uFF0C${I.activeIndex+1}/${I.commands.length}`},cD=()=>`${Kr}::${I.error?"!":""}::${I.commands.length}::${I.commands.map(t=>t.id).join(",")}`,w0=null,uD=()=>{if(G.replaceChildren(),I.error){let t=document.createElement("div");t.className="weibei-slash-error",t.textContent=I.error,G.appendChild(t)}if(!I.commands.length){let t=document.createElement("div");t.className="weibei-slash-empty",t.textContent=ue("slashNoResults"),G.appendChild(t);return}for(let t of rD){let e=I.commands.filter(i=>i.group===t.id);if(!e.length)continue;let n=document.createElement("section");n.className="weibei-slash-section";let r=document.createElement("div");r.className="weibei-slash-group",r.textContent=ue(t.label),n.appendChild(r);for(let i of e){let o=I.commands.indexOf(i),s=document.createElement("div");s.id=`weibei-slash-command-${i.id}`,s.className=`weibei-slash-command${o===I.activeIndex?" is-active":""}`,s.setAttribute("role","option"),s.setAttribute("aria-selected",String(o===I.activeIndex)),s.setAttribute("aria-posinset",String(o+1)),s.setAttribute("aria-setsize",String(I.commands.length));let a=document.createElement("button");a.type="button",a.tabIndex=-1,a.className="weibei-slash-command-button",a.textContent=ue(i.label),a.addEventListener("pointerdown",l=>l.preventDefault()),a.addEventListener("pointermove",l=>{!Number(l.movementX)&&!Number(l.movementY)||(I.activeIndex=o,I.tableOpen=i.id==="table",Pp(),Sn())}),a.addEventListener("click",()=>{i.id!=="table"&&Jr(i.id)}),s.appendChild(a),n.appendChild(s)}G.appendChild(n)}},Pp=()=>{G.querySelectorAll(".weibei-slash-command").forEach((t,e)=>{t.classList.toggle("is-active",e===I.activeIndex),t.setAttribute("aria-selected",String(e===I.activeIndex))}),G.querySelector(".weibei-slash-command.is-active")?.scrollIntoView({block:"nearest"}),Bp()},vp=null,Z0=()=>{Cs?.remove(),Cs=null,vp=null,I.tableMenuBaseLeft&&(G.style.left=I.tableMenuBaseLeft,I.tableMenuBaseLeft="")},Sn=()=>{let t=G.querySelector("#weibei-slash-command-table .weibei-slash-command-button");if(!I.tableOpen||G.dataset.show!=="true"||!t){Z0();return}let e=vp;if(!e){let f=document.createElement("div");f.className="weibei-slash-table-panel",f.setAttribute("role","group");let d=g=>{let y=g==="rows",x=document.createElement("div");x.className=`weibei-slash-stepper${I.tableFocus===g?" is-focused":""}`;let C=document.createElement("span");C.className="weibei-slash-stepper-label",C.textContent=ue(y?"slashRows":"slashColumns"),x.appendChild(C);let v=()=>y?I.tableRows:I.tableColumns,A=O=>{y?I.tableRows=O:I.tableColumns=O},w=document.createElement("button");w.type="button",w.textContent="\u2212",w.setAttribute("aria-label",`${C.textContent} \u2212`),w.addEventListener("pointerdown",O=>O.preventDefault()),w.addEventListener("click",()=>{A(Math.max(1,v()-1)),I.tableFocus=g,Sn()}),x.appendChild(w);let N=document.createElement("input");N.className="weibei-slash-stepper-input",N.type="number",N.inputMode="numeric",N.min="1",N.max=String(y?20:12),N.step="1",N.setAttribute("aria-label",C.textContent),N.addEventListener("focus",()=>{I.tableFocus=g,f.querySelectorAll(".weibei-slash-stepper.is-focused").forEach(O=>O.classList.remove("is-focused")),x.classList.add("is-focused")}),N.addEventListener("input",()=>{let O=Number.parseInt(N.value,10);Number.isFinite(O)&&A(Math.min(y?20:12,Math.max(1,O)))}),N.addEventListener("change",()=>{let O=Math.min(y?20:12,Math.max(1,Number.parseInt(N.value,10)||1));N.value=String(O),A(O)}),N.addEventListener("keydown",O=>{if(O.stopPropagation(),O.key==="Enter"){let S=Math.min(y?20:12,Math.max(1,Number.parseInt(N.value,10)||1));A(S),Jr("table"),O.preventDefault()}}),x.appendChild(N);let B=document.createElement("button");return B.type="button",B.textContent="+",B.setAttribute("aria-label",`${C.textContent} +`),B.addEventListener("pointerdown",O=>O.preventDefault()),B.addEventListener("click",()=>{A(Math.min(y?20:12,v()+1)),I.tableFocus=g,Sn()}),x.appendChild(B),{stepper:x,input:N,decrement:w,increment:B}},p=d("rows"),h=d("columns"),m=document.createElement("button");m.type="button",m.className="weibei-slash-table-insert",m.textContent=ue("slashInsertTable"),m.addEventListener("pointerdown",g=>g.preventDefault()),m.addEventListener("click",()=>Jr("table")),f.append(p.stepper,h.stepper,m),document.body.appendChild(f),e={panel:f,rowsInput:p.input,rowsDecrement:p.decrement,rowsIncrement:p.increment,rowsStepper:p.stepper,columnsInput:h.input,columnsDecrement:h.decrement,columnsIncrement:h.increment,columnsStepper:h.stepper},Cs=f,vp=e}document.activeElement!==e.rowsInput&&(e.rowsInput.value=String(I.tableRows)),document.activeElement!==e.columnsInput&&(e.columnsInput.value=String(I.tableColumns)),e.rowsDecrement.disabled=I.tableRows<=1,e.rowsIncrement.disabled=I.tableRows>=20,e.columnsDecrement.disabled=I.tableColumns<=1,e.columnsIncrement.disabled=I.tableColumns>=12,e.rowsStepper.classList.toggle("is-focused",I.tableFocus==="rows"),e.columnsStepper.classList.toggle("is-focused",I.tableFocus==="columns");let n=8,r=6,i=e.panel.offsetWidth,o=G.getBoundingClientRect(),s=o.right+r+i<=window.innerWidth-n,a=o.left-r-i>=n;!s&&!a&&o.width+r+i<=window.innerWidth-n*2&&(I.tableMenuBaseLeft||(I.tableMenuBaseLeft=G.style.left),G.style.left=`${n}px`,o=G.getBoundingClientRect());let l=o.right+r+i<=window.innerWidth-n;e.panel.dataset.side=l?"right":"left";let c=l?o.right+r:o.left-r-i;e.panel.style.left=`${Math.max(n,Math.min(window.innerWidth-i-n,c))}px`;let u=t.getBoundingClientRect();e.panel.style.top=`${Math.max(n,Math.min(window.innerHeight-e.panel.offsetHeight-n,u.top))}px`},Ss=()=>{let t=I.view,e=t&&Zi(t);if(!t||!e||I.dismissedContext===e.key){I.provider?.hide(),Bp();return}I.activationContext!==`${e.blockFrom}:${tt}`&&Object.assign(I,{activationContext:`${e.blockFrom}:${tt}`,activeIndex:0,tableOpen:!1,tableFocus:"rows",tableRows:3,tableColumns:3,tableMenuBaseLeft:"",error:""}),I.context=e,I.commands=sD(e.query,e,t.state.schema),I.activeIndex=Math.min(I.activeIndex,Math.max(0,I.commands.length-1));let n=cD();n!==w0&&(w0=n,uD()),Pp(),Sn()},fD=(t,e)=>{let n=Zi(t);if(G.dataset.show!=="true"||!n||e.isComposing||e.keyCode===229)return!1;if(e.key==="Escape")return I.dismissedContext=n.key,I.provider?.hide(),e.preventDefault(),!0;if(I.tableOpen){if(e.key==="ArrowLeft"||e.key==="ArrowRight"){let i=e.key==="ArrowLeft"?-1:1;return I.tableFocus==="rows"?I.tableRows=Math.min(20,Math.max(1,I.tableRows+i)):I.tableColumns=Math.min(12,Math.max(1,I.tableColumns+i)),Sn(),e.preventDefault(),!0}if(["Tab","ArrowUp","ArrowDown"].includes(e.key))return I.tableFocus=I.tableFocus==="rows"?"columns":"rows",Sn(),e.preventDefault(),!0;if(e.key==="Enter")return Jr("table"),e.preventDefault(),!0}if(e.key==="ArrowUp"||e.key==="ArrowDown")return I.commands.length&&(I.activeIndex=(I.activeIndex+(e.key==="ArrowUp"?-1:1)+I.commands.length)%I.commands.length,I.tableOpen=!1,Pp(),Sn(),e.preventDefault()),!0;let r=I.commands[I.activeIndex];return e.key==="ArrowRight"&&r?.id==="table"?(I.tableOpen=!0,Sn(),e.preventDefault(),!0):e.key==="Enter"&&r?(r.id==="table"?(I.tableOpen=!0,Sn()):Jr(r.id),e.preventDefault(),!0):e.key==="Tab"&&r?.id!=="table"?(Jr(r.id),e.preventDefault(),!0):!1};document.documentElement.dataset.weibeiCompactPreview=Ll?"true":"false";window.weiBeiEditorCheckMode&&(document.documentElement.dataset.weibeiCheckMode="true");var C0=0,yp=0,S0=0,M0=0,e1=()=>[document.querySelector("#editor"),document.querySelector(".milkdown"),document.querySelector(".ProseMirror")].filter(Boolean),dD=t=>{let e=t.getBoundingClientRect?.();return Math.max(0,t.scrollHeight||0,t.offsetHeight||0,t.clientHeight||0,e?.height||0)},E0=()=>{let t=e1(),e=Math.ceil(Math.max(1,...t.map(dD))),n=Math.ceil(Math.max(1,...t.map(r=>r.getBoundingClientRect?.().width||r.clientWidth||0)));window.WeiBeiCompactPreviewHeight=e,window.WeiBeiCompactPreviewMeasuredAt=Date.now(),!(Math.abs(e-S0)<1&&Math.abs(n-M0)<1)&&(S0=e,M0=n,Le("contentHeightChanged",{height:e}))},pD=()=>{!Ll||!$0||(E0(),window.cancelAnimationFrame(C0),C0=window.requestAnimationFrame(E0))},_t=()=>{if(!Ll||yp)return;let t=yt!==null?100:40;yp=window.setTimeout(()=>{yp=0,pD()},t)},hD=()=>{if(Ll){if(window.ResizeObserver){let t=new ResizeObserver(_t);e1().forEach(e=>t.observe(e))}_t(),document.fonts?.ready?.then(_t).catch(()=>{})}},mD=()=>{let t=window.getSelection();if(!t||t.rangeCount===0)return null;let e=t.getRangeAt(0).getBoundingClientRect();return!e||e.width+e.height===0?null:{x:e.left+e.width/2,y:e.bottom,width:e.width,height:e.height}},Pl=t=>Xw(vs,t),gD=t=>String(t||"").split(/\r?\n/).slice(1,-1).map(e=>{let n=e.match(/^\s*([^:#][^:]*):\s*(.*)$/);return n?{key:n[1].trim(),value:n[2].trim()||" "}:null}).filter(Boolean),Fl=()=>{let t=document.querySelector("#frontmatter-panel");if(!t)return;let e=gD(vs);t.dataset.visible=e.length>0?"true":"false",t.innerHTML=e.length>0?`<div class="frontmatter-title">${YO()}</div>${e.map(n=>`<div class="frontmatter-row"><span class="frontmatter-key">${Ap(n.key)}</span><span>${Ap(n.value)}</span></div>`).join("")}`:""},Ap=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),T0=t=>`${UO}://image?src=${encodeURIComponent(t)}`,yD=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|tiff?)(?:$|[?#])/i,t1=t=>{let n=(t||"").trim().match(/^(\d{1,4})(?:x(\d{1,4}))?$/i);return n?{width:Math.max(1,Number(n[1])),height:n[2]?Math.max(1,Number(n[2])):null}:null},kD=(t,e)=>{t.style.width=e?`${e.width}px`:"",t.style.maxWidth=e?"100%":"",t.style.height=e?.height?`${e.height}px`:""},Ol=t=>{let e=String(t||"").split("|"),n=e.length>1?t1(e.at(-1)):null;return{alt:n?e.slice(0,-1).join("|").trim():String(t||""),size:n}},bD=(t,e,n)=>{let r=e,i=n;for(;r<i&&/\s/.test(t[r]);)r+=1;for(;i>r&&/\s/.test(t[i-1]);)i-=1;return{start:r,end:i}},n1=t=>{let e=String(t||""),n=[],r=0,i="";for(let o=0;o<e.length;o+=1){let s=e[o],a=e[o+1];if(s==="\\"&&a==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+2,i="",o+=1;continue}if(s==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+1,i="";continue}i+=s}return n.push({raw:e.slice(r),value:i,start:r,end:e.length}),n},r1=t=>{let e=String(t||"").trim(),n=n1(e),i=(n.shift()||{value:"",start:0,end:0}).value.trim(),o=n,s=o.map(u=>u.value).join("|").trim(),a=o.length>0?bD(e,o[0].start,o.at(-1).end):null,l=i.indexOf("#"),c=l>=0?i.slice(0,l).trim():i;return{source:e,target:i,noteTitle:c,display:s||i,alias:s,aliasRange:a}},xD=t=>{let e=n1(String(t||"").trim()),n=(e.shift()?.value||"").trim(),r=e.at(-1),i=r?t1(r.value):null,o=i?e.slice(0,-1):e;return{target:n,size:i,label:o.map(s=>s.value).join("|").trim()}},i1=()=>{let t=Gi==="inkstone"?{background:"#151515",accent:"#a6362b",text:"#d7cbb0"}:{background:"#efe6d8",accent:"#9f3b2f",text:"#6b5148"},e=`<svg xmlns="http://www.w3.org/2000/svg" width="156" height="34" viewBox="0 0 156 34"> +`).trim(),q0=t=>t==="glassLight"||t==="glassMist"?"xuan":t==="glassDark"||t==="glassSlate"?"stele":t==="xuan"||t==="inkstone"||t==="stele"||t==="paper"?t:"paper",eD=t=>["glassLight","glassDark","glassMist","glassSlate"].includes(t)?t:"",Gi=q0(window.weiBeiTheme),tD=()=>{switch(Gi){case"inkstone":return{background:"#151515",primaryColor:"#1c1c1c",primaryTextColor:"#d7cbb0",primaryBorderColor:"#3a3328",lineColor:"#8b5e3c",secondaryColor:"#222222",tertiaryColor:"#171717",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"stele":return{background:"#1e2228",primaryColor:"#252a32",primaryTextColor:"#d2d6dc",primaryBorderColor:"#3a414c",lineColor:"#8a7a5c",secondaryColor:"#2a3038",tertiaryColor:"#1a1e24",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"xuan":return{background:"#f7f4ef",primaryColor:"#fcfbf8",primaryTextColor:"#25231f",primaryBorderColor:"#d8d2c6",lineColor:"#6e634f",secondaryColor:"#ebe6dc",tertiaryColor:"#f7f4ef",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};default:return{background:"#fbf5e8",primaryColor:"#f6eddc",primaryTextColor:"#2e261f",primaryBorderColor:"#cbb79b",lineColor:"#7a6250",secondaryColor:"#efe4d2",tertiaryColor:"#f8f0e1",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'}}},nD=t=>{t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:tD()})},K0=t=>{Gi=q0(t);let e=eD(t);document.documentElement.dataset.weibeiTheme=Gi,document.body&&(document.body.dataset.weibeiTheme=Gi),e?(document.documentElement.dataset.weibeiGlass=e,document.body&&(document.body.dataset.weibeiGlass=e)):(delete document.documentElement.dataset.weibeiGlass,document.body&&delete document.body.dataset.weibeiGlass),Ji+=1};K0(window.weiBeiTheme);var Qi=t=>{if(window.WeiBeiEditorBootFailed){window.WeiBeiEditorBootFailed(t);return}let e=document.querySelector("#editor");e&&(e.innerHTML=`<pre style="white-space:pre-wrap;color:#9f3427;padding:24px;font:13px/1.5 SFMono-Regular,Menlo,monospace;">${ue("bootFailed")} +${String(t?.stack||t)}</pre>`)};window.addEventListener("error",t=>Qi(t.error||t.message));window.addEventListener("unhandledrejection",t=>Qi(t.reason));var Le=(t,e={})=>{let n=$0?.[t];if(!n)return;let r=a0({documentID:tt,documentGeneration:je,revision:Mn.revision},e);typeof r.markdown=="string"&&(Sp+=1),At(st,"bridgeMessages"),st&&At(st,"bridgeBytes",new TextEncoder().encode(JSON.stringify(r)).byteLength),n.postMessage(r)},G=document.createElement("div"),Ur=document.createElement("div"),ot=document.createElement("button"),Se=document.createElement("div");G.className="weibei-slash-menu",G.dataset.show="false",G.dataset.state="closed",G.setAttribute("role","listbox"),G.setAttribute("aria-label","Slash commands"),Ur.className="weibei-visually-hidden",Ur.setAttribute("role","status"),Ur.setAttribute("aria-live","polite"),ot.type="button",ot.className="weibei-line-plus",ot.textContent="\uFF0B",ot.setAttribute("aria-label","\u63D2\u5165\u5185\u5BB9"),ot.hidden=!0,Se.className="weibei-table-toolbar",Se.dataset.state="closed",Se.setAttribute("aria-hidden","true"),Se.setAttribute("role","toolbar");for(let[t,e]of[["addRow","tableAddRow"],["deleteRow","tableDeleteRow"],["addColumn","tableAddColumn"],["deleteColumn","tableDeleteColumn"],["header","tableHeader"]]){let n=document.createElement("button");n.type="button",n.dataset.action=t,n.dataset.label=e,Se.append(n)}var Cs=null,rD=[{id:"structure",label:"slashStructure"},{id:"lists",label:"slashLists"},{id:"content",label:"slashContent"},{id:"rich",label:"slashRichContent"},{id:"fonts",label:"slashFonts"}],iD=[{id:"heading1",group:"structure",label:"slashHeading1",aliases:["h1","heading_1","yjbt","yijibiaoti","\u4E00\u7EA7","\u6807\u98981"]},{id:"heading2",group:"structure",label:"slashHeading2",aliases:["h2","heading_2","ejbt","erjibiaoti","\u4E8C\u7EA7","\u6807\u98982"]},{id:"heading3",group:"structure",label:"slashHeading3",aliases:["h3","heading_3","sjbt","sanjibiaoti","\u4E09\u7EA7","\u6807\u98983"]},{id:"heading4",group:"structure",label:"slashHeading4",aliases:["h4","heading_4","sijbt","sijibiaoti","\u56DB\u7EA7","\u6807\u98984"]},{id:"heading5",group:"structure",label:"slashHeading5",aliases:["h5","heading_5","wjbt","wujibiaoti","\u4E94\u7EA7","\u6807\u98985"]},{id:"heading6",group:"structure",label:"slashHeading6",aliases:["h6","heading_6","ljbt","liujibiaoti","\u516D\u7EA7","\u6807\u98986"]},{id:"bulletList",group:"lists",label:"slashBulletList",aliases:["bullet_list","bullet","ul","wxlb","wuxuliebiao","\u65E0\u5E8F","\u9879\u76EE\u7B26\u53F7"]},{id:"orderedList",group:"lists",label:"slashOrderedList",aliases:["ordered_list","ol","yxlb","youxuliebiao","\u6709\u5E8F","\u7F16\u53F7"]},{id:"taskList",group:"lists",label:"slashTaskList",aliases:["task_list","todo","task","checklist","dblb","daibanliebiao","\u5F85\u529E","\u4EFB\u52A1"]},{id:"quote",group:"lists",label:"slashQuote",aliases:["quote","blockquote","yy","yinyong","\u5F15\u7528"]},{id:"callout",group:"content",label:"slashCallout",aliases:["callout","note","tsk","tishikuai","\u63D0\u793A","\u672D\u8BB0"]},{id:"code",group:"content",label:"slashCode",aliases:["code","code_block","dmk","daimakuai","\u4EE3\u7801"]},{id:"divider",group:"content",label:"slashDivider",aliases:["divider","horizontal_rule","hr","fgx","fengexian","\u5206\u9694","\u6A2A\u7EBF"]},{id:"link",group:"content",label:"slashLink",aliases:["link","url","lj","lianjie","\u94FE\u63A5","\u7F51\u5740"]},{id:"wikiLink",group:"content",label:"slashWikiLink",aliases:["wiki","note_link","bjl","bijilianjie","\u7B14\u8BB0","\u53CC\u94FE"]},{id:"footnote",group:"content",label:"slashFootnote",aliases:["footnote","note_ref","jz","jiaozhu","\u811A\u6CE8","\u6CE8\u91CA"]},{id:"table",group:"rich",label:"slashTable",aliases:["table","grid","bg","biaoge","\u8868\u683C"]},{id:"image",group:"rich",label:"slashImage",aliases:["image","photo","picture","tp","tupian","\u56FE\u7247","\u7167\u7247"]},{id:"mermaid",group:"rich",label:"slashMermaid",aliases:["mermaid","diagram","flowchart","lct","liuchengtu","\u56FE\u8868","\u6D41\u7A0B\u56FE"]},{id:"inlineMath",group:"rich",label:"slashInlineMath",aliases:["math","formula","inline_math","hngs","hangneigongshi","\u516C\u5F0F","\u884C\u5185"]},{id:"blockMath",group:"rich",label:"slashBlockMath",aliases:["display_math","equation","block_math","kjgs","kuaijigongshi","\u65B9\u7A0B","\u5757\u7EA7"]},{id:"fontSystem",group:"fonts",label:"slashFontSystem",aliases:["font","system","sf pro","pingfang sc","ziti","\u5B57\u4F53","\u82F9\u65B9"]},{id:"fontSerif",group:"fonts",label:"slashFontSerif",aliases:["font","serif","songti sc","ziti","\u5B57\u4F53","\u5B8B\u4F53"]},{id:"fontLiterary",group:"fonts",label:"slashFontLiterary",aliases:["font","weibeistele","wei bei stele","ziti","\u5B57\u4F53","\u9B4F\u7891"]}],U0=new Set(["system","serif","literary"]),Ep={fontSystem:"system",fontSerif:"serif",fontLiterary:"literary"},I={provider:null,view:null,context:null,commands:[],activeIndex:0,dismissedContext:"",activationContext:"",tableOpen:!1,tableFocus:"rows",tableRows:3,tableColumns:3,tableMenuBaseLeft:"",error:""},J0=new Set(["list_item","task_list_item","table","table_row","table_header_row","table_cell","table_header","code_block","math_block"]),De={state:"closed",generation:0,timer:0,frame:0},Tp=()=>document.documentElement.dataset.weibeiReduceMotion==="true",G0=t=>{document.documentElement.dataset.weibeiReduceMotion=t===!0||t==="true"?"true":"false"},X0=t=>{let e=Number(t),n=Number.isFinite(e)&&e>0?e:1;document.documentElement.style.setProperty("--weibei-text-scale",String(n))},Zi=t=>{if(!ie||t.composing)return null;let{selection:e}=t.state;if(!(e instanceof P)||!e.empty)return null;let{$from:n}=e;if(n.parent.type.name!=="paragraph")return null;for(let u=n.depth;u>0;u-=1)if(J0.has(n.node(u).type.name))return null;let r=n.parent.textBetween(0,n.parentOffset,"\uFFFC","\uFFFC"),i=r.lastIndexOf("/");if(i<0)return null;let o=r.slice(i+1);if(/[\s/]/u.test(o))return null;let s=/^[\u200B\uFEFF]*$/u.test(r.slice(0,i))?0:i,a=n.depth,l=n.before(a),c=n.start(a)+s;return{query:o,parent:n.parent,triggerFrom:c,triggerTo:n.pos,triggerStartOffset:s,triggerEndOffset:n.parentOffset,blockFrom:l,blockTo:n.after(a),index:n.index(a-1),container:n.node(a-1),key:`${c}:${o}`}},Y0=t=>{if(!ie||t.composing)return null;let{selection:e}=t.state;if(!(e instanceof P)||!e.empty||e.$from.parent.type.name!=="paragraph"||e.$from.parent.content.size!==0)return null;for(let n=e.$from.depth;n>0;n-=1)if(J0.has(e.$from.node(n).type.name))return null;return e.$from},C0=t=>{let e=Y0(t);if(ot.hidden=!e,!e)return;let n=t.coordsAtPos(e.pos);ot.style.left=`${Math.max(6,n.left-30)}px`,ot.style.top=`${Math.max(6,n.top-2)}px`},Bp=(t,e,n={})=>{let r=e.nodes.paragraph;if(!r)return null;if(t.startsWith("heading")){let i=e.nodes.heading;return i?{content:M.from(i.create({level:Number(t.at(-1))})),selectionOffset:1}:null}if(["bulletList","orderedList","taskList"].includes(t)){let i=t==="orderedList"?e.nodes.ordered_list:e.nodes.bullet_list,o=e.nodes.list_item?.createAndFill(t==="taskList"?{checked:!1}:null,r.create()),s=o&&i?.createAndFill(null,o);return s?{content:M.from(s),selectionOffset:3}:null}if(t==="callout"){let o=e.nodes.callout?.create({calloutType:"note",title:"",fold:""},r.create());return o?{content:M.from(o),selectionOffset:2}:null}if(t==="quote"){let i=e.nodes.blockquote||e.nodes.block_quote;if(!i)return null;let o=i.create(null,r.create());return{content:M.from(o),selectionOffset:2}}if(t==="code"||t==="mermaid"){let i=e.nodes.code_block;if(!i)return null;let o=t==="mermaid"?`graph TD + A --> B`:"";return{content:M.from(i.create({language:t==="mermaid"?"mermaid":""},o?e.text(o):null)),selectionOffset:o.length+1}}if(t==="inlineMath"){let o=e.nodes.math_inline?.create(null,e.text("x"));return o?{content:M.from(r.create(null,o)),selectionOffset:1}:null}if(t==="link"){let i=e.marks.link,o=ue("linkPlaceholder"),s=i?r.create(null,e.text(o,[i.create({href:""})])):null;return s?{content:M.from(s),selectionFromOffset:1,selectionToOffset:o.length+1}:null}if(t==="wikiLink"){let i=e.nodes.wiki_link,o=ue("wikiLinkPlaceholder"),s=i?.create({raw:o,target:o,label:""});return s?{content:M.from(r.create(null,s)),selectionOffset:1,activateEvent:"weibei-edit-structured"}:null}if(t==="footnote"){let o=e.nodes.inline_footnote?.create({value:ue("footnotePlaceholder")});return o?{content:M.from(r.create(null,o)),selectionOffset:1,activateEvent:"weibei-edit-structured"}:null}if(t==="blockMath"){let o=e.nodes.math_block?.create({value:"x"});return o?{content:M.from(o),selectionOffset:0}:null}if(t==="divider"){let o=(e.nodes.hr||e.nodes.horizontal_rule)?.create();return o?{content:M.from([o,r.create()]),selectionOffset:o.nodeSize+1}:null}if(t==="table"){let{table:i,table_header_row:o,table_row:s,table_header:a,table_cell:l}=e.nodes,c=Math.min(20,Math.max(1,Number(n.rows)||3)),u=Math.min(12,Math.max(1,Number(n.columns)||3));if(!i||!o||!s||!a||!l)return null;let f=Array.from({length:u},()=>a.createAndFill()),d=Array.from({length:c-1},()=>s.create(null,Array.from({length:u},()=>l.createAndFill())));return f.some(p=>!p)||d.some(p=>!p)?null:{content:M.from(i.create(null,[o.create(null,f),...d])),selectionOffset:4}}if(t==="image"){let i=e.nodes.image;return i&&n.src?{content:M.from(r.create(null,i.create({src:n.src,alt:n.alt||"image"}))),selectionOffset:2}:null}return null},Q0=(t,e)=>{let n=e?.content?.firstChild;if(!t||!n)return null;if(e.content.childCount===1&&n.type===t.parent.type){let a=t.parent.content.cut(0,t.triggerStartOffset).append(n.content).append(t.parent.content.cut(t.triggerEndOffset));return{content:M.from(t.parent.type.create(t.parent.attrs,a,t.parent.marks)),selectionBase:t.triggerFrom-1}}let r=[],i=t.parent.content.cut(0,t.triggerStartOffset),o=t.parent.content.cut(t.triggerEndOffset);i.size&&r.push(t.parent.type.create(t.parent.attrs,i,t.parent.marks));let s=t.blockFrom+r.reduce((a,l)=>a+l.nodeSize,0);return e.content.forEach(a=>r.push(a)),o.size&&r.push(t.parent.type.create(t.parent.attrs,o,t.parent.marks)),{content:M.from(r),selectionBase:s}},oD=(t,e,n)=>{if(!e)return!1;if(Ep[t.id])return!!n.marks.writing_font;if(t.id==="image")return!!n.nodes.image;let r=Bp(t.id,n,{rows:3,columns:3}),i=Q0(e,r);return!!(i&&e.container.canReplace(e.index,e.index+1,i.content))},sD=(t,e,n)=>{let r=String(t||"").toLocaleLowerCase();return iD.filter(i=>oD(i,e,n)&&(!r||[Rl["zh-Hans"][i.label],Rl.en[i.label],...i.aliases].some(o=>String(o).toLocaleLowerCase().includes(r))))},Z0=(t,e,n)=>{if(!e||!n)return!1;let r=t.state.doc.nodeAt(e.blockFrom),i=Q0(e,n);if(!r?.eq(e.parent)||!i||!e.container.canReplace(e.index,e.index+1,i.content))return!1;let o=is(t.state.tr.replaceWith(e.blockFrom,e.blockTo,i.content)),s=n.activateEvent?H.create(o.doc,i.selectionBase+n.selectionOffset):Number.isInteger(n.selectionFromOffset)&&Number.isInteger(n.selectionToOffset)?P.create(o.doc,i.selectionBase+n.selectionFromOffset,i.selectionBase+n.selectionToOffset):_.findFrom(o.doc.resolve(Math.min(i.selectionBase+n.selectionOffset,o.doc.content.size)),1,!0);return s&&o.setSelection(s),t.dispatch(o.scrollIntoView()),I.dismissedContext="",I.provider?.hide(),t.focus(),n.activateEvent&&s&&window.requestAnimationFrame(()=>{t.nodeDOM(s.from)?.dispatchEvent(new CustomEvent(n.activateEvent))}),window.requestAnimationFrame(Xi),!0},aD=(t,e)=>{let n=`image-picker-${Date.now()}-${Lp+=1}`;zt.set(n,{mode:"insert",view:t,context:e,documentID:tt,documentGeneration:je}),I.dismissedContext=e.key,I.provider?.hide(),Le("imagePickerRequested",{id:n})},lD=(t,e,n)=>{let r=t.state.schema.marks.writing_font;if(!r||!U0.has(n))return!1;let i=t.state.storedMarks||t.state.selection.$from.marks(),o=is(t.state.tr.delete(e.triggerFrom,e.triggerTo));return o.setSelection(P.create(o.doc,e.triggerFrom)),o.setStoredMarks([...i.filter(s=>s.type!==r),r.create({font:n})]),t.dispatch(o.scrollIntoView()),I.dismissedContext="",I.provider?.hide(),t.focus(),window.requestAnimationFrame(Xi),!0},Jr=t=>{let e=I.view,n=e&&Zi(e);return!e||!n?!1:t==="image"?(aD(e,n),!0):Ep[t]?lD(e,n,Ep[t]):Z0(e,n,Bp(t,e.state.schema,{rows:I.tableRows,columns:I.tableColumns}))},Pp=()=>{let t=I.view?.dom,e=I.commands[I.activeIndex];if(!t||G.dataset.show!=="true"||!e){t?.removeAttribute("aria-controls"),t?.removeAttribute("aria-expanded"),t?.removeAttribute("aria-activedescendant");return}G.id="weibei-slash-menu",t.setAttribute("aria-controls",G.id),t.setAttribute("aria-expanded","true"),t.setAttribute("aria-activedescendant",`weibei-slash-command-${e.id}`),G.setAttribute("aria-activedescendant",`weibei-slash-command-${e.id}`),Ur.textContent=`${ue(e.label)}\uFF0C${I.activeIndex+1}/${I.commands.length}`},cD=()=>`${Kr}::${I.error?"!":""}::${I.commands.length}::${I.commands.map(t=>t.id).join(",")}`,S0=null,uD=()=>{if(G.replaceChildren(),I.error){let t=document.createElement("div");t.className="weibei-slash-error",t.textContent=I.error,G.appendChild(t)}if(!I.commands.length){let t=document.createElement("div");t.className="weibei-slash-empty",t.textContent=ue("slashNoResults"),G.appendChild(t);return}for(let t of rD){let e=I.commands.filter(i=>i.group===t.id);if(!e.length)continue;let n=document.createElement("section");n.className="weibei-slash-section";let r=document.createElement("div");r.className="weibei-slash-group",r.textContent=ue(t.label),n.appendChild(r);for(let i of e){let o=I.commands.indexOf(i),s=document.createElement("div");s.id=`weibei-slash-command-${i.id}`,s.className=`weibei-slash-command${o===I.activeIndex?" is-active":""}`,s.setAttribute("role","option"),s.setAttribute("aria-selected",String(o===I.activeIndex)),s.setAttribute("aria-posinset",String(o+1)),s.setAttribute("aria-setsize",String(I.commands.length));let a=document.createElement("button");a.type="button",a.tabIndex=-1,a.className="weibei-slash-command-button",a.textContent=ue(i.label),a.addEventListener("pointerdown",l=>l.preventDefault()),a.addEventListener("pointermove",l=>{!Number(l.movementX)&&!Number(l.movementY)||(I.activeIndex=o,I.tableOpen=i.id==="table",Fp(),Sn())}),a.addEventListener("click",()=>{i.id!=="table"&&Jr(i.id)}),s.appendChild(a),n.appendChild(s)}G.appendChild(n)}},Fp=()=>{G.querySelectorAll(".weibei-slash-command").forEach((t,e)=>{t.classList.toggle("is-active",e===I.activeIndex),t.setAttribute("aria-selected",String(e===I.activeIndex))}),G.querySelector(".weibei-slash-command.is-active")?.scrollIntoView({block:"nearest"}),Pp()},vp=null,e1=()=>{Cs?.remove(),Cs=null,vp=null,I.tableMenuBaseLeft&&(G.style.left=I.tableMenuBaseLeft,I.tableMenuBaseLeft="")},Sn=()=>{let t=G.querySelector("#weibei-slash-command-table .weibei-slash-command-button");if(!I.tableOpen||G.dataset.show!=="true"||!t){e1();return}let e=vp;if(!e){let f=document.createElement("div");f.className="weibei-slash-table-panel",f.setAttribute("role","group");let d=g=>{let y=g==="rows",x=document.createElement("div");x.className=`weibei-slash-stepper${I.tableFocus===g?" is-focused":""}`;let C=document.createElement("span");C.className="weibei-slash-stepper-label",C.textContent=ue(y?"slashRows":"slashColumns"),x.appendChild(C);let v=()=>y?I.tableRows:I.tableColumns,A=O=>{y?I.tableRows=O:I.tableColumns=O},w=document.createElement("button");w.type="button",w.textContent="\u2212",w.setAttribute("aria-label",`${C.textContent} \u2212`),w.addEventListener("pointerdown",O=>O.preventDefault()),w.addEventListener("click",()=>{A(Math.max(1,v()-1)),I.tableFocus=g,Sn()}),x.appendChild(w);let N=document.createElement("input");N.className="weibei-slash-stepper-input",N.type="number",N.inputMode="numeric",N.min="1",N.max=String(y?20:12),N.step="1",N.setAttribute("aria-label",C.textContent),N.addEventListener("focus",()=>{I.tableFocus=g,f.querySelectorAll(".weibei-slash-stepper.is-focused").forEach(O=>O.classList.remove("is-focused")),x.classList.add("is-focused")}),N.addEventListener("input",()=>{let O=Number.parseInt(N.value,10);Number.isFinite(O)&&A(Math.min(y?20:12,Math.max(1,O)))}),N.addEventListener("change",()=>{let O=Math.min(y?20:12,Math.max(1,Number.parseInt(N.value,10)||1));N.value=String(O),A(O)}),N.addEventListener("keydown",O=>{if(O.stopPropagation(),O.key==="Enter"){let S=Math.min(y?20:12,Math.max(1,Number.parseInt(N.value,10)||1));A(S),Jr("table"),O.preventDefault()}}),x.appendChild(N);let B=document.createElement("button");return B.type="button",B.textContent="+",B.setAttribute("aria-label",`${C.textContent} +`),B.addEventListener("pointerdown",O=>O.preventDefault()),B.addEventListener("click",()=>{A(Math.min(y?20:12,v()+1)),I.tableFocus=g,Sn()}),x.appendChild(B),{stepper:x,input:N,decrement:w,increment:B}},p=d("rows"),h=d("columns"),m=document.createElement("button");m.type="button",m.className="weibei-slash-table-insert",m.textContent=ue("slashInsertTable"),m.addEventListener("pointerdown",g=>g.preventDefault()),m.addEventListener("click",()=>Jr("table")),f.append(p.stepper,h.stepper,m),document.body.appendChild(f),e={panel:f,rowsInput:p.input,rowsDecrement:p.decrement,rowsIncrement:p.increment,rowsStepper:p.stepper,columnsInput:h.input,columnsDecrement:h.decrement,columnsIncrement:h.increment,columnsStepper:h.stepper},Cs=f,vp=e}document.activeElement!==e.rowsInput&&(e.rowsInput.value=String(I.tableRows)),document.activeElement!==e.columnsInput&&(e.columnsInput.value=String(I.tableColumns)),e.rowsDecrement.disabled=I.tableRows<=1,e.rowsIncrement.disabled=I.tableRows>=20,e.columnsDecrement.disabled=I.tableColumns<=1,e.columnsIncrement.disabled=I.tableColumns>=12,e.rowsStepper.classList.toggle("is-focused",I.tableFocus==="rows"),e.columnsStepper.classList.toggle("is-focused",I.tableFocus==="columns");let n=8,r=6,i=e.panel.offsetWidth,o=G.getBoundingClientRect(),s=o.right+r+i<=window.innerWidth-n,a=o.left-r-i>=n;!s&&!a&&o.width+r+i<=window.innerWidth-n*2&&(I.tableMenuBaseLeft||(I.tableMenuBaseLeft=G.style.left),G.style.left=`${n}px`,o=G.getBoundingClientRect());let l=o.right+r+i<=window.innerWidth-n;e.panel.dataset.side=l?"right":"left";let c=l?o.right+r:o.left-r-i;e.panel.style.left=`${Math.max(n,Math.min(window.innerWidth-i-n,c))}px`;let u=t.getBoundingClientRect();e.panel.style.top=`${Math.max(n,Math.min(window.innerHeight-e.panel.offsetHeight-n,u.top))}px`},Ss=()=>{let t=I.view,e=t&&Zi(t);if(!t||!e||I.dismissedContext===e.key){I.provider?.hide(),Pp();return}I.activationContext!==`${e.blockFrom}:${tt}`&&Object.assign(I,{activationContext:`${e.blockFrom}:${tt}`,activeIndex:0,tableOpen:!1,tableFocus:"rows",tableRows:3,tableColumns:3,tableMenuBaseLeft:"",error:""}),I.context=e,I.commands=sD(e.query,e,t.state.schema),I.activeIndex=Math.min(I.activeIndex,Math.max(0,I.commands.length-1));let n=cD();n!==S0&&(S0=n,uD()),Fp(),Sn()},fD=(t,e)=>{let n=Zi(t);if(G.dataset.show!=="true"||!n||e.isComposing||e.keyCode===229)return!1;if(e.key==="Escape")return I.dismissedContext=n.key,I.provider?.hide(),e.preventDefault(),!0;if(I.tableOpen){if(e.key==="ArrowLeft"||e.key==="ArrowRight"){let i=e.key==="ArrowLeft"?-1:1;return I.tableFocus==="rows"?I.tableRows=Math.min(20,Math.max(1,I.tableRows+i)):I.tableColumns=Math.min(12,Math.max(1,I.tableColumns+i)),Sn(),e.preventDefault(),!0}if(["Tab","ArrowUp","ArrowDown"].includes(e.key))return I.tableFocus=I.tableFocus==="rows"?"columns":"rows",Sn(),e.preventDefault(),!0;if(e.key==="Enter")return Jr("table"),e.preventDefault(),!0}if(e.key==="ArrowUp"||e.key==="ArrowDown")return I.commands.length&&(I.activeIndex=(I.activeIndex+(e.key==="ArrowUp"?-1:1)+I.commands.length)%I.commands.length,I.tableOpen=!1,Fp(),Sn(),e.preventDefault()),!0;let r=I.commands[I.activeIndex];return e.key==="ArrowRight"&&r?.id==="table"?(I.tableOpen=!0,Sn(),e.preventDefault(),!0):e.key==="Enter"&&r?(r.id==="table"?(I.tableOpen=!0,Sn()):Jr(r.id),e.preventDefault(),!0):e.key==="Tab"&&r?.id!=="table"?(Jr(r.id),e.preventDefault(),!0):!1};document.documentElement.dataset.weibeiCompactPreview=Ll?"true":"false";window.weiBeiEditorCheckMode&&(document.documentElement.dataset.weibeiCheckMode="true");var M0=0,yp=0,E0=0,T0=0,t1=()=>[document.querySelector("#editor"),document.querySelector(".milkdown"),document.querySelector(".ProseMirror")].filter(Boolean),dD=t=>{let e=t.getBoundingClientRect?.();return Math.max(0,t.scrollHeight||0,t.offsetHeight||0,t.clientHeight||0,e?.height||0)},Ap=()=>{let t=t1(),e=Math.ceil(Math.max(1,...t.map(dD))),n=Math.ceil(Math.max(1,...t.map(r=>r.getBoundingClientRect?.().width||r.clientWidth||0)));window.WeiBeiCompactPreviewHeight=e,window.WeiBeiCompactPreviewMeasuredAt=Date.now(),!(Math.abs(e-E0)<1&&Math.abs(n-T0)<1)&&(E0=e,T0=n,Le("contentHeightChanged",{height:e}))},pD=()=>{!Ll||!_0||(Ap(),window.cancelAnimationFrame(M0),M0=window.requestAnimationFrame(Ap))},_t=()=>{if(!Ll||yp)return;let t=yt!==null?100:40;yp=window.setTimeout(()=>{yp=0,pD()},t)},hD=()=>{if(Ll){if(window.ResizeObserver){let t=new ResizeObserver(_t);t1().forEach(e=>t.observe(e))}_t(),document.fonts?.ready?.then(_t).catch(()=>{})}},mD=()=>{let t=window.getSelection();if(!t||t.rangeCount===0)return null;let e=t.getRangeAt(0).getBoundingClientRect();return!e||e.width+e.height===0?null:{x:e.left+e.width/2,y:e.bottom,width:e.width,height:e.height}},Pl=t=>Qw(vs,t),gD=t=>String(t||"").split(/\r?\n/).slice(1,-1).map(e=>{let n=e.match(/^\s*([^:#][^:]*):\s*(.*)$/);return n?{key:n[1].trim(),value:n[2].trim()||" "}:null}).filter(Boolean),Fl=()=>{let t=document.querySelector("#frontmatter-panel");if(!t)return;let e=gD(vs);t.dataset.visible=e.length>0?"true":"false",t.innerHTML=e.length>0?`<div class="frontmatter-title">${YO()}</div>${e.map(n=>`<div class="frontmatter-row"><span class="frontmatter-key">${Ip(n.key)}</span><span>${Ip(n.value)}</span></div>`).join("")}`:""},Ip=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),v0=t=>`${UO}://image?src=${encodeURIComponent(t)}`,yD=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|tiff?)(?:$|[?#])/i,n1=t=>{let n=(t||"").trim().match(/^(\d{1,4})(?:x(\d{1,4}))?$/i);return n?{width:Math.max(1,Number(n[1])),height:n[2]?Math.max(1,Number(n[2])):null}:null},kD=(t,e)=>{t.style.width=e?`${e.width}px`:"",t.style.maxWidth=e?"100%":"",t.style.height=e?.height?`${e.height}px`:""},Ol=t=>{let e=String(t||"").split("|"),n=e.length>1?n1(e.at(-1)):null;return{alt:n?e.slice(0,-1).join("|").trim():String(t||""),size:n}},bD=(t,e,n)=>{let r=e,i=n;for(;r<i&&/\s/.test(t[r]);)r+=1;for(;i>r&&/\s/.test(t[i-1]);)i-=1;return{start:r,end:i}},r1=t=>{let e=String(t||""),n=[],r=0,i="";for(let o=0;o<e.length;o+=1){let s=e[o],a=e[o+1];if(s==="\\"&&a==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+2,i="",o+=1;continue}if(s==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+1,i="";continue}i+=s}return n.push({raw:e.slice(r),value:i,start:r,end:e.length}),n},i1=t=>{let e=String(t||"").trim(),n=r1(e),i=(n.shift()||{value:"",start:0,end:0}).value.trim(),o=n,s=o.map(u=>u.value).join("|").trim(),a=o.length>0?bD(e,o[0].start,o.at(-1).end):null,l=i.indexOf("#"),c=l>=0?i.slice(0,l).trim():i;return{source:e,target:i,noteTitle:c,display:s||i,alias:s,aliasRange:a}},xD=t=>{let e=r1(String(t||"").trim()),n=(e.shift()?.value||"").trim(),r=e.at(-1),i=r?n1(r.value):null,o=i?e.slice(0,-1):e;return{target:n,size:i,label:o.map(s=>s.value).join("|").trim()}},o1=()=>{let t=Gi==="inkstone"?{background:"#151515",accent:"#a6362b",text:"#d7cbb0"}:{background:"#efe6d8",accent:"#9f3b2f",text:"#6b5148"},e=`<svg xmlns="http://www.w3.org/2000/svg" width="156" height="34" viewBox="0 0 156 34"> <rect width="156" height="34" rx="3" fill="${t.background}"/> <path d="M18 22l5-6 4 4 3-3 6 5" fill="none" stroke="${t.accent}" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/> <rect x="17" y="11" width="20" height="14" rx="2" fill="none" stroke="${t.accent}" stroke-width="1.2"/> - <text x="48" y="22" fill="${t.text}" font-family="-apple-system, BlinkMacSystemFont, 'Songti SC', serif" font-size="13">${Ap(ue("imageMissing"))}</text> -</svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`},o1=t=>{if(!t||/^(?:data:|blob:|weibeiimage:)/i.test(t))return t;if(/^https:/i.test(t))return T0(t);if(/^http:/i.test(t))return"";try{let e=new URL(t,_0||window.location.href).href;return/^(?:file:|https:)/i.test(e)?T0(e):/^(?:data:|blob:|weibeiimage:)/i.test(e)?e:""}catch{return""}},Fp=()=>{document.body.dataset.editable=ie?"true":"false",document.querySelectorAll(".weibei-code-language-input").forEach(t=>{t instanceof HTMLInputElement&&(t.readOnly=!ie,t.tabIndex=ie?0:-1,t.setAttribute("aria-readonly",t.readOnly?"true":"false"),t.setAttribute("aria-label",ue("codeLanguage")),t.placeholder=ue("codeLanguagePlaceholder"))})},Ip=new Set,Ms=new Set;var wD=(t,e,n)=>{let r=t,i=document.createElement("span"),o=document.createElement("img"),s=document.createElement("span"),a=document.createElement("button"),l=document.createElement("button"),c=document.createElement("select");i.className="weibei-image-node",i.contentEditable="false",o.className="weibei-image",s.className="weibei-image-controls",a.type=l.type="button",a.textContent="\u66F4\u6362",l.textContent="\u5220\u9664",a.setAttribute("aria-label","\u66F4\u6362\u56FE\u7247"),l.setAttribute("aria-label","\u5220\u9664\u56FE\u7247");for(let[g,y]of[["","\u539F\u5C3A\u5BF8"],["320","\u5C0F"],["560","\u4E2D"],["900","\u5927"]]){let x=document.createElement("option");x.value=g,x.textContent=y,c.append(x)}c.setAttribute("aria-label","\u56FE\u7247\u5C3A\u5BF8"),s.append(a,l,c),i.append(o,s),s.dataset.state="closed",s.setAttribute("aria-hidden","true");let u=()=>{o.dataset.weibeiImageMissingFor=o.dataset.weibeiResolvedSrc||o.getAttribute("src")||"",o.dataset.weibeiImagePlaceholder="true",o.classList.add("weibei-image-missing"),o.title=ue("imageMissing"),_t()},f=()=>{o.dataset.weibeiImagePlaceholder!=="true"&&(o.classList.remove("weibei-image-missing"),_t())},d=()=>{At(st,"imageNodeUpdates");let g=String(r.attrs.src||""),y=o1(g),x=Ol(r.attrs.alt||"");if(o.alt=x.alt,o.title=String(r.attrs.title||""),o.dataset.weibeiMarkdownSrc=g,c.value=x.size&&["320","560","900"].includes(String(x.size.width))?String(x.size.width):"",kD(o,x.size),!(o.dataset.weibeiImagePlaceholder==="true"&&o.dataset.weibeiImageMissingFor===y)){if(!y){o.dataset.weibeiImageMissingFor=y,o.dataset.weibeiImagePlaceholder="true",o.classList.add("weibei-image-missing"),o.setAttribute("src",i1());return}o.dataset.weibeiResolvedSrc=y,delete o.dataset.weibeiImagePlaceholder,o.classList.remove("weibei-image-missing"),o.setAttribute("src",y)}},p=()=>{let g=`image-picker-${Date.now()}-${Dp+=1}`;zt.set(g,{mode:"replace",view:e,getPos:n,documentID:tt,documentGeneration:je}),Le("imagePickerRequested",{id:g})},h=()=>{let g=n(),y=typeof g=="number"?e.state.doc.nodeAt(g):null;y?.type===r.type&&e.dispatch(e.state.tr.delete(g,g+y.nodeSize).scrollIntoView())},m=()=>{let g=n(),y=typeof g=="number"?e.state.doc.nodeAt(g):null;if(y?.type!==r.type)return;let C=`${Ol(y.attrs.alt||"").alt}${c.value?`|${c.value}`:""}`;e.dispatch(e.state.tr.setNodeMarkup(g,void 0,{...y.attrs,alt:C}).scrollIntoView()),e.focus()};return o.addEventListener("error",u),o.addEventListener("load",f),a.addEventListener("click",p),l.addEventListener("click",h),c.addEventListener("change",m),Ip.add(d),d(),{dom:i,update(g){if(g.type!==r.type)return!1;let y=g.attrs.src!==r.attrs.src||g.attrs.alt!==r.attrs.alt||g.attrs.title!==r.attrs.title;return r=g,y&&d(),!0},selectNode(){i.classList.add("ProseMirror-selectednode"),o.classList.add("ProseMirror-selectednode"),s.dataset.state="open",s.setAttribute("aria-hidden","false")},deselectNode(){i.classList.remove("ProseMirror-selectednode"),o.classList.remove("ProseMirror-selectednode"),s.dataset.state="closed",s.setAttribute("aria-hidden","true")},stopEvent(g){return s.contains(g.target)},ignoreMutation(g){return s.contains(g.target)},destroy(){Ip.delete(d),o.removeEventListener("error",u),o.removeEventListener("load",f),a.removeEventListener("click",p),l.removeEventListener("click",h),c.removeEventListener("change",m)}}},s1=()=>Ip.forEach(t=>t()),zp=()=>{if(!K)return null;let t=K.action(e=>e.get(U).state.selection);return!t||t.empty?null:{from:t.from,to:t.to}},a1=()=>K?K.action(t=>{let{selection:e}=t.get(U).state;if(!e||e.empty)return"";let n=e.content().content;return j0(n.textBetween(0,n.size,` -`))}):"",CD=()=>j0(window.getSelection()?.toString()||a1()),Yt=(t,e,n,r,i={})=>{n<=e||t.push(le.inline(e,n,{...i,class:r}))},SD=t=>(Array.isArray(t)?t:[]).map(e=>({id:String(e?.id||""),text:String(e?.text||"").trim()})).filter(e=>e.id&&e.text.length>=4),MD=(t,e,n,r)=>{ie||Mp.length===0||Mp.forEach(i=>{let o=0,s=r.get(i.id)||0;for(;s<3;){let a=e.indexOf(i.text,o);if(a<0)break;Yt(t,n+a,n+a+i.text.length,"weibei-selection-ask-mark",{"data-thread-id":i.id,title:"\u6253\u5F00\u5F53\u65F6\u7684\u9009\u533A\u95EE\u7B54"}),s+=1,o=a+i.text.length}r.set(i.id,s)})};var ED=(t,e,n)=>{for(let r of e.matchAll(/(?:^|[\s`])((?:来源:|Source:)[^`\n]+)/g)){let i=r[0].startsWith(r[1])?0:1,o=r[1].startsWith("\u6765\u6E90\uFF1A")?"\u6765\u6E90\uFF1A":"Source:",s=n+(r.index||0)+i,a=s+r[1].length;Yt(t,s,a,"weibei-source-reference",{role:"link",tabindex:"0",title:ue("openSource",{value:r[1].slice(o.length).trim()}),"data-source-reference":r[1]})}},TD=(t,e,n,r)=>{let i=0;for(;i<e.length;){if(r.open){let a=e.indexOf("%%",i);if(a<0){Yt(t,n+i,n+e.length,"weibei-comment");return}Yt(t,n+i,n+a+2,"weibei-comment"),r.open=!1,i=a+2;continue}let o=e.indexOf("%%",i);if(o<0)return;let s=e.indexOf("%%",o+2);if(s<0){Yt(t,n+o,n+e.length,"weibei-comment"),r.open=!0;return}Yt(t,n+o,n+s+2,"weibei-comment"),i=s+2}},vD=(t,e,n)=>{for(let r of e.matchAll(/(^|\s)(#[\p{L}\p{N}_/-]+)\b/gu)){let i=n+(r.index||0)+r[1].length;Yt(t,i,i+r[2].length,"weibei-tag")}for(let r of e.matchAll(/(^|\s)(\^[A-Za-z0-9-]+)\s*$/g)){let i=n+(r.index||0)+r[1].length;Yt(t,i,i+r[2].length,"weibei-block-id")}},AD=(t,e,n)=>{for(let r of e.matchAll(/<br\s*\/?>/gi)){let i=n+(r.index||0),o=i+r[0].length;Yt(t,i,o,"weibei-html-break-source"),t.push(le.widget(o,()=>{let s=document.createElement("br");return s.className="weibei-html-break-preview",s},{side:1}))}},v0=t=>{let e=document.createElement("div");e.className="weibei-mermaid-render",e.textContent=ue("mermaidRendering");let n="\0",r=0,i=0,o=(s,a=!1)=>{let l=String(s||"");if(l===n)return;n=l;let c=i+=1;window.clearTimeout(r),r=window.setTimeout(async()=>{if(!(!e.isConnected||c!==i)){e.classList.remove("weibei-mermaid-error");try{let u=await Kw();nD(u);let f=`weibei-mermaid-${JO+=1}`;At(st,"mermaidRenders");let{svg:d,bindFunctions:p}=await u.render(f,l,e);if(!e.isConnected||c!==i)return;e.innerHTML=d,p?.(e),e.dataset.rendered="true"}catch(u){if(!e.isConnected||c!==i)return;e.classList.add("weibei-mermaid-error"),e.textContent=ue("mermaidFailed",{value:String(u?.message||u)})}_t()}},a?300:0)};return o(t),{element:e,updateSource:o}},Il=new WeakMap,$t=null,bs=!1,ID=t=>{if(!bs||!(t.selection instanceof P))return null;let{$from:e}=t.selection;for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(r.type.name==="code_block")return $p(r.attrs.language||"")!=="mermaid"?null:{node:r,pos:e.before(n)}}return null},ND=t=>{$t&&($t.documentGeneration!==je||$t.contentGeneration!==Gn||$t.generation!==Ji||t?.pos!==$t.pos)&&($t=null)},RD=(t,e,n)=>{let r=n?.pos===e;if(r&&!$t){let s=Il.get(t);$t=s?.generation===Ji?{...s,pos:e,documentGeneration:je,contentGeneration:Gn}:{...v0(t.textContent),generation:Ji,key:`mermaid-preview-${m0+=1}`,pos:e,documentGeneration:je,contentGeneration:Gn}}if(r)return $t.updateSource(t.textContent,!0),$t;let i=Il.get(t);if(i?.generation===Ji)return i.updateSource(t.textContent),i;let o={...v0(t.textContent),generation:Ji,key:`mermaid-preview-${m0+=1}`};return Il.set(t,o),o},OD=(t,e,n,r)=>{if($p(e.attrs.language||"")!=="mermaid")return!1;t.push(le.node(n,n+e.nodeSize,{class:"weibei-code-block weibei-mermaid-block","data-language":"mermaid"}));let i=RD(e,n,r);return t.push(le.widget(n+e.nodeSize,()=>i.element,{side:-1,key:i.key})),!0},DD=t=>{let e=r1(t);return e.target||e.noteTitle},LD=t=>{let e=t instanceof Element?t.closest(".weibei-wikilink, .weibei-embed-note[data-wikilink-title]"):null;return e?.getAttribute("data-wikilink-title")||e?.textContent?.trim()||""},Np=t=>{let e=LD(t);return e?(Le("wikiLinkActivated",{title:e}),!0):!1},BD=t=>(t instanceof Element?t.closest(".weibei-source-reference[data-source-reference]"):null)?.getAttribute("data-source-reference")||"",Rp=t=>{let e=BD(t);return e?(Le("sourceReferenceActivated",{reference:e}),!0):!1},l1=t=>{let e=t instanceof Element?t.closest(".weibei-selection-ask-mark[data-thread-id]"):null,n=e?.getAttribute("data-thread-id")||"";return n?(Le("selectionAskMark",{threadId:n,text:e.textContent||""}),!0):!1},c1=t=>{if(ie||!(t instanceof Element))return!1;let e=t.closest('blockquote.weibei-callout[data-callout-fold="-"]');return e?(e.classList.toggle("weibei-callout-open"),!0):!1},$p=t=>{let e=(t||"").trim().toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",sh:"bash",shell:"bash",zsh:"bash",md:"markdown",yml:"yaml"}[e]||e},u1=t=>typeof t=="string"?t.length:Array.isArray(t.content)?t.content.reduce((e,n)=>e+u1(n),0):String(t.content||"").length,PD=t=>{let e=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return["weibei-prism-token","token",t.type,...e].filter(Boolean).join(" ")},A0=new WeakMap,FD=new Set(["bash","css","do","java","javascript","json","jsx","markdown","python","r","ruby","rust","sql","stata","swift","tsx","typescript","yaml"]),ws=null,I0=!1,zD=()=>{ws||I0||(I0=!0,Uw().then(t=>{ws=t,Yi+=1,K?.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiPrismReady",!0))})}).catch(Qi))},f1=(t,e,n)=>{let r=n;for(let i of e){let o=u1(i);typeof i!="string"&&o>0&&(t.push({from:r,to:r+o,className:PD(i)}),Array.isArray(i.content)&&f1(t,i.content,r)),r+=o}},$D=(t,e,n)=>{let r=$p(e.attrs.language||"");if(!FD.has(r))return;if(!ws){zD();return}let i=A0.get(e);try{i||(At(st,"codeTokenizations"),i=[],f1(i,ws.tokenize(e.textContent,ws.languages[r]),0),A0.set(e,i)),i.forEach(o=>Yt(t,n+1+o.from,n+1+o.to,o.className))}catch{}};var N0=(t,e,n)=>{let r=t,i=r.type.name==="math_block",o=document.createElement(i?"div":"span");o.className=`weibei-math-node ${i?"weibei-math-block":"weibei-math-inline"}`,o.dataset.type=r.type.name,o.contentEditable="false",o.tabIndex=0;let s=document.createElement(i?"div":"span");s.className="weibei-math-preview";let a=document.createElement(i?"textarea":"input");a.className="weibei-math-source",a.setAttribute("aria-label",ue(i?"slashBlockMath":"slashInlineMath")),a.setAttribute("autocapitalize","none"),a.setAttribute("autocomplete","off"),a.setAttribute("spellcheck","false"),a instanceof HTMLInputElement&&(a.type="text"),o.append(s,a);let l=!1,c=0,u=()=>i?String(r.attrs.value||""):r.textContent,f=async(h=u())=>{let m=c+=1;o.dataset.value=h,s.replaceChildren(),s.textContent=h||"\u516C\u5F0F";let g=(y,x=!1)=>{m!==c||x&&!o.isConnected||(s.replaceChildren(),At(st,"katexRenders"),y.render(h,s,{throwOnError:!0,strict:!1,trust:!1,displayMode:i}),o.classList.remove("weibei-math-invalid"),o.removeAttribute("title"))};try{let y=qw();y?g(y):g(await Vw(),!0)}catch{if(m!==c)return;s.textContent=h||"\u516C\u5F0F",o.classList.add("weibei-math-invalid"),o.title=Kr==="en"?"Not displayable yet; keep editing.":"\u6682\u65F6\u65E0\u6CD5\u663E\u793A\uFF0C\u7EE7\u7EED\u7F16\u8F91\u5373\u53EF"}},d=h=>{!ie&&h||(l=h,o.classList.toggle("weibei-math-editing",h),h&&(a.value=u(),a.focus(),a.select()))},p=()=>{let h=a.value;d(!1);let m=n();if(typeof m!="number")return;if(h===u()){e.dispatch(e.state.tr.setSelection(H.create(e.state.doc,m))),f(),e.focus();return}let g=i?r.type.create({...r.attrs,value:h}):r.type.create(r.attrs,h?e.state.schema.text(h):null,r.marks),y=e.state.tr.replaceWith(m,m+r.nodeSize,g);y.setSelection(H.create(y.doc,m)),e.dispatch(y.scrollIntoView()),e.focus()};return o.addEventListener("click",h=>{!l&&h.target!==a&&d(!0)}),o.addEventListener("weibei-edit-math",()=>d(!0)),o.addEventListener("keydown",h=>{let m=h;if(!l&&m.key==="Enter"){h.preventDefault(),d(!0);return}l&&(m.key==="Escape"||m.key==="Enter"&&(!i||m.metaKey))&&(h.preventDefault(),p())}),a.addEventListener("input",()=>f(a.value)),a.addEventListener("blur",p),f(),{dom:o,update(h){if(h.type!==r.type)return!1;let m=(i?h.attrs.value:h.textContent)!==u();return r=h,m&&!l&&f(),!0},selectNode(){o.classList.add("ProseMirror-selectednode")},deselectNode(){o.classList.remove("ProseMirror-selectednode")},stopEvent(h){return h.target===a||a.contains(h.target)},ignoreMutation(){return!0}}},_D=(t,e,n)=>{let r=document.createElement("pre");r.className="weibei-code-block";let i=document.createElement("input");i.type="text",i.className="weibei-code-language-input",i.maxLength=32,i.setAttribute("autocomplete","off"),i.setAttribute("autocapitalize","none"),i.setAttribute("spellcheck","false");let o=document.createElement("code");o.setAttribute("autocapitalize","none"),o.setAttribute("autocorrect","off"),o.setAttribute("spellcheck","false"),r.append(i,o);let s=String(t.attrs.language||""),a=tt,l=je,c=Gn,u=()=>{r.dataset.language=s,i.value=s,i.placeholder=ue("codeLanguagePlaceholder"),i.setAttribute("aria-label",ue("codeLanguage")),i.readOnly=!ie,i.tabIndex=ie?0:-1,i.setAttribute("aria-readonly",i.readOnly?"true":"false")},f=()=>{let p=i.value.trim().split(/\s+/u)[0]?.slice(0,32)||"";if(i.value=p,!ie||p===s||a!==tt||l!==je||c!==Gn){i.value=s;return}let h=n(),m=e.state.doc.nodeAt(h);if(m?.type.name!=="code_block"||String(m.attrs.language||"")!==s){i.value=s;return}e.dispatch(e.state.tr.setNodeMarkup(h,void 0,{...m.attrs,language:p}))},d=p=>{if(p.key==="Escape"){i.value=s,i.blur();return}p.key==="Enter"&&(p.preventDefault(),f(),i.blur(),e.focus())};return i.addEventListener("change",f),i.addEventListener("blur",f),i.addEventListener("keydown",d),u(),{dom:r,contentDOM:o,update(p){return p.type.name!=="code_block"||a!==tt||l!==je||c!==Gn?!1:(s=String(p.attrs.language||""),u(),!0)},stopEvent(p){return p.target===i||p.target instanceof Node&&i.contains(p.target)},ignoreMutation(p){return p.target===i||i.contains(p.target)},destroy(){i.removeEventListener("change",f),i.removeEventListener("blur",f),i.removeEventListener("keydown",d)}}},kp=(t,e,n)=>{let r=t,i=!1,o=document.createElement("span");o.contentEditable="false";let s=()=>{i=!1;let l=r.type.name;if(o.className=`weibei-structured-node ${l==="wiki_link"?"weibei-wikilink":l==="embed"?"weibei-embed-preview weibei-embed-note":"weibei-inline-footnote"}`,o.dataset.type=l,o.dataset.wikilinkTarget=l==="inline_footnote"?"":r.attrs.target,o.dataset.wikilinkTitle=l==="inline_footnote"?"":r.attrs.target,o.setAttribute("role",l==="inline_footnote"?"note":"link"),o.tabIndex=0,o.replaceChildren(),l==="embed"&&yD.test(r.attrs.target)){let c=document.createElement("img");c.className="weibei-embed-image",c.alt=r.attrs.label||r.attrs.target,c.src=o1(r.attrs.target),c.addEventListener("error",()=>{c.src=i1(),c.classList.add("weibei-image-missing")},{once:!0}),o.append(c)}else o.textContent=l==="inline_footnote"?r.attrs.value:r.attrs.label||r.attrs.target;o.title=l==="inline_footnote"?ue("inlineFootnote",{value:r.attrs.value}):ue(l==="embed"?"embed":"openOrCreateNote",{value:r.attrs.target})},a=()=>{if(!ie||i)return;i=!0;let l=r.type.name==="inline_footnote",c=document.createElement("input"),u=document.createElement("input");c.className=u.className="weibei-structured-input",c.value=l?r.attrs.value:r.attrs.target,u.value=l?"":r.attrs.label,c.setAttribute("aria-label",l?"\u811A\u6CE8":"\u76EE\u6807"),u.setAttribute("aria-label","\u6807\u9898"),u.placeholder="\u6807\u9898";let f=p=>{if(i)if(i=!1,p){let h=n();if((typeof h=="number"?e.state.doc.nodeAt(h):null)?.type===r.type){let g=l?{value:c.value}:{target:c.value.trim(),label:u.value.trim(),raw:`${c.value.trim()}${u.value.trim()?`|${u.value.trim()}`:""}`};e.dispatch(e.state.tr.setNodeMarkup(h,void 0,g))}}else s()},d=p=>{p.key==="Enter"&&(p.preventDefault(),f(!0)),p.key==="Escape"&&(p.preventDefault(),f(!1))};c.addEventListener("keydown",d),u.addEventListener("keydown",d),o.replaceChildren(c),l||o.append(u),o.addEventListener("focusout",()=>window.setTimeout(()=>{o.contains(document.activeElement)||f(!0)}),{once:!0}),c.focus(),c.select()};return o.addEventListener("click",l=>{ie&&(l.preventDefault(),l.stopPropagation(),a())}),o.addEventListener("weibei-edit-structured",a),Ms.add(s),s(),{dom:o,update(l){return l.type!==r.type?!1:(r=l,i||s(),!0)},selectNode(){o.classList.add("ProseMirror-selectednode")},deselectNode(){o.classList.remove("ProseMirror-selectednode")},stopEvent(l){return l.target instanceof HTMLInputElement},ignoreMutation(){return!0},destroy(){Ms.delete(s)}}},HD=(t,e,n)=>{let r=t,i=document.createElement("blockquote"),o=document.createElement("div"),s=document.createElement("select"),a=document.createElement("input"),l=document.createElement("div"),c=document.createElement("div");o.className="weibei-callout-header",s.className="weibei-callout-type",a.className="weibei-callout-title",a.placeholder="\u6807\u9898",l.className="weibei-callout-content",c.className="weibei-callout-collapse",o.append(s,a),c.append(l),i.append(o,c);let u=()=>{let d=String(r.attrs.calloutType||"note"),p=gp.has(d)?Array.from(gp):[d,...gp];s.replaceChildren(...p.map(h=>{let m=document.createElement("option");return m.value=h,m.textContent=b0(h),m})),s.value=d,a.value=r.attrs.title||"",s.disabled=!ie,a.readOnly=!ie,i.className=`weibei-callout weibei-callout-has-heading weibei-callout-${d}`,i.dataset.type="callout",i.dataset.callout=d,i.dataset.calloutFold=r.attrs.fold||"",i.dataset.calloutTitle=r.attrs.title||b0(d)},f=()=>{let d=n();(ie&&typeof d=="number"?e.state.doc.nodeAt(d):null)?.type===r.type&&e.dispatch(e.state.tr.setNodeMarkup(d,void 0,{...r.attrs,calloutType:s.value,title:a.value.trim()}))};return s.addEventListener("change",f),a.addEventListener("blur",f),a.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),f(),a.blur()),d.key==="Escape"&&(d.preventDefault(),u(),a.blur())}),Ms.add(u),u(),{dom:i,contentDOM:l,update(d){return d.type!==r.type?!1:(r=d,u(),!0)},stopEvent(d){return d.target===s||d.target===a},ignoreMutation(d){return o.contains(d.target)},destroy(){Ms.delete(u)}}},WD=()=>K?K.action(t=>{let e=t.get(U),n=e.state.selection.from,r="";return e.state.doc.descendants((i,o)=>{if(!i.isText||r)return!0;let s=i.text||"",a=o,l=o+s.length;if(n<a||n>l)return!0;for(let c of s.matchAll(/\[\[([^\]\n]+)\]\]/g)){let u=a+(c.index||0),f=u+c[0].length;if(n>=u&&n<=f)return r=DD(c[1]),!1}return!0}),r}):"",d1=async t=>{let{alt:e,src:n}=await sp(t);if(!z0?.imageAttachmentRequested)return{alt:e,src:n};let r=`attachment-${Date.now()}-${Dp+=1}`;return new Promise((i,o)=>{Jn.set(r,{resolve:i,reject:o}),Le("imageAttachmentRequested",{id:r,name:t.name||e||"image",mime:t.type||"image/png",dataURL:n}),window.setTimeout(()=>{Jn.has(r)&&(Jn.delete(r),o(new Error("Attachment save timed out")))},15e3)})},jD=t=>{let e=String(t||""),n=e.trim();return n?e.includes(` + <text x="48" y="22" fill="${t.text}" font-family="-apple-system, BlinkMacSystemFont, 'Songti SC', serif" font-size="13">${Ip(ue("imageMissing"))}</text> +</svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`},s1=t=>{if(!t||/^(?:data:|blob:|weibeiimage:)/i.test(t))return t;if(/^https:/i.test(t))return v0(t);if(/^http:/i.test(t))return"";try{let e=new URL(t,H0||window.location.href).href;return/^(?:file:|https:)/i.test(e)?v0(e):/^(?:data:|blob:|weibeiimage:)/i.test(e)?e:""}catch{return""}},zp=()=>{document.body.dataset.editable=ie?"true":"false",document.querySelectorAll(".weibei-code-language-input").forEach(t=>{t instanceof HTMLInputElement&&(t.readOnly=!ie,t.tabIndex=ie?0:-1,t.setAttribute("aria-readonly",t.readOnly?"true":"false"),t.setAttribute("aria-label",ue("codeLanguage")),t.placeholder=ue("codeLanguagePlaceholder"))})},Np=new Set,Ms=new Set;var wD=(t,e,n)=>{let r=t,i=document.createElement("span"),o=document.createElement("img"),s=document.createElement("span"),a=document.createElement("button"),l=document.createElement("button"),c=document.createElement("select");i.className="weibei-image-node",i.contentEditable="false",o.className="weibei-image",s.className="weibei-image-controls",a.type=l.type="button",a.textContent="\u66F4\u6362",l.textContent="\u5220\u9664",a.setAttribute("aria-label","\u66F4\u6362\u56FE\u7247"),l.setAttribute("aria-label","\u5220\u9664\u56FE\u7247");for(let[g,y]of[["","\u539F\u5C3A\u5BF8"],["320","\u5C0F"],["560","\u4E2D"],["900","\u5927"]]){let x=document.createElement("option");x.value=g,x.textContent=y,c.append(x)}c.setAttribute("aria-label","\u56FE\u7247\u5C3A\u5BF8"),s.append(a,l,c),i.append(o,s),s.dataset.state="closed",s.setAttribute("aria-hidden","true");let u=()=>{o.dataset.weibeiImageMissingFor=o.dataset.weibeiResolvedSrc||o.getAttribute("src")||"",o.dataset.weibeiImagePlaceholder="true",o.classList.add("weibei-image-missing"),o.title=ue("imageMissing"),_t()},f=()=>{o.dataset.weibeiImagePlaceholder!=="true"&&(o.classList.remove("weibei-image-missing"),_t())},d=()=>{At(st,"imageNodeUpdates");let g=String(r.attrs.src||""),y=s1(g),x=Ol(r.attrs.alt||"");if(o.alt=x.alt,o.title=String(r.attrs.title||""),o.dataset.weibeiMarkdownSrc=g,c.value=x.size&&["320","560","900"].includes(String(x.size.width))?String(x.size.width):"",kD(o,x.size),!(o.dataset.weibeiImagePlaceholder==="true"&&o.dataset.weibeiImageMissingFor===y)){if(!y){o.dataset.weibeiImageMissingFor=y,o.dataset.weibeiImagePlaceholder="true",o.classList.add("weibei-image-missing"),o.setAttribute("src",o1());return}o.dataset.weibeiResolvedSrc=y,delete o.dataset.weibeiImagePlaceholder,o.classList.remove("weibei-image-missing"),o.setAttribute("src",y)}},p=()=>{let g=`image-picker-${Date.now()}-${Lp+=1}`;zt.set(g,{mode:"replace",view:e,getPos:n,documentID:tt,documentGeneration:je}),Le("imagePickerRequested",{id:g})},h=()=>{let g=n(),y=typeof g=="number"?e.state.doc.nodeAt(g):null;y?.type===r.type&&e.dispatch(e.state.tr.delete(g,g+y.nodeSize).scrollIntoView())},m=()=>{let g=n(),y=typeof g=="number"?e.state.doc.nodeAt(g):null;if(y?.type!==r.type)return;let C=`${Ol(y.attrs.alt||"").alt}${c.value?`|${c.value}`:""}`;e.dispatch(e.state.tr.setNodeMarkup(g,void 0,{...y.attrs,alt:C}).scrollIntoView()),e.focus()};return o.addEventListener("error",u),o.addEventListener("load",f),a.addEventListener("click",p),l.addEventListener("click",h),c.addEventListener("change",m),Np.add(d),d(),{dom:i,update(g){if(g.type!==r.type)return!1;let y=g.attrs.src!==r.attrs.src||g.attrs.alt!==r.attrs.alt||g.attrs.title!==r.attrs.title;return r=g,y&&d(),!0},selectNode(){i.classList.add("ProseMirror-selectednode"),o.classList.add("ProseMirror-selectednode"),s.dataset.state="open",s.setAttribute("aria-hidden","false")},deselectNode(){i.classList.remove("ProseMirror-selectednode"),o.classList.remove("ProseMirror-selectednode"),s.dataset.state="closed",s.setAttribute("aria-hidden","true")},stopEvent(g){return s.contains(g.target)},ignoreMutation(g){return s.contains(g.target)},destroy(){Np.delete(d),o.removeEventListener("error",u),o.removeEventListener("load",f),a.removeEventListener("click",p),l.removeEventListener("click",h),c.removeEventListener("change",m)}}},a1=()=>Np.forEach(t=>t()),$p=()=>{if(!K)return null;let t=K.action(e=>e.get(U).state.selection);return!t||t.empty?null:{from:t.from,to:t.to}},l1=()=>K?K.action(t=>{let{selection:e}=t.get(U).state;if(!e||e.empty)return"";let n=e.content().content;return V0(n.textBetween(0,n.size,` +`))}):"",CD=()=>V0(window.getSelection()?.toString()||l1()),Yt=(t,e,n,r,i={})=>{n<=e||t.push(le.inline(e,n,{...i,class:r}))},SD=t=>(Array.isArray(t)?t:[]).map(e=>({id:String(e?.id||""),text:String(e?.text||"").trim()})).filter(e=>e.id&&e.text.length>=4),MD=(t,e,n,r)=>{ie||Mp.length===0||Mp.forEach(i=>{let o=0,s=r.get(i.id)||0;for(;s<3;){let a=e.indexOf(i.text,o);if(a<0)break;Yt(t,n+a,n+a+i.text.length,"weibei-selection-ask-mark",{"data-thread-id":i.id,title:"\u6253\u5F00\u5F53\u65F6\u7684\u9009\u533A\u95EE\u7B54"}),s+=1,o=a+i.text.length}r.set(i.id,s)})};var ED=(t,e,n)=>{for(let r of e.matchAll(/(?:^|[\s`])((?:来源:|Source:)[^`\n]+)/g)){let i=r[0].startsWith(r[1])?0:1,o=r[1].startsWith("\u6765\u6E90\uFF1A")?"\u6765\u6E90\uFF1A":"Source:",s=n+(r.index||0)+i,a=s+r[1].length;Yt(t,s,a,"weibei-source-reference",{role:"link",tabindex:"0",title:ue("openSource",{value:r[1].slice(o.length).trim()}),"data-source-reference":r[1]})}},TD=(t,e,n,r)=>{let i=0;for(;i<e.length;){if(r.open){let a=e.indexOf("%%",i);if(a<0){Yt(t,n+i,n+e.length,"weibei-comment");return}Yt(t,n+i,n+a+2,"weibei-comment"),r.open=!1,i=a+2;continue}let o=e.indexOf("%%",i);if(o<0)return;let s=e.indexOf("%%",o+2);if(s<0){Yt(t,n+o,n+e.length,"weibei-comment"),r.open=!0;return}Yt(t,n+o,n+s+2,"weibei-comment"),i=s+2}},vD=(t,e,n)=>{for(let r of e.matchAll(/(^|\s)(#[\p{L}\p{N}_/-]+)\b/gu)){let i=n+(r.index||0)+r[1].length;Yt(t,i,i+r[2].length,"weibei-tag")}for(let r of e.matchAll(/(^|\s)(\^[A-Za-z0-9-]+)\s*$/g)){let i=n+(r.index||0)+r[1].length;Yt(t,i,i+r[2].length,"weibei-block-id")}},AD=(t,e,n)=>{for(let r of e.matchAll(/<br\s*\/?>/gi)){let i=n+(r.index||0),o=i+r[0].length;Yt(t,i,o,"weibei-html-break-source"),t.push(le.widget(o,()=>{let s=document.createElement("br");return s.className="weibei-html-break-preview",s},{side:1}))}},A0=t=>{let e=document.createElement("div");e.className="weibei-mermaid-render",e.textContent=ue("mermaidRendering");let n="\0",r=0,i=0,o=(s,a=!1)=>{let l=String(s||"");if(l===n)return;n=l;let c=i+=1;window.clearTimeout(r),r=window.setTimeout(async()=>{if(!(!e.isConnected||c!==i)){e.classList.remove("weibei-mermaid-error");try{let u=await Jw();nD(u);let f=`weibei-mermaid-${JO+=1}`;At(st,"mermaidRenders");let{svg:d,bindFunctions:p}=await u.render(f,l,e);if(!e.isConnected||c!==i)return;e.innerHTML=d,p?.(e),e.dataset.rendered="true"}catch(u){if(!e.isConnected||c!==i)return;e.classList.add("weibei-mermaid-error"),e.textContent=ue("mermaidFailed",{value:String(u?.message||u)})}_t()}},a?300:0)};return o(t),{element:e,updateSource:o}},Il=new WeakMap,$t=null,bs=!1,ID=t=>{if(!bs||!(t.selection instanceof P))return null;let{$from:e}=t.selection;for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(r.type.name==="code_block")return _p(r.attrs.language||"")!=="mermaid"?null:{node:r,pos:e.before(n)}}return null},ND=t=>{$t&&($t.documentGeneration!==je||$t.contentGeneration!==Gn||$t.generation!==Ji||t?.pos!==$t.pos)&&($t=null)},RD=(t,e,n)=>{let r=n?.pos===e;if(r&&!$t){let s=Il.get(t);$t=s?.generation===Ji?{...s,pos:e,documentGeneration:je,contentGeneration:Gn}:{...A0(t.textContent),generation:Ji,key:`mermaid-preview-${y0+=1}`,pos:e,documentGeneration:je,contentGeneration:Gn}}if(r)return $t.updateSource(t.textContent,!0),$t;let i=Il.get(t);if(i?.generation===Ji)return i.updateSource(t.textContent),i;let o={...A0(t.textContent),generation:Ji,key:`mermaid-preview-${y0+=1}`};return Il.set(t,o),o},OD=(t,e,n,r)=>{if(_p(e.attrs.language||"")!=="mermaid")return!1;t.push(le.node(n,n+e.nodeSize,{class:"weibei-code-block weibei-mermaid-block","data-language":"mermaid"}));let i=RD(e,n,r);return t.push(le.widget(n+e.nodeSize,()=>i.element,{side:-1,key:i.key})),!0},DD=t=>{let e=i1(t);return e.target||e.noteTitle},LD=t=>{let e=t instanceof Element?t.closest(".weibei-wikilink, .weibei-embed-note[data-wikilink-title]"):null;return e?.getAttribute("data-wikilink-title")||e?.textContent?.trim()||""},Rp=t=>{let e=LD(t);return e?(Le("wikiLinkActivated",{title:e}),!0):!1},BD=t=>(t instanceof Element?t.closest(".weibei-source-reference[data-source-reference]"):null)?.getAttribute("data-source-reference")||"",Op=t=>{let e=BD(t);return e?(Le("sourceReferenceActivated",{reference:e}),!0):!1},c1=t=>{let e=t instanceof Element?t.closest(".weibei-selection-ask-mark[data-thread-id]"):null,n=e?.getAttribute("data-thread-id")||"";return n?(Le("selectionAskMark",{threadId:n,text:e.textContent||""}),!0):!1},u1=t=>{if(ie||!(t instanceof Element))return!1;let e=t.closest('blockquote.weibei-callout[data-callout-fold="-"]');return e?(e.classList.toggle("weibei-callout-open"),!0):!1},_p=t=>{let e=(t||"").trim().toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",sh:"bash",shell:"bash",zsh:"bash",md:"markdown",yml:"yaml"}[e]||e},f1=t=>typeof t=="string"?t.length:Array.isArray(t.content)?t.content.reduce((e,n)=>e+f1(n),0):String(t.content||"").length,PD=t=>{let e=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return["weibei-prism-token","token",t.type,...e].filter(Boolean).join(" ")},I0=new WeakMap,FD=new Set(["bash","css","do","java","javascript","json","jsx","markdown","python","r","ruby","rust","sql","stata","swift","tsx","typescript","yaml"]),ws=null,N0=!1,zD=()=>{ws||N0||(N0=!0,Gw().then(t=>{ws=t,Yi+=1,K?.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiPrismReady",!0))})}).catch(Qi))},d1=(t,e,n)=>{let r=n;for(let i of e){let o=f1(i);typeof i!="string"&&o>0&&(t.push({from:r,to:r+o,className:PD(i)}),Array.isArray(i.content)&&d1(t,i.content,r)),r+=o}},$D=(t,e,n)=>{let r=_p(e.attrs.language||"");if(!FD.has(r))return;if(!ws){zD();return}let i=I0.get(e);try{i||(At(st,"codeTokenizations"),i=[],d1(i,ws.tokenize(e.textContent,ws.languages[r]),0),I0.set(e,i)),i.forEach(o=>Yt(t,n+1+o.from,n+1+o.to,o.className))}catch{}};var R0=(t,e,n)=>{let r=t,i=r.type.name==="math_block",o=document.createElement(i?"div":"span");o.className=`weibei-math-node ${i?"weibei-math-block":"weibei-math-inline"}`,o.dataset.type=r.type.name,o.contentEditable="false",o.tabIndex=0;let s=document.createElement(i?"div":"span");s.className="weibei-math-preview";let a=document.createElement(i?"textarea":"input");a.className="weibei-math-source",a.setAttribute("aria-label",ue(i?"slashBlockMath":"slashInlineMath")),a.setAttribute("autocapitalize","none"),a.setAttribute("autocomplete","off"),a.setAttribute("spellcheck","false"),a instanceof HTMLInputElement&&(a.type="text"),o.append(s,a);let l=!1,c=0,u=()=>i?String(r.attrs.value||""):r.textContent,f=async(h=u())=>{let m=c+=1;o.dataset.value=h,s.replaceChildren(),s.textContent=h||"\u516C\u5F0F";let g=(y,x=!1)=>{m!==c||x&&!o.isConnected||(s.replaceChildren(),At(st,"katexRenders"),y.render(h,s,{throwOnError:!0,strict:!1,trust:!1,displayMode:i}),o.classList.remove("weibei-math-invalid"),o.removeAttribute("title"))};try{let y=Uw();y?g(y):g(await Kw(),!0)}catch{if(m!==c)return;s.textContent=h||"\u516C\u5F0F",o.classList.add("weibei-math-invalid"),o.title=Kr==="en"?"Not displayable yet; keep editing.":"\u6682\u65F6\u65E0\u6CD5\u663E\u793A\uFF0C\u7EE7\u7EED\u7F16\u8F91\u5373\u53EF"}},d=h=>{!ie&&h||(l=h,o.classList.toggle("weibei-math-editing",h),h&&(a.value=u(),a.focus(),a.select()))},p=()=>{let h=a.value;d(!1);let m=n();if(typeof m!="number")return;if(h===u()){e.dispatch(e.state.tr.setSelection(H.create(e.state.doc,m))),f(),e.focus();return}let g=i?r.type.create({...r.attrs,value:h}):r.type.create(r.attrs,h?e.state.schema.text(h):null,r.marks),y=e.state.tr.replaceWith(m,m+r.nodeSize,g);y.setSelection(H.create(y.doc,m)),e.dispatch(y.scrollIntoView()),e.focus()};return o.addEventListener("click",h=>{!l&&h.target!==a&&d(!0)}),o.addEventListener("weibei-edit-math",()=>d(!0)),o.addEventListener("keydown",h=>{let m=h;if(!l&&m.key==="Enter"){h.preventDefault(),d(!0);return}l&&(m.key==="Escape"||m.key==="Enter"&&(!i||m.metaKey))&&(h.preventDefault(),p())}),a.addEventListener("input",()=>f(a.value)),a.addEventListener("blur",p),f(),{dom:o,update(h){if(h.type!==r.type)return!1;let m=(i?h.attrs.value:h.textContent)!==u();return r=h,m&&!l&&f(),!0},selectNode(){o.classList.add("ProseMirror-selectednode")},deselectNode(){o.classList.remove("ProseMirror-selectednode")},stopEvent(h){return h.target===a||a.contains(h.target)},ignoreMutation(){return!0}}},_D=(t,e,n)=>{let r=document.createElement("pre");r.className="weibei-code-block";let i=document.createElement("input");i.type="text",i.className="weibei-code-language-input",i.maxLength=32,i.setAttribute("autocomplete","off"),i.setAttribute("autocapitalize","none"),i.setAttribute("spellcheck","false");let o=document.createElement("code");o.setAttribute("autocapitalize","none"),o.setAttribute("autocorrect","off"),o.setAttribute("spellcheck","false"),r.append(i,o);let s=String(t.attrs.language||""),a=tt,l=je,c=Gn,u=()=>{r.dataset.language=s,i.value=s,i.placeholder=ue("codeLanguagePlaceholder"),i.setAttribute("aria-label",ue("codeLanguage")),i.readOnly=!ie,i.tabIndex=ie?0:-1,i.setAttribute("aria-readonly",i.readOnly?"true":"false")},f=()=>{let p=i.value.trim().split(/\s+/u)[0]?.slice(0,32)||"";if(i.value=p,!ie||p===s||a!==tt||l!==je||c!==Gn){i.value=s;return}let h=n(),m=e.state.doc.nodeAt(h);if(m?.type.name!=="code_block"||String(m.attrs.language||"")!==s){i.value=s;return}e.dispatch(e.state.tr.setNodeMarkup(h,void 0,{...m.attrs,language:p}))},d=p=>{if(p.key==="Escape"){i.value=s,i.blur();return}p.key==="Enter"&&(p.preventDefault(),f(),i.blur(),e.focus())};return i.addEventListener("change",f),i.addEventListener("blur",f),i.addEventListener("keydown",d),u(),{dom:r,contentDOM:o,update(p){return p.type.name!=="code_block"||a!==tt||l!==je||c!==Gn?!1:(s=String(p.attrs.language||""),u(),!0)},stopEvent(p){return p.target===i||p.target instanceof Node&&i.contains(p.target)},ignoreMutation(p){return p.target===i||i.contains(p.target)},destroy(){i.removeEventListener("change",f),i.removeEventListener("blur",f),i.removeEventListener("keydown",d)}}},kp=(t,e,n)=>{let r=t,i=!1,o=document.createElement("span");o.contentEditable="false";let s=()=>{i=!1;let l=r.type.name;if(o.className=`weibei-structured-node ${l==="wiki_link"?"weibei-wikilink":l==="embed"?"weibei-embed-preview weibei-embed-note":"weibei-inline-footnote"}`,o.dataset.type=l,o.dataset.wikilinkTarget=l==="inline_footnote"?"":r.attrs.target,o.dataset.wikilinkTitle=l==="inline_footnote"?"":r.attrs.target,o.setAttribute("role",l==="inline_footnote"?"note":"link"),o.tabIndex=0,o.replaceChildren(),l==="embed"&&yD.test(r.attrs.target)){let c=document.createElement("img");c.className="weibei-embed-image",c.alt=r.attrs.label||r.attrs.target,c.src=s1(r.attrs.target),c.addEventListener("error",()=>{c.src=o1(),c.classList.add("weibei-image-missing")},{once:!0}),o.append(c)}else o.textContent=l==="inline_footnote"?r.attrs.value:r.attrs.label||r.attrs.target;o.title=l==="inline_footnote"?ue("inlineFootnote",{value:r.attrs.value}):ue(l==="embed"?"embed":"openOrCreateNote",{value:r.attrs.target})},a=()=>{if(!ie||i)return;i=!0;let l=r.type.name==="inline_footnote",c=document.createElement("input"),u=document.createElement("input");c.className=u.className="weibei-structured-input",c.value=l?r.attrs.value:r.attrs.target,u.value=l?"":r.attrs.label,c.setAttribute("aria-label",l?"\u811A\u6CE8":"\u76EE\u6807"),u.setAttribute("aria-label","\u6807\u9898"),u.placeholder="\u6807\u9898";let f=p=>{if(i)if(i=!1,p){let h=n();if((typeof h=="number"?e.state.doc.nodeAt(h):null)?.type===r.type){let g=l?{value:c.value}:{target:c.value.trim(),label:u.value.trim(),raw:`${c.value.trim()}${u.value.trim()?`|${u.value.trim()}`:""}`};e.dispatch(e.state.tr.setNodeMarkup(h,void 0,g))}}else s()},d=p=>{p.key==="Enter"&&(p.preventDefault(),f(!0)),p.key==="Escape"&&(p.preventDefault(),f(!1))};c.addEventListener("keydown",d),u.addEventListener("keydown",d),o.replaceChildren(c),l||o.append(u),o.addEventListener("focusout",()=>window.setTimeout(()=>{o.contains(document.activeElement)||f(!0)}),{once:!0}),c.focus(),c.select()};return o.addEventListener("click",l=>{ie&&(l.preventDefault(),l.stopPropagation(),a())}),o.addEventListener("weibei-edit-structured",a),Ms.add(s),s(),{dom:o,update(l){return l.type!==r.type?!1:(r=l,i||s(),!0)},selectNode(){o.classList.add("ProseMirror-selectednode")},deselectNode(){o.classList.remove("ProseMirror-selectednode")},stopEvent(l){return l.target instanceof HTMLInputElement},ignoreMutation(){return!0},destroy(){Ms.delete(s)}}},HD=(t,e,n)=>{let r=t,i=document.createElement("blockquote"),o=document.createElement("div"),s=document.createElement("select"),a=document.createElement("input"),l=document.createElement("div"),c=document.createElement("div");o.className="weibei-callout-header",s.className="weibei-callout-type",a.className="weibei-callout-title",a.placeholder="\u6807\u9898",l.className="weibei-callout-content",c.className="weibei-callout-collapse",o.append(s,a),c.append(l),i.append(o,c);let u=()=>{let d=String(r.attrs.calloutType||"note"),p=gp.has(d)?Array.from(gp):[d,...gp];s.replaceChildren(...p.map(h=>{let m=document.createElement("option");return m.value=h,m.textContent=w0(h),m})),s.value=d,a.value=r.attrs.title||"",s.disabled=!ie,a.readOnly=!ie,i.className=`weibei-callout weibei-callout-has-heading weibei-callout-${d}`,i.dataset.type="callout",i.dataset.callout=d,i.dataset.calloutFold=r.attrs.fold||"",i.dataset.calloutTitle=r.attrs.title||w0(d)},f=()=>{let d=n();(ie&&typeof d=="number"?e.state.doc.nodeAt(d):null)?.type===r.type&&e.dispatch(e.state.tr.setNodeMarkup(d,void 0,{...r.attrs,calloutType:s.value,title:a.value.trim()}))};return s.addEventListener("change",f),a.addEventListener("blur",f),a.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),f(),a.blur()),d.key==="Escape"&&(d.preventDefault(),u(),a.blur())}),Ms.add(u),u(),{dom:i,contentDOM:l,update(d){return d.type!==r.type?!1:(r=d,u(),!0)},stopEvent(d){return d.target===s||d.target===a},ignoreMutation(d){return o.contains(d.target)},destroy(){Ms.delete(u)}}},WD=()=>K?K.action(t=>{let e=t.get(U),n=e.state.selection.from,r="";return e.state.doc.descendants((i,o)=>{if(!i.isText||r)return!0;let s=i.text||"",a=o,l=o+s.length;if(n<a||n>l)return!0;for(let c of s.matchAll(/\[\[([^\]\n]+)\]\]/g)){let u=a+(c.index||0),f=u+c[0].length;if(n>=u&&n<=f)return r=DD(c[1]),!1}return!0}),r}):"",p1=async t=>{let{alt:e,src:n}=await sp(t);if(!$0?.imageAttachmentRequested)return{alt:e,src:n};let r=`attachment-${Date.now()}-${Lp+=1}`;return new Promise((i,o)=>{Jn.set(r,{resolve:i,reject:o}),Le("imageAttachmentRequested",{id:r,name:t.name||e||"image",mime:t.type||"image/png",dataURL:n}),window.setTimeout(()=>{Jn.has(r)&&(Jn.delete(r),o(new Error("Attachment save timed out")))},15e3)})},jD=t=>{let e=String(t||""),n=e.trim();return n?e.includes(` `)?!0:/^(?:#{1,6}\s|[-*+]\s|\d+\.\s|>\s|```|~~~|\$\$|\|.*\||---$)/.test(n):!1},VD=t=>{let e=String(t||"");return jD(e)?` ${e.trim()} -`:e},qD=()=>K.action(t=>{let e=t.get(U),n=null,r=null;if(e.state.doc.descendants((s,a)=>{if(!s.isText||n||r)return!0;let l=s.text||"",c=l.indexOf(mp),u=l.indexOf(y0);if(c>=0&&u>c)return n={startFrom:a+c,startTo:a+c+mp.length,endFrom:a+u,endTo:a+u+y0.length},!1;let f=l.indexOf(g0);return f<0?!0:(r={from:a+f,to:a+f+g0.length},!1)}),n){let s=e.state.tr.delete(n.endFrom,n.endTo).delete(n.startFrom,n.startTo),a=Math.min(n.startFrom,s.doc.content.size),l=Math.min(Math.max(a,n.endFrom-mp.length),s.doc.content.size);return s.setSelection(P.create(s.doc,a,l)),e.dispatch(s),!0}if(!r)return!1;let i=e.state.tr.delete(r.from,r.to),o=Math.min(r.from,i.doc.content.size);return i.setSelection(P.create(i.doc,o)),e.dispatch(i),!0}),KD=()=>K.action(t=>{let e=t.get(U),n=Math.min(e.state.selection.to,e.state.doc.content.size);e.dispatch(e.state.tr.setSelection(P.create(e.state.doc,n)))}),UD=async(t,e)=>{if(!ie)return[];let n=[];for(let o=0;o<t.length;o+=1){let s=t.item(o);s&&s.type.includes("image")&&n.push(s)}let r=e.nodes.image;return!r||n.length===0?[]:(await Promise.all(n.map(d1))).map(({alt:o,src:s})=>r.createAndFill({alt:o,src:s})).filter(Boolean)},R0=t=>Array.from(t||[]).map(e=>e.getAsFile?.()).filter(e=>e&&e.type.includes("image")),JD=({alt:t,src:e})=>{let n=(t||"image").replace(/[\[\]\n\r]/g," ").trim()||"image",r=String(e||"").replace(/\s/g,"%20").replace(/\)/g,"%29");return`![${n}](${r})`},O0=async t=>{if(!ie)return;let e=await Promise.all(t.map(d1));Es(e.map(JD).join(` +`:e},qD=()=>K.action(t=>{let e=t.get(U),n=null,r=null;if(e.state.doc.descendants((s,a)=>{if(!s.isText||n||r)return!0;let l=s.text||"",c=l.indexOf(mp),u=l.indexOf(b0);if(c>=0&&u>c)return n={startFrom:a+c,startTo:a+c+mp.length,endFrom:a+u,endTo:a+u+b0.length},!1;let f=l.indexOf(k0);return f<0?!0:(r={from:a+f,to:a+f+k0.length},!1)}),n){let s=e.state.tr.delete(n.endFrom,n.endTo).delete(n.startFrom,n.startTo),a=Math.min(n.startFrom,s.doc.content.size),l=Math.min(Math.max(a,n.endFrom-mp.length),s.doc.content.size);return s.setSelection(P.create(s.doc,a,l)),e.dispatch(s),!0}if(!r)return!1;let i=e.state.tr.delete(r.from,r.to),o=Math.min(r.from,i.doc.content.size);return i.setSelection(P.create(i.doc,o)),e.dispatch(i),!0}),KD=()=>K.action(t=>{let e=t.get(U),n=Math.min(e.state.selection.to,e.state.doc.content.size);e.dispatch(e.state.tr.setSelection(P.create(e.state.doc,n)))}),UD=async(t,e)=>{if(!ie)return[];let n=[];for(let o=0;o<t.length;o+=1){let s=t.item(o);s&&s.type.includes("image")&&n.push(s)}let r=e.nodes.image;return!r||n.length===0?[]:(await Promise.all(n.map(p1))).map(({alt:o,src:s})=>r.createAndFill({alt:o,src:s})).filter(Boolean)},O0=t=>Array.from(t||[]).map(e=>e.getAsFile?.()).filter(e=>e&&e.type.includes("image")),JD=({alt:t,src:e})=>{let n=(t||"image").replace(/[\[\]\n\r]/g," ").trim()||"image",r=String(e||"").replace(/\s/g,"%20").replace(/\)/g,"%29");return`![${n}](${r})`},D0=async t=>{if(!ie)return;let e=await Promise.all(t.map(p1));Es(e.map(JD).join(` -`))},GD="#editor, .ProseMirror pre, .weibei-math-block",bp=new WeakMap,XD=t=>{if(!(t instanceof Element))return;t.classList.add("weibei-scroll-active");let e=bp.get(t);e&&window.clearTimeout(e),bp.set(t,window.setTimeout(()=>{t.classList.remove("weibei-scroll-active"),bp.delete(t)},850))},YD=()=>{document.addEventListener("scroll",t=>{let e=t.target instanceof Element?t.target.closest(GD):null;e&&XD(e)},!0)},QD=new Set(["list_item","task_list_item"]),p1=t=>(t.textContent||"").replace(/[\u200B\uFEFF]/g,"").trim(),D0=t=>{let{selection:e}=t;if(!e.empty)return null;let{$from:n}=e;for(let r=n.depth;r>0;r-=1){let i=n.node(r);if(QD.has(i.type.name))return p1(i).length>0?null:i.type}return null},ZD=t=>{let{state:e}=t,{$from:n}=e.selection,r=n.parent;if(r?.isTextblock!==!0||!r.textContent||p1(r).length>0)return;let i=n.start(),o=n.end(),s=e.tr.delete(i,o);s.setSelection(P.create(s.doc,Math.min(i,s.doc.content.size))),t.dispatch(s)},eL=t=>{let e=D0(t.state);return e?(ZD(t),e=D0(t.state)||e,Wa(e)(t.state,t.dispatch,t)):!1},tL=(t,e)=>{if(!ie||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||!["Backspace","Delete"].includes(e.key))return!1;let{selection:n,schema:r}=t.state;return n instanceof P&&n.empty&&n.$from.parent.type.spec.code===!0&&n.$from.parent.content.size===0&&!!(r.nodes.paragraph&&Dn(r.nodes.paragraph)(t.state,t.dispatch))},nL=(t,e)=>{if(!ie||e.key!=="Tab"||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof P)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(" "));return t.dispatch(r.setSelection(P.create(r.doc,n.from+1)).scrollIntoView()),!0},rL=new Set(["-","'",'"']),iL=(t,e)=>{if(!ie||!rL.has(e.key)||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof P)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(e.key));return t.dispatch(r.setSelection(P.create(r.doc,n.from+e.key.length)).scrollIntoView()),!0},oL=(t,e)=>{if(!ie||e.inputType!=="insertReplacementText"||e.isComposing||!e.cancelable)return!1;let{selection:n}=t.state;return!(n instanceof P)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0?!1:(e.preventDefault(),e.stopImmediatePropagation(),!0)},sL=(t,e)=>{if(!ie||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||!["ArrowRight","ArrowDown"].includes(e.key))return!1;let{selection:n}=t.state;if(!(n instanceof P)||!n.empty||n.$from.parent.type.spec.code!==!0)return!1;let{$from:r}=n;return r.indexAfter(-1)!==r.node(-1).childCount||e.key==="ArrowRight"&&r.parentOffset!==r.parent.content.size||e.key==="ArrowDown"&&!t.endOfTextblock("down")&&r.parentOffset!==r.parent.content.size?!1:Qc(t.state,t.dispatch)},aL=(t,e)=>{if(!ie||e.key!=="Tab"||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||!Re(t.state))return!1;let n=vt(t.state);if(n.bottom!==n.map.height||n.right!==n.map.width)return!1;let r=!1;return Yf(t.state,i=>{t.dispatch(i),r=!0}),r&&Xo(1)(t.state,t.dispatch,t),r},lL=(t,e)=>{if(!ie||!Re(t.state))return!1;if(e==="addRow")return Yf(t.state,t.dispatch);if(e==="deleteRow")return tl(t.state,t.dispatch);if(e==="addColumn")return Za(t.state,t.dispatch);if(e==="deleteColumn")return el(t.state,t.dispatch);if(e==="header"){let{$from:n}=t.state.selection;for(let r=n.depth;r>0;r-=1){if(n.node(r).type.name!=="table")continue;let i=Math.min(n.before(r)+4,t.state.doc.content.size);return t.dispatch(t.state.tr.setSelection(_.near(t.state.doc.resolve(i),1)).scrollIntoView()),!0}}return!1},xp=t=>{t?(Se.dataset.state="open",Se.setAttribute("aria-hidden","false")):Se.dataset.state!=="closed"&&(Se.dataset.state="closed",Se.setAttribute("aria-hidden","true"))},wp=t=>{if(Se.querySelectorAll("button").forEach(i=>{let o=ue(i.dataset.label);i.textContent=o,i.setAttribute("aria-label",o)}),!ie||!Re(t.state)){xp(!1);return}let e=t.domAtPos(t.state.selection.from).node,n=(e instanceof Element?e:e.parentElement)?.closest("td, th");if(!(n instanceof HTMLElement)){xp(!1);return}let r=n.getBoundingClientRect();Se.style.left=`${Math.max(8,Math.min(window.innerWidth-Se.offsetWidth-8,r.left))}px`,Se.style.top=`${Math.max(8,r.top-32)}px`,xp(!0)},L0={doc:null,focusedMermaidPos:null,generation:-1,decorations:ae.empty},B0=(t,e,n)=>{let r=!1,i=Math.max(0,Math.min(t.content.size,e-1)),o=Math.max(i,Math.min(t.content.size,Math.max(n,e+1)+1));return t.nodesBetween(i,o,s=>(s.type.name==="heading"&&(r=!0),!r)),r},cL=t=>t.steps.some((e,n)=>{let r=t.docs[n],i=t.docs[n+1]||t.doc,o=!1;return e.getMap().forEach((s,a,l,c)=>{(B0(r,s,a)||B0(i,l,c))&&(o=!0)}),o}),uL=pe(()=>new X({state:{init:()=>null,apply:(t,e,n,r)=>(At(st,"transactions"),t.docChanged&&!Cp&&(Mn=i0(Mn,!0),Le("dirtyChanged",{dirty:Mn.dirty})),t.docChanged&&cL(t)&&jp(r.doc),e)},view(t){let e={autocapitalize:"none",autocorrect:"off",spellcheck:"false"},n=new Map(Object.keys(e).map(h=>[h,t.dom.getAttribute(h)])),r=h=>{if(h.state.selection.$from.parent.type.spec.code===!0){for(let[m,g]of Object.entries(e))h.dom.setAttribute(m,g);return}for(let[m,g]of n)g===null?h.dom.removeAttribute(m):h.dom.setAttribute(m,g)},i=h=>{let m=h.state.doc;h.dom.classList.toggle("weibei-empty-document",m.childCount===1&&m.firstChild?.type.name==="paragraph"&&m.firstChild.content.size===0),h.dom.dataset.emptyPlaceholder=ue("emptyNotePlaceholder")},o=h=>{bs!==h&&(bs=h,t.dispatch(t.state.tr.setMeta("weibeiMermaidFocusChanged",h)))},s=h=>o(h.target===t.dom),a=h=>{h.target===t.dom&&o(!1)},l=()=>{Dl=to,Nl=!1;let{$from:h}=t.state.selection;xs=h.parent.isTextblock&&h.parent.content.size===0?h.before(h.depth):null},c=()=>{Nl=!0,setTimeout(dL)},u=h=>{h.target!==t.dom||!t.hasFocus()||!nL(t,h)&&!iL(t,h)||(h.preventDefault(),h.stopImmediatePropagation())},f=h=>{h.target===t.dom&&oL(t,h)},d=h=>h.preventDefault(),p=h=>{let m=h.target instanceof Element?h.target.closest("button[data-action]"):null;m instanceof HTMLElement&&(lL(t,m.dataset.action||""),t.focus(),window.requestAnimationFrame(()=>wp(t)))};return t.dom.addEventListener("focus",s,!0),t.dom.addEventListener("blur",a,!0),t.dom.addEventListener("compositionstart",l,!0),t.dom.addEventListener("compositionend",c,!0),t.dom.addEventListener("keydown",u,!0),t.dom.addEventListener("beforeinput",f,!0),Se.addEventListener("mousedown",d),Se.addEventListener("click",p),document.body.appendChild(Se),r(t),i(t),wp(t),bs=t.hasFocus(),{update(h,m){r(h),i(h),wp(h),!h.state.doc.eq(m.doc)&&(_t(),eo())},destroy(){t.dom.removeEventListener("focus",s,!0),t.dom.removeEventListener("blur",a,!0),t.dom.removeEventListener("compositionstart",l,!0),t.dom.removeEventListener("compositionend",c,!0),t.dom.removeEventListener("keydown",u,!0),t.dom.removeEventListener("beforeinput",f,!0),Se.removeEventListener("mousedown",d),Se.removeEventListener("click",p),Se.remove();for(let[h,m]of n)m===null?t.dom.removeAttribute(h):t.dom.setAttribute(h,m);bs=!1,$t=null,Il=new WeakMap}}},props:{handlePaste:(t,e)=>{if(!ie)return!1;let n=R0(e.clipboardData?.items);if(n.length>0)return e.preventDefault(),O0(n).catch(Qi),!0;let r=e.clipboardData?.getData("text/plain")||"",i=qr(r,"userPaste");return!r||i===r?!1:(e.preventDefault(),Es(i),!0)},handleDrop:(t,e)=>{if(!ie)return!1;let n=R0(e.dataTransfer?.items);return n.length===0?!1:(e.preventDefault(),O0(n).catch(Qi),!0)},handleTextInput:(t,e,n,r)=>{if(!ie)return!1;let i=String(r||"");if(!i)return!1;let o=Math.min(12,e),a=`${t.state.doc.textBetween(e-o,e,` +`))},GD="#editor, .ProseMirror pre, .weibei-math-block",bp=new WeakMap,XD=t=>{if(!(t instanceof Element))return;t.classList.add("weibei-scroll-active");let e=bp.get(t);e&&window.clearTimeout(e),bp.set(t,window.setTimeout(()=>{t.classList.remove("weibei-scroll-active"),bp.delete(t)},850))},YD=()=>{document.addEventListener("scroll",t=>{let e=t.target instanceof Element?t.target.closest(GD):null;e&&XD(e)},!0)},QD=new Set(["list_item","task_list_item"]),h1=t=>(t.textContent||"").replace(/[\u200B\uFEFF]/g,"").trim(),L0=t=>{let{selection:e}=t;if(!e.empty)return null;let{$from:n}=e;for(let r=n.depth;r>0;r-=1){let i=n.node(r);if(QD.has(i.type.name))return h1(i).length>0?null:i.type}return null},ZD=t=>{let{state:e}=t,{$from:n}=e.selection,r=n.parent;if(r?.isTextblock!==!0||!r.textContent||h1(r).length>0)return;let i=n.start(),o=n.end(),s=e.tr.delete(i,o);s.setSelection(P.create(s.doc,Math.min(i,s.doc.content.size))),t.dispatch(s)},eL=t=>{let e=L0(t.state);return e?(ZD(t),e=L0(t.state)||e,Wa(e)(t.state,t.dispatch,t)):!1},tL=(t,e)=>{if(!ie||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||!["Backspace","Delete"].includes(e.key))return!1;let{selection:n,schema:r}=t.state;return n instanceof P&&n.empty&&n.$from.parent.type.spec.code===!0&&n.$from.parent.content.size===0&&!!(r.nodes.paragraph&&Dn(r.nodes.paragraph)(t.state,t.dispatch))},nL=(t,e)=>{if(!ie||e.key!=="Tab"||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof P)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(" "));return t.dispatch(r.setSelection(P.create(r.doc,n.from+1)).scrollIntoView()),!0},rL=new Set(["-","'",'"']),iL=(t,e)=>{if(!ie||!rL.has(e.key)||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof P)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(e.key));return t.dispatch(r.setSelection(P.create(r.doc,n.from+e.key.length)).scrollIntoView()),!0},oL=(t,e)=>{if(!ie||e.inputType!=="insertReplacementText"||e.isComposing||!e.cancelable)return!1;let{selection:n}=t.state;return!(n instanceof P)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0?!1:(e.preventDefault(),e.stopImmediatePropagation(),!0)},sL=(t,e)=>{if(!ie||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||!["ArrowRight","ArrowDown"].includes(e.key))return!1;let{selection:n}=t.state;if(!(n instanceof P)||!n.empty||n.$from.parent.type.spec.code!==!0)return!1;let{$from:r}=n;return r.indexAfter(-1)!==r.node(-1).childCount||e.key==="ArrowRight"&&r.parentOffset!==r.parent.content.size||e.key==="ArrowDown"&&!t.endOfTextblock("down")&&r.parentOffset!==r.parent.content.size?!1:Qc(t.state,t.dispatch)},aL=(t,e)=>{if(!ie||e.key!=="Tab"||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||!Re(t.state))return!1;let n=vt(t.state);if(n.bottom!==n.map.height||n.right!==n.map.width)return!1;let r=!1;return Yf(t.state,i=>{t.dispatch(i),r=!0}),r&&Xo(1)(t.state,t.dispatch,t),r},lL=(t,e)=>{if(!ie||!Re(t.state))return!1;if(e==="addRow")return Yf(t.state,t.dispatch);if(e==="deleteRow")return tl(t.state,t.dispatch);if(e==="addColumn")return Za(t.state,t.dispatch);if(e==="deleteColumn")return el(t.state,t.dispatch);if(e==="header"){let{$from:n}=t.state.selection;for(let r=n.depth;r>0;r-=1){if(n.node(r).type.name!=="table")continue;let i=Math.min(n.before(r)+4,t.state.doc.content.size);return t.dispatch(t.state.tr.setSelection(_.near(t.state.doc.resolve(i),1)).scrollIntoView()),!0}}return!1},xp=t=>{t?(Se.dataset.state="open",Se.setAttribute("aria-hidden","false")):Se.dataset.state!=="closed"&&(Se.dataset.state="closed",Se.setAttribute("aria-hidden","true"))},wp=t=>{if(Se.querySelectorAll("button").forEach(i=>{let o=ue(i.dataset.label);i.textContent=o,i.setAttribute("aria-label",o)}),!ie||!Re(t.state)){xp(!1);return}let e=t.domAtPos(t.state.selection.from).node,n=(e instanceof Element?e:e.parentElement)?.closest("td, th");if(!(n instanceof HTMLElement)){xp(!1);return}let r=n.getBoundingClientRect();Se.style.left=`${Math.max(8,Math.min(window.innerWidth-Se.offsetWidth-8,r.left))}px`,Se.style.top=`${Math.max(8,r.top-32)}px`,xp(!0)},B0={doc:null,focusedMermaidPos:null,generation:-1,decorations:oe.empty},P0=(t,e,n)=>{let r=!1,i=Math.max(0,Math.min(t.content.size,e-1)),o=Math.max(i,Math.min(t.content.size,Math.max(n,e+1)+1));return t.nodesBetween(i,o,s=>(s.type.name==="heading"&&(r=!0),!r)),r},cL=t=>t.steps.some((e,n)=>{let r=t.docs[n],i=t.docs[n+1]||t.doc,o=!1;return e.getMap().forEach((s,a,l,c)=>{(P0(r,s,a)||P0(i,l,c))&&(o=!0)}),o}),uL=pe(()=>new X({state:{init:()=>null,apply:(t,e,n,r)=>(At(st,"transactions"),t.docChanged&&!Cp&&(Mn=s0(Mn,!0),Le("dirtyChanged",{dirty:Mn.dirty})),t.docChanged&&cL(t)&&Vp(r.doc),e)},view(t){let e={autocapitalize:"none",autocorrect:"off",spellcheck:"false"},n=new Map(Object.keys(e).map(h=>[h,t.dom.getAttribute(h)])),r=h=>{if(h.state.selection.$from.parent.type.spec.code===!0){for(let[m,g]of Object.entries(e))h.dom.setAttribute(m,g);return}for(let[m,g]of n)g===null?h.dom.removeAttribute(m):h.dom.setAttribute(m,g)},i=h=>{let m=h.state.doc;h.dom.classList.toggle("weibei-empty-document",m.childCount===1&&m.firstChild?.type.name==="paragraph"&&m.firstChild.content.size===0),h.dom.dataset.emptyPlaceholder=ue("emptyNotePlaceholder")},o=h=>{bs!==h&&(bs=h,t.dispatch(t.state.tr.setMeta("weibeiMermaidFocusChanged",h)))},s=h=>o(h.target===t.dom),a=h=>{h.target===t.dom&&o(!1)},l=()=>{Dl=to,Nl=!1;let{$from:h}=t.state.selection;xs=h.parent.isTextblock&&h.parent.content.size===0?h.before(h.depth):null},c=()=>{Nl=!0,setTimeout(dL)},u=h=>{h.target!==t.dom||!t.hasFocus()||!nL(t,h)&&!iL(t,h)||(h.preventDefault(),h.stopImmediatePropagation())},f=h=>{h.target===t.dom&&oL(t,h)},d=h=>h.preventDefault(),p=h=>{let m=h.target instanceof Element?h.target.closest("button[data-action]"):null;m instanceof HTMLElement&&(lL(t,m.dataset.action||""),t.focus(),window.requestAnimationFrame(()=>wp(t)))};return t.dom.addEventListener("focus",s,!0),t.dom.addEventListener("blur",a,!0),t.dom.addEventListener("compositionstart",l,!0),t.dom.addEventListener("compositionend",c,!0),t.dom.addEventListener("keydown",u,!0),t.dom.addEventListener("beforeinput",f,!0),Se.addEventListener("mousedown",d),Se.addEventListener("click",p),document.body.appendChild(Se),r(t),i(t),wp(t),bs=t.hasFocus(),{update(h,m){r(h),i(h),wp(h),!h.state.doc.eq(m.doc)&&(_t(),eo())},destroy(){t.dom.removeEventListener("focus",s,!0),t.dom.removeEventListener("blur",a,!0),t.dom.removeEventListener("compositionstart",l,!0),t.dom.removeEventListener("compositionend",c,!0),t.dom.removeEventListener("keydown",u,!0),t.dom.removeEventListener("beforeinput",f,!0),Se.removeEventListener("mousedown",d),Se.removeEventListener("click",p),Se.remove();for(let[h,m]of n)m===null?t.dom.removeAttribute(h):t.dom.setAttribute(h,m);bs=!1,$t=null,Il=new WeakMap}}},props:{handlePaste:(t,e)=>{if(!ie)return!1;let n=O0(e.clipboardData?.items);if(n.length>0)return e.preventDefault(),D0(n).catch(Qi),!0;let r=e.clipboardData?.getData("text/plain")||"",i=qr(r,"userPaste");return!r||i===r?!1:(e.preventDefault(),Es(i),!0)},handleDrop:(t,e)=>{if(!ie)return!1;let n=O0(e.dataTransfer?.items);return n.length===0?!1:(e.preventDefault(),D0(n).catch(Qi),!0)},handleTextInput:(t,e,n,r)=>{if(!ie)return!1;let i=String(r||"");if(!i)return!1;let o=Math.min(12,e),a=`${t.state.doc.textBetween(e-o,e,` `,` -`)}${i}`.match(/<br\s*\/?>$/i);if(!a)return!1;let l=t.state.schema.nodes.hardbreak||t.state.schema.nodes.hard_break;if(!l)return!1;let c=e-(a[0].length-i.length),u=t.state.tr.replaceWith(c,n,l.create()).scrollIntoView();return u.setSelection(P.create(u.doc,Math.min(c+1,u.doc.content.size))),t.dispatch(u),!0},handleClick(t,e,n){return l1(n.target)||Np(n.target)||Rp(n.target)||c1(n.target)},handleKeyDown(t,e){if(aL(t,e))return e.preventDefault(),!0;if(fD(t,e))return!0;if(e.key==="Enter"&&t.state.selection instanceof H){let r=t.state.selection.node;if(r.type.name==="math_inline"||r.type.name==="math_block")return t.nodeDOM(t.state.selection.from)?.dispatchEvent(new CustomEvent("weibei-edit-math")),e.preventDefault(),!0}if(tL(t,e)||sL(t,e)||e.key==="Enter"&&ie&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey&&eL(t))return e.preventDefault(),!0;if(e.key!=="Enter"&&e.key!==" ")return!1;if(Rp(e.target))return e.preventDefault(),!0;if(!e.metaKey&&!e.ctrlKey)return!1;let n=WD();return n?(Le("wikiLinkActivated",{title:n}),e.preventDefault(),!0):!1},decorations(t){let e=ID(t);ND(e);let n=e?.pos??null,r=L0;if(r.doc===t.doc&&r.focusedMermaidPos===n&&r.generation===Yi)return At(st,"decorationCacheHits"),r.decorations;let i=[],o={open:!1},s=new Map;t.doc.descendants((l,c,u)=>{if(At(st,"decorationNodes"),l.type.name==="code_block")return OD(i,l,c,e)||(i.push(le.node(c,c+l.nodeSize,{class:"weibei-code-block","data-language":l.attrs.language||""})),$D(i,l,c)),!1;if(l.isText){let d=c,p=l.text||"";if((l.marks||[]).some(m=>m.type.name.toLowerCase().includes("code"))||yt!==null)return!0;AD(i,p,d),TD(i,p,d,o),ED(i,p,d),vD(i,p,d),MD(i,p,d,s)}return!0});let a=ae.create(t.doc,i);return L0={doc:t.doc,focusedMermaidPos:n,generation:Yi,decorations:a},a}}})),Xi=()=>{if(window.weiBeiSuppressSelectionReport)return;let t=CD(),e=t?mD():null,n=t&&K?K.action(o=>{let{state:s}=o.get(U),{selection:a}=s,c=["strong","emphasis","highlight","link","inlineCode"].filter(y=>s.schema.marks[y]&&s.doc.rangeHasMark(a.from,a.to,s.schema.marks[y])),u=s.schema.marks.writing_font,f,d=!1;u&&s.doc.nodesBetween(a.from,a.to,y=>{if(!y.isText)return!0;let x=u.isInSet(y.marks||[])?.attrs.font||"serif";return f===void 0?f=x:f!==x&&(d=!0),!0}),f&&!d&&c.push(`font:${f}`);let p=a instanceof H&&a.node.type.name==="math_inline";p&&c.push("inlineMath");let h=a.$from.parent.type.name;for(let y=a.$from.depth;y>0;y-=1){let x=a.$from.node(y).type.name;if(x==="blockquote"||x==="block_quote"){h="blockquote";break}}h==="heading"&&(h=`heading${a.$from.parent.attrs.level||""}`);let m="",g=s.schema.marks.link;return g&&s.doc.nodesBetween(a.from,a.to,y=>{let x=g.isInSet(y.marks||[]);return x&&!m&&(m=String(x.attrs.href||"")),!m}),{activeMarks:c,blockType:h,canConvertToMath:p||a instanceof P&&!a.empty&&a.$from.parent===a.$to.parent&&a.$from.parent.isTextblock,linkTarget:m}}):{activeMarks:[],blockType:"",canConvertToMath:!1,linkTarget:""},r=e?`${Math.round(e.x)}:${Math.round(e.y)}:${Math.round(e.width)}:${Math.round(e.height)}`:"",i=JSON.stringify(n);if(!(t===Ui.text&&r===Ui.rectKey&&i===Ui.detailKey)){if(Ui={text:t,rectKey:r,detailKey:i},!t){Qt=null,Le("selectionChanged",{text:"",rect:null,...n});return}Qt=zp(),Le("selectionChanged",{text:t,rect:e,...n})}},h1=(t,e="")=>!K||!ie||typeof t!="string"?!1:K.action(n=>{let r=n.get(U);if(r.state.selection.empty&&Qt){let l=Math.min(Qt.from,r.state.doc.content.size),c=Math.min(Qt.to,r.state.doc.content.size);l<c&&r.dispatch(r.state.tr.setSelection(P.create(r.state.doc,l,c)))}let{state:i}=r,{selection:o}=i;if(o.empty)return!1;let s=!1,a=l=>{let c=i.schema.marks[l];return!!(c&&Ln(c)(r.state,r.dispatch,r))};switch(t){case"bold":s=a("strong");break;case"italic":s=a("emphasis");break;case"highlight":s=a("highlight");break;case"inlineCode":s=a("inlineCode");break;case"font":{let l=typeof e=="string"&&K0.has(e)?e:"",c=i.schema.marks.writing_font;if(!l||!c)break;let u=i.tr.removeMark(o.from,o.to,c).addMark(o.from,o.to,c.create({font:l}));r.dispatch(u.scrollIntoView()),s=!0;break}case"link":{let l=i.schema.marks.link;if(!l)break;let c=typeof e=="string"?e.trim():"",u=i.tr.removeMark(o.from,o.to,l);c&&u.addMark(o.from,o.to,l.create({href:c})),r.dispatch(u.scrollIntoView()),s=!0;break}case"inlineMath":{let l=i.schema.nodes.math_inline,c=o instanceof H?o.node:i.doc.nodeAt(o.from);if(c?.type===l&&o.to===o.from+c.nodeSize){let p=c.textContent,h=is(p?i.tr.replaceWith(o.from,o.to,i.schema.text(p)):i.tr.delete(o.from,o.to));h.setSelection(p?P.create(h.doc,o.from,o.from+p.length):_.near(h.doc.resolve(Math.min(o.from,h.doc.content.size)))),r.dispatch(h.scrollIntoView()),s=!0;break}let u=i.doc.textBetween(o.from,o.to,` +`)}${i}`.match(/<br\s*\/?>$/i);if(!a)return!1;let l=t.state.schema.nodes.hardbreak||t.state.schema.nodes.hard_break;if(!l)return!1;let c=e-(a[0].length-i.length),u=t.state.tr.replaceWith(c,n,l.create()).scrollIntoView();return u.setSelection(P.create(u.doc,Math.min(c+1,u.doc.content.size))),t.dispatch(u),!0},handleClick(t,e,n){return c1(n.target)||Rp(n.target)||Op(n.target)||u1(n.target)},handleKeyDown(t,e){if(aL(t,e))return e.preventDefault(),!0;if(fD(t,e))return!0;if(e.key==="Enter"&&t.state.selection instanceof H){let r=t.state.selection.node;if(r.type.name==="math_inline"||r.type.name==="math_block")return t.nodeDOM(t.state.selection.from)?.dispatchEvent(new CustomEvent("weibei-edit-math")),e.preventDefault(),!0}if(tL(t,e)||sL(t,e)||e.key==="Enter"&&ie&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey&&eL(t))return e.preventDefault(),!0;if(e.key!=="Enter"&&e.key!==" ")return!1;if(Op(e.target))return e.preventDefault(),!0;if(!e.metaKey&&!e.ctrlKey)return!1;let n=WD();return n?(Le("wikiLinkActivated",{title:n}),e.preventDefault(),!0):!1},decorations(t){let e=ID(t);ND(e);let n=e?.pos??null,r=B0;if(r.doc===t.doc&&r.focusedMermaidPos===n&&r.generation===Yi)return At(st,"decorationCacheHits"),r.decorations;let i=[],o={open:!1},s=new Map;t.doc.descendants((l,c,u)=>{if(At(st,"decorationNodes"),l.type.name==="code_block")return OD(i,l,c,e)||(i.push(le.node(c,c+l.nodeSize,{class:"weibei-code-block","data-language":l.attrs.language||""})),$D(i,l,c)),!1;if(l.isText){let d=c,p=l.text||"";if((l.marks||[]).some(m=>m.type.name.toLowerCase().includes("code"))||yt!==null)return!0;AD(i,p,d),TD(i,p,d,o),ED(i,p,d),vD(i,p,d),MD(i,p,d,s)}return!0});let a=oe.create(t.doc,i);return B0={doc:t.doc,focusedMermaidPos:n,generation:Yi,decorations:a},a}}})),Xi=()=>{if(window.weiBeiSuppressSelectionReport)return;let t=CD(),e=t?mD():null,n=t&&K?K.action(o=>{let{state:s}=o.get(U),{selection:a}=s,c=["strong","emphasis","highlight","link","inlineCode"].filter(y=>s.schema.marks[y]&&s.doc.rangeHasMark(a.from,a.to,s.schema.marks[y])),u=s.schema.marks.writing_font,f,d=!1;u&&s.doc.nodesBetween(a.from,a.to,y=>{if(!y.isText)return!0;let x=u.isInSet(y.marks||[])?.attrs.font||"serif";return f===void 0?f=x:f!==x&&(d=!0),!0}),f&&!d&&c.push(`font:${f}`);let p=a instanceof H&&a.node.type.name==="math_inline";p&&c.push("inlineMath");let h=a.$from.parent.type.name;for(let y=a.$from.depth;y>0;y-=1){let x=a.$from.node(y).type.name;if(x==="blockquote"||x==="block_quote"){h="blockquote";break}}h==="heading"&&(h=`heading${a.$from.parent.attrs.level||""}`);let m="",g=s.schema.marks.link;return g&&s.doc.nodesBetween(a.from,a.to,y=>{let x=g.isInSet(y.marks||[]);return x&&!m&&(m=String(x.attrs.href||"")),!m}),{activeMarks:c,blockType:h,canConvertToMath:p||a instanceof P&&!a.empty&&a.$from.parent===a.$to.parent&&a.$from.parent.isTextblock,linkTarget:m}}):{activeMarks:[],blockType:"",canConvertToMath:!1,linkTarget:""},r=e?`${Math.round(e.x)}:${Math.round(e.y)}:${Math.round(e.width)}:${Math.round(e.height)}`:"",i=JSON.stringify(n);if(!(t===Ui.text&&r===Ui.rectKey&&i===Ui.detailKey)){if(Ui={text:t,rectKey:r,detailKey:i},!t){Qt=null,Le("selectionChanged",{text:"",rect:null,...n});return}Qt=$p(),Le("selectionChanged",{text:t,rect:e,...n})}},m1=(t,e="")=>!K||!ie||typeof t!="string"?!1:K.action(n=>{let r=n.get(U);if(r.state.selection.empty&&Qt){let l=Math.min(Qt.from,r.state.doc.content.size),c=Math.min(Qt.to,r.state.doc.content.size);l<c&&r.dispatch(r.state.tr.setSelection(P.create(r.state.doc,l,c)))}let{state:i}=r,{selection:o}=i;if(o.empty)return!1;let s=!1,a=l=>{let c=i.schema.marks[l];return!!(c&&Ln(c)(r.state,r.dispatch,r))};switch(t){case"bold":s=a("strong");break;case"italic":s=a("emphasis");break;case"highlight":s=a("highlight");break;case"inlineCode":s=a("inlineCode");break;case"font":{let l=typeof e=="string"&&U0.has(e)?e:"",c=i.schema.marks.writing_font;if(!l||!c)break;let u=i.tr.removeMark(o.from,o.to,c).addMark(o.from,o.to,c.create({font:l}));r.dispatch(u.scrollIntoView()),s=!0;break}case"link":{let l=i.schema.marks.link;if(!l)break;let c=typeof e=="string"?e.trim():"",u=i.tr.removeMark(o.from,o.to,l);c&&u.addMark(o.from,o.to,l.create({href:c})),r.dispatch(u.scrollIntoView()),s=!0;break}case"inlineMath":{let l=i.schema.nodes.math_inline,c=o instanceof H?o.node:i.doc.nodeAt(o.from);if(c?.type===l&&o.to===o.from+c.nodeSize){let p=c.textContent,h=is(p?i.tr.replaceWith(o.from,o.to,i.schema.text(p)):i.tr.delete(o.from,o.to));h.setSelection(p?P.create(h.doc,o.from,o.from+p.length):_.near(h.doc.resolve(Math.min(o.from,h.doc.content.size)))),r.dispatch(h.scrollIntoView()),s=!0;break}let u=i.doc.textBetween(o.from,o.to,` `,` -`);if(!l||!u||!(o instanceof P)||o.$from.parent!==o.$to.parent)break;let f=l.create(null,i.schema.text(u)),d=is(i.tr.replaceRangeWith(o.from,o.to,f));d.setSelection(H.create(d.doc,o.from)),r.dispatch(d.scrollIntoView()),s=!0;break}case"quote":{let l=i.schema.nodes.blockquote||i.schema.nodes.block_quote;if(!l)break;s=!!(Array.from({length:o.$from.depth},(u,f)=>o.$from.node(f+1)).some(u=>u.type===l)?Ig:pi(l))(r.state,r.dispatch,r);break}default:return!1}return s&&(r.focus(),window.requestAnimationFrame(Xi)),s}),En=()=>{if(!K)throw new Error("WeiBei editor is not ready")},m1=t=>{Mp=SD(t),Yi+=1,K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiSelectionAskMarksChanged",!0))})},fL=()=>{if(!K||xs===null)return;let t=xs;xs=null,K.action(e=>{let n=e.get(U);n.domObserver?.flush();let r=n.state.doc.nodeAt(t);if(!r?.isTextblock||!r.textContent)return;let i=n.state.schema.nodes.hardbreak||n.state.schema.nodes.hard_break,o=[];for(let a=0;a<r.childCount;a+=1){let l=r.child(a);l.type!==i&&o.push(l)}if(o.length!==r.childCount){let a=r.type.create(r.attrs,M.fromArray(o),r.marks),l=n.state.tr.replaceWith(t,t+r.nodeSize,a).scrollIntoView();l.setSelection(P.create(l.doc,Math.min(t+1+a.content.size,l.doc.content.size))),n.dispatch(l)}let s=n.nodeDOM(t);s instanceof HTMLElement&&(s.querySelectorAll("br").forEach(a=>a.remove()),n.domObserver?.flush())})},dL=()=>{K&&(fL(),Nl=!1,Dl=null,_t(),eo())},_p=()=>K.action(t=>t.get(Q)),pL=(t=!0)=>{yt!==null&&(_p().call(ml.key,{keep:t}),yt=null,Cn=null,Bl=null)},Hp=t=>{En();let e=String(t||"");Bl=e;let n=vl(e);vs=n.frontmatter,Fl();let r=n.body,i=Cn!==null&&yt===Cn&&r.startsWith(Cn)?r.slice(Cn.length):null,o;i!==null&&!/[$<>\\`\r]/.test(i)?(o=r,Cn=r):(o=qr(r,"agentGenerated"),Cn=o===r?r:null,to=Pl(o));let s=_p();yt===null?(s.call(cs.key),yt=""):o.startsWith(yt)||(s.call(us.key,{diffReview:!1}),s.call(cs.key),yt="");let a=o.slice(yt.length);a&&s.call(hl.key,a),yt=o,_t()},hL=t=>{let e=String(t||"");if(!e)return;let n=Bl;Hp(n===null?e:n+e)},mL=t=>{Cn=null,Hp(t),_p().call(us.key,{diffReview:!1}),Cn=null,yt=null;try{K?.action(e=>{e.get(U).updateState(e.get(U).state)})}catch{}_t()},g1=t=>{En(),pL(),Bl=null,Dl=null,xs=null,Nl=!1,Gn+=1;let e=vl(t||""),n=qr(e.body,"userDocument");vs=e.frontmatter,Fl(),K.action(Nk(n)),to=Pl(n),K.action(r=>jp(r.get(U).state.doc)),_t()},P0=(t,e=0,n=!1)=>{Cp=!0,Mn={revision:e,dirty:n};try{g1(t)}finally{Cp=!1}Le("dirtyChanged",{dirty:n})},y1=()=>(En(),At(st,"fullSerializations"),Pl(K.action(Ik()))),Es=t=>{En();let e=qr(t||"","internalFragment"),n=Qt||zp();n?K.action(Gu(e,n)):K.action(Ju(e)),Qt=null},Wp=(t,e="internalFragment")=>{En();let n=zp(),r=VD(qr(t,e));n?K.action(Gu(r,n)):K.action(Ju(r)),qD()||KD(),Qt=null},k1=t=>{En(),K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setSelection(_.atEnd(n.state.doc)))}),Wp(t,"agentGenerated")},gL=t=>(En(),!window.weiBeiEditorCheckMode||!t?!1:K.action(e=>{let n=e.get(U),r=null;return n.state.doc.descendants((i,o)=>{if(!i.isText||r)return!0;let s=(i.text||"").indexOf(t);return s<0?!0:(r={from:o+s,to:o+s+t.length},!1)}),r?(n.dispatch(n.state.tr.setSelection(P.create(n.state.doc,r.from,r.to))),Qt=r,!0):!1})),yL=t=>(En(),window.weiBeiEditorCheckMode?K.action(e=>{let n=e.get(U);n.focus();for(let r of String(t||"")){let{from:i,to:o}=n.state.selection,s=!1;n.someProp("handleTextInput",a=>s?!0:(s=a(n,i,o,r)===!0,s)),s||n.dispatch(n.state.tr.insertText(r,i,o))}return!0}):!1),kL=(t,e={})=>(En(),window.weiBeiEditorCheckMode?K.action(n=>{let r=n.get(U);r.focus();let i=new KeyboardEvent("keydown",{key:t,bubbles:!0,cancelable:!0,shiftKey:e.shiftKey===!0,altKey:e.altKey===!0,metaKey:e.metaKey===!0,ctrlKey:e.ctrlKey===!0});return r.dom.dispatchEvent(i),!0}):!1),b1=()=>Array.from(document.querySelectorAll(".ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6")),F0=0,Al=-2,Op=null,jp=t=>{let e=[],n=Math.max(1,t.content.size);t.descendants((i,o)=>{if(i.type.name!=="heading")return!0;let s=i.textContent.trim();if(!s)return!1;let a=e.length;return e.push({id:`note-heading-${a}`,index:a,level:Number(i.attrs.level||1),title:s,position:Math.max(0,Math.min(1,o/n))}),!1});let r=e0(e);r!==Op&&(Op=r,At(st,"outlineReports"),Le("outlineChanged",{items:e}))},eo=()=>{window.cancelAnimationFrame(F0),F0=window.requestAnimationFrame(()=>{let t=b1();if(t.length===0){Al!==-1&&(Al=-1,Le("activeHeadingChanged",{index:null}));return}let e=Math.max(0,window.innerHeight*.32),n=0;t.forEach((r,i)=>{r.getBoundingClientRect().top<=e&&(n=i)}),n!==Al&&(Al=n,Le("activeHeadingChanged",{index:n}))})},Vp=t=>{let e=Number(t),n=b1(),r=Number.isFinite(e)?n[Math.max(0,Math.floor(e))]:null;if(!r)return!1;let i=Tp();return r.scrollIntoView({block:"start",behavior:i?"auto":"smooth"}),i?eo():window.setTimeout(eo,180),!0},x1=(t,e)=>{let n=t!==tt||e!==je;tt=t,je=e,n&&(Op=null,Gn+=1,zt.clear(),Jn.clear(),m1([]))},w1=t=>{ie=t!==!1,Fp(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiEditableChanged",ie))})},qp=t=>{q0(t),Yi+=1,s1(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",Gi))})},Kp=t=>{Kr=W0(t),Yi+=1,document.documentElement.dataset.weibeiLanguage=Kr,Fl(),Fp(),Ms.forEach(e=>e()),G.dataset.show==="true"&&Ss(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiLanguageChanged",Kr))})},Up=()=>K?(K.action(t=>t.get(U).focus()),!0):!1,gt=(t,e)=>t.payload[e]??t.payload.value,bL=t=>{let e=n0(t);if(!e||!r0(e,{documentID:tt,documentGeneration:je,revision:Mn.revision}))return!1;switch(e.type){case"loadDocument":{let n=gt(e,"markdown"),r=gt(e,"initialRevision");return typeof n!="string"||r!==void 0&&!Number.isInteger(r)?!1:(x1(e.documentID,e.documentGeneration),P0(n,Number(r??0)),!0)}case"requestSnapshot":{let n=y1();return to=n,Le("snapshotReady",{requestID:e.requestID,markdown:n}),!0}case"setTheme":return qp(gt(e,"theme")),!0;case"setLanguage":return Kp(gt(e,"language")),!0;case"setEditable":return w1(gt(e,"editable")),!0;case"focus":return Up();case"scrollToHeading":return Vp(gt(e,"index"));case"applyMarkdownFragment":{let n=gt(e,"markdown");return typeof n!="string"?!1:(k1(n),!0)}case"replaceSelection":{let n=gt(e,"markdown");return typeof n!="string"?!1:(Es(n),!0)}case"executeSelectionCommand":return h1(gt(e,"action"),gt(e,"value"));case"insertStructuredBlock":{let n=gt(e,"markdown");return typeof n!="string"?!1:(Wp(n),!0)}case"restoreCheckpoint":{let n=gt(e,"markdown"),r=gt(e,"revision");return typeof n!="string"||r!==void 0&&(!Number.isInteger(r)||Number(r)<0)?!1:(P0(n,r===void 0?Mn.revision:Number(r),!0),!0)}}};window.WeiBeiEditor={dispatchCommand:bL,resolveAttachment:(t,e,n)=>{let r=Jn.get(t);r&&(Jn.delete(t),r.resolve({src:e,alt:n}))},rejectAttachment:(t,e)=>{let n=Jn.get(t);n&&(Jn.delete(t),n.reject(new Error(e||"Attachment save failed")))},resolveImagePicker:(t,e,n)=>{let r=zt.get(t);if(!r||(zt.delete(t),r.documentID!==tt||r.documentGeneration!==je))return!1;if(r.mode==="replace"){let i=r.getPos(),o=typeof i=="number"?r.view.state.doc.nodeAt(i):null;if(o?.type.name!=="image")return!1;let s=Ol(o.attrs.alt||"").size,a=`${String(n||"image")}${s?`|${s.width}${s.height?`x${s.height}`:""}`:""}`;return r.view.dispatch(r.view.state.tr.setNodeMarkup(i,void 0,{...o.attrs,src:e,alt:a}).scrollIntoView()),r.view.focus(),!0}return Q0(r.view,r.context,Lp("image",r.view.state.schema,{src:e,alt:n}))},cancelImagePicker:t=>{let e=zt.get(t);return e?(zt.delete(t),e.mode==="replace"&&e.view.focus(),e.documentID===tt&&e.documentGeneration===je):!1},discardImagePicker:t=>zt.delete(t),rejectImagePicker:(t,e)=>{let n=zt.get(t);return!n||(zt.delete(t),n.documentID!==tt||n.documentGeneration!==je)?!1:n.mode==="replace"?(n.view.focus(),!0):(I.dismissedContext="",I.error=e||ue("slashImageFailed"),I.view=n.view,I.provider?.show(),Ss(),!0)},setTheme:qp,setInterfaceLanguage:Kp,setReduceMotion:J0,setTextScale:G0,focus:Up,scrollToHeading:Vp,setSelectionAskMarks:m1,setMarkdownBaseURL:t=>{_0=t||"",s1()}};window.weiBeiEditorCheckMode&&(Object.assign(window.WeiBeiEditor,{getMarkdown:y1,setMarkdown:g1,updateStreamingMarkdown:Hp,appendStreamingMarkdown:hL,finishStreamingMarkdown:t=>(mL(t),!0),replaceSelection:Es,executeSelectionCommand:h1,applyAgentPatch:k1,insertMarkdownImage:Es,insertMarkdown:Wp,setEditable:w1,setDocumentID:t=>x1(String(t||""),je+1),setTheme:qp,setInterfaceLanguage:Kp,setReduceMotion:J0,setTextScale:G0,focus:Up,scrollToHeading:Vp}),window.WeiBeiEditor.getCheckMetrics=()=>({...st,fullBridgeMessages:Sp}),window.WeiBeiEditor.resetCheckMetrics=()=>{Zw(st),Sp=0},window.WeiBeiEditor.getBridgeSessionForCheck=()=>({protocolVersion:2,documentID:tt,documentGeneration:je,revision:Mn.revision,dirty:Mn.dirty}),window.WeiBeiEditor.selectFirstTextForCheck=gL,window.WeiBeiEditor.selectedTextForCheck=a1,window.WeiBeiEditor.typeTextForCheck=yL,window.WeiBeiEditor.pressKeyForCheck=kL,window.WeiBeiEditor.compositionStateForCheck=()=>({start:Dl,last:to,composing:K.action(t=>t.get(U).composing)}),window.WeiBeiEditor.openSlashMenuForCheck=()=>{let t=I.view;return!t||!Zi(t)?!1:(I.dismissedContext="",I.provider?.show(),Ss(),G.dataset.show==="true")},window.WeiBeiEditor.slashStateForCheck=()=>({show:G.dataset.show==="true",commands:Array.from(G.querySelectorAll(".weibei-slash-command-button")).map(t=>t.textContent),groups:Array.from(G.querySelectorAll(".weibei-slash-group")).map(t=>t.textContent),rows:I.tableRows,columns:I.tableColumns,tableOpen:I.tableOpen,tableSide:Cs?.dataset.side||"",activeDescendant:I.view?.dom.getAttribute("aria-activedescendant")||"",announcement:Ur.textContent,error:I.error}),window.WeiBeiEditor.renderSlashMenuForCheck=Ss,window.WeiBeiEditor.executeSlashCommandForCheck=t=>Jr(t),window.WeiBeiEditor.pendingImagePickerIDsForCheck=()=>Array.from(zt.keys()),window.WeiBeiEditor.undoForCheck=()=>K.action(t=>ss(t.get(U).state,t.get(U).dispatch)),window.WeiBeiEditor.redoForCheck=()=>K.action(t=>as(t.get(U).state,t.get(U).dispatch)),window.WeiBeiEditor.selectFirstCodeBlockEndForCheck=()=>K.action(t=>{let e=t.get(U),n=null;return e.state.doc.descendants((r,i)=>n!==null||r.type.name!=="code_block"?!0:(n=i+r.content.size+1,!1)),n===null?!1:(e.dispatch(e.state.tr.setSelection(P.create(e.state.doc,n))),e.focus(),!0)}),window.WeiBeiEditor.selectDocumentEndForCheck=()=>K.action(t=>{let e=t.get(U);return e.dispatch(e.state.tr.setSelection(_.atEnd(e.state.doc))),e.focus(),!0}),window.WeiBeiEditor.selectionForCheck=()=>K.action(t=>{let e=t.get(U).state.selection;return{from:e.from,to:e.to,parent:e.$from.parent.type.name,parentOffset:e.$from.parentOffset}}));var Ts=vl(window.initialMarkdown||"");Ts.body=qr(Ts.body,"userDocument");vs=Ts.frontmatter;to=Pl(Ts.body);Fl();var Gr=Ek.make().config(t=>{t.set(Vo,document.querySelector("#editor")),t.set(Ho,Ts.body),t.set(Rr,{editable:()=>ie,nodeViews:{code_block:_D,image:wD,math_inline:N0,math_block:N0,wiki_link:kp,embed:kp,inline_footnote:kp,callout:HD}}),t.set(qn.key,{throttleMs:0,scrollFollow:!1,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}})});Gr=Gr.config(t=>{t.set(Vr.key,{uploader:UD,enableHtmlFileUploader:!0,uploadWidgetFactory:(e,n)=>{let r=document.createElement("span");return r.className="weibei-uploading",r.textContent=ue("uploadingImage"),le.widget(e,r,n)}}),t.set(H0.key,{view(e){let n=l=>l.preventDefault(),r=()=>{let l=X0(e);l&&(e.dispatch(e.state.tr.insertText("/",l.pos).scrollIntoView()),e.focus(),I.dismissedContext="")};ot.addEventListener("mousedown",n),ot.addEventListener("click",r),document.body.append(Ur,ot);let i=new Bw({content:G,debounce:0,offset:6,root:document.body,shouldShow:l=>{let c=Zi(l);return!!(c&&I.dismissedContext!==c.key)}});I.provider=i,I.view=e;let o=i.show.bind(i),s=i.hide.bind(i),a=l=>{De.generation===l&&(De.state="closed",G.dataset.state="closed",s())};return i.show=()=>{if(De.generation+=1,window.clearTimeout(De.timer),window.weiBeiEditorCheckMode||Tp()){De.state="open",G.dataset.state="open",o();return}o(),De.state="opening",G.dataset.state="opening";let l=De.generation;De.frame=window.requestAnimationFrame(()=>{De.generation===l&&(De.state="open",G.dataset.state="open")})},i.hide=()=>{if(De.generation+=1,window.clearTimeout(De.timer),window.cancelAnimationFrame(De.frame),G.dataset.show!=="true"||window.weiBeiEditorCheckMode||Tp()){a(De.generation);return}De.state="closing",G.dataset.state="closing",G.setAttribute("aria-hidden","true");let l=De.generation,c=()=>{De.generation===l&&(G.removeAttribute("aria-hidden"),a(l))};G.addEventListener("transitionend",function u(f){f.target!==G||f.propertyName!=="opacity"||(G.removeEventListener("transitionend",u),c())}),De.timer=window.setTimeout(c,200)},i.onShow=()=>{I.view=e,Ss()},i.onHide=()=>{I.context=null,I.tableOpen=!1,Z0(),Bp()},i.update(e),x0(e),{update(l,c){I.view=l;let u=Zi(l);I.dismissedContext&&u?.key!==I.dismissedContext&&(I.dismissedContext=""),i.update(l,c),x0(l)},destroy(){i.destroy(),ot.removeEventListener("mousedown",n),ot.removeEventListener("click",r),G.remove(),Ur.remove(),ot.remove(),Cs?.remove(),I.provider=null,I.view=null}}}})});Gr=Gr.use(uL).use(rb).use(Mx).use(h0).use(XO).use(iw).use(pe(()=>sw(()=>yt!==null)));Gr=Gr.use(H0).use(jx).use(Xd).use(Fw);Gr.use(Hd).config(t=>{t.get(ll).selectionUpdated(()=>{requestAnimationFrame(Xi)})}).create().then(t=>{K=t,Fp(),YD(),document.querySelector("#editor-status")?.remove(),document.addEventListener("mouseup",Xi),document.addEventListener("pointerdown",()=>{window.weiBeiSuppressSelectionReport||(Qt=null,Ui.text="",Ui.rectKey="",Le("selectionChanged",{text:"",rect:null}))},!0),document.addEventListener("click",e=>{ie&&e.target instanceof Element&&e.target.closest(".weibei-structured-node")||!l1(e.target)&&!Np(e.target)&&!Rp(e.target)&&!c1(e.target)||(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keydown",e=>{e.key!=="Enter"&&e.key!==" "||Np(e.target)&&(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keyup",e=>{Xi()}),document.addEventListener("scroll",eo,!0),Le("editorReady",{}),window.setTimeout(()=>{$0=!0,hD(),K.action(e=>jp(e.get(U).state.doc)),eo()})}).catch(Qi);})(); +`);if(!l||!u||!(o instanceof P)||o.$from.parent!==o.$to.parent)break;let f=l.create(null,i.schema.text(u)),d=is(i.tr.replaceRangeWith(o.from,o.to,f));d.setSelection(H.create(d.doc,o.from)),r.dispatch(d.scrollIntoView()),s=!0;break}case"quote":{let l=i.schema.nodes.blockquote||i.schema.nodes.block_quote;if(!l)break;s=!!(Array.from({length:o.$from.depth},(u,f)=>o.$from.node(f+1)).some(u=>u.type===l)?Ng:pi(l))(r.state,r.dispatch,r);break}default:return!1}return s&&(r.focus(),window.requestAnimationFrame(Xi)),s}),En=()=>{if(!K)throw new Error("WeiBei editor is not ready")},g1=t=>{Mp=SD(t),Yi+=1,K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiSelectionAskMarksChanged",!0))})},fL=()=>{if(!K||xs===null)return;let t=xs;xs=null,K.action(e=>{let n=e.get(U);n.domObserver?.flush();let r=n.state.doc.nodeAt(t);if(!r?.isTextblock||!r.textContent)return;let i=n.state.schema.nodes.hardbreak||n.state.schema.nodes.hard_break,o=[];for(let a=0;a<r.childCount;a+=1){let l=r.child(a);l.type!==i&&o.push(l)}if(o.length!==r.childCount){let a=r.type.create(r.attrs,M.fromArray(o),r.marks),l=n.state.tr.replaceWith(t,t+r.nodeSize,a).scrollIntoView();l.setSelection(P.create(l.doc,Math.min(t+1+a.content.size,l.doc.content.size))),n.dispatch(l)}let s=n.nodeDOM(t);s instanceof HTMLElement&&(s.querySelectorAll("br").forEach(a=>a.remove()),n.domObserver?.flush())})},dL=()=>{K&&(fL(),Nl=!1,Dl=null,_t(),eo())},Hp=()=>K.action(t=>t.get(Q)),pL=(t=!0)=>{yt!==null&&(Hp().call(ml.key,{keep:t}),yt=null,Cn=null,Bl=null)},Wp=t=>{En();let e=String(t||"");Bl=e;let n=vl(e);vs=n.frontmatter,Fl();let r=n.body,i=Cn!==null&&yt===Cn&&r.startsWith(Cn)?r.slice(Cn.length):null,o;i!==null&&!/[$<>\\`\r]/.test(i)?(o=r,Cn=r):(o=qr(r,"agentGenerated"),Cn=o===r?r:null,to=Pl(o));let s=Hp();yt===null?(s.call(cs.key),yt=""):o.startsWith(yt)||(s.call(us.key,{diffReview:!1}),s.call(cs.key),yt="");let a=o.slice(yt.length);a&&s.call(hl.key,a),yt=o,_t()},hL=t=>{let e=String(t||"");if(!e)return;let n=Bl;Wp(n===null?e:n+e)},mL=t=>{Cn=null,Wp(t),Hp().call(us.key,{diffReview:!1}),Cn=null,yt=null;try{K?.action(e=>{e.get(U).updateState(e.get(U).state)})}catch{}Ap(),_t()},y1=t=>{En(),pL(),Bl=null,Dl=null,xs=null,Nl=!1,Gn+=1;let e=vl(t||""),n=qr(e.body,"userDocument");vs=e.frontmatter,Fl(),K.action(Rk(n)),to=Pl(n),K.action(r=>Vp(r.get(U).state.doc)),_t()},F0=(t,e=0,n=!1)=>{Cp=!0,Mn={revision:e,dirty:n};try{y1(t)}finally{Cp=!1}Le("dirtyChanged",{dirty:n})},k1=()=>(En(),At(st,"fullSerializations"),Pl(K.action(Nk()))),Es=t=>{En();let e=qr(t||"","internalFragment"),n=Qt||$p();n?K.action(Gu(e,n)):K.action(Ju(e)),Qt=null},jp=(t,e="internalFragment")=>{En();let n=$p(),r=VD(qr(t,e));n?K.action(Gu(r,n)):K.action(Ju(r)),qD()||KD(),Qt=null},b1=t=>{En(),K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setSelection(_.atEnd(n.state.doc)))}),jp(t,"agentGenerated")},gL=t=>(En(),!window.weiBeiEditorCheckMode||!t?!1:K.action(e=>{let n=e.get(U),r=null;return n.state.doc.descendants((i,o)=>{if(!i.isText||r)return!0;let s=(i.text||"").indexOf(t);return s<0?!0:(r={from:o+s,to:o+s+t.length},!1)}),r?(n.dispatch(n.state.tr.setSelection(P.create(n.state.doc,r.from,r.to))),Qt=r,!0):!1})),yL=t=>(En(),window.weiBeiEditorCheckMode?K.action(e=>{let n=e.get(U);n.focus();for(let r of String(t||"")){let{from:i,to:o}=n.state.selection,s=!1;n.someProp("handleTextInput",a=>s?!0:(s=a(n,i,o,r)===!0,s)),s||n.dispatch(n.state.tr.insertText(r,i,o))}return!0}):!1),kL=(t,e={})=>(En(),window.weiBeiEditorCheckMode?K.action(n=>{let r=n.get(U);r.focus();let i=new KeyboardEvent("keydown",{key:t,bubbles:!0,cancelable:!0,shiftKey:e.shiftKey===!0,altKey:e.altKey===!0,metaKey:e.metaKey===!0,ctrlKey:e.ctrlKey===!0});return r.dom.dispatchEvent(i),!0}):!1),x1=()=>Array.from(document.querySelectorAll(".ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6")),z0=0,Al=-2,Dp=null,Vp=t=>{let e=[],n=Math.max(1,t.content.size);t.descendants((i,o)=>{if(i.type.name!=="heading")return!0;let s=i.textContent.trim();if(!s)return!1;let a=e.length;return e.push({id:`note-heading-${a}`,index:a,level:Number(i.attrs.level||1),title:s,position:Math.max(0,Math.min(1,o/n))}),!1});let r=n0(e);r!==Dp&&(Dp=r,At(st,"outlineReports"),Le("outlineChanged",{items:e}))},eo=()=>{window.cancelAnimationFrame(z0),z0=window.requestAnimationFrame(()=>{let t=x1();if(t.length===0){Al!==-1&&(Al=-1,Le("activeHeadingChanged",{index:null}));return}let e=Math.max(0,window.innerHeight*.32),n=0;t.forEach((r,i)=>{r.getBoundingClientRect().top<=e&&(n=i)}),n!==Al&&(Al=n,Le("activeHeadingChanged",{index:n}))})},qp=t=>{let e=Number(t),n=x1(),r=Number.isFinite(e)?n[Math.max(0,Math.floor(e))]:null;if(!r)return!1;let i=Tp();return r.scrollIntoView({block:"start",behavior:i?"auto":"smooth"}),i?eo():window.setTimeout(eo,180),!0},w1=(t,e)=>{let n=t!==tt||e!==je;tt=t,je=e,n&&(Dp=null,Gn+=1,zt.clear(),Jn.clear(),g1([]))},C1=t=>{ie=t!==!1,zp(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiEditableChanged",ie))})},Kp=t=>{K0(t),Yi+=1,a1(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",Gi))})},Up=t=>{Kr=j0(t),Yi+=1,document.documentElement.dataset.weibeiLanguage=Kr,Fl(),zp(),Ms.forEach(e=>e()),G.dataset.show==="true"&&Ss(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiLanguageChanged",Kr))})},Jp=()=>K?(K.action(t=>t.get(U).focus()),!0):!1,gt=(t,e)=>t.payload[e]??t.payload.value,bL=t=>{let e=i0(t);if(!e||!o0(e,{documentID:tt,documentGeneration:je,revision:Mn.revision}))return!1;switch(e.type){case"loadDocument":{let n=gt(e,"markdown"),r=gt(e,"initialRevision");return typeof n!="string"||r!==void 0&&!Number.isInteger(r)?!1:(w1(e.documentID,e.documentGeneration),F0(n,Number(r??0)),!0)}case"requestSnapshot":{let n=k1();return to=n,Le("snapshotReady",{requestID:e.requestID,markdown:n}),!0}case"setTheme":return Kp(gt(e,"theme")),!0;case"setLanguage":return Up(gt(e,"language")),!0;case"setEditable":return C1(gt(e,"editable")),!0;case"focus":return Jp();case"scrollToHeading":return qp(gt(e,"index"));case"applyMarkdownFragment":{let n=gt(e,"markdown");return typeof n!="string"?!1:(b1(n),!0)}case"replaceSelection":{let n=gt(e,"markdown");return typeof n!="string"?!1:(Es(n),!0)}case"executeSelectionCommand":return m1(gt(e,"action"),gt(e,"value"));case"insertStructuredBlock":{let n=gt(e,"markdown");return typeof n!="string"?!1:(jp(n),!0)}case"restoreCheckpoint":{let n=gt(e,"markdown"),r=gt(e,"revision");return typeof n!="string"||r!==void 0&&(!Number.isInteger(r)||Number(r)<0)?!1:(F0(n,r===void 0?Mn.revision:Number(r),!0),!0)}}};window.WeiBeiEditor={dispatchCommand:bL,resolveAttachment:(t,e,n)=>{let r=Jn.get(t);r&&(Jn.delete(t),r.resolve({src:e,alt:n}))},rejectAttachment:(t,e)=>{let n=Jn.get(t);n&&(Jn.delete(t),n.reject(new Error(e||"Attachment save failed")))},resolveImagePicker:(t,e,n)=>{let r=zt.get(t);if(!r||(zt.delete(t),r.documentID!==tt||r.documentGeneration!==je))return!1;if(r.mode==="replace"){let i=r.getPos(),o=typeof i=="number"?r.view.state.doc.nodeAt(i):null;if(o?.type.name!=="image")return!1;let s=Ol(o.attrs.alt||"").size,a=`${String(n||"image")}${s?`|${s.width}${s.height?`x${s.height}`:""}`:""}`;return r.view.dispatch(r.view.state.tr.setNodeMarkup(i,void 0,{...o.attrs,src:e,alt:a}).scrollIntoView()),r.view.focus(),!0}return Z0(r.view,r.context,Bp("image",r.view.state.schema,{src:e,alt:n}))},cancelImagePicker:t=>{let e=zt.get(t);return e?(zt.delete(t),e.mode==="replace"&&e.view.focus(),e.documentID===tt&&e.documentGeneration===je):!1},discardImagePicker:t=>zt.delete(t),rejectImagePicker:(t,e)=>{let n=zt.get(t);return!n||(zt.delete(t),n.documentID!==tt||n.documentGeneration!==je)?!1:n.mode==="replace"?(n.view.focus(),!0):(I.dismissedContext="",I.error=e||ue("slashImageFailed"),I.view=n.view,I.provider?.show(),Ss(),!0)},setTheme:Kp,setInterfaceLanguage:Up,setReduceMotion:G0,setTextScale:X0,focus:Jp,scrollToHeading:qp,setSelectionAskMarks:g1,setMarkdownBaseURL:t=>{H0=t||"",a1()}};window.weiBeiEditorCheckMode&&(Object.assign(window.WeiBeiEditor,{getMarkdown:k1,setMarkdown:y1,updateStreamingMarkdown:Wp,appendStreamingMarkdown:hL,finishStreamingMarkdown:t=>(mL(t),!0),replaceSelection:Es,executeSelectionCommand:m1,applyAgentPatch:b1,insertMarkdownImage:Es,insertMarkdown:jp,setEditable:C1,setDocumentID:t=>w1(String(t||""),je+1),setTheme:Kp,setInterfaceLanguage:Up,setReduceMotion:G0,setTextScale:X0,focus:Jp,scrollToHeading:qp}),window.WeiBeiEditor.getCheckMetrics=()=>({...st,fullBridgeMessages:Sp}),window.WeiBeiEditor.resetCheckMetrics=()=>{t0(st),Sp=0},window.WeiBeiEditor.getBridgeSessionForCheck=()=>({protocolVersion:2,documentID:tt,documentGeneration:je,revision:Mn.revision,dirty:Mn.dirty}),window.WeiBeiEditor.selectFirstTextForCheck=gL,window.WeiBeiEditor.selectedTextForCheck=l1,window.WeiBeiEditor.typeTextForCheck=yL,window.WeiBeiEditor.pressKeyForCheck=kL,window.WeiBeiEditor.compositionStateForCheck=()=>({start:Dl,last:to,composing:K.action(t=>t.get(U).composing)}),window.WeiBeiEditor.openSlashMenuForCheck=()=>{let t=I.view;return!t||!Zi(t)?!1:(I.dismissedContext="",I.provider?.show(),Ss(),G.dataset.show==="true")},window.WeiBeiEditor.slashStateForCheck=()=>({show:G.dataset.show==="true",commands:Array.from(G.querySelectorAll(".weibei-slash-command-button")).map(t=>t.textContent),groups:Array.from(G.querySelectorAll(".weibei-slash-group")).map(t=>t.textContent),rows:I.tableRows,columns:I.tableColumns,tableOpen:I.tableOpen,tableSide:Cs?.dataset.side||"",activeDescendant:I.view?.dom.getAttribute("aria-activedescendant")||"",announcement:Ur.textContent,error:I.error}),window.WeiBeiEditor.renderSlashMenuForCheck=Ss,window.WeiBeiEditor.executeSlashCommandForCheck=t=>Jr(t),window.WeiBeiEditor.pendingImagePickerIDsForCheck=()=>Array.from(zt.keys()),window.WeiBeiEditor.undoForCheck=()=>K.action(t=>ss(t.get(U).state,t.get(U).dispatch)),window.WeiBeiEditor.redoForCheck=()=>K.action(t=>as(t.get(U).state,t.get(U).dispatch)),window.WeiBeiEditor.selectFirstCodeBlockEndForCheck=()=>K.action(t=>{let e=t.get(U),n=null;return e.state.doc.descendants((r,i)=>n!==null||r.type.name!=="code_block"?!0:(n=i+r.content.size+1,!1)),n===null?!1:(e.dispatch(e.state.tr.setSelection(P.create(e.state.doc,n))),e.focus(),!0)}),window.WeiBeiEditor.selectDocumentEndForCheck=()=>K.action(t=>{let e=t.get(U);return e.dispatch(e.state.tr.setSelection(_.atEnd(e.state.doc))),e.focus(),!0}),window.WeiBeiEditor.selectionForCheck=()=>K.action(t=>{let e=t.get(U).state.selection;return{from:e.from,to:e.to,parent:e.$from.parent.type.name,parentOffset:e.$from.parentOffset}}));var Ts=vl(window.initialMarkdown||"");Ts.body=qr(Ts.body,"userDocument");vs=Ts.frontmatter;to=Pl(Ts.body);Fl();var Gr=Tk.make().config(t=>{t.set(Vo,document.querySelector("#editor")),t.set(Ho,Ts.body),t.set(Rr,{editable:()=>ie,nodeViews:{code_block:_D,image:wD,math_inline:R0,math_block:R0,wiki_link:kp,embed:kp,inline_footnote:kp,callout:HD}}),t.set(qn.key,{throttleMs:0,scrollFollow:!1,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}})});Gr=Gr.config(t=>{t.set(Vr.key,{uploader:UD,enableHtmlFileUploader:!0,uploadWidgetFactory:(e,n)=>{let r=document.createElement("span");return r.className="weibei-uploading",r.textContent=ue("uploadingImage"),le.widget(e,r,n)}}),t.set(W0.key,{view(e){let n=l=>l.preventDefault(),r=()=>{let l=Y0(e);l&&(e.dispatch(e.state.tr.insertText("/",l.pos).scrollIntoView()),e.focus(),I.dismissedContext="")};ot.addEventListener("mousedown",n),ot.addEventListener("click",r),document.body.append(Ur,ot);let i=new Fw({content:G,debounce:0,offset:6,root:document.body,shouldShow:l=>{let c=Zi(l);return!!(c&&I.dismissedContext!==c.key)}});I.provider=i,I.view=e;let o=i.show.bind(i),s=i.hide.bind(i),a=l=>{De.generation===l&&(De.state="closed",G.dataset.state="closed",s())};return i.show=()=>{if(De.generation+=1,window.clearTimeout(De.timer),window.weiBeiEditorCheckMode||Tp()){De.state="open",G.dataset.state="open",o();return}o(),De.state="opening",G.dataset.state="opening";let l=De.generation;De.frame=window.requestAnimationFrame(()=>{De.generation===l&&(De.state="open",G.dataset.state="open")})},i.hide=()=>{if(De.generation+=1,window.clearTimeout(De.timer),window.cancelAnimationFrame(De.frame),G.dataset.show!=="true"||window.weiBeiEditorCheckMode||Tp()){a(De.generation);return}De.state="closing",G.dataset.state="closing",G.setAttribute("aria-hidden","true");let l=De.generation,c=()=>{De.generation===l&&(G.removeAttribute("aria-hidden"),a(l))};G.addEventListener("transitionend",function u(f){f.target!==G||f.propertyName!=="opacity"||(G.removeEventListener("transitionend",u),c())}),De.timer=window.setTimeout(c,200)},i.onShow=()=>{I.view=e,Ss()},i.onHide=()=>{I.context=null,I.tableOpen=!1,e1(),Pp()},i.update(e),C0(e),{update(l,c){I.view=l;let u=Zi(l);I.dismissedContext&&u?.key!==I.dismissedContext&&(I.dismissedContext=""),i.update(l,c),C0(l)},destroy(){i.destroy(),ot.removeEventListener("mousedown",n),ot.removeEventListener("click",r),G.remove(),Ur.remove(),ot.remove(),Cs?.remove(),I.provider=null,I.view=null}}}})});Gr=Gr.use(uL).use(ib).use(Ex).use(g0).use(XO).use(ow).use(pe(()=>lw(()=>yt!==null)));Gr=Gr.use(W0).use(Vx).use(Xd).use($w);Gr.use(Hd).config(t=>{t.get(ll).selectionUpdated(()=>{requestAnimationFrame(Xi)})}).create().then(t=>{K=t,zp(),YD(),document.querySelector("#editor-status")?.remove(),document.addEventListener("mouseup",Xi),document.addEventListener("pointerdown",()=>{window.weiBeiSuppressSelectionReport||(Qt=null,Ui.text="",Ui.rectKey="",Le("selectionChanged",{text:"",rect:null}))},!0),document.addEventListener("click",e=>{ie&&e.target instanceof Element&&e.target.closest(".weibei-structured-node")||!c1(e.target)&&!Rp(e.target)&&!Op(e.target)&&!u1(e.target)||(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keydown",e=>{e.key!=="Enter"&&e.key!==" "||Rp(e.target)&&(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keyup",e=>{Xi()}),document.addEventListener("scroll",eo,!0),Le("editorReady",{}),window.setTimeout(()=>{_0=!0,hD(),K.action(e=>Vp(e.get(U).state.doc)),eo()})}).catch(Qi);})(); /*! Bundled license information: lodash-es/lodash.js: diff --git a/Sources/WeiBei/Resources/Editor/editor-resources.json b/Sources/WeiBei/Resources/Editor/editor-resources.json index da5788cd9..af34a1798 100644 --- a/Sources/WeiBei/Resources/Editor/editor-resources.json +++ b/Sources/WeiBei/Resources/Editor/editor-resources.json @@ -3,8 +3,8 @@ "assets": [ { "name": "editor-entry.js", - "bytes": 596356, - "sha256": "fc491f441731389237eb241423e8ab4dd17453b8f5718c46e484d323a7b6fb74" + "bytes": 596509, + "sha256": "e60ac200d47eccca70402ded4f34d3b6d1db557d0eaf64e2c62f90b81cd841f4" }, { "name": "editor.css", @@ -333,8 +333,8 @@ }, { "name": "viewer-entry.js", - "bytes": 516964, - "sha256": "046c6a4312333e3e8a91a38bd8a14255d4a618117ef81e8b845bfa8b5717b843" + "bytes": 517117, + "sha256": "d0fd5f23ac0ba5554832a3cc84663ba916efe81781ef93d0af2c2f579f8dbddf" } ] } diff --git a/Sources/WeiBei/Resources/Editor/viewer-entry.js b/Sources/WeiBei/Resources/Editor/viewer-entry.js index 9b1c9c853..2f5751852 100644 --- a/Sources/WeiBei/Resources/Editor/viewer-entry.js +++ b/Sources/WeiBei/Resources/Editor/viewer-entry.js @@ -1,59 +1,59 @@ -"use strict";(()=>{var lx=Object.create;var wa=Object.defineProperty;var cx=Object.getOwnPropertyDescriptor;var ux=Object.getOwnPropertyNames;var fx=Object.getPrototypeOf,dx=Object.prototype.hasOwnProperty;var px=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},hx=(t,e)=>{for(var n in e)wa(t,n,{get:e[n],enumerable:!0})},mx=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ux(e))!dx.call(t,i)&&i!==n&&wa(t,i,{get:()=>e[i],enumerable:!(r=cx(e,i))||r.enumerable});return t};var gx=(t,e,n)=>(n=t!=null?lx(fx(t)):{},mx(e||!t||!t.__esModule?wa(n,"default",{value:t,enumerable:!0}):n,t));var Cp=px((dP,Sp)=>{"use strict";var Vo=Object.prototype.hasOwnProperty,wp=Object.prototype.toString,mp=Object.defineProperty,gp=Object.getOwnPropertyDescriptor,yp=function(e){return typeof Array.isArray=="function"?Array.isArray(e):wp.call(e)==="[object Array]"},kp=function(e){if(!e||wp.call(e)!=="[object Object]")return!1;var n=Vo.call(e,"constructor"),r=e.constructor&&e.constructor.prototype&&Vo.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!n&&!r)return!1;var i;for(i in e);return typeof i>"u"||Vo.call(e,i)},bp=function(e,n){mp&&n.name==="__proto__"?mp(e,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):e[n.name]=n.newValue},xp=function(e,n){if(n==="__proto__")if(Vo.call(e,n)){if(gp)return gp(e,n).value}else return;return e[n]};Sp.exports=function t(){var e,n,r,i,o,s,a=arguments[0],l=1,c=arguments.length,u=!1;for(typeof a=="boolean"&&(u=a,a=arguments[1]||{},l=2),(a==null||typeof a!="object"&&typeof a!="function")&&(a={});l<c;++l)if(e=arguments[l],e!=null)for(n in e)r=xp(a,n),i=xp(e,n),a!==i&&(u&&i&&(kp(i)||(o=yp(i)))?(o?(o=!1,s=r&&yp(r)?r:[]):s=r&&kp(r)?r:{},bp(a,{name:n,newValue:t(u,s,i)})):typeof i<"u"&&bp(a,{name:n,newValue:i}));return a}});var Ze=(function(t){return t.docTypeError="docTypeError",t.contextNotFound="contextNotFound",t.timerNotFound="timerNotFound",t.ctxCallOutOfScope="ctxCallOutOfScope",t.createNodeInParserFail="createNodeInParserFail",t.stackOverFlow="stackOverFlow",t.parserMatchError="parserMatchError",t.serializerMatchError="serializerMatchError",t.getAtomFromSchemaFail="getAtomFromSchemaFail",t.expectDomTypeError="expectDomTypeError",t.callCommandBeforeEditorView="callCommandBeforeEditorView",t.missingRootElement="missingRootElement",t.missingNodeInSchema="missingNodeInSchema",t.missingMarkInSchema="missingMarkInSchema",t.ctxNotBind="ctxNotBind",t.missingYjsDoc="missingYjsDoc",t.aiProviderError="aiProviderError",t.aiBuildContextError="aiBuildContextError",t})({}),et=class extends Error{constructor(t,e,n){super(e,n),this.name="MilkdownError",this.code=t,n?.cause!==void 0&&(this.cause=n.cause)}},yx=(t,e)=>typeof e=="function"?"[Function]":e,wo=t=>JSON.stringify(t,yx);function ed(t){return new et(Ze.docTypeError,`Doc type error, unsupported type: ${wo(t)}`)}function td(t){return new et(Ze.contextNotFound,`Context "${t}" not found, do you forget to inject it?`)}function nd(t){return new et(Ze.timerNotFound,`Timer "${t}" not found, do you forget to record it?`)}function dr(){return new et(Ze.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function rd(t,e,n){let r=`Cannot create node for ${"name"in t?t.name:t}`,i=s=>{if(s==null)return"null";if(Array.isArray(s))return`[${s.map(i).join(", ")}]`;if(typeof s=="object")return"toJSON"in s&&typeof s.toJSON=="function"?JSON.stringify(s.toJSON()):"spec"in s?JSON.stringify(s.spec):JSON.stringify(s);if(typeof s=="string"||typeof s=="number"||typeof s=="boolean")return JSON.stringify(s);if(typeof s=="function")return`[Function: ${s.name||"anonymous"}]`;try{return String(s)}catch{return"[Unserializable]"}},o=[["[Description]",r],["[Attributes]",e],["[Content]",(n??[]).map(s=>s?typeof s=="object"&&"type"in s?`${s}`:i(s):"null")]].reduce((s,[a,l])=>{let c=`${a}: ${i(l)}.`;return s.concat(c)},[]);return new et(Ze.createNodeInParserFail,o.join(` -`))}function Sa(){return new et(Ze.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function id(t){return new et(Ze.parserMatchError,`Cannot match target parser for node: ${wo(t)}.`)}function od(t){return new et(Ze.serializerMatchError,`Cannot match target serializer for node: ${wo(t)}.`)}function tt(t){return new et(Ze.expectDomTypeError,`Expect to be a dom, but get: ${wo(t)}.`)}function So(){return new et(Ze.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function sd(t){return new et(Ze.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${t}" in schema.`)}function ad(t){return new et(Ze.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${t}" in schema.`)}var Ca=class{constructor(){this.sliceMap=new Map,this.get=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);if(!e)throw td(typeof t=="string"?t:t.name);return e},this.remove=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);e&&this.sliceMap.delete(e.type.id)},this.has=t=>typeof t=="string"?[...this.sliceMap.values()].some(e=>e.type.name===t):this.sliceMap.has(t.id)}},kx=class{#t;#e;#r;constructor(t,e,n){this.#t=[],this.#r=()=>{this.#t.forEach(r=>r(this.#e))},this.set=r=>{this.#e=r,this.#r()},this.get=()=>this.#e,this.update=r=>{this.#e=r(this.#e),this.#r()},this.type=n,this.#e=e,t.set(n.id,this)}on(t){return this.#t.push(t),()=>{this.#t=this.#t.filter(e=>e!==t)}}once(t){let e=this.on(n=>{t(n),e()});return e}off(t){this.#t=this.#t.filter(e=>e!==t)}offAll(){this.#t=[]}},bx=class{constructor(t,e){this.id=Symbol(`Context-${e}`),this.name=e,this._defaultValue=t,this._typeInfo=()=>{throw dr()}}create(t,e=this._defaultValue){return new kx(t,e,this)}},K=(t,e)=>new bx(t,e),xx=class{#t;#e;#r;#n;#s;#o;#i;constructor(t,e,n){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#i=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),consumedSlices:[...this.#s].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),recordedTimers:[...this.#o].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)})),waitTimers:[...this.#i].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)}))}),this.onRecord=r=>{this.#o.set(r,{start:Date.now(),duration:0})},this.onClear=r=>{this.#o.delete(r)},this.onDone=r=>{let i=this.#o.get(r);i&&(i.duration=Date.now()-i.start)},this.onWait=(r,i)=>{let o=Date.now();i.finally(()=>{this.#i.set(r,{duration:Date.now()-o})}).catch(console.error)},this.onInject=r=>{this.#n.add(r)},this.onRemove=r=>{this.#n.delete(r)},this.onUse=r=>{this.#s.add(r)},this.#a=r=>this.#e.get(r).get(),this.#l=r=>this.#r.get(r).status,this.#e=t,this.#r=e,this.#t=n}#a;#l},ld=class cd{#t;#e;#r;#n;constructor(e,n,r){this.produce=i=>i&&Object.keys(i).length?new cd(this.#t,this.#e,{...i}):this,this.inject=(i,o)=>{let s=i.create(this.#t.sliceMap);return o!=null&&s.set(o),this.#n?.onInject(i),this},this.remove=i=>(this.#t.remove(i),this.#n?.onRemove(i),this),this.record=i=>(i.create(this.#e.store),this.#n?.onRecord(i),this),this.clearTimer=i=>(this.#e.remove(i),this.#n?.onClear(i),this),this.isInjected=i=>this.#t.has(i),this.isRecorded=i=>this.#e.has(i),this.use=i=>(this.#n?.onUse(i),this.#t.get(i)),this.get=i=>this.use(i).get(),this.set=(i,o)=>this.use(i).set(o),this.update=(i,o)=>this.use(i).update(o),this.timer=i=>this.#e.get(i),this.done=i=>{this.timer(i).done(),this.#n?.onDone(i)},this.wait=i=>{let o=this.timer(i).start();return this.#n?.onWait(i,o),o},this.waitTimers=async i=>{await Promise.all(this.get(i).map(o=>this.wait(o)))},this.#t=e,this.#e=n,this.#r=r,r&&(this.#n=new xx(e,n,r))}get meta(){return this.#r}get inspector(){return this.#n}},ud=class{constructor(){this.store=new Map,this.get=t=>{let e=this.store.get(t.id);if(!e)throw nd(t.name);return e},this.remove=t=>{this.store.delete(t.id)},this.has=t=>this.store.has(t.id)}},wx=class{#t;#e;#r;#n;constructor(t,e){this.#t=null,this.#e=null,this.#n="pending",this.start=()=>(this.#t??=new Promise((n,r)=>{this.#e=i=>{i instanceof CustomEvent&&i.detail.id===this.#r&&(this.#n="resolved",this.#s(),i.stopImmediatePropagation(),n())},this.#o(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#s(),r(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{let n=new CustomEvent(this.type.name,{detail:{id:this.#r}});dispatchEvent(n)},this.#s=()=>{this.#e&&removeEventListener(this.type.name,this.#e)},this.#o=n=>{setTimeout(()=>{n()},this.type.timeout)},this.#r=Symbol(e.name),this.type=e,t.set(e.id,this)}get status(){return this.#n}#s;#o},Sx=class{constructor(t,e=3e3){this.create=n=>new wx(n,this),this.id=Symbol(`Timer-${t}`),this.name=t,this.timeout=e}},nt=(t,e=3e3)=>new Sx(t,e);var Cx={};function En(t,e){let n=e||Cx,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return dd(t,r,i)}function dd(t,e,n){if(Mx(t)){if("value"in t)return t.type==="html"&&!n?"":t.value;if(e&&"alt"in t&&t.alt)return t.alt;if("children"in t)return fd(t.children,e,n)}return Array.isArray(t)?fd(t,e,n):""}function fd(t,e,n){let r=[],i=-1;for(;++i<t.length;)r[i]=dd(t[i],e,n);return r.join("")}function Mx(t){return!!(t&&typeof t=="object")}var pd=document.createElement("i");function pr(t){let e="&"+t+";";pd.innerHTML=e;let n=pd.textContent;return n.charCodeAt(n.length-1)===59&&t!=="semi"||n===e?!1:n}function ue(t,e,n,r){let i=t.length,o=0,s;if(e<0?e=-e>i?0:i+e:e=e>i?i:e,n=n>0?n:0,r.length<1e4)s=Array.from(r),s.unshift(e,n),t.splice(...s);else for(n&&t.splice(e,n);o<r.length;)s=r.slice(o,o+1e4),s.unshift(e,0),t.splice(...s),o+=1e4,e+=1e4}function Be(t,e){return t.length>0?(ue(t,t.length,0,e),t):e}var hd={}.hasOwnProperty;function Co(t){let e={},n=-1;for(;++n<t.length;)Ex(e,t[n]);return e}function Ex(t,e){let n;for(n in e){let i=(hd.call(t,n)?t[n]:void 0)||(t[n]={}),o=e[n],s;if(o)for(s in o){hd.call(i,s)||(i[s]=[]);let a=o[s];Tx(i[s],Array.isArray(a)?a:a?[a]:[])}}}function Tx(t,e){let n=-1,r=[];for(;++n<e.length;)(e[n].add==="after"?t:r).push(e[n]);ue(t,0,0,r)}function Mo(t,e){let n=Number.parseInt(t,e);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"\uFFFD":String.fromCodePoint(n)}function Ae(t){return t.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}var ge=tn(/[A-Za-z]/),ye=tn(/[\dA-Za-z]/),md=tn(/[#-'*+\--9=?A-Z^-~]/);function Tn(t){return t!==null&&(t<32||t===127)}var pi=tn(/\d/),gd=tn(/[\dA-Fa-f]/),yd=tn(/[!-/:-@[-`{-~]/);function R(t){return t!==null&&t<-2}function U(t){return t!==null&&(t<0||t===32)}function _(t){return t===-2||t===-1||t===32}var vn=tn(/\p{P}|\p{S}/u),Et=tn(/\s/);function tn(t){return e;function e(n){return n!==null&&n>-1&&t.test(String.fromCharCode(n))}}function F(t,e,n,r){let i=r?r-1:Number.POSITIVE_INFINITY,o=0;return s;function s(l){return _(l)?(t.enter(n),a(l)):e(l)}function a(l){return _(l)&&o++<i?(t.consume(l),a):(t.exit(n),e(l))}}var kd={tokenize:vx};function vx(t){let e=t.attempt(this.parser.constructs.contentInitial,r,i),n;return e;function r(a){if(a===null){t.consume(a);return}return t.enter("lineEnding"),t.consume(a),t.exit("lineEnding"),F(t,e,"linePrefix")}function i(a){return t.enter("paragraph"),o(a)}function o(a){let l=t.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,s(a)}function s(a){if(a===null){t.exit("chunkText"),t.exit("paragraph"),t.consume(a);return}return R(a)?(t.consume(a),t.exit("chunkText"),o):(t.consume(a),s)}}var xd={tokenize:Ix},bd={tokenize:Ax};function Ix(t){let e=this,n=[],r=0,i,o,s;return a;function a(C){if(r<n.length){let v=n[r];return e.containerState=v[1],t.attempt(v[0].continuation,l,c)(C)}return c(C)}function l(C){if(r++,e.containerState._closeFlow){e.containerState._closeFlow=void 0,i&&x();let v=e.events.length,I=v,w;for(;I--;)if(e.events[I][0]==="exit"&&e.events[I][1].type==="chunkFlow"){w=e.events[I][1].end;break}y(r);let N=v;for(;N<e.events.length;)e.events[N][1].end={...w},N++;return ue(e.events,I+1,0,e.events.slice(v)),e.events.length=N,c(C)}return a(C)}function c(C){if(r===n.length){if(!i)return d(C);if(i.currentConstruct&&i.currentConstruct.concrete)return h(C);e.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return e.containerState={},t.check(bd,u,f)(C)}function u(C){return i&&x(),y(r),d(C)}function f(C){return e.parser.lazy[e.now().line]=r!==n.length,s=e.now().offset,h(C)}function d(C){return e.containerState={},t.attempt(bd,p,h)(C)}function p(C){return r++,n.push([e.currentConstruct,e.containerState]),d(C)}function h(C){if(C===null){i&&x(),y(0),t.consume(C);return}return i=i||e.parser.flow(e.now()),t.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:o}),m(C)}function m(C){if(C===null){g(t.exit("chunkFlow"),!0),y(0),t.consume(C);return}return R(C)?(t.consume(C),g(t.exit("chunkFlow")),r=0,e.interrupt=void 0,a):(t.consume(C),m)}function g(C,v){let I=e.sliceStream(C);if(v&&I.push(null),C.previous=o,o&&(o.next=C),o=C,i.defineSkip(C.start),i.write(I),e.parser.lazy[C.start.line]){let w=i.events.length;for(;w--;)if(i.events[w][1].start.offset<s&&(!i.events[w][1].end||i.events[w][1].end.offset>s))return;let N=e.events.length,D=N,B,S;for(;D--;)if(e.events[D][0]==="exit"&&e.events[D][1].type==="chunkFlow"){if(B){S=e.events[D][1].end;break}B=!0}for(y(r),w=N;w<e.events.length;)e.events[w][1].end={...S},w++;ue(e.events,D+1,0,e.events.slice(N)),e.events.length=w}}function y(C){let v=n.length;for(;v-- >C;){let I=n[v];e.containerState=I[1],I[0].exit.call(e,t)}n.length=C}function x(){i.write([null]),o=void 0,i=void 0,e.containerState._closeFlow=void 0}}function Ax(t,e,n){return F(t,t.attempt(this.parser.constructs.document,e,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function zt(t){if(t===null||U(t)||Et(t))return 1;if(vn(t))return 2}function nn(t,e,n){let r=[],i=-1;for(;++i<t.length;){let o=t[i].resolveAll;o&&!r.includes(o)&&(e=o(e,n),r.push(o))}return e}var hi={name:"attention",resolveAll:Nx,tokenize:Rx};function Nx(t,e){let n=-1,r,i,o,s,a,l,c,u;for(;++n<t.length;)if(t[n][0]==="enter"&&t[n][1].type==="attentionSequence"&&t[n][1]._close){for(r=n;r--;)if(t[r][0]==="exit"&&t[r][1].type==="attentionSequence"&&t[r][1]._open&&e.sliceSerialize(t[r][1]).charCodeAt(0)===e.sliceSerialize(t[n][1]).charCodeAt(0)){if((t[r][1]._close||t[n][1]._open)&&(t[n][1].end.offset-t[n][1].start.offset)%3&&!((t[r][1].end.offset-t[r][1].start.offset+t[n][1].end.offset-t[n][1].start.offset)%3))continue;l=t[r][1].end.offset-t[r][1].start.offset>1&&t[n][1].end.offset-t[n][1].start.offset>1?2:1;let f={...t[r][1].end},d={...t[n][1].start};wd(f,-l),wd(d,l),s={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...t[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...t[n][1].start},end:d},o={type:l>1?"strongText":"emphasisText",start:{...t[r][1].end},end:{...t[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...s.start},end:{...a.end}},t[r][1].end={...s.start},t[n][1].start={...a.end},c=[],t[r][1].end.offset-t[r][1].start.offset&&(c=Be(c,[["enter",t[r][1],e],["exit",t[r][1],e]])),c=Be(c,[["enter",i,e],["enter",s,e],["exit",s,e],["enter",o,e]]),c=Be(c,nn(e.parser.constructs.insideSpan.null,t.slice(r+1,n),e)),c=Be(c,[["exit",o,e],["enter",a,e],["exit",a,e],["exit",i,e]]),t[n][1].end.offset-t[n][1].start.offset?(u=2,c=Be(c,[["enter",t[n][1],e],["exit",t[n][1],e]])):u=0,ue(t,r-1,n-r+3,c),n=r+c.length-u-2;break}}for(n=-1;++n<t.length;)t[n][1].type==="attentionSequence"&&(t[n][1].type="data");return t}function Rx(t,e){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=zt(r),o;return s;function s(l){return o=l,t.enter("attentionSequence"),a(l)}function a(l){if(l===o)return t.consume(l),a;let c=t.exit("attentionSequence"),u=zt(l),f=!u||u===2&&i||n.includes(l),d=!i||i===2&&u||n.includes(r);return c._open=!!(o===42?f:f&&(i||!d)),c._close=!!(o===42?d:d&&(u||!f)),e(l)}}function wd(t,e){t.column+=e,t.offset+=e,t._bufferIndex+=e}var Ma={name:"autolink",tokenize:Ox};function Ox(t,e,n){let r=0;return i;function i(p){return t.enter("autolink"),t.enter("autolinkMarker"),t.consume(p),t.exit("autolinkMarker"),t.enter("autolinkProtocol"),o}function o(p){return ge(p)?(t.consume(p),s):p===64?n(p):c(p)}function s(p){return p===43||p===45||p===46||ye(p)?(r=1,a(p)):c(p)}function a(p){return p===58?(t.consume(p),r=0,l):(p===43||p===45||p===46||ye(p))&&r++<32?(t.consume(p),a):(r=0,c(p))}function l(p){return p===62?(t.exit("autolinkProtocol"),t.enter("autolinkMarker"),t.consume(p),t.exit("autolinkMarker"),t.exit("autolink"),e):p===null||p===32||p===60||Tn(p)?n(p):(t.consume(p),l)}function c(p){return p===64?(t.consume(p),u):md(p)?(t.consume(p),c):n(p)}function u(p){return ye(p)?f(p):n(p)}function f(p){return p===46?(t.consume(p),r=0,u):p===62?(t.exit("autolinkProtocol").type="autolinkEmail",t.enter("autolinkMarker"),t.consume(p),t.exit("autolinkMarker"),t.exit("autolink"),e):d(p)}function d(p){if((p===45||ye(p))&&r++<63){let h=p===45?d:f;return t.consume(p),h}return n(p)}}var Tt={partial:!0,tokenize:Dx};function Dx(t,e,n){return r;function r(o){return _(o)?F(t,i,"linePrefix")(o):i(o)}function i(o){return o===null||R(o)?e(o):n(o)}}var Eo={continuation:{tokenize:Lx},exit:Px,name:"blockQuote",tokenize:Bx};function Bx(t,e,n){let r=this;return i;function i(s){if(s===62){let a=r.containerState;return a.open||(t.enter("blockQuote",{_container:!0}),a.open=!0),t.enter("blockQuotePrefix"),t.enter("blockQuoteMarker"),t.consume(s),t.exit("blockQuoteMarker"),o}return n(s)}function o(s){return _(s)?(t.enter("blockQuotePrefixWhitespace"),t.consume(s),t.exit("blockQuotePrefixWhitespace"),t.exit("blockQuotePrefix"),e):(t.exit("blockQuotePrefix"),e(s))}}function Lx(t,e,n){let r=this;return i;function i(s){return _(s)?F(t,o,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(s):o(s)}function o(s){return t.attempt(Eo,e,n)(s)}}function Px(t){t.exit("blockQuote")}var To={name:"characterEscape",tokenize:Fx};function Fx(t,e,n){return r;function r(o){return t.enter("characterEscape"),t.enter("escapeMarker"),t.consume(o),t.exit("escapeMarker"),i}function i(o){return yd(o)?(t.enter("characterEscapeValue"),t.consume(o),t.exit("characterEscapeValue"),t.exit("characterEscape"),e):n(o)}}var vo={name:"characterReference",tokenize:zx};function zx(t,e,n){let r=this,i=0,o,s;return a;function a(f){return t.enter("characterReference"),t.enter("characterReferenceMarker"),t.consume(f),t.exit("characterReferenceMarker"),l}function l(f){return f===35?(t.enter("characterReferenceMarkerNumeric"),t.consume(f),t.exit("characterReferenceMarkerNumeric"),c):(t.enter("characterReferenceValue"),o=31,s=ye,u(f))}function c(f){return f===88||f===120?(t.enter("characterReferenceMarkerHexadecimal"),t.consume(f),t.exit("characterReferenceMarkerHexadecimal"),t.enter("characterReferenceValue"),o=6,s=gd,u):(t.enter("characterReferenceValue"),o=7,s=pi,u(f))}function u(f){if(f===59&&i){let d=t.exit("characterReferenceValue");return s===ye&&!pr(r.sliceSerialize(d))?n(f):(t.enter("characterReferenceMarker"),t.consume(f),t.exit("characterReferenceMarker"),t.exit("characterReference"),e)}return s(f)&&i++<o?(t.consume(f),u):n(f)}}var Sd={partial:!0,tokenize:_x},Io={concrete:!0,name:"codeFenced",tokenize:$x};function $x(t,e,n){let r=this,i={partial:!0,tokenize:I},o=0,s=0,a;return l;function l(w){return c(w)}function c(w){let N=r.events[r.events.length-1];return o=N&&N[1].type==="linePrefix"?N[2].sliceSerialize(N[1],!0).length:0,a=w,t.enter("codeFenced"),t.enter("codeFencedFence"),t.enter("codeFencedFenceSequence"),u(w)}function u(w){return w===a?(s++,t.consume(w),u):s<3?n(w):(t.exit("codeFencedFenceSequence"),_(w)?F(t,f,"whitespace")(w):f(w))}function f(w){return w===null||R(w)?(t.exit("codeFencedFence"),r.interrupt?e(w):t.check(Sd,m,v)(w)):(t.enter("codeFencedFenceInfo"),t.enter("chunkString",{contentType:"string"}),d(w))}function d(w){return w===null||R(w)?(t.exit("chunkString"),t.exit("codeFencedFenceInfo"),f(w)):_(w)?(t.exit("chunkString"),t.exit("codeFencedFenceInfo"),F(t,p,"whitespace")(w)):w===96&&w===a?n(w):(t.consume(w),d)}function p(w){return w===null||R(w)?f(w):(t.enter("codeFencedFenceMeta"),t.enter("chunkString",{contentType:"string"}),h(w))}function h(w){return w===null||R(w)?(t.exit("chunkString"),t.exit("codeFencedFenceMeta"),f(w)):w===96&&w===a?n(w):(t.consume(w),h)}function m(w){return t.attempt(i,v,g)(w)}function g(w){return t.enter("lineEnding"),t.consume(w),t.exit("lineEnding"),y}function y(w){return o>0&&_(w)?F(t,x,"linePrefix",o+1)(w):x(w)}function x(w){return w===null||R(w)?t.check(Sd,m,v)(w):(t.enter("codeFlowValue"),C(w))}function C(w){return w===null||R(w)?(t.exit("codeFlowValue"),x(w)):(t.consume(w),C)}function v(w){return t.exit("codeFenced"),e(w)}function I(w,N,D){let B=0;return S;function S(j){return w.enter("lineEnding"),w.consume(j),w.exit("lineEnding"),ce}function ce(j){return w.enter("codeFencedFence"),_(j)?F(w,Y,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(j):Y(j)}function Y(j){return j===a?(w.enter("codeFencedFenceSequence"),L(j)):D(j)}function L(j){return j===a?(B++,w.consume(j),L):B>=s?(w.exit("codeFencedFenceSequence"),_(j)?F(w,W,"whitespace")(j):W(j)):D(j)}function W(j){return j===null||R(j)?(w.exit("codeFencedFence"),N(j)):D(j)}}}function _x(t,e,n){let r=this;return i;function i(s){return s===null?n(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}var mi={name:"codeIndented",tokenize:Vx},Hx={partial:!0,tokenize:Wx};function Vx(t,e,n){let r=this;return i;function i(c){return t.enter("codeIndented"),F(t,o,"linePrefix",5)(c)}function o(c){let u=r.events[r.events.length-1];return u&&u[1].type==="linePrefix"&&u[2].sliceSerialize(u[1],!0).length>=4?s(c):n(c)}function s(c){return c===null?l(c):R(c)?t.attempt(Hx,s,l)(c):(t.enter("codeFlowValue"),a(c))}function a(c){return c===null||R(c)?(t.exit("codeFlowValue"),s(c)):(t.consume(c),a)}function l(c){return t.exit("codeIndented"),e(c)}}function Wx(t,e,n){let r=this;return i;function i(s){return r.parser.lazy[r.now().line]?n(s):R(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),i):F(t,o,"linePrefix",5)(s)}function o(s){let a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(s):R(s)?i(s):n(s)}}var Ea={name:"codeText",previous:qx,resolve:jx,tokenize:Kx};function jx(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="codeTextData"){t[n][1].type="codeTextPadding",t[e][1].type="codeTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)i===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(i=r):(r===e||t[r][1].type==="lineEnding")&&(t[i][1].type="codeTextData",r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),e-=r-i-2,r=i+2),i=void 0);return t}function qx(t){return t!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Kx(t,e,n){let r=this,i=0,o,s;return a;function a(d){return t.enter("codeText"),t.enter("codeTextSequence"),l(d)}function l(d){return d===96?(t.consume(d),i++,l):(t.exit("codeTextSequence"),c(d))}function c(d){return d===null?n(d):d===32?(t.enter("space"),t.consume(d),t.exit("space"),c):d===96?(s=t.enter("codeTextSequence"),o=0,f(d)):R(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),c):(t.enter("codeTextData"),u(d))}function u(d){return d===null||d===32||d===96||R(d)?(t.exit("codeTextData"),c(d)):(t.consume(d),u)}function f(d){return d===96?(t.consume(d),o++,f):o===i?(t.exit("codeTextSequence"),t.exit("codeText"),e(d)):(s.type="codeTextData",u(d))}}var Ao=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,n){let r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(e,r):e>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(e,n,r){let i=n||0;this.setCursor(Math.trunc(e));let o=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&gi(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),gi(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),gi(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e<this.left.length){let n=this.left.splice(e,Number.POSITIVE_INFINITY);gi(this.right,n.reverse())}else{let n=this.right.splice(this.left.length+this.right.length-e,Number.POSITIVE_INFINITY);gi(this.left,n.reverse())}}};function gi(t,e){let n=0;if(e.length<1e4)t.push(...e);else for(;n<e.length;)t.push(...e.slice(n,n+1e4)),n+=1e4}function No(t){let e={},n=-1,r,i,o,s,a,l,c,u=new Ao(t);for(;++n<u.length;){for(;n in e;)n=e[n];if(r=u.get(n),n&&r[1].type==="chunkFlow"&&u.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,o=0,o<l.length&&l[o][1].type==="lineEndingBlank"&&(o+=2),o<l.length&&l[o][1].type==="content"))for(;++o<l.length&&l[o][1].type!=="content";)l[o][1].type==="chunkText"&&(l[o][1]._isInFirstContentOfListItem=!0,o++);if(r[0]==="enter")r[1].contentType&&(Object.assign(e,Ux(u,n)),n=e[n],c=!0);else if(r[1]._container){for(o=n,i=void 0;o--;)if(s=u.get(o),s[1].type==="lineEnding"||s[1].type==="lineEndingBlank")s[0]==="enter"&&(i&&(u.get(i)[1].type="lineEndingBlank"),s[1].type="lineEnding",i=o);else if(!(s[1].type==="linePrefix"||s[1].type==="listItemIndent"))break;i&&(r[1].end={...u.get(i)[1].start},a=u.slice(i,n),a.unshift(r),u.splice(i,n-i+1,a))}}return ue(t,0,Number.POSITIVE_INFINITY,u.slice(0)),!c}function Ux(t,e){let n=t.get(e)[1],r=t.get(e)[2],i=e-1,o=[],s=n._tokenizer;s||(s=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(s._contentTypeTextTrailing=!0));let a=s.events,l=[],c={},u,f,d=-1,p=n,h=0,m=0,g=[m];for(;p;){for(;t.get(++i)[1]!==p;);o.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),f&&s.defineSkip(p.start),p._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=!0),s.write(u),p._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=void 0)),f=p,p=p.next}for(p=n;++d<a.length;)a[d][0]==="exit"&&a[d-1][0]==="enter"&&a[d][1].type===a[d-1][1].type&&a[d][1].start.line!==a[d][1].end.line&&(m=d+1,g.push(m),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(s.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),d=g.length;d--;){let y=a.slice(g[d],g[d+1]),x=o.pop();l.push([x,x+y.length-1]),t.splice(x,2,y)}for(l.reverse(),d=-1;++d<l.length;)c[h+l[d][0]]=h+l[d][1],h+=l[d][1]-l[d][0]-1;return c}var Ta={resolve:Gx,tokenize:Qx},Jx={partial:!0,tokenize:Yx};function Gx(t){return No(t),t}function Qx(t,e){let n;return r;function r(a){return t.enter("content"),n=t.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?o(a):R(a)?t.check(Jx,s,o)(a):(t.consume(a),i)}function o(a){return t.exit("chunkContent"),t.exit("content"),e(a)}function s(a){return t.consume(a),t.exit("chunkContent"),n.next=t.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function Yx(t,e,n){let r=this;return i;function i(s){return t.exit("chunkContent"),t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),F(t,o,"linePrefix")}function o(s){if(s===null||R(s))return n(s);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(s):t.interrupt(r.parser.constructs.flow,n,e)(s)}}function Ro(t,e,n,r,i,o,s,a,l){let c=l||Number.POSITIVE_INFINITY,u=0;return f;function f(y){return y===60?(t.enter(r),t.enter(i),t.enter(o),t.consume(y),t.exit(o),d):y===null||y===32||y===41||Tn(y)?n(y):(t.enter(r),t.enter(s),t.enter(a),t.enter("chunkString",{contentType:"string"}),m(y))}function d(y){return y===62?(t.enter(o),t.consume(y),t.exit(o),t.exit(i),t.exit(r),e):(t.enter(a),t.enter("chunkString",{contentType:"string"}),p(y))}function p(y){return y===62?(t.exit("chunkString"),t.exit(a),d(y)):y===null||y===60||R(y)?n(y):(t.consume(y),y===92?h:p)}function h(y){return y===60||y===62||y===92?(t.consume(y),p):p(y)}function m(y){return!u&&(y===null||y===41||U(y))?(t.exit("chunkString"),t.exit(a),t.exit(s),t.exit(r),e(y)):u<c&&y===40?(t.consume(y),u++,m):y===41?(t.consume(y),u--,m):y===null||y===32||y===40||Tn(y)?n(y):(t.consume(y),y===92?g:m)}function g(y){return y===40||y===41||y===92?(t.consume(y),m):m(y)}}function Oo(t,e,n,r,i,o){let s=this,a=0,l;return c;function c(p){return t.enter(r),t.enter(i),t.consume(p),t.exit(i),t.enter(o),u}function u(p){return a>999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in s.parser.constructs?n(p):p===93?(t.exit(o),t.enter(i),t.consume(p),t.exit(i),t.exit(r),e):R(p)?(t.enter("lineEnding"),t.consume(p),t.exit("lineEnding"),u):(t.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||R(p)||a++>999?(t.exit("chunkString"),u(p)):(t.consume(p),l||(l=!_(p)),p===92?d:f)}function d(p){return p===91||p===92||p===93?(t.consume(p),a++,f):f(p)}}function Do(t,e,n,r,i,o){let s;return a;function a(d){return d===34||d===39||d===40?(t.enter(r),t.enter(i),t.consume(d),t.exit(i),s=d===40?41:d,l):n(d)}function l(d){return d===s?(t.enter(i),t.consume(d),t.exit(i),t.exit(r),e):(t.enter(o),c(d))}function c(d){return d===s?(t.exit(o),l(s)):d===null?n(d):R(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),F(t,c,"linePrefix")):(t.enter("chunkString",{contentType:"string"}),u(d))}function u(d){return d===s||d===null||R(d)?(t.exit("chunkString"),c(d)):(t.consume(d),d===92?f:u)}function f(d){return d===s||d===92?(t.consume(d),u):u(d)}}function In(t,e){let n;return r;function r(i){return R(i)?(t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),n=!0,r):_(i)?F(t,r,n?"linePrefix":"lineSuffix")(i):e(i)}}var va={name:"definition",tokenize:Zx},Xx={partial:!0,tokenize:ew};function Zx(t,e,n){let r=this,i;return o;function o(p){return t.enter("definition"),s(p)}function s(p){return Oo.call(r,t,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Ae(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(t.enter("definitionMarker"),t.consume(p),t.exit("definitionMarker"),l):n(p)}function l(p){return U(p)?In(t,c)(p):c(p)}function c(p){return Ro(t,u,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function u(p){return t.attempt(Xx,f,f)(p)}function f(p){return _(p)?F(t,d,"whitespace")(p):d(p)}function d(p){return p===null||R(p)?(t.exit("definition"),r.parser.defined.push(i),e(p)):n(p)}}function ew(t,e,n){return r;function r(a){return U(a)?In(t,i)(a):n(a)}function i(a){return Do(t,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function o(a){return _(a)?F(t,s,"whitespace")(a):s(a)}function s(a){return a===null||R(a)?e(a):n(a)}}var Ia={name:"hardBreakEscape",tokenize:tw};function tw(t,e,n){return r;function r(o){return t.enter("hardBreakEscape"),t.consume(o),i}function i(o){return R(o)?(t.exit("hardBreakEscape"),e(o)):n(o)}}var Aa={name:"headingAtx",resolve:nw,tokenize:rw};function nw(t,e){let n=t.length-2,r=3,i,o;return t[r][1].type==="whitespace"&&(r+=2),n-2>r&&t[n][1].type==="whitespace"&&(n-=2),t[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&t[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:t[r][1].start,end:t[n][1].end},o={type:"chunkText",start:t[r][1].start,end:t[n][1].end,contentType:"text"},ue(t,r,n-r+1,[["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e]])),t}function rw(t,e,n){let r=0;return i;function i(u){return t.enter("atxHeading"),o(u)}function o(u){return t.enter("atxHeadingSequence"),s(u)}function s(u){return u===35&&r++<6?(t.consume(u),s):u===null||U(u)?(t.exit("atxHeadingSequence"),a(u)):n(u)}function a(u){return u===35?(t.enter("atxHeadingSequence"),l(u)):u===null||R(u)?(t.exit("atxHeading"),e(u)):_(u)?F(t,a,"whitespace")(u):(t.enter("atxHeadingText"),c(u))}function l(u){return u===35?(t.consume(u),l):(t.exit("atxHeadingSequence"),a(u))}function c(u){return u===null||u===35||U(u)?(t.exit("atxHeadingText"),a(u)):(t.consume(u),c)}}var Cd=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Na=["pre","script","style","textarea"];var Ra={concrete:!0,name:"htmlFlow",resolveTo:sw,tokenize:aw},iw={partial:!0,tokenize:cw},ow={partial:!0,tokenize:lw};function sw(t){let e=t.length;for(;e--&&!(t[e][0]==="enter"&&t[e][1].type==="htmlFlow"););return e>1&&t[e-2][1].type==="linePrefix"&&(t[e][1].start=t[e-2][1].start,t[e+1][1].start=t[e-2][1].start,t.splice(e-2,2)),t}function aw(t,e,n){let r=this,i,o,s,a,l;return c;function c(b){return u(b)}function u(b){return t.enter("htmlFlow"),t.enter("htmlFlowData"),t.consume(b),f}function f(b){return b===33?(t.consume(b),d):b===47?(t.consume(b),o=!0,m):b===63?(t.consume(b),i=3,r.interrupt?e:k):ge(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function d(b){return b===45?(t.consume(b),i=2,p):b===91?(t.consume(b),i=5,a=0,h):ge(b)?(t.consume(b),i=4,r.interrupt?e:k):n(b)}function p(b){return b===45?(t.consume(b),r.interrupt?e:k):n(b)}function h(b){let We="CDATA[";return b===We.charCodeAt(a++)?(t.consume(b),a===We.length?r.interrupt?e:Y:h):n(b)}function m(b){return ge(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function g(b){if(b===null||b===47||b===62||U(b)){let We=b===47,Sn=s.toLowerCase();return!We&&!o&&Na.includes(Sn)?(i=1,r.interrupt?e(b):Y(b)):Cd.includes(s.toLowerCase())?(i=6,We?(t.consume(b),y):r.interrupt?e(b):Y(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):o?x(b):C(b))}return b===45||ye(b)?(t.consume(b),s+=String.fromCharCode(b),g):n(b)}function y(b){return b===62?(t.consume(b),r.interrupt?e:Y):n(b)}function x(b){return _(b)?(t.consume(b),x):S(b)}function C(b){return b===47?(t.consume(b),S):b===58||b===95||ge(b)?(t.consume(b),v):_(b)?(t.consume(b),C):S(b)}function v(b){return b===45||b===46||b===58||b===95||ye(b)?(t.consume(b),v):I(b)}function I(b){return b===61?(t.consume(b),w):_(b)?(t.consume(b),I):C(b)}function w(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(t.consume(b),l=b,N):_(b)?(t.consume(b),w):D(b)}function N(b){return b===l?(t.consume(b),l=null,B):b===null||R(b)?n(b):(t.consume(b),N)}function D(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||U(b)?I(b):(t.consume(b),D)}function B(b){return b===47||b===62||_(b)?C(b):n(b)}function S(b){return b===62?(t.consume(b),ce):n(b)}function ce(b){return b===null||R(b)?Y(b):_(b)?(t.consume(b),ce):n(b)}function Y(b){return b===45&&i===2?(t.consume(b),le):b===60&&i===1?(t.consume(b),me):b===62&&i===4?(t.consume(b),Xe):b===63&&i===3?(t.consume(b),k):b===93&&i===5?(t.consume(b),Mt):R(b)&&(i===6||i===7)?(t.exit("htmlFlowData"),t.check(iw,Bt,L)(b)):b===null||R(b)?(t.exit("htmlFlowData"),L(b)):(t.consume(b),Y)}function L(b){return t.check(ow,W,Bt)(b)}function W(b){return t.enter("lineEnding"),t.consume(b),t.exit("lineEnding"),j}function j(b){return b===null||R(b)?L(b):(t.enter("htmlFlowData"),Y(b))}function le(b){return b===45?(t.consume(b),k):Y(b)}function me(b){return b===47?(t.consume(b),s="",ut):Y(b)}function ut(b){if(b===62){let We=s.toLowerCase();return Na.includes(We)?(t.consume(b),Xe):Y(b)}return ge(b)&&s.length<8?(t.consume(b),s+=String.fromCharCode(b),ut):Y(b)}function Mt(b){return b===93?(t.consume(b),k):Y(b)}function k(b){return b===62?(t.consume(b),Xe):b===45&&i===2?(t.consume(b),k):Y(b)}function Xe(b){return b===null||R(b)?(t.exit("htmlFlowData"),Bt(b)):(t.consume(b),Xe)}function Bt(b){return t.exit("htmlFlow"),e(b)}}function lw(t,e,n){let r=this;return i;function i(s){return R(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o):n(s)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function cw(t,e,n){return r;function r(i){return t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),t.attempt(Tt,e,n)}}var Oa={name:"htmlText",tokenize:uw};function uw(t,e,n){let r=this,i,o,s;return a;function a(k){return t.enter("htmlText"),t.enter("htmlTextData"),t.consume(k),l}function l(k){return k===33?(t.consume(k),c):k===47?(t.consume(k),I):k===63?(t.consume(k),C):ge(k)?(t.consume(k),D):n(k)}function c(k){return k===45?(t.consume(k),u):k===91?(t.consume(k),o=0,h):ge(k)?(t.consume(k),x):n(k)}function u(k){return k===45?(t.consume(k),p):n(k)}function f(k){return k===null?n(k):k===45?(t.consume(k),d):R(k)?(s=f,me(k)):(t.consume(k),f)}function d(k){return k===45?(t.consume(k),p):f(k)}function p(k){return k===62?le(k):k===45?d(k):f(k)}function h(k){let Xe="CDATA[";return k===Xe.charCodeAt(o++)?(t.consume(k),o===Xe.length?m:h):n(k)}function m(k){return k===null?n(k):k===93?(t.consume(k),g):R(k)?(s=m,me(k)):(t.consume(k),m)}function g(k){return k===93?(t.consume(k),y):m(k)}function y(k){return k===62?le(k):k===93?(t.consume(k),y):m(k)}function x(k){return k===null||k===62?le(k):R(k)?(s=x,me(k)):(t.consume(k),x)}function C(k){return k===null?n(k):k===63?(t.consume(k),v):R(k)?(s=C,me(k)):(t.consume(k),C)}function v(k){return k===62?le(k):C(k)}function I(k){return ge(k)?(t.consume(k),w):n(k)}function w(k){return k===45||ye(k)?(t.consume(k),w):N(k)}function N(k){return R(k)?(s=N,me(k)):_(k)?(t.consume(k),N):le(k)}function D(k){return k===45||ye(k)?(t.consume(k),D):k===47||k===62||U(k)?B(k):n(k)}function B(k){return k===47?(t.consume(k),le):k===58||k===95||ge(k)?(t.consume(k),S):R(k)?(s=B,me(k)):_(k)?(t.consume(k),B):le(k)}function S(k){return k===45||k===46||k===58||k===95||ye(k)?(t.consume(k),S):ce(k)}function ce(k){return k===61?(t.consume(k),Y):R(k)?(s=ce,me(k)):_(k)?(t.consume(k),ce):B(k)}function Y(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(t.consume(k),i=k,L):R(k)?(s=Y,me(k)):_(k)?(t.consume(k),Y):(t.consume(k),W)}function L(k){return k===i?(t.consume(k),i=void 0,j):k===null?n(k):R(k)?(s=L,me(k)):(t.consume(k),L)}function W(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||U(k)?B(k):(t.consume(k),W)}function j(k){return k===47||k===62||U(k)?B(k):n(k)}function le(k){return k===62?(t.consume(k),t.exit("htmlTextData"),t.exit("htmlText"),e):n(k)}function me(k){return t.exit("htmlTextData"),t.enter("lineEnding"),t.consume(k),t.exit("lineEnding"),ut}function ut(k){return _(k)?F(t,Mt,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):Mt(k)}function Mt(k){return t.enter("htmlTextData"),s(k)}}var An={name:"labelEnd",resolveAll:hw,resolveTo:mw,tokenize:gw},fw={tokenize:yw},dw={tokenize:kw},pw={tokenize:bw};function hw(t){let e=-1,n=[];for(;++e<t.length;){let r=t[e][1];if(n.push(t[e]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){let i=r.type==="labelImage"?4:2;r.type="data",e+=i}}return t.length!==n.length&&ue(t,0,t.length,n),t}function mw(t,e){let n=t.length,r=0,i,o,s,a;for(;n--;)if(i=t[n][1],o){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;t[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(s){if(t[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(o=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(s=n);let l={type:t[o][1].type==="labelLink"?"link":"image",start:{...t[o][1].start},end:{...t[t.length-1][1].end}},c={type:"label",start:{...t[o][1].start},end:{...t[s][1].end}},u={type:"labelText",start:{...t[o+r+2][1].end},end:{...t[s-2][1].start}};return a=[["enter",l,e],["enter",c,e]],a=Be(a,t.slice(o+1,o+r+3)),a=Be(a,[["enter",u,e]]),a=Be(a,nn(e.parser.constructs.insideSpan.null,t.slice(o+r+4,s-3),e)),a=Be(a,[["exit",u,e],t[s-2],t[s-1],["exit",c,e]]),a=Be(a,t.slice(s+1)),a=Be(a,[["exit",l,e]]),ue(t,o,t.length,a),t}function gw(t,e,n){let r=this,i=r.events.length,o,s;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){o=r.events[i][1];break}return a;function a(d){return o?o._inactive?f(d):(s=r.parser.defined.includes(Ae(r.sliceSerialize({start:o.end,end:r.now()}))),t.enter("labelEnd"),t.enter("labelMarker"),t.consume(d),t.exit("labelMarker"),t.exit("labelEnd"),l):n(d)}function l(d){return d===40?t.attempt(fw,u,s?u:f)(d):d===91?t.attempt(dw,u,s?c:f)(d):s?u(d):f(d)}function c(d){return t.attempt(pw,u,f)(d)}function u(d){return e(d)}function f(d){return o._balanced=!0,n(d)}}function yw(t,e,n){return r;function r(f){return t.enter("resource"),t.enter("resourceMarker"),t.consume(f),t.exit("resourceMarker"),i}function i(f){return U(f)?In(t,o)(f):o(f)}function o(f){return f===41?u(f):Ro(t,s,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function s(f){return U(f)?In(t,l)(f):u(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?Do(t,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):u(f)}function c(f){return U(f)?In(t,u)(f):u(f)}function u(f){return f===41?(t.enter("resourceMarker"),t.consume(f),t.exit("resourceMarker"),t.exit("resource"),e):n(f)}}function kw(t,e,n){let r=this;return i;function i(a){return Oo.call(r,t,o,s,"reference","referenceMarker","referenceString")(a)}function o(a){return r.parser.defined.includes(Ae(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?e(a):n(a)}function s(a){return n(a)}}function bw(t,e,n){return r;function r(o){return t.enter("reference"),t.enter("referenceMarker"),t.consume(o),t.exit("referenceMarker"),i}function i(o){return o===93?(t.enter("referenceMarker"),t.consume(o),t.exit("referenceMarker"),t.exit("reference"),e):n(o)}}var Da={name:"labelStartImage",resolveAll:An.resolveAll,tokenize:xw};function xw(t,e,n){let r=this;return i;function i(a){return t.enter("labelImage"),t.enter("labelImageMarker"),t.consume(a),t.exit("labelImageMarker"),o}function o(a){return a===91?(t.enter("labelMarker"),t.consume(a),t.exit("labelMarker"),t.exit("labelImage"),s):n(a)}function s(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):e(a)}}var Ba={name:"labelStartLink",resolveAll:An.resolveAll,tokenize:ww};function ww(t,e,n){let r=this;return i;function i(s){return t.enter("labelLink"),t.enter("labelMarker"),t.consume(s),t.exit("labelMarker"),t.exit("labelLink"),o}function o(s){return s===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(s):e(s)}}var yi={name:"lineEnding",tokenize:Sw};function Sw(t,e){return n;function n(r){return t.enter("lineEnding"),t.consume(r),t.exit("lineEnding"),F(t,e,"linePrefix")}}var Nn={name:"thematicBreak",tokenize:Cw};function Cw(t,e,n){let r=0,i;return o;function o(c){return t.enter("thematicBreak"),s(c)}function s(c){return i=c,a(c)}function a(c){return c===i?(t.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||R(c))?(t.exit("thematicBreak"),e(c)):n(c)}function l(c){return c===i?(t.consume(c),r++,l):(t.exit("thematicBreakSequence"),_(c)?F(t,a,"whitespace")(c):a(c))}}var Ne={continuation:{tokenize:vw},exit:Aw,name:"list",tokenize:Tw},Mw={partial:!0,tokenize:Nw},Ew={partial:!0,tokenize:Iw};function Tw(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(p){let h=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(h==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:pi(p)){if(r.containerState.type||(r.containerState.type=h,t.enter(h,{_container:!0})),h==="listUnordered")return t.enter("listItemPrefix"),p===42||p===45?t.check(Nn,n,c)(p):c(p);if(!r.interrupt||p===49)return t.enter("listItemPrefix"),t.enter("listItemValue"),l(p)}return n(p)}function l(p){return pi(p)&&++s<10?(t.consume(p),l):(!r.interrupt||s<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(t.exit("listItemValue"),c(p)):n(p)}function c(p){return t.enter("listItemMarker"),t.consume(p),t.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,t.check(Tt,r.interrupt?n:u,t.attempt(Mw,d,f))}function u(p){return r.containerState.initialBlankLine=!0,o++,d(p)}function f(p){return _(p)?(t.enter("listItemPrefixWhitespace"),t.consume(p),t.exit("listItemPrefixWhitespace"),d):n(p)}function d(p){return r.containerState.size=o+r.sliceSerialize(t.exit("listItemPrefix"),!0).length,e(p)}}function vw(t,e,n){let r=this;return r.containerState._closeFlow=void 0,t.check(Tt,i,o);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,F(t,e,"listItemIndent",r.containerState.size+1)(a)}function o(a){return r.containerState.furtherBlankLines||!_(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,t.attempt(Ew,e,s)(a))}function s(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,F(t,t.attempt(Ne,e,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Iw(t,e,n){let r=this;return F(t,i,"listItemIndent",r.containerState.size+1);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===r.containerState.size?e(o):n(o)}}function Aw(t){t.exit(this.containerState.type)}function Nw(t,e,n){let r=this;return F(t,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(o){let s=r.events[r.events.length-1];return!_(o)&&s&&s[1].type==="listItemPrefixWhitespace"?e(o):n(o)}}var Bo={name:"setextUnderline",resolveTo:Rw,tokenize:Ow};function Rw(t,e){let n=t.length,r,i,o;for(;n--;)if(t[n][0]==="enter"){if(t[n][1].type==="content"){r=n;break}t[n][1].type==="paragraph"&&(i=n)}else t[n][1].type==="content"&&t.splice(n,1),!o&&t[n][1].type==="definition"&&(o=n);let s={type:"setextHeading",start:{...t[r][1].start},end:{...t[t.length-1][1].end}};return t[i][1].type="setextHeadingText",o?(t.splice(i,0,["enter",s,e]),t.splice(o+1,0,["exit",t[r][1],e]),t[r][1].end={...t[o][1].end}):t[r][1]=s,t.push(["exit",s,e]),t}function Ow(t,e,n){let r=this,i;return o;function o(c){let u=r.events.length,f;for(;u--;)if(r.events[u][1].type!=="lineEnding"&&r.events[u][1].type!=="linePrefix"&&r.events[u][1].type!=="content"){f=r.events[u][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(t.enter("setextHeadingLine"),i=c,s(c)):n(c)}function s(c){return t.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===i?(t.consume(c),a):(t.exit("setextHeadingLineSequence"),_(c)?F(t,l,"lineSuffix")(c):l(c))}function l(c){return c===null||R(c)?(t.exit("setextHeadingLine"),e(c)):n(c)}}var Md={tokenize:Dw};function Dw(t){let e=this,n=t.attempt(Tt,r,t.attempt(this.parser.constructs.flowInitial,i,F(t,t.attempt(this.parser.constructs.flow,i,t.attempt(Ta,i)),"linePrefix")));return n;function r(o){if(o===null){t.consume(o);return}return t.enter("lineEndingBlank"),t.consume(o),t.exit("lineEndingBlank"),e.currentConstruct=void 0,n}function i(o){if(o===null){t.consume(o);return}return t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),e.currentConstruct=void 0,n}}var Ed={resolveAll:Ad()},Td=Id("string"),vd=Id("text");function Id(t){return{resolveAll:Ad(t==="text"?Bw:void 0),tokenize:e};function e(n){let r=this,i=this.parser.constructs[t],o=n.attempt(i,s,a);return s;function s(u){return c(u)?o(u):a(u)}function a(u){if(u===null){n.consume(u);return}return n.enter("data"),n.consume(u),l}function l(u){return c(u)?(n.exit("data"),o(u)):(n.consume(u),l)}function c(u){if(u===null)return!0;let f=i[u],d=-1;if(f)for(;++d<f.length;){let p=f[d];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function Ad(t){return e;function e(n,r){let i=-1,o;for(;++i<=n.length;)o===void 0?n[i]&&n[i][1].type==="data"&&(o=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==o+2&&(n[o][1].end=n[i-1][1].end,n.splice(o+2,i-o-2),i=o+2),o=void 0);return t?t(n,r):n}}function Bw(t,e){let n=0;for(;++n<=t.length;)if((n===t.length||t[n][1].type==="lineEnding")&&t[n-1][1].type==="data"){let r=t[n-1][1],i=e.sliceStream(r),o=i.length,s=-1,a=0,l;for(;o--;){let c=i[o];if(typeof c=="string"){for(s=c.length;c.charCodeAt(s-1)===32;)a++,s--;if(s)break;s=-1}else if(c===-2)l=!0,a++;else if(c!==-1){o++;break}}if(e._contentTypeTextTrailing&&n===t.length&&(a=0),a){let c={type:n===t.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?s:r.start._bufferIndex+s,_index:r.start._index+o,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...c.start},r.start.offset===r.end.offset?Object.assign(r,c):(t.splice(n,0,["enter",c,e],["exit",c,e]),n+=2)}n++}return t}var La={};hx(La,{attentionMarkers:()=>Vw,contentInitial:()=>Pw,disable:()=>Ww,document:()=>Lw,flow:()=>zw,flowInitial:()=>Fw,insideSpan:()=>Hw,string:()=>$w,text:()=>_w});var Lw={42:Ne,43:Ne,45:Ne,48:Ne,49:Ne,50:Ne,51:Ne,52:Ne,53:Ne,54:Ne,55:Ne,56:Ne,57:Ne,62:Eo},Pw={91:va},Fw={[-2]:mi,[-1]:mi,32:mi},zw={35:Aa,42:Nn,45:[Bo,Nn],60:Ra,61:Bo,95:Nn,96:Io,126:Io},$w={38:vo,92:To},_w={[-5]:yi,[-4]:yi,[-3]:yi,33:Da,38:vo,42:hi,60:[Ma,Oa],91:Ba,92:[Ia,To],93:An,95:hi,96:Ea},Hw={null:[hi,Ed]},Vw={null:[42,95]},Ww={null:[]};function Nd(t,e,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},o=[],s=[],a=[],l=!0,c={attempt:B(N),check:B(D),consume:v,enter:I,exit:w,interrupt:B(D,{interrupt:!0})},u={code:null,containerState:{},defineSkip:y,events:[],now:g,parser:t,previous:null,sliceSerialize:h,sliceStream:m,write:p},f=e.tokenize.call(u,c),d;return e.resolveAll&&o.push(e),u;function p(L){return s=Be(s,L),x(),s[s.length-1]!==null?[]:(S(e,0),u.events=nn(o,u.events,u),u.events)}function h(L,W){return qw(m(L),W)}function m(L){return jw(s,L)}function g(){let{_bufferIndex:L,_index:W,line:j,column:le,offset:me}=r;return{_bufferIndex:L,_index:W,line:j,column:le,offset:me}}function y(L){i[L.line]=L.column,Y()}function x(){let L;for(;r._index<s.length;){let W=s[r._index];if(typeof W=="string")for(L=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===L&&r._bufferIndex<W.length;)C(W.charCodeAt(r._bufferIndex));else C(W)}}function C(L){l=void 0,d=L,f=f(L)}function v(L){R(L)?(r.line++,r.column=1,r.offset+=L===-3?2:1,Y()):L!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===s[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=L,l=!0}function I(L,W){let j=W||{};return j.type=L,j.start=g(),u.events.push(["enter",j,u]),a.push(j),j}function w(L){let W=a.pop();return W.end=g(),u.events.push(["exit",W,u]),W}function N(L,W){S(L,W.from)}function D(L,W){W.restore()}function B(L,W){return j;function j(le,me,ut){let Mt,k,Xe,Bt;return Array.isArray(le)?We(le):"tokenize"in le?We([le]):b(le);function b(Me){return ui;function ui(Lt){let Cn=Lt!==null&&Me[Lt],ur=Lt!==null&&Me.null,xa=[...Array.isArray(Cn)?Cn:Cn?[Cn]:[],...Array.isArray(ur)?ur:ur?[ur]:[]];return We(xa)(Lt)}}function We(Me){return Mt=Me,k=0,Me.length===0?ut:Sn(Me[k])}function Sn(Me){return ui;function ui(Lt){return Bt=ce(),Xe=Me,Me.partial||(u.currentConstruct=Me),Me.name&&u.parser.constructs.disable.null.includes(Me.name)?xo(Lt):Me.tokenize.call(W?Object.assign(Object.create(u),W):u,c,ba,xo)(Lt)}}function ba(Me){return l=!0,L(Xe,Bt),me}function xo(Me){return l=!0,Bt.restore(),++k<Mt.length?Sn(Mt[k]):ut}}}function S(L,W){L.resolveAll&&!o.includes(L)&&o.push(L),L.resolve&&ue(u.events,W,u.events.length-W,L.resolve(u.events.slice(W),u)),L.resolveTo&&(u.events=L.resolveTo(u.events,u))}function ce(){let L=g(),W=u.previous,j=u.currentConstruct,le=u.events.length,me=Array.from(a);return{from:le,restore:ut};function ut(){r=L,u.previous=W,u.currentConstruct=j,u.events.length=le,a=me,Y()}}function Y(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function jw(t,e){let n=e.start._index,r=e.start._bufferIndex,i=e.end._index,o=e.end._bufferIndex,s;if(n===i)s=[t[n].slice(r,o)];else{if(s=t.slice(n,i),r>-1){let a=s[0];typeof a=="string"?s[0]=a.slice(r):s.shift()}o>0&&s.push(t[i].slice(0,o))}return s}function qw(t,e){let n=-1,r=[],i;for(;++n<t.length;){let o=t[n],s;if(typeof o=="string")s=o;else switch(o){case-5:{s="\r";break}case-4:{s=` +"use strict";(()=>{var cx=Object.create;var wa=Object.defineProperty;var ux=Object.getOwnPropertyDescriptor;var fx=Object.getOwnPropertyNames;var dx=Object.getPrototypeOf,px=Object.prototype.hasOwnProperty;var hx=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},mx=(t,e)=>{for(var n in e)wa(t,n,{get:e[n],enumerable:!0})},gx=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of fx(e))!px.call(t,i)&&i!==n&&wa(t,i,{get:()=>e[i],enumerable:!(r=ux(e,i))||r.enumerable});return t};var yx=(t,e,n)=>(n=t!=null?cx(dx(t)):{},gx(e||!t||!t.__esModule?wa(n,"default",{value:t,enumerable:!0}):n,t));var Mp=hx((dP,Cp)=>{"use strict";var Vo=Object.prototype.hasOwnProperty,Sp=Object.prototype.toString,gp=Object.defineProperty,yp=Object.getOwnPropertyDescriptor,kp=function(e){return typeof Array.isArray=="function"?Array.isArray(e):Sp.call(e)==="[object Array]"},bp=function(e){if(!e||Sp.call(e)!=="[object Object]")return!1;var n=Vo.call(e,"constructor"),r=e.constructor&&e.constructor.prototype&&Vo.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!n&&!r)return!1;var i;for(i in e);return typeof i>"u"||Vo.call(e,i)},xp=function(e,n){gp&&n.name==="__proto__"?gp(e,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):e[n.name]=n.newValue},wp=function(e,n){if(n==="__proto__")if(Vo.call(e,n)){if(yp)return yp(e,n).value}else return;return e[n]};Cp.exports=function t(){var e,n,r,i,o,s,a=arguments[0],l=1,c=arguments.length,u=!1;for(typeof a=="boolean"&&(u=a,a=arguments[1]||{},l=2),(a==null||typeof a!="object"&&typeof a!="function")&&(a={});l<c;++l)if(e=arguments[l],e!=null)for(n in e)r=wp(a,n),i=wp(e,n),a!==i&&(u&&i&&(bp(i)||(o=kp(i)))?(o?(o=!1,s=r&&kp(r)?r:[]):s=r&&bp(r)?r:{},xp(a,{name:n,newValue:t(u,s,i)})):typeof i<"u"&&xp(a,{name:n,newValue:i}));return a}});var Ze=(function(t){return t.docTypeError="docTypeError",t.contextNotFound="contextNotFound",t.timerNotFound="timerNotFound",t.ctxCallOutOfScope="ctxCallOutOfScope",t.createNodeInParserFail="createNodeInParserFail",t.stackOverFlow="stackOverFlow",t.parserMatchError="parserMatchError",t.serializerMatchError="serializerMatchError",t.getAtomFromSchemaFail="getAtomFromSchemaFail",t.expectDomTypeError="expectDomTypeError",t.callCommandBeforeEditorView="callCommandBeforeEditorView",t.missingRootElement="missingRootElement",t.missingNodeInSchema="missingNodeInSchema",t.missingMarkInSchema="missingMarkInSchema",t.ctxNotBind="ctxNotBind",t.missingYjsDoc="missingYjsDoc",t.aiProviderError="aiProviderError",t.aiBuildContextError="aiBuildContextError",t})({}),et=class extends Error{constructor(t,e,n){super(e,n),this.name="MilkdownError",this.code=t,n?.cause!==void 0&&(this.cause=n.cause)}},kx=(t,e)=>typeof e=="function"?"[Function]":e,wo=t=>JSON.stringify(t,kx);function td(t){return new et(Ze.docTypeError,`Doc type error, unsupported type: ${wo(t)}`)}function nd(t){return new et(Ze.contextNotFound,`Context "${t}" not found, do you forget to inject it?`)}function rd(t){return new et(Ze.timerNotFound,`Timer "${t}" not found, do you forget to record it?`)}function dr(){return new et(Ze.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function id(t,e,n){let r=`Cannot create node for ${"name"in t?t.name:t}`,i=s=>{if(s==null)return"null";if(Array.isArray(s))return`[${s.map(i).join(", ")}]`;if(typeof s=="object")return"toJSON"in s&&typeof s.toJSON=="function"?JSON.stringify(s.toJSON()):"spec"in s?JSON.stringify(s.spec):JSON.stringify(s);if(typeof s=="string"||typeof s=="number"||typeof s=="boolean")return JSON.stringify(s);if(typeof s=="function")return`[Function: ${s.name||"anonymous"}]`;try{return String(s)}catch{return"[Unserializable]"}},o=[["[Description]",r],["[Attributes]",e],["[Content]",(n??[]).map(s=>s?typeof s=="object"&&"type"in s?`${s}`:i(s):"null")]].reduce((s,[a,l])=>{let c=`${a}: ${i(l)}.`;return s.concat(c)},[]);return new et(Ze.createNodeInParserFail,o.join(` +`))}function Sa(){return new et(Ze.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function od(t){return new et(Ze.parserMatchError,`Cannot match target parser for node: ${wo(t)}.`)}function sd(t){return new et(Ze.serializerMatchError,`Cannot match target serializer for node: ${wo(t)}.`)}function tt(t){return new et(Ze.expectDomTypeError,`Expect to be a dom, but get: ${wo(t)}.`)}function So(){return new et(Ze.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function ad(t){return new et(Ze.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${t}" in schema.`)}function ld(t){return new et(Ze.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${t}" in schema.`)}var Ca=class{constructor(){this.sliceMap=new Map,this.get=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);if(!e)throw nd(typeof t=="string"?t:t.name);return e},this.remove=t=>{let e=typeof t=="string"?[...this.sliceMap.values()].find(n=>n.type.name===t):this.sliceMap.get(t.id);e&&this.sliceMap.delete(e.type.id)},this.has=t=>typeof t=="string"?[...this.sliceMap.values()].some(e=>e.type.name===t):this.sliceMap.has(t.id)}},bx=class{#t;#e;#r;constructor(t,e,n){this.#t=[],this.#r=()=>{this.#t.forEach(r=>r(this.#e))},this.set=r=>{this.#e=r,this.#r()},this.get=()=>this.#e,this.update=r=>{this.#e=r(this.#e),this.#r()},this.type=n,this.#e=e,t.set(n.id,this)}on(t){return this.#t.push(t),()=>{this.#t=this.#t.filter(e=>e!==t)}}once(t){let e=this.on(n=>{t(n),e()});return e}off(t){this.#t=this.#t.filter(e=>e!==t)}offAll(){this.#t=[]}},xx=class{constructor(t,e){this.id=Symbol(`Context-${e}`),this.name=e,this._defaultValue=t,this._typeInfo=()=>{throw dr()}}create(t,e=this._defaultValue){return new bx(t,e,this)}},K=(t,e)=>new xx(t,e),wx=class{#t;#e;#r;#n;#s;#o;#i;constructor(t,e,n){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#i=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),consumedSlices:[...this.#s].map(r=>({name:typeof r=="string"?r:r.name,value:this.#a(r)})),recordedTimers:[...this.#o].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)})),waitTimers:[...this.#i].map(([r,{duration:i}])=>({name:r.name,duration:i,status:this.#l(r)}))}),this.onRecord=r=>{this.#o.set(r,{start:Date.now(),duration:0})},this.onClear=r=>{this.#o.delete(r)},this.onDone=r=>{let i=this.#o.get(r);i&&(i.duration=Date.now()-i.start)},this.onWait=(r,i)=>{let o=Date.now();i.finally(()=>{this.#i.set(r,{duration:Date.now()-o})}).catch(console.error)},this.onInject=r=>{this.#n.add(r)},this.onRemove=r=>{this.#n.delete(r)},this.onUse=r=>{this.#s.add(r)},this.#a=r=>this.#e.get(r).get(),this.#l=r=>this.#r.get(r).status,this.#e=t,this.#r=e,this.#t=n}#a;#l},cd=class ud{#t;#e;#r;#n;constructor(e,n,r){this.produce=i=>i&&Object.keys(i).length?new ud(this.#t,this.#e,{...i}):this,this.inject=(i,o)=>{let s=i.create(this.#t.sliceMap);return o!=null&&s.set(o),this.#n?.onInject(i),this},this.remove=i=>(this.#t.remove(i),this.#n?.onRemove(i),this),this.record=i=>(i.create(this.#e.store),this.#n?.onRecord(i),this),this.clearTimer=i=>(this.#e.remove(i),this.#n?.onClear(i),this),this.isInjected=i=>this.#t.has(i),this.isRecorded=i=>this.#e.has(i),this.use=i=>(this.#n?.onUse(i),this.#t.get(i)),this.get=i=>this.use(i).get(),this.set=(i,o)=>this.use(i).set(o),this.update=(i,o)=>this.use(i).update(o),this.timer=i=>this.#e.get(i),this.done=i=>{this.timer(i).done(),this.#n?.onDone(i)},this.wait=i=>{let o=this.timer(i).start();return this.#n?.onWait(i,o),o},this.waitTimers=async i=>{await Promise.all(this.get(i).map(o=>this.wait(o)))},this.#t=e,this.#e=n,this.#r=r,r&&(this.#n=new wx(e,n,r))}get meta(){return this.#r}get inspector(){return this.#n}},fd=class{constructor(){this.store=new Map,this.get=t=>{let e=this.store.get(t.id);if(!e)throw rd(t.name);return e},this.remove=t=>{this.store.delete(t.id)},this.has=t=>this.store.has(t.id)}},Sx=class{#t;#e;#r;#n;constructor(t,e){this.#t=null,this.#e=null,this.#n="pending",this.start=()=>(this.#t??=new Promise((n,r)=>{this.#e=i=>{i instanceof CustomEvent&&i.detail.id===this.#r&&(this.#n="resolved",this.#s(),i.stopImmediatePropagation(),n())},this.#o(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#s(),r(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{let n=new CustomEvent(this.type.name,{detail:{id:this.#r}});dispatchEvent(n)},this.#s=()=>{this.#e&&removeEventListener(this.type.name,this.#e)},this.#o=n=>{setTimeout(()=>{n()},this.type.timeout)},this.#r=Symbol(e.name),this.type=e,t.set(e.id,this)}get status(){return this.#n}#s;#o},Cx=class{constructor(t,e=3e3){this.create=n=>new Sx(n,this),this.id=Symbol(`Timer-${t}`),this.name=t,this.timeout=e}},nt=(t,e=3e3)=>new Cx(t,e);var Mx={};function En(t,e){let n=e||Mx,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return pd(t,r,i)}function pd(t,e,n){if(Ex(t)){if("value"in t)return t.type==="html"&&!n?"":t.value;if(e&&"alt"in t&&t.alt)return t.alt;if("children"in t)return dd(t.children,e,n)}return Array.isArray(t)?dd(t,e,n):""}function dd(t,e,n){let r=[],i=-1;for(;++i<t.length;)r[i]=pd(t[i],e,n);return r.join("")}function Ex(t){return!!(t&&typeof t=="object")}var hd=document.createElement("i");function pr(t){let e="&"+t+";";hd.innerHTML=e;let n=hd.textContent;return n.charCodeAt(n.length-1)===59&&t!=="semi"||n===e?!1:n}function ue(t,e,n,r){let i=t.length,o=0,s;if(e<0?e=-e>i?0:i+e:e=e>i?i:e,n=n>0?n:0,r.length<1e4)s=Array.from(r),s.unshift(e,n),t.splice(...s);else for(n&&t.splice(e,n);o<r.length;)s=r.slice(o,o+1e4),s.unshift(e,0),t.splice(...s),o+=1e4,e+=1e4}function Be(t,e){return t.length>0?(ue(t,t.length,0,e),t):e}var md={}.hasOwnProperty;function Co(t){let e={},n=-1;for(;++n<t.length;)Tx(e,t[n]);return e}function Tx(t,e){let n;for(n in e){let i=(md.call(t,n)?t[n]:void 0)||(t[n]={}),o=e[n],s;if(o)for(s in o){md.call(i,s)||(i[s]=[]);let a=o[s];vx(i[s],Array.isArray(a)?a:a?[a]:[])}}}function vx(t,e){let n=-1,r=[];for(;++n<e.length;)(e[n].add==="after"?t:r).push(e[n]);ue(t,0,0,r)}function Mo(t,e){let n=Number.parseInt(t,e);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"\uFFFD":String.fromCodePoint(n)}function Ae(t){return t.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}var ge=tn(/[A-Za-z]/),ye=tn(/[\dA-Za-z]/),gd=tn(/[#-'*+\--9=?A-Z^-~]/);function Tn(t){return t!==null&&(t<32||t===127)}var pi=tn(/\d/),yd=tn(/[\dA-Fa-f]/),kd=tn(/[!-/:-@[-`{-~]/);function R(t){return t!==null&&t<-2}function U(t){return t!==null&&(t<0||t===32)}function _(t){return t===-2||t===-1||t===32}var vn=tn(/\p{P}|\p{S}/u),Et=tn(/\s/);function tn(t){return e;function e(n){return n!==null&&n>-1&&t.test(String.fromCharCode(n))}}function F(t,e,n,r){let i=r?r-1:Number.POSITIVE_INFINITY,o=0;return s;function s(l){return _(l)?(t.enter(n),a(l)):e(l)}function a(l){return _(l)&&o++<i?(t.consume(l),a):(t.exit(n),e(l))}}var bd={tokenize:Ix};function Ix(t){let e=t.attempt(this.parser.constructs.contentInitial,r,i),n;return e;function r(a){if(a===null){t.consume(a);return}return t.enter("lineEnding"),t.consume(a),t.exit("lineEnding"),F(t,e,"linePrefix")}function i(a){return t.enter("paragraph"),o(a)}function o(a){let l=t.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,s(a)}function s(a){if(a===null){t.exit("chunkText"),t.exit("paragraph"),t.consume(a);return}return R(a)?(t.consume(a),t.exit("chunkText"),o):(t.consume(a),s)}}var wd={tokenize:Ax},xd={tokenize:Nx};function Ax(t){let e=this,n=[],r=0,i,o,s;return a;function a(C){if(r<n.length){let v=n[r];return e.containerState=v[1],t.attempt(v[0].continuation,l,c)(C)}return c(C)}function l(C){if(r++,e.containerState._closeFlow){e.containerState._closeFlow=void 0,i&&x();let v=e.events.length,I=v,w;for(;I--;)if(e.events[I][0]==="exit"&&e.events[I][1].type==="chunkFlow"){w=e.events[I][1].end;break}y(r);let N=v;for(;N<e.events.length;)e.events[N][1].end={...w},N++;return ue(e.events,I+1,0,e.events.slice(v)),e.events.length=N,c(C)}return a(C)}function c(C){if(r===n.length){if(!i)return d(C);if(i.currentConstruct&&i.currentConstruct.concrete)return h(C);e.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return e.containerState={},t.check(xd,u,f)(C)}function u(C){return i&&x(),y(r),d(C)}function f(C){return e.parser.lazy[e.now().line]=r!==n.length,s=e.now().offset,h(C)}function d(C){return e.containerState={},t.attempt(xd,p,h)(C)}function p(C){return r++,n.push([e.currentConstruct,e.containerState]),d(C)}function h(C){if(C===null){i&&x(),y(0),t.consume(C);return}return i=i||e.parser.flow(e.now()),t.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:o}),m(C)}function m(C){if(C===null){g(t.exit("chunkFlow"),!0),y(0),t.consume(C);return}return R(C)?(t.consume(C),g(t.exit("chunkFlow")),r=0,e.interrupt=void 0,a):(t.consume(C),m)}function g(C,v){let I=e.sliceStream(C);if(v&&I.push(null),C.previous=o,o&&(o.next=C),o=C,i.defineSkip(C.start),i.write(I),e.parser.lazy[C.start.line]){let w=i.events.length;for(;w--;)if(i.events[w][1].start.offset<s&&(!i.events[w][1].end||i.events[w][1].end.offset>s))return;let N=e.events.length,D=N,B,S;for(;D--;)if(e.events[D][0]==="exit"&&e.events[D][1].type==="chunkFlow"){if(B){S=e.events[D][1].end;break}B=!0}for(y(r),w=N;w<e.events.length;)e.events[w][1].end={...S},w++;ue(e.events,D+1,0,e.events.slice(N)),e.events.length=w}}function y(C){let v=n.length;for(;v-- >C;){let I=n[v];e.containerState=I[1],I[0].exit.call(e,t)}n.length=C}function x(){i.write([null]),o=void 0,i=void 0,e.containerState._closeFlow=void 0}}function Nx(t,e,n){return F(t,t.attempt(this.parser.constructs.document,e,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function zt(t){if(t===null||U(t)||Et(t))return 1;if(vn(t))return 2}function nn(t,e,n){let r=[],i=-1;for(;++i<t.length;){let o=t[i].resolveAll;o&&!r.includes(o)&&(e=o(e,n),r.push(o))}return e}var hi={name:"attention",resolveAll:Rx,tokenize:Ox};function Rx(t,e){let n=-1,r,i,o,s,a,l,c,u;for(;++n<t.length;)if(t[n][0]==="enter"&&t[n][1].type==="attentionSequence"&&t[n][1]._close){for(r=n;r--;)if(t[r][0]==="exit"&&t[r][1].type==="attentionSequence"&&t[r][1]._open&&e.sliceSerialize(t[r][1]).charCodeAt(0)===e.sliceSerialize(t[n][1]).charCodeAt(0)){if((t[r][1]._close||t[n][1]._open)&&(t[n][1].end.offset-t[n][1].start.offset)%3&&!((t[r][1].end.offset-t[r][1].start.offset+t[n][1].end.offset-t[n][1].start.offset)%3))continue;l=t[r][1].end.offset-t[r][1].start.offset>1&&t[n][1].end.offset-t[n][1].start.offset>1?2:1;let f={...t[r][1].end},d={...t[n][1].start};Sd(f,-l),Sd(d,l),s={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...t[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...t[n][1].start},end:d},o={type:l>1?"strongText":"emphasisText",start:{...t[r][1].end},end:{...t[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...s.start},end:{...a.end}},t[r][1].end={...s.start},t[n][1].start={...a.end},c=[],t[r][1].end.offset-t[r][1].start.offset&&(c=Be(c,[["enter",t[r][1],e],["exit",t[r][1],e]])),c=Be(c,[["enter",i,e],["enter",s,e],["exit",s,e],["enter",o,e]]),c=Be(c,nn(e.parser.constructs.insideSpan.null,t.slice(r+1,n),e)),c=Be(c,[["exit",o,e],["enter",a,e],["exit",a,e],["exit",i,e]]),t[n][1].end.offset-t[n][1].start.offset?(u=2,c=Be(c,[["enter",t[n][1],e],["exit",t[n][1],e]])):u=0,ue(t,r-1,n-r+3,c),n=r+c.length-u-2;break}}for(n=-1;++n<t.length;)t[n][1].type==="attentionSequence"&&(t[n][1].type="data");return t}function Ox(t,e){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=zt(r),o;return s;function s(l){return o=l,t.enter("attentionSequence"),a(l)}function a(l){if(l===o)return t.consume(l),a;let c=t.exit("attentionSequence"),u=zt(l),f=!u||u===2&&i||n.includes(l),d=!i||i===2&&u||n.includes(r);return c._open=!!(o===42?f:f&&(i||!d)),c._close=!!(o===42?d:d&&(u||!f)),e(l)}}function Sd(t,e){t.column+=e,t.offset+=e,t._bufferIndex+=e}var Ma={name:"autolink",tokenize:Dx};function Dx(t,e,n){let r=0;return i;function i(p){return t.enter("autolink"),t.enter("autolinkMarker"),t.consume(p),t.exit("autolinkMarker"),t.enter("autolinkProtocol"),o}function o(p){return ge(p)?(t.consume(p),s):p===64?n(p):c(p)}function s(p){return p===43||p===45||p===46||ye(p)?(r=1,a(p)):c(p)}function a(p){return p===58?(t.consume(p),r=0,l):(p===43||p===45||p===46||ye(p))&&r++<32?(t.consume(p),a):(r=0,c(p))}function l(p){return p===62?(t.exit("autolinkProtocol"),t.enter("autolinkMarker"),t.consume(p),t.exit("autolinkMarker"),t.exit("autolink"),e):p===null||p===32||p===60||Tn(p)?n(p):(t.consume(p),l)}function c(p){return p===64?(t.consume(p),u):gd(p)?(t.consume(p),c):n(p)}function u(p){return ye(p)?f(p):n(p)}function f(p){return p===46?(t.consume(p),r=0,u):p===62?(t.exit("autolinkProtocol").type="autolinkEmail",t.enter("autolinkMarker"),t.consume(p),t.exit("autolinkMarker"),t.exit("autolink"),e):d(p)}function d(p){if((p===45||ye(p))&&r++<63){let h=p===45?d:f;return t.consume(p),h}return n(p)}}var Tt={partial:!0,tokenize:Bx};function Bx(t,e,n){return r;function r(o){return _(o)?F(t,i,"linePrefix")(o):i(o)}function i(o){return o===null||R(o)?e(o):n(o)}}var Eo={continuation:{tokenize:Px},exit:Fx,name:"blockQuote",tokenize:Lx};function Lx(t,e,n){let r=this;return i;function i(s){if(s===62){let a=r.containerState;return a.open||(t.enter("blockQuote",{_container:!0}),a.open=!0),t.enter("blockQuotePrefix"),t.enter("blockQuoteMarker"),t.consume(s),t.exit("blockQuoteMarker"),o}return n(s)}function o(s){return _(s)?(t.enter("blockQuotePrefixWhitespace"),t.consume(s),t.exit("blockQuotePrefixWhitespace"),t.exit("blockQuotePrefix"),e):(t.exit("blockQuotePrefix"),e(s))}}function Px(t,e,n){let r=this;return i;function i(s){return _(s)?F(t,o,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(s):o(s)}function o(s){return t.attempt(Eo,e,n)(s)}}function Fx(t){t.exit("blockQuote")}var To={name:"characterEscape",tokenize:zx};function zx(t,e,n){return r;function r(o){return t.enter("characterEscape"),t.enter("escapeMarker"),t.consume(o),t.exit("escapeMarker"),i}function i(o){return kd(o)?(t.enter("characterEscapeValue"),t.consume(o),t.exit("characterEscapeValue"),t.exit("characterEscape"),e):n(o)}}var vo={name:"characterReference",tokenize:$x};function $x(t,e,n){let r=this,i=0,o,s;return a;function a(f){return t.enter("characterReference"),t.enter("characterReferenceMarker"),t.consume(f),t.exit("characterReferenceMarker"),l}function l(f){return f===35?(t.enter("characterReferenceMarkerNumeric"),t.consume(f),t.exit("characterReferenceMarkerNumeric"),c):(t.enter("characterReferenceValue"),o=31,s=ye,u(f))}function c(f){return f===88||f===120?(t.enter("characterReferenceMarkerHexadecimal"),t.consume(f),t.exit("characterReferenceMarkerHexadecimal"),t.enter("characterReferenceValue"),o=6,s=yd,u):(t.enter("characterReferenceValue"),o=7,s=pi,u(f))}function u(f){if(f===59&&i){let d=t.exit("characterReferenceValue");return s===ye&&!pr(r.sliceSerialize(d))?n(f):(t.enter("characterReferenceMarker"),t.consume(f),t.exit("characterReferenceMarker"),t.exit("characterReference"),e)}return s(f)&&i++<o?(t.consume(f),u):n(f)}}var Cd={partial:!0,tokenize:Hx},Io={concrete:!0,name:"codeFenced",tokenize:_x};function _x(t,e,n){let r=this,i={partial:!0,tokenize:I},o=0,s=0,a;return l;function l(w){return c(w)}function c(w){let N=r.events[r.events.length-1];return o=N&&N[1].type==="linePrefix"?N[2].sliceSerialize(N[1],!0).length:0,a=w,t.enter("codeFenced"),t.enter("codeFencedFence"),t.enter("codeFencedFenceSequence"),u(w)}function u(w){return w===a?(s++,t.consume(w),u):s<3?n(w):(t.exit("codeFencedFenceSequence"),_(w)?F(t,f,"whitespace")(w):f(w))}function f(w){return w===null||R(w)?(t.exit("codeFencedFence"),r.interrupt?e(w):t.check(Cd,m,v)(w)):(t.enter("codeFencedFenceInfo"),t.enter("chunkString",{contentType:"string"}),d(w))}function d(w){return w===null||R(w)?(t.exit("chunkString"),t.exit("codeFencedFenceInfo"),f(w)):_(w)?(t.exit("chunkString"),t.exit("codeFencedFenceInfo"),F(t,p,"whitespace")(w)):w===96&&w===a?n(w):(t.consume(w),d)}function p(w){return w===null||R(w)?f(w):(t.enter("codeFencedFenceMeta"),t.enter("chunkString",{contentType:"string"}),h(w))}function h(w){return w===null||R(w)?(t.exit("chunkString"),t.exit("codeFencedFenceMeta"),f(w)):w===96&&w===a?n(w):(t.consume(w),h)}function m(w){return t.attempt(i,v,g)(w)}function g(w){return t.enter("lineEnding"),t.consume(w),t.exit("lineEnding"),y}function y(w){return o>0&&_(w)?F(t,x,"linePrefix",o+1)(w):x(w)}function x(w){return w===null||R(w)?t.check(Cd,m,v)(w):(t.enter("codeFlowValue"),C(w))}function C(w){return w===null||R(w)?(t.exit("codeFlowValue"),x(w)):(t.consume(w),C)}function v(w){return t.exit("codeFenced"),e(w)}function I(w,N,D){let B=0;return S;function S(j){return w.enter("lineEnding"),w.consume(j),w.exit("lineEnding"),ce}function ce(j){return w.enter("codeFencedFence"),_(j)?F(w,Y,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(j):Y(j)}function Y(j){return j===a?(w.enter("codeFencedFenceSequence"),L(j)):D(j)}function L(j){return j===a?(B++,w.consume(j),L):B>=s?(w.exit("codeFencedFenceSequence"),_(j)?F(w,W,"whitespace")(j):W(j)):D(j)}function W(j){return j===null||R(j)?(w.exit("codeFencedFence"),N(j)):D(j)}}}function Hx(t,e,n){let r=this;return i;function i(s){return s===null?n(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}var mi={name:"codeIndented",tokenize:Wx},Vx={partial:!0,tokenize:jx};function Wx(t,e,n){let r=this;return i;function i(c){return t.enter("codeIndented"),F(t,o,"linePrefix",5)(c)}function o(c){let u=r.events[r.events.length-1];return u&&u[1].type==="linePrefix"&&u[2].sliceSerialize(u[1],!0).length>=4?s(c):n(c)}function s(c){return c===null?l(c):R(c)?t.attempt(Vx,s,l)(c):(t.enter("codeFlowValue"),a(c))}function a(c){return c===null||R(c)?(t.exit("codeFlowValue"),s(c)):(t.consume(c),a)}function l(c){return t.exit("codeIndented"),e(c)}}function jx(t,e,n){let r=this;return i;function i(s){return r.parser.lazy[r.now().line]?n(s):R(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),i):F(t,o,"linePrefix",5)(s)}function o(s){let a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(s):R(s)?i(s):n(s)}}var Ea={name:"codeText",previous:Kx,resolve:qx,tokenize:Ux};function qx(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="codeTextData"){t[n][1].type="codeTextPadding",t[e][1].type="codeTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)i===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(i=r):(r===e||t[r][1].type==="lineEnding")&&(t[i][1].type="codeTextData",r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),e-=r-i-2,r=i+2),i=void 0);return t}function Kx(t){return t!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Ux(t,e,n){let r=this,i=0,o,s;return a;function a(d){return t.enter("codeText"),t.enter("codeTextSequence"),l(d)}function l(d){return d===96?(t.consume(d),i++,l):(t.exit("codeTextSequence"),c(d))}function c(d){return d===null?n(d):d===32?(t.enter("space"),t.consume(d),t.exit("space"),c):d===96?(s=t.enter("codeTextSequence"),o=0,f(d)):R(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),c):(t.enter("codeTextData"),u(d))}function u(d){return d===null||d===32||d===96||R(d)?(t.exit("codeTextData"),c(d)):(t.consume(d),u)}function f(d){return d===96?(t.consume(d),o++,f):o===i?(t.exit("codeTextSequence"),t.exit("codeText"),e(d)):(s.type="codeTextData",u(d))}}var Ao=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,n){let r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(e,r):e>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(e,n,r){let i=n||0;this.setCursor(Math.trunc(e));let o=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&gi(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),gi(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),gi(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e<this.left.length){let n=this.left.splice(e,Number.POSITIVE_INFINITY);gi(this.right,n.reverse())}else{let n=this.right.splice(this.left.length+this.right.length-e,Number.POSITIVE_INFINITY);gi(this.left,n.reverse())}}};function gi(t,e){let n=0;if(e.length<1e4)t.push(...e);else for(;n<e.length;)t.push(...e.slice(n,n+1e4)),n+=1e4}function No(t){let e={},n=-1,r,i,o,s,a,l,c,u=new Ao(t);for(;++n<u.length;){for(;n in e;)n=e[n];if(r=u.get(n),n&&r[1].type==="chunkFlow"&&u.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,o=0,o<l.length&&l[o][1].type==="lineEndingBlank"&&(o+=2),o<l.length&&l[o][1].type==="content"))for(;++o<l.length&&l[o][1].type!=="content";)l[o][1].type==="chunkText"&&(l[o][1]._isInFirstContentOfListItem=!0,o++);if(r[0]==="enter")r[1].contentType&&(Object.assign(e,Jx(u,n)),n=e[n],c=!0);else if(r[1]._container){for(o=n,i=void 0;o--;)if(s=u.get(o),s[1].type==="lineEnding"||s[1].type==="lineEndingBlank")s[0]==="enter"&&(i&&(u.get(i)[1].type="lineEndingBlank"),s[1].type="lineEnding",i=o);else if(!(s[1].type==="linePrefix"||s[1].type==="listItemIndent"))break;i&&(r[1].end={...u.get(i)[1].start},a=u.slice(i,n),a.unshift(r),u.splice(i,n-i+1,a))}}return ue(t,0,Number.POSITIVE_INFINITY,u.slice(0)),!c}function Jx(t,e){let n=t.get(e)[1],r=t.get(e)[2],i=e-1,o=[],s=n._tokenizer;s||(s=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(s._contentTypeTextTrailing=!0));let a=s.events,l=[],c={},u,f,d=-1,p=n,h=0,m=0,g=[m];for(;p;){for(;t.get(++i)[1]!==p;);o.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),f&&s.defineSkip(p.start),p._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=!0),s.write(u),p._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=void 0)),f=p,p=p.next}for(p=n;++d<a.length;)a[d][0]==="exit"&&a[d-1][0]==="enter"&&a[d][1].type===a[d-1][1].type&&a[d][1].start.line!==a[d][1].end.line&&(m=d+1,g.push(m),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(s.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),d=g.length;d--;){let y=a.slice(g[d],g[d+1]),x=o.pop();l.push([x,x+y.length-1]),t.splice(x,2,y)}for(l.reverse(),d=-1;++d<l.length;)c[h+l[d][0]]=h+l[d][1],h+=l[d][1]-l[d][0]-1;return c}var Ta={resolve:Qx,tokenize:Yx},Gx={partial:!0,tokenize:Xx};function Qx(t){return No(t),t}function Yx(t,e){let n;return r;function r(a){return t.enter("content"),n=t.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?o(a):R(a)?t.check(Gx,s,o)(a):(t.consume(a),i)}function o(a){return t.exit("chunkContent"),t.exit("content"),e(a)}function s(a){return t.consume(a),t.exit("chunkContent"),n.next=t.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function Xx(t,e,n){let r=this;return i;function i(s){return t.exit("chunkContent"),t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),F(t,o,"linePrefix")}function o(s){if(s===null||R(s))return n(s);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(s):t.interrupt(r.parser.constructs.flow,n,e)(s)}}function Ro(t,e,n,r,i,o,s,a,l){let c=l||Number.POSITIVE_INFINITY,u=0;return f;function f(y){return y===60?(t.enter(r),t.enter(i),t.enter(o),t.consume(y),t.exit(o),d):y===null||y===32||y===41||Tn(y)?n(y):(t.enter(r),t.enter(s),t.enter(a),t.enter("chunkString",{contentType:"string"}),m(y))}function d(y){return y===62?(t.enter(o),t.consume(y),t.exit(o),t.exit(i),t.exit(r),e):(t.enter(a),t.enter("chunkString",{contentType:"string"}),p(y))}function p(y){return y===62?(t.exit("chunkString"),t.exit(a),d(y)):y===null||y===60||R(y)?n(y):(t.consume(y),y===92?h:p)}function h(y){return y===60||y===62||y===92?(t.consume(y),p):p(y)}function m(y){return!u&&(y===null||y===41||U(y))?(t.exit("chunkString"),t.exit(a),t.exit(s),t.exit(r),e(y)):u<c&&y===40?(t.consume(y),u++,m):y===41?(t.consume(y),u--,m):y===null||y===32||y===40||Tn(y)?n(y):(t.consume(y),y===92?g:m)}function g(y){return y===40||y===41||y===92?(t.consume(y),m):m(y)}}function Oo(t,e,n,r,i,o){let s=this,a=0,l;return c;function c(p){return t.enter(r),t.enter(i),t.consume(p),t.exit(i),t.enter(o),u}function u(p){return a>999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in s.parser.constructs?n(p):p===93?(t.exit(o),t.enter(i),t.consume(p),t.exit(i),t.exit(r),e):R(p)?(t.enter("lineEnding"),t.consume(p),t.exit("lineEnding"),u):(t.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||R(p)||a++>999?(t.exit("chunkString"),u(p)):(t.consume(p),l||(l=!_(p)),p===92?d:f)}function d(p){return p===91||p===92||p===93?(t.consume(p),a++,f):f(p)}}function Do(t,e,n,r,i,o){let s;return a;function a(d){return d===34||d===39||d===40?(t.enter(r),t.enter(i),t.consume(d),t.exit(i),s=d===40?41:d,l):n(d)}function l(d){return d===s?(t.enter(i),t.consume(d),t.exit(i),t.exit(r),e):(t.enter(o),c(d))}function c(d){return d===s?(t.exit(o),l(s)):d===null?n(d):R(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),F(t,c,"linePrefix")):(t.enter("chunkString",{contentType:"string"}),u(d))}function u(d){return d===s||d===null||R(d)?(t.exit("chunkString"),c(d)):(t.consume(d),d===92?f:u)}function f(d){return d===s||d===92?(t.consume(d),u):u(d)}}function In(t,e){let n;return r;function r(i){return R(i)?(t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),n=!0,r):_(i)?F(t,r,n?"linePrefix":"lineSuffix")(i):e(i)}}var va={name:"definition",tokenize:ew},Zx={partial:!0,tokenize:tw};function ew(t,e,n){let r=this,i;return o;function o(p){return t.enter("definition"),s(p)}function s(p){return Oo.call(r,t,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Ae(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(t.enter("definitionMarker"),t.consume(p),t.exit("definitionMarker"),l):n(p)}function l(p){return U(p)?In(t,c)(p):c(p)}function c(p){return Ro(t,u,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function u(p){return t.attempt(Zx,f,f)(p)}function f(p){return _(p)?F(t,d,"whitespace")(p):d(p)}function d(p){return p===null||R(p)?(t.exit("definition"),r.parser.defined.push(i),e(p)):n(p)}}function tw(t,e,n){return r;function r(a){return U(a)?In(t,i)(a):n(a)}function i(a){return Do(t,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function o(a){return _(a)?F(t,s,"whitespace")(a):s(a)}function s(a){return a===null||R(a)?e(a):n(a)}}var Ia={name:"hardBreakEscape",tokenize:nw};function nw(t,e,n){return r;function r(o){return t.enter("hardBreakEscape"),t.consume(o),i}function i(o){return R(o)?(t.exit("hardBreakEscape"),e(o)):n(o)}}var Aa={name:"headingAtx",resolve:rw,tokenize:iw};function rw(t,e){let n=t.length-2,r=3,i,o;return t[r][1].type==="whitespace"&&(r+=2),n-2>r&&t[n][1].type==="whitespace"&&(n-=2),t[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&t[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:t[r][1].start,end:t[n][1].end},o={type:"chunkText",start:t[r][1].start,end:t[n][1].end,contentType:"text"},ue(t,r,n-r+1,[["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e]])),t}function iw(t,e,n){let r=0;return i;function i(u){return t.enter("atxHeading"),o(u)}function o(u){return t.enter("atxHeadingSequence"),s(u)}function s(u){return u===35&&r++<6?(t.consume(u),s):u===null||U(u)?(t.exit("atxHeadingSequence"),a(u)):n(u)}function a(u){return u===35?(t.enter("atxHeadingSequence"),l(u)):u===null||R(u)?(t.exit("atxHeading"),e(u)):_(u)?F(t,a,"whitespace")(u):(t.enter("atxHeadingText"),c(u))}function l(u){return u===35?(t.consume(u),l):(t.exit("atxHeadingSequence"),a(u))}function c(u){return u===null||u===35||U(u)?(t.exit("atxHeadingText"),a(u)):(t.consume(u),c)}}var Md=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Na=["pre","script","style","textarea"];var Ra={concrete:!0,name:"htmlFlow",resolveTo:aw,tokenize:lw},ow={partial:!0,tokenize:uw},sw={partial:!0,tokenize:cw};function aw(t){let e=t.length;for(;e--&&!(t[e][0]==="enter"&&t[e][1].type==="htmlFlow"););return e>1&&t[e-2][1].type==="linePrefix"&&(t[e][1].start=t[e-2][1].start,t[e+1][1].start=t[e-2][1].start,t.splice(e-2,2)),t}function lw(t,e,n){let r=this,i,o,s,a,l;return c;function c(b){return u(b)}function u(b){return t.enter("htmlFlow"),t.enter("htmlFlowData"),t.consume(b),f}function f(b){return b===33?(t.consume(b),d):b===47?(t.consume(b),o=!0,m):b===63?(t.consume(b),i=3,r.interrupt?e:k):ge(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function d(b){return b===45?(t.consume(b),i=2,p):b===91?(t.consume(b),i=5,a=0,h):ge(b)?(t.consume(b),i=4,r.interrupt?e:k):n(b)}function p(b){return b===45?(t.consume(b),r.interrupt?e:k):n(b)}function h(b){let We="CDATA[";return b===We.charCodeAt(a++)?(t.consume(b),a===We.length?r.interrupt?e:Y:h):n(b)}function m(b){return ge(b)?(t.consume(b),s=String.fromCharCode(b),g):n(b)}function g(b){if(b===null||b===47||b===62||U(b)){let We=b===47,Sn=s.toLowerCase();return!We&&!o&&Na.includes(Sn)?(i=1,r.interrupt?e(b):Y(b)):Md.includes(s.toLowerCase())?(i=6,We?(t.consume(b),y):r.interrupt?e(b):Y(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):o?x(b):C(b))}return b===45||ye(b)?(t.consume(b),s+=String.fromCharCode(b),g):n(b)}function y(b){return b===62?(t.consume(b),r.interrupt?e:Y):n(b)}function x(b){return _(b)?(t.consume(b),x):S(b)}function C(b){return b===47?(t.consume(b),S):b===58||b===95||ge(b)?(t.consume(b),v):_(b)?(t.consume(b),C):S(b)}function v(b){return b===45||b===46||b===58||b===95||ye(b)?(t.consume(b),v):I(b)}function I(b){return b===61?(t.consume(b),w):_(b)?(t.consume(b),I):C(b)}function w(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(t.consume(b),l=b,N):_(b)?(t.consume(b),w):D(b)}function N(b){return b===l?(t.consume(b),l=null,B):b===null||R(b)?n(b):(t.consume(b),N)}function D(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||U(b)?I(b):(t.consume(b),D)}function B(b){return b===47||b===62||_(b)?C(b):n(b)}function S(b){return b===62?(t.consume(b),ce):n(b)}function ce(b){return b===null||R(b)?Y(b):_(b)?(t.consume(b),ce):n(b)}function Y(b){return b===45&&i===2?(t.consume(b),le):b===60&&i===1?(t.consume(b),me):b===62&&i===4?(t.consume(b),Xe):b===63&&i===3?(t.consume(b),k):b===93&&i===5?(t.consume(b),Mt):R(b)&&(i===6||i===7)?(t.exit("htmlFlowData"),t.check(ow,Bt,L)(b)):b===null||R(b)?(t.exit("htmlFlowData"),L(b)):(t.consume(b),Y)}function L(b){return t.check(sw,W,Bt)(b)}function W(b){return t.enter("lineEnding"),t.consume(b),t.exit("lineEnding"),j}function j(b){return b===null||R(b)?L(b):(t.enter("htmlFlowData"),Y(b))}function le(b){return b===45?(t.consume(b),k):Y(b)}function me(b){return b===47?(t.consume(b),s="",ut):Y(b)}function ut(b){if(b===62){let We=s.toLowerCase();return Na.includes(We)?(t.consume(b),Xe):Y(b)}return ge(b)&&s.length<8?(t.consume(b),s+=String.fromCharCode(b),ut):Y(b)}function Mt(b){return b===93?(t.consume(b),k):Y(b)}function k(b){return b===62?(t.consume(b),Xe):b===45&&i===2?(t.consume(b),k):Y(b)}function Xe(b){return b===null||R(b)?(t.exit("htmlFlowData"),Bt(b)):(t.consume(b),Xe)}function Bt(b){return t.exit("htmlFlow"),e(b)}}function cw(t,e,n){let r=this;return i;function i(s){return R(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o):n(s)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function uw(t,e,n){return r;function r(i){return t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),t.attempt(Tt,e,n)}}var Oa={name:"htmlText",tokenize:fw};function fw(t,e,n){let r=this,i,o,s;return a;function a(k){return t.enter("htmlText"),t.enter("htmlTextData"),t.consume(k),l}function l(k){return k===33?(t.consume(k),c):k===47?(t.consume(k),I):k===63?(t.consume(k),C):ge(k)?(t.consume(k),D):n(k)}function c(k){return k===45?(t.consume(k),u):k===91?(t.consume(k),o=0,h):ge(k)?(t.consume(k),x):n(k)}function u(k){return k===45?(t.consume(k),p):n(k)}function f(k){return k===null?n(k):k===45?(t.consume(k),d):R(k)?(s=f,me(k)):(t.consume(k),f)}function d(k){return k===45?(t.consume(k),p):f(k)}function p(k){return k===62?le(k):k===45?d(k):f(k)}function h(k){let Xe="CDATA[";return k===Xe.charCodeAt(o++)?(t.consume(k),o===Xe.length?m:h):n(k)}function m(k){return k===null?n(k):k===93?(t.consume(k),g):R(k)?(s=m,me(k)):(t.consume(k),m)}function g(k){return k===93?(t.consume(k),y):m(k)}function y(k){return k===62?le(k):k===93?(t.consume(k),y):m(k)}function x(k){return k===null||k===62?le(k):R(k)?(s=x,me(k)):(t.consume(k),x)}function C(k){return k===null?n(k):k===63?(t.consume(k),v):R(k)?(s=C,me(k)):(t.consume(k),C)}function v(k){return k===62?le(k):C(k)}function I(k){return ge(k)?(t.consume(k),w):n(k)}function w(k){return k===45||ye(k)?(t.consume(k),w):N(k)}function N(k){return R(k)?(s=N,me(k)):_(k)?(t.consume(k),N):le(k)}function D(k){return k===45||ye(k)?(t.consume(k),D):k===47||k===62||U(k)?B(k):n(k)}function B(k){return k===47?(t.consume(k),le):k===58||k===95||ge(k)?(t.consume(k),S):R(k)?(s=B,me(k)):_(k)?(t.consume(k),B):le(k)}function S(k){return k===45||k===46||k===58||k===95||ye(k)?(t.consume(k),S):ce(k)}function ce(k){return k===61?(t.consume(k),Y):R(k)?(s=ce,me(k)):_(k)?(t.consume(k),ce):B(k)}function Y(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(t.consume(k),i=k,L):R(k)?(s=Y,me(k)):_(k)?(t.consume(k),Y):(t.consume(k),W)}function L(k){return k===i?(t.consume(k),i=void 0,j):k===null?n(k):R(k)?(s=L,me(k)):(t.consume(k),L)}function W(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||U(k)?B(k):(t.consume(k),W)}function j(k){return k===47||k===62||U(k)?B(k):n(k)}function le(k){return k===62?(t.consume(k),t.exit("htmlTextData"),t.exit("htmlText"),e):n(k)}function me(k){return t.exit("htmlTextData"),t.enter("lineEnding"),t.consume(k),t.exit("lineEnding"),ut}function ut(k){return _(k)?F(t,Mt,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):Mt(k)}function Mt(k){return t.enter("htmlTextData"),s(k)}}var An={name:"labelEnd",resolveAll:mw,resolveTo:gw,tokenize:yw},dw={tokenize:kw},pw={tokenize:bw},hw={tokenize:xw};function mw(t){let e=-1,n=[];for(;++e<t.length;){let r=t[e][1];if(n.push(t[e]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){let i=r.type==="labelImage"?4:2;r.type="data",e+=i}}return t.length!==n.length&&ue(t,0,t.length,n),t}function gw(t,e){let n=t.length,r=0,i,o,s,a;for(;n--;)if(i=t[n][1],o){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;t[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(s){if(t[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(o=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(s=n);let l={type:t[o][1].type==="labelLink"?"link":"image",start:{...t[o][1].start},end:{...t[t.length-1][1].end}},c={type:"label",start:{...t[o][1].start},end:{...t[s][1].end}},u={type:"labelText",start:{...t[o+r+2][1].end},end:{...t[s-2][1].start}};return a=[["enter",l,e],["enter",c,e]],a=Be(a,t.slice(o+1,o+r+3)),a=Be(a,[["enter",u,e]]),a=Be(a,nn(e.parser.constructs.insideSpan.null,t.slice(o+r+4,s-3),e)),a=Be(a,[["exit",u,e],t[s-2],t[s-1],["exit",c,e]]),a=Be(a,t.slice(s+1)),a=Be(a,[["exit",l,e]]),ue(t,o,t.length,a),t}function yw(t,e,n){let r=this,i=r.events.length,o,s;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){o=r.events[i][1];break}return a;function a(d){return o?o._inactive?f(d):(s=r.parser.defined.includes(Ae(r.sliceSerialize({start:o.end,end:r.now()}))),t.enter("labelEnd"),t.enter("labelMarker"),t.consume(d),t.exit("labelMarker"),t.exit("labelEnd"),l):n(d)}function l(d){return d===40?t.attempt(dw,u,s?u:f)(d):d===91?t.attempt(pw,u,s?c:f)(d):s?u(d):f(d)}function c(d){return t.attempt(hw,u,f)(d)}function u(d){return e(d)}function f(d){return o._balanced=!0,n(d)}}function kw(t,e,n){return r;function r(f){return t.enter("resource"),t.enter("resourceMarker"),t.consume(f),t.exit("resourceMarker"),i}function i(f){return U(f)?In(t,o)(f):o(f)}function o(f){return f===41?u(f):Ro(t,s,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function s(f){return U(f)?In(t,l)(f):u(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?Do(t,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):u(f)}function c(f){return U(f)?In(t,u)(f):u(f)}function u(f){return f===41?(t.enter("resourceMarker"),t.consume(f),t.exit("resourceMarker"),t.exit("resource"),e):n(f)}}function bw(t,e,n){let r=this;return i;function i(a){return Oo.call(r,t,o,s,"reference","referenceMarker","referenceString")(a)}function o(a){return r.parser.defined.includes(Ae(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?e(a):n(a)}function s(a){return n(a)}}function xw(t,e,n){return r;function r(o){return t.enter("reference"),t.enter("referenceMarker"),t.consume(o),t.exit("referenceMarker"),i}function i(o){return o===93?(t.enter("referenceMarker"),t.consume(o),t.exit("referenceMarker"),t.exit("reference"),e):n(o)}}var Da={name:"labelStartImage",resolveAll:An.resolveAll,tokenize:ww};function ww(t,e,n){let r=this;return i;function i(a){return t.enter("labelImage"),t.enter("labelImageMarker"),t.consume(a),t.exit("labelImageMarker"),o}function o(a){return a===91?(t.enter("labelMarker"),t.consume(a),t.exit("labelMarker"),t.exit("labelImage"),s):n(a)}function s(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):e(a)}}var Ba={name:"labelStartLink",resolveAll:An.resolveAll,tokenize:Sw};function Sw(t,e,n){let r=this;return i;function i(s){return t.enter("labelLink"),t.enter("labelMarker"),t.consume(s),t.exit("labelMarker"),t.exit("labelLink"),o}function o(s){return s===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(s):e(s)}}var yi={name:"lineEnding",tokenize:Cw};function Cw(t,e){return n;function n(r){return t.enter("lineEnding"),t.consume(r),t.exit("lineEnding"),F(t,e,"linePrefix")}}var Nn={name:"thematicBreak",tokenize:Mw};function Mw(t,e,n){let r=0,i;return o;function o(c){return t.enter("thematicBreak"),s(c)}function s(c){return i=c,a(c)}function a(c){return c===i?(t.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||R(c))?(t.exit("thematicBreak"),e(c)):n(c)}function l(c){return c===i?(t.consume(c),r++,l):(t.exit("thematicBreakSequence"),_(c)?F(t,a,"whitespace")(c):a(c))}}var Ne={continuation:{tokenize:Iw},exit:Nw,name:"list",tokenize:vw},Ew={partial:!0,tokenize:Rw},Tw={partial:!0,tokenize:Aw};function vw(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(p){let h=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(h==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:pi(p)){if(r.containerState.type||(r.containerState.type=h,t.enter(h,{_container:!0})),h==="listUnordered")return t.enter("listItemPrefix"),p===42||p===45?t.check(Nn,n,c)(p):c(p);if(!r.interrupt||p===49)return t.enter("listItemPrefix"),t.enter("listItemValue"),l(p)}return n(p)}function l(p){return pi(p)&&++s<10?(t.consume(p),l):(!r.interrupt||s<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(t.exit("listItemValue"),c(p)):n(p)}function c(p){return t.enter("listItemMarker"),t.consume(p),t.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,t.check(Tt,r.interrupt?n:u,t.attempt(Ew,d,f))}function u(p){return r.containerState.initialBlankLine=!0,o++,d(p)}function f(p){return _(p)?(t.enter("listItemPrefixWhitespace"),t.consume(p),t.exit("listItemPrefixWhitespace"),d):n(p)}function d(p){return r.containerState.size=o+r.sliceSerialize(t.exit("listItemPrefix"),!0).length,e(p)}}function Iw(t,e,n){let r=this;return r.containerState._closeFlow=void 0,t.check(Tt,i,o);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,F(t,e,"listItemIndent",r.containerState.size+1)(a)}function o(a){return r.containerState.furtherBlankLines||!_(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,t.attempt(Tw,e,s)(a))}function s(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,F(t,t.attempt(Ne,e,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Aw(t,e,n){let r=this;return F(t,i,"listItemIndent",r.containerState.size+1);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===r.containerState.size?e(o):n(o)}}function Nw(t){t.exit(this.containerState.type)}function Rw(t,e,n){let r=this;return F(t,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(o){let s=r.events[r.events.length-1];return!_(o)&&s&&s[1].type==="listItemPrefixWhitespace"?e(o):n(o)}}var Bo={name:"setextUnderline",resolveTo:Ow,tokenize:Dw};function Ow(t,e){let n=t.length,r,i,o;for(;n--;)if(t[n][0]==="enter"){if(t[n][1].type==="content"){r=n;break}t[n][1].type==="paragraph"&&(i=n)}else t[n][1].type==="content"&&t.splice(n,1),!o&&t[n][1].type==="definition"&&(o=n);let s={type:"setextHeading",start:{...t[r][1].start},end:{...t[t.length-1][1].end}};return t[i][1].type="setextHeadingText",o?(t.splice(i,0,["enter",s,e]),t.splice(o+1,0,["exit",t[r][1],e]),t[r][1].end={...t[o][1].end}):t[r][1]=s,t.push(["exit",s,e]),t}function Dw(t,e,n){let r=this,i;return o;function o(c){let u=r.events.length,f;for(;u--;)if(r.events[u][1].type!=="lineEnding"&&r.events[u][1].type!=="linePrefix"&&r.events[u][1].type!=="content"){f=r.events[u][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(t.enter("setextHeadingLine"),i=c,s(c)):n(c)}function s(c){return t.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===i?(t.consume(c),a):(t.exit("setextHeadingLineSequence"),_(c)?F(t,l,"lineSuffix")(c):l(c))}function l(c){return c===null||R(c)?(t.exit("setextHeadingLine"),e(c)):n(c)}}var Ed={tokenize:Bw};function Bw(t){let e=this,n=t.attempt(Tt,r,t.attempt(this.parser.constructs.flowInitial,i,F(t,t.attempt(this.parser.constructs.flow,i,t.attempt(Ta,i)),"linePrefix")));return n;function r(o){if(o===null){t.consume(o);return}return t.enter("lineEndingBlank"),t.consume(o),t.exit("lineEndingBlank"),e.currentConstruct=void 0,n}function i(o){if(o===null){t.consume(o);return}return t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),e.currentConstruct=void 0,n}}var Td={resolveAll:Nd()},vd=Ad("string"),Id=Ad("text");function Ad(t){return{resolveAll:Nd(t==="text"?Lw:void 0),tokenize:e};function e(n){let r=this,i=this.parser.constructs[t],o=n.attempt(i,s,a);return s;function s(u){return c(u)?o(u):a(u)}function a(u){if(u===null){n.consume(u);return}return n.enter("data"),n.consume(u),l}function l(u){return c(u)?(n.exit("data"),o(u)):(n.consume(u),l)}function c(u){if(u===null)return!0;let f=i[u],d=-1;if(f)for(;++d<f.length;){let p=f[d];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function Nd(t){return e;function e(n,r){let i=-1,o;for(;++i<=n.length;)o===void 0?n[i]&&n[i][1].type==="data"&&(o=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==o+2&&(n[o][1].end=n[i-1][1].end,n.splice(o+2,i-o-2),i=o+2),o=void 0);return t?t(n,r):n}}function Lw(t,e){let n=0;for(;++n<=t.length;)if((n===t.length||t[n][1].type==="lineEnding")&&t[n-1][1].type==="data"){let r=t[n-1][1],i=e.sliceStream(r),o=i.length,s=-1,a=0,l;for(;o--;){let c=i[o];if(typeof c=="string"){for(s=c.length;c.charCodeAt(s-1)===32;)a++,s--;if(s)break;s=-1}else if(c===-2)l=!0,a++;else if(c!==-1){o++;break}}if(e._contentTypeTextTrailing&&n===t.length&&(a=0),a){let c={type:n===t.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?s:r.start._bufferIndex+s,_index:r.start._index+o,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...c.start},r.start.offset===r.end.offset?Object.assign(r,c):(t.splice(n,0,["enter",c,e],["exit",c,e]),n+=2)}n++}return t}var La={};mx(La,{attentionMarkers:()=>Ww,contentInitial:()=>Fw,disable:()=>jw,document:()=>Pw,flow:()=>$w,flowInitial:()=>zw,insideSpan:()=>Vw,string:()=>_w,text:()=>Hw});var Pw={42:Ne,43:Ne,45:Ne,48:Ne,49:Ne,50:Ne,51:Ne,52:Ne,53:Ne,54:Ne,55:Ne,56:Ne,57:Ne,62:Eo},Fw={91:va},zw={[-2]:mi,[-1]:mi,32:mi},$w={35:Aa,42:Nn,45:[Bo,Nn],60:Ra,61:Bo,95:Nn,96:Io,126:Io},_w={38:vo,92:To},Hw={[-5]:yi,[-4]:yi,[-3]:yi,33:Da,38:vo,42:hi,60:[Ma,Oa],91:Ba,92:[Ia,To],93:An,95:hi,96:Ea},Vw={null:[hi,Td]},Ww={null:[42,95]},jw={null:[]};function Rd(t,e,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},o=[],s=[],a=[],l=!0,c={attempt:B(N),check:B(D),consume:v,enter:I,exit:w,interrupt:B(D,{interrupt:!0})},u={code:null,containerState:{},defineSkip:y,events:[],now:g,parser:t,previous:null,sliceSerialize:h,sliceStream:m,write:p},f=e.tokenize.call(u,c),d;return e.resolveAll&&o.push(e),u;function p(L){return s=Be(s,L),x(),s[s.length-1]!==null?[]:(S(e,0),u.events=nn(o,u.events,u),u.events)}function h(L,W){return Kw(m(L),W)}function m(L){return qw(s,L)}function g(){let{_bufferIndex:L,_index:W,line:j,column:le,offset:me}=r;return{_bufferIndex:L,_index:W,line:j,column:le,offset:me}}function y(L){i[L.line]=L.column,Y()}function x(){let L;for(;r._index<s.length;){let W=s[r._index];if(typeof W=="string")for(L=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===L&&r._bufferIndex<W.length;)C(W.charCodeAt(r._bufferIndex));else C(W)}}function C(L){l=void 0,d=L,f=f(L)}function v(L){R(L)?(r.line++,r.column=1,r.offset+=L===-3?2:1,Y()):L!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===s[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=L,l=!0}function I(L,W){let j=W||{};return j.type=L,j.start=g(),u.events.push(["enter",j,u]),a.push(j),j}function w(L){let W=a.pop();return W.end=g(),u.events.push(["exit",W,u]),W}function N(L,W){S(L,W.from)}function D(L,W){W.restore()}function B(L,W){return j;function j(le,me,ut){let Mt,k,Xe,Bt;return Array.isArray(le)?We(le):"tokenize"in le?We([le]):b(le);function b(Me){return ui;function ui(Lt){let Cn=Lt!==null&&Me[Lt],ur=Lt!==null&&Me.null,xa=[...Array.isArray(Cn)?Cn:Cn?[Cn]:[],...Array.isArray(ur)?ur:ur?[ur]:[]];return We(xa)(Lt)}}function We(Me){return Mt=Me,k=0,Me.length===0?ut:Sn(Me[k])}function Sn(Me){return ui;function ui(Lt){return Bt=ce(),Xe=Me,Me.partial||(u.currentConstruct=Me),Me.name&&u.parser.constructs.disable.null.includes(Me.name)?xo(Lt):Me.tokenize.call(W?Object.assign(Object.create(u),W):u,c,ba,xo)(Lt)}}function ba(Me){return l=!0,L(Xe,Bt),me}function xo(Me){return l=!0,Bt.restore(),++k<Mt.length?Sn(Mt[k]):ut}}}function S(L,W){L.resolveAll&&!o.includes(L)&&o.push(L),L.resolve&&ue(u.events,W,u.events.length-W,L.resolve(u.events.slice(W),u)),L.resolveTo&&(u.events=L.resolveTo(u.events,u))}function ce(){let L=g(),W=u.previous,j=u.currentConstruct,le=u.events.length,me=Array.from(a);return{from:le,restore:ut};function ut(){r=L,u.previous=W,u.currentConstruct=j,u.events.length=le,a=me,Y()}}function Y(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function qw(t,e){let n=e.start._index,r=e.start._bufferIndex,i=e.end._index,o=e.end._bufferIndex,s;if(n===i)s=[t[n].slice(r,o)];else{if(s=t.slice(n,i),r>-1){let a=s[0];typeof a=="string"?s[0]=a.slice(r):s.shift()}o>0&&s.push(t[i].slice(0,o))}return s}function Kw(t,e){let n=-1,r=[],i;for(;++n<t.length;){let o=t[n],s;if(typeof o=="string")s=o;else switch(o){case-5:{s="\r";break}case-4:{s=` `;break}case-3:{s=`\r -`;break}case-2:{s=e?" ":" ";break}case-1:{if(!e&&i)continue;s=" ";break}default:s=String.fromCharCode(o)}i=o===-2,r.push(s)}return r.join("")}function Pa(t){let r={constructs:Co([La,...(t||{}).extensions||[]]),content:i(kd),defined:[],document:i(xd),flow:i(Md),lazy:{},string:i(Td),text:i(vd)};return r;function i(o){return s;function s(a){return Nd(r,o,a)}}}function Fa(t){for(;!No(t););return t}var Rd=/[\0\t\n\r]/g;function za(){let t=1,e="",n=!0,r;return i;function i(o,s,a){let l=[],c,u,f,d,p;for(o=e+(typeof o=="string"?o.toString():new TextDecoder(s||void 0).decode(o)),f=0,e="",n&&(o.charCodeAt(0)===65279&&f++,n=void 0);f<o.length;){if(Rd.lastIndex=f,c=Rd.exec(o),d=c&&c.index!==void 0?c.index:o.length,p=o.charCodeAt(d),!c){e=o.slice(f);break}if(p===10&&f===d&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<d&&(l.push(o.slice(f,d)),t+=d-f),p){case 0:{l.push(65533),t++;break}case 9:{for(u=Math.ceil(t/4)*4,l.push(-2);t++<u;)l.push(-1);break}case 10:{l.push(-4),t=1;break}default:r=!0,t=1}f=d+1}return a&&(r&&l.push(-5),e&&l.push(e),l.push(null)),l}}var Kw=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function Lo(t){return t.replace(Kw,Uw)}function Uw(t,e,n){if(e)return e;if(n.charCodeAt(0)===35){let i=n.charCodeAt(1),o=i===120||i===88;return Mo(n.slice(o?2:1),o?16:10)}return pr(n)||t}function rn(t){return!t||typeof t!="object"?"":"position"in t||"type"in t?Od(t.position):"start"in t||"end"in t?Od(t):"line"in t||"column"in t?$a(t):""}function $a(t){return Dd(t&&t.line)+":"+Dd(t&&t.column)}function Od(t){return $a(t&&t.start)+"-"+$a(t&&t.end)}function Dd(t){return t&&typeof t=="number"?t:1}var Ld={}.hasOwnProperty;function _a(t,e,n){return e&&typeof e=="object"&&(n=e,e=void 0),Jw(n)(Fa(Pa(n).document().write(za()(t,e,!0))))}function Jw(t){let e={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:o(Xf),autolinkProtocol:B,autolinkEmail:B,atxHeading:o(Gf),blockQuote:o(Lt),characterEscape:B,characterReference:B,codeFenced:o(Cn),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:o(Cn,s),codeText:o(ur,s),codeTextData:B,data:B,codeFlowValue:B,definition:o(xa),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:o(tx),hardBreakEscape:o(Qf),hardBreakTrailing:o(Qf),htmlFlow:o(Yf,s),htmlFlowData:B,htmlText:o(Yf,s),htmlTextData:B,image:o(nx),label:s,link:o(Xf),listItem:o(rx),listItemValue:d,listOrdered:o(Zf,f),listUnordered:o(Zf),paragraph:o(ix),reference:b,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:o(Gf),strong:o(ox),thematicBreak:o(ax)},exit:{atxHeading:l(),atxHeadingSequence:I,autolink:l(),autolinkEmail:ui,autolinkProtocol:Me,blockQuote:l(),characterEscapeValue:S,characterReferenceMarkerHexadecimal:Sn,characterReferenceMarkerNumeric:Sn,characterReferenceValue:ba,characterReference:xo,codeFenced:l(g),codeFencedFence:m,codeFencedFenceInfo:p,codeFencedFenceMeta:h,codeFlowValue:S,codeIndented:l(y),codeText:l(j),codeTextData:S,data:S,definition:l(),definitionDestinationString:v,definitionLabelString:x,definitionTitleString:C,emphasis:l(),hardBreakEscape:l(Y),hardBreakTrailing:l(Y),htmlFlow:l(L),htmlFlowData:S,htmlText:l(W),htmlTextData:S,image:l(me),label:Mt,labelText:ut,lineEnding:ce,link:l(le),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:We,resourceDestinationString:k,resourceTitleString:Xe,resource:Bt,setextHeading:l(D),setextHeadingLineSequence:N,setextHeadingText:w,strong:l(),thematicBreak:l()}};Pd(e,(t||{}).mdastExtensions||[]);let n={};return r;function r(T){let O={type:"root",children:[]},q={stack:[O],tokenStack:[],config:e,enter:a,exit:c,buffer:s,resume:u,data:n},Q=[],ie=-1;for(;++ie<T.length;)if(T[ie][1].type==="listOrdered"||T[ie][1].type==="listUnordered")if(T[ie][0]==="enter")Q.push(ie);else{let ft=Q.pop();ie=i(T,ft,ie)}for(ie=-1;++ie<T.length;){let ft=e[T[ie][0]];Ld.call(ft,T[ie][1].type)&&ft[T[ie][1].type].call(Object.assign({sliceSerialize:T[ie][2].sliceSerialize},q),T[ie][1])}if(q.tokenStack.length>0){let ft=q.tokenStack[q.tokenStack.length-1];(ft[1]||Bd).call(q,void 0,ft[0])}for(O.position={start:on(T.length>0?T[0][1].start:{line:1,column:1,offset:0}),end:on(T.length>0?T[T.length-2][1].end:{line:1,column:1,offset:0})},ie=-1;++ie<e.transforms.length;)O=e.transforms[ie](O)||O;return O}function i(T,O,q){let Q=O-1,ie=-1,ft=!1,Mn,Pt,fi,di;for(;++Q<=q;){let je=T[Q];switch(je[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{je[0]==="enter"?ie++:ie--,di=void 0;break}case"lineEndingBlank":{je[0]==="enter"&&(Mn&&!di&&!ie&&!fi&&(fi=Q),di=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:di=void 0}if(!ie&&je[0]==="enter"&&je[1].type==="listItemPrefix"||ie===-1&&je[0]==="exit"&&(je[1].type==="listUnordered"||je[1].type==="listOrdered")){if(Mn){let fr=Q;for(Pt=void 0;fr--;){let Ft=T[fr];if(Ft[1].type==="lineEnding"||Ft[1].type==="lineEndingBlank"){if(Ft[0]==="exit")continue;Pt&&(T[Pt][1].type="lineEndingBlank",ft=!0),Ft[1].type="lineEnding",Pt=fr}else if(!(Ft[1].type==="linePrefix"||Ft[1].type==="blockQuotePrefix"||Ft[1].type==="blockQuotePrefixWhitespace"||Ft[1].type==="blockQuoteMarker"||Ft[1].type==="listItemIndent"))break}fi&&(!Pt||fi<Pt)&&(Mn._spread=!0),Mn.end=Object.assign({},Pt?T[Pt][1].start:je[1].end),T.splice(Pt||Q,0,["exit",Mn,je[2]]),Q++,q++}if(je[1].type==="listItemPrefix"){let fr={type:"listItem",_spread:!1,start:Object.assign({},je[1].start),end:void 0};Mn=fr,T.splice(Q,0,["enter",fr,je[2]]),Q++,q++,fi=void 0,di=!0}}}return T[O][1]._spread=ft,q}function o(T,O){return q;function q(Q){a.call(this,T(Q),Q),O&&O.call(this,Q)}}function s(){this.stack.push({type:"fragment",children:[]})}function a(T,O,q){this.stack[this.stack.length-1].children.push(T),this.stack.push(T),this.tokenStack.push([O,q||void 0]),T.position={start:on(O.start),end:void 0}}function l(T){return O;function O(q){T&&T.call(this,q),c.call(this,q)}}function c(T,O){let q=this.stack.pop(),Q=this.tokenStack.pop();if(Q)Q[0].type!==T.type&&(O?O.call(this,T,Q[0]):(Q[1]||Bd).call(this,T,Q[0]));else throw new Error("Cannot close `"+T.type+"` ("+rn({start:T.start,end:T.end})+"): it\u2019s not open");q.position.end=on(T.end)}function u(){return En(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function d(T){if(this.data.expectingFirstListItemValue){let O=this.stack[this.stack.length-2];O.start=Number.parseInt(this.sliceSerialize(T),10),this.data.expectingFirstListItemValue=void 0}}function p(){let T=this.resume(),O=this.stack[this.stack.length-1];O.lang=T}function h(){let T=this.resume(),O=this.stack[this.stack.length-1];O.meta=T}function m(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function g(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function y(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T.replace(/(\r?\n|\r)$/g,"")}function x(T){let O=this.resume(),q=this.stack[this.stack.length-1];q.label=O,q.identifier=Ae(this.sliceSerialize(T)).toLowerCase()}function C(){let T=this.resume(),O=this.stack[this.stack.length-1];O.title=T}function v(){let T=this.resume(),O=this.stack[this.stack.length-1];O.url=T}function I(T){let O=this.stack[this.stack.length-1];if(!O.depth){let q=this.sliceSerialize(T).length;O.depth=q}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function N(T){let O=this.stack[this.stack.length-1];O.depth=this.sliceSerialize(T).codePointAt(0)===61?1:2}function D(){this.data.setextHeadingSlurpLineEnding=void 0}function B(T){let q=this.stack[this.stack.length-1].children,Q=q[q.length-1];(!Q||Q.type!=="text")&&(Q=sx(),Q.position={start:on(T.start),end:void 0},q.push(Q)),this.stack.push(Q)}function S(T){let O=this.stack.pop();O.value+=this.sliceSerialize(T),O.position.end=on(T.end)}function ce(T){let O=this.stack[this.stack.length-1];if(this.data.atHardBreak){let q=O.children[O.children.length-1];q.position.end=on(T.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&e.canContainEols.includes(O.type)&&(B.call(this,T),S.call(this,T))}function Y(){this.data.atHardBreak=!0}function L(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T}function W(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T}function j(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T}function le(){let T=this.stack[this.stack.length-1];if(this.data.inReference){let O=this.data.referenceType||"shortcut";T.type+="Reference",T.referenceType=O,delete T.url,delete T.title}else delete T.identifier,delete T.label;this.data.referenceType=void 0}function me(){let T=this.stack[this.stack.length-1];if(this.data.inReference){let O=this.data.referenceType||"shortcut";T.type+="Reference",T.referenceType=O,delete T.url,delete T.title}else delete T.identifier,delete T.label;this.data.referenceType=void 0}function ut(T){let O=this.sliceSerialize(T),q=this.stack[this.stack.length-2];q.label=Lo(O),q.identifier=Ae(O).toLowerCase()}function Mt(){let T=this.stack[this.stack.length-1],O=this.resume(),q=this.stack[this.stack.length-1];if(this.data.inReference=!0,q.type==="link"){let Q=T.children;q.children=Q}else q.alt=O}function k(){let T=this.resume(),O=this.stack[this.stack.length-1];O.url=T}function Xe(){let T=this.resume(),O=this.stack[this.stack.length-1];O.title=T}function Bt(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function We(T){let O=this.resume(),q=this.stack[this.stack.length-1];q.label=O,q.identifier=Ae(this.sliceSerialize(T)).toLowerCase(),this.data.referenceType="full"}function Sn(T){this.data.characterReferenceType=T.type}function ba(T){let O=this.sliceSerialize(T),q=this.data.characterReferenceType,Q;q?(Q=Mo(O,q==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):Q=pr(O);let ie=this.stack[this.stack.length-1];ie.value+=Q}function xo(T){let O=this.stack.pop();O.position.end=on(T.end)}function Me(T){S.call(this,T);let O=this.stack[this.stack.length-1];O.url=this.sliceSerialize(T)}function ui(T){S.call(this,T);let O=this.stack[this.stack.length-1];O.url="mailto:"+this.sliceSerialize(T)}function Lt(){return{type:"blockquote",children:[]}}function Cn(){return{type:"code",lang:null,meta:null,value:""}}function ur(){return{type:"inlineCode",value:""}}function xa(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function tx(){return{type:"emphasis",children:[]}}function Gf(){return{type:"heading",depth:0,children:[]}}function Qf(){return{type:"break"}}function Yf(){return{type:"html",value:""}}function nx(){return{type:"image",title:null,url:"",alt:null}}function Xf(){return{type:"link",title:null,url:"",children:[]}}function Zf(T){return{type:"list",ordered:T.type==="listOrdered",start:null,spread:T._spread,children:[]}}function rx(T){return{type:"listItem",spread:T._spread,checked:null,children:[]}}function ix(){return{type:"paragraph",children:[]}}function ox(){return{type:"strong",children:[]}}function sx(){return{type:"text",value:""}}function ax(){return{type:"thematicBreak"}}}function on(t){return{line:t.line,column:t.column,offset:t.offset}}function Pd(t,e){let n=-1;for(;++n<e.length;){let r=e[n];Array.isArray(r)?Pd(t,r):Gw(t,r)}}function Gw(t,e){let n;for(n in e)if(Ld.call(e,n))switch(n){case"canContainEols":{let r=e[n];r&&t[n].push(...r);break}case"transforms":{let r=e[n];r&&t[n].push(...r);break}case"enter":case"exit":{let r=e[n];r&&Object.assign(t[n],r);break}}}function Bd(t,e){throw t?new Error("Cannot close `"+t.type+"` ("+rn({start:t.start,end:t.end})+"): a different token (`"+e.type+"`, "+rn({start:e.start,end:e.end})+") is open"):new Error("Cannot close document, a token (`"+e.type+"`, "+rn({start:e.start,end:e.end})+") is still open")}function hr(t){let e=this;e.parser=n;function n(r){return _a(r,{...e.data("settings"),...t,extensions:e.data("micromarkExtensions")||[],mdastExtensions:e.data("fromMarkdownExtensions")||[]})}}var Fd={}.hasOwnProperty;function zd(t,e){let n=e||{};function r(i,...o){let s=r.invalid,a=r.handlers;if(i&&Fd.call(i,t)){let l=String(i[t]);s=Fd.call(a,l)?a[l]:r.unknown}if(s)return s.call(this,i,...o)}return r.handlers=n.handlers||{},r.invalid=n.invalid,r.unknown=n.unknown,r}var Qw={}.hasOwnProperty;function Ha(t,e){let n=-1,r;if(e.extensions)for(;++n<e.extensions.length;)Ha(t,e.extensions[n]);for(r in e)if(Qw.call(e,r))switch(r){case"extensions":break;case"unsafe":{$d(t[r],e[r]);break}case"join":{$d(t[r],e[r]);break}case"handlers":{Yw(t[r],e[r]);break}default:t.options[r]=e[r]}return t}function $d(t,e){e&&t.push(...e)}function Yw(t,e){e&&Object.assign(t,e)}function _d(t,e,n,r){let i=n.enter("blockquote"),o=n.createTracker(r);o.move("> "),o.shift(2);let s=n.indentLines(n.containerFlow(t,o.current()),Xw);return i(),s}function Xw(t,e,n){return">"+(n?"":" ")+t}function Po(t,e){return Hd(t,e.inConstruct,!0)&&!Hd(t,e.notInConstruct,!1)}function Hd(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++r<e.length;)if(t.includes(e[r]))return!0;return!1}function Va(t,e,n,r){let i=-1;for(;++i<n.unsafe.length;)if(n.unsafe[i].character===` +`;break}case-2:{s=e?" ":" ";break}case-1:{if(!e&&i)continue;s=" ";break}default:s=String.fromCharCode(o)}i=o===-2,r.push(s)}return r.join("")}function Pa(t){let r={constructs:Co([La,...(t||{}).extensions||[]]),content:i(bd),defined:[],document:i(wd),flow:i(Ed),lazy:{},string:i(vd),text:i(Id)};return r;function i(o){return s;function s(a){return Rd(r,o,a)}}}function Fa(t){for(;!No(t););return t}var Od=/[\0\t\n\r]/g;function za(){let t=1,e="",n=!0,r;return i;function i(o,s,a){let l=[],c,u,f,d,p;for(o=e+(typeof o=="string"?o.toString():new TextDecoder(s||void 0).decode(o)),f=0,e="",n&&(o.charCodeAt(0)===65279&&f++,n=void 0);f<o.length;){if(Od.lastIndex=f,c=Od.exec(o),d=c&&c.index!==void 0?c.index:o.length,p=o.charCodeAt(d),!c){e=o.slice(f);break}if(p===10&&f===d&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<d&&(l.push(o.slice(f,d)),t+=d-f),p){case 0:{l.push(65533),t++;break}case 9:{for(u=Math.ceil(t/4)*4,l.push(-2);t++<u;)l.push(-1);break}case 10:{l.push(-4),t=1;break}default:r=!0,t=1}f=d+1}return a&&(r&&l.push(-5),e&&l.push(e),l.push(null)),l}}var Uw=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function Lo(t){return t.replace(Uw,Jw)}function Jw(t,e,n){if(e)return e;if(n.charCodeAt(0)===35){let i=n.charCodeAt(1),o=i===120||i===88;return Mo(n.slice(o?2:1),o?16:10)}return pr(n)||t}function rn(t){return!t||typeof t!="object"?"":"position"in t||"type"in t?Dd(t.position):"start"in t||"end"in t?Dd(t):"line"in t||"column"in t?$a(t):""}function $a(t){return Bd(t&&t.line)+":"+Bd(t&&t.column)}function Dd(t){return $a(t&&t.start)+"-"+$a(t&&t.end)}function Bd(t){return t&&typeof t=="number"?t:1}var Pd={}.hasOwnProperty;function _a(t,e,n){return e&&typeof e=="object"&&(n=e,e=void 0),Gw(n)(Fa(Pa(n).document().write(za()(t,e,!0))))}function Gw(t){let e={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:o(Zf),autolinkProtocol:B,autolinkEmail:B,atxHeading:o(Qf),blockQuote:o(Lt),characterEscape:B,characterReference:B,codeFenced:o(Cn),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:o(Cn,s),codeText:o(ur,s),codeTextData:B,data:B,codeFlowValue:B,definition:o(xa),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:o(nx),hardBreakEscape:o(Yf),hardBreakTrailing:o(Yf),htmlFlow:o(Xf,s),htmlFlowData:B,htmlText:o(Xf,s),htmlTextData:B,image:o(rx),label:s,link:o(Zf),listItem:o(ix),listItemValue:d,listOrdered:o(ed,f),listUnordered:o(ed),paragraph:o(ox),reference:b,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:o(Qf),strong:o(sx),thematicBreak:o(lx)},exit:{atxHeading:l(),atxHeadingSequence:I,autolink:l(),autolinkEmail:ui,autolinkProtocol:Me,blockQuote:l(),characterEscapeValue:S,characterReferenceMarkerHexadecimal:Sn,characterReferenceMarkerNumeric:Sn,characterReferenceValue:ba,characterReference:xo,codeFenced:l(g),codeFencedFence:m,codeFencedFenceInfo:p,codeFencedFenceMeta:h,codeFlowValue:S,codeIndented:l(y),codeText:l(j),codeTextData:S,data:S,definition:l(),definitionDestinationString:v,definitionLabelString:x,definitionTitleString:C,emphasis:l(),hardBreakEscape:l(Y),hardBreakTrailing:l(Y),htmlFlow:l(L),htmlFlowData:S,htmlText:l(W),htmlTextData:S,image:l(me),label:Mt,labelText:ut,lineEnding:ce,link:l(le),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:We,resourceDestinationString:k,resourceTitleString:Xe,resource:Bt,setextHeading:l(D),setextHeadingLineSequence:N,setextHeadingText:w,strong:l(),thematicBreak:l()}};Fd(e,(t||{}).mdastExtensions||[]);let n={};return r;function r(T){let O={type:"root",children:[]},q={stack:[O],tokenStack:[],config:e,enter:a,exit:c,buffer:s,resume:u,data:n},Q=[],ie=-1;for(;++ie<T.length;)if(T[ie][1].type==="listOrdered"||T[ie][1].type==="listUnordered")if(T[ie][0]==="enter")Q.push(ie);else{let ft=Q.pop();ie=i(T,ft,ie)}for(ie=-1;++ie<T.length;){let ft=e[T[ie][0]];Pd.call(ft,T[ie][1].type)&&ft[T[ie][1].type].call(Object.assign({sliceSerialize:T[ie][2].sliceSerialize},q),T[ie][1])}if(q.tokenStack.length>0){let ft=q.tokenStack[q.tokenStack.length-1];(ft[1]||Ld).call(q,void 0,ft[0])}for(O.position={start:on(T.length>0?T[0][1].start:{line:1,column:1,offset:0}),end:on(T.length>0?T[T.length-2][1].end:{line:1,column:1,offset:0})},ie=-1;++ie<e.transforms.length;)O=e.transforms[ie](O)||O;return O}function i(T,O,q){let Q=O-1,ie=-1,ft=!1,Mn,Pt,fi,di;for(;++Q<=q;){let je=T[Q];switch(je[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{je[0]==="enter"?ie++:ie--,di=void 0;break}case"lineEndingBlank":{je[0]==="enter"&&(Mn&&!di&&!ie&&!fi&&(fi=Q),di=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:di=void 0}if(!ie&&je[0]==="enter"&&je[1].type==="listItemPrefix"||ie===-1&&je[0]==="exit"&&(je[1].type==="listUnordered"||je[1].type==="listOrdered")){if(Mn){let fr=Q;for(Pt=void 0;fr--;){let Ft=T[fr];if(Ft[1].type==="lineEnding"||Ft[1].type==="lineEndingBlank"){if(Ft[0]==="exit")continue;Pt&&(T[Pt][1].type="lineEndingBlank",ft=!0),Ft[1].type="lineEnding",Pt=fr}else if(!(Ft[1].type==="linePrefix"||Ft[1].type==="blockQuotePrefix"||Ft[1].type==="blockQuotePrefixWhitespace"||Ft[1].type==="blockQuoteMarker"||Ft[1].type==="listItemIndent"))break}fi&&(!Pt||fi<Pt)&&(Mn._spread=!0),Mn.end=Object.assign({},Pt?T[Pt][1].start:je[1].end),T.splice(Pt||Q,0,["exit",Mn,je[2]]),Q++,q++}if(je[1].type==="listItemPrefix"){let fr={type:"listItem",_spread:!1,start:Object.assign({},je[1].start),end:void 0};Mn=fr,T.splice(Q,0,["enter",fr,je[2]]),Q++,q++,fi=void 0,di=!0}}}return T[O][1]._spread=ft,q}function o(T,O){return q;function q(Q){a.call(this,T(Q),Q),O&&O.call(this,Q)}}function s(){this.stack.push({type:"fragment",children:[]})}function a(T,O,q){this.stack[this.stack.length-1].children.push(T),this.stack.push(T),this.tokenStack.push([O,q||void 0]),T.position={start:on(O.start),end:void 0}}function l(T){return O;function O(q){T&&T.call(this,q),c.call(this,q)}}function c(T,O){let q=this.stack.pop(),Q=this.tokenStack.pop();if(Q)Q[0].type!==T.type&&(O?O.call(this,T,Q[0]):(Q[1]||Ld).call(this,T,Q[0]));else throw new Error("Cannot close `"+T.type+"` ("+rn({start:T.start,end:T.end})+"): it\u2019s not open");q.position.end=on(T.end)}function u(){return En(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function d(T){if(this.data.expectingFirstListItemValue){let O=this.stack[this.stack.length-2];O.start=Number.parseInt(this.sliceSerialize(T),10),this.data.expectingFirstListItemValue=void 0}}function p(){let T=this.resume(),O=this.stack[this.stack.length-1];O.lang=T}function h(){let T=this.resume(),O=this.stack[this.stack.length-1];O.meta=T}function m(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function g(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function y(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T.replace(/(\r?\n|\r)$/g,"")}function x(T){let O=this.resume(),q=this.stack[this.stack.length-1];q.label=O,q.identifier=Ae(this.sliceSerialize(T)).toLowerCase()}function C(){let T=this.resume(),O=this.stack[this.stack.length-1];O.title=T}function v(){let T=this.resume(),O=this.stack[this.stack.length-1];O.url=T}function I(T){let O=this.stack[this.stack.length-1];if(!O.depth){let q=this.sliceSerialize(T).length;O.depth=q}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function N(T){let O=this.stack[this.stack.length-1];O.depth=this.sliceSerialize(T).codePointAt(0)===61?1:2}function D(){this.data.setextHeadingSlurpLineEnding=void 0}function B(T){let q=this.stack[this.stack.length-1].children,Q=q[q.length-1];(!Q||Q.type!=="text")&&(Q=ax(),Q.position={start:on(T.start),end:void 0},q.push(Q)),this.stack.push(Q)}function S(T){let O=this.stack.pop();O.value+=this.sliceSerialize(T),O.position.end=on(T.end)}function ce(T){let O=this.stack[this.stack.length-1];if(this.data.atHardBreak){let q=O.children[O.children.length-1];q.position.end=on(T.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&e.canContainEols.includes(O.type)&&(B.call(this,T),S.call(this,T))}function Y(){this.data.atHardBreak=!0}function L(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T}function W(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T}function j(){let T=this.resume(),O=this.stack[this.stack.length-1];O.value=T}function le(){let T=this.stack[this.stack.length-1];if(this.data.inReference){let O=this.data.referenceType||"shortcut";T.type+="Reference",T.referenceType=O,delete T.url,delete T.title}else delete T.identifier,delete T.label;this.data.referenceType=void 0}function me(){let T=this.stack[this.stack.length-1];if(this.data.inReference){let O=this.data.referenceType||"shortcut";T.type+="Reference",T.referenceType=O,delete T.url,delete T.title}else delete T.identifier,delete T.label;this.data.referenceType=void 0}function ut(T){let O=this.sliceSerialize(T),q=this.stack[this.stack.length-2];q.label=Lo(O),q.identifier=Ae(O).toLowerCase()}function Mt(){let T=this.stack[this.stack.length-1],O=this.resume(),q=this.stack[this.stack.length-1];if(this.data.inReference=!0,q.type==="link"){let Q=T.children;q.children=Q}else q.alt=O}function k(){let T=this.resume(),O=this.stack[this.stack.length-1];O.url=T}function Xe(){let T=this.resume(),O=this.stack[this.stack.length-1];O.title=T}function Bt(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function We(T){let O=this.resume(),q=this.stack[this.stack.length-1];q.label=O,q.identifier=Ae(this.sliceSerialize(T)).toLowerCase(),this.data.referenceType="full"}function Sn(T){this.data.characterReferenceType=T.type}function ba(T){let O=this.sliceSerialize(T),q=this.data.characterReferenceType,Q;q?(Q=Mo(O,q==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):Q=pr(O);let ie=this.stack[this.stack.length-1];ie.value+=Q}function xo(T){let O=this.stack.pop();O.position.end=on(T.end)}function Me(T){S.call(this,T);let O=this.stack[this.stack.length-1];O.url=this.sliceSerialize(T)}function ui(T){S.call(this,T);let O=this.stack[this.stack.length-1];O.url="mailto:"+this.sliceSerialize(T)}function Lt(){return{type:"blockquote",children:[]}}function Cn(){return{type:"code",lang:null,meta:null,value:""}}function ur(){return{type:"inlineCode",value:""}}function xa(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function nx(){return{type:"emphasis",children:[]}}function Qf(){return{type:"heading",depth:0,children:[]}}function Yf(){return{type:"break"}}function Xf(){return{type:"html",value:""}}function rx(){return{type:"image",title:null,url:"",alt:null}}function Zf(){return{type:"link",title:null,url:"",children:[]}}function ed(T){return{type:"list",ordered:T.type==="listOrdered",start:null,spread:T._spread,children:[]}}function ix(T){return{type:"listItem",spread:T._spread,checked:null,children:[]}}function ox(){return{type:"paragraph",children:[]}}function sx(){return{type:"strong",children:[]}}function ax(){return{type:"text",value:""}}function lx(){return{type:"thematicBreak"}}}function on(t){return{line:t.line,column:t.column,offset:t.offset}}function Fd(t,e){let n=-1;for(;++n<e.length;){let r=e[n];Array.isArray(r)?Fd(t,r):Qw(t,r)}}function Qw(t,e){let n;for(n in e)if(Pd.call(e,n))switch(n){case"canContainEols":{let r=e[n];r&&t[n].push(...r);break}case"transforms":{let r=e[n];r&&t[n].push(...r);break}case"enter":case"exit":{let r=e[n];r&&Object.assign(t[n],r);break}}}function Ld(t,e){throw t?new Error("Cannot close `"+t.type+"` ("+rn({start:t.start,end:t.end})+"): a different token (`"+e.type+"`, "+rn({start:e.start,end:e.end})+") is open"):new Error("Cannot close document, a token (`"+e.type+"`, "+rn({start:e.start,end:e.end})+") is still open")}function hr(t){let e=this;e.parser=n;function n(r){return _a(r,{...e.data("settings"),...t,extensions:e.data("micromarkExtensions")||[],mdastExtensions:e.data("fromMarkdownExtensions")||[]})}}var zd={}.hasOwnProperty;function $d(t,e){let n=e||{};function r(i,...o){let s=r.invalid,a=r.handlers;if(i&&zd.call(i,t)){let l=String(i[t]);s=zd.call(a,l)?a[l]:r.unknown}if(s)return s.call(this,i,...o)}return r.handlers=n.handlers||{},r.invalid=n.invalid,r.unknown=n.unknown,r}var Yw={}.hasOwnProperty;function Ha(t,e){let n=-1,r;if(e.extensions)for(;++n<e.extensions.length;)Ha(t,e.extensions[n]);for(r in e)if(Yw.call(e,r))switch(r){case"extensions":break;case"unsafe":{_d(t[r],e[r]);break}case"join":{_d(t[r],e[r]);break}case"handlers":{Xw(t[r],e[r]);break}default:t.options[r]=e[r]}return t}function _d(t,e){e&&t.push(...e)}function Xw(t,e){e&&Object.assign(t,e)}function Hd(t,e,n,r){let i=n.enter("blockquote"),o=n.createTracker(r);o.move("> "),o.shift(2);let s=n.indentLines(n.containerFlow(t,o.current()),Zw);return i(),s}function Zw(t,e,n){return">"+(n?"":" ")+t}function Po(t,e){return Vd(t,e.inConstruct,!0)&&!Vd(t,e.notInConstruct,!1)}function Vd(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++r<e.length;)if(t.includes(e[r]))return!0;return!1}function Va(t,e,n,r){let i=-1;for(;++i<n.unsafe.length;)if(n.unsafe[i].character===` `&&Po(n.stack,n.unsafe[i]))return/[ \t]/.test(r.before)?"":" ";return`\\ -`}function Fo(t,e){let n=String(t),r=n.indexOf(e),i=r,o=0,s=0;if(typeof e!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++o>s&&(s=o):o=1,i=r+e.length,r=n.indexOf(e,i);return s}function ki(t,e){return!!(e.options.fences===!1&&t.value&&!t.lang&&/[^ \r\n]/.test(t.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(t.value))}function Vd(t){let e=t.options.fence||"`";if(e!=="`"&&e!=="~")throw new Error("Cannot serialize code with `"+e+"` for `options.fence`, expected `` ` `` or `~`");return e}function Wd(t,e,n,r){let i=Vd(n),o=t.value||"",s=i==="`"?"GraveAccent":"Tilde";if(ki(t,n)){let f=n.enter("codeIndented"),d=n.indentLines(o,Zw);return f(),d}let a=n.createTracker(r),l=i.repeat(Math.max(Fo(o,i)+1,3)),c=n.enter("codeFenced"),u=a.move(l);if(t.lang){let f=n.enter(`codeFencedLang${s}`);u+=a.move(n.safe(t.lang,{before:u,after:" ",encode:["`"],...a.current()})),f()}if(t.lang&&t.meta){let f=n.enter(`codeFencedMeta${s}`);u+=a.move(" "),u+=a.move(n.safe(t.meta,{before:u,after:` +`}function Fo(t,e){let n=String(t),r=n.indexOf(e),i=r,o=0,s=0;if(typeof e!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++o>s&&(s=o):o=1,i=r+e.length,r=n.indexOf(e,i);return s}function ki(t,e){return!!(e.options.fences===!1&&t.value&&!t.lang&&/[^ \r\n]/.test(t.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(t.value))}function Wd(t){let e=t.options.fence||"`";if(e!=="`"&&e!=="~")throw new Error("Cannot serialize code with `"+e+"` for `options.fence`, expected `` ` `` or `~`");return e}function jd(t,e,n,r){let i=Wd(n),o=t.value||"",s=i==="`"?"GraveAccent":"Tilde";if(ki(t,n)){let f=n.enter("codeIndented"),d=n.indentLines(o,e1);return f(),d}let a=n.createTracker(r),l=i.repeat(Math.max(Fo(o,i)+1,3)),c=n.enter("codeFenced"),u=a.move(l);if(t.lang){let f=n.enter(`codeFencedLang${s}`);u+=a.move(n.safe(t.lang,{before:u,after:" ",encode:["`"],...a.current()})),f()}if(t.lang&&t.meta){let f=n.enter(`codeFencedMeta${s}`);u+=a.move(" "),u+=a.move(n.safe(t.meta,{before:u,after:` `,encode:["`"],...a.current()})),f()}return u+=a.move(` `),o&&(u+=a.move(o+` -`)),u+=a.move(l),c(),u}function Zw(t,e,n){return(n?"":" ")+t}function mr(t){let e=t.options.quote||'"';if(e!=='"'&&e!=="'")throw new Error("Cannot serialize title with `"+e+"` for `options.quote`, expected `\"`, or `'`");return e}function jd(t,e,n,r){let i=mr(n),o=i==='"'?"Quote":"Apostrophe",s=n.enter("definition"),a=n.enter("label"),l=n.createTracker(r),c=l.move("[");return c+=l.move(n.safe(n.associationId(t),{before:c,after:"]",...l.current()})),c+=l.move("]: "),a(),!t.url||/[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":` -`,...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),s(),c}function qd(t){let e=t.options.emphasis||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize emphasis with `"+e+"` for `options.emphasis`, expected `*`, or `_`");return e}function qe(t){return"&#x"+t.toString(16).toUpperCase()+";"}function gr(t,e,n){let r=zt(t),i=zt(e);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}Wa.peek=e1;function Wa(t,e,n,r){let i=qd(n),o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=gr(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=qe(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=gr(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+qe(f));let p=s.move(i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function e1(t,e,n){return n.options.emphasis||"*"}var sn=(function(t){if(t==null)return i1;if(typeof t=="function")return zo(t);if(typeof t=="object")return Array.isArray(t)?t1(t):n1(t);if(typeof t=="string")return r1(t);throw new Error("Expected function, string, or object as test")});function t1(t){let e=[],n=-1;for(;++n<t.length;)e[n]=sn(t[n]);return zo(r);function r(...i){let o=-1;for(;++o<e.length;)if(e[o].apply(this,i))return!0;return!1}}function n1(t){let e=t;return zo(n);function n(r){let i=r,o;for(o in t)if(i[o]!==e[o])return!1;return!0}}function r1(t){return zo(e);function e(n){return n&&n.type===t}}function zo(t){return e;function e(n,r,i){return!!(o1(n)&&t.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function i1(){return!0}function o1(t){return t!==null&&typeof t=="object"&&"type"in t}var Kd=[],$o=!0,Rn=!1,On="skip";function Dn(t,e,n,r){let i;typeof e=="function"&&typeof n!="function"?(r=n,n=e):i=e;let o=sn(i),s=r?-1:1;a(t,void 0,[])();function a(l,c,u){let f=l&&typeof l=="object"?l:{};if(typeof f.type=="string"){let p=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(d,"name",{value:"node ("+(l.type+(p?"<"+p+">":""))+")"})}return d;function d(){let p=Kd,h,m,g;if((!e||o(l,c,u[u.length-1]||void 0))&&(p=s1(n(l,u)),p[0]===Rn))return p;if("children"in l&&l.children){let y=l;if(y.children&&p[0]!==On)for(m=(r?y.children.length:-1)+s,g=u.concat(y);m>-1&&m<y.children.length;){let x=y.children[m];if(h=a(x,m,g)(),h[0]===Rn)return h;m=typeof h[1]=="number"?h[1]:m+s}}return p}}}function s1(t){return Array.isArray(t)?t:typeof t=="number"?[$o,t]:t==null?Kd:[t]}function dt(t,e,n,r){let i,o,s;typeof e=="function"&&typeof n!="function"?(o=void 0,s=e,i=n):(o=e,s=n,i=r),Dn(t,o,a,i);function a(l,c){let u=c[c.length-1],f=u?u.children.indexOf(l):void 0;return s(l,f,u)}}function _o(t,e){let n=!1;return dt(t,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,Rn}),!!((!t.depth||t.depth<3)&&En(t)&&(e.options.setext||n))}function Ud(t,e,n,r){let i=Math.max(Math.min(6,t.depth||1),1),o=n.createTracker(r);if(_o(t,n)){let u=n.enter("headingSetext"),f=n.enter("phrasing"),d=n.containerPhrasing(t,{...o.current(),before:` +`)),u+=a.move(l),c(),u}function e1(t,e,n){return(n?"":" ")+t}function mr(t){let e=t.options.quote||'"';if(e!=='"'&&e!=="'")throw new Error("Cannot serialize title with `"+e+"` for `options.quote`, expected `\"`, or `'`");return e}function qd(t,e,n,r){let i=mr(n),o=i==='"'?"Quote":"Apostrophe",s=n.enter("definition"),a=n.enter("label"),l=n.createTracker(r),c=l.move("[");return c+=l.move(n.safe(n.associationId(t),{before:c,after:"]",...l.current()})),c+=l.move("]: "),a(),!t.url||/[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":` +`,...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),s(),c}function Kd(t){let e=t.options.emphasis||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize emphasis with `"+e+"` for `options.emphasis`, expected `*`, or `_`");return e}function qe(t){return"&#x"+t.toString(16).toUpperCase()+";"}function gr(t,e,n){let r=zt(t),i=zt(e);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}Wa.peek=t1;function Wa(t,e,n,r){let i=Kd(n),o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=gr(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=qe(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=gr(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+qe(f));let p=s.move(i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function t1(t,e,n){return n.options.emphasis||"*"}var sn=(function(t){if(t==null)return o1;if(typeof t=="function")return zo(t);if(typeof t=="object")return Array.isArray(t)?n1(t):r1(t);if(typeof t=="string")return i1(t);throw new Error("Expected function, string, or object as test")});function n1(t){let e=[],n=-1;for(;++n<t.length;)e[n]=sn(t[n]);return zo(r);function r(...i){let o=-1;for(;++o<e.length;)if(e[o].apply(this,i))return!0;return!1}}function r1(t){let e=t;return zo(n);function n(r){let i=r,o;for(o in t)if(i[o]!==e[o])return!1;return!0}}function i1(t){return zo(e);function e(n){return n&&n.type===t}}function zo(t){return e;function e(n,r,i){return!!(s1(n)&&t.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function o1(){return!0}function s1(t){return t!==null&&typeof t=="object"&&"type"in t}var Ud=[],$o=!0,Rn=!1,On="skip";function Dn(t,e,n,r){let i;typeof e=="function"&&typeof n!="function"?(r=n,n=e):i=e;let o=sn(i),s=r?-1:1;a(t,void 0,[])();function a(l,c,u){let f=l&&typeof l=="object"?l:{};if(typeof f.type=="string"){let p=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(d,"name",{value:"node ("+(l.type+(p?"<"+p+">":""))+")"})}return d;function d(){let p=Ud,h,m,g;if((!e||o(l,c,u[u.length-1]||void 0))&&(p=a1(n(l,u)),p[0]===Rn))return p;if("children"in l&&l.children){let y=l;if(y.children&&p[0]!==On)for(m=(r?y.children.length:-1)+s,g=u.concat(y);m>-1&&m<y.children.length;){let x=y.children[m];if(h=a(x,m,g)(),h[0]===Rn)return h;m=typeof h[1]=="number"?h[1]:m+s}}return p}}}function a1(t){return Array.isArray(t)?t:typeof t=="number"?[$o,t]:t==null?Ud:[t]}function dt(t,e,n,r){let i,o,s;typeof e=="function"&&typeof n!="function"?(o=void 0,s=e,i=n):(o=e,s=n,i=r),Dn(t,o,a,i);function a(l,c){let u=c[c.length-1],f=u?u.children.indexOf(l):void 0;return s(l,f,u)}}function _o(t,e){let n=!1;return dt(t,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,Rn}),!!((!t.depth||t.depth<3)&&En(t)&&(e.options.setext||n))}function Jd(t,e,n,r){let i=Math.max(Math.min(6,t.depth||1),1),o=n.createTracker(r);if(_o(t,n)){let u=n.enter("headingSetext"),f=n.enter("phrasing"),d=n.containerPhrasing(t,{...o.current(),before:` `,after:` `});return f(),u(),d+` `+(i===1?"=":"-").repeat(d.length-(Math.max(d.lastIndexOf("\r"),d.lastIndexOf(` `))+1))}let s="#".repeat(i),a=n.enter("headingAtx"),l=n.enter("phrasing");o.move(s+" ");let c=n.containerPhrasing(t,{before:"# ",after:` -`,...o.current()});return/^[\t ]/.test(c)&&(c=qe(c.charCodeAt(0))+c.slice(1)),c=c?s+" "+c:s,n.options.closeAtx&&(c+=" "+s),l(),a(),c}ja.peek=a1;function ja(t){return t.value||""}function a1(){return"<"}qa.peek=l1;function qa(t,e,n,r){let i=mr(n),o=i==='"'?"Quote":"Apostrophe",s=n.enter("image"),a=n.enter("label"),l=n.createTracker(r),c=l.move("![");return c+=l.move(n.safe(t.alt,{before:c,after:"]",...l.current()})),c+=l.move("]("),a(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":")",...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),c+=l.move(")"),s(),c}function l1(){return"!"}Ka.peek=c1;function Ka(t,e,n,r){let i=t.referenceType,o=n.enter("imageReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("!["),c=n.safe(t.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function c1(){return"!"}Ua.peek=u1;function Ua(t,e,n){let r=t.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++o<n.unsafe.length;){let s=n.unsafe[o],a=n.compilePattern(s),l;if(s.atBreak)for(;l=a.exec(r);){let c=l.index;r.charCodeAt(c)===10&&r.charCodeAt(c-1)===13&&c--,r=r.slice(0,c)+" "+r.slice(l.index+1)}}return i+r+i}function u1(){return"`"}function Ja(t,e){let n=En(t);return!!(!e.options.resourceLink&&t.url&&!t.title&&t.children&&t.children.length===1&&t.children[0].type==="text"&&(n===t.url||"mailto:"+n===t.url)&&/^[a-z][a-z+.-]+:/i.test(t.url)&&!/[\0- <>\u007F]/.test(t.url))}Ga.peek=f1;function Ga(t,e,n,r){let i=mr(n),o=i==='"'?"Quote":"Apostrophe",s=n.createTracker(r),a,l;if(Ja(t,n)){let u=n.stack;n.stack=[],a=n.enter("autolink");let f=s.move("<");return f+=s.move(n.containerPhrasing(t,{before:f,after:">",...s.current()})),f+=s.move(">"),a(),n.stack=u,f}a=n.enter("link"),l=n.enter("label");let c=s.move("[");return c+=s.move(n.containerPhrasing(t,{before:c,after:"](",...s.current()})),c+=s.move("]("),l(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(l=n.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(n.safe(t.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=n.enter("destinationRaw"),c+=s.move(n.safe(t.url,{before:c,after:t.title?" ":")",...s.current()}))),l(),t.title&&(l=n.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(n.safe(t.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),c+=s.move(")"),a(),c}function f1(t,e,n){return Ja(t,n)?"<":"["}Qa.peek=d1;function Qa(t,e,n,r){let i=t.referenceType,o=n.enter("linkReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("["),c=n.containerPhrasing(t,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function d1(){return"["}function yr(t){let e=t.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function Jd(t){let e=yr(t),n=t.options.bulletOther;if(!n)return e==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Gd(t){let e=t.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function Ho(t){let e=t.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function Qd(t,e,n,r){let i=n.enter("list"),o=n.bulletCurrent,s=t.ordered?Gd(n):yr(n),a=t.ordered?s==="."?")":".":Jd(n),l=e&&n.bulletLastUsed?s===n.bulletLastUsed:!1;if(!t.ordered){let u=t.children?t.children[0]:void 0;if((s==="*"||s==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),Ho(n)===s&&u){let f=-1;for(;++f<t.children.length;){let d=t.children[f];if(d&&d.type==="listItem"&&d.children&&d.children[0]&&d.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(s=a),n.bulletCurrent=s;let c=n.containerFlow(t,r);return n.bulletLastUsed=s,n.bulletCurrent=o,i(),c}function Yd(t){let e=t.options.listItemIndent||"one";if(e!=="tab"&&e!=="one"&&e!=="mixed")throw new Error("Cannot serialize items with `"+e+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return e}function Xd(t,e,n,r){let i=Yd(n),o=n.bulletCurrent||yr(n);e&&e.type==="list"&&e.ordered&&(o=(typeof e.start=="number"&&e.start>-1?e.start:1)+(n.options.incrementListMarker===!1?0:e.children.indexOf(t))+o);let s=o.length+1;(i==="tab"||i==="mixed"&&(e&&e.type==="list"&&e.spread||t.spread))&&(s=Math.ceil(s/4)*4);let a=n.createTracker(r);a.move(o+" ".repeat(s-o.length)),a.shift(s);let l=n.enter("listItem"),c=n.indentLines(n.containerFlow(t,a.current()),u);return l(),c;function u(f,d,p){return d?(p?"":" ".repeat(s))+f:(p?o:o+" ".repeat(s-o.length))+f}}function Zd(t,e,n,r){let i=n.enter("paragraph"),o=n.enter("phrasing"),s=n.containerPhrasing(t,r);return o(),i(),s}var Ya=sn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function ep(t,e,n,r){return(t.children.some(function(s){return Ya(s)})?n.containerPhrasing:n.containerFlow).call(n,t,r)}function tp(t){let e=t.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}Xa.peek=p1;function Xa(t,e,n,r){let i=tp(n),o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=gr(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=qe(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=gr(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+qe(f));let p=s.move(i+i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function p1(t,e,n){return n.options.strong||"*"}function np(t,e,n,r){return n.safe(t.value,r)}function rp(t){let e=t.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function ip(t,e,n){let r=(Ho(n)+(n.options.ruleSpaces?" ":"")).repeat(rp(n));return n.options.ruleSpaces?r.slice(0,-1):r}var Bn={blockquote:_d,break:Va,code:Wd,definition:jd,emphasis:Wa,hardBreak:Va,heading:Ud,html:ja,image:qa,imageReference:Ka,inlineCode:Ua,link:Ga,linkReference:Qa,list:Qd,listItem:Xd,paragraph:Zd,root:ep,strong:Xa,text:np,thematicBreak:ip};var op=[h1];function h1(t,e,n,r){if(e.type==="code"&&ki(e,r)&&(t.type==="list"||t.type===e.type&&ki(t,r)))return!1;if("spread"in n&&typeof n.spread=="boolean")return t.type==="paragraph"&&(t.type===e.type||e.type==="definition"||e.type==="heading"&&_o(e,r))?void 0:n.spread?1:0}var Ln=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],sp=[{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:` +`,...o.current()});return/^[\t ]/.test(c)&&(c=qe(c.charCodeAt(0))+c.slice(1)),c=c?s+" "+c:s,n.options.closeAtx&&(c+=" "+s),l(),a(),c}ja.peek=l1;function ja(t){return t.value||""}function l1(){return"<"}qa.peek=c1;function qa(t,e,n,r){let i=mr(n),o=i==='"'?"Quote":"Apostrophe",s=n.enter("image"),a=n.enter("label"),l=n.createTracker(r),c=l.move("![");return c+=l.move(n.safe(t.alt,{before:c,after:"]",...l.current()})),c+=l.move("]("),a(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":")",...l.current()}))),a(),t.title&&(a=n.enter(`title${o}`),c+=l.move(" "+i),c+=l.move(n.safe(t.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),c+=l.move(")"),s(),c}function c1(){return"!"}Ka.peek=u1;function Ka(t,e,n,r){let i=t.referenceType,o=n.enter("imageReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("!["),c=n.safe(t.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function u1(){return"!"}Ua.peek=f1;function Ua(t,e,n){let r=t.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++o<n.unsafe.length;){let s=n.unsafe[o],a=n.compilePattern(s),l;if(s.atBreak)for(;l=a.exec(r);){let c=l.index;r.charCodeAt(c)===10&&r.charCodeAt(c-1)===13&&c--,r=r.slice(0,c)+" "+r.slice(l.index+1)}}return i+r+i}function f1(){return"`"}function Ja(t,e){let n=En(t);return!!(!e.options.resourceLink&&t.url&&!t.title&&t.children&&t.children.length===1&&t.children[0].type==="text"&&(n===t.url||"mailto:"+n===t.url)&&/^[a-z][a-z+.-]+:/i.test(t.url)&&!/[\0- <>\u007F]/.test(t.url))}Ga.peek=d1;function Ga(t,e,n,r){let i=mr(n),o=i==='"'?"Quote":"Apostrophe",s=n.createTracker(r),a,l;if(Ja(t,n)){let u=n.stack;n.stack=[],a=n.enter("autolink");let f=s.move("<");return f+=s.move(n.containerPhrasing(t,{before:f,after:">",...s.current()})),f+=s.move(">"),a(),n.stack=u,f}a=n.enter("link"),l=n.enter("label");let c=s.move("[");return c+=s.move(n.containerPhrasing(t,{before:c,after:"](",...s.current()})),c+=s.move("]("),l(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(l=n.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(n.safe(t.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=n.enter("destinationRaw"),c+=s.move(n.safe(t.url,{before:c,after:t.title?" ":")",...s.current()}))),l(),t.title&&(l=n.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(n.safe(t.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),c+=s.move(")"),a(),c}function d1(t,e,n){return Ja(t,n)?"<":"["}Qa.peek=p1;function Qa(t,e,n,r){let i=t.referenceType,o=n.enter("linkReference"),s=n.enter("label"),a=n.createTracker(r),l=a.move("["),c=n.containerPhrasing(t,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),s();let u=n.stack;n.stack=[],s=n.enter("reference");let f=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return s(),n.stack=u,o(),i==="full"||!c||c!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function p1(){return"["}function yr(t){let e=t.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function Gd(t){let e=yr(t),n=t.options.bulletOther;if(!n)return e==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Qd(t){let e=t.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function Ho(t){let e=t.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function Yd(t,e,n,r){let i=n.enter("list"),o=n.bulletCurrent,s=t.ordered?Qd(n):yr(n),a=t.ordered?s==="."?")":".":Gd(n),l=e&&n.bulletLastUsed?s===n.bulletLastUsed:!1;if(!t.ordered){let u=t.children?t.children[0]:void 0;if((s==="*"||s==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),Ho(n)===s&&u){let f=-1;for(;++f<t.children.length;){let d=t.children[f];if(d&&d.type==="listItem"&&d.children&&d.children[0]&&d.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(s=a),n.bulletCurrent=s;let c=n.containerFlow(t,r);return n.bulletLastUsed=s,n.bulletCurrent=o,i(),c}function Xd(t){let e=t.options.listItemIndent||"one";if(e!=="tab"&&e!=="one"&&e!=="mixed")throw new Error("Cannot serialize items with `"+e+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return e}function Zd(t,e,n,r){let i=Xd(n),o=n.bulletCurrent||yr(n);e&&e.type==="list"&&e.ordered&&(o=(typeof e.start=="number"&&e.start>-1?e.start:1)+(n.options.incrementListMarker===!1?0:e.children.indexOf(t))+o);let s=o.length+1;(i==="tab"||i==="mixed"&&(e&&e.type==="list"&&e.spread||t.spread))&&(s=Math.ceil(s/4)*4);let a=n.createTracker(r);a.move(o+" ".repeat(s-o.length)),a.shift(s);let l=n.enter("listItem"),c=n.indentLines(n.containerFlow(t,a.current()),u);return l(),c;function u(f,d,p){return d?(p?"":" ".repeat(s))+f:(p?o:o+" ".repeat(s-o.length))+f}}function ep(t,e,n,r){let i=n.enter("paragraph"),o=n.enter("phrasing"),s=n.containerPhrasing(t,r);return o(),i(),s}var Ya=sn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function tp(t,e,n,r){return(t.children.some(function(s){return Ya(s)})?n.containerPhrasing:n.containerFlow).call(n,t,r)}function np(t){let e=t.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}Xa.peek=h1;function Xa(t,e,n,r){let i=np(n),o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i),l=s.move(n.containerPhrasing(t,{after:i,before:a,...s.current()})),c=l.charCodeAt(0),u=gr(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=qe(c)+l.slice(1));let f=l.charCodeAt(l.length-1),d=gr(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+qe(f));let p=s.move(i+i);return o(),n.attentionEncodeSurroundingInfo={after:d.outside,before:u.outside},a+l+p}function h1(t,e,n){return n.options.strong||"*"}function rp(t,e,n,r){return n.safe(t.value,r)}function ip(t){let e=t.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function op(t,e,n){let r=(Ho(n)+(n.options.ruleSpaces?" ":"")).repeat(ip(n));return n.options.ruleSpaces?r.slice(0,-1):r}var Bn={blockquote:Hd,break:Va,code:jd,definition:qd,emphasis:Wa,hardBreak:Va,heading:Jd,html:ja,image:qa,imageReference:Ka,inlineCode:Ua,link:Ga,linkReference:Qa,list:Yd,listItem:Zd,paragraph:ep,root:tp,strong:Xa,text:rp,thematicBreak:op};var sp=[m1];function m1(t,e,n,r){if(e.type==="code"&&ki(e,r)&&(t.type==="list"||t.type===e.type&&ki(t,r)))return!1;if("spread"in n&&typeof n.spread=="boolean")return t.type==="paragraph"&&(t.type===e.type||e.type==="definition"||e.type==="heading"&&_o(e,r))?void 0:n.spread?1:0}var Ln=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],ap=[{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:` `,inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"!",after:"\\[",inConstruct:"phrasing",notInConstruct:Ln},{character:'"',inConstruct:"titleQuote"},{atBreak:!0,character:"#"},{character:"#",inConstruct:"headingAtx",after:`(?:[\r ]|$)`},{character:"&",after:"[#A-Za-z]",inConstruct:"phrasing"},{character:"'",inConstruct:"titleApostrophe"},{character:"(",inConstruct:"destinationRaw"},{before:"\\]",character:"(",inConstruct:"phrasing",notInConstruct:Ln},{atBreak:!0,before:"\\d+",character:")"},{character:")",inConstruct:"destinationRaw"},{atBreak:!0,character:"*",after:`(?:[ \r *])`},{character:"*",inConstruct:"phrasing",notInConstruct:Ln},{atBreak:!0,character:"+",after:`(?:[ \r ])`},{atBreak:!0,character:"-",after:`(?:[ \r -])`},{atBreak:!0,before:"\\d+",character:".",after:`(?:[ \r -]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:Ln},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:Ln},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:Ln},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:Ln},{atBreak:!0,character:"~"}];function ap(t){return t.label||!t.identifier?t.label||"":Lo(t.identifier)}function lp(t){if(!t._compiled){let e=(t.atBreak?"[\\r\\n][\\t ]*":"")+(t.before?"(?:"+t.before+")":"");t._compiled=new RegExp((e?"("+e+")":"")+(/[|\\{}()[\]^$+*?.-]/.test(t.character)?"\\":"")+t.character+(t.after?"(?:"+t.after+")":""),"g")}return t._compiled}function cp(t,e,n){let r=e.indexStack,i=t.children||[],o=[],s=-1,a=n.before,l;r.push(-1);let c=e.createTracker(n);for(;++s<i.length;){let u=i[s],f;if(r[r.length-1]=s,s+1<i.length){let h=e.handle.handlers[i[s+1].type];h&&h.peek&&(h=h.peek),f=h?h(i[s+1],t,e,{before:"",after:"",...c.current()}).charAt(0):""}else f=n.after;o.length>0&&(a==="\r"||a===` -`)&&u.type==="html"&&(o[o.length-1]=o[o.length-1].replace(/(\r?\n|\r)$/," "),a=" ",c=e.createTracker(n),c.move(o.join("")));let d=e.handle(u,t,e,{...c.current(),after:f,before:a});l&&l===d.slice(0,1)&&(d=qe(l.charCodeAt(0))+d.slice(1));let p=e.attentionEncodeSurroundingInfo;e.attentionEncodeSurroundingInfo=void 0,l=void 0,p&&(o.length>0&&p.before&&a===o[o.length-1].slice(-1)&&(o[o.length-1]=o[o.length-1].slice(0,-1)+qe(a.charCodeAt(0))),p.after&&(l=f)),c.move(d),o.push(d),a=d.slice(-1)}return r.pop(),o.join("")}function up(t,e,n){let r=e.indexStack,i=t.children||[],o=e.createTracker(n),s=[],a=-1;for(r.push(-1);++a<i.length;){let l=i[a];r[r.length-1]=a,s.push(o.move(e.handle(l,t,e,{before:` +]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:Ln},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:Ln},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:Ln},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:Ln},{atBreak:!0,character:"~"}];function lp(t){return t.label||!t.identifier?t.label||"":Lo(t.identifier)}function cp(t){if(!t._compiled){let e=(t.atBreak?"[\\r\\n][\\t ]*":"")+(t.before?"(?:"+t.before+")":"");t._compiled=new RegExp((e?"("+e+")":"")+(/[|\\{}()[\]^$+*?.-]/.test(t.character)?"\\":"")+t.character+(t.after?"(?:"+t.after+")":""),"g")}return t._compiled}function up(t,e,n){let r=e.indexStack,i=t.children||[],o=[],s=-1,a=n.before,l;r.push(-1);let c=e.createTracker(n);for(;++s<i.length;){let u=i[s],f;if(r[r.length-1]=s,s+1<i.length){let h=e.handle.handlers[i[s+1].type];h&&h.peek&&(h=h.peek),f=h?h(i[s+1],t,e,{before:"",after:"",...c.current()}).charAt(0):""}else f=n.after;o.length>0&&(a==="\r"||a===` +`)&&u.type==="html"&&(o[o.length-1]=o[o.length-1].replace(/(\r?\n|\r)$/," "),a=" ",c=e.createTracker(n),c.move(o.join("")));let d=e.handle(u,t,e,{...c.current(),after:f,before:a});l&&l===d.slice(0,1)&&(d=qe(l.charCodeAt(0))+d.slice(1));let p=e.attentionEncodeSurroundingInfo;e.attentionEncodeSurroundingInfo=void 0,l=void 0,p&&(o.length>0&&p.before&&a===o[o.length-1].slice(-1)&&(o[o.length-1]=o[o.length-1].slice(0,-1)+qe(a.charCodeAt(0))),p.after&&(l=f)),c.move(d),o.push(d),a=d.slice(-1)}return r.pop(),o.join("")}function fp(t,e,n){let r=e.indexStack,i=t.children||[],o=e.createTracker(n),s=[],a=-1;for(r.push(-1);++a<i.length;){let l=i[a];r[r.length-1]=a,s.push(o.move(e.handle(l,t,e,{before:` `,after:` -`,...o.current()}))),l.type!=="list"&&(e.bulletLastUsed=void 0),a<i.length-1&&s.push(o.move(m1(l,i[a+1],t,e)))}return r.pop(),s.join("")}function m1(t,e,n,r){let i=r.join.length;for(;i--;){let o=r.join[i](t,e,n,r);if(o===!0||o===1)break;if(typeof o=="number")return` +`,...o.current()}))),l.type!=="list"&&(e.bulletLastUsed=void 0),a<i.length-1&&s.push(o.move(g1(l,i[a+1],t,e)))}return r.pop(),s.join("")}function g1(t,e,n,r){let i=r.join.length;for(;i--;){let o=r.join[i](t,e,n,r);if(o===!0||o===1)break;if(typeof o=="number")return` `.repeat(1+o);if(o===!1)return` <!----> `}return` -`}var g1=/\r?\n|\r/g;function fp(t,e){let n=[],r=0,i=0,o;for(;o=g1.exec(t);)s(t.slice(r,o.index)),n.push(o[0]),r=o.index+o[0].length,i++;return s(t.slice(r)),n.join("");function s(a){n.push(e(a,i,!a))}}function pp(t,e,n){let r=(n.before||"")+(e||"")+(n.after||""),i=[],o=[],s={},a=-1;for(;++a<t.unsafe.length;){let u=t.unsafe[a];if(!Po(t.stack,u))continue;let f=t.compilePattern(u),d;for(;d=f.exec(r);){let p="before"in u||!!u.atBreak,h="after"in u,m=d.index+(p?d[1].length:0);i.includes(m)?(s[m].before&&!p&&(s[m].before=!1),s[m].after&&!h&&(s[m].after=!1)):(i.push(m),s[m]={before:p,after:h})}}i.sort(y1);let l=n.before?n.before.length:0,c=r.length-(n.after?n.after.length:0);for(a=-1;++a<i.length;){let u=i[a];u<l||u>=c||u+1<c&&i[a+1]===u+1&&s[u].after&&!s[u+1].before&&!s[u+1].after||i[a-1]===u-1&&s[u].before&&!s[u-1].before&&!s[u-1].after||(l!==u&&o.push(dp(r.slice(l,u),"\\")),l=u,/[!-/:-@[-`{-~]/.test(r.charAt(u))&&(!n.encode||!n.encode.includes(r.charAt(u)))?o.push("\\"):(o.push(qe(r.charCodeAt(u))),l++))}return o.push(dp(r.slice(l,c),n.after)),o.join("")}function y1(t,e){return t-e}function dp(t,e){let n=/\\(?=[!-/:-@[-`{-~])/g,r=[],i=[],o=t+e,s=-1,a=0,l;for(;l=n.exec(o);)r.push(l.index);for(;++s<r.length;)a!==r[s]&&i.push(t.slice(a,r[s])),i.push("\\"),a=r[s];return i.push(t.slice(a)),i.join("")}function hp(t){let e=t||{},n=e.now||{},r=e.lineShift||0,i=n.line||1,o=n.column||1;return{move:l,current:s,shift:a};function s(){return{now:{line:i,column:o},lineShift:r}}function a(c){r+=c}function l(c){let u=c||"",f=u.split(/\r?\n|\r/g),d=f[f.length-1];return i+=f.length-1,o=f.length===1?o+d.length:1+d.length+r,u}}function Za(t,e){let n=e||{},r={associationId:ap,containerPhrasing:w1,containerFlow:S1,createTracker:hp,compilePattern:lp,enter:o,handlers:{...Bn},handle:void 0,indentLines:fp,indexStack:[],join:[...op],options:{},safe:C1,stack:[],unsafe:[...sp]};Ha(r,n),r.options.tightDefinitions&&r.join.push(x1),r.handle=zd("type",{invalid:k1,unknown:b1,handlers:r.handlers});let i=r.handle(t,void 0,r,{before:` +`}var y1=/\r?\n|\r/g;function dp(t,e){let n=[],r=0,i=0,o;for(;o=y1.exec(t);)s(t.slice(r,o.index)),n.push(o[0]),r=o.index+o[0].length,i++;return s(t.slice(r)),n.join("");function s(a){n.push(e(a,i,!a))}}function hp(t,e,n){let r=(n.before||"")+(e||"")+(n.after||""),i=[],o=[],s={},a=-1;for(;++a<t.unsafe.length;){let u=t.unsafe[a];if(!Po(t.stack,u))continue;let f=t.compilePattern(u),d;for(;d=f.exec(r);){let p="before"in u||!!u.atBreak,h="after"in u,m=d.index+(p?d[1].length:0);i.includes(m)?(s[m].before&&!p&&(s[m].before=!1),s[m].after&&!h&&(s[m].after=!1)):(i.push(m),s[m]={before:p,after:h})}}i.sort(k1);let l=n.before?n.before.length:0,c=r.length-(n.after?n.after.length:0);for(a=-1;++a<i.length;){let u=i[a];u<l||u>=c||u+1<c&&i[a+1]===u+1&&s[u].after&&!s[u+1].before&&!s[u+1].after||i[a-1]===u-1&&s[u].before&&!s[u-1].before&&!s[u-1].after||(l!==u&&o.push(pp(r.slice(l,u),"\\")),l=u,/[!-/:-@[-`{-~]/.test(r.charAt(u))&&(!n.encode||!n.encode.includes(r.charAt(u)))?o.push("\\"):(o.push(qe(r.charCodeAt(u))),l++))}return o.push(pp(r.slice(l,c),n.after)),o.join("")}function k1(t,e){return t-e}function pp(t,e){let n=/\\(?=[!-/:-@[-`{-~])/g,r=[],i=[],o=t+e,s=-1,a=0,l;for(;l=n.exec(o);)r.push(l.index);for(;++s<r.length;)a!==r[s]&&i.push(t.slice(a,r[s])),i.push("\\"),a=r[s];return i.push(t.slice(a)),i.join("")}function mp(t){let e=t||{},n=e.now||{},r=e.lineShift||0,i=n.line||1,o=n.column||1;return{move:l,current:s,shift:a};function s(){return{now:{line:i,column:o},lineShift:r}}function a(c){r+=c}function l(c){let u=c||"",f=u.split(/\r?\n|\r/g),d=f[f.length-1];return i+=f.length-1,o=f.length===1?o+d.length:1+d.length+r,u}}function Za(t,e){let n=e||{},r={associationId:lp,containerPhrasing:S1,containerFlow:C1,createTracker:mp,compilePattern:cp,enter:o,handlers:{...Bn},handle:void 0,indentLines:dp,indexStack:[],join:[...sp],options:{},safe:M1,stack:[],unsafe:[...ap]};Ha(r,n),r.options.tightDefinitions&&r.join.push(w1),r.handle=$d("type",{invalid:b1,unknown:x1,handlers:r.handlers});let i=r.handle(t,void 0,r,{before:` `,after:` `,now:{line:1,column:1},lineShift:0});return i&&i.charCodeAt(i.length-1)!==10&&i.charCodeAt(i.length-1)!==13&&(i+=` -`),i;function o(s){return r.stack.push(s),a;function a(){r.stack.pop()}}}function k1(t){throw new Error("Cannot handle value `"+t+"`, expected node")}function b1(t){let e=t;throw new Error("Cannot handle unknown node `"+e.type+"`")}function x1(t,e){if(t.type==="definition"&&t.type===e.type)return 0}function w1(t,e){return cp(t,this,e)}function S1(t,e){return up(t,this,e)}function C1(t,e){return pp(this,t,e)}function kr(t){let e=this;e.compiler=n;function n(r){return Za(r,{...e.data("settings"),...t,extensions:e.data("toMarkdownExtensions")||[]})}}function el(t){if(t)throw t}var jo=gx(Cp(),1);function bi(t){if(typeof t!="object"||t===null)return!1;let e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function tl(){let t=[],e={run:n,use:r};return e;function n(...i){let o=-1,s=i.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);a(null,...i);function a(l,...c){let u=t[++o],f=-1;if(l){s(l);return}for(;++f<i.length;)(c[f]===null||c[f]===void 0)&&(c[f]=i[f]);i=c,u?Mp(u,a)(...c):s(null,...c)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return t.push(i),e}}function Mp(t,e){let n;return r;function r(...s){let a=t.length>s.length,l;a&&s.push(i);try{l=t.apply(this,s)}catch(c){let u=c;if(a&&n)throw u;return i(u)}a||(l&&l.then&&typeof l.then=="function"?l.then(o,i):l instanceof Error?i(l):o(l))}function i(s,...a){n||(n=!0,e(s,...a))}function o(s){i(null,s)}}var be=class extends Error{constructor(e,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",o={},s=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let l=r.indexOf(":");l===-1?o.ruleId=r:(o.source=r.slice(0,l),o.ruleId=r.slice(l+1))}if(!o.place&&o.ancestors&&o.ancestors){let l=o.ancestors[o.ancestors.length-1];l&&(o.place=l.position)}let a=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=rn(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};be.prototype.file="";be.prototype.name="";be.prototype.reason="";be.prototype.message="";be.prototype.stack="";be.prototype.column=void 0;be.prototype.line=void 0;be.prototype.ancestors=void 0;be.prototype.cause=void 0;be.prototype.fatal=void 0;be.prototype.place=void 0;be.prototype.ruleId=void 0;be.prototype.source=void 0;var pt={basename:M1,dirname:E1,extname:T1,join:v1,sep:"/"};function M1(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');xi(t);let n=0,r=-1,i=t.length,o;if(e===void 0||e.length===0||e.length>t.length){for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":t.slice(n,r)}if(e===t)return"";let s=-1,a=e.length-1;for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else s<0&&(o=!0,s=i+1),a>-1&&(t.codePointAt(i)===e.codePointAt(a--)?a<0&&(r=i):(a=-1,r=s));return n===r?r=s:r<0&&(r=t.length),t.slice(n,r)}function E1(t){if(xi(t),t.length===0)return".";let e=-1,n=t.length,r;for(;--n;)if(t.codePointAt(n)===47){if(r){e=n;break}}else r||(r=!0);return e<0?t.codePointAt(0)===47?"/":".":e===1&&t.codePointAt(0)===47?"//":t.slice(0,e)}function T1(t){xi(t);let e=t.length,n=-1,r=0,i=-1,o=0,s;for(;e--;){let a=t.codePointAt(e);if(a===47){if(s){r=e+1;break}continue}n<0&&(s=!0,n=e+1),a===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||n<0||o===0||o===1&&i===n-1&&i===r+1?"":t.slice(i,n)}function v1(...t){let e=-1,n;for(;++e<t.length;)xi(t[e]),t[e]&&(n=n===void 0?t[e]:n+"/"+t[e]);return n===void 0?".":I1(n)}function I1(t){xi(t);let e=t.codePointAt(0)===47,n=A1(t,!e);return n.length===0&&!e&&(n="."),n.length>0&&t.codePointAt(t.length-1)===47&&(n+="/"),e?"/"+n:n}function A1(t,e){let n="",r=0,i=-1,o=0,s=-1,a,l;for(;++s<=t.length;){if(s<t.length)a=t.codePointAt(s);else{if(a===47)break;a=47}if(a===47){if(!(i===s-1||o===1))if(i!==s-1&&o===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=s,o=0;continue}}else if(n.length>0){n="",r=0,i=s,o=0;continue}}e&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+t.slice(i+1,s):n=t.slice(i+1,s),r=s-i-1;i=s,o=0}else a===46&&o>-1?o++:o=-1}return n}function xi(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}var Ep={cwd:N1};function N1(){return"/"}function br(t){return!!(t!==null&&typeof t=="object"&&"href"in t&&t.href&&"protocol"in t&&t.protocol&&t.auth===void 0)}function Tp(t){if(typeof t=="string")t=new URL(t);else if(!br(t)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+t+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(t.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return R1(t)}function R1(t){if(t.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=t.pathname,n=-1;for(;++n<e.length;)if(e.codePointAt(n)===37&&e.codePointAt(n+1)===50){let r=e.codePointAt(n+2);if(r===70||r===102){let i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(e)}var nl=["history","path","basename","stem","extname","dirname"],wi=class{constructor(e){let n;e?br(e)?n={path:e}:typeof e=="string"||O1(e)?n={value:e}:n=e:n={},this.cwd="cwd"in n?"":Ep.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<nl.length;){let o=nl[r];o in n&&n[o]!==void 0&&n[o]!==null&&(this[o]=o==="history"?[...n[o]]:n[o])}let i;for(i in n)nl.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?pt.basename(this.path):void 0}set basename(e){il(e,"basename"),rl(e,"basename"),this.path=pt.join(this.dirname||"",e)}get dirname(){return typeof this.path=="string"?pt.dirname(this.path):void 0}set dirname(e){vp(this.basename,"dirname"),this.path=pt.join(e||"",this.basename)}get extname(){return typeof this.path=="string"?pt.extname(this.path):void 0}set extname(e){if(rl(e,"extname"),vp(this.dirname,"extname"),e){if(e.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=pt.join(this.dirname,this.stem+(e||""))}get path(){return this.history[this.history.length-1]}set path(e){br(e)&&(e=Tp(e)),il(e,"path"),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path=="string"?pt.basename(this.path,this.extname):void 0}set stem(e){il(e,"stem"),rl(e,"stem"),this.path=pt.join(this.dirname||"",e+(this.extname||""))}fail(e,n,r){let i=this.message(e,n,r);throw i.fatal=!0,i}info(e,n,r){let i=this.message(e,n,r);return i.fatal=void 0,i}message(e,n,r){let i=new be(e,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(e){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(e||void 0).decode(this.value)}};function rl(t,e){if(t&&t.includes(pt.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+pt.sep+"`")}function il(t,e){if(!t)throw new Error("`"+e+"` cannot be empty")}function vp(t,e){if(!t)throw new Error("Setting `"+e+"` requires `path` to be set too")}function O1(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}var Ip=(function(t){let r=this.constructor.prototype,i=r[t],o=function(){return i.apply(o,arguments)};return Object.setPrototypeOf(o,r),o});var D1={}.hasOwnProperty,ll=class t extends Ip{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=tl()}copy(){let e=new t,n=-1;for(;++n<this.attachers.length;){let r=this.attachers[n];e.use(...r)}return e.data((0,jo.default)(!0,{},this.namespace)),e}data(e,n){return typeof e=="string"?arguments.length===2?(al("data",this.frozen),this.namespace[e]=n,this):D1.call(this.namespace,e)&&this.namespace[e]||void 0:e?(al("data",this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);let i=n.call(e,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(e){this.freeze();let n=Wo(e),r=this.parser||this.Parser;return ol("parse",r),r(String(n),n)}process(e,n){let r=this;return this.freeze(),ol("process",this.parser||this.Parser),sl("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(o,s){let a=Wo(e),l=r.parse(a);r.run(l,a,function(u,f,d){if(u||!f||!d)return c(u);let p=f,h=r.stringify(p,d);L1(h)?d.value=h:d.result=h,c(u,d)});function c(u,f){u||!f?s(u):o?o(f):n(void 0,f)}}}processSync(e){let n=!1,r;return this.freeze(),ol("processSync",this.parser||this.Parser),sl("processSync",this.compiler||this.Compiler),this.process(e,i),Np("processSync","process",n),r;function i(o,s){n=!0,el(o),r=s}}run(e,n,r){Ap(e),this.freeze();let i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?o(void 0,r):new Promise(o);function o(s,a){let l=Wo(n);i.run(e,l,c);function c(u,f,d){let p=f||e;u?a(u):s?s(p):r(void 0,p,d)}}}runSync(e,n){let r=!1,i;return this.run(e,n,o),Np("runSync","run",r),i;function o(s,a){el(s),i=a,r=!0}}stringify(e,n){this.freeze();let r=Wo(n),i=this.compiler||this.Compiler;return sl("stringify",i),Ap(e),i(e,r)}use(e,...n){let r=this.attachers,i=this.namespace;if(al("use",this.frozen),e!=null)if(typeof e=="function")l(e,n);else if(typeof e=="object")Array.isArray(e)?a(e):s(e);else throw new TypeError("Expected usable value, not `"+e+"`");return this;function o(c){if(typeof c=="function")l(c,[]);else if(typeof c=="object")if(Array.isArray(c)){let[u,...f]=c;l(u,f)}else s(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function s(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(c.plugins),c.settings&&(i.settings=(0,jo.default)(!0,i.settings,c.settings))}function a(c){let u=-1;if(c!=null)if(Array.isArray(c))for(;++u<c.length;){let f=c[u];o(f)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function l(c,u){let f=-1,d=-1;for(;++f<r.length;)if(r[f][0]===c){d=f;break}if(d===-1)r.push([c,...u]);else if(u.length>0){let[p,...h]=u,m=r[d][1];bi(m)&&bi(p)&&(p=(0,jo.default)(!0,m,p)),r[d]=[c,p,...h]}}}},Si=new ll().freeze();function ol(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `parser`")}function sl(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `compiler`")}function al(t,e){if(e)throw new Error("Cannot call `"+t+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Ap(t){if(!bi(t)||typeof t.type!="string")throw new TypeError("Expected node, got `"+t+"`")}function Np(t,e,n){if(!n)throw new Error("`"+t+"` finished async. Use `"+e+"` instead")}function Wo(t){return B1(t)?t:new wi(t)}function B1(t){return!!(t&&typeof t=="object"&&"message"in t&&"messages"in t)}function L1(t){return typeof t=="string"||P1(t)}function P1(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}function Re(t){this.content=t}Re.prototype={constructor:Re,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var r=n&&n!=t?this.remove(n):this,i=r.find(t),o=r.content.slice();return i==-1?o.push(n||t,e):(o[i+1]=e,n&&(o[i]=n)),new Re(o)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new Re(n)},addToStart:function(t,e){return new Re([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new Re(n)},addBefore:function(t,e,n){var r=this.remove(e),i=r.content.slice(),o=r.find(t);return i.splice(o==-1?i.length:o,0,e,n),new Re(i)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=Re.from(t),t.size?new Re(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=Re.from(t),t.size?new Re(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=Re.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};Re.from=function(t){if(t instanceof Re)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Re(e)};var cl=Re;function _p(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){let s=i.text,a=o.text,l=0;for(;s[l]==a[l];l++)n++;return l&&l<s.length&&l<a.length&&Wp(s.charCodeAt(l-1))&&Vp(s.charCodeAt(l))&&n--,n}if(i.content.size||o.content.size){let s=_p(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function Hp(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let s=t.child(--i),a=e.child(--o),l=s.nodeSize;if(s==a){n-=l,r-=l;continue}if(!s.sameMarkup(a))return{a:n,b:r};if(s.isText&&s.text!=a.text){let c=s.text,u=a.text,f=c.length,d=u.length;for(;f>0&&d>0&&c[f-1]==u[d-1];)f--,d--,n--,r--;return f&&d&&f<c.length&&Wp(c.charCodeAt(f-1))&&Vp(c.charCodeAt(f))&&(n++,r++),{a:n,b:r}}if(s.content.size||a.content.size){let c=Hp(s.content,a.content,n-1,r-1);if(c)return c}n-=l,r-=l}}function Vp(t){return t>=56320&&t<57344}function Wp(t){return t>=55296&&t<56320}var E=class t{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,i=0,o){for(let s=0,a=0;a<n;s++){let l=this.content[s],c=a+l.nodeSize;if(c>e&&r(l,i+a,o||null,s)!==!1&&l.content.size){let u=a+1;l.nodesBetween(Math.max(0,e-u),Math.min(l.content.size,n-u),r,i+u)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(a,l)=>{let c=a.isText?a.text.slice(Math.max(e,l)-l,n-l):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&c||a.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)i.push(e.content[o]);return new t(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],i=0;if(n>e)for(let o=0,s=0;s<n;o++){let a=this.content[o],l=s+a.nodeSize;l>e&&((s<e||l>n)&&(a.isText?a=a.cut(Math.max(0,e-s),Math.min(a.text.length,n-s)):a=a.cut(Math.max(0,e-s-1),Math.min(a.content.size,n-s-1))),r.push(a),i+=a.nodeSize),s=l}return new t(r,i)}cutByIndex(e,n){return e==n?t.empty:e==0&&n==this.content.length?this:new t(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new t(i,o)}addToStart(e){return new t([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new t(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let i=this.content[n];e(i,r,n),r+=i.nodeSize}}findDiffStart(e,n=0){return _p(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Hp(this,e,n,r)}findIndex(e){if(e==0)return qo(0,e);if(e==this.size)return qo(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),o=r+i.nodeSize;if(o>=e)return o==e?qo(n+1,o):qo(n,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return t.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return t.fromArray(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return t.empty;let n,r=0;for(let i=0;i<e.length;i++){let o=e[i];r+=o.nodeSize,i&&o.isText&&e[i-1].sameMarkup(o)?(n||(n=e.slice(0,i)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new t(n||e,r)}static from(e){if(!e)return t.empty;if(e instanceof t)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new t([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};E.empty=new E([],0);var ul={index:0,offset:0};function qo(t,e){return ul.index=t,ul.offset=e,ul}function Jo(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Jo(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Jo(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}var J=class t{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,i));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Jo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);let i=r.create(n.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return t.none;if(e instanceof t)return[e];let n=e.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}};J.none=[];var an=class extends Error{},A=class t{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=qp(this.content,e+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new t(r,this.openStart,this.openEnd)}removeBetween(e,n){return new t(jp(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return t.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new t(E.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new t(e,r,i)}};A.empty=new A(E.empty,0,0);function jp(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:a}=t.findIndex(n);if(i==e||o.isText){if(a!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(jp(o.content,e-i-1,n-i-1)))}function qp(t,e,n,r,i,o){let{index:s,offset:a}=t.findIndex(e),l=t.maybeChild(s);if(a==e||l.isText)return o&&r<=0&&i<=0&&!o.canReplace(s,s,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=qp(l.content,e-a-1,n,s==0?r-1:0,s==t.childCount-1?i-1:0,l);return c&&t.replaceChild(s,l.copy(c))}function F1(t,e,n){if(n.openStart>t.depth)throw new an("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new an("Inconsistent open depths");return Kp(t,e,n,0)}function Kp(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r<t.depth-n.openStart){let s=Kp(t,e,n,r+1);return o.copy(o.content.replaceChild(i,s))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==r&&e.depth==r){let s=t.parent,a=s.content;return Fn(s,a.cut(0,t.parentOffset).append(n.content).append(a.cut(e.parentOffset)))}else{let{start:s,end:a}=z1(n,t);return Fn(o,Jp(t,s,a,e,r))}else return Fn(o,Go(t,e,r))}function Up(t,e){if(!e.type.compatibleContent(t.type))throw new an("Cannot join "+e.type.name+" onto "+t.type.name)}function fl(t,e,n){let r=t.node(n);return Up(r,e.node(n)),r}function Pn(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Ci(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(Pn(t.nodeAfter,r),o++));for(let a=o;a<s;a++)Pn(i.child(a),r);e&&e.depth==n&&e.textOffset&&Pn(e.nodeBefore,r)}function Fn(t,e){if(!t.type.validContent(e))throw new an("Invalid content for node "+t.type.name);return t.copy(e)}function Jp(t,e,n,r,i){let o=t.depth>i&&fl(t,e,i+1),s=r.depth>i&&fl(n,r,i+1),a=[];return Ci(null,t,i,a),o&&s&&e.index(i)==n.index(i)?(Up(o,s),Pn(Fn(o,Jp(t,e,n,r,i+1)),a)):(o&&Pn(Fn(o,Go(t,e,i+1)),a),Ci(e,n,i,a),s&&Pn(Fn(s,Go(n,r,i+1)),a)),Ci(r,null,i,a),new E(a)}function Go(t,e,n){let r=[];if(Ci(null,t,n,r),t.depth>n){let i=fl(t,e,n+1);Pn(Fn(i,Go(t,e,n+1)),r)}return Ci(e,null,n,r),new E(r)}function z1(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(E.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}var Qo=class t{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o<e;o++)i+=r.child(o).nodeSize;return i}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return J.none;if(this.textOffset)return e.child(n).marks;let r=e.maybeChild(n-1),i=e.maybeChild(n);if(!r){let a=r;r=i,i=a}let o=r.marks;for(var s=0;s<o.length;s++)o[s].type.spec.inclusive===!1&&(!i||!o[s].isInSet(i.marks))&&(o=o[s--].removeFromSet(o));return o}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let r=n.marks,i=e.parent.maybeChild(e.index());for(var o=0;o<r.length;o++)r[o].type.spec.inclusive===!1&&(!i||!r[o].isInSet(i.marks))&&(r=r[o--].removeFromSet(r));return r}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Ei(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:a,offset:l}=s.content.findIndex(o),c=o-l;if(r.push(s,a,i+l),!c||(s=s.child(a),s.isText))break;o=c-1,i+=l+1}return new t(n,r,o)}static resolveCached(e,n){let r=Rp.get(e);if(r)for(let o=0;o<r.elts.length;o++){let s=r.elts[o];if(s.pos==n)return s}else Rp.set(e,r=new dl);let i=r.elts[r.i]=t.resolve(e,n);return r.i=(r.i+1)%$1,i}},dl=class{constructor(){this.elts=[],this.i=0}},$1=12,Rp=new WeakMap,Ei=class{constructor(e,n,r){this.$from=e,this.$to=n,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},_1=Object.create(null),He=class t{constructor(e,n,r,i=J.none){this.type=e,this.attrs=n,this.marks=i,this.content=r||E.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,r,i=0){this.content.nodesBetween(e,n,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,r,i){return this.content.textBetween(e,n,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,r){return this.type==e&&Jo(this.attrs,n||e.defaultAttrs||_1)&&J.sameSet(this.marks,r||J.none)}copy(e=null){return e==this.content?this:new t(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new t(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,r=!1){if(e==n)return A.empty;let i=this.resolve(e),o=this.resolve(n),s=r?0:i.sharedDepth(n),a=i.start(s),c=i.node(s).content.cut(i.pos-a,o.pos-a);return new A(c,i.depth-s,o.depth-s)}replace(e,n,r){return F1(this.resolve(e),this.resolve(n),r)}nodeAt(e){for(let n=this;;){let{index:r,offset:i}=n.content.findIndex(e);if(n=n.maybeChild(r),!n)return null;if(i==e||n.isText)return n;e-=i+1}}childAfter(e){let{index:n,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(n),index:n,offset:r};let i=this.content.child(n-1);return{node:i,index:n-1,offset:r-i.nodeSize}}resolve(e){return Qo.resolveCached(this,e)}resolveNoCache(e){return Qo.resolve(this,e)}rangeHasMark(e,n,r){let i=!1;return n>e&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Gp(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=E.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),a=s&&s.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let l=i;l<o;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,n,r,i){if(i&&!this.type.allowsMarks(i))return!1;let o=this.contentMatchAt(e).matchType(r),s=o&&o.matchFragment(this.content,n);return s?s.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=J.none;for(let n=0;n<this.marks.length;n++){let r=this.marks[n];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!J.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=E.fromJSON(e,n.content),o=e.nodeType(n.type).create(n.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};He.prototype.text=void 0;var pl=class t extends He{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Gp(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new t(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new t(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Gp(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}var zn=class t{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new hl(e,n);if(r.next==null)return t.empty;let i=Qp(r);r.next&&r.err("Unexpected trailing text");let o=U1(K1(i));return J1(o,r),o}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,r=e.childCount){let i=this;for(let o=n;i&&o<r;o++)i=i.matchType(e.child(o).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let r=0;r<e.next.length;r++)if(this.next[n].type==e.next[r].type)return!0;return!1}fillBefore(e,n=!1,r=0){let i=[this];function o(s,a){let l=s.matchFragment(e,r);if(l&&(!n||l.validEnd))return E.from(a.map(c=>c.createAndFill()));for(let c=0;c<s.next.length;c++){let{type:u,next:f}=s.next[c];if(!(u.isText||u.hasRequiredAttrs())&&i.indexOf(f)==-1){i.push(f);let d=o(f,a.concat(u));if(d)return d}}return null}return o(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),o=i.match;if(o.matchType(e)){let s=[];for(let a=i;a.type;a=a.via)s.push(a.type);return s.reverse()}for(let s=0;s<o.next.length;s++){let{type:a,next:l}=o.next[s];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in n)&&(!i.type||l.validEnd)&&(r.push({match:a.contentMatch,type:a,via:i}),n[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&n(r.next[i].next)}return n(this),e.map((r,i)=>{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s<r.next.length;s++)o+=(s?", ":"")+r.next[s].type.name+"->"+e.indexOf(r.next[s].next);return o}).join(` -`)}};zn.empty=new zn(!0);var hl=class{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Qp(t){let e=[];do e.push(H1(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function H1(t){let e=[];do e.push(V1(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function V1(t){let e=q1(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=W1(t,e);else break;return e}function Op(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function W1(t,e){let n=Op(t),r=n;return t.eat(",")&&(t.next!="}"?r=Op(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function j1(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function q1(t){if(t.eat("(")){let e=Qp(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=j1(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function K1(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,a,l){let c={term:l,to:a};return e[s].push(c),c}function i(s,a){s.forEach(l=>l.to=a)}function o(s,a){if(s.type=="choice")return s.exprs.reduce((l,c)=>l.concat(o(c,a)),[]);if(s.type=="seq")for(let l=0;;l++){let c=o(s.exprs[l],a);if(l==s.exprs.length-1)return c;i(c,a=n())}else if(s.type=="star"){let l=n();return r(a,l),i(o(s.expr,l),l),[r(l)]}else if(s.type=="plus"){let l=n();return i(o(s.expr,a),l),i(o(s.expr,l),l),[r(l)]}else{if(s.type=="opt")return[r(a)].concat(o(s.expr,a));if(s.type=="range"){let l=a;for(let c=0;c<s.min;c++){let u=n();i(o(s.expr,l),u),l=u}if(s.max==-1)i(o(s.expr,l),l);else for(let c=s.min;c<s.max;c++){let u=n();r(l,u),i(o(s.expr,l),u),l=u}return[r(l)]}else{if(s.type=="name")return[r(a,void 0,s.value)];throw new Error("Unknown expr type")}}}}function Yp(t,e){return e-t}function Dp(t,e){let n=[];return r(e),n.sort(Yp);function r(i){let o=t[i];if(o.length==1&&!o[0].term)return r(o[0].to);n.push(i);for(let s=0;s<o.length;s++){let{term:a,to:l}=o[s];!a&&n.indexOf(l)==-1&&r(l)}}}function U1(t){let e=Object.create(null);return n(Dp(t,0));function n(r){let i=[];r.forEach(s=>{t[s].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let u=0;u<i.length;u++)i[u][0]==a&&(c=i[u][1]);Dp(t,l).forEach(u=>{c||i.push([a,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let o=e[r.join(",")]=new zn(r.indexOf(t.length-1)>-1);for(let s=0;s<i.length;s++){let a=i[s][1].sort(Yp);o.next.push({type:i[s][0],next:e[a.join(",")]||n(a)})}return o}}function J1(t,e){for(let n=0,r=[t];n<r.length;n++){let i=r[n],o=!i.validEnd,s=[];for(let a=0;a<i.next.length;a++){let{type:l,next:c}=i.next[a];s.push(l.name),o&&!(l.isText||l.hasRequiredAttrs())&&(o=!1),r.indexOf(c)==-1&&r.push(c)}o&&e.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Xp(t){let e=Object.create(null);for(let n in t){let r=t[n];if(!r.hasDefault)return null;e[n]=r.default}return e}function Zp(t,e){let n=Object.create(null);for(let r in t){let i=e&&e[r];if(i===void 0){let o=t[r];if(o.hasDefault)i=o.default;else throw new RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function eh(t,e,n,r){for(let i in e)if(!(i in t))throw new RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let i in t)t[i].validate&&t[i].validate(e[i])}function th(t,e){let n=Object.create(null);if(e)for(let r in e)n[r]=new ml(t,r,e[r]);return n}var Ti=class t{constructor(e,n,r){this.name=e,this.schema=n,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=th(e,r.attrs),this.defaultAttrs=Xp(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==zn.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Zp(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new He(this,this.computeAttrs(e),E.from(n),J.setFrom(r))}createChecked(e=null,n,r){return n=E.from(n),this.checkContent(n),new He(this,this.computeAttrs(e),n,J.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=E.from(n),n.size){let s=this.contentMatch.fillBefore(n);if(!s)return null;n=s.append(n)}let i=this.contentMatch.matchFragment(n),o=i&&i.fillBefore(E.empty,!0);return o?new He(this,e,n.append(o),J.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){eh(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?n&&n.push(e[r]):n||(n=e.slice(0,r));return n?n.length?n:J.none:e}static compile(e,n){let r=Object.create(null);e.forEach((o,s)=>r[o]=new t(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function G1(t,e,n){let r=n.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${o}`)}}var ml=class{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?G1(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}},vi=class t{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=th(e,i.attrs),this.excluded=null;let o=Xp(this.attrs);this.instance=o?new J(this,o):null}create(e=null){return!e&&this.instance?this.instance:new J(this,Zp(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new t(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}checkAttrs(e){eh(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},Yo=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=cl.from(e.nodes),n.marks=cl.from(e.marks||{}),this.nodes=Ti.compile(this.spec.nodes,this),this.marks=vi.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",a=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=zn.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=a=="_"?null:a?Bp(this,a.split(" ")):a==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Bp(this,s.split(" "))}this.nodeFromJSON=i=>He.fromJSON(this,i),this.markFromJSON=i=>J.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ti){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new pl(r,r.defaultAttrs,e,J.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}};function Bp(t,e){let n=[];for(let r=0;r<e.length;r++){let i=e[r],o=t.marks[i],s=o;if(o)n.push(o);else for(let a in t.marks){let l=t.marks[a];(i=="_"||l.spec.group&&l.spec.group.split(" ").indexOf(i)>-1)&&n.push(s=l)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function Q1(t){return t.tag!=null}function Y1(t){return t.style!=null}var ln=class t{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(Q1(i))this.tags.push(i);else if(Y1(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,n={}){let r=new Xo(this,n,!1);return r.addAll(e,J.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Xo(this,n,!0);return r.addAll(e,J.none,n.from,n.to),A.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let o=this.tags[i];if(eS(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let s=o.getAttrs(e);if(s===!1)continue;o.attrs=s||void 0}return o}}}matchStyle(e,n,r,i){for(let o=i?this.styles.indexOf(i)+1:0;o<this.styles.length;o++){let s=this.styles[o],a=s.style;if(!(a.indexOf(e)!=0||s.context&&!r.matchesContext(s.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(s.getAttrs){let l=s.getAttrs(n);if(l===!1)continue;s.attrs=l||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s<n.length;s++){let a=n[s];if((a.priority==null?50:a.priority)<o)break}n.splice(s,0,i)}for(let i in e.marks){let o=e.marks[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Pp(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Pp(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new t(e,t.schemaRules(e)))}},nh={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},X1={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},rh={ol:!0,ul:!0},Ii=1,gl=2,Mi=4;function Lp(t,e,n){return e!=null?(e?Ii:0)|(e==="full"?gl:0):t&&t.whitespace=="pre"?Ii|gl:n&~Mi}var xr=class{constructor(e,n,r,i,o,s){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=J.none,this.match=o||(s&Mi?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(E.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ii)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=E.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(E.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!nh.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Xo=class{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,o,s=Lp(null,n.preserveWhitespace,0)|(r?Mi:0);i?o=new xr(i.type,i.attrs,J.none,!0,n.topMatch||i.type.contentMatch,s):r?o=new xr(null,null,J.none,!0,null,s):o=new xr(e.schema.topNodeType,null,J.none,!0,null,s),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,o=i.options&gl?"full":this.localPreserveWS||(i.options&Ii)>0,{schema:s}=this.parser;if(o==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)if(o==="full")r=r.replace(/\r\n?/g,` -`);else if(s.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(s.linebreakReplacement.create())){let a=r.split(/\r?\n|\r/);for(let l=0;l<a.length;l++)l&&this.insertNode(s.linebreakReplacement.create(),n,!0),a[l]&&this.insertNode(s.text(a[l]),n,!/\S/.test(a[l]));r=""}else r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let a=i.content[i.content.length-1],l=e.previousSibling;(!a||l&&l.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(r=r.slice(1))}r&&this.insertNode(s.text(r),n,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,n,r){let i=this.localPreserveWS,o=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),a;rh.hasOwnProperty(s)&&this.parser.normalizeLists&&Z1(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:X1.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,n);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let c,u=this.needsBlock;if(nh.hasOwnProperty(s))o.content.length&&o.content[0].isInline&&this.open&&(this.open--,o=this.top),c=!0,o.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);break e}let f=l&&l.skip?n:this.readStyles(e,n);f&&this.addAll(e,f),c&&this.sync(o),this.needsBlock=u}else{let c=this.readStyles(e,n);c&&this.addElementByRule(e,l,c,l.consuming===!1?a:void 0)}this.localPreserveWS=i}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let r=e.style;if(r&&r.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let o=this.parser.matchedStyles[i],s=r.getPropertyValue(o);if(s)for(let a=void 0;;){let l=this.parser.matchStyle(o,s,this,a);if(!l)break;if(l.ignore)return null;if(l.clearMark?n=n.filter(c=>!l.clearMark(c)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return n}addElementByRule(e,n,r,i){let o,s;if(n.node)if(s=this.parser.schema.nodes[n.node],s.isLeaf)this.insertNode(s.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(s,n.attrs||null,r,n.preserveWhitespace);l&&(o=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let a=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}o&&this.sync(a)&&this.open--}addAll(e,n,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,a=i==null?null:e.childNodes[i];s!=a;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,n);this.findAtPoint(e,o)}findPlace(e,n,r){let i,o;for(let s=this.open,a=0;s>=0;s--){let l=this.nodes[s],c=l.findWrapping(e);if(c&&(!i||i.length>c.length+a)&&(i=c,o=l,!c.length))break;if(l.solid){if(r)break;a+=2}}if(!i)return null;this.sync(o);for(let s=0;s<i.length;s++)n=this.enterInner(i[s],null,n,!1);return n}insertNode(e,n,r){if(e.isInline&&this.needsBlock&&!this.top.type){let o=this.textblockFromContext();o&&(n=this.enterInner(o,null,n))}let i=this.findPlace(e,n,r);if(i){this.closeExtra();let o=this.top;o.match&&(o.match=o.match.matchType(e.type));let s=J.none;for(let a of i.concat(e.marks))(o.type?o.type.allowsMarkType(a.type):Fp(a.type,e.type))&&(s=a.addToSet(s));return o.content.push(e.mark(s)),!0}return!1}enter(e,n,r,i){let o=this.findPlace(e.create(n),r,!1);return o&&(o=this.enterInner(e,n,r,!0,i)),o}enterInner(e,n,r,i=!1,o){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let a=Lp(e,o,s.options);s.options&Mi&&s.content.length==0&&(a|=Mi);let l=J.none;return r=r.filter(c=>(s.type?s.type.allowsMarkType(c.type):Fp(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new xr(e,n,l,i,null,a)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=Ii)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(a,l)=>{for(;a>=0;a--){let c=n[a];if(c==""){if(a==n.length-1||a==0)continue;for(;l>=o;l--)if(s(a-1,l))return!0;return!1}else{let u=l>0||l==0&&i?this.nodes[l].type:r&&l>=o?r.node(l-o).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;l--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}};function Z1(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&rh.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function eS(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Pp(t){let e={};for(let n in t)e[n]=t[n];return e}function Fp(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=a=>{o.push(a);for(let l=0;l<a.edgeCount;l++){let{type:c,next:u}=a.edge(l);if(c==e||o.indexOf(u)<0&&s(u))return!0}};if(s(i.contentMatch))return!0}}var cn=class t{constructor(e,n){this.nodes=e,this.marks=n}serializeFragment(e,n={},r){r||(r=Ko(n).createDocumentFragment());let i=r,o=[];return e.forEach(s=>{if(o.length||s.marks.length){let a=0,l=0;for(;a<o.length&&l<s.marks.length;){let c=s.marks[l];if(!this.marks[c.type.name]){l++;continue}if(!c.eq(o[a][0])||c.type.spec.spanning===!1)break;a++,l++}for(;a<o.length;)i=o.pop()[1];for(;l<s.marks.length;){let c=s.marks[l++],u=this.serializeMark(c,s.isInline,n);u&&(o.push([c,i]),i.appendChild(u.dom),i=u.contentDOM||u.dom)}}i.appendChild(this.serializeNodeInner(s,n))}),r}serializeNodeInner(e,n){if(e.isText)return Ko(n).createTextNode(e.text);let{dom:r,contentDOM:i}=Uo(Ko(n),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,n,i)}return r}serializeNode(e,n={}){let r=this.serializeNodeInner(e,n);for(let i=e.marks.length-1;i>=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Uo(Ko(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return typeof n=="string"?{dom:e.createTextNode(n)}:Uo(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new t(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=zp(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return zp(e.marks)}};function zp(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Ko(t){return t.document||window.document}var $p=new WeakMap;function tS(t){let e=$p.get(t);return e===void 0&&$p.set(t,e=nS(t)),e}function nS(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i<r.length;i++)n(r[i]);else for(let i in r)n(r[i])}return n(t),e}function Uo(t,e,n,r){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let i=e[0],o;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(o=tS(r))&&o.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let a,l=n?t.createElementNS(n,i):t.createElement(i),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let f in c)if(c[f]!=null){let d=f.indexOf(" ");d>0?l.setAttributeNS(f.slice(0,d),f.slice(d+1),c[f]):f=="style"&&l.style?l.style.cssText=c[f]:l.setAttribute(f,c[f])}}for(let f=u;f<e.length;f++){let d=e[f];if(d===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else if(typeof d=="string")l.appendChild(t.createTextNode(d));else{let{dom:p,contentDOM:h}=Uo(t,d,n,r);if(l.appendChild(p),h){if(a)throw new RangeError("Multiple content holes");a=h}}}return{dom:l,contentDOM:a}}var sh=65535,ah=Math.pow(2,16);function rS(t,e){return t+e*ah}function ih(t){return t&sh}function iS(t){return(t-(t&sh))/ah}var lh=1,ch=2,Zo=4,uh=8,Ri=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&uh)>0}get deletedBefore(){return(this.delInfo&(lh|Zo))>0}get deletedAfter(){return(this.delInfo&(ch|Zo))>0}get deletedAcross(){return(this.delInfo&Zo)>0}},$t=class t{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&t.empty)return t.empty}recover(e){let n=0,r=ih(e);if(!this.inverted)for(let i=0;i<r;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+n+iS(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let i=0,o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?i:0);if(l>e)break;let c=this.ranges[a+o],u=this.ranges[a+s],f=l+c;if(e<=f){let d=c?e==l?-1:e==f?1:n:n,p=l+i+(d<0?0:u);if(r)return p;let h=e==(n<0?l:f)?null:rS(a/3,e-l),m=e==l?ch:e==f?lh:Zo;return(n<0?e!=l:e!=f)&&(m|=uh),new Ri(p,m,h)}i+=u-c}return r?e+i:new Ri(e+i,0,null)}touches(e,n){let r=0,i=ih(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?r:0);if(l>e)break;let c=this.ranges[a+o],u=l+c;if(e<=u&&a==i*3)return!0;r+=this.ranges[a+s]-c}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let s=this.ranges[i],a=s-(this.inverted?o:0),l=s+(this.inverted?0:o),c=this.ranges[i+n],u=this.ranges[i+r];e(a,a+c,l,l+u),o+=u-c}}invert(){return new t(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?t.empty:new t(e<0?[0,-e,0]:[0,0,e])}};$t.empty=new $t([]);var xl=class t{constructor(e,n,r=0,i=e?e.length:0){this.mirror=n,this.from=r,this.to=i,this._maps=e||[],this.ownData=!(e||n)}get maps(){return this._maps}slice(e=0,n=this.maps.length){return new t(this._maps,this.mirror,e,n)}appendMap(e,n){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),n!=null&&this.setMirror(this._maps.length-1,n)}appendMapping(e){for(let n=0,r=this._maps.length;n<e._maps.length;n++){let i=e.getMirror(n);this.appendMap(e._maps[n],i!=null&&i<n?r+i:void 0)}}getMirror(e){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==e)return this.mirror[n+(n%2?-1:1)]}}setMirror(e,n){this.mirror||(this.mirror=[]),this.mirror.push(e,n)}appendMappingInverted(e){for(let n=e.maps.length-1,r=this._maps.length+e._maps.length;n>=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new t;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;r<this.to;r++)e=this._maps[r].map(e,n);return e}mapResult(e,n=1){return this._map(e,n,!1)}_map(e,n,r){let i=0;for(let o=this.from;o<this.to;o++){let s=this._maps[o],a=s.mapResult(e,n);if(a.recover!=null){let l=this.getMirror(o);if(l!=null&&l>o&&l<this.to){o=l,e=this._maps[l].recover(a.recover);continue}}i|=a.delInfo,e=a.pos}return r?e:new Ri(e,i,null)}},yl=Object.create(null),xe=class{getMap(){return $t.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=yl[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in yl)throw new RangeError("Duplicate use of step JSON ID "+e);return yl[e]=n,n.prototype.jsonID=e,n}},Ee=class t{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new t(e,null)}static fail(e){return new t(null,e)}static fromReplace(e,n,r,i){try{return t.ok(e.replace(n,r,i))}catch(o){if(o instanceof an)return t.fail(o.message);throw o}}};function Cl(t,e,n){let r=[];for(let i=0;i<t.childCount;i++){let o=t.child(i);o.content.size&&(o=o.copy(Cl(o.content,e,o))),o.isInline&&(o=e(o,n,i)),r.push(o)}return E.fromArray(r)}var $n=class t extends xe{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),o=new A(Cl(n.content,(s,a)=>!s.isAtom||!a.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Ee.fromReplace(e,this.from,this.to,o)}invert(){return new _n(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};xe.jsonID("addMark",$n);var _n=class t extends xe{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new A(Cl(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Ee.fromReplace(e,this.from,this.to,r)}invert(){return new $n(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};xe.jsonID("removeMark",_n);var Oi=class t extends xe{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Ee.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Ee.fromReplace(e,this.pos,this.pos+1,new A(E.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(r))return new t(this.pos,n.marks[i]);return new t(this.pos,this.mark)}}return new wr(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new t(n.pos,e.markFromJSON(n.mark))}};xe.jsonID("addNodeMark",Oi);var wr=class t extends xe{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Ee.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Ee.fromReplace(e,this.pos,this.pos+1,new A(E.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Oi(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new t(n.pos,e.markFromJSON(n.mark))}};xe.jsonID("removeNodeMark",wr);var de=class t extends xe{constructor(e,n,r,i=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=i}apply(e){return this.structure&&wl(e,this.from,this.to)?Ee.fail("Structure replace would overwrite content"):Ee.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new $t([this.from,this.to-this.from,this.slice.size])}invert(e){return new t(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.to,-1),r=this.from==this.to&&t.MAP_BIAS<0?n:e.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new t(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof t)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?A.empty:new A(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new t(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?A.empty:new A(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new t(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new t(n.from,n.to,A.fromJSON(e,n.slice),!!n.structure)}};de.MAP_BIAS=1;xe.jsonID("replace",de);var Te=class t extends xe{constructor(e,n,r,i,o,s,a=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=s,this.structure=a}apply(e){if(this.structure&&(wl(e,this.from,this.gapFrom)||wl(e,this.gapTo,this.to)))return Ee.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Ee.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Ee.fromReplace(e,this.from,this.to,r):Ee.fail("Content does not fit in gap")}getMap(){return new $t([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new t(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),o=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||o>r.pos?null:new t(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new t(n.from,n.to,n.gapFrom,n.gapTo,A.fromJSON(e,n.slice),n.insert,!!n.structure)}};xe.jsonID("replaceAround",Te);function wl(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function oS(t,e,n,r){let i=[],o=[],s,a;t.doc.nodesBetween(e,n,(l,c,u)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+l.nodeSize,n),h=r.addToSet(f);for(let m=0;m<f.length;m++)f[m].isInSet(h)||(s&&s.to==d&&s.mark.eq(f[m])?s.to=p:i.push(s=new _n(d,p,f[m])));a&&a.to==d?a.to=p:o.push(a=new $n(d,p,r))}}),i.forEach(l=>t.step(l)),o.forEach(l=>t.step(l))}function sS(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,a)=>{if(!s.isInline)return;o++;let l=null;if(r instanceof vi){let c=s.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(s.marks)&&(l=[r]):l=s.marks;if(l&&l.length){let c=Math.min(a+s.nodeSize,n);for(let u=0;u<l.length;u++){let f=l[u],d;for(let p=0;p<i.length;p++){let h=i[p];h.step==o-1&&f.eq(i[p].style)&&(d=h)}d?(d.to=c,d.step=o):i.push({style:f,from:Math.max(a,e),to:c,step:o})}}}),i.forEach(s=>t.step(new _n(s.from,s.to,s.style)))}function Ml(t,e,n,r=n.contentMatch,i=!0){let o=t.doc.nodeAt(e),s=[],a=e+1;for(let l=0;l<o.childCount;l++){let c=o.child(l),u=a+c.nodeSize,f=r.matchType(c.type);if(!f)s.push(new de(a,u,A.empty));else{r=f;for(let d=0;d<c.marks.length;d++)n.allowsMarkType(c.marks[d].type)||t.step(new _n(a,u,c.marks[d]));if(i&&c.isText&&n.whitespace!="pre"){let d,p=/\r?\n|\r/g,h;for(;d=p.exec(c.text);)h||(h=new A(E.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),s.push(new de(a+d.index,a+d.index+d[0].length,h))}}a=u}if(!r.validEnd){let l=r.fillBefore(E.empty,!0);t.replace(a,a,new A(l,0,0))}for(let l=s.length-1;l>=0;l--)t.step(s[l])}function aS(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Mr(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,o=0;;--r){let s=t.$from.node(r),a=t.$from.index(r)+i,l=t.$to.indexAfter(r)-o;if(r<t.depth&&s.canReplace(a,l,n))return r;if(r==0||s.type.spec.isolating||!aS(s,a,l))break;a&&(i=1),l<s.childCount&&(o=1)}return null}function lS(t,e,n){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),a=i.after(o+1),l=s,c=a,u=E.empty,f=0;for(let h=o,m=!1;h>n;h--)m||r.index(h)>0?(m=!0,u=E.from(r.node(h).copy(u)),f++):l--;let d=E.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)<i.end(h)?(m=!0,d=E.from(i.node(h).copy(d)),p++):c++;t.step(new Te(l,c,s,a,new A(u.append(d),f,p),u.size-f,!0))}function Hn(t,e,n=null,r=t){let i=cS(t,e),o=i&&uS(r,e);return o?i.map(oh).concat({type:e,attrs:n}).concat(o.map(oh)):null}function oh(t){return{type:t,attrs:null}}function cS(t,e){let{parent:n,startIndex:r,endIndex:i}=t,o=n.contentMatchAt(r).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return n.canReplaceWith(r,i,s)?o:null}function uS(t,e){let{parent:n,startIndex:r,endIndex:i}=t,o=n.child(r),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let l=(s.length?s[s.length-1]:e).contentMatch;for(let c=r;l&&c<i;c++)l=l.matchType(n.child(c).type);return!l||!l.validEnd?null:s}function fS(t,e,n){let r=E.empty;for(let s=n.length-1;s>=0;s--){if(r.size){let a=n[s].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=E.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new Te(i,o,i,o,new A(r,0,0),n.length,!0))}function dS(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,a)=>{let l=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,l)&&pS(t.doc,t.mapping.slice(o).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!h?c=!1:!p&&h&&(c=!0)}c===!1&&dh(t,s,a,o),Ml(t,t.mapping.slice(o).map(a,1),r,void 0,c===null);let u=t.mapping.slice(o),f=u.map(a,1),d=u.map(a+s.nodeSize,1);return t.step(new Te(f,d,f+1,d-1,new A(E.from(r.create(l,null,s.marks)),0,0),1,!0)),c===!0&&fh(t,s,a,o),!1}})}function fh(t,e,n,r){e.forEach((i,o)=>{if(i.isText){let s,a=/\r?\n|\r/g;for(;s=a.exec(i.text);){let l=t.mapping.slice(r).map(n+1+o+s.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function dh(t,e,n,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(n+1+o);t.replaceWith(s,s+1,e.type.schema.text(` -`))}})}function pS(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function hS(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Te(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new A(E.from(s),0,0),1,!0))}function Vn(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,u=n-2;c>o;c--,u--){let f=i.node(c),d=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[u+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=r&&r[u]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(p))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function mS(t,e,n=1,r){let i=t.doc.resolve(e),o=E.empty,s=E.empty;for(let a=i.depth,l=i.depth-n,c=n-1;a>l;a--,c--){o=E.from(i.node(a).copy(o));let u=r&&r[c];s=E.from(u?u.type.create(u.attrs,s):i.node(a).copy(s))}t.step(new de(e,e,new A(o.append(s),n,n),!0))}function Wn(t,e){let n=t.resolve(e),r=n.index();return yS(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function gS(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i<e.childCount;i++){let o=e.child(i),s=o.type==r?t.type.schema.nodes.text:o.type;if(n=n.matchType(s),!n||!t.type.allowsMarks(o.marks))return!1}return n.validEnd}function yS(t,e){return!!(t&&e&&!t.isLeaf&&gS(t,e))}function kS(t,e,n){let r=null,{linebreakReplacement:i}=t.doc.type.schema,o=t.doc.resolve(e-n),s=o.node().type;if(i&&s.inlineContent){let u=s.whitespace=="pre",f=!!s.contentMatch.matchType(i);u&&!f?r=!1:!u&&f&&(r=!0)}let a=t.steps.length;if(r===!1){let u=t.doc.resolve(e+n);dh(t,u.node(),u.before(),a)}s.inlineContent&&Ml(t,e+n-1,s,o.node().contentMatchAt(o.index()),r==null);let l=t.mapping.slice(a),c=l.map(e-n);if(t.step(new de(c,l.map(e+n,-1),A.empty,!0)),r===!0){let u=t.doc.resolve(c);fh(t,u.node(),u.before(),t.steps.length)}return t}function bS(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o<r.node(i).childCount)return null}return null}function ph(t,e,n){let r=t.resolve(e);if(!n.content.size)return e;let i=n.content;for(let o=0;o<n.openStart;o++)i=i.firstChild.content;for(let o=1;o<=(n.openStart==0&&n.size?2:1);o++)for(let s=r.depth;s>=0;s--){let a=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,l=r.index(s)+(a>0?1:0),c=r.node(s),u=!1;if(o==1)u=c.canReplace(l,l,i);else{let f=c.contentMatchAt(l).findWrapping(i.firstChild.type);u=f&&c.canReplaceWith(l,l,f[0])}if(u)return a==0?r.pos:a<0?r.before(s+1):r.after(s+1)}return null}function Di(t,e,n=e,r=A.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return hh(i,o,r)?new de(e,n,r):new Sl(i,o,r).fit()}function hh(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}var Sl=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=E.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=E.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,a=i.depth;for(;s&&a&&o.childCount==1;)o=o.firstChild.content,s--,a--;let l=new A(o,s,a);return e>-1?new Te(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new de(r.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r<e;r++){let o=n.firstChild;if(n.childCount>1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=kl(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],u,f=null;if(n==1&&(s?c.matchType(s.type)||(f=c.fillBefore(E.from(s),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:a,parent:o,inject:f};if(n==2&&s&&(u=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:a,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=kl(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new A(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=kl(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new A(Ai(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new A(Ai(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m<o.length;m++)this.openFrontierNode(o[m]);let s=this.unplaced,a=r?r.content:s.content,l=s.openStart-e,c=0,u=[],{match:f,type:d}=this.frontier[n];if(i){for(let m=0;m<i.childCount;m++)u.push(i.child(m));f=f.matchFragment(i)}let p=a.size+e-(s.content.size-s.openEnd);for(;c<a.childCount;){let m=a.child(c),g=f.matchType(m.type);if(!g)break;c++,(c>1||l==0||m.content.size)&&(f=g,u.push(mh(m.mark(d.allowedMarks(m.marks)),c==1?l:0,c==a.childCount?p:-1)))}let h=c==a.childCount;h||(p=-1),this.placed=Ni(this.placed,n,E.from(u)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=a;m<p;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=h?e==0?A.empty:new A(Ai(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new A(Ai(s.content,e,c),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],n;if(!e.type.isTextblock||!bl(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(n=this.findCloseLevel(this.$to))&&n.depth==this.depth)return-1;let{depth:r}=this.$to,i=this.$to.after(r);for(;r>1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n<e.depth&&e.end(n+1)==e.pos+(e.depth-(n+1)),s=bl(e,n,i,r,o);if(s){for(let a=n-1;a>=0;a--){let{match:l,type:c}=this.frontier[a],u=bl(e,a,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Ni(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ni(this.placed,this.depth,E.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(E.empty,!0);n.childCount&&(this.placed=Ni(this.placed,this.frontier.length,n))}};function Ai(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Ai(t.firstChild.content,e-1,n)))}function Ni(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Ni(t.lastChild.content,e-1,n)))}function kl(t,e){for(let n=0;n<e;n++)t=t.firstChild.content;return t}function mh(t,e,n){if(e<=0)return t;let r=t.content;return e>1&&(r=r.replaceChild(0,mh(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(E.empty,!0)))),t.copy(r)}function bl(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!xS(n,o.content,s)?a:null}function xS(t,e,n){for(let r=n;r<e.childCount;r++)if(!t.allowsMarks(e.child(r).marks))return!0;return!1}function wS(t){return t.spec.defining||t.spec.definingForContent}function SS(t,e,n,r){if(!r.size)return t.deleteRange(e,n);let i=t.doc.resolve(e),o=t.doc.resolve(n);if(hh(i,o,r))return t.step(new de(e,n,r));let s=yh(i,o);s[s.length-1]==0&&s.pop();let a=-(i.depth+1);s.unshift(a);for(let d=i.depth,p=i.pos-1;d>0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?a=d:i.before(d)==p&&s.splice(1,0,-d)}let l=s.indexOf(a),c=[],u=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(c.push(h),p==r.openStart)break;d=h.content}for(let d=u-1;d>=0;d--){let p=c[d],h=wS(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(a)-1)))u=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+u+1)%(r.openStart+1),h=c[p];if(h)for(let m=0;m<s.length;m++){let g=s[(m+l)%s.length],y=!0;g<0&&(y=!1,g=-g);let x=i.node(g-1),C=i.index(g-1);if(x.canReplaceWith(C,C,h.type,h.marks))return t.replace(i.before(g),y?o.after(g):n,new A(gh(r.content,0,r.openStart,p),p,r.openEnd))}}let f=t.steps.length;for(let d=s.length-1;d>=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function gh(t,e,n,r,i){if(e<n){let o=t.firstChild;t=t.replaceChild(0,o.copy(gh(o.content,e+1,n,r,o)))}if(e>r){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(E.empty,!0))}return t}function CS(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=bS(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new A(E.from(r),0,0))}function MS(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let s=r.sharedDepth(n),a=!1;for(let l=r.depth;l>s;l--)r.node(l).type.spec.isolating&&(a=!0);for(let l=i.depth;l>s;l--)i.node(l).type.spec.isolating&&(a=!0);if(!a){for(let l=r.depth;l>0&&e==r.start(l);l--)e=r.before(l);for(let l=i.depth;l>0&&n==i.start(l);l--)n=i.before(l);r=t.doc.resolve(e),i=t.doc.resolve(n)}}let o=yh(r,i);for(let s=0;s<o.length;s++){let a=o[s],l=s==o.length-1;if(l&&a==0||r.node(a).type.contentMatch.validEnd)return t.delete(r.start(a),i.end(a));if(a>0&&(l||r.node(a-1).canReplace(r.index(a-1),i.indexAfter(a-1))))return t.delete(r.before(a),i.after(a))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return t.delete(r.before(s),n);t.delete(e,n)}function yh(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(o<t.pos-(t.depth-i)||e.end(i)>e.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}var es=class t extends xe{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Ee.fromReplace(e,this.pos,this.pos+1,new A(E.from(i),0,n.isLeaf?0:1))}getMap(){return $t.empty}invert(e){return new t(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new t(n.pos,n.attr,n.value)}};xe.jsonID("attr",es);var ts=class t extends xe{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Ee.ok(r)}getMap(){return $t.empty}invert(e){return new t(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new t(n.attr,n.value)}};xe.jsonID("docAttr",ts);var Sr=class extends Error{};Sr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Sr.prototype=Object.create(Error.prototype);Sr.prototype.constructor=Sr;Sr.prototype.name="TransformError";var Cr=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new xl}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Sr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r<this.mapping.maps.length;r++){let i=this.mapping.maps[r];r&&(e=i.map(e,1),n=i.map(n,-1)),i.forEach((o,s,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=A.empty){let i=Di(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new A(E.from(r),0,0))}delete(e,n){return this.replace(e,n,A.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return SS(this,e,n,r),this}replaceRangeWith(e,n,r){return CS(this,e,n,r),this}deleteRange(e,n){return MS(this,e,n),this}lift(e,n){return lS(this,e,n),this}join(e,n=1){return kS(this,e,n),this}wrap(e,n){return fS(this,e,n),this}setBlockType(e,n=e,r,i=null){return dS(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return hS(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new es(e,n,r)),this}setDocAttribute(e,n){return this.step(new ts(e,n)),this}addNodeMark(e,n){return this.step(new Oi(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof J)n.isInSet(r.marks)&&this.step(new wr(e,n));else{let i=r.marks,o,s=[];for(;o=n.isInSet(i);)s.push(new wr(e,o)),i=o.removeFromSet(i);for(let a=s.length-1;a>=0;a--)this.step(s[a])}return this}split(e,n=1,r){return mS(this,e,n,r),this}addMark(e,n,r){return oS(this,e,n,r),this}removeMark(e,n,r){return sS(this,e,n,r),this}clearIncompatible(e,n,r){return Ml(this,e,n,r),this}};var El=Object.create(null),$=class{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new un(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=A.empty){let r=n.content.lastChild,i=null;for(let a=0;a<n.openEnd;a++)i=r,r=r.lastChild;let o=e.steps.length,s=this.ranges;for(let a=0;a<s.length;a++){let{$from:l,$to:c}=s[a],u=e.mapping.slice(o);e.replaceRange(u.map(l.pos),u.map(c.pos),a?A.empty:n),a==0&&xh(e,o,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:s,$to:a}=i[o],l=e.mapping.slice(r),c=l.map(s.pos),u=l.map(a.pos);o?e.deleteRange(c,u):(e.replaceRangeWith(c,u,n),xh(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let i=e.parent.inlineContent?new z(e):Er(e.node(0),e.parent,e.pos,e.index(),n,r);if(i)return i;for(let o=e.depth-1;o>=0;o--){let s=n<0?Er(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Er(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new Ke(e.node(0))}static atStart(e){return Er(e,e,0,0,1)||new Ke(e)}static atEnd(e){return Er(e,e,e.content.size,e.childCount,-1)||new Ke(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=El[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in El)throw new RangeError("Duplicate use of selection JSON ID "+e);return El[e]=n,n.prototype.jsonID=e,n}getBookmark(){return z.between(this.$anchor,this.$head).getBookmark()}};$.prototype.visible=!0;var un=class{constructor(e,n){this.$from=e,this.$to=n}},kh=!1;function bh(t){!kh&&!t.parent.inlineContent&&(kh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}var z=class t extends ${constructor(e,n=e){bh(e),bh(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return $.near(r);let i=e.resolve(n.map(this.anchor));return new t(i.parent.inlineContent?i:r,r)}replace(e,n=A.empty){if(super.replace(e,n),n==A.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof t&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new rs(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new t(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=$.findFrom(n,r,!0)||$.findFrom(n,-r,!0);if(o)n=o.$head;else return $.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=($.findFrom(e,-r,!0)||$.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=i<0&&(e=n))),new t(e,n)}};$.jsonID("text",z);var rs=class t{constructor(e,n){this.anchor=e,this.head=n}map(e){return new t(e.map(this.anchor),e.map(this.head))}resolve(e){return z.between(e.resolve(this.anchor),e.resolve(this.head))}},H=class t extends ${constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),o=e.resolve(i);return r?$.near(o):new t(o)}content(){return new A(E.from(this.node),0,0)}eq(e){return e instanceof t&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new vl(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new t(e.resolve(n.anchor))}static create(e,n){return new t(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};H.prototype.visible=!1;$.jsonID("node",H);var vl=class t{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new rs(r,r):new t(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&H.isSelectable(r)?new H(n):$.near(n)}},Ke=class t extends ${constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=A.empty){if(n==A.empty){e.delete(0,e.doc.content.size);let r=$.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new t(e)}map(e){return new t(e)}eq(e){return e instanceof t}getBookmark(){return ES}};$.jsonID("all",Ke);var ES={map(){return this},resolve(t){return new Ke(t)}};function Er(t,e,n,r,i,o=!1){if(e.inlineContent)return z.create(t,n);for(let s=r-(i>0?0:1);i>0?s<e.childCount:s>=0;s+=i){let a=e.child(s);if(a.isAtom){if(!o&&H.isSelectable(a))return H.create(t,n-(i<0?a.nodeSize:0))}else{let l=Er(t,a,n+i,i<0?a.childCount:0,i,o);if(l)return l}n+=a.nodeSize*i}return null}function xh(t,e,n){let r=t.steps.length-1;if(r<e)return;let i=t.steps[r];if(!(i instanceof de||i instanceof Te))return;let o=t.mapping.maps[r],s;o.forEach((a,l,c,u)=>{s==null&&(s=u)}),t.setSelection($.near(t.doc.resolve(s),n))}var wh=1,ns=2,Sh=4,Il=class extends Cr{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|wh)&~ns,this.storedMarks=null,this}get selectionSet(){return(this.updated&wh)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=ns,this}ensureMarks(e){return J.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&ns)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~ns,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||J.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection($.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Sh,this}get scrolledIntoView(){return(this.updated&Sh)>0}};function Ch(t,e){return!e||!t?t:t.bind(e)}var jn=class{constructor(e,n,r){this.name=e,this.init=Ch(n.init,r),this.apply=Ch(n.apply,r)}},TS=[new jn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new jn("selection",{init(t,e){return t.selection||$.atStart(e.doc)},apply(t){return t.selection}}),new jn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new jn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})],Bi=class{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=TS.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new jn(r.key,r.spec.state,r))})}},Tr=class t{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=n){let i=this.config.plugins[r];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let n=[e],r=this.applyInner(e),i=null;for(;;){let o=!1;for(let s=0;s<this.config.plugins.length;s++){let a=this.config.plugins[s];if(a.spec.appendTransaction){let l=i?i[s].n:0,c=i?i[s].state:this,u=l<n.length&&a.spec.appendTransaction.call(a,l?n.slice(l):n,c,r);if(u&&r.filterTransaction(u,s)){if(u.setMeta("appendedTransaction",e),!i){i=[];for(let f=0;f<this.config.plugins.length;f++)i.push(f<s?{state:r,n:n.length}:{state:this,n:0})}n.push(u),r=r.applyInner(u),o=!0}i&&(i[s]={state:r,n:n.length})}}if(!o)return{state:r,transactions:n}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let n=new t(this.config),r=this.config.fields;for(let i=0;i<r.length;i++){let o=r[i];n[o.name]=o.apply(e,this[o.name],this,n)}return n}get tr(){return new Il(this)}static create(e){let n=new Bi(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new t(n);for(let i=0;i<n.fields.length;i++)r[n.fields[i].name]=n.fields[i].init(e,r);return r}reconfigure(e){let n=new Bi(this.schema,e.plugins),r=n.fields,i=new t(n);for(let o=0;o<r.length;o++){let s=r[o].name;i[s]=this.hasOwnProperty(s)?this[s]:r[o].init(e,i)}return i}toJSON(e){let n={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(n.storedMarks=this.storedMarks.map(r=>r.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Bi(e.schema,e.plugins),o=new t(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=He.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=$.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let l=r[a],c=l.spec.state;if(l.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){o[s.name]=c.fromJSON.call(l,e,n[a],o);return}}o[s.name]=s.init(e,o)}}),o}};function Mh(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Mh(i,e,{})),n[r]=i}return n}var X=class{constructor(e){this.spec=e,this.props={},e.props&&Mh(e.props,this,this.props),this.key=e.key?e.key.key:Eh("plugin")}getState(e){return e[this.key]}},Tl=Object.create(null);function Eh(t){return t in Tl?t+"$"+ ++Tl[t]:(Tl[t]=0,t+"$")}var ee=class{constructor(e="key"){this.key=Eh(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var is=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function vh(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}var Nl=(t,e,n)=>{let r=vh(t,n);if(!r)return!1;let i=Ol(r);if(!i){let s=r.blockRange(),a=s&&Mr(s);return a==null?!1:(e&&e(t.tr.lift(s,a).scrollIntoView()),!0)}let o=i.nodeBefore;if(Nh(t,i,e,-1))return!0;if(r.parent.content.size==0&&(vr(o,"end")||H.isSelectable(o)))for(let s=r.depth;;s--){let a=Di(t.doc,r.before(s),r.after(s),A.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=t.tr.step(a);l.setSelection(vr(o,"end")?$.findFrom(l.doc.resolve(l.mapping.map(i.pos,-1)),-1):H.create(l.doc,i.pos-o.nodeSize)),e(l.scrollIntoView())}return!0}if(s==1||r.node(s-1).childCount>1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1},Ih=(t,e,n)=>{let r=vh(t,n);if(!r)return!1;let i=Ol(r);return i?vS(t,i,e):!1};function vS(t,e,n){let r=e.nodeBefore,i=r,o=e.pos-1;for(;!i.isTextblock;o--){if(i.type.spec.isolating)return!1;let u=i.lastChild;if(!u)return!1;i=u}let s=e.nodeAfter,a=s,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let u=a.firstChild;if(!u)return!1;a=u}let c=Di(t.doc,o,l,A.empty);if(!c||c.from!=o||c instanceof de&&c.slice.size>=l-o)return!1;if(n){let u=t.tr.step(c);u.setSelection(z.create(u.doc,o)),n(u.scrollIntoView())}return!0}function vr(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Rl=(t,e,n)=>{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;o=Ol(r)}let s=o&&o.nodeBefore;return!s||!H.isSelectable(s)?!1:(e&&e(t.tr.setSelection(H.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Ol(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function IS(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)?null:n}var AS=(t,e,n)=>{let r=IS(t,n);if(!r)return!1;let i=Ah(r);if(!i)return!1;let o=i.nodeAfter;if(Nh(t,i,e,1))return!0;if(r.parent.content.size==0&&(vr(o,"start")||H.isSelectable(o))){let s=Di(t.doc,r.before(),r.after(),A.empty);if(s&&s.slice.size<s.to-s.from){if(e){let a=t.tr.step(s);a.setSelection(vr(o,"start")?$.findFrom(a.doc.resolve(a.mapping.map(i.pos)),1):H.create(a.doc,a.mapping.map(i.pos))),e(a.scrollIntoView())}return!0}}return o.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos,i.pos+o.nodeSize).scrollIntoView()),!0):!1},NS=(t,e,n)=>{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset<r.parent.content.size)return!1;o=Ah(r)}let s=o&&o.nodeAfter;return!s||!H.isSelectable(s)?!1:(e&&e(t.tr.setSelection(H.create(t.doc,o.pos)).scrollIntoView()),!0)};function Ah(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let n=t.node(e);if(t.index(e)+1<n.childCount)return t.doc.resolve(t.after(e+1));if(n.type.spec.isolating)break}return null}var RS=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` -`).scrollIntoView()),!0)};function Dl(t){for(let e=0;e<t.edgeCount;e++){let{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var OS=(t,e)=>{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=Dl(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let a=n.after(),l=t.tr.replaceWith(a,a,s.createAndFill());l.setSelection($.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},DS=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof Ke||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Dl(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,a=t.tr.insert(s,o.createAndFill());a.setSelection(z.create(a.doc,s+1)),e(a.scrollIntoView())}return!0},BS=(t,e)=>{let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if(Vn(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Mr(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function LS(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof H&&e.selection.node.isBlock)return!r.parentOffset||!Vn(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,a,l=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){l=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),a=Dl(r.node(p-1).contentMatchAt(r.indexAfter(p-1)));let m=t&&t(i.parent,l,r);o.unshift(m||(l&&a?{type:a}:null)),s=p;break}else{if(p==1)return!1;o.unshift(null)}let u=e.tr;(e.selection instanceof z||e.selection instanceof Ke)&&u.deleteSelection();let f=u.mapping.map(r.pos),d=Vn(u.doc,f,o.length,o);if(d||(o[0]=a?{type:a}:null,d=Vn(u.doc,f,o.length,o)),!d)return!1;if(u.split(f,o.length,o),!l&&c&&r.node(s).type!=a){let p=u.mapping.map(r.before(s)),h=u.doc.resolve(p);a&&r.node(s-1).canReplaceWith(h.index(),h.index()+1,a)&&u.setNodeMarkup(u.mapping.map(r.before(s)),a)}return n&&n(u.scrollIntoView()),!0}}var PS=LS();var FS=(t,e)=>(e&&e(t.tr.setSelection(new Ke(t.doc))),!0);function zS(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||Wn(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function Nh(t,e,n,r){let i=e.nodeBefore,o=e.nodeAfter,s,a,l=i.type.spec.isolating||o.type.spec.isolating;if(!l&&zS(t,e,n))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(s=(a=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&a.matchType(s[0]||o.type).validEnd){if(n){let p=e.pos+o.nodeSize,h=E.empty;for(let y=s.length-1;y>=0;y--)h=E.from(s[y].create(null,h));h=E.from(i.copy(h));let m=t.tr.step(new Te(e.pos-1,p,e.pos,p,new A(h,1,0),s.length,!0)),g=m.doc.resolve(p+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Wn(m.doc,g.pos)&&m.join(g.pos),n(m.scrollIntoView())}return!0}let u=o.type.spec.isolating||r>0&&l?null:$.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),d=f&&Mr(f);if(d!=null&&d>=e.depth)return n&&n(t.tr.lift(f,d).scrollIntoView()),!0;if(c&&vr(o,"start",!0)&&vr(i,"end")){let p=i,h=[];for(;h.push(p),!p.isTextblock;)p=p.lastChild;let m=o,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(n){let y=E.empty;for(let C=h.length-1;C>=0;C--)y=E.from(h[C].copy(y));let x=t.tr.step(new Te(e.pos-h.length,e.pos+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new A(y,h.length,0),0,!0));n(x.scrollIntoView())}return!0}}return!1}function Rh(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(n&&n(e.tr.setSelection(z.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}var $S=Rh(-1),_S=Rh(1);function ss(t,e=null){return function(n,r){let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=s&&Hn(s,t,e);return a?(r&&r(n.tr.wrap(s,a).scrollIntoView()),!0):!1}}function Ir(t,e=null){return function(n,r){let i=!1;for(let o=0;o<n.selection.ranges.length&&!i;o++){let{$from:{pos:s},$to:{pos:a}}=n.selection.ranges[o];n.doc.nodesBetween(s,a,(l,c)=>{if(i)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)i=!0;else{let u=n.doc.resolve(c),f=u.index();i=u.parent.canReplaceWith(f,f+1,t)}})}if(!i)return!1;if(r){let o=n.tr;for(let s=0;s<n.selection.ranges.length;s++){let{$from:{pos:a},$to:{pos:l}}=n.selection.ranges[s];o.setBlockType(a,l,t,e)}r(o.scrollIntoView())}return!0}}function HS(t,e,n,r){for(let i=0;i<e.length;i++){let{$from:o,$to:s}=e[i],a=o.depth==0?t.inlineContent&&t.type.allowsMarkType(n):!1;if(t.nodesBetween(o.pos,s.pos,(l,c)=>{if(a||!r&&l.isAtom&&l.isInline&&c>=o.pos&&c+l.nodeSize<=s.pos)return!1;a=l.inlineContent&&l.type.allowsMarkType(n)}),a)return!0}return!1}function VS(t){let e=[];for(let n=0;n<t.length;n++){let{$from:r,$to:i}=t[n];r.doc.nodesBetween(r.pos,i.pos,(o,s)=>{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new un(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.pos<i.pos&&e.push(new un(r,i))}return e}function Ar(t,e=null,n){let r=(n&&n.removeWhenPresent)!==!1,i=(n&&n.enterInlineAtoms)!==!1,o=!(n&&n.includeWhitespace);return function(s,a){let{empty:l,$cursor:c,ranges:u}=s.selection;if(l&&!c||!HS(s.doc,u,t,i))return!1;if(a)if(c)t.isInSet(s.storedMarks||c.marks())?a(s.tr.removeStoredMark(t)):a(s.tr.addStoredMark(t.create(e)));else{let f,d=s.tr;i||(u=VS(u)),r?f=!u.some(p=>s.doc.rangeHasMark(p.$from.pos,p.$to.pos,t)):f=!u.every(p=>{let h=!1;return d.doc.nodesBetween(p.$from.pos,p.$to.pos,(m,g,y)=>{if(h)return!1;h=!t.isInSet(m.marks)&&!!y&&y.type.allowsMarkType(t)&&!(m.isText&&/^\s*$/.test(m.textBetween(Math.max(0,p.$from.pos-g),Math.min(m.nodeSize,p.$to.pos-g))))}),!h});for(let p=0;p<u.length;p++){let{$from:h,$to:m}=u[p];if(!f)d.removeMark(h.pos,m.pos,t);else{let g=h.pos,y=m.pos,x=h.nodeAfter,C=m.nodeBefore,v=o&&x&&x.isText?/^\s*/.exec(x.text)[0].length:0,I=o&&C&&C.isText?/\s*$/.exec(C.text)[0].length:0;g+v<y&&(g+=v,y-=I),d.addMark(g,y,t.create(e))}}a(d.scrollIntoView())}return!0}}function qn(...t){return function(e,n,r){for(let i=0;i<t.length;i++)if(t[i](e,n,r))return!0;return!1}}var Al=qn(is,Nl,Rl),Th=qn(is,AS,NS),_t={Enter:qn(RS,DS,BS,PS),"Mod-Enter":OS,Backspace:Al,"Mod-Backspace":Al,"Shift-Backspace":Al,Delete:Th,"Mod-Delete":Th,"Mod-a":FS},Oh={"Ctrl-h":_t.Backspace,"Alt-Backspace":_t["Mod-Backspace"],"Ctrl-d":_t.Delete,"Ctrl-Alt-Backspace":_t["Mod-Delete"],"Alt-Delete":_t["Mod-Delete"],"Alt-d":_t["Mod-Delete"],"Ctrl-a":$S,"Ctrl-e":_S};for(let t in _t)Oh[t]=_t[t];var WS=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Dh=WS?Oh:_t;var ke=class{constructor(e,n,r={}){this.match=e,this.match=e,this.handler=typeof n=="string"?jS(n):n,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function jS(t){return function(e,n,r,i){let o=t;if(n[1]){let s=n[0].lastIndexOf(n[1]);o+=n[0].slice(s+n[1].length),r+=s;let a=r-i;a>0&&(o=n[0].slice(s-a,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Bh=(t,e)=>{let n=t.plugins;for(let r=0;r<n.length;r++){let i=n[r],o;if(i.spec.isInputRules&&(o=i.getState(t))){if(e){let s=t.tr,a=o.transform;for(let l=a.steps.length-1;l>=0;l--)s.step(a.steps[l].invert(a.docs[l]));if(o.text){let l=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,t.schema.text(o.text,l))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},iF=new ke(/--$/,"\u2014",{inCodeMark:!1}),oF=new ke(/\.\.\.$/,"\u2026",{inCodeMark:!1}),sF=new ke(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),aF=new ke(/"$/,"\u201D",{inCodeMark:!1}),lF=new ke(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),cF=new ke(/'$/,"\u2019",{inCodeMark:!1});function as(t,e,n=null,r){return new ke(t,(i,o,s,a)=>{let l=n instanceof Function?n(o):n,c=i.tr.delete(s,a),u=c.doc.resolve(s),f=u.blockRange(),d=f&&Hn(f,e,l);if(!d)return null;c.wrap(f,d);let p=c.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Wn(c.doc,s-1)&&(!r||r(o,p))&&c.join(s-1),c})}function Bl(t,e,n=null){return new ke(t,(r,i,o,s)=>{let a=r.doc.resolve(o),l=n instanceof Function?n(i):n;return a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,l):null})}var fn=typeof navigator<"u"?navigator:null,Lh=typeof document<"u"?document:null,dn=fn&&fn.userAgent||"",Pl=/Edge\/(\d+)/.exec(dn),Ph=/MSIE \d/.exec(dn),Fl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(dn),$l=!!(Ph||Fl||Pl),pF=Ph?document.documentMode:Fl?+Fl[1]:Pl?+Pl[1]:0,qS=!$l&&/gecko\/(\d+)/i.test(dn),hF=qS&&+(/Firefox\/(\d+)/.exec(dn)||[0,0])[1],zl=!$l&&/Chrome\/(\d+)/.exec(dn),KS=!!zl,mF=zl?+zl[1]:0,US=!$l&&!!fn&&/Apple Computer/.test(fn.vendor),JS=US&&(/Mobile\/\w+/.test(dn)||!!fn&&fn.maxTouchPoints>2),gF=JS||(fn?/Mac/.test(fn.platform):!1),GS=/Android \d/.test(dn),QS=!!Lh&&"webkitFontSmoothing"in Lh.documentElement.style,yF=QS?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ll(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,a=s.doc.resolve(e);if(a.parent.type.spec.code)return!1;let l=a.parent.textBetween(Math.max(0,a.parentOffset-500),a.parentOffset,void 0,"\uFFFC")+r;for(let c of i){let u=c,f=u.match.exec(l),d=f&&f[0]&&u.handler(s,f,e-(f[0].length-r.length),n);if(d)return u.undoable!==!1&&d.setMeta(o,{transform:d,from:e,to:n,text:r}),t.dispatch(d),!0}return!1}var YS=new ee("MILKDOWN_CUSTOM_INPUTRULES");function Fh({rules:t}){let e=new X({key:YS,isInputRules:!0,state:{init(){return null},apply(n,r){let i=n.getMeta(this);return i||(n.selectionSet||n.docChanged?null:r)}},props:{handleTextInput(n,r,i,o){return Ll(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>(setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&Ll(n,r.pos,r.pos,"",t,e)}),!1),keydown:(n,r)=>!(GS&&KS&&r.key==="Enter")||n.composing?!1:n.someProp("handleKeyDown",i=>i(n,r))?(r.preventDefault(),!0):!1},handleKeyDown(n,r){if(r.key!=="Enter")return!1;let{$cursor:i}=n.state.selection;return i?Ll(n,i.pos,i.pos,` -`,t,e):!1}}});return e}function Ht(t,e,n={}){return new ke(t,(r,i,o,s)=>{var a,l,c,u;let{tr:f}=r,d=i.length,p=i[d-1],h=i[0],m=[],g,y={group:p,fullMatch:h,start:o,end:s},x=(a=n.updateCaptured)==null?void 0:a.call(n,y);if(Object.assign(y,x),{group:p,fullMatch:h,start:o,end:s}=y,h===null||p?.trim()==="")return null;if(p){let C=h.search(/\S/),v=o+h.indexOf(p),I=v+p.length;m=(l=f.storedMarks)!=null?l:[],I<s&&f.delete(I,s),v>o&&f.delete(o+C,v),g=o+C+p.length;let w=(c=n.getAttr)==null?void 0:c.call(n,i);f.addMark(o,g,e.create(w)),f.setStoredMarks(m),(u=n.beforeDispatch)==null||u.call(n,{match:i,start:o,end:s,tr:f})}return f})}function ls(t,e,n={}){return new ke(t,(r,i,o,s)=>{var a,l,c;let{tr:u}=r,f=i[1],d=i[0],p={group:f,fullMatch:d,start:o,end:s},h=(a=n.updateCaptured)==null?void 0:a.call(n,p);if(Object.assign(p,h),{group:f,fullMatch:d,start:o,end:s}=p,d===null||!f||f.trim()==="")return null;let m=(l=n.getAttr)==null?void 0:l.call(n,i),g=e.createAndFill(m);return g&&(u.replaceRangeWith(e.isBlock?u.doc.resolve(o).before():o,s,g),(c=n.beforeDispatch)==null||c.call(n,{match:[d,f],start:o,end:s,tr:u})),u})}function _l(t){return Object.assign(Object.create(t),t).setTime(Date.now())}function XS(t,e){return Array.isArray(t)&&t.includes(e.type)||e.type===t}function ZS(t){return e=>{for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r)){let i=e.before(n),o=e.after(n);return{from:i,to:o,node:r}}}}}function zh(t,e){return ZS(n=>n.type===e)(t)}function $h(t){return e=>{for(let n=e.depth;n>0;n--){let r=e.node(n);if(t(r))return{pos:e.before(n),start:e.start(n),depth:n,node:r}}}}function _h(t,e){if(!(t instanceof H))return;let{node:n,$from:r}=t;if(XS(e,n))return{node:n,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Hh=(t,e)=>{let{selection:n,doc:r}=t;if(n instanceof H)return{hasNode:n.node.type===e,pos:n.from,target:n.node};let{from:i,to:o}=n,s=!1,a=-1,l=null;return r.nodesBetween(i,o,(c,u)=>l?!1:c.type===e?(s=!0,a=u,l=c,!1):!0),{hasNode:s,pos:a,target:l}};var Vt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},us={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},e0=typeof navigator<"u"&&/Mac/.test(navigator.platform),t0=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(pe=0;pe<10;pe++)Vt[48+pe]=Vt[96+pe]=String(pe);var pe;for(pe=1;pe<=24;pe++)Vt[pe+111]="F"+pe;var pe;for(pe=65;pe<=90;pe++)Vt[pe]=String.fromCharCode(pe+32),us[pe]=String.fromCharCode(pe);var pe;for(cs in Vt)us.hasOwnProperty(cs)||(us[cs]=Vt[cs]);var cs;function Vh(t){var e=e0&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||t0&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?us:Vt)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var n0=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),r0=typeof navigator<"u"&&/Win/.test(navigator.platform);function i0(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let a=0;a<e.length-1;a++){let l=e[a];if(/^(cmd|meta|m)$/i.test(l))s=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))i=!0;else if(/^s(hift)?$/i.test(l))o=!0;else if(/^mod$/i.test(l))n0?s=!0:i=!0;else throw new Error("Unrecognized modifier name: "+l)}return r&&(n="Alt-"+n),i&&(n="Ctrl-"+n),s&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function o0(t){let e=Object.create(null);for(let n in t)e[i0(n)]=t[n];return e}function Hl(t,e,n=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n&&e.shiftKey&&(t="Shift-"+t),t}function Wh(t){return new X({props:{handleKeyDown:Vl(t)}})}function Vl(t){let e=o0(t);return function(n,r){let i=Vh(r),o,s=e[Hl(i,r)];if(s&&s(n.state,n.dispatch,n))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let a=e[Hl(i,r,!1)];if(a&&a(n.state,n.dispatch,n))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(r0&&r.ctrlKey&&r.altKey)&&(o=Vt[r.keyCode])&&o!=i){let a=e[Hl(o,r)];if(a&&a(n.state,n.dispatch,n))return!0}}return!1}}var qh=class{},Kh=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=t=>{this.top()?.push(t)},this.open=t=>{this.elements.push(t)},this.close=()=>{let t=this.elements.pop();if(!t)throw Sa();return t}}},s0=class Uh extends qh{constructor(e,n,r){super(),this.type=e,this.content=n,this.attrs=r}push(e,...n){this.content.push(e,...n)}pop(){return this.content.pop()}static create(e,n,r){return new Uh(e,n,r)}},Jh=class extends Kh{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(e,r),n.toDoc())}}constructor(t){super(),this.#t=J.none,this.#e=e=>e.isText,this.#r=(e,n)=>{if(this.#e(e)&&this.#e(n)&&J.sameSet(e.marks,n.marks))return this.schema.text(e.text+n.text,e.marks)},this.#n=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.parseMarkdown.match(e));if(!n)throw id(e);return n},this.#s=e=>{let n=this.#n(e);n.spec.parseMarkdown.runner(this,e,n)},this.injectRoot=(e,n,r)=>(this.openNode(n,r),this.next(e.children),this),this.openNode=(e,n)=>(this.open(s0.create(e,[],n)),this),this.#o=()=>{this.#t=J.none;let e=this.close();return this.#i(e.type,e.attrs,e.content)},this.closeNode=()=>{try{this.#o()}catch(e){console.error(e)}return this},this.#i=(e,n,r)=>{let i=e.createAndFill(n,r,this.#t);if(!i)throw rd(e,n,r);return this.push(i),i},this.addNode=(e,n,r)=>{try{this.#i(e,n,r)}catch(i){console.error(i)}return this},this.openMark=(e,n)=>{let r=e.create(n);return this.#t=r.addToSet(this.#t),this},this.closeMark=e=>(this.#t=e.removeFromSet(this.#t),this),this.addText=e=>{try{let n=this.top();if(!n)throw Sa();let r=n.pop(),i=this.schema.text(e,this.#t);if(!r)return n.push(i),this;let o=this.#r(r,i);return o?(n.push(o),this):(n.push(r,i),this)}catch(n){return console.error(n),this}},this.build=()=>{let e;do e=this.#o();while(this.size());return e},this.next=(e=[])=>([e].flat().forEach(n=>this.#s(n)),this),this.toDoc=()=>this.build(),this.run=(e,n)=>{let r=e.runSync(e.parse(n),n);return this.next(r),this},this.schema=t}#e;#r;#n;#s;#o;#i},jh=class Gh extends qh{constructor(e,n,r,i={}){super(),this.type=e,this.children=n,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}static{this.create=(e,n,r,i={})=>new Gh(e,n,r,i)}},a0=t=>Object.prototype.hasOwnProperty.call(t,"size"),Qh=class extends Kh{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(r),n.toString(e))}}constructor(t){super(),this.#t=[],this.#e=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.toMarkdown.match(e));if(!n)throw od(e.type);return n},this.#r=e=>this.#e(e).spec.toMarkdown.runner(this,e),this.#n=(e,n)=>this.#e(e).spec.toMarkdown.runner(this,e,n),this.#s=e=>{let n=o=>o.type.spec.priority??50,r=[...e].sort((o,s)=>n(o)-n(s)),i=[];return this.#t.forEach(({mark:o})=>{let s=r.findIndex(a=>a.eq(o));s>=0&&i.push(...r.splice(s,1))}),i.concat(r)},this.#o=e=>{let n=e?.marks,r=0;for(;r<this.#t.length;){let{mark:i,spanning:o}=this.#t[r];if(o&&n?.some(s=>s.eq(i)))r++;else break}for(let i=this.#t.length-1;i>=r;i--)this.#f(this.#t[i].mark)},this.#i=(e,n)=>{this.#s(e.marks).every(r=>!this.#n(r,e))&&this.#r(e),this.#o(n)},this.#a=e=>{let{children:n}=e;return n&&(e.children=n.reduce((r,i,o)=>{if(o===0)return[i];let s=r.at(-1);if(s&&s.isMark&&i.isMark){let{children:a,...l}=i,{children:c,...u}=s;if(i.type===s.type&&a&&c&&JSON.stringify(l)===JSON.stringify(u)){let f={...u,children:[...c,...a]};return r.slice(0,-1).concat(this.#a(f))}}return r.concat(i)},[])),e},this.#l=e=>{let n={...e.props,type:e.type};return e.children&&(n.children=e.children),e.value&&(n.value=e.value),n},this.openNode=(e,n,r)=>(this.open(jh.create(e,void 0,n,r)),this),this.#d=(e,n)=>{let r="",i="",o=e.children;if(o){let a=o[0],l=o.at(-1);if(l&&l.type==="text"&&l.value.endsWith(" ")){let c=l.value,u=c.trimEnd();i=c.slice(u.length),l.value=u}if(a&&a.type==="text"&&a.value.startsWith(" ")){let c=a.value,u=c.trimStart();r=c.slice(0,c.length-u.length),a.value=u}}r.length&&this.#u("text",void 0,r);let s=n();return i.length&&this.#u("text",void 0,i),s},this.#c=(e=!1)=>{let n=this.close(),r=()=>this.#u(n.type,n.children,n.value,n.props);return e?this.#d(n,r):r()},this.closeNode=()=>(this.#c(),this),this.#u=(e,n,r,i)=>{let o=jh.create(e,n,r,i),s=this.#a(this.#l(o));return this.push(s),s},this.addNode=(e,n,r,i)=>(this.#u(e,n,r,i),this),this.#p=(e,n,r,i)=>this.#t.some(o=>o.mark.eq(e))?this:(this.#t.push({mark:e,spanning:r==null}),this.openNode(n,r,{...i,isMark:!0})),this.#f=e=>{let n=-1;for(let r=this.#t.length-1;r>=0;r--)if(this.#t[r].mark.eq(e)){n=r;break}n<0||(this.#t.splice(n,1),this.#c(!0))},this.withMark=(e,n,r,i)=>(this.#p(e,n,r,i),this),this.closeMark=e=>(this.#f(e),this),this.build=()=>{let e=null;do e=this.#c();while(this.size());return e},this.next=e=>a0(e)?(e.forEach((n,r,i)=>{this.#i(n,e.maybeChild(i+1)??void 0)}),this):(this.#i(e),this),this.toString=e=>e.stringify(this.build()),this.run=e=>(this.#t=[],this.next(e),this),this.schema=t}#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f};var ve=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Dr=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},Jl=null,jt=function(t,e,n){let r=Jl||(Jl=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},l0=function(){Jl=null},Zn=function(t,e,n,r){return n&&(Yh(t,e,n,r,-1)||Yh(t,e,n,r,1))},c0=/^(img|br|input|textarea|hr)$/i;function Yh(t,e,n,r,i){for(var o;;){if(t==n&&e==r)return!0;if(e==(i<0?0:it(t))){let s=t.parentNode;if(!s||s.nodeType!=1||Vi(t)||c0.test(t.nodeName)||t.contentEditable=="false")return!1;e=ve(t)+(i<0?0:1),t=s}else if(t.nodeType==1){let s=t.childNodes[e+(i<0?-1:0)];if(s.nodeType==1&&s.contentEditable=="false")if(!((o=s.pmViewDesc)===null||o===void 0)&&o.ignoreForSelection)e+=i;else return!1;else t=s,e=i<0?it(t):0}else return!1}}function it(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function u0(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=it(t)}else if(t.parentNode&&!Vi(t))e=ve(t),t=t.parentNode;else return null}}function f0(t,e){for(;;){if(t.nodeType==3&&e<t.nodeValue.length)return t;if(t.nodeType==1&&e<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[e],e=0}else if(t.parentNode&&!Vi(t))e=ve(t)+1,t=t.parentNode;else return null}}function d0(t,e,n){for(let r=e==0,i=e==it(t);r||i;){if(t==n)return!0;let o=ve(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==it(t)}}function Vi(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}var Ss=function(t){return t.focusNode&&Zn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Kn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function p0(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function h0(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:Math.min(it(r.offsetNode),r.offset)}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:Math.min(it(r.startContainer),r.startOffset)}}}var vt=typeof navigator<"u"?navigator:null,Xh=typeof document<"u"?document:null,yn=vt&&vt.userAgent||"",Gl=/Edge\/(\d+)/.exec(yn),vm=/MSIE \d/.exec(yn),Ql=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(yn),Ve=!!(vm||Ql||Gl),mn=vm?document.documentMode:Ql?+Ql[1]:Gl?+Gl[1]:0,ot=!Ve&&/gecko\/(\d+)/i.test(yn);ot&&+(/Firefox\/(\d+)/.exec(yn)||[0,0])[1];var Yl=!Ve&&/Chrome\/(\d+)/.exec(yn),we=!!Yl,Im=Yl?+Yl[1]:0,De=!Ve&&!!vt&&/Apple Computer/.test(vt.vendor),Br=De&&(/Mobile\/\w+/.test(yn)||!!vt&&vt.maxTouchPoints>2),rt=Br||(vt?/Mac/.test(vt.platform):!1),Am=vt?/Win/.test(vt.platform):!1,qt=/Android \d/.test(yn),Wi=!!Xh&&"webkitFontSmoothing"in Xh.documentElement.style,m0=Wi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function g0(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Wt(t,e){return typeof t=="number"?t:t[e]}function y0(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function Zh(t,e,n){if(!Xl(e)&&e.left==0)return;let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;){if(s.nodeType!=1){s=Dr(s);continue}let a=s,l=a==o.body,c=l?g0(o):y0(a),u=0,f=0;if(e.top<c.top+Wt(r,"top")?f=-(c.top-e.top+Wt(i,"top")):e.bottom>c.bottom-Wt(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+Wt(i,"top")-c.top:e.bottom-c.bottom+Wt(i,"bottom")),e.left<c.left+Wt(r,"left")?u=-(c.left-e.left+Wt(i,"left")):e.right>c.right-Wt(r,"right")&&(u=e.right-c.right+Wt(i,"right")),u||f)if(l)o.defaultView.scrollBy(u,f);else{let p=a.scrollLeft,h=a.scrollTop;f&&(a.scrollTop+=f),u&&(a.scrollLeft+=u);let m=a.scrollLeft-p,g=a.scrollTop-h;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=l?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:Dr(s)}}function k0(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s<Math.min(innerHeight,e.bottom);s+=5){let a=t.root.elementFromPoint(o,s);if(!a||a==t.dom||!t.dom.contains(a))continue;let l=a.getBoundingClientRect();if(l.top>=n-20){r=a,i=l.top;break}}return{refDOM:r,refTop:i,stack:Nm(t.dom)}}function Nm(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Dr(r));return e}function b0({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Rm(n,r==0?0:r-e)}function Rm(t,e){for(let n=0;n<t.length;n++){let{dom:r,top:i,left:o}=t[n];r.scrollTop!=i+e&&(r.scrollTop=i+e),r.scrollLeft!=o&&(r.scrollLeft=o)}}var Nr=null;function x0(t){if(t.setActive)return t.setActive();if(Nr)return t.focus(Nr);let e=Nm(t);t.focus(Nr==null?{get preventScroll(){return Nr={preventScroll:!0},!0}}:void 0),Nr||(Nr=!1,Rm(e,0))}function Om(t,e){let n,r=2e8,i,o=0,s=e.top,a=e.top,l,c;for(let u=t.firstChild,f=0;u;u=u.nextSibling,f++){let d;if(u.nodeType==1)d=u.getClientRects();else if(u.nodeType==3)d=jt(u).getClientRects();else continue;for(let p=0;p<d.length;p++){let h=d[p];if(h.top<=s&&h.bottom>=a){s=Math.max(h.bottom,s),a=Math.min(h.top,a);let m=h.left>e.left?h.left-e.left:h.right<e.left?e.left-h.right:0;if(m<r){n=u,r=m,i=m&&n.nodeType==3?{left:h.right<e.left?h.right:h.left,top:e.top}:e,u.nodeType==1&&m&&(o=f+(e.left>=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!l&&h.left<=e.left&&h.right>=e.left&&(l=u,c={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!n&&l&&(n=l,i=c,r=0),n&&n.nodeType==3?w0(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Om(n,i)}function w0(t,e){let n=t.nodeValue.length,r=document.createRange(),i;for(let o=0;o<n;o++){r.setEnd(t,o+1),r.setStart(t,o);let s=pn(r,1);if(s.top!=s.bottom&&hc(e,s)){i={node:t,offset:o+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}function hc(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function S0(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left<t.getBoundingClientRect().left?n:t}function C0(t,e,n){let{node:r,offset:i}=Om(e,n),o=-1;if(r.nodeType==1&&!r.firstChild){let s=r.getBoundingClientRect();o=s.left!=s.right&&n.left>(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function M0(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let a=t.docView.nearestDesc(o,!0),l;if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)&&((l=a.dom.getBoundingClientRect()).width||l.height)&&(a.node.isBlock&&a.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(a.dom.nodeName)&&(!s&&l.left>r.left||l.top>r.top?i=a.posBefore:(!s&&l.right<r.left||l.bottom<r.top)&&(i=a.posAfter),s=!0),!a.contentDOM&&i<0&&!a.node.isText))return(a.node.isBlock?r.top<(l.top+l.bottom)/2:r.left<(l.left+l.right)/2)?a.posBefore:a.posAfter;o=a.dom.parentNode}return i>-1?i:t.docView.posFromDOM(e,n,-1)}function Dm(t,e,n){let r=t.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-n.top)/(n.bottom-n.top))-2)),o=i;;){let s=t.childNodes[o];if(s.nodeType==1){let a=s.getClientRects();for(let l=0;l<a.length;l++){let c=a[l];if(hc(e,c))return Dm(s,e,c)}}if((o=(o+1)%r)==i)break}return t}function E0(t,e){let n=t.dom.ownerDocument,r,i=0,o=h0(n,e.left,e.top);o&&({node:r,offset:i}=o);let s=(t.root.elementFromPoint?t.root:n).elementFromPoint(e.left,e.top),a;if(!s||!t.dom.contains(s.nodeType!=1?s.parentNode:s)){let c=t.dom.getBoundingClientRect();if(!hc(e,c)||(s=Dm(t.dom,e,c),!s))return null}if(De)for(let c=s;r&&c;c=Dr(c))c.draggable&&(r=void 0);if(s=S0(s,e),r){if(ot&&r.nodeType==1&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let u=r.childNodes[i],f;u.nodeName=="IMG"&&(f=u.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&i++}let c;Wi&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(a=M0(t,r,i,e))}a==null&&(a=C0(t,s,e));let l=t.docView.nearestDesc(s,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function Xl(t){return t.top<t.bottom||t.left<t.right}function pn(t,e){let n=t.getClientRects();if(n.length){let r=n[e<0?0:n.length-1];if(Xl(r))return r}return Array.prototype.find.call(n,Xl)||t.getBoundingClientRect()}var T0=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Bm(t,e,n){let{node:r,offset:i,atom:o}=t.docView.domFromPos(e,n<0?-1:1),s=Wi||ot;if(r.nodeType==3)if(s&&(T0.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let l=pn(jt(r,i,i),n);if(ot&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let c=pn(jt(r,i-1,i-1),-1);if(c.top==l.top){let u=pn(jt(r,i,i+1),-1);if(u.top!=l.top)return Li(u,u.left<c.left)}}return l}else{let l=i,c=i,u=n<0?1:-1;return n<0&&!i?(c++,u=-1):n>=0&&i==r.nodeValue.length?(l--,u=1):n<0?l--:c++,Li(pn(jt(r,l,c),u),u<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==it(r))){let l=r.childNodes[i-1];if(l.nodeType==1)return Wl(l.getBoundingClientRect(),!1)}if(o==null&&i<it(r)){let l=r.childNodes[i];if(l.nodeType==1)return Wl(l.getBoundingClientRect(),!0)}return Wl(r.getBoundingClientRect(),n>=0)}if(o==null&&i&&(n<0||i==it(r))){let l=r.childNodes[i-1],c=l.nodeType==3?jt(l,it(l)-(s?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return Li(pn(c,1),!1)}if(o==null&&i<it(r)){let l=r.childNodes[i];for(;l.pmViewDesc&&l.pmViewDesc.ignoreForCoords;)l=l.nextSibling;let c=l?l.nodeType==3?jt(l,0,s?0:1):l.nodeType==1?l:null:null;if(c)return Li(pn(c,-1),!0)}return Li(pn(r.nodeType==3?jt(r):r,-n),n>=0)}function Li(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Wl(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Lm(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function v0(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Lm(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(o,!0);if(!a)break;if(a.node.isBlock){o=a.contentDOM||a.dom;break}o=a.dom.parentNode}let s=Bm(t,i.pos,1);for(let a=o.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=jt(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;c<l.length;c++){let u=l[c];if(u.bottom>u.top+1&&(n=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var I0=/[\u0590-\u08ac]/;function A0(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,a=t.domSelection();return a?!I0.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?o:s:Lm(t,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:u,anchorOffset:f}=t.domSelectionRange(),d=a.caretBidiLevel;a.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||l==h&&c==m;try{a.collapse(u,f),l&&(l!=u||c!=f)&&a.extend&&a.extend(l,c)}catch{}return d!=null&&(a.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var em=null,tm=null,nm=!1;function N0(t,e,n){return em==e&&tm==n?nm:(em=e,tm=n,nm=n=="up"||n=="down"?v0(t,e,n):A0(t,e,n))}var st=0,rm=1,Un=2,ht=3,er=class{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=st,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;n<this.children.length;n++)e+=this.children[n].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let n=0,r=this.posAtStart;;n++){let i=this.children[n];if(i==e)return r;r+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,n,r){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(r<0){let o,s;if(e==this.contentDOM)o=e.childNodes[n-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;o=e.previousSibling}for(;o&&!((s=o.pmViewDesc)&&s.parent==this);)o=o.previousSibling;return o?this.posBeforeChild(s)+s.size:this.posAtStart}else{let o,s;if(e==this.contentDOM)o=e.childNodes[n];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;o=e.nextSibling}for(;o&&!((s=o.pmViewDesc)&&s.parent==this);)o=o.nextSibling;return o?this.posBeforeChild(s):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=n>ve(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;n<this.children.length;n++){let i=this.children[n],o=r+i.size;if(r==e&&o!=r){for(;!i.border&&i.children.length;)for(let s=0;s<i.children.length;s++){let a=i.children[s];if(a.size){i=a;break}}return i}if(e<o)return i.descAt(e-r-i.border);r=o}}domFromPos(e,n){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,i=0;for(let o=0;r<this.children.length;r++){let s=this.children[r],a=o+s.size;if(a>e||s instanceof ps){i=e-o;break}o=a}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof fs&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?ve(o.dom)+1:0}}else{let o,s=!0;for(;o=r<this.children.length?this.children[r]:null,!(!o||o.dom.parentNode==this.contentDOM);r++,s=!1);return o&&s&&!o.border&&!o.domAtom?o.domFromPos(0,n):{node:this.contentDOM,offset:o?ve(o.dom):this.contentDOM.childNodes.length}}}parseRange(e,n,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:n,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,o=-1;for(let s=r,a=0;;a++){let l=this.children[a],c=s+l.size;if(i==-1&&e<=c){let u=s+l.border;if(e>=u&&n<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,n,u);e=s;for(let f=a;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ve(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>n||a==this.children.length-1)){n=c;for(let u=a+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){o=ve(f.dom);break}n+=f.size}o==-1&&(o=this.contentDOM.childNodes.length);break}s=c}return{node:this.contentDOM,from:e,to:n,fromOffset:i,toOffset:o}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let n=this.children[e<0?0:this.children.length-1];return n.size==0||n.emptyChildAt(e)}domAfterPos(e){let{node:n,offset:r}=this.domFromPos(e,0);if(n.nodeType!=1||r==n.childNodes.length)throw new RangeError("No node after pos "+e);return n.childNodes[r]}setSelection(e,n,r,i=!1){let o=Math.min(e,n),s=Math.max(e,n);for(let p=0,h=0;p<this.children.length;p++){let m=this.children[p],g=h+m.size;if(o>h&&s<g)return m.setSelection(e-h-m.border,n-h-m.border,r,i);h=g}let a=this.domFromPos(e,e?-1:1),l=n==e?a:this.domFromPos(n,n?-1:1),c=r.root.getSelection(),u=r.domSelectionRange(),f=!1;if((ot||De)&&e==n){let{node:p,offset:h}=a;if(p.nodeType==3){if(f=!!(h&&p.nodeValue[h-1]==` -`),f&&h==p.nodeValue.length)for(let m=p,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(a=l={node:g.parentNode,offset:ve(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=p.childNodes[h-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(ot&&u.focusNode&&u.focusNode!=l.node&&u.focusNode.nodeType==1){let p=u.focusNode.childNodes[u.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||f&&De)&&Zn(a.node,a.offset,u.anchorNode,u.anchorOffset)&&Zn(l.node,l.offset,u.focusNode,u.focusOffset))return;let d=!1;if((c.extend||e==n)&&!(f&&ot)){c.collapse(a.node,a.offset);try{e!=n&&c.extend(l.node,l.offset),d=!0}catch{}}if(!d){if(e>n){let h=a;a=l,l=h}let p=document.createRange();p.setEnd(l.node,l.offset),p.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i<this.children.length;i++){let o=this.children[i],s=r+o.size;if(r==s?e<=s&&n>=r:e<s&&n>r){let a=r+o.border,l=s-o.border;if(e>=a&&n<=l){this.dirty=e==r||n==s?Un:rm,e==a&&n==l&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=ht:o.markDirty(e-a,n-a);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Un:ht}r=s}this.dirty=Un}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Un:rm;n.dirty<r&&(n.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},fs=class extends er{constructor(e,n,r,i){let o,s=n.type.toDOM;if(typeof s=="function"&&(s=s(r,()=>{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let a=document.createElement("span");a.appendChild(s),s=a}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==st&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Zl=class extends er{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Gn=class t extends er{constructor(e,n,r,i,o){super(e,[],r,i),this.mark=n,this.spec=o}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=cn.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new t(e,n,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&ht||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ht&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=st){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=st}}slice(e,n,r){let i=t.create(this.parent,this.mark,!0,r),o=this.children,s=this.size;n<s&&(o=rc(o,n,s,r)),e>0&&(o=rc(o,0,e,r));for(let a=0;a<o.length;a++)o[a].parent=i;return i.children=o,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},gn=class t extends er{constructor(e,n,r,i,o,s,a){super(e,[],o,s),this.node=n,this.outerDeco=r,this.innerDeco=i,this.nodeDOM=a}static create(e,n,r,i,o,s){let a=o.nodeViews[n.type.name],l,c=a&&a(n,o,()=>{if(!l)return s;if(l.parent)return l.parent.posBeforeChild(l)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=cn.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),n.type.spec.draggable&&(u.draggable=!0));let d=u;return u=zm(u,r,n),c?l=new ec(e,n,r,i,u,f||null,d,c):n.isText?new ds(e,n,r,i,u,d):new t(e,n,r,i,u,f||null,d)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>E.empty)}return e}matchesNode(e,n,r){return this.dirty==st&&e.eq(this.node)&&hs(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,a=o&&o.pos<0,l=new nc(this,s&&s.node,e);B0(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&l.syncToMarks(u==this.node.childCount?J.none:this.node.child(u).marks,r,e,u),l.placeWidget(c,e,i)},(c,u,f,d)=>{l.syncToMarks(c.marks,r,e,d);let p;l.findNodeMatch(c,u,f,d)||a&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(p=l.findIndexWithChild(o.node))>-1&&l.updateNodeAt(c,u,f,p,e)||l.updateNextNode(c,u,f,e,d,i)||l.addNode(c,u,f,e,i),i+=c.nodeSize}),l.syncToMarks([],r,e,0),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==Un)&&(s&&this.protectLocalComposition(e,s),Pm(this.contentDOM,this.children,e),Br&&L0(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof z)||r<n||i>n+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,a=P0(this.node.content,s,r-n,i-n);return a<0?null:{node:o,pos:a,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Zl(this,o,n,i);e.input.compositionNodes.push(s),this.children=rc(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==ht||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=st}updateOuterDeco(e){if(hs(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Fm(this.dom,this.nodeDOM,tc(this.outerDeco,this.node,n),tc(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function im(t,e,n,r,i){zm(r,e,t);let o=new gn(void 0,t,e,n,r,r,r);return o.contentDOM&&o.updateChildren(i,0),o}var ds=class t extends gn{constructor(e,n,r,i,o,s){super(e,n,r,i,o,null,s)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==ht||this.dirty!=st&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=st||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=st,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new t(this.parent,i,this.outerDeco,this.innerDeco,o,o)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=ht)}get domAtom(){return!1}isText(e){return this.node.text==e}},ps=class extends er{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==st&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},ec=class extends gn{constructor(e,n,r,i,o,s,a,l){super(e,n,r,i,o,s,a),this.spec=l}update(e,n,r,i){if(this.dirty==ht)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Pm(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o<e.length;o++){let s=e[o],a=s.dom;if(a.parentNode==t){for(;a!=r;)r=om(r),i=!0;r=r.nextSibling}else i=!0,t.insertBefore(a,r);if(s instanceof Gn){let l=r?r.previousSibling:t.lastChild;Pm(s.contentDOM,s.children,n),r=l?l.nextSibling:t.firstChild}}for(;r;)r=om(r),i=!0;i&&n.trackWrites==t&&(n.trackWrites=null)}var Pi=function(t){t&&(this.nodeName=t)};Pi.prototype=Object.create(null);var Jn=[new Pi];function tc(t,e,n){if(t.length==0)return Jn;let r=n?Jn[0]:new Pi,i=[r];for(let o=0;o<t.length;o++){let s=t[o].type.attrs;if(s){s.nodeName&&i.push(r=new Pi(s.nodeName));for(let a in s){let l=s[a];l!=null&&(n&&i.length==1&&i.push(r=new Pi(e.isInline?"span":"div")),a=="class"?r.class=(r.class?r.class+" ":"")+l:a=="style"?r.style=(r.style?r.style+";":"")+l:a!="nodeName"&&(r[a]=l))}}}return i}function Fm(t,e,n,r){if(n==Jn&&r==Jn)return e;let i=e;for(let o=0;o<r.length;o++){let s=r[o],a=n[o];if(o){let l;a&&a.nodeName==s.nodeName&&i!=t&&(l=i.parentNode)&&l.nodeName.toLowerCase()==s.nodeName||(l=document.createElement(s.nodeName),l.pmIsDeco=!0,l.appendChild(i),a=Jn[0]),i=l}R0(i,a||Jn[0],s)}return i}function R0(t,e,n){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in n)&&t.removeAttribute(r);for(let r in n)r!="class"&&r!="style"&&r!="nodeName"&&n[r]!=e[r]&&t.setAttribute(r,n[r]);if(e.class!=n.class){let r=e.class?e.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let o=0;o<r.length;o++)i.indexOf(r[o])==-1&&t.classList.remove(r[o]);for(let o=0;o<i.length;o++)r.indexOf(i[o])==-1&&t.classList.add(i[o]);t.classList.length==0&&t.removeAttribute("class")}if(e.style!=n.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=r.exec(e.style);)t.style.removeProperty(i[1])}n.style&&(t.style.cssText+=n.style)}}function zm(t,e,n){return Fm(t,t,Jn,tc(e,n,t.nodeType!=1))}function hs(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].type.eq(e[n].type))return!1;return!0}function om(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}var nc=class{constructor(e,n,r){this.lock=n,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=O0(e.node.content,e)}destroyBetween(e,n){if(e!=n){for(let r=e;r<n;r++)this.top.children[r].destroy();this.top.children.splice(e,n-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,n,r,i){let o=0,s=this.stack.length>>1,a=Math.min(s,e.length);for(;o<a&&(o==s-1?this.top:this.stack[o+1<<1]).matchesMark(e[o])&&e[o].type.spec.spanning!==!1;)o++;for(;o<s;)this.destroyRest(),this.top.dirty=st,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let l=-1,c=this.top.children.length;i<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let u=this.index;u<c;u++){let f=this.top.children[u];if(f.matchesMark(e[s])&&!this.isLocked(f.dom)){l=u;break}}if(l<0&&this.index<this.top.children.length){let u=this.top.children[this.index];u instanceof Gn&&u.dirty!=ht&&u.mark.type==e[s].type&&u.spec.update&&!this.isLocked(u.dom)&&u.spec.update(e[s])&&(u.mark=e[s],l=this.index,this.changed=!0)}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let u=Gn.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let a=this.index,l=Math.min(this.top.children.length,a+5);a<l;a++){let c=this.top.children[a];if(c.matchesNode(e,n,r)&&!this.preMatch.matched.has(c)){o=a;break}}return o<0?!1:(this.destroyBetween(this.index,o),this.index++,!0)}updateNodeAt(e,n,r,i,o){let s=this.top.children[i];return s.dirty==ht&&s.dom==s.contentDOM&&(s.dirty=Un),s.update(e,n,r,o)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let n=e.parentNode;if(!n)return-1;if(n==this.top.contentDOM){let r=e.pmViewDesc;if(r){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==r)return i}return-1}e=n}}updateNextNode(e,n,r,i,o,s){for(let a=this.index;a<this.top.children.length;a++){let l=this.top.children[a];if(l instanceof gn){let c=this.preMatch.matched.get(l);if(c!=null&&c!=o)return!1;let u=l.dom,f,d=this.isLocked(u)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&l.dirty!=ht&&hs(n,l.outerDeco));if(!d&&l.update(e,n,r,i))return this.destroyBetween(this.index,a),l.dom!=u&&(this.changed=!0),this.index++,!0;if(!d&&(f=this.recreateWrapper(l,e,n,r,i,s)))return this.destroyBetween(this.index,a),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Un,f.updateChildren(i,s+1),f.dirty=st),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,n,r,i,o,s){if(e.dirty||n.isAtom||!e.children.length||!e.node.content.eq(n.content)||!hs(r,e.outerDeco)||!i.eq(e.innerDeco))return null;let a=gn.create(this.top,n,r,i,o,s);if(a.contentDOM){a.children=e.children,e.children=[];for(let l of a.children)l.parent=a}return e.destroy(),a}addNode(e,n,r,i,o){let s=gn.create(this.top,e,n,r,i,o);s.contentDOM&&s.updateChildren(i,o+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,n,r){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let o=new fs(this.top,e,n,r);this.top.children.splice(this.index++,0,o),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],n=this.top;for(;e instanceof Gn;)n=e,e=n.children[n.children.length-1];(!e||!(e instanceof ds)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((De||we)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",n),this.addHackNode("BR",this.top))}addHackNode(e,n){if(n==this.top&&this.index<n.children.length&&n.children[this.index].matchesHack(e))this.index++;else{let r=document.createElement(e);e=="IMG"&&(r.className="ProseMirror-separator",r.alt=""),e=="BR"&&(r.className="ProseMirror-trailingBreak");let i=new ps(this.top,[],r,null);n!=this.top?n.children.push(i):n.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}};function O0(t,e){let n=e,r=n.children.length,i=t.childCount,o=new Map,s=[];e:for(;i>0;){let a;for(;;)if(r){let c=n.children[r-1];if(c instanceof Gn)n=c,r=c.children.length;else{a=c,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=t.child(i-1))break;--i,o.set(a,i),s.push(a)}}return{index:i,matched:o,matches:s.reverse()}}function D0(t,e){return t.type.side-e.type.side}function B0(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let c=0;c<t.childCount;c++){let u=t.child(c);r(u,i,e.forChild(o,u),c),o+=u.nodeSize}return}let s=0,a=[],l=null;for(let c=0;;){let u,f;for(;s<i.length&&i[s].to==o;){let g=i[s++];g.widget&&(u?(f||(f=[u])).push(g):u=g)}if(u)if(f){f.sort(D0);for(let g=0;g<f.length;g++)n(f[g],c,!!l)}else n(u,c,!!l);let d,p;if(l)p=-1,d=l,l=null;else if(c<t.childCount)p=c,d=t.child(c++);else break;for(let g=0;g<a.length;g++)a[g].to<=o&&a.splice(g--,1);for(;s<i.length&&i[s].from<=o&&i[s].to>o;)a.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let g=h;s<i.length&&i[s].from<g&&(g=i[s].from);for(let y=0;y<a.length;y++)a[y].to<g&&(g=a[y].to);g<h&&(l=d.cut(g-o),d=d.cut(0,g-o),h=g,p=-1)}else for(;s<i.length&&i[s].to<h;)s++;let m=d.isInline&&!d.isLeaf?a.filter(g=>!g.inline):a.slice();r(d,m,e.forChild(o,d),p),o=h}}function L0(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function P0(t,e,n,r){for(let i=0,o=0;i<t.childCount&&o<=r;){let s=t.child(i++),a=o;if(o+=s.nodeSize,!s.isText)continue;let l=s.text;for(;i<t.childCount;){let c=t.child(i++);if(o+=c.nodeSize,!c.isText)break;l+=c.text}if(o>=n){if(o>=r&&l.slice(r-e.length-a,r-a)==e)return r-e.length;let c=a<r?l.lastIndexOf(e,r-a-1):-1;if(c>=0&&c+e.length+a>=n)return a+c;if(n==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}function rc(t,e,n,r,i){let o=[];for(let s=0,a=0;s<t.length;s++){let l=t[s],c=a,u=a+=l.size;c>=n||u<=e?o.push(l):(c<e&&o.push(l.slice(0,e-c,r)),i&&(o.push(i),i=void 0),u>n&&o.push(l.slice(n-c,l.size,r)))}return o}function mc(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a=r.resolve(s),l,c;if(Ss(n)){for(l=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&H.isSelectable(f)&&i.parent&&!(f.isInline&&d0(n.focusNode,n.focusOffset,i.dom))){let d=i.posBefore;c=new H(s==d?a:r.resolve(d))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=s,d=s;for(let p=0;p<n.rangeCount;p++){let h=n.getRangeAt(p);f=Math.min(f,t.docView.posFromDOM(h.startContainer,h.startOffset,1)),d=Math.max(d,t.docView.posFromDOM(h.endContainer,h.endOffset,-1))}if(f<0)return null;[l,s]=d==t.state.selection.anchor?[d,f]:[f,d],a=r.resolve(s)}else l=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let u=r.resolve(l);if(!c){let f=e=="pointer"||t.state.selection.head<a.pos&&!o?1:-1;c=gc(t,u,a,f)}return c}function $m(t){return t.editable?t.hasFocus():Hm(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Ut(t,e=!1){let n=t.state.selection;if(_m(t,n),!$m(t))return;let r=t.input.mouseDown;if(!e&&we&&r){let i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Zn(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)&&r.delaySelUpdate()){t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)z0(t);else{let{anchor:i,head:o}=n,s,a;sm&&!(n instanceof z)&&(n.$from.parent.inlineContent||(s=am(t,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(a=am(t,n.to))),t.docView.setSelection(i,o,t,e),sm&&(s&&lm(s),a&&lm(a)),n.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&F0(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}var sm=De||we&&Im<63;function am(t,e){let{node:n,offset:r}=t.docView.domFromPos(e,0),i=r<n.childNodes.length?n.childNodes[r]:null,o=r?n.childNodes[r-1]:null;if(De&&i&&i.contentEditable=="false")return jl(i);if((!i||i.contentEditable=="false")&&(!o||o.contentEditable=="false")){if(i)return jl(i);if(o)return jl(o)}}function jl(t){return t.contentEditable="true",De&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function lm(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function F0(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let n=t.domSelectionRange(),r=n.anchorNode,i=n.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!$m(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function z0(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,ve(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&Ve&&mn<=11&&(n.disabled=!0,n.disabled=!1)}function _m(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(cm(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else cm(t)}function cm(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function gc(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||z.between(e,n,r)}function um(t){return t.editable&&!t.hasFocus()?!1:Hm(t)}function Hm(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function $0(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Zn(e.node,e.offset,n.anchorNode,n.anchorOffset)}function ic(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&$.findFrom(o,e)}function hn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function fm(t,e,n){let r=t.state.selection;if(r instanceof z)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return hn(t,new z(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=ic(t.state,e);return i&&i instanceof H?hn(t,i):!1}else if(!(rt&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let a=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(a))&&!s.contentDOM?H.isSelectable(o)?hn(t,new H(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):Wi?hn(t,new z(t.state.doc.resolve(e<0?a:a+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof H&&r.node.isInline)return hn(t,new z(e>0?r.$to:r.$from));{let i=ic(t.state,e);return i?hn(t,i):!1}}}function ms(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Fi(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Rr(t,e){return e<0?_0(t):H0(t)}function _0(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(ot&&n.nodeType==1&&r<ms(n)&&Fi(n.childNodes[r],-1)&&(s=!0);;)if(r>0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(Fi(a,-1))i=n,o=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if(Vm(n))break;{let a=n.previousSibling;for(;a&&Fi(a,-1);)i=n.parentNode,o=ve(a),a=a.previousSibling;if(a)n=a,r=ms(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?oc(t,n,r):i&&oc(t,i,o)}function H0(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=ms(n),o,s;for(;;)if(r<i){if(n.nodeType!=1)break;let a=n.childNodes[r];if(Fi(a,1))o=n,s=++r;else break}else{if(Vm(n))break;{let a=n.nextSibling;for(;a&&Fi(a,1);)o=a.parentNode,s=ve(a)+1,a=a.nextSibling;if(a)n=a,r=0,i=ms(n);else{if(n=n.parentNode,n==t.dom)break;r=i=0}}}o&&oc(t,o,s)}function Vm(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function V0(t,e){for(;t&&e==t.childNodes.length&&!Vi(t);)e=ve(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let n=t.childNodes[e];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable=="false")break;t=n,e=0}}function W0(t,e){for(;t&&!e&&!Vi(t);)e=ve(t),t=t.parentNode;for(;t&&e;){let n=t.childNodes[e-1];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable=="false")break;t=n,e=t.childNodes.length}}function oc(t,e,n){if(e.nodeType!=3){let o,s;(s=V0(e,n))?(e=s,n=0):(o=W0(e,n))&&(e=o,n=o.nodeValue.length)}let r=t.domSelection();if(!r)return;if(Ss(r)){let o=document.createRange();o.setEnd(e,n),o.setStart(e,n),r.removeAllRanges(),r.addRange(o)}else r.extend&&r.extend(e,n);t.domObserver.setCurSelection();let{state:i}=t;setTimeout(()=>{t.state==i&&Ut(t)},50)}function dm(t,e){let n=t.state.doc.resolve(e);if(!(we||Am)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s<i.bottom&&Math.abs(o.left-i.left)>1)return o.left<i.left?"ltr":"rtl"}if(e<n.end()){let o=t.coordsAtPos(e+1),s=(o.top+o.bottom)/2;if(s>i.top&&s<i.bottom&&Math.abs(o.left-i.left)>1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function pm(t,e,n){let r=t.state.selection;if(r instanceof z&&!r.empty||n.indexOf("s")>-1||rt&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=ic(t.state,e);if(s&&s instanceof H)return hn(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,a=r instanceof Ke?$.near(s,e):$.findFrom(s,e);return a?hn(t,a):!1}return!1}function hm(t,e){if(!(t.state.selection instanceof z))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function mm(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function j0(t){if(!De||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;mm(t,r,"true"),setTimeout(()=>mm(t,r,"false"),20)}return!1}function q0(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function K0(t,e){let n=e.keyCode,r=q0(e);if(n==8||rt&&n==72&&r=="c")return hm(t,-1)||Rr(t,-1);if(n==46&&!e.shiftKey||rt&&n==68&&r=="c")return hm(t,1)||Rr(t,1);if(n==13||n==27)return!0;if(n==37||rt&&n==66&&r=="c"){let i=n==37?dm(t,t.state.selection.from)=="ltr"?-1:1:-1;return fm(t,i,r)||Rr(t,i)}else if(n==39||rt&&n==70&&r=="c"){let i=n==39?dm(t,t.state.selection.from)=="ltr"?1:-1:1;return fm(t,i,r)||Rr(t,i)}else{if(n==38||rt&&n==80&&r=="c")return pm(t,-1,r)||Rr(t,-1);if(n==40||rt&&n==78&&r=="c")return j0(t)||pm(t,1,r)||Rr(t,1);if(r==(rt?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function yc(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=t.someProp("clipboardSerializer")||cn.fromSchema(t.state.schema),a=Jm(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c=l.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Um[c.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let h=a.createElement(u[p]);for(;l.firstChild;)h.appendChild(l.firstChild);l.appendChild(h),f++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(n)}`);let d=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,` +`),i;function o(s){return r.stack.push(s),a;function a(){r.stack.pop()}}}function b1(t){throw new Error("Cannot handle value `"+t+"`, expected node")}function x1(t){let e=t;throw new Error("Cannot handle unknown node `"+e.type+"`")}function w1(t,e){if(t.type==="definition"&&t.type===e.type)return 0}function S1(t,e){return up(t,this,e)}function C1(t,e){return fp(t,this,e)}function M1(t,e){return hp(this,t,e)}function kr(t){let e=this;e.compiler=n;function n(r){return Za(r,{...e.data("settings"),...t,extensions:e.data("toMarkdownExtensions")||[]})}}function el(t){if(t)throw t}var jo=yx(Mp(),1);function bi(t){if(typeof t!="object"||t===null)return!1;let e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function tl(){let t=[],e={run:n,use:r};return e;function n(...i){let o=-1,s=i.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);a(null,...i);function a(l,...c){let u=t[++o],f=-1;if(l){s(l);return}for(;++f<i.length;)(c[f]===null||c[f]===void 0)&&(c[f]=i[f]);i=c,u?Ep(u,a)(...c):s(null,...c)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return t.push(i),e}}function Ep(t,e){let n;return r;function r(...s){let a=t.length>s.length,l;a&&s.push(i);try{l=t.apply(this,s)}catch(c){let u=c;if(a&&n)throw u;return i(u)}a||(l&&l.then&&typeof l.then=="function"?l.then(o,i):l instanceof Error?i(l):o(l))}function i(s,...a){n||(n=!0,e(s,...a))}function o(s){i(null,s)}}var be=class extends Error{constructor(e,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",o={},s=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let l=r.indexOf(":");l===-1?o.ruleId=r:(o.source=r.slice(0,l),o.ruleId=r.slice(l+1))}if(!o.place&&o.ancestors&&o.ancestors){let l=o.ancestors[o.ancestors.length-1];l&&(o.place=l.position)}let a=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=rn(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};be.prototype.file="";be.prototype.name="";be.prototype.reason="";be.prototype.message="";be.prototype.stack="";be.prototype.column=void 0;be.prototype.line=void 0;be.prototype.ancestors=void 0;be.prototype.cause=void 0;be.prototype.fatal=void 0;be.prototype.place=void 0;be.prototype.ruleId=void 0;be.prototype.source=void 0;var pt={basename:E1,dirname:T1,extname:v1,join:I1,sep:"/"};function E1(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');xi(t);let n=0,r=-1,i=t.length,o;if(e===void 0||e.length===0||e.length>t.length){for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":t.slice(n,r)}if(e===t)return"";let s=-1,a=e.length-1;for(;i--;)if(t.codePointAt(i)===47){if(o){n=i+1;break}}else s<0&&(o=!0,s=i+1),a>-1&&(t.codePointAt(i)===e.codePointAt(a--)?a<0&&(r=i):(a=-1,r=s));return n===r?r=s:r<0&&(r=t.length),t.slice(n,r)}function T1(t){if(xi(t),t.length===0)return".";let e=-1,n=t.length,r;for(;--n;)if(t.codePointAt(n)===47){if(r){e=n;break}}else r||(r=!0);return e<0?t.codePointAt(0)===47?"/":".":e===1&&t.codePointAt(0)===47?"//":t.slice(0,e)}function v1(t){xi(t);let e=t.length,n=-1,r=0,i=-1,o=0,s;for(;e--;){let a=t.codePointAt(e);if(a===47){if(s){r=e+1;break}continue}n<0&&(s=!0,n=e+1),a===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||n<0||o===0||o===1&&i===n-1&&i===r+1?"":t.slice(i,n)}function I1(...t){let e=-1,n;for(;++e<t.length;)xi(t[e]),t[e]&&(n=n===void 0?t[e]:n+"/"+t[e]);return n===void 0?".":A1(n)}function A1(t){xi(t);let e=t.codePointAt(0)===47,n=N1(t,!e);return n.length===0&&!e&&(n="."),n.length>0&&t.codePointAt(t.length-1)===47&&(n+="/"),e?"/"+n:n}function N1(t,e){let n="",r=0,i=-1,o=0,s=-1,a,l;for(;++s<=t.length;){if(s<t.length)a=t.codePointAt(s);else{if(a===47)break;a=47}if(a===47){if(!(i===s-1||o===1))if(i!==s-1&&o===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=s,o=0;continue}}else if(n.length>0){n="",r=0,i=s,o=0;continue}}e&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+t.slice(i+1,s):n=t.slice(i+1,s),r=s-i-1;i=s,o=0}else a===46&&o>-1?o++:o=-1}return n}function xi(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}var Tp={cwd:R1};function R1(){return"/"}function br(t){return!!(t!==null&&typeof t=="object"&&"href"in t&&t.href&&"protocol"in t&&t.protocol&&t.auth===void 0)}function vp(t){if(typeof t=="string")t=new URL(t);else if(!br(t)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+t+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(t.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return O1(t)}function O1(t){if(t.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=t.pathname,n=-1;for(;++n<e.length;)if(e.codePointAt(n)===37&&e.codePointAt(n+1)===50){let r=e.codePointAt(n+2);if(r===70||r===102){let i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(e)}var nl=["history","path","basename","stem","extname","dirname"],wi=class{constructor(e){let n;e?br(e)?n={path:e}:typeof e=="string"||D1(e)?n={value:e}:n=e:n={},this.cwd="cwd"in n?"":Tp.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<nl.length;){let o=nl[r];o in n&&n[o]!==void 0&&n[o]!==null&&(this[o]=o==="history"?[...n[o]]:n[o])}let i;for(i in n)nl.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?pt.basename(this.path):void 0}set basename(e){il(e,"basename"),rl(e,"basename"),this.path=pt.join(this.dirname||"",e)}get dirname(){return typeof this.path=="string"?pt.dirname(this.path):void 0}set dirname(e){Ip(this.basename,"dirname"),this.path=pt.join(e||"",this.basename)}get extname(){return typeof this.path=="string"?pt.extname(this.path):void 0}set extname(e){if(rl(e,"extname"),Ip(this.dirname,"extname"),e){if(e.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=pt.join(this.dirname,this.stem+(e||""))}get path(){return this.history[this.history.length-1]}set path(e){br(e)&&(e=vp(e)),il(e,"path"),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path=="string"?pt.basename(this.path,this.extname):void 0}set stem(e){il(e,"stem"),rl(e,"stem"),this.path=pt.join(this.dirname||"",e+(this.extname||""))}fail(e,n,r){let i=this.message(e,n,r);throw i.fatal=!0,i}info(e,n,r){let i=this.message(e,n,r);return i.fatal=void 0,i}message(e,n,r){let i=new be(e,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(e){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(e||void 0).decode(this.value)}};function rl(t,e){if(t&&t.includes(pt.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+pt.sep+"`")}function il(t,e){if(!t)throw new Error("`"+e+"` cannot be empty")}function Ip(t,e){if(!t)throw new Error("Setting `"+e+"` requires `path` to be set too")}function D1(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}var Ap=(function(t){let r=this.constructor.prototype,i=r[t],o=function(){return i.apply(o,arguments)};return Object.setPrototypeOf(o,r),o});var B1={}.hasOwnProperty,ll=class t extends Ap{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=tl()}copy(){let e=new t,n=-1;for(;++n<this.attachers.length;){let r=this.attachers[n];e.use(...r)}return e.data((0,jo.default)(!0,{},this.namespace)),e}data(e,n){return typeof e=="string"?arguments.length===2?(al("data",this.frozen),this.namespace[e]=n,this):B1.call(this.namespace,e)&&this.namespace[e]||void 0:e?(al("data",this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);let i=n.call(e,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(e){this.freeze();let n=Wo(e),r=this.parser||this.Parser;return ol("parse",r),r(String(n),n)}process(e,n){let r=this;return this.freeze(),ol("process",this.parser||this.Parser),sl("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(o,s){let a=Wo(e),l=r.parse(a);r.run(l,a,function(u,f,d){if(u||!f||!d)return c(u);let p=f,h=r.stringify(p,d);P1(h)?d.value=h:d.result=h,c(u,d)});function c(u,f){u||!f?s(u):o?o(f):n(void 0,f)}}}processSync(e){let n=!1,r;return this.freeze(),ol("processSync",this.parser||this.Parser),sl("processSync",this.compiler||this.Compiler),this.process(e,i),Rp("processSync","process",n),r;function i(o,s){n=!0,el(o),r=s}}run(e,n,r){Np(e),this.freeze();let i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?o(void 0,r):new Promise(o);function o(s,a){let l=Wo(n);i.run(e,l,c);function c(u,f,d){let p=f||e;u?a(u):s?s(p):r(void 0,p,d)}}}runSync(e,n){let r=!1,i;return this.run(e,n,o),Rp("runSync","run",r),i;function o(s,a){el(s),i=a,r=!0}}stringify(e,n){this.freeze();let r=Wo(n),i=this.compiler||this.Compiler;return sl("stringify",i),Np(e),i(e,r)}use(e,...n){let r=this.attachers,i=this.namespace;if(al("use",this.frozen),e!=null)if(typeof e=="function")l(e,n);else if(typeof e=="object")Array.isArray(e)?a(e):s(e);else throw new TypeError("Expected usable value, not `"+e+"`");return this;function o(c){if(typeof c=="function")l(c,[]);else if(typeof c=="object")if(Array.isArray(c)){let[u,...f]=c;l(u,f)}else s(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function s(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(c.plugins),c.settings&&(i.settings=(0,jo.default)(!0,i.settings,c.settings))}function a(c){let u=-1;if(c!=null)if(Array.isArray(c))for(;++u<c.length;){let f=c[u];o(f)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function l(c,u){let f=-1,d=-1;for(;++f<r.length;)if(r[f][0]===c){d=f;break}if(d===-1)r.push([c,...u]);else if(u.length>0){let[p,...h]=u,m=r[d][1];bi(m)&&bi(p)&&(p=(0,jo.default)(!0,m,p)),r[d]=[c,p,...h]}}}},Si=new ll().freeze();function ol(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `parser`")}function sl(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `compiler`")}function al(t,e){if(e)throw new Error("Cannot call `"+t+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Np(t){if(!bi(t)||typeof t.type!="string")throw new TypeError("Expected node, got `"+t+"`")}function Rp(t,e,n){if(!n)throw new Error("`"+t+"` finished async. Use `"+e+"` instead")}function Wo(t){return L1(t)?t:new wi(t)}function L1(t){return!!(t&&typeof t=="object"&&"message"in t&&"messages"in t)}function P1(t){return typeof t=="string"||F1(t)}function F1(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}function Re(t){this.content=t}Re.prototype={constructor:Re,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var r=n&&n!=t?this.remove(n):this,i=r.find(t),o=r.content.slice();return i==-1?o.push(n||t,e):(o[i+1]=e,n&&(o[i]=n)),new Re(o)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new Re(n)},addToStart:function(t,e){return new Re([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new Re(n)},addBefore:function(t,e,n){var r=this.remove(e),i=r.content.slice(),o=r.find(t);return i.splice(o==-1?i.length:o,0,e,n),new Re(i)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=Re.from(t),t.size?new Re(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=Re.from(t),t.size?new Re(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=Re.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};Re.from=function(t){if(t instanceof Re)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Re(e)};var cl=Re;function Hp(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){let s=i.text,a=o.text,l=0;for(;s[l]==a[l];l++)n++;return l&&l<s.length&&l<a.length&&jp(s.charCodeAt(l-1))&&Wp(s.charCodeAt(l))&&n--,n}if(i.content.size||o.content.size){let s=Hp(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function Vp(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let s=t.child(--i),a=e.child(--o),l=s.nodeSize;if(s==a){n-=l,r-=l;continue}if(!s.sameMarkup(a))return{a:n,b:r};if(s.isText&&s.text!=a.text){let c=s.text,u=a.text,f=c.length,d=u.length;for(;f>0&&d>0&&c[f-1]==u[d-1];)f--,d--,n--,r--;return f&&d&&f<c.length&&jp(c.charCodeAt(f-1))&&Wp(c.charCodeAt(f))&&(n++,r++),{a:n,b:r}}if(s.content.size||a.content.size){let c=Vp(s.content,a.content,n-1,r-1);if(c)return c}n-=l,r-=l}}function Wp(t){return t>=56320&&t<57344}function jp(t){return t>=55296&&t<56320}var E=class t{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,i=0,o){for(let s=0,a=0;a<n;s++){let l=this.content[s],c=a+l.nodeSize;if(c>e&&r(l,i+a,o||null,s)!==!1&&l.content.size){let u=a+1;l.nodesBetween(Math.max(0,e-u),Math.min(l.content.size,n-u),r,i+u)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(a,l)=>{let c=a.isText?a.text.slice(Math.max(e,l)-l,n-l):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&c||a.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)i.push(e.content[o]);return new t(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],i=0;if(n>e)for(let o=0,s=0;s<n;o++){let a=this.content[o],l=s+a.nodeSize;l>e&&((s<e||l>n)&&(a.isText?a=a.cut(Math.max(0,e-s),Math.min(a.text.length,n-s)):a=a.cut(Math.max(0,e-s-1),Math.min(a.content.size,n-s-1))),r.push(a),i+=a.nodeSize),s=l}return new t(r,i)}cutByIndex(e,n){return e==n?t.empty:e==0&&n==this.content.length?this:new t(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new t(i,o)}addToStart(e){return new t([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new t(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let i=this.content[n];e(i,r,n),r+=i.nodeSize}}findDiffStart(e,n=0){return Hp(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Vp(this,e,n,r)}findIndex(e){if(e==0)return qo(0,e);if(e==this.size)return qo(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),o=r+i.nodeSize;if(o>=e)return o==e?qo(n+1,o):qo(n,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return t.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return t.fromArray(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return t.empty;let n,r=0;for(let i=0;i<e.length;i++){let o=e[i];r+=o.nodeSize,i&&o.isText&&e[i-1].sameMarkup(o)?(n||(n=e.slice(0,i)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new t(n||e,r)}static from(e){if(!e)return t.empty;if(e instanceof t)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new t([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};E.empty=new E([],0);var ul={index:0,offset:0};function qo(t,e){return ul.index=t,ul.offset=e,ul}function Jo(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Jo(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Jo(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}var J=class t{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,i));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Jo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);let i=r.create(n.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return t.none;if(e instanceof t)return[e];let n=e.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}};J.none=[];var an=class extends Error{},A=class t{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Kp(this.content,e+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new t(r,this.openStart,this.openEnd)}removeBetween(e,n){return new t(qp(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return t.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new t(E.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new t(e,r,i)}};A.empty=new A(E.empty,0,0);function qp(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:a}=t.findIndex(n);if(i==e||o.isText){if(a!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(qp(o.content,e-i-1,n-i-1)))}function Kp(t,e,n,r,i,o){let{index:s,offset:a}=t.findIndex(e),l=t.maybeChild(s);if(a==e||l.isText)return o&&r<=0&&i<=0&&!o.canReplace(s,s,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=Kp(l.content,e-a-1,n,s==0?r-1:0,s==t.childCount-1?i-1:0,l);return c&&t.replaceChild(s,l.copy(c))}function z1(t,e,n){if(n.openStart>t.depth)throw new an("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new an("Inconsistent open depths");return Up(t,e,n,0)}function Up(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r<t.depth-n.openStart){let s=Up(t,e,n,r+1);return o.copy(o.content.replaceChild(i,s))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==r&&e.depth==r){let s=t.parent,a=s.content;return Fn(s,a.cut(0,t.parentOffset).append(n.content).append(a.cut(e.parentOffset)))}else{let{start:s,end:a}=$1(n,t);return Fn(o,Gp(t,s,a,e,r))}else return Fn(o,Go(t,e,r))}function Jp(t,e){if(!e.type.compatibleContent(t.type))throw new an("Cannot join "+e.type.name+" onto "+t.type.name)}function fl(t,e,n){let r=t.node(n);return Jp(r,e.node(n)),r}function Pn(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Ci(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(Pn(t.nodeAfter,r),o++));for(let a=o;a<s;a++)Pn(i.child(a),r);e&&e.depth==n&&e.textOffset&&Pn(e.nodeBefore,r)}function Fn(t,e){if(!t.type.validContent(e))throw new an("Invalid content for node "+t.type.name);return t.copy(e)}function Gp(t,e,n,r,i){let o=t.depth>i&&fl(t,e,i+1),s=r.depth>i&&fl(n,r,i+1),a=[];return Ci(null,t,i,a),o&&s&&e.index(i)==n.index(i)?(Jp(o,s),Pn(Fn(o,Gp(t,e,n,r,i+1)),a)):(o&&Pn(Fn(o,Go(t,e,i+1)),a),Ci(e,n,i,a),s&&Pn(Fn(s,Go(n,r,i+1)),a)),Ci(r,null,i,a),new E(a)}function Go(t,e,n){let r=[];if(Ci(null,t,n,r),t.depth>n){let i=fl(t,e,n+1);Pn(Fn(i,Go(t,e,n+1)),r)}return Ci(e,null,n,r),new E(r)}function $1(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(E.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}var Qo=class t{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o<e;o++)i+=r.child(o).nodeSize;return i}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return J.none;if(this.textOffset)return e.child(n).marks;let r=e.maybeChild(n-1),i=e.maybeChild(n);if(!r){let a=r;r=i,i=a}let o=r.marks;for(var s=0;s<o.length;s++)o[s].type.spec.inclusive===!1&&(!i||!o[s].isInSet(i.marks))&&(o=o[s--].removeFromSet(o));return o}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let r=n.marks,i=e.parent.maybeChild(e.index());for(var o=0;o<r.length;o++)r[o].type.spec.inclusive===!1&&(!i||!r[o].isInSet(i.marks))&&(r=r[o--].removeFromSet(r));return r}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Ei(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:a,offset:l}=s.content.findIndex(o),c=o-l;if(r.push(s,a,i+l),!c||(s=s.child(a),s.isText))break;o=c-1,i+=l+1}return new t(n,r,o)}static resolveCached(e,n){let r=Op.get(e);if(r)for(let o=0;o<r.elts.length;o++){let s=r.elts[o];if(s.pos==n)return s}else Op.set(e,r=new dl);let i=r.elts[r.i]=t.resolve(e,n);return r.i=(r.i+1)%_1,i}},dl=class{constructor(){this.elts=[],this.i=0}},_1=12,Op=new WeakMap,Ei=class{constructor(e,n,r){this.$from=e,this.$to=n,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},H1=Object.create(null),He=class t{constructor(e,n,r,i=J.none){this.type=e,this.attrs=n,this.marks=i,this.content=r||E.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,r,i=0){this.content.nodesBetween(e,n,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,r,i){return this.content.textBetween(e,n,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,r){return this.type==e&&Jo(this.attrs,n||e.defaultAttrs||H1)&&J.sameSet(this.marks,r||J.none)}copy(e=null){return e==this.content?this:new t(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new t(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,r=!1){if(e==n)return A.empty;let i=this.resolve(e),o=this.resolve(n),s=r?0:i.sharedDepth(n),a=i.start(s),c=i.node(s).content.cut(i.pos-a,o.pos-a);return new A(c,i.depth-s,o.depth-s)}replace(e,n,r){return z1(this.resolve(e),this.resolve(n),r)}nodeAt(e){for(let n=this;;){let{index:r,offset:i}=n.content.findIndex(e);if(n=n.maybeChild(r),!n)return null;if(i==e||n.isText)return n;e-=i+1}}childAfter(e){let{index:n,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(n),index:n,offset:r};let i=this.content.child(n-1);return{node:i,index:n-1,offset:r-i.nodeSize}}resolve(e){return Qo.resolveCached(this,e)}resolveNoCache(e){return Qo.resolve(this,e)}rangeHasMark(e,n,r){let i=!1;return n>e&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Qp(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=E.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),a=s&&s.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let l=i;l<o;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,n,r,i){if(i&&!this.type.allowsMarks(i))return!1;let o=this.contentMatchAt(e).matchType(r),s=o&&o.matchFragment(this.content,n);return s?s.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=J.none;for(let n=0;n<this.marks.length;n++){let r=this.marks[n];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!J.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=E.fromJSON(e,n.content),o=e.nodeType(n.type).create(n.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};He.prototype.text=void 0;var pl=class t extends He{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Qp(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new t(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new t(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Qp(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}var zn=class t{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new hl(e,n);if(r.next==null)return t.empty;let i=Yp(r);r.next&&r.err("Unexpected trailing text");let o=J1(U1(i));return G1(o,r),o}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,r=e.childCount){let i=this;for(let o=n;i&&o<r;o++)i=i.matchType(e.child(o).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let r=0;r<e.next.length;r++)if(this.next[n].type==e.next[r].type)return!0;return!1}fillBefore(e,n=!1,r=0){let i=[this];function o(s,a){let l=s.matchFragment(e,r);if(l&&(!n||l.validEnd))return E.from(a.map(c=>c.createAndFill()));for(let c=0;c<s.next.length;c++){let{type:u,next:f}=s.next[c];if(!(u.isText||u.hasRequiredAttrs())&&i.indexOf(f)==-1){i.push(f);let d=o(f,a.concat(u));if(d)return d}}return null}return o(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),o=i.match;if(o.matchType(e)){let s=[];for(let a=i;a.type;a=a.via)s.push(a.type);return s.reverse()}for(let s=0;s<o.next.length;s++){let{type:a,next:l}=o.next[s];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in n)&&(!i.type||l.validEnd)&&(r.push({match:a.contentMatch,type:a,via:i}),n[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&n(r.next[i].next)}return n(this),e.map((r,i)=>{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s<r.next.length;s++)o+=(s?", ":"")+r.next[s].type.name+"->"+e.indexOf(r.next[s].next);return o}).join(` +`)}};zn.empty=new zn(!0);var hl=class{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Yp(t){let e=[];do e.push(V1(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function V1(t){let e=[];do e.push(W1(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function W1(t){let e=K1(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=j1(t,e);else break;return e}function Dp(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function j1(t,e){let n=Dp(t),r=n;return t.eat(",")&&(t.next!="}"?r=Dp(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function q1(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function K1(t){if(t.eat("(")){let e=Yp(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=q1(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function U1(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,a,l){let c={term:l,to:a};return e[s].push(c),c}function i(s,a){s.forEach(l=>l.to=a)}function o(s,a){if(s.type=="choice")return s.exprs.reduce((l,c)=>l.concat(o(c,a)),[]);if(s.type=="seq")for(let l=0;;l++){let c=o(s.exprs[l],a);if(l==s.exprs.length-1)return c;i(c,a=n())}else if(s.type=="star"){let l=n();return r(a,l),i(o(s.expr,l),l),[r(l)]}else if(s.type=="plus"){let l=n();return i(o(s.expr,a),l),i(o(s.expr,l),l),[r(l)]}else{if(s.type=="opt")return[r(a)].concat(o(s.expr,a));if(s.type=="range"){let l=a;for(let c=0;c<s.min;c++){let u=n();i(o(s.expr,l),u),l=u}if(s.max==-1)i(o(s.expr,l),l);else for(let c=s.min;c<s.max;c++){let u=n();r(l,u),i(o(s.expr,l),u),l=u}return[r(l)]}else{if(s.type=="name")return[r(a,void 0,s.value)];throw new Error("Unknown expr type")}}}}function Xp(t,e){return e-t}function Bp(t,e){let n=[];return r(e),n.sort(Xp);function r(i){let o=t[i];if(o.length==1&&!o[0].term)return r(o[0].to);n.push(i);for(let s=0;s<o.length;s++){let{term:a,to:l}=o[s];!a&&n.indexOf(l)==-1&&r(l)}}}function J1(t){let e=Object.create(null);return n(Bp(t,0));function n(r){let i=[];r.forEach(s=>{t[s].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let u=0;u<i.length;u++)i[u][0]==a&&(c=i[u][1]);Bp(t,l).forEach(u=>{c||i.push([a,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let o=e[r.join(",")]=new zn(r.indexOf(t.length-1)>-1);for(let s=0;s<i.length;s++){let a=i[s][1].sort(Xp);o.next.push({type:i[s][0],next:e[a.join(",")]||n(a)})}return o}}function G1(t,e){for(let n=0,r=[t];n<r.length;n++){let i=r[n],o=!i.validEnd,s=[];for(let a=0;a<i.next.length;a++){let{type:l,next:c}=i.next[a];s.push(l.name),o&&!(l.isText||l.hasRequiredAttrs())&&(o=!1),r.indexOf(c)==-1&&r.push(c)}o&&e.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Zp(t){let e=Object.create(null);for(let n in t){let r=t[n];if(!r.hasDefault)return null;e[n]=r.default}return e}function eh(t,e){let n=Object.create(null);for(let r in t){let i=e&&e[r];if(i===void 0){let o=t[r];if(o.hasDefault)i=o.default;else throw new RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function th(t,e,n,r){for(let i in e)if(!(i in t))throw new RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let i in t)t[i].validate&&t[i].validate(e[i])}function nh(t,e){let n=Object.create(null);if(e)for(let r in e)n[r]=new ml(t,r,e[r]);return n}var Ti=class t{constructor(e,n,r){this.name=e,this.schema=n,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=nh(e,r.attrs),this.defaultAttrs=Zp(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==zn.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:eh(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new He(this,this.computeAttrs(e),E.from(n),J.setFrom(r))}createChecked(e=null,n,r){return n=E.from(n),this.checkContent(n),new He(this,this.computeAttrs(e),n,J.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=E.from(n),n.size){let s=this.contentMatch.fillBefore(n);if(!s)return null;n=s.append(n)}let i=this.contentMatch.matchFragment(n),o=i&&i.fillBefore(E.empty,!0);return o?new He(this,e,n.append(o),J.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){th(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?n&&n.push(e[r]):n||(n=e.slice(0,r));return n?n.length?n:J.none:e}static compile(e,n){let r=Object.create(null);e.forEach((o,s)=>r[o]=new t(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Q1(t,e,n){let r=n.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${o}`)}}var ml=class{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Q1(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}},vi=class t{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=nh(e,i.attrs),this.excluded=null;let o=Zp(this.attrs);this.instance=o?new J(this,o):null}create(e=null){return!e&&this.instance?this.instance:new J(this,eh(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new t(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}checkAttrs(e){th(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},Yo=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=cl.from(e.nodes),n.marks=cl.from(e.marks||{}),this.nodes=Ti.compile(this.spec.nodes,this),this.marks=vi.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",a=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=zn.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=a=="_"?null:a?Lp(this,a.split(" ")):a==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Lp(this,s.split(" "))}this.nodeFromJSON=i=>He.fromJSON(this,i),this.markFromJSON=i=>J.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ti){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new pl(r,r.defaultAttrs,e,J.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}};function Lp(t,e){let n=[];for(let r=0;r<e.length;r++){let i=e[r],o=t.marks[i],s=o;if(o)n.push(o);else for(let a in t.marks){let l=t.marks[a];(i=="_"||l.spec.group&&l.spec.group.split(" ").indexOf(i)>-1)&&n.push(s=l)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function Y1(t){return t.tag!=null}function X1(t){return t.style!=null}var ln=class t{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(Y1(i))this.tags.push(i);else if(X1(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,n={}){let r=new Xo(this,n,!1);return r.addAll(e,J.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Xo(this,n,!0);return r.addAll(e,J.none,n.from,n.to),A.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let o=this.tags[i];if(tS(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let s=o.getAttrs(e);if(s===!1)continue;o.attrs=s||void 0}return o}}}matchStyle(e,n,r,i){for(let o=i?this.styles.indexOf(i)+1:0;o<this.styles.length;o++){let s=this.styles[o],a=s.style;if(!(a.indexOf(e)!=0||s.context&&!r.matchesContext(s.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(s.getAttrs){let l=s.getAttrs(n);if(l===!1)continue;s.attrs=l||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s<n.length;s++){let a=n[s];if((a.priority==null?50:a.priority)<o)break}n.splice(s,0,i)}for(let i in e.marks){let o=e.marks[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Fp(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Fp(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new t(e,t.schemaRules(e)))}},rh={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Z1={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ih={ol:!0,ul:!0},Ii=1,gl=2,Mi=4;function Pp(t,e,n){return e!=null?(e?Ii:0)|(e==="full"?gl:0):t&&t.whitespace=="pre"?Ii|gl:n&~Mi}var xr=class{constructor(e,n,r,i,o,s){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=J.none,this.match=o||(s&Mi?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(E.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ii)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=E.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(E.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!rh.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Xo=class{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,o,s=Pp(null,n.preserveWhitespace,0)|(r?Mi:0);i?o=new xr(i.type,i.attrs,J.none,!0,n.topMatch||i.type.contentMatch,s):r?o=new xr(null,null,J.none,!0,null,s):o=new xr(e.schema.topNodeType,null,J.none,!0,null,s),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,o=i.options&gl?"full":this.localPreserveWS||(i.options&Ii)>0,{schema:s}=this.parser;if(o==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)if(o==="full")r=r.replace(/\r\n?/g,` +`);else if(s.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(s.linebreakReplacement.create())){let a=r.split(/\r?\n|\r/);for(let l=0;l<a.length;l++)l&&this.insertNode(s.linebreakReplacement.create(),n,!0),a[l]&&this.insertNode(s.text(a[l]),n,!/\S/.test(a[l]));r=""}else r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let a=i.content[i.content.length-1],l=e.previousSibling;(!a||l&&l.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(r=r.slice(1))}r&&this.insertNode(s.text(r),n,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,n,r){let i=this.localPreserveWS,o=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),a;ih.hasOwnProperty(s)&&this.parser.normalizeLists&&eS(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:Z1.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,n);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let c,u=this.needsBlock;if(rh.hasOwnProperty(s))o.content.length&&o.content[0].isInline&&this.open&&(this.open--,o=this.top),c=!0,o.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);break e}let f=l&&l.skip?n:this.readStyles(e,n);f&&this.addAll(e,f),c&&this.sync(o),this.needsBlock=u}else{let c=this.readStyles(e,n);c&&this.addElementByRule(e,l,c,l.consuming===!1?a:void 0)}this.localPreserveWS=i}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let r=e.style;if(r&&r.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let o=this.parser.matchedStyles[i],s=r.getPropertyValue(o);if(s)for(let a=void 0;;){let l=this.parser.matchStyle(o,s,this,a);if(!l)break;if(l.ignore)return null;if(l.clearMark?n=n.filter(c=>!l.clearMark(c)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return n}addElementByRule(e,n,r,i){let o,s;if(n.node)if(s=this.parser.schema.nodes[n.node],s.isLeaf)this.insertNode(s.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(s,n.attrs||null,r,n.preserveWhitespace);l&&(o=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let a=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}o&&this.sync(a)&&this.open--}addAll(e,n,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,a=i==null?null:e.childNodes[i];s!=a;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,n);this.findAtPoint(e,o)}findPlace(e,n,r){let i,o;for(let s=this.open,a=0;s>=0;s--){let l=this.nodes[s],c=l.findWrapping(e);if(c&&(!i||i.length>c.length+a)&&(i=c,o=l,!c.length))break;if(l.solid){if(r)break;a+=2}}if(!i)return null;this.sync(o);for(let s=0;s<i.length;s++)n=this.enterInner(i[s],null,n,!1);return n}insertNode(e,n,r){if(e.isInline&&this.needsBlock&&!this.top.type){let o=this.textblockFromContext();o&&(n=this.enterInner(o,null,n))}let i=this.findPlace(e,n,r);if(i){this.closeExtra();let o=this.top;o.match&&(o.match=o.match.matchType(e.type));let s=J.none;for(let a of i.concat(e.marks))(o.type?o.type.allowsMarkType(a.type):zp(a.type,e.type))&&(s=a.addToSet(s));return o.content.push(e.mark(s)),!0}return!1}enter(e,n,r,i){let o=this.findPlace(e.create(n),r,!1);return o&&(o=this.enterInner(e,n,r,!0,i)),o}enterInner(e,n,r,i=!1,o){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let a=Pp(e,o,s.options);s.options&Mi&&s.content.length==0&&(a|=Mi);let l=J.none;return r=r.filter(c=>(s.type?s.type.allowsMarkType(c.type):zp(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new xr(e,n,l,i,null,a)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=Ii)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(a,l)=>{for(;a>=0;a--){let c=n[a];if(c==""){if(a==n.length-1||a==0)continue;for(;l>=o;l--)if(s(a-1,l))return!0;return!1}else{let u=l>0||l==0&&i?this.nodes[l].type:r&&l>=o?r.node(l-o).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;l--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}};function eS(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ih.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function tS(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Fp(t){let e={};for(let n in t)e[n]=t[n];return e}function zp(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=a=>{o.push(a);for(let l=0;l<a.edgeCount;l++){let{type:c,next:u}=a.edge(l);if(c==e||o.indexOf(u)<0&&s(u))return!0}};if(s(i.contentMatch))return!0}}var cn=class t{constructor(e,n){this.nodes=e,this.marks=n}serializeFragment(e,n={},r){r||(r=Ko(n).createDocumentFragment());let i=r,o=[];return e.forEach(s=>{if(o.length||s.marks.length){let a=0,l=0;for(;a<o.length&&l<s.marks.length;){let c=s.marks[l];if(!this.marks[c.type.name]){l++;continue}if(!c.eq(o[a][0])||c.type.spec.spanning===!1)break;a++,l++}for(;a<o.length;)i=o.pop()[1];for(;l<s.marks.length;){let c=s.marks[l++],u=this.serializeMark(c,s.isInline,n);u&&(o.push([c,i]),i.appendChild(u.dom),i=u.contentDOM||u.dom)}}i.appendChild(this.serializeNodeInner(s,n))}),r}serializeNodeInner(e,n){if(e.isText)return Ko(n).createTextNode(e.text);let{dom:r,contentDOM:i}=Uo(Ko(n),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,n,i)}return r}serializeNode(e,n={}){let r=this.serializeNodeInner(e,n);for(let i=e.marks.length-1;i>=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Uo(Ko(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return typeof n=="string"?{dom:e.createTextNode(n)}:Uo(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new t(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=$p(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return $p(e.marks)}};function $p(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Ko(t){return t.document||window.document}var _p=new WeakMap;function nS(t){let e=_p.get(t);return e===void 0&&_p.set(t,e=rS(t)),e}function rS(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i<r.length;i++)n(r[i]);else for(let i in r)n(r[i])}return n(t),e}function Uo(t,e,n,r){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let i=e[0],o;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(o=nS(r))&&o.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let a,l=n?t.createElementNS(n,i):t.createElement(i),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let f in c)if(c[f]!=null){let d=f.indexOf(" ");d>0?l.setAttributeNS(f.slice(0,d),f.slice(d+1),c[f]):f=="style"&&l.style?l.style.cssText=c[f]:l.setAttribute(f,c[f])}}for(let f=u;f<e.length;f++){let d=e[f];if(d===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else if(typeof d=="string")l.appendChild(t.createTextNode(d));else{let{dom:p,contentDOM:h}=Uo(t,d,n,r);if(l.appendChild(p),h){if(a)throw new RangeError("Multiple content holes");a=h}}}return{dom:l,contentDOM:a}}var ah=65535,lh=Math.pow(2,16);function iS(t,e){return t+e*lh}function oh(t){return t&ah}function oS(t){return(t-(t&ah))/lh}var ch=1,uh=2,Zo=4,fh=8,Ri=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&fh)>0}get deletedBefore(){return(this.delInfo&(ch|Zo))>0}get deletedAfter(){return(this.delInfo&(uh|Zo))>0}get deletedAcross(){return(this.delInfo&Zo)>0}},$t=class t{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&t.empty)return t.empty}recover(e){let n=0,r=oh(e);if(!this.inverted)for(let i=0;i<r;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+n+oS(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let i=0,o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?i:0);if(l>e)break;let c=this.ranges[a+o],u=this.ranges[a+s],f=l+c;if(e<=f){let d=c?e==l?-1:e==f?1:n:n,p=l+i+(d<0?0:u);if(r)return p;let h=e==(n<0?l:f)?null:iS(a/3,e-l),m=e==l?uh:e==f?ch:Zo;return(n<0?e!=l:e!=f)&&(m|=fh),new Ri(p,m,h)}i+=u-c}return r?e+i:new Ri(e+i,0,null)}touches(e,n){let r=0,i=oh(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?r:0);if(l>e)break;let c=this.ranges[a+o],u=l+c;if(e<=u&&a==i*3)return!0;r+=this.ranges[a+s]-c}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let s=this.ranges[i],a=s-(this.inverted?o:0),l=s+(this.inverted?0:o),c=this.ranges[i+n],u=this.ranges[i+r];e(a,a+c,l,l+u),o+=u-c}}invert(){return new t(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?t.empty:new t(e<0?[0,-e,0]:[0,0,e])}};$t.empty=new $t([]);var xl=class t{constructor(e,n,r=0,i=e?e.length:0){this.mirror=n,this.from=r,this.to=i,this._maps=e||[],this.ownData=!(e||n)}get maps(){return this._maps}slice(e=0,n=this.maps.length){return new t(this._maps,this.mirror,e,n)}appendMap(e,n){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),n!=null&&this.setMirror(this._maps.length-1,n)}appendMapping(e){for(let n=0,r=this._maps.length;n<e._maps.length;n++){let i=e.getMirror(n);this.appendMap(e._maps[n],i!=null&&i<n?r+i:void 0)}}getMirror(e){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==e)return this.mirror[n+(n%2?-1:1)]}}setMirror(e,n){this.mirror||(this.mirror=[]),this.mirror.push(e,n)}appendMappingInverted(e){for(let n=e.maps.length-1,r=this._maps.length+e._maps.length;n>=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new t;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;r<this.to;r++)e=this._maps[r].map(e,n);return e}mapResult(e,n=1){return this._map(e,n,!1)}_map(e,n,r){let i=0;for(let o=this.from;o<this.to;o++){let s=this._maps[o],a=s.mapResult(e,n);if(a.recover!=null){let l=this.getMirror(o);if(l!=null&&l>o&&l<this.to){o=l,e=this._maps[l].recover(a.recover);continue}}i|=a.delInfo,e=a.pos}return r?e:new Ri(e,i,null)}},yl=Object.create(null),xe=class{getMap(){return $t.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=yl[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in yl)throw new RangeError("Duplicate use of step JSON ID "+e);return yl[e]=n,n.prototype.jsonID=e,n}},Ee=class t{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new t(e,null)}static fail(e){return new t(null,e)}static fromReplace(e,n,r,i){try{return t.ok(e.replace(n,r,i))}catch(o){if(o instanceof an)return t.fail(o.message);throw o}}};function Cl(t,e,n){let r=[];for(let i=0;i<t.childCount;i++){let o=t.child(i);o.content.size&&(o=o.copy(Cl(o.content,e,o))),o.isInline&&(o=e(o,n,i)),r.push(o)}return E.fromArray(r)}var $n=class t extends xe{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),o=new A(Cl(n.content,(s,a)=>!s.isAtom||!a.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Ee.fromReplace(e,this.from,this.to,o)}invert(){return new _n(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};xe.jsonID("addMark",$n);var _n=class t extends xe{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new A(Cl(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Ee.fromReplace(e,this.from,this.to,r)}invert(){return new $n(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new t(n.pos,r.pos,this.mark)}merge(e){return e instanceof t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new t(n.from,n.to,e.markFromJSON(n.mark))}};xe.jsonID("removeMark",_n);var Oi=class t extends xe{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Ee.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Ee.fromReplace(e,this.pos,this.pos+1,new A(E.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(r))return new t(this.pos,n.marks[i]);return new t(this.pos,this.mark)}}return new wr(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new t(n.pos,e.markFromJSON(n.mark))}};xe.jsonID("addNodeMark",Oi);var wr=class t extends xe{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Ee.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Ee.fromReplace(e,this.pos,this.pos+1,new A(E.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Oi(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new t(n.pos,e.markFromJSON(n.mark))}};xe.jsonID("removeNodeMark",wr);var de=class t extends xe{constructor(e,n,r,i=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=i}apply(e){return this.structure&&wl(e,this.from,this.to)?Ee.fail("Structure replace would overwrite content"):Ee.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new $t([this.from,this.to-this.from,this.slice.size])}invert(e){return new t(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.to,-1),r=this.from==this.to&&t.MAP_BIAS<0?n:e.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new t(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof t)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?A.empty:new A(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new t(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?A.empty:new A(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new t(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new t(n.from,n.to,A.fromJSON(e,n.slice),!!n.structure)}};de.MAP_BIAS=1;xe.jsonID("replace",de);var Te=class t extends xe{constructor(e,n,r,i,o,s,a=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=s,this.structure=a}apply(e){if(this.structure&&(wl(e,this.from,this.gapFrom)||wl(e,this.gapTo,this.to)))return Ee.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Ee.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Ee.fromReplace(e,this.from,this.to,r):Ee.fail("Content does not fit in gap")}getMap(){return new $t([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new t(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),o=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||o>r.pos?null:new t(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new t(n.from,n.to,n.gapFrom,n.gapTo,A.fromJSON(e,n.slice),n.insert,!!n.structure)}};xe.jsonID("replaceAround",Te);function wl(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function sS(t,e,n,r){let i=[],o=[],s,a;t.doc.nodesBetween(e,n,(l,c,u)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+l.nodeSize,n),h=r.addToSet(f);for(let m=0;m<f.length;m++)f[m].isInSet(h)||(s&&s.to==d&&s.mark.eq(f[m])?s.to=p:i.push(s=new _n(d,p,f[m])));a&&a.to==d?a.to=p:o.push(a=new $n(d,p,r))}}),i.forEach(l=>t.step(l)),o.forEach(l=>t.step(l))}function aS(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,a)=>{if(!s.isInline)return;o++;let l=null;if(r instanceof vi){let c=s.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(s.marks)&&(l=[r]):l=s.marks;if(l&&l.length){let c=Math.min(a+s.nodeSize,n);for(let u=0;u<l.length;u++){let f=l[u],d;for(let p=0;p<i.length;p++){let h=i[p];h.step==o-1&&f.eq(i[p].style)&&(d=h)}d?(d.to=c,d.step=o):i.push({style:f,from:Math.max(a,e),to:c,step:o})}}}),i.forEach(s=>t.step(new _n(s.from,s.to,s.style)))}function Ml(t,e,n,r=n.contentMatch,i=!0){let o=t.doc.nodeAt(e),s=[],a=e+1;for(let l=0;l<o.childCount;l++){let c=o.child(l),u=a+c.nodeSize,f=r.matchType(c.type);if(!f)s.push(new de(a,u,A.empty));else{r=f;for(let d=0;d<c.marks.length;d++)n.allowsMarkType(c.marks[d].type)||t.step(new _n(a,u,c.marks[d]));if(i&&c.isText&&n.whitespace!="pre"){let d,p=/\r?\n|\r/g,h;for(;d=p.exec(c.text);)h||(h=new A(E.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),s.push(new de(a+d.index,a+d.index+d[0].length,h))}}a=u}if(!r.validEnd){let l=r.fillBefore(E.empty,!0);t.replace(a,a,new A(l,0,0))}for(let l=s.length-1;l>=0;l--)t.step(s[l])}function lS(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Mr(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,o=0;;--r){let s=t.$from.node(r),a=t.$from.index(r)+i,l=t.$to.indexAfter(r)-o;if(r<t.depth&&s.canReplace(a,l,n))return r;if(r==0||s.type.spec.isolating||!lS(s,a,l))break;a&&(i=1),l<s.childCount&&(o=1)}return null}function cS(t,e,n){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),a=i.after(o+1),l=s,c=a,u=E.empty,f=0;for(let h=o,m=!1;h>n;h--)m||r.index(h)>0?(m=!0,u=E.from(r.node(h).copy(u)),f++):l--;let d=E.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)<i.end(h)?(m=!0,d=E.from(i.node(h).copy(d)),p++):c++;t.step(new Te(l,c,s,a,new A(u.append(d),f,p),u.size-f,!0))}function Hn(t,e,n=null,r=t){let i=uS(t,e),o=i&&fS(r,e);return o?i.map(sh).concat({type:e,attrs:n}).concat(o.map(sh)):null}function sh(t){return{type:t,attrs:null}}function uS(t,e){let{parent:n,startIndex:r,endIndex:i}=t,o=n.contentMatchAt(r).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return n.canReplaceWith(r,i,s)?o:null}function fS(t,e){let{parent:n,startIndex:r,endIndex:i}=t,o=n.child(r),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let l=(s.length?s[s.length-1]:e).contentMatch;for(let c=r;l&&c<i;c++)l=l.matchType(n.child(c).type);return!l||!l.validEnd?null:s}function dS(t,e,n){let r=E.empty;for(let s=n.length-1;s>=0;s--){if(r.size){let a=n[s].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=E.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new Te(i,o,i,o,new A(r,0,0),n.length,!0))}function pS(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,a)=>{let l=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,l)&&hS(t.doc,t.mapping.slice(o).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!h?c=!1:!p&&h&&(c=!0)}c===!1&&ph(t,s,a,o),Ml(t,t.mapping.slice(o).map(a,1),r,void 0,c===null);let u=t.mapping.slice(o),f=u.map(a,1),d=u.map(a+s.nodeSize,1);return t.step(new Te(f,d,f+1,d-1,new A(E.from(r.create(l,null,s.marks)),0,0),1,!0)),c===!0&&dh(t,s,a,o),!1}})}function dh(t,e,n,r){e.forEach((i,o)=>{if(i.isText){let s,a=/\r?\n|\r/g;for(;s=a.exec(i.text);){let l=t.mapping.slice(r).map(n+1+o+s.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function ph(t,e,n,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(n+1+o);t.replaceWith(s,s+1,e.type.schema.text(` +`))}})}function hS(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function mS(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Te(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new A(E.from(s),0,0),1,!0))}function Vn(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,u=n-2;c>o;c--,u--){let f=i.node(c),d=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[u+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=r&&r[u]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(p))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function gS(t,e,n=1,r){let i=t.doc.resolve(e),o=E.empty,s=E.empty;for(let a=i.depth,l=i.depth-n,c=n-1;a>l;a--,c--){o=E.from(i.node(a).copy(o));let u=r&&r[c];s=E.from(u?u.type.create(u.attrs,s):i.node(a).copy(s))}t.step(new de(e,e,new A(o.append(s),n,n),!0))}function Wn(t,e){let n=t.resolve(e),r=n.index();return kS(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function yS(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i<e.childCount;i++){let o=e.child(i),s=o.type==r?t.type.schema.nodes.text:o.type;if(n=n.matchType(s),!n||!t.type.allowsMarks(o.marks))return!1}return n.validEnd}function kS(t,e){return!!(t&&e&&!t.isLeaf&&yS(t,e))}function bS(t,e,n){let r=null,{linebreakReplacement:i}=t.doc.type.schema,o=t.doc.resolve(e-n),s=o.node().type;if(i&&s.inlineContent){let u=s.whitespace=="pre",f=!!s.contentMatch.matchType(i);u&&!f?r=!1:!u&&f&&(r=!0)}let a=t.steps.length;if(r===!1){let u=t.doc.resolve(e+n);ph(t,u.node(),u.before(),a)}s.inlineContent&&Ml(t,e+n-1,s,o.node().contentMatchAt(o.index()),r==null);let l=t.mapping.slice(a),c=l.map(e-n);if(t.step(new de(c,l.map(e+n,-1),A.empty,!0)),r===!0){let u=t.doc.resolve(c);dh(t,u.node(),u.before(),t.steps.length)}return t}function xS(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o<r.node(i).childCount)return null}return null}function hh(t,e,n){let r=t.resolve(e);if(!n.content.size)return e;let i=n.content;for(let o=0;o<n.openStart;o++)i=i.firstChild.content;for(let o=1;o<=(n.openStart==0&&n.size?2:1);o++)for(let s=r.depth;s>=0;s--){let a=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,l=r.index(s)+(a>0?1:0),c=r.node(s),u=!1;if(o==1)u=c.canReplace(l,l,i);else{let f=c.contentMatchAt(l).findWrapping(i.firstChild.type);u=f&&c.canReplaceWith(l,l,f[0])}if(u)return a==0?r.pos:a<0?r.before(s+1):r.after(s+1)}return null}function Di(t,e,n=e,r=A.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return mh(i,o,r)?new de(e,n,r):new Sl(i,o,r).fit()}function mh(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}var Sl=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=E.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=E.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,a=i.depth;for(;s&&a&&o.childCount==1;)o=o.firstChild.content,s--,a--;let l=new A(o,s,a);return e>-1?new Te(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new de(r.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r<e;r++){let o=n.firstChild;if(n.childCount>1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=kl(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],u,f=null;if(n==1&&(s?c.matchType(s.type)||(f=c.fillBefore(E.from(s),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:a,parent:o,inject:f};if(n==2&&s&&(u=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:a,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=kl(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new A(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=kl(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new A(Ai(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new A(Ai(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m<o.length;m++)this.openFrontierNode(o[m]);let s=this.unplaced,a=r?r.content:s.content,l=s.openStart-e,c=0,u=[],{match:f,type:d}=this.frontier[n];if(i){for(let m=0;m<i.childCount;m++)u.push(i.child(m));f=f.matchFragment(i)}let p=a.size+e-(s.content.size-s.openEnd);for(;c<a.childCount;){let m=a.child(c),g=f.matchType(m.type);if(!g)break;c++,(c>1||l==0||m.content.size)&&(f=g,u.push(gh(m.mark(d.allowedMarks(m.marks)),c==1?l:0,c==a.childCount?p:-1)))}let h=c==a.childCount;h||(p=-1),this.placed=Ni(this.placed,n,E.from(u)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=a;m<p;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=h?e==0?A.empty:new A(Ai(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new A(Ai(s.content,e,c),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],n;if(!e.type.isTextblock||!bl(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(n=this.findCloseLevel(this.$to))&&n.depth==this.depth)return-1;let{depth:r}=this.$to,i=this.$to.after(r);for(;r>1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n<e.depth&&e.end(n+1)==e.pos+(e.depth-(n+1)),s=bl(e,n,i,r,o);if(s){for(let a=n-1;a>=0;a--){let{match:l,type:c}=this.frontier[a],u=bl(e,a,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Ni(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ni(this.placed,this.depth,E.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(E.empty,!0);n.childCount&&(this.placed=Ni(this.placed,this.frontier.length,n))}};function Ai(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Ai(t.firstChild.content,e-1,n)))}function Ni(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Ni(t.lastChild.content,e-1,n)))}function kl(t,e){for(let n=0;n<e;n++)t=t.firstChild.content;return t}function gh(t,e,n){if(e<=0)return t;let r=t.content;return e>1&&(r=r.replaceChild(0,gh(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(E.empty,!0)))),t.copy(r)}function bl(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!wS(n,o.content,s)?a:null}function wS(t,e,n){for(let r=n;r<e.childCount;r++)if(!t.allowsMarks(e.child(r).marks))return!0;return!1}function SS(t){return t.spec.defining||t.spec.definingForContent}function CS(t,e,n,r){if(!r.size)return t.deleteRange(e,n);let i=t.doc.resolve(e),o=t.doc.resolve(n);if(mh(i,o,r))return t.step(new de(e,n,r));let s=kh(i,o);s[s.length-1]==0&&s.pop();let a=-(i.depth+1);s.unshift(a);for(let d=i.depth,p=i.pos-1;d>0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?a=d:i.before(d)==p&&s.splice(1,0,-d)}let l=s.indexOf(a),c=[],u=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(c.push(h),p==r.openStart)break;d=h.content}for(let d=u-1;d>=0;d--){let p=c[d],h=SS(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(a)-1)))u=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+u+1)%(r.openStart+1),h=c[p];if(h)for(let m=0;m<s.length;m++){let g=s[(m+l)%s.length],y=!0;g<0&&(y=!1,g=-g);let x=i.node(g-1),C=i.index(g-1);if(x.canReplaceWith(C,C,h.type,h.marks))return t.replace(i.before(g),y?o.after(g):n,new A(yh(r.content,0,r.openStart,p),p,r.openEnd))}}let f=t.steps.length;for(let d=s.length-1;d>=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function yh(t,e,n,r,i){if(e<n){let o=t.firstChild;t=t.replaceChild(0,o.copy(yh(o.content,e+1,n,r,o)))}if(e>r){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(E.empty,!0))}return t}function MS(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=xS(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new A(E.from(r),0,0))}function ES(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let s=r.sharedDepth(n),a=!1;for(let l=r.depth;l>s;l--)r.node(l).type.spec.isolating&&(a=!0);for(let l=i.depth;l>s;l--)i.node(l).type.spec.isolating&&(a=!0);if(!a){for(let l=r.depth;l>0&&e==r.start(l);l--)e=r.before(l);for(let l=i.depth;l>0&&n==i.start(l);l--)n=i.before(l);r=t.doc.resolve(e),i=t.doc.resolve(n)}}let o=kh(r,i);for(let s=0;s<o.length;s++){let a=o[s],l=s==o.length-1;if(l&&a==0||r.node(a).type.contentMatch.validEnd)return t.delete(r.start(a),i.end(a));if(a>0&&(l||r.node(a-1).canReplace(r.index(a-1),i.indexAfter(a-1))))return t.delete(r.before(a),i.after(a))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return t.delete(r.before(s),n);t.delete(e,n)}function kh(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(o<t.pos-(t.depth-i)||e.end(i)>e.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}var es=class t extends xe{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Ee.fromReplace(e,this.pos,this.pos+1,new A(E.from(i),0,n.isLeaf?0:1))}getMap(){return $t.empty}invert(e){return new t(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new t(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new t(n.pos,n.attr,n.value)}};xe.jsonID("attr",es);var ts=class t extends xe{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Ee.ok(r)}getMap(){return $t.empty}invert(e){return new t(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new t(n.attr,n.value)}};xe.jsonID("docAttr",ts);var Sr=class extends Error{};Sr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Sr.prototype=Object.create(Error.prototype);Sr.prototype.constructor=Sr;Sr.prototype.name="TransformError";var Cr=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new xl}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Sr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r<this.mapping.maps.length;r++){let i=this.mapping.maps[r];r&&(e=i.map(e,1),n=i.map(n,-1)),i.forEach((o,s,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=A.empty){let i=Di(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new A(E.from(r),0,0))}delete(e,n){return this.replace(e,n,A.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return CS(this,e,n,r),this}replaceRangeWith(e,n,r){return MS(this,e,n,r),this}deleteRange(e,n){return ES(this,e,n),this}lift(e,n){return cS(this,e,n),this}join(e,n=1){return bS(this,e,n),this}wrap(e,n){return dS(this,e,n),this}setBlockType(e,n=e,r,i=null){return pS(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return mS(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new es(e,n,r)),this}setDocAttribute(e,n){return this.step(new ts(e,n)),this}addNodeMark(e,n){return this.step(new Oi(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof J)n.isInSet(r.marks)&&this.step(new wr(e,n));else{let i=r.marks,o,s=[];for(;o=n.isInSet(i);)s.push(new wr(e,o)),i=o.removeFromSet(i);for(let a=s.length-1;a>=0;a--)this.step(s[a])}return this}split(e,n=1,r){return gS(this,e,n,r),this}addMark(e,n,r){return sS(this,e,n,r),this}removeMark(e,n,r){return aS(this,e,n,r),this}clearIncompatible(e,n,r){return Ml(this,e,n,r),this}};var El=Object.create(null),$=class{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new un(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=A.empty){let r=n.content.lastChild,i=null;for(let a=0;a<n.openEnd;a++)i=r,r=r.lastChild;let o=e.steps.length,s=this.ranges;for(let a=0;a<s.length;a++){let{$from:l,$to:c}=s[a],u=e.mapping.slice(o);e.replaceRange(u.map(l.pos),u.map(c.pos),a?A.empty:n),a==0&&wh(e,o,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:s,$to:a}=i[o],l=e.mapping.slice(r),c=l.map(s.pos),u=l.map(a.pos);o?e.deleteRange(c,u):(e.replaceRangeWith(c,u,n),wh(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let i=e.parent.inlineContent?new z(e):Er(e.node(0),e.parent,e.pos,e.index(),n,r);if(i)return i;for(let o=e.depth-1;o>=0;o--){let s=n<0?Er(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Er(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new Ke(e.node(0))}static atStart(e){return Er(e,e,0,0,1)||new Ke(e)}static atEnd(e){return Er(e,e,e.content.size,e.childCount,-1)||new Ke(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=El[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in El)throw new RangeError("Duplicate use of selection JSON ID "+e);return El[e]=n,n.prototype.jsonID=e,n}getBookmark(){return z.between(this.$anchor,this.$head).getBookmark()}};$.prototype.visible=!0;var un=class{constructor(e,n){this.$from=e,this.$to=n}},bh=!1;function xh(t){!bh&&!t.parent.inlineContent&&(bh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}var z=class t extends ${constructor(e,n=e){xh(e),xh(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return $.near(r);let i=e.resolve(n.map(this.anchor));return new t(i.parent.inlineContent?i:r,r)}replace(e,n=A.empty){if(super.replace(e,n),n==A.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof t&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new rs(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new t(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=$.findFrom(n,r,!0)||$.findFrom(n,-r,!0);if(o)n=o.$head;else return $.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=($.findFrom(e,-r,!0)||$.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=i<0&&(e=n))),new t(e,n)}};$.jsonID("text",z);var rs=class t{constructor(e,n){this.anchor=e,this.head=n}map(e){return new t(e.map(this.anchor),e.map(this.head))}resolve(e){return z.between(e.resolve(this.anchor),e.resolve(this.head))}},H=class t extends ${constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),o=e.resolve(i);return r?$.near(o):new t(o)}content(){return new A(E.from(this.node),0,0)}eq(e){return e instanceof t&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new vl(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new t(e.resolve(n.anchor))}static create(e,n){return new t(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};H.prototype.visible=!1;$.jsonID("node",H);var vl=class t{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new rs(r,r):new t(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&H.isSelectable(r)?new H(n):$.near(n)}},Ke=class t extends ${constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=A.empty){if(n==A.empty){e.delete(0,e.doc.content.size);let r=$.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new t(e)}map(e){return new t(e)}eq(e){return e instanceof t}getBookmark(){return TS}};$.jsonID("all",Ke);var TS={map(){return this},resolve(t){return new Ke(t)}};function Er(t,e,n,r,i,o=!1){if(e.inlineContent)return z.create(t,n);for(let s=r-(i>0?0:1);i>0?s<e.childCount:s>=0;s+=i){let a=e.child(s);if(a.isAtom){if(!o&&H.isSelectable(a))return H.create(t,n-(i<0?a.nodeSize:0))}else{let l=Er(t,a,n+i,i<0?a.childCount:0,i,o);if(l)return l}n+=a.nodeSize*i}return null}function wh(t,e,n){let r=t.steps.length-1;if(r<e)return;let i=t.steps[r];if(!(i instanceof de||i instanceof Te))return;let o=t.mapping.maps[r],s;o.forEach((a,l,c,u)=>{s==null&&(s=u)}),t.setSelection($.near(t.doc.resolve(s),n))}var Sh=1,ns=2,Ch=4,Il=class extends Cr{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Sh)&~ns,this.storedMarks=null,this}get selectionSet(){return(this.updated&Sh)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=ns,this}ensureMarks(e){return J.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&ns)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~ns,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||J.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection($.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Ch,this}get scrolledIntoView(){return(this.updated&Ch)>0}};function Mh(t,e){return!e||!t?t:t.bind(e)}var jn=class{constructor(e,n,r){this.name=e,this.init=Mh(n.init,r),this.apply=Mh(n.apply,r)}},vS=[new jn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new jn("selection",{init(t,e){return t.selection||$.atStart(e.doc)},apply(t){return t.selection}}),new jn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new jn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})],Bi=class{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=vS.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new jn(r.key,r.spec.state,r))})}},Tr=class t{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=n){let i=this.config.plugins[r];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let n=[e],r=this.applyInner(e),i=null;for(;;){let o=!1;for(let s=0;s<this.config.plugins.length;s++){let a=this.config.plugins[s];if(a.spec.appendTransaction){let l=i?i[s].n:0,c=i?i[s].state:this,u=l<n.length&&a.spec.appendTransaction.call(a,l?n.slice(l):n,c,r);if(u&&r.filterTransaction(u,s)){if(u.setMeta("appendedTransaction",e),!i){i=[];for(let f=0;f<this.config.plugins.length;f++)i.push(f<s?{state:r,n:n.length}:{state:this,n:0})}n.push(u),r=r.applyInner(u),o=!0}i&&(i[s]={state:r,n:n.length})}}if(!o)return{state:r,transactions:n}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let n=new t(this.config),r=this.config.fields;for(let i=0;i<r.length;i++){let o=r[i];n[o.name]=o.apply(e,this[o.name],this,n)}return n}get tr(){return new Il(this)}static create(e){let n=new Bi(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new t(n);for(let i=0;i<n.fields.length;i++)r[n.fields[i].name]=n.fields[i].init(e,r);return r}reconfigure(e){let n=new Bi(this.schema,e.plugins),r=n.fields,i=new t(n);for(let o=0;o<r.length;o++){let s=r[o].name;i[s]=this.hasOwnProperty(s)?this[s]:r[o].init(e,i)}return i}toJSON(e){let n={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(n.storedMarks=this.storedMarks.map(r=>r.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Bi(e.schema,e.plugins),o=new t(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=He.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=$.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let l=r[a],c=l.spec.state;if(l.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){o[s.name]=c.fromJSON.call(l,e,n[a],o);return}}o[s.name]=s.init(e,o)}}),o}};function Eh(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Eh(i,e,{})),n[r]=i}return n}var X=class{constructor(e){this.spec=e,this.props={},e.props&&Eh(e.props,this,this.props),this.key=e.key?e.key.key:Th("plugin")}getState(e){return e[this.key]}},Tl=Object.create(null);function Th(t){return t in Tl?t+"$"+ ++Tl[t]:(Tl[t]=0,t+"$")}var te=class{constructor(e="key"){this.key=Th(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var is=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function Ih(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}var Nl=(t,e,n)=>{let r=Ih(t,n);if(!r)return!1;let i=Ol(r);if(!i){let s=r.blockRange(),a=s&&Mr(s);return a==null?!1:(e&&e(t.tr.lift(s,a).scrollIntoView()),!0)}let o=i.nodeBefore;if(Rh(t,i,e,-1))return!0;if(r.parent.content.size==0&&(vr(o,"end")||H.isSelectable(o)))for(let s=r.depth;;s--){let a=Di(t.doc,r.before(s),r.after(s),A.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=t.tr.step(a);l.setSelection(vr(o,"end")?$.findFrom(l.doc.resolve(l.mapping.map(i.pos,-1)),-1):H.create(l.doc,i.pos-o.nodeSize)),e(l.scrollIntoView())}return!0}if(s==1||r.node(s-1).childCount>1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1},Ah=(t,e,n)=>{let r=Ih(t,n);if(!r)return!1;let i=Ol(r);return i?IS(t,i,e):!1};function IS(t,e,n){let r=e.nodeBefore,i=r,o=e.pos-1;for(;!i.isTextblock;o--){if(i.type.spec.isolating)return!1;let u=i.lastChild;if(!u)return!1;i=u}let s=e.nodeAfter,a=s,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let u=a.firstChild;if(!u)return!1;a=u}let c=Di(t.doc,o,l,A.empty);if(!c||c.from!=o||c instanceof de&&c.slice.size>=l-o)return!1;if(n){let u=t.tr.step(c);u.setSelection(z.create(u.doc,o)),n(u.scrollIntoView())}return!0}function vr(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Rl=(t,e,n)=>{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;o=Ol(r)}let s=o&&o.nodeBefore;return!s||!H.isSelectable(s)?!1:(e&&e(t.tr.setSelection(H.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Ol(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function AS(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)?null:n}var NS=(t,e,n)=>{let r=AS(t,n);if(!r)return!1;let i=Nh(r);if(!i)return!1;let o=i.nodeAfter;if(Rh(t,i,e,1))return!0;if(r.parent.content.size==0&&(vr(o,"start")||H.isSelectable(o))){let s=Di(t.doc,r.before(),r.after(),A.empty);if(s&&s.slice.size<s.to-s.from){if(e){let a=t.tr.step(s);a.setSelection(vr(o,"start")?$.findFrom(a.doc.resolve(a.mapping.map(i.pos)),1):H.create(a.doc,a.mapping.map(i.pos))),e(a.scrollIntoView())}return!0}}return o.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos,i.pos+o.nodeSize).scrollIntoView()),!0):!1},RS=(t,e,n)=>{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset<r.parent.content.size)return!1;o=Nh(r)}let s=o&&o.nodeAfter;return!s||!H.isSelectable(s)?!1:(e&&e(t.tr.setSelection(H.create(t.doc,o.pos)).scrollIntoView()),!0)};function Nh(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let n=t.node(e);if(t.index(e)+1<n.childCount)return t.doc.resolve(t.after(e+1));if(n.type.spec.isolating)break}return null}var OS=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` +`).scrollIntoView()),!0)};function Dl(t){for(let e=0;e<t.edgeCount;e++){let{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var DS=(t,e)=>{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=Dl(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let a=n.after(),l=t.tr.replaceWith(a,a,s.createAndFill());l.setSelection($.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},BS=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof Ke||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Dl(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,a=t.tr.insert(s,o.createAndFill());a.setSelection(z.create(a.doc,s+1)),e(a.scrollIntoView())}return!0},LS=(t,e)=>{let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if(Vn(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Mr(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function PS(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof H&&e.selection.node.isBlock)return!r.parentOffset||!Vn(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,a,l=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){l=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),a=Dl(r.node(p-1).contentMatchAt(r.indexAfter(p-1)));let m=t&&t(i.parent,l,r);o.unshift(m||(l&&a?{type:a}:null)),s=p;break}else{if(p==1)return!1;o.unshift(null)}let u=e.tr;(e.selection instanceof z||e.selection instanceof Ke)&&u.deleteSelection();let f=u.mapping.map(r.pos),d=Vn(u.doc,f,o.length,o);if(d||(o[0]=a?{type:a}:null,d=Vn(u.doc,f,o.length,o)),!d)return!1;if(u.split(f,o.length,o),!l&&c&&r.node(s).type!=a){let p=u.mapping.map(r.before(s)),h=u.doc.resolve(p);a&&r.node(s-1).canReplaceWith(h.index(),h.index()+1,a)&&u.setNodeMarkup(u.mapping.map(r.before(s)),a)}return n&&n(u.scrollIntoView()),!0}}var FS=PS();var zS=(t,e)=>(e&&e(t.tr.setSelection(new Ke(t.doc))),!0);function $S(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||Wn(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function Rh(t,e,n,r){let i=e.nodeBefore,o=e.nodeAfter,s,a,l=i.type.spec.isolating||o.type.spec.isolating;if(!l&&$S(t,e,n))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(s=(a=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&a.matchType(s[0]||o.type).validEnd){if(n){let p=e.pos+o.nodeSize,h=E.empty;for(let y=s.length-1;y>=0;y--)h=E.from(s[y].create(null,h));h=E.from(i.copy(h));let m=t.tr.step(new Te(e.pos-1,p,e.pos,p,new A(h,1,0),s.length,!0)),g=m.doc.resolve(p+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Wn(m.doc,g.pos)&&m.join(g.pos),n(m.scrollIntoView())}return!0}let u=o.type.spec.isolating||r>0&&l?null:$.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),d=f&&Mr(f);if(d!=null&&d>=e.depth)return n&&n(t.tr.lift(f,d).scrollIntoView()),!0;if(c&&vr(o,"start",!0)&&vr(i,"end")){let p=i,h=[];for(;h.push(p),!p.isTextblock;)p=p.lastChild;let m=o,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(n){let y=E.empty;for(let C=h.length-1;C>=0;C--)y=E.from(h[C].copy(y));let x=t.tr.step(new Te(e.pos-h.length,e.pos+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new A(y,h.length,0),0,!0));n(x.scrollIntoView())}return!0}}return!1}function Oh(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(n&&n(e.tr.setSelection(z.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}var _S=Oh(-1),HS=Oh(1);function ss(t,e=null){return function(n,r){let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=s&&Hn(s,t,e);return a?(r&&r(n.tr.wrap(s,a).scrollIntoView()),!0):!1}}function Ir(t,e=null){return function(n,r){let i=!1;for(let o=0;o<n.selection.ranges.length&&!i;o++){let{$from:{pos:s},$to:{pos:a}}=n.selection.ranges[o];n.doc.nodesBetween(s,a,(l,c)=>{if(i)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)i=!0;else{let u=n.doc.resolve(c),f=u.index();i=u.parent.canReplaceWith(f,f+1,t)}})}if(!i)return!1;if(r){let o=n.tr;for(let s=0;s<n.selection.ranges.length;s++){let{$from:{pos:a},$to:{pos:l}}=n.selection.ranges[s];o.setBlockType(a,l,t,e)}r(o.scrollIntoView())}return!0}}function VS(t,e,n,r){for(let i=0;i<e.length;i++){let{$from:o,$to:s}=e[i],a=o.depth==0?t.inlineContent&&t.type.allowsMarkType(n):!1;if(t.nodesBetween(o.pos,s.pos,(l,c)=>{if(a||!r&&l.isAtom&&l.isInline&&c>=o.pos&&c+l.nodeSize<=s.pos)return!1;a=l.inlineContent&&l.type.allowsMarkType(n)}),a)return!0}return!1}function WS(t){let e=[];for(let n=0;n<t.length;n++){let{$from:r,$to:i}=t[n];r.doc.nodesBetween(r.pos,i.pos,(o,s)=>{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new un(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.pos<i.pos&&e.push(new un(r,i))}return e}function Ar(t,e=null,n){let r=(n&&n.removeWhenPresent)!==!1,i=(n&&n.enterInlineAtoms)!==!1,o=!(n&&n.includeWhitespace);return function(s,a){let{empty:l,$cursor:c,ranges:u}=s.selection;if(l&&!c||!VS(s.doc,u,t,i))return!1;if(a)if(c)t.isInSet(s.storedMarks||c.marks())?a(s.tr.removeStoredMark(t)):a(s.tr.addStoredMark(t.create(e)));else{let f,d=s.tr;i||(u=WS(u)),r?f=!u.some(p=>s.doc.rangeHasMark(p.$from.pos,p.$to.pos,t)):f=!u.every(p=>{let h=!1;return d.doc.nodesBetween(p.$from.pos,p.$to.pos,(m,g,y)=>{if(h)return!1;h=!t.isInSet(m.marks)&&!!y&&y.type.allowsMarkType(t)&&!(m.isText&&/^\s*$/.test(m.textBetween(Math.max(0,p.$from.pos-g),Math.min(m.nodeSize,p.$to.pos-g))))}),!h});for(let p=0;p<u.length;p++){let{$from:h,$to:m}=u[p];if(!f)d.removeMark(h.pos,m.pos,t);else{let g=h.pos,y=m.pos,x=h.nodeAfter,C=m.nodeBefore,v=o&&x&&x.isText?/^\s*/.exec(x.text)[0].length:0,I=o&&C&&C.isText?/\s*$/.exec(C.text)[0].length:0;g+v<y&&(g+=v,y-=I),d.addMark(g,y,t.create(e))}}a(d.scrollIntoView())}return!0}}function qn(...t){return function(e,n,r){for(let i=0;i<t.length;i++)if(t[i](e,n,r))return!0;return!1}}var Al=qn(is,Nl,Rl),vh=qn(is,NS,RS),_t={Enter:qn(OS,BS,LS,FS),"Mod-Enter":DS,Backspace:Al,"Mod-Backspace":Al,"Shift-Backspace":Al,Delete:vh,"Mod-Delete":vh,"Mod-a":zS},Dh={"Ctrl-h":_t.Backspace,"Alt-Backspace":_t["Mod-Backspace"],"Ctrl-d":_t.Delete,"Ctrl-Alt-Backspace":_t["Mod-Delete"],"Alt-Delete":_t["Mod-Delete"],"Alt-d":_t["Mod-Delete"],"Ctrl-a":_S,"Ctrl-e":HS};for(let t in _t)Dh[t]=_t[t];var jS=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Bh=jS?Dh:_t;var ke=class{constructor(e,n,r={}){this.match=e,this.match=e,this.handler=typeof n=="string"?qS(n):n,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function qS(t){return function(e,n,r,i){let o=t;if(n[1]){let s=n[0].lastIndexOf(n[1]);o+=n[0].slice(s+n[1].length),r+=s;let a=r-i;a>0&&(o=n[0].slice(s-a,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Lh=(t,e)=>{let n=t.plugins;for(let r=0;r<n.length;r++){let i=n[r],o;if(i.spec.isInputRules&&(o=i.getState(t))){if(e){let s=t.tr,a=o.transform;for(let l=a.steps.length-1;l>=0;l--)s.step(a.steps[l].invert(a.docs[l]));if(o.text){let l=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,t.schema.text(o.text,l))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},iF=new ke(/--$/,"\u2014",{inCodeMark:!1}),oF=new ke(/\.\.\.$/,"\u2026",{inCodeMark:!1}),sF=new ke(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),aF=new ke(/"$/,"\u201D",{inCodeMark:!1}),lF=new ke(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),cF=new ke(/'$/,"\u2019",{inCodeMark:!1});function as(t,e,n=null,r){return new ke(t,(i,o,s,a)=>{let l=n instanceof Function?n(o):n,c=i.tr.delete(s,a),u=c.doc.resolve(s),f=u.blockRange(),d=f&&Hn(f,e,l);if(!d)return null;c.wrap(f,d);let p=c.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Wn(c.doc,s-1)&&(!r||r(o,p))&&c.join(s-1),c})}function Bl(t,e,n=null){return new ke(t,(r,i,o,s)=>{let a=r.doc.resolve(o),l=n instanceof Function?n(i):n;return a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,l):null})}var fn=typeof navigator<"u"?navigator:null,Ph=typeof document<"u"?document:null,dn=fn&&fn.userAgent||"",Pl=/Edge\/(\d+)/.exec(dn),Fh=/MSIE \d/.exec(dn),Fl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(dn),$l=!!(Fh||Fl||Pl),pF=Fh?document.documentMode:Fl?+Fl[1]:Pl?+Pl[1]:0,KS=!$l&&/gecko\/(\d+)/i.test(dn),hF=KS&&+(/Firefox\/(\d+)/.exec(dn)||[0,0])[1],zl=!$l&&/Chrome\/(\d+)/.exec(dn),US=!!zl,mF=zl?+zl[1]:0,JS=!$l&&!!fn&&/Apple Computer/.test(fn.vendor),GS=JS&&(/Mobile\/\w+/.test(dn)||!!fn&&fn.maxTouchPoints>2),gF=GS||(fn?/Mac/.test(fn.platform):!1),QS=/Android \d/.test(dn),YS=!!Ph&&"webkitFontSmoothing"in Ph.documentElement.style,yF=YS?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ll(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,a=s.doc.resolve(e);if(a.parent.type.spec.code)return!1;let l=a.parent.textBetween(Math.max(0,a.parentOffset-500),a.parentOffset,void 0,"\uFFFC")+r;for(let c of i){let u=c,f=u.match.exec(l),d=f&&f[0]&&u.handler(s,f,e-(f[0].length-r.length),n);if(d)return u.undoable!==!1&&d.setMeta(o,{transform:d,from:e,to:n,text:r}),t.dispatch(d),!0}return!1}var XS=new te("MILKDOWN_CUSTOM_INPUTRULES");function zh({rules:t}){let e=new X({key:XS,isInputRules:!0,state:{init(){return null},apply(n,r){let i=n.getMeta(this);return i||(n.selectionSet||n.docChanged?null:r)}},props:{handleTextInput(n,r,i,o){return Ll(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>(setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&Ll(n,r.pos,r.pos,"",t,e)}),!1),keydown:(n,r)=>!(QS&&US&&r.key==="Enter")||n.composing?!1:n.someProp("handleKeyDown",i=>i(n,r))?(r.preventDefault(),!0):!1},handleKeyDown(n,r){if(r.key!=="Enter")return!1;let{$cursor:i}=n.state.selection;return i?Ll(n,i.pos,i.pos,` +`,t,e):!1}}});return e}function Ht(t,e,n={}){return new ke(t,(r,i,o,s)=>{var a,l,c,u;let{tr:f}=r,d=i.length,p=i[d-1],h=i[0],m=[],g,y={group:p,fullMatch:h,start:o,end:s},x=(a=n.updateCaptured)==null?void 0:a.call(n,y);if(Object.assign(y,x),{group:p,fullMatch:h,start:o,end:s}=y,h===null||p?.trim()==="")return null;if(p){let C=h.search(/\S/),v=o+h.indexOf(p),I=v+p.length;m=(l=f.storedMarks)!=null?l:[],I<s&&f.delete(I,s),v>o&&f.delete(o+C,v),g=o+C+p.length;let w=(c=n.getAttr)==null?void 0:c.call(n,i);f.addMark(o,g,e.create(w)),f.setStoredMarks(m),(u=n.beforeDispatch)==null||u.call(n,{match:i,start:o,end:s,tr:f})}return f})}function ls(t,e,n={}){return new ke(t,(r,i,o,s)=>{var a,l,c;let{tr:u}=r,f=i[1],d=i[0],p={group:f,fullMatch:d,start:o,end:s},h=(a=n.updateCaptured)==null?void 0:a.call(n,p);if(Object.assign(p,h),{group:f,fullMatch:d,start:o,end:s}=p,d===null||!f||f.trim()==="")return null;let m=(l=n.getAttr)==null?void 0:l.call(n,i),g=e.createAndFill(m);return g&&(u.replaceRangeWith(e.isBlock?u.doc.resolve(o).before():o,s,g),(c=n.beforeDispatch)==null||c.call(n,{match:[d,f],start:o,end:s,tr:u})),u})}function _l(t){return Object.assign(Object.create(t),t).setTime(Date.now())}function ZS(t,e){return Array.isArray(t)&&t.includes(e.type)||e.type===t}function e0(t){return e=>{for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r)){let i=e.before(n),o=e.after(n);return{from:i,to:o,node:r}}}}}function $h(t,e){return e0(n=>n.type===e)(t)}function _h(t){return e=>{for(let n=e.depth;n>0;n--){let r=e.node(n);if(t(r))return{pos:e.before(n),start:e.start(n),depth:n,node:r}}}}function Hh(t,e){if(!(t instanceof H))return;let{node:n,$from:r}=t;if(ZS(e,n))return{node:n,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Vh=(t,e)=>{let{selection:n,doc:r}=t;if(n instanceof H)return{hasNode:n.node.type===e,pos:n.from,target:n.node};let{from:i,to:o}=n,s=!1,a=-1,l=null;return r.nodesBetween(i,o,(c,u)=>l?!1:c.type===e?(s=!0,a=u,l=c,!1):!0),{hasNode:s,pos:a,target:l}};var Vt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},us={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},t0=typeof navigator<"u"&&/Mac/.test(navigator.platform),n0=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(pe=0;pe<10;pe++)Vt[48+pe]=Vt[96+pe]=String(pe);var pe;for(pe=1;pe<=24;pe++)Vt[pe+111]="F"+pe;var pe;for(pe=65;pe<=90;pe++)Vt[pe]=String.fromCharCode(pe+32),us[pe]=String.fromCharCode(pe);var pe;for(cs in Vt)us.hasOwnProperty(cs)||(us[cs]=Vt[cs]);var cs;function Wh(t){var e=t0&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||n0&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?us:Vt)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var r0=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),i0=typeof navigator<"u"&&/Win/.test(navigator.platform);function o0(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let a=0;a<e.length-1;a++){let l=e[a];if(/^(cmd|meta|m)$/i.test(l))s=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))i=!0;else if(/^s(hift)?$/i.test(l))o=!0;else if(/^mod$/i.test(l))r0?s=!0:i=!0;else throw new Error("Unrecognized modifier name: "+l)}return r&&(n="Alt-"+n),i&&(n="Ctrl-"+n),s&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function s0(t){let e=Object.create(null);for(let n in t)e[o0(n)]=t[n];return e}function Hl(t,e,n=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n&&e.shiftKey&&(t="Shift-"+t),t}function jh(t){return new X({props:{handleKeyDown:Vl(t)}})}function Vl(t){let e=s0(t);return function(n,r){let i=Wh(r),o,s=e[Hl(i,r)];if(s&&s(n.state,n.dispatch,n))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let a=e[Hl(i,r,!1)];if(a&&a(n.state,n.dispatch,n))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(i0&&r.ctrlKey&&r.altKey)&&(o=Vt[r.keyCode])&&o!=i){let a=e[Hl(o,r)];if(a&&a(n.state,n.dispatch,n))return!0}}return!1}}var Kh=class{},Uh=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=t=>{this.top()?.push(t)},this.open=t=>{this.elements.push(t)},this.close=()=>{let t=this.elements.pop();if(!t)throw Sa();return t}}},a0=class Jh extends Kh{constructor(e,n,r){super(),this.type=e,this.content=n,this.attrs=r}push(e,...n){this.content.push(e,...n)}pop(){return this.content.pop()}static create(e,n,r){return new Jh(e,n,r)}},Gh=class extends Uh{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(e,r),n.toDoc())}}constructor(t){super(),this.#t=J.none,this.#e=e=>e.isText,this.#r=(e,n)=>{if(this.#e(e)&&this.#e(n)&&J.sameSet(e.marks,n.marks))return this.schema.text(e.text+n.text,e.marks)},this.#n=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.parseMarkdown.match(e));if(!n)throw od(e);return n},this.#s=e=>{let n=this.#n(e);n.spec.parseMarkdown.runner(this,e,n)},this.injectRoot=(e,n,r)=>(this.openNode(n,r),this.next(e.children),this),this.openNode=(e,n)=>(this.open(a0.create(e,[],n)),this),this.#o=()=>{this.#t=J.none;let e=this.close();return this.#i(e.type,e.attrs,e.content)},this.closeNode=()=>{try{this.#o()}catch(e){console.error(e)}return this},this.#i=(e,n,r)=>{let i=e.createAndFill(n,r,this.#t);if(!i)throw id(e,n,r);return this.push(i),i},this.addNode=(e,n,r)=>{try{this.#i(e,n,r)}catch(i){console.error(i)}return this},this.openMark=(e,n)=>{let r=e.create(n);return this.#t=r.addToSet(this.#t),this},this.closeMark=e=>(this.#t=e.removeFromSet(this.#t),this),this.addText=e=>{try{let n=this.top();if(!n)throw Sa();let r=n.pop(),i=this.schema.text(e,this.#t);if(!r)return n.push(i),this;let o=this.#r(r,i);return o?(n.push(o),this):(n.push(r,i),this)}catch(n){return console.error(n),this}},this.build=()=>{let e;do e=this.#o();while(this.size());return e},this.next=(e=[])=>([e].flat().forEach(n=>this.#s(n)),this),this.toDoc=()=>this.build(),this.run=(e,n)=>{let r=e.runSync(e.parse(n),n);return this.next(r),this},this.schema=t}#e;#r;#n;#s;#o;#i},qh=class Qh extends Kh{constructor(e,n,r,i={}){super(),this.type=e,this.children=n,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}static{this.create=(e,n,r,i={})=>new Qh(e,n,r,i)}},l0=t=>Object.prototype.hasOwnProperty.call(t,"size"),Yh=class extends Uh{#t;static{this.create=(t,e)=>{let n=new this(t);return r=>(n.run(r),n.toString(e))}}constructor(t){super(),this.#t=[],this.#e=e=>{let n=Object.values({...this.schema.nodes,...this.schema.marks}).find(r=>r.spec.toMarkdown.match(e));if(!n)throw sd(e.type);return n},this.#r=e=>this.#e(e).spec.toMarkdown.runner(this,e),this.#n=(e,n)=>this.#e(e).spec.toMarkdown.runner(this,e,n),this.#s=e=>{let n=o=>o.type.spec.priority??50,r=[...e].sort((o,s)=>n(o)-n(s)),i=[];return this.#t.forEach(({mark:o})=>{let s=r.findIndex(a=>a.eq(o));s>=0&&i.push(...r.splice(s,1))}),i.concat(r)},this.#o=e=>{let n=e?.marks,r=0;for(;r<this.#t.length;){let{mark:i,spanning:o}=this.#t[r];if(o&&n?.some(s=>s.eq(i)))r++;else break}for(let i=this.#t.length-1;i>=r;i--)this.#f(this.#t[i].mark)},this.#i=(e,n)=>{this.#s(e.marks).every(r=>!this.#n(r,e))&&this.#r(e),this.#o(n)},this.#a=e=>{let{children:n}=e;return n&&(e.children=n.reduce((r,i,o)=>{if(o===0)return[i];let s=r.at(-1);if(s&&s.isMark&&i.isMark){let{children:a,...l}=i,{children:c,...u}=s;if(i.type===s.type&&a&&c&&JSON.stringify(l)===JSON.stringify(u)){let f={...u,children:[...c,...a]};return r.slice(0,-1).concat(this.#a(f))}}return r.concat(i)},[])),e},this.#l=e=>{let n={...e.props,type:e.type};return e.children&&(n.children=e.children),e.value&&(n.value=e.value),n},this.openNode=(e,n,r)=>(this.open(qh.create(e,void 0,n,r)),this),this.#d=(e,n)=>{let r="",i="",o=e.children;if(o){let a=o[0],l=o.at(-1);if(l&&l.type==="text"&&l.value.endsWith(" ")){let c=l.value,u=c.trimEnd();i=c.slice(u.length),l.value=u}if(a&&a.type==="text"&&a.value.startsWith(" ")){let c=a.value,u=c.trimStart();r=c.slice(0,c.length-u.length),a.value=u}}r.length&&this.#u("text",void 0,r);let s=n();return i.length&&this.#u("text",void 0,i),s},this.#c=(e=!1)=>{let n=this.close(),r=()=>this.#u(n.type,n.children,n.value,n.props);return e?this.#d(n,r):r()},this.closeNode=()=>(this.#c(),this),this.#u=(e,n,r,i)=>{let o=qh.create(e,n,r,i),s=this.#a(this.#l(o));return this.push(s),s},this.addNode=(e,n,r,i)=>(this.#u(e,n,r,i),this),this.#p=(e,n,r,i)=>this.#t.some(o=>o.mark.eq(e))?this:(this.#t.push({mark:e,spanning:r==null}),this.openNode(n,r,{...i,isMark:!0})),this.#f=e=>{let n=-1;for(let r=this.#t.length-1;r>=0;r--)if(this.#t[r].mark.eq(e)){n=r;break}n<0||(this.#t.splice(n,1),this.#c(!0))},this.withMark=(e,n,r,i)=>(this.#p(e,n,r,i),this),this.closeMark=e=>(this.#f(e),this),this.build=()=>{let e=null;do e=this.#c();while(this.size());return e},this.next=e=>l0(e)?(e.forEach((n,r,i)=>{this.#i(n,e.maybeChild(i+1)??void 0)}),this):(this.#i(e),this),this.toString=e=>e.stringify(this.build()),this.run=e=>(this.#t=[],this.next(e),this),this.schema=t}#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f};var ve=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Dr=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},Jl=null,jt=function(t,e,n){let r=Jl||(Jl=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},c0=function(){Jl=null},Zn=function(t,e,n,r){return n&&(Xh(t,e,n,r,-1)||Xh(t,e,n,r,1))},u0=/^(img|br|input|textarea|hr)$/i;function Xh(t,e,n,r,i){for(var o;;){if(t==n&&e==r)return!0;if(e==(i<0?0:it(t))){let s=t.parentNode;if(!s||s.nodeType!=1||Vi(t)||u0.test(t.nodeName)||t.contentEditable=="false")return!1;e=ve(t)+(i<0?0:1),t=s}else if(t.nodeType==1){let s=t.childNodes[e+(i<0?-1:0)];if(s.nodeType==1&&s.contentEditable=="false")if(!((o=s.pmViewDesc)===null||o===void 0)&&o.ignoreForSelection)e+=i;else return!1;else t=s,e=i<0?it(t):0}else return!1}}function it(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function f0(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=it(t)}else if(t.parentNode&&!Vi(t))e=ve(t),t=t.parentNode;else return null}}function d0(t,e){for(;;){if(t.nodeType==3&&e<t.nodeValue.length)return t;if(t.nodeType==1&&e<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[e],e=0}else if(t.parentNode&&!Vi(t))e=ve(t)+1,t=t.parentNode;else return null}}function p0(t,e,n){for(let r=e==0,i=e==it(t);r||i;){if(t==n)return!0;let o=ve(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==it(t)}}function Vi(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}var Ss=function(t){return t.focusNode&&Zn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Kn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function h0(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function m0(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:Math.min(it(r.offsetNode),r.offset)}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:Math.min(it(r.startContainer),r.startOffset)}}}var vt=typeof navigator<"u"?navigator:null,Zh=typeof document<"u"?document:null,yn=vt&&vt.userAgent||"",Gl=/Edge\/(\d+)/.exec(yn),Im=/MSIE \d/.exec(yn),Ql=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(yn),Ve=!!(Im||Ql||Gl),mn=Im?document.documentMode:Ql?+Ql[1]:Gl?+Gl[1]:0,ot=!Ve&&/gecko\/(\d+)/i.test(yn);ot&&+(/Firefox\/(\d+)/.exec(yn)||[0,0])[1];var Yl=!Ve&&/Chrome\/(\d+)/.exec(yn),we=!!Yl,Am=Yl?+Yl[1]:0,De=!Ve&&!!vt&&/Apple Computer/.test(vt.vendor),Br=De&&(/Mobile\/\w+/.test(yn)||!!vt&&vt.maxTouchPoints>2),rt=Br||(vt?/Mac/.test(vt.platform):!1),Nm=vt?/Win/.test(vt.platform):!1,qt=/Android \d/.test(yn),Wi=!!Zh&&"webkitFontSmoothing"in Zh.documentElement.style,g0=Wi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function y0(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Wt(t,e){return typeof t=="number"?t:t[e]}function k0(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function em(t,e,n){if(!Xl(e)&&e.left==0)return;let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;){if(s.nodeType!=1){s=Dr(s);continue}let a=s,l=a==o.body,c=l?y0(o):k0(a),u=0,f=0;if(e.top<c.top+Wt(r,"top")?f=-(c.top-e.top+Wt(i,"top")):e.bottom>c.bottom-Wt(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+Wt(i,"top")-c.top:e.bottom-c.bottom+Wt(i,"bottom")),e.left<c.left+Wt(r,"left")?u=-(c.left-e.left+Wt(i,"left")):e.right>c.right-Wt(r,"right")&&(u=e.right-c.right+Wt(i,"right")),u||f)if(l)o.defaultView.scrollBy(u,f);else{let p=a.scrollLeft,h=a.scrollTop;f&&(a.scrollTop+=f),u&&(a.scrollLeft+=u);let m=a.scrollLeft-p,g=a.scrollTop-h;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=l?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:Dr(s)}}function b0(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s<Math.min(innerHeight,e.bottom);s+=5){let a=t.root.elementFromPoint(o,s);if(!a||a==t.dom||!t.dom.contains(a))continue;let l=a.getBoundingClientRect();if(l.top>=n-20){r=a,i=l.top;break}}return{refDOM:r,refTop:i,stack:Rm(t.dom)}}function Rm(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Dr(r));return e}function x0({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Om(n,r==0?0:r-e)}function Om(t,e){for(let n=0;n<t.length;n++){let{dom:r,top:i,left:o}=t[n];r.scrollTop!=i+e&&(r.scrollTop=i+e),r.scrollLeft!=o&&(r.scrollLeft=o)}}var Nr=null;function w0(t){if(t.setActive)return t.setActive();if(Nr)return t.focus(Nr);let e=Rm(t);t.focus(Nr==null?{get preventScroll(){return Nr={preventScroll:!0},!0}}:void 0),Nr||(Nr=!1,Om(e,0))}function Dm(t,e){let n,r=2e8,i,o=0,s=e.top,a=e.top,l,c;for(let u=t.firstChild,f=0;u;u=u.nextSibling,f++){let d;if(u.nodeType==1)d=u.getClientRects();else if(u.nodeType==3)d=jt(u).getClientRects();else continue;for(let p=0;p<d.length;p++){let h=d[p];if(h.top<=s&&h.bottom>=a){s=Math.max(h.bottom,s),a=Math.min(h.top,a);let m=h.left>e.left?h.left-e.left:h.right<e.left?e.left-h.right:0;if(m<r){n=u,r=m,i=m&&n.nodeType==3?{left:h.right<e.left?h.right:h.left,top:e.top}:e,u.nodeType==1&&m&&(o=f+(e.left>=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!l&&h.left<=e.left&&h.right>=e.left&&(l=u,c={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!n&&l&&(n=l,i=c,r=0),n&&n.nodeType==3?S0(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Dm(n,i)}function S0(t,e){let n=t.nodeValue.length,r=document.createRange(),i;for(let o=0;o<n;o++){r.setEnd(t,o+1),r.setStart(t,o);let s=pn(r,1);if(s.top!=s.bottom&&hc(e,s)){i={node:t,offset:o+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}function hc(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function C0(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left<t.getBoundingClientRect().left?n:t}function M0(t,e,n){let{node:r,offset:i}=Dm(e,n),o=-1;if(r.nodeType==1&&!r.firstChild){let s=r.getBoundingClientRect();o=s.left!=s.right&&n.left>(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function E0(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let a=t.docView.nearestDesc(o,!0),l;if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)&&((l=a.dom.getBoundingClientRect()).width||l.height)&&(a.node.isBlock&&a.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(a.dom.nodeName)&&(!s&&l.left>r.left||l.top>r.top?i=a.posBefore:(!s&&l.right<r.left||l.bottom<r.top)&&(i=a.posAfter),s=!0),!a.contentDOM&&i<0&&!a.node.isText))return(a.node.isBlock?r.top<(l.top+l.bottom)/2:r.left<(l.left+l.right)/2)?a.posBefore:a.posAfter;o=a.dom.parentNode}return i>-1?i:t.docView.posFromDOM(e,n,-1)}function Bm(t,e,n){let r=t.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-n.top)/(n.bottom-n.top))-2)),o=i;;){let s=t.childNodes[o];if(s.nodeType==1){let a=s.getClientRects();for(let l=0;l<a.length;l++){let c=a[l];if(hc(e,c))return Bm(s,e,c)}}if((o=(o+1)%r)==i)break}return t}function T0(t,e){let n=t.dom.ownerDocument,r,i=0,o=m0(n,e.left,e.top);o&&({node:r,offset:i}=o);let s=(t.root.elementFromPoint?t.root:n).elementFromPoint(e.left,e.top),a;if(!s||!t.dom.contains(s.nodeType!=1?s.parentNode:s)){let c=t.dom.getBoundingClientRect();if(!hc(e,c)||(s=Bm(t.dom,e,c),!s))return null}if(De)for(let c=s;r&&c;c=Dr(c))c.draggable&&(r=void 0);if(s=C0(s,e),r){if(ot&&r.nodeType==1&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let u=r.childNodes[i],f;u.nodeName=="IMG"&&(f=u.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&i++}let c;Wi&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(a=E0(t,r,i,e))}a==null&&(a=M0(t,s,e));let l=t.docView.nearestDesc(s,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function Xl(t){return t.top<t.bottom||t.left<t.right}function pn(t,e){let n=t.getClientRects();if(n.length){let r=n[e<0?0:n.length-1];if(Xl(r))return r}return Array.prototype.find.call(n,Xl)||t.getBoundingClientRect()}var v0=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Lm(t,e,n){let{node:r,offset:i,atom:o}=t.docView.domFromPos(e,n<0?-1:1),s=Wi||ot;if(r.nodeType==3)if(s&&(v0.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let l=pn(jt(r,i,i),n);if(ot&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let c=pn(jt(r,i-1,i-1),-1);if(c.top==l.top){let u=pn(jt(r,i,i+1),-1);if(u.top!=l.top)return Li(u,u.left<c.left)}}return l}else{let l=i,c=i,u=n<0?1:-1;return n<0&&!i?(c++,u=-1):n>=0&&i==r.nodeValue.length?(l--,u=1):n<0?l--:c++,Li(pn(jt(r,l,c),u),u<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==it(r))){let l=r.childNodes[i-1];if(l.nodeType==1)return Wl(l.getBoundingClientRect(),!1)}if(o==null&&i<it(r)){let l=r.childNodes[i];if(l.nodeType==1)return Wl(l.getBoundingClientRect(),!0)}return Wl(r.getBoundingClientRect(),n>=0)}if(o==null&&i&&(n<0||i==it(r))){let l=r.childNodes[i-1],c=l.nodeType==3?jt(l,it(l)-(s?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return Li(pn(c,1),!1)}if(o==null&&i<it(r)){let l=r.childNodes[i];for(;l.pmViewDesc&&l.pmViewDesc.ignoreForCoords;)l=l.nextSibling;let c=l?l.nodeType==3?jt(l,0,s?0:1):l.nodeType==1?l:null:null;if(c)return Li(pn(c,-1),!0)}return Li(pn(r.nodeType==3?jt(r):r,-n),n>=0)}function Li(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Wl(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Pm(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function I0(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Pm(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(o,!0);if(!a)break;if(a.node.isBlock){o=a.contentDOM||a.dom;break}o=a.dom.parentNode}let s=Lm(t,i.pos,1);for(let a=o.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=jt(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;c<l.length;c++){let u=l[c];if(u.bottom>u.top+1&&(n=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var A0=/[\u0590-\u08ac]/;function N0(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,a=t.domSelection();return a?!A0.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?o:s:Pm(t,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:u,anchorOffset:f}=t.domSelectionRange(),d=a.caretBidiLevel;a.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||l==h&&c==m;try{a.collapse(u,f),l&&(l!=u||c!=f)&&a.extend&&a.extend(l,c)}catch{}return d!=null&&(a.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var tm=null,nm=null,rm=!1;function R0(t,e,n){return tm==e&&nm==n?rm:(tm=e,nm=n,rm=n=="up"||n=="down"?I0(t,e,n):N0(t,e,n))}var st=0,im=1,Un=2,ht=3,er=class{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=st,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;n<this.children.length;n++)e+=this.children[n].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let n=0,r=this.posAtStart;;n++){let i=this.children[n];if(i==e)return r;r+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,n,r){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(r<0){let o,s;if(e==this.contentDOM)o=e.childNodes[n-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;o=e.previousSibling}for(;o&&!((s=o.pmViewDesc)&&s.parent==this);)o=o.previousSibling;return o?this.posBeforeChild(s)+s.size:this.posAtStart}else{let o,s;if(e==this.contentDOM)o=e.childNodes[n];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;o=e.nextSibling}for(;o&&!((s=o.pmViewDesc)&&s.parent==this);)o=o.nextSibling;return o?this.posBeforeChild(s):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=n>ve(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;n<this.children.length;n++){let i=this.children[n],o=r+i.size;if(r==e&&o!=r){for(;!i.border&&i.children.length;)for(let s=0;s<i.children.length;s++){let a=i.children[s];if(a.size){i=a;break}}return i}if(e<o)return i.descAt(e-r-i.border);r=o}}domFromPos(e,n){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,i=0;for(let o=0;r<this.children.length;r++){let s=this.children[r],a=o+s.size;if(a>e||s instanceof ps){i=e-o;break}o=a}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof fs&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?ve(o.dom)+1:0}}else{let o,s=!0;for(;o=r<this.children.length?this.children[r]:null,!(!o||o.dom.parentNode==this.contentDOM);r++,s=!1);return o&&s&&!o.border&&!o.domAtom?o.domFromPos(0,n):{node:this.contentDOM,offset:o?ve(o.dom):this.contentDOM.childNodes.length}}}parseRange(e,n,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:n,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,o=-1;for(let s=r,a=0;;a++){let l=this.children[a],c=s+l.size;if(i==-1&&e<=c){let u=s+l.border;if(e>=u&&n<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,n,u);e=s;for(let f=a;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ve(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>n||a==this.children.length-1)){n=c;for(let u=a+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){o=ve(f.dom);break}n+=f.size}o==-1&&(o=this.contentDOM.childNodes.length);break}s=c}return{node:this.contentDOM,from:e,to:n,fromOffset:i,toOffset:o}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let n=this.children[e<0?0:this.children.length-1];return n.size==0||n.emptyChildAt(e)}domAfterPos(e){let{node:n,offset:r}=this.domFromPos(e,0);if(n.nodeType!=1||r==n.childNodes.length)throw new RangeError("No node after pos "+e);return n.childNodes[r]}setSelection(e,n,r,i=!1){let o=Math.min(e,n),s=Math.max(e,n);for(let p=0,h=0;p<this.children.length;p++){let m=this.children[p],g=h+m.size;if(o>h&&s<g)return m.setSelection(e-h-m.border,n-h-m.border,r,i);h=g}let a=this.domFromPos(e,e?-1:1),l=n==e?a:this.domFromPos(n,n?-1:1),c=r.root.getSelection(),u=r.domSelectionRange(),f=!1;if((ot||De)&&e==n){let{node:p,offset:h}=a;if(p.nodeType==3){if(f=!!(h&&p.nodeValue[h-1]==` +`),f&&h==p.nodeValue.length)for(let m=p,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(a=l={node:g.parentNode,offset:ve(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=p.childNodes[h-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(ot&&u.focusNode&&u.focusNode!=l.node&&u.focusNode.nodeType==1){let p=u.focusNode.childNodes[u.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||f&&De)&&Zn(a.node,a.offset,u.anchorNode,u.anchorOffset)&&Zn(l.node,l.offset,u.focusNode,u.focusOffset))return;let d=!1;if((c.extend||e==n)&&!(f&&ot)){c.collapse(a.node,a.offset);try{e!=n&&c.extend(l.node,l.offset),d=!0}catch{}}if(!d){if(e>n){let h=a;a=l,l=h}let p=document.createRange();p.setEnd(l.node,l.offset),p.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i<this.children.length;i++){let o=this.children[i],s=r+o.size;if(r==s?e<=s&&n>=r:e<s&&n>r){let a=r+o.border,l=s-o.border;if(e>=a&&n<=l){this.dirty=e==r||n==s?Un:im,e==a&&n==l&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=ht:o.markDirty(e-a,n-a);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Un:ht}r=s}this.dirty=Un}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Un:im;n.dirty<r&&(n.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},fs=class extends er{constructor(e,n,r,i){let o,s=n.type.toDOM;if(typeof s=="function"&&(s=s(r,()=>{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let a=document.createElement("span");a.appendChild(s),s=a}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==st&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Zl=class extends er{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Gn=class t extends er{constructor(e,n,r,i,o){super(e,[],r,i),this.mark=n,this.spec=o}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=cn.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new t(e,n,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&ht||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ht&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=st){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=st}}slice(e,n,r){let i=t.create(this.parent,this.mark,!0,r),o=this.children,s=this.size;n<s&&(o=rc(o,n,s,r)),e>0&&(o=rc(o,0,e,r));for(let a=0;a<o.length;a++)o[a].parent=i;return i.children=o,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},gn=class t extends er{constructor(e,n,r,i,o,s,a){super(e,[],o,s),this.node=n,this.outerDeco=r,this.innerDeco=i,this.nodeDOM=a}static create(e,n,r,i,o,s){let a=o.nodeViews[n.type.name],l,c=a&&a(n,o,()=>{if(!l)return s;if(l.parent)return l.parent.posBeforeChild(l)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=cn.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),n.type.spec.draggable&&(u.draggable=!0));let d=u;return u=$m(u,r,n),c?l=new ec(e,n,r,i,u,f||null,d,c):n.isText?new ds(e,n,r,i,u,d):new t(e,n,r,i,u,f||null,d)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>E.empty)}return e}matchesNode(e,n,r){return this.dirty==st&&e.eq(this.node)&&hs(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,a=o&&o.pos<0,l=new nc(this,s&&s.node,e);L0(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&l.syncToMarks(u==this.node.childCount?J.none:this.node.child(u).marks,r,e,u),l.placeWidget(c,e,i)},(c,u,f,d)=>{l.syncToMarks(c.marks,r,e,d);let p;l.findNodeMatch(c,u,f,d)||a&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(p=l.findIndexWithChild(o.node))>-1&&l.updateNodeAt(c,u,f,p,e)||l.updateNextNode(c,u,f,e,d,i)||l.addNode(c,u,f,e,i),i+=c.nodeSize}),l.syncToMarks([],r,e,0),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==Un)&&(s&&this.protectLocalComposition(e,s),Fm(this.contentDOM,this.children,e),Br&&P0(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof z)||r<n||i>n+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,a=F0(this.node.content,s,r-n,i-n);return a<0?null:{node:o,pos:a,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Zl(this,o,n,i);e.input.compositionNodes.push(s),this.children=rc(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==ht||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=st}updateOuterDeco(e){if(hs(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=zm(this.dom,this.nodeDOM,tc(this.outerDeco,this.node,n),tc(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function om(t,e,n,r,i){$m(r,e,t);let o=new gn(void 0,t,e,n,r,r,r);return o.contentDOM&&o.updateChildren(i,0),o}var ds=class t extends gn{constructor(e,n,r,i,o,s){super(e,n,r,i,o,null,s)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==ht||this.dirty!=st&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=st||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=st,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new t(this.parent,i,this.outerDeco,this.innerDeco,o,o)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=ht)}get domAtom(){return!1}isText(e){return this.node.text==e}},ps=class extends er{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==st&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},ec=class extends gn{constructor(e,n,r,i,o,s,a,l){super(e,n,r,i,o,s,a),this.spec=l}update(e,n,r,i){if(this.dirty==ht)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Fm(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o<e.length;o++){let s=e[o],a=s.dom;if(a.parentNode==t){for(;a!=r;)r=sm(r),i=!0;r=r.nextSibling}else i=!0,t.insertBefore(a,r);if(s instanceof Gn){let l=r?r.previousSibling:t.lastChild;Fm(s.contentDOM,s.children,n),r=l?l.nextSibling:t.firstChild}}for(;r;)r=sm(r),i=!0;i&&n.trackWrites==t&&(n.trackWrites=null)}var Pi=function(t){t&&(this.nodeName=t)};Pi.prototype=Object.create(null);var Jn=[new Pi];function tc(t,e,n){if(t.length==0)return Jn;let r=n?Jn[0]:new Pi,i=[r];for(let o=0;o<t.length;o++){let s=t[o].type.attrs;if(s){s.nodeName&&i.push(r=new Pi(s.nodeName));for(let a in s){let l=s[a];l!=null&&(n&&i.length==1&&i.push(r=new Pi(e.isInline?"span":"div")),a=="class"?r.class=(r.class?r.class+" ":"")+l:a=="style"?r.style=(r.style?r.style+";":"")+l:a!="nodeName"&&(r[a]=l))}}}return i}function zm(t,e,n,r){if(n==Jn&&r==Jn)return e;let i=e;for(let o=0;o<r.length;o++){let s=r[o],a=n[o];if(o){let l;a&&a.nodeName==s.nodeName&&i!=t&&(l=i.parentNode)&&l.nodeName.toLowerCase()==s.nodeName||(l=document.createElement(s.nodeName),l.pmIsDeco=!0,l.appendChild(i),a=Jn[0]),i=l}O0(i,a||Jn[0],s)}return i}function O0(t,e,n){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in n)&&t.removeAttribute(r);for(let r in n)r!="class"&&r!="style"&&r!="nodeName"&&n[r]!=e[r]&&t.setAttribute(r,n[r]);if(e.class!=n.class){let r=e.class?e.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let o=0;o<r.length;o++)i.indexOf(r[o])==-1&&t.classList.remove(r[o]);for(let o=0;o<i.length;o++)r.indexOf(i[o])==-1&&t.classList.add(i[o]);t.classList.length==0&&t.removeAttribute("class")}if(e.style!=n.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=r.exec(e.style);)t.style.removeProperty(i[1])}n.style&&(t.style.cssText+=n.style)}}function $m(t,e,n){return zm(t,t,Jn,tc(e,n,t.nodeType!=1))}function hs(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].type.eq(e[n].type))return!1;return!0}function sm(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}var nc=class{constructor(e,n,r){this.lock=n,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=D0(e.node.content,e)}destroyBetween(e,n){if(e!=n){for(let r=e;r<n;r++)this.top.children[r].destroy();this.top.children.splice(e,n-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,n,r,i){let o=0,s=this.stack.length>>1,a=Math.min(s,e.length);for(;o<a&&(o==s-1?this.top:this.stack[o+1<<1]).matchesMark(e[o])&&e[o].type.spec.spanning!==!1;)o++;for(;o<s;)this.destroyRest(),this.top.dirty=st,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let l=-1,c=this.top.children.length;i<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let u=this.index;u<c;u++){let f=this.top.children[u];if(f.matchesMark(e[s])&&!this.isLocked(f.dom)){l=u;break}}if(l<0&&this.index<this.top.children.length){let u=this.top.children[this.index];u instanceof Gn&&u.dirty!=ht&&u.mark.type==e[s].type&&u.spec.update&&!this.isLocked(u.dom)&&u.spec.update(e[s])&&(u.mark=e[s],l=this.index,this.changed=!0)}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let u=Gn.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let a=this.index,l=Math.min(this.top.children.length,a+5);a<l;a++){let c=this.top.children[a];if(c.matchesNode(e,n,r)&&!this.preMatch.matched.has(c)){o=a;break}}return o<0?!1:(this.destroyBetween(this.index,o),this.index++,!0)}updateNodeAt(e,n,r,i,o){let s=this.top.children[i];return s.dirty==ht&&s.dom==s.contentDOM&&(s.dirty=Un),s.update(e,n,r,o)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let n=e.parentNode;if(!n)return-1;if(n==this.top.contentDOM){let r=e.pmViewDesc;if(r){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==r)return i}return-1}e=n}}updateNextNode(e,n,r,i,o,s){for(let a=this.index;a<this.top.children.length;a++){let l=this.top.children[a];if(l instanceof gn){let c=this.preMatch.matched.get(l);if(c!=null&&c!=o)return!1;let u=l.dom,f,d=this.isLocked(u)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&l.dirty!=ht&&hs(n,l.outerDeco));if(!d&&l.update(e,n,r,i))return this.destroyBetween(this.index,a),l.dom!=u&&(this.changed=!0),this.index++,!0;if(!d&&(f=this.recreateWrapper(l,e,n,r,i,s)))return this.destroyBetween(this.index,a),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Un,f.updateChildren(i,s+1),f.dirty=st),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,n,r,i,o,s){if(e.dirty||n.isAtom||!e.children.length||!e.node.content.eq(n.content)||!hs(r,e.outerDeco)||!i.eq(e.innerDeco))return null;let a=gn.create(this.top,n,r,i,o,s);if(a.contentDOM){a.children=e.children,e.children=[];for(let l of a.children)l.parent=a}return e.destroy(),a}addNode(e,n,r,i,o){let s=gn.create(this.top,e,n,r,i,o);s.contentDOM&&s.updateChildren(i,o+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,n,r){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let o=new fs(this.top,e,n,r);this.top.children.splice(this.index++,0,o),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],n=this.top;for(;e instanceof Gn;)n=e,e=n.children[n.children.length-1];(!e||!(e instanceof ds)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((De||we)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",n),this.addHackNode("BR",this.top))}addHackNode(e,n){if(n==this.top&&this.index<n.children.length&&n.children[this.index].matchesHack(e))this.index++;else{let r=document.createElement(e);e=="IMG"&&(r.className="ProseMirror-separator",r.alt=""),e=="BR"&&(r.className="ProseMirror-trailingBreak");let i=new ps(this.top,[],r,null);n!=this.top?n.children.push(i):n.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}};function D0(t,e){let n=e,r=n.children.length,i=t.childCount,o=new Map,s=[];e:for(;i>0;){let a;for(;;)if(r){let c=n.children[r-1];if(c instanceof Gn)n=c,r=c.children.length;else{a=c,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=t.child(i-1))break;--i,o.set(a,i),s.push(a)}}return{index:i,matched:o,matches:s.reverse()}}function B0(t,e){return t.type.side-e.type.side}function L0(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let c=0;c<t.childCount;c++){let u=t.child(c);r(u,i,e.forChild(o,u),c),o+=u.nodeSize}return}let s=0,a=[],l=null;for(let c=0;;){let u,f;for(;s<i.length&&i[s].to==o;){let g=i[s++];g.widget&&(u?(f||(f=[u])).push(g):u=g)}if(u)if(f){f.sort(B0);for(let g=0;g<f.length;g++)n(f[g],c,!!l)}else n(u,c,!!l);let d,p;if(l)p=-1,d=l,l=null;else if(c<t.childCount)p=c,d=t.child(c++);else break;for(let g=0;g<a.length;g++)a[g].to<=o&&a.splice(g--,1);for(;s<i.length&&i[s].from<=o&&i[s].to>o;)a.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let g=h;s<i.length&&i[s].from<g&&(g=i[s].from);for(let y=0;y<a.length;y++)a[y].to<g&&(g=a[y].to);g<h&&(l=d.cut(g-o),d=d.cut(0,g-o),h=g,p=-1)}else for(;s<i.length&&i[s].to<h;)s++;let m=d.isInline&&!d.isLeaf?a.filter(g=>!g.inline):a.slice();r(d,m,e.forChild(o,d),p),o=h}}function P0(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function F0(t,e,n,r){for(let i=0,o=0;i<t.childCount&&o<=r;){let s=t.child(i++),a=o;if(o+=s.nodeSize,!s.isText)continue;let l=s.text;for(;i<t.childCount;){let c=t.child(i++);if(o+=c.nodeSize,!c.isText)break;l+=c.text}if(o>=n){if(o>=r&&l.slice(r-e.length-a,r-a)==e)return r-e.length;let c=a<r?l.lastIndexOf(e,r-a-1):-1;if(c>=0&&c+e.length+a>=n)return a+c;if(n==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}function rc(t,e,n,r,i){let o=[];for(let s=0,a=0;s<t.length;s++){let l=t[s],c=a,u=a+=l.size;c>=n||u<=e?o.push(l):(c<e&&o.push(l.slice(0,e-c,r)),i&&(o.push(i),i=void 0),u>n&&o.push(l.slice(n-c,l.size,r)))}return o}function mc(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a=r.resolve(s),l,c;if(Ss(n)){for(l=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&H.isSelectable(f)&&i.parent&&!(f.isInline&&p0(n.focusNode,n.focusOffset,i.dom))){let d=i.posBefore;c=new H(s==d?a:r.resolve(d))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=s,d=s;for(let p=0;p<n.rangeCount;p++){let h=n.getRangeAt(p);f=Math.min(f,t.docView.posFromDOM(h.startContainer,h.startOffset,1)),d=Math.max(d,t.docView.posFromDOM(h.endContainer,h.endOffset,-1))}if(f<0)return null;[l,s]=d==t.state.selection.anchor?[d,f]:[f,d],a=r.resolve(s)}else l=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let u=r.resolve(l);if(!c){let f=e=="pointer"||t.state.selection.head<a.pos&&!o?1:-1;c=gc(t,u,a,f)}return c}function _m(t){return t.editable?t.hasFocus():Vm(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Ut(t,e=!1){let n=t.state.selection;if(Hm(t,n),!_m(t))return;let r=t.input.mouseDown;if(!e&&we&&r){let i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Zn(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)&&r.delaySelUpdate()){t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)$0(t);else{let{anchor:i,head:o}=n,s,a;am&&!(n instanceof z)&&(n.$from.parent.inlineContent||(s=lm(t,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(a=lm(t,n.to))),t.docView.setSelection(i,o,t,e),am&&(s&&cm(s),a&&cm(a)),n.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&z0(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}var am=De||we&&Am<63;function lm(t,e){let{node:n,offset:r}=t.docView.domFromPos(e,0),i=r<n.childNodes.length?n.childNodes[r]:null,o=r?n.childNodes[r-1]:null;if(De&&i&&i.contentEditable=="false")return jl(i);if((!i||i.contentEditable=="false")&&(!o||o.contentEditable=="false")){if(i)return jl(i);if(o)return jl(o)}}function jl(t){return t.contentEditable="true",De&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function cm(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function z0(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let n=t.domSelectionRange(),r=n.anchorNode,i=n.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!_m(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function $0(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,ve(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&Ve&&mn<=11&&(n.disabled=!0,n.disabled=!1)}function Hm(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(um(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else um(t)}function um(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function gc(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||z.between(e,n,r)}function fm(t){return t.editable&&!t.hasFocus()?!1:Vm(t)}function Vm(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function _0(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Zn(e.node,e.offset,n.anchorNode,n.anchorOffset)}function ic(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&$.findFrom(o,e)}function hn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function dm(t,e,n){let r=t.state.selection;if(r instanceof z)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return hn(t,new z(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=ic(t.state,e);return i&&i instanceof H?hn(t,i):!1}else if(!(rt&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let a=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(a))&&!s.contentDOM?H.isSelectable(o)?hn(t,new H(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):Wi?hn(t,new z(t.state.doc.resolve(e<0?a:a+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof H&&r.node.isInline)return hn(t,new z(e>0?r.$to:r.$from));{let i=ic(t.state,e);return i?hn(t,i):!1}}}function ms(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Fi(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Rr(t,e){return e<0?H0(t):V0(t)}function H0(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(ot&&n.nodeType==1&&r<ms(n)&&Fi(n.childNodes[r],-1)&&(s=!0);;)if(r>0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(Fi(a,-1))i=n,o=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if(Wm(n))break;{let a=n.previousSibling;for(;a&&Fi(a,-1);)i=n.parentNode,o=ve(a),a=a.previousSibling;if(a)n=a,r=ms(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?oc(t,n,r):i&&oc(t,i,o)}function V0(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=ms(n),o,s;for(;;)if(r<i){if(n.nodeType!=1)break;let a=n.childNodes[r];if(Fi(a,1))o=n,s=++r;else break}else{if(Wm(n))break;{let a=n.nextSibling;for(;a&&Fi(a,1);)o=a.parentNode,s=ve(a)+1,a=a.nextSibling;if(a)n=a,r=0,i=ms(n);else{if(n=n.parentNode,n==t.dom)break;r=i=0}}}o&&oc(t,o,s)}function Wm(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function W0(t,e){for(;t&&e==t.childNodes.length&&!Vi(t);)e=ve(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let n=t.childNodes[e];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable=="false")break;t=n,e=0}}function j0(t,e){for(;t&&!e&&!Vi(t);)e=ve(t),t=t.parentNode;for(;t&&e;){let n=t.childNodes[e-1];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable=="false")break;t=n,e=t.childNodes.length}}function oc(t,e,n){if(e.nodeType!=3){let o,s;(s=W0(e,n))?(e=s,n=0):(o=j0(e,n))&&(e=o,n=o.nodeValue.length)}let r=t.domSelection();if(!r)return;if(Ss(r)){let o=document.createRange();o.setEnd(e,n),o.setStart(e,n),r.removeAllRanges(),r.addRange(o)}else r.extend&&r.extend(e,n);t.domObserver.setCurSelection();let{state:i}=t;setTimeout(()=>{t.state==i&&Ut(t)},50)}function pm(t,e){let n=t.state.doc.resolve(e);if(!(we||Nm)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s<i.bottom&&Math.abs(o.left-i.left)>1)return o.left<i.left?"ltr":"rtl"}if(e<n.end()){let o=t.coordsAtPos(e+1),s=(o.top+o.bottom)/2;if(s>i.top&&s<i.bottom&&Math.abs(o.left-i.left)>1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function hm(t,e,n){let r=t.state.selection;if(r instanceof z&&!r.empty||n.indexOf("s")>-1||rt&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=ic(t.state,e);if(s&&s instanceof H)return hn(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,a=r instanceof Ke?$.near(s,e):$.findFrom(s,e);return a?hn(t,a):!1}return!1}function mm(t,e){if(!(t.state.selection instanceof z))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function gm(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function q0(t){if(!De||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;gm(t,r,"true"),setTimeout(()=>gm(t,r,"false"),20)}return!1}function K0(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function U0(t,e){let n=e.keyCode,r=K0(e);if(n==8||rt&&n==72&&r=="c")return mm(t,-1)||Rr(t,-1);if(n==46&&!e.shiftKey||rt&&n==68&&r=="c")return mm(t,1)||Rr(t,1);if(n==13||n==27)return!0;if(n==37||rt&&n==66&&r=="c"){let i=n==37?pm(t,t.state.selection.from)=="ltr"?-1:1:-1;return dm(t,i,r)||Rr(t,i)}else if(n==39||rt&&n==70&&r=="c"){let i=n==39?pm(t,t.state.selection.from)=="ltr"?1:-1:1;return dm(t,i,r)||Rr(t,i)}else{if(n==38||rt&&n==80&&r=="c")return hm(t,-1,r)||Rr(t,-1);if(n==40||rt&&n==78&&r=="c")return q0(t)||hm(t,1,r)||Rr(t,1);if(r==(rt?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function yc(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=t.someProp("clipboardSerializer")||cn.fromSchema(t.state.schema),a=Gm(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c=l.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Jm[c.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let h=a.createElement(u[p]);for(;l.firstChild;)h.appendChild(l.firstChild);l.appendChild(h),f++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(n)}`);let d=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,` -`);return{dom:l,text:d,slice:e}}function Wm(t,e,n,r,i){let o=i.parent.type.spec.code,s,a;if(!n&&!e)return null;let l=!!e&&(r||o||!n);if(l){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return a=new A(E.from(t.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0),t.someProp("transformPasted",d=>{a=d(a,t,!0)}),a;let f=t.someProp("clipboardTextParser",d=>d(e,i,r,t));if(f)a=f;else{let d=i.marks(),{schema:p}=t.state,h=cn.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,d)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),s=Q0(n),Wi&&Y0(s);let c=s&&s.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||ln.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!U0.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)a=X0(gm(a,+u[1],+u[2]),u[4]);else if(a=A.maxOpen(J0(a.content,i),!0),a.openStart||a.openEnd){let f=0,d=0;for(let p=a.content.firstChild;f<a.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=a.content.lastChild;d<a.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);a=gm(a,f,d)}return t.someProp("transformPasted",f=>{a=f(a,t,l)}),a}var U0=/^(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 J0(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),o,s=[];if(t.forEach(a=>{if(!s)return;let l=i.findWrapping(a.type),c;if(!l)return s=null;if(c=s.length&&o.length&&qm(l,o,a,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Km(s[s.length-1],o.length));let u=jm(a,l);s.push(u),i=i.matchType(u.type),o=l}}),s)return E.from(s)}return t}function jm(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,E.from(t));return t}function qm(t,e,n,r,i){if(i<t.length&&i<e.length&&t[i]==e[i]){let o=qm(t,e,n,r.lastChild,i+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(i==t.length-1?n.type:t[i+1]))return r.copy(r.content.append(E.from(jm(n,t,i+1))))}}function Km(t,e){if(e==0)return t;let n=t.content.replaceChild(t.childCount-1,Km(t.lastChild,e-1)),r=t.contentMatchAt(t.childCount).fillBefore(E.empty,!0);return t.copy(n.append(r))}function sc(t,e,n,r,i,o){let s=e<0?t.firstChild:t.lastChild,a=s.content;return t.childCount>1&&(o=0),i<r-1&&(a=sc(a,e,n,r,i+1,o)),i>=n&&(a=e<0?s.contentMatchAt(0).fillBefore(a,o<=i).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(E.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(a))}function gm(t,e,n){return e<t.openStart&&(t=new A(sc(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),n<t.openEnd&&(t=new A(sc(t.content,1,n,t.openEnd,0,0),t.openStart,n)),t}var Um={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function Jm(){return document.implementation.createHTMLDocument("title")}var ql=null;function G0(t){let e=window.trustedTypes;return e?(ql||(ql=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:n=>n})),ql.createHTML(t)):t}function Q0(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Jm(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(t),o;if((o=i&&Um[i[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"</"+s+">").reverse().join("")),r.innerHTML=G0(t),o)for(let s=0;s<o.length;s++)r=r.querySelector(o[s])||r;for(let s=0;s<n.styleSheets.length;s++){let a=n.styleSheets[s];for(let l=0;l<a.rules.length;l++){let c=a.rules[l];if(c instanceof CSSStyleRule){let u=r.querySelectorAll(c.selectorText);for(let f=0;f<u.length;f++)u[f].style.cssText+=c.style.cssText}}}return r}function Y0(t){let e=t.querySelectorAll(we?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<e.length;n++){let r=e[n];r.childNodes.length==1&&r.textContent=="\xA0"&&r.parentNode&&r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),r)}}function X0(t,e){if(!t.size)return t;let n=t.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return t}let{content:i,openStart:o,openEnd:s}=t;for(let a=r.length-2;a>=0;a-=2){let l=n.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;i=E.from(l.create(r[a+1],i)),o++,s++}return new A(i,o,s)}var Le={},Pe={},Z0={touchstart:!0,touchmove:!0},ac=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 eC(t){for(let e in Le){let n=Le[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{nC(t,r)&&!kc(t,r)&&(t.editable||!(r.type in Pe))&&n(t,r)},Z0[e]?{passive:!0}:void 0)}De&&t.dom.addEventListener("input",()=>null),lc(t)}function Kt(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function tC(t){t.input.mouseDown&&t.input.mouseDown.done(),t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function lc(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>kc(t,r))})}function kc(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function nC(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function rC(t,e){!kc(t,e)&&Le[e.type]&&(t.editable||!(e.type in Pe))&&Le[e.type](t,e)}Pe.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!Ym(t)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(qt&&we&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),Br&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,Kn(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||K0(t,n)?n.preventDefault():Kt(t,"key")};Pe.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Pe.keypress=(t,e)=>{let n=e;if(Ym(t)||!n.charCode||n.ctrlKey&&!n.altKey||rt&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof z)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode),o=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",s=>s(t,r.$from.pos,r.$to.pos,i,o))&&t.dispatch(o()),n.preventDefault()}};function ji(t){return{left:t.clientX,top:t.clientY}}function iC(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function bc(t,e,n,r,i){if(r==-1)return!1;let o=t.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,a=>s>o.depth?a(t,n,o.nodeAfter,o.before(s),i,!0):a(t,n,o.node(s),o.before(s),i,!1)))return!0;return!1}function qi(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function oC(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&H.isSelectable(r)?(qi(t,new H(n),"pointer"),!0):!1}function sC(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof H&&(r=n.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let a=s>o.depth?o.nodeAfter:o.node(s);if(H.isSelectable(a)){r&&n.$from.depth>0&&s>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?i=o.before(n.$from.depth):i=o.before(s);break}}return i!=null?(qi(t,H.create(t.state.doc,i),"pointer"),!0):!1}function aC(t,e,n,r,i){return bc(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?sC(t,n):oC(t,n))}function lC(t,e,n,r){return bc(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function cC(t,e,n,r){return bc(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||uC(t,n,r)}function uC(t,e,n){if(n.button!=0)return!1;let r=Gm(t,e,!0),i=t.state.doc;return r?(qi(t,r,"pointer"),r instanceof z&&i.eq(t.state.doc)&&(t.input.mouseDown=new uc(t,r)),!0):!1}function Gm(t,e,n){let r=t.state.doc;if(e==-1)return r.inlineContent?z.create(r,0,r.content.size):null;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),a=i.before(o);if(s.inlineContent)return z.create(r,a+1,a+1+s.content.size);if(n&&H.isSelectable(s))return H.create(r,a)}return null}function xc(t){return ys(t)}var Qm=rt?"metaKey":"ctrlKey";Le.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=xc(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&iC(n,t.input.lastClick)&&!n[Qm]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o,button:n.button},t.input.mouseDown&&t.input.mouseDown.done();let s=t.posAtCoords(ji(n));s&&(o=="singleClick"?t.input.mouseDown=new cc(t,s,n,!!r):(o=="doubleClick"?lC:cC)(t,s.pos,s.inside,n)?n.preventDefault():Kt(t,"pointer"))};var gs=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},cc=class extends gs{constructor(e,n,r,i){super(e),this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!r[Qm],this.allowDefault=r.shiftKey;let o,s;if(n.inside>-1)o=e.state.doc.nodeAt(n.inside),s=n.inside;else{let u=e.state.doc.resolve(n.pos);o=u.parent,s=u.depth?u.before():0}let a=i?null:r.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:c}=e.state;r.button==0&&(o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof H&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ot&&!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()),Kt(e,"pointer")}done(){super.done(),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(()=>{this.view.isDestroyed||Ut(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(ji(e))),this.updateAllowDefault(e),this.allowDefault||!n?Kt(this.view,"pointer"):aC(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||De&&this.mightDrag&&!this.mightDrag.node.isAtom||we&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(qi(this.view,$.near(this.view.state.doc.resolve(n.pos)),"pointer"),e.preventDefault()):Kt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Kt(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},uc=class extends gs{constructor(e,n){super(e),this.startSelection=n,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),Kt(this.view,"pointer");let n=this.view.posAtCoords(ji(e)),r=n&&Gm(this.view,n.inside,!1);if(!r)return;let{doc:i}=this.view.state,o=this.startSelection,[s,a]=r.from<o.from?[o.to,r.from]:[o.from,r.to];qi(this.view,z.create(i,s,a),"pointer")}};Le.touchstart=t=>{t.input.lastTouch=Date.now(),xc(t),Kt(t,"pointer")};Le.touchmove=t=>{t.input.lastTouch=Date.now(),Kt(t,"pointer")};Le.contextmenu=t=>xc(t);function Ym(t,e){return t.composing?!0:De&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var fC=qt?5e3:-1;Pe.compositionstart=Pe.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof z&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||we&&Am&&dC(t)))t.markCursor=t.state.storedMarks||n.marks(),ys(t,!0),t.markCursor=null;else if(ys(t,!e.selection.empty),ot&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let a=t.domSelection();a&&a.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}t.input.composing=!0}Xm(t,fC)};function dC(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}Pe.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now(),t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,Xm(t,20))};function Xm(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>ys(t),e))}function Zm(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function pC(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=u0(e.focusNode,e.focusOffset),r=f0(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,o=t.domObserver.lastChangedTextNode;if(n==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let s=n.pmViewDesc;if(!(!s||!s.isText(n.nodeValue)))return r}}return n||r}function ys(t,e=!1){if(!(qt&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Zm(t),e||t.docView&&t.docView.dirty){let n=mc(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function hC(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}var zi=Ve&&mn<15||Br&&m0<604;Le.copy=Pe.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=zi?null:n.clipboardData,s=r.content(),{dom:a,text:l}=yc(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):hC(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function mC(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function gC(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.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=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?$i(t,r.value,null,i,e):$i(t,r.textContent,r.innerHTML,i,e)},50)}function $i(t,e,n,r,i){let o=Wm(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,i,o||A.empty)))return!0;if(!o)return!1;let s=mC(o),a=s?t.state.tr.replaceSelectionWith(s,r):t.state.tr.replaceSelection(o);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function eg(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Pe.paste=(t,e)=>{let n=e;if(t.composing&&!qt)return;let r=zi?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&$i(t,eg(r),r.getData("text/html"),i,n)?n.preventDefault():gC(t,n)};var ks=class{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}},yC=rt?"altKey":"ctrlKey";function tg(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[yC]}Le.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,o=i.empty?null:t.posAtCoords(ji(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof H?i.to-1:i.to))){if(r&&r.mightDrag)s=H.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(s=H.create(t.state.doc,f.posBefore))}}let a=(s||t.state.selection).content(),{dom:l,text:c,slice:u}=yc(t,a);(!n.dataTransfer.files.length||!we||Im>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(zi?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",zi||n.dataTransfer.setData("text/plain",c),t.dragging=new ks(u,tg(t,n),s)};Le.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Pe.dragover=Pe.dragenter=(t,e)=>e.preventDefault();Pe.drop=(t,e)=>{try{kC(t,e,t.dragging)}finally{t.dragging=null}};function kC(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(ji(e));if(!r)return;let i=t.state.doc.resolve(r.pos),o=n&&n.slice;o?t.someProp("transformPasted",p=>{o=p(o,t,!1)}):o=Wm(t,eg(e.dataTransfer),zi?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(n&&tg(t,e));if(t.someProp("handleDrop",p=>p(t,e,o||A.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let a=o?ph(t.state.doc,i.pos,o):i.pos;a==null&&(a=i.pos);let l=t.state.tr;if(s){let{node:p}=n;p?p.replace(l):l.deleteSelection()}let c=l.mapping.map(a),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=l.doc;if(u?l.replaceRangeWith(c,c,o.content.firstChild):l.replaceRange(c,c,o),l.doc.eq(f))return;let d=l.doc.resolve(c);if(u&&H.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))l.setSelection(new H(d));else{let p=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((h,m,g,y)=>p=y),l.setSelection(gc(t,d,l.doc.resolve(p)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}Le.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Ut(t)},20))};Le.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Le.beforeinput=(t,e)=>{if(we&&qt&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,Kn(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Pe)Le[t]=Pe[t];function _i(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}var bs=class t{constructor(e,n){this.toDOM=e,this.spec=n||Yn,this.side=this.spec.side||0}map(e,n,r,i){let{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof t&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&_i(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Qn=class t{constructor(e,n){this.attrs=e,this.spec=n||Yn}map(e,n,r,i){let o=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new se(o,s,this)}valid(e,n){return n.from<n.to}eq(e){return this==e||e instanceof t&&_i(this.attrs,e.attrs)&&_i(this.spec,e.spec)}static is(e){return e.type instanceof t}destroy(){}},fc=class t{constructor(e,n){this.attrs=e,this.spec=n||Yn}map(e,n,r,i){let o=e.mapResult(n.from+i,1);if(o.deleted)return null;let s=e.mapResult(n.to+i,-1);return s.deleted||s.pos<=o.pos?null:new se(o.pos-r,s.pos-r,this)}valid(e,n){let{index:r,offset:i}=e.content.findIndex(n.from),o;return i==n.from&&!(o=e.child(r)).isText&&i+o.nodeSize==n.to}eq(e){return this==e||e instanceof t&&_i(this.attrs,e.attrs)&&_i(this.spec,e.spec)}destroy(){}},se=class t{constructor(e,n,r){this.from=e,this.to=n,this.type=r}copy(e,n){return new t(e,n,this.type)}eq(e,n=0){return this.type.eq(e.type)&&this.from+n==e.from&&this.to+n==e.to}map(e,n,r){return this.type.map(e,this,n,r)}static widget(e,n,r){return new t(e,e,new bs(n,r))}static inline(e,n,r,i){return new t(e,n,new Qn(r,i))}static node(e,n,r,i){return new t(e,n,new fc(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Qn}get widget(){return this.type instanceof bs}},Or=[],Yn={},ne=class t{constructor(e,n){this.local=e.length?e:Or,this.children=n.length?n:Or}static create(e,n){return n.length?ws(n,e,0,Yn):Oe}find(e,n,r){let i=[];return this.findInner(e??0,n??1e9,i,0,r),i}findInner(e,n,r,i,o){for(let s=0;s<this.local.length;s++){let a=this.local[s];a.from<=n&&a.to>=e&&(!o||o(a.spec))&&r.push(a.copy(a.from+i,a.to+i))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<n&&this.children[s+1]>e){let a=this.children[s]+1;this.children[s+2].findInner(e-a,n-a,r,i+a,o)}}map(e,n,r){return this==Oe||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Yn)}mapInner(e,n,r,i,o){let s;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,r,i);l&&l.type.valid(n,l)?(s||(s=[])).push(l):o.onRemove&&o.onRemove(this.local[a].spec)}return this.children.length?bC(this.children,s||[],e,n,r,i,o):s?new t(s.sort(Xn),Or):Oe}add(e,n){return n.length?this==Oe?t.create(e,n):this.addInner(e,n,0):this}addInner(e,n,r){let i,o=0;e.forEach((a,l)=>{let c=l+r,u;if(u=rg(n,a,c)){for(i||(i=this.children.slice());o<i.length&&i[o]<l;)o+=3;i[o]==l?i[o+2]=i[o+2].addInner(a,u,c+1):i.splice(o,0,l,l+a.nodeSize,ws(u,a,c+1,Yn)),o+=3}});let s=ng(o?ig(n):n,-r);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||s.splice(a--,1);return new t(s.length?this.local.concat(s).sort(Xn):this.local,i||this.children)}remove(e){return e.length==0||this==Oe?this:this.removeInner(e,0)}removeInner(e,n){let r=this.children,i=this.local;for(let o=0;o<r.length;o+=3){let s,a=r[o]+n,l=r[o+1]+n;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>a&&f.to<l&&(e[u]=null,(s||(s=[])).push(f));if(!s)continue;r==this.children&&(r=this.children.slice());let c=r[o+2].removeInner(s,a+1);c!=Oe?r[o+2]=c:(r.splice(o,3),o-=3)}if(i.length){for(let o=0,s;o<e.length;o++)if(s=e[o])for(let a=0;a<i.length;a++)i[a].eq(s,n)&&(i==this.local&&(i=this.local.slice()),i.splice(a--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new t(i,r):Oe}forChild(e,n){if(this==Oe)return this;if(n.isLeaf)return t.empty;let r,i;for(let a=0;a<this.children.length;a+=3)if(this.children[a]>=e){this.children[a]==e&&(r=this.children[a+2]);break}let o=e+1,s=o+n.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<s&&l.to>o&&l.type instanceof Qn){let c=Math.max(o,l.from)-o,u=Math.min(s,l.to)-o;c<u&&(i||(i=[])).push(l.copy(c,u))}}if(i){let a=new t(i.sort(Xn),Or);return r?new xs([a,r]):a}return r||Oe}eq(e){if(this==e)return!0;if(!(e instanceof t)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let n=0;n<this.local.length;n++)if(!this.local[n].eq(e.local[n]))return!1;for(let n=0;n<this.children.length;n+=3)if(this.children[n]!=e.children[n]||this.children[n+1]!=e.children[n+1]||!this.children[n+2].eq(e.children[n+2]))return!1;return!0}locals(e){return wc(this.localsInner(e))}localsInner(e){if(this==Oe)return Or;if(e.inlineContent||!this.local.some(Qn.is))return this.local;let n=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Qn||n.push(this.local[r]);return n}forEachSet(e){e(this)}};ne.empty=new ne([],[]);ne.removeOverlap=wc;var Oe=ne.empty,xs=class t{constructor(e){this.members=e}map(e,n){let r=this.members.map(i=>i.map(e,n,Yn));return t.from(r)}forChild(e,n){if(n.isLeaf)return ne.empty;let r=[];for(let i=0;i<this.members.length;i++){let o=this.members[i].forChild(e,n);o!=Oe&&(o instanceof t?r=r.concat(o.members):r.push(o))}return t.from(r)}eq(e){if(!(e instanceof t)||e.members.length!=this.members.length)return!1;for(let n=0;n<this.members.length;n++)if(!this.members[n].eq(e.members[n]))return!1;return!0}locals(e){let n,r=!0;for(let i=0;i<this.members.length;i++){let o=this.members[i].localsInner(e);if(o.length)if(!n)n=o;else{r&&(n=n.slice(),r=!1);for(let s=0;s<o.length;s++)n.push(o[s])}}return n?wc(r?n:n.sort(Xn)):Or}static from(e){switch(e.length){case 0:return Oe;case 1:return e[0];default:return new t(e.every(n=>n instanceof ne)?e:e.reduce((n,r)=>n.concat(r instanceof ne?r:r.members),[]))}}forEachSet(e){for(let n=0;n<this.members.length;n++)this.members[n].forEachSet(e)}};function bC(t,e,n,r,i,o,s){let a=t.slice();for(let c=0,u=o;c<n.maps.length;c++){let f=0;n.maps[c].forEach((d,p,h,m)=>{let g=m-h-(p-d);for(let y=0;y<a.length;y+=3){let x=a[y+1];if(x<0||d>x+u-f)continue;let C=a[y]+u-f;p>=C?a[y+1]=d<=C?-2:-1:d>=u&&g&&(a[y]+=g,a[y+1]+=g)}f+=g}),u=n.maps[c].map(u,-1)}let l=!1;for(let c=0;c<a.length;c+=3)if(a[c+1]<0){if(a[c+1]==-2){l=!0,a[c+1]=-1;continue}let u=n.map(t[c]+o),f=u-i;if(f<0||f>=r.content.size){l=!0;continue}let d=n.map(t[c+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),g=r.maybeChild(h);if(g&&m==f&&m+g.nodeSize==p){let y=a[c+2].mapInner(n,g,u+1,t[c]+o+1,s);y!=Oe?(a[c]=f,a[c+1]=p,a[c+2]=y):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=xC(a,t,e,n,i,o,s),u=ws(c,r,0,s);e=u.local;for(let f=0;f<a.length;f+=3)a[f+1]<0&&(a.splice(f,3),f-=3);for(let f=0,d=0;f<u.children.length;f+=3){let p=u.children[f];for(;d<a.length&&a[d]<p;)d+=3;a.splice(d,0,u.children[f],u.children[f+1],u.children[f+2])}}return new ne(e.sort(Xn),a)}function ng(t,e){if(!e||!t.length)return t;let n=[];for(let r=0;r<t.length;r++){let i=t[r];n.push(new se(i.from+e,i.to+e,i.type))}return n}function xC(t,e,n,r,i,o,s){function a(l,c){for(let u=0;u<l.local.length;u++){let f=l.local[u].map(r,i,c);f?n.push(f):s.onRemove&&s.onRemove(l.local[u].spec)}for(let u=0;u<l.children.length;u+=3)a(l.children[u+2],l.children[u]+c+1)}for(let l=0;l<t.length;l+=3)t[l+1]==-1&&a(t[l+2],e[l]+o+1);return n}function rg(t,e,n){if(e.isLeaf)return null;let r=n+e.nodeSize,i=null;for(let o=0,s;o<t.length;o++)(s=t[o])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),t[o]=null);return i}function ig(t){let e=[];for(let n=0;n<t.length;n++)t[n]!=null&&e.push(t[n]);return e}function ws(t,e,n,r){let i=[],o=!1;e.forEach((a,l)=>{let c=rg(t,a,l+n);if(c){o=!0;let u=ws(c,a,n+l+1,r);u!=Oe&&i.push(l,l+a.nodeSize,u)}});let s=ng(o?ig(t):t,-n).sort(Xn);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||(r.onRemove&&r.onRemove(s[a].spec),s.splice(a--,1));return s.length||i.length?new ne(s,i):Oe}function Xn(t,e){return t.from-e.from||t.to-e.to}function wc(t){let e=t;for(let n=0;n<e.length-1;n++){let r=e[n];if(r.from!=r.to)for(let i=n+1;i<e.length;i++){let o=e[i];if(o.from==r.from){o.to!=r.to&&(e==t&&(e=t.slice()),e[i]=o.copy(o.from,r.to),ym(e,i+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(e==t&&(e=t.slice()),e[n]=r.copy(r.from,o.from),ym(e,i,r.copy(o.from,r.to)));break}}}return e}function ym(t,e,n){for(;e<t.length&&Xn(n,t[e])>0;)e++;t.splice(e,0,n)}function Kl(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=Oe&&e.push(r)}),t.cursorWrapper&&e.push(ne.create(t.state.doc,[t.cursorWrapper.deco])),xs.from(e)}var wC={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},SC=Ve&&mn<=11,dc=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}},pc=class{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new dc,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;i<r.length;i++)this.queue.push(r[i]);Ve&&mn<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():De&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),SC&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,wC)),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 n=0;n<e.length;n++)this.queue.push(e[n]);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(um(this.view)){if(this.suppressingSelectionUpdates)return Ut(this.view);if(Ve&&mn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Zn(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 n=new Set,r;for(let o=e.focusNode;o;o=Dr(o))n.add(o);for(let o=e.anchorNode;o;o=Dr(o))if(n.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&um(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,a=!1,l=[];if(e.editable)for(let u=0;u<n.length;u++){let f=this.registerMutation(n[u],l);f&&(o=o<0?f.from:Math.min(f.from,o),s=s<0?f.to:Math.max(f.to,s),f.typeOver&&(a=!0))}if(l.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||we&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&n.some(u=>u.type=="childList"&&u.removedNodes.length))){for(let u of l)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;for(;f&&f.nodeType==1;){if(f.contentEditable=="false"){u.parentNode.removeChild(u);break}f=f.firstChild}}}else if(ot&&l.length){let u=l.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,d]=u;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of u){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||EC(e,f)!=p)&&d.remove()}}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ss(r)&&(c=mc(e))&&c.eq($.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Ut(e),this.currentSelection.set(r),e.scrollToSelection()):(o>-1||i)&&(o>-1&&(e.docView.markDirty(o,s),CC(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,TC(e,l)),this.handleDOMChange(o,s,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Ut(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];n.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let i=e.previousSibling,o=e.nextSibling;if(Ve&&mn<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:d}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(o=d)}let s=i&&i.parentNode==e.target?ve(i)+1:0,a=r.localPosFromDOM(e.target,s,-1),l=o&&o.parentNode==e.target?ve(o):e.target.childNodes.length,c=r.localPosFromDOM(e.target,l,1);return{from:a,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},km=new WeakMap,bm=!1;function CC(t){if(!km.has(t)&&(km.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=ot,bm)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."),bm=!0}}function xm(t,e){let n=e.startContainer,r=e.startOffset,i=e.endContainer,o=e.endOffset,s=t.domAtPos(t.state.selection.anchor);return Zn(s.node,s.offset,i,o)&&([n,r,i,o]=[i,o,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:o}}function MC(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return xm(t,i)}let n;function r(i){i.preventDefault(),i.stopImmediatePropagation(),n=i.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",r,!0),n?xm(t,n):null}function EC(t,e){for(let n=e.parentNode;n&&n!=t.dom;n=n.parentNode){let r=t.docView.nearestDesc(n,!0);if(r&&r.node.isBlock)return n}return null}function TC(t,e){var n;let{focusNode:r,focusOffset:i}=t.domSelectionRange();for(let o of e)if(((n=o.parentNode)===null||n===void 0?void 0:n.nodeName)=="TR"){let s=o.nextSibling;for(;s&&s.nodeName!="TD"&&s.nodeName!="TH";)s=s.nextSibling;if(s){let a=s;for(;;){let l=a.firstChild;if(!l||l.nodeType!=1||l.contentEditable=="false"||/^(BR|IMG)$/.test(l.nodeName))break;a=l}a.insertBefore(o,a.firstChild),r==o&&t.domSelection().collapse(o,i)}else o.parentNode.removeChild(o)}}function vC(t,e,n){let{node:r,fromOffset:i,toOffset:o,from:s,to:a}=t.docView.parseRange(e,n),l=t.domSelectionRange(),c,u=l.anchorNode;if(u&&t.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:l.anchorOffset}],Ss(l)||c.push({node:l.focusNode,offset:l.focusOffset})),we&&t.input.lastKeyCode===8)for(let g=o;g>i;g--){let y=r.childNodes[g-1],x=y.pmViewDesc;if(y.nodeName=="BR"&&!x){o=g;break}if(!x||x.size)break}let f=t.state.doc,d=t.someProp("domParser")||ln.fromSchema(t.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:IC,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),h={anchor:g+s,head:y+s}}return{doc:m,sel:h,from:s,to:a}}function IC(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(De&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||De&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}var AC=/^(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 NC(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let N=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,D=mc(t,N);if(D&&!t.state.selection.eq(D)){if(we&&qt&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",S=>S(t,Kn(13,"Enter"))))return;let B=t.state.tr.setSelection(D);N=="pointer"?B.setMeta("pointer",!0):N=="key"&&B.scrollIntoView(),o&&B.setMeta("composition",o),t.dispatch(B)}return}let s=t.state.doc.resolve(e),a=s.sharedDepth(n);e=s.before(a+1),n=t.state.doc.resolve(n).after(a+1);let l=t.state.selection,c=vC(t,e,n),u=t.state.doc,f=u.slice(c.from,c.to),d,p;t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime?(d=t.state.selection.to,p="end"):(d=t.state.selection.from,p="start"),t.input.lastKeyCode=null;let h=DC(f.content,c.doc.content,c.from,d,p);if(h&&t.input.domChangeCount++,(Br&&t.input.lastIOSEnter>Date.now()-225||qt)&&i.some(N=>N.nodeType==1&&!AC.test(N.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",N=>N(t,Kn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&l instanceof z&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let N=wm(t,t.state.doc,c.sel);if(N&&!N.eq(t.state.selection)){let D=t.state.tr.setSelection(N);o&&D.setMeta("composition",o),t.dispatch(D)}}return}t.state.selection.from<t.state.selection.to&&h.start==h.endB&&t.state.selection instanceof z&&(h.start>t.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=c.from?h.start=t.state.selection.from:h.endA<t.state.selection.to&&h.endA>=t.state.selection.to-2&&t.state.selection.to<=c.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),Ve&&mn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>c.from&&c.doc.textBetween(h.start-c.from-1,h.start-c.from+1)==" \xA0"&&(h.start--,h.endA--,h.endB--);let m=c.doc.resolveNoCache(h.start-c.from),g=c.doc.resolveNoCache(h.endB-c.from),y=u.resolve(h.start),x=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=h.endA;if((Br&&t.input.lastIOSEnter>Date.now()-225&&(!x||i.some(N=>N.nodeName=="DIV"||N.nodeName=="P"))||!x&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(c.doc.textBetween(m.pos,g.pos,"","")))&&t.someProp("handleKeyDown",N=>N(t,Kn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&OC(u,h.start,h.endA,m,g)&&t.someProp("handleKeyDown",N=>N(t,Kn(8,"Backspace")))){qt&&we&&t.domObserver.suppressSelectionUpdates();return}we&&h.endB==h.start&&(t.input.lastChromeDelete=Date.now()),qt&&!x&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==h.endA&&(h.endB-=2,g=c.doc.resolveNoCache(h.endB-c.from),setTimeout(()=>{t.someProp("handleKeyDown",function(N){return N(t,Kn(13,"Enter"))})},20));let C=h.start,v=h.endA,I=N=>{let D=N||t.state.tr.replace(C,v,c.doc.slice(h.start-c.from,h.endB-c.from));if(c.sel){let B=wm(t,D.doc,c.sel);B&&!(we&&t.composing&&B.empty&&(h.start!=h.endB||t.input.lastChromeDelete<Date.now()-100)&&(B.head==C||B.head==D.mapping.map(v)-1)||Ve&&B.empty&&B.head==C)&&D.setSelection(B)}return o&&D.setMeta("composition",o),D.scrollIntoView()},w;if(x)if(m.pos==g.pos){Ve&&mn<=11&&m.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>Ut(t),20));let N=I(t.state.tr.delete(C,v)),D=u.resolve(h.start).marksAcross(u.resolve(h.endA));D&&N.ensureMarks(D),t.dispatch(N)}else if(h.endA==h.endB&&(w=RC(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,h.endA-y.start())))){let N=I(t.state.tr);w.type=="add"?N.addMark(C,v,w.mark):N.removeMark(C,v,w.mark),t.dispatch(N)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let N=m.parent.textBetween(m.parentOffset,g.parentOffset),D=()=>I(t.state.tr.insertText(N,C,v));t.someProp("handleTextInput",B=>B(t,C,v,N,D))||t.dispatch(D())}else t.dispatch(I());else t.dispatch(I())}function wm(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:gc(t,e.resolve(n.anchor),e.resolve(n.head))}function RC(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,a,l;for(let u=0;u<r.length;u++)i=r[u].removeFromSet(i);for(let u=0;u<n.length;u++)o=n[u].removeFromSet(o);if(i.length==1&&o.length==0)a=i[0],s="add",l=u=>u.mark(a.addToSet(u.marks));else if(i.length==0&&o.length==1)a=o[0],s="remove",l=u=>u.mark(a.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(l(e.child(u)));if(E.from(c).eq(t))return{mark:a,type:s}}function OC(t,e,n,r,i){if(n-e<=i.pos-r.pos||Ul(r,!0,!1)<i.pos)return!1;let o=t.resolve(e);if(!r.parent.isTextblock){let a=o.nodeAfter;return a!=null&&n==e+a.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=t.resolve(Ul(o,!0,!0));return!s.parent.isTextblock||s.pos>n||Ul(s,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(s.parent.content)}function Ul(t,e,n){let r=t.depth,i=e?t.end():t.pos;for(;r>0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let o=t.node(r).maybeChild(t.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function DC(t,e,n,r,i){let o=t.findDiffStart(e,n),s=n+t.size,a=n+e.size;if(o==null)return null;let{a:l,b:c}=t.findDiffEnd(e,s,a);if(i=="end"){let u=Math.max(0,o-Math.min(l,c));r-=l+u-o}if(l<o&&s<a){let u=r<=o&&r>=l?o-r:0;o-=u,c=o+(c-l),l=o}else if(c<o){let u=r<=o&&r>=c?o-r:0;o-=u,l=o+(l-c),c=o}return{start:o,endA:l,endB:c}}var Hi=class{constructor(e,n){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 ac,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(Tm),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=Mm(this),Cm(this),this.nodeViews=Em(this),this.docView=im(this.state.doc,Sm(this),Kl(this),this.dom,this),this.domObserver=new pc(this,(r,i,o,s)=>NC(this,r,i,o,s)),this.domObserver.start(),eC(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&lc(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Tm),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Zm(this),s=!0),this.state=e;let a=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(a||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=Em(this);LC(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&lc(this),this.editable=Mm(this),Cm(this);let l=Kl(this),c=Sm(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,c,l);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&k0(this);if(s){this.domObserver.stop();let p=f&&(Ve||we)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&BC(i.selection,e.selection);if(f){let m=we?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=pC(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=im(e.doc,c,l,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let h=this.input.mouseDown;p||!(h&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&$0(this)&&h.delaySelUpdate())?Ut(this,p):(_m(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():d&&b0(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof H){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&Zh(this,n.getBoundingClientRect(),e)}else Zh(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 n=0;n<this.directPlugins.length;n++){let r=this.directPlugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let n=0;n<this.state.plugins.length;n++){let r=this.state.plugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let n=0;n<this.pluginViews.length;n++){let r=this.pluginViews[n];r.update&&r.update(this,e)}}updateDraggedNode(e,n){let r=e.node,i=-1;if(r.from<this.state.doc.content.size&&this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let o=r.from+(this.state.doc.content.size-n.doc.content.size);(o>0&&o<this.state.doc.content.size&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ks(e.slice,e.move,i<0?void 0:H.create(this.state.doc,i))}someProp(e,n){let r=this._props&&this._props[e],i;if(r!=null&&(i=n?n(r):r))return i;for(let s=0;s<this.directPlugins.length;s++){let a=this.directPlugins[s].props[e];if(a!=null&&(i=n?n(a):a))return i}let o=this.state.plugins;if(o)for(let s=0;s<o.length;s++){let a=o[s].props[e];if(a!=null&&(i=n?n(a):a))return i}}hasFocus(){if(Ve){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&&x0(this.dom),Ut(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let n=this.dom.parentNode;n;n=n.parentNode)if(n.nodeType==9||n.nodeType==11&&n.host)return n.getSelection||(Object.getPrototypeOf(n).getSelection=()=>n.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return E0(this,e)}coordsAtPos(e,n=1){return Bm(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return N0(this,n||this.state,e)}pasteHTML(e,n){return $i(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return $i(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return yc(this,e)}destroy(){this.docView&&(tC(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Kl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,l0())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return rC(this,e)}domSelectionRange(){let e=this.domSelection();return e?De&&this.root.nodeType===11&&p0(this.dom.ownerDocument)==this.dom&&MC(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Hi.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function Sm(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[se.node(0,t.state.doc.content.size,e)]}function Cm(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:se.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Mm(t){return!t.someProp("editable",e=>e(t.state)===!1)}function BC(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Em(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function LC(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function Tm(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function Gt(t,e){return t.meta={package:"@milkdown/core",group:"System",...e},t}var ag={text:(t,e,n,r)=>{let i=t.value;return/^[^*_\\]*\s+$/.test(i)?i:n.safe(i,{...r,encode:[]})},strong:(t,e,n,r)=>{let i=t.marker||n.options.strong||"*",o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i+i),o(),a},emphasis:(t,e,n,r)=>{let i=t.marker||n.options.emphasis||"*",o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i),o(),a}},oe=K({},"editorView"),Ki=K({},"editorState"),Sc=K([],"initTimer"),og=K({},"editor"),Hr=K([],"inputRules"),gt=K([],"prosePlugins"),Vr=K([],"remarkPlugins"),Os=K([],"nodeView"),Ds=K([],"markView"),tr=K(Si().use(hr).use(kr),"remark"),Lr=K({handlers:ag,encode:[]},"remarkStringifyOptions"),Cs=nt("ConfigReady");function PC(t){let e=n=>(n.record(Cs),async()=>(await t(n),n.done(Cs),()=>{n.clearTimer(Cs)}));return Gt(e,{displayName:"Config"}),e}var Jt=nt("InitReady");function FC(t){let e=n=>(n.inject(og,t).inject(gt,[]).inject(Vr,[]).inject(Hr,[]).inject(Os,[]).inject(Ds,[]).inject(Lr,{handlers:ag,encode:[]}).inject(tr,Si().use(hr).use(kr)).inject(Sc,[Cs]).record(Jt),async()=>{await n.waitTimers(Sc);let r=n.get(Lr);return n.set(tr,Si().use(hr).use(kr,r)),n.done(Jt),()=>{n.remove(og).remove(gt).remove(Vr).remove(Hr).remove(Os).remove(Ds).remove(Lr).remove(tr).remove(Sc).clearTimer(Jt)}});return Gt(e,{displayName:"Init"}),e}var Fe=nt("SchemaReady"),Ms=K([],"schemaTimer"),mt=K({},"schema"),Pr=K([],"nodes"),Fr=K([],"marks");function sg(t){return{...t,parseDOM:t.parseDOM?.map(e=>({priority:t.priority,...e}))}}var lg=t=>(t.inject(mt,{}).inject(Pr,[]).inject(Fr,[]).inject(Ms,[Jt]).record(Fe),async()=>{await t.waitTimers(Ms);let e=t.get(tr),n=t.get(Vr).reduce((i,o)=>i.use(o.plugin,o.options),e);t.set(tr,n);let r=new Yo({nodes:Object.fromEntries(t.get(Pr).map(([i,o])=>[i,sg(o)])),marks:Object.fromEntries(t.get(Fr).map(([i,o])=>[i,sg(o)]))});return t.set(mt,r),t.done(Fe),()=>{t.remove(mt).remove(Pr).remove(Fr).remove(Ms).clearTimer(Fe)}});Gt(lg,{displayName:"Schema"});var cg=class{constructor(){this.#t=new Ca,this.#e=null,this.setCtx=t=>{this.#e=t},this.chain=()=>{if(this.#e==null)throw So();let t=this.#e,e=[],n=this.get.bind(this),r={run:()=>{let o=qn(...e),s=t.get(oe);return o(s.state,s.dispatch,s)},inline:o=>(e.push(o),r),pipe:i.bind(this)};function i(o,s){let a=n(o);return e.push(a(s)),r}return r}}#t;#e;get ctx(){return this.#e}create(t,e){let n=t.create(this.#t.sliceMap);return n.set(e),n}get(t){return this.#t.get(t).get()}remove(t){return this.#t.remove(t)}call(t,e){if(this.#e==null)throw So();let n=this.get(t)(e),r=this.#e.get(oe);return n(r.state,r.dispatch,r)}inline(t){if(this.#e==null)throw So();let e=this.#e.get(oe);return t(e.state,e.dispatch,e)}};function ug(t="cmdKey"){return K((()=>()=>!1),t)}var G=K(new cg,"commands"),Es=K([Fe],"commandsTimer"),zr=nt("CommandsReady"),fg=t=>{let e=new cg;return e.setCtx(t),t.inject(G,e).inject(Es,[Fe]).record(zr),async()=>(await t.waitTimers(Es),t.done(zr),()=>{t.remove(G).remove(Es).clearTimer(zr)})};Gt(fg,{displayName:"Commands"});function zC(t){return t.Backspace=qn(Bh,is,Ih,Rl),t}var dg=class{constructor(){this.#t=null,this.#e=[],this.setCtx=t=>{this.#t=t},this.add=t=>(this.#e.push(t),()=>{this.#e=this.#e.filter(e=>e!==t)}),this.addObjectKeymap=t=>{let e=[];return Object.entries(t).forEach(([n,r])=>{if(typeof r=="function"){let i={key:n,onRun:()=>r};this.#e.push(i),e.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}else this.#e.push(r),e.push(()=>{this.#e=this.#e.filter(i=>i!==r)})}),()=>{e.forEach(n=>n())}},this.addBaseKeymap=()=>{let t=zC(Dh);return this.addObjectKeymap(t)},this.build=()=>{let t={};return this.#e.forEach(e=>{t[e.key]=[...t[e.key]||[],e]}),Object.fromEntries(Object.entries(t).map(([e,n])=>{let r=n.sort((o,s)=>(s.priority??50)-(o.priority??50));return[e,(o,s,a)=>{let l=this.#t;if(l==null)throw dr();return qn(...r.map(c=>c.onRun(l)))(o,s,a)}]}))}}#t;#e;get ctx(){return this.#t}},Xi=K(new dg,"keymap"),Cc=K([Fe],"keymapTimer"),$r=nt("KeymapReady"),$C=t=>{let e=new dg;return e.setCtx(t),t.inject(Xi,e).inject(Cc,[Fe]).record($r),async()=>(await t.waitTimers(Cc),t.done($r),()=>{t.remove(Xi).remove(Cc).clearTimer($r)})},Ts=nt("ParserReady"),pg=(()=>{throw dr()}),Ue=K(pg,"parser"),Mc=K([],"parserTimer"),hg=t=>(t.inject(Ue,pg).inject(Mc,[Fe]).record(Ts),async()=>{await t.waitTimers(Mc);let e=t.get(tr),n=t.get(mt);return t.set(Ue,Jh.create(n,e)),t.done(Ts),()=>{t.remove(Ue).remove(Mc).clearTimer(Ts)}});Gt(hg,{displayName:"Parser"});var _r=nt("SerializerReady"),Ec=K([],"serializerTimer"),mg=(()=>{throw dr()}),nr=K(mg,"serializer"),gg=t=>(t.inject(nr,mg).inject(Ec,[Fe]).record(_r),async()=>{await t.waitTimers(Ec);let e=t.get(tr),n=t.get(mt);return t.set(nr,Qh.create(n,e)),t.done(_r),()=>{t.remove(nr).remove(Ec).clearTimer(_r)}});Gt(gg,{displayName:"Serializer"});var Ui=K("","defaultValue"),Ji=K(t=>t,"stateOptions"),vs=K([],"editorStateTimer"),Is=nt("EditorStateReady");function _C(t,e,n){if(typeof t=="string")return e(t);if(t.type==="html")return ln.fromSchema(n).parse(t.dom);if(t.type==="json")return He.fromJSON(n,t.value);throw ed(t)}var HC=new ee("MILKDOWN_STATE_TRACKER"),yg=t=>(t.inject(Ui,"").inject(Ki,{}).inject(Ji,e=>e).inject(vs,[Ts,_r,zr,$r]).record(Is),async()=>{await t.waitTimers(vs);let e=t.get(mt),n=t.get(Ue),r=t.get(Hr),i=t.get(Ji),o=t.get(gt),s=_C(t.get(Ui),n,e),a=t.get(Xi),l=a.addBaseKeymap(),c=[...o,new X({key:HC,state:{init:()=>{},apply:(d,p,h,m)=>{t.set(Ki,m)}}}),Fh({rules:r}),Wh(a.build())];t.set(gt,c);let u=i({schema:e,doc:s,plugins:c}),f=Tr.create(u);return t.set(Ki,f),t.done(Is),()=>{l(),t.remove(Ui).remove(Ki).remove(Ji).remove(vs).clearTimer(Is)}});Gt(yg,{displayName:"EditorState"});var Wr=K([],"pasteRule"),As=K([Fe],"pasteRuleTimer"),Ns=nt("PasteRuleReady"),kg=t=>(t.inject(Wr,[]).inject(As,[Fe]).record(Ns),async()=>(await t.waitTimers(As),t.done(Ns),()=>{t.remove(Wr).remove(As).clearTimer(Ns)}));Gt(kg,{displayName:"PasteRule"});var Gi=nt("EditorViewReady"),Rs=K([],"editorViewTimer"),Qi=K({},"editorViewOptions"),Yi=K(null,"root"),Tc=K(null,"rootDOM"),vc=K({},"rootAttrs");function VC(t,e){let n=document.createElement("div");n.className="milkdown",t.appendChild(n),e.set(Tc,n);let r=e.get(vc);return Object.entries(r).forEach(([i,o])=>n.setAttribute(i,o)),n}function WC(t){t.classList.add("editor"),t.setAttribute("role","textbox")}var jC=new ee("MILKDOWN_VIEW_CLEAR"),bg=t=>(t.inject(Yi,document.body).inject(oe,{}).inject(Qi,{}).inject(Tc,null).inject(vc,{}).inject(Rs,[Is,Ns]).record(Gi),async()=>{await t.wait(Jt);let e=t.get(Yi)||document.body,n=typeof e=="string"?document.querySelector(e):e;t.update(gt,s=>[new X({key:jC,view:a=>{let l=n?VC(n,t):void 0;return(()=>{if(l&&n){let u=a.dom;n.replaceChild(l,u),l.appendChild(u)}})(),{destroy:()=>{l?.parentNode&&l?.parentNode.replaceChild(a.dom,l),l?.remove()}}}}),...s]),await t.waitTimers(Rs);let r=t.get(Ki),i=t.get(Qi),o=new Hi(n,{state:r,nodeViews:Object.fromEntries(t.get(Os)),markViews:Object.fromEntries(t.get(Ds)),transformPasted:(s,a,l)=>(t.get(Wr).sort((c,u)=>(u.priority??50)-(c.priority??50)).map(c=>c.run).forEach(c=>{s=c(s,a,l)}),s),...i});return WC(o.dom),t.set(oe,o),t.done(Gi),()=>{o?.destroy(),t.remove(Yi).remove(oe).remove(Qi).remove(Tc).remove(vc).remove(Rs).clearTimer(Gi)}});Gt(bg,{displayName:"EditorView"});var xg=class wg{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Ca,this.#o=new ud,this.#i=new Map,this.#a=new Map,this.#l=new ld(this.#s,this.#o),this.#d=()=>{let e=PC(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),n=[lg,hg,gg,fg,$C,kg,yg,bg,FC(this),e];this.#c(n,this.#a)},this.#c=(e,n)=>{e.forEach(r=>{let i=this.#l.produce(this.#t?r.meta:void 0),o=r(i);n.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#u=(e,n=!1)=>Promise.all([e].flat().map(async r=>{let i=this.#i.get(r)?.cleanup;return n?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof i=="function"?i():i})),this.#p=async()=>{await Promise.all([...this.#a.entries()].map(async([e,{cleanup:n}])=>typeof n=="function"?n():n)),this.#a.clear()},this.#f=e=>{this.#e=e,this.#n(e)},this.#h=e=>[...e.entries()].map(async([n,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(n,{ctx:i,handler:o,cleanup:s})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#r.push(e),this),this.removeConfig=e=>(this.#r=this.#r.filter(n=>n!==e),this),this.use=e=>{let n=[e].flat();return n.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(n,this.#i),this},this.remove=async e=>this.#e==="OnCreate"?(console.warn("[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code."),new Promise(n=>{setTimeout(()=>{n(this.remove(e))},50)})):(await this.#u([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#f("OnCreate"),this.#d(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#h(this.#a),this.#h(this.#i)].flat()),this.#f("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(n=>{setTimeout(()=>{n(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#f("OnDestroy"),await this.#u([...this.#i.keys()],e),await this.#p(),this.#f("Destroyed"),this),this.action=e=>e(this.#l),this.inspect=()=>this.#t?[...this.#a.values(),...this.#i.values()].map(({ctx:e})=>e?.inspector?.read()).filter(e=>!!e):(console.warn("[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first."),[])}static make(){return new wg}#t;#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f;#h;get ctx(){return this.#l}get status(){return this.#e}};var qC=t=>crypto.getRandomValues(new Uint8Array(t)),KC=(t,e,n)=>{let r=256-256%t.length;if(r===256){let o=t.length-1;return(s=e)=>{if(!s)return"";let a="";for(;;){let l=n(s),c=s;for(;c--;)if(a+=t[l[c]&o],a.length>=s)return a}}}let i=Math.ceil(1.6*256*e/r);return(o=e)=>{if(!o)return"";let s="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]<r&&(s+=t[a[l]%t.length],s.length>=o))return s}}},Sg=(t,e=21)=>KC(t,e|0,qC);var rz=Sg("abcedfghicklmn",10);function P(t,e){let n=ug(t),r=i=>async()=>{r.key=n,await i.wait(zr);let o=e(i);return i.get(G).create(n,o),r.run=s=>i.get(G).call(t,s),()=>{i.get(G).remove(n)}};return r}function fe(t){let e=n=>async()=>{await n.wait(Fe);let r=t(n);return n.update(Hr,i=>[...i,r]),e.inputRule=r,()=>{n.update(Hr,i=>i.filter(o=>o!==r))}};return e}function Cg(t){let e=n=>async()=>{await n.wait(Fe);let r=t(n);return n.update(Wr,i=>[...i,r]),e.pasteRule=r,()=>{n.update(Wr,i=>i.filter(o=>o!==r))}};return e}function UC(t,e){let n=r=>async()=>{let i=e(r);return r.update(Fr,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(Fr,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get(mt).marks[t];if(!i)throw ad(t);return i},n}function Bs(t,e){let n=r=>async()=>{let i=e(r);return r.update(Pr,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(Pr,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get(mt).nodes[t];if(!i)throw sd(t);return i},n}function Se(t){let e,n=r=>async()=>(await r.wait(Fe),e=t(r),r.update(gt,i=>[...i,e]),()=>{r.update(gt,i=>i.filter(o=>o!==e))});return n.plugin=()=>e,n.key=()=>e.spec.key,n}function JC(t){let e=n=>async()=>{await n.wait($r);let r=n.get(Xi),i=t(n),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function Je(t,e){let n=K(t,e),r=i=>(i.inject(n),()=>()=>{i.remove(n)});return r.key=n,r}function te(t,e){let n=Je(e,t),r=Bs(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>te(t,o(e)),i}function yt(t,e){let n=Je(e,t),r=UC(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>yt(t,o(e)),i}function ze(t,e){let n=Je(Object.fromEntries(Object.entries(e).map(([o,{shortcuts:s,priority:a}])=>[o,{shortcuts:s,priority:a}])),`${t}Keymap`),r=JC(o=>{let s=o.get(n.key),a=Object.entries(e).flatMap(([l,{command:c}])=>{let u=s[l],f=[u.shortcuts].flat(),d=u.priority;return f.map(p=>[p,{key:p,onRun:c,priority:d}])});return Object.fromEntries(a)}),i=[n,r];return i.ctx=n,i.shortcuts=r,i.key=n.key,i.keymap=r.keymap,i}var at=(t,e=()=>({}))=>Je(e,`${t}Attr`),rr=(t,e=()=>({}))=>Je(e,`${t}Attr`);function Ge(t,e,n){let r=Je(n??{},t),i=s=>async()=>{await s.wait(Jt);let a={plugin:e(s),options:s.get(r.key)};return s.update(Vr,l=>[...l,a]),()=>{s.update(Vr,l=>l.filter(c=>c!==a))}},o=[r,i];return o.id=t,o.plugin=i,o.options=r,o}function Mg(t){return e=>{let n=e.get(oe),r=e.get(mt),i=e.get(nr);if(!t)return i(n.state.doc);let o=n.state.doc.slice(t.from,t.to,!0),s=r.topNodeType.createAndFill(null,o.content);return s?i(s):(console.error("No document found"),"")}}function Eg(t,e=!1){return n=>{let r=n.get(oe),i=n.get(Ue)(t);if(!i)return;if(!e){let{state:l}=r;return r.dispatch(l.tr.replace(0,l.doc.content.size,new A(i.content,0,0)))}let o=n.get(mt),s=n.get(Ji)({schema:o,doc:i,plugins:n.get(gt)}),a=Tr.create(s);r.updateState(a)}}function Tg(t,e){return function(n,r){let{$from:i,$to:o,node:s}=n.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let a=i.node(-1);if(a.type!=t)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=t||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=E.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let y=i.depth-d;y>=i.depth-3;y--)f=E.from(i.node(y).copy(f));let p=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(E.from(t.createAndFill()));let h=i.before(i.depth-(d-1)),m=n.tr.replace(h,i.after(-p),new A(f,4-d,0)),g=-1;m.doc.nodesBetween(h,m.doc.content.size,(y,x)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=x+1)}),g>-1&&m.setSelection($.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let l=o.pos==i.end()?a.contentMatchAt(0).defaultType:null,c=n.tr.delete(i.pos,o.pos),u=l?[e?{type:t,attrs:e}:null,{type:l}]:void 0;return Vn(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function vg(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==t);return o?n?r.node(o.depth-1).type==t?GC(e,n,t,o):QC(e,n,o):!0:!1}}function GC(t,e,n,r){let i=t.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(i.step(new Te(o-1,s,o,s,new A(E.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new Ei(i.doc.resolve(r.$from.pos),i.doc.resolve(s),r.depth));let a=Mr(r);if(a==null)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(o,-1)-1);return Wn(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),e(i.scrollIntoView()),!0}function QC(t,e,n){let r=t.tr,i=n.parent;for(let p=n.end,h=n.endIndex-1,m=n.startIndex;h>m;h--)p-=i.child(h).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let a=n.startIndex==0,l=n.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(a?0:1),u+1,s.content.append(l?E.empty:E.from(i))))return!1;let f=o.pos,d=f+s.nodeSize;return r.step(new Te(f-(a?1:0),d+(l?1:0),f+1,d-1,new A((a?E.empty:E.from(i.copy(E.empty))).append(l?E.empty:E.from(i.copy(E.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function Ig(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==t);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let a=o.parent,l=a.child(s-1);if(l.type!=t)return!1;if(n){let c=l.lastChild&&l.lastChild.type==a.type,u=E.from(c?t.create():null),f=new A(E.from(t.create(null,E.from(a.type.create(null,u)))),c?3:1,0),d=o.start,p=o.end;n(e.tr.step(new Te(d-(c?3:1),p,d,p,f,1,!0)).scrollIntoView())}return!0}}function Ic(t){let e=new Map;if(!t||!t.type)throw new Error("mdast-util-definitions expected node");return dt(t,"definition",function(r){let i=Ag(r.identifier);i&&!e.get(i)&&e.set(i,r)}),n;function n(r){let i=Ag(r);return e.get(i)}}function Ag(t){return String(t||"").toUpperCase()}function Ls(){return function(t){let e=Ic(t);dt(t,function(n,r,i){if(n.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[On,r];if(n.type==="imageReference"||n.type==="linkReference"){let o=e(n.identifier);if(o&&i&&typeof r=="number")return i.children[r]=n.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:n.alt}:{type:"link",url:o.url,title:o.title,children:n.children},[On,r]}})}}function Ng(t,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){t.next(e.content);return}let n=[];e.content.forEach((r,i,o)=>{o!==e.childCount-1&&n.push(r)}),t.next(E.fromArray(n))}function M(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-commonmark",...e}}),t}var Ac=rr("emphasis");M(Ac,{displayName:"Attr<emphasis>",group:"Emphasis"});var qr=yt("emphasis",t=>({attrs:{marker:{default:t.get(Lr).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",t.get(Ac.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,n)=>{e.withMark(n,"emphasis",void 0,{marker:n.attrs.marker})}}}));M(qr.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});M(qr.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Nc=P("ToggleEmphasis",t=>()=>Ar(qr.type(t)));M(Nc,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var Rg=fe(t=>Ht(/(?:^|[^*])\*([^*]+)\*$/,qr.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:n+1}}));M(Rg,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var Og=fe(t=>Ht(/\b_(?![_\s])(.*?[^_\s])_\b/,qr.type(t),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:n+1}}));M(Og,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var Rc=ze("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:t=>{let e=t.get(G);return()=>e.call(Nc.key)}}});M(Rc.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});M(Rc.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var Oc=rr("strong");M(Oc,{displayName:"Attr<strong>",group:"Strong"});var Zi=yt("strong",t=>({attrs:{marker:{default:t.get(Lr).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:e=>e.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:e=>e==="bold"},{style:"font-weight=400",clearMark:e=>e.type.name=="strong"},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:e=>["strong",t.get(Oc.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,n)=>{e.withMark(n,"strong",void 0,{marker:n.attrs.marker})}}}));M(Zi.mark,{displayName:"MarkSchema<strong>",group:"Strong"});M(Zi.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var Dc=P("ToggleStrong",t=>()=>Ar(Zi.type(t)));M(Dc,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var Dg=fe(t=>Ht(/(?<![\w:/])(?:\*\*|__)([^*_]+?)(?:\*\*|__)(?![\w/])$/,Zi.type(t),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));M(Dg,{displayName:"InputRule<strong>",group:"Strong"});var Bc=ze("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:t=>{let e=t.get(G);return()=>e.call(Dc.key)}}});M(Bc.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});M(Bc.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var Lc=rr("inlineCode");M(Lc,{displayName:"Attr<inlineCode>",group:"InlineCode"});var bn=yt("inlineCode",t=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",t.get(Lc.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,n,r)=>{e.openMark(r),e.addText(n.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,n,r)=>(e.withMark(n,"inlineCode",r.text||""),!0)}}));M(bn.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});M(bn.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Pc=P("ToggleInlineCode",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,bn.type(t))?(n?.(i.removeMark(o,s,bn.type(t))),!0):(Object.keys(e.schema.marks).filter(a=>a!==bn.type.name).map(a=>e.schema.marks[a]).forEach(a=>{i.removeMark(o,s,a)}),n?.(i.addMark(o,s,bn.type(t).create())),!0)});M(Pc,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var Bg=fe(t=>Ht(/(?:`)([^`]+)(?:`)$/,bn.type(t)));M(Bg,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var Fc=ze("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:t=>{let e=t.get(G);return()=>e.call(Pc.key)}}});M(Fc.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});M(Fc.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var YC=new Set(["http:","https:","mailto:","tel:","ftp:"]);function XC(t){return t<=32||t>=127&&t<=160||t>=8203&&t<=8205||t===8232||t===8233||t===65279}function ZC(t){let e="";for(let n of t)XC(n.codePointAt(0)??0)||(e+=n);return e}function eM(t){if(typeof t!="string")return"";let e=t.trim();if(!e)return"";let n=ZC(e),r=/^([a-z][a-z0-9+.-]*):/i.exec(n)?.[1];return!r||YC.has(`${r.toLowerCase()}:`)?e:""}var zc=rr("link");M(zc,{displayName:"Attr<link>",group:"Link"});var jr=yt("link",t=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw tt(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...t.get(zc.key)(e),...e.attrs,href:eM(e.attrs.href)}],parseMarkdown:{match:e=>e.type==="link",runner:(e,n,r)=>{let i=n.url,o=n.title;e.openMark(r,{href:i,title:o}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,n)=>{e.withMark(n,"link",void 0,{title:n.attrs.title,url:n.attrs.href})}}}));M(jr.mark,{displayName:"MarkSchema<link>",group:"Link"});var Lg=P("ToggleLink",t=>(e={})=>Ar(jr.type(t),e));M(Lg,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Pg=P("UpdateLink",t=>(e={})=>(n,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=n,{from:a,to:l}=s;if(n.doc.nodesBetween(a,a===l?l+1:l,(h,m)=>{if(jr.type(t).isInSet(h.marks))return i=h,o=m,!1}),!i)return!1;let c=i.marks.find(({type:h})=>h===jr.type(t));if(!c)return!1;let u=o,f=o+i.nodeSize,{tr:d}=n,p=jr.type(t).create({...c.attrs,...e});return p?(r(d.removeMark(u,f,c).addMark(u,f,p).setSelection(new z(d.selection.$anchor)).scrollIntoView()),!0):!1});M(Pg,{displayName:"Command<updateLinkCommand>",group:"Link"});var Fg=Bs("doc",()=>({content:"block+",parseMarkdown:{match:({type:t})=>t==="root",runner:(t,e,n)=>{t.injectRoot(e,n)}},toMarkdown:{match:t=>t.type.name==="doc",runner:(t,e)=>{t.openNode("root"),t.next(e.content)}}}));M(Fg,{displayName:"NodeSchema<doc>",group:"Doc"});function tM(t){return Dn(t,e=>e.type==="html"&&["<br />","<br>","<br >","<br/>"].includes(e.value?.trim()),(e,n)=>{if(!n.length)return;let r=n[n.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var Fs=Ge("remark-preserve-empty-line",()=>()=>tM);M(Fs.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});M(Fs.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var $c=at("paragraph");M($c,{displayName:"Attr<paragraph>",group:"Paragraph"});var kt=te("paragraph",t=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",t.get($c.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,n,r)=>{e.openNode(r),n.children?e.next(n.children):e.addText(n.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,n)=>{let r=t.get(oe).state?.doc.lastChild;e.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&nM(t)?e.addNode("html",void 0,"<br />"):Ng(e,n),e.closeNode()}}}));function nM(t){let e=!1;try{t.get(Fs.id),e=!0}catch{e=!1}return e}M(kt.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});M(kt.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var _c=P("TurnIntoText",t=>()=>Ir(kt.type(t)));M(_c,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Hc=ze("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:t=>{let e=t.get(G);return()=>e.call(_c.key)}}});M(Hc.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});M(Hc.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var rM=Array(6).fill(0).map((t,e)=>e+1);function iM(t){return t.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var zs=Je(iM,"headingIdGenerator");M(zs,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Vc=at("heading");M(Vc,{displayName:"Attr<heading>",group:"Heading"});var or=te("heading",t=>{let e=t.get(zs.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:rM.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw tt(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...t.get(Vc.key)(n),id:n.attrs.id||e(n)},0],parseMarkdown:{match:({type:n})=>n==="heading",runner:(n,r,i)=>{let o=r.depth;n.openNode(i,{level:o}),n.next(r.children),n.closeNode()}},toMarkdown:{match:n=>n.type.name==="heading",runner:(n,r)=>{n.openNode("heading",void 0,{depth:r.attrs.level}),Ng(n,r),n.closeNode()}}}});M(or.node,{displayName:"NodeSchema<heading>",group:"Heading"});M(or.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var zg=fe(t=>Bl(/^(?<hashes>#+)\s$/,or.type(t),e=>{let n=e.groups?.hashes?.length||0,{$from:r}=t.get(oe).state.selection,i=r.node();if(i.type.name==="heading"){let o=Number(i.attrs.level)+Number(n);return o>6&&(o=6),{level:o}}return{level:n}}));M(zg,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var kn=P("WrapInHeading",t=>e=>(e??=1,e<1?Ir(kt.type(t)):Ir(or.type(t),{level:e})));M(kn,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Wc=P("DowngradeHeading",t=>()=>(e,n,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==or.type(t)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(n?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):Ir(kt.type(t))(e,n,r)});M(Wc,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var jc=ze("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:t=>{let e=t.get(G);return()=>e.call(kn.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:t=>{let e=t.get(G);return()=>e.call(kn.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:t=>{let e=t.get(G);return()=>e.call(kn.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:t=>{let e=t.get(G);return()=>e.call(kn.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:t=>{let e=t.get(G);return()=>e.call(kn.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:t=>{let e=t.get(G);return()=>e.call(kn.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:t=>{let e=t.get(G);return()=>e.call(Wc.key)}}});M(jc.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});M(jc.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var qc=at("blockquote");M(qc,{displayName:"Attr<blockquote>",group:"Blockquote"});var eo=te("blockquote",t=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",t.get(qc.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,n,r)=>{e.openNode(r).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,n)=>{e.openNode("blockquote").next(n.content).closeNode()}}}));M(eo.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});M(eo.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var $g=fe(t=>as(/^\s*>\s$/,eo.type(t)));M($g,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Kc=P("WrapInBlockquote",t=>()=>ss(eo.type(t)));M(Kc,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Uc=ze("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:t=>{let e=t.get(G);return()=>e.call(Kc.key)}}});M(Uc.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});M(Uc.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var Jc=at("codeBlock",()=>({pre:{},code:{}}));M(Jc,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var to=te("code_block",t=>({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 tt(e);return{language:e.dataset.language}}}],toDOM:e=>{let n=t.get(Jc.key)(e),r=e.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,n,r)=>{let i=n.lang??"",o=n.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,n)=>{e.addNode("code",void 0,n.content.firstChild?.text||"",{lang:n.attrs.language})}}}));M(to.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});M(to.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var _g=fe(t=>Bl(/^```(?<language>[a-z]*)?[\s\n]$/,to.type(t),e=>({language:e.groups?.language??""})));M(_g,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Gc=P("CreateCodeBlock",t=>(e="")=>Ir(to.type(t),{language:e}));M(Gc,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var oM=P("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(n,r)=>t>=0?(r?.(n.tr.setNodeAttribute(t,"language",e)),!0):!1);M(oM,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Qc=ze("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:t=>{let e=t.get(G);return()=>e.call(Gc.key)}}});M(Qc.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});M(Qc.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Yc=at("image");M(Yc,{displayName:"Attr<image>",group:"Image"});var Kr=te("image",t=>({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 tt(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...t.get(Yc.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,n,r)=>{let i=n.url,o=n.alt,s=n.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,n)=>{e.addNode("image",void 0,void 0,{title:n.attrs.title,url:n.attrs.src,alt:n.attrs.alt})}}}));M(Kr.node,{displayName:"NodeSchema<image>",group:"Image"});M(Kr.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var Hg=P("InsertImage",t=>(e={})=>(n,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,a=Kr.type(t).create({src:i,alt:o,title:s});return a&&r(n.tr.replaceSelectionWith(a).scrollIntoView()),!0});M(Hg,{displayName:"Command<insertImageCommand>",group:"Image"});var Vg=P("UpdateImage",t=>(e={})=>(n,r)=>{let i=_h(n.selection,Kr.type(t));if(!i)return!1;let{node:o,pos:s}=i,a={...o.attrs},{src:l,alt:c,title:u}=e;return l!==void 0&&(a.src=l),c!==void 0&&(a.alt=c),u!==void 0&&(a.title=u),r?.(n.tr.setNodeMarkup(s,void 0,a).scrollIntoView()),!0});M(Vg,{displayName:"Command<updateImageCommand>",group:"Image"});var sM=fe(t=>new ke(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,n,r,i)=>{let[o,s,a="",l]=n;return o?e.tr.replaceWith(r,i,Kr.type(t).create({src:a,alt:s,title:l})):null}));M(sM,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Ps=at("hardbreak",t=>({"data-type":"hardbreak","data-is-inline":t.attrs.isInline}));M(Ps,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var ir=te("hardbreak",t=>({inline:!0,group:"inline",attrs:{isInline:{default:!1,validate:"boolean"}},selectable:!1,parseDOM:[{tag:"br"},{tag:'span[data-type="hardbreak"]',getAttrs:()=>({isInline:!0})}],toDOM:e=>e.attrs.isInline?["span",t.get(Ps.key)(e)," "]:["br",t.get(Ps.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,n,r)=>{e.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>` +`);return{dom:l,text:d,slice:e}}function jm(t,e,n,r,i){let o=i.parent.type.spec.code,s,a;if(!n&&!e)return null;let l=!!e&&(r||o||!n);if(l){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return a=new A(E.from(t.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0),t.someProp("transformPasted",d=>{a=d(a,t,!0)}),a;let f=t.someProp("clipboardTextParser",d=>d(e,i,r,t));if(f)a=f;else{let d=i.marks(),{schema:p}=t.state,h=cn.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,d)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),s=Y0(n),Wi&&X0(s);let c=s&&s.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||ln.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!J0.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)a=Z0(ym(a,+u[1],+u[2]),u[4]);else if(a=A.maxOpen(G0(a.content,i),!0),a.openStart||a.openEnd){let f=0,d=0;for(let p=a.content.firstChild;f<a.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=a.content.lastChild;d<a.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);a=ym(a,f,d)}return t.someProp("transformPasted",f=>{a=f(a,t,l)}),a}var J0=/^(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 G0(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),o,s=[];if(t.forEach(a=>{if(!s)return;let l=i.findWrapping(a.type),c;if(!l)return s=null;if(c=s.length&&o.length&&Km(l,o,a,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Um(s[s.length-1],o.length));let u=qm(a,l);s.push(u),i=i.matchType(u.type),o=l}}),s)return E.from(s)}return t}function qm(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,E.from(t));return t}function Km(t,e,n,r,i){if(i<t.length&&i<e.length&&t[i]==e[i]){let o=Km(t,e,n,r.lastChild,i+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(i==t.length-1?n.type:t[i+1]))return r.copy(r.content.append(E.from(qm(n,t,i+1))))}}function Um(t,e){if(e==0)return t;let n=t.content.replaceChild(t.childCount-1,Um(t.lastChild,e-1)),r=t.contentMatchAt(t.childCount).fillBefore(E.empty,!0);return t.copy(n.append(r))}function sc(t,e,n,r,i,o){let s=e<0?t.firstChild:t.lastChild,a=s.content;return t.childCount>1&&(o=0),i<r-1&&(a=sc(a,e,n,r,i+1,o)),i>=n&&(a=e<0?s.contentMatchAt(0).fillBefore(a,o<=i).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(E.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(a))}function ym(t,e,n){return e<t.openStart&&(t=new A(sc(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),n<t.openEnd&&(t=new A(sc(t.content,1,n,t.openEnd,0,0),t.openStart,n)),t}var Jm={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function Gm(){return document.implementation.createHTMLDocument("title")}var ql=null;function Q0(t){let e=window.trustedTypes;return e?(ql||(ql=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:n=>n})),ql.createHTML(t)):t}function Y0(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Gm(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(t),o;if((o=i&&Jm[i[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"</"+s+">").reverse().join("")),r.innerHTML=Q0(t),o)for(let s=0;s<o.length;s++)r=r.querySelector(o[s])||r;for(let s=0;s<n.styleSheets.length;s++){let a=n.styleSheets[s];for(let l=0;l<a.rules.length;l++){let c=a.rules[l];if(c instanceof CSSStyleRule){let u=r.querySelectorAll(c.selectorText);for(let f=0;f<u.length;f++)u[f].style.cssText+=c.style.cssText}}}return r}function X0(t){let e=t.querySelectorAll(we?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<e.length;n++){let r=e[n];r.childNodes.length==1&&r.textContent=="\xA0"&&r.parentNode&&r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),r)}}function Z0(t,e){if(!t.size)return t;let n=t.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return t}let{content:i,openStart:o,openEnd:s}=t;for(let a=r.length-2;a>=0;a-=2){let l=n.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;i=E.from(l.create(r[a+1],i)),o++,s++}return new A(i,o,s)}var Le={},Pe={},eC={touchstart:!0,touchmove:!0},ac=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 tC(t){for(let e in Le){let n=Le[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{rC(t,r)&&!kc(t,r)&&(t.editable||!(r.type in Pe))&&n(t,r)},eC[e]?{passive:!0}:void 0)}De&&t.dom.addEventListener("input",()=>null),lc(t)}function Kt(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function nC(t){t.input.mouseDown&&t.input.mouseDown.done(),t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function lc(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>kc(t,r))})}function kc(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function rC(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function iC(t,e){!kc(t,e)&&Le[e.type]&&(t.editable||!(e.type in Pe))&&Le[e.type](t,e)}Pe.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!Xm(t)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(qt&&we&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),Br&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,Kn(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||U0(t,n)?n.preventDefault():Kt(t,"key")};Pe.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Pe.keypress=(t,e)=>{let n=e;if(Xm(t)||!n.charCode||n.ctrlKey&&!n.altKey||rt&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof z)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode),o=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",s=>s(t,r.$from.pos,r.$to.pos,i,o))&&t.dispatch(o()),n.preventDefault()}};function ji(t){return{left:t.clientX,top:t.clientY}}function oC(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function bc(t,e,n,r,i){if(r==-1)return!1;let o=t.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,a=>s>o.depth?a(t,n,o.nodeAfter,o.before(s),i,!0):a(t,n,o.node(s),o.before(s),i,!1)))return!0;return!1}function qi(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function sC(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&H.isSelectable(r)?(qi(t,new H(n),"pointer"),!0):!1}function aC(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof H&&(r=n.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let a=s>o.depth?o.nodeAfter:o.node(s);if(H.isSelectable(a)){r&&n.$from.depth>0&&s>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?i=o.before(n.$from.depth):i=o.before(s);break}}return i!=null?(qi(t,H.create(t.state.doc,i),"pointer"),!0):!1}function lC(t,e,n,r,i){return bc(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?aC(t,n):sC(t,n))}function cC(t,e,n,r){return bc(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function uC(t,e,n,r){return bc(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||fC(t,n,r)}function fC(t,e,n){if(n.button!=0)return!1;let r=Qm(t,e,!0),i=t.state.doc;return r?(qi(t,r,"pointer"),r instanceof z&&i.eq(t.state.doc)&&(t.input.mouseDown=new uc(t,r)),!0):!1}function Qm(t,e,n){let r=t.state.doc;if(e==-1)return r.inlineContent?z.create(r,0,r.content.size):null;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),a=i.before(o);if(s.inlineContent)return z.create(r,a+1,a+1+s.content.size);if(n&&H.isSelectable(s))return H.create(r,a)}return null}function xc(t){return ys(t)}var Ym=rt?"metaKey":"ctrlKey";Le.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=xc(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&oC(n,t.input.lastClick)&&!n[Ym]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o,button:n.button},t.input.mouseDown&&t.input.mouseDown.done();let s=t.posAtCoords(ji(n));s&&(o=="singleClick"?t.input.mouseDown=new cc(t,s,n,!!r):(o=="doubleClick"?cC:uC)(t,s.pos,s.inside,n)?n.preventDefault():Kt(t,"pointer"))};var gs=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},cc=class extends gs{constructor(e,n,r,i){super(e),this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!r[Ym],this.allowDefault=r.shiftKey;let o,s;if(n.inside>-1)o=e.state.doc.nodeAt(n.inside),s=n.inside;else{let u=e.state.doc.resolve(n.pos);o=u.parent,s=u.depth?u.before():0}let a=i?null:r.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:c}=e.state;r.button==0&&(o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof H&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ot&&!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()),Kt(e,"pointer")}done(){super.done(),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(()=>{this.view.isDestroyed||Ut(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(ji(e))),this.updateAllowDefault(e),this.allowDefault||!n?Kt(this.view,"pointer"):lC(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||De&&this.mightDrag&&!this.mightDrag.node.isAtom||we&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(qi(this.view,$.near(this.view.state.doc.resolve(n.pos)),"pointer"),e.preventDefault()):Kt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Kt(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},uc=class extends gs{constructor(e,n){super(e),this.startSelection=n,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),Kt(this.view,"pointer");let n=this.view.posAtCoords(ji(e)),r=n&&Qm(this.view,n.inside,!1);if(!r)return;let{doc:i}=this.view.state,o=this.startSelection,[s,a]=r.from<o.from?[o.to,r.from]:[o.from,r.to];qi(this.view,z.create(i,s,a),"pointer")}};Le.touchstart=t=>{t.input.lastTouch=Date.now(),xc(t),Kt(t,"pointer")};Le.touchmove=t=>{t.input.lastTouch=Date.now(),Kt(t,"pointer")};Le.contextmenu=t=>xc(t);function Xm(t,e){return t.composing?!0:De&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var dC=qt?5e3:-1;Pe.compositionstart=Pe.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof z&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||we&&Nm&&pC(t)))t.markCursor=t.state.storedMarks||n.marks(),ys(t,!0),t.markCursor=null;else if(ys(t,!e.selection.empty),ot&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let a=t.domSelection();a&&a.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}t.input.composing=!0}Zm(t,dC)};function pC(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}Pe.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now(),t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,Zm(t,20))};function Zm(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>ys(t),e))}function eg(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function hC(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=f0(e.focusNode,e.focusOffset),r=d0(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,o=t.domObserver.lastChangedTextNode;if(n==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let s=n.pmViewDesc;if(!(!s||!s.isText(n.nodeValue)))return r}}return n||r}function ys(t,e=!1){if(!(qt&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),eg(t),e||t.docView&&t.docView.dirty){let n=mc(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function mC(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}var zi=Ve&&mn<15||Br&&g0<604;Le.copy=Pe.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=zi?null:n.clipboardData,s=r.content(),{dom:a,text:l}=yc(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):mC(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function gC(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function yC(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.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=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?$i(t,r.value,null,i,e):$i(t,r.textContent,r.innerHTML,i,e)},50)}function $i(t,e,n,r,i){let o=jm(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,i,o||A.empty)))return!0;if(!o)return!1;let s=gC(o),a=s?t.state.tr.replaceSelectionWith(s,r):t.state.tr.replaceSelection(o);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function tg(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Pe.paste=(t,e)=>{let n=e;if(t.composing&&!qt)return;let r=zi?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&$i(t,tg(r),r.getData("text/html"),i,n)?n.preventDefault():yC(t,n)};var ks=class{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}},kC=rt?"altKey":"ctrlKey";function ng(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[kC]}Le.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,o=i.empty?null:t.posAtCoords(ji(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof H?i.to-1:i.to))){if(r&&r.mightDrag)s=H.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(s=H.create(t.state.doc,f.posBefore))}}let a=(s||t.state.selection).content(),{dom:l,text:c,slice:u}=yc(t,a);(!n.dataTransfer.files.length||!we||Am>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(zi?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",zi||n.dataTransfer.setData("text/plain",c),t.dragging=new ks(u,ng(t,n),s)};Le.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Pe.dragover=Pe.dragenter=(t,e)=>e.preventDefault();Pe.drop=(t,e)=>{try{bC(t,e,t.dragging)}finally{t.dragging=null}};function bC(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(ji(e));if(!r)return;let i=t.state.doc.resolve(r.pos),o=n&&n.slice;o?t.someProp("transformPasted",p=>{o=p(o,t,!1)}):o=jm(t,tg(e.dataTransfer),zi?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(n&&ng(t,e));if(t.someProp("handleDrop",p=>p(t,e,o||A.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let a=o?hh(t.state.doc,i.pos,o):i.pos;a==null&&(a=i.pos);let l=t.state.tr;if(s){let{node:p}=n;p?p.replace(l):l.deleteSelection()}let c=l.mapping.map(a),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=l.doc;if(u?l.replaceRangeWith(c,c,o.content.firstChild):l.replaceRange(c,c,o),l.doc.eq(f))return;let d=l.doc.resolve(c);if(u&&H.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))l.setSelection(new H(d));else{let p=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((h,m,g,y)=>p=y),l.setSelection(gc(t,d,l.doc.resolve(p)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}Le.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Ut(t)},20))};Le.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Le.beforeinput=(t,e)=>{if(we&&qt&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,Kn(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Pe)Le[t]=Pe[t];function _i(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}var bs=class t{constructor(e,n){this.toDOM=e,this.spec=n||Yn,this.side=this.spec.side||0}map(e,n,r,i){let{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new oe(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof t&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&_i(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Qn=class t{constructor(e,n){this.attrs=e,this.spec=n||Yn}map(e,n,r,i){let o=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new oe(o,s,this)}valid(e,n){return n.from<n.to}eq(e){return this==e||e instanceof t&&_i(this.attrs,e.attrs)&&_i(this.spec,e.spec)}static is(e){return e.type instanceof t}destroy(){}},fc=class t{constructor(e,n){this.attrs=e,this.spec=n||Yn}map(e,n,r,i){let o=e.mapResult(n.from+i,1);if(o.deleted)return null;let s=e.mapResult(n.to+i,-1);return s.deleted||s.pos<=o.pos?null:new oe(o.pos-r,s.pos-r,this)}valid(e,n){let{index:r,offset:i}=e.content.findIndex(n.from),o;return i==n.from&&!(o=e.child(r)).isText&&i+o.nodeSize==n.to}eq(e){return this==e||e instanceof t&&_i(this.attrs,e.attrs)&&_i(this.spec,e.spec)}destroy(){}},oe=class t{constructor(e,n,r){this.from=e,this.to=n,this.type=r}copy(e,n){return new t(e,n,this.type)}eq(e,n=0){return this.type.eq(e.type)&&this.from+n==e.from&&this.to+n==e.to}map(e,n,r){return this.type.map(e,this,n,r)}static widget(e,n,r){return new t(e,e,new bs(n,r))}static inline(e,n,r,i){return new t(e,n,new Qn(r,i))}static node(e,n,r,i){return new t(e,n,new fc(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Qn}get widget(){return this.type instanceof bs}},Or=[],Yn={},ee=class t{constructor(e,n){this.local=e.length?e:Or,this.children=n.length?n:Or}static create(e,n){return n.length?ws(n,e,0,Yn):Oe}find(e,n,r){let i=[];return this.findInner(e??0,n??1e9,i,0,r),i}findInner(e,n,r,i,o){for(let s=0;s<this.local.length;s++){let a=this.local[s];a.from<=n&&a.to>=e&&(!o||o(a.spec))&&r.push(a.copy(a.from+i,a.to+i))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<n&&this.children[s+1]>e){let a=this.children[s]+1;this.children[s+2].findInner(e-a,n-a,r,i+a,o)}}map(e,n,r){return this==Oe||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Yn)}mapInner(e,n,r,i,o){let s;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,r,i);l&&l.type.valid(n,l)?(s||(s=[])).push(l):o.onRemove&&o.onRemove(this.local[a].spec)}return this.children.length?xC(this.children,s||[],e,n,r,i,o):s?new t(s.sort(Xn),Or):Oe}add(e,n){return n.length?this==Oe?t.create(e,n):this.addInner(e,n,0):this}addInner(e,n,r){let i,o=0;e.forEach((a,l)=>{let c=l+r,u;if(u=ig(n,a,c)){for(i||(i=this.children.slice());o<i.length&&i[o]<l;)o+=3;i[o]==l?i[o+2]=i[o+2].addInner(a,u,c+1):i.splice(o,0,l,l+a.nodeSize,ws(u,a,c+1,Yn)),o+=3}});let s=rg(o?og(n):n,-r);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||s.splice(a--,1);return new t(s.length?this.local.concat(s).sort(Xn):this.local,i||this.children)}remove(e){return e.length==0||this==Oe?this:this.removeInner(e,0)}removeInner(e,n){let r=this.children,i=this.local;for(let o=0;o<r.length;o+=3){let s,a=r[o]+n,l=r[o+1]+n;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>a&&f.to<l&&(e[u]=null,(s||(s=[])).push(f));if(!s)continue;r==this.children&&(r=this.children.slice());let c=r[o+2].removeInner(s,a+1);c!=Oe?r[o+2]=c:(r.splice(o,3),o-=3)}if(i.length){for(let o=0,s;o<e.length;o++)if(s=e[o])for(let a=0;a<i.length;a++)i[a].eq(s,n)&&(i==this.local&&(i=this.local.slice()),i.splice(a--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new t(i,r):Oe}forChild(e,n){if(this==Oe)return this;if(n.isLeaf)return t.empty;let r,i;for(let a=0;a<this.children.length;a+=3)if(this.children[a]>=e){this.children[a]==e&&(r=this.children[a+2]);break}let o=e+1,s=o+n.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<s&&l.to>o&&l.type instanceof Qn){let c=Math.max(o,l.from)-o,u=Math.min(s,l.to)-o;c<u&&(i||(i=[])).push(l.copy(c,u))}}if(i){let a=new t(i.sort(Xn),Or);return r?new xs([a,r]):a}return r||Oe}eq(e){if(this==e)return!0;if(!(e instanceof t)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let n=0;n<this.local.length;n++)if(!this.local[n].eq(e.local[n]))return!1;for(let n=0;n<this.children.length;n+=3)if(this.children[n]!=e.children[n]||this.children[n+1]!=e.children[n+1]||!this.children[n+2].eq(e.children[n+2]))return!1;return!0}locals(e){return wc(this.localsInner(e))}localsInner(e){if(this==Oe)return Or;if(e.inlineContent||!this.local.some(Qn.is))return this.local;let n=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Qn||n.push(this.local[r]);return n}forEachSet(e){e(this)}};ee.empty=new ee([],[]);ee.removeOverlap=wc;var Oe=ee.empty,xs=class t{constructor(e){this.members=e}map(e,n){let r=this.members.map(i=>i.map(e,n,Yn));return t.from(r)}forChild(e,n){if(n.isLeaf)return ee.empty;let r=[];for(let i=0;i<this.members.length;i++){let o=this.members[i].forChild(e,n);o!=Oe&&(o instanceof t?r=r.concat(o.members):r.push(o))}return t.from(r)}eq(e){if(!(e instanceof t)||e.members.length!=this.members.length)return!1;for(let n=0;n<this.members.length;n++)if(!this.members[n].eq(e.members[n]))return!1;return!0}locals(e){let n,r=!0;for(let i=0;i<this.members.length;i++){let o=this.members[i].localsInner(e);if(o.length)if(!n)n=o;else{r&&(n=n.slice(),r=!1);for(let s=0;s<o.length;s++)n.push(o[s])}}return n?wc(r?n:n.sort(Xn)):Or}static from(e){switch(e.length){case 0:return Oe;case 1:return e[0];default:return new t(e.every(n=>n instanceof ee)?e:e.reduce((n,r)=>n.concat(r instanceof ee?r:r.members),[]))}}forEachSet(e){for(let n=0;n<this.members.length;n++)this.members[n].forEachSet(e)}};function xC(t,e,n,r,i,o,s){let a=t.slice();for(let c=0,u=o;c<n.maps.length;c++){let f=0;n.maps[c].forEach((d,p,h,m)=>{let g=m-h-(p-d);for(let y=0;y<a.length;y+=3){let x=a[y+1];if(x<0||d>x+u-f)continue;let C=a[y]+u-f;p>=C?a[y+1]=d<=C?-2:-1:d>=u&&g&&(a[y]+=g,a[y+1]+=g)}f+=g}),u=n.maps[c].map(u,-1)}let l=!1;for(let c=0;c<a.length;c+=3)if(a[c+1]<0){if(a[c+1]==-2){l=!0,a[c+1]=-1;continue}let u=n.map(t[c]+o),f=u-i;if(f<0||f>=r.content.size){l=!0;continue}let d=n.map(t[c+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),g=r.maybeChild(h);if(g&&m==f&&m+g.nodeSize==p){let y=a[c+2].mapInner(n,g,u+1,t[c]+o+1,s);y!=Oe?(a[c]=f,a[c+1]=p,a[c+2]=y):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=wC(a,t,e,n,i,o,s),u=ws(c,r,0,s);e=u.local;for(let f=0;f<a.length;f+=3)a[f+1]<0&&(a.splice(f,3),f-=3);for(let f=0,d=0;f<u.children.length;f+=3){let p=u.children[f];for(;d<a.length&&a[d]<p;)d+=3;a.splice(d,0,u.children[f],u.children[f+1],u.children[f+2])}}return new ee(e.sort(Xn),a)}function rg(t,e){if(!e||!t.length)return t;let n=[];for(let r=0;r<t.length;r++){let i=t[r];n.push(new oe(i.from+e,i.to+e,i.type))}return n}function wC(t,e,n,r,i,o,s){function a(l,c){for(let u=0;u<l.local.length;u++){let f=l.local[u].map(r,i,c);f?n.push(f):s.onRemove&&s.onRemove(l.local[u].spec)}for(let u=0;u<l.children.length;u+=3)a(l.children[u+2],l.children[u]+c+1)}for(let l=0;l<t.length;l+=3)t[l+1]==-1&&a(t[l+2],e[l]+o+1);return n}function ig(t,e,n){if(e.isLeaf)return null;let r=n+e.nodeSize,i=null;for(let o=0,s;o<t.length;o++)(s=t[o])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),t[o]=null);return i}function og(t){let e=[];for(let n=0;n<t.length;n++)t[n]!=null&&e.push(t[n]);return e}function ws(t,e,n,r){let i=[],o=!1;e.forEach((a,l)=>{let c=ig(t,a,l+n);if(c){o=!0;let u=ws(c,a,n+l+1,r);u!=Oe&&i.push(l,l+a.nodeSize,u)}});let s=rg(o?og(t):t,-n).sort(Xn);for(let a=0;a<s.length;a++)s[a].type.valid(e,s[a])||(r.onRemove&&r.onRemove(s[a].spec),s.splice(a--,1));return s.length||i.length?new ee(s,i):Oe}function Xn(t,e){return t.from-e.from||t.to-e.to}function wc(t){let e=t;for(let n=0;n<e.length-1;n++){let r=e[n];if(r.from!=r.to)for(let i=n+1;i<e.length;i++){let o=e[i];if(o.from==r.from){o.to!=r.to&&(e==t&&(e=t.slice()),e[i]=o.copy(o.from,r.to),km(e,i+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(e==t&&(e=t.slice()),e[n]=r.copy(r.from,o.from),km(e,i,r.copy(o.from,r.to)));break}}}return e}function km(t,e,n){for(;e<t.length&&Xn(n,t[e])>0;)e++;t.splice(e,0,n)}function Kl(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=Oe&&e.push(r)}),t.cursorWrapper&&e.push(ee.create(t.state.doc,[t.cursorWrapper.deco])),xs.from(e)}var SC={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},CC=Ve&&mn<=11,dc=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}},pc=class{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new dc,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;i<r.length;i++)this.queue.push(r[i]);Ve&&mn<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():De&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),CC&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,SC)),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 n=0;n<e.length;n++)this.queue.push(e[n]);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(fm(this.view)){if(this.suppressingSelectionUpdates)return Ut(this.view);if(Ve&&mn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Zn(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 n=new Set,r;for(let o=e.focusNode;o;o=Dr(o))n.add(o);for(let o=e.anchorNode;o;o=Dr(o))if(n.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&fm(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,a=!1,l=[];if(e.editable)for(let u=0;u<n.length;u++){let f=this.registerMutation(n[u],l);f&&(o=o<0?f.from:Math.min(f.from,o),s=s<0?f.to:Math.max(f.to,s),f.typeOver&&(a=!0))}if(l.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||we&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&n.some(u=>u.type=="childList"&&u.removedNodes.length))){for(let u of l)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;for(;f&&f.nodeType==1;){if(f.contentEditable=="false"){u.parentNode.removeChild(u);break}f=f.firstChild}}}else if(ot&&l.length){let u=l.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,d]=u;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of u){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||TC(e,f)!=p)&&d.remove()}}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ss(r)&&(c=mc(e))&&c.eq($.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Ut(e),this.currentSelection.set(r),e.scrollToSelection()):(o>-1||i)&&(o>-1&&(e.docView.markDirty(o,s),MC(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,vC(e,l)),this.handleDOMChange(o,s,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Ut(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];n.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let i=e.previousSibling,o=e.nextSibling;if(Ve&&mn<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:d}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(o=d)}let s=i&&i.parentNode==e.target?ve(i)+1:0,a=r.localPosFromDOM(e.target,s,-1),l=o&&o.parentNode==e.target?ve(o):e.target.childNodes.length,c=r.localPosFromDOM(e.target,l,1);return{from:a,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},bm=new WeakMap,xm=!1;function MC(t){if(!bm.has(t)&&(bm.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=ot,xm)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."),xm=!0}}function wm(t,e){let n=e.startContainer,r=e.startOffset,i=e.endContainer,o=e.endOffset,s=t.domAtPos(t.state.selection.anchor);return Zn(s.node,s.offset,i,o)&&([n,r,i,o]=[i,o,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:o}}function EC(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return wm(t,i)}let n;function r(i){i.preventDefault(),i.stopImmediatePropagation(),n=i.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",r,!0),n?wm(t,n):null}function TC(t,e){for(let n=e.parentNode;n&&n!=t.dom;n=n.parentNode){let r=t.docView.nearestDesc(n,!0);if(r&&r.node.isBlock)return n}return null}function vC(t,e){var n;let{focusNode:r,focusOffset:i}=t.domSelectionRange();for(let o of e)if(((n=o.parentNode)===null||n===void 0?void 0:n.nodeName)=="TR"){let s=o.nextSibling;for(;s&&s.nodeName!="TD"&&s.nodeName!="TH";)s=s.nextSibling;if(s){let a=s;for(;;){let l=a.firstChild;if(!l||l.nodeType!=1||l.contentEditable=="false"||/^(BR|IMG)$/.test(l.nodeName))break;a=l}a.insertBefore(o,a.firstChild),r==o&&t.domSelection().collapse(o,i)}else o.parentNode.removeChild(o)}}function IC(t,e,n){let{node:r,fromOffset:i,toOffset:o,from:s,to:a}=t.docView.parseRange(e,n),l=t.domSelectionRange(),c,u=l.anchorNode;if(u&&t.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:l.anchorOffset}],Ss(l)||c.push({node:l.focusNode,offset:l.focusOffset})),we&&t.input.lastKeyCode===8)for(let g=o;g>i;g--){let y=r.childNodes[g-1],x=y.pmViewDesc;if(y.nodeName=="BR"&&!x){o=g;break}if(!x||x.size)break}let f=t.state.doc,d=t.someProp("domParser")||ln.fromSchema(t.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:AC,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),h={anchor:g+s,head:y+s}}return{doc:m,sel:h,from:s,to:a}}function AC(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(De&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||De&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}var NC=/^(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 RC(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let N=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,D=mc(t,N);if(D&&!t.state.selection.eq(D)){if(we&&qt&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",S=>S(t,Kn(13,"Enter"))))return;let B=t.state.tr.setSelection(D);N=="pointer"?B.setMeta("pointer",!0):N=="key"&&B.scrollIntoView(),o&&B.setMeta("composition",o),t.dispatch(B)}return}let s=t.state.doc.resolve(e),a=s.sharedDepth(n);e=s.before(a+1),n=t.state.doc.resolve(n).after(a+1);let l=t.state.selection,c=IC(t,e,n),u=t.state.doc,f=u.slice(c.from,c.to),d,p;t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime?(d=t.state.selection.to,p="end"):(d=t.state.selection.from,p="start"),t.input.lastKeyCode=null;let h=BC(f.content,c.doc.content,c.from,d,p);if(h&&t.input.domChangeCount++,(Br&&t.input.lastIOSEnter>Date.now()-225||qt)&&i.some(N=>N.nodeType==1&&!NC.test(N.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",N=>N(t,Kn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&l instanceof z&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let N=Sm(t,t.state.doc,c.sel);if(N&&!N.eq(t.state.selection)){let D=t.state.tr.setSelection(N);o&&D.setMeta("composition",o),t.dispatch(D)}}return}t.state.selection.from<t.state.selection.to&&h.start==h.endB&&t.state.selection instanceof z&&(h.start>t.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=c.from?h.start=t.state.selection.from:h.endA<t.state.selection.to&&h.endA>=t.state.selection.to-2&&t.state.selection.to<=c.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),Ve&&mn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>c.from&&c.doc.textBetween(h.start-c.from-1,h.start-c.from+1)==" \xA0"&&(h.start--,h.endA--,h.endB--);let m=c.doc.resolveNoCache(h.start-c.from),g=c.doc.resolveNoCache(h.endB-c.from),y=u.resolve(h.start),x=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=h.endA;if((Br&&t.input.lastIOSEnter>Date.now()-225&&(!x||i.some(N=>N.nodeName=="DIV"||N.nodeName=="P"))||!x&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(c.doc.textBetween(m.pos,g.pos,"","")))&&t.someProp("handleKeyDown",N=>N(t,Kn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&DC(u,h.start,h.endA,m,g)&&t.someProp("handleKeyDown",N=>N(t,Kn(8,"Backspace")))){qt&&we&&t.domObserver.suppressSelectionUpdates();return}we&&h.endB==h.start&&(t.input.lastChromeDelete=Date.now()),qt&&!x&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==h.endA&&(h.endB-=2,g=c.doc.resolveNoCache(h.endB-c.from),setTimeout(()=>{t.someProp("handleKeyDown",function(N){return N(t,Kn(13,"Enter"))})},20));let C=h.start,v=h.endA,I=N=>{let D=N||t.state.tr.replace(C,v,c.doc.slice(h.start-c.from,h.endB-c.from));if(c.sel){let B=Sm(t,D.doc,c.sel);B&&!(we&&t.composing&&B.empty&&(h.start!=h.endB||t.input.lastChromeDelete<Date.now()-100)&&(B.head==C||B.head==D.mapping.map(v)-1)||Ve&&B.empty&&B.head==C)&&D.setSelection(B)}return o&&D.setMeta("composition",o),D.scrollIntoView()},w;if(x)if(m.pos==g.pos){Ve&&mn<=11&&m.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>Ut(t),20));let N=I(t.state.tr.delete(C,v)),D=u.resolve(h.start).marksAcross(u.resolve(h.endA));D&&N.ensureMarks(D),t.dispatch(N)}else if(h.endA==h.endB&&(w=OC(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,h.endA-y.start())))){let N=I(t.state.tr);w.type=="add"?N.addMark(C,v,w.mark):N.removeMark(C,v,w.mark),t.dispatch(N)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let N=m.parent.textBetween(m.parentOffset,g.parentOffset),D=()=>I(t.state.tr.insertText(N,C,v));t.someProp("handleTextInput",B=>B(t,C,v,N,D))||t.dispatch(D())}else t.dispatch(I());else t.dispatch(I())}function Sm(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:gc(t,e.resolve(n.anchor),e.resolve(n.head))}function OC(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,a,l;for(let u=0;u<r.length;u++)i=r[u].removeFromSet(i);for(let u=0;u<n.length;u++)o=n[u].removeFromSet(o);if(i.length==1&&o.length==0)a=i[0],s="add",l=u=>u.mark(a.addToSet(u.marks));else if(i.length==0&&o.length==1)a=o[0],s="remove",l=u=>u.mark(a.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(l(e.child(u)));if(E.from(c).eq(t))return{mark:a,type:s}}function DC(t,e,n,r,i){if(n-e<=i.pos-r.pos||Ul(r,!0,!1)<i.pos)return!1;let o=t.resolve(e);if(!r.parent.isTextblock){let a=o.nodeAfter;return a!=null&&n==e+a.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=t.resolve(Ul(o,!0,!0));return!s.parent.isTextblock||s.pos>n||Ul(s,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(s.parent.content)}function Ul(t,e,n){let r=t.depth,i=e?t.end():t.pos;for(;r>0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let o=t.node(r).maybeChild(t.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function BC(t,e,n,r,i){let o=t.findDiffStart(e,n),s=n+t.size,a=n+e.size;if(o==null)return null;let{a:l,b:c}=t.findDiffEnd(e,s,a);if(i=="end"){let u=Math.max(0,o-Math.min(l,c));r-=l+u-o}if(l<o&&s<a){let u=r<=o&&r>=l?o-r:0;o-=u,c=o+(c-l),l=o}else if(c<o){let u=r<=o&&r>=c?o-r:0;o-=u,l=o+(l-c),c=o}return{start:o,endA:l,endB:c}}var Hi=class{constructor(e,n){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 ac,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(vm),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=Em(this),Mm(this),this.nodeViews=Tm(this),this.docView=om(this.state.doc,Cm(this),Kl(this),this.dom,this),this.domObserver=new pc(this,(r,i,o,s)=>RC(this,r,i,o,s)),this.domObserver.start(),tC(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&lc(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(vm),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(eg(this),s=!0),this.state=e;let a=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(a||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=Tm(this);PC(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&lc(this),this.editable=Em(this),Mm(this);let l=Kl(this),c=Cm(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,c,l);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&b0(this);if(s){this.domObserver.stop();let p=f&&(Ve||we)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&LC(i.selection,e.selection);if(f){let m=we?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=hC(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=om(e.doc,c,l,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let h=this.input.mouseDown;p||!(h&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&_0(this)&&h.delaySelUpdate())?Ut(this,p):(Hm(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():d&&x0(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof H){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&em(this,n.getBoundingClientRect(),e)}else em(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 n=0;n<this.directPlugins.length;n++){let r=this.directPlugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let n=0;n<this.state.plugins.length;n++){let r=this.state.plugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let n=0;n<this.pluginViews.length;n++){let r=this.pluginViews[n];r.update&&r.update(this,e)}}updateDraggedNode(e,n){let r=e.node,i=-1;if(r.from<this.state.doc.content.size&&this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let o=r.from+(this.state.doc.content.size-n.doc.content.size);(o>0&&o<this.state.doc.content.size&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ks(e.slice,e.move,i<0?void 0:H.create(this.state.doc,i))}someProp(e,n){let r=this._props&&this._props[e],i;if(r!=null&&(i=n?n(r):r))return i;for(let s=0;s<this.directPlugins.length;s++){let a=this.directPlugins[s].props[e];if(a!=null&&(i=n?n(a):a))return i}let o=this.state.plugins;if(o)for(let s=0;s<o.length;s++){let a=o[s].props[e];if(a!=null&&(i=n?n(a):a))return i}}hasFocus(){if(Ve){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&&w0(this.dom),Ut(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let n=this.dom.parentNode;n;n=n.parentNode)if(n.nodeType==9||n.nodeType==11&&n.host)return n.getSelection||(Object.getPrototypeOf(n).getSelection=()=>n.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return T0(this,e)}coordsAtPos(e,n=1){return Lm(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return R0(this,n||this.state,e)}pasteHTML(e,n){return $i(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return $i(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return yc(this,e)}destroy(){this.docView&&(nC(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Kl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,c0())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return iC(this,e)}domSelectionRange(){let e=this.domSelection();return e?De&&this.root.nodeType===11&&h0(this.dom.ownerDocument)==this.dom&&EC(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Hi.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function Cm(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[oe.node(0,t.state.doc.content.size,e)]}function Mm(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:oe.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Em(t){return!t.someProp("editable",e=>e(t.state)===!1)}function LC(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Tm(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function PC(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function vm(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function Gt(t,e){return t.meta={package:"@milkdown/core",group:"System",...e},t}var lg={text:(t,e,n,r)=>{let i=t.value;return/^[^*_\\]*\s+$/.test(i)?i:n.safe(i,{...r,encode:[]})},strong:(t,e,n,r)=>{let i=t.marker||n.options.strong||"*",o=n.enter("strong"),s=n.createTracker(r),a=s.move(i+i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i+i),o(),a},emphasis:(t,e,n,r)=>{let i=t.marker||n.options.emphasis||"*",o=n.enter("emphasis"),s=n.createTracker(r),a=s.move(i);return a+=s.move(n.containerPhrasing(t,{before:a,after:i,...s.current()})),a+=s.move(i),o(),a}},se=K({},"editorView"),Ki=K({},"editorState"),Sc=K([],"initTimer"),sg=K({},"editor"),Hr=K([],"inputRules"),gt=K([],"prosePlugins"),Vr=K([],"remarkPlugins"),Os=K([],"nodeView"),Ds=K([],"markView"),tr=K(Si().use(hr).use(kr),"remark"),Lr=K({handlers:lg,encode:[]},"remarkStringifyOptions"),Cs=nt("ConfigReady");function FC(t){let e=n=>(n.record(Cs),async()=>(await t(n),n.done(Cs),()=>{n.clearTimer(Cs)}));return Gt(e,{displayName:"Config"}),e}var Jt=nt("InitReady");function zC(t){let e=n=>(n.inject(sg,t).inject(gt,[]).inject(Vr,[]).inject(Hr,[]).inject(Os,[]).inject(Ds,[]).inject(Lr,{handlers:lg,encode:[]}).inject(tr,Si().use(hr).use(kr)).inject(Sc,[Cs]).record(Jt),async()=>{await n.waitTimers(Sc);let r=n.get(Lr);return n.set(tr,Si().use(hr).use(kr,r)),n.done(Jt),()=>{n.remove(sg).remove(gt).remove(Vr).remove(Hr).remove(Os).remove(Ds).remove(Lr).remove(tr).remove(Sc).clearTimer(Jt)}});return Gt(e,{displayName:"Init"}),e}var Fe=nt("SchemaReady"),Ms=K([],"schemaTimer"),mt=K({},"schema"),Pr=K([],"nodes"),Fr=K([],"marks");function ag(t){return{...t,parseDOM:t.parseDOM?.map(e=>({priority:t.priority,...e}))}}var cg=t=>(t.inject(mt,{}).inject(Pr,[]).inject(Fr,[]).inject(Ms,[Jt]).record(Fe),async()=>{await t.waitTimers(Ms);let e=t.get(tr),n=t.get(Vr).reduce((i,o)=>i.use(o.plugin,o.options),e);t.set(tr,n);let r=new Yo({nodes:Object.fromEntries(t.get(Pr).map(([i,o])=>[i,ag(o)])),marks:Object.fromEntries(t.get(Fr).map(([i,o])=>[i,ag(o)]))});return t.set(mt,r),t.done(Fe),()=>{t.remove(mt).remove(Pr).remove(Fr).remove(Ms).clearTimer(Fe)}});Gt(cg,{displayName:"Schema"});var ug=class{constructor(){this.#t=new Ca,this.#e=null,this.setCtx=t=>{this.#e=t},this.chain=()=>{if(this.#e==null)throw So();let t=this.#e,e=[],n=this.get.bind(this),r={run:()=>{let o=qn(...e),s=t.get(se);return o(s.state,s.dispatch,s)},inline:o=>(e.push(o),r),pipe:i.bind(this)};function i(o,s){let a=n(o);return e.push(a(s)),r}return r}}#t;#e;get ctx(){return this.#e}create(t,e){let n=t.create(this.#t.sliceMap);return n.set(e),n}get(t){return this.#t.get(t).get()}remove(t){return this.#t.remove(t)}call(t,e){if(this.#e==null)throw So();let n=this.get(t)(e),r=this.#e.get(se);return n(r.state,r.dispatch,r)}inline(t){if(this.#e==null)throw So();let e=this.#e.get(se);return t(e.state,e.dispatch,e)}};function fg(t="cmdKey"){return K((()=>()=>!1),t)}var G=K(new ug,"commands"),Es=K([Fe],"commandsTimer"),zr=nt("CommandsReady"),dg=t=>{let e=new ug;return e.setCtx(t),t.inject(G,e).inject(Es,[Fe]).record(zr),async()=>(await t.waitTimers(Es),t.done(zr),()=>{t.remove(G).remove(Es).clearTimer(zr)})};Gt(dg,{displayName:"Commands"});function $C(t){return t.Backspace=qn(Lh,is,Ah,Rl),t}var pg=class{constructor(){this.#t=null,this.#e=[],this.setCtx=t=>{this.#t=t},this.add=t=>(this.#e.push(t),()=>{this.#e=this.#e.filter(e=>e!==t)}),this.addObjectKeymap=t=>{let e=[];return Object.entries(t).forEach(([n,r])=>{if(typeof r=="function"){let i={key:n,onRun:()=>r};this.#e.push(i),e.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}else this.#e.push(r),e.push(()=>{this.#e=this.#e.filter(i=>i!==r)})}),()=>{e.forEach(n=>n())}},this.addBaseKeymap=()=>{let t=$C(Bh);return this.addObjectKeymap(t)},this.build=()=>{let t={};return this.#e.forEach(e=>{t[e.key]=[...t[e.key]||[],e]}),Object.fromEntries(Object.entries(t).map(([e,n])=>{let r=n.sort((o,s)=>(s.priority??50)-(o.priority??50));return[e,(o,s,a)=>{let l=this.#t;if(l==null)throw dr();return qn(...r.map(c=>c.onRun(l)))(o,s,a)}]}))}}#t;#e;get ctx(){return this.#t}},Xi=K(new pg,"keymap"),Cc=K([Fe],"keymapTimer"),$r=nt("KeymapReady"),_C=t=>{let e=new pg;return e.setCtx(t),t.inject(Xi,e).inject(Cc,[Fe]).record($r),async()=>(await t.waitTimers(Cc),t.done($r),()=>{t.remove(Xi).remove(Cc).clearTimer($r)})},Ts=nt("ParserReady"),hg=(()=>{throw dr()}),Ue=K(hg,"parser"),Mc=K([],"parserTimer"),mg=t=>(t.inject(Ue,hg).inject(Mc,[Fe]).record(Ts),async()=>{await t.waitTimers(Mc);let e=t.get(tr),n=t.get(mt);return t.set(Ue,Gh.create(n,e)),t.done(Ts),()=>{t.remove(Ue).remove(Mc).clearTimer(Ts)}});Gt(mg,{displayName:"Parser"});var _r=nt("SerializerReady"),Ec=K([],"serializerTimer"),gg=(()=>{throw dr()}),nr=K(gg,"serializer"),yg=t=>(t.inject(nr,gg).inject(Ec,[Fe]).record(_r),async()=>{await t.waitTimers(Ec);let e=t.get(tr),n=t.get(mt);return t.set(nr,Yh.create(n,e)),t.done(_r),()=>{t.remove(nr).remove(Ec).clearTimer(_r)}});Gt(yg,{displayName:"Serializer"});var Ui=K("","defaultValue"),Ji=K(t=>t,"stateOptions"),vs=K([],"editorStateTimer"),Is=nt("EditorStateReady");function HC(t,e,n){if(typeof t=="string")return e(t);if(t.type==="html")return ln.fromSchema(n).parse(t.dom);if(t.type==="json")return He.fromJSON(n,t.value);throw td(t)}var VC=new te("MILKDOWN_STATE_TRACKER"),kg=t=>(t.inject(Ui,"").inject(Ki,{}).inject(Ji,e=>e).inject(vs,[Ts,_r,zr,$r]).record(Is),async()=>{await t.waitTimers(vs);let e=t.get(mt),n=t.get(Ue),r=t.get(Hr),i=t.get(Ji),o=t.get(gt),s=HC(t.get(Ui),n,e),a=t.get(Xi),l=a.addBaseKeymap(),c=[...o,new X({key:VC,state:{init:()=>{},apply:(d,p,h,m)=>{t.set(Ki,m)}}}),zh({rules:r}),jh(a.build())];t.set(gt,c);let u=i({schema:e,doc:s,plugins:c}),f=Tr.create(u);return t.set(Ki,f),t.done(Is),()=>{l(),t.remove(Ui).remove(Ki).remove(Ji).remove(vs).clearTimer(Is)}});Gt(kg,{displayName:"EditorState"});var Wr=K([],"pasteRule"),As=K([Fe],"pasteRuleTimer"),Ns=nt("PasteRuleReady"),bg=t=>(t.inject(Wr,[]).inject(As,[Fe]).record(Ns),async()=>(await t.waitTimers(As),t.done(Ns),()=>{t.remove(Wr).remove(As).clearTimer(Ns)}));Gt(bg,{displayName:"PasteRule"});var Gi=nt("EditorViewReady"),Rs=K([],"editorViewTimer"),Qi=K({},"editorViewOptions"),Yi=K(null,"root"),Tc=K(null,"rootDOM"),vc=K({},"rootAttrs");function WC(t,e){let n=document.createElement("div");n.className="milkdown",t.appendChild(n),e.set(Tc,n);let r=e.get(vc);return Object.entries(r).forEach(([i,o])=>n.setAttribute(i,o)),n}function jC(t){t.classList.add("editor"),t.setAttribute("role","textbox")}var qC=new te("MILKDOWN_VIEW_CLEAR"),xg=t=>(t.inject(Yi,document.body).inject(se,{}).inject(Qi,{}).inject(Tc,null).inject(vc,{}).inject(Rs,[Is,Ns]).record(Gi),async()=>{await t.wait(Jt);let e=t.get(Yi)||document.body,n=typeof e=="string"?document.querySelector(e):e;t.update(gt,s=>[new X({key:qC,view:a=>{let l=n?WC(n,t):void 0;return(()=>{if(l&&n){let u=a.dom;n.replaceChild(l,u),l.appendChild(u)}})(),{destroy:()=>{l?.parentNode&&l?.parentNode.replaceChild(a.dom,l),l?.remove()}}}}),...s]),await t.waitTimers(Rs);let r=t.get(Ki),i=t.get(Qi),o=new Hi(n,{state:r,nodeViews:Object.fromEntries(t.get(Os)),markViews:Object.fromEntries(t.get(Ds)),transformPasted:(s,a,l)=>(t.get(Wr).sort((c,u)=>(u.priority??50)-(c.priority??50)).map(c=>c.run).forEach(c=>{s=c(s,a,l)}),s),...i});return jC(o.dom),t.set(se,o),t.done(Gi),()=>{o?.destroy(),t.remove(Yi).remove(se).remove(Qi).remove(Tc).remove(vc).remove(Rs).clearTimer(Gi)}});Gt(xg,{displayName:"EditorView"});var wg=class Sg{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Ca,this.#o=new fd,this.#i=new Map,this.#a=new Map,this.#l=new cd(this.#s,this.#o),this.#d=()=>{let e=FC(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),n=[cg,mg,yg,dg,_C,bg,kg,xg,zC(this),e];this.#c(n,this.#a)},this.#c=(e,n)=>{e.forEach(r=>{let i=this.#l.produce(this.#t?r.meta:void 0),o=r(i);n.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#u=(e,n=!1)=>Promise.all([e].flat().map(async r=>{let i=this.#i.get(r)?.cleanup;return n?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof i=="function"?i():i})),this.#p=async()=>{await Promise.all([...this.#a.entries()].map(async([e,{cleanup:n}])=>typeof n=="function"?n():n)),this.#a.clear()},this.#f=e=>{this.#e=e,this.#n(e)},this.#h=e=>[...e.entries()].map(async([n,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(n,{ctx:i,handler:o,cleanup:s})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#r.push(e),this),this.removeConfig=e=>(this.#r=this.#r.filter(n=>n!==e),this),this.use=e=>{let n=[e].flat();return n.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(n,this.#i),this},this.remove=async e=>this.#e==="OnCreate"?(console.warn("[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code."),new Promise(n=>{setTimeout(()=>{n(this.remove(e))},50)})):(await this.#u([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#f("OnCreate"),this.#d(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#h(this.#a),this.#h(this.#i)].flat()),this.#f("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(n=>{setTimeout(()=>{n(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#f("OnDestroy"),await this.#u([...this.#i.keys()],e),await this.#p(),this.#f("Destroyed"),this),this.action=e=>e(this.#l),this.inspect=()=>this.#t?[...this.#a.values(),...this.#i.values()].map(({ctx:e})=>e?.inspector?.read()).filter(e=>!!e):(console.warn("[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first."),[])}static make(){return new Sg}#t;#e;#r;#n;#s;#o;#i;#a;#l;#d;#c;#u;#p;#f;#h;get ctx(){return this.#l}get status(){return this.#e}};var KC=t=>crypto.getRandomValues(new Uint8Array(t)),UC=(t,e,n)=>{let r=256-256%t.length;if(r===256){let o=t.length-1;return(s=e)=>{if(!s)return"";let a="";for(;;){let l=n(s),c=s;for(;c--;)if(a+=t[l[c]&o],a.length>=s)return a}}}let i=Math.ceil(1.6*256*e/r);return(o=e)=>{if(!o)return"";let s="";for(;;){let a=n(i),l=i;for(;l--;)if(a[l]<r&&(s+=t[a[l]%t.length],s.length>=o))return s}}},Cg=(t,e=21)=>UC(t,e|0,KC);var rz=Cg("abcedfghicklmn",10);function P(t,e){let n=fg(t),r=i=>async()=>{r.key=n,await i.wait(zr);let o=e(i);return i.get(G).create(n,o),r.run=s=>i.get(G).call(t,s),()=>{i.get(G).remove(n)}};return r}function fe(t){let e=n=>async()=>{await n.wait(Fe);let r=t(n);return n.update(Hr,i=>[...i,r]),e.inputRule=r,()=>{n.update(Hr,i=>i.filter(o=>o!==r))}};return e}function Mg(t){let e=n=>async()=>{await n.wait(Fe);let r=t(n);return n.update(Wr,i=>[...i,r]),e.pasteRule=r,()=>{n.update(Wr,i=>i.filter(o=>o!==r))}};return e}function JC(t,e){let n=r=>async()=>{let i=e(r);return r.update(Fr,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(Fr,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get(mt).marks[t];if(!i)throw ld(t);return i},n}function Bs(t,e){let n=r=>async()=>{let i=e(r);return r.update(Pr,o=>[...o.filter(s=>s[0]!==t),[t,i]]),n.id=t,n.schema=i,()=>{r.update(Pr,o=>o.filter(([s])=>s!==t))}};return n.type=r=>{let i=r.get(mt).nodes[t];if(!i)throw ad(t);return i},n}function Se(t){let e,n=r=>async()=>(await r.wait(Fe),e=t(r),r.update(gt,i=>[...i,e]),()=>{r.update(gt,i=>i.filter(o=>o!==e))});return n.plugin=()=>e,n.key=()=>e.spec.key,n}function GC(t){let e=n=>async()=>{await n.wait($r);let r=n.get(Xi),i=t(n),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function Je(t,e){let n=K(t,e),r=i=>(i.inject(n),()=>()=>{i.remove(n)});return r.key=n,r}function ne(t,e){let n=Je(e,t),r=Bs(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>ne(t,o(e)),i}function yt(t,e){let n=Je(e,t),r=JC(t,o=>o.get(n.key)(o)),i=[n,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=n,i.key=n.key,i.extendSchema=o=>yt(t,o(e)),i}function ze(t,e){let n=Je(Object.fromEntries(Object.entries(e).map(([o,{shortcuts:s,priority:a}])=>[o,{shortcuts:s,priority:a}])),`${t}Keymap`),r=GC(o=>{let s=o.get(n.key),a=Object.entries(e).flatMap(([l,{command:c}])=>{let u=s[l],f=[u.shortcuts].flat(),d=u.priority;return f.map(p=>[p,{key:p,onRun:c,priority:d}])});return Object.fromEntries(a)}),i=[n,r];return i.ctx=n,i.shortcuts=r,i.key=n.key,i.keymap=r.keymap,i}var at=(t,e=()=>({}))=>Je(e,`${t}Attr`),rr=(t,e=()=>({}))=>Je(e,`${t}Attr`);function Ge(t,e,n){let r=Je(n??{},t),i=s=>async()=>{await s.wait(Jt);let a={plugin:e(s),options:s.get(r.key)};return s.update(Vr,l=>[...l,a]),()=>{s.update(Vr,l=>l.filter(c=>c!==a))}},o=[r,i];return o.id=t,o.plugin=i,o.options=r,o}function Eg(t){return e=>{let n=e.get(se),r=e.get(mt),i=e.get(nr);if(!t)return i(n.state.doc);let o=n.state.doc.slice(t.from,t.to,!0),s=r.topNodeType.createAndFill(null,o.content);return s?i(s):(console.error("No document found"),"")}}function Tg(t,e=!1){return n=>{let r=n.get(se),i=n.get(Ue)(t);if(!i)return;if(!e){let{state:l}=r;return r.dispatch(l.tr.replace(0,l.doc.content.size,new A(i.content,0,0)))}let o=n.get(mt),s=n.get(Ji)({schema:o,doc:i,plugins:n.get(gt)}),a=Tr.create(s);r.updateState(a)}}function vg(t,e){return function(n,r){let{$from:i,$to:o,node:s}=n.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let a=i.node(-1);if(a.type!=t)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=t||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=E.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let y=i.depth-d;y>=i.depth-3;y--)f=E.from(i.node(y).copy(f));let p=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(E.from(t.createAndFill()));let h=i.before(i.depth-(d-1)),m=n.tr.replace(h,i.after(-p),new A(f,4-d,0)),g=-1;m.doc.nodesBetween(h,m.doc.content.size,(y,x)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=x+1)}),g>-1&&m.setSelection($.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let l=o.pos==i.end()?a.contentMatchAt(0).defaultType:null,c=n.tr.delete(i.pos,o.pos),u=l?[e?{type:t,attrs:e}:null,{type:l}]:void 0;return Vn(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function Ig(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==t);return o?n?r.node(o.depth-1).type==t?QC(e,n,t,o):YC(e,n,o):!0:!1}}function QC(t,e,n,r){let i=t.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(i.step(new Te(o-1,s,o,s,new A(E.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new Ei(i.doc.resolve(r.$from.pos),i.doc.resolve(s),r.depth));let a=Mr(r);if(a==null)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(o,-1)-1);return Wn(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),e(i.scrollIntoView()),!0}function YC(t,e,n){let r=t.tr,i=n.parent;for(let p=n.end,h=n.endIndex-1,m=n.startIndex;h>m;h--)p-=i.child(h).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let a=n.startIndex==0,l=n.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(a?0:1),u+1,s.content.append(l?E.empty:E.from(i))))return!1;let f=o.pos,d=f+s.nodeSize;return r.step(new Te(f-(a?1:0),d+(l?1:0),f+1,d-1,new A((a?E.empty:E.from(i.copy(E.empty))).append(l?E.empty:E.from(i.copy(E.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function Ag(t){return function(e,n){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==t);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let a=o.parent,l=a.child(s-1);if(l.type!=t)return!1;if(n){let c=l.lastChild&&l.lastChild.type==a.type,u=E.from(c?t.create():null),f=new A(E.from(t.create(null,E.from(a.type.create(null,u)))),c?3:1,0),d=o.start,p=o.end;n(e.tr.step(new Te(d-(c?3:1),p,d,p,f,1,!0)).scrollIntoView())}return!0}}function Ic(t){let e=new Map;if(!t||!t.type)throw new Error("mdast-util-definitions expected node");return dt(t,"definition",function(r){let i=Ng(r.identifier);i&&!e.get(i)&&e.set(i,r)}),n;function n(r){let i=Ng(r);return e.get(i)}}function Ng(t){return String(t||"").toUpperCase()}function Ls(){return function(t){let e=Ic(t);dt(t,function(n,r,i){if(n.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[On,r];if(n.type==="imageReference"||n.type==="linkReference"){let o=e(n.identifier);if(o&&i&&typeof r=="number")return i.children[r]=n.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:n.alt}:{type:"link",url:o.url,title:o.title,children:n.children},[On,r]}})}}function Rg(t,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){t.next(e.content);return}let n=[];e.content.forEach((r,i,o)=>{o!==e.childCount-1&&n.push(r)}),t.next(E.fromArray(n))}function M(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-commonmark",...e}}),t}var Ac=rr("emphasis");M(Ac,{displayName:"Attr<emphasis>",group:"Emphasis"});var qr=yt("emphasis",t=>({attrs:{marker:{default:t.get(Lr).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",t.get(Ac.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,n)=>{e.withMark(n,"emphasis",void 0,{marker:n.attrs.marker})}}}));M(qr.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});M(qr.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Nc=P("ToggleEmphasis",t=>()=>Ar(qr.type(t)));M(Nc,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var Og=fe(t=>Ht(/(?:^|[^*])\*([^*]+)\*$/,qr.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:n+1}}));M(Og,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var Dg=fe(t=>Ht(/\b_(?![_\s])(.*?[^_\s])_\b/,qr.type(t),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:n+1}}));M(Dg,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var Rc=ze("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:t=>{let e=t.get(G);return()=>e.call(Nc.key)}}});M(Rc.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});M(Rc.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var Oc=rr("strong");M(Oc,{displayName:"Attr<strong>",group:"Strong"});var Zi=yt("strong",t=>({attrs:{marker:{default:t.get(Lr).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:e=>e.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:e=>e==="bold"},{style:"font-weight=400",clearMark:e=>e.type.name=="strong"},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:e=>["strong",t.get(Oc.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,n,r)=>{e.openMark(r,{marker:n.marker}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,n)=>{e.withMark(n,"strong",void 0,{marker:n.attrs.marker})}}}));M(Zi.mark,{displayName:"MarkSchema<strong>",group:"Strong"});M(Zi.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var Dc=P("ToggleStrong",t=>()=>Ar(Zi.type(t)));M(Dc,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var Bg=fe(t=>Ht(/(?<![\w:/])(?:\*\*|__)([^*_]+?)(?:\*\*|__)(?![\w/])$/,Zi.type(t),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));M(Bg,{displayName:"InputRule<strong>",group:"Strong"});var Bc=ze("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:t=>{let e=t.get(G);return()=>e.call(Dc.key)}}});M(Bc.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});M(Bc.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var Lc=rr("inlineCode");M(Lc,{displayName:"Attr<inlineCode>",group:"InlineCode"});var bn=yt("inlineCode",t=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",t.get(Lc.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,n,r)=>{e.openMark(r),e.addText(n.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,n,r)=>(e.withMark(n,"inlineCode",r.text||""),!0)}}));M(bn.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});M(bn.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Pc=P("ToggleInlineCode",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,bn.type(t))?(n?.(i.removeMark(o,s,bn.type(t))),!0):(Object.keys(e.schema.marks).filter(a=>a!==bn.type.name).map(a=>e.schema.marks[a]).forEach(a=>{i.removeMark(o,s,a)}),n?.(i.addMark(o,s,bn.type(t).create())),!0)});M(Pc,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var Lg=fe(t=>Ht(/(?:`)([^`]+)(?:`)$/,bn.type(t)));M(Lg,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var Fc=ze("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:t=>{let e=t.get(G);return()=>e.call(Pc.key)}}});M(Fc.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});M(Fc.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var XC=new Set(["http:","https:","mailto:","tel:","ftp:"]);function ZC(t){return t<=32||t>=127&&t<=160||t>=8203&&t<=8205||t===8232||t===8233||t===65279}function eM(t){let e="";for(let n of t)ZC(n.codePointAt(0)??0)||(e+=n);return e}function tM(t){if(typeof t!="string")return"";let e=t.trim();if(!e)return"";let n=eM(e),r=/^([a-z][a-z0-9+.-]*):/i.exec(n)?.[1];return!r||XC.has(`${r.toLowerCase()}:`)?e:""}var zc=rr("link");M(zc,{displayName:"Attr<link>",group:"Link"});var jr=yt("link",t=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw tt(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...t.get(zc.key)(e),...e.attrs,href:tM(e.attrs.href)}],parseMarkdown:{match:e=>e.type==="link",runner:(e,n,r)=>{let i=n.url,o=n.title;e.openMark(r,{href:i,title:o}),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,n)=>{e.withMark(n,"link",void 0,{title:n.attrs.title,url:n.attrs.href})}}}));M(jr.mark,{displayName:"MarkSchema<link>",group:"Link"});var Pg=P("ToggleLink",t=>(e={})=>Ar(jr.type(t),e));M(Pg,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Fg=P("UpdateLink",t=>(e={})=>(n,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=n,{from:a,to:l}=s;if(n.doc.nodesBetween(a,a===l?l+1:l,(h,m)=>{if(jr.type(t).isInSet(h.marks))return i=h,o=m,!1}),!i)return!1;let c=i.marks.find(({type:h})=>h===jr.type(t));if(!c)return!1;let u=o,f=o+i.nodeSize,{tr:d}=n,p=jr.type(t).create({...c.attrs,...e});return p?(r(d.removeMark(u,f,c).addMark(u,f,p).setSelection(new z(d.selection.$anchor)).scrollIntoView()),!0):!1});M(Fg,{displayName:"Command<updateLinkCommand>",group:"Link"});var zg=Bs("doc",()=>({content:"block+",parseMarkdown:{match:({type:t})=>t==="root",runner:(t,e,n)=>{t.injectRoot(e,n)}},toMarkdown:{match:t=>t.type.name==="doc",runner:(t,e)=>{t.openNode("root"),t.next(e.content)}}}));M(zg,{displayName:"NodeSchema<doc>",group:"Doc"});function nM(t){return Dn(t,e=>e.type==="html"&&["<br />","<br>","<br >","<br/>"].includes(e.value?.trim()),(e,n)=>{if(!n.length)return;let r=n[n.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var Fs=Ge("remark-preserve-empty-line",()=>()=>nM);M(Fs.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});M(Fs.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var $c=at("paragraph");M($c,{displayName:"Attr<paragraph>",group:"Paragraph"});var kt=ne("paragraph",t=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",t.get($c.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,n,r)=>{e.openNode(r),n.children?e.next(n.children):e.addText(n.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,n)=>{let r=t.get(se).state?.doc.lastChild;e.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&rM(t)?e.addNode("html",void 0,"<br />"):Rg(e,n),e.closeNode()}}}));function rM(t){let e=!1;try{t.get(Fs.id),e=!0}catch{e=!1}return e}M(kt.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});M(kt.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var _c=P("TurnIntoText",t=>()=>Ir(kt.type(t)));M(_c,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Hc=ze("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:t=>{let e=t.get(G);return()=>e.call(_c.key)}}});M(Hc.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});M(Hc.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var iM=Array(6).fill(0).map((t,e)=>e+1);function oM(t){return t.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var zs=Je(oM,"headingIdGenerator");M(zs,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Vc=at("heading");M(Vc,{displayName:"Attr<heading>",group:"Heading"});var or=ne("heading",t=>{let e=t.get(zs.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:iM.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw tt(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...t.get(Vc.key)(n),id:n.attrs.id||e(n)},0],parseMarkdown:{match:({type:n})=>n==="heading",runner:(n,r,i)=>{let o=r.depth;n.openNode(i,{level:o}),n.next(r.children),n.closeNode()}},toMarkdown:{match:n=>n.type.name==="heading",runner:(n,r)=>{n.openNode("heading",void 0,{depth:r.attrs.level}),Rg(n,r),n.closeNode()}}}});M(or.node,{displayName:"NodeSchema<heading>",group:"Heading"});M(or.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var $g=fe(t=>Bl(/^(?<hashes>#+)\s$/,or.type(t),e=>{let n=e.groups?.hashes?.length||0,{$from:r}=t.get(se).state.selection,i=r.node();if(i.type.name==="heading"){let o=Number(i.attrs.level)+Number(n);return o>6&&(o=6),{level:o}}return{level:n}}));M($g,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var kn=P("WrapInHeading",t=>e=>(e??=1,e<1?Ir(kt.type(t)):Ir(or.type(t),{level:e})));M(kn,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Wc=P("DowngradeHeading",t=>()=>(e,n,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==or.type(t)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(n?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):Ir(kt.type(t))(e,n,r)});M(Wc,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var jc=ze("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:t=>{let e=t.get(G);return()=>e.call(kn.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:t=>{let e=t.get(G);return()=>e.call(kn.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:t=>{let e=t.get(G);return()=>e.call(kn.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:t=>{let e=t.get(G);return()=>e.call(kn.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:t=>{let e=t.get(G);return()=>e.call(kn.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:t=>{let e=t.get(G);return()=>e.call(kn.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:t=>{let e=t.get(G);return()=>e.call(Wc.key)}}});M(jc.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});M(jc.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var qc=at("blockquote");M(qc,{displayName:"Attr<blockquote>",group:"Blockquote"});var eo=ne("blockquote",t=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",t.get(qc.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,n,r)=>{e.openNode(r).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,n)=>{e.openNode("blockquote").next(n.content).closeNode()}}}));M(eo.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});M(eo.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var _g=fe(t=>as(/^\s*>\s$/,eo.type(t)));M(_g,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Kc=P("WrapInBlockquote",t=>()=>ss(eo.type(t)));M(Kc,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Uc=ze("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:t=>{let e=t.get(G);return()=>e.call(Kc.key)}}});M(Uc.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});M(Uc.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var Jc=at("codeBlock",()=>({pre:{},code:{}}));M(Jc,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var to=ne("code_block",t=>({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 tt(e);return{language:e.dataset.language}}}],toDOM:e=>{let n=t.get(Jc.key)(e),r=e.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,n,r)=>{let i=n.lang??"",o=n.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,n)=>{e.addNode("code",void 0,n.content.firstChild?.text||"",{lang:n.attrs.language})}}}));M(to.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});M(to.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var Hg=fe(t=>Bl(/^```(?<language>[a-z]*)?[\s\n]$/,to.type(t),e=>({language:e.groups?.language??""})));M(Hg,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Gc=P("CreateCodeBlock",t=>(e="")=>Ir(to.type(t),{language:e}));M(Gc,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var sM=P("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(n,r)=>t>=0?(r?.(n.tr.setNodeAttribute(t,"language",e)),!0):!1);M(sM,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Qc=ze("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:t=>{let e=t.get(G);return()=>e.call(Gc.key)}}});M(Qc.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});M(Qc.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Yc=at("image");M(Yc,{displayName:"Attr<image>",group:"Image"});var Kr=ne("image",t=>({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 tt(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...t.get(Yc.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,n,r)=>{let i=n.url,o=n.alt,s=n.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,n)=>{e.addNode("image",void 0,void 0,{title:n.attrs.title,url:n.attrs.src,alt:n.attrs.alt})}}}));M(Kr.node,{displayName:"NodeSchema<image>",group:"Image"});M(Kr.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var Vg=P("InsertImage",t=>(e={})=>(n,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,a=Kr.type(t).create({src:i,alt:o,title:s});return a&&r(n.tr.replaceSelectionWith(a).scrollIntoView()),!0});M(Vg,{displayName:"Command<insertImageCommand>",group:"Image"});var Wg=P("UpdateImage",t=>(e={})=>(n,r)=>{let i=Hh(n.selection,Kr.type(t));if(!i)return!1;let{node:o,pos:s}=i,a={...o.attrs},{src:l,alt:c,title:u}=e;return l!==void 0&&(a.src=l),c!==void 0&&(a.alt=c),u!==void 0&&(a.title=u),r?.(n.tr.setNodeMarkup(s,void 0,a).scrollIntoView()),!0});M(Wg,{displayName:"Command<updateImageCommand>",group:"Image"});var aM=fe(t=>new ke(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,n,r,i)=>{let[o,s,a="",l]=n;return o?e.tr.replaceWith(r,i,Kr.type(t).create({src:a,alt:s,title:l})):null}));M(aM,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Ps=at("hardbreak",t=>({"data-type":"hardbreak","data-is-inline":t.attrs.isInline}));M(Ps,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var ir=ne("hardbreak",t=>({inline:!0,group:"inline",attrs:{isInline:{default:!1,validate:"boolean"}},selectable:!1,parseDOM:[{tag:"br"},{tag:'span[data-type="hardbreak"]',getAttrs:()=>({isInline:!0})}],toDOM:e=>e.attrs.isInline?["span",t.get(Ps.key)(e)," "]:["br",t.get(Ps.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,n,r)=>{e.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>` `,toMarkdown:{match:e=>e.type.name==="hardbreak",runner:(e,n)=>{n.attrs.isInline?e.addNode("text",void 0,` -`):e.addNode("break")}}}));M(ir.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});M(ir.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Xc=P("InsertHardbreak",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(!(r instanceof z))return!1;if(r.empty){let o=r.$from.node();if(o.childCount>0&&o.lastChild?.type.name==="hardbreak")return n?.(i.replaceRangeWith(r.to-1,r.to,e.schema.node("paragraph")).setSelection($.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(i.setMeta("hardbreak",!0).replaceSelectionWith(ir.type(t).create()).scrollIntoView()),!0});M(Xc,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Zc=ze("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:t=>{let e=t.get(G);return()=>e.call(Xc.key)}}});M(Zc.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});M(Zc.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var eu=at("hr");M(eu,{displayName:"Attr<hr>",group:"Hr"});var no=te("hr",t=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",t.get(eu.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,n,r)=>{e.addNode(r)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));M(no.node,{displayName:"NodeSchema<hr>",group:"Hr"});M(no.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var Wg=fe(t=>new ke(/^(?:---|___\s|\*\*\*\s)$/,(e,n,r,i)=>{let{tr:o}=e;return n[0]&&o.replaceWith(r-1,i,no.type(t).create()),o}));M(Wg,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var jg=P("InsertHr",t=>()=>(e,n)=>{if(!n)return!0;let r=kt.node.type(t).create(),{tr:i,selection:o}=e,{from:s}=o,a=no.type(t).create();if(!a)return!0;let l=i.replaceSelectionWith(a).insert(s,r),c=$.findFrom(l.doc.resolve(s),1,!0);return c&&n(l.setSelection(c).scrollIntoView()),!0});M(jg,{displayName:"Command<insertHrCommand>",group:"Hr"});var tu=at("bulletList");M(tu,{displayName:"Attr<bulletList>",group:"BulletList"});var Ur=te("bullet_list",t=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw tt(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...t.get(tu.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"false";e.openNode(r,{spread:i}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!1,spread:n.attrs.spread}).next(n.content).closeNode()}}}));M(Ur.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});M(Ur.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var qg=fe(t=>as(/^\s*([-+*])\s$/,Ur.type(t)));M(qg,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var nu=P("WrapInBulletList",t=>()=>ss(Ur.type(t)));M(nu,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var ru=ze("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:t=>{let e=t.get(G);return()=>e.call(nu.key)}}});M(ru.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});M(ru.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var iu=at("orderedList");M(iu,{displayName:"Attr<orderedList>",group:"OrderedList"});var Jr=te("ordered_list",t=>({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 tt(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...t.get(iu.key)(e),...e.attrs.order===1?{}:{start:e.attrs.order},"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{spread:i,order:n.start??1}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!0,start:n.attrs.order??1,spread:n.attrs.spread==="true"}),e.next(n.content),e.closeNode()}}}));M(Jr.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});M(Jr.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var Kg=fe(t=>as(/^\s*(\d+)\.\s$/,Jr.type(t),e=>({order:Number(e[1])}),(e,n)=>n.childCount+n.attrs.order===Number(e[1])));M(Kg,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var ou=P("WrapInOrderedList",t=>()=>ss(Jr.type(t)));M(ou,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var su=ze("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:t=>{let e=t.get(G);return()=>e.call(ou.key)}}});M(su.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});M(su.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var au=at("listItem");M(au,{displayName:"Attr<listItem>",group:"ListItem"});var It=te("list_item",t=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"\u2022",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw tt(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...t.get(au.key)(e),"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e})=>e==="listItem",runner:(e,n,r)=>{let i=n.label!=null?`${n.label}.`:"\u2022",o=n.label!=null?"ordered":"bullet",s=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{label:i,listType:o,spread:s}),e.next(n.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,n)=>{e.openNode("listItem",void 0,{spread:n.attrs.spread}),e.next(n.content),e.closeNode()}}}));M(It.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});M(It.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var lu=P("SinkListItem",t=>()=>Ig(It.type(t)));M(lu,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var cu=P("LiftListItem",t=>()=>vg(It.type(t)));M(cu,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var uu=P("SplitListItem",t=>()=>Tg(It.type(t)));M(uu,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function aM(t){return(e,n,r)=>{let{selection:i}=e;if(!(i instanceof z))return!1;let{empty:o,$from:s}=i;return!o||s.parentOffset!==0||s.node(-1).type!==It.type(t)?!1:Nl(e,n,r)}}var fu=P("LiftFirstListItem",t=>()=>aM(t));M(fu,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var du=ze("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:t=>{let e=t.get(G);return()=>e.call(uu.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:t=>{let e=t.get(G);return()=>e.call(lu.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:t=>{let e=t.get(G);return()=>e.call(cu.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:t=>{let e=t.get(G);return()=>e.call(fu.key)}}});M(du.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});M(du.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var Ug=Bs("text",()=>({group:"inline",parseMarkdown:{match:({type:t})=>t==="text",runner:(t,e)=>{t.addText(e.value)}},toMarkdown:{match:t=>t.type.name==="text",runner:(t,e)=>{t.addNode("text",void 0,e.text)}}}));M(Ug,{displayName:"NodeSchema<text>",group:"Text"});var pu=at("html");M(pu,{displayName:"Attr<html>",group:"Html"});var hu=te("html",t=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{let n=document.createElement("span"),r={...t.get(pu.key)(e),"data-value":e.attrs.value,"data-type":"html"};return n.textContent=e.attrs.value,["span",r,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,n,r)=>{e.addNode(r,{value:n.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,n)=>{e.addNode("html",void 0,n.attrs.value)}}}));M(hu.node,{displayName:"NodeSchema<html>",group:"Html"});M(hu.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var lM=[Fg,$c,kt,zs,Vc,or,Ps,ir,qc,eo,Jc,to,eu,no,Yc,Kr,tu,Ur,iu,Jr,au,It,Ac,qr,Oc,Zi,Lc,bn,zc,jr,pu,hu,Ug].flat(),cM=[$g,qg,Kg,_g,Wg,zg].flat(),uM=[Rg,Og,Bg,Dg],fM=P("IsMarkSelected",()=>t=>e=>{if(!t)return!1;let{doc:n,selection:r}=e;return n.rangeHasMark(r.from,r.to,t)}),dM=P("IsNoteSelected",()=>t=>e=>t?Hh(e,t).hasNode:!1),pM=P("ClearTextInCurrentBlock",()=>()=>(t,e)=>{let n=t.tr,{$from:r,$to:i}=n.selection,{pos:o}=r,{pos:s}=i,a=o-r.node().content.size;return a<0?!1:(n=n.deleteRange(a,s),e?.(n),!0)}),hM=P("SetBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr,{from:s,to:a}=o.selection;try{o.setBlockType(s,a,r,i)}catch{return!1}return n?.(o),!0}),mM=P("WrapInBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let{$from:s,$to:a}=o.selection,l=s.blockRange(a),c=l&&Hn(l,r,i);if(!c)return!1;o=o.wrap(l,c)}catch{return!1}return n?.(o),!0}),gM=P("AddBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let s=r instanceof He?r:r.createAndFill(i);if(!s)return!1;o.replaceSelectionWith(s)}catch{return!1}return n?.(o),!0}),yM=P("SelectTextNearPos",()=>t=>(e,n)=>{let{pos:r}=t??{};if(r==null)return!1;let i=(s,a,l)=>Math.min(Math.max(s,a),l),o=e.tr;try{let s=e.doc.resolve(i(r,0,e.doc.content.size));o.setSelection(z.near(s))}catch{return!1}return n?.(o.scrollIntoView()),!0}),kM=[_c,Kc,kn,Wc,Gc,Xc,jg,Hg,Vg,ou,nu,lu,uu,cu,fu,Nc,Pc,Dc,Lg,Pg,fM,dM,pM,hM,mM,gM,yM],bM=[Uc,Qc,Zc,jc,du,su,ru,Hc,Rc,Fc,Bc].flat(),mu=Ge("remarkAddOrderInList",()=>()=>t=>{dt(t,"list",e=>{if(e.ordered){let n=e.start??1;e.children.forEach((r,i)=>{r.label=i+n})}})});M(mu.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});M(mu.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var gu=Ge("remarkLineBreak",()=>()=>t=>{let e=/[\t ]*(?:\r?\n|\r)/g;dt(t,"text",(n,r,i)=>{if(!n.value||typeof n.value!="string")return;let o=[],s=0;e.lastIndex=0;let a=e.exec(n.value);for(;a;){let l=a.index;s!==l&&o.push({type:"text",value:n.value.slice(s,l)}),o.push({type:"break",data:{isInline:!0}}),s=l+a[0].length,a=e.exec(n.value)}if(o.length>0&&i&&typeof r=="number")return s<n.value.length&&o.push({type:"text",value:n.value.slice(s)}),i.children.splice(r,1,...o),r+o.length})});M(gu.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});M(gu.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var yu=Ge("remarkInlineLink",()=>Ls);M(yu.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});M(yu.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var xM=t=>!!t.children,wM=t=>t.type==="html";function SM(t,e){return n(t,0,null)[0];function n(r,i,o){if(xM(r)){let s=[];for(let a=0,l=r.children.length;a<l;a++){let c=r.children[a];if(c){let u=n(c,a,r);if(u)for(let f=0,d=u.length;f<d;f++){let p=u[f];p&&s.push(p)}}}r.children=s}return e(r,i,o)}}var CM=["root","blockquote","listItem"],ku=Ge("remarkHTMLTransformer",()=>()=>t=>{SM(t,(e,n,r)=>wM(e)?(r&&CM.includes(r.type)&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});M(ku.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});M(ku.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var bu=Ge("remarkMarker",()=>()=>(t,e)=>{let n=r=>e.value.charAt(r.position.start.offset);dt(t,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});M(bu.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});M(bu.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var Jg=Se(()=>{let t=!1,e=new X({key:new ee("MILKDOWN_INLINE_NODES_CURSOR"),state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;let r=n.selection.$from,i=r.nodeBefore,o=r.nodeAfter;return!!(i&&o&&i.isInline&&!i.isText&&o.isInline&&!o.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>t?(t=!1,requestAnimationFrame(()=>{if(e.getState(n.state)){let i=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i))}}),!0):!1,compositionstart:n=>(e.getState(n.state)&&(t=!0),!1),beforeinput:(n,r)=>{if(e.getState(n.state)&&r instanceof InputEvent&&r.data&&!t){let i=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i)),!0}return!1}},decorations(n){if(e.getState(n)){let r=n.selection.$from.pos,i=document.createElement("span"),o=se.widget(r,i,{side:-1}),s=document.createElement("span"),a=se.widget(r,s);return setTimeout(()=>{i.contentEditable="true",s.contentEditable="true"}),ne.create(n.doc,[o,a])}return ne.empty}}});return e});M(Jg,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Gg=Se(t=>new X({key:new ee("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,n,r)=>{if(!e.length)return;let[i]=e;if(!i)return;let[o]=i.steps;if(i.getMeta("hardbreak")){if(!(o instanceof de))return;let{from:s}=o;return r.tr.setNodeMarkup(s,ir.type(t),void 0,[])}if(o instanceof $n){let s=r.tr,{from:a,to:l}=o;return r.doc.nodesBetween(a,l,(c,u)=>{c.type===ir.type(t)&&(s=s.setNodeMarkup(u,ir.type(t),void 0,[]))}),s}}}));M(Gg,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var xu=Je(["table","code_block"],"hardbreakFilterNodes");M(xu,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var Qg=Se(t=>{let e=t.get(xu.key);return new X({key:new ee("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(n,r)=>{let i=n.getMeta("hardbreak"),[o]=n.steps;if(i&&o){let{from:s}=o,a=r.doc.resolve(s),l=a.depth,c=!0;for(;l>0;)e.includes(a.node(l).type.name)&&(c=!1),l--;return c}return!0}})});M(Qg,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var Yg=Se(t=>{let e=new ee("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;let i=t.get(zs.key),o=r.state.tr.setMeta("addToHistory",!1),s=!1,a={};r.state.doc.descendants((l,c)=>{if(l.type===or.type(t)){if(l.textContent.trim().length===0)return;let u=l.attrs,f=i(l);a[f]?(a[f]+=1,f+=`-#${a[f]}`):a[f]=1,u.id!==f&&(s=!0,o.setMeta(e,!0).setNodeMarkup(c,void 0,{...u,id:f}))}}),s&&r.dispatch(o)};return new X({key:e,view:r=>(n(r),{update:(i,o)=>{i.state.doc.eq(o.doc)||n(i)}})})});M(Yg,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var Xg=Se(t=>{let e=(n,r,i)=>{if(!i.selection||n.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;let o=Jr.type(t),s=Ur.type(t),a=It.type(t),l=(f,d,p=1)=>{let h=!1,m=`${d+p}.`;return f.label!==m&&(f.label=m,h=!0),h},c=i.tr,u=!1;return i.doc.descendants((f,d,p,h)=>{if(f.type===s){let m=f.maybeChild(0);m?.type===a&&m.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(d,o,{spread:"true"}),f.descendants((g,y,x,C)=>{if(g.type===a){let v={...g.attrs};l(v,C)&&(c=c.setNodeMarkup(y,void 0,v))}return!1}))}else if(f.type===a&&p?.type===o){let m={...f.attrs},g=!1;m.listType!=="ordered"&&(m.listType="ordered",g=!0),p?.maybeChild(0)&&(g=l(m,h,p?.attrs.order??1)),g&&(c=c.setNodeMarkup(d,void 0,m),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new X({key:new ee("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});M(Xg,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var MM=[Gg,xu,Qg,Jg,mu,yu,gu,ku,bu,Fs,Yg,Xg].flat(),Zg=[lM,cM,uM,kM,bM,MM].flat();var Su,Cu;if(typeof WeakMap<"u"){let t=new WeakMap;Su=e=>t.get(e),Cu=(e,n)=>(t.set(e,n),n)}else{let t=[],n=0;Su=r=>{for(let i=0;i<t.length;i+=2)if(t[i]==r)return t[i+1]},Cu=(r,i)=>(n==10&&(n=0),t[n++]=r,t[n++]=i)}var Z=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e<this.map.length;e++){let n=this.map[e];if(n!=t)continue;let r=e%this.width,i=e/this.width|0,o=r+1,s=i+1;for(let a=1;o<this.width&&this.map[e+a]==n;a++)o++;for(let a=1;s<this.height&&this.map[e+this.width*a]==n;a++)s++;return{left:r,top:i,right:o,bottom:s}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){let{left:r,right:i,top:o,bottom:s}=this.findCell(t);return e=="horiz"?(n<0?r==0:i==this.width)?null:this.map[o*this.width+(n<0?r-1:i)]:(n<0?o==0:s==this.height)?null:this.map[r+this.width*(n<0?o-1:s)]}rectBetween(t,e){let{left:n,right:r,top:i,bottom:o}=this.findCell(t),{left:s,right:a,top:l,bottom:c}=this.findCell(e);return{left:Math.min(n,s),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(o,c)}}cellsInRect(t){let e=[],n={};for(let r=t.top;r<t.bottom;r++)for(let i=t.left;i<t.right;i++){let o=r*this.width+i,s=this.map[o];n[s]||(n[s]=!0,!(i==t.left&&i&&this.map[o-1]==s||r==t.top&&r&&this.map[o-this.width]==s)&&e.push(s))}return e}positionAt(t,e,n){for(let r=0,i=0;;r++){let o=i+n.child(r).nodeSize;if(r==t){let s=e+t*this.width,a=(t+1)*this.width;for(;s<a&&this.map[s]<i;)s++;return s==a?o-1:this.map[s]}i=o}}static get(t){return Su(t)||Cu(t,EM(t))}};function EM(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);let e=TM(t),n=t.childCount,r=[],i=0,o=null,s=[];for(let c=0,u=e*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){let f=t.child(c);u++;for(let h=0;;h++){for(;i<r.length&&r[i]!=0;)i++;if(h==f.childCount)break;let m=f.child(h),{colspan:g,rowspan:y,colwidth:x}=m.attrs;for(let C=0;C<y;C++){if(C+c>=n){(o||(o=[])).push({type:"overlong_rowspan",pos:u,n:y-C});break}let v=i+C*e;for(let I=0;I<g;I++){r[v+I]==0?r[v+I]=u:(o||(o=[])).push({type:"collision",row:c,pos:u,n:g-I});let w=x&&x[I];if(w){let N=(v+I)%e*2,D=s[N];D==null||D!=w&&s[N+1]==1?(s[N]=w,s[N+1]=1):D==w&&s[N+1]++}}}i+=g,u+=m.nodeSize}let d=(c+1)*e,p=0;for(;i<d;)r[i++]==0&&p++;p&&(o||(o=[])).push({type:"missing",row:c,n:p}),u++}(e===0||n===0)&&(o||(o=[])).push({type:"zero_sized"});let a=new Z(e,n,r,o),l=!1;for(let c=0;!l&&c<s.length;c+=2)s[c]!=null&&s[c+1]<n&&(l=!0);return l&&vM(a,s,t),a}function TM(t){let e=-1,n=!1;for(let r=0;r<t.childCount;r++){let i=t.child(r),o=0;if(n)for(let s=0;s<r;s++){let a=t.child(s);for(let l=0;l<a.childCount;l++){let c=a.child(l);s+c.attrs.rowspan>r&&(o+=c.attrs.colspan)}}for(let s=0;s<i.childCount;s++){let a=i.child(s);o+=a.attrs.colspan,a.attrs.rowspan>1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function vM(t,e,n){t.problems||(t.problems=[]);let r={};for(let i=0;i<t.map.length;i++){let o=t.map[i];if(r[o])continue;r[o]=!0;let s=n.nodeAt(o);if(!s)throw new RangeError(`No cell with offset ${o} found`);let a=null,l=s.attrs;for(let c=0;c<l.colspan;c++){let u=e[(i+c)%t.width*2];u!=null&&(!l.colwidth||l.colwidth[c]!=u)&&((a||(a=IM(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function IM(t){if(t.colwidth)return t.colwidth.slice();let e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function ey(t,e){if(typeof t=="string")return{};let n=t.getAttribute("data-colwidth"),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(s=>Number(s)):null,i=Number(t.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let a=e[s].getFromDOM,l=a&&a(t);l!=null&&(o[s]=l)}return o}function ty(t,e){let n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan),t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan),t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(t.attrs[r],n)}return n}function AM(t){if(t!==null){if(!Array.isArray(t))throw new TypeError("colwidth must be null or an array");for(let e of t)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function py(t){let e=t.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:AM}};for(let r in e)n[r]={default:e[r].default,validate:e[r].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:t.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:t.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>ey(r,e)}],toDOM(r){return["td",ty(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ey(r,e)}],toDOM(r){return["th",ty(r,e),0]}}}}function $e(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(let n in t.nodes){let r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var xn=new ee("selectingCells");function Yr(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function Ie(t){let e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function js(t){let e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let n=Yr(e.$head)||NM(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function NM(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function Mu(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function RM(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function vu(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function hy(t,e,n){let r=t.node(-1),i=Z.get(r),o=t.start(-1),s=i.nextCell(t.pos-o,e,n);return s==null?null:t.node(0).resolve(o+s)}function sr(t,e,n=1){let r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function OM(t,e,n=1){let r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(e,0,0)}return r}function DM(t,e,n){let r=$e(e.type.schema).header_cell;for(let i=0;i<t.height;i++)if(e.nodeAt(t.map[n+i*t.width]).type!=r)return!1;return!0}var ae=class Qt extends ${constructor(e,n=e){let r=e.node(-1),i=Z.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,n.pos-o),a=e.node(0),l=i.cellsInRect(s).filter(u=>u!=n.pos-o);l.unshift(n.pos-o);let c=l.map(u=>{let f=r.nodeAt(u);if(!f)throw new RangeError(`No cell with offset ${u} found`);let d=o+u+1;return new un(a.resolve(d),a.resolve(d+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){let r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(Mu(r)&&Mu(i)&&vu(r,i)){let o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Qt.rowSelection(r,i):o&&this.isColSelection()?Qt.colSelection(r,i):new Qt(r,i)}return z.between(r,i)}content(){let e=this.$anchorCell.node(-1),n=Z.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let l=i.top;l<i.bottom;l++){let c=[];for(let u=l*n.width+i.left,f=i.left;f<i.right;f++,u++){let d=n.map[u];if(o[d])continue;o[d]=!0;let p=n.findCell(d),h=e.nodeAt(d);if(!h)throw new RangeError(`No cell with offset ${d} found`);let m=i.left-p.left,g=p.right-i.right;if(m>0||g>0){let y=h.attrs;if(m>0&&(y=sr(y,0,m)),g>0&&(y=sr(y,y.colspan-g,g)),p.left<i.left){if(h=h.type.createAndFill(y),!h)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else h=h.type.create(y,h.content)}if(p.top<i.top||p.bottom>i.bottom){let y={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top<i.top?h=h.type.createAndFill(y):h=h.type.create(y,h.content)}c.push(h)}s.push(e.child(l).copy(E.from(c)))}let a=this.isColSelection()&&this.isRowSelection()?e:s;return new A(E.from(a),1,1)}replace(e,n=A.empty){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:a,$to:l}=i[s],c=e.mapping.slice(r);e.replace(c.map(a.pos),c.map(l.pos),s?A.empty:n)}let o=$.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);o&&e.setSelection(o)}replaceWith(e,n){this.replace(e,new A(E.from(n),0,0))}forEachCell(e){let n=this.$anchorCell.node(-1),r=Z.get(n),i=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let s=0;s<o.length;s++)e(n.nodeAt(o[s]),i+o[s])}isColSelection(){let e=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(e,n)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){let r=e.node(-1),i=Z.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.top<=a.top?(s.top>0&&(e=l.resolve(o+i.map[s.left])),a.bottom<i.height&&(n=l.resolve(o+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(o+i.map[a.left])),s.bottom<i.height&&(e=l.resolve(o+i.map[i.width*(i.height-1)+s.right-1]))),new Qt(e,n)}isRowSelection(){let e=this.$anchorCell.node(-1),n=Z.get(e),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),o=n.colCount(this.$headCell.pos-r);if(Math.min(i,o)>0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,a=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,a)==n.width}eq(e){return e instanceof Qt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){let r=e.node(-1),i=Z.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.left<=a.left?(s.left>0&&(e=l.resolve(o+i.map[s.top*i.width])),a.right<i.width&&(n=l.resolve(o+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(o+i.map[a.top*i.width])),s.right<i.width&&(e=l.resolve(o+i.map[i.width*(s.top+1)-1]))),new Qt(e,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,n){return new Qt(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){return new Qt(e.resolve(n),e.resolve(r))}getBookmark(){return new BM(this.$anchorCell.pos,this.$headCell.pos)}};ae.prototype.visible=!1;$.jsonID("cell",ae);var BM=class my{constructor(e,n){this.anchor=e,this.head=n}map(e){return new my(e.map(this.anchor),e.map(this.head))}resolve(e){let n=e.resolve(this.anchor),r=e.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&vu(n,r)?new ae(n,r):$.near(r,1)}};function LM(t){if(!(t.selection instanceof ae))return null;let e=[];return t.selection.forEachCell((n,r)=>{e.push(se.node(r,r+n.nodeSize,{class:"selectedCell"}))}),ne.create(t.doc,e)}function PM({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let n=t.pos,r=e.pos,i=t.depth;for(;i>=0&&!(t.after(i+1)<t.end(i));i--,n++);for(let o=e.depth;o>=0&&!(e.before(o+1)>e.start(o));o--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function FM({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){let o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&e.parentOffset===0}function zM(t,e,n){let r=(e||t).selection,i=(e||t).doc,o,s;if(r instanceof H&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=ae.create(i,r.from);else if(s=="row"){let a=i.resolve(r.from+1);o=ae.rowSelection(a,a)}else if(!n){let a=Z.get(r.node),l=r.from+1,c=l+a.map[a.width*a.height-1];o=ae.create(i,l+1,c)}}else r instanceof z&&PM(r)?o=z.create(i,r.from):r instanceof z&&FM(r)&&(o=z.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var $M=new ee("fix-tables");function gy(t,e,n,r){let i=t.childCount,o=e.childCount;e:for(let s=0,a=0;s<o;s++){let l=e.child(s);for(let c=a,u=Math.min(i,s+3);c<u;c++)if(t.child(c)==l){a=c+1,n+=l.nodeSize;continue e}r(l,n),a<i&&t.child(a).sameMarkup(l)?gy(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function _M(t,e){let n,r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=HM(t,i,o,n))};return e?e.doc!=t.doc&&gy(e.doc,t.doc,0,r):t.doc.descendants(r),n}function HM(t,e,n,r){let i=Z.get(e);if(!i.problems)return r;r||(r=t.tr);let o=[];for(let l=0;l<i.height;l++)o.push(0);for(let l=0;l<i.problems.length;l++){let c=i.problems[l];if(c.type=="collision"){let u=e.nodeAt(c.pos);if(!u)continue;let f=u.attrs;for(let d=0;d<f.rowspan;d++)o[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,sr(f,f.colspan-c.n,c.n))}else if(c.type=="missing")o[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){let u=r.mapping.map(n);r.delete(u,u+e.nodeSize)}}let s,a;for(let l=0;l<o.length;l++)o[l]&&(s==null&&(s=l),a=l);for(let l=0,c=n+1;l<i.height;l++){let u=e.child(l),f=c+u.nodeSize,d=o[l];if(d>0){let p="cell";u.firstChild&&(p=u.firstChild.type.spec.tableRole);let h=[];for(let g=0;g<d;g++){let y=$e(t.schema)[p].createAndFill();y&&h.push(y)}let m=(l==0||s==l-1)&&a==l?c+1:f-1;r.insert(r.mapping.map(m),h)}c=f}return r.setMeta($M,{fixTables:!0})}function yy(t){let e=Z.get(t),n=[],r=e.height,i=e.width;for(let o=0;o<r;o++){let s=[];for(let a=0;a<i;a++){let l=o*i+a,c=e.map[l];if(o>0){let u=l-i;if(c===e.map[u]){s.push(null);continue}}if(a>0){let u=l-1;if(c===e.map[u]){s.push(null);continue}}s.push(t.nodeAt(c))}n.push(s)}return n}function ky(t,e){let n=[],r=Z.get(t),i=r.height,o=r.width;for(let s=0;s<i;s++){let a=t.child(s),l=[];for(let u=0;u<o;u++){let f=e[s][u];if(!f)continue;let d=r.map[s*r.width+u],p=t.nodeAt(d);if(!p)continue;let h=p.type.createChecked(f.attrs,f.content,f.marks);l.push(h)}let c=a.type.createChecked(a.attrs,l,a.marks);n.push(c)}return t.type.createChecked(t.attrs,n,t.marks)}function by(t,e,n,r){let i=e[0]>n[0]?-1:1,o=t.splice(e[0],e.length),s=o.length%2===0?1:0,a;return r===-1&&i===1?a=n[0]-1:r===1&&i===-1?a=n[n.length-1]-s+1:a=i===-1?n[0]:n[n.length-1]-s,t.splice(a,0,...o),t}function Xr(t){return VM(e=>e.type.spec.tableRole==="table",t)}function VM(t,e){for(let n=e.depth;n>=0;n-=1){let r=e.node(n);if(t(r))return{node:r,pos:n===0?0:e.before(n),start:e.start(n),depth:n}}return null}function Gr(t,e){let n=Xr(e.$from);if(!n)return;let r=Z.get(n.node);if(!(t<0||t>r.width-1))return r.cellsInRect({left:t,right:t+1,top:0,bottom:r.height}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function Qr(t,e){let n=Xr(e.$from);if(!n)return;let r=Z.get(n.node);if(!(t<0||t>r.height-1))return r.cellsInRect({left:0,right:r.width,top:t,bottom:t+1}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function ny(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Gr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Gr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;d.node.attrs.colspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Gr(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Gr(r,t.selection),a=Qr(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Gr(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function ry(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Qr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Qr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;d.node.attrs.rowspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Qr(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Qr(r,t.selection),a=Gr(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Qr(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function iy(t){return t[0].map((e,n)=>t.map(r=>r[n]))}function WM(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Xr(r.doc.resolve(a));if(!l)return!1;let c=(e=ny(r,i))===null||e===void 0?void 0:e.indexes,u=(n=ny(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=jM(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=Z.get(f),p=l.start,h=o,m=d.positionAt(d.height-1,h,f),g=r.doc.resolve(p+m),y=d.positionAt(0,h,f),x=r.doc.resolve(p+y);return r.setSelection(ae.colSelection(g,x)),!0}function jM(t,e,n,r){let i=iy(yy(t));return i=by(i,e,n,r),i=iy(i),ky(t,i)}function qM(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Xr(r.doc.resolve(a));if(!l)return!1;let c=(e=ry(r,i))===null||e===void 0?void 0:e.indexes,u=(n=ry(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=KM(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=Z.get(f),p=l.start,h=o,m=d.positionAt(h,d.width-1,f),g=r.doc.resolve(p+m),y=d.positionAt(h,0,f),x=r.doc.resolve(p+y);return r.setSelection(ae.rowSelection(g,x)),!0}function KM(t,e,n,r){let i=yy(t);return i=by(i,e,n,r),ky(t,i)}function bt(t){let e=t.selection,n=js(t),r=n.node(-1),i=n.start(-1),o=Z.get(r);return{...e instanceof ae?o.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o.findCell(n.pos-i),tableStart:i,map:o,table:r}}function xy(t,{map:e,tableStart:n,table:r},i){let o=i>0?-1:0;DM(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s<e.height;s++){let a=s*e.width+i;if(i>0&&i<e.width&&e.map[a-1]==e.map[a]){let l=e.map[a],c=r.nodeAt(l);t.setNodeMarkup(t.mapping.map(n+l),null,OM(c.attrs,i-e.colCount(l))),s+=c.attrs.rowspan-1}else{let l=o==null?$e(r.type.schema).cell:r.nodeAt(e.map[a+o]).type,c=e.positionAt(s,i,r);t.insert(t.mapping.map(n+c),l.createAndFill())}}return t}function wy(t,e){if(!Ie(t))return!1;if(e){let n=bt(t);e(xy(t.tr,n,n.left))}return!0}function qs(t,e){if(!Ie(t))return!1;if(e){let n=bt(t);e(xy(t.tr,n,n.right))}return!0}function UM(t,{map:e,table:n,tableStart:r},i){let o=t.mapping.maps.length;for(let s=0;s<e.height;){let a=s*e.width+i,l=e.map[a],c=n.nodeAt(l),u=c.attrs;if(i>0&&e.map[a-1]==l||i<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(o).map(r+l),null,sr(u,i-e.colCount(l)));else{let f=t.mapping.slice(o).map(r+l);t.delete(f,f+c.nodeSize)}s+=u.rowspan}}function Ks(t,e){if(!Ie(t))return!1;if(e){let n=bt(t),r=t.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;UM(r,n,i),i!=n.left;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=Z.get(o)}e(r)}return!0}function JM(t,e,n){var r;let i=$e(e.type.schema).header_cell;for(let o=0;o<t.width;o++)if(((r=e.nodeAt(t.map[o+n*t.width]))===null||r===void 0?void 0:r.type)!=i)return!1;return!0}function GM(t,{map:e,tableStart:n,table:r},i){let o=n;for(let c=0;c<i;c++)o+=r.child(c).nodeSize;let s=[],a=i>0?-1:0;JM(e,r,i+a)&&(a=i==0||i==e.height?null:0);for(let c=0,u=e.width*i;c<e.width;c++,u++)if(i>0&&i<e.height&&e.map[u]==e.map[u-e.width]){let f=e.map[u],d=r.nodeAt(f).attrs;t.setNodeMarkup(n+f,null,{...d,rowspan:d.rowspan+1}),c+=d.colspan-1}else{var l;let f=a==null?$e(r.type.schema).cell:(l=r.nodeAt(e.map[u+a*e.width]))===null||l===void 0?void 0:l.type,d=f?.createAndFill();d&&s.push(d)}return t.insert(o,$e(r.type.schema).row.create(null,s)),t}function Sy(t,e){if(!Ie(t))return!1;if(e){let n=bt(t);e(GM(t.tr,n,n.bottom))}return!0}function QM(t,{map:e,table:n,tableStart:r},i){let o=0;for(let c=0;c<i;c++)o+=n.child(c).nodeSize;let s=o+n.child(i).nodeSize,a=t.mapping.maps.length;t.delete(o+r,s+r);let l=new Set;for(let c=0,u=i*e.width;c<e.width;c++,u++){let f=e.map[u];if(!l.has(f)){if(l.add(f),i>0&&f==e.map[u-e.width]){let d=n.nodeAt(f).attrs;t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d,rowspan:d.rowspan-1}),c+=d.colspan-1}else if(i<e.height&&f==e.map[u+e.width]){let d=n.nodeAt(f),p=d.attrs,h=d.type.create({...p,rowspan:d.attrs.rowspan-1},d.content),m=e.positionAt(i+1,c,n);t.insert(t.mapping.slice(a).map(r+m),h),c+=p.colspan-1}}}}function Us(t,e){if(!Ie(t))return!1;if(e){let n=bt(t),r=t.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;QM(r,n,i),i!=n.top;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=Z.get(n.table)}e(r)}return!0}function Cy(t,e){return function(n,r){if(!Ie(n))return!1;let i=js(n);if(i.nodeAfter.attrs[t]===e)return!1;if(r){let o=n.tr;n.selection instanceof ae?n.selection.forEachCell((s,a)=>{s.attrs[t]!==e&&o.setNodeMarkup(a,null,{...s.attrs,[t]:e})}):o.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[t]:e}),r(o)}return!0}}function YM(t){return function(e,n){if(!Ie(e))return!1;if(n){let r=$e(e.schema),i=bt(e),o=e.tr,s=i.map.cellsInRect(t=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:t=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=s.map(l=>i.table.nodeAt(l));for(let l=0;l<s.length;l++)a[l].type==r.header_cell&&o.setNodeMarkup(i.tableStart+s[l],r.cell,a[l].attrs);if(o.steps.length===0)for(let l=0;l<s.length;l++)o.setNodeMarkup(i.tableStart+s[l],r.header_cell,a[l].attrs);n(o)}return!0}}function oy(t,e,n){let r=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let i=0;i<r.length;i++){let o=e.table.nodeAt(r[i]);if(o&&o.type!==n.header_cell)return!1}return!0}function Iu(t,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?YM(t):function(n,r){if(!Ie(n))return!1;if(r){let i=$e(n.schema),o=bt(n),s=n.tr,a=oy("row",o,i),l=oy("column",o,i),c=(t==="column"?a:t==="row"&&l)?1:0,u=t=="column"?{left:0,top:c,right:1,bottom:o.map.height}:t=="row"?{left:c,top:0,right:o.map.width,bottom:1}:o,f=t=="column"?l?i.cell:i.header_cell:t=="row"?a?i.cell:i.header_cell:i.cell;o.map.cellsInRect(u).forEach(d=>{let p=d+o.tableStart,h=s.doc.nodeAt(p);h&&s.setNodeMarkup(p,f,h.attrs)}),r(s)}return!0}}var zz=Iu("row",{useDeprecatedLogic:!0}),$z=Iu("column",{useDeprecatedLogic:!0}),_z=Iu("cell",{useDeprecatedLogic:!0});function XM(t,e){if(e<0){let n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,i=t.before();r>=0;r--){let o=t.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;let n=t.node(-1);for(let r=t.indexAfter(-1),i=t.after();r<n.childCount;r++){let o=n.child(r);if(o.childCount)return i+1;i+=o.nodeSize}}return null}function Js(t){return function(e,n){if(!Ie(e))return!1;let r=XM(js(e),t);if(r==null)return!1;if(n){let i=e.doc.resolve(r);n(e.tr.setSelection(z.between(i,RM(i))).scrollIntoView())}return!0}}function My(t,e){let n=t.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function $s(t,e){let n=t.selection;if(!(n instanceof ae))return!1;if(e){let r=t.tr,i=$e(t.schema).cell.createAndFill().content;n.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new A(i,0,0))}),r.docChanged&&e(r)}return!0}function Ey(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return qM({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function Ty(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return WM({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function ZM(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;let i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,a=[];if(o=="row")for(let l=0;l<e.childCount;l++){let c=e.child(l).content,u=l?0:Math.max(0,n-1),f=l<e.childCount-1?0:Math.max(0,r-1);(u||f)&&(c=Eu($e(s).row,new A(c,u,f)).content),a.push(c)}else if(o=="cell"||o=="header_cell")a.push(n||r?Eu($e(s).row,new A(e,n,r)).content:e);else return null;return eE(s,a)}function eE(t,e){let n=[];for(let i=0;i<e.length;i++){let o=e[i];for(let s=o.childCount-1;s>=0;s--){let{rowspan:a,colspan:l}=o.child(s).attrs;for(let c=i;c<i+a;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=e.length&&e.push(E.empty),n[i]<r){let o=$e(t).cell.createAndFill(),s=[];for(let a=n[i];a<r;a++)s.push(o);e[i]=e[i].append(E.from(s))}return{height:e.length,width:r,rows:e}}function Eu(t,e){let n=t.createAndFill();return new Cr(n).replace(0,n.content.size,e).doc}function tE({width:t,height:e,rows:n},r,i){if(t!=r){let o=[],s=[];for(let a=0;a<n.length;a++){let l=n[a],c=[];for(let u=o[a]||0,f=0;u<r;f++){let d=l.child(f%l.childCount);u+d.attrs.colspan>r&&(d=d.type.createChecked(sr(d.attrs,d.attrs.colspan,u+d.attrs.colspan-r),d.content)),c.push(d),u+=d.attrs.colspan;for(let p=1;p<d.attrs.rowspan;p++)o[a+p]=(o[a+p]||0)+d.attrs.colspan}s.push(E.from(c))}n=s,t=r}if(e!=i){let o=[];for(let s=0,a=0;s<i;s++,a++){let l=[],c=n[a%e];for(let u=0;u<c.childCount;u++){let f=c.child(u);s+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),l.push(f)}o.push(E.from(l))}n=o,e=i}return{width:t,height:e,rows:n}}function nE(t,e,n,r,i,o,s){let a=t.doc.type.schema,l=$e(a),c,u;if(i>e.width)for(let f=0,d=0;f<e.height;f++){let p=n.child(f);d+=p.nodeSize;let h=[],m;p.lastChild==null||p.lastChild.type==l.cell?m=c||(c=l.cell.createAndFill()):m=u||(u=l.header_cell.createAndFill());for(let g=e.width;g<i;g++)h.push(m);t.insert(t.mapping.slice(s).map(d-1+r),h)}if(o>e.height){let f=[];for(let h=0,m=(e.height-1)*e.width;h<Math.max(e.width,i);h++){let g=h>=e.width?!1:n.nodeAt(e.map[m+h]).type==l.header_cell;f.push(g?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}let d=l.row.create(null,E.from(f)),p=[];for(let h=e.height;h<o;h++)p.push(d);t.insert(t.mapping.slice(s).map(r+n.nodeSize-2),p)}return!!(c||u)}function sy(t,e,n,r,i,o,s,a){if(s==0||s==e.height)return!1;let l=!1;for(let c=i;c<o;c++){let u=s*e.width+c,f=e.map[u];if(e.map[u-e.width]==f){l=!0;let d=n.nodeAt(f),{top:p,left:h}=e.findCell(f);t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d.attrs,rowspan:s-p}),t.insert(t.mapping.slice(a).map(e.positionAt(s,h,n)),d.type.createAndFill({...d.attrs,rowspan:p+d.attrs.rowspan-s})),c+=d.attrs.colspan-1}}return l}function ay(t,e,n,r,i,o,s,a){if(s==0||s==e.width)return!1;let l=!1;for(let c=i;c<o;c++){let u=c*e.width+s,f=e.map[u];if(e.map[u-1]==f){l=!0;let d=n.nodeAt(f),p=e.colCount(f),h=t.mapping.slice(a).map(f+r);t.setNodeMarkup(h,null,sr(d.attrs,s-p,d.attrs.colspan-(s-p))),t.insert(h+d.nodeSize,d.type.createAndFill(sr(d.attrs,0,s-p))),c+=d.attrs.rowspan-1}}return l}function ly(t,e,n,r,i){let o=n?t.doc.nodeAt(n-1):t.doc;if(!o)throw new Error("No table found");let s=Z.get(o),{top:a,left:l}=r,c=l+i.width,u=a+i.height,f=t.tr,d=0;function p(){if(o=n?f.doc.nodeAt(n-1):f.doc,!o)throw new Error("No table found");s=Z.get(o),d=f.mapping.maps.length}nE(f,s,o,n,c,u,d)&&p(),sy(f,s,o,n,l,c,a,d)&&p(),sy(f,s,o,n,l,c,u,d)&&p(),ay(f,s,o,n,a,u,l,d)&&p(),ay(f,s,o,n,a,u,c,d)&&p();for(let h=a;h<u;h++){let m=s.positionAt(h,l,o),g=s.positionAt(h,c,o);f.replace(f.mapping.slice(d).map(m+n),f.mapping.slice(d).map(g+n),new A(i.rows[h-a],0,0))}p(),f.setSelection(new ae(f.doc.resolve(n+s.positionAt(a,l,o)),f.doc.resolve(n+s.positionAt(u-1,c-1,o)))),e(f)}var rE=Vl({ArrowLeft:_s("horiz",-1),ArrowRight:_s("horiz",1),ArrowUp:_s("vert",-1),ArrowDown:_s("vert",1),"Shift-ArrowLeft":Hs("horiz",-1),"Shift-ArrowRight":Hs("horiz",1),"Shift-ArrowUp":Hs("vert",-1),"Shift-ArrowDown":Hs("vert",1),Backspace:$s,"Mod-Backspace":$s,Delete:$s,"Mod-Delete":$s});function Vs(t,e,n){return n.eq(t.selection)?!1:(e&&e(t.tr.setSelection(n).scrollIntoView()),!0)}function _s(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection;if(o instanceof ae)return Vs(n,r,$.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;let s=vy(i,t,e);if(s==null)return!1;if(t=="horiz")return Vs(n,r,$.near(n.doc.resolve(o.head+e),e));{let a=n.doc.resolve(s),l=hy(a,t,e),c;return l?c=$.near(l,1):e<0?c=$.near(n.doc.resolve(a.before(-1)),-1):c=$.near(n.doc.resolve(a.after(-1)),1),Vs(n,r,c)}}}function Hs(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection,s;if(o instanceof ae)s=o;else{let l=vy(i,t,e);if(l==null)return!1;s=new ae(n.doc.resolve(l))}let a=hy(s.$headCell,t,e);return a?Vs(n,r,new ae(s.$anchorCell,a)):!1}}function iE(t,e){let n=t.state.doc,r=Yr(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new ae(r))),!0):!1}function oE(t,e,n){if(!Ie(t.state))return!1;let r=ZM(n),i=t.state.selection;if(i instanceof ae){r||(r={width:1,height:1,rows:[E.from(Eu($e(t.state.schema).cell,n))]});let o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),a=Z.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=tE(r,a.right-a.left,a.bottom-a.top),ly(t.state,t.dispatch,s,a,r),!0}else if(r){let o=js(t.state),s=o.start(-1);return ly(t.state,t.dispatch,s,Z.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function sE(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;let r=cy(t,e.target),i;if(e.shiftKey&&t.state.selection instanceof ae)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Yr(t.state.selection.$anchor))!=null&&((n=wu(t,e))===null||n===void 0?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(l,c){let u=wu(t,c),f=xn.getState(t.state)==null;if(!u||!vu(l,u))if(f)u=l;else return;let d=new ae(l,u);if(f||!t.state.selection.eq(d)){let p=t.state.tr.setSelection(d);f&&p.setMeta(xn,l.pos),t.dispatch(p)}}function s(){t.root.removeEventListener("mouseup",s),t.root.removeEventListener("dragstart",s),t.root.removeEventListener("mousemove",a),xn.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(xn,-1))}function a(l){let c=l,u=xn.getState(t.state),f;if(u!=null)f=t.state.doc.resolve(u);else if(cy(t,c.target)!=r&&(f=wu(t,e),!f))return s();f&&o(f,c)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",a)}function vy(t,e,n){if(!(t.state.selection instanceof z))return null;let{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){let o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){let s=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?s:null}}return null}function cy(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function wu(t,e){let n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Yr(t.state.doc.resolve(r))||Yr(t.state.doc.resolve(i))}var aE=class{constructor(t,e){this.node=t,this.defaultCellMinWidth=e,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",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Tu(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,Tu(t,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Tu(t,e,n,r,i,o){let s=0,a=!0,l=e.firstChild,c=t.firstChild;if(c){for(let f=0,d=0;f<c.childCount;f++){let{colspan:p,colwidth:h}=c.child(f).attrs;for(let m=0;m<p;m++,d++){let g=i==d?o:h&&h[m],y=g?g+"px":"";if(s+=g||r,g||(a=!1),l)l.style.width!=y&&(l.style.width=y),l=l.nextSibling;else{let x=document.createElement("col");x.style.width=y,e.appendChild(x)}}}for(;l;){var u;let f=l.nextSibling;(u=l.parentNode)===null||u===void 0||u.removeChild(l),l=f}a?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}var Qe=new ee("tableColumnResizing");function Iy({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=aE,lastColumnResizable:i=!0}={}){let o=new X({key:Qe,state:{init(s,a){var l;let c=(l=o.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews,u=$e(a.schema).table.name;return r&&c&&(c[u]=(f,d)=>new r(f,n,d)),new lE(-1,!1)},apply(s,a){return a.apply(s)}},props:{attributes:s=>{let a=Qe.getState(s);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,a)=>{cE(s,a,t,i)},mouseleave:s=>{uE(s)},mousedown:(s,a)=>{fE(s,a,e,n)}},decorations:s=>{let a=Qe.getState(s);if(a&&a.activeHandle>-1)return gE(s,a.activeHandle)},nodeViews:{}}});return o}var lE=class Ws{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){let n=this,r=e.getMeta(Qe);if(r&&r.setHandle!=null)return new Ws(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ws(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return Mu(e.doc.resolve(i))||(i=-1),new Ws(i,n.dragging)}return n}};function cE(t,e,n,r){if(!t.editable)return;let i=Qe.getState(t.state);if(i&&!i.dragging){let o=pE(e.target),s=-1;if(o){let{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=n?s=uy(t,e,"left",n):l-e.clientX<=n&&(s=uy(t,e,"right",n))}if(s!=i.activeHandle){if(!r&&s!==-1){let a=t.state.doc.resolve(s),l=a.node(-1),c=Z.get(l),u=a.start(-1);if(c.colCount(a.pos-u)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Ay(t,s)}}}function uE(t){if(!t.editable)return;let e=Qe.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Ay(t,-1)}function fE(t,e,n,r){var i;if(!t.editable)return!1;let o=(i=t.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,s=Qe.getState(t.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let a=t.state.doc.nodeAt(s.activeHandle),l=dE(t,s.activeHandle,a.attrs);t.dispatch(t.state.tr.setMeta(Qe,{setDragging:{startX:e.clientX,startWidth:l}}));function c(f){o.removeEventListener("mouseup",c),o.removeEventListener("mousemove",u);let d=Qe.getState(t.state);d?.dragging&&(hE(t,d.activeHandle,fy(d.dragging,f,n)),t.dispatch(t.state.tr.setMeta(Qe,{setDragging:null})))}function u(f){if(!f.which)return c(f);let d=Qe.getState(t.state);if(d&&d.dragging){let p=fy(d.dragging,f,n);dy(t,d.activeHandle,p,r)}}return dy(t,s.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),e.preventDefault(),!0}function dE(t,e,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=t.domAtPos(e),s=o.node.childNodes[o.offset].offsetWidth,a=n;if(r)for(let l=0;l<n;l++)r[l]&&(s-=r[l],a--);return s/a}function pE(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function uy(t,e,n,r){let i=n=="right"?-r:r,o=t.posAtCoords({left:e.clientX+i,top:e.clientY});if(!o)return-1;let{pos:s}=o,a=Yr(t.state.doc.resolve(s));if(!a)return-1;if(n=="right")return a.pos;let l=Z.get(a.node(-1)),c=a.start(-1),u=l.map.indexOf(a.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function fy(t,e,n){let r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function Ay(t,e){t.dispatch(t.state.tr.setMeta(Qe,{setHandle:e}))}function hE(t,e,n){let r=t.state.doc.resolve(e),i=r.node(-1),o=Z.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let c=0;c<o.height;c++){let u=c*o.width+a;if(c&&o.map[u]==o.map[u-o.width])continue;let f=o.map[u],d=i.nodeAt(f).attrs,p=d.colspan==1?0:a-o.colCount(f);if(d.colwidth&&d.colwidth[p]==n)continue;let h=d.colwidth?d.colwidth.slice():mE(d.colspan);h[p]=n,l.setNodeMarkup(s+f,null,{...d,colwidth:h})}l.docChanged&&t.dispatch(l)}function dy(t,e,n,r){let i=t.state.doc.resolve(e),o=i.node(-1),s=i.start(-1),a=Z.get(o).colCount(i.pos-s)+i.nodeAfter.attrs.colspan-1,l=t.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&Tu(o,l.firstChild,l,r,a,n)}function mE(t){return Array(t).fill(0)}function gE(t,e){let n=[],r=t.doc.resolve(e),i=r.node(-1);if(!i)return ne.empty;let o=Z.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<o.height;c++){let u=a+c*o.width;if((a==o.width-1||o.map[u]!=o.map[u+1])&&(c==0||o.map[u]!=o.map[u-o.width])){var l;let f=o.map[u],d=s+f+i.nodeAt(f).nodeSize-1,p=document.createElement("div");p.className="column-resize-handle",!((l=Qe.getState(t))===null||l===void 0)&&l.dragging&&n.push(se.node(s+f,s+f+i.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),n.push(se.widget(d,p))}}return ne.create(t.doc,n)}function Ny({allowTableNodeSelection:t=!1}={}){return new X({key:xn,state:{init(){return null},apply(e,n){let r=e.getMeta(xn);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;let{deleted:i,pos:o}=e.mapping.mapResult(n);return i?null:o}},props:{decorations:LM,handleDOMEvents:{mousedown:sE},createSelectionBetween(e){return xn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:iE,handleKeyDown:rE,handlePaste:oE},appendTransaction(e,n,r){return zM(r,_M(r,n),t)}})}var Gs=typeof navigator<"u"?navigator:null,Nu=Gs&&Gs.userAgent||"",yE=/Edge\/(\d+)/.exec(Nu),kE=/MSIE \d/.exec(Nu),bE=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Nu),xE=!!(kE||bE||yE),wE=!xE&&!!Gs&&/Apple Computer/.test(Gs.vendor),Ry=new ee("safari-ime-span"),Au=!1,SE={key:Ry,props:{decorations:CE,handleDOMEvents:{compositionstart:()=>{Au=!0},compositionend:()=>{Au=!1}}}};function CE(t){let{$from:e,$to:n,to:r}=t.selection;if(Au&&e.sameParent(n)){let i=se.widget(r,ME,{ignoreSelection:!0,key:"safari-ime-span"});return ne.create(t.doc,[i])}}function ME(t){let e=t.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var Oy=new X(wE?SE:{key:Ry});function Ru(t,e){let n=String(t);if(typeof e!="string")throw new TypeError("Expected character");let r=0,i=n.indexOf(e);for(;i!==-1;)r++,i=n.indexOf(e,i+e.length);return r}function Ou(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Du(t,e,n){let i=sn((n||{}).ignore||[]),o=EE(e),s=-1;for(;++s<o.length;)Dn(t,"text",a);function a(c,u){let f=-1,d;for(;++f<u.length;){let p=u[f],h=d?d.children:void 0;if(i(p,h?h.indexOf(p):void 0,d))return;d=p}if(d)return l(c,u)}function l(c,u){let f=u[u.length-1],d=o[s][0],p=o[s][1],h=0,g=f.children.indexOf(c),y=!1,x=[];d.lastIndex=0;let C=d.exec(c.value);for(;C;){let v=C.index,I={index:C.index,input:C.input,stack:[...u,c]},w=p(...C,I);if(typeof w=="string"&&(w=w.length>0?{type:"text",value:w}:void 0),w===!1?d.lastIndex=v+1:(h!==v&&x.push({type:"text",value:c.value.slice(h,v)}),Array.isArray(w)?x.push(...w):w&&x.push(w),h=v+C[0].length,y=!0),!d.global)break;C=d.exec(c.value)}return y?(h<c.value.length&&x.push({type:"text",value:c.value.slice(h)}),f.children.splice(g,1,...x)):x=[c],g+x.length}}function EE(t){let e=[];if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");let n=!t[0]||Array.isArray(t[0])?t:[t],r=-1;for(;++r<n.length;){let i=n[r];e.push([TE(i[0]),vE(i[1])])}return e}function TE(t){return typeof t=="string"?new RegExp(Ou(t),"g"):t}function vE(t){return typeof t=="function"?t:function(){return t}}var Bu="phrasing",Lu=["autolink","link","image","label"];function Fu(){return{transforms:[DE],enter:{literalAutolink:IE,literalAutolinkEmail:Pu,literalAutolinkHttp:Pu,literalAutolinkWww:Pu},exit:{literalAutolink:OE,literalAutolinkEmail:RE,literalAutolinkHttp:AE,literalAutolinkWww:NE}}}function zu(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:Bu,notInConstruct:Lu},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:Bu,notInConstruct:Lu},{character:":",before:"[ps]",after:"\\/",inConstruct:Bu,notInConstruct:Lu}]}}function IE(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function Pu(t){this.config.enter.autolinkProtocol.call(this,t)}function AE(t){this.config.exit.autolinkProtocol.call(this,t)}function NE(t){this.config.exit.data.call(this,t);let e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function RE(t){this.config.exit.autolinkEmail.call(this,t)}function OE(t){this.exit(t)}function DE(t){Du(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,BE],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,LE]],{ignore:["link","linkReference"]})}function BE(t,e,n,r,i){let o="";if(!Dy(i)||(/^w/i.test(e)&&(n=e+n,e="",o="http://"),!PE(n)))return!1;let s=FE(n+r);if(!s[0])return!1;let a={type:"link",title:null,url:o+e+s[0],children:[{type:"text",value:e+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function LE(t,e,n,r){return!Dy(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function PE(t){let e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function FE(t){let e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let n=e[0],r=n.indexOf(")"),i=Ru(t,"("),o=Ru(t,")");for(;r!==-1&&i>o;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),o++;return[t,n]}function Dy(t,e){let n=t.input.charCodeAt(t.index-1);return(t.index===0||Et(n)||vn(n))&&(!e||n!==47)}By.peek=KE;function zE(){this.buffer()}function $E(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function _E(){this.buffer()}function HE(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function VE(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ae(this.sliceSerialize(t)).toLowerCase(),n.label=e}function WE(t){this.exit(t)}function jE(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ae(this.sliceSerialize(t)).toLowerCase(),n.label=e}function qE(t){this.exit(t)}function KE(){return"["}function By(t,e,n,r){let i=n.createTracker(r),o=i.move("[^"),s=n.enter("footnoteReference"),a=n.enter("reference");return o+=i.move(n.safe(n.associationId(t),{after:"]",before:o})),a(),s(),o+=i.move("]"),o}function $u(){return{enter:{gfmFootnoteCallString:zE,gfmFootnoteCall:$E,gfmFootnoteDefinitionLabelString:_E,gfmFootnoteDefinition:HE},exit:{gfmFootnoteCallString:VE,gfmFootnoteCall:WE,gfmFootnoteDefinitionLabelString:jE,gfmFootnoteDefinition:qE}}}function _u(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:By},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,o,s){let a=o.createTracker(s),l=a.move("[^"),c=o.enter("footnoteDefinition"),u=o.enter("label");return l+=a.move(o.safe(o.associationId(r),{before:l,after:"]"})),u(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((e?` -`:" ")+o.indentLines(o.containerFlow(r,a.current()),e?Ly:UE))),c(),l}}function UE(t,e,n){return e===0?t:Ly(t,e,n)}function Ly(t,e,n){return(n?"":" ")+t}var JE=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Py.peek=YE;function Hu(){return{canContainEols:["delete"],enter:{strikethrough:GE},exit:{strikethrough:QE}}}function Vu(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:JE}],handlers:{delete:Py}}}function GE(t){this.enter({type:"delete",children:[]},t)}function QE(t){this.exit(t)}function Py(t,e,n,r){let i=n.createTracker(r),o=n.enter("strikethrough"),s=i.move("~~");return s+=n.containerPhrasing(t,{...i.current(),before:s,after:"~"}),s+=i.move("~~"),o(),s}function YE(){return"~"}function XE(t){return t.length}function zy(t,e){let n=e||{},r=(n.align||[]).concat(),i=n.stringLength||XE,o=[],s=[],a=[],l=[],c=0,u=-1;for(;++u<t.length;){let m=[],g=[],y=-1;for(t[u].length>c&&(c=t[u].length);++y<t[u].length;){let x=ZE(t[u][y]);if(n.alignDelimiters!==!1){let C=i(x);g[y]=C,(l[y]===void 0||C>l[y])&&(l[y]=C)}m.push(x)}s[u]=m,a[u]=g}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<c;)o[f]=Fy(r[f]);else{let m=Fy(r);for(;++f<c;)o[f]=m}f=-1;let d=[],p=[];for(;++f<c;){let m=o[f],g="",y="";m===99?(g=":",y=":"):m===108?g=":":m===114&&(y=":");let x=n.alignDelimiters===!1?1:Math.max(1,l[f]-g.length-y.length),C=g+"-".repeat(x)+y;n.alignDelimiters!==!1&&(x=g.length+x+y.length,x>l[f]&&(l[f]=x),p[f]=x),d[f]=C}s.splice(1,0,d),a.splice(1,0,p),u=-1;let h=[];for(;++u<s.length;){let m=s[u],g=a[u];f=-1;let y=[];for(;++f<c;){let x=m[f]||"",C="",v="";if(n.alignDelimiters!==!1){let I=l[f]-(g[f]||0),w=o[f];w===114?C=" ".repeat(I):w===99?I%2?(C=" ".repeat(I/2+.5),v=" ".repeat(I/2-.5)):(C=" ".repeat(I/2),v=C):v=" ".repeat(I)}n.delimiterStart!==!1&&!f&&y.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&x==="")&&(n.delimiterStart!==!1||f)&&y.push(" "),n.alignDelimiters!==!1&&y.push(C),y.push(x),n.alignDelimiters!==!1&&y.push(v),n.padding!==!1&&y.push(" "),(n.delimiterEnd!==!1||f!==c-1)&&y.push("|")}h.push(n.delimiterEnd===!1?y.join("").replace(/ +$/,""):y.join(""))}return h.join(` -`)}function ZE(t){return t==null?"":String(t)}function Fy(t){let e=typeof t=="string"?t.codePointAt(0):0;return e===67||e===99?99:e===76||e===108?108:e===82||e===114?114:0}function ju(){return{enter:{table:eT,tableData:$y,tableHeader:$y,tableRow:nT},exit:{codeText:rT,table:tT,tableData:Wu,tableHeader:Wu,tableRow:Wu}}}function eT(t){let e=t._align;this.enter({type:"table",align:e.map(function(n){return n==="none"?null:n}),children:[]},t),this.data.inTable=!0}function tT(t){this.exit(t),this.data.inTable=void 0}function nT(t){this.enter({type:"tableRow",children:[]},t)}function Wu(t){this.exit(t)}function $y(t){this.enter({type:"tableCell",children:[]},t)}function rT(t){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,iT));let n=this.stack[this.stack.length-1];n.type,n.value=e,this.exit(t)}function iT(t,e){return e==="|"?e:t}function qu(t){let e=t||{},n=e.tableCellPadding,r=e.tablePipeAlign,i=e.stringLength,o=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:` +`):e.addNode("break")}}}));M(ir.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});M(ir.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Xc=P("InsertHardbreak",t=>()=>(e,n)=>{let{selection:r,tr:i}=e;if(!(r instanceof z))return!1;if(r.empty){let o=r.$from.node();if(o.childCount>0&&o.lastChild?.type.name==="hardbreak")return n?.(i.replaceRangeWith(r.to-1,r.to,e.schema.node("paragraph")).setSelection($.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(i.setMeta("hardbreak",!0).replaceSelectionWith(ir.type(t).create()).scrollIntoView()),!0});M(Xc,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Zc=ze("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:t=>{let e=t.get(G);return()=>e.call(Xc.key)}}});M(Zc.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});M(Zc.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var eu=at("hr");M(eu,{displayName:"Attr<hr>",group:"Hr"});var no=ne("hr",t=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",t.get(eu.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,n,r)=>{e.addNode(r)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));M(no.node,{displayName:"NodeSchema<hr>",group:"Hr"});M(no.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var jg=fe(t=>new ke(/^(?:---|___\s|\*\*\*\s)$/,(e,n,r,i)=>{let{tr:o}=e;return n[0]&&o.replaceWith(r-1,i,no.type(t).create()),o}));M(jg,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var qg=P("InsertHr",t=>()=>(e,n)=>{if(!n)return!0;let r=kt.node.type(t).create(),{tr:i,selection:o}=e,{from:s}=o,a=no.type(t).create();if(!a)return!0;let l=i.replaceSelectionWith(a).insert(s,r),c=$.findFrom(l.doc.resolve(s),1,!0);return c&&n(l.setSelection(c).scrollIntoView()),!0});M(qg,{displayName:"Command<insertHrCommand>",group:"Hr"});var tu=at("bulletList");M(tu,{displayName:"Attr<bulletList>",group:"BulletList"});var Ur=ne("bullet_list",t=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw tt(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...t.get(tu.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"false";e.openNode(r,{spread:i}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!1,spread:n.attrs.spread}).next(n.content).closeNode()}}}));M(Ur.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});M(Ur.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var Kg=fe(t=>as(/^\s*([-+*])\s$/,Ur.type(t)));M(Kg,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var nu=P("WrapInBulletList",t=>()=>ss(Ur.type(t)));M(nu,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var ru=ze("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:t=>{let e=t.get(G);return()=>e.call(nu.key)}}});M(ru.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});M(ru.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var iu=at("orderedList");M(iu,{displayName:"Attr<orderedList>",group:"OrderedList"});var Jr=ne("ordered_list",t=>({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 tt(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...t.get(iu.key)(e),...e.attrs.order===1?{}:{start:e.attrs.order},"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:n})=>e==="list"&&!!n,runner:(e,n,r)=>{let i=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{spread:i,order:n.start??1}).next(n.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,n)=>{e.openNode("list",void 0,{ordered:!0,start:n.attrs.order??1,spread:n.attrs.spread==="true"}),e.next(n.content),e.closeNode()}}}));M(Jr.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});M(Jr.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var Ug=fe(t=>as(/^\s*(\d+)\.\s$/,Jr.type(t),e=>({order:Number(e[1])}),(e,n)=>n.childCount+n.attrs.order===Number(e[1])));M(Ug,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var ou=P("WrapInOrderedList",t=>()=>ss(Jr.type(t)));M(ou,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var su=ze("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:t=>{let e=t.get(G);return()=>e.call(ou.key)}}});M(su.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});M(su.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var au=at("listItem");M(au,{displayName:"Attr<listItem>",group:"ListItem"});var It=ne("list_item",t=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"\u2022",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw tt(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...t.get(au.key)(e),"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e})=>e==="listItem",runner:(e,n,r)=>{let i=n.label!=null?`${n.label}.`:"\u2022",o=n.label!=null?"ordered":"bullet",s=n.spread!=null?`${n.spread}`:"true";e.openNode(r,{label:i,listType:o,spread:s}),e.next(n.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,n)=>{e.openNode("listItem",void 0,{spread:n.attrs.spread}),e.next(n.content),e.closeNode()}}}));M(It.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});M(It.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var lu=P("SinkListItem",t=>()=>Ag(It.type(t)));M(lu,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var cu=P("LiftListItem",t=>()=>Ig(It.type(t)));M(cu,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var uu=P("SplitListItem",t=>()=>vg(It.type(t)));M(uu,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function lM(t){return(e,n,r)=>{let{selection:i}=e;if(!(i instanceof z))return!1;let{empty:o,$from:s}=i;return!o||s.parentOffset!==0||s.node(-1).type!==It.type(t)?!1:Nl(e,n,r)}}var fu=P("LiftFirstListItem",t=>()=>lM(t));M(fu,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var du=ze("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:t=>{let e=t.get(G);return()=>e.call(uu.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:t=>{let e=t.get(G);return()=>e.call(lu.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:t=>{let e=t.get(G);return()=>e.call(cu.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:t=>{let e=t.get(G);return()=>e.call(fu.key)}}});M(du.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});M(du.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var Jg=Bs("text",()=>({group:"inline",parseMarkdown:{match:({type:t})=>t==="text",runner:(t,e)=>{t.addText(e.value)}},toMarkdown:{match:t=>t.type.name==="text",runner:(t,e)=>{t.addNode("text",void 0,e.text)}}}));M(Jg,{displayName:"NodeSchema<text>",group:"Text"});var pu=at("html");M(pu,{displayName:"Attr<html>",group:"Html"});var hu=ne("html",t=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{let n=document.createElement("span"),r={...t.get(pu.key)(e),"data-value":e.attrs.value,"data-type":"html"};return n.textContent=e.attrs.value,["span",r,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,n,r)=>{e.addNode(r,{value:n.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,n)=>{e.addNode("html",void 0,n.attrs.value)}}}));M(hu.node,{displayName:"NodeSchema<html>",group:"Html"});M(hu.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var cM=[zg,$c,kt,zs,Vc,or,Ps,ir,qc,eo,Jc,to,eu,no,Yc,Kr,tu,Ur,iu,Jr,au,It,Ac,qr,Oc,Zi,Lc,bn,zc,jr,pu,hu,Jg].flat(),uM=[_g,Kg,Ug,Hg,jg,$g].flat(),fM=[Og,Dg,Lg,Bg],dM=P("IsMarkSelected",()=>t=>e=>{if(!t)return!1;let{doc:n,selection:r}=e;return n.rangeHasMark(r.from,r.to,t)}),pM=P("IsNoteSelected",()=>t=>e=>t?Vh(e,t).hasNode:!1),hM=P("ClearTextInCurrentBlock",()=>()=>(t,e)=>{let n=t.tr,{$from:r,$to:i}=n.selection,{pos:o}=r,{pos:s}=i,a=o-r.node().content.size;return a<0?!1:(n=n.deleteRange(a,s),e?.(n),!0)}),mM=P("SetBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr,{from:s,to:a}=o.selection;try{o.setBlockType(s,a,r,i)}catch{return!1}return n?.(o),!0}),gM=P("WrapInBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let{$from:s,$to:a}=o.selection,l=s.blockRange(a),c=l&&Hn(l,r,i);if(!c)return!1;o=o.wrap(l,c)}catch{return!1}return n?.(o),!0}),yM=P("AddBlockType",()=>t=>(e,n)=>{let{nodeType:r,attrs:i=null}=t??{};if(!r)return!1;let o=e.tr;try{let s=r instanceof He?r:r.createAndFill(i);if(!s)return!1;o.replaceSelectionWith(s)}catch{return!1}return n?.(o),!0}),kM=P("SelectTextNearPos",()=>t=>(e,n)=>{let{pos:r}=t??{};if(r==null)return!1;let i=(s,a,l)=>Math.min(Math.max(s,a),l),o=e.tr;try{let s=e.doc.resolve(i(r,0,e.doc.content.size));o.setSelection(z.near(s))}catch{return!1}return n?.(o.scrollIntoView()),!0}),bM=[_c,Kc,kn,Wc,Gc,Xc,qg,Vg,Wg,ou,nu,lu,uu,cu,fu,Nc,Pc,Dc,Pg,Fg,dM,pM,hM,mM,gM,yM,kM],xM=[Uc,Qc,Zc,jc,du,su,ru,Hc,Rc,Fc,Bc].flat(),mu=Ge("remarkAddOrderInList",()=>()=>t=>{dt(t,"list",e=>{if(e.ordered){let n=e.start??1;e.children.forEach((r,i)=>{r.label=i+n})}})});M(mu.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});M(mu.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var gu=Ge("remarkLineBreak",()=>()=>t=>{let e=/[\t ]*(?:\r?\n|\r)/g;dt(t,"text",(n,r,i)=>{if(!n.value||typeof n.value!="string")return;let o=[],s=0;e.lastIndex=0;let a=e.exec(n.value);for(;a;){let l=a.index;s!==l&&o.push({type:"text",value:n.value.slice(s,l)}),o.push({type:"break",data:{isInline:!0}}),s=l+a[0].length,a=e.exec(n.value)}if(o.length>0&&i&&typeof r=="number")return s<n.value.length&&o.push({type:"text",value:n.value.slice(s)}),i.children.splice(r,1,...o),r+o.length})});M(gu.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});M(gu.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var yu=Ge("remarkInlineLink",()=>Ls);M(yu.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});M(yu.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var wM=t=>!!t.children,SM=t=>t.type==="html";function CM(t,e){return n(t,0,null)[0];function n(r,i,o){if(wM(r)){let s=[];for(let a=0,l=r.children.length;a<l;a++){let c=r.children[a];if(c){let u=n(c,a,r);if(u)for(let f=0,d=u.length;f<d;f++){let p=u[f];p&&s.push(p)}}}r.children=s}return e(r,i,o)}}var MM=["root","blockquote","listItem"],ku=Ge("remarkHTMLTransformer",()=>()=>t=>{CM(t,(e,n,r)=>SM(e)?(r&&MM.includes(r.type)&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});M(ku.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});M(ku.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var bu=Ge("remarkMarker",()=>()=>(t,e)=>{let n=r=>e.value.charAt(r.position.start.offset);dt(t,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});M(bu.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});M(bu.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var Gg=Se(()=>{let t=!1,e=new X({key:new te("MILKDOWN_INLINE_NODES_CURSOR"),state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;let r=n.selection.$from,i=r.nodeBefore,o=r.nodeAfter;return!!(i&&o&&i.isInline&&!i.isText&&o.isInline&&!o.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>t?(t=!1,requestAnimationFrame(()=>{if(e.getState(n.state)){let i=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i))}}),!0):!1,compositionstart:n=>(e.getState(n.state)&&(t=!0),!1),beforeinput:(n,r)=>{if(e.getState(n.state)&&r instanceof InputEvent&&r.data&&!t){let i=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",i)),!0}return!1}},decorations(n){if(e.getState(n)){let r=n.selection.$from.pos,i=document.createElement("span"),o=oe.widget(r,i,{side:-1}),s=document.createElement("span"),a=oe.widget(r,s);return setTimeout(()=>{i.contentEditable="true",s.contentEditable="true"}),ee.create(n.doc,[o,a])}return ee.empty}}});return e});M(Gg,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Qg=Se(t=>new X({key:new te("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,n,r)=>{if(!e.length)return;let[i]=e;if(!i)return;let[o]=i.steps;if(i.getMeta("hardbreak")){if(!(o instanceof de))return;let{from:s}=o;return r.tr.setNodeMarkup(s,ir.type(t),void 0,[])}if(o instanceof $n){let s=r.tr,{from:a,to:l}=o;return r.doc.nodesBetween(a,l,(c,u)=>{c.type===ir.type(t)&&(s=s.setNodeMarkup(u,ir.type(t),void 0,[]))}),s}}}));M(Qg,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var xu=Je(["table","code_block"],"hardbreakFilterNodes");M(xu,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var Yg=Se(t=>{let e=t.get(xu.key);return new X({key:new te("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(n,r)=>{let i=n.getMeta("hardbreak"),[o]=n.steps;if(i&&o){let{from:s}=o,a=r.doc.resolve(s),l=a.depth,c=!0;for(;l>0;)e.includes(a.node(l).type.name)&&(c=!1),l--;return c}return!0}})});M(Yg,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var Xg=Se(t=>{let e=new te("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;let i=t.get(zs.key),o=r.state.tr.setMeta("addToHistory",!1),s=!1,a={};r.state.doc.descendants((l,c)=>{if(l.type===or.type(t)){if(l.textContent.trim().length===0)return;let u=l.attrs,f=i(l);a[f]?(a[f]+=1,f+=`-#${a[f]}`):a[f]=1,u.id!==f&&(s=!0,o.setMeta(e,!0).setNodeMarkup(c,void 0,{...u,id:f}))}}),s&&r.dispatch(o)};return new X({key:e,view:r=>(n(r),{update:(i,o)=>{i.state.doc.eq(o.doc)||n(i)}})})});M(Xg,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var Zg=Se(t=>{let e=(n,r,i)=>{if(!i.selection||n.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;let o=Jr.type(t),s=Ur.type(t),a=It.type(t),l=(f,d,p=1)=>{let h=!1,m=`${d+p}.`;return f.label!==m&&(f.label=m,h=!0),h},c=i.tr,u=!1;return i.doc.descendants((f,d,p,h)=>{if(f.type===s){let m=f.maybeChild(0);m?.type===a&&m.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(d,o,{spread:"true"}),f.descendants((g,y,x,C)=>{if(g.type===a){let v={...g.attrs};l(v,C)&&(c=c.setNodeMarkup(y,void 0,v))}return!1}))}else if(f.type===a&&p?.type===o){let m={...f.attrs},g=!1;m.listType!=="ordered"&&(m.listType="ordered",g=!0),p?.maybeChild(0)&&(g=l(m,h,p?.attrs.order??1)),g&&(c=c.setNodeMarkup(d,void 0,m),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new X({key:new te("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});M(Zg,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var EM=[Qg,xu,Yg,Gg,mu,yu,gu,ku,bu,Fs,Xg,Zg].flat(),ey=[cM,uM,fM,bM,xM,EM].flat();var Su,Cu;if(typeof WeakMap<"u"){let t=new WeakMap;Su=e=>t.get(e),Cu=(e,n)=>(t.set(e,n),n)}else{let t=[],n=0;Su=r=>{for(let i=0;i<t.length;i+=2)if(t[i]==r)return t[i+1]},Cu=(r,i)=>(n==10&&(n=0),t[n++]=r,t[n++]=i)}var Z=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e<this.map.length;e++){let n=this.map[e];if(n!=t)continue;let r=e%this.width,i=e/this.width|0,o=r+1,s=i+1;for(let a=1;o<this.width&&this.map[e+a]==n;a++)o++;for(let a=1;s<this.height&&this.map[e+this.width*a]==n;a++)s++;return{left:r,top:i,right:o,bottom:s}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){let{left:r,right:i,top:o,bottom:s}=this.findCell(t);return e=="horiz"?(n<0?r==0:i==this.width)?null:this.map[o*this.width+(n<0?r-1:i)]:(n<0?o==0:s==this.height)?null:this.map[r+this.width*(n<0?o-1:s)]}rectBetween(t,e){let{left:n,right:r,top:i,bottom:o}=this.findCell(t),{left:s,right:a,top:l,bottom:c}=this.findCell(e);return{left:Math.min(n,s),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(o,c)}}cellsInRect(t){let e=[],n={};for(let r=t.top;r<t.bottom;r++)for(let i=t.left;i<t.right;i++){let o=r*this.width+i,s=this.map[o];n[s]||(n[s]=!0,!(i==t.left&&i&&this.map[o-1]==s||r==t.top&&r&&this.map[o-this.width]==s)&&e.push(s))}return e}positionAt(t,e,n){for(let r=0,i=0;;r++){let o=i+n.child(r).nodeSize;if(r==t){let s=e+t*this.width,a=(t+1)*this.width;for(;s<a&&this.map[s]<i;)s++;return s==a?o-1:this.map[s]}i=o}}static get(t){return Su(t)||Cu(t,TM(t))}};function TM(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);let e=vM(t),n=t.childCount,r=[],i=0,o=null,s=[];for(let c=0,u=e*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){let f=t.child(c);u++;for(let h=0;;h++){for(;i<r.length&&r[i]!=0;)i++;if(h==f.childCount)break;let m=f.child(h),{colspan:g,rowspan:y,colwidth:x}=m.attrs;for(let C=0;C<y;C++){if(C+c>=n){(o||(o=[])).push({type:"overlong_rowspan",pos:u,n:y-C});break}let v=i+C*e;for(let I=0;I<g;I++){r[v+I]==0?r[v+I]=u:(o||(o=[])).push({type:"collision",row:c,pos:u,n:g-I});let w=x&&x[I];if(w){let N=(v+I)%e*2,D=s[N];D==null||D!=w&&s[N+1]==1?(s[N]=w,s[N+1]=1):D==w&&s[N+1]++}}}i+=g,u+=m.nodeSize}let d=(c+1)*e,p=0;for(;i<d;)r[i++]==0&&p++;p&&(o||(o=[])).push({type:"missing",row:c,n:p}),u++}(e===0||n===0)&&(o||(o=[])).push({type:"zero_sized"});let a=new Z(e,n,r,o),l=!1;for(let c=0;!l&&c<s.length;c+=2)s[c]!=null&&s[c+1]<n&&(l=!0);return l&&IM(a,s,t),a}function vM(t){let e=-1,n=!1;for(let r=0;r<t.childCount;r++){let i=t.child(r),o=0;if(n)for(let s=0;s<r;s++){let a=t.child(s);for(let l=0;l<a.childCount;l++){let c=a.child(l);s+c.attrs.rowspan>r&&(o+=c.attrs.colspan)}}for(let s=0;s<i.childCount;s++){let a=i.child(s);o+=a.attrs.colspan,a.attrs.rowspan>1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function IM(t,e,n){t.problems||(t.problems=[]);let r={};for(let i=0;i<t.map.length;i++){let o=t.map[i];if(r[o])continue;r[o]=!0;let s=n.nodeAt(o);if(!s)throw new RangeError(`No cell with offset ${o} found`);let a=null,l=s.attrs;for(let c=0;c<l.colspan;c++){let u=e[(i+c)%t.width*2];u!=null&&(!l.colwidth||l.colwidth[c]!=u)&&((a||(a=AM(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function AM(t){if(t.colwidth)return t.colwidth.slice();let e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function ty(t,e){if(typeof t=="string")return{};let n=t.getAttribute("data-colwidth"),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(s=>Number(s)):null,i=Number(t.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let a=e[s].getFromDOM,l=a&&a(t);l!=null&&(o[s]=l)}return o}function ny(t,e){let n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan),t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan),t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(t.attrs[r],n)}return n}function NM(t){if(t!==null){if(!Array.isArray(t))throw new TypeError("colwidth must be null or an array");for(let e of t)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function hy(t){let e=t.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:NM}};for(let r in e)n[r]={default:e[r].default,validate:e[r].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:t.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:t.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>ty(r,e)}],toDOM(r){return["td",ny(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ty(r,e)}],toDOM(r){return["th",ny(r,e),0]}}}}function $e(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(let n in t.nodes){let r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var xn=new te("selectingCells");function Yr(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function Ie(t){let e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function js(t){let e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let n=Yr(e.$head)||RM(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function RM(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function Mu(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function OM(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function vu(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function my(t,e,n){let r=t.node(-1),i=Z.get(r),o=t.start(-1),s=i.nextCell(t.pos-o,e,n);return s==null?null:t.node(0).resolve(o+s)}function sr(t,e,n=1){let r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function DM(t,e,n=1){let r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(e,0,0)}return r}function BM(t,e,n){let r=$e(e.type.schema).header_cell;for(let i=0;i<t.height;i++)if(e.nodeAt(t.map[n+i*t.width]).type!=r)return!1;return!0}var ae=class Qt extends ${constructor(e,n=e){let r=e.node(-1),i=Z.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,n.pos-o),a=e.node(0),l=i.cellsInRect(s).filter(u=>u!=n.pos-o);l.unshift(n.pos-o);let c=l.map(u=>{let f=r.nodeAt(u);if(!f)throw new RangeError(`No cell with offset ${u} found`);let d=o+u+1;return new un(a.resolve(d),a.resolve(d+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){let r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(Mu(r)&&Mu(i)&&vu(r,i)){let o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Qt.rowSelection(r,i):o&&this.isColSelection()?Qt.colSelection(r,i):new Qt(r,i)}return z.between(r,i)}content(){let e=this.$anchorCell.node(-1),n=Z.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let l=i.top;l<i.bottom;l++){let c=[];for(let u=l*n.width+i.left,f=i.left;f<i.right;f++,u++){let d=n.map[u];if(o[d])continue;o[d]=!0;let p=n.findCell(d),h=e.nodeAt(d);if(!h)throw new RangeError(`No cell with offset ${d} found`);let m=i.left-p.left,g=p.right-i.right;if(m>0||g>0){let y=h.attrs;if(m>0&&(y=sr(y,0,m)),g>0&&(y=sr(y,y.colspan-g,g)),p.left<i.left){if(h=h.type.createAndFill(y),!h)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else h=h.type.create(y,h.content)}if(p.top<i.top||p.bottom>i.bottom){let y={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top<i.top?h=h.type.createAndFill(y):h=h.type.create(y,h.content)}c.push(h)}s.push(e.child(l).copy(E.from(c)))}let a=this.isColSelection()&&this.isRowSelection()?e:s;return new A(E.from(a),1,1)}replace(e,n=A.empty){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:a,$to:l}=i[s],c=e.mapping.slice(r);e.replace(c.map(a.pos),c.map(l.pos),s?A.empty:n)}let o=$.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);o&&e.setSelection(o)}replaceWith(e,n){this.replace(e,new A(E.from(n),0,0))}forEachCell(e){let n=this.$anchorCell.node(-1),r=Z.get(n),i=this.$anchorCell.start(-1),o=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let s=0;s<o.length;s++)e(n.nodeAt(o[s]),i+o[s])}isColSelection(){let e=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(e,n)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){let r=e.node(-1),i=Z.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.top<=a.top?(s.top>0&&(e=l.resolve(o+i.map[s.left])),a.bottom<i.height&&(n=l.resolve(o+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(o+i.map[a.left])),s.bottom<i.height&&(e=l.resolve(o+i.map[i.width*(i.height-1)+s.right-1]))),new Qt(e,n)}isRowSelection(){let e=this.$anchorCell.node(-1),n=Z.get(e),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),o=n.colCount(this.$headCell.pos-r);if(Math.min(i,o)>0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,a=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,a)==n.width}eq(e){return e instanceof Qt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){let r=e.node(-1),i=Z.get(r),o=e.start(-1),s=i.findCell(e.pos-o),a=i.findCell(n.pos-o),l=e.node(0);return s.left<=a.left?(s.left>0&&(e=l.resolve(o+i.map[s.top*i.width])),a.right<i.width&&(n=l.resolve(o+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(o+i.map[a.top*i.width])),s.right<i.width&&(e=l.resolve(o+i.map[i.width*(s.top+1)-1]))),new Qt(e,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,n){return new Qt(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){return new Qt(e.resolve(n),e.resolve(r))}getBookmark(){return new LM(this.$anchorCell.pos,this.$headCell.pos)}};ae.prototype.visible=!1;$.jsonID("cell",ae);var LM=class gy{constructor(e,n){this.anchor=e,this.head=n}map(e){return new gy(e.map(this.anchor),e.map(this.head))}resolve(e){let n=e.resolve(this.anchor),r=e.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&vu(n,r)?new ae(n,r):$.near(r,1)}};function PM(t){if(!(t.selection instanceof ae))return null;let e=[];return t.selection.forEachCell((n,r)=>{e.push(oe.node(r,r+n.nodeSize,{class:"selectedCell"}))}),ee.create(t.doc,e)}function FM({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let n=t.pos,r=e.pos,i=t.depth;for(;i>=0&&!(t.after(i+1)<t.end(i));i--,n++);for(let o=e.depth;o>=0&&!(e.before(o+1)>e.start(o));o--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function zM({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){let o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&e.parentOffset===0}function $M(t,e,n){let r=(e||t).selection,i=(e||t).doc,o,s;if(r instanceof H&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=ae.create(i,r.from);else if(s=="row"){let a=i.resolve(r.from+1);o=ae.rowSelection(a,a)}else if(!n){let a=Z.get(r.node),l=r.from+1,c=l+a.map[a.width*a.height-1];o=ae.create(i,l+1,c)}}else r instanceof z&&FM(r)?o=z.create(i,r.from):r instanceof z&&zM(r)&&(o=z.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var _M=new te("fix-tables");function yy(t,e,n,r){let i=t.childCount,o=e.childCount;e:for(let s=0,a=0;s<o;s++){let l=e.child(s);for(let c=a,u=Math.min(i,s+3);c<u;c++)if(t.child(c)==l){a=c+1,n+=l.nodeSize;continue e}r(l,n),a<i&&t.child(a).sameMarkup(l)?yy(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function HM(t,e){let n,r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=VM(t,i,o,n))};return e?e.doc!=t.doc&&yy(e.doc,t.doc,0,r):t.doc.descendants(r),n}function VM(t,e,n,r){let i=Z.get(e);if(!i.problems)return r;r||(r=t.tr);let o=[];for(let l=0;l<i.height;l++)o.push(0);for(let l=0;l<i.problems.length;l++){let c=i.problems[l];if(c.type=="collision"){let u=e.nodeAt(c.pos);if(!u)continue;let f=u.attrs;for(let d=0;d<f.rowspan;d++)o[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,sr(f,f.colspan-c.n,c.n))}else if(c.type=="missing")o[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){let u=r.mapping.map(n);r.delete(u,u+e.nodeSize)}}let s,a;for(let l=0;l<o.length;l++)o[l]&&(s==null&&(s=l),a=l);for(let l=0,c=n+1;l<i.height;l++){let u=e.child(l),f=c+u.nodeSize,d=o[l];if(d>0){let p="cell";u.firstChild&&(p=u.firstChild.type.spec.tableRole);let h=[];for(let g=0;g<d;g++){let y=$e(t.schema)[p].createAndFill();y&&h.push(y)}let m=(l==0||s==l-1)&&a==l?c+1:f-1;r.insert(r.mapping.map(m),h)}c=f}return r.setMeta(_M,{fixTables:!0})}function ky(t){let e=Z.get(t),n=[],r=e.height,i=e.width;for(let o=0;o<r;o++){let s=[];for(let a=0;a<i;a++){let l=o*i+a,c=e.map[l];if(o>0){let u=l-i;if(c===e.map[u]){s.push(null);continue}}if(a>0){let u=l-1;if(c===e.map[u]){s.push(null);continue}}s.push(t.nodeAt(c))}n.push(s)}return n}function by(t,e){let n=[],r=Z.get(t),i=r.height,o=r.width;for(let s=0;s<i;s++){let a=t.child(s),l=[];for(let u=0;u<o;u++){let f=e[s][u];if(!f)continue;let d=r.map[s*r.width+u],p=t.nodeAt(d);if(!p)continue;let h=p.type.createChecked(f.attrs,f.content,f.marks);l.push(h)}let c=a.type.createChecked(a.attrs,l,a.marks);n.push(c)}return t.type.createChecked(t.attrs,n,t.marks)}function xy(t,e,n,r){let i=e[0]>n[0]?-1:1,o=t.splice(e[0],e.length),s=o.length%2===0?1:0,a;return r===-1&&i===1?a=n[0]-1:r===1&&i===-1?a=n[n.length-1]-s+1:a=i===-1?n[0]:n[n.length-1]-s,t.splice(a,0,...o),t}function Xr(t){return WM(e=>e.type.spec.tableRole==="table",t)}function WM(t,e){for(let n=e.depth;n>=0;n-=1){let r=e.node(n);if(t(r))return{node:r,pos:n===0?0:e.before(n),start:e.start(n),depth:n}}return null}function Gr(t,e){let n=Xr(e.$from);if(!n)return;let r=Z.get(n.node);if(!(t<0||t>r.width-1))return r.cellsInRect({left:t,right:t+1,top:0,bottom:r.height}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function Qr(t,e){let n=Xr(e.$from);if(!n)return;let r=Z.get(n.node);if(!(t<0||t>r.height-1))return r.cellsInRect({left:0,right:r.width,top:t,bottom:t+1}).map(i=>{let o=n.node.nodeAt(i),s=i+n.start;return{pos:s,start:s+1,node:o,depth:n.depth+2}})}function ry(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Gr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Gr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.colspan+u-1;d.node.attrs.colspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Gr(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Gr(r,t.selection),a=Qr(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Gr(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function iy(t,e,n=e){let r=e,i=n;for(let u=e;u>=0;u--){let f=Qr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;p>=r&&(r=u),p>i&&(i=p)})}for(let u=e;u<=i;u++){let f=Qr(u,t.selection);f&&f.forEach(d=>{let p=d.node.attrs.rowspan+u-1;d.node.attrs.rowspan>1&&p>i&&(i=p)})}let o=[];for(let u=r;u<=i;u++){let f=Qr(u,t.selection);f&&f.length>0&&o.push(u)}r=o[0],i=o[o.length-1];let s=Qr(r,t.selection),a=Gr(0,t.selection);if(!s||!a)return;let l=t.doc.resolve(s[s.length-1].pos),c;for(let u=i;u>=r;u--){let f=Qr(u,t.selection);if(f&&f.length>0){for(let d=a.length-1;d>=0;d--)if(a[d].pos===f[0].pos){c=f[0];break}if(c)break}}if(c)return{$anchor:l,$head:t.doc.resolve(c.pos),indexes:o}}function oy(t){return t[0].map((e,n)=>t.map(r=>r[n]))}function jM(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Xr(r.doc.resolve(a));if(!l)return!1;let c=(e=ry(r,i))===null||e===void 0?void 0:e.indexes,u=(n=ry(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=qM(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=Z.get(f),p=l.start,h=o,m=d.positionAt(d.height-1,h,f),g=r.doc.resolve(p+m),y=d.positionAt(0,h,f),x=r.doc.resolve(p+y);return r.setSelection(ae.colSelection(g,x)),!0}function qM(t,e,n,r){let i=oy(ky(t));return i=xy(i,e,n,r),i=oy(i),by(t,i)}function KM(t){var e,n;let{tr:r,originIndex:i,targetIndex:o,select:s,pos:a}=t,l=Xr(r.doc.resolve(a));if(!l)return!1;let c=(e=iy(r,i))===null||e===void 0?void 0:e.indexes,u=(n=iy(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=UM(l.node,c,u,0);if(r.replaceWith(l.pos,l.pos+l.node.nodeSize,f),!s)return!0;let d=Z.get(f),p=l.start,h=o,m=d.positionAt(h,d.width-1,f),g=r.doc.resolve(p+m),y=d.positionAt(h,0,f),x=r.doc.resolve(p+y);return r.setSelection(ae.rowSelection(g,x)),!0}function UM(t,e,n,r){let i=ky(t);return i=xy(i,e,n,r),by(t,i)}function bt(t){let e=t.selection,n=js(t),r=n.node(-1),i=n.start(-1),o=Z.get(r);return{...e instanceof ae?o.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o.findCell(n.pos-i),tableStart:i,map:o,table:r}}function wy(t,{map:e,tableStart:n,table:r},i){let o=i>0?-1:0;BM(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s<e.height;s++){let a=s*e.width+i;if(i>0&&i<e.width&&e.map[a-1]==e.map[a]){let l=e.map[a],c=r.nodeAt(l);t.setNodeMarkup(t.mapping.map(n+l),null,DM(c.attrs,i-e.colCount(l))),s+=c.attrs.rowspan-1}else{let l=o==null?$e(r.type.schema).cell:r.nodeAt(e.map[a+o]).type,c=e.positionAt(s,i,r);t.insert(t.mapping.map(n+c),l.createAndFill())}}return t}function Sy(t,e){if(!Ie(t))return!1;if(e){let n=bt(t);e(wy(t.tr,n,n.left))}return!0}function qs(t,e){if(!Ie(t))return!1;if(e){let n=bt(t);e(wy(t.tr,n,n.right))}return!0}function JM(t,{map:e,table:n,tableStart:r},i){let o=t.mapping.maps.length;for(let s=0;s<e.height;){let a=s*e.width+i,l=e.map[a],c=n.nodeAt(l),u=c.attrs;if(i>0&&e.map[a-1]==l||i<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(o).map(r+l),null,sr(u,i-e.colCount(l)));else{let f=t.mapping.slice(o).map(r+l);t.delete(f,f+c.nodeSize)}s+=u.rowspan}}function Ks(t,e){if(!Ie(t))return!1;if(e){let n=bt(t),r=t.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;JM(r,n,i),i!=n.left;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=Z.get(o)}e(r)}return!0}function GM(t,e,n){var r;let i=$e(e.type.schema).header_cell;for(let o=0;o<t.width;o++)if(((r=e.nodeAt(t.map[o+n*t.width]))===null||r===void 0?void 0:r.type)!=i)return!1;return!0}function QM(t,{map:e,tableStart:n,table:r},i){let o=n;for(let c=0;c<i;c++)o+=r.child(c).nodeSize;let s=[],a=i>0?-1:0;GM(e,r,i+a)&&(a=i==0||i==e.height?null:0);for(let c=0,u=e.width*i;c<e.width;c++,u++)if(i>0&&i<e.height&&e.map[u]==e.map[u-e.width]){let f=e.map[u],d=r.nodeAt(f).attrs;t.setNodeMarkup(n+f,null,{...d,rowspan:d.rowspan+1}),c+=d.colspan-1}else{var l;let f=a==null?$e(r.type.schema).cell:(l=r.nodeAt(e.map[u+a*e.width]))===null||l===void 0?void 0:l.type,d=f?.createAndFill();d&&s.push(d)}return t.insert(o,$e(r.type.schema).row.create(null,s)),t}function Cy(t,e){if(!Ie(t))return!1;if(e){let n=bt(t);e(QM(t.tr,n,n.bottom))}return!0}function YM(t,{map:e,table:n,tableStart:r},i){let o=0;for(let c=0;c<i;c++)o+=n.child(c).nodeSize;let s=o+n.child(i).nodeSize,a=t.mapping.maps.length;t.delete(o+r,s+r);let l=new Set;for(let c=0,u=i*e.width;c<e.width;c++,u++){let f=e.map[u];if(!l.has(f)){if(l.add(f),i>0&&f==e.map[u-e.width]){let d=n.nodeAt(f).attrs;t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d,rowspan:d.rowspan-1}),c+=d.colspan-1}else if(i<e.height&&f==e.map[u+e.width]){let d=n.nodeAt(f),p=d.attrs,h=d.type.create({...p,rowspan:d.attrs.rowspan-1},d.content),m=e.positionAt(i+1,c,n);t.insert(t.mapping.slice(a).map(r+m),h),c+=p.colspan-1}}}}function Us(t,e){if(!Ie(t))return!1;if(e){let n=bt(t),r=t.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;YM(r,n,i),i!=n.top;i--){let o=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!o)throw new RangeError("No table found");n.table=o,n.map=Z.get(n.table)}e(r)}return!0}function My(t,e){return function(n,r){if(!Ie(n))return!1;let i=js(n);if(i.nodeAfter.attrs[t]===e)return!1;if(r){let o=n.tr;n.selection instanceof ae?n.selection.forEachCell((s,a)=>{s.attrs[t]!==e&&o.setNodeMarkup(a,null,{...s.attrs,[t]:e})}):o.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[t]:e}),r(o)}return!0}}function XM(t){return function(e,n){if(!Ie(e))return!1;if(n){let r=$e(e.schema),i=bt(e),o=e.tr,s=i.map.cellsInRect(t=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:t=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=s.map(l=>i.table.nodeAt(l));for(let l=0;l<s.length;l++)a[l].type==r.header_cell&&o.setNodeMarkup(i.tableStart+s[l],r.cell,a[l].attrs);if(o.steps.length===0)for(let l=0;l<s.length;l++)o.setNodeMarkup(i.tableStart+s[l],r.header_cell,a[l].attrs);n(o)}return!0}}function sy(t,e,n){let r=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let i=0;i<r.length;i++){let o=e.table.nodeAt(r[i]);if(o&&o.type!==n.header_cell)return!1}return!0}function Iu(t,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?XM(t):function(n,r){if(!Ie(n))return!1;if(r){let i=$e(n.schema),o=bt(n),s=n.tr,a=sy("row",o,i),l=sy("column",o,i),c=(t==="column"?a:t==="row"&&l)?1:0,u=t=="column"?{left:0,top:c,right:1,bottom:o.map.height}:t=="row"?{left:c,top:0,right:o.map.width,bottom:1}:o,f=t=="column"?l?i.cell:i.header_cell:t=="row"?a?i.cell:i.header_cell:i.cell;o.map.cellsInRect(u).forEach(d=>{let p=d+o.tableStart,h=s.doc.nodeAt(p);h&&s.setNodeMarkup(p,f,h.attrs)}),r(s)}return!0}}var zz=Iu("row",{useDeprecatedLogic:!0}),$z=Iu("column",{useDeprecatedLogic:!0}),_z=Iu("cell",{useDeprecatedLogic:!0});function ZM(t,e){if(e<0){let n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,i=t.before();r>=0;r--){let o=t.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;let n=t.node(-1);for(let r=t.indexAfter(-1),i=t.after();r<n.childCount;r++){let o=n.child(r);if(o.childCount)return i+1;i+=o.nodeSize}}return null}function Js(t){return function(e,n){if(!Ie(e))return!1;let r=ZM(js(e),t);if(r==null)return!1;if(n){let i=e.doc.resolve(r);n(e.tr.setSelection(z.between(i,OM(i))).scrollIntoView())}return!0}}function Ey(t,e){let n=t.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function $s(t,e){let n=t.selection;if(!(n instanceof ae))return!1;if(e){let r=t.tr,i=$e(t.schema).cell.createAndFill().content;n.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new A(i,0,0))}),r.docChanged&&e(r)}return!0}function Ty(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return KM({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function vy(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return jM({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function eE(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;let i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,a=[];if(o=="row")for(let l=0;l<e.childCount;l++){let c=e.child(l).content,u=l?0:Math.max(0,n-1),f=l<e.childCount-1?0:Math.max(0,r-1);(u||f)&&(c=Eu($e(s).row,new A(c,u,f)).content),a.push(c)}else if(o=="cell"||o=="header_cell")a.push(n||r?Eu($e(s).row,new A(e,n,r)).content:e);else return null;return tE(s,a)}function tE(t,e){let n=[];for(let i=0;i<e.length;i++){let o=e[i];for(let s=o.childCount-1;s>=0;s--){let{rowspan:a,colspan:l}=o.child(s).attrs;for(let c=i;c<i+a;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=e.length&&e.push(E.empty),n[i]<r){let o=$e(t).cell.createAndFill(),s=[];for(let a=n[i];a<r;a++)s.push(o);e[i]=e[i].append(E.from(s))}return{height:e.length,width:r,rows:e}}function Eu(t,e){let n=t.createAndFill();return new Cr(n).replace(0,n.content.size,e).doc}function nE({width:t,height:e,rows:n},r,i){if(t!=r){let o=[],s=[];for(let a=0;a<n.length;a++){let l=n[a],c=[];for(let u=o[a]||0,f=0;u<r;f++){let d=l.child(f%l.childCount);u+d.attrs.colspan>r&&(d=d.type.createChecked(sr(d.attrs,d.attrs.colspan,u+d.attrs.colspan-r),d.content)),c.push(d),u+=d.attrs.colspan;for(let p=1;p<d.attrs.rowspan;p++)o[a+p]=(o[a+p]||0)+d.attrs.colspan}s.push(E.from(c))}n=s,t=r}if(e!=i){let o=[];for(let s=0,a=0;s<i;s++,a++){let l=[],c=n[a%e];for(let u=0;u<c.childCount;u++){let f=c.child(u);s+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),l.push(f)}o.push(E.from(l))}n=o,e=i}return{width:t,height:e,rows:n}}function rE(t,e,n,r,i,o,s){let a=t.doc.type.schema,l=$e(a),c,u;if(i>e.width)for(let f=0,d=0;f<e.height;f++){let p=n.child(f);d+=p.nodeSize;let h=[],m;p.lastChild==null||p.lastChild.type==l.cell?m=c||(c=l.cell.createAndFill()):m=u||(u=l.header_cell.createAndFill());for(let g=e.width;g<i;g++)h.push(m);t.insert(t.mapping.slice(s).map(d-1+r),h)}if(o>e.height){let f=[];for(let h=0,m=(e.height-1)*e.width;h<Math.max(e.width,i);h++){let g=h>=e.width?!1:n.nodeAt(e.map[m+h]).type==l.header_cell;f.push(g?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}let d=l.row.create(null,E.from(f)),p=[];for(let h=e.height;h<o;h++)p.push(d);t.insert(t.mapping.slice(s).map(r+n.nodeSize-2),p)}return!!(c||u)}function ay(t,e,n,r,i,o,s,a){if(s==0||s==e.height)return!1;let l=!1;for(let c=i;c<o;c++){let u=s*e.width+c,f=e.map[u];if(e.map[u-e.width]==f){l=!0;let d=n.nodeAt(f),{top:p,left:h}=e.findCell(f);t.setNodeMarkup(t.mapping.slice(a).map(f+r),null,{...d.attrs,rowspan:s-p}),t.insert(t.mapping.slice(a).map(e.positionAt(s,h,n)),d.type.createAndFill({...d.attrs,rowspan:p+d.attrs.rowspan-s})),c+=d.attrs.colspan-1}}return l}function ly(t,e,n,r,i,o,s,a){if(s==0||s==e.width)return!1;let l=!1;for(let c=i;c<o;c++){let u=c*e.width+s,f=e.map[u];if(e.map[u-1]==f){l=!0;let d=n.nodeAt(f),p=e.colCount(f),h=t.mapping.slice(a).map(f+r);t.setNodeMarkup(h,null,sr(d.attrs,s-p,d.attrs.colspan-(s-p))),t.insert(h+d.nodeSize,d.type.createAndFill(sr(d.attrs,0,s-p))),c+=d.attrs.rowspan-1}}return l}function cy(t,e,n,r,i){let o=n?t.doc.nodeAt(n-1):t.doc;if(!o)throw new Error("No table found");let s=Z.get(o),{top:a,left:l}=r,c=l+i.width,u=a+i.height,f=t.tr,d=0;function p(){if(o=n?f.doc.nodeAt(n-1):f.doc,!o)throw new Error("No table found");s=Z.get(o),d=f.mapping.maps.length}rE(f,s,o,n,c,u,d)&&p(),ay(f,s,o,n,l,c,a,d)&&p(),ay(f,s,o,n,l,c,u,d)&&p(),ly(f,s,o,n,a,u,l,d)&&p(),ly(f,s,o,n,a,u,c,d)&&p();for(let h=a;h<u;h++){let m=s.positionAt(h,l,o),g=s.positionAt(h,c,o);f.replace(f.mapping.slice(d).map(m+n),f.mapping.slice(d).map(g+n),new A(i.rows[h-a],0,0))}p(),f.setSelection(new ae(f.doc.resolve(n+s.positionAt(a,l,o)),f.doc.resolve(n+s.positionAt(u-1,c-1,o)))),e(f)}var iE=Vl({ArrowLeft:_s("horiz",-1),ArrowRight:_s("horiz",1),ArrowUp:_s("vert",-1),ArrowDown:_s("vert",1),"Shift-ArrowLeft":Hs("horiz",-1),"Shift-ArrowRight":Hs("horiz",1),"Shift-ArrowUp":Hs("vert",-1),"Shift-ArrowDown":Hs("vert",1),Backspace:$s,"Mod-Backspace":$s,Delete:$s,"Mod-Delete":$s});function Vs(t,e,n){return n.eq(t.selection)?!1:(e&&e(t.tr.setSelection(n).scrollIntoView()),!0)}function _s(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection;if(o instanceof ae)return Vs(n,r,$.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;let s=Iy(i,t,e);if(s==null)return!1;if(t=="horiz")return Vs(n,r,$.near(n.doc.resolve(o.head+e),e));{let a=n.doc.resolve(s),l=my(a,t,e),c;return l?c=$.near(l,1):e<0?c=$.near(n.doc.resolve(a.before(-1)),-1):c=$.near(n.doc.resolve(a.after(-1)),1),Vs(n,r,c)}}}function Hs(t,e){return(n,r,i)=>{if(!i)return!1;let o=n.selection,s;if(o instanceof ae)s=o;else{let l=Iy(i,t,e);if(l==null)return!1;s=new ae(n.doc.resolve(l))}let a=my(s.$headCell,t,e);return a?Vs(n,r,new ae(s.$anchorCell,a)):!1}}function oE(t,e){let n=t.state.doc,r=Yr(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new ae(r))),!0):!1}function sE(t,e,n){if(!Ie(t.state))return!1;let r=eE(n),i=t.state.selection;if(i instanceof ae){r||(r={width:1,height:1,rows:[E.from(Eu($e(t.state.schema).cell,n))]});let o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),a=Z.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=nE(r,a.right-a.left,a.bottom-a.top),cy(t.state,t.dispatch,s,a,r),!0}else if(r){let o=js(t.state),s=o.start(-1);return cy(t.state,t.dispatch,s,Z.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function aE(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;let r=uy(t,e.target),i;if(e.shiftKey&&t.state.selection instanceof ae)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Yr(t.state.selection.$anchor))!=null&&((n=wu(t,e))===null||n===void 0?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(l,c){let u=wu(t,c),f=xn.getState(t.state)==null;if(!u||!vu(l,u))if(f)u=l;else return;let d=new ae(l,u);if(f||!t.state.selection.eq(d)){let p=t.state.tr.setSelection(d);f&&p.setMeta(xn,l.pos),t.dispatch(p)}}function s(){t.root.removeEventListener("mouseup",s),t.root.removeEventListener("dragstart",s),t.root.removeEventListener("mousemove",a),xn.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(xn,-1))}function a(l){let c=l,u=xn.getState(t.state),f;if(u!=null)f=t.state.doc.resolve(u);else if(uy(t,c.target)!=r&&(f=wu(t,e),!f))return s();f&&o(f,c)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",a)}function Iy(t,e,n){if(!(t.state.selection instanceof z))return null;let{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){let o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){let s=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?s:null}}return null}function uy(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function wu(t,e){let n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Yr(t.state.doc.resolve(r))||Yr(t.state.doc.resolve(i))}var lE=class{constructor(t,e){this.node=t,this.defaultCellMinWidth=e,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",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Tu(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,Tu(t,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Tu(t,e,n,r,i,o){let s=0,a=!0,l=e.firstChild,c=t.firstChild;if(c){for(let f=0,d=0;f<c.childCount;f++){let{colspan:p,colwidth:h}=c.child(f).attrs;for(let m=0;m<p;m++,d++){let g=i==d?o:h&&h[m],y=g?g+"px":"";if(s+=g||r,g||(a=!1),l)l.style.width!=y&&(l.style.width=y),l=l.nextSibling;else{let x=document.createElement("col");x.style.width=y,e.appendChild(x)}}}for(;l;){var u;let f=l.nextSibling;(u=l.parentNode)===null||u===void 0||u.removeChild(l),l=f}a?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}var Qe=new te("tableColumnResizing");function Ay({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=lE,lastColumnResizable:i=!0}={}){let o=new X({key:Qe,state:{init(s,a){var l;let c=(l=o.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews,u=$e(a.schema).table.name;return r&&c&&(c[u]=(f,d)=>new r(f,n,d)),new cE(-1,!1)},apply(s,a){return a.apply(s)}},props:{attributes:s=>{let a=Qe.getState(s);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,a)=>{uE(s,a,t,i)},mouseleave:s=>{fE(s)},mousedown:(s,a)=>{dE(s,a,e,n)}},decorations:s=>{let a=Qe.getState(s);if(a&&a.activeHandle>-1)return yE(s,a.activeHandle)},nodeViews:{}}});return o}var cE=class Ws{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){let n=this,r=e.getMeta(Qe);if(r&&r.setHandle!=null)return new Ws(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ws(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return Mu(e.doc.resolve(i))||(i=-1),new Ws(i,n.dragging)}return n}};function uE(t,e,n,r){if(!t.editable)return;let i=Qe.getState(t.state);if(i&&!i.dragging){let o=hE(e.target),s=-1;if(o){let{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=n?s=fy(t,e,"left",n):l-e.clientX<=n&&(s=fy(t,e,"right",n))}if(s!=i.activeHandle){if(!r&&s!==-1){let a=t.state.doc.resolve(s),l=a.node(-1),c=Z.get(l),u=a.start(-1);if(c.colCount(a.pos-u)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Ny(t,s)}}}function fE(t){if(!t.editable)return;let e=Qe.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Ny(t,-1)}function dE(t,e,n,r){var i;if(!t.editable)return!1;let o=(i=t.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,s=Qe.getState(t.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let a=t.state.doc.nodeAt(s.activeHandle),l=pE(t,s.activeHandle,a.attrs);t.dispatch(t.state.tr.setMeta(Qe,{setDragging:{startX:e.clientX,startWidth:l}}));function c(f){o.removeEventListener("mouseup",c),o.removeEventListener("mousemove",u);let d=Qe.getState(t.state);d?.dragging&&(mE(t,d.activeHandle,dy(d.dragging,f,n)),t.dispatch(t.state.tr.setMeta(Qe,{setDragging:null})))}function u(f){if(!f.which)return c(f);let d=Qe.getState(t.state);if(d&&d.dragging){let p=dy(d.dragging,f,n);py(t,d.activeHandle,p,r)}}return py(t,s.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),e.preventDefault(),!0}function pE(t,e,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=t.domAtPos(e),s=o.node.childNodes[o.offset].offsetWidth,a=n;if(r)for(let l=0;l<n;l++)r[l]&&(s-=r[l],a--);return s/a}function hE(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function fy(t,e,n,r){let i=n=="right"?-r:r,o=t.posAtCoords({left:e.clientX+i,top:e.clientY});if(!o)return-1;let{pos:s}=o,a=Yr(t.state.doc.resolve(s));if(!a)return-1;if(n=="right")return a.pos;let l=Z.get(a.node(-1)),c=a.start(-1),u=l.map.indexOf(a.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function dy(t,e,n){let r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function Ny(t,e){t.dispatch(t.state.tr.setMeta(Qe,{setHandle:e}))}function mE(t,e,n){let r=t.state.doc.resolve(e),i=r.node(-1),o=Z.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let c=0;c<o.height;c++){let u=c*o.width+a;if(c&&o.map[u]==o.map[u-o.width])continue;let f=o.map[u],d=i.nodeAt(f).attrs,p=d.colspan==1?0:a-o.colCount(f);if(d.colwidth&&d.colwidth[p]==n)continue;let h=d.colwidth?d.colwidth.slice():gE(d.colspan);h[p]=n,l.setNodeMarkup(s+f,null,{...d,colwidth:h})}l.docChanged&&t.dispatch(l)}function py(t,e,n,r){let i=t.state.doc.resolve(e),o=i.node(-1),s=i.start(-1),a=Z.get(o).colCount(i.pos-s)+i.nodeAfter.attrs.colspan-1,l=t.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&Tu(o,l.firstChild,l,r,a,n)}function gE(t){return Array(t).fill(0)}function yE(t,e){let n=[],r=t.doc.resolve(e),i=r.node(-1);if(!i)return ee.empty;let o=Z.get(i),s=r.start(-1),a=o.colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<o.height;c++){let u=a+c*o.width;if((a==o.width-1||o.map[u]!=o.map[u+1])&&(c==0||o.map[u]!=o.map[u-o.width])){var l;let f=o.map[u],d=s+f+i.nodeAt(f).nodeSize-1,p=document.createElement("div");p.className="column-resize-handle",!((l=Qe.getState(t))===null||l===void 0)&&l.dragging&&n.push(oe.node(s+f,s+f+i.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),n.push(oe.widget(d,p))}}return ee.create(t.doc,n)}function Ry({allowTableNodeSelection:t=!1}={}){return new X({key:xn,state:{init(){return null},apply(e,n){let r=e.getMeta(xn);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;let{deleted:i,pos:o}=e.mapping.mapResult(n);return i?null:o}},props:{decorations:PM,handleDOMEvents:{mousedown:aE},createSelectionBetween(e){return xn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:oE,handleKeyDown:iE,handlePaste:sE},appendTransaction(e,n,r){return $M(r,HM(r,n),t)}})}var Gs=typeof navigator<"u"?navigator:null,Nu=Gs&&Gs.userAgent||"",kE=/Edge\/(\d+)/.exec(Nu),bE=/MSIE \d/.exec(Nu),xE=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Nu),wE=!!(bE||xE||kE),SE=!wE&&!!Gs&&/Apple Computer/.test(Gs.vendor),Oy=new te("safari-ime-span"),Au=!1,CE={key:Oy,props:{decorations:ME,handleDOMEvents:{compositionstart:()=>{Au=!0},compositionend:()=>{Au=!1}}}};function ME(t){let{$from:e,$to:n,to:r}=t.selection;if(Au&&e.sameParent(n)){let i=oe.widget(r,EE,{ignoreSelection:!0,key:"safari-ime-span"});return ee.create(t.doc,[i])}}function EE(t){let e=t.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var Dy=new X(SE?CE:{key:Oy});function Ru(t,e){let n=String(t);if(typeof e!="string")throw new TypeError("Expected character");let r=0,i=n.indexOf(e);for(;i!==-1;)r++,i=n.indexOf(e,i+e.length);return r}function Ou(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Du(t,e,n){let i=sn((n||{}).ignore||[]),o=TE(e),s=-1;for(;++s<o.length;)Dn(t,"text",a);function a(c,u){let f=-1,d;for(;++f<u.length;){let p=u[f],h=d?d.children:void 0;if(i(p,h?h.indexOf(p):void 0,d))return;d=p}if(d)return l(c,u)}function l(c,u){let f=u[u.length-1],d=o[s][0],p=o[s][1],h=0,g=f.children.indexOf(c),y=!1,x=[];d.lastIndex=0;let C=d.exec(c.value);for(;C;){let v=C.index,I={index:C.index,input:C.input,stack:[...u,c]},w=p(...C,I);if(typeof w=="string"&&(w=w.length>0?{type:"text",value:w}:void 0),w===!1?d.lastIndex=v+1:(h!==v&&x.push({type:"text",value:c.value.slice(h,v)}),Array.isArray(w)?x.push(...w):w&&x.push(w),h=v+C[0].length,y=!0),!d.global)break;C=d.exec(c.value)}return y?(h<c.value.length&&x.push({type:"text",value:c.value.slice(h)}),f.children.splice(g,1,...x)):x=[c],g+x.length}}function TE(t){let e=[];if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");let n=!t[0]||Array.isArray(t[0])?t:[t],r=-1;for(;++r<n.length;){let i=n[r];e.push([vE(i[0]),IE(i[1])])}return e}function vE(t){return typeof t=="string"?new RegExp(Ou(t),"g"):t}function IE(t){return typeof t=="function"?t:function(){return t}}var Bu="phrasing",Lu=["autolink","link","image","label"];function Fu(){return{transforms:[BE],enter:{literalAutolink:AE,literalAutolinkEmail:Pu,literalAutolinkHttp:Pu,literalAutolinkWww:Pu},exit:{literalAutolink:DE,literalAutolinkEmail:OE,literalAutolinkHttp:NE,literalAutolinkWww:RE}}}function zu(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:Bu,notInConstruct:Lu},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:Bu,notInConstruct:Lu},{character:":",before:"[ps]",after:"\\/",inConstruct:Bu,notInConstruct:Lu}]}}function AE(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function Pu(t){this.config.enter.autolinkProtocol.call(this,t)}function NE(t){this.config.exit.autolinkProtocol.call(this,t)}function RE(t){this.config.exit.data.call(this,t);let e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function OE(t){this.config.exit.autolinkEmail.call(this,t)}function DE(t){this.exit(t)}function BE(t){Du(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,LE],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,PE]],{ignore:["link","linkReference"]})}function LE(t,e,n,r,i){let o="";if(!By(i)||(/^w/i.test(e)&&(n=e+n,e="",o="http://"),!FE(n)))return!1;let s=zE(n+r);if(!s[0])return!1;let a={type:"link",title:null,url:o+e+s[0],children:[{type:"text",value:e+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function PE(t,e,n,r){return!By(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function FE(t){let e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function zE(t){let e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let n=e[0],r=n.indexOf(")"),i=Ru(t,"("),o=Ru(t,")");for(;r!==-1&&i>o;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),o++;return[t,n]}function By(t,e){let n=t.input.charCodeAt(t.index-1);return(t.index===0||Et(n)||vn(n))&&(!e||n!==47)}Ly.peek=UE;function $E(){this.buffer()}function _E(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function HE(){this.buffer()}function VE(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function WE(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ae(this.sliceSerialize(t)).toLowerCase(),n.label=e}function jE(t){this.exit(t)}function qE(t){let e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ae(this.sliceSerialize(t)).toLowerCase(),n.label=e}function KE(t){this.exit(t)}function UE(){return"["}function Ly(t,e,n,r){let i=n.createTracker(r),o=i.move("[^"),s=n.enter("footnoteReference"),a=n.enter("reference");return o+=i.move(n.safe(n.associationId(t),{after:"]",before:o})),a(),s(),o+=i.move("]"),o}function $u(){return{enter:{gfmFootnoteCallString:$E,gfmFootnoteCall:_E,gfmFootnoteDefinitionLabelString:HE,gfmFootnoteDefinition:VE},exit:{gfmFootnoteCallString:WE,gfmFootnoteCall:jE,gfmFootnoteDefinitionLabelString:qE,gfmFootnoteDefinition:KE}}}function _u(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:Ly},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,o,s){let a=o.createTracker(s),l=a.move("[^"),c=o.enter("footnoteDefinition"),u=o.enter("label");return l+=a.move(o.safe(o.associationId(r),{before:l,after:"]"})),u(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((e?` +`:" ")+o.indentLines(o.containerFlow(r,a.current()),e?Py:JE))),c(),l}}function JE(t,e,n){return e===0?t:Py(t,e,n)}function Py(t,e,n){return(n?"":" ")+t}var GE=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Fy.peek=XE;function Hu(){return{canContainEols:["delete"],enter:{strikethrough:QE},exit:{strikethrough:YE}}}function Vu(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:GE}],handlers:{delete:Fy}}}function QE(t){this.enter({type:"delete",children:[]},t)}function YE(t){this.exit(t)}function Fy(t,e,n,r){let i=n.createTracker(r),o=n.enter("strikethrough"),s=i.move("~~");return s+=n.containerPhrasing(t,{...i.current(),before:s,after:"~"}),s+=i.move("~~"),o(),s}function XE(){return"~"}function ZE(t){return t.length}function $y(t,e){let n=e||{},r=(n.align||[]).concat(),i=n.stringLength||ZE,o=[],s=[],a=[],l=[],c=0,u=-1;for(;++u<t.length;){let m=[],g=[],y=-1;for(t[u].length>c&&(c=t[u].length);++y<t[u].length;){let x=eT(t[u][y]);if(n.alignDelimiters!==!1){let C=i(x);g[y]=C,(l[y]===void 0||C>l[y])&&(l[y]=C)}m.push(x)}s[u]=m,a[u]=g}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<c;)o[f]=zy(r[f]);else{let m=zy(r);for(;++f<c;)o[f]=m}f=-1;let d=[],p=[];for(;++f<c;){let m=o[f],g="",y="";m===99?(g=":",y=":"):m===108?g=":":m===114&&(y=":");let x=n.alignDelimiters===!1?1:Math.max(1,l[f]-g.length-y.length),C=g+"-".repeat(x)+y;n.alignDelimiters!==!1&&(x=g.length+x+y.length,x>l[f]&&(l[f]=x),p[f]=x),d[f]=C}s.splice(1,0,d),a.splice(1,0,p),u=-1;let h=[];for(;++u<s.length;){let m=s[u],g=a[u];f=-1;let y=[];for(;++f<c;){let x=m[f]||"",C="",v="";if(n.alignDelimiters!==!1){let I=l[f]-(g[f]||0),w=o[f];w===114?C=" ".repeat(I):w===99?I%2?(C=" ".repeat(I/2+.5),v=" ".repeat(I/2-.5)):(C=" ".repeat(I/2),v=C):v=" ".repeat(I)}n.delimiterStart!==!1&&!f&&y.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&x==="")&&(n.delimiterStart!==!1||f)&&y.push(" "),n.alignDelimiters!==!1&&y.push(C),y.push(x),n.alignDelimiters!==!1&&y.push(v),n.padding!==!1&&y.push(" "),(n.delimiterEnd!==!1||f!==c-1)&&y.push("|")}h.push(n.delimiterEnd===!1?y.join("").replace(/ +$/,""):y.join(""))}return h.join(` +`)}function eT(t){return t==null?"":String(t)}function zy(t){let e=typeof t=="string"?t.codePointAt(0):0;return e===67||e===99?99:e===76||e===108?108:e===82||e===114?114:0}function ju(){return{enter:{table:tT,tableData:_y,tableHeader:_y,tableRow:rT},exit:{codeText:iT,table:nT,tableData:Wu,tableHeader:Wu,tableRow:Wu}}}function tT(t){let e=t._align;this.enter({type:"table",align:e.map(function(n){return n==="none"?null:n}),children:[]},t),this.data.inTable=!0}function nT(t){this.exit(t),this.data.inTable=void 0}function rT(t){this.enter({type:"tableRow",children:[]},t)}function Wu(t){this.exit(t)}function _y(t){this.enter({type:"tableCell",children:[]},t)}function iT(t){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,oT));let n=this.stack[this.stack.length-1];n.type,n.value=e,this.exit(t)}function oT(t,e){return e==="|"?e:t}function qu(t){let e=t||{},n=e.tableCellPadding,r=e.tablePipeAlign,i=e.stringLength,o=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:` `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:d,table:s,tableCell:l,tableRow:a}};function s(p,h,m,g){return c(u(p,m,g),p.align)}function a(p,h,m,g){let y=f(p,m,g),x=c([y]);return x.slice(0,x.indexOf(` -`))}function l(p,h,m,g){let y=m.enter("tableCell"),x=m.enter("phrasing"),C=m.containerPhrasing(p,{...g,before:o,after:o});return x(),y(),C}function c(p,h){return zy(p,{align:h,alignDelimiters:r,padding:n,stringLength:i})}function u(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("table");for(;++y<g.length;)x[y]=f(g[y],h,m);return C(),x}function f(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("tableRow");for(;++y<g.length;)x[y]=l(g[y],p,h,m);return C(),x}function d(p,h,m){let g=Bn.inlineCode(p,h,m);return m.stack.includes("tableCell")&&(g=g.replace(/\|/g,"\\$&")),g}}function Ku(){return{exit:{taskListCheckValueChecked:_y,taskListCheckValueUnchecked:_y,paragraph:oT}}}function Uu(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:sT}}}function _y(t){let e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function oT(t){let e=this.stack[this.stack.length-2];if(e&&e.type==="listItem"&&typeof e.checked=="boolean"){let n=this.stack[this.stack.length-1];n.type;let r=n.children[0];if(r&&r.type==="text"){let i=e.children,o=-1,s;for(;++o<i.length;){let a=i[o];if(a.type==="paragraph"){s=a;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(t)}function sT(t,e,n,r){let i=t.children[0],o=typeof t.checked=="boolean"&&i&&i.type==="paragraph",s="["+(t.checked?"x":" ")+"] ",a=n.createTracker(r);o&&a.move(s);let l=Bn.listItem(t,e,n,{...r,...a.current()});return o&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+s}}function Ju(){return[Fu(),$u(),Hu(),ju(),Ku()]}function Gu(t){return{extensions:[zu(),_u(t),Vu(),qu(t),Uu()]}}var aT={tokenize:dT,partial:!0},Hy={tokenize:pT,partial:!0},Vy={tokenize:hT,partial:!0},Wy={tokenize:mT,partial:!0},lT={tokenize:gT,partial:!0},jy={name:"wwwAutolink",tokenize:uT,previous:Ky},qy={name:"protocolAutolink",tokenize:fT,previous:Uy},Yt={name:"emailAutolink",tokenize:cT,previous:Jy},At={};function Yu(){return{text:At}}var ar=48;for(;ar<123;)At[ar]=Yt,ar++,ar===58?ar=65:ar===91&&(ar=97);At[43]=Yt;At[45]=Yt;At[46]=Yt;At[95]=Yt;At[72]=[Yt,qy];At[104]=[Yt,qy];At[87]=[Yt,jy];At[119]=[Yt,jy];function cT(t,e,n){let r=this,i,o;return s;function s(f){return!Qu(f)||!Jy.call(r,r.previous)||Xu(r.events)?n(f):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(f))}function a(f){return Qu(f)?(t.consume(f),a):f===64?(t.consume(f),l):n(f)}function l(f){return f===46?t.check(lT,u,c)(f):f===45||f===95||ye(f)?(o=!0,t.consume(f),l):u(f)}function c(f){return t.consume(f),i=!0,l}function u(f){return o&&i&&ge(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(f)):n(f)}}function uT(t,e,n){let r=this;return i;function i(s){return s!==87&&s!==119||!Ky.call(r,r.previous)||Xu(r.events)?n(s):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(aT,t.attempt(Hy,t.attempt(Vy,o),n),n)(s))}function o(s){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(s)}}function fT(t,e,n){let r=this,i="",o=!1;return s;function s(f){return(f===72||f===104)&&Uy.call(r,r.previous)&&!Xu(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),t.consume(f),a):n(f)}function a(f){if(ge(f)&&i.length<5)return i+=String.fromCodePoint(f),t.consume(f),a;if(f===58){let d=i.toLowerCase();if(d==="http"||d==="https")return t.consume(f),l}return n(f)}function l(f){return f===47?(t.consume(f),o?c:(o=!0,l)):n(f)}function c(f){return f===null||Tn(f)||U(f)||Et(f)||vn(f)?n(f):t.attempt(Hy,t.attempt(Vy,u),n)(f)}function u(f){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(f)}}function dT(t,e,n){let r=0;return i;function i(s){return(s===87||s===119)&&r<3?(r++,t.consume(s),i):s===46&&r===3?(t.consume(s),o):n(s)}function o(s){return s===null?n(s):e(s)}}function pT(t,e,n){let r,i,o;return s;function s(c){return c===46||c===95?t.check(Wy,l,a)(c):c===null||U(c)||Et(c)||c!==45&&vn(c)?l(c):(o=!0,t.consume(c),s)}function a(c){return c===95?r=!0:(i=r,r=void 0),t.consume(c),s}function l(c){return i||r||!o?n(c):e(c)}}function hT(t,e){let n=0,r=0;return i;function i(s){return s===40?(n++,t.consume(s),i):s===41&&r<n?o(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?t.check(Wy,e,o)(s):s===null||U(s)||Et(s)?e(s):(t.consume(s),i)}function o(s){return s===41&&r++,t.consume(s),i}}function mT(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),o):a===93?(t.consume(a),i):a===60||a===null||U(a)||Et(a)?e(a):n(a)}function i(a){return a===null||a===40||a===91||U(a)||Et(a)?e(a):r(a)}function o(a){return ge(a)?s(a):n(a)}function s(a){return a===59?(t.consume(a),r):ge(a)?(t.consume(a),s):n(a)}}function gT(t,e,n){return r;function r(o){return t.consume(o),i}function i(o){return ye(o)?n(o):e(o)}}function Ky(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||U(t)}function Uy(t){return!ge(t)}function Jy(t){return!(t===47||Qu(t))}function Qu(t){return t===43||t===45||t===46||t===95||ye(t)}function Xu(t){let e=t.length,n=!1;for(;e--;){let r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var yT={tokenize:MT,partial:!0};function Zu(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:wT,continuation:{tokenize:ST},exit:CT}},text:{91:{name:"gfmFootnoteCall",tokenize:xT},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:kT,resolveTo:bT}}}}function kT(t,e,n){let r=this,i=r.events.length,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),s;for(;i--;){let l=r.events[i][1];if(l.type==="labelImage"){s=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!s||!s._balanced)return n(l);let c=Ae(r.sliceSerialize({start:s.end,end:r.now()}));return c.codePointAt(0)!==94||!o.includes(c.slice(1))?n(l):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(l),t.exit("gfmFootnoteCallLabelMarker"),e(l))}}function bT(t,e){let n=t.length,r;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){r=t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";let i={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;let s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},t[t.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},l=[t[n+1],t[n+2],["enter",i,e],t[n+3],t[n+4],["enter",o,e],["exit",o,e],["enter",s,e],["enter",a,e],["exit",a,e],["exit",s,e],t[t.length-2],t[t.length-1],["exit",i,e]];return t.splice(n,t.length-n+1,...l),t}function xT(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o=0,s;return a;function a(f){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(t.enter("gfmFootnoteCallMarker"),t.consume(f),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",c)}function c(f){if(o>999||f===93&&!s||f===null||f===91||U(f))return n(f);if(f===93){t.exit("chunkString");let d=t.exit("gfmFootnoteCallString");return i.includes(Ae(r.sliceSerialize(d)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(f)}return U(f)||(s=!0),o++,t.consume(f),f===92?u:c}function u(f){return f===91||f===92||f===93?(t.consume(f),o++,c):c(f)}}function wT(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o,s=0,a;return l;function l(h){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(h){return h===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",u):n(h)}function u(h){if(s>999||h===93&&!a||h===null||h===91||U(h))return n(h);if(h===93){t.exit("chunkString");let m=t.exit("gfmFootnoteDefinitionLabelString");return o=Ae(r.sliceSerialize(m)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),d}return U(h)||(a=!0),s++,t.consume(h),h===92?f:u}function f(h){return h===91||h===92||h===93?(t.consume(h),s++,u):u(h)}function d(h){return h===58?(t.enter("definitionMarker"),t.consume(h),t.exit("definitionMarker"),i.includes(o)||i.push(o),F(t,p,"gfmFootnoteDefinitionWhitespace")):n(h)}function p(h){return e(h)}}function ST(t,e,n){return t.check(Tt,e,t.attempt(yT,e,n))}function CT(t){t.exit("gfmFootnoteDefinition")}function MT(t,e,n){let r=this;return F(t,i,"gfmFootnoteDefinitionIndent",5);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?e(o):n(o)}}function ef(t){let n=(t||{}).singleTilde,r={name:"strikethrough",tokenize:o,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(s,a){let l=-1;for(;++l<s.length;)if(s[l][0]==="enter"&&s[l][1].type==="strikethroughSequenceTemporary"&&s[l][1]._close){let c=l;for(;c--;)if(s[c][0]==="exit"&&s[c][1].type==="strikethroughSequenceTemporary"&&s[c][1]._open&&s[l][1].end.offset-s[l][1].start.offset===s[c][1].end.offset-s[c][1].start.offset){s[l][1].type="strikethroughSequence",s[c][1].type="strikethroughSequence";let u={type:"strikethrough",start:Object.assign({},s[c][1].start),end:Object.assign({},s[l][1].end)},f={type:"strikethroughText",start:Object.assign({},s[c][1].end),end:Object.assign({},s[l][1].start)},d=[["enter",u,a],["enter",s[c][1],a],["exit",s[c][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&ue(d,d.length,0,nn(p,s.slice(c+1,l),a)),ue(d,d.length,0,[["exit",f,a],["enter",s[l][1],a],["exit",s[l][1],a],["exit",u,a]]),ue(s,c-1,l-c+3,d),l=c+d.length-2;break}}for(l=-1;++l<s.length;)s[l][1].type==="strikethroughSequenceTemporary"&&(s[l][1].type="data");return s}function o(s,a,l){let c=this.previous,u=this.events,f=0;return d;function d(h){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(h):(s.enter("strikethroughSequenceTemporary"),p(h))}function p(h){let m=zt(c);if(h===126)return f>1?l(h):(s.consume(h),f++,p);if(f<2&&!n)return l(h);let g=s.exit("strikethroughSequenceTemporary"),y=zt(h);return g._open=!y||y===2&&!!m,g._close=!m||m===2&&!!y,a(h)}}}var Qs=class{constructor(){this.map=[]}add(e,n,r){ET(this,e,n,r)}consume(e){if(this.map.sort(function(o,s){return o[0]-s[0]}),this.map.length===0)return;let n=this.map.length,r=[];for(;n>0;)n-=1,r.push(e.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),e.length=this.map[n][0];r.push(e.slice()),e.length=0;let i=r.pop();for(;i;){for(let o of i)e.push(o);i=r.pop()}this.map.length=0}};function ET(t,e,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<t.map.length;){if(t.map[i][0]===e){t.map[i][1]+=n,t.map[i][2].push(...r);return}i+=1}t.map.push([e,n,r])}}function Gy(t,e){let n=!1,r=[];for(;e<t.length;){let i=t[e];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(t[e+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(t[e-1][1].type==="tableDelimiterMarker"){let o=r.length-1;r[o]=r[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);e+=1}return r}function tf(){return{flow:{null:{name:"table",tokenize:TT,resolveAll:vT}}}}function TT(t,e,n){let r=this,i=0,o=0,s;return a;function a(S){let ce=r.events.length-1;for(;ce>-1;){let W=r.events[ce][1].type;if(W==="lineEnding"||W==="linePrefix")ce--;else break}let Y=ce>-1?r.events[ce][1].type:null,L=Y==="tableHead"||Y==="tableRow"?w:l;return L===w&&r.parser.lazy[r.now().line]?n(S):L(S)}function l(S){return t.enter("tableHead"),t.enter("tableRow"),c(S)}function c(S){return S===124||(s=!0,o+=1),u(S)}function u(S){return S===null?n(S):R(S)?o>1?(o=0,r.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(S),t.exit("lineEnding"),p):n(S):_(S)?F(t,u,"whitespace")(S):(o+=1,s&&(s=!1,i+=1),S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),s=!0,u):(t.enter("data"),f(S)))}function f(S){return S===null||S===124||U(S)?(t.exit("data"),u(S)):(t.consume(S),S===92?d:f)}function d(S){return S===92||S===124?(t.consume(S),f):f(S)}function p(S){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(S):(t.enter("tableDelimiterRow"),s=!1,_(S)?F(t,h,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):h(S))}function h(S){return S===45||S===58?g(S):S===124?(s=!0,t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),m):I(S)}function m(S){return _(S)?F(t,g,"whitespace")(S):g(S)}function g(S){return S===58?(o+=1,s=!0,t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),y):S===45?(o+=1,y(S)):S===null||R(S)?v(S):I(S)}function y(S){return S===45?(t.enter("tableDelimiterFiller"),x(S)):I(S)}function x(S){return S===45?(t.consume(S),x):S===58?(s=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),C):(t.exit("tableDelimiterFiller"),C(S))}function C(S){return _(S)?F(t,v,"whitespace")(S):v(S)}function v(S){return S===124?h(S):S===null||R(S)?!s||i!==o?I(S):(t.exit("tableDelimiterRow"),t.exit("tableHead"),e(S)):I(S)}function I(S){return n(S)}function w(S){return t.enter("tableRow"),N(S)}function N(S){return S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),N):S===null||R(S)?(t.exit("tableRow"),e(S)):_(S)?F(t,N,"whitespace")(S):(t.enter("data"),D(S))}function D(S){return S===null||S===124||U(S)?(t.exit("data"),N(S)):(t.consume(S),S===92?B:D)}function B(S){return S===92||S===124?(t.consume(S),D):D(S)}}function vT(t,e){let n=-1,r=!0,i=0,o=[0,0,0,0],s=[0,0,0,0],a=!1,l=0,c,u,f,d=new Qs;for(;++n<t.length;){let p=t[n],h=p[1];p[0]==="enter"?h.type==="tableHead"?(a=!1,l!==0&&(Qy(d,e,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",c,e]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(r=!0,f=void 0,o=[0,0,0,0],s=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",u,e]])),i=h.type==="tableDelimiterRow"?2:u?3:1):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(o[1]!==0&&(s[0]=s[1],f=Ys(d,e,o,i,void 0,f),o=[0,0,0,0]),s[2]=n)):h.type==="tableCellDivider"&&(r?r=!1:(o[1]!==0&&(s[0]=s[1],f=Ys(d,e,o,i,void 0,f)),o=s,s=[o[1],n,0,0])):h.type==="tableHead"?(a=!0,l=n):h.type==="tableRow"||h.type==="tableDelimiterRow"?(l=n,o[1]!==0?(s[0]=s[1],f=Ys(d,e,o,i,n,f)):s[1]!==0&&(f=Ys(d,e,s,i,n,f)),i=0):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(s[3]=n)}for(l!==0&&Qy(d,e,l,c,u),d.consume(e.events),n=-1;++n<e.events.length;){let p=e.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Gy(e.events,n))}return t}function Ys(t,e,n,r,i,o){let s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(o.end=Object.assign({},Zr(e.events,n[0])),t.add(n[0],0,[["exit",o,e]]));let l=Zr(e.events,n[1]);if(o={type:s,start:Object.assign({},l),end:Object.assign({},l)},t.add(n[1],0,[["enter",o,e]]),n[2]!==0){let c=Zr(e.events,n[2]),u=Zr(e.events,n[3]),f={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(t.add(n[2],0,[["enter",f,e]]),r!==2){let d=e.events[n[2]],p=e.events[n[3]];if(d[1].end=Object.assign({},p[1].end),d[1].type="chunkText",d[1].contentType="text",n[3]>n[2]+1){let h=n[2]+1,m=n[3]-n[2]-1;t.add(h,m,[])}}t.add(n[3]+1,0,[["exit",f,e]])}return i!==void 0&&(o.end=Object.assign({},Zr(e.events,i)),t.add(i,0,[["exit",o,e]]),o=void 0),o}function Qy(t,e,n,r,i){let o=[],s=Zr(e.events,n);i&&(i.end=Object.assign({},s),o.push(["exit",i,e])),r.end=Object.assign({},s),o.push(["exit",r,e]),t.add(n+1,0,o)}function Zr(t,e){let n=t[e],r=n[0]==="enter"?"start":"end";return n[1][r]}var IT={name:"tasklistCheck",tokenize:AT};function nf(){return{text:{91:IT}}}function AT(t,e,n){let r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),o)}function o(l){return U(l)?(t.enter("taskListCheckValueUnchecked"),t.consume(l),t.exit("taskListCheckValueUnchecked"),s):l===88||l===120?(t.enter("taskListCheckValueChecked"),t.consume(l),t.exit("taskListCheckValueChecked"),s):n(l)}function s(l){return l===93?(t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),a):n(l)}function a(l){return R(l)?e(l):_(l)?t.check({tokenize:NT},e,n)(l):n(l)}}function NT(t,e,n){return F(t,r,"whitespace");function r(i){return i===null?n(i):e(i)}}function Yy(t){return Co([Yu(),Zu(),ef(t),tf(),nf()])}var RT={};function Xs(t){let e=this,n=t||RT,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Yy(n)),o.push(Ju()),s.push(Gu(n))}function V(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-gfm",...e}}),t}var sf=rr("strike_through");V(sf,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var ro=yt("strike_through",t=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:e=>e==="line-through"}],toDOM:e=>["del",t.get(sf.key)(e)],parseMarkdown:{match:e=>e.type==="delete",runner:(e,n,r)=>{e.openMark(r),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strike_through",runner:(e,n)=>{e.withMark(n,"delete")}}}));V(ro.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});V(ro.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var af=P("ToggleStrikeThrough",t=>()=>Ar(ro.type(t)));V(af,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var Zy=fe(t=>Ht(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,ro.type(t)));V(Zy,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var lf=ze("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:t=>{let e=t.get(G);return()=>e.call(af.key)}}});V(lf.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});V(lf.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var io=py({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:t=>t.style.textAlign||"left",setDOMAttr:(t,e)=>{e.style=`text-align: ${t||"left"}`}}}}),Xt=te("table",()=>({...io.table,content:"table_header_row table_row+",disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="table",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r,isHeader:s===0}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table",runner:(t,e)=>{let n=e.content.firstChild?.content;if(!n)return;let r=[];n.forEach(i=>{r.push(i.attrs.alignment)}),t.openNode("table",void 0,{align:r}),t.next(e.content),t.closeNode()}}}));V(Xt.node,{displayName:"NodeSchema<table>",group:"Table"});V(Xt.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var oo=te("table_header_row",()=>({...io.table_row,disableDropCursor:!0,content:"(table_header)*",parseDOM:[{tag:"tr[data-is-header]"},{tag:"tr",getAttrs:t=>t instanceof HTMLElement&&t.querySelector("th")?{}:!1}],toDOM(){return["tr",{"data-is-header":!0},0]},parseMarkdown:{match:t=>!!(t.type==="tableRow"&&t.isHeader),runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s],isHeader:e.isHeader}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow",void 0,{isHeader:!0}),t.next(e.content),t.closeNode())}}}));V(oo.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});V(oo.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var ti=te("table_row",()=>({...io.table_row,disableDropCursor:!0,content:"(table_cell)*",parseMarkdown:{match:t=>t.type==="tableRow",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s]}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow"),t.next(e.content),t.closeNode())}}}));V(ti.node,{displayName:"NodeSchema<tableRow>",group:"Table"});V(ti.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var so=te("table_cell",()=>({...io.table_cell,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}).openNode(t.schema.nodes.paragraph).next(e.children).closeNode().closeNode()}},toMarkdown:{match:t=>t.type.name==="table_cell",runner:(t,e)=>{t.openNode("tableCell").next(e.content).closeNode()}}}));V(so.node,{displayName:"NodeSchema<tableCell>",group:"Table"});V(so.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var ei=te("table_header",()=>({...io.table_header,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}),t.openNode(t.schema.nodes.paragraph),t.next(e.children),t.closeNode(),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header",runner:(t,e)=>{t.openNode("tableCell"),t.next(e.content),t.closeNode()}}}));V(ei.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});V(ei.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function ek(t,e=3,n=3){let r=Array(n).fill(0).map(()=>so.type(t).createAndFill()),i=Array(n).fill(0).map(()=>ei.type(t).createAndFill()),o=Array(e).fill(0).map((s,a)=>a===0?oo.type(t).create(null,i):ti.type(t).create(null,r));return Xt.type(t).create(null,o)}function tk(t){return(e,n)=>r=>{n=n??r.selection.from;let i=r.doc.resolve(n),o=$h(l=>l.type.name==="table")(i),s=o?{node:o.node,from:o.start}:void 0,a=t==="row";if(s){let l=Z.get(s.node);if(e>=0&&e<(a?l.height:l.width)){let c=l.positionAt(a?e:l.height-1,a?l.width-1:e,s.node),u=r.doc.resolve(s.from+c),f=a?ae.rowSelection:ae.colSelection,d=l.positionAt(a?e:0,a?0:e,s.node),p=r.doc.resolve(s.from+d);return _l(r.setSelection(f(u,p)))}}return r}}var OT=tk("row"),DT=tk("col");function nk(t,e,{map:n,tableStart:r,table:i},o){let s=Array(o).fill(0).reduce((l,c,u)=>l+i.child(u).nodeSize,r),a=Array(n.width).fill(0).map((l,c)=>{let u=i.nodeAt(n.map[c]);return so.type(t).createAndFill({alignment:u?.attrs.alignment})});return e.insert(s,ti.type(t).create(null,a)),e}function BT(t){let e=Xr(t.$from);if(!e)return;let n=Z.get(e.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(r=>{let i=e.node.nodeAt(r),o=r+e.start;return{pos:o,start:o+1,node:i}})}function LT(t){let e=BT(t.selection);if(e&&e[0]){let n=t.doc.resolve(e[0].pos),r=e[e.length-1];if(r){let i=t.doc.resolve(r.pos);return _l(t.setSelection(new ae(i,n)))}}return t}var cf=P("GoToPrevTableCell",()=>()=>Js(-1));V(cf,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var uf=P("GoToNextTableCell",()=>()=>Js(1));V(uf,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var ff=P("ExitTable",t=>()=>(e,n)=>{if(!Ie(e))return!1;let{$head:r}=e.selection,i=zh(r,Xt.type(t));if(!i)return!1;let{to:o}=i,s=e.tr.replaceWith(o,o,kt.type(t).createAndFill());return s.setSelection($.near(s.doc.resolve(o),1)).scrollIntoView(),n?.(s),!0});V(ff,{displayName:"Command<breakTableCommand>",group:"Table"});var rk=P("InsertTable",t=>({row:e,col:n}={})=>(r,i)=>{let{selection:o,tr:s}=r,{from:a}=o,l=ek(t,e,n),c=s.replaceSelectionWith(l),u=$.findFrom(c.doc.resolve(a),1,!0);return u&&c.setSelection(u),i?.(c),!0});V(rk,{displayName:"Command<insertTableCommand>",group:"Table"});var ik=P("MoveRow",()=>({from:t,to:e,pos:n}={})=>Ey({from:t??0,to:e??0,pos:n}));V(ik,{displayName:"Command<moveRowCommand>",group:"Table"});var ok=P("MoveCol",()=>({from:t,to:e,pos:n}={})=>Ty({from:t??0,to:e??0,pos:n}));V(ok,{displayName:"Command<moveColCommand>",group:"Table"});var sk=P("SelectRow",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(OT(t.index,t.pos)(r))});V(sk,{displayName:"Command<selectRowCommand>",group:"Table"});var ak=P("SelectCol",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(DT(t.index,t.pos)(r))});V(ak,{displayName:"Command<selectColCommand>",group:"Table"});var lk=P("SelectTable",()=>()=>(t,e)=>{let{tr:n}=t;return!!e?.(LT(n))});V(lk,{displayName:"Command<selectTableCommand>",group:"Table"});var ck=P("DeleteSelectedCells",()=>()=>(t,e)=>{let{selection:n}=t;if(!(n instanceof ae))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?My(t,e):i?Ks(t,e):Us(t,e)});V(ck,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var uk=P("AddColBefore",()=>()=>wy);V(uk,{displayName:"Command<addColBeforeCommand>",group:"Table"});var fk=P("AddColAfter",()=>()=>qs);V(fk,{displayName:"Command<addColAfterCommand>",group:"Table"});var dk=P("AddRowBefore",t=>()=>(e,n)=>{if(!Ie(e))return!1;if(n){let r=bt(e);n(nk(t,e.tr,r,r.top))}return!0});V(dk,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var pk=P("AddRowAfter",t=>()=>(e,n)=>{if(!Ie(e))return!1;if(n){let r=bt(e);n(nk(t,e.tr,r,r.bottom))}return!0});V(pk,{displayName:"Command<addRowAfterCommand>",group:"Table"});var hk=P("SetAlign",()=>(t="left")=>Cy("alignment",t));V(hk,{displayName:"Command<setAlignCommand>",group:"Table"});var mk=fe(t=>new ke(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(e,n,r,i)=>{let o=e.doc.resolve(r);if(!o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),Xt.type(t)))return null;let s=ek(t,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),a=e.tr.replaceRangeWith(r,i,s);return a.setSelection(z.create(a.doc,r+3)).scrollIntoView()}));V(mk,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var gk=Cg(t=>({run:(e,n,r)=>{if(r)return e;function i(c){let u=c.childCount,f=c.lastChild?.childCount??0;if(u===0||f===0)return kt.type(t).create();let d=c.firstChild;if(!(f>0&&d&&d.childCount===0))return c;if(u>=3){let g=c.child(1),y=[];for(let v=0;v<g.childCount;v++){let I=g.child(v);y.push(ei.type(t).create(I.attrs,I.content,I.marks))}let x=d.type.create(d.attrs,y),C=[];for(let v=2;v<u;v++)C.push(c.child(v));return c.type.create(c.attrs,[x,...C])}let p=Array(f).fill(0).map(()=>ei.type(t).createAndFill()),h=new A(E.from(p),0,0),m=d.replace(0,0,h);return c.replace(0,d.nodeSize,new A(E.from(m),0,0))}function o(c){let u=ti.type(t),f=[],d=[],p=!1;function h(){if(d.length===0)return;let m=oo.type(t).createAndFill(),g=Xt.type(t).create(null,[m,...d]);f.push(i(g)),d=[]}return c.forEach(m=>{m.type===u?(p=!0,d.push(m)):(h(),f.push(m))}),h(),p?E.from(f):c}function s(c){let u=o(c),f=u!==c,d=[];return u.forEach(p=>{if(p.type===Xt.type(t)){let h=i(p);h!==p&&(f=!0),d.push(h)}else if(p.childCount>0){let h=s(p.content);h!==p.content?(f=!0,d.push(p.copy(h))):d.push(p)}else d.push(p)}),f?E.from(d):c}function a(c){let u=[],f=[];c.forEach(d=>f.push(d));for(let d=0;d<f.length;d++){let p=f[d],h=f[d+1];p.type===kt.type(t)&&p.content.size===0&&h&&h.type===Xt.type(t)||u.push(p)}return u.length<f.length?E.from(u):c}let l=s(e.content);return l=a(l),new A(E.from(l),e.openStart,e.openEnd)}}));V(gk,{displayName:"PasteRule<table>",group:"Table"});var df=ze("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:t=>{let e=t.get(G);return()=>e.call(uf.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:t=>{let e=t.get(G);return()=>e.call(cf.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:t=>{let e=t.get(G);return()=>e.call(ff.key)}}});V(df.ctx,{displayName:"KeymapCtx<table>",group:"Table"});V(df.shortcuts,{displayName:"Keymap<table>",group:"Table"});var rf="footnote_definition",Xy="footnoteDefinition",pf=te("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${rf}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw tt(t);return{label:t.dataset.label}},contentElement:"dd"}],toDOM:t=>{let e=t.attrs.label;return["dl",{"data-label":e,"data-type":rf},["dt",e],["dd",0]]},parseMarkdown:{match:({type:t})=>t===Xy,runner:(t,e,n)=>{t.openNode(n,{label:e.label}).next(e.children).closeNode()}},toMarkdown:{match:t=>t.type.name===rf,runner:(t,e)=>{t.openNode(Xy,void 0,{label:e.attrs.label,identifier:e.attrs.label}).next(e.content).closeNode()}}}));V(pf.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});V(pf.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var of="footnote_reference",hf=te("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${of}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw tt(t);return{label:t.dataset.label}}}],toDOM:t=>{let e=t.attrs.label;return["sup",{"data-label":e,"data-type":of},e]},parseMarkdown:{match:({type:t})=>t==="footnoteReference",runner:(t,e,n)=>{t.addNode(n,{label:e.label})}},toMarkdown:{match:t=>t.type.name===of,runner:(t,e)=>{t.addNode("footnoteReference",void 0,void 0,{label:e.attrs.label,identifier:e.attrs.label})}}}));V(hf.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});V(hf.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var mf=It.extendSchema(t=>e=>{let n=t(e);return{...n,attrs:{...n.attrs,checked:{default:null,validate:"boolean|null"}},parseDOM:[{tag:'li[data-item-type="task"]',getAttrs:r=>{if(!(r instanceof HTMLElement))throw tt(r);return{label:r.dataset.label,listType:r.dataset.listType,spread:r.dataset.spread,checked:r.dataset.checked?r.dataset.checked==="true":null}}},...n?.parseDOM||[]],toDOM:r=>n.toDOM&&r.attrs.checked==null?n.toDOM(r):["li",{"data-item-type":"task","data-label":r.attrs.label,"data-list-type":r.attrs.listType,"data-spread":r.attrs.spread,"data-checked":r.attrs.checked},0],parseMarkdown:{match:({type:r})=>r==="listItem",runner:(r,i,o)=>{if(i.checked==null){n.parseMarkdown.runner(r,i,o);return}let s=i.label!=null?`${i.label}.`:"\u2022",a=i.checked!=null?!!i.checked:null,l=i.label!=null?"ordered":"bullet",c=i.spread!=null?`${i.spread}`:"true";r.openNode(o,{label:s,listType:l,spread:c,checked:a}),r.next(i.children),r.closeNode()}},toMarkdown:{match:r=>r.type.name==="list_item",runner:(r,i)=>{if(i.attrs.checked==null){n.toMarkdown.runner(r,i);return}let o=i.attrs.label,s=i.attrs.listType,a=i.attrs.spread==="true",l=i.attrs.checked;r.openNode("listItem",void 0,{label:o,listType:s,spread:a,checked:l}),r.next(i.content),r.closeNode()}}}});V(mf.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});V(mf.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var yk=fe(()=>new ke(/^\[(?<checked>\s|x)\]\s$/,(t,e,n,r)=>{let i=t.doc.resolve(n),o=0,s=i.node(o);for(;s&&s.type.name!=="list_item";)o--,s=i.node(o);if(!s||s.attrs.checked!=null)return null;let a=e.groups?.checked==="x",l=i.before(o),c=t.tr;return c.deleteRange(n,r).setNodeMarkup(l,void 0,{...s.attrs,checked:a}),c}));V(yk,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var PT=[lf,df].flat(),FT=[mk,yk],zT=[Zy],$T=[gk],kk=Se(()=>Oy);V(kk,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var _T=Se(()=>Iy({}));V(_T,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var bk=Se(()=>Ny({allowTableNodeSelection:!0}));V(bk,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var gf=Ge("remarkGFM",()=>Xs);V(gf.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});V(gf.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var HT=new ee("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function VT(t,e){let n=0;return e.forEach((r,i,o)=>{r===t&&(n=o)}),n}var xk=Se(()=>new X({key:HT,appendTransaction:(t,e,n)=>{let r,i=(o,s)=>{if(r||(r=n.tr),o.type.name!=="table_cell")return;let a=n.doc.resolve(s),l=a.node(a.depth),c=a.node(a.depth-1).firstChild;if(!c)return;let u=VT(o,l),f=c.maybeChild(u);if(!f)return;let d=f.attrs.alignment;d!==o.attrs.alignment&&r.setNodeMarkup(s,void 0,{...o.attrs,alignment:d})};return e.doc!==n.doc&&n.doc.descendants(i),r}}));V(xk,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var WT=[xk,kk,gf,bk].flat(),jT=[mf,Xt,oo,ti,ei,so,pf,hf,sf,ro].flat(),qT=[uf,cf,ff,rk,ik,ok,sk,ak,lk,ck,dk,pk,uk,fk,hk,af],wk=[jT,FT,$T,zT,PT,qT,WT].flat();var KT=typeof global=="object"&&global&&global.Object===Object&&global,Sk=KT;var UT=typeof self=="object"&&self&&self.Object===Object&&self,JT=Sk||UT||Function("return this")(),Zs=JT;var GT=Zs.Symbol,ni=GT;var Ck=Object.prototype,QT=Ck.hasOwnProperty,YT=Ck.toString,ao=ni?ni.toStringTag:void 0;function XT(t){var e=QT.call(t,ao),n=t[ao];try{t[ao]=void 0;var r=!0}catch{}var i=YT.call(t);return r&&(e?t[ao]=n:delete t[ao]),i}var Mk=XT;var ZT=Object.prototype,ev=ZT.toString;function tv(t){return ev.call(t)}var Ek=tv;var nv="[object Null]",rv="[object Undefined]",Tk=ni?ni.toStringTag:void 0;function iv(t){return t==null?t===void 0?rv:nv:Tk&&Tk in Object(t)?Mk(t):Ek(t)}var vk=iv;function ov(t){return t!=null&&typeof t=="object"}var Ik=ov;var sv="[object Symbol]";function av(t){return typeof t=="symbol"||Ik(t)&&vk(t)==sv}var Ak=av;var lv=/\s/;function cv(t){for(var e=t.length;e--&&lv.test(t.charAt(e)););return e}var Nk=cv;var uv=/^\s+/;function fv(t){return t&&t.slice(0,Nk(t)+1).replace(uv,"")}var Rk=fv;function dv(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var lo=dv;var Ok=NaN,pv=/^[-+]0x[0-9a-f]+$/i,hv=/^0b[01]+$/i,mv=/^0o[0-7]+$/i,gv=parseInt;function yv(t){if(typeof t=="number")return t;if(Ak(t))return Ok;if(lo(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=lo(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=Rk(t);var n=hv.test(t);return n||mv.test(t)?gv(t.slice(2),n?2:8):pv.test(t)?Ok:+t}var yf=yv;var kv=function(){return Zs.Date.now()},ea=kv;var bv="Expected a function",xv=Math.max,wv=Math.min;function Sv(t,e,n){var r,i,o,s,a,l,c=0,u=!1,f=!1,d=!0;if(typeof t!="function")throw new TypeError(bv);e=yf(e)||0,lo(n)&&(u=!!n.leading,f="maxWait"in n,o=f?xv(yf(n.maxWait)||0,e):o,d="trailing"in n?!!n.trailing:d);function p(w){var N=r,D=i;return r=i=void 0,c=w,s=t.apply(D,N),s}function h(w){return c=w,a=setTimeout(y,e),u?p(w):s}function m(w){var N=w-l,D=w-c,B=e-N;return f?wv(B,o-D):B}function g(w){var N=w-l,D=w-c;return l===void 0||N>=e||N<0||f&&D>=o}function y(){var w=ea();if(g(w))return x(w);a=setTimeout(y,m(w))}function x(w){return a=void 0,d&&r?p(w):(r=i=void 0,s)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=i=a=void 0}function v(){return a===void 0?s:x(ea())}function I(){var w=ea(),N=g(w);if(r=arguments,i=this,l=w,N){if(a===void 0)return h(l);if(f)return clearTimeout(a),a=setTimeout(y,e),p(l)}return a===void 0&&(a=setTimeout(y,e)),s}return I.cancel=C,I.flush=v,I}var kf=Sv;var Dk=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=t=>(this.beforeMountedListeners.push(t),this),this.mounted=t=>(this.mountedListeners.push(t),this),this.updated=t=>(this.updatedListeners.push(t),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(t){return this.markdownUpdatedListeners.push(t),this}blur(t){return this.blurListeners.push(t),this}focus(t){return this.focusListeners.push(t),this}destroy(t){return this.destroyListeners.push(t),this}selectionUpdated(t){return this.selectionUpdatedListeners.push(t),this}},ta=K(new Dk,"listener"),Cv=new ee("MILKDOWN_LISTENER"),bf=t=>(t.inject(ta,new Dk),async()=>{await t.wait(Jt);let{listeners:e}=t.get(ta);e.beforeMount.forEach(c=>c(t)),await t.wait(_r);let n=t.get(nr),r=null,i=null,o=null,s=null,a=kf(()=>{if(!s)return;let{doc:c}=s;if(e.updated.length>0&&r&&!r.eq(c)&&e.updated.forEach(u=>{u(t,c,r)}),e.markdownUpdated.length>0&&r&&!r.eq(c)){let u=n(c);e.markdownUpdated.forEach(f=>{f(t,u,i)}),i=u}r=c,s=null},200),l=new X({key:Cv,view:()=>({destroy:()=>{a.cancel(),e.destroy.forEach(c=>c(t))}}),props:{handleDOMEvents:{focus:()=>(e.focus.forEach(c=>c(t)),!1),blur:()=>(e.blur.forEach(c=>c(t)),!1)}},state:{init:(c,u)=>{r=u.doc,i=n(u.doc)},apply:c=>{let u=c.selection;(!o&&u||o&&!u.eq(o))&&(e.selectionUpdated.forEach(f=>{f(t,u,o)}),o=u),!(!(c.docChanged||c.storedMarksSet)||c.getMeta("addToHistory")===!1)&&(s=c,a())}}});t.update(gt,c=>c.concat(l)),await t.wait(Gi),e.mounted.forEach(c=>c(t))});bf.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};function Mv(t){let e=t.schema.cached.changeSetIDs||(t.schema.cached.changeSetIDs=Object.create(null)),n=e[t.name];return n==null&&(e[t.name]=n=Object.keys(t.schema.nodes).indexOf(t.name)+1),n}var Pk={encodeCharacter:t=>t,encodeNodeStart:t=>t.type.name,encodeNodeEnd:t=>-Mv(t.type),compareTokens:(t,e)=>t===e};function xf(t,e,n,r,i){for(let o=0,s=0;o<t.childCount;o++){let a=t.child(o),l=s+a.nodeSize,c=Math.max(s,n),u=Math.min(l,r);if(c<u)if(a.isText)for(let f=c;f<u;f++)i.push(e.encodeCharacter(a.text.charCodeAt(f-s),a.marks));else a.isLeaf?i.push(e.encodeNodeStart(a)):(c==s&&i.push(e.encodeNodeStart(a)),xf(a.content,e,Math.max(s+1,c)-s-1,Math.min(l-1,u)-s-1,i),u==l&&i.push(e.encodeNodeEnd(a)));s=l}return i}var Ev=5e3;function Tv(t,e){return Math.min(15,Math.max(2,Math.floor(Math.max(t,e)/10)))}function Fk(t,e,n,r=Pk){let i=xf(t,r,n.fromA,n.toA,[]),o=xf(e,r,n.fromB,n.toB,[]),s=0,a=i.length,l=o.length,c=r.compareTokens;for(;s<i.length&&s<o.length&&c(i[s],o[s]);)s++;if(s==i.length&&s==o.length)return[];for(;a>s&&l>s&&c(i[a-1],o[l-1]);)a--,l--;if(a==s||l==s||a==l&&a==s+1)return[n.slice(s,a,s,l)];let u=a-s,f=l-s,d=Math.min(Ev,u+f),p=d+1,h=[],m=[];for(let g=p*2,y=0;y<g;y++)m[y]=-1;for(let g=0;g<=d;g++){for(let y=-g;y<=g;y+=2){let x=m[y+1+d],C=m[y-1+d],v=x<C?C:x+1,I=v+y;for(;v<u&&I<f&&c(i[s+v],o[s+I]);)v++,I++;if(m[y+d]=v,v>=u&&I>=f){let w=[],N=Tv(a-s,l-s),D=-1,B=-1,S=-1,ce=-1,Y=(L,W,j,le)=>{D>-1&&D<W+N?(D=L,S=j):(D>-1&&w.push(n.slice(D,B,S,ce)),D=L,B=W,S=j,ce=le)};for(let L=g-1;L>=0;L--){let W=m[y+1+d],j=m[y-1+d];W<j?(y--,v=j+s,I=v+y,Y(v,v,I,I+1)):(y++,v=W+s,I=v+y,Y(v,v+1,I,I)),m=h[L>>1]}return D>-1&&w.push(n.slice(D,B,S,ce)),w.reverse()}}g%2==0&&h.push(m.slice())}return[n.slice(s,a,s,l)]}var he=class t{constructor(e,n){this.length=e,this.data=n}cut(e){return e==this.length?this:new t(e,this.data)}static slice(e,n,r){if(n==r)return t.none;if(n==0&&r==t.len(e))return e;let i=[];for(let o=0,s=0;s<r;o++){let a=e[o],l=s+a.length,c=Math.min(r,l)-Math.max(n,s);c>0&&i.push(a.cut(c)),s=l}return i}static join(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=r(e[e.length-1].data,n[0].data);if(i==null)return e.concat(n);let o=e.slice(0,e.length-1);o.push(new t(e[e.length-1].length+n[0].length,i));for(let s=1;s<n.length;s++)o.push(n[s]);return o}static len(e){let n=0;for(let r=0;r<e.length;r++)n+=e[r].length;return n}};he.none=[];var Nt=class t{constructor(e,n,r,i,o,s){this.fromA=e,this.toA=n,this.fromB=r,this.toB=i,this.deleted=o,this.inserted=s}get lenA(){return this.toA-this.fromA}get lenB(){return this.toB-this.fromB}slice(e,n,r,i){return e==0&&r==0&&n==this.toA-this.fromA&&i==this.toB-this.fromB?this:new t(this.fromA+e,this.fromA+n,this.fromB+r,this.fromB+i,he.slice(this.deleted,e,n),he.slice(this.inserted,r,i))}static merge(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=[];for(let o=0,s=0,a=e[0],l=n[0];;){if(!a&&!l)return i;if(a&&(!l||a.toB<l.fromA)){let c=s?n[s-1].toB-n[s-1].toA:0;i.push(c==0?a:new t(a.fromA,a.toA,a.fromB+c,a.toB+c,a.deleted,a.inserted)),a=o++==e.length?null:e[o]}else if(l&&(!a||l.toA<a.fromB)){let c=o?e[o-1].toB-e[o-1].toA:0;i.push(c==0?l:new t(l.fromA-c,l.toA-c,l.fromB,l.toB,l.deleted,l.inserted)),l=s++==n.length?null:n[s]}else{let c=Math.min(a.fromB,l.fromA),u=Math.min(a.fromA,l.fromA-(o?e[o-1].toB-e[o-1].toA:0)),f=u,d=Math.min(l.fromB,a.fromB+(s?n[s-1].toB-n[s-1].toA:0)),p=d,h=he.none,m=he.none,g=!1,y=!1;for(;;){let x=a?c>=a.fromB?a.toB:a.fromB:2e8,C=l?c>=l.fromA?l.toA:l.fromA:2e8,v=Math.min(x,C),I=a&&c>=a.fromB,w=l&&c>=l.fromA;if(!I&&!w)break;I&&c==a.fromB&&!g&&(h=he.join(h,a.deleted,r),f+=a.lenA,g=!0),I&&!w&&(m=he.join(m,he.slice(a.inserted,c-a.fromB,v-a.fromB),r),p+=v-c),w&&c==l.fromA&&!y&&(m=he.join(m,l.inserted,r),p+=l.lenB,y=!0),w&&!I&&(h=he.join(h,he.slice(l.deleted,c-l.fromA,v-l.fromA),r),f+=v-c),I&&v==a.toB&&(a=o++==e.length?null:e[o],g=!1),w&&v==l.toA&&(l=s++==n.length?null:n[s],y=!1),c=v}(u<f||d<p)&&i.push(new t(u,f,d,p,h,m))}}}static fromJSON(e){return new t(e.fromA,e.toA,e.fromB,e.toB,e.deleted.map(n=>new he(n.length,n.data)),e.inserted.map(n=>new he(n.length,n.data)))}toJSON(){return this}},vv;try{vv=new RegExp("[\\p{Alphabetic}_]","u")}catch{}var ri=class t{constructor(e,n){this.config=e,this.changes=n}addSteps(e,n,r){let i=[];for(let l=0;l<n.length;l++){let c=Array.isArray(r)?r[l]:r,u=0;n[l].forEach((f,d,p,h)=>{i.push(new Nt(f+u,d+u,p,h,f==d?he.none:[new he(d-f,c)],p==h?he.none:[new he(h-p,c)])),u=h-p-(d-f)})}if(i.length==0)return this;let o=wf(i,this.config.combine),s=Nt.merge(this.changes,o,this.config.combine),a=s;for(let l=0;l<a.length;l++){let c=a[l];if(c.fromA==c.toA||c.fromB==c.toB||!o.some(f=>f.toB>c.fromB&&f.fromB<c.toB))continue;let u=Fk(this.config.doc.content,e.content,c,this.config.encoder);u.length==1&&u[0].fromB==0&&u[0].toB==c.toB-c.fromB||(a==s&&(a=s.slice()),u.length==1?a[l]=u[0]:(a.splice(l,1,...u),l+=u.length-1))}return new t(this.config,a)}get startDoc(){return this.config.doc}map(e){let n=r=>{let i=e(r);return i===r.data?r:new he(r.length,i)};return new t(this.config,this.changes.map(r=>new Nt(r.fromA,r.toA,r.fromB,r.toB,r.deleted.map(n),r.inserted.map(n))))}changedRange(e,n){if(e==this)return null;let r=n&&Iv(n),i=r?r.toB-r.fromB-(r.toA-r.fromA):0;function o(f){return!r||f<=r.fromA?f:f+i}let s=r?r.fromB:2e8,a=r?r.toB:-2e8;function l(f,d=f){s=Math.min(f,s),a=Math.max(d,a)}let c=this.changes,u=e.changes;for(let f=0,d=0;f<c.length&&d<u.length;){let p=c[f],h=u[d];p&&h&&Av(p,h,o)?(f++,d++):h&&(!p||o(p.fromB)>=h.fromB)?(l(h.fromB,h.toB),d++):(l(o(p.fromB),o(p.toB)),f++)}return s<=a?{from:s,to:a}:null}static create(e,n=(o,s)=>o===s?o:null,r=Pk,i=[]){return new t({combine:n,doc:e,encoder:r},i)}};ri.computeDiff=Fk;function wf(t,e,n=0,r=t.length){if(r==n+1)return[t[n]];let i=n+r>>1;return Nt.merge(wf(t,e,n,i),wf(t,e,i,r),e)}function Bk(t){let e=2e8,n=-2e8;for(let r=0;r<t.length;r++){let i=t[r];e!=2e8&&(e=i.map(e,-1),n=i.map(n,1)),i.forEach((o,s,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==2e8?null:{from:e,to:n}}function Iv(t){let e=Bk(t);if(!e)return null;let n=Bk(t.map(r=>r.invert()).reverse());return{fromA:n.from,toA:n.to,fromB:e.from,toB:e.to}}function Av(t,e,n){return n(t.fromB)==e.fromB&&n(t.toB)==e.toB&&Lk(t.deleted,e.deleted)&&Lk(t.inserted,e.inserted)}function Lk(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n].length!=e[n].length||t[n].data!==e[n].data)return!1;return!0}function Rt(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-diff",...e}}),t}var zk=500;function Nv(t={}){let e=new WeakMap,n=new WeakMap;function r(i){let o=e.get(i);if(o!=null)return o;let s=i.attrs,a=s?Object.keys(s).filter(l=>s[l]!=null).sort():[];if(a.length===0)o=i.type.name;else{let l={};for(let c of a)l[c]=s[c];o=`${i.type.name}:${JSON.stringify(l)}`}return e.set(i,o),o}return{encodeCharacter:(i,o)=>{if(o.length===0)return i;let s=n.get(o);return s==null&&(s=o.map(r).join(","),n.set(o,s)),`${i}:${s}`},encodeNodeStart:i=>{let o=i.attrs;if(o&&Object.keys(o).length>0){let s=t[i.type.name]??[],a=Object.keys(o).filter(l=>{if(s.includes(l))return!1;let c=i.type.spec.attrs?.[l]?.default;return o[l]!==c});if(a.length>0){let l={};for(let c of a.sort())l[c]=o[c];return`${i.type.name}:${JSON.stringify(l)}`}}return i.type.name},encodeNodeEnd:i=>{let o=i.type.schema,s=o.cached.changeSetIDs||(o.cached.changeSetIDs=Object.create(null)),a=s[i.type.name];return a==null&&(s[i.type.name]=a=Object.keys(o.nodes).indexOf(i.type.name)+1),-a},compareTokens:(i,o)=>i===o}}function Vk(t,e,n){let r=n.get(t);if(r!=null)return r;let i=[String(e.encodeNodeStart(t))];if(t.isText){let s=t.text;for(let a=0;a<s.length;a++)i.push(":"+String(e.encodeCharacter(s.charCodeAt(a),t.marks)))}else t.content.forEach(s=>{i.push("/"+Vk(s,e,n))});i.push("\\"+String(e.encodeNodeEnd(t)));let o=i.join("");return n.set(t,o),o}function $k(t,e,n){let r=[],i=0;return t.content.forEach(o=>{r.push({node:o,offset:i,size:o.nodeSize,signature:Vk(o,n.encoder,n.sigCache)}),i+=o.nodeSize}),{node:t,contentStart:e,content:r}}function Rv(t,e){let n=t.length,r=e.length,i=Array.from({length:n+1},()=>Array.from({length:r+1},()=>0));for(let l=n-1;l>=0;l--)for(let c=r-1;c>=0;c--)t[l].signature===e[c].signature?i[l][c]=i[l+1][c+1]+1:i[l][c]=Math.max(i[l+1][c],i[l][c+1]);let o=[],s=0,a=0;for(;s<n&&a<r;)t[s].signature===e[a].signature?(o.push([s,a]),s++,a++):i[s+1][a]>=i[s][a+1]?s++:a++;return o}function Ov(t,e){if(t.type!==e.type)return!1;let n=t.type;return!(n.isTextblock||n.isAtom||n.spec.code===!0||!n.isBlock)}function Wk(t,e,n){return Nt.fromJSON({fromA:t.fromA+e,toA:t.toA+e,fromB:t.fromB+n,toB:t.toB+n,deleted:t.deleted.map(r=>({length:r.length,data:r.data})),inserted:t.inserted.map(r=>({length:r.length,data:r.data}))})}function Dv(t,e,n){let r=t.parent.copy(E.from(t.node)),i=e.parent.copy(E.from(e.node)),o=new de(0,r.content.size,new A(i.content,0,0));return ri.create(r,void 0,n.encoder).addSteps(i,[o.getMap()],null).changes.map(s=>Wk(s,t.abs,e.abs))}function _k(t,e){let n=t.content;if(e<n.length)return t.contentStart+n[e].offset;if(e>0){let r=n[e-1];return t.contentStart+r.offset+r.size}return t.contentStart+t.node.content.size}function Bv(t,e,n){return Nt.fromJSON({fromA:e,toA:e+t.size,fromB:n,toB:n,deleted:[{length:t.size,data:null}],inserted:[]})}function Lv(t,e,n){return Nt.fromJSON({fromA:e,toA:e,fromB:n,toB:n+t.size,deleted:[],inserted:[{length:t.size,data:null}]})}function Pv(t,e,n,r,i){let o=new de(0,t.content.size,new A(e.content,0,0));return ri.create(t,void 0,i.encoder).addSteps(e,[o.getMap()],null).changes.map(s=>Wk(s,n,r))}function na(t,e,n,r,i){if(t.childCount>zk||e.childCount>zk)return Pv(t,e,n,r,i);let o=$k(t,n,i),s=$k(e,r,i),a=Rv(o.content,s.content),l=[],c=0,u=0;for(let[f,d]of a)Hk(o,s,{oldStart:c,oldEnd:f,newStart:u,newEnd:d},i,l),c=f+1,u=d+1;return Hk(o,s,{oldStart:c,oldEnd:o.content.length,newStart:u,newEnd:s.content.length},i,l),l}function Hk(t,e,n,r,i){let o=t.content,s=e.content,a=n.oldStart,l=n.newStart;for(;a<n.oldEnd||l<n.newEnd;){let c=a<n.oldEnd?o[a]:null,u=l<n.newEnd?s[l]:null,f=c&&u&&c.node.type===u.node.type;if(c&&u&&f){i.push(...Fv(t,e,c,u,r)),a++,l++;continue}if(c&&(!u||!f)){let d=t.contentStart+c.offset;i.push(Bv(c,d,_k(e,l))),a++;continue}if(u){let d=e.contentStart+u.offset;i.push(Lv(u,_k(t,a),d)),l++}}}function Fv(t,e,n,r,i){let o=t.contentStart+n.offset,s=e.contentStart+r.offset;return Ov(n.node,r.node)&&zv(n.node,r.node,i.encoder)?na(n.node,r.node,o+1,s+1,i):Dv({node:n.node,parent:t.node,abs:o},{node:r.node,parent:e.node,abs:s},i)}function zv(t,e,n){return n.encodeNodeStart(t)===n.encodeNodeStart(e)}function $v(t,e,n,r,i){let o=t.resolve(n),s=t.resolve(r),a=e.resolve(n),l=e.resolve(r),c=o.sharedDepth(r);if(a.sharedDepth(r)!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) resolves to different sharedDepth in old and new docs`);for(let m=0;m<=c;m++){if(i.encodeNodeStart(o.node(m))!==i.encodeNodeStart(a.node(m)))throw new RangeError(`computeDocDiff: ancestor at depth ${m} differs in type or non-ignored attrs along the path to the shared ancestor`);if(o.start(m)!==a.start(m))throw new RangeError(`computeDocDiff: ancestor at depth ${m} starts at different absolute positions in old and new docs (content before the range differs in size)`)}let u=o.node(c);if(u.isTextblock)throw new RangeError(`computeDocDiff: range [${n}, ${r}) lands inside a textblock; widen the range to a block boundary`);if(o.depth!==c||s.depth!==c||a.depth!==c||l.depth!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) endpoints must be aligned to child boundaries of the shared ancestor`);let f=a.node(c),d=o.start(c),p=n-d,h=r-d;return{oldCut:u.copy(u.content.cut(p,h)),newCut:f.copy(f.content.cut(p,h)),cutAbsStart:n}}function co(t,e,n){let r=Nv(n?.ignoreAttrs),i={encoder:r,sigCache:new WeakMap},o=t.content.size,s=e.content.size,a=n?.range;if(a==null)return na(t,e,0,0,i);let l=Math.min(o,s),c=Math.max(0,Math.min(a.from??0,l)),u=Math.max(c,Math.min(a.to??l,l));if(c===u)return[];if(c===0&&u===l&&o===s)return na(t,e,0,0,i);let f=$v(t,e,c,u,r);return na(f.oldCut,f.newCut,f.cutAbsStart,f.cutAbsStart,i)}var jk=Je({ignoreAttrs:{heading:["id"]}},"diffConfig");Rt(jk,{displayName:"Ctx<diffConfig>",group:"Diff"});var Ce=new ee("MILKDOWN_DIFF");function _v(t,e,n){let r=co(t,e.newDoc,n);return{...e,changes:r}}function Hv(t,e){return e.some(n=>t.fromB<n.toB&&t.toB>n.fromB)}function ra(t){return t.changes.filter(e=>!Hv(e,t.rejectedRanges))}var Vv=Se(t=>{let e=t.get(jk.key);return new X({key:Ce,state:{init:()=>null,apply(n,r,i,o){let s=n.getMeta(Ce);if(!r){if(s?.type==="start"){let c=co(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}return null}let a=r;if(n.docChanged&&a.active&&(a=_v(o.doc,a,{ignoreAttrs:e.ignoreAttrs})),!s)return a;let l;switch(s.type){case"start":{let c=co(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}case"accept":case"acceptRange":l=a;break;case"reject":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.fromB,toB:s.toB}]};break;case"rejectRange":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.range.fromB,toB:s.range.toB}]};break;case"acceptAll":case"clear":return null;default:return a}return l.active&&ra(l).length===0?null:l}},filterTransaction(n,r){return!Ce.getState(r)?.active||n.getMeta(Ce)?!0:!n.docChanged}})});Rt(Vv,{displayName:"Prose<diff>",group:"Diff"});function Wv(t,e){let n=ra(e);for(let r=n.length-1;r>=0;r--){let i=n[r],o=e.newDoc.slice(i.fromB,i.toB);t=t.replace(i.fromA,i.toA,o)}return t}var jv=P("StartDiffReview",t=>e=>(n,r)=>{if(e==null)return!1;let i=t.get(Ue)(e);return i?(r&&r(n.tr.setMeta(Ce,{type:"start",newDoc:i})),!0):!1});Rt(jv,{displayName:"Command<startDiffReview>",group:"Diff"});var Sf=P("StartDiffReviewFromDoc",()=>t=>(e,n)=>!t||t.type!==e.doc.type?!1:(n&&n(e.tr.setMeta(Ce,{type:"start",newDoc:t})),!0));Rt(Sf,{displayName:"Command<startDiffReviewFromDoc>",group:"Diff"});var qv=P("AcceptDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Ce.getState(e);if(!r)return!1;let i=ra(r)[t];if(!i)return!1;if(n){let o=r.newDoc.slice(i.fromB,i.toB),s=e.tr.replace(i.fromA,i.toA,o);s=s.setMeta(Ce,{type:"accept",changeIndex:t}),n(s)}return!0});Rt(qv,{displayName:"Command<acceptDiffChunk>",group:"Diff"});var Kv=P("RejectDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Ce.getState(e);if(!r)return!1;let i=ra(r)[t];return i?(n&&n(e.tr.setMeta(Ce,{type:"reject",fromB:i.fromB,toB:i.toB})),!0):!1});Rt(Kv,{displayName:"Command<rejectDiffChunk>",group:"Diff"});var Uv=P("AcceptDiffRange",()=>t=>(e,n)=>{if(!t)return!1;let r=Ce.getState(e);if(!r)return!1;if(n){let i=r.newDoc.slice(t.fromB,t.toB),o=e.tr.replace(t.fromA,t.toA,i);o=o.setMeta(Ce,{type:"acceptRange",range:t}),n(o)}return!0});Rt(Uv,{displayName:"Command<acceptDiffRange>",group:"Diff"});var Jv=P("RejectDiffRange",()=>t=>(e,n)=>!t||!Ce.getState(e)?!1:(n&&n(e.tr.setMeta(Ce,{type:"rejectRange",range:t})),!0));Rt(Jv,{displayName:"Command<rejectDiffRange>",group:"Diff"});var Gv=P("AcceptAllDiffs",()=>()=>(t,e)=>{let n=Ce.getState(t);return n?(e&&e((n.rejectedRanges.length===0?t.tr.replaceWith(0,t.doc.content.size,n.newDoc.content):Wv(t.tr,n)).setMeta(Ce,{type:"acceptAll"})),!0):!1});Rt(Gv,{displayName:"Command<acceptAllDiffs>",group:"Diff"});var Qv=P("ClearDiffReview",()=>()=>(t,e)=>Ce.getState(t)?(e&&e(t.tr.setMeta(Ce,{type:"clear"})),!0):!1);Rt(Qv,{displayName:"Command<clearDiffReview>",group:"Diff"});function ii(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-streaming",...e}}),t}var wn=Je({throttleMs:100,scrollFollow:!0,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}},"streamingConfig");ii(wn,{displayName:"Ctx<streamingConfig>",group:"Streaming"});function Yv(t,e,n){let r=t.get(Ue)(n);if(!r)return{tr:e,newDoc:null};let i=t.get(wn.key).ignoreAttrs,o=co(e.doc,r,i?{ignoreAttrs:i}:void 0);for(let s=o.length-1;s>=0;s--){let a=o[s],l=r.slice(a.fromB,a.toB);e=e.replace(a.fromA,a.toA,l)}return{tr:e,newDoc:r}}function Xv(t){if(t.parent.type.spec.code)return{type:"plain-text",preserveNewlines:!0};for(let e=t.depth;e>0;e--)if(t.node(e).type.name==="table")return{type:"plain-text",preserveNewlines:!1};return t.depth>=1?{type:"split-block"}:{type:"block"}}function qk(t){if(t.childCount===0)return t;let e=t.lastChild;return e.type.name==="paragraph"&&e.content.size===0?t.cut(0,t.size-e.nodeSize):t}function Zv(t,e,n){let{insertPos:r,currentEndPos:i}=n,o=n.buffer.replace(/\r\n?/g,` -`);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=e.doc.content.size,a=Math.max(0,Math.min(r,s)),l=Math.max(a,Math.min(i,s)),c=e.doc.resolve(a),u=(t.get(wn.key).insertStrategy??Xv)(c),f={ctx:t,tr:e,buffer:o,from:a,to:l,resolved:c};switch(u.type){case"plain-text":return eI(f,u.preserveNewlines??!1);case"split-block":return nI(f);case"block":return rI(f)}}function eI({tr:t,buffer:e,from:n,to:r},i){let o=i?e:e.replace(/\n/g," "),s=t.doc.type.schema.text(o);return t=t.replaceWith(n,r,s),{tr:t,applied:!0,insertEndPos:n+o.length}}var tI=/[*_~`[\\<]/;function Cf(t,e,n){if(!n)return E.empty;if(!tI.test(n))return E.from(e.text(n));let r=t.get(Ue)(n)?.firstChild;if(r?.type.name!=="paragraph"||r.content.size===0)return E.from(e.text(n));let i=!1;if(r.content.forEach(l=>{(!l.isText||l.marks.length>0)&&(i=!0)}),!i)return E.from(e.text(n));let o=r.content,s=/^\s+/.exec(n)?.[0];s&&((o.firstChild?.isText?o.firstChild.text??"":"").startsWith(s)||(o=E.from(e.text(s)).append(o)));let a=/\s+$/.exec(n)?.[0];return a&&((o.lastChild?.isText?o.lastChild.text??"":"").endsWith(a)||(o=o.append(E.from(e.text(a))))),o}function nI({ctx:t,tr:e,buffer:n,from:r,to:i,resolved:o}){let s=e.doc.type.schema,a=n.indexOf(` -`);if(a<0){let I=Cf(t,s,n);return e=e.replaceWith(r,i,I),{tr:e,applied:!0,insertEndPos:r+I.size}}let l=n.substring(0,a),c=n.substring(a+1),u=t.get(Ue),f=c.trim()?u(c):null,d=f?qk(f.content):E.empty;if(d.childCount===0){let I=Cf(t,s,n.replace(/\n/g," "));return e=e.replaceWith(r,i,I),{tr:e,applied:!0,insertEndPos:r+I.size}}let p=o.depth,h=Cf(t,s,l);for(let I=p;I>0;I--)h=E.from(o.node(I).copy(h));let m=h.append(d),g=new A(m,p,0),y=e.doc.content.size,x=e.doc.resolve(Math.min(i,y)),C=i;p>0&&x.depth===p&&x.parentOffset===x.parent.content.size&&(C=x.after(p)),e=e.replace(r,C,g);let v=m.size-p;return{tr:e,applied:!0,insertEndPos:r+v}}function rI({ctx:t,tr:e,buffer:n,from:r,to:i}){let o=t.get(Ue)(n);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=qk(o.content);return s.size===0?{tr:e,applied:!1,insertEndPos:i}:(e=e.replace(r,i,new A(s,0,0)),{tr:e,applied:!0,insertEndPos:r+s.size})}function Mf(t,e,n){if(n.insertPos!=null){let r=n.insertPos,i=Zv(t,e,{buffer:n.buffer,insertPos:r,currentEndPos:n.insertEndPos??r});return{tr:i.tr,newDoc:i.applied?i.tr.doc:null,insertEndPos:i.insertEndPos}}return Yv(t,e,n.buffer)}var _e=new ee("MILKDOWN_STREAMING");function iI(t,e){if(!t&&e?.type!=="start")return null;if(!e)return t;switch(e.type){case"start":return{buffer:"",originalDoc:e.originalDoc,active:!0,lastApplyTime:e.lastApplyTime,insertPos:e.insertPos??null,insertEndPos:e.insertEndPos??e.insertPos??null};case"push":return t?{...t,buffer:t.buffer+e.token}:null;case"apply":return t?{...t,lastApplyTime:e.lastApplyTime,insertEndPos:e.insertEndPos??t.insertEndPos}:null;case"end":case"abort":return null;default:return t}}var Kk=Se(t=>{let e=t.get(wn.key);return new X({key:_e,state:{init:()=>null,apply(n,r){return iI(r,n.getMeta(_e))}},filterTransaction(n,r){return!_e.getState(r)?.active||n.getMeta(_e)?!0:!n.docChanged},view(){return oI(t,e)}})});ii(Kk,{displayName:"Prose<streaming>",group:"Streaming"});function oI(t,e){let n=null,r=-1,i=null;function o(){if(!i)return;let a=_e.getState(i.state);if(!a?.active||a.buffer.length===r)return;r=a.buffer.length;let l=Mf(t,i.state.tr,a);if(!l.newDoc)return;let c=l.tr;!c.docChanged&&l.insertEndPos==null||(c=c.setMeta(_e,{type:"apply",lastApplyTime:Date.now(),insertEndPos:l.insertEndPos}),e.scrollFollow&&(c=c.scrollIntoView()),i.dispatch(c))}function s(){n!=null&&clearTimeout(n),n=setTimeout(o,e.throttleMs)}return{update(a){i=a;let l=_e.getState(a.state);if(!l?.active){n!=null&&(clearTimeout(n),n=null),r=-1;return}l.buffer.length!==r&&(Date.now()-l.lastApplyTime>=e.throttleMs?o():s())},destroy(){n!=null&&(clearTimeout(n),n=null),i=null}}}var uo=P("StartStreaming",()=>t=>(e,n)=>{if(_e.getState(e)?.active)return!1;if(n){let r,i;if(t?.insertAt!=null)if(t.insertAt==="selection"){if(r=e.selection.from,i=e.selection.to,e.selection.empty){let o=e.doc.resolve(r);o.parent.isTextblock&&!o.parent.type.spec.code&&o.parent.content.size===0&&o.depth===1&&(r=o.before(o.depth),i=o.after(o.depth))}}else{let o=t.insertAt==="cursor"?e.selection.head:t.insertAt;if(!Number.isFinite(o))return!1;r=Math.max(0,Math.min(Math.round(o),e.doc.content.size));let s=e.doc.resolve(r);s.parent.isTextblock&&!s.parent.type.spec.code&&s.parent.content.size===0&&s.depth===1&&(r=s.before(s.depth),i=s.after(s.depth))}n(e.tr.setMeta(_e,{type:"start",originalDoc:e.doc,insertPos:r,insertEndPos:i,lastApplyTime:Date.now()}))}return!0});ii(uo,{displayName:"Command<startStreaming>",group:"Streaming"});var ia=P("PushChunk",()=>t=>(e,n)=>t==null||!_e.getState(e)?.active?!1:(n&&n(e.tr.setMeta(_e,{type:"push",token:t})),!0));ii(ia,{displayName:"Command<pushChunk>",group:"Streaming"});var fo=P("EndStreaming",t=>e=>(n,r)=>{let i=_e.getState(n);if(!i?.active)return!1;if(r){let o=t.get(wn.key),s=e?.diffReview??o.diffReviewOnEnd,a=Mf(t,n.tr,i),l=a.tr;if(l=l.setMeta(_e,{type:"end"}),s&&a.newDoc){let c=l.doc;l=l.replace(0,l.doc.content.size,new A(i.originalDoc.content,0,0)),r(l);try{t.get(G).call(Sf.key,c)}catch(u){console.warn("[milkdown/streaming] diff review handoff skipped:",u)}return!0}r(l)}return!0});ii(fo,{displayName:"Command<endStreaming>",group:"Streaming"});var oa=P("AbortStreaming",t=>e=>(n,r)=>{let i=_e.getState(n);if(!i?.active)return!1;if(r){let o=e?.keep??!1,s=n.tr;o?s=Mf(t,s,i).tr:s=s.replace(0,n.doc.content.size,new A(i.originalDoc.content,0,0)),s=s.setMeta(_e,{type:"abort"}),r(s)}return!0});ii(oa,{displayName:"Command<abortStreaming>",group:"Streaming"});var Uk=[wn,Kk,uo,ia,fo,oa];var Jk=new ee("weibeiStreamingAppearance"),sI={class:"wb-stream-in"},aI={side:1},lI=260,cI=400,uI=24;function fI(){let t=document.createElement("span");return t.className="wb-stream-caret",t}function Gk(t){return new X({key:Jk,state:{init:()=>({fades:[],caretPosition:null,caretExpiresAt:0,set:ne.empty}),apply(e,n){let r=Date.now(),i=[];for(let l of n.fades){let c=e.mapping.map(l.from),u=e.mapping.map(l.to);c>=u||r>=l.expiresAt||e.doc.resolve(c).parent===e.doc.resolve(u).parent&&i.push({from:c,to:u,expiresAt:l.expiresAt})}let o=n.caretPosition===null?null:e.mapping.map(n.caretPosition),s=n.caretExpiresAt;e.docChanged&&t()&&e.steps.forEach((l,c)=>{let u=e.mapping.slice(c+1);e.mapping.maps[c].forEach((f,d,p,h)=>{if(h<=p)return;let m=u.map(p),g=u.map(h);if(g-m>uI)return;let y=e.doc.resolve(m);y.parent===e.doc.resolve(g).parent&&y.parent.isTextblock&&(i.push({from:m,to:g,expiresAt:r+lI}),o=g,s=r+cI)})}),o!==null&&r>=s&&(o=null);let a=i.map(l=>se.inline(l.from,l.to,sI));return o!==null&&a.push(se.widget(o,fI,aI)),{fades:i,caretPosition:o,caretExpiresAt:s,set:ne.create(e.doc,a)}}},props:{decorations(e){let n=Jk.getState(e);return!n||!t()?ne.empty:n.set}}})}function Ef(){return{enter:{mathFlow:t,mathFlowFenceMeta:e,mathText:o},exit:{mathFlow:i,mathFlowFence:r,mathFlowFenceMeta:n,mathFlowValue:a,mathText:s,mathTextData:a}};function t(l){let c={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[c]}},l)}function e(){this.buffer()}function n(){let l=this.resume(),c=this.stack[this.stack.length-1];c.type,c.meta=l}function r(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function i(l){let c=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c;let f=u.data.hChildren[0];f.type,f.tagName,f.children.push({type:"text",value:c}),this.data.mathFlowInside=void 0}function o(l){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},l),this.buffer()}function s(l){let c=this.resume(),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c,u.data.hChildren.push({type:"text",value:c})}function a(l){this.config.enter.data.call(this,l),this.config.exit.data.call(this,l)}}function Tf(t){let e=(t||{}).singleDollarTextMath;return e==null&&(e=!0),r.peek=i,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:` +`))}function l(p,h,m,g){let y=m.enter("tableCell"),x=m.enter("phrasing"),C=m.containerPhrasing(p,{...g,before:o,after:o});return x(),y(),C}function c(p,h){return $y(p,{align:h,alignDelimiters:r,padding:n,stringLength:i})}function u(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("table");for(;++y<g.length;)x[y]=f(g[y],h,m);return C(),x}function f(p,h,m){let g=p.children,y=-1,x=[],C=h.enter("tableRow");for(;++y<g.length;)x[y]=l(g[y],p,h,m);return C(),x}function d(p,h,m){let g=Bn.inlineCode(p,h,m);return m.stack.includes("tableCell")&&(g=g.replace(/\|/g,"\\$&")),g}}function Ku(){return{exit:{taskListCheckValueChecked:Hy,taskListCheckValueUnchecked:Hy,paragraph:sT}}}function Uu(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:aT}}}function Hy(t){let e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function sT(t){let e=this.stack[this.stack.length-2];if(e&&e.type==="listItem"&&typeof e.checked=="boolean"){let n=this.stack[this.stack.length-1];n.type;let r=n.children[0];if(r&&r.type==="text"){let i=e.children,o=-1,s;for(;++o<i.length;){let a=i[o];if(a.type==="paragraph"){s=a;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(t)}function aT(t,e,n,r){let i=t.children[0],o=typeof t.checked=="boolean"&&i&&i.type==="paragraph",s="["+(t.checked?"x":" ")+"] ",a=n.createTracker(r);o&&a.move(s);let l=Bn.listItem(t,e,n,{...r,...a.current()});return o&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+s}}function Ju(){return[Fu(),$u(),Hu(),ju(),Ku()]}function Gu(t){return{extensions:[zu(),_u(t),Vu(),qu(t),Uu()]}}var lT={tokenize:pT,partial:!0},Vy={tokenize:hT,partial:!0},Wy={tokenize:mT,partial:!0},jy={tokenize:gT,partial:!0},cT={tokenize:yT,partial:!0},qy={name:"wwwAutolink",tokenize:fT,previous:Uy},Ky={name:"protocolAutolink",tokenize:dT,previous:Jy},Yt={name:"emailAutolink",tokenize:uT,previous:Gy},At={};function Yu(){return{text:At}}var ar=48;for(;ar<123;)At[ar]=Yt,ar++,ar===58?ar=65:ar===91&&(ar=97);At[43]=Yt;At[45]=Yt;At[46]=Yt;At[95]=Yt;At[72]=[Yt,Ky];At[104]=[Yt,Ky];At[87]=[Yt,qy];At[119]=[Yt,qy];function uT(t,e,n){let r=this,i,o;return s;function s(f){return!Qu(f)||!Gy.call(r,r.previous)||Xu(r.events)?n(f):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(f))}function a(f){return Qu(f)?(t.consume(f),a):f===64?(t.consume(f),l):n(f)}function l(f){return f===46?t.check(cT,u,c)(f):f===45||f===95||ye(f)?(o=!0,t.consume(f),l):u(f)}function c(f){return t.consume(f),i=!0,l}function u(f){return o&&i&&ge(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(f)):n(f)}}function fT(t,e,n){let r=this;return i;function i(s){return s!==87&&s!==119||!Uy.call(r,r.previous)||Xu(r.events)?n(s):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(lT,t.attempt(Vy,t.attempt(Wy,o),n),n)(s))}function o(s){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(s)}}function dT(t,e,n){let r=this,i="",o=!1;return s;function s(f){return(f===72||f===104)&&Jy.call(r,r.previous)&&!Xu(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),t.consume(f),a):n(f)}function a(f){if(ge(f)&&i.length<5)return i+=String.fromCodePoint(f),t.consume(f),a;if(f===58){let d=i.toLowerCase();if(d==="http"||d==="https")return t.consume(f),l}return n(f)}function l(f){return f===47?(t.consume(f),o?c:(o=!0,l)):n(f)}function c(f){return f===null||Tn(f)||U(f)||Et(f)||vn(f)?n(f):t.attempt(Vy,t.attempt(Wy,u),n)(f)}function u(f){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(f)}}function pT(t,e,n){let r=0;return i;function i(s){return(s===87||s===119)&&r<3?(r++,t.consume(s),i):s===46&&r===3?(t.consume(s),o):n(s)}function o(s){return s===null?n(s):e(s)}}function hT(t,e,n){let r,i,o;return s;function s(c){return c===46||c===95?t.check(jy,l,a)(c):c===null||U(c)||Et(c)||c!==45&&vn(c)?l(c):(o=!0,t.consume(c),s)}function a(c){return c===95?r=!0:(i=r,r=void 0),t.consume(c),s}function l(c){return i||r||!o?n(c):e(c)}}function mT(t,e){let n=0,r=0;return i;function i(s){return s===40?(n++,t.consume(s),i):s===41&&r<n?o(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?t.check(jy,e,o)(s):s===null||U(s)||Et(s)?e(s):(t.consume(s),i)}function o(s){return s===41&&r++,t.consume(s),i}}function gT(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),o):a===93?(t.consume(a),i):a===60||a===null||U(a)||Et(a)?e(a):n(a)}function i(a){return a===null||a===40||a===91||U(a)||Et(a)?e(a):r(a)}function o(a){return ge(a)?s(a):n(a)}function s(a){return a===59?(t.consume(a),r):ge(a)?(t.consume(a),s):n(a)}}function yT(t,e,n){return r;function r(o){return t.consume(o),i}function i(o){return ye(o)?n(o):e(o)}}function Uy(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||U(t)}function Jy(t){return!ge(t)}function Gy(t){return!(t===47||Qu(t))}function Qu(t){return t===43||t===45||t===46||t===95||ye(t)}function Xu(t){let e=t.length,n=!1;for(;e--;){let r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var kT={tokenize:ET,partial:!0};function Zu(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:ST,continuation:{tokenize:CT},exit:MT}},text:{91:{name:"gfmFootnoteCall",tokenize:wT},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:bT,resolveTo:xT}}}}function bT(t,e,n){let r=this,i=r.events.length,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),s;for(;i--;){let l=r.events[i][1];if(l.type==="labelImage"){s=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!s||!s._balanced)return n(l);let c=Ae(r.sliceSerialize({start:s.end,end:r.now()}));return c.codePointAt(0)!==94||!o.includes(c.slice(1))?n(l):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(l),t.exit("gfmFootnoteCallLabelMarker"),e(l))}}function xT(t,e){let n=t.length,r;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){r=t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";let i={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;let s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},t[t.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},l=[t[n+1],t[n+2],["enter",i,e],t[n+3],t[n+4],["enter",o,e],["exit",o,e],["enter",s,e],["enter",a,e],["exit",a,e],["exit",s,e],t[t.length-2],t[t.length-1],["exit",i,e]];return t.splice(n,t.length-n+1,...l),t}function wT(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o=0,s;return a;function a(f){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(t.enter("gfmFootnoteCallMarker"),t.consume(f),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",c)}function c(f){if(o>999||f===93&&!s||f===null||f===91||U(f))return n(f);if(f===93){t.exit("chunkString");let d=t.exit("gfmFootnoteCallString");return i.includes(Ae(r.sliceSerialize(d)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(f),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(f)}return U(f)||(s=!0),o++,t.consume(f),f===92?u:c}function u(f){return f===91||f===92||f===93?(t.consume(f),o++,c):c(f)}}function ST(t,e,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o,s=0,a;return l;function l(h){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(h){return h===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",u):n(h)}function u(h){if(s>999||h===93&&!a||h===null||h===91||U(h))return n(h);if(h===93){t.exit("chunkString");let m=t.exit("gfmFootnoteDefinitionLabelString");return o=Ae(r.sliceSerialize(m)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(h),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),d}return U(h)||(a=!0),s++,t.consume(h),h===92?f:u}function f(h){return h===91||h===92||h===93?(t.consume(h),s++,u):u(h)}function d(h){return h===58?(t.enter("definitionMarker"),t.consume(h),t.exit("definitionMarker"),i.includes(o)||i.push(o),F(t,p,"gfmFootnoteDefinitionWhitespace")):n(h)}function p(h){return e(h)}}function CT(t,e,n){return t.check(Tt,e,t.attempt(kT,e,n))}function MT(t){t.exit("gfmFootnoteDefinition")}function ET(t,e,n){let r=this;return F(t,i,"gfmFootnoteDefinitionIndent",5);function i(o){let s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?e(o):n(o)}}function ef(t){let n=(t||{}).singleTilde,r={name:"strikethrough",tokenize:o,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(s,a){let l=-1;for(;++l<s.length;)if(s[l][0]==="enter"&&s[l][1].type==="strikethroughSequenceTemporary"&&s[l][1]._close){let c=l;for(;c--;)if(s[c][0]==="exit"&&s[c][1].type==="strikethroughSequenceTemporary"&&s[c][1]._open&&s[l][1].end.offset-s[l][1].start.offset===s[c][1].end.offset-s[c][1].start.offset){s[l][1].type="strikethroughSequence",s[c][1].type="strikethroughSequence";let u={type:"strikethrough",start:Object.assign({},s[c][1].start),end:Object.assign({},s[l][1].end)},f={type:"strikethroughText",start:Object.assign({},s[c][1].end),end:Object.assign({},s[l][1].start)},d=[["enter",u,a],["enter",s[c][1],a],["exit",s[c][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&ue(d,d.length,0,nn(p,s.slice(c+1,l),a)),ue(d,d.length,0,[["exit",f,a],["enter",s[l][1],a],["exit",s[l][1],a],["exit",u,a]]),ue(s,c-1,l-c+3,d),l=c+d.length-2;break}}for(l=-1;++l<s.length;)s[l][1].type==="strikethroughSequenceTemporary"&&(s[l][1].type="data");return s}function o(s,a,l){let c=this.previous,u=this.events,f=0;return d;function d(h){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(h):(s.enter("strikethroughSequenceTemporary"),p(h))}function p(h){let m=zt(c);if(h===126)return f>1?l(h):(s.consume(h),f++,p);if(f<2&&!n)return l(h);let g=s.exit("strikethroughSequenceTemporary"),y=zt(h);return g._open=!y||y===2&&!!m,g._close=!m||m===2&&!!y,a(h)}}}var Qs=class{constructor(){this.map=[]}add(e,n,r){TT(this,e,n,r)}consume(e){if(this.map.sort(function(o,s){return o[0]-s[0]}),this.map.length===0)return;let n=this.map.length,r=[];for(;n>0;)n-=1,r.push(e.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),e.length=this.map[n][0];r.push(e.slice()),e.length=0;let i=r.pop();for(;i;){for(let o of i)e.push(o);i=r.pop()}this.map.length=0}};function TT(t,e,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<t.map.length;){if(t.map[i][0]===e){t.map[i][1]+=n,t.map[i][2].push(...r);return}i+=1}t.map.push([e,n,r])}}function Qy(t,e){let n=!1,r=[];for(;e<t.length;){let i=t[e];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(t[e+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(t[e-1][1].type==="tableDelimiterMarker"){let o=r.length-1;r[o]=r[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);e+=1}return r}function tf(){return{flow:{null:{name:"table",tokenize:vT,resolveAll:IT}}}}function vT(t,e,n){let r=this,i=0,o=0,s;return a;function a(S){let ce=r.events.length-1;for(;ce>-1;){let W=r.events[ce][1].type;if(W==="lineEnding"||W==="linePrefix")ce--;else break}let Y=ce>-1?r.events[ce][1].type:null,L=Y==="tableHead"||Y==="tableRow"?w:l;return L===w&&r.parser.lazy[r.now().line]?n(S):L(S)}function l(S){return t.enter("tableHead"),t.enter("tableRow"),c(S)}function c(S){return S===124||(s=!0,o+=1),u(S)}function u(S){return S===null?n(S):R(S)?o>1?(o=0,r.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(S),t.exit("lineEnding"),p):n(S):_(S)?F(t,u,"whitespace")(S):(o+=1,s&&(s=!1,i+=1),S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),s=!0,u):(t.enter("data"),f(S)))}function f(S){return S===null||S===124||U(S)?(t.exit("data"),u(S)):(t.consume(S),S===92?d:f)}function d(S){return S===92||S===124?(t.consume(S),f):f(S)}function p(S){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(S):(t.enter("tableDelimiterRow"),s=!1,_(S)?F(t,h,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):h(S))}function h(S){return S===45||S===58?g(S):S===124?(s=!0,t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),m):I(S)}function m(S){return _(S)?F(t,g,"whitespace")(S):g(S)}function g(S){return S===58?(o+=1,s=!0,t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),y):S===45?(o+=1,y(S)):S===null||R(S)?v(S):I(S)}function y(S){return S===45?(t.enter("tableDelimiterFiller"),x(S)):I(S)}function x(S){return S===45?(t.consume(S),x):S===58?(s=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(S),t.exit("tableDelimiterMarker"),C):(t.exit("tableDelimiterFiller"),C(S))}function C(S){return _(S)?F(t,v,"whitespace")(S):v(S)}function v(S){return S===124?h(S):S===null||R(S)?!s||i!==o?I(S):(t.exit("tableDelimiterRow"),t.exit("tableHead"),e(S)):I(S)}function I(S){return n(S)}function w(S){return t.enter("tableRow"),N(S)}function N(S){return S===124?(t.enter("tableCellDivider"),t.consume(S),t.exit("tableCellDivider"),N):S===null||R(S)?(t.exit("tableRow"),e(S)):_(S)?F(t,N,"whitespace")(S):(t.enter("data"),D(S))}function D(S){return S===null||S===124||U(S)?(t.exit("data"),N(S)):(t.consume(S),S===92?B:D)}function B(S){return S===92||S===124?(t.consume(S),D):D(S)}}function IT(t,e){let n=-1,r=!0,i=0,o=[0,0,0,0],s=[0,0,0,0],a=!1,l=0,c,u,f,d=new Qs;for(;++n<t.length;){let p=t[n],h=p[1];p[0]==="enter"?h.type==="tableHead"?(a=!1,l!==0&&(Yy(d,e,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",c,e]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(r=!0,f=void 0,o=[0,0,0,0],s=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},d.add(n,0,[["enter",u,e]])),i=h.type==="tableDelimiterRow"?2:u?3:1):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(o[1]!==0&&(s[0]=s[1],f=Ys(d,e,o,i,void 0,f),o=[0,0,0,0]),s[2]=n)):h.type==="tableCellDivider"&&(r?r=!1:(o[1]!==0&&(s[0]=s[1],f=Ys(d,e,o,i,void 0,f)),o=s,s=[o[1],n,0,0])):h.type==="tableHead"?(a=!0,l=n):h.type==="tableRow"||h.type==="tableDelimiterRow"?(l=n,o[1]!==0?(s[0]=s[1],f=Ys(d,e,o,i,n,f)):s[1]!==0&&(f=Ys(d,e,s,i,n,f)),i=0):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(s[3]=n)}for(l!==0&&Yy(d,e,l,c,u),d.consume(e.events),n=-1;++n<e.events.length;){let p=e.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Qy(e.events,n))}return t}function Ys(t,e,n,r,i,o){let s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(o.end=Object.assign({},Zr(e.events,n[0])),t.add(n[0],0,[["exit",o,e]]));let l=Zr(e.events,n[1]);if(o={type:s,start:Object.assign({},l),end:Object.assign({},l)},t.add(n[1],0,[["enter",o,e]]),n[2]!==0){let c=Zr(e.events,n[2]),u=Zr(e.events,n[3]),f={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(t.add(n[2],0,[["enter",f,e]]),r!==2){let d=e.events[n[2]],p=e.events[n[3]];if(d[1].end=Object.assign({},p[1].end),d[1].type="chunkText",d[1].contentType="text",n[3]>n[2]+1){let h=n[2]+1,m=n[3]-n[2]-1;t.add(h,m,[])}}t.add(n[3]+1,0,[["exit",f,e]])}return i!==void 0&&(o.end=Object.assign({},Zr(e.events,i)),t.add(i,0,[["exit",o,e]]),o=void 0),o}function Yy(t,e,n,r,i){let o=[],s=Zr(e.events,n);i&&(i.end=Object.assign({},s),o.push(["exit",i,e])),r.end=Object.assign({},s),o.push(["exit",r,e]),t.add(n+1,0,o)}function Zr(t,e){let n=t[e],r=n[0]==="enter"?"start":"end";return n[1][r]}var AT={name:"tasklistCheck",tokenize:NT};function nf(){return{text:{91:AT}}}function NT(t,e,n){let r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),o)}function o(l){return U(l)?(t.enter("taskListCheckValueUnchecked"),t.consume(l),t.exit("taskListCheckValueUnchecked"),s):l===88||l===120?(t.enter("taskListCheckValueChecked"),t.consume(l),t.exit("taskListCheckValueChecked"),s):n(l)}function s(l){return l===93?(t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),a):n(l)}function a(l){return R(l)?e(l):_(l)?t.check({tokenize:RT},e,n)(l):n(l)}}function RT(t,e,n){return F(t,r,"whitespace");function r(i){return i===null?n(i):e(i)}}function Xy(t){return Co([Yu(),Zu(),ef(t),tf(),nf()])}var OT={};function Xs(t){let e=this,n=t||OT,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Xy(n)),o.push(Ju()),s.push(Gu(n))}function V(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-gfm",...e}}),t}var sf=rr("strike_through");V(sf,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var ro=yt("strike_through",t=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:e=>e==="line-through"}],toDOM:e=>["del",t.get(sf.key)(e)],parseMarkdown:{match:e=>e.type==="delete",runner:(e,n,r)=>{e.openMark(r),e.next(n.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strike_through",runner:(e,n)=>{e.withMark(n,"delete")}}}));V(ro.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});V(ro.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var af=P("ToggleStrikeThrough",t=>()=>Ar(ro.type(t)));V(af,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var ek=fe(t=>Ht(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,ro.type(t)));V(ek,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var lf=ze("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:t=>{let e=t.get(G);return()=>e.call(af.key)}}});V(lf.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});V(lf.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var io=hy({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:t=>t.style.textAlign||"left",setDOMAttr:(t,e)=>{e.style=`text-align: ${t||"left"}`}}}}),Xt=ne("table",()=>({...io.table,content:"table_header_row table_row+",disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="table",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r,isHeader:s===0}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table",runner:(t,e)=>{let n=e.content.firstChild?.content;if(!n)return;let r=[];n.forEach(i=>{r.push(i.attrs.alignment)}),t.openNode("table",void 0,{align:r}),t.next(e.content),t.closeNode()}}}));V(Xt.node,{displayName:"NodeSchema<table>",group:"Table"});V(Xt.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var oo=ne("table_header_row",()=>({...io.table_row,disableDropCursor:!0,content:"(table_header)*",parseDOM:[{tag:"tr[data-is-header]"},{tag:"tr",getAttrs:t=>t instanceof HTMLElement&&t.querySelector("th")?{}:!1}],toDOM(){return["tr",{"data-is-header":!0},0]},parseMarkdown:{match:t=>!!(t.type==="tableRow"&&t.isHeader),runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s],isHeader:e.isHeader}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow",void 0,{isHeader:!0}),t.next(e.content),t.closeNode())}}}));V(oo.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});V(oo.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var ti=ne("table_row",()=>({...io.table_row,disableDropCursor:!0,content:"(table_cell)*",parseMarkdown:{match:t=>t.type==="tableRow",runner:(t,e,n)=>{let r=e.align,i=e.children.map((o,s)=>({...o,align:r[s]}));t.openNode(n),t.next(i),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_row",runner:(t,e)=>{e.content.size!==0&&(t.openNode("tableRow"),t.next(e.content),t.closeNode())}}}));V(ti.node,{displayName:"NodeSchema<tableRow>",group:"Table"});V(ti.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var so=ne("table_cell",()=>({...io.table_cell,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}).openNode(t.schema.nodes.paragraph).next(e.children).closeNode().closeNode()}},toMarkdown:{match:t=>t.type.name==="table_cell",runner:(t,e)=>{t.openNode("tableCell").next(e.content).closeNode()}}}));V(so.node,{displayName:"NodeSchema<tableCell>",group:"Table"});V(so.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var ei=ne("table_header",()=>({...io.table_header,disableDropCursor:!0,parseMarkdown:{match:t=>t.type==="tableCell"&&!!t.isHeader,runner:(t,e,n)=>{let r=e.align;t.openNode(n,{alignment:r}),t.openNode(t.schema.nodes.paragraph),t.next(e.children),t.closeNode(),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="table_header",runner:(t,e)=>{t.openNode("tableCell"),t.next(e.content),t.closeNode()}}}));V(ei.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});V(ei.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function tk(t,e=3,n=3){let r=Array(n).fill(0).map(()=>so.type(t).createAndFill()),i=Array(n).fill(0).map(()=>ei.type(t).createAndFill()),o=Array(e).fill(0).map((s,a)=>a===0?oo.type(t).create(null,i):ti.type(t).create(null,r));return Xt.type(t).create(null,o)}function nk(t){return(e,n)=>r=>{n=n??r.selection.from;let i=r.doc.resolve(n),o=_h(l=>l.type.name==="table")(i),s=o?{node:o.node,from:o.start}:void 0,a=t==="row";if(s){let l=Z.get(s.node);if(e>=0&&e<(a?l.height:l.width)){let c=l.positionAt(a?e:l.height-1,a?l.width-1:e,s.node),u=r.doc.resolve(s.from+c),f=a?ae.rowSelection:ae.colSelection,d=l.positionAt(a?e:0,a?0:e,s.node),p=r.doc.resolve(s.from+d);return _l(r.setSelection(f(u,p)))}}return r}}var DT=nk("row"),BT=nk("col");function rk(t,e,{map:n,tableStart:r,table:i},o){let s=Array(o).fill(0).reduce((l,c,u)=>l+i.child(u).nodeSize,r),a=Array(n.width).fill(0).map((l,c)=>{let u=i.nodeAt(n.map[c]);return so.type(t).createAndFill({alignment:u?.attrs.alignment})});return e.insert(s,ti.type(t).create(null,a)),e}function LT(t){let e=Xr(t.$from);if(!e)return;let n=Z.get(e.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(r=>{let i=e.node.nodeAt(r),o=r+e.start;return{pos:o,start:o+1,node:i}})}function PT(t){let e=LT(t.selection);if(e&&e[0]){let n=t.doc.resolve(e[0].pos),r=e[e.length-1];if(r){let i=t.doc.resolve(r.pos);return _l(t.setSelection(new ae(i,n)))}}return t}var cf=P("GoToPrevTableCell",()=>()=>Js(-1));V(cf,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var uf=P("GoToNextTableCell",()=>()=>Js(1));V(uf,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var ff=P("ExitTable",t=>()=>(e,n)=>{if(!Ie(e))return!1;let{$head:r}=e.selection,i=$h(r,Xt.type(t));if(!i)return!1;let{to:o}=i,s=e.tr.replaceWith(o,o,kt.type(t).createAndFill());return s.setSelection($.near(s.doc.resolve(o),1)).scrollIntoView(),n?.(s),!0});V(ff,{displayName:"Command<breakTableCommand>",group:"Table"});var ik=P("InsertTable",t=>({row:e,col:n}={})=>(r,i)=>{let{selection:o,tr:s}=r,{from:a}=o,l=tk(t,e,n),c=s.replaceSelectionWith(l),u=$.findFrom(c.doc.resolve(a),1,!0);return u&&c.setSelection(u),i?.(c),!0});V(ik,{displayName:"Command<insertTableCommand>",group:"Table"});var ok=P("MoveRow",()=>({from:t,to:e,pos:n}={})=>Ty({from:t??0,to:e??0,pos:n}));V(ok,{displayName:"Command<moveRowCommand>",group:"Table"});var sk=P("MoveCol",()=>({from:t,to:e,pos:n}={})=>vy({from:t??0,to:e??0,pos:n}));V(sk,{displayName:"Command<moveColCommand>",group:"Table"});var ak=P("SelectRow",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(DT(t.index,t.pos)(r))});V(ak,{displayName:"Command<selectRowCommand>",group:"Table"});var lk=P("SelectCol",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(BT(t.index,t.pos)(r))});V(lk,{displayName:"Command<selectColCommand>",group:"Table"});var ck=P("SelectTable",()=>()=>(t,e)=>{let{tr:n}=t;return!!e?.(PT(n))});V(ck,{displayName:"Command<selectTableCommand>",group:"Table"});var uk=P("DeleteSelectedCells",()=>()=>(t,e)=>{let{selection:n}=t;if(!(n instanceof ae))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?Ey(t,e):i?Ks(t,e):Us(t,e)});V(uk,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var fk=P("AddColBefore",()=>()=>Sy);V(fk,{displayName:"Command<addColBeforeCommand>",group:"Table"});var dk=P("AddColAfter",()=>()=>qs);V(dk,{displayName:"Command<addColAfterCommand>",group:"Table"});var pk=P("AddRowBefore",t=>()=>(e,n)=>{if(!Ie(e))return!1;if(n){let r=bt(e);n(rk(t,e.tr,r,r.top))}return!0});V(pk,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var hk=P("AddRowAfter",t=>()=>(e,n)=>{if(!Ie(e))return!1;if(n){let r=bt(e);n(rk(t,e.tr,r,r.bottom))}return!0});V(hk,{displayName:"Command<addRowAfterCommand>",group:"Table"});var mk=P("SetAlign",()=>(t="left")=>My("alignment",t));V(mk,{displayName:"Command<setAlignCommand>",group:"Table"});var gk=fe(t=>new ke(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(e,n,r,i)=>{let o=e.doc.resolve(r);if(!o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),Xt.type(t)))return null;let s=tk(t,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),a=e.tr.replaceRangeWith(r,i,s);return a.setSelection(z.create(a.doc,r+3)).scrollIntoView()}));V(gk,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var yk=Mg(t=>({run:(e,n,r)=>{if(r)return e;function i(c){let u=c.childCount,f=c.lastChild?.childCount??0;if(u===0||f===0)return kt.type(t).create();let d=c.firstChild;if(!(f>0&&d&&d.childCount===0))return c;if(u>=3){let g=c.child(1),y=[];for(let v=0;v<g.childCount;v++){let I=g.child(v);y.push(ei.type(t).create(I.attrs,I.content,I.marks))}let x=d.type.create(d.attrs,y),C=[];for(let v=2;v<u;v++)C.push(c.child(v));return c.type.create(c.attrs,[x,...C])}let p=Array(f).fill(0).map(()=>ei.type(t).createAndFill()),h=new A(E.from(p),0,0),m=d.replace(0,0,h);return c.replace(0,d.nodeSize,new A(E.from(m),0,0))}function o(c){let u=ti.type(t),f=[],d=[],p=!1;function h(){if(d.length===0)return;let m=oo.type(t).createAndFill(),g=Xt.type(t).create(null,[m,...d]);f.push(i(g)),d=[]}return c.forEach(m=>{m.type===u?(p=!0,d.push(m)):(h(),f.push(m))}),h(),p?E.from(f):c}function s(c){let u=o(c),f=u!==c,d=[];return u.forEach(p=>{if(p.type===Xt.type(t)){let h=i(p);h!==p&&(f=!0),d.push(h)}else if(p.childCount>0){let h=s(p.content);h!==p.content?(f=!0,d.push(p.copy(h))):d.push(p)}else d.push(p)}),f?E.from(d):c}function a(c){let u=[],f=[];c.forEach(d=>f.push(d));for(let d=0;d<f.length;d++){let p=f[d],h=f[d+1];p.type===kt.type(t)&&p.content.size===0&&h&&h.type===Xt.type(t)||u.push(p)}return u.length<f.length?E.from(u):c}let l=s(e.content);return l=a(l),new A(E.from(l),e.openStart,e.openEnd)}}));V(yk,{displayName:"PasteRule<table>",group:"Table"});var df=ze("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:t=>{let e=t.get(G);return()=>e.call(uf.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:t=>{let e=t.get(G);return()=>e.call(cf.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:t=>{let e=t.get(G);return()=>e.call(ff.key)}}});V(df.ctx,{displayName:"KeymapCtx<table>",group:"Table"});V(df.shortcuts,{displayName:"Keymap<table>",group:"Table"});var rf="footnote_definition",Zy="footnoteDefinition",pf=ne("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${rf}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw tt(t);return{label:t.dataset.label}},contentElement:"dd"}],toDOM:t=>{let e=t.attrs.label;return["dl",{"data-label":e,"data-type":rf},["dt",e],["dd",0]]},parseMarkdown:{match:({type:t})=>t===Zy,runner:(t,e,n)=>{t.openNode(n,{label:e.label}).next(e.children).closeNode()}},toMarkdown:{match:t=>t.type.name===rf,runner:(t,e)=>{t.openNode(Zy,void 0,{label:e.attrs.label,identifier:e.attrs.label}).next(e.content).closeNode()}}}));V(pf.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});V(pf.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var of="footnote_reference",hf=ne("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${of}"]`,getAttrs:t=>{if(!(t instanceof HTMLElement))throw tt(t);return{label:t.dataset.label}}}],toDOM:t=>{let e=t.attrs.label;return["sup",{"data-label":e,"data-type":of},e]},parseMarkdown:{match:({type:t})=>t==="footnoteReference",runner:(t,e,n)=>{t.addNode(n,{label:e.label})}},toMarkdown:{match:t=>t.type.name===of,runner:(t,e)=>{t.addNode("footnoteReference",void 0,void 0,{label:e.attrs.label,identifier:e.attrs.label})}}}));V(hf.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});V(hf.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var mf=It.extendSchema(t=>e=>{let n=t(e);return{...n,attrs:{...n.attrs,checked:{default:null,validate:"boolean|null"}},parseDOM:[{tag:'li[data-item-type="task"]',getAttrs:r=>{if(!(r instanceof HTMLElement))throw tt(r);return{label:r.dataset.label,listType:r.dataset.listType,spread:r.dataset.spread,checked:r.dataset.checked?r.dataset.checked==="true":null}}},...n?.parseDOM||[]],toDOM:r=>n.toDOM&&r.attrs.checked==null?n.toDOM(r):["li",{"data-item-type":"task","data-label":r.attrs.label,"data-list-type":r.attrs.listType,"data-spread":r.attrs.spread,"data-checked":r.attrs.checked},0],parseMarkdown:{match:({type:r})=>r==="listItem",runner:(r,i,o)=>{if(i.checked==null){n.parseMarkdown.runner(r,i,o);return}let s=i.label!=null?`${i.label}.`:"\u2022",a=i.checked!=null?!!i.checked:null,l=i.label!=null?"ordered":"bullet",c=i.spread!=null?`${i.spread}`:"true";r.openNode(o,{label:s,listType:l,spread:c,checked:a}),r.next(i.children),r.closeNode()}},toMarkdown:{match:r=>r.type.name==="list_item",runner:(r,i)=>{if(i.attrs.checked==null){n.toMarkdown.runner(r,i);return}let o=i.attrs.label,s=i.attrs.listType,a=i.attrs.spread==="true",l=i.attrs.checked;r.openNode("listItem",void 0,{label:o,listType:s,spread:a,checked:l}),r.next(i.content),r.closeNode()}}}});V(mf.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});V(mf.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var kk=fe(()=>new ke(/^\[(?<checked>\s|x)\]\s$/,(t,e,n,r)=>{let i=t.doc.resolve(n),o=0,s=i.node(o);for(;s&&s.type.name!=="list_item";)o--,s=i.node(o);if(!s||s.attrs.checked!=null)return null;let a=e.groups?.checked==="x",l=i.before(o),c=t.tr;return c.deleteRange(n,r).setNodeMarkup(l,void 0,{...s.attrs,checked:a}),c}));V(kk,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var FT=[lf,df].flat(),zT=[gk,kk],$T=[ek],_T=[yk],bk=Se(()=>Dy);V(bk,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var HT=Se(()=>Ay({}));V(HT,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var xk=Se(()=>Ry({allowTableNodeSelection:!0}));V(xk,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var gf=Ge("remarkGFM",()=>Xs);V(gf.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});V(gf.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var VT=new te("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function WT(t,e){let n=0;return e.forEach((r,i,o)=>{r===t&&(n=o)}),n}var wk=Se(()=>new X({key:VT,appendTransaction:(t,e,n)=>{let r,i=(o,s)=>{if(r||(r=n.tr),o.type.name!=="table_cell")return;let a=n.doc.resolve(s),l=a.node(a.depth),c=a.node(a.depth-1).firstChild;if(!c)return;let u=WT(o,l),f=c.maybeChild(u);if(!f)return;let d=f.attrs.alignment;d!==o.attrs.alignment&&r.setNodeMarkup(s,void 0,{...o.attrs,alignment:d})};return e.doc!==n.doc&&n.doc.descendants(i),r}}));V(wk,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var jT=[wk,bk,gf,xk].flat(),qT=[mf,Xt,oo,ti,ei,so,pf,hf,sf,ro].flat(),KT=[uf,cf,ff,ik,ok,sk,ak,lk,ck,uk,pk,hk,fk,dk,mk,af],Sk=[qT,zT,_T,$T,FT,KT,jT].flat();var UT=typeof global=="object"&&global&&global.Object===Object&&global,Ck=UT;var JT=typeof self=="object"&&self&&self.Object===Object&&self,GT=Ck||JT||Function("return this")(),Zs=GT;var QT=Zs.Symbol,ni=QT;var Mk=Object.prototype,YT=Mk.hasOwnProperty,XT=Mk.toString,ao=ni?ni.toStringTag:void 0;function ZT(t){var e=YT.call(t,ao),n=t[ao];try{t[ao]=void 0;var r=!0}catch{}var i=XT.call(t);return r&&(e?t[ao]=n:delete t[ao]),i}var Ek=ZT;var ev=Object.prototype,tv=ev.toString;function nv(t){return tv.call(t)}var Tk=nv;var rv="[object Null]",iv="[object Undefined]",vk=ni?ni.toStringTag:void 0;function ov(t){return t==null?t===void 0?iv:rv:vk&&vk in Object(t)?Ek(t):Tk(t)}var Ik=ov;function sv(t){return t!=null&&typeof t=="object"}var Ak=sv;var av="[object Symbol]";function lv(t){return typeof t=="symbol"||Ak(t)&&Ik(t)==av}var Nk=lv;var cv=/\s/;function uv(t){for(var e=t.length;e--&&cv.test(t.charAt(e)););return e}var Rk=uv;var fv=/^\s+/;function dv(t){return t&&t.slice(0,Rk(t)+1).replace(fv,"")}var Ok=dv;function pv(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var lo=pv;var Dk=NaN,hv=/^[-+]0x[0-9a-f]+$/i,mv=/^0b[01]+$/i,gv=/^0o[0-7]+$/i,yv=parseInt;function kv(t){if(typeof t=="number")return t;if(Nk(t))return Dk;if(lo(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=lo(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=Ok(t);var n=mv.test(t);return n||gv.test(t)?yv(t.slice(2),n?2:8):hv.test(t)?Dk:+t}var yf=kv;var bv=function(){return Zs.Date.now()},ea=bv;var xv="Expected a function",wv=Math.max,Sv=Math.min;function Cv(t,e,n){var r,i,o,s,a,l,c=0,u=!1,f=!1,d=!0;if(typeof t!="function")throw new TypeError(xv);e=yf(e)||0,lo(n)&&(u=!!n.leading,f="maxWait"in n,o=f?wv(yf(n.maxWait)||0,e):o,d="trailing"in n?!!n.trailing:d);function p(w){var N=r,D=i;return r=i=void 0,c=w,s=t.apply(D,N),s}function h(w){return c=w,a=setTimeout(y,e),u?p(w):s}function m(w){var N=w-l,D=w-c,B=e-N;return f?Sv(B,o-D):B}function g(w){var N=w-l,D=w-c;return l===void 0||N>=e||N<0||f&&D>=o}function y(){var w=ea();if(g(w))return x(w);a=setTimeout(y,m(w))}function x(w){return a=void 0,d&&r?p(w):(r=i=void 0,s)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=i=a=void 0}function v(){return a===void 0?s:x(ea())}function I(){var w=ea(),N=g(w);if(r=arguments,i=this,l=w,N){if(a===void 0)return h(l);if(f)return clearTimeout(a),a=setTimeout(y,e),p(l)}return a===void 0&&(a=setTimeout(y,e)),s}return I.cancel=C,I.flush=v,I}var kf=Cv;var Bk=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=t=>(this.beforeMountedListeners.push(t),this),this.mounted=t=>(this.mountedListeners.push(t),this),this.updated=t=>(this.updatedListeners.push(t),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(t){return this.markdownUpdatedListeners.push(t),this}blur(t){return this.blurListeners.push(t),this}focus(t){return this.focusListeners.push(t),this}destroy(t){return this.destroyListeners.push(t),this}selectionUpdated(t){return this.selectionUpdatedListeners.push(t),this}},ta=K(new Bk,"listener"),Mv=new te("MILKDOWN_LISTENER"),bf=t=>(t.inject(ta,new Bk),async()=>{await t.wait(Jt);let{listeners:e}=t.get(ta);e.beforeMount.forEach(c=>c(t)),await t.wait(_r);let n=t.get(nr),r=null,i=null,o=null,s=null,a=kf(()=>{if(!s)return;let{doc:c}=s;if(e.updated.length>0&&r&&!r.eq(c)&&e.updated.forEach(u=>{u(t,c,r)}),e.markdownUpdated.length>0&&r&&!r.eq(c)){let u=n(c);e.markdownUpdated.forEach(f=>{f(t,u,i)}),i=u}r=c,s=null},200),l=new X({key:Mv,view:()=>({destroy:()=>{a.cancel(),e.destroy.forEach(c=>c(t))}}),props:{handleDOMEvents:{focus:()=>(e.focus.forEach(c=>c(t)),!1),blur:()=>(e.blur.forEach(c=>c(t)),!1)}},state:{init:(c,u)=>{r=u.doc,i=n(u.doc)},apply:c=>{let u=c.selection;(!o&&u||o&&!u.eq(o))&&(e.selectionUpdated.forEach(f=>{f(t,u,o)}),o=u),!(!(c.docChanged||c.storedMarksSet)||c.getMeta("addToHistory")===!1)&&(s=c,a())}}});t.update(gt,c=>c.concat(l)),await t.wait(Gi),e.mounted.forEach(c=>c(t))});bf.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};function Ev(t){let e=t.schema.cached.changeSetIDs||(t.schema.cached.changeSetIDs=Object.create(null)),n=e[t.name];return n==null&&(e[t.name]=n=Object.keys(t.schema.nodes).indexOf(t.name)+1),n}var Fk={encodeCharacter:t=>t,encodeNodeStart:t=>t.type.name,encodeNodeEnd:t=>-Ev(t.type),compareTokens:(t,e)=>t===e};function xf(t,e,n,r,i){for(let o=0,s=0;o<t.childCount;o++){let a=t.child(o),l=s+a.nodeSize,c=Math.max(s,n),u=Math.min(l,r);if(c<u)if(a.isText)for(let f=c;f<u;f++)i.push(e.encodeCharacter(a.text.charCodeAt(f-s),a.marks));else a.isLeaf?i.push(e.encodeNodeStart(a)):(c==s&&i.push(e.encodeNodeStart(a)),xf(a.content,e,Math.max(s+1,c)-s-1,Math.min(l-1,u)-s-1,i),u==l&&i.push(e.encodeNodeEnd(a)));s=l}return i}var Tv=5e3;function vv(t,e){return Math.min(15,Math.max(2,Math.floor(Math.max(t,e)/10)))}function zk(t,e,n,r=Fk){let i=xf(t,r,n.fromA,n.toA,[]),o=xf(e,r,n.fromB,n.toB,[]),s=0,a=i.length,l=o.length,c=r.compareTokens;for(;s<i.length&&s<o.length&&c(i[s],o[s]);)s++;if(s==i.length&&s==o.length)return[];for(;a>s&&l>s&&c(i[a-1],o[l-1]);)a--,l--;if(a==s||l==s||a==l&&a==s+1)return[n.slice(s,a,s,l)];let u=a-s,f=l-s,d=Math.min(Tv,u+f),p=d+1,h=[],m=[];for(let g=p*2,y=0;y<g;y++)m[y]=-1;for(let g=0;g<=d;g++){for(let y=-g;y<=g;y+=2){let x=m[y+1+d],C=m[y-1+d],v=x<C?C:x+1,I=v+y;for(;v<u&&I<f&&c(i[s+v],o[s+I]);)v++,I++;if(m[y+d]=v,v>=u&&I>=f){let w=[],N=vv(a-s,l-s),D=-1,B=-1,S=-1,ce=-1,Y=(L,W,j,le)=>{D>-1&&D<W+N?(D=L,S=j):(D>-1&&w.push(n.slice(D,B,S,ce)),D=L,B=W,S=j,ce=le)};for(let L=g-1;L>=0;L--){let W=m[y+1+d],j=m[y-1+d];W<j?(y--,v=j+s,I=v+y,Y(v,v,I,I+1)):(y++,v=W+s,I=v+y,Y(v,v+1,I,I)),m=h[L>>1]}return D>-1&&w.push(n.slice(D,B,S,ce)),w.reverse()}}g%2==0&&h.push(m.slice())}return[n.slice(s,a,s,l)]}var he=class t{constructor(e,n){this.length=e,this.data=n}cut(e){return e==this.length?this:new t(e,this.data)}static slice(e,n,r){if(n==r)return t.none;if(n==0&&r==t.len(e))return e;let i=[];for(let o=0,s=0;s<r;o++){let a=e[o],l=s+a.length,c=Math.min(r,l)-Math.max(n,s);c>0&&i.push(a.cut(c)),s=l}return i}static join(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=r(e[e.length-1].data,n[0].data);if(i==null)return e.concat(n);let o=e.slice(0,e.length-1);o.push(new t(e[e.length-1].length+n[0].length,i));for(let s=1;s<n.length;s++)o.push(n[s]);return o}static len(e){let n=0;for(let r=0;r<e.length;r++)n+=e[r].length;return n}};he.none=[];var Nt=class t{constructor(e,n,r,i,o,s){this.fromA=e,this.toA=n,this.fromB=r,this.toB=i,this.deleted=o,this.inserted=s}get lenA(){return this.toA-this.fromA}get lenB(){return this.toB-this.fromB}slice(e,n,r,i){return e==0&&r==0&&n==this.toA-this.fromA&&i==this.toB-this.fromB?this:new t(this.fromA+e,this.fromA+n,this.fromB+r,this.fromB+i,he.slice(this.deleted,e,n),he.slice(this.inserted,r,i))}static merge(e,n,r){if(e.length==0)return n;if(n.length==0)return e;let i=[];for(let o=0,s=0,a=e[0],l=n[0];;){if(!a&&!l)return i;if(a&&(!l||a.toB<l.fromA)){let c=s?n[s-1].toB-n[s-1].toA:0;i.push(c==0?a:new t(a.fromA,a.toA,a.fromB+c,a.toB+c,a.deleted,a.inserted)),a=o++==e.length?null:e[o]}else if(l&&(!a||l.toA<a.fromB)){let c=o?e[o-1].toB-e[o-1].toA:0;i.push(c==0?l:new t(l.fromA-c,l.toA-c,l.fromB,l.toB,l.deleted,l.inserted)),l=s++==n.length?null:n[s]}else{let c=Math.min(a.fromB,l.fromA),u=Math.min(a.fromA,l.fromA-(o?e[o-1].toB-e[o-1].toA:0)),f=u,d=Math.min(l.fromB,a.fromB+(s?n[s-1].toB-n[s-1].toA:0)),p=d,h=he.none,m=he.none,g=!1,y=!1;for(;;){let x=a?c>=a.fromB?a.toB:a.fromB:2e8,C=l?c>=l.fromA?l.toA:l.fromA:2e8,v=Math.min(x,C),I=a&&c>=a.fromB,w=l&&c>=l.fromA;if(!I&&!w)break;I&&c==a.fromB&&!g&&(h=he.join(h,a.deleted,r),f+=a.lenA,g=!0),I&&!w&&(m=he.join(m,he.slice(a.inserted,c-a.fromB,v-a.fromB),r),p+=v-c),w&&c==l.fromA&&!y&&(m=he.join(m,l.inserted,r),p+=l.lenB,y=!0),w&&!I&&(h=he.join(h,he.slice(l.deleted,c-l.fromA,v-l.fromA),r),f+=v-c),I&&v==a.toB&&(a=o++==e.length?null:e[o],g=!1),w&&v==l.toA&&(l=s++==n.length?null:n[s],y=!1),c=v}(u<f||d<p)&&i.push(new t(u,f,d,p,h,m))}}}static fromJSON(e){return new t(e.fromA,e.toA,e.fromB,e.toB,e.deleted.map(n=>new he(n.length,n.data)),e.inserted.map(n=>new he(n.length,n.data)))}toJSON(){return this}},Iv;try{Iv=new RegExp("[\\p{Alphabetic}_]","u")}catch{}var ri=class t{constructor(e,n){this.config=e,this.changes=n}addSteps(e,n,r){let i=[];for(let l=0;l<n.length;l++){let c=Array.isArray(r)?r[l]:r,u=0;n[l].forEach((f,d,p,h)=>{i.push(new Nt(f+u,d+u,p,h,f==d?he.none:[new he(d-f,c)],p==h?he.none:[new he(h-p,c)])),u=h-p-(d-f)})}if(i.length==0)return this;let o=wf(i,this.config.combine),s=Nt.merge(this.changes,o,this.config.combine),a=s;for(let l=0;l<a.length;l++){let c=a[l];if(c.fromA==c.toA||c.fromB==c.toB||!o.some(f=>f.toB>c.fromB&&f.fromB<c.toB))continue;let u=zk(this.config.doc.content,e.content,c,this.config.encoder);u.length==1&&u[0].fromB==0&&u[0].toB==c.toB-c.fromB||(a==s&&(a=s.slice()),u.length==1?a[l]=u[0]:(a.splice(l,1,...u),l+=u.length-1))}return new t(this.config,a)}get startDoc(){return this.config.doc}map(e){let n=r=>{let i=e(r);return i===r.data?r:new he(r.length,i)};return new t(this.config,this.changes.map(r=>new Nt(r.fromA,r.toA,r.fromB,r.toB,r.deleted.map(n),r.inserted.map(n))))}changedRange(e,n){if(e==this)return null;let r=n&&Av(n),i=r?r.toB-r.fromB-(r.toA-r.fromA):0;function o(f){return!r||f<=r.fromA?f:f+i}let s=r?r.fromB:2e8,a=r?r.toB:-2e8;function l(f,d=f){s=Math.min(f,s),a=Math.max(d,a)}let c=this.changes,u=e.changes;for(let f=0,d=0;f<c.length&&d<u.length;){let p=c[f],h=u[d];p&&h&&Nv(p,h,o)?(f++,d++):h&&(!p||o(p.fromB)>=h.fromB)?(l(h.fromB,h.toB),d++):(l(o(p.fromB),o(p.toB)),f++)}return s<=a?{from:s,to:a}:null}static create(e,n=(o,s)=>o===s?o:null,r=Fk,i=[]){return new t({combine:n,doc:e,encoder:r},i)}};ri.computeDiff=zk;function wf(t,e,n=0,r=t.length){if(r==n+1)return[t[n]];let i=n+r>>1;return Nt.merge(wf(t,e,n,i),wf(t,e,i,r),e)}function Lk(t){let e=2e8,n=-2e8;for(let r=0;r<t.length;r++){let i=t[r];e!=2e8&&(e=i.map(e,-1),n=i.map(n,1)),i.forEach((o,s,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==2e8?null:{from:e,to:n}}function Av(t){let e=Lk(t);if(!e)return null;let n=Lk(t.map(r=>r.invert()).reverse());return{fromA:n.from,toA:n.to,fromB:e.from,toB:e.to}}function Nv(t,e,n){return n(t.fromB)==e.fromB&&n(t.toB)==e.toB&&Pk(t.deleted,e.deleted)&&Pk(t.inserted,e.inserted)}function Pk(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n].length!=e[n].length||t[n].data!==e[n].data)return!1;return!0}function Rt(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-diff",...e}}),t}var $k=500;function Rv(t={}){let e=new WeakMap,n=new WeakMap;function r(i){let o=e.get(i);if(o!=null)return o;let s=i.attrs,a=s?Object.keys(s).filter(l=>s[l]!=null).sort():[];if(a.length===0)o=i.type.name;else{let l={};for(let c of a)l[c]=s[c];o=`${i.type.name}:${JSON.stringify(l)}`}return e.set(i,o),o}return{encodeCharacter:(i,o)=>{if(o.length===0)return i;let s=n.get(o);return s==null&&(s=o.map(r).join(","),n.set(o,s)),`${i}:${s}`},encodeNodeStart:i=>{let o=i.attrs;if(o&&Object.keys(o).length>0){let s=t[i.type.name]??[],a=Object.keys(o).filter(l=>{if(s.includes(l))return!1;let c=i.type.spec.attrs?.[l]?.default;return o[l]!==c});if(a.length>0){let l={};for(let c of a.sort())l[c]=o[c];return`${i.type.name}:${JSON.stringify(l)}`}}return i.type.name},encodeNodeEnd:i=>{let o=i.type.schema,s=o.cached.changeSetIDs||(o.cached.changeSetIDs=Object.create(null)),a=s[i.type.name];return a==null&&(s[i.type.name]=a=Object.keys(o.nodes).indexOf(i.type.name)+1),-a},compareTokens:(i,o)=>i===o}}function Wk(t,e,n){let r=n.get(t);if(r!=null)return r;let i=[String(e.encodeNodeStart(t))];if(t.isText){let s=t.text;for(let a=0;a<s.length;a++)i.push(":"+String(e.encodeCharacter(s.charCodeAt(a),t.marks)))}else t.content.forEach(s=>{i.push("/"+Wk(s,e,n))});i.push("\\"+String(e.encodeNodeEnd(t)));let o=i.join("");return n.set(t,o),o}function _k(t,e,n){let r=[],i=0;return t.content.forEach(o=>{r.push({node:o,offset:i,size:o.nodeSize,signature:Wk(o,n.encoder,n.sigCache)}),i+=o.nodeSize}),{node:t,contentStart:e,content:r}}function Ov(t,e){let n=t.length,r=e.length,i=Array.from({length:n+1},()=>Array.from({length:r+1},()=>0));for(let l=n-1;l>=0;l--)for(let c=r-1;c>=0;c--)t[l].signature===e[c].signature?i[l][c]=i[l+1][c+1]+1:i[l][c]=Math.max(i[l+1][c],i[l][c+1]);let o=[],s=0,a=0;for(;s<n&&a<r;)t[s].signature===e[a].signature?(o.push([s,a]),s++,a++):i[s+1][a]>=i[s][a+1]?s++:a++;return o}function Dv(t,e){if(t.type!==e.type)return!1;let n=t.type;return!(n.isTextblock||n.isAtom||n.spec.code===!0||!n.isBlock)}function jk(t,e,n){return Nt.fromJSON({fromA:t.fromA+e,toA:t.toA+e,fromB:t.fromB+n,toB:t.toB+n,deleted:t.deleted.map(r=>({length:r.length,data:r.data})),inserted:t.inserted.map(r=>({length:r.length,data:r.data}))})}function Bv(t,e,n){let r=t.parent.copy(E.from(t.node)),i=e.parent.copy(E.from(e.node)),o=new de(0,r.content.size,new A(i.content,0,0));return ri.create(r,void 0,n.encoder).addSteps(i,[o.getMap()],null).changes.map(s=>jk(s,t.abs,e.abs))}function Hk(t,e){let n=t.content;if(e<n.length)return t.contentStart+n[e].offset;if(e>0){let r=n[e-1];return t.contentStart+r.offset+r.size}return t.contentStart+t.node.content.size}function Lv(t,e,n){return Nt.fromJSON({fromA:e,toA:e+t.size,fromB:n,toB:n,deleted:[{length:t.size,data:null}],inserted:[]})}function Pv(t,e,n){return Nt.fromJSON({fromA:e,toA:e,fromB:n,toB:n+t.size,deleted:[],inserted:[{length:t.size,data:null}]})}function Fv(t,e,n,r,i){let o=new de(0,t.content.size,new A(e.content,0,0));return ri.create(t,void 0,i.encoder).addSteps(e,[o.getMap()],null).changes.map(s=>jk(s,n,r))}function na(t,e,n,r,i){if(t.childCount>$k||e.childCount>$k)return Fv(t,e,n,r,i);let o=_k(t,n,i),s=_k(e,r,i),a=Ov(o.content,s.content),l=[],c=0,u=0;for(let[f,d]of a)Vk(o,s,{oldStart:c,oldEnd:f,newStart:u,newEnd:d},i,l),c=f+1,u=d+1;return Vk(o,s,{oldStart:c,oldEnd:o.content.length,newStart:u,newEnd:s.content.length},i,l),l}function Vk(t,e,n,r,i){let o=t.content,s=e.content,a=n.oldStart,l=n.newStart;for(;a<n.oldEnd||l<n.newEnd;){let c=a<n.oldEnd?o[a]:null,u=l<n.newEnd?s[l]:null,f=c&&u&&c.node.type===u.node.type;if(c&&u&&f){i.push(...zv(t,e,c,u,r)),a++,l++;continue}if(c&&(!u||!f)){let d=t.contentStart+c.offset;i.push(Lv(c,d,Hk(e,l))),a++;continue}if(u){let d=e.contentStart+u.offset;i.push(Pv(u,Hk(t,a),d)),l++}}}function zv(t,e,n,r,i){let o=t.contentStart+n.offset,s=e.contentStart+r.offset;return Dv(n.node,r.node)&&$v(n.node,r.node,i.encoder)?na(n.node,r.node,o+1,s+1,i):Bv({node:n.node,parent:t.node,abs:o},{node:r.node,parent:e.node,abs:s},i)}function $v(t,e,n){return n.encodeNodeStart(t)===n.encodeNodeStart(e)}function _v(t,e,n,r,i){let o=t.resolve(n),s=t.resolve(r),a=e.resolve(n),l=e.resolve(r),c=o.sharedDepth(r);if(a.sharedDepth(r)!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) resolves to different sharedDepth in old and new docs`);for(let m=0;m<=c;m++){if(i.encodeNodeStart(o.node(m))!==i.encodeNodeStart(a.node(m)))throw new RangeError(`computeDocDiff: ancestor at depth ${m} differs in type or non-ignored attrs along the path to the shared ancestor`);if(o.start(m)!==a.start(m))throw new RangeError(`computeDocDiff: ancestor at depth ${m} starts at different absolute positions in old and new docs (content before the range differs in size)`)}let u=o.node(c);if(u.isTextblock)throw new RangeError(`computeDocDiff: range [${n}, ${r}) lands inside a textblock; widen the range to a block boundary`);if(o.depth!==c||s.depth!==c||a.depth!==c||l.depth!==c)throw new RangeError(`computeDocDiff: range [${n}, ${r}) endpoints must be aligned to child boundaries of the shared ancestor`);let f=a.node(c),d=o.start(c),p=n-d,h=r-d;return{oldCut:u.copy(u.content.cut(p,h)),newCut:f.copy(f.content.cut(p,h)),cutAbsStart:n}}function co(t,e,n){let r=Rv(n?.ignoreAttrs),i={encoder:r,sigCache:new WeakMap},o=t.content.size,s=e.content.size,a=n?.range;if(a==null)return na(t,e,0,0,i);let l=Math.min(o,s),c=Math.max(0,Math.min(a.from??0,l)),u=Math.max(c,Math.min(a.to??l,l));if(c===u)return[];if(c===0&&u===l&&o===s)return na(t,e,0,0,i);let f=_v(t,e,c,u,r);return na(f.oldCut,f.newCut,f.cutAbsStart,f.cutAbsStart,i)}var qk=Je({ignoreAttrs:{heading:["id"]}},"diffConfig");Rt(qk,{displayName:"Ctx<diffConfig>",group:"Diff"});var Ce=new te("MILKDOWN_DIFF");function Hv(t,e,n){let r=co(t,e.newDoc,n);return{...e,changes:r}}function Vv(t,e){return e.some(n=>t.fromB<n.toB&&t.toB>n.fromB)}function ra(t){return t.changes.filter(e=>!Vv(e,t.rejectedRanges))}var Wv=Se(t=>{let e=t.get(qk.key);return new X({key:Ce,state:{init:()=>null,apply(n,r,i,o){let s=n.getMeta(Ce);if(!r){if(s?.type==="start"){let c=co(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}return null}let a=r;if(n.docChanged&&a.active&&(a=Hv(o.doc,a,{ignoreAttrs:e.ignoreAttrs})),!s)return a;let l;switch(s.type){case"start":{let c=co(o.doc,s.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:s.newDoc,changes:c,rejectedRanges:[],active:!0}}case"accept":case"acceptRange":l=a;break;case"reject":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.fromB,toB:s.toB}]};break;case"rejectRange":l={...a,rejectedRanges:[...a.rejectedRanges,{fromB:s.range.fromB,toB:s.range.toB}]};break;case"acceptAll":case"clear":return null;default:return a}return l.active&&ra(l).length===0?null:l}},filterTransaction(n,r){return!Ce.getState(r)?.active||n.getMeta(Ce)?!0:!n.docChanged}})});Rt(Wv,{displayName:"Prose<diff>",group:"Diff"});function jv(t,e){let n=ra(e);for(let r=n.length-1;r>=0;r--){let i=n[r],o=e.newDoc.slice(i.fromB,i.toB);t=t.replace(i.fromA,i.toA,o)}return t}var qv=P("StartDiffReview",t=>e=>(n,r)=>{if(e==null)return!1;let i=t.get(Ue)(e);return i?(r&&r(n.tr.setMeta(Ce,{type:"start",newDoc:i})),!0):!1});Rt(qv,{displayName:"Command<startDiffReview>",group:"Diff"});var Sf=P("StartDiffReviewFromDoc",()=>t=>(e,n)=>!t||t.type!==e.doc.type?!1:(n&&n(e.tr.setMeta(Ce,{type:"start",newDoc:t})),!0));Rt(Sf,{displayName:"Command<startDiffReviewFromDoc>",group:"Diff"});var Kv=P("AcceptDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Ce.getState(e);if(!r)return!1;let i=ra(r)[t];if(!i)return!1;if(n){let o=r.newDoc.slice(i.fromB,i.toB),s=e.tr.replace(i.fromA,i.toA,o);s=s.setMeta(Ce,{type:"accept",changeIndex:t}),n(s)}return!0});Rt(Kv,{displayName:"Command<acceptDiffChunk>",group:"Diff"});var Uv=P("RejectDiffChunk",()=>t=>(e,n)=>{if(t==null)return!1;let r=Ce.getState(e);if(!r)return!1;let i=ra(r)[t];return i?(n&&n(e.tr.setMeta(Ce,{type:"reject",fromB:i.fromB,toB:i.toB})),!0):!1});Rt(Uv,{displayName:"Command<rejectDiffChunk>",group:"Diff"});var Jv=P("AcceptDiffRange",()=>t=>(e,n)=>{if(!t)return!1;let r=Ce.getState(e);if(!r)return!1;if(n){let i=r.newDoc.slice(t.fromB,t.toB),o=e.tr.replace(t.fromA,t.toA,i);o=o.setMeta(Ce,{type:"acceptRange",range:t}),n(o)}return!0});Rt(Jv,{displayName:"Command<acceptDiffRange>",group:"Diff"});var Gv=P("RejectDiffRange",()=>t=>(e,n)=>!t||!Ce.getState(e)?!1:(n&&n(e.tr.setMeta(Ce,{type:"rejectRange",range:t})),!0));Rt(Gv,{displayName:"Command<rejectDiffRange>",group:"Diff"});var Qv=P("AcceptAllDiffs",()=>()=>(t,e)=>{let n=Ce.getState(t);return n?(e&&e((n.rejectedRanges.length===0?t.tr.replaceWith(0,t.doc.content.size,n.newDoc.content):jv(t.tr,n)).setMeta(Ce,{type:"acceptAll"})),!0):!1});Rt(Qv,{displayName:"Command<acceptAllDiffs>",group:"Diff"});var Yv=P("ClearDiffReview",()=>()=>(t,e)=>Ce.getState(t)?(e&&e(t.tr.setMeta(Ce,{type:"clear"})),!0):!1);Rt(Yv,{displayName:"Command<clearDiffReview>",group:"Diff"});function ii(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-streaming",...e}}),t}var wn=Je({throttleMs:100,scrollFollow:!0,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}},"streamingConfig");ii(wn,{displayName:"Ctx<streamingConfig>",group:"Streaming"});function Xv(t,e,n){let r=t.get(Ue)(n);if(!r)return{tr:e,newDoc:null};let i=t.get(wn.key).ignoreAttrs,o=co(e.doc,r,i?{ignoreAttrs:i}:void 0);for(let s=o.length-1;s>=0;s--){let a=o[s],l=r.slice(a.fromB,a.toB);e=e.replace(a.fromA,a.toA,l)}return{tr:e,newDoc:r}}function Zv(t){if(t.parent.type.spec.code)return{type:"plain-text",preserveNewlines:!0};for(let e=t.depth;e>0;e--)if(t.node(e).type.name==="table")return{type:"plain-text",preserveNewlines:!1};return t.depth>=1?{type:"split-block"}:{type:"block"}}function Kk(t){if(t.childCount===0)return t;let e=t.lastChild;return e.type.name==="paragraph"&&e.content.size===0?t.cut(0,t.size-e.nodeSize):t}function eI(t,e,n){let{insertPos:r,currentEndPos:i}=n,o=n.buffer.replace(/\r\n?/g,` +`);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=e.doc.content.size,a=Math.max(0,Math.min(r,s)),l=Math.max(a,Math.min(i,s)),c=e.doc.resolve(a),u=(t.get(wn.key).insertStrategy??Zv)(c),f={ctx:t,tr:e,buffer:o,from:a,to:l,resolved:c};switch(u.type){case"plain-text":return tI(f,u.preserveNewlines??!1);case"split-block":return rI(f);case"block":return iI(f)}}function tI({tr:t,buffer:e,from:n,to:r},i){let o=i?e:e.replace(/\n/g," "),s=t.doc.type.schema.text(o);return t=t.replaceWith(n,r,s),{tr:t,applied:!0,insertEndPos:n+o.length}}var nI=/[*_~`[\\<]/;function Cf(t,e,n){if(!n)return E.empty;if(!nI.test(n))return E.from(e.text(n));let r=t.get(Ue)(n)?.firstChild;if(r?.type.name!=="paragraph"||r.content.size===0)return E.from(e.text(n));let i=!1;if(r.content.forEach(l=>{(!l.isText||l.marks.length>0)&&(i=!0)}),!i)return E.from(e.text(n));let o=r.content,s=/^\s+/.exec(n)?.[0];s&&((o.firstChild?.isText?o.firstChild.text??"":"").startsWith(s)||(o=E.from(e.text(s)).append(o)));let a=/\s+$/.exec(n)?.[0];return a&&((o.lastChild?.isText?o.lastChild.text??"":"").endsWith(a)||(o=o.append(E.from(e.text(a))))),o}function rI({ctx:t,tr:e,buffer:n,from:r,to:i,resolved:o}){let s=e.doc.type.schema,a=n.indexOf(` +`);if(a<0){let I=Cf(t,s,n);return e=e.replaceWith(r,i,I),{tr:e,applied:!0,insertEndPos:r+I.size}}let l=n.substring(0,a),c=n.substring(a+1),u=t.get(Ue),f=c.trim()?u(c):null,d=f?Kk(f.content):E.empty;if(d.childCount===0){let I=Cf(t,s,n.replace(/\n/g," "));return e=e.replaceWith(r,i,I),{tr:e,applied:!0,insertEndPos:r+I.size}}let p=o.depth,h=Cf(t,s,l);for(let I=p;I>0;I--)h=E.from(o.node(I).copy(h));let m=h.append(d),g=new A(m,p,0),y=e.doc.content.size,x=e.doc.resolve(Math.min(i,y)),C=i;p>0&&x.depth===p&&x.parentOffset===x.parent.content.size&&(C=x.after(p)),e=e.replace(r,C,g);let v=m.size-p;return{tr:e,applied:!0,insertEndPos:r+v}}function iI({ctx:t,tr:e,buffer:n,from:r,to:i}){let o=t.get(Ue)(n);if(!o)return{tr:e,applied:!1,insertEndPos:i};let s=Kk(o.content);return s.size===0?{tr:e,applied:!1,insertEndPos:i}:(e=e.replace(r,i,new A(s,0,0)),{tr:e,applied:!0,insertEndPos:r+s.size})}function Mf(t,e,n){if(n.insertPos!=null){let r=n.insertPos,i=eI(t,e,{buffer:n.buffer,insertPos:r,currentEndPos:n.insertEndPos??r});return{tr:i.tr,newDoc:i.applied?i.tr.doc:null,insertEndPos:i.insertEndPos}}return Xv(t,e,n.buffer)}var _e=new te("MILKDOWN_STREAMING");function oI(t,e){if(!t&&e?.type!=="start")return null;if(!e)return t;switch(e.type){case"start":return{buffer:"",originalDoc:e.originalDoc,active:!0,lastApplyTime:e.lastApplyTime,insertPos:e.insertPos??null,insertEndPos:e.insertEndPos??e.insertPos??null};case"push":return t?{...t,buffer:t.buffer+e.token}:null;case"apply":return t?{...t,lastApplyTime:e.lastApplyTime,insertEndPos:e.insertEndPos??t.insertEndPos}:null;case"end":case"abort":return null;default:return t}}var Uk=Se(t=>{let e=t.get(wn.key);return new X({key:_e,state:{init:()=>null,apply(n,r){return oI(r,n.getMeta(_e))}},filterTransaction(n,r){return!_e.getState(r)?.active||n.getMeta(_e)?!0:!n.docChanged},view(){return sI(t,e)}})});ii(Uk,{displayName:"Prose<streaming>",group:"Streaming"});function sI(t,e){let n=null,r=-1,i=null;function o(){if(!i)return;let a=_e.getState(i.state);if(!a?.active||a.buffer.length===r)return;r=a.buffer.length;let l=Mf(t,i.state.tr,a);if(!l.newDoc)return;let c=l.tr;!c.docChanged&&l.insertEndPos==null||(c=c.setMeta(_e,{type:"apply",lastApplyTime:Date.now(),insertEndPos:l.insertEndPos}),e.scrollFollow&&(c=c.scrollIntoView()),i.dispatch(c))}function s(){n!=null&&clearTimeout(n),n=setTimeout(o,e.throttleMs)}return{update(a){i=a;let l=_e.getState(a.state);if(!l?.active){n!=null&&(clearTimeout(n),n=null),r=-1;return}l.buffer.length!==r&&(Date.now()-l.lastApplyTime>=e.throttleMs?o():s())},destroy(){n!=null&&(clearTimeout(n),n=null),i=null}}}var uo=P("StartStreaming",()=>t=>(e,n)=>{if(_e.getState(e)?.active)return!1;if(n){let r,i;if(t?.insertAt!=null)if(t.insertAt==="selection"){if(r=e.selection.from,i=e.selection.to,e.selection.empty){let o=e.doc.resolve(r);o.parent.isTextblock&&!o.parent.type.spec.code&&o.parent.content.size===0&&o.depth===1&&(r=o.before(o.depth),i=o.after(o.depth))}}else{let o=t.insertAt==="cursor"?e.selection.head:t.insertAt;if(!Number.isFinite(o))return!1;r=Math.max(0,Math.min(Math.round(o),e.doc.content.size));let s=e.doc.resolve(r);s.parent.isTextblock&&!s.parent.type.spec.code&&s.parent.content.size===0&&s.depth===1&&(r=s.before(s.depth),i=s.after(s.depth))}n(e.tr.setMeta(_e,{type:"start",originalDoc:e.doc,insertPos:r,insertEndPos:i,lastApplyTime:Date.now()}))}return!0});ii(uo,{displayName:"Command<startStreaming>",group:"Streaming"});var ia=P("PushChunk",()=>t=>(e,n)=>t==null||!_e.getState(e)?.active?!1:(n&&n(e.tr.setMeta(_e,{type:"push",token:t})),!0));ii(ia,{displayName:"Command<pushChunk>",group:"Streaming"});var fo=P("EndStreaming",t=>e=>(n,r)=>{let i=_e.getState(n);if(!i?.active)return!1;if(r){let o=t.get(wn.key),s=e?.diffReview??o.diffReviewOnEnd,a=Mf(t,n.tr,i),l=a.tr;if(l=l.setMeta(_e,{type:"end"}),s&&a.newDoc){let c=l.doc;l=l.replace(0,l.doc.content.size,new A(i.originalDoc.content,0,0)),r(l);try{t.get(G).call(Sf.key,c)}catch(u){console.warn("[milkdown/streaming] diff review handoff skipped:",u)}return!0}r(l)}return!0});ii(fo,{displayName:"Command<endStreaming>",group:"Streaming"});var oa=P("AbortStreaming",t=>e=>(n,r)=>{let i=_e.getState(n);if(!i?.active)return!1;if(r){let o=e?.keep??!1,s=n.tr;o?s=Mf(t,s,i).tr:s=s.replace(0,n.doc.content.size,new A(i.originalDoc.content,0,0)),s=s.setMeta(_e,{type:"abort"}),r(s)}return!0});ii(oa,{displayName:"Command<abortStreaming>",group:"Streaming"});var Jk=[wn,Uk,uo,ia,fo,oa];var Gk=new te("weibeiStreamingAppearance"),Qk={class:"wb-stream-in"},aI={side:1},lI=260,cI=400,uI=24;function fI(){let t=document.createElement("span");return t.className="wb-stream-caret",t}function Yk(t){return new X({key:Gk,state:{init:()=>({fades:[],caretPosition:null,caretExpiresAt:0,set:ee.empty}),apply(e,n){let r=Date.now(),i=[];for(let l of n.fades){let c=e.mapping.map(l.from),u=e.mapping.map(l.to);c>=u||r>=l.expiresAt||e.doc.resolve(c).parent===e.doc.resolve(u).parent&&i.push({from:c,to:u,expiresAt:l.expiresAt})}let o=n.caretPosition===null?null:e.mapping.map(n.caretPosition),s=n.caretExpiresAt;e.docChanged&&t()&&e.steps.forEach((l,c)=>{let u=e.mapping.slice(c+1);e.mapping.maps[c].forEach((f,d,p,h)=>{if(h<=p)return;let m=u.map(p),g=u.map(h);if(g-m>uI)return;let y=e.doc.resolve(m);y.parent===e.doc.resolve(g).parent&&y.parent.isTextblock&&(i.push({from:m,to:g,expiresAt:r+lI}),o=g,s=r+cI)})}),o!==null&&r>=s&&(o=null);let a=i.map(l=>oe.inline(l.from,l.to,Qk));return o!==null&&a.push(oe.widget(o,fI,aI)),{fades:i,caretPosition:o,caretExpiresAt:s,set:ee.create(e.doc,a)}}},props:{decorations(e){let n=Gk.getState(e);if(!n)return ee.empty;if(!t()){let r=Date.now(),i=n.fades.filter(o=>r<o.expiresAt);return i.length===0?ee.empty:ee.create(e.doc,i.map(o=>oe.inline(o.from,o.to,Qk)))}return n.set}}})}function Ef(){return{enter:{mathFlow:t,mathFlowFenceMeta:e,mathText:o},exit:{mathFlow:i,mathFlowFence:r,mathFlowFenceMeta:n,mathFlowValue:a,mathText:s,mathTextData:a}};function t(l){let c={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[c]}},l)}function e(){this.buffer()}function n(){let l=this.resume(),c=this.stack[this.stack.length-1];c.type,c.meta=l}function r(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function i(l){let c=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c;let f=u.data.hChildren[0];f.type,f.tagName,f.children.push({type:"text",value:c}),this.data.mathFlowInside=void 0}function o(l){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},l),this.buffer()}function s(l){let c=this.resume(),u=this.stack[this.stack.length-1];u.type,this.exit(l),u.value=c,u.data.hChildren.push({type:"text",value:c})}function a(l){this.config.enter.data.call(this,l),this.config.exit.data.call(this,l)}}function Tf(t){let e=(t||{}).singleDollarTextMath;return e==null&&(e=!0),r.peek=i,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:` `,inConstruct:"mathFlowMeta"},{character:"$",after:e?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:n,inlineMath:r}};function n(o,s,a,l){let c=o.value||"",u=a.createTracker(l),f="$".repeat(Math.max(Fo(c,"$")+1,2)),d=a.enter("mathFlow"),p=u.move(f);if(o.meta){let h=a.enter("mathFlowMeta");p+=u.move(a.safe(o.meta,{after:` `,before:p,encode:["$"],...u.current()})),h()}return p+=u.move(` `),c&&(p+=u.move(c+` -`)),p+=u.move(f),d(),p}function r(o,s,a){let l=o.value||"",c=1;for(e||c++;new RegExp("(^|[^$])"+"\\$".repeat(c)+"([^$]|$)").test(l);)c++;let u="$".repeat(c);/[^ \r\n]/.test(l)&&(/^[ \r\n]/.test(l)&&/[ \r\n]$/.test(l)||/^\$|\$$/.test(l))&&(l=" "+l+" ");let f=-1;for(;++f<a.unsafe.length;){let d=a.unsafe[f];if(!d.atBreak)continue;let p=a.compilePattern(d),h;for(;h=p.exec(l);){let m=h.index;l.codePointAt(m)===10&&l.codePointAt(m-1)===13&&m--,l=l.slice(0,m)+" "+l.slice(h.index+1)}}return u+l+u}function i(){return"$"}}var Yk={tokenize:dI,concrete:!0,name:"mathFlow"},Qk={tokenize:pI,partial:!0};function dI(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(x){return t.enter("mathFlow"),t.enter("mathFlowFence"),t.enter("mathFlowFenceSequence"),l(x)}function l(x){return x===36?(t.consume(x),s++,l):s<2?n(x):(t.exit("mathFlowFenceSequence"),F(t,c,"whitespace")(x))}function c(x){return x===null||R(x)?f(x):(t.enter("mathFlowFenceMeta"),t.enter("chunkString",{contentType:"string"}),u(x))}function u(x){return x===null||R(x)?(t.exit("chunkString"),t.exit("mathFlowFenceMeta"),f(x)):x===36?n(x):(t.consume(x),u)}function f(x){return t.exit("mathFlowFence"),r.interrupt?e(x):t.attempt(Qk,d,g)(x)}function d(x){return t.attempt({tokenize:y,partial:!0},g,p)(x)}function p(x){return(o?F(t,h,"linePrefix",o+1):h)(x)}function h(x){return x===null?g(x):R(x)?t.attempt(Qk,d,g)(x):(t.enter("mathFlowValue"),m(x))}function m(x){return x===null||R(x)?(t.exit("mathFlowValue"),h(x)):(t.consume(x),m)}function g(x){return t.exit("mathFlow"),e(x)}function y(x,C,v){let I=0;return F(x,w,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function w(B){return x.enter("mathFlowFence"),x.enter("mathFlowFenceSequence"),N(B)}function N(B){return B===36?(I++,x.consume(B),N):I<s?v(B):(x.exit("mathFlowFenceSequence"),F(x,D,"whitespace")(B))}function D(B){return B===null||R(B)?(x.exit("mathFlowFence"),C(B)):v(B)}}}function pI(t,e,n){let r=this;return i;function i(s){return s===null?e(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function Xk(t){let n=(t||{}).singleDollarTextMath;return n==null&&(n=!0),{tokenize:r,resolve:hI,previous:mI,name:"mathText"};function r(i,o,s){let a=this,l=0,c,u;return f;function f(g){return i.enter("mathText"),i.enter("mathTextSequence"),d(g)}function d(g){return g===36?(i.consume(g),l++,d):l<2&&!n?s(g):(i.exit("mathTextSequence"),p(g))}function p(g){return g===null?s(g):g===36?(u=i.enter("mathTextSequence"),c=0,m(g)):g===32?(i.enter("space"),i.consume(g),i.exit("space"),p):R(g)?(i.enter("lineEnding"),i.consume(g),i.exit("lineEnding"),p):(i.enter("mathTextData"),h(g))}function h(g){return g===null||g===32||g===36||R(g)?(i.exit("mathTextData"),p(g)):(i.consume(g),h)}function m(g){return g===36?(i.consume(g),c++,m):c===l?(i.exit("mathTextSequence"),i.exit("mathText"),o(g)):(u.type="mathTextData",h(g))}}}function hI(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="mathTextData"){t[e][1].type="mathTextPadding",t[n][1].type="mathTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)i===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(i=r):(r===e||t[r][1].type==="lineEnding")&&(t[i][1].type="mathTextData",r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),e-=r-i-2,r=i+2),i=void 0);return t}function mI(t){return t!==36||this.events[this.events.length-1][1].type==="characterEscape"}function vf(t){return{flow:{36:Yk},text:{36:Xk(t)}}}var gI={};function sa(t){let e=this,n=t||gI,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(vf(n)),o.push(Ef()),s.push(Tf(n))}var Zk=Ge("weiBeiRemarkMath",()=>sa),eb=te("math_inline",()=>({group:"inline",content:"text*",inline:!0,atom:!0,parseDOM:[{tag:'span[data-type="math_inline"]',getContent:(t,e)=>E.from(e.text(t.dataset.value||""))}],toDOM:t=>["span",{"data-type":"math_inline","data-value":t.textContent},t.textContent],parseMarkdown:{match:t=>t.type==="inlineMath",runner:(t,e,n)=>t.openNode(n).addText(e.value).closeNode()},toMarkdown:{match:t=>t.type.name==="math_inline",runner:(t,e)=>t.addNode("inlineMath",void 0,e.textContent)}})),tb=te("math_block",()=>({content:"text*",group:"block",marks:"",defining:!0,atom:!0,isolating:!0,attrs:{value:{default:""}},parseDOM:[{tag:'div[data-type="math_block"]',preserveWhitespace:"full",getAttrs:t=>({value:t.dataset.value||""})}],toDOM:t=>["div",{"data-type":"math_block","data-value":t.attrs.value},t.attrs.value],parseMarkdown:{match:t=>t.type==="math",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="math_block",runner:(t,e)=>t.addNode("math",void 0,e.attrs.value)}}));var nb=new Map,If=t=>{let e=nb.get(t);if(e)return e;let n=new Promise((r,i)=>{let o=document.createElement("script");o.src=new URL(t,document.baseURI).href,o.onload=()=>r(),o.onerror=()=>i(new Error(`Unable to load local editor runtime: ${t}`)),document.head.appendChild(o)});return nb.set(t,n),n},rb=()=>If("katex-runtime.js").then(()=>window.WeiBeiKaTeX),ib=()=>window.WeiBeiKaTeX,ob=()=>If("mermaid-runtime.js").then(()=>window.WeiBeiMermaid),sb=()=>If("prism-runtime.js").then(()=>window.WeiBeiPrism);var Af="[A-Za-z][A-Za-z0-9_-]*",yI=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},ab=(t,e,n)=>{let r=t.indexOf(e,n);for(;r>=0&&yI(t,r);)r=t.indexOf(e,r+e.length);return r},kI=(t,e)=>{let n=String(t||""),r="",i=0;for(;i<n.length;){let o=ab(n,"`",i);if(o<0){r+=e(n.slice(i));break}r+=e(n.slice(i,o));let s=n.slice(o).match(/^`+/)?.[0]||"`",a=ab(n,s,o+s.length);if(a<0){r+=e(n.slice(o));break}r+=n.slice(o,a+s.length),i=a+s.length}return r},bI=t=>String(t||"").replace(/(?<!\\)`/g,"\\`").replace(/\\\[\\\[/g,"[[").replace(/\\\]\\\]/g,"]]").replace(/\\=\\=([^=\n]+?)\\=\\=/g,"==$1==").replace(/\^\\\[/g,"^[").replace(/(^|\s)\\#(?=[\p{L}\p{N}_/-])/gu,"$1#").replace(/\\\$(?=\d)/g,"$").replace(new RegExp(`^(\\s*(?:>\\s*)*)\\\\(\\[!(?:${Af})\\])`,"gim"),"$1$2"),po=(t,e)=>{let n=String(t||"").split(/(\r?\n)/),r=!1,i="",o=0,s="";for(let a=0;a<n.length;a+=2){let l=n[a]||"",c=n[a+1]||"",u=l.match(/^\s*(?:>\s*)*(`{3,}|~{3,})/);if(u){r?u[1][0]===i&&u[1].length>=o&&(r=!1,o=0):(r=!0,i=u[1][0],o=u[1].length),s+=l+c;continue}if(r){s+=l+c;continue}let f=kI(l,e);s+=f,f.endsWith(` +`)),p+=u.move(f),d(),p}function r(o,s,a){let l=o.value||"",c=1;for(e||c++;new RegExp("(^|[^$])"+"\\$".repeat(c)+"([^$]|$)").test(l);)c++;let u="$".repeat(c);/[^ \r\n]/.test(l)&&(/^[ \r\n]/.test(l)&&/[ \r\n]$/.test(l)||/^\$|\$$/.test(l))&&(l=" "+l+" ");let f=-1;for(;++f<a.unsafe.length;){let d=a.unsafe[f];if(!d.atBreak)continue;let p=a.compilePattern(d),h;for(;h=p.exec(l);){let m=h.index;l.codePointAt(m)===10&&l.codePointAt(m-1)===13&&m--,l=l.slice(0,m)+" "+l.slice(h.index+1)}}return u+l+u}function i(){return"$"}}var Zk={tokenize:dI,concrete:!0,name:"mathFlow"},Xk={tokenize:pI,partial:!0};function dI(t,e,n){let r=this,i=r.events[r.events.length-1],o=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,s=0;return a;function a(x){return t.enter("mathFlow"),t.enter("mathFlowFence"),t.enter("mathFlowFenceSequence"),l(x)}function l(x){return x===36?(t.consume(x),s++,l):s<2?n(x):(t.exit("mathFlowFenceSequence"),F(t,c,"whitespace")(x))}function c(x){return x===null||R(x)?f(x):(t.enter("mathFlowFenceMeta"),t.enter("chunkString",{contentType:"string"}),u(x))}function u(x){return x===null||R(x)?(t.exit("chunkString"),t.exit("mathFlowFenceMeta"),f(x)):x===36?n(x):(t.consume(x),u)}function f(x){return t.exit("mathFlowFence"),r.interrupt?e(x):t.attempt(Xk,d,g)(x)}function d(x){return t.attempt({tokenize:y,partial:!0},g,p)(x)}function p(x){return(o?F(t,h,"linePrefix",o+1):h)(x)}function h(x){return x===null?g(x):R(x)?t.attempt(Xk,d,g)(x):(t.enter("mathFlowValue"),m(x))}function m(x){return x===null||R(x)?(t.exit("mathFlowValue"),h(x)):(t.consume(x),m)}function g(x){return t.exit("mathFlow"),e(x)}function y(x,C,v){let I=0;return F(x,w,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function w(B){return x.enter("mathFlowFence"),x.enter("mathFlowFenceSequence"),N(B)}function N(B){return B===36?(I++,x.consume(B),N):I<s?v(B):(x.exit("mathFlowFenceSequence"),F(x,D,"whitespace")(B))}function D(B){return B===null||R(B)?(x.exit("mathFlowFence"),C(B)):v(B)}}}function pI(t,e,n){let r=this;return i;function i(s){return s===null?e(s):(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),o)}function o(s){return r.parser.lazy[r.now().line]?n(s):e(s)}}function eb(t){let n=(t||{}).singleDollarTextMath;return n==null&&(n=!0),{tokenize:r,resolve:hI,previous:mI,name:"mathText"};function r(i,o,s){let a=this,l=0,c,u;return f;function f(g){return i.enter("mathText"),i.enter("mathTextSequence"),d(g)}function d(g){return g===36?(i.consume(g),l++,d):l<2&&!n?s(g):(i.exit("mathTextSequence"),p(g))}function p(g){return g===null?s(g):g===36?(u=i.enter("mathTextSequence"),c=0,m(g)):g===32?(i.enter("space"),i.consume(g),i.exit("space"),p):R(g)?(i.enter("lineEnding"),i.consume(g),i.exit("lineEnding"),p):(i.enter("mathTextData"),h(g))}function h(g){return g===null||g===32||g===36||R(g)?(i.exit("mathTextData"),p(g)):(i.consume(g),h)}function m(g){return g===36?(i.consume(g),c++,m):c===l?(i.exit("mathTextSequence"),i.exit("mathText"),o(g)):(u.type="mathTextData",h(g))}}}function hI(t){let e=t.length-4,n=3,r,i;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="mathTextData"){t[e][1].type="mathTextPadding",t[n][1].type="mathTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)i===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(i=r):(r===e||t[r][1].type==="lineEnding")&&(t[i][1].type="mathTextData",r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),e-=r-i-2,r=i+2),i=void 0);return t}function mI(t){return t!==36||this.events[this.events.length-1][1].type==="characterEscape"}function vf(t){return{flow:{36:Zk},text:{36:eb(t)}}}var gI={};function sa(t){let e=this,n=t||gI,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(vf(n)),o.push(Ef()),s.push(Tf(n))}var tb=Ge("weiBeiRemarkMath",()=>sa),nb=ne("math_inline",()=>({group:"inline",content:"text*",inline:!0,atom:!0,parseDOM:[{tag:'span[data-type="math_inline"]',getContent:(t,e)=>E.from(e.text(t.dataset.value||""))}],toDOM:t=>["span",{"data-type":"math_inline","data-value":t.textContent},t.textContent],parseMarkdown:{match:t=>t.type==="inlineMath",runner:(t,e,n)=>t.openNode(n).addText(e.value).closeNode()},toMarkdown:{match:t=>t.type.name==="math_inline",runner:(t,e)=>t.addNode("inlineMath",void 0,e.textContent)}})),rb=ne("math_block",()=>({content:"text*",group:"block",marks:"",defining:!0,atom:!0,isolating:!0,attrs:{value:{default:""}},parseDOM:[{tag:'div[data-type="math_block"]',preserveWhitespace:"full",getAttrs:t=>({value:t.dataset.value||""})}],toDOM:t=>["div",{"data-type":"math_block","data-value":t.attrs.value},t.attrs.value],parseMarkdown:{match:t=>t.type==="math",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="math_block",runner:(t,e)=>t.addNode("math",void 0,e.attrs.value)}}));var ib=new Map,If=t=>{let e=ib.get(t);if(e)return e;let n=new Promise((r,i)=>{let o=document.createElement("script");o.src=new URL(t,document.baseURI).href,o.onload=()=>r(),o.onerror=()=>i(new Error(`Unable to load local editor runtime: ${t}`)),document.head.appendChild(o)});return ib.set(t,n),n},ob=()=>If("katex-runtime.js").then(()=>window.WeiBeiKaTeX),sb=()=>window.WeiBeiKaTeX,ab=()=>If("mermaid-runtime.js").then(()=>window.WeiBeiMermaid),lb=()=>If("prism-runtime.js").then(()=>window.WeiBeiPrism);var Af="[A-Za-z][A-Za-z0-9_-]*",yI=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},cb=(t,e,n)=>{let r=t.indexOf(e,n);for(;r>=0&&yI(t,r);)r=t.indexOf(e,r+e.length);return r},kI=(t,e)=>{let n=String(t||""),r="",i=0;for(;i<n.length;){let o=cb(n,"`",i);if(o<0){r+=e(n.slice(i));break}r+=e(n.slice(i,o));let s=n.slice(o).match(/^`+/)?.[0]||"`",a=cb(n,s,o+s.length);if(a<0){r+=e(n.slice(o));break}r+=n.slice(o,a+s.length),i=a+s.length}return r},bI=t=>String(t||"").replace(/(?<!\\)`/g,"\\`").replace(/\\\[\\\[/g,"[[").replace(/\\\]\\\]/g,"]]").replace(/\\=\\=([^=\n]+?)\\=\\=/g,"==$1==").replace(/\^\\\[/g,"^[").replace(/(^|\s)\\#(?=[\p{L}\p{N}_/-])/gu,"$1#").replace(/\\\$(?=\d)/g,"$").replace(new RegExp(`^(\\s*(?:>\\s*)*)\\\\(\\[!(?:${Af})\\])`,"gim"),"$1$2"),po=(t,e)=>{let n=String(t||"").split(/(\r?\n)/),r=!1,i="",o=0,s="";for(let a=0;a<n.length;a+=2){let l=n[a]||"",c=n[a+1]||"",u=l.match(/^\s*(?:>\s*)*(`{3,}|~{3,})/);if(u){r?u[1][0]===i&&u[1].length>=o&&(r=!1,o=0):(r=!0,i=u[1][0],o=u[1].length),s+=l+c;continue}if(r){s+=l+c;continue}let f=kI(l,e);s+=f,f.endsWith(` `)&&c||(s+=c)}return s},xI=t=>po(t,bI),wI=t=>/^\s*(?:>\s*)*<br\s*\/?>\s*$/i.test(t)?t:String(t||"").replace(/<br\s*\/?>[ \t]*/gi,` `.padStart(3)),SI=t=>po(t,wI);var CI=t=>String(t||"").replace(/(^|[^\\])\$(?=\d)/g,"$1\\$"),MI=t=>po(t,CI),EI=t=>po(t,e=>e.replace(/\\\[([\s\S]*?)\\\]/g,(n,r)=>`$$ ${String(r).trim()} @@ -61,21 +61,21 @@ $$`).replace(/\\\(([^\n]*?)\\\)/g,(n,r)=>`$${String(r).trim()}$`)),TI=t=>po(t,e= ${String(r).trim()} $$`).replace(/^[ \t]*\$\$([^$\n]+)\$\$[ \t]*$/gm,(n,r)=>`$$ ${String(r).trim()} -$$`).replace(/\\hat\s+(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}").replace(/\\hat(?!\{)(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}")),aa=(t,e)=>{let n=SI(t);return(e==="userPaste"||e==="agentGenerated")&&(n=EI(n)),e==="agentGenerated"&&(n=TI(n)),MI(n)},la=t=>{let e=t||"",n=e.match(/^(---\n[\s\S]*?\n---)(?:\n+|$)/);return n?{frontmatter:n[1],body:e.slice(n[0].length)}:{frontmatter:"",body:e}},lb=(t,e)=>{let n=xI(e),r=t?n.replace(/^\n+/,""):n;return t?`${t} +$$`).replace(/\\hat\s+(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}").replace(/\\hat(?!\{)(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}")),aa=(t,e)=>{let n=SI(t);return(e==="userPaste"||e==="agentGenerated")&&(n=EI(n)),e==="agentGenerated"&&(n=TI(n)),MI(n)},la=t=>{let e=t||"",n=e.match(/^(---\n[\s\S]*?\n---)(?:\n+|$)/);return n?{frontmatter:n[1],body:e.slice(n[0].length)}:{frontmatter:"",body:e}},ub=(t,e)=>{let n=xI(e),r=t?n.replace(/^\n+/,""):n;return t?`${t} -${r}`:r};var vI=["transactions","fullSerializations","bridgeMessages","bridgeBytes","decorationNodes","decorationCacheHits","katexRenders","mermaidRenders","imageScans","imageNodeUpdates","codeTokenizations","outlineReports"],cb=()=>Object.fromEntries(vI.map(t=>[t,0])),xt=(t,e,n=1)=>{t&&(t[e]+=n)};var ub=t=>JSON.stringify(t.map(({level:e,title:n})=>[e,n]));var fb=(t,e)=>({...e,protocolVersion:2,documentID:t.documentID,documentGeneration:t.documentGeneration,revision:t.revision});var II=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},db=t=>{let e=[],n=/!\[\[([^\]\n]+)\]\]|\[\[([^\]\n]+)\]\]|==([^=\n]+)==|\^\[([^\]\n]+)\]/g,r=0;for(let i of t.matchAll(n)){let o=i.index||0;if(II(t,o))continue;o>r&&e.push({type:"text",value:t.slice(r,o)});let s=i[1]??i[2];if(s!==void 0){let a=s.indexOf("|"),l=(a<0?s:s.slice(0,a)).trim(),c=(a<0?"":s.slice(a+1)).trim();e.push({type:i[1]===void 0?"wikiLink":"embed",raw:s,target:l,label:c})}else i[3]!==void 0?e.push({type:"highlight",value:i[3]}):e.push({type:"inlineFootnote",value:i[4]});r=o+i[0].length}return r<t.length&&e.push({type:"text",value:t.slice(r)}),e.length?e:[{type:"text",value:t}]};var pb=t=>{let e=t.match(/^\[!([A-Za-z][A-Za-z0-9_-]*)\]([+-]?)(?:[ \t]+(.+))?$/);return e?{calloutType:e[1].toLowerCase(),fold:e[2]||"",title:(e[3]||"").trim()}:null},hb=t=>`[!${t.calloutType}]${t.fold}${t.title?` ${t.title}`:""}`;var Nf=new Set(["system","serif","literary"]),AI=t=>{let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],i=r.type==="html"?String(r.value||"").match(/^<span data-weibei-font="(system|serif|literary)">$/):null;if(!i){e.push(r);continue}let o=t.findIndex((s,a)=>a>n&&s.type==="html"&&String(s.value||"")==="</span>");if(o<0){e.push(r);continue}e.push({type:"writingFont",font:i[1],children:t.slice(n+1,o)}),n=o}return e},NI=t=>t.type==="text"?{type:"text",value:t.value}:t.type==="highlight"?{type:"highlight",children:[{type:"text",value:t.value}]}:t.type==="inlineFootnote"?{type:"inlineFootnote",value:t.value}:{type:t.type,raw:t.raw,target:t.target,label:t.label},mb=t=>{if(!t.children||["code","inlineCode","html"].includes(t.type))return;if(t.type==="blockquote"){let n=t.children[0],r=n?.type==="paragraph"&&n.children?.length===1&&n.children[0].type==="text"?String(n.children[0].value||""):"",i=pb(r);if(i){t.type="callout",t.calloutType=i.calloutType,t.fold=i.fold,t.title=i.title,t.children=t.children.slice(1),t.children.length===0&&t.children.push({type:"paragraph",children:[]});let o=t.children[0]?.type==="paragraph"?t.children[0].children?.[0]:null;o?.type==="text"&&(o.value=String(o.value||"").replace(/^\[![A-Za-z][A-Za-z0-9_-]*\][+-]?[ \t]*/,""))}}let e=t.children.flatMap(n=>n.type!=="text"?(mb(n),[n]):db(String(n.value||"")).map(NI));t.children=AI(e)},RI=Ge("weiBeiStructuredMarkdown",()=>(function(){let e=this.data();return(e.toMarkdownExtensions||(e.toMarkdownExtensions=[])).push({handlers:{wikiLink:(r,i,o,s)=>`[[${o.safe(r.raw,{...s,before:"[[",after:"]]"})}]]`,embed:(r,i,o,s)=>`![[${o.safe(r.raw,{...s,before:"![[",after:"]]"})}]]`,inlineFootnote:(r,i,o,s)=>`^[${o.safe(r.value,{...s,before:"^[",after:"]"})}]`,highlight:(r,i,o,s)=>`==${o.containerPhrasing(r,{...s,before:"==",after:"=="})}==`,writingFont:(r,i,o,s)=>{let a=Nf.has(r.font)?r.font:"serif",l=o.containerPhrasing(r,{...s,before:">",after:"<"});return`<span data-weibei-font="${a}">${l}</span>`},callout:(r,i,o,s)=>{let l={type:"blockquote",children:[{type:"paragraph",children:[{type:"text",value:hb({calloutType:r.calloutType,fold:r.fold||"",title:r.title||""})}]},...r.children||[]]},c=o.enter("blockquote"),u=o.createTracker(s);u.move("> "),u.shift(2);let f=o.indentLines(o.containerFlow(l,u.current()),(d,p,h)=>`>${h?"":" "}${d}`);return c(),f}}}),r=>mb(r)})),gb=te("wiki_link",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="wiki_link"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"wiki_link","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-wikilink weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="wikiLink",runner:(t,e,n)=>{t.addNode(n,{raw:e.raw,target:e.target,label:e.label})}},toMarkdown:{match:t=>t.type.name==="wiki_link",runner:(t,e)=>t.addNode("wikiLink",void 0,void 0,e.attrs)}})),yb=te("embed",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="embed"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"embed","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-embed-note weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="embed",runner:(t,e,n)=>t.addNode(n,{raw:e.raw,target:e.target,label:e.label})},toMarkdown:{match:t=>t.type.name==="embed",runner:(t,e)=>t.addNode("embed",void 0,void 0,e.attrs)}})),kb=te("inline_footnote",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{value:{default:""}},parseDOM:[{tag:'span[data-type="inline_footnote"]',getAttrs:t=>t instanceof HTMLElement?{value:t.dataset.value||""}:!1}],toDOM:t=>["span",{"data-type":"inline_footnote","data-value":t.attrs.value,class:"weibei-inline-footnote weibei-structured-node"},t.attrs.value],parseMarkdown:{match:t=>t.type==="inlineFootnote",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="inline_footnote",runner:(t,e)=>t.addNode("inlineFootnote",void 0,void 0,{value:e.attrs.value})}})),OI=fe(t=>ls(/!\[\[([^\]\n]+)\]\]$/,yb.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),DI=fe(t=>ls(/(?<!!)\[\[([^\]\n]+)\]\]$/,gb.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),BI=fe(t=>ls(/\^\[([^\]\n]+)\]$/,kb.type(t),{getAttr:e=>({value:e[1]||""})})),bb=yt("highlight",()=>({parseDOM:[{tag:"mark.weibei-highlight"}],toDOM:()=>["mark",{class:"weibei-highlight"},0],parseMarkdown:{match:t=>t.type==="highlight",runner:(t,e,n)=>t.openMark(n).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="highlight",runner:(t,e)=>{t.withMark(e,"highlight")}}})),LI=yt("writing_font",()=>({attrs:{font:{default:"serif"}},excludes:"writing_font",priority:10,parseDOM:[{tag:"span[data-weibei-font]",getAttrs:t=>{let e=t instanceof HTMLElement?t.dataset.weibeiFont:"";return e&&Nf.has(e)?{font:e}:!1}}],toDOM:t=>["span",{"data-weibei-font":Nf.has(t.attrs.font)?t.attrs.font:"serif"},0],parseMarkdown:{match:t=>t.type==="writingFont",runner:(t,e,n)=>t.openMark(n,{font:e.font}).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="writing_font",runner:(t,e)=>{t.withMark(e,"writingFont",void 0,{font:e.attrs.font})}}})),PI=fe(t=>Ht(/(?:^|[^\\=])==([^=\n]+)==$/,bb.type(t))),FI=te("callout",()=>({content:"block+",group:"block",defining:!0,selectable:!0,attrs:{calloutType:{default:"note"},title:{default:""},fold:{default:""}},parseDOM:[{tag:'blockquote[data-type="callout"]',getAttrs:t=>t instanceof HTMLElement?{calloutType:t.dataset.callout||"note",title:t.dataset.calloutTitle||"",fold:t.dataset.calloutFold||""}:!1}],toDOM:t=>["blockquote",{"data-type":"callout","data-callout":t.attrs.calloutType,"data-callout-title":t.attrs.title,"data-callout-fold":t.attrs.fold,class:`weibei-callout weibei-callout-${t.attrs.calloutType}`},0],parseMarkdown:{match:t=>t.type==="callout",runner:(t,e,n)=>t.openNode(n,{calloutType:e.calloutType,title:e.title,fold:e.fold}).next(e.children).closeNode()},toMarkdown:{match:t=>t.type.name==="callout",runner:(t,e)=>{t.openNode("callout",void 0,e.attrs).next(e.content).closeNode()}}})),xb=[RI,gb,yb,kb,LI,bb,PI,FI,OI,DI,BI].flat();var zI=window.webkit?.messageHandlers,St=window.weiBeiEditorCheckMode?cb():null,re,ha="",Wf=null,mo=null,da=!1,Lf=null,oi={text:null,rectKey:null,detailKey:null},bo="",lt=!1,ma=window.weiBeiMarkdownCompactPreview===!0,pa=window.weiBeiDocumentID||"",cr=window.weiBeiDocumentGeneration||0,$I={revision:0,dirty:!1};var Pb=!1,_I=0,Fb=window.weiBeiMarkdownBaseURL||"",HI=window.weiBeiLocalImageScheme||"weibeiimage";var VI=0,wb=0,si=0,WI=new Map,jI=new Map;var qI=[Zk,eb,tb].flat(),yo=0,Ye=null,Zt=null,ga=null,Pf=[],li=0;var zb=t=>t==="en"?"en":"zh-Hans",ua=zb(window.weiBeiInterfaceLanguage);var Sb={"zh-Hans":{properties:"\u5C5E\u6027",bootFailed:"Milkdown \u521D\u59CB\u5316\u5931\u8D25",imageMissing:"\u56FE\u7247\u672A\u627E\u5230",inlineFootnote:"\u884C\u5185\u811A\u6CE8\uFF1A{value}",openOrCreateNote:"\u6253\u5F00\u6216\u521B\u5EFA\u7B14\u8BB0\uFF1A{value}",openSource:"\u6253\u5F00\u6765\u6E90\uFF1A{value}",embed:"\u5D4C\u5165\uFF1A{value}",mermaidRendering:"\u6B63\u5728\u6E32\u67D3 Mermaid \u56FE\u8868...",mermaidFailed:`Mermaid \u56FE\u8868\u672A\u89E3\u6790 +${r}`:r};var vI=["transactions","fullSerializations","bridgeMessages","bridgeBytes","decorationNodes","decorationCacheHits","katexRenders","mermaidRenders","imageScans","imageNodeUpdates","codeTokenizations","outlineReports"],fb=()=>Object.fromEntries(vI.map(t=>[t,0])),xt=(t,e,n=1)=>{t&&(t[e]+=n)};var db=t=>JSON.stringify(t.map(({level:e,title:n})=>[e,n]));var pb=(t,e)=>({...e,protocolVersion:2,documentID:t.documentID,documentGeneration:t.documentGeneration,revision:t.revision});var II=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},hb=t=>{let e=[],n=/!\[\[([^\]\n]+)\]\]|\[\[([^\]\n]+)\]\]|==([^=\n]+)==|\^\[([^\]\n]+)\]/g,r=0;for(let i of t.matchAll(n)){let o=i.index||0;if(II(t,o))continue;o>r&&e.push({type:"text",value:t.slice(r,o)});let s=i[1]??i[2];if(s!==void 0){let a=s.indexOf("|"),l=(a<0?s:s.slice(0,a)).trim(),c=(a<0?"":s.slice(a+1)).trim();e.push({type:i[1]===void 0?"wikiLink":"embed",raw:s,target:l,label:c})}else i[3]!==void 0?e.push({type:"highlight",value:i[3]}):e.push({type:"inlineFootnote",value:i[4]});r=o+i[0].length}return r<t.length&&e.push({type:"text",value:t.slice(r)}),e.length?e:[{type:"text",value:t}]};var mb=t=>{let e=t.match(/^\[!([A-Za-z][A-Za-z0-9_-]*)\]([+-]?)(?:[ \t]+(.+))?$/);return e?{calloutType:e[1].toLowerCase(),fold:e[2]||"",title:(e[3]||"").trim()}:null},gb=t=>`[!${t.calloutType}]${t.fold}${t.title?` ${t.title}`:""}`;var Nf=new Set(["system","serif","literary"]),AI=t=>{let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],i=r.type==="html"?String(r.value||"").match(/^<span data-weibei-font="(system|serif|literary)">$/):null;if(!i){e.push(r);continue}let o=t.findIndex((s,a)=>a>n&&s.type==="html"&&String(s.value||"")==="</span>");if(o<0){e.push(r);continue}e.push({type:"writingFont",font:i[1],children:t.slice(n+1,o)}),n=o}return e},NI=t=>t.type==="text"?{type:"text",value:t.value}:t.type==="highlight"?{type:"highlight",children:[{type:"text",value:t.value}]}:t.type==="inlineFootnote"?{type:"inlineFootnote",value:t.value}:{type:t.type,raw:t.raw,target:t.target,label:t.label},yb=t=>{if(!t.children||["code","inlineCode","html"].includes(t.type))return;if(t.type==="blockquote"){let n=t.children[0],r=n?.type==="paragraph"&&n.children?.length===1&&n.children[0].type==="text"?String(n.children[0].value||""):"",i=mb(r);if(i){t.type="callout",t.calloutType=i.calloutType,t.fold=i.fold,t.title=i.title,t.children=t.children.slice(1),t.children.length===0&&t.children.push({type:"paragraph",children:[]});let o=t.children[0]?.type==="paragraph"?t.children[0].children?.[0]:null;o?.type==="text"&&(o.value=String(o.value||"").replace(/^\[![A-Za-z][A-Za-z0-9_-]*\][+-]?[ \t]*/,""))}}let e=t.children.flatMap(n=>n.type!=="text"?(yb(n),[n]):hb(String(n.value||"")).map(NI));t.children=AI(e)},RI=Ge("weiBeiStructuredMarkdown",()=>(function(){let e=this.data();return(e.toMarkdownExtensions||(e.toMarkdownExtensions=[])).push({handlers:{wikiLink:(r,i,o,s)=>`[[${o.safe(r.raw,{...s,before:"[[",after:"]]"})}]]`,embed:(r,i,o,s)=>`![[${o.safe(r.raw,{...s,before:"![[",after:"]]"})}]]`,inlineFootnote:(r,i,o,s)=>`^[${o.safe(r.value,{...s,before:"^[",after:"]"})}]`,highlight:(r,i,o,s)=>`==${o.containerPhrasing(r,{...s,before:"==",after:"=="})}==`,writingFont:(r,i,o,s)=>{let a=Nf.has(r.font)?r.font:"serif",l=o.containerPhrasing(r,{...s,before:">",after:"<"});return`<span data-weibei-font="${a}">${l}</span>`},callout:(r,i,o,s)=>{let l={type:"blockquote",children:[{type:"paragraph",children:[{type:"text",value:gb({calloutType:r.calloutType,fold:r.fold||"",title:r.title||""})}]},...r.children||[]]},c=o.enter("blockquote"),u=o.createTracker(s);u.move("> "),u.shift(2);let f=o.indentLines(o.containerFlow(l,u.current()),(d,p,h)=>`>${h?"":" "}${d}`);return c(),f}}}),r=>yb(r)})),kb=ne("wiki_link",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="wiki_link"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"wiki_link","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-wikilink weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="wikiLink",runner:(t,e,n)=>{t.addNode(n,{raw:e.raw,target:e.target,label:e.label})}},toMarkdown:{match:t=>t.type.name==="wiki_link",runner:(t,e)=>t.addNode("wikiLink",void 0,void 0,e.attrs)}})),bb=ne("embed",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{raw:{default:""},target:{default:""},label:{default:""}},parseDOM:[{tag:'span[data-type="embed"]',getAttrs:t=>t instanceof HTMLElement?{raw:t.dataset.raw||"",target:t.dataset.target||"",label:t.dataset.label||""}:!1}],toDOM:t=>["span",{"data-type":"embed","data-raw":t.attrs.raw,"data-target":t.attrs.target,"data-label":t.attrs.label,class:"weibei-embed-note weibei-structured-node"},t.attrs.label||t.attrs.target],parseMarkdown:{match:t=>t.type==="embed",runner:(t,e,n)=>t.addNode(n,{raw:e.raw,target:e.target,label:e.label})},toMarkdown:{match:t=>t.type.name==="embed",runner:(t,e)=>t.addNode("embed",void 0,void 0,e.attrs)}})),xb=ne("inline_footnote",()=>({group:"inline",inline:!0,atom:!0,selectable:!0,attrs:{value:{default:""}},parseDOM:[{tag:'span[data-type="inline_footnote"]',getAttrs:t=>t instanceof HTMLElement?{value:t.dataset.value||""}:!1}],toDOM:t=>["span",{"data-type":"inline_footnote","data-value":t.attrs.value,class:"weibei-inline-footnote weibei-structured-node"},t.attrs.value],parseMarkdown:{match:t=>t.type==="inlineFootnote",runner:(t,e,n)=>t.addNode(n,{value:e.value})},toMarkdown:{match:t=>t.type.name==="inline_footnote",runner:(t,e)=>t.addNode("inlineFootnote",void 0,void 0,{value:e.attrs.value})}})),OI=fe(t=>ls(/!\[\[([^\]\n]+)\]\]$/,bb.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),DI=fe(t=>ls(/(?<!!)\[\[([^\]\n]+)\]\]$/,kb.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),BI=fe(t=>ls(/\^\[([^\]\n]+)\]$/,xb.type(t),{getAttr:e=>({value:e[1]||""})})),wb=yt("highlight",()=>({parseDOM:[{tag:"mark.weibei-highlight"}],toDOM:()=>["mark",{class:"weibei-highlight"},0],parseMarkdown:{match:t=>t.type==="highlight",runner:(t,e,n)=>t.openMark(n).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="highlight",runner:(t,e)=>{t.withMark(e,"highlight")}}})),LI=yt("writing_font",()=>({attrs:{font:{default:"serif"}},excludes:"writing_font",priority:10,parseDOM:[{tag:"span[data-weibei-font]",getAttrs:t=>{let e=t instanceof HTMLElement?t.dataset.weibeiFont:"";return e&&Nf.has(e)?{font:e}:!1}}],toDOM:t=>["span",{"data-weibei-font":Nf.has(t.attrs.font)?t.attrs.font:"serif"},0],parseMarkdown:{match:t=>t.type==="writingFont",runner:(t,e,n)=>t.openMark(n,{font:e.font}).next(e.children).closeMark(n)},toMarkdown:{match:t=>t.type.name==="writing_font",runner:(t,e)=>{t.withMark(e,"writingFont",void 0,{font:e.attrs.font})}}})),PI=fe(t=>Ht(/(?:^|[^\\=])==([^=\n]+)==$/,wb.type(t))),FI=ne("callout",()=>({content:"block+",group:"block",defining:!0,selectable:!0,attrs:{calloutType:{default:"note"},title:{default:""},fold:{default:""}},parseDOM:[{tag:'blockquote[data-type="callout"]',getAttrs:t=>t instanceof HTMLElement?{calloutType:t.dataset.callout||"note",title:t.dataset.calloutTitle||"",fold:t.dataset.calloutFold||""}:!1}],toDOM:t=>["blockquote",{"data-type":"callout","data-callout":t.attrs.calloutType,"data-callout-title":t.attrs.title,"data-callout-fold":t.attrs.fold,class:`weibei-callout weibei-callout-${t.attrs.calloutType}`},0],parseMarkdown:{match:t=>t.type==="callout",runner:(t,e,n)=>t.openNode(n,{calloutType:e.calloutType,title:e.title,fold:e.fold}).next(e.children).closeNode()},toMarkdown:{match:t=>t.type.name==="callout",runner:(t,e)=>{t.openNode("callout",void 0,e.attrs).next(e.content).closeNode()}}})),Sb=[RI,kb,bb,xb,LI,wb,PI,FI,OI,DI,BI].flat();var zI=window.webkit?.messageHandlers,St=window.weiBeiEditorCheckMode?fb():null,re,ha="",jf=null,mo=null,da=!1,Lf=null,oi={text:null,rectKey:null,detailKey:null},bo="",lt=!1,ma=window.weiBeiMarkdownCompactPreview===!0,pa=window.weiBeiDocumentID||"",cr=window.weiBeiDocumentGeneration||0,$I={revision:0,dirty:!1};var Fb=!1,_I=0,zb=window.weiBeiMarkdownBaseURL||"",HI=window.weiBeiLocalImageScheme||"weibeiimage";var VI=0,Cb=0,si=0,WI=new Map,jI=new Map;var qI=[tb,nb,rb].flat(),yo=0,Ye=null,Zt=null,ga=null,Pf=[],li=0;var $b=t=>t==="en"?"en":"zh-Hans",ua=$b(window.weiBeiInterfaceLanguage);var Mb={"zh-Hans":{properties:"\u5C5E\u6027",bootFailed:"Milkdown \u521D\u59CB\u5316\u5931\u8D25",imageMissing:"\u56FE\u7247\u672A\u627E\u5230",inlineFootnote:"\u884C\u5185\u811A\u6CE8\uFF1A{value}",openOrCreateNote:"\u6253\u5F00\u6216\u521B\u5EFA\u7B14\u8BB0\uFF1A{value}",openSource:"\u6253\u5F00\u6765\u6E90\uFF1A{value}",embed:"\u5D4C\u5165\uFF1A{value}",mermaidRendering:"\u6B63\u5728\u6E32\u67D3 Mermaid \u56FE\u8868...",mermaidFailed:`Mermaid \u56FE\u8868\u672A\u89E3\u6790 {value}`,uploadingImage:"\u6B63\u5728\u6536\u7EB3\u56FE\u7247...",emptyNotePlaceholder:"\u4ECE\u8FD9\u91CC\u5F00\u59CB\u5199\u4E0B\u7B2C\u4E00\u53E5\u2026",slashNoResults:"\u6CA1\u6709\u5339\u914D\u547D\u4EE4",slashStructure:"\u7ED3\u6784",slashLists:"\u5217\u8868",slashContent:"\u5185\u5BB9",slashRichContent:"\u4E30\u5BCC\u5185\u5BB9",slashFonts:"\u5B57\u4F53",slashHeading1:"\u4E00\u7EA7\u6807\u9898",slashHeading2:"\u4E8C\u7EA7\u6807\u9898",slashHeading3:"\u4E09\u7EA7\u6807\u9898",slashHeading4:"\u56DB\u7EA7\u6807\u9898",slashHeading5:"\u4E94\u7EA7\u6807\u9898",slashHeading6:"\u516D\u7EA7\u6807\u9898",slashBulletList:"\u65E0\u5E8F\u5217\u8868",slashOrderedList:"\u6709\u5E8F\u5217\u8868",slashTaskList:"\u5F85\u529E\u5217\u8868",slashQuote:"\u5F15\u7528",slashCallout:"\u63D0\u793A\u5757",slashCode:"\u4EE3\u7801\u5757",slashDivider:"\u5206\u9694\u7EBF",slashTable:"\u8868\u683C",slashImage:"\u56FE\u7247",slashMermaid:"Mermaid \u56FE\u8868",slashLink:"\u94FE\u63A5",slashWikiLink:"\u7B14\u8BB0\u94FE\u63A5",slashFootnote:"\u811A\u6CE8",slashInlineMath:"\u884C\u5185\u516C\u5F0F",slashBlockMath:"\u5757\u7EA7\u516C\u5F0F",slashFontSystem:"\u5B57\u4F53\uFF1ASF Pro / PingFang SC",slashFontSerif:"\u5B57\u4F53\uFF1ASongti SC",slashFontLiterary:"\u5B57\u4F53\uFF1AWeiBeiStele",slashRows:"\u884C",slashColumns:"\u5217",slashInsertTable:"\u63D2\u5165\u8868\u683C",slashImageFailed:"\u56FE\u7247\u8BFB\u53D6\u6216\u4FDD\u5B58\u5931\u8D25",tableAddRow:"\uFF0B\u884C",tableDeleteRow:"\u2212\u884C",tableAddColumn:"\uFF0B\u5217",tableDeleteColumn:"\u2212\u5217",tableHeader:"\u8868\u5934",linkPlaceholder:"\u94FE\u63A5\u6587\u5B57",wikiLinkPlaceholder:"\u7B14\u8BB0\u6807\u9898",footnotePlaceholder:"\u811A\u6CE8\u5185\u5BB9",codeLanguage:"\u4EE3\u7801\u8BED\u8A00",codeLanguagePlaceholder:"text"},en:{properties:"Properties",bootFailed:"Milkdown failed to initialize",imageMissing:"Image not found",inlineFootnote:"Inline footnote: {value}",openOrCreateNote:"Open or create note: {value}",openSource:"Open source: {value}",embed:"Embed: {value}",mermaidRendering:"Rendering Mermaid diagram...",mermaidFailed:`Mermaid diagram did not parse -{value}`,uploadingImage:"Saving image...",emptyNotePlaceholder:"Start writing here\u2026",slashNoResults:"No matching commands",slashStructure:"Structure",slashLists:"Lists",slashContent:"Content",slashRichContent:"Rich content",slashFonts:"Fonts",slashHeading1:"Heading 1",slashHeading2:"Heading 2",slashHeading3:"Heading 3",slashHeading4:"Heading 4",slashHeading5:"Heading 5",slashHeading6:"Heading 6",slashBulletList:"Bulleted list",slashOrderedList:"Numbered list",slashTaskList:"To-do list",slashQuote:"Quote",slashCallout:"Callout",slashCode:"Code block",slashDivider:"Divider",slashTable:"Table",slashImage:"Image",slashMermaid:"Mermaid diagram",slashLink:"Link",slashWikiLink:"Note link",slashFootnote:"Footnote",slashInlineMath:"Inline formula",slashBlockMath:"Block formula",slashFontSystem:"Font: SF Pro / PingFang SC",slashFontSerif:"Font: Songti SC",slashFontLiterary:"Font: WeiBeiStele",slashRows:"Rows",slashColumns:"Columns",slashInsertTable:"Insert table",slashImageFailed:"Image could not be read or saved",tableAddRow:"+ Row",tableDeleteRow:"\u2212 Row",tableAddColumn:"+ Column",tableDeleteColumn:"\u2212 Column",tableHeader:"Header",linkPlaceholder:"Link text",wikiLinkPlaceholder:"Note title",footnotePlaceholder:"Footnote",codeLanguage:"Code language",codeLanguagePlaceholder:"text"}},Dt=(t,e={})=>{let n=Sb[ua]?.[t]||Sb["zh-Hans"][t]||t;for(let[r,i]of Object.entries(e))n=n.split(`{${r}}`).join(String(i));return n},KI=()=>Dt("properties"),UI=new RegExp(`(^|\\n)\\s*(?:>\\s*)*\\\\?\\[!(?:${Af})\\][+-]?[ \\t]*`,"gi"),JI=/<br\s*\/?>/gi,$b=t=>String(t||"").replace(JI,` -`).replace(/%%[\s\S]*?%%\n?/g,"").replace(/!\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=lA(n);return r.label||r.target}).replace(/\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=Kb(n);return r.display||r.target}).replace(/!\[([^\]\n]*)\]\([^\)\n]+\)/g,(e,n)=>jb(n).alt||"").replace(/\[([^\]\n]+)\]\([^\)\n]+\)/g,"$1").replace(/==([^=\n]+)==/g,"$1").replace(/~~([^~\n]+)~~/g,"$1").replace(/`([^`\n]+)`/g,"$1").replace(/\^\[([^\]\n]+)\]/g,"$1").replace(UI,"$1").replace(/(^|\n)\s*>\s?/g,"$1").replace(/(^|\n)\s*[-*+]\s+\[[ xX]\]\s*/g,"$1").replace(/[ \t]+\n/g,` +{value}`,uploadingImage:"Saving image...",emptyNotePlaceholder:"Start writing here\u2026",slashNoResults:"No matching commands",slashStructure:"Structure",slashLists:"Lists",slashContent:"Content",slashRichContent:"Rich content",slashFonts:"Fonts",slashHeading1:"Heading 1",slashHeading2:"Heading 2",slashHeading3:"Heading 3",slashHeading4:"Heading 4",slashHeading5:"Heading 5",slashHeading6:"Heading 6",slashBulletList:"Bulleted list",slashOrderedList:"Numbered list",slashTaskList:"To-do list",slashQuote:"Quote",slashCallout:"Callout",slashCode:"Code block",slashDivider:"Divider",slashTable:"Table",slashImage:"Image",slashMermaid:"Mermaid diagram",slashLink:"Link",slashWikiLink:"Note link",slashFootnote:"Footnote",slashInlineMath:"Inline formula",slashBlockMath:"Block formula",slashFontSystem:"Font: SF Pro / PingFang SC",slashFontSerif:"Font: Songti SC",slashFontLiterary:"Font: WeiBeiStele",slashRows:"Rows",slashColumns:"Columns",slashInsertTable:"Insert table",slashImageFailed:"Image could not be read or saved",tableAddRow:"+ Row",tableDeleteRow:"\u2212 Row",tableAddColumn:"+ Column",tableDeleteColumn:"\u2212 Column",tableHeader:"Header",linkPlaceholder:"Link text",wikiLinkPlaceholder:"Note title",footnotePlaceholder:"Footnote",codeLanguage:"Code language",codeLanguagePlaceholder:"text"}},Dt=(t,e={})=>{let n=Mb[ua]?.[t]||Mb["zh-Hans"][t]||t;for(let[r,i]of Object.entries(e))n=n.split(`{${r}}`).join(String(i));return n},KI=()=>Dt("properties"),UI=new RegExp(`(^|\\n)\\s*(?:>\\s*)*\\\\?\\[!(?:${Af})\\][+-]?[ \\t]*`,"gi"),JI=/<br\s*\/?>/gi,_b=t=>String(t||"").replace(JI,` +`).replace(/%%[\s\S]*?%%\n?/g,"").replace(/!\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=lA(n);return r.label||r.target}).replace(/\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=Ub(n);return r.display||r.target}).replace(/!\[([^\]\n]*)\]\([^\)\n]+\)/g,(e,n)=>qb(n).alt||"").replace(/\[([^\]\n]+)\]\([^\)\n]+\)/g,"$1").replace(/==([^=\n]+)==/g,"$1").replace(/~~([^~\n]+)~~/g,"$1").replace(/`([^`\n]+)`/g,"$1").replace(/\^\[([^\]\n]+)\]/g,"$1").replace(UI,"$1").replace(/(^|\n)\s*>\s?/g,"$1").replace(/(^|\n)\s*[-*+]\s+\[[ xX]\]\s*/g,"$1").replace(/[ \t]+\n/g,` `).replace(/\n{2,}/g,` -`).trim(),_b=t=>t==="glassLight"||t==="glassMist"?"xuan":t==="glassDark"||t==="glassSlate"?"stele":t==="xuan"||t==="inkstone"||t==="stele"||t==="paper"?t:"paper",GI=t=>["glassLight","glassDark","glassMist","glassSlate"].includes(t)?t:"",ai=_b(window.weiBeiTheme),QI=()=>{switch(ai){case"inkstone":return{background:"#151515",primaryColor:"#1c1c1c",primaryTextColor:"#d7cbb0",primaryBorderColor:"#3a3328",lineColor:"#8b5e3c",secondaryColor:"#222222",tertiaryColor:"#171717",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"stele":return{background:"#1e2228",primaryColor:"#252a32",primaryTextColor:"#d2d6dc",primaryBorderColor:"#3a414c",lineColor:"#8a7a5c",secondaryColor:"#2a3038",tertiaryColor:"#1a1e24",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"xuan":return{background:"#f7f4ef",primaryColor:"#fcfbf8",primaryTextColor:"#25231f",primaryBorderColor:"#d8d2c6",lineColor:"#6e634f",secondaryColor:"#ebe6dc",tertiaryColor:"#f7f4ef",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};default:return{background:"#fbf5e8",primaryColor:"#f6eddc",primaryTextColor:"#2e261f",primaryBorderColor:"#cbb79b",lineColor:"#7a6250",secondaryColor:"#efe4d2",tertiaryColor:"#f8f0e1",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'}}},YI=t=>{t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:QI()})},Hb=t=>{ai=_b(t);let e=GI(t);document.documentElement.dataset.weibeiTheme=ai,document.body&&(document.body.dataset.weibeiTheme=ai),e?(document.documentElement.dataset.weibeiGlass=e,document.body&&(document.body.dataset.weibeiGlass=e)):(delete document.documentElement.dataset.weibeiGlass,document.body&&delete document.body.dataset.weibeiGlass),si+=1};Hb(window.weiBeiTheme);var lr=t=>{if(window.WeiBeiEditorBootFailed){window.WeiBeiEditorBootFailed(t);return}let e=document.querySelector("#editor");e&&(e.innerHTML=`<pre style="white-space:pre-wrap;color:#9f3427;padding:24px;font:13px/1.5 SFMono-Regular,Menlo,monospace;">${Dt("bootFailed")} -${String(t?.stack||t)}</pre>`)};window.addEventListener("error",t=>lr(t.error||t.message));window.addEventListener("unhandledrejection",t=>lr(t.reason));var ct=(t,e={})=>{let n=zI?.[t];if(!n)return;let r=fb({documentID:pa,documentGeneration:cr,revision:$I.revision},e);typeof r.markdown=="string"&&(_I+=1),xt(St,"bridgeMessages"),St&&xt(St,"bridgeBytes",new TextEncoder().encode(JSON.stringify(r)).byteLength),n.postMessage(r)};var en=null;var XI=()=>document.documentElement.dataset.weibeiReduceMotion==="true",ZI=t=>{document.documentElement.dataset.weibeiReduceMotion=t===!0||t==="true"?"true":"false"},eA=t=>{let e=Number(t),n=Number.isFinite(e)&&e>0?e:1;document.documentElement.style.setProperty("--weibei-text-scale",String(n))};document.documentElement.dataset.weibeiCompactPreview=ma?"true":"false";window.weiBeiEditorCheckMode&&(document.documentElement.dataset.weibeiCheckMode="true");var Cb=0,Rf=0,Mb=0,Eb=0,Vb=()=>[document.querySelector("#editor"),document.querySelector(".milkdown"),document.querySelector(".ProseMirror")].filter(Boolean),tA=t=>{let e=t.getBoundingClientRect?.();return Math.max(0,t.scrollHeight||0,t.offsetHeight||0,t.clientHeight||0,e?.height||0)},Tb=()=>{let t=Vb(),e=Math.ceil(Math.max(1,...t.map(tA))),n=Math.ceil(Math.max(1,...t.map(r=>r.getBoundingClientRect?.().width||r.clientWidth||0)));window.WeiBeiCompactPreviewHeight=e,window.WeiBeiCompactPreviewMeasuredAt=Date.now(),!(Math.abs(e-Mb)<1&&Math.abs(n-Eb)<1)&&(Mb=e,Eb=n,ct("contentHeightChanged",{height:e}))},nA=()=>{!ma||!Pb||(Tb(),window.cancelAnimationFrame(Cb),Cb=window.requestAnimationFrame(Tb))},Ct=()=>{if(!ma||Rf)return;let t=Ye!==null?100:40;Rf=window.setTimeout(()=>{Rf=0,nA()},t)},rA=()=>{if(ma){if(window.ResizeObserver){let t=new ResizeObserver(Ct);Vb().forEach(e=>t.observe(e))}Ct(),document.fonts?.ready?.then(Ct).catch(()=>{})}},iA=()=>{let t=window.getSelection();if(!t||t.rangeCount===0)return null;let e=t.getRangeAt(0).getBoundingClientRect();return!e||e.width+e.height===0?null:{x:e.left+e.width/2,y:e.bottom,width:e.width,height:e.height}},ya=t=>lb(bo,t),oA=t=>String(t||"").split(/\r?\n/).slice(1,-1).map(e=>{let n=e.match(/^\s*([^:#][^:]*):\s*(.*)$/);return n?{key:n[1].trim(),value:n[2].trim()||" "}:null}).filter(Boolean),ka=()=>{let t=document.querySelector("#frontmatter-panel");if(!t)return;let e=oA(bo);t.dataset.visible=e.length>0?"true":"false",t.innerHTML=e.length>0?`<div class="frontmatter-title">${KI()}</div>${e.map(n=>`<div class="frontmatter-row"><span class="frontmatter-key">${Ff(n.key)}</span><span>${Ff(n.value)}</span></div>`).join("")}`:""},Ff=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),vb=t=>`${HI}://image?src=${encodeURIComponent(t)}`;var Wb=t=>{let n=(t||"").trim().match(/^(\d{1,4})(?:x(\d{1,4}))?$/i);return n?{width:Math.max(1,Number(n[1])),height:n[2]?Math.max(1,Number(n[2])):null}:null},sA=(t,e)=>{t.style.width=e?`${e.width}px`:"",t.style.maxWidth=e?"100%":"",t.style.height=e?.height?`${e.height}px`:""},jb=t=>{let e=String(t||"").split("|"),n=e.length>1?Wb(e.at(-1)):null;return{alt:n?e.slice(0,-1).join("|").trim():String(t||""),size:n}},aA=(t,e,n)=>{let r=e,i=n;for(;r<i&&/\s/.test(t[r]);)r+=1;for(;i>r&&/\s/.test(t[i-1]);)i-=1;return{start:r,end:i}},qb=t=>{let e=String(t||""),n=[],r=0,i="";for(let o=0;o<e.length;o+=1){let s=e[o],a=e[o+1];if(s==="\\"&&a==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+2,i="",o+=1;continue}if(s==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+1,i="";continue}i+=s}return n.push({raw:e.slice(r),value:i,start:r,end:e.length}),n},Kb=t=>{let e=String(t||"").trim(),n=qb(e),i=(n.shift()||{value:"",start:0,end:0}).value.trim(),o=n,s=o.map(u=>u.value).join("|").trim(),a=o.length>0?aA(e,o[0].start,o.at(-1).end):null,l=i.indexOf("#"),c=l>=0?i.slice(0,l).trim():i;return{source:e,target:i,noteTitle:c,display:s||i,alias:s,aliasRange:a}},lA=t=>{let e=qb(String(t||"").trim()),n=(e.shift()?.value||"").trim(),r=e.at(-1),i=r?Wb(r.value):null,o=i?e.slice(0,-1):e;return{target:n,size:i,label:o.map(s=>s.value).join("|").trim()}},Ib=()=>{let t=ai==="inkstone"?{background:"#151515",accent:"#a6362b",text:"#d7cbb0"}:{background:"#efe6d8",accent:"#9f3b2f",text:"#6b5148"},e=`<svg xmlns="http://www.w3.org/2000/svg" width="156" height="34" viewBox="0 0 156 34"> +`).trim(),Hb=t=>t==="glassLight"||t==="glassMist"?"xuan":t==="glassDark"||t==="glassSlate"?"stele":t==="xuan"||t==="inkstone"||t==="stele"||t==="paper"?t:"paper",GI=t=>["glassLight","glassDark","glassMist","glassSlate"].includes(t)?t:"",ai=Hb(window.weiBeiTheme),QI=()=>{switch(ai){case"inkstone":return{background:"#151515",primaryColor:"#1c1c1c",primaryTextColor:"#d7cbb0",primaryBorderColor:"#3a3328",lineColor:"#8b5e3c",secondaryColor:"#222222",tertiaryColor:"#171717",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"stele":return{background:"#1e2228",primaryColor:"#252a32",primaryTextColor:"#d2d6dc",primaryBorderColor:"#3a414c",lineColor:"#8a7a5c",secondaryColor:"#2a3038",tertiaryColor:"#1a1e24",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};case"xuan":return{background:"#f7f4ef",primaryColor:"#fcfbf8",primaryTextColor:"#25231f",primaryBorderColor:"#d8d2c6",lineColor:"#6e634f",secondaryColor:"#ebe6dc",tertiaryColor:"#f7f4ef",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'};default:return{background:"#fbf5e8",primaryColor:"#f6eddc",primaryTextColor:"#2e261f",primaryBorderColor:"#cbb79b",lineColor:"#7a6250",secondaryColor:"#efe4d2",tertiaryColor:"#f8f0e1",fontFamily:'-apple-system, BlinkMacSystemFont, "Songti SC", serif'}}},YI=t=>{t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:QI()})},Vb=t=>{ai=Hb(t);let e=GI(t);document.documentElement.dataset.weibeiTheme=ai,document.body&&(document.body.dataset.weibeiTheme=ai),e?(document.documentElement.dataset.weibeiGlass=e,document.body&&(document.body.dataset.weibeiGlass=e)):(delete document.documentElement.dataset.weibeiGlass,document.body&&delete document.body.dataset.weibeiGlass),si+=1};Vb(window.weiBeiTheme);var lr=t=>{if(window.WeiBeiEditorBootFailed){window.WeiBeiEditorBootFailed(t);return}let e=document.querySelector("#editor");e&&(e.innerHTML=`<pre style="white-space:pre-wrap;color:#9f3427;padding:24px;font:13px/1.5 SFMono-Regular,Menlo,monospace;">${Dt("bootFailed")} +${String(t?.stack||t)}</pre>`)};window.addEventListener("error",t=>lr(t.error||t.message));window.addEventListener("unhandledrejection",t=>lr(t.reason));var ct=(t,e={})=>{let n=zI?.[t];if(!n)return;let r=pb({documentID:pa,documentGeneration:cr,revision:$I.revision},e);typeof r.markdown=="string"&&(_I+=1),xt(St,"bridgeMessages"),St&&xt(St,"bridgeBytes",new TextEncoder().encode(JSON.stringify(r)).byteLength),n.postMessage(r)};var en=null;var XI=()=>document.documentElement.dataset.weibeiReduceMotion==="true",ZI=t=>{document.documentElement.dataset.weibeiReduceMotion=t===!0||t==="true"?"true":"false"},eA=t=>{let e=Number(t),n=Number.isFinite(e)&&e>0?e:1;document.documentElement.style.setProperty("--weibei-text-scale",String(n))};document.documentElement.dataset.weibeiCompactPreview=ma?"true":"false";window.weiBeiEditorCheckMode&&(document.documentElement.dataset.weibeiCheckMode="true");var Eb=0,Rf=0,Tb=0,vb=0,Wb=()=>[document.querySelector("#editor"),document.querySelector(".milkdown"),document.querySelector(".ProseMirror")].filter(Boolean),tA=t=>{let e=t.getBoundingClientRect?.();return Math.max(0,t.scrollHeight||0,t.offsetHeight||0,t.clientHeight||0,e?.height||0)},Ff=()=>{let t=Wb(),e=Math.ceil(Math.max(1,...t.map(tA))),n=Math.ceil(Math.max(1,...t.map(r=>r.getBoundingClientRect?.().width||r.clientWidth||0)));window.WeiBeiCompactPreviewHeight=e,window.WeiBeiCompactPreviewMeasuredAt=Date.now(),!(Math.abs(e-Tb)<1&&Math.abs(n-vb)<1)&&(Tb=e,vb=n,ct("contentHeightChanged",{height:e}))},nA=()=>{!ma||!Fb||(Ff(),window.cancelAnimationFrame(Eb),Eb=window.requestAnimationFrame(Ff))},Ct=()=>{if(!ma||Rf)return;let t=Ye!==null?100:40;Rf=window.setTimeout(()=>{Rf=0,nA()},t)},rA=()=>{if(ma){if(window.ResizeObserver){let t=new ResizeObserver(Ct);Wb().forEach(e=>t.observe(e))}Ct(),document.fonts?.ready?.then(Ct).catch(()=>{})}},iA=()=>{let t=window.getSelection();if(!t||t.rangeCount===0)return null;let e=t.getRangeAt(0).getBoundingClientRect();return!e||e.width+e.height===0?null:{x:e.left+e.width/2,y:e.bottom,width:e.width,height:e.height}},ya=t=>ub(bo,t),oA=t=>String(t||"").split(/\r?\n/).slice(1,-1).map(e=>{let n=e.match(/^\s*([^:#][^:]*):\s*(.*)$/);return n?{key:n[1].trim(),value:n[2].trim()||" "}:null}).filter(Boolean),ka=()=>{let t=document.querySelector("#frontmatter-panel");if(!t)return;let e=oA(bo);t.dataset.visible=e.length>0?"true":"false",t.innerHTML=e.length>0?`<div class="frontmatter-title">${KI()}</div>${e.map(n=>`<div class="frontmatter-row"><span class="frontmatter-key">${zf(n.key)}</span><span>${zf(n.value)}</span></div>`).join("")}`:""},zf=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Ib=t=>`${HI}://image?src=${encodeURIComponent(t)}`;var jb=t=>{let n=(t||"").trim().match(/^(\d{1,4})(?:x(\d{1,4}))?$/i);return n?{width:Math.max(1,Number(n[1])),height:n[2]?Math.max(1,Number(n[2])):null}:null},sA=(t,e)=>{t.style.width=e?`${e.width}px`:"",t.style.maxWidth=e?"100%":"",t.style.height=e?.height?`${e.height}px`:""},qb=t=>{let e=String(t||"").split("|"),n=e.length>1?jb(e.at(-1)):null;return{alt:n?e.slice(0,-1).join("|").trim():String(t||""),size:n}},aA=(t,e,n)=>{let r=e,i=n;for(;r<i&&/\s/.test(t[r]);)r+=1;for(;i>r&&/\s/.test(t[i-1]);)i-=1;return{start:r,end:i}},Kb=t=>{let e=String(t||""),n=[],r=0,i="";for(let o=0;o<e.length;o+=1){let s=e[o],a=e[o+1];if(s==="\\"&&a==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+2,i="",o+=1;continue}if(s==="|"){n.push({raw:e.slice(r,o),value:i,start:r,end:o}),r=o+1,i="";continue}i+=s}return n.push({raw:e.slice(r),value:i,start:r,end:e.length}),n},Ub=t=>{let e=String(t||"").trim(),n=Kb(e),i=(n.shift()||{value:"",start:0,end:0}).value.trim(),o=n,s=o.map(u=>u.value).join("|").trim(),a=o.length>0?aA(e,o[0].start,o.at(-1).end):null,l=i.indexOf("#"),c=l>=0?i.slice(0,l).trim():i;return{source:e,target:i,noteTitle:c,display:s||i,alias:s,aliasRange:a}},lA=t=>{let e=Kb(String(t||"").trim()),n=(e.shift()?.value||"").trim(),r=e.at(-1),i=r?jb(r.value):null,o=i?e.slice(0,-1):e;return{target:n,size:i,label:o.map(s=>s.value).join("|").trim()}},Ab=()=>{let t=ai==="inkstone"?{background:"#151515",accent:"#a6362b",text:"#d7cbb0"}:{background:"#efe6d8",accent:"#9f3b2f",text:"#6b5148"},e=`<svg xmlns="http://www.w3.org/2000/svg" width="156" height="34" viewBox="0 0 156 34"> <rect width="156" height="34" rx="3" fill="${t.background}"/> <path d="M18 22l5-6 4 4 3-3 6 5" fill="none" stroke="${t.accent}" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/> <rect x="17" y="11" width="20" height="14" rx="2" fill="none" stroke="${t.accent}" stroke-width="1.2"/> - <text x="48" y="22" fill="${t.text}" font-family="-apple-system, BlinkMacSystemFont, 'Songti SC', serif" font-size="13">${Ff(Dt("imageMissing"))}</text> -</svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`},cA=t=>{if(!t||/^(?:data:|blob:|weibeiimage:)/i.test(t))return t;if(/^https:/i.test(t))return vb(t);if(/^http:/i.test(t))return"";try{let e=new URL(t,Fb||window.location.href).href;return/^(?:file:|https:)/i.test(e)?vb(e):/^(?:data:|blob:|weibeiimage:)/i.test(e)?e:""}catch{return""}},Ub=()=>{document.body.dataset.editable=lt?"true":"false",document.querySelectorAll(".weibei-code-language-input").forEach(t=>{t instanceof HTMLInputElement&&(t.readOnly=!lt,t.tabIndex=lt?0:-1,t.setAttribute("aria-readonly",t.readOnly?"true":"false"),t.setAttribute("aria-label",Dt("codeLanguage")),t.placeholder=Dt("codeLanguagePlaceholder"))})},zf=new Set,uA=new Set,fA=t=>{let e=t,n=document.createElement("img");n.className="weibei-image";let r=()=>{let i=jb(e.attrs.alt||""),o=cA(String(e.attrs.src||""));n.alt=i.alt,n.title=String(e.attrs.title||""),sA(n,i.size),n.src=o||Ib()};return n.addEventListener("load",Ct),n.addEventListener("error",()=>{n.src=Ib()}),zf.add(r),r(),{dom:n,update(i){return i.type!==e.type?!1:(e=i,r(),!0)},destroy(){zf.delete(r)}}};var Jb=()=>zf.forEach(t=>t()),dA=()=>{if(!re)return null;let t=re.action(e=>e.get(oe).state.selection);return!t||t.empty?null:{from:t.from,to:t.to}},pA=()=>re?re.action(t=>{let{selection:e}=t.get(oe).state;if(!e||e.empty)return"";let n=e.content().content;return $b(n.textBetween(0,n.size,` -`))}):"",hA=()=>$b(window.getSelection()?.toString()||pA()),Ot=(t,e,n,r,i={})=>{n<=e||t.push(se.inline(e,n,{...i,class:r}))},mA=t=>(Array.isArray(t)?t:[]).map(e=>({id:String(e?.id||""),text:String(e?.text||"").trim()})).filter(e=>e.id&&e.text.length>=4),gA=(t,e,n,r)=>{lt||Pf.length===0||Pf.forEach(i=>{let o=0,s=r.get(i.id)||0;for(;s<3;){let a=e.indexOf(i.text,o);if(a<0)break;Ot(t,n+a,n+a+i.text.length,"weibei-selection-ask-mark",{"data-thread-id":i.id,title:"\u6253\u5F00\u5F53\u65F6\u7684\u9009\u533A\u95EE\u7B54"}),s+=1,o=a+i.text.length}r.set(i.id,s)})};var yA=(t,e,n)=>{for(let r of e.matchAll(/(?:^|[\s`])((?:来源:|Source:)[^`\n]+)/g)){let i=r[0].startsWith(r[1])?0:1,o=r[1].startsWith("\u6765\u6E90\uFF1A")?"\u6765\u6E90\uFF1A":"Source:",s=n+(r.index||0)+i,a=s+r[1].length;Ot(t,s,a,"weibei-source-reference",{role:"link",tabindex:"0",title:Dt("openSource",{value:r[1].slice(o.length).trim()}),"data-source-reference":r[1]})}},kA=(t,e,n,r)=>{let i=0;for(;i<e.length;){if(r.open){let a=e.indexOf("%%",i);if(a<0){Ot(t,n+i,n+e.length,"weibei-comment");return}Ot(t,n+i,n+a+2,"weibei-comment"),r.open=!1,i=a+2;continue}let o=e.indexOf("%%",i);if(o<0)return;let s=e.indexOf("%%",o+2);if(s<0){Ot(t,n+o,n+e.length,"weibei-comment"),r.open=!0;return}Ot(t,n+o,n+s+2,"weibei-comment"),i=s+2}},bA=(t,e,n)=>{for(let r of e.matchAll(/(^|\s)(#[\p{L}\p{N}_/-]+)\b/gu)){let i=n+(r.index||0)+r[1].length;Ot(t,i,i+r[2].length,"weibei-tag")}for(let r of e.matchAll(/(^|\s)(\^[A-Za-z0-9-]+)\s*$/g)){let i=n+(r.index||0)+r[1].length;Ot(t,i,i+r[2].length,"weibei-block-id")}},xA=(t,e,n)=>{for(let r of e.matchAll(/<br\s*\/?>/gi)){let i=n+(r.index||0),o=i+r[0].length;Ot(t,i,o,"weibei-html-break-source"),t.push(se.widget(o,()=>{let s=document.createElement("br");return s.className="weibei-html-break-preview",s},{side:1}))}},Ab=t=>{let e=document.createElement("div");e.className="weibei-mermaid-render",e.textContent=Dt("mermaidRendering");let n="\0",r=0,i=0,o=(s,a=!1)=>{let l=String(s||"");if(l===n)return;n=l;let c=i+=1;window.clearTimeout(r),r=window.setTimeout(async()=>{if(!(!e.isConnected||c!==i)){e.classList.remove("weibei-mermaid-error");try{let u=await ob();YI(u);let f=`weibei-mermaid-${VI+=1}`;xt(St,"mermaidRenders");let{svg:d,bindFunctions:p}=await u.render(f,l,e);if(!e.isConnected||c!==i)return;e.innerHTML=d,p?.(e),e.dataset.rendered="true"}catch(u){if(!e.isConnected||c!==i)return;e.classList.add("weibei-mermaid-error"),e.textContent=Dt("mermaidFailed",{value:String(u?.message||u)})}Ct()}},a?300:0)};return o(t),{element:e,updateSource:o}},fa=new WeakMap,wt=null,ho=!1,wA=t=>{if(!ho||!(t.selection instanceof z))return null;let{$from:e}=t.selection;for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(r.type.name==="code_block")return jf(r.attrs.language||"")!=="mermaid"?null:{node:r,pos:e.before(n)}}return null},SA=t=>{wt&&(wt.documentGeneration!==cr||wt.contentGeneration!==yo||wt.generation!==si||t?.pos!==wt.pos)&&(wt=null)},CA=(t,e,n)=>{let r=n?.pos===e;if(r&&!wt){let s=fa.get(t);wt=s?.generation===si?{...s,pos:e,documentGeneration:cr,contentGeneration:yo}:{...Ab(t.textContent),generation:si,key:`mermaid-preview-${wb+=1}`,pos:e,documentGeneration:cr,contentGeneration:yo}}if(r)return wt.updateSource(t.textContent,!0),wt;let i=fa.get(t);if(i?.generation===si)return i.updateSource(t.textContent),i;let o={...Ab(t.textContent),generation:si,key:`mermaid-preview-${wb+=1}`};return fa.set(t,o),o},MA=(t,e,n,r)=>{if(jf(e.attrs.language||"")!=="mermaid")return!1;t.push(se.node(n,n+e.nodeSize,{class:"weibei-code-block weibei-mermaid-block","data-language":"mermaid"}));let i=CA(e,n,r);return t.push(se.widget(n+e.nodeSize,()=>i.element,{side:-1,key:i.key})),!0},EA=t=>{let e=Kb(t);return e.target||e.noteTitle},TA=t=>{let e=t instanceof Element?t.closest(".weibei-wikilink, .weibei-embed-note[data-wikilink-title]"):null;return e?.getAttribute("data-wikilink-title")||e?.textContent?.trim()||""},$f=t=>{let e=TA(t);return e?(ct("wikiLinkActivated",{title:e}),!0):!1},vA=t=>(t instanceof Element?t.closest(".weibei-source-reference[data-source-reference]"):null)?.getAttribute("data-source-reference")||"",_f=t=>{let e=vA(t);return e?(ct("sourceReferenceActivated",{reference:e}),!0):!1},Gb=t=>{let e=t instanceof Element?t.closest(".weibei-selection-ask-mark[data-thread-id]"):null,n=e?.getAttribute("data-thread-id")||"";return n?(ct("selectionAskMark",{threadId:n,text:e.textContent||""}),!0):!1},Qb=t=>{if(lt||!(t instanceof Element))return!1;let e=t.closest('blockquote.weibei-callout[data-callout-fold="-"]');return e?(e.classList.toggle("weibei-callout-open"),!0):!1},jf=t=>{let e=(t||"").trim().toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",sh:"bash",shell:"bash",zsh:"bash",md:"markdown",yml:"yaml"}[e]||e},Yb=t=>typeof t=="string"?t.length:Array.isArray(t.content)?t.content.reduce((e,n)=>e+Yb(n),0):String(t.content||"").length,IA=t=>{let e=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return["weibei-prism-token","token",t.type,...e].filter(Boolean).join(" ")},Nb=new WeakMap,AA=new Set(["bash","css","do","java","javascript","json","jsx","markdown","python","r","ruby","rust","sql","stata","swift","tsx","typescript","yaml"]),go=null,Rb=!1,NA=()=>{go||Rb||(Rb=!0,sb().then(t=>{go=t,li+=1,re?.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiPrismReady",!0))})}).catch(lr))},Xb=(t,e,n)=>{let r=n;for(let i of e){let o=Yb(i);typeof i!="string"&&o>0&&(t.push({from:r,to:r+o,className:IA(i)}),Array.isArray(i.content)&&Xb(t,i.content,r)),r+=o}},RA=(t,e,n)=>{let r=jf(e.attrs.language||"");if(!AA.has(r))return;if(!go){NA();return}let i=Nb.get(e);try{i||(xt(St,"codeTokenizations"),i=[],Xb(i,go.tokenize(e.textContent,go.languages[r]),0),Nb.set(e,i)),i.forEach(o=>Ot(t,n+1+o.from,n+1+o.to,o.className))}catch{}},Ob=t=>{let e=t,n=e.type.name==="math_block",r=document.createElement(n?"div":"span");r.className=`weibei-math-node ${n?"weibei-math-block":"weibei-math-inline"}`,r.dataset.type=e.type.name;let i=0,o=()=>n?String(e.attrs.value||""):e.textContent,s=async()=>{let a=i+=1,l=o();r.dataset.value=l,r.textContent=l||"\u516C\u5F0F";let c=(u,f=!1)=>{a!==i||f&&!r.isConnected||(xt(St,"katexRenders"),u.render(l,r,{throwOnError:!0,strict:!1,trust:!1,displayMode:n}))};try{let u=ib();u?c(u):c(await rb(),!0)}catch{a===i&&(r.textContent=l||"\u516C\u5F0F")}Ct()};return s(),{dom:r,update(a){return a.type!==e.type?!1:(e=a,s(),!0)},ignoreMutation(){return!0}}};var OA=()=>re?re.action(t=>{let e=t.get(oe),n=e.state.selection.from,r="";return e.state.doc.descendants((i,o)=>{if(!i.isText||r)return!0;let s=i.text||"",a=o,l=o+s.length;if(n<a||n>l)return!0;for(let c of s.matchAll(/\[\[([^\]\n]+)\]\]/g)){let u=a+(c.index||0),f=u+c[0].length;if(n>=u&&n<=f)return r=EA(c[1]),!1}return!0}),r}):"";var DA="#editor, .ProseMirror pre, .weibei-math-block",Of=new WeakMap,BA=t=>{if(!(t instanceof Element))return;t.classList.add("weibei-scroll-active");let e=Of.get(t);e&&window.clearTimeout(e),Of.set(t,window.setTimeout(()=>{t.classList.remove("weibei-scroll-active"),Of.delete(t)},850))},LA=()=>{document.addEventListener("scroll",t=>{let e=t.target instanceof Element?t.target.closest(DA):null;e&&BA(e)},!0)};var PA=(t,e)=>{if(!lt||e.key!=="Tab"||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof z)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(" "));return t.dispatch(r.setSelection(z.create(r.doc,n.from+1)).scrollIntoView()),!0},FA=new Set(["-","'",'"']),zA=(t,e)=>{if(!lt||!FA.has(e.key)||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof z)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(e.key));return t.dispatch(r.setSelection(z.create(r.doc,n.from+e.key.length)).scrollIntoView()),!0},$A=(t,e)=>{if(!lt||e.inputType!=="insertReplacementText"||e.isComposing||!e.cancelable)return!1;let{selection:n}=t.state;return!(n instanceof z)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0?!1:(e.preventDefault(),e.stopImmediatePropagation(),!0)};var _A=(t,e)=>{if(!lt||!Ie(t.state))return!1;if(e==="addRow")return Sy(t.state,t.dispatch);if(e==="deleteRow")return Us(t.state,t.dispatch);if(e==="addColumn")return qs(t.state,t.dispatch);if(e==="deleteColumn")return Ks(t.state,t.dispatch);if(e==="header"){let{$from:n}=t.state.selection;for(let r=n.depth;r>0;r-=1){if(n.node(r).type.name!=="table")continue;let i=Math.min(n.before(r)+4,t.state.doc.content.size);return t.dispatch(t.state.tr.setSelection($.near(t.state.doc.resolve(i),1)).scrollIntoView()),!0}}return!1},Df=t=>{t?(en.dataset.state="open",en.setAttribute("aria-hidden","false")):en.dataset.state!=="closed"&&(en.dataset.state="closed",en.setAttribute("aria-hidden","true"))},HA=t=>{if(en.querySelectorAll("button").forEach(i=>{let o=Dt(i.dataset.label);i.textContent=o,i.setAttribute("aria-label",o)}),!lt||!Ie(t.state)){Df(!1);return}let e=t.domAtPos(t.state.selection.from).node,n=(e instanceof Element?e:e.parentElement)?.closest("td, th");if(!(n instanceof HTMLElement)){Df(!1);return}let r=n.getBoundingClientRect();en.style.left=`${Math.max(8,Math.min(window.innerWidth-en.offsetWidth-8,r.left))}px`,en.style.top=`${Math.max(8,r.top-32)}px`,Df(!0)},Db={doc:null,focusedMermaidPos:null,generation:-1,decorations:ne.empty},Bb=(t,e,n)=>{let r=!1,i=Math.max(0,Math.min(t.content.size,e-1)),o=Math.max(i,Math.min(t.content.size,Math.max(n,e+1)+1));return t.nodesBetween(i,o,s=>(s.type.name==="heading"&&(r=!0),!r)),r},VA=t=>t.steps.some((e,n)=>{let r=t.docs[n],i=t.docs[n+1]||t.doc,o=!1;return e.getMap().forEach((s,a,l,c)=>{(Bb(r,s,a)||Bb(i,l,c))&&(o=!0)}),o}),WA=Se(()=>new X({state:{init:()=>null,apply:(t,e,n,r)=>(xt(St,"transactions"),t.docChanged&&VA(t)&&Jf(r.doc),e)},view(t){let e={autocapitalize:"none",autocorrect:"off",spellcheck:"false"},n=new Map(Object.keys(e).map(h=>[h,t.dom.getAttribute(h)])),r=h=>{if(h.state.selection.$from.parent.type.spec.code===!0){for(let[m,g]of Object.entries(e))h.dom.setAttribute(m,g);return}for(let[m,g]of n)g===null?h.dom.removeAttribute(m):h.dom.setAttribute(m,g)},i=h=>{let m=h.state.doc;h.dom.classList.toggle("weibei-empty-document",m.childCount===1&&m.firstChild?.type.name==="paragraph"&&m.firstChild.content.size===0),h.dom.dataset.emptyPlaceholder=Dt("emptyNotePlaceholder")},o=h=>{ho!==h&&(ho=h,t.dispatch(t.state.tr.setMeta("weibeiMermaidFocusChanged",h)))},s=h=>o(h.target===t.dom),a=h=>{h.target===t.dom&&o(!1)},l=()=>{Wf=ha,da=!1;let{$from:h}=t.state.selection;mo=h.parent.isTextblock&&h.parent.content.size===0?h.before(h.depth):null},c=()=>{da=!0,setTimeout(qA)},u=h=>{h.target!==t.dom||!t.hasFocus()||!PA(t,h)&&!zA(t,h)||(h.preventDefault(),h.stopImmediatePropagation())},f=h=>{h.target===t.dom&&$A(t,h)},d=h=>h.preventDefault(),p=h=>{let m=h.target instanceof Element?h.target.closest("button[data-action]"):null;m instanceof HTMLElement&&(_A(t,m.dataset.action||""),t.focus(),window.requestAnimationFrame(()=>HA(t)))};return t.dom.addEventListener("focus",s,!0),t.dom.addEventListener("blur",a,!0),ho=t.hasFocus(),{update(h,m){h.state.doc.eq(m.doc)||(Ct(),ci())},destroy(){t.dom.removeEventListener("focus",s,!0),t.dom.removeEventListener("blur",a,!0),ho=!1,wt=null,fa=new WeakMap}}},props:{handlePaste:()=>!1,handleDrop:()=>!1,handleTextInput:()=>!1,handleClick(t,e,n){return Gb(n.target)||$f(n.target)||_f(n.target)||Qb(n.target)},handleKeyDown(t,e){if(e.key!=="Enter"&&e.key!==" ")return!1;if(_f(e.target))return e.preventDefault(),!0;if(!e.metaKey&&!e.ctrlKey)return!1;let n=OA();return n?(ct("wikiLinkActivated",{title:n}),e.preventDefault(),!0):!1},decorations(t){let e=wA(t);SA(e);let n=e?.pos??null,r=Db;if(r.doc===t.doc&&r.focusedMermaidPos===n&&r.generation===li)return xt(St,"decorationCacheHits"),r.decorations;let i=[],o={open:!1},s=new Map;t.doc.descendants((l,c,u)=>{if(xt(St,"decorationNodes"),l.type.name==="code_block")return MA(i,l,c,e)||(i.push(se.node(c,c+l.nodeSize,{class:"weibei-code-block","data-language":l.attrs.language||""})),RA(i,l,c)),!1;if(l.isText){let d=c,p=l.text||"";if((l.marks||[]).some(m=>m.type.name.toLowerCase().includes("code"))||Ye!==null)return!0;xA(i,p,d),kA(i,p,d,o),yA(i,p,d),bA(i,p,d),gA(i,p,d,s)}return!0});let a=ne.create(t.doc,i);return Db={doc:t.doc,focusedMermaidPos:n,generation:li,decorations:a},a}}})),Bf=()=>{if(window.weiBeiSuppressSelectionReport)return;let t=hA(),e=t?iA():null,n=t&&re?re.action(o=>{let{state:s}=o.get(oe),{selection:a}=s,c=["strong","emphasis","highlight","link","inlineCode"].filter(y=>s.schema.marks[y]&&s.doc.rangeHasMark(a.from,a.to,s.schema.marks[y])),u=s.schema.marks.writing_font,f,d=!1;u&&s.doc.nodesBetween(a.from,a.to,y=>{if(!y.isText)return!0;let x=u.isInSet(y.marks||[])?.attrs.font||"serif";return f===void 0?f=x:f!==x&&(d=!0),!0}),f&&!d&&c.push(`font:${f}`);let p=a instanceof H&&a.node.type.name==="math_inline";p&&c.push("inlineMath");let h=a.$from.parent.type.name;for(let y=a.$from.depth;y>0;y-=1){let x=a.$from.node(y).type.name;if(x==="blockquote"||x==="block_quote"){h="blockquote";break}}h==="heading"&&(h=`heading${a.$from.parent.attrs.level||""}`);let m="",g=s.schema.marks.link;return g&&s.doc.nodesBetween(a.from,a.to,y=>{let x=g.isInSet(y.marks||[]);return x&&!m&&(m=String(x.attrs.href||"")),!m}),{activeMarks:c,blockType:h,canConvertToMath:p||a instanceof z&&!a.empty&&a.$from.parent===a.$to.parent&&a.$from.parent.isTextblock,linkTarget:m}}):{activeMarks:[],blockType:"",canConvertToMath:!1,linkTarget:""},r=e?`${Math.round(e.x)}:${Math.round(e.y)}:${Math.round(e.width)}:${Math.round(e.height)}`:"",i=JSON.stringify(n);if(!(t===oi.text&&r===oi.rectKey&&i===oi.detailKey)){if(oi={text:t,rectKey:r,detailKey:i},!t){Lf=null,ct("selectionChanged",{text:"",rect:null,...n});return}Lf=dA(),ct("selectionChanged",{text:t,rect:e,...n})}};var qf=()=>{if(!re)throw new Error("WeiBei editor is not ready")},Zb=t=>{Pf=mA(t),li+=1,re&&re.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiSelectionAskMarksChanged",!0))})},jA=()=>{if(!re||mo===null)return;let t=mo;mo=null,re.action(e=>{let n=e.get(oe);n.domObserver?.flush();let r=n.state.doc.nodeAt(t);if(!r?.isTextblock||!r.textContent)return;let i=n.state.schema.nodes.hardbreak||n.state.schema.nodes.hard_break,o=[];for(let a=0;a<r.childCount;a+=1){let l=r.child(a);l.type!==i&&o.push(l)}if(o.length!==r.childCount){let a=r.type.create(r.attrs,E.fromArray(o),r.marks),l=n.state.tr.replaceWith(t,t+r.nodeSize,a).scrollIntoView();l.setSelection(z.create(l.doc,Math.min(t+1+a.content.size,l.doc.content.size))),n.dispatch(l)}let s=n.nodeDOM(t);s instanceof HTMLElement&&(s.querySelectorAll("br").forEach(a=>a.remove()),n.domObserver?.flush())})},qA=()=>{re&&(jA(),da=!1,Wf=null,Ct(),ci())},Kf=()=>re.action(t=>t.get(G)),KA=(t=!0)=>{Ye!==null&&(Kf().call(oa.key,{keep:t}),Ye=null,Zt=null,ga=null)},Uf=t=>{qf();let e=String(t||"");ga=e;let n=la(e);bo=n.frontmatter,ka();let r=n.body,i=Zt!==null&&Ye===Zt&&r.startsWith(Zt)?r.slice(Zt.length):null,o;i!==null&&!/[$<>\\`\r]/.test(i)?(o=r,Zt=r):(o=aa(r,"agentGenerated"),Zt=o===r?r:null,ha=ya(o));let s=Kf();Ye===null?(s.call(uo.key),Ye=""):o.startsWith(Ye)||(s.call(fo.key,{diffReview:!1}),s.call(uo.key),Ye="");let a=o.slice(Ye.length);a&&s.call(ia.key,a),Ye=o,Ct()},UA=t=>{let e=String(t||"");if(!e)return;let n=ga;Uf(n===null?e:n+e)},JA=t=>{Zt=null,Uf(t),Kf().call(fo.key,{diffReview:!1}),Zt=null,Ye=null;try{re?.action(e=>{e.get(oe).updateState(e.get(oe).state)})}catch{}Ct()},GA=t=>{qf(),KA(),ga=null,Wf=null,mo=null,da=!1,yo+=1;let e=la(t||""),n=aa(e.body,"userDocument");bo=e.frontmatter,ka(),re.action(Eg(n)),ha=ya(n),re.action(r=>Jf(r.get(oe).state.doc)),Ct()};var QA=()=>(qf(),xt(St,"fullSerializations"),ya(re.action(Mg())));var ex=()=>Array.from(document.querySelectorAll(".ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6")),Lb=0,ca=-2,Hf=null,Jf=t=>{let e=[],n=Math.max(1,t.content.size);t.descendants((i,o)=>{if(i.type.name!=="heading")return!0;let s=i.textContent.trim();if(!s)return!1;let a=e.length;return e.push({id:`note-heading-${a}`,index:a,level:Number(i.attrs.level||1),title:s,position:Math.max(0,Math.min(1,o/n))}),!1});let r=ub(e);r!==Hf&&(Hf=r,xt(St,"outlineReports"),ct("outlineChanged",{items:e}))},ci=()=>{window.cancelAnimationFrame(Lb),Lb=window.requestAnimationFrame(()=>{let t=ex();if(t.length===0){ca!==-1&&(ca=-1,ct("activeHeadingChanged",{index:null}));return}let e=Math.max(0,window.innerHeight*.32),n=0;t.forEach((r,i)=>{r.getBoundingClientRect().top<=e&&(n=i)}),n!==ca&&(ca=n,ct("activeHeadingChanged",{index:n}))})},YA=t=>{let e=Number(t),n=ex(),r=Number.isFinite(e)?n[Math.max(0,Math.floor(e))]:null;if(!r)return!1;let i=XI();return r.scrollIntoView({block:"start",behavior:i?"auto":"smooth"}),i?ci():window.setTimeout(ci,180),!0},XA=(t,e)=>{let n=t!==pa||e!==cr;pa=t,cr=e,n&&(Hf=null,yo+=1,jI.clear(),WI.clear(),Zb([]))};var ZA=t=>{Hb(t),li+=1,Jb(),re&&re.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",ai))})},eN=t=>{ua=zb(t),li+=1,document.documentElement.dataset.weibeiLanguage=ua,ka(),Ub(),uA.forEach(e=>e()),re&&re.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiLanguageChanged",ua))})},tN=()=>re?(re.action(t=>t.get(oe).focus()),!0):!1;window.WeiBeiEditor={getMarkdown:QA,setMarkdown:t=>GA(String(t||"")),updateStreamingMarkdown:t=>{try{Uf(t)}catch(e){lr(e)}},appendStreamingMarkdown:t=>{try{UA(t)}catch(e){lr(e)}},finishStreamingMarkdown:t=>{try{return JA(t),!0}catch(e){return lr(e),!1}},setDocumentID:t=>{let e=t||"";e!==pa&&XA(e,cr+1)},setTheme:ZA,setInterfaceLanguage:eN,setReduceMotion:ZI,setTextScale:eA,focus:tN,scrollToHeading:YA,setSelectionAskMarks:Zb,setMarkdownBaseURL:t=>{Fb=t||"",Jb()}};var ko=la(window.initialMarkdown||"");ko.body=aa(ko.body,"userDocument");bo=ko.frontmatter;ha=ya(ko.body);ka();var Vf=xg.make().config(t=>{t.set(Yi,document.querySelector("#editor")),t.set(Ui,ko.body),t.set(Qi,{editable:()=>lt,nodeViews:{image:fA,math_inline:Ob,math_block:Ob}}),t.set(wn.key,{throttleMs:0,scrollFollow:!1,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}})});Vf=Vf.use(WA).use(Zg).use(wk).use(xb).use(qI).use(Uk).use(Se(()=>Gk(()=>Ye!==null)));Vf.use(bf).config(t=>{t.get(ta).selectionUpdated(()=>{requestAnimationFrame(Bf)})}).create().then(t=>{re=t,Ub(),LA(),document.querySelector("#editor-status")?.remove(),document.addEventListener("mouseup",Bf),document.addEventListener("pointerdown",()=>{window.weiBeiSuppressSelectionReport||(Lf=null,oi.text="",oi.rectKey="",ct("selectionChanged",{text:"",rect:null}))},!0),document.addEventListener("click",e=>{lt&&e.target instanceof Element&&e.target.closest(".weibei-structured-node")||!Gb(e.target)&&!$f(e.target)&&!_f(e.target)&&!Qb(e.target)||(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keydown",e=>{e.key!=="Enter"&&e.key!==" "||$f(e.target)&&(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keyup",e=>{Bf()}),document.addEventListener("scroll",ci,!0),ct("editorReady",{}),window.setTimeout(()=>{Pb=!0,rA(),re.action(e=>Jf(e.get(oe).state.doc)),ci()})}).catch(lr);})(); + <text x="48" y="22" fill="${t.text}" font-family="-apple-system, BlinkMacSystemFont, 'Songti SC', serif" font-size="13">${zf(Dt("imageMissing"))}</text> +</svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`},cA=t=>{if(!t||/^(?:data:|blob:|weibeiimage:)/i.test(t))return t;if(/^https:/i.test(t))return Ib(t);if(/^http:/i.test(t))return"";try{let e=new URL(t,zb||window.location.href).href;return/^(?:file:|https:)/i.test(e)?Ib(e):/^(?:data:|blob:|weibeiimage:)/i.test(e)?e:""}catch{return""}},Jb=()=>{document.body.dataset.editable=lt?"true":"false",document.querySelectorAll(".weibei-code-language-input").forEach(t=>{t instanceof HTMLInputElement&&(t.readOnly=!lt,t.tabIndex=lt?0:-1,t.setAttribute("aria-readonly",t.readOnly?"true":"false"),t.setAttribute("aria-label",Dt("codeLanguage")),t.placeholder=Dt("codeLanguagePlaceholder"))})},$f=new Set,uA=new Set,fA=t=>{let e=t,n=document.createElement("img");n.className="weibei-image";let r=()=>{let i=qb(e.attrs.alt||""),o=cA(String(e.attrs.src||""));n.alt=i.alt,n.title=String(e.attrs.title||""),sA(n,i.size),n.src=o||Ab()};return n.addEventListener("load",Ct),n.addEventListener("error",()=>{n.src=Ab()}),$f.add(r),r(),{dom:n,update(i){return i.type!==e.type?!1:(e=i,r(),!0)},destroy(){$f.delete(r)}}};var Gb=()=>$f.forEach(t=>t()),dA=()=>{if(!re)return null;let t=re.action(e=>e.get(se).state.selection);return!t||t.empty?null:{from:t.from,to:t.to}},pA=()=>re?re.action(t=>{let{selection:e}=t.get(se).state;if(!e||e.empty)return"";let n=e.content().content;return _b(n.textBetween(0,n.size,` +`))}):"",hA=()=>_b(window.getSelection()?.toString()||pA()),Ot=(t,e,n,r,i={})=>{n<=e||t.push(oe.inline(e,n,{...i,class:r}))},mA=t=>(Array.isArray(t)?t:[]).map(e=>({id:String(e?.id||""),text:String(e?.text||"").trim()})).filter(e=>e.id&&e.text.length>=4),gA=(t,e,n,r)=>{lt||Pf.length===0||Pf.forEach(i=>{let o=0,s=r.get(i.id)||0;for(;s<3;){let a=e.indexOf(i.text,o);if(a<0)break;Ot(t,n+a,n+a+i.text.length,"weibei-selection-ask-mark",{"data-thread-id":i.id,title:"\u6253\u5F00\u5F53\u65F6\u7684\u9009\u533A\u95EE\u7B54"}),s+=1,o=a+i.text.length}r.set(i.id,s)})};var yA=(t,e,n)=>{for(let r of e.matchAll(/(?:^|[\s`])((?:来源:|Source:)[^`\n]+)/g)){let i=r[0].startsWith(r[1])?0:1,o=r[1].startsWith("\u6765\u6E90\uFF1A")?"\u6765\u6E90\uFF1A":"Source:",s=n+(r.index||0)+i,a=s+r[1].length;Ot(t,s,a,"weibei-source-reference",{role:"link",tabindex:"0",title:Dt("openSource",{value:r[1].slice(o.length).trim()}),"data-source-reference":r[1]})}},kA=(t,e,n,r)=>{let i=0;for(;i<e.length;){if(r.open){let a=e.indexOf("%%",i);if(a<0){Ot(t,n+i,n+e.length,"weibei-comment");return}Ot(t,n+i,n+a+2,"weibei-comment"),r.open=!1,i=a+2;continue}let o=e.indexOf("%%",i);if(o<0)return;let s=e.indexOf("%%",o+2);if(s<0){Ot(t,n+o,n+e.length,"weibei-comment"),r.open=!0;return}Ot(t,n+o,n+s+2,"weibei-comment"),i=s+2}},bA=(t,e,n)=>{for(let r of e.matchAll(/(^|\s)(#[\p{L}\p{N}_/-]+)\b/gu)){let i=n+(r.index||0)+r[1].length;Ot(t,i,i+r[2].length,"weibei-tag")}for(let r of e.matchAll(/(^|\s)(\^[A-Za-z0-9-]+)\s*$/g)){let i=n+(r.index||0)+r[1].length;Ot(t,i,i+r[2].length,"weibei-block-id")}},xA=(t,e,n)=>{for(let r of e.matchAll(/<br\s*\/?>/gi)){let i=n+(r.index||0),o=i+r[0].length;Ot(t,i,o,"weibei-html-break-source"),t.push(oe.widget(o,()=>{let s=document.createElement("br");return s.className="weibei-html-break-preview",s},{side:1}))}},Nb=t=>{let e=document.createElement("div");e.className="weibei-mermaid-render",e.textContent=Dt("mermaidRendering");let n="\0",r=0,i=0,o=(s,a=!1)=>{let l=String(s||"");if(l===n)return;n=l;let c=i+=1;window.clearTimeout(r),r=window.setTimeout(async()=>{if(!(!e.isConnected||c!==i)){e.classList.remove("weibei-mermaid-error");try{let u=await ab();YI(u);let f=`weibei-mermaid-${VI+=1}`;xt(St,"mermaidRenders");let{svg:d,bindFunctions:p}=await u.render(f,l,e);if(!e.isConnected||c!==i)return;e.innerHTML=d,p?.(e),e.dataset.rendered="true"}catch(u){if(!e.isConnected||c!==i)return;e.classList.add("weibei-mermaid-error"),e.textContent=Dt("mermaidFailed",{value:String(u?.message||u)})}Ct()}},a?300:0)};return o(t),{element:e,updateSource:o}},fa=new WeakMap,wt=null,ho=!1,wA=t=>{if(!ho||!(t.selection instanceof z))return null;let{$from:e}=t.selection;for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(r.type.name==="code_block")return qf(r.attrs.language||"")!=="mermaid"?null:{node:r,pos:e.before(n)}}return null},SA=t=>{wt&&(wt.documentGeneration!==cr||wt.contentGeneration!==yo||wt.generation!==si||t?.pos!==wt.pos)&&(wt=null)},CA=(t,e,n)=>{let r=n?.pos===e;if(r&&!wt){let s=fa.get(t);wt=s?.generation===si?{...s,pos:e,documentGeneration:cr,contentGeneration:yo}:{...Nb(t.textContent),generation:si,key:`mermaid-preview-${Cb+=1}`,pos:e,documentGeneration:cr,contentGeneration:yo}}if(r)return wt.updateSource(t.textContent,!0),wt;let i=fa.get(t);if(i?.generation===si)return i.updateSource(t.textContent),i;let o={...Nb(t.textContent),generation:si,key:`mermaid-preview-${Cb+=1}`};return fa.set(t,o),o},MA=(t,e,n,r)=>{if(qf(e.attrs.language||"")!=="mermaid")return!1;t.push(oe.node(n,n+e.nodeSize,{class:"weibei-code-block weibei-mermaid-block","data-language":"mermaid"}));let i=CA(e,n,r);return t.push(oe.widget(n+e.nodeSize,()=>i.element,{side:-1,key:i.key})),!0},EA=t=>{let e=Ub(t);return e.target||e.noteTitle},TA=t=>{let e=t instanceof Element?t.closest(".weibei-wikilink, .weibei-embed-note[data-wikilink-title]"):null;return e?.getAttribute("data-wikilink-title")||e?.textContent?.trim()||""},_f=t=>{let e=TA(t);return e?(ct("wikiLinkActivated",{title:e}),!0):!1},vA=t=>(t instanceof Element?t.closest(".weibei-source-reference[data-source-reference]"):null)?.getAttribute("data-source-reference")||"",Hf=t=>{let e=vA(t);return e?(ct("sourceReferenceActivated",{reference:e}),!0):!1},Qb=t=>{let e=t instanceof Element?t.closest(".weibei-selection-ask-mark[data-thread-id]"):null,n=e?.getAttribute("data-thread-id")||"";return n?(ct("selectionAskMark",{threadId:n,text:e.textContent||""}),!0):!1},Yb=t=>{if(lt||!(t instanceof Element))return!1;let e=t.closest('blockquote.weibei-callout[data-callout-fold="-"]');return e?(e.classList.toggle("weibei-callout-open"),!0):!1},qf=t=>{let e=(t||"").trim().toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",sh:"bash",shell:"bash",zsh:"bash",md:"markdown",yml:"yaml"}[e]||e},Xb=t=>typeof t=="string"?t.length:Array.isArray(t.content)?t.content.reduce((e,n)=>e+Xb(n),0):String(t.content||"").length,IA=t=>{let e=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return["weibei-prism-token","token",t.type,...e].filter(Boolean).join(" ")},Rb=new WeakMap,AA=new Set(["bash","css","do","java","javascript","json","jsx","markdown","python","r","ruby","rust","sql","stata","swift","tsx","typescript","yaml"]),go=null,Ob=!1,NA=()=>{go||Ob||(Ob=!0,lb().then(t=>{go=t,li+=1,re?.action(e=>{let n=e.get(se);n.dispatch(n.state.tr.setMeta("weibeiPrismReady",!0))})}).catch(lr))},Zb=(t,e,n)=>{let r=n;for(let i of e){let o=Xb(i);typeof i!="string"&&o>0&&(t.push({from:r,to:r+o,className:IA(i)}),Array.isArray(i.content)&&Zb(t,i.content,r)),r+=o}},RA=(t,e,n)=>{let r=qf(e.attrs.language||"");if(!AA.has(r))return;if(!go){NA();return}let i=Rb.get(e);try{i||(xt(St,"codeTokenizations"),i=[],Zb(i,go.tokenize(e.textContent,go.languages[r]),0),Rb.set(e,i)),i.forEach(o=>Ot(t,n+1+o.from,n+1+o.to,o.className))}catch{}},Db=t=>{let e=t,n=e.type.name==="math_block",r=document.createElement(n?"div":"span");r.className=`weibei-math-node ${n?"weibei-math-block":"weibei-math-inline"}`,r.dataset.type=e.type.name;let i=0,o=()=>n?String(e.attrs.value||""):e.textContent,s=async()=>{let a=i+=1,l=o();r.dataset.value=l,r.textContent=l||"\u516C\u5F0F";let c=(u,f=!1)=>{a!==i||f&&!r.isConnected||(xt(St,"katexRenders"),u.render(l,r,{throwOnError:!0,strict:!1,trust:!1,displayMode:n}))};try{let u=sb();u?c(u):c(await ob(),!0)}catch{a===i&&(r.textContent=l||"\u516C\u5F0F")}Ct()};return s(),{dom:r,update(a){return a.type!==e.type?!1:(e=a,s(),!0)},ignoreMutation(){return!0}}};var OA=()=>re?re.action(t=>{let e=t.get(se),n=e.state.selection.from,r="";return e.state.doc.descendants((i,o)=>{if(!i.isText||r)return!0;let s=i.text||"",a=o,l=o+s.length;if(n<a||n>l)return!0;for(let c of s.matchAll(/\[\[([^\]\n]+)\]\]/g)){let u=a+(c.index||0),f=u+c[0].length;if(n>=u&&n<=f)return r=EA(c[1]),!1}return!0}),r}):"";var DA="#editor, .ProseMirror pre, .weibei-math-block",Of=new WeakMap,BA=t=>{if(!(t instanceof Element))return;t.classList.add("weibei-scroll-active");let e=Of.get(t);e&&window.clearTimeout(e),Of.set(t,window.setTimeout(()=>{t.classList.remove("weibei-scroll-active"),Of.delete(t)},850))},LA=()=>{document.addEventListener("scroll",t=>{let e=t.target instanceof Element?t.target.closest(DA):null;e&&BA(e)},!0)};var PA=(t,e)=>{if(!lt||e.key!=="Tab"||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof z)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(" "));return t.dispatch(r.setSelection(z.create(r.doc,n.from+1)).scrollIntoView()),!0},FA=new Set(["-","'",'"']),zA=(t,e)=>{if(!lt||!FA.has(e.key)||e.altKey||e.metaKey||e.ctrlKey||e.isComposing||e.keyCode===229)return!1;let{selection:n}=t.state;if(!(n instanceof z)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0)return!1;let r=t.state.tr.replaceWith(n.from,n.to,t.state.schema.text(e.key));return t.dispatch(r.setSelection(z.create(r.doc,n.from+e.key.length)).scrollIntoView()),!0},$A=(t,e)=>{if(!lt||e.inputType!=="insertReplacementText"||e.isComposing||!e.cancelable)return!1;let{selection:n}=t.state;return!(n instanceof z)||n.$from.parent!==n.$to.parent||n.$from.parent.type.spec.code!==!0?!1:(e.preventDefault(),e.stopImmediatePropagation(),!0)};var _A=(t,e)=>{if(!lt||!Ie(t.state))return!1;if(e==="addRow")return Cy(t.state,t.dispatch);if(e==="deleteRow")return Us(t.state,t.dispatch);if(e==="addColumn")return qs(t.state,t.dispatch);if(e==="deleteColumn")return Ks(t.state,t.dispatch);if(e==="header"){let{$from:n}=t.state.selection;for(let r=n.depth;r>0;r-=1){if(n.node(r).type.name!=="table")continue;let i=Math.min(n.before(r)+4,t.state.doc.content.size);return t.dispatch(t.state.tr.setSelection($.near(t.state.doc.resolve(i),1)).scrollIntoView()),!0}}return!1},Df=t=>{t?(en.dataset.state="open",en.setAttribute("aria-hidden","false")):en.dataset.state!=="closed"&&(en.dataset.state="closed",en.setAttribute("aria-hidden","true"))},HA=t=>{if(en.querySelectorAll("button").forEach(i=>{let o=Dt(i.dataset.label);i.textContent=o,i.setAttribute("aria-label",o)}),!lt||!Ie(t.state)){Df(!1);return}let e=t.domAtPos(t.state.selection.from).node,n=(e instanceof Element?e:e.parentElement)?.closest("td, th");if(!(n instanceof HTMLElement)){Df(!1);return}let r=n.getBoundingClientRect();en.style.left=`${Math.max(8,Math.min(window.innerWidth-en.offsetWidth-8,r.left))}px`,en.style.top=`${Math.max(8,r.top-32)}px`,Df(!0)},Bb={doc:null,focusedMermaidPos:null,generation:-1,decorations:ee.empty},Lb=(t,e,n)=>{let r=!1,i=Math.max(0,Math.min(t.content.size,e-1)),o=Math.max(i,Math.min(t.content.size,Math.max(n,e+1)+1));return t.nodesBetween(i,o,s=>(s.type.name==="heading"&&(r=!0),!r)),r},VA=t=>t.steps.some((e,n)=>{let r=t.docs[n],i=t.docs[n+1]||t.doc,o=!1;return e.getMap().forEach((s,a,l,c)=>{(Lb(r,s,a)||Lb(i,l,c))&&(o=!0)}),o}),WA=Se(()=>new X({state:{init:()=>null,apply:(t,e,n,r)=>(xt(St,"transactions"),t.docChanged&&VA(t)&&Gf(r.doc),e)},view(t){let e={autocapitalize:"none",autocorrect:"off",spellcheck:"false"},n=new Map(Object.keys(e).map(h=>[h,t.dom.getAttribute(h)])),r=h=>{if(h.state.selection.$from.parent.type.spec.code===!0){for(let[m,g]of Object.entries(e))h.dom.setAttribute(m,g);return}for(let[m,g]of n)g===null?h.dom.removeAttribute(m):h.dom.setAttribute(m,g)},i=h=>{let m=h.state.doc;h.dom.classList.toggle("weibei-empty-document",m.childCount===1&&m.firstChild?.type.name==="paragraph"&&m.firstChild.content.size===0),h.dom.dataset.emptyPlaceholder=Dt("emptyNotePlaceholder")},o=h=>{ho!==h&&(ho=h,t.dispatch(t.state.tr.setMeta("weibeiMermaidFocusChanged",h)))},s=h=>o(h.target===t.dom),a=h=>{h.target===t.dom&&o(!1)},l=()=>{jf=ha,da=!1;let{$from:h}=t.state.selection;mo=h.parent.isTextblock&&h.parent.content.size===0?h.before(h.depth):null},c=()=>{da=!0,setTimeout(qA)},u=h=>{h.target!==t.dom||!t.hasFocus()||!PA(t,h)&&!zA(t,h)||(h.preventDefault(),h.stopImmediatePropagation())},f=h=>{h.target===t.dom&&$A(t,h)},d=h=>h.preventDefault(),p=h=>{let m=h.target instanceof Element?h.target.closest("button[data-action]"):null;m instanceof HTMLElement&&(_A(t,m.dataset.action||""),t.focus(),window.requestAnimationFrame(()=>HA(t)))};return t.dom.addEventListener("focus",s,!0),t.dom.addEventListener("blur",a,!0),ho=t.hasFocus(),{update(h,m){h.state.doc.eq(m.doc)||(Ct(),ci())},destroy(){t.dom.removeEventListener("focus",s,!0),t.dom.removeEventListener("blur",a,!0),ho=!1,wt=null,fa=new WeakMap}}},props:{handlePaste:()=>!1,handleDrop:()=>!1,handleTextInput:()=>!1,handleClick(t,e,n){return Qb(n.target)||_f(n.target)||Hf(n.target)||Yb(n.target)},handleKeyDown(t,e){if(e.key!=="Enter"&&e.key!==" ")return!1;if(Hf(e.target))return e.preventDefault(),!0;if(!e.metaKey&&!e.ctrlKey)return!1;let n=OA();return n?(ct("wikiLinkActivated",{title:n}),e.preventDefault(),!0):!1},decorations(t){let e=wA(t);SA(e);let n=e?.pos??null,r=Bb;if(r.doc===t.doc&&r.focusedMermaidPos===n&&r.generation===li)return xt(St,"decorationCacheHits"),r.decorations;let i=[],o={open:!1},s=new Map;t.doc.descendants((l,c,u)=>{if(xt(St,"decorationNodes"),l.type.name==="code_block")return MA(i,l,c,e)||(i.push(oe.node(c,c+l.nodeSize,{class:"weibei-code-block","data-language":l.attrs.language||""})),RA(i,l,c)),!1;if(l.isText){let d=c,p=l.text||"";if((l.marks||[]).some(m=>m.type.name.toLowerCase().includes("code"))||Ye!==null)return!0;xA(i,p,d),kA(i,p,d,o),yA(i,p,d),bA(i,p,d),gA(i,p,d,s)}return!0});let a=ee.create(t.doc,i);return Bb={doc:t.doc,focusedMermaidPos:n,generation:li,decorations:a},a}}})),Bf=()=>{if(window.weiBeiSuppressSelectionReport)return;let t=hA(),e=t?iA():null,n=t&&re?re.action(o=>{let{state:s}=o.get(se),{selection:a}=s,c=["strong","emphasis","highlight","link","inlineCode"].filter(y=>s.schema.marks[y]&&s.doc.rangeHasMark(a.from,a.to,s.schema.marks[y])),u=s.schema.marks.writing_font,f,d=!1;u&&s.doc.nodesBetween(a.from,a.to,y=>{if(!y.isText)return!0;let x=u.isInSet(y.marks||[])?.attrs.font||"serif";return f===void 0?f=x:f!==x&&(d=!0),!0}),f&&!d&&c.push(`font:${f}`);let p=a instanceof H&&a.node.type.name==="math_inline";p&&c.push("inlineMath");let h=a.$from.parent.type.name;for(let y=a.$from.depth;y>0;y-=1){let x=a.$from.node(y).type.name;if(x==="blockquote"||x==="block_quote"){h="blockquote";break}}h==="heading"&&(h=`heading${a.$from.parent.attrs.level||""}`);let m="",g=s.schema.marks.link;return g&&s.doc.nodesBetween(a.from,a.to,y=>{let x=g.isInSet(y.marks||[]);return x&&!m&&(m=String(x.attrs.href||"")),!m}),{activeMarks:c,blockType:h,canConvertToMath:p||a instanceof z&&!a.empty&&a.$from.parent===a.$to.parent&&a.$from.parent.isTextblock,linkTarget:m}}):{activeMarks:[],blockType:"",canConvertToMath:!1,linkTarget:""},r=e?`${Math.round(e.x)}:${Math.round(e.y)}:${Math.round(e.width)}:${Math.round(e.height)}`:"",i=JSON.stringify(n);if(!(t===oi.text&&r===oi.rectKey&&i===oi.detailKey)){if(oi={text:t,rectKey:r,detailKey:i},!t){Lf=null,ct("selectionChanged",{text:"",rect:null,...n});return}Lf=dA(),ct("selectionChanged",{text:t,rect:e,...n})}};var Kf=()=>{if(!re)throw new Error("WeiBei editor is not ready")},ex=t=>{Pf=mA(t),li+=1,re&&re.action(e=>{let n=e.get(se);n.dispatch(n.state.tr.setMeta("weibeiSelectionAskMarksChanged",!0))})},jA=()=>{if(!re||mo===null)return;let t=mo;mo=null,re.action(e=>{let n=e.get(se);n.domObserver?.flush();let r=n.state.doc.nodeAt(t);if(!r?.isTextblock||!r.textContent)return;let i=n.state.schema.nodes.hardbreak||n.state.schema.nodes.hard_break,o=[];for(let a=0;a<r.childCount;a+=1){let l=r.child(a);l.type!==i&&o.push(l)}if(o.length!==r.childCount){let a=r.type.create(r.attrs,E.fromArray(o),r.marks),l=n.state.tr.replaceWith(t,t+r.nodeSize,a).scrollIntoView();l.setSelection(z.create(l.doc,Math.min(t+1+a.content.size,l.doc.content.size))),n.dispatch(l)}let s=n.nodeDOM(t);s instanceof HTMLElement&&(s.querySelectorAll("br").forEach(a=>a.remove()),n.domObserver?.flush())})},qA=()=>{re&&(jA(),da=!1,jf=null,Ct(),ci())},Uf=()=>re.action(t=>t.get(G)),KA=(t=!0)=>{Ye!==null&&(Uf().call(oa.key,{keep:t}),Ye=null,Zt=null,ga=null)},Jf=t=>{Kf();let e=String(t||"");ga=e;let n=la(e);bo=n.frontmatter,ka();let r=n.body,i=Zt!==null&&Ye===Zt&&r.startsWith(Zt)?r.slice(Zt.length):null,o;i!==null&&!/[$<>\\`\r]/.test(i)?(o=r,Zt=r):(o=aa(r,"agentGenerated"),Zt=o===r?r:null,ha=ya(o));let s=Uf();Ye===null?(s.call(uo.key),Ye=""):o.startsWith(Ye)||(s.call(fo.key,{diffReview:!1}),s.call(uo.key),Ye="");let a=o.slice(Ye.length);a&&s.call(ia.key,a),Ye=o,Ct()},UA=t=>{let e=String(t||"");if(!e)return;let n=ga;Jf(n===null?e:n+e)},JA=t=>{Zt=null,Jf(t),Uf().call(fo.key,{diffReview:!1}),Zt=null,Ye=null;try{re?.action(e=>{e.get(se).updateState(e.get(se).state)})}catch{}Ff(),Ct()},GA=t=>{Kf(),KA(),ga=null,jf=null,mo=null,da=!1,yo+=1;let e=la(t||""),n=aa(e.body,"userDocument");bo=e.frontmatter,ka(),re.action(Tg(n)),ha=ya(n),re.action(r=>Gf(r.get(se).state.doc)),Ct()};var QA=()=>(Kf(),xt(St,"fullSerializations"),ya(re.action(Eg())));var tx=()=>Array.from(document.querySelectorAll(".ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6")),Pb=0,ca=-2,Vf=null,Gf=t=>{let e=[],n=Math.max(1,t.content.size);t.descendants((i,o)=>{if(i.type.name!=="heading")return!0;let s=i.textContent.trim();if(!s)return!1;let a=e.length;return e.push({id:`note-heading-${a}`,index:a,level:Number(i.attrs.level||1),title:s,position:Math.max(0,Math.min(1,o/n))}),!1});let r=db(e);r!==Vf&&(Vf=r,xt(St,"outlineReports"),ct("outlineChanged",{items:e}))},ci=()=>{window.cancelAnimationFrame(Pb),Pb=window.requestAnimationFrame(()=>{let t=tx();if(t.length===0){ca!==-1&&(ca=-1,ct("activeHeadingChanged",{index:null}));return}let e=Math.max(0,window.innerHeight*.32),n=0;t.forEach((r,i)=>{r.getBoundingClientRect().top<=e&&(n=i)}),n!==ca&&(ca=n,ct("activeHeadingChanged",{index:n}))})},YA=t=>{let e=Number(t),n=tx(),r=Number.isFinite(e)?n[Math.max(0,Math.floor(e))]:null;if(!r)return!1;let i=XI();return r.scrollIntoView({block:"start",behavior:i?"auto":"smooth"}),i?ci():window.setTimeout(ci,180),!0},XA=(t,e)=>{let n=t!==pa||e!==cr;pa=t,cr=e,n&&(Vf=null,yo+=1,jI.clear(),WI.clear(),ex([]))};var ZA=t=>{Vb(t),li+=1,Gb(),re&&re.action(e=>{let n=e.get(se);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",ai))})},eN=t=>{ua=$b(t),li+=1,document.documentElement.dataset.weibeiLanguage=ua,ka(),Jb(),uA.forEach(e=>e()),re&&re.action(e=>{let n=e.get(se);n.dispatch(n.state.tr.setMeta("weibeiLanguageChanged",ua))})},tN=()=>re?(re.action(t=>t.get(se).focus()),!0):!1;window.WeiBeiEditor={getMarkdown:QA,setMarkdown:t=>GA(String(t||"")),updateStreamingMarkdown:t=>{try{Jf(t)}catch(e){lr(e)}},appendStreamingMarkdown:t=>{try{UA(t)}catch(e){lr(e)}},finishStreamingMarkdown:t=>{try{return JA(t),!0}catch(e){return lr(e),!1}},setDocumentID:t=>{let e=t||"";e!==pa&&XA(e,cr+1)},setTheme:ZA,setInterfaceLanguage:eN,setReduceMotion:ZI,setTextScale:eA,focus:tN,scrollToHeading:YA,setSelectionAskMarks:ex,setMarkdownBaseURL:t=>{zb=t||"",Gb()}};var ko=la(window.initialMarkdown||"");ko.body=aa(ko.body,"userDocument");bo=ko.frontmatter;ha=ya(ko.body);ka();var Wf=wg.make().config(t=>{t.set(Yi,document.querySelector("#editor")),t.set(Ui,ko.body),t.set(Qi,{editable:()=>lt,nodeViews:{image:fA,math_inline:Db,math_block:Db}}),t.set(wn.key,{throttleMs:0,scrollFollow:!1,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}})});Wf=Wf.use(WA).use(ey).use(Sk).use(Sb).use(qI).use(Jk).use(Se(()=>Yk(()=>Ye!==null)));Wf.use(bf).config(t=>{t.get(ta).selectionUpdated(()=>{requestAnimationFrame(Bf)})}).create().then(t=>{re=t,Jb(),LA(),document.querySelector("#editor-status")?.remove(),document.addEventListener("mouseup",Bf),document.addEventListener("pointerdown",()=>{window.weiBeiSuppressSelectionReport||(Lf=null,oi.text="",oi.rectKey="",ct("selectionChanged",{text:"",rect:null}))},!0),document.addEventListener("click",e=>{lt&&e.target instanceof Element&&e.target.closest(".weibei-structured-node")||!Qb(e.target)&&!_f(e.target)&&!Hf(e.target)&&!Yb(e.target)||(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keydown",e=>{e.key!=="Enter"&&e.key!==" "||_f(e.target)&&(e.preventDefault(),e.stopPropagation())},!0),document.addEventListener("keyup",e=>{Bf()}),document.addEventListener("scroll",ci,!0),ct("editorReady",{}),window.setTimeout(()=>{Fb=!0,rA(),re.action(e=>Gf(e.get(se).state.doc)),ci()})}).catch(lr);})(); /*! Bundled license information: lodash-es/lodash.js: diff --git a/Sources/WeiBei/Views/NotesAgentView.swift b/Sources/WeiBei/Views/NotesAgentView.swift index 5b64de2ec..2e86c3428 100644 --- a/Sources/WeiBei/Views/NotesAgentView.swift +++ b/Sources/WeiBei/Views/NotesAgentView.swift @@ -910,6 +910,10 @@ struct MarkdownPreviewView: View { @State private var maxObservedMeasuredHeight: CGFloat = 0 @State private var lastLayoutWidthKey = 0 @State private var lastChatWideTypography = false + /// Largest measurement rejected while the finalized-snapshot gate is closed. + /// The web side de-duplicates identical height reports, so one swallowed + /// during the gate would otherwise never arrive again. + @State private var latestGatedHeight: CGFloat = 0 /// Post-streaming height corrections ease instead of snapping: the finalized /// snapshot and the async re-measures that follow (KaTeX, fonts) can land @@ -940,13 +944,6 @@ struct MarkdownPreviewView: View { onSelectionChange: onSelectionChange, onAskAgentWithSelection: onSelectionChange, onContentHeightChange: { height in - guard acceptsHeightMeasurements else { - WeiBeiPerf.event( - "webview.markdown_height_ignored", - extra: "reason=finalizing" - ) - return - } guard compact && fitsContentHeight else { WeiBeiPerf.event( "webview.markdown_height_ignored", @@ -965,6 +962,19 @@ struct MarkdownPreviewView: View { } let measuredHeight = ceil(height) let nextFrameHeight = max(measuredHeight, Self.compactPreviewLoadingHeight) + guard acceptsHeightMeasurements else { + // Gate window before the finalized snapshot lands. Keep the + // freshest rejected height: the web side dedups repeated + // reports, so one swallowed here never re-arrives, and the + // row would stay at the stale pre-finish height — clipping + // the last wrapped lines after completion. + latestGatedHeight = max(latestGatedHeight, nextFrameHeight) + WeiBeiPerf.event( + "webview.markdown_height_ignored", + extra: "reason=finalizing" + ) + return + } if freezeHeightAfterMeasure, heightFrozen { // Keep rejecting recycled-row shrink and jitter, but accept // real late growth from Mermaid, formulas, fonts or images. @@ -1034,13 +1044,18 @@ struct MarkdownPreviewView: View { measuredHeight, Self.compactPreviewLoadingHeight ) + // Reconcile with measurements rejected during the gate: the + // snapshot may have been read before the finish re-layout, and + // a smaller height clips the answer's last wrapped lines. + let settledHeight = max(nextFrameHeight, latestGatedHeight) + latestGatedHeight = 0 heightFrozen = false acceptedMeasureCount = 0 - applySettledHeight(nextFrameHeight) - maxObservedMeasuredHeight = nextFrameHeight + applySettledHeight(settledHeight) + maxObservedMeasuredHeight = settledHeight onMeasuredHeight(measuredHeight) onContentHeightChange() - onFinalizedSnapshotReady(measuredHeight) + onFinalizedSnapshotReady(settledHeight) }, onRenderFailure: onRenderFailure ) diff --git a/Sources/WeiBei/WebEditor/src/editor.ts b/Sources/WeiBei/WebEditor/src/editor.ts index 61331da95..efc642178 100644 --- a/Sources/WeiBei/WebEditor/src/editor.ts +++ b/Sources/WeiBei/WebEditor/src/editor.ts @@ -2980,6 +2980,12 @@ const finishStreamingMarkdownInternal = (markdown: any) => { } catch { // View not ready yet; decorations clear on the next transaction anyway. } + // Measure synchronously so the height returned to native reflects the + // finalized DOM, not the last streamed report. The finish re-layout can + // grow the document (last wrapped lines, KaTeX), and native reads + // WeiBeiCompactPreviewHeight the instant this call returns — a stale + // smaller value left the completed row clipping its final lines. + publishContentHeight(); scheduleContentHeightReports(); }; diff --git a/Sources/WeiBei/WebEditor/src/streaming-appearance.ts b/Sources/WeiBei/WebEditor/src/streaming-appearance.ts index 7f13c0d8d..afa581e82 100644 --- a/Sources/WeiBei/WebEditor/src/streaming-appearance.ts +++ b/Sources/WeiBei/WebEditor/src/streaming-appearance.ts @@ -100,11 +100,22 @@ export function streamingAppearancePlugin(isStreamingActive: () => boolean): Plu }, }, props: { - // Hidden entirely once the streaming session is over, so the finished - // render never keeps a caret or stale fade spans. + // Once the streaming session is over the caret is gone, but in-flight + // fades keep their spans until they expire so the last streamed + // characters finish their 260ms fade instead of popping to full + // opacity when the finish repaint unwraps the decoration spans. decorations(state) { const appearance = appearanceKey.getState(state) as AppearanceState | undefined; - if (!appearance || !isStreamingActive()) return DecorationSet.empty; + if (!appearance) return DecorationSet.empty; + if (!isStreamingActive()) { + const now = Date.now(); + const remaining = appearance.fades.filter((entry) => now < entry.expiresAt); + if (remaining.length === 0) return DecorationSet.empty; + return DecorationSet.create( + state.doc, + remaining.map((entry) => Decoration.inline(entry.from, entry.to, FADE_SPEC)), + ); + } return appearance.set; }, },