diff --git a/Sources/WeiBei/App/WeiBeiApp.swift b/Sources/WeiBei/App/WeiBeiApp.swift index 74d7a6beb..c064211c0 100644 --- a/Sources/WeiBei/App/WeiBeiApp.swift +++ b/Sources/WeiBei/App/WeiBeiApp.swift @@ -121,6 +121,7 @@ struct WeiBeiApp: App { .environmentObject(store.paneState) .environmentObject(store.interaction) .preferredColorScheme(store.appearanceMode.colorScheme) + .environment(\.weiBeiTextScale, store.interfaceTextScale.multiplier) .modifier(WeiBeiAppearanceTransition(mode: store.appearanceMode)) .background(WindowChromeConfigurator(appearanceMode: store.appearanceMode)) .background(MainWindowReopenBridge(appDelegate: appDelegate)) diff --git a/Sources/WeiBei/Resources/Editor/editor-entry.js b/Sources/WeiBei/Resources/Editor/editor-entry.js index 87cbbf8d7..f177e0a13 100644 --- a/Sources/WeiBei/Resources/Editor/editor-entry.js +++ b/Sources/WeiBei/Resources/Editor/editor-entry.js @@ -1,4 +1,4 @@ -"use strict";(()=>{var v1=Object.create;var _l=Object.defineProperty;var A1=Object.getOwnPropertyDescriptor;var I1=Object.getOwnPropertyNames;var N1=Object.getPrototypeOf,R1=Object.prototype.hasOwnProperty;var O1=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},D1=(t,e)=>{for(var n in e)_l(t,n,{get:e[n],enumerable:!0})},L1=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of I1(e))!R1.call(t,i)&&i!==n&&_l(t,i,{get:()=>e[i],enumerable:!(r=A1(e,i))||r.enumerable});return t};var B1=(t,e,n)=>(n=t!=null?v1(N1(t)):{},L1(e||!t||!t.__esModule?_l(n,"default",{value:t,enumerable:!0}):n,t));var km=O1((I_,ym)=>{"use strict";var Ys=Object.prototype.hasOwnProperty,gm=Object.prototype.toString,um=Object.defineProperty,fm=Object.getOwnPropertyDescriptor,dm=function(e){return typeof Array.isArray=="function"?Array.isArray(e):gm.call(e)==="[object Array]"},pm=function(e){if(!e||gm.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)},hm=function(e,n){um&&n.name==="__proto__"?um(e,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):e[n.name]=n.newValue},mm=function(e,n){if(n==="__proto__")if(Ys.call(e,n)){if(fm)return fm(e,n).value}else return;return e[n]};ym.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,P1);function Gp(t){return new ut(ct.docTypeError,`Doc type error, unsupported type: ${Is(t)}`)}function Xp(t){return new ut(ct.contextNotFound,`Context "${t}" not found, do you forget to inject it?`)}function Yp(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 Qp(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(` +"use strict";(()=>{var v1=Object.create;var _l=Object.defineProperty;var A1=Object.getOwnPropertyDescriptor;var I1=Object.getOwnPropertyNames;var N1=Object.getPrototypeOf,R1=Object.prototype.hasOwnProperty;var O1=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},D1=(t,e)=>{for(var n in e)_l(t,n,{get:e[n],enumerable:!0})},L1=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of I1(e))!R1.call(t,i)&&i!==n&&_l(t,i,{get:()=>e[i],enumerable:!(r=A1(e,i))||r.enumerable});return t};var B1=(t,e,n)=>(n=t!=null?v1(N1(t)):{},L1(e||!t||!t.__esModule?_l(n,"default",{value:t,enumerable:!0}):n,t));var km=O1((N_,ym)=>{"use strict";var Ys=Object.prototype.hasOwnProperty,gm=Object.prototype.toString,um=Object.defineProperty,fm=Object.getOwnPropertyDescriptor,dm=function(e){return typeof Array.isArray=="function"?Array.isArray(e):gm.call(e)==="[object Array]"},pm=function(e){if(!e||gm.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)},hm=function(e,n){um&&n.name==="__proto__"?um(e,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):e[n.name]=n.newValue},mm=function(e,n){if(n==="__proto__")if(Ys.call(e,n)){if(fm)return fm(e,n).value}else return;return e[n]};ym.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,P1);function Gp(t){return new ut(ct.docTypeError,`Doc type error, unsupported type: ${Is(t)}`)}function Xp(t){return new ut(ct.contextNotFound,`Context "${t}" not found, do you forget to inject it?`)}function Yp(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 Qp(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 Zp(t){return new ut(ct.parserMatchError,`Cannot match target parser for node: ${Is(t)}.`)}function eh(t){return new ut(ct.serializerMatchError,`Cannot match target serializer for node: ${Is(t)}.`)}function th(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 nh(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 Xp(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)}},F1=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=[]}},z1=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 F1(t,e,this)}},Y=(t,e)=>new z1(t,e),$1=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},rh=class ih{#t;#e;#r;#n;constructor(e,n,r){this.produce=i=>i&&Object.keys(i).length?new ih(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 $1(e,n,r))}get meta(){return this.#r}get inspector(){return this.#n}},oh=class{constructor(){this.store=new Map,this.get=t=>{let e=this.store.get(t.id);if(!e)throw Yp(t.name);return e},this.remove=t=>{this.store.delete(t.id)},this.has=t=>this.store.has(t.id)}},_1=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},H1=class{constructor(t,e=3e3){this.create=n=>new _1(n,this),this.id=Symbol(`Timer-${t}`),this.name=t,this.timeout=e}},bt=(t,e=3e3)=>new H1(t,e);var W1={};function Zn(t,e){let n=e||W1,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return ah(t,r,i)}function ah(t,e,n){if(j1(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 sh(t.children,e,n)}return Array.isArray(t)?sh(t,e,n):""}function sh(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 ch={}.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]/),uh=Tn(/[#-'*+\--9=?A-Z^-~]/);function er(t){return t!==null&&(t<32||t===127)}var oo=Tn(/\d/),fh=Tn(/[\dA-Fa-f]/),dh=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 J1(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};gh(f,-l),gh(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(yh,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 oC(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:aC},sC={partial:!0,tokenize:lC};function aC(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(sC,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 lC(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:uC,resolve:cC,tokenize:fC};function cC(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:kC},yC={partial:!0,tokenize:bC};function kC(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(yC,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 bC(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:xC};function xC(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:wC,tokenize:CC};function wC(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 CC(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 kh=["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:EC,tokenize:TC},SC={partial:!0,tokenize:AC},MC={partial:!0,tokenize:vC};function EC(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 TC(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)):kh.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(SC,Zt,F)(b)):b===null||D(b)?(t.exit("htmlFlowData"),F(b)):(t.consume(b),te)}function F(b){return t.check(MC,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 vC(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 AC(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:IC};function IC(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:DC,resolveTo:LC,tokenize:BC},NC={tokenize:PC},RC={tokenize:FC},OC={tokenize:zC};function DC(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:KC},exit:JC,name:"list",tokenize:qC},jC={partial:!0,tokenize:GC},VC={partial:!0,tokenize:UC};function qC(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(jC,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 KC(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(VC,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 UC(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 JC(t){t.exit(this.containerState.type)}function GC(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:XC,tokenize:YC};function XC(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 YC(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 bh={tokenize:QC};function QC(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 xh={resolveAll:Mh()},wh=Sh("string"),Ch=Sh("text");function Sh(t){return{resolveAll:Mh(t==="text"?ZC: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(;++daS,contentInitial:()=>tS,disable:()=>lS,document:()=>eS,flow:()=>rS,flowInitial:()=>nS,insideSpan:()=>sS,string:()=>iS,text:()=>oS});var eS={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},tS={91:Kl},nS={[-2]:ao,[-1]:ao,32:ao},rS={35:Jl,42:ir,45:[js,ir],60:Xl,61:js,95:ir,96:Fs,126:Fs},iS={38:Ps,92:Bs},oS={[-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},sS={null:[so,xh]},aS={null:[42,95]},lS={null:[]};function Eh(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 uS(m(F),W)}function m(F){return cS(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 uS(t,e){let n=-1,r=[],i;for(;++n0){let It=J.tokenStack[J.tokenStack.length-1];(It[1]||Ih).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()),yS);return i(),s}function yS(t,e,n){return">"+(n?"":" ")+t}function qs(t,e){return Ph(t,e.inConstruct,!0)&&!Ph(t,e.notInConstruct,!1)}function Ph(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++r!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):Om(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 kM(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Qm.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function bM(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Rm(t){let e={};for(let n in t)e[n]=t[n];return e}function Om(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=Dm(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Dm(e.marks)}};function Dm(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 Lm=new WeakMap;function xM(t){let e=Lm.get(t);return e===void 0&&Lm.set(t,e=wM(t)),e}function wM(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 tg=65535,ng=Math.pow(2,16);function CM(t,e){return t+e*ng}function Zm(t){return t&tg}function SM(t){return(t-(t&tg))/ng}var rg=1,ig=2,la=4,og=8,Mo=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&og)>0}get deletedBefore(){return(this.delInfo&(rg|la))>0}get deletedAfter(){return(this.delInfo&(ig|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=Zm(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:CM(a/3,e-l),m=e==l?ig:e==f?rg:la;return(n<0?e!=l:e!=f)&&(m|=og),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=Zm(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 MM(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 EM(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 TM(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 RM(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)&&OM(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&&ag(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&&sg(t,s,a,o),!1}})}function sg(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 ag(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 OM(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function DM(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 LM(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 PM(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function BM(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 cg(i,o,r)?new xe(e,n,r):new _c(i,o,r).fit()}function cg(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(ug(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,ug(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&&!$M(n,o.content,s)?a:null}function $M(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=_M(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 fg(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 WM(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=zM(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new R(M.from(r),0,0))}function jM(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=dg(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 dg(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 HM(this,e,n,r),this}replaceRangeWith(e,n,r){return WM(this,e,n,r),this}deleteRange(e,n){return jM(this,e,n),this}lift(e,n){return vM(this,e,n),this}join(e,n=1){return FM(this,e,n),this}wrap(e,n){return NM(this,e,n),this}setBlockType(e,n=e,r,i=null){return RM(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return DM(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 LM(this,e,n,r),this}addMark(e,n,r){return MM(this,e,n,r),this}removeMark(e,n,r){return EM(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}},pg=!1;function hg(t){!pg&&!t.parent.inlineContent&&(pg=!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){hg(e),hg(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 mg(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=u)}),t.setSelection(_.near(t.doc.resolve(s),n))}var gg=1,fa=2,yg=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|=yg,this}get scrolledIntoView(){return(this.updated&yg)>0}};function kg(t,e){return!e||!t?t:t.bind(e)}var br=class{constructor(e,n,r){this.name=e,this.init=kg(n.init,r),this.apply=kg(n.apply,r)}},qM=[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=qM.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 bg(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=bg(i,e,{})),n[r]=i}return n}var X=class{constructor(e){this.spec=e,this.props={},e.props&&bg(e.props,this,this.props),this.key=e.key?e.key.key:xg("plugin")}getState(e){return e[this.key]}},Vc=Object.create(null);function xg(t){return t in Vc?t+"$"+ ++Vc[t]:(Vc[t]=0,t+"$")}var ee=class{constructor(e="key"){this.key=xg(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 Cg(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=Cg(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(Tg(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},Sg=(t,e,n)=>{let r=Cg(t,n);if(!r)return!1;let i=Xc(r);return i?KM(t,i,e):!1};function KM(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 UM(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=UM(t,n);if(!r)return!1;let i=Mg(r);if(!i)return!1;let o=i.nodeAfter;if(Tg(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)},XM=(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},YM=(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 ZM(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 eE=ZM();var tE=(t,e)=>(e&&e(t.tr.setSelection(new pt(t.doc))),!0);function nE(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 Tg(t,e,n,r){let i=e.nodeBefore,o=e.nodeAfter,s,a,l=i.type.spec.isolating||o.type.spec.isolating;if(!l&&nE(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 vg(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 rE=vg(-1),iE=vg(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 sE(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 Ng=(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},w2=new be(/--$/,"\u2014",{inCodeMark:!1}),C2=new be(/\.\.\.$/,"\u2026",{inCodeMark:!1}),S2=new be(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),M2=new be(/"$/,"\u201D",{inCodeMark:!1}),E2=new be(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),T2=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,Rg=typeof document<"u"?document:null,Pn=Bn&&Bn.userAgent||"",tu=/Edge\/(\d+)/.exec(Pn),Bg=/MSIE \d/.exec(Pn),nu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Pn),iu=!!(Bg||nu||tu),O2=Bg?document.documentMode:nu?+nu[1]:tu?+tu[1]:0,cE=!iu&&/gecko\/(\d+)/i.test(Pn),D2=cE&&+(/Firefox\/(\d+)/.exec(Pn)||[0,0])[1],ru=!iu&&/Chrome\/(\d+)/.exec(Pn),uE=!!ru,L2=ru?+ru[1]:0,fE=!iu&&!!Bn&&/Apple Computer/.test(Bn.vendor),dE=fE&&(/Mobile\/\w+/.test(Pn)||!!Bn&&Bn.maxTouchPoints>2),B2=dE||(Bn?/Mac/.test(Bn.platform):!1),pE=/Android \d/.test(Pn),hE=!!Rg&&"webkitFontSmoothing"in Rg.documentElement.style,P2=hE?+(/\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 mE=new ee("MILKDOWN_CUSTOM_INPUTRULES");function Pg({rules:t}){let e=new X({key:mE,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)=>!(pE&&uE&&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,` +`).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},YM=(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 ZM(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 eE=ZM();var tE=(t,e)=>(e&&e(t.tr.setSelection(new pt(t.doc))),!0);function nE(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 Tg(t,e,n,r){let i=e.nodeBefore,o=e.nodeAfter,s,a,l=i.type.spec.isolating||o.type.spec.isolating;if(!l&&nE(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 vg(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 rE=vg(-1),iE=vg(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 sE(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 Ng=(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,Rg=typeof document<"u"?document:null,Pn=Bn&&Bn.userAgent||"",tu=/Edge\/(\d+)/.exec(Pn),Bg=/MSIE \d/.exec(Pn),nu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Pn),iu=!!(Bg||nu||tu),D2=Bg?document.documentMode:nu?+nu[1]:tu?+tu[1]:0,cE=!iu&&/gecko\/(\d+)/i.test(Pn),L2=cE&&+(/Firefox\/(\d+)/.exec(Pn)||[0,0])[1],ru=!iu&&/Chrome\/(\d+)/.exec(Pn),uE=!!ru,B2=ru?+ru[1]:0,fE=!iu&&!!Bn&&/Apple Computer/.test(Bn.vendor),dE=fE&&(/Mobile\/\w+/.test(Pn)||!!Bn&&Bn.maxTouchPoints>2),P2=dE||(Bn?/Mac/.test(Bn.platform):!1),pE=/Android \d/.test(Pn),hE=!!Rg&&"webkitFontSmoothing"in Rg.documentElement.style,F2=hE?+(/\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 mE=new ee("MILKDOWN_CUSTOM_INPUTRULES");function Pg({rules:t}){let e=new X({key:mE,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)=>!(pE&&uE&&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 gE=Object.defineProperty,yE=Object.defineProperties,kE=Object.getOwnPropertyDescriptors,Og=Object.getOwnPropertySymbols,bE=Object.prototype.hasOwnProperty,xE=Object.prototype.propertyIsEnumerable,Dg=(t,e,n)=>e in t?gE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,wE=(t,e)=>{for(var n in e||(e={}))bE.call(e,n)&&Dg(t,n,e[n]);if(Og)for(var n of Og(e))xE.call(e,n)&&Dg(t,n,e[n]);return t},CE=(t,e)=>yE(t,kE(e));function Lg(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Fg(t,e,n){let i=t.state.doc.content.size,o=Lg(e,0,i),s=Lg(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 CE(wE({},y),{toJSON:()=>y})}function ou(t){return Object.assign(Object.create(t),t).setTime(Date.now())}function SE(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 ME(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 zg(t,e){return ME(n=>n.type===e)(t)}function $g(t,e){let n=e.nodes[t];if(!n)throw th("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 _g(t){return e=>su(t)(e.$from)}function Hg(t,e){if(!(t instanceof H))return;let{node:n,$from:r}=t;if(SE(e,n))return{node:n,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Wg=(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:'"'},EE=typeof navigator<"u"&&/Mac/.test(navigator.platform),TE=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=EE&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||TE&&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 vE=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),AE=typeof navigator<"u"&&/Win/.test(navigator.platform);function IE(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}}},RE=class Jg extends Kg{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 Jg(e,n,r)}},Gg=class extends Ug{#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 Zp(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(RE.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 Qp(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},qg=class Xg extends Kg{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 Xg(e,n,r,i)}},OE=t=>Object.prototype.hasOwnProperty.call(t,"size"),Yg=class extends Ug{#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 eh(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(qg.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=qg.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=>OE(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},DE=function(){hu=null},Ar=function(t,e,n,r){return n&&(Qg(t,e,n,r,-1)||Qg(t,e,n,r,1))},LE=/^(img|br|input|textarea|hr)$/i;function Qg(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)||LE.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 BE(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 PE(t,e){for(;;){if(t.nodeType==3&&e2),Ct=bi||(jt?/Mac/.test(jt.platform):!1),Ny=jt?/Win/.test(jt.platform):!1,fn=/Android \d/.test(Hn),Fo=!!Zg&&"webkitFontSmoothing"in Zg.documentElement.style,_E=Fo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function HE(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 WE(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 ey(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?HE(o):WE(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 jE(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:Ry(t.dom)}}function Ry(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 VE({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Oy(n,r==0?0:r-e)}function Oy(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?KE(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Dy(n,i)}function KE(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 UE(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 GE(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 Ly(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=GE(t,r,i,e))}a==null&&(a=JE(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 Py(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 QE(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Py(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=By(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 ZE=/[\u0590-\u08ac]/;function eT(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?!ZE.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?o:s:Py(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 ty=null,ny=null,ry=!1;function tT(t,e,n){return ty==e&&ny==n?ry:(ty=e,ny=n,ry=n=="up"||n=="down"?QE(t,e,n):eT(t,e,n))}var Et=0,iy=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:iy,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:iy;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=$y(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);oT(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),Fy(this.contentDOM,this.children,e),bi&&sT(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=aT(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=zy(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 oy(t,e,n,r,i){$y(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 Fy(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 iT(t,e){return t.type.side-e.type.side}function oT(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 sT(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 aT(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&&FE(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(()=>{(!_y(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function cT(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 Hy(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(uy(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else uy(t)}function uy(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 fy(t){return t.editable&&!t.hasFocus()?!1:Wy(t)}function Wy(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 uT(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 dy(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?fT(t):dT(t)}function fT(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 dT(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 py(t,e){let n=t.state.doc.resolve(e);if(!(Ne||Ny)&&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 hy(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 my(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 gy(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function mT(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;gy(t,r,"true"),setTimeout(()=>gy(t,r,"false"),20)}return!1}function gT(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function yT(t,e){let n=e.keyCode,r=gT(e);if(n==8||Ct&&n==72&&r=="c")return my(t,-1)||gi(t,-1);if(n==46&&!e.shiftKey||Ct&&n==68&&r=="c")return my(t,1)||gi(t,1);if(n==13||n==27)return!0;if(n==37||Ct&&n==66&&r=="c"){let i=n==37?py(t,t.state.selection.from)=="ltr"?-1:1:-1;return dy(t,i,r)||gi(t,i)}else if(n==39||Ct&&n==70&&r=="c"){let i=n==39?py(t,t.state.selection.from)=="ltr"?1:-1:1;return dy(t,i,r)||gi(t,i)}else{if(n==38||Ct&&n==80&&r=="c")return hy(t,-1,r)||gi(t,-1);if(n==40||Ct&&n==78&&r=="c")return mT(t)||hy(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=Gy(),l=a.createElement("div");l.appendChild(s.serializeFragment(r,{document:a}));let c=l.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Jy[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 Vy(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=wT(n),Fo&&CT(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&&!kT.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)a=ST(yy(a,+u[1],+u[2]),u[4]);else if(a=R.maxOpen(bT(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 kT=/^(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 bT(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&&Ky(l,o,a,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Uy(s[s.length-1],o.length));let u=qy(a,l);s.push(u),i=i.matchType(u.type),o=l}}),s)return M.from(s)}return t}function qy(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,M.from(t));return t}function Ky(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 yy(t,e,n){return en})),fu.createHTML(t)):t}function wT(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Gy(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(t),o;if((o=i&&Jy[i[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"").reverse().join("")),r.innerHTML=xT(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={},MT={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 ET(t){for(let e in Xe){let n=Xe[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{vT(t,r)&&!zu(t,r)&&(t.editable||!(r.type in Ye))&&n(t,r)},MT[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 TT(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 vT(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 AT(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,!Qy(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))||yT(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(Qy(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 IT(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 NT(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 RT(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 OT(t,e,n,r,i){return $u(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?RT(t,n):NT(t,n))}function DT(t,e,n,r){return $u(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function LT(t,e,n,r){return $u(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||BT(t,n,r)}function BT(t,e,n){if(n.button!=0)return!1;let r=Xy(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 Xy(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 Yy=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&&IT(n,t.input.lastClick)&&!n[Yy]&&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"?DT:LT)(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[Yy],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"):OT(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&&Xy(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 Qy(t,e){return t.composing?!0:Je&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var PT=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&&Ny&&FT(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}Zy(t,PT)};function FT(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++,Zy(t,20))};function Zy(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Ma(t),e))}function ek(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function zT(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=BE(e.focusNode,e.focusOffset),r=PE(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(),ek(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 $T(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&&_E<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)):$T(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function _T(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function HT(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=Vy(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=_T(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 tk(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,tk(r),r.getData("text/html"),i,n)?n.preventDefault():HT(t,n)};var Ea=class{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}},WT=Ct?"altKey":"ctrlKey";function nk(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[WT]}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||Iy>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,nk(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{jT(t,e,t.dragging)}finally{t.dragging=null}};function jT(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=Vy(t,tk(e.dataTransfer),Oo?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(n&&nk(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?lg(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=ik(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=qT(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=ik(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=rk(o?ok(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 KT={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},UT=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()}),UT&&(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,KT)),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(fy(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)&&fy(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||XT(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),JT(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,YT(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:ZT,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 ZT(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 ev=/^(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 tv(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=QT(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&&!ev.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=Cy(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&&rv(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=Cy(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=nv(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 Cy(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 nv(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 iv(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(vy),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=Ey(this),My(this),this.nodeViews=Ty(this),this.docView=oy(this.state.doc,Sy(this),du(this),this.dom,this),this.domObserver=new Du(this,(r,i,o,s)=>tv(this,r,i,o,s)),this.domObserver.start(),ET(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(vy),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&&(ek(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=Ty(this);sv(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&Au(this),this.editable=Ey(this),My(this);let l=du(this),c=Sy(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&&jE(this);if(s){this.domObserver.stop();let p=f&&(rt||Ne)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&ov(i.selection,e.selection);if(f){let m=Ne?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=zT(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=oy(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())&&uT(this)&&h.delaySelUpdate())?pn(this,p):(Hy(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&&VE(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&&ey(this,n.getBoundingClientRect(),e)}else ey(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 XE(this,e)}coordsAtPos(e,n=1){return By(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 tT(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&&(TT(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,DE())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return AT(this,e)}domSelectionRange(){let e=this.domSelection();return e?Je&&this.root.nodeType===11&&zE(this.dom.ownerDocument)==this.dom&>(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 Sy(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 My(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 Ey(t){return!t.someProp("editable",e=>e(t.state)===!1)}function ov(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 Ty(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 sv(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 vy(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 lk={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"),sk=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:lk,encode:[]},"remarkStringifyOptions"),Na=bt("ConfigReady");function av(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 lv(t){let e=n=>(n.inject(sk,t).inject(Dt,[]).inject(vi,[]).inject(Ti,[]).inject($a,[]).inject(_a,[]).inject(xi,{handlers:lk,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(sk).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 ak(t){return{...t,parseDOM:t.parseDOM?.map(e=>({priority:t.priority,...e}))}}var ck=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,ak(o)])),marks:Object.fromEntries(t.get(Ci).map(([i,o])=>[i,ak(o)]))});return t.set($e,r),t.done(Qe),()=>{t.remove($e).remove(wi).remove(Ci).remove(Ra).clearTimer(Qe)}});gn(ck,{displayName:"Schema"});var uk=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 fk(t="cmdKey"){return Y((()=>()=>!1),t)}var Q=Y(new uk,"commands"),Oa=Y([Qe],"commandsTimer"),Si=bt("CommandsReady"),dk=t=>{let e=new uk;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(dk,{displayName:"Commands"});function cv(t){return t.Backspace=xr(Ng,pa,Sg,Gc),t}var pk=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=cv(Ig);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 pk,"keymap"),ju=Y([Qe],"keymapTimer"),Mi=bt("KeymapReady"),uv=t=>{let e=new pk;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"),hk=(()=>{throw Qr()}),_e=Y(hk,"parser"),Vu=Y([],"parserTimer"),mk=t=>(t.inject(_e,hk).inject(Vu,[Qe]).record(Da),async()=>{await t.waitTimers(Vu);let e=t.get(Nr),n=t.get($e);return t.set(_e,Gg.create(n,e)),t.done(Da),()=>{t.remove(_e).remove(Vu).clearTimer(Da)}});gn(mk,{displayName:"Parser"});var Ei=bt("SerializerReady"),qu=Y([],"serializerTimer"),gk=(()=>{throw Qr()}),mn=Y(gk,"serializer"),yk=t=>(t.inject(mn,gk).inject(qu,[Qe]).record(Ei),async()=>{await t.waitTimers(qu);let e=t.get(Nr),n=t.get($e);return t.set(mn,Yg.create(n,e)),t.done(Ei),()=>{t.remove(mn).remove(qu).clearTimer(Ei)}});gn(yk,{displayName:"Serializer"});var Ho=Y("","defaultValue"),Wo=Y(t=>t,"stateOptions"),La=Y([],"editorStateTimer"),Ba=bt("EditorStateReady");function fv(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 Gp(t)}var dv=new ee("MILKDOWN_STATE_TRACKER"),kk=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=fv(t.get(Ho),n,e),a=t.get(qo),l=a.addBaseKeymap(),c=[...o,new X({key:dv,state:{init:()=>{},apply:(d,p,h,m)=>{t.set(_o,m)}}}),Pg({rules:r}),Vg(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(kk,{displayName:"EditorState"});var Ai=Y([],"pasteRule"),Pa=Y([Qe],"pasteRuleTimer"),Fa=bt("PasteRuleReady"),bk=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(bk,{displayName:"PasteRule"});var jo=bt("EditorViewReady"),za=Y([],"editorViewTimer"),Rr=Y({},"editorViewOptions"),Vo=Y(null,"root"),Ku=Y(null,"rootDOM"),Uu=Y({},"rootAttrs");function pv(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 hv(t){t.classList.add("editor"),t.setAttribute("role","textbox")}var mv=new ee("MILKDOWN_VIEW_CLEAR"),xk=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:mv,view:a=>{let l=n?pv(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 hv(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(xk,{displayName:"EditorView"});var wk=class Ck{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Wl,this.#o=new oh,this.#i=new Map,this.#a=new Map,this.#l=new rh(this.#s,this.#o),this.#d=()=>{let e=av(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),n=[ck,mk,yk,dk,uv,bk,kk,xk,lv(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 Ck}#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 gv=t=>crypto.getRandomValues(new Uint8Array(t)),yv=(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}}},Sk=(t,e=21)=>yv(t,e|0,gv);var SH=Sk("abcedfghicklmn",10);function z(t,e){let n=fk(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 Mk(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 kv(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 nh(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 bv(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=kv(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=bv(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 Ek(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 Tk(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 xv(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=xv(t)(n);r.dispatch(r.state.tr.replace(e.from,e.to,i))}}function vk(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?wv(e,n,t,o):Cv(e,n,o):!0:!1}}function wv(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 Ak(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=Ik(r.identifier);i&&!e.get(i)&&e.set(i,r)}),n;function n(r){let i=Ik(r);return e.get(i)}}function Ik(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 Nk(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 Rk=ge(t=>an(/(?:^|[^*])\*([^*]+)\*$/,Ni.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:n+1}}));E(Rk,{displayName:"InputRule|Star",group:"Emphasis"});var Ok=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(Ok,{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 Dk=ge(t=>an(/(?({marker:e[0].startsWith("*")?"*":"_"})}));E(Dk,{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 Lk=ge(t=>an(/(?:`)([^`]+)(?:`)$/,jn.type(t)));E(Lk,{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 Sv=new Set(["http:","https:","mailto:","tel:","ftp:"]);function Mv(t){return t<=32||t>=127&&t<=160||t>=8203&&t<=8205||t===8232||t===8233||t===65279}function Ev(t){let e="";for(let n of t)Mv(n.codePointAt(0)??0)||(e+=n);return e}function Tv(t){if(typeof t!="string")return"";let e=t.trim();if(!e)return"";let n=Ev(e),r=/^([a-z][a-z0-9+.-]*):/i.exec(n)?.[1];return!r||Sv.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:Tv(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 Bk=z("ToggleLink",t=>(e={})=>Ln(Ii.type(t),e));E(Bk,{displayName:"Command",group:"Link"});var Pk=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(Pk,{displayName:"Command",group:"Link"});var Fk=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(Fk,{displayName:"NodeSchema",group:"Doc"});function vv(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",()=>()=>vv);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&&Av(t)?e.addNode("html",void 0,"
"):Nk(e,n),e.closeNode()}}}));function Av(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 Iv=Array(6).fill(0).map((t,e)=>e+1);function Nv(t){return t.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Ka=ve(Nv,"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:Iv.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}),Nk(n,r),n.closeNode()}}}});E(Lr.node,{displayName:"NodeSchema",group:"Heading"});E(Lr.ctx,{displayName:"NodeSchemaCtx",group:"Heading"});var zk=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(zk,{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 $k=ge(t=>ha(/^\s*>\s$/,Uo.type(t)));E($k,{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 _k=ge(t=>Zc(/^```(?[a-z]*)?[\s\n]$/,Jo.type(t),e=>({language:e.groups?.language??""})));E(_k,{displayName:"InputRule",group:"CodeBlock"});var kf=z("CreateCodeBlock",t=>(e="")=>Dn(Jo.type(t),{language:e}));E(kf,{displayName:"Command",group:"CodeBlock"});var Rv=z("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(n,r)=>t>=0?(r?.(n.tr.setNodeAttribute(t,"language",e)),!0):!1);E(Rv,{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 Hk=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(Hk,{displayName:"Command",group:"Image"});var Wk=z("UpdateImage",t=>(e={})=>(n,r)=>{let i=Hg(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(Wk,{displayName:"Command",group:"Image"});var Ov=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(Ov,{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:()=>` +`))),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=wT(n),Fo&&CT(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&&!kT.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)a=ST(yy(a,+u[1],+u[2]),u[4]);else if(a=R.maxOpen(bT(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=yy(a,f,d)}return t.someProp("transformPasted",f=>{a=f(a,t,l)}),a}var kT=/^(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 bT(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&&Ky(l,o,a,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Uy(s[s.length-1],o.length));let u=qy(a,l);s.push(u),i=i.matchType(u.type),o=l}}),s)return M.from(s)}return t}function qy(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,M.from(t));return t}function Ky(t,e,n,r,i){if(i<t.length&&i<e.length&&t[i]==e[i]){let o=Ky(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(qy(n,t,i+1))))}}function Uy(t,e){if(e==0)return t;let n=t.content.replaceChild(t.childCount-1,Uy(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 yy(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 Jy={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 Gy(){return document.implementation.createHTMLDocument("title")}var fu=null;function xT(t){let e=window.trustedTypes;return e?(fu||(fu=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:n=>n})),fu.createHTML(t)):t}function wT(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Gy(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(t),o;if((o=i&&Jy[i[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"</"+s+">").reverse().join("")),r.innerHTML=xT(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 CT(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 ST(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={},MT={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 ET(t){for(let e in Xe){let n=Xe[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{vT(t,r)&&!zu(t,r)&&(t.editable||!(r.type in Ye))&&n(t,r)},MT[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 TT(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 vT(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 AT(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,!Qy(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))||yT(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(Qy(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 IT(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 NT(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 RT(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 OT(t,e,n,r,i){return $u(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?RT(t,n):NT(t,n))}function DT(t,e,n,r){return $u(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function LT(t,e,n,r){return $u(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||BT(t,n,r)}function BT(t,e,n){if(n.button!=0)return!1;let r=Xy(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 Xy(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 Yy=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&&IT(n,t.input.lastClick)&&!n[Yy]&&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"?DT:LT)(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[Yy],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"):OT(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&&Xy(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 Qy(t,e){return t.composing?!0:Je&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var PT=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&&Ny&&FT(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}Zy(t,PT)};function FT(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++,Zy(t,20))};function Zy(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Ma(t),e))}function ek(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function zT(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=BE(e.focusNode,e.focusOffset),r=PE(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(),ek(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 $T(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&&_E<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)):$T(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function _T(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function HT(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=Vy(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=_T(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 tk(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,tk(r),r.getData("text/html"),i,n)?n.preventDefault():HT(t,n)};var Ea=class{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}},WT=Ct?"altKey":"ctrlKey";function nk(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[WT]}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||Iy>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,nk(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{jT(t,e,t.dragging)}finally{t.dragging=null}};function jT(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=Vy(t,tk(e.dataTransfer),Oo?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(n&&nk(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?lg(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={},ae=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?VT(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=ik(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=rk(o?ok(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)}};ae.empty=new ae([],[]);ae.removeOverlap=Hu;var Ue=ae.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 ae.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 ae)?e:e.reduce((n,r)=>n.concat(r instanceof ae?r:r.members),[]))}}forEachSet(e){for(let n=0;n<this.members.length;n++)this.members[n].forEachSet(e)}};function VT(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=qT(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 ae(e.sort(vr),a)}function rk(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 qT(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 ik(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 ok(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=ik(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=rk(o?ok(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 ae(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),ky(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),ky(e,i,r.copy(o.from,r.to)));break}}}return e}function ky(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(ae.create(t.state.doc,[t.cursorWrapper.deco])),va.from(e)}var KT={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},UT=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()}),UT&&(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,KT)),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(fy(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)&&fy(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||XT(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),JT(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,YT(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})}},by=new WeakMap,xy=!1;function JT(t){if(!by.has(t)&&(by.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=Mt,xy)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."),xy=!0}}function wy(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 GT(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return wy(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?wy(t,n):null}function XT(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 YT(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 QT(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:ZT,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 ZT(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 ev=/^(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 tv(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=QT(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=iv(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&&!ev.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=Cy(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&&rv(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=Cy(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=nv(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 Cy(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 nv(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 rv(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 iv(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(vy),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=Ey(this),My(this),this.nodeViews=Ty(this),this.docView=oy(this.state.doc,Sy(this),du(this),this.dom,this),this.domObserver=new Du(this,(r,i,o,s)=>tv(this,r,i,o,s)),this.domObserver.start(),ET(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(vy),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&&(ek(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=Ty(this);sv(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&Au(this),this.editable=Ey(this),My(this);let l=du(this),c=Sy(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&&jE(this);if(s){this.domObserver.stop();let p=f&&(rt||Ne)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&ov(i.selection,e.selection);if(f){let m=Ne?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=zT(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=oy(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())&&uT(this)&&h.delaySelUpdate())?pn(this,p):(Hy(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&&VE(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&&ey(this,n.getBoundingClientRect(),e)}else ey(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&&qE(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 XE(this,e)}coordsAtPos(e,n=1){return By(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 tT(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&&(TT(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,DE())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return AT(this,e)}domSelectionRange(){let e=this.domSelection();return e?Je&&this.root.nodeType===11&&zE(this.dom.ownerDocument)==this.dom&>(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 Sy(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 My(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 Ey(t){return!t.someProp("editable",e=>e(t.state)===!1)}function ov(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 Ty(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 sv(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 vy(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 lk={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"),sk=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:lk,encode:[]},"remarkStringifyOptions"),Na=bt("ConfigReady");function av(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 lv(t){let e=n=>(n.inject(sk,t).inject(Dt,[]).inject(vi,[]).inject(Ti,[]).inject($a,[]).inject(_a,[]).inject(xi,{handlers:lk,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(sk).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 ak(t){return{...t,parseDOM:t.parseDOM?.map(e=>({priority:t.priority,...e}))}}var ck=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,ak(o)])),marks:Object.fromEntries(t.get(Ci).map(([i,o])=>[i,ak(o)]))});return t.set($e,r),t.done(Qe),()=>{t.remove($e).remove(wi).remove(Ci).remove(Ra).clearTimer(Qe)}});gn(ck,{displayName:"Schema"});var uk=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 fk(t="cmdKey"){return Y((()=>()=>!1),t)}var Q=Y(new uk,"commands"),Oa=Y([Qe],"commandsTimer"),Si=bt("CommandsReady"),dk=t=>{let e=new uk;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(dk,{displayName:"Commands"});function cv(t){return t.Backspace=xr(Ng,pa,Sg,Gc),t}var pk=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=cv(Ig);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 pk,"keymap"),ju=Y([Qe],"keymapTimer"),Mi=bt("KeymapReady"),uv=t=>{let e=new pk;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"),hk=(()=>{throw Qr()}),_e=Y(hk,"parser"),Vu=Y([],"parserTimer"),mk=t=>(t.inject(_e,hk).inject(Vu,[Qe]).record(Da),async()=>{await t.waitTimers(Vu);let e=t.get(Nr),n=t.get($e);return t.set(_e,Gg.create(n,e)),t.done(Da),()=>{t.remove(_e).remove(Vu).clearTimer(Da)}});gn(mk,{displayName:"Parser"});var Ei=bt("SerializerReady"),qu=Y([],"serializerTimer"),gk=(()=>{throw Qr()}),mn=Y(gk,"serializer"),yk=t=>(t.inject(mn,gk).inject(qu,[Qe]).record(Ei),async()=>{await t.waitTimers(qu);let e=t.get(Nr),n=t.get($e);return t.set(mn,Yg.create(n,e)),t.done(Ei),()=>{t.remove(mn).remove(qu).clearTimer(Ei)}});gn(yk,{displayName:"Serializer"});var Ho=Y("","defaultValue"),Wo=Y(t=>t,"stateOptions"),La=Y([],"editorStateTimer"),Ba=bt("EditorStateReady");function fv(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 Gp(t)}var dv=new ee("MILKDOWN_STATE_TRACKER"),kk=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=fv(t.get(Ho),n,e),a=t.get(qo),l=a.addBaseKeymap(),c=[...o,new X({key:dv,state:{init:()=>{},apply:(d,p,h,m)=>{t.set(_o,m)}}}),Pg({rules:r}),Vg(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(kk,{displayName:"EditorState"});var Ai=Y([],"pasteRule"),Pa=Y([Qe],"pasteRuleTimer"),Fa=bt("PasteRuleReady"),bk=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(bk,{displayName:"PasteRule"});var jo=bt("EditorViewReady"),za=Y([],"editorViewTimer"),Rr=Y({},"editorViewOptions"),Vo=Y(null,"root"),Ku=Y(null,"rootDOM"),Uu=Y({},"rootAttrs");function pv(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 hv(t){t.classList.add("editor"),t.setAttribute("role","textbox")}var mv=new ee("MILKDOWN_VIEW_CLEAR"),xk=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:mv,view:a=>{let l=n?pv(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 hv(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(xk,{displayName:"EditorView"});var wk=class Ck{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new Wl,this.#o=new oh,this.#i=new Map,this.#a=new Map,this.#l=new rh(this.#s,this.#o),this.#d=()=>{let e=av(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),n=[ck,mk,yk,dk,uv,bk,kk,xk,lv(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 Ck}#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 gv=t=>crypto.getRandomValues(new Uint8Array(t)),yv=(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}}},Sk=(t,e=21)=>yv(t,e|0,gv);var MH=Sk("abcedfghicklmn",10);function z(t,e){let n=fk(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 Mk(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 kv(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 nh(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 bv(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=kv(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=bv(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 Ek(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 Tk(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 xv(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=xv(t)(n);r.dispatch(r.state.tr.replace(e.from,e.to,i))}}function vk(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?wv(e,n,t,o):Cv(e,n,o):!0:!1}}function wv(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 Cv(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 Ak(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=Ik(r.identifier);i&&!e.get(i)&&e.set(i,r)}),n;function n(r){let i=Ik(r);return e.get(i)}}function Ik(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 Nk(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 Rk=ge(t=>an(/(?:^|[^*])\*([^*]+)\*$/,Ni.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:n})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:n+1}}));E(Rk,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var Ok=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(Ok,{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 Dk=ge(t=>an(/(?<![\w:/])(?:\*\*|__)([^*_]+?)(?:\*\*|__)(?![\w/])$/,Ko.type(t),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));E(Dk,{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 Lk=ge(t=>an(/(?:`)([^`]+)(?:`)$/,jn.type(t)));E(Lk,{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 Sv=new Set(["http:","https:","mailto:","tel:","ftp:"]);function Mv(t){return t<=32||t>=127&&t<=160||t>=8203&&t<=8205||t===8232||t===8233||t===65279}function Ev(t){let e="";for(let n of t)Mv(n.codePointAt(0)??0)||(e+=n);return e}function Tv(t){if(typeof t!="string")return"";let e=t.trim();if(!e)return"";let n=Ev(e),r=/^([a-z][a-z0-9+.-]*):/i.exec(n)?.[1];return!r||Sv.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:Tv(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 Bk=z("ToggleLink",t=>(e={})=>Ln(Ii.type(t),e));E(Bk,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Pk=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(Pk,{displayName:"Command<updateLinkCommand>",group:"Link"});var Fk=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(Fk,{displayName:"NodeSchema<doc>",group:"Doc"});function vv(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",()=>()=>vv);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&&Av(t)?e.addNode("html",void 0,"<br />"):Nk(e,n),e.closeNode()}}}));function Av(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 Iv=Array(6).fill(0).map((t,e)=>e+1);function Nv(t){return t.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Ka=ve(Nv,"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:Iv.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}),Nk(n,r),n.closeNode()}}}});E(Lr.node,{displayName:"NodeSchema<heading>",group:"Heading"});E(Lr.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var zk=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(zk,{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 $k=ge(t=>ha(/^\s*>\s$/,Uo.type(t)));E($k,{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 _k=ge(t=>Zc(/^```(?<language>[a-z]*)?[\s\n]$/,Jo.type(t),e=>({language:e.groups?.language??""})));E(_k,{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 Rv=z("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(n,r)=>t>=0?(r?.(n.tr.setNodeAttribute(t,"language",e)),!0):!1);E(Rv,{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 Hk=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(Hk,{displayName:"Command<insertImageCommand>",group:"Image"});var Wk=z("UpdateImage",t=>(e={})=>(n,r)=>{let i=Hg(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(Wk,{displayName:"Command<updateImageCommand>",group:"Image"});var Ov=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(Ov,{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 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 Vk=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(Vk,{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 qk=ge(t=>ha(/^\s*([-+*])\s$/,Oi.type(t)));E(qk,{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 Kk=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(Kk,{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=>()=>Ak(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=>()=>vk(Vt.type(t)));E(Df,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Dv(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=>()=>Dv(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 Uk=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(Uk,{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 Lv=[Fk,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,Uk].flat(),Bv=[$k,qk,Kk,_k,jk,zk].flat(),Pv=[Rk,Ok,Lk,Dk],Fv=z("IsMarkSelected",()=>t=>e=>{if(!t)return!1;let{doc:n,selection:r}=e;return n.rangeHasMark(r.from,r.to,t)}),zv=z("IsNoteSelected",()=>t=>e=>t?Wg(e,t).hasNode:!1),$v=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)}),_v=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}),Hv=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}),Wv=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}),jv=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}),Vv=[cf,mf,Wn,df,kf,wf,Vk,Hk,Wk,Af,Ef,Rf,Df,Of,Lf,Qu,of,tf,Bk,Pk,Fv,zv,$v,_v,Hv,Wv,jv],qv=[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 Kv=t=>!!t.children,Uv=t=>t.type==="html";function Jv(t,e){return n(t,0,null)[0];function n(r,i,o){if(Kv(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 Gv=["root","blockquote","listItem"],Hf=ht("remarkHTMLTransformer",()=>()=>t=>{Jv(t,(e,n,r)=>Uv(e)?(r&&Gv.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 Jk=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(Jk,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Gk=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(Gk,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var jf=ve(["table","code_block"],"hardbreakFilterNodes");E(jf,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var Xk=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(Xk,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var Yk=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(Yk,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var Qk=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(Qk,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Xv=[Gk,jf,Xk,Jk,zf,_f,$f,Hf,Wf,qa,Yk,Qk].flat(),Zk=[Lv,Bv,Pv,Vv,qv,Xv].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,Yv(t))}};function Yv(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);let e=Qv(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&&Zv(a,s,t),a}function Qv(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 Zv(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=eA(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function eA(t){if(t.colwidth)return t.colwidth.slice();let e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function eb(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 tb(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 tA(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 pb(t){let e=t.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:tA}};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=>eb(r,e)}],toDOM(r){return["td",tb(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>eb(r,e)}],toDOM(r){return["th",tb(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)||nA(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function nA(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 rA(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 hb(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 iA(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 oA(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 sA(this.$anchorCell.pos,this.$headCell.pos)}};he.prototype.visible=!1;_.jsonID("cell",he);var sA=class mb{constructor(e,n){this.anchor=e,this.head=n}map(e){return new mb(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 aA(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 lA({$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 cA({$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 uA(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&&lA(r)?o=P.create(i,r.from):r instanceof P&&cA(r)&&(o=P.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var fA=new ee("fix-tables");function gb(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)?gb(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function dA(t,e){let n,r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=pA(t,i,o,n))};return e?e.doc!=t.doc&&gb(e.doc,t.doc,0,r):t.doc.descendants(r),n}function pA(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(fA,{fixTables:!0})}function yb(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 kb(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 bb(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 hA(e=>e.type.spec.tableRole==="table",t)}function hA(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 nb(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 rb(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 ib(t){return t[0].map((e,n)=>t.map(r=>r[n]))}function mA(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=nb(r,i))===null||e===void 0?void 0:e.indexes,u=(n=nb(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=gA(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 gA(t,e,n,r){let i=ib(yb(t));return i=bb(i,e,n,r),i=ib(i),kb(t,i)}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=rb(r,i))===null||e===void 0?void 0:e.indexes,u=(n=rb(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(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 kA(t,e,n,r){let i=yb(t);return i=bb(i,e,n,r),kb(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 xb(t,{map:e,tableStart:n,table:r},i){let o=i>0?-1:0;oA(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,iA(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 wb(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(xb(t.tr,n,n.left))}return!0}function Za(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(xb(t.tr,n,n.right))}return!0}function bA(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;bA(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 xA(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 wA(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;xA(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(wA(t.tr,n,n.bottom))}return!0}function CA(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;CA(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 Cb(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 SA(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 ob(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?SA(t):function(n,r){if(!Re(n))return!1;if(r){let i=Ze(n.schema),o=vt(n),s=n.tr,a=ob("row",o,i),l=ob("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 iW=Qf("row",{useDeprecatedLogic:!0}),oW=Qf("column",{useDeprecatedLogic:!0}),sW=Qf("cell",{useDeprecatedLogic:!0});function MA(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=MA(Qa(e),t);if(r==null)return!1;if(n){let i=e.doc.resolve(r);n(e.tr.setSelection(P.between(i,rA(i))).scrollIntoView())}return!0}}function Sb(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 Mb(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 Eb(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return mA({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function EA(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 TA(s,a)}function TA(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 vA({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 AA(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 sb(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 ab(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 lb(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}AA(f,s,o,n,c,u,d)&&p(),sb(f,s,o,n,l,c,a,d)&&p(),sb(f,s,o,n,l,c,u,d)&&p(),ab(f,s,o,n,a,u,l,d)&&p(),ab(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 IA=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=Tb(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=hb(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=Tb(i,t,e);if(l==null)return!1;s=new he(n.doc.resolve(l))}let a=hb(s.$headCell,t,e);return a?Xa(n,r,new he(s.$anchorCell,a)):!1}}function NA(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 RA(t,e,n){if(!Re(t.state))return!1;let r=EA(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=vA(r,a.right-a.left,a.bottom-a.top),lb(t.state,t.dispatch,s,a,r),!0}else if(r){let o=Qa(t.state),s=o.start(-1);return lb(t.state,t.dispatch,s,oe.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function OA(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;let r=cb(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(cb(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 Tb(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 cb(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 DA=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 vb({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=DA,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 LA(-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)=>{BA(s,a,t,i)},mouseleave:s=>{PA(s)},mousedown:(s,a)=>{FA(s,a,e,n)}},decorations:s=>{let a=mt.getState(s);if(a&&a.activeHandle>-1)return WA(s,a.activeHandle)},nodeViews:{}}});return o}var LA=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 BA(t,e,n,r){if(!t.editable)return;let i=mt.getState(t.state);if(i&&!i.dragging){let o=$A(e.target),s=-1;if(o){let{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=n?s=ub(t,e,"left",n):l-e.clientX<=n&&(s=ub(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}Ab(t,s)}}}function PA(t){if(!t.editable)return;let e=mt.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Ab(t,-1)}function FA(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=zA(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&&(_A(t,d.activeHandle,fb(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=fb(d.dragging,f,n);db(t,d.activeHandle,p,r)}}return db(t,s.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),e.preventDefault(),!0}function zA(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 $A(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function ub(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 fb(t,e,n){let r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function Ab(t,e){t.dispatch(t.state.tr.setMeta(mt,{setHandle:e}))}function _A(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():HA(d.colspan);h[p]=n,l.setNodeMarkup(s+f,null,{...d,colwidth:h})}l.docChanged&&t.dispatch(l)}function db(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 HA(t){return Array(t).fill(0)}function WA(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 Ib({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:aA,handleDOMEvents:{mousedown:OA},createSelectionBetween(e){return Vn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:NA,handleKeyDown:IA,handlePaste:RA},appendTransaction(e,n,r){return uA(r,dA(r,n),t)}})}var nl=typeof navigator<"u"?navigator:null,ed=nl&&nl.userAgent||"",jA=/Edge\/(\d+)/.exec(ed),VA=/MSIE \d/.exec(ed),qA=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ed),KA=!!(VA||qA||jA),UA=!KA&&!!nl&&/Apple Computer/.test(nl.vendor),Nb=new ee("safari-ime-span"),Zf=!1,JA={key:Nb,props:{decorations:GA,handleDOMEvents:{compositionstart:()=>{Zf=!0},compositionend:()=>{Zf=!1}}}};function GA(t){let{$from:e,$to:n,to:r}=t.selection;if(Zf&&e.sameParent(n)){let i=le.widget(r,XA,{ignoreSelection:!0,key:"safari-ime-span"});return ae.create(t.doc,[i])}}function XA(t){let e=t.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var Rb=new X(UA?JA:{key:Nb});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=YA(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 YA(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([QA(i[0]),ZA(i[1])])}return e}function QA(t){return typeof t=="string"?new RegExp(nd(t),"g"):t}function ZA(t){return typeof t=="function"?t:function(){return t}}var id="phrasing",od=["autolink","link","image","label"];function ad(){return{transforms:[oI],enter:{literalAutolink:eI,literalAutolinkEmail:sd,literalAutolinkHttp:sd,literalAutolinkWww:sd},exit:{literalAutolink:iI,literalAutolinkEmail:rI,literalAutolinkHttp:tI,literalAutolinkWww:nI}}}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 eI(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function sd(t){this.config.enter.autolinkProtocol.call(this,t)}function tI(t){this.config.exit.autolinkProtocol.call(this,t)}function nI(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 rI(t){this.config.exit.autolinkEmail.call(this,t)}function iI(t){this.exit(t)}function oI(t){rd(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,sI],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,aI]],{ignore:["link","linkReference"]})}function sI(t,e,n,r,i){let o="";if(!Ob(i)||(/^w/i.test(e)&&(n=e+n,e="",o="http://"),!lI(n)))return!1;let s=cI(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 aI(t,e,n,r){return!Ob(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function lI(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 cI(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 Ob(t,e){let n=t.input.charCodeAt(t.index-1);return(t.index===0||Ht(n)||tr(n))&&(!e||n!==47)}Db.peek=kI;function uI(){this.buffer()}function fI(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function dI(){this.buffer()}function pI(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function hI(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 mI(t){this.exit(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(){return"["}function Db(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:uI,gfmFootnoteCall:fI,gfmFootnoteDefinitionLabelString:dI,gfmFootnoteDefinition:pI},exit:{gfmFootnoteCallString:hI,gfmFootnoteCall:mI,gfmFootnoteDefinitionLabelString:gI,gfmFootnoteDefinition:yI}}}function ud(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:Db},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?` +`):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 Vk=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(Vk,{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 qk=ge(t=>ha(/^\s*([-+*])\s$/,Oi.type(t)));E(qk,{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 Kk=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(Kk,{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=>()=>Ak(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=>()=>vk(Vt.type(t)));E(Df,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Dv(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=>()=>Dv(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 Uk=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(Uk,{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 Lv=[Fk,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,Uk].flat(),Bv=[$k,qk,Kk,_k,jk,zk].flat(),Pv=[Rk,Ok,Lk,Dk],Fv=z("IsMarkSelected",()=>t=>e=>{if(!t)return!1;let{doc:n,selection:r}=e;return n.rangeHasMark(r.from,r.to,t)}),zv=z("IsNoteSelected",()=>t=>e=>t?Wg(e,t).hasNode:!1),$v=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)}),_v=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}),Hv=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}),Wv=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}),jv=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}),Vv=[cf,mf,Wn,df,kf,wf,Vk,Hk,Wk,Af,Ef,Rf,Df,Of,Lf,Qu,of,tf,Bk,Pk,Fv,zv,$v,_v,Hv,Wv,jv],qv=[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 Kv=t=>!!t.children,Uv=t=>t.type==="html";function Jv(t,e){return n(t,0,null)[0];function n(r,i,o){if(Kv(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 Gv=["root","blockquote","listItem"],Hf=ht("remarkHTMLTransformer",()=>()=>t=>{Jv(t,(e,n,r)=>Uv(e)?(r&&Gv.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 Jk=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(Jk,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Gk=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(Gk,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var jf=ve(["table","code_block"],"hardbreakFilterNodes");E(jf,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var Xk=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(Xk,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var Yk=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(Yk,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var Qk=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(Qk,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Xv=[Gk,jf,Xk,Jk,zf,_f,$f,Hf,Wf,qa,Yk,Qk].flat(),Zk=[Lv,Bv,Pv,Vv,qv,Xv].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,Yv(t))}};function Yv(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);let e=Qv(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&&Zv(a,s,t),a}function Qv(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 Zv(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=eA(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:o,colwidth:a})}}function eA(t){if(t.colwidth)return t.colwidth.slice();let e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function eb(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 tb(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 tA(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 pb(t){let e=t.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:tA}};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=>eb(r,e)}],toDOM(r){return["td",tb(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>eb(r,e)}],toDOM(r){return["th",tb(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)||nA(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function nA(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 rA(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 hb(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 iA(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 oA(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 sA(this.$anchorCell.pos,this.$headCell.pos)}};he.prototype.visible=!1;_.jsonID("cell",he);var sA=class mb{constructor(e,n){this.anchor=e,this.head=n}map(e){return new mb(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 aA(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 lA({$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 cA({$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 uA(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&&lA(r)?o=P.create(i,r.from):r instanceof P&&cA(r)&&(o=P.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var fA=new ee("fix-tables");function gb(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)?gb(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function dA(t,e){let n,r=(i,o)=>{i.type.spec.tableRole=="table"&&(n=pA(t,i,o,n))};return e?e.doc!=t.doc&&gb(e.doc,t.doc,0,r):t.doc.descendants(r),n}function pA(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(fA,{fixTables:!0})}function yb(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 kb(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 bb(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 hA(e=>e.type.spec.tableRole==="table",t)}function hA(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 nb(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 rb(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 ib(t){return t[0].map((e,n)=>t.map(r=>r[n]))}function mA(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=nb(r,i))===null||e===void 0?void 0:e.indexes,u=(n=nb(r,o))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(o))return!1;let f=gA(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 gA(t,e,n,r){let i=ib(yb(t));return i=bb(i,e,n,r),i=ib(i),kb(t,i)}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=rb(r,i))===null||e===void 0?void 0:e.indexes,u=(n=rb(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(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 kA(t,e,n,r){let i=yb(t);return i=bb(i,e,n,r),kb(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 xb(t,{map:e,tableStart:n,table:r},i){let o=i>0?-1:0;oA(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,iA(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 wb(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(xb(t.tr,n,n.left))}return!0}function Za(t,e){if(!Re(t))return!1;if(e){let n=vt(t);e(xb(t.tr,n,n.right))}return!0}function bA(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;bA(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 xA(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 wA(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;xA(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(wA(t.tr,n,n.bottom))}return!0}function CA(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;CA(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 Cb(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 SA(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 ob(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?SA(t):function(n,r){if(!Re(n))return!1;if(r){let i=Ze(n.schema),o=vt(n),s=n.tr,a=ob("row",o,i),l=ob("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 MA(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=MA(Qa(e),t);if(r==null)return!1;if(n){let i=e.doc.resolve(r);n(e.tr.setSelection(P.between(i,rA(i))).scrollIntoView())}return!0}}function Sb(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 Mb(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 Eb(t){return(e,n)=>{let{from:r,to:i,select:o=!0,pos:s=e.selection.from}=t,a=e.tr;return mA({tr:a,originIndex:r,targetIndex:i,select:o,pos:s})?(n?.(a),!0):!1}}function EA(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 TA(s,a)}function TA(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 vA({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 AA(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 sb(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 ab(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 lb(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}AA(f,s,o,n,c,u,d)&&p(),sb(f,s,o,n,l,c,a,d)&&p(),sb(f,s,o,n,l,c,u,d)&&p(),ab(f,s,o,n,a,u,l,d)&&p(),ab(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 IA=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=Tb(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=hb(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=Tb(i,t,e);if(l==null)return!1;s=new he(n.doc.resolve(l))}let a=hb(s.$headCell,t,e);return a?Xa(n,r,new he(s.$anchorCell,a)):!1}}function NA(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 RA(t,e,n){if(!Re(t.state))return!1;let r=EA(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=vA(r,a.right-a.left,a.bottom-a.top),lb(t.state,t.dispatch,s,a,r),!0}else if(r){let o=Qa(t.state),s=o.start(-1);return lb(t.state,t.dispatch,s,oe.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function OA(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;let r=cb(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(cb(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 Tb(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 cb(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 DA=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 vb({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=DA,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 LA(-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)=>{BA(s,a,t,i)},mouseleave:s=>{PA(s)},mousedown:(s,a)=>{FA(s,a,e,n)}},decorations:s=>{let a=mt.getState(s);if(a&&a.activeHandle>-1)return WA(s,a.activeHandle)},nodeViews:{}}});return o}var LA=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 BA(t,e,n,r){if(!t.editable)return;let i=mt.getState(t.state);if(i&&!i.dragging){let o=$A(e.target),s=-1;if(o){let{left:a,right:l}=o.getBoundingClientRect();e.clientX-a<=n?s=ub(t,e,"left",n):l-e.clientX<=n&&(s=ub(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}Ab(t,s)}}}function PA(t){if(!t.editable)return;let e=mt.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Ab(t,-1)}function FA(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=zA(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&&(_A(t,d.activeHandle,fb(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=fb(d.dragging,f,n);db(t,d.activeHandle,p,r)}}return db(t,s.activeHandle,l,r),o.addEventListener("mouseup",c),o.addEventListener("mousemove",u),e.preventDefault(),!0}function zA(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 $A(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function ub(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 fb(t,e,n){let r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function Ab(t,e){t.dispatch(t.state.tr.setMeta(mt,{setHandle:e}))}function _A(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():HA(d.colspan);h[p]=n,l.setNodeMarkup(s+f,null,{...d,colwidth:h})}l.docChanged&&t.dispatch(l)}function db(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 HA(t){return Array(t).fill(0)}function WA(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 Ib({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:aA,handleDOMEvents:{mousedown:OA},createSelectionBetween(e){return Vn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:NA,handleKeyDown:IA,handlePaste:RA},appendTransaction(e,n,r){return uA(r,dA(r,n),t)}})}var nl=typeof navigator<"u"?navigator:null,ed=nl&&nl.userAgent||"",jA=/Edge\/(\d+)/.exec(ed),VA=/MSIE \d/.exec(ed),qA=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ed),KA=!!(VA||qA||jA),UA=!KA&&!!nl&&/Apple Computer/.test(nl.vendor),Nb=new ee("safari-ime-span"),Zf=!1,JA={key:Nb,props:{decorations:GA,handleDOMEvents:{compositionstart:()=>{Zf=!0},compositionend:()=>{Zf=!1}}}};function GA(t){let{$from:e,$to:n,to:r}=t.selection;if(Zf&&e.sameParent(n)){let i=le.widget(r,XA,{ignoreSelection:!0,key:"safari-ime-span"});return ae.create(t.doc,[i])}}function XA(t){let e=t.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var Rb=new X(UA?JA:{key:Nb});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=YA(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 YA(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([QA(i[0]),ZA(i[1])])}return e}function QA(t){return typeof t=="string"?new RegExp(nd(t),"g"):t}function ZA(t){return typeof t=="function"?t:function(){return t}}var id="phrasing",od=["autolink","link","image","label"];function ad(){return{transforms:[oI],enter:{literalAutolink:eI,literalAutolinkEmail:sd,literalAutolinkHttp:sd,literalAutolinkWww:sd},exit:{literalAutolink:iI,literalAutolinkEmail:rI,literalAutolinkHttp:tI,literalAutolinkWww:nI}}}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 eI(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function sd(t){this.config.enter.autolinkProtocol.call(this,t)}function tI(t){this.config.exit.autolinkProtocol.call(this,t)}function nI(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 rI(t){this.config.exit.autolinkEmail.call(this,t)}function iI(t){this.exit(t)}function oI(t){rd(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,sI],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,aI]],{ignore:["link","linkReference"]})}function sI(t,e,n,r,i){let o="";if(!Ob(i)||(/^w/i.test(e)&&(n=e+n,e="",o="http://"),!lI(n)))return!1;let s=cI(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 aI(t,e,n,r){return!Ob(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function lI(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 cI(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 Ob(t,e){let n=t.input.charCodeAt(t.index-1);return(t.index===0||Ht(n)||tr(n))&&(!e||n!==47)}Db.peek=kI;function uI(){this.buffer()}function fI(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function dI(){this.buffer()}function pI(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function hI(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 mI(t){this.exit(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(){return"["}function Db(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:uI,gfmFootnoteCall:fI,gfmFootnoteDefinitionLabelString:dI,gfmFootnoteDefinition:pI},exit:{gfmFootnoteCallString:hI,gfmFootnoteCall:mI,gfmFootnoteDefinitionLabelString:gI,gfmFootnoteDefinition:yI}}}function ud(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:Db},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?Lb:bI))),c(),l}}function bI(t,e,n){return e===0?t:Lb(t,e,n)}function Lb(t,e,n){return(n?"":" ")+t}var xI=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Bb.peek=SI;function fd(){return{canContainEols:["delete"],enter:{strikethrough:wI},exit:{strikethrough:CI}}}function dd(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:xI}],handlers:{delete:Bb}}}function wI(t){this.enter({type:"delete",children:[]},t)}function CI(t){this.exit(t)}function Bb(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 SI(){return"~"}function MI(t){return t.length}function Fb(t,e){let n=e||{},r=(n.align||[]).concat(),i=n.stringLength||MI,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=EI(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]=Pb(r[f]);else{let m=Pb(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 EI(t){return t==null?"":String(t)}function Pb(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:TI,tableData:zb,tableHeader:zb,tableRow:AI},exit:{codeText:II,table:vI,tableData:pd,tableHeader:pd,tableRow:pd}}}function TI(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 vI(t){this.exit(t),this.data.inTable=void 0}function AI(t){this.enter({type:"tableRow",children:[]},t)}function pd(t){this.exit(t)}function zb(t){this.enter({type:"tableCell",children:[]},t)}function II(t){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,NI));let n=this.stack[this.stack.length-1];n.type,n.value=e,this.exit(t)}function NI(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 Fb(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:$b,taskListCheckValueUnchecked:$b,paragraph:RI}}}function yd(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:OI}}}function $b(t){let e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function RI(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 OI(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 DI={tokenize:zI,partial:!0},_b={tokenize:$I,partial:!0},Hb={tokenize:_I,partial:!0},Wb={tokenize:HI,partial:!0},LI={tokenize:WI,partial:!0},jb={name:"wwwAutolink",tokenize:PI,previous:qb},Vb={name:"protocolAutolink",tokenize:FI,previous:Kb},kn={name:"emailAutolink",tokenize:BI,previous:Ub},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,Vb];qt[104]=[kn,Vb];qt[87]=[kn,jb];qt[119]=[kn,jb];function BI(t,e,n){let r=this,i,o;return s;function s(f){return!xd(f)||!Ub.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(LI,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 PI(t,e,n){let r=this;return i;function i(s){return s!==87&&s!==119||!qb.call(r,r.previous)||Cd(r.events)?n(s):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(DI,t.attempt(_b,t.attempt(Hb,o),n),n)(s))}function o(s){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(s)}}function FI(t,e,n){let r=this,i="",o=!1;return s;function s(f){return(f===72||f===104)&&Kb.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(_b,t.attempt(Hb,u),n)(f)}function u(f){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(f)}}function zI(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 $I(t,e,n){let r,i,o;return s;function s(c){return c===46||c===95?t.check(Wb,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 _I(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(Wb,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 HI(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 WI(t,e,n){return r;function r(o){return t.consume(o),i}function i(o){return Te(o)?n(o):e(o)}}function qb(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||Z(t)}function Kb(t){return!Ee(t)}function Ub(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 jI={tokenize:XI,partial:!0};function Sd(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:UI,continuation:{tokenize:JI},exit:GI}},text:{91:{name:"gfmFootnoteCall",tokenize:KI},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:VI,resolveTo:qI}}}}function VI(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 qI(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 KI(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 UI(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 JI(t,e,n){return t.check(Wt,e,t.attempt(jI,e,n))}function GI(t){t.exit("gfmFootnoteDefinition")}function XI(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){YI(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 YI(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 Jb(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:QI,resolveAll:ZI}}}}function QI(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 ZI(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&&(Gb(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&&Gb(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=Jb(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 Gb(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 eN={name:"tasklistCheck",tokenize:tN};function Td(){return{text:{91:eN}}}function tN(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:nN},e,n)(l):n(l)}}function nN(t,e,n){return $(t,r,"whitespace");function r(i){return i===null?n(i):e(i)}}function Xb(t){return Os([wd(),Sd(),Md(t),Ed(),Td()])}var rN={};function ol(t){let e=this,n=t||rN,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Xb(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 Qb=ge(t=>an(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,Yo.type(t)));q(Qb,{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=pb({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 Zb(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 ex(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 iN=ex("row"),oN=ex("col");function tx(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 sN(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 aN(t){let e=sN(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=zg(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 nx=z("InsertTable",t=>({row:e,col:n}={})=>(r,i)=>{let{selection:o,tr:s}=r,{from:a}=o,l=Zb(t,e,n),c=s.replaceSelectionWith(l),u=_.findFrom(c.doc.resolve(a),1,!0);return u&&c.setSelection(u),i?.(c),!0});q(nx,{displayName:"Command<insertTableCommand>",group:"Table"});var rx=z("MoveRow",()=>({from:t,to:e,pos:n}={})=>Mb({from:t??0,to:e??0,pos:n}));q(rx,{displayName:"Command<moveRowCommand>",group:"Table"});var ix=z("MoveCol",()=>({from:t,to:e,pos:n}={})=>Eb({from:t??0,to:e??0,pos:n}));q(ix,{displayName:"Command<moveColCommand>",group:"Table"});var ox=z("SelectRow",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(iN(t.index,t.pos)(r))});q(ox,{displayName:"Command<selectRowCommand>",group:"Table"});var sx=z("SelectCol",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(oN(t.index,t.pos)(r))});q(sx,{displayName:"Command<selectColCommand>",group:"Table"});var ax=z("SelectTable",()=>()=>(t,e)=>{let{tr:n}=t;return!!e?.(aN(n))});q(ax,{displayName:"Command<selectTableCommand>",group:"Table"});var lx=z("DeleteSelectedCells",()=>()=>(t,e)=>{let{selection:n}=t;if(!(n instanceof he))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?Sb(t,e):i?el(t,e):tl(t,e)});q(lx,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var cx=z("AddColBefore",()=>()=>wb);q(cx,{displayName:"Command<addColBeforeCommand>",group:"Table"});var ux=z("AddColAfter",()=>()=>Za);q(ux,{displayName:"Command<addColAfterCommand>",group:"Table"});var fx=z("AddRowBefore",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(tx(t,e.tr,r,r.top))}return!0});q(fx,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var dx=z("AddRowAfter",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(tx(t,e.tr,r,r.bottom))}return!0});q(dx,{displayName:"Command<addRowAfterCommand>",group:"Table"});var px=z("SetAlign",()=>(t="left")=>Cb("alignment",t));q(px,{displayName:"Command<setAlignCommand>",group:"Table"});var hx=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=Zb(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(hx,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var mx=Mk(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(mx,{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",Yb="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===Yb,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(Yb,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 gx=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(gx,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var lN=[Rd,Bd].flat(),cN=[hx,gx],uN=[Qb],fN=[mx],yx=pe(()=>Rb);q(yx,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var dN=pe(()=>vb({}));q(dN,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var kx=pe(()=>Ib({allowTableNodeSelection:!0}));q(kx,{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 pN=new ee("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function hN(t,e){let n=0;return e.forEach((r,i,o)=>{r===t&&(n=o)}),n}var bx=pe(()=>new X({key:pN,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=hN(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(bx,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var mN=[bx,yx,$d,kx].flat(),gN=[zd,bn,Zo,_i,$i,es,Pd,Fd,Id,Yo].flat(),yN=[Dd,Od,Ld,nx,rx,ix,ox,sx,ax,lx,fx,dx,cx,ux,px,Nd],xx=[gN,cN,fN,uN,lN,yN,mN].flat();var kN=typeof global=="object"&&global&&global.Object===Object&&global,wx=kN;var bN=typeof self=="object"&&self&&self.Object===Object&&self,xN=wx||bN||Function("return this")(),sl=xN;var wN=sl.Symbol,Hi=wN;var Cx=Object.prototype,CN=Cx.hasOwnProperty,SN=Cx.toString,ts=Hi?Hi.toStringTag:void 0;function MN(t){var e=CN.call(t,ts),n=t[ts];try{t[ts]=void 0;var r=!0}catch{}var i=SN.call(t);return r&&(e?t[ts]=n:delete t[ts]),i}var Sx=MN;var EN=Object.prototype,TN=EN.toString;function vN(t){return TN.call(t)}var Mx=vN;var AN="[object Null]",IN="[object Undefined]",Ex=Hi?Hi.toStringTag:void 0;function NN(t){return t==null?t===void 0?IN:AN:Ex&&Ex in Object(t)?Sx(t):Mx(t)}var Tx=NN;function RN(t){return t!=null&&typeof t=="object"}var vx=RN;var ON="[object Symbol]";function DN(t){return typeof t=="symbol"||vx(t)&&Tx(t)==ON}var Ax=DN;var LN=/\s/;function BN(t){for(var e=t.length;e--&&LN.test(t.charAt(e)););return e}var Ix=BN;var PN=/^\s+/;function FN(t){return t&&t.slice(0,Ix(t)+1).replace(PN,"")}var Nx=FN;function zN(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var ns=zN;var Rx=NaN,$N=/^[-+]0x[0-9a-f]+$/i,_N=/^0b[01]+$/i,HN=/^0o[0-7]+$/i,WN=parseInt;function jN(t){if(typeof t=="number")return t;if(Ax(t))return Rx;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=Nx(t);var n=_N.test(t);return n||HN.test(t)?WN(t.slice(2),n?2:8):$N.test(t)?Rx:+t}var _d=jN;var VN=function(){return sl.Date.now()},al=VN;var qN="Expected a function",KN=Math.max,UN=Math.min;function JN(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(qN);e=_d(e)||0,ns(n)&&(u=!!n.leading,f="maxWait"in n,o=f?KN(_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?UN(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=JN;var Ox=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 Ox,"listener"),GN=new ee("MILKDOWN_LISTENER"),Hd=t=>(t.inject(ll,new Ox),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:GN,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 XN(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 Dx(e):We.empty};var Dx=(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 Dx([]);var XN=(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 YN=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>ZN&&(a=QN(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()>YN&&(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 QN(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}},ZN=20;function eR(t,e,n,r){let i=n.getMeta(Fr),o;if(i)return i.historyState;n.getMeta(Px)&&(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,Lx(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||!tR(n,t.prevRanges)),c=s?jd(t.prevRanges,n.mapping):Lx(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 tR(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 Lx(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 nR(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,Bx=null;function ul(t){let e=t.plugins;if(Bx!=e){Vd=!1,Bx=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(Px,!0)}var Fr=new ee("history"),Px=new ee("closeHistory");function Fx(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 eR(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=nR(i,n,t);o&&r(e?o.scrollIntoView():o)}return!0}}var ss=fl(!1,!0),as=fl(!0,!0),JV=fl(!1,!1),GV=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 zx=pe(t=>Fx(t.get(Ud.key)));Wi(zx,{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 $x=[Ud,zx,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 rR(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-clipboard",...e}}),t}function _x(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=$g("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,` +`))}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 Fb(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:$b,taskListCheckValueUnchecked:$b,paragraph:RI}}}function yd(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:OI}}}function $b(t){let e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function RI(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 OI(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 DI={tokenize:zI,partial:!0},_b={tokenize:$I,partial:!0},Hb={tokenize:_I,partial:!0},Wb={tokenize:HI,partial:!0},LI={tokenize:WI,partial:!0},jb={name:"wwwAutolink",tokenize:PI,previous:qb},Vb={name:"protocolAutolink",tokenize:FI,previous:Kb},kn={name:"emailAutolink",tokenize:BI,previous:Ub},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,Vb];qt[104]=[kn,Vb];qt[87]=[kn,jb];qt[119]=[kn,jb];function BI(t,e,n){let r=this,i,o;return s;function s(f){return!xd(f)||!Ub.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(LI,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 PI(t,e,n){let r=this;return i;function i(s){return s!==87&&s!==119||!qb.call(r,r.previous)||Cd(r.events)?n(s):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(DI,t.attempt(_b,t.attempt(Hb,o),n),n)(s))}function o(s){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(s)}}function FI(t,e,n){let r=this,i="",o=!1;return s;function s(f){return(f===72||f===104)&&Kb.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(_b,t.attempt(Hb,u),n)(f)}function u(f){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(f)}}function zI(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 $I(t,e,n){let r,i,o;return s;function s(c){return c===46||c===95?t.check(Wb,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 _I(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(Wb,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 HI(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 WI(t,e,n){return r;function r(o){return t.consume(o),i}function i(o){return Te(o)?n(o):e(o)}}function qb(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||Z(t)}function Kb(t){return!Ee(t)}function Ub(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 jI={tokenize:XI,partial:!0};function Sd(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:UI,continuation:{tokenize:JI},exit:GI}},text:{91:{name:"gfmFootnoteCall",tokenize:KI},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:VI,resolveTo:qI}}}}function VI(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 qI(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 KI(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 UI(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 JI(t,e,n){return t.check(Wt,e,t.attempt(jI,e,n))}function GI(t){t.exit("gfmFootnoteDefinition")}function XI(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){YI(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 YI(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 Jb(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:QI,resolveAll:ZI}}}}function QI(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 ZI(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&&(Gb(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&&Gb(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=Jb(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 Gb(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 eN={name:"tasklistCheck",tokenize:tN};function Td(){return{text:{91:eN}}}function tN(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:nN},e,n)(l):n(l)}}function nN(t,e,n){return $(t,r,"whitespace");function r(i){return i===null?n(i):e(i)}}function Xb(t){return Os([wd(),Sd(),Md(t),Ed(),Td()])}var rN={};function ol(t){let e=this,n=t||rN,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Xb(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 Qb=ge(t=>an(/(?<![\w:/])(~{1,2})(.+?)\1(?!\w|\/)/,Yo.type(t)));q(Qb,{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=pb({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 Zb(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 ex(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 iN=ex("row"),oN=ex("col");function tx(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 sN(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 aN(t){let e=sN(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=zg(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 nx=z("InsertTable",t=>({row:e,col:n}={})=>(r,i)=>{let{selection:o,tr:s}=r,{from:a}=o,l=Zb(t,e,n),c=s.replaceSelectionWith(l),u=_.findFrom(c.doc.resolve(a),1,!0);return u&&c.setSelection(u),i?.(c),!0});q(nx,{displayName:"Command<insertTableCommand>",group:"Table"});var rx=z("MoveRow",()=>({from:t,to:e,pos:n}={})=>Mb({from:t??0,to:e??0,pos:n}));q(rx,{displayName:"Command<moveRowCommand>",group:"Table"});var ix=z("MoveCol",()=>({from:t,to:e,pos:n}={})=>Eb({from:t??0,to:e??0,pos:n}));q(ix,{displayName:"Command<moveColCommand>",group:"Table"});var ox=z("SelectRow",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(iN(t.index,t.pos)(r))});q(ox,{displayName:"Command<selectRowCommand>",group:"Table"});var sx=z("SelectCol",()=>(t={index:0})=>(e,n)=>{let{tr:r}=e;return!!n?.(oN(t.index,t.pos)(r))});q(sx,{displayName:"Command<selectColCommand>",group:"Table"});var ax=z("SelectTable",()=>()=>(t,e)=>{let{tr:n}=t;return!!e?.(aN(n))});q(ax,{displayName:"Command<selectTableCommand>",group:"Table"});var lx=z("DeleteSelectedCells",()=>()=>(t,e)=>{let{selection:n}=t;if(!(n instanceof he))return!1;let r=n.isRowSelection(),i=n.isColSelection();return r&&i?Sb(t,e):i?el(t,e):tl(t,e)});q(lx,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var cx=z("AddColBefore",()=>()=>wb);q(cx,{displayName:"Command<addColBeforeCommand>",group:"Table"});var ux=z("AddColAfter",()=>()=>Za);q(ux,{displayName:"Command<addColAfterCommand>",group:"Table"});var fx=z("AddRowBefore",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(tx(t,e.tr,r,r.top))}return!0});q(fx,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var dx=z("AddRowAfter",t=>()=>(e,n)=>{if(!Re(e))return!1;if(n){let r=vt(e);n(tx(t,e.tr,r,r.bottom))}return!0});q(dx,{displayName:"Command<addRowAfterCommand>",group:"Table"});var px=z("SetAlign",()=>(t="left")=>Cb("alignment",t));q(px,{displayName:"Command<setAlignCommand>",group:"Table"});var hx=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=Zb(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(hx,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var mx=Mk(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(mx,{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",Yb="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===Yb,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(Yb,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 gx=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(gx,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var lN=[Rd,Bd].flat(),cN=[hx,gx],uN=[Qb],fN=[mx],yx=pe(()=>Rb);q(yx,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var dN=pe(()=>vb({}));q(dN,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var kx=pe(()=>Ib({allowTableNodeSelection:!0}));q(kx,{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 pN=new ee("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function hN(t,e){let n=0;return e.forEach((r,i,o)=>{r===t&&(n=o)}),n}var bx=pe(()=>new X({key:pN,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=hN(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(bx,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var mN=[bx,yx,$d,kx].flat(),gN=[zd,bn,Zo,_i,$i,es,Pd,Fd,Id,Yo].flat(),yN=[Dd,Od,Ld,nx,rx,ix,ox,sx,ax,lx,fx,dx,cx,ux,px,Nd],xx=[gN,cN,fN,uN,lN,yN,mN].flat();var kN=typeof global=="object"&&global&&global.Object===Object&&global,wx=kN;var bN=typeof self=="object"&&self&&self.Object===Object&&self,xN=wx||bN||Function("return this")(),sl=xN;var wN=sl.Symbol,Hi=wN;var Cx=Object.prototype,CN=Cx.hasOwnProperty,SN=Cx.toString,ts=Hi?Hi.toStringTag:void 0;function MN(t){var e=CN.call(t,ts),n=t[ts];try{t[ts]=void 0;var r=!0}catch{}var i=SN.call(t);return r&&(e?t[ts]=n:delete t[ts]),i}var Sx=MN;var EN=Object.prototype,TN=EN.toString;function vN(t){return TN.call(t)}var Mx=vN;var AN="[object Null]",IN="[object Undefined]",Ex=Hi?Hi.toStringTag:void 0;function NN(t){return t==null?t===void 0?IN:AN:Ex&&Ex in Object(t)?Sx(t):Mx(t)}var Tx=NN;function RN(t){return t!=null&&typeof t=="object"}var vx=RN;var ON="[object Symbol]";function DN(t){return typeof t=="symbol"||vx(t)&&Tx(t)==ON}var Ax=DN;var LN=/\s/;function BN(t){for(var e=t.length;e--&&LN.test(t.charAt(e)););return e}var Ix=BN;var PN=/^\s+/;function FN(t){return t&&t.slice(0,Ix(t)+1).replace(PN,"")}var Nx=FN;function zN(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var ns=zN;var Rx=NaN,$N=/^[-+]0x[0-9a-f]+$/i,_N=/^0b[01]+$/i,HN=/^0o[0-7]+$/i,WN=parseInt;function jN(t){if(typeof t=="number")return t;if(Ax(t))return Rx;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=Nx(t);var n=_N.test(t);return n||HN.test(t)?WN(t.slice(2),n?2:8):$N.test(t)?Rx:+t}var _d=jN;var VN=function(){return sl.Date.now()},al=VN;var qN="Expected a function",KN=Math.max,UN=Math.min;function JN(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(qN);e=_d(e)||0,ns(n)&&(u=!!n.leading,f="maxWait"in n,o=f?KN(_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?UN(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=JN;var Ox=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 Ox,"listener"),GN=new ee("MILKDOWN_LISTENER"),Hd=t=>(t.inject(ll,new Ox),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:GN,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 XN(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 Dx(e):We.empty};var Dx=(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 Dx([]);var XN=(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 YN=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>ZN&&(a=QN(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()>YN&&(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 QN(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}},ZN=20;function eR(t,e,n,r){let i=n.getMeta(Fr),o;if(i)return i.historyState;n.getMeta(Px)&&(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,Lx(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||!tR(n,t.prevRanges)),c=s?jd(t.prevRanges,n.mapping):Lx(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 tR(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 Lx(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 nR(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,Bx=null;function ul(t){let e=t.plugins;if(Bx!=e){Vd=!1,Bx=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(Px,!0)}var Fr=new ee("history"),Px=new ee("closeHistory");function Fx(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 eR(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=nR(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 zx=pe(t=>Fx(t.get(Ud.key)));Wi(zx,{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 $x=[Ud,zx,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 rR(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-clipboard",...e}}),t}function _x(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=$g("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 _x(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 _x(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):""}}})});rR(Xd,{displayName:"Prose<clipboard>"});function iR(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=>-iR(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 oR=5e3;function sR(t,e){return Math.min(15,Math.max(2,Math.floor(Math.max(t,e)/10)))}function Vx(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(oR,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=sR(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}},aR;try{aR=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=Vx(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&&lR(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&&cR(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=Vx;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 Hx(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 lR(t){let e=Hx(t);if(!e)return null;let n=Hx(t.map(r=>r.invert()).reverse());return{fromA:n.from,toA:n.to,fromB:e.from,toB:e.to}}function cR(t,e,n){return n(t.fromB)==e.fromB&&n(t.toB)==e.toB&&Wx(t.deleted,e.deleted)&&Wx(t.inserted,e.inserted)}function Wx(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 qx=500;function uR(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 Gx(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("/"+Gx(s,e,n))});i.push("\\"+String(e.encodeNodeEnd(t)));let o=i.join("");return n.set(t,o),o}function Kx(t,e,n){let r=[],i=0;return t.content.forEach(o=>{r.push({node:o,offset:i,size:o.nodeSize,signature:Gx(o,n.encoder,n.sigCache)}),i+=o.nodeSize}),{node:t,contentStart:e,content:r}}function fR(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 dR(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 Xx(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 pR(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=>Xx(s,t.abs,e.abs))}function Ux(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 hR(t,e,n){return Jt.fromJSON({fromA:e,toA:e+t.size,fromB:n,toB:n,deleted:[{length:t.size,data:null}],inserted:[]})}function mR(t,e,n){return Jt.fromJSON({fromA:e,toA:e,fromB:n,toB:n+t.size,deleted:[],inserted:[{length:t.size,data:null}]})}function gR(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=>Xx(s,n,r))}function dl(t,e,n,r,i){if(t.childCount>qx||e.childCount>qx)return gR(t,e,n,r,i);let o=Kx(t,n,i),s=Kx(e,r,i),a=fR(o.content,s.content),l=[],c=0,u=0;for(let[f,d]of a)Jx(o,s,{oldStart:c,oldEnd:f,newStart:u,newEnd:d},i,l),c=f+1,u=d+1;return Jx(o,s,{oldStart:c,oldEnd:o.content.length,newStart:u,newEnd:s.content.length},i,l),l}function Jx(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(...yR(t,e,c,u,r)),a++,l++;continue}if(c&&(!u||!f)){let d=t.contentStart+c.offset;i.push(hR(c,d,Ux(e,l))),a++;continue}if(u){let d=e.contentStart+u.offset;i.push(mR(u,Ux(t,a),d)),l++}}}function yR(t,e,n,r,i){let o=t.contentStart+n.offset,s=e.contentStart+r.offset;return dR(n.node,r.node)&&kR(n.node,r.node,i.encoder)?dl(n.node,r.node,o+1,s+1,i):pR({node:n.node,parent:t.node,abs:o},{node:r.node,parent:e.node,abs:s},i)}function kR(t,e,n){return n.encodeNodeStart(t)===n.encodeNodeStart(e)}function bR(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=uR(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=bR(t,e,c,u,r);return dl(f.oldCut,f.newCut,f.cutAbsStart,f.cutAbsStart,i)}var Yx=ve({ignoreAttrs:{heading:["id"]}},"diffConfig");Gt(Yx,{displayName:"Ctx<diffConfig>",group:"Diff"});var Oe=new ee("MILKDOWN_DIFF");function xR(t,e,n){let r=ls(t,e.newDoc,n);return{...e,changes:r}}function wR(t,e){return e.some(n=>t.fromB<n.toB&&t.toB>n.fromB)}function pl(t){return t.changes.filter(e=>!wR(e,t.rejectedRanges))}var CR=pe(t=>{let e=t.get(Yx.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=xR(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(CR,{displayName:"Prose<diff>",group:"Diff"});function SR(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 MR=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(MR,{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 ER=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(ER,{displayName:"Command<acceptDiffChunk>",group:"Diff"});var TR=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(TR,{displayName:"Command<rejectDiffChunk>",group:"Diff"});var vR=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(vR,{displayName:"Command<acceptDiffRange>",group:"Diff"});var AR=z("RejectDiffRange",()=>t=>(e,n)=>!t||!Oe.getState(e)?!1:(n&&n(e.tr.setMeta(Oe,{type:"rejectRange",range:t})),!0));Gt(AR,{displayName:"Command<rejectDiffRange>",group:"Diff"});var IR=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):SR(t.tr,n)).setMeta(Oe,{type:"acceptAll"})),!0):!1});Gt(IR,{displayName:"Command<acceptAllDiffs>",group:"Diff"});var NR=z("ClearDiffReview",()=>()=>(t,e)=>Oe.getState(t)?(e&&e(t.tr.setMeta(Oe,{type:"clear"})),!0):!1);Gt(NR,{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 RR(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 OR(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 Qx(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 DR(t,e,n){let{insertPos:r,currentEndPos:i}=n,o=n.buffer.replace(/\r\n?/g,` @@ -69,28 +69,28 @@ $$`).replace(/\\hat\s+(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}").replace(/\\hat(?!\{) ${r}`:r};var Uw=["transactions","fullSerializations","bridgeMessages","bridgeBytes","decorationNodes","decorationCacheHits","katexRenders","mermaidRenders","imageScans","imageNodeUpdates","codeTokenizations","outlineReports"],Jw=()=>Object.fromEntries(Uw.map(t=>[t,0])),At=(t,e,n=1)=>{t&&(t[e]+=n)},Gw=t=>{if(t)for(let e of Uw)t[e]=0};var Xw=t=>JSON.stringify(t.map(({level:e,title:n})=>[e,n]));var DO=["loadDocument","requestSnapshot","setTheme","setLanguage","setEditable","focus","scrollToHeading","applyMarkdownFragment","replaceSelection","executeSelectionCommand","insertStructuredBlock","restoreCheckpoint"],Yw=t=>Number.isInteger(t)&&Number(t)>=0,pp=t=>typeof t=="string"&&t.length>0,Qw=t=>{if(!t||typeof t!="object")return null;let e=t;return e.protocolVersion!==2||!pp(e.commandID)||typeof e.documentID!="string"||!Yw(e.documentGeneration)||!DO.includes(e.type)||!e.payload||typeof e.payload!="object"||Array.isArray(e.payload)||e.minimumRevision!==void 0&&!Yw(e.minimumRevision)||e.requestID!==void 0&&!pp(e.requestID)||e.type==="requestSnapshot"&&!pp(e.requestID)?null:e},Zw=(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),e0=(t,e)=>e?{revision:t.revision+1,dirty:!0,changed:!0}:{...t,changed:!1},t0=(t,e)=>({...e,protocolVersion:2,documentID:t.documentID,documentGeneration:t.documentGeneration,revision:t.revision});var LO=(t,e)=>{let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1},n0=t=>{let e=[],n=/!\[\[([^\]\n]+)\]\]|\[\[([^\]\n]+)\]\]|==([^=\n]+)==|\^\[([^\]\n]+)\]/g,r=0;for(let i of t.matchAll(n)){let o=i.index||0;if(LO(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 r0=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},i0=t=>`[!${t.calloutType}]${t.fold}${t.title?` ${t.title}`:""}`;var hp=new Set(["system","serif","literary"]),BO=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},PO=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},o0=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=r0(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"?(o0(n),[n]):n0(String(n.value||"")).map(PO));t.children=BO(e)},FO=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:i0({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=>o0(r)})),s0=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)}})),a0=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)}})),l0=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})}})),zO=ge(t=>hi(/!\[\[([^\]\n]+)\]\]$/,a0.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),$O=ge(t=>hi(/(?<!!)\[\[([^\]\n]+)\]\]$/,s0.type(t),{getAttr:e=>{let n=e[1]||"",[r="",...i]=n.split("|");return{raw:n,target:r.trim(),label:i.join("|").trim()}}})),_O=ge(t=>hi(/\^\[([^\]\n]+)\]$/,l0.type(t),{getAttr:e=>({value:e[1]||""})})),c0=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")}}})),HO=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})}}})),WO=ge(t=>an(/(?:^|[^\\=])==([^=\n]+)==$/,c0.type(t))),jO=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()}}})),u0=[FO,s0,a0,l0,HO,c0,WO,jO,zO,$O,_O].flat();var L0=window.webkit?.messageHandlers,st=window.weiBeiEditorCheckMode?Jw():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,B0=!1,Sp=0,P0=window.weiBeiMarkdownBaseURL||"",qO=window.weiBeiLocalImageScheme||"weibeiimage",Dp=0,KO=0,f0=0,Ji=0,Jn=new Map,zt=new Map,F0=Nw("WEIBEI_BLOCK_COMMAND"),UO=ge(t=>hi(qw,up.type(t),{beforeDispatch:({tr:e,match:n,start:r})=>e.insertText(n[1]||"",r+1)})),JO=[Fw,up,Tl,zw,UO].flat(),Gn=0,yt=null,Cn=null,Bl=null,Mp=[],Yi=0,d0="{{WEIBEI_CURSOR}}",mp="{{WEIBEI_SELECT_START}}",p0="{{WEIBEI_SELECT_END}}",gp=new Set(["note","tip","important","warning","caution","summary","abstract","quote","question","example","info","success","failure","danger","bug","todo"]);var z0=t=>t==="en"?"en":"zh-Hans",Kr=z0(window.weiBeiInterfaceLanguage),h0={"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"}},m0=t=>h0[Kr]?.[t]||h0["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},GO=()=>ue("properties"),XO=new RegExp(`(^|\\n)\\s*(?:>\\s*)*\\\\?\\[!(?:${dp})\\][+-]?[ \\t]*`,"gi"),YO=/<br\s*\/?>/gi,$0=t=>String(t||"").replace(YO,` -`).replace(/%%[\s\S]*?%%\n?/g,"").replace(/!\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=bD(n);return r.label||r.target}).replace(/\[\[([^\]\n]+)\]\]/g,(e,n)=>{let r=Y0(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(XO,"$1").replace(/(^|\n)\s*>\s?/g,"$1").replace(/(^|\n)\s*[-*+]\s+\[[ xX]\]\s*/g,"$1").replace(/[ \t]+\n/g,` +`).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=Y0(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(XO,"$1").replace(/(^|\n)\s*>\s?/g,"$1").replace(/(^|\n)\s*[-*+]\s+\[[ xX]\]\s*/g,"$1").replace(/[ \t]+\n/g,` `).replace(/\n{2,}/g,` `).trim(),_0=t=>t==="glassLight"||t==="glassMist"?"xuan":t==="glassDark"||t==="glassSlate"?"stele":t==="xuan"||t==="inkstone"||t==="stele"||t==="paper"?t:"paper",QO=t=>["glassLight","glassDark","glassMist","glassSlate"].includes(t)?t:"",Gi=_0(window.weiBeiTheme),ZO=()=>{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'}}},eD=t=>{t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"base",themeVariables:ZO()})},H0=t=>{Gi=_0(t);let e=QO(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};H0(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=L0?.[t];if(!n)return;let r=t0({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,tD=[{id:"structure",label:"slashStructure"},{id:"lists",label:"slashLists"},{id:"content",label:"slashContent"},{id:"rich",label:"slashRichContent"},{id:"fonts",label:"slashFonts"}],nD=[{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"]}],W0=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",rD=t=>{document.documentElement.dataset.weibeiReduceMotion=t===!0||t==="true"?"true":"false"},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}`}},V0=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},g0=t=>{let e=V0(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},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}},iD=(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=q0(e,r);return!!(i&&e.container.canReplace(e.index,e.index+1,i.content))},oD=(t,e,n)=>{let r=String(t||"").toLocaleLowerCase();return nD.filter(i=>iD(i,e,n)&&(!r||[Rl["zh-Hans"][i.label],Rl.en[i.label],...i.aliases].some(o=>String(o).toLocaleLowerCase().includes(r))))},K0=(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},sD=(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})},aD=(t,e,n)=>{let r=t.state.schema.marks.writing_font;if(!r||!W0.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"?(sD(e,n),!0):Ep[t]?aD(e,n,Ep[t]):K0(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}`},lD=()=>`${Kr}::${I.error?"!":""}::${I.commands.length}::${I.commands.map(t=>t.id).join(",")}`,y0=null,cD=()=>{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 tD){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,U0=()=>{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){U0();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=oD(e.query,e,t.state.schema),I.activeIndex=Math.min(I.activeIndex,Math.max(0,I.commands.length-1));let n=lD();n!==y0&&(y0=n,cD()),Pp(),Sn()},uD=(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 k0=0,yp=0,b0=0,x0=0,J0=()=>[document.querySelector("#editor"),document.querySelector(".milkdown"),document.querySelector(".ProseMirror")].filter(Boolean),fD=t=>{let e=t.getBoundingClientRect?.();return Math.max(0,t.scrollHeight||0,t.offsetHeight||0,t.clientHeight||0,e?.height||0)},w0=()=>{let t=J0(),e=Math.ceil(Math.max(1,...t.map(fD))),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-b0)<1&&Math.abs(n-x0)<1)&&(b0=e,x0=n,Le("contentHeightChanged",{height:e}))},dD=()=>{!Ll||!B0||(w0(),window.cancelAnimationFrame(k0),k0=window.requestAnimationFrame(w0))},_t=()=>{if(!Ll||yp)return;let t=yt!==null?100:40;yp=window.setTimeout(()=>{yp=0,dD()},t)},pD=()=>{if(Ll){if(window.ResizeObserver){let t=new ResizeObserver(_t);J0().forEach(e=>t.observe(e))}_t(),document.fonts?.ready?.then(_t).catch(()=>{})}},hD=()=>{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=>Kw(vs,t),mD=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=mD(vs);t.dataset.visible=e.length>0?"true":"false",t.innerHTML=e.length>0?`<div class="frontmatter-title">${GO()}</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,"""),C0=t=>`${qO}://image?src=${encodeURIComponent(t)}`,gD=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|tiff?)(?:$|[?#])/i,G0=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},yD=(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?G0(e.at(-1)):null;return{alt:n?e.slice(0,-1).join("|").trim():String(t||""),size:n}},kD=(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}},X0=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},Y0=t=>{let e=String(t||"").trim(),n=X0(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?kD(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}},bD=t=>{let e=X0(String(t||"").trim()),n=(e.shift()?.value||"").trim(),r=e.at(-1),i=r?G0(r.value):null,o=i?e.slice(0,-1):e;return{target:n,size:i,label:o.map(s=>s.value).join("|").trim()}},Q0=()=>{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"> +${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=L0?.[t];if(!n)return;let r=t0({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,tD=[{id:"structure",label:"slashStructure"},{id:"lists",label:"slashLists"},{id:"content",label:"slashContent"},{id:"rich",label:"slashRichContent"},{id:"fonts",label:"slashFonts"}],nD=[{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"]}],W0=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",rD=t=>{document.documentElement.dataset.weibeiReduceMotion=t===!0||t==="true"?"true":"false"},iD=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}`}},V0=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},g0=t=>{let e=V0(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},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=Lp(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 nD.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))))},K0=(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()}-${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||!W0.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]):K0(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(",")}`,y0=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 tD){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,U0=()=>{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){U0();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!==y0&&(y0=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 k0=0,yp=0,b0=0,x0=0,J0=()=>[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)},w0=()=>{let t=J0(),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-b0)<1&&Math.abs(n-x0)<1)&&(b0=e,x0=n,Le("contentHeightChanged",{height:e}))},pD=()=>{!Ll||!B0||(w0(),window.cancelAnimationFrame(k0),k0=window.requestAnimationFrame(w0))},_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);J0().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=>Kw(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">${GO()}</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,"""),C0=t=>`${qO}://image?src=${encodeURIComponent(t)}`,yD=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|tiff?)(?:$|[?#])/i,G0=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?G0(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}},X0=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},Y0=t=>{let e=String(t||"").trim(),n=X0(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=X0(String(t||"").trim()),n=(e.shift()?.value||"").trim(),r=e.at(-1),i=r?G0(r.value):null,o=i?e.slice(0,-1):e;return{target:n,size:i,label:o.map(s=>s.value).join("|").trim()}},Q0=()=>{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)}`},Z0=t=>{if(!t||/^(?:data:|blob:|weibeiimage:)/i.test(t))return t;if(/^https:/i.test(t))return C0(t);if(/^http:/i.test(t))return"";try{let e=new URL(t,P0||window.location.href).href;return/^(?:file:|https:)/i.test(e)?C0(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 xD=(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=Z0(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):"",yD(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",Q0());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)}}},e1=()=>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}},t1=()=>K?K.action(t=>{let{selection:e}=t.get(U).state;if(!e||e.empty)return"";let n=e.content().content;return $0(n.textBetween(0,n.size,` -`))}):"",wD=()=>$0(window.getSelection()?.toString()||t1()),Yt=(t,e,n,r,i={})=>{n<=e||t.push(le.inline(e,n,{...i,class:r}))},CD=t=>(Array.isArray(t)?t:[]).map(e=>({id:String(e?.id||""),text:String(e?.text||"").trim()})).filter(e=>e.id&&e.text.length>=4),SD=(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 MD=(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]})}},ED=(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}},TD=(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")}},vD=(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}))}},S0=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 Ww();eD(u);let f=`weibei-mermaid-${KO+=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,AD=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},ID=t=>{$t&&($t.documentGeneration!==je||$t.contentGeneration!==Gn||$t.generation!==Ji||t?.pos!==$t.pos)&&($t=null)},ND=(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}:{...S0(t.textContent),generation:Ji,key:`mermaid-preview-${f0+=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={...S0(t.textContent),generation:Ji,key:`mermaid-preview-${f0+=1}`};return Il.set(t,o),o},RD=(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=ND(e,n,r);return t.push(le.widget(n+e.nodeSize,()=>i.element,{side:-1,key:i.key})),!0},OD=t=>{let e=Y0(t);return e.target||e.noteTitle},DD=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=DD(t);return e?(Le("wikiLinkActivated",{title:e}),!0):!1},LD=t=>(t instanceof Element?t.closest(".weibei-source-reference[data-source-reference]"):null)?.getAttribute("data-source-reference")||"",Rp=t=>{let e=LD(t);return e?(Le("sourceReferenceActivated",{reference:e}),!0):!1},n1=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},r1=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},i1=t=>typeof t=="string"?t.length:Array.isArray(t.content)?t.content.reduce((e,n)=>e+i1(n),0):String(t.content||"").length,BD=t=>{let e=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return["weibei-prism-token","token",t.type,...e].filter(Boolean).join(" ")},M0=new WeakMap,PD=new Set(["bash","css","do","java","javascript","json","jsx","markdown","python","r","ruby","rust","sql","stata","swift","tsx","typescript","yaml"]),ws=null,E0=!1,FD=()=>{ws||E0||(E0=!0,jw().then(t=>{ws=t,Yi+=1,K?.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiPrismReady",!0))})}).catch(Qi))},o1=(t,e,n)=>{let r=n;for(let i of e){let o=i1(i);typeof i!="string"&&o>0&&(t.push({from:r,to:r+o,className:BD(i)}),Array.isArray(i.content)&&o1(t,i.content,r)),r+=o}},zD=(t,e,n)=>{let r=$p(e.attrs.language||"");if(!PD.has(r))return;if(!ws){FD();return}let i=M0.get(e);try{i||(At(st,"codeTokenizations"),i=[],o1(i,ws.tokenize(e.textContent,ws.languages[r]),0),M0.set(e,i)),i.forEach(o=>Yt(t,n+1+o.from,n+1+o.to,o.className))}catch{}};var T0=(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=Hw();y?g(y):g(await _w(),!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"&&gD.test(r.attrs.target)){let c=document.createElement("img");c.className="weibei-embed-image",c.alt=r.attrs.label||r.attrs.target,c.src=Z0(r.attrs.target),c.addEventListener("error",()=>{c.src=Q0(),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)}}},_D=(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=m0(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||m0(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)}}},HD=()=>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=OD(c[1]),!1}return!0}),r}):"",s1=async t=>{let{alt:e,src:n}=await sp(t);if(!L0?.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)})},WD=t=>{let e=String(t||""),n=e.trim();return n?e.includes(` -`)?!0:/^(?:#{1,6}\s|[-*+]\s|\d+\.\s|>\s|```|~~~|\$\$|\|.*\||---$)/.test(n):!1},jD=t=>{let e=String(t||"");return WD(e)?` +</svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`},Z0=t=>{if(!t||/^(?:data:|blob:|weibeiimage:)/i.test(t))return t;if(/^https:/i.test(t))return C0(t);if(/^http:/i.test(t))return"";try{let e=new URL(t,P0||window.location.href).href;return/^(?:file:|https:)/i.test(e)?C0(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=Z0(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",Q0());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)}}},e1=()=>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}},t1=()=>K?K.action(t=>{let{selection:e}=t.get(U).state;if(!e||e.empty)return"";let n=e.content().content;return $0(n.textBetween(0,n.size,` +`))}):"",CD=()=>$0(window.getSelection()?.toString()||t1()),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}))}},S0=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 Ww();eD(u);let f=`weibei-mermaid-${KO+=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}:{...S0(t.textContent),generation:Ji,key:`mermaid-preview-${f0+=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={...S0(t.textContent),generation:Ji,key:`mermaid-preview-${f0+=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=Y0(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},n1=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},r1=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},i1=t=>typeof t=="string"?t.length:Array.isArray(t.content)?t.content.reduce((e,n)=>e+i1(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(" ")},M0=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,E0=!1,zD=()=>{ws||E0||(E0=!0,jw().then(t=>{ws=t,Yi+=1,K?.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiPrismReady",!0))})}).catch(Qi))},o1=(t,e,n)=>{let r=n;for(let i of e){let o=i1(i);typeof i!="string"&&o>0&&(t.push({from:r,to:r+o,className:PD(i)}),Array.isArray(i.content)&&o1(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=M0.get(e);try{i||(At(st,"codeTokenizations"),i=[],o1(i,ws.tokenize(e.textContent,ws.languages[r]),0),M0.set(e,i)),i.forEach(o=>Yt(t,n+1+o.from,n+1+o.to,o.className))}catch{}};var T0=(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=Hw();y?g(y):g(await _w(),!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=Z0(r.attrs.target),c.addEventListener("error",()=>{c.src=Q0(),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=m0(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||m0(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}):"",s1=async t=>{let{alt:e,src:n}=await sp(t);if(!L0?.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(` +`)?!0:/^(?:#{1,6}\s|[-*+]\s|\d+\.\s|>\s|```|~~~|\$\$|\|.*\||---$)/.test(n):!1},VD=t=>{let e=String(t||"");return jD(e)?` ${e.trim()} -`:e},VD=()=>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(p0);if(c>=0&&u>c)return n={startFrom:a+c,startTo:a+c+mp.length,endFrom:a+u,endTo:a+u+p0.length},!1;let f=l.indexOf(d0);return f<0?!0:(r={from:a+f,to:a+f+d0.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}),qD=()=>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)))}),KD=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(s1))).map(({alt:o,src:s})=>r.createAndFill({alt:o,src:s})).filter(Boolean)},v0=t=>Array.from(t||[]).map(e=>e.getAsFile?.()).filter(e=>e&&e.type.includes("image")),UD=({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})`},A0=async t=>{if(!ie)return;let e=await Promise.all(t.map(s1));Es(e.map(UD).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(p0);if(c>=0&&u>c)return n={startFrom:a+c,startTo:a+c+mp.length,endFrom:a+u,endTo:a+u+p0.length},!1;let f=l.indexOf(d0);return f<0?!0:(r={from:a+f,to:a+f+d0.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(s1))).map(({alt:o,src:s})=>r.createAndFill({alt:o,src:s})).filter(Boolean)},v0=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})`},A0=async t=>{if(!ie)return;let e=await Promise.all(t.map(s1));Es(e.map(JD).join(` -`))},JD="#editor, .ProseMirror pre, .weibei-math-block",bp=new WeakMap,GD=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))},XD=()=>{document.addEventListener("scroll",t=>{let e=t.target instanceof Element?t.target.closest(JD):null;e&&GD(e)},!0)},YD=new Set(["list_item","task_list_item"]),a1=t=>(t.textContent||"").replace(/[\u200B\uFEFF]/g,"").trim(),I0=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(YD.has(i.type.name))return a1(i).length>0?null:i.type}return null},QD=t=>{let{state:e}=t,{$from:n}=e.selection,r=n.parent;if(r?.isTextblock!==!0||!r.textContent||a1(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)},ZD=t=>{let e=I0(t.state);return e?(QD(t),e=I0(t.state)||e,Wa(e)(t.state,t.dispatch,t)):!1},eL=(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))},tL=(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},nL=new Set(["-","'",'"']),rL=(t,e)=>{if(!ie||!nL.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},iL=(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)},oL=(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)},sL=(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},aL=(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)},N0={doc:null,focusedMermaidPos:null,generation:-1,decorations:ae.empty},R0=(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},lL=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)=>{(R0(r,s,a)||R0(i,l,c))&&(o=!0)}),o}),cL=pe(()=>new X({state:{init:()=>null,apply:(t,e,n,r)=>(At(st,"transactions"),t.docChanged&&!Cp&&(Mn=e0(Mn,!0),Le("dirtyChanged",{dirty:Mn.dirty})),t.docChanged&&lL(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(fL)},u=h=>{h.target!==t.dom||!t.hasFocus()||!tL(t,h)&&!rL(t,h)||(h.preventDefault(),h.stopImmediatePropagation())},f=h=>{h.target===t.dom&&iL(t,h)},d=h=>h.preventDefault(),p=h=>{let m=h.target instanceof Element?h.target.closest("button[data-action]"):null;m instanceof HTMLElement&&(aL(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=v0(e.clipboardData?.items);if(n.length>0)return e.preventDefault(),A0(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=v0(e.dataTransfer?.items);return n.length===0?!1:(e.preventDefault(),A0(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"]),a1=t=>(t.textContent||"").replace(/[\u200B\uFEFF]/g,"").trim(),I0=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 a1(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||a1(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=I0(t.state);return e?(ZD(t),e=I0(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)},N0={doc:null,focusedMermaidPos:null,generation:-1,decorations:ae.empty},R0=(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)=>{(R0(r,s,a)||R0(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=e0(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=v0(e.clipboardData?.items);if(n.length>0)return e.preventDefault(),A0(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=v0(e.dataTransfer?.items);return n.length===0?!1:(e.preventDefault(),A0(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 n1(n.target)||Np(n.target)||Rp(n.target)||r1(n.target)},handleKeyDown(t,e){if(sL(t,e))return e.preventDefault(),!0;if(uD(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(eL(t,e)||oL(t,e)||e.key==="Enter"&&ie&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey&&ZD(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=HD();return n?(Le("wikiLinkActivated",{title:n}),e.preventDefault(),!0):!1},decorations(t){let e=AD(t);ID(e);let n=e?.pos??null,r=N0;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 RD(i,l,c,e)||(i.push(le.node(c,c+l.nodeSize,{class:"weibei-code-block","data-language":l.attrs.language||""})),zD(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;vD(i,p,d),ED(i,p,d,o),MD(i,p,d),TD(i,p,d),SD(i,p,d,s)}return!0});let a=ae.create(t.doc,i);return N0={doc:t.doc,focusedMermaidPos:n,generation:Yi,decorations:a},a}}})),Xi=()=>{if(window.weiBeiSuppressSelectionReport)return;let t=wD(),e=t?hD():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})}},l1=(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"&&W0.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 n1(n.target)||Np(n.target)||Rp(n.target)||r1(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=N0;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 N0={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})}},l1=(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"&&W0.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)?Eg: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")},c1=t=>{Mp=CD(t),Yi+=1,K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiSelectionAskMarksChanged",!0))})},uL=()=>{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())})},fL=()=>{K&&(uL(),Nl=!1,Dl=null,_t(),eo())},_p=()=>K.action(t=>t.get(Q)),dL=(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()},pL=t=>{let e=String(t||"");if(!e)return;let n=Bl;Hp(n===null?e:n+e)},hL=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()},u1=t=>{En(),dL(),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(Tk(n)),to=Pl(n),K.action(r=>jp(r.get(U).state.doc)),_t()},O0=(t,e=0,n=!1)=>{Cp=!0,Mn={revision:e,dirty:n};try{u1(t)}finally{Cp=!1}Le("dirtyChanged",{dirty:n})},f1=()=>(En(),At(st,"fullSerializations"),Pl(K.action(Ek()))),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=jD(qr(t,e));n?K.action(Gu(r,n)):K.action(Ju(r)),VD()||qD(),Qt=null},d1=t=>{En(),K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setSelection(_.atEnd(n.state.doc)))}),Wp(t,"agentGenerated")},mL=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})),gL=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),yL=(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),p1=()=>Array.from(document.querySelectorAll(".ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6")),D0=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=Xw(e);r!==Op&&(Op=r,At(st,"outlineReports"),Le("outlineChanged",{items:e}))},eo=()=>{window.cancelAnimationFrame(D0),D0=window.requestAnimationFrame(()=>{let t=p1();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}))})},h1=t=>{let e=Number(t),n=p1(),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},m1=(t,e)=>{let n=t!==tt||e!==je;tt=t,je=e,n&&(Op=null,Gn+=1,zt.clear(),Jn.clear(),c1([]))},g1=t=>{ie=t!==!1,Fp(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiEditableChanged",ie))})},y1=t=>{H0(t),Yi+=1,e1(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",Gi))})},k1=t=>{Kr=z0(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))})},b1=()=>K?(K.action(t=>t.get(U).focus()),!0):!1,gt=(t,e)=>t.payload[e]??t.payload.value,kL=t=>{let e=Qw(t);if(!e||!Zw(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:(m1(e.documentID,e.documentGeneration),O0(n,Number(r??0)),!0)}case"requestSnapshot":{let n=f1();return to=n,Le("snapshotReady",{requestID:e.requestID,markdown:n}),!0}case"setTheme":return y1(gt(e,"theme")),!0;case"setLanguage":return k1(gt(e,"language")),!0;case"setEditable":return g1(gt(e,"editable")),!0;case"focus":return b1();case"scrollToHeading":return h1(gt(e,"index"));case"applyMarkdownFragment":{let n=gt(e,"markdown");return typeof n!="string"?!1:(d1(n),!0)}case"replaceSelection":{let n=gt(e,"markdown");return typeof n!="string"?!1:(Es(n),!0)}case"executeSelectionCommand":return l1(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:(O0(n,r===void 0?Mn.revision:Number(r),!0),!0)}}};window.WeiBeiEditor={dispatchCommand:kL,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 K0(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)},setSelectionAskMarks:c1,setMarkdownBaseURL:t=>{P0=t||"",e1()}};window.weiBeiEditorCheckMode&&(Object.assign(window.WeiBeiEditor,{getMarkdown:f1,setMarkdown:u1,updateStreamingMarkdown:Hp,appendStreamingMarkdown:pL,finishStreamingMarkdown:t=>(hL(t),!0),replaceSelection:Es,executeSelectionCommand:l1,applyAgentPatch:d1,insertMarkdownImage:Es,insertMarkdown:Wp,setEditable:g1,setDocumentID:t=>m1(String(t||""),je+1),setTheme:y1,setInterfaceLanguage:k1,setReduceMotion:rD,focus:b1,scrollToHeading:h1}),window.WeiBeiEditor.getCheckMetrics=()=>({...st,fullBridgeMessages:Sp}),window.WeiBeiEditor.resetCheckMetrics=()=>{Gw(st),Sp=0},window.WeiBeiEditor.getBridgeSessionForCheck=()=>({protocolVersion:2,documentID:tt,documentGeneration:je,revision:Mn.revision,dirty:Mn.dirty}),window.WeiBeiEditor.selectFirstTextForCheck=mL,window.WeiBeiEditor.selectedTextForCheck=t1,window.WeiBeiEditor.typeTextForCheck=gL,window.WeiBeiEditor.pressKeyForCheck=yL,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=wk.make().config(t=>{t.set(Vo,document.querySelector("#editor")),t.set(Ho,Ts.body),t.set(Rr,{editable:()=>ie,nodeViews:{code_block:$D,image:xD,math_inline:T0,math_block:T0,wiki_link:kp,embed:kp,inline_footnote:kp,callout:_D}}),t.set(qn.key,{throttleMs:0,scrollFollow:!1,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}})});Gr=Gr.config(t=>{t.set(Vr.key,{uploader:KD,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(F0.key,{view(e){let n=l=>l.preventDefault(),r=()=>{let l=V0(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 Rw({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,U0(),Bp()},i.update(e),g0(e),{update(l,c){I.view=l;let u=Zi(l);I.dismissedContext&&u?.key!==I.dismissedContext&&(I.dismissedContext=""),i.update(l,c),g0(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(cL).use(Zk).use(xx).use(u0).use(JO).use(ew).use(pe(()=>nw(()=>yt!==null)));Gr=Gr.use(F0).use($x).use(Xd).use(Dw);Gr.use(Hd).config(t=>{t.get(ll).selectionUpdated(()=>{requestAnimationFrame(Xi)})}).create().then(t=>{K=t,Fp(),XD(),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")||!n1(e.target)&&!Np(e.target)&&!Rp(e.target)&&!r1(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(()=>{B0=!0,pD(),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)?Eg: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")},c1=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()},u1=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(Tk(n)),to=Pl(n),K.action(r=>jp(r.get(U).state.doc)),_t()},O0=(t,e=0,n=!1)=>{Cp=!0,Mn={revision:e,dirty:n};try{u1(t)}finally{Cp=!1}Le("dirtyChanged",{dirty:n})},f1=()=>(En(),At(st,"fullSerializations"),Pl(K.action(Ek()))),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},d1=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),p1=()=>Array.from(document.querySelectorAll(".ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6")),D0=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=Xw(e);r!==Op&&(Op=r,At(st,"outlineReports"),Le("outlineChanged",{items:e}))},eo=()=>{window.cancelAnimationFrame(D0),D0=window.requestAnimationFrame(()=>{let t=p1();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}))})},h1=t=>{let e=Number(t),n=p1(),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},m1=(t,e)=>{let n=t!==tt||e!==je;tt=t,je=e,n&&(Op=null,Gn+=1,zt.clear(),Jn.clear(),c1([]))},g1=t=>{ie=t!==!1,Fp(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiEditableChanged",ie))})},y1=t=>{H0(t),Yi+=1,e1(),K&&K.action(e=>{let n=e.get(U);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",Gi))})},k1=t=>{Kr=z0(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))})},b1=()=>K?(K.action(t=>t.get(U).focus()),!0):!1,gt=(t,e)=>t.payload[e]??t.payload.value,bL=t=>{let e=Qw(t);if(!e||!Zw(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:(m1(e.documentID,e.documentGeneration),O0(n,Number(r??0)),!0)}case"requestSnapshot":{let n=f1();return to=n,Le("snapshotReady",{requestID:e.requestID,markdown:n}),!0}case"setTheme":return y1(gt(e,"theme")),!0;case"setLanguage":return k1(gt(e,"language")),!0;case"setEditable":return g1(gt(e,"editable")),!0;case"focus":return b1();case"scrollToHeading":return h1(gt(e,"index"));case"applyMarkdownFragment":{let n=gt(e,"markdown");return typeof n!="string"?!1:(d1(n),!0)}case"replaceSelection":{let n=gt(e,"markdown");return typeof n!="string"?!1:(Es(n),!0)}case"executeSelectionCommand":return l1(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:(O0(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 K0(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)},setSelectionAskMarks:c1,setMarkdownBaseURL:t=>{P0=t||"",e1()}};window.weiBeiEditorCheckMode&&(Object.assign(window.WeiBeiEditor,{getMarkdown:f1,setMarkdown:u1,updateStreamingMarkdown:Hp,appendStreamingMarkdown:hL,finishStreamingMarkdown:t=>(mL(t),!0),replaceSelection:Es,executeSelectionCommand:l1,applyAgentPatch:d1,insertMarkdownImage:Es,insertMarkdown:Wp,setEditable:g1,setDocumentID:t=>m1(String(t||""),je+1),setTheme:y1,setInterfaceLanguage:k1,setReduceMotion:rD,setTextScale:iD,focus:b1,scrollToHeading:h1}),window.WeiBeiEditor.getCheckMetrics=()=>({...st,fullBridgeMessages:Sp}),window.WeiBeiEditor.resetCheckMetrics=()=>{Gw(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=t1,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=wk.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:T0,math_block:T0,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(F0.key,{view(e){let n=l=>l.preventDefault(),r=()=>{let l=V0(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 Rw({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,U0(),Bp()},i.update(e),g0(e),{update(l,c){I.view=l;let u=Zi(l);I.dismissedContext&&u?.key!==I.dismissedContext&&(I.dismissedContext=""),i.update(l,c),g0(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(Zk).use(xx).use(u0).use(JO).use(ew).use(pe(()=>nw(()=>yt!==null)));Gr=Gr.use(F0).use($x).use(Xd).use(Dw);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")||!n1(e.target)&&!Np(e.target)&&!Rp(e.target)&&!r1(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(()=>{B0=!0,hD(),K.action(e=>jp(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 b89b99682..f72d1b85f 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": 596111, - "sha256": "79faa6be2129b58f030ed5f062c1173d5b89363318dd6dbd41e150bde2c38a7e" + "bytes": 596257, + "sha256": "4ed73e076a6be9b724d57abf770e93b34b4230436709575663e9dbcdddb4fb9f" }, { "name": "editor.css", @@ -313,8 +313,8 @@ }, { "name": "index.html", - "bytes": 48872, - "sha256": "524797dc16aac196e1b9eb83e4571821692a0ba5edcd04af3bfe49a681dde423" + "bytes": 49020, + "sha256": "28437821549e01b3261c3bfb4322ef47d518484f6c97f1b0a0d97f92d9b54edb" }, { "name": "katex-runtime.js", @@ -333,8 +333,8 @@ }, { "name": "viewer-entry.js", - "bytes": 516818, - "sha256": "3a61bbdf17677d793ffb7de1dad4b62634ff5d54f46267a1d166b311848aabb4" + "bytes": 516964, + "sha256": "046c6a4312333e3e8a91a38bd8a14255d4a618117ef81e8b845bfa8b5717b843" } ] } diff --git a/Sources/WeiBei/Resources/Editor/index.html b/Sources/WeiBei/Resources/Editor/index.html index 75e8f13d3..0a2e6c3d4 100644 --- a/Sources/WeiBei/Resources/Editor/index.html +++ b/Sources/WeiBei/Resources/Editor/index.html @@ -372,10 +372,14 @@ border-left-color: var(--cinnabar-line); } + :root { + --weibei-text-scale: 1; + } + .ProseMirror { outline: none; min-height: calc(100vh - 92px); - font-size: 17px; + font-size: calc(17px * var(--weibei-text-scale)); line-height: 1.82; caret-color: var(--cinnabar); word-break: break-word; @@ -390,12 +394,12 @@ :root[data-weibei-compact-preview="true"] .ProseMirror { min-height: 0; - font-size: 14px; + font-size: calc(14px * var(--weibei-text-scale)); line-height: 1.68; } :root[data-weibei-chat-wide="true"] .ProseMirror { - font-size: 16px; + font-size: calc(16px * var(--weibei-text-scale)); line-height: 1.8; } diff --git a/Sources/WeiBei/Resources/Editor/viewer-entry.js b/Sources/WeiBei/Resources/Editor/viewer-entry.js index f80620987..9b1c9c853 100644 --- a/Sources/WeiBei/Resources/Editor/viewer-entry.js +++ b/Sources/WeiBei/Resources/Editor/viewer-entry.js @@ -1,4 +1,4 @@ -"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((fP,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(` +"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=` `;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===` @@ -36,14 +36,14 @@ `);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},rF=new ke(/--$/,"\u2014",{inCodeMark:!1}),iF=new ke(/\.\.\.$/,"\u2026",{inCodeMark:!1}),oF=new ke(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),sF=new ke(/"$/,"\u201D",{inCodeMark:!1}),aF=new ke(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),lF=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),dF=Ph?document.documentMode:Fl?+Fl[1]:Pl?+Pl[1]:0,qS=!$l&&/gecko\/(\d+)/i.test(dn),pF=qS&&+(/Firefox\/(\d+)/.exec(dn)||[0,0])[1],zl=!$l&&/Chrome\/(\d+)/.exec(dn),KS=!!zl,hF=zl?+zl[1]:0,US=!$l&&!!fn&&/Apple Computer/.test(fn.vendor),JS=US&&(/Mobile\/\w+/.test(dn)||!!fn&&fn.maxTouchPoints>2),mF=JS||(fn?/Mac/.test(fn.platform):!1),GS=/Android \d/.test(dn),QS=!!Lh&&"webkitFontSmoothing"in Lh.documentElement.style,gF=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,` +`).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,` `);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 nz=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:()=>` +`))),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:()=>` `,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 Fz=Iu("row",{useDeprecatedLogic:!0}),zz=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?` +`):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:` `,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(` @@ -66,16 +66,16 @@ $$`).replace(/\\hat\s+(\\[A-Za-z]+|[A-Za-z])/g,"\\hat{$1}").replace(/\\hat(?!\{) ${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 {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=aA(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,` +`).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,` `).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"};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),eA=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(eA))),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}))},tA=()=>{!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,tA()},t)},nA=()=>{if(ma){if(window.ResizeObserver){let t=new ResizeObserver(Ct);Vb().forEach(e=>t.observe(e))}Ct(),document.fonts?.ready?.then(Ct).catch(()=>{})}},rA=()=>{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),iA=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=iA(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},oA=(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}},sA=(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?sA(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}},aA=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"> +${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"> <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)}`},lA=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,cA=new Set,uA=t=>{let e=t,n=document.createElement("img");n.className="weibei-image";let r=()=>{let i=jb(e.attrs.alt||""),o=lA(String(e.attrs.src||""));n.alt=i.alt,n.title=String(e.attrs.title||""),oA(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()),fA=()=>{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}},dA=()=>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,` -`))}):"",pA=()=>$b(window.getSelection()?.toString()||dA()),Ot=(t,e,n,r,i={})=>{n<=e||t.push(se.inline(e,n,{...i,class:r}))},hA=t=>(Array.isArray(t)?t:[]).map(e=>({id:String(e?.id||""),text:String(e?.text||"").trim()})).filter(e=>e.id&&e.text.length>=4),mA=(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 gA=(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]})}},yA=(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}},kA=(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")}},bA=(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,xA=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},wA=t=>{wt&&(wt.documentGeneration!==cr||wt.contentGeneration!==yo||wt.generation!==si||t?.pos!==wt.pos)&&(wt=null)},SA=(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},CA=(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=SA(e,n,r);return t.push(se.widget(n+e.nodeSize,()=>i.element,{side:-1,key:i.key})),!0},MA=t=>{let e=Kb(t);return e.target||e.noteTitle},EA=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=EA(t);return e?(ct("wikiLinkActivated",{title:e}),!0):!1},TA=t=>(t instanceof Element?t.closest(".weibei-source-reference[data-source-reference]"):null)?.getAttribute("data-source-reference")||"",_f=t=>{let e=TA(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,vA=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,IA=new Set(["bash","css","do","java","javascript","json","jsx","markdown","python","r","ruby","rust","sql","stata","swift","tsx","typescript","yaml"]),go=null,Rb=!1,AA=()=>{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:vA(i)}),Array.isArray(i.content)&&Xb(t,i.content,r)),r+=o}},NA=(t,e,n)=>{let r=jf(e.attrs.language||"");if(!IA.has(r))return;if(!go){AA();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 RA=()=>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=MA(c[1]),!1}return!0}),r}):"";var OA="#editor, .ProseMirror pre, .weibei-math-block",Of=new WeakMap,DA=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))},BA=()=>{document.addEventListener("scroll",t=>{let e=t.target instanceof Element?t.target.closest(OA):null;e&&DA(e)},!0)};var LA=(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},PA=new Set(["-","'",'"']),FA=(t,e)=>{if(!lt||!PA.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},zA=(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"))},_A=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},HA=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}),VA=Se(()=>new X({state:{init:()=>null,apply:(t,e,n,r)=>(xt(St,"transactions"),t.docChanged&&HA(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(jA)},u=h=>{h.target!==t.dom||!t.hasFocus()||!LA(t,h)&&!FA(t,h)||(h.preventDefault(),h.stopImmediatePropagation())},f=h=>{h.target===t.dom&&zA(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(()=>_A(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=RA();return n?(ct("wikiLinkActivated",{title:n}),e.preventDefault(),!0):!1},decorations(t){let e=xA(t);wA(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 CA(i,l,c,e)||(i.push(se.node(c,c+l.nodeSize,{class:"weibei-code-block","data-language":l.attrs.language||""})),NA(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;bA(i,p,d),yA(i,p,d,o),gA(i,p,d),kA(i,p,d),mA(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=pA(),e=t?rA():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=fA(),ct("selectionChanged",{text:t,rect:e,...n})}};var qf=()=>{if(!re)throw new Error("WeiBei editor is not ready")},Zb=t=>{Pf=hA(t),li+=1,re&&re.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiSelectionAskMarksChanged",!0))})},WA=()=>{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())})},jA=()=>{re&&(WA(),da=!1,Wf=null,Ct(),ci())},Kf=()=>re.action(t=>t.get(G)),qA=(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()},KA=t=>{let e=String(t||"");if(!e)return;let n=ga;Uf(n===null?e:n+e)},UA=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()},JA=t=>{qf(),qA(),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 GA=()=>(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}))})},QA=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},YA=(t,e)=>{let n=t!==pa||e!==cr;pa=t,cr=e,n&&(Hf=null,yo+=1,jI.clear(),WI.clear(),Zb([]))};var XA=t=>{Hb(t),li+=1,Jb(),re&&re.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiThemeChanged",ai))})},ZA=t=>{ua=zb(t),li+=1,document.documentElement.dataset.weibeiLanguage=ua,ka(),Ub(),cA.forEach(e=>e()),re&&re.action(e=>{let n=e.get(oe);n.dispatch(n.state.tr.setMeta("weibeiLanguageChanged",ua))})},eN=()=>re?(re.action(t=>t.get(oe).focus()),!0):!1;window.WeiBeiEditor={getMarkdown:GA,setMarkdown:t=>JA(String(t||"")),updateStreamingMarkdown:t=>{try{Uf(t)}catch(e){lr(e)}},appendStreamingMarkdown:t=>{try{KA(t)}catch(e){lr(e)}},finishStreamingMarkdown:t=>{try{return UA(t),!0}catch(e){return lr(e),!1}},setDocumentID:t=>{let e=t||"";e!==pa&&YA(e,cr+1)},setTheme:XA,setInterfaceLanguage:ZA,setReduceMotion:ZI,focus:eN,scrollToHeading:QA,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:uA,math_inline:Ob,math_block:Ob}}),t.set(wn.key,{throttleMs:0,scrollFollow:!1,diffReviewOnEnd:!1,ignoreAttrs:{heading:["id"]}})});Vf=Vf.use(VA).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(),BA(),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,nA(),re.action(e=>Jf(e.get(oe).state.doc)),ci()})}).catch(lr);})(); +</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);})(); /*! Bundled license information: lodash-es/lodash.js: diff --git a/Sources/WeiBei/Stores/WorkspaceStore.swift b/Sources/WeiBei/Stores/WorkspaceStore.swift index ef4721d5b..bd3b4ca28 100644 --- a/Sources/WeiBei/Stores/WorkspaceStore.swift +++ b/Sources/WeiBei/Stores/WorkspaceStore.swift @@ -309,9 +309,8 @@ enum ContentSourceRemovalError: LocalizedError { } } -/// Isolated chrome state for the course drawer. -/// Kept off `WorkspaceStore`'s `@Published` surface so opening/closing the drawer -/// does not invalidate reader/agent/notes bodies (that was the multi-second pre-slide lag). +/// Isolated chrome state for the course drawer; kept off `WorkspaceStore`'s +/// `@Published` surface so open/close does not invalidate reader/agent/notes bodies. @MainActor final class LibraryDrawerState: ObservableObject { @Published var isOpen = false @@ -456,9 +455,8 @@ final class WorkspaceStore: ObservableObject { readerSourceHighlightPageIndex = nil } } - /// Reader viewport (HTML section / PDF page). Scroll commits must not - /// auto-publish — every EnvironmentObject consumer (agent chat WKWebView - /// rows) would remasure and freeze the main thread (sample 2026-08-01). + /// Reader viewport (HTML section / PDF page). Scroll commits must not auto-publish: + /// every EnvironmentObject consumer would remasure and freeze main (sample 2026-08-01). private var suppressReaderViewportPublish = false private var readerLocationIDValue: String? private var readerLocationTitleValue: String? @@ -610,6 +608,7 @@ final class WorkspaceStore: ObservableObject { @Published var motionPreference: WeiBeiMotionPreference = .system @Published var adaptImportedDocumentColors = true @Published var interfaceLanguage: WeiBeiInterfaceLanguage = .chinese + @Published var interfaceTextScale: WeiBeiTypography.TextScale = .standard @Published var courseWorkspacePresented = false @Published private(set) var courseWorkspaceCourseID: UUID? @Published private(set) var courseWorkspaceDestination: CourseWorkspaceDestination = .hub @@ -6886,9 +6885,8 @@ final class WorkspaceStore: ObservableObject { mustBeInsideLibrary: expectedCourse.sourceRootRelativePath != nil ) - // Trash path still refuses when the live folder cannot accept - // the latest portable state. Unregister-only must not require - // that write: the folder is already gone or unwritable. + // Trash path still refuses when the live folder cannot accept the + // latest portable state; unregister-only never requires that write. guard await persistWorkspaceNow(), !dirtyPortableCourseIDs.contains(courseID), !blockedPortableCourseIDs.contains(courseID), @@ -8399,10 +8397,8 @@ final class WorkspaceStore: ObservableObject { } } - /// One-pass course → visible-item counts for the contextual browser. - /// Replaces per-course full-library rescans (`contextualBrowserItems` - /// re-filtered + ICU-sorted once per course) that made opening the - /// browser stutter on large libraries. + /// One-pass course → visible-item counts for the contextual browser; replaces + /// per-course full-library rescans that made opening stutter on large libraries. func contextualBrowserItemCounts( _ kind: ContextualContentKind ) -> [UUID: Int] { @@ -12319,6 +12315,12 @@ final class WorkspaceStore: ObservableObject { save() } + func setInterfaceTextScale(_ scale: WeiBeiTypography.TextScale) { + guard interfaceTextScale != scale else { return } + interfaceTextScale = scale + save() + } + func setAgentAuthMethod(_ method: AgentAuthMethod) { guard agentAuthMethod != method else { return } agentAuthMethod = method @@ -12892,9 +12894,8 @@ final class WorkspaceStore: ObservableObject { let cleanedOwnerTitle = ownerTitle?.trimmingCharacters(in: .whitespacesAndNewlines) let resolvedOwnerTitle = (cleanedOwnerTitle?.isEmpty == false ? cleanedOwnerTitle : nil) ?? selectionOwnerTitle(for: source) let boundedText = Self.boundedSelectionText(cleaned) - // Multi-pane and immersive both get the selection capsule when there is an anchor. - // (Previously suppressed whenever the chat column was open — that made multi-pane - // look "broken" vs immersive reading.) + // Multi-pane and immersive both get the selection capsule when there is an anchor + // (previously suppressed whenever the chat column was open — looked "broken"). let shouldRevealSelectionPrompt = anchor != nil || pinnedFloatingAgent let contentMatches = selectionContext.map { $0.text == boundedText @@ -19264,10 +19265,8 @@ final class WorkspaceStore: ObservableObject { changed = true continue } - // Existing legacy workspaces are the local source of truth - // on first upgrade. An equal payload can establish the - // baseline without replaying the disk snapshot over local - // chats, memories, drafts, or shared canonical items. + // Legacy workspaces are the local source of truth on first upgrade; + // an equal payload just baselines without replaying the disk snapshot. coursePortableStateRevisions[courseID] = state.revision coursePortableStateDigests[courseID] = diskDigest changed = true @@ -19640,11 +19639,9 @@ final class WorkspaceStore: ObservableObject { existingSharedPath == sharedRelativePath else { throw CoursePortableStateError.crossCourseReference } - // A shared item is one canonical workspace record used by - // every course. A single course's older portable snapshot - // may restore its membership, but it must not downgrade the - // canonical file URL, identity, bookmark, digest, or file - // metadata already verified by the workspace. + // A shared item is one canonical workspace record used by every course; + // a course's older portable snapshot may restore membership but must not + // downgrade canonical URL/identity/bookmark/digest/metadata already verified. preservedExistingShared = existing itemURL = existing.url itemIdentity = existing.importedFileIdentity @@ -20280,8 +20277,7 @@ final class WorkspaceStore: ObservableObject { self.agentBaseURL = agentBaseURL } // Legacy field: still read so older workspaces restore immersion/multi-pane; - // free drag order lives in threePaneOrder and is the source of truth for columns. - // Unknown / retired strings only drop the layout field, never the workspace. + // threePaneOrder owns free drag order; retired strings only drop this field. var migratedRetiredSplitLayout = false if let persistedLayoutRaw = snapshot.workspaceLayout { if let workspaceLayout = WorkspaceLayout.resolve(persistedValue: persistedLayoutRaw) { @@ -20322,6 +20318,10 @@ final class WorkspaceStore: ObservableObject { let interfaceLanguage = WeiBeiInterfaceLanguage(rawValue: interfaceLanguageRaw) { self.interfaceLanguage = interfaceLanguage } + if let interfaceTextScaleRaw = snapshot.interfaceTextScaleRaw, + let interfaceTextScale = WeiBeiTypography.TextScale(rawValue: interfaceTextScaleRaw) { + self.interfaceTextScale = interfaceTextScale + } noteText = noteText(for: activeNoteItem) } @@ -20432,7 +20432,8 @@ final class WorkspaceStore: ObservableObject { showDailyInspiration: showDailyInspiration, appearanceModeRaw: appearanceMode.rawValue, adaptImportedDocumentColors: adaptImportedDocumentColors, - interfaceLanguageRaw: interfaceLanguage.rawValue + interfaceLanguageRaw: interfaceLanguage.rawValue, + interfaceTextScaleRaw: interfaceTextScale.rawValue ), resumePoints ) @@ -20925,10 +20926,8 @@ final class WorkspaceStore: ObservableObject { } return merged } - // A newer in-memory generation may arrive while this transaction is - // on disk. Keep the committed CAS baseline before building that next - // generation; otherwise it would compare against an obsolete revision - // and falsely report a conflict. + // A newer in-memory generation may arrive while this transaction is on disk; + // keep the committed CAS baseline or the next compare falsely reports conflict. if hasNewerGeneration { coursePortableStateRevisions = mergingDictionary( result.portableStateRevisions, @@ -21182,7 +21181,8 @@ final class WorkspaceStore: ObservableObject { showDailyInspiration: showDailyInspiration, appearanceModeRaw: appearanceMode.rawValue, adaptImportedDocumentColors: adaptImportedDocumentColors, - interfaceLanguageRaw: interfaceLanguage.rawValue + interfaceLanguageRaw: interfaceLanguage.rawValue, + interfaceTextScaleRaw: interfaceTextScale.rawValue ) let noteEditorSaveReceipt = makeNoteEditorWorkspaceSaveReceipt(snapshot) do { diff --git a/Sources/WeiBei/Support/AgentMarkdownBlockFallback.swift b/Sources/WeiBei/Support/AgentMarkdownBlockFallback.swift index 941221099..6c887f035 100644 --- a/Sources/WeiBei/Support/AgentMarkdownBlockFallback.swift +++ b/Sources/WeiBei/Support/AgentMarkdownBlockFallback.swift @@ -56,12 +56,12 @@ struct AgentMarkdownBlockFallback: View { switch block.kind { case let .heading(level): Text(inline(AgentMarkdownBlockParser.headingBody(block.lines.first ?? ""))) - .font(.system(size: headingFontSize(level), weight: .semibold)) + .weiBeiText(headingFontSize(level), weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) case .paragraph: Text(inline(block.lines.joined(separator: "\n"))) - .font(.system(size: compact ? 13.2 : 15)) + .weiBeiText(compact ? 13.2 : 15) .lineSpacing(compact ? 4.2 : 5.2) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) @@ -71,10 +71,10 @@ struct AgentMarkdownBlockFallback: View { ForEach(Array(block.lines.enumerated()), id: \.offset) { index, rawLine in HStack(alignment: .firstTextBaseline, spacing: 7) { Text(ordered ? "\(index + 1)." : "•") - .font(.system(size: compact ? 13.2 : 15)) + .weiBeiText(compact ? 13.2 : 15) .foregroundStyle(WeiBeiTheme.ink.opacity(0.72)) Text(inline(AgentMarkdownBlockParser.listItemBody(rawLine))) - .font(.system(size: compact ? 13.2 : 15)) + .weiBeiText(compact ? 13.2 : 15) .lineSpacing(compact ? 3.6 : 4.4) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) @@ -89,12 +89,12 @@ struct AgentMarkdownBlockFallback: View { VStack(alignment: .leading, spacing: 1.5) { if let language, !language.isEmpty { Text(language) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(WeiBeiTheme.ink.opacity(0.55)) } ForEach(Array(block.lines.enumerated()), id: \.offset) { _, line in Text(line.isEmpty ? " " : line) - .font(.system(size: compact ? 11.6 : 12.4, design: .monospaced)) + .weiBeiText(compact ? 11.6 : 12.4, design: .monospaced) .foregroundStyle(WeiBeiTheme.ink.opacity(0.88)) .fixedSize(horizontal: false, vertical: true) } @@ -110,7 +110,7 @@ struct AgentMarkdownBlockFallback: View { .fill(WeiBeiTheme.cinnabar.opacity(0.6)) .frame(width: 2.5) Text(inline(block.lines.map(AgentMarkdownBlockParser.quoteBody).joined(separator: "\n"))) - .font(.system(size: compact ? 13 : 14.6)) + .weiBeiText(compact ? 13 : 14.6) .lineSpacing(compact ? 3.8 : 4.6) .foregroundStyle(WeiBeiTheme.ink.opacity(0.86)) .fixedSize(horizontal: false, vertical: true) diff --git a/Sources/WeiBei/Support/Theme.swift b/Sources/WeiBei/Support/Theme.swift index f1b83fcd3..efc5c190e 100644 --- a/Sources/WeiBei/Support/Theme.swift +++ b/Sources/WeiBei/Support/Theme.swift @@ -148,6 +148,43 @@ enum WeiBeiTypography { static let englishDisplayFontName = "WeiBeiStele-Regular" static let englishMonoFontName = "WeiBeiSteleMono-Regular" + /// App-side text size tiers. The multiplier applies to every token-driven + /// font so SwiftUI chrome and the Milkdown web runtime scale together. + enum TextScale: String, CaseIterable, Identifiable { + case compact + case standard + case large + case extraLarge + case maximum + + var id: String { rawValue } + + var multiplier: CGFloat { + switch self { + case .compact: return 0.9 + case .standard: return 1.0 + case .large: return 1.15 + case .extraLarge: return 1.35 + case .maximum: return 1.6 + } + } + + func label(language: WeiBeiInterfaceLanguage) -> String { + switch self { + case .compact: + return language.text("紧凑", "Compact") + case .standard: + return language.text("标准", "Standard") + case .large: + return language.text("大", "Large") + case .extraLarge: + return language.text("特大", "Extra Large") + case .maximum: + return language.text("最大", "Maximum") + } + } + } + private static var didRegisterBundledFonts = false static func registerBundledFonts() { @@ -187,6 +224,69 @@ enum WeiBeiTypography { } } +private struct WeiBeiTextScaleKey: EnvironmentKey { + static let defaultValue: CGFloat = 1 +} + +extension EnvironmentValues { + /// Multiplier applied by the weiBei* font modifiers; injected at the app root. + var weiBeiTextScale: CGFloat { + get { self[WeiBeiTextScaleKey.self] } + set { self[WeiBeiTextScaleKey.self] = newValue } + } +} + +private struct WeiBeiScaledTextModifier: ViewModifier { + @Environment(\.weiBeiTextScale) private var scale + let size: CGFloat + let weight: Font.Weight + let design: Font.Design + + func body(content: Content) -> some View { + content.font(.system(size: size * scale, weight: weight, design: design)) + } +} + +private struct WeiBeiScaledBrandTextModifier: ViewModifier { + @Environment(\.weiBeiTextScale) private var scale + let language: WeiBeiInterfaceLanguage + let size: CGFloat + let weight: Font.Weight + + func body(content: Content) -> some View { + content.font(WeiBeiTypography.brandFont(language: language, size: size * scale, weight: weight)) + } +} + +private struct WeiBeiScaledMonoTextModifier: ViewModifier { + @Environment(\.weiBeiTextScale) private var scale + let language: WeiBeiInterfaceLanguage + let size: CGFloat + + func body(content: Content) -> some View { + content.font(WeiBeiTypography.monoFont(language: language, size: size * scale)) + } +} + +extension View { + /// Token-driven fixed-size text that scales with the user's text tier. + func weiBeiText(_ size: CGFloat, weight: Font.Weight = .regular, design: Font.Design = .default) -> some View { + modifier(WeiBeiScaledTextModifier(size: size, weight: weight, design: design)) + } + + func weiBeiBrandFont(language: WeiBeiInterfaceLanguage, size: CGFloat, weight: Font.Weight = .semibold) -> some View { + modifier(WeiBeiScaledBrandTextModifier(language: language, size: size, weight: weight)) + } + + func weiBeiEnglishBrandFont(size: CGFloat, weight: Font.Weight = .semibold) -> some View { + modifier(WeiBeiScaledBrandTextModifier(language: .english, size: size, weight: weight)) + } + + func weiBeiMonoFont(language: WeiBeiInterfaceLanguage, size: CGFloat) -> some View { + modifier(WeiBeiScaledMonoTextModifier(language: language, size: size)) + } +} + private struct WeiBeiTone { var red: CGFloat var green: CGFloat @@ -957,7 +1057,7 @@ private struct AppearanceThemePalettePopover: View { .frame(width: 22, height: 2) } Text(mode.label(language: store.interfaceLanguage)) - .font(.system(size: 11, weight: mode == store.appearanceMode ? .semibold : .medium)) + .weiBeiText(11, weight: mode == store.appearanceMode ? .semibold : .medium) .foregroundStyle( mode == store.appearanceMode ? WeiBeiTheme.ink : WeiBeiTheme.secondaryInk ) @@ -1354,7 +1454,7 @@ private struct WeiBeiIconButtonBody: View { var body: some View { configuration.label - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .frame(width: size, height: size) .foregroundStyle(foreground(isPressed: configuration.isPressed)) .background(background(isPressed: configuration.isPressed)) @@ -1441,7 +1541,7 @@ struct WeiBeiTextActionButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(foreground) .padding(.horizontal, 8) .frame(height: 24) diff --git a/Sources/WeiBei/Views/CommandPaletteView.swift b/Sources/WeiBei/Views/CommandPaletteView.swift index c7260105c..41543547c 100644 --- a/Sources/WeiBei/Views/CommandPaletteView.swift +++ b/Sources/WeiBei/Views/CommandPaletteView.swift @@ -148,7 +148,7 @@ struct CommandPaletteView: View { .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) .focused($searchFocused) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 18, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 18, weight: .semibold) } .weibeiInputSurface(active: searchFocused, height: 36) .padding(.horizontal, 12) @@ -163,7 +163,7 @@ struct CommandPaletteView: View { LazyVStack(spacing: 3) { if filtered.isEmpty { Text(store.ui("没有匹配命令", "No matching commands")) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundStyle(WeiBeiTheme.tertiaryInk) .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 14) @@ -175,7 +175,7 @@ struct CommandPaletteView: View { } label: { HStack(spacing: 12) { Text(command.title) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .lineLimit(1) Spacer() if !command.shortcut.isEmpty { diff --git a/Sources/WeiBei/Views/ContentRailView.swift b/Sources/WeiBei/Views/ContentRailView.swift index 56895b830..d33ffb21c 100644 --- a/Sources/WeiBei/Views/ContentRailView.swift +++ b/Sources/WeiBei/Views/ContentRailView.swift @@ -452,20 +452,20 @@ private struct ContentRailPreviewCard: View { VStack(alignment: .leading, spacing: 7) { Text(label) - .font(.system(size: 9.5, weight: .semibold, design: .serif)) + .weiBeiText(9.5, weight: .semibold, design: .serif) .tracking(0.7) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.78)) .lineLimit(1) Text(item.title) - .font(.system(size: 13.5, weight: .semibold)) + .weiBeiText(13.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(2) .frame(maxWidth: .infinity, alignment: .leading) if !item.excerpt.isEmpty { Text(item.excerpt) - .font(.system(size: 12.5)) + .weiBeiText(12.5) .lineSpacing(3) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(showsPreviewImage ? 3 : 4) @@ -474,7 +474,7 @@ private struct ContentRailPreviewCard: View { if !item.metadata.isEmpty { Text(item.metadata) - .font(.system(size: 10.5, weight: .medium, design: .monospaced)) + .weiBeiText(10.5, weight: .medium, design: .monospaced) .foregroundStyle(WeiBeiTheme.tertiaryInk) .lineLimit(1) .frame(maxWidth: .infinity, alignment: .leading) diff --git a/Sources/WeiBei/Views/ContentView.swift b/Sources/WeiBei/Views/ContentView.swift index b88c11c57..5cab7972a 100644 --- a/Sources/WeiBei/Views/ContentView.swift +++ b/Sources/WeiBei/Views/ContentView.swift @@ -351,7 +351,7 @@ private struct ImportProgressPill: View { "正在导入 \(progress?.completed ?? 0)/\(progress?.total ?? 0):\(progress?.currentFileName ?? "")", "Importing \(progress?.completed ?? 0)/\(progress?.total ?? 0): \(progress?.currentFileName ?? "")" )) - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) .truncationMode(.middle) @@ -384,10 +384,10 @@ private struct WorkspaceStatusBanner: View { var body: some View { HStack(spacing: 8) { Image(systemName: isImportant ? "exclamationmark.triangle.fill" : "info.circle") - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(isImportant ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) Text(message) - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(3) .multilineTextAlignment(.leading) @@ -397,7 +397,7 @@ private struct WorkspaceStatusBanner: View { store.dismissImportantOperationError() } label: { Image(systemName: "xmark") - .font(.system(size: 10, weight: .semibold)) + .weiBeiText(10, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) .contentShape(Rectangle()) } @@ -520,7 +520,7 @@ private struct UnifiedTopBarView: View { .foregroundColor(WeiBeiTheme.ink) .foregroundStyle(WeiBeiTheme.ink) .tint(WeiBeiTheme.link) - .font(.system(size: 12)) + .weiBeiText(12) .weibeiInputSurface(active: searchFocused.wrappedValue, height: controlHeight) .frame(width: 220) .onExitCommand { @@ -1192,9 +1192,9 @@ private struct PaneReorderPreviewView: View { WeiBeiTheme.paper HStack(spacing: 7) { Image(systemName: role.systemImage) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) Text(role.label(language: store.interfaceLanguage)) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) } .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.horizontal, 12) @@ -1211,10 +1211,10 @@ struct EmptyWorkspaceView: View { WeiBeiTheme.paper VStack(spacing: 14) { Image(systemName: "seal") - .font(.system(size: 34, weight: .regular)) + .weiBeiText(34, weight: .regular) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(store.appearanceMode.isDark ? 0.12 : 0.08)) Text(store.ui("在顶栏点亮一个板块开始", "Light up a pane above to begin")) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) } .padding(.bottom, 18) @@ -1237,9 +1237,9 @@ private struct PaneDropTargetView: View { .overlay(alignment: .topLeading) { HStack(spacing: 7) { Image(systemName: role.systemImage) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) Text(role.label(language: store.interfaceLanguage)) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) } .foregroundStyle(WeiBeiTheme.cinnabar) .padding(.horizontal, 10) diff --git a/Sources/WeiBei/Views/CourseDocNoteWorkspaceView.swift b/Sources/WeiBei/Views/CourseDocNoteWorkspaceView.swift index 92244d0c2..49b3d0185 100644 --- a/Sources/WeiBei/Views/CourseDocNoteWorkspaceView.swift +++ b/Sources/WeiBei/Views/CourseDocNoteWorkspaceView.swift @@ -238,10 +238,10 @@ struct CourseDocNoteWorkspaceView: View { private func sectionHeader(title: String, count: Int, kind: CourseRelationLens) -> some View { HStack(spacing: 8) { Text(title) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) Text("\(count)") - .font(.system(size: 11, weight: .medium, design: .monospaced)) + .weiBeiText(11, weight: .medium, design: .monospaced) .foregroundStyle(WeiBeiTheme.tertiaryInk) Spacer(minLength: 0) if let courseID { @@ -297,7 +297,7 @@ struct CourseDocNoteWorkspaceView: View { kind: kind == .materials ? .notes : .materials, counterpart: item ) ? "checkmark.square.fill" : "square") - .font(.system(size: 14, weight: .medium)) + .weiBeiText(14, weight: .medium) .foregroundStyle( isLinked( item: counterpart, @@ -400,12 +400,12 @@ struct CourseDocNoteWorkspaceView: View { .foregroundStyle(WeiBeiTheme.cinnabar) Text(store.displayTitle(for: item)) - .font(.system(size: 16, weight: .semibold)) + .weiBeiText(16, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(2) Text(itemDetail(item)) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) @@ -420,7 +420,7 @@ struct CourseDocNoteWorkspaceView: View { .buttonStyle(WeiBeiTextActionButtonStyle(active: true)) Text(relationCountLabel(for: item, kind: kind)) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) } } @@ -432,14 +432,14 @@ struct CourseDocNoteWorkspaceView: View { Text(kind == .materials ? store.ui("关联笔记", "Linked notes") : store.ui("关联文稿", "Linked docs")) - .font(.system(size: 12.5, weight: .semibold)) + .weiBeiText(12.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Text(store.ui( "勾选即保存;这里只改变文稿—笔记关系,不改变课程归属。", "Checks save immediately. This changes doc–note links, not course membership." )) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) } diff --git a/Sources/WeiBei/Views/CourseHubView.swift b/Sources/WeiBei/Views/CourseHubView.swift index 1122f0c6c..a12e294e4 100644 --- a/Sources/WeiBei/Views/CourseHubView.swift +++ b/Sources/WeiBei/Views/CourseHubView.swift @@ -199,28 +199,24 @@ struct CourseHubView: View { VStack(alignment: .leading, spacing: 22) { VStack(alignment: .leading, spacing: 6) { Text(store.ui("选择一门课程", "Choose a course")) - .font(WeiBeiTypography.brandFont( - language: store.interfaceLanguage, - size: 22, - weight: .semibold - )) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 22, weight: .semibold) Text(store.ui( "进入课程后,可以继续阅读并打开这门课里的文稿、笔记与对话。", "Open a course to resume reading and browse its materials, notes, and chats." )) - .font(.system(size: 12.5)) + .weiBeiText(12.5) .foregroundStyle(WeiBeiTheme.secondaryInk) } if store.courses.isEmpty { VStack(alignment: .leading, spacing: 14) { Text(store.ui("还没有课程", "No courses yet")) - .font(.system(size: 14, weight: .semibold)) + .weiBeiText(14, weight: .semibold) Text(store.ui( "每门课程都有自己的本地项目文件夹,可以容纳多份文稿与笔记。", "Each course has a local project folder for multiple materials and notes." )) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) courseCreationActions @@ -239,7 +235,7 @@ struct CourseHubView: View { } label: { HStack(spacing: 12) { Image(systemName: "book.closed") - .font(.system(size: 14, weight: .medium)) + .weiBeiText(14, weight: .medium) .foregroundStyle( courseWorkspaceAccent(colorIndex: course.colorIndex) ) @@ -255,14 +251,14 @@ struct CourseHubView: View { .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(courseContentCount(for: course.id)) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.secondaryInk) } Spacer(minLength: 8) Image(systemName: "chevron.right") - .font(.system(size: 10, weight: .semibold)) + .weiBeiText(10, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) } .padding(.horizontal, 14) @@ -336,11 +332,7 @@ struct CourseHubView: View { private var continueReadingSection: some View { VStack(alignment: .leading, spacing: 14) { Text(store.ui("继续上次", "Continue where you left off")) - .font(WeiBeiTypography.brandFont( - language: store.interfaceLanguage, - size: 21, - weight: .semibold - )) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 21, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) if let courseID, let reading = continueReading { @@ -416,11 +408,7 @@ struct CourseHubView: View { Text(cleanedSearch.isEmpty ? store.ui("最近内容", "Recent content") : store.ui("搜索结果", "Search results")) - .font(WeiBeiTypography.brandFont( - language: store.interfaceLanguage, - size: 18, - weight: .semibold - )) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 18, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) if !cleanedSearch.isEmpty, !isSearching { @@ -428,7 +416,7 @@ struct CourseHubView: View { "\(searchResults.count) 项", "\(searchResults.count) results" )) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.secondaryInk) } @@ -534,7 +522,7 @@ struct CourseHubView: View { ProgressView() .controlSize(.small) Text(store.ui("正在搜索课程内容…", "Searching course content…")) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) } .frame(minHeight: 62) @@ -551,7 +539,7 @@ struct CourseHubView: View { "部分课程资料无法读取或建立搜索索引,请检查课程文件夹后重试。", "Some course materials could not be read or indexed. Check the course folder and retry." )) - .font(.system(size: 12.5)) + .weiBeiText(12.5) .foregroundStyle(WeiBeiTheme.secondaryInk) Spacer(minLength: 8) @@ -571,7 +559,7 @@ struct CourseHubView: View { "没有找到与“\(cleanedSearch)”相关的课程内容。", "No course content matched “\(cleanedSearch)”." )) - .font(.system(size: 12.5)) + .weiBeiText(12.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(maxWidth: .infinity, minHeight: 72, alignment: .leading) } @@ -600,7 +588,7 @@ struct CourseHubView: View { "这门课还没有文稿、笔记或对话。", "This course has no materials, notes, or chats yet." )) - .font(.system(size: 12.5)) + .weiBeiText(12.5) .foregroundStyle(WeiBeiTheme.secondaryInk) importAndCreateActions @@ -624,9 +612,9 @@ struct CourseHubView: View { "View all materials, notes, and chats" )) Image(systemName: showsAllContent ? "chevron.up" : "chevron.down") - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) } - .font(.system(size: 12.5, weight: .medium)) + .weiBeiText(12.5, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar) .frame(maxWidth: .infinity, minHeight: 52) .contentShape(Rectangle()) @@ -659,7 +647,7 @@ struct CourseHubView: View { private func unavailableCourseRootBanner(reason: String) -> some View { HStack(alignment: .center, spacing: 12) { Image(systemName: "folder.badge.questionmark") - .font(.system(size: 15, weight: .medium)) + .weiBeiText(15, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar) VStack(alignment: .leading, spacing: 3) { @@ -667,9 +655,9 @@ struct CourseHubView: View { "课程文件夹暂时不可用", "Course folder unavailable" )) - .font(.system(size: 12.5, weight: .semibold)) + .weiBeiText(12.5, weight: .semibold) Text(reason) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) } @@ -957,17 +945,17 @@ private struct CourseHubContinueCard: View { var body: some View { HStack(spacing: 18) { Image(systemName: icon) - .font(.system(size: 24, weight: .regular)) + .weiBeiText(24, weight: .regular) .foregroundStyle(WeiBeiTheme.cinnabar) .frame(width: 46) VStack(alignment: .leading, spacing: 6) { Text(title) - .font(.system(size: 17, weight: .semibold)) + .weiBeiText(17, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) } @@ -1005,7 +993,7 @@ private struct CourseHubContinueActionButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(primary ? Color.white : WeiBeiTheme.cinnabar) .padding(.horizontal, 20) .frame(minWidth: 132, minHeight: 42) @@ -1042,16 +1030,16 @@ private struct CourseHubStartReadingRow: View { var body: some View { HStack(spacing: 18) { Image(systemName: "doc.badge.plus") - .font(.system(size: 22, weight: .regular)) + .weiBeiText(22, weight: .regular) .foregroundStyle(WeiBeiTheme.cinnabar) .frame(width: 46) VStack(alignment: .leading, spacing: 5) { Text(title) - .font(.system(size: 15, weight: .semibold)) + .weiBeiText(15, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Text(detail) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) } @@ -1086,7 +1074,7 @@ private struct CourseHubContentRow: View { Button(action: action) { HStack(spacing: 14) { Image(systemName: icon) - .font(.system(size: 14, weight: .medium)) + .weiBeiText(14, weight: .medium) .foregroundStyle(selected ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) @@ -1094,19 +1082,19 @@ private struct CourseHubContentRow: View { VStack(alignment: .leading, spacing: 4) { Text(title) - .font(.system(size: 13.5, weight: selected ? .semibold : .medium)) + .weiBeiText(13.5, weight: selected ? .semibold : .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) if let snippet, !snippet.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { Text(snippet) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.tertiaryInk) .lineLimit(2) } @@ -1115,7 +1103,7 @@ private struct CourseHubContentRow: View { Spacer(minLength: 10) Image(systemName: "chevron.right") - .font(.system(size: 9.5, weight: .semibold)) + .weiBeiText(9.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) } .padding(.horizontal, 12) @@ -1164,17 +1152,17 @@ private struct CourseHubMemoryLine: View { private var content: some View { HStack(spacing: 14) { Image(systemName: icon) - .font(.system(size: 15, weight: .regular)) + .weiBeiText(15, weight: .regular) .foregroundStyle(WeiBeiTheme.cinnabar) .frame(width: 24) Text(title) - .font(.system(size: 13.5, weight: .semibold)) + .weiBeiText(13.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .frame(width: 104, alignment: .leading) Text(text) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle( isPlaceholder ? WeiBeiTheme.tertiaryInk @@ -1185,7 +1173,7 @@ private struct CourseHubMemoryLine: View { if action != nil { Image(systemName: "chevron.right") - .font(.system(size: 9.5, weight: .semibold)) + .weiBeiText(9.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) } } diff --git a/Sources/WeiBei/Views/CourseLibraryVolatilityBanner.swift b/Sources/WeiBei/Views/CourseLibraryVolatilityBanner.swift index 994f5c0f7..c9146d6eb 100644 --- a/Sources/WeiBei/Views/CourseLibraryVolatilityBanner.swift +++ b/Sources/WeiBei/Views/CourseLibraryVolatilityBanner.swift @@ -7,7 +7,7 @@ struct CourseLibraryVolatilityBanner: View { var body: some View { HStack(alignment: .center, spacing: 12) { Image(systemName: "exclamationmark.triangle.fill") - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) .accessibilityHidden(true) @@ -16,11 +16,11 @@ struct CourseLibraryVolatilityBanner: View { "当前资料库位于临时位置,系统可能清理", "The current library is in a temporary location and the system may delete it" )) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) if let path = store.courseLibraryRootPath { Text(path) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) .truncationMode(.middle) diff --git a/Sources/WeiBei/Views/CourseRecordsView.swift b/Sources/WeiBei/Views/CourseRecordsView.swift index f1679e2aa..53291d976 100644 --- a/Sources/WeiBei/Views/CourseRecordsView.swift +++ b/Sources/WeiBei/Views/CourseRecordsView.swift @@ -250,10 +250,10 @@ struct LearningMemoryListSection: View { Image(systemName: "brain.head.profile") .foregroundStyle(WeiBeiTheme.cinnabar) Text(title) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 14, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 14, weight: .semibold) Spacer() Text(store.ui("\(memories.count) 条", "\(memories.count)")) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) } .padding(.horizontal, 16) @@ -264,7 +264,7 @@ struct LearningMemoryListSection: View { Text(search.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? store.ui("还没有形成学习记忆。", "No learning memory yet.") : store.ui("没有匹配的学习记忆。", "No matching learning memory.")) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.horizontal, 16) .padding(.bottom, 14) @@ -325,21 +325,21 @@ struct LearningMemoryListSection: View { VStack(alignment: .leading, spacing: 5) { HStack(spacing: 7) { Text(store.learningMemoryKindLabel(memory.kind)) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) if memory.status == .resolved { Text(store.ui("已解决", "Resolved")) - .font(.system(size: 10, weight: .medium)) + .weiBeiText(10, weight: .medium) .foregroundStyle(WeiBeiTheme.tertiaryInk) } } Text(memory.text) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundStyle(WeiBeiTheme.ink) .multilineTextAlignment(.leading) .fixedSize(horizontal: false, vertical: true) Text(memorySource(memory)) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.tertiaryInk) } .frame(maxWidth: .infinity, alignment: .leading) @@ -403,7 +403,7 @@ private struct LearningMemoryEditSheet: View { var body: some View { VStack(alignment: .leading, spacing: 18) { Text(store.ui("修改学习记忆", "Edit Learning Memory")) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 19, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 19, weight: .semibold) Picker(store.ui("类型", "Kind"), selection: $kind) { ForEach(LearningMemoryKind.allCases, id: \.self) { kind in @@ -412,7 +412,7 @@ private struct LearningMemoryEditSheet: View { } TextEditor(text: $text) - .font(.system(size: 13)) + .weiBeiText(13) .frame(minHeight: 110) .padding(8) .background(WeiBeiTheme.paperInset.opacity(0.45)) @@ -425,7 +425,7 @@ private struct LearningMemoryEditSheet: View { "\(text.count) / 500 字", "\(text.count) / 500 characters" )) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(text.count > 500 ? WeiBeiTheme.cinnabar : WeiBeiTheme.tertiaryInk) .frame(maxWidth: .infinity, alignment: .trailing) diff --git a/Sources/WeiBei/Views/CourseRelationPaperView.swift b/Sources/WeiBei/Views/CourseRelationPaperView.swift index 639292878..336ff6f9a 100644 --- a/Sources/WeiBei/Views/CourseRelationPaperView.swift +++ b/Sources/WeiBei/Views/CourseRelationPaperView.swift @@ -162,7 +162,7 @@ struct CourseRelationPaperView: View { ScrollView(showsIndicators: false) { VStack(alignment: .leading, spacing: 4) { Text(store.ui("按课程", "By course")) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) .padding(.horizontal, 12) .padding(.top, 14) @@ -246,11 +246,11 @@ struct CourseRelationPaperView: View { VStack(alignment: .leading, spacing: 2) { Text(title) - .font(.system(size: 12.5, weight: selected ? .semibold : .medium)) + .weiBeiText(12.5, weight: selected ? .semibold : .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) } @@ -290,10 +290,10 @@ struct CourseRelationPaperView: View { } label: { HStack(spacing: 6) { Text(scopeTitle(effectiveScope)) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .lineLimit(1) Image(systemName: "chevron.down") - .font(.system(size: 9, weight: .bold)) + .weiBeiText(9, weight: .bold) } .foregroundStyle(WeiBeiTheme.ink) .padding(.horizontal, 10) @@ -445,7 +445,7 @@ struct CourseRelationPaperView: View { setZoomScale(zoomScale - 0.1) } label: { Image(systemName: "minus") - .font(.system(size: 10.5, weight: .bold)) + .weiBeiText(10.5, weight: .bold) .frame(width: 30, height: 28) } .buttonStyle(.plain) @@ -455,7 +455,7 @@ struct CourseRelationPaperView: View { zoomControlDivider Text("\(Int((zoomScale * 100).rounded()))%") - .font(.system(size: 10.5, weight: .semibold, design: .monospaced)) + .weiBeiText(10.5, weight: .semibold, design: .monospaced) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 48, height: 28) .accessibilityLabel(store.ui("当前缩放 \(Int((zoomScale * 100).rounded()))%", "Current zoom \(Int((zoomScale * 100).rounded())) percent")) @@ -466,7 +466,7 @@ struct CourseRelationPaperView: View { setZoomScale(zoomScale + 0.1) } label: { Image(systemName: "plus") - .font(.system(size: 10.5, weight: .bold)) + .weiBeiText(10.5, weight: .bold) .frame(width: 30, height: 28) } .buttonStyle(.plain) @@ -481,9 +481,9 @@ struct CourseRelationPaperView: View { } label: { HStack(spacing: 4) { Image(systemName: "arrow.up.left.and.arrow.down.right") - .font(.system(size: 9.5, weight: .semibold)) + .weiBeiText(9.5, weight: .semibold) Text(store.ui("适合", "Fit")) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) } .padding(.horizontal, 9) .frame(height: 28) @@ -621,7 +621,7 @@ struct CourseRelationPaperView: View { ) -> some View { VStack(alignment: .leading, spacing: 10) { Text(title) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.horizontal, 4) @@ -746,7 +746,7 @@ struct CourseRelationPaperView: View { private func hiddenCountBadge(_ count: Int) -> some View { Text(store.ui("其余 \(count) 项已收起", "\(count) more items hidden")) - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.horizontal, 12) .frame(height: 30) @@ -1037,17 +1037,17 @@ private struct CourseRelationPaperNodeView: View { HStack(spacing: 9) { Image(systemName: node.item.symbolName) - .font(.system(size: 14, weight: .semibold)) + .weiBeiText(14, weight: .semibold) .foregroundStyle(iconColor) .frame(width: 18) VStack(alignment: .leading, spacing: 2) { Text(node.item.title) - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detailText) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) } @@ -1107,7 +1107,7 @@ private struct CourseRelationPaperNodeView: View { private func connectionButton(_ state: CourseRelationConnectionState) -> some View { Button(action: connect) { Image(systemName: state == .linked || state == .source ? "minus" : "plus") - .font(.system(size: 10.5, weight: .bold)) + .weiBeiText(10.5, weight: .bold) .foregroundStyle(connectionForeground(state)) .frame(width: 24, height: 24) .background(connectionBackground(state), in: Circle()) diff --git a/Sources/WeiBei/Views/CourseWorkspaceComponents.swift b/Sources/WeiBei/Views/CourseWorkspaceComponents.swift index a8ca72949..f7d86a99c 100644 --- a/Sources/WeiBei/Views/CourseWorkspaceComponents.swift +++ b/Sources/WeiBei/Views/CourseWorkspaceComponents.swift @@ -51,14 +51,10 @@ struct CourseManagementSheet: View { VStack(alignment: .leading, spacing: 18) { VStack(alignment: .leading, spacing: 5) { Text(store.ui("课程设置", "Course Settings")) - .font(WeiBeiTypography.brandFont( - language: store.interfaceLanguage, - size: 21, - weight: .semibold - )) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 21, weight: .semibold) if let course { Text(course.title) - .font(.system(size: 12.5, weight: .medium)) + .weiBeiText(12.5, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) } } @@ -66,10 +62,10 @@ struct CourseManagementSheet: View { if let rootURL { VStack(alignment: .leading, spacing: 7) { Text(store.ui("课程文件夹", "Course Folder")) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) Text(rootURL.path) - .font(.system(size: 11.5, design: .monospaced)) + .weiBeiText(11.5, design: .monospaced) .foregroundStyle(WeiBeiTheme.secondaryInk) .textSelection(.enabled) .lineLimit(3) @@ -92,7 +88,7 @@ struct CourseManagementSheet: View { rootUnavailableReason, systemImage: "folder.badge.questionmark" ) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) } else if rootURL == nil { @@ -103,7 +99,7 @@ struct CourseManagementSheet: View { ), systemImage: "folder.badge.questionmark" ) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) } @@ -111,7 +107,7 @@ struct CourseManagementSheet: View { VStack(alignment: .leading, spacing: 9) { Text(store.ui("危险操作", "Danger Zone")) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) if UnavailableCourseUnregister.shouldOfferUnregister( rootURL: rootURL, @@ -121,7 +117,7 @@ struct CourseManagementSheet: View { UnavailableCourseUnregister.confirmationMessage(chinese: true), UnavailableCourseUnregister.confirmationMessage(chinese: false) )) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) @@ -137,7 +133,7 @@ struct CourseManagementSheet: View { "这会把整个真实课程文件夹及其中内容移到 macOS 废纸篓。只有移动成功后,课程才会从魏碑移除。", "This moves the entire real course folder to the macOS Trash. WeiBei removes the course only after the move succeeds." )) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) @@ -162,7 +158,7 @@ struct CourseManagementSheet: View { "正在安全移动课程文件夹…", "Moving the course folder safely…" )) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) } .accessibilityElement(children: .combine) @@ -173,7 +169,7 @@ struct CourseManagementSheet: View { errorMessage, systemImage: "exclamationmark.triangle" ) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.cinnabar) .fixedSize(horizontal: false, vertical: true) } @@ -320,13 +316,9 @@ struct CourseProjectEntrySheet: View { VStack(alignment: .leading, spacing: 18) { VStack(alignment: .leading, spacing: 6) { Text(heading) - .font(WeiBeiTypography.brandFont( - language: store.interfaceLanguage, - size: 21, - weight: .semibold - )) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 21, weight: .semibold) Text(detail) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) } @@ -348,7 +340,7 @@ struct CourseProjectEntrySheet: View { if let errorMessage { Label(errorMessage, systemImage: "exclamationmark.triangle") - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.cinnabar) .fixedSize(horizontal: false, vertical: true) .accessibilityLabel(Text(store.ui( @@ -449,7 +441,7 @@ struct CourseProjectEntrySheet: View { ?? store.ui("当前无法访问这个资料库。", "This library is currently unavailable."), systemImage: "exclamationmark.triangle" ) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) } else { @@ -457,7 +449,7 @@ struct CourseProjectEntrySheet: View { store.ui("建议选择或新建一个名为“魏碑”的总文件夹。", "Choose or create a top-level WeiBei folder."), systemImage: "folder" ) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) } @@ -493,7 +485,7 @@ struct CourseProjectEntrySheet: View { ), systemImage: "arrow.triangle.2.circlepath" ) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) } else if let selectedFolder { @@ -514,7 +506,7 @@ struct CourseProjectEntrySheet: View { TextField(store.ui("课程名", "Course title"), text: $title) .textFieldStyle(.plain) .focused($titleFocused) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundColor(WeiBeiTheme.ink) .weibeiInputSurface(active: titleFocused, height: 32) .onSubmit(submitCurrentIntent) @@ -538,7 +530,7 @@ struct CourseProjectEntrySheet: View { "已选择 \(selectedImportURLs.count) 项;课程创建后会直接导入。Markdown 会同时出现在文稿与笔记中。", "Selected \(selectedImportURLs.count) item(s). Markdown will appear in both Materials and Notes." )) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) } @@ -551,10 +543,10 @@ struct CourseProjectEntrySheet: View { private func pathLine(label: String, path: String) -> some View { VStack(alignment: .leading, spacing: 4) { Text(label) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) Text(path) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) .truncationMode(.middle) @@ -833,10 +825,10 @@ struct CourseRelationDetailHeader: View { .tracking(0.8) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.76)) Text(title) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 20, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 20, weight: .semibold) .lineLimit(2) Text(detail) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.secondaryInk) } @@ -865,22 +857,22 @@ struct CourseLinkedItemRow: View { var body: some View { HStack(spacing: 11) { Image(systemName: item.kind.systemImage) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 20) VStack(alignment: .leading, spacing: 3) { Text(store.displayTitle(for: item)) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) } Spacer() Text(store.ui("已关联", "Linked")) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar) } .padding(.horizontal, 10) @@ -909,17 +901,17 @@ struct CourseWorkspaceRow: View { Button(action: action) { HStack(spacing: 11) { Image(systemName: icon) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(iconColor) .frame(width: 20) VStack(alignment: .leading, spacing: 3) { Text(title) - .font(.system(size: 13, weight: selected || prominence == .linked ? .semibold : .medium)) + .weiBeiText(13, weight: selected || prominence == .linked ? .semibold : .medium) .foregroundStyle(WeiBeiTheme.ink.opacity(prominence == .dimmed ? 0.55 : 1)) .lineLimit(1) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk.opacity(prominence == .dimmed ? 0.7 : 1)) .lineLimit(1) } @@ -928,7 +920,7 @@ struct CourseWorkspaceRow: View { if !status.isEmpty { Text(status) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(selected || prominence == .linked ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) .multilineTextAlignment(.trailing) .lineLimit(2) @@ -982,7 +974,7 @@ struct RelationSelectionRow: View { Button(action: action) { HStack(spacing: 11) { Image(systemName: checked ? "checkmark.square.fill" : "square") - .font(.system(size: 14, weight: .medium)) + .weiBeiText(14, weight: .medium) .foregroundStyle(checked ? WeiBeiTheme.cinnabar : WeiBeiTheme.tertiaryInk) .frame(width: 20) Image(systemName: item.kind.systemImage) @@ -990,11 +982,11 @@ struct RelationSelectionRow: View { .frame(width: 18) VStack(alignment: .leading, spacing: 2) { Text(store.displayTitle(for: item)) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) } @@ -1002,7 +994,7 @@ struct RelationSelectionRow: View { Text(item.isNotebookNote ? store.ui("笔记", "Note") : item.kind.label(language: store.interfaceLanguage)) - .font(.system(size: 10, weight: .medium)) + .weiBeiText(10, weight: .medium) .foregroundStyle(WeiBeiTheme.tertiaryInk) } .padding(.horizontal, 10) @@ -1028,7 +1020,7 @@ struct CourseDetailSection<Content: View>: View { var body: some View { VStack(alignment: .leading, spacing: 12) { Text(title) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) content } @@ -1046,11 +1038,11 @@ struct CourseContextLine: View { .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 18) Text(label) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 76, alignment: .leading) Text(value) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Spacer() @@ -1075,11 +1067,11 @@ struct CourseActionRow: View { .frame(width: 18) VStack(alignment: .leading, spacing: 3) { Text(title) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) } @@ -1104,21 +1096,21 @@ struct CourseAttentionRow: View { Button(action: action) { HStack(spacing: 12) { Text("\(count)") - .font(.system(size: 15, weight: .semibold, design: .monospaced)) + .weiBeiText(15, weight: .semibold, design: .monospaced) .foregroundStyle(count == 0 ? WeiBeiTheme.tertiaryInk : WeiBeiTheme.cinnabar) .frame(width: 34, alignment: .leading) VStack(alignment: .leading, spacing: 2) { Text(title) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) Text(detail) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) } Spacer() Image(systemName: "chevron.right") - .font(.system(size: 10, weight: .semibold)) + .weiBeiText(10, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) } .padding(.horizontal, 12) @@ -1140,15 +1132,15 @@ struct CourseEmptyState: View { var body: some View { VStack(alignment: alignment, spacing: 8) { Image(systemName: systemImage) - .font(.system(size: 19, weight: .regular)) + .weiBeiText(19, weight: .regular) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.58)) .frame(width: 28, height: 28, alignment: .center) Text(title) - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) .frame(minHeight: 32, alignment: alignment == .leading ? .topLeading : .top) @@ -1172,15 +1164,15 @@ struct CourseHubColumnEmptyState: View { var body: some View { VStack(alignment: .leading, spacing: 10) { Image(systemName: systemImage) - .font(.system(size: 20, weight: .regular)) + .weiBeiText(20, weight: .regular) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.72)) .frame(width: 28, height: 28, alignment: .center) Text(title) - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) Text(detail) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(2) .frame(height: 34, alignment: .topLeading) @@ -1243,19 +1235,19 @@ func relationFooter( ) -> some View { HStack { Text(countTitle) - .font(.system(size: 11.5, weight: .semibold)) + .weiBeiText(11.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) Spacer() if let errorTitle { Text(errorTitle) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.cinnabar) .lineLimit(1) Button(retryTitle, action: retry) .buttonStyle(WeiBeiTextActionButtonStyle(active: true)) } else { Text(statusTitle) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) } } diff --git a/Sources/WeiBei/Views/CourseWorkspaceView.swift b/Sources/WeiBei/Views/CourseWorkspaceView.swift index 2693d096e..a32adec9d 100644 --- a/Sources/WeiBei/Views/CourseWorkspaceView.swift +++ b/Sources/WeiBei/Views/CourseWorkspaceView.swift @@ -341,9 +341,9 @@ private struct CourseNewNoteSheet: View { VStack(alignment: .leading, spacing: 18) { VStack(alignment: .leading, spacing: 6) { Text(store.ui("新建课程笔记", "New course note")) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 20, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 20, weight: .semibold) Text(store.ui("新笔记会写入当前课程文件夹里的“笔记”目录。", "The note will be written to the Notes folder inside this course.")) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) } @@ -352,7 +352,7 @@ private struct CourseNewNoteSheet: View { if let error, !error.isEmpty { Text(error) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.cinnabar) } @@ -390,7 +390,7 @@ struct CourseWorkspaceHeader: View { Image(systemName: "chevron.left") Text(store.ui("返回工作台", "Back to workspace")) } - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(minHeight: 32) .contentShape(Rectangle()) @@ -410,7 +410,7 @@ struct CourseWorkspaceHeader: View { } } label: { Label(page.label(language: store.interfaceLanguage), systemImage: "chevron.down") - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) } .menuStyle(.borderlessButton) .fixedSize() @@ -441,7 +441,7 @@ struct CourseWorkspaceHeader: View { if let saveError = store.workspaceSaveError { Button(action: { _ = store.retryWorkspaceSave() }) { Label(store.ui("保存失败,点此重试", "Save failed, retry"), systemImage: "exclamationmark.triangle") - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar) } .buttonStyle(.plain) @@ -454,7 +454,7 @@ struct CourseWorkspaceHeader: View { TextField(searchPrompt, text: $search) .textFieldStyle(.plain) .focused(searchFocused) - .font(.system(size: 12)) + .weiBeiText(12) } .weibeiInputSurface(active: searchFocused.wrappedValue, height: 30) .frame(width: isCompact ? 160 : 220) @@ -570,7 +570,7 @@ struct CourseWorkspaceTab: View { var body: some View { Button(action: action) { Text(title) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 12.5, weight: active ? .semibold : .medium)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 12.5, weight: active ? .semibold : .medium) .foregroundStyle(active ? WeiBeiTheme.ink : WeiBeiTheme.secondaryInk) .padding(.horizontal, 8) .frame(height: 40) diff --git a/Sources/WeiBei/Views/EmptyWorkspaceLauncherView.swift b/Sources/WeiBei/Views/EmptyWorkspaceLauncherView.swift index bbf9a5552..c682c16f6 100644 --- a/Sources/WeiBei/Views/EmptyWorkspaceLauncherView.swift +++ b/Sources/WeiBei/Views/EmptyWorkspaceLauncherView.swift @@ -160,7 +160,7 @@ struct EmptyWorkspaceLauncherView: View { private func greeting(at date: Date, compact: Bool) -> some View { Text(EmptyWorkspaceDayPeriod.current(at: date).greeting(language: store.interfaceLanguage)) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: compact ? 14.5 : 16, weight: .regular)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: compact ? 14.5 : 16, weight: .regular) .tracking(store.interfaceLanguage == .chinese ? 0.8 : 0.35) .foregroundStyle(EmptyWorkspaceResolvedColor.secondaryInk(liveAppearanceMode).opacity(0.92)) .multilineTextAlignment(.center) @@ -367,7 +367,7 @@ private struct EmptyWorkspaceInspirationView: View { inspirationContent Text(inspiration.credit) - .font(.system(size: compact ? 10.5 : 11.5, weight: .medium, design: .serif)) + .weiBeiText(compact ? 10.5 : 11.5, weight: .medium, design: .serif) .foregroundStyle(WeiBeiTheme.secondaryInk) .multilineTextAlignment(.center) .lineLimit(2) @@ -447,7 +447,7 @@ private struct EmptyWorkspaceInspirationView: View { private func inspirationText(size: CGFloat) -> some View { Text(inspiration.text) - .font(.system(size: size, weight: .regular, design: .serif)) + .weiBeiText(size, weight: .regular, design: .serif) .foregroundStyle(WeiBeiTheme.ink.opacity(0.90)) .multilineTextAlignment(.center) .lineLimit(compact ? 3 : 2) @@ -469,7 +469,7 @@ private struct EmptyWorkspaceInspirationView: View { rightsLink } } - .font(.system(size: compact ? 9 : 9.5, weight: .regular)) + .weiBeiText(compact ? 9 : 9.5, weight: .regular) .foregroundStyle(WeiBeiTheme.tertiaryInk) .multilineTextAlignment(.center) .lineLimit(2) diff --git a/Sources/WeiBei/Views/GeneratedRichAnswerView.swift b/Sources/WeiBei/Views/GeneratedRichAnswerView.swift index 04aa671ec..f2eb16474 100644 --- a/Sources/WeiBei/Views/GeneratedRichAnswerView.swift +++ b/Sources/WeiBei/Views/GeneratedRichAnswerView.swift @@ -264,11 +264,11 @@ private struct GeneratedRichAnswerMetric: View { VStack(alignment: .leading, spacing: 2) { if let label = node.label { Text(label) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) } Text(displayValue) - .font(.system(size: node.emphasis == .strong ? 22 : 18, weight: .semibold, design: .monospaced)) + .weiBeiText(node.emphasis == .strong ? 22 : 18, weight: .semibold, design: .monospaced) .foregroundStyle(generatedToneColor(node.tone)) if let text = node.text, !text.isEmpty { Text(text) @@ -321,7 +321,7 @@ private struct GeneratedRichAnswerSequence: View { VStack(alignment: .leading, spacing: 8) { if let label = node.label, !label.isEmpty { Text(label) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(generatedToneColor(node.tone)) } ViewThatFits(in: .horizontal) { @@ -356,7 +356,7 @@ private struct GeneratedRichAnswerSequence: View { } .frame(height: 18) Text(row.label ?? "") - .font(.system(size: 10.5, weight: isActive(row) ? .semibold : .regular)) + .weiBeiText(10.5, weight: isActive(row) ? .semibold : .regular) .lineLimit(2) .multilineTextAlignment(.center) .foregroundStyle(isActive(row) ? WeiBeiTheme.cinnabar : WeiBeiTheme.ink) @@ -384,7 +384,7 @@ private struct GeneratedRichAnswerSequence: View { marker(index: index, row: row) .padding(.top, 1) Text(row.label ?? "") - .font(.system(size: 11, weight: isActive(row) ? .semibold : .regular)) + .weiBeiText(11, weight: isActive(row) ? .semibold : .regular) .foregroundStyle(isActive(row) ? WeiBeiTheme.cinnabar : WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) } @@ -414,7 +414,7 @@ private struct GeneratedRichAnswerSequence: View { .stroke(active ? WeiBeiTheme.cinnabar : WeiBeiTheme.hairline.opacity(0.74), lineWidth: 1) } Text("\(index + 1)") - .font(.system(size: 8.5, weight: .semibold, design: .monospaced)) + .weiBeiText(8.5, weight: .semibold, design: .monospaced) .foregroundStyle(active ? WeiBeiTheme.onCinnabar : WeiBeiTheme.secondaryInk) } .frame(width: 18, height: 18) @@ -455,11 +455,11 @@ private struct GeneratedRichAnswerControl: View { VStack(alignment: .leading, spacing: 5) { HStack(spacing: 8) { Text(node.label ?? binding.label) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) Spacer(minLength: 8) Text(formattedValue(binding)) - .font(.system(size: 11.5, weight: .medium, design: .monospaced)) + .weiBeiText(11.5, weight: .medium, design: .monospaced) .foregroundStyle(WeiBeiTheme.ink) } Slider( @@ -484,15 +484,15 @@ private struct GeneratedRichAnswerControl: View { ) .toggleStyle(.switch) .controlSize(.small) - .font(.system(size: 11.5, weight: .medium)) + .weiBeiText(11.5, weight: .medium) .accessibilityIdentifier("rich-answer-control-\(node.id)-\(binding.id)") } case .select: HStack(spacing: 6) { Image(systemName: "cursorarrow.click") - .font(.system(size: 10, weight: .semibold)) + .weiBeiText(10, weight: .semibold) Text(node.label ?? "点选图中元素") - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) } .foregroundStyle(WeiBeiTheme.secondaryInk) .accessibilityLabel(node.label ?? "点选图中元素") @@ -560,9 +560,9 @@ private struct GeneratedRichAnswerEvidence: View { } label: { HStack(spacing: 5) { Image(systemName: "arrow.up.right") - .font(.system(size: 8.5, weight: .semibold)) + .weiBeiText(8.5, weight: .semibold) Text(item.sourceLabel) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .lineLimit(1) } .foregroundStyle(WeiBeiTheme.secondaryInk) diff --git a/Sources/WeiBei/Views/LinkedSourcesView.swift b/Sources/WeiBei/Views/LinkedSourcesView.swift index a40bd194e..10eb216b5 100644 --- a/Sources/WeiBei/Views/LinkedSourcesView.swift +++ b/Sources/WeiBei/Views/LinkedSourcesView.swift @@ -32,14 +32,14 @@ struct LinkedSourcesPopover: View { HStack(alignment: .firstTextBaseline) { VStack(alignment: .leading, spacing: 3) { Text(store.ui("这份笔记的资料", "Sources for this note")) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 16, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 16, weight: .semibold) Text(store.ui("选中的资料会一直跟随这份笔记", "Selected sources stay with this note")) .font(.caption) .foregroundStyle(WeiBeiTheme.secondaryInk) } Spacer() Text("\(draftIDs.count)") - .font(.system(size: 18, weight: .medium, design: .serif)) + .weiBeiText(18, weight: .medium, design: .serif) .foregroundStyle(WeiBeiTheme.cinnabar) } @@ -49,7 +49,7 @@ struct LinkedSourcesPopover: View { TextField(store.ui("搜索标题、文件名", "Search title or file name"), text: $query) .textFieldStyle(.plain) } - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(height: 32) if let current = store.selectedMaterialItem { @@ -65,7 +65,7 @@ struct LinkedSourcesPopover: View { ForEach(groupedMaterials, id: \.0) { group in VStack(alignment: .leading, spacing: 4) { Text(group.0) - .font(.system(size: 10, weight: .semibold)) + .weiBeiText(10, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) .padding(.horizontal, 7) ForEach(group.1) { item in diff --git a/Sources/WeiBei/Views/NotesAgentView.swift b/Sources/WeiBei/Views/NotesAgentView.swift index f6368aad7..40871248c 100644 --- a/Sources/WeiBei/Views/NotesAgentView.swift +++ b/Sources/WeiBei/Views/NotesAgentView.swift @@ -119,7 +119,7 @@ struct WeiBeiPaneHeader<Actions: View>: View { } // Always present for accessibility / self-check; hide visually when the strip is narrow. Text(subtitle) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) .truncationMode(.tail) @@ -296,7 +296,7 @@ private struct AgentComposerField: View { if store.agentDraft.isEmpty && !editorActive { Text(prompt) - .font(.system(size: fontSize)) + .weiBeiText(fontSize) .foregroundStyle(WeiBeiTheme.placeholderInk) .frame(maxWidth: .infinity, alignment: .leading) .allowsHitTesting(false) @@ -327,7 +327,7 @@ private struct AgentComposerField: View { if showsModelFooter { HStack(spacing: 10) { Text(store.modelName.isEmpty ? store.ui("模型", "Model") : store.modelName) - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.tertiaryInk) .lineLimit(1) Spacer(minLength: 8) @@ -793,7 +793,7 @@ private struct NotebookCreationPanel: View { var body: some View { HStack(spacing: 9) { Text(draft.kind == .blank ? store.ui("新建笔记", "New Note") : store.ui("资料笔记", "Material Note")) - .font(.system(size: 12.5, weight: .semibold, design: .serif)) + .weiBeiText(12.5, weight: .semibold, design: .serif) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.86)) .lineLimit(1) .fixedSize(horizontal: true, vertical: false) @@ -805,7 +805,7 @@ private struct NotebookCreationPanel: View { .foregroundStyle(WeiBeiTheme.placeholderInk) ) .textFieldStyle(.plain) - .font(.system(size: 14.5, weight: .medium)) + .weiBeiText(14.5, weight: .medium) .foregroundColor(WeiBeiTheme.ink) .focused($focused) .onSubmit(confirm) @@ -816,7 +816,7 @@ private struct NotebookCreationPanel: View { Image(systemName: "checkmark") } .buttonStyle(.plain) - .font(.system(size: 16, weight: .semibold)) + .weiBeiText(16, weight: .semibold) .foregroundStyle(confirmColor) .frame(width: 28, height: 26) .background { @@ -844,7 +844,7 @@ private struct NotebookCreationPanel: View { Image(systemName: "xmark") } .buttonStyle(.plain) - .font(.system(size: 15, weight: .semibold)) + .weiBeiText(15, weight: .semibold) .foregroundStyle(cancelColor) .frame(width: 28, height: 26) .background { @@ -1784,7 +1784,7 @@ struct AgentPaneView: View { } } label: { Image(systemName: "arrow.down") - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink.opacity(0.85)) .frame(width: 34, height: 34) .background(Circle().fill(WeiBeiTheme.paperRaised)) @@ -1829,9 +1829,9 @@ struct AgentPaneView: View { } label: { HStack(spacing: 6) { Image(systemName: "chevron.up") - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) Text(store.ui("查看更早的 \(revealCount) 条消息", "Show \(revealCount) earlier messages")) - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) } .foregroundStyle(isAgentHistoryRevealButtonHovered ? WeiBeiTheme.link : WeiBeiTheme.secondaryInk) .padding(.vertical, 6) @@ -1896,7 +1896,7 @@ struct AgentPaneView: View { store.submitAgentDraft() } } - .font(.system(size: fontSize)) + .weiBeiText(fontSize) .frame(maxWidth: AgentChatLayoutMetrics.wideMaxWidth, alignment: .bottom) .padding(.top, wide ? 6 : 4) .padding(.bottom, wide ? 16 : 12) @@ -2076,9 +2076,9 @@ private struct AgentSelectionAttachmentPill: View { // click is not eaten by hover-popover dismissal. HStack(spacing: 6) { Image(systemName: "text.bubble") - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) Text(store.ui("\(interaction.selectionAttachments.count) 个已选文本片段", "\(interaction.selectionAttachments.count) selected text fragments")) - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) } .contentShape(Rectangle()) .onHover { value in @@ -2088,7 +2088,7 @@ private struct AgentSelectionAttachmentPill: View { Button(action: clearAllAttachments) { Image(systemName: "xmark") - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) } .buttonStyle(WeiBeiIconButtonStyle(size: 18)) .accessibilityLabel(Text(store.ui("清空已选文本片段", "Clear selected text fragments"))) @@ -2132,11 +2132,11 @@ private struct AgentSelectionAttachmentPill: View { VStack(alignment: .leading, spacing: 10) { HStack { Text(store.ui("\(interaction.selectionAttachments.count) 个已选文本片段", "\(interaction.selectionAttachments.count) selected text fragments")) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Spacer() Text(store.ui("发问时会作为上下文", "Used as context when asking")) - .font(.system(size: 10, weight: .medium)) + .weiBeiText(10, weight: .medium) .foregroundStyle(WeiBeiTheme.tertiaryInk) Button(store.ui("清空", "Clear")) { clearAllAttachments() @@ -2166,10 +2166,10 @@ private struct AgentSelectionAttachmentPill: View { VStack(alignment: .leading, spacing: 6) { HStack(spacing: 8) { Text(store.ui("片段 \(index + 1)", "Fragment \(index + 1)")) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Text(selection.ownerTitle) - .font(.system(size: 10, weight: .medium)) + .weiBeiText(10, weight: .medium) .lineLimit(1) .foregroundStyle(WeiBeiTheme.secondaryInk) Spacer(minLength: 8) @@ -2190,7 +2190,7 @@ private struct AgentSelectionAttachmentPill: View { } Text(selection.text) - .font(.system(size: 12)) + .weiBeiText(12) .lineSpacing(3) .lineLimit(5) .foregroundStyle(WeiBeiTheme.ink) @@ -2246,7 +2246,7 @@ private struct FloatingSelectionPreview: View { var body: some View { Text(cleanedText) - .font(.system(size: 11.5, weight: .medium)) + .weiBeiText(11.5, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) .frame(maxWidth: .infinity, alignment: .leading) @@ -2401,7 +2401,7 @@ struct FloatingSelectionAgentView: View { } } } - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .buttonStyle(.plain) .padding(.horizontal, 12) .frame(height: 34) @@ -2448,7 +2448,7 @@ struct FloatingSelectionAgentView: View { .accessibilityLabel(Text(store.ui("就这段提问", "Ask about this passage"))) .help(store.ui("就这段提问", "Ask about this passage")) } - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .buttonStyle(.plain) .padding(.horizontal, 8) .frame(height: 34) @@ -2498,7 +2498,7 @@ struct FloatingSelectionAgentView: View { private var linkEditor: some View { VStack(alignment: .leading, spacing: 10) { Text(store.ui("链接地址", "Link address")) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) TextField("https://", text: $linkDraft) .textFieldStyle(.roundedBorder) .frame(width: 260) @@ -2553,7 +2553,7 @@ struct FloatingSelectionAgentView: View { withAnimation(WeiBeiMotion.micro) { togglePinnedFloatingAgent() } } label: { Image(systemName: store.pinnedFloatingAgent ? "pin.fill" : "pin") - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(store.pinnedFloatingAgent ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) .frame(width: 24, height: 24) } @@ -2567,7 +2567,7 @@ struct FloatingSelectionAgentView: View { closeFloatingAgent() } label: { Image(systemName: "xmark") - .font(.system(size: 10, weight: .bold)) + .weiBeiText(10, weight: .bold) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 24, height: 24) } @@ -2945,7 +2945,7 @@ private struct FloatingSelectionMessageBubble: View { VStack(alignment: .leading, spacing: 0) { if isError { Text(text) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundStyle(WeiBeiTheme.cinnabar) .frame(maxWidth: .infinity, alignment: .leading) .fixedSize(horizontal: false, vertical: true) @@ -3074,7 +3074,7 @@ private struct AgentBubble: View { copyMessage() } label: { Image(systemName: copiedMessage ? "checkmark" : "doc.on.doc") - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(copiedMessage ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) .frame(width: 24, height: 24) .contentShape(Rectangle()) @@ -3088,7 +3088,7 @@ private struct AgentBubble: View { store.regenerateLastAssistantReply() } label: { Image(systemName: "arrow.clockwise") - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 24, height: 24) .contentShape(Rectangle()) @@ -3531,12 +3531,12 @@ private struct RichAnswerNarrativeText: View { switch block.kind { case let .heading(level): Text(attributed(block.text)) - .font(.system(size: level <= 2 ? 21 : 17, weight: .semibold)) + .weiBeiText(level <= 2 ? 21 : 17, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) case .paragraph: Text(attributed(block.text)) - .font(.system(size: 14)) + .weiBeiText(14) .lineSpacing(4) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) @@ -3545,14 +3545,14 @@ private struct RichAnswerNarrativeText: View { Text("•") .foregroundStyle(WeiBeiTheme.cinnabar) Text(attributed(block.text)) - .font(.system(size: 14)) + .weiBeiText(14) .lineSpacing(4) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) } case .quote: Text(attributed(block.text)) - .font(.system(size: 13.5)) + .weiBeiText(13.5) .lineSpacing(3) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) @@ -3679,10 +3679,10 @@ private struct AgentReplyMemoryUpdateTag: View { "Learning memory updated · \(update.memoryIDs.count)" )) Image(systemName: expanded ? "chevron.up" : "chevron.down") - .font(.system(size: 8.5, weight: .bold)) + .weiBeiText(8.5, weight: .bold) .accessibilityHidden(true) } - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) .padding(.horizontal, 9) .frame(height: 25) @@ -3708,7 +3708,7 @@ private struct AgentReplyMemoryUpdateTag: View { ForEach(revisions) { revision in HStack(alignment: .firstTextBaseline, spacing: 7) { Text(store.learningMemoryKindLabel(revision.kind)) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) .fixedSize() Text(revision.text) @@ -3838,7 +3838,7 @@ private struct AgentReplyActionCard: View { private var editableContent: some View { if action.kind == .writeNote { Text(store.ui("建议写入内容:", "Suggested note content:")) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) if let target = store.agentReplyActionTargetTitle(action) { @@ -3852,12 +3852,12 @@ private struct AgentReplyActionCard: View { .weibeiInputSurface(height: 32) TextEditor(text: $bodyText) - .font(.system(size: 12.5)) + .weiBeiText(12.5) .scrollContentBackground(.hidden) .weibeiInputSurface(height: 104, horizontalPadding: 6) } else { Text(store.ui("建议建立关系:", "Suggested relation:")) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) ViewThatFits(in: .horizontal) { HStack(spacing: 8) { @@ -4182,7 +4182,7 @@ private struct AgentReplySourceTagRow: View { Button("+\(sources.count - 1)") { showsMore.toggle() } - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.horizontal, 8) .frame(height: 22) @@ -4237,9 +4237,9 @@ private struct AgentReplySourceTag: View { Button(action: action) { HStack(spacing: 4) { Image(systemName: source.kind.sourceSystemImage) - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) Text(label) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .lineLimit(1) } .foregroundStyle(hovering ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) @@ -4300,31 +4300,31 @@ private struct AgentReplySourceDetail: View { var body: some View { HStack(alignment: .top, spacing: 9) { Image(systemName: source.kind.sourceSystemImage) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.82)) .frame(width: 16) VStack(alignment: .leading, spacing: 4) { HStack(alignment: .firstTextBaseline, spacing: 6) { Text(source.title) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) if let position = source.positionLabel(language: store.interfaceLanguage) { Text(position) - .font(.system(size: 10.5)) + .weiBeiText(10.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(1) } } Text(source.excerpt) - .font(.system(size: 11.5)) + .weiBeiText(11.5) .foregroundStyle(WeiBeiTheme.secondaryInk) .lineLimit(3) .fixedSize(horizontal: false, vertical: true) } Spacer(minLength: 4) Image(systemName: "arrow.up.right") - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) } .padding(.horizontal, 12) @@ -4409,9 +4409,9 @@ private struct AgentCitationTag: View { Button(action: action) { HStack(spacing: 4) { Image(systemName: citation.kind.systemImage) - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) Text(chipLabel) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .lineLimit(1) } .foregroundStyle(foreground) @@ -5132,7 +5132,7 @@ private struct AgentMessageMarkdownText: View { private var nativeBody: some View { Text(renderedText) - .font(.system(size: compact ? 13.2 : (rendersRichMarkdown ? 15 : 14.5))) + .weiBeiText(compact ? 13.2 : (rendersRichMarkdown ? 15 : 14.5)) .lineSpacing(compact ? 4.2 : (rendersRichMarkdown ? 5.5 : 4.5)) .foregroundStyle(WeiBeiTheme.ink) .multilineTextAlignment(.leading) @@ -5293,7 +5293,7 @@ private struct AgentThinkingIndicator: View { Group { if reduceMotion { Text(text) - .font(.system(size: Self.statusFontSize, weight: .medium)) + .weiBeiText(Self.statusFontSize, weight: .medium) .foregroundStyle(WeiBeiTheme.ink.opacity(0.93)) .lineLimit(1) .frame(width: textWidth, height: Self.textLineHeight, alignment: .leading) diff --git a/Sources/WeiBei/Views/ReaderView.swift b/Sources/WeiBei/Views/ReaderView.swift index 73b1ea1f5..767979a34 100644 --- a/Sources/WeiBei/Views/ReaderView.swift +++ b/Sources/WeiBei/Views/ReaderView.swift @@ -155,7 +155,7 @@ struct ImmersiveHoverTitleView<Actions: View>: View { private func renameField(_ titleRename: HoverTitleRename) -> some View { TextField(title, text: titleRename.draft) .textFieldStyle(.plain) - .font(.system(size: 11.8, weight: .medium)) + .weiBeiText(11.8, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .frame(width: 220) .focused($titleFieldFocused) @@ -195,7 +195,7 @@ struct ImmersiveHoverTitleView<Actions: View>: View { private var titleView: some View { Text(title) - .font(.system(size: 11.8, weight: .medium)) + .weiBeiText(11.8, weight: .medium) .lineLimit(1) .truncationMode(.tail) .foregroundStyle(WeiBeiTheme.secondaryInk) @@ -723,7 +723,7 @@ struct ReaderView: View { } } label: { Text(store.ui("已问 · \(threads.count)", "Asked · \(threads.count)")) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.9)) .padding(.horizontal, 8) .frame(height: 22) @@ -827,9 +827,9 @@ struct ReaderView: View { private var pdfTextLayerNotice: some View { HStack(spacing: 7) { Image(systemName: "text.viewfinder") - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) Text(store.ui("未检测到可选文本层", "No selectable text layer")) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) } .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.horizontal, 9) @@ -870,7 +870,7 @@ struct ReaderView: View { .help(store.ui("上一页", "Previous page")) Text(PageNavigator.display(pdfPageIndex, pageCount: pdfPageCount)) - .font(.system(size: 11, weight: .medium, design: .monospaced)) + .weiBeiText(11, weight: .medium, design: .monospaced) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(width: 50, height: 22) @@ -902,10 +902,10 @@ struct ReaderView: View { } label: { HStack(spacing: showsPDFModeLabel ? 5 : 0) { Image(systemName: pdfBrowseMode.systemImage) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) if showsPDFModeLabel { Text(pdfBrowseMode.label(language: store.interfaceLanguage)) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) } } .foregroundStyle(pdfModeForeground) @@ -3335,13 +3335,13 @@ private struct ReaderStateMessage: View { var body: some View { VStack(spacing: 10) { Image(systemName: systemImage) - .font(.system(size: 18, weight: .medium)) + .weiBeiText(18, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.62)) Text(title) - .font(.system(size: 18, weight: .semibold, design: .serif)) + .weiBeiText(18, weight: .semibold, design: .serif) .foregroundStyle(WeiBeiTheme.ink) Text(detail) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .multilineTextAlignment(.center) .lineLimit(2) @@ -3384,14 +3384,14 @@ struct ContextualContentPicker: View { backButton } Text(title) - .font(.system(size: 19, weight: .semibold, design: .serif)) + .weiBeiText(19, weight: .semibold, design: .serif) .foregroundStyle(WeiBeiTheme.ink) .frame(maxWidth: .infinity, alignment: .leading) .padding(.bottom, 3) if visibleRows.isEmpty { Text(emptyText) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(height: 54) } else { @@ -3406,7 +3406,7 @@ struct ContextualContentPicker: View { showsAll = true } .buttonStyle(.plain) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .padding(.top, 3) } @@ -3514,7 +3514,7 @@ struct ContextualContentPicker: View { Label(store.ui("全部", "All"), systemImage: "chevron.left") } .buttonStyle(.plain) - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) .frame(maxWidth: .infinity, alignment: .leading) } @@ -3535,18 +3535,18 @@ struct ContextualContentPicker: View { rowIcon(row) .frame(width: 18) Text(row.title(store: store, kind: kind)) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .foregroundStyle(WeiBeiTheme.ink) .lineLimit(1) .truncationMode(.middle) Spacer(minLength: 8) if let count = row.count { Text("\(count)") - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .foregroundStyle(WeiBeiTheme.tertiaryInk) } Image(systemName: row.isContainer ? "chevron.right" : "arrow.up.right") - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk.opacity(0.72)) } .padding(.horizontal, 17) @@ -3595,11 +3595,11 @@ struct ContextualContentPicker: View { .frame(width: 11, height: 11) case .common: Image(systemName: "tray.full") - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.78)) case .item(let item): Image(systemName: item.isNotebookNote ? "note.text" : "doc.text") - .font(.system(size: 12, weight: .medium)) + .weiBeiText(12, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) } } diff --git a/Sources/WeiBei/Views/RichAnswerHost.swift b/Sources/WeiBei/Views/RichAnswerHost.swift index 034eb9743..8cf540cfa 100644 --- a/Sources/WeiBei/Views/RichAnswerHost.swift +++ b/Sources/WeiBei/Views/RichAnswerHost.swift @@ -221,7 +221,7 @@ struct RichAnswerHost: View { selectedSceneID = scene.id } label: { Text(scenePickerLabel(scene)) - .font(.system(size: 11.5, weight: isSelected ? .semibold : .medium)) + .weiBeiText(11.5, weight: isSelected ? .semibold : .medium) .foregroundStyle(isSelected ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) .padding(.horizontal, 4) .padding(.vertical, 7) @@ -410,11 +410,11 @@ private struct TextAlignmentSceneView: View { } label: { VStack(alignment: .leading, spacing: 3) { Text(object.label) - .font(.system(size: 12.5, weight: .semibold)) + .weiBeiText(12.5, weight: .semibold) .foregroundStyle(selectedObjectID == object.id ? WeiBeiTheme.cinnabar : WeiBeiTheme.ink) if let text = object.text, !text.isEmpty { Text(text) - .font(.system(size: 13.5)) + .weiBeiText(13.5) .lineSpacing(4) .foregroundStyle(WeiBeiTheme.secondaryInk) .fixedSize(horizontal: false, vertical: true) @@ -526,7 +526,7 @@ private struct QuantityCoordinateSceneView: View { .foregroundStyle(WeiBeiTheme.secondaryInk) Spacer(minLength: 8) Text(parameterText(parameter, value: adjustmentValue(for: operation, parameter: parameter))) - .font(.system(size: 11, design: .monospaced)) + .weiBeiText(11, design: .monospaced) .foregroundStyle(WeiBeiTheme.ink) if let resetOperation { Button(resetOperation.label) { @@ -553,7 +553,7 @@ private struct QuantityCoordinateSceneView: View { Slider(value: $fallbackProbeValue, in: 0...1) .tint(WeiBeiTheme.cinnabar) Text(String(format: "%.0f%%", fallbackProbeValue * 100)) - .font(.system(size: 11, design: .monospaced)) + .weiBeiText(11, design: .monospaced) .foregroundStyle(WeiBeiTheme.secondaryInk) } } @@ -696,7 +696,7 @@ private struct ProcessStateSceneView: View { let object = processObjects.indices.contains(activeIndex) ? processObjects[activeIndex] : processObjects.first return VStack(alignment: .leading, spacing: 4) { Text(object?.label ?? "未选择步骤") - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Text(object?.text ?? "这里仅切换本地步骤观察状态,不推断新的过程结果。") .font(.caption) @@ -719,7 +719,7 @@ private struct ProcessStateSceneView: View { } .buttonStyle(WeiBeiTextActionButtonStyle()) Text("\(min(activeIndex + 1, max(processObjects.count, 1))) / \(max(processObjects.count, 1))") - .font(.system(size: 11, design: .monospaced)) + .weiBeiText(11, design: .monospaced) .foregroundStyle(WeiBeiTheme.secondaryInk) Button("下一步") { isPlaying = false @@ -832,10 +832,10 @@ private struct RelationEvidenceSceneView: View { if let relation = focusedRelation { HStack(alignment: .top, spacing: 8) { Text(relation.kind.label) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(relationColor(relation.kind)) Text("\(objectLabel(relation.sourceID)) → \(objectLabel(relation.targetID))") - .font(.system(size: 12.5, weight: .semibold)) + .weiBeiText(12.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) if let label = relation.label, !label.isEmpty { Text(label) @@ -997,7 +997,7 @@ private struct RelationMapNode: View { var body: some View { Button(action: action) { Text(object.label) - .font(.system(size: 11.5, weight: .semibold)) + .weiBeiText(11.5, weight: .semibold) .multilineTextAlignment(.center) .foregroundStyle(focused ? WeiBeiTheme.ink : WeiBeiTheme.secondaryInk) .lineLimit(3) @@ -1151,7 +1151,7 @@ private struct ImageOverlaySceneView: View { Slider(value: $zoomScale, in: 1...2.4, step: 0.1) .tint(WeiBeiTheme.cinnabar) Text(String(format: "%.1f×", zoomScale)) - .font(.system(size: 11, design: .monospaced)) + .weiBeiText(11, design: .monospaced) .foregroundStyle(WeiBeiTheme.secondaryInk) Button("复位") { zoomScale = 1 @@ -1194,10 +1194,10 @@ private struct ImageOverlaySceneView: View { } else { VStack(spacing: 5) { Image(systemName: "photo.on.rectangle.angled") - .font(.system(size: 24)) + .weiBeiText(24) .foregroundStyle(WeiBeiTheme.tertiaryInk) Text("当前素材无法在回答中预览") - .font(.system(size: 12.5, weight: .semibold)) + .weiBeiText(12.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) Text("保留区域说明,并可打开原始素材核对。") .font(.caption) @@ -1318,7 +1318,7 @@ private struct ComparisonEvaluationSceneView: View { selectedObjectID = object.id } label: { Text(object.label) - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .foregroundStyle(selectedObjectID == object.id ? WeiBeiTheme.cinnabar : WeiBeiTheme.ink) .frame(maxWidth: .infinity, alignment: .leading) } @@ -1448,7 +1448,7 @@ private struct CalculationConstraintSceneView: View { .font(.system(size: 10, weight: .semibold, design: .monospaced)) .foregroundStyle(WeiBeiTheme.cinnabar) Text(object.text ?? objectValueText(object)) - .font(.system(size: 12.5, design: .monospaced)) + .weiBeiText(12.5, design: .monospaced) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) } @@ -1470,7 +1470,7 @@ private struct CalculationConstraintSceneView: View { .foregroundStyle(WeiBeiTheme.secondaryInk) Spacer(minLength: 8) Text(parameterText(parameter, value: value(for: parameter))) - .font(.system(size: 11, design: .monospaced)) + .weiBeiText(11, design: .monospaced) .foregroundStyle(WeiBeiTheme.tertiaryInk) } Slider( @@ -1498,14 +1498,14 @@ private struct CalculationConstraintSceneView: View { value: parameterText(parameter, value: value(for: parameter)) ) Image(systemName: "arrow.right") - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) resultValue(label: operation.label, value: resultText(result, for: operation)) } } Spacer(minLength: 0) Text("确定性结果") - .font(.system(size: 9.5, weight: .semibold)) + .weiBeiText(9.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) } } @@ -1597,10 +1597,10 @@ private struct CalculationConstraintSceneView: View { private func resultValue(label: String, value: String) -> some View { VStack(alignment: .leading, spacing: 1) { Text(label) - .font(.system(size: 9.5, weight: .medium)) + .weiBeiText(9.5, weight: .medium) .foregroundStyle(WeiBeiTheme.secondaryInk) Text(value) - .font(.system(size: 18, weight: .semibold, design: .monospaced)) + .weiBeiText(18, weight: .semibold, design: .monospaced) .foregroundStyle(WeiBeiTheme.ink) } } @@ -1642,7 +1642,7 @@ private struct SceneTitle: View { var body: some View { Text(scene.title) - .font(.system(size: 15.5, weight: .semibold)) + .weiBeiText(15.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .fixedSize(horizontal: false, vertical: true) } @@ -1725,7 +1725,7 @@ private struct CoordinateCanvas: View { HStack(spacing: 10) { ForEach(scene.frames.prefix(2), id: \.id) { frame in Text(frameAxisLabel(frame)) - .font(.system(size: 10.5, design: .monospaced)) + .weiBeiText(10.5, design: .monospaced) .foregroundStyle(WeiBeiTheme.tertiaryInk) } } @@ -1885,7 +1885,7 @@ private struct TimelineCanvas: View { } symbols: { ForEach(timelineObjects.map(\.object), id: \.id) { object in Text(object.label) - .font(.system(size: 9.5, weight: .medium)) + .weiBeiText(9.5, weight: .medium) .foregroundStyle(layerIsVisible(for: object) ? WeiBeiTheme.secondaryInk : WeiBeiTheme.tertiaryInk.opacity(0.30)) .lineLimit(2) .frame(width: 92) @@ -1952,7 +1952,7 @@ private struct SpatialMapCanvas: View { } symbols: { ForEach(visibleObjects, id: \.id) { object in Text(object.label) - .font(.system(size: 9.5, weight: .medium)) + .weiBeiText(9.5, weight: .medium) .foregroundStyle(layerIsVisible(for: object) ? WeiBeiTheme.secondaryInk : WeiBeiTheme.tertiaryInk.opacity(0.30)) .lineLimit(2) .frame(width: 96, alignment: .leading) @@ -2016,7 +2016,7 @@ private struct ImageRegionOverlay: View { } symbols: { ForEach(scene.objects.filter { $0.bounds != nil }, id: \.id) { object in Text(object.label) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(selectedRegionID == object.id ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) .padding(.horizontal, 5) .padding(.vertical, 3) @@ -2072,7 +2072,7 @@ private struct RichAnswerEvidenceLedger: View { if !evidence.isEmpty { VStack(alignment: .leading, spacing: 7) { Text("来源索引") - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) EvidenceStrip(evidence: evidence, onOpenEvidence: onOpenEvidence) } @@ -2091,18 +2091,18 @@ private struct EvidenceChip: View { } label: { HStack(spacing: 5) { Image(systemName: "arrow.up.right") - .font(.system(size: 8.5, weight: .semibold)) + .weiBeiText(8.5, weight: .semibold) Text(evidence.sourceLabel) - .font(.system(size: 10.5, weight: .medium)) + .weiBeiText(10.5, weight: .medium) .lineLimit(1) ForEach(Array(evidence.tags).sorted().prefix(2), id: \.self) { tag in Text(tag) - .font(.system(size: 9.5)) + .weiBeiText(9.5) .foregroundStyle(WeiBeiTheme.secondaryInk) } if evidence.isTruncated { Text("截断") - .font(.system(size: 9.5)) + .weiBeiText(9.5) .foregroundStyle(WeiBeiTheme.cinnabar) } } diff --git a/Sources/WeiBei/Views/RichAnswerWebRuntimeView.swift b/Sources/WeiBei/Views/RichAnswerWebRuntimeView.swift index 382f114b1..c0b71c2ef 100644 --- a/Sources/WeiBei/Views/RichAnswerWebRuntimeView.swift +++ b/Sources/WeiBei/Views/RichAnswerWebRuntimeView.swift @@ -144,9 +144,9 @@ struct RichAnswerWebRuntimeView: View { if runtimeError != nil { VStack(alignment: .leading, spacing: 3) { Label("这项富回答无法显示", systemImage: "exclamationmark.triangle") - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) Text("请继续阅读正文,稍后可重试这项视觉。") - .font(.system(size: 10)) + .weiBeiText(10) .foregroundStyle(WeiBeiTheme.secondaryInk) } .accessibilityElement(children: .combine) @@ -157,7 +157,7 @@ struct RichAnswerWebRuntimeView: View { onRequestExpansion() } label: { Label("放大操作", systemImage: "arrow.up.left.and.arrow.down.right") - .font(.system(size: 11, weight: .medium)) + .weiBeiText(11, weight: .medium) .symbolRenderingMode(.hierarchical) } .buttonStyle(.plain) diff --git a/Sources/WeiBei/Views/Settings/AgentModelPicker.swift b/Sources/WeiBei/Views/Settings/AgentModelPicker.swift index b44df89f5..7e45d2798 100644 --- a/Sources/WeiBei/Views/Settings/AgentModelPicker.swift +++ b/Sources/WeiBei/Views/Settings/AgentModelPicker.swift @@ -20,7 +20,7 @@ extension SettingsView { HStack(spacing: 8) { if oauthService.isRefreshingCatalog { Image(systemName: "arrow.triangle.2.circlepath") - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) // Continuous spin while loading: drive via a monotonically increasing // angle that animates itself each cycle. @@ -38,7 +38,7 @@ extension SettingsView { requestModelListRefresh(force: true) } label: { Image(systemName: "arrow.clockwise") - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) } .buttonStyle(WeiBeiTextActionButtonStyle(active: !oauthService.isRefreshingCatalog)) .help(store.ui("重新获取模型列表", "Refresh model list")) @@ -99,11 +99,11 @@ extension SettingsView { private var modelStatusLine: some View { if oauthService.isRefreshingCatalog { Text(store.ui("正在获取模型…", "Fetching models…")) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.tertiaryInk) } else if let message = oauthService.catalogError { Text(message) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.tertiaryInk) .frame(maxWidth: 260, alignment: .trailing) .lineLimit(2) diff --git a/Sources/WeiBei/Views/Settings/AgentSettingsView.swift b/Sources/WeiBei/Views/Settings/AgentSettingsView.swift index d3945e7dd..119b40f37 100644 --- a/Sources/WeiBei/Views/Settings/AgentSettingsView.swift +++ b/Sources/WeiBei/Views/Settings/AgentSettingsView.swift @@ -76,7 +76,7 @@ extension SettingsView { ) .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: false, height: 38) .frame(width: SettingsView.controlWidth) } @@ -146,7 +146,7 @@ extension SettingsView { ) .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: true, height: 30) .frame(width: 140) .onSubmit { commitProfileRename() } @@ -252,7 +252,7 @@ extension SettingsView { .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) .focused($focusedField, equals: .apiKey) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: focusedField == .apiKey, height: 38) .frame(width: SettingsView.controlWidth) .onSubmit { saveActiveAPIKey() } @@ -438,7 +438,7 @@ extension SettingsView { if let prompt = oauthService.pendingPrompt { VStack(alignment: .trailing, spacing: 8) { Text(prompt.message) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) .multilineTextAlignment(.trailing) .fixedSize(horizontal: false, vertical: true) @@ -459,7 +459,7 @@ extension SettingsView { ) .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: true, height: 38) .frame(width: SettingsView.controlWidth) .onSubmit { oauthService.submitPrompt() } @@ -473,7 +473,7 @@ extension SettingsView { ) .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: true, height: 38) .frame(width: SettingsView.controlWidth) .onSubmit { oauthService.submitPrompt() } @@ -610,7 +610,7 @@ extension SettingsView { private var agentManualModelSheet: some View { VStack(alignment: .leading, spacing: 16) { Text(store.ui("手动输入模型 ID", "Enter model id")) - .font(.system(size: 15, weight: .semibold)) + .weiBeiText(15, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) TextField( "", @@ -624,7 +624,7 @@ extension SettingsView { ) .textFieldStyle(.plain) .foregroundColor(WeiBeiTheme.ink) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: true, height: 38) HStack { Spacer() diff --git a/Sources/WeiBei/Views/Settings/SettingsView.swift b/Sources/WeiBei/Views/Settings/SettingsView.swift index f422863a7..f53ce4f3c 100644 --- a/Sources/WeiBei/Views/Settings/SettingsView.swift +++ b/Sources/WeiBei/Views/Settings/SettingsView.swift @@ -163,7 +163,7 @@ struct SettingsView: View { private var settingsSidebar: some View { VStack(alignment: .leading, spacing: 16) { Text(store.ui("设置", "Settings")) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 20, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 20, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) .padding(.horizontal, 22) .padding(.top, 22) @@ -210,7 +210,7 @@ struct SettingsView: View { private var settingsHeader: some View { HStack(alignment: .center) { Text(selectedSection.title(store)) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 17, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 17, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Spacer() } @@ -270,6 +270,24 @@ struct SettingsView: View { } settingsGroup(store.ui("偏好", "Preferences")) { + settingsRow( + title: store.ui("界面文字大小", "Interface Text Size"), + detail: store.ui( + "调整整个界面的文字大小,笔记正文同步缩放", + "Scales text across the interface; note content follows" + ), + showsBottomDivider: false + ) { + compactMenu(store.interfaceTextScale.label(language: store.interfaceLanguage)) { + ForEach(WeiBeiTypography.TextScale.allCases) { scale in + Button( + "\(scale.label(language: store.interfaceLanguage)) · \(Int((scale.multiplier * 100).rounded()))%" + ) { + store.setInterfaceTextScale(scale) + } + } + } + } settingsRow( title: store.ui("今日一句", "Today's line"), showsBottomDivider: false @@ -456,14 +474,14 @@ struct SettingsView: View { if selected { Image(systemName: "checkmark.circle.fill") - .font(.system(size: 15, weight: .semibold)) + .weiBeiText(15, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar) .padding(7) } } Text(mode.label(language: store.interfaceLanguage)) - .font(.system(size: 12, weight: selected ? .semibold : .medium)) + .weiBeiText(12, weight: selected ? .semibold : .medium) .foregroundStyle(selected ? WeiBeiTheme.ink : WeiBeiTheme.secondaryInk) .lineLimit(1) } @@ -534,7 +552,7 @@ struct SettingsView: View { Text(recording ? store.ui("按下…", "Press…") : chord.display) - .font(.system(size: 11, weight: .semibold, design: .monospaced)) + .weiBeiText(11, weight: .semibold, design: .monospaced) .foregroundStyle(recording ? WeiBeiTheme.cinnabar : WeiBeiTheme.secondaryInk) .padding(.horizontal, 7) .frame(height: 22) @@ -701,7 +719,7 @@ struct SettingsView: View { private var feedbackSheet: some View { VStack(alignment: .leading, spacing: 14) { Text(store.ui("提交反馈", "Send Feedback")) - .font(.system(size: 15, weight: .semibold)) + .weiBeiText(15, weight: .semibold) .foregroundStyle(WeiBeiTheme.ink) Text(store.ui( @@ -718,21 +736,21 @@ struct SettingsView: View { .foregroundStyle(WeiBeiTheme.placeholderInk) ) .textFieldStyle(.plain) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundColor(WeiBeiTheme.ink) .weibeiInputSurface(active: true, height: 34) ZStack(alignment: .topLeading) { if feedbackBody.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { Text(store.ui("发生了什么?如何复现?", "What happened? How can we reproduce it?")) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundStyle(WeiBeiTheme.placeholderInk) .padding(.horizontal, 10) .padding(.vertical, 10) .allowsHitTesting(false) } TextEditor(text: $feedbackBody) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundColor(WeiBeiTheme.ink) .scrollContentBackground(.hidden) .frame(minHeight: 140, maxHeight: 200) @@ -896,7 +914,7 @@ struct SettingsView: View { } label: { HStack(spacing: 10) { Image(systemName: section.icon) - .font(.system(size: 13, weight: .semibold)) + .weiBeiText(13, weight: .semibold) .frame(width: 18) Text(section.title(store)) .font(SettingsType.rowTitle(active: active)) @@ -974,7 +992,7 @@ struct SettingsView: View { func settingsNote(_ text: String, icon: String) -> some View { HStack(alignment: .firstTextBaseline, spacing: 8) { Image(systemName: icon) - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.90)) Text(text) .font(SettingsType.detail) @@ -989,7 +1007,7 @@ struct SettingsView: View { func settingsPill(title: String, icon: String, active: Bool) -> some View { HStack(spacing: 7) { Image(systemName: icon) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) Text(title) .font(SettingsType.pill) .lineLimit(1) @@ -1031,7 +1049,7 @@ struct SettingsView: View { .font(SettingsType.menu) .lineLimit(1) Image(systemName: "chevron.down") - .font(.system(size: 8, weight: .bold)) + .weiBeiText(8, weight: .bold) } .foregroundStyle(WeiBeiTheme.ink) .padding(.horizontal, 9) @@ -1050,7 +1068,7 @@ struct SettingsView: View { /// Shared Settings group title label. func sectionTitle(_ title: String) -> some View { Text(title) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 12, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 12, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) } } diff --git a/Sources/WeiBei/Views/SidebarView.swift b/Sources/WeiBei/Views/SidebarView.swift index cd3536d01..c05a7b5d8 100644 --- a/Sources/WeiBei/Views/SidebarView.swift +++ b/Sources/WeiBei/Views/SidebarView.swift @@ -69,9 +69,9 @@ struct SidebarView: View { HStack(spacing: 3) { Text(ui("课程空间", "Course Space")) Image(systemName: "chevron.right") - .font(.system(size: 8, weight: .bold)) + .weiBeiText(8, weight: .bold) } - .font(.system(size: 12, weight: .semibold)) + .weiBeiText(12, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.82)) } .buttonStyle(.plain) @@ -117,7 +117,7 @@ struct SidebarView: View { .textFieldStyle(.plain) .focused($librarySearchFocused) .foregroundColor(WeiBeiTheme.ink) - .font(.system(size: 13)) + .weiBeiText(13) .weibeiInputSurface(active: librarySearchFocused) .padding(.horizontal, 14) .padding(.bottom, 10) @@ -247,7 +247,7 @@ struct CourseSidebarList: View { Button { store.openCourseSpace(course.id) } label: { Text(ui("进入", "Enter")) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.88)) .padding(.horizontal, 8) .frame(height: 28) @@ -484,7 +484,7 @@ private struct SidebarSectionHeader: View { var body: some View { Text(title) - .font(.system(size: 11, weight: .semibold)) + .weiBeiText(11, weight: .semibold) .foregroundStyle(WeiBeiTheme.tertiaryInk) .textCase(nil) } @@ -495,7 +495,7 @@ private struct SidebarEmptyRow: View { var body: some View { Text(title) - .font(.system(size: 11)) + .weiBeiText(11) .foregroundStyle(WeiBeiTheme.tertiaryInk.opacity(0.78)) .frame(height: 28, alignment: .leading) } @@ -512,19 +512,19 @@ private struct SidebarCourseGroupHeader: View { var body: some View { HStack(spacing: 5) { Image(systemName: systemImage) - .font(.system(size: 9.5, weight: .semibold)) + .weiBeiText(9.5, weight: .semibold) .foregroundStyle(accent.opacity(0.74)) Text(title) - .font(.system(size: 10.5, weight: .semibold)) + .weiBeiText(10.5, weight: .semibold) .foregroundStyle(WeiBeiTheme.secondaryInk) Spacer(minLength: 4) Text("\(count)") - .font(.system(size: 9.5, weight: .medium, design: .monospaced)) + .weiBeiText(9.5, weight: .medium, design: .monospaced) .foregroundStyle(WeiBeiTheme.tertiaryInk) if let add { Button(action: add) { Image(systemName: "plus") - .font(.system(size: 9.5, weight: .semibold)) + .weiBeiText(9.5, weight: .semibold) } .buttonStyle(.plain) .foregroundStyle(accent.opacity(0.82)) @@ -561,7 +561,7 @@ private struct SidebarCourseRow: View { .scaleEffect(expanded || hovering ? 1.08 : 1) VStack(alignment: .leading, spacing: 2) { Text(course.title) - .font(.system(size: 13, weight: .medium)) + .weiBeiText(13, weight: .medium) .lineLimit(1) .foregroundStyle(WeiBeiTheme.ink) Text(language.text( @@ -574,7 +574,7 @@ private struct SidebarCourseRow: View { } Spacer(minLength: 6) Image(systemName: "chevron.right") - .font(.system(size: 9, weight: .semibold)) + .weiBeiText(9, weight: .semibold) .foregroundStyle(expanded ? accent.opacity(0.78) : WeiBeiTheme.tertiaryInk) .rotationEffect(.degrees(expanded ? 90 : 0)) } @@ -614,15 +614,15 @@ private struct SidebarCourseNameSheet: View { VStack(alignment: .leading, spacing: 18) { VStack(alignment: .leading, spacing: 5) { Text(heading) - .font(WeiBeiTypography.brandFont(language: store.interfaceLanguage, size: 21, weight: .semibold)) + .weiBeiBrandFont(language: store.interfaceLanguage, size: 21, weight: .semibold) Text(detail) - .font(.system(size: 12)) + .weiBeiText(12) .foregroundStyle(WeiBeiTheme.secondaryInk) } TextField(store.ui("课程名", "Course title"), text: $title) .textFieldStyle(.plain) .focused($titleFocused) - .font(.system(size: 13)) + .weiBeiText(13) .foregroundColor(WeiBeiTheme.ink) .weibeiInputSurface(active: titleFocused, height: 32) .onSubmit(confirm) @@ -674,7 +674,7 @@ private struct NotebookRenameRow: View { ) .textFieldStyle(.plain) .focused($focused) - .font(.system(size: compact ? 12.5 : 13, weight: .medium)) + .weiBeiText(compact ? 12.5 : 13, weight: .medium) .foregroundColor(WeiBeiTheme.ink) .onSubmit { if !title.wrappedValue.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { @@ -717,7 +717,7 @@ private struct LibraryRow: View { .opacity(selected || hovering ? 1 : 0.78) VStack(alignment: .leading, spacing: compact ? 1 : 2) { Text(resolvedTitle ?? item.title) - .font(.system(size: compact ? 12.5 : 13, weight: compact ? .medium : .regular)) + .weiBeiText(compact ? 12.5 : 13, weight: compact ? .medium : .regular) .lineLimit(1) .foregroundStyle(WeiBeiTheme.ink) Text(item.subtitle) @@ -726,7 +726,7 @@ private struct LibraryRow: View { .lineLimit(1) if !compact, !tags.isEmpty { Text(tags.prefix(3).joined(separator: " ")) - .font(.system(size: 10, weight: .medium)) + .weiBeiText(10, weight: .medium) .foregroundStyle(WeiBeiTheme.cinnabar.opacity(0.72)) .lineLimit(1) } diff --git a/Sources/WeiBei/WebEditor/src/editor.ts b/Sources/WeiBei/WebEditor/src/editor.ts index 3de411992..9cf39d6ee 100644 --- a/Sources/WeiBei/WebEditor/src/editor.ts +++ b/Sources/WeiBei/WebEditor/src/editor.ts @@ -467,6 +467,14 @@ const setReduceMotionInternal = (next: unknown) => { document.documentElement.dataset.weibeiReduceMotion = next === true || next === 'true' ? 'true' : 'false'; }; +/** Native text-scale sync: drives --weibei-text-scale so editor body copy + * follows the app-wide interface text tier without a reload. */ +const setTextScaleInternal = (next: unknown) => { + const value = Number(next); + const scale = Number.isFinite(value) && value > 0 ? value : 1; + document.documentElement.style.setProperty('--weibei-text-scale', String(scale)); +}; + /** Returns the `/query` immediately before the caret without consuming surrounding content. */ const slashContextForView = (view: any) => { if (!isEditable || view.composing) return null; @@ -3385,6 +3393,7 @@ window.WeiBeiEditor = { setTheme: setThemeInternal, setInterfaceLanguage: setLanguageInternal, setReduceMotion: setReduceMotionInternal, + setTextScale: setTextScaleInternal, focus: focusInternal, scrollToHeading: scrollToHeadingInternal, }), @@ -3412,6 +3421,7 @@ if (WEIBEI_EDITOR_RUNTIME && window.weiBeiEditorCheckMode) { setTheme: setThemeInternal, setInterfaceLanguage: setLanguageInternal, setReduceMotion: setReduceMotionInternal, + setTextScale: setTextScaleInternal, focus: focusInternal, scrollToHeading: scrollToHeadingInternal, }); diff --git a/Sources/WeiBeiCore/WorkspaceModels.swift b/Sources/WeiBeiCore/WorkspaceModels.swift index 465b4a280..0be6093b4 100644 --- a/Sources/WeiBeiCore/WorkspaceModels.swift +++ b/Sources/WeiBeiCore/WorkspaceModels.swift @@ -1938,6 +1938,7 @@ public struct PersistedWorkspace: Codable, Sendable { public var appearanceModeRaw: String? public var adaptImportedDocumentColors: Bool? public var interfaceLanguageRaw: String? + public var interfaceTextScaleRaw: String? public init( importedItems: [StudyItem] = [], @@ -1985,7 +1986,8 @@ public struct PersistedWorkspace: Codable, Sendable { showDailyInspiration: Bool? = nil, appearanceModeRaw: String? = nil, adaptImportedDocumentColors: Bool? = nil, - interfaceLanguageRaw: String? = nil + interfaceLanguageRaw: String? = nil, + interfaceTextScaleRaw: String? = nil ) { self.importedItems = importedItems self.notesByItemID = notesByItemID @@ -2033,6 +2035,7 @@ public struct PersistedWorkspace: Codable, Sendable { self.appearanceModeRaw = appearanceModeRaw self.adaptImportedDocumentColors = adaptImportedDocumentColors self.interfaceLanguageRaw = interfaceLanguageRaw + self.interfaceTextScaleRaw = interfaceTextScaleRaw } } diff --git a/Sources/WeiBeiSelfCheck/main.swift b/Sources/WeiBeiSelfCheck/main.swift index 87a331fd2..c57c130d9 100644 --- a/Sources/WeiBeiSelfCheck/main.swift +++ b/Sources/WeiBeiSelfCheck/main.swift @@ -114,6 +114,7 @@ try checkNotePersistenceScenes() try checkImportIdentityScenes() try checkLibraryRelativeStorage() try checkImportCopySemantics() +try checkInterfaceTextScalePersistence() try checkWorkspaceSafetyScenes() expect(EmptyWorkspaceDayPeriod(hour: 5) == .morning @@ -2370,4 +2371,17 @@ func checkImportCopySemantics() throws { expect(sizeMismatchCopy != sizeMismatchTarget, "size mismatch short-circuits to a unique copy without byte comparison") } +func checkInterfaceTextScalePersistence() throws { + func roundTrip(_ raw: String?) throws -> String? { + let snapshot = PersistedWorkspace(appearanceModeRaw: "paper", interfaceLanguageRaw: "chinese", interfaceTextScaleRaw: raw) + let data = try JSONEncoder().encode(snapshot) + return try JSONDecoder().decode(PersistedWorkspace.self, from: data).interfaceTextScaleRaw + } + let persistedRaw = try roundTrip("extraLarge") + expect(persistedRaw == "extraLarge", "text scale tier persists across workspace save/load") + let absentRaw = try roundTrip(nil) + expect(absentRaw == nil, "absent text scale stays absent so older snapshots stay compatible") +} + + print("WeiBei self-check passed")