Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com

fix(frontend): inject collab plugin via prosePluginsCtx (state) not editorViewOptionsCtx (view)

+13 -13
+1 -1
milkdown-entry.js
··· 1 - export { Editor, rootCtx, defaultValueCtx, editorViewCtx, serializerCtx, editorViewOptionsCtx } from '@milkdown/kit/core'; 1 + export { Editor, rootCtx, defaultValueCtx, editorViewCtx, editorViewOptionsCtx, serializerCtx, prosePluginsCtx } from '@milkdown/kit/core'; 2 2 export { commonmark, toggleStrongCommand, toggleEmphasisCommand, wrapInHeadingCommand, turnIntoTextCommand, wrapInBulletListCommand, wrapInBlockquoteCommand } from '@milkdown/kit/preset/commonmark'; 3 3 export { listener, listenerCtx } from '@milkdown/kit/plugin/listener'; 4 4 export { TooltipProvider, tooltipFactory } from '@milkdown/kit/plugin/tooltip';
+5 -5
static/vendor/milkdown.js
··· 36 36 `}var vk=/\r?\n|\r/g;function $h(n,e){let t=[],r=0,i=0,o;for(;o=vk.exec(n);)s(n.slice(r,o.index)),t.push(o[0]),r=o.index+o[0].length,i++;return s(n.slice(r)),t.join("");function s(l){t.push(e(l,i,!l))}}function jh(n,e,t){let r=(t.before||"")+(e||"")+(t.after||""),i=[],o=[],s={},l=-1;for(;++l<n.unsafe.length;){let u=n.unsafe[l];if(!Ro(n.stack,u))continue;let f=n.compilePattern(u),d;for(;d=f.exec(r);){let h="before"in u||!!u.atBreak,p="after"in u,m=d.index+(h?d[1].length:0);i.includes(m)?(s[m].before&&!h&&(s[m].before=!1),s[m].after&&!p&&(s[m].after=!1)):(i.push(m),s[m]={before:h,after:p})}}i.sort(Dk);let a=t.before?t.before.length:0,c=r.length-(t.after?t.after.length:0);for(l=-1;++l<i.length;){let u=i[l];u<a||u>=c||u+1<c&&i[l+1]===u+1&&s[u].after&&!s[u+1].before&&!s[u+1].after||i[l-1]===u-1&&s[u].before&&!s[u-1].before&&!s[u-1].after||(a!==u&&o.push(Wh(r.slice(a,u),"\\")),a=u,/[!-/:-@[-`{-~]/.test(r.charAt(u))&&(!t.encode||!t.encode.includes(r.charAt(u)))?o.push("\\"):(o.push(Ve(r.charCodeAt(u))),a++))}return o.push(Wh(r.slice(a,c),t.after)),o.join("")}function Dk(n,e){return n-e}function Wh(n,e){let t=/\\(?=[!-/:-@[-`{-~])/g,r=[],i=[],o=n+e,s=-1,l=0,a;for(;a=t.exec(o);)r.push(a.index);for(;++s<r.length;)l!==r[s]&&i.push(n.slice(l,r[s])),i.push("\\"),l=r[s];return i.push(n.slice(l)),i.join("")}function Hh(n){let e=n||{},t=e.now||{},r=e.lineShift||0,i=t.line||1,o=t.column||1;return{move:a,current:s,shift:l};function s(){return{now:{line:i,column:o},lineShift:r}}function l(c){r+=c}function a(c){let u=c||"",f=u.split(/\r?\n|\r/g),d=f[f.length-1];return i+=f.length-1,o=f.length===1?o+d.length:1+d.length+r,u}}function ua(n,e){let t=e||{},r={associationId:zh,containerPhrasing:zk,containerFlow:Fk,createTracker:Hh,compilePattern:Fh,enter:o,handlers:{...Ph},handle:void 0,indentLines:$h,indexStack:[],join:[...Lh],options:{},safe:_k,stack:[],unsafe:[...Bh]};Xl(r,t),r.options.tightDefinitions&&r.join.push(Bk),r.handle=hh("type",{invalid:Pk,unknown:Lk,handlers:r.handlers});let i=r.handle(n,void 0,r,{before:` 37 37 `,after:` 38 38 `,now:{line:1,column:1},lineShift:0});return i&&i.charCodeAt(i.length-1)!==10&&i.charCodeAt(i.length-1)!==13&&(i+=` 39 - `),i;function o(s){return r.stack.push(s),l;function l(){r.stack.pop()}}}function Pk(n){throw new Error("Cannot handle value `"+n+"`, expected node")}function Lk(n){let e=n;throw new Error("Cannot handle unknown node `"+e.type+"`")}function Bk(n,e){if(n.type==="definition"&&n.type===e.type)return 0}function zk(n,e){return _h(n,this,e)}function Fk(n,e){return Vh(n,this,e)}function _k(n,e){return jh(this,n,e)}function cr(n){let e=this;e.compiler=t;function t(r){return ua(r,{...e.data("settings"),...n,extensions:e.data("toMarkdownExtensions")||[]})}}function fa(n){if(n)throw n}var Fo=Ag(Zh(),1);function ui(n){if(typeof n!="object"||n===null)return!1;let e=Object.getPrototypeOf(n);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in n)&&!(Symbol.iterator in n)}function ha(){let n=[],e={run:t,use:r};return e;function t(...i){let o=-1,s=i.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);l(null,...i);function l(a,...c){let u=n[++o],f=-1;if(a){s(a);return}for(;++f<i.length;)(c[f]===null||c[f]===void 0)&&(c[f]=i[f]);i=c,u?ed(u,l)(...c):s(null,...c)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return n.push(i),e}}function ed(n,e){let t;return r;function r(...s){let l=n.length>s.length,a;l&&s.push(i);try{a=n.apply(this,s)}catch(c){let u=c;if(l&&t)throw u;return i(u)}l||(a&&a.then&&typeof a.then=="function"?a.then(o,i):a instanceof Error?i(a):o(a))}function i(s,...l){t||(t=!0,e(s,...l))}function o(s){i(null,s)}}var ce=class extends Error{constructor(e,t,r){super(),typeof t=="string"&&(r=t,t=void 0);let i="",o={},s=!1;if(t&&("line"in t&&"column"in t?o={place:t}:"start"in t&&"end"in t?o={place:t}:"type"in t?o={ancestors:[t],place:t.position}:o={...t}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let a=r.indexOf(":");a===-1?o.ruleId=r:(o.source=r.slice(0,a),o.ruleId=r.slice(a+1))}if(!o.place&&o.ancestors&&o.ancestors){let a=o.ancestors[o.ancestors.length-1];a&&(o.place=a.position)}let l=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=l?l.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=l?l.line:void 0,this.name=Ft(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};ce.prototype.file="";ce.prototype.name="";ce.prototype.reason="";ce.prototype.message="";ce.prototype.stack="";ce.prototype.column=void 0;ce.prototype.line=void 0;ce.prototype.ancestors=void 0;ce.prototype.cause=void 0;ce.prototype.fatal=void 0;ce.prototype.place=void 0;ce.prototype.ruleId=void 0;ce.prototype.source=void 0;var tt={basename:Vk,dirname:$k,extname:Wk,join:jk,sep:"/"};function Vk(n,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');fi(n);let t=0,r=-1,i=n.length,o;if(e===void 0||e.length===0||e.length>n.length){for(;i--;)if(n.codePointAt(i)===47){if(o){t=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":n.slice(t,r)}if(e===n)return"";let s=-1,l=e.length-1;for(;i--;)if(n.codePointAt(i)===47){if(o){t=i+1;break}}else s<0&&(o=!0,s=i+1),l>-1&&(n.codePointAt(i)===e.codePointAt(l--)?l<0&&(r=i):(l=-1,r=s));return t===r?r=s:r<0&&(r=n.length),n.slice(t,r)}function $k(n){if(fi(n),n.length===0)return".";let e=-1,t=n.length,r;for(;--t;)if(n.codePointAt(t)===47){if(r){e=t;break}}else r||(r=!0);return e<0?n.codePointAt(0)===47?"/":".":e===1&&n.codePointAt(0)===47?"//":n.slice(0,e)}function Wk(n){fi(n);let e=n.length,t=-1,r=0,i=-1,o=0,s;for(;e--;){let l=n.codePointAt(e);if(l===47){if(s){r=e+1;break}continue}t<0&&(s=!0,t=e+1),l===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||t<0||o===0||o===1&&i===t-1&&i===r+1?"":n.slice(i,t)}function jk(...n){let e=-1,t;for(;++e<n.length;)fi(n[e]),n[e]&&(t=t===void 0?n[e]:t+"/"+n[e]);return t===void 0?".":Hk(t)}function Hk(n){fi(n);let e=n.codePointAt(0)===47,t=qk(n,!e);return t.length===0&&!e&&(t="."),t.length>0&&n.codePointAt(n.length-1)===47&&(t+="/"),e?"/"+t:t}function qk(n,e){let t="",r=0,i=-1,o=0,s=-1,l,a;for(;++s<=n.length;){if(s<n.length)l=n.codePointAt(s);else{if(l===47)break;l=47}if(l===47){if(!(i===s-1||o===1))if(i!==s-1&&o===2){if(t.length<2||r!==2||t.codePointAt(t.length-1)!==46||t.codePointAt(t.length-2)!==46){if(t.length>2){if(a=t.lastIndexOf("/"),a!==t.length-1){a<0?(t="",r=0):(t=t.slice(0,a),r=t.length-1-t.lastIndexOf("/")),i=s,o=0;continue}}else if(t.length>0){t="",r=0,i=s,o=0;continue}}e&&(t=t.length>0?t+"/..":"..",r=2)}else t.length>0?t+="/"+n.slice(i+1,s):t=n.slice(i+1,s),r=s-i-1;i=s,o=0}else l===46&&o>-1?o++:o=-1}return t}function fi(n){if(typeof n!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(n))}var td={cwd:Kk};function Kk(){return"/"}function ur(n){return!!(n!==null&&typeof n=="object"&&"href"in n&&n.href&&"protocol"in n&&n.protocol&&n.auth===void 0)}function nd(n){if(typeof n=="string")n=new URL(n);else if(!ur(n)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+n+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(n.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return Uk(n)}function Uk(n){if(n.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=n.pathname,t=-1;for(;++t<e.length;)if(e.codePointAt(t)===37&&e.codePointAt(t+1)===50){let r=e.codePointAt(t+2);if(r===70||r===102){let i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(e)}var da=["history","path","basename","stem","extname","dirname"],hi=class{constructor(e){let t;e?ur(e)?t={path:e}:typeof e=="string"||Jk(e)?t={value:e}:t=e:t={},this.cwd="cwd"in t?"":td.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<da.length;){let o=da[r];o in t&&t[o]!==void 0&&t[o]!==null&&(this[o]=o==="history"?[...t[o]]:t[o])}let i;for(i in t)da.includes(i)||(this[i]=t[i])}get basename(){return typeof this.path=="string"?tt.basename(this.path):void 0}set basename(e){ma(e,"basename"),pa(e,"basename"),this.path=tt.join(this.dirname||"",e)}get dirname(){return typeof this.path=="string"?tt.dirname(this.path):void 0}set dirname(e){rd(this.basename,"dirname"),this.path=tt.join(e||"",this.basename)}get extname(){return typeof this.path=="string"?tt.extname(this.path):void 0}set extname(e){if(pa(e,"extname"),rd(this.dirname,"extname"),e){if(e.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=tt.join(this.dirname,this.stem+(e||""))}get path(){return this.history[this.history.length-1]}set path(e){ur(e)&&(e=nd(e)),ma(e,"path"),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path=="string"?tt.basename(this.path,this.extname):void 0}set stem(e){ma(e,"stem"),pa(e,"stem"),this.path=tt.join(this.dirname||"",e+(this.extname||""))}fail(e,t,r){let i=this.message(e,t,r);throw i.fatal=!0,i}info(e,t,r){let i=this.message(e,t,r);return i.fatal=void 0,i}message(e,t,r){let i=new ce(e,t,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(e){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(e||void 0).decode(this.value)}};function pa(n,e){if(n&&n.includes(tt.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+tt.sep+"`")}function ma(n,e){if(!n)throw new Error("`"+e+"` cannot be empty")}function rd(n,e){if(!n)throw new Error("Setting `"+e+"` requires `path` to be set too")}function Jk(n){return!!(n&&typeof n=="object"&&"byteLength"in n&&"byteOffset"in n)}var id=(function(n){let r=this.constructor.prototype,i=r[n],o=function(){return i.apply(o,arguments)};return Object.setPrototypeOf(o,r),o});var Gk={}.hasOwnProperty,ka=class n extends id{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=ha()}copy(){let e=new n,t=-1;for(;++t<this.attachers.length;){let r=this.attachers[t];e.use(...r)}return e.data((0,Fo.default)(!0,{},this.namespace)),e}data(e,t){return typeof e=="string"?arguments.length===2?(xa("data",this.frozen),this.namespace[e]=t,this):Gk.call(this.namespace,e)&&this.namespace[e]||void 0:e?(xa("data",this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);let i=t.call(e,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(e){this.freeze();let t=zo(e),r=this.parser||this.Parser;return ga("parse",r),r(String(t),t)}process(e,t){let r=this;return this.freeze(),ga("process",this.parser||this.Parser),ya("process",this.compiler||this.Compiler),t?i(void 0,t):new Promise(i);function i(o,s){let l=zo(e),a=r.parse(l);r.run(a,l,function(u,f,d){if(u||!f||!d)return c(u);let h=f,p=r.stringify(h,d);Qk(p)?d.value=p:d.result=p,c(u,d)});function c(u,f){u||!f?s(u):o?o(f):t(void 0,f)}}}processSync(e){let t=!1,r;return this.freeze(),ga("processSync",this.parser||this.Parser),ya("processSync",this.compiler||this.Compiler),this.process(e,i),sd("processSync","process",t),r;function i(o,s){t=!0,fa(o),r=s}}run(e,t,r){od(e),this.freeze();let i=this.transformers;return!r&&typeof t=="function"&&(r=t,t=void 0),r?o(void 0,r):new Promise(o);function o(s,l){let a=zo(t);i.run(e,a,c);function c(u,f,d){let h=f||e;u?l(u):s?s(h):r(void 0,h,d)}}}runSync(e,t){let r=!1,i;return this.run(e,t,o),sd("runSync","run",r),i;function o(s,l){fa(s),i=l,r=!0}}stringify(e,t){this.freeze();let r=zo(t),i=this.compiler||this.Compiler;return ya("stringify",i),od(e),i(e,r)}use(e,...t){let r=this.attachers,i=this.namespace;if(xa("use",this.frozen),e!=null)if(typeof e=="function")a(e,t);else if(typeof e=="object")Array.isArray(e)?l(e):s(e);else throw new TypeError("Expected usable value, not `"+e+"`");return this;function o(c){if(typeof c=="function")a(c,[]);else if(typeof c=="object")if(Array.isArray(c)){let[u,...f]=c;a(u,f)}else s(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function s(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(c.plugins),c.settings&&(i.settings=(0,Fo.default)(!0,i.settings,c.settings))}function l(c){let u=-1;if(c!=null)if(Array.isArray(c))for(;++u<c.length;){let f=c[u];o(f)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function a(c,u){let f=-1,d=-1;for(;++f<r.length;)if(r[f][0]===c){d=f;break}if(d===-1)r.push([c,...u]);else if(u.length>0){let[h,...p]=u,m=r[d][1];ui(m)&&ui(h)&&(h=(0,Fo.default)(!0,m,h)),r[d]=[c,h,...p]}}}},di=new ka().freeze();function ga(n,e){if(typeof e!="function")throw new TypeError("Cannot `"+n+"` without `parser`")}function ya(n,e){if(typeof e!="function")throw new TypeError("Cannot `"+n+"` without `compiler`")}function xa(n,e){if(e)throw new Error("Cannot call `"+n+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function od(n){if(!ui(n)||typeof n.type!="string")throw new TypeError("Expected node, got `"+n+"`")}function sd(n,e,t){if(!t)throw new Error("`"+n+"` finished async. Use `"+e+"` instead")}function zo(n){return Yk(n)?n:new hi(n)}function Yk(n){return!!(n&&typeof n=="object"&&"message"in n&&"messages"in n)}function Qk(n){return typeof n=="string"||Xk(n)}function Xk(n){return!!(n&&typeof n=="object"&&"byteLength"in n&&"byteOffset"in n)}var ad=n=>{throw TypeError(n)},cd=(n,e,t)=>e.has(n)||ad("Cannot "+t),H=(n,e,t)=>(cd(n,e,"read from private field"),t?t.call(n):e.get(n)),oe=(n,e,t)=>e.has(n)?ad("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),ee=(n,e,t,r)=>(cd(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),st,pi,_o,Vo,$o,mi,gi,wt,yi,Wo,jo,xi,Ho,ki,qo,Ko,fr,wn,Uo,bi,Jo=class{},Go=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=e=>{this.top()?.push(e)},this.open=e=>{this.elements.push(e)},this.close=()=>{let e=this.elements.pop();if(!e)throw il();return e}}},ba=class n extends Jo{constructor(e,t,r){super(),this.type=e,this.content=t,this.attrs=r}push(e,...t){this.content.push(e,...t)}pop(){return this.content.pop()}static create(e,t,r){return new n(e,t,r)}},wa=class extends Go{constructor(e){super(),oe(this,st),oe(this,pi),oe(this,_o),oe(this,Vo),oe(this,$o),oe(this,mi),oe(this,gi),ee(this,st,q.none),ee(this,pi,t=>t.isText),ee(this,_o,(t,r)=>{if(H(this,pi).call(this,t)&&H(this,pi).call(this,r)&&q.sameSet(t.marks,r.marks))return this.schema.text(t.text+r.text,t.marks)}),ee(this,Vo,t=>{let r=Object.values({...this.schema.nodes,...this.schema.marks}).find(i=>i.spec.parseMarkdown.match(t));if(!r)throw Au(t);return r}),ee(this,$o,t=>{let r=H(this,Vo).call(this,t);r.spec.parseMarkdown.runner(this,t,r)}),this.injectRoot=(t,r,i)=>(this.openNode(r,i),this.next(t.children),this),this.openNode=(t,r)=>(this.open(ba.create(t,[],r)),this),ee(this,mi,()=>{ee(this,st,q.none);let t=this.close();return H(this,gi).call(this,t.type,t.attrs,t.content)}),this.closeNode=()=>{try{H(this,mi).call(this)}catch(t){console.error(t)}return this},ee(this,gi,(t,r,i)=>{let o=t.createAndFill(r,i,H(this,st));if(!o)throw Eu(t,r,i);return this.push(o),o}),this.addNode=(t,r,i)=>{try{H(this,gi).call(this,t,r,i)}catch(o){console.error(o)}return this},this.openMark=(t,r)=>{let i=t.create(r);return ee(this,st,i.addToSet(H(this,st))),this},this.closeMark=t=>(ee(this,st,t.removeFromSet(H(this,st))),this),this.addText=t=>{try{let r=this.top();if(!r)throw il();let i=r.pop(),o=this.schema.text(t,H(this,st));if(!i)return r.push(o),this;let s=H(this,_o).call(this,i,o);return s?(r.push(s),this):(r.push(i,o),this)}catch(r){return console.error(r),this}},this.build=()=>{let t;do t=H(this,mi).call(this);while(this.size());return t},this.next=(t=[])=>([t].flat().forEach(r=>H(this,$o).call(this,r)),this),this.toDoc=()=>this.build(),this.run=(t,r)=>{let i=t.runSync(t.parse(r),r);return this.next(i),this},this.schema=e}};st=new WeakMap;pi=new WeakMap;_o=new WeakMap;Vo=new WeakMap;$o=new WeakMap;mi=new WeakMap;gi=new WeakMap;wa.create=(n,e)=>{let t=new wa(n);return r=>(t.run(e,r),t.toDoc())};var ud=wa,Sa=class extends Jo{constructor(e,t,r,i={}){super(),this.type=e,this.children=t,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}};Sa.create=(n,e,t,r={})=>new Sa(n,e,t,r);var ld=Sa,Zk=n=>Object.prototype.hasOwnProperty.call(n,"size"),Ca=class extends Go{constructor(e){super(),oe(this,wt),oe(this,yi),oe(this,Wo),oe(this,jo),oe(this,xi),oe(this,Ho),oe(this,ki),oe(this,qo),oe(this,Ko),oe(this,fr),oe(this,wn),oe(this,Uo),oe(this,bi),ee(this,wt,q.none),ee(this,yi,t=>{let r=Object.values({...this.schema.nodes,...this.schema.marks}).find(i=>i.spec.toMarkdown.match(t));if(!r)throw Ru(t.type);return r}),ee(this,Wo,t=>H(this,yi).call(this,t).spec.toMarkdown.runner(this,t)),ee(this,jo,(t,r)=>H(this,yi).call(this,t).spec.toMarkdown.runner(this,t,r)),ee(this,xi,t=>{let{marks:r}=t,i=l=>l.type.spec.priority??50;[...r].sort((l,a)=>i(l)-i(a)).every(l=>!H(this,jo).call(this,l,t))&&H(this,Wo).call(this,t),r.forEach(l=>H(this,bi).call(this,l))}),ee(this,Ho,(t,r)=>{if(t.type===r||t.children?.length!==1)return t;let i=a=>{if(a.type===r)return a;if(a.children?.length!==1)return null;let[c]=a.children;return c?i(c):null},o=i(t);if(!o)return t;let s=o.children?[...o.children]:void 0,l={...t,children:s};return l.children=s,o.children=[l],o}),ee(this,ki,t=>{let{children:r}=t;return r&&(t.children=r.reduce((i,o,s)=>{if(s===0)return[o];let l=i.at(-1);if(l&&l.isMark&&o.isMark){o=H(this,Ho).call(this,o,l.type);let{children:a,...c}=o,{children:u,...f}=l;if(o.type===l.type&&a&&u&&JSON.stringify(c)===JSON.stringify(f)){let d={...f,children:[...u,...a]};return i.slice(0,-1).concat(H(this,ki).call(this,d))}}return i.concat(o)},[])),t}),ee(this,qo,t=>{let r={...t.props,type:t.type};return t.children&&(r.children=t.children),t.value&&(r.value=t.value),r}),this.openNode=(t,r,i)=>(this.open(ld.create(t,void 0,r,i)),this),ee(this,Ko,(t,r)=>{let i="",o="",s=t.children,l=-1,a=-1,c=f=>{f&&f.forEach((d,h)=>{d.type==="text"&&d.value&&(l<0&&(l=h),a=h)})};if(s){c(s);let f=s?.[a],d=s?.[l];if(f&&f.value.endsWith(" ")){let h=f.value,p=h.trimEnd();o=h.slice(p.length),f.value=p}if(d&&d.value.startsWith(" ")){let h=d.value,p=h.trimStart();i=h.slice(0,h.length-p.length),d.value=p}}i.length&&H(this,wn).call(this,"text",void 0,i);let u=r();return o.length&&H(this,wn).call(this,"text",void 0,o),u}),ee(this,fr,(t=!1)=>{let r=this.close(),i=()=>H(this,wn).call(this,r.type,r.children,r.value,r.props);return t?H(this,Ko).call(this,r,i):i()}),this.closeNode=()=>(H(this,fr).call(this),this),ee(this,wn,(t,r,i,o)=>{let s=ld.create(t,r,i,o),l=H(this,ki).call(this,H(this,qo).call(this,s));return this.push(l),l}),this.addNode=(t,r,i,o)=>(H(this,wn).call(this,t,r,i,o),this),ee(this,Uo,(t,r,i,o)=>t.isInSet(H(this,wt))?this:(ee(this,wt,t.addToSet(H(this,wt))),this.openNode(r,i,{...o,isMark:!0}))),ee(this,bi,t=>{t.isInSet(H(this,wt))&&(ee(this,wt,t.type.removeFromSet(H(this,wt))),H(this,fr).call(this,!0))}),this.withMark=(t,r,i,o)=>(H(this,Uo).call(this,t,r,i,o),this),this.closeMark=t=>(H(this,bi).call(this,t),this),this.build=()=>{let t=null;do t=H(this,fr).call(this);while(this.size());return t},this.next=t=>Zk(t)?(t.forEach(r=>{H(this,xi).call(this,r)}),this):(H(this,xi).call(this,t),this),this.toString=t=>t.stringify(this.build()),this.run=t=>(this.next(t),this),this.schema=e}};wt=new WeakMap;yi=new WeakMap;Wo=new WeakMap;jo=new WeakMap;xi=new WeakMap;Ho=new WeakMap;ki=new WeakMap;qo=new WeakMap;Ko=new WeakMap;fr=new WeakMap;wn=new WeakMap;Uo=new WeakMap;bi=new WeakMap;Ca.create=(n,e)=>{let t=new Ca(n);return r=>(t.run(r),t.toString(e))};var fd=Ca;var Ne=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?eb(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function eb(n){return function(e,t,r,i){let o=n;if(t[1]){let s=t[0].lastIndexOf(t[1]);o+=t[0].slice(s+t[1].length),r+=s;let l=r-i;l>0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var hd=(n,e)=>{let t=n.plugins;for(let r=0;r<t.length;r++){let i=t[r],o;if(i.spec.isInputRules&&(o=i.getState(n))){if(e){let s=n.tr,l=o.transform;for(let a=l.steps.length-1;a>=0;a--)s.step(l.steps[a].invert(l.docs[a]));if(o.text){let a=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,a))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},rE=new Ne(/--$/,"\u2014",{inCodeMark:!1}),iE=new Ne(/\.\.\.$/,"\u2026",{inCodeMark:!1}),oE=new Ne(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),sE=new Ne(/"$/,"\u201D",{inCodeMark:!1}),lE=new Ne(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),aE=new Ne(/'$/,"\u2019",{inCodeMark:!1});function Yo(n,e,t=null,r){return new Ne(n,(i,o,s,l)=>{let a=t instanceof Function?t(o):t,c=i.tr.delete(s,l),u=c.doc.resolve(s),f=u.blockRange(),d=f&&cn(f,e,a);if(!d)return null;c.wrap(f,d);let h=c.doc.resolve(s-1).nodeBefore;return h&&h.type==e&&fn(c.doc,s-1)&&(!r||r(o,h))&&c.join(s-1),c})}function Ma(n,e,t=null){return new Ne(n,(r,i,o,s)=>{let l=r.doc.resolve(o),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,a):null})}var Vt=typeof navigator<"u"?navigator:null,dd=typeof document<"u"?document:null,$t=Vt&&Vt.userAgent||"",Ia=/Edge\/(\d+)/.exec($t),xd=/MSIE \d/.exec($t),Ta=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec($t),Oa=!!(xd||Ta||Ia),hE=xd?document.documentMode:Ta?+Ta[1]:Ia?+Ia[1]:0,tb=!Oa&&/gecko\/(\d+)/i.test($t),dE=tb&&+(/Firefox\/(\d+)/.exec($t)||[0,0])[1],pd=!Oa&&/Chrome\/(\d+)/.exec($t);var pE=pd?+pd[1]:0,nb=!Oa&&!!Vt&&/Apple Computer/.test(Vt.vendor),rb=nb&&(/Mobile\/\w+/.test($t)||!!Vt&&Vt.maxTouchPoints>2),mE=rb||(Vt?/Mac/.test(Vt.platform):!1),gE=/Android \d/.test($t),ib=!!dd&&"webkitFontSmoothing"in dd.documentElement.style,yE=ib?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Na(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e);if(l.parent.type.spec.code)return!1;let a=l.parent.textBetween(Math.max(0,l.parentOffset-500),l.parentOffset,void 0,"\uFFFC")+r;for(let c of i){let u=c,f=u.match.exec(a),d=f&&f[0]&&u.handler(s,f,e-(f[0].length-r.length),t);if(d)return u.undoable!==!1&&d.setMeta(o,{transform:d,from:e,to:t,text:r}),n.dispatch(d),!0}return!1}var ob=new re("MILKDOWN_CUSTOM_INPUTRULES");function kd({rules:n}){let e=new ne({key:ob,isInputRules:!0,state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Na(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>(setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Na(t,r.pos,r.pos,"",n,e)}),!1)},handleKeyDown(t,r){if(r.key!=="Enter")return!1;let{$cursor:i}=t.state.selection;return i?Na(t,i.pos,i.pos,` 40 - `,n,e):!1}}});return e}function wi(n,e,t={}){return new Ne(n,(r,i,o,s)=>{var l,a,c,u;let{tr:f}=r,d=i.length,h=i[d-1],p=i[0],m=[],k=s,x={group:h,fullMatch:p,start:o,end:s},I=(l=t.updateCaptured)==null?void 0:l.call(t,x);if(Object.assign(x,I),{group:h,fullMatch:p,start:o,end:s}=x,p===null||h?.trim()==="")return null;if(h){let C=p.search(/\S/),A=o+p.indexOf(h),v=A+h.length;m=(a=f.storedMarks)!=null?a:[],v<s&&f.delete(v,s),A>o&&f.delete(o+C,A),k=o+C+h.length;let b=(c=t.getAttr)==null?void 0:c.call(t,i);f.addMark(o,k,e.create(b)),f.setStoredMarks(m),(u=t.beforeDispatch)==null||u.call(t,{match:i,start:o,end:s,tr:f})}return f})}var sb=Object.defineProperty,lb=Object.defineProperties,ab=Object.getOwnPropertyDescriptors,md=Object.getOwnPropertySymbols,cb=Object.prototype.hasOwnProperty,ub=Object.prototype.propertyIsEnumerable,gd=(n,e,t)=>e in n?sb(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,fb=(n,e)=>{for(var t in e||(e={}))cb.call(e,t)&&gd(n,t,e[t]);if(md)for(var t of md(e))ub.call(e,t)&&gd(n,t,e[t]);return n},hb=(n,e)=>lb(n,ab(e));function yd(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function bd(n,e,t){let i=n.state.doc.content.size,o=yd(e,0,i),s=yd(t,0,i),l=n.coordsAtPos(o),a=n.coordsAtPos(s,-1),c=Math.min(l.top,a.top),u=Math.max(l.bottom,a.bottom),f=Math.min(l.left,a.left),d=Math.max(l.right,a.right),h=d-f,p=u-c,x={top:c,bottom:u,left:f,right:d,width:h,height:p,x:f,y:c};return hb(fb({},x),{toJSON:()=>x})}function db(n,e){return Array.isArray(n)&&n.includes(e.type)||e.type===n}function wd(n,e){if(!(n instanceof B))return;let{node:t,$from:r}=n;if(db(e,t))return{node:t,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Sd=(n,e)=>{let{selection:t,doc:r}=n;if(t instanceof B)return{hasNode:t.node.type===e,pos:t.from,target:t.node};let{from:i,to:o}=t,s=!1,l=-1,a=null;return r.nodesBetween(i,o,(c,u)=>a?!1:c.type===e?(s=!0,l=u,a=c,!1):!0),{hasNode:s,pos:l,target:a}};var St={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:"'"},Xo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},pb=typeof navigator<"u"&&/Mac/.test(navigator.platform),mb=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(se=0;se<10;se++)St[48+se]=St[96+se]=String(se);var se;for(se=1;se<=24;se++)St[se+111]="F"+se;var se;for(se=65;se<=90;se++)St[se]=String.fromCharCode(se+32),Xo[se]=String.fromCharCode(se);var se;for(Qo in St)Xo.hasOwnProperty(Qo)||(Xo[Qo]=St[Qo]);var Qo;function Cd(n){var e=pb&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||mb&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Xo:St)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var gb=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),yb=typeof navigator<"u"&&/Win/.test(navigator.platform);function xb(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))s=!0;else if(/^a(lt)?$/i.test(a))r=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))o=!0;else if(/^mod$/i.test(a))gb?s=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return r&&(t="Alt-"+t),i&&(t="Ctrl-"+t),s&&(t="Meta-"+t),o&&(t="Shift-"+t),t}function kb(n){let e=Object.create(null);for(let t in n)e[xb(t)]=n[t];return e}function Ea(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function Md(n){return new ne({props:{handleKeyDown:bb(n)}})}function bb(n){let e=kb(n);return function(t,r){let i=Cd(r),o,s=e[Ea(i,r)];if(s&&s(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let l=e[Ea(i,r,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(yb&&r.ctrlKey&&r.altKey)&&(o=St[r.keyCode])&&o!=i){let l=e[Ea(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var pe=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},gr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},La=null,Mt=function(n,e,t){let r=La||(La=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},wb=function(){La=null},On=function(n,e,t,r){return t&&(Nd(n,e,t,r,-1)||Nd(n,e,t,r,1))},Sb=/^(img|br|input|textarea|hr)$/i;function Nd(n,e,t,r,i){for(var o;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ke(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Ei(n)||Sb.test(n.nodeName)||n.contentEditable=="false")return!1;e=pe(n)+(i<0?0:1),n=s}else if(n.nodeType==1){let s=n.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 n=s,e=i<0?Ke(n):0}else return!1}}function Ke(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Cb(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Ke(n)}else if(n.parentNode&&!Ei(n))e=pe(n),n=n.parentNode;else return null}}function Mb(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!Ei(n))e=pe(n)+1,n=n.parentNode;else return null}}function Nb(n,e,t){for(let r=e==0,i=e==Ke(n);r||i;){if(n==t)return!0;let o=pe(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Ke(n)}}function Ei(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}var us=function(n){return n.focusNode&&On(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Sn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Ib(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Tb(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(Ke(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(Ke(r.startContainer),r.startOffset)}}}var lt=typeof navigator<"u"?navigator:null,Id=typeof document<"u"?document:null,Ut=lt&&lt.userAgent||"",Ba=/Edge\/(\d+)/.exec(Ut),ip=/MSIE \d/.exec(Ut),za=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ut),Re=!!(ip||za||Ba),qt=ip?document.documentMode:za?+za[1]:Ba?+Ba[1]:0,Ue=!Re&&/gecko\/(\d+)/i.test(Ut);Ue&&+(/Firefox\/(\d+)/.exec(Ut)||[0,0])[1];var Fa=!Re&&/Chrome\/(\d+)/.exec(Ut),me=!!Fa,op=Fa?+Fa[1]:0,we=!Re&&!!lt&&/Apple Computer/.test(lt.vendor),yr=we&&(/Mobile\/\w+/.test(Ut)||!!lt&&lt.maxTouchPoints>2),qe=yr||(lt?/Mac/.test(lt.platform):!1),sp=lt?/Win/.test(lt.platform):!1,Nt=/Android \d/.test(Ut),Ai=!!Id&&"webkitFontSmoothing"in Id.documentElement.style,Ob=Ai?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Eb(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Ct(n,e){return typeof n=="number"?n:n[e]}function Ab(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Td(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;){if(s.nodeType!=1){s=gr(s);continue}let l=s,a=l==o.body,c=a?Eb(o):Ab(l),u=0,f=0;if(e.top<c.top+Ct(r,"top")?f=-(c.top-e.top+Ct(i,"top")):e.bottom>c.bottom-Ct(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+Ct(i,"top")-c.top:e.bottom-c.bottom+Ct(i,"bottom")),e.left<c.left+Ct(r,"left")?u=-(c.left-e.left+Ct(i,"left")):e.right>c.right-Ct(r,"right")&&(u=e.right-c.right+Ct(i,"right")),u||f)if(a)o.defaultView.scrollBy(u,f);else{let h=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let m=l.scrollLeft-h,k=l.scrollTop-p;e={left:e.left-m,top:e.top-k,right:e.right-m,bottom:e.bottom-k}}let d=a?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:gr(s)}}function Rb(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s<Math.min(innerHeight,e.bottom);s+=5){let l=n.root.elementFromPoint(o,s);if(!l||l==n.dom||!n.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:lp(n.dom)}}function lp(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=gr(r));return e}function vb({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;ap(t,r==0?0:r-e)}function ap(n,e){for(let t=0;t<n.length;t++){let{dom:r,top:i,left:o}=n[t];r.scrollTop!=i+e&&(r.scrollTop=i+e),r.scrollLeft!=o&&(r.scrollLeft=o)}}var hr=null;function Db(n){if(n.setActive)return n.setActive();if(hr)return n.focus(hr);let e=lp(n);n.focus(hr==null?{get preventScroll(){return hr={preventScroll:!0},!0}}:void 0),hr||(hr=!1,ap(e,0))}function cp(n,e){let t,r=2e8,i,o=0,s=e.top,l=e.top,a,c;for(let u=n.firstChild,f=0;u;u=u.nextSibling,f++){let d;if(u.nodeType==1)d=u.getClientRects();else if(u.nodeType==3)d=Mt(u).getClientRects();else continue;for(let h=0;h<d.length;h++){let p=d[h];if(p.top<=s&&p.bottom>=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right<e.left?e.left-p.right:0;if(m<r){t=u,r=m,i=m&&t.nodeType==3?{left:p.right<e.left?p.right:p.left,top:e.top}:e,u.nodeType==1&&m&&(o=f+(e.left>=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=u,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?Pb(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:cp(t,i)}function Pb(n,e){let t=n.nodeValue.length,r=document.createRange(),i;for(let o=0;o<t;o++){r.setEnd(n,o+1),r.setStart(n,o);let s=Wt(r,1);if(s.top!=s.bottom&&Za(e,s)){i={node:n,offset:o+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:n,offset:0}}function Za(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Lb(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function Bb(n,e,t){let{node:r,offset:i}=cp(e,t),o=-1;if(r.nodeType==1&&!r.firstChild){let s=r.getBoundingClientRect();o=s.left!=s.right&&t.left>(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function zb(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right<r.left||a.bottom<r.top)&&(i=l.posAfter),s=!0),!l.contentDOM&&i<0&&!l.node.isText))return(l.node.isBlock?r.top<(a.top+a.bottom)/2:r.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;o=l.dom.parentNode}return i>-1?i:n.docView.posFromDOM(e,t,-1)}function up(n,e,t){let r=n.childNodes.length;if(r&&t.top<t.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-t.top)/(t.bottom-t.top))-2)),o=i;;){let s=n.childNodes[o];if(s.nodeType==1){let l=s.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Za(e,c))return up(s,e,c)}}if((o=(o+1)%r)==i)break}return n}function Fb(n,e){let t=n.dom.ownerDocument,r,i=0,o=Tb(t,e.left,e.top);o&&({node:r,offset:i}=o);let s=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!s||!n.dom.contains(s.nodeType!=1?s.parentNode:s)){let c=n.dom.getBoundingClientRect();if(!Za(e,c)||(s=up(n.dom,e,c),!s))return null}if(we)for(let c=s;r&&c;c=gr(c))c.draggable&&(r=void 0);if(s=Lb(s,e),r){if(Ue&&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;Ai&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=zb(n,r,i,e))}l==null&&(l=Bb(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Od(n){return n.top<n.bottom||n.left<n.right}function Wt(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(Od(r))return r}return Array.prototype.find.call(t,Od)||n.getBoundingClientRect()}var _b=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function fp(n,e,t){let{node:r,offset:i,atom:o}=n.docView.domFromPos(e,t<0?-1:1),s=Ai||Ue;if(r.nodeType==3)if(s&&(_b.test(r.nodeValue)||(t<0?!i:i==r.nodeValue.length))){let a=Wt(Mt(r,i,i),t);if(Ue&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let c=Wt(Mt(r,i-1,i-1),-1);if(c.top==a.top){let u=Wt(Mt(r,i,i+1),-1);if(u.top!=a.top)return Si(u,u.left<c.left)}}return a}else{let a=i,c=i,u=t<0?1:-1;return t<0&&!i?(c++,u=-1):t>=0&&i==r.nodeValue.length?(a--,u=1):t<0?a--:c++,Si(Wt(Mt(r,a,c),u),u<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==Ke(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Aa(a.getBoundingClientRect(),!1)}if(o==null&&i<Ke(r)){let a=r.childNodes[i];if(a.nodeType==1)return Aa(a.getBoundingClientRect(),!0)}return Aa(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==Ke(r))){let a=r.childNodes[i-1],c=a.nodeType==3?Mt(a,Ke(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Si(Wt(c,1),!1)}if(o==null&&i<Ke(r)){let a=r.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?Mt(a,0,s?0:1):a.nodeType==1?a:null:null;if(c)return Si(Wt(c,-1),!0)}return Si(Wt(r.nodeType==3?Mt(r):r,-t),t>=0)}function Si(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Aa(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function hp(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Vb(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return hp(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=fp(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Mt(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let u=a[c];if(u.bottom>u.top+1&&(t=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var $b=/[\u0590-\u08ac]/;function Wb(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!$b.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:hp(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let h=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),k=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(u,f),a&&(a!=u||c!=f)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),k}):r.pos==r.start()||r.pos==r.end()}var Ed=null,Ad=null,Rd=!1;function jb(n,e,t){return Ed==e&&Ad==t?Rd:(Ed=e,Ad=t,Rd=t=="up"||t=="down"?Vb(n,e,t):Wb(n,e,t))}var Je=0,vd=1,Cn=2,at=3,En=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Je,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].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 t=0,r=this.posAtStart;;t++){let i=this.children[t];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,t,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[t-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[t];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=t>pe(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(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==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,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||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 t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;t<this.children.length;t++){let i=this.children[t],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 l=i.children[s];if(l.size){i=l;break}}return i}if(e<o)return i.descAt(e-r-i.border);r=o}}domFromPos(e,t){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],l=o+s.size;if(l>e||s instanceof ts){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Zo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?pe(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,t):{node:this.contentDOM,offset:o?pe(o.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,o=-1;for(let s=r,l=0;;l++){let a=this.children[l],c=s+a.size;if(i==-1&&e<=c){let u=s+a.border;if(e>=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=pe(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){o=pe(f.dom);break}t+=f.size}o==-1&&(o=this.contentDOM.childNodes.length);break}s=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:o}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:r}=this.domFromPos(e,0);if(t.nodeType!=1||r==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[r]}setSelection(e,t,r,i=!1){let o=Math.min(e,t),s=Math.max(e,t);for(let h=0,p=0;h<this.children.length;h++){let m=this.children[h],k=p+m.size;if(o>p&&s<k)return m.setSelection(e-p-m.border,t-p-m.border,r,i);p=k}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=r.root.getSelection(),u=r.domSelectionRange(),f=!1;if((Ue||we)&&e==t){let{node:h,offset:p}=l;if(h.nodeType==3){if(f=!!(p&&h.nodeValue[p-1]==` 41 - `),f&&p==h.nodeValue.length)for(let m=h,k;m;m=m.parentNode){if(k=m.nextSibling){k.nodeName=="BR"&&(l=a={node:k.parentNode,offset:pe(k)+1});break}let x=m.pmViewDesc;if(x&&x.node&&x.node.isBlock)break}}else{let m=h.childNodes[p-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(Ue&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){let h=u.focusNode.childNodes[u.focusOffset];h&&h.contentEditable=="false"&&(i=!0)}if(!(i||f&&we)&&On(l.node,l.offset,u.anchorNode,u.anchorOffset)&&On(a.node,a.offset,u.focusNode,u.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(f&&Ue)){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(h)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){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&&t>=r:e<s&&t>r){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Cn:vd,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=at:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Cn:at}r=s}this.dirty=Cn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Cn:vd;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},Zo=class extends En{constructor(e,t,r,i){let o,s=t.type.toDOM;if(typeof s=="function"&&(s=s(r,()=>{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==Je&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(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}},_a=class extends En{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},xr=class n extends En{constructor(e,t,r,i,o){super(e,[],r,i),this.mark=t,this.spec=o}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=sn.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&at||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=at&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Je){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=Je}}slice(e,t,r){let i=n.create(this.parent,this.mark,!0,r),o=this.children,s=this.size;t<s&&(o=ja(o,t,s,r)),e>0&&(o=ja(o,0,e,r));for(let l=0;l<o.length;l++)o[l].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()}},Kt=class n extends En{constructor(e,t,r,i,o,s,l,a,c){super(e,[],o,s),this.node=t,this.outerDeco=r,this.innerDeco=i,this.nodeDOM=l}static create(e,t,r,i,o,s){let l=o.nodeViews[t.type.name],a,c=l&&l(t,o,()=>{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=sn.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let d=u;return u=mp(u,r,t),c?a=new Va(e,t,r,i,u,f||null,d,c,o,s+1):t.isText?new es(e,t,r,i,u,d,o):new n(e,t,r,i,u,f||null,d,o,s+1)}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 t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>M.empty)}return e}matchesNode(e,t,r){return this.dirty==Je&&e.eq(this.node)&&ns(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new Wa(this,s&&s.node,e);Ub(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&a.syncToMarks(u==this.node.childCount?q.none:this.node.child(u).marks,r,e,u),a.placeWidget(c,e,i)},(c,u,f,d)=>{a.syncToMarks(c.marks,r,e,d);let h;a.findNodeMatch(c,u,f,d)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(h=a.findIndexWithChild(o.node))>-1&&a.updateNodeAt(c,u,f,h,e)||a.updateNextNode(c,u,f,e,d,i)||a.addNode(c,u,f,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Cn)&&(s&&this.protectLocalComposition(e,s),dp(this.contentDOM,this.children,e),yr&&Jb(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof j)||r<t||i>t+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,l=Gb(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;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 _a(this,o,t,i);e.input.compositionNodes.push(s),this.children=ja(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==at||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Je}updateOuterDeco(e){if(ns(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=pp(this.dom,this.nodeDOM,$a(this.outerDeco,this.node,t),$a(e,this.node,t)),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 Dd(n,e,t,r,i){mp(r,e,n);let o=new Kt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var es=class n extends Kt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==at||this.dirty!=Je&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Je||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=Je,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=at)}get domAtom(){return!1}isText(e){return this.node.text==e}},ts=class extends En{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Je&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Va=class extends Kt{constructor(e,t,r,i,o,s,l,a,c,u){super(e,t,r,i,o,s,l,c,u),this.spec=a}update(e,t,r,i){if(this.dirty==at)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,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 dp(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o<e.length;o++){let s=e[o],l=s.dom;if(l.parentNode==n){for(;l!=r;)r=Pd(r),i=!0;r=r.nextSibling}else i=!0,n.insertBefore(l,r);if(s instanceof xr){let a=r?r.previousSibling:n.lastChild;dp(s.contentDOM,s.children,t),r=a?a.nextSibling:n.firstChild}}for(;r;)r=Pd(r),i=!0;i&&t.trackWrites==n&&(t.trackWrites=null)}var Ci=function(n){n&&(this.nodeName=n)};Ci.prototype=Object.create(null);var Mn=[new Ci];function $a(n,e,t){if(n.length==0)return Mn;let r=t?Mn[0]:new Ci,i=[r];for(let o=0;o<n.length;o++){let s=n[o].type.attrs;if(s){s.nodeName&&i.push(r=new Ci(s.nodeName));for(let l in s){let a=s[l];a!=null&&(t&&i.length==1&&i.push(r=new Ci(e.isInline?"span":"div")),l=="class"?r.class=(r.class?r.class+" ":"")+a:l=="style"?r.style=(r.style?r.style+";":"")+a:l!="nodeName"&&(r[l]=a))}}}return i}function pp(n,e,t,r){if(t==Mn&&r==Mn)return e;let i=e;for(let o=0;o<r.length;o++){let s=r[o],l=t[o];if(o){let a;l&&l.nodeName==s.nodeName&&i!=n&&(a=i.parentNode)&&a.nodeName.toLowerCase()==s.nodeName||(a=document.createElement(s.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=Mn[0]),i=a}Hb(i,l||Mn[0],s)}return i}function Hb(n,e,t){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in t)&&n.removeAttribute(r);for(let r in t)r!="class"&&r!="style"&&r!="nodeName"&&t[r]!=e[r]&&n.setAttribute(r,t[r]);if(e.class!=t.class){let r=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let o=0;o<r.length;o++)i.indexOf(r[o])==-1&&n.classList.remove(r[o]);for(let o=0;o<i.length;o++)r.indexOf(i[o])==-1&&n.classList.add(i[o]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=r.exec(e.style);)n.style.removeProperty(i[1])}t.style&&(n.style.cssText+=t.style)}}function mp(n,e,t){return pp(n,n,Mn,$a(e,t,n.nodeType!=1))}function ns(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function Pd(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}var Wa=class{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=qb(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let r=e;r<t;r++)this.top.children[r].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,r,i){let o=0,s=this.stack.length>>1,l=Math.min(s,e.length);for(;o<l&&(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=Je,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let a=-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)){a=u;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=xr.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,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,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,r)&&!this.preMatch.matched.has(c)){o=l;break}}return o<0?!1:(this.destroyBetween(this.index,o),this.index++,!0)}updateNodeAt(e,t,r,i,o){let s=this.top.children[i];return s.dirty==at&&s.dom==s.contentDOM&&(s.dirty=Cn),s.update(e,t,r,o)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==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=t}}updateNextNode(e,t,r,i,o,s){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Kt){let c=this.preMatch.matched.get(a);if(c!=null&&c!=o)return!1;let u=a.dom,f,d=this.isLocked(u)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=at&&ns(t,a.outerDeco));if(!d&&a.update(e,t,r,i))return this.destroyBetween(this.index,l),a.dom!=u&&(this.changed=!0),this.index++,!0;if(!d&&(f=this.recreateWrapper(a,e,t,r,i,s)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Cn,f.updateChildren(i,s+1),f.dirty=Je),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,r,i,o,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!ns(r,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Kt.create(this.top,t,r,i,o,s);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,r,i,o){let s=Kt.create(this.top,e,t,r,i,o);s.contentDOM&&s.updateChildren(i,o+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,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 Zo(this.top,e,t,r);this.top.children.splice(this.index++,0,o),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof xr;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof es)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((we||me)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.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 ts(this.top,[],r,null);t!=this.top?t.children.push(i):t.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 qb(n,e){let t=e,r=t.children.length,i=n.childCount,o=new Map,s=[];e:for(;i>0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof xr)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Kb(n,e){return n.type.side-e.type.side}function Ub(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let c=0;c<n.childCount;c++){let u=n.child(c);r(u,i,e.forChild(o,u),c),o+=u.nodeSize}return}let s=0,l=[],a=null;for(let c=0;;){let u,f;for(;s<i.length&&i[s].to==o;){let k=i[s++];k.widget&&(u?(f||(f=[u])).push(k):u=k)}if(u)if(f){f.sort(Kb);for(let k=0;k<f.length;k++)t(f[k],c,!!a)}else t(u,c,!!a);let d,h;if(a)h=-1,d=a,a=null;else if(c<n.childCount)h=c,d=n.child(c++);else break;for(let k=0;k<l.length;k++)l[k].to<=o&&l.splice(k--,1);for(;s<i.length&&i[s].from<=o&&i[s].to>o;)l.push(i[s++]);let p=o+d.nodeSize;if(d.isText){let k=p;s<i.length&&i[s].from<k&&(k=i[s].from);for(let x=0;x<l.length;x++)l[x].to<k&&(k=l[x].to);k<p&&(a=d.cut(k-o),d=d.cut(0,k-o),p=k,h=-1)}else for(;s<i.length&&i[s].to<p;)s++;let m=d.isInline&&!d.isLeaf?l.filter(k=>!k.inline):l.slice();r(d,m,e.forChild(o,d),h),o=p}}function Jb(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Gb(n,e,t,r){for(let i=0,o=0;i<n.childCount&&o<=r;){let s=n.child(i++),l=o;if(o+=s.nodeSize,!s.isText)continue;let a=s.text;for(;i<n.childCount;){let c=n.child(i++);if(o+=c.nodeSize,!c.isText)break;a+=c.text}if(o>=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l<r?a.lastIndexOf(e,r-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function ja(n,e,t,r,i){let o=[];for(let s=0,l=0;s<n.length;s++){let a=n[s],c=l,u=l+=a.size;c>=t||u<=e?o.push(a):(c<e&&o.push(a.slice(0,e-c,r)),i&&(o.push(i),i=void 0),u>t&&o.push(a.slice(t-c,a.size,r)))}return o}function ec(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,c;if(us(t)){for(a=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&B.isSelectable(f)&&i.parent&&!(f.isInline&&Nb(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new B(s==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,d=s;for(let h=0;h<t.rangeCount;h++){let p=t.getRangeAt(h);f=Math.min(f,n.docView.posFromDOM(p.startContainer,p.startOffset,1)),d=Math.max(d,n.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(f<0)return null;[a,s]=d==n.state.selection.anchor?[d,f]:[f,d],l=r.resolve(s)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let u=r.resolve(a);if(!c){let f=e=="pointer"||n.state.selection.head<l.pos&&!o?1:-1;c=tc(n,u,l,f)}return c}function gp(n){return n.editable?n.hasFocus():xp(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function It(n,e=!1){let t=n.state.selection;if(yp(n,t),!!gp(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&me){let r=n.domSelectionRange(),i=n.domObserver.currentSelection;if(r.anchorNode&&i.anchorNode&&On(r.anchorNode,r.anchorOffset,i.anchorNode,i.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)Qb(n);else{let{anchor:r,head:i}=t,o,s;Ld&&!(t instanceof j)&&(t.$from.parent.inlineContent||(o=Bd(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(s=Bd(n,t.to))),n.docView.setSelection(r,i,n,e),Ld&&(o&&zd(o),s&&zd(s)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Yb(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}var Ld=we||me&&op<63;function Bd(n,e){let{node:t,offset:r}=n.docView.domFromPos(e,0),i=r<t.childNodes.length?t.childNodes[r]:null,o=r?t.childNodes[r-1]:null;if(we&&i&&i.contentEditable=="false")return Ra(i);if((!i||i.contentEditable=="false")&&(!o||o.contentEditable=="false")){if(i)return Ra(i);if(o)return Ra(o)}}function Ra(n){return n.contentEditable="true",we&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function zd(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Yb(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),r=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!gp(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Qb(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,r=t.nodeName=="IMG";r?e.collapse(t.parentNode,pe(t)+1):e.collapse(t,0),!r&&!n.state.selection.visible&&Re&&qt<=11&&(t.disabled=!0,t.disabled=!1)}function yp(n,e){if(e instanceof B){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Fd(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Fd(n)}function Fd(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function tc(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||j.between(e,t,r)}function _d(n){return n.editable&&!n.hasFocus()?!1:xp(n)}function xp(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Xb(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return On(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ha(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&W.findFrom(o,e)}function jt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Vd(n,e,t){let r=n.state.selection;if(r instanceof j)if(t.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=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return jt(n,new j(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ha(n.state,e);return i&&i instanceof B?jt(n,i):!1}else if(!(qe&&t.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 l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?B.isSelectable(o)?jt(n,new B(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Ai?jt(n,new j(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof B&&r.node.isInline)return jt(n,new j(e>0?r.$to:r.$from));{let i=Ha(n.state,e);return i?jt(n,i):!1}}}function rs(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Mi(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function dr(n,e){return e<0?Zb(n):ew(n)}function Zb(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Ue&&t.nodeType==1&&r<rs(t)&&Mi(t.childNodes[r],-1)&&(s=!0);;)if(r>0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Mi(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(kp(t))break;{let l=t.previousSibling;for(;l&&Mi(l,-1);)i=t.parentNode,o=pe(l),l=l.previousSibling;if(l)t=l,r=rs(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?qa(n,t,r):i&&qa(n,i,o)}function ew(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=rs(t),o,s;for(;;)if(r<i){if(t.nodeType!=1)break;let l=t.childNodes[r];if(Mi(l,1))o=t,s=++r;else break}else{if(kp(t))break;{let l=t.nextSibling;for(;l&&Mi(l,1);)o=l.parentNode,s=pe(l)+1,l=l.nextSibling;if(l)t=l,r=0,i=rs(t);else{if(t=t.parentNode,t==n.dom)break;r=i=0}}}o&&qa(n,o,s)}function kp(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function tw(n,e){for(;n&&e==n.childNodes.length&&!Ei(n);)e=pe(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function nw(n,e){for(;n&&!e&&!Ei(n);)e=pe(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function qa(n,e,t){if(e.nodeType!=3){let o,s;(s=tw(e,t))?(e=s,t=0):(o=nw(e,t))&&(e=o,t=o.nodeValue.length)}let r=n.domSelection();if(!r)return;if(us(r)){let o=document.createRange();o.setEnd(e,t),o.setStart(e,t),r.removeAllRanges(),r.addRange(o)}else r.extend&&r.extend(e,t);n.domObserver.setCurSelection();let{state:i}=n;setTimeout(()=>{n.state==i&&It(n)},50)}function $d(n,e){let t=n.state.doc.resolve(e);if(!(me||sp)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.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<t.end()){let o=n.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(n.dom).direction=="rtl"?"rtl":"ltr"}function Wd(n,e,t){let r=n.state.selection;if(r instanceof j&&!r.empty||t.indexOf("s")>-1||qe&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ha(n.state,e);if(s&&s instanceof B)return jt(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Fe?W.near(s,e):W.findFrom(s,e);return l?jt(n,l):!1}return!1}function jd(n,e){if(!(n.state.selection instanceof j))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function Hd(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function rw(n){if(!we||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;Hd(n,r,"true"),setTimeout(()=>Hd(n,r,"false"),20)}return!1}function iw(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function ow(n,e){let t=e.keyCode,r=iw(e);if(t==8||qe&&t==72&&r=="c")return jd(n,-1)||dr(n,-1);if(t==46&&!e.shiftKey||qe&&t==68&&r=="c")return jd(n,1)||dr(n,1);if(t==13||t==27)return!0;if(t==37||qe&&t==66&&r=="c"){let i=t==37?$d(n,n.state.selection.from)=="ltr"?-1:1:-1;return Vd(n,i,r)||dr(n,i)}else if(t==39||qe&&t==70&&r=="c"){let i=t==39?$d(n,n.state.selection.from)=="ltr"?1:-1:1;return Vd(n,i,r)||dr(n,i)}else{if(t==38||qe&&t==80&&r=="c")return Wd(n,-1,r)||dr(n,-1);if(t==40||qe&&t==78&&r=="c")return rw(n)||Wd(n,1,r)||dr(n,1);if(r==(qe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function nc(n,e){n.someProp("transformCopied",h=>{e=h(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let h=r.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let s=n.someProp("clipboardSerializer")||sn.fromSchema(n.state.schema),l=Np(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let c=a.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Mp[c.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let p=l.createElement(u[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),f++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,` 39 + `),i;function o(s){return r.stack.push(s),l;function l(){r.stack.pop()}}}function Pk(n){throw new Error("Cannot handle value `"+n+"`, expected node")}function Lk(n){let e=n;throw new Error("Cannot handle unknown node `"+e.type+"`")}function Bk(n,e){if(n.type==="definition"&&n.type===e.type)return 0}function zk(n,e){return _h(n,this,e)}function Fk(n,e){return Vh(n,this,e)}function _k(n,e){return jh(this,n,e)}function cr(n){let e=this;e.compiler=t;function t(r){return ua(r,{...e.data("settings"),...n,extensions:e.data("toMarkdownExtensions")||[]})}}function fa(n){if(n)throw n}var Fo=Ag(Zh(),1);function ui(n){if(typeof n!="object"||n===null)return!1;let e=Object.getPrototypeOf(n);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in n)&&!(Symbol.iterator in n)}function ha(){let n=[],e={run:t,use:r};return e;function t(...i){let o=-1,s=i.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);l(null,...i);function l(a,...c){let u=n[++o],f=-1;if(a){s(a);return}for(;++f<i.length;)(c[f]===null||c[f]===void 0)&&(c[f]=i[f]);i=c,u?ed(u,l)(...c):s(null,...c)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return n.push(i),e}}function ed(n,e){let t;return r;function r(...s){let l=n.length>s.length,a;l&&s.push(i);try{a=n.apply(this,s)}catch(c){let u=c;if(l&&t)throw u;return i(u)}l||(a&&a.then&&typeof a.then=="function"?a.then(o,i):a instanceof Error?i(a):o(a))}function i(s,...l){t||(t=!0,e(s,...l))}function o(s){i(null,s)}}var ce=class extends Error{constructor(e,t,r){super(),typeof t=="string"&&(r=t,t=void 0);let i="",o={},s=!1;if(t&&("line"in t&&"column"in t?o={place:t}:"start"in t&&"end"in t?o={place:t}:"type"in t?o={ancestors:[t],place:t.position}:o={...t}),typeof e=="string"?i=e:!o.cause&&e&&(s=!0,i=e.message,o.cause=e),!o.ruleId&&!o.source&&typeof r=="string"){let a=r.indexOf(":");a===-1?o.ruleId=r:(o.source=r.slice(0,a),o.ruleId=r.slice(a+1))}if(!o.place&&o.ancestors&&o.ancestors){let a=o.ancestors[o.ancestors.length-1];a&&(o.place=a.position)}let l=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=l?l.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=l?l.line:void 0,this.name=Ft(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=s&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};ce.prototype.file="";ce.prototype.name="";ce.prototype.reason="";ce.prototype.message="";ce.prototype.stack="";ce.prototype.column=void 0;ce.prototype.line=void 0;ce.prototype.ancestors=void 0;ce.prototype.cause=void 0;ce.prototype.fatal=void 0;ce.prototype.place=void 0;ce.prototype.ruleId=void 0;ce.prototype.source=void 0;var tt={basename:Vk,dirname:$k,extname:Wk,join:jk,sep:"/"};function Vk(n,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');fi(n);let t=0,r=-1,i=n.length,o;if(e===void 0||e.length===0||e.length>n.length){for(;i--;)if(n.codePointAt(i)===47){if(o){t=i+1;break}}else r<0&&(o=!0,r=i+1);return r<0?"":n.slice(t,r)}if(e===n)return"";let s=-1,l=e.length-1;for(;i--;)if(n.codePointAt(i)===47){if(o){t=i+1;break}}else s<0&&(o=!0,s=i+1),l>-1&&(n.codePointAt(i)===e.codePointAt(l--)?l<0&&(r=i):(l=-1,r=s));return t===r?r=s:r<0&&(r=n.length),n.slice(t,r)}function $k(n){if(fi(n),n.length===0)return".";let e=-1,t=n.length,r;for(;--t;)if(n.codePointAt(t)===47){if(r){e=t;break}}else r||(r=!0);return e<0?n.codePointAt(0)===47?"/":".":e===1&&n.codePointAt(0)===47?"//":n.slice(0,e)}function Wk(n){fi(n);let e=n.length,t=-1,r=0,i=-1,o=0,s;for(;e--;){let l=n.codePointAt(e);if(l===47){if(s){r=e+1;break}continue}t<0&&(s=!0,t=e+1),l===46?i<0?i=e:o!==1&&(o=1):i>-1&&(o=-1)}return i<0||t<0||o===0||o===1&&i===t-1&&i===r+1?"":n.slice(i,t)}function jk(...n){let e=-1,t;for(;++e<n.length;)fi(n[e]),n[e]&&(t=t===void 0?n[e]:t+"/"+n[e]);return t===void 0?".":Hk(t)}function Hk(n){fi(n);let e=n.codePointAt(0)===47,t=qk(n,!e);return t.length===0&&!e&&(t="."),t.length>0&&n.codePointAt(n.length-1)===47&&(t+="/"),e?"/"+t:t}function qk(n,e){let t="",r=0,i=-1,o=0,s=-1,l,a;for(;++s<=n.length;){if(s<n.length)l=n.codePointAt(s);else{if(l===47)break;l=47}if(l===47){if(!(i===s-1||o===1))if(i!==s-1&&o===2){if(t.length<2||r!==2||t.codePointAt(t.length-1)!==46||t.codePointAt(t.length-2)!==46){if(t.length>2){if(a=t.lastIndexOf("/"),a!==t.length-1){a<0?(t="",r=0):(t=t.slice(0,a),r=t.length-1-t.lastIndexOf("/")),i=s,o=0;continue}}else if(t.length>0){t="",r=0,i=s,o=0;continue}}e&&(t=t.length>0?t+"/..":"..",r=2)}else t.length>0?t+="/"+n.slice(i+1,s):t=n.slice(i+1,s),r=s-i-1;i=s,o=0}else l===46&&o>-1?o++:o=-1}return t}function fi(n){if(typeof n!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(n))}var td={cwd:Kk};function Kk(){return"/"}function ur(n){return!!(n!==null&&typeof n=="object"&&"href"in n&&n.href&&"protocol"in n&&n.protocol&&n.auth===void 0)}function nd(n){if(typeof n=="string")n=new URL(n);else if(!ur(n)){let e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+n+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(n.protocol!=="file:"){let e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return Uk(n)}function Uk(n){if(n.hostname!==""){let r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}let e=n.pathname,t=-1;for(;++t<e.length;)if(e.codePointAt(t)===37&&e.codePointAt(t+1)===50){let r=e.codePointAt(t+2);if(r===70||r===102){let i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(e)}var da=["history","path","basename","stem","extname","dirname"],hi=class{constructor(e){let t;e?ur(e)?t={path:e}:typeof e=="string"||Jk(e)?t={value:e}:t=e:t={},this.cwd="cwd"in t?"":td.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<da.length;){let o=da[r];o in t&&t[o]!==void 0&&t[o]!==null&&(this[o]=o==="history"?[...t[o]]:t[o])}let i;for(i in t)da.includes(i)||(this[i]=t[i])}get basename(){return typeof this.path=="string"?tt.basename(this.path):void 0}set basename(e){ma(e,"basename"),pa(e,"basename"),this.path=tt.join(this.dirname||"",e)}get dirname(){return typeof this.path=="string"?tt.dirname(this.path):void 0}set dirname(e){rd(this.basename,"dirname"),this.path=tt.join(e||"",this.basename)}get extname(){return typeof this.path=="string"?tt.extname(this.path):void 0}set extname(e){if(pa(e,"extname"),rd(this.dirname,"extname"),e){if(e.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=tt.join(this.dirname,this.stem+(e||""))}get path(){return this.history[this.history.length-1]}set path(e){ur(e)&&(e=nd(e)),ma(e,"path"),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path=="string"?tt.basename(this.path,this.extname):void 0}set stem(e){ma(e,"stem"),pa(e,"stem"),this.path=tt.join(this.dirname||"",e+(this.extname||""))}fail(e,t,r){let i=this.message(e,t,r);throw i.fatal=!0,i}info(e,t,r){let i=this.message(e,t,r);return i.fatal=void 0,i}message(e,t,r){let i=new ce(e,t,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(e){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(e||void 0).decode(this.value)}};function pa(n,e){if(n&&n.includes(tt.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+tt.sep+"`")}function ma(n,e){if(!n)throw new Error("`"+e+"` cannot be empty")}function rd(n,e){if(!n)throw new Error("Setting `"+e+"` requires `path` to be set too")}function Jk(n){return!!(n&&typeof n=="object"&&"byteLength"in n&&"byteOffset"in n)}var id=(function(n){let r=this.constructor.prototype,i=r[n],o=function(){return i.apply(o,arguments)};return Object.setPrototypeOf(o,r),o});var Gk={}.hasOwnProperty,ka=class n extends id{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=ha()}copy(){let e=new n,t=-1;for(;++t<this.attachers.length;){let r=this.attachers[t];e.use(...r)}return e.data((0,Fo.default)(!0,{},this.namespace)),e}data(e,t){return typeof e=="string"?arguments.length===2?(xa("data",this.frozen),this.namespace[e]=t,this):Gk.call(this.namespace,e)&&this.namespace[e]||void 0:e?(xa("data",this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);let i=t.call(e,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(e){this.freeze();let t=zo(e),r=this.parser||this.Parser;return ga("parse",r),r(String(t),t)}process(e,t){let r=this;return this.freeze(),ga("process",this.parser||this.Parser),ya("process",this.compiler||this.Compiler),t?i(void 0,t):new Promise(i);function i(o,s){let l=zo(e),a=r.parse(l);r.run(a,l,function(u,f,d){if(u||!f||!d)return c(u);let h=f,p=r.stringify(h,d);Qk(p)?d.value=p:d.result=p,c(u,d)});function c(u,f){u||!f?s(u):o?o(f):t(void 0,f)}}}processSync(e){let t=!1,r;return this.freeze(),ga("processSync",this.parser||this.Parser),ya("processSync",this.compiler||this.Compiler),this.process(e,i),sd("processSync","process",t),r;function i(o,s){t=!0,fa(o),r=s}}run(e,t,r){od(e),this.freeze();let i=this.transformers;return!r&&typeof t=="function"&&(r=t,t=void 0),r?o(void 0,r):new Promise(o);function o(s,l){let a=zo(t);i.run(e,a,c);function c(u,f,d){let h=f||e;u?l(u):s?s(h):r(void 0,h,d)}}}runSync(e,t){let r=!1,i;return this.run(e,t,o),sd("runSync","run",r),i;function o(s,l){fa(s),i=l,r=!0}}stringify(e,t){this.freeze();let r=zo(t),i=this.compiler||this.Compiler;return ya("stringify",i),od(e),i(e,r)}use(e,...t){let r=this.attachers,i=this.namespace;if(xa("use",this.frozen),e!=null)if(typeof e=="function")a(e,t);else if(typeof e=="object")Array.isArray(e)?l(e):s(e);else throw new TypeError("Expected usable value, not `"+e+"`");return this;function o(c){if(typeof c=="function")a(c,[]);else if(typeof c=="object")if(Array.isArray(c)){let[u,...f]=c;a(u,f)}else s(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function s(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(c.plugins),c.settings&&(i.settings=(0,Fo.default)(!0,i.settings,c.settings))}function l(c){let u=-1;if(c!=null)if(Array.isArray(c))for(;++u<c.length;){let f=c[u];o(f)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function a(c,u){let f=-1,d=-1;for(;++f<r.length;)if(r[f][0]===c){d=f;break}if(d===-1)r.push([c,...u]);else if(u.length>0){let[h,...p]=u,m=r[d][1];ui(m)&&ui(h)&&(h=(0,Fo.default)(!0,m,h)),r[d]=[c,h,...p]}}}},di=new ka().freeze();function ga(n,e){if(typeof e!="function")throw new TypeError("Cannot `"+n+"` without `parser`")}function ya(n,e){if(typeof e!="function")throw new TypeError("Cannot `"+n+"` without `compiler`")}function xa(n,e){if(e)throw new Error("Cannot call `"+n+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function od(n){if(!ui(n)||typeof n.type!="string")throw new TypeError("Expected node, got `"+n+"`")}function sd(n,e,t){if(!t)throw new Error("`"+n+"` finished async. Use `"+e+"` instead")}function zo(n){return Yk(n)?n:new hi(n)}function Yk(n){return!!(n&&typeof n=="object"&&"message"in n&&"messages"in n)}function Qk(n){return typeof n=="string"||Xk(n)}function Xk(n){return!!(n&&typeof n=="object"&&"byteLength"in n&&"byteOffset"in n)}var ad=n=>{throw TypeError(n)},cd=(n,e,t)=>e.has(n)||ad("Cannot "+t),H=(n,e,t)=>(cd(n,e,"read from private field"),t?t.call(n):e.get(n)),oe=(n,e,t)=>e.has(n)?ad("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),ee=(n,e,t,r)=>(cd(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),lt,pi,_o,Vo,$o,mi,gi,wt,yi,Wo,jo,xi,Ho,ki,qo,Ko,fr,wn,Uo,bi,Jo=class{},Go=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=e=>{this.top()?.push(e)},this.open=e=>{this.elements.push(e)},this.close=()=>{let e=this.elements.pop();if(!e)throw il();return e}}},ba=class n extends Jo{constructor(e,t,r){super(),this.type=e,this.content=t,this.attrs=r}push(e,...t){this.content.push(e,...t)}pop(){return this.content.pop()}static create(e,t,r){return new n(e,t,r)}},wa=class extends Go{constructor(e){super(),oe(this,lt),oe(this,pi),oe(this,_o),oe(this,Vo),oe(this,$o),oe(this,mi),oe(this,gi),ee(this,lt,q.none),ee(this,pi,t=>t.isText),ee(this,_o,(t,r)=>{if(H(this,pi).call(this,t)&&H(this,pi).call(this,r)&&q.sameSet(t.marks,r.marks))return this.schema.text(t.text+r.text,t.marks)}),ee(this,Vo,t=>{let r=Object.values({...this.schema.nodes,...this.schema.marks}).find(i=>i.spec.parseMarkdown.match(t));if(!r)throw Au(t);return r}),ee(this,$o,t=>{let r=H(this,Vo).call(this,t);r.spec.parseMarkdown.runner(this,t,r)}),this.injectRoot=(t,r,i)=>(this.openNode(r,i),this.next(t.children),this),this.openNode=(t,r)=>(this.open(ba.create(t,[],r)),this),ee(this,mi,()=>{ee(this,lt,q.none);let t=this.close();return H(this,gi).call(this,t.type,t.attrs,t.content)}),this.closeNode=()=>{try{H(this,mi).call(this)}catch(t){console.error(t)}return this},ee(this,gi,(t,r,i)=>{let o=t.createAndFill(r,i,H(this,lt));if(!o)throw Eu(t,r,i);return this.push(o),o}),this.addNode=(t,r,i)=>{try{H(this,gi).call(this,t,r,i)}catch(o){console.error(o)}return this},this.openMark=(t,r)=>{let i=t.create(r);return ee(this,lt,i.addToSet(H(this,lt))),this},this.closeMark=t=>(ee(this,lt,t.removeFromSet(H(this,lt))),this),this.addText=t=>{try{let r=this.top();if(!r)throw il();let i=r.pop(),o=this.schema.text(t,H(this,lt));if(!i)return r.push(o),this;let s=H(this,_o).call(this,i,o);return s?(r.push(s),this):(r.push(i,o),this)}catch(r){return console.error(r),this}},this.build=()=>{let t;do t=H(this,mi).call(this);while(this.size());return t},this.next=(t=[])=>([t].flat().forEach(r=>H(this,$o).call(this,r)),this),this.toDoc=()=>this.build(),this.run=(t,r)=>{let i=t.runSync(t.parse(r),r);return this.next(i),this},this.schema=e}};lt=new WeakMap;pi=new WeakMap;_o=new WeakMap;Vo=new WeakMap;$o=new WeakMap;mi=new WeakMap;gi=new WeakMap;wa.create=(n,e)=>{let t=new wa(n);return r=>(t.run(e,r),t.toDoc())};var ud=wa,Sa=class extends Jo{constructor(e,t,r,i={}){super(),this.type=e,this.children=t,this.value=r,this.props=i,this.push=(o,...s)=>{this.children||(this.children=[]),this.children.push(o,...s)},this.pop=()=>this.children?.pop()}};Sa.create=(n,e,t,r={})=>new Sa(n,e,t,r);var ld=Sa,Zk=n=>Object.prototype.hasOwnProperty.call(n,"size"),Ca=class extends Go{constructor(e){super(),oe(this,wt),oe(this,yi),oe(this,Wo),oe(this,jo),oe(this,xi),oe(this,Ho),oe(this,ki),oe(this,qo),oe(this,Ko),oe(this,fr),oe(this,wn),oe(this,Uo),oe(this,bi),ee(this,wt,q.none),ee(this,yi,t=>{let r=Object.values({...this.schema.nodes,...this.schema.marks}).find(i=>i.spec.toMarkdown.match(t));if(!r)throw Ru(t.type);return r}),ee(this,Wo,t=>H(this,yi).call(this,t).spec.toMarkdown.runner(this,t)),ee(this,jo,(t,r)=>H(this,yi).call(this,t).spec.toMarkdown.runner(this,t,r)),ee(this,xi,t=>{let{marks:r}=t,i=l=>l.type.spec.priority??50;[...r].sort((l,a)=>i(l)-i(a)).every(l=>!H(this,jo).call(this,l,t))&&H(this,Wo).call(this,t),r.forEach(l=>H(this,bi).call(this,l))}),ee(this,Ho,(t,r)=>{if(t.type===r||t.children?.length!==1)return t;let i=a=>{if(a.type===r)return a;if(a.children?.length!==1)return null;let[c]=a.children;return c?i(c):null},o=i(t);if(!o)return t;let s=o.children?[...o.children]:void 0,l={...t,children:s};return l.children=s,o.children=[l],o}),ee(this,ki,t=>{let{children:r}=t;return r&&(t.children=r.reduce((i,o,s)=>{if(s===0)return[o];let l=i.at(-1);if(l&&l.isMark&&o.isMark){o=H(this,Ho).call(this,o,l.type);let{children:a,...c}=o,{children:u,...f}=l;if(o.type===l.type&&a&&u&&JSON.stringify(c)===JSON.stringify(f)){let d={...f,children:[...u,...a]};return i.slice(0,-1).concat(H(this,ki).call(this,d))}}return i.concat(o)},[])),t}),ee(this,qo,t=>{let r={...t.props,type:t.type};return t.children&&(r.children=t.children),t.value&&(r.value=t.value),r}),this.openNode=(t,r,i)=>(this.open(ld.create(t,void 0,r,i)),this),ee(this,Ko,(t,r)=>{let i="",o="",s=t.children,l=-1,a=-1,c=f=>{f&&f.forEach((d,h)=>{d.type==="text"&&d.value&&(l<0&&(l=h),a=h)})};if(s){c(s);let f=s?.[a],d=s?.[l];if(f&&f.value.endsWith(" ")){let h=f.value,p=h.trimEnd();o=h.slice(p.length),f.value=p}if(d&&d.value.startsWith(" ")){let h=d.value,p=h.trimStart();i=h.slice(0,h.length-p.length),d.value=p}}i.length&&H(this,wn).call(this,"text",void 0,i);let u=r();return o.length&&H(this,wn).call(this,"text",void 0,o),u}),ee(this,fr,(t=!1)=>{let r=this.close(),i=()=>H(this,wn).call(this,r.type,r.children,r.value,r.props);return t?H(this,Ko).call(this,r,i):i()}),this.closeNode=()=>(H(this,fr).call(this),this),ee(this,wn,(t,r,i,o)=>{let s=ld.create(t,r,i,o),l=H(this,ki).call(this,H(this,qo).call(this,s));return this.push(l),l}),this.addNode=(t,r,i,o)=>(H(this,wn).call(this,t,r,i,o),this),ee(this,Uo,(t,r,i,o)=>t.isInSet(H(this,wt))?this:(ee(this,wt,t.addToSet(H(this,wt))),this.openNode(r,i,{...o,isMark:!0}))),ee(this,bi,t=>{t.isInSet(H(this,wt))&&(ee(this,wt,t.type.removeFromSet(H(this,wt))),H(this,fr).call(this,!0))}),this.withMark=(t,r,i,o)=>(H(this,Uo).call(this,t,r,i,o),this),this.closeMark=t=>(H(this,bi).call(this,t),this),this.build=()=>{let t=null;do t=H(this,fr).call(this);while(this.size());return t},this.next=t=>Zk(t)?(t.forEach(r=>{H(this,xi).call(this,r)}),this):(H(this,xi).call(this,t),this),this.toString=t=>t.stringify(this.build()),this.run=t=>(this.next(t),this),this.schema=e}};wt=new WeakMap;yi=new WeakMap;Wo=new WeakMap;jo=new WeakMap;xi=new WeakMap;Ho=new WeakMap;ki=new WeakMap;qo=new WeakMap;Ko=new WeakMap;fr=new WeakMap;wn=new WeakMap;Uo=new WeakMap;bi=new WeakMap;Ca.create=(n,e)=>{let t=new Ca(n);return r=>(t.run(r),t.toString(e))};var fd=Ca;var Ne=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?eb(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function eb(n){return function(e,t,r,i){let o=n;if(t[1]){let s=t[0].lastIndexOf(t[1]);o+=t[0].slice(s+t[1].length),r+=s;let l=r-i;l>0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var hd=(n,e)=>{let t=n.plugins;for(let r=0;r<t.length;r++){let i=t[r],o;if(i.spec.isInputRules&&(o=i.getState(n))){if(e){let s=n.tr,l=o.transform;for(let a=l.steps.length-1;a>=0;a--)s.step(l.steps[a].invert(l.docs[a]));if(o.text){let a=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,a))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},rE=new Ne(/--$/,"\u2014",{inCodeMark:!1}),iE=new Ne(/\.\.\.$/,"\u2026",{inCodeMark:!1}),oE=new Ne(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),sE=new Ne(/"$/,"\u201D",{inCodeMark:!1}),lE=new Ne(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),aE=new Ne(/'$/,"\u2019",{inCodeMark:!1});function Yo(n,e,t=null,r){return new Ne(n,(i,o,s,l)=>{let a=t instanceof Function?t(o):t,c=i.tr.delete(s,l),u=c.doc.resolve(s),f=u.blockRange(),d=f&&cn(f,e,a);if(!d)return null;c.wrap(f,d);let h=c.doc.resolve(s-1).nodeBefore;return h&&h.type==e&&fn(c.doc,s-1)&&(!r||r(o,h))&&c.join(s-1),c})}function Ma(n,e,t=null){return new Ne(n,(r,i,o,s)=>{let l=r.doc.resolve(o),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,a):null})}var Vt=typeof navigator<"u"?navigator:null,dd=typeof document<"u"?document:null,$t=Vt&&Vt.userAgent||"",Ia=/Edge\/(\d+)/.exec($t),xd=/MSIE \d/.exec($t),Ta=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec($t),Oa=!!(xd||Ta||Ia),hE=xd?document.documentMode:Ta?+Ta[1]:Ia?+Ia[1]:0,tb=!Oa&&/gecko\/(\d+)/i.test($t),dE=tb&&+(/Firefox\/(\d+)/.exec($t)||[0,0])[1],pd=!Oa&&/Chrome\/(\d+)/.exec($t);var pE=pd?+pd[1]:0,nb=!Oa&&!!Vt&&/Apple Computer/.test(Vt.vendor),rb=nb&&(/Mobile\/\w+/.test($t)||!!Vt&&Vt.maxTouchPoints>2),mE=rb||(Vt?/Mac/.test(Vt.platform):!1),gE=/Android \d/.test($t),ib=!!dd&&"webkitFontSmoothing"in dd.documentElement.style,yE=ib?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Na(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e);if(l.parent.type.spec.code)return!1;let a=l.parent.textBetween(Math.max(0,l.parentOffset-500),l.parentOffset,void 0,"\uFFFC")+r;for(let c of i){let u=c,f=u.match.exec(a),d=f&&f[0]&&u.handler(s,f,e-(f[0].length-r.length),t);if(d)return u.undoable!==!1&&d.setMeta(o,{transform:d,from:e,to:t,text:r}),n.dispatch(d),!0}return!1}var ob=new re("MILKDOWN_CUSTOM_INPUTRULES");function kd({rules:n}){let e=new ne({key:ob,isInputRules:!0,state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Na(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>(setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Na(t,r.pos,r.pos,"",n,e)}),!1)},handleKeyDown(t,r){if(r.key!=="Enter")return!1;let{$cursor:i}=t.state.selection;return i?Na(t,i.pos,i.pos,` 40 + `,n,e):!1}}});return e}function wi(n,e,t={}){return new Ne(n,(r,i,o,s)=>{var l,a,c,u;let{tr:f}=r,d=i.length,h=i[d-1],p=i[0],m=[],k=s,x={group:h,fullMatch:p,start:o,end:s},I=(l=t.updateCaptured)==null?void 0:l.call(t,x);if(Object.assign(x,I),{group:h,fullMatch:p,start:o,end:s}=x,p===null||h?.trim()==="")return null;if(h){let C=p.search(/\S/),A=o+p.indexOf(h),v=A+h.length;m=(a=f.storedMarks)!=null?a:[],v<s&&f.delete(v,s),A>o&&f.delete(o+C,A),k=o+C+h.length;let b=(c=t.getAttr)==null?void 0:c.call(t,i);f.addMark(o,k,e.create(b)),f.setStoredMarks(m),(u=t.beforeDispatch)==null||u.call(t,{match:i,start:o,end:s,tr:f})}return f})}var sb=Object.defineProperty,lb=Object.defineProperties,ab=Object.getOwnPropertyDescriptors,md=Object.getOwnPropertySymbols,cb=Object.prototype.hasOwnProperty,ub=Object.prototype.propertyIsEnumerable,gd=(n,e,t)=>e in n?sb(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,fb=(n,e)=>{for(var t in e||(e={}))cb.call(e,t)&&gd(n,t,e[t]);if(md)for(var t of md(e))ub.call(e,t)&&gd(n,t,e[t]);return n},hb=(n,e)=>lb(n,ab(e));function yd(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function bd(n,e,t){let i=n.state.doc.content.size,o=yd(e,0,i),s=yd(t,0,i),l=n.coordsAtPos(o),a=n.coordsAtPos(s,-1),c=Math.min(l.top,a.top),u=Math.max(l.bottom,a.bottom),f=Math.min(l.left,a.left),d=Math.max(l.right,a.right),h=d-f,p=u-c,x={top:c,bottom:u,left:f,right:d,width:h,height:p,x:f,y:c};return hb(fb({},x),{toJSON:()=>x})}function db(n,e){return Array.isArray(n)&&n.includes(e.type)||e.type===n}function wd(n,e){if(!(n instanceof B))return;let{node:t,$from:r}=n;if(db(e,t))return{node:t,pos:r.pos,start:r.start(r.depth),depth:r.depth}}var Sd=(n,e)=>{let{selection:t,doc:r}=n;if(t instanceof B)return{hasNode:t.node.type===e,pos:t.from,target:t.node};let{from:i,to:o}=t,s=!1,l=-1,a=null;return r.nodesBetween(i,o,(c,u)=>a?!1:c.type===e?(s=!0,l=u,a=c,!1):!0),{hasNode:s,pos:l,target:a}};var St={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:"'"},Xo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},pb=typeof navigator<"u"&&/Mac/.test(navigator.platform),mb=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(se=0;se<10;se++)St[48+se]=St[96+se]=String(se);var se;for(se=1;se<=24;se++)St[se+111]="F"+se;var se;for(se=65;se<=90;se++)St[se]=String.fromCharCode(se+32),Xo[se]=String.fromCharCode(se);var se;for(Qo in St)Xo.hasOwnProperty(Qo)||(Xo[Qo]=St[Qo]);var Qo;function Cd(n){var e=pb&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||mb&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Xo:St)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var gb=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),yb=typeof navigator<"u"&&/Win/.test(navigator.platform);function xb(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))s=!0;else if(/^a(lt)?$/i.test(a))r=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))o=!0;else if(/^mod$/i.test(a))gb?s=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return r&&(t="Alt-"+t),i&&(t="Ctrl-"+t),s&&(t="Meta-"+t),o&&(t="Shift-"+t),t}function kb(n){let e=Object.create(null);for(let t in n)e[xb(t)]=n[t];return e}function Ea(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function Md(n){return new ne({props:{handleKeyDown:bb(n)}})}function bb(n){let e=kb(n);return function(t,r){let i=Cd(r),o,s=e[Ea(i,r)];if(s&&s(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let l=e[Ea(i,r,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(yb&&r.ctrlKey&&r.altKey)&&(o=St[r.keyCode])&&o!=i){let l=e[Ea(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var pe=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},gr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},La=null,Mt=function(n,e,t){let r=La||(La=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},wb=function(){La=null},On=function(n,e,t,r){return t&&(Nd(n,e,t,r,-1)||Nd(n,e,t,r,1))},Sb=/^(img|br|input|textarea|hr)$/i;function Nd(n,e,t,r,i){for(var o;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ke(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Ei(n)||Sb.test(n.nodeName)||n.contentEditable=="false")return!1;e=pe(n)+(i<0?0:1),n=s}else if(n.nodeType==1){let s=n.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 n=s,e=i<0?Ke(n):0}else return!1}}function Ke(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Cb(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Ke(n)}else if(n.parentNode&&!Ei(n))e=pe(n),n=n.parentNode;else return null}}function Mb(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!Ei(n))e=pe(n)+1,n=n.parentNode;else return null}}function Nb(n,e,t){for(let r=e==0,i=e==Ke(n);r||i;){if(n==t)return!0;let o=pe(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Ke(n)}}function Ei(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}var us=function(n){return n.focusNode&&On(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Sn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Ib(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Tb(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(Ke(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(Ke(r.startContainer),r.startOffset)}}}var at=typeof navigator<"u"?navigator:null,Id=typeof document<"u"?document:null,Ut=at&&at.userAgent||"",Ba=/Edge\/(\d+)/.exec(Ut),ip=/MSIE \d/.exec(Ut),za=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ut),Re=!!(ip||za||Ba),qt=ip?document.documentMode:za?+za[1]:Ba?+Ba[1]:0,Ue=!Re&&/gecko\/(\d+)/i.test(Ut);Ue&&+(/Firefox\/(\d+)/.exec(Ut)||[0,0])[1];var Fa=!Re&&/Chrome\/(\d+)/.exec(Ut),me=!!Fa,op=Fa?+Fa[1]:0,we=!Re&&!!at&&/Apple Computer/.test(at.vendor),yr=we&&(/Mobile\/\w+/.test(Ut)||!!at&&at.maxTouchPoints>2),qe=yr||(at?/Mac/.test(at.platform):!1),sp=at?/Win/.test(at.platform):!1,Nt=/Android \d/.test(Ut),Ai=!!Id&&"webkitFontSmoothing"in Id.documentElement.style,Ob=Ai?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Eb(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Ct(n,e){return typeof n=="number"?n:n[e]}function Ab(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Td(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;){if(s.nodeType!=1){s=gr(s);continue}let l=s,a=l==o.body,c=a?Eb(o):Ab(l),u=0,f=0;if(e.top<c.top+Ct(r,"top")?f=-(c.top-e.top+Ct(i,"top")):e.bottom>c.bottom-Ct(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+Ct(i,"top")-c.top:e.bottom-c.bottom+Ct(i,"bottom")),e.left<c.left+Ct(r,"left")?u=-(c.left-e.left+Ct(i,"left")):e.right>c.right-Ct(r,"right")&&(u=e.right-c.right+Ct(i,"right")),u||f)if(a)o.defaultView.scrollBy(u,f);else{let h=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let m=l.scrollLeft-h,k=l.scrollTop-p;e={left:e.left-m,top:e.top-k,right:e.right-m,bottom:e.bottom-k}}let d=a?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:gr(s)}}function Rb(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s<Math.min(innerHeight,e.bottom);s+=5){let l=n.root.elementFromPoint(o,s);if(!l||l==n.dom||!n.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:lp(n.dom)}}function lp(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=gr(r));return e}function vb({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;ap(t,r==0?0:r-e)}function ap(n,e){for(let t=0;t<n.length;t++){let{dom:r,top:i,left:o}=n[t];r.scrollTop!=i+e&&(r.scrollTop=i+e),r.scrollLeft!=o&&(r.scrollLeft=o)}}var hr=null;function Db(n){if(n.setActive)return n.setActive();if(hr)return n.focus(hr);let e=lp(n);n.focus(hr==null?{get preventScroll(){return hr={preventScroll:!0},!0}}:void 0),hr||(hr=!1,ap(e,0))}function cp(n,e){let t,r=2e8,i,o=0,s=e.top,l=e.top,a,c;for(let u=n.firstChild,f=0;u;u=u.nextSibling,f++){let d;if(u.nodeType==1)d=u.getClientRects();else if(u.nodeType==3)d=Mt(u).getClientRects();else continue;for(let h=0;h<d.length;h++){let p=d[h];if(p.top<=s&&p.bottom>=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right<e.left?e.left-p.right:0;if(m<r){t=u,r=m,i=m&&t.nodeType==3?{left:p.right<e.left?p.right:p.left,top:e.top}:e,u.nodeType==1&&m&&(o=f+(e.left>=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=u,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?Pb(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:cp(t,i)}function Pb(n,e){let t=n.nodeValue.length,r=document.createRange(),i;for(let o=0;o<t;o++){r.setEnd(n,o+1),r.setStart(n,o);let s=Wt(r,1);if(s.top!=s.bottom&&Za(e,s)){i={node:n,offset:o+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:n,offset:0}}function Za(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Lb(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function Bb(n,e,t){let{node:r,offset:i}=cp(e,t),o=-1;if(r.nodeType==1&&!r.firstChild){let s=r.getBoundingClientRect();o=s.left!=s.right&&t.left>(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function zb(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right<r.left||a.bottom<r.top)&&(i=l.posAfter),s=!0),!l.contentDOM&&i<0&&!l.node.isText))return(l.node.isBlock?r.top<(a.top+a.bottom)/2:r.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;o=l.dom.parentNode}return i>-1?i:n.docView.posFromDOM(e,t,-1)}function up(n,e,t){let r=n.childNodes.length;if(r&&t.top<t.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-t.top)/(t.bottom-t.top))-2)),o=i;;){let s=n.childNodes[o];if(s.nodeType==1){let l=s.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Za(e,c))return up(s,e,c)}}if((o=(o+1)%r)==i)break}return n}function Fb(n,e){let t=n.dom.ownerDocument,r,i=0,o=Tb(t,e.left,e.top);o&&({node:r,offset:i}=o);let s=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!s||!n.dom.contains(s.nodeType!=1?s.parentNode:s)){let c=n.dom.getBoundingClientRect();if(!Za(e,c)||(s=up(n.dom,e,c),!s))return null}if(we)for(let c=s;r&&c;c=gr(c))c.draggable&&(r=void 0);if(s=Lb(s,e),r){if(Ue&&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;Ai&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=zb(n,r,i,e))}l==null&&(l=Bb(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Od(n){return n.top<n.bottom||n.left<n.right}function Wt(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(Od(r))return r}return Array.prototype.find.call(t,Od)||n.getBoundingClientRect()}var _b=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function fp(n,e,t){let{node:r,offset:i,atom:o}=n.docView.domFromPos(e,t<0?-1:1),s=Ai||Ue;if(r.nodeType==3)if(s&&(_b.test(r.nodeValue)||(t<0?!i:i==r.nodeValue.length))){let a=Wt(Mt(r,i,i),t);if(Ue&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let c=Wt(Mt(r,i-1,i-1),-1);if(c.top==a.top){let u=Wt(Mt(r,i,i+1),-1);if(u.top!=a.top)return Si(u,u.left<c.left)}}return a}else{let a=i,c=i,u=t<0?1:-1;return t<0&&!i?(c++,u=-1):t>=0&&i==r.nodeValue.length?(a--,u=1):t<0?a--:c++,Si(Wt(Mt(r,a,c),u),u<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==Ke(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Aa(a.getBoundingClientRect(),!1)}if(o==null&&i<Ke(r)){let a=r.childNodes[i];if(a.nodeType==1)return Aa(a.getBoundingClientRect(),!0)}return Aa(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==Ke(r))){let a=r.childNodes[i-1],c=a.nodeType==3?Mt(a,Ke(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Si(Wt(c,1),!1)}if(o==null&&i<Ke(r)){let a=r.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?Mt(a,0,s?0:1):a.nodeType==1?a:null:null;if(c)return Si(Wt(c,-1),!0)}return Si(Wt(r.nodeType==3?Mt(r):r,-t),t>=0)}function Si(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Aa(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function hp(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Vb(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return hp(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=fp(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Mt(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let u=a[c];if(u.bottom>u.top+1&&(t=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var $b=/[\u0590-\u08ac]/;function Wb(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!$b.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:hp(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let h=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),k=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(u,f),a&&(a!=u||c!=f)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),k}):r.pos==r.start()||r.pos==r.end()}var Ed=null,Ad=null,Rd=!1;function jb(n,e,t){return Ed==e&&Ad==t?Rd:(Ed=e,Ad=t,Rd=t=="up"||t=="down"?Vb(n,e,t):Wb(n,e,t))}var Je=0,vd=1,Cn=2,ct=3,En=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Je,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].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 t=0,r=this.posAtStart;;t++){let i=this.children[t];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,t,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[t-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[t];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=t>pe(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(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==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,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||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 t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;t<this.children.length;t++){let i=this.children[t],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 l=i.children[s];if(l.size){i=l;break}}return i}if(e<o)return i.descAt(e-r-i.border);r=o}}domFromPos(e,t){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],l=o+s.size;if(l>e||s instanceof ts){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Zo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?pe(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,t):{node:this.contentDOM,offset:o?pe(o.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,o=-1;for(let s=r,l=0;;l++){let a=this.children[l],c=s+a.size;if(i==-1&&e<=c){let u=s+a.border;if(e>=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=pe(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){o=pe(f.dom);break}t+=f.size}o==-1&&(o=this.contentDOM.childNodes.length);break}s=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:o}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:r}=this.domFromPos(e,0);if(t.nodeType!=1||r==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[r]}setSelection(e,t,r,i=!1){let o=Math.min(e,t),s=Math.max(e,t);for(let h=0,p=0;h<this.children.length;h++){let m=this.children[h],k=p+m.size;if(o>p&&s<k)return m.setSelection(e-p-m.border,t-p-m.border,r,i);p=k}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=r.root.getSelection(),u=r.domSelectionRange(),f=!1;if((Ue||we)&&e==t){let{node:h,offset:p}=l;if(h.nodeType==3){if(f=!!(p&&h.nodeValue[p-1]==` 41 + `),f&&p==h.nodeValue.length)for(let m=h,k;m;m=m.parentNode){if(k=m.nextSibling){k.nodeName=="BR"&&(l=a={node:k.parentNode,offset:pe(k)+1});break}let x=m.pmViewDesc;if(x&&x.node&&x.node.isBlock)break}}else{let m=h.childNodes[p-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(Ue&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){let h=u.focusNode.childNodes[u.focusOffset];h&&h.contentEditable=="false"&&(i=!0)}if(!(i||f&&we)&&On(l.node,l.offset,u.anchorNode,u.anchorOffset)&&On(a.node,a.offset,u.focusNode,u.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(f&&Ue)){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(h)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){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&&t>=r:e<s&&t>r){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Cn:vd,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=ct:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Cn:ct}r=s}this.dirty=Cn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Cn:vd;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},Zo=class extends En{constructor(e,t,r,i){let o,s=t.type.toDOM;if(typeof s=="function"&&(s=s(r,()=>{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==Je&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(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}},_a=class extends En{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},xr=class n extends En{constructor(e,t,r,i,o){super(e,[],r,i),this.mark=t,this.spec=o}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=sn.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&ct||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ct&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Je){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=Je}}slice(e,t,r){let i=n.create(this.parent,this.mark,!0,r),o=this.children,s=this.size;t<s&&(o=ja(o,t,s,r)),e>0&&(o=ja(o,0,e,r));for(let l=0;l<o.length;l++)o[l].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()}},Kt=class n extends En{constructor(e,t,r,i,o,s,l,a,c){super(e,[],o,s),this.node=t,this.outerDeco=r,this.innerDeco=i,this.nodeDOM=l}static create(e,t,r,i,o,s){let l=o.nodeViews[t.type.name],a,c=l&&l(t,o,()=>{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=sn.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let d=u;return u=mp(u,r,t),c?a=new Va(e,t,r,i,u,f||null,d,c,o,s+1):t.isText?new es(e,t,r,i,u,d,o):new n(e,t,r,i,u,f||null,d,o,s+1)}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 t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>M.empty)}return e}matchesNode(e,t,r){return this.dirty==Je&&e.eq(this.node)&&ns(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new Wa(this,s&&s.node,e);Ub(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&a.syncToMarks(u==this.node.childCount?q.none:this.node.child(u).marks,r,e,u),a.placeWidget(c,e,i)},(c,u,f,d)=>{a.syncToMarks(c.marks,r,e,d);let h;a.findNodeMatch(c,u,f,d)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(h=a.findIndexWithChild(o.node))>-1&&a.updateNodeAt(c,u,f,h,e)||a.updateNextNode(c,u,f,e,d,i)||a.addNode(c,u,f,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Cn)&&(s&&this.protectLocalComposition(e,s),dp(this.contentDOM,this.children,e),yr&&Jb(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof j)||r<t||i>t+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,l=Gb(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;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 _a(this,o,t,i);e.input.compositionNodes.push(s),this.children=ja(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==ct||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Je}updateOuterDeco(e){if(ns(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=pp(this.dom,this.nodeDOM,$a(this.outerDeco,this.node,t),$a(e,this.node,t)),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 Dd(n,e,t,r,i){mp(r,e,n);let o=new Kt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var es=class n extends Kt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==ct||this.dirty!=Je&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Je||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=Je,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=ct)}get domAtom(){return!1}isText(e){return this.node.text==e}},ts=class extends En{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Je&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Va=class extends Kt{constructor(e,t,r,i,o,s,l,a,c,u){super(e,t,r,i,o,s,l,c,u),this.spec=a}update(e,t,r,i){if(this.dirty==ct)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,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 dp(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o<e.length;o++){let s=e[o],l=s.dom;if(l.parentNode==n){for(;l!=r;)r=Pd(r),i=!0;r=r.nextSibling}else i=!0,n.insertBefore(l,r);if(s instanceof xr){let a=r?r.previousSibling:n.lastChild;dp(s.contentDOM,s.children,t),r=a?a.nextSibling:n.firstChild}}for(;r;)r=Pd(r),i=!0;i&&t.trackWrites==n&&(t.trackWrites=null)}var Ci=function(n){n&&(this.nodeName=n)};Ci.prototype=Object.create(null);var Mn=[new Ci];function $a(n,e,t){if(n.length==0)return Mn;let r=t?Mn[0]:new Ci,i=[r];for(let o=0;o<n.length;o++){let s=n[o].type.attrs;if(s){s.nodeName&&i.push(r=new Ci(s.nodeName));for(let l in s){let a=s[l];a!=null&&(t&&i.length==1&&i.push(r=new Ci(e.isInline?"span":"div")),l=="class"?r.class=(r.class?r.class+" ":"")+a:l=="style"?r.style=(r.style?r.style+";":"")+a:l!="nodeName"&&(r[l]=a))}}}return i}function pp(n,e,t,r){if(t==Mn&&r==Mn)return e;let i=e;for(let o=0;o<r.length;o++){let s=r[o],l=t[o];if(o){let a;l&&l.nodeName==s.nodeName&&i!=n&&(a=i.parentNode)&&a.nodeName.toLowerCase()==s.nodeName||(a=document.createElement(s.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=Mn[0]),i=a}Hb(i,l||Mn[0],s)}return i}function Hb(n,e,t){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in t)&&n.removeAttribute(r);for(let r in t)r!="class"&&r!="style"&&r!="nodeName"&&t[r]!=e[r]&&n.setAttribute(r,t[r]);if(e.class!=t.class){let r=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let o=0;o<r.length;o++)i.indexOf(r[o])==-1&&n.classList.remove(r[o]);for(let o=0;o<i.length;o++)r.indexOf(i[o])==-1&&n.classList.add(i[o]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=r.exec(e.style);)n.style.removeProperty(i[1])}t.style&&(n.style.cssText+=t.style)}}function mp(n,e,t){return pp(n,n,Mn,$a(e,t,n.nodeType!=1))}function ns(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function Pd(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}var Wa=class{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=qb(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let r=e;r<t;r++)this.top.children[r].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,r,i){let o=0,s=this.stack.length>>1,l=Math.min(s,e.length);for(;o<l&&(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=Je,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let a=-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)){a=u;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=xr.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,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,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,r)&&!this.preMatch.matched.has(c)){o=l;break}}return o<0?!1:(this.destroyBetween(this.index,o),this.index++,!0)}updateNodeAt(e,t,r,i,o){let s=this.top.children[i];return s.dirty==ct&&s.dom==s.contentDOM&&(s.dirty=Cn),s.update(e,t,r,o)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==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=t}}updateNextNode(e,t,r,i,o,s){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Kt){let c=this.preMatch.matched.get(a);if(c!=null&&c!=o)return!1;let u=a.dom,f,d=this.isLocked(u)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=ct&&ns(t,a.outerDeco));if(!d&&a.update(e,t,r,i))return this.destroyBetween(this.index,l),a.dom!=u&&(this.changed=!0),this.index++,!0;if(!d&&(f=this.recreateWrapper(a,e,t,r,i,s)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Cn,f.updateChildren(i,s+1),f.dirty=Je),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,r,i,o,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!ns(r,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Kt.create(this.top,t,r,i,o,s);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,r,i,o){let s=Kt.create(this.top,e,t,r,i,o);s.contentDOM&&s.updateChildren(i,o+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,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 Zo(this.top,e,t,r);this.top.children.splice(this.index++,0,o),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof xr;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof es)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((we||me)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.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 ts(this.top,[],r,null);t!=this.top?t.children.push(i):t.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 qb(n,e){let t=e,r=t.children.length,i=n.childCount,o=new Map,s=[];e:for(;i>0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof xr)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Kb(n,e){return n.type.side-e.type.side}function Ub(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let c=0;c<n.childCount;c++){let u=n.child(c);r(u,i,e.forChild(o,u),c),o+=u.nodeSize}return}let s=0,l=[],a=null;for(let c=0;;){let u,f;for(;s<i.length&&i[s].to==o;){let k=i[s++];k.widget&&(u?(f||(f=[u])).push(k):u=k)}if(u)if(f){f.sort(Kb);for(let k=0;k<f.length;k++)t(f[k],c,!!a)}else t(u,c,!!a);let d,h;if(a)h=-1,d=a,a=null;else if(c<n.childCount)h=c,d=n.child(c++);else break;for(let k=0;k<l.length;k++)l[k].to<=o&&l.splice(k--,1);for(;s<i.length&&i[s].from<=o&&i[s].to>o;)l.push(i[s++]);let p=o+d.nodeSize;if(d.isText){let k=p;s<i.length&&i[s].from<k&&(k=i[s].from);for(let x=0;x<l.length;x++)l[x].to<k&&(k=l[x].to);k<p&&(a=d.cut(k-o),d=d.cut(0,k-o),p=k,h=-1)}else for(;s<i.length&&i[s].to<p;)s++;let m=d.isInline&&!d.isLeaf?l.filter(k=>!k.inline):l.slice();r(d,m,e.forChild(o,d),h),o=p}}function Jb(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Gb(n,e,t,r){for(let i=0,o=0;i<n.childCount&&o<=r;){let s=n.child(i++),l=o;if(o+=s.nodeSize,!s.isText)continue;let a=s.text;for(;i<n.childCount;){let c=n.child(i++);if(o+=c.nodeSize,!c.isText)break;a+=c.text}if(o>=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l<r?a.lastIndexOf(e,r-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function ja(n,e,t,r,i){let o=[];for(let s=0,l=0;s<n.length;s++){let a=n[s],c=l,u=l+=a.size;c>=t||u<=e?o.push(a):(c<e&&o.push(a.slice(0,e-c,r)),i&&(o.push(i),i=void 0),u>t&&o.push(a.slice(t-c,a.size,r)))}return o}function ec(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,c;if(us(t)){for(a=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&B.isSelectable(f)&&i.parent&&!(f.isInline&&Nb(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new B(s==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,d=s;for(let h=0;h<t.rangeCount;h++){let p=t.getRangeAt(h);f=Math.min(f,n.docView.posFromDOM(p.startContainer,p.startOffset,1)),d=Math.max(d,n.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(f<0)return null;[a,s]=d==n.state.selection.anchor?[d,f]:[f,d],l=r.resolve(s)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let u=r.resolve(a);if(!c){let f=e=="pointer"||n.state.selection.head<l.pos&&!o?1:-1;c=tc(n,u,l,f)}return c}function gp(n){return n.editable?n.hasFocus():xp(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function It(n,e=!1){let t=n.state.selection;if(yp(n,t),!!gp(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&me){let r=n.domSelectionRange(),i=n.domObserver.currentSelection;if(r.anchorNode&&i.anchorNode&&On(r.anchorNode,r.anchorOffset,i.anchorNode,i.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)Qb(n);else{let{anchor:r,head:i}=t,o,s;Ld&&!(t instanceof j)&&(t.$from.parent.inlineContent||(o=Bd(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(s=Bd(n,t.to))),n.docView.setSelection(r,i,n,e),Ld&&(o&&zd(o),s&&zd(s)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Yb(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}var Ld=we||me&&op<63;function Bd(n,e){let{node:t,offset:r}=n.docView.domFromPos(e,0),i=r<t.childNodes.length?t.childNodes[r]:null,o=r?t.childNodes[r-1]:null;if(we&&i&&i.contentEditable=="false")return Ra(i);if((!i||i.contentEditable=="false")&&(!o||o.contentEditable=="false")){if(i)return Ra(i);if(o)return Ra(o)}}function Ra(n){return n.contentEditable="true",we&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function zd(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Yb(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),r=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!gp(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Qb(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,r=t.nodeName=="IMG";r?e.collapse(t.parentNode,pe(t)+1):e.collapse(t,0),!r&&!n.state.selection.visible&&Re&&qt<=11&&(t.disabled=!0,t.disabled=!1)}function yp(n,e){if(e instanceof B){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Fd(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Fd(n)}function Fd(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function tc(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||j.between(e,t,r)}function _d(n){return n.editable&&!n.hasFocus()?!1:xp(n)}function xp(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Xb(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return On(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ha(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&W.findFrom(o,e)}function jt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Vd(n,e,t){let r=n.state.selection;if(r instanceof j)if(t.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=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return jt(n,new j(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ha(n.state,e);return i&&i instanceof B?jt(n,i):!1}else if(!(qe&&t.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 l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?B.isSelectable(o)?jt(n,new B(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Ai?jt(n,new j(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof B&&r.node.isInline)return jt(n,new j(e>0?r.$to:r.$from));{let i=Ha(n.state,e);return i?jt(n,i):!1}}}function rs(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Mi(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function dr(n,e){return e<0?Zb(n):ew(n)}function Zb(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Ue&&t.nodeType==1&&r<rs(t)&&Mi(t.childNodes[r],-1)&&(s=!0);;)if(r>0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Mi(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(kp(t))break;{let l=t.previousSibling;for(;l&&Mi(l,-1);)i=t.parentNode,o=pe(l),l=l.previousSibling;if(l)t=l,r=rs(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?qa(n,t,r):i&&qa(n,i,o)}function ew(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=rs(t),o,s;for(;;)if(r<i){if(t.nodeType!=1)break;let l=t.childNodes[r];if(Mi(l,1))o=t,s=++r;else break}else{if(kp(t))break;{let l=t.nextSibling;for(;l&&Mi(l,1);)o=l.parentNode,s=pe(l)+1,l=l.nextSibling;if(l)t=l,r=0,i=rs(t);else{if(t=t.parentNode,t==n.dom)break;r=i=0}}}o&&qa(n,o,s)}function kp(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function tw(n,e){for(;n&&e==n.childNodes.length&&!Ei(n);)e=pe(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function nw(n,e){for(;n&&!e&&!Ei(n);)e=pe(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function qa(n,e,t){if(e.nodeType!=3){let o,s;(s=tw(e,t))?(e=s,t=0):(o=nw(e,t))&&(e=o,t=o.nodeValue.length)}let r=n.domSelection();if(!r)return;if(us(r)){let o=document.createRange();o.setEnd(e,t),o.setStart(e,t),r.removeAllRanges(),r.addRange(o)}else r.extend&&r.extend(e,t);n.domObserver.setCurSelection();let{state:i}=n;setTimeout(()=>{n.state==i&&It(n)},50)}function $d(n,e){let t=n.state.doc.resolve(e);if(!(me||sp)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.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<t.end()){let o=n.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(n.dom).direction=="rtl"?"rtl":"ltr"}function Wd(n,e,t){let r=n.state.selection;if(r instanceof j&&!r.empty||t.indexOf("s")>-1||qe&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ha(n.state,e);if(s&&s instanceof B)return jt(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Fe?W.near(s,e):W.findFrom(s,e);return l?jt(n,l):!1}return!1}function jd(n,e){if(!(n.state.selection instanceof j))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function Hd(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function rw(n){if(!we||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;Hd(n,r,"true"),setTimeout(()=>Hd(n,r,"false"),20)}return!1}function iw(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function ow(n,e){let t=e.keyCode,r=iw(e);if(t==8||qe&&t==72&&r=="c")return jd(n,-1)||dr(n,-1);if(t==46&&!e.shiftKey||qe&&t==68&&r=="c")return jd(n,1)||dr(n,1);if(t==13||t==27)return!0;if(t==37||qe&&t==66&&r=="c"){let i=t==37?$d(n,n.state.selection.from)=="ltr"?-1:1:-1;return Vd(n,i,r)||dr(n,i)}else if(t==39||qe&&t==70&&r=="c"){let i=t==39?$d(n,n.state.selection.from)=="ltr"?1:-1:1;return Vd(n,i,r)||dr(n,i)}else{if(t==38||qe&&t==80&&r=="c")return Wd(n,-1,r)||dr(n,-1);if(t==40||qe&&t==78&&r=="c")return rw(n)||Wd(n,1,r)||dr(n,1);if(r==(qe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function nc(n,e){n.someProp("transformCopied",h=>{e=h(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let h=r.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let s=n.someProp("clipboardSerializer")||sn.fromSchema(n.state.schema),l=Np(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let c=a.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Mp[c.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let p=l.createElement(u[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),f++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,` 42 42 43 43 `);return{dom:a,text:d,slice:e}}function bp(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=!!e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return l=new O(M.from(n.state.schema.text(e.replace(/\r\n?/g,` 44 - `))),0,0),n.someProp("transformPasted",d=>{l=d(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:h}=n.state,p=sn.fromSchema(h);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let k=s.appendChild(document.createElement("p"));m&&k.appendChild(p.serializeNode(h.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=cw(t),Ai&&uw(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(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||on.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!sw.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)l=fw(qd(l,+u[1],+u[2]),u[4]);else if(l=O.maxOpen(lw(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let h=l.content.firstChild;f<l.openStart&&!h.type.spec.isolating;f++,h=h.firstChild);for(let h=l.content.lastChild;d<l.openEnd&&!h.type.spec.isolating;d++,h=h.lastChild);l=qd(l,f,d)}return n.someProp("transformPasted",f=>{l=f(l,n,a)}),l}var sw=/^(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 lw(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),c;if(!a)return s=null;if(c=s.length&&o.length&&Sp(a,o,l,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Cp(s[s.length-1],o.length));let u=wp(l,a);s.push(u),i=i.matchType(u.type),o=a}}),s)return M.from(s)}return n}function wp(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,M.from(n));return n}function Sp(n,e,t,r,i){if(i<n.length&&i<e.length&&n[i]==e[i]){let o=Sp(n,e,t,r.lastChild,i+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(i==n.length-1?t.type:n[i+1]))return r.copy(r.content.append(M.from(wp(t,n,i+1))))}}function Cp(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Cp(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(M.empty,!0);return n.copy(t.append(r))}function Ka(n,e,t,r,i,o){let s=e<0?n.firstChild:n.lastChild,l=s.content;return n.childCount>1&&(o=0),i<r-1&&(l=Ka(l,e,t,r,i+1,o)),i>=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(M.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function qd(n,e,t){return e<n.openStart&&(n=new O(Ka(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new O(Ka(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}var Mp={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},Kd=null;function Np(){return Kd||(Kd=document.implementation.createHTMLDocument("title"))}var va=null;function aw(n){let e=window.trustedTypes;return e?(va||(va=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),va.createHTML(n)):n}function cw(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Np().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Mp[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"</"+o+">").reverse().join("")),t.innerHTML=aw(n),i)for(let o=0;o<i.length;o++)t=t.querySelector(i[o])||t;return t}function uw(n){let e=n.querySelectorAll(me?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let r=e[t];r.childNodes.length==1&&r.textContent=="\xA0"&&r.parentNode&&r.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),r)}}function fw(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return n}let{content:i,openStart:o,openEnd:s}=n;for(let l=r.length-2;l>=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=M.from(a.create(r[l+1],i)),o++,s++}return new O(i,o,s)}var Te={},Oe={},hw={touchstart:!0,touchmove:!0},Ua=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 dw(n){for(let e in Te){let t=Te[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{mw(n,r)&&!rc(n,r)&&(n.editable||!(r.type in Oe))&&t(n,r)},hw[e]?{passive:!0}:void 0)}we&&n.dom.addEventListener("input",()=>null),Ja(n)}function Ht(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function pw(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Ja(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>rc(n,r))})}function rc(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function mw(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function gw(n,e){!rc(n,e)&&Te[e.type]&&(n.editable||!(e.type in Oe))&&Te[e.type](n,e)}Oe.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Tp(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Nt&&me&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),yr&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||ow(n,t)?t.preventDefault():Ht(n,"key")};Oe.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Oe.keypress=(n,e)=>{let t=e;if(Tp(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||qe&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof j)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),o=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i,o))&&n.dispatch(o()),t.preventDefault()}};function fs(n){return{left:n.clientX,top:n.clientY}}function yw(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function ic(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function mr(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function xw(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&B.isSelectable(r)?(mr(n,new B(t),"pointer"),!0):!1}function kw(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof B&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(B.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(mr(n,B.create(n.state.doc,i),"pointer"),!0):!1}function bw(n,e,t,r,i){return ic(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?kw(n,t):xw(n,t))}function ww(n,e,t,r){return ic(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Sw(n,e,t,r){return ic(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Cw(n,t,r)}function Cw(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(mr(n,j.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)mr(n,j.create(r,l+1,l+1+s.content.size),"pointer");else if(B.isSelectable(s))mr(n,B.create(r,l),"pointer");else continue;return!0}}function oc(n){return is(n)}var Ip=qe?"metaKey":"ctrlKey";Te.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=oc(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&yw(t,n.input.lastClick)&&!t[Ip]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o,button:t.button};let s=n.posAtCoords(fs(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Ga(n,s,t,!!r)):(o=="doubleClick"?ww:Sw)(n,s.pos,s.inside,t)?t.preventDefault():Ht(n,"pointer"))};var Ga=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Ip],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let u=e.state.doc.resolve(t.pos);o=u.parent,s=u.depth?u.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof B&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ue&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Ht(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>It(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fs(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ht(this.view,"pointer"):bw(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||we&&this.mightDrag&&!this.mightDrag.node.isAtom||me&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(mr(this.view,W.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Ht(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ht(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};Te.touchstart=n=>{n.input.lastTouch=Date.now(),oc(n),Ht(n,"pointer")};Te.touchmove=n=>{n.input.lastTouch=Date.now(),Ht(n,"pointer")};Te.contextmenu=n=>oc(n);function Tp(n,e){return n.composing?!0:we&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var Mw=Nt?5e3:-1;Oe.compositionstart=Oe.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof j&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||me&&sp&&Nw(n)))n.markCursor=n.state.storedMarks||t.marks(),is(n,!0),n.markCursor=null;else if(is(n,!e.selection.empty),Ue&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.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 l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Op(n,Mw)};function Nw(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let r=e.childNodes[t];return r.nodeType==1&&r.contentEditable=="false"}Oe.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Op(n,20))};function Op(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>is(n),e))}function Ep(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Tw());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Iw(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Cb(e.focusNode,e.focusOffset),r=Mb(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function Tw(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function is(n,e=!1){if(!(Nt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ep(n),e||n.docView&&n.docView.dirty){let t=ec(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function Ow(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Ni=Re&&qt<15||yr&&Ob<604;Te.copy=Oe.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Ni?null:t.clipboardData,s=r.content(),{dom:l,text:a}=nc(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):Ow(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Ew(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function Aw(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Ii(n,r.value,null,i,e):Ii(n,r.textContent,r.innerHTML,i,e)},50)}function Ii(n,e,t,r,i){let o=bp(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||O.empty)))return!0;if(!o)return!1;let s=Ew(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Ap(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Oe.paste=(n,e)=>{let t=e;if(n.composing&&!Nt)return;let r=Ni?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Ii(n,Ap(r),r.getData("text/html"),i,t)?t.preventDefault():Aw(n,t)};var ss=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Rw=qe?"altKey":"ctrlKey";function Rp(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[Rw]}Te.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(fs(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof B?i.to-1:i.to))){if(r&&r.mightDrag)s=B.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=B.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:c,slice:u}=nc(n,l);(!t.dataTransfer.files.length||!me||op>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Ni?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Ni||t.dataTransfer.setData("text/plain",c),n.dragging=new ss(u,Rp(n,t),s)};Te.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Oe.dragover=Oe.dragenter=(n,e)=>e.preventDefault();Oe.drop=(n,e)=>{try{vw(n,e,n.dragging)}finally{n.dragging=null}};function vw(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(fs(e));if(!r)return;let i=n.state.doc.resolve(r.pos),o=t&&t.slice;o?n.someProp("transformPasted",h=>{o=h(o,n,!1)}):o=bp(n,Ap(e.dataTransfer),Ni?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(t&&Rp(n,e));if(n.someProp("handleDrop",h=>h(n,e,o||O.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let l=o?mf(n.state.doc,i.pos,o):i.pos;l==null&&(l=i.pos);let a=n.state.tr;if(s){let{node:h}=t;h?h.replace(a):a.deleteSelection()}let c=a.mapping.map(l),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(u?a.replaceRangeWith(c,c,o.content.firstChild):a.replaceRange(c,c,o),a.doc.eq(f))return;let d=a.doc.resolve(c);if(u&&B.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new B(d));else{let h=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,k,x)=>h=x),a.setSelection(tc(n,d,a.doc.resolve(h)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Te.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&It(n)},20))};Te.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Te.beforeinput=(n,e)=>{if(me&&Nt&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,Sn(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Oe)Te[n]=Oe[n];function Ti(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var ls=class n{constructor(e,t){this.toDOM=e,this.spec=t||In,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new nt(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Ti(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Nn=class n{constructor(e,t){this.attrs=e,this.spec=t||In}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new nt(o,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof n&&Ti(this.attrs,e.attrs)&&Ti(this.spec,e.spec)}static is(e){return e.type instanceof n}destroy(){}},Ya=class n{constructor(e,t){this.attrs=e,this.spec=t||In}map(e,t,r,i){let o=e.mapResult(t.from+i,1);if(o.deleted)return null;let s=e.mapResult(t.to+i,-1);return s.deleted||s.pos<=o.pos?null:new nt(o.pos-r,s.pos-r,this)}valid(e,t){let{index:r,offset:i}=e.content.findIndex(t.from),o;return i==t.from&&!(o=e.child(r)).isText&&i+o.nodeSize==t.to}eq(e){return this==e||e instanceof n&&Ti(this.attrs,e.attrs)&&Ti(this.spec,e.spec)}destroy(){}},nt=class n{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new n(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,r){return this.type.map(e,this,t,r)}static widget(e,t,r){return new n(e,e,new ls(t,r))}static inline(e,t,r,i){return new n(e,t,new Nn(r,i))}static node(e,t,r,i){return new n(e,t,new Ya(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Nn}get widget(){return this.type instanceof ls}},pr=[],In={},Ie=class n{constructor(e,t){this.local=e.length?e:pr,this.children=t.length?t:pr}static create(e,t){return t.length?cs(t,e,0,In):be}find(e,t,r){let i=[];return this.findInner(e??0,t??1e9,i,0,r),i}findInner(e,t,r,i,o){for(let s=0;s<this.local.length;s++){let l=this.local[s];l.from<=t&&l.to>=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==be||e.maps.length==0?this:this.mapInner(e,t,0,0,r||In)}mapInner(e,t,r,i,o){let s;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,r,i);a&&a.type.valid(t,a)?(s||(s=[])).push(a):o.onRemove&&o.onRemove(this.local[l].spec)}return this.children.length?Dw(this.children,s||[],e,t,r,i,o):s?new n(s.sort(Tn),pr):be}add(e,t){return t.length?this==be?n.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let i,o=0;e.forEach((l,a)=>{let c=a+r,u;if(u=Dp(t,l,c)){for(i||(i=this.children.slice());o<i.length&&i[o]<a;)o+=3;i[o]==a?i[o+2]=i[o+2].addInner(l,u,c+1):i.splice(o,0,a,a+l.nodeSize,cs(u,l,c+1,In)),o+=3}});let s=vp(o?Pp(t):t,-r);for(let l=0;l<s.length;l++)s[l].type.valid(e,s[l])||s.splice(l--,1);return new n(s.length?this.local.concat(s).sort(Tn):this.local,i||this.children)}remove(e){return e.length==0||this==be?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,i=this.local;for(let o=0;o<r.length;o+=3){let s,l=r[o]+t,a=r[o+1]+t;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>l&&f.to<a&&(e[u]=null,(s||(s=[])).push(f));if(!s)continue;r==this.children&&(r=this.children.slice());let c=r[o+2].removeInner(s,l+1);c!=be?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 l=0;l<i.length;l++)i[l].eq(s,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new n(i,r):be}forChild(e,t){if(this==be)return this;if(t.isLeaf)return n.empty;let r,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<s&&a.to>o&&a.type instanceof Nn){let c=Math.max(o,a.from)-o,u=Math.min(s,a.to)-o;c<u&&(i||(i=[])).push(a.copy(c,u))}}if(i){let l=new n(i.sort(Tn),pr);return r?new as([l,r]):l}return r||be}eq(e){if(this==e)return!0;if(!(e instanceof n)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return sc(this.localsInner(e))}localsInner(e){if(this==be)return pr;if(e.inlineContent||!this.local.some(Nn.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Nn||t.push(this.local[r]);return t}forEachSet(e){e(this)}};Ie.empty=new Ie([],[]);Ie.removeOverlap=sc;var be=Ie.empty,as=class n{constructor(e){this.members=e}map(e,t){let r=this.members.map(i=>i.map(e,t,In));return n.from(r)}forChild(e,t){if(t.isLeaf)return Ie.empty;let r=[];for(let i=0;i<this.members.length;i++){let o=this.members[i].forChild(e,t);o!=be&&(o instanceof n?r=r.concat(o.members):r.push(o))}return n.from(r)}eq(e){if(!(e instanceof n)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,r=!0;for(let i=0;i<this.members.length;i++){let o=this.members[i].localsInner(e);if(o.length)if(!t)t=o;else{r&&(t=t.slice(),r=!1);for(let s=0;s<o.length;s++)t.push(o[s])}}return t?sc(r?t:t.sort(Tn)):pr}static from(e){switch(e.length){case 0:return be;case 1:return e[0];default:return new n(e.every(t=>t instanceof Ie)?e:e.reduce((t,r)=>t.concat(r instanceof Ie?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Dw(n,e,t,r,i,o,s){let l=n.slice();for(let c=0,u=o;c<t.maps.length;c++){let f=0;t.maps[c].forEach((d,h,p,m)=>{let k=m-p-(h-d);for(let x=0;x<l.length;x+=3){let I=l[x+1];if(I<0||d>I+u-f)continue;let C=l[x]+u-f;h>=C?l[x+1]=d<=C?-2:-1:d>=u&&k&&(l[x]+=k,l[x+1]+=k)}f+=k}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let u=t.map(n[c]+o),f=u-i;if(f<0||f>=r.content.size){a=!0;continue}let d=t.map(n[c+1]+o,-1),h=d-i,{index:p,offset:m}=r.content.findIndex(f),k=r.maybeChild(p);if(k&&m==f&&m+k.nodeSize==h){let x=l[c+2].mapInner(t,k,u+1,n[c]+o+1,s);x!=be?(l[c]=f,l[c+1]=h,l[c+2]=x):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Pw(l,n,e,t,i,o,s),u=cs(c,r,0,s);e=u.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,d=0;f<u.children.length;f+=3){let h=u.children[f];for(;d<l.length&&l[d]<h;)d+=3;l.splice(d,0,u.children[f],u.children[f+1],u.children[f+2])}}return new Ie(e.sort(Tn),l)}function vp(n,e){if(!e||!n.length)return n;let t=[];for(let r=0;r<n.length;r++){let i=n[r];t.push(new nt(i.from+e,i.to+e,i.type))}return t}function Pw(n,e,t,r,i,o,s){function l(a,c){for(let u=0;u<a.local.length;u++){let f=a.local[u].map(r,i,c);f?t.push(f):s.onRemove&&s.onRemove(a.local[u].spec)}for(let u=0;u<a.children.length;u+=3)l(a.children[u+2],a.children[u]+c+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+o+1);return t}function Dp(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,i=null;for(let o=0,s;o<n.length;o++)(s=n[o])&&s.from>t&&s.to<r&&((i||(i=[])).push(s),n[o]=null);return i}function Pp(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function cs(n,e,t,r){let i=[],o=!1;e.forEach((l,a)=>{let c=Dp(n,l,a+t);if(c){o=!0;let u=cs(c,l,t+a+1,r);u!=be&&i.push(a,a+l.nodeSize,u)}});let s=vp(o?Pp(n):n,-t).sort(Tn);for(let l=0;l<s.length;l++)s[l].type.valid(e,s[l])||(r.onRemove&&r.onRemove(s[l].spec),s.splice(l--,1));return s.length||i.length?new Ie(s,i):be}function Tn(n,e){return n.from-e.from||n.to-e.to}function sc(n){let e=n;for(let t=0;t<e.length-1;t++){let r=e[t];if(r.from!=r.to)for(let i=t+1;i<e.length;i++){let o=e[i];if(o.from==r.from){o.to!=r.to&&(e==n&&(e=n.slice()),e[i]=o.copy(o.from,r.to),Ud(e,i+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,o.from),Ud(e,i,r.copy(o.from,r.to)));break}}}return e}function Ud(n,e,t){for(;e<n.length&&Tn(t,n[e])>0;)e++;n.splice(e,0,t)}function Da(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=be&&e.push(r)}),n.cursorWrapper&&e.push(Ie.create(n.state.doc,[n.cursorWrapper.deco])),as.from(e)}var Lw={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Bw=Re&&qt<=11,Qa=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}},Xa=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Qa,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]);Re&&qt<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():we&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Bw&&(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,Lw)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(_d(this.view)){if(this.suppressingSelectionUpdates)return It(this.view);if(Re&&qt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&On(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let o=e.focusNode;o;o=gr(o))t.add(o);for(let o=e.anchorNode;o;o=gr(o))if(t.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 t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&_d(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let u=0;u<t.length;u++){let f=this.registerMutation(t[u],a);f&&(o=o<0?f.from:Math.min(f.from,o),s=s<0?f.to:Math.max(f.to,s),f.typeOver&&(l=!0))}if(a.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of a)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(Ue&&a.length){let u=a.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 h=d.parentNode;h&&h.nodeName=="LI"&&(!f||_w(e,f)!=h)&&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&&us(r)&&(c=ec(e))&&c.eq(W.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,It(e),this.currentSelection.set(r),e.scrollToSelection()):(o>-1||i)&&(o>-1&&(e.docView.markDirty(o,s),zw(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Vw(e,a)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||It(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.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];t.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(Re&&qt<=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?pe(i)+1:0,l=r.localPosFromDOM(e.target,s,-1),a=o&&o.parentNode==e.target?pe(o):e.target.childNodes.length,c=r.localPosFromDOM(e.target,a,1);return{from:l,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})}},Jd=new WeakMap,Gd=!1;function zw(n){if(!Jd.has(n)&&(Jd.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Ue,Gd)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."),Gd=!0}}function Yd(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,o=e.endOffset,s=n.domAtPos(n.state.selection.anchor);return On(s.node,s.offset,i,o)&&([t,r,i,o]=[i,o,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:o}}function Fw(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Yd(n,i)}let t;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",r,!0),t?Yd(n,t):null}function _w(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let r=n.docView.nearestDesc(t,!0);if(r&&r.node.isBlock)return t}return null}function Vw(n,e){var t;let{focusNode:r,focusOffset:i}=n.domSelectionRange();for(let o of e)if(((t=o.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let s=o.nextSibling;for(;s&&s.nodeName!="TD"&&s.nodeName!="TH";)s=s.nextSibling;if(s){let l=s;for(;;){let a=l.firstChild;if(!a||a.nodeType!=1||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(o,l.firstChild),r==o&&n.domSelection().collapse(o,i)}else o.parentNode.removeChild(o)}}function $w(n,e,t){let{node:r,fromOffset:i,toOffset:o,from:s,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),c,u=a.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:a.anchorOffset}],us(a)||c.push({node:a.focusNode,offset:a.focusOffset})),me&&n.input.lastKeyCode===8)for(let k=o;k>i;k--){let x=r.childNodes[k-1],I=x.pmViewDesc;if(x.nodeName=="BR"&&!I){o=k;break}if(!I||I.size)break}let f=n.state.doc,d=n.someProp("domParser")||on.fromSchema(n.state.schema),h=f.resolve(s),p=null,m=d.parse(r,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:o,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Ww,context:h});if(c&&c[0].pos!=null){let k=c[0].pos,x=c[1]&&c[1].pos;x==null&&(x=k),p={anchor:k+s,head:x+s}}return{doc:m,sel:p,from:s,to:l}}function Ww(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(we&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||we&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var jw=/^(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 Hw(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,P=ec(n,T);if(P&&!n.state.selection.eq(P)){if(me&&Nt&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",U=>U(n,Sn(13,"Enter"))))return;let D=n.state.tr.setSelection(P);T=="pointer"?D.setMeta("pointer",!0):T=="key"&&D.scrollIntoView(),o&&D.setMeta("composition",o),n.dispatch(D)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=$w(n,e,t),u=n.state.doc,f=u.slice(c.from,c.to),d,h;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(d=n.state.selection.to,h="end"):(d=n.state.selection.from,h="start"),n.input.lastKeyCode=null;let p=Uw(f.content,c.doc.content,c.from,d,h);if(p&&n.input.domChangeCount++,(yr&&n.input.lastIOSEnter>Date.now()-225||Nt)&&i.some(T=>T.nodeType==1&&!jw.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,Sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&a instanceof j&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let T=Qd(n,n.state.doc,c.sel);if(T&&!T.eq(n.state.selection)){let P=n.state.tr.setSelection(T);o&&P.setMeta("composition",o),n.dispatch(P)}}return}n.state.selection.from<n.state.selection.to&&p.start==p.endB&&n.state.selection instanceof j&&(p.start>n.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?p.start=n.state.selection.from:p.endA<n.state.selection.to&&p.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),Re&&qt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),k=c.doc.resolveNoCache(p.endB-c.from),x=u.resolve(p.start),I=m.sameParent(k)&&m.parent.inlineContent&&x.end()>=p.endA;if((yr&&n.input.lastIOSEnter>Date.now()-225&&(!I||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!I&&m.pos<c.doc.content.size&&(!m.sameParent(k)||!m.parent.inlineContent)&&m.pos<k.pos&&!/\S/.test(c.doc.textBetween(m.pos,k.pos,"","")))&&n.someProp("handleKeyDown",T=>T(n,Sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Kw(u,p.start,p.endA,m,k)&&n.someProp("handleKeyDown",T=>T(n,Sn(8,"Backspace")))){Nt&&me&&n.domObserver.suppressSelectionUpdates();return}me&&p.endB==p.start&&(n.input.lastChromeDelete=Date.now()),Nt&&!I&&m.start()!=k.start()&&k.parentOffset==0&&m.depth==k.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,k=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,Sn(13,"Enter"))})},20));let C=p.start,A=p.endA,v=T=>{let P=T||n.state.tr.replace(C,A,c.doc.slice(p.start-c.from,p.endB-c.from));if(c.sel){let D=Qd(n,P.doc,c.sel);D&&!(me&&n.composing&&D.empty&&(p.start!=p.endB||n.input.lastChromeDelete<Date.now()-100)&&(D.head==C||D.head==P.mapping.map(A)-1)||Re&&D.empty&&D.head==C)&&P.setSelection(D)}return o&&P.setMeta("composition",o),P.scrollIntoView()},b;if(I)if(m.pos==k.pos){Re&&qt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>It(n),20));let T=v(n.state.tr.delete(C,A)),P=u.resolve(p.start).marksAcross(u.resolve(p.endA));P&&T.ensureMarks(P),n.dispatch(T)}else if(p.endA==p.endB&&(b=qw(m.parent.content.cut(m.parentOffset,k.parentOffset),x.parent.content.cut(x.parentOffset,p.endA-x.start())))){let T=v(n.state.tr);b.type=="add"?T.addMark(C,A,b.mark):T.removeMark(C,A,b.mark),n.dispatch(T)}else if(m.parent.child(m.index()).isText&&m.index()==k.index()-(k.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,k.parentOffset),P=()=>v(n.state.tr.insertText(T,C,A));n.someProp("handleTextInput",D=>D(n,C,A,T,P))||n.dispatch(P())}else n.dispatch(v());else n.dispatch(v())}function Qd(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:tc(n,e.resolve(t.anchor),e.resolve(t.head))}function qw(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let u=0;u<r.length;u++)i=r[u].removeFromSet(i);for(let u=0;u<t.length;u++)o=t[u].removeFromSet(o);if(i.length==1&&o.length==0)l=i[0],s="add",a=u=>u.mark(l.addToSet(u.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(a(e.child(u)));if(M.from(c).eq(n))return{mark:l,type:s}}function Kw(n,e,t,r,i){if(t-e<=i.pos-r.pos||Pa(r,!0,!1)<i.pos)return!1;let o=n.resolve(e);if(!r.parent.isTextblock){let l=o.nodeAfter;return l!=null&&t==e+l.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=n.resolve(Pa(o,!0,!0));return!s.parent.isTextblock||s.pos>t||Pa(s,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(s.parent.content)}function Pa(n,e,t){let r=n.depth,i=e?n.end():n.pos;for(;r>0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Uw(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s<o&&n.size<e.size){let a=r<=o&&r>=s?o-r:0;o-=a,o&&o<e.size&&Xd(e.textBetween(o-1,o+1))&&(o+=a?1:-1),l=o+(l-s),s=o}else if(l<o){let a=r<=o&&r>=l?o-r:0;o-=a,o&&o<n.size&&Xd(n.textBetween(o-1,o+1))&&(o+=a?1:-1),s=o+(s-l),l=o}return{start:o,endA:s,endB:l}}function Xd(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}var Oi=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Ua,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(rp),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=tp(this),ep(this),this.nodeViews=np(this),this.docView=Dd(this.state.doc,Zd(this),Da(this),this.dom,this),this.domObserver=new Xa(this,(r,i,o,s)=>Hw(this,r,i,o,s)),this.domObserver.start(),dw(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Ja(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(rp),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Ep(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let h=np(this);Gw(h,this.nodeViews)&&(this.nodeViews=h,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Ja(this),this.editable=tp(this),ep(this);let a=Da(this),c=Zd(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,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&Rb(this);if(s){this.domObserver.stop();let h=f&&(Re||me)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Jw(i.selection,e.selection);if(f){let p=me?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Iw(this)),(o||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Dd(e.doc,c,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Xb(this))?It(this,h):(yp(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&&vb(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof B){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Td(this,t.getBoundingClientRect(),e)}else Td(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 t=0;t<this.directPlugins.length;t++){let r=this.directPlugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let r=this.state.plugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let r=this.pluginViews[t];r.update&&r.update(this,e)}}updateDraggedNode(e,t){let r=e.node,i=-1;if(this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let o=r.from+(this.state.doc.content.size-t.doc.content.size);(o>0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ss(e.slice,e.move,i<0?void 0:B.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;s<this.directPlugins.length;s++){let l=this.directPlugins[s].props[e];if(l!=null&&(i=t?t(l):l))return i}let o=this.state.plugins;if(o)for(let s=0;s<o.length;s++){let l=o[s].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(Re){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&&Db(this.dom),It(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Fb(this,e)}coordsAtPos(e,t=1){return fp(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return jb(this,t||this.state,e)}pasteHTML(e,t){return Ii(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Ii(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return nc(this,e)}destroy(){this.docView&&(pw(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Da(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,wb())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return gw(this,e)}domSelectionRange(){let e=this.domSelection();return e?we&&this.root.nodeType===11&&Ib(this.dom.ownerDocument)==this.dom&&Fw(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Oi.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Zd(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[nt.node(0,n.state.doc.content.size,e)]}function ep(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:nt.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function tp(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Jw(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function np(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Gw(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function rp(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function Et(n,e){return n.meta={package:"@milkdown/core",group:"System",...e},n}var zp={text:(n,e,t,r)=>{let i=n.value;return/^[^*_\\]*\s+$/.test(i)?i:t.safe(i,{...r,encode:[]})},strong:(n,e,t,r)=>{let i=n.marker||t.options.strong||"*",o=t.enter("strong"),s=t.createTracker(r),l=s.move(i+i);return l+=s.move(t.containerPhrasing(n,{before:l,after:i,...s.current()})),l+=s.move(i+i),o(),l},emphasis:(n,e,t,r)=>{let i=n.marker||t.options.emphasis||"*",o=t.enter("emphasis"),s=t.createTracker(r),l=s.move(i);return l+=s.move(t.containerPhrasing(n,{before:l,after:i,...s.current()})),l+=s.move(i),o(),l}},rt=$({},"editorView"),Ri=$({},"editorState"),lc=$([],"initTimer"),Lp=$({},"editor"),Nr=$([],"inputRules"),ct=$([],"prosePlugins"),Ir=$([],"remarkPlugins"),Ns=$([],"nodeView"),Is=$([],"markView"),An=$(di().use(ir).use(cr),"remark"),kr=$({handlers:zp,encode:[]},"remarkStringifyOptions"),hs=He("ConfigReady");function Yw(n){let e=t=>(t.record(hs),async()=>(await n(t),t.done(hs),()=>{t.clearTimer(hs)}));return Et(e,{displayName:"Config"}),e}var Tt=He("InitReady");function Qw(n){let e=t=>(t.inject(Lp,n).inject(ct,[]).inject(Ir,[]).inject(Nr,[]).inject(Ns,[]).inject(Is,[]).inject(kr,{handlers:zp,encode:[]}).inject(An,di().use(ir).use(cr)).inject(lc,[hs]).record(Tt),async()=>{await t.waitTimers(lc);let r=t.get(kr);return t.set(An,di().use(ir).use(cr,r)),t.done(Tt),()=>{t.remove(Lp).remove(ct).remove(Ir).remove(Nr).remove(Ns).remove(Is).remove(kr).remove(An).remove(lc).clearTimer(Tt)}});return Et(e,{displayName:"Init"}),e}var ve=He("SchemaReady"),ds=$([],"schemaTimer"),Ot=$({},"schema"),br=$([],"nodes"),wr=$([],"marks");function Bp(n){return{...n,parseDOM:n.parseDOM?.map(e=>({priority:n.priority,...e}))}}var Fp=n=>(n.inject(Ot,{}).inject(br,[]).inject(wr,[]).inject(ds,[Tt]).record(ve),async()=>{await n.waitTimers(ds);let e=n.get(An),r=n.get(Ir).reduce((l,a)=>l.use(a.plugin,a.options),e);n.set(An,r);let i=Object.fromEntries(n.get(br).map(([l,a])=>[l,Bp(a)])),o=Object.fromEntries(n.get(wr).map(([l,a])=>[l,Bp(a)])),s=new so({nodes:i,marks:o});return n.set(Ot,s),n.done(ve),()=>{n.remove(Ot).remove(br).remove(wr).remove(ds).clearTimer(ve)}});Et(Fp,{displayName:"Schema"});var Ts=class{constructor(){this.#t=new jr,this.#e=null,this.setCtx=e=>{this.#e=e},this.chain=()=>{if(this.#e==null)throw Qi();let e=this.#e,t=[],r=this.get.bind(this),i={run:()=>{let s=dn(...t),l=e.get(rt);return s(l.state,l.dispatch,l)},inline:s=>(t.push(s),i),pipe:o.bind(this)};function o(s,l){let a=r(s);return t.push(a(l)),i}return i}}#t;#e;get ctx(){return this.#e}create(e,t){let r=e.create(this.#t.sliceMap);return r.set(t),r}get(e){return this.#t.get(e).get()}remove(e){return this.#t.remove(e)}call(e,t){if(this.#e==null)throw Qi();let i=this.get(e)(t),o=this.#e.get(rt);return i(o.state,o.dispatch,o)}inline(e){if(this.#e==null)throw Qi();let t=this.#e.get(rt);return e(t.state,t.dispatch,t)}};function _p(n="cmdKey"){return $((()=>()=>!1),n)}var G=$(new Ts,"commands"),ps=$([ve],"commandsTimer"),Sr=He("CommandsReady"),Vp=n=>{let e=new Ts;return e.setCtx(n),n.inject(G,e).inject(ps,[ve]).record(Sr),async()=>(await n.waitTimers(ps),n.done(Sr),()=>{n.remove(G).remove(ps).clearTimer(Sr)})};Et(Vp,{displayName:"Commands"});function Xw(n){let e=dn(hd,go,Af,vl);return n.Backspace=e,n}var Os=class{constructor(){this.#t=null,this.#e=[],this.setCtx=e=>{this.#t=e},this.add=e=>(this.#e.push(e),()=>{this.#e=this.#e.filter(t=>t!==e)}),this.addObjectKeymap=e=>{let t=[];return Object.entries(e).forEach(([r,i])=>{if(typeof i=="function"){let o={key:r,onRun:()=>i};this.#e.push(o),t.push(()=>{this.#e=this.#e.filter(s=>s!==o)})}else this.#e.push(i),t.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}),()=>{t.forEach(r=>r())}},this.addBaseKeymap=()=>{let e=Xw(Lf);return this.addObjectKeymap(e)},this.build=()=>{let e={};return this.#e.forEach(r=>{e[r.key]=[...e[r.key]||[],r]}),Object.fromEntries(Object.entries(e).map(([r,i])=>{let o=i.sort((l,a)=>(a.priority??50)-(l.priority??50));return[r,(l,a,c)=>{let u=this.#t;if(u==null)throw Kn();let f=o.map(h=>h.onRun(u));return dn(...f)(l,a,c)}]}))}}#t;#e;get ctx(){return this.#t}},Pi=$(new Os,"keymap"),ac=$([ve],"keymapTimer"),Cr=He("KeymapReady"),Zw=n=>{let e=new Os;return e.setCtx(n),n.inject(Pi,e).inject(ac,[ve]).record(Cr),async()=>(await n.waitTimers(ac),n.done(Cr),()=>{n.remove(Pi).remove(ac).clearTimer(Cr)})},ms=He("ParserReady"),$p=(()=>{throw Kn()}),vi=$($p,"parser"),cc=$([],"parserTimer"),Wp=n=>(n.inject(vi,$p).inject(cc,[ve]).record(ms),async()=>{await n.waitTimers(cc);let e=n.get(An),t=n.get(Ot);return n.set(vi,ud.create(t,e)),n.done(ms),()=>{n.remove(vi).remove(cc).clearTimer(ms)}});Et(Wp,{displayName:"Parser"});var Mr=He("SerializerReady"),uc=$([],"serializerTimer"),jp=(()=>{throw Kn()}),Rn=$(jp,"serializer"),Hp=n=>(n.inject(Rn,jp).inject(uc,[ve]).record(Mr),async()=>{await n.waitTimers(uc);let e=n.get(An),t=n.get(Ot);return n.set(Rn,fd.create(t,e)),n.done(Mr),()=>{n.remove(Rn).remove(uc).clearTimer(Mr)}});Et(Hp,{displayName:"Serializer"});var gs=$("","defaultValue"),ys=$(n=>n,"stateOptions"),xs=$([],"editorStateTimer"),ks=He("EditorStateReady");function e0(n,e,t){if(typeof n=="string")return e(n);if(n.type==="html")return on.fromSchema(t).parse(n.dom);if(n.type==="json")return Ae.fromJSON(t,n.value);throw Iu(n)}var t0=new re("MILKDOWN_STATE_TRACKER"),qp=n=>(n.inject(gs,"").inject(Ri,{}).inject(ys,e=>e).inject(xs,[ms,Mr,Sr,Cr]).record(ks),async()=>{await n.waitTimers(xs);let e=n.get(Ot),t=n.get(vi),r=n.get(Nr),i=n.get(ys),o=n.get(ct),s=n.get(gs),l=e0(s,t,e),a=n.get(Pi),c=a.addBaseKeymap(),u=[...o,new ne({key:t0,state:{init:()=>{},apply:(h,p,m,k)=>{n.set(Ri,k)}}}),kd({rules:r}),Md(a.build())];n.set(ct,u);let f=i({schema:e,doc:l,plugins:u}),d=mo.create(f);return n.set(Ri,d),n.done(ks),()=>{c(),n.remove(gs).remove(Ri).remove(ys).remove(xs).clearTimer(ks)}});Et(qp,{displayName:"EditorState"});var Es=$([],"pasteRule"),bs=$([ve],"pasteRuleTimer"),ws=He("PasteRuleReady"),Kp=n=>(n.inject(Es,[]).inject(bs,[ve]).record(ws),async()=>(await n.waitTimers(bs),n.done(ws),()=>{n.remove(Es).remove(bs).clearTimer(ws)}));Et(Kp,{displayName:"PasteRule"});var Di=He("EditorViewReady"),Ss=$([],"editorViewTimer"),Cs=$({},"editorViewOptions"),Ms=$(null,"root"),fc=$(null,"rootDOM"),hc=$({},"rootAttrs");function n0(n,e){let t=document.createElement("div");t.className="milkdown",n.appendChild(t),e.set(fc,t);let r=e.get(hc);return Object.entries(r).forEach(([i,o])=>t.setAttribute(i,o)),t}function r0(n){n.classList.add("editor"),n.setAttribute("role","textbox")}var i0=new re("MILKDOWN_VIEW_CLEAR"),Up=n=>(n.inject(Ms,document.body).inject(rt,{}).inject(Cs,{}).inject(fc,null).inject(hc,{}).inject(Ss,[ks,ws]).record(Di),async()=>{await n.wait(Tt);let e=n.get(Ms)||document.body,t=typeof e=="string"?document.querySelector(e):e;n.update(ct,a=>[new ne({key:i0,view:c=>{let u=t?n0(t,n):void 0;return(()=>{if(u&&t){let d=c.dom;t.replaceChild(u,d),u.appendChild(d)}})(),{destroy:()=>{u?.parentNode&&u?.parentNode.replaceChild(c.dom,u),u?.remove()}}}}),...a]),await n.waitTimers(Ss);let r=n.get(Ri),i=n.get(Cs),o=Object.fromEntries(n.get(Ns)),s=Object.fromEntries(n.get(Is)),l=new Oi(t,{state:r,nodeViews:o,markViews:s,transformPasted:(a,c,u)=>(n.get(Es).sort((f,d)=>(d.priority??50)-(f.priority??50)).map(f=>f.run).forEach(f=>{a=f(a,c,u)}),a),...i});return r0(l.dom),n.set(rt,l),n.done(Di),()=>{l?.destroy(),n.remove(Ms).remove(rt).remove(Cs).remove(fc).remove(hc).remove(Ss).clearTimer(Di)}});Et(Up,{displayName:"EditorView"});var dc=class n{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new jr,this.#o=new Zi,this.#i=new Map,this.#l=new Map,this.#a=new Xi(this.#s,this.#o),this.#h=()=>{let e=Yw(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),t=[Fp,Wp,Hp,Vp,Zw,Kp,qp,Up,Qw(this),e];this.#c(t,this.#l)},this.#c=(e,t)=>{e.forEach(r=>{let i=this.#a.produce(this.#t?r.meta:void 0),o=r(i);t.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#u=(e,t=!1)=>Promise.all([e].flat().map(async r=>{let o=this.#i.get(r)?.cleanup;return t?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof o=="function"?o():o})),this.#d=async()=>{await Promise.all([...this.#l.entries()].map(async([e,{cleanup:t}])=>typeof t=="function"?t():t)),this.#l.clear()},this.#f=e=>{this.#e=e,this.#n(e)},this.#p=e=>[...e.entries()].map(async([t,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(t,{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(t=>t!==e),this),this.use=e=>{let t=[e].flat();return t.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(t,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(t=>{setTimeout(()=>{t(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.#h(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#p(this.#l),this.#p(this.#i)].flat()),this.#f("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(t=>{setTimeout(()=>{t(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#f("OnDestroy"),await this.#u([...this.#i.keys()],e),await this.#d(),this.#f("Destroyed"),this),this.action=e=>e(this.#a),this.inspect=()=>this.#t?[...this.#l.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 n}#t;#e;#r;#n;#s;#o;#i;#l;#a;#h;#c;#u;#d;#f;#p;get ctx(){return this.#a}get status(){return this.#e}};var o0=n=>crypto.getRandomValues(new Uint8Array(n)),s0=(n,e,t)=>{let r=(2<<Math.log2(n.length-1))-1,i=-~(1.6*r*e/n.length);return(o=e)=>{let s="";for(;;){let l=t(i),a=i|0;for(;a--;)if(s+=n[l[a]&r]||"",s.length>=o)return s}}},Jp=(n,e=21)=>s0(n,e|0,o0);var KE=Jp("abcedfghicklmn",10);function J(n,e){let t=_p(n),r=i=>async()=>{r.key=t,await i.wait(Sr);let o=e(i);return i.get(G).create(t,o),r.run=s=>i.get(G).call(n,s),()=>{i.get(G).remove(t)}};return r}function Ge(n){let e=t=>async()=>{await t.wait(ve);let r=n(t);return t.update(Nr,i=>[...i,r]),e.inputRule=r,()=>{t.update(Nr,i=>i.filter(o=>o!==r))}};return e}function l0(n,e){let t=r=>async()=>{let i=e(r);return r.update(wr,o=>[...o.filter(s=>s[0]!==n),[n,i]]),t.id=n,t.schema=i,()=>{r.update(wr,o=>o.filter(([s])=>s!==n))}};return t.type=r=>{let i=r.get(Ot).marks[n];if(!i)throw Du(n);return i},t}function As(n,e){let t=r=>async()=>{let i=e(r);return r.update(br,o=>[...o.filter(s=>s[0]!==n),[n,i]]),t.id=n,t.schema=i,()=>{r.update(br,o=>o.filter(([s])=>s!==n))}};return t.type=r=>{let i=r.get(Ot).nodes[n];if(!i)throw vu(n);return i},t}function ut(n){let e,t=r=>async()=>(await r.wait(ve),e=n(r),r.update(ct,i=>[...i,e]),()=>{r.update(ct,i=>i.filter(o=>o!==e))});return t.plugin=()=>e,t.key=()=>e.spec.key,t}function a0(n){let e=t=>async()=>{await t.wait(Cr);let r=t.get(Pi),i=n(t),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function $e(n,e){let t=$(n,e),r=i=>(i.inject(t),()=>()=>{i.remove(t)});return r.key=t,r}function We(n,e){let t=$e(e,n),r=As(n,o=>o.get(t.key)(o)),i=[t,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=t,i.key=t.key,i.extendSchema=o=>{let s=o(e);return We(n,s)},i}function Tr(n,e){let t=$e(e,n),r=l0(n,o=>o.get(t.key)(o)),i=[t,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=t,i.key=t.key,i.extendSchema=o=>{let s=o(e);return Tr(n,s)},i}function De(n,e){let t=Object.fromEntries(Object.entries(e).map(([s,{shortcuts:l,priority:a}])=>[s,{shortcuts:l,priority:a}])),r=$e(t,`${n}Keymap`),i=a0(s=>{let l=s.get(r.key),a=Object.entries(e).flatMap(([c,{command:u}])=>{let f=l[c],d=[f.shortcuts].flat(),h=f.priority;return d.map(p=>[p,{key:p,onRun:u,priority:h}])});return Object.fromEntries(a)}),o=[r,i];return o.ctx=r,o.shortcuts=i,o.key=r.key,o.keymap=i.keymap,o}var Ye=(n,e=()=>({}))=>$e(e,`${n}Attr`),Li=(n,e=()=>({}))=>$e(e,`${n}Attr`);function vn(n,e,t){let r=$e(t??{},n),i=s=>async()=>{await s.wait(Tt);let a={plugin:e(s),options:s.get(r.key)};return s.update(Ir,c=>[...c,a]),()=>{s.update(Ir,c=>c.filter(u=>u!==a))}},o=[r,i];return o.id=n,o.plugin=i,o.options=r,o}function c0(n,e){return t=>t.get(G).call(n,e)}function Gp(n,e){return function(t,r){let{$from:i,$to:o,node:s}=t.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let l=i.node(-1);if(l.type!=n)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=n||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 x=i.depth-d;x>=i.depth-3;x--)f=M.from(i.node(x).copy(f));let h=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(M.from(n.createAndFill()));let p=i.before(i.depth-(d-1)),m=t.tr.replace(p,i.after(-h),new O(f,4-d,0)),k=-1;m.doc.nodesBetween(p,m.doc.content.size,(x,I)=>{if(k>-1)return!1;x.isTextblock&&x.content.size==0&&(k=I+1)}),k>-1&&m.setSelection(W.near(m.doc.resolve(k))),r(m.scrollIntoView())}return!0}let a=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,o.pos),u=a?[e?{type:n,attrs:e}:null,{type:a}]:void 0;return un(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function Yp(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?u0(e,t,n,o):f0(e,t,o):!0:!1}}function u0(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(i.step(new he(o-1,s,o,s,new O(M.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new Kr(i.doc.resolve(r.$from.pos),i.doc.resolve(s),r.depth));let l=Yn(r);if(l==null)return!1;i.lift(r,l);let a=i.doc.resolve(i.mapping.map(o,-1)-1);return fn(i.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&i.join(a.pos),e(i.scrollIntoView()),!0}function f0(n,e,t){let r=n.tr,i=t.parent;for(let h=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)h-=i.child(p).nodeSize,r.delete(h-1,h+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(l?0:1),u+1,s.content.append(a?M.empty:M.from(i))))return!1;let f=o.pos,d=f+s.nodeSize;return r.step(new he(f-(l?1:0),d+(a?1:0),f+1,d-1,new O((l?M.empty:M.from(i.copy(M.empty))).append(a?M.empty:M.from(i.copy(M.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function Qp(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,a=l.child(s-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,u=M.from(c?n.create():null),f=new O(M.from(n.create(null,M.from(l.type.create(null,u)))),c?3:1,0),d=o.start,h=o.end;t(e.tr.step(new he(d-(c?3:1),h,d,h,f,1,!0)).scrollIntoView())}return!0}}function pc(n){let e=new Map;if(!n||!n.type)throw new Error("mdast-util-definitions expected node");return et(n,"definition",function(r){let i=Xp(r.identifier);i&&!e.get(i)&&e.set(i,r)}),t;function t(r){let i=Xp(r);return e.get(i)}}function Xp(n){return String(n||"").toUpperCase()}function Rs(){return function(n){let e=pc(n);et(n,function(t,r,i){if(t.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[kn,r];if(t.type==="imageReference"||t.type==="linkReference"){let o=e(t.identifier);if(o&&i&&typeof r=="number")return i.children[r]=t.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:t.alt}:{type:"link",url:o.url,title:o.title,children:t.children},[kn,r]}})}}function Zp(n,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){n.next(e.content);return}let r=[];e.content.forEach((i,o,s)=>{s!==e.childCount-1&&r.push(i)}),n.next(M.fromArray(r))}function w(n,e){return Object.assign(n,{meta:{package:"@milkdown/preset-commonmark",...e}}),n}var mc=Li("emphasis");w(mc,{displayName:"Attr<emphasis>",group:"Emphasis"});var Er=Tr("emphasis",n=>({attrs:{marker:{default:n.get(kr).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",n.get(mc.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,t,r)=>{e.openMark(r,{marker:t.marker}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,t)=>{e.withMark(t,"emphasis",void 0,{marker:t.attrs.marker})}}}));w(Er.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});w(Er.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Ds=J("ToggleEmphasis",n=>()=>xo(Er.type(n)));w(Ds,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var em=Ge(n=>wi(/(?:^|[^*])\*([^*]+)\*$/,Er.type(n),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:t+1}}));w(em,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var tm=Ge(n=>wi(/\b_(?![_\s])(.*?[^_\s])_\b/,Er.type(n),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:t+1}}));w(tm,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var gc=De("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:n=>{let e=n.get(G);return()=>e.call(Ds.key)}}});w(gc.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});w(gc.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var yc=Li("strong");w(yc,{displayName:"Attr<strong>",group:"Strong"});var Bi=Tr("strong",n=>({attrs:{marker:{default:n.get(kr).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",n.get(yc.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,t,r)=>{e.openMark(r,{marker:t.marker}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,t)=>{e.withMark(t,"strong",void 0,{marker:t.attrs.marker})}}}));w(Bi.mark,{displayName:"MarkSchema<strong>",group:"Strong"});w(Bi.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var Ps=J("ToggleStrong",n=>()=>xo(Bi.type(n)));w(Ps,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var nm=Ge(n=>wi(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),Bi.type(n),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));w(nm,{displayName:"InputRule<strong>",group:"Strong"});var xc=De("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:n=>{let e=n.get(G);return()=>e.call(Ps.key)}}});w(xc.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});w(xc.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var kc=Li("inlineCode");w(kc,{displayName:"Attr<inlineCode>",group:"InlineCode"});var Jt=Tr("inlineCode",n=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",n.get(kc.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,t,r)=>{e.openMark(r),e.addText(t.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,t,r)=>{e.withMark(t,"inlineCode",r.text||"")}}}));w(Jt.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});w(Jt.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var bc=J("ToggleInlineCode",n=>()=>(e,t)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,Jt.type(n))?(t?.(i.removeMark(o,s,Jt.type(n))),!0):(Object.keys(e.schema.marks).filter(c=>c!==Jt.type.name).map(c=>e.schema.marks[c]).forEach(c=>{i.removeMark(o,s,c)}),t?.(i.addMark(o,s,Jt.type(n).create())),!0)});w(bc,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var rm=Ge(n=>wi(/(?:`)([^`]+)(?:`)$/,Jt.type(n)));w(rm,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var wc=De("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:n=>{let e=n.get(G);return()=>e.call(bc.key)}}});w(wc.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});w(wc.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var Sc=Li("link");w(Sc,{displayName:"Attr<link>",group:"Link"});var Or=Tr("link",n=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Lt(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...n.get(Sc.key)(e),...e.attrs}],parseMarkdown:{match:e=>e.type==="link",runner:(e,t,r)=>{let i=t.url,o=t.title;e.openMark(r,{href:i,title:o}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,t)=>{e.withMark(t,"link",void 0,{title:t.attrs.title,url:t.attrs.href})}}}));w(Or.mark,{displayName:"MarkSchema<link>",group:"Link"});var im=J("ToggleLink",n=>(e={})=>xo(Or.type(n),e));w(im,{displayName:"Command<toggleLinkCommand>",group:"Link"});var om=J("UpdateLink",n=>(e={})=>(t,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=t,{from:l,to:a}=s;if(t.doc.nodesBetween(l,l===a?a+1:a,(p,m)=>{if(Or.type(n).isInSet(p.marks))return i=p,o=m,!1}),!i)return!1;let c=i.marks.find(({type:p})=>p===Or.type(n));if(!c)return!1;let u=o,f=o+i.nodeSize,{tr:d}=t,h=Or.type(n).create({...c.attrs,...e});return h?(r(d.removeMark(u,f,c).addMark(u,f,h).setSelection(new j(d.selection.$anchor)).scrollIntoView()),!0):!1});w(om,{displayName:"Command<updateLinkCommand>",group:"Link"});var sm=As("doc",()=>({content:"block+",parseMarkdown:{match:({type:n})=>n==="root",runner:(n,e,t)=>{n.injectRoot(e,t)}},toMarkdown:{match:n=>n.type.name==="doc",runner:(n,e)=>{n.openNode("root"),n.next(e.content)}}}));w(sm,{displayName:"NodeSchema<doc>",group:"Doc"});function h0(n){return ci(n,e=>e.type==="html"&&["<br />","<br>","<br >","<br/>"].includes(e.value?.trim()),(e,t)=>{if(!t.length)return;let r=t[t.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var Ls=vn("remark-preserve-empty-line",()=>()=>h0);w(Ls.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});w(Ls.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Cc=Ye("paragraph");w(Cc,{displayName:"Attr<paragraph>",group:"Paragraph"});var Pn=We("paragraph",n=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",n.get(Cc.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,t,r)=>{e.openNode(r),t.children?e.next(t.children):e.addText(t.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,t)=>{let i=n.get(rt).state?.doc.lastChild;e.openNode("paragraph"),(!t.content||t.content.size===0)&&t!==i&&d0(n)?e.addNode("html",void 0,"<br />"):Zp(e,t),e.closeNode()}}}));function d0(n){let e=!1;try{n.get(Ls.id),e=!0}catch{e=!1}return e}w(Pn.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});w(Pn.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var Bs=J("TurnIntoText",n=>()=>er(Pn.type(n)));w(Bs,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Mc=De("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:n=>{let e=n.get(G);return()=>e.call(Bs.key)}}});w(Mc.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});w(Mc.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var p0=Array(6).fill(0).map((n,e)=>e+1);function m0(n){return n.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var zs=$e(m0,"headingIdGenerator");w(zs,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Nc=Ye("heading");w(Nc,{displayName:"Attr<heading>",group:"Heading"});var Ln=We("heading",n=>{let e=n.get(zs.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:p0.map(t=>({tag:`h${t}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw Lt(r);return{level:t,id:r.id}}})),toDOM:t=>[`h${t.attrs.level}`,{...n.get(Nc.key)(t),id:t.attrs.id||e(t)},0],parseMarkdown:{match:({type:t})=>t==="heading",runner:(t,r,i)=>{let o=r.depth;t.openNode(i,{level:o}),t.next(r.children),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="heading",runner:(t,r)=>{t.openNode("heading",void 0,{depth:r.attrs.level}),Zp(t,r),t.closeNode()}}}});w(Ln.node,{displayName:"NodeSchema<heading>",group:"Heading"});w(Ln.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var lm=Ge(n=>Ma(/^(?<hashes>#+)\s$/,Ln.type(n),e=>{let t=e.groups?.hashes?.length||0,r=n.get(rt),{$from:i}=r.state.selection,o=i.node();if(o.type.name==="heading"){let s=Number(o.attrs.level)+Number(t);return s>6&&(s=6),{level:s}}return{level:t}}));w(lm,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var At=J("WrapInHeading",n=>e=>(e??=1,e<1?er(Pn.type(n)):er(Ln.type(n),{level:e})));w(At,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Ic=J("DowngradeHeading",n=>()=>(e,t,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==Ln.type(n)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(t?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):er(Pn.type(n))(e,t,r)});w(Ic,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var Tc=De("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:n=>{let e=n.get(G);return()=>e.call(At.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:n=>{let e=n.get(G);return()=>e.call(At.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:n=>{let e=n.get(G);return()=>e.call(At.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:n=>{let e=n.get(G);return()=>e.call(At.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:n=>{let e=n.get(G);return()=>e.call(At.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:n=>{let e=n.get(G);return()=>e.call(At.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:n=>{let e=n.get(G);return()=>e.call(Ic.key)}}});w(Tc.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});w(Tc.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Oc=Ye("blockquote");w(Oc,{displayName:"Attr<blockquote>",group:"Blockquote"});var zi=We("blockquote",n=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",n.get(Oc.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,t,r)=>{e.openNode(r).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,t)=>{e.openNode("blockquote").next(t.content).closeNode()}}}));w(zi.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});w(zi.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var am=Ge(n=>Yo(/^\s*>\s$/,zi.type(n)));w(am,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Fs=J("WrapInBlockquote",n=>()=>yo(zi.type(n)));w(Fs,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Ec=De("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:n=>{let e=n.get(G);return()=>e.call(Fs.key)}}});w(Ec.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});w(Ec.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var Ac=Ye("codeBlock",()=>({pre:{},code:{}}));w(Ac,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var Fi=We("code_block",n=>({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 Lt(e);return{language:e.dataset.language}}}],toDOM:e=>{let t=n.get(Ac.key)(e),r=e.attrs.language,i=r&&r.length>0?{"data-language":r}:void 0;return["pre",{...t.pre,...i},["code",t.code,0]]},parseMarkdown:{match:({type:e})=>e==="code",runner:(e,t,r)=>{let i=t.lang??"",o=t.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,t)=>{e.addNode("code",void 0,t.content.firstChild?.text||"",{lang:t.attrs.language})}}}));w(Fi.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});w(Fi.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var cm=Ge(n=>Ma(/^```(?<language>[a-z]*)?[\s\n]$/,Fi.type(n),e=>({language:e.groups?.language??""})));w(cm,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Rc=J("CreateCodeBlock",n=>(e="")=>er(Fi.type(n),{language:e}));w(Rc,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var g0=J("UpdateCodeBlockLanguage",()=>({pos:n,language:e}={pos:-1,language:""})=>(t,r)=>n>=0?(r?.(t.tr.setNodeAttribute(n,"language",e)),!0):!1);w(g0,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var vc=De("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:n=>{let e=n.get(G);return()=>e.call(Rc.key)}}});w(vc.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});w(vc.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Dc=Ye("image");w(Dc,{displayName:"Attr<image>",group:"Image"});var Ar=We("image",n=>({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 Lt(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...n.get(Dc.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,t,r)=>{let i=t.url,o=t.alt,s=t.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,t)=>{e.addNode("image",void 0,void 0,{title:t.attrs.title,url:t.attrs.src,alt:t.attrs.alt})}}}));w(Ar.node,{displayName:"NodeSchema<image>",group:"Image"});w(Ar.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var um=J("InsertImage",n=>(e={})=>(t,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,l=Ar.type(n).create({src:i,alt:o,title:s});return l&&r(t.tr.replaceSelectionWith(l).scrollIntoView()),!0});w(um,{displayName:"Command<insertImageCommand>",group:"Image"});var fm=J("UpdateImage",n=>(e={})=>(t,r)=>{let i=wd(t.selection,Ar.type(n));if(!i)return!1;let{node:o,pos:s}=i,l={...o.attrs},{src:a,alt:c,title:u}=e;return a!==void 0&&(l.src=a),c!==void 0&&(l.alt=c),u!==void 0&&(l.title=u),r?.(t.tr.setNodeMarkup(s,void 0,l).scrollIntoView()),!0});w(fm,{displayName:"Command<updateImageCommand>",group:"Image"});var y0=Ge(n=>new Ne(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,t,r,i)=>{let[o,s,l="",a]=t;return o?e.tr.replaceWith(r,i,Ar.type(n).create({src:l,alt:s,title:a})):null}));w(y0,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var vs=Ye("hardbreak",n=>({"data-type":"hardbreak","data-is-inline":n.attrs.isInline}));w(vs,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Dn=We("hardbreak",n=>({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",n.get(vs.key)(e)," "]:["br",n.get(vs.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,t,r)=>{e.addNode(r,{isInline:!!t.data?.isInline})}},leafText:()=>` 44 + `))),0,0),n.someProp("transformPasted",d=>{l=d(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:h}=n.state,p=sn.fromSchema(h);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let k=s.appendChild(document.createElement("p"));m&&k.appendChild(p.serializeNode(h.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=cw(t),Ai&&uw(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(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||on.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!sw.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)l=fw(qd(l,+u[1],+u[2]),u[4]);else if(l=O.maxOpen(lw(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let h=l.content.firstChild;f<l.openStart&&!h.type.spec.isolating;f++,h=h.firstChild);for(let h=l.content.lastChild;d<l.openEnd&&!h.type.spec.isolating;d++,h=h.lastChild);l=qd(l,f,d)}return n.someProp("transformPasted",f=>{l=f(l,n,a)}),l}var sw=/^(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 lw(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),c;if(!a)return s=null;if(c=s.length&&o.length&&Sp(a,o,l,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=Cp(s[s.length-1],o.length));let u=wp(l,a);s.push(u),i=i.matchType(u.type),o=a}}),s)return M.from(s)}return n}function wp(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,M.from(n));return n}function Sp(n,e,t,r,i){if(i<n.length&&i<e.length&&n[i]==e[i]){let o=Sp(n,e,t,r.lastChild,i+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(i==n.length-1?t.type:n[i+1]))return r.copy(r.content.append(M.from(wp(t,n,i+1))))}}function Cp(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Cp(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(M.empty,!0);return n.copy(t.append(r))}function Ka(n,e,t,r,i,o){let s=e<0?n.firstChild:n.lastChild,l=s.content;return n.childCount>1&&(o=0),i<r-1&&(l=Ka(l,e,t,r,i+1,o)),i>=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(M.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function qd(n,e,t){return e<n.openStart&&(n=new O(Ka(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new O(Ka(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}var Mp={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},Kd=null;function Np(){return Kd||(Kd=document.implementation.createHTMLDocument("title"))}var va=null;function aw(n){let e=window.trustedTypes;return e?(va||(va=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),va.createHTML(n)):n}function cw(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Np().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Mp[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"</"+o+">").reverse().join("")),t.innerHTML=aw(n),i)for(let o=0;o<i.length;o++)t=t.querySelector(i[o])||t;return t}function uw(n){let e=n.querySelectorAll(me?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let r=e[t];r.childNodes.length==1&&r.textContent=="\xA0"&&r.parentNode&&r.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),r)}}function fw(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return n}let{content:i,openStart:o,openEnd:s}=n;for(let l=r.length-2;l>=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=M.from(a.create(r[l+1],i)),o++,s++}return new O(i,o,s)}var Te={},Oe={},hw={touchstart:!0,touchmove:!0},Ua=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 dw(n){for(let e in Te){let t=Te[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{mw(n,r)&&!rc(n,r)&&(n.editable||!(r.type in Oe))&&t(n,r)},hw[e]?{passive:!0}:void 0)}we&&n.dom.addEventListener("input",()=>null),Ja(n)}function Ht(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function pw(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Ja(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>rc(n,r))})}function rc(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function mw(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function gw(n,e){!rc(n,e)&&Te[e.type]&&(n.editable||!(e.type in Oe))&&Te[e.type](n,e)}Oe.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Tp(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Nt&&me&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),yr&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||ow(n,t)?t.preventDefault():Ht(n,"key")};Oe.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Oe.keypress=(n,e)=>{let t=e;if(Tp(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||qe&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof j)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),o=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i,o))&&n.dispatch(o()),t.preventDefault()}};function fs(n){return{left:n.clientX,top:n.clientY}}function yw(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function ic(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function mr(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function xw(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&B.isSelectable(r)?(mr(n,new B(t),"pointer"),!0):!1}function kw(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof B&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(B.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(mr(n,B.create(n.state.doc,i),"pointer"),!0):!1}function bw(n,e,t,r,i){return ic(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?kw(n,t):xw(n,t))}function ww(n,e,t,r){return ic(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Sw(n,e,t,r){return ic(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Cw(n,t,r)}function Cw(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(mr(n,j.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)mr(n,j.create(r,l+1,l+1+s.content.size),"pointer");else if(B.isSelectable(s))mr(n,B.create(r,l),"pointer");else continue;return!0}}function oc(n){return is(n)}var Ip=qe?"metaKey":"ctrlKey";Te.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=oc(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&yw(t,n.input.lastClick)&&!t[Ip]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o,button:t.button};let s=n.posAtCoords(fs(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Ga(n,s,t,!!r)):(o=="doubleClick"?ww:Sw)(n,s.pos,s.inside,t)?t.preventDefault():Ht(n,"pointer"))};var Ga=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Ip],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let u=e.state.doc.resolve(t.pos);o=u.parent,s=u.depth?u.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof B&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ue&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Ht(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>It(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fs(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ht(this.view,"pointer"):bw(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||we&&this.mightDrag&&!this.mightDrag.node.isAtom||me&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(mr(this.view,W.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Ht(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ht(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};Te.touchstart=n=>{n.input.lastTouch=Date.now(),oc(n),Ht(n,"pointer")};Te.touchmove=n=>{n.input.lastTouch=Date.now(),Ht(n,"pointer")};Te.contextmenu=n=>oc(n);function Tp(n,e){return n.composing?!0:we&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var Mw=Nt?5e3:-1;Oe.compositionstart=Oe.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof j&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||me&&sp&&Nw(n)))n.markCursor=n.state.storedMarks||t.marks(),is(n,!0),n.markCursor=null;else if(is(n,!e.selection.empty),Ue&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.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 l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Op(n,Mw)};function Nw(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let r=e.childNodes[t];return r.nodeType==1&&r.contentEditable=="false"}Oe.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Op(n,20))};function Op(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>is(n),e))}function Ep(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Tw());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Iw(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Cb(e.focusNode,e.focusOffset),r=Mb(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function Tw(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function is(n,e=!1){if(!(Nt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ep(n),e||n.docView&&n.docView.dirty){let t=ec(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function Ow(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Ni=Re&&qt<15||yr&&Ob<604;Te.copy=Oe.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Ni?null:t.clipboardData,s=r.content(),{dom:l,text:a}=nc(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):Ow(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Ew(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function Aw(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Ii(n,r.value,null,i,e):Ii(n,r.textContent,r.innerHTML,i,e)},50)}function Ii(n,e,t,r,i){let o=bp(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||O.empty)))return!0;if(!o)return!1;let s=Ew(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Ap(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Oe.paste=(n,e)=>{let t=e;if(n.composing&&!Nt)return;let r=Ni?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Ii(n,Ap(r),r.getData("text/html"),i,t)?t.preventDefault():Aw(n,t)};var ss=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Rw=qe?"altKey":"ctrlKey";function Rp(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[Rw]}Te.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(fs(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof B?i.to-1:i.to))){if(r&&r.mightDrag)s=B.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=B.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:c,slice:u}=nc(n,l);(!t.dataTransfer.files.length||!me||op>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Ni?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Ni||t.dataTransfer.setData("text/plain",c),n.dragging=new ss(u,Rp(n,t),s)};Te.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Oe.dragover=Oe.dragenter=(n,e)=>e.preventDefault();Oe.drop=(n,e)=>{try{vw(n,e,n.dragging)}finally{n.dragging=null}};function vw(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(fs(e));if(!r)return;let i=n.state.doc.resolve(r.pos),o=t&&t.slice;o?n.someProp("transformPasted",h=>{o=h(o,n,!1)}):o=bp(n,Ap(e.dataTransfer),Ni?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(t&&Rp(n,e));if(n.someProp("handleDrop",h=>h(n,e,o||O.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let l=o?mf(n.state.doc,i.pos,o):i.pos;l==null&&(l=i.pos);let a=n.state.tr;if(s){let{node:h}=t;h?h.replace(a):a.deleteSelection()}let c=a.mapping.map(l),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(u?a.replaceRangeWith(c,c,o.content.firstChild):a.replaceRange(c,c,o),a.doc.eq(f))return;let d=a.doc.resolve(c);if(u&&B.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new B(d));else{let h=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,k,x)=>h=x),a.setSelection(tc(n,d,a.doc.resolve(h)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Te.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&It(n)},20))};Te.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Te.beforeinput=(n,e)=>{if(me&&Nt&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,Sn(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Oe)Te[n]=Oe[n];function Ti(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var ls=class n{constructor(e,t){this.toDOM=e,this.spec=t||In,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new nt(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Ti(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Nn=class n{constructor(e,t){this.attrs=e,this.spec=t||In}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new nt(o,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof n&&Ti(this.attrs,e.attrs)&&Ti(this.spec,e.spec)}static is(e){return e.type instanceof n}destroy(){}},Ya=class n{constructor(e,t){this.attrs=e,this.spec=t||In}map(e,t,r,i){let o=e.mapResult(t.from+i,1);if(o.deleted)return null;let s=e.mapResult(t.to+i,-1);return s.deleted||s.pos<=o.pos?null:new nt(o.pos-r,s.pos-r,this)}valid(e,t){let{index:r,offset:i}=e.content.findIndex(t.from),o;return i==t.from&&!(o=e.child(r)).isText&&i+o.nodeSize==t.to}eq(e){return this==e||e instanceof n&&Ti(this.attrs,e.attrs)&&Ti(this.spec,e.spec)}destroy(){}},nt=class n{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new n(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,r){return this.type.map(e,this,t,r)}static widget(e,t,r){return new n(e,e,new ls(t,r))}static inline(e,t,r,i){return new n(e,t,new Nn(r,i))}static node(e,t,r,i){return new n(e,t,new Ya(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Nn}get widget(){return this.type instanceof ls}},pr=[],In={},Ie=class n{constructor(e,t){this.local=e.length?e:pr,this.children=t.length?t:pr}static create(e,t){return t.length?cs(t,e,0,In):be}find(e,t,r){let i=[];return this.findInner(e??0,t??1e9,i,0,r),i}findInner(e,t,r,i,o){for(let s=0;s<this.local.length;s++){let l=this.local[s];l.from<=t&&l.to>=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==be||e.maps.length==0?this:this.mapInner(e,t,0,0,r||In)}mapInner(e,t,r,i,o){let s;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,r,i);a&&a.type.valid(t,a)?(s||(s=[])).push(a):o.onRemove&&o.onRemove(this.local[l].spec)}return this.children.length?Dw(this.children,s||[],e,t,r,i,o):s?new n(s.sort(Tn),pr):be}add(e,t){return t.length?this==be?n.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let i,o=0;e.forEach((l,a)=>{let c=a+r,u;if(u=Dp(t,l,c)){for(i||(i=this.children.slice());o<i.length&&i[o]<a;)o+=3;i[o]==a?i[o+2]=i[o+2].addInner(l,u,c+1):i.splice(o,0,a,a+l.nodeSize,cs(u,l,c+1,In)),o+=3}});let s=vp(o?Pp(t):t,-r);for(let l=0;l<s.length;l++)s[l].type.valid(e,s[l])||s.splice(l--,1);return new n(s.length?this.local.concat(s).sort(Tn):this.local,i||this.children)}remove(e){return e.length==0||this==be?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,i=this.local;for(let o=0;o<r.length;o+=3){let s,l=r[o]+t,a=r[o+1]+t;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>l&&f.to<a&&(e[u]=null,(s||(s=[])).push(f));if(!s)continue;r==this.children&&(r=this.children.slice());let c=r[o+2].removeInner(s,l+1);c!=be?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 l=0;l<i.length;l++)i[l].eq(s,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new n(i,r):be}forChild(e,t){if(this==be)return this;if(t.isLeaf)return n.empty;let r,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<s&&a.to>o&&a.type instanceof Nn){let c=Math.max(o,a.from)-o,u=Math.min(s,a.to)-o;c<u&&(i||(i=[])).push(a.copy(c,u))}}if(i){let l=new n(i.sort(Tn),pr);return r?new as([l,r]):l}return r||be}eq(e){if(this==e)return!0;if(!(e instanceof n)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return sc(this.localsInner(e))}localsInner(e){if(this==be)return pr;if(e.inlineContent||!this.local.some(Nn.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Nn||t.push(this.local[r]);return t}forEachSet(e){e(this)}};Ie.empty=new Ie([],[]);Ie.removeOverlap=sc;var be=Ie.empty,as=class n{constructor(e){this.members=e}map(e,t){let r=this.members.map(i=>i.map(e,t,In));return n.from(r)}forChild(e,t){if(t.isLeaf)return Ie.empty;let r=[];for(let i=0;i<this.members.length;i++){let o=this.members[i].forChild(e,t);o!=be&&(o instanceof n?r=r.concat(o.members):r.push(o))}return n.from(r)}eq(e){if(!(e instanceof n)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,r=!0;for(let i=0;i<this.members.length;i++){let o=this.members[i].localsInner(e);if(o.length)if(!t)t=o;else{r&&(t=t.slice(),r=!1);for(let s=0;s<o.length;s++)t.push(o[s])}}return t?sc(r?t:t.sort(Tn)):pr}static from(e){switch(e.length){case 0:return be;case 1:return e[0];default:return new n(e.every(t=>t instanceof Ie)?e:e.reduce((t,r)=>t.concat(r instanceof Ie?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Dw(n,e,t,r,i,o,s){let l=n.slice();for(let c=0,u=o;c<t.maps.length;c++){let f=0;t.maps[c].forEach((d,h,p,m)=>{let k=m-p-(h-d);for(let x=0;x<l.length;x+=3){let I=l[x+1];if(I<0||d>I+u-f)continue;let C=l[x]+u-f;h>=C?l[x+1]=d<=C?-2:-1:d>=u&&k&&(l[x]+=k,l[x+1]+=k)}f+=k}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let u=t.map(n[c]+o),f=u-i;if(f<0||f>=r.content.size){a=!0;continue}let d=t.map(n[c+1]+o,-1),h=d-i,{index:p,offset:m}=r.content.findIndex(f),k=r.maybeChild(p);if(k&&m==f&&m+k.nodeSize==h){let x=l[c+2].mapInner(t,k,u+1,n[c]+o+1,s);x!=be?(l[c]=f,l[c+1]=h,l[c+2]=x):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Pw(l,n,e,t,i,o,s),u=cs(c,r,0,s);e=u.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,d=0;f<u.children.length;f+=3){let h=u.children[f];for(;d<l.length&&l[d]<h;)d+=3;l.splice(d,0,u.children[f],u.children[f+1],u.children[f+2])}}return new Ie(e.sort(Tn),l)}function vp(n,e){if(!e||!n.length)return n;let t=[];for(let r=0;r<n.length;r++){let i=n[r];t.push(new nt(i.from+e,i.to+e,i.type))}return t}function Pw(n,e,t,r,i,o,s){function l(a,c){for(let u=0;u<a.local.length;u++){let f=a.local[u].map(r,i,c);f?t.push(f):s.onRemove&&s.onRemove(a.local[u].spec)}for(let u=0;u<a.children.length;u+=3)l(a.children[u+2],a.children[u]+c+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+o+1);return t}function Dp(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,i=null;for(let o=0,s;o<n.length;o++)(s=n[o])&&s.from>t&&s.to<r&&((i||(i=[])).push(s),n[o]=null);return i}function Pp(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function cs(n,e,t,r){let i=[],o=!1;e.forEach((l,a)=>{let c=Dp(n,l,a+t);if(c){o=!0;let u=cs(c,l,t+a+1,r);u!=be&&i.push(a,a+l.nodeSize,u)}});let s=vp(o?Pp(n):n,-t).sort(Tn);for(let l=0;l<s.length;l++)s[l].type.valid(e,s[l])||(r.onRemove&&r.onRemove(s[l].spec),s.splice(l--,1));return s.length||i.length?new Ie(s,i):be}function Tn(n,e){return n.from-e.from||n.to-e.to}function sc(n){let e=n;for(let t=0;t<e.length-1;t++){let r=e[t];if(r.from!=r.to)for(let i=t+1;i<e.length;i++){let o=e[i];if(o.from==r.from){o.to!=r.to&&(e==n&&(e=n.slice()),e[i]=o.copy(o.from,r.to),Ud(e,i+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,o.from),Ud(e,i,r.copy(o.from,r.to)));break}}}return e}function Ud(n,e,t){for(;e<n.length&&Tn(t,n[e])>0;)e++;n.splice(e,0,t)}function Da(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=be&&e.push(r)}),n.cursorWrapper&&e.push(Ie.create(n.state.doc,[n.cursorWrapper.deco])),as.from(e)}var Lw={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Bw=Re&&qt<=11,Qa=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}},Xa=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Qa,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]);Re&&qt<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():we&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Bw&&(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,Lw)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(_d(this.view)){if(this.suppressingSelectionUpdates)return It(this.view);if(Re&&qt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&On(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let o=e.focusNode;o;o=gr(o))t.add(o);for(let o=e.anchorNode;o;o=gr(o))if(t.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 t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&_d(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let u=0;u<t.length;u++){let f=this.registerMutation(t[u],a);f&&(o=o<0?f.from:Math.min(f.from,o),s=s<0?f.to:Math.max(f.to,s),f.typeOver&&(l=!0))}if(a.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of a)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(Ue&&a.length){let u=a.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 h=d.parentNode;h&&h.nodeName=="LI"&&(!f||_w(e,f)!=h)&&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&&us(r)&&(c=ec(e))&&c.eq(W.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,It(e),this.currentSelection.set(r),e.scrollToSelection()):(o>-1||i)&&(o>-1&&(e.docView.markDirty(o,s),zw(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Vw(e,a)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||It(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.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];t.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(Re&&qt<=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?pe(i)+1:0,l=r.localPosFromDOM(e.target,s,-1),a=o&&o.parentNode==e.target?pe(o):e.target.childNodes.length,c=r.localPosFromDOM(e.target,a,1);return{from:l,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})}},Jd=new WeakMap,Gd=!1;function zw(n){if(!Jd.has(n)&&(Jd.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Ue,Gd)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."),Gd=!0}}function Yd(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,o=e.endOffset,s=n.domAtPos(n.state.selection.anchor);return On(s.node,s.offset,i,o)&&([t,r,i,o]=[i,o,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:o}}function Fw(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Yd(n,i)}let t;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",r,!0),t?Yd(n,t):null}function _w(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let r=n.docView.nearestDesc(t,!0);if(r&&r.node.isBlock)return t}return null}function Vw(n,e){var t;let{focusNode:r,focusOffset:i}=n.domSelectionRange();for(let o of e)if(((t=o.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let s=o.nextSibling;for(;s&&s.nodeName!="TD"&&s.nodeName!="TH";)s=s.nextSibling;if(s){let l=s;for(;;){let a=l.firstChild;if(!a||a.nodeType!=1||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(o,l.firstChild),r==o&&n.domSelection().collapse(o,i)}else o.parentNode.removeChild(o)}}function $w(n,e,t){let{node:r,fromOffset:i,toOffset:o,from:s,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),c,u=a.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:a.anchorOffset}],us(a)||c.push({node:a.focusNode,offset:a.focusOffset})),me&&n.input.lastKeyCode===8)for(let k=o;k>i;k--){let x=r.childNodes[k-1],I=x.pmViewDesc;if(x.nodeName=="BR"&&!I){o=k;break}if(!I||I.size)break}let f=n.state.doc,d=n.someProp("domParser")||on.fromSchema(n.state.schema),h=f.resolve(s),p=null,m=d.parse(r,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:o,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Ww,context:h});if(c&&c[0].pos!=null){let k=c[0].pos,x=c[1]&&c[1].pos;x==null&&(x=k),p={anchor:k+s,head:x+s}}return{doc:m,sel:p,from:s,to:l}}function Ww(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(we&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||we&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var jw=/^(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 Hw(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,P=ec(n,T);if(P&&!n.state.selection.eq(P)){if(me&&Nt&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",U=>U(n,Sn(13,"Enter"))))return;let D=n.state.tr.setSelection(P);T=="pointer"?D.setMeta("pointer",!0):T=="key"&&D.scrollIntoView(),o&&D.setMeta("composition",o),n.dispatch(D)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=$w(n,e,t),u=n.state.doc,f=u.slice(c.from,c.to),d,h;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(d=n.state.selection.to,h="end"):(d=n.state.selection.from,h="start"),n.input.lastKeyCode=null;let p=Uw(f.content,c.doc.content,c.from,d,h);if(p&&n.input.domChangeCount++,(yr&&n.input.lastIOSEnter>Date.now()-225||Nt)&&i.some(T=>T.nodeType==1&&!jw.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,Sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&a instanceof j&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let T=Qd(n,n.state.doc,c.sel);if(T&&!T.eq(n.state.selection)){let P=n.state.tr.setSelection(T);o&&P.setMeta("composition",o),n.dispatch(P)}}return}n.state.selection.from<n.state.selection.to&&p.start==p.endB&&n.state.selection instanceof j&&(p.start>n.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?p.start=n.state.selection.from:p.endA<n.state.selection.to&&p.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),Re&&qt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),k=c.doc.resolveNoCache(p.endB-c.from),x=u.resolve(p.start),I=m.sameParent(k)&&m.parent.inlineContent&&x.end()>=p.endA;if((yr&&n.input.lastIOSEnter>Date.now()-225&&(!I||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!I&&m.pos<c.doc.content.size&&(!m.sameParent(k)||!m.parent.inlineContent)&&m.pos<k.pos&&!/\S/.test(c.doc.textBetween(m.pos,k.pos,"","")))&&n.someProp("handleKeyDown",T=>T(n,Sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Kw(u,p.start,p.endA,m,k)&&n.someProp("handleKeyDown",T=>T(n,Sn(8,"Backspace")))){Nt&&me&&n.domObserver.suppressSelectionUpdates();return}me&&p.endB==p.start&&(n.input.lastChromeDelete=Date.now()),Nt&&!I&&m.start()!=k.start()&&k.parentOffset==0&&m.depth==k.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,k=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,Sn(13,"Enter"))})},20));let C=p.start,A=p.endA,v=T=>{let P=T||n.state.tr.replace(C,A,c.doc.slice(p.start-c.from,p.endB-c.from));if(c.sel){let D=Qd(n,P.doc,c.sel);D&&!(me&&n.composing&&D.empty&&(p.start!=p.endB||n.input.lastChromeDelete<Date.now()-100)&&(D.head==C||D.head==P.mapping.map(A)-1)||Re&&D.empty&&D.head==C)&&P.setSelection(D)}return o&&P.setMeta("composition",o),P.scrollIntoView()},b;if(I)if(m.pos==k.pos){Re&&qt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>It(n),20));let T=v(n.state.tr.delete(C,A)),P=u.resolve(p.start).marksAcross(u.resolve(p.endA));P&&T.ensureMarks(P),n.dispatch(T)}else if(p.endA==p.endB&&(b=qw(m.parent.content.cut(m.parentOffset,k.parentOffset),x.parent.content.cut(x.parentOffset,p.endA-x.start())))){let T=v(n.state.tr);b.type=="add"?T.addMark(C,A,b.mark):T.removeMark(C,A,b.mark),n.dispatch(T)}else if(m.parent.child(m.index()).isText&&m.index()==k.index()-(k.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,k.parentOffset),P=()=>v(n.state.tr.insertText(T,C,A));n.someProp("handleTextInput",D=>D(n,C,A,T,P))||n.dispatch(P())}else n.dispatch(v());else n.dispatch(v())}function Qd(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:tc(n,e.resolve(t.anchor),e.resolve(t.head))}function qw(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let u=0;u<r.length;u++)i=r[u].removeFromSet(i);for(let u=0;u<t.length;u++)o=t[u].removeFromSet(o);if(i.length==1&&o.length==0)l=i[0],s="add",a=u=>u.mark(l.addToSet(u.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(a(e.child(u)));if(M.from(c).eq(n))return{mark:l,type:s}}function Kw(n,e,t,r,i){if(t-e<=i.pos-r.pos||Pa(r,!0,!1)<i.pos)return!1;let o=n.resolve(e);if(!r.parent.isTextblock){let l=o.nodeAfter;return l!=null&&t==e+l.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=n.resolve(Pa(o,!0,!0));return!s.parent.isTextblock||s.pos>t||Pa(s,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(s.parent.content)}function Pa(n,e,t){let r=n.depth,i=e?n.end():n.pos;for(;r>0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Uw(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s<o&&n.size<e.size){let a=r<=o&&r>=s?o-r:0;o-=a,o&&o<e.size&&Xd(e.textBetween(o-1,o+1))&&(o+=a?1:-1),l=o+(l-s),s=o}else if(l<o){let a=r<=o&&r>=l?o-r:0;o-=a,o&&o<n.size&&Xd(n.textBetween(o-1,o+1))&&(o+=a?1:-1),s=o+(s-l),l=o}return{start:o,endA:s,endB:l}}function Xd(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}var Oi=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Ua,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(rp),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=tp(this),ep(this),this.nodeViews=np(this),this.docView=Dd(this.state.doc,Zd(this),Da(this),this.dom,this),this.domObserver=new Xa(this,(r,i,o,s)=>Hw(this,r,i,o,s)),this.domObserver.start(),dw(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Ja(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(rp),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Ep(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let h=np(this);Gw(h,this.nodeViews)&&(this.nodeViews=h,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Ja(this),this.editable=tp(this),ep(this);let a=Da(this),c=Zd(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,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&Rb(this);if(s){this.domObserver.stop();let h=f&&(Re||me)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Jw(i.selection,e.selection);if(f){let p=me?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Iw(this)),(o||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Dd(e.doc,c,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Xb(this))?It(this,h):(yp(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&&vb(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof B){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Td(this,t.getBoundingClientRect(),e)}else Td(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 t=0;t<this.directPlugins.length;t++){let r=this.directPlugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let r=this.state.plugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let r=this.pluginViews[t];r.update&&r.update(this,e)}}updateDraggedNode(e,t){let r=e.node,i=-1;if(this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let o=r.from+(this.state.doc.content.size-t.doc.content.size);(o>0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ss(e.slice,e.move,i<0?void 0:B.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;s<this.directPlugins.length;s++){let l=this.directPlugins[s].props[e];if(l!=null&&(i=t?t(l):l))return i}let o=this.state.plugins;if(o)for(let s=0;s<o.length;s++){let l=o[s].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(Re){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&&Db(this.dom),It(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Fb(this,e)}coordsAtPos(e,t=1){return fp(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return jb(this,t||this.state,e)}pasteHTML(e,t){return Ii(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Ii(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return nc(this,e)}destroy(){this.docView&&(pw(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Da(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,wb())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return gw(this,e)}domSelectionRange(){let e=this.domSelection();return e?we&&this.root.nodeType===11&&Ib(this.dom.ownerDocument)==this.dom&&Fw(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Oi.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Zd(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[nt.node(0,n.state.doc.content.size,e)]}function ep(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:nt.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function tp(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Jw(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function np(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Gw(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function rp(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function Et(n,e){return n.meta={package:"@milkdown/core",group:"System",...e},n}var zp={text:(n,e,t,r)=>{let i=n.value;return/^[^*_\\]*\s+$/.test(i)?i:t.safe(i,{...r,encode:[]})},strong:(n,e,t,r)=>{let i=n.marker||t.options.strong||"*",o=t.enter("strong"),s=t.createTracker(r),l=s.move(i+i);return l+=s.move(t.containerPhrasing(n,{before:l,after:i,...s.current()})),l+=s.move(i+i),o(),l},emphasis:(n,e,t,r)=>{let i=n.marker||t.options.emphasis||"*",o=t.enter("emphasis"),s=t.createTracker(r),l=s.move(i);return l+=s.move(t.containerPhrasing(n,{before:l,after:i,...s.current()})),l+=s.move(i),o(),l}},rt=$({},"editorView"),Ri=$({},"editorState"),lc=$([],"initTimer"),Lp=$({},"editor"),Nr=$([],"inputRules"),it=$([],"prosePlugins"),Ir=$([],"remarkPlugins"),Ns=$([],"nodeView"),Is=$([],"markView"),An=$(di().use(ir).use(cr),"remark"),kr=$({handlers:zp,encode:[]},"remarkStringifyOptions"),hs=He("ConfigReady");function Yw(n){let e=t=>(t.record(hs),async()=>(await n(t),t.done(hs),()=>{t.clearTimer(hs)}));return Et(e,{displayName:"Config"}),e}var Tt=He("InitReady");function Qw(n){let e=t=>(t.inject(Lp,n).inject(it,[]).inject(Ir,[]).inject(Nr,[]).inject(Ns,[]).inject(Is,[]).inject(kr,{handlers:zp,encode:[]}).inject(An,di().use(ir).use(cr)).inject(lc,[hs]).record(Tt),async()=>{await t.waitTimers(lc);let r=t.get(kr);return t.set(An,di().use(ir).use(cr,r)),t.done(Tt),()=>{t.remove(Lp).remove(it).remove(Ir).remove(Nr).remove(Ns).remove(Is).remove(kr).remove(An).remove(lc).clearTimer(Tt)}});return Et(e,{displayName:"Init"}),e}var ve=He("SchemaReady"),ds=$([],"schemaTimer"),Ot=$({},"schema"),br=$([],"nodes"),wr=$([],"marks");function Bp(n){return{...n,parseDOM:n.parseDOM?.map(e=>({priority:n.priority,...e}))}}var Fp=n=>(n.inject(Ot,{}).inject(br,[]).inject(wr,[]).inject(ds,[Tt]).record(ve),async()=>{await n.waitTimers(ds);let e=n.get(An),r=n.get(Ir).reduce((l,a)=>l.use(a.plugin,a.options),e);n.set(An,r);let i=Object.fromEntries(n.get(br).map(([l,a])=>[l,Bp(a)])),o=Object.fromEntries(n.get(wr).map(([l,a])=>[l,Bp(a)])),s=new so({nodes:i,marks:o});return n.set(Ot,s),n.done(ve),()=>{n.remove(Ot).remove(br).remove(wr).remove(ds).clearTimer(ve)}});Et(Fp,{displayName:"Schema"});var Ts=class{constructor(){this.#t=new jr,this.#e=null,this.setCtx=e=>{this.#e=e},this.chain=()=>{if(this.#e==null)throw Qi();let e=this.#e,t=[],r=this.get.bind(this),i={run:()=>{let s=dn(...t),l=e.get(rt);return s(l.state,l.dispatch,l)},inline:s=>(t.push(s),i),pipe:o.bind(this)};function o(s,l){let a=r(s);return t.push(a(l)),i}return i}}#t;#e;get ctx(){return this.#e}create(e,t){let r=e.create(this.#t.sliceMap);return r.set(t),r}get(e){return this.#t.get(e).get()}remove(e){return this.#t.remove(e)}call(e,t){if(this.#e==null)throw Qi();let i=this.get(e)(t),o=this.#e.get(rt);return i(o.state,o.dispatch,o)}inline(e){if(this.#e==null)throw Qi();let t=this.#e.get(rt);return e(t.state,t.dispatch,t)}};function _p(n="cmdKey"){return $((()=>()=>!1),n)}var G=$(new Ts,"commands"),ps=$([ve],"commandsTimer"),Sr=He("CommandsReady"),Vp=n=>{let e=new Ts;return e.setCtx(n),n.inject(G,e).inject(ps,[ve]).record(Sr),async()=>(await n.waitTimers(ps),n.done(Sr),()=>{n.remove(G).remove(ps).clearTimer(Sr)})};Et(Vp,{displayName:"Commands"});function Xw(n){let e=dn(hd,go,Af,vl);return n.Backspace=e,n}var Os=class{constructor(){this.#t=null,this.#e=[],this.setCtx=e=>{this.#t=e},this.add=e=>(this.#e.push(e),()=>{this.#e=this.#e.filter(t=>t!==e)}),this.addObjectKeymap=e=>{let t=[];return Object.entries(e).forEach(([r,i])=>{if(typeof i=="function"){let o={key:r,onRun:()=>i};this.#e.push(o),t.push(()=>{this.#e=this.#e.filter(s=>s!==o)})}else this.#e.push(i),t.push(()=>{this.#e=this.#e.filter(o=>o!==i)})}),()=>{t.forEach(r=>r())}},this.addBaseKeymap=()=>{let e=Xw(Lf);return this.addObjectKeymap(e)},this.build=()=>{let e={};return this.#e.forEach(r=>{e[r.key]=[...e[r.key]||[],r]}),Object.fromEntries(Object.entries(e).map(([r,i])=>{let o=i.sort((l,a)=>(a.priority??50)-(l.priority??50));return[r,(l,a,c)=>{let u=this.#t;if(u==null)throw Kn();let f=o.map(h=>h.onRun(u));return dn(...f)(l,a,c)}]}))}}#t;#e;get ctx(){return this.#t}},Pi=$(new Os,"keymap"),ac=$([ve],"keymapTimer"),Cr=He("KeymapReady"),Zw=n=>{let e=new Os;return e.setCtx(n),n.inject(Pi,e).inject(ac,[ve]).record(Cr),async()=>(await n.waitTimers(ac),n.done(Cr),()=>{n.remove(Pi).remove(ac).clearTimer(Cr)})},ms=He("ParserReady"),$p=(()=>{throw Kn()}),vi=$($p,"parser"),cc=$([],"parserTimer"),Wp=n=>(n.inject(vi,$p).inject(cc,[ve]).record(ms),async()=>{await n.waitTimers(cc);let e=n.get(An),t=n.get(Ot);return n.set(vi,ud.create(t,e)),n.done(ms),()=>{n.remove(vi).remove(cc).clearTimer(ms)}});Et(Wp,{displayName:"Parser"});var Mr=He("SerializerReady"),uc=$([],"serializerTimer"),jp=(()=>{throw Kn()}),Rn=$(jp,"serializer"),Hp=n=>(n.inject(Rn,jp).inject(uc,[ve]).record(Mr),async()=>{await n.waitTimers(uc);let e=n.get(An),t=n.get(Ot);return n.set(Rn,fd.create(t,e)),n.done(Mr),()=>{n.remove(Rn).remove(uc).clearTimer(Mr)}});Et(Hp,{displayName:"Serializer"});var gs=$("","defaultValue"),ys=$(n=>n,"stateOptions"),xs=$([],"editorStateTimer"),ks=He("EditorStateReady");function e0(n,e,t){if(typeof n=="string")return e(n);if(n.type==="html")return on.fromSchema(t).parse(n.dom);if(n.type==="json")return Ae.fromJSON(t,n.value);throw Iu(n)}var t0=new re("MILKDOWN_STATE_TRACKER"),qp=n=>(n.inject(gs,"").inject(Ri,{}).inject(ys,e=>e).inject(xs,[ms,Mr,Sr,Cr]).record(ks),async()=>{await n.waitTimers(xs);let e=n.get(Ot),t=n.get(vi),r=n.get(Nr),i=n.get(ys),o=n.get(it),s=n.get(gs),l=e0(s,t,e),a=n.get(Pi),c=a.addBaseKeymap(),u=[...o,new ne({key:t0,state:{init:()=>{},apply:(h,p,m,k)=>{n.set(Ri,k)}}}),kd({rules:r}),Md(a.build())];n.set(it,u);let f=i({schema:e,doc:l,plugins:u}),d=mo.create(f);return n.set(Ri,d),n.done(ks),()=>{c(),n.remove(gs).remove(Ri).remove(ys).remove(xs).clearTimer(ks)}});Et(qp,{displayName:"EditorState"});var Es=$([],"pasteRule"),bs=$([ve],"pasteRuleTimer"),ws=He("PasteRuleReady"),Kp=n=>(n.inject(Es,[]).inject(bs,[ve]).record(ws),async()=>(await n.waitTimers(bs),n.done(ws),()=>{n.remove(Es).remove(bs).clearTimer(ws)}));Et(Kp,{displayName:"PasteRule"});var Di=He("EditorViewReady"),Ss=$([],"editorViewTimer"),Cs=$({},"editorViewOptions"),Ms=$(null,"root"),fc=$(null,"rootDOM"),hc=$({},"rootAttrs");function n0(n,e){let t=document.createElement("div");t.className="milkdown",n.appendChild(t),e.set(fc,t);let r=e.get(hc);return Object.entries(r).forEach(([i,o])=>t.setAttribute(i,o)),t}function r0(n){n.classList.add("editor"),n.setAttribute("role","textbox")}var i0=new re("MILKDOWN_VIEW_CLEAR"),Up=n=>(n.inject(Ms,document.body).inject(rt,{}).inject(Cs,{}).inject(fc,null).inject(hc,{}).inject(Ss,[ks,ws]).record(Di),async()=>{await n.wait(Tt);let e=n.get(Ms)||document.body,t=typeof e=="string"?document.querySelector(e):e;n.update(it,a=>[new ne({key:i0,view:c=>{let u=t?n0(t,n):void 0;return(()=>{if(u&&t){let d=c.dom;t.replaceChild(u,d),u.appendChild(d)}})(),{destroy:()=>{u?.parentNode&&u?.parentNode.replaceChild(c.dom,u),u?.remove()}}}}),...a]),await n.waitTimers(Ss);let r=n.get(Ri),i=n.get(Cs),o=Object.fromEntries(n.get(Ns)),s=Object.fromEntries(n.get(Is)),l=new Oi(t,{state:r,nodeViews:o,markViews:s,transformPasted:(a,c,u)=>(n.get(Es).sort((f,d)=>(d.priority??50)-(f.priority??50)).map(f=>f.run).forEach(f=>{a=f(a,c,u)}),a),...i});return r0(l.dom),n.set(rt,l),n.done(Di),()=>{l?.destroy(),n.remove(Ms).remove(rt).remove(Cs).remove(fc).remove(hc).remove(Ss).clearTimer(Di)}});Et(Up,{displayName:"EditorView"});var dc=class n{constructor(){this.#t=!1,this.#e="Idle",this.#r=[],this.#n=()=>{},this.#s=new jr,this.#o=new Zi,this.#i=new Map,this.#l=new Map,this.#a=new Xi(this.#s,this.#o),this.#h=()=>{let e=Yw(async r=>{await Promise.all(this.#r.map(i=>Promise.resolve(i(r))))}),t=[Fp,Wp,Hp,Vp,Zw,Kp,qp,Up,Qw(this),e];this.#c(t,this.#l)},this.#c=(e,t)=>{e.forEach(r=>{let i=this.#a.produce(this.#t?r.meta:void 0),o=r(i);t.set(r,{ctx:i,handler:o,cleanup:void 0})})},this.#u=(e,t=!1)=>Promise.all([e].flat().map(async r=>{let o=this.#i.get(r)?.cleanup;return t?this.#i.delete(r):this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof o=="function"?o():o})),this.#d=async()=>{await Promise.all([...this.#l.entries()].map(async([e,{cleanup:t}])=>typeof t=="function"?t():t)),this.#l.clear()},this.#f=e=>{this.#e=e,this.#n(e)},this.#p=e=>[...e.entries()].map(async([t,r])=>{let{ctx:i,handler:o}=r;if(!o)return;let s=await o();e.set(t,{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(t=>t!==e),this),this.use=e=>{let t=[e].flat();return t.flat().forEach(r=>{this.#i.set(r,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(t,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(t=>{setTimeout(()=>{t(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.#h(),this.#c([...this.#i.keys()],this.#i),await Promise.all([this.#p(this.#l),this.#p(this.#i)].flat()),this.#f("Created"),this),this.destroy=async(e=!1)=>this.#e==="Destroyed"||this.#e==="OnDestroy"?this:this.#e==="OnCreate"?new Promise(t=>{setTimeout(()=>{t(this.destroy(e))},50)}):(e&&(this.#r=[]),this.#f("OnDestroy"),await this.#u([...this.#i.keys()],e),await this.#d(),this.#f("Destroyed"),this),this.action=e=>e(this.#a),this.inspect=()=>this.#t?[...this.#l.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 n}#t;#e;#r;#n;#s;#o;#i;#l;#a;#h;#c;#u;#d;#f;#p;get ctx(){return this.#a}get status(){return this.#e}};var o0=n=>crypto.getRandomValues(new Uint8Array(n)),s0=(n,e,t)=>{let r=(2<<Math.log2(n.length-1))-1,i=-~(1.6*r*e/n.length);return(o=e)=>{let s="";for(;;){let l=t(i),a=i|0;for(;a--;)if(s+=n[l[a]&r]||"",s.length>=o)return s}}},Jp=(n,e=21)=>s0(n,e|0,o0);var KE=Jp("abcedfghicklmn",10);function J(n,e){let t=_p(n),r=i=>async()=>{r.key=t,await i.wait(Sr);let o=e(i);return i.get(G).create(t,o),r.run=s=>i.get(G).call(n,s),()=>{i.get(G).remove(t)}};return r}function Ge(n){let e=t=>async()=>{await t.wait(ve);let r=n(t);return t.update(Nr,i=>[...i,r]),e.inputRule=r,()=>{t.update(Nr,i=>i.filter(o=>o!==r))}};return e}function l0(n,e){let t=r=>async()=>{let i=e(r);return r.update(wr,o=>[...o.filter(s=>s[0]!==n),[n,i]]),t.id=n,t.schema=i,()=>{r.update(wr,o=>o.filter(([s])=>s!==n))}};return t.type=r=>{let i=r.get(Ot).marks[n];if(!i)throw Du(n);return i},t}function As(n,e){let t=r=>async()=>{let i=e(r);return r.update(br,o=>[...o.filter(s=>s[0]!==n),[n,i]]),t.id=n,t.schema=i,()=>{r.update(br,o=>o.filter(([s])=>s!==n))}};return t.type=r=>{let i=r.get(Ot).nodes[n];if(!i)throw vu(n);return i},t}function ut(n){let e,t=r=>async()=>(await r.wait(ve),e=n(r),r.update(it,i=>[...i,e]),()=>{r.update(it,i=>i.filter(o=>o!==e))});return t.plugin=()=>e,t.key=()=>e.spec.key,t}function a0(n){let e=t=>async()=>{await t.wait(Cr);let r=t.get(Pi),i=n(t),o=r.addObjectKeymap(i);return e.keymap=i,()=>{o()}};return e}function $e(n,e){let t=$(n,e),r=i=>(i.inject(t),()=>()=>{i.remove(t)});return r.key=t,r}function We(n,e){let t=$e(e,n),r=As(n,o=>o.get(t.key)(o)),i=[t,r];return i.id=r.id,i.node=r,i.type=o=>r.type(o),i.ctx=t,i.key=t.key,i.extendSchema=o=>{let s=o(e);return We(n,s)},i}function Tr(n,e){let t=$e(e,n),r=l0(n,o=>o.get(t.key)(o)),i=[t,r];return i.id=r.id,i.mark=r,i.type=o=>r.type(o),i.ctx=t,i.key=t.key,i.extendSchema=o=>{let s=o(e);return Tr(n,s)},i}function De(n,e){let t=Object.fromEntries(Object.entries(e).map(([s,{shortcuts:l,priority:a}])=>[s,{shortcuts:l,priority:a}])),r=$e(t,`${n}Keymap`),i=a0(s=>{let l=s.get(r.key),a=Object.entries(e).flatMap(([c,{command:u}])=>{let f=l[c],d=[f.shortcuts].flat(),h=f.priority;return d.map(p=>[p,{key:p,onRun:u,priority:h}])});return Object.fromEntries(a)}),o=[r,i];return o.ctx=r,o.shortcuts=i,o.key=r.key,o.keymap=i.keymap,o}var Ye=(n,e=()=>({}))=>$e(e,`${n}Attr`),Li=(n,e=()=>({}))=>$e(e,`${n}Attr`);function vn(n,e,t){let r=$e(t??{},n),i=s=>async()=>{await s.wait(Tt);let a={plugin:e(s),options:s.get(r.key)};return s.update(Ir,c=>[...c,a]),()=>{s.update(Ir,c=>c.filter(u=>u!==a))}},o=[r,i];return o.id=n,o.plugin=i,o.options=r,o}function c0(n,e){return t=>t.get(G).call(n,e)}function Gp(n,e){return function(t,r){let{$from:i,$to:o,node:s}=t.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(o))return!1;let l=i.node(-1);if(l.type!=n)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=n||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 x=i.depth-d;x>=i.depth-3;x--)f=M.from(i.node(x).copy(f));let h=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(M.from(n.createAndFill()));let p=i.before(i.depth-(d-1)),m=t.tr.replace(p,i.after(-h),new O(f,4-d,0)),k=-1;m.doc.nodesBetween(p,m.doc.content.size,(x,I)=>{if(k>-1)return!1;x.isTextblock&&x.content.size==0&&(k=I+1)}),k>-1&&m.setSelection(W.near(m.doc.resolve(k))),r(m.scrollIntoView())}return!0}let a=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,o.pos),u=a?[e?{type:n,attrs:e}:null,{type:a}]:void 0;return un(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function Yp(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?u0(e,t,n,o):f0(e,t,o):!0:!1}}function u0(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(i.step(new he(o-1,s,o,s,new O(M.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new Kr(i.doc.resolve(r.$from.pos),i.doc.resolve(s),r.depth));let l=Yn(r);if(l==null)return!1;i.lift(r,l);let a=i.doc.resolve(i.mapping.map(o,-1)-1);return fn(i.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&i.join(a.pos),e(i.scrollIntoView()),!0}function f0(n,e,t){let r=n.tr,i=t.parent;for(let h=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)h-=i.child(p).nodeSize,r.delete(h-1,h+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(l?0:1),u+1,s.content.append(a?M.empty:M.from(i))))return!1;let f=o.pos,d=f+s.nodeSize;return r.step(new he(f-(l?1:0),d+(a?1:0),f+1,d-1,new O((l?M.empty:M.from(i.copy(M.empty))).append(a?M.empty:M.from(i.copy(M.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function Qp(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,a=l.child(s-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,u=M.from(c?n.create():null),f=new O(M.from(n.create(null,M.from(l.type.create(null,u)))),c?3:1,0),d=o.start,h=o.end;t(e.tr.step(new he(d-(c?3:1),h,d,h,f,1,!0)).scrollIntoView())}return!0}}function pc(n){let e=new Map;if(!n||!n.type)throw new Error("mdast-util-definitions expected node");return et(n,"definition",function(r){let i=Xp(r.identifier);i&&!e.get(i)&&e.set(i,r)}),t;function t(r){let i=Xp(r);return e.get(i)}}function Xp(n){return String(n||"").toUpperCase()}function Rs(){return function(n){let e=pc(n);et(n,function(t,r,i){if(t.type==="definition"&&i!==void 0&&typeof r=="number")return i.children.splice(r,1),[kn,r];if(t.type==="imageReference"||t.type==="linkReference"){let o=e(t.identifier);if(o&&i&&typeof r=="number")return i.children[r]=t.type==="imageReference"?{type:"image",url:o.url,title:o.title,alt:t.alt}:{type:"link",url:o.url,title:o.title,children:t.children},[kn,r]}})}}function Zp(n,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){n.next(e.content);return}let r=[];e.content.forEach((i,o,s)=>{s!==e.childCount-1&&r.push(i)}),n.next(M.fromArray(r))}function w(n,e){return Object.assign(n,{meta:{package:"@milkdown/preset-commonmark",...e}}),n}var mc=Li("emphasis");w(mc,{displayName:"Attr<emphasis>",group:"Emphasis"});var Er=Tr("emphasis",n=>({attrs:{marker:{default:n.get(kr).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",n.get(mc.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,t,r)=>{e.openMark(r,{marker:t.marker}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,t)=>{e.withMark(t,"emphasis",void 0,{marker:t.attrs.marker})}}}));w(Er.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});w(Er.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Ds=J("ToggleEmphasis",n=>()=>xo(Er.type(n)));w(Ds,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var em=Ge(n=>wi(/(?:^|[^*])\*([^*]+)\*$/,Er.type(n),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:t+1}}));w(em,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var tm=Ge(n=>wi(/\b_(?![_\s])(.*?[^_\s])_\b/,Er.type(n),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:t+1}}));w(tm,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var gc=De("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:n=>{let e=n.get(G);return()=>e.call(Ds.key)}}});w(gc.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});w(gc.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var yc=Li("strong");w(yc,{displayName:"Attr<strong>",group:"Strong"});var Bi=Tr("strong",n=>({attrs:{marker:{default:n.get(kr).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",n.get(yc.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,t,r)=>{e.openMark(r,{marker:t.marker}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,t)=>{e.withMark(t,"strong",void 0,{marker:t.attrs.marker})}}}));w(Bi.mark,{displayName:"MarkSchema<strong>",group:"Strong"});w(Bi.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var Ps=J("ToggleStrong",n=>()=>xo(Bi.type(n)));w(Ps,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var nm=Ge(n=>wi(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),Bi.type(n),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));w(nm,{displayName:"InputRule<strong>",group:"Strong"});var xc=De("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:n=>{let e=n.get(G);return()=>e.call(Ps.key)}}});w(xc.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});w(xc.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var kc=Li("inlineCode");w(kc,{displayName:"Attr<inlineCode>",group:"InlineCode"});var Jt=Tr("inlineCode",n=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",n.get(kc.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,t,r)=>{e.openMark(r),e.addText(t.value),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,t,r)=>{e.withMark(t,"inlineCode",r.text||"")}}}));w(Jt.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});w(Jt.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var bc=J("ToggleInlineCode",n=>()=>(e,t)=>{let{selection:r,tr:i}=e;if(r.empty)return!1;let{from:o,to:s}=r;return e.doc.rangeHasMark(o,s,Jt.type(n))?(t?.(i.removeMark(o,s,Jt.type(n))),!0):(Object.keys(e.schema.marks).filter(c=>c!==Jt.type.name).map(c=>e.schema.marks[c]).forEach(c=>{i.removeMark(o,s,c)}),t?.(i.addMark(o,s,Jt.type(n).create())),!0)});w(bc,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var rm=Ge(n=>wi(/(?:`)([^`]+)(?:`)$/,Jt.type(n)));w(rm,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var wc=De("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:n=>{let e=n.get(G);return()=>e.call(bc.key)}}});w(wc.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});w(wc.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var Sc=Li("link");w(Sc,{displayName:"Attr<link>",group:"Link"});var Or=Tr("link",n=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Lt(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...n.get(Sc.key)(e),...e.attrs}],parseMarkdown:{match:e=>e.type==="link",runner:(e,t,r)=>{let i=t.url,o=t.title;e.openMark(r,{href:i,title:o}),e.next(t.children),e.closeMark(r)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,t)=>{e.withMark(t,"link",void 0,{title:t.attrs.title,url:t.attrs.href})}}}));w(Or.mark,{displayName:"MarkSchema<link>",group:"Link"});var im=J("ToggleLink",n=>(e={})=>xo(Or.type(n),e));w(im,{displayName:"Command<toggleLinkCommand>",group:"Link"});var om=J("UpdateLink",n=>(e={})=>(t,r)=>{if(!r)return!1;let i,o=-1,{selection:s}=t,{from:l,to:a}=s;if(t.doc.nodesBetween(l,l===a?a+1:a,(p,m)=>{if(Or.type(n).isInSet(p.marks))return i=p,o=m,!1}),!i)return!1;let c=i.marks.find(({type:p})=>p===Or.type(n));if(!c)return!1;let u=o,f=o+i.nodeSize,{tr:d}=t,h=Or.type(n).create({...c.attrs,...e});return h?(r(d.removeMark(u,f,c).addMark(u,f,h).setSelection(new j(d.selection.$anchor)).scrollIntoView()),!0):!1});w(om,{displayName:"Command<updateLinkCommand>",group:"Link"});var sm=As("doc",()=>({content:"block+",parseMarkdown:{match:({type:n})=>n==="root",runner:(n,e,t)=>{n.injectRoot(e,t)}},toMarkdown:{match:n=>n.type.name==="doc",runner:(n,e)=>{n.openNode("root"),n.next(e.content)}}}));w(sm,{displayName:"NodeSchema<doc>",group:"Doc"});function h0(n){return ci(n,e=>e.type==="html"&&["<br />","<br>","<br >","<br/>"].includes(e.value?.trim()),(e,t)=>{if(!t.length)return;let r=t[t.length-1];if(!r)return;let i=r.children.indexOf(e);i!==-1&&r.children.splice(i,1)},!0)}var Ls=vn("remark-preserve-empty-line",()=>()=>h0);w(Ls.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});w(Ls.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Cc=Ye("paragraph");w(Cc,{displayName:"Attr<paragraph>",group:"Paragraph"});var Pn=We("paragraph",n=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",n.get(Cc.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,t,r)=>{e.openNode(r),t.children?e.next(t.children):e.addText(t.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,t)=>{let i=n.get(rt).state?.doc.lastChild;e.openNode("paragraph"),(!t.content||t.content.size===0)&&t!==i&&d0(n)?e.addNode("html",void 0,"<br />"):Zp(e,t),e.closeNode()}}}));function d0(n){let e=!1;try{n.get(Ls.id),e=!0}catch{e=!1}return e}w(Pn.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});w(Pn.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var Bs=J("TurnIntoText",n=>()=>er(Pn.type(n)));w(Bs,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Mc=De("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:n=>{let e=n.get(G);return()=>e.call(Bs.key)}}});w(Mc.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});w(Mc.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var p0=Array(6).fill(0).map((n,e)=>e+1);function m0(n){return n.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var zs=$e(m0,"headingIdGenerator");w(zs,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Nc=Ye("heading");w(Nc,{displayName:"Attr<heading>",group:"Heading"});var Ln=We("heading",n=>{let e=n.get(zs.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:p0.map(t=>({tag:`h${t}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw Lt(r);return{level:t,id:r.id}}})),toDOM:t=>[`h${t.attrs.level}`,{...n.get(Nc.key)(t),id:t.attrs.id||e(t)},0],parseMarkdown:{match:({type:t})=>t==="heading",runner:(t,r,i)=>{let o=r.depth;t.openNode(i,{level:o}),t.next(r.children),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="heading",runner:(t,r)=>{t.openNode("heading",void 0,{depth:r.attrs.level}),Zp(t,r),t.closeNode()}}}});w(Ln.node,{displayName:"NodeSchema<heading>",group:"Heading"});w(Ln.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var lm=Ge(n=>Ma(/^(?<hashes>#+)\s$/,Ln.type(n),e=>{let t=e.groups?.hashes?.length||0,r=n.get(rt),{$from:i}=r.state.selection,o=i.node();if(o.type.name==="heading"){let s=Number(o.attrs.level)+Number(t);return s>6&&(s=6),{level:s}}return{level:t}}));w(lm,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var At=J("WrapInHeading",n=>e=>(e??=1,e<1?er(Pn.type(n)):er(Ln.type(n),{level:e})));w(At,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Ic=J("DowngradeHeading",n=>()=>(e,t,r)=>{let{$from:i}=e.selection,o=i.node();if(o.type!==Ln.type(n)||!e.selection.empty||i.parentOffset!==0)return!1;let s=o.attrs.level-1;return s?(t?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...o.attrs,level:s})),!0):er(Pn.type(n))(e,t,r)});w(Ic,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var Tc=De("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:n=>{let e=n.get(G);return()=>e.call(At.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:n=>{let e=n.get(G);return()=>e.call(At.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:n=>{let e=n.get(G);return()=>e.call(At.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:n=>{let e=n.get(G);return()=>e.call(At.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:n=>{let e=n.get(G);return()=>e.call(At.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:n=>{let e=n.get(G);return()=>e.call(At.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:n=>{let e=n.get(G);return()=>e.call(Ic.key)}}});w(Tc.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});w(Tc.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Oc=Ye("blockquote");w(Oc,{displayName:"Attr<blockquote>",group:"Blockquote"});var zi=We("blockquote",n=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",n.get(Oc.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,t,r)=>{e.openNode(r).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,t)=>{e.openNode("blockquote").next(t.content).closeNode()}}}));w(zi.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});w(zi.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var am=Ge(n=>Yo(/^\s*>\s$/,zi.type(n)));w(am,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Fs=J("WrapInBlockquote",n=>()=>yo(zi.type(n)));w(Fs,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Ec=De("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:n=>{let e=n.get(G);return()=>e.call(Fs.key)}}});w(Ec.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});w(Ec.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var Ac=Ye("codeBlock",()=>({pre:{},code:{}}));w(Ac,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var Fi=We("code_block",n=>({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 Lt(e);return{language:e.dataset.language}}}],toDOM:e=>{let t=n.get(Ac.key)(e),r=e.attrs.language,i=r&&r.length>0?{"data-language":r}:void 0;return["pre",{...t.pre,...i},["code",t.code,0]]},parseMarkdown:{match:({type:e})=>e==="code",runner:(e,t,r)=>{let i=t.lang??"",o=t.value;e.openNode(r,{language:i}),o&&e.addText(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,t)=>{e.addNode("code",void 0,t.content.firstChild?.text||"",{lang:t.attrs.language})}}}));w(Fi.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});w(Fi.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var cm=Ge(n=>Ma(/^```(?<language>[a-z]*)?[\s\n]$/,Fi.type(n),e=>({language:e.groups?.language??""})));w(cm,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Rc=J("CreateCodeBlock",n=>(e="")=>er(Fi.type(n),{language:e}));w(Rc,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var g0=J("UpdateCodeBlockLanguage",()=>({pos:n,language:e}={pos:-1,language:""})=>(t,r)=>n>=0?(r?.(t.tr.setNodeAttribute(n,"language",e)),!0):!1);w(g0,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var vc=De("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:n=>{let e=n.get(G);return()=>e.call(Rc.key)}}});w(vc.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});w(vc.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Dc=Ye("image");w(Dc,{displayName:"Attr<image>",group:"Image"});var Ar=We("image",n=>({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 Lt(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...n.get(Dc.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,t,r)=>{let i=t.url,o=t.alt,s=t.title;e.addNode(r,{src:i,alt:o,title:s})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,t)=>{e.addNode("image",void 0,void 0,{title:t.attrs.title,url:t.attrs.src,alt:t.attrs.alt})}}}));w(Ar.node,{displayName:"NodeSchema<image>",group:"Image"});w(Ar.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var um=J("InsertImage",n=>(e={})=>(t,r)=>{if(!r)return!0;let{src:i="",alt:o="",title:s=""}=e,l=Ar.type(n).create({src:i,alt:o,title:s});return l&&r(t.tr.replaceSelectionWith(l).scrollIntoView()),!0});w(um,{displayName:"Command<insertImageCommand>",group:"Image"});var fm=J("UpdateImage",n=>(e={})=>(t,r)=>{let i=wd(t.selection,Ar.type(n));if(!i)return!1;let{node:o,pos:s}=i,l={...o.attrs},{src:a,alt:c,title:u}=e;return a!==void 0&&(l.src=a),c!==void 0&&(l.alt=c),u!==void 0&&(l.title=u),r?.(t.tr.setNodeMarkup(s,void 0,l).scrollIntoView()),!0});w(fm,{displayName:"Command<updateImageCommand>",group:"Image"});var y0=Ge(n=>new Ne(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,t,r,i)=>{let[o,s,l="",a]=t;return o?e.tr.replaceWith(r,i,Ar.type(n).create({src:l,alt:s,title:a})):null}));w(y0,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var vs=Ye("hardbreak",n=>({"data-type":"hardbreak","data-is-inline":n.attrs.isInline}));w(vs,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Dn=We("hardbreak",n=>({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",n.get(vs.key)(e)," "]:["br",n.get(vs.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,t,r)=>{e.addNode(r,{isInline:!!t.data?.isInline})}},leafText:()=>` 45 45 `,toMarkdown:{match:e=>e.type.name==="hardbreak",runner:(e,t)=>{t.attrs.isInline?e.addNode("text",void 0,` 46 - `):e.addNode("break")}}}));w(Dn.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});w(Dn.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Pc=J("InsertHardbreak",n=>()=>(e,t)=>{let{selection:r,tr:i}=e;if(!(r instanceof j))return!1;if(r.empty){let o=r.$from.node();if(o.childCount>0&&o.lastChild?.type.name==="hardbreak")return t?.(i.replaceRangeWith(r.to-1,r.to,e.schema.node("paragraph")).setSelection(W.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return t?.(i.setMeta("hardbreak",!0).replaceSelectionWith(Dn.type(n).create()).scrollIntoView()),!0});w(Pc,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Lc=De("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:n=>{let e=n.get(G);return()=>e.call(Pc.key)}}});w(Lc.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});w(Lc.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Bc=Ye("hr");w(Bc,{displayName:"Attr<hr>",group:"Hr"});var _i=We("hr",n=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",n.get(Bc.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,t,r)=>{e.addNode(r)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));w(_i.node,{displayName:"NodeSchema<hr>",group:"Hr"});w(_i.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var hm=Ge(n=>new Ne(/^(?:---|___\s|\*\*\*\s)$/,(e,t,r,i)=>{let{tr:o}=e;return t[0]&&o.replaceWith(r-1,i,_i.type(n).create()),o}));w(hm,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var dm=J("InsertHr",n=>()=>(e,t)=>{if(!t)return!0;let r=Pn.node.type(n).create(),{tr:i,selection:o}=e,{from:s}=o,l=_i.type(n).create();if(!l)return!0;let a=i.replaceSelectionWith(l).insert(s,r),c=W.findFrom(a.doc.resolve(s),1,!0);return c&&t(a.setSelection(c).scrollIntoView()),!0});w(dm,{displayName:"Command<insertHrCommand>",group:"Hr"});var zc=Ye("bulletList");w(zc,{displayName:"Attr<bulletList>",group:"BulletList"});var Rr=We("bullet_list",n=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Lt(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...n.get(zc.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!t,runner:(e,t,r)=>{let i=t.spread!=null?`${t.spread}`:"false";e.openNode(r,{spread:i}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!1,spread:t.attrs.spread}).next(t.content).closeNode()}}}));w(Rr.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});w(Rr.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var pm=Ge(n=>Yo(/^\s*([-+*])\s$/,Rr.type(n)));w(pm,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var _s=J("WrapInBulletList",n=>()=>yo(Rr.type(n)));w(_s,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Fc=De("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:n=>{let e=n.get(G);return()=>e.call(_s.key)}}});w(Fc.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});w(Fc.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var _c=Ye("orderedList");w(_c,{displayName:"Attr<orderedList>",group:"OrderedList"});var vr=We("ordered_list",n=>({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 Lt(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...n.get(_c.key)(e),...e.attrs.order===1?{}:e.attrs.order,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!!t,runner:(e,t,r)=>{let i=t.spread!=null?`${t.spread}`:"true";e.openNode(r,{spread:i}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!0,start:1,spread:t.attrs.spread==="true"}),e.next(t.content),e.closeNode()}}}));w(vr.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});w(vr.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var mm=Ge(n=>Yo(/^\s*(\d+)\.\s$/,vr.type(n),e=>({order:Number(e[1])}),(e,t)=>t.childCount+t.attrs.order===Number(e[1])));w(mm,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Vc=J("WrapInOrderedList",n=>()=>yo(vr.type(n)));w(Vc,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var $c=De("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:n=>{let e=n.get(G);return()=>e.call(Vc.key)}}});w($c.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});w($c.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Wc=Ye("listItem");w(Wc,{displayName:"Attr<listItem>",group:"ListItem"});var Gt=We("list_item",n=>({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 Lt(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...n.get(Wc.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,t,r)=>{let i=t.label!=null?`${t.label}.`:"\u2022",o=t.label!=null?"ordered":"bullet",s=t.spread!=null?`${t.spread}`:"true";e.openNode(r,{label:i,listType:o,spread:s}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,t)=>{e.openNode("listItem",void 0,{spread:t.attrs.spread}),e.next(t.content),e.closeNode()}}}));w(Gt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});w(Gt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var jc=J("SinkListItem",n=>()=>Qp(Gt.type(n)));w(jc,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Hc=J("LiftListItem",n=>()=>Yp(Gt.type(n)));w(Hc,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var qc=J("SplitListItem",n=>()=>Gp(Gt.type(n)));w(qc,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function x0(n){return(e,t,r)=>{let{selection:i}=e;if(!(i instanceof j))return!1;let{empty:o,$from:s}=i;return!o||s.parentOffset!==0||s.node(-1).type!==Gt.type(n)?!1:Rl(e,t,r)}}var Kc=J("LiftFirstListItem",n=>()=>x0(n));w(Kc,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Uc=De("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:n=>{let e=n.get(G);return()=>e.call(qc.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:n=>{let e=n.get(G);return()=>e.call(jc.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:n=>{let e=n.get(G);return()=>e.call(Hc.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:n=>{let e=n.get(G);return()=>e.call(Kc.key)}}});w(Uc.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});w(Uc.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var gm=As("text",()=>({group:"inline",parseMarkdown:{match:({type:n})=>n==="text",runner:(n,e)=>{n.addText(e.value)}},toMarkdown:{match:n=>n.type.name==="text",runner:(n,e)=>{n.addNode("text",void 0,e.text)}}}));w(gm,{displayName:"NodeSchema<text>",group:"Text"});var Jc=Ye("html");w(Jc,{displayName:"Attr<html>",group:"Html"});var Gc=We("html",n=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{let t=document.createElement("span"),r={...n.get(Jc.key)(e),"data-value":e.attrs.value,"data-type":"html"};return t.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,t,r)=>{e.addNode(r,{value:t.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,t)=>{e.addNode("html",void 0,t.attrs.value)}}}));w(Gc.node,{displayName:"NodeSchema<html>",group:"Html"});w(Gc.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var k0=[sm,Cc,Pn,zs,Nc,Ln,vs,Dn,Oc,zi,Ac,Fi,Bc,_i,Dc,Ar,zc,Rr,_c,vr,Wc,Gt,mc,Er,yc,Bi,kc,Jt,Sc,Or,Jc,Gc,gm].flat(),b0=[am,pm,mm,cm,hm,lm].flat(),w0=[em,tm,rm,nm],S0=J("IsMarkSelected",()=>n=>e=>{if(!n)return!1;let{doc:t,selection:r}=e;return t.rangeHasMark(r.from,r.to,n)}),C0=J("IsNoteSelected",()=>n=>e=>n?Sd(e,n).hasNode:!1),M0=J("ClearTextInCurrentBlock",()=>()=>(n,e)=>{let t=n.tr,{$from:r,$to:i}=t.selection,{pos:o}=r,{pos:s}=i,l=o-r.node().content.size;return l<0?!1:(t=t.deleteRange(l,s),e?.(t),!0)}),N0=J("SetBlockType",()=>n=>(e,t)=>{let{nodeType:r,attrs:i=null}=n??{};if(!r)return!1;let o=e.tr,{from:s,to:l}=o.selection;try{o.setBlockType(s,l,r,i)}catch{return!1}return t?.(o),!0}),I0=J("WrapInBlockType",()=>n=>(e,t)=>{let{nodeType:r,attrs:i=null}=n??{};if(!r)return!1;let o=e.tr;try{let{$from:s,$to:l}=o.selection,a=s.blockRange(l),c=a&&cn(a,r,i);if(!c)return!1;o=o.wrap(a,c)}catch{return!1}return t?.(o),!0}),T0=J("AddBlockType",()=>n=>(e,t)=>{let{nodeType:r,attrs:i=null}=n??{};if(!r)return!1;let o=e.tr;try{let s=r instanceof Ae?r:r.createAndFill(i);if(!s)return!1;o.replaceSelectionWith(s)}catch{return!1}return t?.(o),!0}),O0=J("SelectTextNearPos",()=>n=>(e,t)=>{let{pos:r}=n??{};if(r==null)return!1;let i=(s,l,a)=>Math.min(Math.max(s,l),a),o=e.tr;try{let s=e.doc.resolve(i(r,0,e.doc.content.size));o.setSelection(j.near(s))}catch{return!1}return t?.(o.scrollIntoView()),!0}),E0=[Bs,Fs,At,Ic,Rc,Pc,dm,um,fm,Vc,_s,jc,qc,Hc,Kc,Ds,bc,Ps,im,om,S0,C0,M0,N0,I0,T0,O0],A0=[Ec,vc,Lc,Tc,Uc,$c,Fc,Mc,gc,wc,xc].flat(),Yc=vn("remarkAddOrderInList",()=>()=>n=>{et(n,"list",e=>{if(e.ordered){let t=e.start??1;e.children.forEach((r,i)=>{r.label=i+t})}})});w(Yc.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});w(Yc.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var Qc=vn("remarkLineBreak",()=>()=>n=>{let e=/[\t ]*(?:\r?\n|\r)/g;et(n,"text",(t,r,i)=>{if(!t.value||typeof t.value!="string")return;let o=[],s=0;e.lastIndex=0;let l=e.exec(t.value);for(;l;){let c=l.index;s!==c&&o.push({type:"text",value:t.value.slice(s,c)}),o.push({type:"break",data:{isInline:!0}}),s=c+l[0].length,l=e.exec(t.value)}if(o.length>0&&i&&typeof r=="number")return s<t.value.length&&o.push({type:"text",value:t.value.slice(s)}),i.children.splice(r,1,...o),r+o.length})});w(Qc.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});w(Qc.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var Xc=vn("remarkInlineLink",()=>Rs);w(Xc.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});w(Xc.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var R0=n=>!!n.children,v0=n=>n.type==="html";function D0(n,e){return t(n,0,null)[0];function t(r,i,o){if(R0(r)){let s=[];for(let l=0,a=r.children.length;l<a;l++){let c=r.children[l];if(c){let u=t(c,l,r);if(u)for(let f=0,d=u.length;f<d;f++){let h=u[f];h&&s.push(h)}}}r.children=s}return e(r,i,o)}}var P0=["root","blockquote","listItem"],Zc=vn("remarkHTMLTransformer",()=>()=>n=>{D0(n,(e,t,r)=>v0(e)?(r&&P0.includes(r.type)&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});w(Zc.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});w(Zc.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var eu=vn("remarkMarker",()=>()=>(n,e)=>{let t=r=>e.value.charAt(r.position.start.offset);et(n,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=t(r)})});w(eu.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});w(eu.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var ym=ut(()=>{let n=!1,e=new re("MILKDOWN_INLINE_NODES_CURSOR"),t=new ne({key:e,state:{init(){return!1},apply(r){if(!r.selection.empty)return!1;let i=r.selection.$from,o=i.nodeBefore,s=i.nodeAfter;return!!(o&&s&&o.isInline&&!o.isText&&s.isInline&&!s.isText)}},props:{handleDOMEvents:{compositionend:(r,i)=>n?(n=!1,requestAnimationFrame(()=>{if(t.getState(r.state)){let s=r.state.selection.from;i.preventDefault(),r.dispatch(r.state.tr.insertText(i.data||"",s))}}),!0):!1,compositionstart:r=>(t.getState(r.state)&&(n=!0),!1),beforeinput:(r,i)=>{if(t.getState(r.state)&&i instanceof InputEvent&&i.data&&!n){let s=r.state.selection.from;return i.preventDefault(),r.dispatch(r.state.tr.insertText(i.data||"",s)),!0}return!1}},decorations(r){if(t.getState(r)){let s=r.selection.$from.pos,l=document.createElement("span"),a=nt.widget(s,l,{side:-1}),c=document.createElement("span"),u=nt.widget(s,c);return setTimeout(()=>{l.contentEditable="true",c.contentEditable="true"}),Ie.create(r.doc,[a,u])}return Ie.empty}}});return t});w(ym,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var xm=ut(n=>new ne({key:new re("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,t,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:a}=o;return r.tr.setNodeMarkup(a,Dn.type(n),void 0,[])}if(o instanceof ln){let a=r.tr,{from:c,to:u}=o;return r.doc.nodesBetween(c,u,(f,d)=>{f.type===Dn.type(n)&&(a=a.setNodeMarkup(d,Dn.type(n),void 0,[]))}),a}}}));w(xm,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var tu=$e(["table","code_block"],"hardbreakFilterNodes");w(tu,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var km=ut(n=>{let e=n.get(tu.key);return new ne({key:new re("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(t,r)=>{let i=t.getMeta("hardbreak"),[o]=t.steps;if(i&&o){let{from:s}=o,l=r.doc.resolve(s),a=l.depth,c=!0;for(;a>0;)e.includes(l.node(a).type.name)&&(c=!1),a--;return c}return!0}})});w(km,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var bm=ut(n=>{let e=new re("MILKDOWN_HEADING_ID"),t=r=>{if(r.composing)return;let i=n.get(zs.key),o=r.state.tr.setMeta("addToHistory",!1),s=!1,l={};r.state.doc.descendants((a,c)=>{if(a.type===Ln.type(n)){if(a.textContent.trim().length===0)return;let u=a.attrs,f=i(a);l[f]?(l[f]+=1,f+=`-#${l[f]}`):l[f]=1,u.id!==f&&(s=!0,o.setMeta(e,!0).setNodeMarkup(c,void 0,{...u,id:f}))}}),s&&r.dispatch(o)};return new ne({key:e,view:r=>(t(r),{update:(i,o)=>{i.state.doc.eq(o.doc)||t(i)}})})});w(bm,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var wm=ut(n=>{let e=(t,r,i)=>{if(!i.selection||t.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;let o=vr.type(n),s=Rr.type(n),l=Gt.type(n),a=(f,d)=>{let h=!1,p=`${d+1}.`;return f.label!==p&&(f.label=p,h=!0),h},c=i.tr,u=!1;return i.doc.descendants((f,d,h,p)=>{if(f.type===s){let m=f.maybeChild(0);m?.type===l&&m.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(d,o,{spread:"true"}),f.descendants((k,x,I,C)=>{if(k.type===l){let A={...k.attrs};a(A,C)&&(c=c.setNodeMarkup(x,void 0,A))}return!1}))}else if(f.type===l&&h?.type===o){let m={...f.attrs},k=!1;m.listType!=="ordered"&&(m.listType="ordered",k=!0),h?.maybeChild(0)&&(k=a(m,p)),k&&(c=c.setNodeMarkup(d,void 0,m),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new ne({key:new re("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});w(wm,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var L0=[xm,tu,km,ym,Yc,Xc,Qc,Zc,eu,Ls,bm,wm].flat(),B0=[k0,b0,w0,E0,A0,L0].flat();var z0=typeof global=="object"&&global&&global.Object===Object&&global,Sm=z0;var F0=typeof self=="object"&&self&&self.Object===Object&&self,_0=Sm||F0||Function("return this")(),Vs=_0;var V0=Vs.Symbol,Dr=V0;var Cm=Object.prototype,$0=Cm.hasOwnProperty,W0=Cm.toString,Vi=Dr?Dr.toStringTag:void 0;function j0(n){var e=$0.call(n,Vi),t=n[Vi];try{n[Vi]=void 0;var r=!0}catch{}var i=W0.call(n);return r&&(e?n[Vi]=t:delete n[Vi]),i}var Mm=j0;var H0=Object.prototype,q0=H0.toString;function K0(n){return q0.call(n)}var Nm=K0;var U0="[object Null]",J0="[object Undefined]",Im=Dr?Dr.toStringTag:void 0;function G0(n){return n==null?n===void 0?J0:U0:Im&&Im in Object(n)?Mm(n):Nm(n)}var Tm=G0;function Y0(n){return n!=null&&typeof n=="object"}var Om=Y0;var Q0="[object Symbol]";function X0(n){return typeof n=="symbol"||Om(n)&&Tm(n)==Q0}var Em=X0;var Z0=/\s/;function e1(n){for(var e=n.length;e--&&Z0.test(n.charAt(e)););return e}var Am=e1;var t1=/^\s+/;function n1(n){return n&&n.slice(0,Am(n)+1).replace(t1,"")}var Rm=n1;function r1(n){var e=typeof n;return n!=null&&(e=="object"||e=="function")}var Bn=r1;var vm=NaN,i1=/^[-+]0x[0-9a-f]+$/i,o1=/^0b[01]+$/i,s1=/^0o[0-7]+$/i,l1=parseInt;function a1(n){if(typeof n=="number")return n;if(Em(n))return vm;if(Bn(n)){var e=typeof n.valueOf=="function"?n.valueOf():n;n=Bn(e)?e+"":e}if(typeof n!="string")return n===0?n:+n;n=Rm(n);var t=o1.test(n);return t||s1.test(n)?l1(n.slice(2),t?2:8):i1.test(n)?vm:+n}var nu=a1;var c1=function(){return Vs.Date.now()},$s=c1;var u1="Expected a function",f1=Math.max,h1=Math.min;function d1(n,e,t){var r,i,o,s,l,a,c=0,u=!1,f=!1,d=!0;if(typeof n!="function")throw new TypeError(u1);e=nu(e)||0,Bn(t)&&(u=!!t.leading,f="maxWait"in t,o=f?f1(nu(t.maxWait)||0,e):o,d="trailing"in t?!!t.trailing:d);function h(b){var T=r,P=i;return r=i=void 0,c=b,s=n.apply(P,T),s}function p(b){return c=b,l=setTimeout(x,e),u?h(b):s}function m(b){var T=b-a,P=b-c,D=e-T;return f?h1(D,o-P):D}function k(b){var T=b-a,P=b-c;return a===void 0||T>=e||T<0||f&&P>=o}function x(){var b=$s();if(k(b))return I(b);l=setTimeout(x,m(b))}function I(b){return l=void 0,d&&r?h(b):(r=i=void 0,s)}function C(){l!==void 0&&clearTimeout(l),c=0,r=a=i=l=void 0}function A(){return l===void 0?s:I($s())}function v(){var b=$s(),T=k(b);if(r=arguments,i=this,a=b,T){if(l===void 0)return p(a);if(f)return clearTimeout(l),l=setTimeout(x,e),h(a)}return l===void 0&&(l=setTimeout(x,e)),s}return v.cancel=C,v.flush=A,v}var $i=d1;var p1="Expected a function";function m1(n,e,t){var r=!0,i=!0;if(typeof n!="function")throw new TypeError(p1);return Bn(t)&&(r="leading"in t?!!t.leading:r,i="trailing"in t?!!t.trailing:i),$i(n,e,{leading:r,maxWait:e,trailing:i})}var ru=m1;var Ws=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=e=>(this.beforeMountedListeners.push(e),this),this.mounted=e=>(this.mountedListeners.push(e),this),this.updated=e=>(this.updatedListeners.push(e),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners,selectionUpdated:this.selectionUpdatedListeners}}markdownUpdated(e){return this.markdownUpdatedListeners.push(e),this}blur(e){return this.blurListeners.push(e),this}focus(e){return this.focusListeners.push(e),this}destroy(e){return this.destroyListeners.push(e),this}selectionUpdated(e){return this.selectionUpdatedListeners.push(e),this}},iu=$(new Ws,"listener"),g1=new re("MILKDOWN_LISTENER"),Dm=n=>(n.inject(iu,new Ws),async()=>{await n.wait(Tt);let e=n.get(iu),{listeners:t}=e;t.beforeMount.forEach(a=>a(n)),await n.wait(Mr);let r=n.get(Rn),i=null,o=null,s=null,l=new ne({key:g1,view:()=>({destroy:()=>{t.destroy.forEach(a=>a(n))}}),props:{handleDOMEvents:{focus:()=>(t.focus.forEach(a=>a(n)),!1),blur:()=>(t.blur.forEach(a=>a(n)),!1)}},state:{init:(a,c)=>{i=c.doc,o=r(c.doc)},apply:a=>{let c=a.selection;return(!s&&c||s&&!c.eq(s))&&(t.selectionUpdated.forEach(f=>{f(n,c,s)}),s=c),!(a.docChanged||a.storedMarksSet)||a.getMeta("addToHistory")===!1?void 0:$i(()=>{let{doc:f}=a;if(t.updated.length>0&&i&&!i.eq(f)&&t.updated.forEach(d=>{d(n,f,i)}),t.markdownUpdated.length>0&&i&&!i.eq(f)){let d=r(f);t.markdownUpdated.forEach(h=>{h(n,d,o)}),o=d}i=f},200)()}}});n.update(ct,a=>a.concat(l)),await n.wait(Di),t.mounted.forEach(a=>a(n))});Dm.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var Pr=Math.min,Rt=Math.max,ji=Math.round,Hi=Math.floor,it=n=>({x:n,y:n}),y1={left:"right",right:"left",bottom:"top",top:"bottom"};function ou(n,e,t){return Rt(n,Pr(e,t))}function qi(n,e){return typeof n=="function"?n(e):n}function Yt(n){return n.split("-")[0]}function Ki(n){return n.split("-")[1]}function su(n){return n==="x"?"y":"x"}function lu(n){return n==="y"?"height":"width"}function vt(n){let e=n[0];return e==="t"||e==="b"?"y":"x"}function au(n){return su(vt(n))}function Bm(n,e,t){t===void 0&&(t=!1);let r=Ki(n),i=au(n),o=lu(i),s=i==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(s=Wi(s)),[s,Wi(s)]}function zm(n){let e=Wi(n);return[js(n),e,js(e)]}function js(n){return n.includes("start")?n.replace("start","end"):n.replace("end","start")}var Pm=["left","right"],Lm=["right","left"],x1=["top","bottom"],k1=["bottom","top"];function b1(n,e,t){switch(n){case"top":case"bottom":return t?e?Lm:Pm:e?Pm:Lm;case"left":case"right":return e?x1:k1;default:return[]}}function Fm(n,e,t,r){let i=Ki(n),o=b1(Yt(n),t==="start",r);return i&&(o=o.map(s=>s+"-"+i),e&&(o=o.concat(o.map(js)))),o}function Wi(n){let e=Yt(n);return y1[e]+n.slice(e.length)}function w1(n){return{top:0,right:0,bottom:0,left:0,...n}}function _m(n){return typeof n!="number"?w1(n):{top:n,right:n,bottom:n,left:n}}function zn(n){let{x:e,y:t,width:r,height:i}=n;return{width:r,height:i,top:t,left:e,right:e+r,bottom:t+i,x:e,y:t}}function Vm(n,e,t){let{reference:r,floating:i}=n,o=vt(e),s=au(e),l=lu(s),a=Yt(e),c=o==="y",u=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,d=r[l]/2-i[l]/2,h;switch(a){case"top":h={x:u,y:r.y-i.height};break;case"bottom":h={x:u,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-i.width,y:f};break;default:h={x:r.x,y:r.y}}switch(Ki(e)){case"start":h[s]-=d*(t&&c?-1:1);break;case"end":h[s]+=d*(t&&c?-1:1);break}return h}async function $m(n,e){var t;e===void 0&&(e={});let{x:r,y:i,platform:o,rects:s,elements:l,strategy:a}=n,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:h=0}=qi(e,n),p=_m(h),k=l[d?f==="floating"?"reference":"floating":f],x=zn(await o.getClippingRect({element:(t=await(o.isElement==null?void 0:o.isElement(k)))==null||t?k:k.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:a})),I=f==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,C=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l.floating)),A=await(o.isElement==null?void 0:o.isElement(C))?await(o.getScale==null?void 0:o.getScale(C))||{x:1,y:1}:{x:1,y:1},v=zn(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:I,offsetParent:C,strategy:a}):I);return{top:(x.top-v.top+p.top)/A.y,bottom:(v.bottom-x.bottom+p.bottom)/A.y,left:(x.left-v.left+p.left)/A.x,right:(v.right-x.right+p.right)/A.x}}var S1=50,Wm=async(n,e,t)=>{let{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:s}=t,l=s.detectOverflow?s:{...s,detectOverflow:$m},a=await(s.isRTL==null?void 0:s.isRTL(e)),c=await s.getElementRects({reference:n,floating:e,strategy:i}),{x:u,y:f}=Vm(c,r,a),d=r,h=0,p={};for(let m=0;m<o.length;m++){let k=o[m];if(!k)continue;let{name:x,fn:I}=k,{x:C,y:A,data:v,reset:b}=await I({x:u,y:f,initialPlacement:r,placement:d,strategy:i,middlewareData:p,rects:c,platform:l,elements:{reference:n,floating:e}});u=C??u,f=A??f,p[x]={...p[x],...v},b&&h<S1&&(h++,typeof b=="object"&&(b.placement&&(d=b.placement),b.rects&&(c=b.rects===!0?await s.getElementRects({reference:n,floating:e,strategy:i}):b.rects),{x:u,y:f}=Vm(c,d,a)),m=-1)}return{x:u,y:f,placement:d,strategy:i,middlewareData:p}};var jm=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,r;let{placement:i,middlewareData:o,rects:s,initialPlacement:l,platform:a,elements:c}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:d,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:m=!0,...k}=qi(n,e);if((t=o.arrow)!=null&&t.alignmentOffset)return{};let x=Yt(i),I=vt(l),C=Yt(l)===l,A=await(a.isRTL==null?void 0:a.isRTL(c.floating)),v=d||(C||!m?[Wi(l)]:zm(l)),b=p!=="none";!d&&b&&v.push(...Fm(l,m,p,A));let T=[l,...v],P=await a.detectOverflow(e,k),D=[],U=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&D.push(P[x]),f){let L=Bm(i,s,A);D.push(P[L[0]],P[L[1]])}if(U=[...U,{placement:i,overflows:D}],!D.every(L=>L<=0)){var Se,Y;let L=(((Se=o.flip)==null?void 0:Se.index)||0)+1,F=T[L];if(F&&(!(f==="alignment"?I!==vt(F):!1)||U.every(te=>vt(te.placement)===I?te.overflows[0]>0:!0)))return{data:{index:L,overflows:U},reset:{placement:F}};let Q=(Y=U.filter(X=>X.overflows[0]<=0).sort((X,te)=>X.overflows[1]-te.overflows[1])[0])==null?void 0:Y.placement;if(!Q)switch(h){case"bestFit":{var R;let X=(R=U.filter(te=>{if(b){let le=vt(te.placement);return le===I||le==="y"}return!0}).map(te=>[te.placement,te.overflows.filter(le=>le>0).reduce((le,g)=>le+g,0)]).sort((te,le)=>te[1]-le[1])[0])==null?void 0:R[0];X&&(Q=X);break}case"initialPlacement":Q=l;break}if(i!==Q)return{reset:{placement:Q}}}return{}}}};var C1=new Set(["left","top"]);async function M1(n,e){let{placement:t,platform:r,elements:i}=n,o=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Yt(t),l=Ki(t),a=vt(t)==="y",c=C1.has(s)?-1:1,u=o&&a?-1:1,f=qi(e,n),{mainAxis:d,crossAxis:h,alignmentAxis:p}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&typeof p=="number"&&(h=l==="end"?p*-1:p),a?{x:h*u,y:d*c}:{x:d*c,y:h*u}}var Hm=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,r;let{x:i,y:o,placement:s,middlewareData:l}=e,a=await M1(e,n);return s===((t=l.offset)==null?void 0:t.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+a.x,y:o+a.y,data:{...a,placement:s}}}}},qm=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){let{x:t,y:r,placement:i,platform:o}=e,{mainAxis:s=!0,crossAxis:l=!1,limiter:a={fn:x=>{let{x:I,y:C}=x;return{x:I,y:C}}},...c}=qi(n,e),u={x:t,y:r},f=await o.detectOverflow(e,c),d=vt(Yt(i)),h=su(d),p=u[h],m=u[d];if(s){let x=h==="y"?"top":"left",I=h==="y"?"bottom":"right",C=p+f[x],A=p-f[I];p=ou(C,p,A)}if(l){let x=d==="y"?"top":"left",I=d==="y"?"bottom":"right",C=m+f[x],A=m-f[I];m=ou(C,m,A)}let k=a.fn({...e,[h]:p,[d]:m});return{...k,data:{x:k.x-t,y:k.y-r,enabled:{[h]:s,[d]:l}}}}}};function Hs(){return typeof window<"u"}function _n(n){return Um(n)?(n.nodeName||"").toLowerCase():"#document"}function Pe(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function ot(n){var e;return(e=(Um(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Um(n){return Hs()?n instanceof Node||n instanceof Pe(n).Node:!1}function Qe(n){return Hs()?n instanceof Element||n instanceof Pe(n).Element:!1}function ft(n){return Hs()?n instanceof HTMLElement||n instanceof Pe(n).HTMLElement:!1}function Km(n){return!Hs()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Pe(n).ShadowRoot}function Br(n){let{overflow:e,overflowX:t,overflowY:r,display:i}=Xe(n);return/auto|scroll|overlay|hidden|clip/.test(e+r+t)&&i!=="inline"&&i!=="contents"}function Jm(n){return/^(table|td|th)$/.test(_n(n))}function Ui(n){try{if(n.matches(":popover-open"))return!0}catch{}try{return n.matches(":modal")}catch{return!1}}var N1=/transform|translate|scale|rotate|perspective|filter/,I1=/paint|layout|strict|content/,Fn=n=>!!n&&n!=="none",cu;function qs(n){let e=Qe(n)?Xe(n):n;return Fn(e.transform)||Fn(e.translate)||Fn(e.scale)||Fn(e.rotate)||Fn(e.perspective)||!Ks()&&(Fn(e.backdropFilter)||Fn(e.filter))||N1.test(e.willChange||"")||I1.test(e.contain||"")}function Gm(n){let e=Dt(n);for(;ft(e)&&!Vn(e);){if(qs(e))return e;if(Ui(e))return null;e=Dt(e)}return null}function Ks(){return cu==null&&(cu=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),cu}function Vn(n){return/^(html|body|#document)$/.test(_n(n))}function Xe(n){return Pe(n).getComputedStyle(n)}function Ji(n){return Qe(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function Dt(n){if(_n(n)==="html")return n;let e=n.assignedSlot||n.parentNode||Km(n)&&n.host||ot(n);return Km(e)?e.host:e}function Ym(n){let e=Dt(n);return Vn(e)?n.ownerDocument?n.ownerDocument.body:n.body:ft(e)&&Br(e)?e:Ym(e)}function Lr(n,e,t){var r;e===void 0&&(e=[]),t===void 0&&(t=!0);let i=Ym(n),o=i===((r=n.ownerDocument)==null?void 0:r.body),s=Pe(i);if(o){let l=Us(s);return e.concat(s,s.visualViewport||[],Br(i)?i:[],l&&t?Lr(l):[])}else return e.concat(i,Lr(i,[],t))}function Us(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function eg(n){let e=Xe(n),t=parseFloat(e.width)||0,r=parseFloat(e.height)||0,i=ft(n),o=i?n.offsetWidth:t,s=i?n.offsetHeight:r,l=ji(t)!==o||ji(r)!==s;return l&&(t=o,r=s),{width:t,height:r,$:l}}function fu(n){return Qe(n)?n:n.contextElement}function zr(n){let e=fu(n);if(!ft(e))return it(1);let t=e.getBoundingClientRect(),{width:r,height:i,$:o}=eg(e),s=(o?ji(t.width):t.width)/r,l=(o?ji(t.height):t.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!l||!Number.isFinite(l))&&(l=1),{x:s,y:l}}var T1=it(0);function tg(n){let e=Pe(n);return!Ks()||!e.visualViewport?T1:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function O1(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Pe(n)?!1:e}function $n(n,e,t,r){e===void 0&&(e=!1),t===void 0&&(t=!1);let i=n.getBoundingClientRect(),o=fu(n),s=it(1);e&&(r?Qe(r)&&(s=zr(r)):s=zr(n));let l=O1(o,t,r)?tg(o):it(0),a=(i.left+l.x)/s.x,c=(i.top+l.y)/s.y,u=i.width/s.x,f=i.height/s.y;if(o){let d=Pe(o),h=r&&Qe(r)?Pe(r):r,p=d,m=Us(p);for(;m&&r&&h!==p;){let k=zr(m),x=m.getBoundingClientRect(),I=Xe(m),C=x.left+(m.clientLeft+parseFloat(I.paddingLeft))*k.x,A=x.top+(m.clientTop+parseFloat(I.paddingTop))*k.y;a*=k.x,c*=k.y,u*=k.x,f*=k.y,a+=C,c+=A,p=Pe(m),m=Us(p)}}return zn({width:u,height:f,x:a,y:c})}function Js(n,e){let t=Ji(n).scrollLeft;return e?e.left+t:$n(ot(n)).left+t}function ng(n,e){let t=n.getBoundingClientRect(),r=t.left+e.scrollLeft-Js(n,t),i=t.top+e.scrollTop;return{x:r,y:i}}function E1(n){let{elements:e,rect:t,offsetParent:r,strategy:i}=n,o=i==="fixed",s=ot(r),l=e?Ui(e.floating):!1;if(r===s||l&&o)return t;let a={scrollLeft:0,scrollTop:0},c=it(1),u=it(0),f=ft(r);if((f||!f&&!o)&&((_n(r)!=="body"||Br(s))&&(a=Ji(r)),f)){let h=$n(r);c=zr(r),u.x=h.x+r.clientLeft,u.y=h.y+r.clientTop}let d=s&&!f&&!o?ng(s,a):it(0);return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-a.scrollLeft*c.x+u.x+d.x,y:t.y*c.y-a.scrollTop*c.y+u.y+d.y}}function A1(n){return Array.from(n.getClientRects())}function R1(n){let e=ot(n),t=Ji(n),r=n.ownerDocument.body,i=Rt(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=Rt(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight),s=-t.scrollLeft+Js(n),l=-t.scrollTop;return Xe(r).direction==="rtl"&&(s+=Rt(e.clientWidth,r.clientWidth)-i),{width:i,height:o,x:s,y:l}}var Qm=25;function v1(n,e){let t=Pe(n),r=ot(n),i=t.visualViewport,o=r.clientWidth,s=r.clientHeight,l=0,a=0;if(i){o=i.width,s=i.height;let u=Ks();(!u||u&&e==="fixed")&&(l=i.offsetLeft,a=i.offsetTop)}let c=Js(r);if(c<=0){let u=r.ownerDocument,f=u.body,d=getComputedStyle(f),h=u.compatMode==="CSS1Compat"&&parseFloat(d.marginLeft)+parseFloat(d.marginRight)||0,p=Math.abs(r.clientWidth-f.clientWidth-h);p<=Qm&&(o-=p)}else c<=Qm&&(o+=c);return{width:o,height:s,x:l,y:a}}function D1(n,e){let t=$n(n,!0,e==="fixed"),r=t.top+n.clientTop,i=t.left+n.clientLeft,o=ft(n)?zr(n):it(1),s=n.clientWidth*o.x,l=n.clientHeight*o.y,a=i*o.x,c=r*o.y;return{width:s,height:l,x:a,y:c}}function Xm(n,e,t){let r;if(e==="viewport")r=v1(n,t);else if(e==="document")r=R1(ot(n));else if(Qe(e))r=D1(e,t);else{let i=tg(n);r={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return zn(r)}function rg(n,e){let t=Dt(n);return t===e||!Qe(t)||Vn(t)?!1:Xe(t).position==="fixed"||rg(t,e)}function P1(n,e){let t=e.get(n);if(t)return t;let r=Lr(n,[],!1).filter(l=>Qe(l)&&_n(l)!=="body"),i=null,o=Xe(n).position==="fixed",s=o?Dt(n):n;for(;Qe(s)&&!Vn(s);){let l=Xe(s),a=qs(s);!a&&l.position==="fixed"&&(i=null),(o?!a&&!i:!a&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Br(s)&&!a&&rg(n,s))?r=r.filter(u=>u!==s):i=l,s=Dt(s)}return e.set(n,r),r}function L1(n){let{element:e,boundary:t,rootBoundary:r,strategy:i}=n,s=[...t==="clippingAncestors"?Ui(e)?[]:P1(e,this._c):[].concat(t),r],l=Xm(e,s[0],i),a=l.top,c=l.right,u=l.bottom,f=l.left;for(let d=1;d<s.length;d++){let h=Xm(e,s[d],i);a=Rt(h.top,a),c=Pr(h.right,c),u=Pr(h.bottom,u),f=Rt(h.left,f)}return{width:c-f,height:u-a,x:f,y:a}}function B1(n){let{width:e,height:t}=eg(n);return{width:e,height:t}}function z1(n,e,t){let r=ft(e),i=ot(e),o=t==="fixed",s=$n(n,!0,o,e),l={scrollLeft:0,scrollTop:0},a=it(0);function c(){a.x=Js(i)}if(r||!r&&!o)if((_n(e)!=="body"||Br(i))&&(l=Ji(e)),r){let h=$n(e,!0,o,e);a.x=h.x+e.clientLeft,a.y=h.y+e.clientTop}else i&&c();o&&!r&&i&&c();let u=i&&!r&&!o?ng(i,l):it(0),f=s.left+l.scrollLeft-a.x-u.x,d=s.top+l.scrollTop-a.y-u.y;return{x:f,y:d,width:s.width,height:s.height}}function uu(n){return Xe(n).position==="static"}function Zm(n,e){if(!ft(n)||Xe(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return ot(n)===t&&(t=t.ownerDocument.body),t}function ig(n,e){let t=Pe(n);if(Ui(n))return t;if(!ft(n)){let i=Dt(n);for(;i&&!Vn(i);){if(Qe(i)&&!uu(i))return i;i=Dt(i)}return t}let r=Zm(n,e);for(;r&&Jm(r)&&uu(r);)r=Zm(r,e);return r&&Vn(r)&&uu(r)&&!qs(r)?t:r||Gm(n)||t}var F1=async function(n){let e=this.getOffsetParent||ig,t=this.getDimensions,r=await t(n.floating);return{reference:z1(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function _1(n){return Xe(n).direction==="rtl"}var V1={convertOffsetParentRelativeRectToViewportRelativeRect:E1,getDocumentElement:ot,getClippingRect:L1,getOffsetParent:ig,getElementRects:F1,getClientRects:A1,getDimensions:B1,getScale:zr,isElement:Qe,isRTL:_1};function og(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function $1(n,e){let t=null,r,i=ot(n);function o(){var l;clearTimeout(r),(l=t)==null||l.disconnect(),t=null}function s(l,a){l===void 0&&(l=!1),a===void 0&&(a=1),o();let c=n.getBoundingClientRect(),{left:u,top:f,width:d,height:h}=c;if(l||e(),!d||!h)return;let p=Hi(f),m=Hi(i.clientWidth-(u+d)),k=Hi(i.clientHeight-(f+h)),x=Hi(u),C={rootMargin:-p+"px "+-m+"px "+-k+"px "+-x+"px",threshold:Rt(0,Pr(1,a))||1},A=!0;function v(b){let T=b[0].intersectionRatio;if(T!==a){if(!A)return s();T?s(!1,T):r=setTimeout(()=>{s(!1,1e-7)},1e3)}T===1&&!og(c,n.getBoundingClientRect())&&s(),A=!1}try{t=new IntersectionObserver(v,{...C,root:i.ownerDocument})}catch{t=new IntersectionObserver(v,C)}t.observe(n)}return s(!0),o}function hu(n,e,t,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:o=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:a=!1}=r,c=fu(n),u=i||o?[...c?Lr(c):[],...e?Lr(e):[]]:[];u.forEach(x=>{i&&x.addEventListener("scroll",t,{passive:!0}),o&&x.addEventListener("resize",t)});let f=c&&l?$1(c,t):null,d=-1,h=null;s&&(h=new ResizeObserver(x=>{let[I]=x;I&&I.target===c&&h&&e&&(h.unobserve(e),cancelAnimationFrame(d),d=requestAnimationFrame(()=>{var C;(C=h)==null||C.observe(e)})),t()}),c&&!a&&h.observe(c),e&&h.observe(e));let p,m=a?$n(n):null;a&&k();function k(){let x=$n(n);m&&!og(m,x)&&t(),m=x,p=requestAnimationFrame(k)}return t(),()=>{var x;u.forEach(I=>{i&&I.removeEventListener("scroll",t),o&&I.removeEventListener("resize",t)}),f?.(),(x=h)==null||x.disconnect(),h=null,a&&cancelAnimationFrame(p)}}var sg=Hm;var lg=qm,ag=jm;var cg=(n,e,t)=>{let r=new Map,i={platform:V1,...t},o={...i.platform,_c:r};return Wm(n,e,{...i,platform:o})};var du=class{constructor(e){this.#o=!1,this.onShow=()=>{},this.onHide=()=>{},this.#c=t=>{cg(t,this.element,{placement:this.#n.placement??"top",middleware:[ag(),sg(this.#l),lg(this.#a),...this.#r],...this.#n}).then(({x:r,y:i})=>{Object.assign(this.element.style,{left:`${r}px`,top:`${i}px`})}).catch(console.error)},this.#u=t=>this.#s!==t.dom.parentElement,this.#d=(t,r)=>{let{state:i,composing:o}=t,{selection:s,doc:l}=i,{ranges:a}=s,c=Math.min(...a.map(h=>h.$from.pos)),u=Math.max(...a.map(h=>h.$to.pos)),f=r&&r.doc.eq(l)&&r.selection.eq(s);if(this.#o||((this.#s??t.dom.parentElement??document.body).appendChild(this.element),this.#o=!0),o||f)return;if(this.#i?.(),this.#i=void 0,!this.#e(t,r)){this.hide();return}let d={getBoundingClientRect:()=>bd(t,c,u),contextElement:t.dom};this.#u(t)?this.#i=hu(d,this.element,()=>this.#c(d)):this.#c(d),this.show()},this.update=(t,r)=>{this.#h(t,r)},this.destroy=()=>{this.#i?.(),this.#h.cancel()},this.show=(t,r)=>{if(this.element.dataset.show="true",t){this.#i?.(),this.#i=void 0;let i={...t,contextElement:r?.dom};r&&this.#u(r)?this.#i=hu(i,this.element,()=>this.#c(i)):this.#c(i)}this.onShow()},this.hide=()=>{this.element.dataset.show!=="false"&&(this.element.dataset.show="false",this.onHide())},this.element=e.content,this.#t=e.debounce??200,this.#e=e.shouldShow??this.#f,this.#l=e.offset,this.#a=e.shift,this.#r=e.middleware??[],this.#n=e.floatingUIOptions??{},this.#s=e.root,this.element.dataset.show="false",this.#h=ru(this.#d,this.#t)}#t;#e;#r;#n;#s;#o;#i;#l;#a;#h;#c;#u;#d;#f(e){let{doc:t,selection:r}=e.state,{empty:i,from:o,to:s}=r,l=!t.textBetween(o,s).length&&e.state.selection instanceof j,a=this.element.contains(document.activeElement),c=!e.hasFocus()&&!a,u=!e.editable;return!(c||i||l||u)}};function W1(n){let e=$e({},`${n}_TOOLTIP_SPEC`),t=ut(i=>{let o=i.get(e.key);return new ne({key:new re(`${n}_TOOLTIP`),...o})}),r=[e,t];return r.key=e.key,r.pluginKey=t.key,e.meta={package:"@milkdown/plugin-tooltip",displayName:`Ctx<tooltipSpec>|${n}`},t.meta={package:"@milkdown/plugin-tooltip",displayName:`Prose<tooltip>|${n}`},r}var Gs=200,ge=function(){};ge.prototype.append=function(e){return e.length?(e=ge.from(e),!this.length&&e||e.length<Gs&&this.leafAppend(e)||this.length<Gs&&e.leafPrepend(this)||this.appendInner(e)):this};ge.prototype.prepend=function(e){return e.length?ge.from(e).append(this):this};ge.prototype.appendInner=function(e){return new j1(this,e)};ge.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ge.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};ge.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};ge.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};ge.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,r),i};ge.from=function(e){return e instanceof ge?e:e&&e.length?new ug(e):ge.empty};var ug=(function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={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,l){for(var a=o;a<s;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,l){for(var a=o-1;a>=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=Gs)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Gs)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(ge);ge.empty=new ug([]);var j1=(function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.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 l=this.left.length;if(i<l&&this.left.forEachInner(r,i,Math.min(o,l),s)===!1||o>l&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o<l&&this.left.forEachInvertedInner(r,Math.min(i,l),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})(ge),pu=ge;var H1=500,jn=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){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;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,a,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 ht(f.map));let h=f.step.map(i.slice(o)),p;h&&s.maybeStep(h).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],c.push(new ht(p,void 0,void 0,c.length+u.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(o)):f.selection,a=new n(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),d=new ht(e.mapping.maps[u],f,t),h;(h=a&&a.merge(d))&&(d=h,u?o.pop():l=l.slice(0,l.length-1)),o.push(d),t&&(s++,t=void 0),i||(a=d)}let c=s-r.depth;return c>K1&&(l=q1(l,c),s-=c),new n(l.append(o),s)}remapping(e,t){let r=new Xr;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,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new ht(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let h=o.getMirror(--a);if(h==null)return;s=Math.min(s,h);let p=o.maps[h];if(d.step){let m=e.steps[h].invert(e.docs[h]),k=d.selection&&d.selection.map(o.slice(a+1,h));k&&l++,r.push(new ht(p,m,k))}else r.push(new ht(p))},i);let c=[];for(let d=t;d<s;d++)c.push(new ht(o.maps[d]));let u=this.items.slice(0,i).append(c).append(r),f=new n(u,l);return f.emptyItemCount()>H1&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let u=s.selection&&s.selection.map(t.slice(r));u&&o++;let f=new ht(c.invert(),a,u),d,h=i.length-1;(d=i.length&&i[h].merge(f))?i[h]=d:i.push(f)}}else s.map&&r--},this.items.length,0),new n(pu.from(i.reverse()),o)}};jn.empty=new jn(pu.empty,0);function q1(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var ht=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},dt=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},K1=20;function U1(n,e,t,r){let i=t.getMeta(Wn),o;if(i)return i.historyState;t.getMeta(Y1)&&(n=new dt(n.done,n.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(s&&s.getMeta(Wn))return s.getMeta(Wn).redo?new dt(n.done.addTransform(t,void 0,r,Ys(e)),n.undone,fg(t.mapping.maps),n.prevTime,n.prevComposition):new dt(n.done,n.undone.addTransform(t,void 0,r,Ys(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!s&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!J1(t,n.prevRanges)),c=s?mu(n.prevRanges,t.mapping):fg(t.mapping.maps);return new dt(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,Ys(e)),jn.empty,c,t.time,l??n.prevComposition)}else return(o=t.getMeta("rebased"))?new dt(n.done.rebased(t,o),n.undone.rebased(t,o),mu(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new dt(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),mu(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function J1(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let o=0;o<e.length;o+=2)r<=e[o+1]&&i>=e[o]&&(t=!0)}),t}function fg(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,o,s)=>e.push(o,s));return e}function mu(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let i=e.map(n[r],1),o=e.map(n[r+1],-1);i<=o&&t.push(i,o)}return t}function G1(n,e,t){let r=Ys(e),i=Wn.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),a=new dt(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(Wn,{redo:t,historyState:a})}var gu=!1,hg=null;function Ys(n){let e=n.plugins;if(hg!=e){gu=!1,hg=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){gu=!0;break}}return gu}var Wn=new re("history"),Y1=new re("closeHistory");function dg(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ne({key:Wn,state:{init(){return new dt(jn.empty,jn.empty,null,0,-1)},apply(e,t,r){return U1(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,i=r=="historyUndo"?yu:r=="historyRedo"?xu:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function Qs(n,e){return(t,r)=>{let i=Wn.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let o=G1(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var yu=Qs(!1,!0),xu=Qs(!0,!0),BR=Qs(!1,!1),zR=Qs(!0,!1);function Fr(n,e){return Object.assign(n,{meta:{package:"@milkdown/plugin-history",...e}}),n}var Xs=J("Undo",()=>()=>yu);Fr(Xs,{displayName:"Command<undo>"});var Zs=J("Redo",()=>()=>xu);Fr(Zs,{displayName:"Command<redo>"});var ku=$e({},"historyProviderConfig");Fr(ku,{displayName:"Ctx<historyProviderConfig>"});var pg=ut(n=>dg(n.get(ku.key)));Fr(pg,{displayName:"Ctx<historyProviderPlugin>"});var bu=De("historyKeymap",{Undo:{shortcuts:"Mod-z",command:n=>{let e=n.get(G);return()=>e.call(Xs.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:n=>{let e=n.get(G);return()=>e.call(Zs.key)}}});Fr(bu.ctx,{displayName:"KeymapCtx<history>"});Fr(bu.shortcuts,{displayName:"Keymap<history>"});var Q1=[ku,pg,bu,Xs,Zs].flat();var el=class{constructor(e,t,r){this.step=e,this.inverted=t,this.origin=r}};function X1(n,e,t){for(let i=n.length-1;i>=0;i--)t.step(n[i].inverted);for(let i=0;i<e.length;i++)t.step(e[i]);let r=[];for(let i=0,o=n.length;i<n.length;i++){let s=n[i].step.map(t.mapping.slice(o));o--,s&&!t.maybeStep(s).failed&&(t.mapping.setMirror(o,t.steps.length-1),r.push(new el(s,s.invert(t.docs[t.docs.length-1]),n[i].origin)))}return r}var _r=class{constructor(e,t){this.version=e,this.unconfirmed=t}};function Z1(n){let e=[];for(let t=0;t<n.steps.length;t++)e.push(new el(n.steps[t],n.steps[t].invert(n.docs[t]),n));return e}var Pt=new re("collab");function eS(n={}){let e={version:n.version||0,clientID:n.clientID==null?Math.floor(Math.random()*4294967295):n.clientID};return new ne({key:Pt,state:{init:()=>new _r(e.version,[]),apply(t,r){let i=t.getMeta(Pt);return i||(t.docChanged?new _r(r.version,r.unconfirmed.concat(Z1(t))):r)}},config:e,historyPreserveItems:!0})}function tS(n,e,t,r={}){let i=Pt.getState(n),o=i.version+e.length,s=Pt.get(n).spec.config.clientID,l=0;for(;l<t.length&&t[l]==s;)++l;let a=i.unconfirmed.slice(l);if(e=l?e.slice(l):e,!e.length)return n.tr.setMeta(Pt,new _r(o,a));let c=a.length,u=n.tr;if(c)a=X1(a,e,u);else{for(let d=0;d<e.length;d++)u.step(e[d]);a=[]}let f=new _r(o,a);return r&&r.mapSelectionBackward&&n.selection instanceof j&&(u.setSelection(j.between(u.doc.resolve(u.mapping.map(n.selection.anchor,-1)),u.doc.resolve(u.mapping.map(n.selection.head,-1)),-1)),u.updated&=-2),u.setMeta("rebased",c).setMeta("addToHistory",!1).setMeta(Pt,f)}function nS(n){let e=Pt.getState(n);return e.unconfirmed.length==0?null:{version:e.version,steps:e.unconfirmed.map(t=>t.step),clientID:Pt.get(n).spec.config.clientID,get origins(){return this._origins||(this._origins=e.unconfirmed.map(t=>t.origin))}}}function rS(n){return Pt.getState(n).version}export{dc as Editor,ae as Step,du as TooltipProvider,c0 as callCommand,eS as collab,B0 as commonmark,gs as defaultValueCtx,rt as editorViewCtx,Cs as editorViewOptionsCtx,rS as getVersion,Q1 as history,Dm as listener,iu as listenerCtx,tS as receiveTransaction,Zs as redoCommand,Ms as rootCtx,nS as sendableSteps,Rn as serializerCtx,Ds as toggleEmphasisCommand,Ps as toggleStrongCommand,W1 as tooltipFactory,Bs as turnIntoTextCommand,Xs as undoCommand,Fs as wrapInBlockquoteCommand,_s as wrapInBulletListCommand,At as wrapInHeadingCommand}; 46 + `):e.addNode("break")}}}));w(Dn.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});w(Dn.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Pc=J("InsertHardbreak",n=>()=>(e,t)=>{let{selection:r,tr:i}=e;if(!(r instanceof j))return!1;if(r.empty){let o=r.$from.node();if(o.childCount>0&&o.lastChild?.type.name==="hardbreak")return t?.(i.replaceRangeWith(r.to-1,r.to,e.schema.node("paragraph")).setSelection(W.near(i.doc.resolve(r.to))).scrollIntoView()),!0}return t?.(i.setMeta("hardbreak",!0).replaceSelectionWith(Dn.type(n).create()).scrollIntoView()),!0});w(Pc,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Lc=De("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:n=>{let e=n.get(G);return()=>e.call(Pc.key)}}});w(Lc.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});w(Lc.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Bc=Ye("hr");w(Bc,{displayName:"Attr<hr>",group:"Hr"});var _i=We("hr",n=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",n.get(Bc.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,t,r)=>{e.addNode(r)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));w(_i.node,{displayName:"NodeSchema<hr>",group:"Hr"});w(_i.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var hm=Ge(n=>new Ne(/^(?:---|___\s|\*\*\*\s)$/,(e,t,r,i)=>{let{tr:o}=e;return t[0]&&o.replaceWith(r-1,i,_i.type(n).create()),o}));w(hm,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var dm=J("InsertHr",n=>()=>(e,t)=>{if(!t)return!0;let r=Pn.node.type(n).create(),{tr:i,selection:o}=e,{from:s}=o,l=_i.type(n).create();if(!l)return!0;let a=i.replaceSelectionWith(l).insert(s,r),c=W.findFrom(a.doc.resolve(s),1,!0);return c&&t(a.setSelection(c).scrollIntoView()),!0});w(dm,{displayName:"Command<insertHrCommand>",group:"Hr"});var zc=Ye("bulletList");w(zc,{displayName:"Attr<bulletList>",group:"BulletList"});var Rr=We("bullet_list",n=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Lt(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...n.get(zc.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!t,runner:(e,t,r)=>{let i=t.spread!=null?`${t.spread}`:"false";e.openNode(r,{spread:i}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!1,spread:t.attrs.spread}).next(t.content).closeNode()}}}));w(Rr.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});w(Rr.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var pm=Ge(n=>Yo(/^\s*([-+*])\s$/,Rr.type(n)));w(pm,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var _s=J("WrapInBulletList",n=>()=>yo(Rr.type(n)));w(_s,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Fc=De("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:n=>{let e=n.get(G);return()=>e.call(_s.key)}}});w(Fc.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});w(Fc.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var _c=Ye("orderedList");w(_c,{displayName:"Attr<orderedList>",group:"OrderedList"});var vr=We("ordered_list",n=>({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 Lt(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...n.get(_c.key)(e),...e.attrs.order===1?{}:e.attrs.order,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!!t,runner:(e,t,r)=>{let i=t.spread!=null?`${t.spread}`:"true";e.openNode(r,{spread:i}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!0,start:1,spread:t.attrs.spread==="true"}),e.next(t.content),e.closeNode()}}}));w(vr.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});w(vr.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var mm=Ge(n=>Yo(/^\s*(\d+)\.\s$/,vr.type(n),e=>({order:Number(e[1])}),(e,t)=>t.childCount+t.attrs.order===Number(e[1])));w(mm,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Vc=J("WrapInOrderedList",n=>()=>yo(vr.type(n)));w(Vc,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var $c=De("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:n=>{let e=n.get(G);return()=>e.call(Vc.key)}}});w($c.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});w($c.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Wc=Ye("listItem");w(Wc,{displayName:"Attr<listItem>",group:"ListItem"});var Gt=We("list_item",n=>({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 Lt(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...n.get(Wc.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,t,r)=>{let i=t.label!=null?`${t.label}.`:"\u2022",o=t.label!=null?"ordered":"bullet",s=t.spread!=null?`${t.spread}`:"true";e.openNode(r,{label:i,listType:o,spread:s}),e.next(t.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,t)=>{e.openNode("listItem",void 0,{spread:t.attrs.spread}),e.next(t.content),e.closeNode()}}}));w(Gt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});w(Gt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var jc=J("SinkListItem",n=>()=>Qp(Gt.type(n)));w(jc,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Hc=J("LiftListItem",n=>()=>Yp(Gt.type(n)));w(Hc,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var qc=J("SplitListItem",n=>()=>Gp(Gt.type(n)));w(qc,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function x0(n){return(e,t,r)=>{let{selection:i}=e;if(!(i instanceof j))return!1;let{empty:o,$from:s}=i;return!o||s.parentOffset!==0||s.node(-1).type!==Gt.type(n)?!1:Rl(e,t,r)}}var Kc=J("LiftFirstListItem",n=>()=>x0(n));w(Kc,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Uc=De("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:n=>{let e=n.get(G);return()=>e.call(qc.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:n=>{let e=n.get(G);return()=>e.call(jc.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:n=>{let e=n.get(G);return()=>e.call(Hc.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:n=>{let e=n.get(G);return()=>e.call(Kc.key)}}});w(Uc.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});w(Uc.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var gm=As("text",()=>({group:"inline",parseMarkdown:{match:({type:n})=>n==="text",runner:(n,e)=>{n.addText(e.value)}},toMarkdown:{match:n=>n.type.name==="text",runner:(n,e)=>{n.addNode("text",void 0,e.text)}}}));w(gm,{displayName:"NodeSchema<text>",group:"Text"});var Jc=Ye("html");w(Jc,{displayName:"Attr<html>",group:"Html"});var Gc=We("html",n=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{let t=document.createElement("span"),r={...n.get(Jc.key)(e),"data-value":e.attrs.value,"data-type":"html"};return t.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,t,r)=>{e.addNode(r,{value:t.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,t)=>{e.addNode("html",void 0,t.attrs.value)}}}));w(Gc.node,{displayName:"NodeSchema<html>",group:"Html"});w(Gc.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var k0=[sm,Cc,Pn,zs,Nc,Ln,vs,Dn,Oc,zi,Ac,Fi,Bc,_i,Dc,Ar,zc,Rr,_c,vr,Wc,Gt,mc,Er,yc,Bi,kc,Jt,Sc,Or,Jc,Gc,gm].flat(),b0=[am,pm,mm,cm,hm,lm].flat(),w0=[em,tm,rm,nm],S0=J("IsMarkSelected",()=>n=>e=>{if(!n)return!1;let{doc:t,selection:r}=e;return t.rangeHasMark(r.from,r.to,n)}),C0=J("IsNoteSelected",()=>n=>e=>n?Sd(e,n).hasNode:!1),M0=J("ClearTextInCurrentBlock",()=>()=>(n,e)=>{let t=n.tr,{$from:r,$to:i}=t.selection,{pos:o}=r,{pos:s}=i,l=o-r.node().content.size;return l<0?!1:(t=t.deleteRange(l,s),e?.(t),!0)}),N0=J("SetBlockType",()=>n=>(e,t)=>{let{nodeType:r,attrs:i=null}=n??{};if(!r)return!1;let o=e.tr,{from:s,to:l}=o.selection;try{o.setBlockType(s,l,r,i)}catch{return!1}return t?.(o),!0}),I0=J("WrapInBlockType",()=>n=>(e,t)=>{let{nodeType:r,attrs:i=null}=n??{};if(!r)return!1;let o=e.tr;try{let{$from:s,$to:l}=o.selection,a=s.blockRange(l),c=a&&cn(a,r,i);if(!c)return!1;o=o.wrap(a,c)}catch{return!1}return t?.(o),!0}),T0=J("AddBlockType",()=>n=>(e,t)=>{let{nodeType:r,attrs:i=null}=n??{};if(!r)return!1;let o=e.tr;try{let s=r instanceof Ae?r:r.createAndFill(i);if(!s)return!1;o.replaceSelectionWith(s)}catch{return!1}return t?.(o),!0}),O0=J("SelectTextNearPos",()=>n=>(e,t)=>{let{pos:r}=n??{};if(r==null)return!1;let i=(s,l,a)=>Math.min(Math.max(s,l),a),o=e.tr;try{let s=e.doc.resolve(i(r,0,e.doc.content.size));o.setSelection(j.near(s))}catch{return!1}return t?.(o.scrollIntoView()),!0}),E0=[Bs,Fs,At,Ic,Rc,Pc,dm,um,fm,Vc,_s,jc,qc,Hc,Kc,Ds,bc,Ps,im,om,S0,C0,M0,N0,I0,T0,O0],A0=[Ec,vc,Lc,Tc,Uc,$c,Fc,Mc,gc,wc,xc].flat(),Yc=vn("remarkAddOrderInList",()=>()=>n=>{et(n,"list",e=>{if(e.ordered){let t=e.start??1;e.children.forEach((r,i)=>{r.label=i+t})}})});w(Yc.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});w(Yc.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var Qc=vn("remarkLineBreak",()=>()=>n=>{let e=/[\t ]*(?:\r?\n|\r)/g;et(n,"text",(t,r,i)=>{if(!t.value||typeof t.value!="string")return;let o=[],s=0;e.lastIndex=0;let l=e.exec(t.value);for(;l;){let c=l.index;s!==c&&o.push({type:"text",value:t.value.slice(s,c)}),o.push({type:"break",data:{isInline:!0}}),s=c+l[0].length,l=e.exec(t.value)}if(o.length>0&&i&&typeof r=="number")return s<t.value.length&&o.push({type:"text",value:t.value.slice(s)}),i.children.splice(r,1,...o),r+o.length})});w(Qc.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});w(Qc.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var Xc=vn("remarkInlineLink",()=>Rs);w(Xc.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});w(Xc.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var R0=n=>!!n.children,v0=n=>n.type==="html";function D0(n,e){return t(n,0,null)[0];function t(r,i,o){if(R0(r)){let s=[];for(let l=0,a=r.children.length;l<a;l++){let c=r.children[l];if(c){let u=t(c,l,r);if(u)for(let f=0,d=u.length;f<d;f++){let h=u[f];h&&s.push(h)}}}r.children=s}return e(r,i,o)}}var P0=["root","blockquote","listItem"],Zc=vn("remarkHTMLTransformer",()=>()=>n=>{D0(n,(e,t,r)=>v0(e)?(r&&P0.includes(r.type)&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});w(Zc.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});w(Zc.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var eu=vn("remarkMarker",()=>()=>(n,e)=>{let t=r=>e.value.charAt(r.position.start.offset);et(n,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=t(r)})});w(eu.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});w(eu.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var ym=ut(()=>{let n=!1,e=new re("MILKDOWN_INLINE_NODES_CURSOR"),t=new ne({key:e,state:{init(){return!1},apply(r){if(!r.selection.empty)return!1;let i=r.selection.$from,o=i.nodeBefore,s=i.nodeAfter;return!!(o&&s&&o.isInline&&!o.isText&&s.isInline&&!s.isText)}},props:{handleDOMEvents:{compositionend:(r,i)=>n?(n=!1,requestAnimationFrame(()=>{if(t.getState(r.state)){let s=r.state.selection.from;i.preventDefault(),r.dispatch(r.state.tr.insertText(i.data||"",s))}}),!0):!1,compositionstart:r=>(t.getState(r.state)&&(n=!0),!1),beforeinput:(r,i)=>{if(t.getState(r.state)&&i instanceof InputEvent&&i.data&&!n){let s=r.state.selection.from;return i.preventDefault(),r.dispatch(r.state.tr.insertText(i.data||"",s)),!0}return!1}},decorations(r){if(t.getState(r)){let s=r.selection.$from.pos,l=document.createElement("span"),a=nt.widget(s,l,{side:-1}),c=document.createElement("span"),u=nt.widget(s,c);return setTimeout(()=>{l.contentEditable="true",c.contentEditable="true"}),Ie.create(r.doc,[a,u])}return Ie.empty}}});return t});w(ym,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var xm=ut(n=>new ne({key:new re("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,t,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:a}=o;return r.tr.setNodeMarkup(a,Dn.type(n),void 0,[])}if(o instanceof ln){let a=r.tr,{from:c,to:u}=o;return r.doc.nodesBetween(c,u,(f,d)=>{f.type===Dn.type(n)&&(a=a.setNodeMarkup(d,Dn.type(n),void 0,[]))}),a}}}));w(xm,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var tu=$e(["table","code_block"],"hardbreakFilterNodes");w(tu,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var km=ut(n=>{let e=n.get(tu.key);return new ne({key:new re("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(t,r)=>{let i=t.getMeta("hardbreak"),[o]=t.steps;if(i&&o){let{from:s}=o,l=r.doc.resolve(s),a=l.depth,c=!0;for(;a>0;)e.includes(l.node(a).type.name)&&(c=!1),a--;return c}return!0}})});w(km,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var bm=ut(n=>{let e=new re("MILKDOWN_HEADING_ID"),t=r=>{if(r.composing)return;let i=n.get(zs.key),o=r.state.tr.setMeta("addToHistory",!1),s=!1,l={};r.state.doc.descendants((a,c)=>{if(a.type===Ln.type(n)){if(a.textContent.trim().length===0)return;let u=a.attrs,f=i(a);l[f]?(l[f]+=1,f+=`-#${l[f]}`):l[f]=1,u.id!==f&&(s=!0,o.setMeta(e,!0).setNodeMarkup(c,void 0,{...u,id:f}))}}),s&&r.dispatch(o)};return new ne({key:e,view:r=>(t(r),{update:(i,o)=>{i.state.doc.eq(o.doc)||t(i)}})})});w(bm,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var wm=ut(n=>{let e=(t,r,i)=>{if(!i.selection||t.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;let o=vr.type(n),s=Rr.type(n),l=Gt.type(n),a=(f,d)=>{let h=!1,p=`${d+1}.`;return f.label!==p&&(f.label=p,h=!0),h},c=i.tr,u=!1;return i.doc.descendants((f,d,h,p)=>{if(f.type===s){let m=f.maybeChild(0);m?.type===l&&m.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(d,o,{spread:"true"}),f.descendants((k,x,I,C)=>{if(k.type===l){let A={...k.attrs};a(A,C)&&(c=c.setNodeMarkup(x,void 0,A))}return!1}))}else if(f.type===l&&h?.type===o){let m={...f.attrs},k=!1;m.listType!=="ordered"&&(m.listType="ordered",k=!0),h?.maybeChild(0)&&(k=a(m,p)),k&&(c=c.setNodeMarkup(d,void 0,m),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new ne({key:new re("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});w(wm,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var L0=[xm,tu,km,ym,Yc,Xc,Qc,Zc,eu,Ls,bm,wm].flat(),B0=[k0,b0,w0,E0,A0,L0].flat();var z0=typeof global=="object"&&global&&global.Object===Object&&global,Sm=z0;var F0=typeof self=="object"&&self&&self.Object===Object&&self,_0=Sm||F0||Function("return this")(),Vs=_0;var V0=Vs.Symbol,Dr=V0;var Cm=Object.prototype,$0=Cm.hasOwnProperty,W0=Cm.toString,Vi=Dr?Dr.toStringTag:void 0;function j0(n){var e=$0.call(n,Vi),t=n[Vi];try{n[Vi]=void 0;var r=!0}catch{}var i=W0.call(n);return r&&(e?n[Vi]=t:delete n[Vi]),i}var Mm=j0;var H0=Object.prototype,q0=H0.toString;function K0(n){return q0.call(n)}var Nm=K0;var U0="[object Null]",J0="[object Undefined]",Im=Dr?Dr.toStringTag:void 0;function G0(n){return n==null?n===void 0?J0:U0:Im&&Im in Object(n)?Mm(n):Nm(n)}var Tm=G0;function Y0(n){return n!=null&&typeof n=="object"}var Om=Y0;var Q0="[object Symbol]";function X0(n){return typeof n=="symbol"||Om(n)&&Tm(n)==Q0}var Em=X0;var Z0=/\s/;function e1(n){for(var e=n.length;e--&&Z0.test(n.charAt(e)););return e}var Am=e1;var t1=/^\s+/;function n1(n){return n&&n.slice(0,Am(n)+1).replace(t1,"")}var Rm=n1;function r1(n){var e=typeof n;return n!=null&&(e=="object"||e=="function")}var Bn=r1;var vm=NaN,i1=/^[-+]0x[0-9a-f]+$/i,o1=/^0b[01]+$/i,s1=/^0o[0-7]+$/i,l1=parseInt;function a1(n){if(typeof n=="number")return n;if(Em(n))return vm;if(Bn(n)){var e=typeof n.valueOf=="function"?n.valueOf():n;n=Bn(e)?e+"":e}if(typeof n!="string")return n===0?n:+n;n=Rm(n);var t=o1.test(n);return t||s1.test(n)?l1(n.slice(2),t?2:8):i1.test(n)?vm:+n}var nu=a1;var c1=function(){return Vs.Date.now()},$s=c1;var u1="Expected a function",f1=Math.max,h1=Math.min;function d1(n,e,t){var r,i,o,s,l,a,c=0,u=!1,f=!1,d=!0;if(typeof n!="function")throw new TypeError(u1);e=nu(e)||0,Bn(t)&&(u=!!t.leading,f="maxWait"in t,o=f?f1(nu(t.maxWait)||0,e):o,d="trailing"in t?!!t.trailing:d);function h(b){var T=r,P=i;return r=i=void 0,c=b,s=n.apply(P,T),s}function p(b){return c=b,l=setTimeout(x,e),u?h(b):s}function m(b){var T=b-a,P=b-c,D=e-T;return f?h1(D,o-P):D}function k(b){var T=b-a,P=b-c;return a===void 0||T>=e||T<0||f&&P>=o}function x(){var b=$s();if(k(b))return I(b);l=setTimeout(x,m(b))}function I(b){return l=void 0,d&&r?h(b):(r=i=void 0,s)}function C(){l!==void 0&&clearTimeout(l),c=0,r=a=i=l=void 0}function A(){return l===void 0?s:I($s())}function v(){var b=$s(),T=k(b);if(r=arguments,i=this,a=b,T){if(l===void 0)return p(a);if(f)return clearTimeout(l),l=setTimeout(x,e),h(a)}return l===void 0&&(l=setTimeout(x,e)),s}return v.cancel=C,v.flush=A,v}var $i=d1;var p1="Expected a function";function m1(n,e,t){var r=!0,i=!0;if(typeof n!="function")throw new TypeError(p1);return Bn(t)&&(r="leading"in t?!!t.leading:r,i="trailing"in t?!!t.trailing:i),$i(n,e,{leading:r,maxWait:e,trailing:i})}var ru=m1;var Ws=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=e=>(this.beforeMountedListeners.push(e),this),this.mounted=e=>(this.mountedListeners.push(e),this),this.updated=e=>(this.updatedListeners.push(e),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners,selectionUpdated:this.selectionUpdatedListeners}}markdownUpdated(e){return this.markdownUpdatedListeners.push(e),this}blur(e){return this.blurListeners.push(e),this}focus(e){return this.focusListeners.push(e),this}destroy(e){return this.destroyListeners.push(e),this}selectionUpdated(e){return this.selectionUpdatedListeners.push(e),this}},iu=$(new Ws,"listener"),g1=new re("MILKDOWN_LISTENER"),Dm=n=>(n.inject(iu,new Ws),async()=>{await n.wait(Tt);let e=n.get(iu),{listeners:t}=e;t.beforeMount.forEach(a=>a(n)),await n.wait(Mr);let r=n.get(Rn),i=null,o=null,s=null,l=new ne({key:g1,view:()=>({destroy:()=>{t.destroy.forEach(a=>a(n))}}),props:{handleDOMEvents:{focus:()=>(t.focus.forEach(a=>a(n)),!1),blur:()=>(t.blur.forEach(a=>a(n)),!1)}},state:{init:(a,c)=>{i=c.doc,o=r(c.doc)},apply:a=>{let c=a.selection;return(!s&&c||s&&!c.eq(s))&&(t.selectionUpdated.forEach(f=>{f(n,c,s)}),s=c),!(a.docChanged||a.storedMarksSet)||a.getMeta("addToHistory")===!1?void 0:$i(()=>{let{doc:f}=a;if(t.updated.length>0&&i&&!i.eq(f)&&t.updated.forEach(d=>{d(n,f,i)}),t.markdownUpdated.length>0&&i&&!i.eq(f)){let d=r(f);t.markdownUpdated.forEach(h=>{h(n,d,o)}),o=d}i=f},200)()}}});n.update(it,a=>a.concat(l)),await n.wait(Di),t.mounted.forEach(a=>a(n))});Dm.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var Pr=Math.min,Rt=Math.max,ji=Math.round,Hi=Math.floor,ot=n=>({x:n,y:n}),y1={left:"right",right:"left",bottom:"top",top:"bottom"};function ou(n,e,t){return Rt(n,Pr(e,t))}function qi(n,e){return typeof n=="function"?n(e):n}function Yt(n){return n.split("-")[0]}function Ki(n){return n.split("-")[1]}function su(n){return n==="x"?"y":"x"}function lu(n){return n==="y"?"height":"width"}function vt(n){let e=n[0];return e==="t"||e==="b"?"y":"x"}function au(n){return su(vt(n))}function Bm(n,e,t){t===void 0&&(t=!1);let r=Ki(n),i=au(n),o=lu(i),s=i==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(s=Wi(s)),[s,Wi(s)]}function zm(n){let e=Wi(n);return[js(n),e,js(e)]}function js(n){return n.includes("start")?n.replace("start","end"):n.replace("end","start")}var Pm=["left","right"],Lm=["right","left"],x1=["top","bottom"],k1=["bottom","top"];function b1(n,e,t){switch(n){case"top":case"bottom":return t?e?Lm:Pm:e?Pm:Lm;case"left":case"right":return e?x1:k1;default:return[]}}function Fm(n,e,t,r){let i=Ki(n),o=b1(Yt(n),t==="start",r);return i&&(o=o.map(s=>s+"-"+i),e&&(o=o.concat(o.map(js)))),o}function Wi(n){let e=Yt(n);return y1[e]+n.slice(e.length)}function w1(n){return{top:0,right:0,bottom:0,left:0,...n}}function _m(n){return typeof n!="number"?w1(n):{top:n,right:n,bottom:n,left:n}}function zn(n){let{x:e,y:t,width:r,height:i}=n;return{width:r,height:i,top:t,left:e,right:e+r,bottom:t+i,x:e,y:t}}function Vm(n,e,t){let{reference:r,floating:i}=n,o=vt(e),s=au(e),l=lu(s),a=Yt(e),c=o==="y",u=r.x+r.width/2-i.width/2,f=r.y+r.height/2-i.height/2,d=r[l]/2-i[l]/2,h;switch(a){case"top":h={x:u,y:r.y-i.height};break;case"bottom":h={x:u,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-i.width,y:f};break;default:h={x:r.x,y:r.y}}switch(Ki(e)){case"start":h[s]-=d*(t&&c?-1:1);break;case"end":h[s]+=d*(t&&c?-1:1);break}return h}async function $m(n,e){var t;e===void 0&&(e={});let{x:r,y:i,platform:o,rects:s,elements:l,strategy:a}=n,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:h=0}=qi(e,n),p=_m(h),k=l[d?f==="floating"?"reference":"floating":f],x=zn(await o.getClippingRect({element:(t=await(o.isElement==null?void 0:o.isElement(k)))==null||t?k:k.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:a})),I=f==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,C=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l.floating)),A=await(o.isElement==null?void 0:o.isElement(C))?await(o.getScale==null?void 0:o.getScale(C))||{x:1,y:1}:{x:1,y:1},v=zn(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:I,offsetParent:C,strategy:a}):I);return{top:(x.top-v.top+p.top)/A.y,bottom:(v.bottom-x.bottom+p.bottom)/A.y,left:(x.left-v.left+p.left)/A.x,right:(v.right-x.right+p.right)/A.x}}var S1=50,Wm=async(n,e,t)=>{let{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:s}=t,l=s.detectOverflow?s:{...s,detectOverflow:$m},a=await(s.isRTL==null?void 0:s.isRTL(e)),c=await s.getElementRects({reference:n,floating:e,strategy:i}),{x:u,y:f}=Vm(c,r,a),d=r,h=0,p={};for(let m=0;m<o.length;m++){let k=o[m];if(!k)continue;let{name:x,fn:I}=k,{x:C,y:A,data:v,reset:b}=await I({x:u,y:f,initialPlacement:r,placement:d,strategy:i,middlewareData:p,rects:c,platform:l,elements:{reference:n,floating:e}});u=C??u,f=A??f,p[x]={...p[x],...v},b&&h<S1&&(h++,typeof b=="object"&&(b.placement&&(d=b.placement),b.rects&&(c=b.rects===!0?await s.getElementRects({reference:n,floating:e,strategy:i}):b.rects),{x:u,y:f}=Vm(c,d,a)),m=-1)}return{x:u,y:f,placement:d,strategy:i,middlewareData:p}};var jm=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,r;let{placement:i,middlewareData:o,rects:s,initialPlacement:l,platform:a,elements:c}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:d,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:m=!0,...k}=qi(n,e);if((t=o.arrow)!=null&&t.alignmentOffset)return{};let x=Yt(i),I=vt(l),C=Yt(l)===l,A=await(a.isRTL==null?void 0:a.isRTL(c.floating)),v=d||(C||!m?[Wi(l)]:zm(l)),b=p!=="none";!d&&b&&v.push(...Fm(l,m,p,A));let T=[l,...v],P=await a.detectOverflow(e,k),D=[],U=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&D.push(P[x]),f){let L=Bm(i,s,A);D.push(P[L[0]],P[L[1]])}if(U=[...U,{placement:i,overflows:D}],!D.every(L=>L<=0)){var Se,Y;let L=(((Se=o.flip)==null?void 0:Se.index)||0)+1,F=T[L];if(F&&(!(f==="alignment"?I!==vt(F):!1)||U.every(te=>vt(te.placement)===I?te.overflows[0]>0:!0)))return{data:{index:L,overflows:U},reset:{placement:F}};let Q=(Y=U.filter(X=>X.overflows[0]<=0).sort((X,te)=>X.overflows[1]-te.overflows[1])[0])==null?void 0:Y.placement;if(!Q)switch(h){case"bestFit":{var R;let X=(R=U.filter(te=>{if(b){let le=vt(te.placement);return le===I||le==="y"}return!0}).map(te=>[te.placement,te.overflows.filter(le=>le>0).reduce((le,g)=>le+g,0)]).sort((te,le)=>te[1]-le[1])[0])==null?void 0:R[0];X&&(Q=X);break}case"initialPlacement":Q=l;break}if(i!==Q)return{reset:{placement:Q}}}return{}}}};var C1=new Set(["left","top"]);async function M1(n,e){let{placement:t,platform:r,elements:i}=n,o=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Yt(t),l=Ki(t),a=vt(t)==="y",c=C1.has(s)?-1:1,u=o&&a?-1:1,f=qi(e,n),{mainAxis:d,crossAxis:h,alignmentAxis:p}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&typeof p=="number"&&(h=l==="end"?p*-1:p),a?{x:h*u,y:d*c}:{x:d*c,y:h*u}}var Hm=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,r;let{x:i,y:o,placement:s,middlewareData:l}=e,a=await M1(e,n);return s===((t=l.offset)==null?void 0:t.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+a.x,y:o+a.y,data:{...a,placement:s}}}}},qm=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){let{x:t,y:r,placement:i,platform:o}=e,{mainAxis:s=!0,crossAxis:l=!1,limiter:a={fn:x=>{let{x:I,y:C}=x;return{x:I,y:C}}},...c}=qi(n,e),u={x:t,y:r},f=await o.detectOverflow(e,c),d=vt(Yt(i)),h=su(d),p=u[h],m=u[d];if(s){let x=h==="y"?"top":"left",I=h==="y"?"bottom":"right",C=p+f[x],A=p-f[I];p=ou(C,p,A)}if(l){let x=d==="y"?"top":"left",I=d==="y"?"bottom":"right",C=m+f[x],A=m-f[I];m=ou(C,m,A)}let k=a.fn({...e,[h]:p,[d]:m});return{...k,data:{x:k.x-t,y:k.y-r,enabled:{[h]:s,[d]:l}}}}}};function Hs(){return typeof window<"u"}function _n(n){return Um(n)?(n.nodeName||"").toLowerCase():"#document"}function Pe(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function st(n){var e;return(e=(Um(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Um(n){return Hs()?n instanceof Node||n instanceof Pe(n).Node:!1}function Qe(n){return Hs()?n instanceof Element||n instanceof Pe(n).Element:!1}function ft(n){return Hs()?n instanceof HTMLElement||n instanceof Pe(n).HTMLElement:!1}function Km(n){return!Hs()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Pe(n).ShadowRoot}function Br(n){let{overflow:e,overflowX:t,overflowY:r,display:i}=Xe(n);return/auto|scroll|overlay|hidden|clip/.test(e+r+t)&&i!=="inline"&&i!=="contents"}function Jm(n){return/^(table|td|th)$/.test(_n(n))}function Ui(n){try{if(n.matches(":popover-open"))return!0}catch{}try{return n.matches(":modal")}catch{return!1}}var N1=/transform|translate|scale|rotate|perspective|filter/,I1=/paint|layout|strict|content/,Fn=n=>!!n&&n!=="none",cu;function qs(n){let e=Qe(n)?Xe(n):n;return Fn(e.transform)||Fn(e.translate)||Fn(e.scale)||Fn(e.rotate)||Fn(e.perspective)||!Ks()&&(Fn(e.backdropFilter)||Fn(e.filter))||N1.test(e.willChange||"")||I1.test(e.contain||"")}function Gm(n){let e=Dt(n);for(;ft(e)&&!Vn(e);){if(qs(e))return e;if(Ui(e))return null;e=Dt(e)}return null}function Ks(){return cu==null&&(cu=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),cu}function Vn(n){return/^(html|body|#document)$/.test(_n(n))}function Xe(n){return Pe(n).getComputedStyle(n)}function Ji(n){return Qe(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function Dt(n){if(_n(n)==="html")return n;let e=n.assignedSlot||n.parentNode||Km(n)&&n.host||st(n);return Km(e)?e.host:e}function Ym(n){let e=Dt(n);return Vn(e)?n.ownerDocument?n.ownerDocument.body:n.body:ft(e)&&Br(e)?e:Ym(e)}function Lr(n,e,t){var r;e===void 0&&(e=[]),t===void 0&&(t=!0);let i=Ym(n),o=i===((r=n.ownerDocument)==null?void 0:r.body),s=Pe(i);if(o){let l=Us(s);return e.concat(s,s.visualViewport||[],Br(i)?i:[],l&&t?Lr(l):[])}else return e.concat(i,Lr(i,[],t))}function Us(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function eg(n){let e=Xe(n),t=parseFloat(e.width)||0,r=parseFloat(e.height)||0,i=ft(n),o=i?n.offsetWidth:t,s=i?n.offsetHeight:r,l=ji(t)!==o||ji(r)!==s;return l&&(t=o,r=s),{width:t,height:r,$:l}}function fu(n){return Qe(n)?n:n.contextElement}function zr(n){let e=fu(n);if(!ft(e))return ot(1);let t=e.getBoundingClientRect(),{width:r,height:i,$:o}=eg(e),s=(o?ji(t.width):t.width)/r,l=(o?ji(t.height):t.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!l||!Number.isFinite(l))&&(l=1),{x:s,y:l}}var T1=ot(0);function tg(n){let e=Pe(n);return!Ks()||!e.visualViewport?T1:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function O1(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Pe(n)?!1:e}function $n(n,e,t,r){e===void 0&&(e=!1),t===void 0&&(t=!1);let i=n.getBoundingClientRect(),o=fu(n),s=ot(1);e&&(r?Qe(r)&&(s=zr(r)):s=zr(n));let l=O1(o,t,r)?tg(o):ot(0),a=(i.left+l.x)/s.x,c=(i.top+l.y)/s.y,u=i.width/s.x,f=i.height/s.y;if(o){let d=Pe(o),h=r&&Qe(r)?Pe(r):r,p=d,m=Us(p);for(;m&&r&&h!==p;){let k=zr(m),x=m.getBoundingClientRect(),I=Xe(m),C=x.left+(m.clientLeft+parseFloat(I.paddingLeft))*k.x,A=x.top+(m.clientTop+parseFloat(I.paddingTop))*k.y;a*=k.x,c*=k.y,u*=k.x,f*=k.y,a+=C,c+=A,p=Pe(m),m=Us(p)}}return zn({width:u,height:f,x:a,y:c})}function Js(n,e){let t=Ji(n).scrollLeft;return e?e.left+t:$n(st(n)).left+t}function ng(n,e){let t=n.getBoundingClientRect(),r=t.left+e.scrollLeft-Js(n,t),i=t.top+e.scrollTop;return{x:r,y:i}}function E1(n){let{elements:e,rect:t,offsetParent:r,strategy:i}=n,o=i==="fixed",s=st(r),l=e?Ui(e.floating):!1;if(r===s||l&&o)return t;let a={scrollLeft:0,scrollTop:0},c=ot(1),u=ot(0),f=ft(r);if((f||!f&&!o)&&((_n(r)!=="body"||Br(s))&&(a=Ji(r)),f)){let h=$n(r);c=zr(r),u.x=h.x+r.clientLeft,u.y=h.y+r.clientTop}let d=s&&!f&&!o?ng(s,a):ot(0);return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-a.scrollLeft*c.x+u.x+d.x,y:t.y*c.y-a.scrollTop*c.y+u.y+d.y}}function A1(n){return Array.from(n.getClientRects())}function R1(n){let e=st(n),t=Ji(n),r=n.ownerDocument.body,i=Rt(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=Rt(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight),s=-t.scrollLeft+Js(n),l=-t.scrollTop;return Xe(r).direction==="rtl"&&(s+=Rt(e.clientWidth,r.clientWidth)-i),{width:i,height:o,x:s,y:l}}var Qm=25;function v1(n,e){let t=Pe(n),r=st(n),i=t.visualViewport,o=r.clientWidth,s=r.clientHeight,l=0,a=0;if(i){o=i.width,s=i.height;let u=Ks();(!u||u&&e==="fixed")&&(l=i.offsetLeft,a=i.offsetTop)}let c=Js(r);if(c<=0){let u=r.ownerDocument,f=u.body,d=getComputedStyle(f),h=u.compatMode==="CSS1Compat"&&parseFloat(d.marginLeft)+parseFloat(d.marginRight)||0,p=Math.abs(r.clientWidth-f.clientWidth-h);p<=Qm&&(o-=p)}else c<=Qm&&(o+=c);return{width:o,height:s,x:l,y:a}}function D1(n,e){let t=$n(n,!0,e==="fixed"),r=t.top+n.clientTop,i=t.left+n.clientLeft,o=ft(n)?zr(n):ot(1),s=n.clientWidth*o.x,l=n.clientHeight*o.y,a=i*o.x,c=r*o.y;return{width:s,height:l,x:a,y:c}}function Xm(n,e,t){let r;if(e==="viewport")r=v1(n,t);else if(e==="document")r=R1(st(n));else if(Qe(e))r=D1(e,t);else{let i=tg(n);r={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return zn(r)}function rg(n,e){let t=Dt(n);return t===e||!Qe(t)||Vn(t)?!1:Xe(t).position==="fixed"||rg(t,e)}function P1(n,e){let t=e.get(n);if(t)return t;let r=Lr(n,[],!1).filter(l=>Qe(l)&&_n(l)!=="body"),i=null,o=Xe(n).position==="fixed",s=o?Dt(n):n;for(;Qe(s)&&!Vn(s);){let l=Xe(s),a=qs(s);!a&&l.position==="fixed"&&(i=null),(o?!a&&!i:!a&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||Br(s)&&!a&&rg(n,s))?r=r.filter(u=>u!==s):i=l,s=Dt(s)}return e.set(n,r),r}function L1(n){let{element:e,boundary:t,rootBoundary:r,strategy:i}=n,s=[...t==="clippingAncestors"?Ui(e)?[]:P1(e,this._c):[].concat(t),r],l=Xm(e,s[0],i),a=l.top,c=l.right,u=l.bottom,f=l.left;for(let d=1;d<s.length;d++){let h=Xm(e,s[d],i);a=Rt(h.top,a),c=Pr(h.right,c),u=Pr(h.bottom,u),f=Rt(h.left,f)}return{width:c-f,height:u-a,x:f,y:a}}function B1(n){let{width:e,height:t}=eg(n);return{width:e,height:t}}function z1(n,e,t){let r=ft(e),i=st(e),o=t==="fixed",s=$n(n,!0,o,e),l={scrollLeft:0,scrollTop:0},a=ot(0);function c(){a.x=Js(i)}if(r||!r&&!o)if((_n(e)!=="body"||Br(i))&&(l=Ji(e)),r){let h=$n(e,!0,o,e);a.x=h.x+e.clientLeft,a.y=h.y+e.clientTop}else i&&c();o&&!r&&i&&c();let u=i&&!r&&!o?ng(i,l):ot(0),f=s.left+l.scrollLeft-a.x-u.x,d=s.top+l.scrollTop-a.y-u.y;return{x:f,y:d,width:s.width,height:s.height}}function uu(n){return Xe(n).position==="static"}function Zm(n,e){if(!ft(n)||Xe(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return st(n)===t&&(t=t.ownerDocument.body),t}function ig(n,e){let t=Pe(n);if(Ui(n))return t;if(!ft(n)){let i=Dt(n);for(;i&&!Vn(i);){if(Qe(i)&&!uu(i))return i;i=Dt(i)}return t}let r=Zm(n,e);for(;r&&Jm(r)&&uu(r);)r=Zm(r,e);return r&&Vn(r)&&uu(r)&&!qs(r)?t:r||Gm(n)||t}var F1=async function(n){let e=this.getOffsetParent||ig,t=this.getDimensions,r=await t(n.floating);return{reference:z1(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function _1(n){return Xe(n).direction==="rtl"}var V1={convertOffsetParentRelativeRectToViewportRelativeRect:E1,getDocumentElement:st,getClippingRect:L1,getOffsetParent:ig,getElementRects:F1,getClientRects:A1,getDimensions:B1,getScale:zr,isElement:Qe,isRTL:_1};function og(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function $1(n,e){let t=null,r,i=st(n);function o(){var l;clearTimeout(r),(l=t)==null||l.disconnect(),t=null}function s(l,a){l===void 0&&(l=!1),a===void 0&&(a=1),o();let c=n.getBoundingClientRect(),{left:u,top:f,width:d,height:h}=c;if(l||e(),!d||!h)return;let p=Hi(f),m=Hi(i.clientWidth-(u+d)),k=Hi(i.clientHeight-(f+h)),x=Hi(u),C={rootMargin:-p+"px "+-m+"px "+-k+"px "+-x+"px",threshold:Rt(0,Pr(1,a))||1},A=!0;function v(b){let T=b[0].intersectionRatio;if(T!==a){if(!A)return s();T?s(!1,T):r=setTimeout(()=>{s(!1,1e-7)},1e3)}T===1&&!og(c,n.getBoundingClientRect())&&s(),A=!1}try{t=new IntersectionObserver(v,{...C,root:i.ownerDocument})}catch{t=new IntersectionObserver(v,C)}t.observe(n)}return s(!0),o}function hu(n,e,t,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:o=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:a=!1}=r,c=fu(n),u=i||o?[...c?Lr(c):[],...e?Lr(e):[]]:[];u.forEach(x=>{i&&x.addEventListener("scroll",t,{passive:!0}),o&&x.addEventListener("resize",t)});let f=c&&l?$1(c,t):null,d=-1,h=null;s&&(h=new ResizeObserver(x=>{let[I]=x;I&&I.target===c&&h&&e&&(h.unobserve(e),cancelAnimationFrame(d),d=requestAnimationFrame(()=>{var C;(C=h)==null||C.observe(e)})),t()}),c&&!a&&h.observe(c),e&&h.observe(e));let p,m=a?$n(n):null;a&&k();function k(){let x=$n(n);m&&!og(m,x)&&t(),m=x,p=requestAnimationFrame(k)}return t(),()=>{var x;u.forEach(I=>{i&&I.removeEventListener("scroll",t),o&&I.removeEventListener("resize",t)}),f?.(),(x=h)==null||x.disconnect(),h=null,a&&cancelAnimationFrame(p)}}var sg=Hm;var lg=qm,ag=jm;var cg=(n,e,t)=>{let r=new Map,i={platform:V1,...t},o={...i.platform,_c:r};return Wm(n,e,{...i,platform:o})};var du=class{constructor(e){this.#o=!1,this.onShow=()=>{},this.onHide=()=>{},this.#c=t=>{cg(t,this.element,{placement:this.#n.placement??"top",middleware:[ag(),sg(this.#l),lg(this.#a),...this.#r],...this.#n}).then(({x:r,y:i})=>{Object.assign(this.element.style,{left:`${r}px`,top:`${i}px`})}).catch(console.error)},this.#u=t=>this.#s!==t.dom.parentElement,this.#d=(t,r)=>{let{state:i,composing:o}=t,{selection:s,doc:l}=i,{ranges:a}=s,c=Math.min(...a.map(h=>h.$from.pos)),u=Math.max(...a.map(h=>h.$to.pos)),f=r&&r.doc.eq(l)&&r.selection.eq(s);if(this.#o||((this.#s??t.dom.parentElement??document.body).appendChild(this.element),this.#o=!0),o||f)return;if(this.#i?.(),this.#i=void 0,!this.#e(t,r)){this.hide();return}let d={getBoundingClientRect:()=>bd(t,c,u),contextElement:t.dom};this.#u(t)?this.#i=hu(d,this.element,()=>this.#c(d)):this.#c(d),this.show()},this.update=(t,r)=>{this.#h(t,r)},this.destroy=()=>{this.#i?.(),this.#h.cancel()},this.show=(t,r)=>{if(this.element.dataset.show="true",t){this.#i?.(),this.#i=void 0;let i={...t,contextElement:r?.dom};r&&this.#u(r)?this.#i=hu(i,this.element,()=>this.#c(i)):this.#c(i)}this.onShow()},this.hide=()=>{this.element.dataset.show!=="false"&&(this.element.dataset.show="false",this.onHide())},this.element=e.content,this.#t=e.debounce??200,this.#e=e.shouldShow??this.#f,this.#l=e.offset,this.#a=e.shift,this.#r=e.middleware??[],this.#n=e.floatingUIOptions??{},this.#s=e.root,this.element.dataset.show="false",this.#h=ru(this.#d,this.#t)}#t;#e;#r;#n;#s;#o;#i;#l;#a;#h;#c;#u;#d;#f(e){let{doc:t,selection:r}=e.state,{empty:i,from:o,to:s}=r,l=!t.textBetween(o,s).length&&e.state.selection instanceof j,a=this.element.contains(document.activeElement),c=!e.hasFocus()&&!a,u=!e.editable;return!(c||i||l||u)}};function W1(n){let e=$e({},`${n}_TOOLTIP_SPEC`),t=ut(i=>{let o=i.get(e.key);return new ne({key:new re(`${n}_TOOLTIP`),...o})}),r=[e,t];return r.key=e.key,r.pluginKey=t.key,e.meta={package:"@milkdown/plugin-tooltip",displayName:`Ctx<tooltipSpec>|${n}`},t.meta={package:"@milkdown/plugin-tooltip",displayName:`Prose<tooltip>|${n}`},r}var Gs=200,ge=function(){};ge.prototype.append=function(e){return e.length?(e=ge.from(e),!this.length&&e||e.length<Gs&&this.leafAppend(e)||this.length<Gs&&e.leafPrepend(this)||this.appendInner(e)):this};ge.prototype.prepend=function(e){return e.length?ge.from(e).append(this):this};ge.prototype.appendInner=function(e){return new j1(this,e)};ge.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ge.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};ge.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};ge.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};ge.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,r),i};ge.from=function(e){return e instanceof ge?e:e&&e.length?new ug(e):ge.empty};var ug=(function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={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,l){for(var a=o;a<s;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,l){for(var a=o-1;a>=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=Gs)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Gs)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(ge);ge.empty=new ug([]);var j1=(function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.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 l=this.left.length;if(i<l&&this.left.forEachInner(r,i,Math.min(o,l),s)===!1||o>l&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o<l&&this.left.forEachInvertedInner(r,Math.min(i,l),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})(ge),pu=ge;var H1=500,jn=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){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;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,a,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 ht(f.map));let h=f.step.map(i.slice(o)),p;h&&s.maybeStep(h).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],c.push(new ht(p,void 0,void 0,c.length+u.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(o)):f.selection,a=new n(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),d=new ht(e.mapping.maps[u],f,t),h;(h=a&&a.merge(d))&&(d=h,u?o.pop():l=l.slice(0,l.length-1)),o.push(d),t&&(s++,t=void 0),i||(a=d)}let c=s-r.depth;return c>K1&&(l=q1(l,c),s-=c),new n(l.append(o),s)}remapping(e,t){let r=new Xr;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,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new ht(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let h=o.getMirror(--a);if(h==null)return;s=Math.min(s,h);let p=o.maps[h];if(d.step){let m=e.steps[h].invert(e.docs[h]),k=d.selection&&d.selection.map(o.slice(a+1,h));k&&l++,r.push(new ht(p,m,k))}else r.push(new ht(p))},i);let c=[];for(let d=t;d<s;d++)c.push(new ht(o.maps[d]));let u=this.items.slice(0,i).append(c).append(r),f=new n(u,l);return f.emptyItemCount()>H1&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let u=s.selection&&s.selection.map(t.slice(r));u&&o++;let f=new ht(c.invert(),a,u),d,h=i.length-1;(d=i.length&&i[h].merge(f))?i[h]=d:i.push(f)}}else s.map&&r--},this.items.length,0),new n(pu.from(i.reverse()),o)}};jn.empty=new jn(pu.empty,0);function q1(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var ht=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},dt=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},K1=20;function U1(n,e,t,r){let i=t.getMeta(Wn),o;if(i)return i.historyState;t.getMeta(Y1)&&(n=new dt(n.done,n.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(s&&s.getMeta(Wn))return s.getMeta(Wn).redo?new dt(n.done.addTransform(t,void 0,r,Ys(e)),n.undone,fg(t.mapping.maps),n.prevTime,n.prevComposition):new dt(n.done,n.undone.addTransform(t,void 0,r,Ys(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!s&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!J1(t,n.prevRanges)),c=s?mu(n.prevRanges,t.mapping):fg(t.mapping.maps);return new dt(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,Ys(e)),jn.empty,c,t.time,l??n.prevComposition)}else return(o=t.getMeta("rebased"))?new dt(n.done.rebased(t,o),n.undone.rebased(t,o),mu(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new dt(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),mu(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function J1(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let o=0;o<e.length;o+=2)r<=e[o+1]&&i>=e[o]&&(t=!0)}),t}function fg(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,o,s)=>e.push(o,s));return e}function mu(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let i=e.map(n[r],1),o=e.map(n[r+1],-1);i<=o&&t.push(i,o)}return t}function G1(n,e,t){let r=Ys(e),i=Wn.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),a=new dt(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(Wn,{redo:t,historyState:a})}var gu=!1,hg=null;function Ys(n){let e=n.plugins;if(hg!=e){gu=!1,hg=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){gu=!0;break}}return gu}var Wn=new re("history"),Y1=new re("closeHistory");function dg(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ne({key:Wn,state:{init(){return new dt(jn.empty,jn.empty,null,0,-1)},apply(e,t,r){return U1(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,i=r=="historyUndo"?yu:r=="historyRedo"?xu:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function Qs(n,e){return(t,r)=>{let i=Wn.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let o=G1(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var yu=Qs(!1,!0),xu=Qs(!0,!0),BR=Qs(!1,!1),zR=Qs(!0,!1);function Fr(n,e){return Object.assign(n,{meta:{package:"@milkdown/plugin-history",...e}}),n}var Xs=J("Undo",()=>()=>yu);Fr(Xs,{displayName:"Command<undo>"});var Zs=J("Redo",()=>()=>xu);Fr(Zs,{displayName:"Command<redo>"});var ku=$e({},"historyProviderConfig");Fr(ku,{displayName:"Ctx<historyProviderConfig>"});var pg=ut(n=>dg(n.get(ku.key)));Fr(pg,{displayName:"Ctx<historyProviderPlugin>"});var bu=De("historyKeymap",{Undo:{shortcuts:"Mod-z",command:n=>{let e=n.get(G);return()=>e.call(Xs.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:n=>{let e=n.get(G);return()=>e.call(Zs.key)}}});Fr(bu.ctx,{displayName:"KeymapCtx<history>"});Fr(bu.shortcuts,{displayName:"Keymap<history>"});var Q1=[ku,pg,bu,Xs,Zs].flat();var el=class{constructor(e,t,r){this.step=e,this.inverted=t,this.origin=r}};function X1(n,e,t){for(let i=n.length-1;i>=0;i--)t.step(n[i].inverted);for(let i=0;i<e.length;i++)t.step(e[i]);let r=[];for(let i=0,o=n.length;i<n.length;i++){let s=n[i].step.map(t.mapping.slice(o));o--,s&&!t.maybeStep(s).failed&&(t.mapping.setMirror(o,t.steps.length-1),r.push(new el(s,s.invert(t.docs[t.docs.length-1]),n[i].origin)))}return r}var _r=class{constructor(e,t){this.version=e,this.unconfirmed=t}};function Z1(n){let e=[];for(let t=0;t<n.steps.length;t++)e.push(new el(n.steps[t],n.steps[t].invert(n.docs[t]),n));return e}var Pt=new re("collab");function eS(n={}){let e={version:n.version||0,clientID:n.clientID==null?Math.floor(Math.random()*4294967295):n.clientID};return new ne({key:Pt,state:{init:()=>new _r(e.version,[]),apply(t,r){let i=t.getMeta(Pt);return i||(t.docChanged?new _r(r.version,r.unconfirmed.concat(Z1(t))):r)}},config:e,historyPreserveItems:!0})}function tS(n,e,t,r={}){let i=Pt.getState(n),o=i.version+e.length,s=Pt.get(n).spec.config.clientID,l=0;for(;l<t.length&&t[l]==s;)++l;let a=i.unconfirmed.slice(l);if(e=l?e.slice(l):e,!e.length)return n.tr.setMeta(Pt,new _r(o,a));let c=a.length,u=n.tr;if(c)a=X1(a,e,u);else{for(let d=0;d<e.length;d++)u.step(e[d]);a=[]}let f=new _r(o,a);return r&&r.mapSelectionBackward&&n.selection instanceof j&&(u.setSelection(j.between(u.doc.resolve(u.mapping.map(n.selection.anchor,-1)),u.doc.resolve(u.mapping.map(n.selection.head,-1)),-1)),u.updated&=-2),u.setMeta("rebased",c).setMeta("addToHistory",!1).setMeta(Pt,f)}function nS(n){let e=Pt.getState(n);return e.unconfirmed.length==0?null:{version:e.version,steps:e.unconfirmed.map(t=>t.step),clientID:Pt.get(n).spec.config.clientID,get origins(){return this._origins||(this._origins=e.unconfirmed.map(t=>t.origin))}}}function rS(n){return Pt.getState(n).version}export{dc as Editor,ae as Step,du as TooltipProvider,c0 as callCommand,eS as collab,B0 as commonmark,gs as defaultValueCtx,rt as editorViewCtx,Cs as editorViewOptionsCtx,rS as getVersion,Q1 as history,Dm as listener,iu as listenerCtx,it as prosePluginsCtx,tS as receiveTransaction,Zs as redoCommand,Ms as rootCtx,nS as sendableSteps,Rn as serializerCtx,Ds as toggleEmphasisCommand,Ps as toggleStrongCommand,W1 as tooltipFactory,Bs as turnIntoTextCommand,Xs as undoCommand,Fs as wrapInBlockquoteCommand,_s as wrapInBulletListCommand,At as wrapInHeadingCommand}; 47 47 /*! Bundled license information: 48 48 49 49 lodash-es/lodash.js:
+7 -7
templates/document_edit.html
··· 95 95 <script type="module"> 96 96 import {EditorView, basicSetup, markdown, oneDark, Compartment, Annotation} from '/static/vendor/editor.js'; 97 97 import { 98 - Editor, rootCtx, defaultValueCtx, editorViewCtx, editorViewOptionsCtx, serializerCtx, 98 + Editor, rootCtx, defaultValueCtx, editorViewCtx, serializerCtx, prosePluginsCtx, 99 99 commonmark, 100 100 listener, listenerCtx, 101 101 history, undoCommand, redoCommand, callCommand, ··· 319 319 .config((ctx) => { 320 320 ctx.set(rootCtx, container); 321 321 ctx.set(defaultValueCtx, initialMarkdown); 322 - // Register the prosemirror-collab plugin so sendableSteps/receiveTransaction 323 - // have a state slot to read from. 324 - ctx.update(editorViewOptionsCtx, (prev) => ({ 325 - ...prev, 326 - plugins: [...(prev.plugins || []), collab({ version: collabClient.version })], 327 - })); 322 + // Register the prosemirror-collab plugin into EditorState (not EditorView) 323 + // so sendableSteps/receiveTransaction have a state slot to read from. 324 + ctx.update(prosePluginsCtx, (plugins) => [ 325 + ...plugins, 326 + collab({ version: collabClient.version }), 327 + ]); 328 328 }) 329 329 .use(commonmark) 330 330 .use(history)