@hjd-hitsz/claudex-web 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +3 -3
- package/build-info.json +4 -4
- package/client/dist/app.js +148 -116
- package/client/dist/code-highlight-style.js +23 -45
- package/client/dist/document-editor.js +14 -14
- package/client/dist/style.css +1 -1
- package/docs/architecture/backends.md +3 -1
- package/docs/architecture/behavior.md +24 -16
- package/docs/background-tasks.md +5 -3
- package/docs/deployment.md +9 -9
- package/docs/development.md +21 -5
- package/docs/images/desktop-dark.png +0 -0
- package/docs/images/desktop-light.png +0 -0
- package/docs/images/mobile-sidebar.png +0 -0
- package/docs/images/mobile.png +0 -0
- package/docs/releases/v4.2.0.md +2 -0
- package/docs/releases/v4.2.1.md +15 -0
- package/docs/versioning.md +6 -6
- package/package.json +1 -1
- package/packages/background-terminal/background-protocol.mjs +13 -3
- package/packages/background-terminal/delivery.mjs +3 -1
- package/packages/translation-engine/package.json +1 -1
- package/server/src/backends/codex/adapter.mjs +15 -6
- package/server/src/backends/codex/background-terminals.mjs +12 -0
- package/server/src/backends/codex/events.mjs +14 -1
- package/server/src/backends/codex/requests.mjs +16 -0
- package/server/src/backends/codex/streaming-messages.mjs +50 -0
|
@@ -1,48 +1,26 @@
|
|
|
1
|
-
var Nu=i=>{throw TypeError(i)};var Du=(i,e,t)=>e.has(i)||Nu("Cannot "+t);var F=(i,e,t)=>(Du(i,e,"read from private field"),t?t.call(i):e.get(i)),ae=(i,e,t)=>e.has(i)?Nu("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),re=(i,e,t,n)=>(Du(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);import{a1 as Iu,a2 as t1,a3 as n1,a4 as i1,a5 as Eu,a6 as r1,a7 as s1,a8 as ir,a9 as o1,aa as Nm,ab as l1,ac as a1,ad as h1,ae as c1,af as ch,ag as fh,ah as Us,ai as uh,aj as f1}from"./app.js";const u1={}.hasOwnProperty;function Dm(i,e){let t=-1,n;if(e.extensions)for(;++t<e.extensions.length;)Dm(i,e.extensions[t]);for(n in e)if(u1.call(e,n))switch(n){case"extensions":break;case"unsafe":{Ru(i[n],e[n]);break}case"join":{Ru(i[n],e[n]);break}case"handlers":{d1(i[n],e[n]);break}default:i.options[n]=e[n]}return i}function Ru(i,e){e&&i.push(...e)}function d1(i,e){e&&Object.assign(i,e)}function dh(i){if(i.charCodeAt(0)!==60)return;const e=i.charCodeAt(1);if(e===33){const l=i.charCodeAt(2);return l===45?2:l===91?5:Iu(l)?4:void 0}if(e===63)return 3;const t=e===47,n=t?2:1;let r=n,s=i.charCodeAt(r);if(!Iu(s))return;for(;s===45||t1(s);)s=i.charCodeAt(++r);const o=i.slice(n,r).toLowerCase();return!t&&s!==47&&n1.includes(o)?1:i1.includes(o)?6:7}const p1=[m1];function m1(i,e,t,n){if(e.type==="code"&&Eu(e,n)&&(i.type==="list"||i.type===e.type&&Eu(i,n)))return!1;if("spread"in t&&typeof t.spread=="boolean"){if(i.type==="paragraph"&&(i.type===e.type||e.type==="definition"||e.type==="heading"&&r1(e,n)))return;if(i.type==="html"){const r=dh(i.value);if(r===void 0||r===6||r===7)return 1}if(i.type==="paragraph"&&e.type==="html"){const r=dh(e.value);if(r===void 0||r===7)return 1}return t.spread?1:0}}const Gn=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],Im=[{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:`
|
|
2
|
-
`,inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:"\r",before:"[\\r\\n]",inConstruct:"phrasing"},{character:"\r",after:"\\r",inConstruct:"phrasing"},{character:`
|
|
3
|
-
|
|
4
|
-
`,after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"!",after:"\\[",inConstruct:"phrasing",notInConstruct:Gn},{character:'"',inConstruct:"titleQuote"},{atBreak:!0,character:"#"},{character:"#",inConstruct:"headingAtx",after:`(?:[\r
|
|
5
|
-
]|$)`},{character:"&",after:"[#A-Za-z]",inConstruct:"phrasing"},{character:"'",inConstruct:"titleApostrophe"},{character:"(",inConstruct:"destinationRaw"},{before:"\\]",character:"(",inConstruct:"phrasing",notInConstruct:Gn},{atBreak:!0,before:"\\d+",character:")"},{character:")",inConstruct:"destinationRaw"},{atBreak:!0,character:"*",after:`(?:[ \r
|
|
6
|
-
|
|
7
|
-
])
|
|
8
|
-
-])`},{atBreak:!0,before:"\\d+",character:".",after:`(?:[ \r
|
|
9
|
-
]|$)`},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:Gn},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:Gn},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:Gn},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:Gn},{atBreak:!0,character:"~"},{character:"<",inConstruct:"autolink"},{character:">",inConstruct:"autolink"},{character:"",inConstruct:"autolink"}];let Bu=-1;for(;++Bu<33;)Im.push({character:String.fromCharCode(Bu),inConstruct:"autolink"});function g1(i){return i.label||!i.identifier?i.label||"":s1(i.identifier)}function y1(i){if(!i._compiled){const e=(i.atBreak?"[\\r\\n][\\t ]*":"")+(i.before?"(?:"+i.before+")":"");i._compiled=new RegExp((i.beforeNode?"^":e?"("+e+")":"")+(/[$()*+.?[\\\]^{|}]/.test(i.character)?"\\":"")+i.character+(i.afterNode?"$":i.after?"(?:"+i.after+")":""),i.unicode?"gu":"g")}return i._compiled}function sl(i){const e=i.codePointAt(0);return e===void 0?"":String.fromCodePoint(e)}function jr(i){const e=i.codePointAt(i.length-2);return e!==void 0&&e>65535?i.slice(-2):i.slice(-1)}function Pu(i,e,t){const n=ir(i),r=ir(e);return n===void 0?r===void 0?t==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:r===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:n===1?r===void 0?{inside:!1,outside:!1}:r===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:r===void 0?{inside:!1,outside:!1}:r===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}const b1=new Map([["*",!1],["_",!0]]);function k1(i,e,t){const n=new Set;for(const s of i){const o=t.get(s);if(o&&s.attention&&e.some(l=>l.attention===s.attention))for(const l of o.tokens)n.add(l.attention)}const r=[];for(const s of i)s.attention&&n.delete(s.attention)&&r.push(s.attention);return r.reverse(),r}function Em(i,e,t){const n=[],r=new Map,s=new Map;let o=0;for(;o<i.length;){if(!i[o].attention){o++;continue}const l=i[o].value.charAt(0),a=b1.get(l);let h=o+1;for(;h<i.length&&i[h].attention&&i[h].value.charAt(0)===l;)h++;const c=o?i[o-1].value:e,f=ir(c.charCodeAt(c.length-1)),u=ir((h<i.length?i[h].value:t).charCodeAt(0)),d=!u||u===2&&!!f,p=!f||f===2&&!!u,m={tokens:i.slice(o,h),markers:[],start:0,end:0,open:a?d&&(!!f||!p):d,close:a?p&&(!!u||!d):p,split:a!==void 0};for(const g of m.tokens){r.set(g,[...m.tokens]),s.set(g,m);let y=g.value.length;for(;y--;)m.markers.push(g)}m.end=m.markers.length,n.push(m),o=h}for(S1(n,r),o=-1;++o<i.length;){const l=r.get(i[o]);if(l)return{attention:k1(i,l,s),index:o}}}function x1(i,e,t){return ph(Rm(i,e,t),t.before,t.after)}function go(i,e){const t=i[e?0:i.length-1];if(!t||t.attention)return;const n=e?sl(t.value):jr(t.value),r=Nm(n.codePointAt(0));t.value=e?r+t.value.slice(n.length):t.value.slice(0,t.value.length-n.length)+r}function w1(i,e,t,n,r){for(const s of t.attention){const o=e.get(s)||s.sequences[0];for(const l of s.sequences){if(l===o)continue;const a=new Map(e);a.set(s,l);const h=Rc(i,a,n,r),c=Em(h,n,r);if(!c||c.index>t.index)return{chosen:a,mistake:c,tokens:h}}}}function S1(i,e){let t=0;for(;t<i.length;){const n=i[t],r=n.tokens[0].value.charAt(0),s=n.end-n.start;let o=n.close&&s?t:0;for(;o--;){const l=i[o],a=l.end-l.start;if(l.tokens[0].value.charAt(0)===r&&l.open&&a&&(n.split?!((l.close||n.open)&&s%3)||(a+s)%3:a===l.markers.length&&a===s)){const h=n.split?a>1&&s>1?2:1:s,c=l.markers.slice(l.end-h,l.end),f=n.markers.slice(n.start,n.start+h),u=c[0],d=f[0];if(u===c[h-1]&&u.value.length===h&&d===f[h-1]&&d.value.length===h&&u.attention===d.attention)e.delete(u),e.delete(d);else{const p=[...new Set([...c,...f])];for(const m of p){const g=e.get(m);g&&g.push(...p)}}l.end-=h,n.start+=h;break}}(o===-1||n.start===n.end)&&t++}}function C1(i,e,t){if(e.length===0)throw new Error("Cannot serialize `"+i+"` as attention without markers, expected one or more markers");if(t.length===0)throw new Error("Cannot serialize `"+i+"` as attention without sizes, expected one or more sizes");for(const r of t)if(!Number.isSafeInteger(r)||r<1)throw new Error("Cannot serialize `"+i+"` as attention with `"+r+"` as size, expected positive integer");const n=[];for(const r of e){if(r.length!==1)throw new Error("Cannot serialize `"+i+"` as attention with `"+r+"` as marker, expected a single ascii character");if(!o1(r.charCodeAt(0)))throw new Error("Cannot serialize `"+i+"` as attention with `"+r+"` as marker, expected ascii punctuation");for(const s of t)n.push(r.repeat(s))}return n}function Rm(i,e,t){const n=e.indexStack,r=i.children||[],s=[];let o=-1,l=t.before;n.push(-1);let a=e.createTracker(t);for(;++o<r.length;){const h=r[o];let c;if(n[n.length-1]=o,o+1<r.length){let d=e.handle.handlers[r[o+1].type];d&&d.peek&&(d=d.peek),c=d?sl(d(r[o+1],i,e,{before:"",after:"",...a.current()})):""}else c=t.after;const f=s[s.length-1];typeof f=="string"&&(l==="\r"||l===`
|
|
10
|
-
`)&&h.type==="html"&&dh(h.value)!==7&&(s[s.length-1]=f.replace(/(\r?\n|\r)$/," "),l=" ",a=e.createTracker(t),a.move(ph(s,t.before,t.after)));const u=e.handle.handlers[h.type];if(u&&u.attention){const{construct:d,markers:p,sizes:m}=u.attention(h,e),g=C1(h.type,p,m),y=g[0],b=e.enter(d);a.move(y);const k=Rm(h,e,{...a.current(),before:y,after:y});a.move(ph(k,y,y)),a.move(y),b(),s.push({children:k,sequences:g}),l=y.charAt(y.length-1)}else{const d=e.handle(h,i,e,{...a.current(),after:c,before:l});if(!d)continue;a.move(d),s.push(d),l=jr(d)}}return n.pop(),s}function Rc(i,e,t,n){const r=[];let s,o=jr(t),l=-1;for(;++l<i.length;){const a=i[l];if(typeof a=="string"){const k={value:a,attention:void 0};s&&s===sl(a)&&go([k],!0),s=void 0,r.push(k),k.value&&(o=jr(k.value));continue}const h=e.get(a)||a.sequences[0],c=h.charAt(0),f=i[l+1],u=o,d=sl(f===void 0?n:typeof f=="string"?f:e.get(f)||f.sequences[0]),p=Rc(a.children,e,h,h),m=p.length>0?p[0].value:"",g=Pu(u.charCodeAt(u.length-1),m.charCodeAt(0),c);g.inside&&go(p,!0);const y=p.length>0?jr(p[p.length-1].value):"",b=Pu(d.charCodeAt(0),y.charCodeAt(y.length-1),c);b.inside&&go(p,!1),g.outside&&u!==`
|
|
11
|
-
`&&u!=="\r"&&go(r,!1),b.outside&&(s=d),r.push({value:h,attention:a},...p,{value:h,attention:a}),o=h.charAt(h.length-1)}return r}function ph(i,e,t){let n=new Map;const r=Rc(i,n,e,t);let s=r,o=Em(s,e,t);for(;o;){const a=w1(i,n,o,e,t);if(!a){s=r;break}n=a.chosen,s=a.tokens,o=a.mistake}let l="";for(const a of s)l+=a.value;return l}function v1(i,e,t){const n=e.indexStack,r=i.children||[],s=e.createTracker(t),o=[];let l=-1;for(n.push(-1);++l<r.length;){const a=r[l];n[n.length-1]=l,o.push(s.move(e.handle(a,i,e,{before:`
|
|
12
|
-
`,after:`
|
|
13
|
-
`,...s.current()}))),a.type!=="list"&&(e.bulletLastUsed=void 0),l<r.length-1&&o.push(s.move(M1(a,r[l+1],i,e)))}return n.pop(),o.join("")}function M1(i,e,t,n){let r=n.join.length;for(;r--;){const s=n.join[r](i,e,t,n);if(s===!0||s===1)break;if(typeof s=="number")return`
|
|
14
|
-
`.repeat(1+s);if(s===!1)return`
|
|
1
|
+
var xu=i=>{throw TypeError(i)};var wu=(i,e,t)=>e.has(i)||xu("Cannot "+t);var F=(i,e,t)=>(wu(i,e,"read from private field"),t?t.call(i):e.get(i)),ae=(i,e,t)=>e.has(i)?xu("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),re=(i,e,t,n)=>(wu(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);import{a1 as Bk,a2 as rh,a3 as sh,a4 as js,a5 as oh,a6 as Pk}from"./app.js";function Se(i){this.content=i}Se.prototype={constructor:Se,find:function(i){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===i)return e;return-1},get:function(i){var e=this.find(i);return e==-1?void 0:this.content[e+1]},update:function(i,e,t){var n=t&&t!=i?this.remove(t):this,r=n.find(i),s=n.content.slice();return r==-1?s.push(t||i,e):(s[r+1]=e,t&&(s[r]=t)),new Se(s)},remove:function(i){var e=this.find(i);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Se(t)},addToStart:function(i,e){return new Se([i,e].concat(this.remove(i).content))},addToEnd:function(i,e){var t=this.remove(i).content.slice();return t.push(i,e),new Se(t)},addBefore:function(i,e,t){var n=this.remove(e),r=n.content.slice(),s=n.find(i);return r.splice(s==-1?r.length:s,0,e,t),new Se(r)},forEach:function(i){for(var e=0;e<this.content.length;e+=2)i(this.content[e],this.content[e+1])},prepend:function(i){return i=Se.from(i),i.size?new Se(i.content.concat(this.subtract(i).content)):this},append:function(i){return i=Se.from(i),i.size?new Se(this.subtract(i).content.concat(i.content)):this},subtract:function(i){var e=this;i=Se.from(i);for(var t=0;t<i.content.length;t+=2)e=e.remove(i.content[t]);return e},toObject:function(){var i={};return this.forEach(function(e,t){i[e]=t}),i},get size(){return this.content.length>>1}};Se.from=function(i){if(i instanceof Se)return i;var e=[];if(i)for(var t in i)e.push(t,i[t]);return new Se(e)};function dm(i,e,t){for(let n=0;;n++){if(n==i.childCount||n==e.childCount)return i.childCount==e.childCount?null:t;let r=i.child(n),s=e.child(n);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){let o=r.text,l=s.text,a=0;for(;o[a]==l[a];a++)t++;return a&&a<o.length&&a<l.length&&gm(o.charCodeAt(a-1))&&mm(o.charCodeAt(a))&&t--,t}if(r.content.size||s.content.size){let o=dm(r.content,s.content,t+1);if(o!=null)return o}t+=r.nodeSize}}function pm(i,e,t,n){for(let r=i.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:n};let o=i.child(--r),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let h=o.text,c=l.text,f=h.length,u=c.length;for(;f>0&&u>0&&h[f-1]==c[u-1];)f--,u--,t--,n--;return f&&u&&f<h.length&&gm(h.charCodeAt(f-1))&&mm(h.charCodeAt(f))&&(t++,n++),{a:t,b:n}}if(o.content.size||l.content.size){let h=pm(o.content,l.content,t-1,n-1);if(h)return h}t-=a,n-=a}}function mm(i){return i>=56320&&i<57344}function gm(i){return i>=55296&&i<56320}class A{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,r=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],h=l+a.nodeSize;if(h>e&&n(a,r+l,s||null,o)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),n,r+c)}l=h}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let h=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&h||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=h},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),s=1);s<e.content.length;s++)r.push(e.content[s]);return new A(r,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let n=[],r=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),r+=l.nodeSize),o=a}return new A(n,r)}cutByIndex(e,t){return e==t?A.empty:e==0&&t==this.content.length?this:new A(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new A(r,s)}addToStart(e){return new A([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new A(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return dm(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return pm(this,e,t,n)}findIndex(e){if(e==0)return uo(0,e);if(e==this.size)return uo(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),s=n+r.nodeSize;if(s>=e)return s==e?uo(t+1,s):uo(t,n);n=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return A.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return A.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return A.empty;let t,n=0;for(let r=0;r<e.length;r++){let s=e[r];n+=s.nodeSize,r&&s.isText&&e[r-1].sameMarkup(s)?(t||(t=e.slice(0,r)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new A(t||e,n)}static from(e){if(!e)return A.empty;if(e instanceof A)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new A([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}A.empty=new A([],0);const oa={index:0,offset:0};function uo(i,e){return oa.index=i,oa.offset=e,oa}function tl(i,e){if(i===e)return!0;if(!(i&&typeof i=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(i);if(Array.isArray(e)!=t)return!1;if(t){if(i.length!=e.length)return!1;for(let n=0;n<i.length;n++)if(!tl(i[n],e[n]))return!1}else{for(let n in i)if(!(n in e)||!tl(i[n],e[n]))return!1;for(let n in e)if(!(n in i))return!1}return!0}class j{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&tl(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);return n.create(t.attrs)}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return j.none;if(e instanceof j)return[e];let t=e.slice();return t.sort((n,r)=>n.type.rank-r.type.rank),t}}j.none=[];class ls extends Error{}let E=class Ei{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=bm(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new Ei(n,this.openStart,this.openEnd)}removeBetween(e,t){return new Ei(ym(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return Ei.empty;let n=t.openStart||0,r=t.openEnd||0;if(typeof n!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Ei(A.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new Ei(e,n,r)}};E.empty=new E(A.empty,0,0);function ym(i,e,t){let{index:n,offset:r}=i.findIndex(e),s=i.maybeChild(n),{index:o,offset:l}=i.findIndex(t);if(r==e||s.isText){if(l!=t&&!i.child(o).isText)throw new RangeError("Removing non-flat range");return i.cut(0,e).append(i.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return i.replaceChild(n,s.copy(ym(s.content,e-r-1,t-r-1)))}function bm(i,e,t,n,r,s){let{index:o,offset:l}=i.findIndex(e),a=i.maybeChild(o);if(l==e||a.isText)return s&&n<=0&&r<=0&&!s.canReplace(o,o,t)?null:i.cut(0,e).append(t).append(i.cut(e));let h=bm(a.content,e-l-1,t,o==0?n-1:0,o==i.childCount-1?r-1:0,a);return h&&i.replaceChild(o,a.copy(h))}function Lk(i,e,t){if(t.openStart>i.depth)throw new ls("Inserted content deeper than insertion position");if(i.depth-t.openStart!=e.depth-t.openEnd)throw new ls("Inconsistent open depths");return km(i,e,t,0)}function km(i,e,t,n){let r=i.index(n),s=i.node(n);if(r==e.index(n)&&n<i.depth-t.openStart){let o=km(i,e,t,n+1);return s.copy(s.content.replaceChild(r,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&i.depth==n&&e.depth==n){let o=i.parent,l=o.content;return si(o,l.cut(0,i.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Fk(t,i);return si(s,wm(i,o,l,e,n))}else return si(s,nl(i,e,n))}function xm(i,e){if(!e.type.compatibleContent(i.type))throw new ls("Cannot join "+e.type.name+" onto "+i.type.name)}function lh(i,e,t){let n=i.node(t);return xm(n,e.node(t)),n}function ri(i,e){let t=e.length-1;t>=0&&i.isText&&i.sameMarkup(e[t])?e[t]=i.withText(e[t].text+i.text):e.push(i)}function Kr(i,e,t,n){let r=(e||i).node(t),s=0,o=e?e.index(t):r.childCount;i&&(s=i.index(t),i.depth>t?s++:i.textOffset&&(ri(i.nodeAfter,n),s++));for(let l=s;l<o;l++)ri(r.child(l),n);e&&e.depth==t&&e.textOffset&&ri(e.nodeBefore,n)}function si(i,e){if(!i.type.validContent(e))throw new ls("Invalid content for node "+i.type.name);return i.copy(e)}function wm(i,e,t,n,r){let s=i.depth>r&&lh(i,e,r+1),o=n.depth>r&&lh(t,n,r+1),l=[];return Kr(null,i,r,l),s&&o&&e.index(r)==t.index(r)?(xm(s,o),ri(si(s,wm(i,e,t,n,r+1)),l)):(s&&ri(si(s,nl(i,e,r+1)),l),Kr(e,t,r,l),o&&ri(si(o,nl(t,n,r+1)),l)),Kr(n,null,r,l),new A(l)}function nl(i,e,t){let n=[];if(Kr(null,i,t,n),i.depth>t){let r=lh(i,e,t+1);ri(si(r,nl(i,e,t+1)),n)}return Kr(e,null,t,n),new A(n)}function Fk(i,e){let t=e.depth-i.openStart,r=e.node(t).copy(i.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(A.from(r));return{start:r.resolveNoCache(i.openStart+t),end:r.resolveNoCache(r.content.size-i.openEnd-t)}}class as{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=n.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return j.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let l=n;n=r,r=l}let s=n.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!r||!s[o].isInSet(r.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<n.length;s++)n[s].type.spec.inclusive===!1&&(!r||!n[s].isInSet(r.marks))&&(n=n[s--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Sm(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],r=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),h=s-a;if(n.push(o,l,r+a),!h||(o=o.child(l),o.isText))break;s=h-1,r+=a+1}return new as(t,n,s)}static resolveCached(e,t){let n=Su.get(e);if(n)for(let s=0;s<n.elts.length;s++){let o=n.elts[s];if(o.pos==t)return o}else Su.set(e,n=new Vk);let r=n.elts[n.i]=as.resolve(e,t);return n.i=(n.i+1)%zk,r}}class Vk{constructor(){this.elts=[],this.i=0}}const zk=12,Su=new WeakMap;class Sm{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const Hk=Object.create(null);class yt{constructor(e,t,n,r=j.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||A.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&tl(this.attrs,t||e.defaultAttrs||Hk)&&j.sameSet(this.marks,n||j.none)}copy(e=null){return e==this.content?this:new yt(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new yt(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return E.empty;let r=this.resolve(e),s=this.resolve(t),o=n?0:r.sharedDepth(t),l=r.start(o),h=r.node(o).content.cut(r.pos-l,s.pos-l);return new E(h,r.depth-o,s.depth-o)}replace(e,t,n){return Lk(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return as.resolveCached(this,e)}resolveNoCache(e){return as.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Cm(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=A.empty,r=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=r;a<s;a++)if(!this.type.allowsMarks(n.child(a).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(n),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),Cu(this.type.attrs,this.attrs,"node",this.type.name);let e=j.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];Cu(n.type.attrs,n.attrs,"mark",n.type.name),e=n.addToSet(e)}if(!j.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=A.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,r,n)}}yt.prototype.text=void 0;let Wk=class ah extends yt{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Cm(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new ah(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ah(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Cm(i,e){for(let t=i.length-1;t>=0;t--)e=i[t].type.name+"("+e+")";return e}function Cu(i,e,t,n){for(let r in e)if(!(r in i))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${n}`);for(let r in i)i[r].validate&&i[r].validate(e[r])}class mi{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new $k(e,t);if(n.next==null)return mi.empty;let r=vm(n);n.next&&n.err("Unexpected trailing text");let s=Gk(Uk(r));return Yk(s,n),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let s=t;r&&s<n;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function s(o,l){let a=o.matchFragment(e,n);if(a&&(!t||a.validEnd))return A.from(l.map(h=>h.createAndFill()));for(let h=0;h<o.next.length;h++){let{type:c,next:f}=o.next[h];if(!(c.isText||c.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let u=s(f,l.concat(c));if(u)return u}}return null}return s(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),s=r.match;if(s.matchType(e)){let o=[];for(let l=r;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||a.validEnd)&&(n.push({match:l.contentMatch,type:l,via:r}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((n,r)=>{let s=r+(n.validEnd?"*":" ")+" ";for(let o=0;o<n.next.length;o++)s+=(o?", ":"")+n.next[o].type.name+"->"+e.indexOf(n.next[o].next);return s}).join(`
|
|
2
|
+
`)}}mi.empty=new mi(!0);class $k{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function vm(i){let e=[];do e.push(Kk(i));while(i.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Kk(i){let e=[];do e.push(qk(i));while(i.next&&i.next!=")"&&i.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function qk(i){let e=_k(i);for(;;)if(i.eat("+"))e={type:"plus",expr:e};else if(i.eat("*"))e={type:"star",expr:e};else if(i.eat("?"))e={type:"opt",expr:e};else if(i.eat("{"))e=jk(i,e);else break;return e}function vu(i){/\D/.test(i.next)&&i.err("Expected number, got '"+i.next+"'");let e=Number(i.next);return i.pos++,e}function jk(i,e){let t=vu(i),n=t;return i.eat(",")&&(i.next!="}"?n=vu(i):n=-1),i.eat("}")||i.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function Jk(i,e){let t=i.nodeTypes,n=t[e];if(n)return[n];let r=[];for(let s in t){let o=t[s];o.isInGroup(e)&&r.push(o)}return r.length==0&&i.err("No node type or group '"+e+"' found"),r}function _k(i){if(i.eat("(")){let e=vm(i);return i.eat(")")||i.err("Missing closing paren"),e}else if(/\W/.test(i.next))i.err("Unexpected token '"+i.next+"'");else{let e=Jk(i,i.next).map(t=>(i.inline==null?i.inline=t.isInline:i.inline!=t.isInline&&i.err("Mixing inline and block content"),{type:"name",value:t}));return i.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Uk(i){let e=[[]];return r(s(i,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let h={term:a,to:l};return e[o].push(h),h}function r(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,h)=>a.concat(s(h,l)),[]);if(o.type=="seq")for(let a=0;;a++){let h=s(o.exprs[a],l);if(a==o.exprs.length-1)return h;r(h,l=t())}else if(o.type=="star"){let a=t();return n(l,a),r(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return r(s(o.expr,l),a),r(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let h=0;h<o.min;h++){let c=t();r(s(o.expr,a),c),a=c}if(o.max==-1)r(s(o.expr,a),a);else for(let h=o.min;h<o.max;h++){let c=t();n(a,c),r(s(o.expr,a),c),a=c}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Mm(i,e){return e-i}function Mu(i,e){let t=[];return n(e),t.sort(Mm);function n(r){let s=i[r];if(s.length==1&&!s[0].term)return n(s[0].to);t.push(r);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&n(a)}}}function Gk(i){let e=Object.create(null);return t(Mu(i,0));function t(n){let r=[];n.forEach(o=>{i[o].forEach(({term:l,to:a})=>{if(!l)return;let h;for(let c=0;c<r.length;c++)r[c][0]==l&&(h=r[c][1]);Mu(i,a).forEach(c=>{h||r.push([l,h=[]]),h.indexOf(c)==-1&&h.push(c)})})});let s=e[n.join(",")]=new mi(n.indexOf(i.length-1)>-1);for(let o=0;o<r.length;o++){let l=r[o][1].sort(Mm);s.next.push({type:r[o][0],next:e[l.join(",")]||t(l)})}return s}}function Yk(i,e){for(let t=0,n=[i];t<n.length;t++){let r=n[t],s=!r.validEnd,o=[];for(let l=0;l<r.next.length;l++){let{type:a,next:h}=r.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),n.indexOf(h)==-1&&n.push(h)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Am(i){let e=Object.create(null);for(let t in i){let n=i[t];if(!n.hasDefault)return null;e[t]=n.default}return e}function Om(i,e){let t=Object.create(null);for(let n in i){let r=i[n],s=e&&e[n];if(s===void 0)if(r.hasDefault)s=r.default;else throw new RangeError("No value supplied for attribute "+n);else r.validate&&r.validate(s);t[n]=s}return t}function Tm(i,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new Qk(i,n,e[n]);return t}let hs=class Nm{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=Tm(e,n.attrs),this.defaultAttrs=Am(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==mi.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Om(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new yt(this,this.computeAttrs(e),A.from(t),j.setFrom(n))}createChecked(e=null,t,n){return t=A.from(t),this.checkContent(t),new yt(this,this.computeAttrs(e),t,j.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=A.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let r=this.contentMatch.matchFragment(t),s=r&&r.fillBefore(A.empty,!0);return s?new yt(this,e,t.append(s),j.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:j.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new Nm(s,t,o));let r=t.spec.topNode||"doc";if(!n[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function Xk(i,e,t){let n=t.split("|");return r=>{let s=r===null?"null":typeof r;if(n.indexOf(s)<0)throw new RangeError(`Expected value of type ${n} for attribute ${e} on type ${i}, got ${s}`)}}class Qk{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Xk(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Dl{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=Tm(e,r.attrs),this.excluded=null;let s=Am(this.attrs);this.instance=s?new j(this,s):null}create(e=null){return!e&&this.instance?this.instance:new j(this,Om(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((s,o)=>n[s]=new Dl(s,r++,t,o)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}excludes(e){return this.excluded.indexOf(e)>-1}}class Zk{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let r in e)t[r]=e[r];t.nodes=Se.from(e.nodes),t.marks=Se.from(e.marks||{}),this.nodes=hs.compile(this.spec.nodes,this),this.marks=Dl.compile(this.spec.marks,this);let n=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let s=this.nodes[r],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=n[o]||(n[o]=mi.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Au(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let r in this.marks){let s=this.marks[r],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Au(this,o.split(" "))}this.nodeFromJSON=r=>yt.fromJSON(this,r),this.markFromJSON=r=>j.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof hs){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new Wk(n,n.defaultAttrs,e,j.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Au(i,e){let t=[];for(let n=0;n<e.length;n++){let r=e[n],s=i.marks[r],o=s;if(s)t.push(s);else for(let l in i.marks){let a=i.marks[l];(r=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(r)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}function e1(i){return i.tag!=null}function t1(i){return i.style!=null}class nr{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(r=>{if(e1(r))this.tags.push(r);else if(t1(r)){let s=/[^=]*/.exec(r.style)[0];n.indexOf(s)<0&&n.push(s),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let s=e.nodes[r.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let n=new Tu(this,t,!1);return n.addAll(e,j.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Tu(this,t,!0);return n.addAll(e,j.none,t.from,t.to),E.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(r1(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,n,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!n.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(r){let s=r.priority==null?50:r.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,r)}for(let r in e.marks){let s=e.marks[r].spec.parseDOM;s&&s.forEach(o=>{n(o=Nu(o)),o.mark||o.ignore||o.clearMark||(o.mark=r)})}for(let r in e.nodes){let s=e.nodes[r].spec.parseDOM;s&&s.forEach(o=>{n(o=Nu(o)),o.node||o.ignore||o.mark||(o.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new nr(e,nr.schemaRules(e)))}}const Dm={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},n1={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Im={ol:!0,ul:!0},cs=1,hh=2,qr=4;function Ou(i,e,t){return e!=null?(e?cs:0)|(e==="full"?hh:0):i&&i.whitespace=="pre"?cs|hh:t&~qr}class po{constructor(e,t,n,r,s,o){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=o,this.content=[],this.activeMarks=j.none,this.match=s||(o&qr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(A.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,r;return(r=n.findWrapping(e.type))?(this.match=n,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&cs)){let n=this.content[this.content.length-1],r;if(n&&n.isText&&(r=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-r[0].length))}}let t=A.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(A.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Dm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}let Tu=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,o=Ou(null,t.preserveWhitespace,0)|(n?qr:0);r?s=new po(r.type,r.attrs,j.none,!0,t.topMatch||r.type.contentMatch,o):n?s=new po(null,null,j.none,!0,null,o):s=new po(e.schema.topNodeType,null,j.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,s=r.options&hh?"full":this.localPreserveWS||(r.options&cs)>0,{schema:o}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,`
|
|
3
|
+
`);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let l=r.content[r.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Im.hasOwnProperty(o)&&this.parser.normalizeLists&&i1(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:n1.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let h,c=this.needsBlock;if(Dm.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),h=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let f=a&&a.skip?t:this.readStyles(e,t);f&&this.addAll(e,f),h&&this.sync(s),this.needsBlock=c}else{let h=this.readStyles(e,t);h&&this.addElementByRule(e,a,h,a.consuming===!1?l:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
4
|
+
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],o=n.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(h=>!a.clearMark(h)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,r){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,r){let s=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,n){let r,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],h=a.findWrapping(e);if(h&&(!r||r.length>h.length+l)&&(r=h,s=a,!h.length))break;if(a.solid){if(n)break;l+=2}}if(!r)return null;this.sync(s);for(let o=0;o<r.length;o++)t=this.enterInner(r[o],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=j.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Du(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,n,r){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,r)),s}enterInner(e,t,n,r=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=Ou(e,s,o.options);o.options&qr&&o.content.length==0&&(l|=qr);let a=j.none;return n=n.filter(h=>(o.type?o.type.allowsMarkType(h.type):Du(h.type,e))?(a=h.addToSet(a),!1):!0),this.nodes.push(new po(e,t,a,r,null,l)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=cs)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let r=n.length-1;r>=0;r--)e+=n[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(r?0:1),o=(l,a)=>{for(;l>=0;l--){let h=t[l];if(h==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let c=a>0||a==0&&r?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!c||c.name!=h&&!c.isInGroup(h))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}};function i1(i){for(let e=i.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Im.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function r1(i,e){return(i.matches||i.msMatchesSelector||i.webkitMatchesSelector||i.mozMatchesSelector).call(i,e)}function Nu(i){let e={};for(let t in i)e[t]=i[t];return e}function Du(i,e){let t=e.schema.nodes;for(let n in t){let r=t[n];if(!r.allowsMarkType(i))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:h,next:c}=l.edge(a);if(h==e||s.indexOf(c)<0&&o(c))return!0}};if(o(r.contentMatch))return!0}}class yr{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=mo(t).createDocumentFragment());let r=n,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let h=o.marks[a];if(!this.marks[h.type.name]){a++;continue}if(!h.eq(s[l][0])||h.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)r=s.pop()[1];for(;a<o.marks.length;){let h=o.marks[a++],c=this.serializeMark(h,o.isInline,t);c&&(s.push([h,r]),r.appendChild(c.dom),r=c.contentDOM||c.dom)}}r.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){if(e.isText)return mo(t).createTextNode(e.text);let{dom:n,contentDOM:r}=Fo(mo(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Fo(mo(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t=="string"?{dom:e.createTextNode(t)}:Fo(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new yr(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Iu(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return Iu(e.marks)}}function Iu(i){let e={};for(let t in i){let n=i[t].spec.toDOM;n&&(e[t]=n)}return e}function mo(i){return i.document||window.document}const Eu=new WeakMap;function s1(i){let e=Eu.get(i);return e===void 0&&Eu.set(i,e=o1(i)),e}function o1(i){let e=null;function t(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")e||(e=[]),e.push(n);else for(let r=0;r<n.length;r++)t(n[r]);else for(let r in n)t(n[r])}return t(i),e}function Fo(i,e,t,n){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(s=s1(n))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=r.indexOf(" ");o>0&&(t=r.slice(0,o),r=r.slice(o+1));let l,a=t?i.createElementNS(t,r):i.createElement(r),h=e[1],c=1;if(h&&typeof h=="object"&&h.nodeType==null&&!Array.isArray(h)){c=2;for(let f in h)if(h[f]!=null){let u=f.indexOf(" ");u>0?a.setAttributeNS(f.slice(0,u),f.slice(u+1),h[f]):f=="style"&&a.style?a.style.cssText=h[f]:a.setAttribute(f,h[f])}}for(let f=c;f<e.length;f++){let u=e[f];if(u===0){if(f<e.length-1||f>c)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else if(typeof u=="string")a.appendChild(i.createTextNode(u));else{let{dom:d,contentDOM:p}=Fo(i,u,t,n);if(a.appendChild(d),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Em=65535,Rm=Math.pow(2,16);function l1(i,e){return i+e*Rm}function Ru(i){return i&Em}function a1(i){return(i-(i&Em))/Rm}const Bm=1,Pm=2,Vo=4,Lm=8;class ch{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&Lm)>0}get deletedBefore(){return(this.delInfo&(Bm|Vo))>0}get deletedAfter(){return(this.delInfo&(Pm|Vo))>0}get deletedAcross(){return(this.delInfo&Vo)>0}}class rt{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&rt.empty)return rt.empty}recover(e){let t=0,n=Ru(e);if(!this.inverted)for(let r=0;r<n;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[n*3]+t+a1(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let h=this.ranges[l+s],c=this.ranges[l+o],f=a+h;if(e<=f){let u=h?e==a?-1:e==f?1:t:t,d=a+r+(u<0?0:c);if(n)return d;let p=e==(t<0?a:f)?null:l1(l/3,e-a),m=0;return h&&(m|=e==a?Pm:e==f?Bm:Vo,(t<0?e!=a:e!=f)&&(m|=Lm)),new ch(d,m,p)}r+=c-h}return n?e+r:new ch(e+r,0,null)}touches(e,t){let n=0,r=Ru(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?n:0);if(a>e)break;let h=this.ranges[l+s],c=a+h;if(e<=c&&l==r*3)return!0;n+=this.ranges[l+o]-h}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let o=this.ranges[r],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),h=this.ranges[r+t],c=this.ranges[r+n];e(l,l+h,a,a+c),s+=c-h}}invert(){return new rt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?rt.empty:new rt(e<0?[0,-e,0]:[0,0,e])}}rt.empty=new rt([]);class il{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new il(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let e=new il;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return n?e:new ch(e,r,null)}}const la=Object.create(null);class ye{getMap(){return rt.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=la[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in la)throw new RangeError("Duplicate use of step JSON ID "+e);return la[e]=t,t.prototype.jsonID=e,t}}class fe{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new fe(e,null)}static fail(e){return new fe(null,e)}static fromReplace(e,t,n,r){try{return fe.ok(e.replace(t,n,r))}catch(s){if(s instanceof ls)return fe.fail(s.message);throw s}}}function Mc(i,e,t){let n=[];for(let r=0;r<i.childCount;r++){let s=i.child(r);s.content.size&&(s=s.copy(Mc(s.content,e,s))),s.isInline&&(s=e(s,t,r)),n.push(s)}return A.fromArray(n)}class Vt extends ye{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),s=new E(Mc(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),r),t.openStart,t.openEnd);return fe.fromReplace(e,this.from,this.to,s)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,r)=>{if(n.isInline&&n.isAtom){let s=this.mark.addToSet(n.marks);if(!j.sameSet(s,n.marks)){let o=Math.max(this.from,r),l=Math.min(this.to,r+n.nodeSize);rl(tn,o,l,this.mark,t);for(let a of n.marks)a.isInSet(s)||rl(Vt,o,l,a,t)}}}),t.length==1?t[0]:new oi(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new Vt(t,n,this.mark)}merge(e){return e instanceof Vt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Vt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Vt(t.from,t.to,e.markFromJSON(t.mark))}}ye.jsonID("addMark",Vt);class tn extends ye{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new E(Mc(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return fe.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,r)=>{n.isInline&&n.isAtom&&this.mark.isInSet(n.marks)&&rl(Vt,Math.max(this.from,r),Math.min(this.to,r+n.nodeSize),this.mark,t)}),t.length==1?t[0]:new oi(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new tn(t,n,this.mark)}merge(e){return e instanceof tn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new tn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new tn(t.from,t.to,e.markFromJSON(t.mark))}}ye.jsonID("removeMark",tn);function rl(i,e,t,n,r){let s=r.length?r[r.length-1]:null;s&&s instanceof i&&s.to==e&&s.mark.eq(n)?r[r.length-1]=new i(s.from,t,n):r.push(new i(e,t,n))}class oi extends ye{constructor(e){super(),this.steps=e}apply(e){for(let t of this.steps){let n=t.apply(e);if(!n.doc)return n;e=n.doc}return new fe(e,null)}invert(e){return new oi(this.steps.map(t=>t.invert(e)))}map(e){let t=[];for(let n of this.steps){let r=n.map(e);r&&t.push(r)}return t.length?new oi(t):null}toJSON(){return{stepType:"markSet",steps:this.steps.map(e=>e.toJSON())}}static fromJSON(e,t){if(!Array.isArray(t.steps)||!t.steps.every(n=>n.stepType=="addMark"||n.stepType=="removeMark"))throw new RangeError("Invalid JSON for MarkSetStep");return new oi(t.steps.map(n=>ye.fromJSON(e,n)))}}ye.jsonID("markSet",oi);class On extends ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return fe.fromReplace(e,this.pos,this.pos+1,new E(A.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(n))return new On(this.pos,t.marks[r]);return new On(this.pos,this.mark)}}return new gi(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new On(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new On(t.pos,e.markFromJSON(t.mark))}}ye.jsonID("addNodeMark",On);class gi extends ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return fe.fromReplace(e,this.pos,this.pos+1,new E(A.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new On(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new gi(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new gi(t.pos,e.markFromJSON(t.mark))}}ye.jsonID("removeNodeMark",gi);class ue extends ye{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&fh(e,this.from,this.to)?fe.fail("Structure replace would overwrite content"):fe.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new rt([this.from,this.to-this.from,this.slice.size])}invert(e){return new ue(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&ue.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new ue(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof ue)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?E.empty:new E(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new ue(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?E.empty:new E(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new ue(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new ue(t.from,t.to,E.fromJSON(e,t.slice),!!t.structure)}}ue.MAP_BIAS=1;ye.jsonID("replace",ue);class Be extends ye{constructor(e,t,n,r,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(fh(e,this.from,this.gapFrom)||fh(e,this.gapTo,this.to)))return fe.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return fe.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?fe.fromReplace(e,this.from,this.to,n):fe.fail("Content does not fit in gap")}getMap(){return new rt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Be(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||s>n.pos?null:new Be(t.pos,n.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Be(t.from,t.to,t.gapFrom,t.gapTo,E.fromJSON(e,t.slice),t.insert,!!t.structure)}}ye.jsonID("replaceAround",Be);function fh(i,e,t){let n=i.resolve(e),r=t-e,s=n.depth;for(;r>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,r--;if(r>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;r>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,r--}}return!1}function h1(i,e,t,n){let r=[];i.doc.nodesBetween(e,t,(s,o,l)=>{if(!s.isInline)return;let a=s.marks;if(!n.isInSet(a)&&l.type.allowsMarkType(n.type)){let h=Math.max(o,e),c=Math.min(o+s.nodeSize,t);rl(Vt,h,c,n,r)}}),r.forEach(s=>i.step(s))}function c1(i,e,t,n){let r=[],s=0;i.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline||!o.isAtom)return;s++;let a=null;if(n instanceof Dl){let h=o.marks,c;for(;c=n.isInSet(h);)(a||(a=[])).push(c),h=c.removeFromSet(h)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let h=Math.min(l+o.nodeSize,t);for(let c=0;c<a.length;c++){let f=a[c],u;for(let d=0;d<r.length;d++){let p=r[d];p.step==s-1&&f.eq(r[d].style)&&(u=p)}u?(u.to=h,u.step=s):r.push({style:f,from:Math.max(l,e),to:h,step:s})}}}),r.forEach(o=>i.step(new tn(o.from,o.to,o.style)))}function Ac(i,e,t,n=t.contentMatch,r=!0){let s=i.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let h=s.child(a),c=l+h.nodeSize,f=n.matchType(h.type);if(!f)o.push(new ue(l,c,E.empty));else{n=f;for(let u=0;u<h.marks.length;u++)t.allowsMarkType(h.marks[u].type)||i.step(new tn(l,c,h.marks[u]));if(r&&h.isText&&t.whitespace!="pre"){let u,d=/\r?\n|\r/g,p;for(;u=d.exec(h.text);)p||(p=new E(A.from(t.schema.text(" ",t.allowedMarks(h.marks))),0,0)),o.push(new ue(l+u.index,l+u.index+u[0].length,p))}}l=c}if(!n.validEnd){let a=n.fillBefore(A.empty,!0);i.replace(l,l,new E(a,0,0))}for(let a=o.length-1;a>=0;a--)i.step(o[a])}function f1(i,e,t){return(e==0||i.canReplace(e,i.childCount))&&(t==i.childCount||i.canReplace(0,t))}function Il(i){let t=i.parent.content.cutByIndex(i.startIndex,i.endIndex);for(let n=i.depth,r=0,s=0;;--n){let o=i.$from.node(n),l=i.$from.index(n)+r,a=i.$to.indexAfter(n)-s;if(n<i.depth&&o.canReplace(l,a,t))return n;if(n==0||o.type.spec.isolating||!f1(o,l,a))break;l&&(r=1),a<o.childCount&&(s=1)}return null}function u1(i,e,t){let{$from:n,$to:r,depth:s}=e,o=n.before(s+1),l=r.after(s+1),a=o,h=l,c=A.empty,f=0;for(let p=s,m=!1;p>t;p--)m||n.index(p)>0?(m=!0,c=A.from(n.node(p).copy(c)),f++):a--;let u=A.empty,d=0;for(let p=s,m=!1;p>t;p--)m||r.after(p+1)<r.end(p)?(m=!0,u=A.from(r.node(p).copy(u)),d++):h++;i.step(new Be(a,h,o,l,new E(c.append(u),f,d),c.size-f,!0))}function Oc(i,e,t=null,n=i){let r=d1(i,e),s=r&&p1(n,e);return s?r.map(Bu).concat({type:e,attrs:t}).concat(s.map(Bu)):null}function Bu(i){return{type:i,attrs:null}}function d1(i,e){let{parent:t,startIndex:n,endIndex:r}=i,s=t.contentMatchAt(n).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(n,r,o)?s:null}function p1(i,e){let{parent:t,startIndex:n,endIndex:r}=i,s=t.child(n),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let h=n;a&&h<r;h++)a=a.matchType(t.child(h).type);return!a||!a.validEnd?null:o}function m1(i,e,t){let n=A.empty;for(let o=t.length-1;o>=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=A.from(t[o].type.create(t[o].attrs,n))}let r=e.start,s=e.end;i.step(new Be(r,s,r,s,new E(n,0,0),t.length,!0))}function g1(i,e,t,n,r){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=i.steps.length;i.doc.nodesBetween(e,t,(o,l)=>{let a=typeof r=="function"?r(o):r;if(o.isTextblock&&!o.hasMarkup(n,a)&&y1(i.doc,i.mapping.slice(s).map(l),n)){let h=null;if(n.schema.linebreakReplacement){let d=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);d&&!p?h=!1:!d&&p&&(h=!0)}h===!1&&Vm(i,o,l,s),Ac(i,i.mapping.slice(s).map(l,1),n,void 0,h===null);let c=i.mapping.slice(s),f=c.map(l,1),u=c.map(l+o.nodeSize,1);return i.step(new Be(f,u,f+1,u-1,new E(A.from(n.create(a,null,o.marks)),0,0),1,!0)),h===!0&&Fm(i,o,l,s),!1}})}function Fm(i,e,t,n){e.forEach((r,s)=>{if(r.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(r.text);){let a=i.mapping.slice(n).map(t+1+s+o.index);i.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Vm(i,e,t,n){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let o=i.mapping.slice(n).map(t+1+s);i.replaceWith(o,o+1,e.type.schema.text(`
|
|
5
|
+
`))}})}function y1(i,e,t){let n=i.resolve(e),r=n.index();return n.parent.canReplaceWith(r,r+1,t)}function b1(i,e,t,n,r){let s=i.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,r||s.marks);if(s.isLeaf)return i.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);i.step(new Be(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new E(A.from(o),0,0),1,!0))}function jr(i,e,t=1,n){let r=i.resolve(e),s=r.depth-t,o=n&&n[n.length-1]||r.parent;if(s<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!o.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let h=r.depth-1,c=t-2;h>s;h--,c--){let f=r.node(h),u=r.index(h);if(f.type.spec.isolating)return!1;let d=f.content.cutByIndex(u,f.childCount),p=n&&n[c+1];p&&(d=d.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[c]||f;if(!f.canReplace(u+1,f.childCount)||!m.type.validContent(d))return!1}let l=r.indexAfter(s),a=n&&n[0];return r.node(s).canReplaceWith(l,l,a?a.type:r.node(s+1).type)}function k1(i,e,t=1,n){let r=i.doc.resolve(e),s=A.empty,o=A.empty;for(let l=r.depth,a=r.depth-t,h=t-1;l>a;l--,h--){s=A.from(r.node(l).copy(s));let c=n&&n[h];o=A.from(c?c.type.create(c.attrs,o):r.node(l).copy(o))}i.step(new ue(e,e,new E(s.append(o),t,t),!0))}function El(i,e){let t=i.resolve(e),n=t.index();return w1(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function x1(i,e){e.content.size||i.type.compatibleContent(e.type);let t=i.contentMatchAt(i.childCount),{linebreakReplacement:n}=i.type.schema;for(let r=0;r<e.childCount;r++){let s=e.child(r),o=s.type==n?i.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!i.type.allowsMarks(s.marks))return!1}return t.validEnd}function w1(i,e){return!!(i&&e&&!i.isLeaf&&x1(i,e))}function S1(i,e,t){let n=null,{linebreakReplacement:r}=i.doc.type.schema,s=i.doc.resolve(e-t),o=s.node().type;if(r&&o.inlineContent){let c=o.whitespace=="pre",f=!!o.contentMatch.matchType(r);c&&!f?n=!1:!c&&f&&(n=!0)}let l=i.steps.length;if(n===!1){let c=i.doc.resolve(e+t);Vm(i,c.node(),c.before(),l)}o.inlineContent&&Ac(i,e+t-1,o,s.node().contentMatchAt(s.index()),n==null);let a=i.mapping.slice(l),h=a.map(e-t);if(i.step(new ue(h,a.map(e+t,-1),E.empty,!0)),n===!0){let c=i.doc.resolve(h);Fm(i,c.node(),c.before(),i.steps.length)}return i}function C1(i,e,t){let n=i.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let r=n.depth-1;r>=0;r--){let s=n.index(r);if(n.node(r).canReplaceWith(s,s,t))return n.before(r+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let r=n.depth-1;r>=0;r--){let s=n.indexAfter(r);if(n.node(r).canReplaceWith(s,s,t))return n.after(r+1);if(s<n.node(r).childCount)return null}return null}function v1(i,e,t){let n=i.resolve(e);if(!t.content.size)return e;let r=t.content;for(let s=0;s<t.openStart;s++)r=r.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=n.depth;o>=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),h=n.node(o),c=!1;if(s==1)c=h.canReplace(a,a,r);else{let f=h.contentMatchAt(a).findWrapping(r.firstChild.type);c=f&&h.canReplaceWith(a,a,f[0])}if(c)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function Rl(i,e,t=e,n=E.empty){if(e==t&&!n.size)return null;let r=i.resolve(e),s=i.resolve(t);return zm(r,s,n)?new ue(e,t,n):new M1(r,s,n).fit()}function zm(i,e,t){return!t.openStart&&!t.openEnd&&i.start()==e.start()&&i.parent.canReplace(i.index(),e.index(),t.content)}class M1{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=A.empty;for(let r=0;r<=e.depth;r++){let s=e.node(r);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=A.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let h=this.findFittable();h?this.placeNodes(h):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let s=this.placed,o=n.depth,l=r.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new E(s,o,l);return e>-1?new Be(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new ue(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let s=t.firstChild;if(t.childCount>1&&(r=0),s.type.spec.isolating&&r<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let r,s=null;n?(s=Pu(this.unplaced.content,n-1).firstChild,r=s.content):r=this.unplaced.content;let o=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:h}=this.frontier[l],c,f=null;if(t==1&&(o?h.matchType(o.type)||(f=h.fillBefore(A.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(c=h.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:c};if(s&&h.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return Lu(e,-1)<=t?!1:(this.unplaced.size>1&&Lu(e,1)>n&&n++,this.unplaced=new E(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Pu(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new E(Br(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new E(Br(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=n?n.content:o.content,a=o.openStart-e,h=0,c=[],{match:f,type:u}=this.frontier[t];if(r){for(let m=0;m<r.childCount;m++)c.push(r.child(m));f=f.matchFragment(r)}let d=l.size+e-(o.content.size-o.openEnd);for(;h<l.childCount;){let m=l.child(h),g=f.matchType(m.type);if(!g)break;h++,(h>1||a==0||m.content.size)&&(f=g,c.push(Hm(m.mark(u.allowedMarks(m.marks)),h==1?a:0,h==l.childCount?d:-1)))}let p=h==l.childCount;p||(d=-1),this.placed=Pr(this.placed,t,A.from(c)),this.frontier[t].match=f,p&&d<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<d;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=p?e==0?E.empty:new E(Br(o.content,e-1,1),e-1,d<0?o.openEnd:e-1):new E(Br(o.content,e,h),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!aa(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=aa(e,t,r,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:h}=this.frontier[l],c=aa(e,l,h,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Pr(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let r=e.node(n),s=r.type.contentMatch.fillBefore(r.content,!0,e.index(n));this.openFrontierNode(r.type,r.attrs,s)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Pr(this.placed,this.depth,A.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(A.empty,!0);t.childCount&&(this.placed=Pr(this.placed,this.frontier.length,t))}}function Br(i,e,t){return e==0?i.cutByIndex(t,i.childCount):i.replaceChild(0,i.firstChild.copy(Br(i.firstChild.content,e-1,t)))}function Pr(i,e,t){return e==0?i.append(t):i.replaceChild(i.childCount-1,i.lastChild.copy(Pr(i.lastChild.content,e-1,t)))}function Pu(i,e){for(let t=0;t<e;t++)i=i.firstChild.content;return i}function Hm(i,e,t){if(e<=0)return i;let n=i.content;return e>1&&(n=n.replaceChild(0,Hm(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=i.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(i.type.contentMatch.matchFragment(n).fillBefore(A.empty,!0)))),i.copy(n)}function aa(i,e,t,n,r){let s=i.node(e),o=r?i.indexAfter(e):i.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!A1(t,s.content,o)?l:null}function A1(i,e,t){for(let n=t;n<e.childCount;n++)if(!i.allowsMarks(e.child(n).marks))return!0;return!1}function O1(i){return i.spec.defining||i.spec.definingForContent}function Lu(i,e){for(let t=0;;t++){let n=e<0?i.firstChild:i.lastChild;if(!n||n.isAtom)return t;i=n.content}}function T1(i,e,t,n){if(!n.size)return i.deleteRange(e,t);let r=i.doc.resolve(e),s=i.doc.resolve(t);if(zm(r,s,n))return i.step(new ue(e,t,n));let o=$m(r,s);o[o.length-1]==0&&o.pop();let l=-(r.depth+1);o.unshift(l);for(let u=r.depth,d=r.pos-1;u>0;u--,d--){let p=r.node(u).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(u)>-1?l=u:r.before(u)==d&&o.splice(1,0,-u)}let a=o.indexOf(l),h=[],c=n.openStart;for(let u=n.content,d=0;;d++){let p=u.firstChild;if(h.push(p),d==n.openStart)break;u=p.content}for(let u=c-1;u>=0;u--){let d=h[u],p=O1(d.type);if(p&&!d.sameMarkup(r.node(Math.abs(l)-1)))c=u;else if(p||!d.type.isTextblock)break}for(let u=n.openStart;u>=0;u--){let d=(u+c+1)%(n.openStart+1),p=h[d];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let b=r.node(g-1),k=r.index(g-1);if(b.canReplaceWith(k,k,p.type,p.marks))return i.replace(r.before(g),y?s.after(g):t,new E(Wm(n.content,0,n.openStart,d),d,n.openEnd))}}let f=i.steps.length;for(let u=o.length-1;u>=0&&(i.replace(e,t,n),!(i.steps.length>f));u--){let d=o[u];d<0||(e=r.before(d),t=s.after(d))}}function Wm(i,e,t,n,r){if(e<t){let s=i.firstChild;i=i.replaceChild(0,s.copy(Wm(s.content,e+1,t,n,s)))}if(e>n){let s=r.contentMatchAt(0),o=s.fillBefore(i).append(i);i=o.append(s.matchFragment(o).fillBefore(A.empty,!0))}return i}function N1(i,e,t,n){if(!n.isInline&&e==t&&i.doc.resolve(e).parent.content.size){let r=C1(i.doc,e,n.type);r!=null&&(e=t=r)}i.replaceRange(e,t,new E(A.from(n),0,0))}function D1(i,e,t){let n=i.doc.resolve(e),r=i.doc.resolve(t);if(n.parent.isTextblock&&r.parent.isTextblock&&n.start()!=r.start()&&n.parentOffset==0&&r.parentOffset==0){let o=n.sharedDepth(t),l=!1;for(let a=n.depth;a>o;a--)n.node(a).type.spec.isolating&&(l=!0);for(let a=r.depth;a>o;a--)r.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=n.depth;a>0&&e==n.start(a);a--)e=n.before(a);for(let a=r.depth;a>0&&t==r.start(a);a--)t=r.before(a);n=i.doc.resolve(e),r=i.doc.resolve(t)}}let s=$m(n,r);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||n.node(l).type.contentMatch.validEnd)return i.delete(n.start(l),r.end(l));if(l>0&&(a||n.node(l-1).canReplace(n.index(l-1),r.indexAfter(l-1))))return i.delete(n.before(l),r.after(l))}for(let o=1;o<=n.depth&&o<=r.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&r.end(o)-t!=r.depth-o&&n.start(o-1)==r.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),r.index(o-1)))return i.delete(n.before(o),t);i.delete(e,t)}function $m(i,e){let t=[],n=Math.min(i.depth,e.depth);for(let r=n;r>=0;r--){let s=i.start(r);if(s<i.pos-(i.depth-r)||e.end(r)>e.pos+(e.depth-r)||i.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==i.depth&&r==e.depth&&i.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&t.push(r)}return t}class Hi extends ye{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return fe.fromReplace(e,this.pos,this.pos+1,new E(A.from(r),0,t.isLeaf?0:1))}getMap(){return rt.empty}invert(e){return new Hi(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Hi(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Hi(t.pos,t.attr,t.value)}}ye.jsonID("attr",Hi);class fs extends ye{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return fe.ok(n)}getMap(){return rt.empty}invert(e){return new fs(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new fs(t.attr,t.value)}}ye.jsonID("docAttr",fs);let ir=class extends Error{};ir=function i(e){let t=Error.call(this,e);return t.__proto__=i.prototype,t};ir.prototype=Object.create(Error.prototype);ir.prototype.constructor=ir;ir.prototype.name="TransformError";class I1{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new il}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ir(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((s,o,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=E.empty){let r=Rl(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new E(A.from(n),0,0))}delete(e,t){return this.replace(e,t,E.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return T1(this,e,t,n),this}replaceRangeWith(e,t,n){return N1(this,e,t,n),this}deleteRange(e,t){return D1(this,e,t),this}lift(e,t){return u1(this,e,t),this}join(e,t=1){return S1(this,e,t),this}wrap(e,t){return m1(this,e,t),this}setBlockType(e,t=e,n,r=null){return g1(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return b1(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new Hi(e,t,n)),this}setDocAttribute(e,t){return this.step(new fs(e,t)),this}addNodeMark(e,t){return this.step(new On(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof j)t.isInSet(n.marks)&&this.step(new gi(e,t));else{let r=n.marks,s,o=[];for(;s=t.isInSet(r);)o.push(new gi(e,s)),r=s.removeFromSet(r);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return k1(this,e,t,n),this}addMark(e,t,n){return h1(this,e,t,n),this}removeMark(e,t,n){return c1(this,e,t,n),this}clearIncompatible(e,t,n){return Ac(this,e,t,n),this}}const ha=Object.create(null);class _{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new E1(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=E.empty){let n=t.content.lastChild,r=null;for(let l=0;l<t.openEnd;l++)r=n,n=n.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:h}=o[l],c=e.mapping.slice(s);e.replaceRange(c.map(a.pos),c.map(h.pos),l?E.empty:t),l==0&&zu(e,s,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:o,$to:l}=r[s],a=e.mapping.slice(n),h=a.map(o.pos),c=a.map(l.pos);s?e.deleteRange(h,c):(e.replaceRangeWith(h,c,t),zu(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new K(e):Ri(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let s=e.depth-1;s>=0;s--){let o=t<0?Ri(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Ri(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new st(e.node(0))}static atStart(e){return Ri(e,e,0,0,1)||new st(e)}static atEnd(e){return Ri(e,e,e.content.size,e.childCount,-1)||new st(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=ha[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in ha)throw new RangeError("Duplicate use of selection JSON ID "+e);return ha[e]=t,t.prototype.jsonID=e,t}getBookmark(){return K.between(this.$anchor,this.$head).getBookmark()}}_.prototype.visible=!0;let E1=class{constructor(e,t){this.$from=e,this.$to=t}},Fu=!1;function Vu(i){!Fu&&!i.parent.inlineContent&&(Fu=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+i.parent.type.name+")"))}class K extends _{constructor(e,t=e){Vu(e),Vu(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return _.near(n);let r=e.resolve(t.map(this.anchor));return new K(r.parent.inlineContent?r:n,n)}replace(e,t=E.empty){if(super.replace(e,t),t==E.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof K&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Bl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new K(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let s=_.findFrom(t,n,!0)||_.findFrom(t,-n,!0);if(s)t=s.$head;else return _.near(t,n)}return e.parent.inlineContent||(r==0?e=t:(e=(_.findFrom(e,-n,!0)||_.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new K(e,t)}}_.jsonID("text",K);class Bl{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Bl(e.map(this.anchor),e.map(this.head))}resolve(e){return K.between(e.resolve(this.anchor),e.resolve(this.head))}}class V extends _{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),s=e.resolve(r);return n?_.near(s):new V(s)}content(){return new E(A.from(this.node),0,0)}eq(e){return e instanceof V&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Tc(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new V(e.resolve(t.anchor))}static create(e,t){return new V(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}V.prototype.visible=!1;_.jsonID("node",V);class Tc{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Bl(n,n):new Tc(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&V.isSelectable(n)?new V(t):_.near(t)}}class st extends _{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=E.empty){if(t==E.empty){e.delete(0,e.doc.content.size);let n=_.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new st(e)}map(e){return new st(e)}eq(e){return e instanceof st}getBookmark(){return R1}}_.jsonID("all",st);const R1={map(){return this},resolve(i){return new st(i)}};function Ri(i,e,t,n,r,s=!1){if(e.inlineContent)return K.create(i,t);for(let o=n-(r>0?0:1);r>0?o<e.childCount:o>=0;o+=r){let l=e.child(o);if(l.isAtom){if(!s&&V.isSelectable(l))return V.create(i,t-(r<0?l.nodeSize:0))}else{let a=Ri(i,l,t+r,r<0?l.childCount:0,r,s);if(a)return a}t+=l.nodeSize*r}return null}function zu(i,e,t){let n=i.steps.length-1;if(n<e)return;let r=i.steps[n];if(!(r instanceof ue||r instanceof Be))return;let s=i.mapping.maps[n],o;s.forEach((l,a,h,c)=>{o==null&&(o=c)}),i.setSelection(_.near(i.doc.resolve(o),t))}const Hu=1,go=2,Wu=4;let B1=class extends I1{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Hu)&~go,this.storedMarks=null,this}get selectionSet(){return(this.updated&Hu)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=go,this}ensureMarks(e){return j.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&go)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~go,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||j.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(_.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Wu,this}get scrolledIntoView(){return(this.updated&Wu)>0}};function $u(i,e){return!e||!i?i:i.bind(e)}class Lr{constructor(e,t,n){this.name=e,this.init=$u(t.init,n),this.apply=$u(t.apply,n)}}const P1=[new Lr("doc",{init(i){return i.doc||i.schema.topNodeType.createAndFill()},apply(i){return i.doc}}),new Lr("selection",{init(i,e){return i.selection||_.atStart(e.doc)},apply(i){return i.selection}}),new Lr("storedMarks",{init(i){return i.storedMarks||null},apply(i,e,t,n){return n.selection.$cursor?i.storedMarks:null}}),new Lr("scrollToSelection",{init(){return 0},apply(i,e){return i.scrolledIntoView?e+1:e}})];let ca=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=P1.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new Lr(n.key,n.spec.state,n))})}},Km=class Fr{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let r=this.config.plugins[n];if(r.spec.filterTransaction&&!r.spec.filterTransaction.call(r,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=r?r[o].n:0,h=r?r[o].state:this,c=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,h,n);if(c&&n.filterTransaction(c,o)){if(c.setMeta("appendedTransaction",e),!r){r=[];for(let f=0;f<this.config.plugins.length;f++)r.push(f<o?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),s=!0}r&&(r[o]={state:n,n:t.length})}}if(!s)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Fr(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let s=n[r];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new B1(this)}static create(e){let t=new ca(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Fr(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new ca(this.schema,e.plugins),n=t.fields,r=new Fr(t);for(let s=0;s<n.length;s++){let o=n[s].name;r[o]=this.hasOwnProperty(o)?this[o]:n[s].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(n=>n.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],s=r.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new ca(e.schema,e.plugins),s=new Fr(r);return r.fields.forEach(o=>{if(o.name=="doc")s.doc=yt.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=_.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],h=a.spec.state;if(a.key==o.name&&h&&h.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=h.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function qm(i,e,t){for(let n in i){let r=i[n];r instanceof Function?r=r.bind(e):n=="handleDOMEvents"&&(r=qm(r,e,{})),t[n]=r}return t}class un{constructor(e){this.spec=e,this.props={},e.props&&qm(e.props,this,this.props),this.key=e.key?e.key.key:jm("plugin")}getState(e){return e[this.key]}}const fa=Object.create(null);function jm(i){return i in fa?i+"$"+ ++fa[i]:(fa[i]=0,i+"$")}class Kn{constructor(e="key"){this.key=jm(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}var _e=(function(i){return i.docTypeError="docTypeError",i.contextNotFound="contextNotFound",i.timerNotFound="timerNotFound",i.ctxCallOutOfScope="ctxCallOutOfScope",i.createNodeInParserFail="createNodeInParserFail",i.stackOverFlow="stackOverFlow",i.parserMatchError="parserMatchError",i.serializerMatchError="serializerMatchError",i.getAtomFromSchemaFail="getAtomFromSchemaFail",i.expectDomTypeError="expectDomTypeError",i.callCommandBeforeEditorView="callCommandBeforeEditorView",i.missingRootElement="missingRootElement",i.missingNodeInSchema="missingNodeInSchema",i.missingMarkInSchema="missingMarkInSchema",i.ctxNotBind="ctxNotBind",i.missingYjsDoc="missingYjsDoc",i.aiProviderError="aiProviderError",i.aiBuildContextError="aiBuildContextError",i})({}),Ue=class extends Error{constructor(i,e,t){super(e,t),this.name="MilkdownError",this.code=i,t?.cause!==void 0&&(this.cause=t.cause)}},L1=(i,e)=>typeof e=="function"?"[Function]":e,Js=i=>JSON.stringify(i,L1);function F1(i){return new Ue(_e.docTypeError,`Doc type error, unsupported type: ${Js(i)}`)}function V1(i){return new Ue(_e.contextNotFound,`Context "${i}" not found, do you forget to inject it?`)}function z1(i){return new Ue(_e.timerNotFound,`Timer "${i}" not found, do you forget to record it?`)}function Pl(){return new Ue(_e.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function H1(i,e,t){const n=`Cannot create node for ${"name"in i?i.name:i}`,r=o=>{if(o==null)return"null";if(Array.isArray(o))return`[${o.map(r).join(", ")}]`;if(typeof o=="object")return"toJSON"in o&&typeof o.toJSON=="function"?JSON.stringify(o.toJSON()):"spec"in o?JSON.stringify(o.spec):JSON.stringify(o);if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return JSON.stringify(o);if(typeof o=="function")return`[Function: ${o.name||"anonymous"}]`;try{return String(o)}catch{return"[Unserializable]"}},s=[["[Description]",n],["[Attributes]",e],["[Content]",(t??[]).map(o=>o?typeof o=="object"&&"type"in o?`${o}`:r(o):"null")]].reduce((o,[l,a])=>{const h=`${l}: ${r(a)}.`;return o.concat(h)},[]);return new Ue(_e.createNodeInParserFail,s.join(`
|
|
6
|
+
`))}function Jm(){return new Ue(_e.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function W1(i){return new Ue(_e.parserMatchError,`Cannot match target parser for node: ${Js(i)}.`)}function $1(i){return new Ue(_e.serializerMatchError,`Cannot match target serializer for node: ${Js(i)}.`)}function K1(i,e){return new Ue(_e.getAtomFromSchemaFail,`Cannot get ${i}: ${e} from schema.`)}function Ci(i){return new Ue(_e.expectDomTypeError,`Expect to be a dom, but get: ${Js(i)}.`)}function ua(){return new Ue(_e.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function q1(i){return new Ue(_e.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${i}" in schema.`)}function j1(i){return new Ue(_e.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${i}" in schema.`)}function _m(i){try{return Js(i)}catch{return"[Unserializable]"}}function XN(i){const e=i instanceof Error?i.message:_m(i);return new Ue(_e.aiProviderError,`AI provider error: ${e}`,{cause:i})}function QN(i){const e=i instanceof Error?i.message:_m(i);return new Ue(_e.aiBuildContextError,`AI buildContext failed: ${e}`,{cause:i})}var Um=class{constructor(){this.sliceMap=new Map,this.get=i=>{const e=typeof i=="string"?[...this.sliceMap.values()].find(t=>t.type.name===i):this.sliceMap.get(i.id);if(!e){const t=typeof i=="string"?i:i.name;throw V1(t)}return e},this.remove=i=>{const e=typeof i=="string"?[...this.sliceMap.values()].find(t=>t.type.name===i):this.sliceMap.get(i.id);e&&this.sliceMap.delete(e.type.id)},this.has=i=>typeof i=="string"?[...this.sliceMap.values()].some(e=>e.type.name===i):this.sliceMap.has(i.id)}},J1=class{#t;#e;#i;constructor(i,e,t){this.#t=[],this.#i=()=>{this.#t.forEach(n=>n(this.#e))},this.set=n=>{this.#e=n,this.#i()},this.get=()=>this.#e,this.update=n=>{this.#e=n(this.#e),this.#i()},this.type=t,this.#e=e,i.set(t.id,this)}on(i){return this.#t.push(i),()=>{this.#t=this.#t.filter(e=>e!==i)}}once(i){const e=this.on(t=>{i(t),e()});return e}off(i){this.#t=this.#t.filter(e=>e!==i)}offAll(){this.#t=[]}},_1=class{constructor(i,e){this.id=Symbol(`Context-${e}`),this.name=e,this._defaultValue=i,this._typeInfo=()=>{throw Pl()}}create(i,e=this._defaultValue){return new J1(i,e,this)}},q=(i,e)=>new _1(i,e),U1=class{#t;#e;#i;#n;#s;#o;#r;constructor(i,e,t){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#r=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(n=>({name:typeof n=="string"?n:n.name,value:this.#l(n)})),consumedSlices:[...this.#s].map(n=>({name:typeof n=="string"?n:n.name,value:this.#l(n)})),recordedTimers:[...this.#o].map(([n,{duration:r}])=>({name:n.name,duration:r,status:this.#a(n)})),waitTimers:[...this.#r].map(([n,{duration:r}])=>({name:n.name,duration:r,status:this.#a(n)}))}),this.onRecord=n=>{this.#o.set(n,{start:Date.now(),duration:0})},this.onClear=n=>{this.#o.delete(n)},this.onDone=n=>{const r=this.#o.get(n);r&&(r.duration=Date.now()-r.start)},this.onWait=(n,r)=>{const s=Date.now();r.finally(()=>{this.#r.set(n,{duration:Date.now()-s})}).catch(console.error)},this.onInject=n=>{this.#n.add(n)},this.onRemove=n=>{this.#n.delete(n)},this.onUse=n=>{this.#s.add(n)},this.#l=n=>this.#e.get(n).get(),this.#a=n=>this.#i.get(n).status,this.#e=i,this.#i=e,this.#t=t}#l;#a},G1=class Gm{#t;#e;#i;#n;constructor(e,t,n){this.produce=r=>r&&Object.keys(r).length?new Gm(this.#t,this.#e,{...r}):this,this.inject=(r,s)=>{const o=r.create(this.#t.sliceMap);return s!=null&&o.set(s),this.#n?.onInject(r),this},this.remove=r=>(this.#t.remove(r),this.#n?.onRemove(r),this),this.record=r=>(r.create(this.#e.store),this.#n?.onRecord(r),this),this.clearTimer=r=>(this.#e.remove(r),this.#n?.onClear(r),this),this.isInjected=r=>this.#t.has(r),this.isRecorded=r=>this.#e.has(r),this.use=r=>(this.#n?.onUse(r),this.#t.get(r)),this.get=r=>this.use(r).get(),this.set=(r,s)=>this.use(r).set(s),this.update=(r,s)=>this.use(r).update(s),this.timer=r=>this.#e.get(r),this.done=r=>{this.timer(r).done(),this.#n?.onDone(r)},this.wait=r=>{const s=this.timer(r).start();return this.#n?.onWait(r,s),s},this.waitTimers=async r=>{await Promise.all(this.get(r).map(s=>this.wait(s)))},this.#t=e,this.#e=t,this.#i=n,n&&(this.#n=new U1(e,t,n))}get meta(){return this.#i}get inspector(){return this.#n}},Y1=class{constructor(){this.store=new Map,this.get=i=>{const e=this.store.get(i.id);if(!e)throw z1(i.name);return e},this.remove=i=>{this.store.delete(i.id)},this.has=i=>this.store.has(i.id)}},X1=class{#t;#e;#i;#n;#s;constructor(i,e){this.#t=null,this.#e=null,this.#n="pending",this.#s=null,this.start=()=>(this.#t??=new Promise((t,n)=>{this.#e=r=>{r instanceof CustomEvent&&r.detail.id===this.#i&&(this.#n="resolved",this.#o(),r.stopImmediatePropagation(),t())},this.#r(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#o(),n(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{const t=new CustomEvent(this.type.name,{detail:{id:this.#i}});dispatchEvent(t)},this.#o=()=>{this.#s!==null&&(clearTimeout(this.#s),this.#s=null),this.#e&&removeEventListener(this.type.name,this.#e)},this.#r=t=>{this.#s=setTimeout(()=>{this.#s=null,t()},this.type.timeout)},this.#i=Symbol(e.name),this.type=e,i.set(e.id,this)}get status(){return this.#n}#o;#r},Q1=class{constructor(i,e=3e3){this.create=t=>new X1(t,this),this.id=Symbol(`Timer-${i}`),this.name=i,this.timeout=e}},Ut=(i,e=3e3)=>new Q1(i,e);function uh(i){const e=this;e.compiler=t;function t(n){return Bk(n,{...e.data("settings"),...i,extensions:e.data("toMarkdownExtensions")||[]})}}const Nc=(i,e)=>i.selection.empty?!1:(e&&e(i.tr.deleteSelection().scrollIntoView()),!0);function Ym(i,e){let{$cursor:t}=i.selection;return!t||(e?!e.endOfTextblock("backward",i):t.parentOffset>0)?null:t}const Xm=(i,e,t)=>{let n=Ym(i,t);if(!n)return!1;let r=Dc(n);if(!r){let o=n.blockRange(),l=o&&Il(o);return l==null?!1:(e&&e(i.tr.lift(o,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(eg(i,r,e,-1))return!0;if(n.parent.content.size==0&&(rr(s,"end")||V.isSelectable(s)))for(let o=n.depth;;o--){let l=Rl(i.doc,n.before(o),n.after(o),E.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=i.tr.step(l);a.setSelection(rr(s,"end")?_.findFrom(a.doc.resolve(a.mapping.map(r.pos,-1)),-1):V.create(a.doc,r.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||n.node(o-1).childCount>1)break}return s.isAtom&&r.depth==n.depth-1?(e&&e(i.tr.delete(r.pos-s.nodeSize,r.pos).scrollIntoView()),!0):!1},Z1=(i,e,t)=>{let n=Ym(i,t);if(!n)return!1;let r=Dc(n);return r?ex(i,r,e):!1};function ex(i,e,t){let n=e.nodeBefore,r=n,s=e.pos-1;for(;!r.isTextblock;s--){if(r.type.spec.isolating)return!1;let c=r.lastChild;if(!c)return!1;r=c}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let c=l.firstChild;if(!c)return!1;l=c}let h=Rl(i.doc,s,a,E.empty);if(!h||h.from!=s||h instanceof ue&&h.slice.size>=a-s)return!1;if(t){let c=i.tr.step(h);c.setSelection(K.create(c.doc,s)),t(c.scrollIntoView())}return!0}function rr(i,e,t=!1){for(let n=i;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(t&&n.childCount!=1)return!1}return!1}const Qm=(i,e,t)=>{let{$head:n,empty:r}=i.selection,s=n;if(!r)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",i):n.parentOffset>0)return!1;s=Dc(n)}let o=s&&s.nodeBefore;return!o||!V.isSelectable(o)?!1:(e&&e(i.tr.setSelection(V.create(i.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Dc(i){if(!i.parent.type.spec.isolating)for(let e=i.depth-1;e>=0;e--){if(i.index(e)>0)return i.doc.resolve(i.before(e+1));if(i.node(e).type.spec.isolating)break}return null}function tx(i,e){let{$cursor:t}=i.selection;return!t||(e?!e.endOfTextblock("forward",i):t.parentOffset<t.parent.content.size)?null:t}const nx=(i,e,t)=>{let n=tx(i,t);if(!n)return!1;let r=Zm(n);if(!r)return!1;let s=r.nodeAfter;if(eg(i,r,e,1))return!0;if(n.parent.content.size==0&&(rr(s,"start")||V.isSelectable(s))){let o=Rl(i.doc,n.before(),n.after(),E.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=i.tr.step(o);l.setSelection(rr(s,"start")?_.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):V.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&r.depth==n.depth-1?(e&&e(i.tr.delete(r.pos,r.pos+s.nodeSize).scrollIntoView()),!0):!1},ix=(i,e,t)=>{let{$head:n,empty:r}=i.selection,s=n;if(!r)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",i):n.parentOffset<n.parent.content.size)return!1;s=Zm(n)}let o=s&&s.nodeAfter;return!o||!V.isSelectable(o)?!1:(e&&e(i.tr.setSelection(V.create(i.doc,s.pos)).scrollIntoView()),!0)};function Zm(i){if(!i.parent.type.spec.isolating)for(let e=i.depth-1;e>=0;e--){let t=i.node(e);if(i.index(e)+1<t.childCount)return i.doc.resolve(i.after(e+1));if(t.type.spec.isolating)break}return null}const rx=(i,e)=>{let{$head:t,$anchor:n}=i.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(i.tr.insertText(`
|
|
7
|
+
`).scrollIntoView()),!0)};function Ic(i){for(let e=0;e<i.edgeCount;e++){let{type:t}=i.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const sx=(i,e)=>{let{$head:t,$anchor:n}=i.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let r=t.node(-1),s=t.indexAfter(-1),o=Ic(r.contentMatchAt(s));if(!o||!r.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=i.tr.replaceWith(l,l,o.createAndFill());a.setSelection(_.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},ox=(i,e)=>{let t=i.selection,{$from:n,$to:r}=t;if(t instanceof st||n.parent.inlineContent||r.parent.inlineContent)return!1;let s=Ic(r.parent.contentMatchAt(r.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&r.index()<r.parent.childCount?n:r).pos,l=i.tr.insert(o,s.createAndFill());l.setSelection(K.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},lx=(i,e)=>{let{$cursor:t}=i.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(jr(i.doc,s))return e&&e(i.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),r=n&&Il(n);return r==null?!1:(e&&e(i.tr.lift(n,r).scrollIntoView()),!0)};function ax(i){return(e,t)=>{if(e.selection instanceof V&&e.selection.node.isBlock){let{$from:d}=e.selection;return!d.parentOffset||!jr(e.doc,d.pos)?!1:(t&&t(e.tr.split(d.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let n=e.tr;!e.selection.empty&&(e.selection instanceof K||e.selection instanceof st)&&n.deleteSelection();let{$from:r}=n.selection,s=n.steps.length,o=[],l,a,h=!1,c=!1;for(let d=r.depth;;d--)if(r.node(d).isBlock){h=r.end(d)==r.pos+(r.depth-d),c=r.start(d)==r.pos-(r.depth-d),a=Ic(r.node(d-1).contentMatchAt(r.indexAfter(d-1))),o.unshift(h&&a?{type:a}:null),l=d;break}else{if(d==1)return!1;o.unshift(null)}let f=r.pos,u=jr(n.doc,f,o.length,o);if(u||(o[0]=a?{type:a}:null,u=jr(n.doc,f,o.length,o)),!u)return!1;if(n.split(f,o.length,o),!h&&c&&r.node(l).type!=a){let d=n.mapping.slice(s),p=d.map(r.before(l)),m=n.doc.resolve(p);a&&r.node(l-1).canReplaceWith(m.index(),m.index()+1,a)&&n.setNodeMarkup(d.map(r.before(l)),a)}return t&&t(n.scrollIntoView()),!0}}const hx=ax(),cx=(i,e)=>(e&&e(i.tr.setSelection(new st(i.doc))),!0);function fx(i,e,t){let n=e.nodeBefore,r=e.nodeAfter,s=e.index();return!n||!r||!n.type.compatibleContent(r.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(i.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(r.isTextblock||El(i.doc,e.pos))?!1:(t&&t(i.tr.join(e.pos).scrollIntoView()),!0)}function eg(i,e,t,n){let r=e.nodeBefore,s=e.nodeAfter,o,l,a=r.type.spec.isolating||s.type.spec.isolating;if(!a&&fx(i,e,t))return!0;let h=!a&&e.parent.canReplace(e.index(),e.index()+1);if(h&&(o=(l=r.contentMatchAt(r.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let d=e.pos+s.nodeSize,p=A.empty;for(let y=o.length-1;y>=0;y--)p=A.from(o[y].create(null,p));p=A.from(r.copy(p));let m=i.tr.step(new Be(e.pos-1,d,e.pos,d,new E(p,1,0),o.length,!0)),g=m.doc.resolve(d+2*o.length);g.nodeAfter&&g.nodeAfter.type==r.type&&El(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let c=s.type.spec.isolating||n>0&&a?null:_.findFrom(e,1),f=c&&c.$from.blockRange(c.$to),u=f&&Il(f);if(u!=null&&u>=e.depth)return t&&t(i.tr.lift(f,u).scrollIntoView()),!0;if(h&&rr(s,"start",!0)&&rr(r,"end")){let d=r,p=[];for(;p.push(d),!d.isTextblock;)d=d.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(d.canReplace(d.childCount,d.childCount,m.content)){if(t){let y=A.empty;for(let k=p.length-1;k>=0;k--)y=A.from(p[k].copy(y));let b=i.tr.step(new Be(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new E(y,p.length,0),0,!0));t(b.scrollIntoView())}return!0}}return!1}function tg(i){return function(e,t){let n=e.selection,r=i<0?n.$from:n.$to,s=r.depth;for(;r.node(s).isInline;){if(!s)return!1;s--}return r.node(s).isTextblock?(t&&t(e.tr.setSelection(K.create(e.doc,i<0?r.start(s):r.end(s)))),!0):!1}}const ux=tg(-1),dx=tg(1);function Ec(i,e=null){return function(t,n){let{$from:r,$to:s}=t.selection,o=r.blockRange(s),l=o&&Oc(o,i,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function us(i,e=null){return function(t,n){let r=!1;for(let s=0;s<t.selection.ranges.length&&!r;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,h)=>{if(r)return!1;if(!(!a.isTextblock||a.hasMarkup(i,e)))if(a.type==i)r=!0;else{let c=t.doc.resolve(h),f=c.index();r=c.parent.canReplaceWith(f,f+1,i)}})}if(!r)return!1;if(n){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[o];s.setBlockType(l,a,i,e)}n(s.scrollIntoView())}return!0}}function px(i,e,t,n){for(let r=0;r<e.length;r++){let{$from:s,$to:o}=e[r],l=s.depth==0?i.inlineContent&&i.type.allowsMarkType(t):!1;if(i.nodesBetween(s.pos,o.pos,(a,h)=>{if(l)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Rc(i,e=null,t){return function(n,r){let{empty:s,$cursor:o,ranges:l}=n.selection;if(s&&!o||!px(n.doc,l,i))return!1;if(r)if(o)i.isInSet(n.storedMarks||o.marks())?r(n.tr.removeStoredMark(i)):r(n.tr.addStoredMark(i.create(e)));else{let a,h=n.tr;a=!l.some(c=>n.doc.rangeHasMark(c.$from.pos,c.$to.pos,i));for(let c=0;c<l.length;c++){let{$from:f,$to:u}=l[c];if(!a)h.removeMark(f.pos,u.pos,i);else{let d=f.pos,p=u.pos,m=f.nodeAfter,g=u.nodeBefore,y=m&&m.isText?/^\s*/.exec(m.text)[0].length:0,b=g&&g.isText?/\s*$/.exec(g.text)[0].length:0;d+y<p&&(d+=y,p-=b),h.addMark(d,p,i.create(e))}}r(h.scrollIntoView())}return!0}}function br(...i){return function(e,t,n){for(let r=0;r<i.length;r++)if(i[r](e,t,n))return!0;return!1}}let da=br(Nc,Xm,Qm),Ku=br(Nc,nx,ix);const Qt={Enter:br(rx,ox,lx,hx),"Mod-Enter":sx,Backspace:da,"Mod-Backspace":da,"Shift-Backspace":da,Delete:Ku,"Mod-Delete":Ku,"Mod-a":cx},ng={"Ctrl-h":Qt.Backspace,"Alt-Backspace":Qt["Mod-Backspace"],"Ctrl-d":Qt.Delete,"Ctrl-Alt-Backspace":Qt["Mod-Delete"],"Alt-Delete":Qt["Mod-Delete"],"Alt-d":Qt["Mod-Delete"],"Ctrl-a":ux,"Ctrl-e":dx};for(let i in Qt)ng[i]=Qt[i];const mx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,gx=mx?ng:Qt;class kt{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t=="string"?yx(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1,this.inCodeMark=n.inCodeMark!==!1}}function yx(i){return function(e,t,n,r){let s=i;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),n+=o;let l=n-r;l>0&&(s=t[0].slice(o-l,o)+s,n=r)}return e.tr.insertText(s,n,r)}}const bx=(i,e)=>{let t=i.plugins;for(let n=0;n<t.length;n++){let r=t[n],s;if(r.spec.isInputRules&&(s=r.getState(i))){if(e){let o=i.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,i.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1};new kt(/--$/,"—",{inCodeMark:!1});new kt(/\.\.\.$/,"…",{inCodeMark:!1});new kt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1});new kt(/"$/,"”",{inCodeMark:!1});new kt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1});new kt(/'$/,"’",{inCodeMark:!1});function Bc(i,e,t=null,n){return new kt(i,(r,s,o,l)=>{let a=t instanceof Function?t(s):t,h=r.tr.delete(o,l),c=h.doc.resolve(o),f=c.blockRange(),u=f&&Oc(f,e,a);if(!u)return null;h.wrap(f,u);let d=h.doc.resolve(o-1).nodeBefore;return d&&d.type==e&&El(h.doc,o-1)&&(!n||n(s,d))&&h.join(o-1),h})}function ig(i,e,t=null){return new kt(i,(n,r,s,o)=>{let l=n.doc.resolve(s),a=t instanceof Function?t(r):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?n.tr.delete(s,o).setBlockType(s,s,e,a):null})}const Pn=typeof navigator<"u"?navigator:null,qu=typeof document<"u"?document:null,qn=Pn&&Pn.userAgent||"",dh=/Edge\/(\d+)/.exec(qn),rg=/MSIE \d/.exec(qn),ph=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(qn),Ll=!!(rg||ph||dh),kx=rg?document.documentMode:ph?+ph[1]:dh?+dh[1]:0,sg=!Ll&&/gecko\/(\d+)/i.test(qn),xx=sg&&+(/Firefox\/(\d+)/.exec(qn)||[0,0])[1],mh=!Ll&&/Chrome\/(\d+)/.exec(qn),og=!!mh,wx=mh?+mh[1]:0,lg=!Ll&&!!Pn&&/Apple Computer/.test(Pn.vendor),ag=lg&&(/Mobile\/\w+/.test(qn)||!!Pn&&Pn.maxTouchPoints>2),Sx=ag||(Pn?/Mac/.test(Pn.platform):!1),hg=/Android \d/.test(qn),cg=!!qu&&"webkitFontSmoothing"in qu.documentElement.style,Cx=cg?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;var ZN=Object.freeze({__proto__:null,android:hg,chrome:og,chrome_version:wx,gecko:sg,gecko_version:xx,ie:Ll,ie_version:kx,ios:ag,mac:Sx,safari:lg,webkit:cg,webkit_version:Cx});function pa(i,e,t,n,r,s){if(i.composing)return!1;const o=i.state,l=o.doc.resolve(e);if(l.parent.type.spec.code)return!1;const a=l.parent.textBetween(Math.max(0,l.parentOffset-500),l.parentOffset,void 0,"")+n;for(let h of r){const c=h,f=c.match.exec(a),u=f&&f[0]&&c.handler(o,f,e-(f[0].length-n.length),t);if(u)return c.undoable!==!1&&u.setMeta(s,{transform:u,from:e,to:t,text:n}),i.dispatch(u),!0}return!1}const vx=new Kn("MILKDOWN_CUSTOM_INPUTRULES");function Mx({rules:i}){const e=new un({key:vx,isInputRules:!0,state:{init(){return null},apply(t,n){const r=t.getMeta(this);return r||(t.selectionSet||t.docChanged?null:n)}},props:{handleTextInput(t,n,r,s){return pa(t,n,r,s,i,e)},handleDOMEvents:{compositionend:t=>(setTimeout(()=>{const{$cursor:n}=t.state.selection;n&&pa(t,n.pos,n.pos,"",i,e)}),!1),keydown:(t,n)=>!(hg&&og&&n.key==="Enter")||t.composing?!1:t.someProp("handleKeyDown",r=>r(t,n))?(n.preventDefault(),!0):!1},handleKeyDown(t,n){if(n.key!=="Enter")return!1;const{$cursor:r}=t.state.selection;return r?pa(t,r.pos,r.pos,`
|
|
8
|
+
`,i,e):!1}}});return e}function fg(i){return i.some(e=>e.type.spec.code)}function ju(i,e,t){if(e>=t)return!1;let n=!1;return i.doc.nodesBetween(e,t,r=>(r.isInline&&fg(r.marks)&&(n=!0),!n)),n}function Ax(i,e){var t;return fg((t=i.storedMarks)!=null?t:i.doc.resolve(e).marks())}function Fl(i,e,t={}){return new kt(i,(n,r,s,o)=>{var l,a,h,c;const{tr:f}=n,u=r.length;let d=r[u-1],p=r[0],m=[],g;const y={group:d,fullMatch:p,start:s,end:o},b=(l=t.updateCaptured)==null?void 0:l.call(t,y);if(Object.assign(y,b),{group:d,fullMatch:p,start:s,end:o}=y,p===null||d?.trim()==="")return null;if(d){const k=p.search(/\S/),O=s+p.indexOf(d),w=O+d.length,M=ju(n,s+k,O),C=w<o&&ju(n,w,o);if(M||C||Ax(n,o))return null;m=(a=f.storedMarks)!=null?a:[],w<o&&f.delete(w,o),O>s&&f.delete(s+k,O),g=s+k+d.length;const I=(h=t.getAttr)==null?void 0:h.call(t,r);f.addMark(s,g,e.create(I)),f.setStoredMarks(m),(c=t.beforeDispatch)==null||c.call(t,{match:r,start:s,end:o,tr:f})}return f})}function eD(i,e,t={}){return new kt(i,(n,r,s,o)=>{var l,a,h;const{tr:c}=n;let f=r[1],u=r[0];const d={group:f,fullMatch:u,start:s,end:o},p=(l=t.updateCaptured)==null?void 0:l.call(t,d);if(Object.assign(d,p),{group:f,fullMatch:u,start:s,end:o}=d,u===null||!f||f.trim()==="")return null;const m=(a=t.getAttr)==null?void 0:a.call(t,r),g=e.createAndFill(m);return g&&(c.replaceRangeWith(e.isBlock?c.doc.resolve(s).before():s,o,g),(h=t.beforeDispatch)==null||h.call(t,{match:[u,f],start:s,end:o,tr:c})),c})}var Ox=Object.defineProperty,Tx=Object.defineProperties,Nx=Object.getOwnPropertyDescriptors,Ju=Object.getOwnPropertySymbols,Dx=Object.prototype.hasOwnProperty,Ix=Object.prototype.propertyIsEnumerable,_u=(i,e,t)=>e in i?Ox(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,Ex=(i,e)=>{for(var t in e||(e={}))Dx.call(e,t)&&_u(i,t,e[t]);if(Ju)for(var t of Ju(e))Ix.call(e,t)&&_u(i,t,e[t]);return i},Rx=(i,e)=>Tx(i,Nx(e));function Uu(i=0,e=0,t=0){return Math.min(Math.max(i,e),t)}function tD(i,e,t){const r=i.state.doc.content.size,s=Uu(e,0,r),o=Uu(t,0,r),l=i.coordsAtPos(s),a=i.coordsAtPos(o,-1),h=Math.min(l.top,a.top),c=Math.max(l.bottom,a.bottom),f=Math.min(l.left,a.left),u=Math.max(l.right,a.right),d=u-f,p=c-h,y={top:h,bottom:c,left:f,right:u,width:d,height:p,x:f,y:h};return Rx(Ex({},y),{toJSON:()=>y})}function nD(i){return Object.assign(Object.create(i),i).setTime(Date.now())}function Bx(i,e){return Array.isArray(i)&&i.includes(e.type)||e.type===i}function iD(i){if(i.content.childCount===1){const e=i.content.firstChild;if(e?.type.name==="text"&&e.marks.length===0)return e;if(e?.type.name==="paragraph"&&e.childCount===1){const t=e.firstChild;if(t?.type.name==="text"&&t.marks.length===0)return t}}return!1}function Px(i){return e=>{for(let t=e.depth;t>0;t-=1){const n=e.node(t);if(i(n)){const r=e.before(t),s=e.after(t);return{from:r,to:s,node:n}}}}}function rD(i,e){return Px(t=>t.type===e)(i)}function sD(i,e){const t=e.nodes[i];if(!t)throw K1("node",i);return t}function Lx(i){return e=>{for(let t=e.depth;t>0;t--){const n=e.node(t);if(i(n))return{pos:e.before(t),start:e.start(t),depth:t,node:n}}}}function oD(i){return e=>Lx(i)(e.$from)}function Fx(i,e){if(!(i instanceof V))return;const{node:t,$from:n}=i;if(Bx(e,t))return{node:t,pos:n.pos,start:n.start(n.depth),depth:n.depth}}const Vx=(i,e)=>{const{selection:t,doc:n}=i;if(t instanceof V)return{hasNode:t.node.type===e,pos:t.from,target:t.node};const{from:r,to:s}=t;let o=!1,l=-1,a=null;return n.nodesBetween(r,s,(h,c)=>a?!1:h.type===e?(o=!0,l=c,a=h,!1):!0),{hasNode:o,pos:l,target:a}};var hn={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:"'"},ds={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},zx=typeof navigator<"u"&&/Mac/.test(navigator.platform),Hx=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ve=0;ve<10;ve++)hn[48+ve]=hn[96+ve]=String(ve);for(var ve=1;ve<=24;ve++)hn[ve+111]="F"+ve;for(var ve=65;ve<=90;ve++)hn[ve]=String.fromCharCode(ve+32),ds[ve]=String.fromCharCode(ve);for(var ma in hn)ds.hasOwnProperty(ma)||(ds[ma]=hn[ma]);function ug(i){var e=zx&&i.metaKey&&i.shiftKey&&!i.ctrlKey&&!i.altKey||Hx&&i.shiftKey&&i.key&&i.key.length==1||i.key=="Unidentified",t=!e&&i.key||(i.shiftKey?ds:hn)[i.keyCode]||i.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}const Wx=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),$x=typeof navigator<"u"&&/Win/.test(navigator.platform);function Kx(i){let e=i.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,r,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))n=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Wx?o=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return n&&(t="Alt-"+t),r&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function qx(i){let e=Object.create(null);for(let t in i)e[Kx(t)]=i[t];return e}function ga(i,e,t=!0){return e.altKey&&(i="Alt-"+i),e.ctrlKey&&(i="Ctrl-"+i),e.metaKey&&(i="Meta-"+i),t&&e.shiftKey&&(i="Shift-"+i),i}function jx(i){return new un({props:{handleKeyDown:Jx(i)}})}function Jx(i){let e=qx(i);return function(t,n){let r=ug(n),s,o=e[ga(r,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(n.shiftKey){let l=e[ga(r,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!($x&&n.ctrlKey&&n.altKey)&&(s=hn[n.keyCode])&&s!=r){let l=e[ga(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var dg=class{},pg=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=i=>{this.top()?.push(i)},this.open=i=>{this.elements.push(i)},this.close=()=>{const i=this.elements.pop();if(!i)throw Jm();return i}}},_x=class mg extends dg{constructor(e,t,n){super(),this.type=e,this.content=t,this.attrs=n}push(e,...t){this.content.push(e,...t)}pop(){return this.content.pop()}static create(e,t,n){return new mg(e,t,n)}},St,Gi,Ps,Ls,Fs,Yi,Xi,ui,Ux=(ui=class extends pg{constructor(t){super();ae(this,St);ae(this,Gi);ae(this,Ps);ae(this,Ls);ae(this,Fs);ae(this,Yi);ae(this,Xi);re(this,St,j.none),re(this,Gi,n=>n.isText),re(this,Ps,(n,r)=>{if(F(this,Gi).call(this,n)&&F(this,Gi).call(this,r)&&j.sameSet(n.marks,r.marks))return this.schema.text(n.text+r.text,n.marks)}),re(this,Ls,n=>{const r=Object.values({...this.schema.nodes,...this.schema.marks}).find(s=>s.spec.parseMarkdown.match(n));if(!r)throw W1(n);return r}),re(this,Fs,n=>{const r=F(this,Ls).call(this,n);r.spec.parseMarkdown.runner(this,n,r)}),this.injectRoot=(n,r,s)=>(this.openNode(r,s),this.next(n.children),this),this.openNode=(n,r)=>(this.open(_x.create(n,[],r)),this),re(this,Yi,()=>{re(this,St,j.none);const n=this.close();return F(this,Xi).call(this,n.type,n.attrs,n.content)}),this.closeNode=()=>{try{F(this,Yi).call(this)}catch(n){console.error(n)}return this},re(this,Xi,(n,r,s)=>{const o=n.createAndFill(r,s,F(this,St));if(!o)throw H1(n,r,s);return this.push(o),o}),this.addNode=(n,r,s)=>{try{F(this,Xi).call(this,n,r,s)}catch(o){console.error(o)}return this},this.openMark=(n,r)=>{const s=n.create(r);return re(this,St,s.addToSet(F(this,St))),this},this.closeMark=n=>(re(this,St,n.removeFromSet(F(this,St))),this),this.addText=n=>{try{const r=this.top();if(!r)throw Jm();const s=r.pop(),o=this.schema.text(n,F(this,St));if(!s)return r.push(o),this;const l=F(this,Ps).call(this,s,o);return l?(r.push(l),this):(r.push(s,o),this)}catch(r){return console.error(r),this}},this.build=()=>{let n;do n=F(this,Yi).call(this);while(this.size());return n},this.next=(n=[])=>([n].flat().forEach(r=>F(this,Fs).call(this,r)),this),this.toDoc=()=>this.build(),this.run=(n,r)=>{const s=n.runSync(n.parse(r),r);return this.next(s),this},this.schema=t}},St=new WeakMap,Gi=new WeakMap,Ps=new WeakMap,Ls=new WeakMap,Fs=new WeakMap,Yi=new WeakMap,Xi=new WeakMap,ui.create=(t,n)=>{const r=new ui(t);return s=>(r.run(n,s),r.toDoc())},ui),di,Gu=(di=class extends dg{constructor(e,t,n,r={}){super(),this.type=e,this.children=t,this.value=n,this.props=r,this.push=(s,...o)=>{this.children||(this.children=[]),this.children.push(s,...o)},this.pop=()=>this.children?.pop()}},di.create=(e,t,n,r={})=>new di(e,t,n,r),di),Gx=i=>Object.prototype.hasOwnProperty.call(i,"size"),ze,Qi,Vs,zs,Hs,Ws,Zi,er,$s,Ks,ii,An,qs,tr,pi,Yx=(pi=class extends pg{constructor(t){super();ae(this,ze);ae(this,Qi);ae(this,Vs);ae(this,zs);ae(this,Hs);ae(this,Ws);ae(this,Zi);ae(this,er);ae(this,$s);ae(this,Ks);ae(this,ii);ae(this,An);ae(this,qs);ae(this,tr);re(this,ze,[]),re(this,Qi,n=>{const r=Object.values({...this.schema.nodes,...this.schema.marks}).find(s=>s.spec.toMarkdown.match(n));if(!r)throw $1(n.type);return r}),re(this,Vs,n=>F(this,Qi).call(this,n).spec.toMarkdown.runner(this,n)),re(this,zs,(n,r)=>F(this,Qi).call(this,n).spec.toMarkdown.runner(this,n,r)),re(this,Hs,n=>{const r=l=>l.type.spec.priority??50,s=[...n].sort((l,a)=>r(l)-r(a)),o=[];return F(this,ze).forEach(({mark:l})=>{const a=s.findIndex(h=>h.eq(l));a>=0&&o.push(...s.splice(a,1))}),o.concat(s)}),re(this,Ws,n=>{const r=n?.marks;let s=0;for(;s<F(this,ze).length;){const{mark:o,spanning:l}=F(this,ze)[s];if(l&&r?.some(a=>a.eq(o)))s++;else break}for(let o=F(this,ze).length-1;o>=s;o--)F(this,tr).call(this,F(this,ze)[o].mark)}),re(this,Zi,(n,r)=>{F(this,Hs).call(this,n.marks).every(s=>!F(this,zs).call(this,s,n))&&F(this,Vs).call(this,n),F(this,Ws).call(this,r)}),re(this,er,n=>{const{children:r}=n;return r&&(n.children=r.reduce((s,o,l)=>{if(l===0)return[o];const a=s.at(-1);if(a&&a.isMark&&o.isMark){const{children:h,...c}=o,{children:f,...u}=a;if(o.type===a.type&&h&&f&&JSON.stringify(c)===JSON.stringify(u)){const d={...u,children:[...f,...h]};return s.slice(0,-1).concat(F(this,er).call(this,d))}}return s.concat(o)},[])),n}),re(this,$s,n=>{const r={...n.props,type:n.type};return n.children&&(r.children=n.children),n.value&&(r.value=n.value),r}),this.openNode=(n,r,s)=>(this.open(Gu.create(n,void 0,r,s)),this),re(this,Ks,(n,r)=>{let s="",o="";const l=n.children;if(l){const h=l[0],c=l.at(-1);if(c&&c.type==="text"&&c.value.endsWith(" ")){const f=c.value,u=f.trimEnd();o=f.slice(u.length),c.value=u}if(h&&h.type==="text"&&h.value.startsWith(" ")){const f=h.value,u=f.trimStart();s=f.slice(0,f.length-u.length),h.value=u}}s.length&&F(this,An).call(this,"text",void 0,s);const a=r();return o.length&&F(this,An).call(this,"text",void 0,o),a}),re(this,ii,(n=!1)=>{const r=this.close(),s=()=>F(this,An).call(this,r.type,r.children,r.value,r.props);return n?F(this,Ks).call(this,r,s):s()}),this.closeNode=()=>(F(this,ii).call(this),this),re(this,An,(n,r,s,o)=>{const l=Gu.create(n,r,s,o),a=F(this,er).call(this,F(this,$s).call(this,l));return this.push(a),a}),this.addNode=(n,r,s,o)=>(F(this,An).call(this,n,r,s,o),this),re(this,qs,(n,r,s,o)=>F(this,ze).some(l=>l.mark.eq(n))?this:(F(this,ze).push({mark:n,spanning:s==null}),this.openNode(r,s,{...o,isMark:!0}))),re(this,tr,n=>{let r=-1;for(let s=F(this,ze).length-1;s>=0;s--)if(F(this,ze)[s].mark.eq(n)){r=s;break}r<0||(F(this,ze).splice(r,1),F(this,ii).call(this,!0))}),this.withMark=(n,r,s,o)=>(F(this,qs).call(this,n,r,s,o),this),this.closeMark=n=>(F(this,tr).call(this,n),this),this.build=()=>{let n=null;do n=F(this,ii).call(this);while(this.size());return n.children||(n.children=[]),n},this.next=n=>Gx(n)?(n.forEach((r,s,o)=>{F(this,Zi).call(this,r,n.maybeChild(o+1)??void 0)}),this):(F(this,Zi).call(this,n),this),this.toString=n=>n.stringify(this.build()),this.run=n=>(re(this,ze,[]),this.next(n),this),this.schema=t}},ze=new WeakMap,Qi=new WeakMap,Vs=new WeakMap,zs=new WeakMap,Hs=new WeakMap,Ws=new WeakMap,Zi=new WeakMap,er=new WeakMap,$s=new WeakMap,Ks=new WeakMap,ii=new WeakMap,An=new WeakMap,qs=new WeakMap,tr=new WeakMap,pi.create=(t,n)=>{const r=new pi(t);return s=>(r.run(s),r.toString(n))},pi);const Me=function(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e},sr=function(i){let e=i.assignedSlot||i.parentNode;return e&&e.nodeType==11?e.host:e};let gh=null;const Xt=function(i,e,t){let n=gh||(gh=document.createRange());return n.setEnd(i,t??i.nodeValue.length),n.setStart(i,e||0),n},Xx=function(){gh=null},yi=function(i,e,t,n){return t&&(Yu(i,e,t,n,-1)||Yu(i,e,t,n,1))},Qx=/^(img|br|input|textarea|hr)$/i;function Yu(i,e,t,n,r){for(var s;;){if(i==t&&e==n)return!0;if(e==(r<0?0:Ee(i))){let o=i.parentNode;if(!o||!B(o)||_s(i)||Qx.test(i.nodeName)||i.contentEditable=="false")return!1;e=Me(i)+(r<0?0:1),i=o}else if(B(i)){let o=i.childNodes[e+(r<0?-1:0)];if(B(o)&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=r;else return!1;else i=o,e=r<0?Ee(i):0}else return!1}}function Ee(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}function B(i){return i.nodeType==1}function ge(i){return i.nodeType==3}function bi(i,e){return e?i.contains(B(e)?e:e.parentNode):!1}function Zx(i,e){for(;;){if(ge(i)&&e)return i;if(B(i)&&e>0){if(i.contentEditable=="false")return null;i=i.childNodes[e-1],e=Ee(i)}else if(i.parentNode&&!_s(i))e=Me(i),i=i.parentNode;else return null}}function ew(i,e){for(;;){if(ge(i)&&e<i.nodeValue.length)return i;if(B(i)&&e<i.childNodes.length){if(i.contentEditable=="false")return null;i=i.childNodes[e],e=0}else if(i.parentNode&&!_s(i))e=Me(i)+1,i=i.parentNode;else return null}}function tw(i,e,t){for(let n=e==0,r=e==Ee(i);n||r;){if(i==t)return!0;let s=Me(i);if(i=i.parentNode,!i)return!1;n=n&&s==0,r=r&&s==Ee(i)}}function _s(i){let e;for(let t=i;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==i||e.contentDOM==i)}const Vl=function(i){return i.focusNode&&yi(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)};function nw(i,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=i,t.key=t.code=e,t}function iw(i){let e=i.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function rw(i,e,t){if(i.caretPositionFromPoint)try{let n=i.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(Ee(n.offsetNode),n.offset)}}catch{}if(i.caretRangeFromPoint){let n=i.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(Ee(n.startContainer),n.startOffset)}}}const _t=typeof navigator<"u"?navigator:null,Xu=typeof document<"u"?document:null,jn=_t&&_t.userAgent||"",yh=/Edge\/(\d+)/.exec(jn),gg=/MSIE \d/.exec(jn),bh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(jn),et=!!(gg||bh||yh),Dn=gg?document.documentMode:bh?+bh[1]:yh?+yh[1]:0,ot=!et&&/gecko\/(\d+)/i.test(jn);ot&&+(/Firefox\/(\d+)/.exec(jn)||[0,0])[1];const kh=!et&&/Chrome\/(\d+)/.exec(jn),Oe=!!kh,yg=kh?+kh[1]:0,Le=!et&&!!_t&&/Apple Computer/.test(_t.vendor),or=Le&&(/Mobile\/\w+/.test(jn)||!!_t&&_t.maxTouchPoints>2),ht=or||(_t?/Mac/.test(_t.platform):!1),bg=_t?/Win/.test(_t.platform):!1,nn=/Android \d/.test(jn),zl=!!Xu&&"webkitFontSmoothing"in Xu.documentElement.style,sw=zl?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ow(i){let e=i.defaultView&&i.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:i.documentElement.clientWidth,top:0,bottom:i.documentElement.clientHeight}}function Yt(i,e){return typeof i=="number"?i:i[e]}function lw(i){let e=i.getBoundingClientRect(),t=e.width/i.offsetWidth||1,n=e.height/i.offsetHeight||1;return{left:e.left,right:e.left+i.clientWidth*t,top:e.top,bottom:e.top+i.clientHeight*n}}function Qu(i,e,t){if(!xh(e)&&e.left==0)return;let n=i.someProp("scrollThreshold")||0,r=i.someProp("scrollMargin")||5,s=i.dom.ownerDocument;for(let o=t||i.dom;o;){if(!B(o)){o=sr(o);continue}let l=o==s.body,a=l?ow(s):lw(o),h=0,c=0;if(e.top<a.top+Yt(n,"top")?c=-(a.top-e.top+Yt(r,"top")):e.bottom>a.bottom-Yt(n,"bottom")&&(c=e.bottom-e.top>a.bottom-a.top?e.top+Yt(r,"top")-a.top:e.bottom-a.bottom+Yt(r,"bottom")),e.left<a.left+Yt(n,"left")?h=-(a.left-e.left+Yt(r,"left")):e.right>a.right-Yt(n,"right")&&(h=e.right-a.right+Yt(r,"right")),h||c)if(l)s.defaultView.scrollBy(h,c);else{let u=o.scrollLeft,d=o.scrollTop;c&&(o.scrollTop+=c),h&&(o.scrollLeft+=h);let p=o.scrollLeft-u,m=o.scrollTop-d;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}let f=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:sr(o)}}function aw(i){let e=i.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,r;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=i.root.elementFromPoint(s,o);if(!l||l==i.dom||!i.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){n=l,r=a.top;break}}return{refDOM:n,refTop:r,stack:kg(i.dom)}}function kg(i){let e=[],t=i.ownerDocument;for(let n=i;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),i!=t);n=sr(n));return e}function hw({refDOM:i,refTop:e,stack:t}){let n=i?i.getBoundingClientRect().top:0;xg(t,n==0?0:n-e)}function xg(i,e){for(let t=0;t<i.length;t++){let{dom:n,top:r,left:s}=i[t];n.scrollTop!=r+e&&(n.scrollTop=r+e),n.scrollLeft!=s&&(n.scrollLeft=s)}}let Ni=null;function cw(i){if(i.setActive)return i.setActive();if(Ni)return i.focus(Ni);let e=kg(i);i.focus(Ni==null?{get preventScroll(){return Ni={preventScroll:!0},!0}}:void 0),Ni||(Ni=!1,xg(e,0))}function wg(i,e){let t,n=2e8,r,s=0,o=e.top,l=e.top,a,h;for(let c=i.firstChild,f=0;c;c=c.nextSibling,f++){let u;if(B(c))u=c.getClientRects();else if(ge(c))u=Xt(c).getClientRects();else continue;for(let d=0;d<u.length;d++){let p=u[d];if(p.top<=o&&p.bottom>=l){o=Math.max(p.bottom,o),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<n){t=c,n=m,r=m&&ge(t)?{left:p.right<e.left?p.right:p.left,top:e.top}:e,B(c)&&m&&(s=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=c,h={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)&&(s=f+1)}}return!t&&a&&(t=a,r=h,n=0),t&&ge(t)?fw(t,r):!t||n?{node:i,offset:s}:wg(t,r)}function fw(i,e){let t=i.nodeValue.length,n=document.createRange(),r;for(let s=0;s<t;s++){n.setEnd(i,s+1),n.setStart(i,s);let o=yn(n,1);if(o.top!=o.bottom&&Pc(e,o)){r={node:i,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return n.detach(),r||{node:i,offset:0}}function Pc(i,e){return i.left>=e.left-1&&i.left<=e.right+1&&i.top>=e.top-1&&i.top<=e.bottom+1}function uw(i,e){let t=i.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<i.getBoundingClientRect().left?t:i}function dw(i,e,t){let{node:n,offset:r}=wg(e,t),s=-1;if(B(n)&&!n.firstChild){let o=n.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return i.docView.posFromDOM(n,r,s)}function pw(i,e,t,n){let r=-1;for(let s=e,o=!1;s!=i.dom;){let l=i.docView.nearestDesc(s,!0),a;if(!l)return null;if(B(l.dom)&&(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)&&(!o&&a.left>n.left||a.top>n.top?r=l.posBefore:(!o&&a.right<n.left||a.bottom<n.top)&&(r=l.posAfter),o=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?n.top<(a.top+a.bottom)/2:n.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:i.docView.posFromDOM(e,t,-1)}function Sg(i,e,t){let n=i.childNodes.length;if(n&&t.top<t.bottom)for(let r=Math.max(0,Math.min(n-1,Math.floor(n*(e.top-t.top)/(t.bottom-t.top))-2)),s=r;;){let o=i.childNodes[s];if(B(o)){let l=o.getClientRects();for(let a=0;a<l.length;a++){let h=l[a];if(Pc(e,h))return Sg(o,e,h)}}if((s=(s+1)%n)==r)break}return i}function mw(i,e){let t=i.dom.ownerDocument,n,r=0,s=rw(t,e.left,e.top);s&&({node:n,offset:r}=s);let o=(i.root.elementFromPoint?i.root:t).elementFromPoint(e.left,e.top),l;if(!o||!i.dom.contains(o)){let h=i.dom.getBoundingClientRect();if(!Pc(e,h)||(o=Sg(i.dom,e,h),!o))return null}if(Le)for(let h=o;n&&h;h=sr(h))h.draggable&&(n=void 0);if(o=uw(o,e),n){if(ot&&B(n)&&(r=Math.min(r,n.childNodes.length),r<n.childNodes.length)){let c=n.childNodes[r],f;c.nodeName=="IMG"&&(f=c.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&r++}let h;zl&&r&&B(n)&&B(h=n.childNodes[r-1])&&h.contentEditable=="false"&&h.getBoundingClientRect().top>=e.top&&r--,n==i.dom&&r==n.childNodes.length-1&&B(n.lastChild)&&e.top>n.lastChild.getBoundingClientRect().bottom?l=i.state.doc.content.size:(r==0||!B(n)||n.childNodes[r-1].nodeName!="BR")&&(l=pw(i,n,r,e))}l==null&&(l=dw(i,o,e));let a=i.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function xh(i){return i.top<i.bottom||i.left<i.right}function yn(i,e){let t=i.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(xh(n))return n}return Array.prototype.find.call(t,xh)||i.getBoundingClientRect()}const gw=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Cg(i,e,t){let{node:n,offset:r,atom:s}=i.docView.domFromPos(e,t<0?-1:1),o=zl||ot;if(ge(n))if(o&&(gw.test(n.nodeValue)||(t<0?!r:r==n.nodeValue.length))){let a=yn(Xt(n,r,r),t);if(ot&&r&&/\s/.test(n.nodeValue[r-1])&&r<n.nodeValue.length){let h=yn(Xt(n,r-1,r-1),-1);if(h.top==a.top){let c=yn(Xt(n,r,r+1),-1);if(c.top!=a.top)return Or(c,c.left<h.left)}}return a}else{let a=r,h=r,c=t<0?1:-1;return t<0&&!r?(h++,c=-1):t>=0&&r==n.nodeValue.length?(a--,c=1):t<0?a--:h++,Or(yn(Xt(n,a,h),c),c<0)}if(!i.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Ee(n))){let a=n.childNodes[r-1];if(B(a))return ya(a.getBoundingClientRect(),!1)}if(s==null&&r<Ee(n)){let a=n.childNodes[r];if(B(a))return ya(a.getBoundingClientRect(),!0)}return ya(n.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Ee(n))){let a=n.childNodes[r-1],h=ge(a)?Xt(a,Ee(a)-(o?0:1)):B(a)&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(h)return Or(yn(h,1),!1)}if(s==null&&r<Ee(n)){let a=n.childNodes[r];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let h=a?ge(a)?Xt(a,0,o?0:1):B(a)?a:null:null;if(h)return Or(yn(h,-1),!0)}return Or(yn(ge(n)?Xt(n):n,-t),t>=0)}function Or(i,e){if(i.width==0)return i;let t=e?i.left:i.right;return{top:i.top,bottom:i.bottom,left:t,right:t}}function ya(i,e){if(i.height==0)return i;let t=e?i.top:i.bottom;return{top:t,bottom:t,left:i.left,right:i.right}}function vg(i,e,t){let n=i.state,r=i.root.activeElement;n!=e&&i.updateState(e),r!=i.dom&&i.focus();try{return t()}finally{n!=e&&i.updateState(n),r!=i.dom&&r&&r.focus()}}function yw(i,e,t){let n=e.selection,r=t=="up"?n.$from:n.$to;return vg(i,e,()=>{let{node:s}=i.docView.domFromPos(r.pos,t=="up"?-1:1);for(;;){let l=i.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Cg(i,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(B(l))a=l.getClientRects();else if(ge(l))a=Xt(l,0,l.nodeValue.length).getClientRects();else continue;for(let h=0;h<a.length;h++){let c=a[h];if(c.bottom>c.top+1&&(t=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}const bw=/[\u0590-\u08ac]/;function kw(i,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let r=n.parentOffset,s=!r,o=r==n.parent.content.size,l=i.domSelection();return l?!bw.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:vg(i,e,()=>{let{focusNode:a,focusOffset:h,anchorNode:c,anchorOffset:f}=i.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let d=n.depth?i.docView.domAfterPos(n.before()):i.dom,{focusNode:p,focusOffset:m}=i.domSelectionRange(),g=p&&!bi(d,p)||a==p&&h==m;try{l.collapse(c,f),a&&(a!=c||h!=f)&&l.extend&&l.extend(a,h)}catch{}return u!=null&&(l.caretBidiLevel=u),g}):n.pos==n.start()||n.pos==n.end()}let Zu=null,ed=null,td=!1;function xw(i,e,t){return Zu==e&&ed==t?td:(Zu=e,ed=t,td=t=="up"||t=="down"?yw(i,e,t):kw(i,e,t))}const bt=0,nd=1,Qn=2,Mt=3;class Us{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=bt,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){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,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.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,n){if(this.contentDOM&&bi(this.contentDOM,e))if(n<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Me(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let s=e.compareDocumentPosition(this.contentDOM);s&16?r=t>Array.from(e.childNodes).findIndex(o=>o.contains(this.contentDOM)):r=!(s&4)}else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!1;break}if(s.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!0;break}if(s.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let s=this.getDesc(r),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(B(o)?bi(o,e):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],s=n+r.size;if(n==e&&s!=n){for(;!r.border&&r.children.length;)for(let o=0;o<r.children.length;o++){let l=r.children[o];if(l.size){r=l;break}}return r}if(e<s)return r.descAt(e-n-r.border);n=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let s=0;n<this.children.length;n++){let o=this.children[n],l=s+o.size;if(l>e){r=e-s;break}s=l}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(;n>0;n--){let s=this.children[n-1];if(s.size||!(s instanceof Ag||s instanceof Mg&&s.side>=0))break}if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?Me(s.dom)+1:0}}else{let s,o=!0;for(;s=n<this.children.length?this.children[n]:null,!(!s||s.dom.parentNode==this.contentDOM);n++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?Me(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let o=n,l=0;;l++){let a=this.children[l],h=o+a.size;if(r==-1&&e<=h){let c=o+a.border;if(e>=c&&t<=h-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=o;for(let f=l;f>0;f--){let u=this.children[f-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){r=Me(u.dom)+1;break}e-=u.size}r==-1&&(r=0)}if(r>-1&&(h>t||l==this.children.length-1)){t=h;for(let c=l+1;c<this.children.length;c++){let f=this.children[c];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=Me(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=h}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:s}}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:n}=this.domFromPos(e,0);if(!B(t)||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let d=0,p=0;d<this.children.length;d++){let m=this.children[d],g=p+m.size;if(s>p&&o<g)return m.setSelection(e-p-m.border,t-p-m.border,n,r);p=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),h=n.root.getSelection(),c=n.domSelectionRange(),f=!1;if((ot||Le)&&e==t){let{node:d,offset:p}=l;if(ge(d)){if(f=!!(p&&d.nodeValue[p-1]==`
|
|
9
|
+
`),f&&p==d.nodeValue.length)for(let m=d,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:Me(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=d.childNodes[p-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(ot&&c.focusNode&&c.focusNode!=a.node&&B(c.focusNode)){let d=c.focusNode.childNodes[c.focusOffset];d&&d.contentEditable=="false"&&(r=!0)}if(!(r||f&&Le)&&yi(l.node,l.offset,c.anchorNode,c.anchorOffset)&&yi(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((h.extend||e==t)&&!(f&&ot)){h.collapse(l.node,l.offset);try{e!=t&&h.extend(a.node,a.offset),u=!0}catch{}}if(!u){if(e>t){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),h.removeAllRanges(),h.addRange(d)}}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 n=0,r=0;r<this.children.length;r++){let s=this.children[r],o=n+s.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?Qn:nd,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Mt:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Qn:Mt}n=o}this.dirty=Qn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Qn:nd;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Mg extends Us{constructor(e,t,n,r){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(n,()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){let l=B(o)?o:document.createElement("span");l!=o&&(l.appendChild(o),o=l),l.hasAttribute("contenteditable")||(l.contentEditable="false"),l.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==bt&&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}}class ww extends Us{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}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}}class In extends Us{constructor(e,t,n,r,s){super(e,[],n,r),this.mark=t,this.spec=s}static create(e,t,n,r){let s=r.nodeViews[t.type.name],o=s&&s(t,r,n);return(!o||!o.dom)&&(o=yr.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new In(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Mt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Mt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=bt){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=bt}}slice(e,t,n){let r=In.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=Sh(s,t,o,n)),e>0&&(s=Sh(s,0,e,n));for(let l=0;l<s.length;l++)s[l].parent=r;return r.children=s,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class En extends Us{constructor(e,t,n,r,s,o,l){super(e,[],s,o),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=l}static create(e,t,n,r,s,o){let l=s.nodeViews[t.type.name],a,h=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,r),c=h&&h.dom,f=h&&h.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(!ge(c))throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=yr.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return c=Ng(c,n,t),h?a=new Sw(e,t,n,r,c,f||null,u,h):t.isText?new Hl(e,t,n,r,c,u):new En(e,t,n,r,c,f||null,u)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(t.preserveWhitespace="full"),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){t.contentElement=r.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(r=>B(r)&&e.indexOf(r.parentNode)<0&&this.dom.contains(r));n?t.contentElement=n:t.getContent=()=>A.empty}}return t}matchesNode(e,t,n){return this.dirty==bt&&e.eq(this.node)&&sl(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new vw(this,o&&o.node,e),h=this.node.inlineContent,c=h&&this.node.isBlock;Ow(this.node,this.innerDeco,(f,u,d)=>{f.spec.marks?a.syncToMarks(f.spec.marks,n,e,u):f.type.side>=0&&!d&&a.syncToMarks(u==this.node.childCount?j.none:this.node.child(u).marks,n,e,u),a.placeWidget(f,e,r)},(f,u,d,p)=>{a.syncToMarks(f.marks,n,e,p),c&&f.isAtom&&!f.isText&&a.addHackNode("IMG",a.top);let m;a.findNodeMatch(f,u,d,p)||l&&e.state.selection.from>r&&e.state.selection.to<r+f.nodeSize&&(m=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(f,u,d,m,e)||a.updateNextNode(f,u,d,e,p,r)||a.addNode(f,u,d,e,r),r+=f.nodeSize,h&&(c=f.isAtom&&!f.isText)}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Qn)&&(o&&this.protectLocalComposition(e,o),Og(this.contentDOM,this.children,e),or&&Tw(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof K)||n<t||r>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Nw(this.node.content,o,n-t,r-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new ww(this,s,t,r);e.input.compositionNodes.push(o),this.children=Sh(this.children,n,n+r.length,e,o)}update(e,t,n,r){return this.dirty==Mt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=bt}updateOuterDeco(e){if(sl(e,this.outerDeco))return;let t=!B(this.nodeDOM),n=this.dom;this.dom=Tg(this.dom,this.nodeDOM,wh(this.outerDeco,this.node,t),wh(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){B(this.nodeDOM)&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){B(this.nodeDOM)&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function id(i,e,t,n,r){Ng(n,e,i);let s=new En(void 0,i,e,t,n,n,n);return s.contentDOM&&s.updateChildren(r,0),s}class Hl extends En{constructor(e,t,n,r,s,o){super(e,t,n,r,s,null,o)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==Mt||this.dirty!=bt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=bt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=bt,!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,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let r=this.node.cut(e,t),s=document.createTextNode(r.text);return new Hl(this.parent,r,this.outerDeco,this.innerDeco,s,s)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Mt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Ag extends Us{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==bt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Sw extends En{constructor(e,t,n,r,s,o,l,a){super(e,t,n,r,s,o,l),this.spec=a}update(e,t,n,r){if(this.dirty==Mt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,r),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}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 Og(i,e,t){let n=i.firstChild,r=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==i){for(;l!=n;)n=rd(n),r=!0;n=n.nextSibling}else r=!0,i.insertBefore(l,n);if(o instanceof In){let a=n?n.previousSibling:i.lastChild;Og(o.contentDOM,o.children,t),n=a?a.nextSibling:i.firstChild}}for(;n;)n=rd(n),r=!0;r&&t.trackWrites==i&&(t.trackWrites=null)}const Jr=function(i){i&&(this.nodeName=i)};Jr.prototype=Object.create(null);const Zn=[new Jr];function wh(i,e,t){if(i.length==0)return Zn;let n=t?Zn[0]:new Jr,r=[n];for(let s=0;s<i.length;s++){let o=i[s].type.attrs;if(o){o.nodeName&&r.push(n=new Jr(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&r.length==1&&r.push(n=new Jr(e.isInline?"span":"div")),l=="class"?n.class=(n.class?n.class+" ":"")+a:l=="style"?n.style=(n.style?n.style+";":"")+a:l!="nodeName"&&(n[l]=a))}}}return r}function Tg(i,e,t,n){if(t==Zn&&n==Zn)return e;let r=e;for(let s=0;s<n.length;s++){let o=n[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&r!=i&&(a=r.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(r),l=Zn[0]),r=a}Cw(r,l||Zn[0],o)}return r}function Cw(i,e,t){for(let n in e)n!="class"&&n!="style"&&n!="nodeName"&&!(n in t)&&i.removeAttribute(n);for(let n in t)n!="class"&&n!="style"&&n!="nodeName"&&t[n]!=e[n]&&i.setAttribute(n,t[n]);if(e.class!=t.class){let n=e.class?e.class.split(" ").filter(Boolean):[],r=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<n.length;s++)r.indexOf(n[s])==-1&&i.classList.remove(n[s]);for(let s=0;s<r.length;s++)n.indexOf(r[s])==-1&&i.classList.add(r[s]);i.classList.length==0&&i.removeAttribute("class")}if(e.style!=t.style){if(e.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(e.style);)i.style.removeProperty(r[1])}t.style&&(i.style.cssText+=t.style)}}function Ng(i,e,t){return Tg(i,i,Zn,wh(e,t,!B(i)))}function sl(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(!i[t].type.eq(e[t].type))return!1;return!0}function rd(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}class vw{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Mw(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=bt,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,h=this.top.children.length;r<this.preMatch.index&&(h=Math.min(this.index+3,h));for(let c=this.index;c<h;c++){let f=this.top.children[c];if(f.matchesMark(e[o])&&!this.isLocked(f.dom)){a=c;break}}if(a<0&&this.index<this.top.children.length){let c=this.top.children[this.index];c instanceof In&&c.dirty!=Mt&&c.mark.type==e[o].type&&c.spec.update&&!this.isLocked(c.dom)&&c.spec.update(e[o])&&(c.mark=e[o],a=this.index,this.changed=!0)}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let c=In.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,r){let s=-1,o;if(r>=this.preMatch.index&&(o=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let h=this.top.children[l];if(h.matchesNode(e,t,n)&&!this.preMatch.matched.has(h)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,r,s){let o=this.top.children[r];return o.dirty==Mt&&o.dom==o.contentDOM&&(o.dirty=Qn),o.update(e,t,n,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let n=e.pmViewDesc;if(n){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==n)return r}return-1}e=t}}updateNextNode(e,t,n,r,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof En){let h=this.preMatch.matched.get(a);if(h!=null&&h!=s)return!1;let c=a.dom,f,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=Mt&&sl(t,a.outerDeco));if(!u&&a.update(e,t,n,r))return this.destroyBetween(this.index,l),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(f=this.recreateWrapper(a,e,t,n,r,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Qn,f.updateChildren(r,o+1),f.dirty=bt),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!sl(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=En.create(this.top,t,n,r,s,o);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,n,r,s){let o=En.create(this.top,e,t,n,r,s);o.contentDOM&&o.updateChildren(r,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let s=new Mg(this.top,e,t,n);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof In;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Hl)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Le||Oe)&&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 n=document.createElement(e);e=="IMG"&&(n.className="ProseMirror-separator",n.alt=""),e=="BR"&&(n.className="ProseMirror-trailingBreak");let r=new Ag(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||B(e)&&e.contains(this.lock.parentNode))}}function Mw(i,e){let t=e,n=t.children.length,r=i.childCount,s=new Map,o=[];e:for(;r>0;){let l;for(;;)if(n){let h=t.children[n-1];if(h instanceof In)t=h,n=h.children.length;else{l=h,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=i.child(r-1))break;--r,s.set(l,r),o.push(l)}}return{index:r,matched:s,matches:o.reverse()}}function Aw(i,e){return i.type.side-e.type.side}function Ow(i,e,t,n){let r=e.locals(i),s=0;if(r.length==0){for(let h=0;h<i.childCount;h++){let c=i.child(h);n(c,r,e.forChild(s,c),h),s+=c.nodeSize}return}let o=0,l=[],a=null;for(let h=0;;){let c,f;for(;o<r.length&&r[o].to==s;){let g=r[o++];g.widget&&(c?(f||(f=[c])).push(g):c=g)}if(c)if(f){f.sort(Aw);for(let g=0;g<f.length;g++)t(f[g],h,!!a)}else t(c,h,!!a);let u,d;if(a)d=-1,u=a,a=null;else if(h<i.childCount)d=h,u=i.child(h++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<r.length&&r[o].from<=s&&r[o].to>s;)l.push(r[o++]);let p=s+u.nodeSize;if(u.isText){let g=p;o<r.length&&r[o].from<g&&(g=r[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<p&&(a=u.cut(g-s),u=u.cut(0,g-s),p=g,d=-1)}else for(;o<r.length&&r[o].to<p;)o++;let m=u.isInline&&!u.isLeaf?l.filter(g=>!g.inline):l.slice();n(u,m,e.forChild(s,u),d),s=p}}function Tw(i){if(i.nodeName=="UL"||i.nodeName=="OL"){let e=i.style.cssText;i.style.cssText=e+"; list-style: square !important",window.getComputedStyle(i).listStyle,i.style.cssText=e}}function Nw(i,e,t,n){for(let r=0,s=0;r<i.childCount&&s<=n;){let o=i.child(r++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;r<i.childCount;){let h=i.child(r++);if(s+=h.nodeSize,!h.isText)break;a+=h.text}if(s>=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let h=l<n?a.lastIndexOf(e,n-l-1):-1;if(h>=0&&h+e.length+l>=t)return l+h;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function Sh(i,e,t,n,r){let s=[];for(let o=0,l=0;o<i.length;o++){let a=i[o],h=l,c=l+=a.size;h>=t||c<=e?s.push(a):(h<e&&s.push(a.slice(0,e-h,n)),r&&(s.push(r),r=void 0),c>t&&s.push(a.slice(t-h,a.size,n)))}return s}function Lc(i,e=null){let t=i.domSelectionRange(),n=i.state.doc;if(!t.focusNode)return null;let r=i.docView.nearestDesc(t.focusNode),s=r&&r.size==0,o=i.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,h;if(Vl(t)){for(a=o;r&&!r.node;)r=r.parent;if(r&&r.node.isAtom&&V.isSelectable(r.node)&&r.parent&&!(r.node.isInline&&tw(t.focusNode,t.focusOffset,r.dom))){let f=r.posBefore;h=new V(o==f?l:n.resolve(f))}else if(ot&&e=="key"&&o>i.state.selection.to&&B(t.focusNode)&&t.focusOffset==t.focusNode.childNodes.length&&r&&r.posAtStart>i.state.selection.to)for(let f=t.focusNode;;f=f.parentNode){if(getComputedStyle(f).overflow!="visible"){h=_.findFrom(n.resolve(r.posAtStart),1);break}if(f==r.dom||f.nextSibling||!f.parentNode||!B(f.parentNode))break}}else{if(t instanceof i.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,u=o;for(let d=0;d<t.rangeCount;d++){let p=t.getRangeAt(d);f=Math.min(f,i.docView.posFromDOM(p.startContainer,p.startOffset,1)),u=Math.max(u,i.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(f<0)return null;[a,o]=u==i.state.selection.anchor?[u,f]:[f,u],l=n.resolve(o)}else a=i.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let c=n.resolve(a);if(!h){let f=e=="pointer"||i.state.selection.head<l.pos&&!s?1:-1;h=Fc(i,c,l,f)}return h}function Dg(i){return i.editable?i.hasFocus():Eg(i)&&document.activeElement&&document.activeElement.contains(i.dom)}function sn(i,e=!1){let t=i.state.selection;if(Ig(i,t),!Dg(i))return;let n=i.input.mouseDown;if(!e&&Oe&&n){let r=i.domSelectionRange(),s=i.domObserver.currentSelection;if(r.anchorNode&&s.anchorNode&&yi(r.anchorNode,r.anchorOffset,s.anchorNode,s.anchorOffset)&&n.delaySelUpdate()){i.domObserver.setCurSelection();return}}if(i.domObserver.disconnectSelection(),i.cursorWrapper)Iw(i);else{let{anchor:r,head:s}=t,o,l;sd&&!(t instanceof K)&&(t.$from.parent.inlineContent||(o=od(i,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(l=od(i,t.to))),i.docView.setSelection(r,s,i,e),sd&&(o&&ld(o),l&&ld(l)),t.visible?i.dom.classList.remove("ProseMirror-hideselection"):(i.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Dw(i))}i.domObserver.setCurSelection(),i.domObserver.connectSelection()}const sd=Le||Oe&&yg<63;function od(i,e){let{node:t,offset:n}=i.docView.domFromPos(e,0),r=n<t.childNodes.length?t.childNodes[n]:null,s=n?t.childNodes[n-1]:null;if(Le&&r&&r.contentEditable=="false")return ba(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return ba(r);if(s)return ba(s)}}function ba(i){return i.contentEditable="true",Le&&i.draggable&&(i.draggable=!1,i.wasDraggable=!0),i}function ld(i){i.contentEditable="false",i.wasDraggable&&(i.draggable=!0,i.wasDraggable=null)}function Dw(i){let e=i.dom.ownerDocument;e.removeEventListener("selectionchange",i.input.hideSelectionGuard);let t=i.domSelectionRange(),n=t.anchorNode,r=t.anchorOffset;e.addEventListener("selectionchange",i.input.hideSelectionGuard=()=>{(t.anchorNode!=n||t.anchorOffset!=r)&&(e.removeEventListener("selectionchange",i.input.hideSelectionGuard),setTimeout(()=>{(!Dg(i)||i.state.selection.visible)&&i.dom.classList.remove("ProseMirror-hideselection")},20))})}function Iw(i){let e=i.domSelection();if(!e)return;let t=i.cursorWrapper.dom,n=t.nodeName=="IMG";n?e.collapse(t.parentNode,Me(t)+1):e.collapse(t,0),!n&&!i.state.selection.visible&&et&&Dn<=11&&(t.disabled=!0,t.disabled=!1)}function Ig(i,e){if(e instanceof V){let t=i.docView.descAt(e.from);t!=i.lastSelectedViewDesc&&(ad(i),t&&t.selectNode(),i.lastSelectedViewDesc=t)}else ad(i)}function ad(i){i.lastSelectedViewDesc&&(i.lastSelectedViewDesc.parent&&i.lastSelectedViewDesc.deselectNode(),i.lastSelectedViewDesc=void 0)}function Fc(i,e,t,n){return i.someProp("createSelectionBetween",r=>r(i,e,t))||K.between(e,t,n)}function hd(i){return i.editable&&!i.hasFocus()?!1:Eg(i)}function Eg(i){let e=i.domSelectionRange();if(!e.anchorNode)return!1;try{return bi(i.dom,e.anchorNode)&&(i.editable||bi(i.dom,e.focusNode))}catch{return!1}}function Ew(i){let e=i.docView.domFromPos(i.state.selection.anchor,0),t=i.domSelectionRange();return yi(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ch(i,e){let{$anchor:t,$head:n}=i.selection,r=e>0?t.max(n):t.min(n),s=r.parent.inlineContent?r.depth?i.doc.resolve(e>0?r.after():r.before()):null:r;return s&&_.findFrom(s,e)}function bn(i,e){return i.dispatch(i.state.tr.setSelection(e).scrollIntoView()),!0}function cd(i,e,t){let n=i.state.selection;if(n instanceof K)if(t.indexOf("s")>-1){let{$head:r}=n,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=i.state.doc.resolve(r.pos+s.nodeSize*(e<0?-1:1));return bn(i,new K(n.$anchor,o))}else if(n.empty){if(i.endOfTextblock(e>0?"forward":"backward")){let r=Ch(i.state,e);return r&&r instanceof V?bn(i,r):!1}else if(!ht||t.indexOf("m")<0){let r=n.$head,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?r.pos-s.nodeSize:r.pos;return s.isAtom||(o=i.docView.descAt(l))&&!o.contentDOM?V.isSelectable(s)?bn(i,new V(e<0?i.state.doc.resolve(r.pos-s.nodeSize):r)):bn(i,new K(i.state.doc.resolve(e<0?l:l+s.nodeSize))):!1}}else return!1;else{if(n instanceof V&&n.node.isInline)return bn(i,new K(e>0?n.$to:n.$from));{let r=Ch(i.state,e);return r?bn(i,r):!1}}}function _r(i,e){let t=i.pmViewDesc;return t?t.size==0&&(e<0||i.nextSibling||i.nodeName!="BR"):B(i)&&i.contentEditable=="false"}function Di(i,e){return e<0?Rw(i):Bw(i)}function Rw(i){let e=i.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let r,s,o=!1;for(ot&&B(t)&&n<Ee(t)&&_r(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(!B(t))break;let l=t.childNodes[n-1];if(_r(l,-1))r=t,s=--n;else if(ge(l))t=l,n=t.nodeValue.length;else break}else{if(Rg(t))break;{let l=t.previousSibling;for(;l&&_r(l,-1);)r=t.parentNode,s=Me(l),l=l.previousSibling;if(l)t=l,n=Ee(t);else{if(t=t.parentNode,t==i.dom)break;n=0}}}o?vh(i,t,n):r&&vh(i,r,s)}function Bw(i){let e=i.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let r=Ee(t),s,o;for(;;)if(n<r){if(!B(t))break;let l=t.childNodes[n];if(_r(l,1))s=t,o=++n;else break}else{if(Rg(t))break;{let l=t.nextSibling;for(;l&&_r(l,1);)s=l.parentNode,o=Me(l)+1,l=l.nextSibling;if(l)t=l,n=0,r=Ee(t);else{if(t=t.parentNode,t==i.dom)break;n=r=0}}}s&&vh(i,s,o)}function Rg(i){let e=i.pmViewDesc;return e&&e.node&&e.node.isBlock}function Pw(i,e){for(;i&&e==i.childNodes.length&&!_s(i);)e=Me(i)+1,i=i.parentNode;for(;i&&e<i.childNodes.length;){let t=i.childNodes[e];if(ge(t))return t;if(B(t)&&t.contentEditable=="false")break;i=t,e=0}}function Lw(i,e){for(;i&&!e&&!_s(i);)e=Me(i),i=i.parentNode;for(;i&&e;){let t=i.childNodes[e-1];if(ge(t))return t;if(B(t)&&t.contentEditable=="false")break;i=t,e=i.childNodes.length}}function vh(i,e,t){if(!ge(e)){let o,l;(l=Pw(e,t))?(e=l,t=0):(o=Lw(e,t))&&(e=o,t=o.nodeValue.length)}let n=i.domSelection(),r=i.domSelectionRange();if(!n)return;Vl(r)?n.collapse(e,t):n.extend&&(n.collapse(r.anchorNode,r.anchorOffset),n.extend(e,t)),i.domObserver.setCurSelection();let{state:s}=i;setTimeout(()=>{i.state==s&&sn(i)},50)}function fd(i,e){let t=i.state.doc.resolve(e);if(!(Oe||bg)&&t.parent.inlineContent){let s=i.coordsAtPos(e);if(e>t.start()){let o=i.coordsAtPos(e-1),l=(o.top+o.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(o.left-s.left)>1)return o.left<s.left?"ltr":"rtl"}if(e<t.end()){let o=i.coordsAtPos(e+1),l=(o.top+o.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(o.left-s.left)>1)return o.left>s.left?"ltr":"rtl"}}let n=i.dom;for(let s=t.depth;s>0;s--)if(t.node(s).isBlock){n=i.nodeDOM(t.before(s))||n;break}return getComputedStyle(n).direction=="rtl"?"rtl":"ltr"}function ud(i,e,t){let n=i.state.selection;if(n instanceof K&&!n.empty||t.indexOf("s")>-1||ht&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=n;if(!r.parent.inlineContent||i.endOfTextblock(e<0?"up":"down")){let o=Ch(i.state,e);if(o&&o instanceof V)return bn(i,o)}if(!r.parent.inlineContent){let o=e<0?r:s,l=n instanceof st?_.near(o,e):_.findFrom(o,e);return l?bn(i,l):!1}return!1}function dd(i,e){if(!(i.state.selection instanceof K))return!0;let{$head:t,$anchor:n,empty:r}=i.state.selection;if(!t.sameParent(n))return!0;if(!r)return!1;if(i.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=i.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),i.dispatch(o),!0}return!1}function pd(i,e,t){i.domObserver.stop(),e.contentEditable=t,i.domObserver.start()}function Fw(i){if(!Le||i.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=i.domSelectionRange();if(e&&B(e)&&t==0&&e.firstChild&&B(e.firstChild)&&e.firstChild.contentEditable=="false"){let n=e.firstChild;pd(i,n,"true"),setTimeout(()=>pd(i,n,"false"),20)}return!1}function Vw(i){let e="";return i.ctrlKey&&(e+="c"),i.metaKey&&(e+="m"),i.altKey&&(e+="a"),i.shiftKey&&(e+="s"),e}function zw(i,e){let t=e.keyCode,n=Vw(e);if(t==8||ht&&t==72&&n=="c")return dd(i,-1)||Di(i,-1);if(t==46&&!e.shiftKey||ht&&t==68&&n=="c")return dd(i,1)||Di(i,1);if(t==13||t==27)return!0;if(t==37||ht&&t==66&&n=="c"){let r=t==37?fd(i,i.state.selection.from)=="ltr"?-1:1:-1;return cd(i,r,n)||Di(i,r)}else if(t==39||ht&&t==70&&n=="c"){let r=t==39?fd(i,i.state.selection.from)=="ltr"?1:-1:1;return cd(i,r,n)||Di(i,r)}else{if(t==38||ht&&t==80&&n=="c")return ud(i,-1,n)||Di(i,-1);if(t==40||ht&&t==78&&n=="c")return Fw(i)||ud(i,1,n)||Di(i,1);if(n==(ht?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Vc(i,e){i.someProp("transformCopied",d=>{e=d(e,i)});let t=[],{content:n,openStart:r,openEnd:s}=e;for(;r>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){r--,s--;let d=n.firstChild;t.push(d.type.name,d.attrs!=d.type.defaultAttrs?d.attrs:null),n=d.content}let o=i.someProp("clipboardSerializer")||yr.fromSchema(i.state.schema),l=zg(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let h=a.firstChild,c,f=0;for(;h&&B(h)&&(c=Vg[h.nodeName.toLowerCase()]);){for(let d=c.length-1;d>=0;d--){let p=l.createElement(c[d]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),f++}h=a.firstChild}h&&B(h)&&h.setAttribute("data-pm-slice",`${r} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let u=i.someProp("clipboardTextSerializer",d=>d(e,i))||e.content.textBetween(0,e.content.size,`
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
`}return
|
|
19
|
-
|
|
20
|
-
`}const A1=/\r?\n|\r/g;function O1(i,e){const t=[];let n=0,r=0,s;for(;s=A1.exec(i);)o(i.slice(n,s.index)),t.push(s[0]),n=s.index+s[0].length,r++;return o(i.slice(n)),t.join("");function o(l){t.push(e(l,r,!l))}}const fa={}.hasOwnProperty;function T1(i,e,t){const n=(t.before||"")+(e||"")+(t.after||""),r=[],s=[],o={},l=i.stack.includes("autolink"),a=t.before?t.before.length:0,h=n.length-(t.after?t.after.length:0);let c=-1;for(;++c<i.unsafe.length;){const d=i.unsafe[c];if(!l1(i.stack,d)||!Lu(d.beforeNode,t.beforeNode)||!Lu(d.afterNode,t.afterNode))continue;const p=i.compilePattern(d),m=d.beforeNode?a:0,g=n.slice(m,d.afterNode?h:void 0);let y;for(;y=p.exec(g);){const b="before"in d||!!d.atBreak,k="after"in d,O=m+y.index+(b?y[1].length:0);fa.call(o,O)?(o[O].before&&!b&&(o[O].before=!1),o[O].after&&!k&&(o[O].after=!1)):(r.push(O),o[O]={before:b,after:k})}}r.sort(N1);let f=a;for(c=-1;++c<r.length;){const d=r[c];if(!(d<f||d>=h)){if(n.charAt(d)==="_"&&d>0&&ir(n.charCodeAt(d-1))===void 0&&!fa.call(o,d-1)&&!(d-1===a&&/[*_]/.test(n.charAt(a-1)))){let p=d+1;for(;p<h&&n.charAt(p)==="_";)p++;const m=p-d-1;if(r[c+m]===p-1&&p<n.length&&ir(n.charCodeAt(p))===void 0&&!fa.call(o,p)&&!(p===h-1&&/[*_]/.test(n.charAt(h)))){c+=m;continue}}if(!(d+1<h&&r[c+1]===d+1&&o[d].after&&!o[d+1].before&&!o[d+1].after||r[c-1]===d-1&&o[d].before&&!o[d-1].before&&!o[d-1].after)){if(f!==d){const p=n.slice(f,d);s.push(l?p:Fu(p,"\\"))}f=d,l?(s.push("%"+n.charCodeAt(d).toString(16).toUpperCase().padStart(2,"0")),f++):/[!-/:-@[-`{-~]/.test(n.charAt(d))&&(!t.encode||!t.encode.includes(n.charAt(d)))?s.push("\\"):(s.push(Nm(n.charCodeAt(d))),f++)}}}const u=n.slice(f,h);return s.push(l?u:Fu(u,t.after)),s.join("")}function Lu(i,e){return i?e?typeof i=="string"?i===e.type:i.includes(e.type):!1:!0}function N1(i,e){return i-e}function Fu(i,e){const t=/\\(?=[!-/:-@[-`{-~])/g,n=[],r=[],s=i+e;let o=-1,l=0,a;for(;a=t.exec(s);)n.push(a.index);for(;++o<n.length;)l!==n[o]&&r.push(i.slice(l,n[o])),r.push("\\"),l=n[o];return r.push(i.slice(l)),r.join("")}function D1(i){const e=i||{},t=e.now||{};let n=e.lineShift||0,r=t.line||1,s=t.column||1;return{move:a,current:o,shift:l};function o(){return{now:{line:r,column:s},lineShift:n}}function l(h){n+=h}function a(h){const c=h||"",f=c.split(/\r?\n|\r/g),u=f[f.length-1];return r+=f.length-1,s=f.length===1?s+u.length:1+u.length+n,c}}function I1(i,e){const t=e||{},n={associationId:g1,bulletCurrent:void 0,bulletLastUsed:void 0,containerPhrasing:P1,containerFlow:L1,createTracker:D1,compilePattern:y1,enter:s,handlers:{...h1},handle:void 0,indentLines:O1,indexStack:[],join:[...p1],options:{},safe:F1,stack:[],unsafe:[...Im]};Dm(n,t),n.options.tightDefinitions&&n.join.push(B1),n.handle=a1("type",{invalid:E1,unknown:R1,handlers:n.handlers});let r=n.handle(c1(i)?{type:"root",children:[i]}:i,void 0,n,{before:`
|
|
21
|
-
`,after:`
|
|
22
|
-
|
|
23
|
-
`),r;function s(o){return n.stack.push(o),l;function l(){n.stack.pop()}}}function E1(i){throw new Error("Cannot handle value `"+i+"`, expected node")}function R1(i){const e=i;throw new Error("Cannot handle unknown node `"+e.type+"`")}function B1(i,e){if(i.type==="definition"&&i.type===e.type)return 0}function P1(i,e){return x1(i,this,e)}function L1(i,e){return v1(i,this,e)}function F1(i,e){return T1(this,i,e)}function Se(i){this.content=i}Se.prototype={constructor:Se,find:function(i){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===i)return e;return-1},get:function(i){var e=this.find(i);return e==-1?void 0:this.content[e+1]},update:function(i,e,t){var n=t&&t!=i?this.remove(t):this,r=n.find(i),s=n.content.slice();return r==-1?s.push(t||i,e):(s[r+1]=e,t&&(s[r]=t)),new Se(s)},remove:function(i){var e=this.find(i);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Se(t)},addToStart:function(i,e){return new Se([i,e].concat(this.remove(i).content))},addToEnd:function(i,e){var t=this.remove(i).content.slice();return t.push(i,e),new Se(t)},addBefore:function(i,e,t){var n=this.remove(e),r=n.content.slice(),s=n.find(i);return r.splice(s==-1?r.length:s,0,e,t),new Se(r)},forEach:function(i){for(var e=0;e<this.content.length;e+=2)i(this.content[e],this.content[e+1])},prepend:function(i){return i=Se.from(i),i.size?new Se(i.content.concat(this.subtract(i).content)):this},append:function(i){return i=Se.from(i),i.size?new Se(this.subtract(i).content.concat(i.content)):this},subtract:function(i){var e=this;i=Se.from(i);for(var t=0;t<i.content.length;t+=2)e=e.remove(i.content[t]);return e},toObject:function(){var i={};return this.forEach(function(e,t){i[e]=t}),i},get size(){return this.content.length>>1}};Se.from=function(i){if(i instanceof Se)return i;var e=[];if(i)for(var t in i)e.push(t,i[t]);return new Se(e)};function Bm(i,e,t){for(let n=0;;n++){if(n==i.childCount||n==e.childCount)return i.childCount==e.childCount?null:t;let r=i.child(n),s=e.child(n);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){let o=r.text,l=s.text,a=0;for(;o[a]==l[a];a++)t++;return a&&a<o.length&&a<l.length&&Fm(o.charCodeAt(a-1))&&Lm(o.charCodeAt(a))&&t--,t}if(r.content.size||s.content.size){let o=Bm(r.content,s.content,t+1);if(o!=null)return o}t+=r.nodeSize}}function Pm(i,e,t,n){for(let r=i.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:n};let o=i.child(--r),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let h=o.text,c=l.text,f=h.length,u=c.length;for(;f>0&&u>0&&h[f-1]==c[u-1];)f--,u--,t--,n--;return f&&u&&f<h.length&&Fm(h.charCodeAt(f-1))&&Lm(h.charCodeAt(f))&&(t++,n++),{a:t,b:n}}if(o.content.size||l.content.size){let h=Pm(o.content,l.content,t-1,n-1);if(h)return h}t-=a,n-=a}}function Lm(i){return i>=56320&&i<57344}function Fm(i){return i>=55296&&i<56320}class A{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,r=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],h=l+a.nodeSize;if(h>e&&n(a,r+l,s||null,o)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),n,r+c)}l=h}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let h=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&h||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=h},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),s=1);s<e.content.length;s++)r.push(e.content[s]);return new A(r,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let n=[],r=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),r+=l.nodeSize),o=a}return new A(n,r)}cutByIndex(e,t){return e==t?A.empty:e==0&&t==this.content.length?this:new A(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new A(r,s)}addToStart(e){return new A([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new A(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return Bm(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Pm(this,e,t,n)}findIndex(e){if(e==0)return yo(0,e);if(e==this.size)return yo(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),s=n+r.nodeSize;if(s>=e)return s==e?yo(t+1,s):yo(t,n);n=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return A.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return A.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return A.empty;let t,n=0;for(let r=0;r<e.length;r++){let s=e[r];n+=s.nodeSize,r&&s.isText&&e[r-1].sameMarkup(s)?(t||(t=e.slice(0,r)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new A(t||e,n)}static from(e){if(!e)return A.empty;if(e instanceof A)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new A([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}A.empty=new A([],0);const ua={index:0,offset:0};function yo(i,e){return ua.index=i,ua.offset=e,ua}function ol(i,e){if(i===e)return!0;if(!(i&&typeof i=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(i);if(Array.isArray(e)!=t)return!1;if(t){if(i.length!=e.length)return!1;for(let n=0;n<i.length;n++)if(!ol(i[n],e[n]))return!1}else{for(let n in i)if(!(n in e)||!ol(i[n],e[n]))return!1;for(let n in e)if(!(n in i))return!1}return!0}class j{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&ol(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);return n.create(t.attrs)}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return j.none;if(e instanceof j)return[e];let t=e.slice();return t.sort((n,r)=>n.type.rank-r.type.rank),t}}j.none=[];class cs extends Error{}let E=class Ri{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Vm(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new Ri(n,this.openStart,this.openEnd)}removeBetween(e,t){return new Ri(zm(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return Ri.empty;let n=t.openStart||0,r=t.openEnd||0;if(typeof n!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Ri(A.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new Ri(e,n,r)}};E.empty=new E(A.empty,0,0);function zm(i,e,t){let{index:n,offset:r}=i.findIndex(e),s=i.maybeChild(n),{index:o,offset:l}=i.findIndex(t);if(r==e||s.isText){if(l!=t&&!i.child(o).isText)throw new RangeError("Removing non-flat range");return i.cut(0,e).append(i.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return i.replaceChild(n,s.copy(zm(s.content,e-r-1,t-r-1)))}function Vm(i,e,t,n,r,s){let{index:o,offset:l}=i.findIndex(e),a=i.maybeChild(o);if(l==e||a.isText)return s&&n<=0&&r<=0&&!s.canReplace(o,o,t)?null:i.cut(0,e).append(t).append(i.cut(e));let h=Vm(a.content,e-l-1,t,o==0?n-1:0,o==i.childCount-1?r-1:0,a);return h&&i.replaceChild(o,a.copy(h))}function z1(i,e,t){if(t.openStart>i.depth)throw new cs("Inserted content deeper than insertion position");if(i.depth-t.openStart!=e.depth-t.openEnd)throw new cs("Inconsistent open depths");return Hm(i,e,t,0)}function Hm(i,e,t,n){let r=i.index(n),s=i.node(n);if(r==e.index(n)&&n<i.depth-t.openStart){let o=Hm(i,e,t,n+1);return s.copy(s.content.replaceChild(r,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&i.depth==n&&e.depth==n){let o=i.parent,l=o.content;return oi(o,l.cut(0,i.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=V1(t,i);return oi(s,$m(i,o,l,e,n))}else return oi(s,ll(i,e,n))}function Wm(i,e){if(!e.type.compatibleContent(i.type))throw new cs("Cannot join "+e.type.name+" onto "+i.type.name)}function mh(i,e,t){let n=i.node(t);return Wm(n,e.node(t)),n}function si(i,e){let t=e.length-1;t>=0&&i.isText&&i.sameMarkup(e[t])?e[t]=i.withText(e[t].text+i.text):e.push(i)}function Jr(i,e,t,n){let r=(e||i).node(t),s=0,o=e?e.index(t):r.childCount;i&&(s=i.index(t),i.depth>t?s++:i.textOffset&&(si(i.nodeAfter,n),s++));for(let l=s;l<o;l++)si(r.child(l),n);e&&e.depth==t&&e.textOffset&&si(e.nodeBefore,n)}function oi(i,e){if(!i.type.validContent(e))throw new cs("Invalid content for node "+i.type.name);return i.copy(e)}function $m(i,e,t,n,r){let s=i.depth>r&&mh(i,e,r+1),o=n.depth>r&&mh(t,n,r+1),l=[];return Jr(null,i,r,l),s&&o&&e.index(r)==t.index(r)?(Wm(s,o),si(oi(s,$m(i,e,t,n,r+1)),l)):(s&&si(oi(s,ll(i,e,r+1)),l),Jr(e,t,r,l),o&&si(oi(o,ll(t,n,r+1)),l)),Jr(n,null,r,l),new A(l)}function ll(i,e,t){let n=[];if(Jr(null,i,t,n),i.depth>t){let r=mh(i,e,t+1);si(oi(r,ll(i,e,t+1)),n)}return Jr(e,null,t,n),new A(n)}function V1(i,e){let t=e.depth-i.openStart,r=e.node(t).copy(i.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(A.from(r));return{start:r.resolveNoCache(i.openStart+t),end:r.resolveNoCache(r.content.size-i.openEnd-t)}}class fs{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=n.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return j.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let l=n;n=r,r=l}let s=n.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!r||!s[o].isInSet(r.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<n.length;s++)n[s].type.spec.inclusive===!1&&(!r||!n[s].isInSet(r.marks))&&(n=n[s--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Km(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],r=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),h=s-a;if(n.push(o,l,r+a),!h||(o=o.child(l),o.isText))break;s=h-1,r+=a+1}return new fs(t,n,s)}static resolveCached(e,t){let n=zu.get(e);if(n)for(let s=0;s<n.elts.length;s++){let o=n.elts[s];if(o.pos==t)return o}else zu.set(e,n=new H1);let r=n.elts[n.i]=fs.resolve(e,t);return n.i=(n.i+1)%W1,r}}class H1{constructor(){this.elts=[],this.i=0}}const W1=12,zu=new WeakMap;class Km{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const $1=Object.create(null);class yt{constructor(e,t,n,r=j.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||A.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&ol(this.attrs,t||e.defaultAttrs||$1)&&j.sameSet(this.marks,n||j.none)}copy(e=null){return e==this.content?this:new yt(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new yt(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return E.empty;let r=this.resolve(e),s=this.resolve(t),o=n?0:r.sharedDepth(t),l=r.start(o),h=r.node(o).content.cut(r.pos-l,s.pos-l);return new E(h,r.depth-o,s.depth-o)}replace(e,t,n){return z1(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return fs.resolveCached(this,e)}resolveNoCache(e){return fs.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),qm(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=A.empty,r=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=r;a<s;a++)if(!this.type.allowsMarks(n.child(a).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(n),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),Vu(this.type.attrs,this.attrs,"node",this.type.name);let e=j.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];Vu(n.type.attrs,n.attrs,"mark",n.type.name),e=n.addToSet(e)}if(!j.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=A.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,r,n)}}yt.prototype.text=void 0;let K1=class gh extends yt{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):qm(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new gh(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new gh(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function qm(i,e){for(let t=i.length-1;t>=0;t--)e=i[t].type.name+"("+e+")";return e}function Vu(i,e,t,n){for(let r in e)if(!(r in i))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${n}`);for(let r in i)i[r].validate&&i[r].validate(e[r])}class gi{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new q1(e,t);if(n.next==null)return gi.empty;let r=jm(n);n.next&&n.err("Unexpected trailing text");let s=X1(Y1(r));return Q1(s,n),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let s=t;r&&s<n;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function s(o,l){let a=o.matchFragment(e,n);if(a&&(!t||a.validEnd))return A.from(l.map(h=>h.createAndFill()));for(let h=0;h<o.next.length;h++){let{type:c,next:f}=o.next[h];if(!(c.isText||c.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let u=s(f,l.concat(c));if(u)return u}}return null}return s(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),s=r.match;if(s.matchType(e)){let o=[];for(let l=r;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||a.validEnd)&&(n.push({match:l.contentMatch,type:l,via:r}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((n,r)=>{let s=r+(n.validEnd?"*":" ")+" ";for(let o=0;o<n.next.length;o++)s+=(o?", ":"")+n.next[o].type.name+"->"+e.indexOf(n.next[o].next);return s}).join(`
|
|
24
|
-
`)}}gi.empty=new gi(!0);class q1{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function jm(i){let e=[];do e.push(j1(i));while(i.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function j1(i){let e=[];do e.push(J1(i));while(i.next&&i.next!=")"&&i.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function J1(i){let e=G1(i);for(;;)if(i.eat("+"))e={type:"plus",expr:e};else if(i.eat("*"))e={type:"star",expr:e};else if(i.eat("?"))e={type:"opt",expr:e};else if(i.eat("{"))e=_1(i,e);else break;return e}function Hu(i){/\D/.test(i.next)&&i.err("Expected number, got '"+i.next+"'");let e=Number(i.next);return i.pos++,e}function _1(i,e){let t=Hu(i),n=t;return i.eat(",")&&(i.next!="}"?n=Hu(i):n=-1),i.eat("}")||i.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function U1(i,e){let t=i.nodeTypes,n=t[e];if(n)return[n];let r=[];for(let s in t){let o=t[s];o.isInGroup(e)&&r.push(o)}return r.length==0&&i.err("No node type or group '"+e+"' found"),r}function G1(i){if(i.eat("(")){let e=jm(i);return i.eat(")")||i.err("Missing closing paren"),e}else if(/\W/.test(i.next))i.err("Unexpected token '"+i.next+"'");else{let e=U1(i,i.next).map(t=>(i.inline==null?i.inline=t.isInline:i.inline!=t.isInline&&i.err("Mixing inline and block content"),{type:"name",value:t}));return i.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Y1(i){let e=[[]];return r(s(i,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let h={term:a,to:l};return e[o].push(h),h}function r(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,h)=>a.concat(s(h,l)),[]);if(o.type=="seq")for(let a=0;;a++){let h=s(o.exprs[a],l);if(a==o.exprs.length-1)return h;r(h,l=t())}else if(o.type=="star"){let a=t();return n(l,a),r(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return r(s(o.expr,l),a),r(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let h=0;h<o.min;h++){let c=t();r(s(o.expr,a),c),a=c}if(o.max==-1)r(s(o.expr,a),a);else for(let h=o.min;h<o.max;h++){let c=t();n(a,c),r(s(o.expr,a),c),a=c}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Jm(i,e){return e-i}function Wu(i,e){let t=[];return n(e),t.sort(Jm);function n(r){let s=i[r];if(s.length==1&&!s[0].term)return n(s[0].to);t.push(r);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&n(a)}}}function X1(i){let e=Object.create(null);return t(Wu(i,0));function t(n){let r=[];n.forEach(o=>{i[o].forEach(({term:l,to:a})=>{if(!l)return;let h;for(let c=0;c<r.length;c++)r[c][0]==l&&(h=r[c][1]);Wu(i,a).forEach(c=>{h||r.push([l,h=[]]),h.indexOf(c)==-1&&h.push(c)})})});let s=e[n.join(",")]=new gi(n.indexOf(i.length-1)>-1);for(let o=0;o<r.length;o++){let l=r[o][1].sort(Jm);s.next.push({type:r[o][0],next:e[l.join(",")]||t(l)})}return s}}function Q1(i,e){for(let t=0,n=[i];t<n.length;t++){let r=n[t],s=!r.validEnd,o=[];for(let l=0;l<r.next.length;l++){let{type:a,next:h}=r.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),n.indexOf(h)==-1&&n.push(h)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function _m(i){let e=Object.create(null);for(let t in i){let n=i[t];if(!n.hasDefault)return null;e[t]=n.default}return e}function Um(i,e){let t=Object.create(null);for(let n in i){let r=i[n],s=e&&e[n];if(s===void 0)if(r.hasDefault)s=r.default;else throw new RangeError("No value supplied for attribute "+n);else r.validate&&r.validate(s);t[n]=s}return t}function Gm(i,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new ex(i,n,e[n]);return t}let us=class Ym{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=Gm(e,n.attrs),this.defaultAttrs=_m(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==gi.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Um(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new yt(this,this.computeAttrs(e),A.from(t),j.setFrom(n))}createChecked(e=null,t,n){return t=A.from(t),this.checkContent(t),new yt(this,this.computeAttrs(e),t,j.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=A.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let r=this.contentMatch.matchFragment(t),s=r&&r.fillBefore(A.empty,!0);return s?new yt(this,e,t.append(s),j.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:j.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new Ym(s,t,o));let r=t.spec.topNode||"doc";if(!n[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function Z1(i,e,t){let n=t.split("|");return r=>{let s=r===null?"null":typeof r;if(n.indexOf(s)<0)throw new RangeError(`Expected value of type ${n} for attribute ${e} on type ${i}, got ${s}`)}}class ex{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Z1(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Pl{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=Gm(e,r.attrs),this.excluded=null;let s=_m(this.attrs);this.instance=s?new j(this,s):null}create(e=null){return!e&&this.instance?this.instance:new j(this,Um(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((s,o)=>n[s]=new Pl(s,r++,t,o)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}excludes(e){return this.excluded.indexOf(e)>-1}}class tx{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let r in e)t[r]=e[r];t.nodes=Se.from(e.nodes),t.marks=Se.from(e.marks||{}),this.nodes=us.compile(this.spec.nodes,this),this.marks=Pl.compile(this.spec.marks,this);let n=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let s=this.nodes[r],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=n[o]||(n[o]=gi.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?$u(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let r in this.marks){let s=this.marks[r],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:$u(this,o.split(" "))}this.nodeFromJSON=r=>yt.fromJSON(this,r),this.markFromJSON=r=>j.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof us){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new K1(n,n.defaultAttrs,e,j.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function $u(i,e){let t=[];for(let n=0;n<e.length;n++){let r=e[n],s=i.marks[r],o=s;if(s)t.push(s);else for(let l in i.marks){let a=i.marks[l];(r=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(r)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}function nx(i){return i.tag!=null}function ix(i){return i.style!=null}class rr{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(r=>{if(nx(r))this.tags.push(r);else if(ix(r)){let s=/[^=]*/.exec(r.style)[0];n.indexOf(s)<0&&n.push(s),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let s=e.nodes[r.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let n=new qu(this,t,!1);return n.addAll(e,j.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new qu(this,t,!0);return n.addAll(e,j.none,t.from,t.to),E.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(ox(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,n,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!n.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(r){let s=r.priority==null?50:r.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,r)}for(let r in e.marks){let s=e.marks[r].spec.parseDOM;s&&s.forEach(o=>{n(o=ju(o)),o.mark||o.ignore||o.clearMark||(o.mark=r)})}for(let r in e.nodes){let s=e.nodes[r].spec.parseDOM;s&&s.forEach(o=>{n(o=ju(o)),o.node||o.ignore||o.mark||(o.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new rr(e,rr.schemaRules(e)))}}const Xm={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},rx={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Qm={ol:!0,ul:!0},ds=1,yh=2,_r=4;function Ku(i,e,t){return e!=null?(e?ds:0)|(e==="full"?yh:0):i&&i.whitespace=="pre"?ds|yh:t&~_r}class bo{constructor(e,t,n,r,s,o){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=o,this.content=[],this.activeMarks=j.none,this.match=s||(o&_r?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(A.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,r;return(r=n.findWrapping(e.type))?(this.match=n,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&ds)){let n=this.content[this.content.length-1],r;if(n&&n.isText&&(r=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-r[0].length))}}let t=A.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(A.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Xm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}let qu=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,o=Ku(null,t.preserveWhitespace,0)|(n?_r:0);r?s=new bo(r.type,r.attrs,j.none,!0,t.topMatch||r.type.contentMatch,o):n?s=new bo(null,null,j.none,!0,null,o):s=new bo(e.schema.topNodeType,null,j.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,s=r.options&yh?"full":this.localPreserveWS||(r.options&ds)>0,{schema:o}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,`
|
|
25
|
-
`);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let l=r.content[r.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Qm.hasOwnProperty(o)&&this.parser.normalizeLists&&sx(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:rx.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let h,c=this.needsBlock;if(Xm.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),h=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let f=a&&a.skip?t:this.readStyles(e,t);f&&this.addAll(e,f),h&&this.sync(s),this.needsBlock=c}else{let h=this.readStyles(e,t);h&&this.addElementByRule(e,a,h,a.consuming===!1?l:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
26
|
-
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],o=n.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(h=>!a.clearMark(h)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,r){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,r){let s=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,n){let r,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],h=a.findWrapping(e);if(h&&(!r||r.length>h.length+l)&&(r=h,s=a,!h.length))break;if(a.solid){if(n)break;l+=2}}if(!r)return null;this.sync(s);for(let o=0;o<r.length;o++)t=this.enterInner(r[o],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=j.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Ju(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,n,r){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,r)),s}enterInner(e,t,n,r=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=Ku(e,s,o.options);o.options&_r&&o.content.length==0&&(l|=_r);let a=j.none;return n=n.filter(h=>(o.type?o.type.allowsMarkType(h.type):Ju(h.type,e))?(a=h.addToSet(a),!1):!0),this.nodes.push(new bo(e,t,a,r,null,l)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=ds)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let r=n.length-1;r>=0;r--)e+=n[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(r?0:1),o=(l,a)=>{for(;l>=0;l--){let h=t[l];if(h==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let c=a>0||a==0&&r?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!c||c.name!=h&&!c.isInGroup(h))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}};function sx(i){for(let e=i.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Qm.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function ox(i,e){return(i.matches||i.msMatchesSelector||i.webkitMatchesSelector||i.mozMatchesSelector).call(i,e)}function ju(i){let e={};for(let t in i)e[t]=i[t];return e}function Ju(i,e){let t=e.schema.nodes;for(let n in t){let r=t[n];if(!r.allowsMarkType(i))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:h,next:c}=l.edge(a);if(h==e||s.indexOf(c)<0&&o(c))return!0}};if(o(r.contentMatch))return!0}}class kr{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=ko(t).createDocumentFragment());let r=n,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let h=o.marks[a];if(!this.marks[h.type.name]){a++;continue}if(!h.eq(s[l][0])||h.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)r=s.pop()[1];for(;a<o.marks.length;){let h=o.marks[a++],c=this.serializeMark(h,o.isInline,t);c&&(s.push([h,r]),r.appendChild(c.dom),r=c.contentDOM||c.dom)}}r.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){if(e.isText)return ko(t).createTextNode(e.text);let{dom:n,contentDOM:r}=Wo(ko(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Wo(ko(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t=="string"?{dom:e.createTextNode(t)}:Wo(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new kr(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=_u(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return _u(e.marks)}}function _u(i){let e={};for(let t in i){let n=i[t].spec.toDOM;n&&(e[t]=n)}return e}function ko(i){return i.document||window.document}const Uu=new WeakMap;function lx(i){let e=Uu.get(i);return e===void 0&&Uu.set(i,e=ax(i)),e}function ax(i){let e=null;function t(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")e||(e=[]),e.push(n);else for(let r=0;r<n.length;r++)t(n[r]);else for(let r in n)t(n[r])}return t(i),e}function Wo(i,e,t,n){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(s=lx(n))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=r.indexOf(" ");o>0&&(t=r.slice(0,o),r=r.slice(o+1));let l,a=t?i.createElementNS(t,r):i.createElement(r),h=e[1],c=1;if(h&&typeof h=="object"&&h.nodeType==null&&!Array.isArray(h)){c=2;for(let f in h)if(h[f]!=null){let u=f.indexOf(" ");u>0?a.setAttributeNS(f.slice(0,u),f.slice(u+1),h[f]):f=="style"&&a.style?a.style.cssText=h[f]:a.setAttribute(f,h[f])}}for(let f=c;f<e.length;f++){let u=e[f];if(u===0){if(f<e.length-1||f>c)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else if(typeof u=="string")a.appendChild(i.createTextNode(u));else{let{dom:d,contentDOM:p}=Wo(i,u,t,n);if(a.appendChild(d),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Zm=65535,eg=Math.pow(2,16);function hx(i,e){return i+e*eg}function Gu(i){return i&Zm}function cx(i){return(i-(i&Zm))/eg}const tg=1,ng=2,$o=4,ig=8;class bh{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ig)>0}get deletedBefore(){return(this.delInfo&(tg|$o))>0}get deletedAfter(){return(this.delInfo&(ng|$o))>0}get deletedAcross(){return(this.delInfo&$o)>0}}class rt{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&rt.empty)return rt.empty}recover(e){let t=0,n=Gu(e);if(!this.inverted)for(let r=0;r<n;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[n*3]+t+cx(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let h=this.ranges[l+s],c=this.ranges[l+o],f=a+h;if(e<=f){let u=h?e==a?-1:e==f?1:t:t,d=a+r+(u<0?0:c);if(n)return d;let p=e==(t<0?a:f)?null:hx(l/3,e-a),m=0;return h&&(m|=e==a?ng:e==f?tg:$o,(t<0?e!=a:e!=f)&&(m|=ig)),new bh(d,m,p)}r+=c-h}return n?e+r:new bh(e+r,0,null)}touches(e,t){let n=0,r=Gu(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?n:0);if(a>e)break;let h=this.ranges[l+s],c=a+h;if(e<=c&&l==r*3)return!0;n+=this.ranges[l+o]-h}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let o=this.ranges[r],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),h=this.ranges[r+t],c=this.ranges[r+n];e(l,l+h,a,a+c),s+=c-h}}invert(){return new rt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?rt.empty:new rt(e<0?[0,-e,0]:[0,0,e])}}rt.empty=new rt([]);class al{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new al(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let e=new al;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return n?e:new bh(e,r,null)}}const da=Object.create(null);class ye{getMap(){return rt.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=da[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in da)throw new RangeError("Duplicate use of step JSON ID "+e);return da[e]=t,t.prototype.jsonID=e,t}}class fe{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new fe(e,null)}static fail(e){return new fe(null,e)}static fromReplace(e,t,n,r){try{return fe.ok(e.replace(t,n,r))}catch(s){if(s instanceof cs)return fe.fail(s.message);throw s}}}function Bc(i,e,t){let n=[];for(let r=0;r<i.childCount;r++){let s=i.child(r);s.content.size&&(s=s.copy(Bc(s.content,e,s))),s.isInline&&(s=e(s,t,r)),n.push(s)}return A.fromArray(n)}class zt extends ye{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),s=new E(Bc(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),r),t.openStart,t.openEnd);return fe.fromReplace(e,this.from,this.to,s)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,r)=>{if(n.isInline&&n.isAtom){let s=this.mark.addToSet(n.marks);if(!j.sameSet(s,n.marks)){let o=Math.max(this.from,r),l=Math.min(this.to,r+n.nodeSize);hl(tn,o,l,this.mark,t);for(let a of n.marks)a.isInSet(s)||hl(zt,o,l,a,t)}}}),t.length==1?t[0]:new li(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new zt(t,n,this.mark)}merge(e){return e instanceof zt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new zt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new zt(t.from,t.to,e.markFromJSON(t.mark))}}ye.jsonID("addMark",zt);class tn extends ye{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new E(Bc(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return fe.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,r)=>{n.isInline&&n.isAtom&&this.mark.isInSet(n.marks)&&hl(zt,Math.max(this.from,r),Math.min(this.to,r+n.nodeSize),this.mark,t)}),t.length==1?t[0]:new li(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new tn(t,n,this.mark)}merge(e){return e instanceof tn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new tn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new tn(t.from,t.to,e.markFromJSON(t.mark))}}ye.jsonID("removeMark",tn);function hl(i,e,t,n,r){let s=r.length?r[r.length-1]:null;s&&s instanceof i&&s.to==e&&s.mark.eq(n)?r[r.length-1]=new i(s.from,t,n):r.push(new i(e,t,n))}class li extends ye{constructor(e){super(),this.steps=e}apply(e){for(let t of this.steps){let n=t.apply(e);if(!n.doc)return n;e=n.doc}return new fe(e,null)}invert(e){return new li(this.steps.map(t=>t.invert(e)))}map(e){let t=[];for(let n of this.steps){let r=n.map(e);r&&t.push(r)}return t.length?new li(t):null}toJSON(){return{stepType:"markSet",steps:this.steps.map(e=>e.toJSON())}}static fromJSON(e,t){if(!Array.isArray(t.steps)||!t.steps.every(n=>n.stepType=="addMark"||n.stepType=="removeMark"))throw new RangeError("Invalid JSON for MarkSetStep");return new li(t.steps.map(n=>ye.fromJSON(e,n)))}}ye.jsonID("markSet",li);class On extends ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return fe.fromReplace(e,this.pos,this.pos+1,new E(A.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(n))return new On(this.pos,t.marks[r]);return new On(this.pos,this.mark)}}return new yi(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new On(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new On(t.pos,e.markFromJSON(t.mark))}}ye.jsonID("addNodeMark",On);class yi extends ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return fe.fromReplace(e,this.pos,this.pos+1,new E(A.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new On(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new yi(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new yi(t.pos,e.markFromJSON(t.mark))}}ye.jsonID("removeNodeMark",yi);class ue extends ye{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&kh(e,this.from,this.to)?fe.fail("Structure replace would overwrite content"):fe.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new rt([this.from,this.to-this.from,this.slice.size])}invert(e){return new ue(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&ue.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new ue(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof ue)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?E.empty:new E(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new ue(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?E.empty:new E(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new ue(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new ue(t.from,t.to,E.fromJSON(e,t.slice),!!t.structure)}}ue.MAP_BIAS=1;ye.jsonID("replace",ue);class Be extends ye{constructor(e,t,n,r,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(kh(e,this.from,this.gapFrom)||kh(e,this.gapTo,this.to)))return fe.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return fe.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?fe.fromReplace(e,this.from,this.to,n):fe.fail("Content does not fit in gap")}getMap(){return new rt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Be(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||s>n.pos?null:new Be(t.pos,n.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Be(t.from,t.to,t.gapFrom,t.gapTo,E.fromJSON(e,t.slice),t.insert,!!t.structure)}}ye.jsonID("replaceAround",Be);function kh(i,e,t){let n=i.resolve(e),r=t-e,s=n.depth;for(;r>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,r--;if(r>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;r>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,r--}}return!1}function fx(i,e,t,n){let r=[];i.doc.nodesBetween(e,t,(s,o,l)=>{if(!s.isInline)return;let a=s.marks;if(!n.isInSet(a)&&l.type.allowsMarkType(n.type)){let h=Math.max(o,e),c=Math.min(o+s.nodeSize,t);hl(zt,h,c,n,r)}}),r.forEach(s=>i.step(s))}function ux(i,e,t,n){let r=[],s=0;i.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline||!o.isAtom)return;s++;let a=null;if(n instanceof Pl){let h=o.marks,c;for(;c=n.isInSet(h);)(a||(a=[])).push(c),h=c.removeFromSet(h)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let h=Math.min(l+o.nodeSize,t);for(let c=0;c<a.length;c++){let f=a[c],u;for(let d=0;d<r.length;d++){let p=r[d];p.step==s-1&&f.eq(r[d].style)&&(u=p)}u?(u.to=h,u.step=s):r.push({style:f,from:Math.max(l,e),to:h,step:s})}}}),r.forEach(o=>i.step(new tn(o.from,o.to,o.style)))}function Pc(i,e,t,n=t.contentMatch,r=!0){let s=i.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let h=s.child(a),c=l+h.nodeSize,f=n.matchType(h.type);if(!f)o.push(new ue(l,c,E.empty));else{n=f;for(let u=0;u<h.marks.length;u++)t.allowsMarkType(h.marks[u].type)||i.step(new tn(l,c,h.marks[u]));if(r&&h.isText&&t.whitespace!="pre"){let u,d=/\r?\n|\r/g,p;for(;u=d.exec(h.text);)p||(p=new E(A.from(t.schema.text(" ",t.allowedMarks(h.marks))),0,0)),o.push(new ue(l+u.index,l+u.index+u[0].length,p))}}l=c}if(!n.validEnd){let a=n.fillBefore(A.empty,!0);i.replace(l,l,new E(a,0,0))}for(let a=o.length-1;a>=0;a--)i.step(o[a])}function dx(i,e,t){return(e==0||i.canReplace(e,i.childCount))&&(t==i.childCount||i.canReplace(0,t))}function Ll(i){let t=i.parent.content.cutByIndex(i.startIndex,i.endIndex);for(let n=i.depth,r=0,s=0;;--n){let o=i.$from.node(n),l=i.$from.index(n)+r,a=i.$to.indexAfter(n)-s;if(n<i.depth&&o.canReplace(l,a,t))return n;if(n==0||o.type.spec.isolating||!dx(o,l,a))break;l&&(r=1),a<o.childCount&&(s=1)}return null}function px(i,e,t){let{$from:n,$to:r,depth:s}=e,o=n.before(s+1),l=r.after(s+1),a=o,h=l,c=A.empty,f=0;for(let p=s,m=!1;p>t;p--)m||n.index(p)>0?(m=!0,c=A.from(n.node(p).copy(c)),f++):a--;let u=A.empty,d=0;for(let p=s,m=!1;p>t;p--)m||r.after(p+1)<r.end(p)?(m=!0,u=A.from(r.node(p).copy(u)),d++):h++;i.step(new Be(a,h,o,l,new E(c.append(u),f,d),c.size-f,!0))}function Lc(i,e,t=null,n=i){let r=mx(i,e),s=r&&gx(n,e);return s?r.map(Yu).concat({type:e,attrs:t}).concat(s.map(Yu)):null}function Yu(i){return{type:i,attrs:null}}function mx(i,e){let{parent:t,startIndex:n,endIndex:r}=i,s=t.contentMatchAt(n).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(n,r,o)?s:null}function gx(i,e){let{parent:t,startIndex:n,endIndex:r}=i,s=t.child(n),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let h=n;a&&h<r;h++)a=a.matchType(t.child(h).type);return!a||!a.validEnd?null:o}function yx(i,e,t){let n=A.empty;for(let o=t.length-1;o>=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=A.from(t[o].type.create(t[o].attrs,n))}let r=e.start,s=e.end;i.step(new Be(r,s,r,s,new E(n,0,0),t.length,!0))}function bx(i,e,t,n,r){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=i.steps.length;i.doc.nodesBetween(e,t,(o,l)=>{let a=typeof r=="function"?r(o):r;if(o.isTextblock&&!o.hasMarkup(n,a)&&kx(i.doc,i.mapping.slice(s).map(l),n)){let h=null;if(n.schema.linebreakReplacement){let d=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);d&&!p?h=!1:!d&&p&&(h=!0)}h===!1&&sg(i,o,l,s),Pc(i,i.mapping.slice(s).map(l,1),n,void 0,h===null);let c=i.mapping.slice(s),f=c.map(l,1),u=c.map(l+o.nodeSize,1);return i.step(new Be(f,u,f+1,u-1,new E(A.from(n.create(a,null,o.marks)),0,0),1,!0)),h===!0&&rg(i,o,l,s),!1}})}function rg(i,e,t,n){e.forEach((r,s)=>{if(r.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(r.text);){let a=i.mapping.slice(n).map(t+1+s+o.index);i.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function sg(i,e,t,n){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let o=i.mapping.slice(n).map(t+1+s);i.replaceWith(o,o+1,e.type.schema.text(`
|
|
27
|
-
`))}})}function kx(i,e,t){let n=i.resolve(e),r=n.index();return n.parent.canReplaceWith(r,r+1,t)}function xx(i,e,t,n,r){let s=i.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,r||s.marks);if(s.isLeaf)return i.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);i.step(new Be(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new E(A.from(o),0,0),1,!0))}function Ur(i,e,t=1,n){let r=i.resolve(e),s=r.depth-t,o=n&&n[n.length-1]||r.parent;if(s<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!o.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let h=r.depth-1,c=t-2;h>s;h--,c--){let f=r.node(h),u=r.index(h);if(f.type.spec.isolating)return!1;let d=f.content.cutByIndex(u,f.childCount),p=n&&n[c+1];p&&(d=d.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[c]||f;if(!f.canReplace(u+1,f.childCount)||!m.type.validContent(d))return!1}let l=r.indexAfter(s),a=n&&n[0];return r.node(s).canReplaceWith(l,l,a?a.type:r.node(s+1).type)}function wx(i,e,t=1,n){let r=i.doc.resolve(e),s=A.empty,o=A.empty;for(let l=r.depth,a=r.depth-t,h=t-1;l>a;l--,h--){s=A.from(r.node(l).copy(s));let c=n&&n[h];o=A.from(c?c.type.create(c.attrs,o):r.node(l).copy(o))}i.step(new ue(e,e,new E(s.append(o),t,t),!0))}function Fl(i,e){let t=i.resolve(e),n=t.index();return Cx(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function Sx(i,e){e.content.size||i.type.compatibleContent(e.type);let t=i.contentMatchAt(i.childCount),{linebreakReplacement:n}=i.type.schema;for(let r=0;r<e.childCount;r++){let s=e.child(r),o=s.type==n?i.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!i.type.allowsMarks(s.marks))return!1}return t.validEnd}function Cx(i,e){return!!(i&&e&&!i.isLeaf&&Sx(i,e))}function vx(i,e,t){let n=null,{linebreakReplacement:r}=i.doc.type.schema,s=i.doc.resolve(e-t),o=s.node().type;if(r&&o.inlineContent){let c=o.whitespace=="pre",f=!!o.contentMatch.matchType(r);c&&!f?n=!1:!c&&f&&(n=!0)}let l=i.steps.length;if(n===!1){let c=i.doc.resolve(e+t);sg(i,c.node(),c.before(),l)}o.inlineContent&&Pc(i,e+t-1,o,s.node().contentMatchAt(s.index()),n==null);let a=i.mapping.slice(l),h=a.map(e-t);if(i.step(new ue(h,a.map(e+t,-1),E.empty,!0)),n===!0){let c=i.doc.resolve(h);rg(i,c.node(),c.before(),i.steps.length)}return i}function Mx(i,e,t){let n=i.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let r=n.depth-1;r>=0;r--){let s=n.index(r);if(n.node(r).canReplaceWith(s,s,t))return n.before(r+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let r=n.depth-1;r>=0;r--){let s=n.indexAfter(r);if(n.node(r).canReplaceWith(s,s,t))return n.after(r+1);if(s<n.node(r).childCount)return null}return null}function Ax(i,e,t){let n=i.resolve(e);if(!t.content.size)return e;let r=t.content;for(let s=0;s<t.openStart;s++)r=r.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=n.depth;o>=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),h=n.node(o),c=!1;if(s==1)c=h.canReplace(a,a,r);else{let f=h.contentMatchAt(a).findWrapping(r.firstChild.type);c=f&&h.canReplaceWith(a,a,f[0])}if(c)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function zl(i,e,t=e,n=E.empty){if(e==t&&!n.size)return null;let r=i.resolve(e),s=i.resolve(t);return og(r,s,n)?new ue(e,t,n):new Ox(r,s,n).fit()}function og(i,e,t){return!t.openStart&&!t.openEnd&&i.start()==e.start()&&i.parent.canReplace(i.index(),e.index(),t.content)}class Ox{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=A.empty;for(let r=0;r<=e.depth;r++){let s=e.node(r);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=A.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let h=this.findFittable();h?this.placeNodes(h):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let s=this.placed,o=n.depth,l=r.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new E(s,o,l);return e>-1?new Be(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new ue(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let s=t.firstChild;if(t.childCount>1&&(r=0),s.type.spec.isolating&&r<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let r,s=null;n?(s=Xu(this.unplaced.content,n-1).firstChild,r=s.content):r=this.unplaced.content;let o=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:h}=this.frontier[l],c,f=null;if(t==1&&(o?h.matchType(o.type)||(f=h.fillBefore(A.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(c=h.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:c};if(s&&h.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return Qu(e,-1)<=t?!1:(this.unplaced.size>1&&Qu(e,1)>n&&n++,this.unplaced=new E(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Xu(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new E(Lr(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new E(Lr(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=n?n.content:o.content,a=o.openStart-e,h=0,c=[],{match:f,type:u}=this.frontier[t];if(r){for(let m=0;m<r.childCount;m++)c.push(r.child(m));f=f.matchFragment(r)}let d=l.size+e-(o.content.size-o.openEnd);for(;h<l.childCount;){let m=l.child(h),g=f.matchType(m.type);if(!g)break;h++,(h>1||a==0||m.content.size)&&(f=g,c.push(lg(m.mark(u.allowedMarks(m.marks)),h==1?a:0,h==l.childCount?d:-1)))}let p=h==l.childCount;p||(d=-1),this.placed=Fr(this.placed,t,A.from(c)),this.frontier[t].match=f,p&&d<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<d;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=p?e==0?E.empty:new E(Lr(o.content,e-1,1),e-1,d<0?o.openEnd:e-1):new E(Lr(o.content,e,h),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!pa(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=pa(e,t,r,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:h}=this.frontier[l],c=pa(e,l,h,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Fr(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let r=e.node(n),s=r.type.contentMatch.fillBefore(r.content,!0,e.index(n));this.openFrontierNode(r.type,r.attrs,s)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Fr(this.placed,this.depth,A.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(A.empty,!0);t.childCount&&(this.placed=Fr(this.placed,this.frontier.length,t))}}function Lr(i,e,t){return e==0?i.cutByIndex(t,i.childCount):i.replaceChild(0,i.firstChild.copy(Lr(i.firstChild.content,e-1,t)))}function Fr(i,e,t){return e==0?i.append(t):i.replaceChild(i.childCount-1,i.lastChild.copy(Fr(i.lastChild.content,e-1,t)))}function Xu(i,e){for(let t=0;t<e;t++)i=i.firstChild.content;return i}function lg(i,e,t){if(e<=0)return i;let n=i.content;return e>1&&(n=n.replaceChild(0,lg(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=i.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(i.type.contentMatch.matchFragment(n).fillBefore(A.empty,!0)))),i.copy(n)}function pa(i,e,t,n,r){let s=i.node(e),o=r?i.indexAfter(e):i.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!Tx(t,s.content,o)?l:null}function Tx(i,e,t){for(let n=t;n<e.childCount;n++)if(!i.allowsMarks(e.child(n).marks))return!0;return!1}function Nx(i){return i.spec.defining||i.spec.definingForContent}function Qu(i,e){for(let t=0;;t++){let n=e<0?i.firstChild:i.lastChild;if(!n||n.isAtom)return t;i=n.content}}function Dx(i,e,t,n){if(!n.size)return i.deleteRange(e,t);let r=i.doc.resolve(e),s=i.doc.resolve(t);if(og(r,s,n))return i.step(new ue(e,t,n));let o=hg(r,s);o[o.length-1]==0&&o.pop();let l=-(r.depth+1);o.unshift(l);for(let u=r.depth,d=r.pos-1;u>0;u--,d--){let p=r.node(u).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(u)>-1?l=u:r.before(u)==d&&o.splice(1,0,-u)}let a=o.indexOf(l),h=[],c=n.openStart;for(let u=n.content,d=0;;d++){let p=u.firstChild;if(h.push(p),d==n.openStart)break;u=p.content}for(let u=c-1;u>=0;u--){let d=h[u],p=Nx(d.type);if(p&&!d.sameMarkup(r.node(Math.abs(l)-1)))c=u;else if(p||!d.type.isTextblock)break}for(let u=n.openStart;u>=0;u--){let d=(u+c+1)%(n.openStart+1),p=h[d];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let b=r.node(g-1),k=r.index(g-1);if(b.canReplaceWith(k,k,p.type,p.marks))return i.replace(r.before(g),y?s.after(g):t,new E(ag(n.content,0,n.openStart,d),d,n.openEnd))}}let f=i.steps.length;for(let u=o.length-1;u>=0&&(i.replace(e,t,n),!(i.steps.length>f));u--){let d=o[u];d<0||(e=r.before(d),t=s.after(d))}}function ag(i,e,t,n,r){if(e<t){let s=i.firstChild;i=i.replaceChild(0,s.copy(ag(s.content,e+1,t,n,s)))}if(e>n){let s=r.contentMatchAt(0),o=s.fillBefore(i).append(i);i=o.append(s.matchFragment(o).fillBefore(A.empty,!0))}return i}function Ix(i,e,t,n){if(!n.isInline&&e==t&&i.doc.resolve(e).parent.content.size){let r=Mx(i.doc,e,n.type);r!=null&&(e=t=r)}i.replaceRange(e,t,new E(A.from(n),0,0))}function Ex(i,e,t){let n=i.doc.resolve(e),r=i.doc.resolve(t);if(n.parent.isTextblock&&r.parent.isTextblock&&n.start()!=r.start()&&n.parentOffset==0&&r.parentOffset==0){let o=n.sharedDepth(t),l=!1;for(let a=n.depth;a>o;a--)n.node(a).type.spec.isolating&&(l=!0);for(let a=r.depth;a>o;a--)r.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=n.depth;a>0&&e==n.start(a);a--)e=n.before(a);for(let a=r.depth;a>0&&t==r.start(a);a--)t=r.before(a);n=i.doc.resolve(e),r=i.doc.resolve(t)}}let s=hg(n,r);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||n.node(l).type.contentMatch.validEnd)return i.delete(n.start(l),r.end(l));if(l>0&&(a||n.node(l-1).canReplace(n.index(l-1),r.indexAfter(l-1))))return i.delete(n.before(l),r.after(l))}for(let o=1;o<=n.depth&&o<=r.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&r.end(o)-t!=r.depth-o&&n.start(o-1)==r.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),r.index(o-1)))return i.delete(n.before(o),t);i.delete(e,t)}function hg(i,e){let t=[],n=Math.min(i.depth,e.depth);for(let r=n;r>=0;r--){let s=i.start(r);if(s<i.pos-(i.depth-r)||e.end(r)>e.pos+(e.depth-r)||i.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==i.depth&&r==e.depth&&i.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&t.push(r)}return t}class Wi extends ye{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return fe.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return fe.fromReplace(e,this.pos,this.pos+1,new E(A.from(r),0,t.isLeaf?0:1))}getMap(){return rt.empty}invert(e){return new Wi(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Wi(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Wi(t.pos,t.attr,t.value)}}ye.jsonID("attr",Wi);class ps extends ye{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return fe.ok(n)}getMap(){return rt.empty}invert(e){return new ps(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new ps(t.attr,t.value)}}ye.jsonID("docAttr",ps);let sr=class extends Error{};sr=function i(e){let t=Error.call(this,e);return t.__proto__=i.prototype,t};sr.prototype=Object.create(Error.prototype);sr.prototype.constructor=sr;sr.prototype.name="TransformError";class Rx{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new al}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new sr(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((s,o,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=E.empty){let r=zl(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new E(A.from(n),0,0))}delete(e,t){return this.replace(e,t,E.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return Dx(this,e,t,n),this}replaceRangeWith(e,t,n){return Ix(this,e,t,n),this}deleteRange(e,t){return Ex(this,e,t),this}lift(e,t){return px(this,e,t),this}join(e,t=1){return vx(this,e,t),this}wrap(e,t){return yx(this,e,t),this}setBlockType(e,t=e,n,r=null){return bx(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return xx(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new Wi(e,t,n)),this}setDocAttribute(e,t){return this.step(new ps(e,t)),this}addNodeMark(e,t){return this.step(new On(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof j)t.isInSet(n.marks)&&this.step(new yi(e,t));else{let r=n.marks,s,o=[];for(;s=t.isInSet(r);)o.push(new yi(e,s)),r=s.removeFromSet(r);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return wx(this,e,t,n),this}addMark(e,t,n){return fx(this,e,t,n),this}removeMark(e,t,n){return ux(this,e,t,n),this}clearIncompatible(e,t,n){return Pc(this,e,t,n),this}}const ma=Object.create(null);class _{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Bx(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=E.empty){let n=t.content.lastChild,r=null;for(let l=0;l<t.openEnd;l++)r=n,n=n.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:h}=o[l],c=e.mapping.slice(s);e.replaceRange(c.map(a.pos),c.map(h.pos),l?E.empty:t),l==0&&td(e,s,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:o,$to:l}=r[s],a=e.mapping.slice(n),h=a.map(o.pos),c=a.map(l.pos);s?e.deleteRange(h,c):(e.replaceRangeWith(h,c,t),td(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new K(e):Bi(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let s=e.depth-1;s>=0;s--){let o=t<0?Bi(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Bi(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new st(e.node(0))}static atStart(e){return Bi(e,e,0,0,1)||new st(e)}static atEnd(e){return Bi(e,e,e.content.size,e.childCount,-1)||new st(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=ma[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in ma)throw new RangeError("Duplicate use of selection JSON ID "+e);return ma[e]=t,t.prototype.jsonID=e,t}getBookmark(){return K.between(this.$anchor,this.$head).getBookmark()}}_.prototype.visible=!0;let Bx=class{constructor(e,t){this.$from=e,this.$to=t}},Zu=!1;function ed(i){!Zu&&!i.parent.inlineContent&&(Zu=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+i.parent.type.name+")"))}class K extends _{constructor(e,t=e){ed(e),ed(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return _.near(n);let r=e.resolve(t.map(this.anchor));return new K(r.parent.inlineContent?r:n,n)}replace(e,t=E.empty){if(super.replace(e,t),t==E.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof K&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Vl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new K(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let s=_.findFrom(t,n,!0)||_.findFrom(t,-n,!0);if(s)t=s.$head;else return _.near(t,n)}return e.parent.inlineContent||(r==0?e=t:(e=(_.findFrom(e,-n,!0)||_.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new K(e,t)}}_.jsonID("text",K);class Vl{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Vl(e.map(this.anchor),e.map(this.head))}resolve(e){return K.between(e.resolve(this.anchor),e.resolve(this.head))}}class z extends _{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),s=e.resolve(r);return n?_.near(s):new z(s)}content(){return new E(A.from(this.node),0,0)}eq(e){return e instanceof z&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Fc(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new z(e.resolve(t.anchor))}static create(e,t){return new z(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}z.prototype.visible=!1;_.jsonID("node",z);class Fc{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Vl(n,n):new Fc(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&z.isSelectable(n)?new z(t):_.near(t)}}class st extends _{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=E.empty){if(t==E.empty){e.delete(0,e.doc.content.size);let n=_.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new st(e)}map(e){return new st(e)}eq(e){return e instanceof st}getBookmark(){return Px}}_.jsonID("all",st);const Px={map(){return this},resolve(i){return new st(i)}};function Bi(i,e,t,n,r,s=!1){if(e.inlineContent)return K.create(i,t);for(let o=n-(r>0?0:1);r>0?o<e.childCount:o>=0;o+=r){let l=e.child(o);if(l.isAtom){if(!s&&z.isSelectable(l))return z.create(i,t-(r<0?l.nodeSize:0))}else{let a=Bi(i,l,t+r,r<0?l.childCount:0,r,s);if(a)return a}t+=l.nodeSize*r}return null}function td(i,e,t){let n=i.steps.length-1;if(n<e)return;let r=i.steps[n];if(!(r instanceof ue||r instanceof Be))return;let s=i.mapping.maps[n],o;s.forEach((l,a,h,c)=>{o==null&&(o=c)}),i.setSelection(_.near(i.doc.resolve(o),t))}const nd=1,xo=2,id=4;let Lx=class extends Rx{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|nd)&~xo,this.storedMarks=null,this}get selectionSet(){return(this.updated&nd)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=xo,this}ensureMarks(e){return j.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&xo)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~xo,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||j.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(_.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=id,this}get scrolledIntoView(){return(this.updated&id)>0}};function rd(i,e){return!e||!i?i:i.bind(e)}class zr{constructor(e,t,n){this.name=e,this.init=rd(t.init,n),this.apply=rd(t.apply,n)}}const Fx=[new zr("doc",{init(i){return i.doc||i.schema.topNodeType.createAndFill()},apply(i){return i.doc}}),new zr("selection",{init(i,e){return i.selection||_.atStart(e.doc)},apply(i){return i.selection}}),new zr("storedMarks",{init(i){return i.storedMarks||null},apply(i,e,t,n){return n.selection.$cursor?i.storedMarks:null}}),new zr("scrollToSelection",{init(){return 0},apply(i,e){return i.scrolledIntoView?e+1:e}})];let ga=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Fx.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new zr(n.key,n.spec.state,n))})}},cg=class Vr{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let r=this.config.plugins[n];if(r.spec.filterTransaction&&!r.spec.filterTransaction.call(r,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=r?r[o].n:0,h=r?r[o].state:this,c=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,h,n);if(c&&n.filterTransaction(c,o)){if(c.setMeta("appendedTransaction",e),!r){r=[];for(let f=0;f<this.config.plugins.length;f++)r.push(f<o?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),s=!0}r&&(r[o]={state:n,n:t.length})}}if(!s)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Vr(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let s=n[r];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new Lx(this)}static create(e){let t=new ga(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Vr(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new ga(this.schema,e.plugins),n=t.fields,r=new Vr(t);for(let s=0;s<n.length;s++){let o=n[s].name;r[o]=this.hasOwnProperty(o)?this[o]:n[s].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(n=>n.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],s=r.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new ga(e.schema,e.plugins),s=new Vr(r);return r.fields.forEach(o=>{if(o.name=="doc")s.doc=yt.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=_.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],h=a.spec.state;if(a.key==o.name&&h&&h.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=h.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function fg(i,e,t){for(let n in i){let r=i[n];r instanceof Function?r=r.bind(e):n=="handleDOMEvents"&&(r=fg(r,e,{})),t[n]=r}return t}class un{constructor(e){this.spec=e,this.props={},e.props&&fg(e.props,this,this.props),this.key=e.key?e.key.key:ug("plugin")}getState(e){return e[this.key]}}const ya=Object.create(null);function ug(i){return i in ya?i+"$"+ ++ya[i]:(ya[i]=0,i+"$")}class Kn{constructor(e="key"){this.key=ug(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}var _e=(function(i){return i.docTypeError="docTypeError",i.contextNotFound="contextNotFound",i.timerNotFound="timerNotFound",i.ctxCallOutOfScope="ctxCallOutOfScope",i.createNodeInParserFail="createNodeInParserFail",i.stackOverFlow="stackOverFlow",i.parserMatchError="parserMatchError",i.serializerMatchError="serializerMatchError",i.getAtomFromSchemaFail="getAtomFromSchemaFail",i.expectDomTypeError="expectDomTypeError",i.callCommandBeforeEditorView="callCommandBeforeEditorView",i.missingRootElement="missingRootElement",i.missingNodeInSchema="missingNodeInSchema",i.missingMarkInSchema="missingMarkInSchema",i.ctxNotBind="ctxNotBind",i.missingYjsDoc="missingYjsDoc",i.aiProviderError="aiProviderError",i.aiBuildContextError="aiBuildContextError",i})({}),Ue=class extends Error{constructor(i,e,t){super(e,t),this.name="MilkdownError",this.code=i,t?.cause!==void 0&&(this.cause=t.cause)}},zx=(i,e)=>typeof e=="function"?"[Function]":e,Gs=i=>JSON.stringify(i,zx);function Vx(i){return new Ue(_e.docTypeError,`Doc type error, unsupported type: ${Gs(i)}`)}function Hx(i){return new Ue(_e.contextNotFound,`Context "${i}" not found, do you forget to inject it?`)}function Wx(i){return new Ue(_e.timerNotFound,`Timer "${i}" not found, do you forget to record it?`)}function Hl(){return new Ue(_e.ctxCallOutOfScope,"Should not call a context out of the plugin.")}function $x(i,e,t){const n=`Cannot create node for ${"name"in i?i.name:i}`,r=o=>{if(o==null)return"null";if(Array.isArray(o))return`[${o.map(r).join(", ")}]`;if(typeof o=="object")return"toJSON"in o&&typeof o.toJSON=="function"?JSON.stringify(o.toJSON()):"spec"in o?JSON.stringify(o.spec):JSON.stringify(o);if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return JSON.stringify(o);if(typeof o=="function")return`[Function: ${o.name||"anonymous"}]`;try{return String(o)}catch{return"[Unserializable]"}},s=[["[Description]",n],["[Attributes]",e],["[Content]",(t??[]).map(o=>o?typeof o=="object"&&"type"in o?`${o}`:r(o):"null")]].reduce((o,[l,a])=>{const h=`${l}: ${r(a)}.`;return o.concat(h)},[]);return new Ue(_e.createNodeInParserFail,s.join(`
|
|
28
|
-
`))}function dg(){return new Ue(_e.stackOverFlow,"Stack over flow, cannot pop on an empty stack.")}function Kx(i){return new Ue(_e.parserMatchError,`Cannot match target parser for node: ${Gs(i)}.`)}function qx(i){return new Ue(_e.serializerMatchError,`Cannot match target serializer for node: ${Gs(i)}.`)}function jx(i,e){return new Ue(_e.getAtomFromSchemaFail,`Cannot get ${i}: ${e} from schema.`)}function vi(i){return new Ue(_e.expectDomTypeError,`Expect to be a dom, but get: ${Gs(i)}.`)}function ba(){return new Ue(_e.callCommandBeforeEditorView,"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized")}function Jx(i){return new Ue(_e.missingNodeInSchema,`Missing node in schema, milkdown cannot find "${i}" in schema.`)}function _x(i){return new Ue(_e.missingMarkInSchema,`Missing mark in schema, milkdown cannot find "${i}" in schema.`)}function pg(i){try{return Gs(i)}catch{return"[Unserializable]"}}function ZD(i){const e=i instanceof Error?i.message:pg(i);return new Ue(_e.aiProviderError,`AI provider error: ${e}`,{cause:i})}function eI(i){const e=i instanceof Error?i.message:pg(i);return new Ue(_e.aiBuildContextError,`AI buildContext failed: ${e}`,{cause:i})}var mg=class{constructor(){this.sliceMap=new Map,this.get=i=>{const e=typeof i=="string"?[...this.sliceMap.values()].find(t=>t.type.name===i):this.sliceMap.get(i.id);if(!e){const t=typeof i=="string"?i:i.name;throw Hx(t)}return e},this.remove=i=>{const e=typeof i=="string"?[...this.sliceMap.values()].find(t=>t.type.name===i):this.sliceMap.get(i.id);e&&this.sliceMap.delete(e.type.id)},this.has=i=>typeof i=="string"?[...this.sliceMap.values()].some(e=>e.type.name===i):this.sliceMap.has(i.id)}},Ux=class{#t;#e;#i;constructor(i,e,t){this.#t=[],this.#i=()=>{this.#t.forEach(n=>n(this.#e))},this.set=n=>{this.#e=n,this.#i()},this.get=()=>this.#e,this.update=n=>{this.#e=n(this.#e),this.#i()},this.type=t,this.#e=e,i.set(t.id,this)}on(i){return this.#t.push(i),()=>{this.#t=this.#t.filter(e=>e!==i)}}once(i){const e=this.on(t=>{i(t),e()});return e}off(i){this.#t=this.#t.filter(e=>e!==i)}offAll(){this.#t=[]}},Gx=class{constructor(i,e){this.id=Symbol(`Context-${e}`),this.name=e,this._defaultValue=i,this._typeInfo=()=>{throw Hl()}}create(i,e=this._defaultValue){return new Ux(i,e,this)}},q=(i,e)=>new Gx(i,e),Yx=class{#t;#e;#i;#n;#s;#o;#r;constructor(i,e,t){this.#n=new Set,this.#s=new Set,this.#o=new Map,this.#r=new Map,this.read=()=>({metadata:this.#t,injectedSlices:[...this.#n].map(n=>({name:typeof n=="string"?n:n.name,value:this.#l(n)})),consumedSlices:[...this.#s].map(n=>({name:typeof n=="string"?n:n.name,value:this.#l(n)})),recordedTimers:[...this.#o].map(([n,{duration:r}])=>({name:n.name,duration:r,status:this.#a(n)})),waitTimers:[...this.#r].map(([n,{duration:r}])=>({name:n.name,duration:r,status:this.#a(n)}))}),this.onRecord=n=>{this.#o.set(n,{start:Date.now(),duration:0})},this.onClear=n=>{this.#o.delete(n)},this.onDone=n=>{const r=this.#o.get(n);r&&(r.duration=Date.now()-r.start)},this.onWait=(n,r)=>{const s=Date.now();r.finally(()=>{this.#r.set(n,{duration:Date.now()-s})}).catch(console.error)},this.onInject=n=>{this.#n.add(n)},this.onRemove=n=>{this.#n.delete(n)},this.onUse=n=>{this.#s.add(n)},this.#l=n=>this.#e.get(n).get(),this.#a=n=>this.#i.get(n).status,this.#e=i,this.#i=e,this.#t=t}#l;#a},Xx=class gg{#t;#e;#i;#n;constructor(e,t,n){this.produce=r=>r&&Object.keys(r).length?new gg(this.#t,this.#e,{...r}):this,this.inject=(r,s)=>{const o=r.create(this.#t.sliceMap);return s!=null&&o.set(s),this.#n?.onInject(r),this},this.remove=r=>(this.#t.remove(r),this.#n?.onRemove(r),this),this.record=r=>(r.create(this.#e.store),this.#n?.onRecord(r),this),this.clearTimer=r=>(this.#e.remove(r),this.#n?.onClear(r),this),this.isInjected=r=>this.#t.has(r),this.isRecorded=r=>this.#e.has(r),this.use=r=>(this.#n?.onUse(r),this.#t.get(r)),this.get=r=>this.use(r).get(),this.set=(r,s)=>this.use(r).set(s),this.update=(r,s)=>this.use(r).update(s),this.timer=r=>this.#e.get(r),this.done=r=>{this.timer(r).done(),this.#n?.onDone(r)},this.wait=r=>{const s=this.timer(r).start();return this.#n?.onWait(r,s),s},this.waitTimers=async r=>{await Promise.all(this.get(r).map(s=>this.wait(s)))},this.#t=e,this.#e=t,this.#i=n,n&&(this.#n=new Yx(e,t,n))}get meta(){return this.#i}get inspector(){return this.#n}},Qx=class{constructor(){this.store=new Map,this.get=i=>{const e=this.store.get(i.id);if(!e)throw Wx(i.name);return e},this.remove=i=>{this.store.delete(i.id)},this.has=i=>this.store.has(i.id)}},Zx=class{#t;#e;#i;#n;#s;constructor(i,e){this.#t=null,this.#e=null,this.#n="pending",this.#s=null,this.start=()=>(this.#t??=new Promise((t,n)=>{this.#e=r=>{r instanceof CustomEvent&&r.detail.id===this.#i&&(this.#n="resolved",this.#o(),r.stopImmediatePropagation(),t())},this.#r(()=>{this.#n==="pending"&&(this.#n="rejected"),this.#o(),n(new Error(`Timing ${this.type.name} timeout.`))}),this.#n="pending",addEventListener(this.type.name,this.#e)}),this.#t),this.done=()=>{const t=new CustomEvent(this.type.name,{detail:{id:this.#i}});dispatchEvent(t)},this.#o=()=>{this.#s!==null&&(clearTimeout(this.#s),this.#s=null),this.#e&&removeEventListener(this.type.name,this.#e)},this.#r=t=>{this.#s=setTimeout(()=>{this.#s=null,t()},this.type.timeout)},this.#i=Symbol(e.name),this.type=e,i.set(e.id,this)}get status(){return this.#n}#o;#r},ew=class{constructor(i,e=3e3){this.create=t=>new Zx(t,this),this.id=Symbol(`Timer-${i}`),this.name=i,this.timeout=e}},Ut=(i,e=3e3)=>new ew(i,e);function xh(i){const e=this;e.compiler=t;function t(n){return I1(n,{...e.data("settings"),...i,extensions:e.data("toMarkdownExtensions")||[]})}}const zc=(i,e)=>i.selection.empty?!1:(e&&e(i.tr.deleteSelection().scrollIntoView()),!0);function yg(i,e){let{$cursor:t}=i.selection;return!t||(e?!e.endOfTextblock("backward",i):t.parentOffset>0)?null:t}const bg=(i,e,t)=>{let n=yg(i,t);if(!n)return!1;let r=Vc(n);if(!r){let o=n.blockRange(),l=o&&Ll(o);return l==null?!1:(e&&e(i.tr.lift(o,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(wg(i,r,e,-1))return!0;if(n.parent.content.size==0&&(or(s,"end")||z.isSelectable(s)))for(let o=n.depth;;o--){let l=zl(i.doc,n.before(o),n.after(o),E.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=i.tr.step(l);a.setSelection(or(s,"end")?_.findFrom(a.doc.resolve(a.mapping.map(r.pos,-1)),-1):z.create(a.doc,r.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||n.node(o-1).childCount>1)break}return s.isAtom&&r.depth==n.depth-1?(e&&e(i.tr.delete(r.pos-s.nodeSize,r.pos).scrollIntoView()),!0):!1},tw=(i,e,t)=>{let n=yg(i,t);if(!n)return!1;let r=Vc(n);return r?nw(i,r,e):!1};function nw(i,e,t){let n=e.nodeBefore,r=n,s=e.pos-1;for(;!r.isTextblock;s--){if(r.type.spec.isolating)return!1;let c=r.lastChild;if(!c)return!1;r=c}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let c=l.firstChild;if(!c)return!1;l=c}let h=zl(i.doc,s,a,E.empty);if(!h||h.from!=s||h instanceof ue&&h.slice.size>=a-s)return!1;if(t){let c=i.tr.step(h);c.setSelection(K.create(c.doc,s)),t(c.scrollIntoView())}return!0}function or(i,e,t=!1){for(let n=i;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(t&&n.childCount!=1)return!1}return!1}const kg=(i,e,t)=>{let{$head:n,empty:r}=i.selection,s=n;if(!r)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",i):n.parentOffset>0)return!1;s=Vc(n)}let o=s&&s.nodeBefore;return!o||!z.isSelectable(o)?!1:(e&&e(i.tr.setSelection(z.create(i.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Vc(i){if(!i.parent.type.spec.isolating)for(let e=i.depth-1;e>=0;e--){if(i.index(e)>0)return i.doc.resolve(i.before(e+1));if(i.node(e).type.spec.isolating)break}return null}function iw(i,e){let{$cursor:t}=i.selection;return!t||(e?!e.endOfTextblock("forward",i):t.parentOffset<t.parent.content.size)?null:t}const rw=(i,e,t)=>{let n=iw(i,t);if(!n)return!1;let r=xg(n);if(!r)return!1;let s=r.nodeAfter;if(wg(i,r,e,1))return!0;if(n.parent.content.size==0&&(or(s,"start")||z.isSelectable(s))){let o=zl(i.doc,n.before(),n.after(),E.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=i.tr.step(o);l.setSelection(or(s,"start")?_.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):z.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&r.depth==n.depth-1?(e&&e(i.tr.delete(r.pos,r.pos+s.nodeSize).scrollIntoView()),!0):!1},sw=(i,e,t)=>{let{$head:n,empty:r}=i.selection,s=n;if(!r)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",i):n.parentOffset<n.parent.content.size)return!1;s=xg(n)}let o=s&&s.nodeAfter;return!o||!z.isSelectable(o)?!1:(e&&e(i.tr.setSelection(z.create(i.doc,s.pos)).scrollIntoView()),!0)};function xg(i){if(!i.parent.type.spec.isolating)for(let e=i.depth-1;e>=0;e--){let t=i.node(e);if(i.index(e)+1<t.childCount)return i.doc.resolve(i.after(e+1));if(t.type.spec.isolating)break}return null}const ow=(i,e)=>{let{$head:t,$anchor:n}=i.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(i.tr.insertText(`
|
|
29
|
-
`).scrollIntoView()),!0)};function Hc(i){for(let e=0;e<i.edgeCount;e++){let{type:t}=i.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const lw=(i,e)=>{let{$head:t,$anchor:n}=i.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let r=t.node(-1),s=t.indexAfter(-1),o=Hc(r.contentMatchAt(s));if(!o||!r.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=i.tr.replaceWith(l,l,o.createAndFill());a.setSelection(_.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},aw=(i,e)=>{let t=i.selection,{$from:n,$to:r}=t;if(t instanceof st||n.parent.inlineContent||r.parent.inlineContent)return!1;let s=Hc(r.parent.contentMatchAt(r.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&r.index()<r.parent.childCount?n:r).pos,l=i.tr.insert(o,s.createAndFill());l.setSelection(K.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},hw=(i,e)=>{let{$cursor:t}=i.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Ur(i.doc,s))return e&&e(i.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),r=n&&Ll(n);return r==null?!1:(e&&e(i.tr.lift(n,r).scrollIntoView()),!0)};function cw(i){return(e,t)=>{if(e.selection instanceof z&&e.selection.node.isBlock){let{$from:d}=e.selection;return!d.parentOffset||!Ur(e.doc,d.pos)?!1:(t&&t(e.tr.split(d.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let n=e.tr;!e.selection.empty&&(e.selection instanceof K||e.selection instanceof st)&&n.deleteSelection();let{$from:r}=n.selection,s=n.steps.length,o=[],l,a,h=!1,c=!1;for(let d=r.depth;;d--)if(r.node(d).isBlock){h=r.end(d)==r.pos+(r.depth-d),c=r.start(d)==r.pos-(r.depth-d),a=Hc(r.node(d-1).contentMatchAt(r.indexAfter(d-1))),o.unshift(h&&a?{type:a}:null),l=d;break}else{if(d==1)return!1;o.unshift(null)}let f=r.pos,u=Ur(n.doc,f,o.length,o);if(u||(o[0]=a?{type:a}:null,u=Ur(n.doc,f,o.length,o)),!u)return!1;if(n.split(f,o.length,o),!h&&c&&r.node(l).type!=a){let d=n.mapping.slice(s),p=d.map(r.before(l)),m=n.doc.resolve(p);a&&r.node(l-1).canReplaceWith(m.index(),m.index()+1,a)&&n.setNodeMarkup(d.map(r.before(l)),a)}return t&&t(n.scrollIntoView()),!0}}const fw=cw(),uw=(i,e)=>(e&&e(i.tr.setSelection(new st(i.doc))),!0);function dw(i,e,t){let n=e.nodeBefore,r=e.nodeAfter,s=e.index();return!n||!r||!n.type.compatibleContent(r.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(i.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(r.isTextblock||Fl(i.doc,e.pos))?!1:(t&&t(i.tr.join(e.pos).scrollIntoView()),!0)}function wg(i,e,t,n){let r=e.nodeBefore,s=e.nodeAfter,o,l,a=r.type.spec.isolating||s.type.spec.isolating;if(!a&&dw(i,e,t))return!0;let h=!a&&e.parent.canReplace(e.index(),e.index()+1);if(h&&(o=(l=r.contentMatchAt(r.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let d=e.pos+s.nodeSize,p=A.empty;for(let y=o.length-1;y>=0;y--)p=A.from(o[y].create(null,p));p=A.from(r.copy(p));let m=i.tr.step(new Be(e.pos-1,d,e.pos,d,new E(p,1,0),o.length,!0)),g=m.doc.resolve(d+2*o.length);g.nodeAfter&&g.nodeAfter.type==r.type&&Fl(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let c=s.type.spec.isolating||n>0&&a?null:_.findFrom(e,1),f=c&&c.$from.blockRange(c.$to),u=f&&Ll(f);if(u!=null&&u>=e.depth)return t&&t(i.tr.lift(f,u).scrollIntoView()),!0;if(h&&or(s,"start",!0)&&or(r,"end")){let d=r,p=[];for(;p.push(d),!d.isTextblock;)d=d.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(d.canReplace(d.childCount,d.childCount,m.content)){if(t){let y=A.empty;for(let k=p.length-1;k>=0;k--)y=A.from(p[k].copy(y));let b=i.tr.step(new Be(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new E(y,p.length,0),0,!0));t(b.scrollIntoView())}return!0}}return!1}function Sg(i){return function(e,t){let n=e.selection,r=i<0?n.$from:n.$to,s=r.depth;for(;r.node(s).isInline;){if(!s)return!1;s--}return r.node(s).isTextblock?(t&&t(e.tr.setSelection(K.create(e.doc,i<0?r.start(s):r.end(s)))),!0):!1}}const pw=Sg(-1),mw=Sg(1);function Wc(i,e=null){return function(t,n){let{$from:r,$to:s}=t.selection,o=r.blockRange(s),l=o&&Lc(o,i,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function ms(i,e=null){return function(t,n){let r=!1;for(let s=0;s<t.selection.ranges.length&&!r;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,h)=>{if(r)return!1;if(!(!a.isTextblock||a.hasMarkup(i,e)))if(a.type==i)r=!0;else{let c=t.doc.resolve(h),f=c.index();r=c.parent.canReplaceWith(f,f+1,i)}})}if(!r)return!1;if(n){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[o];s.setBlockType(l,a,i,e)}n(s.scrollIntoView())}return!0}}function gw(i,e,t,n){for(let r=0;r<e.length;r++){let{$from:s,$to:o}=e[r],l=s.depth==0?i.inlineContent&&i.type.allowsMarkType(t):!1;if(i.nodesBetween(s.pos,o.pos,(a,h)=>{if(l)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function $c(i,e=null,t){return function(n,r){let{empty:s,$cursor:o,ranges:l}=n.selection;if(s&&!o||!gw(n.doc,l,i))return!1;if(r)if(o)i.isInSet(n.storedMarks||o.marks())?r(n.tr.removeStoredMark(i)):r(n.tr.addStoredMark(i.create(e)));else{let a,h=n.tr;a=!l.some(c=>n.doc.rangeHasMark(c.$from.pos,c.$to.pos,i));for(let c=0;c<l.length;c++){let{$from:f,$to:u}=l[c];if(!a)h.removeMark(f.pos,u.pos,i);else{let d=f.pos,p=u.pos,m=f.nodeAfter,g=u.nodeBefore,y=m&&m.isText?/^\s*/.exec(m.text)[0].length:0,b=g&&g.isText?/\s*$/.exec(g.text)[0].length:0;d+y<p&&(d+=y,p-=b),h.addMark(d,p,i.create(e))}}r(h.scrollIntoView())}return!0}}function xr(...i){return function(e,t,n){for(let r=0;r<i.length;r++)if(i[r](e,t,n))return!0;return!1}}let ka=xr(zc,bg,kg),sd=xr(zc,rw,sw);const Qt={Enter:xr(ow,aw,hw,fw),"Mod-Enter":lw,Backspace:ka,"Mod-Backspace":ka,"Shift-Backspace":ka,Delete:sd,"Mod-Delete":sd,"Mod-a":uw},Cg={"Ctrl-h":Qt.Backspace,"Alt-Backspace":Qt["Mod-Backspace"],"Ctrl-d":Qt.Delete,"Ctrl-Alt-Backspace":Qt["Mod-Delete"],"Alt-Delete":Qt["Mod-Delete"],"Alt-d":Qt["Mod-Delete"],"Ctrl-a":pw,"Ctrl-e":mw};for(let i in Qt)Cg[i]=Qt[i];const yw=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,bw=yw?Cg:Qt;class kt{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t=="string"?kw(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1,this.inCodeMark=n.inCodeMark!==!1}}function kw(i){return function(e,t,n,r){let s=i;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),n+=o;let l=n-r;l>0&&(s=t[0].slice(o-l,o)+s,n=r)}return e.tr.insertText(s,n,r)}}const xw=(i,e)=>{let t=i.plugins;for(let n=0;n<t.length;n++){let r=t[n],s;if(r.spec.isInputRules&&(s=r.getState(i))){if(e){let o=i.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,i.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1};new kt(/--$/,"—",{inCodeMark:!1});new kt(/\.\.\.$/,"…",{inCodeMark:!1});new kt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1});new kt(/"$/,"”",{inCodeMark:!1});new kt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1});new kt(/'$/,"’",{inCodeMark:!1});function Kc(i,e,t=null,n){return new kt(i,(r,s,o,l)=>{let a=t instanceof Function?t(s):t,h=r.tr.delete(o,l),c=h.doc.resolve(o),f=c.blockRange(),u=f&&Lc(f,e,a);if(!u)return null;h.wrap(f,u);let d=h.doc.resolve(o-1).nodeBefore;return d&&d.type==e&&Fl(h.doc,o-1)&&(!n||n(s,d))&&h.join(o-1),h})}function vg(i,e,t=null){return new kt(i,(n,r,s,o)=>{let l=n.doc.resolve(s),a=t instanceof Function?t(r):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?n.tr.delete(s,o).setBlockType(s,s,e,a):null})}const Pn=typeof navigator<"u"?navigator:null,od=typeof document<"u"?document:null,qn=Pn&&Pn.userAgent||"",wh=/Edge\/(\d+)/.exec(qn),Mg=/MSIE \d/.exec(qn),Sh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(qn),Wl=!!(Mg||Sh||wh),ww=Mg?document.documentMode:Sh?+Sh[1]:wh?+wh[1]:0,Ag=!Wl&&/gecko\/(\d+)/i.test(qn),Sw=Ag&&+(/Firefox\/(\d+)/.exec(qn)||[0,0])[1],Ch=!Wl&&/Chrome\/(\d+)/.exec(qn),Og=!!Ch,Cw=Ch?+Ch[1]:0,Tg=!Wl&&!!Pn&&/Apple Computer/.test(Pn.vendor),Ng=Tg&&(/Mobile\/\w+/.test(qn)||!!Pn&&Pn.maxTouchPoints>2),vw=Ng||(Pn?/Mac/.test(Pn.platform):!1),Dg=/Android \d/.test(qn),Ig=!!od&&"webkitFontSmoothing"in od.documentElement.style,Mw=Ig?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;var tI=Object.freeze({__proto__:null,android:Dg,chrome:Og,chrome_version:Cw,gecko:Ag,gecko_version:Sw,ie:Wl,ie_version:ww,ios:Ng,mac:vw,safari:Tg,webkit:Ig,webkit_version:Mw});function xa(i,e,t,n,r,s){if(i.composing)return!1;const o=i.state,l=o.doc.resolve(e);if(l.parent.type.spec.code)return!1;const a=l.parent.textBetween(Math.max(0,l.parentOffset-500),l.parentOffset,void 0,"")+n;for(let h of r){const c=h,f=c.match.exec(a),u=f&&f[0]&&c.handler(o,f,e-(f[0].length-n.length),t);if(u)return c.undoable!==!1&&u.setMeta(s,{transform:u,from:e,to:t,text:n}),i.dispatch(u),!0}return!1}const Aw=new Kn("MILKDOWN_CUSTOM_INPUTRULES");function Ow({rules:i}){const e=new un({key:Aw,isInputRules:!0,state:{init(){return null},apply(t,n){const r=t.getMeta(this);return r||(t.selectionSet||t.docChanged?null:n)}},props:{handleTextInput(t,n,r,s){return xa(t,n,r,s,i,e)},handleDOMEvents:{compositionend:t=>(setTimeout(()=>{const{$cursor:n}=t.state.selection;n&&xa(t,n.pos,n.pos,"",i,e)}),!1),keydown:(t,n)=>!(Dg&&Og&&n.key==="Enter")||t.composing?!1:t.someProp("handleKeyDown",r=>r(t,n))?(n.preventDefault(),!0):!1},handleKeyDown(t,n){if(n.key!=="Enter")return!1;const{$cursor:r}=t.state.selection;return r?xa(t,r.pos,r.pos,`
|
|
30
|
-
`,i,e):!1}}});return e}function Eg(i){return i.some(e=>e.type.spec.code)}function ld(i,e,t){if(e>=t)return!1;let n=!1;return i.doc.nodesBetween(e,t,r=>(r.isInline&&Eg(r.marks)&&(n=!0),!n)),n}function Tw(i,e){var t;return Eg((t=i.storedMarks)!=null?t:i.doc.resolve(e).marks())}function $l(i,e,t={}){return new kt(i,(n,r,s,o)=>{var l,a,h,c;const{tr:f}=n,u=r.length;let d=r[u-1],p=r[0],m=[],g;const y={group:d,fullMatch:p,start:s,end:o},b=(l=t.updateCaptured)==null?void 0:l.call(t,y);if(Object.assign(y,b),{group:d,fullMatch:p,start:s,end:o}=y,p===null||d?.trim()==="")return null;if(d){const k=p.search(/\S/),O=s+p.indexOf(d),w=O+d.length,M=ld(n,s+k,O),C=w<o&&ld(n,w,o);if(M||C||Tw(n,o))return null;m=(a=f.storedMarks)!=null?a:[],w<o&&f.delete(w,o),O>s&&f.delete(s+k,O),g=s+k+d.length;const I=(h=t.getAttr)==null?void 0:h.call(t,r);f.addMark(s,g,e.create(I)),f.setStoredMarks(m),(c=t.beforeDispatch)==null||c.call(t,{match:r,start:s,end:o,tr:f})}return f})}function nI(i,e,t={}){return new kt(i,(n,r,s,o)=>{var l,a,h;const{tr:c}=n;let f=r[1],u=r[0];const d={group:f,fullMatch:u,start:s,end:o},p=(l=t.updateCaptured)==null?void 0:l.call(t,d);if(Object.assign(d,p),{group:f,fullMatch:u,start:s,end:o}=d,u===null||!f||f.trim()==="")return null;const m=(a=t.getAttr)==null?void 0:a.call(t,r),g=e.createAndFill(m);return g&&(c.replaceRangeWith(e.isBlock?c.doc.resolve(s).before():s,o,g),(h=t.beforeDispatch)==null||h.call(t,{match:[u,f],start:s,end:o,tr:c})),c})}var Nw=Object.defineProperty,Dw=Object.defineProperties,Iw=Object.getOwnPropertyDescriptors,ad=Object.getOwnPropertySymbols,Ew=Object.prototype.hasOwnProperty,Rw=Object.prototype.propertyIsEnumerable,hd=(i,e,t)=>e in i?Nw(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,Bw=(i,e)=>{for(var t in e||(e={}))Ew.call(e,t)&&hd(i,t,e[t]);if(ad)for(var t of ad(e))Rw.call(e,t)&&hd(i,t,e[t]);return i},Pw=(i,e)=>Dw(i,Iw(e));function cd(i=0,e=0,t=0){return Math.min(Math.max(i,e),t)}function iI(i,e,t){const r=i.state.doc.content.size,s=cd(e,0,r),o=cd(t,0,r),l=i.coordsAtPos(s),a=i.coordsAtPos(o,-1),h=Math.min(l.top,a.top),c=Math.max(l.bottom,a.bottom),f=Math.min(l.left,a.left),u=Math.max(l.right,a.right),d=u-f,p=c-h,y={top:h,bottom:c,left:f,right:u,width:d,height:p,x:f,y:h};return Pw(Bw({},y),{toJSON:()=>y})}function rI(i){return Object.assign(Object.create(i),i).setTime(Date.now())}function Lw(i,e){return Array.isArray(i)&&i.includes(e.type)||e.type===i}function sI(i){if(i.content.childCount===1){const e=i.content.firstChild;if(e?.type.name==="text"&&e.marks.length===0)return e;if(e?.type.name==="paragraph"&&e.childCount===1){const t=e.firstChild;if(t?.type.name==="text"&&t.marks.length===0)return t}}return!1}function Fw(i){return e=>{for(let t=e.depth;t>0;t-=1){const n=e.node(t);if(i(n)){const r=e.before(t),s=e.after(t);return{from:r,to:s,node:n}}}}}function oI(i,e){return Fw(t=>t.type===e)(i)}function lI(i,e){const t=e.nodes[i];if(!t)throw jx("node",i);return t}function zw(i){return e=>{for(let t=e.depth;t>0;t--){const n=e.node(t);if(i(n))return{pos:e.before(t),start:e.start(t),depth:t,node:n}}}}function aI(i){return e=>zw(i)(e.$from)}function Vw(i,e){if(!(i instanceof z))return;const{node:t,$from:n}=i;if(Lw(e,t))return{node:t,pos:n.pos,start:n.start(n.depth),depth:n.depth}}const Hw=(i,e)=>{const{selection:t,doc:n}=i;if(t instanceof z)return{hasNode:t.node.type===e,pos:t.from,target:t.node};const{from:r,to:s}=t;let o=!1,l=-1,a=null;return n.nodesBetween(r,s,(h,c)=>a?!1:h.type===e?(o=!0,l=c,a=h,!1):!0),{hasNode:o,pos:l,target:a}};var hn={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:"'"},gs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Ww=typeof navigator<"u"&&/Mac/.test(navigator.platform),$w=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ve=0;ve<10;ve++)hn[48+ve]=hn[96+ve]=String(ve);for(var ve=1;ve<=24;ve++)hn[ve+111]="F"+ve;for(var ve=65;ve<=90;ve++)hn[ve]=String.fromCharCode(ve+32),gs[ve]=String.fromCharCode(ve);for(var wa in hn)gs.hasOwnProperty(wa)||(gs[wa]=hn[wa]);function Rg(i){var e=Ww&&i.metaKey&&i.shiftKey&&!i.ctrlKey&&!i.altKey||$w&&i.shiftKey&&i.key&&i.key.length==1||i.key=="Unidentified",t=!e&&i.key||(i.shiftKey?gs:hn)[i.keyCode]||i.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}const Kw=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),qw=typeof navigator<"u"&&/Win/.test(navigator.platform);function jw(i){let e=i.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,r,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))n=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Kw?o=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return n&&(t="Alt-"+t),r&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Jw(i){let e=Object.create(null);for(let t in i)e[jw(t)]=i[t];return e}function Sa(i,e,t=!0){return e.altKey&&(i="Alt-"+i),e.ctrlKey&&(i="Ctrl-"+i),e.metaKey&&(i="Meta-"+i),t&&e.shiftKey&&(i="Shift-"+i),i}function _w(i){return new un({props:{handleKeyDown:Uw(i)}})}function Uw(i){let e=Jw(i);return function(t,n){let r=Rg(n),s,o=e[Sa(r,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(n.shiftKey){let l=e[Sa(r,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(qw&&n.ctrlKey&&n.altKey)&&(s=hn[n.keyCode])&&s!=r){let l=e[Sa(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var Bg=class{},Pg=class{constructor(){this.elements=[],this.size=()=>this.elements.length,this.top=()=>this.elements.at(-1),this.push=i=>{this.top()?.push(i)},this.open=i=>{this.elements.push(i)},this.close=()=>{const i=this.elements.pop();if(!i)throw dg();return i}}},Gw=class Lg extends Bg{constructor(e,t,n){super(),this.type=e,this.content=t,this.attrs=n}push(e,...t){this.content.push(e,...t)}pop(){return this.content.pop()}static create(e,t,n){return new Lg(e,t,n)}},St,Yi,zs,Vs,Hs,Xi,Qi,di,Yw=(di=class extends Pg{constructor(t){super();ae(this,St);ae(this,Yi);ae(this,zs);ae(this,Vs);ae(this,Hs);ae(this,Xi);ae(this,Qi);re(this,St,j.none),re(this,Yi,n=>n.isText),re(this,zs,(n,r)=>{if(F(this,Yi).call(this,n)&&F(this,Yi).call(this,r)&&j.sameSet(n.marks,r.marks))return this.schema.text(n.text+r.text,n.marks)}),re(this,Vs,n=>{const r=Object.values({...this.schema.nodes,...this.schema.marks}).find(s=>s.spec.parseMarkdown.match(n));if(!r)throw Kx(n);return r}),re(this,Hs,n=>{const r=F(this,Vs).call(this,n);r.spec.parseMarkdown.runner(this,n,r)}),this.injectRoot=(n,r,s)=>(this.openNode(r,s),this.next(n.children),this),this.openNode=(n,r)=>(this.open(Gw.create(n,[],r)),this),re(this,Xi,()=>{re(this,St,j.none);const n=this.close();return F(this,Qi).call(this,n.type,n.attrs,n.content)}),this.closeNode=()=>{try{F(this,Xi).call(this)}catch(n){console.error(n)}return this},re(this,Qi,(n,r,s)=>{const o=n.createAndFill(r,s,F(this,St));if(!o)throw $x(n,r,s);return this.push(o),o}),this.addNode=(n,r,s)=>{try{F(this,Qi).call(this,n,r,s)}catch(o){console.error(o)}return this},this.openMark=(n,r)=>{const s=n.create(r);return re(this,St,s.addToSet(F(this,St))),this},this.closeMark=n=>(re(this,St,n.removeFromSet(F(this,St))),this),this.addText=n=>{try{const r=this.top();if(!r)throw dg();const s=r.pop(),o=this.schema.text(n,F(this,St));if(!s)return r.push(o),this;const l=F(this,zs).call(this,s,o);return l?(r.push(l),this):(r.push(s,o),this)}catch(r){return console.error(r),this}},this.build=()=>{let n;do n=F(this,Xi).call(this);while(this.size());return n},this.next=(n=[])=>([n].flat().forEach(r=>F(this,Hs).call(this,r)),this),this.toDoc=()=>this.build(),this.run=(n,r)=>{const s=n.runSync(n.parse(r),r);return this.next(s),this},this.schema=t}},St=new WeakMap,Yi=new WeakMap,zs=new WeakMap,Vs=new WeakMap,Hs=new WeakMap,Xi=new WeakMap,Qi=new WeakMap,di.create=(t,n)=>{const r=new di(t);return s=>(r.run(n,s),r.toDoc())},di),pi,fd=(pi=class extends Bg{constructor(e,t,n,r={}){super(),this.type=e,this.children=t,this.value=n,this.props=r,this.push=(s,...o)=>{this.children||(this.children=[]),this.children.push(s,...o)},this.pop=()=>this.children?.pop()}},pi.create=(e,t,n,r={})=>new pi(e,t,n,r),pi),Xw=i=>Object.prototype.hasOwnProperty.call(i,"size"),Ve,Zi,Ws,$s,Ks,qs,er,tr,js,Js,ri,An,_s,nr,mi,Qw=(mi=class extends Pg{constructor(t){super();ae(this,Ve);ae(this,Zi);ae(this,Ws);ae(this,$s);ae(this,Ks);ae(this,qs);ae(this,er);ae(this,tr);ae(this,js);ae(this,Js);ae(this,ri);ae(this,An);ae(this,_s);ae(this,nr);re(this,Ve,[]),re(this,Zi,n=>{const r=Object.values({...this.schema.nodes,...this.schema.marks}).find(s=>s.spec.toMarkdown.match(n));if(!r)throw qx(n.type);return r}),re(this,Ws,n=>F(this,Zi).call(this,n).spec.toMarkdown.runner(this,n)),re(this,$s,(n,r)=>F(this,Zi).call(this,n).spec.toMarkdown.runner(this,n,r)),re(this,Ks,n=>{const r=l=>l.type.spec.priority??50,s=[...n].sort((l,a)=>r(l)-r(a)),o=[];return F(this,Ve).forEach(({mark:l})=>{const a=s.findIndex(h=>h.eq(l));a>=0&&o.push(...s.splice(a,1))}),o.concat(s)}),re(this,qs,n=>{const r=n?.marks;let s=0;for(;s<F(this,Ve).length;){const{mark:o,spanning:l}=F(this,Ve)[s];if(l&&r?.some(a=>a.eq(o)))s++;else break}for(let o=F(this,Ve).length-1;o>=s;o--)F(this,nr).call(this,F(this,Ve)[o].mark)}),re(this,er,(n,r)=>{F(this,Ks).call(this,n.marks).every(s=>!F(this,$s).call(this,s,n))&&F(this,Ws).call(this,n),F(this,qs).call(this,r)}),re(this,tr,n=>{const{children:r}=n;return r&&(n.children=r.reduce((s,o,l)=>{if(l===0)return[o];const a=s.at(-1);if(a&&a.isMark&&o.isMark){const{children:h,...c}=o,{children:f,...u}=a;if(o.type===a.type&&h&&f&&JSON.stringify(c)===JSON.stringify(u)){const d={...u,children:[...f,...h]};return s.slice(0,-1).concat(F(this,tr).call(this,d))}}return s.concat(o)},[])),n}),re(this,js,n=>{const r={...n.props,type:n.type};return n.children&&(r.children=n.children),n.value&&(r.value=n.value),r}),this.openNode=(n,r,s)=>(this.open(fd.create(n,void 0,r,s)),this),re(this,Js,(n,r)=>{let s="",o="";const l=n.children;if(l){const h=l[0],c=l.at(-1);if(c&&c.type==="text"&&c.value.endsWith(" ")){const f=c.value,u=f.trimEnd();o=f.slice(u.length),c.value=u}if(h&&h.type==="text"&&h.value.startsWith(" ")){const f=h.value,u=f.trimStart();s=f.slice(0,f.length-u.length),h.value=u}}s.length&&F(this,An).call(this,"text",void 0,s);const a=r();return o.length&&F(this,An).call(this,"text",void 0,o),a}),re(this,ri,(n=!1)=>{const r=this.close(),s=()=>F(this,An).call(this,r.type,r.children,r.value,r.props);return n?F(this,Js).call(this,r,s):s()}),this.closeNode=()=>(F(this,ri).call(this),this),re(this,An,(n,r,s,o)=>{const l=fd.create(n,r,s,o),a=F(this,tr).call(this,F(this,js).call(this,l));return this.push(a),a}),this.addNode=(n,r,s,o)=>(F(this,An).call(this,n,r,s,o),this),re(this,_s,(n,r,s,o)=>F(this,Ve).some(l=>l.mark.eq(n))?this:(F(this,Ve).push({mark:n,spanning:s==null}),this.openNode(r,s,{...o,isMark:!0}))),re(this,nr,n=>{let r=-1;for(let s=F(this,Ve).length-1;s>=0;s--)if(F(this,Ve)[s].mark.eq(n)){r=s;break}r<0||(F(this,Ve).splice(r,1),F(this,ri).call(this,!0))}),this.withMark=(n,r,s,o)=>(F(this,_s).call(this,n,r,s,o),this),this.closeMark=n=>(F(this,nr).call(this,n),this),this.build=()=>{let n=null;do n=F(this,ri).call(this);while(this.size());return n.children||(n.children=[]),n},this.next=n=>Xw(n)?(n.forEach((r,s,o)=>{F(this,er).call(this,r,n.maybeChild(o+1)??void 0)}),this):(F(this,er).call(this,n),this),this.toString=n=>n.stringify(this.build()),this.run=n=>(re(this,Ve,[]),this.next(n),this),this.schema=t}},Ve=new WeakMap,Zi=new WeakMap,Ws=new WeakMap,$s=new WeakMap,Ks=new WeakMap,qs=new WeakMap,er=new WeakMap,tr=new WeakMap,js=new WeakMap,Js=new WeakMap,ri=new WeakMap,An=new WeakMap,_s=new WeakMap,nr=new WeakMap,mi.create=(t,n)=>{const r=new mi(t);return s=>(r.run(s),r.toString(n))},mi);const Me=function(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e},lr=function(i){let e=i.assignedSlot||i.parentNode;return e&&e.nodeType==11?e.host:e};let vh=null;const Xt=function(i,e,t){let n=vh||(vh=document.createRange());return n.setEnd(i,t??i.nodeValue.length),n.setStart(i,e||0),n},Zw=function(){vh=null},bi=function(i,e,t,n){return t&&(ud(i,e,t,n,-1)||ud(i,e,t,n,1))},eS=/^(img|br|input|textarea|hr)$/i;function ud(i,e,t,n,r){for(var s;;){if(i==t&&e==n)return!0;if(e==(r<0?0:Ee(i))){let o=i.parentNode;if(!o||!B(o)||Ys(i)||eS.test(i.nodeName)||i.contentEditable=="false")return!1;e=Me(i)+(r<0?0:1),i=o}else if(B(i)){let o=i.childNodes[e+(r<0?-1:0)];if(B(o)&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=r;else return!1;else i=o,e=r<0?Ee(i):0}else return!1}}function Ee(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}function B(i){return i.nodeType==1}function ge(i){return i.nodeType==3}function ki(i,e){return e?i.contains(B(e)?e:e.parentNode):!1}function tS(i,e){for(;;){if(ge(i)&&e)return i;if(B(i)&&e>0){if(i.contentEditable=="false")return null;i=i.childNodes[e-1],e=Ee(i)}else if(i.parentNode&&!Ys(i))e=Me(i),i=i.parentNode;else return null}}function nS(i,e){for(;;){if(ge(i)&&e<i.nodeValue.length)return i;if(B(i)&&e<i.childNodes.length){if(i.contentEditable=="false")return null;i=i.childNodes[e],e=0}else if(i.parentNode&&!Ys(i))e=Me(i)+1,i=i.parentNode;else return null}}function iS(i,e,t){for(let n=e==0,r=e==Ee(i);n||r;){if(i==t)return!0;let s=Me(i);if(i=i.parentNode,!i)return!1;n=n&&s==0,r=r&&s==Ee(i)}}function Ys(i){let e;for(let t=i;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==i||e.contentDOM==i)}const Kl=function(i){return i.focusNode&&bi(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)};function rS(i,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=i,t.key=t.code=e,t}function sS(i){let e=i.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function oS(i,e,t){if(i.caretPositionFromPoint)try{let n=i.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(Ee(n.offsetNode),n.offset)}}catch{}if(i.caretRangeFromPoint){let n=i.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(Ee(n.startContainer),n.startOffset)}}}const _t=typeof navigator<"u"?navigator:null,dd=typeof document<"u"?document:null,jn=_t&&_t.userAgent||"",Mh=/Edge\/(\d+)/.exec(jn),Fg=/MSIE \d/.exec(jn),Ah=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(jn),et=!!(Fg||Ah||Mh),Dn=Fg?document.documentMode:Ah?+Ah[1]:Mh?+Mh[1]:0,ot=!et&&/gecko\/(\d+)/i.test(jn);ot&&+(/Firefox\/(\d+)/.exec(jn)||[0,0])[1];const Oh=!et&&/Chrome\/(\d+)/.exec(jn),Oe=!!Oh,zg=Oh?+Oh[1]:0,Le=!et&&!!_t&&/Apple Computer/.test(_t.vendor),ar=Le&&(/Mobile\/\w+/.test(jn)||!!_t&&_t.maxTouchPoints>2),ht=ar||(_t?/Mac/.test(_t.platform):!1),Vg=_t?/Win/.test(_t.platform):!1,nn=/Android \d/.test(jn),ql=!!dd&&"webkitFontSmoothing"in dd.documentElement.style,lS=ql?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function aS(i){let e=i.defaultView&&i.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:i.documentElement.clientWidth,top:0,bottom:i.documentElement.clientHeight}}function Yt(i,e){return typeof i=="number"?i:i[e]}function hS(i){let e=i.getBoundingClientRect(),t=e.width/i.offsetWidth||1,n=e.height/i.offsetHeight||1;return{left:e.left,right:e.left+i.clientWidth*t,top:e.top,bottom:e.top+i.clientHeight*n}}function pd(i,e,t){if(!Th(e)&&e.left==0)return;let n=i.someProp("scrollThreshold")||0,r=i.someProp("scrollMargin")||5,s=i.dom.ownerDocument;for(let o=t||i.dom;o;){if(!B(o)){o=lr(o);continue}let l=o==s.body,a=l?aS(s):hS(o),h=0,c=0;if(e.top<a.top+Yt(n,"top")?c=-(a.top-e.top+Yt(r,"top")):e.bottom>a.bottom-Yt(n,"bottom")&&(c=e.bottom-e.top>a.bottom-a.top?e.top+Yt(r,"top")-a.top:e.bottom-a.bottom+Yt(r,"bottom")),e.left<a.left+Yt(n,"left")?h=-(a.left-e.left+Yt(r,"left")):e.right>a.right-Yt(n,"right")&&(h=e.right-a.right+Yt(r,"right")),h||c)if(l)s.defaultView.scrollBy(h,c);else{let u=o.scrollLeft,d=o.scrollTop;c&&(o.scrollTop+=c),h&&(o.scrollLeft+=h);let p=o.scrollLeft-u,m=o.scrollTop-d;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}let f=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:lr(o)}}function cS(i){let e=i.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,r;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=i.root.elementFromPoint(s,o);if(!l||l==i.dom||!i.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){n=l,r=a.top;break}}return{refDOM:n,refTop:r,stack:Hg(i.dom)}}function Hg(i){let e=[],t=i.ownerDocument;for(let n=i;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),i!=t);n=lr(n));return e}function fS({refDOM:i,refTop:e,stack:t}){let n=i?i.getBoundingClientRect().top:0;Wg(t,n==0?0:n-e)}function Wg(i,e){for(let t=0;t<i.length;t++){let{dom:n,top:r,left:s}=i[t];n.scrollTop!=r+e&&(n.scrollTop=r+e),n.scrollLeft!=s&&(n.scrollLeft=s)}}let Di=null;function uS(i){if(i.setActive)return i.setActive();if(Di)return i.focus(Di);let e=Hg(i);i.focus(Di==null?{get preventScroll(){return Di={preventScroll:!0},!0}}:void 0),Di||(Di=!1,Wg(e,0))}function $g(i,e){let t,n=2e8,r,s=0,o=e.top,l=e.top,a,h;for(let c=i.firstChild,f=0;c;c=c.nextSibling,f++){let u;if(B(c))u=c.getClientRects();else if(ge(c))u=Xt(c).getClientRects();else continue;for(let d=0;d<u.length;d++){let p=u[d];if(p.top<=o&&p.bottom>=l){o=Math.max(p.bottom,o),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<n){t=c,n=m,r=m&&ge(t)?{left:p.right<e.left?p.right:p.left,top:e.top}:e,B(c)&&m&&(s=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=c,h={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)&&(s=f+1)}}return!t&&a&&(t=a,r=h,n=0),t&&ge(t)?dS(t,r):!t||n?{node:i,offset:s}:$g(t,r)}function dS(i,e){let t=i.nodeValue.length,n=document.createRange(),r;for(let s=0;s<t;s++){n.setEnd(i,s+1),n.setStart(i,s);let o=yn(n,1);if(o.top!=o.bottom&&qc(e,o)){r={node:i,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return n.detach(),r||{node:i,offset:0}}function qc(i,e){return i.left>=e.left-1&&i.left<=e.right+1&&i.top>=e.top-1&&i.top<=e.bottom+1}function pS(i,e){let t=i.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<i.getBoundingClientRect().left?t:i}function mS(i,e,t){let{node:n,offset:r}=$g(e,t),s=-1;if(B(n)&&!n.firstChild){let o=n.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return i.docView.posFromDOM(n,r,s)}function gS(i,e,t,n){let r=-1;for(let s=e,o=!1;s!=i.dom;){let l=i.docView.nearestDesc(s,!0),a;if(!l)return null;if(B(l.dom)&&(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)&&(!o&&a.left>n.left||a.top>n.top?r=l.posBefore:(!o&&a.right<n.left||a.bottom<n.top)&&(r=l.posAfter),o=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?n.top<(a.top+a.bottom)/2:n.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:i.docView.posFromDOM(e,t,-1)}function Kg(i,e,t){let n=i.childNodes.length;if(n&&t.top<t.bottom)for(let r=Math.max(0,Math.min(n-1,Math.floor(n*(e.top-t.top)/(t.bottom-t.top))-2)),s=r;;){let o=i.childNodes[s];if(B(o)){let l=o.getClientRects();for(let a=0;a<l.length;a++){let h=l[a];if(qc(e,h))return Kg(o,e,h)}}if((s=(s+1)%n)==r)break}return i}function yS(i,e){let t=i.dom.ownerDocument,n,r=0,s=oS(t,e.left,e.top);s&&({node:n,offset:r}=s);let o=(i.root.elementFromPoint?i.root:t).elementFromPoint(e.left,e.top),l;if(!o||!i.dom.contains(o)){let h=i.dom.getBoundingClientRect();if(!qc(e,h)||(o=Kg(i.dom,e,h),!o))return null}if(Le)for(let h=o;n&&h;h=lr(h))h.draggable&&(n=void 0);if(o=pS(o,e),n){if(ot&&B(n)&&(r=Math.min(r,n.childNodes.length),r<n.childNodes.length)){let c=n.childNodes[r],f;c.nodeName=="IMG"&&(f=c.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&r++}let h;ql&&r&&B(n)&&B(h=n.childNodes[r-1])&&h.contentEditable=="false"&&h.getBoundingClientRect().top>=e.top&&r--,n==i.dom&&r==n.childNodes.length-1&&B(n.lastChild)&&e.top>n.lastChild.getBoundingClientRect().bottom?l=i.state.doc.content.size:(r==0||!B(n)||n.childNodes[r-1].nodeName!="BR")&&(l=gS(i,n,r,e))}l==null&&(l=mS(i,o,e));let a=i.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Th(i){return i.top<i.bottom||i.left<i.right}function yn(i,e){let t=i.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(Th(n))return n}return Array.prototype.find.call(t,Th)||i.getBoundingClientRect()}const bS=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function qg(i,e,t){let{node:n,offset:r,atom:s}=i.docView.domFromPos(e,t<0?-1:1),o=ql||ot;if(ge(n))if(o&&(bS.test(n.nodeValue)||(t<0?!r:r==n.nodeValue.length))){let a=yn(Xt(n,r,r),t);if(ot&&r&&/\s/.test(n.nodeValue[r-1])&&r<n.nodeValue.length){let h=yn(Xt(n,r-1,r-1),-1);if(h.top==a.top){let c=yn(Xt(n,r,r+1),-1);if(c.top!=a.top)return Nr(c,c.left<h.left)}}return a}else{let a=r,h=r,c=t<0?1:-1;return t<0&&!r?(h++,c=-1):t>=0&&r==n.nodeValue.length?(a--,c=1):t<0?a--:h++,Nr(yn(Xt(n,a,h),c),c<0)}if(!i.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Ee(n))){let a=n.childNodes[r-1];if(B(a))return Ca(a.getBoundingClientRect(),!1)}if(s==null&&r<Ee(n)){let a=n.childNodes[r];if(B(a))return Ca(a.getBoundingClientRect(),!0)}return Ca(n.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Ee(n))){let a=n.childNodes[r-1],h=ge(a)?Xt(a,Ee(a)-(o?0:1)):B(a)&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(h)return Nr(yn(h,1),!1)}if(s==null&&r<Ee(n)){let a=n.childNodes[r];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let h=a?ge(a)?Xt(a,0,o?0:1):B(a)?a:null:null;if(h)return Nr(yn(h,-1),!0)}return Nr(yn(ge(n)?Xt(n):n,-t),t>=0)}function Nr(i,e){if(i.width==0)return i;let t=e?i.left:i.right;return{top:i.top,bottom:i.bottom,left:t,right:t}}function Ca(i,e){if(i.height==0)return i;let t=e?i.top:i.bottom;return{top:t,bottom:t,left:i.left,right:i.right}}function jg(i,e,t){let n=i.state,r=i.root.activeElement;n!=e&&i.updateState(e),r!=i.dom&&i.focus();try{return t()}finally{n!=e&&i.updateState(n),r!=i.dom&&r&&r.focus()}}function kS(i,e,t){let n=e.selection,r=t=="up"?n.$from:n.$to;return jg(i,e,()=>{let{node:s}=i.docView.domFromPos(r.pos,t=="up"?-1:1);for(;;){let l=i.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=qg(i,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(B(l))a=l.getClientRects();else if(ge(l))a=Xt(l,0,l.nodeValue.length).getClientRects();else continue;for(let h=0;h<a.length;h++){let c=a[h];if(c.bottom>c.top+1&&(t=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}const xS=/[\u0590-\u08ac]/;function wS(i,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let r=n.parentOffset,s=!r,o=r==n.parent.content.size,l=i.domSelection();return l?!xS.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:jg(i,e,()=>{let{focusNode:a,focusOffset:h,anchorNode:c,anchorOffset:f}=i.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let d=n.depth?i.docView.domAfterPos(n.before()):i.dom,{focusNode:p,focusOffset:m}=i.domSelectionRange(),g=p&&!ki(d,p)||a==p&&h==m;try{l.collapse(c,f),a&&(a!=c||h!=f)&&l.extend&&l.extend(a,h)}catch{}return u!=null&&(l.caretBidiLevel=u),g}):n.pos==n.start()||n.pos==n.end()}let md=null,gd=null,yd=!1;function SS(i,e,t){return md==e&&gd==t?yd:(md=e,gd=t,yd=t=="up"||t=="down"?kS(i,e,t):wS(i,e,t))}const bt=0,bd=1,Zn=2,Mt=3;class Xs{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=bt,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){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,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.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,n){if(this.contentDOM&&ki(this.contentDOM,e))if(n<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Me(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let s=e.compareDocumentPosition(this.contentDOM);s&16?r=t>Array.from(e.childNodes).findIndex(o=>o.contains(this.contentDOM)):r=!(s&4)}else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!1;break}if(s.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!0;break}if(s.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let s=this.getDesc(r),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(B(o)?ki(o,e):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],s=n+r.size;if(n==e&&s!=n){for(;!r.border&&r.children.length;)for(let o=0;o<r.children.length;o++){let l=r.children[o];if(l.size){r=l;break}}return r}if(e<s)return r.descAt(e-n-r.border);n=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let s=0;n<this.children.length;n++){let o=this.children[n],l=s+o.size;if(l>e){r=e-s;break}s=l}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(;n>0;n--){let s=this.children[n-1];if(s.size||!(s instanceof _g||s instanceof Jg&&s.side>=0))break}if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?Me(s.dom)+1:0}}else{let s,o=!0;for(;s=n<this.children.length?this.children[n]:null,!(!s||s.dom.parentNode==this.contentDOM);n++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?Me(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let o=n,l=0;;l++){let a=this.children[l],h=o+a.size;if(r==-1&&e<=h){let c=o+a.border;if(e>=c&&t<=h-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=o;for(let f=l;f>0;f--){let u=this.children[f-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){r=Me(u.dom)+1;break}e-=u.size}r==-1&&(r=0)}if(r>-1&&(h>t||l==this.children.length-1)){t=h;for(let c=l+1;c<this.children.length;c++){let f=this.children[c];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=Me(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=h}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:s}}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:n}=this.domFromPos(e,0);if(!B(t)||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let d=0,p=0;d<this.children.length;d++){let m=this.children[d],g=p+m.size;if(s>p&&o<g)return m.setSelection(e-p-m.border,t-p-m.border,n,r);p=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),h=n.root.getSelection(),c=n.domSelectionRange(),f=!1;if((ot||Le)&&e==t){let{node:d,offset:p}=l;if(ge(d)){if(f=!!(p&&d.nodeValue[p-1]==`
|
|
31
|
-
`),f&&p==d.nodeValue.length)for(let m=d,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:Me(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=d.childNodes[p-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(ot&&c.focusNode&&c.focusNode!=a.node&&B(c.focusNode)){let d=c.focusNode.childNodes[c.focusOffset];d&&d.contentEditable=="false"&&(r=!0)}if(!(r||f&&Le)&&bi(l.node,l.offset,c.anchorNode,c.anchorOffset)&&bi(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((h.extend||e==t)&&!(f&&ot)){h.collapse(l.node,l.offset);try{e!=t&&h.extend(a.node,a.offset),u=!0}catch{}}if(!u){if(e>t){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),h.removeAllRanges(),h.addRange(d)}}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 n=0,r=0;r<this.children.length;r++){let s=this.children[r],o=n+s.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?Zn:bd,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Mt:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Zn:Mt}n=o}this.dirty=Zn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Zn:bd;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Jg extends Xs{constructor(e,t,n,r){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(n,()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){let l=B(o)?o:document.createElement("span");l!=o&&(l.appendChild(o),o=l),l.hasAttribute("contenteditable")||(l.contentEditable="false"),l.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==bt&&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}}class CS extends Xs{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}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}}class In extends Xs{constructor(e,t,n,r,s){super(e,[],n,r),this.mark=t,this.spec=s}static create(e,t,n,r){let s=r.nodeViews[t.type.name],o=s&&s(t,r,n);return(!o||!o.dom)&&(o=kr.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new In(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Mt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Mt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=bt){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=bt}}slice(e,t,n){let r=In.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=Dh(s,t,o,n)),e>0&&(s=Dh(s,0,e,n));for(let l=0;l<s.length;l++)s[l].parent=r;return r.children=s,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class En extends Xs{constructor(e,t,n,r,s,o,l){super(e,[],s,o),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=l}static create(e,t,n,r,s,o){let l=s.nodeViews[t.type.name],a,h=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,r),c=h&&h.dom,f=h&&h.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(!ge(c))throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=kr.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return c=Yg(c,n,t),h?a=new vS(e,t,n,r,c,f||null,u,h):t.isText?new jl(e,t,n,r,c,u):new En(e,t,n,r,c,f||null,u)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(t.preserveWhitespace="full"),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){t.contentElement=r.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(r=>B(r)&&e.indexOf(r.parentNode)<0&&this.dom.contains(r));n?t.contentElement=n:t.getContent=()=>A.empty}}return t}matchesNode(e,t,n){return this.dirty==bt&&e.eq(this.node)&&cl(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new AS(this,o&&o.node,e),h=this.node.inlineContent,c=h&&this.node.isBlock;NS(this.node,this.innerDeco,(f,u,d)=>{f.spec.marks?a.syncToMarks(f.spec.marks,n,e,u):f.type.side>=0&&!d&&a.syncToMarks(u==this.node.childCount?j.none:this.node.child(u).marks,n,e,u),a.placeWidget(f,e,r)},(f,u,d,p)=>{a.syncToMarks(f.marks,n,e,p),c&&f.isAtom&&!f.isText&&a.addHackNode("IMG",a.top);let m;a.findNodeMatch(f,u,d,p)||l&&e.state.selection.from>r&&e.state.selection.to<r+f.nodeSize&&(m=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(f,u,d,m,e)||a.updateNextNode(f,u,d,e,p,r)||a.addNode(f,u,d,e,r),r+=f.nodeSize,h&&(c=f.isAtom&&!f.isText)}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Zn)&&(o&&this.protectLocalComposition(e,o),Ug(this.contentDOM,this.children,e),ar&&DS(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof K)||n<t||r>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=IS(this.node.content,o,n-t,r-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new CS(this,s,t,r);e.input.compositionNodes.push(o),this.children=Dh(this.children,n,n+r.length,e,o)}update(e,t,n,r){return this.dirty==Mt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=bt}updateOuterDeco(e){if(cl(e,this.outerDeco))return;let t=!B(this.nodeDOM),n=this.dom;this.dom=Gg(this.dom,this.nodeDOM,Nh(this.outerDeco,this.node,t),Nh(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){B(this.nodeDOM)&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){B(this.nodeDOM)&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function kd(i,e,t,n,r){Yg(n,e,i);let s=new En(void 0,i,e,t,n,n,n);return s.contentDOM&&s.updateChildren(r,0),s}class jl extends En{constructor(e,t,n,r,s,o){super(e,t,n,r,s,null,o)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==Mt||this.dirty!=bt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=bt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=bt,!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,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let r=this.node.cut(e,t),s=document.createTextNode(r.text);return new jl(this.parent,r,this.outerDeco,this.innerDeco,s,s)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Mt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class _g extends Xs{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==bt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class vS extends En{constructor(e,t,n,r,s,o,l,a){super(e,t,n,r,s,o,l),this.spec=a}update(e,t,n,r){if(this.dirty==Mt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,r),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}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 Ug(i,e,t){let n=i.firstChild,r=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==i){for(;l!=n;)n=xd(n),r=!0;n=n.nextSibling}else r=!0,i.insertBefore(l,n);if(o instanceof In){let a=n?n.previousSibling:i.lastChild;Ug(o.contentDOM,o.children,t),n=a?a.nextSibling:i.firstChild}}for(;n;)n=xd(n),r=!0;r&&t.trackWrites==i&&(t.trackWrites=null)}const Gr=function(i){i&&(this.nodeName=i)};Gr.prototype=Object.create(null);const ei=[new Gr];function Nh(i,e,t){if(i.length==0)return ei;let n=t?ei[0]:new Gr,r=[n];for(let s=0;s<i.length;s++){let o=i[s].type.attrs;if(o){o.nodeName&&r.push(n=new Gr(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&r.length==1&&r.push(n=new Gr(e.isInline?"span":"div")),l=="class"?n.class=(n.class?n.class+" ":"")+a:l=="style"?n.style=(n.style?n.style+";":"")+a:l!="nodeName"&&(n[l]=a))}}}return r}function Gg(i,e,t,n){if(t==ei&&n==ei)return e;let r=e;for(let s=0;s<n.length;s++){let o=n[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&r!=i&&(a=r.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(r),l=ei[0]),r=a}MS(r,l||ei[0],o)}return r}function MS(i,e,t){for(let n in e)n!="class"&&n!="style"&&n!="nodeName"&&!(n in t)&&i.removeAttribute(n);for(let n in t)n!="class"&&n!="style"&&n!="nodeName"&&t[n]!=e[n]&&i.setAttribute(n,t[n]);if(e.class!=t.class){let n=e.class?e.class.split(" ").filter(Boolean):[],r=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<n.length;s++)r.indexOf(n[s])==-1&&i.classList.remove(n[s]);for(let s=0;s<r.length;s++)n.indexOf(r[s])==-1&&i.classList.add(r[s]);i.classList.length==0&&i.removeAttribute("class")}if(e.style!=t.style){if(e.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(e.style);)i.style.removeProperty(r[1])}t.style&&(i.style.cssText+=t.style)}}function Yg(i,e,t){return Gg(i,i,ei,Nh(e,t,!B(i)))}function cl(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(!i[t].type.eq(e[t].type))return!1;return!0}function xd(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}class AS{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=OS(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=bt,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,h=this.top.children.length;r<this.preMatch.index&&(h=Math.min(this.index+3,h));for(let c=this.index;c<h;c++){let f=this.top.children[c];if(f.matchesMark(e[o])&&!this.isLocked(f.dom)){a=c;break}}if(a<0&&this.index<this.top.children.length){let c=this.top.children[this.index];c instanceof In&&c.dirty!=Mt&&c.mark.type==e[o].type&&c.spec.update&&!this.isLocked(c.dom)&&c.spec.update(e[o])&&(c.mark=e[o],a=this.index,this.changed=!0)}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let c=In.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,r){let s=-1,o;if(r>=this.preMatch.index&&(o=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let h=this.top.children[l];if(h.matchesNode(e,t,n)&&!this.preMatch.matched.has(h)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,r,s){let o=this.top.children[r];return o.dirty==Mt&&o.dom==o.contentDOM&&(o.dirty=Zn),o.update(e,t,n,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let n=e.pmViewDesc;if(n){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==n)return r}return-1}e=t}}updateNextNode(e,t,n,r,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof En){let h=this.preMatch.matched.get(a);if(h!=null&&h!=s)return!1;let c=a.dom,f,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=Mt&&cl(t,a.outerDeco));if(!u&&a.update(e,t,n,r))return this.destroyBetween(this.index,l),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(f=this.recreateWrapper(a,e,t,n,r,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Zn,f.updateChildren(r,o+1),f.dirty=bt),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!cl(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=En.create(this.top,t,n,r,s,o);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,n,r,s){let o=En.create(this.top,e,t,n,r,s);o.contentDOM&&o.updateChildren(r,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let s=new Jg(this.top,e,t,n);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof In;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof jl)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Le||Oe)&&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 n=document.createElement(e);e=="IMG"&&(n.className="ProseMirror-separator",n.alt=""),e=="BR"&&(n.className="ProseMirror-trailingBreak");let r=new _g(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||B(e)&&e.contains(this.lock.parentNode))}}function OS(i,e){let t=e,n=t.children.length,r=i.childCount,s=new Map,o=[];e:for(;r>0;){let l;for(;;)if(n){let h=t.children[n-1];if(h instanceof In)t=h,n=h.children.length;else{l=h,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=i.child(r-1))break;--r,s.set(l,r),o.push(l)}}return{index:r,matched:s,matches:o.reverse()}}function TS(i,e){return i.type.side-e.type.side}function NS(i,e,t,n){let r=e.locals(i),s=0;if(r.length==0){for(let h=0;h<i.childCount;h++){let c=i.child(h);n(c,r,e.forChild(s,c),h),s+=c.nodeSize}return}let o=0,l=[],a=null;for(let h=0;;){let c,f;for(;o<r.length&&r[o].to==s;){let g=r[o++];g.widget&&(c?(f||(f=[c])).push(g):c=g)}if(c)if(f){f.sort(TS);for(let g=0;g<f.length;g++)t(f[g],h,!!a)}else t(c,h,!!a);let u,d;if(a)d=-1,u=a,a=null;else if(h<i.childCount)d=h,u=i.child(h++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<r.length&&r[o].from<=s&&r[o].to>s;)l.push(r[o++]);let p=s+u.nodeSize;if(u.isText){let g=p;o<r.length&&r[o].from<g&&(g=r[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<p&&(a=u.cut(g-s),u=u.cut(0,g-s),p=g,d=-1)}else for(;o<r.length&&r[o].to<p;)o++;let m=u.isInline&&!u.isLeaf?l.filter(g=>!g.inline):l.slice();n(u,m,e.forChild(s,u),d),s=p}}function DS(i){if(i.nodeName=="UL"||i.nodeName=="OL"){let e=i.style.cssText;i.style.cssText=e+"; list-style: square !important",window.getComputedStyle(i).listStyle,i.style.cssText=e}}function IS(i,e,t,n){for(let r=0,s=0;r<i.childCount&&s<=n;){let o=i.child(r++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;r<i.childCount;){let h=i.child(r++);if(s+=h.nodeSize,!h.isText)break;a+=h.text}if(s>=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let h=l<n?a.lastIndexOf(e,n-l-1):-1;if(h>=0&&h+e.length+l>=t)return l+h;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function Dh(i,e,t,n,r){let s=[];for(let o=0,l=0;o<i.length;o++){let a=i[o],h=l,c=l+=a.size;h>=t||c<=e?s.push(a):(h<e&&s.push(a.slice(0,e-h,n)),r&&(s.push(r),r=void 0),c>t&&s.push(a.slice(t-h,a.size,n)))}return s}function jc(i,e=null){let t=i.domSelectionRange(),n=i.state.doc;if(!t.focusNode)return null;let r=i.docView.nearestDesc(t.focusNode),s=r&&r.size==0,o=i.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,h;if(Kl(t)){for(a=o;r&&!r.node;)r=r.parent;if(r&&r.node.isAtom&&z.isSelectable(r.node)&&r.parent&&!(r.node.isInline&&iS(t.focusNode,t.focusOffset,r.dom))){let f=r.posBefore;h=new z(o==f?l:n.resolve(f))}else if(ot&&e=="key"&&o>i.state.selection.to&&B(t.focusNode)&&t.focusOffset==t.focusNode.childNodes.length&&r&&r.posAtStart>i.state.selection.to)for(let f=t.focusNode;;f=f.parentNode){if(getComputedStyle(f).overflow!="visible"){h=_.findFrom(n.resolve(r.posAtStart),1);break}if(f==r.dom||f.nextSibling||!f.parentNode||!B(f.parentNode))break}}else{if(t instanceof i.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,u=o;for(let d=0;d<t.rangeCount;d++){let p=t.getRangeAt(d);f=Math.min(f,i.docView.posFromDOM(p.startContainer,p.startOffset,1)),u=Math.max(u,i.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(f<0)return null;[a,o]=u==i.state.selection.anchor?[u,f]:[f,u],l=n.resolve(o)}else a=i.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let c=n.resolve(a);if(!h){let f=e=="pointer"||i.state.selection.head<l.pos&&!s?1:-1;h=Jc(i,c,l,f)}return h}function Xg(i){return i.editable?i.hasFocus():Zg(i)&&document.activeElement&&document.activeElement.contains(i.dom)}function sn(i,e=!1){let t=i.state.selection;if(Qg(i,t),!Xg(i))return;let n=i.input.mouseDown;if(!e&&Oe&&n){let r=i.domSelectionRange(),s=i.domObserver.currentSelection;if(r.anchorNode&&s.anchorNode&&bi(r.anchorNode,r.anchorOffset,s.anchorNode,s.anchorOffset)&&n.delaySelUpdate()){i.domObserver.setCurSelection();return}}if(i.domObserver.disconnectSelection(),i.cursorWrapper)RS(i);else{let{anchor:r,head:s}=t,o,l;wd&&!(t instanceof K)&&(t.$from.parent.inlineContent||(o=Sd(i,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(l=Sd(i,t.to))),i.docView.setSelection(r,s,i,e),wd&&(o&&Cd(o),l&&Cd(l)),t.visible?i.dom.classList.remove("ProseMirror-hideselection"):(i.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&ES(i))}i.domObserver.setCurSelection(),i.domObserver.connectSelection()}const wd=Le||Oe&&zg<63;function Sd(i,e){let{node:t,offset:n}=i.docView.domFromPos(e,0),r=n<t.childNodes.length?t.childNodes[n]:null,s=n?t.childNodes[n-1]:null;if(Le&&r&&r.contentEditable=="false")return va(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return va(r);if(s)return va(s)}}function va(i){return i.contentEditable="true",Le&&i.draggable&&(i.draggable=!1,i.wasDraggable=!0),i}function Cd(i){i.contentEditable="false",i.wasDraggable&&(i.draggable=!0,i.wasDraggable=null)}function ES(i){let e=i.dom.ownerDocument;e.removeEventListener("selectionchange",i.input.hideSelectionGuard);let t=i.domSelectionRange(),n=t.anchorNode,r=t.anchorOffset;e.addEventListener("selectionchange",i.input.hideSelectionGuard=()=>{(t.anchorNode!=n||t.anchorOffset!=r)&&(e.removeEventListener("selectionchange",i.input.hideSelectionGuard),setTimeout(()=>{(!Xg(i)||i.state.selection.visible)&&i.dom.classList.remove("ProseMirror-hideselection")},20))})}function RS(i){let e=i.domSelection();if(!e)return;let t=i.cursorWrapper.dom,n=t.nodeName=="IMG";n?e.collapse(t.parentNode,Me(t)+1):e.collapse(t,0),!n&&!i.state.selection.visible&&et&&Dn<=11&&(t.disabled=!0,t.disabled=!1)}function Qg(i,e){if(e instanceof z){let t=i.docView.descAt(e.from);t!=i.lastSelectedViewDesc&&(vd(i),t&&t.selectNode(),i.lastSelectedViewDesc=t)}else vd(i)}function vd(i){i.lastSelectedViewDesc&&(i.lastSelectedViewDesc.parent&&i.lastSelectedViewDesc.deselectNode(),i.lastSelectedViewDesc=void 0)}function Jc(i,e,t,n){return i.someProp("createSelectionBetween",r=>r(i,e,t))||K.between(e,t,n)}function Md(i){return i.editable&&!i.hasFocus()?!1:Zg(i)}function Zg(i){let e=i.domSelectionRange();if(!e.anchorNode)return!1;try{return ki(i.dom,e.anchorNode)&&(i.editable||ki(i.dom,e.focusNode))}catch{return!1}}function BS(i){let e=i.docView.domFromPos(i.state.selection.anchor,0),t=i.domSelectionRange();return bi(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ih(i,e){let{$anchor:t,$head:n}=i.selection,r=e>0?t.max(n):t.min(n),s=r.parent.inlineContent?r.depth?i.doc.resolve(e>0?r.after():r.before()):null:r;return s&&_.findFrom(s,e)}function bn(i,e){return i.dispatch(i.state.tr.setSelection(e).scrollIntoView()),!0}function Ad(i,e,t){let n=i.state.selection;if(n instanceof K)if(t.indexOf("s")>-1){let{$head:r}=n,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=i.state.doc.resolve(r.pos+s.nodeSize*(e<0?-1:1));return bn(i,new K(n.$anchor,o))}else if(n.empty){if(i.endOfTextblock(e>0?"forward":"backward")){let r=Ih(i.state,e);return r&&r instanceof z?bn(i,r):!1}else if(!ht||t.indexOf("m")<0){let r=n.$head,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?r.pos-s.nodeSize:r.pos;return s.isAtom||(o=i.docView.descAt(l))&&!o.contentDOM?z.isSelectable(s)?bn(i,new z(e<0?i.state.doc.resolve(r.pos-s.nodeSize):r)):bn(i,new K(i.state.doc.resolve(e<0?l:l+s.nodeSize))):!1}}else return!1;else{if(n instanceof z&&n.node.isInline)return bn(i,new K(e>0?n.$to:n.$from));{let r=Ih(i.state,e);return r?bn(i,r):!1}}}function Yr(i,e){let t=i.pmViewDesc;return t?t.size==0&&(e<0||i.nextSibling||i.nodeName!="BR"):B(i)&&i.contentEditable=="false"}function Ii(i,e){return e<0?PS(i):LS(i)}function PS(i){let e=i.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let r,s,o=!1;for(ot&&B(t)&&n<Ee(t)&&Yr(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(!B(t))break;let l=t.childNodes[n-1];if(Yr(l,-1))r=t,s=--n;else if(ge(l))t=l,n=t.nodeValue.length;else break}else{if(e0(t))break;{let l=t.previousSibling;for(;l&&Yr(l,-1);)r=t.parentNode,s=Me(l),l=l.previousSibling;if(l)t=l,n=Ee(t);else{if(t=t.parentNode,t==i.dom)break;n=0}}}o?Eh(i,t,n):r&&Eh(i,r,s)}function LS(i){let e=i.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let r=Ee(t),s,o;for(;;)if(n<r){if(!B(t))break;let l=t.childNodes[n];if(Yr(l,1))s=t,o=++n;else break}else{if(e0(t))break;{let l=t.nextSibling;for(;l&&Yr(l,1);)s=l.parentNode,o=Me(l)+1,l=l.nextSibling;if(l)t=l,n=0,r=Ee(t);else{if(t=t.parentNode,t==i.dom)break;n=r=0}}}s&&Eh(i,s,o)}function e0(i){let e=i.pmViewDesc;return e&&e.node&&e.node.isBlock}function FS(i,e){for(;i&&e==i.childNodes.length&&!Ys(i);)e=Me(i)+1,i=i.parentNode;for(;i&&e<i.childNodes.length;){let t=i.childNodes[e];if(ge(t))return t;if(B(t)&&t.contentEditable=="false")break;i=t,e=0}}function zS(i,e){for(;i&&!e&&!Ys(i);)e=Me(i),i=i.parentNode;for(;i&&e;){let t=i.childNodes[e-1];if(ge(t))return t;if(B(t)&&t.contentEditable=="false")break;i=t,e=i.childNodes.length}}function Eh(i,e,t){if(!ge(e)){let o,l;(l=FS(e,t))?(e=l,t=0):(o=zS(e,t))&&(e=o,t=o.nodeValue.length)}let n=i.domSelection(),r=i.domSelectionRange();if(!n)return;Kl(r)?n.collapse(e,t):n.extend&&(n.collapse(r.anchorNode,r.anchorOffset),n.extend(e,t)),i.domObserver.setCurSelection();let{state:s}=i;setTimeout(()=>{i.state==s&&sn(i)},50)}function Od(i,e){let t=i.state.doc.resolve(e);if(!(Oe||Vg)&&t.parent.inlineContent){let s=i.coordsAtPos(e);if(e>t.start()){let o=i.coordsAtPos(e-1),l=(o.top+o.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(o.left-s.left)>1)return o.left<s.left?"ltr":"rtl"}if(e<t.end()){let o=i.coordsAtPos(e+1),l=(o.top+o.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(o.left-s.left)>1)return o.left>s.left?"ltr":"rtl"}}let n=i.dom;for(let s=t.depth;s>0;s--)if(t.node(s).isBlock){n=i.nodeDOM(t.before(s))||n;break}return getComputedStyle(n).direction=="rtl"?"rtl":"ltr"}function Td(i,e,t){let n=i.state.selection;if(n instanceof K&&!n.empty||t.indexOf("s")>-1||ht&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=n;if(!r.parent.inlineContent||i.endOfTextblock(e<0?"up":"down")){let o=Ih(i.state,e);if(o&&o instanceof z)return bn(i,o)}if(!r.parent.inlineContent){let o=e<0?r:s,l=n instanceof st?_.near(o,e):_.findFrom(o,e);return l?bn(i,l):!1}return!1}function Nd(i,e){if(!(i.state.selection instanceof K))return!0;let{$head:t,$anchor:n,empty:r}=i.state.selection;if(!t.sameParent(n))return!0;if(!r)return!1;if(i.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=i.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),i.dispatch(o),!0}return!1}function Dd(i,e,t){i.domObserver.stop(),e.contentEditable=t,i.domObserver.start()}function VS(i){if(!Le||i.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=i.domSelectionRange();if(e&&B(e)&&t==0&&e.firstChild&&B(e.firstChild)&&e.firstChild.contentEditable=="false"){let n=e.firstChild;Dd(i,n,"true"),setTimeout(()=>Dd(i,n,"false"),20)}return!1}function HS(i){let e="";return i.ctrlKey&&(e+="c"),i.metaKey&&(e+="m"),i.altKey&&(e+="a"),i.shiftKey&&(e+="s"),e}function WS(i,e){let t=e.keyCode,n=HS(e);if(t==8||ht&&t==72&&n=="c")return Nd(i,-1)||Ii(i,-1);if(t==46&&!e.shiftKey||ht&&t==68&&n=="c")return Nd(i,1)||Ii(i,1);if(t==13||t==27)return!0;if(t==37||ht&&t==66&&n=="c"){let r=t==37?Od(i,i.state.selection.from)=="ltr"?-1:1:-1;return Ad(i,r,n)||Ii(i,r)}else if(t==39||ht&&t==70&&n=="c"){let r=t==39?Od(i,i.state.selection.from)=="ltr"?1:-1:1;return Ad(i,r,n)||Ii(i,r)}else{if(t==38||ht&&t==80&&n=="c")return Td(i,-1,n)||Ii(i,-1);if(t==40||ht&&t==78&&n=="c")return VS(i)||Td(i,1,n)||Ii(i,1);if(n==(ht?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function _c(i,e){i.someProp("transformCopied",d=>{e=d(e,i)});let t=[],{content:n,openStart:r,openEnd:s}=e;for(;r>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){r--,s--;let d=n.firstChild;t.push(d.type.name,d.attrs!=d.type.defaultAttrs?d.attrs:null),n=d.content}let o=i.someProp("clipboardSerializer")||kr.fromSchema(i.state.schema),l=o0(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let h=a.firstChild,c,f=0;for(;h&&B(h)&&(c=s0[h.nodeName.toLowerCase()]);){for(let d=c.length-1;d>=0;d--){let p=l.createElement(c[d]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),f++}h=a.firstChild}h&&B(h)&&h.setAttribute("data-pm-slice",`${r} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let u=i.someProp("clipboardTextSerializer",d=>d(e,i))||e.content.textBetween(0,e.content.size,`
|
|
32
|
-
|
|
33
|
-
`);return{dom:a,text:u,slice:e}}function t0(i,e,t,n,r){let s=r.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(n||s||!t);if(a){if(i.someProp("transformPastedText",u=>{e=u(e,s||n,i)}),s)return l=new E(A.from(i.state.schema.text(e.replace(/\r\n?/g,`
|
|
34
|
-
`))),0,0),i.someProp("transformPasted",u=>{l=u(l,i,!0)}),l;let f=i.someProp("clipboardTextParser",u=>u(e,r,n,i));if(f)l=f;else{let u=r.marks(),{schema:d}=i.state,p=kr.fromSchema(d);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(d.text(m,u)))})}}else i.someProp("transformPastedHTML",f=>{t=f(t,i)}),o=jS(t),ql&&JS(o);let h=o&&o.querySelector("[data-pm-slice]"),c=h&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(h.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let u=o.firstChild;for(;u&&!B(u);)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(i.someProp("clipboardParser")||i.someProp("domParser")||rr.fromSchema(i.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||c),context:r,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!$S.test(u.parentNode.nodeName)?{ignore:!0}:null}})),c)l=_S(Id(l,+c[1],+c[2]),c[4]);else if(l=E.maxOpen(KS(l.content,r),!0),l.openStart||l.openEnd){let f=0,u=0;for(let d=l.content.firstChild;f<l.openStart&&!d.type.spec.isolating;f++,d=d.firstChild);for(let d=l.content.lastChild;u<l.openEnd&&!d.type.spec.isolating;u++,d=d.lastChild);l=Id(l,f,u)}return i.someProp("transformPasted",f=>{l=f(l,i,a)}),l}const $S=/^(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 KS(i,e){if(i.childCount<2)return i;for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(i.forEach(l=>{if(!o)return;let a=r.findWrapping(l.type),h;if(!a)return o=null;if(h=o.length&&s.length&&i0(a,s,l,o[o.length-1],0))o[o.length-1]=h;else{o.length&&(o[o.length-1]=r0(o[o.length-1],s.length));let c=n0(l,a);o.push(c),r=r.matchType(c.type),s=a}}),o)return A.from(o)}return i}function n0(i,e,t=0){for(let n=e.length-1;n>=t;n--)i=e[n].create(null,A.from(i));return i}function i0(i,e,t,n,r){if(r<i.length&&r<e.length&&i[r]==e[r]){let s=i0(i,e,t,n.lastChild,r+1);if(s)return n.copy(n.content.replaceChild(n.childCount-1,s));if(n.contentMatchAt(n.childCount).matchType(r==i.length-1?t.type:i[r+1]))return n.copy(n.content.append(A.from(n0(t,i,r+1))))}}function r0(i,e){if(e==0)return i;let t=i.content.replaceChild(i.childCount-1,r0(i.lastChild,e-1)),n=i.contentMatchAt(i.childCount).fillBefore(A.empty,!0);return i.copy(t.append(n))}function Rh(i,e,t,n,r,s){let o=e<0?i.firstChild:i.lastChild,l=o.content;return i.childCount>1&&(s=0),r<n-1&&(l=Rh(l,e,t,n,r+1,s)),r>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=r).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(A.empty,!0))),i.replaceChild(e<0?0:i.childCount-1,o.copy(l))}function Id(i,e,t){return e<i.openStart&&(i=new E(Rh(i.content,-1,e,i.openStart,0,i.openEnd),e,i.openEnd)),t<i.openEnd&&(i=new E(Rh(i.content,1,t,i.openEnd,0,0),i.openStart,t)),i}const s0={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function o0(){return document.implementation.createHTMLDocument("title")}let Dr=null;function qS(i){let e=window.trustedTypes;if(!e)return i;if(!Dr){if(Dr=e.defaultPolicy)try{return Dr.createHTML(i)}catch{}Dr=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return Dr.createHTML(i)}function jS(i){let e=/^(\s*<meta [^>]*>)*/.exec(i);e&&(i=i.slice(e[0].length));let t=o0(),n=t.body,r=/<([a-z][^>\s]+)/i.exec(i),s;if((s=r&&s0[r[1].toLowerCase()])&&(i=s.map(o=>"<"+o+">").join("")+i+s.map(o=>"</"+o+">").reverse().join("")),n.innerHTML=qS(i),s)for(let o=0;o<s.length;o++)n=n.querySelector(s[o])||n;for(let o=0;o<t.styleSheets.length;o++){let l=t.styleSheets[o];for(let a=0;a<l.rules.length;a++){let h=l.rules[a];if(h instanceof CSSStyleRule){let c=n.querySelectorAll(h.selectorText);for(let f=0;f<c.length;f++)c[f].style.cssText+=h.style.cssText}}}return n}function JS(i){let e=i.querySelectorAll(Oe?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let n=e[t];n.childNodes.length==1&&n.textContent==" "&&n.parentNode&&n.parentNode.replaceChild(i.ownerDocument.createTextNode(" "),n)}}function _S(i,e){if(!i.size)return i;let t=i.content.firstChild.type.schema,n;try{n=JSON.parse(e)}catch{return i}let{content:r,openStart:s,openEnd:o}=i;for(let l=n.length-2;l>=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;try{r=A.from(a.create(n[l+1],r))}catch{break}s++,o++}return new E(r,s,o)}const Ke={},qe={},US={touchstart:!0,touchmove:!0};let GS=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastKeyDispatched=!1,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 YS(i){for(let e in Ke){let t=Ke[e];i.dom.addEventListener(e,i.input.eventHandlers[e]=n=>{QS(i,n)&&!Uc(i,n)&&(i.editable||!(n.type in qe))&&t(i,n)},US[e]?{passive:!0}:void 0)}Le&&i.dom.addEventListener("input",()=>null),Bh(i)}function rn(i,e){i.input.lastSelectionOrigin=e,i.input.lastSelectionTime=Date.now()}function XS(i){i.input.mouseDown&&i.input.mouseDown.done(),i.domObserver.stop();for(let e in i.input.eventHandlers)i.dom.removeEventListener(e,i.input.eventHandlers[e]);clearTimeout(i.input.composingTimeout),clearTimeout(i.input.lastIOSEnterFallbackTimeout)}function Bh(i){i.someProp("handleDOMEvents",e=>{for(let t in e)i.input.eventHandlers[t]||i.dom.addEventListener(t,i.input.eventHandlers[t]=n=>Uc(i,n))})}function Uc(i,e){return i.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(i,e)||e.defaultPrevented:!1})}function QS(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=i.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ZS(i,e){!Uc(i,e)&&Ke[e.type]&&(i.editable||!(e.type in qe))&&Ke[e.type](i,e)}function Sn(i,e){let{input:t}=i;return t.lastKeyDispatched||i.composing?!1:(t.lastKeyDispatched=!0,typeof e=="string"&&(e=rS(e=="Backspace"?8:13,e)),i.someProp("handleKeyDown",n=>n(i,e)))}qe.keydown=(i,e)=>{let t=e;if(i.input.shiftKey=t.keyCode==16||t.shiftKey,!c0(i)&&(i.input.lastKeyCode=t.keyCode,i.input.lastKeyCodeTime=Date.now(),i.input.lastKeyDispatched=!1,!(nn&&Oe&&t.keyCode==13)))if(t.keyCode!=229&&i.domObserver.forceFlush(),ar&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();i.input.lastIOSEnter=n,i.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{i.input.lastIOSEnter==n&&(Sn(i,"Enter"),i.input.lastIOSEnter=0)},200)}else Sn(i,t)||WS(i,t)?t.preventDefault():rn(i,"key")};qe.keyup=(i,e)=>{e.keyCode==16&&(i.input.shiftKey=!1)};qe.keypress=(i,e)=>{let t=e;if(c0(i)||!t.charCode||t.ctrlKey&&!t.altKey||ht&&t.metaKey)return;if(i.someProp("handleKeyPress",r=>r(i,t))){t.preventDefault();return}let n=i.state.selection;if(!(n instanceof K)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(t.charCode),s=()=>i.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!i.someProp("handleTextInput",o=>o(i,n.$from.pos,n.$to.pos,r,s))&&i.dispatch(s()),t.preventDefault()}};function Qs(i){return{left:i.clientX,top:i.clientY}}function eC(i,e){let t=e.x-i.clientX,n=e.y-i.clientY;return t*t+n*n<100}function Gc(i,e,t,n,r){if(n==-1)return!1;let s=i.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(i.someProp(e,l=>o>s.depth?l(i,t,s.nodeAfter,s.before(o),r,!0):l(i,t,s.node(o),s.before(o),r,!1)))return!0;return!1}function Zs(i,e,t){if(i.focused||i.focus(),i.state.selection.eq(e))return;let n=i.state.tr.setSelection(e);n.setMeta("pointer",!0),i.dispatch(n)}function tC(i,e){if(e==-1)return!1;let t=i.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&z.isSelectable(n)?(Zs(i,new z(t)),!0):!1}function nC(i,e){if(e==-1)return!1;let t=i.state.selection,n,r;t instanceof z&&(n=t.node);let s=i.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(z.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?r=s.before(t.$from.depth):r=s.before(o);break}}return r!=null?(Zs(i,z.create(i.state.doc,r)),!0):!1}function iC(i,e,t,n,r){return Gc(i,"handleClickOn",e,t,n)||i.someProp("handleClick",s=>s(i,e,n))||(r?nC(i,t):tC(i,t))}function rC(i,e,t,n){return Gc(i,"handleDoubleClickOn",e,t,n)||i.someProp("handleDoubleClick",r=>r(i,e,n))}function sC(i,e,t,n){return Gc(i,"handleTripleClickOn",e,t,n)||i.someProp("handleTripleClick",r=>r(i,e,n))||oC(i,t,n)}function oC(i,e,t){if(t.button!=0)return!1;let n=l0(i,e,!0),r=i.state.doc;return n?(Zs(i,n),n instanceof K&&r.eq(i.state.doc)&&(i.input.mouseDown=new aC(i,n)),!0):!1}function l0(i,e,t){let n=i.state.doc;if(e==-1)return n.inlineContent?K.create(n,0,n.content.size):null;let r=n.resolve(e);for(let s=r.depth+1;s>0;s--){let o=s>r.depth?r.nodeAfter:r.node(s),l=r.before(s);if(o.inlineContent)return K.create(n,l+1,l+1+o.content.size);if(t&&z.isSelectable(o))return z.create(n,l)}return null}function Yc(i){return fl(i)}const a0=ht?"metaKey":"ctrlKey";Ke.mousedown=(i,e)=>{let t=e;i.input.shiftKey=t.shiftKey;let n=Yc(i),r=Date.now(),s="singleClick";r-i.input.lastClick.time<500&&eC(t,i.input.lastClick)&&!t[a0]&&i.input.lastClick.button==t.button&&(i.input.lastClick.type=="singleClick"?s="doubleClick":i.input.lastClick.type=="doubleClick"&&(s="tripleClick")),i.input.lastClick={time:r,x:t.clientX,y:t.clientY,type:s,button:t.button},i.input.mouseDown&&i.input.mouseDown.done();let o=i.posAtCoords(Qs(t));o&&(s=="singleClick"?i.input.mouseDown=new lC(i,o,t,!!n):(s=="doubleClick"?rC:sC)(i,o.pos,o.inside,t)?t.preventDefault():rn(i,"pointer"))};class h0{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}}class lC extends h0{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[a0],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let c=e.state.doc.resolve(t.pos);s=c.parent,o=c.depth?c.before():0}const l=r?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&B(a.nodeDOM)?a.nodeDOM:null;let{selection:h}=e.state;n.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||h instanceof z&&h.from<=o&&h.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ot&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),rn(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||sn(this.view)})}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(Qs(e))),this.updateAllowDefault(e),this.allowDefault||!t?rn(this.view,"pointer"):iC(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Le&&this.mightDrag&&!this.mightDrag.node.isAtom||Oe&&!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)?(Zs(this.view,_.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):rn(this.view,"pointer")}move(e){this.updateAllowDefault(e),rn(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}}class aC extends h0{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),rn(this.view,"pointer");let t=this.view.posAtCoords(Qs(e)),n=t&&l0(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,s=this.startSelection,[o,l]=n.from<s.from?[s.to,n.from]:[s.from,n.to];Zs(this.view,K.create(r,o,l))}}Ke.touchstart=i=>{i.input.lastTouch=Date.now(),Yc(i),rn(i,"pointer")};Ke.touchmove=i=>{i.input.lastTouch=Date.now(),rn(i,"pointer")};Ke.contextmenu=i=>Yc(i);function c0(i,e){return i.composing?!0:Le&&Math.abs(Date.now()-i.input.compositionEndedAt)<500?(i.input.compositionEndedAt=-2e8,!0):!1}const hC=nn?5e3:-1;qe.compositionstart=qe.compositionupdate=i=>{if(!i.composing){i.domObserver.flush();let{state:e}=i,t=e.selection.$to;if(e.selection instanceof K&&e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||Oe&&Vg&&cC(i)))i.markCursor=i.state.storedMarks||t.marks(),fl(i,!0),i.markCursor=null;else if(fl(i,!e.selection.empty),ot&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=i.domSelectionRange();for(let r=n.focusNode,s=n.focusOffset;r&&B(r)&&s!=0;){let o=s<0?r.lastChild:r.childNodes[s-1];if(!o)break;if(ge(o)){let l=i.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else r=o,s=-1}}i.input.composing=!0}f0(i,hC)};function cC(i){let{focusNode:e,focusOffset:t}=i.domSelectionRange();if(!e||!B(e)||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return B(n)&&n.contentEditable=="false"}qe.compositionend=(i,e)=>{i.composing&&(i.input.composing=!1,i.input.compositionEndedAt=Date.now(),i.input.compositionPendingChanges=i.domObserver.pendingRecords().length?i.input.compositionID:0,i.input.compositionNode=null,i.input.badSafariComposition?i.domObserver.forceFlush():i.input.compositionPendingChanges&&Promise.resolve().then(()=>i.domObserver.flush()),i.input.compositionID++,f0(i,20))};function f0(i,e){clearTimeout(i.input.composingTimeout),e>-1&&(i.input.composingTimeout=setTimeout(()=>fl(i),e))}function u0(i){for(i.composing&&(i.input.composing=!1,i.input.compositionEndedAt=Date.now());i.input.compositionNodes.length>0;)i.input.compositionNodes.pop().markParentsDirty()}function fC(i){let e=i.domSelectionRange();if(!e.focusNode)return null;let t=tS(e.focusNode,e.focusOffset),n=nS(e.focusNode,e.focusOffset);if(t&&n&&t!=n){let r=n.pmViewDesc,s=i.domObserver.lastChangedTextNode;if(t==s||n==s)return s;if(!r||!r.isText(n.nodeValue))return n;if(i.input.compositionNode==n){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return n}}return t||n}function fl(i,e=!1){if(!(nn&&i.domObserver.flushingSoon>=0)){if(i.domObserver.forceFlush(),u0(i),e||i.docView&&i.docView.dirty){let t=jc(i),n=i.state.selection;return t&&!t.eq(n)?i.dispatch(i.state.tr.setSelection(t)):(i.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?i.dispatch(i.state.tr.deleteSelection()):i.updateState(i.state),!0}return!1}}function uC(i,e){if(!i.dom.parentNode)return;let t=i.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),r=document.createRange();r.selectNodeContents(e),i.dom.blur(),n.removeAllRanges(),n.addRange(r),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),i.focus()},50)}const ys=et&&Dn<15||ar&&lS<604;Ke.copy=qe.cut=(i,e)=>{let t=e,n=i.state.selection,r=t.type=="cut";if(n.empty)return;let s=ys?null:t.clipboardData,o=n.content(),{dom:l,text:a}=_c(i,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):uC(i,l),r&&i.dispatch(i.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dC(i){return i.openStart==0&&i.openEnd==0&&i.content.childCount==1?i.content.firstChild:null}function pC(i,e){if(!i.dom.parentNode)return;let t=i.input.shiftKey||i.state.selection.$from.parent.type.spec.code,n=i.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let r=i.input.shiftKey&&i.input.lastKeyCode!=45;setTimeout(()=>{i.focus(),n.parentNode&&n.parentNode.removeChild(n),t?bs(i,n.value,null,r,e):bs(i,n.textContent,n.innerHTML,r,e)},50)}function bs(i,e,t,n,r){let s=t0(i,e,t,n,i.state.selection.$from);if(i.someProp("handlePaste",a=>a(i,r,s||E.empty)))return!0;if(!s)return!1;let o=dC(s),l=o?i.state.tr.replaceSelectionWith(o,n):i.state.tr.replaceSelection(s);return i.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function d0(i){let e=i.getData("text/plain")||i.getData("Text");if(e)return e;let t=i.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}qe.paste=(i,e)=>{let t=e;if(i.composing&&!nn)return;let n=ys?null:t.clipboardData,r=i.input.shiftKey&&i.input.lastKeyCode!=45;n&&bs(i,d0(n),n.getData("text/html"),r,t)?t.preventDefault():pC(i,t)};class p0{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const mC=ht?"altKey":"ctrlKey";function m0(i,e){let t;return i.someProp("dragCopies",n=>{t=t||n(e)}),t!=null?!t:!e[mC]}Ke.dragstart=(i,e)=>{let t=e,n=i.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let r=i.state.selection,s=r.empty?null:i.posAtCoords(Qs(t)),o;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof z?r.to-1:r.to))){if(n&&n.mightDrag)o=z.create(i.state.doc,n.mightDrag.pos);else if(t.target&&B(t.target)){let f=i.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=i.docView&&(o=z.create(i.state.doc,f.posBefore))}}let l=(o||i.state.selection).content(),{dom:a,text:h,slice:c}=_c(i,l);(!t.dataTransfer.files.length||!Oe||zg>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ys?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",ys||t.dataTransfer.setData("text/plain",h),i.dragging=new p0(c,m0(i,t),o)};Ke.dragend=i=>{let e=i.dragging;window.setTimeout(()=>{i.dragging==e&&(i.dragging=null)},50)};qe.dragover=qe.dragenter=(i,e)=>e.preventDefault();qe.drop=(i,e)=>{try{gC(i,e,i.dragging)}finally{i.dragging=null}};function gC(i,e,t){if(!e.dataTransfer)return;let n=i.posAtCoords(Qs(e));if(!n)return;let r=i.state.doc.resolve(n.pos),s=t&&t.slice;s?i.someProp("transformPasted",d=>{s=d(s,i,!1)}):s=t0(i,d0(e.dataTransfer),ys?null:e.dataTransfer.getData("text/html"),!1,r);let o=!!(t&&m0(i,e));if(i.someProp("handleDrop",d=>d(i,e,s||E.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Ax(i.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let a=i.state.tr;if(o){let{node:d}=t;d?d.replace(a):a.deleteSelection()}let h=a.mapping.map(l),c=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(c?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(c&&z.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new z(u));else{let d=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,y)=>d=y),a.setSelection(Jc(i,u,a.doc.resolve(d)))}i.focus(),i.dispatch(a.setMeta("uiEvent","drop"))}Ke.focus=i=>{if(i.input.lastFocus=Date.now(),!i.focused){i.domObserver.stop(),i.dom.classList.add("ProseMirror-focused"),i.domObserver.start(),i.focused=!0;let e=i.domSelectionRange();if(!i.domObserver.currentSelection.eq(e)){let{focusNode:t,focusOffset:n}=e;setTimeout(()=>{let r=i.domSelectionRange();r.focusNode==t&&r.focusOffset==n&&i.docView&&i.hasFocus()&&sn(i)},20)}}};Ke.blur=(i,e)=>{let t=e;i.focused&&(i.domObserver.stop(),i.dom.classList.remove("ProseMirror-focused"),i.domObserver.start(),t.relatedTarget&&i.dom.contains(t.relatedTarget)&&i.domObserver.currentSelection.clear(),i.focused=!1)};Ke.beforeinput=(i,e)=>{if(nn&&e.inputType=="deleteContentBackward"){i.domObserver.flushSoon();let{domChangeCount:n}=i.input;setTimeout(()=>{if(i.input.domChangeCount!=n||i.domObserver.pendingRecords().length||(i.dom.blur(),i.focus(),Sn(i,"Backspace")))return;let{$cursor:r}=i.state.selection;r&&r.pos>0&&i.dispatch(i.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let i in qe)Ke[i]=qe[i];function ks(i,e){if(i==e)return!0;for(let t in i)if(i[t]!==e[t])return!1;for(let t in e)if(!(t in i))return!1;return!0}let Ph=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index<this.frag.childCount;){let t=this.frag.child(this.index);if(this.off==e)return t;this.off+=t.nodeSize,this.index++}return null}},Ed=class g0{constructor(e,t){this.toDOM=e,this.spec=t||ai,this.side=this.spec.side||0}map(e,t,n,r){let{pos:s,deleted:o}=e.mapResult(t.from+r,this.side<0?-1:1);return o?null:new Ln(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof g0&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ks(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}};class Rn{constructor(e,t){this.attrs=e,this.spec=t||ai}map(e,t,n,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new Ln(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Rn&&ks(this.attrs,e.attrs)&&ks(this.spec,e.spec)}static is(e){return e.type instanceof Rn}destroy(){}}let yC=class y0{constructor(e,t){this.attrs=e,this.spec=t||ai}map(e,t,n,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let o=e.mapResult(t.to+r,-1);return o.deleted||o.pos<=s.pos?null:new Ln(s.pos-n,o.pos-n,this)}valid(e,t,n){let r=n.nodeAt(t.from);return!!r&&!r.isText&&t.from+r.nodeSize==t.to}eq(e){return this==e||e instanceof y0&&ks(this.attrs,e.attrs)&&ks(this.spec,e.spec)}destroy(){}},Ln=class Hr{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Hr(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,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new Hr(e,e,new Ed(t,n))}static inline(e,t,n,r){return new Hr(e,t,new Rn(n,r))}static node(e,t,n,r){return new Hr(e,t,new yC(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Rn}get widget(){return this.type instanceof Ed}};const Pi=[],ai={};class de{constructor(e,t){this.local=e.length?e:Pi,this.children=t.length?t:Pi}static create(e,t){return t.length?ul(t,e,0,ai):De}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+r,l.to+r))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,r+l,s)}}map(e,t,n){return this==De||e.maps.length==0?this:this.mapInner(e,t,0,0,n||ai)}mapInner(e,t,n,r,s){let o;if(this.local.length){let l=new Ph(t.content);for(let a=0;a<this.local.length;a++){let h=this.local[a].map(e,n,r);h&&h.type.valid(t,h,l)?(o||(o=[])).push(h):s.onRemove&&s.onRemove(this.local[a].spec)}}return this.children.length?bC(this.children,o||[],e,t,n,r,s):o?new de(o.sort(hi),Pi):De}add(e,t){return t.length?this==De?de.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,s=0;e.forEach((l,a)=>{let h=a+n,c;if(c=k0(t,l,h)){for(r||(r=this.children.slice());s<r.length&&r[s]<a;)s+=3;r[s]==a?r[s+2]=r[s+2].addInner(l,c,h+1):r.splice(s,0,a,a+l.nodeSize,ul(c,l,h+1,ai)),s+=3}});let o=b0(s?x0(t):t,-n);if(o.length){let l=new Ph(e.content);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a],l)||o.splice(a--,1)}return new de(o.length?this.local.concat(o).sort(hi):this.local,r||this.children)}remove(e){return e.length==0||this==De?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let s=0;s<n.length;s+=3){let o,l=n[s]+t,a=n[s+1]+t;for(let c=0,f;c<e.length;c++)(f=e[c])&&f.from>l&&f.to<a&&(e[c]=null,(o||(o=[])).push(f));if(!o)continue;n==this.children&&(n=this.children.slice());let h=n[s+2].removeInner(o,l+1);h!=De?n[s+2]=h:(n.splice(s,3),s-=3)}if(r.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<r.length;l++)r[l].eq(o,t)&&(r==this.local&&(r=this.local.slice()),r.splice(l--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new de(r,n):De}forChild(e,t){if(this==De)return this;if(t.isLeaf)return de.empty;let n,r;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof Rn){let h=Math.max(s,a.from)-s,c=Math.min(o,a.to)-s;h<c&&(r||(r=[])).push(a.copy(h,c))}}if(r){let l=new de(r.sort(hi),Pi);return n?new Cn([l,n]):l}return n||De}eq(e){if(this==e)return!0;if(!(e instanceof de)||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 Xc(this.localsInner(e))}localsInner(e){if(this==De)return Pi;if(e.inlineContent||!this.local.some(Rn.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Rn||t.push(this.local[n]);return t}forEachSet(e){e(this)}}de.empty=new de([],[]);de.removeOverlap=Xc;const De=de.empty;class Cn{constructor(e){this.members=e}map(e,t){const n=this.members.map(r=>r.map(e,t,ai));return Cn.from(n)}forChild(e,t){if(t.isLeaf)return de.empty;let n=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=De&&(s instanceof Cn?n=n.concat(s.members):n.push(s))}return Cn.from(n)}eq(e){if(!(e instanceof Cn)||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,n=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(!t)t=s;else{n&&(t=t.slice(),n=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?Xc(n?t:t.sort(hi)):Pi}static from(e){switch(e.length){case 0:return De;case 1:return e[0];default:return new Cn(e.every(t=>t instanceof de)?e:e.reduce((t,n)=>t.concat(n instanceof de?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function bC(i,e,t,n,r,s,o){let l=i.slice();for(let h=0,c=s;h<t.maps.length;h++){let f=0;t.maps[h].forEach((u,d,p,m)=>{let g=m-p-(d-u);for(let y=0;y<l.length;y+=3){let b=l[y+1];if(b<0||u>b+c-f)continue;let k=l[y]+c-f;d>=k?l[y+1]=u<=k?-2:-1:u>=c&&g&&(l[y]+=g,l[y+1]+=g)}f+=g}),c=t.maps[h].map(c,-1)}let a=!1;for(let h=0;h<l.length;h+=3)if(l[h+1]<0){if(l[h+1]==-2){a=!0,l[h+1]=-1;continue}let c=t.map(i[h]+s),f=c-r;if(f<0||f>=n.content.size){a=!0;continue}let u=t.map(i[h+1]+s,-1),d=u-r,{index:p,offset:m}=n.content.findIndex(f),g=n.maybeChild(p);if(g&&m==f&&m+g.nodeSize==d){let y=l[h+2].mapInner(t,g,c+1,i[h]+s+1,o);y!=De?(l[h]=f,l[h+1]=d,l[h+2]=y):(l[h+1]=-2,a=!0)}else a=!0}if(a){let h=kC(l,i,e,t,r,s,o),c=ul(h,n,0,o);e=c.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,u=0;f<c.children.length;f+=3){let d=c.children[f];for(;u<l.length&&l[u]<d;)u+=3;l.splice(u,0,c.children[f],c.children[f+1],c.children[f+2])}}return new de(e.sort(hi),l)}function b0(i,e){if(!e||!i.length)return i;let t=[];for(let n=0;n<i.length;n++){let r=i[n];t.push(new Ln(r.from+e,r.to+e,r.type))}return t}function kC(i,e,t,n,r,s,o){function l(a,h){for(let c=0;c<a.local.length;c++){let f=a.local[c].map(n,r,h);f?t.push(f):o.onRemove&&o.onRemove(a.local[c].spec)}for(let c=0;c<a.children.length;c+=3)l(a.children[c+2],a.children[c]+h+1)}for(let a=0;a<i.length;a+=3)i[a+1]==-1&&l(i[a+2],e[a]+s+1);return t}function k0(i,e,t){if(e.isLeaf)return null;let n=t+e.nodeSize,r=null;for(let s=0,o;s<i.length;s++)(o=i[s])&&o.from>t&&o.to<n&&((r||(r=[])).push(o),i[s]=null);return r}function x0(i){let e=[];for(let t=0;t<i.length;t++)i[t]!=null&&e.push(i[t]);return e}function ul(i,e,t,n){let r=[],s=!1;e.forEach((l,a)=>{let h=k0(i,l,a+t);if(h){s=!0;let c=ul(h,l,t+a+1,n);c!=De&&r.push(a,a+l.nodeSize,c)}});let o=b0(s?x0(i):i,-t).sort(hi);if(o.length){let l=new Ph(e.content);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a],l)||(n.onRemove&&n.onRemove(o[a].spec),o.splice(a--,1))}return o.length||r.length?new de(o,r):De}function hi(i,e){return i.from-e.from||i.to-e.to}function Xc(i){let e=i;for(let t=0;t<e.length-1;t++){let n=e[t];if(n.from!=n.to)for(let r=t+1;r<e.length;r++){let s=e[r];if(s.from==n.from){s.to!=n.to&&(e==i&&(e=i.slice()),e[r]=s.copy(s.from,n.to),Rd(e,r+1,s.copy(n.to,s.to)));continue}else{s.from<n.to&&(e==i&&(e=i.slice()),e[t]=n.copy(n.from,s.from),Rd(e,r,n.copy(s.from,n.to)));break}}}return e}function Rd(i,e,t){for(;e<i.length&&hi(t,i[e])>0;)e++;i.splice(e,0,t)}function Ma(i){let e=[];return i.someProp("decorations",t=>{let n=t(i.state);n&&n!=De&&e.push(n)}),i.cursorWrapper&&e.push(de.create(i.state.doc,[i.cursorWrapper.deco])),Cn.from(e)}const xC={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wC=et&&Dn<=11;class SC{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}}let CC=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new SC,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let r=0;r<n.length;r++)this.queue.push(n[r]);et&&Dn<=11&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():Le&&e.composing&&n.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),wC&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.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,xC)),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(Md(this.view)){if(this.suppressingSelectionUpdates)return sn(this.view);if(et&&Dn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&bi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let s=e.focusNode;s;s=lr(s))t.add(s);for(let s=e.anchorNode;s;s=lr(s))if(t.has(s)){n=s;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:ge(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n,r=!1;!this.suppressingSelectionUpdates&&Md(e)&&(n=e.domSelectionRange(),r=!this.currentSelection.eq(n)&&!this.ignoreSelectionChange(n));let s=-1,o=-1,l=!1,a=[];if(e.editable)for(let c=0;c<t.length;c++){let f=this.registerMutation(t[c],a);f&&(s=s<0?f.from:Math.min(f.from,s),o=o<0?f.to:Math.max(f.to,o),f.typeOver&&(l=!0))}if(a.some(c=>c.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||Oe&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(c=>c.type=="childList"&&c.removedNodes.length))){for(let c of a)if(c.nodeName=="BR"&&c.parentNode){let f=c.nextSibling;for(;f&&B(f);){if(f.contentEditable=="false"){c.parentNode.removeChild(c);break}f=f.firstChild}}}else if(ot&&a.length){let c=a.filter(f=>f.nodeName=="BR");if(c.length==2){let[f,u]=c;f.parentNode&&f.parentNode.parentNode==u.parentNode?u.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let u of c){let d=u.parentNode;d&&d.nodeName=="LI"&&(!f||AC(e,f)!=d)&&u.remove()}}}let h=null;s<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Kl(n)&&(h=jc(e))&&h.eq(_.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,sn(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,o),vC(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,OC(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):n&&!this.currentSelection.eq(n)&&sn(e),n&&this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;c<e.addedNodes.length;c++){let f=e.addedNodes[c];t.push(f),ge(f)&&(this.lastChangedTextNode=f)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,s=e.nextSibling;if(et&&Dn<=11&&e.addedNodes.length)for(let c=0;c<e.addedNodes.length;c++){let{previousSibling:f,nextSibling:u}=e.addedNodes[c];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(r=f),(!u||Array.prototype.indexOf.call(e.addedNodes,u)<0)&&(s=u)}let o=r&&r.parentNode==e.target?Me(r)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?Me(s):e.target.childNodes.length,h=n.localPosFromDOM(e.target,a,1);return{from:l,to:h}}else return e.type=="attributes"?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},Bd=new WeakMap,Pd=!1;function vC(i){if(!Bd.has(i)&&(Bd.set(i,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(i.dom).whiteSpace)!==-1)){if(i.requiresGeckoHackNode=ot,Pd)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."),Pd=!0}}function Ld(i,e){let t=e.startContainer,n=e.startOffset,r=e.endContainer,s=e.endOffset,o=i.domAtPos(i.state.selection.anchor);return bi(o.node,o.offset,r,s)&&([t,n,r,s]=[r,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}}function MC(i,e){if(e.getComposedRanges){let r=e.getComposedRanges(i.root)[0];if(r)return Ld(i,r)}let t;function n(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return i.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),i.dom.removeEventListener("beforeinput",n,!0),t?Ld(i,t):null}function AC(i,e){for(let t=e.parentNode;t&&t!=i.dom;t=t.parentNode){let n=i.docView.nearestDesc(t,!0);if(n&&n.node.isBlock)return t}return null}function OC(i,e){var t;let{focusNode:n,focusOffset:r}=i.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||!B(a)||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),n==s&&i.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function TC(i,e,t,n){let{node:r,fromOffset:s,toOffset:o,from:l,to:a}=i.docView.parseRange(e,t),h=i.domSelectionRange(),c,f=h.anchorNode;if(f&&ki(i.dom,f)&&(c=[{node:f,offset:h.anchorOffset}],Kl(h)||c.push({node:h.focusNode,offset:h.focusOffset})),Oe&&i.input.lastKeyCode===8)for(let y=o;y>s;y--){let b=r.childNodes[y-1],k=b.pmViewDesc;if(b.nodeName=="BR"&&!k){o=y;break}if(!k||k.size)break}let u=i.state.doc,d=i.someProp("domParser")||rr.fromSchema(i.state.schema),p=u.resolve(l),m=null,g=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:s,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:NC(n),context:p});if(c&&c[0].pos!=null){let y=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=y),m={anchor:y+l,head:b+l}}return{doc:g,sel:m,from:l,to:a}}const NC=i=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(i);if(e.nodeName=="BR"&&e.parentNode){if(Le&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(e.parentNode.lastChild==e||Le&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},DC=/^(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 IC(i,e,t,n,r){let s=i.input.compositionPendingChanges||(i.composing?i.input.compositionID:0);if(i.input.compositionPendingChanges=0,e<0){let C=i.input.lastSelectionTime>Date.now()-50?i.input.lastSelectionOrigin:null,I=jc(i,C);if(I&&!i.state.selection.eq(I)){if(Oe&&nn&&i.input.lastKeyCode===13&&Date.now()-100<i.input.lastKeyCodeTime&&Sn(i,"Enter"))return;let P=i.state.tr.setSelection(I);C=="pointer"?P.setMeta("pointer",!0):C=="key"&&P.scrollIntoView(),s&&P.setMeta("composition",s),i.dispatch(P)}return}let o=i.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=i.state.doc.resolve(t).after(l+1);let a=i.state.selection,h=TC(i,e,t,r),c=i.state.doc,f=c.slice(h.from,h.to),u,d;i.input.lastKeyCode===8&&Date.now()-100<i.input.lastKeyCodeTime?(u=i.state.selection.to,d="end"):(u=i.state.selection.from,d="start"),i.input.lastKeyCode=null;let p=PC(f.content,h.doc.content,h.from,u,d);if(p&&i.input.domChangeCount++,(ar&&i.input.lastIOSEnter>Date.now()-225||nn)&&r.some(C=>B(C)&&!DC.test(C.nodeName))&&(!p||p.endA>=p.endB)&&Sn(i,"Enter")){i.input.lastIOSEnter=0;return}if(!p)if(n&&a instanceof K&&!a.empty&&a.$head.sameParent(a.$anchor)&&!i.composing&&!(h.sel&&h.sel.anchor!=h.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(h.sel){let C=Fd(i,i.state.doc,h.sel);if(C&&!C.eq(i.state.selection)){let I=i.state.tr.setSelection(C);s&&I.setMeta("composition",s),i.dispatch(I)}}return}i.state.selection.from<i.state.selection.to&&p.start==p.endB&&i.state.selection instanceof K&&(p.start>i.state.selection.from&&p.start<=i.state.selection.from+2&&i.state.selection.from>=h.from?p.start=i.state.selection.from:p.endA<i.state.selection.to&&p.endA>=i.state.selection.to-2&&i.state.selection.to<=h.to&&(p.endB+=i.state.selection.to-p.endA,p.endA=i.state.selection.to)),et&&Dn<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>h.from&&h.doc.textBetween(p.start-h.from-1,p.start-h.from+1)==" "&&(p.start--,p.endA--,p.endB--);let m=h.doc.resolveNoCache(p.start-h.from),g=h.doc.resolveNoCache(p.endB-h.from),y=c.resolve(p.start),b=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA;if((ar&&i.input.lastIOSEnter>Date.now()-225&&(!b||r.some(C=>C.nodeName=="DIV"||C.nodeName=="P"))||!b&&BC(h.doc,m.pos,g.pos))&&Sn(i,"Enter")){i.input.lastIOSEnter=0;return}if(i.state.selection.anchor>p.start&&(b?p.endA>p.start&&p.endB==p.start:RC(c,p.start,p.endA,m,g))&&Sn(i,"Backspace")){nn&&Oe&&i.domObserver.suppressSelectionUpdates();return}Oe&&p.endB==p.start&&(i.input.lastChromeDelete=Date.now()),nn&&!b&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&h.sel&&h.sel.anchor==h.sel.head&&h.sel.head==p.endA&&(p.endB-=2,g=h.doc.resolveNoCache(p.endB-h.from),setTimeout(()=>Sn(i,"Enter"),20));let k=p.start,O=p.endA,w=C=>{let I=C||i.state.tr.replace(k,O,h.doc.slice(p.start-h.from,p.endB-h.from));if(h.sel){let P=Fd(i,I.doc,h.sel);P&&!(Oe&&i.composing&&P.empty&&(p.start!=p.endB||i.input.lastChromeDelete<Date.now()-100)&&(P.head==k||P.head==I.mapping.map(O)-1)||et&&P.empty&&P.head==k)&&I.setSelection(P)}return s&&I.setMeta("composition",s),I.scrollIntoView()},M;if(b)if(m.pos==g.pos){et&&Dn<=11&&m.parentOffset==0&&(i.domObserver.suppressSelectionUpdates(),setTimeout(()=>sn(i),20));let C=w(i.state.tr.delete(k,O)),I=c.resolve(p.start).marksAcross(c.resolve(p.endA));I&&C.ensureMarks(I),i.dispatch(C)}else if(p.endA==p.endB&&(M=EC(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start())))){let C=w(i.state.tr);M.type=="add"?C.addMark(k,O,M.mark):C.removeMark(k,O,M.mark),i.dispatch(C)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let C=m.parent.textBetween(m.parentOffset,g.parentOffset),I=()=>w(i.state.tr.insertText(C,k,O));i.someProp("handleTextInput",P=>P(i,k,O,C,I))||i.dispatch(I())}else i.dispatch(w());else i.dispatch(w())}function Fd(i,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Jc(i,e.resolve(t.anchor),e.resolve(t.head))}function EC(i,e){let t=i.firstChild.marks,n=e.firstChild.marks,r=t,s=n,o,l,a;for(let c=0;c<n.length;c++)r=n[c].removeFromSet(r);for(let c=0;c<t.length;c++)s=t[c].removeFromSet(s);if(r.length==1&&s.length==0)l=r[0],o="add",a=c=>c.mark(l.addToSet(c.marks));else if(r.length==0&&s.length==1)l=s[0],o="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let h=[];for(let c=0;c<e.childCount;c++)h.push(a(e.child(c)));if(A.from(h).eq(i))return{mark:l,type:o}}function RC(i,e,t,n,r){if(t-e<=r.pos-n.pos||Aa(n,!0,!1)<r.pos)return!1;let s=i.resolve(e);if(!n.parent.inlineContent){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=i.resolve(Aa(s,!0,!0));return!o.parent.isTextblock||o.pos>t||Aa(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function BC(i,e,t){let n=0,r=0;return i.nodesBetween(e,t,(s,o)=>{s.isTextblock&&o>=e&&o<t?n++:(s.isText?/\S/.test(s.text.slice(Math.max(0,e-o),Math.min(s.nodeSize,t-o))):s.isLeaf)&&r++}),r==0&&n==1}function Aa(i,e,t){let n=i.depth,r=e?i.end():i.pos;for(;n>0&&(e||i.indexAfter(n)==i.node(n).childCount);)n--,r++,e=!1;if(t){let s=i.node(n).maybeChild(i.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,r++}return r}function PC(i,e,t,n,r){let s=i.findDiffStart(e,t),o=t+i.size,l=t+e.size;if(s==null)return null;let{a,b:h}=i.findDiffEnd(e,o,l);if(r=="end"){let c=Math.max(0,s-Math.min(a,h));n-=a+c-s}if(a<s&&o<l){let c=n<=s&&n>=a?s-n:0;s-=c,h=s+(h-a),a=s}else if(h<s){let c=n<=s&&n>=h?s-n:0;s-=c,a=s+(a-h),h=s}return{start:s,endA:a,endB:h}}let w0=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 GS,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach($d),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=Hd(this),Vd(this),this.nodeViews=Wd(this),this.docView=kd(this.state.doc,zd(this),Ma(this),this.dom,this),this.domObserver=new CC(this,(n,r,s,o)=>IC(this,n,r,s,o)),this.domObserver.start(),YS(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&&Bh(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach($d),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let r=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(u0(this),o=!0),this.state=e;let l=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let d=Wd(this);FC(d,this.nodeViews)&&(this.nodeViews=d,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Bh(this),this.editable=Hd(this),Vd(this);let a=Ma(this),h=zd(this),c=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,h,a);(f||!e.selection.eq(r.selection))&&(o=!0);let u=c=="preserve"&&o&&this.dom.style.overflowAnchor==null&&cS(this);if(o){this.domObserver.stop();let d=f&&(et||Oe)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&LC(r.selection,e.selection);if(f){let m=Oe?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=fC(this)),(s||!this.docView.update(e.doc,h,a,this))&&(this.docView.updateOuterDeco(h),this.docView.destroy(),this.docView=kd(e.doc,h,a,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(d=!0)}let p=this.input.mouseDown;d||!(p&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&BS(this)&&p.delaySelUpdate())?sn(this,d):(Qg(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((n=this.dragging)===null||n===void 0)&&n.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():u&&fS(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!ki(this.dom,e))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof z){let t=this.docView.domAfterPos(this.state.selection.from);B(t)&&pd(this,t.getBoundingClientRect(),e)}else pd(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 n=this.directPlugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let n=this.state.plugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let s=n.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==n.node&&(r=s)}this.dragging=new p0(e.slice,e.move,r<0?void 0:z.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(r=t?t(l):l))return r}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(r=t?t(l):l))return r}}hasFocus(){if(et){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&&uS(this.dom),sn(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 yS(this,e)}coordsAtPos(e,t=1){return qg(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return SS(this,t||this.state,e)}pasteHTML(e,t){return bs(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return bs(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return _c(this,e)}destroy(){this.docView&&(XS(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ma(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Zw())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ZS(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?Le&&this.root.nodeType===11&&sS(this.dom.ownerDocument)==this.dom&&MC(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};w0.prototype.dispatch=function(i){let e=this._props.dispatchTransaction;e?e.call(this,i):this.updateState(this.state.apply(i))};function zd(i){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(i.editable),i.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(i.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[Ln.node(0,i.state.doc.content.size,e)]}function Vd(i){if(i.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),i.cursorWrapper={dom:e,deco:Ln.widget(i.state.selection.from,e,{raw:!0,marks:i.markCursor})}}else i.cursorWrapper=null}function Hd(i){return!i.someProp("editable",e=>e(i.state)===!1)}function LC(i,e){let t=Math.min(i.$anchor.sharedDepth(i.head),e.$anchor.sharedDepth(e.head));return i.$anchor.start(t)!=e.$anchor.start(t)}function Wd(i){let e=Object.create(null);function t(n){for(let r in n)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=n[r])}return i.someProp("nodeViews",t),i.someProp("markViews",t),e}function FC(i,e){let t=0,n=0;for(let r in i){if(i[r]!=e[r])return!0;t++}for(let r in e)n++;return t!=n}function $d(i){if(i.spec.state||i.spec.filterTransaction||i.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function dn(i,e){return i.meta={package:"@milkdown/core",group:"System",...e},i}var S0={text:(i,e,t,n)=>{const r=i.value;return/^[^*_\\]*\s+$/.test(r)?r:t.safe(r,{...n,encode:[]})},strong:(i,e,t,n)=>{const r=i.marker||t.options.strong||"*",s=t.enter("strong"),o=t.createTracker(n);let l=o.move(r+r);return l+=o.move(t.containerPhrasing(i,{before:l,after:r,...o.current()})),l+=o.move(r+r),s(),l},emphasis:(i,e,t,n)=>{const r=i.marker||t.options.emphasis||"*",s=t.enter("emphasis"),o=t.createTracker(n);let l=o.move(r);return l+=o.move(t.containerPhrasing(i,{before:l,after:r,...o.current()})),l+=o.move(r),s(),l}},on=q({},"editorView"),Wr=q({},"editorState"),Oa=q([],"initTimer"),Kd=q({},"editor"),xs=q([],"inputRules"),Fn=q([],"prosePlugins"),ws=q([],"remarkPlugins"),Ss=q([],"nodeView"),Cs=q([],"markView"),ci=q(ch().use(fh).use(xh),"remark"),Xr=q({handlers:S0,encode:[]},"remarkStringifyOptions"),Ko=Ut("ConfigReady");function zC(i){const e=t=>(t.record(Ko),async()=>(await i(t),t.done(Ko),()=>{t.clearTimer(Ko)}));return dn(e,{displayName:"Config"}),e}var $i=Ut("InitReady");function VC(i){const e=t=>(t.inject(Kd,i).inject(Fn,[]).inject(ws,[]).inject(xs,[]).inject(Ss,[]).inject(Cs,[]).inject(Xr,{handlers:S0,encode:[]}).inject(ci,ch().use(fh).use(xh)).inject(Oa,[Ko]).record($i),async()=>{await t.waitTimers(Oa);const n=t.get(Xr);return t.set(ci,ch().use(fh).use(xh,n)),t.done($i),()=>{t.remove(Kd).remove(Fn).remove(ws).remove(xs).remove(Ss).remove(Cs).remove(Xr).remove(ci).remove(Oa).clearTimer($i)}});return dn(e,{displayName:"Init"}),e}var We=Ut("SchemaReady"),Ta=q([],"schemaTimer"),jt=q({},"schema"),Qr=q([],"nodes"),Zr=q([],"marks");function qd(i){return{...i,parseDOM:i.parseDOM?.map(e=>({priority:i.priority,...e}))}}var C0=i=>(i.inject(jt,{}).inject(Qr,[]).inject(Zr,[]).inject(Ta,[$i]).record(We),async()=>{await i.waitTimers(Ta);const e=i.get(ci),t=i.get(ws).reduce((o,l)=>o.use(l.plugin,l.options),e);i.set(ci,t);const n=Object.fromEntries(i.get(Qr).map(([o,l])=>[o,qd(l)])),r=Object.fromEntries(i.get(Zr).map(([o,l])=>[o,qd(l)])),s=new tx({nodes:n,marks:r});return i.set(jt,s),i.done(We),()=>{i.remove(jt).remove(Qr).remove(Zr).remove(Ta).clearTimer(We)}});dn(C0,{displayName:"Schema"});var v0=class{constructor(){this.#t=new mg,this.#e=null,this.setCtx=i=>{this.#e=i},this.chain=()=>{if(this.#e==null)throw ba();const i=this.#e,e=[],t=this.get.bind(this),n={run:()=>{const s=xr(...e),o=i.get(on);return s(o.state,o.dispatch,o)},inline:s=>(e.push(s),n),pipe:r.bind(this)};function r(s,o){const l=t(s);return e.push(l(o)),n}return n}}#t;#e;get ctx(){return this.#e}create(i,e){const t=i.create(this.#t.sliceMap);return t.set(e),t}get(i){return this.#t.get(i).get()}remove(i){return this.#t.remove(i)}call(i,e){if(this.#e==null)throw ba();const t=this.get(i)(e),n=this.#e.get(on);return t(n.state,n.dispatch,n)}inline(i){if(this.#e==null)throw ba();const e=this.#e.get(on);return i(e.state,e.dispatch,e)}};function HC(i="cmdKey"){return q((()=>()=>!1),i)}var le=q(new v0,"commands"),Na=q([We],"commandsTimer"),es=Ut("CommandsReady"),M0=i=>{const e=new v0;return e.setCtx(i),i.inject(le,e).inject(Na,[We]).record(es),async()=>(await i.waitTimers(Na),i.done(es),()=>{i.remove(le).remove(Na).clearTimer(es)})};dn(M0,{displayName:"Commands"});function WC(i){return i.Backspace=xr(xw,zc,tw,kg),i}var A0=class{constructor(){this.#t=null,this.#e=[],this.setCtx=i=>{this.#t=i},this.add=i=>(this.#e.push(i),()=>{this.#e=this.#e.filter(e=>e!==i)}),this.addObjectKeymap=i=>{const e=[];return Object.entries(i).forEach(([t,n])=>{if(typeof n=="function"){const r={key:t,onRun:()=>n};this.#e.push(r),e.push(()=>{this.#e=this.#e.filter(s=>s!==r)})}else this.#e.push(n),e.push(()=>{this.#e=this.#e.filter(r=>r!==n)})}),()=>{e.forEach(t=>t())}},this.addBaseKeymap=()=>{const i=WC(bw);return this.addObjectKeymap(i)},this.build=()=>{const i={};return this.#e.forEach(e=>{i[e.key]=[...i[e.key]||[],e]}),Object.fromEntries(Object.entries(i).map(([e,t])=>{const n=t.sort((s,o)=>(o.priority??50)-(s.priority??50));return[e,(s,o,l)=>{const a=this.#t;if(a==null)throw Hl();const h=n.map(c=>c.onRun(a));return xr(...h)(s,o,l)}]}))}}#t;#e;get ctx(){return this.#t}},dl=q(new A0,"keymap"),Da=q([We],"keymapTimer"),ts=Ut("KeymapReady"),$C=i=>{const e=new A0;return e.setCtx(i),i.inject(dl,e).inject(Da,[We]).record(ts),async()=>(await i.waitTimers(Da),i.done(ts),()=>{i.remove(dl).remove(Da).clearTimer(ts)})},qo=Ut("ParserReady"),O0=(()=>{throw Hl()}),ns=q(O0,"parser"),Ia=q([],"parserTimer"),T0=i=>(i.inject(ns,O0).inject(Ia,[We]).record(qo),async()=>{await i.waitTimers(Ia);const e=i.get(ci),t=i.get(jt);return i.set(ns,Yw.create(t,e)),i.done(qo),()=>{i.remove(ns).remove(Ia).clearTimer(qo)}});dn(T0,{displayName:"Parser"});var jo=Ut("SerializerReady"),Ea=q([],"serializerTimer"),N0=(()=>{throw Hl()}),Jo=q(N0,"serializer"),D0=i=>(i.inject(Jo,N0).inject(Ea,[We]).record(jo),async()=>{await i.waitTimers(Ea);const e=i.get(ci),t=i.get(jt);return i.set(Jo,Qw.create(t,e)),i.done(jo),()=>{i.remove(Jo).remove(Ea).clearTimer(jo)}});dn(D0,{displayName:"Serializer"});var Ra=q("","defaultValue"),_o=q(i=>i,"stateOptions"),Ba=q([],"editorStateTimer"),Uo=Ut("EditorStateReady");function KC(i,e,t){if(typeof i=="string")return e(i);if(i.type==="html")return rr.fromSchema(t).parse(i.dom);if(i.type==="json")return yt.fromJSON(t,i.value);throw Vx(i)}var qC=new Kn("MILKDOWN_STATE_TRACKER"),I0=i=>(i.inject(Ra,"").inject(Wr,{}).inject(_o,e=>e).inject(Ba,[qo,jo,es,ts]).record(Uo),async()=>{await i.waitTimers(Ba);const e=i.get(jt),t=i.get(ns),n=i.get(xs),r=i.get(_o),s=i.get(Fn),o=KC(i.get(Ra),t,e),l=i.get(dl),a=l.addBaseKeymap(),h=[...s,new un({key:qC,state:{init:()=>{},apply:(u,d,p,m)=>{i.set(Wr,m)}}}),Ow({rules:n}),_w(l.build())];i.set(Fn,h);const c=r({schema:e,doc:o,plugins:h}),f=cg.create(c);return i.set(Wr,f),i.done(Uo),()=>{a(),i.remove(Ra).remove(Wr).remove(_o).remove(Ba).clearTimer(Uo)}});dn(I0,{displayName:"EditorState"});var vs=q([],"pasteRule"),Pa=q([We],"pasteRuleTimer"),Go=Ut("PasteRuleReady"),E0=i=>(i.inject(vs,[]).inject(Pa,[We]).record(Go),async()=>(await i.waitTimers(Pa),i.done(Go),()=>{i.remove(vs).remove(Pa).clearTimer(Go)}));dn(E0,{displayName:"PasteRule"});var La=Ut("EditorViewReady"),Fa=q([],"editorViewTimer"),za=q({},"editorViewOptions"),Va=q(null,"root"),Lh=q(null,"rootDOM"),Fh=q({},"rootAttrs");function jC(i,e){const t=document.createElement("div");t.className="milkdown",i.appendChild(t),e.set(Lh,t);const n=e.get(Fh);return Object.entries(n).forEach(([r,s])=>t.setAttribute(r,s)),t}function JC(i){i.classList.add("editor"),i.setAttribute("role","textbox")}var _C=new Kn("MILKDOWN_VIEW_CLEAR"),R0=i=>(i.inject(Va,document.body).inject(on,{}).inject(za,{}).inject(Lh,null).inject(Fh,{}).inject(Fa,[Uo,Go]).record(La),async()=>{await i.wait($i);const e=i.get(Va)||document.body,t=typeof e=="string"?document.querySelector(e):e;i.update(Fn,a=>[new un({key:_C,view:h=>{const c=t?jC(t,i):void 0;return(()=>{if(c&&t){const u=h.dom;t.replaceChild(c,u),c.appendChild(u)}})(),{destroy:()=>{c?.parentNode&&c?.parentNode.replaceChild(h.dom,c),c?.remove()}}}}),...a]),await i.waitTimers(Fa);const n=i.get(Wr),r=i.get(za),s=Object.fromEntries(i.get(Ss)),o=Object.fromEntries(i.get(Cs)),l=new w0(t,{state:n,nodeViews:s,markViews:o,transformPasted:(a,h,c)=>(i.get(vs).sort((f,u)=>(u.priority??50)-(f.priority??50)).map(f=>f.run).forEach(f=>{a=f(a,h,c)}),a),...r});return JC(l.dom),i.set(on,l),i.done(La),()=>{l?.destroy(),i.remove(Va).remove(on).remove(za).remove(Lh).remove(Fh).remove(Fa).clearTimer(La)}});dn(R0,{displayName:"EditorView"});var dI=(function(i){return i.Idle="Idle",i.OnCreate="OnCreate",i.Created="Created",i.OnDestroy="OnDestroy",i.Destroyed="Destroyed",i})({}),pI=class B0{constructor(){this.#t=!1,this.#e="Idle",this.#i=[],this.#n=()=>{},this.#s=new mg,this.#o=new Qx,this.#r=new Map,this.#l=new Map,this.#a=new Xx(this.#s,this.#o),this.#d=()=>{const e=zC(async n=>{await Promise.all(this.#i.map(r=>Promise.resolve(r(n))))}),t=[C0,T0,D0,M0,$C,E0,I0,R0,VC(this),e];this.#c(t,this.#l)},this.#c=(e,t)=>{e.forEach(n=>{const r=this.#a.produce(this.#t?n.meta:void 0),s=n(r);t.set(n,{ctx:r,handler:s,cleanup:void 0})})},this.#f=(e,t=!1)=>Promise.all([e].flat().map(async n=>{const r=this.#r.get(n)?.cleanup;return t?this.#r.delete(n):this.#r.set(n,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof r=="function"?r():r})),this.#p=async()=>{await Promise.all([...this.#l.entries()].map(async([e,{cleanup:t}])=>typeof t=="function"?t():t)),this.#l.clear()},this.#h=e=>{this.#e=e,this.#n(e)},this.#u=e=>[...e.entries()].map(async([t,n])=>{const{ctx:r,handler:s}=n;if(!s)return;const o=await s();e.set(t,{ctx:r,handler:s,cleanup:o})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#i.push(e),this),this.removeConfig=e=>(this.#i=this.#i.filter(t=>t!==e),this),this.use=e=>{const t=[e].flat();return t.flat().forEach(n=>{this.#r.set(n,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(t,this.#r),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.#f([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#h("OnCreate"),this.#d(),this.#c([...this.#r.keys()],this.#r),await Promise.all([this.#u(this.#l),this.#u(this.#r)].flat()),this.#h("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.#i=[]),this.#h("OnDestroy"),await this.#f([...this.#r.keys()],e),await this.#p(),this.#h("Destroyed"),this),this.action=e=>e(this.#a),this.inspect=()=>this.#t?[...this.#l.values(),...this.#r.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 B0}#t;#e;#i;#n;#s;#o;#r;#l;#a;#d;#c;#f;#p;#h;#u;get ctx(){return this.#a}get status(){return this.#e}};function P0(i,e,t){const n=i.findIndex(([s])=>s===e);if(n===-1)return[...i,t];const r=i.slice();return r[n]=t,r}function ee(i,e){const t=HC(i),n=r=>async()=>{n.key=t,await r.wait(es);const s=e(r);return r.get(le).create(t,s),n.run=o=>r.get(le).call(i,o),()=>{r.get(le).remove(t)}};return n}function Ot(i){const e=t=>async()=>{await t.wait(We);const n=i(t);return t.update(xs,r=>[...r,n]),e.inputRule=n,()=>{t.update(xs,r=>r.filter(s=>s!==n))}};return e}function mI(i){const e=t=>async()=>{await t.wait(We);const n=i(t);return t.update(vs,r=>[...r,n]),e.pasteRule=n,()=>{t.update(vs,r=>r.filter(s=>s!==n))}};return e}function UC(i,e){const t=n=>async()=>{const r=e(n);return n.update(Zr,s=>P0(s,i,[i,r])),t.id=i,t.schema=r,()=>{n.update(Zr,s=>s.filter(([o])=>o!==i))}};return t.type=n=>{const r=n.get(jt).marks[i];if(!r)throw _x(i);return r},t}function Qc(i,e){const t=n=>async()=>{const r=e(n);return n.update(Qr,s=>P0(s,i,[i,r])),t.id=i,t.schema=r,()=>{n.update(Qr,s=>s.filter(([o])=>o!==i))}};return t.type=n=>{const r=n.get(jt).nodes[i];if(!r)throw Jx(i);return r},t}function eo(i){let e;const t=n=>async()=>(await n.wait(We),e=i(n),n.update(Fn,r=>[...r,e]),()=>{n.update(Fn,r=>r.filter(s=>s!==e))});return t.plugin=()=>e,t.key=()=>e.spec.key,t}function GC(i){const e=t=>async()=>{await t.wait(ts);const n=t.get(dl),r=i(t),s=n.addObjectKeymap(r);return e.keymap=r,()=>{s()}};return e}function gI(i,e){const t=n=>async()=>{await n.wait(We);const r=e(n);return i.type(n)instanceof us?n.update(Ss,s=>[...s,[i.id,r]]):n.update(Cs,s=>[...s,[i.id,r]]),t.view=r,t.type=i,()=>{i.type(n)instanceof us?n.update(Ss,s=>s.filter(o=>o[0]!==i.id)):n.update(Cs,s=>s.filter(o=>o[0]!==i.id))}};return t}function pn(i,e){const t=q(i,e),n=r=>(r.inject(t),()=>()=>{r.remove(t)});return n.key=t,n}function xt(i,e){const t=pn(e,i),n=Qc(i,s=>s.get(t.key)(s)),r=[t,n];return r.id=n.id,r.node=n,r.type=s=>n.type(s),r.ctx=t,r.key=t.key,r.extendSchema=s=>xt(i,s(e)),r}function to(i,e){const t=pn(e,i),n=UC(i,s=>s.get(t.key)(s)),r=[t,n];return r.id=n.id,r.mark=n,r.type=s=>n.type(s),r.ctx=t,r.key=t.key,r.extendSchema=s=>to(i,s(e)),r}function Tt(i,e){const t=pn(Object.fromEntries(Object.entries(e).map(([s,{shortcuts:o,priority:l}])=>[s,{shortcuts:o,priority:l}])),`${i}Keymap`),n=GC(s=>{const o=s.get(t.key),l=Object.entries(e).flatMap(([a,{command:h}])=>{const c=o[a],f=[c.shortcuts].flat(),u=c.priority;return f.map(d=>[d,{key:d,onRun:h,priority:u}])});return Object.fromEntries(l)}),r=[t,n];return r.ctx=t,r.shortcuts=n,r.key=t.key,r.keymap=n.keymap,r}var Nt=(i,e=()=>({}))=>pn(e,`${i}Attr`),Jl=(i,e=()=>({}))=>pn(e,`${i}Attr`);function wr(i,e,t){const n=pn({},i),r=o=>async()=>{await o.wait($i);const l={plugin:e(o),options:o.get(n.key)};return o.update(ws,a=>[...a,l]),()=>{o.update(ws,a=>a.filter(h=>h!==l))}},s=[n,r];return s.id=i,s.plugin=r,s.options=n,s}function yI(i){return e=>{const t=e.get(on);return e.get(jt),e.get(Jo)(t.state.doc)}}function bI(i,e=!1){return t=>{const n=t.get(on),r=t.get(ns)(i);if(!r)return;if(!e){const{state:a}=n;return n.dispatch(a.tr.replace(0,a.doc.content.size,new E(r.content,0,0)))}const s=t.get(jt),o=t.get(_o)({schema:s,doc:r,plugins:t.get(Fn)}),l=cg.create(o);n.updateState(l)}}const YC=1024;let XC=0,ft=class{constructor(e,t){this.from=e,this.to=t}};class H{constructor(e={}){this.id=XC++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=je.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}}H.closedBy=new H({deserialize:i=>i.split(" ")});H.openedBy=new H({deserialize:i=>i.split(" ")});H.group=new H({deserialize:i=>i.split(" ")});H.isolate=new H({deserialize:i=>{if(i&&i!="rtl"&&i!="ltr"&&i!="auto")throw new RangeError("Invalid value for isolate: "+i);return i||"auto"}});H.contextHash=new H({perNode:!0});H.lookAhead=new H({perNode:!0});H.mounted=new H({perNode:!0});class Ki{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[H.mounted.id]}}const QC=Object.create(null);class je{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(e){let t=e.props&&e.props.length?Object.create(null):QC,n=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),r=new je(e.name||"",t,e.id,n);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(r)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return r}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(H.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(" "))t[r]=e[n];return n=>{for(let r=n.prop(H.group),s=-1;s<(r?r.length:0);s++){let o=t[s<0?n.name:r[s]];if(o)return o}}}}je.none=new je("",Object.create(null),0,8);class Zc{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let n of this.types){let r=null;for(let s of e){let o=s(n);if(o){r||(r=Object.assign({},n.props));let l=o[1],a=o[0];a.combine&&a.id in r&&(l=a.combine(r[a.id],l)),r[a.id]=l}}t.push(r?new je(n.name,r,n.id,n.flags):n)}return new Zc(t)}}const wo=new WeakMap,jd=new WeakMap;var Q;(function(i){i[i.ExcludeBuffers=1]="ExcludeBuffers",i[i.IncludeAnonymous=2]="IncludeAnonymous",i[i.IgnoreMounts=4]="IgnoreMounts",i[i.IgnoreOverlays=8]="IgnoreOverlays",i[i.EnterBracketed=16]="EnterBracketed"})(Q||(Q={}));class ie{constructor(e,t,n,r,s){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,l]of s)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Ki.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let n of this.children){let r=n.toString();r&&(t&&(t+=","),t+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new pl(this.topNode,e)}cursorAt(e,t=0,n=0){let r=wo.get(this)||this.topNode,s=new pl(r);return s.moveTo(e,t),wo.set(this,s._tree),s}get topNode(){return new Pe(this,0,0,null)}resolve(e,t=0){let n=Ms(wo.get(this)||this.topNode,e,t,!1);return wo.set(this,n),n}resolveInner(e,t=0){let n=Ms(jd.get(this)||this.topNode,e,t,!0);return jd.set(this,n),n}resolveStack(e,t=0){return tv(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:s=this.length}=e,o=e.mode||0,l=(o&Q.IncludeAnonymous)>0;for(let a=this.cursor(o|Q.IncludeAnonymous);;){let h=!1;if(a.from<=s&&a.to>=r&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&n&&(l||!a.type.isAnonymous)&&n(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:nf(je.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new ie(this.type,t,n,r,this.propValues),e.makeTree||((t,n,r)=>new ie(je.none,t,n,r)))}static build(e){return nv(e)}}ie.empty=new ie(je.none,[],[],0);class ef{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new ef(this.buffer,this.index)}}class zn{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return je.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],s=r.name;if(/\W/.test(s)&&!r.isError&&(s=JSON.stringify(s)),e+=4,n==e)return s;let o=[];for(;e<n;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,n,r,s){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(L0(s,r,o[a+1],o[a+2])&&(l=a,n>0));a=o[a+3]);return l}slice(e,t,n){let r=this.buffer,s=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){s[a++]=r[l++],s[a++]=r[l++]-n;let h=s[a++]=r[l++]-n;s[a++]=r[l++]-e,o=Math.max(o,h)}return new zn(s,o,this.set)}}function L0(i,e,t,n){switch(i){case-2:return t<e;case-1:return n>=e&&t<e;case 0:return t<e&&n>e;case 1:return t<=e&&n>e;case 2:return n>e;case 4:return!0}}function Ms(i,e,t,n){for(var r;i.from==i.to||(t<1?i.from>=e:i.from>e)||(t>-1?i.to<=e:i.to<e);){let o=!n&&i instanceof Pe&&i.index<0?null:i.parent;if(!o)return i;i=o}let s=n?0:Q.IgnoreOverlays;if(n)for(let o=i,l=o.parent;l;o=l,l=o.parent)o instanceof Pe&&o.index<0&&((r=l.enter(e,t,s))===null||r===void 0?void 0:r.from)!=o.from&&(i=l);for(;;){let o=i.enter(e,t,s);if(!o)return i;i=o}}class F0{cursor(e=0){return new pl(this,e)}getChild(e,t=null,n=null){let r=Jd(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Jd(this,e,t,n)}resolve(e,t=0){return Ms(this,e,t,!1)}resolveInner(e,t=0){return Ms(this,e,t,!0)}matchContext(e){return zh(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let r=t.lastChild;if(!r||r.to!=t.to)break;r.type.isError&&r.from==r.to?(n=t,t=r.prevSibling):t=r}return n}get node(){return this}get next(){return this.parent}}class Pe extends F0{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,n,r,s=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],f=a[e]+o.from,u;if(!(!(s&Q.EnterBracketed&&c instanceof ie&&(u=Ki.get(c))&&!u.overlay&&u.bracketed&&n>=f&&n<=f+c.length)&&!L0(r,n,f,f+c.length))){if(c instanceof zn){if(s&Q.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,n-f,r);if(d>-1)return new Wt(new ZC(o,c,e,f),null,d)}else if(s&Q.IncludeAnonymous||!c.type.isAnonymous||tf(c)){let d;if(!(s&Q.IgnoreMounts)&&(d=Ki.get(c))&&!d.overlay)return new Pe(d.tree,f,e,o);let p=new Pe(c,f,e,o);return s&Q.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,n,r,s)}}}if(s&Q.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,n=0){let r;if(!(n&Q.IgnoreOverlays)&&(r=Ki.get(this._tree))&&r.overlay){let s=e-this.from,o=n&Q.EnterBracketed&&r.bracketed;for(let{from:l,to:a}of r.overlay)if((t>0||o?l<=s:l<s)&&(t<0||o?a>=s:a>s))return new Pe(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,n)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Jd(i,e,t,n){let r=i.cursor(),s=[];if(!r.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=r.type.is(t),!r.nextSibling())return s}for(;;){if(n!=null&&r.type.is(n))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return n==null?s:[]}}function zh(i,e,t=e.length-1){for(let n=i;t>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[t]&&e[t]!=n.name)return!1;t--}}return!0}class ZC{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}}class Wt extends F0{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(e,t,n){let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,n);return s<0?null:new Wt(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,n=0){if(n&Q.ExcludeBuffers)return null;let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new Wt(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new Wt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new Wt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,s=n.buffer[this.index+3];if(s>r){let o=n.buffer[this.index+1];e.push(n.slice(r,s,o)),t.push(0)}return new ie(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function z0(i){if(!i.length)return null;let e=0,t=i[0];for(let s=1;s<i.length;s++){let o=i[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let n=t instanceof Pe&&t.index<0?null:t.parent,r=i.slice();return n?r[e]=n:r.splice(e,1),new ev(r,t)}class ev{constructor(e,t){this.heads=e,this.node=t}get next(){return z0(this.heads)}}function tv(i,e,t){let n=i.resolveInner(e,t),r=null;for(let s=n instanceof Pe?n:n.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(r||(r=[n])).push(o.resolve(e,t)),s=o}else{let o=Ki.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new Pe(o.tree,o.overlay[0].from+s.from,-1,s);(r||(r=[n])).push(Ms(l,e,t,!1))}}return r?z0(r):n}class pl{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~Q.EnterBracketed,e instanceof Pe)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let n=e._parent;n;n=n._parent)this.stack.unshift(n.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof Pe?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&Q.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Q.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Q.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let r=n<0?0:this.stack[n]+4;if(this.index!=r)return this.yieldBuf(t.findChild(r,this.index,-1,0,4))}else{let r=t.buffer[this.index+3];if(r<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(r)}return n<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(r.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let s=t+e,o=e<0?-1:n._tree.children.length;s!=o;s+=e){let l=n._tree.children[s];if(this.mode&Q.IncludeAnonymous||l instanceof zn||!l.type.isAnonymous||tf(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)e:for(let r=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==r){if(r==this.index)return o;t=o,n=s+1;break e}r=this.stack[--s]}for(let r=n;r<this.stack.length;r++)t=new Wt(this.buffer,t,this.stack[r]);return this.bufferNode=new Wt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return zh(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,s=this.stack.length-1;r>=0;s--){if(s<0)return zh(this._tree,e,r);let o=n[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}return!0}}function tf(i){return i.children.some(e=>e instanceof zn||!e.type.isAnonymous||tf(e))}function nv(i){var e;let{buffer:t,nodeSet:n,maxBufferLength:r=YC,reused:s=[],minRepeatType:o=n.types.length}=i,l=Array.isArray(t)?new ef(t,t.length):t,a=n.types,h=0,c=0;function f(w,M,C,I,P,te){let{id:W,start:L,end:X,size:G}=l,oe=c,ze=h;if(G<0)if(l.next(),G==-1){let Gt=s[W];C.push(Gt),I.push(L-w);return}else if(G==-3){h=W;return}else if(G==-4){c=W;return}else throw new RangeError(`Unrecognized record size: ${G}`);let tt=a[W],Et,we,lt=L-w;if(X-L<=r&&(we=g(l.pos-M,P))){let Gt=new Uint16Array(we.size-we.skip),at=l.pos-we.size,Rt=Gt.length;for(;l.pos>at;)Rt=y(we.start,Gt,Rt);Et=new zn(Gt,X-we.start,n),lt=we.start-w}else{let Gt=l.pos-G;l.next();let at=[],Rt=[],Un=W>=o?W:-1,Ni=0,mo=X,ca=oe;for(;l.pos>Gt;)Un>=0&&l.id==Un&&l.size>=0?(l.end<=mo-r&&(p(at,Rt,L,Ni,l.end,mo,Un,ca,ze),Ni=at.length,mo=l.end,ca=c),l.next()):te>2500?u(L,Gt,at,Rt):f(L,Gt,at,Rt,Un,te+1);if(Un>=0&&Ni>0&&Ni<at.length&&p(at,Rt,L,Ni,L,mo,Un,ca,ze),at.reverse(),Rt.reverse(),Un>-1&&Ni>0){let Tu=d(tt,ze);Et=nf(tt,at,Rt,0,at.length,0,X-L,Tu,Tu)}else Et=m(tt,at,Rt,X-L,oe-X,ze)}C.push(Et),I.push(lt)}function u(w,M,C,I){let P=[],te=0,W=-1;for(;l.pos>M;){let{id:L,start:X,end:G,size:oe}=l;if(oe>4)l.next();else{if(W>-1&&X<W)break;W<0&&(W=G-r),P.push(L,X,G),te++,l.next()}}if(te){let L=new Uint16Array(te*4),X=P[P.length-2];for(let G=P.length-3,oe=0;G>=0;G-=3)L[oe++]=P[G],L[oe++]=P[G+1]-X,L[oe++]=P[G+2]-X,L[oe++]=oe;C.push(new zn(L,P[2]-X,n)),I.push(X-w)}}function d(w,M){return(C,I,P)=>{let te=0,W=C.length-1,L,X;if(W>=0&&(L=C[W])instanceof ie){if(!W&&L.type==w&&L.length==P)return L;(X=L.prop(H.lookAhead))&&(te=I[W]+L.length+X-P)}return m(w,C,I,P,te,M)}}function p(w,M,C,I,P,te,W,L,X){let G=[],oe=[];for(;w.length>I;)G.push(w.pop()),oe.push(M.pop()+C-P);w.push(m(n.types[W],G,oe,te-P,L-te,X)),M.push(P-C)}function m(w,M,C,I,P,te,W){if(te){let L=[H.contextHash,te];W=W?[L].concat(W):[L]}if(P>25){let L=[H.lookAhead,P];W=W?[L].concat(W):[L]}return new ie(w,M,C,I,W)}function g(w,M){let C=l.fork(),I=0,P=0,te=0,W=C.end-r,L={size:0,start:0,skip:0};e:for(let X=C.pos-w;C.pos>X;){let G=C.size;if(C.id==M&&G>=0){L.size=I,L.start=P,L.skip=te,te+=4,I+=4,C.next();continue}let oe=C.pos-G;if(G<0||oe<X||C.start<W)break;let ze=C.id>=o?4:0,tt=C.start;for(C.next();C.pos>oe;){if(C.size<0)if(C.size==-3||C.size==-4)ze+=4;else break e;else C.id>=o&&(ze+=4);C.next()}P=tt,I+=G,te+=ze}return(M<0||I==w)&&(L.size=I,L.start=P,L.skip=te),L.size>4?L:void 0}function y(w,M,C){let{id:I,start:P,end:te,size:W}=l;if(l.next(),W>=0&&I<o){let L=C;if(W>4){let X=l.pos-(W-4);for(;l.pos>X;)C=y(w,M,C)}M[--C]=L,M[--C]=te-w,M[--C]=P-w,M[--C]=I}else W==-3?h=I:W==-4&&(c=I);return C}let b=[],k=[];for(;l.pos>0;)f(i.start||0,i.bufferStart||0,b,k,-1,0);let O=(e=i.length)!==null&&e!==void 0?e:b.length?k[0]+b[0].length:0;return new ie(a[i.topID],b.reverse(),k.reverse(),O)}const _d=new WeakMap;function Yo(i,e){if(!i.isAnonymous||e instanceof zn||e.type!=i)return 1;let t=_d.get(e);if(t==null){t=1;for(let n of e.children){if(n.type!=i||!(n instanceof ie)){t=1;break}t+=Yo(i,n)}_d.set(e,t)}return t}function nf(i,e,t,n,r,s,o,l,a){let h=0;for(let p=n;p<r;p++)h+=Yo(i,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,m,g,y,b){for(let k=g;k<y;){let O=k,w=m[k],M=Yo(i,p[k]);for(k++;k<y;k++){let C=Yo(i,p[k]);if(M+C>=c)break;M+=C}if(k==O+1){if(M>c){let C=p[O];d(C.children,C.positions,0,C.children.length,m[O]+b);continue}f.push(p[O])}else{let C=m[k-1]+p[k-1].length-w;f.push(nf(i,p,m,O,k,w,C,null,a))}u.push(w+b-s)}}return d(e,t,n,r,0),(l||a)(f,u,o)}class xI{constructor(){this.map=new WeakMap}setBuffer(e,t,n){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,n)}getBuffer(e,t){let n=this.map.get(e);return n&&n.get(t)}set(e,t){e instanceof Wt?this.setBuffer(e.context.buffer,e.index,t):e instanceof Pe&&this.map.set(e.tree,t)}get(e){return e instanceof Wt?this.getBuffer(e.context.buffer,e.index):e instanceof Pe?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class ln{constructor(e,t,n,r,s=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],n=!1){let r=[new ln(0,e.length,e,0,!1,n)];for(let s of t)s.to>e.length&&r.push(s);return r}static applyChanges(e,t,n=128){if(!t.length)return e;let r=[],s=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=n)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new ln(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&r.push(u),o.to>f)break;o=s<e.length?e[s++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return r}}class V0{startParse(e,t,n){return typeof e=="string"&&(e=new iv(e)),n=n?n.length?n.map(r=>new ft(r.from,r.to)):[new ft(0,0)]:[new ft(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let s=r.advance();if(s)return s}}}class iv{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function wI(i){return(e,t,n,r)=>new sv(e,i,t,n,r)}class Ud{constructor(e,t,n,r,s,o){this.parser=e,this.parse=t,this.overlay=n,this.bracketed=r,this.target=s,this.from=o}}function Gd(i){if(!i.length||i.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(i))}class rv{constructor(e,t,n,r,s,o,l,a){this.parser=e,this.predicate=t,this.mounts=n,this.index=r,this.start=s,this.bracketed=o,this.target=l,this.prev=a,this.depth=0,this.ranges=[]}}const Vh=new H({perNode:!0});class sv{constructor(e,t,n,r,s){this.nest=t,this.input=n,this.fragments=r,this.ranges=s,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let n=this.baseParse.advance();if(!n)return null;if(this.baseParse=null,this.baseTree=n,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let n=this.baseTree;return this.stoppedAt!=null&&(n=new ie(n.type,n.children,n.positions,n.length,n.propValues.concat([[Vh,this.stoppedAt]]))),n}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let n=Object.assign(Object.create(null),e.target.props);n[H.mounted.id]=new Ki(t,e.overlay,e.parser,e.bracketed),e.target.props=n}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new av(this.fragments),t=null,n=null,r=new pl(new Pe(this.baseTree,this.ranges[0].from,0,null),Q.IncludeAnonymous|Q.IgnoreMounts);e:for(let s,o;;){let l=!0,a;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)l=!1;else if(e.hasNode(r)){if(t){let h=t.mounts.find(c=>c.frag.from<=r.from&&c.frag.to>=r.to&&c.mount.overlay);if(h)for(let c of h.mount.overlay){let f=c.from+h.pos,u=c.to+h.pos;f>=r.from&&u<=r.to&&!t.ranges.some(d=>d.from<u&&d.to>f)&&t.ranges.push({from:f,to:u})}}l=!1}else if(n&&(o=ov(n.ranges,r.from,r.to)))l=o!=2;else if(!r.type.isAnonymous&&(s=this.nest(r,this.input))&&(r.from<r.to||!s.overlay)){r.tree||(lv(r),t&&t.depth++,n&&n.depth++);let h=e.findMounts(r.from,s.parser);if(typeof s.overlay=="function")t=new rv(s.parser,s.overlay,h,this.inner.length,r.from,!!s.bracketed,r.tree,t);else{let c=Qd(this.ranges,s.overlay||(r.from<r.to?[new ft(r.from,r.to)]:[]));c.length&&Gd(c),(c.length||!s.overlay)&&this.inner.push(new Ud(s.parser,c.length?s.parser.startParse(this.input,Zd(h,c),c):s.parser.startParse(""),s.overlay?s.overlay.map(f=>new ft(f.from-r.from,f.to-r.from)):null,!!s.bracketed,r.tree,c.length?c[0].from:r.from)),s.overlay?c.length&&(n={ranges:c,depth:0,prev:n}):l=!1}}else if(t&&(a=t.predicate(r))&&(a===!0&&(a=new ft(r.from,r.to)),a.from<a.to)){let h=t.ranges.length-1;h>=0&&t.ranges[h].to==a.from?t.ranges[h]={from:t.ranges[h].from,to:a.to}:t.ranges.push(a)}if(l&&r.firstChild())t&&t.depth++,n&&n.depth++;else for(;!r.nextSibling();){if(!r.parent())break e;if(t&&!--t.depth){let h=Qd(this.ranges,t.ranges);h.length&&(Gd(h),this.inner.splice(t.index,0,new Ud(t.parser,t.parser.startParse(this.input,Zd(t.mounts,h),h),t.ranges.map(c=>new ft(c.from-t.start,c.to-t.start)),t.bracketed,t.target,h[0].from))),t=t.prev}n&&!--n.depth&&(n=n.prev)}}}}function ov(i,e,t){for(let n of i){if(n.from>=t)break;if(n.to>e)return n.from<=e&&n.to>=t?2:1}return 0}function Yd(i,e,t,n,r,s){if(e<t){let o=i.buffer[e+1];n.push(i.slice(e,t,o)),r.push(o-s)}}function lv(i){let{node:e}=i,t=[],n=e.context.buffer;do t.push(i.index),i.parent();while(!i.tree);let r=i.tree,s=r.children.indexOf(n),o=r.children[s],l=o.buffer,a=[s];function h(c,f,u,d,p,m){let g=t[m],y=[],b=[];Yd(o,c,g,y,b,d);let k=l[g+1],O=l[g+2];a.push(y.length);let w=m?h(g+4,l[g+3],o.set.types[l[g]],k,O-k,m-1):e.toTree();return y.push(w),b.push(k-d),Yd(o,l[g+3],f,y,b,d),new ie(u,y,b,p)}r.children[s]=h(0,l.length,je.none,0,o.length,t.length-1);for(let c of a){let f=i.tree.children[c],u=i.tree.positions[c];i.yield(new Pe(f,u+i.from,c,i._tree))}}class Xd{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(Q.IncludeAnonymous|Q.IgnoreMounts|Q.ExcludeBuffers)}moveTo(e){let{cursor:t}=this,n=e-this.offset;for(;!this.done&&t.from<n;)if(!(t.to>=n&&t.enter(n,1,Q.IncludeAnonymous|Q.IgnoreOverlays|Q.ExcludeBuffers)))if(t.to<=n)t.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof ie)t=t.children[0];else break}return!1}}class av{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let n=this.curFrag=e[0];this.curTo=(t=n.tree.prop(Vh))!==null&&t!==void 0?t:n.to,this.inner=new Xd(n.tree,-n.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Vh))!==null&&e!==void 0?e:t.to,this.inner=new Xd(t.tree,-t.offset)}}findMounts(e,t){var n;let r=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let s=this.inner.cursor.node;s;s=s.parent){let o=(n=s.tree)===null||n===void 0?void 0:n.prop(H.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let a=this.fragments[l];if(a.from>=s.to)break;a.tree==this.curFrag.tree&&r.push({frag:a,pos:s.from-a.offset,mount:o})}}}return r}}function Qd(i,e){let t=null,n=e;for(let r=1,s=0;r<i.length;r++){let o=i[r-1].to,l=i[r].from;for(;s<n.length;s++){let a=n[s];if(a.from>=l)break;a.to<=o||(t||(n=t=e.slice()),a.from<o?(t[s]=new ft(a.from,o),a.to>l&&t.splice(s+1,0,new ft(l,a.to))):a.to>l?t[s--]=new ft(l,a.to):t.splice(s--,1))}}return n}function hv(i,e,t,n){let r=0,s=0,o=!1,l=!1,a=-1e9,h=[];for(;;){let c=r==i.length?1e9:o?i[r].to:i[r].from,f=s==e.length?1e9:l?e[s].to:e[s].from;if(o!=l){let u=Math.max(a,t),d=Math.min(c,f,n);u<d&&h.push(new ft(u,d))}if(a=Math.min(c,f),a==1e9)break;c==a&&(o?(o=!1,r++):o=!0),f==a&&(l?(l=!1,s++):l=!0)}return h}function Zd(i,e){let t=[];for(let{pos:n,mount:r,frag:s}of i){let o=n+(r.overlay?r.overlay[0].from:0),l=o+r.tree.length,a=Math.max(s.from,o),h=Math.min(s.to,l);if(r.overlay){let c=r.overlay.map(u=>new ft(u.from+n,u.to+n)),f=hv(e,c,a,h);for(let u=0,d=a;;u++){let p=u==f.length,m=p?h:f[u].from;if(m>d&&t.push(new ln(d,m,r.tree,-o,s.from>=d||s.openStart,s.to<=m||s.openEnd)),p)break;d=f[u].to}}else t.push(new ln(a,h,r.tree,-o,s.from>=o||s.openStart,s.to<=l||s.openEnd))}return t}let Hh=[],H0=[];(()=>{let i="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<i.length;e++)(e%2?H0:Hh).push(t=t+i[e])})();function cv(i){if(i<768)return!1;for(let e=0,t=Hh.length;;){let n=e+t>>1;if(i<Hh[n])t=n;else if(i>=H0[n])e=n+1;else return!0;if(e==t)return!1}}function ep(i){return i>=127462&&i<=127487}const tp=8205;function fv(i,e,t=!0,n=!0){return(t?W0:uv)(i,e,n)}function W0(i,e,t){if(e==i.length)return e;e&&$0(i.charCodeAt(e))&&K0(i.charCodeAt(e-1))&&e--;let n=Ha(i,e);for(e+=np(n);e<i.length;){let r=Ha(i,e);if(n==tp||r==tp||t&&cv(r))e+=np(r),n=r;else if(ep(r)){let s=0,o=e-2;for(;o>=0&&ep(Ha(i,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function uv(i,e,t){for(;e>1;){let n=W0(i,e-2,t);if(n<e)return n;e--}return 0}function Ha(i,e){let t=i.charCodeAt(e);if(!K0(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return $0(n)?(t-55296<<10)+(n-56320)+65536:t}function $0(i){return i>=56320&&i<57344}function K0(i){return i>=55296&&i<56320}function np(i){return i<65536?1:2}let U=class q0{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=hr(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Vt.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=hr(this,e,t);let n=[];return this.decompose(e,t,n,0),Vt.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new is(this),s=new is(e);for(let o=t,l=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(l+=r.value.length,r.done||l>=n)return!0}}iter(e=1){return new is(this,e)}iterRange(e,t=this.length){return new j0(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new J0(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?q0.empty:e.length<=32?new ce(e):Vt.from(ce.split(e,[]))}};class ce extends U{constructor(e,t=dv(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.text[s],l=r+o.length;if((t?n:l)>=e)return new pv(r,l,n,o);r=l+1,n++}}decompose(e,t,n,r){let s=e<=0&&t>=this.length?this:new ce(ip(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){let o=n.pop(),l=Xo(s.text,o.text.slice(),0,s.length);if(l.length<=32)n.push(new ce(l,o.length+s.length));else{let a=l.length>>1;n.push(new ce(l.slice(0,a)),new ce(l.slice(a)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof ce))return super.replace(e,t,n);[e,t]=hr(this,e,t);let r=Xo(this.text,Xo(n.text,ip(this.text,0,e)),t),s=this.length+n.length-(t-e);return r.length<=32?new ce(r,s):Vt.from(ce.split(r,[]),s)}sliceString(e,t=this.length,n=`
|
|
35
|
-
`){[e,t]=hr(this,e,t);let r="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let l=this.text[o],a=s+l.length;s>e&&o&&(r+=n),e<a&&t>s&&(r+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],r=-1;for(let s of e)n.push(s),r+=s.length+1,n.length==32&&(t.push(new ce(n,r)),n=[],r=-1);return r>-1&&t.push(new ce(n,r)),t}}class Vt extends U{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let n of e)this.lines+=n.lines}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.children[s],l=r+o.length,a=n+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,n,r);r=l+1,n=a+1}}decompose(e,t,n,r){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let l=this.children[s],a=o+l.length;if(e<=a&&t>=o){let h=r&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?n.push(l):l.decompose(e-o,t-o,n,h)}o=a+1}}replace(e,t,n){if([e,t]=hr(this,e,t),n.lines<this.lines)for(let r=0,s=0;r<this.children.length;r++){let o=this.children[r],l=s+o.length;if(e>=s&&t<=l){let a=o.replace(e-s,t-s,n),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[r]=a,new Vt(c,this.length-(t-e)+n.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n=`
|
|
36
|
-
`){[e,t]=hr(this,e,t);let r="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let l=this.children[s],a=o+l.length;o>e&&s&&(r+=n),e<a&&t>o&&(r+=l.sliceString(e-o,t-o,n)),o=a+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Vt))return 0;let n=0,[r,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;r+=t,s+=t){if(r==o||s==l)return n;let a=this.children[r],h=e.children[s];if(a!=h)return n+a.scanIdentical(h,t);n+=a.length+1}}static from(e,t=e.reduce((n,r)=>n+r.length+1,-1)){let n=0;for(let d of e)n+=d.lines;if(n<32){let d=[];for(let p of e)p.flatten(d);return new ce(d,t)}let r=Math.max(32,n>>5),s=r<<1,o=r>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>s&&d instanceof Vt)for(let m of d.children)f(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof ce&&a&&(p=c[c.length-1])instanceof ce&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new ce(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>r&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:Vt.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new Vt(l,t)}}U.empty=new ce([""],0);function dv(i){let e=-1;for(let t of i)e+=t.length+1;return e}function Xo(i,e,t=0,n=1e9){for(let r=0,s=0,o=!0;s<i.length&&r<=n;s++){let l=i[s],a=r+l.length;a>=t&&(a>n&&(l=l.slice(0,n-r)),r<t&&(l=l.slice(t-r)),o?(e[e.length-1]+=l,o=!1):e.push(l)),r=a+1}return e}function ip(i,e,t){return Xo(i,[""],e,t)}class is{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof ce?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],s=this.offsets[n],o=s>>1,l=r instanceof ce?r.text.length:r.children.length;if(o==(t>0?l:0)){if(n==0)return this.done=!0,this.value="",this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
37
|
-
`,this;e--}else if(r instanceof ce){let a=r.text[o+(t<0?-1:0)];if(this.offsets[n]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=r.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ce?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class j0{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new is(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class J0{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(U.prototype[Symbol.iterator]=function(){return this.iter()},is.prototype[Symbol.iterator]=j0.prototype[Symbol.iterator]=J0.prototype[Symbol.iterator]=function(){return this});class pv{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}}function hr(i,e,t){return e=Math.max(0,Math.min(i.length,e)),[e,Math.max(e,Math.min(i.length,t))]}function Re(i,e,t=!0,n=!0){return fv(i,e,t,n)}function mv(i){return i>=56320&&i<57344}function gv(i){return i>=55296&&i<56320}function it(i,e){let t=i.charCodeAt(e);if(!gv(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return mv(n)?(t-55296<<10)+(n-56320)+65536:t}function _0(i){return i<=65535?String.fromCharCode(i):(i-=65536,String.fromCharCode((i>>10)+55296,(i&1023)+56320))}function Zt(i){return i<65536?1:2}const Wh=/\r\n?|\n/;var Ae=(function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i})(Ae||(Ae={}));class Jt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(n,r,s),r+=s):r+=o,n+=s}}iterChangedRanges(e,t=!1){$h(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];r<0?e.push(n,r):e.push(r,n)}return new Jt(e)}composeDesc(e){return this.empty?e:e.empty?this:U0(this,e)}mapDesc(e,t=!1){return e.empty?this:Kh(this,e,t)}mapPos(e,t=-1,n=Ae.Simple){let r=0,s=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=r+l;if(a<0){if(h>e)return s+(e-r);s+=l}else{if(n!=Ae.Simple&&h>=e&&(n==Ae.TrackDel&&r<e&&h>e||n==Ae.TrackBefore&&r<e||n==Ae.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==r||t<0?s:s+a;s+=a}r=h}if(e>r)throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);return s}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let s=this.sections[n++],o=this.sections[n++],l=r+s;if(o>=0&&r<=t&&l>=e)return r<e&&l>t?"cover":!0;r=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?" ":"")+n+(r>=0?":"+r:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Jt(e)}static create(e){return new Jt(e)}}class me extends Jt{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return $h(this,(t,n,r,s,o)=>e=e.replace(r,r+(n-t),o),!1),e}mapDesc(e,t=!1){return Kh(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let r=0,s=0;r<t.length;r+=2){let o=t[r],l=t[r+1];if(l>=0){t[r]=l,t[r+1]=o;let a=r>>1;for(;n.length<a;)n.push(U.empty);n.push(o?e.slice(s,s+o):U.empty)}s+=o}return new me(t,n)}compose(e){return this.empty?e:e.empty?this:U0(this,e,!0)}map(e,t=!1){return e.empty?this:Kh(this,e,t,!0)}iterChanges(e,t=!1){$h(this,e,t)}get desc(){return Jt.create(this.sections)}filter(e){let t=[],n=[],r=[],s=new As(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,a-l);Ie(r,c,-1);let f=s.ins==-1?-1:s.off==0?s.ins:0;Ie(t,c,f),f>0&&Tn(n,t,s.text),s.forward(c),l+=c}let h=e[o++];for(;l<h;){if(s.done)break e;let c=Math.min(s.len,h-l);Ie(t,c,-1),Ie(r,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),l+=c}}return{changes:new me(t,n),filtered:Jt.create(r)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,n){let r=[],s=[],o=0,l=null;function a(c=!1){if(!c&&!r.length)return;o<t&&Ie(r,t-o,-1);let f=new me(r,s);l=l?l.compose(f.map(l)):f,r=[],s=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof me){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?U.of(d.split(n||Wh)):d:U.empty,m=p.length;if(f==u&&m==0)return;f<o&&a(),f>o&&Ie(r,f-o,-1),Ie(r,u-f,m),Tn(s,r,p),o=u}}return h(e),a(!l),l}static empty(e){return new me(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let r=0;r<e.length;r++){let s=e[r];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;n.length<r;)n.push(U.empty);n[r]=U.of(s.slice(1)),t.push(s[0],n[r].length)}}}return new me(t,n)}static createSet(e,t){return new me(e,t)}}function Ie(i,e,t,n=!1){if(e==0&&t<=0)return;let r=i.length-2;r>=0&&t<=0&&t==i[r+1]?i[r]+=e:r>=0&&e==0&&i[r]==0?i[r+1]+=t:n?(i[r]+=e,i[r+1]+=t):i.push(e,t)}function Tn(i,e,t){if(t.length==0)return;let n=e.length-2>>1;if(n<i.length)i[i.length-1]=i[i.length-1].append(t);else{for(;i.length<n;)i.push(U.empty);i.push(t)}}function $h(i,e,t){let n=i.inserted;for(let r=0,s=0,o=0;o<i.sections.length;){let l=i.sections[o++],a=i.sections[o++];if(a<0)r+=l,s+=l;else{let h=r,c=s,f=U.empty;for(;h+=l,c+=a,a&&n&&(f=f.append(n[o-2>>1])),!(t||o==i.sections.length||i.sections[o+1]<0);)l=i.sections[o++],a=i.sections[o++];e(r,h,s,c,f),r=h,s=c}}}function Kh(i,e,t,n=!1){let r=[],s=n?[]:null,o=new As(i),l=new As(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);Ie(r,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(Ie(r,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(Ie(r,0,o.ins),s&&Tn(s,r,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;Ie(r,h,a<o.i?o.ins:0),s&&a<o.i&&Tn(s,r,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return s?me.createSet(r,s):Jt.create(r);throw new Error("Mismatched change set lengths")}}}function U0(i,e,t=!1){let n=[],r=t?[]:null,s=new As(i),o=new As(e);for(let l=!1;;){if(s.done&&o.done)return r?me.createSet(n,r):Jt.create(n);if(s.ins==0)Ie(n,s.len,0,l),s.next();else if(o.len==0&&!o.done)Ie(n,0,o.ins,l),r&&Tn(r,n,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(s.len2,o.len),h=n.length;if(s.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;Ie(n,a,c,l),r&&c&&Tn(r,n,o.text)}else o.ins==-1?(Ie(n,s.off?0:s.len,a,l),r&&Tn(r,n,s.textBit(a))):(Ie(n,s.off?0:s.len,o.off?0:o.ins,l),r&&!o.off&&Tn(r,n,o.text));l=(s.ins>a||o.ins>=0&&o.len>a)&&(l||n.length>h),s.forward2(a),o.forward(a)}}}}class As{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?U.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?U.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class vn{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,t=-1){let n,r;return this.empty?n=r=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),r=e.mapPos(this.to,-1)),n==this.from&&r==this.to?this:new vn(n,r,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return S.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return S.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return S.range(e.anchor,e.head)}static create(e,t,n,r){return new vn(e,t,n,r)}}class S{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:S.create(this.ranges.map(n=>n.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new S([this.main],0)}addRange(e,t=!0){return S.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let n=this.ranges.slice();return n[t]=e,S.create(n,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new S(e.ranges.map(t=>vn.fromJSON(t)),e.main)}static single(e,t=e){return new S([S.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,r=0;r<e.length;r++){let s=e[r];if(s.empty?s.from<=n:s.from<n)return S.normalized(e.slice(),t);n=s.to}return new S(e,t)}static cursor(e,t=0,n,r){return vn.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,s){let o=r==null?7:Math.min(6,r);return!s&&e!=t&&(s=t<e?1:-1),s&&(o|=s<0?8:16),t<e?vn.create(t,e,o|32,n):vn.create(e,t,o,n)}static undirectionalRange(e,t){return vn.create(e,t,64,void 0)}static normalized(e,t=0){let n=e[t];e.sort((r,s)=>r.from-s.from),t=e.indexOf(n);for(let r=1;r<e.length;r++){let s=e[r],o=e[r-1];if(s.empty?s.from<=o.to:s.from<o.to){let l=o.from,a=Math.max(s.to,o.to);r<=t&&t--,e.splice(--r,2,s.anchor>s.head?S.range(a,l):S.range(l,a))}}return new S(e,t)}}function G0(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let rf=0;class D{constructor(e,t,n,r,s){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=rf++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new D(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:sf),!!e.static,e.enables)}of(e){return new Qo([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Qo(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Qo(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}}function sf(i,e){return i==e||i.length==e.length&&i.every((t,n)=>t===e[n])}class Qo{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=rf++}dynamicSlot(e){var t;let n=this.value,r=this.facet.compareInput,s=this.id,o=e[s]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=n(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||qh(f,c)){let d=n(f);if(l?!rp(d,f.values[o],r):!r(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[s];if(p!=null){let m=gl(u,p);if(this.dependencies.every(g=>g instanceof D?u.facet(g)===f.facet(g):g instanceof Ge?u.field(g,!1)==f.field(g,!1):!0)||(l?rp(d=n(f),m,r):r(d=n(f),m)))return f.values[o]=m,0}else d=n(f);return f.values[o]=d,1}}}get extension(){return this}}function rp(i,e,t){if(i.length!=e.length)return!1;for(let n=0;n<i.length;n++)if(!t(i[n],e[n]))return!1;return!0}function qh(i,e){let t=!1;for(let n of e)rs(i,n)&1&&(t=!0);return t}function yv(i,e,t){let n=t.map(a=>i[a.id]),r=t.map(a=>a.type),s=n.filter(a=>!(a&1)),o=i[e.id]>>1;function l(a){let h=[];for(let c=0;c<n.length;c++){let f=gl(a,n[c]);if(r[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of n)rs(a,h);return a.values[o]=l(a),1},update(a,h){if(!qh(a,s))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=qh(a,n),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&sf(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const So=D.define({static:!0});class Ge{constructor(e,t,n,r,s){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=s,this.provides=void 0}static define(e){let t=new Ge(rf++,e.create,e.update,e.compare||((n,r)=>n===r),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(So).find(n=>n.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:n=>(n.values[t]=this.create(n),1),update:(n,r)=>{let s=n.values[t],o=this.updateF(s,r);return this.compareF(s,o)?0:(n.values[t]=o,1)},reconfigure:(n,r)=>{let s=n.facet(So),o=r.facet(So),l;return(l=s.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(n.values[t]=l.create(n),1):r.config.address[this.id]!=null?(n.values[t]=r.field(this),0):(n.values[t]=this.create(n),1)}}}init(e){return[this,So.of({field:this,create:e})]}get extension(){return this}}const Qn={lowest:4,low:3,default:2,high:1,highest:0};function Ir(i){return e=>new Y0(e,i)}const Mi={highest:Ir(Qn.highest),high:Ir(Qn.high),default:Ir(Qn.default),low:Ir(Qn.low),lowest:Ir(Qn.lowest)};class Y0{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}}class _l{of(e){return new jh(this,e)}reconfigure(e){return _l.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class jh{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}}class ml{constructor(e,t,n,r,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,n){let r=[],s=Object.create(null),o=new Map;for(let u of bv(e,t,o))u instanceof Ge?r.push(u):(s[u.facet.id]||(s[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of r)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=n?.config.facets;for(let u in s){let d=s[u],p=d[0].facet,m=c&&c[u]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,sf(m,d))a.push(n.facet(p));else{let g=p.combine(d.map(y=>y.value));a.push(n&&p.compare(g,n.facet(p))?n.facet(p):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(y=>g.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(g=>yv(g,p,d))}}let f=h.map(u=>u(l));return new ml(e,o,f,l,a,s)}}function bv(i,e,t){let n=[[],[],[],[],[]],r=new Map;function s(o,l){let a=r.get(o);if(a!=null){if(a<=l)return;let h=n[a].indexOf(o);h>-1&&n[a].splice(h,1),o instanceof jh&&t.delete(o.compartment)}if(r.set(o,l),Array.isArray(o))for(let h of o)s(h,l);else if(o instanceof jh){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),s(h,l)}else if(o instanceof Y0)s(o.inner,o.prec);else if(o instanceof Ge)n[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof Qo)n[l].push(o),o.facet.extensions&&s(o.facet.extensions,Qn.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}).`);if(h==o)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,l)}}return s(i,Qn.default),n.reduce((o,l)=>o.concat(l))}function rs(i,e){if(e&1)return 2;let t=e>>1,n=i.status[t];if(n==4)throw new Error("Cyclic dependency between fields and/or facets");if(n&2)return n;i.status[t]=4;let r=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|r}function gl(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}const X0=D.define(),Jh=D.define({combine:i=>i.some(e=>e),static:!0}),Q0=D.define({combine:i=>i.length?i[0]:void 0,static:!0}),Z0=D.define(),ey=D.define(),ty=D.define(),ny=D.define({combine:i=>i.length?i[0]:!1});class mn{constructor(e,t){this.type=e,this.value=t}static define(){return new kv}}class kv{of(e){return new mn(this,e)}}class xv{constructor(e){this.map=e}of(e){return new V(this,e)}}class V{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new V(this.type,t)}is(e){return this.type==e}static define(e={}){return new xv(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let s=r.map(t);s&&n.push(s)}return n}}V.reconfigure=V.define();V.appendConfig=V.define();class pe{constructor(e,t,n,r,s,o){this.startState=e,this.changes=t,this.selection=n,this.effects=r,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,n&&G0(n,t.newLength),s.some(l=>l.type==pe.time)||(this.annotations=s.concat(pe.time.of(Date.now())))}static create(e,t,n,r,s,o){return new pe(e,t,n,r,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(pe.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}pe.time=mn.define();pe.userEvent=mn.define();pe.addToHistory=mn.define();pe.remote=mn.define();function wv(i,e){let t=[];for(let n=0,r=0;;){let s,o;if(n<i.length&&(r==e.length||e[r]>=i[n]))s=i[n++],o=i[n++];else if(r<e.length)s=e[r++],o=e[r++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function iy(i,e,t){var n;let r,s,o;return t?(r=e.changes,s=me.empty(e.changes.length),o=i.changes.compose(e.changes)):(r=e.changes.map(i.changes),s=i.changes.mapDesc(e.changes,!0),o=i.changes.compose(r)),{changes:o,selection:e.selection?e.selection.map(s):(n=i.selection)===null||n===void 0?void 0:n.map(r),effects:V.mapEffects(i.effects,r).concat(V.mapEffects(e.effects,s)),annotations:i.annotations.length?i.annotations.concat(e.annotations):e.annotations,scrollIntoView:i.scrollIntoView||e.scrollIntoView}}function _h(i,e,t){let n=e.selection,r=qi(e.annotations);return e.userEvent&&(r=r.concat(pe.userEvent.of(e.userEvent))),{changes:e.changes instanceof me?e.changes:me.of(e.changes||[],t,i.facet(Q0)),selection:n&&(n instanceof S?n:S.single(n.anchor,n.head)),effects:qi(e.effects),annotations:r,scrollIntoView:!!e.scrollIntoView}}function ry(i,e,t){let n=_h(i,e.length?e[0]:{},i.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;n=iy(n,_h(i,e[s],o?n.changes.newLength:i.doc.length),o)}let r=pe.create(i,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return Cv(t?Sv(r):r)}function Sv(i){let e=i.startState,t=!0;for(let r of e.facet(Z0)){let s=r(i);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:wv(t,s))}if(t!==!0){let r,s;if(t===!1)s=i.changes.invertedDesc,r=me.empty(e.doc.length);else{let o=i.changes.filter(t);r=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}i=pe.create(e,r,i.selection&&i.selection.map(s),V.mapEffects(i.effects,s),i.annotations,i.scrollIntoView)}let n=e.facet(ey);for(let r=n.length-1;r>=0;r--){let s=n[r](i);s instanceof pe?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof pe?i=s[0]:i=ry(e,qi(s),!1)}return i}function Cv(i){let e=i.startState,t=e.facet(ty),n=i;for(let r=t.length-1;r>=0;r--){let s=t[r](i);s&&Object.keys(s).length&&(n=iy(n,_h(e,s,i.changes.newLength),!0))}return n==i?i:pe.create(e,i.changes,i.selection,n.effects,n.annotations,n.scrollIntoView)}const vv=[];function qi(i){return i==null?vv:Array.isArray(i)?i:[i]}var ut=(function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i})(ut||(ut={}));const Mv=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Uh;try{Uh=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Av(i){if(Uh)return Uh.test(i);for(let e=0;e<i.length;e++){let t=i[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||Mv.test(t)))return!0}return!1}function Ov(i){return e=>{if(!/\S/.test(e))return ut.Space;if(Av(e))return ut.Word;for(let t=0;t<i.length;t++)if(e.indexOf(i[t])>-1)return ut.Word;return ut.Other}}class Y{constructor(e,t,n,r,s,o){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)rs(this,l<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw new RangeError("Field is not present in this state");return}return rs(this,n),gl(this,n)}update(...e){return ry(this,e,!0)}applyTransaction(e){let t=this.config,{base:n,compartments:r}=t;for(let l of e.effects)l.is(_l.reconfigure)?(t&&(r=new Map,t.compartments.forEach((a,h)=>r.set(h,a)),t=null),r.set(l.value.compartment,l.value.extension)):l.is(V.reconfigure)?(t=null,n=l.value):l.is(V.appendConfig)&&(t=null,n=qi(n).concat(l.value));let s;t?s=e.startState.values.slice():(t=ml.resolve(n,r,this),s=new Y(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Jh)?e.newSelection:e.newSelection.asSingle();new Y(t,e.newDoc,o,s,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:S.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),s=[n.range],o=qi(n.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(r);for(let u=0;u<l;u++)s[u]=s[u].map(c);let f=r.mapDesc(h,!0);s.push(a.range.map(f)),r=r.compose(c),o=V.mapEffects(o,c).concat(V.mapEffects(qi(a.effects),f))}return{changes:r,selection:S.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof me?e:me.of(e,this.doc.length,this.facet(Y.lineSeparator))}toText(e){return U.of(e.split(this.facet(Y.lineSeparator)||Wh))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(rs(this,t),gl(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof Ge&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(e,t={},n){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let r=[];if(n){for(let s in n)if(Object.prototype.hasOwnProperty.call(e,s)){let o=n[s],l=e[s];r.push(o.init(a=>o.spec.fromJSON(l,a)))}}return Y.create({doc:e.doc,selection:S.fromJSON(e.selection),extensions:t.extensions?r.concat([t.extensions]):r})}static create(e={}){let t=ml.resolve(e.extensions||[],new Map),n=e.doc instanceof U?e.doc:U.of((e.doc||"").split(t.staticFacet(Y.lineSeparator)||Wh)),r=e.selection?e.selection instanceof S?e.selection:S.single(e.selection.anchor,e.selection.head):S.single(0);return G0(r,n.length),t.staticFacet(Jh)||(r=r.asSingle()),new Y(t,n,r,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(Y.tabSize)}get lineBreak(){return this.facet(Y.lineSeparator)||`
|
|
38
|
-
`}get readOnly(){return this.facet(ny)}phrase(e,...t){for(let n of this.facet(Y.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,r)=>{if(r=="$")return"$";let s=+(r||1);return!s||s>t.length?n:t[s-1]})),e}languageDataAt(e,t,n=-1){let r=[];for(let s of this.facet(X0))for(let o of s(this,t,n))Object.prototype.hasOwnProperty.call(o,e)&&r.push(o[e]);return r}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return Ov(t.length?t[0]:"")}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-n,l=e-n;for(;o>0;){let a=Re(t,o,!1);if(s(t.slice(a,o))!=ut.Word)break;o=a}for(;l<r;){let a=Re(t,l);if(s(t.slice(l,a))!=ut.Word)break;l=a}return o==l?null:S.range(o+n,l+n)}}Y.allowMultipleSelections=Jh;Y.tabSize=D.define({combine:i=>i.length?i[0]:4});Y.lineSeparator=Q0;Y.readOnly=ny;Y.phrases=D.define({compare(i,e){let t=Object.keys(i),n=Object.keys(e);return t.length==n.length&&t.every(r=>i[r]==e[r])}});Y.languageData=X0;Y.changeFilter=Z0;Y.transactionFilter=ey;Y.transactionExtender=ty;_l.reconfigure=V.define();function Ai(i,e,t={}){let n={};for(let r of i)for(let s of Object.keys(r)){let o=r[s],l=n[s];if(l===void 0)n[s]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,s))n[s]=t[s](l,o);else throw new Error("Config merge conflict for field "+s)}for(let r in e)n[r]===void 0&&(n[r]=e[r]);return n}class Vn{eq(e){return this==e}range(e,t=e){return Os.create(e,t,this)}}Vn.prototype.startSide=Vn.prototype.endSide=0;Vn.prototype.point=!1;Vn.prototype.mapMode=Ae.TrackDel;function of(i,e){return i==e||i.constructor==e.constructor&&i.eq(e)}class Os{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new Os(e,t,n)}}function Gh(i,e){return i.from-e.from||i.value.startSide-e.value.startSide}class lf{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return Li(this.to)}findIndex(e,t,n,r=0){let s=n?this.to:this.from;for(let o=r,l=s.length;;){if(o==l)return o;let a=o+l>>1,h=s[a]-e||(n?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,n,r){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(n,1e9,!1,s);s<o;s++)if(r(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t,n,r,s){let o=[],l=[],a=[],h=-1,c=-1;e:for(let f=0;f<this.value.length;f++){let u=this.value[f],d=this.from[f]+e,p=this.to[f]+e,m,g;if(d==p){let y=t.mapPos(d,u.startSide,u.mapMode);if(y==null||(m=g=y,u.startSide!=u.endSide&&(g=t.mapPos(d,u.endSide),g<m)))continue}else if(m=t.mapPos(d,u.startSide),g=t.mapPos(p,u.endSide),m>g||m==g&&u.startSide>0&&u.endSide<=0)continue;if(!((g-m||u.endSide-u.startSide)<0))if(h<0&&(h=m),u.point&&(c=Math.max(c,g-m)),(m-n||u.startSide-r)>=0)o.push(u),l.push(m-h),a.push(g-h),n=g,r=u.endSide;else{if(m==g)for(let y=o.length;y>0;y--){if((m-(a[y-1]+h)||u.startSide-o[y-1].endSide)>=0){o.splice(y,0,u),l.splice(y,0,m-h),a.splice(y,0,g-h);continue e}if((m-(l[y-1]+h)||u.endSide-o[y-1].startSide)>0)break}s(m,g,u)}}return{mapped:o.length?new lf(l,a,o,c):null,pos:h}}}class ${constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(e,t,n,r){return new $(e,t,n,r)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:n=!1,filterFrom:r=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(n&&(t=t.slice().sort(Gh)),this.isEmpty)return t.length?$.of(t):this;let l=new sy(this,null,-1).goto(0),a=0,h=[],c=new Bn;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];c.addInner(f.from,f.to,f.value,!1)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||r>this.chunkEnd(l.chunkIndex)||s<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||r>l.to||s<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value,!1)||h.push(Os.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?$.empty:this.nextLayer.update({add:h,filter:o,filterFrom:r,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],n=[],r=-1,s,o=(a,h,c)=>{s||(s=new Bn),s.addRange(a,h,c,!1)};for(let a=0;a<this.chunk.length;a++){let h=this.chunkPos[a],c=this.chunk[a],f=e.touchesRange(h,h+c.length);if(f===!1)r=Math.max(r,c.maxPoint),t.push(c),n.push(e.mapPos(h));else if(f===!0){let[u,d]=t.length?[Li(n)+Li(t).length,Li(Li(t).value).endSide]:[-1,-1],{mapped:p,pos:m}=c.map(h,e,u,d,o);p&&(r=Math.max(r,p.maxPoint),t.push(p),n.push(m))}}let l=this.nextLayer.map(e);return s&&(l=s.finishInner(l)),t.length==0?l:new $(n,t,l||$.empty,r)}between(e,t,n){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let s=this.chunkPos[r],o=this.chunk[r];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return Ts.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ts.from(e).goto(t)}static compare(e,t,n,r,s=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),a=sp(o,l,n),h=new Er(o,a,s),c=new Er(l,a,s);n.iterGaps((f,u,d)=>op(h,f,c,u,d,r)),n.empty&&n.length==0&&op(h,0,c,0,0,r)}static eq(e,t,n=0,r){r==null&&(r=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=sp(s,o),a=new Er(s,l,0).goto(n),h=new Er(o,l,0).goto(n);for(;;){if(a.to!=h.to||!Yh(a.active,h.active)||a.point&&(!h.point||!of(a.point,h.point)))return!1;if(a.to>r)return!0;a.next(),h.next()}}static spans(e,t,n,r,s=-1){let o=new Er(e,null,s).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,n);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,a);r.point(l,h,o.point,c,f,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(r.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>n)return a+(o.point&&o.to>n?1:0);l=o.to,o.next()}}static of(e,t=!1){let n=new Bn;for(let r of e instanceof Os?[e]:t?Tv(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(e){if(!e.length)return $.empty;let t=Li(e);for(let n=e.length-2;n>=0;n--)for(let r=e[n];r!=$.empty;r=r.nextLayer)t=new $(r.chunkPos,r.chunk,t,Math.max(r.maxPoint,t.maxPoint));return t}}$.empty=new $([],[],null,-1);function Li(i){return i[i.length-1]}function Tv(i){if(i.length>1)for(let e=i[0],t=1;t<i.length;t++){let n=i[t];if(Gh(e,n)>0)return i.slice().sort(Gh);e=n}return i}$.empty.nextLayer=$.empty;class Bn{finishChunk(e){this.chunks.push(new lf(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,n){this.addRange(e,t,n,!0)}addRange(e,t,n,r){this.addInner(e,t,n,r)||(this.nextLayer||(this.nextLayer=new Bn)).addRange(e,t,n,r)}addInner(e,t,n,r){let s=e-this.lastTo||n.startSide-this.last.endSide;if(r&&s<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner($.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=$.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function sp(i,e,t){let n=new Map;for(let s of i)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&n.set(s.chunk[o],s.chunkPos[o]);let r=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let l=n.get(s.chunk[o]);l!=null&&(t?t.mapPos(l):l)==s.chunkPos[o]&&!t?.touchesRange(l,l+s.chunk[o].length)&&r.add(s.chunk[o])}return r}class sy{constructor(e,t,n,r=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex<this.layer.chunk.length;){let r=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(r)||this.layer.chunkEnd(this.chunkIndex)<e||r.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],n=e+t.from[this.rangeIndex];if(this.from=n,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class Ts{constructor(e){this.heap=e}static from(e,t=null,n=-1){let r=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=n&&r.push(new sy(o,t,n,s));return r.length==1?r[0]:new Ts(r)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let n=this.heap.length>>1;n>=0;n--)Wa(this.heap,n);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let n=this.heap.length>>1;n>=0;n--)Wa(this.heap,n);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Wa(this.heap,0)}}}function Wa(i,e){for(let t=i[e];;){let n=(e<<1)+1;if(n>=i.length)break;let r=i[n];if(n+1<i.length&&r.compare(i[n+1])>=0&&(r=i[n+1],n++),t.compare(r)<0)break;i[n]=t,i[e]=r,e=n}}class Er{constructor(e,t,n){this.minPoint=n,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ts.from(e,t,n)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Co(this.active,e),Co(this.activeTo,e),Co(this.activeRank,e),this.minActive=lp(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||r-this.activeTo[t])>0;)t++;vo(this.active,t,n),vo(this.activeTo,t,r),vo(this.activeRank,t,s),e&&vo(e,t,this.cursor.from),this.minActive=lp(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&Co(n,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(n){this.openStart=0;for(let r=n.length-1;r>=0&&n[r]<e;r--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}}function op(i,e,t,n,r,s){i.goto(e),t.goto(n);let o=n+r,l=n,a=n-e,h=!!s.boundChange;for(let c=!1;;){let f=i.to+a-t.to,u=f||i.endSide-t.endSide,d=u<0?i.to+a:t.to,p=Math.min(d,o);if(i.point||t.point?(i.point&&t.point&&of(i.point,t.point)&&Yh(i.activeForPoint(i.to),t.activeForPoint(t.to))||s.comparePoint(l,p,i.point,t.point),c=!1):(c&&(s.boundChange(l),c=!1),p>l&&!Yh(i.active,t.active)&&s.compareRange(l,p,i.active,t.active),h&&p<o&&(f||i.openEnd(d)!=t.openEnd(d))&&(c=!0)),d>o)break;l=d,u<=0&&i.next(),u>=0&&t.next()}}function Yh(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(i[t]!=e[t]&&!of(i[t],e[t]))return!1;return!0}function Co(i,e){for(let t=e,n=i.length-1;t<n;t++)i[t]=i[t+1];i.pop()}function vo(i,e,t){for(let n=i.length-1;n>=e;n--)i[n+1]=i[n];i[e]=t}function lp(i,e){let t=-1,n=1e9;for(let r=0;r<e.length;r++)(e[r]-n||i[r].endSide-i[t].endSide)<0&&(t=r,n=e[r]);return t}function Sr(i,e,t=i.length){let n=0;for(let r=0;r<t&&r<i.length;)i.charCodeAt(r)==9?(n+=e-n%e,r++):(n++,r=Re(i,r));return n}function Xh(i,e,t,n){for(let r=0,s=0;;){if(s>=e)return r;if(r==i.length)break;s+=i.charCodeAt(r)==9?t-s%t:1,r=Re(i,r)}return n===!0?-1:i.length}const Qh="ͼ",ap=typeof Symbol>"u"?"__"+Qh:Symbol.for(Qh),Zh=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),hp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Hn{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))s(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");s(r(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||u)&&a.push((n&&!f&&!h?o.map(n):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(r(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
|
39
|
-
`)}static newName(){let e=hp[ap]||1;return hp[ap]=e+1,Qh+e.toString(36)}static mount(e,t,n){let r=e[Zh],s=n&&n.nonce;r?s&&r.setNonce(s):r=new Nv(e,s),r.mount(Array.isArray(t)?t:[t],e)}}let cp=new Map;class Nv{constructor(e,t){let n=e.ownerDocument||e,r=n.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let s=cp.get(n);if(s)return e[Zh]=s;this.sheet=new r.CSSStyleSheet,cp.set(n,this)}else this.styleTag=n.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[Zh]=this}mount(e,t){let n=this.sheet,r=0,s=0,o=!1;for(let l=0;l<e.length;l++){let a=e[l],h=this.modules.indexOf(a);if(h<s&&h>-1&&(this.modules.splice(h,1),o=!0,s--,h=-1),h==-1){if(this.modules.splice(s++,0,a),o=!0,n)for(let c=0;c<a.rules.length;c++)n.insertRule(a.rules[c],r++)}else{for(;s<h;)r+=this.modules[s++].rules.length;r+=a.rules.length,s++}}if(n)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{if(o){let a="";for(let h=0;h<this.modules.length;h++)a+=this.modules[h].getRules()+`
|
|
40
|
-
`;this.styleTag.textContent=a}let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}function Ei(){var i=arguments[0];typeof i=="string"&&(i=document.createElement(i));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=t[n];typeof r=="string"?i.setAttribute(n,r):r!=null&&(i[n]=r)}e++}for(;e<arguments.length;e++)oy(i,arguments[e]);return i}function oy(i,e){if(typeof e=="string")i.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)i.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)oy(i,e[t]);else throw new RangeError("Unsupported child node: "+e)}let He=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},ec=typeof document<"u"?document:{documentElement:{style:{}}};const tc=/Edge\/(\d+)/.exec(He.userAgent),ly=/MSIE \d/.test(He.userAgent),nc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(He.userAgent),Ul=!!(ly||nc||tc),fp=!Ul&&/gecko\/(\d+)/i.test(He.userAgent),$a=!Ul&&/Chrome\/(\d+)/.exec(He.userAgent),up="webkitFontSmoothing"in ec.documentElement.style,ic=!Ul&&/Apple Computer/.test(He.vendor),dp=ic&&(/Mobile\/\w+/.test(He.userAgent)||He.maxTouchPoints>2);var N={mac:dp||/Mac/.test(He.platform),windows:/Win/.test(He.platform),linux:/Linux|X11/.test(He.platform),ie:Ul,ie_version:ly?ec.documentMode||6:nc?+nc[1]:tc?+tc[1]:0,gecko:fp,gecko_version:fp?+(/Firefox\/(\d+)/.exec(He.userAgent)||[0,0])[1]:0,chrome:!!$a,chrome_version:$a?+$a[1]:0,ios:dp,android:/Android\b/.test(He.userAgent),webkit:up,webkit_version:up?+(/\bAppleWebKit\/(\d+)/.exec(He.userAgent)||[0,0])[1]:0,safari:ic,safari_version:ic?+(/\bVersion\/(\d+(\.\d+)?)/.exec(He.userAgent)||[0,0])[1]:0,tabSize:ec.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function af(i,e){for(let t in i)t=="class"&&e.class?e.class+=" "+i.class:t=="style"&&e.style?e.style+=";"+i.style:e[t]=i[t];return e}const yl=Object.create(null);function hf(i,e,t){if(i==e)return!0;i||(i=yl),e||(e=yl);let n=Object.keys(i),r=Object.keys(e);if(n.length-0!=r.length-0)return!1;for(let s of n)if(s!=t&&(r.indexOf(s)==-1||i[s]!==e[s]))return!1;return!0}function Dv(i,e){for(let t=i.attributes.length-1;t>=0;t--){let n=i.attributes[t].name;e[n]==null&&i.removeAttribute(n)}for(let t in e){let n=e[t];t=="style"?i.style.cssText=n:i.getAttribute(t)!=n&&i.setAttribute(t,n)}}function pp(i,e,t){let n=!1;if(e)for(let r in e)t&&r in t||(n=!0,r=="style"?i.style.cssText="":i.removeAttribute(r));if(t)for(let r in t)e&&e[r]==t[r]||(n=!0,r=="style"?i.style.cssText=t[r]:i.setAttribute(r,t[r]));return n}function Iv(i){let e=Object.create(null);for(let t=0;t<i.attributes.length;t++){let n=i.attributes[t];e[n.name]=n.value}return e}class gn{eq(e){return!1}updateDOM(e,t,n){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var Te=(function(i){return i[i.Text=0]="Text",i[i.WidgetBefore=1]="WidgetBefore",i[i.WidgetAfter=2]="WidgetAfter",i[i.WidgetRange=3]="WidgetRange",i})(Te||(Te={}));class J extends Vn{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new no(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new xi(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:s,end:o}=ay(e,t);n=(s?t?-3e8:-1:5e8)-1,r=(o?t?2e8:1:-6e8)+1}return new xi(e,n,r,t,e.widget||null,!0)}static line(e){return new io(e)}static set(e,t=!1){return $.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}J.none=$.empty;class no extends J{constructor(e){let{start:t,end:n}=ay(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?af(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||yl}eq(e){return this==e||e instanceof no&&this.tagName==e.tagName&&hf(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}no.prototype.point=!1;class io extends J{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof io&&this.spec.class==e.spec.class&&hf(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}io.prototype.mapMode=Ae.TrackBefore;io.prototype.point=!0;class xi extends J{constructor(e,t,n,r,s,o){super(t,n,s,e),this.block=r,this.isReplace=o,this.mapMode=r?t<=0?Ae.TrackBefore:Ae.TrackAfter:Ae.TrackDel}get type(){return this.startSide!=this.endSide?Te.WidgetRange:this.startSide<=0?Te.WidgetBefore:Te.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof xi&&Ev(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}xi.prototype.point=!0;function ay(i,e=!1){let{inclusiveStart:t,inclusiveEnd:n}=i;return t==null&&(t=i.inclusive),n==null&&(n=i.inclusive),{start:t??e,end:n??e}}function Ev(i,e){return i==e||!!(i&&e&&i.compare(e))}function ji(i,e,t,n=0){let r=t.length-1;r>=0&&t[r]+n>=i?t[r]=Math.max(t[r],e):t.push(i,e)}class Ns extends Vn{constructor(e,t,n){super(),this.tagName=e,this.attributes=t,this.rank=n}eq(e){return e==this||e instanceof Ns&&this.tagName==e.tagName&&hf(this.attributes,e.attributes)}static create(e){return new Ns(e.tagName,e.attributes||yl,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return $.of(e,t)}}Ns.prototype.startSide=Ns.prototype.endSide=-1;const xe=i=>i.nodeType==1,cr=i=>i.nodeType==3;function Ds(i){let e;return i.nodeType==11?e=i.getSelection?i:i.ownerDocument:e=i,e.getSelection()}function rc(i,e){return e?i==e||i.contains(e.nodeType!=1?e.parentNode:e):!1}function ss(i,e){if(!e.anchorNode)return!1;try{return rc(i,e.anchorNode)}catch{return!1}}function Zo(i){return cr(i)?Is(i,0,i.nodeValue.length).getClientRects():xe(i)?i.getClientRects():[]}function ls(i,e,t,n){return t?mp(i,e,t,n,-1)||mp(i,e,t,n,1):!1}function Wn(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e}function bl(i){return xe(i)&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(i.nodeName)}function mp(i,e,t,n,r){for(;;){if(i==t&&e==n)return!0;if(e==(r<0?0:cn(i))){if(i.nodeName=="DIV")return!1;let s=i.parentNode;if(!s||!xe(s))return!1;e=Wn(i)+(r<0?0:1),i=s}else if(xe(i)){if(i=i.childNodes[e+(r<0?-1:0)],xe(i)&&(i.nodeName=="IMG"||i.nodeName=="BR"||i.contentEditable=="false"))return!1;e=r<0?cn(i):0}else return!1}}function cn(i){return cr(i)?i.nodeValue.length:i.childNodes.length}function kl(i,e){let{left:t,right:n}=i;if(t==n)return i;let r=e?t:n;return{left:r,right:r,top:i.top,bottom:i.bottom}}function Rv(i){let e=i.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function hy(i,e){let t=e.width/i.offsetWidth,n=e.height/i.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-i.offsetWidth)<1)&&(t=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-i.offsetHeight)<1)&&(n=1),{scaleX:t,scaleY:n}}function Bv(i,e,t,n,r,s,o,l){let a=i.ownerDocument,h=a.defaultView||window;for(let c=i,f=!1;c&&!f;)if(xe(c)){let u,d=c==a.body,p=1,m=1,g=!0,y=!0;if(d)u=Rv(h);else{let O=getComputedStyle(c);if(/^(fixed|sticky)$/.test(O.position)&&(f=!0),(c.scrollHeight<=c.clientHeight||!/auto|scroll/.test(O.overflowY))&&(y=!1),(c.scrollWidth<=c.clientWidth||!/auto|scroll/.test(O.overflowX))&&(g=!1),!g&&!y){c=c.assignedSlot||c.parentNode;continue}let w=c.getBoundingClientRect();({scaleX:p,scaleY:m}=hy(c,w)),u={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*m}}let b=0,k=0;if(y)if(r=="nearest")e.top<u.top+o?(k=e.top-(u.top+o),t>0&&e.bottom>u.bottom+k&&(k=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(k=e.bottom-u.bottom+o,t<0&&e.top-k<u.top&&(k=e.top-(u.top+o)));else{let O=e.bottom-e.top,w=u.bottom-u.top;k=(r=="center"&&O<=w?e.top+O/2-w/2:r=="start"||r=="center"&&t<0?e.top-o:e.bottom-w+o)-u.top}if(g&&(n=="nearest"?e.left<u.left+s?(b=e.left-(u.left+s),t>0&&e.right>u.right+b&&(b=e.right-u.right+s)):e.right>u.right-s&&(b=e.right-u.right+s,t<0&&e.left<u.left+b&&(b=e.left-(u.left+s))):b=(n=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:n=="start"==l?e.left-s:e.right-(u.right-u.left)+s)-u.left),b||k)if(d)h.scrollBy(b,k);else{let O=0,w=0;if(k){let M=c.scrollTop;c.scrollTop+=k/m,w=(c.scrollTop-M)*m}if(b){let M=c.scrollLeft;c.scrollLeft+=b/p,O=(c.scrollLeft-M)*p}e={left:e.left-O,top:e.top-w,right:e.right-O,bottom:e.bottom-w},O&&Math.abs(O-b)<1&&(n="nearest"),w&&Math.abs(w-k)<1&&(r="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function cy(i,e=!0){let t=i.ownerDocument,n=null,r=null;for(let s=i.parentNode;s&&!(s==t.body||(!e||n)&&r);)if(xe(s))!r&&s.scrollHeight>s.clientHeight&&/scroll|auto/.test(getComputedStyle(s).overflowY)&&(r=s),e&&!n&&s.scrollWidth>s.clientWidth&&/scroll|auto/.test(getComputedStyle(s).overflowX)&&(n=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:n,y:r}}class Pv{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?cn(t):0),n,Math.min(e.focusOffset,n?cn(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}}function fy(i){let e=[];for(let t=i;t;t=t.nodeType==11?t.host:t.parentNode)xe(t)&&e.push({node:t,left:t.scrollLeft,top:t.scrollTop});return e}function uy(i,e=!0){for(let{node:t,left:n,top:r}of i)e&&t.scrollTop!=r&&(t.scrollTop=r),t.scrollLeft!=n&&(t.scrollLeft=n)}let Xn=null;N.safari&&N.safari_version>=26&&(Xn=!1);function dy(i){if(i.setActive)return i.setActive();if(Xn)return i.focus(Xn);let e=fy(i);i.focus(Xn==null?{get preventScroll(){return Xn={preventScroll:!0},!0}}:void 0),Xn||(Xn=!1,uy(e))}let gp;function Is(i,e,t=e){let n=gp||(gp=document.createRange());return n.setEnd(i,t),n.setStart(i,e),n}function Ji(i,e,t,n){let r={key:e,code:e,keyCode:t,which:t,cancelable:!0};n&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=n);let s=new KeyboardEvent("keydown",r);s.synthetic=!0,i.dispatchEvent(s);let o=new KeyboardEvent("keyup",r);return o.synthetic=!0,i.dispatchEvent(o),s.defaultPrevented||o.defaultPrevented}function Lv(i){for(;i;){if(i&&(i.nodeType==9||i.nodeType==11&&i.host))return i;i=i.assignedSlot||i.parentNode}return null}function Fv(i,e){let t=e.focusNode,n=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=n)return!1;for(n=Math.min(n,cn(t));;)if(n){if(!xe(t))return!1;let r=t.childNodes[n-1];r.contentEditable=="false"?n--:(t=r,n=cn(t))}else{if(t==i)return!0;n=Wn(t),t=t.parentNode}}function py(i){return i instanceof Window?i.pageYOffset>Math.max(0,i.document.documentElement.scrollHeight-i.innerHeight-4):i.scrollTop>Math.max(1,i.scrollHeight-i.clientHeight-4)}function my(i,e){for(let t=i,n=e;;){if(cr(t)&&n>0)return{node:t,offset:n};if(xe(t)&&n>0){if(t.contentEditable=="false")return null;t=t.childNodes[n-1],n=cn(t)}else if(t.parentNode&&!bl(t))n=Wn(t),t=t.parentNode;else return null}}function gy(i,e){for(let t=i,n=e;;){if(cr(t)&&n<t.nodeValue.length)return{node:t,offset:n};if(xe(t)&&n<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[n],n=0}else if(t.parentNode&&!bl(t))n=Wn(t)+1,t=t.parentNode;else return null}}class vt{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(e,t){return new vt(e.parentNode,Wn(e),t)}static after(e,t){return new vt(e.parentNode,Wn(e)+1,t)}}var Z=(function(i){return i[i.LTR=0]="LTR",i[i.RTL=1]="RTL",i})(Z||(Z={}));const fr=Z.LTR,cf=Z.RTL;function yy(i){let e=[];for(let t=0;t<i.length;t++)e.push(1<<+i[t]);return e}const zv=yy("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Vv=yy("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),sc=Object.create(null),Bt=[];for(let i of["()","[]","{}"]){let e=i.charCodeAt(0),t=i.charCodeAt(1);sc[e]=t,sc[t]=-e}function by(i){return i<=247?zv[i]:1424<=i&&i<=1524?2:1536<=i&&i<=1785?Vv[i-1536]:1774<=i&&i<=2220?4:8192<=i&&i<=8204?256:64336<=i&&i<=65023?4:1}const Hv=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class $t{get dir(){return this.level%2?cf:fr}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let s=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==n)return o;(s<0||(r!=0?r<0?l.from<t:l.to>t:e[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}}function ky(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++){let n=i[t],r=e[t];if(n.from!=r.from||n.to!=r.to||n.direction!=r.direction||!ky(n.inner,r.inner))return!1}return!0}const ne=[];function Wv(i,e,t,n,r){for(let s=0;s<=n.length;s++){let o=s?n[s-1].to:e,l=s<n.length?n[s].from:t,a=s?256:r;for(let h=o,c=a,f=a;h<l;h++){let u=by(i.charCodeAt(h));u==512?u=c:u==8&&f==4&&(u=16),ne[h]=u==4?2:u,u&7&&(f=u),c=u}for(let h=o,c=a,f=a;h<l;h++){let u=ne[h];if(u==128)h<l-1&&c==ne[h+1]&&c&24?u=ne[h]=c:ne[h]=256;else if(u==64){let d=h+1;for(;d<l&&ne[d]==64;)d++;let p=h&&c==8||d<t&&ne[d]==8?f==1?1:8:256;for(let m=h;m<d;m++)ne[m]=p;h=d-1}else u==8&&f==1&&(ne[h]=1);c=u,u&7&&(f=u)}}}function $v(i,e,t,n,r){let s=r==1?2:1;for(let o=0,l=0,a=0;o<=n.length;o++){let h=o?n[o-1].to:e,c=o<n.length?n[o].from:t;for(let f=h,u,d,p;f<c;f++)if(d=sc[u=i.charCodeAt(f)])if(d<0){for(let m=l-3;m>=0;m-=3)if(Bt[m+1]==-d){let g=Bt[m+2],y=g&2?r:g&4?g&1?s:r:0;y&&(ne[f]=ne[Bt[m]]=y),l=m;break}}else{if(Bt.length==189)break;Bt[l++]=f,Bt[l++]=u,Bt[l++]=a}else if((p=ne[f])==2||p==1){let m=p==r;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=Bt[g+2];if(y&2)break;if(m)Bt[g+2]|=2;else{if(y&4)break;Bt[g+2]|=4}}}}}function Kv(i,e,t,n){for(let r=0,s=n;r<=t.length;r++){let o=r?t[r-1].to:i,l=r<t.length?t[r].from:e;for(let a=o;a<l;){let h=ne[a];if(h==256){let c=a+1;for(;;)if(c==l){if(r==t.length)break;c=t[r++].to,l=r<t.length?t[r].from:e}else if(ne[c]==256)c++;else break;let f=s==1,u=(c<e?ne[c]:n)==1,d=f==u?f?1:2:n;for(let p=c,m=r,g=m?t[m-1].to:i;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:i),ne[--p]=d;a=c}else s=h,a++}}}function oc(i,e,t,n,r,s,o){let l=n%2?2:1;if(n%2==r%2)for(let a=e,h=0;a<t;){let c=!0,f=!1;if(h==s.length||a<s[h].from){let m=ne[a];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?n:n+1,p=a;e:for(;;)if(h<s.length&&p==s[h].from){if(f)break e;let m=s[h];if(!c)for(let g=m.to,y=h+1;;){if(g==t)break e;if(y<s.length&&s[y].from==g)g=s[y++].to;else{if(ne[g]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new $t(a,m.from,d));let g=m.direction==fr!=!(d%2);lc(i,g?n+1:n,r,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?ne[p]!=l:ne[p]==l))break;p++}u?oc(i,a,p,n+1,r,u,o):a<p&&o.push(new $t(a,p,d)),a=p}else for(let a=t,h=s.length;a>e;){let c=!0,f=!1;if(!h||a>s[h-1].to){let m=ne[a-1];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?n:n+1,p=a;e:for(;;)if(h&&p==s[h-1].to){if(f)break e;let m=s[--h];if(!c)for(let g=m.from,y=h;;){if(g==e)break e;if(y&&s[y-1].to==g)g=s[--y].from;else{if(ne[g-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new $t(m.to,a,d));let g=m.direction==fr!=!(d%2);lc(i,g?n+1:n,r,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(c?ne[p-1]!=l:ne[p-1]==l))break;p--}u?oc(i,p,a,n+1,r,u,o):p<a&&o.push(new $t(p,a,d)),a=p}}function lc(i,e,t,n,r,s,o){let l=e%2?2:1;Wv(i,r,s,n,l),$v(i,r,s,n,l),Kv(r,s,n,l),oc(i,r,s,e,t,n,o)}function qv(i,e,t){if(!i)return[new $t(0,0,e==cf?1:0)];if(e==fr&&!t.length&&!Hv.test(i))return xy(i.length);if(t.length)for(;i.length>ne.length;)ne[ne.length]=256;let n=[],r=e==fr?0:1;return lc(i,r,r,t,0,i.length,n),n}function xy(i){return[new $t(0,i,0)]}let wy="";function jv(i,e,t,n,r){var s;if(!i.length)return null;let o=n.head-i.from,l;if(n.head==i.from&&n.assoc<0){if(!r)return null;o=e[l=0].side(!1,t)}else if(n.head==i.to&&n.assoc>0){if(r)return null;o=e[l=e.length-1].side(!0,t)}else l=$t.find(e,o,(s=n.bidiLevel)!==null&&s!==void 0?s:-1,n.assoc);let a=e[l],h=a.side(r,t);if(o==h){let u=l+=r?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!r,t),h=a.side(r,t)}let c=Re(i.text,o,a.forward(r,t));(c<a.from||c>a.to)&&(c=h),wy=i.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(r?e.length-1:0)?null:e[l+(r?1:-1)];if(c==h){if(!f)return r?S.cursor(i.to,1):S.cursor(i.from,-1);if(f.level+(r?0:1)<a.level)return S.cursor(f.side(!r,t)+i.from,f.forward(r,t)?1:-1,f.level)}return S.cursor(c+i.from,a.forward(r,t)?-1:1,a.level)}function Jv(i,e,t){for(let n=e;n<t;n++){let r=by(i.charCodeAt(n));if(r==1)return fr;if(r==2||r==4)return cf}}const Sy=D.define(),Cy=D.define(),vy=D.define(),My=D.define(),ac=D.define(),Ay=D.define(),Oy=D.define(),ff=D.define(),uf=D.define(),Ty=D.define({combine:i=>i.some(e=>e)}),Ny=D.define({combine:i=>i.some(e=>e)}),Dy=D.define();class _i{constructor(e,t,n,r,s,o=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new _i(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new _i(S.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Mo=V.define({map:(i,e)=>i.map(e)}),Iy=V.define();function Qe(i,e,t){let n=i.facet(My);n.length?n[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const en=D.define({combine:i=>i.length?i[0]:!0});let _v=0;const zi=D.define({combine(i){return i.filter((e,t)=>{for(let n=0;n<t;n++)if(i[n].plugin==e.plugin)return!1;return!0})}});class be{constructor(e,t,n,r,s){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(zi.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(zi.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:n,eventObservers:r,provide:s,decorations:o}=t||{};return new be(_v++,e,n,r,l=>{let a=[];return o&&a.push(Gl.of(h=>{let c=h.plugin(l);return c?o(c):J.none})),s&&a.push(s(l)),a})}static fromClass(e,t){return be.define((n,r)=>new e(n,r),t)}}class Ka{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(n){if(Qe(t.state,n,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Qe(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(n){Qe(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ey=D.define(),df=D.define(),Gl=D.define(),Ry=D.define(),pf=D.define(),ro=D.define(),By=D.define();function yp(i,e){let t=i.state.facet(By);if(!t.length)return t;let n=t.map(s=>s instanceof Function?s(i):s),r=[];return $.spans(n,e.from,e.to,{point(){},span(s,o,l,a){let h=s-e.from,c=o-e.from,f=r;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==d)p.to=c,f=p.inner;else{let m={from:h,to:c,direction:d,inner:[]};f.push(m),f=m.inner}}}}),Py(e.text,r)}function Py(i,e){for(let t of e){if(t.direction==null){for(let n=t.from,r=0;n<t.to;r++){let s=r<t.inner.length?t.inner[r]:null,o=Jv(i,n,s?s.from:t.to);if(o){t.direction=o;break}if(!s)break;n=s.to}t.direction==null&&(t.direction=Z.LTR)}Py(i,t.inner)}return e}const Ly=D.define();function mf(i){let e=0,t=0,n=0,r=0;for(let s of i.state.facet(Ly)){let o=s(i);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(n=Math.max(n,o.top)),o.bottom!=null&&(r=Math.max(r,o.bottom)))}return{left:e,right:t,top:n,bottom:r}}const $r=D.define();class dt{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(e){return new dt(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toA<n.fromA)break;n=n.join(r),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(e,t){if(t.length==0)return e;let n=[];for(let r=0,s=0,o=0;;){let l=r<e.length?e[r].fromB:1e9,a=s<t.length?t[s]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+o,f=h,u=c;for(;;)if(s<t.length&&t[s]<=f){let d=t[s+1];s+=2,f=Math.max(f,d);for(let p=r;p<e.length&&e[p].fromB<=f;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(r<e.length&&e[r].fromB<=f){let d=e[r++];f=Math.max(f,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;n.push(new dt(c,u,h,f))}return n}}class xl{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=me.empty(this.startState.doc.length);for(let s of n)this.changes=this.changes.compose(s.changes);let r=[];this.changes.iterChangedRanges((s,o,l,a)=>r.push(new dt(s,o,l,a))),this.changedRanges=r}static create(e,t,n){return new xl(e,t,n)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const Uv=[];class he{constructor(e,t,n=0){this.dom=e,this.length=t,this.flags=n,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return Uv}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&Dv(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let n=t;for(let r of this.children){if(r==e)return n;n+=r.length+r.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,n){return null}domPosFor(e,t){let n=Wn(this.dom),r=this.length?e>0:t>0;return new vt(this.parent.dom,n+(r?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Xl)return e;return null}static get(e){return e.cmTile}}class Yl extends he{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,n=null,r,s=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,r=n?n.nextSibling:t.firstChild,s&&r!=l.dom&&(s.written=!0),l.dom.parentNode==t)for(;r&&r!=l.dom;)r=bp(r);else t.insertBefore(l.dom,r);n=l.dom}for(r=n?n.nextSibling:t.firstChild,s&&r&&(s.written=!0);r;)r=bp(r);this.length=o}}function bp(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}class Xl extends Yl{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=he.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],n=this,r=0,s=0;;)if(r==n.children.length){if(!t.length)return;n=n.parent,n.breakAfter&&s++,r=t.pop()}else{let o=n.children[r++];if(o instanceof an)t.push(r),n=o,r=0;else{let l=s+o.length,a=e(o,s);if(a!==void 0)return a;s=l+o.breakAfter}}}resolveBlock(e,t){let n,r=-1,s,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(e>=a&&e<=h){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(n=void 0)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!n||!l.isWidget()&&n.isWidget())&&(n=l,r=e-a),(h>e||e==a&&(t>1?l.length:l.covers(-1)))&&(!s||!l.isWidget()&&s.isWidget())&&(s=l,o=e-a)}}),!n&&!s)throw new Error("No tile at position "+e);return n&&t<0||!s?{tile:n,offset:r}:{tile:s,offset:o}}}class an extends Yl{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let n=new an(t||document.createElement(e.tagName),e);return t||(n.flags|=4),n}}class ur extends Yl{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,n){let r=new ur(t||document.createElement("div"),e);return(!t||!n)&&(r.flags|=4),r}get domAttrs(){return this.attrs}resolveInline(e,t,n=!1){let r=null,s=-1,o=null,l=-1;function a(c,f){for(let u=0,d=0;u<c.children.length&&d<=f;u++){let p=c.children[u],m=d+p.length;m>=f&&(p.isComposite()?a(p,f-d):(!o||n&&o.isHidden&&(t>0&&!(o.flags&32)||n&&Yv(o,p)))&&(m>f||p.flags&32&&t<=1)?(o=p,l=f-d):(d<f||p.flags&16&&!(n&&p.isHidden)&&t>=-1)&&(r=p,s=f-d)),d=m}}a(this,e);let h=(t<0?r:o)||r||o;return h?{tile:h,offset:h==r?s:l}:null}coordsIn(e,t,n){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t,n):Gv(this)}domIn(e,t){let n=this.resolveInline(e,t);if(n){let{tile:r,offset:s}=n;if(this.dom.contains(r.dom))return r.isText()?new vt(r.dom,Math.min(r.dom.nodeValue.length,s)):r.domPosFor(s,r.flags&16?1:r.flags&32?-1:t);let o=n.tile.parent,l=!1;for(let a of o.children){if(l)return new vt(a.dom,0);a==n.tile&&(l=!0)}}return new vt(this.dom,0)}}function Gv(i){let e=i.dom.lastChild;if(!e)return i.dom.getBoundingClientRect();let t=Zo(e);return t[t.length-1]||null}function Yv(i,e){let t=i.coordsIn(0,1),n=e.coordsIn(0,1);return t&&n&&n.top<t.bottom}class Xe extends Yl{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let n=new Xe(t||document.createElement(e.tagName),e);return t||(n.flags|=4),n}}class ti extends he{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,n){let r=this.dom.nodeValue.length;e>r&&(e=r);let s=e,o=e,l=0;e==0&&t<0||e==r&&t>=0?N.chrome||N.gecko||(e?(s--,l=1):o<r&&(o++,l=-1)):t<0?s--:o<r&&o++;let a=Is(this.dom,s,o).getClientRects();if(!a.length)return null;let h=a[(l?l<0:t>=0)?0:a.length-1];return N.safari&&!l&&h.width==0&&(h=Array.prototype.find.call(a,c=>c.width)||h),n==null?h:kl(h,(l?l>0:t<0)==n)}static of(e,t){let n=new ti(t||document.createTextNode(e),e);return t||(n.flags|=2),n}}class wi extends he{constructor(e,t,n,r){super(e,t,r),this.widget=n}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,n){let r=this.widget.coordsAt(this.dom,e,t);if(r)return r;if(n)return kl(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),o=null;if(!s.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?s.length-1:0;o=s[a],!(e>0?a==0:a==s.length-1||o.top<o.bottom);a+=l?-1:1);return kl(o,!l)}}get overrideDOMText(){if(!this.length)return U.empty;let{root:e}=this;if(!e)return U.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,n,r,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new wi(s,n,e,r)}}class wl extends he{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return U.empty}coordsIn(e,t,n){let r=this.dom.getBoundingClientRect();return n==null?r:kl(r,t>0==n)}}class Xv{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,n){let{tile:r,index:s,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(r.isComposite())if(o){if(!e)break;n&&n.break(),e--,o=!1}else if(s==r.children.length){if(!e&&!l.length)break;n&&n.leave(r),o=!!r.breakAfter,{tile:r,index:s}=l.pop(),s++}else{let a=r.children[s],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!n||n.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,s++,e-=a.length):(l.push({tile:r,index:s}),r=a,s=0,n&&a.isComposite()&&n.enter(a))}else{let a=r.length;if(s<a&&e){let h=Math.min(e,a-s);n&&n.skip(r,s,s+h),e-=h,s+=h}if(s==a)o=!!r.breakAfter,{tile:r,index:s}=l.pop(),s++;else if(!e)break}return this.tile=r,this.index=s,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class Qv{constructor(e,t,n,r){this.from=e,this.to=t,this.wrapper=n,this.rank=r}}class Zv{constructor(e,t,n){this.cache=e,this.root=t,this.blockWrappers=n,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,n,r){var s;this.flushBuffer();let o=this.ensureMarks(t,n),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new ti(l.dom,l.text+e);a.parent=o}else o.append(r||ti.of(e,(s=this.cache.find(ti))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let n=this.curLine;n.dom!=t.line.dom&&(n.setDOM(this.cache.reused.has(t.line)?qa(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let r=n;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],h=r.lastChild;if(h instanceof Xe&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(qa(a.dom)),r=h;else{let{dom:c}=a;this.cache.reused.get(a)&&he.get(a.dom)&&(c=qa(a.dom));let f=Xe.of(a.mark,c);r.append(f),r=f}this.cache.reused.set(a,2)}let s=he.get(e.text);s&&this.cache.reused.set(s,2);let o=new ti(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,r.append(o)}addInlineWidget(e,t,n){let r=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);r||this.flushBuffer();let s=this.ensureMarks(t,n);!r&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,n){this.flushBuffer(),this.ensureMarks(t,n).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var n;e||(e=Fy);let r=ur.start(e,t||((n=this.cache.find(ur))===null||n===void 0?void 0:n.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=r)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var n;let r=this.curLine;for(let s=e.length-1;s>=0;s--){let o=e[s],l;if(t>0&&(l=r.lastChild)&&l instanceof Xe&&l.mark.eq(o))r=l,t--;else{let a=Xe.of(o,(n=this.cache.find(Xe,h=>h.mark.eq(o)))===null||n===void 0?void 0:n.dom);r.append(a),r=a,t=0}}return r}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!kp(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(N.ios&&kp(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(ja,0,32)||new wi(ja.toDOM(),0,ja,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,n=new Qv(e.from,e.to,e.value,t),r=this.wrappers.length;for(;r>0&&(this.wrappers[r-1].rank-n.rank||this.wrappers[r-1].to-n.to)<0;)r--;this.wrappers.splice(r,0,n)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let n of this.wrappers){let r=t.lastChild;if(n.from<this.pos&&r instanceof an&&r.wrapper.eq(n.wrapper))t=r;else{let s=an.of(n.wrapper,(e=this.cache.find(an,o=>o.wrapper.eq(n.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),n=this.cache.find(wl,void 0,1);return n&&(n.flags=t),n||new wl(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class eM{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:r,lineBreak:s,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=r;let l=this.textOff=Math.min(e,r.length);return s?null:r.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),n=this.text.slice(this.textOff,t);return this.textOff=t,n}}const Sl=[wi,ur,ti,Xe,wl,an,Xl];for(let i=0;i<Sl.length;i++)Sl[i].bucket=i;class tM{constructor(e){this.view=e,this.buckets=Sl.map(()=>[]),this.index=Sl.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,n=this.buckets[t];n.length<6?n.push(e):n[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,n=2){let r=e.bucket,s=this.buckets[r],o=this.index[r];for(let l=0;l<s.length;l++){let a=(l+o)%s.length,h=s[a];if((!t||t(h))&&!this.reused.has(h))return s.splice(a,1),a<o&&this.index[r]--,this.reused.set(h,n),h}return null}findWidget(e,t,n){let r=this.buckets[0];if(r.length)for(let s=0,o=0;;s++){if(s==r.length){if(o)return null;o=1,s=0}let l=r[s];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return r.splice(s,1),s<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==n?(this.reused.set(l,1),l):(this.reused.set(l,2),new wi(l.dom,t,e,l.flags&-498|n))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class nM{constructor(e,t,n,r,s){this.view=e,this.decorations=r,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new tM(e),this.text=new eM(e.state.doc),this.builder=new Zv(this.cache,new Xl(e,e.contentDOM),$.iter(n)),this.cache.reused.set(t,2),this.old=new Xv(t),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let n=t&&this.getCompositionContext(t.text);for(let r=0,s=0,o=0;;){let l=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>r){let h=a-r;this.preserve(h,!o,!l),r=a,s+=h}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,n),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(s,l.toB)),s=l.toB,r=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,n){let r=sM(this.old),s=this.openMarks;this.old.advance(e,n?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?wi.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,r,s),s=r.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,r,s,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),r,s)),s=r.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof wl)this.cache.add(o);else if(o instanceof Xe)this.builder.ensureLine(null),this.builder.addMark(o,r,s),this.cache.reused.set(o,1),s=r.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof Xe&&r.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?r.length&&(r.length=s=0):o instanceof Xe&&(r.shift(),s=Math.min(s,r.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let n=null,r=this.builder,s=-1,o=$.spans(this.decorations,e,t,{point:(l,a,h,c,f,u)=>{if(h instanceof xi){if(this.disallowBlockEffectsFor[u]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,f>c.length)r.continueWidget(a-l);else{let d=h.widget||(h.block?dr.block:dr.inline),p=iM(h),m=this.cache.findWidget(d,a-l,p)||wi.of(d,this.view,a-l,p);h.block?(h.startSide>0&&r.addLineStartIfNotCovered(n),r.addBlockWidget(m)):(r.ensureLine(n),r.addInlineWidget(m,c,f))}n=null}else n=rM(n,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let u=this.text.next(Math.min(512,a-f));u==null?(r.addLineStartIfNotCovered(n),r.addBreak(),f++):(r.ensureLine(n),r.addText(u,h,f==l?c:h.length),f+=u.length),n=null}s=h.length}});s>-1&&(this.openWidget=o>s),this.openWidget||r.addLineStartIfNotCovered(n),this.openMarks=o}forward(e,t,n=1){t-e<=10?this.old.advance(t-e,n,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,n,this.reuseWalker))}getCompositionContext(e){let t=[],n=null;for(let r=e.parentNode;;r=r.parentNode){let s=he.get(r);if(r==this.view.contentDOM)break;s instanceof Xe?t.push(s):s?.isLine()?n=s:s instanceof an||(r.nodeName=="DIV"&&!n?n=new ur(r,Fy):n||t.push(Xe.of(new no({tagName:r.nodeName.toLowerCase(),attributes:Iv(r)}),r)))}return n?{line:n,marks:t}:null}}function kp(i,e){let t=n=>{for(let r of n.children)if((e?r.isText():r.length)||t(r))return!0;return!1};return t(i)}function iM(i){let e=i.isReplace?(i.startSide<0?64:0)|(i.endSide>0?128:0):i.startSide>0?32:16;return i.block&&(e|=256),e}const Fy={class:"cm-line"};function rM(i,e){let t=e.spec.attributes,n=e.spec.class;return!t&&!n||(i||(i={class:"cm-line"}),t&&af(t,i),n&&(i.class+=" "+n)),i}function sM(i){let e=[];for(let t=i.parents.length;t>1;t--){let n=t==i.parents.length?i.tile:i.parents[t].tile;n instanceof Xe&&e.push(n.mark)}return e}function qa(i){let e=he.get(i);return e&&e.setDOM(i.cloneNode()),i}class dr extends gn{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}dr.inline=new dr("span");dr.block=new dr("div");const ja=new class extends gn{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class xp{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=J.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Xl(e,e.contentDOM),this.updateInner([new dt(0,0,0,e.state.doc.length)],null)}update(e){var t;let n=e.changedRanges;this.minWidth>0&&n.length&&(n.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let r=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?r=this.domChanged.newSel.head:!pM(e.changes,this.hasComposition)&&!e.selectionSet&&(r=e.state.selection.main.head));let s=r>-1?lM(this.view,e.changes,r):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;n=new dt(c,f,e.changes.mapPos(c,-1),e.changes.mapPos(f,1)).addToSet(n.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(N.ie||N.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=cM(o,this.decorations,e.changes);a.length&&(n=dt.extendWithRanges(n,a));let h=uM(l,this.blockWrappers,e.changes);return h.length&&(n=dt.extendWithRanges(n,h)),s&&!n.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(n=s.range.addToSet(n.slice())),this.tile.flags&2&&n.length==0?!1:(this.updateInner(n,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:n}=this.view;n.ignore(()=>{if(t||e.length){let o=this.tile,l=new nM(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&he.get(t.text)&&l.cache.reused.set(he.get(t.text),2),this.tile=l.run(e,t),hc(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=N.chrome||N.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||n.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof Ja&&r.push(s.dom);n.updateGaps(r)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let n of t.effects)n.is(Iy)&&(this.editContextFormatting=n.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:n}=this.tile,r=this.view.root.activeElement,s=r==n,o=!s&&!(this.view.state.facet(en)||n.tabIndex>-1)&&ss(n,this.view.observer.selectionRange)&&!(r&&n.contains(r));if(!(s||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),N.gecko&&a.empty&&!this.hasComposition&&oM(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=c=new vt(u,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!ls(h.node,h.offset,f.anchorNode,f.anchorOffset)||!ls(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{N.android&&N.chrome&&n.contains(f.focusNode)&&dM(f.focusNode,n)&&(n.blur(),n.focus({preventScroll:!0}));let u=Ds(this.view.root);if(u)if(a.empty){if(N.gecko){let d=aM(h.node,h.offset);if(d&&d!=3){let p=(d==1?my:gy)(h.node,h.offset);p&&(h=new vt(p.node,p.offset))}}u.collapse(h.node,h.offset),a.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=a.bidiLevel)}else if(u.extend){u.collapse(h.node,h.offset);try{u.extend(c.node,c.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),d.setEnd(c.node,c.offset),d.setStart(h.node,h.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==n&&(n.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new vt(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new vt(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&ls(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=Ds(e.root),{anchorNode:r,anchorOffset:s}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);n.collapse(c.node,c.offset),n.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&n.collapse(r,s)}posFromDOM(e,t){let n=this.tile.nearest(e);if(!n)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let r=n.posAtStart;if(n.isComposite()){let s;if(e==n.dom)s=n.dom.childNodes[t];else{let o=cn(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==n.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?s=e:s=e.nextSibling}if(s==n.dom.firstChild)return r;for(;s&&!he.get(s);)s=s.nextSibling;if(!s)return r+n.length;for(let o=0,l=r;;o++){let a=n.children[o];if(a.dom==s)return l;l+=a.length+a.breakAfter}}else return n.isText()?e==n.dom?r+t:r+(t?n.length:0):r}domAtPos(e,t){let{tile:n,offset:r}=this.tile.resolveBlock(e,t);return n.isWidget()?n.domPosFor(r,t):n.domIn(r,t)}inlineDOMNearPos(e,t){let n,r=-1,s=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=e)return!0;h.flags&16&&(s=!0)}else{let f=c+h.length;if(c<=e&&(n=h,r=e-c,s=f<e),f>=e&&!o&&(o=h,l=e-c,a=c>e),c>e&&o)return!0}}),!n&&!o?this.domAtPos(e,t):(s&&o?n=null:a&&n&&(o=null),n&&t<0||!o?n.domIn(r,t):o.domIn(l,t))}coordsAt(e,t,n){let{tile:r,offset:s}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof Ja?null:r.coordsInWidget(s,t,!0):r.coordsIn(s,t,n)}lineAt(e,t){let{tile:n}=this.tile.resolveBlock(e,t);return n.isLine()?n:null}coordsForChar(e){let{tile:t,offset:n}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function r(s,o){if(s.isComposite())for(let l of s.children){if(l.length>=o){let a=r(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(s.isText()&&o<s.length){let l=Re(s.text,o);if(l==o)return null;let a=Is(s.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return r(t,n)}measureVisibleLineHeights(e){let t=[],{from:n,to:r}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==Z.LTR,h=0,c=(f,u,d)=>{for(let p=0;p<f.children.length&&!(u>r);p++){let m=f.children[p],g=u+m.length,y=m.dom.getBoundingClientRect(),{height:b}=y;if(d&&!p&&(h+=y.top-d.top),m instanceof an)g>n&&c(m,u,y);else if(u>=n&&(h>0&&t.push(-h),t.push(b+h),h=0,o)){let k=m.dom.lastChild,O=k?Zo(k):[];if(O.length){let w=O[O.length-1],M=a?w.right-y.left:y.right-w.left;M>l&&(l=M,this.minWidth=s,this.minWidthFrom=u,this.minWidthTo=g)}}d&&p==f.children.length-1&&(h+=d.bottom-y.bottom),u=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?Z.RTL:Z.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Zo(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),n,r,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Zo(t.firstChild)[0];n=t.getBoundingClientRect().height,r=o&&o.width?o.width/27:7,s=o&&o.height?o.height:n,t.remove()}),{lineHeight:n,charWidth:r,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let s=r==t.viewports.length?null:t.viewports[r],o=s?s.from-1:this.view.state.doc.length;if(o>n){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(J.replace({widget:new Ja(l),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!s)break;n=s.to+1}return J.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Gl).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),n=!1,r=this.view.state.facet(pf).map((s,o)=>{let l=typeof s=="function";return l&&(n=!0),l?s(this.view):s});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push($.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(Ry).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let h=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=h.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let h of this.view.state.facet(Dy))try{if(h(this.view,e.range,e))return!0}catch(c){Qe(this.view.state,c,"scroll handler")}let{range:t}=e,n=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let s=mf(this.view),o={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;if(Bv(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==Z.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.visualViewport.offsetTop)){let h=this.view.docView.lineAt(t.head,1);if(h){let c=fy(h.dom);h.dom.scrollIntoView({block:"nearest"}),uy(c,!1)}}}lineHasWidget(e){let t=n=>n.isWidget()||n.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){hc(this.tile)}}function hc(i,e){let t=e?.get(i);if(t!=1){t==null&&i.destroy();for(let n of i.children)hc(n,e)}}function oM(i){return xe(i.node)&&i.node.firstChild&&(i.offset==0||i.node.childNodes[i.offset-1].contentEditable=="false")&&(i.offset==i.node.childNodes.length||i.node.childNodes[i.offset].contentEditable=="false")}function zy(i,e){let t=i.observer.selectionRange;if(!t.focusNode)return null;let n=my(t.focusNode,t.focusOffset),r=gy(t.focusNode,t.focusOffset),s=n||r;if(r&&n&&r.node!=n.node){let l=he.get(r.node);if(!l||l.isText()&&l.text!=r.node.nodeValue)s=r;else if(i.docView.lastCompositionAfterCursor){let a=he.get(n.node);!a||a.isText()&&a.text!=n.node.nodeValue||(s=r)}}if(i.docView.lastCompositionAfterCursor=s!=n,!s)return null;let o=e-s.offset;return{from:o,to:o+s.node.nodeValue.length,node:s.node}}function lM(i,e,t){let n=zy(i,t);if(!n)return null;let{node:r,from:s,to:o}=n,l=r.nodeValue;if(/[\n\r]/.test(l)||i.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc;return{range:new dt(a.mapPos(s),a.mapPos(o),s,o),text:r}}function aM(i,e){return xe(i)?(e&&i.childNodes[e-1].contentEditable=="false"?1:0)|(e<i.childNodes.length&&i.childNodes[e].contentEditable=="false"?2:0):0}let hM=class{constructor(){this.changes=[]}compareRange(e,t){ji(e,t,this.changes)}comparePoint(e,t){ji(e,t,this.changes)}boundChange(e){ji(e,e,this.changes)}};function cM(i,e,t){let n=new hM;return $.compare(i,e,t,n),n.changes}class fM{constructor(){this.changes=[]}compareRange(e,t){ji(e,t,this.changes)}comparePoint(){}boundChange(e){ji(e,e,this.changes)}}function uM(i,e,t){let n=new fM;return $.compare(i,e,t,n),n.changes}function dM(i,e){for(let t=i;t&&t!=e;t=t.assignedSlot||t.parentNode)if(xe(t)&&t.contentEditable=="false")return!0;return!1}function pM(i,e){let t=!1;return e&&i.iterChangedRanges((n,r)=>{n<e.to&&r>e.from&&(t=!0)}),t}class Ja extends gn{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function mM(i,e,t=1){let n=i.charCategorizer(e),r=i.doc.lineAt(e),s=e-r.from;if(r.length==0)return S.cursor(e);s==0?t=1:s==r.length&&(t=-1);let o=s,l=s;t<0?o=Re(r.text,s,!1):l=Re(r.text,s);let a=n(r.text.slice(o,l));for(;o>0;){let h=Re(r.text,o,!1);if(n(r.text.slice(h,o))!=a)break;o=h}for(;l<r.length;){let h=Re(r.text,l);if(n(r.text.slice(l,h))!=a)break;l=h}return S.undirectionalRange(o+r.from,l+r.from)}function gM(i,e,t,n,r){let s=Math.round((n-e.left)*i.defaultCharacterWidth);if(i.lineWrapping&&t.height>i.defaultLineHeight*1.5){let l=i.viewState.heightOracle.textHeight,a=Math.floor((r-t.top-(i.defaultLineHeight-l)*.5)/l);s+=a*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+Xh(o,s,i.state.tabSize)}function cc(i,e,t){let n=i.lineBlockAt(e);if(Array.isArray(n.type)){let r;for(let s of n.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!r||s.type==Te.Text&&(r.type!=s.type||(t<0?s.from<e:s.to>e)))&&(r=s)}}return r||n}return n}function yM(i,e,t,n){let r=cc(i,e.head,e.assoc||-1),s=!n||r.type!=Te.Text||!(i.lineWrapping||r.widgetLineBreaks)?null:i.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head);if(s){let o=i.dom.getBoundingClientRect(),l=i.textDirectionAt(r.from),a=i.posAndSideAtCoords({x:t==(l==Z.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(a)return S.cursor(a.pos,a.assoc)}return S.cursor(t?r.to:r.from,t?1:-1)}function wp(i,e,t,n){let r=i.state.doc.lineAt(e.head),s=i.bidiSpans(r),o=i.textDirectionAt(r.from);for(let l=e,a=null;;){let h=jv(r,s,o,l,t),c=wy;if(!h){if(r.number==(t?i.state.doc.lines:1))return l;c=`
|
|
41
|
-
`,r=i.state.doc.line(r.number+(t?1:-1)),s=i.bidiSpans(r),h=t?S.cursor(r.from,-1):S.cursor(r.to,1)}if(a){if(!a(c))return l}else{if(!n)return h;a=n(c)}l=h}}function bM(i,e,t){let n=i.state.charCategorizer(e),r=n(t);return s=>{let o=n(s);return r==ut.Space&&(r=o),r==o}}function kM(i,e,t,n){let r=e.head,s=t?1:-1;if(r==(t?i.state.doc.length:0))return S.cursor(r,e.assoc);let o=e.goalColumn,l,a=i.contentDOM.getBoundingClientRect(),h=i.coordsAtPos(r,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=i.documentTop;if(h)o==null&&(o=h.left-a.left),l=s<0?h.top:h.bottom;else{let p=i.viewState.lineBlockAt(r);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(r-p.from))),l=(s<0?p.top:p.bottom)+c}let f=a.left+o,u=i.viewState.heightOracle.textHeight>>1,d=n??u;for(let p=0;;p+=u){let m=l+(d+p)*s,g=fc(i,{x:f,y:m},!1,s);if(t?m>a.bottom:m<a.top)return S.cursor(g.pos,g.assoc);let y=i.coordsAtPos(g.pos,g.assoc),b=y?(y.top+y.bottom)/2:0;if(!y||(t?b>l:b<l))return S.cursor(g.pos,g.assoc,void 0,o)}}function as(i,e,t){for(;;){let n=0;for(let r of i)r.between(e-1,e+1,(s,o,l)=>{if(e>s&&e<o){let a=n||t||(e-s<o-e?-1:1);e=a<0?s:o,n=a}});if(!n)return e}}function Vy(i,e){let t=null;for(let n=0;n<e.ranges.length;n++){let r=e.ranges[n],s=null;if(r.empty){let o=as(i,r.from,0);o!=r.from&&(s=S.cursor(o,-1))}else{let o=as(i,r.from,-1),l=as(i,r.to,1);(o!=r.from||l!=r.to)&&(r.undirectional?s=S.undirectionalRange(r.from,r.to):s=S.range(r.from==r.anchor?o:l,r.from==r.head?o:l))}s&&(t||(t=e.ranges.slice()),t[n]=s)}return t?S.create(t,e.mainIndex):e}function _a(i,e,t){let n=as(i.state.facet(ro).map(r=>r(i)),t.from,e.head>t.from?-1:1);return n==t.from?t:S.cursor(n,n<t.from?1:-1)}class Ht{constructor(e,t){this.pos=e,this.assoc=t}}function fc(i,e,t,n){let r=i.contentDOM.getBoundingClientRect(),s=r.top+i.viewState.paddingTop,{x:o,y:l}=e,a=l-s,h;for(;;){if(a<0)return new Ht(0,1);if(a>i.viewState.docHeight)return new Ht(i.state.doc.length,-1);if(h=i.elementAtHeight(a),n==null)break;if(h.type==Te.Text){if(n<0?h.to<i.viewport.from:h.from>i.viewport.to)break;let u=i.docView.coordsAt(n<0?h.from:h.to,n>0?-1:1);if(u&&(n<0?u.top<=a+s:u.bottom>=a+s))break}let f=i.viewState.heightOracle.textHeight/2;a=n>0?h.bottom+f:h.top-f}if(i.viewport.from>=h.to||i.viewport.to<=h.from){if(t)return null;if(h.type==Te.Text){let f=gM(i,r,h,o,l);return new Ht(f,f==h.from?1:-1)}}if(h.type!=Te.Text)return a<(h.top+h.bottom)/2?new Ht(h.from,1):new Ht(h.to,-1);let c=i.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=i.docView.lineAt(h.from,-2)),new xM(i,o,l,i.textDirectionAt(h.from)).scanTile(c,h.from)}class xM{constructor(e,t,n,r){this.view=e,this.x=t,this.y=n,this.baseDir=r,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[$t.find(r,e-n.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[$t.find(r,e-n.from,-1,t)].dir}bidiIn(e,t){let{spans:n,line:r}=this.bidiSpansAt(e);return n.length>1||n.length&&(n[0].level!=this.baseDir||n[0].to+r.from<t)}scan(e,t,n=!1){let r=0,s=e.length-1,o=new Set,l=this.bidiIn(e[0],e[s]),a,h,c=-1,f=1e9,u;e:for(;r<s;){let p=s-r,m=r+s>>1;t:if(o.has(m)){for(let b=1;b<p;b++){let k=m+b;if(k>=s&&(k-=p),!o.has(k)){m=k;break t}}break e}o.add(m);let g=t(m),y=0;if(g)for(let b=0;b<g.length;b++){let k=g[b];if(!(k.width==0&&g.length>1))if(k.bottom<this.y)(!a||a.bottom<k.bottom)&&(a=k),y=1;else if(k.top>this.y)(!h||h.top>k.top)&&(h=k),y=-1;else{let O=k.left>this.x?this.x-k.left:k.right<this.x?this.x-k.right:0,w=Math.abs(O);w<f&&(c=m,f=w,u=k),O&&(y=O<0==(this.baseDir==Z.LTR)?-1:1)}}y==-1&&(!l||this.baseDirAt(e[m],1))?s=m:y==1&&(!l||this.baseDirAt(e[m+1],-1))&&(r=m+1)}if(!u){if(!h&&!a)return{i:0,after:!1};let p=a&&(!h||this.y-a.bottom<h.top-this.y)?a:h;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(f&&!n){let{top:p,bottom:m}=u;if(a&&a.bottom>(p+p+m)/3)return this.y=a.bottom-1,this.scan(e,t,!0);if(h&&h.top<(p+m+m)/3)return this.y=h.top+1,this.scan(e,t,!0)}let d=(l?this.dirAt(e[c],1):this.baseDir)==Z.LTR;return{i:c,after:this.x>(u.left+u.right)/2==d}}scanText(e,t){let n=[];for(let s=0;s<e.length;s=Re(e.text,s))n.push(t+s);n.push(t+e.length);let r=this.scan(n,s=>{let o=n[s]-t,l=n[s+1]-t;return Is(e.dom,o,l).getClientRects()});return r.after?new Ht(n[r.i+1],-1):new Ht(n[r.i],1)}scanTile(e,t){if(!e.length)return new Ht(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let n=[t];for(let l=0,a=t;l<e.children.length;l++)n.push(a+=e.children[l].length);let r=this.scan(n,l=>{let a=e.children[l];return a.flags&48?null:(xe(a.dom)?a.dom:Is(a.dom,0,a.length)).getClientRects()}),s=e.children[r.i],o=n[r.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):r.after?new Ht(n[r.i+1],-1):new Ht(o,1)}}const Fi="";class wM{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(Y.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Fi}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r);let s=this.text.length;this.readNode(r);let o=he.get(r),l=r.nextSibling;if(l==t){o?.breakAfter&&!l&&n!=this.view.contentDOM&&this.lineBreak();break}let a=he.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:bl(r))||bl(l)&&(r.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!CM(l,t)&&this.lineBreak(),r=l}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,l;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(l=r.exec(t))&&(s=l.index,o=l[0].length),this.append(t.slice(n,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);n=s+o}}readNode(e){let t=he.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let r=n.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.value)}else cr(e)?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():xe(e)&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(cr(e)?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(SM(e,n.node,n.offset)?t:0))}}function SM(i,e,t){for(;;){if(!e||t<cn(e))return!1;if(e==i)return!0;t=Wn(e)+1,e=e.parentNode}}function CM(i,e){let t;for(;!(i==e||!i);i=i.nextSibling){let n=he.get(i);if(!n?.isWidget())return!1;n&&(t||(t=[])).push(n)}if(t)for(let n of t){let r=n.overrideDOMText;if(r?.length)return!1}return!0}class Sp{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class vM{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Hy(e.docView.tile,t,n,0))){let a=s||o?[]:AM(e),h=new wM(a,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=OM(a,this.bounds.from)}else{let a=e.observer.selectionRange,h=s&&s.node==a.focusNode&&s.offset==a.focusOffset||!rc(e.contentDOM,a.focusNode)?l.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),c=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!rc(e.contentDOM,a.anchorNode)?l.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),f=e.viewport;if((N.ios||N.chrome)&&h!=c&&Math.min(h,c)<=l.main.from&&Math.max(h,c)>=l.main.to&&(f.from>0||f.to<e.state.doc.length)){let u=Math.min(h,c),d=Math.max(h,c),p=f.from-u,m=f.to-d;(p==0||p==1||u==0)&&(m==0||m==-1||d==e.state.doc.length)&&(h=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(S.range(c,h));else if(e.lineWrapping&&c==h&&!(l.main.empty&&l.main.head==h)&&e.inputState.lastTouchTime>Date.now()-100){let u=e.coordsAtPos(h,-1),d=0;u&&(d=e.inputState.lastTouchY<=u.bottom?-1:1),this.newSel=S.create([S.cursor(h,d)])}else this.newSel=S.single(c,h)}}}function Hy(i,e,t,n){if(i.isComposite()){let r=-1,s=-1,o=-1,l=-1;for(let a=0,h=n,c=n;a<i.children.length;a++){let f=i.children[a],u=h+f.length;if(h<e&&u>t)return Hy(f,e,t,h);if(u>=e&&r==-1&&(r=a,s=h),h>t&&f.dom.parentNode==i.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:s,to:l<0?n+i.length:l,startDOM:(r?i.children[r-1].dom.nextSibling:null)||i.dom.firstChild,endDOM:o<i.children.length&&o>=0?i.children[o].dom:null}}else return i.isText()?{from:n,to:n+i.length,startDOM:i.dom,endDOM:i.dom.nextSibling}:null}function Wy(i,e){let t,{newSel:n}=e,{state:r}=i,s=r.selection.main,o=i.inputState.lastKeyTime>Date.now()-100?i.inputState.lastKeyCode:-1;if(e.bounds){let{from:l,to:a}=e.bounds,h=s.from,c=null;(o===8||N.android&&e.text.length<a-l)&&(h=s.to,c="end");let f=r.doc.sliceString(l,a,Fi),u,d;!s.empty&&s.from>=l&&s.to<=a&&(e.typeOver||f!=e.text)&&f.slice(0,s.from-l)==e.text.slice(0,s.from-l)&&f.slice(s.to-l)==e.text.slice(u=e.text.length-(f.length-(s.to-l)))?t={from:s.from,to:s.to,insert:U.of(e.text.slice(s.from-l,u).split(Fi))}:(d=$y(f,e.text,h-l,c))&&(N.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==Fi+Fi&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:U.of(e.text.slice(d.from,d.toB).split(Fi))})}else n&&(!i.hasFocus&&r.facet(en)||uc(n,s))&&(n=null);if(!t&&!n)return!1;if((N.mac||N.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&i.contentDOM.getAttribute("autocorrect")=="off"?(n&&t.insert.length==2&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:t.from,to:t.to,insert:U.of([t.insert.toString().replace("."," ")])}):r.doc.lineAt(s.from).to<s.to&&i.docView.lineHasWidget(s.to)&&i.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:r.toText(i.inputState.insertingText)}:N.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
42
|
-
`&&i.lineWrapping&&(n&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:s.from,to:s.to,insert:U.of([" "])}),t)return gf(i,t,n,o);if(n&&!uc(n,s)){let l=!1,a="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(l=!0),a=i.inputState.lastSelectionOrigin,a=="select.pointer"&&(n=Vy(r.facet(ro).map(h=>h(i)),n))),i.dispatch({selection:n,scrollIntoView:l,userEvent:a}),!0}else return!1}function gf(i,e,t,n=-1){if(N.ios&&i.inputState.flushIOSKey(e))return!0;let r=i.state.selection.main;if(N.android&&(e.to==r.to&&(e.from==r.from||e.from==r.from-1&&i.state.sliceDoc(e.from,r.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Ji(i.contentDOM,"Enter",13)||(e.from==r.from-1&&e.to==r.to&&e.insert.length==0||n==8&&e.insert.length<e.to-e.from&&e.to>r.head)&&Ji(i.contentDOM,"Backspace",8)||e.from==r.from&&e.to==r.to+1&&e.insert.length==0&&Ji(i.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();i.inputState.composing>=0&&i.inputState.composing++;let o,l=()=>o||(o=MM(i,e,t));return i.state.facet(Ay).some(a=>a(i,e.from,e.to,s,l))||i.dispatch(l()),!0}function MM(i,e,t){let n,r=i.state,s=r.selection.main,o=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let a=e.from<s.from?-1:1,h=a<0?s.from:s.to,c=as(r.facet(ro).map(f=>f(i)),h,a);e.from==c&&(o=c)}if(o>-1)n={changes:e,selection:S.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&i.inputState.composing<0){let a=s.from<e.from?r.sliceDoc(s.from,e.from):"",h=s.to>e.to?r.sliceDoc(e.to,s.to):"";n=r.replaceSelection(i.state.toText(a+e.insert.sliceString(0,void 0,i.state.lineBreak)+h))}else{let a=r.changes(e),h=t&&t.main.to<=a.newLength?t.main:void 0;if(r.selection.ranges.length>1&&(i.inputState.composing>=0||i.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=i.state.sliceDoc(e.from,e.to),f,u=t&&zy(i,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);f={from:u.from,to:u.to-p}}else f=i.state.doc.lineAt(s.head);let d=s.to-e.to;n=r.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,g=m-c.length;if(i.state.sliceDoc(g,m)!=c||m>=f.from&&g<=f.to)return{range:p};let y=r.changes({from:g,to:m,insert:e.insert}),b=p.to-s.to;return{changes:y,range:h?S.range(Math.max(0,h.anchor+b),Math.max(0,h.head+b)):p.map(y)}})}else n={changes:a,selection:h&&r.selection.replaceRange(h)}}let l="input.type";return(i.composing||i.inputState.compositionPendingChange&&i.inputState.compositionEndedAt>Date.now()-50)&&(i.inputState.compositionPendingChange=!1,l+=".compose",i.inputState.compositionFirstChange&&(l+=".start",i.inputState.compositionFirstChange=!1)),r.update(n,{userEvent:l,scrollIntoView:!0})}function $y(i,e,t,n){let r=Math.min(i.length,e.length),s=0;for(;s<r&&i.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==r&&i.length==e.length)return null;let o=i.length,l=e.length;for(;o>0&&l>0&&i.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(n=="end"){let a=Math.max(0,s-Math.min(o,l));t-=o+a-s}if(o<s&&i.length<e.length){let a=t<=s&&t>=o?s-t:0;s-=a,l=s+(l-o),o=s}else if(l<s){let a=t<=s&&t>=l?s-t:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function AM(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}=i.observer.selectionRange;return t&&(e.push(new Sp(t,n)),(r!=t||s!=n)&&e.push(new Sp(r,s))),e}function OM(i,e){if(i.length==0)return null;let t=i[0].pos,n=i.length==2?i[1].pos:t;return t<0||n<0?null:t==n?S.create([S.cursor(n+e,-1)]):S.single(t+e,n+e)}function uc(i,e){return e.head==i.main.head&&e.anchor==i.main.anchor}class TM{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,N.safari&&e.contentDOM.addEventListener("input",()=>null),N.gecko&&qM(e.contentDOM.ownerDocument)}handleEvent(e){!FM(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let r of n.observers)r(this.view,t);for(let r of n.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=DM(e),n=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,l=n[s];l&&o!=!l.handlers.length&&(r.removeEventListener(s,this.handleEvent),l=null),l||r.addEventListener(s,this.handleEvent,{passive:o})}for(let s in n)s!="scroll"&&!t[s]&&r.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&qy.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),N.android&&N.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(N.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(Ky.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||IM.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};t.shiftKey&&N.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&NM(this.view.win)&&(t.shiftKey=!1);let n=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t};return setTimeout(()=>{this.pendingIOSKey==n&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let t=this.pendingIOSKey;return!t||this.view.observer.pendingRecords().length||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Ji(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:N.safari&&!N.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function NM(i){return i.visualViewport?i.visualViewport.height*i.visualViewport.scale/i.document.documentElement.clientHeight<.85:!1}function Cp(i,e){return(t,n)=>{try{return e.call(i,n,t)}catch(r){Qe(t.state,r)}}}function DM(i){let e=Object.create(null);function t(n){return e[n]||(e[n]={observers:[],handlers:[]})}for(let n of i){let r=n.spec,s=r&&r.plugin.domEventHandlers,o=r&&r.plugin.domEventObservers;if(s)for(let l in s){let a=s[l];a&&t(l).handlers.push(Cp(n.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(Cp(n.value,a))}}for(let n in At)t(n).handlers.push(At[n]);for(let n in Je)t(n).observers.push(Je[n]);return e}const Ky=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],IM="dthko",qy=[16,17,18,20,91,92,224,225],Ao=6;function Oo(i){return Math.max(0,i)*.7+8}function EM(i,e){return Math.max(Math.abs(i.clientX-e.clientX),Math.abs(i.clientY-e.clientY))}class RM{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=cy(e.contentDOM),this.atoms=e.state.facet(ro).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Y.allowMultipleSelections)&&BM(e,t),this.dragging=LM(e,t)&&_y(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&EM(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,s=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=mf(this.view);e.clientX-a.left<=r+Ao?t=-Oo(r-e.clientX):e.clientX+a.right>=o-Ao&&(t=Oo(e.clientX-o)),e.clientY-a.top<=s+Ao?n=-Oo(s-e.clientY):e.clientY+a.bottom>=l-Ao&&(n=Oo(e.clientY-l)),this.setScrollSpeed(t,n)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,n=Vy(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!n.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:n,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function BM(i,e){let t=i.state.facet(Sy);return t.length?t[0](e):N.mac?e.metaKey:e.ctrlKey}function PM(i,e){let t=i.state.facet(Cy);return t.length?t[0](e):N.mac?!e.altKey:!e.ctrlKey}function LM(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=Ds(i.root);if(!n||n.rangeCount==0)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s<r.length;s++){let o=r[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function FM(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,n;t!=i.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(n=he.get(t))&&n.isWidget()&&!n.isHidden&&n.widget.ignoreEvent(e))return!1;return!0}const At=Object.create(null),Je=Object.create(null),jy=N.ie&&N.ie_version<15||N.ios&&N.webkit_version<604;function zM(i){let e=i.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{i.focus(),t.remove(),Jy(i,t.value)},50)}function Ql(i,e,t){for(let n of i.facet(e))t=n(t,i);return t}function Jy(i,e){e=Ql(i.state,ff,e);let{state:t}=i,n,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(dc!=null&&t.selection.ranges.every(a=>a.empty)&&dc==s.toString()){let a=-1;n=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?s.line(r++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:S.cursor(h.from+f.length,-1)}})}else o?n=t.changeByRange(a=>{let h=s.line(r++);return{changes:{from:a.from,to:a.to,insert:h.text},range:S.cursor(a.from+h.length,-1)}}):n=t.replaceSelection(s);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}Je.scroll=i=>{let e=i.inputState;e.lastScrollTop=i.scrollDOM.scrollTop,e.lastScrollLeft=i.scrollDOM.scrollLeft,N.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};Je.wheel=Je.mousewheel=i=>{i.inputState.lastWheelEvent=Date.now()};At.keydown=(i,e)=>(i.inputState.setSelectionOrigin("select"),e.keyCode==27&&i.inputState.tabFocusMode!=0&&(i.inputState.tabFocusMode=Date.now()+2e3),!1);Je.touchstart=(i,e)=>{let t=i.inputState,n=e.targetTouches[0];t.touchActive=!0,t.lastTouchTime=Date.now(),n&&(t.lastTouchX=n.clientX,t.lastTouchY=n.clientY),t.setSelectionOrigin("select.pointer")};Je.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};Je.touchend=(i,e)=>{i.inputState.touchActive=!1};At.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let n of i.state.facet(vy))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=HM(i,e)),t){let n=!i.hasFocus;i.inputState.startMouseSelection(new RM(i,e,t,n)),n&&i.observer.ignore(()=>{dy(i.contentDOM);let s=i.root.activeElement;s&&!s.contains(i.contentDOM)&&s.blur()});let r=i.inputState.mouseSelection;if(r)return r.start(e),r.dragging===!1}else i.inputState.setSelectionOrigin("select.pointer");return!1};function vp(i,e,t,n){if(n==1)return S.cursor(e,t);if(n==2)return mM(i.state,e,t);{let r=i.docView.lineAt(e,t),s=i.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,l=r?r.posAtEnd:s.to;return l<i.state.doc.length&&l==s.to&&l++,S.undirectionalRange(o,l)}}const VM=N.ie&&N.ie_version<=11;let Mp=null,Ap=0,Op=0;function _y(i){if(!VM)return i.detail;let e=Mp,t=Op;return Mp=i,Op=Date.now(),Ap=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?(Ap+1)%3:1}function HM(i,e){let t=i.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),n=_y(e),r=i.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),r=r.map(s.changes))},get(s,o,l){let a=i.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),h,c=vp(i,a.pos,a.assoc,n);if(t.pos!=a.pos&&!o){let f=vp(i,t.pos,t.assoc,n),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u<c.from?S.range(u,d,c.assoc):S.range(d,u,c.assoc)}return o?r.replaceRange(r.main.extend(c.from,c.to,c.assoc)):l&&n==1&&r.ranges.length>1&&(h=WM(r,a.pos))?h:l?r.addRange(c):S.create([c])}}}function WM(i,e){for(let t=0;t<i.ranges.length;t++){let{from:n,to:r}=i.ranges[t];if(n<=e&&r>=e)return S.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}return null}At.dragstart=(i,e)=>{let{selection:{main:t}}=i.state;if(e.target.draggable){let r=i.docView.tile.nearest(e.target);if(r&&r.isWidget()){let s=r.posAtStart,o=s+r.length;(s>=t.to||o<=t.from)&&(t=S.undirectionalRange(s,o))}}let{inputState:n}=i;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Ql(i.state,uf,i.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};At.dragend=i=>(i.inputState.draggedContent=null,!1);function Tp(i,e,t,n){if(t=Ql(i.state,ff,t),!t)return;let r=i.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=i.inputState,o=n&&s&&PM(i,e)?{from:s.from,to:s.to}:null,l={from:r,insert:t},a=i.state.changes(o?[o,l]:l);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(r,-1),head:a.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),i.inputState.draggedContent=null}At.drop=(i,e)=>{if(!e.dataTransfer)return!1;if(i.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let n=Array(t.length),r=0,s=()=>{++r==t.length&&Tp(i,e,n.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=s,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(n[o]=l.result),s()},l.readAsText(t[o])}return!0}else{let n=e.dataTransfer.getData("Text");if(n)return Tp(i,e,n,!0),!0}return!1};At.paste=(i,e)=>{if(i.state.readOnly)return!0;i.observer.flush();let t=jy?null:e.clipboardData;return t?(Jy(i,t.getData("text/plain")||t.getData("text/uri-list")),!0):(zM(i),!1)};function $M(i,e){let t=i.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),i.focus()},50)}function KM(i){let e=[],t=[],n=!1;for(let r of i.selection.ranges)r.empty||(e.push(i.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of i.selection.ranges){let o=i.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),r=o.number}n=!0}return{text:Ql(i,uf,e.join(i.lineBreak)),ranges:t,linewise:n}}let dc=null;At.copy=At.cut=(i,e)=>{if(!ss(i.contentDOM,i.observer.selectionRange))return!1;let{text:t,ranges:n,linewise:r}=KM(i.state);if(!t&&!r)return!1;dc=r?t:null,e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=jy?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):($M(i,t),!1)};const Uy=mn.define();function Gy(i,e){let t=[];for(let n of i.facet(Oy)){let r=n(i,e);r&&t.push(r)}return t.length?i.update({effects:t,annotations:Uy.of(!0)}):null}function Yy(i){setTimeout(()=>{let e=i.hasFocus;if(e!=i.inputState.notifiedFocused){let t=Gy(i.state,e);t?i.dispatch(t):i.update([])}},10)}Je.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),Yy(i)};Je.blur=i=>{i.observer.clearSelectionRange(),Yy(i)};Je.compositionstart=Je.compositionupdate=(i,e)=>{if(!i.observer.editContext&&(i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0)){let{main:t}=i.state.selection;!t.empty&&i.lineBlockAt(t.from).from!=i.lineBlockAt(t.to).from&&!i.state.readOnly&&i.dispatch({changes:i.state.selection.ranges.filter(n=>!n.empty).map(n=>({from:n.from,to:n.to})),userEvent:"input"}),i.inputState.composing=0}};Je.compositionend=i=>{i.observer.editContext||(i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionPendingKey=!0,i.inputState.compositionPendingChange=i.observer.pendingRecords().length>0,i.inputState.compositionFirstChange=null,N.chrome&&N.android?i.observer.flushSoon():i.inputState.compositionPendingChange?Promise.resolve().then(()=>i.observer.flush()):setTimeout(()=>{i.inputState.composing<0&&i.docView.hasComposition&&i.update([])},50))};Je.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};At.beforeinput=(i,e)=>{var t,n;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(i.inputState.insertingText=e.data,i.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&i.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let l=o[0],a=i.posAtDOM(l.startContainer,l.startOffset),h=i.posAtDOM(l.endContainer,l.endOffset);return gf(i,{from:a,to:h,insert:i.state.toText(s)},null),!0}}let r;if(N.chrome&&N.android&&(r=Ky.find(s=>s.inputType==e.inputType))&&(i.observer.delayAndroidKey(r.key,r.keyCode),r.key=="Backspace"||r.key=="Delete")){let s=((n=window.visualViewport)===null||n===void 0?void 0:n.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}return N.ios&&e.inputType=="deleteContentForward"&&i.observer.flushSoon(),N.safari&&e.inputType=="insertText"&&i.inputState.composing>=0&&setTimeout(()=>Je.compositionend(i,e),20),!1};const Np=new Set;function qM(i){Np.has(i)||(Np.add(i),i.addEventListener("copy",()=>{}),i.addEventListener("cut",()=>{}))}const Dp=["pre-wrap","normal","pre-line","break-spaces"];let pr=!1;function Ip(){pr=!1}class jM{constructor(e){this.lineWrapping=e,this.doc=U.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Dp.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];r<0?n++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,n,r,s,o){let l=Dp.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=s,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class JM{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Ct{constructor(e,t,n,r,s){this.from=e,this.length=t,this.top=n,this.height=r,this._content=s}get type(){return typeof this._content=="number"?Te.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof xi?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Ct(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var se=(function(i){return i[i.ByPos=0]="ByPos",i[i.ByHeight=1]="ByHeight",i[i.ByPosNoHeight=2]="ByPosNoHeight",i})(se||(se={}));const el=.001;class $e{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>el&&(pr=!0),this.height=e)}replace(e,t,n){return $e.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let s=this,o=n.doc;for(let l=r.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=r[l],u=s.lineAt(a,se.ByPosNoHeight,n.setDoc(t),0,0),d=u.to>=h?u:s.lineAt(h,se.ByPosNoHeight,n,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=r[l-1].toA;)a=r[l-1].fromA,c=r[l-1].fromB,l--,a<u.from&&(u=s.lineAt(a,se.ByPosNoHeight,n,0,0));c+=u.from-a,a=u.from;let p=yf.build(n.setDoc(o),e,c,f);s=Cl(s,s.replace(a,h,p))}return s.updateHeight(n,0)}static empty(){return new nt(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,n=e.length,r=0,s=0;for(;;)if(t==n)if(r>s*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),n+=1+l.break,r-=l.size}else if(s>r*2){let l=e[n];l.break?e.splice(n,1,l.left,null,l.right):e.splice(n,1,l.left,l.right),n+=2+l.break,s-=l.size}else break;else if(r<s){let l=e[t++];l&&(r+=l.size)}else{let l=e[--n];l&&(s+=l.size)}let o=!1;return e[t-1]==null?(o=!0,t--):e[t]==null&&(o=!0,n++),new UM($e.of(e.slice(0,t)),o,$e.of(e.slice(n)))}}function Cl(i,e){return i==e?i:(i.constructor!=e.constructor&&(pr=!0),e)}$e.prototype.size=1;const _M=J.replace({});class Xy extends $e{constructor(e,t,n){super(e,t),this.deco=n,this.spaceAbove=0}mainBlock(e,t){return new Ct(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,n,r){return this.spaceAbove&&e<n+this.spaceAbove?new Ct(r,0,n,this.spaceAbove,_M):this.mainBlock(n,r)}lineAt(e,t,n,r,s){let o=this.mainBlock(r,s);return this.spaceAbove?this.blockAt(0,n,r,s).join(o):o}forEachLine(e,t,n,r,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,se.ByPos,n,r,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}}class nt extends Xy{constructor(e,t,n){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=n}mainBlock(e,t){return new Ct(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,n){let r=n[0];return n.length==1&&(r instanceof nt||r instanceof Ce&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof Ce?r=new nt(r.length,this.height,this.spaceAbove):r.height=this.height,this.outdated||(r.outdated=!1),r):$e.of(n)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(n||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Ce extends $e{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*s);o=a/s,this.length>s+1&&(l=(this.height-a)/(this.length-s-1))}else o=this.height/s;return{firstLine:n,lastLine:r,perLine:o,perChar:l}}blockAt(e,t,n,r){let{firstLine:s,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let h=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length)),c=t.doc.lineAt(h),f=l+c.length*a,u=Math.max(n,e-f/2);return new Ct(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-s,Math.floor((e-n)/l))),{from:c,length:f}=t.doc.line(s+h);return new Ct(c,f,n+l*h,l,0)}}lineAt(e,t,n,r,s){if(t==se.ByHeight)return this.blockAt(e,n,r,s);if(t==se.ByPosNoHeight){let{from:d,to:p}=n.doc.lineAt(e);return new Ct(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(n,s),h=n.doc.lineAt(e),c=l+h.length*a,f=h.number-o,u=r+l*f+a*(h.from-s-f);return new Ct(h.from,h.length,Math.max(r,Math.min(u,r+this.height-c)),c,0)}forEachLine(e,t,n,r,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(n,s);for(let c=e,f=r;c<=t;){let u=n.doc.lineAt(c);if(c==e){let p=u.number-l;f+=a*p+h*(e-s-p)}let d=a+h*u.length;o(new Ct(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(e,t,n){let r=this.length-t;if(r>0){let s=n[n.length-1];s instanceof Ce?n[n.length-1]=new Ce(s.length+r):n.push(null,new Ce(r-1))}if(e>0){let s=n[0];s instanceof Ce?n[0]=new Ce(e+s.length):n.unshift(new Ce(e-1),null)}return $e.of(n)}decomposeLeft(e,t){t.push(new Ce(e-1),null)}decomposeRight(e,t){t.push(null,new Ce(this.length-e-1))}updateHeight(e,t=0,n=!1,r){let s=t+this.length;if(r&&r.from<=t+this.length&&r.more){let o=[],l=Math.max(t,r.from),a=-1;for(r.from>t&&o.push(new Ce(r.from-t-1).updateHeight(e,t));l<=s&&r.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=r.heights[r.index++],u=0;f<0&&(u=-f,f=r.heights[r.index++]),a==-1?a=f:Math.abs(f-a)>=el&&(a=-2);let d=new nt(c,f,u);d.outdated=!1,o.push(d),l+=c+1}l<=s&&o.push(null,new Ce(s-l).updateHeight(e,l));let h=$e.of(o);return(a<0||Math.abs(h.height-this.height)>=el||Math.abs(a-this.heightMetrics(e,t).perLine)>=el)&&(pr=!0),Cl(this,h)}else(n||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class UM extends $e{constructor(e,t,n){super(e.length+(t?1:0)+n.length,e.height+n.height,(t?1:0)|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let s=n+this.left.height;return e<s?this.left.blockAt(e,t,n,r):this.right.blockAt(e,t,s,r+this.left.length+this.break)}lineAt(e,t,n,r,s){let o=r+this.left.height,l=s+this.left.length+this.break,a=t==se.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,n,r,s):this.right.lineAt(e,t,n,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==se.ByPosNoHeight?se.ByPosNoHeight:se.ByPos;return a?h.join(this.right.lineAt(l,c,n,o,l)):this.left.lineAt(l,c,n,r,s).join(h)}forEachLine(e,t,n,r,s,o){let l=r+this.left.height,a=s+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,n,r,s,o),t>=a&&this.right.forEachLine(e,t,n,l,a,o);else{let h=this.lineAt(a,se.ByPos,n,r,s);e<h.from&&this.left.forEachLine(e,Math.min(t,h.from-1),n,r,s,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(Math.max(e,h.to+1),t,n,l,a,o)}}replace(e,t,n){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of n)s.push(l);if(e>0&&Ep(s,o-1),t<this.length){let l=s.length;this.decomposeRight(t,s),Ep(s,l)}return $e.of(s)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?$e.of(this.break?[e,null,t]:[e,t]):(this.left=Cl(this.left,e),this.right=Cl(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,r){let{left:s,right:o}=this,l=t+s.length+this.break,a=null;return r&&r.from<=t+s.length&&r.more?a=s=s.updateHeight(e,t,n,r):s.updateHeight(e,t,n),r&&r.from<=l+o.length&&r.more?a=o=o.updateHeight(e,l,n,r):o.updateHeight(e,l,n),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ep(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof Ce&&(n=i[e+1])instanceof Ce&&i.splice(e-1,3,new Ce(t.length+1+n.length))}const GM=5;class yf{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let n=Math.min(t,this.lineEnd),r=this.nodes[this.nodes.length-1];r instanceof nt?r.length+=n-this.pos:(n>this.pos||!this.isCovered)&&this.nodes.push(new nt(n-this.pos,-1,0)),this.writtenTo=n,t>n&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let r=n.widget?n.widget.estimatedHeight:0,s=n.widget?n.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let o=t-e;n.block?this.addBlock(new Xy(o,r,n)):(o||s||r>=GM)&&this.addLineDeco(r,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new nt(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let n=new Ce(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof nt)return e;let t=new nt(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos=this.pos+n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof nt)&&!this.isCovered?this.nodes.push(new nt(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let r of this.nodes)r instanceof nt&&r.updateHeight(this.oracle,n),n+=r?r.length:1;return this.nodes}static build(e,t,n,r){let s=new yf(n,e);return $.spans(t,n,r,s,0),s.finish(n)}}function YM(i,e,t){let n=new XM;return $.compare(i,e,t,n,0),n.changes}class XM{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,r){(e<t||n&&n.heightRelevant||r&&r.heightRelevant)&&ji(e,t,this.changes,5)}}function QM(i,e){let t=i.getBoundingClientRect(),n=i.ownerDocument,r=n.defaultView||window,s=Math.max(0,t.left),o=Math.min(r.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(r.innerHeight,t.bottom);for(let h=i.parentNode;h&&h!=n.body;)if(xe(h)){let c=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&c.overflow!="visible"){let f=h.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),a=Math.min(h==i.parentNode?r.innerHeight:a,f.bottom)}h=c.position=="absolute"||c.position=="fixed"?h.offsetParent:h.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function ZM(i){let e=i.getBoundingClientRect(),t=i.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function eA(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Ua{constructor(e,t,n,r){this.from=e,this.to=t,this.size=n,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],s=t[n];if(r.from!=s.from||r.to!=s.to||r.size!=s.size)return!1}return!0}draw(e,t){return J.replace({widget:new tA(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class tA extends gn{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class Rp{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=pc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Z.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let n=t.facet(df).some(r=>typeof r!="function"&&r.class=="cm-lineWrapping");this.heightOracle=new jM(n),this.stateDeco=Bp(t),this.heightMap=$e.empty().applyChanges(this.stateDeco,U.empty,this.heightOracle.setDoc(t.doc),[new dt(0,0,0,t.doc.length)]);for(let r=0;r<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());r++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=J.set(this.lineGaps.map(r=>r.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:s,to:o})=>r>=s&&r<=o)){let{from:s,to:o}=this.lineBlockAt(r);e.push(new To(s,o))}}return this.viewports=e.sort((n,r)=>n.from-r.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?pc:vl.get(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Kr(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=Bp(this.state);let r=e.changedRanges,s=dt.extendWithRanges(r,YM(n,this.stateDeco,e?e.changes:me.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ip(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||pr)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Ny)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,s=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?Z.RTL:Z.LTR;let o=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:w,scaleY:M}=hy(t,l);(w>.005&&Math.abs(this.scaleX-w)>.005||M>.005&&Math.abs(this.scaleY-M)>.005)&&(this.scaleX=w,this.scaleY=M,h|=16,o=a=!0)}let f=(parseInt(n.paddingTop)||0)*this.scaleY,u=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=cy(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=py(this.scrollParent||e.win);let m=(this.printing?eA:QM)(t,this.paddingTop),g=m.top-this.pixelViewport.top,y=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(a=!0)),!this.inView&&!this.scrollTarget&&!ZM(e.dom))return 0;let k=l.width;if((this.contentDOMWidth!=k||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let w=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(w)&&(o=!0),o||r.lineWrapping&&Math.abs(k-this.contentDOMWidth)>r.charWidth){let{lineHeight:M,charWidth:C,textHeight:I}=e.docView.measureTextSize();o=M>0&&r.refresh(s,M,C,I,Math.max(5,k/C),w),o&&(e.docView.minWidth=0,h|=16)}g>0&&y>0?c=Math.max(g,y):g<0&&y<0&&(c=Math.min(g,y)),Ip();for(let M of this.viewports){let C=M.from==this.viewport.from?w:e.docView.measureVisibleLineHeights(M);this.heightMap=(o?$e.empty().applyChanges(this.stateDeco,U.empty,this.heightOracle,[new dt(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new JM(M.from,C))}pr&&(h|=2)}let O=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return O&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||O)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new To(r.lineAt(o-n*1e3,se.ByHeight,s,0,0).from,r.lineAt(l+(1-n)*1e3,se.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=r.lineAt(h,se.ByPos,s,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new To(r.lineAt(u-1e3/2,se.ByHeight,s,0,0).from,r.lineAt(u+c+1e3/2,se.ByHeight,s,0,0).to)}}return a}mapViewport(e,t){let n=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new To(this.heightMap.lineAt(n,se.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,se.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,se.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,se.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||r<=o-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||s>=l+Math.max(10,Math.min(n,250)))&&r>o-2*1e3&&s<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let r of e)t.touchesRange(r.from,r.to)||n.push(new Ua(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,r=n?1e4:2e3,s=r>>1,o=r<<1;if(this.defaultTextDirection!=Z.LTR&&!n)return[];let l=[],a=(c,f,u,d)=>{if(f-c<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>c&&y<f){a(c,y-10,u,d),a(y+10,f,u,d);return}let g=iA(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-c)<s&&Math.abs(y.to-f)<s&&!m.some(b=>y.from<b&&y.to>b));if(!g){if(f<u.to&&t&&n&&t.visibleRanges.some(k=>k.from<=f&&k.to>=f)){let k=t.moveToLineBoundary(S.cursor(f),!1,!0).head;k>c&&(f=k)}let y=this.gapSize(u,c,f,d),b=n||y<2e6?y:2e6;g=new Ua(c,f,y,b)}l.push(g)},h=c=>{if(c.length<o||c.type!=Te.Text)return;let f=nA(c.from,c.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(n){let m=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(u!=null){let b=Do(f,u),k=((this.visibleBottom-this.visibleTop)/2+m)/c.height;g=b-k,y=b+k}else g=(this.visibleTop-c.top-m)/c.height,y=(this.visibleBottom-c.top+m)/c.height;d=No(f,g),p=No(f,y)}else{let m=f.total*this.heightOracle.charWidth,g=r*this.heightOracle.charWidth,y=0;if(m>2e6)for(let M of e)M.from>=c.from&&M.from<c.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=M.size-M.displaySize);let b=this.pixelViewport.left+y,k=this.pixelViewport.right+y,O,w;if(u!=null){let M=Do(f,u),C=((k-b)/2+g)/m;O=M-C,w=M+C}else O=(b-g)/m,w=(k+g)/m;d=No(f,O),p=No(f,w)}d>c.from&&a(c.from,d,c,f),p<c.to&&a(p,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(e,t,n,r){let s=Do(r,n)-Do(r,t);return this.heightOracle.lineWrapping?e.height*s:r.total*this.heightOracle.charWidth*s}updateLineGaps(e){Ua.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=J.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];$.spans(t,this.viewport.from,this.viewport.to,{span(s,o){n.push({from:s,to:o})},point(){}},20);let r=0;if(n.length!=this.visibleRanges.length)r=12;else for(let s=0;s<n.length&&!(r&8);s++){let o=this.visibleRanges[s],l=n[s];(o.from!=l.from||o.to!=l.to)&&(r|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(r|=8))}return this.visibleRanges=n,r}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Kr(this.heightMap.lineAt(e,se.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Kr(this.heightMap.lineAt(this.scaler.fromDOM(e),se.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+12-this.paddingTop);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Kr(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class To{constructor(e,t){this.from=e,this.to=t}}function nA(i,e,t){let n=[],r=i,s=0;return $.spans(t,i,e,{span(){},point(o,l){o>r&&(n.push({from:r,to:o}),s+=o-r),r=l}},20),r<e&&(n.push({from:r,to:e}),s+=e-r),{total:s,ranges:n}}function No({total:i,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let n=Math.floor(i*t);for(let r=0;;r++){let{from:s,to:o}=e[r],l=o-s;if(n<=l)return s+n;n-=l}}function Do(i,e){let t=0;for(let{from:n,to:r}of i.ranges){if(e<=r){t+=e-n;break}t+=r-n}return t/i.total}function iA(i,e){for(let t of i)if(e(t))return t}const pc={toDOM(i){return i},fromDOM(i){return i},scale:1,eq(i){return i==this}};function Bp(i){let e=i.facet(Gl).filter(n=>typeof n!="function"),t=i.facet(pf).filter(n=>typeof n!="function");return t.length&&e.push($.join(t)),e}class vl{constructor(e,t){this.scale=e,this.viewports=t}static get(e,t,n){let r=0,s=0,o=0,l=n.map(({from:h,to:c})=>{let f=t.lineAt(h,se.ByPos,e,0,0).top,u=t.lineAt(c,se.ByPos,e,0,0).bottom;return r+=u-f,{from:h,to:c,top:f,bottom:u,domTop:0,domBottom:0}});if(t.height-r<10)return pc;let a=(7e6-r)/(t.height-r);for(let h of l)h.domTop=o+(h.top-s)*a,o=h.domBottom=h.domTop+(h.bottom-h.top),s=h.bottom;return new vl(a,l)}toDOM(e){for(let t=0,n=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return r+(e-n)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);n=s.bottom,r=s.domBottom}}fromDOM(e){for(let t=0,n=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return n+(e-r)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);n=s.bottom,r=s.domBottom}}eq(e){return e instanceof vl?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,n)=>t.from==e.viewports[n].from&&t.to==e.viewports[n].to):!1}}function Kr(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new Ct(i.from,i.length,t,n-t,Array.isArray(i._content)?i._content.map(r=>Kr(r,e)):i._content)}const Io=D.define({combine:i=>i.join(" ")}),mc=D.define({combine:i=>i.indexOf(!0)>-1}),gc=Hn.newName(),Qy=Hn.newName(),Zy=Hn.newName(),eb={"&light":"."+Qy,"&dark":"."+Zy};function yc(i,e,t){return new Hn(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,r=>{if(r=="&")return i;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):i+" "+n}})}const rA=yc("."+gc,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"baseline",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},eb),sA={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ga=N.ie&&N.ie_version<=11;class oA{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Pv,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let n of t)this.queue.push(n);(N.ie&&N.ie_version<=11||N.ios&&e.composing)&&t.some(n=>n.type=="childList"&&n.removedNodes.length||n.type=="characterData"&&n.oldValue.length>n.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&N.android&&e.constructor.EDIT_CONTEXT!==!1&&!(N.chrome&&N.chrome_version<126)&&(this.editContext=new aA(e),e.state.facet(en)&&(e.contentDOM.editContext=this.editContext.editContext)),Ga&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(this.pendingRecords().length>0),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(en)?n.root.activeElement!=this.dom:!ss(this.dom,r))return;let s=r.anchorNode&&n.docView.tile.nearest(r.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(N.ie&&N.ie_version<=11||N.android&&N.chrome)&&!n.state.selection.main.empty&&r.focusNode&&ls(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Ds(e.root);if(!t)return!1;let n=N.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&lA(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=ss(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Fv(this.dom,n)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(n),r&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(xe(n))!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);for(let n of this.scrollTargets=t)n.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,sA),Ga&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ga&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var n;if(!this.delayedAndroidKey){let r=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Ji(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((n=this.delayedAndroidKey)===null||n===void 0)&&n.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!0),t==-1?{from:t,to:n}=o:(t=Math.min(o.from,t),n=Math.max(o.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&ss(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new vM(this.view,e,t,n);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.selectionChanged,n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,s=Wy(this.view,n);return this.view.state==r&&(n.domChanged||t)&&this.view.update([]),s}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let n=Pp(t,e.previousSibling||e.target.previousSibling,-1),r=Pp(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(en)!=e.state.facet(en)&&(e.view.contentDOM.editContext=e.state.facet(en)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resizeScroll)===null||n===void 0||n.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Pp(i,e,t){for(;e;){let n=he.get(e);if(n&&n.parent==i)return n;let r=e.parentNode;e=r!=i.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function Lp(i,e){let t=e.startContainer,n=e.startOffset,r=e.endContainer,s=e.endOffset,o=i.docView.domAtPos(i.state.selection.main.anchor,1);return ls(o.node,o.offset,r,s)&&([t,n,r,s]=[r,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}}function lA(i,e){if(e.getComposedRanges){let r=e.getComposedRanges(i.root)[0];if(r)return Lp(i,r)}let t=null;function n(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return i.contentDOM.addEventListener("beforeinput",n,!0),i.dom.ownerDocument.execCommand("indent"),i.contentDOM.removeEventListener("beforeinput",n,!0),t?Lp(i,t):null}class aA{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let r=e.state.selection.main,{anchor:s,head:o}=r,l=this.toEditorPos(n.updateRangeStart),a=this.toEditorPos(n.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:n.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>n.text.length;l==this.from&&s<this.from?l=s:a==this.to&&s>this.to&&(a=s);let c=$y(e.state.sliceDoc(l,a),n.text,(h?r.from:r.to)-l,h?"end":null);if(!c){let u=S.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd));uc(u,r)||e.dispatch({selection:u,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:U.of(n.text.slice(c.from,c.toB).split(`
|
|
43
|
-
`))};if((N.mac||N.android)&&f.from==o-1&&/^\. ?$/.test(n.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:U.of([n.text.replace("."," ")])}),this.pendingContextChange=f,!e.state.readOnly){let u=this.to-this.from+(f.to-f.from+f.insert.length);gf(e,f,S.single(this.toEditorPos(n.selectionStart,u),this.toEditorPos(n.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),f.from<f.to&&!f.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,n.updateRangeStart-1),Math.min(t.text.length,n.updateRangeStart+1)))&&this.handlers.compositionend(n)},this.handlers.characterboundsupdate=n=>{let r=[],s=null;for(let o=this.toEditorPos(n.rangeStart),l=this.toEditorPos(n.rangeEnd);o<l;o++){let a=e.coordsForChar(o);s=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||s||new DOMRect,r.push(s)}t.updateCharacterBounds(n.rangeStart,r)},this.handlers.textformatupdate=n=>{let r=[];for(let s of n.getTextFormats()){let o=s.underlineStyle,l=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(s.rangeStart),h=this.toEditorPos(s.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;r.push(J.mark({attributes:{style:c}}).range(a,h))}}}e.dispatch({effects:Iy.of(J.set(r))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:n}=this.composing;this.composing=null,n&&this.reset(e.state)}};for(let n in this.handlers)t.addEventListener(n,this.handlers[n]);this.measureReq={read:n=>{let r=Ds(n.root);r&&r.rangeCount&&this.editContext.updateSelectionBounds(r.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((s,o,l,a,h)=>{if(n)return;let c=h.length-(o-s);if(r&&o>=r.to)if(r.from==s&&r.to==o&&r.insert.eq(h)){r=this.pendingContextChange=null,t+=c,this.to+=c;return}else r=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+h.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(r=>!r.isUserEvent("input.type")&&r.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class R{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:n}=e;this.dispatchTransactions=e.dispatchTransactions||n&&(r=>r.forEach(s=>n(s,this)))||(r=>this.update(r)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Lv(e.parent)||document,this.viewState=new Rp(this,e.state||Y.create(e)),e.scrollTo&&e.scrollTo.is(Mo)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(zi).map(r=>new Ka(r));for(let r of this.plugins)r.update(this);this.observer=new oA(this),this.inputState=new TM(this),this.inputState.ensureHandlers(this.plugins),this.docView=new xp(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof pe?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,n=!1,r,s=this.state;for(let u of e){if(u.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=u.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(Uy))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Gy(s,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(Y.phrases)!=this.state.facet(Y.phrases))return this.setState(s);r=xl.create(this,s,e),r.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:m}=this.state.facet(R.cursorScrollMargin);f=new _i(d.empty?d:S.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of u.effects)d.is(Mo)&&(f=d.value.clip(this.state))}this.viewState.update(r,f),this.bidiCache=Ml.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet($r)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(Io)!=r.state.facet(Io)&&(this.viewState.mustMeasureContent=!0),(t||n||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let u of this.state.facet(ac))try{u(r)}catch(d){Qe(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Wy(this,c)&&h.force&&Ji(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let n of this.plugins)n.destroy(this);this.viewState=new Rp(this,e),this.plugins=e.facet(zi).map(n=>new Ka(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView.destroy(),this.docView=new xp(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(zi),n=e.state.facet(zi);if(t!=n){let r=[];for(let s of n){let o=t.indexOf(s);if(o<0)r.push(new Ka(s));else{let l=this.plugins[o];l.mustUpdate=e,r.push(l)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r<this.plugins.length;r++)this.plugins[r].update(this);t!=n&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(n){Qe(this.state,n,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.viewState.scrollParent,r=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:o,scaleY:l}=this.viewState;Math.abs(r-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0){if(py(n||this.win))s=-1,o=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(r);s=p.from,o=p.top}l=this.viewState.scaleY}this.updateState=1;let h=this.viewState.measure();if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];h&4||([this.measureRequests,c]=[c,this.measureRequests]);let f=c.map(p=>{try{return p.read(this)}catch(m){return Qe(this.state,m),Fp}}),u=xl.create(this,this.state,[]),d=!1;u.flags|=h,t?t.flags|=h:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),d=this.docView.update(u),d&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(f[p]!=Fp)try{let m=c[p];m.write&&m.write(f[p],this)}catch(m){Qe(this.state,m)}if(d&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-o/l;if((m>1||m<-1)&&!(N.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(n==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){r=r+m,n?s<0?n.scrollTop=n.scrollHeight:n.scrollTop+=m:this.win.scrollBy(0,m),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let a of this.state.facet(ac))a(t)}get themeClasses(){return gc+" "+(this.state.facet(mc)?Zy:Qy)+" "+this.state.facet(Io)}updateAttrs(){let e=zp(this,Ey,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(en)?"true":"false",class:"cm-content",style:`${N.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),zp(this,df,t);let n=this.observer.ignore(()=>{let r=pp(this.contentDOM,this.contentAttrs,t),s=pp(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let r of n.effects)if(r.is(R.announce)){t&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent=" "},200),t=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet($r);let e=this.state.facet(R.cspNonce);Hn.mount(this.root,this.styleModules.concat(rA).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(n=>n.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return _a(this,e,wp(this,e,t,n))}moveByGroup(e,t){return _a(this,e,wp(this,e,t,n=>bM(this,e.head,n)))}visualLineSide(e,t){return t?S.cursor(e.to,1):S.cursor(e.from,-1)}moveToLineBoundary(e,t,n=!0){return yM(this,e,t,n)}moveVertically(e,t,n){return _a(this,e,kM(this,e,t,n))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let n=fc(this,e,t);return n&&n.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),fc(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),s=r[$t.find(r,e-n.from,-1,t)];return n.length&&(e==n.from&&t<0||e==n.to&&t>0)&&s.dir!=this.textDirectionAt(n.from)&&(e==n.to?(e=n.from+s.from,t=1):(e=n.from+s.to,t=-1)),this.docView.coordsAt(e,t,s.dir==Z.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Ty)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>hA)return xy(e.length);let t=this.textDirectionAt(e.from),n;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||ky(s.isolates,n=yp(this,e))))return s.order;n||(n=yp(this,e));let r=qv(e.text,t,n);return this.bidiCache.push(new Ml(e.from,e.to,t,n,!0,r)),r}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||N.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{dy(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var n,r,s,o;return Mo.of(new _i(typeof e=="number"?S.cursor(e):e,(n=t.y)!==null&&n!==void 0?n:"nearest",(r=t.x)!==null&&r!==void 0?r:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return Mo.of(new _i(S.cursor(n.from),"start","start",n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return be.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return be.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=Hn.newName(),r=[Io.of(n),$r.of(yc(`.${n}`,e))];return t&&t.dark&&r.push(mc.of(!0)),r}static baseTheme(e){return Mi.lowest($r.of(yc("."+gc,e,eb)))}static findFromDOM(e){var t;let n=e.querySelector(".cm-content"),r=n&&he.get(n)||he.get(e);return((t=r?.root)===null||t===void 0?void 0:t.view)||null}}R.styleModule=$r;R.inputHandler=Ay;R.clipboardInputFilter=ff;R.clipboardOutputFilter=uf;R.scrollHandler=Dy;R.focusChangeEffect=Oy;R.perLineTextDirection=Ty;R.exceptionSink=My;R.updateListener=ac;R.editable=en;R.mouseSelectionStyle=vy;R.dragMovesSelection=Cy;R.clickAddsSelectionRange=Sy;R.decorations=Gl;R.blockWrappers=Ry;R.outerDecorations=pf;R.atomicRanges=ro;R.bidiIsolatedRanges=By;R.cursorScrollMargin=D.define({combine:i=>{let e=5,t=5;for(let n of i)typeof n=="number"?e=t=n:{x:e,y:t}=n;return{x:e,y:t}}});R.scrollMargins=Ly;R.darkTheme=mc;R.cspNonce=D.define({combine:i=>i.length?i[0]:""});R.contentAttributes=df;R.editorAttributes=Ey;R.lineWrapping=R.contentAttributes.of({class:"cm-lineWrapping"});R.announce=V.define();const hA=4096,Fp={};class Ml{constructor(e,t,n,r,s,o){this.from=e,this.to=t,this.dir=n,this.isolates=r,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let n=[],r=e.length?e[e.length-1].dir:Z.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==r&&!t.touchesRange(o.from,o.to)&&n.push(new Ml(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return n}}function zp(i,e,t){for(let n=i.state.facet(e),r=n.length-1;r>=0;r--){let s=n[r],o=typeof s=="function"?s(i):s;o&&af(o,t)}return t}const cA=N.mac?"mac":N.windows?"win":N.linux?"linux":"key";function fA(i,e){const t=i.split(/-(?!$)/);let n=t[t.length-1];n=="Space"&&(n=" ");let r,s,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))r=!0;else if(/^(c|ctrl|control)$/i.test(h))s=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:s=!0;else throw new Error("Unrecognized modifier name: "+h)}return r&&(n="Alt-"+n),s&&(n="Ctrl-"+n),l&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function Eo(i,e,t){return e.altKey&&(i="Alt-"+i),e.ctrlKey&&(i="Ctrl-"+i),e.metaKey&&(i="Meta-"+i),t!==!1&&e.shiftKey&&(i="Shift-"+i),i}const uA=Mi.default(R.domEventHandlers({keydown(i,e){return nb(tb(e.state),i,e,"editor")}})),bf=D.define({enables:uA}),Vp=new WeakMap;function tb(i){let e=i.facet(bf),t=Vp.get(e);return t||Vp.set(e,t=pA(e.reduce((n,r)=>n.concat(r),[]))),t}function CI(i,e,t){return nb(tb(i.state),e,i,t)}let Mn=null;const dA=4e3;function pA(i,e=cA){let t=Object.create(null),n=Object.create(null),r=(o,l)=>{let a=n[o];if(a==null)n[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,l,a,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>fA(y,e));for(let y=1;y<p.length;y++){let b=p.slice(0,y).join(" ");r(b,!0),d[b]||(d[b]={preventDefault:!0,stopPropagation:!1,run:[k=>{let O=Mn={view:k,prefix:b,scope:o};return setTimeout(()=>{Mn==O&&(Mn=null)},dA),!0}]})}let m=p.join(" ");r(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of i){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in c)c[u].run.push(d=>f(d,bc))}let a=o[e]||o.key;if(a)for(let h of l)s(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let bc=null;function nb(i,e,t,n){bc=e;let r=Rg(e),s=it(r,0),o=Zt(s)==r.length&&r!=" ",l="",a=!1,h=!1,c=!1;Mn&&Mn.view==t&&Mn.scope==n&&(l=Mn.prefix+" ",qy.indexOf(e.keyCode)<0&&(h=!0,Mn=null));let f=new Set,u=g=>{if(g){for(let y of g.run)if(!f.has(y)&&(f.add(y),y(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),h=!0)}return!1},d=i[n],p,m;return d&&(u(d[l+Eo(r,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(N.windows&&e.ctrlKey&&e.altKey)&&!(N.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=hn[e.keyCode])&&p!=r?(u(d[l+Eo(p,e,!0)])||e.shiftKey&&(m=gs[e.keyCode])!=r&&m!=p&&u(d[l+Eo(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Eo(r,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),bc=null,a}class fi{constructor(e,t,n,r,s){this.className=e,this.left=t,this.top=n,this.width=r,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,n){if(n.empty){let r=e.coordsAtPos(n.head,n.assoc||1);if(!r)return[];let s=ib(e);return[new fi(t,r.left-s.left,r.top-s.top,null,r.bottom-r.top)]}else return mA(e,t,n)}}function ib(i){let e=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==Z.LTR?e.left:e.right-i.scrollDOM.clientWidth*i.scaleX)-i.scrollDOM.scrollLeft*i.scaleX,top:e.top-i.scrollDOM.scrollTop*i.scaleY}}function Hp(i,e,t,n){let r=i.coordsAtPos(e,t*2);if(!r)return n;let s=i.dom.getBoundingClientRect(),o=(r.top+r.bottom)/2,l=i.posAtCoords({x:s.left+1,y:o}),a=i.posAtCoords({x:s.right-1,y:o});return l==null||a==null?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}function mA(i,e,t){if(t.to<=i.viewport.from||t.from>=i.viewport.to)return[];let n=Math.max(t.from,i.viewport.from),r=Math.min(t.to,i.viewport.to),s=i.textDirection==Z.LTR,o=i.contentDOM,l=o.getBoundingClientRect(),a=ib(i),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),d=cc(i,n,1),p=cc(i,r,-1),m=d.type==Te.Text?d:null,g=p.type==Te.Text?p:null;if(m&&(i.lineWrapping||d.widgetLineBreaks)&&(m=Hp(i,n,1,m)),g&&(i.lineWrapping||p.widgetLineBreaks)&&(g=Hp(i,r,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return b(k(t.from,t.to,m));{let w=m?k(t.from,null,m):O(d,!1),M=g?k(null,t.to,g):O(p,!0),C=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&w.bottom+i.defaultLineHeight/2<M.top?C.push(y(f,w.bottom,u,M.top)):w.bottom<M.top&&i.elementAtHeight((w.bottom+M.top)/2).type==Te.Text&&(w.bottom=M.top=(w.bottom+M.top)/2),b(w).concat(C).concat(b(M))}function y(w,M,C,I){return new fi(e,w-a.left,M-a.top,Math.max(0,C-w),I-M)}function b({top:w,bottom:M,horizontal:C}){let I=[];for(let P=0;P<C.length;P+=2)I.push(y(C[P],w,C[P+1],M));return I}function k(w,M,C){let I=1e9,P=-1e9,te=[];function W(G,oe,ze,tt,Et){let we=i.coordsAtPos(G,G==C.to?-2:2),lt=i.coordsAtPos(ze,ze==C.from?2:-2);!we||!lt||(I=Math.min(we.top,lt.top,I),P=Math.max(we.bottom,lt.bottom,P),Et==Z.LTR?te.push(s&&oe?f:we.left,s&&tt?u:lt.right):te.push(!s&&tt?f:lt.left,!s&&oe?u:we.right))}let L=w??C.from,X=M??C.to;for(let G of i.visibleRanges)if(G.to>L&&G.from<X)for(let oe=Math.max(G.from,L),ze=Math.min(G.to,X);;){let tt=i.state.doc.lineAt(oe);for(let Et of i.bidiSpans(tt)){let we=Et.from+tt.from,lt=Et.to+tt.from;if(we>=ze)break;lt>oe&&W(Math.max(we,oe),w==null&&we<=L,Math.min(lt,ze),M==null&<>=X,Et.dir)}if(oe=tt.to+1,oe>=ze)break}return te.length==0&&W(L,w==null,X,M==null,i.textDirection),{top:I,bottom:P,horizontal:te}}function O(w,M){let C=l.top+(M?w.top:w.bottom);return{top:C,bottom:C,horizontal:[]}}}function gA(i,e){return i.constructor==e.constructor&&i.eq(e)}class yA{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(tl)!=e.state.facet(tl)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(tl);for(;t<n.length&&n[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,n)=>!gA(t,this.drawn[n]))){let t=this.dom.firstChild,n=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[n].constructor&&r.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(r.draw(),t);for(;t;){let r=t.nextSibling;t.remove(),t=r}this.drawn=e,N.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const tl=D.define();function rb(i){return[be.define(e=>new yA(e,i)),tl.of(i)]}const kc=!N.ios,mr=D.define({combine(i){return Ai(i,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function vI(i={}){return[mr.of(i),bA,kA,wA,Ny.of(!0)]}function sb(i){return i.startState.facet(mr)!=i.state.facet(mr)}const bA=rb({above:!0,markers(i){let{state:e}=i,t=e.facet(mr),n=[];for(let r of e.selection.ranges){let s=r==e.selection.main;if(r.empty||t.drawRangeCursor&&!(s&&N.ios&&t.iosSelectionHandles)){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=r.empty?r:S.cursor(r.head,r.assoc);for(let a of fi.forRange(i,o,l))n.push(a)}}return n},update(i,e){i.transactions.some(n=>n.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=sb(i);return t&&Wp(i.state,e),i.docChanged||i.selectionSet||t},mount(i,e){Wp(e.state,i)},class:"cm-cursorLayer"});function Wp(i,e){e.style.animationDuration=i.facet(mr).cursorBlinkRate+"ms"}const kA=rb({above:!1,markers(i){let e=[],{main:t,ranges:n}=i.state.selection;for(let r of n)if(!r.empty&&(kc||r!=t))for(let s of fi.forRange(i,"cm-selectionBackground",r))e.push(s);if(N.ios&&!t.empty&&i.state.facet(mr).iosSelectionHandles){for(let r of fi.forRange(i,"cm-selectionHandle cm-selectionHandle-start",S.cursor(t.from,1)))e.push(r);for(let r of fi.forRange(i,"cm-selectionHandle cm-selectionHandle-end",S.cursor(t.to,1)))e.push(r)}return e},update(i,e){return i.docChanged||i.selectionSet||i.viewportChanged||sb(i)},class:"cm-selectionLayer"}),xA=N.gecko&&N.gecko_version==153?"#ffffff01":"transparent",wA=Mi.highest(R.theme({".cm-line":{...kc?{"& ::selection, &::selection":{backgroundColor:`${xA} !important`}}:{},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important",...kc?{"&::selection, & ::selection":{backgroundColor:"Highlight !important"}}:{}}}})),ob=V.define({map(i,e){return i==null?null:e.mapPos(i)}}),qr=Ge.define({create(){return null},update(i,e){return i!=null&&(i=e.changes.mapPos(i)),e.effects.reduce((t,n)=>n.is(ob)?n.value:t,i)}}),SA=be.fromClass(class{constructor(i){this.view=i,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(i){var e;let t=i.state.field(qr);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(i.startState.field(qr)!=t||i.docChanged||i.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:i}=this,e=i.state.field(qr),t=e!=null&&i.coordsAtPos(e);if(!t)return null;let n=i.scrollDOM.getBoundingClientRect();return{left:t.left-n.left+i.scrollDOM.scrollLeft*i.scaleX,top:t.top-n.top+i.scrollDOM.scrollTop*i.scaleY,height:t.bottom-t.top}}drawCursor(i){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;i?(this.cursor.style.left=i.left/e+"px",this.cursor.style.top=i.top/t+"px",this.cursor.style.height=i.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(i){this.view.state.field(qr)!=i&&this.view.dispatch({effects:ob.of(i)})}},{eventObservers:{dragover(i){this.setDropPos(this.view.posAtCoords({x:i.clientX,y:i.clientY}))},dragleave(i){(i.target==this.view.contentDOM||!this.view.contentDOM.contains(i.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function MI(){return[qr,SA]}function $p(i,e,t,n,r){e.lastIndex=0;for(let s=i.iterRange(t,n),o=t,l;!s.next().done;o+=s.value.length)if(!s.lineBreak)for(;l=e.exec(s.value);)r(o+l.index,l)}function CA(i,e){let t=i.visibleRanges;if(t.length==1&&t[0].from==i.viewport.from&&t[0].to==i.viewport.to)return t;let n=[];for(let{from:r,to:s}of t)r=Math.max(i.state.doc.lineAt(r).from,r-e),s=Math.min(i.state.doc.lineAt(s).to,s+e),n.length&&n[n.length-1].to>=r?n[n.length-1].to=s:n.push({from:r,to:s});return n}class vA{constructor(e){const{regexp:t,decoration:n,decorate:r,boundary:s,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,r)this.addMatch=(l,a,h,c)=>r(c,h,h+l[0].length,l,a);else if(typeof n=="function")this.addMatch=(l,a,h,c)=>{let f=n(l,a,h);f&&c(h,h+l[0].length,f)};else if(n)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,n);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=s,this.maxLength=o}createDeco(e){let t=new Bn,n=t.add.bind(t);for(let{from:r,to:s}of CA(e,this.maxLength))$p(e.state.doc,this.regexp,r,s,(o,l)=>this.addMatch(l,e,o,n));return t.finish()}updateDeco(e,t){let n=1e9,r=-1;return e.docChanged&&e.changes.iterChanges((s,o,l,a)=>{a>=e.view.viewport.from&&l<=e.view.viewport.to&&(n=Math.min(l,n),r=Math.max(a,r))}),e.viewportMoved||r-n>1e3?this.createDeco(e.view):r>-1?this.updateRange(e.view,t.map(e.changes),n,r):t}updateRange(e,t,n,r){for(let s of e.visibleRanges){let o=Math.max(s.from,n),l=Math.min(s.to,r);if(l>=o){let a=e.state.doc.lineAt(o),h=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(s.from,a.from),f=Math.min(s.to,h.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let u=[],d,p=(m,g,y)=>u.push(y.range(m,g));if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else $p(e.state.doc,this.regexp,c,f,(m,g)=>this.addMatch(g,e,m,p));t=t.update({filterFrom:c,filterTo:f,filter:(m,g)=>m<c||g>f,add:u})}}return t}}const xc=/x/.unicode!=null?"gu":"g",MA=new RegExp(`[\0-\b
|
|
44
|
-
--\u2028\u2029\uFEFF-]`,xc),AA={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Ya=null;function OA(){var i;if(Ya==null&&typeof document<"u"&&document.body){let e=document.body.style;Ya=((i=e.tabSize)!==null&&i!==void 0?i:e.MozTabSize)!=null}return Ya||!1}const nl=D.define({combine(i){let e=Ai(i,{render:null,specialChars:MA,addSpecialChars:null});return(e.replaceTabs=!OA())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,xc)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,xc)),e}});function AI(i={}){return[nl.of(i),TA()]}let Kp=null;function TA(){return Kp||(Kp=be.fromClass(class{constructor(i){this.view=i,this.decorations=J.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(i.state.facet(nl)),this.decorations=this.decorator.createDeco(i)}makeDecorator(i){return new vA({regexp:i.specialChars,decoration:(e,t,n)=>{let{doc:r}=t.state,s=it(e[0],0);if(s==9){let o=r.lineAt(n),l=t.state.tabSize,a=Sr(o.text,l,n-o.from);return J.replace({widget:new EA((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[s]||(this.decorationCache[s]=J.replace({widget:new IA(i,s)}))},boundary:i.replaceTabs?void 0:/[^]/})}update(i){let e=i.state.facet(nl);i.startState.facet(nl)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(i.view)):this.decorations=this.decorator.updateDeco(i,this.decorations)}},{decorations:i=>i.decorations}))}const NA="•";function DA(i){return i>=32?NA:i==10?"":String.fromCharCode(9216+i)}class IA extends gn{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=DA(this.code),n=e.state.phrase("Control character")+" "+(AA[this.code]||"0x"+this.code.toString(16)),r=this.options.render&&this.options.render(this.code,n,t);if(r)return r;let s=document.createElement("span");return s.textContent=t,s.title=n,s.setAttribute("aria-label",n),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class EA extends gn{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function OI(){return BA}const RA=J.line({class:"cm-activeLine"}),BA=be.fromClass(class{constructor(i){this.decorations=this.getDeco(i)}update(i){(i.docChanged||i.selectionSet)&&(this.decorations=this.getDeco(i.view))}getDeco(i){let e=-1,t=[];for(let n of i.state.selection.ranges){let r=i.lineBlockAt(n.head);r.from>e&&(t.push(RA.range(r.from)),e=r.from)}return J.set(t)}},{decorations:i=>i.decorations}),wc=2e3;function PA(i,e,t){let n=Math.min(e.line,t.line),r=Math.max(e.line,t.line),s=[];if(e.off>wc||t.off>wc||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=n;a<=r;a++){let h=i.doc.line(a);h.length<=l&&s.push(S.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=n;a<=r;a++){let h=i.doc.line(a),c=Xh(h.text,o,i.tabSize,!0);if(c<0)s.push(S.cursor(h.to));else{let f=Xh(h.text,l,i.tabSize);s.push(S.range(h.from+c,h.from+f))}}}return s}function LA(i,e){let t=i.coordsAtPos(i.viewport.from);return t?Math.round(Math.abs((t.left-e)/i.defaultCharacterWidth)):-1}function qp(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1),n=i.state.doc.lineAt(t),r=t-n.from,s=r>wc?-1:r==n.length?LA(i,e.clientX):Sr(n.text,i.state.tabSize,t-n.from);return{line:n.number,col:s,off:r}}function FA(i,e){let t=qp(i,e),n=i.state.selection;return t?{update(r){if(r.docChanged){let s=r.changes.mapPos(r.startState.doc.line(t.line).from),o=r.state.doc.lineAt(s);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},n=n.map(r.changes)}},get(r,s,o){let l=qp(i,r);if(!l)return n;let a=PA(i.state,t,l);return a.length?o?S.create(a.concat(n.ranges)):S.create(a):n}}:null}function TI(i){let e=(t=>t.altKey&&t.button==0);return R.mouseSelectionStyle.of((t,n)=>e(n)?FA(t,n):null)}const zA={Alt:[18,i=>!!i.altKey],Control:[17,i=>!!i.ctrlKey],Shift:[16,i=>!!i.shiftKey],Meta:[91,i=>!!i.metaKey]},VA={style:"cursor: crosshair"};function NI(i={}){let[e,t]=zA[i.key||"Alt"],n=be.fromClass(class{constructor(r){this.view=r,this.isDown=!1}set(r){this.isDown!=r&&(this.isDown=r,this.view.update([]))}},{eventObservers:{keydown(r){this.set(r.keyCode==e||t(r))},keyup(r){(r.keyCode==e||!t(r))&&this.set(!1)},mousemove(r){this.set(t(r))}}});return[n,R.contentAttributes.of(r=>{var s;return!((s=r.plugin(n))===null||s===void 0)&&s.isDown?VA:null})]}const Ro="-10000px";class lb{constructor(e,t,n,r){this.facet=t,this.createTooltipView=n,this.removeTooltipView=r,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let s=null;this.tooltipViews=this.tooltips.map(o=>s=n(o,s))}update(e,t){var n;let r=e.state.facet(this.facet),s=r.filter(a=>a);if(r===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<s.length;a++){let h=s[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==h.create&&(c=f)}if(c<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let f=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(n=a.destroy)===null||n===void 0||n.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=r,this.tooltips=s,this.tooltipViews=o,!0}}function ab(i){let e=i.dom.ownerDocument.documentElement,t=e.clientWidth,n=getComputedStyle(e);if(!/stable/.test(n.scrollbarGutter||""))return{left:0,right:t};let r=e.getBoundingClientRect(),s=i.win.scrollX;return{left:Math.max(0,r.left+s-parseFloat(n.marginLeft)),right:Math.min(t,r.right+s+parseFloat(n.marginRight))}}function HA(i){let{left:e,right:t}=ab(i);return{top:0,left:e,right:t,bottom:i.dom.ownerDocument.documentElement.clientHeight}}const Xa=D.define({combine:i=>{var e,t,n;return{position:N.ios?"absolute":((e=i.find(r=>r.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=i.find(r=>r.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((n=i.find(r=>r.tooltipSpace))===null||n===void 0?void 0:n.tooltipSpace)||HA}}}),jp=new WeakMap,kf=be.fromClass(class{constructor(i){this.view=i,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=i.state.facet(Xa);this.position=e.position,this.parent=e.parent,this.classes=i.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new lb(i,xf,(t,n)=>this.createTooltip(t,n),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),i.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let i of this.manager.tooltipViews)this.intersectionObserver.observe(i.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(i){i.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(i,this.above);e&&this.observeIntersection();let t=e||i.geometryChanged,n=i.state.facet(Xa);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let r of this.manager.tooltipViews)r.dom.style.position=this.position;t=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let r of this.manager.tooltipViews)this.container.appendChild(r.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(i,e){let t=i.create(this.view),n=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),i.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let r=document.createElement("div");r.className="cm-tooltip-arrow",t.dom.appendChild(r)}return t.dom.style.position=this.position,t.dom.style.top=Ro,t.dom.style.left="0px",this.container.insertBefore(t.dom,n),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var i,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let n of this.manager.tooltipViews)n.dom.remove(),(i=n.destroy)===null||i===void 0||i.call(n);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let i=1,e=1,t=!1,n=0;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:o}=this.manager.tooltipViews[0];if(N.safari){let l=o.getBoundingClientRect();t=Math.abs(l.top+1e4)>1||Math.abs(l.left)>1}else t=!!o.offsetParent&&o.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let o=this.parent.getBoundingClientRect();o.width&&o.height&&(i=o.width/this.parent.offsetWidth,e=o.height/this.parent.offsetHeight)}else({scaleX:i,scaleY:e}=this.view.viewState);else n=ab(this.view).left;let r=this.view.scrollDOM.getBoundingClientRect(),s=mf(this.view);return{visible:{left:r.left+s.left,top:r.top+s.top,right:r.right-s.right,bottom:r.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((o,l)=>{let a=this.manager.tooltipViews[l];return a.getCoords?a.getCoords(o.pos):this.view.coordsAtPos(o.pos)}),size:this.manager.tooltipViews.map(({dom:o})=>o.getBoundingClientRect()),space:this.view.state.facet(Xa).tooltipSpace(this.view),scaleX:i,scaleY:e,makeAbsolute:t,fixedLeft:n}}writeMeasure(i){var e;if(i.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:n,scaleX:r,scaleY:s}=i,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=i.pos[l],u=i.size[l];if(!f||a.clip!==!1&&(f.bottom<=Math.max(t.top,n.top)||f.top>=Math.min(t.bottom,n.bottom)||f.right<Math.max(t.left,n.left)-.1||f.left>Math.min(t.right,n.right)+.1)){c.style.top=Ro;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=jp.get(h))!==null&&e!==void 0?e:u.bottom-u.top,y=h.offset||$A,b=this.view.textDirection==Z.LTR,k=u.width>n.right-n.left?b?n.left:n.right-u.width:b?Math.max(n.left,Math.min(f.left-(d?14:0)+y.x,n.right-m)):Math.min(Math.max(n.left,f.left-m+(d?14:0)-y.x),n.right-m),O=this.above[l];!a.strictSide&&(O?f.top-g-p-y.y<n.top:f.bottom+g+p+y.y>n.bottom)&&O==n.bottom-f.bottom>f.top-n.top&&(O=this.above[l]=!O);let w=(O?f.top-n.top:n.bottom-f.bottom)-p;if(w<g&&h.resize!==!1){if(w<this.view.defaultLineHeight){c.style.top=Ro;continue}jp.set(h,g),c.style.height=(g=w)/s+"px"}else c.style.height&&(c.style.height="");let M=O?f.top-g-p-y.y:f.bottom+p+y.y,C=k+m;if(h.overlap!==!0)for(let I of o)I.left<C&&I.right>k&&I.top<M+g&&I.bottom>M&&(M=O?I.top-g-2-p:I.bottom+p+2);if(this.position=="absolute"?(c.style.top=(M-i.parent.top)/s+"px",Jp(c,(k-i.parent.left)/r)):(c.style.top=M/s+"px",Jp(c,(k-i.fixedLeft)/r)),d){let I=f.left+(b?y.x:-y.x)-(k+14-7);d.style.left=I/r+"px"}h.overlap!==!0&&o.push({left:k,top:M,right:C,bottom:M+g}),c.classList.toggle("cm-tooltip-above",O),c.classList.toggle("cm-tooltip-below",!O),h.positioned&&h.positioned(i.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let i of this.manager.tooltipViews)i.dom.style.top=Ro}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Jp(i,e){let t=parseInt(i.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(i.style.left=e+"px")}const WA=R.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),$A={x:0,y:0},xf=D.define({enables:[kf,WA]}),Al=D.define({combine:i=>i.reduce((e,t)=>e.concat(t),[])});class Zl{static create(e){return new Zl(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new lb(e,Al,(t,n)=>this.createHostedView(t,n),t=>t.dom.remove())}createHostedView(e,t){let n=e.create(this.view);return n.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(n.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&n.mount&&n.mount(this.view),n}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let n of this.manager.tooltipViews){let r=n[e];if(r!==void 0){if(t===void 0)t=r;else if(t!==r)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const KA=xf.compute([Al],i=>{let e=i.facet(Al);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var n;return(n=t.end)!==null&&n!==void 0?n:t.pos})),create:Zl.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),hb=D.define();class qA{constructor(e,t,n,r,s,o){this.view=e,this.source=t,this.field=n,this.locked=r,this.setHover=s,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(e){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,n=e.docView.tile.nearest(t.target);if(!n)return;let r,s=1;if(n.isWidget())r=n.posAtStart;else{if(r=e.posAtCoords(t),r==null)return;let o=e.coordsAtPos(r);if(!o||t.y<o.top||t.y>o.bottom||t.x<o.left-e.defaultCharacterWidth||t.x>o.right+e.defaultCharacterWidth)return;let l=e.bidiSpans(e.state.doc.lineAt(r)).find(h=>h.from<=r&&h.to>=r),a=l&&l.dir==Z.RTL?-1:1;s=t.x<o.left?-a:a}this.activateHover(e,r,s)}activateHover(e,t,n,r){let s=this.source(e,t,n),o=l=>{if(l&&!(Array.isArray(l)&&!l.length)){let a=Array.isArray(l)?l:[l];r&&this.locked.set(a,r),e.dispatch({effects:this.setHover.of(a)})}};if(s&&"then"in s){let l=this.pending={pos:t};s.then(a=>{this.pending==l&&(this.pending=null,o(a))},a=>Qe(e.state,a,"hover tooltip"))}else o(s)}get tooltip(){let e=this.view.plugin(kf),t=e?e.manager.tooltips.findIndex(n=>n.create==Zl.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,n;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:r,tooltip:s}=this;if(r.length&&!this.locked.has(r)&&s&&!jA(s.dom,e)||this.pending){let{pos:o}=r[0]||this.pending,l=(n=(t=r[0])===null||t===void 0?void 0:t.end)!==null&&n!==void 0?n:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!JA(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length&&!this.locked.has(t)){let{tooltip:n}=this;n&&n.dom.contains(e.relatedTarget)?this.watchTooltipLeave(n.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=n=>{e.removeEventListener("mouseleave",t);let{active:r}=this;r.length&&!this.locked.has(r)&&!this.view.dom.contains(n.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Bo=4;function jA(i,e){let{left:t,right:n,top:r,bottom:s}=i.getBoundingClientRect(),o;if(o=i.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();r=Math.min(l.top,r),s=Math.max(l.bottom,s)}return e.clientX>=t-Bo&&e.clientX<=n+Bo&&e.clientY>=r-Bo&&e.clientY<=s+Bo}function JA(i,e,t,n,r,s){let o=i.scrollDOM.getBoundingClientRect(),l=i.documentTop+i.documentPadding.top+i.contentHeight;if(o.left>n||o.right<n||o.top>r||Math.min(o.bottom,l)<r)return!1;let a=i.posAtCoords({x:n,y:r},!1);return a>=e&&a<=t}function DI(i,e={}){let t=V.define(),n=new WeakMap,r=Ge.define({create(){return[]},update(o,l){let a=n.get(o);if(o.length&&(e.hideOnChange&&(l.docChanged||l.selection)?o=[]:a&&a(l)?o=[]:e.hideOn&&(o=o.filter(h=>!e.hideOn(l,h)))),l.docChanged&&o.length){let h=[];for(let c of o){let f=l.changes.mapPos(c.pos,-1,Ae.TrackDel);if(f!=null){let u=Object.assign(Object.create(null),c);u.pos=f,u.end!=null&&(u.end=l.changes.mapPos(u.end)),h.push(u)}}o=h}for(let h of l.effects)h.is(t)&&(o=h.value,a=void 0),(h.is(_A)&&!h.value||h.value==r)&&(o=[]);return o.length&&a&&n.set(o,a),o},provide:o=>Al.from(o)});const s=be.define(o=>new qA(o,i,r,n,t,e.hoverTime||300));return{active:r,extension:[r,s,hb.of(s),KA]}}function II(i,e,t,n={}){var r;let s=i.state.facet(hb).map(o=>i.plugin(o)).filter(o=>!!o);if(n.tooltip&&n.tooltip.active){let o=s.find(l=>l.field==n.tooltip.active);o&&(s=[o])}for(let o of s)o.activateHover(i,e,t,(r=n.until)!==null&&r!==void 0?r:(()=>!1))}function cb(i,e){let t=i.plugin(kf);if(!t)return null;let n=t.manager.tooltips.indexOf(e);return n<0?null:t.manager.tooltipViews[n]}const _A=V.define(),_p=D.define({combine(i){let e,t;for(let n of i)e=e||n.topContainer,t=t||n.bottomContainer;return{topContainer:e,bottomContainer:t}}});function UA(i,e){let t=i.plugin(fb),n=t?t.specs.indexOf(e):-1;return n>-1?t.panels[n]:null}const fb=be.fromClass(class{constructor(i){this.input=i.state.facet(Sc),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(i));let e=i.state.facet(_p);this.top=new Po(i,!0,e.topContainer),this.bottom=new Po(i,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(i){let e=i.state.facet(_p);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Po(i.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Po(i.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=i.state.facet(Sc);if(t!=this.input){let n=t.filter(a=>a),r=[],s=[],o=[],l=[];for(let a of n){let h=this.specs.indexOf(a),c;h<0?(c=a(i.view),l.push(c)):(c=this.panels[h],c.update&&c.update(i)),r.push(c),(c.top?s:o).push(c)}this.specs=n,this.panels=r,this.top.sync(s),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let n of this.panels)n.update&&n.update(i)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:i=>R.scrollMargins.of(e=>{let t=e.plugin(i);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Po{constructor(e,t,n){this.view=e,this.top=t,this.container=n,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Up(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Up(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Up(i){let e=i.nextSibling;return i.remove(),e}const Sc=D.define({enables:fb});function EI(i,e){let t,n=new Promise(o=>t=o),r=o=>GA(o,e,t);i.state.field(il,!1)?i.dispatch({effects:ub.of(r)}):i.dispatch({effects:V.appendConfig.of(il.init(()=>[r]))});let s=db.of(r);return{close:s,result:n.then(o=>((i.win.queueMicrotask||(a=>i.win.setTimeout(a,10)))(()=>{i.state.field(il).indexOf(r)>-1&&i.dispatch({effects:s})}),o))}}function RI(i,e){let t=i.state.field(il,!1)||[];for(let n of t){let r=UA(i,n);if(r&&r.dom.classList.contains(e))return r}return null}const il=Ge.define({create(){return[]},update(i,e){for(let t of e.effects)t.is(ub)?i=[t.value].concat(i):t.is(db)&&(i=i.filter(n=>n!=t.value));return i},provide:i=>Sc.computeN([i],e=>e.field(i))}),ub=V.define(),db=V.define();function GA(i,e,t){let n=e.content?e.content(i,()=>l(null)):null;if(!n){if(n=Ei("form"),e.input){let a=Ei("input",e.input);/^(text|password|number|email|tel|url)$/.test(a.type)&&a.classList.add("cm-textfield"),a.name||(a.name="input"),n.appendChild(Ei("label",(e.label||"")+": ",a))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(Ei("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let r=n.nodeName=="FORM"?[n]:n.querySelectorAll("form");for(let a=0;a<r.length;a++){let h=r[a];h.addEventListener("keydown",c=>{c.keyCode==27?(c.preventDefault(),l(null)):c.keyCode==13&&(c.preventDefault(),l(h))}),h.addEventListener("submit",c=>{c.preventDefault(),l(h)})}let s=Ei("div",n,Ei("button",{onclick:()=>l(null),"aria-label":i.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(s.className=e.class),s.classList.add("cm-dialog");let o=typeof e.focus=="string"?n.querySelector(e.focus):e.focus?n.querySelector("input")||n.querySelector("button"):null;function l(a){s.contains(s.ownerDocument.activeElement)&&i.focus(),t(a)}return{dom:s,top:e.top,mount:()=>{o&&("select"in o?o.select():"focus"in o&&o.focus())},destroy:()=>t(null)}}class fn extends Vn{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}fn.prototype.elementClass="";fn.prototype.toDOM=void 0;fn.prototype.mapMode=Ae.TrackBefore;fn.prototype.startSide=fn.prototype.endSide=-1;fn.prototype.point=!0;const rl=D.define(),YA=D.define(),XA={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>$.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},hs=D.define();function QA(i){return[pb(),hs.of({...XA,...i})]}const Gp=D.define({combine:i=>i.some(e=>e)});function pb(i){return[ZA]}const ZA=be.fromClass(class{constructor(i){this.view=i,this.domAfter=null,this.prevViewport=i.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=i.state.facet(hs).map(e=>new Xp(i,e)),this.fixed=!i.state.facet(Gp);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),i.scrollDOM.insertBefore(this.dom,i.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(i){if(this.updateGutters(i)){let e=this.prevViewport,t=i.view.viewport,n=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(n<(t.to-t.from)*.8)}if(i.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Gp)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=i.view.viewport}syncGutters(i){let e=this.dom.nextSibling;i&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=$.iter(this.view.state.facet(rl),this.view.viewport.from),n=[],r=this.gutters.map(s=>new eO(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(s.type)){let o=!0;for(let l of s.type)if(l.type==Te.Text&&o){Cc(t,n,l.from);for(let a of r)a.line(this.view,l,n);o=!1}else if(l.widget)for(let a of r)a.widget(this.view,l)}else if(s.type==Te.Text){Cc(t,n,s.from);for(let o of r)o.line(this.view,s,n)}else if(s.widget)for(let o of r)o.widget(this.view,s);for(let s of r)s.finish();i&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(i){let e=i.startState.facet(hs),t=i.state.facet(hs),n=i.docChanged||i.heightChanged||i.viewportChanged||!$.eq(i.startState.facet(rl),i.state.facet(rl),i.view.viewport.from,i.view.viewport.to);if(e==t)for(let r of this.gutters)r.update(i)&&(n=!0);else{n=!0;let r=[];for(let s of t){let o=e.indexOf(s);o<0?r.push(new Xp(this.view,s)):(this.gutters[o].update(i),r.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),r.indexOf(s)<0&&s.destroy();for(let s of r)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=r}return n}destroy(){for(let i of this.gutters)i.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:i=>R.scrollMargins.of(e=>{let t=e.plugin(i);if(!t||t.gutters.length==0||!t.fixed)return null;let n=t.dom.offsetWidth*e.scaleX,r=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Z.LTR?{left:n,right:r}:{right:n,left:r}})});function Yp(i){return Array.isArray(i)?i:[i]}function Cc(i,e,t){for(;i.value&&i.from<=t;)i.from==t&&e.push(i.value),i.next()}class eO{constructor(e,t,n){this.gutter=e,this.height=n,this.i=0,this.cursor=$.iter(e.markers,t.from)}addElement(e,t,n){let{gutter:r}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==r.elements.length){let l=new mb(e,o,s,n);r.elements.push(l),r.dom.appendChild(l.dom)}else r.elements[this.i].update(e,o,s,n);this.height=t.bottom,this.i++}line(e,t,n){let r=[];Cc(this.cursor,r,t.from),n.length&&(r=r.concat(n));let s=this.gutter.config.lineMarker(e,t,r);s&&r.unshift(s);let o=this.gutter;r.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,r)}widget(e,t){let n=this.gutter.config.widgetMarker(e,t.widget,t),r=n?[n]:null;for(let s of e.state.facet(YA)){let o=s(e,t.widget,t);o&&(r||(r=[])).push(o)}r&&this.addElement(e,t,r)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class Xp{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let n in t.domEventHandlers)this.dom.addEventListener(n,r=>{let s=r.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let a=s.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=r.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[n](e,l,r)&&r.preventDefault()});this.markers=Yp(t.markers(e)),t.initialSpacer&&(this.spacer=new mb(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Yp(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let r=this.config.updateSpacer(this.spacer.markers[0],e);r!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[r])}let n=e.view.viewport;return!$.eq(this.markers,t,n.from,n.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class mb{constructor(e,t,n,r){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,n,r)}update(e,t,n,r){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=n&&(this.dom.style.marginTop=(this.above=n)?n+"px":""),tO(this.markers,r)||this.setMarkers(e,r)}setMarkers(e,t){let n="cm-gutterElement",r=this.dom.firstChild;for(let s=0,o=0;;){let l=o,a=s<t.length?t[s++]:null,h=!1;if(a){let c=a.elementClass;c&&(n+=" "+c);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(r);let f=r.nextSibling;r.remove(),r=f}}if(!a)break;a.toDOM&&(h?r=r.nextSibling:this.dom.insertBefore(a.toDOM(e),r)),h&&o++}this.dom.className=n,this.markers=t}destroy(){this.setMarkers(null,[])}}function tO(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(!i[t].compare(e[t]))return!1;return!0}const nO=D.define(),iO=D.define(),Vi=D.define({combine(i){return Ai(i,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let n=Object.assign({},e);for(let r in t){let s=n[r],o=t[r];n[r]=s?(l,a,h)=>s(l,a,h)||o(l,a,h):o}return n}})}});class Qa extends fn{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Za(i,e){return i.state.facet(Vi).formatNumber(e,i.state)}const rO=hs.compute([Vi],i=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(nO)},lineMarker(e,t,n){return n.some(r=>r.toDOM)?null:new Qa(Za(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,n)=>{for(let r of e.state.facet(iO)){let s=r(e,t,n);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Vi)!=e.state.facet(Vi),initialSpacer(e){return new Qa(Za(e,Qp(e.state.doc.lines)))},updateSpacer(e,t){let n=Za(t.view,Qp(t.view.state.doc.lines));return n==e.number?e:new Qa(n)},domEventHandlers:i.facet(Vi).domEventHandlers,side:"before"}));function BI(i={}){return[Vi.of(i),pb(),rO]}function Qp(i){let e=9;for(;e<i;)e=e*10+9;return e}const sO=new class extends fn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},oO=rl.compute(["selection"],i=>{let e=[],t=-1;for(let n of i.selection.ranges){let r=i.doc.lineAt(n.head).from;r>t&&(t=r,e.push(sO.range(r)))}return $.of(e)});function PI(){return oO}let lO=0;class ct{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=lO++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let n=typeof e=="string"?e:"?";if(e instanceof ct&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let r=new ct(n,[],null,[]);if(r.set.push(r),t)for(let s of t.set)r.set.push(s);return r}static defineModifier(e){let t=new Ol(e);return n=>n.modified.indexOf(t)>-1?n:Ol.get(n.base||n,n.modified.concat(t).sort((r,s)=>r.id-s.id))}}let aO=0;class Ol{constructor(e){this.name=e,this.instances=[],this.id=aO++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find(l=>l.base==e&&hO(t,l.modified));if(n)return n;let r=[],s=new ct(e.name,r,e,t);for(let l of t)l.instances.push(s);let o=cO(t);for(let l of e.set)if(!l.modified.length)for(let a of o)r.push(Ol.get(l,a));return s}}function hO(i,e){return i.length==e.length&&i.every((t,n)=>t==e[n])}function cO(i){let e=[[]];for(let t=0;t<i.length;t++)for(let n=0,r=e.length;n<r;n++)e.push(e[n].concat(i[t]));return e.sort((t,n)=>n.length-t.length)}function fO(i){let e=Object.create(null);for(let t in i){let n=i[t];Array.isArray(n)||(n=[n]);for(let r of t.split(" "))if(r){let s=[],o=2,l=r;for(let f=0;;){if(l=="..."&&f>0&&f+3==r.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+r);if(s.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==r.length)break;let d=r[f++];if(f==r.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+r);l=r.slice(f)}let a=s.length-1,h=s[a];if(!h)throw new RangeError("Invalid path: "+r);let c=new Es(n,o,a>0?s.slice(0,a):null);e[h]=c.sort(e[h])}}return gb.add(e)}const gb=new H({combine(i,e){let t,n,r;for(;i||e;){if(!i||e&&i.depth<=e.depth?(r=e,e=e.next):(r=i,i=i.next),t&&t.mode==r.mode&&!r.context&&!t.context)continue;let s=new Es(r.tags,r.mode,r.context);t?t.next=s:n=s,t=s}return n}});class Es{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Es.empty=new Es([],2,null);function yb(i,e){let t=Object.create(null);for(let s of i)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:n,all:r=null}=e||{};return{style:s=>{let o=r;for(let l of s)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:n}}function uO(i,e){let t=null;for(let n of i){let r=n.style(e);r&&(t=t?t+" "+r:r)}return t}function dO(i,e,t,n=0,r=i.length){let s=new pO(n,Array.isArray(e)?e:[e],t);s.highlightRange(i.cursor(),n,r,"",s.highlighters),s.flush(r)}class pO{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,s){let{type:o,from:l,to:a}=e;if(l>=n||a<=t)return;o.isTop&&(s=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=r,c=mO(e)||Es.empty,f=uO(s,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(r+=(r?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop(H.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(u.tree.type)),m=e.firstChild();for(let g=0,y=l;;g++){let b=g<u.overlay.length?u.overlay[g]:null,k=b?b.from+l:a,O=Math.max(t,y),w=Math.min(n,k);if(O<w&&m)for(;e.from<w&&(this.highlightRange(e,O,w,r,s),this.startSpan(Math.min(w,e.to),h),!(e.to>=k||!e.nextSibling())););if(!b||k>n)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(n,y),"",p),this.startSpan(Math.min(n,y),h))}m&&e.parent()}else if(e.firstChild()){u&&(r="");do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,r,s),this.startSpan(Math.min(n,e.to),h)}while(e.nextSibling());e.parent()}}}function mO(i){let e=i.type.prop(gb);for(;e&&e.context&&!i.matchContext(e.context);)e=e.next;return e||null}const T=ct.define,Lo=T(),kn=T(),Zp=T(kn),em=T(kn),xn=T(),Fo=T(xn),eh=T(xn),Ft=T(),Yn=T(Ft),Pt=T(),Lt=T(),vc=T(),Rr=T(vc),zo=T(),v={comment:Lo,lineComment:T(Lo),blockComment:T(Lo),docComment:T(Lo),name:kn,variableName:T(kn),typeName:Zp,tagName:T(Zp),propertyName:em,attributeName:T(em),className:T(kn),labelName:T(kn),namespace:T(kn),macroName:T(kn),literal:xn,string:Fo,docString:T(Fo),character:T(Fo),attributeValue:T(Fo),number:eh,integer:T(eh),float:T(eh),bool:T(xn),regexp:T(xn),escape:T(xn),color:T(xn),url:T(xn),keyword:Pt,self:T(Pt),null:T(Pt),atom:T(Pt),unit:T(Pt),modifier:T(Pt),operatorKeyword:T(Pt),controlKeyword:T(Pt),definitionKeyword:T(Pt),moduleKeyword:T(Pt),operator:Lt,derefOperator:T(Lt),arithmeticOperator:T(Lt),logicOperator:T(Lt),bitwiseOperator:T(Lt),compareOperator:T(Lt),updateOperator:T(Lt),definitionOperator:T(Lt),typeOperator:T(Lt),controlOperator:T(Lt),punctuation:vc,separator:T(vc),bracket:Rr,angleBracket:T(Rr),squareBracket:T(Rr),paren:T(Rr),brace:T(Rr),content:Ft,heading:Yn,heading1:T(Yn),heading2:T(Yn),heading3:T(Yn),heading4:T(Yn),heading5:T(Yn),heading6:T(Yn),contentSeparator:T(Ft),list:T(Ft),quote:T(Ft),emphasis:T(Ft),strong:T(Ft),link:T(Ft),monospace:T(Ft),strikethrough:T(Ft),inserted:T(),deleted:T(),changed:T(),invalid:T(),meta:zo,documentMeta:T(zo),annotation:T(zo),processingInstruction:T(zo),definition:ct.defineModifier("definition"),constant:ct.defineModifier("constant"),function:ct.defineModifier("function"),standard:ct.defineModifier("standard"),local:ct.defineModifier("local"),special:ct.defineModifier("special")};for(let i in v){let e=v[i];e instanceof ct&&(e.name=i)}yb([{tag:v.link,class:"tok-link"},{tag:v.heading,class:"tok-heading"},{tag:v.emphasis,class:"tok-emphasis"},{tag:v.strong,class:"tok-strong"},{tag:v.keyword,class:"tok-keyword"},{tag:v.atom,class:"tok-atom"},{tag:v.bool,class:"tok-bool"},{tag:v.url,class:"tok-url"},{tag:v.labelName,class:"tok-labelName"},{tag:v.inserted,class:"tok-inserted"},{tag:v.deleted,class:"tok-deleted"},{tag:v.literal,class:"tok-literal"},{tag:v.string,class:"tok-string"},{tag:v.number,class:"tok-number"},{tag:[v.regexp,v.escape,v.special(v.string)],class:"tok-string2"},{tag:v.variableName,class:"tok-variableName"},{tag:v.local(v.variableName),class:"tok-variableName tok-local"},{tag:v.definition(v.variableName),class:"tok-variableName tok-definition"},{tag:v.special(v.variableName),class:"tok-variableName2"},{tag:v.definition(v.propertyName),class:"tok-propertyName tok-definition"},{tag:v.typeName,class:"tok-typeName"},{tag:v.namespace,class:"tok-namespace"},{tag:v.className,class:"tok-className"},{tag:v.macroName,class:"tok-macroName"},{tag:v.propertyName,class:"tok-propertyName"},{tag:v.operator,class:"tok-operator"},{tag:v.comment,class:"tok-comment"},{tag:v.meta,class:"tok-meta"},{tag:v.invalid,class:"tok-invalid"},{tag:v.punctuation,class:"tok-punctuation"}]);function tm(i,e,t,n=0,r=0){e==null&&(e=i.search(/[^\s\u00a0]/),e==-1&&(e=i.length));let s=r;for(let o=n;o<e;o++)i.charCodeAt(o)==9?s+=t-s%t:s++;return s}class bb{constructor(e,t,n,r){this.string=e,this.tabSize=t,this.indentUnit=n,this.overrideIndent=r,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),n;if(typeof e=="string"?n=t==e:n=t&&(e instanceof RegExp?e.test(t):e(t)),n)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=tm(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:tm(this.string,null,this.tabSize)}match(e,t,n){if(typeof e=="string"){let r=o=>n?o.toLowerCase():o,s=this.string.substr(this.pos,e.length);return r(s)==r(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let r=this.string.slice(this.pos).match(e);return r&&r.index>0?null:(r&&t!==!1&&(this.pos+=r[0].length),r)}}current(){return this.string.slice(this.start,this.pos)}}var th;const ni=new H;function kb(i){return D.define({combine:i?e=>e.concat(i):void 0})}const gO=new H;class pt{constructor(e,t,n=[],r=""){this.data=e,this.name=r,Y.prototype.hasOwnProperty("tree")||Object.defineProperty(Y.prototype,"tree",{get(){return Ne(this)}}),this.parser=t,this.extension=[$n.of(this),Y.languageData.of((s,o,l)=>{let a=nm(s,o,l),h=a.type.prop(ni);if(!h)return[];let c=s.facet(h),f=a.type.prop(gO);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,s)){let p=s.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(n)}isActiveAt(e,t,n=-1){return nm(e,t,n).type.prop(ni)==this.data}findRegions(e){let t=e.facet($n);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(s,o)=>{if(s.prop(ni)==this.data){n.push({from:o,to:o+s.length});return}let l=s.prop(H.mounted);if(l){if(l.tree.prop(ni)==this.data){if(l.overlay)for(let a of l.overlay)n.push({from:a.from+o,to:a.to+o});else n.push({from:o,to:o+s.length});return}else if(l.overlay){let a=n.length;if(r(l.tree,l.overlay[0].from+o),n.length>a)return}}for(let a=0;a<s.children.length;a++){let h=s.children[a];h instanceof ie&&r(h,s.positions[a]+o)}};return r(Ne(e),0),n}get allowsNesting(){return!0}}pt.setState=V.define();function nm(i,e,t){let n=i.facet($n),r=Ne(i).topNode;if(!n||n.allowsNesting)for(let s=r;s;s=s.enter(e,t,Q.ExcludeBuffers|Q.EnterBracketed))s.type.isTop&&(r=s);return r}class Mc extends pt{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(e){let t=kb(e.languageData);return new Mc(t,e.parser.configure({props:[ni.add(n=>n.isTop?t:void 0)]}),e.name)}configure(e,t){return new Mc(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Ne(i){let e=i.field(pt.state,!1);return e?e.tree:ie.empty}class yO{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}}let Br=null;class gr{constructor(e,t,n=[],r,s,o,l,a){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new gr(e,t,[],ie.empty,0,n,[],null)}startParse(){return this.parser.startParse(new yO(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=ie.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let r=Date.now()+e;e=()=>Date.now()>r}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let r=this.parse.advance();if(r)if(this.fragments=this.withoutTempSkipped(ln.addTree(r,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(n=this.parse.stoppedAt)!==null&&n!==void 0?n:this.state.doc.length,this.tree=r,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(ln.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Br;Br=this;try{return e()}finally{Br=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=im(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:r,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),n=ln.applyChanges(n,a),r=ie.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new gr(this.parser,t,n,r,s,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let n=0;n<this.skipped.length;n++){let{from:r,to:s}=this.skipped[n];r<e.to&&s>e.from&&(this.fragments=im(this.fragments,r,s),this.skipped.splice(n--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends V0{createParse(t,n,r){let s=r[0].from,o=r[r.length-1].to;return{parsedPos:s,advance(){let a=Br;if(a){for(let h of r)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new ie(je.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Br}}function im(i,e,t){return ln.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}class yr{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new yr(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=gr.create(e.facet($n).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new yr(n)}}pt.state=Ge.define({create:yr.init,update(i,e){for(let t of e.effects)if(t.is(pt.setState))return t.value;return e.startState.facet($n)!=e.state.facet($n)?yr.init(e.state):i.apply(e)}});let xb=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(xb=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const nh=typeof navigator<"u"&&(!((th=navigator.scheduling)===null||th===void 0)&&th.isInputPending)?()=>navigator.scheduling.isInputPending():null,bO=be.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(pt.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(pt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=xb(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:r}}=this.view,s=n.field(pt.state);if(s.tree==s.context.tree&&s.context.isDone(r+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!nh?Math.max(25,e.timeRemaining()-5):1e9),l=s.context.treeLen<r&&n.doc.length>r+1e3,a=s.context.work(()=>nh&&nh()||Date.now()>o,r+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:pt.setState.of(new yr(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Qe(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),$n=D.define({combine(i){return i.length?i[0]:null},enables:i=>[pt.state,bO,R.contentAttributes.compute([i],e=>{let t=e.facet(i);return t&&t.name?{"data-language":t.name}:{}})]});class FI{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class wb{constructor(e,t,n,r,s,o=void 0){this.name=e,this.alias=t,this.extensions=n,this.filename=r,this.loadFunc=s,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:n}=e;if(!t){if(!n)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(n)}return new wb(e.name,(e.alias||[]).concat(e.name).map(r=>r.toLowerCase()),e.extensions||[],e.filename,t,n)}static matchFilename(e,t){for(let r of e)if(r.filename&&r.filename.test(t))return r;let n=/\.([^.]+)$/.exec(t);if(n){for(let r of e)if(r.extensions.indexOf(n[1])>-1)return r}return null}static matchLanguageName(e,t,n=!0){t=t.toLowerCase();for(let r of e)if(r.alias.some(s=>s==t))return r;if(n)for(let r of e)for(let s of r.alias){let o=t.indexOf(s);if(o>-1&&(s.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+s.length])))return r}return null}}const kO=D.define(),ea=D.define({combine:i=>{if(!i.length)return" ";let e=i[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(i[0]));return e}});function Si(i){let e=i.facet(ea);return e.charCodeAt(0)==9?i.tabSize*e.length:e.length}function Rs(i,e){let t="",n=i.tabSize,r=i.facet(ea)[0];if(r==" "){for(;e>=n;)t+=" ",e-=n;r=" "}for(let s=0;s<e;s++)t+=r;return t}function wf(i,e){i instanceof Y&&(i=new ta(i));for(let n of i.state.facet(kO)){let r=n(i,e);if(r!==void 0)return r}let t=Ne(i.state);return t.length>=e?xO(i,t,e):null}class ta{constructor(e,t={}){this.state=e,this.options=t,this.unit=Si(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:s}=this.options;return r!=null&&r>=n.from&&r<=n.to?s&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),s=this.countColumn(n,e-r),o=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return o>-1&&(s+=o-this.countColumn(n,n.search(/\S|$/))),s}countColumn(e,t=e.length){return Sr(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(r);if(o>-1)return o}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Sb=new H;function xO(i,e,t){let n=e.resolveStack(t),r=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(r!=n.node){let s=[];for(let o=r;o&&!(o.from<n.node.from||o.to>n.node.to||o.from==n.node.from&&o.type==n.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)n={node:s[o],next:n}}return Cb(n,i,t)}function Cb(i,e,t){for(let n=i;n;n=n.next){let r=SO(n.node);if(r)return r(Sf.create(e,t,n))}return 0}function wO(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function SO(i){let e=i.type.prop(Sb);if(e)return e;let t=i.firstChild,n;if(t&&(n=t.type.prop(H.closedBy))){let r=i.lastChild,s=r&&n.indexOf(r.name)>-1;return o=>vb(o,!0,1,void 0,s&&!wO(o)?r.from:void 0)}return i.parent==null?CO:null}function CO(){return 0}class Sf extends ta{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.context=n}get node(){return this.context.node}static create(e,t,n){return new Sf(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(vO(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){return Cb(this.context.next,this.base,this.pos)}}function vO(i,e){for(let t=e;t;t=t.parent)if(i==t)return!0;return!1}function MO(i){let e=i.node,t=e.childAfter(e.from),n=e.lastChild;if(!t)return null;let r=i.options.simulateBreak,s=i.state.doc.lineAt(t.from),o=r==null||r<=s.from?s.to:Math.min(s.to,r);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==n)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let h=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function zI({closing:i,align:e=!0,units:t=1}){return n=>vb(n,e,t,i)}function vb(i,e,t,n,r){let s=i.textAfter,o=s.match(/^\s*/)[0].length,l=n&&s.slice(o,o+n.length)==n||r==i.pos+o,a=e?MO(i):null;return a?l?i.column(a.from):i.column(a.to):i.baseIndent+(l?0:i.unit*t)}const VI=i=>i.baseIndent;function HI({except:i,units:e=1}={}){return t=>{let n=i&&i.test(t.textAfter);return t.baseIndent+(n?0:e*t.unit)}}const AO=200;function WI(){return Y.transactionFilter.of(i=>{if(!i.docChanged||!i.isUserEvent("input.type")&&!i.isUserEvent("input.complete"))return i;let e=i.startState.languageDataAt("indentOnInput",i.startState.selection.main.head);if(!e.length)return i;let t=i.newDoc,{head:n}=i.newSelection.main,r=t.lineAt(n);if(n>r.from+AO)return i;let s=t.sliceString(r.from,n);if(!e.some(h=>h.test(s)))return i;let{state:o}=i,l=-1,a=[];for(let{head:h}of o.selection.ranges){let c=o.doc.lineAt(h);if(c.from==l)continue;l=c.from;let f=wf(o,c.from);if(f==null)continue;let u=/^\s*/.exec(c.text)[0],d=Rs(o,f);u!=d&&a.push({from:c.from,to:c.from+u.length,insert:d})}return a.length?[i,{changes:a,sequential:!0}]:i})}const OO=D.define(),TO=new H;function $I(i){let e=i.firstChild,t=i.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?i.to:t.from}:null}function NO(i,e,t){let n=Ne(i);if(n.length<t)return null;let r=n.resolveStack(t,1),s=null;for(let o=r;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(s&&l.from<e)break;let a=l.type.prop(TO);if(a&&(l.to<n.length-50||n.length==i.doc.length||!DO(l))){let h=a(l,i);h&&h.from<=t&&h.from>=e&&h.to>t&&(s=h)}}return s}function DO(i){let e=i.lastChild;return e&&e.to==i.to&&e.type.isError}function Tl(i,e,t){for(let n of i.facet(OO)){let r=n(i,e,t);if(r)return r}return NO(i,e,t)}function Mb(i,e){let t=e.mapPos(i.from,1),n=e.mapPos(i.to,-1);return t>=n?void 0:{from:t,to:n}}const na=V.define({map:Mb}),so=V.define({map:Mb});function Ab(i){let e=[];for(let{head:t}of i.state.selection.ranges)e.some(n=>n.from<=t&&n.to>=t)||e.push(i.lineBlockAt(t));return e}const Ci=Ge.define({create(){return J.none},update(i,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((n,r)=>i=rm(i,n,r)),i=i.map(e.changes);let t=[];for(let n of e.effects)n.is(na)&&!IO(i,n.value.from,n.value.to)?t.push(n.value):n.is(so)&&(i=i.update({filter:(r,s)=>n.value.from!=r||n.value.to!=s,filterFrom:n.value.from,filterTo:n.value.to}));if(t.length){let{preparePlaceholder:n}=e.state.facet(Nb),r=t.map(s=>(n?J.replace({widget:new FO(n(e.state,s))}):sm).range(s.from,s.to));i=i.update({add:r})}return e.selection&&(i=rm(i,e.selection.main.head)),i},provide:i=>R.decorations.from(i),toJSON(i,e){let t=[];return i.between(0,e.doc.length,(n,r)=>{t.push(n,r)}),t},fromJSON(i){if(!Array.isArray(i)||i.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<i.length;){let n=i[t++],r=i[t++];if(typeof n!="number"||typeof r!="number")throw new RangeError("Invalid JSON for fold state");e.push(sm.range(n,r))}return J.set(e,!0)}});function rm(i,e,t=e){let n=!1;return i.between(e,t,(r,s)=>{r<t&&s>e&&(n=!0)}),n?i.update({filterFrom:e,filterTo:t,filter:(r,s)=>r>=t||s<=e}):i}function Nl(i,e,t){var n;let r=null;return(n=i.field(Ci,!1))===null||n===void 0||n.between(e,t,(s,o)=>{(!r||r.from>s)&&(r={from:s,to:o})}),r}function IO(i,e,t){let n=!1;return i.between(e,e,(r,s)=>{r==e&&s==t&&(n=!0)}),n}function Ob(i,e){return i.field(Ci,!1)?e:e.concat(V.appendConfig.of(Db()))}const EO=i=>{for(let e of Ab(i)){let t=Tl(i.state,e.from,e.to);if(t)return i.dispatch({effects:Ob(i.state,[na.of(t),Tb(i,t)])}),!0}return!1},RO=i=>{if(!i.state.field(Ci,!1))return!1;let e=[];for(let t of Ab(i)){let n=Nl(i.state,t.from,t.to);n&&e.push(so.of(n),Tb(i,n,!1))}return e.length&&i.dispatch({effects:e}),e.length>0};function Tb(i,e,t=!0){let n=i.state.doc.lineAt(e.from).number,r=i.state.doc.lineAt(e.to).number;return R.announce.of(`${i.state.phrase(t?"Folded lines":"Unfolded lines")} ${n} ${i.state.phrase("to")} ${r}.`)}const BO=i=>{let{state:e}=i,t=[];for(let n=0;n<e.doc.length;){let r=i.lineBlockAt(n),s=Tl(e,r.from,r.to);s&&t.push(na.of(s)),n=(s?i.lineBlockAt(s.to):r).to+1}return t.length&&i.dispatch({effects:Ob(i.state,t)}),!!t.length},PO=i=>{let e=i.state.field(Ci,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,i.state.doc.length,(n,r)=>{t.push(so.of({from:n,to:r}))}),i.dispatch({effects:t}),!0},KI=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:EO},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:RO},{key:"Ctrl-Alt-[",run:BO},{key:"Ctrl-Alt-]",run:PO}],LO={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Nb=D.define({combine(i){return Ai(i,LO)}});function Db(i){return[Ci,VO]}function Ib(i,e){let{state:t}=i,n=t.facet(Nb),r=o=>{let l=i.lineBlockAt(i.posAtDOM(o.target)),a=Nl(i.state,l.from,l.to);a&&i.dispatch({effects:so.of(a)}),o.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(i,r,e);let s=document.createElement("span");return s.textContent=n.placeholderText,s.setAttribute("aria-label",t.phrase("folded code")),s.title=t.phrase("unfold"),s.className="cm-foldPlaceholder",s.onclick=r,s}const sm=J.replace({widget:new class extends gn{toDOM(i){return Ib(i,null)}}});class FO extends gn{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Ib(e,this.value)}}const zO={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class ih extends fn{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function qI(i={}){let e={...zO,...i},t=new ih(e,!0),n=new ih(e,!1),r=be.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet($n)!=o.state.facet($n)||o.startState.field(Ci,!1)!=o.state.field(Ci,!1)||Ne(o.startState)!=Ne(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new Bn;for(let a of o.viewportLineBlocks){let h=Nl(o.state,a.from,a.to)?n:Tl(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:s}=e;return[r,QA({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(r))===null||l===void 0?void 0:l.markers)||$.empty},initialSpacer(){return new ih(e,!1)},domEventHandlers:{...s,click:(o,l,a)=>{if(s.click&&s.click(o,l,a))return!0;let h=Nl(o.state,l.from,l.to);if(h)return o.dispatch({effects:so.of(h)}),!0;let c=Tl(o.state,l.from,l.to);return c?(o.dispatch({effects:na.of(c)}),!0):!1}}}),Db()]}const VO=R.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class oo{constructor(e,t){this.specs=e;let n;function r(l){let a=Hn.newName();return(n||(n=Object.create(null)))["."+a]=l,a}const s=typeof t.all=="string"?t.all:t.all?r(t.all):void 0,o=t.scope;this.scope=o instanceof pt?l=>l.prop(ni)==o.data:o?l=>l==o:void 0,this.style=yb(e.map(l=>({tag:l.tag,class:l.class||r(Object.assign({},l,{tag:null}))})),{all:s}).style,this.module=n?new Hn(n):null,this.themeType=t.themeType}static define(e,t){return new oo(e,t||{})}}const Ac=D.define(),Eb=D.define({combine(i){return i.length?[i[0]]:null}});function rh(i){let e=i.facet(Ac);return e.length?e:i.facet(Eb)}function jI(i,e){let t=[WO],n;return i instanceof oo&&(i.module&&t.push(R.styleModule.of(i.module)),n=i.themeType),e?.fallback?t.push(Eb.of(i)):n?t.push(Ac.computeN([R.darkTheme],r=>r.facet(R.darkTheme)==(n=="dark")?[i]:[])):t.push(Ac.of(i)),t}class HO{constructor(e){this.markCache=Object.create(null),this.tree=Ne(e.state),this.decorations=this.buildDeco(e,rh(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Ne(e.state),n=rh(e.state),r=n!=rh(e.startState),{viewport:s}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<s.to&&!r&&t.type==this.tree.type&&o>=s.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n),this.decoratedTo=s.to)}buildDeco(e,t){if(!t||!this.tree.length)return J.none;let n=new Bn;for(let{from:r,to:s}of e.visibleRanges)dO(this.tree,t,(o,l,a)=>{n.add(o,l,this.markCache[a]||(this.markCache[a]=J.mark({class:a})))},r,s);return n.finish()}}const WO=Mi.high(be.fromClass(HO,{decorations:i=>i.decorations})),JI=oo.define([{tag:v.meta,color:"#404740"},{tag:v.link,textDecoration:"underline"},{tag:v.heading,textDecoration:"underline",fontWeight:"bold"},{tag:v.emphasis,fontStyle:"italic"},{tag:v.strong,fontWeight:"bold"},{tag:v.strikethrough,textDecoration:"line-through"},{tag:v.keyword,color:"#708"},{tag:[v.atom,v.bool,v.url,v.contentSeparator,v.labelName],color:"#219"},{tag:[v.literal,v.inserted],color:"#164"},{tag:[v.string,v.deleted],color:"#a11"},{tag:[v.regexp,v.escape,v.special(v.string)],color:"#e40"},{tag:v.definition(v.variableName),color:"#00f"},{tag:v.local(v.variableName),color:"#30a"},{tag:[v.typeName,v.namespace],color:"#085"},{tag:v.className,color:"#167"},{tag:[v.special(v.variableName),v.macroName],color:"#256"},{tag:v.definition(v.propertyName),color:"#00c"},{tag:v.comment,color:"#940"},{tag:v.invalid,color:"#f00"}]),$O=R.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Rb=1e4,Bb="()[]{}",Pb=D.define({combine(i){return Ai(i,{afterCursor:!0,brackets:Bb,maxScanDistance:Rb,renderMatch:jO})}}),KO=J.mark({class:"cm-matchingBracket"}),qO=J.mark({class:"cm-nonmatchingBracket"});function jO(i){let e=[],t=i.matched?KO:qO;return e.push(t.range(i.start.from,i.start.to)),i.end&&e.push(t.range(i.end.from,i.end.to)),e}function om(i){let e=[],t=i.facet(Pb);for(let n of i.selection.ranges){if(!n.empty)continue;let r=Kt(i,n.head,-1,t)||n.head>0&&Kt(i,n.head-1,1,t)||t.afterCursor&&(Kt(i,n.head,1,t)||n.head<i.doc.length&&Kt(i,n.head+1,-1,t));r&&(e=e.concat(t.renderMatch(r,i)))}return J.set(e,!0)}const JO=be.fromClass(class{constructor(i){this.paused=!1,this.decorations=om(i.state)}update(i){(i.docChanged||i.selectionSet||this.paused)&&(i.view.composing?(this.decorations=this.decorations.map(i.changes),this.paused=!0):(this.decorations=om(i.state),this.paused=!1))}},{decorations:i=>i.decorations}),_O=[JO,$O];function _I(i={}){return[Pb.of(i),_O]}const UO=new H;function Oc(i,e,t){let n=i.prop(e<0?H.openedBy:H.closedBy);if(n)return n;if(i.name.length==1){let r=t.indexOf(i.name);if(r>-1&&r%2==(e<0?1:0))return[t[r+e]]}return null}function Tc(i){let e=i.type.prop(UO);return e?e(i.node):i}function Kt(i,e,t,n={}){let r=n.maxScanDistance||Rb,s=n.brackets||Bb,o=Ne(i),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Oc(a.type,t,s);if(h&&a.from<a.to){let c=Tc(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return GO(i,e,t,a,c,h,s)}}return YO(i,e,t,o,l.type,r,s)}function GO(i,e,t,n,r,s,o){let l=n.parent,a={from:r.from,to:r.to},h=0,c=l?.cursor();if(c&&(t<0?c.childBefore(n.from):c.childAfter(n.to)))do if(t<0?c.to<=n.from:c.from>=n.to){if(h==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let f=Tc(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(Oc(c.type,t,o))h++;else if(Oc(c.type,-t,o)){if(h==0){let f=Tc(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function YO(i,e,t,n,r,s,o){if(t<0?!e:e==i.doc.length)return null;let l=t<0?i.sliceDoc(e-1,e):i.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=i.doc.iterRange(e,t>0?i.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=s;){let d=c.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||n.resolveInner(p+m,1).type!=r))if(y%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}function XO(i){return{name:i.name||"",token:i.token,blankLine:i.blankLine||(()=>{}),startState:i.startState||(()=>!0),copyState:i.copyState||QO,indent:i.indent||(()=>null),languageData:i.languageData||{},tokenTable:i.tokenTable||vf,mergeTokens:i.mergeTokens!==!1}}function QO(i){if(typeof i!="object")return i;let e={};for(let t in i){let n=i[t];e[t]=n instanceof Array?n.slice():n}return e}const lm=new WeakMap;class Lb extends pt{constructor(e){let t=kb(e.languageData),n=XO(e),r,s=new class extends V0{createParse(o,l,a){return new eT(r,o,l,a)}};super(t,s,[],e.name),this.topNode=iT(t,this),r=this,this.streamParser=n,this.stateAfter=new H({perNode:!0}),this.tokenTable=e.tokenTable?new Hb(n.tokenTable):nT}static define(e){return new Lb(e)}getIndent(e){let t,{overrideIndentation:n}=e.options;n&&(t=lm.get(e.state),t!=null&&t<e.pos-1e4&&(t=void 0));let r=Cf(this,e.node.tree,e.node.from,e.node.from,t??e.pos),s,o;if(r?(o=r.state,s=r.pos+1):(o=this.streamParser.startState(e.unit),s=e.node.from),e.pos-s>1e4)return null;for(;s<e.pos;){let a=e.state.doc.lineAt(s),h=Math.min(e.pos,a.to);if(a.length){let c=n?n(a.from):-1,f=new bb(a.text,e.state.tabSize,e.unit,c<0?void 0:c);for(;f.pos<h-a.from;)zb(this.streamParser.token,f,o)}else this.streamParser.blankLine(o,e.unit);if(h==e.pos)break;s=a.to+1}let l=e.lineAt(e.pos);return n&&t==null&&lm.set(e.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],e)}get allowsNesting(){return!1}}function Cf(i,e,t,n,r){let s=t>=n&&t+e.length<=r&&e.prop(i.stateAfter);if(s)return{state:i.streamParser.copyState(s),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof ie&&a<r&&Cf(i,l,a,n,r);if(h)return h}return null}function Fb(i,e,t,n,r){if(r&&t<=0&&n>=e.length)return e;!r&&t==0&&e.type==i.topNode&&(r=!0);for(let s=e.children.length-1;s>=0;s--){let o=e.positions[s],l=e.children[s],a;if(o<n&&l instanceof ie){if(!(a=Fb(i,l,t-o,n-o,r)))break;return r?new ie(e.type,e.children.slice(0,s).concat(a),e.positions.slice(0,s+1),o+a.length):a}}return null}function ZO(i,e,t,n,r){for(let s of e){let o=s.from+(s.openStart?25:0),l=s.to-(s.openEnd?25:0),a=o<=t&&l>t&&Cf(i,s.tree,0-s.offset,t,l),h;if(a&&a.pos<=n&&(h=Fb(i,s.tree,t+s.offset,a.pos+s.offset,!1)))return{state:a.state,tree:h}}return{state:i.streamParser.startState(r?Si(r):4),tree:ie.empty}}class eT{constructor(e,t,n,r){this.lang=e,this.input=t,this.fragments=n,this.ranges=r,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=r[r.length-1].to;let s=gr.get(),o=r[0].from,{state:l,tree:a}=ZO(e,n,o,this.to,s?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);s&&this.parsedPos<s.viewport.from-1e5&&r.some(h=>h.from<=s.viewport.from&&h.to>=s.viewport.from)&&(this.state=this.lang.streamParser.startState(Si(s.state)),s.skipUntilInView(this.parsedPos,s.viewport.from),this.parsedPos=s.viewport.from),this.moveRangeIndex()}advance(){let e=gr.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),n=Math.min(t,this.chunkStart+512);for(e&&(n=Math.min(n,e.viewport.to));this.parsedPos<n;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
|
|
11
|
+
`);return{dom:a,text:u,slice:e}}function Bg(i,e,t,n,r){let s=r.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(n||s||!t);if(a){if(i.someProp("transformPastedText",u=>{e=u(e,s||n,i)}),s)return l=new E(A.from(i.state.schema.text(e.replace(/\r\n?/g,`
|
|
12
|
+
`))),0,0),i.someProp("transformPasted",u=>{l=u(l,i,!0)}),l;let f=i.someProp("clipboardTextParser",u=>u(e,r,n,i));if(f)l=f;else{let u=r.marks(),{schema:d}=i.state,p=yr.fromSchema(d);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(d.text(m,u)))})}}else i.someProp("transformPastedHTML",f=>{t=f(t,i)}),o=Kw(t),zl&&qw(o);let h=o&&o.querySelector("[data-pm-slice]"),c=h&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(h.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let u=o.firstChild;for(;u&&!B(u);)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(i.someProp("clipboardParser")||i.someProp("domParser")||nr.fromSchema(i.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||c),context:r,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!Hw.test(u.parentNode.nodeName)?{ignore:!0}:null}})),c)l=jw(md(l,+c[1],+c[2]),c[4]);else if(l=E.maxOpen(Ww(l.content,r),!0),l.openStart||l.openEnd){let f=0,u=0;for(let d=l.content.firstChild;f<l.openStart&&!d.type.spec.isolating;f++,d=d.firstChild);for(let d=l.content.lastChild;u<l.openEnd&&!d.type.spec.isolating;u++,d=d.lastChild);l=md(l,f,u)}return i.someProp("transformPasted",f=>{l=f(l,i,a)}),l}const Hw=/^(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 Ww(i,e){if(i.childCount<2)return i;for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(i.forEach(l=>{if(!o)return;let a=r.findWrapping(l.type),h;if(!a)return o=null;if(h=o.length&&s.length&&Lg(a,s,l,o[o.length-1],0))o[o.length-1]=h;else{o.length&&(o[o.length-1]=Fg(o[o.length-1],s.length));let c=Pg(l,a);o.push(c),r=r.matchType(c.type),s=a}}),o)return A.from(o)}return i}function Pg(i,e,t=0){for(let n=e.length-1;n>=t;n--)i=e[n].create(null,A.from(i));return i}function Lg(i,e,t,n,r){if(r<i.length&&r<e.length&&i[r]==e[r]){let s=Lg(i,e,t,n.lastChild,r+1);if(s)return n.copy(n.content.replaceChild(n.childCount-1,s));if(n.contentMatchAt(n.childCount).matchType(r==i.length-1?t.type:i[r+1]))return n.copy(n.content.append(A.from(Pg(t,i,r+1))))}}function Fg(i,e){if(e==0)return i;let t=i.content.replaceChild(i.childCount-1,Fg(i.lastChild,e-1)),n=i.contentMatchAt(i.childCount).fillBefore(A.empty,!0);return i.copy(t.append(n))}function Mh(i,e,t,n,r,s){let o=e<0?i.firstChild:i.lastChild,l=o.content;return i.childCount>1&&(s=0),r<n-1&&(l=Mh(l,e,t,n,r+1,s)),r>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=r).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(A.empty,!0))),i.replaceChild(e<0?0:i.childCount-1,o.copy(l))}function md(i,e,t){return e<i.openStart&&(i=new E(Mh(i.content,-1,e,i.openStart,0,i.openEnd),e,i.openEnd)),t<i.openEnd&&(i=new E(Mh(i.content,1,t,i.openEnd,0,0),i.openStart,t)),i}const Vg={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function zg(){return document.implementation.createHTMLDocument("title")}let Tr=null;function $w(i){let e=window.trustedTypes;if(!e)return i;if(!Tr){if(Tr=e.defaultPolicy)try{return Tr.createHTML(i)}catch{}Tr=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return Tr.createHTML(i)}function Kw(i){let e=/^(\s*<meta [^>]*>)*/.exec(i);e&&(i=i.slice(e[0].length));let t=zg(),n=t.body,r=/<([a-z][^>\s]+)/i.exec(i),s;if((s=r&&Vg[r[1].toLowerCase()])&&(i=s.map(o=>"<"+o+">").join("")+i+s.map(o=>"</"+o+">").reverse().join("")),n.innerHTML=$w(i),s)for(let o=0;o<s.length;o++)n=n.querySelector(s[o])||n;for(let o=0;o<t.styleSheets.length;o++){let l=t.styleSheets[o];for(let a=0;a<l.rules.length;a++){let h=l.rules[a];if(h instanceof CSSStyleRule){let c=n.querySelectorAll(h.selectorText);for(let f=0;f<c.length;f++)c[f].style.cssText+=h.style.cssText}}}return n}function qw(i){let e=i.querySelectorAll(Oe?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let n=e[t];n.childNodes.length==1&&n.textContent==" "&&n.parentNode&&n.parentNode.replaceChild(i.ownerDocument.createTextNode(" "),n)}}function jw(i,e){if(!i.size)return i;let t=i.content.firstChild.type.schema,n;try{n=JSON.parse(e)}catch{return i}let{content:r,openStart:s,openEnd:o}=i;for(let l=n.length-2;l>=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;try{r=A.from(a.create(n[l+1],r))}catch{break}s++,o++}return new E(r,s,o)}const Ke={},qe={},Jw={touchstart:!0,touchmove:!0};let _w=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastKeyDispatched=!1,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 Uw(i){for(let e in Ke){let t=Ke[e];i.dom.addEventListener(e,i.input.eventHandlers[e]=n=>{Yw(i,n)&&!zc(i,n)&&(i.editable||!(n.type in qe))&&t(i,n)},Jw[e]?{passive:!0}:void 0)}Le&&i.dom.addEventListener("input",()=>null),Ah(i)}function rn(i,e){i.input.lastSelectionOrigin=e,i.input.lastSelectionTime=Date.now()}function Gw(i){i.input.mouseDown&&i.input.mouseDown.done(),i.domObserver.stop();for(let e in i.input.eventHandlers)i.dom.removeEventListener(e,i.input.eventHandlers[e]);clearTimeout(i.input.composingTimeout),clearTimeout(i.input.lastIOSEnterFallbackTimeout)}function Ah(i){i.someProp("handleDOMEvents",e=>{for(let t in e)i.input.eventHandlers[t]||i.dom.addEventListener(t,i.input.eventHandlers[t]=n=>zc(i,n))})}function zc(i,e){return i.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(i,e)||e.defaultPrevented:!1})}function Yw(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=i.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Xw(i,e){!zc(i,e)&&Ke[e.type]&&(i.editable||!(e.type in qe))&&Ke[e.type](i,e)}function Sn(i,e){let{input:t}=i;return t.lastKeyDispatched||i.composing?!1:(t.lastKeyDispatched=!0,typeof e=="string"&&(e=nw(e=="Backspace"?8:13,e)),i.someProp("handleKeyDown",n=>n(i,e)))}qe.keydown=(i,e)=>{let t=e;if(i.input.shiftKey=t.keyCode==16||t.shiftKey,!Kg(i)&&(i.input.lastKeyCode=t.keyCode,i.input.lastKeyCodeTime=Date.now(),i.input.lastKeyDispatched=!1,!(nn&&Oe&&t.keyCode==13)))if(t.keyCode!=229&&i.domObserver.forceFlush(),or&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();i.input.lastIOSEnter=n,i.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{i.input.lastIOSEnter==n&&(Sn(i,"Enter"),i.input.lastIOSEnter=0)},200)}else Sn(i,t)||zw(i,t)?t.preventDefault():rn(i,"key")};qe.keyup=(i,e)=>{e.keyCode==16&&(i.input.shiftKey=!1)};qe.keypress=(i,e)=>{let t=e;if(Kg(i)||!t.charCode||t.ctrlKey&&!t.altKey||ht&&t.metaKey)return;if(i.someProp("handleKeyPress",r=>r(i,t))){t.preventDefault();return}let n=i.state.selection;if(!(n instanceof K)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(t.charCode),s=()=>i.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!i.someProp("handleTextInput",o=>o(i,n.$from.pos,n.$to.pos,r,s))&&i.dispatch(s()),t.preventDefault()}};function Gs(i){return{left:i.clientX,top:i.clientY}}function Qw(i,e){let t=e.x-i.clientX,n=e.y-i.clientY;return t*t+n*n<100}function Hc(i,e,t,n,r){if(n==-1)return!1;let s=i.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(i.someProp(e,l=>o>s.depth?l(i,t,s.nodeAfter,s.before(o),r,!0):l(i,t,s.node(o),s.before(o),r,!1)))return!0;return!1}function Ys(i,e,t){if(i.focused||i.focus(),i.state.selection.eq(e))return;let n=i.state.tr.setSelection(e);n.setMeta("pointer",!0),i.dispatch(n)}function Zw(i,e){if(e==-1)return!1;let t=i.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&V.isSelectable(n)?(Ys(i,new V(t)),!0):!1}function eS(i,e){if(e==-1)return!1;let t=i.state.selection,n,r;t instanceof V&&(n=t.node);let s=i.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(V.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?r=s.before(t.$from.depth):r=s.before(o);break}}return r!=null?(Ys(i,V.create(i.state.doc,r)),!0):!1}function tS(i,e,t,n,r){return Hc(i,"handleClickOn",e,t,n)||i.someProp("handleClick",s=>s(i,e,n))||(r?eS(i,t):Zw(i,t))}function nS(i,e,t,n){return Hc(i,"handleDoubleClickOn",e,t,n)||i.someProp("handleDoubleClick",r=>r(i,e,n))}function iS(i,e,t,n){return Hc(i,"handleTripleClickOn",e,t,n)||i.someProp("handleTripleClick",r=>r(i,e,n))||rS(i,t,n)}function rS(i,e,t){if(t.button!=0)return!1;let n=Hg(i,e,!0),r=i.state.doc;return n?(Ys(i,n),n instanceof K&&r.eq(i.state.doc)&&(i.input.mouseDown=new oS(i,n)),!0):!1}function Hg(i,e,t){let n=i.state.doc;if(e==-1)return n.inlineContent?K.create(n,0,n.content.size):null;let r=n.resolve(e);for(let s=r.depth+1;s>0;s--){let o=s>r.depth?r.nodeAfter:r.node(s),l=r.before(s);if(o.inlineContent)return K.create(n,l+1,l+1+o.content.size);if(t&&V.isSelectable(o))return V.create(n,l)}return null}function Wc(i){return ol(i)}const Wg=ht?"metaKey":"ctrlKey";Ke.mousedown=(i,e)=>{let t=e;i.input.shiftKey=t.shiftKey;let n=Wc(i),r=Date.now(),s="singleClick";r-i.input.lastClick.time<500&&Qw(t,i.input.lastClick)&&!t[Wg]&&i.input.lastClick.button==t.button&&(i.input.lastClick.type=="singleClick"?s="doubleClick":i.input.lastClick.type=="doubleClick"&&(s="tripleClick")),i.input.lastClick={time:r,x:t.clientX,y:t.clientY,type:s,button:t.button},i.input.mouseDown&&i.input.mouseDown.done();let o=i.posAtCoords(Gs(t));o&&(s=="singleClick"?i.input.mouseDown=new sS(i,o,t,!!n):(s=="doubleClick"?nS:iS)(i,o.pos,o.inside,t)?t.preventDefault():rn(i,"pointer"))};class $g{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}}class sS extends $g{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[Wg],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let c=e.state.doc.resolve(t.pos);s=c.parent,o=c.depth?c.before():0}const l=r?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&B(a.nodeDOM)?a.nodeDOM:null;let{selection:h}=e.state;n.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||h instanceof V&&h.from<=o&&h.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ot&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),rn(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||sn(this.view)})}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(Gs(e))),this.updateAllowDefault(e),this.allowDefault||!t?rn(this.view,"pointer"):tS(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Le&&this.mightDrag&&!this.mightDrag.node.isAtom||Oe&&!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)?(Ys(this.view,_.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):rn(this.view,"pointer")}move(e){this.updateAllowDefault(e),rn(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}}class oS extends $g{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),rn(this.view,"pointer");let t=this.view.posAtCoords(Gs(e)),n=t&&Hg(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,s=this.startSelection,[o,l]=n.from<s.from?[s.to,n.from]:[s.from,n.to];Ys(this.view,K.create(r,o,l))}}Ke.touchstart=i=>{i.input.lastTouch=Date.now(),Wc(i),rn(i,"pointer")};Ke.touchmove=i=>{i.input.lastTouch=Date.now(),rn(i,"pointer")};Ke.contextmenu=i=>Wc(i);function Kg(i,e){return i.composing?!0:Le&&Math.abs(Date.now()-i.input.compositionEndedAt)<500?(i.input.compositionEndedAt=-2e8,!0):!1}const lS=nn?5e3:-1;qe.compositionstart=qe.compositionupdate=i=>{if(!i.composing){i.domObserver.flush();let{state:e}=i,t=e.selection.$to;if(e.selection instanceof K&&e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||Oe&&bg&&aS(i)))i.markCursor=i.state.storedMarks||t.marks(),ol(i,!0),i.markCursor=null;else if(ol(i,!e.selection.empty),ot&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=i.domSelectionRange();for(let r=n.focusNode,s=n.focusOffset;r&&B(r)&&s!=0;){let o=s<0?r.lastChild:r.childNodes[s-1];if(!o)break;if(ge(o)){let l=i.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else r=o,s=-1}}i.input.composing=!0}qg(i,lS)};function aS(i){let{focusNode:e,focusOffset:t}=i.domSelectionRange();if(!e||!B(e)||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return B(n)&&n.contentEditable=="false"}qe.compositionend=(i,e)=>{i.composing&&(i.input.composing=!1,i.input.compositionEndedAt=Date.now(),i.input.compositionPendingChanges=i.domObserver.pendingRecords().length?i.input.compositionID:0,i.input.compositionNode=null,i.input.badSafariComposition?i.domObserver.forceFlush():i.input.compositionPendingChanges&&Promise.resolve().then(()=>i.domObserver.flush()),i.input.compositionID++,qg(i,20))};function qg(i,e){clearTimeout(i.input.composingTimeout),e>-1&&(i.input.composingTimeout=setTimeout(()=>ol(i),e))}function jg(i){for(i.composing&&(i.input.composing=!1,i.input.compositionEndedAt=Date.now());i.input.compositionNodes.length>0;)i.input.compositionNodes.pop().markParentsDirty()}function hS(i){let e=i.domSelectionRange();if(!e.focusNode)return null;let t=Zx(e.focusNode,e.focusOffset),n=ew(e.focusNode,e.focusOffset);if(t&&n&&t!=n){let r=n.pmViewDesc,s=i.domObserver.lastChangedTextNode;if(t==s||n==s)return s;if(!r||!r.isText(n.nodeValue))return n;if(i.input.compositionNode==n){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return n}}return t||n}function ol(i,e=!1){if(!(nn&&i.domObserver.flushingSoon>=0)){if(i.domObserver.forceFlush(),jg(i),e||i.docView&&i.docView.dirty){let t=Lc(i),n=i.state.selection;return t&&!t.eq(n)?i.dispatch(i.state.tr.setSelection(t)):(i.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?i.dispatch(i.state.tr.deleteSelection()):i.updateState(i.state),!0}return!1}}function cS(i,e){if(!i.dom.parentNode)return;let t=i.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),r=document.createRange();r.selectNodeContents(e),i.dom.blur(),n.removeAllRanges(),n.addRange(r),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),i.focus()},50)}const ps=et&&Dn<15||or&&sw<604;Ke.copy=qe.cut=(i,e)=>{let t=e,n=i.state.selection,r=t.type=="cut";if(n.empty)return;let s=ps?null:t.clipboardData,o=n.content(),{dom:l,text:a}=Vc(i,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):cS(i,l),r&&i.dispatch(i.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function fS(i){return i.openStart==0&&i.openEnd==0&&i.content.childCount==1?i.content.firstChild:null}function uS(i,e){if(!i.dom.parentNode)return;let t=i.input.shiftKey||i.state.selection.$from.parent.type.spec.code,n=i.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let r=i.input.shiftKey&&i.input.lastKeyCode!=45;setTimeout(()=>{i.focus(),n.parentNode&&n.parentNode.removeChild(n),t?ms(i,n.value,null,r,e):ms(i,n.textContent,n.innerHTML,r,e)},50)}function ms(i,e,t,n,r){let s=Bg(i,e,t,n,i.state.selection.$from);if(i.someProp("handlePaste",a=>a(i,r,s||E.empty)))return!0;if(!s)return!1;let o=fS(s),l=o?i.state.tr.replaceSelectionWith(o,n):i.state.tr.replaceSelection(s);return i.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Jg(i){let e=i.getData("text/plain")||i.getData("Text");if(e)return e;let t=i.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}qe.paste=(i,e)=>{let t=e;if(i.composing&&!nn)return;let n=ps?null:t.clipboardData,r=i.input.shiftKey&&i.input.lastKeyCode!=45;n&&ms(i,Jg(n),n.getData("text/html"),r,t)?t.preventDefault():uS(i,t)};class _g{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const dS=ht?"altKey":"ctrlKey";function Ug(i,e){let t;return i.someProp("dragCopies",n=>{t=t||n(e)}),t!=null?!t:!e[dS]}Ke.dragstart=(i,e)=>{let t=e,n=i.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let r=i.state.selection,s=r.empty?null:i.posAtCoords(Gs(t)),o;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof V?r.to-1:r.to))){if(n&&n.mightDrag)o=V.create(i.state.doc,n.mightDrag.pos);else if(t.target&&B(t.target)){let f=i.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=i.docView&&(o=V.create(i.state.doc,f.posBefore))}}let l=(o||i.state.selection).content(),{dom:a,text:h,slice:c}=Vc(i,l);(!t.dataTransfer.files.length||!Oe||yg>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ps?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",ps||t.dataTransfer.setData("text/plain",h),i.dragging=new _g(c,Ug(i,t),o)};Ke.dragend=i=>{let e=i.dragging;window.setTimeout(()=>{i.dragging==e&&(i.dragging=null)},50)};qe.dragover=qe.dragenter=(i,e)=>e.preventDefault();qe.drop=(i,e)=>{try{pS(i,e,i.dragging)}finally{i.dragging=null}};function pS(i,e,t){if(!e.dataTransfer)return;let n=i.posAtCoords(Gs(e));if(!n)return;let r=i.state.doc.resolve(n.pos),s=t&&t.slice;s?i.someProp("transformPasted",d=>{s=d(s,i,!1)}):s=Bg(i,Jg(e.dataTransfer),ps?null:e.dataTransfer.getData("text/html"),!1,r);let o=!!(t&&Ug(i,e));if(i.someProp("handleDrop",d=>d(i,e,s||E.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?v1(i.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let a=i.state.tr;if(o){let{node:d}=t;d?d.replace(a):a.deleteSelection()}let h=a.mapping.map(l),c=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(c?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(c&&V.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new V(u));else{let d=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,y)=>d=y),a.setSelection(Fc(i,u,a.doc.resolve(d)))}i.focus(),i.dispatch(a.setMeta("uiEvent","drop"))}Ke.focus=i=>{if(i.input.lastFocus=Date.now(),!i.focused){i.domObserver.stop(),i.dom.classList.add("ProseMirror-focused"),i.domObserver.start(),i.focused=!0;let e=i.domSelectionRange();if(!i.domObserver.currentSelection.eq(e)){let{focusNode:t,focusOffset:n}=e;setTimeout(()=>{let r=i.domSelectionRange();r.focusNode==t&&r.focusOffset==n&&i.docView&&i.hasFocus()&&sn(i)},20)}}};Ke.blur=(i,e)=>{let t=e;i.focused&&(i.domObserver.stop(),i.dom.classList.remove("ProseMirror-focused"),i.domObserver.start(),t.relatedTarget&&i.dom.contains(t.relatedTarget)&&i.domObserver.currentSelection.clear(),i.focused=!1)};Ke.beforeinput=(i,e)=>{if(nn&&e.inputType=="deleteContentBackward"){i.domObserver.flushSoon();let{domChangeCount:n}=i.input;setTimeout(()=>{if(i.input.domChangeCount!=n||i.domObserver.pendingRecords().length||(i.dom.blur(),i.focus(),Sn(i,"Backspace")))return;let{$cursor:r}=i.state.selection;r&&r.pos>0&&i.dispatch(i.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let i in qe)Ke[i]=qe[i];function gs(i,e){if(i==e)return!0;for(let t in i)if(i[t]!==e[t])return!1;for(let t in e)if(!(t in i))return!1;return!0}let Oh=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index<this.frag.childCount;){let t=this.frag.child(this.index);if(this.off==e)return t;this.off+=t.nodeSize,this.index++}return null}},gd=class Gg{constructor(e,t){this.toDOM=e,this.spec=t||li,this.side=this.spec.side||0}map(e,t,n,r){let{pos:s,deleted:o}=e.mapResult(t.from+r,this.side<0?-1:1);return o?null:new Ln(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Gg&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&gs(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}};class Rn{constructor(e,t){this.attrs=e,this.spec=t||li}map(e,t,n,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new Ln(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Rn&&gs(this.attrs,e.attrs)&&gs(this.spec,e.spec)}static is(e){return e.type instanceof Rn}destroy(){}}let mS=class Yg{constructor(e,t){this.attrs=e,this.spec=t||li}map(e,t,n,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let o=e.mapResult(t.to+r,-1);return o.deleted||o.pos<=s.pos?null:new Ln(s.pos-n,o.pos-n,this)}valid(e,t,n){let r=n.nodeAt(t.from);return!!r&&!r.isText&&t.from+r.nodeSize==t.to}eq(e){return this==e||e instanceof Yg&&gs(this.attrs,e.attrs)&&gs(this.spec,e.spec)}destroy(){}},Ln=class Vr{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Vr(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,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new Vr(e,e,new gd(t,n))}static inline(e,t,n,r){return new Vr(e,t,new Rn(n,r))}static node(e,t,n,r){return new Vr(e,t,new mS(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Rn}get widget(){return this.type instanceof gd}};const Bi=[],li={};class de{constructor(e,t){this.local=e.length?e:Bi,this.children=t.length?t:Bi}static create(e,t){return t.length?ll(t,e,0,li):De}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+r,l.to+r))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,r+l,s)}}map(e,t,n){return this==De||e.maps.length==0?this:this.mapInner(e,t,0,0,n||li)}mapInner(e,t,n,r,s){let o;if(this.local.length){let l=new Oh(t.content);for(let a=0;a<this.local.length;a++){let h=this.local[a].map(e,n,r);h&&h.type.valid(t,h,l)?(o||(o=[])).push(h):s.onRemove&&s.onRemove(this.local[a].spec)}}return this.children.length?gS(this.children,o||[],e,t,n,r,s):o?new de(o.sort(ai),Bi):De}add(e,t){return t.length?this==De?de.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,s=0;e.forEach((l,a)=>{let h=a+n,c;if(c=Qg(t,l,h)){for(r||(r=this.children.slice());s<r.length&&r[s]<a;)s+=3;r[s]==a?r[s+2]=r[s+2].addInner(l,c,h+1):r.splice(s,0,a,a+l.nodeSize,ll(c,l,h+1,li)),s+=3}});let o=Xg(s?Zg(t):t,-n);if(o.length){let l=new Oh(e.content);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a],l)||o.splice(a--,1)}return new de(o.length?this.local.concat(o).sort(ai):this.local,r||this.children)}remove(e){return e.length==0||this==De?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let s=0;s<n.length;s+=3){let o,l=n[s]+t,a=n[s+1]+t;for(let c=0,f;c<e.length;c++)(f=e[c])&&f.from>l&&f.to<a&&(e[c]=null,(o||(o=[])).push(f));if(!o)continue;n==this.children&&(n=this.children.slice());let h=n[s+2].removeInner(o,l+1);h!=De?n[s+2]=h:(n.splice(s,3),s-=3)}if(r.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<r.length;l++)r[l].eq(o,t)&&(r==this.local&&(r=this.local.slice()),r.splice(l--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new de(r,n):De}forChild(e,t){if(this==De)return this;if(t.isLeaf)return de.empty;let n,r;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof Rn){let h=Math.max(s,a.from)-s,c=Math.min(o,a.to)-s;h<c&&(r||(r=[])).push(a.copy(h,c))}}if(r){let l=new de(r.sort(ai),Bi);return n?new Cn([l,n]):l}return n||De}eq(e){if(this==e)return!0;if(!(e instanceof de)||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 $c(this.localsInner(e))}localsInner(e){if(this==De)return Bi;if(e.inlineContent||!this.local.some(Rn.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Rn||t.push(this.local[n]);return t}forEachSet(e){e(this)}}de.empty=new de([],[]);de.removeOverlap=$c;const De=de.empty;class Cn{constructor(e){this.members=e}map(e,t){const n=this.members.map(r=>r.map(e,t,li));return Cn.from(n)}forChild(e,t){if(t.isLeaf)return de.empty;let n=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=De&&(s instanceof Cn?n=n.concat(s.members):n.push(s))}return Cn.from(n)}eq(e){if(!(e instanceof Cn)||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,n=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(!t)t=s;else{n&&(t=t.slice(),n=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?$c(n?t:t.sort(ai)):Bi}static from(e){switch(e.length){case 0:return De;case 1:return e[0];default:return new Cn(e.every(t=>t instanceof de)?e:e.reduce((t,n)=>t.concat(n instanceof de?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function gS(i,e,t,n,r,s,o){let l=i.slice();for(let h=0,c=s;h<t.maps.length;h++){let f=0;t.maps[h].forEach((u,d,p,m)=>{let g=m-p-(d-u);for(let y=0;y<l.length;y+=3){let b=l[y+1];if(b<0||u>b+c-f)continue;let k=l[y]+c-f;d>=k?l[y+1]=u<=k?-2:-1:u>=c&&g&&(l[y]+=g,l[y+1]+=g)}f+=g}),c=t.maps[h].map(c,-1)}let a=!1;for(let h=0;h<l.length;h+=3)if(l[h+1]<0){if(l[h+1]==-2){a=!0,l[h+1]=-1;continue}let c=t.map(i[h]+s),f=c-r;if(f<0||f>=n.content.size){a=!0;continue}let u=t.map(i[h+1]+s,-1),d=u-r,{index:p,offset:m}=n.content.findIndex(f),g=n.maybeChild(p);if(g&&m==f&&m+g.nodeSize==d){let y=l[h+2].mapInner(t,g,c+1,i[h]+s+1,o);y!=De?(l[h]=f,l[h+1]=d,l[h+2]=y):(l[h+1]=-2,a=!0)}else a=!0}if(a){let h=yS(l,i,e,t,r,s,o),c=ll(h,n,0,o);e=c.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,u=0;f<c.children.length;f+=3){let d=c.children[f];for(;u<l.length&&l[u]<d;)u+=3;l.splice(u,0,c.children[f],c.children[f+1],c.children[f+2])}}return new de(e.sort(ai),l)}function Xg(i,e){if(!e||!i.length)return i;let t=[];for(let n=0;n<i.length;n++){let r=i[n];t.push(new Ln(r.from+e,r.to+e,r.type))}return t}function yS(i,e,t,n,r,s,o){function l(a,h){for(let c=0;c<a.local.length;c++){let f=a.local[c].map(n,r,h);f?t.push(f):o.onRemove&&o.onRemove(a.local[c].spec)}for(let c=0;c<a.children.length;c+=3)l(a.children[c+2],a.children[c]+h+1)}for(let a=0;a<i.length;a+=3)i[a+1]==-1&&l(i[a+2],e[a]+s+1);return t}function Qg(i,e,t){if(e.isLeaf)return null;let n=t+e.nodeSize,r=null;for(let s=0,o;s<i.length;s++)(o=i[s])&&o.from>t&&o.to<n&&((r||(r=[])).push(o),i[s]=null);return r}function Zg(i){let e=[];for(let t=0;t<i.length;t++)i[t]!=null&&e.push(i[t]);return e}function ll(i,e,t,n){let r=[],s=!1;e.forEach((l,a)=>{let h=Qg(i,l,a+t);if(h){s=!0;let c=ll(h,l,t+a+1,n);c!=De&&r.push(a,a+l.nodeSize,c)}});let o=Xg(s?Zg(i):i,-t).sort(ai);if(o.length){let l=new Oh(e.content);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a],l)||(n.onRemove&&n.onRemove(o[a].spec),o.splice(a--,1))}return o.length||r.length?new de(o,r):De}function ai(i,e){return i.from-e.from||i.to-e.to}function $c(i){let e=i;for(let t=0;t<e.length-1;t++){let n=e[t];if(n.from!=n.to)for(let r=t+1;r<e.length;r++){let s=e[r];if(s.from==n.from){s.to!=n.to&&(e==i&&(e=i.slice()),e[r]=s.copy(s.from,n.to),yd(e,r+1,s.copy(n.to,s.to)));continue}else{s.from<n.to&&(e==i&&(e=i.slice()),e[t]=n.copy(n.from,s.from),yd(e,r,n.copy(s.from,n.to)));break}}}return e}function yd(i,e,t){for(;e<i.length&&ai(t,i[e])>0;)e++;i.splice(e,0,t)}function ka(i){let e=[];return i.someProp("decorations",t=>{let n=t(i.state);n&&n!=De&&e.push(n)}),i.cursorWrapper&&e.push(de.create(i.state.doc,[i.cursorWrapper.deco])),Cn.from(e)}const bS={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},kS=et&&Dn<=11;class xS{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}}let wS=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new xS,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let r=0;r<n.length;r++)this.queue.push(n[r]);et&&Dn<=11&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():Le&&e.composing&&n.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),kS&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.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,bS)),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(hd(this.view)){if(this.suppressingSelectionUpdates)return sn(this.view);if(et&&Dn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&yi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let s=e.focusNode;s;s=sr(s))t.add(s);for(let s=e.anchorNode;s;s=sr(s))if(t.has(s)){n=s;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:ge(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n,r=!1;!this.suppressingSelectionUpdates&&hd(e)&&(n=e.domSelectionRange(),r=!this.currentSelection.eq(n)&&!this.ignoreSelectionChange(n));let s=-1,o=-1,l=!1,a=[];if(e.editable)for(let c=0;c<t.length;c++){let f=this.registerMutation(t[c],a);f&&(s=s<0?f.from:Math.min(f.from,s),o=o<0?f.to:Math.max(f.to,o),f.typeOver&&(l=!0))}if(a.some(c=>c.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||Oe&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(c=>c.type=="childList"&&c.removedNodes.length))){for(let c of a)if(c.nodeName=="BR"&&c.parentNode){let f=c.nextSibling;for(;f&&B(f);){if(f.contentEditable=="false"){c.parentNode.removeChild(c);break}f=f.firstChild}}}else if(ot&&a.length){let c=a.filter(f=>f.nodeName=="BR");if(c.length==2){let[f,u]=c;f.parentNode&&f.parentNode.parentNode==u.parentNode?u.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let u of c){let d=u.parentNode;d&&d.nodeName=="LI"&&(!f||vS(e,f)!=d)&&u.remove()}}}let h=null;s<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Vl(n)&&(h=Lc(e))&&h.eq(_.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,sn(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,o),SS(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,MS(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):n&&!this.currentSelection.eq(n)&&sn(e),n&&this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;c<e.addedNodes.length;c++){let f=e.addedNodes[c];t.push(f),ge(f)&&(this.lastChangedTextNode=f)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,s=e.nextSibling;if(et&&Dn<=11&&e.addedNodes.length)for(let c=0;c<e.addedNodes.length;c++){let{previousSibling:f,nextSibling:u}=e.addedNodes[c];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(r=f),(!u||Array.prototype.indexOf.call(e.addedNodes,u)<0)&&(s=u)}let o=r&&r.parentNode==e.target?Me(r)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?Me(s):e.target.childNodes.length,h=n.localPosFromDOM(e.target,a,1);return{from:l,to:h}}else return e.type=="attributes"?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},bd=new WeakMap,kd=!1;function SS(i){if(!bd.has(i)&&(bd.set(i,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(i.dom).whiteSpace)!==-1)){if(i.requiresGeckoHackNode=ot,kd)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."),kd=!0}}function xd(i,e){let t=e.startContainer,n=e.startOffset,r=e.endContainer,s=e.endOffset,o=i.domAtPos(i.state.selection.anchor);return yi(o.node,o.offset,r,s)&&([t,n,r,s]=[r,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}}function CS(i,e){if(e.getComposedRanges){let r=e.getComposedRanges(i.root)[0];if(r)return xd(i,r)}let t;function n(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return i.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),i.dom.removeEventListener("beforeinput",n,!0),t?xd(i,t):null}function vS(i,e){for(let t=e.parentNode;t&&t!=i.dom;t=t.parentNode){let n=i.docView.nearestDesc(t,!0);if(n&&n.node.isBlock)return t}return null}function MS(i,e){var t;let{focusNode:n,focusOffset:r}=i.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||!B(a)||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),n==s&&i.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function AS(i,e,t,n){let{node:r,fromOffset:s,toOffset:o,from:l,to:a}=i.docView.parseRange(e,t),h=i.domSelectionRange(),c,f=h.anchorNode;if(f&&bi(i.dom,f)&&(c=[{node:f,offset:h.anchorOffset}],Vl(h)||c.push({node:h.focusNode,offset:h.focusOffset})),Oe&&i.input.lastKeyCode===8)for(let y=o;y>s;y--){let b=r.childNodes[y-1],k=b.pmViewDesc;if(b.nodeName=="BR"&&!k){o=y;break}if(!k||k.size)break}let u=i.state.doc,d=i.someProp("domParser")||nr.fromSchema(i.state.schema),p=u.resolve(l),m=null,g=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:s,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:OS(n),context:p});if(c&&c[0].pos!=null){let y=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=y),m={anchor:y+l,head:b+l}}return{doc:g,sel:m,from:l,to:a}}const OS=i=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(i);if(e.nodeName=="BR"&&e.parentNode){if(Le&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(e.parentNode.lastChild==e||Le&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},TS=/^(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 NS(i,e,t,n,r){let s=i.input.compositionPendingChanges||(i.composing?i.input.compositionID:0);if(i.input.compositionPendingChanges=0,e<0){let C=i.input.lastSelectionTime>Date.now()-50?i.input.lastSelectionOrigin:null,I=Lc(i,C);if(I&&!i.state.selection.eq(I)){if(Oe&&nn&&i.input.lastKeyCode===13&&Date.now()-100<i.input.lastKeyCodeTime&&Sn(i,"Enter"))return;let P=i.state.tr.setSelection(I);C=="pointer"?P.setMeta("pointer",!0):C=="key"&&P.scrollIntoView(),s&&P.setMeta("composition",s),i.dispatch(P)}return}let o=i.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=i.state.doc.resolve(t).after(l+1);let a=i.state.selection,h=AS(i,e,t,r),c=i.state.doc,f=c.slice(h.from,h.to),u,d;i.input.lastKeyCode===8&&Date.now()-100<i.input.lastKeyCodeTime?(u=i.state.selection.to,d="end"):(u=i.state.selection.from,d="start"),i.input.lastKeyCode=null;let p=RS(f.content,h.doc.content,h.from,u,d);if(p&&i.input.domChangeCount++,(or&&i.input.lastIOSEnter>Date.now()-225||nn)&&r.some(C=>B(C)&&!TS.test(C.nodeName))&&(!p||p.endA>=p.endB)&&Sn(i,"Enter")){i.input.lastIOSEnter=0;return}if(!p)if(n&&a instanceof K&&!a.empty&&a.$head.sameParent(a.$anchor)&&!i.composing&&!(h.sel&&h.sel.anchor!=h.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(h.sel){let C=wd(i,i.state.doc,h.sel);if(C&&!C.eq(i.state.selection)){let I=i.state.tr.setSelection(C);s&&I.setMeta("composition",s),i.dispatch(I)}}return}i.state.selection.from<i.state.selection.to&&p.start==p.endB&&i.state.selection instanceof K&&(p.start>i.state.selection.from&&p.start<=i.state.selection.from+2&&i.state.selection.from>=h.from?p.start=i.state.selection.from:p.endA<i.state.selection.to&&p.endA>=i.state.selection.to-2&&i.state.selection.to<=h.to&&(p.endB+=i.state.selection.to-p.endA,p.endA=i.state.selection.to)),et&&Dn<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>h.from&&h.doc.textBetween(p.start-h.from-1,p.start-h.from+1)==" "&&(p.start--,p.endA--,p.endB--);let m=h.doc.resolveNoCache(p.start-h.from),g=h.doc.resolveNoCache(p.endB-h.from),y=c.resolve(p.start),b=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA;if((or&&i.input.lastIOSEnter>Date.now()-225&&(!b||r.some(C=>C.nodeName=="DIV"||C.nodeName=="P"))||!b&&ES(h.doc,m.pos,g.pos))&&Sn(i,"Enter")){i.input.lastIOSEnter=0;return}if(i.state.selection.anchor>p.start&&(b?p.endA>p.start&&p.endB==p.start:IS(c,p.start,p.endA,m,g))&&Sn(i,"Backspace")){nn&&Oe&&i.domObserver.suppressSelectionUpdates();return}Oe&&p.endB==p.start&&(i.input.lastChromeDelete=Date.now()),nn&&!b&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&h.sel&&h.sel.anchor==h.sel.head&&h.sel.head==p.endA&&(p.endB-=2,g=h.doc.resolveNoCache(p.endB-h.from),setTimeout(()=>Sn(i,"Enter"),20));let k=p.start,O=p.endA,w=C=>{let I=C||i.state.tr.replace(k,O,h.doc.slice(p.start-h.from,p.endB-h.from));if(h.sel){let P=wd(i,I.doc,h.sel);P&&!(Oe&&i.composing&&P.empty&&(p.start!=p.endB||i.input.lastChromeDelete<Date.now()-100)&&(P.head==k||P.head==I.mapping.map(O)-1)||et&&P.empty&&P.head==k)&&I.setSelection(P)}return s&&I.setMeta("composition",s),I.scrollIntoView()},M;if(b)if(m.pos==g.pos){et&&Dn<=11&&m.parentOffset==0&&(i.domObserver.suppressSelectionUpdates(),setTimeout(()=>sn(i),20));let C=w(i.state.tr.delete(k,O)),I=c.resolve(p.start).marksAcross(c.resolve(p.endA));I&&C.ensureMarks(I),i.dispatch(C)}else if(p.endA==p.endB&&(M=DS(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start())))){let C=w(i.state.tr);M.type=="add"?C.addMark(k,O,M.mark):C.removeMark(k,O,M.mark),i.dispatch(C)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let C=m.parent.textBetween(m.parentOffset,g.parentOffset),I=()=>w(i.state.tr.insertText(C,k,O));i.someProp("handleTextInput",P=>P(i,k,O,C,I))||i.dispatch(I())}else i.dispatch(w());else i.dispatch(w())}function wd(i,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Fc(i,e.resolve(t.anchor),e.resolve(t.head))}function DS(i,e){let t=i.firstChild.marks,n=e.firstChild.marks,r=t,s=n,o,l,a;for(let c=0;c<n.length;c++)r=n[c].removeFromSet(r);for(let c=0;c<t.length;c++)s=t[c].removeFromSet(s);if(r.length==1&&s.length==0)l=r[0],o="add",a=c=>c.mark(l.addToSet(c.marks));else if(r.length==0&&s.length==1)l=s[0],o="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let h=[];for(let c=0;c<e.childCount;c++)h.push(a(e.child(c)));if(A.from(h).eq(i))return{mark:l,type:o}}function IS(i,e,t,n,r){if(t-e<=r.pos-n.pos||xa(n,!0,!1)<r.pos)return!1;let s=i.resolve(e);if(!n.parent.inlineContent){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=i.resolve(xa(s,!0,!0));return!o.parent.isTextblock||o.pos>t||xa(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function ES(i,e,t){let n=0,r=0;return i.nodesBetween(e,t,(s,o)=>{s.isTextblock&&o>=e&&o<t?n++:(s.isText?/\S/.test(s.text.slice(Math.max(0,e-o),Math.min(s.nodeSize,t-o))):s.isLeaf)&&r++}),r==0&&n==1}function xa(i,e,t){let n=i.depth,r=e?i.end():i.pos;for(;n>0&&(e||i.indexAfter(n)==i.node(n).childCount);)n--,r++,e=!1;if(t){let s=i.node(n).maybeChild(i.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,r++}return r}function RS(i,e,t,n,r){let s=i.findDiffStart(e,t),o=t+i.size,l=t+e.size;if(s==null)return null;let{a,b:h}=i.findDiffEnd(e,o,l);if(r=="end"){let c=Math.max(0,s-Math.min(a,h));n-=a+c-s}if(a<s&&o<l){let c=n<=s&&n>=a?s-n:0;s-=c,h=s+(h-a),a=s}else if(h<s){let c=n<=s&&n>=h?s-n:0;s-=c,a=s+(a-h),h=s}return{start:s,endA:a,endB:h}}let e0=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 _w,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Ad),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=vd(this),Cd(this),this.nodeViews=Md(this),this.docView=id(this.state.doc,Sd(this),ka(this),this.dom,this),this.domObserver=new wS(this,(n,r,s,o)=>NS(this,n,r,s,o)),this.domObserver.start(),Uw(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&&Ah(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ad),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let r=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(jg(this),o=!0),this.state=e;let l=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let d=Md(this);PS(d,this.nodeViews)&&(this.nodeViews=d,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Ah(this),this.editable=vd(this),Cd(this);let a=ka(this),h=Sd(this),c=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,h,a);(f||!e.selection.eq(r.selection))&&(o=!0);let u=c=="preserve"&&o&&this.dom.style.overflowAnchor==null&&aw(this);if(o){this.domObserver.stop();let d=f&&(et||Oe)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&BS(r.selection,e.selection);if(f){let m=Oe?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=hS(this)),(s||!this.docView.update(e.doc,h,a,this))&&(this.docView.updateOuterDeco(h),this.docView.destroy(),this.docView=id(e.doc,h,a,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(d=!0)}let p=this.input.mouseDown;d||!(p&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ew(this)&&p.delaySelUpdate())?sn(this,d):(Ig(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((n=this.dragging)===null||n===void 0)&&n.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():u&&hw(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!bi(this.dom,e))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof V){let t=this.docView.domAfterPos(this.state.selection.from);B(t)&&Qu(this,t.getBoundingClientRect(),e)}else Qu(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 n=this.directPlugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let n=this.state.plugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let s=n.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==n.node&&(r=s)}this.dragging=new _g(e.slice,e.move,r<0?void 0:V.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(r=t?t(l):l))return r}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(r=t?t(l):l))return r}}hasFocus(){if(et){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&&cw(this.dom),sn(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 mw(this,e)}coordsAtPos(e,t=1){return Cg(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return xw(this,t||this.state,e)}pasteHTML(e,t){return ms(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ms(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Vc(this,e)}destroy(){this.docView&&(Gw(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],ka(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Xx())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Xw(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?Le&&this.root.nodeType===11&&iw(this.dom.ownerDocument)==this.dom&&CS(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};e0.prototype.dispatch=function(i){let e=this._props.dispatchTransaction;e?e.call(this,i):this.updateState(this.state.apply(i))};function Sd(i){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(i.editable),i.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(i.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[Ln.node(0,i.state.doc.content.size,e)]}function Cd(i){if(i.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),i.cursorWrapper={dom:e,deco:Ln.widget(i.state.selection.from,e,{raw:!0,marks:i.markCursor})}}else i.cursorWrapper=null}function vd(i){return!i.someProp("editable",e=>e(i.state)===!1)}function BS(i,e){let t=Math.min(i.$anchor.sharedDepth(i.head),e.$anchor.sharedDepth(e.head));return i.$anchor.start(t)!=e.$anchor.start(t)}function Md(i){let e=Object.create(null);function t(n){for(let r in n)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=n[r])}return i.someProp("nodeViews",t),i.someProp("markViews",t),e}function PS(i,e){let t=0,n=0;for(let r in i){if(i[r]!=e[r])return!0;t++}for(let r in e)n++;return t!=n}function Ad(i){if(i.spec.state||i.spec.filterTransaction||i.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function dn(i,e){return i.meta={package:"@milkdown/core",group:"System",...e},i}var t0={text:(i,e,t,n)=>{const r=i.value;return/^[^*_\\]*\s+$/.test(r)?r:t.safe(r,{...n,encode:[]})},strong:(i,e,t,n)=>{const r=i.marker||t.options.strong||"*",s=t.enter("strong"),o=t.createTracker(n);let l=o.move(r+r);return l+=o.move(t.containerPhrasing(i,{before:l,after:r,...o.current()})),l+=o.move(r+r),s(),l},emphasis:(i,e,t,n)=>{const r=i.marker||t.options.emphasis||"*",s=t.enter("emphasis"),o=t.createTracker(n);let l=o.move(r);return l+=o.move(t.containerPhrasing(i,{before:l,after:r,...o.current()})),l+=o.move(r),s(),l}},on=q({},"editorView"),zr=q({},"editorState"),wa=q([],"initTimer"),Od=q({},"editor"),ys=q([],"inputRules"),Fn=q([],"prosePlugins"),bs=q([],"remarkPlugins"),ks=q([],"nodeView"),xs=q([],"markView"),hi=q(rh().use(sh).use(uh),"remark"),Ur=q({handlers:t0,encode:[]},"remarkStringifyOptions"),zo=Ut("ConfigReady");function LS(i){const e=t=>(t.record(zo),async()=>(await i(t),t.done(zo),()=>{t.clearTimer(zo)}));return dn(e,{displayName:"Config"}),e}var Wi=Ut("InitReady");function FS(i){const e=t=>(t.inject(Od,i).inject(Fn,[]).inject(bs,[]).inject(ys,[]).inject(ks,[]).inject(xs,[]).inject(Ur,{handlers:t0,encode:[]}).inject(hi,rh().use(sh).use(uh)).inject(wa,[zo]).record(Wi),async()=>{await t.waitTimers(wa);const n=t.get(Ur);return t.set(hi,rh().use(sh).use(uh,n)),t.done(Wi),()=>{t.remove(Od).remove(Fn).remove(bs).remove(ys).remove(ks).remove(xs).remove(Ur).remove(hi).remove(wa).clearTimer(Wi)}});return dn(e,{displayName:"Init"}),e}var We=Ut("SchemaReady"),Sa=q([],"schemaTimer"),jt=q({},"schema"),Gr=q([],"nodes"),Yr=q([],"marks");function Td(i){return{...i,parseDOM:i.parseDOM?.map(e=>({priority:i.priority,...e}))}}var n0=i=>(i.inject(jt,{}).inject(Gr,[]).inject(Yr,[]).inject(Sa,[Wi]).record(We),async()=>{await i.waitTimers(Sa);const e=i.get(hi),t=i.get(bs).reduce((o,l)=>o.use(l.plugin,l.options),e);i.set(hi,t);const n=Object.fromEntries(i.get(Gr).map(([o,l])=>[o,Td(l)])),r=Object.fromEntries(i.get(Yr).map(([o,l])=>[o,Td(l)])),s=new Zk({nodes:n,marks:r});return i.set(jt,s),i.done(We),()=>{i.remove(jt).remove(Gr).remove(Yr).remove(Sa).clearTimer(We)}});dn(n0,{displayName:"Schema"});var i0=class{constructor(){this.#t=new Um,this.#e=null,this.setCtx=i=>{this.#e=i},this.chain=()=>{if(this.#e==null)throw ua();const i=this.#e,e=[],t=this.get.bind(this),n={run:()=>{const s=br(...e),o=i.get(on);return s(o.state,o.dispatch,o)},inline:s=>(e.push(s),n),pipe:r.bind(this)};function r(s,o){const l=t(s);return e.push(l(o)),n}return n}}#t;#e;get ctx(){return this.#e}create(i,e){const t=i.create(this.#t.sliceMap);return t.set(e),t}get(i){return this.#t.get(i).get()}remove(i){return this.#t.remove(i)}call(i,e){if(this.#e==null)throw ua();const t=this.get(i)(e),n=this.#e.get(on);return t(n.state,n.dispatch,n)}inline(i){if(this.#e==null)throw ua();const e=this.#e.get(on);return i(e.state,e.dispatch,e)}};function VS(i="cmdKey"){return q((()=>()=>!1),i)}var le=q(new i0,"commands"),Ca=q([We],"commandsTimer"),Xr=Ut("CommandsReady"),r0=i=>{const e=new i0;return e.setCtx(i),i.inject(le,e).inject(Ca,[We]).record(Xr),async()=>(await i.waitTimers(Ca),i.done(Xr),()=>{i.remove(le).remove(Ca).clearTimer(Xr)})};dn(r0,{displayName:"Commands"});function zS(i){return i.Backspace=br(bx,Nc,Z1,Qm),i}var s0=class{constructor(){this.#t=null,this.#e=[],this.setCtx=i=>{this.#t=i},this.add=i=>(this.#e.push(i),()=>{this.#e=this.#e.filter(e=>e!==i)}),this.addObjectKeymap=i=>{const e=[];return Object.entries(i).forEach(([t,n])=>{if(typeof n=="function"){const r={key:t,onRun:()=>n};this.#e.push(r),e.push(()=>{this.#e=this.#e.filter(s=>s!==r)})}else this.#e.push(n),e.push(()=>{this.#e=this.#e.filter(r=>r!==n)})}),()=>{e.forEach(t=>t())}},this.addBaseKeymap=()=>{const i=zS(gx);return this.addObjectKeymap(i)},this.build=()=>{const i={};return this.#e.forEach(e=>{i[e.key]=[...i[e.key]||[],e]}),Object.fromEntries(Object.entries(i).map(([e,t])=>{const n=t.sort((s,o)=>(o.priority??50)-(s.priority??50));return[e,(s,o,l)=>{const a=this.#t;if(a==null)throw Pl();const h=n.map(c=>c.onRun(a));return br(...h)(s,o,l)}]}))}}#t;#e;get ctx(){return this.#t}},al=q(new s0,"keymap"),va=q([We],"keymapTimer"),Qr=Ut("KeymapReady"),HS=i=>{const e=new s0;return e.setCtx(i),i.inject(al,e).inject(va,[We]).record(Qr),async()=>(await i.waitTimers(va),i.done(Qr),()=>{i.remove(al).remove(va).clearTimer(Qr)})},Ho=Ut("ParserReady"),o0=(()=>{throw Pl()}),Zr=q(o0,"parser"),Ma=q([],"parserTimer"),l0=i=>(i.inject(Zr,o0).inject(Ma,[We]).record(Ho),async()=>{await i.waitTimers(Ma);const e=i.get(hi),t=i.get(jt);return i.set(Zr,Ux.create(t,e)),i.done(Ho),()=>{i.remove(Zr).remove(Ma).clearTimer(Ho)}});dn(l0,{displayName:"Parser"});var Wo=Ut("SerializerReady"),Aa=q([],"serializerTimer"),a0=(()=>{throw Pl()}),$o=q(a0,"serializer"),h0=i=>(i.inject($o,a0).inject(Aa,[We]).record(Wo),async()=>{await i.waitTimers(Aa);const e=i.get(hi),t=i.get(jt);return i.set($o,Yx.create(t,e)),i.done(Wo),()=>{i.remove($o).remove(Aa).clearTimer(Wo)}});dn(h0,{displayName:"Serializer"});var Oa=q("","defaultValue"),Ko=q(i=>i,"stateOptions"),Ta=q([],"editorStateTimer"),qo=Ut("EditorStateReady");function WS(i,e,t){if(typeof i=="string")return e(i);if(i.type==="html")return nr.fromSchema(t).parse(i.dom);if(i.type==="json")return yt.fromJSON(t,i.value);throw F1(i)}var $S=new Kn("MILKDOWN_STATE_TRACKER"),c0=i=>(i.inject(Oa,"").inject(zr,{}).inject(Ko,e=>e).inject(Ta,[Ho,Wo,Xr,Qr]).record(qo),async()=>{await i.waitTimers(Ta);const e=i.get(jt),t=i.get(Zr),n=i.get(ys),r=i.get(Ko),s=i.get(Fn),o=WS(i.get(Oa),t,e),l=i.get(al),a=l.addBaseKeymap(),h=[...s,new un({key:$S,state:{init:()=>{},apply:(u,d,p,m)=>{i.set(zr,m)}}}),Mx({rules:n}),jx(l.build())];i.set(Fn,h);const c=r({schema:e,doc:o,plugins:h}),f=Km.create(c);return i.set(zr,f),i.done(qo),()=>{a(),i.remove(Oa).remove(zr).remove(Ko).remove(Ta).clearTimer(qo)}});dn(c0,{displayName:"EditorState"});var ws=q([],"pasteRule"),Na=q([We],"pasteRuleTimer"),jo=Ut("PasteRuleReady"),f0=i=>(i.inject(ws,[]).inject(Na,[We]).record(jo),async()=>(await i.waitTimers(Na),i.done(jo),()=>{i.remove(ws).remove(Na).clearTimer(jo)}));dn(f0,{displayName:"PasteRule"});var Da=Ut("EditorViewReady"),Ia=q([],"editorViewTimer"),Ea=q({},"editorViewOptions"),Ra=q(null,"root"),Th=q(null,"rootDOM"),Nh=q({},"rootAttrs");function KS(i,e){const t=document.createElement("div");t.className="milkdown",i.appendChild(t),e.set(Th,t);const n=e.get(Nh);return Object.entries(n).forEach(([r,s])=>t.setAttribute(r,s)),t}function qS(i){i.classList.add("editor"),i.setAttribute("role","textbox")}var jS=new Kn("MILKDOWN_VIEW_CLEAR"),u0=i=>(i.inject(Ra,document.body).inject(on,{}).inject(Ea,{}).inject(Th,null).inject(Nh,{}).inject(Ia,[qo,jo]).record(Da),async()=>{await i.wait(Wi);const e=i.get(Ra)||document.body,t=typeof e=="string"?document.querySelector(e):e;i.update(Fn,a=>[new un({key:jS,view:h=>{const c=t?KS(t,i):void 0;return(()=>{if(c&&t){const u=h.dom;t.replaceChild(c,u),c.appendChild(u)}})(),{destroy:()=>{c?.parentNode&&c?.parentNode.replaceChild(h.dom,c),c?.remove()}}}}),...a]),await i.waitTimers(Ia);const n=i.get(zr),r=i.get(Ea),s=Object.fromEntries(i.get(ks)),o=Object.fromEntries(i.get(xs)),l=new e0(t,{state:n,nodeViews:s,markViews:o,transformPasted:(a,h,c)=>(i.get(ws).sort((f,u)=>(u.priority??50)-(f.priority??50)).map(f=>f.run).forEach(f=>{a=f(a,h,c)}),a),...r});return qS(l.dom),i.set(on,l),i.done(Da),()=>{l?.destroy(),i.remove(Ra).remove(on).remove(Ea).remove(Th).remove(Nh).remove(Ia).clearTimer(Da)}});dn(u0,{displayName:"EditorView"});var fD=(function(i){return i.Idle="Idle",i.OnCreate="OnCreate",i.Created="Created",i.OnDestroy="OnDestroy",i.Destroyed="Destroyed",i})({}),uD=class d0{constructor(){this.#t=!1,this.#e="Idle",this.#i=[],this.#n=()=>{},this.#s=new Um,this.#o=new Y1,this.#r=new Map,this.#l=new Map,this.#a=new G1(this.#s,this.#o),this.#d=()=>{const e=LS(async n=>{await Promise.all(this.#i.map(r=>Promise.resolve(r(n))))}),t=[n0,l0,h0,r0,HS,f0,c0,u0,FS(this),e];this.#c(t,this.#l)},this.#c=(e,t)=>{e.forEach(n=>{const r=this.#a.produce(this.#t?n.meta:void 0),s=n(r);t.set(n,{ctx:r,handler:s,cleanup:void 0})})},this.#f=(e,t=!1)=>Promise.all([e].flat().map(async n=>{const r=this.#r.get(n)?.cleanup;return t?this.#r.delete(n):this.#r.set(n,{ctx:void 0,handler:void 0,cleanup:void 0}),typeof r=="function"?r():r})),this.#p=async()=>{await Promise.all([...this.#l.entries()].map(async([e,{cleanup:t}])=>typeof t=="function"?t():t)),this.#l.clear()},this.#h=e=>{this.#e=e,this.#n(e)},this.#u=e=>[...e.entries()].map(async([t,n])=>{const{ctx:r,handler:s}=n;if(!s)return;const o=await s();e.set(t,{ctx:r,handler:s,cleanup:o})}),this.enableInspector=(e=!0)=>(this.#t=e,this),this.onStatusChange=e=>(this.#n=e,this),this.config=e=>(this.#i.push(e),this),this.removeConfig=e=>(this.#i=this.#i.filter(t=>t!==e),this),this.use=e=>{const t=[e].flat();return t.flat().forEach(n=>{this.#r.set(n,{ctx:void 0,handler:void 0,cleanup:void 0})}),this.#e==="Created"&&this.#c(t,this.#r),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.#f([e].flat(),!0),this),this.create=async()=>this.#e==="OnCreate"?this:(this.#e==="Created"&&await this.destroy(),this.#h("OnCreate"),this.#d(),this.#c([...this.#r.keys()],this.#r),await Promise.all([this.#u(this.#l),this.#u(this.#r)].flat()),this.#h("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.#i=[]),this.#h("OnDestroy"),await this.#f([...this.#r.keys()],e),await this.#p(),this.#h("Destroyed"),this),this.action=e=>e(this.#a),this.inspect=()=>this.#t?[...this.#l.values(),...this.#r.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 d0}#t;#e;#i;#n;#s;#o;#r;#l;#a;#d;#c;#f;#p;#h;#u;get ctx(){return this.#a}get status(){return this.#e}};function p0(i,e,t){const n=i.findIndex(([s])=>s===e);if(n===-1)return[...i,t];const r=i.slice();return r[n]=t,r}function ee(i,e){const t=VS(i),n=r=>async()=>{n.key=t,await r.wait(Xr);const s=e(r);return r.get(le).create(t,s),n.run=o=>r.get(le).call(i,o),()=>{r.get(le).remove(t)}};return n}function Ot(i){const e=t=>async()=>{await t.wait(We);const n=i(t);return t.update(ys,r=>[...r,n]),e.inputRule=n,()=>{t.update(ys,r=>r.filter(s=>s!==n))}};return e}function dD(i){const e=t=>async()=>{await t.wait(We);const n=i(t);return t.update(ws,r=>[...r,n]),e.pasteRule=n,()=>{t.update(ws,r=>r.filter(s=>s!==n))}};return e}function JS(i,e){const t=n=>async()=>{const r=e(n);return n.update(Yr,s=>p0(s,i,[i,r])),t.id=i,t.schema=r,()=>{n.update(Yr,s=>s.filter(([o])=>o!==i))}};return t.type=n=>{const r=n.get(jt).marks[i];if(!r)throw j1(i);return r},t}function Kc(i,e){const t=n=>async()=>{const r=e(n);return n.update(Gr,s=>p0(s,i,[i,r])),t.id=i,t.schema=r,()=>{n.update(Gr,s=>s.filter(([o])=>o!==i))}};return t.type=n=>{const r=n.get(jt).nodes[i];if(!r)throw q1(i);return r},t}function Xs(i){let e;const t=n=>async()=>(await n.wait(We),e=i(n),n.update(Fn,r=>[...r,e]),()=>{n.update(Fn,r=>r.filter(s=>s!==e))});return t.plugin=()=>e,t.key=()=>e.spec.key,t}function _S(i){const e=t=>async()=>{await t.wait(Qr);const n=t.get(al),r=i(t),s=n.addObjectKeymap(r);return e.keymap=r,()=>{s()}};return e}function pD(i,e){const t=n=>async()=>{await n.wait(We);const r=e(n);return i.type(n)instanceof hs?n.update(ks,s=>[...s,[i.id,r]]):n.update(xs,s=>[...s,[i.id,r]]),t.view=r,t.type=i,()=>{i.type(n)instanceof hs?n.update(ks,s=>s.filter(o=>o[0]!==i.id)):n.update(xs,s=>s.filter(o=>o[0]!==i.id))}};return t}function pn(i,e){const t=q(i,e),n=r=>(r.inject(t),()=>()=>{r.remove(t)});return n.key=t,n}function xt(i,e){const t=pn(e,i),n=Kc(i,s=>s.get(t.key)(s)),r=[t,n];return r.id=n.id,r.node=n,r.type=s=>n.type(s),r.ctx=t,r.key=t.key,r.extendSchema=s=>xt(i,s(e)),r}function Qs(i,e){const t=pn(e,i),n=JS(i,s=>s.get(t.key)(s)),r=[t,n];return r.id=n.id,r.mark=n,r.type=s=>n.type(s),r.ctx=t,r.key=t.key,r.extendSchema=s=>Qs(i,s(e)),r}function Tt(i,e){const t=pn(Object.fromEntries(Object.entries(e).map(([s,{shortcuts:o,priority:l}])=>[s,{shortcuts:o,priority:l}])),`${i}Keymap`),n=_S(s=>{const o=s.get(t.key),l=Object.entries(e).flatMap(([a,{command:h}])=>{const c=o[a],f=[c.shortcuts].flat(),u=c.priority;return f.map(d=>[d,{key:d,onRun:h,priority:u}])});return Object.fromEntries(l)}),r=[t,n];return r.ctx=t,r.shortcuts=n,r.key=t.key,r.keymap=n.keymap,r}var Nt=(i,e=()=>({}))=>pn(e,`${i}Attr`),Wl=(i,e=()=>({}))=>pn(e,`${i}Attr`);function kr(i,e,t){const n=pn({},i),r=o=>async()=>{await o.wait(Wi);const l={plugin:e(o),options:o.get(n.key)};return o.update(bs,a=>[...a,l]),()=>{o.update(bs,a=>a.filter(h=>h!==l))}},s=[n,r];return s.id=i,s.plugin=r,s.options=n,s}function mD(i){return e=>{const t=e.get(on);return e.get(jt),e.get($o)(t.state.doc)}}function gD(i,e=!1){return t=>{const n=t.get(on),r=t.get(Zr)(i);if(!r)return;if(!e){const{state:a}=n;return n.dispatch(a.tr.replace(0,a.doc.content.size,new E(r.content,0,0)))}const s=t.get(jt),o=t.get(Ko)({schema:s,doc:r,plugins:t.get(Fn)}),l=Km.create(o);n.updateState(l)}}const US=1024;let GS=0,ft=class{constructor(e,t){this.from=e,this.to=t}};class H{constructor(e={}){this.id=GS++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=je.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}}H.closedBy=new H({deserialize:i=>i.split(" ")});H.openedBy=new H({deserialize:i=>i.split(" ")});H.group=new H({deserialize:i=>i.split(" ")});H.isolate=new H({deserialize:i=>{if(i&&i!="rtl"&&i!="ltr"&&i!="auto")throw new RangeError("Invalid value for isolate: "+i);return i||"auto"}});H.contextHash=new H({perNode:!0});H.lookAhead=new H({perNode:!0});H.mounted=new H({perNode:!0});class $i{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[H.mounted.id]}}const YS=Object.create(null);class je{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(e){let t=e.props&&e.props.length?Object.create(null):YS,n=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),r=new je(e.name||"",t,e.id,n);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(r)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return r}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(H.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(" "))t[r]=e[n];return n=>{for(let r=n.prop(H.group),s=-1;s<(r?r.length:0);s++){let o=t[s<0?n.name:r[s]];if(o)return o}}}}je.none=new je("",Object.create(null),0,8);class qc{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let n of this.types){let r=null;for(let s of e){let o=s(n);if(o){r||(r=Object.assign({},n.props));let l=o[1],a=o[0];a.combine&&a.id in r&&(l=a.combine(r[a.id],l)),r[a.id]=l}}t.push(r?new je(n.name,r,n.id,n.flags):n)}return new qc(t)}}const yo=new WeakMap,Nd=new WeakMap;var Q;(function(i){i[i.ExcludeBuffers=1]="ExcludeBuffers",i[i.IncludeAnonymous=2]="IncludeAnonymous",i[i.IgnoreMounts=4]="IgnoreMounts",i[i.IgnoreOverlays=8]="IgnoreOverlays",i[i.EnterBracketed=16]="EnterBracketed"})(Q||(Q={}));class ie{constructor(e,t,n,r,s){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,l]of s)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=$i.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let n of this.children){let r=n.toString();r&&(t&&(t+=","),t+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new hl(this.topNode,e)}cursorAt(e,t=0,n=0){let r=yo.get(this)||this.topNode,s=new hl(r);return s.moveTo(e,t),yo.set(this,s._tree),s}get topNode(){return new Pe(this,0,0,null)}resolve(e,t=0){let n=Ss(yo.get(this)||this.topNode,e,t,!1);return yo.set(this,n),n}resolveInner(e,t=0){let n=Ss(Nd.get(this)||this.topNode,e,t,!0);return Nd.set(this,n),n}resolveStack(e,t=0){return ZS(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:s=this.length}=e,o=e.mode||0,l=(o&Q.IncludeAnonymous)>0;for(let a=this.cursor(o|Q.IncludeAnonymous);;){let h=!1;if(a.from<=s&&a.to>=r&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&n&&(l||!a.type.isAnonymous)&&n(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:_c(je.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new ie(this.type,t,n,r,this.propValues),e.makeTree||((t,n,r)=>new ie(je.none,t,n,r)))}static build(e){return eC(e)}}ie.empty=new ie(je.none,[],[],0);class jc{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new jc(this.buffer,this.index)}}class Vn{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return je.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],s=r.name;if(/\W/.test(s)&&!r.isError&&(s=JSON.stringify(s)),e+=4,n==e)return s;let o=[];for(;e<n;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,n,r,s){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(m0(s,r,o[a+1],o[a+2])&&(l=a,n>0));a=o[a+3]);return l}slice(e,t,n){let r=this.buffer,s=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){s[a++]=r[l++],s[a++]=r[l++]-n;let h=s[a++]=r[l++]-n;s[a++]=r[l++]-e,o=Math.max(o,h)}return new Vn(s,o,this.set)}}function m0(i,e,t,n){switch(i){case-2:return t<e;case-1:return n>=e&&t<e;case 0:return t<e&&n>e;case 1:return t<=e&&n>e;case 2:return n>e;case 4:return!0}}function Ss(i,e,t,n){for(var r;i.from==i.to||(t<1?i.from>=e:i.from>e)||(t>-1?i.to<=e:i.to<e);){let o=!n&&i instanceof Pe&&i.index<0?null:i.parent;if(!o)return i;i=o}let s=n?0:Q.IgnoreOverlays;if(n)for(let o=i,l=o.parent;l;o=l,l=o.parent)o instanceof Pe&&o.index<0&&((r=l.enter(e,t,s))===null||r===void 0?void 0:r.from)!=o.from&&(i=l);for(;;){let o=i.enter(e,t,s);if(!o)return i;i=o}}class g0{cursor(e=0){return new hl(this,e)}getChild(e,t=null,n=null){let r=Dd(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Dd(this,e,t,n)}resolve(e,t=0){return Ss(this,e,t,!1)}resolveInner(e,t=0){return Ss(this,e,t,!0)}matchContext(e){return Dh(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let r=t.lastChild;if(!r||r.to!=t.to)break;r.type.isError&&r.from==r.to?(n=t,t=r.prevSibling):t=r}return n}get node(){return this}get next(){return this.parent}}class Pe extends g0{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,n,r,s=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],f=a[e]+o.from,u;if(!(!(s&Q.EnterBracketed&&c instanceof ie&&(u=$i.get(c))&&!u.overlay&&u.bracketed&&n>=f&&n<=f+c.length)&&!m0(r,n,f,f+c.length))){if(c instanceof Vn){if(s&Q.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,n-f,r);if(d>-1)return new Wt(new XS(o,c,e,f),null,d)}else if(s&Q.IncludeAnonymous||!c.type.isAnonymous||Jc(c)){let d;if(!(s&Q.IgnoreMounts)&&(d=$i.get(c))&&!d.overlay)return new Pe(d.tree,f,e,o);let p=new Pe(c,f,e,o);return s&Q.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,n,r,s)}}}if(s&Q.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,n=0){let r;if(!(n&Q.IgnoreOverlays)&&(r=$i.get(this._tree))&&r.overlay){let s=e-this.from,o=n&Q.EnterBracketed&&r.bracketed;for(let{from:l,to:a}of r.overlay)if((t>0||o?l<=s:l<s)&&(t<0||o?a>=s:a>s))return new Pe(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,n)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Dd(i,e,t,n){let r=i.cursor(),s=[];if(!r.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=r.type.is(t),!r.nextSibling())return s}for(;;){if(n!=null&&r.type.is(n))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return n==null?s:[]}}function Dh(i,e,t=e.length-1){for(let n=i;t>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[t]&&e[t]!=n.name)return!1;t--}}return!0}class XS{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}}class Wt extends g0{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(e,t,n){let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,n);return s<0?null:new Wt(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,n=0){if(n&Q.ExcludeBuffers)return null;let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new Wt(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new Wt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new Wt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,s=n.buffer[this.index+3];if(s>r){let o=n.buffer[this.index+1];e.push(n.slice(r,s,o)),t.push(0)}return new ie(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function y0(i){if(!i.length)return null;let e=0,t=i[0];for(let s=1;s<i.length;s++){let o=i[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let n=t instanceof Pe&&t.index<0?null:t.parent,r=i.slice();return n?r[e]=n:r.splice(e,1),new QS(r,t)}class QS{constructor(e,t){this.heads=e,this.node=t}get next(){return y0(this.heads)}}function ZS(i,e,t){let n=i.resolveInner(e,t),r=null;for(let s=n instanceof Pe?n:n.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(r||(r=[n])).push(o.resolve(e,t)),s=o}else{let o=$i.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new Pe(o.tree,o.overlay[0].from+s.from,-1,s);(r||(r=[n])).push(Ss(l,e,t,!1))}}return r?y0(r):n}class hl{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~Q.EnterBracketed,e instanceof Pe)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let n=e._parent;n;n=n._parent)this.stack.unshift(n.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof Pe?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&Q.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Q.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Q.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let r=n<0?0:this.stack[n]+4;if(this.index!=r)return this.yieldBuf(t.findChild(r,this.index,-1,0,4))}else{let r=t.buffer[this.index+3];if(r<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(r)}return n<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(r.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let s=t+e,o=e<0?-1:n._tree.children.length;s!=o;s+=e){let l=n._tree.children[s];if(this.mode&Q.IncludeAnonymous||l instanceof Vn||!l.type.isAnonymous||Jc(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)e:for(let r=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==r){if(r==this.index)return o;t=o,n=s+1;break e}r=this.stack[--s]}for(let r=n;r<this.stack.length;r++)t=new Wt(this.buffer,t,this.stack[r]);return this.bufferNode=new Wt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return Dh(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,s=this.stack.length-1;r>=0;s--){if(s<0)return Dh(this._tree,e,r);let o=n[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}return!0}}function Jc(i){return i.children.some(e=>e instanceof Vn||!e.type.isAnonymous||Jc(e))}function eC(i){var e;let{buffer:t,nodeSet:n,maxBufferLength:r=US,reused:s=[],minRepeatType:o=n.types.length}=i,l=Array.isArray(t)?new jc(t,t.length):t,a=n.types,h=0,c=0;function f(w,M,C,I,P,te){let{id:W,start:L,end:X,size:G}=l,oe=c,Ve=h;if(G<0)if(l.next(),G==-1){let Gt=s[W];C.push(Gt),I.push(L-w);return}else if(G==-3){h=W;return}else if(G==-4){c=W;return}else throw new RangeError(`Unrecognized record size: ${G}`);let tt=a[W],Et,we,lt=L-w;if(X-L<=r&&(we=g(l.pos-M,P))){let Gt=new Uint16Array(we.size-we.skip),at=l.pos-we.size,Rt=Gt.length;for(;l.pos>at;)Rt=y(we.start,Gt,Rt);Et=new Vn(Gt,X-we.start,n),lt=we.start-w}else{let Gt=l.pos-G;l.next();let at=[],Rt=[],Un=W>=o?W:-1,Ti=0,fo=X,sa=oe;for(;l.pos>Gt;)Un>=0&&l.id==Un&&l.size>=0?(l.end<=fo-r&&(p(at,Rt,L,Ti,l.end,fo,Un,sa,Ve),Ti=at.length,fo=l.end,sa=c),l.next()):te>2500?u(L,Gt,at,Rt):f(L,Gt,at,Rt,Un,te+1);if(Un>=0&&Ti>0&&Ti<at.length&&p(at,Rt,L,Ti,L,fo,Un,sa,Ve),at.reverse(),Rt.reverse(),Un>-1&&Ti>0){let ku=d(tt,Ve);Et=_c(tt,at,Rt,0,at.length,0,X-L,ku,ku)}else Et=m(tt,at,Rt,X-L,oe-X,Ve)}C.push(Et),I.push(lt)}function u(w,M,C,I){let P=[],te=0,W=-1;for(;l.pos>M;){let{id:L,start:X,end:G,size:oe}=l;if(oe>4)l.next();else{if(W>-1&&X<W)break;W<0&&(W=G-r),P.push(L,X,G),te++,l.next()}}if(te){let L=new Uint16Array(te*4),X=P[P.length-2];for(let G=P.length-3,oe=0;G>=0;G-=3)L[oe++]=P[G],L[oe++]=P[G+1]-X,L[oe++]=P[G+2]-X,L[oe++]=oe;C.push(new Vn(L,P[2]-X,n)),I.push(X-w)}}function d(w,M){return(C,I,P)=>{let te=0,W=C.length-1,L,X;if(W>=0&&(L=C[W])instanceof ie){if(!W&&L.type==w&&L.length==P)return L;(X=L.prop(H.lookAhead))&&(te=I[W]+L.length+X-P)}return m(w,C,I,P,te,M)}}function p(w,M,C,I,P,te,W,L,X){let G=[],oe=[];for(;w.length>I;)G.push(w.pop()),oe.push(M.pop()+C-P);w.push(m(n.types[W],G,oe,te-P,L-te,X)),M.push(P-C)}function m(w,M,C,I,P,te,W){if(te){let L=[H.contextHash,te];W=W?[L].concat(W):[L]}if(P>25){let L=[H.lookAhead,P];W=W?[L].concat(W):[L]}return new ie(w,M,C,I,W)}function g(w,M){let C=l.fork(),I=0,P=0,te=0,W=C.end-r,L={size:0,start:0,skip:0};e:for(let X=C.pos-w;C.pos>X;){let G=C.size;if(C.id==M&&G>=0){L.size=I,L.start=P,L.skip=te,te+=4,I+=4,C.next();continue}let oe=C.pos-G;if(G<0||oe<X||C.start<W)break;let Ve=C.id>=o?4:0,tt=C.start;for(C.next();C.pos>oe;){if(C.size<0)if(C.size==-3||C.size==-4)Ve+=4;else break e;else C.id>=o&&(Ve+=4);C.next()}P=tt,I+=G,te+=Ve}return(M<0||I==w)&&(L.size=I,L.start=P,L.skip=te),L.size>4?L:void 0}function y(w,M,C){let{id:I,start:P,end:te,size:W}=l;if(l.next(),W>=0&&I<o){let L=C;if(W>4){let X=l.pos-(W-4);for(;l.pos>X;)C=y(w,M,C)}M[--C]=L,M[--C]=te-w,M[--C]=P-w,M[--C]=I}else W==-3?h=I:W==-4&&(c=I);return C}let b=[],k=[];for(;l.pos>0;)f(i.start||0,i.bufferStart||0,b,k,-1,0);let O=(e=i.length)!==null&&e!==void 0?e:b.length?k[0]+b[0].length:0;return new ie(a[i.topID],b.reverse(),k.reverse(),O)}const Id=new WeakMap;function Jo(i,e){if(!i.isAnonymous||e instanceof Vn||e.type!=i)return 1;let t=Id.get(e);if(t==null){t=1;for(let n of e.children){if(n.type!=i||!(n instanceof ie)){t=1;break}t+=Jo(i,n)}Id.set(e,t)}return t}function _c(i,e,t,n,r,s,o,l,a){let h=0;for(let p=n;p<r;p++)h+=Jo(i,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,m,g,y,b){for(let k=g;k<y;){let O=k,w=m[k],M=Jo(i,p[k]);for(k++;k<y;k++){let C=Jo(i,p[k]);if(M+C>=c)break;M+=C}if(k==O+1){if(M>c){let C=p[O];d(C.children,C.positions,0,C.children.length,m[O]+b);continue}f.push(p[O])}else{let C=m[k-1]+p[k-1].length-w;f.push(_c(i,p,m,O,k,w,C,null,a))}u.push(w+b-s)}}return d(e,t,n,r,0),(l||a)(f,u,o)}class bD{constructor(){this.map=new WeakMap}setBuffer(e,t,n){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,n)}getBuffer(e,t){let n=this.map.get(e);return n&&n.get(t)}set(e,t){e instanceof Wt?this.setBuffer(e.context.buffer,e.index,t):e instanceof Pe&&this.map.set(e.tree,t)}get(e){return e instanceof Wt?this.getBuffer(e.context.buffer,e.index):e instanceof Pe?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class ln{constructor(e,t,n,r,s=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],n=!1){let r=[new ln(0,e.length,e,0,!1,n)];for(let s of t)s.to>e.length&&r.push(s);return r}static applyChanges(e,t,n=128){if(!t.length)return e;let r=[],s=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=n)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new ln(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&r.push(u),o.to>f)break;o=s<e.length?e[s++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return r}}class b0{startParse(e,t,n){return typeof e=="string"&&(e=new tC(e)),n=n?n.length?n.map(r=>new ft(r.from,r.to)):[new ft(0,0)]:[new ft(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let s=r.advance();if(s)return s}}}class tC{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function kD(i){return(e,t,n,r)=>new iC(e,i,t,n,r)}class Ed{constructor(e,t,n,r,s,o){this.parser=e,this.parse=t,this.overlay=n,this.bracketed=r,this.target=s,this.from=o}}function Rd(i){if(!i.length||i.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(i))}class nC{constructor(e,t,n,r,s,o,l,a){this.parser=e,this.predicate=t,this.mounts=n,this.index=r,this.start=s,this.bracketed=o,this.target=l,this.prev=a,this.depth=0,this.ranges=[]}}const Ih=new H({perNode:!0});class iC{constructor(e,t,n,r,s){this.nest=t,this.input=n,this.fragments=r,this.ranges=s,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let n=this.baseParse.advance();if(!n)return null;if(this.baseParse=null,this.baseTree=n,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let n=this.baseTree;return this.stoppedAt!=null&&(n=new ie(n.type,n.children,n.positions,n.length,n.propValues.concat([[Ih,this.stoppedAt]]))),n}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let n=Object.assign(Object.create(null),e.target.props);n[H.mounted.id]=new $i(t,e.overlay,e.parser,e.bracketed),e.target.props=n}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new oC(this.fragments),t=null,n=null,r=new hl(new Pe(this.baseTree,this.ranges[0].from,0,null),Q.IncludeAnonymous|Q.IgnoreMounts);e:for(let s,o;;){let l=!0,a;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)l=!1;else if(e.hasNode(r)){if(t){let h=t.mounts.find(c=>c.frag.from<=r.from&&c.frag.to>=r.to&&c.mount.overlay);if(h)for(let c of h.mount.overlay){let f=c.from+h.pos,u=c.to+h.pos;f>=r.from&&u<=r.to&&!t.ranges.some(d=>d.from<u&&d.to>f)&&t.ranges.push({from:f,to:u})}}l=!1}else if(n&&(o=rC(n.ranges,r.from,r.to)))l=o!=2;else if(!r.type.isAnonymous&&(s=this.nest(r,this.input))&&(r.from<r.to||!s.overlay)){r.tree||(sC(r),t&&t.depth++,n&&n.depth++);let h=e.findMounts(r.from,s.parser);if(typeof s.overlay=="function")t=new nC(s.parser,s.overlay,h,this.inner.length,r.from,!!s.bracketed,r.tree,t);else{let c=Ld(this.ranges,s.overlay||(r.from<r.to?[new ft(r.from,r.to)]:[]));c.length&&Rd(c),(c.length||!s.overlay)&&this.inner.push(new Ed(s.parser,c.length?s.parser.startParse(this.input,Fd(h,c),c):s.parser.startParse(""),s.overlay?s.overlay.map(f=>new ft(f.from-r.from,f.to-r.from)):null,!!s.bracketed,r.tree,c.length?c[0].from:r.from)),s.overlay?c.length&&(n={ranges:c,depth:0,prev:n}):l=!1}}else if(t&&(a=t.predicate(r))&&(a===!0&&(a=new ft(r.from,r.to)),a.from<a.to)){let h=t.ranges.length-1;h>=0&&t.ranges[h].to==a.from?t.ranges[h]={from:t.ranges[h].from,to:a.to}:t.ranges.push(a)}if(l&&r.firstChild())t&&t.depth++,n&&n.depth++;else for(;!r.nextSibling();){if(!r.parent())break e;if(t&&!--t.depth){let h=Ld(this.ranges,t.ranges);h.length&&(Rd(h),this.inner.splice(t.index,0,new Ed(t.parser,t.parser.startParse(this.input,Fd(t.mounts,h),h),t.ranges.map(c=>new ft(c.from-t.start,c.to-t.start)),t.bracketed,t.target,h[0].from))),t=t.prev}n&&!--n.depth&&(n=n.prev)}}}}function rC(i,e,t){for(let n of i){if(n.from>=t)break;if(n.to>e)return n.from<=e&&n.to>=t?2:1}return 0}function Bd(i,e,t,n,r,s){if(e<t){let o=i.buffer[e+1];n.push(i.slice(e,t,o)),r.push(o-s)}}function sC(i){let{node:e}=i,t=[],n=e.context.buffer;do t.push(i.index),i.parent();while(!i.tree);let r=i.tree,s=r.children.indexOf(n),o=r.children[s],l=o.buffer,a=[s];function h(c,f,u,d,p,m){let g=t[m],y=[],b=[];Bd(o,c,g,y,b,d);let k=l[g+1],O=l[g+2];a.push(y.length);let w=m?h(g+4,l[g+3],o.set.types[l[g]],k,O-k,m-1):e.toTree();return y.push(w),b.push(k-d),Bd(o,l[g+3],f,y,b,d),new ie(u,y,b,p)}r.children[s]=h(0,l.length,je.none,0,o.length,t.length-1);for(let c of a){let f=i.tree.children[c],u=i.tree.positions[c];i.yield(new Pe(f,u+i.from,c,i._tree))}}class Pd{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(Q.IncludeAnonymous|Q.IgnoreMounts|Q.ExcludeBuffers)}moveTo(e){let{cursor:t}=this,n=e-this.offset;for(;!this.done&&t.from<n;)if(!(t.to>=n&&t.enter(n,1,Q.IncludeAnonymous|Q.IgnoreOverlays|Q.ExcludeBuffers)))if(t.to<=n)t.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof ie)t=t.children[0];else break}return!1}}class oC{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let n=this.curFrag=e[0];this.curTo=(t=n.tree.prop(Ih))!==null&&t!==void 0?t:n.to,this.inner=new Pd(n.tree,-n.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Ih))!==null&&e!==void 0?e:t.to,this.inner=new Pd(t.tree,-t.offset)}}findMounts(e,t){var n;let r=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let s=this.inner.cursor.node;s;s=s.parent){let o=(n=s.tree)===null||n===void 0?void 0:n.prop(H.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let a=this.fragments[l];if(a.from>=s.to)break;a.tree==this.curFrag.tree&&r.push({frag:a,pos:s.from-a.offset,mount:o})}}}return r}}function Ld(i,e){let t=null,n=e;for(let r=1,s=0;r<i.length;r++){let o=i[r-1].to,l=i[r].from;for(;s<n.length;s++){let a=n[s];if(a.from>=l)break;a.to<=o||(t||(n=t=e.slice()),a.from<o?(t[s]=new ft(a.from,o),a.to>l&&t.splice(s+1,0,new ft(l,a.to))):a.to>l?t[s--]=new ft(l,a.to):t.splice(s--,1))}}return n}function lC(i,e,t,n){let r=0,s=0,o=!1,l=!1,a=-1e9,h=[];for(;;){let c=r==i.length?1e9:o?i[r].to:i[r].from,f=s==e.length?1e9:l?e[s].to:e[s].from;if(o!=l){let u=Math.max(a,t),d=Math.min(c,f,n);u<d&&h.push(new ft(u,d))}if(a=Math.min(c,f),a==1e9)break;c==a&&(o?(o=!1,r++):o=!0),f==a&&(l?(l=!1,s++):l=!0)}return h}function Fd(i,e){let t=[];for(let{pos:n,mount:r,frag:s}of i){let o=n+(r.overlay?r.overlay[0].from:0),l=o+r.tree.length,a=Math.max(s.from,o),h=Math.min(s.to,l);if(r.overlay){let c=r.overlay.map(u=>new ft(u.from+n,u.to+n)),f=lC(e,c,a,h);for(let u=0,d=a;;u++){let p=u==f.length,m=p?h:f[u].from;if(m>d&&t.push(new ln(d,m,r.tree,-o,s.from>=d||s.openStart,s.to<=m||s.openEnd)),p)break;d=f[u].to}}else t.push(new ln(a,h,r.tree,-o,s.from>=o||s.openStart,s.to<=l||s.openEnd))}return t}let Eh=[],k0=[];(()=>{let i="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<i.length;e++)(e%2?k0:Eh).push(t=t+i[e])})();function aC(i){if(i<768)return!1;for(let e=0,t=Eh.length;;){let n=e+t>>1;if(i<Eh[n])t=n;else if(i>=k0[n])e=n+1;else return!0;if(e==t)return!1}}function Vd(i){return i>=127462&&i<=127487}const zd=8205;function hC(i,e,t=!0,n=!0){return(t?x0:cC)(i,e,n)}function x0(i,e,t){if(e==i.length)return e;e&&w0(i.charCodeAt(e))&&S0(i.charCodeAt(e-1))&&e--;let n=Ba(i,e);for(e+=Hd(n);e<i.length;){let r=Ba(i,e);if(n==zd||r==zd||t&&aC(r))e+=Hd(r),n=r;else if(Vd(r)){let s=0,o=e-2;for(;o>=0&&Vd(Ba(i,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function cC(i,e,t){for(;e>1;){let n=x0(i,e-2,t);if(n<e)return n;e--}return 0}function Ba(i,e){let t=i.charCodeAt(e);if(!S0(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return w0(n)?(t-55296<<10)+(n-56320)+65536:t}function w0(i){return i>=56320&&i<57344}function S0(i){return i>=55296&&i<56320}function Hd(i){return i<65536?1:2}let U=class C0{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=lr(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),zt.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=lr(this,e,t);let n=[];return this.decompose(e,t,n,0),zt.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new es(this),s=new es(e);for(let o=t,l=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(l+=r.value.length,r.done||l>=n)return!0}}iter(e=1){return new es(this,e)}iterRange(e,t=this.length){return new v0(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new M0(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?C0.empty:e.length<=32?new ce(e):zt.from(ce.split(e,[]))}};class ce extends U{constructor(e,t=fC(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.text[s],l=r+o.length;if((t?n:l)>=e)return new uC(r,l,n,o);r=l+1,n++}}decompose(e,t,n,r){let s=e<=0&&t>=this.length?this:new ce(Wd(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){let o=n.pop(),l=_o(s.text,o.text.slice(),0,s.length);if(l.length<=32)n.push(new ce(l,o.length+s.length));else{let a=l.length>>1;n.push(new ce(l.slice(0,a)),new ce(l.slice(a)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof ce))return super.replace(e,t,n);[e,t]=lr(this,e,t);let r=_o(this.text,_o(n.text,Wd(this.text,0,e)),t),s=this.length+n.length-(t-e);return r.length<=32?new ce(r,s):zt.from(ce.split(r,[]),s)}sliceString(e,t=this.length,n=`
|
|
13
|
+
`){[e,t]=lr(this,e,t);let r="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let l=this.text[o],a=s+l.length;s>e&&o&&(r+=n),e<a&&t>s&&(r+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],r=-1;for(let s of e)n.push(s),r+=s.length+1,n.length==32&&(t.push(new ce(n,r)),n=[],r=-1);return r>-1&&t.push(new ce(n,r)),t}}class zt extends U{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let n of e)this.lines+=n.lines}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.children[s],l=r+o.length,a=n+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,n,r);r=l+1,n=a+1}}decompose(e,t,n,r){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let l=this.children[s],a=o+l.length;if(e<=a&&t>=o){let h=r&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?n.push(l):l.decompose(e-o,t-o,n,h)}o=a+1}}replace(e,t,n){if([e,t]=lr(this,e,t),n.lines<this.lines)for(let r=0,s=0;r<this.children.length;r++){let o=this.children[r],l=s+o.length;if(e>=s&&t<=l){let a=o.replace(e-s,t-s,n),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[r]=a,new zt(c,this.length-(t-e)+n.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n=`
|
|
14
|
+
`){[e,t]=lr(this,e,t);let r="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let l=this.children[s],a=o+l.length;o>e&&s&&(r+=n),e<a&&t>o&&(r+=l.sliceString(e-o,t-o,n)),o=a+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof zt))return 0;let n=0,[r,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;r+=t,s+=t){if(r==o||s==l)return n;let a=this.children[r],h=e.children[s];if(a!=h)return n+a.scanIdentical(h,t);n+=a.length+1}}static from(e,t=e.reduce((n,r)=>n+r.length+1,-1)){let n=0;for(let d of e)n+=d.lines;if(n<32){let d=[];for(let p of e)p.flatten(d);return new ce(d,t)}let r=Math.max(32,n>>5),s=r<<1,o=r>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>s&&d instanceof zt)for(let m of d.children)f(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof ce&&a&&(p=c[c.length-1])instanceof ce&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new ce(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>r&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:zt.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new zt(l,t)}}U.empty=new ce([""],0);function fC(i){let e=-1;for(let t of i)e+=t.length+1;return e}function _o(i,e,t=0,n=1e9){for(let r=0,s=0,o=!0;s<i.length&&r<=n;s++){let l=i[s],a=r+l.length;a>=t&&(a>n&&(l=l.slice(0,n-r)),r<t&&(l=l.slice(t-r)),o?(e[e.length-1]+=l,o=!1):e.push(l)),r=a+1}return e}function Wd(i,e,t){return _o(i,[""],e,t)}class es{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof ce?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],s=this.offsets[n],o=s>>1,l=r instanceof ce?r.text.length:r.children.length;if(o==(t>0?l:0)){if(n==0)return this.done=!0,this.value="",this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
15
|
+
`,this;e--}else if(r instanceof ce){let a=r.text[o+(t<0?-1:0)];if(this.offsets[n]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=r.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ce?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class v0{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new es(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class M0{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(U.prototype[Symbol.iterator]=function(){return this.iter()},es.prototype[Symbol.iterator]=v0.prototype[Symbol.iterator]=M0.prototype[Symbol.iterator]=function(){return this});class uC{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}}function lr(i,e,t){return e=Math.max(0,Math.min(i.length,e)),[e,Math.max(e,Math.min(i.length,t))]}function Re(i,e,t=!0,n=!0){return hC(i,e,t,n)}function dC(i){return i>=56320&&i<57344}function pC(i){return i>=55296&&i<56320}function it(i,e){let t=i.charCodeAt(e);if(!pC(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return dC(n)?(t-55296<<10)+(n-56320)+65536:t}function A0(i){return i<=65535?String.fromCharCode(i):(i-=65536,String.fromCharCode((i>>10)+55296,(i&1023)+56320))}function Zt(i){return i<65536?1:2}const Rh=/\r\n?|\n/;var Ae=(function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i})(Ae||(Ae={}));class Jt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(n,r,s),r+=s):r+=o,n+=s}}iterChangedRanges(e,t=!1){Bh(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];r<0?e.push(n,r):e.push(r,n)}return new Jt(e)}composeDesc(e){return this.empty?e:e.empty?this:O0(this,e)}mapDesc(e,t=!1){return e.empty?this:Ph(this,e,t)}mapPos(e,t=-1,n=Ae.Simple){let r=0,s=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=r+l;if(a<0){if(h>e)return s+(e-r);s+=l}else{if(n!=Ae.Simple&&h>=e&&(n==Ae.TrackDel&&r<e&&h>e||n==Ae.TrackBefore&&r<e||n==Ae.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==r||t<0?s:s+a;s+=a}r=h}if(e>r)throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);return s}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let s=this.sections[n++],o=this.sections[n++],l=r+s;if(o>=0&&r<=t&&l>=e)return r<e&&l>t?"cover":!0;r=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?" ":"")+n+(r>=0?":"+r:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Jt(e)}static create(e){return new Jt(e)}}class me extends Jt{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Bh(this,(t,n,r,s,o)=>e=e.replace(r,r+(n-t),o),!1),e}mapDesc(e,t=!1){return Ph(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let r=0,s=0;r<t.length;r+=2){let o=t[r],l=t[r+1];if(l>=0){t[r]=l,t[r+1]=o;let a=r>>1;for(;n.length<a;)n.push(U.empty);n.push(o?e.slice(s,s+o):U.empty)}s+=o}return new me(t,n)}compose(e){return this.empty?e:e.empty?this:O0(this,e,!0)}map(e,t=!1){return e.empty?this:Ph(this,e,t,!0)}iterChanges(e,t=!1){Bh(this,e,t)}get desc(){return Jt.create(this.sections)}filter(e){let t=[],n=[],r=[],s=new Cs(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,a-l);Ie(r,c,-1);let f=s.ins==-1?-1:s.off==0?s.ins:0;Ie(t,c,f),f>0&&Tn(n,t,s.text),s.forward(c),l+=c}let h=e[o++];for(;l<h;){if(s.done)break e;let c=Math.min(s.len,h-l);Ie(t,c,-1),Ie(r,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),l+=c}}return{changes:new me(t,n),filtered:Jt.create(r)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,n){let r=[],s=[],o=0,l=null;function a(c=!1){if(!c&&!r.length)return;o<t&&Ie(r,t-o,-1);let f=new me(r,s);l=l?l.compose(f.map(l)):f,r=[],s=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof me){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?U.of(d.split(n||Rh)):d:U.empty,m=p.length;if(f==u&&m==0)return;f<o&&a(),f>o&&Ie(r,f-o,-1),Ie(r,u-f,m),Tn(s,r,p),o=u}}return h(e),a(!l),l}static empty(e){return new me(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let r=0;r<e.length;r++){let s=e[r];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;n.length<r;)n.push(U.empty);n[r]=U.of(s.slice(1)),t.push(s[0],n[r].length)}}}return new me(t,n)}static createSet(e,t){return new me(e,t)}}function Ie(i,e,t,n=!1){if(e==0&&t<=0)return;let r=i.length-2;r>=0&&t<=0&&t==i[r+1]?i[r]+=e:r>=0&&e==0&&i[r]==0?i[r+1]+=t:n?(i[r]+=e,i[r+1]+=t):i.push(e,t)}function Tn(i,e,t){if(t.length==0)return;let n=e.length-2>>1;if(n<i.length)i[i.length-1]=i[i.length-1].append(t);else{for(;i.length<n;)i.push(U.empty);i.push(t)}}function Bh(i,e,t){let n=i.inserted;for(let r=0,s=0,o=0;o<i.sections.length;){let l=i.sections[o++],a=i.sections[o++];if(a<0)r+=l,s+=l;else{let h=r,c=s,f=U.empty;for(;h+=l,c+=a,a&&n&&(f=f.append(n[o-2>>1])),!(t||o==i.sections.length||i.sections[o+1]<0);)l=i.sections[o++],a=i.sections[o++];e(r,h,s,c,f),r=h,s=c}}}function Ph(i,e,t,n=!1){let r=[],s=n?[]:null,o=new Cs(i),l=new Cs(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);Ie(r,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(Ie(r,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(Ie(r,0,o.ins),s&&Tn(s,r,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;Ie(r,h,a<o.i?o.ins:0),s&&a<o.i&&Tn(s,r,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return s?me.createSet(r,s):Jt.create(r);throw new Error("Mismatched change set lengths")}}}function O0(i,e,t=!1){let n=[],r=t?[]:null,s=new Cs(i),o=new Cs(e);for(let l=!1;;){if(s.done&&o.done)return r?me.createSet(n,r):Jt.create(n);if(s.ins==0)Ie(n,s.len,0,l),s.next();else if(o.len==0&&!o.done)Ie(n,0,o.ins,l),r&&Tn(r,n,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(s.len2,o.len),h=n.length;if(s.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;Ie(n,a,c,l),r&&c&&Tn(r,n,o.text)}else o.ins==-1?(Ie(n,s.off?0:s.len,a,l),r&&Tn(r,n,s.textBit(a))):(Ie(n,s.off?0:s.len,o.off?0:o.ins,l),r&&!o.off&&Tn(r,n,o.text));l=(s.ins>a||o.ins>=0&&o.len>a)&&(l||n.length>h),s.forward2(a),o.forward(a)}}}}class Cs{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?U.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?U.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class vn{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,t=-1){let n,r;return this.empty?n=r=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),r=e.mapPos(this.to,-1)),n==this.from&&r==this.to?this:new vn(n,r,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return S.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return S.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return S.range(e.anchor,e.head)}static create(e,t,n,r){return new vn(e,t,n,r)}}class S{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:S.create(this.ranges.map(n=>n.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new S([this.main],0)}addRange(e,t=!0){return S.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let n=this.ranges.slice();return n[t]=e,S.create(n,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new S(e.ranges.map(t=>vn.fromJSON(t)),e.main)}static single(e,t=e){return new S([S.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,r=0;r<e.length;r++){let s=e[r];if(s.empty?s.from<=n:s.from<n)return S.normalized(e.slice(),t);n=s.to}return new S(e,t)}static cursor(e,t=0,n,r){return vn.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,s){let o=r==null?7:Math.min(6,r);return!s&&e!=t&&(s=t<e?1:-1),s&&(o|=s<0?8:16),t<e?vn.create(t,e,o|32,n):vn.create(e,t,o,n)}static undirectionalRange(e,t){return vn.create(e,t,64,void 0)}static normalized(e,t=0){let n=e[t];e.sort((r,s)=>r.from-s.from),t=e.indexOf(n);for(let r=1;r<e.length;r++){let s=e[r],o=e[r-1];if(s.empty?s.from<=o.to:s.from<o.to){let l=o.from,a=Math.max(s.to,o.to);r<=t&&t--,e.splice(--r,2,s.anchor>s.head?S.range(a,l):S.range(l,a))}}return new S(e,t)}}function T0(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Uc=0;class D{constructor(e,t,n,r,s){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=Uc++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new D(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:Gc),!!e.static,e.enables)}of(e){return new Uo([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Uo(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Uo(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}}function Gc(i,e){return i==e||i.length==e.length&&i.every((t,n)=>t===e[n])}class Uo{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=Uc++}dynamicSlot(e){var t;let n=this.value,r=this.facet.compareInput,s=this.id,o=e[s]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=n(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||Lh(f,c)){let d=n(f);if(l?!$d(d,f.values[o],r):!r(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[s];if(p!=null){let m=fl(u,p);if(this.dependencies.every(g=>g instanceof D?u.facet(g)===f.facet(g):g instanceof Ge?u.field(g,!1)==f.field(g,!1):!0)||(l?$d(d=n(f),m,r):r(d=n(f),m)))return f.values[o]=m,0}else d=n(f);return f.values[o]=d,1}}}get extension(){return this}}function $d(i,e,t){if(i.length!=e.length)return!1;for(let n=0;n<i.length;n++)if(!t(i[n],e[n]))return!1;return!0}function Lh(i,e){let t=!1;for(let n of e)ts(i,n)&1&&(t=!0);return t}function mC(i,e,t){let n=t.map(a=>i[a.id]),r=t.map(a=>a.type),s=n.filter(a=>!(a&1)),o=i[e.id]>>1;function l(a){let h=[];for(let c=0;c<n.length;c++){let f=fl(a,n[c]);if(r[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of n)ts(a,h);return a.values[o]=l(a),1},update(a,h){if(!Lh(a,s))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=Lh(a,n),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&Gc(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const bo=D.define({static:!0});class Ge{constructor(e,t,n,r,s){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=s,this.provides=void 0}static define(e){let t=new Ge(Uc++,e.create,e.update,e.compare||((n,r)=>n===r),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(bo).find(n=>n.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:n=>(n.values[t]=this.create(n),1),update:(n,r)=>{let s=n.values[t],o=this.updateF(s,r);return this.compareF(s,o)?0:(n.values[t]=o,1)},reconfigure:(n,r)=>{let s=n.facet(bo),o=r.facet(bo),l;return(l=s.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(n.values[t]=l.create(n),1):r.config.address[this.id]!=null?(n.values[t]=r.field(this),0):(n.values[t]=this.create(n),1)}}}init(e){return[this,bo.of({field:this,create:e})]}get extension(){return this}}const Xn={lowest:4,low:3,default:2,high:1,highest:0};function Nr(i){return e=>new N0(e,i)}const vi={highest:Nr(Xn.highest),high:Nr(Xn.high),default:Nr(Xn.default),low:Nr(Xn.low),lowest:Nr(Xn.lowest)};class N0{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}}class $l{of(e){return new Fh(this,e)}reconfigure(e){return $l.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Fh{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}}class cl{constructor(e,t,n,r,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,n){let r=[],s=Object.create(null),o=new Map;for(let u of gC(e,t,o))u instanceof Ge?r.push(u):(s[u.facet.id]||(s[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of r)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=n?.config.facets;for(let u in s){let d=s[u],p=d[0].facet,m=c&&c[u]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,Gc(m,d))a.push(n.facet(p));else{let g=p.combine(d.map(y=>y.value));a.push(n&&p.compare(g,n.facet(p))?n.facet(p):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(y=>g.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(g=>mC(g,p,d))}}let f=h.map(u=>u(l));return new cl(e,o,f,l,a,s)}}function gC(i,e,t){let n=[[],[],[],[],[]],r=new Map;function s(o,l){let a=r.get(o);if(a!=null){if(a<=l)return;let h=n[a].indexOf(o);h>-1&&n[a].splice(h,1),o instanceof Fh&&t.delete(o.compartment)}if(r.set(o,l),Array.isArray(o))for(let h of o)s(h,l);else if(o instanceof Fh){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),s(h,l)}else if(o instanceof N0)s(o.inner,o.prec);else if(o instanceof Ge)n[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof Uo)n[l].push(o),o.facet.extensions&&s(o.facet.extensions,Xn.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}).`);if(h==o)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,l)}}return s(i,Xn.default),n.reduce((o,l)=>o.concat(l))}function ts(i,e){if(e&1)return 2;let t=e>>1,n=i.status[t];if(n==4)throw new Error("Cyclic dependency between fields and/or facets");if(n&2)return n;i.status[t]=4;let r=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|r}function fl(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}const D0=D.define(),Vh=D.define({combine:i=>i.some(e=>e),static:!0}),I0=D.define({combine:i=>i.length?i[0]:void 0,static:!0}),E0=D.define(),R0=D.define(),B0=D.define(),P0=D.define({combine:i=>i.length?i[0]:!1});class mn{constructor(e,t){this.type=e,this.value=t}static define(){return new yC}}class yC{of(e){return new mn(this,e)}}class bC{constructor(e){this.map=e}of(e){return new z(this,e)}}class z{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new z(this.type,t)}is(e){return this.type==e}static define(e={}){return new bC(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let s=r.map(t);s&&n.push(s)}return n}}z.reconfigure=z.define();z.appendConfig=z.define();class pe{constructor(e,t,n,r,s,o){this.startState=e,this.changes=t,this.selection=n,this.effects=r,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,n&&T0(n,t.newLength),s.some(l=>l.type==pe.time)||(this.annotations=s.concat(pe.time.of(Date.now())))}static create(e,t,n,r,s,o){return new pe(e,t,n,r,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(pe.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}pe.time=mn.define();pe.userEvent=mn.define();pe.addToHistory=mn.define();pe.remote=mn.define();function kC(i,e){let t=[];for(let n=0,r=0;;){let s,o;if(n<i.length&&(r==e.length||e[r]>=i[n]))s=i[n++],o=i[n++];else if(r<e.length)s=e[r++],o=e[r++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function L0(i,e,t){var n;let r,s,o;return t?(r=e.changes,s=me.empty(e.changes.length),o=i.changes.compose(e.changes)):(r=e.changes.map(i.changes),s=i.changes.mapDesc(e.changes,!0),o=i.changes.compose(r)),{changes:o,selection:e.selection?e.selection.map(s):(n=i.selection)===null||n===void 0?void 0:n.map(r),effects:z.mapEffects(i.effects,r).concat(z.mapEffects(e.effects,s)),annotations:i.annotations.length?i.annotations.concat(e.annotations):e.annotations,scrollIntoView:i.scrollIntoView||e.scrollIntoView}}function zh(i,e,t){let n=e.selection,r=Ki(e.annotations);return e.userEvent&&(r=r.concat(pe.userEvent.of(e.userEvent))),{changes:e.changes instanceof me?e.changes:me.of(e.changes||[],t,i.facet(I0)),selection:n&&(n instanceof S?n:S.single(n.anchor,n.head)),effects:Ki(e.effects),annotations:r,scrollIntoView:!!e.scrollIntoView}}function F0(i,e,t){let n=zh(i,e.length?e[0]:{},i.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;n=L0(n,zh(i,e[s],o?n.changes.newLength:i.doc.length),o)}let r=pe.create(i,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return wC(t?xC(r):r)}function xC(i){let e=i.startState,t=!0;for(let r of e.facet(E0)){let s=r(i);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:kC(t,s))}if(t!==!0){let r,s;if(t===!1)s=i.changes.invertedDesc,r=me.empty(e.doc.length);else{let o=i.changes.filter(t);r=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}i=pe.create(e,r,i.selection&&i.selection.map(s),z.mapEffects(i.effects,s),i.annotations,i.scrollIntoView)}let n=e.facet(R0);for(let r=n.length-1;r>=0;r--){let s=n[r](i);s instanceof pe?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof pe?i=s[0]:i=F0(e,Ki(s),!1)}return i}function wC(i){let e=i.startState,t=e.facet(B0),n=i;for(let r=t.length-1;r>=0;r--){let s=t[r](i);s&&Object.keys(s).length&&(n=L0(n,zh(e,s,i.changes.newLength),!0))}return n==i?i:pe.create(e,i.changes,i.selection,n.effects,n.annotations,n.scrollIntoView)}const SC=[];function Ki(i){return i==null?SC:Array.isArray(i)?i:[i]}var ut=(function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i})(ut||(ut={}));const CC=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Hh;try{Hh=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function vC(i){if(Hh)return Hh.test(i);for(let e=0;e<i.length;e++){let t=i[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||CC.test(t)))return!0}return!1}function MC(i){return e=>{if(!/\S/.test(e))return ut.Space;if(vC(e))return ut.Word;for(let t=0;t<i.length;t++)if(e.indexOf(i[t])>-1)return ut.Word;return ut.Other}}class Y{constructor(e,t,n,r,s,o){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)ts(this,l<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw new RangeError("Field is not present in this state");return}return ts(this,n),fl(this,n)}update(...e){return F0(this,e,!0)}applyTransaction(e){let t=this.config,{base:n,compartments:r}=t;for(let l of e.effects)l.is($l.reconfigure)?(t&&(r=new Map,t.compartments.forEach((a,h)=>r.set(h,a)),t=null),r.set(l.value.compartment,l.value.extension)):l.is(z.reconfigure)?(t=null,n=l.value):l.is(z.appendConfig)&&(t=null,n=Ki(n).concat(l.value));let s;t?s=e.startState.values.slice():(t=cl.resolve(n,r,this),s=new Y(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Vh)?e.newSelection:e.newSelection.asSingle();new Y(t,e.newDoc,o,s,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:S.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),s=[n.range],o=Ki(n.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(r);for(let u=0;u<l;u++)s[u]=s[u].map(c);let f=r.mapDesc(h,!0);s.push(a.range.map(f)),r=r.compose(c),o=z.mapEffects(o,c).concat(z.mapEffects(Ki(a.effects),f))}return{changes:r,selection:S.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof me?e:me.of(e,this.doc.length,this.facet(Y.lineSeparator))}toText(e){return U.of(e.split(this.facet(Y.lineSeparator)||Rh))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(ts(this,t),fl(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof Ge&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(e,t={},n){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let r=[];if(n){for(let s in n)if(Object.prototype.hasOwnProperty.call(e,s)){let o=n[s],l=e[s];r.push(o.init(a=>o.spec.fromJSON(l,a)))}}return Y.create({doc:e.doc,selection:S.fromJSON(e.selection),extensions:t.extensions?r.concat([t.extensions]):r})}static create(e={}){let t=cl.resolve(e.extensions||[],new Map),n=e.doc instanceof U?e.doc:U.of((e.doc||"").split(t.staticFacet(Y.lineSeparator)||Rh)),r=e.selection?e.selection instanceof S?e.selection:S.single(e.selection.anchor,e.selection.head):S.single(0);return T0(r,n.length),t.staticFacet(Vh)||(r=r.asSingle()),new Y(t,n,r,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(Y.tabSize)}get lineBreak(){return this.facet(Y.lineSeparator)||`
|
|
16
|
+
`}get readOnly(){return this.facet(P0)}phrase(e,...t){for(let n of this.facet(Y.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,r)=>{if(r=="$")return"$";let s=+(r||1);return!s||s>t.length?n:t[s-1]})),e}languageDataAt(e,t,n=-1){let r=[];for(let s of this.facet(D0))for(let o of s(this,t,n))Object.prototype.hasOwnProperty.call(o,e)&&r.push(o[e]);return r}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return MC(t.length?t[0]:"")}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-n,l=e-n;for(;o>0;){let a=Re(t,o,!1);if(s(t.slice(a,o))!=ut.Word)break;o=a}for(;l<r;){let a=Re(t,l);if(s(t.slice(l,a))!=ut.Word)break;l=a}return o==l?null:S.range(o+n,l+n)}}Y.allowMultipleSelections=Vh;Y.tabSize=D.define({combine:i=>i.length?i[0]:4});Y.lineSeparator=I0;Y.readOnly=P0;Y.phrases=D.define({compare(i,e){let t=Object.keys(i),n=Object.keys(e);return t.length==n.length&&t.every(r=>i[r]==e[r])}});Y.languageData=D0;Y.changeFilter=E0;Y.transactionFilter=R0;Y.transactionExtender=B0;$l.reconfigure=z.define();function Mi(i,e,t={}){let n={};for(let r of i)for(let s of Object.keys(r)){let o=r[s],l=n[s];if(l===void 0)n[s]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,s))n[s]=t[s](l,o);else throw new Error("Config merge conflict for field "+s)}for(let r in e)n[r]===void 0&&(n[r]=e[r]);return n}class zn{eq(e){return this==e}range(e,t=e){return vs.create(e,t,this)}}zn.prototype.startSide=zn.prototype.endSide=0;zn.prototype.point=!1;zn.prototype.mapMode=Ae.TrackDel;function Yc(i,e){return i==e||i.constructor==e.constructor&&i.eq(e)}class vs{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new vs(e,t,n)}}function Wh(i,e){return i.from-e.from||i.value.startSide-e.value.startSide}class Xc{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return Pi(this.to)}findIndex(e,t,n,r=0){let s=n?this.to:this.from;for(let o=r,l=s.length;;){if(o==l)return o;let a=o+l>>1,h=s[a]-e||(n?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,n,r){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(n,1e9,!1,s);s<o;s++)if(r(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t,n,r,s){let o=[],l=[],a=[],h=-1,c=-1;e:for(let f=0;f<this.value.length;f++){let u=this.value[f],d=this.from[f]+e,p=this.to[f]+e,m,g;if(d==p){let y=t.mapPos(d,u.startSide,u.mapMode);if(y==null||(m=g=y,u.startSide!=u.endSide&&(g=t.mapPos(d,u.endSide),g<m)))continue}else if(m=t.mapPos(d,u.startSide),g=t.mapPos(p,u.endSide),m>g||m==g&&u.startSide>0&&u.endSide<=0)continue;if(!((g-m||u.endSide-u.startSide)<0))if(h<0&&(h=m),u.point&&(c=Math.max(c,g-m)),(m-n||u.startSide-r)>=0)o.push(u),l.push(m-h),a.push(g-h),n=g,r=u.endSide;else{if(m==g)for(let y=o.length;y>0;y--){if((m-(a[y-1]+h)||u.startSide-o[y-1].endSide)>=0){o.splice(y,0,u),l.splice(y,0,m-h),a.splice(y,0,g-h);continue e}if((m-(l[y-1]+h)||u.endSide-o[y-1].startSide)>0)break}s(m,g,u)}}return{mapped:o.length?new Xc(l,a,o,c):null,pos:h}}}class ${constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(e,t,n,r){return new $(e,t,n,r)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:n=!1,filterFrom:r=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(n&&(t=t.slice().sort(Wh)),this.isEmpty)return t.length?$.of(t):this;let l=new V0(this,null,-1).goto(0),a=0,h=[],c=new Bn;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];c.addInner(f.from,f.to,f.value,!1)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||r>this.chunkEnd(l.chunkIndex)||s<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||r>l.to||s<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value,!1)||h.push(vs.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?$.empty:this.nextLayer.update({add:h,filter:o,filterFrom:r,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],n=[],r=-1,s,o=(a,h,c)=>{s||(s=new Bn),s.addRange(a,h,c,!1)};for(let a=0;a<this.chunk.length;a++){let h=this.chunkPos[a],c=this.chunk[a],f=e.touchesRange(h,h+c.length);if(f===!1)r=Math.max(r,c.maxPoint),t.push(c),n.push(e.mapPos(h));else if(f===!0){let[u,d]=t.length?[Pi(n)+Pi(t).length,Pi(Pi(t).value).endSide]:[-1,-1],{mapped:p,pos:m}=c.map(h,e,u,d,o);p&&(r=Math.max(r,p.maxPoint),t.push(p),n.push(m))}}let l=this.nextLayer.map(e);return s&&(l=s.finishInner(l)),t.length==0?l:new $(n,t,l||$.empty,r)}between(e,t,n){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let s=this.chunkPos[r],o=this.chunk[r];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return Ms.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ms.from(e).goto(t)}static compare(e,t,n,r,s=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),a=Kd(o,l,n),h=new Dr(o,a,s),c=new Dr(l,a,s);n.iterGaps((f,u,d)=>qd(h,f,c,u,d,r)),n.empty&&n.length==0&&qd(h,0,c,0,0,r)}static eq(e,t,n=0,r){r==null&&(r=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=Kd(s,o),a=new Dr(s,l,0).goto(n),h=new Dr(o,l,0).goto(n);for(;;){if(a.to!=h.to||!$h(a.active,h.active)||a.point&&(!h.point||!Yc(a.point,h.point)))return!1;if(a.to>r)return!0;a.next(),h.next()}}static spans(e,t,n,r,s=-1){let o=new Dr(e,null,s).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,n);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,a);r.point(l,h,o.point,c,f,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(r.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>n)return a+(o.point&&o.to>n?1:0);l=o.to,o.next()}}static of(e,t=!1){let n=new Bn;for(let r of e instanceof vs?[e]:t?AC(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(e){if(!e.length)return $.empty;let t=Pi(e);for(let n=e.length-2;n>=0;n--)for(let r=e[n];r!=$.empty;r=r.nextLayer)t=new $(r.chunkPos,r.chunk,t,Math.max(r.maxPoint,t.maxPoint));return t}}$.empty=new $([],[],null,-1);function Pi(i){return i[i.length-1]}function AC(i){if(i.length>1)for(let e=i[0],t=1;t<i.length;t++){let n=i[t];if(Wh(e,n)>0)return i.slice().sort(Wh);e=n}return i}$.empty.nextLayer=$.empty;class Bn{finishChunk(e){this.chunks.push(new Xc(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,n){this.addRange(e,t,n,!0)}addRange(e,t,n,r){this.addInner(e,t,n,r)||(this.nextLayer||(this.nextLayer=new Bn)).addRange(e,t,n,r)}addInner(e,t,n,r){let s=e-this.lastTo||n.startSide-this.last.endSide;if(r&&s<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner($.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=$.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Kd(i,e,t){let n=new Map;for(let s of i)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&n.set(s.chunk[o],s.chunkPos[o]);let r=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let l=n.get(s.chunk[o]);l!=null&&(t?t.mapPos(l):l)==s.chunkPos[o]&&!t?.touchesRange(l,l+s.chunk[o].length)&&r.add(s.chunk[o])}return r}class V0{constructor(e,t,n,r=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex<this.layer.chunk.length;){let r=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(r)||this.layer.chunkEnd(this.chunkIndex)<e||r.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],n=e+t.from[this.rangeIndex];if(this.from=n,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class Ms{constructor(e){this.heap=e}static from(e,t=null,n=-1){let r=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=n&&r.push(new V0(o,t,n,s));return r.length==1?r[0]:new Ms(r)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let n=this.heap.length>>1;n>=0;n--)Pa(this.heap,n);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let n=this.heap.length>>1;n>=0;n--)Pa(this.heap,n);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Pa(this.heap,0)}}}function Pa(i,e){for(let t=i[e];;){let n=(e<<1)+1;if(n>=i.length)break;let r=i[n];if(n+1<i.length&&r.compare(i[n+1])>=0&&(r=i[n+1],n++),t.compare(r)<0)break;i[n]=t,i[e]=r,e=n}}class Dr{constructor(e,t,n){this.minPoint=n,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ms.from(e,t,n)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ko(this.active,e),ko(this.activeTo,e),ko(this.activeRank,e),this.minActive=jd(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||r-this.activeTo[t])>0;)t++;xo(this.active,t,n),xo(this.activeTo,t,r),xo(this.activeRank,t,s),e&&xo(e,t,this.cursor.from),this.minActive=jd(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&ko(n,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(n){this.openStart=0;for(let r=n.length-1;r>=0&&n[r]<e;r--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}}function qd(i,e,t,n,r,s){i.goto(e),t.goto(n);let o=n+r,l=n,a=n-e,h=!!s.boundChange;for(let c=!1;;){let f=i.to+a-t.to,u=f||i.endSide-t.endSide,d=u<0?i.to+a:t.to,p=Math.min(d,o);if(i.point||t.point?(i.point&&t.point&&Yc(i.point,t.point)&&$h(i.activeForPoint(i.to),t.activeForPoint(t.to))||s.comparePoint(l,p,i.point,t.point),c=!1):(c&&(s.boundChange(l),c=!1),p>l&&!$h(i.active,t.active)&&s.compareRange(l,p,i.active,t.active),h&&p<o&&(f||i.openEnd(d)!=t.openEnd(d))&&(c=!0)),d>o)break;l=d,u<=0&&i.next(),u>=0&&t.next()}}function $h(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(i[t]!=e[t]&&!Yc(i[t],e[t]))return!1;return!0}function ko(i,e){for(let t=e,n=i.length-1;t<n;t++)i[t]=i[t+1];i.pop()}function xo(i,e,t){for(let n=i.length-1;n>=e;n--)i[n+1]=i[n];i[e]=t}function jd(i,e){let t=-1,n=1e9;for(let r=0;r<e.length;r++)(e[r]-n||i[r].endSide-i[t].endSide)<0&&(t=r,n=e[r]);return t}function xr(i,e,t=i.length){let n=0;for(let r=0;r<t&&r<i.length;)i.charCodeAt(r)==9?(n+=e-n%e,r++):(n++,r=Re(i,r));return n}function Kh(i,e,t,n){for(let r=0,s=0;;){if(s>=e)return r;if(r==i.length)break;s+=i.charCodeAt(r)==9?t-s%t:1,r=Re(i,r)}return n===!0?-1:i.length}const qh="ͼ",Jd=typeof Symbol>"u"?"__"+qh:Symbol.for(qh),jh=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),_d=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Hn{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))s(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");s(r(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||u)&&a.push((n&&!f&&!h?o.map(n):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(r(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
|
17
|
+
`)}static newName(){let e=_d[Jd]||1;return _d[Jd]=e+1,qh+e.toString(36)}static mount(e,t,n){let r=e[jh],s=n&&n.nonce;r?s&&r.setNonce(s):r=new OC(e,s),r.mount(Array.isArray(t)?t:[t],e)}}let Ud=new Map;class OC{constructor(e,t){let n=e.ownerDocument||e,r=n.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let s=Ud.get(n);if(s)return e[jh]=s;this.sheet=new r.CSSStyleSheet,Ud.set(n,this)}else this.styleTag=n.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[jh]=this}mount(e,t){let n=this.sheet,r=0,s=0,o=!1;for(let l=0;l<e.length;l++){let a=e[l],h=this.modules.indexOf(a);if(h<s&&h>-1&&(this.modules.splice(h,1),o=!0,s--,h=-1),h==-1){if(this.modules.splice(s++,0,a),o=!0,n)for(let c=0;c<a.rules.length;c++)n.insertRule(a.rules[c],r++)}else{for(;s<h;)r+=this.modules[s++].rules.length;r+=a.rules.length,s++}}if(n)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{if(o){let a="";for(let h=0;h<this.modules.length;h++)a+=this.modules[h].getRules()+`
|
|
18
|
+
`;this.styleTag.textContent=a}let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}function Ii(){var i=arguments[0];typeof i=="string"&&(i=document.createElement(i));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=t[n];typeof r=="string"?i.setAttribute(n,r):r!=null&&(i[n]=r)}e++}for(;e<arguments.length;e++)z0(i,arguments[e]);return i}function z0(i,e){if(typeof e=="string")i.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)i.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)z0(i,e[t]);else throw new RangeError("Unsupported child node: "+e)}let He=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Jh=typeof document<"u"?document:{documentElement:{style:{}}};const _h=/Edge\/(\d+)/.exec(He.userAgent),H0=/MSIE \d/.test(He.userAgent),Uh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(He.userAgent),Kl=!!(H0||Uh||_h),Gd=!Kl&&/gecko\/(\d+)/i.test(He.userAgent),La=!Kl&&/Chrome\/(\d+)/.exec(He.userAgent),Yd="webkitFontSmoothing"in Jh.documentElement.style,Gh=!Kl&&/Apple Computer/.test(He.vendor),Xd=Gh&&(/Mobile\/\w+/.test(He.userAgent)||He.maxTouchPoints>2);var N={mac:Xd||/Mac/.test(He.platform),windows:/Win/.test(He.platform),linux:/Linux|X11/.test(He.platform),ie:Kl,ie_version:H0?Jh.documentMode||6:Uh?+Uh[1]:_h?+_h[1]:0,gecko:Gd,gecko_version:Gd?+(/Firefox\/(\d+)/.exec(He.userAgent)||[0,0])[1]:0,chrome:!!La,chrome_version:La?+La[1]:0,ios:Xd,android:/Android\b/.test(He.userAgent),webkit:Yd,webkit_version:Yd?+(/\bAppleWebKit\/(\d+)/.exec(He.userAgent)||[0,0])[1]:0,safari:Gh,safari_version:Gh?+(/\bVersion\/(\d+(\.\d+)?)/.exec(He.userAgent)||[0,0])[1]:0,tabSize:Jh.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Qc(i,e){for(let t in i)t=="class"&&e.class?e.class+=" "+i.class:t=="style"&&e.style?e.style+=";"+i.style:e[t]=i[t];return e}const ul=Object.create(null);function Zc(i,e,t){if(i==e)return!0;i||(i=ul),e||(e=ul);let n=Object.keys(i),r=Object.keys(e);if(n.length-0!=r.length-0)return!1;for(let s of n)if(s!=t&&(r.indexOf(s)==-1||i[s]!==e[s]))return!1;return!0}function TC(i,e){for(let t=i.attributes.length-1;t>=0;t--){let n=i.attributes[t].name;e[n]==null&&i.removeAttribute(n)}for(let t in e){let n=e[t];t=="style"?i.style.cssText=n:i.getAttribute(t)!=n&&i.setAttribute(t,n)}}function Qd(i,e,t){let n=!1;if(e)for(let r in e)t&&r in t||(n=!0,r=="style"?i.style.cssText="":i.removeAttribute(r));if(t)for(let r in t)e&&e[r]==t[r]||(n=!0,r=="style"?i.style.cssText=t[r]:i.setAttribute(r,t[r]));return n}function NC(i){let e=Object.create(null);for(let t=0;t<i.attributes.length;t++){let n=i.attributes[t];e[n.name]=n.value}return e}class gn{eq(e){return!1}updateDOM(e,t,n){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var Te=(function(i){return i[i.Text=0]="Text",i[i.WidgetBefore=1]="WidgetBefore",i[i.WidgetAfter=2]="WidgetAfter",i[i.WidgetRange=3]="WidgetRange",i})(Te||(Te={}));class J extends zn{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new Zs(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ki(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:s,end:o}=W0(e,t);n=(s?t?-3e8:-1:5e8)-1,r=(o?t?2e8:1:-6e8)+1}return new ki(e,n,r,t,e.widget||null,!0)}static line(e){return new eo(e)}static set(e,t=!1){return $.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}J.none=$.empty;class Zs extends J{constructor(e){let{start:t,end:n}=W0(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Qc(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||ul}eq(e){return this==e||e instanceof Zs&&this.tagName==e.tagName&&Zc(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Zs.prototype.point=!1;class eo extends J{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof eo&&this.spec.class==e.spec.class&&Zc(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}eo.prototype.mapMode=Ae.TrackBefore;eo.prototype.point=!0;class ki extends J{constructor(e,t,n,r,s,o){super(t,n,s,e),this.block=r,this.isReplace=o,this.mapMode=r?t<=0?Ae.TrackBefore:Ae.TrackAfter:Ae.TrackDel}get type(){return this.startSide!=this.endSide?Te.WidgetRange:this.startSide<=0?Te.WidgetBefore:Te.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof ki&&DC(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}ki.prototype.point=!0;function W0(i,e=!1){let{inclusiveStart:t,inclusiveEnd:n}=i;return t==null&&(t=i.inclusive),n==null&&(n=i.inclusive),{start:t??e,end:n??e}}function DC(i,e){return i==e||!!(i&&e&&i.compare(e))}function qi(i,e,t,n=0){let r=t.length-1;r>=0&&t[r]+n>=i?t[r]=Math.max(t[r],e):t.push(i,e)}class As extends zn{constructor(e,t,n){super(),this.tagName=e,this.attributes=t,this.rank=n}eq(e){return e==this||e instanceof As&&this.tagName==e.tagName&&Zc(this.attributes,e.attributes)}static create(e){return new As(e.tagName,e.attributes||ul,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return $.of(e,t)}}As.prototype.startSide=As.prototype.endSide=-1;const xe=i=>i.nodeType==1,ar=i=>i.nodeType==3;function Os(i){let e;return i.nodeType==11?e=i.getSelection?i:i.ownerDocument:e=i,e.getSelection()}function Yh(i,e){return e?i==e||i.contains(e.nodeType!=1?e.parentNode:e):!1}function ns(i,e){if(!e.anchorNode)return!1;try{return Yh(i,e.anchorNode)}catch{return!1}}function Go(i){return ar(i)?Ts(i,0,i.nodeValue.length).getClientRects():xe(i)?i.getClientRects():[]}function is(i,e,t,n){return t?Zd(i,e,t,n,-1)||Zd(i,e,t,n,1):!1}function Wn(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e}function dl(i){return xe(i)&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(i.nodeName)}function Zd(i,e,t,n,r){for(;;){if(i==t&&e==n)return!0;if(e==(r<0?0:cn(i))){if(i.nodeName=="DIV")return!1;let s=i.parentNode;if(!s||!xe(s))return!1;e=Wn(i)+(r<0?0:1),i=s}else if(xe(i)){if(i=i.childNodes[e+(r<0?-1:0)],xe(i)&&(i.nodeName=="IMG"||i.nodeName=="BR"||i.contentEditable=="false"))return!1;e=r<0?cn(i):0}else return!1}}function cn(i){return ar(i)?i.nodeValue.length:i.childNodes.length}function pl(i,e){let{left:t,right:n}=i;if(t==n)return i;let r=e?t:n;return{left:r,right:r,top:i.top,bottom:i.bottom}}function IC(i){let e=i.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function $0(i,e){let t=e.width/i.offsetWidth,n=e.height/i.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-i.offsetWidth)<1)&&(t=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-i.offsetHeight)<1)&&(n=1),{scaleX:t,scaleY:n}}function EC(i,e,t,n,r,s,o,l){let a=i.ownerDocument,h=a.defaultView||window;for(let c=i,f=!1;c&&!f;)if(xe(c)){let u,d=c==a.body,p=1,m=1,g=!0,y=!0;if(d)u=IC(h);else{let O=getComputedStyle(c);if(/^(fixed|sticky)$/.test(O.position)&&(f=!0),(c.scrollHeight<=c.clientHeight||!/auto|scroll/.test(O.overflowY))&&(y=!1),(c.scrollWidth<=c.clientWidth||!/auto|scroll/.test(O.overflowX))&&(g=!1),!g&&!y){c=c.assignedSlot||c.parentNode;continue}let w=c.getBoundingClientRect();({scaleX:p,scaleY:m}=$0(c,w)),u={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*m}}let b=0,k=0;if(y)if(r=="nearest")e.top<u.top+o?(k=e.top-(u.top+o),t>0&&e.bottom>u.bottom+k&&(k=e.bottom-u.bottom+o)):e.bottom>u.bottom-o&&(k=e.bottom-u.bottom+o,t<0&&e.top-k<u.top&&(k=e.top-(u.top+o)));else{let O=e.bottom-e.top,w=u.bottom-u.top;k=(r=="center"&&O<=w?e.top+O/2-w/2:r=="start"||r=="center"&&t<0?e.top-o:e.bottom-w+o)-u.top}if(g&&(n=="nearest"?e.left<u.left+s?(b=e.left-(u.left+s),t>0&&e.right>u.right+b&&(b=e.right-u.right+s)):e.right>u.right-s&&(b=e.right-u.right+s,t<0&&e.left<u.left+b&&(b=e.left-(u.left+s))):b=(n=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:n=="start"==l?e.left-s:e.right-(u.right-u.left)+s)-u.left),b||k)if(d)h.scrollBy(b,k);else{let O=0,w=0;if(k){let M=c.scrollTop;c.scrollTop+=k/m,w=(c.scrollTop-M)*m}if(b){let M=c.scrollLeft;c.scrollLeft+=b/p,O=(c.scrollLeft-M)*p}e={left:e.left-O,top:e.top-w,right:e.right-O,bottom:e.bottom-w},O&&Math.abs(O-b)<1&&(n="nearest"),w&&Math.abs(w-k)<1&&(r="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function K0(i,e=!0){let t=i.ownerDocument,n=null,r=null;for(let s=i.parentNode;s&&!(s==t.body||(!e||n)&&r);)if(xe(s))!r&&s.scrollHeight>s.clientHeight&&/scroll|auto/.test(getComputedStyle(s).overflowY)&&(r=s),e&&!n&&s.scrollWidth>s.clientWidth&&/scroll|auto/.test(getComputedStyle(s).overflowX)&&(n=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:n,y:r}}class RC{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?cn(t):0),n,Math.min(e.focusOffset,n?cn(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}}function q0(i){let e=[];for(let t=i;t;t=t.nodeType==11?t.host:t.parentNode)xe(t)&&e.push({node:t,left:t.scrollLeft,top:t.scrollTop});return e}function j0(i,e=!0){for(let{node:t,left:n,top:r}of i)e&&t.scrollTop!=r&&(t.scrollTop=r),t.scrollLeft!=n&&(t.scrollLeft=n)}let Yn=null;N.safari&&N.safari_version>=26&&(Yn=!1);function J0(i){if(i.setActive)return i.setActive();if(Yn)return i.focus(Yn);let e=q0(i);i.focus(Yn==null?{get preventScroll(){return Yn={preventScroll:!0},!0}}:void 0),Yn||(Yn=!1,j0(e))}let ep;function Ts(i,e,t=e){let n=ep||(ep=document.createRange());return n.setEnd(i,t),n.setStart(i,e),n}function ji(i,e,t,n){let r={key:e,code:e,keyCode:t,which:t,cancelable:!0};n&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=n);let s=new KeyboardEvent("keydown",r);s.synthetic=!0,i.dispatchEvent(s);let o=new KeyboardEvent("keyup",r);return o.synthetic=!0,i.dispatchEvent(o),s.defaultPrevented||o.defaultPrevented}function BC(i){for(;i;){if(i&&(i.nodeType==9||i.nodeType==11&&i.host))return i;i=i.assignedSlot||i.parentNode}return null}function PC(i,e){let t=e.focusNode,n=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=n)return!1;for(n=Math.min(n,cn(t));;)if(n){if(!xe(t))return!1;let r=t.childNodes[n-1];r.contentEditable=="false"?n--:(t=r,n=cn(t))}else{if(t==i)return!0;n=Wn(t),t=t.parentNode}}function _0(i){return i instanceof Window?i.pageYOffset>Math.max(0,i.document.documentElement.scrollHeight-i.innerHeight-4):i.scrollTop>Math.max(1,i.scrollHeight-i.clientHeight-4)}function U0(i,e){for(let t=i,n=e;;){if(ar(t)&&n>0)return{node:t,offset:n};if(xe(t)&&n>0){if(t.contentEditable=="false")return null;t=t.childNodes[n-1],n=cn(t)}else if(t.parentNode&&!dl(t))n=Wn(t),t=t.parentNode;else return null}}function G0(i,e){for(let t=i,n=e;;){if(ar(t)&&n<t.nodeValue.length)return{node:t,offset:n};if(xe(t)&&n<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[n],n=0}else if(t.parentNode&&!dl(t))n=Wn(t)+1,t=t.parentNode;else return null}}class vt{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(e,t){return new vt(e.parentNode,Wn(e),t)}static after(e,t){return new vt(e.parentNode,Wn(e)+1,t)}}var Z=(function(i){return i[i.LTR=0]="LTR",i[i.RTL=1]="RTL",i})(Z||(Z={}));const hr=Z.LTR,ef=Z.RTL;function Y0(i){let e=[];for(let t=0;t<i.length;t++)e.push(1<<+i[t]);return e}const LC=Y0("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),FC=Y0("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Xh=Object.create(null),Bt=[];for(let i of["()","[]","{}"]){let e=i.charCodeAt(0),t=i.charCodeAt(1);Xh[e]=t,Xh[t]=-e}function X0(i){return i<=247?LC[i]:1424<=i&&i<=1524?2:1536<=i&&i<=1785?FC[i-1536]:1774<=i&&i<=2220?4:8192<=i&&i<=8204?256:64336<=i&&i<=65023?4:1}const VC=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class $t{get dir(){return this.level%2?ef:hr}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let s=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==n)return o;(s<0||(r!=0?r<0?l.from<t:l.to>t:e[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}}function Q0(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++){let n=i[t],r=e[t];if(n.from!=r.from||n.to!=r.to||n.direction!=r.direction||!Q0(n.inner,r.inner))return!1}return!0}const ne=[];function zC(i,e,t,n,r){for(let s=0;s<=n.length;s++){let o=s?n[s-1].to:e,l=s<n.length?n[s].from:t,a=s?256:r;for(let h=o,c=a,f=a;h<l;h++){let u=X0(i.charCodeAt(h));u==512?u=c:u==8&&f==4&&(u=16),ne[h]=u==4?2:u,u&7&&(f=u),c=u}for(let h=o,c=a,f=a;h<l;h++){let u=ne[h];if(u==128)h<l-1&&c==ne[h+1]&&c&24?u=ne[h]=c:ne[h]=256;else if(u==64){let d=h+1;for(;d<l&&ne[d]==64;)d++;let p=h&&c==8||d<t&&ne[d]==8?f==1?1:8:256;for(let m=h;m<d;m++)ne[m]=p;h=d-1}else u==8&&f==1&&(ne[h]=1);c=u,u&7&&(f=u)}}}function HC(i,e,t,n,r){let s=r==1?2:1;for(let o=0,l=0,a=0;o<=n.length;o++){let h=o?n[o-1].to:e,c=o<n.length?n[o].from:t;for(let f=h,u,d,p;f<c;f++)if(d=Xh[u=i.charCodeAt(f)])if(d<0){for(let m=l-3;m>=0;m-=3)if(Bt[m+1]==-d){let g=Bt[m+2],y=g&2?r:g&4?g&1?s:r:0;y&&(ne[f]=ne[Bt[m]]=y),l=m;break}}else{if(Bt.length==189)break;Bt[l++]=f,Bt[l++]=u,Bt[l++]=a}else if((p=ne[f])==2||p==1){let m=p==r;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=Bt[g+2];if(y&2)break;if(m)Bt[g+2]|=2;else{if(y&4)break;Bt[g+2]|=4}}}}}function WC(i,e,t,n){for(let r=0,s=n;r<=t.length;r++){let o=r?t[r-1].to:i,l=r<t.length?t[r].from:e;for(let a=o;a<l;){let h=ne[a];if(h==256){let c=a+1;for(;;)if(c==l){if(r==t.length)break;c=t[r++].to,l=r<t.length?t[r].from:e}else if(ne[c]==256)c++;else break;let f=s==1,u=(c<e?ne[c]:n)==1,d=f==u?f?1:2:n;for(let p=c,m=r,g=m?t[m-1].to:i;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:i),ne[--p]=d;a=c}else s=h,a++}}}function Qh(i,e,t,n,r,s,o){let l=n%2?2:1;if(n%2==r%2)for(let a=e,h=0;a<t;){let c=!0,f=!1;if(h==s.length||a<s[h].from){let m=ne[a];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?n:n+1,p=a;e:for(;;)if(h<s.length&&p==s[h].from){if(f)break e;let m=s[h];if(!c)for(let g=m.to,y=h+1;;){if(g==t)break e;if(y<s.length&&s[y].from==g)g=s[y++].to;else{if(ne[g]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new $t(a,m.from,d));let g=m.direction==hr!=!(d%2);Zh(i,g?n+1:n,r,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?ne[p]!=l:ne[p]==l))break;p++}u?Qh(i,a,p,n+1,r,u,o):a<p&&o.push(new $t(a,p,d)),a=p}else for(let a=t,h=s.length;a>e;){let c=!0,f=!1;if(!h||a>s[h-1].to){let m=ne[a-1];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?n:n+1,p=a;e:for(;;)if(h&&p==s[h-1].to){if(f)break e;let m=s[--h];if(!c)for(let g=m.from,y=h;;){if(g==e)break e;if(y&&s[y-1].to==g)g=s[--y].from;else{if(ne[g-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new $t(m.to,a,d));let g=m.direction==hr!=!(d%2);Zh(i,g?n+1:n,r,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(c?ne[p-1]!=l:ne[p-1]==l))break;p--}u?Qh(i,p,a,n+1,r,u,o):p<a&&o.push(new $t(p,a,d)),a=p}}function Zh(i,e,t,n,r,s,o){let l=e%2?2:1;zC(i,r,s,n,l),HC(i,r,s,n,l),WC(r,s,n,l),Qh(i,r,s,e,t,n,o)}function $C(i,e,t){if(!i)return[new $t(0,0,e==ef?1:0)];if(e==hr&&!t.length&&!VC.test(i))return Z0(i.length);if(t.length)for(;i.length>ne.length;)ne[ne.length]=256;let n=[],r=e==hr?0:1;return Zh(i,r,r,t,0,i.length,n),n}function Z0(i){return[new $t(0,i,0)]}let ey="";function KC(i,e,t,n,r){var s;if(!i.length)return null;let o=n.head-i.from,l;if(n.head==i.from&&n.assoc<0){if(!r)return null;o=e[l=0].side(!1,t)}else if(n.head==i.to&&n.assoc>0){if(r)return null;o=e[l=e.length-1].side(!0,t)}else l=$t.find(e,o,(s=n.bidiLevel)!==null&&s!==void 0?s:-1,n.assoc);let a=e[l],h=a.side(r,t);if(o==h){let u=l+=r?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!r,t),h=a.side(r,t)}let c=Re(i.text,o,a.forward(r,t));(c<a.from||c>a.to)&&(c=h),ey=i.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(r?e.length-1:0)?null:e[l+(r?1:-1)];if(c==h){if(!f)return r?S.cursor(i.to,1):S.cursor(i.from,-1);if(f.level+(r?0:1)<a.level)return S.cursor(f.side(!r,t)+i.from,f.forward(r,t)?1:-1,f.level)}return S.cursor(c+i.from,a.forward(r,t)?-1:1,a.level)}function qC(i,e,t){for(let n=e;n<t;n++){let r=X0(i.charCodeAt(n));if(r==1)return hr;if(r==2||r==4)return ef}}const ty=D.define(),ny=D.define(),iy=D.define(),ry=D.define(),ec=D.define(),sy=D.define(),oy=D.define(),tf=D.define(),nf=D.define(),ly=D.define({combine:i=>i.some(e=>e)}),ay=D.define({combine:i=>i.some(e=>e)}),hy=D.define();class Ji{constructor(e,t,n,r,s,o=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new Ji(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Ji(S.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const wo=z.define({map:(i,e)=>i.map(e)}),cy=z.define();function Qe(i,e,t){let n=i.facet(ry);n.length?n[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const en=D.define({combine:i=>i.length?i[0]:!0});let jC=0;const Fi=D.define({combine(i){return i.filter((e,t)=>{for(let n=0;n<t;n++)if(i[n].plugin==e.plugin)return!1;return!0})}});class be{constructor(e,t,n,r,s){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Fi.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Fi.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:n,eventObservers:r,provide:s,decorations:o}=t||{};return new be(jC++,e,n,r,l=>{let a=[];return o&&a.push(ql.of(h=>{let c=h.plugin(l);return c?o(c):J.none})),s&&a.push(s(l)),a})}static fromClass(e,t){return be.define((n,r)=>new e(n,r),t)}}class Fa{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(n){if(Qe(t.state,n,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Qe(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(n){Qe(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const fy=D.define(),rf=D.define(),ql=D.define(),uy=D.define(),sf=D.define(),to=D.define(),dy=D.define();function tp(i,e){let t=i.state.facet(dy);if(!t.length)return t;let n=t.map(s=>s instanceof Function?s(i):s),r=[];return $.spans(n,e.from,e.to,{point(){},span(s,o,l,a){let h=s-e.from,c=o-e.from,f=r;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==d)p.to=c,f=p.inner;else{let m={from:h,to:c,direction:d,inner:[]};f.push(m),f=m.inner}}}}),py(e.text,r)}function py(i,e){for(let t of e){if(t.direction==null){for(let n=t.from,r=0;n<t.to;r++){let s=r<t.inner.length?t.inner[r]:null,o=qC(i,n,s?s.from:t.to);if(o){t.direction=o;break}if(!s)break;n=s.to}t.direction==null&&(t.direction=Z.LTR)}py(i,t.inner)}return e}const my=D.define();function of(i){let e=0,t=0,n=0,r=0;for(let s of i.state.facet(my)){let o=s(i);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(n=Math.max(n,o.top)),o.bottom!=null&&(r=Math.max(r,o.bottom)))}return{left:e,right:t,top:n,bottom:r}}const Hr=D.define();class dt{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(e){return new dt(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toA<n.fromA)break;n=n.join(r),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(e,t){if(t.length==0)return e;let n=[];for(let r=0,s=0,o=0;;){let l=r<e.length?e[r].fromB:1e9,a=s<t.length?t[s]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+o,f=h,u=c;for(;;)if(s<t.length&&t[s]<=f){let d=t[s+1];s+=2,f=Math.max(f,d);for(let p=r;p<e.length&&e[p].fromB<=f;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(r<e.length&&e[r].fromB<=f){let d=e[r++];f=Math.max(f,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;n.push(new dt(c,u,h,f))}return n}}class ml{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=me.empty(this.startState.doc.length);for(let s of n)this.changes=this.changes.compose(s.changes);let r=[];this.changes.iterChangedRanges((s,o,l,a)=>r.push(new dt(s,o,l,a))),this.changedRanges=r}static create(e,t,n){return new ml(e,t,n)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const JC=[];class he{constructor(e,t,n=0){this.dom=e,this.length=t,this.flags=n,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return JC}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&TC(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let n=t;for(let r of this.children){if(r==e)return n;n+=r.length+r.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,n){return null}domPosFor(e,t){let n=Wn(this.dom),r=this.length?e>0:t>0;return new vt(this.parent.dom,n+(r?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Jl)return e;return null}static get(e){return e.cmTile}}class jl extends he{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,n=null,r,s=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,r=n?n.nextSibling:t.firstChild,s&&r!=l.dom&&(s.written=!0),l.dom.parentNode==t)for(;r&&r!=l.dom;)r=np(r);else t.insertBefore(l.dom,r);n=l.dom}for(r=n?n.nextSibling:t.firstChild,s&&r&&(s.written=!0);r;)r=np(r);this.length=o}}function np(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}class Jl extends jl{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=he.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],n=this,r=0,s=0;;)if(r==n.children.length){if(!t.length)return;n=n.parent,n.breakAfter&&s++,r=t.pop()}else{let o=n.children[r++];if(o instanceof an)t.push(r),n=o,r=0;else{let l=s+o.length,a=e(o,s);if(a!==void 0)return a;s=l+o.breakAfter}}}resolveBlock(e,t){let n,r=-1,s,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(e>=a&&e<=h){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(n=void 0)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!n||!l.isWidget()&&n.isWidget())&&(n=l,r=e-a),(h>e||e==a&&(t>1?l.length:l.covers(-1)))&&(!s||!l.isWidget()&&s.isWidget())&&(s=l,o=e-a)}}),!n&&!s)throw new Error("No tile at position "+e);return n&&t<0||!s?{tile:n,offset:r}:{tile:s,offset:o}}}class an extends jl{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let n=new an(t||document.createElement(e.tagName),e);return t||(n.flags|=4),n}}class cr extends jl{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,n){let r=new cr(t||document.createElement("div"),e);return(!t||!n)&&(r.flags|=4),r}get domAttrs(){return this.attrs}resolveInline(e,t,n=!1){let r=null,s=-1,o=null,l=-1;function a(c,f){for(let u=0,d=0;u<c.children.length&&d<=f;u++){let p=c.children[u],m=d+p.length;m>=f&&(p.isComposite()?a(p,f-d):(!o||n&&o.isHidden&&(t>0&&!(o.flags&32)||n&&UC(o,p)))&&(m>f||p.flags&32&&t<=1)?(o=p,l=f-d):(d<f||p.flags&16&&!(n&&p.isHidden)&&t>=-1)&&(r=p,s=f-d)),d=m}}a(this,e);let h=(t<0?r:o)||r||o;return h?{tile:h,offset:h==r?s:l}:null}coordsIn(e,t,n){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t,n):_C(this)}domIn(e,t){let n=this.resolveInline(e,t);if(n){let{tile:r,offset:s}=n;if(this.dom.contains(r.dom))return r.isText()?new vt(r.dom,Math.min(r.dom.nodeValue.length,s)):r.domPosFor(s,r.flags&16?1:r.flags&32?-1:t);let o=n.tile.parent,l=!1;for(let a of o.children){if(l)return new vt(a.dom,0);a==n.tile&&(l=!0)}}return new vt(this.dom,0)}}function _C(i){let e=i.dom.lastChild;if(!e)return i.dom.getBoundingClientRect();let t=Go(e);return t[t.length-1]||null}function UC(i,e){let t=i.coordsIn(0,1),n=e.coordsIn(0,1);return t&&n&&n.top<t.bottom}class Xe extends jl{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let n=new Xe(t||document.createElement(e.tagName),e);return t||(n.flags|=4),n}}class ei extends he{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,n){let r=this.dom.nodeValue.length;e>r&&(e=r);let s=e,o=e,l=0;e==0&&t<0||e==r&&t>=0?N.chrome||N.gecko||(e?(s--,l=1):o<r&&(o++,l=-1)):t<0?s--:o<r&&o++;let a=Ts(this.dom,s,o).getClientRects();if(!a.length)return null;let h=a[(l?l<0:t>=0)?0:a.length-1];return N.safari&&!l&&h.width==0&&(h=Array.prototype.find.call(a,c=>c.width)||h),n==null?h:pl(h,(l?l>0:t<0)==n)}static of(e,t){let n=new ei(t||document.createTextNode(e),e);return t||(n.flags|=2),n}}class xi extends he{constructor(e,t,n,r){super(e,t,r),this.widget=n}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,n){let r=this.widget.coordsAt(this.dom,e,t);if(r)return r;if(n)return pl(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),o=null;if(!s.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?s.length-1:0;o=s[a],!(e>0?a==0:a==s.length-1||o.top<o.bottom);a+=l?-1:1);return pl(o,!l)}}get overrideDOMText(){if(!this.length)return U.empty;let{root:e}=this;if(!e)return U.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,n,r,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new xi(s,n,e,r)}}class gl extends he{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return U.empty}coordsIn(e,t,n){let r=this.dom.getBoundingClientRect();return n==null?r:pl(r,t>0==n)}}class GC{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,n){let{tile:r,index:s,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(r.isComposite())if(o){if(!e)break;n&&n.break(),e--,o=!1}else if(s==r.children.length){if(!e&&!l.length)break;n&&n.leave(r),o=!!r.breakAfter,{tile:r,index:s}=l.pop(),s++}else{let a=r.children[s],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!n||n.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,s++,e-=a.length):(l.push({tile:r,index:s}),r=a,s=0,n&&a.isComposite()&&n.enter(a))}else{let a=r.length;if(s<a&&e){let h=Math.min(e,a-s);n&&n.skip(r,s,s+h),e-=h,s+=h}if(s==a)o=!!r.breakAfter,{tile:r,index:s}=l.pop(),s++;else if(!e)break}return this.tile=r,this.index=s,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class YC{constructor(e,t,n,r){this.from=e,this.to=t,this.wrapper=n,this.rank=r}}class XC{constructor(e,t,n){this.cache=e,this.root=t,this.blockWrappers=n,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,n,r){var s;this.flushBuffer();let o=this.ensureMarks(t,n),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new ei(l.dom,l.text+e);a.parent=o}else o.append(r||ei.of(e,(s=this.cache.find(ei))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let n=this.curLine;n.dom!=t.line.dom&&(n.setDOM(this.cache.reused.has(t.line)?Va(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let r=n;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],h=r.lastChild;if(h instanceof Xe&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(Va(a.dom)),r=h;else{let{dom:c}=a;this.cache.reused.get(a)&&he.get(a.dom)&&(c=Va(a.dom));let f=Xe.of(a.mark,c);r.append(f),r=f}this.cache.reused.set(a,2)}let s=he.get(e.text);s&&this.cache.reused.set(s,2);let o=new ei(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,r.append(o)}addInlineWidget(e,t,n){let r=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);r||this.flushBuffer();let s=this.ensureMarks(t,n);!r&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,n){this.flushBuffer(),this.ensureMarks(t,n).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var n;e||(e=gy);let r=cr.start(e,t||((n=this.cache.find(cr))===null||n===void 0?void 0:n.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=r)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var n;let r=this.curLine;for(let s=e.length-1;s>=0;s--){let o=e[s],l;if(t>0&&(l=r.lastChild)&&l instanceof Xe&&l.mark.eq(o))r=l,t--;else{let a=Xe.of(o,(n=this.cache.find(Xe,h=>h.mark.eq(o)))===null||n===void 0?void 0:n.dom);r.append(a),r=a,t=0}}return r}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!ip(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(N.ios&&ip(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(za,0,32)||new xi(za.toDOM(),0,za,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,n=new YC(e.from,e.to,e.value,t),r=this.wrappers.length;for(;r>0&&(this.wrappers[r-1].rank-n.rank||this.wrappers[r-1].to-n.to)<0;)r--;this.wrappers.splice(r,0,n)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let n of this.wrappers){let r=t.lastChild;if(n.from<this.pos&&r instanceof an&&r.wrapper.eq(n.wrapper))t=r;else{let s=an.of(n.wrapper,(e=this.cache.find(an,o=>o.wrapper.eq(n.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),n=this.cache.find(gl,void 0,1);return n&&(n.flags=t),n||new gl(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class QC{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:r,lineBreak:s,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=r;let l=this.textOff=Math.min(e,r.length);return s?null:r.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),n=this.text.slice(this.textOff,t);return this.textOff=t,n}}const yl=[xi,cr,ei,Xe,gl,an,Jl];for(let i=0;i<yl.length;i++)yl[i].bucket=i;class ZC{constructor(e){this.view=e,this.buckets=yl.map(()=>[]),this.index=yl.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,n=this.buckets[t];n.length<6?n.push(e):n[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,n=2){let r=e.bucket,s=this.buckets[r],o=this.index[r];for(let l=0;l<s.length;l++){let a=(l+o)%s.length,h=s[a];if((!t||t(h))&&!this.reused.has(h))return s.splice(a,1),a<o&&this.index[r]--,this.reused.set(h,n),h}return null}findWidget(e,t,n){let r=this.buckets[0];if(r.length)for(let s=0,o=0;;s++){if(s==r.length){if(o)return null;o=1,s=0}let l=r[s];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return r.splice(s,1),s<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==n?(this.reused.set(l,1),l):(this.reused.set(l,2),new xi(l.dom,t,e,l.flags&-498|n))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class ev{constructor(e,t,n,r,s){this.view=e,this.decorations=r,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new ZC(e),this.text=new QC(e.state.doc),this.builder=new XC(this.cache,new Jl(e,e.contentDOM),$.iter(n)),this.cache.reused.set(t,2),this.old=new GC(t),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let n=t&&this.getCompositionContext(t.text);for(let r=0,s=0,o=0;;){let l=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>r){let h=a-r;this.preserve(h,!o,!l),r=a,s+=h}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,n),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(s,l.toB)),s=l.toB,r=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,n){let r=iv(this.old),s=this.openMarks;this.old.advance(e,n?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?xi.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,r,s),s=r.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,r,s,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),r,s)),s=r.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof gl)this.cache.add(o);else if(o instanceof Xe)this.builder.ensureLine(null),this.builder.addMark(o,r,s),this.cache.reused.set(o,1),s=r.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof Xe&&r.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?r.length&&(r.length=s=0):o instanceof Xe&&(r.shift(),s=Math.min(s,r.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let n=null,r=this.builder,s=-1,o=$.spans(this.decorations,e,t,{point:(l,a,h,c,f,u)=>{if(h instanceof ki){if(this.disallowBlockEffectsFor[u]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,f>c.length)r.continueWidget(a-l);else{let d=h.widget||(h.block?fr.block:fr.inline),p=tv(h),m=this.cache.findWidget(d,a-l,p)||xi.of(d,this.view,a-l,p);h.block?(h.startSide>0&&r.addLineStartIfNotCovered(n),r.addBlockWidget(m)):(r.ensureLine(n),r.addInlineWidget(m,c,f))}n=null}else n=nv(n,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let u=this.text.next(Math.min(512,a-f));u==null?(r.addLineStartIfNotCovered(n),r.addBreak(),f++):(r.ensureLine(n),r.addText(u,h,f==l?c:h.length),f+=u.length),n=null}s=h.length}});s>-1&&(this.openWidget=o>s),this.openWidget||r.addLineStartIfNotCovered(n),this.openMarks=o}forward(e,t,n=1){t-e<=10?this.old.advance(t-e,n,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,n,this.reuseWalker))}getCompositionContext(e){let t=[],n=null;for(let r=e.parentNode;;r=r.parentNode){let s=he.get(r);if(r==this.view.contentDOM)break;s instanceof Xe?t.push(s):s?.isLine()?n=s:s instanceof an||(r.nodeName=="DIV"&&!n?n=new cr(r,gy):n||t.push(Xe.of(new Zs({tagName:r.nodeName.toLowerCase(),attributes:NC(r)}),r)))}return n?{line:n,marks:t}:null}}function ip(i,e){let t=n=>{for(let r of n.children)if((e?r.isText():r.length)||t(r))return!0;return!1};return t(i)}function tv(i){let e=i.isReplace?(i.startSide<0?64:0)|(i.endSide>0?128:0):i.startSide>0?32:16;return i.block&&(e|=256),e}const gy={class:"cm-line"};function nv(i,e){let t=e.spec.attributes,n=e.spec.class;return!t&&!n||(i||(i={class:"cm-line"}),t&&Qc(t,i),n&&(i.class+=" "+n)),i}function iv(i){let e=[];for(let t=i.parents.length;t>1;t--){let n=t==i.parents.length?i.tile:i.parents[t].tile;n instanceof Xe&&e.push(n.mark)}return e}function Va(i){let e=he.get(i);return e&&e.setDOM(i.cloneNode()),i}class fr extends gn{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}fr.inline=new fr("span");fr.block=new fr("div");const za=new class extends gn{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class rp{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=J.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Jl(e,e.contentDOM),this.updateInner([new dt(0,0,0,e.state.doc.length)],null)}update(e){var t;let n=e.changedRanges;this.minWidth>0&&n.length&&(n.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let r=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?r=this.domChanged.newSel.head:!uv(e.changes,this.hasComposition)&&!e.selectionSet&&(r=e.state.selection.main.head));let s=r>-1?sv(this.view,e.changes,r):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;n=new dt(c,f,e.changes.mapPos(c,-1),e.changes.mapPos(f,1)).addToSet(n.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(N.ie||N.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=av(o,this.decorations,e.changes);a.length&&(n=dt.extendWithRanges(n,a));let h=cv(l,this.blockWrappers,e.changes);return h.length&&(n=dt.extendWithRanges(n,h)),s&&!n.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(n=s.range.addToSet(n.slice())),this.tile.flags&2&&n.length==0?!1:(this.updateInner(n,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:n}=this.view;n.ignore(()=>{if(t||e.length){let o=this.tile,l=new ev(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&he.get(t.text)&&l.cache.reused.set(he.get(t.text),2),this.tile=l.run(e,t),tc(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=N.chrome||N.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||n.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof Ha&&r.push(s.dom);n.updateGaps(r)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let n of t.effects)n.is(cy)&&(this.editContextFormatting=n.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:n}=this.tile,r=this.view.root.activeElement,s=r==n,o=!s&&!(this.view.state.facet(en)||n.tabIndex>-1)&&ns(n,this.view.observer.selectionRange)&&!(r&&n.contains(r));if(!(s||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),N.gecko&&a.empty&&!this.hasComposition&&rv(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=c=new vt(u,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!is(h.node,h.offset,f.anchorNode,f.anchorOffset)||!is(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{N.android&&N.chrome&&n.contains(f.focusNode)&&fv(f.focusNode,n)&&(n.blur(),n.focus({preventScroll:!0}));let u=Os(this.view.root);if(u)if(a.empty){if(N.gecko){let d=ov(h.node,h.offset);if(d&&d!=3){let p=(d==1?U0:G0)(h.node,h.offset);p&&(h=new vt(p.node,p.offset))}}u.collapse(h.node,h.offset),a.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=a.bidiLevel)}else if(u.extend){u.collapse(h.node,h.offset);try{u.extend(c.node,c.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),d.setEnd(c.node,c.offset),d.setStart(h.node,h.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==n&&(n.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new vt(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new vt(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&is(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=Os(e.root),{anchorNode:r,anchorOffset:s}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);n.collapse(c.node,c.offset),n.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&n.collapse(r,s)}posFromDOM(e,t){let n=this.tile.nearest(e);if(!n)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let r=n.posAtStart;if(n.isComposite()){let s;if(e==n.dom)s=n.dom.childNodes[t];else{let o=cn(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==n.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?s=e:s=e.nextSibling}if(s==n.dom.firstChild)return r;for(;s&&!he.get(s);)s=s.nextSibling;if(!s)return r+n.length;for(let o=0,l=r;;o++){let a=n.children[o];if(a.dom==s)return l;l+=a.length+a.breakAfter}}else return n.isText()?e==n.dom?r+t:r+(t?n.length:0):r}domAtPos(e,t){let{tile:n,offset:r}=this.tile.resolveBlock(e,t);return n.isWidget()?n.domPosFor(r,t):n.domIn(r,t)}inlineDOMNearPos(e,t){let n,r=-1,s=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=e)return!0;h.flags&16&&(s=!0)}else{let f=c+h.length;if(c<=e&&(n=h,r=e-c,s=f<e),f>=e&&!o&&(o=h,l=e-c,a=c>e),c>e&&o)return!0}}),!n&&!o?this.domAtPos(e,t):(s&&o?n=null:a&&n&&(o=null),n&&t<0||!o?n.domIn(r,t):o.domIn(l,t))}coordsAt(e,t,n){let{tile:r,offset:s}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof Ha?null:r.coordsInWidget(s,t,!0):r.coordsIn(s,t,n)}lineAt(e,t){let{tile:n}=this.tile.resolveBlock(e,t);return n.isLine()?n:null}coordsForChar(e){let{tile:t,offset:n}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function r(s,o){if(s.isComposite())for(let l of s.children){if(l.length>=o){let a=r(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(s.isText()&&o<s.length){let l=Re(s.text,o);if(l==o)return null;let a=Ts(s.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return r(t,n)}measureVisibleLineHeights(e){let t=[],{from:n,to:r}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==Z.LTR,h=0,c=(f,u,d)=>{for(let p=0;p<f.children.length&&!(u>r);p++){let m=f.children[p],g=u+m.length,y=m.dom.getBoundingClientRect(),{height:b}=y;if(d&&!p&&(h+=y.top-d.top),m instanceof an)g>n&&c(m,u,y);else if(u>=n&&(h>0&&t.push(-h),t.push(b+h),h=0,o)){let k=m.dom.lastChild,O=k?Go(k):[];if(O.length){let w=O[O.length-1],M=a?w.right-y.left:y.right-w.left;M>l&&(l=M,this.minWidth=s,this.minWidthFrom=u,this.minWidthTo=g)}}d&&p==f.children.length-1&&(h+=d.bottom-y.bottom),u=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?Z.RTL:Z.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Go(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),n,r,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Go(t.firstChild)[0];n=t.getBoundingClientRect().height,r=o&&o.width?o.width/27:7,s=o&&o.height?o.height:n,t.remove()}),{lineHeight:n,charWidth:r,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let s=r==t.viewports.length?null:t.viewports[r],o=s?s.from-1:this.view.state.doc.length;if(o>n){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(J.replace({widget:new Ha(l),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!s)break;n=s.to+1}return J.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ql).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),n=!1,r=this.view.state.facet(sf).map((s,o)=>{let l=typeof s=="function";return l&&(n=!0),l?s(this.view):s});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push($.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(uy).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let h=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=h.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let h of this.view.state.facet(hy))try{if(h(this.view,e.range,e))return!0}catch(c){Qe(this.view.state,c,"scroll handler")}let{range:t}=e,n=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let s=of(this.view),o={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;if(EC(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==Z.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.visualViewport.offsetTop)){let h=this.view.docView.lineAt(t.head,1);if(h){let c=q0(h.dom);h.dom.scrollIntoView({block:"nearest"}),j0(c,!1)}}}lineHasWidget(e){let t=n=>n.isWidget()||n.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){tc(this.tile)}}function tc(i,e){let t=e?.get(i);if(t!=1){t==null&&i.destroy();for(let n of i.children)tc(n,e)}}function rv(i){return xe(i.node)&&i.node.firstChild&&(i.offset==0||i.node.childNodes[i.offset-1].contentEditable=="false")&&(i.offset==i.node.childNodes.length||i.node.childNodes[i.offset].contentEditable=="false")}function yy(i,e){let t=i.observer.selectionRange;if(!t.focusNode)return null;let n=U0(t.focusNode,t.focusOffset),r=G0(t.focusNode,t.focusOffset),s=n||r;if(r&&n&&r.node!=n.node){let l=he.get(r.node);if(!l||l.isText()&&l.text!=r.node.nodeValue)s=r;else if(i.docView.lastCompositionAfterCursor){let a=he.get(n.node);!a||a.isText()&&a.text!=n.node.nodeValue||(s=r)}}if(i.docView.lastCompositionAfterCursor=s!=n,!s)return null;let o=e-s.offset;return{from:o,to:o+s.node.nodeValue.length,node:s.node}}function sv(i,e,t){let n=yy(i,t);if(!n)return null;let{node:r,from:s,to:o}=n,l=r.nodeValue;if(/[\n\r]/.test(l)||i.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc;return{range:new dt(a.mapPos(s),a.mapPos(o),s,o),text:r}}function ov(i,e){return xe(i)?(e&&i.childNodes[e-1].contentEditable=="false"?1:0)|(e<i.childNodes.length&&i.childNodes[e].contentEditable=="false"?2:0):0}let lv=class{constructor(){this.changes=[]}compareRange(e,t){qi(e,t,this.changes)}comparePoint(e,t){qi(e,t,this.changes)}boundChange(e){qi(e,e,this.changes)}};function av(i,e,t){let n=new lv;return $.compare(i,e,t,n),n.changes}class hv{constructor(){this.changes=[]}compareRange(e,t){qi(e,t,this.changes)}comparePoint(){}boundChange(e){qi(e,e,this.changes)}}function cv(i,e,t){let n=new hv;return $.compare(i,e,t,n),n.changes}function fv(i,e){for(let t=i;t&&t!=e;t=t.assignedSlot||t.parentNode)if(xe(t)&&t.contentEditable=="false")return!0;return!1}function uv(i,e){let t=!1;return e&&i.iterChangedRanges((n,r)=>{n<e.to&&r>e.from&&(t=!0)}),t}class Ha extends gn{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function dv(i,e,t=1){let n=i.charCategorizer(e),r=i.doc.lineAt(e),s=e-r.from;if(r.length==0)return S.cursor(e);s==0?t=1:s==r.length&&(t=-1);let o=s,l=s;t<0?o=Re(r.text,s,!1):l=Re(r.text,s);let a=n(r.text.slice(o,l));for(;o>0;){let h=Re(r.text,o,!1);if(n(r.text.slice(h,o))!=a)break;o=h}for(;l<r.length;){let h=Re(r.text,l);if(n(r.text.slice(l,h))!=a)break;l=h}return S.undirectionalRange(o+r.from,l+r.from)}function pv(i,e,t,n,r){let s=Math.round((n-e.left)*i.defaultCharacterWidth);if(i.lineWrapping&&t.height>i.defaultLineHeight*1.5){let l=i.viewState.heightOracle.textHeight,a=Math.floor((r-t.top-(i.defaultLineHeight-l)*.5)/l);s+=a*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+Kh(o,s,i.state.tabSize)}function nc(i,e,t){let n=i.lineBlockAt(e);if(Array.isArray(n.type)){let r;for(let s of n.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!r||s.type==Te.Text&&(r.type!=s.type||(t<0?s.from<e:s.to>e)))&&(r=s)}}return r||n}return n}function mv(i,e,t,n){let r=nc(i,e.head,e.assoc||-1),s=!n||r.type!=Te.Text||!(i.lineWrapping||r.widgetLineBreaks)?null:i.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head);if(s){let o=i.dom.getBoundingClientRect(),l=i.textDirectionAt(r.from),a=i.posAndSideAtCoords({x:t==(l==Z.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(a)return S.cursor(a.pos,a.assoc)}return S.cursor(t?r.to:r.from,t?1:-1)}function sp(i,e,t,n){let r=i.state.doc.lineAt(e.head),s=i.bidiSpans(r),o=i.textDirectionAt(r.from);for(let l=e,a=null;;){let h=KC(r,s,o,l,t),c=ey;if(!h){if(r.number==(t?i.state.doc.lines:1))return l;c=`
|
|
19
|
+
`,r=i.state.doc.line(r.number+(t?1:-1)),s=i.bidiSpans(r),h=t?S.cursor(r.from,-1):S.cursor(r.to,1)}if(a){if(!a(c))return l}else{if(!n)return h;a=n(c)}l=h}}function gv(i,e,t){let n=i.state.charCategorizer(e),r=n(t);return s=>{let o=n(s);return r==ut.Space&&(r=o),r==o}}function yv(i,e,t,n){let r=e.head,s=t?1:-1;if(r==(t?i.state.doc.length:0))return S.cursor(r,e.assoc);let o=e.goalColumn,l,a=i.contentDOM.getBoundingClientRect(),h=i.coordsAtPos(r,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=i.documentTop;if(h)o==null&&(o=h.left-a.left),l=s<0?h.top:h.bottom;else{let p=i.viewState.lineBlockAt(r);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(r-p.from))),l=(s<0?p.top:p.bottom)+c}let f=a.left+o,u=i.viewState.heightOracle.textHeight>>1,d=n??u;for(let p=0;;p+=u){let m=l+(d+p)*s,g=ic(i,{x:f,y:m},!1,s);if(t?m>a.bottom:m<a.top)return S.cursor(g.pos,g.assoc);let y=i.coordsAtPos(g.pos,g.assoc),b=y?(y.top+y.bottom)/2:0;if(!y||(t?b>l:b<l))return S.cursor(g.pos,g.assoc,void 0,o)}}function rs(i,e,t){for(;;){let n=0;for(let r of i)r.between(e-1,e+1,(s,o,l)=>{if(e>s&&e<o){let a=n||t||(e-s<o-e?-1:1);e=a<0?s:o,n=a}});if(!n)return e}}function by(i,e){let t=null;for(let n=0;n<e.ranges.length;n++){let r=e.ranges[n],s=null;if(r.empty){let o=rs(i,r.from,0);o!=r.from&&(s=S.cursor(o,-1))}else{let o=rs(i,r.from,-1),l=rs(i,r.to,1);(o!=r.from||l!=r.to)&&(r.undirectional?s=S.undirectionalRange(r.from,r.to):s=S.range(r.from==r.anchor?o:l,r.from==r.head?o:l))}s&&(t||(t=e.ranges.slice()),t[n]=s)}return t?S.create(t,e.mainIndex):e}function Wa(i,e,t){let n=rs(i.state.facet(to).map(r=>r(i)),t.from,e.head>t.from?-1:1);return n==t.from?t:S.cursor(n,n<t.from?1:-1)}class Ht{constructor(e,t){this.pos=e,this.assoc=t}}function ic(i,e,t,n){let r=i.contentDOM.getBoundingClientRect(),s=r.top+i.viewState.paddingTop,{x:o,y:l}=e,a=l-s,h;for(;;){if(a<0)return new Ht(0,1);if(a>i.viewState.docHeight)return new Ht(i.state.doc.length,-1);if(h=i.elementAtHeight(a),n==null)break;if(h.type==Te.Text){if(n<0?h.to<i.viewport.from:h.from>i.viewport.to)break;let u=i.docView.coordsAt(n<0?h.from:h.to,n>0?-1:1);if(u&&(n<0?u.top<=a+s:u.bottom>=a+s))break}let f=i.viewState.heightOracle.textHeight/2;a=n>0?h.bottom+f:h.top-f}if(i.viewport.from>=h.to||i.viewport.to<=h.from){if(t)return null;if(h.type==Te.Text){let f=pv(i,r,h,o,l);return new Ht(f,f==h.from?1:-1)}}if(h.type!=Te.Text)return a<(h.top+h.bottom)/2?new Ht(h.from,1):new Ht(h.to,-1);let c=i.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=i.docView.lineAt(h.from,-2)),new bv(i,o,l,i.textDirectionAt(h.from)).scanTile(c,h.from)}class bv{constructor(e,t,n,r){this.view=e,this.x=t,this.y=n,this.baseDir=r,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[$t.find(r,e-n.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[$t.find(r,e-n.from,-1,t)].dir}bidiIn(e,t){let{spans:n,line:r}=this.bidiSpansAt(e);return n.length>1||n.length&&(n[0].level!=this.baseDir||n[0].to+r.from<t)}scan(e,t,n=!1){let r=0,s=e.length-1,o=new Set,l=this.bidiIn(e[0],e[s]),a,h,c=-1,f=1e9,u;e:for(;r<s;){let p=s-r,m=r+s>>1;t:if(o.has(m)){for(let b=1;b<p;b++){let k=m+b;if(k>=s&&(k-=p),!o.has(k)){m=k;break t}}break e}o.add(m);let g=t(m),y=0;if(g)for(let b=0;b<g.length;b++){let k=g[b];if(!(k.width==0&&g.length>1))if(k.bottom<this.y)(!a||a.bottom<k.bottom)&&(a=k),y=1;else if(k.top>this.y)(!h||h.top>k.top)&&(h=k),y=-1;else{let O=k.left>this.x?this.x-k.left:k.right<this.x?this.x-k.right:0,w=Math.abs(O);w<f&&(c=m,f=w,u=k),O&&(y=O<0==(this.baseDir==Z.LTR)?-1:1)}}y==-1&&(!l||this.baseDirAt(e[m],1))?s=m:y==1&&(!l||this.baseDirAt(e[m+1],-1))&&(r=m+1)}if(!u){if(!h&&!a)return{i:0,after:!1};let p=a&&(!h||this.y-a.bottom<h.top-this.y)?a:h;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(f&&!n){let{top:p,bottom:m}=u;if(a&&a.bottom>(p+p+m)/3)return this.y=a.bottom-1,this.scan(e,t,!0);if(h&&h.top<(p+m+m)/3)return this.y=h.top+1,this.scan(e,t,!0)}let d=(l?this.dirAt(e[c],1):this.baseDir)==Z.LTR;return{i:c,after:this.x>(u.left+u.right)/2==d}}scanText(e,t){let n=[];for(let s=0;s<e.length;s=Re(e.text,s))n.push(t+s);n.push(t+e.length);let r=this.scan(n,s=>{let o=n[s]-t,l=n[s+1]-t;return Ts(e.dom,o,l).getClientRects()});return r.after?new Ht(n[r.i+1],-1):new Ht(n[r.i],1)}scanTile(e,t){if(!e.length)return new Ht(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let n=[t];for(let l=0,a=t;l<e.children.length;l++)n.push(a+=e.children[l].length);let r=this.scan(n,l=>{let a=e.children[l];return a.flags&48?null:(xe(a.dom)?a.dom:Ts(a.dom,0,a.length)).getClientRects()}),s=e.children[r.i],o=n[r.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):r.after?new Ht(n[r.i+1],-1):new Ht(o,1)}}const Li="";class kv{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(Y.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Li}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r);let s=this.text.length;this.readNode(r);let o=he.get(r),l=r.nextSibling;if(l==t){o?.breakAfter&&!l&&n!=this.view.contentDOM&&this.lineBreak();break}let a=he.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:dl(r))||dl(l)&&(r.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!wv(l,t)&&this.lineBreak(),r=l}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,l;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(l=r.exec(t))&&(s=l.index,o=l[0].length),this.append(t.slice(n,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);n=s+o}}readNode(e){let t=he.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let r=n.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.value)}else ar(e)?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():xe(e)&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(ar(e)?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(xv(e,n.node,n.offset)?t:0))}}function xv(i,e,t){for(;;){if(!e||t<cn(e))return!1;if(e==i)return!0;t=Wn(e)+1,e=e.parentNode}}function wv(i,e){let t;for(;!(i==e||!i);i=i.nextSibling){let n=he.get(i);if(!n?.isWidget())return!1;n&&(t||(t=[])).push(n)}if(t)for(let n of t){let r=n.overrideDOMText;if(r?.length)return!1}return!0}class op{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Sv{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=ky(e.docView.tile,t,n,0))){let a=s||o?[]:vv(e),h=new kv(a,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=Mv(a,this.bounds.from)}else{let a=e.observer.selectionRange,h=s&&s.node==a.focusNode&&s.offset==a.focusOffset||!Yh(e.contentDOM,a.focusNode)?l.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),c=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!Yh(e.contentDOM,a.anchorNode)?l.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),f=e.viewport;if((N.ios||N.chrome)&&h!=c&&Math.min(h,c)<=l.main.from&&Math.max(h,c)>=l.main.to&&(f.from>0||f.to<e.state.doc.length)){let u=Math.min(h,c),d=Math.max(h,c),p=f.from-u,m=f.to-d;(p==0||p==1||u==0)&&(m==0||m==-1||d==e.state.doc.length)&&(h=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(S.range(c,h));else if(e.lineWrapping&&c==h&&!(l.main.empty&&l.main.head==h)&&e.inputState.lastTouchTime>Date.now()-100){let u=e.coordsAtPos(h,-1),d=0;u&&(d=e.inputState.lastTouchY<=u.bottom?-1:1),this.newSel=S.create([S.cursor(h,d)])}else this.newSel=S.single(c,h)}}}function ky(i,e,t,n){if(i.isComposite()){let r=-1,s=-1,o=-1,l=-1;for(let a=0,h=n,c=n;a<i.children.length;a++){let f=i.children[a],u=h+f.length;if(h<e&&u>t)return ky(f,e,t,h);if(u>=e&&r==-1&&(r=a,s=h),h>t&&f.dom.parentNode==i.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:s,to:l<0?n+i.length:l,startDOM:(r?i.children[r-1].dom.nextSibling:null)||i.dom.firstChild,endDOM:o<i.children.length&&o>=0?i.children[o].dom:null}}else return i.isText()?{from:n,to:n+i.length,startDOM:i.dom,endDOM:i.dom.nextSibling}:null}function xy(i,e){let t,{newSel:n}=e,{state:r}=i,s=r.selection.main,o=i.inputState.lastKeyTime>Date.now()-100?i.inputState.lastKeyCode:-1;if(e.bounds){let{from:l,to:a}=e.bounds,h=s.from,c=null;(o===8||N.android&&e.text.length<a-l)&&(h=s.to,c="end");let f=r.doc.sliceString(l,a,Li),u,d;!s.empty&&s.from>=l&&s.to<=a&&(e.typeOver||f!=e.text)&&f.slice(0,s.from-l)==e.text.slice(0,s.from-l)&&f.slice(s.to-l)==e.text.slice(u=e.text.length-(f.length-(s.to-l)))?t={from:s.from,to:s.to,insert:U.of(e.text.slice(s.from-l,u).split(Li))}:(d=wy(f,e.text,h-l,c))&&(N.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==Li+Li&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:U.of(e.text.slice(d.from,d.toB).split(Li))})}else n&&(!i.hasFocus&&r.facet(en)||rc(n,s))&&(n=null);if(!t&&!n)return!1;if((N.mac||N.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&i.contentDOM.getAttribute("autocorrect")=="off"?(n&&t.insert.length==2&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:t.from,to:t.to,insert:U.of([t.insert.toString().replace("."," ")])}):r.doc.lineAt(s.from).to<s.to&&i.docView.lineHasWidget(s.to)&&i.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:r.toText(i.inputState.insertingText)}:N.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
20
|
+
`&&i.lineWrapping&&(n&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:s.from,to:s.to,insert:U.of([" "])}),t)return lf(i,t,n,o);if(n&&!rc(n,s)){let l=!1,a="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(l=!0),a=i.inputState.lastSelectionOrigin,a=="select.pointer"&&(n=by(r.facet(to).map(h=>h(i)),n))),i.dispatch({selection:n,scrollIntoView:l,userEvent:a}),!0}else return!1}function lf(i,e,t,n=-1){if(N.ios&&i.inputState.flushIOSKey(e))return!0;let r=i.state.selection.main;if(N.android&&(e.to==r.to&&(e.from==r.from||e.from==r.from-1&&i.state.sliceDoc(e.from,r.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&ji(i.contentDOM,"Enter",13)||(e.from==r.from-1&&e.to==r.to&&e.insert.length==0||n==8&&e.insert.length<e.to-e.from&&e.to>r.head)&&ji(i.contentDOM,"Backspace",8)||e.from==r.from&&e.to==r.to+1&&e.insert.length==0&&ji(i.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();i.inputState.composing>=0&&i.inputState.composing++;let o,l=()=>o||(o=Cv(i,e,t));return i.state.facet(sy).some(a=>a(i,e.from,e.to,s,l))||i.dispatch(l()),!0}function Cv(i,e,t){let n,r=i.state,s=r.selection.main,o=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let a=e.from<s.from?-1:1,h=a<0?s.from:s.to,c=rs(r.facet(to).map(f=>f(i)),h,a);e.from==c&&(o=c)}if(o>-1)n={changes:e,selection:S.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&i.inputState.composing<0){let a=s.from<e.from?r.sliceDoc(s.from,e.from):"",h=s.to>e.to?r.sliceDoc(e.to,s.to):"";n=r.replaceSelection(i.state.toText(a+e.insert.sliceString(0,void 0,i.state.lineBreak)+h))}else{let a=r.changes(e),h=t&&t.main.to<=a.newLength?t.main:void 0;if(r.selection.ranges.length>1&&(i.inputState.composing>=0||i.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=i.state.sliceDoc(e.from,e.to),f,u=t&&yy(i,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);f={from:u.from,to:u.to-p}}else f=i.state.doc.lineAt(s.head);let d=s.to-e.to;n=r.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,g=m-c.length;if(i.state.sliceDoc(g,m)!=c||m>=f.from&&g<=f.to)return{range:p};let y=r.changes({from:g,to:m,insert:e.insert}),b=p.to-s.to;return{changes:y,range:h?S.range(Math.max(0,h.anchor+b),Math.max(0,h.head+b)):p.map(y)}})}else n={changes:a,selection:h&&r.selection.replaceRange(h)}}let l="input.type";return(i.composing||i.inputState.compositionPendingChange&&i.inputState.compositionEndedAt>Date.now()-50)&&(i.inputState.compositionPendingChange=!1,l+=".compose",i.inputState.compositionFirstChange&&(l+=".start",i.inputState.compositionFirstChange=!1)),r.update(n,{userEvent:l,scrollIntoView:!0})}function wy(i,e,t,n){let r=Math.min(i.length,e.length),s=0;for(;s<r&&i.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==r&&i.length==e.length)return null;let o=i.length,l=e.length;for(;o>0&&l>0&&i.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(n=="end"){let a=Math.max(0,s-Math.min(o,l));t-=o+a-s}if(o<s&&i.length<e.length){let a=t<=s&&t>=o?s-t:0;s-=a,l=s+(l-o),o=s}else if(l<s){let a=t<=s&&t>=l?s-t:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function vv(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}=i.observer.selectionRange;return t&&(e.push(new op(t,n)),(r!=t||s!=n)&&e.push(new op(r,s))),e}function Mv(i,e){if(i.length==0)return null;let t=i[0].pos,n=i.length==2?i[1].pos:t;return t<0||n<0?null:t==n?S.create([S.cursor(n+e,-1)]):S.single(t+e,n+e)}function rc(i,e){return e.head==i.main.head&&e.anchor==i.main.anchor}class Av{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,N.safari&&e.contentDOM.addEventListener("input",()=>null),N.gecko&&$v(e.contentDOM.ownerDocument)}handleEvent(e){!Pv(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let r of n.observers)r(this.view,t);for(let r of n.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Tv(e),n=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,l=n[s];l&&o!=!l.handlers.length&&(r.removeEventListener(s,this.handleEvent),l=null),l||r.addEventListener(s,this.handleEvent,{passive:o})}for(let s in n)s!="scroll"&&!t[s]&&r.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Cy.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),N.android&&N.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(N.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(Sy.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||Nv.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};t.shiftKey&&N.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&Ov(this.view.win)&&(t.shiftKey=!1);let n=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t};return setTimeout(()=>{this.pendingIOSKey==n&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let t=this.pendingIOSKey;return!t||this.view.observer.pendingRecords().length||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,ji(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:N.safari&&!N.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Ov(i){return i.visualViewport?i.visualViewport.height*i.visualViewport.scale/i.document.documentElement.clientHeight<.85:!1}function lp(i,e){return(t,n)=>{try{return e.call(i,n,t)}catch(r){Qe(t.state,r)}}}function Tv(i){let e=Object.create(null);function t(n){return e[n]||(e[n]={observers:[],handlers:[]})}for(let n of i){let r=n.spec,s=r&&r.plugin.domEventHandlers,o=r&&r.plugin.domEventObservers;if(s)for(let l in s){let a=s[l];a&&t(l).handlers.push(lp(n.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(lp(n.value,a))}}for(let n in At)t(n).handlers.push(At[n]);for(let n in Je)t(n).observers.push(Je[n]);return e}const Sy=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Nv="dthko",Cy=[16,17,18,20,91,92,224,225],So=6;function Co(i){return Math.max(0,i)*.7+8}function Dv(i,e){return Math.max(Math.abs(i.clientX-e.clientX),Math.abs(i.clientY-e.clientY))}class Iv{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=K0(e.contentDOM),this.atoms=e.state.facet(to).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Y.allowMultipleSelections)&&Ev(e,t),this.dragging=Bv(e,t)&&Ay(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Dv(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,s=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=of(this.view);e.clientX-a.left<=r+So?t=-Co(r-e.clientX):e.clientX+a.right>=o-So&&(t=Co(e.clientX-o)),e.clientY-a.top<=s+So?n=-Co(s-e.clientY):e.clientY+a.bottom>=l-So&&(n=Co(e.clientY-l)),this.setScrollSpeed(t,n)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,n=by(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!n.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:n,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Ev(i,e){let t=i.state.facet(ty);return t.length?t[0](e):N.mac?e.metaKey:e.ctrlKey}function Rv(i,e){let t=i.state.facet(ny);return t.length?t[0](e):N.mac?!e.altKey:!e.ctrlKey}function Bv(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=Os(i.root);if(!n||n.rangeCount==0)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s<r.length;s++){let o=r[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Pv(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,n;t!=i.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(n=he.get(t))&&n.isWidget()&&!n.isHidden&&n.widget.ignoreEvent(e))return!1;return!0}const At=Object.create(null),Je=Object.create(null),vy=N.ie&&N.ie_version<15||N.ios&&N.webkit_version<604;function Lv(i){let e=i.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{i.focus(),t.remove(),My(i,t.value)},50)}function _l(i,e,t){for(let n of i.facet(e))t=n(t,i);return t}function My(i,e){e=_l(i.state,tf,e);let{state:t}=i,n,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(sc!=null&&t.selection.ranges.every(a=>a.empty)&&sc==s.toString()){let a=-1;n=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?s.line(r++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:S.cursor(h.from+f.length,-1)}})}else o?n=t.changeByRange(a=>{let h=s.line(r++);return{changes:{from:a.from,to:a.to,insert:h.text},range:S.cursor(a.from+h.length,-1)}}):n=t.replaceSelection(s);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}Je.scroll=i=>{let e=i.inputState;e.lastScrollTop=i.scrollDOM.scrollTop,e.lastScrollLeft=i.scrollDOM.scrollLeft,N.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};Je.wheel=Je.mousewheel=i=>{i.inputState.lastWheelEvent=Date.now()};At.keydown=(i,e)=>(i.inputState.setSelectionOrigin("select"),e.keyCode==27&&i.inputState.tabFocusMode!=0&&(i.inputState.tabFocusMode=Date.now()+2e3),!1);Je.touchstart=(i,e)=>{let t=i.inputState,n=e.targetTouches[0];t.touchActive=!0,t.lastTouchTime=Date.now(),n&&(t.lastTouchX=n.clientX,t.lastTouchY=n.clientY),t.setSelectionOrigin("select.pointer")};Je.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};Je.touchend=(i,e)=>{i.inputState.touchActive=!1};At.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let n of i.state.facet(iy))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=Vv(i,e)),t){let n=!i.hasFocus;i.inputState.startMouseSelection(new Iv(i,e,t,n)),n&&i.observer.ignore(()=>{J0(i.contentDOM);let s=i.root.activeElement;s&&!s.contains(i.contentDOM)&&s.blur()});let r=i.inputState.mouseSelection;if(r)return r.start(e),r.dragging===!1}else i.inputState.setSelectionOrigin("select.pointer");return!1};function ap(i,e,t,n){if(n==1)return S.cursor(e,t);if(n==2)return dv(i.state,e,t);{let r=i.docView.lineAt(e,t),s=i.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,l=r?r.posAtEnd:s.to;return l<i.state.doc.length&&l==s.to&&l++,S.undirectionalRange(o,l)}}const Fv=N.ie&&N.ie_version<=11;let hp=null,cp=0,fp=0;function Ay(i){if(!Fv)return i.detail;let e=hp,t=fp;return hp=i,fp=Date.now(),cp=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?(cp+1)%3:1}function Vv(i,e){let t=i.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),n=Ay(e),r=i.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),r=r.map(s.changes))},get(s,o,l){let a=i.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),h,c=ap(i,a.pos,a.assoc,n);if(t.pos!=a.pos&&!o){let f=ap(i,t.pos,t.assoc,n),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u<c.from?S.range(u,d,c.assoc):S.range(d,u,c.assoc)}return o?r.replaceRange(r.main.extend(c.from,c.to,c.assoc)):l&&n==1&&r.ranges.length>1&&(h=zv(r,a.pos))?h:l?r.addRange(c):S.create([c])}}}function zv(i,e){for(let t=0;t<i.ranges.length;t++){let{from:n,to:r}=i.ranges[t];if(n<=e&&r>=e)return S.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}return null}At.dragstart=(i,e)=>{let{selection:{main:t}}=i.state;if(e.target.draggable){let r=i.docView.tile.nearest(e.target);if(r&&r.isWidget()){let s=r.posAtStart,o=s+r.length;(s>=t.to||o<=t.from)&&(t=S.undirectionalRange(s,o))}}let{inputState:n}=i;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",_l(i.state,nf,i.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};At.dragend=i=>(i.inputState.draggedContent=null,!1);function up(i,e,t,n){if(t=_l(i.state,tf,t),!t)return;let r=i.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=i.inputState,o=n&&s&&Rv(i,e)?{from:s.from,to:s.to}:null,l={from:r,insert:t},a=i.state.changes(o?[o,l]:l);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(r,-1),head:a.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),i.inputState.draggedContent=null}At.drop=(i,e)=>{if(!e.dataTransfer)return!1;if(i.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let n=Array(t.length),r=0,s=()=>{++r==t.length&&up(i,e,n.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=s,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(n[o]=l.result),s()},l.readAsText(t[o])}return!0}else{let n=e.dataTransfer.getData("Text");if(n)return up(i,e,n,!0),!0}return!1};At.paste=(i,e)=>{if(i.state.readOnly)return!0;i.observer.flush();let t=vy?null:e.clipboardData;return t?(My(i,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Lv(i),!1)};function Hv(i,e){let t=i.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),i.focus()},50)}function Wv(i){let e=[],t=[],n=!1;for(let r of i.selection.ranges)r.empty||(e.push(i.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of i.selection.ranges){let o=i.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),r=o.number}n=!0}return{text:_l(i,nf,e.join(i.lineBreak)),ranges:t,linewise:n}}let sc=null;At.copy=At.cut=(i,e)=>{if(!ns(i.contentDOM,i.observer.selectionRange))return!1;let{text:t,ranges:n,linewise:r}=Wv(i.state);if(!t&&!r)return!1;sc=r?t:null,e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=vy?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(Hv(i,t),!1)};const Oy=mn.define();function Ty(i,e){let t=[];for(let n of i.facet(oy)){let r=n(i,e);r&&t.push(r)}return t.length?i.update({effects:t,annotations:Oy.of(!0)}):null}function Ny(i){setTimeout(()=>{let e=i.hasFocus;if(e!=i.inputState.notifiedFocused){let t=Ty(i.state,e);t?i.dispatch(t):i.update([])}},10)}Je.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),Ny(i)};Je.blur=i=>{i.observer.clearSelectionRange(),Ny(i)};Je.compositionstart=Je.compositionupdate=(i,e)=>{if(!i.observer.editContext&&(i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0)){let{main:t}=i.state.selection;!t.empty&&i.lineBlockAt(t.from).from!=i.lineBlockAt(t.to).from&&!i.state.readOnly&&i.dispatch({changes:i.state.selection.ranges.filter(n=>!n.empty).map(n=>({from:n.from,to:n.to})),userEvent:"input"}),i.inputState.composing=0}};Je.compositionend=i=>{i.observer.editContext||(i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionPendingKey=!0,i.inputState.compositionPendingChange=i.observer.pendingRecords().length>0,i.inputState.compositionFirstChange=null,N.chrome&&N.android?i.observer.flushSoon():i.inputState.compositionPendingChange?Promise.resolve().then(()=>i.observer.flush()):setTimeout(()=>{i.inputState.composing<0&&i.docView.hasComposition&&i.update([])},50))};Je.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};At.beforeinput=(i,e)=>{var t,n;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(i.inputState.insertingText=e.data,i.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&i.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let l=o[0],a=i.posAtDOM(l.startContainer,l.startOffset),h=i.posAtDOM(l.endContainer,l.endOffset);return lf(i,{from:a,to:h,insert:i.state.toText(s)},null),!0}}let r;if(N.chrome&&N.android&&(r=Sy.find(s=>s.inputType==e.inputType))&&(i.observer.delayAndroidKey(r.key,r.keyCode),r.key=="Backspace"||r.key=="Delete")){let s=((n=window.visualViewport)===null||n===void 0?void 0:n.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}return N.ios&&e.inputType=="deleteContentForward"&&i.observer.flushSoon(),N.safari&&e.inputType=="insertText"&&i.inputState.composing>=0&&setTimeout(()=>Je.compositionend(i,e),20),!1};const dp=new Set;function $v(i){dp.has(i)||(dp.add(i),i.addEventListener("copy",()=>{}),i.addEventListener("cut",()=>{}))}const pp=["pre-wrap","normal","pre-line","break-spaces"];let ur=!1;function mp(){ur=!1}class Kv{constructor(e){this.lineWrapping=e,this.doc=U.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return pp.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];r<0?n++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,n,r,s,o){let l=pp.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=s,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class qv{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Ct{constructor(e,t,n,r,s){this.from=e,this.length=t,this.top=n,this.height=r,this._content=s}get type(){return typeof this._content=="number"?Te.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ki?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Ct(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var se=(function(i){return i[i.ByPos=0]="ByPos",i[i.ByHeight=1]="ByHeight",i[i.ByPosNoHeight=2]="ByPosNoHeight",i})(se||(se={}));const Yo=.001;class $e{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Yo&&(ur=!0),this.height=e)}replace(e,t,n){return $e.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let s=this,o=n.doc;for(let l=r.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=r[l],u=s.lineAt(a,se.ByPosNoHeight,n.setDoc(t),0,0),d=u.to>=h?u:s.lineAt(h,se.ByPosNoHeight,n,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=r[l-1].toA;)a=r[l-1].fromA,c=r[l-1].fromB,l--,a<u.from&&(u=s.lineAt(a,se.ByPosNoHeight,n,0,0));c+=u.from-a,a=u.from;let p=af.build(n.setDoc(o),e,c,f);s=bl(s,s.replace(a,h,p))}return s.updateHeight(n,0)}static empty(){return new nt(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,n=e.length,r=0,s=0;for(;;)if(t==n)if(r>s*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),n+=1+l.break,r-=l.size}else if(s>r*2){let l=e[n];l.break?e.splice(n,1,l.left,null,l.right):e.splice(n,1,l.left,l.right),n+=2+l.break,s-=l.size}else break;else if(r<s){let l=e[t++];l&&(r+=l.size)}else{let l=e[--n];l&&(s+=l.size)}let o=!1;return e[t-1]==null?(o=!0,t--):e[t]==null&&(o=!0,n++),new Jv($e.of(e.slice(0,t)),o,$e.of(e.slice(n)))}}function bl(i,e){return i==e?i:(i.constructor!=e.constructor&&(ur=!0),e)}$e.prototype.size=1;const jv=J.replace({});class Dy extends $e{constructor(e,t,n){super(e,t),this.deco=n,this.spaceAbove=0}mainBlock(e,t){return new Ct(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,n,r){return this.spaceAbove&&e<n+this.spaceAbove?new Ct(r,0,n,this.spaceAbove,jv):this.mainBlock(n,r)}lineAt(e,t,n,r,s){let o=this.mainBlock(r,s);return this.spaceAbove?this.blockAt(0,n,r,s).join(o):o}forEachLine(e,t,n,r,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,se.ByPos,n,r,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}}class nt extends Dy{constructor(e,t,n){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=n}mainBlock(e,t){return new Ct(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,n){let r=n[0];return n.length==1&&(r instanceof nt||r instanceof Ce&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof Ce?r=new nt(r.length,this.height,this.spaceAbove):r.height=this.height,this.outdated||(r.outdated=!1),r):$e.of(n)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(n||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Ce extends $e{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*s);o=a/s,this.length>s+1&&(l=(this.height-a)/(this.length-s-1))}else o=this.height/s;return{firstLine:n,lastLine:r,perLine:o,perChar:l}}blockAt(e,t,n,r){let{firstLine:s,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let h=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length)),c=t.doc.lineAt(h),f=l+c.length*a,u=Math.max(n,e-f/2);return new Ct(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-s,Math.floor((e-n)/l))),{from:c,length:f}=t.doc.line(s+h);return new Ct(c,f,n+l*h,l,0)}}lineAt(e,t,n,r,s){if(t==se.ByHeight)return this.blockAt(e,n,r,s);if(t==se.ByPosNoHeight){let{from:d,to:p}=n.doc.lineAt(e);return new Ct(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(n,s),h=n.doc.lineAt(e),c=l+h.length*a,f=h.number-o,u=r+l*f+a*(h.from-s-f);return new Ct(h.from,h.length,Math.max(r,Math.min(u,r+this.height-c)),c,0)}forEachLine(e,t,n,r,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(n,s);for(let c=e,f=r;c<=t;){let u=n.doc.lineAt(c);if(c==e){let p=u.number-l;f+=a*p+h*(e-s-p)}let d=a+h*u.length;o(new Ct(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(e,t,n){let r=this.length-t;if(r>0){let s=n[n.length-1];s instanceof Ce?n[n.length-1]=new Ce(s.length+r):n.push(null,new Ce(r-1))}if(e>0){let s=n[0];s instanceof Ce?n[0]=new Ce(e+s.length):n.unshift(new Ce(e-1),null)}return $e.of(n)}decomposeLeft(e,t){t.push(new Ce(e-1),null)}decomposeRight(e,t){t.push(null,new Ce(this.length-e-1))}updateHeight(e,t=0,n=!1,r){let s=t+this.length;if(r&&r.from<=t+this.length&&r.more){let o=[],l=Math.max(t,r.from),a=-1;for(r.from>t&&o.push(new Ce(r.from-t-1).updateHeight(e,t));l<=s&&r.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=r.heights[r.index++],u=0;f<0&&(u=-f,f=r.heights[r.index++]),a==-1?a=f:Math.abs(f-a)>=Yo&&(a=-2);let d=new nt(c,f,u);d.outdated=!1,o.push(d),l+=c+1}l<=s&&o.push(null,new Ce(s-l).updateHeight(e,l));let h=$e.of(o);return(a<0||Math.abs(h.height-this.height)>=Yo||Math.abs(a-this.heightMetrics(e,t).perLine)>=Yo)&&(ur=!0),bl(this,h)}else(n||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Jv extends $e{constructor(e,t,n){super(e.length+(t?1:0)+n.length,e.height+n.height,(t?1:0)|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let s=n+this.left.height;return e<s?this.left.blockAt(e,t,n,r):this.right.blockAt(e,t,s,r+this.left.length+this.break)}lineAt(e,t,n,r,s){let o=r+this.left.height,l=s+this.left.length+this.break,a=t==se.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,n,r,s):this.right.lineAt(e,t,n,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==se.ByPosNoHeight?se.ByPosNoHeight:se.ByPos;return a?h.join(this.right.lineAt(l,c,n,o,l)):this.left.lineAt(l,c,n,r,s).join(h)}forEachLine(e,t,n,r,s,o){let l=r+this.left.height,a=s+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,n,r,s,o),t>=a&&this.right.forEachLine(e,t,n,l,a,o);else{let h=this.lineAt(a,se.ByPos,n,r,s);e<h.from&&this.left.forEachLine(e,Math.min(t,h.from-1),n,r,s,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(Math.max(e,h.to+1),t,n,l,a,o)}}replace(e,t,n){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of n)s.push(l);if(e>0&&gp(s,o-1),t<this.length){let l=s.length;this.decomposeRight(t,s),gp(s,l)}return $e.of(s)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?$e.of(this.break?[e,null,t]:[e,t]):(this.left=bl(this.left,e),this.right=bl(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,r){let{left:s,right:o}=this,l=t+s.length+this.break,a=null;return r&&r.from<=t+s.length&&r.more?a=s=s.updateHeight(e,t,n,r):s.updateHeight(e,t,n),r&&r.from<=l+o.length&&r.more?a=o=o.updateHeight(e,l,n,r):o.updateHeight(e,l,n),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function gp(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof Ce&&(n=i[e+1])instanceof Ce&&i.splice(e-1,3,new Ce(t.length+1+n.length))}const _v=5;class af{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let n=Math.min(t,this.lineEnd),r=this.nodes[this.nodes.length-1];r instanceof nt?r.length+=n-this.pos:(n>this.pos||!this.isCovered)&&this.nodes.push(new nt(n-this.pos,-1,0)),this.writtenTo=n,t>n&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let r=n.widget?n.widget.estimatedHeight:0,s=n.widget?n.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let o=t-e;n.block?this.addBlock(new Dy(o,r,n)):(o||s||r>=_v)&&this.addLineDeco(r,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new nt(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let n=new Ce(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof nt)return e;let t=new nt(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos=this.pos+n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof nt)&&!this.isCovered?this.nodes.push(new nt(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let r of this.nodes)r instanceof nt&&r.updateHeight(this.oracle,n),n+=r?r.length:1;return this.nodes}static build(e,t,n,r){let s=new af(n,e);return $.spans(t,n,r,s,0),s.finish(n)}}function Uv(i,e,t){let n=new Gv;return $.compare(i,e,t,n,0),n.changes}class Gv{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,r){(e<t||n&&n.heightRelevant||r&&r.heightRelevant)&&qi(e,t,this.changes,5)}}function Yv(i,e){let t=i.getBoundingClientRect(),n=i.ownerDocument,r=n.defaultView||window,s=Math.max(0,t.left),o=Math.min(r.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(r.innerHeight,t.bottom);for(let h=i.parentNode;h&&h!=n.body;)if(xe(h)){let c=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&c.overflow!="visible"){let f=h.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),a=Math.min(h==i.parentNode?r.innerHeight:a,f.bottom)}h=c.position=="absolute"||c.position=="fixed"?h.offsetParent:h.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function Xv(i){let e=i.getBoundingClientRect(),t=i.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function Qv(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class $a{constructor(e,t,n,r){this.from=e,this.to=t,this.size=n,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],s=t[n];if(r.from!=s.from||r.to!=s.to||r.size!=s.size)return!1}return!0}draw(e,t){return J.replace({widget:new Zv(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class Zv extends gn{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class yp{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=oc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Z.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let n=t.facet(rf).some(r=>typeof r!="function"&&r.class=="cm-lineWrapping");this.heightOracle=new Kv(n),this.stateDeco=bp(t),this.heightMap=$e.empty().applyChanges(this.stateDeco,U.empty,this.heightOracle.setDoc(t.doc),[new dt(0,0,0,t.doc.length)]);for(let r=0;r<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());r++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=J.set(this.lineGaps.map(r=>r.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:s,to:o})=>r>=s&&r<=o)){let{from:s,to:o}=this.lineBlockAt(r);e.push(new vo(s,o))}}return this.viewports=e.sort((n,r)=>n.from-r.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?oc:kl.get(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Wr(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=bp(this.state);let r=e.changedRanges,s=dt.extendWithRanges(r,Uv(n,this.stateDeco,e?e.changes:me.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);mp(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||ur)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(ay)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,s=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?Z.RTL:Z.LTR;let o=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:w,scaleY:M}=$0(t,l);(w>.005&&Math.abs(this.scaleX-w)>.005||M>.005&&Math.abs(this.scaleY-M)>.005)&&(this.scaleX=w,this.scaleY=M,h|=16,o=a=!0)}let f=(parseInt(n.paddingTop)||0)*this.scaleY,u=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=K0(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=_0(this.scrollParent||e.win);let m=(this.printing?Qv:Yv)(t,this.paddingTop),g=m.top-this.pixelViewport.top,y=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(a=!0)),!this.inView&&!this.scrollTarget&&!Xv(e.dom))return 0;let k=l.width;if((this.contentDOMWidth!=k||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let w=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(w)&&(o=!0),o||r.lineWrapping&&Math.abs(k-this.contentDOMWidth)>r.charWidth){let{lineHeight:M,charWidth:C,textHeight:I}=e.docView.measureTextSize();o=M>0&&r.refresh(s,M,C,I,Math.max(5,k/C),w),o&&(e.docView.minWidth=0,h|=16)}g>0&&y>0?c=Math.max(g,y):g<0&&y<0&&(c=Math.min(g,y)),mp();for(let M of this.viewports){let C=M.from==this.viewport.from?w:e.docView.measureVisibleLineHeights(M);this.heightMap=(o?$e.empty().applyChanges(this.stateDeco,U.empty,this.heightOracle,[new dt(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new qv(M.from,C))}ur&&(h|=2)}let O=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return O&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||O)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new vo(r.lineAt(o-n*1e3,se.ByHeight,s,0,0).from,r.lineAt(l+(1-n)*1e3,se.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=r.lineAt(h,se.ByPos,s,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new vo(r.lineAt(u-1e3/2,se.ByHeight,s,0,0).from,r.lineAt(u+c+1e3/2,se.ByHeight,s,0,0).to)}}return a}mapViewport(e,t){let n=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new vo(this.heightMap.lineAt(n,se.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,se.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,se.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,se.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||r<=o-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||s>=l+Math.max(10,Math.min(n,250)))&&r>o-2*1e3&&s<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let r of e)t.touchesRange(r.from,r.to)||n.push(new $a(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,r=n?1e4:2e3,s=r>>1,o=r<<1;if(this.defaultTextDirection!=Z.LTR&&!n)return[];let l=[],a=(c,f,u,d)=>{if(f-c<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>c&&y<f){a(c,y-10,u,d),a(y+10,f,u,d);return}let g=tM(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-c)<s&&Math.abs(y.to-f)<s&&!m.some(b=>y.from<b&&y.to>b));if(!g){if(f<u.to&&t&&n&&t.visibleRanges.some(k=>k.from<=f&&k.to>=f)){let k=t.moveToLineBoundary(S.cursor(f),!1,!0).head;k>c&&(f=k)}let y=this.gapSize(u,c,f,d),b=n||y<2e6?y:2e6;g=new $a(c,f,y,b)}l.push(g)},h=c=>{if(c.length<o||c.type!=Te.Text)return;let f=eM(c.from,c.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(n){let m=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(u!=null){let b=Ao(f,u),k=((this.visibleBottom-this.visibleTop)/2+m)/c.height;g=b-k,y=b+k}else g=(this.visibleTop-c.top-m)/c.height,y=(this.visibleBottom-c.top+m)/c.height;d=Mo(f,g),p=Mo(f,y)}else{let m=f.total*this.heightOracle.charWidth,g=r*this.heightOracle.charWidth,y=0;if(m>2e6)for(let M of e)M.from>=c.from&&M.from<c.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=M.size-M.displaySize);let b=this.pixelViewport.left+y,k=this.pixelViewport.right+y,O,w;if(u!=null){let M=Ao(f,u),C=((k-b)/2+g)/m;O=M-C,w=M+C}else O=(b-g)/m,w=(k+g)/m;d=Mo(f,O),p=Mo(f,w)}d>c.from&&a(c.from,d,c,f),p<c.to&&a(p,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(e,t,n,r){let s=Ao(r,n)-Ao(r,t);return this.heightOracle.lineWrapping?e.height*s:r.total*this.heightOracle.charWidth*s}updateLineGaps(e){$a.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=J.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];$.spans(t,this.viewport.from,this.viewport.to,{span(s,o){n.push({from:s,to:o})},point(){}},20);let r=0;if(n.length!=this.visibleRanges.length)r=12;else for(let s=0;s<n.length&&!(r&8);s++){let o=this.visibleRanges[s],l=n[s];(o.from!=l.from||o.to!=l.to)&&(r|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(r|=8))}return this.visibleRanges=n,r}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Wr(this.heightMap.lineAt(e,se.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Wr(this.heightMap.lineAt(this.scaler.fromDOM(e),se.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+12-this.paddingTop);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Wr(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class vo{constructor(e,t){this.from=e,this.to=t}}function eM(i,e,t){let n=[],r=i,s=0;return $.spans(t,i,e,{span(){},point(o,l){o>r&&(n.push({from:r,to:o}),s+=o-r),r=l}},20),r<e&&(n.push({from:r,to:e}),s+=e-r),{total:s,ranges:n}}function Mo({total:i,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let n=Math.floor(i*t);for(let r=0;;r++){let{from:s,to:o}=e[r],l=o-s;if(n<=l)return s+n;n-=l}}function Ao(i,e){let t=0;for(let{from:n,to:r}of i.ranges){if(e<=r){t+=e-n;break}t+=r-n}return t/i.total}function tM(i,e){for(let t of i)if(e(t))return t}const oc={toDOM(i){return i},fromDOM(i){return i},scale:1,eq(i){return i==this}};function bp(i){let e=i.facet(ql).filter(n=>typeof n!="function"),t=i.facet(sf).filter(n=>typeof n!="function");return t.length&&e.push($.join(t)),e}class kl{constructor(e,t){this.scale=e,this.viewports=t}static get(e,t,n){let r=0,s=0,o=0,l=n.map(({from:h,to:c})=>{let f=t.lineAt(h,se.ByPos,e,0,0).top,u=t.lineAt(c,se.ByPos,e,0,0).bottom;return r+=u-f,{from:h,to:c,top:f,bottom:u,domTop:0,domBottom:0}});if(t.height-r<10)return oc;let a=(7e6-r)/(t.height-r);for(let h of l)h.domTop=o+(h.top-s)*a,o=h.domBottom=h.domTop+(h.bottom-h.top),s=h.bottom;return new kl(a,l)}toDOM(e){for(let t=0,n=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return r+(e-n)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);n=s.bottom,r=s.domBottom}}fromDOM(e){for(let t=0,n=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return n+(e-r)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);n=s.bottom,r=s.domBottom}}eq(e){return e instanceof kl?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,n)=>t.from==e.viewports[n].from&&t.to==e.viewports[n].to):!1}}function Wr(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new Ct(i.from,i.length,t,n-t,Array.isArray(i._content)?i._content.map(r=>Wr(r,e)):i._content)}const Oo=D.define({combine:i=>i.join(" ")}),lc=D.define({combine:i=>i.indexOf(!0)>-1}),ac=Hn.newName(),Iy=Hn.newName(),Ey=Hn.newName(),Ry={"&light":"."+Iy,"&dark":"."+Ey};function hc(i,e,t){return new Hn(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,r=>{if(r=="&")return i;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):i+" "+n}})}const nM=hc("."+ac,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"baseline",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Ry),iM={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ka=N.ie&&N.ie_version<=11;class rM{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new RC,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let n of t)this.queue.push(n);(N.ie&&N.ie_version<=11||N.ios&&e.composing)&&t.some(n=>n.type=="childList"&&n.removedNodes.length||n.type=="characterData"&&n.oldValue.length>n.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&N.android&&e.constructor.EDIT_CONTEXT!==!1&&!(N.chrome&&N.chrome_version<126)&&(this.editContext=new oM(e),e.state.facet(en)&&(e.contentDOM.editContext=this.editContext.editContext)),Ka&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(this.pendingRecords().length>0),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(en)?n.root.activeElement!=this.dom:!ns(this.dom,r))return;let s=r.anchorNode&&n.docView.tile.nearest(r.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(N.ie&&N.ie_version<=11||N.android&&N.chrome)&&!n.state.selection.main.empty&&r.focusNode&&is(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Os(e.root);if(!t)return!1;let n=N.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&sM(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=ns(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&PC(this.dom,n)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(n),r&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(xe(n))!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);for(let n of this.scrollTargets=t)n.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,iM),Ka&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ka&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var n;if(!this.delayedAndroidKey){let r=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&ji(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((n=this.delayedAndroidKey)===null||n===void 0)&&n.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!0),t==-1?{from:t,to:n}=o:(t=Math.min(o.from,t),n=Math.max(o.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&ns(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Sv(this.view,e,t,n);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.selectionChanged,n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,s=xy(this.view,n);return this.view.state==r&&(n.domChanged||t)&&this.view.update([]),s}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let n=kp(t,e.previousSibling||e.target.previousSibling,-1),r=kp(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(en)!=e.state.facet(en)&&(e.view.contentDOM.editContext=e.state.facet(en)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resizeScroll)===null||n===void 0||n.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function kp(i,e,t){for(;e;){let n=he.get(e);if(n&&n.parent==i)return n;let r=e.parentNode;e=r!=i.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function xp(i,e){let t=e.startContainer,n=e.startOffset,r=e.endContainer,s=e.endOffset,o=i.docView.domAtPos(i.state.selection.main.anchor,1);return is(o.node,o.offset,r,s)&&([t,n,r,s]=[r,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}}function sM(i,e){if(e.getComposedRanges){let r=e.getComposedRanges(i.root)[0];if(r)return xp(i,r)}let t=null;function n(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return i.contentDOM.addEventListener("beforeinput",n,!0),i.dom.ownerDocument.execCommand("indent"),i.contentDOM.removeEventListener("beforeinput",n,!0),t?xp(i,t):null}class oM{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let r=e.state.selection.main,{anchor:s,head:o}=r,l=this.toEditorPos(n.updateRangeStart),a=this.toEditorPos(n.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:n.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>n.text.length;l==this.from&&s<this.from?l=s:a==this.to&&s>this.to&&(a=s);let c=wy(e.state.sliceDoc(l,a),n.text,(h?r.from:r.to)-l,h?"end":null);if(!c){let u=S.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd));rc(u,r)||e.dispatch({selection:u,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:U.of(n.text.slice(c.from,c.toB).split(`
|
|
21
|
+
`))};if((N.mac||N.android)&&f.from==o-1&&/^\. ?$/.test(n.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:U.of([n.text.replace("."," ")])}),this.pendingContextChange=f,!e.state.readOnly){let u=this.to-this.from+(f.to-f.from+f.insert.length);lf(e,f,S.single(this.toEditorPos(n.selectionStart,u),this.toEditorPos(n.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),f.from<f.to&&!f.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,n.updateRangeStart-1),Math.min(t.text.length,n.updateRangeStart+1)))&&this.handlers.compositionend(n)},this.handlers.characterboundsupdate=n=>{let r=[],s=null;for(let o=this.toEditorPos(n.rangeStart),l=this.toEditorPos(n.rangeEnd);o<l;o++){let a=e.coordsForChar(o);s=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||s||new DOMRect,r.push(s)}t.updateCharacterBounds(n.rangeStart,r)},this.handlers.textformatupdate=n=>{let r=[];for(let s of n.getTextFormats()){let o=s.underlineStyle,l=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(s.rangeStart),h=this.toEditorPos(s.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;r.push(J.mark({attributes:{style:c}}).range(a,h))}}}e.dispatch({effects:cy.of(J.set(r))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:n}=this.composing;this.composing=null,n&&this.reset(e.state)}};for(let n in this.handlers)t.addEventListener(n,this.handlers[n]);this.measureReq={read:n=>{let r=Os(n.root);r&&r.rangeCount&&this.editContext.updateSelectionBounds(r.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((s,o,l,a,h)=>{if(n)return;let c=h.length-(o-s);if(r&&o>=r.to)if(r.from==s&&r.to==o&&r.insert.eq(h)){r=this.pendingContextChange=null,t+=c,this.to+=c;return}else r=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+h.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(r=>!r.isUserEvent("input.type")&&r.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class R{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:n}=e;this.dispatchTransactions=e.dispatchTransactions||n&&(r=>r.forEach(s=>n(s,this)))||(r=>this.update(r)),this.dispatch=this.dispatch.bind(this),this._root=e.root||BC(e.parent)||document,this.viewState=new yp(this,e.state||Y.create(e)),e.scrollTo&&e.scrollTo.is(wo)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Fi).map(r=>new Fa(r));for(let r of this.plugins)r.update(this);this.observer=new rM(this),this.inputState=new Av(this),this.inputState.ensureHandlers(this.plugins),this.docView=new rp(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof pe?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,n=!1,r,s=this.state;for(let u of e){if(u.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=u.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(Oy))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Ty(s,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(Y.phrases)!=this.state.facet(Y.phrases))return this.setState(s);r=ml.create(this,s,e),r.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:m}=this.state.facet(R.cursorScrollMargin);f=new Ji(d.empty?d:S.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of u.effects)d.is(wo)&&(f=d.value.clip(this.state))}this.viewState.update(r,f),this.bidiCache=xl.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(Hr)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(Oo)!=r.state.facet(Oo)&&(this.viewState.mustMeasureContent=!0),(t||n||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let u of this.state.facet(ec))try{u(r)}catch(d){Qe(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!xy(this,c)&&h.force&&ji(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let n of this.plugins)n.destroy(this);this.viewState=new yp(this,e),this.plugins=e.facet(Fi).map(n=>new Fa(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView.destroy(),this.docView=new rp(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Fi),n=e.state.facet(Fi);if(t!=n){let r=[];for(let s of n){let o=t.indexOf(s);if(o<0)r.push(new Fa(s));else{let l=this.plugins[o];l.mustUpdate=e,r.push(l)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r<this.plugins.length;r++)this.plugins[r].update(this);t!=n&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(n){Qe(this.state,n,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.viewState.scrollParent,r=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:o,scaleY:l}=this.viewState;Math.abs(r-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0){if(_0(n||this.win))s=-1,o=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(r);s=p.from,o=p.top}l=this.viewState.scaleY}this.updateState=1;let h=this.viewState.measure();if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];h&4||([this.measureRequests,c]=[c,this.measureRequests]);let f=c.map(p=>{try{return p.read(this)}catch(m){return Qe(this.state,m),wp}}),u=ml.create(this,this.state,[]),d=!1;u.flags|=h,t?t.flags|=h:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),d=this.docView.update(u),d&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(f[p]!=wp)try{let m=c[p];m.write&&m.write(f[p],this)}catch(m){Qe(this.state,m)}if(d&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-o/l;if((m>1||m<-1)&&!(N.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(n==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){r=r+m,n?s<0?n.scrollTop=n.scrollHeight:n.scrollTop+=m:this.win.scrollBy(0,m),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let a of this.state.facet(ec))a(t)}get themeClasses(){return ac+" "+(this.state.facet(lc)?Ey:Iy)+" "+this.state.facet(Oo)}updateAttrs(){let e=Sp(this,fy,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(en)?"true":"false",class:"cm-content",style:`${N.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Sp(this,rf,t);let n=this.observer.ignore(()=>{let r=Qd(this.contentDOM,this.contentAttrs,t),s=Qd(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let r of n.effects)if(r.is(R.announce)){t&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent=" "},200),t=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(Hr);let e=this.state.facet(R.cspNonce);Hn.mount(this.root,this.styleModules.concat(nM).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(n=>n.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return Wa(this,e,sp(this,e,t,n))}moveByGroup(e,t){return Wa(this,e,sp(this,e,t,n=>gv(this,e.head,n)))}visualLineSide(e,t){return t?S.cursor(e.to,1):S.cursor(e.from,-1)}moveToLineBoundary(e,t,n=!0){return mv(this,e,t,n)}moveVertically(e,t,n){return Wa(this,e,yv(this,e,t,n))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let n=ic(this,e,t);return n&&n.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),ic(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),s=r[$t.find(r,e-n.from,-1,t)];return n.length&&(e==n.from&&t<0||e==n.to&&t>0)&&s.dir!=this.textDirectionAt(n.from)&&(e==n.to?(e=n.from+s.from,t=1):(e=n.from+s.to,t=-1)),this.docView.coordsAt(e,t,s.dir==Z.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(ly)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>lM)return Z0(e.length);let t=this.textDirectionAt(e.from),n;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||Q0(s.isolates,n=tp(this,e))))return s.order;n||(n=tp(this,e));let r=$C(e.text,t,n);return this.bidiCache.push(new xl(e.from,e.to,t,n,!0,r)),r}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||N.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{J0(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var n,r,s,o;return wo.of(new Ji(typeof e=="number"?S.cursor(e):e,(n=t.y)!==null&&n!==void 0?n:"nearest",(r=t.x)!==null&&r!==void 0?r:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return wo.of(new Ji(S.cursor(n.from),"start","start",n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return be.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return be.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=Hn.newName(),r=[Oo.of(n),Hr.of(hc(`.${n}`,e))];return t&&t.dark&&r.push(lc.of(!0)),r}static baseTheme(e){return vi.lowest(Hr.of(hc("."+ac,e,Ry)))}static findFromDOM(e){var t;let n=e.querySelector(".cm-content"),r=n&&he.get(n)||he.get(e);return((t=r?.root)===null||t===void 0?void 0:t.view)||null}}R.styleModule=Hr;R.inputHandler=sy;R.clipboardInputFilter=tf;R.clipboardOutputFilter=nf;R.scrollHandler=hy;R.focusChangeEffect=oy;R.perLineTextDirection=ly;R.exceptionSink=ry;R.updateListener=ec;R.editable=en;R.mouseSelectionStyle=iy;R.dragMovesSelection=ny;R.clickAddsSelectionRange=ty;R.decorations=ql;R.blockWrappers=uy;R.outerDecorations=sf;R.atomicRanges=to;R.bidiIsolatedRanges=dy;R.cursorScrollMargin=D.define({combine:i=>{let e=5,t=5;for(let n of i)typeof n=="number"?e=t=n:{x:e,y:t}=n;return{x:e,y:t}}});R.scrollMargins=my;R.darkTheme=lc;R.cspNonce=D.define({combine:i=>i.length?i[0]:""});R.contentAttributes=rf;R.editorAttributes=fy;R.lineWrapping=R.contentAttributes.of({class:"cm-lineWrapping"});R.announce=z.define();const lM=4096,wp={};class xl{constructor(e,t,n,r,s,o){this.from=e,this.to=t,this.dir=n,this.isolates=r,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let n=[],r=e.length?e[e.length-1].dir:Z.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==r&&!t.touchesRange(o.from,o.to)&&n.push(new xl(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return n}}function Sp(i,e,t){for(let n=i.state.facet(e),r=n.length-1;r>=0;r--){let s=n[r],o=typeof s=="function"?s(i):s;o&&Qc(o,t)}return t}const aM=N.mac?"mac":N.windows?"win":N.linux?"linux":"key";function hM(i,e){const t=i.split(/-(?!$)/);let n=t[t.length-1];n=="Space"&&(n=" ");let r,s,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))r=!0;else if(/^(c|ctrl|control)$/i.test(h))s=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:s=!0;else throw new Error("Unrecognized modifier name: "+h)}return r&&(n="Alt-"+n),s&&(n="Ctrl-"+n),l&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function To(i,e,t){return e.altKey&&(i="Alt-"+i),e.ctrlKey&&(i="Ctrl-"+i),e.metaKey&&(i="Meta-"+i),t!==!1&&e.shiftKey&&(i="Shift-"+i),i}const cM=vi.default(R.domEventHandlers({keydown(i,e){return Py(By(e.state),i,e,"editor")}})),hf=D.define({enables:cM}),Cp=new WeakMap;function By(i){let e=i.facet(hf),t=Cp.get(e);return t||Cp.set(e,t=uM(e.reduce((n,r)=>n.concat(r),[]))),t}function wD(i,e,t){return Py(By(i.state),e,i,t)}let Mn=null;const fM=4e3;function uM(i,e=aM){let t=Object.create(null),n=Object.create(null),r=(o,l)=>{let a=n[o];if(a==null)n[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,l,a,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>hM(y,e));for(let y=1;y<p.length;y++){let b=p.slice(0,y).join(" ");r(b,!0),d[b]||(d[b]={preventDefault:!0,stopPropagation:!1,run:[k=>{let O=Mn={view:k,prefix:b,scope:o};return setTimeout(()=>{Mn==O&&(Mn=null)},fM),!0}]})}let m=p.join(" ");r(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of i){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in c)c[u].run.push(d=>f(d,cc))}let a=o[e]||o.key;if(a)for(let h of l)s(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let cc=null;function Py(i,e,t,n){cc=e;let r=ug(e),s=it(r,0),o=Zt(s)==r.length&&r!=" ",l="",a=!1,h=!1,c=!1;Mn&&Mn.view==t&&Mn.scope==n&&(l=Mn.prefix+" ",Cy.indexOf(e.keyCode)<0&&(h=!0,Mn=null));let f=new Set,u=g=>{if(g){for(let y of g.run)if(!f.has(y)&&(f.add(y),y(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),h=!0)}return!1},d=i[n],p,m;return d&&(u(d[l+To(r,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(N.windows&&e.ctrlKey&&e.altKey)&&!(N.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=hn[e.keyCode])&&p!=r?(u(d[l+To(p,e,!0)])||e.shiftKey&&(m=ds[e.keyCode])!=r&&m!=p&&u(d[l+To(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+To(r,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),cc=null,a}class ci{constructor(e,t,n,r,s){this.className=e,this.left=t,this.top=n,this.width=r,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,n){if(n.empty){let r=e.coordsAtPos(n.head,n.assoc||1);if(!r)return[];let s=Ly(e);return[new ci(t,r.left-s.left,r.top-s.top,null,r.bottom-r.top)]}else return dM(e,t,n)}}function Ly(i){let e=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==Z.LTR?e.left:e.right-i.scrollDOM.clientWidth*i.scaleX)-i.scrollDOM.scrollLeft*i.scaleX,top:e.top-i.scrollDOM.scrollTop*i.scaleY}}function vp(i,e,t,n){let r=i.coordsAtPos(e,t*2);if(!r)return n;let s=i.dom.getBoundingClientRect(),o=(r.top+r.bottom)/2,l=i.posAtCoords({x:s.left+1,y:o}),a=i.posAtCoords({x:s.right-1,y:o});return l==null||a==null?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}function dM(i,e,t){if(t.to<=i.viewport.from||t.from>=i.viewport.to)return[];let n=Math.max(t.from,i.viewport.from),r=Math.min(t.to,i.viewport.to),s=i.textDirection==Z.LTR,o=i.contentDOM,l=o.getBoundingClientRect(),a=Ly(i),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),d=nc(i,n,1),p=nc(i,r,-1),m=d.type==Te.Text?d:null,g=p.type==Te.Text?p:null;if(m&&(i.lineWrapping||d.widgetLineBreaks)&&(m=vp(i,n,1,m)),g&&(i.lineWrapping||p.widgetLineBreaks)&&(g=vp(i,r,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return b(k(t.from,t.to,m));{let w=m?k(t.from,null,m):O(d,!1),M=g?k(null,t.to,g):O(p,!0),C=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&w.bottom+i.defaultLineHeight/2<M.top?C.push(y(f,w.bottom,u,M.top)):w.bottom<M.top&&i.elementAtHeight((w.bottom+M.top)/2).type==Te.Text&&(w.bottom=M.top=(w.bottom+M.top)/2),b(w).concat(C).concat(b(M))}function y(w,M,C,I){return new ci(e,w-a.left,M-a.top,Math.max(0,C-w),I-M)}function b({top:w,bottom:M,horizontal:C}){let I=[];for(let P=0;P<C.length;P+=2)I.push(y(C[P],w,C[P+1],M));return I}function k(w,M,C){let I=1e9,P=-1e9,te=[];function W(G,oe,Ve,tt,Et){let we=i.coordsAtPos(G,G==C.to?-2:2),lt=i.coordsAtPos(Ve,Ve==C.from?2:-2);!we||!lt||(I=Math.min(we.top,lt.top,I),P=Math.max(we.bottom,lt.bottom,P),Et==Z.LTR?te.push(s&&oe?f:we.left,s&&tt?u:lt.right):te.push(!s&&tt?f:lt.left,!s&&oe?u:we.right))}let L=w??C.from,X=M??C.to;for(let G of i.visibleRanges)if(G.to>L&&G.from<X)for(let oe=Math.max(G.from,L),Ve=Math.min(G.to,X);;){let tt=i.state.doc.lineAt(oe);for(let Et of i.bidiSpans(tt)){let we=Et.from+tt.from,lt=Et.to+tt.from;if(we>=Ve)break;lt>oe&&W(Math.max(we,oe),w==null&&we<=L,Math.min(lt,Ve),M==null&<>=X,Et.dir)}if(oe=tt.to+1,oe>=Ve)break}return te.length==0&&W(L,w==null,X,M==null,i.textDirection),{top:I,bottom:P,horizontal:te}}function O(w,M){let C=l.top+(M?w.top:w.bottom);return{top:C,bottom:C,horizontal:[]}}}function pM(i,e){return i.constructor==e.constructor&&i.eq(e)}class mM{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Xo)!=e.state.facet(Xo)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(Xo);for(;t<n.length&&n[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,n)=>!pM(t,this.drawn[n]))){let t=this.dom.firstChild,n=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[n].constructor&&r.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(r.draw(),t);for(;t;){let r=t.nextSibling;t.remove(),t=r}this.drawn=e,N.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Xo=D.define();function Fy(i){return[be.define(e=>new mM(e,i)),Xo.of(i)]}const fc=!N.ios,dr=D.define({combine(i){return Mi(i,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function SD(i={}){return[dr.of(i),gM,yM,kM,ay.of(!0)]}function Vy(i){return i.startState.facet(dr)!=i.state.facet(dr)}const gM=Fy({above:!0,markers(i){let{state:e}=i,t=e.facet(dr),n=[];for(let r of e.selection.ranges){let s=r==e.selection.main;if(r.empty||t.drawRangeCursor&&!(s&&N.ios&&t.iosSelectionHandles)){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=r.empty?r:S.cursor(r.head,r.assoc);for(let a of ci.forRange(i,o,l))n.push(a)}}return n},update(i,e){i.transactions.some(n=>n.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Vy(i);return t&&Mp(i.state,e),i.docChanged||i.selectionSet||t},mount(i,e){Mp(e.state,i)},class:"cm-cursorLayer"});function Mp(i,e){e.style.animationDuration=i.facet(dr).cursorBlinkRate+"ms"}const yM=Fy({above:!1,markers(i){let e=[],{main:t,ranges:n}=i.state.selection;for(let r of n)if(!r.empty&&(fc||r!=t))for(let s of ci.forRange(i,"cm-selectionBackground",r))e.push(s);if(N.ios&&!t.empty&&i.state.facet(dr).iosSelectionHandles){for(let r of ci.forRange(i,"cm-selectionHandle cm-selectionHandle-start",S.cursor(t.from,1)))e.push(r);for(let r of ci.forRange(i,"cm-selectionHandle cm-selectionHandle-end",S.cursor(t.to,1)))e.push(r)}return e},update(i,e){return i.docChanged||i.selectionSet||i.viewportChanged||Vy(i)},class:"cm-selectionLayer"}),bM=N.gecko&&N.gecko_version==153?"#ffffff01":"transparent",kM=vi.highest(R.theme({".cm-line":{...fc?{"& ::selection, &::selection":{backgroundColor:`${bM} !important`}}:{},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important",...fc?{"&::selection, & ::selection":{backgroundColor:"Highlight !important"}}:{}}}})),zy=z.define({map(i,e){return i==null?null:e.mapPos(i)}}),$r=Ge.define({create(){return null},update(i,e){return i!=null&&(i=e.changes.mapPos(i)),e.effects.reduce((t,n)=>n.is(zy)?n.value:t,i)}}),xM=be.fromClass(class{constructor(i){this.view=i,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(i){var e;let t=i.state.field($r);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(i.startState.field($r)!=t||i.docChanged||i.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:i}=this,e=i.state.field($r),t=e!=null&&i.coordsAtPos(e);if(!t)return null;let n=i.scrollDOM.getBoundingClientRect();return{left:t.left-n.left+i.scrollDOM.scrollLeft*i.scaleX,top:t.top-n.top+i.scrollDOM.scrollTop*i.scaleY,height:t.bottom-t.top}}drawCursor(i){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;i?(this.cursor.style.left=i.left/e+"px",this.cursor.style.top=i.top/t+"px",this.cursor.style.height=i.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(i){this.view.state.field($r)!=i&&this.view.dispatch({effects:zy.of(i)})}},{eventObservers:{dragover(i){this.setDropPos(this.view.posAtCoords({x:i.clientX,y:i.clientY}))},dragleave(i){(i.target==this.view.contentDOM||!this.view.contentDOM.contains(i.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function CD(){return[$r,xM]}function Ap(i,e,t,n,r){e.lastIndex=0;for(let s=i.iterRange(t,n),o=t,l;!s.next().done;o+=s.value.length)if(!s.lineBreak)for(;l=e.exec(s.value);)r(o+l.index,l)}function wM(i,e){let t=i.visibleRanges;if(t.length==1&&t[0].from==i.viewport.from&&t[0].to==i.viewport.to)return t;let n=[];for(let{from:r,to:s}of t)r=Math.max(i.state.doc.lineAt(r).from,r-e),s=Math.min(i.state.doc.lineAt(s).to,s+e),n.length&&n[n.length-1].to>=r?n[n.length-1].to=s:n.push({from:r,to:s});return n}class SM{constructor(e){const{regexp:t,decoration:n,decorate:r,boundary:s,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,r)this.addMatch=(l,a,h,c)=>r(c,h,h+l[0].length,l,a);else if(typeof n=="function")this.addMatch=(l,a,h,c)=>{let f=n(l,a,h);f&&c(h,h+l[0].length,f)};else if(n)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,n);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=s,this.maxLength=o}createDeco(e){let t=new Bn,n=t.add.bind(t);for(let{from:r,to:s}of wM(e,this.maxLength))Ap(e.state.doc,this.regexp,r,s,(o,l)=>this.addMatch(l,e,o,n));return t.finish()}updateDeco(e,t){let n=1e9,r=-1;return e.docChanged&&e.changes.iterChanges((s,o,l,a)=>{a>=e.view.viewport.from&&l<=e.view.viewport.to&&(n=Math.min(l,n),r=Math.max(a,r))}),e.viewportMoved||r-n>1e3?this.createDeco(e.view):r>-1?this.updateRange(e.view,t.map(e.changes),n,r):t}updateRange(e,t,n,r){for(let s of e.visibleRanges){let o=Math.max(s.from,n),l=Math.min(s.to,r);if(l>=o){let a=e.state.doc.lineAt(o),h=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(s.from,a.from),f=Math.min(s.to,h.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let u=[],d,p=(m,g,y)=>u.push(y.range(m,g));if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else Ap(e.state.doc,this.regexp,c,f,(m,g)=>this.addMatch(g,e,m,p));t=t.update({filterFrom:c,filterTo:f,filter:(m,g)=>m<c||g>f,add:u})}}return t}}const uc=/x/.unicode!=null?"gu":"g",CM=new RegExp(`[\0-\b
|
|
22
|
+
--\u2028\u2029\uFEFF-]`,uc),vM={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let qa=null;function MM(){var i;if(qa==null&&typeof document<"u"&&document.body){let e=document.body.style;qa=((i=e.tabSize)!==null&&i!==void 0?i:e.MozTabSize)!=null}return qa||!1}const Qo=D.define({combine(i){let e=Mi(i,{render:null,specialChars:CM,addSpecialChars:null});return(e.replaceTabs=!MM())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,uc)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,uc)),e}});function vD(i={}){return[Qo.of(i),AM()]}let Op=null;function AM(){return Op||(Op=be.fromClass(class{constructor(i){this.view=i,this.decorations=J.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(i.state.facet(Qo)),this.decorations=this.decorator.createDeco(i)}makeDecorator(i){return new SM({regexp:i.specialChars,decoration:(e,t,n)=>{let{doc:r}=t.state,s=it(e[0],0);if(s==9){let o=r.lineAt(n),l=t.state.tabSize,a=xr(o.text,l,n-o.from);return J.replace({widget:new DM((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[s]||(this.decorationCache[s]=J.replace({widget:new NM(i,s)}))},boundary:i.replaceTabs?void 0:/[^]/})}update(i){let e=i.state.facet(Qo);i.startState.facet(Qo)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(i.view)):this.decorations=this.decorator.updateDeco(i,this.decorations)}},{decorations:i=>i.decorations}))}const OM="•";function TM(i){return i>=32?OM:i==10?"":String.fromCharCode(9216+i)}class NM extends gn{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=TM(this.code),n=e.state.phrase("Control character")+" "+(vM[this.code]||"0x"+this.code.toString(16)),r=this.options.render&&this.options.render(this.code,n,t);if(r)return r;let s=document.createElement("span");return s.textContent=t,s.title=n,s.setAttribute("aria-label",n),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class DM extends gn{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function MD(){return EM}const IM=J.line({class:"cm-activeLine"}),EM=be.fromClass(class{constructor(i){this.decorations=this.getDeco(i)}update(i){(i.docChanged||i.selectionSet)&&(this.decorations=this.getDeco(i.view))}getDeco(i){let e=-1,t=[];for(let n of i.state.selection.ranges){let r=i.lineBlockAt(n.head);r.from>e&&(t.push(IM.range(r.from)),e=r.from)}return J.set(t)}},{decorations:i=>i.decorations}),dc=2e3;function RM(i,e,t){let n=Math.min(e.line,t.line),r=Math.max(e.line,t.line),s=[];if(e.off>dc||t.off>dc||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=n;a<=r;a++){let h=i.doc.line(a);h.length<=l&&s.push(S.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=n;a<=r;a++){let h=i.doc.line(a),c=Kh(h.text,o,i.tabSize,!0);if(c<0)s.push(S.cursor(h.to));else{let f=Kh(h.text,l,i.tabSize);s.push(S.range(h.from+c,h.from+f))}}}return s}function BM(i,e){let t=i.coordsAtPos(i.viewport.from);return t?Math.round(Math.abs((t.left-e)/i.defaultCharacterWidth)):-1}function Tp(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1),n=i.state.doc.lineAt(t),r=t-n.from,s=r>dc?-1:r==n.length?BM(i,e.clientX):xr(n.text,i.state.tabSize,t-n.from);return{line:n.number,col:s,off:r}}function PM(i,e){let t=Tp(i,e),n=i.state.selection;return t?{update(r){if(r.docChanged){let s=r.changes.mapPos(r.startState.doc.line(t.line).from),o=r.state.doc.lineAt(s);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},n=n.map(r.changes)}},get(r,s,o){let l=Tp(i,r);if(!l)return n;let a=RM(i.state,t,l);return a.length?o?S.create(a.concat(n.ranges)):S.create(a):n}}:null}function AD(i){let e=(t=>t.altKey&&t.button==0);return R.mouseSelectionStyle.of((t,n)=>e(n)?PM(t,n):null)}const LM={Alt:[18,i=>!!i.altKey],Control:[17,i=>!!i.ctrlKey],Shift:[16,i=>!!i.shiftKey],Meta:[91,i=>!!i.metaKey]},FM={style:"cursor: crosshair"};function OD(i={}){let[e,t]=LM[i.key||"Alt"],n=be.fromClass(class{constructor(r){this.view=r,this.isDown=!1}set(r){this.isDown!=r&&(this.isDown=r,this.view.update([]))}},{eventObservers:{keydown(r){this.set(r.keyCode==e||t(r))},keyup(r){(r.keyCode==e||!t(r))&&this.set(!1)},mousemove(r){this.set(t(r))}}});return[n,R.contentAttributes.of(r=>{var s;return!((s=r.plugin(n))===null||s===void 0)&&s.isDown?FM:null})]}const No="-10000px";class Hy{constructor(e,t,n,r){this.facet=t,this.createTooltipView=n,this.removeTooltipView=r,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let s=null;this.tooltipViews=this.tooltips.map(o=>s=n(o,s))}update(e,t){var n;let r=e.state.facet(this.facet),s=r.filter(a=>a);if(r===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<s.length;a++){let h=s[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==h.create&&(c=f)}if(c<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let f=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(n=a.destroy)===null||n===void 0||n.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=r,this.tooltips=s,this.tooltipViews=o,!0}}function Wy(i){let e=i.dom.ownerDocument.documentElement,t=e.clientWidth,n=getComputedStyle(e);if(!/stable/.test(n.scrollbarGutter||""))return{left:0,right:t};let r=e.getBoundingClientRect(),s=i.win.scrollX;return{left:Math.max(0,r.left+s-parseFloat(n.marginLeft)),right:Math.min(t,r.right+s+parseFloat(n.marginRight))}}function VM(i){let{left:e,right:t}=Wy(i);return{top:0,left:e,right:t,bottom:i.dom.ownerDocument.documentElement.clientHeight}}const ja=D.define({combine:i=>{var e,t,n;return{position:N.ios?"absolute":((e=i.find(r=>r.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=i.find(r=>r.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((n=i.find(r=>r.tooltipSpace))===null||n===void 0?void 0:n.tooltipSpace)||VM}}}),Np=new WeakMap,cf=be.fromClass(class{constructor(i){this.view=i,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=i.state.facet(ja);this.position=e.position,this.parent=e.parent,this.classes=i.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Hy(i,ff,(t,n)=>this.createTooltip(t,n),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),i.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let i of this.manager.tooltipViews)this.intersectionObserver.observe(i.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(i){i.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(i,this.above);e&&this.observeIntersection();let t=e||i.geometryChanged,n=i.state.facet(ja);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let r of this.manager.tooltipViews)r.dom.style.position=this.position;t=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let r of this.manager.tooltipViews)this.container.appendChild(r.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(i,e){let t=i.create(this.view),n=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),i.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let r=document.createElement("div");r.className="cm-tooltip-arrow",t.dom.appendChild(r)}return t.dom.style.position=this.position,t.dom.style.top=No,t.dom.style.left="0px",this.container.insertBefore(t.dom,n),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var i,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let n of this.manager.tooltipViews)n.dom.remove(),(i=n.destroy)===null||i===void 0||i.call(n);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let i=1,e=1,t=!1,n=0;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:o}=this.manager.tooltipViews[0];if(N.safari){let l=o.getBoundingClientRect();t=Math.abs(l.top+1e4)>1||Math.abs(l.left)>1}else t=!!o.offsetParent&&o.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let o=this.parent.getBoundingClientRect();o.width&&o.height&&(i=o.width/this.parent.offsetWidth,e=o.height/this.parent.offsetHeight)}else({scaleX:i,scaleY:e}=this.view.viewState);else n=Wy(this.view).left;let r=this.view.scrollDOM.getBoundingClientRect(),s=of(this.view);return{visible:{left:r.left+s.left,top:r.top+s.top,right:r.right-s.right,bottom:r.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((o,l)=>{let a=this.manager.tooltipViews[l];return a.getCoords?a.getCoords(o.pos):this.view.coordsAtPos(o.pos)}),size:this.manager.tooltipViews.map(({dom:o})=>o.getBoundingClientRect()),space:this.view.state.facet(ja).tooltipSpace(this.view),scaleX:i,scaleY:e,makeAbsolute:t,fixedLeft:n}}writeMeasure(i){var e;if(i.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:n,scaleX:r,scaleY:s}=i,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=i.pos[l],u=i.size[l];if(!f||a.clip!==!1&&(f.bottom<=Math.max(t.top,n.top)||f.top>=Math.min(t.bottom,n.bottom)||f.right<Math.max(t.left,n.left)-.1||f.left>Math.min(t.right,n.right)+.1)){c.style.top=No;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=Np.get(h))!==null&&e!==void 0?e:u.bottom-u.top,y=h.offset||HM,b=this.view.textDirection==Z.LTR,k=u.width>n.right-n.left?b?n.left:n.right-u.width:b?Math.max(n.left,Math.min(f.left-(d?14:0)+y.x,n.right-m)):Math.min(Math.max(n.left,f.left-m+(d?14:0)-y.x),n.right-m),O=this.above[l];!a.strictSide&&(O?f.top-g-p-y.y<n.top:f.bottom+g+p+y.y>n.bottom)&&O==n.bottom-f.bottom>f.top-n.top&&(O=this.above[l]=!O);let w=(O?f.top-n.top:n.bottom-f.bottom)-p;if(w<g&&h.resize!==!1){if(w<this.view.defaultLineHeight){c.style.top=No;continue}Np.set(h,g),c.style.height=(g=w)/s+"px"}else c.style.height&&(c.style.height="");let M=O?f.top-g-p-y.y:f.bottom+p+y.y,C=k+m;if(h.overlap!==!0)for(let I of o)I.left<C&&I.right>k&&I.top<M+g&&I.bottom>M&&(M=O?I.top-g-2-p:I.bottom+p+2);if(this.position=="absolute"?(c.style.top=(M-i.parent.top)/s+"px",Dp(c,(k-i.parent.left)/r)):(c.style.top=M/s+"px",Dp(c,(k-i.fixedLeft)/r)),d){let I=f.left+(b?y.x:-y.x)-(k+14-7);d.style.left=I/r+"px"}h.overlap!==!0&&o.push({left:k,top:M,right:C,bottom:M+g}),c.classList.toggle("cm-tooltip-above",O),c.classList.toggle("cm-tooltip-below",!O),h.positioned&&h.positioned(i.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let i of this.manager.tooltipViews)i.dom.style.top=No}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Dp(i,e){let t=parseInt(i.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(i.style.left=e+"px")}const zM=R.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),HM={x:0,y:0},ff=D.define({enables:[cf,zM]}),wl=D.define({combine:i=>i.reduce((e,t)=>e.concat(t),[])});class Ul{static create(e){return new Ul(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Hy(e,wl,(t,n)=>this.createHostedView(t,n),t=>t.dom.remove())}createHostedView(e,t){let n=e.create(this.view);return n.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(n.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&n.mount&&n.mount(this.view),n}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let n of this.manager.tooltipViews){let r=n[e];if(r!==void 0){if(t===void 0)t=r;else if(t!==r)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const WM=ff.compute([wl],i=>{let e=i.facet(wl);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var n;return(n=t.end)!==null&&n!==void 0?n:t.pos})),create:Ul.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),$y=D.define();class $M{constructor(e,t,n,r,s,o){this.view=e,this.source=t,this.field=n,this.locked=r,this.setHover=s,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(e){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,n=e.docView.tile.nearest(t.target);if(!n)return;let r,s=1;if(n.isWidget())r=n.posAtStart;else{if(r=e.posAtCoords(t),r==null)return;let o=e.coordsAtPos(r);if(!o||t.y<o.top||t.y>o.bottom||t.x<o.left-e.defaultCharacterWidth||t.x>o.right+e.defaultCharacterWidth)return;let l=e.bidiSpans(e.state.doc.lineAt(r)).find(h=>h.from<=r&&h.to>=r),a=l&&l.dir==Z.RTL?-1:1;s=t.x<o.left?-a:a}this.activateHover(e,r,s)}activateHover(e,t,n,r){let s=this.source(e,t,n),o=l=>{if(l&&!(Array.isArray(l)&&!l.length)){let a=Array.isArray(l)?l:[l];r&&this.locked.set(a,r),e.dispatch({effects:this.setHover.of(a)})}};if(s&&"then"in s){let l=this.pending={pos:t};s.then(a=>{this.pending==l&&(this.pending=null,o(a))},a=>Qe(e.state,a,"hover tooltip"))}else o(s)}get tooltip(){let e=this.view.plugin(cf),t=e?e.manager.tooltips.findIndex(n=>n.create==Ul.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,n;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:r,tooltip:s}=this;if(r.length&&!this.locked.has(r)&&s&&!KM(s.dom,e)||this.pending){let{pos:o}=r[0]||this.pending,l=(n=(t=r[0])===null||t===void 0?void 0:t.end)!==null&&n!==void 0?n:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!qM(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length&&!this.locked.has(t)){let{tooltip:n}=this;n&&n.dom.contains(e.relatedTarget)?this.watchTooltipLeave(n.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=n=>{e.removeEventListener("mouseleave",t);let{active:r}=this;r.length&&!this.locked.has(r)&&!this.view.dom.contains(n.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Do=4;function KM(i,e){let{left:t,right:n,top:r,bottom:s}=i.getBoundingClientRect(),o;if(o=i.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();r=Math.min(l.top,r),s=Math.max(l.bottom,s)}return e.clientX>=t-Do&&e.clientX<=n+Do&&e.clientY>=r-Do&&e.clientY<=s+Do}function qM(i,e,t,n,r,s){let o=i.scrollDOM.getBoundingClientRect(),l=i.documentTop+i.documentPadding.top+i.contentHeight;if(o.left>n||o.right<n||o.top>r||Math.min(o.bottom,l)<r)return!1;let a=i.posAtCoords({x:n,y:r},!1);return a>=e&&a<=t}function TD(i,e={}){let t=z.define(),n=new WeakMap,r=Ge.define({create(){return[]},update(o,l){let a=n.get(o);if(o.length&&(e.hideOnChange&&(l.docChanged||l.selection)?o=[]:a&&a(l)?o=[]:e.hideOn&&(o=o.filter(h=>!e.hideOn(l,h)))),l.docChanged&&o.length){let h=[];for(let c of o){let f=l.changes.mapPos(c.pos,-1,Ae.TrackDel);if(f!=null){let u=Object.assign(Object.create(null),c);u.pos=f,u.end!=null&&(u.end=l.changes.mapPos(u.end)),h.push(u)}}o=h}for(let h of l.effects)h.is(t)&&(o=h.value,a=void 0),(h.is(jM)&&!h.value||h.value==r)&&(o=[]);return o.length&&a&&n.set(o,a),o},provide:o=>wl.from(o)});const s=be.define(o=>new $M(o,i,r,n,t,e.hoverTime||300));return{active:r,extension:[r,s,$y.of(s),WM]}}function ND(i,e,t,n={}){var r;let s=i.state.facet($y).map(o=>i.plugin(o)).filter(o=>!!o);if(n.tooltip&&n.tooltip.active){let o=s.find(l=>l.field==n.tooltip.active);o&&(s=[o])}for(let o of s)o.activateHover(i,e,t,(r=n.until)!==null&&r!==void 0?r:(()=>!1))}function Ky(i,e){let t=i.plugin(cf);if(!t)return null;let n=t.manager.tooltips.indexOf(e);return n<0?null:t.manager.tooltipViews[n]}const jM=z.define(),Ip=D.define({combine(i){let e,t;for(let n of i)e=e||n.topContainer,t=t||n.bottomContainer;return{topContainer:e,bottomContainer:t}}});function JM(i,e){let t=i.plugin(qy),n=t?t.specs.indexOf(e):-1;return n>-1?t.panels[n]:null}const qy=be.fromClass(class{constructor(i){this.input=i.state.facet(pc),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(i));let e=i.state.facet(Ip);this.top=new Io(i,!0,e.topContainer),this.bottom=new Io(i,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(i){let e=i.state.facet(Ip);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Io(i.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Io(i.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=i.state.facet(pc);if(t!=this.input){let n=t.filter(a=>a),r=[],s=[],o=[],l=[];for(let a of n){let h=this.specs.indexOf(a),c;h<0?(c=a(i.view),l.push(c)):(c=this.panels[h],c.update&&c.update(i)),r.push(c),(c.top?s:o).push(c)}this.specs=n,this.panels=r,this.top.sync(s),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let n of this.panels)n.update&&n.update(i)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:i=>R.scrollMargins.of(e=>{let t=e.plugin(i);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Io{constructor(e,t,n){this.view=e,this.top=t,this.container=n,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Ep(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Ep(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Ep(i){let e=i.nextSibling;return i.remove(),e}const pc=D.define({enables:qy});function DD(i,e){let t,n=new Promise(o=>t=o),r=o=>_M(o,e,t);i.state.field(Zo,!1)?i.dispatch({effects:jy.of(r)}):i.dispatch({effects:z.appendConfig.of(Zo.init(()=>[r]))});let s=Jy.of(r);return{close:s,result:n.then(o=>((i.win.queueMicrotask||(a=>i.win.setTimeout(a,10)))(()=>{i.state.field(Zo).indexOf(r)>-1&&i.dispatch({effects:s})}),o))}}function ID(i,e){let t=i.state.field(Zo,!1)||[];for(let n of t){let r=JM(i,n);if(r&&r.dom.classList.contains(e))return r}return null}const Zo=Ge.define({create(){return[]},update(i,e){for(let t of e.effects)t.is(jy)?i=[t.value].concat(i):t.is(Jy)&&(i=i.filter(n=>n!=t.value));return i},provide:i=>pc.computeN([i],e=>e.field(i))}),jy=z.define(),Jy=z.define();function _M(i,e,t){let n=e.content?e.content(i,()=>l(null)):null;if(!n){if(n=Ii("form"),e.input){let a=Ii("input",e.input);/^(text|password|number|email|tel|url)$/.test(a.type)&&a.classList.add("cm-textfield"),a.name||(a.name="input"),n.appendChild(Ii("label",(e.label||"")+": ",a))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(Ii("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let r=n.nodeName=="FORM"?[n]:n.querySelectorAll("form");for(let a=0;a<r.length;a++){let h=r[a];h.addEventListener("keydown",c=>{c.keyCode==27?(c.preventDefault(),l(null)):c.keyCode==13&&(c.preventDefault(),l(h))}),h.addEventListener("submit",c=>{c.preventDefault(),l(h)})}let s=Ii("div",n,Ii("button",{onclick:()=>l(null),"aria-label":i.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(s.className=e.class),s.classList.add("cm-dialog");let o=typeof e.focus=="string"?n.querySelector(e.focus):e.focus?n.querySelector("input")||n.querySelector("button"):null;function l(a){s.contains(s.ownerDocument.activeElement)&&i.focus(),t(a)}return{dom:s,top:e.top,mount:()=>{o&&("select"in o?o.select():"focus"in o&&o.focus())},destroy:()=>t(null)}}class fn extends zn{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}fn.prototype.elementClass="";fn.prototype.toDOM=void 0;fn.prototype.mapMode=Ae.TrackBefore;fn.prototype.startSide=fn.prototype.endSide=-1;fn.prototype.point=!0;const el=D.define(),UM=D.define(),GM={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>$.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},ss=D.define();function YM(i){return[_y(),ss.of({...GM,...i})]}const Rp=D.define({combine:i=>i.some(e=>e)});function _y(i){return[XM]}const XM=be.fromClass(class{constructor(i){this.view=i,this.domAfter=null,this.prevViewport=i.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=i.state.facet(ss).map(e=>new Pp(i,e)),this.fixed=!i.state.facet(Rp);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),i.scrollDOM.insertBefore(this.dom,i.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(i){if(this.updateGutters(i)){let e=this.prevViewport,t=i.view.viewport,n=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(n<(t.to-t.from)*.8)}if(i.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Rp)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=i.view.viewport}syncGutters(i){let e=this.dom.nextSibling;i&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=$.iter(this.view.state.facet(el),this.view.viewport.from),n=[],r=this.gutters.map(s=>new QM(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(s.type)){let o=!0;for(let l of s.type)if(l.type==Te.Text&&o){mc(t,n,l.from);for(let a of r)a.line(this.view,l,n);o=!1}else if(l.widget)for(let a of r)a.widget(this.view,l)}else if(s.type==Te.Text){mc(t,n,s.from);for(let o of r)o.line(this.view,s,n)}else if(s.widget)for(let o of r)o.widget(this.view,s);for(let s of r)s.finish();i&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(i){let e=i.startState.facet(ss),t=i.state.facet(ss),n=i.docChanged||i.heightChanged||i.viewportChanged||!$.eq(i.startState.facet(el),i.state.facet(el),i.view.viewport.from,i.view.viewport.to);if(e==t)for(let r of this.gutters)r.update(i)&&(n=!0);else{n=!0;let r=[];for(let s of t){let o=e.indexOf(s);o<0?r.push(new Pp(this.view,s)):(this.gutters[o].update(i),r.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),r.indexOf(s)<0&&s.destroy();for(let s of r)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=r}return n}destroy(){for(let i of this.gutters)i.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:i=>R.scrollMargins.of(e=>{let t=e.plugin(i);if(!t||t.gutters.length==0||!t.fixed)return null;let n=t.dom.offsetWidth*e.scaleX,r=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Z.LTR?{left:n,right:r}:{right:n,left:r}})});function Bp(i){return Array.isArray(i)?i:[i]}function mc(i,e,t){for(;i.value&&i.from<=t;)i.from==t&&e.push(i.value),i.next()}class QM{constructor(e,t,n){this.gutter=e,this.height=n,this.i=0,this.cursor=$.iter(e.markers,t.from)}addElement(e,t,n){let{gutter:r}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==r.elements.length){let l=new Uy(e,o,s,n);r.elements.push(l),r.dom.appendChild(l.dom)}else r.elements[this.i].update(e,o,s,n);this.height=t.bottom,this.i++}line(e,t,n){let r=[];mc(this.cursor,r,t.from),n.length&&(r=r.concat(n));let s=this.gutter.config.lineMarker(e,t,r);s&&r.unshift(s);let o=this.gutter;r.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,r)}widget(e,t){let n=this.gutter.config.widgetMarker(e,t.widget,t),r=n?[n]:null;for(let s of e.state.facet(UM)){let o=s(e,t.widget,t);o&&(r||(r=[])).push(o)}r&&this.addElement(e,t,r)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class Pp{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let n in t.domEventHandlers)this.dom.addEventListener(n,r=>{let s=r.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let a=s.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=r.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[n](e,l,r)&&r.preventDefault()});this.markers=Bp(t.markers(e)),t.initialSpacer&&(this.spacer=new Uy(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Bp(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let r=this.config.updateSpacer(this.spacer.markers[0],e);r!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[r])}let n=e.view.viewport;return!$.eq(this.markers,t,n.from,n.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Uy{constructor(e,t,n,r){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,n,r)}update(e,t,n,r){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=n&&(this.dom.style.marginTop=(this.above=n)?n+"px":""),ZM(this.markers,r)||this.setMarkers(e,r)}setMarkers(e,t){let n="cm-gutterElement",r=this.dom.firstChild;for(let s=0,o=0;;){let l=o,a=s<t.length?t[s++]:null,h=!1;if(a){let c=a.elementClass;c&&(n+=" "+c);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(r);let f=r.nextSibling;r.remove(),r=f}}if(!a)break;a.toDOM&&(h?r=r.nextSibling:this.dom.insertBefore(a.toDOM(e),r)),h&&o++}this.dom.className=n,this.markers=t}destroy(){this.setMarkers(null,[])}}function ZM(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(!i[t].compare(e[t]))return!1;return!0}const eA=D.define(),tA=D.define(),Vi=D.define({combine(i){return Mi(i,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let n=Object.assign({},e);for(let r in t){let s=n[r],o=t[r];n[r]=s?(l,a,h)=>s(l,a,h)||o(l,a,h):o}return n}})}});class Ja extends fn{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function _a(i,e){return i.state.facet(Vi).formatNumber(e,i.state)}const nA=ss.compute([Vi],i=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(eA)},lineMarker(e,t,n){return n.some(r=>r.toDOM)?null:new Ja(_a(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,n)=>{for(let r of e.state.facet(tA)){let s=r(e,t,n);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Vi)!=e.state.facet(Vi),initialSpacer(e){return new Ja(_a(e,Lp(e.state.doc.lines)))},updateSpacer(e,t){let n=_a(t.view,Lp(t.view.state.doc.lines));return n==e.number?e:new Ja(n)},domEventHandlers:i.facet(Vi).domEventHandlers,side:"before"}));function ED(i={}){return[Vi.of(i),_y(),nA]}function Lp(i){let e=9;for(;e<i;)e=e*10+9;return e}const iA=new class extends fn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},rA=el.compute(["selection"],i=>{let e=[],t=-1;for(let n of i.selection.ranges){let r=i.doc.lineAt(n.head).from;r>t&&(t=r,e.push(iA.range(r)))}return $.of(e)});function RD(){return rA}let sA=0;class ct{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=sA++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let n=typeof e=="string"?e:"?";if(e instanceof ct&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let r=new ct(n,[],null,[]);if(r.set.push(r),t)for(let s of t.set)r.set.push(s);return r}static defineModifier(e){let t=new Sl(e);return n=>n.modified.indexOf(t)>-1?n:Sl.get(n.base||n,n.modified.concat(t).sort((r,s)=>r.id-s.id))}}let oA=0;class Sl{constructor(e){this.name=e,this.instances=[],this.id=oA++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find(l=>l.base==e&&lA(t,l.modified));if(n)return n;let r=[],s=new ct(e.name,r,e,t);for(let l of t)l.instances.push(s);let o=aA(t);for(let l of e.set)if(!l.modified.length)for(let a of o)r.push(Sl.get(l,a));return s}}function lA(i,e){return i.length==e.length&&i.every((t,n)=>t==e[n])}function aA(i){let e=[[]];for(let t=0;t<i.length;t++)for(let n=0,r=e.length;n<r;n++)e.push(e[n].concat(i[t]));return e.sort((t,n)=>n.length-t.length)}function hA(i){let e=Object.create(null);for(let t in i){let n=i[t];Array.isArray(n)||(n=[n]);for(let r of t.split(" "))if(r){let s=[],o=2,l=r;for(let f=0;;){if(l=="..."&&f>0&&f+3==r.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+r);if(s.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==r.length)break;let d=r[f++];if(f==r.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+r);l=r.slice(f)}let a=s.length-1,h=s[a];if(!h)throw new RangeError("Invalid path: "+r);let c=new Ns(n,o,a>0?s.slice(0,a):null);e[h]=c.sort(e[h])}}return Gy.add(e)}const Gy=new H({combine(i,e){let t,n,r;for(;i||e;){if(!i||e&&i.depth<=e.depth?(r=e,e=e.next):(r=i,i=i.next),t&&t.mode==r.mode&&!r.context&&!t.context)continue;let s=new Ns(r.tags,r.mode,r.context);t?t.next=s:n=s,t=s}return n}});class Ns{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Ns.empty=new Ns([],2,null);function Yy(i,e){let t=Object.create(null);for(let s of i)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:n,all:r=null}=e||{};return{style:s=>{let o=r;for(let l of s)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:n}}function cA(i,e){let t=null;for(let n of i){let r=n.style(e);r&&(t=t?t+" "+r:r)}return t}function fA(i,e,t,n=0,r=i.length){let s=new uA(n,Array.isArray(e)?e:[e],t);s.highlightRange(i.cursor(),n,r,"",s.highlighters),s.flush(r)}class uA{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,s){let{type:o,from:l,to:a}=e;if(l>=n||a<=t)return;o.isTop&&(s=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=r,c=dA(e)||Ns.empty,f=cA(s,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(r+=(r?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop(H.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(u.tree.type)),m=e.firstChild();for(let g=0,y=l;;g++){let b=g<u.overlay.length?u.overlay[g]:null,k=b?b.from+l:a,O=Math.max(t,y),w=Math.min(n,k);if(O<w&&m)for(;e.from<w&&(this.highlightRange(e,O,w,r,s),this.startSpan(Math.min(w,e.to),h),!(e.to>=k||!e.nextSibling())););if(!b||k>n)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(n,y),"",p),this.startSpan(Math.min(n,y),h))}m&&e.parent()}else if(e.firstChild()){u&&(r="");do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,r,s),this.startSpan(Math.min(n,e.to),h)}while(e.nextSibling());e.parent()}}}function dA(i){let e=i.type.prop(Gy);for(;e&&e.context&&!i.matchContext(e.context);)e=e.next;return e||null}const T=ct.define,Eo=T(),kn=T(),Fp=T(kn),Vp=T(kn),xn=T(),Ro=T(xn),Ua=T(xn),Ft=T(),Gn=T(Ft),Pt=T(),Lt=T(),gc=T(),Ir=T(gc),Bo=T(),v={comment:Eo,lineComment:T(Eo),blockComment:T(Eo),docComment:T(Eo),name:kn,variableName:T(kn),typeName:Fp,tagName:T(Fp),propertyName:Vp,attributeName:T(Vp),className:T(kn),labelName:T(kn),namespace:T(kn),macroName:T(kn),literal:xn,string:Ro,docString:T(Ro),character:T(Ro),attributeValue:T(Ro),number:Ua,integer:T(Ua),float:T(Ua),bool:T(xn),regexp:T(xn),escape:T(xn),color:T(xn),url:T(xn),keyword:Pt,self:T(Pt),null:T(Pt),atom:T(Pt),unit:T(Pt),modifier:T(Pt),operatorKeyword:T(Pt),controlKeyword:T(Pt),definitionKeyword:T(Pt),moduleKeyword:T(Pt),operator:Lt,derefOperator:T(Lt),arithmeticOperator:T(Lt),logicOperator:T(Lt),bitwiseOperator:T(Lt),compareOperator:T(Lt),updateOperator:T(Lt),definitionOperator:T(Lt),typeOperator:T(Lt),controlOperator:T(Lt),punctuation:gc,separator:T(gc),bracket:Ir,angleBracket:T(Ir),squareBracket:T(Ir),paren:T(Ir),brace:T(Ir),content:Ft,heading:Gn,heading1:T(Gn),heading2:T(Gn),heading3:T(Gn),heading4:T(Gn),heading5:T(Gn),heading6:T(Gn),contentSeparator:T(Ft),list:T(Ft),quote:T(Ft),emphasis:T(Ft),strong:T(Ft),link:T(Ft),monospace:T(Ft),strikethrough:T(Ft),inserted:T(),deleted:T(),changed:T(),invalid:T(),meta:Bo,documentMeta:T(Bo),annotation:T(Bo),processingInstruction:T(Bo),definition:ct.defineModifier("definition"),constant:ct.defineModifier("constant"),function:ct.defineModifier("function"),standard:ct.defineModifier("standard"),local:ct.defineModifier("local"),special:ct.defineModifier("special")};for(let i in v){let e=v[i];e instanceof ct&&(e.name=i)}Yy([{tag:v.link,class:"tok-link"},{tag:v.heading,class:"tok-heading"},{tag:v.emphasis,class:"tok-emphasis"},{tag:v.strong,class:"tok-strong"},{tag:v.keyword,class:"tok-keyword"},{tag:v.atom,class:"tok-atom"},{tag:v.bool,class:"tok-bool"},{tag:v.url,class:"tok-url"},{tag:v.labelName,class:"tok-labelName"},{tag:v.inserted,class:"tok-inserted"},{tag:v.deleted,class:"tok-deleted"},{tag:v.literal,class:"tok-literal"},{tag:v.string,class:"tok-string"},{tag:v.number,class:"tok-number"},{tag:[v.regexp,v.escape,v.special(v.string)],class:"tok-string2"},{tag:v.variableName,class:"tok-variableName"},{tag:v.local(v.variableName),class:"tok-variableName tok-local"},{tag:v.definition(v.variableName),class:"tok-variableName tok-definition"},{tag:v.special(v.variableName),class:"tok-variableName2"},{tag:v.definition(v.propertyName),class:"tok-propertyName tok-definition"},{tag:v.typeName,class:"tok-typeName"},{tag:v.namespace,class:"tok-namespace"},{tag:v.className,class:"tok-className"},{tag:v.macroName,class:"tok-macroName"},{tag:v.propertyName,class:"tok-propertyName"},{tag:v.operator,class:"tok-operator"},{tag:v.comment,class:"tok-comment"},{tag:v.meta,class:"tok-meta"},{tag:v.invalid,class:"tok-invalid"},{tag:v.punctuation,class:"tok-punctuation"}]);function zp(i,e,t,n=0,r=0){e==null&&(e=i.search(/[^\s\u00a0]/),e==-1&&(e=i.length));let s=r;for(let o=n;o<e;o++)i.charCodeAt(o)==9?s+=t-s%t:s++;return s}class Xy{constructor(e,t,n,r){this.string=e,this.tabSize=t,this.indentUnit=n,this.overrideIndent=r,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),n;if(typeof e=="string"?n=t==e:n=t&&(e instanceof RegExp?e.test(t):e(t)),n)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=zp(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:zp(this.string,null,this.tabSize)}match(e,t,n){if(typeof e=="string"){let r=o=>n?o.toLowerCase():o,s=this.string.substr(this.pos,e.length);return r(s)==r(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let r=this.string.slice(this.pos).match(e);return r&&r.index>0?null:(r&&t!==!1&&(this.pos+=r[0].length),r)}}current(){return this.string.slice(this.start,this.pos)}}var Ga;const ti=new H;function Qy(i){return D.define({combine:i?e=>e.concat(i):void 0})}const pA=new H;class pt{constructor(e,t,n=[],r=""){this.data=e,this.name=r,Y.prototype.hasOwnProperty("tree")||Object.defineProperty(Y.prototype,"tree",{get(){return Ne(this)}}),this.parser=t,this.extension=[$n.of(this),Y.languageData.of((s,o,l)=>{let a=Hp(s,o,l),h=a.type.prop(ti);if(!h)return[];let c=s.facet(h),f=a.type.prop(pA);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,s)){let p=s.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(n)}isActiveAt(e,t,n=-1){return Hp(e,t,n).type.prop(ti)==this.data}findRegions(e){let t=e.facet($n);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(s,o)=>{if(s.prop(ti)==this.data){n.push({from:o,to:o+s.length});return}let l=s.prop(H.mounted);if(l){if(l.tree.prop(ti)==this.data){if(l.overlay)for(let a of l.overlay)n.push({from:a.from+o,to:a.to+o});else n.push({from:o,to:o+s.length});return}else if(l.overlay){let a=n.length;if(r(l.tree,l.overlay[0].from+o),n.length>a)return}}for(let a=0;a<s.children.length;a++){let h=s.children[a];h instanceof ie&&r(h,s.positions[a]+o)}};return r(Ne(e),0),n}get allowsNesting(){return!0}}pt.setState=z.define();function Hp(i,e,t){let n=i.facet($n),r=Ne(i).topNode;if(!n||n.allowsNesting)for(let s=r;s;s=s.enter(e,t,Q.ExcludeBuffers|Q.EnterBracketed))s.type.isTop&&(r=s);return r}class yc extends pt{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(e){let t=Qy(e.languageData);return new yc(t,e.parser.configure({props:[ti.add(n=>n.isTop?t:void 0)]}),e.name)}configure(e,t){return new yc(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Ne(i){let e=i.field(pt.state,!1);return e?e.tree:ie.empty}class mA{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}}let Er=null;class pr{constructor(e,t,n=[],r,s,o,l,a){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new pr(e,t,[],ie.empty,0,n,[],null)}startParse(){return this.parser.startParse(new mA(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=ie.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let r=Date.now()+e;e=()=>Date.now()>r}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let r=this.parse.advance();if(r)if(this.fragments=this.withoutTempSkipped(ln.addTree(r,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(n=this.parse.stoppedAt)!==null&&n!==void 0?n:this.state.doc.length,this.tree=r,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(ln.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Er;Er=this;try{return e()}finally{Er=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Wp(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:r,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),n=ln.applyChanges(n,a),r=ie.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new pr(this.parser,t,n,r,s,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let n=0;n<this.skipped.length;n++){let{from:r,to:s}=this.skipped[n];r<e.to&&s>e.from&&(this.fragments=Wp(this.fragments,r,s),this.skipped.splice(n--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends b0{createParse(t,n,r){let s=r[0].from,o=r[r.length-1].to;return{parsedPos:s,advance(){let a=Er;if(a){for(let h of r)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new ie(je.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Er}}function Wp(i,e,t){return ln.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}class mr{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new mr(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=pr.create(e.facet($n).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new mr(n)}}pt.state=Ge.define({create:mr.init,update(i,e){for(let t of e.effects)if(t.is(pt.setState))return t.value;return e.startState.facet($n)!=e.state.facet($n)?mr.init(e.state):i.apply(e)}});let Zy=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Zy=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Ya=typeof navigator<"u"&&(!((Ga=navigator.scheduling)===null||Ga===void 0)&&Ga.isInputPending)?()=>navigator.scheduling.isInputPending():null,gA=be.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(pt.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(pt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Zy(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:r}}=this.view,s=n.field(pt.state);if(s.tree==s.context.tree&&s.context.isDone(r+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Ya?Math.max(25,e.timeRemaining()-5):1e9),l=s.context.treeLen<r&&n.doc.length>r+1e3,a=s.context.work(()=>Ya&&Ya()||Date.now()>o,r+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:pt.setState.of(new mr(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Qe(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),$n=D.define({combine(i){return i.length?i[0]:null},enables:i=>[pt.state,gA,R.contentAttributes.compute([i],e=>{let t=e.facet(i);return t&&t.name?{"data-language":t.name}:{}})]});class PD{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class eb{constructor(e,t,n,r,s,o=void 0){this.name=e,this.alias=t,this.extensions=n,this.filename=r,this.loadFunc=s,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:n}=e;if(!t){if(!n)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(n)}return new eb(e.name,(e.alias||[]).concat(e.name).map(r=>r.toLowerCase()),e.extensions||[],e.filename,t,n)}static matchFilename(e,t){for(let r of e)if(r.filename&&r.filename.test(t))return r;let n=/\.([^.]+)$/.exec(t);if(n){for(let r of e)if(r.extensions.indexOf(n[1])>-1)return r}return null}static matchLanguageName(e,t,n=!0){t=t.toLowerCase();for(let r of e)if(r.alias.some(s=>s==t))return r;if(n)for(let r of e)for(let s of r.alias){let o=t.indexOf(s);if(o>-1&&(s.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+s.length])))return r}return null}}const yA=D.define(),Gl=D.define({combine:i=>{if(!i.length)return" ";let e=i[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(i[0]));return e}});function wi(i){let e=i.facet(Gl);return e.charCodeAt(0)==9?i.tabSize*e.length:e.length}function Ds(i,e){let t="",n=i.tabSize,r=i.facet(Gl)[0];if(r==" "){for(;e>=n;)t+=" ",e-=n;r=" "}for(let s=0;s<e;s++)t+=r;return t}function uf(i,e){i instanceof Y&&(i=new Yl(i));for(let n of i.state.facet(yA)){let r=n(i,e);if(r!==void 0)return r}let t=Ne(i.state);return t.length>=e?bA(i,t,e):null}class Yl{constructor(e,t={}){this.state=e,this.options=t,this.unit=wi(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:s}=this.options;return r!=null&&r>=n.from&&r<=n.to?s&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),s=this.countColumn(n,e-r),o=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return o>-1&&(s+=o-this.countColumn(n,n.search(/\S|$/))),s}countColumn(e,t=e.length){return xr(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(r);if(o>-1)return o}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const tb=new H;function bA(i,e,t){let n=e.resolveStack(t),r=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(r!=n.node){let s=[];for(let o=r;o&&!(o.from<n.node.from||o.to>n.node.to||o.from==n.node.from&&o.type==n.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)n={node:s[o],next:n}}return nb(n,i,t)}function nb(i,e,t){for(let n=i;n;n=n.next){let r=xA(n.node);if(r)return r(df.create(e,t,n))}return 0}function kA(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function xA(i){let e=i.type.prop(tb);if(e)return e;let t=i.firstChild,n;if(t&&(n=t.type.prop(H.closedBy))){let r=i.lastChild,s=r&&n.indexOf(r.name)>-1;return o=>ib(o,!0,1,void 0,s&&!kA(o)?r.from:void 0)}return i.parent==null?wA:null}function wA(){return 0}class df extends Yl{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.context=n}get node(){return this.context.node}static create(e,t,n){return new df(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(SA(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){return nb(this.context.next,this.base,this.pos)}}function SA(i,e){for(let t=e;t;t=t.parent)if(i==t)return!0;return!1}function CA(i){let e=i.node,t=e.childAfter(e.from),n=e.lastChild;if(!t)return null;let r=i.options.simulateBreak,s=i.state.doc.lineAt(t.from),o=r==null||r<=s.from?s.to:Math.min(s.to,r);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==n)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let h=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function LD({closing:i,align:e=!0,units:t=1}){return n=>ib(n,e,t,i)}function ib(i,e,t,n,r){let s=i.textAfter,o=s.match(/^\s*/)[0].length,l=n&&s.slice(o,o+n.length)==n||r==i.pos+o,a=e?CA(i):null;return a?l?i.column(a.from):i.column(a.to):i.baseIndent+(l?0:i.unit*t)}const FD=i=>i.baseIndent;function VD({except:i,units:e=1}={}){return t=>{let n=i&&i.test(t.textAfter);return t.baseIndent+(n?0:e*t.unit)}}const vA=200;function zD(){return Y.transactionFilter.of(i=>{if(!i.docChanged||!i.isUserEvent("input.type")&&!i.isUserEvent("input.complete"))return i;let e=i.startState.languageDataAt("indentOnInput",i.startState.selection.main.head);if(!e.length)return i;let t=i.newDoc,{head:n}=i.newSelection.main,r=t.lineAt(n);if(n>r.from+vA)return i;let s=t.sliceString(r.from,n);if(!e.some(h=>h.test(s)))return i;let{state:o}=i,l=-1,a=[];for(let{head:h}of o.selection.ranges){let c=o.doc.lineAt(h);if(c.from==l)continue;l=c.from;let f=uf(o,c.from);if(f==null)continue;let u=/^\s*/.exec(c.text)[0],d=Ds(o,f);u!=d&&a.push({from:c.from,to:c.from+u.length,insert:d})}return a.length?[i,{changes:a,sequential:!0}]:i})}const MA=D.define(),AA=new H;function HD(i){let e=i.firstChild,t=i.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?i.to:t.from}:null}function OA(i,e,t){let n=Ne(i);if(n.length<t)return null;let r=n.resolveStack(t,1),s=null;for(let o=r;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(s&&l.from<e)break;let a=l.type.prop(AA);if(a&&(l.to<n.length-50||n.length==i.doc.length||!TA(l))){let h=a(l,i);h&&h.from<=t&&h.from>=e&&h.to>t&&(s=h)}}return s}function TA(i){let e=i.lastChild;return e&&e.to==i.to&&e.type.isError}function Cl(i,e,t){for(let n of i.facet(MA)){let r=n(i,e,t);if(r)return r}return OA(i,e,t)}function rb(i,e){let t=e.mapPos(i.from,1),n=e.mapPos(i.to,-1);return t>=n?void 0:{from:t,to:n}}const Xl=z.define({map:rb}),no=z.define({map:rb});function sb(i){let e=[];for(let{head:t}of i.state.selection.ranges)e.some(n=>n.from<=t&&n.to>=t)||e.push(i.lineBlockAt(t));return e}const Si=Ge.define({create(){return J.none},update(i,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((n,r)=>i=$p(i,n,r)),i=i.map(e.changes);let t=[];for(let n of e.effects)n.is(Xl)&&!NA(i,n.value.from,n.value.to)?t.push(n.value):n.is(no)&&(i=i.update({filter:(r,s)=>n.value.from!=r||n.value.to!=s,filterFrom:n.value.from,filterTo:n.value.to}));if(t.length){let{preparePlaceholder:n}=e.state.facet(ab),r=t.map(s=>(n?J.replace({widget:new PA(n(e.state,s))}):Kp).range(s.from,s.to));i=i.update({add:r})}return e.selection&&(i=$p(i,e.selection.main.head)),i},provide:i=>R.decorations.from(i),toJSON(i,e){let t=[];return i.between(0,e.doc.length,(n,r)=>{t.push(n,r)}),t},fromJSON(i){if(!Array.isArray(i)||i.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<i.length;){let n=i[t++],r=i[t++];if(typeof n!="number"||typeof r!="number")throw new RangeError("Invalid JSON for fold state");e.push(Kp.range(n,r))}return J.set(e,!0)}});function $p(i,e,t=e){let n=!1;return i.between(e,t,(r,s)=>{r<t&&s>e&&(n=!0)}),n?i.update({filterFrom:e,filterTo:t,filter:(r,s)=>r>=t||s<=e}):i}function vl(i,e,t){var n;let r=null;return(n=i.field(Si,!1))===null||n===void 0||n.between(e,t,(s,o)=>{(!r||r.from>s)&&(r={from:s,to:o})}),r}function NA(i,e,t){let n=!1;return i.between(e,e,(r,s)=>{r==e&&s==t&&(n=!0)}),n}function ob(i,e){return i.field(Si,!1)?e:e.concat(z.appendConfig.of(hb()))}const DA=i=>{for(let e of sb(i)){let t=Cl(i.state,e.from,e.to);if(t)return i.dispatch({effects:ob(i.state,[Xl.of(t),lb(i,t)])}),!0}return!1},IA=i=>{if(!i.state.field(Si,!1))return!1;let e=[];for(let t of sb(i)){let n=vl(i.state,t.from,t.to);n&&e.push(no.of(n),lb(i,n,!1))}return e.length&&i.dispatch({effects:e}),e.length>0};function lb(i,e,t=!0){let n=i.state.doc.lineAt(e.from).number,r=i.state.doc.lineAt(e.to).number;return R.announce.of(`${i.state.phrase(t?"Folded lines":"Unfolded lines")} ${n} ${i.state.phrase("to")} ${r}.`)}const EA=i=>{let{state:e}=i,t=[];for(let n=0;n<e.doc.length;){let r=i.lineBlockAt(n),s=Cl(e,r.from,r.to);s&&t.push(Xl.of(s)),n=(s?i.lineBlockAt(s.to):r).to+1}return t.length&&i.dispatch({effects:ob(i.state,t)}),!!t.length},RA=i=>{let e=i.state.field(Si,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,i.state.doc.length,(n,r)=>{t.push(no.of({from:n,to:r}))}),i.dispatch({effects:t}),!0},WD=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:DA},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:IA},{key:"Ctrl-Alt-[",run:EA},{key:"Ctrl-Alt-]",run:RA}],BA={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},ab=D.define({combine(i){return Mi(i,BA)}});function hb(i){return[Si,FA]}function cb(i,e){let{state:t}=i,n=t.facet(ab),r=o=>{let l=i.lineBlockAt(i.posAtDOM(o.target)),a=vl(i.state,l.from,l.to);a&&i.dispatch({effects:no.of(a)}),o.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(i,r,e);let s=document.createElement("span");return s.textContent=n.placeholderText,s.setAttribute("aria-label",t.phrase("folded code")),s.title=t.phrase("unfold"),s.className="cm-foldPlaceholder",s.onclick=r,s}const Kp=J.replace({widget:new class extends gn{toDOM(i){return cb(i,null)}}});class PA extends gn{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return cb(e,this.value)}}const LA={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class Xa extends fn{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function $D(i={}){let e={...LA,...i},t=new Xa(e,!0),n=new Xa(e,!1),r=be.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet($n)!=o.state.facet($n)||o.startState.field(Si,!1)!=o.state.field(Si,!1)||Ne(o.startState)!=Ne(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new Bn;for(let a of o.viewportLineBlocks){let h=vl(o.state,a.from,a.to)?n:Cl(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:s}=e;return[r,YM({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(r))===null||l===void 0?void 0:l.markers)||$.empty},initialSpacer(){return new Xa(e,!1)},domEventHandlers:{...s,click:(o,l,a)=>{if(s.click&&s.click(o,l,a))return!0;let h=vl(o.state,l.from,l.to);if(h)return o.dispatch({effects:no.of(h)}),!0;let c=Cl(o.state,l.from,l.to);return c?(o.dispatch({effects:Xl.of(c)}),!0):!1}}}),hb()]}const FA=R.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class io{constructor(e,t){this.specs=e;let n;function r(l){let a=Hn.newName();return(n||(n=Object.create(null)))["."+a]=l,a}const s=typeof t.all=="string"?t.all:t.all?r(t.all):void 0,o=t.scope;this.scope=o instanceof pt?l=>l.prop(ti)==o.data:o?l=>l==o:void 0,this.style=Yy(e.map(l=>({tag:l.tag,class:l.class||r(Object.assign({},l,{tag:null}))})),{all:s}).style,this.module=n?new Hn(n):null,this.themeType=t.themeType}static define(e,t){return new io(e,t||{})}}const bc=D.define(),fb=D.define({combine(i){return i.length?[i[0]]:null}});function Qa(i){let e=i.facet(bc);return e.length?e:i.facet(fb)}function KD(i,e){let t=[zA],n;return i instanceof io&&(i.module&&t.push(R.styleModule.of(i.module)),n=i.themeType),e?.fallback?t.push(fb.of(i)):n?t.push(bc.computeN([R.darkTheme],r=>r.facet(R.darkTheme)==(n=="dark")?[i]:[])):t.push(bc.of(i)),t}class VA{constructor(e){this.markCache=Object.create(null),this.tree=Ne(e.state),this.decorations=this.buildDeco(e,Qa(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Ne(e.state),n=Qa(e.state),r=n!=Qa(e.startState),{viewport:s}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<s.to&&!r&&t.type==this.tree.type&&o>=s.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n),this.decoratedTo=s.to)}buildDeco(e,t){if(!t||!this.tree.length)return J.none;let n=new Bn;for(let{from:r,to:s}of e.visibleRanges)fA(this.tree,t,(o,l,a)=>{n.add(o,l,this.markCache[a]||(this.markCache[a]=J.mark({class:a})))},r,s);return n.finish()}}const zA=vi.high(be.fromClass(VA,{decorations:i=>i.decorations})),qD=io.define([{tag:v.meta,color:"#404740"},{tag:v.link,textDecoration:"underline"},{tag:v.heading,textDecoration:"underline",fontWeight:"bold"},{tag:v.emphasis,fontStyle:"italic"},{tag:v.strong,fontWeight:"bold"},{tag:v.strikethrough,textDecoration:"line-through"},{tag:v.keyword,color:"#708"},{tag:[v.atom,v.bool,v.url,v.contentSeparator,v.labelName],color:"#219"},{tag:[v.literal,v.inserted],color:"#164"},{tag:[v.string,v.deleted],color:"#a11"},{tag:[v.regexp,v.escape,v.special(v.string)],color:"#e40"},{tag:v.definition(v.variableName),color:"#00f"},{tag:v.local(v.variableName),color:"#30a"},{tag:[v.typeName,v.namespace],color:"#085"},{tag:v.className,color:"#167"},{tag:[v.special(v.variableName),v.macroName],color:"#256"},{tag:v.definition(v.propertyName),color:"#00c"},{tag:v.comment,color:"#940"},{tag:v.invalid,color:"#f00"}]),HA=R.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),ub=1e4,db="()[]{}",pb=D.define({combine(i){return Mi(i,{afterCursor:!0,brackets:db,maxScanDistance:ub,renderMatch:KA})}}),WA=J.mark({class:"cm-matchingBracket"}),$A=J.mark({class:"cm-nonmatchingBracket"});function KA(i){let e=[],t=i.matched?WA:$A;return e.push(t.range(i.start.from,i.start.to)),i.end&&e.push(t.range(i.end.from,i.end.to)),e}function qp(i){let e=[],t=i.facet(pb);for(let n of i.selection.ranges){if(!n.empty)continue;let r=Kt(i,n.head,-1,t)||n.head>0&&Kt(i,n.head-1,1,t)||t.afterCursor&&(Kt(i,n.head,1,t)||n.head<i.doc.length&&Kt(i,n.head+1,-1,t));r&&(e=e.concat(t.renderMatch(r,i)))}return J.set(e,!0)}const qA=be.fromClass(class{constructor(i){this.paused=!1,this.decorations=qp(i.state)}update(i){(i.docChanged||i.selectionSet||this.paused)&&(i.view.composing?(this.decorations=this.decorations.map(i.changes),this.paused=!0):(this.decorations=qp(i.state),this.paused=!1))}},{decorations:i=>i.decorations}),jA=[qA,HA];function jD(i={}){return[pb.of(i),jA]}const JA=new H;function kc(i,e,t){let n=i.prop(e<0?H.openedBy:H.closedBy);if(n)return n;if(i.name.length==1){let r=t.indexOf(i.name);if(r>-1&&r%2==(e<0?1:0))return[t[r+e]]}return null}function xc(i){let e=i.type.prop(JA);return e?e(i.node):i}function Kt(i,e,t,n={}){let r=n.maxScanDistance||ub,s=n.brackets||db,o=Ne(i),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=kc(a.type,t,s);if(h&&a.from<a.to){let c=xc(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return _A(i,e,t,a,c,h,s)}}return UA(i,e,t,o,l.type,r,s)}function _A(i,e,t,n,r,s,o){let l=n.parent,a={from:r.from,to:r.to},h=0,c=l?.cursor();if(c&&(t<0?c.childBefore(n.from):c.childAfter(n.to)))do if(t<0?c.to<=n.from:c.from>=n.to){if(h==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let f=xc(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(kc(c.type,t,o))h++;else if(kc(c.type,-t,o)){if(h==0){let f=xc(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function UA(i,e,t,n,r,s,o){if(t<0?!e:e==i.doc.length)return null;let l=t<0?i.sliceDoc(e-1,e):i.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=i.doc.iterRange(e,t>0?i.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=s;){let d=c.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||n.resolveInner(p+m,1).type!=r))if(y%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}function GA(i){return{name:i.name||"",token:i.token,blankLine:i.blankLine||(()=>{}),startState:i.startState||(()=>!0),copyState:i.copyState||YA,indent:i.indent||(()=>null),languageData:i.languageData||{},tokenTable:i.tokenTable||mf,mergeTokens:i.mergeTokens!==!1}}function YA(i){if(typeof i!="object")return i;let e={};for(let t in i){let n=i[t];e[t]=n instanceof Array?n.slice():n}return e}const jp=new WeakMap;class mb extends pt{constructor(e){let t=Qy(e.languageData),n=GA(e),r,s=new class extends b0{createParse(o,l,a){return new QA(r,o,l,a)}};super(t,s,[],e.name),this.topNode=tO(t,this),r=this,this.streamParser=n,this.stateAfter=new H({perNode:!0}),this.tokenTable=e.tokenTable?new kb(n.tokenTable):eO}static define(e){return new mb(e)}getIndent(e){let t,{overrideIndentation:n}=e.options;n&&(t=jp.get(e.state),t!=null&&t<e.pos-1e4&&(t=void 0));let r=pf(this,e.node.tree,e.node.from,e.node.from,t??e.pos),s,o;if(r?(o=r.state,s=r.pos+1):(o=this.streamParser.startState(e.unit),s=e.node.from),e.pos-s>1e4)return null;for(;s<e.pos;){let a=e.state.doc.lineAt(s),h=Math.min(e.pos,a.to);if(a.length){let c=n?n(a.from):-1,f=new Xy(a.text,e.state.tabSize,e.unit,c<0?void 0:c);for(;f.pos<h-a.from;)yb(this.streamParser.token,f,o)}else this.streamParser.blankLine(o,e.unit);if(h==e.pos)break;s=a.to+1}let l=e.lineAt(e.pos);return n&&t==null&&jp.set(e.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],e)}get allowsNesting(){return!1}}function pf(i,e,t,n,r){let s=t>=n&&t+e.length<=r&&e.prop(i.stateAfter);if(s)return{state:i.streamParser.copyState(s),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof ie&&a<r&&pf(i,l,a,n,r);if(h)return h}return null}function gb(i,e,t,n,r){if(r&&t<=0&&n>=e.length)return e;!r&&t==0&&e.type==i.topNode&&(r=!0);for(let s=e.children.length-1;s>=0;s--){let o=e.positions[s],l=e.children[s],a;if(o<n&&l instanceof ie){if(!(a=gb(i,l,t-o,n-o,r)))break;return r?new ie(e.type,e.children.slice(0,s).concat(a),e.positions.slice(0,s+1),o+a.length):a}}return null}function XA(i,e,t,n,r){for(let s of e){let o=s.from+(s.openStart?25:0),l=s.to-(s.openEnd?25:0),a=o<=t&&l>t&&pf(i,s.tree,0-s.offset,t,l),h;if(a&&a.pos<=n&&(h=gb(i,s.tree,t+s.offset,a.pos+s.offset,!1)))return{state:a.state,tree:h}}return{state:i.streamParser.startState(r?wi(r):4),tree:ie.empty}}class QA{constructor(e,t,n,r){this.lang=e,this.input=t,this.fragments=n,this.ranges=r,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=r[r.length-1].to;let s=pr.get(),o=r[0].from,{state:l,tree:a}=XA(e,n,o,this.to,s?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);s&&this.parsedPos<s.viewport.from-1e5&&r.some(h=>h.from<=s.viewport.from&&h.to>=s.viewport.from)&&(this.state=this.lang.streamParser.startState(wi(s.state)),s.skipUntilInView(this.parsedPos,s.viewport.from),this.parsedPos=s.viewport.from),this.moveRangeIndex()}advance(){let e=pr.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),n=Math.min(t,this.chunkStart+512);for(e&&(n=Math.min(n,e.viewport.to));this.parsedPos<n;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
|
|
45
23
|
`&&(t="");else{let n=t.indexOf(`
|
|
46
|
-
`);n>-1&&(t=t.slice(0,n))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),n=e+t.length;for(let r=this.rangeIndex;;){let s=this.ranges[r].to;if(s>=n||(t=t.slice(0,s-(n-t.length)),r++,r==this.ranges.length))break;let o=this.ranges[r].from,l=this.lineAfter(o);t+=l,n=o+l.length}return{line:t,end:n}}skipGapsTo(e,t,n){for(;;){let r=this.ranges[this.rangeIndex].to,s=e+t;if(n>0?r>s:r>=s)break;let o=this.ranges[++this.rangeIndex].from;t+=o-r}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,n,r){let s=4;if(this.ranges.length>1){r=this.skipGapsTo(t,r,1),t+=r;let l=this.chunk.length;r=this.skipGapsTo(n,r,-1),n+=r,s+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&s==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==t?this.chunk[o+2]=n:this.chunk.push(e,t,n,s),r}parseLine(e){let{line:t,end:n}=this.nextLine(),r=0,{streamParser:s}=this.lang,o=new bb(t,e?e.state.tabSize:4,e?Si(e.state):2);if(o.eol())s.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=zb(s.token,o,this.state);if(l&&(r=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,r)),o.start>1e4)break}this.parsedPos=n,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=ie.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:tT,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new ie(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new ie(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function zb(i,e,t){e.start=e.pos;for(let n=0;n<10;n++){let r=i(e,t);if(e.pos>e.start)return r}throw new Error("Stream parser failed to advance stream.")}const vf=Object.create(null),Bs=[je.none],tT=new Zc(Bs),am=[],hm=Object.create(null),Vb=Object.create(null);for(let[i,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Vb[i]=Wb(vf,e);class Hb{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),Vb)}resolve(e){return e?this.table[e]||(this.table[e]=Wb(this.extra,e)):0}}const nT=new Hb(vf);function sh(i,e){am.indexOf(i)>-1||(am.push(i),console.warn(e))}function Wb(i,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=i[h]||v[h];c?typeof c=="function"?a.length?a=a.map(c):sh(h,`Modifier ${h} used at start of tag`):a.length?sh(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:sh(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let n=e.replace(/ /g,"_"),r=n+" "+t.map(l=>l.id),s=hm[r];if(s)return s.id;let o=hm[r]=je.define({id:Bs.length,name:n,props:[fO({[n]:t})]});return Bs.push(o),o.id}function iT(i,e){let t=je.define({id:Bs.length,name:"Document",props:[ni.add(()=>i),Sb.add(()=>n=>e.getIndent(n))],top:!0});return Bs.push(t),t}Z.RTL,Z.LTR;function br(i,e){return i instanceof us?e==i:i.indexOf(e)>-1}function rT(i,e){return function(t,n){let{$from:r,$to:s,node:o}=t.selection;if(o&&o.isBlock||r.depth<2||!r.sameParent(s))return!1;let l=r.node(-1);if(!br(i,l.type))return!1;if(r.parent.content.size==0&&r.node(-1).childCount==r.indexAfter(-1)){if(r.depth==3||!br(i,r.node(-3).type)||r.index(-2)!=r.node(-2).childCount-1)return!1;if(n){let f=A.empty,u=r.index(-1)?1:r.index(-2)?2:3;for(let y=r.depth-u;y>=r.depth-3;y--)f=A.from(r.node(y).copy(f));let d=r.indexAfter(-1)<r.node(-2).childCount?1:r.indexAfter(-2)<r.node(-3).childCount?2:3;f=f.append(A.from(r.node(-3).type.createAndFill()));let p=r.before(r.depth-(u-1)),m=t.tr.replace(p,r.after(-d),new E(f,4-u,0)),g=-1;m.doc.nodesBetween(p,m.doc.content.size,(y,b)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=b+1)}),g>-1&&m.setSelection(_.near(m.doc.resolve(g))),n(m.scrollIntoView())}return!0}let a=s.pos==r.end()?l.contentMatchAt(0).defaultType:null,h=t.tr.delete(r.pos,s.pos),c=a?[null,{type:a}]:void 0;return Ur(h.doc,r.pos,2,c)?(n&&n(h.split(r.pos,2,c).scrollIntoView()),!0):!1}}function sT(i){return function(e,t){let{$from:n,$to:r}=e.selection,s=n.blockRange(r,o=>o.childCount>0&&br(i,o.firstChild.type));return s?t?br(i,n.node(s.depth-1).type)?oT(e,t,s):lT(e,t,s):!0:!1}}function oT(i,e,t){let n=i.tr,r=t.end,s=t.$to.end(t.depth),o=t.parent.child(t.endIndex-1).type;r<s&&(n.step(new Be(r-1,s,r,s,new E(A.from(o.create(null,t.parent.copy())),1,0),1,!0)),t=new Km(n.doc.resolve(t.$from.pos),n.doc.resolve(s),t.depth));const l=Ll(t);if(l==null)return!1;n.lift(t,l);let a=n.doc.resolve(n.mapping.map(r,-1)-1);return Fl(n.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&n.join(a.pos),e(n.scrollIntoView()),!0}function lT(i,e,t){let n=i.tr,r=t.parent;for(let d=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)d-=r.child(p).nodeSize,n.delete(d-1,d+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==r.childCount,h=s.node(-1),c=s.index(-1);if(!h.canReplace(c+(l?0:1),c+1,o.content.append(a?A.empty:A.from(r))))return!1;let f=s.pos,u=f+o.nodeSize;return n.step(new Be(f-(l?1:0),u+(a?1:0),f+1,u-1,new E((l?A.empty:A.from(r.copy(A.empty))).append(a?A.empty:A.from(r.copy(A.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function aT(i){return function(e,t){let{$from:n,$to:r}=e.selection,s=n.blockRange(r,h=>h.childCount>0&&br(i,h.firstChild.type));if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(!br(i,a.type))return!1;if(t){let h=a.lastChild&&a.lastChild.type==l.type,c=A.from(h?a.lastChild.lastChild.type.create():null),f=new E(A.from(a.type.create(null,A.from(l.type.create(null,c)))),h?3:1,0),u=s.start,d=s.end;t(e.tr.step(new Be(u-(h?3:1),d,u,d,f,1,!0)).scrollIntoView())}return!0}}function hT(i){const e=new Map;if(!i||!i.type)throw new Error("mdast-util-definitions expected node");return Us(i,"definition",function(n){const r=cm(n.identifier);r&&!e.get(r)&&e.set(r,n)}),t;function t(n){const r=cm(n);return e.get(r)}}function cm(i){return String(i||"").toUpperCase()}function cT(){return function(i){const e=hT(i);Us(i,function(t,n,r){if(t.type==="definition"&&r!==void 0&&typeof n=="number")return r.children.splice(n,1),[uh,n];if(t.type==="imageReference"||t.type==="linkReference"){const s=e(t.identifier);if(s&&r&&typeof n=="number")return r.children[n]=t.type==="imageReference"?{type:"image",url:s.url,title:s.title,alt:t.alt}:{type:"link",url:s.url,title:s.title,children:t.children},[uh,n]}})}}function fT(i){const e={...i};return e.position&&(e.position={start:{...e.position.start},end:{...e.position.end}}),delete e.children,e}var uT="<br />",dT=/^<br\s*\/?\s*>$/i,pT=i=>typeof i=="string"&&dT.test(i.trim());function $b(i,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){i.next(e.content);return}const t=[];e.content.forEach((n,r,s)=>{s!==e.childCount-1&&t.push(n)}),i.next(A.fromArray(t))}function x(i,e){return Object.assign(i,{meta:{package:"@milkdown/preset-commonmark",...e}}),i}var Mf=Jl("emphasis");x(Mf,{displayName:"Attr<emphasis>",group:"Emphasis"});var Cr=to("emphasis",i=>({attrs:{marker:{default:i.get(Xr).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",i.get(Mf.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,t,n)=>{e.openMark(n,{marker:t.marker}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,t)=>{e.withMark(t,"emphasis",void 0,{marker:t.attrs.marker})}}}));x(Cr.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});x(Cr.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Af=ee("ToggleEmphasis",i=>()=>$c(Cr.type(i)));x(Af,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var Kb=Ot(i=>$l(/(?:^|[^*])\*([^*]+)\*$/,Cr.type(i),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:t+1}}));x(Kb,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var qb=Ot(i=>$l(/\b_(?![_\s])(.*?[^_\s])_$/,Cr.type(i),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:t+1}}));x(qb,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var Of=Tt("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:i=>{const e=i.get(le);return()=>e.call(Af.key)}}});x(Of.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});x(Of.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var Tf=Jl("strong");x(Tf,{displayName:"Attr<strong>",group:"Strong"});var lo=to("strong",i=>({attrs:{marker:{default:i.get(Xr).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",i.get(Tf.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,t,n)=>{e.openMark(n,{marker:t.marker}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,t)=>{e.withMark(t,"strong",void 0,{marker:t.attrs.marker})}}}));x(lo.mark,{displayName:"MarkSchema<strong>",group:"Strong"});x(lo.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var Nf=ee("ToggleStrong",i=>()=>$c(lo.type(i)));x(Nf,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var jb=Ot(i=>$l(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),lo.type(i),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));x(jb,{displayName:"InputRule<strong>",group:"Strong"});var Df=Tt("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:i=>{const e=i.get(le);return()=>e.call(Nf.key)}}});x(Df.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});x(Df.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var If=Jl("inlineCode");x(If,{displayName:"Attr<inlineCode>",group:"InlineCode"});var Nn=to("inlineCode",i=>({priority:100,code:!0,inclusive:!1,parseDOM:[{tag:"code"}],toDOM:e=>["code",i.get(If.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,t,n)=>{e.openMark(n),e.addText(t.value),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,t,n)=>(e.withMark(t,"inlineCode",n.text||""),!0)}}));x(Nn.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});x(Nn.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Ef=ee("ToggleInlineCode",i=>()=>(e,t)=>{const{selection:n,tr:r}=e;if(n.empty)return!1;const{from:s,to:o}=n;return e.doc.rangeHasMark(s,o,Nn.type(i))?(t?.(r.removeMark(s,o,Nn.type(i))),!0):(Object.keys(e.schema.marks).filter(l=>l!==Nn.type.name).map(l=>e.schema.marks[l]).forEach(l=>{r.removeMark(s,o,l)}),t?.(r.addMark(s,o,Nn.type(i).create())),!0)});x(Ef,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var Jb=Ot(i=>$l(/(?:`)([^`]+)(?:`)$/,Nn.type(i)));x(Jb,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var Rf=Tt("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:i=>{const e=i.get(le);return()=>e.call(Ef.key)}}});x(Rf.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});x(Rf.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var mT=new Set(["http:","https:","mailto:","tel:","ftp:"]);function gT(i){return i<=32||i>=127&&i<=160||i>=8203&&i<=8205||i===8232||i===8233||i===65279}function yT(i){let e="";for(const t of i)gT(t.codePointAt(0)??0)||(e+=t);return e}function bT(i){if(typeof i!="string")return"";const e=i.trim();if(!e)return"";const t=yT(e),n=/^([a-z][a-z0-9+.-]*):/i.exec(t)?.[1];return!n||mT.has(`${n.toLowerCase()}:`)?e:""}var Bf=Jl("link");x(Bf,{displayName:"Attr<link>",group:"Link"});var Ui=to("link",i=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw vi(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...i.get(Bf.key)(e),...e.attrs,href:bT(e.attrs.href)}],parseMarkdown:{match:e=>e.type==="link",runner:(e,t,n)=>{const r=t.url,s=t.title;e.openMark(n,{href:r,title:s}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,t)=>{e.withMark(t,"link",void 0,{title:t.attrs.title,url:t.attrs.href})}}}));x(Ui.mark,{displayName:"MarkSchema<link>",group:"Link"});var _b=ee("ToggleLink",i=>(e={})=>$c(Ui.type(i),e));x(_b,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Ub=ee("UpdateLink",i=>(e={})=>(t,n)=>{if(!n)return!1;let r,s=-1;const{selection:o}=t,{from:l,to:a}=o;if(t.doc.nodesBetween(l,l===a?a+1:a,(p,m)=>{if(Ui.type(i).isInSet(p.marks))return r=p,s=m,!1}),!r)return!1;const h=r.marks.find(({type:p})=>p===Ui.type(i));if(!h)return!1;const c=s,f=s+r.nodeSize,{tr:u}=t,d=Ui.type(i).create({...h.attrs,...e});return d?(n(u.removeMark(c,f,h).addMark(c,f,d).setSelection(new K(u.selection.$anchor)).scrollIntoView()),!0):!1});x(Ub,{displayName:"Command<updateLinkCommand>",group:"Link"});var Gb=Qc("doc",()=>({content:"block+",parseMarkdown:{match:({type:i})=>i==="root",runner:(i,e,t)=>{i.injectRoot(e,t)}},toMarkdown:{match:i=>i.type.name==="doc",runner:(i,e)=>{i.openNode("root");const t=e.childCount>0?e.child(e.childCount-1):null,n=t?.type.name==="paragraph"&&t.content.size===0?e.content.cut(0,e.content.size-t.nodeSize):e.content;i.next(n)}}}));x(Gb,{displayName:"NodeSchema<doc>",group:"Doc"});var Yb=Object.freeze(["root","blockquote","listItem","footnoteDefinition"]),kT=new Set(["paragraph","heading","tableCell","link","linkReference","emphasis","strong","delete","footnote"]),Dl=pn(Yb,"blockContainerTypes");x(Dl,{displayName:"Ctx<blockContainerTypes>",group:"Remark"});var fm=new Set;function Xb(i){const e=i.isInjected(Dl.key)?i.get(Dl.key):Yb,t=new Set;for(const n of e){if(kT.has(n)){fm.has(n)||(fm.add(n),console.warn(`[milkdown/preset-commonmark] "${n}" holds phrasing content and cannot be a block container; it is ignored in blockContainerTypes.`));continue}t.add(n)}return t}var xT=new Set(["paragraph","tableCell"]);function wT(i,e){return f1(i,t=>t.type==="html"&&pT(t.value),(t,n)=>{const r=n[n.length-1];if(r){if(xT.has(r.type)){r.children.length===1&&(r.children=[]);return}if(e.has(r.type)){const s=t;return s.children=[],delete s.value,s.type="paragraph",uh}}})}var ia=wr("remark-preserve-empty-line",i=>()=>e=>wT(e,Xb(i)));x(ia.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});x(ia.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Pf=Nt("paragraph");x(Pf,{displayName:"Attr<paragraph>",group:"Paragraph"});var Oi=xt("paragraph",i=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",i.get(Pf.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,t,n)=>{e.openNode(n),t.children?e.next(t.children):e.addText(t.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,t)=>{e.openNode("paragraph"),(!t.content||t.content.size===0)&&ST(i)?e.addNode("html",void 0,uT):$b(e,t),e.closeNode()}}}));function ST(i){return i.isInjected(ia.options.key)}x(Oi.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});x(Oi.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var Lf=ee("TurnIntoText",i=>()=>ms(Oi.type(i)));x(Lf,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Ff=Tt("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:i=>{const e=i.get(le);return()=>e.call(Lf.key)}}});x(Ff.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});x(Ff.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var CT=Array(6).fill(0).map((i,e)=>e+1);function vT(i){return i.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var ra=pn(vT,"headingIdGenerator");x(ra,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var zf=Nt("heading");x(zf,{displayName:"Attr<heading>",group:"Heading"});var Ti=xt("heading",i=>{const e=i.get(ra.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:CT.map(t=>({tag:`h${t}`,getAttrs:n=>{if(!(n instanceof HTMLElement))throw vi(n);return{level:t,id:n.id}}})),toDOM:t=>[`h${t.attrs.level}`,{...i.get(zf.key)(t),id:t.attrs.id||e(t)},0],parseMarkdown:{match:({type:t})=>t==="heading",runner:(t,n,r)=>{const s=n.depth;t.openNode(r,{level:s}),t.next(n.children),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="heading",runner:(t,n)=>{t.openNode("heading",void 0,{depth:n.attrs.level}),$b(t,n),t.closeNode()}}}});x(Ti.node,{displayName:"NodeSchema<heading>",group:"Heading"});x(Ti.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var Qb=Ot(i=>vg(/^(?<hashes>#+)\s$/,Ti.type(i),e=>{const t=e.groups?.hashes?.length||0,{$from:n}=i.get(on).state.selection,r=n.node();if(r.type.name==="heading"){let s=Number(r.attrs.level)+Number(t);return s>6&&(s=6),{level:s}}return{level:t}}));x(Qb,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var wn=ee("WrapInHeading",i=>e=>(e??=1,e<1?ms(Oi.type(i)):ms(Ti.type(i),{level:e})));x(wn,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Vf=ee("DowngradeHeading",i=>()=>(e,t,n)=>{const{$from:r}=e.selection,s=r.node();if(s.type!==Ti.type(i)||!e.selection.empty||r.parentOffset!==0)return!1;const o=s.attrs.level-1;return o?(t?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...s.attrs,level:o})),!0):ms(Oi.type(i))(e,t)});x(Vf,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var Hf=Tt("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:i=>{const e=i.get(le);return()=>e.call(wn.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:i=>{const e=i.get(le);return()=>e.call(wn.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:i=>{const e=i.get(le);return()=>e.call(wn.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:i=>{const e=i.get(le);return()=>e.call(wn.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:i=>{const e=i.get(le);return()=>e.call(wn.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:i=>{const e=i.get(le);return()=>e.call(wn.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:i=>{const e=i.get(le);return()=>e.call(Vf.key)}}});x(Hf.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});x(Hf.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Wf=Nt("blockquote");x(Wf,{displayName:"Attr<blockquote>",group:"Blockquote"});var ao=xt("blockquote",i=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",i.get(Wf.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,t,n)=>{e.openNode(n).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,t)=>{e.openNode("blockquote").next(t.content).closeNode()}}}));x(ao.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});x(ao.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var Zb=Ot(i=>Kc(/^\s*>\s$/,ao.type(i)));x(Zb,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var $f=ee("WrapInBlockquote",i=>()=>Wc(ao.type(i)));x($f,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Kf=Tt("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:i=>{const e=i.get(le);return()=>e.call($f.key)}}});x(Kf.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});x(Kf.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var qf=Nt("codeBlock",()=>({pre:{},code:{}}));x(qf,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var ho=xt("code_block",i=>({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 vi(e);return{language:e.dataset.language}}}],toDOM:e=>{const t=i.get(qf.key)(e),n=e.attrs.language,r=n&&n.length>0?{"data-language":n}:void 0;return["pre",{...t.pre,...r},["code",t.code,0]]},parseMarkdown:{match:({type:e})=>e==="code",runner:(e,t,n)=>{const r=t.lang??"",s=t.value;e.openNode(n,{language:r}),s&&e.addText(s),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})}}}));x(ho.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});x(ho.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var ek=Ot(i=>vg(/^```(?<language>[a-z]*)?[\s\n]$/,ho.type(i),e=>({language:e.groups?.language??""})));x(ek,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var jf=ee("CreateCodeBlock",i=>(e="")=>ms(ho.type(i),{language:e}));x(jf,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var MT=ee("UpdateCodeBlockLanguage",()=>({pos:i,language:e}={pos:-1,language:""})=>(t,n)=>i>=0?(n?.(t.tr.setNodeAttribute(i,"language",e)),!0):!1);x(MT,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Jf=Tt("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:i=>{const e=i.get(le);return()=>e.call(jf.key)}}});x(Jf.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});x(Jf.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var _f=Nt("image");x(_f,{displayName:"Attr<image>",group:"Image"});var vr=xt("image",i=>({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 vi(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...i.get(_f.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,t,n)=>{const r=t.url,s=t.alt??"",o=t.title??"";e.addNode(n,{src:r,alt:s,title:o})}},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})}}}));x(vr.node,{displayName:"NodeSchema<image>",group:"Image"});x(vr.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var tk=ee("InsertImage",i=>(e={})=>(t,n)=>{if(!n)return!0;const{src:r="",alt:s="",title:o=""}=e,l=vr.type(i).create({src:r,alt:s,title:o});return l&&n(t.tr.replaceSelectionWith(l).scrollIntoView()),!0});x(tk,{displayName:"Command<insertImageCommand>",group:"Image"});var nk=ee("UpdateImage",i=>(e={})=>(t,n)=>{const r=Vw(t.selection,vr.type(i));if(!r)return!1;const{node:s,pos:o}=r,l={...s.attrs},{src:a,alt:h,title:c}=e;return a!==void 0&&(l.src=a),h!==void 0&&(l.alt=h),c!==void 0&&(l.title=c),n?.(t.tr.setNodeMarkup(o,void 0,l).scrollIntoView()),!0});x(nk,{displayName:"Command<updateImageCommand>",group:"Image"});var AT=Ot(i=>new kt(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,t,n,r)=>{const[s,o,l="",a]=t;return s?e.tr.replaceWith(n,r,vr.type(i).create({src:l,alt:o,title:a})):null}));x(AT,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Il=Nt("hardbreak",i=>({"data-type":"hardbreak","data-is-inline":i.attrs.isInline}));x(Il,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var co=xt("hardbreak",i=>({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",i.get(Il.key)(e)," "]:["br",i.get(Il.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,t,n)=>{e.addNode(n,{isInline:!!t.data?.isInline})}},leafText:()=>`
|
|
24
|
+
`);n>-1&&(t=t.slice(0,n))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),n=e+t.length;for(let r=this.rangeIndex;;){let s=this.ranges[r].to;if(s>=n||(t=t.slice(0,s-(n-t.length)),r++,r==this.ranges.length))break;let o=this.ranges[r].from,l=this.lineAfter(o);t+=l,n=o+l.length}return{line:t,end:n}}skipGapsTo(e,t,n){for(;;){let r=this.ranges[this.rangeIndex].to,s=e+t;if(n>0?r>s:r>=s)break;let o=this.ranges[++this.rangeIndex].from;t+=o-r}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,n,r){let s=4;if(this.ranges.length>1){r=this.skipGapsTo(t,r,1),t+=r;let l=this.chunk.length;r=this.skipGapsTo(n,r,-1),n+=r,s+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&s==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==t?this.chunk[o+2]=n:this.chunk.push(e,t,n,s),r}parseLine(e){let{line:t,end:n}=this.nextLine(),r=0,{streamParser:s}=this.lang,o=new Xy(t,e?e.state.tabSize:4,e?wi(e.state):2);if(o.eol())s.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=yb(s.token,o,this.state);if(l&&(r=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,r)),o.start>1e4)break}this.parsedPos=n,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=ie.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:ZA,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new ie(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new ie(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function yb(i,e,t){e.start=e.pos;for(let n=0;n<10;n++){let r=i(e,t);if(e.pos>e.start)return r}throw new Error("Stream parser failed to advance stream.")}const mf=Object.create(null),Is=[je.none],ZA=new qc(Is),Jp=[],_p=Object.create(null),bb=Object.create(null);for(let[i,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])bb[i]=xb(mf,e);class kb{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),bb)}resolve(e){return e?this.table[e]||(this.table[e]=xb(this.extra,e)):0}}const eO=new kb(mf);function Za(i,e){Jp.indexOf(i)>-1||(Jp.push(i),console.warn(e))}function xb(i,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=i[h]||v[h];c?typeof c=="function"?a.length?a=a.map(c):Za(h,`Modifier ${h} used at start of tag`):a.length?Za(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:Za(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let n=e.replace(/ /g,"_"),r=n+" "+t.map(l=>l.id),s=_p[r];if(s)return s.id;let o=_p[r]=je.define({id:Is.length,name:n,props:[hA({[n]:t})]});return Is.push(o),o.id}function tO(i,e){let t=je.define({id:Is.length,name:"Document",props:[ti.add(()=>i),tb.add(()=>n=>e.getIndent(n))],top:!0});return Is.push(t),t}Z.RTL,Z.LTR;function gr(i,e){return i instanceof hs?e==i:i.indexOf(e)>-1}function nO(i,e){return function(t,n){let{$from:r,$to:s,node:o}=t.selection;if(o&&o.isBlock||r.depth<2||!r.sameParent(s))return!1;let l=r.node(-1);if(!gr(i,l.type))return!1;if(r.parent.content.size==0&&r.node(-1).childCount==r.indexAfter(-1)){if(r.depth==3||!gr(i,r.node(-3).type)||r.index(-2)!=r.node(-2).childCount-1)return!1;if(n){let f=A.empty,u=r.index(-1)?1:r.index(-2)?2:3;for(let y=r.depth-u;y>=r.depth-3;y--)f=A.from(r.node(y).copy(f));let d=r.indexAfter(-1)<r.node(-2).childCount?1:r.indexAfter(-2)<r.node(-3).childCount?2:3;f=f.append(A.from(r.node(-3).type.createAndFill()));let p=r.before(r.depth-(u-1)),m=t.tr.replace(p,r.after(-d),new E(f,4-u,0)),g=-1;m.doc.nodesBetween(p,m.doc.content.size,(y,b)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=b+1)}),g>-1&&m.setSelection(_.near(m.doc.resolve(g))),n(m.scrollIntoView())}return!0}let a=s.pos==r.end()?l.contentMatchAt(0).defaultType:null,h=t.tr.delete(r.pos,s.pos),c=a?[null,{type:a}]:void 0;return jr(h.doc,r.pos,2,c)?(n&&n(h.split(r.pos,2,c).scrollIntoView()),!0):!1}}function iO(i){return function(e,t){let{$from:n,$to:r}=e.selection,s=n.blockRange(r,o=>o.childCount>0&&gr(i,o.firstChild.type));return s?t?gr(i,n.node(s.depth-1).type)?rO(e,t,s):sO(e,t,s):!0:!1}}function rO(i,e,t){let n=i.tr,r=t.end,s=t.$to.end(t.depth),o=t.parent.child(t.endIndex-1).type;r<s&&(n.step(new Be(r-1,s,r,s,new E(A.from(o.create(null,t.parent.copy())),1,0),1,!0)),t=new Sm(n.doc.resolve(t.$from.pos),n.doc.resolve(s),t.depth));const l=Il(t);if(l==null)return!1;n.lift(t,l);let a=n.doc.resolve(n.mapping.map(r,-1)-1);return El(n.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&n.join(a.pos),e(n.scrollIntoView()),!0}function sO(i,e,t){let n=i.tr,r=t.parent;for(let d=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)d-=r.child(p).nodeSize,n.delete(d-1,d+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==r.childCount,h=s.node(-1),c=s.index(-1);if(!h.canReplace(c+(l?0:1),c+1,o.content.append(a?A.empty:A.from(r))))return!1;let f=s.pos,u=f+o.nodeSize;return n.step(new Be(f-(l?1:0),u+(a?1:0),f+1,u-1,new E((l?A.empty:A.from(r.copy(A.empty))).append(a?A.empty:A.from(r.copy(A.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function oO(i){return function(e,t){let{$from:n,$to:r}=e.selection,s=n.blockRange(r,h=>h.childCount>0&&gr(i,h.firstChild.type));if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(!gr(i,a.type))return!1;if(t){let h=a.lastChild&&a.lastChild.type==l.type,c=A.from(h?a.lastChild.lastChild.type.create():null),f=new E(A.from(a.type.create(null,A.from(l.type.create(null,c)))),h?3:1,0),u=s.start,d=s.end;t(e.tr.step(new Be(u-(h?3:1),d,u,d,f,1,!0)).scrollIntoView())}return!0}}function lO(i){const e=new Map;if(!i||!i.type)throw new Error("mdast-util-definitions expected node");return js(i,"definition",function(n){const r=Up(n.identifier);r&&!e.get(r)&&e.set(r,n)}),t;function t(n){const r=Up(n);return e.get(r)}}function Up(i){return String(i||"").toUpperCase()}function aO(){return function(i){const e=lO(i);js(i,function(t,n,r){if(t.type==="definition"&&r!==void 0&&typeof n=="number")return r.children.splice(n,1),[oh,n];if(t.type==="imageReference"||t.type==="linkReference"){const s=e(t.identifier);if(s&&r&&typeof n=="number")return r.children[n]=t.type==="imageReference"?{type:"image",url:s.url,title:s.title,alt:t.alt}:{type:"link",url:s.url,title:s.title,children:t.children},[oh,n]}})}}function hO(i){const e={...i};return e.position&&(e.position={start:{...e.position.start},end:{...e.position.end}}),delete e.children,e}var cO="<br />",fO=/^<br\s*\/?\s*>$/i,uO=i=>typeof i=="string"&&fO.test(i.trim());function wb(i,e){if(!(e.childCount>=1&&e.lastChild?.type.name==="hardbreak")){i.next(e.content);return}const t=[];e.content.forEach((n,r,s)=>{s!==e.childCount-1&&t.push(n)}),i.next(A.fromArray(t))}function x(i,e){return Object.assign(i,{meta:{package:"@milkdown/preset-commonmark",...e}}),i}var gf=Wl("emphasis");x(gf,{displayName:"Attr<emphasis>",group:"Emphasis"});var wr=Qs("emphasis",i=>({attrs:{marker:{default:i.get(Ur).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",i.get(gf.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,t,n)=>{e.openMark(n,{marker:t.marker}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,t)=>{e.withMark(t,"emphasis",void 0,{marker:t.attrs.marker})}}}));x(wr.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});x(wr.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var yf=ee("ToggleEmphasis",i=>()=>Rc(wr.type(i)));x(yf,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var Sb=Ot(i=>Fl(/(?:^|[^*])\*([^*]+)\*$/,wr.type(i),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:t+1}}));x(Sb,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var Cb=Ot(i=>Fl(/\b_(?![_\s])(.*?[^_\s])_$/,wr.type(i),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:t})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:t+1}}));x(Cb,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var bf=Tt("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:i=>{const e=i.get(le);return()=>e.call(yf.key)}}});x(bf.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});x(bf.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var kf=Wl("strong");x(kf,{displayName:"Attr<strong>",group:"Strong"});var ro=Qs("strong",i=>({attrs:{marker:{default:i.get(Ur).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",i.get(kf.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,t,n)=>{e.openMark(n,{marker:t.marker}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,t)=>{e.withMark(t,"strong",void 0,{marker:t.attrs.marker})}}}));x(ro.mark,{displayName:"MarkSchema<strong>",group:"Strong"});x(ro.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var xf=ee("ToggleStrong",i=>()=>Rc(ro.type(i)));x(xf,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var vb=Ot(i=>Fl(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),ro.type(i),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));x(vb,{displayName:"InputRule<strong>",group:"Strong"});var wf=Tt("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:i=>{const e=i.get(le);return()=>e.call(xf.key)}}});x(wf.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});x(wf.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var Sf=Wl("inlineCode");x(Sf,{displayName:"Attr<inlineCode>",group:"InlineCode"});var Nn=Qs("inlineCode",i=>({priority:100,code:!0,inclusive:!1,parseDOM:[{tag:"code"}],toDOM:e=>["code",i.get(Sf.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,t,n)=>{e.openMark(n),e.addText(t.value),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,t,n)=>(e.withMark(t,"inlineCode",n.text||""),!0)}}));x(Nn.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});x(Nn.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Cf=ee("ToggleInlineCode",i=>()=>(e,t)=>{const{selection:n,tr:r}=e;if(n.empty)return!1;const{from:s,to:o}=n;return e.doc.rangeHasMark(s,o,Nn.type(i))?(t?.(r.removeMark(s,o,Nn.type(i))),!0):(Object.keys(e.schema.marks).filter(l=>l!==Nn.type.name).map(l=>e.schema.marks[l]).forEach(l=>{r.removeMark(s,o,l)}),t?.(r.addMark(s,o,Nn.type(i).create())),!0)});x(Cf,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var Mb=Ot(i=>Fl(/(?:`)([^`]+)(?:`)$/,Nn.type(i)));x(Mb,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var vf=Tt("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:i=>{const e=i.get(le);return()=>e.call(Cf.key)}}});x(vf.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});x(vf.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var dO=new Set(["http:","https:","mailto:","tel:","ftp:"]);function pO(i){return i<=32||i>=127&&i<=160||i>=8203&&i<=8205||i===8232||i===8233||i===65279}function mO(i){let e="";for(const t of i)pO(t.codePointAt(0)??0)||(e+=t);return e}function gO(i){if(typeof i!="string")return"";const e=i.trim();if(!e)return"";const t=mO(e),n=/^([a-z][a-z0-9+.-]*):/i.exec(t)?.[1];return!n||dO.has(`${n.toLowerCase()}:`)?e:""}var Mf=Wl("link");x(Mf,{displayName:"Attr<link>",group:"Link"});var _i=Qs("link",i=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Ci(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...i.get(Mf.key)(e),...e.attrs,href:gO(e.attrs.href)}],parseMarkdown:{match:e=>e.type==="link",runner:(e,t,n)=>{const r=t.url,s=t.title;e.openMark(n,{href:r,title:s}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,t)=>{e.withMark(t,"link",void 0,{title:t.attrs.title,url:t.attrs.href})}}}));x(_i.mark,{displayName:"MarkSchema<link>",group:"Link"});var Ab=ee("ToggleLink",i=>(e={})=>Rc(_i.type(i),e));x(Ab,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Ob=ee("UpdateLink",i=>(e={})=>(t,n)=>{if(!n)return!1;let r,s=-1;const{selection:o}=t,{from:l,to:a}=o;if(t.doc.nodesBetween(l,l===a?a+1:a,(p,m)=>{if(_i.type(i).isInSet(p.marks))return r=p,s=m,!1}),!r)return!1;const h=r.marks.find(({type:p})=>p===_i.type(i));if(!h)return!1;const c=s,f=s+r.nodeSize,{tr:u}=t,d=_i.type(i).create({...h.attrs,...e});return d?(n(u.removeMark(c,f,h).addMark(c,f,d).setSelection(new K(u.selection.$anchor)).scrollIntoView()),!0):!1});x(Ob,{displayName:"Command<updateLinkCommand>",group:"Link"});var Tb=Kc("doc",()=>({content:"block+",parseMarkdown:{match:({type:i})=>i==="root",runner:(i,e,t)=>{i.injectRoot(e,t)}},toMarkdown:{match:i=>i.type.name==="doc",runner:(i,e)=>{i.openNode("root");const t=e.childCount>0?e.child(e.childCount-1):null,n=t?.type.name==="paragraph"&&t.content.size===0?e.content.cut(0,e.content.size-t.nodeSize):e.content;i.next(n)}}}));x(Tb,{displayName:"NodeSchema<doc>",group:"Doc"});var Nb=Object.freeze(["root","blockquote","listItem","footnoteDefinition"]),yO=new Set(["paragraph","heading","tableCell","link","linkReference","emphasis","strong","delete","footnote"]),Ml=pn(Nb,"blockContainerTypes");x(Ml,{displayName:"Ctx<blockContainerTypes>",group:"Remark"});var Gp=new Set;function Db(i){const e=i.isInjected(Ml.key)?i.get(Ml.key):Nb,t=new Set;for(const n of e){if(yO.has(n)){Gp.has(n)||(Gp.add(n),console.warn(`[milkdown/preset-commonmark] "${n}" holds phrasing content and cannot be a block container; it is ignored in blockContainerTypes.`));continue}t.add(n)}return t}var bO=new Set(["paragraph","tableCell"]);function kO(i,e){return Pk(i,t=>t.type==="html"&&uO(t.value),(t,n)=>{const r=n[n.length-1];if(r){if(bO.has(r.type)){r.children.length===1&&(r.children=[]);return}if(e.has(r.type)){const s=t;return s.children=[],delete s.value,s.type="paragraph",oh}}})}var Ql=kr("remark-preserve-empty-line",i=>()=>e=>kO(e,Db(i)));x(Ql.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});x(Ql.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Af=Nt("paragraph");x(Af,{displayName:"Attr<paragraph>",group:"Paragraph"});var Ai=xt("paragraph",i=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",i.get(Af.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,t,n)=>{e.openNode(n),t.children?e.next(t.children):e.addText(t.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,t)=>{e.openNode("paragraph"),(!t.content||t.content.size===0)&&xO(i)?e.addNode("html",void 0,cO):wb(e,t),e.closeNode()}}}));function xO(i){return i.isInjected(Ql.options.key)}x(Ai.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});x(Ai.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var Of=ee("TurnIntoText",i=>()=>us(Ai.type(i)));x(Of,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Tf=Tt("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:i=>{const e=i.get(le);return()=>e.call(Of.key)}}});x(Tf.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});x(Tf.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var wO=Array(6).fill(0).map((i,e)=>e+1);function SO(i){return i.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Zl=pn(SO,"headingIdGenerator");x(Zl,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Nf=Nt("heading");x(Nf,{displayName:"Attr<heading>",group:"Heading"});var Oi=xt("heading",i=>{const e=i.get(Zl.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:wO.map(t=>({tag:`h${t}`,getAttrs:n=>{if(!(n instanceof HTMLElement))throw Ci(n);return{level:t,id:n.id}}})),toDOM:t=>[`h${t.attrs.level}`,{...i.get(Nf.key)(t),id:t.attrs.id||e(t)},0],parseMarkdown:{match:({type:t})=>t==="heading",runner:(t,n,r)=>{const s=n.depth;t.openNode(r,{level:s}),t.next(n.children),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="heading",runner:(t,n)=>{t.openNode("heading",void 0,{depth:n.attrs.level}),wb(t,n),t.closeNode()}}}});x(Oi.node,{displayName:"NodeSchema<heading>",group:"Heading"});x(Oi.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var Ib=Ot(i=>ig(/^(?<hashes>#+)\s$/,Oi.type(i),e=>{const t=e.groups?.hashes?.length||0,{$from:n}=i.get(on).state.selection,r=n.node();if(r.type.name==="heading"){let s=Number(r.attrs.level)+Number(t);return s>6&&(s=6),{level:s}}return{level:t}}));x(Ib,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var wn=ee("WrapInHeading",i=>e=>(e??=1,e<1?us(Ai.type(i)):us(Oi.type(i),{level:e})));x(wn,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Df=ee("DowngradeHeading",i=>()=>(e,t,n)=>{const{$from:r}=e.selection,s=r.node();if(s.type!==Oi.type(i)||!e.selection.empty||r.parentOffset!==0)return!1;const o=s.attrs.level-1;return o?(t?.(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...s.attrs,level:o})),!0):us(Ai.type(i))(e,t)});x(Df,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var If=Tt("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:i=>{const e=i.get(le);return()=>e.call(wn.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:i=>{const e=i.get(le);return()=>e.call(wn.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:i=>{const e=i.get(le);return()=>e.call(wn.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:i=>{const e=i.get(le);return()=>e.call(wn.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:i=>{const e=i.get(le);return()=>e.call(wn.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:i=>{const e=i.get(le);return()=>e.call(wn.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:i=>{const e=i.get(le);return()=>e.call(Df.key)}}});x(If.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});x(If.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Ef=Nt("blockquote");x(Ef,{displayName:"Attr<blockquote>",group:"Blockquote"});var so=xt("blockquote",i=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",i.get(Ef.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,t,n)=>{e.openNode(n).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,t)=>{e.openNode("blockquote").next(t.content).closeNode()}}}));x(so.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});x(so.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var Eb=Ot(i=>Bc(/^\s*>\s$/,so.type(i)));x(Eb,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Rf=ee("WrapInBlockquote",i=>()=>Ec(so.type(i)));x(Rf,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Bf=Tt("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:i=>{const e=i.get(le);return()=>e.call(Rf.key)}}});x(Bf.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});x(Bf.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var Pf=Nt("codeBlock",()=>({pre:{},code:{}}));x(Pf,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var oo=xt("code_block",i=>({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 Ci(e);return{language:e.dataset.language}}}],toDOM:e=>{const t=i.get(Pf.key)(e),n=e.attrs.language,r=n&&n.length>0?{"data-language":n}:void 0;return["pre",{...t.pre,...r},["code",t.code,0]]},parseMarkdown:{match:({type:e})=>e==="code",runner:(e,t,n)=>{const r=t.lang??"",s=t.value;e.openNode(n,{language:r}),s&&e.addText(s),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})}}}));x(oo.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});x(oo.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var Rb=Ot(i=>ig(/^```(?<language>[a-z]*)?[\s\n]$/,oo.type(i),e=>({language:e.groups?.language??""})));x(Rb,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Lf=ee("CreateCodeBlock",i=>(e="")=>us(oo.type(i),{language:e}));x(Lf,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var CO=ee("UpdateCodeBlockLanguage",()=>({pos:i,language:e}={pos:-1,language:""})=>(t,n)=>i>=0?(n?.(t.tr.setNodeAttribute(i,"language",e)),!0):!1);x(CO,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Ff=Tt("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:i=>{const e=i.get(le);return()=>e.call(Lf.key)}}});x(Ff.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});x(Ff.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Vf=Nt("image");x(Vf,{displayName:"Attr<image>",group:"Image"});var Sr=xt("image",i=>({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 Ci(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...i.get(Vf.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,t,n)=>{const r=t.url,s=t.alt??"",o=t.title??"";e.addNode(n,{src:r,alt:s,title:o})}},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})}}}));x(Sr.node,{displayName:"NodeSchema<image>",group:"Image"});x(Sr.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var Bb=ee("InsertImage",i=>(e={})=>(t,n)=>{if(!n)return!0;const{src:r="",alt:s="",title:o=""}=e,l=Sr.type(i).create({src:r,alt:s,title:o});return l&&n(t.tr.replaceSelectionWith(l).scrollIntoView()),!0});x(Bb,{displayName:"Command<insertImageCommand>",group:"Image"});var Pb=ee("UpdateImage",i=>(e={})=>(t,n)=>{const r=Fx(t.selection,Sr.type(i));if(!r)return!1;const{node:s,pos:o}=r,l={...s.attrs},{src:a,alt:h,title:c}=e;return a!==void 0&&(l.src=a),h!==void 0&&(l.alt=h),c!==void 0&&(l.title=c),n?.(t.tr.setNodeMarkup(o,void 0,l).scrollIntoView()),!0});x(Pb,{displayName:"Command<updateImageCommand>",group:"Image"});var vO=Ot(i=>new kt(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,t,n,r)=>{const[s,o,l="",a]=t;return s?e.tr.replaceWith(n,r,Sr.type(i).create({src:l,alt:o,title:a})):null}));x(vO,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Al=Nt("hardbreak",i=>({"data-type":"hardbreak","data-is-inline":i.attrs.isInline}));x(Al,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var lo=xt("hardbreak",i=>({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",i.get(Al.key)(e)," "]:["br",i.get(Al.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,t,n)=>{e.addNode(n,{isInline:!!t.data?.isInline})}},leafText:()=>`
|
|
47
25
|
`,toMarkdown:{match:e=>e.type.name==="hardbreak",runner:(e,t)=>{t.attrs.isInline?e.addNode("text",void 0,`
|
|
48
|
-
`):e.addNode("break")}}}));x(co.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});x(co.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Uf=ee("InsertHardbreak",i=>()=>(e,t)=>{const{selection:n,tr:r}=e;if(!(n instanceof K))return!1;if(n.empty){const s=n.$from.node();if(s.childCount>0&&s.lastChild?.type.name==="hardbreak")return t?.(r.replaceRangeWith(n.to-1,n.to,e.schema.node("paragraph")).setSelection(_.near(r.doc.resolve(n.to))).scrollIntoView()),!0}return t?.(r.setMeta("hardbreak",!0).replaceSelectionWith(co.type(i).create(),!1).scrollIntoView()),!0});x(Uf,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Gf=Tt("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:i=>{const e=i.get(le);return()=>e.call(Uf.key)}}});x(Gf.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});x(Gf.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Yf=Nt("hr");x(Yf,{displayName:"Attr<hr>",group:"Hr"});var fo=xt("hr",i=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",i.get(Yf.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,t,n)=>{e.addNode(n)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));x(fo.node,{displayName:"NodeSchema<hr>",group:"Hr"});x(fo.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var ik=Ot(i=>new kt(/^(?:---|___\s|\*\*\*\s)$/,(e,t,n,r)=>{const{tr:s}=e;return t[0]&&s.replaceWith(n-1,r,fo.type(i).create()),s}));x(ik,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var rk=ee("InsertHr",i=>()=>(e,t)=>{if(!t)return!0;const n=Oi.node.type(i).create(),{tr:r,selection:s}=e,{from:o}=s,l=fo.type(i).create();if(!l)return!0;const a=r.replaceSelectionWith(l).insert(o,n),h=_.findFrom(a.doc.resolve(o),1,!0);return h&&t(a.setSelection(h).scrollIntoView()),!0});x(rk,{displayName:"Command<insertHrCommand>",group:"Hr"});var Xf=Nt("bulletList");x(Xf,{displayName:"Attr<bulletList>",group:"BulletList"});var Mr=xt("bullet_list",i=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw vi(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...i.get(Xf.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!t,runner:(e,t,n)=>{const r=t.spread??!1;e.openNode(n,{spread:r}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!1,spread:t.attrs.spread}).next(t.content).closeNode()}}}));x(Mr.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});x(Mr.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var sk=Ot(i=>Kc(/^\s*([-+*])\s$/,Mr.type(i)));x(sk,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var Qf=ee("WrapInBulletList",i=>()=>Wc(Mr.type(i)));x(Qf,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Zf=Tt("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:i=>{const e=i.get(le);return()=>e.call(Qf.key)}}});x(Zf.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});x(Zf.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var eu=Nt("orderedList");x(eu,{displayName:"Attr<orderedList>",group:"OrderedList"});var Ar=xt("ordered_list",i=>({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 vi(e);return{spread:e.dataset.spread==="true",order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...i.get(eu.key)(e),...e.attrs.order===1?{}:{start:e.attrs.order},"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!!t,runner:(e,t,n)=>{const r=t.spread??!0;e.openNode(n,{spread:r,order:t.start??1}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!0,start:t.attrs.order??1,spread:t.attrs.spread}),e.next(t.content),e.closeNode()}}}));x(Ar.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});x(Ar.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var ok=Ot(i=>Kc(/^\s*(\d+)\.\s$/,Ar.type(i),e=>({order:Number(e[1])}),(e,t)=>t.childCount+t.attrs.order===Number(e[1])));x(ok,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var tu=ee("WrapInOrderedList",i=>()=>Wc(Ar.type(i)));x(tu,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var nu=Tt("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:i=>{const e=i.get(le);return()=>e.call(tu.key)}}});x(nu.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});x(nu.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var iu=Nt("listItem");x(iu,{displayName:"Attr<listItem>",group:"ListItem"});var Jn=xt("list_item",i=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"•",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw vi(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...i.get(iu.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,n)=>{const r=t.label!=null?`${t.label}.`:"•",s=t.label!=null?"ordered":"bullet",o=t.spread??!0;e.openNode(n,{label:r,listType:s,spread:o}),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()}}}));x(Jn.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});x(Jn.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var ru=ee("SinkListItem",i=>()=>aT(Jn.type(i)));x(ru,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var su=ee("LiftListItem",i=>()=>sT(Jn.type(i)));x(su,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var ou=ee("SplitListItem",i=>()=>(e,t,n)=>rT(Jn.type(i))(e,t&&(r=>{const{$from:s}=e.selection;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){const{$from:o}=r.selection;r.setNodeMarkup(o.before(-1),void 0,s.node(-3).attrs)}t(r)})));x(ou,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function OT(i){return(e,t,n)=>{const{selection:r}=e;if(!(r instanceof K))return!1;const{empty:s,$from:o}=r;return!s||o.parentOffset!==0||o.node(-1).type!==Jn.type(i)?!1:bg(e,t,n)}}var lu=ee("LiftFirstListItem",i=>()=>OT(i));x(lu,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var au=Tt("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:i=>{const e=i.get(le);return()=>e.call(ou.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:i=>{const e=i.get(le);return()=>e.call(ru.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:i=>{const e=i.get(le);return()=>e.call(su.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:i=>{const e=i.get(le);return()=>e.call(lu.key)}}});x(au.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});x(au.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var lk=Qc("text",()=>({group:"inline",parseMarkdown:{match:({type:i})=>i==="text",runner:(i,e)=>{i.addText(e.value)}},toMarkdown:{match:i=>i.type.name==="text",runner:(i,e)=>{i.addNode("text",void 0,e.text)}}}));x(lk,{displayName:"NodeSchema<text>",group:"Text"});var hu=Nt("html");x(hu,{displayName:"Attr<html>",group:"Html"});var cu=xt("html",i=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{const t=document.createElement("span"),n={...i.get(hu.key)(e),"data-value":e.attrs.value,"data-type":"html"};return t.textContent=e.attrs.value,["span",n,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,t,n)=>{e.addNode(n,{value:t.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,t)=>{e.addNode("html",void 0,t.attrs.value)}}}));x(cu.node,{displayName:"NodeSchema<html>",group:"Html"});x(cu.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var TT=[Gb,Pf,Oi,ra,zf,Ti,Il,co,Wf,ao,qf,ho,Yf,fo,_f,vr,Xf,Mr,eu,Ar,iu,Jn,Mf,Cr,Tf,lo,If,Nn,Bf,Ui,hu,cu,lk].flat(),NT=[Zb,sk,ok,ek,ik,Qb].flat(),DT=[Kb,qb,Jb,jb],IT=ee("IsMarkSelected",()=>i=>e=>{if(!i)return!1;const{doc:t,selection:n}=e;return t.rangeHasMark(n.from,n.to,i)}),ET=ee("IsNoteSelected",()=>i=>e=>i?Hw(e,i).hasNode:!1),RT=ee("ClearTextInCurrentBlock",()=>()=>(i,e)=>{let t=i.tr;const{$from:n,$to:r}=t.selection,{pos:s}=n,{pos:o}=r,l=s-n.node().content.size;return l<0?!1:(t=t.deleteRange(l,o),e?.(t),!0)}),BT=ee("SetBlockType",()=>i=>(e,t)=>{const{nodeType:n,attrs:r=null}=i??{};if(!n)return!1;const s=e.tr,{from:o,to:l}=s.selection;try{s.setBlockType(o,l,n,r)}catch{return!1}return t?.(s),!0}),PT=ee("WrapInBlockType",()=>i=>(e,t)=>{const{nodeType:n,attrs:r=null}=i??{};if(!n)return!1;let s=e.tr;try{const{$from:o,$to:l}=s.selection,a=o.blockRange(l),h=a&&Lc(a,n,r);if(!h)return!1;s=s.wrap(a,h)}catch{return!1}return t?.(s),!0}),LT=ee("AddBlockType",()=>i=>(e,t)=>{const{nodeType:n,attrs:r=null}=i??{};if(!n)return!1;const s=e.tr;try{const o=n instanceof yt?n:n.createAndFill(r);if(!o)return!1;s.replaceSelectionWith(o)}catch{return!1}return t?.(s),!0}),FT=ee("SelectTextNearPos",()=>i=>(e,t)=>{const{pos:n}=i??{};if(n==null)return!1;const r=(o,l,a)=>Math.min(Math.max(o,l),a),s=e.tr;try{const o=e.doc.resolve(r(n,0,e.doc.content.size));s.setSelection(K.near(o))}catch{return!1}return t?.(s.scrollIntoView()),!0}),zT=[Lf,$f,wn,Vf,jf,Uf,rk,tk,nk,tu,Qf,ru,ou,su,lu,Af,Ef,Nf,_b,Ub,IT,ET,RT,BT,PT,LT,FT],VT=[Kf,Jf,Gf,Hf,au,nu,Zf,Ff,Of,Rf,Df].flat(),fu=wr("remarkAddOrderInList",()=>()=>i=>{Us(i,"list",e=>{if(e.ordered){const t=e.start??1;e.children.forEach((n,r)=>{n.label=r+t})}})});x(fu.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});x(fu.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var uu=wr("remarkLineBreak",()=>()=>i=>{const e=new RegExp("(?<![\\t ])[\\t ]*(?:\\r?\\n|\\r)","g");Us(i,"text",(t,n,r)=>{if(!t.value||typeof t.value!="string")return;const s=[];let o=0;e.lastIndex=0;let l=e.exec(t.value);for(;l;){const a=l.index;o!==a&&s.push({type:"text",value:t.value.slice(o,a)}),s.push({type:"break",data:{isInline:!0}}),o=a+l[0].length,l=e.exec(t.value)}if(s.length>0&&r&&typeof n=="number")return o<t.value.length&&s.push({type:"text",value:t.value.slice(o)}),r.children.splice(n,1,...s),n+s.length})});x(uu.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});x(uu.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var du=wr("remarkInlineLink",()=>cT);x(du.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});x(du.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var HT=i=>!!i.children,WT=i=>i.type==="html";function $T(i,e){return t(i,0,null)[0];function t(n,r,s){if(HT(n)){const o=[];for(let l=0,a=n.children.length;l<a;l++){const h=n.children[l];if(h){const c=t(h,l,n);if(c)for(let f=0,u=c.length;f<u;f++){const d=c[f];d&&o.push(d)}}}n.children=o}return e(n,r,s)}}var pu=wr("remarkHTMLTransformer",i=>()=>e=>{const t=Xb(i);$T(e,(n,r,s)=>WT(n)?(s&&t.has(s.type)&&(n.children=[fT(n)],delete n.value,n.type="paragraph"),[n]):[n])});x(pu.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});x(pu.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var mu=wr("remarkMarker",()=>()=>(i,e)=>{const t=n=>e.value.charAt(n.position.start.offset);Us(i,n=>["strong","emphasis"].includes(n.type),n=>{n.marker=t(n)})});x(mu.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});x(mu.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var ak=eo(()=>{let i=!1;const e=new Kn("MILKDOWN_INLINE_NODES_CURSOR"),t=new un({key:e,state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;const r=n.selection.$from,s=r.nodeBefore,o=r.nodeAfter;return!!(s&&o&&s.isInline&&!s.isText&&o.isInline&&!o.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>i?(i=!1,requestAnimationFrame(()=>{if(t.getState(n.state)){const s=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",s))}}),!0):!1,compositionstart:n=>(t.getState(n.state)&&(i=!0),!1),beforeinput:(n,r)=>{if(t.getState(n.state)&&r instanceof InputEvent&&r.data&&!i){const s=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",s)),!0}return!1}},decorations(n){if(t.getState(n)){const r=n.selection.$from.pos,s=document.createElement("span"),o=Ln.widget(r,s,{side:-1}),l=document.createElement("span"),a=Ln.widget(r,l);return setTimeout(()=>{s.contentEditable="true",l.contentEditable="true"}),de.create(n.doc,[o,a])}return de.empty}}});return t});x(ak,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var hk=eo(i=>new un({key:new Kn("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,t,n)=>{if(!e.length)return;const r=co.type(i);let s;return e.forEach((o,l)=>{o.steps.forEach((a,h)=>{if(!(a instanceof zt))return;const c=(d,p)=>e.slice(l).reduce((m,g,y)=>(y===0?g.mapping.slice(h+1):g.mapping).map(m,p),d),f=c(a.from,-1),u=c(a.to,1);n.doc.nodesBetween(f,u,(d,p)=>{d.type!==r||d.attrs.isInline||d.marks.length&&(s??=n.tr,s.setNodeMarkup(p,r,d.attrs,[]))})})}),s}}));x(hk,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var gu=pn(["table","code_block"],"hardbreakFilterNodes");x(gu,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var ck=eo(i=>{const e=i.get(gu.key);return new un({key:new Kn("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(t,n)=>{const r=t.getMeta("hardbreak"),[s]=t.steps;if(r&&s instanceof ue){const o=n.doc.resolve(s.from);let l=o.depth,a=!0;for(;l>0;)e.includes(o.node(l).type.name)&&(a=!1),l--;return a}return!0}})});x(ck,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var fk=eo(i=>{const e=new Kn("MILKDOWN_HEADING_ID"),t=n=>{if(n.composing)return;const r=i.get(ra.key),s=n.state.tr.setMeta("addToHistory",!1);let o=!1;const l={};n.state.doc.descendants((a,h)=>{if(a.type===Ti.type(i)){if(a.textContent.trim().length===0)return;const c=a.attrs;let f=r(a);l[f]?(l[f]+=1,f+=`-#${l[f]}`):l[f]=1,c.id!==f&&(o=!0,s.setMeta(e,!0).setNodeMarkup(h,void 0,{...c,id:f}))}}),o&&n.dispatch(s)};return new un({key:e,view:n=>(t(n),{update:(r,s)=>{r.state.doc.eq(s.doc)||t(r)}})})});x(fk,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var uk=eo(i=>{const e=(t,n,r)=>{if(!r.selection||t.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;const s=Ar.type(i),o=Mr.type(i),l=Jn.type(i),a=(f,u,d=1)=>{let p=!1;const m=`${u+d}.`;return f.label!==m&&(f.label=m,p=!0),p};let h=r.tr,c=!1;return r.doc.descendants((f,u,d,p)=>{if(f.type===o){const m=f.maybeChild(0);m?.type===l&&m.attrs.listType==="ordered"&&(c=!0,h.setNodeMarkup(u,s,{spread:!0}),f.descendants((g,y,b,k)=>{if(g.type===l){const O={...g.attrs};a(O,k)&&(h=h.setNodeMarkup(y,void 0,O))}return!1}))}else if(f.type===l&&d?.type===s){const m={...f.attrs};let g=!1;m.listType!=="ordered"&&(m.listType="ordered",g=!0),d?.maybeChild(0)&&(g=a(m,p,d?.attrs.order??1)),g&&(h=h.setNodeMarkup(u,void 0,m),c=!0)}}),c?h.setMeta("addToHistory",!1):null};return new un({key:new Kn("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});x(uk,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var KT=[hk,gu,ck,ak,Dl,fu,du,uu,pu,mu,ia,fk,uk].flat(),UI=[TT,NT,DT,zT,VT,KT].flat();const qT=i=>{let{state:e}=i,t=e.doc.lineAt(e.selection.main.from),n=bu(i.state,t.from);return n.line?jT(i):n.block?_T(i):!1};function yu(i,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=i(e,t);return r?(n(t.update(r)),!0):!1}}const jT=yu(YT,0),JT=yu(dk,0),_T=yu((i,e)=>dk(i,e,GT(e)),0);function bu(i,e){let t=i.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Pr=50;function UT(i,{open:e,close:t},n,r){let s=i.sliceDoc(n-Pr,n),o=i.sliceDoc(r,r+Pr),l=/\s*$/.exec(s)[0].length,a=/^\s*/.exec(o)[0].length,h=s.length-l;if(s.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:n-l,margin:l&&1},close:{pos:r+a,margin:a&&1}};let c,f;r-n<=2*Pr?c=f=i.sliceDoc(n,r):(c=i.sliceDoc(n,n+Pr),f=i.sliceDoc(r-Pr,r));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:n+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:r-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function GT(i){let e=[];for(let t of i.selection.ranges){let n=i.doc.lineAt(t.from),r=t.to<=n.to?n:i.doc.lineAt(t.to);r.from>n.from&&r.from==t.to&&(r=t.to==n.to+1?n:i.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>n.from?e[s].to=r.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:r.to})}return e}function dk(i,e,t=e.selection.ranges){let n=t.map(s=>bu(e,s.from).block);if(!n.every(s=>s))return null;let r=t.map((s,o)=>UT(e,n[o],s.from,s.to));if(i!=2&&!r.every(s=>s))return{changes:e.changes(t.map((s,o)=>r[o]?[]:[{from:s.from,insert:n[o].open+" "},{from:s.to,insert:" "+n[o].close}]))};if(i!=1&&r.some(s=>s)){let s=[];for(let o=0,l;o<r.length;o++)if(l=r[o]){let a=n[o],{open:h,close:c}=l;s.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:s}}return null}function YT(i,e,t=e.selection.ranges){let n=[],r=-1;e:for(let{from:s,to:o}of t){let l=n.length,a=1e9,h;for(let c=s;c<=o;){let f=e.doc.lineAt(c);if(h==null&&(h=bu(e,f.from).line,!h))continue e;if(f.from>r&&(s==o||o>f.from)){r=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+h.length)==h?u:-1;u<f.text.length&&u<a&&(a=u),n.push({line:f,comment:p,token:h,indent:u,empty:d,single:!1})}c=f.to+1}if(a<1e9)for(let c=l;c<n.length;c++)n[c].indent<n[c].line.text.length&&(n[c].indent=a);n.length==l+1&&(n[l].single=!0)}if(i!=2&&n.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of n)(f||!c)&&s.push({from:l.from+h,insert:a+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(i!=1&&n.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:l,token:a}of n)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,s.push({from:h,to:c})}return{changes:s}}return null}const Nc=mn.define(),XT=mn.define(),QT=D.define(),pk=D.define({combine(i){return Ai(i,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),mk=Ge.define({create(){return qt.empty},update(i,e){let t=e.state.facet(pk),n=e.annotation(Nc);if(n){let a=Ze.fromTransaction(e,n.selection),h=n.side,c=h==0?i.undone:i.done;return a?c=El(c,c.length,t.minDepth,a):c=bk(c,e.startState.selection),new qt(h==0?n.rest:c,h==0?c:n.rest)}let r=e.annotation(XT);if((r=="full"||r=="before")&&(i=i.isolate()),e.annotation(pe.addToHistory)===!1)return e.changes.empty?i:i.addMapping(e.changes.desc);let s=Ze.fromTransaction(e),o=e.annotation(pe.time),l=e.annotation(pe.userEvent);return s?i=i.addChanges(s,o,l,t,e):e.selection&&(i=i.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(r=="full"||r=="after")&&(i=i.isolate()),i},toJSON(i){return{done:i.done.map(e=>e.toJSON()),undone:i.undone.map(e=>e.toJSON())}},fromJSON(i){return new qt(i.done.map(Ze.fromJSON),i.undone.map(Ze.fromJSON))}});function GI(i={}){return[mk,pk.of(i),R.domEventHandlers({beforeinput(e,t){let n=e.inputType=="historyUndo"?gk:e.inputType=="historyRedo"?Dc:null;return n?(e.preventDefault(),n(t)):!1}})]}function sa(i,e){return function({state:t,dispatch:n}){if(!e&&t.readOnly)return!1;let r=t.field(mk,!1);if(!r)return!1;let s=r.pop(i,t,e);return s?(n(s),!0):!1}}const gk=sa(0,!1),Dc=sa(1,!1),ZT=sa(0,!0),eN=sa(1,!0);class Ze{constructor(e,t,n,r,s){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=s}setSelAfter(e){return new Ze(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(e){return new Ze(e.changes&&me.fromJSON(e.changes),[],e.mapped&&Jt.fromJSON(e.mapped),e.startSelection&&S.fromJSON(e.startSelection),e.selectionsAfter.map(S.fromJSON))}static fromTransaction(e,t){let n=mt;for(let r of e.startState.facet(QT)){let s=r(e);s.length&&(n=n.concat(s))}return!n.length&&e.changes.empty?null:new Ze(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,mt)}static selection(e){return new Ze(void 0,mt,void 0,void 0,e)}}function El(i,e,t,n){let r=e+1>t+20?e-t-1:0,s=i.slice(r,e);return s.push(n),s}function tN(i,e){let t=[],n=!1;return i.iterChangedRanges((r,s)=>t.push(r,s)),e.iterChangedRanges((r,s,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(n=!0)}}),n}function nN(i,e){return i.ranges.length==e.ranges.length&&i.ranges.filter((t,n)=>t.empty!=e.ranges[n].empty).length===0}function yk(i,e){return i.length?e.length?i.concat(e):i:e}const mt=[],iN=200;function bk(i,e){if(i.length){let t=i[i.length-1],n=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-iN));return n.length&&n[n.length-1].eq(e)?i:(n.push(e),El(i,i.length-1,1e9,t.setSelAfter(n)))}else return[Ze.selection([e])]}function rN(i){let e=i[i.length-1],t=i.slice();return t[i.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function oh(i,e){if(!i.length)return i;let t=i.length,n=mt;for(;t;){let r=sN(i[t-1],e,n);if(r.changes&&!r.changes.empty||r.effects.length){let s=i.slice(0,t);return s[t-1]=r,s}else e=r.mapped,t--,n=r.selectionsAfter}return n.length?[Ze.selection(n)]:mt}function sN(i,e,t){let n=yk(i.selectionsAfter.length?i.selectionsAfter.map(l=>l.map(e)):mt,t);if(!i.changes)return Ze.selection(n);let r=i.changes.map(e),s=e.mapDesc(i.changes,!0),o=i.mapped?i.mapped.composeDesc(s):s;return new Ze(r,V.mapEffects(i.effects,e),o,i.startSelection.map(s),n)}const oN=/^(input\.type|delete)($|\.)/;class qt{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new qt(this.done,this.undone):this}addChanges(e,t,n,r,s){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!n||oN.test(n))&&(!l.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(s,tN(l.changes,e.changes))||n=="input.type.compose")?o=El(o,o.length-1,r.minDepth,new Ze(e.changes.compose(l.changes),yk(V.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,mt)):o=El(o,o.length,r.minDepth,e),new qt(o,mt,t,n)}addSelection(e,t,n,r){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:mt;return s.length>0&&t-this.prevTime<r&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&nN(s[s.length-1],e)?this:new qt(bk(this.done,e),this.undone,t,n)}addMapping(e){return new qt(oh(this.done,e),oh(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let s=r[r.length-1],o=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):t.selection);if(n&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Nc.of({side:e,rest:rN(r),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let l=r.length==1?mt:r.slice(0,r.length-1);return s.mapped&&(l=oh(l,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Nc.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}qt.empty=new qt(mt,mt);const YI=[{key:"Mod-z",run:gk,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Dc,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Dc,preventDefault:!0},{key:"Mod-u",run:ZT,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:eN,preventDefault:!0}];function Or(i,e){return S.create(i.ranges.map(e),i.mainIndex)}function Dt(i,e){return i.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function It({state:i,dispatch:e},t){let n=Or(i.selection,t);return n.eq(i.selection,!0)?!1:(e(Dt(i,n)),!0)}function oa(i,e){return S.cursor(e?i.to:i.from)}function kk(i,e){return It(i,t=>t.empty?i.moveByChar(t,e):oa(t,e))}function Fe(i){return i.textDirectionAt(i.state.selection.main.head)==Z.LTR}const xk=i=>kk(i,!Fe(i)),wk=i=>kk(i,Fe(i));function Sk(i,e){return It(i,t=>t.empty?i.moveByGroup(t,e):oa(t,e))}const lN=i=>Sk(i,!Fe(i)),aN=i=>Sk(i,Fe(i));function hN(i,e,t){if(e.type.prop(t))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(i.sliceDoc(e.from,e.to)))||e.firstChild}function la(i,e,t){let n=Ne(i).resolveInner(e.head),r=t?H.closedBy:H.openedBy;for(let a=e.head;;){let h=t?n.childAfter(a):n.childBefore(a);if(!h)break;hN(i,h,r)?n=h:a=t?h.to:h.from}let s=n.type.prop(r),o,l;return s&&(o=t?Kt(i,n.from,1):Kt(i,n.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?n.to:n.from,S.cursor(l,t?-1:1)}const cN=i=>It(i,e=>la(i.state,e,!Fe(i))),fN=i=>It(i,e=>la(i.state,e,Fe(i)));function Ck(i,e){return It(i,t=>{if(!t.empty)return oa(t,e);let n=i.moveVertically(t,e);return n.head!=t.head?n:i.moveToLineBoundary(t,e)})}const vk=i=>Ck(i,!1),Mk=i=>Ck(i,!0);function Ak(i){let e=i.scrollDOM.clientHeight<i.scrollDOM.scrollHeight-2,t=0,n=0,r;if(e){for(let s of i.state.facet(R.scrollMargins)){let o=s(i);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(n=Math.max(o?.bottom,n))}r=i.scrollDOM.clientHeight-t-n}else r=(i.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:n,selfScroll:e,height:Math.max(i.defaultLineHeight,r-5)}}function Ok(i,e){let t=Ak(i),{state:n}=i,r=Or(n.selection,o=>o.empty?i.moveVertically(o,e,t.height):oa(o,e));if(r.eq(n.selection))return!1;let s;if(t.selfScroll){let o=i.coordsAtPos(n.selection.main.head),l=i.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(s=R.scrollIntoView(r.main.head,{y:"start",yMargin:o.top-a}))}return i.dispatch(Dt(n,r),{effects:s}),!0}const um=i=>Ok(i,!1),Ic=i=>Ok(i,!0);function _n(i,e,t){let n=i.lineBlockAt(e.head),r=i.moveToLineBoundary(e,t);if(r.head==e.head&&r.head!=(t?n.to:n.from)&&(r=i.moveToLineBoundary(e,t,!1)),!t&&r.head==n.from&&n.length){let s=/^\s*/.exec(i.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;s&&e.head!=n.from+s&&(r=S.cursor(n.from+s))}return r}const uN=i=>It(i,e=>_n(i,e,!0)),dN=i=>It(i,e=>_n(i,e,!1)),pN=i=>It(i,e=>_n(i,e,!Fe(i))),mN=i=>It(i,e=>_n(i,e,Fe(i))),gN=i=>It(i,e=>i.moveToLineBoundary(e,!1,!1)),yN=i=>It(i,e=>i.moveToLineBoundary(e,!0,!1));function bN(i,e,t){let n=!1,r=Or(i.selection,s=>{let o=Kt(i,s.head,-1)||Kt(i,s.head,1)||s.head>0&&Kt(i,s.head-1,1)||s.head<i.doc.length&&Kt(i,s.head+1,-1);if(!o||!o.end)return s;n=!0;let l=o.start.from==s.head?o.end.to:o.end.from;return S.cursor(l)});return n?(e(Dt(i,r)),!0):!1}const kN=({state:i,dispatch:e})=>bN(i,e);function wt(i,e,t){let n=Or(i.state.selection,r=>{r.undirectional&&r.head>=r.anchor!=e&&(r=S.range(r.head,r.anchor));let s=t(r);return S.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return n.eq(i.state.selection)?!1:(i.dispatch(Dt(i.state,n)),!0)}function Tk(i,e){return wt(i,e,t=>i.moveByChar(t,e))}const Nk=i=>Tk(i,!Fe(i)),Dk=i=>Tk(i,Fe(i));function Ik(i,e){return wt(i,e,t=>i.moveByGroup(t,e))}const xN=i=>Ik(i,!Fe(i)),wN=i=>Ik(i,Fe(i)),SN=i=>{let e=!Fe(i);return wt(i,e,t=>la(i.state,t,e))},CN=i=>{let e=Fe(i);return wt(i,e,t=>la(i.state,t,e))};function Ek(i,e){return wt(i,e,t=>i.moveVertically(t,e))}const Rk=i=>Ek(i,!1),Bk=i=>Ek(i,!0);function Pk(i,e){return wt(i,e,t=>i.moveVertically(t,e,Ak(i).height))}const dm=i=>Pk(i,!1),pm=i=>Pk(i,!0),vN=i=>wt(i,!0,e=>_n(i,e,!0)),MN=i=>wt(i,!1,e=>_n(i,e,!1)),AN=i=>{let e=!Fe(i);return wt(i,e,t=>_n(i,t,e))},ON=i=>{let e=Fe(i);return wt(i,e,t=>_n(i,t,e))},TN=i=>wt(i,!1,e=>S.cursor(i.lineBlockAt(e.head).from)),NN=i=>wt(i,!0,e=>S.cursor(i.lineBlockAt(e.head).to)),mm=({state:i,dispatch:e})=>(e(Dt(i,{anchor:0})),!0),gm=({state:i,dispatch:e})=>(e(Dt(i,{anchor:i.doc.length})),!0),ym=({state:i,dispatch:e})=>(e(Dt(i,{anchor:i.selection.main.anchor,head:0})),!0),bm=({state:i,dispatch:e})=>(e(Dt(i,{anchor:i.selection.main.anchor,head:i.doc.length})),!0),DN=({state:i,dispatch:e})=>(e(i.update({selection:{anchor:0,head:i.doc.length},userEvent:"select"})),!0),IN=({state:i,dispatch:e})=>{let t=aa(i).map(({from:n,to:r})=>S.undirectionalRange(n,Math.min(r+1,i.doc.length)));return e(i.update({selection:S.create(t),userEvent:"select"})),!0},EN=({state:i,dispatch:e})=>{let t=Or(i.selection,n=>{let r=Ne(i),s=r.resolveStack(n.from,1);if(n.empty){let o=r.resolveStack(n.from,-1);o.node.from>=s.node.from&&o.node.to<=s.node.to&&(s=o)}for(let o=s;o;o=o.next){let{node:l}=o;if((l.from<n.from&&l.to>=n.to||l.to>n.to&&l.from<=n.from)&&o.next)return S.undirectionalRange(l.from,l.to)}return n});return t.eq(i.selection)?!1:(e(Dt(i,t)),!0)};function Lk(i,e){let{state:t}=i,n=t.selection,r=t.selection.ranges.slice();for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head);if(e?o.to<i.state.doc.length:o.from>0)for(let l=s;;){let a=i.moveVertically(l,e);if(a.head<o.from||a.head>o.to){r.some(h=>h.head==a.head)||r.push(a);break}else{if(a.head==l.head)break;l=a}}}return r.length==n.ranges.length?!1:(i.dispatch(Dt(t,S.create(r,r.length-1))),!0)}const RN=i=>Lk(i,!1),BN=i=>Lk(i,!0),PN=({state:i,dispatch:e})=>{let t=i.selection,n=null;return t.ranges.length>1?n=S.create([t.main]):t.main.empty||(n=S.create([S.cursor(t.main.head)])),n?(e(Dt(i,n)),!0):!1};function uo(i,e){if(i.state.readOnly)return!1;let t="delete.selection",{state:n}=i,r=n.changeByRange(s=>{let{from:o,to:l}=s;if(o==l){let a=e(s);a<o?(t="delete.backward",a=Vo(i,a,!1)):a>o&&(t="delete.forward",a=Vo(i,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Vo(i,o,!1),l=Vo(i,l,!0);return o==l?{range:s}:{changes:{from:o,to:l},range:S.cursor(o,o<s.head?-1:1)}});return r.changes.empty?!1:(i.dispatch(n.update(r,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?R.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function Vo(i,e,t){if(i instanceof R)for(let n of i.state.facet(R.atomicRanges).map(r=>r(i)))n.between(e,e,(r,s)=>{r<e&&s>e&&(e=t?s:r)});return e}const Fk=(i,e,t)=>uo(i,n=>{let r=n.from,{state:s}=i,o=s.doc.lineAt(r),l,a;if(t&&!e&&r>o.from&&r<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,r-o.from))){if(l[l.length-1]==" ")return r-1;let h=Sr(l,s.tabSize),c=h%Si(s)||Si(s);for(let f=0;f<c&&l[l.length-1-f]==" ";f++)r--;a=r}else a=Re(o.text,r-o.from,e,e)+o.from,a==r&&o.number!=(e?s.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,r-o.from))&&(a=Re(o.text,a-o.from,!1,!1)+o.from);return a}),Ec=i=>Fk(i,!1,!0),zk=i=>Fk(i,!0,!1),Vk=(i,e)=>uo(i,t=>{let n=t.head,{state:r}=i,s=r.doc.lineAt(n),o=r.charCategorizer(n);for(let l=null;;){if(n==(e?s.to:s.from)){n==t.head&&s.number!=(e?r.doc.lines:1)&&(n+=e?1:-1);break}let a=Re(s.text,n-s.from,e)+s.from,h=s.text.slice(Math.min(n,a)-s.from,Math.max(n,a)-s.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||n!=t.head)&&(l=c),n=a}return n}),Hk=i=>Vk(i,!1),LN=i=>Vk(i,!0),FN=i=>uo(i,e=>{let t=i.lineBlockAt(e.head).to;return e.head<t?t:Math.min(i.state.doc.length,e.head+1)}),zN=i=>uo(i,e=>{let t=i.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),VN=i=>uo(i,e=>{let t=i.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(i.state.doc.length,e.head+1)}),HN=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:U.of(["",""])},range:S.cursor(n.from)}));return e(i.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},WN=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>{if(!n.empty||n.from==0||n.from==i.doc.length)return{range:n};let r=n.from,s=i.doc.lineAt(r),o=r==s.from?r-1:Re(s.text,r-s.from,!1)+s.from,l=r==s.to?r+1:Re(s.text,r-s.from,!0)+s.from;return{changes:{from:o,to:l,insert:i.doc.slice(r,l).append(i.doc.slice(o,r))},range:S.cursor(l)}});return t.changes.empty?!1:(e(i.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function aa(i){let e=[],t=-1;for(let n of i.selection.ranges){let r=i.doc.lineAt(n.from),s=i.doc.lineAt(n.to);if(!n.empty&&n.to==s.from&&(s=i.doc.lineAt(n.to-1)),t>=r.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(n)}else e.push({from:r.from,to:s.to,ranges:[n]});t=s.number+1}return e}function Wk(i,e,t){if(i.readOnly)return!1;let n=[],r=[];for(let s of aa(i)){if(t?s.to==i.doc.length:s.from==0)continue;let o=i.doc.lineAt(t?s.to+1:s.from-1),l=o.length+1;if(t){n.push({from:s.to,to:o.to},{from:s.from,insert:o.text+i.lineBreak});for(let a of s.ranges)r.push(S.range(Math.min(i.doc.length,a.anchor+l),Math.min(i.doc.length,a.head+l)))}else{n.push({from:o.from,to:s.from},{from:s.to,insert:i.lineBreak+o.text});for(let a of s.ranges)r.push(S.range(a.anchor-l,a.head-l))}}return n.length?(e(i.update({changes:n,scrollIntoView:!0,selection:S.create(r,i.selection.mainIndex),userEvent:"move.line"})),!0):!1}const $N=({state:i,dispatch:e})=>Wk(i,e,!1),KN=({state:i,dispatch:e})=>Wk(i,e,!0);function $k(i,e,t){if(i.readOnly)return!1;let n=[];for(let s of aa(i))t?n.push({from:s.from,insert:i.doc.slice(s.from,s.to)+i.lineBreak}):n.push({from:s.to,insert:i.lineBreak+i.doc.slice(s.from,s.to)});let r=i.changes(n);return e(i.update({changes:r,selection:i.selection.map(r,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const qN=({state:i,dispatch:e})=>$k(i,e,!1),jN=({state:i,dispatch:e})=>$k(i,e,!0),JN=i=>{if(i.state.readOnly)return!1;let{state:e}=i,t=e.changes(aa(e).map(({from:r,to:s})=>(r>0?r--:s<e.doc.length&&s++,{from:r,to:s}))),n=Or(e.selection,r=>{let s;if(i.lineWrapping){let o=i.lineBlockAt(r.head),l=i.coordsAtPos(r.head,r.assoc||1);l&&(s=o.bottom+i.documentTop-l.bottom+i.defaultLineHeight/2)}return i.moveVertically(r,!0,s)}).map(t);return i.dispatch({changes:t,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function _N(i,e){if(/\(\)|\[\]|\{\}/.test(i.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Ne(i).resolveInner(e),n=t.childBefore(e),r=t.childAfter(e),s;return n&&r&&n.to<=e&&r.from>=e&&(s=n.type.prop(H.closedBy))&&s.indexOf(r.name)>-1&&i.doc.lineAt(n.to).from==i.doc.lineAt(r.from).from&&!/\S/.test(i.sliceDoc(n.to,r.from))?{from:n.to,to:r.from}:null}const km=Kk(!1),UN=Kk(!0);function Kk(i){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{let{from:s,to:o}=r,l=e.doc.lineAt(s),a=!i&&s==o&&_N(e,s);i&&(s=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new ta(e,{simulateBreak:s,simulateDoubleBreak:!!a}),c=wf(h,s);for(c==null&&(c=Sr(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:s,to:o}=a:s>l.from&&s<l.from+100&&!/\S/.test(l.text.slice(0,s))&&(s=l.from);let f=["",Rs(e,c)];return a&&f.push(Rs(e,h.lineIndent(l.from,-1))),{changes:{from:s,to:o,insert:U.of(f)},range:S.cursor(s+1+f[1].length)}});return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function ku(i,e){let t=-1;return i.changeByRange(n=>{let r=[];for(let o=n.from;o<=n.to;){let l=i.doc.lineAt(o);l.number>t&&(n.empty||n.to>l.from)&&(e(l,r,n),t=l.number),o=l.to+1}let s=i.changes(r);return{changes:r,range:S.range(s.mapPos(n.anchor,1),s.mapPos(n.head,1))}})}const GN=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=Object.create(null),n=new ta(i,{overrideIndentation:s=>{let o=t[s];return o??-1}}),r=ku(i,(s,o,l)=>{let a=wf(n,s.from);if(a==null)return;/\S/.test(s.text)||(a=0);let h=/^\s*/.exec(s.text)[0],c=Rs(i,a);(h!=c||l.from<s.from+h.length)&&(t[s.from]=a,o.push({from:s.from,to:s.from+h.length,insert:c}))});return r.changes.empty||e(i.update(r,{userEvent:"indent"})),!0},qk=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(ku(i,(t,n)=>{n.push({from:t.from,insert:i.facet(ea)})}),{userEvent:"input.indent"})),!0),jk=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(ku(i,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let s=Sr(r,i.tabSize),o=0,l=Rs(i,Math.max(0,s-Si(i)));for(;o<r.length&&o<l.length&&r.charCodeAt(o)==l.charCodeAt(o);)o++;n.push({from:t.from+o,to:t.from+r.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),YN=i=>(i.setTabFocusMode(),!0),XN=[{key:"Ctrl-b",run:xk,shift:Nk,preventDefault:!0},{key:"Ctrl-f",run:wk,shift:Dk},{key:"Ctrl-p",run:vk,shift:Rk},{key:"Ctrl-n",run:Mk,shift:Bk},{key:"Ctrl-a",run:gN,shift:TN},{key:"Ctrl-e",run:yN,shift:NN},{key:"Ctrl-d",run:zk},{key:"Ctrl-h",run:Ec},{key:"Ctrl-k",run:FN},{key:"Ctrl-Alt-h",run:Hk},{key:"Ctrl-o",run:HN},{key:"Ctrl-t",run:WN},{key:"Ctrl-v",run:Ic}],QN=[{key:"ArrowLeft",run:xk,shift:Nk,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:lN,shift:xN,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:pN,shift:AN,preventDefault:!0},{key:"ArrowRight",run:wk,shift:Dk,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:aN,shift:wN,preventDefault:!0},{mac:"Cmd-ArrowRight",run:mN,shift:ON,preventDefault:!0},{key:"ArrowUp",run:vk,shift:Rk,preventDefault:!0},{mac:"Cmd-ArrowUp",run:mm,shift:ym},{mac:"Ctrl-ArrowUp",run:um,shift:dm},{key:"ArrowDown",run:Mk,shift:Bk,preventDefault:!0},{mac:"Cmd-ArrowDown",run:gm,shift:bm},{mac:"Ctrl-ArrowDown",run:Ic,shift:pm},{key:"PageUp",run:um,shift:dm},{key:"PageDown",run:Ic,shift:pm},{key:"Home",run:dN,shift:MN,preventDefault:!0},{key:"Mod-Home",run:mm,shift:ym},{key:"End",run:uN,shift:vN,preventDefault:!0},{key:"Mod-End",run:gm,shift:bm},{key:"Enter",run:km,shift:km},{key:"Mod-a",run:DN},{key:"Backspace",run:Ec,shift:Ec,preventDefault:!0},{key:"Delete",run:zk,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Hk,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:LN,preventDefault:!0},{mac:"Mod-Backspace",run:zN,preventDefault:!0},{mac:"Mod-Delete",run:VN,preventDefault:!0}].concat(XN.map(i=>({mac:i.key,run:i.run,shift:i.shift}))),XI=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:cN,shift:SN},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:fN,shift:CN},{key:"Alt-ArrowUp",run:$N},{key:"Shift-Alt-ArrowUp",run:qN},{key:"Alt-ArrowDown",run:KN},{key:"Shift-Alt-ArrowDown",run:jN},{key:"Mod-Alt-ArrowUp",run:RN},{key:"Mod-Alt-ArrowDown",run:BN},{key:"Escape",run:PN},{key:"Mod-Enter",run:UN},{key:"Alt-l",mac:"Ctrl-l",run:IN},{key:"Mod-i",run:EN,preventDefault:!0},{key:"Mod-[",run:jk},{key:"Mod-]",run:qk},{key:"Mod-Alt-\\",run:GN},{key:"Shift-Mod-k",run:JN},{key:"Shift-Mod-\\",run:kN},{key:"Mod-/",run:qT},{key:"Alt-A",mac:"Ctrl-A",run:JT},{key:"Ctrl-m",mac:"Shift-Alt-m",run:YN}].concat(QN),QI={key:"Tab",run:qk,shift:jk};class Jk{constructor(e,t,n,r){this.state=e,this.pos=t,this.explicit=n,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=Ne(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),r=t.text.slice(n-t.from,this.pos-t.from),s=r.search(_k(e,!1));return s<0?null:{from:n+s,to:this.pos,text:r.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}}function xm(i){let e=Object.keys(i).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function ZN(i){let e=Object.create(null),t=Object.create(null);for(let{label:r}of i){e[r[0]]=!0;for(let s=1;s<r.length;s++)t[r[s]]=!0}let n=xm(e)+xm(t)+"*$";return[new RegExp("^"+n),new RegExp(n)]}function eD(i){let e=i.map(r=>typeof r=="string"?{label:r}:r),[t,n]=e.every(r=>/^\w+$/.test(r.label))?[/\w*$/,/\w+$/]:ZN(e);return r=>{let s=r.matchBefore(n);return s||r.explicit?{from:s?s.from:r.pos,options:e,validFor:t}:null}}function ZI(i,e){return t=>{for(let n=Ne(t.state).resolveInner(t.pos,-1);n;n=n.parent){if(i.indexOf(n.name)>-1)return null;if(n.type.isTop)break}return e(t)}}class wm{constructor(e,t,n,r){this.completion=e,this.source=t,this.match=n,this.score=r}}function ui(i){return i.selection.main.from}function _k(i,e){var t;let{source:n}=i,r=e&&n[0]!="^",s=n[n.length-1]!="$";return!r&&!s?i:new RegExp(`${r?"^":""}(?:${n})${s?"$":""}`,(t=i.flags)!==null&&t!==void 0?t:i.ignoreCase?"i":"")}const xu=mn.define();function tD(i,e,t,n){let{main:r}=i.selection,s=t-r.from,o=n-r.from;return{...i.changeByRange(l=>{if(l!=r&&t!=n&&i.sliceDoc(l.from+s,l.from+o)!=i.sliceDoc(t,n))return{range:l};let a=i.toText(e);return{changes:{from:l.from+s,to:n==r.from?l.to:l.from+o,insert:a},range:S.cursor(l.from+s+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Sm=new WeakMap;function nD(i){if(!Array.isArray(i))return i;let e=Sm.get(i);return e||Sm.set(i,e=eD(i)),e}const Rl=V.define(),Ps=V.define();class iD{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let n=it(e,t),r=Zt(n);this.chars.push(n);let s=e.slice(t,t+r),o=s.toUpperCase();this.folded.push(it(o==s?s.toLowerCase():o,0)),t+=r}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:n,any:r,precise:s,byWord:o}=this;if(t.length==1){let b=it(e,0),k=Zt(b),O=k==e.length?0:-100;if(b!=t[0])if(b==n[0])O+=-200;else return null;return this.ret(O,[0,k])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let b=0,k=Math.min(e.length,200);b<k&&h<a;){let O=it(e,b);(O==t[h]||O==n[h])&&(r[h++]=b),b+=Zt(O)}if(h<a)return null}let c=0,f=0,u=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let b=0,k=Math.min(e.length,200),O=0;b<k&&f<a;){let w=it(e,b);l<0&&(c<a&&w==t[c]&&(s[c++]=b),d<a&&(w==t[d]||w==n[d]?(d==0&&(p=b),m=b+1,d++):d=0));let M,C=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(M=_0(w))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!b||C==1&&g||O==0&&C!=0)&&(t[f]==w||n[f]==w&&(u=!0)?o[f++]=b:o.length&&(y=!1)),O=C,b+=Zt(w)}return f==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):f==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((r[0]?-700:0)+-200+-1100,r,e)}result(e,t,n){let r=[],s=0;for(let o of t){let l=o+(this.astral?Zt(it(n,o)):1);s&&r[s-1]==o?r[s-1]=l:(r[s++]=o,r[s++]=l)}return this.ret(e-n.length,r)}}class rD{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),n=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return n==null?null:(this.matched=[0,t.length],this.score=n+(e.length==this.pattern.length?0:-100),this)}}const ke=D.define({combine(i){return Ai(i,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:sD,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>n=>Cm(e(n),t(n)),optionClass:(e,t)=>n=>Cm(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Cm(i,e){return i?e?i+" "+e:i:e}function sD(i,e,t,n,r,s){let o=i.textDirection==Z.RTL,l=o,a=!1,h="top",c,f,u=e.left-r.left,d=r.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))c=Math.max(r.top,Math.min(t.top,r.bottom-m))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:r.right-e.left)-30);let b=r.bottom-e.bottom;b>=m||b>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let g=(e.bottom-e.top)/s.offsetHeight,y=(e.right-e.left)/s.offsetWidth;return{style:`${h}: ${c/g}px; max-width: ${f/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const wu=V.define();function oD(i){let e=i.addToOptions.slice();return i.icons&&e.push({render(t){let n=document.createElement("div");return n.classList.add("cm-completionIcon"),t.type&&n.classList.add(...t.type.split(/\s+/g).map(r=>"cm-completionIcon-"+r)),n.setAttribute("aria-hidden","true"),n},position:20}),e.push({render(t,n,r,s){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;h<s.length;){let c=s[h++],f=s[h++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(c,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let n=document.createElement("span");return n.className="cm-completionDetail",n.textContent=t.detail,n},position:80}),e.sort((t,n)=>t.position-n.position).map(t=>t.render)}function lh(i,e,t){if(i<=t)return{from:0,to:i};if(e<0&&(e=0),e<=i>>1){let r=Math.floor(e/t);return{from:r*t,to:(r+1)*t}}let n=Math.ceil((i-e)/t);return{from:i-n*t,to:i-(n-1)*t}}class lD{constructor(e,t,n){this.view=e,this.stateField=t,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let r=e.state.field(t),{options:s,selected:o}=r.open,l=e.state.facet(ke);this.optionContent=oD(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=lh(s.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=e.state.field(t).open;for(let c=a.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]<h.length){this.applyCompletion(e,h[+f[1]]),a.preventDefault();return}if(a.target==this.list){let c=this.list.classList.contains("cm-completionListIncompleteTop")&&a.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&a.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;c!=null&&(e.dispatch({effects:wu.of(c)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ke).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Ps.of(null)})}),this.showOptions(s,r.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let n=e.state.field(this.stateField),r=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),n!=r){let{options:s,selected:o,disabled:l}=n.open;(!r.open||r.open.options!=s)&&(this.range=lh(s.length,o,e.state.facet(ke).maxRenderedOptions),this.showOptions(s,n.id)),this.updateSel(),l!=((t=r.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let n of this.currentClass.split(" "))n&&this.dom.classList.remove(n);for(let n of t.split(" "))n&&this.dom.classList.add(n);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=lh(t.options.length,t.selected,this.view.state.facet(ke).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:r}=t.options[t.selected],{info:s}=r;if(!s)return;let o=typeof s=="string"?document.createTextNode(s):s(r);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,r)}).catch(l=>Qe(this.view.state,l,"completion info")):(this.addInfoPane(o,r),n.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let n=this.info=document.createElement("div");if(n.className="cm-tooltip cm-completionInfo",n.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)n.appendChild(e),this.infoDestroy=null;else{let{dom:r,destroy:s}=e;n.appendChild(r),this.infoDestroy=s||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,r=this.range.from;n;n=n.nextSibling,r++)n.nodeName!="LI"||!n.id?r--:r==e?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),t=n):n.hasAttribute("aria-selected")&&(n.removeAttribute("aria-selected"),n.removeAttribute("aria-describedby"));return t&&hD(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),r=e.getBoundingClientRect(),s=this.space;if(!s){let o=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return r.top>Math.min(s.bottom,t.bottom)-10||r.bottom<Math.max(s.top,t.top)+10?null:this.view.state.facet(ke).positionInfo(this.view,t,r,n,s,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,n){const r=document.createElement("ul");r.id=t,r.setAttribute("role","listbox"),r.setAttribute("aria-expanded","true"),r.setAttribute("aria-label",this.view.state.phrase("Completions")),r.addEventListener("mousedown",o=>{o.target==r&&o.preventDefault()});let s=null;for(let o=n.from;o<n.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=s&&(o>n.from||n.from==0))if(s=u,typeof h!="string"&&h.header)r.appendChild(h.header(h));else{let d=r.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=r.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return n.from&&r.classList.add("cm-completionListIncompleteTop"),n.to<e.length&&r.classList.add("cm-completionListIncompleteBottom"),r}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function aD(i,e){return t=>new lD(t,i,e)}function hD(i,e){let t=i.getBoundingClientRect(),n=e.getBoundingClientRect(),r=t.height/i.offsetHeight;n.top<t.top?i.scrollTop-=(t.top-n.top)/r:n.bottom>t.bottom&&(i.scrollTop+=(n.bottom-t.bottom)/r)}function vm(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function cD(i,e){let t=[],n=null,r=null,s=c=>{t.push(c);let{section:f}=c.completion;if(f){n||(n=[]);let u=typeof f=="string"?f:f.name;n.some(d=>d.name==u)||n.push(typeof f=="string"?{name:u}:f)}},o=e.facet(ke);for(let c of i)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let u of c.result.options)s(new wm(u,c.source,f?f(u):[],1e9-t.length));else{let u=e.sliceDoc(c.from,c.to),d,p=o.filterStrict?new rD(u):new iD(u);for(let m of c.result.options)if(d=p.match(m.label)){let g=m.displayLabel?f?f(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(s(new wm(m,c.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:b}=m.section;r||(r=Object.create(null)),r[b]=Math.max(y,r[b]||-1e9)}}}}if(n){let c=Object.create(null),f=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?r[p.name]-r[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of n.sort(u))f-=1e5,c[d.name]=f;for(let d of t){let{section:p}=d.completion;p&&(d.score+=c[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let c of t.sort((f,u)=>u.score-f.score||h(f.completion,u.completion))){let f=c.completion;!a||a.label!=f.label||a.detail!=f.detail||a.type!=null&&f.type!=null&&a.type!=f.type||a.apply!=f.apply||a.boost!=f.boost?l.push(c):vm(c.completion)>vm(a)&&(l[l.length-1]=c),a=c.completion}return l}class Hi{constructor(e,t,n,r,s,o){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=r,this.selected=s,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Hi(this.options,Mm(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,n,r,s,o){if(r&&!o&&e.some(h=>h.isPending))return r.setDisabled();let l=cD(e,t);if(!l.length)return r&&e.some(h=>h.isPending)?r.setDisabled():null;let a=t.facet(ke).selectOnOpen?0:-1;if(r&&r.selected!=a&&r.selected!=-1){let h=r.options[r.selected].completion;for(let c=0;c<l.length;c++)if(l[c].completion==h){a=c;break}}return new Hi(l,Mm(n,a),{pos:e.reduce((h,c)=>c.hasResult()?Math.min(h,c.from):h,1e8),create:gD,above:s.aboveCursor},r?r.timestamp:Date.now(),a,!1)}map(e){return new Hi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Hi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class Bl{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new Bl(pD,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,n=t.facet(ke),s=(n.override||t.languageDataAt("autocomplete",ui(t)).map(nD)).map(a=>(this.active.find(c=>c.source==a)||new gt(a,this.active.some(c=>c.state!=0)?1:0)).update(e,n));s.length==this.active.length&&s.every((a,h)=>a==this.active[h])&&(s=this.active);let o=this.open,l=e.effects.some(a=>a.is(Su));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||s.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!fD(s,this.active)||l?o=Hi.build(s,t,this.id,o,n,l):o&&o.disabled&&!s.some(a=>a.isPending)&&(o=null),!o&&s.every(a=>!a.isPending)&&s.some(a=>a.hasResult())&&(s=s.map(a=>a.hasResult()?new gt(a.source,0):a));for(let a of e.effects)a.is(wu)&&(o=o&&o.setSelected(a.value,this.id));return s==this.active&&o==this.open?this:new Bl(s,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?uD:dD}}function fD(i,e){if(i==e)return!0;for(let t=0,n=0;;){for(;t<i.length&&!i[t].hasResult();)t++;for(;n<e.length&&!e[n].hasResult();)n++;let r=t==i.length,s=n==e.length;if(r||s)return r==s;if(i[t++].result!=e[n++].result)return!1}}const uD={"aria-autocomplete":"list"},dD={};function Mm(i,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":i};return e>-1&&(t["aria-activedescendant"]=i+"-"+e),t}const pD=[];function Uk(i,e){if(i.isUserEvent("input.complete")){let n=i.annotation(xu);if(n&&e.activateOnCompletion(n))return 12}let t=i.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:i.isUserEvent("delete.backward")?2:i.selection?8:i.docChanged?16:0}class gt{constructor(e,t,n=!1){this.source=e,this.state=t,this.explicit=n}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let n=Uk(e,t),r=this;(n&8||n&16&&this.touches(e))&&(r=new gt(r.source,0)),n&4&&r.state==0&&(r=new gt(this.source,1)),r=r.updateFor(e,n);for(let s of e.effects)if(s.is(Rl))r=new gt(r.source,1,s.value);else if(s.is(Ps))r=new gt(r.source,0);else if(s.is(Su))for(let o of s.value)o.source==r.source&&(r=o);return r}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(ui(e.state))}}class Gi extends gt{constructor(e,t,n,r,s,o){super(e,3,t),this.limit=n,this.result=r,this.from=s,this.to=o}hasResult(){return!0}updateFor(e,t){var n;if(!(t&3))return this.map(e.changes);let r=this.result;r.map&&!e.changes.empty&&(r=r.map(r,e.changes));let s=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=ui(e.state);if(l>o||!r||t&2&&(ui(e.startState)==this.from||l<this.limit))return new gt(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return mD(r.validFor,e.state,s,o)?new Gi(this.source,this.explicit,a,r,s,o):r.update&&(r=r.update(r,s,o,new Jk(e.state,l,!1)))?new Gi(this.source,this.explicit,a,r,r.from,(n=r.to)!==null&&n!==void 0?n:ui(e.state)):new gt(this.source,1,this.explicit)}map(e){if(e.empty)return this;let t=this.result.map?this.result.map(this.result,e):this.result;return t?new Gi(this.source,this.explicit,e.mapPos(this.limit),t,e.mapPos(this.from),e.mapPos(this.to,1)):new gt(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function mD(i,e,t,n){if(!i)return!1;let r=e.sliceDoc(t,n);return typeof i=="function"?i(r,t,n,e):_k(i,!0).test(r)}const Su=V.define({map(i,e){return i.map(t=>t.map(e))}}),Ye=Ge.define({create(){return Bl.start()},update(i,e){return i.update(e)},provide:i=>[xf.from(i,e=>e.tooltip),R.contentAttributes.from(i,e=>e.attrs)]});function Cu(i,e){const t=e.completion.apply||e.completion.label;let n=i.state.field(Ye).active.find(r=>r.source==e.source);return n instanceof Gi?(typeof t=="string"?i.dispatch({...tD(i.state,t,n.from,n.to),annotations:xu.of(e.completion)}):t(i,e.completion,n.from,n.to),!0):!1}const gD=aD(Ye,Cu);function Ho(i,e="option"){return t=>{let n=t.state.field(Ye,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp<t.state.facet(ke).interactionDelay)return!1;let r=1,s;e=="page"&&(s=cb(t,n.open.tooltip))&&(r=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:o}=n.open.options,l=n.open.selected>-1?n.open.selected+r*(i?1:-1):i?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:wu.of(l)}),!0}}const yD=i=>{let e=i.state.field(Ye,!1);return i.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<i.state.facet(ke).interactionDelay?!1:Cu(i,e.open.options[e.open.selected])},ah=i=>i.state.field(Ye,!1)?(i.dispatch({effects:Rl.of(!0)}),!0):!1,bD=i=>{let e=i.state.field(Ye,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(i.dispatch({effects:Ps.of(null)}),!0)};class kD{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const xD=50,wD=1e3,SD=be.fromClass(class{constructor(i){this.view=i,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of i.state.field(Ye).active)e.isPending&&this.startQuery(e)}update(i){let e=i.state.field(Ye),t=i.state.facet(ke);if(!i.selectionSet&&!i.docChanged&&i.startState.field(Ye)==e)return;let n=i.transactions.some(s=>{let o=Uk(s,t);return o&8||(s.selection||s.docChanged)&&!(o&3)});for(let s=0;s<this.running.length;s++){let o=this.running[s];if(n||o.context.abortOnDocChange&&i.docChanged||o.updates.length+i.transactions.length>xD&&Date.now()-o.time>wD){for(let l of o.context.abortListeners)try{l()}catch(a){Qe(this.view.state,a)}o.context.abortListeners=null,this.running.splice(s--,1)}else o.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(s=>s.effects.some(o=>o.is(Rl)))&&(this.pendingStart=!0);let r=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.isPending&&!this.running.some(o=>o.active.source==s.source))?setTimeout(()=>this.startUpdate(),r):-1,this.composing!=0)for(let s of i.transactions)s.isUserEvent("input.type")?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:i}=this.view,e=i.field(Ye);for(let t of e.active)t.isPending&&!this.running.some(n=>n.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ke).updateSyncTime))}startQuery(i){let{state:e}=this.view,t=ui(e),n=new Jk(e,t,i.explicit,this.view),r=new kD(i,n);this.running.push(r),Promise.resolve(i.source(n)).then(s=>{r.context.aborted||(r.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:Ps.of(null)}),Qe(this.view.state,s)})}scheduleAccept(){this.running.every(i=>i.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ke).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ke),n=this.view.state.field(Ye);for(let r=0;r<this.running.length;r++){let s=this.running[r];if(s.done===void 0)continue;if(this.running.splice(r--,1),s.done){let l=ui(s.updates.length?s.updates[0].startState:this.view.state),a=Math.min(l,s.done.from+(s.active.explicit?0:1)),h=new Gi(s.active.source,s.active.explicit,a,s.done,s.done.from,(i=s.done.to)!==null&&i!==void 0?i:l);for(let c of s.updates)h=h.update(c,t);if(h.hasResult()){e.push(h);continue}}let o=n.active.find(l=>l.source==s.active.source);if(o&&o.isPending)if(s.done==null){let l=new gt(s.active.source,0);for(let a of s.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:Su.of(e)})}},{eventHandlers:{blur(i){let e=this.view.state.field(Ye,!1);if(e&&e.tooltip&&this.view.state.facet(ke).closeOnBlur){let t=e.open&&cb(this.view,e.open.tooltip);(!t||!t.dom.contains(i.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Ps.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Rl.of(!1)}),20),this.composing=0}}}),CD=typeof navigator=="object"&&/Win/.test(navigator.platform),vD=Mi.highest(R.domEventHandlers({keydown(i,e){let t=e.state.field(Ye,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||!i.key||i.key.length>1||i.ctrlKey&&!(CD&&i.altKey)||i.metaKey)return!1;let n=t.open.options[t.open.selected],r=t.active.find(o=>o.source==n.source),s=n.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(i.key)>-1&&Cu(e,n),!1}})),Gk=R.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class MD{constructor(e,t,n,r){this.field=e,this.line=t,this.from=n,this.to=r}}class vu{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,Ae.TrackDel),n=e.mapPos(this.to,1,Ae.TrackDel);return t==null||n==null?null:new vu(this.field,t,n)}}class Mu{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],r=[t],s=e.doc.lineAt(t),o=/^\s*/.exec(s.text)[0];for(let a of this.lines){if(n.length){let h=o,c=/^\t*/.exec(a)[0].length;for(let f=0;f<c;f++)h+=e.facet(ea);r.push(t+h.length-c),a=h+a.slice(c)}n.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new vu(a.field,r[a.line]+a.from,r[a.line]+a.to));return{text:n,ranges:l}}static parse(e){let t=[],n=[],r=[],s;for(let o of e.split(/\r\n?|\n/)){for(;s=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=s[1]?+s[1]:null,a=s[2]||s[3]||"",h=-1;l===0&&(l=1e9);let c=a.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<t.length;f++)(l!=null?t[f].seq==l:c&&t[f].name==c)&&(h=f);if(h<0){let f=0;for(;f<t.length&&(l==null||t[f].seq!=null&&t[f].seq<l);)f++;t.splice(f,0,{seq:l,name:c}),h=f;for(let u of r)u.field>=h&&u.field++}for(let f of r)if(f.line==n.length&&f.from>s.index){let u=s[2]?3+(s[1]||"").length:2;f.from-=u,f.to-=u}r.push(new MD(h,n.length,s.index,s.index+c.length)),o=o.slice(0,s.index)+a+o.slice(s.index+s[0].length)}o=o.replace(/\\([{}])/g,(l,a,h)=>{for(let c of r)c.line==n.length&&c.from>h&&(c.from--,c.to--);return a}),n.push(o)}return new Mu(n,r)}}let AD=J.widget({widget:new class extends gn{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),OD=J.mark({class:"cm-snippetField"});class Tr{constructor(e,t){this.ranges=e,this.active=t,this.deco=J.set(e.map(n=>(n.from==n.to?AD:OD).range(n.from,n.to)),!0)}map(e){let t=[];for(let n of this.ranges){let r=n.map(e);if(!r)return null;t.push(r)}return new Tr(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(n=>n.field==this.active&&n.from<=t.from&&n.to>=t.to))}}const po=V.define({map(i,e){return i&&i.map(e)}}),TD=V.define(),Ls=Ge.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is(po))return t.value;if(t.is(TD)&&i)return new Tr(i.ranges,t.value)}return i&&e.docChanged&&(i=i.map(e.changes)),i&&e.selection&&!i.selectionInsideField(e.selection)&&(i=null),i},provide:i=>R.decorations.from(i,e=>e?e.deco:J.none)});function Au(i,e){return S.create(i.filter(t=>t.field==e).map(t=>S.range(t.from,t.to)))}function ND(i){let e=Mu.parse(i);return(t,n,r,s)=>{let{text:o,ranges:l}=e.instantiate(t.state,r),{main:a}=t.state.selection,h={changes:{from:r,to:s==a.from?a.to:s,insert:U.of(o)},scrollIntoView:!0,annotations:n?[xu.of(n),pe.userEvent.of("input.complete")]:void 0};if(l.length&&(h.selection=Au(l,0)),l.some(c=>c.field>0)){let c=new Tr(l,0),f=h.effects=[po.of(c)];t.state.field(Ls,!1)===void 0&&f.push(V.appendConfig.of([Ls,BD,PD,Gk]))}t.dispatch(t.state.update(h))}}function Yk(i){return({state:e,dispatch:t})=>{let n=e.field(Ls,!1);if(!n||i<0&&n.active==0)return!1;let r=n.active+i,s=i>0&&!n.ranges.some(o=>o.field==r+i);return t(e.update({selection:Au(n.ranges,r),effects:po.of(s?null:new Tr(n.ranges,r)),scrollIntoView:!0})),!0}}const DD=({state:i,dispatch:e})=>i.field(Ls,!1)?(e(i.update({effects:po.of(null)})),!0):!1,ID=Yk(1),ED=Yk(-1),RD=[{key:"Tab",run:ID,shift:ED},{key:"Escape",run:DD}],Am=D.define({combine(i){return i.length?i[0]:RD}}),BD=Mi.highest(bf.compute([Am],i=>i.facet(Am)));function eE(i,e){return{...e,apply:ND(i)}}const PD=R.domEventHandlers({mousedown(i,e){let t=e.state.field(Ls,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let r=t.ranges.find(s=>s.from<=n&&s.to>=n);return!r||r.field==t.active?!1:(e.dispatch({selection:Au(t.ranges,r.field),effects:po.of(t.ranges.some(s=>s.field>r.field)?new Tr(t.ranges,r.field):null),scrollIntoView:!0}),!0)}}),Fs={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},ii=V.define({map(i,e){let t=e.mapPos(i,-1,Ae.TrackAfter);return t??void 0}}),Ou=new class extends Vn{};Ou.startSide=1;Ou.endSide=-1;const Xk=Ge.define({create(){return $.empty},update(i,e){if(i=i.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);i=i.update({filter:n=>n>=t.from&&n<=t.to})}for(let t of e.effects)t.is(ii)&&(i=i.update({add:[Ou.range(t.value,t.value+1)]}));return i}});function tE(){return[FD,Xk]}const hh="()[]{}<>«»»«[]{}";function Qk(i){for(let e=0;e<hh.length;e+=2)if(hh.charCodeAt(e)==i)return hh.charAt(e+1);return _0(i<128?i:i+1)}function Zk(i,e){return i.languageDataAt("closeBrackets",e)[0]||Fs}const LD=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),FD=R.inputHandler.of((i,e,t,n)=>{if((LD?i.composing:i.compositionStarted)||i.state.readOnly)return!1;let r=i.state.selection.main;if(n.length>2||n.length==2&&Zt(it(n,0))==1||e!=r.from||t!=r.to)return!1;let s=VD(i.state,n);return s?(i.dispatch(s),!0):!1}),zD=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let n=Zk(i,i.selection.main.head).brackets||Fs.brackets,r=null,s=i.changeByRange(o=>{if(o.empty){let l=HD(i.doc,o.head);for(let a of n)if(a==l&&ha(i.doc,o.head)==Qk(it(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:S.cursor(o.head-a.length)}}return{range:r=o}});return r||e(i.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!r},nE=[{key:"Backspace",run:zD}];function VD(i,e){let t=Zk(i,i.selection.main.head),n=t.brackets||Fs.brackets;for(let r of n){let s=Qk(it(r,0));if(e==r)return s==r?KD(i,r,n.indexOf(r+r+r)>-1,t):WD(i,r,s,t.before||Fs.before);if(e==s&&e1(i,i.selection.main.from))return $D(i,r,s)}return null}function e1(i,e){let t=!1;return i.field(Xk).between(0,i.doc.length,n=>{n==e&&(t=!0)}),t}function ha(i,e){let t=i.sliceString(e,e+2);return t.slice(0,Zt(it(t,0)))}function HD(i,e){let t=i.sliceString(e-2,e);return Zt(it(t,0))==t.length?t:t.slice(1)}function WD(i,e,t,n){let r=null,s=i.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:ii.of(o.to+e.length),range:S.range(o.anchor+e.length,o.head+e.length)};let l=ha(i.doc,o.head);return!l||/\s/.test(l)||n.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:ii.of(o.head+e.length),range:S.cursor(o.head+e.length)}:{range:r=o}});return r?null:i.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function $D(i,e,t){let n=null,r=i.changeByRange(s=>s.empty&&ha(i.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:S.cursor(s.head+t.length)}:n={range:s});return n?null:i.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function KD(i,e,t,n){let r=n.stringPrefixes||Fs.stringPrefixes,s=null,o=i.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:ii.of(l.to+e.length),range:S.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=ha(i.doc,a),c;if(h==e){if(Om(i,a))return{changes:{insert:e+e,from:a},effects:ii.of(a+e.length),range:S.cursor(a+e.length)};if(e1(i,a)){let u=t&&i.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:S.cursor(a+u.length)}}}else{if(t&&i.sliceDoc(a-2*e.length,a)==e+e&&(c=Tm(i,a-2*e.length,r))>-1&&Om(i,c))return{changes:{insert:e+e+e+e,from:a},effects:ii.of(a+e.length),range:S.cursor(a+e.length)};if(i.charCategorizer(a)(h)!=ut.Word&&Tm(i,a,r)>-1&&!qD(i,a,e,r))return{changes:{insert:e+e,from:a},effects:ii.of(a+e.length),range:S.cursor(a+e.length)}}return{range:s=l}});return s?null:i.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Om(i,e){let t=Ne(i).resolveInner(e+1);return t.parent&&t.from==e}function qD(i,e,t,n){let r=Ne(i).resolveInner(e,-1),s=n.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=i.sliceDoc(r.from,Math.min(r.to,r.from+t.length+s)),a=l.indexOf(t);if(!a||a>-1&&n.indexOf(l.slice(0,a))>-1){let c=r.firstChild;for(;c&&c.from==r.from&&c.to-c.from>t.length+a;){if(i.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=r.to==e&&r.parent;if(!h)break;r=h}return!1}function Tm(i,e,t){let n=i.charCategorizer(e);if(n(i.sliceDoc(e-1,e))!=ut.Word)return e;for(let r of t){let s=e-r.length;if(i.sliceDoc(s,e)==r&&n(i.sliceDoc(s-1,s))!=ut.Word)return s}return-1}function iE(i={}){return[vD,Ye,ke.of(i),SD,JD,Gk]}const jD=[{key:"Ctrl-Space",run:ah},{mac:"Alt-`",run:ah},{mac:"Alt-i",run:ah},{key:"Escape",run:bD},{key:"ArrowDown",run:Ho(!0)},{key:"ArrowUp",run:Ho(!1)},{key:"PageDown",run:Ho(!0,"page")},{key:"PageUp",run:Ho(!1,"page")},{key:"Enter",run:yD}],JD=Mi.highest(bf.computeN([ke],i=>i.facet(ke).defaultKeymap?[jD]:[])),rE=oo.define([{tag:[v.keyword,v.modifier],class:"hljs-keyword"},{tag:[v.string,v.regexp,v.quote],class:"hljs-string"},{tag:[v.number,v.bool,v.null,v.atom],class:"hljs-number"},{tag:v.comment,class:"hljs-comment"},{tag:[v.typeName,v.className,v.namespace],class:"hljs-type"},{tag:[v.function(v.variableName),v.function(v.propertyName),v.definition(v.variableName)],class:"hljs-title"},{tag:[v.propertyName,v.attributeName],class:"hljs-attr"},{tag:[v.meta,v.processingInstruction],class:"hljs-meta"},{tag:v.tagName,class:"hljs-selector-tag"},{tag:v.heading,color:"var(--link)",fontWeight:"bold"},{tag:v.link,color:"var(--link)",textDecoration:"underline"},{tag:v.emphasis,fontStyle:"italic"},{tag:v.strong,fontWeight:"bold"}]);export{rE as $,Y as A,ni as B,Jk as C,YC as D,R as E,wb as F,gr as G,UO as H,Q as I,gO as J,Ge as K,Mc as L,J as M,Zc as N,_l as O,V0 as P,BI as Q,GI as R,Lb as S,ie as T,vI as U,OI as V,gn as W,XI as X,YI as Y,jI as Z,pe as _,FI as a,CI as a$,gI as a0,eo as a1,wr as a2,bT as a3,Ui as a4,vr as a5,cu as a6,z as a7,K as a8,ho as a9,kt as aA,mI as aB,$l as aC,Jn as aD,Jl as aE,to as aF,Tt as aG,$c as aH,oI as aI,Oi as aJ,rI as aK,zw as aL,lw as aM,V as aN,UA as aO,RI as aP,EI as aQ,be as aR,Sc as aS,it as aT,Zt as aU,D as aV,Ai as aW,ut as aX,Bn as aY,_0 as aZ,Ei as a_,un as aa,Kn as ab,al as ac,xt as ad,oo as ae,pn as af,ee as ag,ue as ah,E as ai,A as aj,ns as ak,de as al,le as am,Ln as an,kr as ao,iI as ap,Fw as aq,on as ar,tI as as,aI as at,vi as au,Uw as av,_ as aw,Bx as ax,Rx as ay,Ot as az,ZI as b,Af as b$,Re as b0,II as b1,DI as b2,PI as b3,AI as b4,qI as b5,MI as b6,WI as b7,JI as b8,_I as b9,Ra as bA,UI as bB,QI as bC,nI as bD,vg as bE,eI as bF,Hw as bG,w0 as bH,cg as bI,tx as bJ,_w as bK,Kd as bL,ZD as bM,RT as bN,BT as bO,Ti as bP,ao as bQ,PT as bR,fo as bS,LT as bT,Mr as bU,Ar as bV,FT as bW,Nf as bX,IT as bY,lo as bZ,Df as b_,tE as ba,iE as bb,TI as bc,NI as bd,nE as be,KI as bf,jD as bg,j as bh,jt as bi,za as bj,Jo as bk,lI as bl,rr as bm,sI as bn,GC as bo,st as bp,q as bq,$i as br,jo as bs,Fn as bt,La as bu,Jx as bv,dI as bw,yI as bx,pI as by,Va as bz,HI as c,Cr as c0,Of as c1,Ef as c2,Nn as c3,Rf as c4,ET as c5,Xr as c6,bI as c7,eD as d,Ne as e,TO as f,S as g,zI as h,Sb as i,$I as j,je as k,H as l,VI as m,eE as n,xI as o,wI as p,ct as q,Mi as r,fO as s,v as t,bf as u,OO as v,Sr as w,pt as x,ea as y,kb as z};
|
|
26
|
+
`):e.addNode("break")}}}));x(lo.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});x(lo.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var zf=ee("InsertHardbreak",i=>()=>(e,t)=>{const{selection:n,tr:r}=e;if(!(n instanceof K))return!1;if(n.empty){const s=n.$from.node();if(s.childCount>0&&s.lastChild?.type.name==="hardbreak")return t?.(r.replaceRangeWith(n.to-1,n.to,e.schema.node("paragraph")).setSelection(_.near(r.doc.resolve(n.to))).scrollIntoView()),!0}return t?.(r.setMeta("hardbreak",!0).replaceSelectionWith(lo.type(i).create(),!1).scrollIntoView()),!0});x(zf,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Hf=Tt("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:i=>{const e=i.get(le);return()=>e.call(zf.key)}}});x(Hf.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});x(Hf.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Wf=Nt("hr");x(Wf,{displayName:"Attr<hr>",group:"Hr"});var ao=xt("hr",i=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",i.get(Wf.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,t,n)=>{e.addNode(n)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));x(ao.node,{displayName:"NodeSchema<hr>",group:"Hr"});x(ao.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var Lb=Ot(i=>new kt(/^(?:---|___\s|\*\*\*\s)$/,(e,t,n,r)=>{const{tr:s}=e;return t[0]&&s.replaceWith(n-1,r,ao.type(i).create()),s}));x(Lb,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var Fb=ee("InsertHr",i=>()=>(e,t)=>{if(!t)return!0;const n=Ai.node.type(i).create(),{tr:r,selection:s}=e,{from:o}=s,l=ao.type(i).create();if(!l)return!0;const a=r.replaceSelectionWith(l).insert(o,n),h=_.findFrom(a.doc.resolve(o),1,!0);return h&&t(a.setSelection(h).scrollIntoView()),!0});x(Fb,{displayName:"Command<insertHrCommand>",group:"Hr"});var $f=Nt("bulletList");x($f,{displayName:"Attr<bulletList>",group:"BulletList"});var Cr=xt("bullet_list",i=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Ci(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...i.get($f.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!t,runner:(e,t,n)=>{const r=t.spread??!1;e.openNode(n,{spread:r}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!1,spread:t.attrs.spread}).next(t.content).closeNode()}}}));x(Cr.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});x(Cr.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var Vb=Ot(i=>Bc(/^\s*([-+*])\s$/,Cr.type(i)));x(Vb,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var Kf=ee("WrapInBulletList",i=>()=>Ec(Cr.type(i)));x(Kf,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var qf=Tt("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:i=>{const e=i.get(le);return()=>e.call(Kf.key)}}});x(qf.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});x(qf.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var jf=Nt("orderedList");x(jf,{displayName:"Attr<orderedList>",group:"OrderedList"});var vr=xt("ordered_list",i=>({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 Ci(e);return{spread:e.dataset.spread==="true",order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...i.get(jf.key)(e),...e.attrs.order===1?{}:{start:e.attrs.order},"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:t})=>e==="list"&&!!t,runner:(e,t,n)=>{const r=t.spread??!0;e.openNode(n,{spread:r,order:t.start??1}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,t)=>{e.openNode("list",void 0,{ordered:!0,start:t.attrs.order??1,spread:t.attrs.spread}),e.next(t.content),e.closeNode()}}}));x(vr.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});x(vr.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var zb=Ot(i=>Bc(/^\s*(\d+)\.\s$/,vr.type(i),e=>({order:Number(e[1])}),(e,t)=>t.childCount+t.attrs.order===Number(e[1])));x(zb,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Jf=ee("WrapInOrderedList",i=>()=>Ec(vr.type(i)));x(Jf,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var _f=Tt("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:i=>{const e=i.get(le);return()=>e.call(Jf.key)}}});x(_f.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});x(_f.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Uf=Nt("listItem");x(Uf,{displayName:"Attr<listItem>",group:"ListItem"});var Jn=xt("list_item",i=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"•",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw Ci(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...i.get(Uf.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,n)=>{const r=t.label!=null?`${t.label}.`:"•",s=t.label!=null?"ordered":"bullet",o=t.spread??!0;e.openNode(n,{label:r,listType:s,spread:o}),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()}}}));x(Jn.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});x(Jn.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Gf=ee("SinkListItem",i=>()=>oO(Jn.type(i)));x(Gf,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Yf=ee("LiftListItem",i=>()=>iO(Jn.type(i)));x(Yf,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var Xf=ee("SplitListItem",i=>()=>(e,t,n)=>nO(Jn.type(i))(e,t&&(r=>{const{$from:s}=e.selection;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){const{$from:o}=r.selection;r.setNodeMarkup(o.before(-1),void 0,s.node(-3).attrs)}t(r)})));x(Xf,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function MO(i){return(e,t,n)=>{const{selection:r}=e;if(!(r instanceof K))return!1;const{empty:s,$from:o}=r;return!s||o.parentOffset!==0||o.node(-1).type!==Jn.type(i)?!1:Xm(e,t,n)}}var Qf=ee("LiftFirstListItem",i=>()=>MO(i));x(Qf,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Zf=Tt("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:i=>{const e=i.get(le);return()=>e.call(Xf.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:i=>{const e=i.get(le);return()=>e.call(Gf.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:i=>{const e=i.get(le);return()=>e.call(Yf.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:i=>{const e=i.get(le);return()=>e.call(Qf.key)}}});x(Zf.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});x(Zf.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var Hb=Kc("text",()=>({group:"inline",parseMarkdown:{match:({type:i})=>i==="text",runner:(i,e)=>{i.addText(e.value)}},toMarkdown:{match:i=>i.type.name==="text",runner:(i,e)=>{i.addNode("text",void 0,e.text)}}}));x(Hb,{displayName:"NodeSchema<text>",group:"Text"});var eu=Nt("html");x(eu,{displayName:"Attr<html>",group:"Html"});var tu=xt("html",i=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{const t=document.createElement("span"),n={...i.get(eu.key)(e),"data-value":e.attrs.value,"data-type":"html"};return t.textContent=e.attrs.value,["span",n,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,t,n)=>{e.addNode(n,{value:t.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,t)=>{e.addNode("html",void 0,t.attrs.value)}}}));x(tu.node,{displayName:"NodeSchema<html>",group:"Html"});x(tu.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var AO=[Tb,Af,Ai,Zl,Nf,Oi,Al,lo,Ef,so,Pf,oo,Wf,ao,Vf,Sr,$f,Cr,jf,vr,Uf,Jn,gf,wr,kf,ro,Sf,Nn,Mf,_i,eu,tu,Hb].flat(),OO=[Eb,Vb,zb,Rb,Lb,Ib].flat(),TO=[Sb,Cb,Mb,vb],NO=ee("IsMarkSelected",()=>i=>e=>{if(!i)return!1;const{doc:t,selection:n}=e;return t.rangeHasMark(n.from,n.to,i)}),DO=ee("IsNoteSelected",()=>i=>e=>i?Vx(e,i).hasNode:!1),IO=ee("ClearTextInCurrentBlock",()=>()=>(i,e)=>{let t=i.tr;const{$from:n,$to:r}=t.selection,{pos:s}=n,{pos:o}=r,l=s-n.node().content.size;return l<0?!1:(t=t.deleteRange(l,o),e?.(t),!0)}),EO=ee("SetBlockType",()=>i=>(e,t)=>{const{nodeType:n,attrs:r=null}=i??{};if(!n)return!1;const s=e.tr,{from:o,to:l}=s.selection;try{s.setBlockType(o,l,n,r)}catch{return!1}return t?.(s),!0}),RO=ee("WrapInBlockType",()=>i=>(e,t)=>{const{nodeType:n,attrs:r=null}=i??{};if(!n)return!1;let s=e.tr;try{const{$from:o,$to:l}=s.selection,a=o.blockRange(l),h=a&&Oc(a,n,r);if(!h)return!1;s=s.wrap(a,h)}catch{return!1}return t?.(s),!0}),BO=ee("AddBlockType",()=>i=>(e,t)=>{const{nodeType:n,attrs:r=null}=i??{};if(!n)return!1;const s=e.tr;try{const o=n instanceof yt?n:n.createAndFill(r);if(!o)return!1;s.replaceSelectionWith(o)}catch{return!1}return t?.(s),!0}),PO=ee("SelectTextNearPos",()=>i=>(e,t)=>{const{pos:n}=i??{};if(n==null)return!1;const r=(o,l,a)=>Math.min(Math.max(o,l),a),s=e.tr;try{const o=e.doc.resolve(r(n,0,e.doc.content.size));s.setSelection(K.near(o))}catch{return!1}return t?.(s.scrollIntoView()),!0}),LO=[Of,Rf,wn,Df,Lf,zf,Fb,Bb,Pb,Jf,Kf,Gf,Xf,Yf,Qf,yf,Cf,xf,Ab,Ob,NO,DO,IO,EO,RO,BO,PO],FO=[Bf,Ff,Hf,If,Zf,_f,qf,Tf,bf,vf,wf].flat(),nu=kr("remarkAddOrderInList",()=>()=>i=>{js(i,"list",e=>{if(e.ordered){const t=e.start??1;e.children.forEach((n,r)=>{n.label=r+t})}})});x(nu.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});x(nu.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var iu=kr("remarkLineBreak",()=>()=>i=>{const e=new RegExp("(?<![\\t ])[\\t ]*(?:\\r?\\n|\\r)","g");js(i,"text",(t,n,r)=>{if(!t.value||typeof t.value!="string")return;const s=[];let o=0;e.lastIndex=0;let l=e.exec(t.value);for(;l;){const a=l.index;o!==a&&s.push({type:"text",value:t.value.slice(o,a)}),s.push({type:"break",data:{isInline:!0}}),o=a+l[0].length,l=e.exec(t.value)}if(s.length>0&&r&&typeof n=="number")return o<t.value.length&&s.push({type:"text",value:t.value.slice(o)}),r.children.splice(n,1,...s),n+s.length})});x(iu.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});x(iu.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var ru=kr("remarkInlineLink",()=>aO);x(ru.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});x(ru.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var VO=i=>!!i.children,zO=i=>i.type==="html";function HO(i,e){return t(i,0,null)[0];function t(n,r,s){if(VO(n)){const o=[];for(let l=0,a=n.children.length;l<a;l++){const h=n.children[l];if(h){const c=t(h,l,n);if(c)for(let f=0,u=c.length;f<u;f++){const d=c[f];d&&o.push(d)}}}n.children=o}return e(n,r,s)}}var su=kr("remarkHTMLTransformer",i=>()=>e=>{const t=Db(i);HO(e,(n,r,s)=>zO(n)?(s&&t.has(s.type)&&(n.children=[hO(n)],delete n.value,n.type="paragraph"),[n]):[n])});x(su.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});x(su.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var ou=kr("remarkMarker",()=>()=>(i,e)=>{const t=n=>e.value.charAt(n.position.start.offset);js(i,n=>["strong","emphasis"].includes(n.type),n=>{n.marker=t(n)})});x(ou.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});x(ou.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var Wb=Xs(()=>{let i=!1;const e=new Kn("MILKDOWN_INLINE_NODES_CURSOR"),t=new un({key:e,state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;const r=n.selection.$from,s=r.nodeBefore,o=r.nodeAfter;return!!(s&&o&&s.isInline&&!s.isText&&o.isInline&&!o.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>i?(i=!1,requestAnimationFrame(()=>{if(t.getState(n.state)){const s=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",s))}}),!0):!1,compositionstart:n=>(t.getState(n.state)&&(i=!0),!1),beforeinput:(n,r)=>{if(t.getState(n.state)&&r instanceof InputEvent&&r.data&&!i){const s=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",s)),!0}return!1}},decorations(n){if(t.getState(n)){const r=n.selection.$from.pos,s=document.createElement("span"),o=Ln.widget(r,s,{side:-1}),l=document.createElement("span"),a=Ln.widget(r,l);return setTimeout(()=>{s.contentEditable="true",l.contentEditable="true"}),de.create(n.doc,[o,a])}return de.empty}}});return t});x(Wb,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var $b=Xs(i=>new un({key:new Kn("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,t,n)=>{if(!e.length)return;const r=lo.type(i);let s;return e.forEach((o,l)=>{o.steps.forEach((a,h)=>{if(!(a instanceof Vt))return;const c=(d,p)=>e.slice(l).reduce((m,g,y)=>(y===0?g.mapping.slice(h+1):g.mapping).map(m,p),d),f=c(a.from,-1),u=c(a.to,1);n.doc.nodesBetween(f,u,(d,p)=>{d.type!==r||d.attrs.isInline||d.marks.length&&(s??=n.tr,s.setNodeMarkup(p,r,d.attrs,[]))})})}),s}}));x($b,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var lu=pn(["table","code_block"],"hardbreakFilterNodes");x(lu,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var Kb=Xs(i=>{const e=i.get(lu.key);return new un({key:new Kn("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(t,n)=>{const r=t.getMeta("hardbreak"),[s]=t.steps;if(r&&s instanceof ue){const o=n.doc.resolve(s.from);let l=o.depth,a=!0;for(;l>0;)e.includes(o.node(l).type.name)&&(a=!1),l--;return a}return!0}})});x(Kb,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var qb=Xs(i=>{const e=new Kn("MILKDOWN_HEADING_ID"),t=n=>{if(n.composing)return;const r=i.get(Zl.key),s=n.state.tr.setMeta("addToHistory",!1);let o=!1;const l={};n.state.doc.descendants((a,h)=>{if(a.type===Oi.type(i)){if(a.textContent.trim().length===0)return;const c=a.attrs;let f=r(a);l[f]?(l[f]+=1,f+=`-#${l[f]}`):l[f]=1,c.id!==f&&(o=!0,s.setMeta(e,!0).setNodeMarkup(h,void 0,{...c,id:f}))}}),o&&n.dispatch(s)};return new un({key:e,view:n=>(t(n),{update:(r,s)=>{r.state.doc.eq(s.doc)||t(r)}})})});x(qb,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var jb=Xs(i=>{const e=(t,n,r)=>{if(!r.selection||t.some(f=>f.getMeta("addToHistory")===!1||!f.isGeneric))return null;const s=vr.type(i),o=Cr.type(i),l=Jn.type(i),a=(f,u,d=1)=>{let p=!1;const m=`${u+d}.`;return f.label!==m&&(f.label=m,p=!0),p};let h=r.tr,c=!1;return r.doc.descendants((f,u,d,p)=>{if(f.type===o){const m=f.maybeChild(0);m?.type===l&&m.attrs.listType==="ordered"&&(c=!0,h.setNodeMarkup(u,s,{spread:!0}),f.descendants((g,y,b,k)=>{if(g.type===l){const O={...g.attrs};a(O,k)&&(h=h.setNodeMarkup(y,void 0,O))}return!1}))}else if(f.type===l&&d?.type===s){const m={...f.attrs};let g=!1;m.listType!=="ordered"&&(m.listType="ordered",g=!0),d?.maybeChild(0)&&(g=a(m,p,d?.attrs.order??1)),g&&(h=h.setNodeMarkup(u,void 0,m),c=!0)}}),c?h.setMeta("addToHistory",!1):null};return new un({key:new Kn("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:e})});x(jb,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var WO=[$b,lu,Kb,Wb,Ml,nu,ru,iu,su,ou,Ql,qb,jb].flat(),JD=[AO,OO,TO,LO,FO,WO].flat();const $O=i=>{let{state:e}=i,t=e.doc.lineAt(e.selection.main.from),n=hu(i.state,t.from);return n.line?KO(i):n.block?jO(i):!1};function au(i,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=i(e,t);return r?(n(t.update(r)),!0):!1}}const KO=au(UO,0),qO=au(Jb,0),jO=au((i,e)=>Jb(i,e,_O(e)),0);function hu(i,e){let t=i.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Rr=50;function JO(i,{open:e,close:t},n,r){let s=i.sliceDoc(n-Rr,n),o=i.sliceDoc(r,r+Rr),l=/\s*$/.exec(s)[0].length,a=/^\s*/.exec(o)[0].length,h=s.length-l;if(s.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:n-l,margin:l&&1},close:{pos:r+a,margin:a&&1}};let c,f;r-n<=2*Rr?c=f=i.sliceDoc(n,r):(c=i.sliceDoc(n,n+Rr),f=i.sliceDoc(r-Rr,r));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:n+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:r-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function _O(i){let e=[];for(let t of i.selection.ranges){let n=i.doc.lineAt(t.from),r=t.to<=n.to?n:i.doc.lineAt(t.to);r.from>n.from&&r.from==t.to&&(r=t.to==n.to+1?n:i.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>n.from?e[s].to=r.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:r.to})}return e}function Jb(i,e,t=e.selection.ranges){let n=t.map(s=>hu(e,s.from).block);if(!n.every(s=>s))return null;let r=t.map((s,o)=>JO(e,n[o],s.from,s.to));if(i!=2&&!r.every(s=>s))return{changes:e.changes(t.map((s,o)=>r[o]?[]:[{from:s.from,insert:n[o].open+" "},{from:s.to,insert:" "+n[o].close}]))};if(i!=1&&r.some(s=>s)){let s=[];for(let o=0,l;o<r.length;o++)if(l=r[o]){let a=n[o],{open:h,close:c}=l;s.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:s}}return null}function UO(i,e,t=e.selection.ranges){let n=[],r=-1;e:for(let{from:s,to:o}of t){let l=n.length,a=1e9,h;for(let c=s;c<=o;){let f=e.doc.lineAt(c);if(h==null&&(h=hu(e,f.from).line,!h))continue e;if(f.from>r&&(s==o||o>f.from)){r=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+h.length)==h?u:-1;u<f.text.length&&u<a&&(a=u),n.push({line:f,comment:p,token:h,indent:u,empty:d,single:!1})}c=f.to+1}if(a<1e9)for(let c=l;c<n.length;c++)n[c].indent<n[c].line.text.length&&(n[c].indent=a);n.length==l+1&&(n[l].single=!0)}if(i!=2&&n.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of n)(f||!c)&&s.push({from:l.from+h,insert:a+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(i!=1&&n.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:l,token:a}of n)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,s.push({from:h,to:c})}return{changes:s}}return null}const wc=mn.define(),GO=mn.define(),YO=D.define(),_b=D.define({combine(i){return Mi(i,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),Ub=Ge.define({create(){return qt.empty},update(i,e){let t=e.state.facet(_b),n=e.annotation(wc);if(n){let a=Ze.fromTransaction(e,n.selection),h=n.side,c=h==0?i.undone:i.done;return a?c=Ol(c,c.length,t.minDepth,a):c=Xb(c,e.startState.selection),new qt(h==0?n.rest:c,h==0?c:n.rest)}let r=e.annotation(GO);if((r=="full"||r=="before")&&(i=i.isolate()),e.annotation(pe.addToHistory)===!1)return e.changes.empty?i:i.addMapping(e.changes.desc);let s=Ze.fromTransaction(e),o=e.annotation(pe.time),l=e.annotation(pe.userEvent);return s?i=i.addChanges(s,o,l,t,e):e.selection&&(i=i.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(r=="full"||r=="after")&&(i=i.isolate()),i},toJSON(i){return{done:i.done.map(e=>e.toJSON()),undone:i.undone.map(e=>e.toJSON())}},fromJSON(i){return new qt(i.done.map(Ze.fromJSON),i.undone.map(Ze.fromJSON))}});function _D(i={}){return[Ub,_b.of(i),R.domEventHandlers({beforeinput(e,t){let n=e.inputType=="historyUndo"?Gb:e.inputType=="historyRedo"?Sc:null;return n?(e.preventDefault(),n(t)):!1}})]}function ea(i,e){return function({state:t,dispatch:n}){if(!e&&t.readOnly)return!1;let r=t.field(Ub,!1);if(!r)return!1;let s=r.pop(i,t,e);return s?(n(s),!0):!1}}const Gb=ea(0,!1),Sc=ea(1,!1),XO=ea(0,!0),QO=ea(1,!0);class Ze{constructor(e,t,n,r,s){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=s}setSelAfter(e){return new Ze(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(e){return new Ze(e.changes&&me.fromJSON(e.changes),[],e.mapped&&Jt.fromJSON(e.mapped),e.startSelection&&S.fromJSON(e.startSelection),e.selectionsAfter.map(S.fromJSON))}static fromTransaction(e,t){let n=mt;for(let r of e.startState.facet(YO)){let s=r(e);s.length&&(n=n.concat(s))}return!n.length&&e.changes.empty?null:new Ze(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,mt)}static selection(e){return new Ze(void 0,mt,void 0,void 0,e)}}function Ol(i,e,t,n){let r=e+1>t+20?e-t-1:0,s=i.slice(r,e);return s.push(n),s}function ZO(i,e){let t=[],n=!1;return i.iterChangedRanges((r,s)=>t.push(r,s)),e.iterChangedRanges((r,s,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(n=!0)}}),n}function eT(i,e){return i.ranges.length==e.ranges.length&&i.ranges.filter((t,n)=>t.empty!=e.ranges[n].empty).length===0}function Yb(i,e){return i.length?e.length?i.concat(e):i:e}const mt=[],tT=200;function Xb(i,e){if(i.length){let t=i[i.length-1],n=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-tT));return n.length&&n[n.length-1].eq(e)?i:(n.push(e),Ol(i,i.length-1,1e9,t.setSelAfter(n)))}else return[Ze.selection([e])]}function nT(i){let e=i[i.length-1],t=i.slice();return t[i.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function eh(i,e){if(!i.length)return i;let t=i.length,n=mt;for(;t;){let r=iT(i[t-1],e,n);if(r.changes&&!r.changes.empty||r.effects.length){let s=i.slice(0,t);return s[t-1]=r,s}else e=r.mapped,t--,n=r.selectionsAfter}return n.length?[Ze.selection(n)]:mt}function iT(i,e,t){let n=Yb(i.selectionsAfter.length?i.selectionsAfter.map(l=>l.map(e)):mt,t);if(!i.changes)return Ze.selection(n);let r=i.changes.map(e),s=e.mapDesc(i.changes,!0),o=i.mapped?i.mapped.composeDesc(s):s;return new Ze(r,z.mapEffects(i.effects,e),o,i.startSelection.map(s),n)}const rT=/^(input\.type|delete)($|\.)/;class qt{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new qt(this.done,this.undone):this}addChanges(e,t,n,r,s){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!n||rT.test(n))&&(!l.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(s,ZO(l.changes,e.changes))||n=="input.type.compose")?o=Ol(o,o.length-1,r.minDepth,new Ze(e.changes.compose(l.changes),Yb(z.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,mt)):o=Ol(o,o.length,r.minDepth,e),new qt(o,mt,t,n)}addSelection(e,t,n,r){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:mt;return s.length>0&&t-this.prevTime<r&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&eT(s[s.length-1],e)?this:new qt(Xb(this.done,e),this.undone,t,n)}addMapping(e){return new qt(eh(this.done,e),eh(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let s=r[r.length-1],o=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):t.selection);if(n&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:wc.of({side:e,rest:nT(r),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let l=r.length==1?mt:r.slice(0,r.length-1);return s.mapped&&(l=eh(l,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:wc.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}qt.empty=new qt(mt,mt);const UD=[{key:"Mod-z",run:Gb,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Sc,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Sc,preventDefault:!0},{key:"Mod-u",run:XO,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:QO,preventDefault:!0}];function Mr(i,e){return S.create(i.ranges.map(e),i.mainIndex)}function Dt(i,e){return i.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function It({state:i,dispatch:e},t){let n=Mr(i.selection,t);return n.eq(i.selection,!0)?!1:(e(Dt(i,n)),!0)}function ta(i,e){return S.cursor(e?i.to:i.from)}function Qb(i,e){return It(i,t=>t.empty?i.moveByChar(t,e):ta(t,e))}function Fe(i){return i.textDirectionAt(i.state.selection.main.head)==Z.LTR}const Zb=i=>Qb(i,!Fe(i)),ek=i=>Qb(i,Fe(i));function tk(i,e){return It(i,t=>t.empty?i.moveByGroup(t,e):ta(t,e))}const sT=i=>tk(i,!Fe(i)),oT=i=>tk(i,Fe(i));function lT(i,e,t){if(e.type.prop(t))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(i.sliceDoc(e.from,e.to)))||e.firstChild}function na(i,e,t){let n=Ne(i).resolveInner(e.head),r=t?H.closedBy:H.openedBy;for(let a=e.head;;){let h=t?n.childAfter(a):n.childBefore(a);if(!h)break;lT(i,h,r)?n=h:a=t?h.to:h.from}let s=n.type.prop(r),o,l;return s&&(o=t?Kt(i,n.from,1):Kt(i,n.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?n.to:n.from,S.cursor(l,t?-1:1)}const aT=i=>It(i,e=>na(i.state,e,!Fe(i))),hT=i=>It(i,e=>na(i.state,e,Fe(i)));function nk(i,e){return It(i,t=>{if(!t.empty)return ta(t,e);let n=i.moveVertically(t,e);return n.head!=t.head?n:i.moveToLineBoundary(t,e)})}const ik=i=>nk(i,!1),rk=i=>nk(i,!0);function sk(i){let e=i.scrollDOM.clientHeight<i.scrollDOM.scrollHeight-2,t=0,n=0,r;if(e){for(let s of i.state.facet(R.scrollMargins)){let o=s(i);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(n=Math.max(o?.bottom,n))}r=i.scrollDOM.clientHeight-t-n}else r=(i.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:n,selfScroll:e,height:Math.max(i.defaultLineHeight,r-5)}}function ok(i,e){let t=sk(i),{state:n}=i,r=Mr(n.selection,o=>o.empty?i.moveVertically(o,e,t.height):ta(o,e));if(r.eq(n.selection))return!1;let s;if(t.selfScroll){let o=i.coordsAtPos(n.selection.main.head),l=i.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(s=R.scrollIntoView(r.main.head,{y:"start",yMargin:o.top-a}))}return i.dispatch(Dt(n,r),{effects:s}),!0}const Yp=i=>ok(i,!1),Cc=i=>ok(i,!0);function _n(i,e,t){let n=i.lineBlockAt(e.head),r=i.moveToLineBoundary(e,t);if(r.head==e.head&&r.head!=(t?n.to:n.from)&&(r=i.moveToLineBoundary(e,t,!1)),!t&&r.head==n.from&&n.length){let s=/^\s*/.exec(i.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;s&&e.head!=n.from+s&&(r=S.cursor(n.from+s))}return r}const cT=i=>It(i,e=>_n(i,e,!0)),fT=i=>It(i,e=>_n(i,e,!1)),uT=i=>It(i,e=>_n(i,e,!Fe(i))),dT=i=>It(i,e=>_n(i,e,Fe(i))),pT=i=>It(i,e=>i.moveToLineBoundary(e,!1,!1)),mT=i=>It(i,e=>i.moveToLineBoundary(e,!0,!1));function gT(i,e,t){let n=!1,r=Mr(i.selection,s=>{let o=Kt(i,s.head,-1)||Kt(i,s.head,1)||s.head>0&&Kt(i,s.head-1,1)||s.head<i.doc.length&&Kt(i,s.head+1,-1);if(!o||!o.end)return s;n=!0;let l=o.start.from==s.head?o.end.to:o.end.from;return S.cursor(l)});return n?(e(Dt(i,r)),!0):!1}const yT=({state:i,dispatch:e})=>gT(i,e);function wt(i,e,t){let n=Mr(i.state.selection,r=>{r.undirectional&&r.head>=r.anchor!=e&&(r=S.range(r.head,r.anchor));let s=t(r);return S.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return n.eq(i.state.selection)?!1:(i.dispatch(Dt(i.state,n)),!0)}function lk(i,e){return wt(i,e,t=>i.moveByChar(t,e))}const ak=i=>lk(i,!Fe(i)),hk=i=>lk(i,Fe(i));function ck(i,e){return wt(i,e,t=>i.moveByGroup(t,e))}const bT=i=>ck(i,!Fe(i)),kT=i=>ck(i,Fe(i)),xT=i=>{let e=!Fe(i);return wt(i,e,t=>na(i.state,t,e))},wT=i=>{let e=Fe(i);return wt(i,e,t=>na(i.state,t,e))};function fk(i,e){return wt(i,e,t=>i.moveVertically(t,e))}const uk=i=>fk(i,!1),dk=i=>fk(i,!0);function pk(i,e){return wt(i,e,t=>i.moveVertically(t,e,sk(i).height))}const Xp=i=>pk(i,!1),Qp=i=>pk(i,!0),ST=i=>wt(i,!0,e=>_n(i,e,!0)),CT=i=>wt(i,!1,e=>_n(i,e,!1)),vT=i=>{let e=!Fe(i);return wt(i,e,t=>_n(i,t,e))},MT=i=>{let e=Fe(i);return wt(i,e,t=>_n(i,t,e))},AT=i=>wt(i,!1,e=>S.cursor(i.lineBlockAt(e.head).from)),OT=i=>wt(i,!0,e=>S.cursor(i.lineBlockAt(e.head).to)),Zp=({state:i,dispatch:e})=>(e(Dt(i,{anchor:0})),!0),em=({state:i,dispatch:e})=>(e(Dt(i,{anchor:i.doc.length})),!0),tm=({state:i,dispatch:e})=>(e(Dt(i,{anchor:i.selection.main.anchor,head:0})),!0),nm=({state:i,dispatch:e})=>(e(Dt(i,{anchor:i.selection.main.anchor,head:i.doc.length})),!0),TT=({state:i,dispatch:e})=>(e(i.update({selection:{anchor:0,head:i.doc.length},userEvent:"select"})),!0),NT=({state:i,dispatch:e})=>{let t=ia(i).map(({from:n,to:r})=>S.undirectionalRange(n,Math.min(r+1,i.doc.length)));return e(i.update({selection:S.create(t),userEvent:"select"})),!0},DT=({state:i,dispatch:e})=>{let t=Mr(i.selection,n=>{let r=Ne(i),s=r.resolveStack(n.from,1);if(n.empty){let o=r.resolveStack(n.from,-1);o.node.from>=s.node.from&&o.node.to<=s.node.to&&(s=o)}for(let o=s;o;o=o.next){let{node:l}=o;if((l.from<n.from&&l.to>=n.to||l.to>n.to&&l.from<=n.from)&&o.next)return S.undirectionalRange(l.from,l.to)}return n});return t.eq(i.selection)?!1:(e(Dt(i,t)),!0)};function mk(i,e){let{state:t}=i,n=t.selection,r=t.selection.ranges.slice();for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head);if(e?o.to<i.state.doc.length:o.from>0)for(let l=s;;){let a=i.moveVertically(l,e);if(a.head<o.from||a.head>o.to){r.some(h=>h.head==a.head)||r.push(a);break}else{if(a.head==l.head)break;l=a}}}return r.length==n.ranges.length?!1:(i.dispatch(Dt(t,S.create(r,r.length-1))),!0)}const IT=i=>mk(i,!1),ET=i=>mk(i,!0),RT=({state:i,dispatch:e})=>{let t=i.selection,n=null;return t.ranges.length>1?n=S.create([t.main]):t.main.empty||(n=S.create([S.cursor(t.main.head)])),n?(e(Dt(i,n)),!0):!1};function ho(i,e){if(i.state.readOnly)return!1;let t="delete.selection",{state:n}=i,r=n.changeByRange(s=>{let{from:o,to:l}=s;if(o==l){let a=e(s);a<o?(t="delete.backward",a=Po(i,a,!1)):a>o&&(t="delete.forward",a=Po(i,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Po(i,o,!1),l=Po(i,l,!0);return o==l?{range:s}:{changes:{from:o,to:l},range:S.cursor(o,o<s.head?-1:1)}});return r.changes.empty?!1:(i.dispatch(n.update(r,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?R.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function Po(i,e,t){if(i instanceof R)for(let n of i.state.facet(R.atomicRanges).map(r=>r(i)))n.between(e,e,(r,s)=>{r<e&&s>e&&(e=t?s:r)});return e}const gk=(i,e,t)=>ho(i,n=>{let r=n.from,{state:s}=i,o=s.doc.lineAt(r),l,a;if(t&&!e&&r>o.from&&r<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,r-o.from))){if(l[l.length-1]==" ")return r-1;let h=xr(l,s.tabSize),c=h%wi(s)||wi(s);for(let f=0;f<c&&l[l.length-1-f]==" ";f++)r--;a=r}else a=Re(o.text,r-o.from,e,e)+o.from,a==r&&o.number!=(e?s.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,r-o.from))&&(a=Re(o.text,a-o.from,!1,!1)+o.from);return a}),vc=i=>gk(i,!1,!0),yk=i=>gk(i,!0,!1),bk=(i,e)=>ho(i,t=>{let n=t.head,{state:r}=i,s=r.doc.lineAt(n),o=r.charCategorizer(n);for(let l=null;;){if(n==(e?s.to:s.from)){n==t.head&&s.number!=(e?r.doc.lines:1)&&(n+=e?1:-1);break}let a=Re(s.text,n-s.from,e)+s.from,h=s.text.slice(Math.min(n,a)-s.from,Math.max(n,a)-s.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||n!=t.head)&&(l=c),n=a}return n}),kk=i=>bk(i,!1),BT=i=>bk(i,!0),PT=i=>ho(i,e=>{let t=i.lineBlockAt(e.head).to;return e.head<t?t:Math.min(i.state.doc.length,e.head+1)}),LT=i=>ho(i,e=>{let t=i.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),FT=i=>ho(i,e=>{let t=i.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(i.state.doc.length,e.head+1)}),VT=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:U.of(["",""])},range:S.cursor(n.from)}));return e(i.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},zT=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>{if(!n.empty||n.from==0||n.from==i.doc.length)return{range:n};let r=n.from,s=i.doc.lineAt(r),o=r==s.from?r-1:Re(s.text,r-s.from,!1)+s.from,l=r==s.to?r+1:Re(s.text,r-s.from,!0)+s.from;return{changes:{from:o,to:l,insert:i.doc.slice(r,l).append(i.doc.slice(o,r))},range:S.cursor(l)}});return t.changes.empty?!1:(e(i.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function ia(i){let e=[],t=-1;for(let n of i.selection.ranges){let r=i.doc.lineAt(n.from),s=i.doc.lineAt(n.to);if(!n.empty&&n.to==s.from&&(s=i.doc.lineAt(n.to-1)),t>=r.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(n)}else e.push({from:r.from,to:s.to,ranges:[n]});t=s.number+1}return e}function xk(i,e,t){if(i.readOnly)return!1;let n=[],r=[];for(let s of ia(i)){if(t?s.to==i.doc.length:s.from==0)continue;let o=i.doc.lineAt(t?s.to+1:s.from-1),l=o.length+1;if(t){n.push({from:s.to,to:o.to},{from:s.from,insert:o.text+i.lineBreak});for(let a of s.ranges)r.push(S.range(Math.min(i.doc.length,a.anchor+l),Math.min(i.doc.length,a.head+l)))}else{n.push({from:o.from,to:s.from},{from:s.to,insert:i.lineBreak+o.text});for(let a of s.ranges)r.push(S.range(a.anchor-l,a.head-l))}}return n.length?(e(i.update({changes:n,scrollIntoView:!0,selection:S.create(r,i.selection.mainIndex),userEvent:"move.line"})),!0):!1}const HT=({state:i,dispatch:e})=>xk(i,e,!1),WT=({state:i,dispatch:e})=>xk(i,e,!0);function wk(i,e,t){if(i.readOnly)return!1;let n=[];for(let s of ia(i))t?n.push({from:s.from,insert:i.doc.slice(s.from,s.to)+i.lineBreak}):n.push({from:s.to,insert:i.lineBreak+i.doc.slice(s.from,s.to)});let r=i.changes(n);return e(i.update({changes:r,selection:i.selection.map(r,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const $T=({state:i,dispatch:e})=>wk(i,e,!1),KT=({state:i,dispatch:e})=>wk(i,e,!0),qT=i=>{if(i.state.readOnly)return!1;let{state:e}=i,t=e.changes(ia(e).map(({from:r,to:s})=>(r>0?r--:s<e.doc.length&&s++,{from:r,to:s}))),n=Mr(e.selection,r=>{let s;if(i.lineWrapping){let o=i.lineBlockAt(r.head),l=i.coordsAtPos(r.head,r.assoc||1);l&&(s=o.bottom+i.documentTop-l.bottom+i.defaultLineHeight/2)}return i.moveVertically(r,!0,s)}).map(t);return i.dispatch({changes:t,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function jT(i,e){if(/\(\)|\[\]|\{\}/.test(i.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Ne(i).resolveInner(e),n=t.childBefore(e),r=t.childAfter(e),s;return n&&r&&n.to<=e&&r.from>=e&&(s=n.type.prop(H.closedBy))&&s.indexOf(r.name)>-1&&i.doc.lineAt(n.to).from==i.doc.lineAt(r.from).from&&!/\S/.test(i.sliceDoc(n.to,r.from))?{from:n.to,to:r.from}:null}const im=Sk(!1),JT=Sk(!0);function Sk(i){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{let{from:s,to:o}=r,l=e.doc.lineAt(s),a=!i&&s==o&&jT(e,s);i&&(s=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Yl(e,{simulateBreak:s,simulateDoubleBreak:!!a}),c=uf(h,s);for(c==null&&(c=xr(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:s,to:o}=a:s>l.from&&s<l.from+100&&!/\S/.test(l.text.slice(0,s))&&(s=l.from);let f=["",Ds(e,c)];return a&&f.push(Ds(e,h.lineIndent(l.from,-1))),{changes:{from:s,to:o,insert:U.of(f)},range:S.cursor(s+1+f[1].length)}});return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function cu(i,e){let t=-1;return i.changeByRange(n=>{let r=[];for(let o=n.from;o<=n.to;){let l=i.doc.lineAt(o);l.number>t&&(n.empty||n.to>l.from)&&(e(l,r,n),t=l.number),o=l.to+1}let s=i.changes(r);return{changes:r,range:S.range(s.mapPos(n.anchor,1),s.mapPos(n.head,1))}})}const _T=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=Object.create(null),n=new Yl(i,{overrideIndentation:s=>{let o=t[s];return o??-1}}),r=cu(i,(s,o,l)=>{let a=uf(n,s.from);if(a==null)return;/\S/.test(s.text)||(a=0);let h=/^\s*/.exec(s.text)[0],c=Ds(i,a);(h!=c||l.from<s.from+h.length)&&(t[s.from]=a,o.push({from:s.from,to:s.from+h.length,insert:c}))});return r.changes.empty||e(i.update(r,{userEvent:"indent"})),!0},Ck=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(cu(i,(t,n)=>{n.push({from:t.from,insert:i.facet(Gl)})}),{userEvent:"input.indent"})),!0),vk=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(cu(i,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let s=xr(r,i.tabSize),o=0,l=Ds(i,Math.max(0,s-wi(i)));for(;o<r.length&&o<l.length&&r.charCodeAt(o)==l.charCodeAt(o);)o++;n.push({from:t.from+o,to:t.from+r.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),UT=i=>(i.setTabFocusMode(),!0),GT=[{key:"Ctrl-b",run:Zb,shift:ak,preventDefault:!0},{key:"Ctrl-f",run:ek,shift:hk},{key:"Ctrl-p",run:ik,shift:uk},{key:"Ctrl-n",run:rk,shift:dk},{key:"Ctrl-a",run:pT,shift:AT},{key:"Ctrl-e",run:mT,shift:OT},{key:"Ctrl-d",run:yk},{key:"Ctrl-h",run:vc},{key:"Ctrl-k",run:PT},{key:"Ctrl-Alt-h",run:kk},{key:"Ctrl-o",run:VT},{key:"Ctrl-t",run:zT},{key:"Ctrl-v",run:Cc}],YT=[{key:"ArrowLeft",run:Zb,shift:ak,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:sT,shift:bT,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:uT,shift:vT,preventDefault:!0},{key:"ArrowRight",run:ek,shift:hk,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:oT,shift:kT,preventDefault:!0},{mac:"Cmd-ArrowRight",run:dT,shift:MT,preventDefault:!0},{key:"ArrowUp",run:ik,shift:uk,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Zp,shift:tm},{mac:"Ctrl-ArrowUp",run:Yp,shift:Xp},{key:"ArrowDown",run:rk,shift:dk,preventDefault:!0},{mac:"Cmd-ArrowDown",run:em,shift:nm},{mac:"Ctrl-ArrowDown",run:Cc,shift:Qp},{key:"PageUp",run:Yp,shift:Xp},{key:"PageDown",run:Cc,shift:Qp},{key:"Home",run:fT,shift:CT,preventDefault:!0},{key:"Mod-Home",run:Zp,shift:tm},{key:"End",run:cT,shift:ST,preventDefault:!0},{key:"Mod-End",run:em,shift:nm},{key:"Enter",run:im,shift:im},{key:"Mod-a",run:TT},{key:"Backspace",run:vc,shift:vc,preventDefault:!0},{key:"Delete",run:yk,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:kk,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:BT,preventDefault:!0},{mac:"Mod-Backspace",run:LT,preventDefault:!0},{mac:"Mod-Delete",run:FT,preventDefault:!0}].concat(GT.map(i=>({mac:i.key,run:i.run,shift:i.shift}))),GD=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:aT,shift:xT},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:hT,shift:wT},{key:"Alt-ArrowUp",run:HT},{key:"Shift-Alt-ArrowUp",run:$T},{key:"Alt-ArrowDown",run:WT},{key:"Shift-Alt-ArrowDown",run:KT},{key:"Mod-Alt-ArrowUp",run:IT},{key:"Mod-Alt-ArrowDown",run:ET},{key:"Escape",run:RT},{key:"Mod-Enter",run:JT},{key:"Alt-l",mac:"Ctrl-l",run:NT},{key:"Mod-i",run:DT,preventDefault:!0},{key:"Mod-[",run:vk},{key:"Mod-]",run:Ck},{key:"Mod-Alt-\\",run:_T},{key:"Shift-Mod-k",run:qT},{key:"Shift-Mod-\\",run:yT},{key:"Mod-/",run:$O},{key:"Alt-A",mac:"Ctrl-A",run:qO},{key:"Ctrl-m",mac:"Shift-Alt-m",run:UT}].concat(YT),YD={key:"Tab",run:Ck,shift:vk};class Mk{constructor(e,t,n,r){this.state=e,this.pos=t,this.explicit=n,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=Ne(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),r=t.text.slice(n-t.from,this.pos-t.from),s=r.search(Ak(e,!1));return s<0?null:{from:n+s,to:this.pos,text:r.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}}function rm(i){let e=Object.keys(i).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function XT(i){let e=Object.create(null),t=Object.create(null);for(let{label:r}of i){e[r[0]]=!0;for(let s=1;s<r.length;s++)t[r[s]]=!0}let n=rm(e)+rm(t)+"*$";return[new RegExp("^"+n),new RegExp(n)]}function QT(i){let e=i.map(r=>typeof r=="string"?{label:r}:r),[t,n]=e.every(r=>/^\w+$/.test(r.label))?[/\w*$/,/\w+$/]:XT(e);return r=>{let s=r.matchBefore(n);return s||r.explicit?{from:s?s.from:r.pos,options:e,validFor:t}:null}}function XD(i,e){return t=>{for(let n=Ne(t.state).resolveInner(t.pos,-1);n;n=n.parent){if(i.indexOf(n.name)>-1)return null;if(n.type.isTop)break}return e(t)}}class sm{constructor(e,t,n,r){this.completion=e,this.source=t,this.match=n,this.score=r}}function fi(i){return i.selection.main.from}function Ak(i,e){var t;let{source:n}=i,r=e&&n[0]!="^",s=n[n.length-1]!="$";return!r&&!s?i:new RegExp(`${r?"^":""}(?:${n})${s?"$":""}`,(t=i.flags)!==null&&t!==void 0?t:i.ignoreCase?"i":"")}const fu=mn.define();function ZT(i,e,t,n){let{main:r}=i.selection,s=t-r.from,o=n-r.from;return{...i.changeByRange(l=>{if(l!=r&&t!=n&&i.sliceDoc(l.from+s,l.from+o)!=i.sliceDoc(t,n))return{range:l};let a=i.toText(e);return{changes:{from:l.from+s,to:n==r.from?l.to:l.from+o,insert:a},range:S.cursor(l.from+s+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const om=new WeakMap;function eN(i){if(!Array.isArray(i))return i;let e=om.get(i);return e||om.set(i,e=QT(i)),e}const Tl=z.define(),Es=z.define();class tN{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let n=it(e,t),r=Zt(n);this.chars.push(n);let s=e.slice(t,t+r),o=s.toUpperCase();this.folded.push(it(o==s?s.toLowerCase():o,0)),t+=r}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:n,any:r,precise:s,byWord:o}=this;if(t.length==1){let b=it(e,0),k=Zt(b),O=k==e.length?0:-100;if(b!=t[0])if(b==n[0])O+=-200;else return null;return this.ret(O,[0,k])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let b=0,k=Math.min(e.length,200);b<k&&h<a;){let O=it(e,b);(O==t[h]||O==n[h])&&(r[h++]=b),b+=Zt(O)}if(h<a)return null}let c=0,f=0,u=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let b=0,k=Math.min(e.length,200),O=0;b<k&&f<a;){let w=it(e,b);l<0&&(c<a&&w==t[c]&&(s[c++]=b),d<a&&(w==t[d]||w==n[d]?(d==0&&(p=b),m=b+1,d++):d=0));let M,C=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(M=A0(w))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!b||C==1&&g||O==0&&C!=0)&&(t[f]==w||n[f]==w&&(u=!0)?o[f++]=b:o.length&&(y=!1)),O=C,b+=Zt(w)}return f==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):f==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((r[0]?-700:0)+-200+-1100,r,e)}result(e,t,n){let r=[],s=0;for(let o of t){let l=o+(this.astral?Zt(it(n,o)):1);s&&r[s-1]==o?r[s-1]=l:(r[s++]=o,r[s++]=l)}return this.ret(e-n.length,r)}}class nN{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),n=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return n==null?null:(this.matched=[0,t.length],this.score=n+(e.length==this.pattern.length?0:-100),this)}}const ke=D.define({combine(i){return Mi(i,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:iN,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>n=>lm(e(n),t(n)),optionClass:(e,t)=>n=>lm(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function lm(i,e){return i?e?i+" "+e:i:e}function iN(i,e,t,n,r,s){let o=i.textDirection==Z.RTL,l=o,a=!1,h="top",c,f,u=e.left-r.left,d=r.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))c=Math.max(r.top,Math.min(t.top,r.bottom-m))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:r.right-e.left)-30);let b=r.bottom-e.bottom;b>=m||b>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let g=(e.bottom-e.top)/s.offsetHeight,y=(e.right-e.left)/s.offsetWidth;return{style:`${h}: ${c/g}px; max-width: ${f/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const uu=z.define();function rN(i){let e=i.addToOptions.slice();return i.icons&&e.push({render(t){let n=document.createElement("div");return n.classList.add("cm-completionIcon"),t.type&&n.classList.add(...t.type.split(/\s+/g).map(r=>"cm-completionIcon-"+r)),n.setAttribute("aria-hidden","true"),n},position:20}),e.push({render(t,n,r,s){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;h<s.length;){let c=s[h++],f=s[h++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(c,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let n=document.createElement("span");return n.className="cm-completionDetail",n.textContent=t.detail,n},position:80}),e.sort((t,n)=>t.position-n.position).map(t=>t.render)}function th(i,e,t){if(i<=t)return{from:0,to:i};if(e<0&&(e=0),e<=i>>1){let r=Math.floor(e/t);return{from:r*t,to:(r+1)*t}}let n=Math.ceil((i-e)/t);return{from:i-n*t,to:i-(n-1)*t}}class sN{constructor(e,t,n){this.view=e,this.stateField=t,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let r=e.state.field(t),{options:s,selected:o}=r.open,l=e.state.facet(ke);this.optionContent=rN(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=th(s.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=e.state.field(t).open;for(let c=a.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]<h.length){this.applyCompletion(e,h[+f[1]]),a.preventDefault();return}if(a.target==this.list){let c=this.list.classList.contains("cm-completionListIncompleteTop")&&a.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&a.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;c!=null&&(e.dispatch({effects:uu.of(c)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ke).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Es.of(null)})}),this.showOptions(s,r.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let n=e.state.field(this.stateField),r=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),n!=r){let{options:s,selected:o,disabled:l}=n.open;(!r.open||r.open.options!=s)&&(this.range=th(s.length,o,e.state.facet(ke).maxRenderedOptions),this.showOptions(s,n.id)),this.updateSel(),l!=((t=r.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let n of this.currentClass.split(" "))n&&this.dom.classList.remove(n);for(let n of t.split(" "))n&&this.dom.classList.add(n);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=th(t.options.length,t.selected,this.view.state.facet(ke).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:r}=t.options[t.selected],{info:s}=r;if(!s)return;let o=typeof s=="string"?document.createTextNode(s):s(r);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,r)}).catch(l=>Qe(this.view.state,l,"completion info")):(this.addInfoPane(o,r),n.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let n=this.info=document.createElement("div");if(n.className="cm-tooltip cm-completionInfo",n.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)n.appendChild(e),this.infoDestroy=null;else{let{dom:r,destroy:s}=e;n.appendChild(r),this.infoDestroy=s||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,r=this.range.from;n;n=n.nextSibling,r++)n.nodeName!="LI"||!n.id?r--:r==e?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),t=n):n.hasAttribute("aria-selected")&&(n.removeAttribute("aria-selected"),n.removeAttribute("aria-describedby"));return t&&lN(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),r=e.getBoundingClientRect(),s=this.space;if(!s){let o=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return r.top>Math.min(s.bottom,t.bottom)-10||r.bottom<Math.max(s.top,t.top)+10?null:this.view.state.facet(ke).positionInfo(this.view,t,r,n,s,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,n){const r=document.createElement("ul");r.id=t,r.setAttribute("role","listbox"),r.setAttribute("aria-expanded","true"),r.setAttribute("aria-label",this.view.state.phrase("Completions")),r.addEventListener("mousedown",o=>{o.target==r&&o.preventDefault()});let s=null;for(let o=n.from;o<n.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=s&&(o>n.from||n.from==0))if(s=u,typeof h!="string"&&h.header)r.appendChild(h.header(h));else{let d=r.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=r.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return n.from&&r.classList.add("cm-completionListIncompleteTop"),n.to<e.length&&r.classList.add("cm-completionListIncompleteBottom"),r}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function oN(i,e){return t=>new sN(t,i,e)}function lN(i,e){let t=i.getBoundingClientRect(),n=e.getBoundingClientRect(),r=t.height/i.offsetHeight;n.top<t.top?i.scrollTop-=(t.top-n.top)/r:n.bottom>t.bottom&&(i.scrollTop+=(n.bottom-t.bottom)/r)}function am(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function aN(i,e){let t=[],n=null,r=null,s=c=>{t.push(c);let{section:f}=c.completion;if(f){n||(n=[]);let u=typeof f=="string"?f:f.name;n.some(d=>d.name==u)||n.push(typeof f=="string"?{name:u}:f)}},o=e.facet(ke);for(let c of i)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let u of c.result.options)s(new sm(u,c.source,f?f(u):[],1e9-t.length));else{let u=e.sliceDoc(c.from,c.to),d,p=o.filterStrict?new nN(u):new tN(u);for(let m of c.result.options)if(d=p.match(m.label)){let g=m.displayLabel?f?f(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(s(new sm(m,c.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:b}=m.section;r||(r=Object.create(null)),r[b]=Math.max(y,r[b]||-1e9)}}}}if(n){let c=Object.create(null),f=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?r[p.name]-r[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of n.sort(u))f-=1e5,c[d.name]=f;for(let d of t){let{section:p}=d.completion;p&&(d.score+=c[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let c of t.sort((f,u)=>u.score-f.score||h(f.completion,u.completion))){let f=c.completion;!a||a.label!=f.label||a.detail!=f.detail||a.type!=null&&f.type!=null&&a.type!=f.type||a.apply!=f.apply||a.boost!=f.boost?l.push(c):am(c.completion)>am(a)&&(l[l.length-1]=c),a=c.completion}return l}class zi{constructor(e,t,n,r,s,o){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=r,this.selected=s,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new zi(this.options,hm(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,n,r,s,o){if(r&&!o&&e.some(h=>h.isPending))return r.setDisabled();let l=aN(e,t);if(!l.length)return r&&e.some(h=>h.isPending)?r.setDisabled():null;let a=t.facet(ke).selectOnOpen?0:-1;if(r&&r.selected!=a&&r.selected!=-1){let h=r.options[r.selected].completion;for(let c=0;c<l.length;c++)if(l[c].completion==h){a=c;break}}return new zi(l,hm(n,a),{pos:e.reduce((h,c)=>c.hasResult()?Math.min(h,c.from):h,1e8),create:pN,above:s.aboveCursor},r?r.timestamp:Date.now(),a,!1)}map(e){return new zi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new zi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class Nl{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new Nl(uN,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,n=t.facet(ke),s=(n.override||t.languageDataAt("autocomplete",fi(t)).map(eN)).map(a=>(this.active.find(c=>c.source==a)||new gt(a,this.active.some(c=>c.state!=0)?1:0)).update(e,n));s.length==this.active.length&&s.every((a,h)=>a==this.active[h])&&(s=this.active);let o=this.open,l=e.effects.some(a=>a.is(du));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||s.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!hN(s,this.active)||l?o=zi.build(s,t,this.id,o,n,l):o&&o.disabled&&!s.some(a=>a.isPending)&&(o=null),!o&&s.every(a=>!a.isPending)&&s.some(a=>a.hasResult())&&(s=s.map(a=>a.hasResult()?new gt(a.source,0):a));for(let a of e.effects)a.is(uu)&&(o=o&&o.setSelected(a.value,this.id));return s==this.active&&o==this.open?this:new Nl(s,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?cN:fN}}function hN(i,e){if(i==e)return!0;for(let t=0,n=0;;){for(;t<i.length&&!i[t].hasResult();)t++;for(;n<e.length&&!e[n].hasResult();)n++;let r=t==i.length,s=n==e.length;if(r||s)return r==s;if(i[t++].result!=e[n++].result)return!1}}const cN={"aria-autocomplete":"list"},fN={};function hm(i,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":i};return e>-1&&(t["aria-activedescendant"]=i+"-"+e),t}const uN=[];function Ok(i,e){if(i.isUserEvent("input.complete")){let n=i.annotation(fu);if(n&&e.activateOnCompletion(n))return 12}let t=i.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:i.isUserEvent("delete.backward")?2:i.selection?8:i.docChanged?16:0}class gt{constructor(e,t,n=!1){this.source=e,this.state=t,this.explicit=n}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let n=Ok(e,t),r=this;(n&8||n&16&&this.touches(e))&&(r=new gt(r.source,0)),n&4&&r.state==0&&(r=new gt(this.source,1)),r=r.updateFor(e,n);for(let s of e.effects)if(s.is(Tl))r=new gt(r.source,1,s.value);else if(s.is(Es))r=new gt(r.source,0);else if(s.is(du))for(let o of s.value)o.source==r.source&&(r=o);return r}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(fi(e.state))}}class Ui extends gt{constructor(e,t,n,r,s,o){super(e,3,t),this.limit=n,this.result=r,this.from=s,this.to=o}hasResult(){return!0}updateFor(e,t){var n;if(!(t&3))return this.map(e.changes);let r=this.result;r.map&&!e.changes.empty&&(r=r.map(r,e.changes));let s=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=fi(e.state);if(l>o||!r||t&2&&(fi(e.startState)==this.from||l<this.limit))return new gt(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return dN(r.validFor,e.state,s,o)?new Ui(this.source,this.explicit,a,r,s,o):r.update&&(r=r.update(r,s,o,new Mk(e.state,l,!1)))?new Ui(this.source,this.explicit,a,r,r.from,(n=r.to)!==null&&n!==void 0?n:fi(e.state)):new gt(this.source,1,this.explicit)}map(e){if(e.empty)return this;let t=this.result.map?this.result.map(this.result,e):this.result;return t?new Ui(this.source,this.explicit,e.mapPos(this.limit),t,e.mapPos(this.from),e.mapPos(this.to,1)):new gt(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function dN(i,e,t,n){if(!i)return!1;let r=e.sliceDoc(t,n);return typeof i=="function"?i(r,t,n,e):Ak(i,!0).test(r)}const du=z.define({map(i,e){return i.map(t=>t.map(e))}}),Ye=Ge.define({create(){return Nl.start()},update(i,e){return i.update(e)},provide:i=>[ff.from(i,e=>e.tooltip),R.contentAttributes.from(i,e=>e.attrs)]});function pu(i,e){const t=e.completion.apply||e.completion.label;let n=i.state.field(Ye).active.find(r=>r.source==e.source);return n instanceof Ui?(typeof t=="string"?i.dispatch({...ZT(i.state,t,n.from,n.to),annotations:fu.of(e.completion)}):t(i,e.completion,n.from,n.to),!0):!1}const pN=oN(Ye,pu);function Lo(i,e="option"){return t=>{let n=t.state.field(Ye,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp<t.state.facet(ke).interactionDelay)return!1;let r=1,s;e=="page"&&(s=Ky(t,n.open.tooltip))&&(r=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:o}=n.open.options,l=n.open.selected>-1?n.open.selected+r*(i?1:-1):i?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:uu.of(l)}),!0}}const mN=i=>{let e=i.state.field(Ye,!1);return i.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<i.state.facet(ke).interactionDelay?!1:pu(i,e.open.options[e.open.selected])},nh=i=>i.state.field(Ye,!1)?(i.dispatch({effects:Tl.of(!0)}),!0):!1,gN=i=>{let e=i.state.field(Ye,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(i.dispatch({effects:Es.of(null)}),!0)};class yN{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const bN=50,kN=1e3,xN=be.fromClass(class{constructor(i){this.view=i,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of i.state.field(Ye).active)e.isPending&&this.startQuery(e)}update(i){let e=i.state.field(Ye),t=i.state.facet(ke);if(!i.selectionSet&&!i.docChanged&&i.startState.field(Ye)==e)return;let n=i.transactions.some(s=>{let o=Ok(s,t);return o&8||(s.selection||s.docChanged)&&!(o&3)});for(let s=0;s<this.running.length;s++){let o=this.running[s];if(n||o.context.abortOnDocChange&&i.docChanged||o.updates.length+i.transactions.length>bN&&Date.now()-o.time>kN){for(let l of o.context.abortListeners)try{l()}catch(a){Qe(this.view.state,a)}o.context.abortListeners=null,this.running.splice(s--,1)}else o.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(s=>s.effects.some(o=>o.is(Tl)))&&(this.pendingStart=!0);let r=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.isPending&&!this.running.some(o=>o.active.source==s.source))?setTimeout(()=>this.startUpdate(),r):-1,this.composing!=0)for(let s of i.transactions)s.isUserEvent("input.type")?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:i}=this.view,e=i.field(Ye);for(let t of e.active)t.isPending&&!this.running.some(n=>n.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ke).updateSyncTime))}startQuery(i){let{state:e}=this.view,t=fi(e),n=new Mk(e,t,i.explicit,this.view),r=new yN(i,n);this.running.push(r),Promise.resolve(i.source(n)).then(s=>{r.context.aborted||(r.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:Es.of(null)}),Qe(this.view.state,s)})}scheduleAccept(){this.running.every(i=>i.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ke).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ke),n=this.view.state.field(Ye);for(let r=0;r<this.running.length;r++){let s=this.running[r];if(s.done===void 0)continue;if(this.running.splice(r--,1),s.done){let l=fi(s.updates.length?s.updates[0].startState:this.view.state),a=Math.min(l,s.done.from+(s.active.explicit?0:1)),h=new Ui(s.active.source,s.active.explicit,a,s.done,s.done.from,(i=s.done.to)!==null&&i!==void 0?i:l);for(let c of s.updates)h=h.update(c,t);if(h.hasResult()){e.push(h);continue}}let o=n.active.find(l=>l.source==s.active.source);if(o&&o.isPending)if(s.done==null){let l=new gt(s.active.source,0);for(let a of s.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:du.of(e)})}},{eventHandlers:{blur(i){let e=this.view.state.field(Ye,!1);if(e&&e.tooltip&&this.view.state.facet(ke).closeOnBlur){let t=e.open&&Ky(this.view,e.open.tooltip);(!t||!t.dom.contains(i.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Es.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Tl.of(!1)}),20),this.composing=0}}}),wN=typeof navigator=="object"&&/Win/.test(navigator.platform),SN=vi.highest(R.domEventHandlers({keydown(i,e){let t=e.state.field(Ye,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||!i.key||i.key.length>1||i.ctrlKey&&!(wN&&i.altKey)||i.metaKey)return!1;let n=t.open.options[t.open.selected],r=t.active.find(o=>o.source==n.source),s=n.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(i.key)>-1&&pu(e,n),!1}})),Tk=R.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class CN{constructor(e,t,n,r){this.field=e,this.line=t,this.from=n,this.to=r}}class mu{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,Ae.TrackDel),n=e.mapPos(this.to,1,Ae.TrackDel);return t==null||n==null?null:new mu(this.field,t,n)}}class gu{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],r=[t],s=e.doc.lineAt(t),o=/^\s*/.exec(s.text)[0];for(let a of this.lines){if(n.length){let h=o,c=/^\t*/.exec(a)[0].length;for(let f=0;f<c;f++)h+=e.facet(Gl);r.push(t+h.length-c),a=h+a.slice(c)}n.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new mu(a.field,r[a.line]+a.from,r[a.line]+a.to));return{text:n,ranges:l}}static parse(e){let t=[],n=[],r=[],s;for(let o of e.split(/\r\n?|\n/)){for(;s=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=s[1]?+s[1]:null,a=s[2]||s[3]||"",h=-1;l===0&&(l=1e9);let c=a.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<t.length;f++)(l!=null?t[f].seq==l:c&&t[f].name==c)&&(h=f);if(h<0){let f=0;for(;f<t.length&&(l==null||t[f].seq!=null&&t[f].seq<l);)f++;t.splice(f,0,{seq:l,name:c}),h=f;for(let u of r)u.field>=h&&u.field++}for(let f of r)if(f.line==n.length&&f.from>s.index){let u=s[2]?3+(s[1]||"").length:2;f.from-=u,f.to-=u}r.push(new CN(h,n.length,s.index,s.index+c.length)),o=o.slice(0,s.index)+a+o.slice(s.index+s[0].length)}o=o.replace(/\\([{}])/g,(l,a,h)=>{for(let c of r)c.line==n.length&&c.from>h&&(c.from--,c.to--);return a}),n.push(o)}return new gu(n,r)}}let vN=J.widget({widget:new class extends gn{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),MN=J.mark({class:"cm-snippetField"});class Ar{constructor(e,t){this.ranges=e,this.active=t,this.deco=J.set(e.map(n=>(n.from==n.to?vN:MN).range(n.from,n.to)),!0)}map(e){let t=[];for(let n of this.ranges){let r=n.map(e);if(!r)return null;t.push(r)}return new Ar(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(n=>n.field==this.active&&n.from<=t.from&&n.to>=t.to))}}const co=z.define({map(i,e){return i&&i.map(e)}}),AN=z.define(),Rs=Ge.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is(co))return t.value;if(t.is(AN)&&i)return new Ar(i.ranges,t.value)}return i&&e.docChanged&&(i=i.map(e.changes)),i&&e.selection&&!i.selectionInsideField(e.selection)&&(i=null),i},provide:i=>R.decorations.from(i,e=>e?e.deco:J.none)});function yu(i,e){return S.create(i.filter(t=>t.field==e).map(t=>S.range(t.from,t.to)))}function ON(i){let e=gu.parse(i);return(t,n,r,s)=>{let{text:o,ranges:l}=e.instantiate(t.state,r),{main:a}=t.state.selection,h={changes:{from:r,to:s==a.from?a.to:s,insert:U.of(o)},scrollIntoView:!0,annotations:n?[fu.of(n),pe.userEvent.of("input.complete")]:void 0};if(l.length&&(h.selection=yu(l,0)),l.some(c=>c.field>0)){let c=new Ar(l,0),f=h.effects=[co.of(c)];t.state.field(Rs,!1)===void 0&&f.push(z.appendConfig.of([Rs,EN,RN,Tk]))}t.dispatch(t.state.update(h))}}function Nk(i){return({state:e,dispatch:t})=>{let n=e.field(Rs,!1);if(!n||i<0&&n.active==0)return!1;let r=n.active+i,s=i>0&&!n.ranges.some(o=>o.field==r+i);return t(e.update({selection:yu(n.ranges,r),effects:co.of(s?null:new Ar(n.ranges,r)),scrollIntoView:!0})),!0}}const TN=({state:i,dispatch:e})=>i.field(Rs,!1)?(e(i.update({effects:co.of(null)})),!0):!1,NN=Nk(1),DN=Nk(-1),IN=[{key:"Tab",run:NN,shift:DN},{key:"Escape",run:TN}],cm=D.define({combine(i){return i.length?i[0]:IN}}),EN=vi.highest(hf.compute([cm],i=>i.facet(cm)));function QD(i,e){return{...e,apply:ON(i)}}const RN=R.domEventHandlers({mousedown(i,e){let t=e.state.field(Rs,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let r=t.ranges.find(s=>s.from<=n&&s.to>=n);return!r||r.field==t.active?!1:(e.dispatch({selection:yu(t.ranges,r.field),effects:co.of(t.ranges.some(s=>s.field>r.field)?new Ar(t.ranges,r.field):null),scrollIntoView:!0}),!0)}}),Bs={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},ni=z.define({map(i,e){let t=e.mapPos(i,-1,Ae.TrackAfter);return t??void 0}}),bu=new class extends zn{};bu.startSide=1;bu.endSide=-1;const Dk=Ge.define({create(){return $.empty},update(i,e){if(i=i.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);i=i.update({filter:n=>n>=t.from&&n<=t.to})}for(let t of e.effects)t.is(ni)&&(i=i.update({add:[bu.range(t.value,t.value+1)]}));return i}});function ZD(){return[PN,Dk]}const ih="()[]{}<>«»»«[]{}";function Ik(i){for(let e=0;e<ih.length;e+=2)if(ih.charCodeAt(e)==i)return ih.charAt(e+1);return A0(i<128?i:i+1)}function Ek(i,e){return i.languageDataAt("closeBrackets",e)[0]||Bs}const BN=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),PN=R.inputHandler.of((i,e,t,n)=>{if((BN?i.composing:i.compositionStarted)||i.state.readOnly)return!1;let r=i.state.selection.main;if(n.length>2||n.length==2&&Zt(it(n,0))==1||e!=r.from||t!=r.to)return!1;let s=FN(i.state,n);return s?(i.dispatch(s),!0):!1}),LN=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let n=Ek(i,i.selection.main.head).brackets||Bs.brackets,r=null,s=i.changeByRange(o=>{if(o.empty){let l=VN(i.doc,o.head);for(let a of n)if(a==l&&ra(i.doc,o.head)==Ik(it(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:S.cursor(o.head-a.length)}}return{range:r=o}});return r||e(i.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!r},eI=[{key:"Backspace",run:LN}];function FN(i,e){let t=Ek(i,i.selection.main.head),n=t.brackets||Bs.brackets;for(let r of n){let s=Ik(it(r,0));if(e==r)return s==r?WN(i,r,n.indexOf(r+r+r)>-1,t):zN(i,r,s,t.before||Bs.before);if(e==s&&Rk(i,i.selection.main.from))return HN(i,r,s)}return null}function Rk(i,e){let t=!1;return i.field(Dk).between(0,i.doc.length,n=>{n==e&&(t=!0)}),t}function ra(i,e){let t=i.sliceString(e,e+2);return t.slice(0,Zt(it(t,0)))}function VN(i,e){let t=i.sliceString(e-2,e);return Zt(it(t,0))==t.length?t:t.slice(1)}function zN(i,e,t,n){let r=null,s=i.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:ni.of(o.to+e.length),range:S.range(o.anchor+e.length,o.head+e.length)};let l=ra(i.doc,o.head);return!l||/\s/.test(l)||n.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:ni.of(o.head+e.length),range:S.cursor(o.head+e.length)}:{range:r=o}});return r?null:i.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function HN(i,e,t){let n=null,r=i.changeByRange(s=>s.empty&&ra(i.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:S.cursor(s.head+t.length)}:n={range:s});return n?null:i.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function WN(i,e,t,n){let r=n.stringPrefixes||Bs.stringPrefixes,s=null,o=i.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:ni.of(l.to+e.length),range:S.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=ra(i.doc,a),c;if(h==e){if(fm(i,a))return{changes:{insert:e+e,from:a},effects:ni.of(a+e.length),range:S.cursor(a+e.length)};if(Rk(i,a)){let u=t&&i.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:S.cursor(a+u.length)}}}else{if(t&&i.sliceDoc(a-2*e.length,a)==e+e&&(c=um(i,a-2*e.length,r))>-1&&fm(i,c))return{changes:{insert:e+e+e+e,from:a},effects:ni.of(a+e.length),range:S.cursor(a+e.length)};if(i.charCategorizer(a)(h)!=ut.Word&&um(i,a,r)>-1&&!$N(i,a,e,r))return{changes:{insert:e+e,from:a},effects:ni.of(a+e.length),range:S.cursor(a+e.length)}}return{range:s=l}});return s?null:i.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fm(i,e){let t=Ne(i).resolveInner(e+1);return t.parent&&t.from==e}function $N(i,e,t,n){let r=Ne(i).resolveInner(e,-1),s=n.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=i.sliceDoc(r.from,Math.min(r.to,r.from+t.length+s)),a=l.indexOf(t);if(!a||a>-1&&n.indexOf(l.slice(0,a))>-1){let c=r.firstChild;for(;c&&c.from==r.from&&c.to-c.from>t.length+a;){if(i.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=r.to==e&&r.parent;if(!h)break;r=h}return!1}function um(i,e,t){let n=i.charCategorizer(e);if(n(i.sliceDoc(e-1,e))!=ut.Word)return e;for(let r of t){let s=e-r.length;if(i.sliceDoc(s,e)==r&&n(i.sliceDoc(s-1,s))!=ut.Word)return s}return-1}function tI(i={}){return[SN,Ye,ke.of(i),xN,qN,Tk]}const KN=[{key:"Ctrl-Space",run:nh},{mac:"Alt-`",run:nh},{mac:"Alt-i",run:nh},{key:"Escape",run:gN},{key:"ArrowDown",run:Lo(!0)},{key:"ArrowUp",run:Lo(!1)},{key:"PageDown",run:Lo(!0,"page")},{key:"PageUp",run:Lo(!1,"page")},{key:"Enter",run:mN}],qN=vi.highest(hf.computeN([ke],i=>i.facet(ke).defaultKeymap?[KN]:[])),nI=io.define([{tag:[v.keyword,v.modifier],class:"hljs-keyword"},{tag:[v.string,v.regexp,v.quote],class:"hljs-string"},{tag:[v.number,v.bool,v.null,v.atom],class:"hljs-number"},{tag:v.comment,class:"hljs-comment"},{tag:[v.typeName,v.className,v.namespace],class:"hljs-type"},{tag:[v.function(v.variableName),v.function(v.propertyName),v.definition(v.variableName)],class:"hljs-title"},{tag:[v.propertyName,v.attributeName],class:"hljs-attr"},{tag:[v.meta,v.processingInstruction],class:"hljs-meta"},{tag:v.tagName,class:"hljs-selector-tag"},{tag:v.heading,color:"var(--link)",fontWeight:"bold"},{tag:v.link,color:"var(--link)",textDecoration:"underline"},{tag:v.emphasis,fontStyle:"italic"},{tag:v.strong,fontWeight:"bold"}]);export{nI as $,Y as A,ti as B,Mk as C,US as D,R as E,eb as F,pr as G,JA as H,Q as I,pA as J,Ge as K,yc as L,J as M,qc as N,$l as O,b0 as P,ED as Q,_D as R,mb as S,ie as T,SD as U,MD as V,gn as W,GD as X,UD as Y,KD as Z,pe as _,PD as a,wD as a$,pD as a0,Xs as a1,kr as a2,gO as a3,_i as a4,Sr as a5,tu as a6,V as a7,K as a8,oo as a9,kt as aA,dD as aB,Fl as aC,Jn as aD,Wl as aE,Qs as aF,Tt as aG,Rc as aH,rD as aI,Ai as aJ,nD as aK,Lx as aL,sx as aM,z as aN,JM as aO,ID as aP,DD as aQ,be as aR,pc as aS,it as aT,Zt as aU,D as aV,Mi as aW,ut as aX,Bn as aY,A0 as aZ,Ii as a_,un as aa,Kn as ab,il as ac,xt as ad,io as ae,pn as af,ee as ag,ue as ah,E as ai,A as aj,Zr as ak,de as al,le as am,Ln as an,yr as ao,tD as ap,Px as aq,on as ar,ZN as as,oD as at,Ci as au,Jx as av,_ as aw,E1 as ax,I1 as ay,Ot as az,XD as b,yf as b$,Re as b0,ND as b1,TD as b2,RD as b3,vD as b4,$D as b5,CD as b6,zD as b7,qD as b8,jD as b9,Oa as bA,JD as bB,YD as bC,eD as bD,ig as bE,QN as bF,Vx as bG,e0 as bH,Km as bI,Zk as bJ,jx as bK,Od as bL,XN as bM,IO as bN,EO as bO,Oi as bP,so as bQ,RO as bR,ao as bS,BO as bT,Cr as bU,vr as bV,PO as bW,xf as bX,NO as bY,ro as bZ,wf as b_,ZD as ba,tI as bb,AD as bc,OD as bd,eI as be,WD as bf,KN as bg,j as bh,jt as bi,Ea as bj,$o as bk,sD as bl,nr as bm,iD as bn,_S as bo,st as bp,q as bq,Wi as br,Wo as bs,Fn as bt,Da as bu,q1 as bv,fD as bw,mD as bx,uD as by,Ra as bz,VD as c,wr as c0,bf as c1,Cf as c2,Nn as c3,vf as c4,DO as c5,Ur as c6,gD as c7,QT as d,Ne as e,AA as f,S as g,LD as h,tb as i,HD as j,je as k,H as l,FD as m,QD as n,bD as o,kD as p,ct as q,vi as r,hA as s,v as t,hf as u,MA as v,xr as w,pt as x,Gl as y,Qy as z};
|