@agentdocumentformat/cli 0.8.4 → 0.8.5

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.
Files changed (30) hide show
  1. package/dist/adf.mjs +2 -2
  2. package/dist/chunks/{chunk-2WIFHJV2.mjs → chunk-IHARCBZH.mjs} +8 -1
  3. package/dist/chunks/{claude-subscription-42L4YM5L.mjs → claude-subscription-X5EVR3Q4.mjs} +1 -1
  4. package/dist/chunks/{daemon-DK3KUDZJ.mjs → daemon-YRG2QUF4.mjs} +3 -3
  5. package/package.json +1 -1
  6. package/web/assets/{EditorPanel-5ZGWvexa.js → EditorPanel-YXnanvaL.js} +3 -3
  7. package/web/assets/{MeshGraphView-Vp2R5TLK.js → MeshGraphView-ChgwUT3O.js} +9 -9
  8. package/web/assets/{SettingsPage-_uHkBERV.js → SettingsPage-BTu2-Yon.js} +1 -1
  9. package/web/assets/{agent-window-B8X7FV4_.js → agent-window-DlJbRHzy.js} +1 -1
  10. package/web/assets/{agent.store-BHweGGTh.js → agent.store-CGzsE0VA.js} +1 -1
  11. package/web/assets/{app.store-j_-OuVPe.js → app.store-hw-ZYpyz.js} +1 -1
  12. package/web/assets/{document.store-CMD3_OM0.js → document.store-BcN3UW-e.js} +1 -1
  13. package/web/assets/{edit-recovery-Ce8tPQZl.js → edit-recovery-uWM2umPk.js} +1 -1
  14. package/web/assets/{index-DS9H-PJI.js → index-B0BKR-7b.js} +1 -1
  15. package/web/assets/{index-Ca6bEWGu.js → index-Ba28S-D0.js} +1 -1
  16. package/web/assets/{index-BQIEMvvt.js → index-BxmMf4oH.js} +1 -1
  17. package/web/assets/{index-DBFkrLao.js → index-BxrG4na5.js} +1 -1
  18. package/web/assets/{index-B5Eot_tL.js → index-C0ujp8ua.js} +1 -1
  19. package/web/assets/{index-KNnHrO8-.js → index-CBCcou8F.js} +1 -1
  20. package/web/assets/{index-nM_Q5x7Q.js → index-Cuc6TCV0.js} +1 -1
  21. package/web/assets/{index-B5FYMbFc.js → index-DlQ8IXY2.js} +1 -1
  22. package/web/assets/{index-C_gf4L3q.js → index-Dms-d0wP.js} +1 -1
  23. package/web/assets/{index-DF1leTEa.js → index-LwIi-F1W.js} +2 -2
  24. package/web/assets/{index-DkhbLs9K.js → index-mW7p_CTU.js} +1 -1
  25. package/web/assets/{main-o2ocfqUC.js → main-CR7cfmOT.js} +3 -3
  26. package/web/assets/{message-queue.store-ke_rFZAb.js → message-queue.store-BMjJTJTP.js} +1 -1
  27. package/web/assets/{react-D-F9gHrJ.js → react-wKFncLeZ.js} +1 -1
  28. package/web/assets/{window-kind-mxlpdE1l.js → window-kind-35FHmfEB.js} +1 -1
  29. package/web/assets/{with-selector-Ot-ZoUn0.js → with-selector-CBB0rjuB.js} +1 -1
  30. package/web/index.html +1 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-KNnHrO8-.js","assets/index-C_gf4L3q.js","assets/index-DF1leTEa.js","assets/index-CuTaWSEs.css","assets/edit-recovery-Ce8tPQZl.js","assets/react-D-F9gHrJ.js","assets/agent.store-BHweGGTh.js","assets/document.store-CMD3_OM0.js","assets/window-kind-mxlpdE1l.js","assets/app.store-j_-OuVPe.js","assets/main-o2ocfqUC.js","assets/message-queue.store-ke_rFZAb.js","assets/agent-window-B8X7FV4_.js","assets/main-Zf3qnQYd.css","assets/with-selector-Ot-ZoUn0.js","assets/index-B5FYMbFc.js","assets/index-DBFkrLao.js","assets/index-nM_Q5x7Q.js","assets/index-DS9H-PJI.js","assets/index-B5Eot_tL.js","assets/index-BQIEMvvt.js","assets/index-Ca6bEWGu.js","assets/index-DkhbLs9K.js"])))=>i.map(i=>d[i]);
2
- import{j as S,a as M,R as En,m as hw,_ as tt}from"./index-DF1leTEa.js";import{u as ve,i as Ba}from"./edit-recovery-Ce8tPQZl.js";import{useDocumentStore as dt}from"./document.store-CMD3_OM0.js";import{u as tn,s as uw}from"./app.store-j_-OuVPe.js";import{a as $f,u as Vf}from"./agent.store-BHweGGTh.js";import{T as fw,f as bg,s as xg,o as wg,a as kg,b as vg,c as Sg,h as Cg,i as Mg,d as Tg,R as dw,r as Ag,e as pw,g as mw,j as gw,k as yw,l as bw,m as xw,n as ww,p as kw,q as vw,D as Sw,t as Cw,u as Mw,A as Tw,v as Aw,C as Ew,E as Ow,I as Rw,w as Dw,x as Nw}from"./main-o2ocfqUC.js";import{r as Iw,w as Lw}from"./with-selector-Ot-ZoUn0.js";import{o as Qi,u as Pw}from"./agent-window-B8X7FV4_.js";const Wf="group relative z-10 flex items-center gap-1.5 px-3 text-xs font-medium whitespace-nowrap transition-colors focus-visible:[outline-offset:-2px]",jf="bg-surface-1 text-[var(--adf-ui-text)] shadow-[inset_0_2px_0_0_var(--adf-ui-text-subtle)]",_f="text-[var(--adf-ui-text-muted)] hover:bg-neutral-500/10 hover:text-[var(--adf-ui-text)]",Js="w-4 h-4 flex items-center justify-center rounded-sm hover:bg-neutral-500/20";function Uf(){return S.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 8 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[S.jsx("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),S.jsx("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})}function za({tabs:n,activeTabPath:e,onSelect:t,onClose:i,onReload:r,chatTab:s}){const o=tn(a=>a.computerMatchTab),l=tn(a=>a.setComputerMatchTab);return n.length===0&&!s?null:S.jsxs("div",{className:"relative flex h-9 items-stretch bg-surface-0 shrink-0",children:[S.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 bottom-0 h-px bg-hairline"}),s&&S.jsxs(S.Fragment,{children:[S.jsxs("button",{type:"button",onClick:s.onSelect,title:"Loops — the agent's chat",className:`${Wf} shrink-0 ${s.active?jf:_f}`,children:[S.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:S.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),S.jsx("span",{children:"Loops"}),S.jsx("span",{"aria-hidden":!0,className:`w-1.5 h-1.5 rounded-full shrink-0 ${s.unread&&!s.active?"bg-blue-500":"bg-transparent"}`}),S.jsx("span",{onClick:a=>{a.stopPropagation(),s.onClose()},title:"Close — put the chat back in the side panel",className:`ml-1 ${Js} ${s.active?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsx(Uf,{})})]}),S.jsx("span",{"aria-hidden":!0,className:"relative z-10 w-px shrink-0 self-stretch bg-hairline"})]}),S.jsx("div",{className:"scrollbar-none flex flex-1 min-w-0 items-stretch overflow-x-auto overflow-y-hidden",children:n.map(a=>{const c=a.path===e,h=a.kind==="browser",u=h?"Computer":a.path.split("/").pop()??a.path,f=h&&a.browserMeta?a.browserMeta.hostPort!=null?`Agent computer — http://127.0.0.1:${a.browserMeta.hostPort}`:"Agent computer — not ready":a.path;return S.jsxs("button",{onClick:()=>t(a.path),onMouseDown:d=>{d.button===1&&(d.preventDefault(),i(a.path))},className:`${Wf} shrink-0 border-r border-hairline ${c?jf:_f}`,children:[S.jsx("span",{className:"truncate max-w-[150px]",title:f,children:u}),h&&S.jsx(fw,{tip:o?"Match tab size is on: the agent's screen resizes to fill this tab. Click to keep the agent's size and scale it to fit.":"Match tab size: resize the agent's screen to fill this tab. Off, the screen keeps the size the agent set, scaled to fit.",children:S.jsx("span",{onClick:d=>{d.stopPropagation(),l(!o)},"aria-pressed":o,className:`${Js} ${o?"opacity-100 text-[var(--adf-ui-accent)]":c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("polyline",{points:"15 3 21 3 21 9"}),S.jsx("polyline",{points:"9 21 3 21 3 15"}),S.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),S.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})}),h&&r&&S.jsx("span",{onClick:d=>{d.stopPropagation(),r(a.path)},title:"Reload viewer",className:`${Js} ${c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"}),S.jsx("polyline",{points:"21 3 21 9 15 9"})]})}),S.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.isDirty?"bg-[var(--adf-ui-text-muted)]":"bg-transparent"}`}),S.jsx("span",{onClick:d=>{d.stopPropagation(),i(a.path)},className:`ml-1 ${Js} ${c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsx(Uf,{})})]},a.path)})})]})}var Eg=Iw();function Fe(n){this.content=n}Fe.prototype={constructor:Fe,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var i=t&&t!=n?this.remove(t):this,r=i.find(n),s=i.content.slice();return r==-1?s.push(t||n,e):(s[r+1]=e,t&&(s[r]=t)),new Fe(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Fe(t)},addToStart:function(n,e){return new Fe([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Fe(t)},addBefore:function(n,e,t){var i=this.remove(e),r=i.content.slice(),s=i.find(n);return r.splice(s==-1?r.length:s,0,e,t),new Fe(r)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Fe.from(n),n.size?new Fe(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Fe.from(n),n.size?new Fe(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Fe.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};Fe.from=function(n){if(n instanceof Fe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Fe(e)};function Og(n,e,t){for(let i=0;;i++){if(i==n.childCount||i==e.childCount)return n.childCount==e.childCount?null:t;let r=n.child(i),s=e.child(i);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){for(let o=0;r.text[o]==s.text[o];o++)t++;return t}if(r.content.size||s.content.size){let o=Og(r.content,s.content,t+1);if(o!=null)return o}t+=r.nodeSize}}function Rg(n,e,t,i){for(let r=n.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:i};let o=n.child(--r),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,i-=a;continue}if(!o.sameMarkup(l))return{a:t,b:i};if(o.isText&&o.text!=l.text){let c=0,h=Math.min(o.text.length,l.text.length);for(;c<h&&o.text[o.text.length-c-1]==l.text[l.text.length-c-1];)c++,t--,i--;return{a:t,b:i}}if(o.content.size||l.content.size){let c=Rg(o.content,l.content,t-1,i-1);if(c)return c}t-=a,i-=a}}class A{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let i=0;i<e.length;i++)this.size+=e[i].nodeSize}nodesBetween(e,t,i,r=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&i(a,r+l,s||null,o)!==!1&&a.content.size){let h=l+1;a.nodesBetween(Math.max(0,e-h),Math.min(a.content.size,t-h),i,r+h)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,i,r){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=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&&c||l.isTextblock)&&i&&(o?o=!1:s+=i),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,i=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(i)&&(r[r.length-1]=t.withText(t.text+i.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 i=[],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))),i.push(l),r+=l.nodeSize),o=a}return new A(i,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 i=this.content[e];if(i==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-i.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,i=0;t<this.content.length;t++){let r=this.content[t];e(r,i,t),i+=r.nodeSize}}findDiffStart(e,t=0){return Og(this,e,t)}findDiffEnd(e,t=this.size,i=e.size){return Rg(this,e,t,i)}findIndex(e){if(e==0)return Gs(0,e);if(e==this.size)return Gs(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,i=0;;t++){let r=this.child(t),s=i+r.nodeSize;if(s>=e)return s==e?Gs(t+1,s):Gs(t,i);i=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 new A(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return A.empty;let t,i=0;for(let r=0;r<e.length;r++){let s=e[r];i+=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,i)}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 Ha={index:0,offset:0};function Gs(n,e){return Ha.index=n,Ha.offset=e,Ha}function Ko(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!Ko(n[i],e[i]))return!1}else{for(let i in n)if(!(i in e)||!Ko(n[i],e[i]))return!1;for(let i in e)if(!(i in n))return!1}return!0}let ae=class Fc{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,i=!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;!i&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),i=!0),t&&t.push(s)}}return t||(t=e.slice()),i||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&&Ko(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 i=e.marks[t.type];if(!i)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=i.create(t.attrs);return i.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].eq(t[i]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Fc.none;if(e instanceof Fc)return[e];let t=e.slice();return t.sort((i,r)=>i.type.rank-r.type.rank),t}};ae.none=[];class Jo extends Error{}class I{constructor(e,t,i){this.content=e,this.openStart=t,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let i=Ng(this.content,e+this.openStart,t);return i&&new I(i,this.openStart,this.openEnd)}removeBetween(e,t){return new I(Dg(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 I.empty;let i=t.openStart||0,r=t.openEnd||0;if(typeof i!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new I(A.fromJSON(e,t.content),i,r)}static maxOpen(e,t=!0){let i=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)i++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new I(e,i,r)}}I.empty=new I(A.empty,0,0);function Dg(n,e,t){let{index:i,offset:r}=n.findIndex(e),s=n.maybeChild(i),{index:o,offset:l}=n.findIndex(t);if(r==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(i!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(i,s.copy(Dg(s.content,e-r-1,t-r-1)))}function Ng(n,e,t,i){let{index:r,offset:s}=n.findIndex(e),o=n.maybeChild(r);if(s==e||o.isText)return i&&!i.canReplace(r,r,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Ng(o.content,e-s-1,t,o);return l&&n.replaceChild(r,o.copy(l))}function Bw(n,e,t){if(t.openStart>n.depth)throw new Jo("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Jo("Inconsistent open depths");return Ig(n,e,t,0)}function Ig(n,e,t,i){let r=n.index(i),s=n.node(i);if(r==e.index(i)&&i<n.depth-t.openStart){let o=Ig(n,e,t,i+1);return s.copy(s.content.replaceChild(r,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==i&&e.depth==i){let o=n.parent,l=o.content;return ki(o,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=zw(t,n);return ki(s,Pg(n,o,l,e,i))}else return ki(s,Go(n,e,i))}function Lg(n,e){if(!e.type.compatibleContent(n.type))throw new Jo("Cannot join "+e.type.name+" onto "+n.type.name)}function $c(n,e,t){let i=n.node(t);return Lg(i,e.node(t)),i}function wi(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Jr(n,e,t,i){let r=(e||n).node(t),s=0,o=e?e.index(t):r.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(wi(n.nodeAfter,i),s++));for(let l=s;l<o;l++)wi(r.child(l),i);e&&e.depth==t&&e.textOffset&&wi(e.nodeBefore,i)}function ki(n,e){return n.type.checkContent(e),n.copy(e)}function Pg(n,e,t,i,r){let s=n.depth>r&&$c(n,e,r+1),o=i.depth>r&&$c(t,i,r+1),l=[];return Jr(null,n,r,l),s&&o&&e.index(r)==t.index(r)?(Lg(s,o),wi(ki(s,Pg(n,e,t,i,r+1)),l)):(s&&wi(ki(s,Go(n,e,r+1)),l),Jr(e,t,r,l),o&&wi(ki(o,Go(t,i,r+1)),l)),Jr(i,null,r,l),new A(l)}function Go(n,e,t){let i=[];if(Jr(null,n,t,i),n.depth>t){let r=$c(n,e,t+1);wi(ki(r,Go(n,e,t+1)),i)}return Jr(e,null,t,i),new A(i)}function zw(n,e){let t=e.depth-n.openStart,r=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(A.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class us{constructor(e,t,i){this.pos=e,this.path=t,this.parentOffset=i,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 i=this.pos-this.path[this.path.length-1],r=e.child(t);return i?e.child(t).cut(i):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 i=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=i.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return ae.none;if(this.textOffset)return e.child(t).marks;let i=e.maybeChild(t-1),r=e.maybeChild(t);if(!i){let l=i;i=r,r=l}let s=i.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 i=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<i.length;s++)i[s].type.spec.inclusive===!1&&(!r||!i[s].isInSet(r.marks))&&(i=i[s--].removeFromSet(i));return i}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 i=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);i>=0;i--)if(e.pos<=this.end(i)&&(!t||t(this.node(i))))return new Yo(this,e,i);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 i=[],r=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(i.push(o,l,r+a),!c||(o=o.child(l),o.isText))break;s=c-1,r+=a+1}return new us(t,i,s)}static resolveCached(e,t){let i=qf.get(e);if(i)for(let s=0;s<i.elts.length;s++){let o=i.elts[s];if(o.pos==t)return o}else qf.set(e,i=new Hw);let r=i.elts[i.i]=us.resolve(e,t);return i.i=(i.i+1)%Fw,r}}class Hw{constructor(){this.elts=[],this.i=0}}const Fw=12,qf=new WeakMap;class Yo{constructor(e,t,i){this.$from=e,this.$to=t,this.depth=i}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 $w=Object.create(null);class Wt{constructor(e,t,i,r=ae.none){this.type=e,this.attrs=t,this.marks=r,this.content=i||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,i,r=0){this.content.nodesBetween(e,t,i,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,i,r){return this.content.textBetween(e,t,i,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,i){return this.type==e&&Ko(this.attrs,t||e.defaultAttrs||$w)&&ae.sameSet(this.marks,i||ae.none)}copy(e=null){return e==this.content?this:new Wt(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Wt(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,i=!1){if(e==t)return I.empty;let r=this.resolve(e),s=this.resolve(t),o=i?0:r.sharedDepth(t),l=r.start(o),c=r.node(o).content.cut(r.pos-l,s.pos-l);return new I(c,r.depth-o,s.depth-o)}replace(e,t,i){return Bw(this.resolve(e),this.resolve(t),i)}nodeAt(e){for(let t=this;;){let{index:i,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(i),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:i}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:i}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:i}=this.content.findIndex(e);if(i<e)return{node:this.content.child(t),index:t,offset:i};let r=this.content.child(t-1);return{node:r,index:t-1,offset:i-r.nodeSize}}resolve(e){return us.resolveCached(this,e)}resolveNoCache(e){return us.resolve(this,e)}rangeHasMark(e,t,i){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(i.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()+")"),Bg(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,i=A.empty,r=0,s=i.childCount){let o=this.contentMatchAt(e).matchFragment(i,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(i.child(a).marks))return!1;return!0}canReplaceWith(e,t,i,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(i),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),this.type.checkAttrs(this.attrs);let e=ae.none;for(let t=0;t<this.marks.length;t++){let i=this.marks[t];i.type.checkAttrs(i.attrs),e=i.addToSet(e)}if(!ae.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 i;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=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,i)}let r=A.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,i);return s.type.checkAttrs(s.attrs),s}}Wt.prototype.text=void 0;let Vw=class Vc extends Wt{constructor(e,t,i,r){if(super(e,t,null,r),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Bg(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 Vc(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Vc(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 Bg(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Ti{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let i=new Ww(e,t);if(i.next==null)return Ti.empty;let r=zg(i);i.next&&i.err("Unexpected trailing text");let s=Gw(Jw(r));return Yw(s,i),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,i=e.childCount){let r=this;for(let s=t;r&&s<i;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 i=0;i<e.next.length;i++)if(this.next[t].type==e.next[i].type)return!0;return!1}fillBefore(e,t=!1,i=0){let r=[this];function s(o,l){let a=o.matchFragment(e,i);if(a&&(!t||a.validEnd))return A.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:h,next:u}=o.next[c];if(!(h.isText||h.hasRequiredAttrs())&&r.indexOf(u)==-1){r.push(u);let f=s(u,l.concat(h));if(f)return f}}return null}return s(this,[])}findWrapping(e){for(let i=0;i<this.wrapCache.length;i+=2)if(this.wrapCache[i]==e)return this.wrapCache[i+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),i=[{match:this,type:null,via:null}];for(;i.length;){let r=i.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)&&(i.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(i){e.push(i);for(let r=0;r<i.next.length;r++)e.indexOf(i.next[r].next)==-1&&t(i.next[r].next)}return t(this),e.map((i,r)=>{let s=r+(i.validEnd?"*":" ")+" ";for(let o=0;o<i.next.length;o++)s+=(o?", ":"")+i.next[o].type.name+"->"+e.indexOf(i.next[o].next);return s}).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CBCcou8F.js","assets/index-Dms-d0wP.js","assets/index-LwIi-F1W.js","assets/index-CuTaWSEs.css","assets/edit-recovery-uWM2umPk.js","assets/react-wKFncLeZ.js","assets/agent.store-CGzsE0VA.js","assets/document.store-BcN3UW-e.js","assets/window-kind-35FHmfEB.js","assets/app.store-hw-ZYpyz.js","assets/main-CR7cfmOT.js","assets/message-queue.store-BMjJTJTP.js","assets/agent-window-DlJbRHzy.js","assets/main-Zf3qnQYd.css","assets/with-selector-CBB0rjuB.js","assets/index-DlQ8IXY2.js","assets/index-BxrG4na5.js","assets/index-Cuc6TCV0.js","assets/index-B0BKR-7b.js","assets/index-C0ujp8ua.js","assets/index-BxmMf4oH.js","assets/index-Ba28S-D0.js","assets/index-mW7p_CTU.js"])))=>i.map(i=>d[i]);
2
+ import{j as S,a as M,R as En,m as hw,_ as tt}from"./index-LwIi-F1W.js";import{u as ve,i as Ba}from"./edit-recovery-uWM2umPk.js";import{useDocumentStore as dt}from"./document.store-BcN3UW-e.js";import{u as tn,s as uw}from"./app.store-hw-ZYpyz.js";import{a as $f,u as Vf}from"./agent.store-CGzsE0VA.js";import{T as fw,f as bg,s as xg,o as wg,a as kg,b as vg,c as Sg,h as Cg,i as Mg,d as Tg,R as dw,r as Ag,e as pw,g as mw,j as gw,k as yw,l as bw,m as xw,n as ww,p as kw,q as vw,D as Sw,t as Cw,u as Mw,A as Tw,v as Aw,C as Ew,E as Ow,I as Rw,w as Dw,x as Nw}from"./main-CR7cfmOT.js";import{r as Iw,w as Lw}from"./with-selector-CBB0rjuB.js";import{o as Qi,u as Pw}from"./agent-window-DlJbRHzy.js";const Wf="group relative z-10 flex items-center gap-1.5 px-3 text-xs font-medium whitespace-nowrap transition-colors focus-visible:[outline-offset:-2px]",jf="bg-surface-1 text-[var(--adf-ui-text)] shadow-[inset_0_2px_0_0_var(--adf-ui-text-subtle)]",_f="text-[var(--adf-ui-text-muted)] hover:bg-neutral-500/10 hover:text-[var(--adf-ui-text)]",Js="w-4 h-4 flex items-center justify-center rounded-sm hover:bg-neutral-500/20";function Uf(){return S.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 8 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[S.jsx("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),S.jsx("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})}function za({tabs:n,activeTabPath:e,onSelect:t,onClose:i,onReload:r,chatTab:s}){const o=tn(a=>a.computerMatchTab),l=tn(a=>a.setComputerMatchTab);return n.length===0&&!s?null:S.jsxs("div",{className:"relative flex h-9 items-stretch bg-surface-0 shrink-0",children:[S.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 bottom-0 h-px bg-hairline"}),s&&S.jsxs(S.Fragment,{children:[S.jsxs("button",{type:"button",onClick:s.onSelect,title:"Loops — the agent's chat",className:`${Wf} shrink-0 ${s.active?jf:_f}`,children:[S.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:S.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),S.jsx("span",{children:"Loops"}),S.jsx("span",{"aria-hidden":!0,className:`w-1.5 h-1.5 rounded-full shrink-0 ${s.unread&&!s.active?"bg-blue-500":"bg-transparent"}`}),S.jsx("span",{onClick:a=>{a.stopPropagation(),s.onClose()},title:"Close — put the chat back in the side panel",className:`ml-1 ${Js} ${s.active?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsx(Uf,{})})]}),S.jsx("span",{"aria-hidden":!0,className:"relative z-10 w-px shrink-0 self-stretch bg-hairline"})]}),S.jsx("div",{className:"scrollbar-none flex flex-1 min-w-0 items-stretch overflow-x-auto overflow-y-hidden",children:n.map(a=>{const c=a.path===e,h=a.kind==="browser",u=h?"Computer":a.path.split("/").pop()??a.path,f=h&&a.browserMeta?a.browserMeta.hostPort!=null?`Agent computer — http://127.0.0.1:${a.browserMeta.hostPort}`:"Agent computer — not ready":a.path;return S.jsxs("button",{onClick:()=>t(a.path),onMouseDown:d=>{d.button===1&&(d.preventDefault(),i(a.path))},className:`${Wf} shrink-0 border-r border-hairline ${c?jf:_f}`,children:[S.jsx("span",{className:"truncate max-w-[150px]",title:f,children:u}),h&&S.jsx(fw,{tip:o?"Match tab size is on: the agent's screen resizes to fill this tab. Click to keep the agent's size and scale it to fit.":"Match tab size: resize the agent's screen to fill this tab. Off, the screen keeps the size the agent set, scaled to fit.",children:S.jsx("span",{onClick:d=>{d.stopPropagation(),l(!o)},"aria-pressed":o,className:`${Js} ${o?"opacity-100 text-[var(--adf-ui-accent)]":c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("polyline",{points:"15 3 21 3 21 9"}),S.jsx("polyline",{points:"9 21 3 21 3 15"}),S.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),S.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})}),h&&r&&S.jsx("span",{onClick:d=>{d.stopPropagation(),r(a.path)},title:"Reload viewer",className:`${Js} ${c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"}),S.jsx("polyline",{points:"21 3 21 9 15 9"})]})}),S.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.isDirty?"bg-[var(--adf-ui-text-muted)]":"bg-transparent"}`}),S.jsx("span",{onClick:d=>{d.stopPropagation(),i(a.path)},className:`ml-1 ${Js} ${c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsx(Uf,{})})]},a.path)})})]})}var Eg=Iw();function Fe(n){this.content=n}Fe.prototype={constructor:Fe,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var i=t&&t!=n?this.remove(t):this,r=i.find(n),s=i.content.slice();return r==-1?s.push(t||n,e):(s[r+1]=e,t&&(s[r]=t)),new Fe(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Fe(t)},addToStart:function(n,e){return new Fe([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Fe(t)},addBefore:function(n,e,t){var i=this.remove(e),r=i.content.slice(),s=i.find(n);return r.splice(s==-1?r.length:s,0,e,t),new Fe(r)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Fe.from(n),n.size?new Fe(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Fe.from(n),n.size?new Fe(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Fe.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};Fe.from=function(n){if(n instanceof Fe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Fe(e)};function Og(n,e,t){for(let i=0;;i++){if(i==n.childCount||i==e.childCount)return n.childCount==e.childCount?null:t;let r=n.child(i),s=e.child(i);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){for(let o=0;r.text[o]==s.text[o];o++)t++;return t}if(r.content.size||s.content.size){let o=Og(r.content,s.content,t+1);if(o!=null)return o}t+=r.nodeSize}}function Rg(n,e,t,i){for(let r=n.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:i};let o=n.child(--r),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,i-=a;continue}if(!o.sameMarkup(l))return{a:t,b:i};if(o.isText&&o.text!=l.text){let c=0,h=Math.min(o.text.length,l.text.length);for(;c<h&&o.text[o.text.length-c-1]==l.text[l.text.length-c-1];)c++,t--,i--;return{a:t,b:i}}if(o.content.size||l.content.size){let c=Rg(o.content,l.content,t-1,i-1);if(c)return c}t-=a,i-=a}}class A{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let i=0;i<e.length;i++)this.size+=e[i].nodeSize}nodesBetween(e,t,i,r=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&i(a,r+l,s||null,o)!==!1&&a.content.size){let h=l+1;a.nodesBetween(Math.max(0,e-h),Math.min(a.content.size,t-h),i,r+h)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,i,r){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=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&&c||l.isTextblock)&&i&&(o?o=!1:s+=i),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,i=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(i)&&(r[r.length-1]=t.withText(t.text+i.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 i=[],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))),i.push(l),r+=l.nodeSize),o=a}return new A(i,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 i=this.content[e];if(i==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-i.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,i=0;t<this.content.length;t++){let r=this.content[t];e(r,i,t),i+=r.nodeSize}}findDiffStart(e,t=0){return Og(this,e,t)}findDiffEnd(e,t=this.size,i=e.size){return Rg(this,e,t,i)}findIndex(e){if(e==0)return Gs(0,e);if(e==this.size)return Gs(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,i=0;;t++){let r=this.child(t),s=i+r.nodeSize;if(s>=e)return s==e?Gs(t+1,s):Gs(t,i);i=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 new A(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return A.empty;let t,i=0;for(let r=0;r<e.length;r++){let s=e[r];i+=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,i)}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 Ha={index:0,offset:0};function Gs(n,e){return Ha.index=n,Ha.offset=e,Ha}function Ko(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!Ko(n[i],e[i]))return!1}else{for(let i in n)if(!(i in e)||!Ko(n[i],e[i]))return!1;for(let i in e)if(!(i in n))return!1}return!0}let ae=class Fc{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,i=!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;!i&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),i=!0),t&&t.push(s)}}return t||(t=e.slice()),i||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&&Ko(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 i=e.marks[t.type];if(!i)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=i.create(t.attrs);return i.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].eq(t[i]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Fc.none;if(e instanceof Fc)return[e];let t=e.slice();return t.sort((i,r)=>i.type.rank-r.type.rank),t}};ae.none=[];class Jo extends Error{}class I{constructor(e,t,i){this.content=e,this.openStart=t,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let i=Ng(this.content,e+this.openStart,t);return i&&new I(i,this.openStart,this.openEnd)}removeBetween(e,t){return new I(Dg(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 I.empty;let i=t.openStart||0,r=t.openEnd||0;if(typeof i!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new I(A.fromJSON(e,t.content),i,r)}static maxOpen(e,t=!0){let i=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)i++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new I(e,i,r)}}I.empty=new I(A.empty,0,0);function Dg(n,e,t){let{index:i,offset:r}=n.findIndex(e),s=n.maybeChild(i),{index:o,offset:l}=n.findIndex(t);if(r==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(i!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(i,s.copy(Dg(s.content,e-r-1,t-r-1)))}function Ng(n,e,t,i){let{index:r,offset:s}=n.findIndex(e),o=n.maybeChild(r);if(s==e||o.isText)return i&&!i.canReplace(r,r,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Ng(o.content,e-s-1,t,o);return l&&n.replaceChild(r,o.copy(l))}function Bw(n,e,t){if(t.openStart>n.depth)throw new Jo("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Jo("Inconsistent open depths");return Ig(n,e,t,0)}function Ig(n,e,t,i){let r=n.index(i),s=n.node(i);if(r==e.index(i)&&i<n.depth-t.openStart){let o=Ig(n,e,t,i+1);return s.copy(s.content.replaceChild(r,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==i&&e.depth==i){let o=n.parent,l=o.content;return ki(o,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=zw(t,n);return ki(s,Pg(n,o,l,e,i))}else return ki(s,Go(n,e,i))}function Lg(n,e){if(!e.type.compatibleContent(n.type))throw new Jo("Cannot join "+e.type.name+" onto "+n.type.name)}function $c(n,e,t){let i=n.node(t);return Lg(i,e.node(t)),i}function wi(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Jr(n,e,t,i){let r=(e||n).node(t),s=0,o=e?e.index(t):r.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(wi(n.nodeAfter,i),s++));for(let l=s;l<o;l++)wi(r.child(l),i);e&&e.depth==t&&e.textOffset&&wi(e.nodeBefore,i)}function ki(n,e){return n.type.checkContent(e),n.copy(e)}function Pg(n,e,t,i,r){let s=n.depth>r&&$c(n,e,r+1),o=i.depth>r&&$c(t,i,r+1),l=[];return Jr(null,n,r,l),s&&o&&e.index(r)==t.index(r)?(Lg(s,o),wi(ki(s,Pg(n,e,t,i,r+1)),l)):(s&&wi(ki(s,Go(n,e,r+1)),l),Jr(e,t,r,l),o&&wi(ki(o,Go(t,i,r+1)),l)),Jr(i,null,r,l),new A(l)}function Go(n,e,t){let i=[];if(Jr(null,n,t,i),n.depth>t){let r=$c(n,e,t+1);wi(ki(r,Go(n,e,t+1)),i)}return Jr(e,null,t,i),new A(i)}function zw(n,e){let t=e.depth-n.openStart,r=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(A.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class us{constructor(e,t,i){this.pos=e,this.path=t,this.parentOffset=i,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 i=this.pos-this.path[this.path.length-1],r=e.child(t);return i?e.child(t).cut(i):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 i=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=i.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return ae.none;if(this.textOffset)return e.child(t).marks;let i=e.maybeChild(t-1),r=e.maybeChild(t);if(!i){let l=i;i=r,r=l}let s=i.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 i=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<i.length;s++)i[s].type.spec.inclusive===!1&&(!r||!i[s].isInSet(r.marks))&&(i=i[s--].removeFromSet(i));return i}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 i=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);i>=0;i--)if(e.pos<=this.end(i)&&(!t||t(this.node(i))))return new Yo(this,e,i);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 i=[],r=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(i.push(o,l,r+a),!c||(o=o.child(l),o.isText))break;s=c-1,r+=a+1}return new us(t,i,s)}static resolveCached(e,t){let i=qf.get(e);if(i)for(let s=0;s<i.elts.length;s++){let o=i.elts[s];if(o.pos==t)return o}else qf.set(e,i=new Hw);let r=i.elts[i.i]=us.resolve(e,t);return i.i=(i.i+1)%Fw,r}}class Hw{constructor(){this.elts=[],this.i=0}}const Fw=12,qf=new WeakMap;class Yo{constructor(e,t,i){this.$from=e,this.$to=t,this.depth=i}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 $w=Object.create(null);class Wt{constructor(e,t,i,r=ae.none){this.type=e,this.attrs=t,this.marks=r,this.content=i||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,i,r=0){this.content.nodesBetween(e,t,i,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,i,r){return this.content.textBetween(e,t,i,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,i){return this.type==e&&Ko(this.attrs,t||e.defaultAttrs||$w)&&ae.sameSet(this.marks,i||ae.none)}copy(e=null){return e==this.content?this:new Wt(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Wt(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,i=!1){if(e==t)return I.empty;let r=this.resolve(e),s=this.resolve(t),o=i?0:r.sharedDepth(t),l=r.start(o),c=r.node(o).content.cut(r.pos-l,s.pos-l);return new I(c,r.depth-o,s.depth-o)}replace(e,t,i){return Bw(this.resolve(e),this.resolve(t),i)}nodeAt(e){for(let t=this;;){let{index:i,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(i),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:i}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:i}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:i}=this.content.findIndex(e);if(i<e)return{node:this.content.child(t),index:t,offset:i};let r=this.content.child(t-1);return{node:r,index:t-1,offset:i-r.nodeSize}}resolve(e){return us.resolveCached(this,e)}resolveNoCache(e){return us.resolve(this,e)}rangeHasMark(e,t,i){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(i.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()+")"),Bg(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,i=A.empty,r=0,s=i.childCount){let o=this.contentMatchAt(e).matchFragment(i,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(i.child(a).marks))return!1;return!0}canReplaceWith(e,t,i,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(i),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),this.type.checkAttrs(this.attrs);let e=ae.none;for(let t=0;t<this.marks.length;t++){let i=this.marks[t];i.type.checkAttrs(i.attrs),e=i.addToSet(e)}if(!ae.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 i;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=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,i)}let r=A.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,i);return s.type.checkAttrs(s.attrs),s}}Wt.prototype.text=void 0;let Vw=class Vc extends Wt{constructor(e,t,i,r){if(super(e,t,null,r),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Bg(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 Vc(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Vc(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 Bg(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Ti{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let i=new Ww(e,t);if(i.next==null)return Ti.empty;let r=zg(i);i.next&&i.err("Unexpected trailing text");let s=Gw(Jw(r));return Yw(s,i),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,i=e.childCount){let r=this;for(let s=t;r&&s<i;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 i=0;i<e.next.length;i++)if(this.next[t].type==e.next[i].type)return!0;return!1}fillBefore(e,t=!1,i=0){let r=[this];function s(o,l){let a=o.matchFragment(e,i);if(a&&(!t||a.validEnd))return A.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:h,next:u}=o.next[c];if(!(h.isText||h.hasRequiredAttrs())&&r.indexOf(u)==-1){r.push(u);let f=s(u,l.concat(h));if(f)return f}}return null}return s(this,[])}findWrapping(e){for(let i=0;i<this.wrapCache.length;i+=2)if(this.wrapCache[i]==e)return this.wrapCache[i+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),i=[{match:this,type:null,via:null}];for(;i.length;){let r=i.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)&&(i.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(i){e.push(i);for(let r=0;r<i.next.length;r++)e.indexOf(i.next[r].next)==-1&&t(i.next[r].next)}return t(this),e.map((i,r)=>{let s=r+(i.validEnd?"*":" ")+" ";for(let o=0;o<i.next.length;o++)s+=(o?", ":"")+i.next[o].type.name+"->"+e.indexOf(i.next[o].next);return s}).join(`
3
3
  `)}}Ti.empty=new Ti(!0);class Ww{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 zg(n){let e=[];do e.push(jw(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function jw(n){let e=[];do e.push(_w(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function _w(n){let e=Kw(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Uw(n,e);else break;return e}function Kf(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Uw(n,e){let t=Kf(n),i=t;return n.eat(",")&&(n.next!="}"?i=Kf(n):i=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:i,expr:e}}function qw(n,e){let t=n.nodeTypes,i=t[e];if(i)return[i];let r=[];for(let s in t){let o=t[s];o.isInGroup(e)&&r.push(o)}return r.length==0&&n.err("No node type or group '"+e+"' found"),r}function Kw(n){if(n.eat("(")){let e=zg(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=qw(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Jw(n){let e=[[]];return r(s(n,0),t()),e;function t(){return e.push([])-1}function i(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function r(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;r(c,l=t())}else if(o.type=="star"){let a=t();return i(l,a),r(s(o.expr,a),a),[i(a)]}else if(o.type=="plus"){let a=t();return r(s(o.expr,l),a),r(s(o.expr,a),a),[i(a)]}else{if(o.type=="opt")return[i(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let h=t();r(s(o.expr,a),h),a=h}if(o.max==-1)r(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let h=t();i(a,h),r(s(o.expr,a),h),a=h}return[i(a)]}else{if(o.type=="name")return[i(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Hg(n,e){return e-n}function Jf(n,e){let t=[];return i(e),t.sort(Hg);function i(r){let s=n[r];if(s.length==1&&!s[0].term)return i(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&&i(a)}}}function Gw(n){let e=Object.create(null);return t(Jf(n,0));function t(i){let r=[];i.forEach(o=>{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let h=0;h<r.length;h++)r[h][0]==l&&(c=r[h][1]);Jf(n,a).forEach(h=>{c||r.push([l,c=[]]),c.indexOf(h)==-1&&c.push(h)})})});let s=e[i.join(",")]=new Ti(i.indexOf(n.length-1)>-1);for(let o=0;o<r.length;o++){let l=r[o][1].sort(Hg);s.next.push({type:r[o][0],next:e[l.join(",")]||t(l)})}return s}}function Yw(n,e){for(let t=0,i=[n];t<i.length;t++){let r=i[t],s=!r.validEnd,o=[];for(let l=0;l<r.next.length;l++){let{type:a,next:c}=r.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),i.indexOf(c)==-1&&i.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Fg(n){let e=Object.create(null);for(let t in n){let i=n[t];if(!i.hasDefault)return null;e[t]=i.default}return e}function $g(n,e){let t=Object.create(null);for(let i in n){let r=e&&e[i];if(r===void 0){let s=n[i];if(s.hasDefault)r=s.default;else throw new RangeError("No value supplied for attribute "+i)}t[i]=r}return t}function Vg(n,e,t,i){for(let r in e)if(!(r in n))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${r}`);for(let r in n){let s=n[r];s.validate&&s.validate(e[r])}}function Wg(n,e){let t=Object.create(null);if(e)for(let i in e)t[i]=new Qw(n,i,e[i]);return t}let Gf=class jg{constructor(e,t,i){this.name=e,this.schema=t,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=Wg(e,i.attrs),this.defaultAttrs=Fg(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(i.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Ti.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:$g(this.attrs,e)}create(e=null,t,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Wt(this,this.computeAttrs(e),A.from(t),ae.setFrom(i))}createChecked(e=null,t,i){return t=A.from(t),this.checkContent(t),new Wt(this,this.computeAttrs(e),t,ae.setFrom(i))}createAndFill(e=null,t,i){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 Wt(this,e,t.append(s),ae.setFrom(i)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let i=0;i<e.childCount;i++)if(!this.allowsMarks(e.child(i).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){Vg(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let 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 i=0;i<e.length;i++)this.allowsMarkType(e[i].type)?t&&t.push(e[i]):t||(t=e.slice(0,i));return t?t.length?t:ae.none:e}static compile(e,t){let i=Object.create(null);e.forEach((s,o)=>i[s]=new jg(s,t,o));let r=t.spec.topNode||"doc";if(!i[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!i.text)throw new RangeError("Every schema needs a 'text' type");for(let s in i.text.attrs)throw new RangeError("The text node type should not have attributes");return i}};function Xw(n,e,t){let i=t.split("|");return r=>{let s=r===null?"null":typeof r;if(i.indexOf(s)<0)throw new RangeError(`Expected value of type ${i} for attribute ${e} on type ${n}, got ${s}`)}}class Qw{constructor(e,t,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default"),this.default=i.default,this.validate=typeof i.validate=="string"?Xw(e,t,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class ia{constructor(e,t,i,r){this.name=e,this.rank=t,this.schema=i,this.spec=r,this.attrs=Wg(e,r.attrs),this.excluded=null;let s=Fg(this.attrs);this.instance=s?new ae(this,s):null}create(e=null){return!e&&this.instance?this.instance:new ae(this,$g(this.attrs,e))}static compile(e,t){let i=Object.create(null),r=0;return e.forEach((s,o)=>i[s]=new ia(s,r++,t,o)),i}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]}checkAttrs(e){Vg(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class _g{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=Fe.from(e.nodes),t.marks=Fe.from(e.marks||{}),this.nodes=Gf.compile(this.spec.nodes,this),this.marks=ia.compile(this.spec.marks,this);let i=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=i[o]||(i[o]=Ti.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?Yf(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==""?[]:Yf(this,o.split(" "))}this.nodeFromJSON=r=>Wt.fromJSON(this,r),this.markFromJSON=r=>ae.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,i,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Gf){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,i,r)}text(e,t){let i=this.nodes.text;return new Vw(i,i.defaultAttrs,e,ae.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 Yf(n,e){let t=[];for(let i=0;i<e.length;i++){let r=e[i],s=n.marks[r],o=s;if(s)t.push(s);else for(let l in n.marks){let a=n.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[i]+"'")}return t}function Zw(n){return n.tag!=null}function ek(n){return n.style!=null}class Sn{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let i=this.matchedStyles=[];t.forEach(r=>{if(Zw(r))this.tags.push(r);else if(ek(r)){let s=/[^=]*/.exec(r.style)[0];i.indexOf(s)<0&&i.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 i=new Qf(this,t,!1);return i.addAll(e,ae.none,t.from,t.to),i.finish()}parseSlice(e,t={}){let i=new Qf(this,t,!0);return i.addAll(e,ae.none,t.from,t.to),I.maxOpen(i.finish())}matchTag(e,t,i){for(let r=i?this.tags.indexOf(i)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(ik(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,i,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&&!i.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 i(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=>{i(o=Zf(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=>{i(o=Zf(o)),o.node||o.ignore||o.mark||(o.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Sn(e,Sn.schemaRules(e)))}}const Ug={address:!0,article:!0,aside:!0,blockquote:!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},tk={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},qg={ol:!0,ul:!0},fs=1,Wc=2,Gr=4;function Xf(n,e,t){return e!=null?(e?fs:0)|(e==="full"?Wc:0):n&&n.whitespace=="pre"?fs|Wc:t&~Gr}class Ys{constructor(e,t,i,r,s,o){this.type=e,this.attrs=t,this.marks=i,this.solid=r,this.options=o,this.content=[],this.activeMarks=ae.none,this.match=s||(o&Gr?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 i=this.type.contentMatch,r;return(r=i.findWrapping(e.type))?(this.match=i,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&fs)){let i=this.content[this.content.length-1],r;if(i&&i.isText&&(r=/[ \t\r\n\u000c]+$/.exec(i.text))){let s=i;i.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&&!Ug.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}let Qf=class{constructor(e,t,i){this.parser=e,this.options=t,this.isOpen=i,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,o=Xf(null,t.preserveWhitespace,0)|(i?Gr:0);r?s=new Ys(r.type,r.attrs,ae.none,!0,t.topMatch||r.type.contentMatch,o):i?s=new Ys(null,null,ae.none,!0,null,o):s=new Ys(e.schema.topNodeType,null,ae.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 i=e.nodeValue,r=this.top,s=r.options&Wc?"full":this.localPreserveWS||(r.options&fs)>0,{schema:o}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(i)){if(s)if(s==="full")i=i.replace(/\r\n?/g,`
4
4
  `);else if(o.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=i.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]));i=""}else i=i.replace(/\r?\n|\r/g," ");else if(i=i.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(i)&&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))&&(i=i.slice(1))}i&&this.insertNode(o.text(i),t,!/\S/.test(i)),this.findInText(e)}else this.findInside(e)}addElement(e,t,i){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;qg.hasOwnProperty(o)&&this.parser.normalizeLists&&nk(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,i));e:if(a?a.ignore:tk.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 c,h=this.needsBlock;if(Ug.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let u=a&&a.skip?t:this.readStyles(e,t);u&&this.addAll(e,u),c&&this.sync(s),this.needsBlock=h}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,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(`
5
5
  `),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 i=e.style;if(i&&i.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],o=i.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(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,i,r){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),i,e.nodeName=="BR")||this.leafFallback(e,i);else{let a=this.enter(o,t.attrs||null,i,t.preserveWhitespace);a&&(s=!0,i=a)}else{let a=this.parser.schema.marks[t.mark];i=i.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,i,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,i,!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,i),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,i,r){let s=i||0;for(let o=i?e.childNodes[i]: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,i){let r,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!r||r.length>c.length+l)&&(r=c,s=a,!c.length))break;if(a.solid){if(i)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,i){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,i);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=ae.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):ed(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,i,r){let s=this.findPlace(e.create(t),i,!1);return s&&(s=this.enterInner(e,t,i,!0,r)),s}enterInner(e,t,i,r=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=Xf(e,s,o.options);o.options&Gr&&o.content.length==0&&(l|=Gr);let a=ae.none;return i=i.filter(c=>(o.type?o.type.allowsMarkType(c.type):ed(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ys(e,t,a,r,null,l)),this.open++,i}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|=fs)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let i=this.nodes[t].content;for(let r=i.length-1;r>=0;r--)e+=i[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==e&&this.find[i].offset==t&&(this.find[i].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,i){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)&(i?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("/"),i=this.options.context,r=!this.isOpen&&(!i||i.parent.type==this.nodes[0].type),s=-(i?i.depth+1:0)+(r?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let h=a>0||a==0&&r?this.nodes[a].type:i&&a>=s?i.node(a-s).type:null;if(!h||h.name!=c&&!h.isInGroup(c))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 i=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let i=this.parser.schema.nodes[t];if(i.isTextblock&&i.defaultAttrs)return i}}};function nk(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let i=e.nodeType==1?e.nodeName.toLowerCase():null;i&&qg.hasOwnProperty(i)&&t?(t.appendChild(e),e=t):i=="li"?t=e:i&&(t=null)}}function ik(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Zf(n){let e={};for(let t in n)e[t]=n[t];return e}function ed(n,e){let t=e.schema.nodes;for(let i in t){let r=t[i];if(!r.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:h}=l.edge(a);if(c==e||s.indexOf(h)<0&&o(h))return!0}};if(o(r.contentMatch))return!0}}class Bi{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},i){i||(i=Fa(t).createDocumentFragment());let r=i,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 c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)r=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],h=this.serializeMark(c,o.isInline,t);h&&(s.push([c,r]),r.appendChild(h.dom),r=h.contentDOM||h.dom)}}r.appendChild(this.serializeNodeInner(o,t))}),i}serializeNodeInner(e,t){let{dom:i,contentDOM:r}=Io(Fa(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 i}serializeNode(e,t={}){let i=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(i),i=s.dom)}return i}serializeMark(e,t,i={}){let r=this.marks[e.type.name];return r&&Io(Fa(i),r(e,t),null,e.attrs)}static renderSpec(e,t,i=null,r){return Io(e,t,i,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Bi(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=td(e.nodes);return t.text||(t.text=i=>i.text),t}static marksFromSchema(e){return td(e.marks)}}function td(n){let e={};for(let t in n){let i=n[t].spec.toDOM;i&&(e[t]=i)}return e}function Fa(n){return n.document||window.document}const nd=new WeakMap;function rk(n){let e=nd.get(n);return e===void 0&&nd.set(n,e=sk(n)),e}function sk(n){let e=null;function t(i){if(i&&typeof i=="object")if(Array.isArray(i))if(typeof i[0]=="string")e||(e=[]),e.push(i);else for(let r=0;r<i.length;r++)t(i[r]);else for(let r in i)t(i[r])}return t(n),e}function Io(n,e,t,i){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(i&&(s=rk(i))&&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?n.createElementNS(t,r):n.createElement(r),c=e[1],h=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){h=2;for(let u in c)if(c[u]!=null){let f=u.indexOf(" ");f>0?a.setAttributeNS(u.slice(0,f),u.slice(f+1),c[u]):u=="style"&&a.style?a.style.cssText=c[u]:a.setAttribute(u,c[u])}}for(let u=h;u<e.length;u++){let f=e[u];if(f===0){if(u<e.length-1||u>h)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:d,contentDOM:p}=Io(n,f,t,i);if(a.appendChild(d),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Kg=65535,Jg=Math.pow(2,16);function ok(n,e){return n+e*Jg}function id(n){return n&Kg}function lk(n){return(n-(n&Kg))/Jg}const Gg=1,Yg=2,Lo=4,Xg=8;class jc{constructor(e,t,i){this.pos=e,this.delInfo=t,this.recover=i}get deleted(){return(this.delInfo&Xg)>0}get deletedBefore(){return(this.delInfo&(Gg|Lo))>0}get deletedAfter(){return(this.delInfo&(Yg|Lo))>0}get deletedAcross(){return(this.delInfo&Lo)>0}}class yt{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&yt.empty)return yt.empty}recover(e){let t=0,i=id(e);if(!this.inverted)for(let r=0;r<i;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[i*3]+t+lk(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,i){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 c=this.ranges[l+s],h=this.ranges[l+o],u=a+c;if(e<=u){let f=c?e==a?-1:e==u?1:t:t,d=a+r+(f<0?0:h);if(i)return d;let p=e==(t<0?a:u)?null:ok(l/3,e-a),m=e==a?Yg:e==u?Gg:Lo;return(t<0?e!=a:e!=u)&&(m|=Xg),new jc(d,m,p)}r+=h-c}return i?e+r:new jc(e+r,0,null)}touches(e,t){let i=0,r=id(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?i:0);if(a>e)break;let c=this.ranges[l+s],h=a+c;if(e<=h&&l==r*3)return!0;i+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,i=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),c=this.ranges[r+t],h=this.ranges[r+i];e(l,l+c,a,a+h),s+=h-c}}invert(){return new yt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?yt.empty:new yt(e<0?[0,-e,0]:[0,0,e])}}yt.empty=new yt([]);class ds{constructor(e,t,i=0,r=e?e.length:0){this.mirror=t,this.from=i,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new ds(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,i=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?i+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,i=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?i-r-1:void 0)}}invert(){let e=new ds;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let i=this.from;i<this.to;i++)e=this._maps[i].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,i){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 i?e:new jc(e,r,null)}}const $a=Object.create(null);class Ge{getMap(){return yt.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=$a[t.stepType];if(!i)throw new RangeError(`No step type ${t.stepType} defined`);return i.fromJSON(e,t)}static jsonID(e,t){if(e in $a)throw new RangeError("Duplicate use of step JSON ID "+e);return $a[e]=t,t.prototype.jsonID=e,t}}class Se{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new Se(e,null)}static fail(e){return new Se(null,e)}static fromReplace(e,t,i,r){try{return Se.ok(e.replace(t,i,r))}catch(s){if(s instanceof Jo)return Se.fail(s.message);throw s}}}function fu(n,e,t){let i=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy(fu(s.content,e,s))),s.isInline&&(s=e(s,t,r)),i.push(s)}return A.fromArray(i)}class _n extends Ge{constructor(e,t,i){super(),this.from=e,this.to=t,this.mark=i}apply(e){let t=e.slice(this.from,this.to),i=e.resolve(this.from),r=i.node(i.sharedDepth(this.to)),s=new I(fu(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 Se.fromReplace(e,this.from,this.to,s)}invert(){return new Ft(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return t.deleted&&i.deleted||t.pos>=i.pos?null:new _n(t.pos,i.pos,this.mark)}merge(e){return e instanceof _n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _n(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 _n(t.from,t.to,e.markFromJSON(t.mark))}}Ge.jsonID("addMark",_n);class Ft extends Ge{constructor(e,t,i){super(),this.from=e,this.to=t,this.mark=i}apply(e){let t=e.slice(this.from,this.to),i=new I(fu(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return Se.fromReplace(e,this.from,this.to,i)}invert(){return new _n(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return t.deleted&&i.deleted||t.pos>=i.pos?null:new Ft(t.pos,i.pos,this.mark)}merge(e){return e instanceof Ft&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ft(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 Ft(t.from,t.to,e.markFromJSON(t.mark))}}Ge.jsonID("removeMark",Ft);class Un extends Ge{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Se.fail("No node at mark step's position");let i=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Se.fromReplace(e,this.pos,this.pos+1,new I(A.from(i),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let i=this.mark.addToSet(t.marks);if(i.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(i))return new Un(this.pos,t.marks[r]);return new Un(this.pos,this.mark)}}return new Ai(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Un(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 Un(t.pos,e.markFromJSON(t.mark))}}Ge.jsonID("addNodeMark",Un);class Ai extends Ge{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Se.fail("No node at mark step's position");let i=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Se.fromReplace(e,this.pos,this.pos+1,new I(A.from(i),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Un(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ai(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 Ai(t.pos,e.markFromJSON(t.mark))}}Ge.jsonID("removeNodeMark",Ai);class Ne extends Ge{constructor(e,t,i,r=!1){super(),this.from=e,this.to=t,this.slice=i,this.structure=r}apply(e){return this.structure&&_c(e,this.from,this.to)?Se.fail("Structure replace would overwrite content"):Se.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new yt([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ne(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return t.deletedAcross&&i.deletedAcross?null:new Ne(t.pos,Math.max(t.pos,i.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Ne)||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?I.empty:new I(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ne(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?I.empty:new I(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ne(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 Ne(t.from,t.to,I.fromJSON(e,t.slice),!!t.structure)}}Ge.jsonID("replace",Ne);class Be extends Ge{constructor(e,t,i,r,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=i,this.gapTo=r,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(_c(e,this.from,this.gapFrom)||_c(e,this.gapTo,this.to)))return Se.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Se.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,t.content);return i?Se.fromReplace(e,this.from,this.to,i):Se.fail("Content does not fit in gap")}getMap(){return new yt([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),i=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?i.pos:e.map(this.gapTo,1);return t.deletedAcross&&i.deletedAcross||r<t.pos||s>i.pos?null:new Be(t.pos,i.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,I.fromJSON(e,t.slice),t.insert,!!t.structure)}}Ge.jsonID("replaceAround",Be);function _c(n,e,t){let i=n.resolve(e),r=t-e,s=i.depth;for(;r>0&&s>0&&i.indexAfter(s)==i.node(s).childCount;)s--,r--;if(r>0){let o=i.node(s).maybeChild(i.indexAfter(s));for(;r>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,r--}}return!1}function ak(n,e,t,i){let r=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,h)=>{if(!a.isInline)return;let u=a.marks;if(!i.isInSet(u)&&h.type.allowsMarkType(i.type)){let f=Math.max(c,e),d=Math.min(c+a.nodeSize,t),p=i.addToSet(u);for(let m=0;m<u.length;m++)u[m].isInSet(p)||(o&&o.to==f&&o.mark.eq(u[m])?o.to=d:r.push(o=new Ft(f,d,u[m])));l&&l.to==f?l.to=d:s.push(l=new _n(f,d,i))}}),r.forEach(a=>n.step(a)),s.forEach(a=>n.step(a))}function ck(n,e,t,i){let r=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(i instanceof ia){let c=o.marks,h;for(;h=i.isInSet(c);)(a||(a=[])).push(h),c=h.removeFromSet(c)}else i?i.isInSet(o.marks)&&(a=[i]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let h=0;h<a.length;h++){let u=a[h],f;for(let d=0;d<r.length;d++){let p=r[d];p.step==s-1&&u.eq(r[d].style)&&(f=p)}f?(f.to=c,f.step=s):r.push({style:u,from:Math.max(l,e),to:c,step:s})}}}),r.forEach(o=>n.step(new Ft(o.from,o.to,o.style)))}function du(n,e,t,i=t.contentMatch,r=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),h=l+c.nodeSize,u=i.matchType(c.type);if(!u)o.push(new Ne(l,h,I.empty));else{i=u;for(let f=0;f<c.marks.length;f++)t.allowsMarkType(c.marks[f].type)||n.step(new Ft(l,h,c.marks[f]));if(r&&c.isText&&t.whitespace!="pre"){let f,d=/\r?\n|\r/g,p;for(;f=d.exec(c.text);)p||(p=new I(A.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new Ne(l+f.index,l+f.index+f[0].length,p))}}l=h}if(!i.validEnd){let a=i.fillBefore(A.empty,!0);n.replace(l,l,new I(a,0,0))}for(let a=o.length-1;a>=0;a--)n.step(o[a])}function hk(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Sr(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let i=n.depth,r=0,s=0;;--i){let o=n.$from.node(i),l=n.$from.index(i)+r,a=n.$to.indexAfter(i)-s;if(i<n.depth&&o.canReplace(l,a,t))return i;if(i==0||o.type.spec.isolating||!hk(o,l,a))break;l&&(r=1),a<o.childCount&&(s=1)}return null}function uk(n,e,t){let{$from:i,$to:r,depth:s}=e,o=i.before(s+1),l=r.after(s+1),a=o,c=l,h=A.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.index(p)>0?(m=!0,h=A.from(i.node(p).copy(h)),u++):a--;let f=A.empty,d=0;for(let p=s,m=!1;p>t;p--)m||r.after(p+1)<r.end(p)?(m=!0,f=A.from(r.node(p).copy(f)),d++):c++;n.step(new Be(a,c,o,l,new I(h.append(f),u,d),h.size-u,!0))}function pu(n,e,t=null,i=n){let r=fk(n,e),s=r&&dk(i,e);return s?r.map(rd).concat({type:e,attrs:t}).concat(s.map(rd)):null}function rd(n){return{type:n,attrs:null}}function fk(n,e){let{parent:t,startIndex:i,endIndex:r}=n,s=t.contentMatchAt(i).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(i,r,o)?s:null}function dk(n,e){let{parent:t,startIndex:i,endIndex:r}=n,s=t.child(i),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let c=i;a&&c<r;c++)a=a.matchType(t.child(c).type);return!a||!a.validEnd?null:o}function pk(n,e,t){let i=A.empty;for(let o=t.length-1;o>=0;o--){if(i.size){let l=t[o].type.contentMatch.matchFragment(i);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}i=A.from(t[o].type.create(t[o].attrs,i))}let r=e.start,s=e.end;n.step(new Be(r,s,r,s,new I(i,0,0),t.length,!0))}function mk(n,e,t,i,r){if(!i.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof r=="function"?r(o):r;if(o.isTextblock&&!o.hasMarkup(i,a)&&gk(n.doc,n.mapping.slice(s).map(l),i)){let c=null;if(i.schema.linebreakReplacement){let d=i.whitespace=="pre",p=!!i.contentMatch.matchType(i.schema.linebreakReplacement);d&&!p?c=!1:!d&&p&&(c=!0)}c===!1&&Zg(n,o,l,s),du(n,n.mapping.slice(s).map(l,1),i,void 0,c===null);let h=n.mapping.slice(s),u=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new Be(u,f,u+1,f-1,new I(A.from(i.create(a,null,o.marks)),0,0),1,!0)),c===!0&&Qg(n,o,l,s),!1}})}function Qg(n,e,t,i){e.forEach((r,s)=>{if(r.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(r.text);){let a=n.mapping.slice(i).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Zg(n,e,t,i){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let o=n.mapping.slice(i).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
@@ -158,4 +158,4 @@ ${d.slice(c+2)}`,u+=1;else break}e.push({indent:c,number:parseInt(l,10),content:
158
158
  `,r=n.state.doc.line(r.number+(t?1:-1)),s=n.bidiSpans(r),c=n.visualLineSide(r,!t)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function yD(n,e,t){let i=n.state.charCategorizer(e),r=i(t);return s=>{let o=i(s);return r==ge.Space&&(r=o),r==o}}function bD(n,e,t,i){let r=e.head,s=t?1:-1;if(r==(t?n.state.doc.length:0))return T.cursor(r,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),c=n.coordsAtPos(r,(e.empty?e.assoc:0)||(t?1:-1)),h=n.documentTop;if(c)o==null&&(o=c.left-a.left),l=s<0?c.top:c.bottom;else{let p=n.viewState.lineBlockAt(r);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(r-p.from))),l=(s<0?p.top:p.bottom)+h}let u=a.left+o,f=i??n.viewState.heightOracle.textHeight>>1,d=qh(n,{x:u,y:l+f*s},!1,s);return T.cursor(d.pos,d.assoc,void 0,o)}function hs(n,e,t){for(;;){let i=0;for(let r of n)r.between(e-1,e+1,(s,o,l)=>{if(e>s&&e<o){let a=i||t||(e-s<o-e?-1:1);e=a<0?s:o,i=a}});if(!i)return e}}function vx(n,e){let t=null;for(let i=0;i<e.ranges.length;i++){let r=e.ranges[i],s=null;if(r.empty){let o=hs(n,r.from,0);o!=r.from&&(s=T.cursor(o,-1))}else{let o=hs(n,r.from,-1),l=hs(n,r.to,1);(o!=r.from||l!=r.to)&&(s=T.range(r.from==r.anchor?o:l,r.from==r.head?o:l))}s&&(t||(t=e.ranges.slice()),t[i]=s)}return t?T.create(t,e.mainIndex):e}function wc(n,e,t){let i=hs(n.state.facet(js).map(r=>r(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:T.cursor(i,i<t.from?1:-1)}class sn{constructor(e,t){this.pos=e,this.assoc=t}}function qh(n,e,t,i){let r=n.contentDOM.getBoundingClientRect(),s=r.top+n.viewState.paddingTop,{x:o,y:l}=e,a=l-s,c;for(;;){if(a<0)return new sn(0,1);if(a>n.viewState.docHeight)return new sn(n.state.doc.length,-1);if(c=n.elementAtHeight(a),i==null)break;if(c.type==lt.Text){if(i<0?c.to<n.viewport.from:c.from>n.viewport.to)break;let f=n.docView.coordsAt(i<0?c.from:c.to,i>0?-1:1);if(f&&(i<0?f.top<=a+s:f.bottom>=a+s))break}let u=n.viewState.heightOracle.textHeight/2;a=i>0?c.bottom+u:c.top-u}if(n.viewport.from>=c.to||n.viewport.to<=c.from){if(t)return null;if(c.type==lt.Text){let u=pD(n,r,c,o,l);return new sn(u,u==c.from?1:-1)}}if(c.type!=lt.Text)return a<(c.top+c.bottom)/2?new sn(c.from,1):new sn(c.to,-1);let h=n.docView.lineAt(c.from,2);return(!h||h.length!=c.length)&&(h=n.docView.lineAt(c.from,-2)),new xD(n,o,l,n.textDirectionAt(c.from)).scanTile(h,c.from)}class xD{constructor(e,t,i,r){this.view=e,this.x=t,this.y=i,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:i,spans:r}=this.bidiSpansAt(e);return r[on.find(r,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:r}=this.bidiSpansAt(e);return r[on.find(r,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:r}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+r.from<t)}scan(e,t){let i=0,r=e.length-1,s=new Set,o=this.bidiIn(e[0],e[r]),l,a,c=-1,h=1e9,u;e:for(;i<r;){let d=r-i,p=i+r>>1;t:if(s.has(p)){let g=i+Math.floor(Math.random()*d);for(let y=0;y<d;y++){if(!s.has(g)){p=g;break t}g++,g==r&&(g=i)}break e}s.add(p);let m=t(p);if(m)for(let g=0;g<m.length;g++){let y=m[g],b=0;if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),b=1;else if(y.top>this.y)(!a||a.top>y.top)&&(a=y),b=-1;else{let x=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,k=Math.abs(x);k<h&&(c=p,h=k,u=y),x&&(b=x<0==(this.baseDir==ye.LTR)?-1:1)}b==-1&&(!o||this.baseDirAt(e[p],1))?r=p:b==1&&(!o||this.baseDirAt(e[p+1],-1))&&(i=p+1)}}if(!u){let d=l&&(!a||this.y-l.bottom<a.top-this.y)?l:a;return this.y=(d.top+d.bottom)/2,this.scan(e,t)}let f=(o?this.dirAt(e[c],1):this.baseDir)==ye.LTR;return{i:c,after:this.x>(u.left+u.right)/2==f}}scanText(e,t){let i=[];for(let s=0;s<e.length;s=Pe(e.text,s))i.push(t+s);i.push(t+e.length);let r=this.scan(i,s=>{let o=i[s]-t,l=i[s+1]-t;return Es(e.dom,o,l).getClientRects()});return r.after?new sn(i[r.i+1],-1):new sn(i[r.i],1)}scanTile(e,t){if(!e.length)return new sn(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 i=[t];for(let l=0,a=t;l<e.children.length;l++)i.push(a+=e.children[l].length);let r=this.scan(i,l=>{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:Es(a.dom,0,a.length)).getClientRects()}),s=e.children[r.i],o=i[r.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):r.after?new sn(i[r.i+1],-1):new sn(o,1)}}const qr="￿";class wD{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(ee.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=qr}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let r=e;;){this.findPointBefore(i,r);let s=this.text.length;this.readNode(r);let o=Te.get(r),l=r.nextSibling;if(l==t){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=Te.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:Bl(r))||Bl(l)&&(r.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!vD(l,t)&&this.lineBreak(),r=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,l;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=r.exec(t))&&(s=l.index,o=l[0].length),this.append(t.slice(i,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);i=s+o}}readNode(e){let t=Te.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let r=i.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(kD(e,i.node,i.offset)?t:0))}}function kD(n,e,t){for(;;){if(!e||t<Rn(e))return!1;if(e==n)return!0;t=ni(e)+1,e=e.parentNode}}function vD(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let i=Te.get(n);if(!i?.isWidget())return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let r=i.overrideDOMText;if(r?.length)return!1}return!0}class sm{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class SD{constructor(e,t,i,r){this.typeOver=r,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Sx(e.docView.tile,t,i,0))){let l=s||o?[]:MD(e),a=new wD(l,e);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=TD(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!$h(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!$h(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=e.viewport;if((P.ios||P.chrome)&&e.state.selection.main.empty&&a!=c&&(h.from>0||h.to<e.state.doc.length)){let u=Math.min(a,c),f=Math.max(a,c),d=h.from-u,p=h.to-f;(d==0||d==1||u==0)&&(p==0||p==-1||f==e.state.doc.length)&&(a=0,c=e.state.doc.length)}e.inputState.composing>-1&&e.state.selection.ranges.length>1?this.newSel=e.state.selection.replaceRange(T.range(c,a)):this.newSel=T.single(c,a)}}}function Sx(n,e,t,i){if(n.isComposite()){let r=-1,s=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<n.children.length;a++){let u=n.children[a],f=c+u.length;if(c<e&&f>t)return Sx(u,e,t,c);if(f>=e&&r==-1&&(r=a,s=c),c>t&&u.dom.parentNode==n.dom){o=a,l=h;break}h=f,c=f+u.breakAfter}return{from:s,to:l<0?i+n.length:l,startDOM:(r?n.children[r-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function Cx(n,e){let t,{newSel:i}=e,r=n.state.selection.main,s=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=r.from,c=null;(s===8||P.android&&e.text.length<l-o)&&(a=r.to,c="end");let h=Mx(n.state.doc.sliceString(o,l,qr),e.text,a-o,c);h&&(P.chrome&&s==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==qr+qr&&h.toB--,t={from:o+h.from,to:o+h.toA,insert:ne.of(e.text.slice(h.from,h.toB).split(qr))})}else i&&(!n.hasFocus&&n.state.facet(wn)||Vl(i,r))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!r.empty&&i&&i.main.empty?t={from:r.from,to:r.to,insert:n.state.doc.slice(r.from,r.to)}:(P.mac||P.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=T.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:ne.of([t.insert.toString().replace("."," ")])}):t&&t.from>=r.from&&t.to<=r.to&&(t.from!=r.from||t.to!=r.to)&&r.to-r.from-(t.to-t.from)<=4?t={from:r.from,to:r.to,insert:n.state.doc.slice(r.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,r.to))}:n.state.doc.lineAt(r.from).to<r.to&&n.docView.lineHasWidget(r.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:n.state.toText(n.inputState.insertingText)}:P.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
159
159
  `&&n.lineWrapping&&(i&&(i=T.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:ne.of([" "])}),t)return yf(n,t,i,s);if(i&&!Vl(i,r)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=vx(n.state.facet(js).map(a=>a(n)),i))),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function yf(n,e,t,i=-1){if(P.ios&&n.inputState.flushIOSKey(e))return!0;let r=n.state.selection.main;if(P.android&&(e.to==r.to&&(e.from==r.from||e.from==r.from-1&&n.state.sliceDoc(e.from,r.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&ir(n.contentDOM,"Enter",13)||(e.from==r.from-1&&e.to==r.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>r.head)&&ir(n.contentDOM,"Backspace",8)||e.from==r.from&&e.to==r.to+1&&e.insert.length==0&&ir(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=CD(n,e,t));return n.state.facet(ux).some(a=>a(n,e.from,e.to,s,l))||n.dispatch(l()),!0}function CD(n,e,t){let i,r=n.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,c=a<0?s.from:s.to,h=hs(r.facet(js).map(u=>u(n)),c,a);e.from==h&&(o=h)}if(o>-1)i={changes:e,selection:T.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)&&n.inputState.composing<0){let a=s.from<e.from?r.sliceDoc(s.from,e.from):"",c=s.to>e.to?r.sliceDoc(e.to,s.to):"";i=r.replaceSelection(n.state.toText(a+e.insert.sliceString(0,void 0,n.state.lineBreak)+c))}else{let a=r.changes(e),c=t&&t.main.to<=a.newLength?t.main:void 0;if(r.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let h=n.state.sliceDoc(e.from,e.to),u,f=t&&kx(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);u={from:f.from,to:f.to-p}}else u=n.state.doc.lineAt(s.head);let d=s.to-e.to;i=r.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:a,range:c||p.map(a)};let m=p.to-d,g=m-h.length;if(n.state.sliceDoc(g,m)!=h||m>=u.from&&g<=u.to)return{range:p};let y=r.changes({from:g,to:m,insert:e.insert}),b=p.to-s.to;return{changes:y,range:c?T.range(Math.max(0,c.anchor+b),Math.max(0,c.head+b)):p.map(y)}})}else i={changes:a,selection:c&&r.selection.replaceRange(c)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),r.update(i,{userEvent:l,scrollIntoView:!0})}function Mx(n,e,t,i){let r=Math.min(n.length,e.length),s=0;for(;s<r&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==r&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,s-Math.min(o,l));t-=o+a-s}if(o<s&&n.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 MD(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:r,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new sm(t,i)),(r!=t||s!=i)&&e.push(new sm(r,s))),e}function TD(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?T.single(t+e,i+e):null}function Vl(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}class AD{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 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,P.safari&&e.contentDOM.addEventListener("input",()=>null),P.gecko&&WD(e.contentDOM.ownerDocument)}handleEvent(e){!PD(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 i=this.handlers[e];if(i){for(let r of i.observers)r(this.view,t);for(let r of i.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=ED(e),i=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,l=i[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 i)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&&Ax.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),P.android&&P.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return P.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=Tx.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||OD.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,ir(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:P.safari&&!P.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 om(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(r){xt(t.state,r)}}}function ED(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let r=i.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(om(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(om(i.value,a))}}for(let i in jt)t(i).handlers.push(jt[i]);for(let i in It)t(i).observers.push(It[i]);return e}const Tx=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],OD="dthko",Ax=[16,17,18,20,91,92,224,225],go=6;function yo(n){return Math.max(0,n)*.7+8}function RD(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class DD{constructor(e,t,i,r){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=DR(e.contentDOM),this.atoms=e.state.facet(js).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(ee.allowMultipleSelections)&&ND(e,t),this.dragging=LD(e,t)&&Rx(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&&RD(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=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=gf(this.view);e.clientX-a.left<=r+go?t=-yo(r-e.clientX):e.clientX+a.right>=o-go&&(t=yo(e.clientX-o)),e.clientY-a.top<=s+go?i=-yo(s-e.clientY):e.clientY+a.bottom>=l-go&&(i=yo(e.clientY-l)),this.setScrollSpeed(t,i)}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,i=vx(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,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 ND(n,e){let t=n.state.facet(lx);return t.length?t[0](e):P.mac?e.metaKey:e.ctrlKey}function ID(n,e){let t=n.state.facet(ax);return t.length?t[0](e):P.mac?!e.altKey:!e.ctrlKey}function LD(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=As(n.root);if(!i||i.rangeCount==0)return!0;let r=i.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 PD(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=Te.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const jt=Object.create(null),It=Object.create(null),Ex=P.ie&&P.ie_version<15||P.ios&&P.webkit_version<604;function BD(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),Ox(n,t.value)},50)}function Ta(n,e,t){for(let i of n.facet(e))t=i(t,n);return t}function Ox(n,e){e=Ta(n.state,ff,e);let{state:t}=n,i,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(Kh!=null&&t.selection.ranges.every(a=>a.empty)&&Kh==s.toString()){let a=-1;i=t.changeByRange(c=>{let h=t.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let u=t.toText((o?s.line(r++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:u},range:T.cursor(c.from+u.length)}})}else o?i=t.changeByRange(a=>{let c=s.line(r++);return{changes:{from:a.from,to:a.to,insert:c.text},range:T.cursor(a.from+c.length)}}):i=t.replaceSelection(s);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}It.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};jt.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);It.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};It.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};jt.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(cx))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=HD(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new DD(n,e,t,i)),i&&n.observer.ignore(()=>{Qb(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let r=n.inputState.mouseSelection;if(r)return r.start(e),r.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function lm(n,e,t,i){if(i==1)return T.cursor(e,t);if(i==2)return dD(n.state,e,t);{let r=n.docView.lineAt(e,t),s=n.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,l=r?r.posAtEnd:s.to;return l<n.state.doc.length&&l==s.to&&l++,T.range(o,l)}}const zD=P.ie&&P.ie_version<=11;let am=null,cm=0,hm=0;function Rx(n){if(!zD)return n.detail;let e=am,t=hm;return am=n,hm=Date.now(),cm=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(cm+1)%3:1}function HD(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Rx(e),r=n.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=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),c,h=lm(n,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let u=lm(n,t.pos,t.assoc,i),f=Math.min(u.from,h.from),d=Math.max(u.to,h.to);h=f<h.from?T.range(f,d):T.range(d,f)}return o?r.replaceRange(r.main.extend(h.from,h.to)):l&&i==1&&r.ranges.length>1&&(c=FD(r,a.pos))?c:l?r.addRange(h):T.create([h])}}}function FD(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:r}=n.ranges[t];if(i<=e&&r>=e)return T.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}jt.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let r=n.docView.tile.nearest(e.target);if(r&&r.isWidget()){let s=r.posAtStart,o=s+r.length;(s>=t.to||o<=t.from)&&(t=T.range(s,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Ta(n.state,df,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};jt.dragend=n=>(n.inputState.draggedContent=null,!1);function um(n,e,t,i){if(t=Ta(n.state,ff,t),!t)return;let r=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,o=i&&s&&ID(n,e)?{from:s.from,to:s.to}:null,l={from:r,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(r,-1),head:a.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}jt.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),r=0,s=()=>{++r==t.length&&um(n,e,i.filter(o=>o!=null).join(n.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)||(i[o]=l.result),s()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return um(n,e,i,!0),!0}return!1};jt.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=Ex?null:e.clipboardData;return t?(Ox(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(BD(n),!1)};function $D(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function VD(n){let e=[],t=[],i=!1;for(let r of n.selection.ranges)r.empty||(e.push(n.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of n.selection.ranges){let o=n.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),r=o.number}i=!0}return{text:Ta(n,df,e.join(n.lineBreak)),ranges:t,linewise:i}}let Kh=null;jt.copy=jt.cut=(n,e)=>{if(!as(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:r}=VD(n.state);if(!t&&!r)return!1;Kh=r?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let s=Ex?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):($D(n,t),!1)};const Dx=Nn.define();function Nx(n,e){let t=[];for(let i of n.facet(fx)){let r=i(n,e);r&&t.push(r)}return t.length?n.update({effects:t,annotations:Dx.of(!0)}):null}function Ix(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=Nx(n.state,e);t?n.dispatch(t):n.update([])}},10)}It.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Ix(n)};It.blur=n=>{n.observer.clearSelectionRange(),Ix(n)};It.compositionstart=It.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};It.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,P.chrome&&P.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};It.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};jt.beforeinput=(n,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.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=n.posAtDOM(l.startContainer,l.startOffset),c=n.posAtDOM(l.endContainer,l.endOffset);return yf(n,{from:a,to:c,insert:n.state.toText(s)},null),!0}}let r;if(P.chrome&&P.android&&(r=Tx.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(r.key,r.keyCode),r.key=="Backspace"||r.key=="Delete")){let s=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return P.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),P.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>It.compositionend(n,e),20),!1};const fm=new Set;function WD(n){fm.has(n)||(fm.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const dm=["pre-wrap","normal","pre-line","break-spaces"];let xr=!1;function pm(){xr=!1}class jD{constructor(e){this.lineWrapping=e,this.doc=ne.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}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 dm.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let r=e[i];r<0?i++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,i,r,s,o){let l=dm.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=r,this.lineLength=s,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}}class _D{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Ht{constructor(e,t,i,r,s){this.from=e,this.length=t,this.top=i,this.height=r,this._content=s}get type(){return typeof this._content=="number"?lt.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 Ii?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 Ht(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var he=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(he||(he={}));const jo=.001;class Qe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}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)>jo&&(xr=!0),this.height=e)}replace(e,t,i){return Qe.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,r){let s=this,o=i.doc;for(let l=r.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:u}=r[l],f=s.lineAt(a,he.ByPosNoHeight,i.setDoc(t),0,0),d=f.to>=c?f:s.lineAt(c,he.ByPosNoHeight,i,0,0);for(u+=d.to-c,c=d.to;l>0&&f.from<=r[l-1].toA;)a=r[l-1].fromA,h=r[l-1].fromB,l--,a<f.from&&(f=s.lineAt(a,he.ByPosNoHeight,i,0,0));h+=f.from-a,a=f.from;let p=bf.build(i.setDoc(o),e,h,u);s=Wl(s,s.replace(a,c,p))}return s.updateHeight(i,0)}static empty(){return new mt(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,r=0,s=0;for(;;)if(t==i)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),i+=1+l.break,r-=l.size}else if(s>r*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,s-=l.size}else break;else if(r<s){let l=e[t++];l&&(r+=l.size)}else{let l=e[--i];l&&(s+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new qD(Qe.of(e.slice(0,t)),o,Qe.of(e.slice(i)))}}function Wl(n,e){return n==e?n:(n.constructor!=e.constructor&&(xr=!0),e)}Qe.prototype.size=1;const UD=q.replace({});class Lx extends Qe{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new Ht(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,r){return this.spaceAbove&&e<i+this.spaceAbove?new Ht(r,0,i,this.spaceAbove,UD):this.mainBlock(i,r)}lineAt(e,t,i,r,s){let o=this.mainBlock(r,s);return this.spaceAbove?this.blockAt(0,i,r,s).join(o):o}forEachLine(e,t,i,r,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,he.ByPos,i,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,i=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}}class mt extends Lx{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new Ht(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let r=i[0];return i.length==1&&(r instanceof mt||r instanceof $e&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof $e?r=new mt(r.length,this.height,this.spaceAbove):r.height=this.height,this.outdated||(r.outdated=!1),r):Qe.of(i)}updateHeight(e,t=0,i=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(i||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 $e extends Qe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-i+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:i,lastLine:r,perLine:o,perChar:l}}blockAt(e,t,i,r){let{firstLine:s,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let c=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),h=t.doc.lineAt(c),u=l+h.length*a,f=Math.max(i,e-u/2);return new Ht(h.from,h.length,f,u,0)}else{let c=Math.max(0,Math.min(o-s,Math.floor((e-i)/l))),{from:h,length:u}=t.doc.line(s+c);return new Ht(h,u,i+l*c,l,0)}}lineAt(e,t,i,r,s){if(t==he.ByHeight)return this.blockAt(e,i,r,s);if(t==he.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Ht(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,s),c=i.doc.lineAt(e),h=l+c.length*a,u=c.number-o,f=r+l*u+a*(c.from-s-u);return new Ht(c.from,c.length,Math.max(r,Math.min(f,r+this.height-h)),h,0)}forEachLine(e,t,i,r,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,s);for(let h=e,u=r;h<=t;){let f=i.doc.lineAt(h);if(h==e){let p=f.number-l;u+=a*p+c*(e-s-p)}let d=a+c*f.length;o(new Ht(f.from,f.length,u,d,0)),u+=d,h=f.to+1}}replace(e,t,i){let r=this.length-t;if(r>0){let s=i[i.length-1];s instanceof $e?i[i.length-1]=new $e(s.length+r):i.push(null,new $e(r-1))}if(e>0){let s=i[0];s instanceof $e?i[0]=new $e(e+s.length):i.unshift(new $e(e-1),null)}return Qe.of(i)}decomposeLeft(e,t){t.push(new $e(e-1),null)}decomposeRight(e,t){t.push(null,new $e(this.length-e-1))}updateHeight(e,t=0,i=!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 $e(r.from-t-1).updateHeight(e,t));l<=s&&r.more;){let h=e.doc.lineAt(l).length;o.length&&o.push(null);let u=r.heights[r.index++],f=0;u<0&&(f=-u,u=r.heights[r.index++]),a==-1?a=u:Math.abs(u-a)>=jo&&(a=-2);let d=new mt(h,u,f);d.outdated=!1,o.push(d),l+=h+1}l<=s&&o.push(null,new $e(s-l).updateHeight(e,l));let c=Qe.of(o);return(a<0||Math.abs(c.height-this.height)>=jo||Math.abs(a-this.heightMetrics(e,t).perLine)>=jo)&&(xr=!0),Wl(this,c)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class qD extends Qe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,r){let s=i+this.left.height;return e<s?this.left.blockAt(e,t,i,r):this.right.blockAt(e,t,s,r+this.left.length+this.break)}lineAt(e,t,i,r,s){let o=r+this.left.height,l=s+this.left.length+this.break,a=t==he.ByHeight?e<o:e<l,c=a?this.left.lineAt(e,t,i,r,s):this.right.lineAt(e,t,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=t==he.ByPosNoHeight?he.ByPosNoHeight:he.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,r,s).join(c)}forEachLine(e,t,i,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,i,r,s,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let c=this.lineAt(a,he.ByPos,i,r,s);e<c.from&&this.left.forEachLine(e,c.from-1,i,r,s,o),c.to>=e&&c.from<=t&&o(c),t>c.to&&this.right.forEachLine(c.to+1,t,i,l,a,o)}}replace(e,t,i){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,i));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of i)s.push(l);if(e>0&&mm(s,o-1),t<this.length){let l=s.length;this.decomposeRight(t,s),mm(s,l)}return Qe.of(s)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,r=i+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<i&&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?Qe.of(this.break?[e,null,t]:[e,t]):(this.left=Wl(this.left,e),this.right=Wl(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,i=!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,i,r):s.updateHeight(e,t,i),r&&r.from<=l+o.length&&r.more?a=o=o.updateHeight(e,l,i,r):o.updateHeight(e,l,i),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 mm(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof $e&&(i=n[e+1])instanceof $e&&n.splice(e-1,3,new $e(t.length+1+i.length))}const KD=5;class bf{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 i=Math.min(t,this.lineEnd),r=this.nodes[this.nodes.length-1];r instanceof mt?r.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new mt(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let r=i.widget?i.widget.estimatedHeight:0,s=i.widget?i.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Lx(o,r,i)):(o||s||r>=KD)&&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 mt(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new $e(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof mt)return e;let t=new mt(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,i){let r=this.ensureLine();r.length+=i,r.collapsed+=i,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof mt)&&!this.isCovered?this.nodes.push(new mt(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let r of this.nodes)r instanceof mt&&r.updateHeight(this.oracle,i),i+=r?r.length:1;return this.nodes}static build(e,t,i,r){let s=new bf(i,e);return X.spans(t,i,r,s,0),s.finish(i)}}function JD(n,e,t){let i=new GD;return X.compare(n,e,t,i,0),i.changes}class GD{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,r){(e<t||i&&i.heightRelevant||r&&r.heightRelevant)&&nr(e,t,this.changes,5)}}function YD(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,r=i.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 c=n.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,u=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&u.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(c==n.parentNode?r.innerHeight:a,f.bottom)}c=u.position=="absolute"||u.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.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 XD(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function QD(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class kc{constructor(e,t,i,r){this.from=e,this.to=t,this.size=i,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let r=e[i],s=t[i];if(r.from!=s.from||r.to!=s.to||r.size!=s.size)return!1}return!0}draw(e,t){return q.replace({widget:new ZD(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class ZD extends $s{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 gm{constructor(e){this.state=e,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.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=ym,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=ye.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(pf).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new jD(t),this.stateDeco=bm(e),this.heightMap=Qe.empty().applyChanges(this.stateDeco,ne.empty,this.heightOracle.setDoc(e.doc),[new At(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=q.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let r=i?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 bo(s,o))}}return this.viewports=e.sort((i,r)=>i.from-r.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?ym:new xf(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 i=this.stateDeco;this.stateDeco=bm(this.state);let r=e.changedRanges,s=At.extendWithRanges(r,JD(i,this.stateDeco,e?e.changes:Ee.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);pm(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||xr)&&(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 c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(c||!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(_R)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),r=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?ye.RTL:ye.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 c=0,h=0;if(l.width&&l.height){let{scaleX:k,scaleY:w}=Xb(t,l);(k>.005&&Math.abs(this.scaleX-k)>.005||w>.005&&Math.abs(this.scaleY-w)>.005)&&(this.scaleX=k,this.scaleY=w,c|=16,o=a=!0)}let u=(parseInt(i.paddingTop)||0)*this.scaleY,f=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=u||this.paddingBottom!=f)&&(this.paddingTop=u,this.paddingBottom=f,c|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=16);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Zb(e.scrollDOM);let p=(this.printing?QD:YD)(t,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget&&!XD(e.dom))return 0;let b=l.width;if((this.contentDOMWidth!=b||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,c|=16),a){let k=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(k)&&(o=!0),o||r.lineWrapping&&Math.abs(b-this.contentDOMWidth)>r.charWidth){let{lineHeight:w,charWidth:C,textHeight:v}=e.docView.measureTextSize();o=w>0&&r.refresh(s,w,C,v,Math.max(5,b/C),k),o&&(e.docView.minWidth=0,c|=16)}m>0&&g>0?h=Math.max(m,g):m<0&&g<0&&(h=Math.min(m,g)),pm();for(let w of this.viewports){let C=w.from==this.viewport.from?k:e.docView.measureVisibleLineHeights(w);this.heightMap=(o?Qe.empty().applyChanges(this.stateDeco,ne.empty,this.heightOracle,[new At(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new _D(w.from,C))}xr&&(c|=2)}let x=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return x&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||x)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new bo(r.lineAt(o-i*1e3,he.ByHeight,s,0,0).from,r.lineAt(l+(1-i)*1e3,he.ByHeight,s,0,0).to);if(t){let{head:c}=t.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),u=r.lineAt(c,he.ByPos,s,0,0),f;t.y=="center"?f=(u.top+u.bottom)/2-h/2:t.y=="start"||t.y=="nearest"&&c<a.from?f=u.top:f=u.bottom-h,a=new bo(r.lineAt(f-1e3/2,he.ByHeight,s,0,0).from,r.lineAt(f+h+1e3/2,he.ByHeight,s,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new bo(this.heightMap.lineAt(i,he.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,he.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,he.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,he.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||r<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||s>=l+Math.max(10,Math.min(i,250)))&&r>o-2*1e3&&s<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let r of e)t.touchesRange(r.from,r.to)||i.push(new kc(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,r=i?1e4:2e3,s=r>>1,o=r<<1;if(this.defaultTextDirection!=ye.LTR&&!i)return[];let l=[],a=(h,u,f,d)=>{if(u-h<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>h&&y<u){a(h,y-10,f,d),a(y+10,u,f,d);return}let g=tN(e,y=>y.from>=f.from&&y.to<=f.to&&Math.abs(y.from-h)<s&&Math.abs(y.to-u)<s&&!m.some(b=>y.from<b&&y.to>b));if(!g){if(u<f.to&&t&&i&&t.visibleRanges.some(x=>x.from<=u&&x.to>=u)){let x=t.moveToLineBoundary(T.cursor(u),!1,!0).head;x>h&&(u=x)}let y=this.gapSize(f,h,u,d),b=i||y<2e6?y:2e6;g=new kc(h,u,y,b)}l.push(g)},c=h=>{if(h.length<o||h.type!=lt.Text)return;let u=eN(h.from,h.to,this.stateDeco);if(u.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(f!=null){let b=wo(u,f),x=((this.visibleBottom-this.visibleTop)/2+m)/h.height;g=b-x,y=b+x}else g=(this.visibleTop-h.top-m)/h.height,y=(this.visibleBottom-h.top+m)/h.height;d=xo(u,g),p=xo(u,y)}else{let m=u.total*this.heightOracle.charWidth,g=r*this.heightOracle.charWidth,y=0;if(m>2e6)for(let C of e)C.from>=h.from&&C.from<h.to&&C.size!=C.displaySize&&C.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=C.size-C.displaySize);let b=this.pixelViewport.left+y,x=this.pixelViewport.right+y,k,w;if(f!=null){let C=wo(u,f),v=((x-b)/2+g)/m;k=C-v,w=C+v}else k=(b-g)/m,w=(x+g)/m;d=xo(u,k),p=xo(u,w)}d>h.from&&a(h.from,d,h,u),p<h.to&&a(p,h.to,h,u)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(e,t,i,r){let s=wo(r,i)-wo(r,t);return this.heightOracle.lineWrapping?e.height*s:r.total*this.heightOracle.charWidth*s}updateLineGaps(e){kc.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=q.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 i=[];X.spans(t,this.viewport.from,this.viewport.to,{span(s,o){i.push({from:s,to:o})},point(){}},20);let r=0;if(i.length!=this.visibleRanges.length)r=12;else for(let s=0;s<i.length&&!(r&8);s++){let o=this.visibleRanges[s],l=i[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=i,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,he.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),he.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);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 bo{constructor(e,t){this.from=e,this.to=t}}function eN(n,e,t){let i=[],r=n,s=0;return X.spans(t,n,e,{span(){},point(o,l){o>r&&(i.push({from:r,to:o}),s+=o-r),r=l}},20),r<e&&(i.push({from:r,to:e}),s+=e-r),{total:s,ranges:i}}function xo({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let r=0;;r++){let{from:s,to:o}=e[r],l=o-s;if(i<=l)return s+i;i-=l}}function wo(n,e){let t=0;for(let{from:i,to:r}of n.ranges){if(e<=r){t+=e-i;break}t+=r-i}return t/n.total}function tN(n,e){for(let t of n)if(e(t))return t}const ym={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function bm(n){let e=n.facet(Sa).filter(i=>typeof i!="function"),t=n.facet(mf).filter(i=>typeof i!="function");return t.length&&e.push(X.join(t)),e}class xf{constructor(e,t,i){let r=0,s=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=t.lineAt(l,he.ByPos,e,0,0).top,h=t.lineAt(a,he.ByPos,e,0,0).bottom;return r+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let l of this.viewports)l.domTop=o+(l.top-s)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),s=l.bottom}toDOM(e){for(let t=0,i=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return r+(e-i)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);i=s.bottom,r=s.domBottom}}fromDOM(e){for(let t=0,i=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return i+(e-r)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);i=s.bottom,r=s.domBottom}}eq(e){return e instanceof xf?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function Kr(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new Ht(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(r=>Kr(r,e)):n._content)}const ko=z.define({combine:n=>n.join(" ")}),Jh=z.define({combine:n=>n.indexOf(!0)>-1}),Gh=ti.newName(),Px=ti.newName(),Bx=ti.newName(),zx={"&light":"."+Px,"&dark":"."+Bx};function Yh(n,e,t){return new ti(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,r=>{if(r=="&")return n;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):n+" "+i}})}const nN=Yh("."+Gh,{"&":{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":{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-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"},"&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:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"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"}},zx),iN={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},vc=P.ie&&P.ie_version<=11;class rN{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new NR,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 i of t)this.queue.push(i);(P.ie&&P.ie_version<=11||P.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&P.android&&e.constructor.EDIT_CONTEXT!==!1&&!(P.chrome&&P.chrome_version<126)&&(this.editContext=new oN(e),e.state.facet(wn)&&(e.contentDOM.editContext=this.editContext.editContext)),vc&&(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(!1),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,i)=>t!=e[i]))){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:i}=this,r=this.selectionRange;if(i.state.facet(wn)?i.root.activeElement!=this.dom:!as(this.dom,r))return;let s=r.anchorNode&&i.docView.tile.nearest(r.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(P.ie&&P.ie_version<=11||P.android&&P.chrome)&&!i.state.selection.main.empty&&r.focusNode&&cs(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=As(e.root);if(!t)return!1;let i=P.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&sN(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let r=as(this.dom,i);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&LR(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),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 i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.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,iN),vc&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),vc&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;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&&ir(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||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.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,i=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:r}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),r=this.selectionChanged&&as(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 SD(this.view,e,t,i);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.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,r=Cx(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!Vl(this.view.state.selection,t.newSel.main))&&this.view.update([]),r}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 i=xm(t,e.previousSibling||e.target.previousSibling,-1),r=xm(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):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(wn)!=e.state.facet(wn)&&(e.view.contentDOM.editContext=e.state.facet(wn)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.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 xm(n,e,t){for(;e;){let i=Te.get(e);if(i&&i.parent==n)return i;let r=e.parentNode;e=r!=n.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function wm(n,e){let t=e.startContainer,i=e.startOffset,r=e.endContainer,s=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return cs(o.node,o.offset,r,s)&&([t,i,r,s]=[r,s,t,i]),{anchorNode:t,anchorOffset:i,focusNode:r,focusOffset:s}}function sN(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return wm(n,r)}let t=null;function i(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?wm(n,t):null}class oN{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=i=>{let r=e.state.selection.main,{anchor:s,head:o}=r,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let c=a-l>i.text.length;l==this.from&&s<this.from?l=s:a==this.to&&s>this.to&&(a=s);let h=Mx(e.state.sliceDoc(l,a),i.text,(c?r.from:r.to)-l,c?"end":null);if(!h){let f=T.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Vl(f,r)||e.dispatch({selection:f,userEvent:"select"});return}let u={from:h.from+l,to:h.toA+l,insert:ne.of(i.text.slice(h.from,h.toB).split(`
160
160
  `))};if((P.mac||P.android)&&u.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(u={from:l,to:a,insert:ne.of([i.text.replace("."," ")])}),this.pendingContextChange=u,!e.state.readOnly){let f=this.to-this.from+(u.to-u.from+u.insert.length);yf(e,u,T.single(this.toEditorPos(i.selectionStart,f),this.toEditorPos(i.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),u.from<u.to&&!u.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let r=[],s=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.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(i.rangeStart,r)},this.handlers.textformatupdate=i=>{let r=[];for(let s of i.getTextFormats()){let o=s.underlineStyle,l=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(s.rangeStart),c=this.toEditorPos(s.rangeEnd);if(a<c){let h=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;r.push(q.mark({attributes:{style:h}}).range(a,c))}}}e.dispatch({effects:mx.of(q.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:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let r=As(i.root);r&&r.rangeCount&&this.editContext.updateSelectionBounds(r.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,r=this.pendingContextChange;return e.changes.iterChanges((s,o,l,a,c)=>{if(i)return;let h=c.length-(o-s);if(r&&o>=r.to)if(r.from==s&&r.to==o&&r.insert.eq(c)){r=this.pendingContextChange=null,t+=h,this.to+=h;return}else r=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=h,this.to+=h;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),c.toString()),this.to+=h}t+=h}),r&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.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,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(i,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 i=this.composing;return i&&i.drifted?i.editorBase+(e-i.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 B{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.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:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(r=>r.forEach(s=>i(s,this)))||(r=>this.update(r)),this.dispatch=this.dispatch.bind(this),this._root=e.root||IR(e.parent)||document,this.viewState=new gm(e.state||ee.create(e)),e.scrollTo&&e.scrollTo.is(mo)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ji).map(r=>new gc(r));for(let r of this.plugins)r.update(this);this.observer=new rN(this),this.inputState=new AD(this),this.inputState.ensureHandlers(this.plugins),this.docView=new im(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 Ce?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,i=!1,r,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,l=0,a=null;e.some(f=>f.annotation(Dx))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Nx(s,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(ee.phrases)!=this.state.facet(ee.phrases))return this.setState(s);r=Hl.create(this,s,e),r.flags|=l;let u=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(u&&(u=u.map(f.changes)),f.scrollIntoView){let{main:d}=f.state.selection;u=new rr(d.empty?d:T.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of f.effects)d.is(mo)&&(u=d.value.clip(this.state))}this.viewState.update(r,u),this.bidiCache=jl.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(Ur)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(ko)!=r.state.facet(ko)&&(this.viewState.mustMeasureContent=!0),(t||i||u||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let f of this.state.facet(_h))try{f(r)}catch(d){xt(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!Cx(this,h)&&c.force&&ir(this.contentDOM,c.key,c.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 i of this.plugins)i.destroy(this);this.viewState=new gm(e),this.plugins=e.facet(Ji).map(i=>new gc(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new im(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(Ji),i=e.state.facet(Ji);if(t!=i){let r=[];for(let s of i){let o=t.indexOf(s);if(o<0)r.push(new gc(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!=i&&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(i){xt(this.state,i,"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,i=this.scrollDOM,r=i.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:o}=this.viewState;Math.abs(r-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Zb(i))s=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(r);s=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return xt(this.state,p),km}}),u=Hl.create(this,this.state,[]),f=!1;u.flags|=a,t?t.flags|=a:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),f=this.docView.update(u),f&&this.docViewUpdate());for(let d=0;d<c.length;d++)if(h[d]!=km)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){xt(this.state,p)}if(f&&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 p=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)-o;if(p>1||p<-1){r=r+p,i.scrollTop=r/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(_h))l(t)}get themeClasses(){return Gh+" "+(this.state.facet(Jh)?Bx:Px)+" "+this.state.facet(ko)}updateAttrs(){let e=vm(this,gx,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(wn)?"true":"false",class:"cm-content",style:`${P.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),vm(this,pf,t);let i=this.observer.ignore(()=>{let r=Xp(this.contentDOM,this.contentAttrs,t),s=Xp(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let r of i.effects)if(r.is(B.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(Ur);let e=this.state.facet(B.cspNonce);ti.mount(this.root,this.styleModules.concat(nN).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(i=>i.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,i){return wc(this,e,rm(this,e,t,i))}moveByGroup(e,t){return wc(this,e,rm(this,e,t,i=>yD(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),r=this.textDirectionAt(e.from),s=i[t?i.length-1:0];return T.cursor(s.side(t,r)+e.from,s.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,i=!0){return gD(this,e,t,i)}moveVertically(e,t,i){return wc(this,e,bD(this,e,t,i))}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 i=qh(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),qh(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let r=this.state.doc.lineAt(e),s=this.bidiSpans(r),o=s[on.find(s,e-r.from,-1,t)];return zl(i,o.dir==ye.LTR==t>0)}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(dx)||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>lN)return sx(e.length);let t=this.textDirectionAt(e.from),i;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||rx(s.isolates,i=em(this,e))))return s.order;i||(i=em(this,e));let r=VR(e.text,t,i);return this.bidiCache.push(new jl(e.from,e.to,t,i,!0,r)),r}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||P.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Qb(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.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return mo.of(new rr(typeof e=="number"?T.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return mo.of(new rr(T.cursor(i.from),"start","start",i.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 at.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return at.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ti.newName(),r=[ko.of(i),Ur.of(Yh(`.${i}`,e))];return t&&t.dark&&r.push(Jh.of(!0)),r}static baseTheme(e){return Fi.lowest(Ur.of(Yh("."+Gh,e,zx)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),r=i&&Te.get(i)||Te.get(e);return((t=r?.root)===null||t===void 0?void 0:t.view)||null}}B.styleModule=Ur;B.inputHandler=ux;B.clipboardInputFilter=ff;B.clipboardOutputFilter=df;B.scrollHandler=px;B.focusChangeEffect=fx;B.perLineTextDirection=dx;B.exceptionSink=hx;B.updateListener=_h;B.editable=wn;B.mouseSelectionStyle=cx;B.dragMovesSelection=ax;B.clickAddsSelectionRange=lx;B.decorations=Sa;B.blockWrappers=yx;B.outerDecorations=mf;B.atomicRanges=js;B.bidiIsolatedRanges=bx;B.scrollMargins=xx;B.darkTheme=Jh;B.cspNonce=z.define({combine:n=>n.length?n[0]:""});B.contentAttributes=pf;B.editorAttributes=gx;B.lineWrapping=B.contentAttributes.of({class:"cm-lineWrapping"});B.announce=Q.define();const lN=4096,km={};class jl{constructor(e,t,i,r,s,o){this.from=e,this.to=t,this.dir=i,this.isolates=r,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let i=[],r=e.length?e[e.length-1].dir:ye.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)&&i.push(new jl(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function vm(n,e,t){for(let i=n.state.facet(e),r=i.length-1;r>=0;r--){let s=i[r],o=typeof s=="function"?s(n):s;o&&cf(o,t)}return t}const aN=P.mac?"mac":P.windows?"win":P.linux?"linux":"key";function cN(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let r,s,o,l;for(let a=0;a<t.length-1;++a){const c=t[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))s=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))e=="mac"?l=!0:s=!0;else throw new Error("Unrecognized modifier name: "+c)}return r&&(i="Alt-"+i),s&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function vo(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const hN=Fi.default(B.domEventHandlers({keydown(n,e){return Fx(Hx(e.state),n,e,"editor")}})),Aa=z.define({enables:hN}),Sm=new WeakMap;function Hx(n){let e=n.facet(Aa),t=Sm.get(e);return t||Sm.set(e,t=dN(e.reduce((i,r)=>i.concat(r),[]))),t}function uN(n,e,t){return Fx(Hx(n.state),e,n,t)}let jn=null;const fN=4e3;function dN(n,e=aN){let t=Object.create(null),i=Object.create(null),r=(o,l)=>{let a=i[o];if(a==null)i[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,c,h)=>{var u,f;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>cN(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:[x=>{let k=jn={view:x,prefix:b,scope:o};return setTimeout(()=>{jn==k&&(jn=null)},fN),!0}]})}let m=p.join(" ");r(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((f=(u=d._any)===null||u===void 0?void 0:u.run)===null||f===void 0?void 0:f.slice())||[]});a&&g.run.push(a),c&&(g.preventDefault=!0),h&&(g.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=t[c]||(t[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:u}=o;for(let f in h)h[f].run.push(d=>u(d,Xh))}let a=o[e]||o.key;if(a)for(let c of l)s(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let Xh=null;function Fx(n,e,t,i){Xh=e;let r=ry(e),s=gt(r,0),o=rn(s)==r.length&&r!=" ",l="",a=!1,c=!1,h=!1;jn&&jn.view==t&&jn.scope==i&&(l=jn.prefix+" ",Ax.indexOf(e.keyCode)<0&&(c=!0,jn=null));let u=new Set,f=g=>{if(g){for(let y of g.run)if(!u.has(y)&&(u.add(y),y(t)))return g.stopPropagation&&(h=!0),!0;g.preventDefault&&(g.stopPropagation&&(h=!0),c=!0)}return!1},d=n[i],p,m;return d&&(f(d[l+vo(r,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(P.windows&&e.ctrlKey&&e.altKey)&&!(P.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=On[e.keyCode])&&p!=r?(f(d[l+vo(p,e,!0)])||e.shiftKey&&(m=bs[e.keyCode])!=r&&m!=p&&f(d[l+vo(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&f(d[l+vo(r,e,!0)])&&(a=!0),!a&&f(d._any)&&(a=!0)),c&&(a=!0),a&&h&&e.stopPropagation(),Xh=null,a}function pN(){return gN}const mN=q.line({class:"cm-activeLine"}),gN=at.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let r=n.lineBlockAt(i.head);r.from>e&&(t.push(mN.range(r.from)),e=r.from)}return q.set(t)}},{decorations:n=>n.decorations}),So="-10000px";class yN{constructor(e,t,i,r){this.facet=t,this.createTooltipView=i,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=i(o,s))}update(e,t){var i;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 c=s[a],h=-1;if(c){for(let u=0;u<this.tooltips.length;u++){let f=this.tooltips[u];f&&f.create==c.create&&(h=u)}if(h<0)o[a]=this.createTooltipView(c,a?o[a-1]:null),l&&(l[a]=!!c.above);else{let u=o[a]=this.tooltipViews[h];l&&(l[a]=t[h]),u.update&&u.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,c)=>t[c]=a),t.length=l.length),this.input=r,this.tooltips=s,this.tooltipViews=o,!0}}function bN(n){let e=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Sc=z.define({combine:n=>{var e,t,i;return{position:P.ios?"absolute":((e=n.find(r=>r.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(r=>r.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(r=>r.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||bN}}}),Cm=new WeakMap,$x=at.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Sc);this.position=e.position,this.parent=e.parent,this.classes=n.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 yN(n,Vx,(t,i)=>this.createTooltip(t,i),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(),n.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 n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Sc);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let r of this.manager.tooltipViews)r.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.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(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.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=So,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);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 n=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(P.safari){let o=s.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else t=!!s.offsetParent&&s.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(n=s.width/this.parent.offsetWidth,e=s.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),r=gf(this.view);return{visible:{left:i.left+r.left,top:i.top+r.top,right:i.right-r.right,bottom:i.bottom-r.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((s,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(Sc).tooltipSpace(this.view),scaleX:n,scaleY:e,makeAbsolute:t}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:r,scaleY:s}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],c=this.manager.tooltipViews[l],{dom:h}=c,u=n.pos[l],f=n.size[l];if(!u||a.clip!==!1&&(u.bottom<=Math.max(t.top,i.top)||u.top>=Math.min(t.bottom,i.bottom)||u.right<Math.max(t.left,i.left)-.1||u.left>Math.min(t.right,i.right)+.1)){h.style.top=So;continue}let d=a.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=(e=Cm.get(c))!==null&&e!==void 0?e:f.bottom-f.top,y=c.offset||wN,b=this.view.textDirection==ye.LTR,x=f.width>i.right-i.left?b?i.left:i.right-f.width:b?Math.max(i.left,Math.min(u.left-(d?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,u.left-m+(d?14:0)-y.x),i.right-m),k=this.above[l];!a.strictSide&&(k?u.top-g-p-y.y<i.top:u.bottom+g+p+y.y>i.bottom)&&k==i.bottom-u.bottom>u.top-i.top&&(k=this.above[l]=!k);let w=(k?u.top-i.top:i.bottom-u.bottom)-p;if(w<g&&c.resize!==!1){if(w<this.view.defaultLineHeight){h.style.top=So;continue}Cm.set(c,g),h.style.height=(g=w)/s+"px"}else h.style.height&&(h.style.height="");let C=k?u.top-g-p-y.y:u.bottom+p+y.y,v=x+m;if(c.overlap!==!0)for(let D of o)D.left<v&&D.right>x&&D.top<C+g&&D.bottom>C&&(C=k?D.top-g-2-p:D.bottom+p+2);if(this.position=="absolute"?(h.style.top=(C-n.parent.top)/s+"px",Mm(h,(x-n.parent.left)/r)):(h.style.top=C/s+"px",Mm(h,x/r)),d){let D=u.left+(b?y.x:-y.x)-(x+14-7);d.style.left=D/r+"px"}c.overlap!==!0&&o.push({left:x,top:C,right:v,bottom:C+g}),h.classList.toggle("cm-tooltip-above",k),h.classList.toggle("cm-tooltip-below",!k),c.positioned&&c.positioned(n.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 n of this.manager.tooltipViews)n.dom.style.top=So}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Mm(n,e){let t=parseInt(n.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(n.style.left=e+"px")}const xN=B.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"}}}),wN={x:0,y:0},Vx=z.define({enables:[$x,xN]});function Wx(n,e){let t=n.plugin($x);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Tm=z.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function jx(n,e){let t=n.plugin(_x),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const _x=at.fromClass(class{constructor(n){this.input=n.state.facet(_l),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(Tm);this.top=new Co(n,!0,e.topContainer),this.bottom=new Co(n,!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(n){let e=n.state.facet(Tm);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Co(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Co(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(_l);if(t!=this.input){let i=t.filter(a=>a),r=[],s=[],o=[],l=[];for(let a of i){let c=this.specs.indexOf(a),h;c<0?(h=a(n.view),l.push(h)):(h=this.panels[c],h.update&&h.update(n)),r.push(h),(h.top?s:o).push(h)}this.specs=i,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 i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>B.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Co{constructor(e,t,i){this.view=e,this.top=t,this.container=i,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",this.dom.style[this.top?"top":"bottom"]="0";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=Am(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Am(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 Am(n){let e=n.nextSibling;return n.remove(),e}const _l=z.define({enables:_x});function kN(n,e){let t,i=new Promise(o=>t=o),r=o=>vN(o,e,t);n.state.field(Cc,!1)?n.dispatch({effects:Ux.of(r)}):n.dispatch({effects:Q.appendConfig.of(Cc.init(()=>[r]))});let s=qx.of(r);return{close:s,result:i.then(o=>((n.win.queueMicrotask||(a=>n.win.setTimeout(a,10)))(()=>{n.state.field(Cc).indexOf(r)>-1&&n.dispatch({effects:s})}),o))}}const Cc=ut.define({create(){return[]},update(n,e){for(let t of e.effects)t.is(Ux)?n=[t.value].concat(n):t.is(qx)&&(n=n.filter(i=>i!=t.value));return n},provide:n=>_l.computeN([n],e=>e.field(n))}),Ux=Q.define(),qx=Q.define();function vN(n,e,t){let i=e.content?e.content(n,()=>o(null)):null;if(!i){if(i=De("form"),e.input){let l=De("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(De("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(De("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let r=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<r.length;l++){let a=r[l];a.addEventListener("keydown",c=>{c.keyCode==27?(c.preventDefault(),o(null)):c.keyCode==13&&(c.preventDefault(),o(a))}),a.addEventListener("submit",c=>{c.preventDefault(),o(a)})}let s=De("div",i,De("button",{onclick:()=>o(null),"aria-label":n.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(s.className=e.class),s.classList.add("cm-dialog");function o(l){s.contains(s.ownerDocument.activeElement)&&n.focus(),t(l)}return{dom:s,top:e.top,mount:()=>{if(e.focus){let l;typeof e.focus=="string"?l=i.querySelector(e.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class ii extends ei{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}ii.prototype.elementClass="";ii.prototype.toDOM=void 0;ii.prototype.mapMode=qe.TrackBefore;ii.prototype.startSide=ii.prototype.endSide=-1;ii.prototype.point=!0;const _o=z.define(),SN=z.define(),Uo=z.define(),Em=z.define({combine:n=>n.some(e=>e)});function CN(n){return[MN]}const MN=at.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.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=n.state.facet(Uo).map(e=>new Rm(n,e)),this.fixed=!n.state.facet(Em);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),n.scrollDOM.insertBefore(this.dom,n.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(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(n.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(Em)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=X.iter(this.view.state.facet(_o),this.view.viewport.from),i=[],r=this.gutters.map(s=>new TN(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(s.type)){let o=!0;for(let l of s.type)if(l.type==lt.Text&&o){Qh(t,i,l.from);for(let a of r)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of r)a.widget(this.view,l)}else if(s.type==lt.Text){Qh(t,i,s.from);for(let o of r)o.line(this.view,s,i)}else if(s.widget)for(let o of r)o.widget(this.view,s);for(let s of r)s.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(Uo),t=n.state.facet(Uo),i=n.docChanged||n.heightChanged||n.viewportChanged||!X.eq(n.startState.facet(_o),n.state.facet(_o),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let r of this.gutters)r.update(n)&&(i=!0);else{i=!0;let r=[];for(let s of t){let o=e.indexOf(s);o<0?r.push(new Rm(this.view,s)):(this.gutters[o].update(n),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 i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>B.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,r=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==ye.LTR?{left:i,right:r}:{right:i,left:r}})});function Om(n){return Array.isArray(n)?n:[n]}function Qh(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class TN{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=X.iter(e.markers,t.from)}addElement(e,t,i){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 Kx(e,o,s,i);r.elements.push(l),r.dom.appendChild(l.dom)}else r.elements[this.i].update(e,o,s,i);this.height=t.bottom,this.i++}line(e,t,i){let r=[];Qh(this.cursor,r,t.from),i.length&&(r=r.concat(i));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 i=this.gutter.config.widgetMarker(e,t.widget,t),r=i?[i]:null;for(let s of e.state.facet(SN)){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 Rm{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 i in t.domEventHandlers)this.dom.addEventListener(i,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[i](e,l,r)&&r.preventDefault()});this.markers=Om(t.markers(e)),t.initialSpacer&&(this.spacer=new Kx(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=Om(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 i=e.view.viewport;return!X.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Kx{constructor(e,t,i,r){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,r)}update(e,t,i,r){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),AN(this.markers,r)||this.setMarkers(e,r)}setMarkers(e,t){let i="cm-gutterElement",r=this.dom.firstChild;for(let s=0,o=0;;){let l=o,a=s<t.length?t[s++]:null,c=!1;if(a){let h=a.elementClass;h&&(i+=" "+h);for(let u=o;u<this.markers.length;u++)if(this.markers[u].compare(a)){l=u,c=!0;break}}else l=this.markers.length;for(;o<l;){let h=this.markers[o++];if(h.toDOM){h.destroy(r);let u=r.nextSibling;r.remove(),r=u}}if(!a)break;a.toDOM&&(c?r=r.nextSibling:this.dom.insertBefore(a.toDOM(e),r)),c&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function AN(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const EN=z.define(),ON=z.define(),Gi=z.define({combine(n){return Cr(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let r in t){let s=i[r],o=t[r];i[r]=s?(l,a,c)=>s(l,a,c)||o(l,a,c):o}return i}})}});class Mc extends ii{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Tc(n,e){return n.state.facet(Gi).formatNumber(e,n.state)}const RN=Uo.compute([Gi],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(EN)},lineMarker(e,t,i){return i.some(r=>r.toDOM)?null:new Mc(Tc(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let r of e.state.facet(ON)){let s=r(e,t,i);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Gi)!=e.state.facet(Gi),initialSpacer(e){return new Mc(Tc(e,Dm(e.state.doc.lines)))},updateSpacer(e,t){let i=Tc(t.view,Dm(t.view.state.doc.lines));return i==e.number?e:new Mc(i)},domEventHandlers:n.facet(Gi).domEventHandlers,side:"before"}));function DN(n={}){return[Gi.of(n),CN(),RN]}function Dm(n){let e=9;for(;e<n;)e=e*10+9;return e}const NN=new class extends ii{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},IN=_o.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges){let r=n.doc.lineAt(i.head).from;r>t&&(t=r,e.push(NN.range(r)))}return X.of(e)});function LN(){return IN}const PN=1024;let BN=0;class Et{constructor(e,t){this.from=e,this.to=t}}class Y{constructor(e={}){this.id=BN++,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=ct.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}Y.closedBy=new Y({deserialize:n=>n.split(" ")});Y.openedBy=new Y({deserialize:n=>n.split(" ")});Y.group=new Y({deserialize:n=>n.split(" ")});Y.isolate=new Y({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});Y.contextHash=new Y({perNode:!0});Y.lookAhead=new Y({perNode:!0});Y.mounted=new Y({perNode:!0});class sr{constructor(e,t,i,r=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=r}static get(e){return e&&e.props&&e.props[Y.mounted.id]}}const zN=Object.create(null);class ct{constructor(e,t,i,r=0){this.name=e,this.props=t,this.id=i,this.flags=r}static define(e){let t=e.props&&e.props.length?Object.create(null):zN,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),r=new ct(e.name||"",t,e.id,i);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(Y.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let r of i.split(" "))t[r]=e[i];return i=>{for(let r=i.prop(Y.group),s=-1;s<(r?r.length:0);s++){let o=t[s<0?i.name:r[s]];if(o)return o}}}}ct.none=new ct("",Object.create(null),0,8);class Jx{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 i of this.types){let r=null;for(let s of e){let o=s(i);if(o){r||(r=Object.assign({},i.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 ct(i.name,r,i.id,i.flags):i)}return new Jx(t)}}const Mo=new WeakMap,Nm=new WeakMap;var le;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(le||(le={}));class Me{constructor(e,t,i,r,s){if(this.type=e,this.children=t,this.positions=i,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=sr.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let r=i.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 Ul(this.topNode,e)}cursorAt(e,t=0,i=0){let r=Mo.get(this)||this.topNode,s=new Ul(r);return s.moveTo(e,t),Mo.set(this,s._tree),s}get topNode(){return new Ke(this,0,0,null)}resolve(e,t=0){let i=Os(Mo.get(this)||this.topNode,e,t,!1);return Mo.set(this,i),i}resolveInner(e,t=0){let i=Os(Nm.get(this)||this.topNode,e,t,!0);return Nm.set(this,i),i}resolveStack(e,t=0){return $N(this,e,t)}iterate(e){let{enter:t,leave:i,from:r=0,to:s=this.length}=e,o=e.mode||0,l=(o&le.IncludeAnonymous)>0;for(let a=this.cursor(o|le.IncludeAnonymous);;){let c=!1;if(a.from<=s&&a.to>=r&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;c=!0}for(;c&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;c=!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:vf(ct.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,r)=>new Me(this.type,t,i,r,this.propValues),e.makeTree||((t,i,r)=>new Me(ct.none,t,i,r)))}static build(e){return VN(e)}}Me.empty=new Me(ct.none,[],[],0);class wf{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 wf(this.buffer,this.index)}}class ri{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ct.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],i=this.buffer[e+3],r=this.set.types[t],s=r.name;if(/\W/.test(s)&&!r.isError&&(s=JSON.stringify(s)),e+=4,i==e)return s;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,i,r,s){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Gx(s,r,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){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++]-i;let c=s[a++]=r[l++]-i;s[a++]=r[l++]-e,o=Math.max(o,c)}return new ri(s,o,this.set)}}function Gx(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Os(n,e,t,i){for(var r;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!i&&n instanceof Ke&&n.index<0?null:n.parent;if(!o)return n;n=o}let s=i?0:le.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof Ke&&o.index<0&&((r=l.enter(e,t,s))===null||r===void 0?void 0:r.from)!=o.from&&(n=l);for(;;){let o=n.enter(e,t,s);if(!o)return n;n=o}}class Yx{cursor(e=0){return new Ul(this,e)}getChild(e,t=null,i=null){let r=Im(this,e,t,i);return r.length?r[0]:null}getChildren(e,t=null,i=null){return Im(this,e,t,i)}resolve(e,t=0){return Os(this,e,t,!1)}resolveInner(e,t=0){return Os(this,e,t,!0)}matchContext(e){return Zh(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let r=t.lastChild;if(!r||r.to!=t.to)break;r.type.isError&&r.from==r.to?(i=t,t=r.prevSibling):t=r}return i}get node(){return this}get next(){return this.parent}}class Ke extends Yx{constructor(e,t,i,r){super(),this._tree=e,this.from=t,this.index=i,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,i,r,s=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,c=t>0?l.length:-1;e!=c;e+=t){let h=l[e],u=a[e]+o.from,f;if(!(!(s&le.EnterBracketed&&h instanceof Me&&(f=sr.get(h))&&!f.overlay&&f.bracketed&&i>=u&&i<=u+h.length)&&!Gx(r,i,u,u+h.length))){if(h instanceof ri){if(s&le.ExcludeBuffers)continue;let d=h.findChild(0,h.buffer.length,t,i-u,r);if(d>-1)return new ln(new HN(o,h,e,u),null,d)}else if(s&le.IncludeAnonymous||!h.type.isAnonymous||kf(h)){let d;if(!(s&le.IgnoreMounts)&&(d=sr.get(h))&&!d.overlay)return new Ke(d.tree,u,e,o);let p=new Ke(h,u,e,o);return s&le.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?h.children.length-1:0,t,i,r,s)}}}if(s&le.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,i=0){let r;if(!(i&le.IgnoreOverlays)&&(r=sr.get(this._tree))&&r.overlay){let s=e-this.from,o=i&le.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 Ke(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}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 Im(n,e,t,i){let r=n.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(i!=null&&r.type.is(i))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return i==null?s:[]}}function Zh(n,e,t=e.length-1){for(let i=n;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class HN{constructor(e,t,i,r){this.parent=e,this.buffer=t,this.index=i,this.start=r}}class ln extends Yx{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,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,i);return s<0?null:new ln(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,i=0){if(i&le.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 ln(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 ln(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 ln(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,r=this.index+4,s=i.buffer[this.index+3];if(s>r){let o=i.buffer[this.index+1];e.push(i.slice(r,s,o)),t.push(0)}return new Me(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Xx(n){if(!n.length)return null;let e=0,t=n[0];for(let s=1;s<n.length;s++){let o=n[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let i=t instanceof Ke&&t.index<0?null:t.parent,r=n.slice();return i?r[e]=i:r.splice(e,1),new FN(r,t)}class FN{constructor(e,t){this.heads=e,this.node=t}get next(){return Xx(this.heads)}}function $N(n,e,t){let i=n.resolveInner(e,t),r=null;for(let s=i instanceof Ke?i:i.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(r||(r=[i])).push(o.resolve(e,t)),s=o}else{let o=sr.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new Ke(o.tree,o.overlay[0].from+s.from,-1,s);(r||(r=[i])).push(Os(l,e,t,!1))}}return r?Xx(r):i}class Ul{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&~le.EnterBracketed,e instanceof Ke)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.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:i,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=i+r.buffer[e+1],this.to=i+r.buffer[e+2],!0}yield(e){return e?e instanceof Ke?(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,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:r}=this.buffer,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,i);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,i=this.mode){return this.buffer?i&le.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&le.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&le.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,i=this.stack.length-1;if(e<0){let r=i<0?0:this.stack[i]+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<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(r)}return i<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,i,{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:i}=r)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let s=t+e,o=e<0?-1:i._tree.children.length;s!=o;s+=e){let l=i._tree.children[s];if(this.mode&le.IncludeAnonymous||l instanceof ri||!l.type.isAnonymous||kf(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,i=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,i=s+1;break e}r=this.stack[--s]}for(let r=i;r<this.stack.length;r++)t=new ln(this.buffer,t,this.stack[r]);return this.bufferNode=new ln(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,r=!0}}}matchContext(e){if(!this.buffer)return Zh(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=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=i[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}return!0}}function kf(n){return n.children.some(e=>e instanceof ri||!e.type.isAnonymous||kf(e))}function VN(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:r=PN,reused:s=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new wf(t,t.length):t,a=i.types,c=0,h=0;function u(w,C,v,D,L,J){let{id:j,start:$,end:te,size:G}=l,Z=h,Oe=c;if(G<0)if(l.next(),G==-1){let E=s[j];v.push(E),D.push($-w);return}else if(G==-3){c=j;return}else if(G==-4){h=j;return}else throw new RangeError(`Unrecognized record size: ${G}`);let ft=a[j],$i,Kt,Ks=$-w;if(te-$<=r&&(Kt=g(l.pos-C,L))){let E=new Uint16Array(Kt.size-Kt.skip),V=l.pos-Kt.size,F=E.length;for(;l.pos>V;)F=y(Kt.start,E,F);$i=new ri(E,te-Kt.start,i),Ks=Kt.start-w}else{let E=l.pos-G;l.next();let V=[],F=[],ie=j>=o?j:-1,Re=0,Pt=te;for(;l.pos>E;)ie>=0&&l.id==ie&&l.size>=0?(l.end<=Pt-r&&(p(V,F,$,Re,l.end,Pt,ie,Z,Oe),Re=V.length,Pt=l.end),l.next()):J>2500?f($,E,V,F):u($,E,V,F,ie,J+1);if(ie>=0&&Re>0&&Re<V.length&&p(V,F,$,Re,$,Pt,ie,Z,Oe),V.reverse(),F.reverse(),ie>-1&&Re>0){let Ff=d(ft,Oe);$i=vf(ft,V,F,0,V.length,0,te-$,Ff,Ff)}else $i=m(ft,V,F,te-$,Z-te,Oe)}v.push($i),D.push(Ks)}function f(w,C,v,D){let L=[],J=0,j=-1;for(;l.pos>C;){let{id:$,start:te,end:G,size:Z}=l;if(Z>4)l.next();else{if(j>-1&&te<j)break;j<0&&(j=G-r),L.push($,te,G),J++,l.next()}}if(J){let $=new Uint16Array(J*4),te=L[L.length-2];for(let G=L.length-3,Z=0;G>=0;G-=3)$[Z++]=L[G],$[Z++]=L[G+1]-te,$[Z++]=L[G+2]-te,$[Z++]=Z;v.push(new ri($,L[2]-te,i)),D.push(te-w)}}function d(w,C){return(v,D,L)=>{let J=0,j=v.length-1,$,te;if(j>=0&&($=v[j])instanceof Me){if(!j&&$.type==w&&$.length==L)return $;(te=$.prop(Y.lookAhead))&&(J=D[j]+$.length+te)}return m(w,v,D,L,J,C)}}function p(w,C,v,D,L,J,j,$,te){let G=[],Z=[];for(;w.length>D;)G.push(w.pop()),Z.push(C.pop()+v-L);w.push(m(i.types[j],G,Z,J-L,$-J,te)),C.push(L-v)}function m(w,C,v,D,L,J,j){if(J){let $=[Y.contextHash,J];j=j?[$].concat(j):[$]}if(L>25){let $=[Y.lookAhead,L];j=j?[$].concat(j):[$]}return new Me(w,C,v,D,j)}function g(w,C){let v=l.fork(),D=0,L=0,J=0,j=v.end-r,$={size:0,start:0,skip:0};e:for(let te=v.pos-w;v.pos>te;){let G=v.size;if(v.id==C&&G>=0){$.size=D,$.start=L,$.skip=J,J+=4,D+=4,v.next();continue}let Z=v.pos-G;if(G<0||Z<te||v.start<j)break;let Oe=v.id>=o?4:0,ft=v.start;for(v.next();v.pos>Z;){if(v.size<0)if(v.size==-3||v.size==-4)Oe+=4;else break e;else v.id>=o&&(Oe+=4);v.next()}L=ft,D+=G,J+=Oe}return(C<0||D==w)&&($.size=D,$.start=L,$.skip=J),$.size>4?$:void 0}function y(w,C,v){let{id:D,start:L,end:J,size:j}=l;if(l.next(),j>=0&&D<o){let $=v;if(j>4){let te=l.pos-(j-4);for(;l.pos>te;)v=y(w,C,v)}C[--v]=$,C[--v]=J-w,C[--v]=L-w,C[--v]=D}else j==-3?c=D:j==-4&&(h=D);return v}let b=[],x=[];for(;l.pos>0;)u(n.start||0,n.bufferStart||0,b,x,-1,0);let k=(e=n.length)!==null&&e!==void 0?e:b.length?x[0]+b[0].length:0;return new Me(a[n.topID],b.reverse(),x.reverse(),k)}const Lm=new WeakMap;function qo(n,e){if(!n.isAnonymous||e instanceof ri||e.type!=n)return 1;let t=Lm.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof Me)){t=1;break}t+=qo(n,i)}Lm.set(e,t)}return t}function vf(n,e,t,i,r,s,o,l,a){let c=0;for(let p=i;p<r;p++)c+=qo(n,e[p]);let h=Math.ceil(c*1.5/8),u=[],f=[];function d(p,m,g,y,b){for(let x=g;x<y;){let k=x,w=m[x],C=qo(n,p[x]);for(x++;x<y;x++){let v=qo(n,p[x]);if(C+v>=h)break;C+=v}if(x==k+1){if(C>h){let v=p[k];d(v.children,v.positions,0,v.children.length,m[k]+b);continue}u.push(p[k])}else{let v=m[x-1]+p[x-1].length-w;u.push(vf(n,p,m,k,x,w,v,null,a))}f.push(w+b-s)}}return d(e,t,i,r,0),(l||a)(u,f,o)}class nB{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof ln?this.setBuffer(e.context.buffer,e.index,t):e instanceof Ke&&this.map.set(e.tree,t)}get(e){return e instanceof ln?this.getBuffer(e.context.buffer,e.index):e instanceof Ke?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 An{constructor(e,t,i,r,s=!1,o=!1){this.from=e,this.to=t,this.tree=i,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=[],i=!1){let r=[new An(0,e.length,e,0,!1,i)];for(let s of t)s.to>e.length&&r.push(s);return r}static applyChanges(e,t,i=128){if(!t.length)return e;let r=[],s=1,o=e.length?e[0]:null;for(let l=0,a=0,c=0;;l++){let h=l<t.length?t[l]:null,u=h?h.fromA:1e9;if(u-a>=i)for(;o&&o.from<u;){let f=o;if(a>=f.from||u<=f.to||c){let d=Math.max(f.from,a)-c,p=Math.min(f.to,u)-c;f=d>=p?null:new An(d,p,f.tree,f.offset+c,l>0,!!h)}if(f&&r.push(f),o.to>u)break;o=s<e.length?e[s++]:null}if(!h)break;a=h.toA,c=h.toA-h.toB}return r}}class WN{startParse(e,t,i){return typeof e=="string"&&(e=new jN(e)),i=i?i.length?i.map(r=>new Et(r.from,r.to)):[new Et(0,0)]:[new Et(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let r=this.startParse(e,t,i);for(;;){let s=r.advance();if(s)return s}}}class jN{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 iB(n){return(e,t,i,r)=>new UN(e,n,t,i,r)}class Pm{constructor(e,t,i,r,s,o){this.parser=e,this.parse=t,this.overlay=i,this.bracketed=r,this.target=s,this.from=o}}function Bm(n){if(!n.length||n.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(n))}class _N{constructor(e,t,i,r,s,o,l,a){this.parser=e,this.predicate=t,this.mounts=i,this.index=r,this.start=s,this.bracketed=o,this.target=l,this.prev=a,this.depth=0,this.ranges=[]}}const eu=new Y({perNode:!0});class UN{constructor(e,t,i,r,s){this.nest=t,this.input=i,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 i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new Me(i.type,i.children,i.positions,i.length,i.propValues.concat([[eu,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[Y.mounted.id]=new sr(t,e.overlay,e.parser,e.bracketed),e.target.props=i}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 JN(this.fragments),t=null,i=null,r=new Ul(new Ke(this.baseTree,this.ranges[0].from,0,null),le.IncludeAnonymous|le.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 c=t.mounts.find(h=>h.frag.from<=r.from&&h.frag.to>=r.to&&h.mount.overlay);if(c)for(let h of c.mount.overlay){let u=h.from+c.pos,f=h.to+c.pos;u>=r.from&&f<=r.to&&!t.ranges.some(d=>d.from<f&&d.to>u)&&t.ranges.push({from:u,to:f})}}l=!1}else if(i&&(o=qN(i.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||(KN(r),t&&t.depth++,i&&i.depth++);let c=e.findMounts(r.from,s.parser);if(typeof s.overlay=="function")t=new _N(s.parser,s.overlay,c,this.inner.length,r.from,!!s.bracketed,r.tree,t);else{let h=Fm(this.ranges,s.overlay||(r.from<r.to?[new Et(r.from,r.to)]:[]));h.length&&Bm(h),(h.length||!s.overlay)&&this.inner.push(new Pm(s.parser,h.length?s.parser.startParse(this.input,$m(c,h),h):s.parser.startParse(""),s.overlay?s.overlay.map(u=>new Et(u.from-r.from,u.to-r.from)):null,!!s.bracketed,r.tree,h.length?h[0].from:r.from)),s.overlay?h.length&&(i={ranges:h,depth:0,prev:i}):l=!1}}else if(t&&(a=t.predicate(r))&&(a===!0&&(a=new Et(r.from,r.to)),a.from<a.to)){let c=t.ranges.length-1;c>=0&&t.ranges[c].to==a.from?t.ranges[c]={from:t.ranges[c].from,to:a.to}:t.ranges.push(a)}if(l&&r.firstChild())t&&t.depth++,i&&i.depth++;else for(;!r.nextSibling();){if(!r.parent())break e;if(t&&!--t.depth){let c=Fm(this.ranges,t.ranges);c.length&&(Bm(c),this.inner.splice(t.index,0,new Pm(t.parser,t.parser.startParse(this.input,$m(t.mounts,c),c),t.ranges.map(h=>new Et(h.from-t.start,h.to-t.start)),t.bracketed,t.target,c[0].from))),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function qN(n,e,t){for(let i of n){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function zm(n,e,t,i,r,s){if(e<t){let o=n.buffer[e+1];i.push(n.slice(e,t,o)),r.push(o-s)}}function KN(n){let{node:e}=n,t=[],i=e.context.buffer;do t.push(n.index),n.parent();while(!n.tree);let r=n.tree,s=r.children.indexOf(i),o=r.children[s],l=o.buffer,a=[s];function c(h,u,f,d,p,m){let g=t[m],y=[],b=[];zm(o,h,g,y,b,d);let x=l[g+1],k=l[g+2];a.push(y.length);let w=m?c(g+4,l[g+3],o.set.types[l[g]],x,k-x,m-1):e.toTree();return y.push(w),b.push(x-d),zm(o,l[g+3],u,y,b,d),new Me(f,y,b,p)}r.children[s]=c(0,l.length,ct.none,0,o.length,t.length-1);for(let h of a){let u=n.tree.children[h],f=n.tree.positions[h];n.yield(new Ke(u,f+n.from,h,n._tree))}}class Hm{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(le.IncludeAnonymous|le.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,le.IgnoreOverlays|le.ExcludeBuffers)||t.next(!1)||(this.done=!0)}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 Me)t=t.children[0];else break}return!1}}class JN{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(eu))!==null&&t!==void 0?t:i.to,this.inner=new Hm(i.tree,-i.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(eu))!==null&&e!==void 0?e:t.to,this.inner=new Hm(t.tree,-t.offset)}}findMounts(e,t){var i;let r=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let s=this.inner.cursor.node;s;s=s.parent){let o=(i=s.tree)===null||i===void 0?void 0:i.prop(Y.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 Fm(n,e){let t=null,i=e;for(let r=1,s=0;r<n.length;r++){let o=n[r-1].to,l=n[r].from;for(;s<i.length;s++){let a=i[s];if(a.from>=l)break;a.to<=o||(t||(i=t=e.slice()),a.from<o?(t[s]=new Et(a.from,o),a.to>l&&t.splice(s+1,0,new Et(l,a.to))):a.to>l?t[s--]=new Et(l,a.to):t.splice(s--,1))}}return i}function GN(n,e,t,i){let r=0,s=0,o=!1,l=!1,a=-1e9,c=[];for(;;){let h=r==n.length?1e9:o?n[r].to:n[r].from,u=s==e.length?1e9:l?e[s].to:e[s].from;if(o!=l){let f=Math.max(a,t),d=Math.min(h,u,i);f<d&&c.push(new Et(f,d))}if(a=Math.min(h,u),a==1e9)break;h==a&&(o?(o=!1,r++):o=!0),u==a&&(l?(l=!1,s++):l=!0)}return c}function $m(n,e){let t=[];for(let{pos:i,mount:r,frag:s}of n){let o=i+(r.overlay?r.overlay[0].from:0),l=o+r.tree.length,a=Math.max(s.from,o),c=Math.min(s.to,l);if(r.overlay){let h=r.overlay.map(f=>new Et(f.from+i,f.to+i)),u=GN(e,h,a,c);for(let f=0,d=a;;f++){let p=f==u.length,m=p?c:u[f].from;if(m>d&&t.push(new An(d,m,r.tree,-o,s.from>=d||s.openStart,s.to<=m||s.openEnd)),p)break;d=u[f].to}}else t.push(new An(a,c,r.tree,-o,s.from>=o||s.openStart,s.to<=l||s.openEnd))}return t}let YN=0;class Mt{constructor(e,t,i,r){this.name=e,this.set=t,this.base=i,this.modified=r,this.id=YN++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof Mt&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let r=new Mt(i,[],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 ql(e);return i=>i.modified.indexOf(t)>-1?i:ql.get(i.base||i,i.modified.concat(t).sort((r,s)=>r.id-s.id))}}let XN=0;class ql{constructor(e){this.name=e,this.instances=[],this.id=XN++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&QN(t,l.modified));if(i)return i;let r=[],s=new Mt(e.name,r,e,t);for(let l of t)l.instances.push(s);let o=ZN(t);for(let l of e.set)if(!l.modified.length)for(let a of o)r.push(ql.get(l,a));return s}}function QN(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function ZN(n){let e=[[]];for(let t=0;t<n.length;t++)for(let i=0,r=e.length;i<r;i++)e.push(e[i].concat(n[t]));return e.sort((t,i)=>i.length-t.length)}function eI(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let r of t.split(" "))if(r){let s=[],o=2,l=r;for(let u=0;;){if(l=="..."&&u>0&&u+3==r.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!f)throw new RangeError("Invalid path: "+r);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),u+=f[0].length,u==r.length)break;let d=r[u++];if(u==r.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+r);l=r.slice(u)}let a=s.length-1,c=s[a];if(!c)throw new RangeError("Invalid path: "+r);let h=new Rs(i,o,a>0?s.slice(0,a):null);e[c]=h.sort(e[c])}}return Qx.add(e)}const Qx=new Y({combine(n,e){let t,i,r;for(;n||e;){if(!n||e&&n.depth<=e.depth?(r=e,e=e.next):(r=n,n=n.next),t&&t.mode==r.mode&&!r.context&&!t.context)continue;let s=new Rs(r.tags,r.mode,r.context);t?t.next=s:i=s,t=s}return i}});class Rs{constructor(e,t,i,r){this.tags=e,this.mode=t,this.context=i,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}}Rs.empty=new Rs([],2,null);function Zx(n,e){let t=Object.create(null);for(let s of n)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:i,all:r=null}=e||{};return{style:s=>{let o=r;for(let l of s)for(let a of l.set){let c=t[a.id];if(c){o=o?o+" "+c:c;break}}return o},scope:i}}function tI(n,e){let t=null;for(let i of n){let r=i.style(e);r&&(t=t?t+" "+r:r)}return t}function nI(n,e,t,i=0,r=n.length){let s=new iI(i,Array.isArray(e)?e:[e],t);s.highlightRange(n.cursor(),i,r,"",s.highlighters),s.flush(r)}class iI{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,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,i,r,s){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(s=this.highlighters.filter(d=>!d.scope||d.scope(o)));let c=r,h=rI(e)||Rs.empty,u=tI(s,h.tags);if(u&&(c&&(c+=" "),c+=u,h.mode==1&&(r+=(r?" ":"")+u)),this.startSpan(Math.max(t,l),c),h.opaque)return;let f=e.tree&&e.tree.prop(Y.mounted);if(f&&f.overlay){let d=e.node.enter(f.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,y=l;;g++){let b=g<f.overlay.length?f.overlay[g]:null,x=b?b.from+l:a,k=Math.max(t,y),w=Math.min(i,x);if(k<w&&m)for(;e.from<w&&(this.highlightRange(e,k,w,r,s),this.startSpan(Math.min(w,e.to),c),!(e.to>=x||!e.nextSibling())););if(!b||x>i)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),c))}m&&e.parent()}else if(e.firstChild()){f&&(r="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,r,s),this.startSpan(Math.min(i,e.to),c)}while(e.nextSibling());e.parent()}}}function rI(n){let e=n.type.prop(Qx);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const N=Mt.define,To=N(),Hn=N(),Vm=N(Hn),Wm=N(Hn),Fn=N(),Ao=N(Fn),Ac=N(Fn),Xt=N(),hi=N(Xt),Gt=N(),Yt=N(),tu=N(),Lr=N(tu),Eo=N(),O={comment:To,lineComment:N(To),blockComment:N(To),docComment:N(To),name:Hn,variableName:N(Hn),typeName:Vm,tagName:N(Vm),propertyName:Wm,attributeName:N(Wm),className:N(Hn),labelName:N(Hn),namespace:N(Hn),macroName:N(Hn),literal:Fn,string:Ao,docString:N(Ao),character:N(Ao),attributeValue:N(Ao),number:Ac,integer:N(Ac),float:N(Ac),bool:N(Fn),regexp:N(Fn),escape:N(Fn),color:N(Fn),url:N(Fn),keyword:Gt,self:N(Gt),null:N(Gt),atom:N(Gt),unit:N(Gt),modifier:N(Gt),operatorKeyword:N(Gt),controlKeyword:N(Gt),definitionKeyword:N(Gt),moduleKeyword:N(Gt),operator:Yt,derefOperator:N(Yt),arithmeticOperator:N(Yt),logicOperator:N(Yt),bitwiseOperator:N(Yt),compareOperator:N(Yt),updateOperator:N(Yt),definitionOperator:N(Yt),typeOperator:N(Yt),controlOperator:N(Yt),punctuation:tu,separator:N(tu),bracket:Lr,angleBracket:N(Lr),squareBracket:N(Lr),paren:N(Lr),brace:N(Lr),content:Xt,heading:hi,heading1:N(hi),heading2:N(hi),heading3:N(hi),heading4:N(hi),heading5:N(hi),heading6:N(hi),contentSeparator:N(Xt),list:N(Xt),quote:N(Xt),emphasis:N(Xt),strong:N(Xt),link:N(Xt),monospace:N(Xt),strikethrough:N(Xt),inserted:N(),deleted:N(),changed:N(),invalid:N(),meta:Eo,documentMeta:N(Eo),annotation:N(Eo),processingInstruction:N(Eo),definition:Mt.defineModifier("definition"),constant:Mt.defineModifier("constant"),function:Mt.defineModifier("function"),standard:Mt.defineModifier("standard"),local:Mt.defineModifier("local"),special:Mt.defineModifier("special")};for(let n in O){let e=O[n];e instanceof Mt&&(e.name=n)}Zx([{tag:O.link,class:"tok-link"},{tag:O.heading,class:"tok-heading"},{tag:O.emphasis,class:"tok-emphasis"},{tag:O.strong,class:"tok-strong"},{tag:O.keyword,class:"tok-keyword"},{tag:O.atom,class:"tok-atom"},{tag:O.bool,class:"tok-bool"},{tag:O.url,class:"tok-url"},{tag:O.labelName,class:"tok-labelName"},{tag:O.inserted,class:"tok-inserted"},{tag:O.deleted,class:"tok-deleted"},{tag:O.literal,class:"tok-literal"},{tag:O.string,class:"tok-string"},{tag:O.number,class:"tok-number"},{tag:[O.regexp,O.escape,O.special(O.string)],class:"tok-string2"},{tag:O.variableName,class:"tok-variableName"},{tag:O.local(O.variableName),class:"tok-variableName tok-local"},{tag:O.definition(O.variableName),class:"tok-variableName tok-definition"},{tag:O.special(O.variableName),class:"tok-variableName2"},{tag:O.definition(O.propertyName),class:"tok-propertyName tok-definition"},{tag:O.typeName,class:"tok-typeName"},{tag:O.namespace,class:"tok-namespace"},{tag:O.className,class:"tok-className"},{tag:O.macroName,class:"tok-macroName"},{tag:O.propertyName,class:"tok-propertyName"},{tag:O.operator,class:"tok-operator"},{tag:O.comment,class:"tok-comment"},{tag:O.meta,class:"tok-meta"},{tag:O.invalid,class:"tok-invalid"},{tag:O.punctuation,class:"tok-punctuation"}]);var Ec;const Yi=new Y;function sI(n){return z.define({combine:n?e=>e.concat(n):void 0})}const oI=new Y;class Vt{constructor(e,t,i=[],r=""){this.data=e,this.name=r,ee.prototype.hasOwnProperty("tree")||Object.defineProperty(ee.prototype,"tree",{get(){return ht(this)}}),this.parser=t,this.extension=[kr.of(this),ee.languageData.of((s,o,l)=>{let a=jm(s,o,l),c=a.type.prop(Yi);if(!c)return[];let h=s.facet(c),u=a.type.prop(oI);if(u){let f=a.resolve(o-a.from,l);for(let d of u)if(d.test(f,s)){let p=s.facet(d.facet);return d.type=="replace"?p:p.concat(h)}}return h})].concat(i)}isActiveAt(e,t,i=-1){return jm(e,t,i).type.prop(Yi)==this.data}findRegions(e){let t=e.facet(kr);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],r=(s,o)=>{if(s.prop(Yi)==this.data){i.push({from:o,to:o+s.length});return}let l=s.prop(Y.mounted);if(l){if(l.tree.prop(Yi)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+s.length});return}else if(l.overlay){let a=i.length;if(r(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<s.children.length;a++){let c=s.children[a];c instanceof Me&&r(c,s.positions[a]+o)}};return r(ht(e),0),i}get allowsNesting(){return!0}}Vt.setState=Q.define();function jm(n,e,t){let i=n.facet(kr),r=ht(n).topNode;if(!i||i.allowsNesting)for(let s=r;s;s=s.enter(e,t,le.ExcludeBuffers|le.EnterBracketed))s.type.isTop&&(r=s);return r}class nu extends Vt{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=sI(e.languageData);return new nu(t,e.parser.configure({props:[Yi.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new nu(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ht(n){let e=n.field(Vt.state,!1);return e?e.tree:Me.empty}class lI{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 i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let Pr=null;class Kl{constructor(e,t,i=[],r,s,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=r,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Kl(e,t,[],Me.empty,0,i,[],null)}startParse(){return this.parser.startParse(new lI(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=Me.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;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(An.addTree(r,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i: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(An.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Pr;Pr=this;try{return e()}finally{Pr=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=_m(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:r,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((c,h,u,f)=>a.push({fromA:c,toA:h,fromB:u,toB:f})),i=An.applyChanges(i,a),r=Me.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let h=e.mapPos(c.from,1),u=e.mapPos(c.to,-1);h<u&&l.push({from:h,to:u})}}}return new Kl(this.parser,t,i,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 i=0;i<this.skipped.length;i++){let{from:r,to:s}=this.skipped[i];r<e.to&&s>e.from&&(this.fragments=_m(this.fragments,r,s),this.skipped.splice(i--,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 WN{createParse(t,i,r){let s=r[0].from,o=r[r.length-1].to;return{parsedPos:s,advance(){let a=Pr;if(a){for(let c of r)a.tempSkipped.push(c);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new Me(ct.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 Pr}}function _m(n,e,t){return An.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class wr{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),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new wr(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Kl.create(e.facet(kr).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new wr(i)}}Vt.state=ut.define({create:wr.init,update(n,e){for(let t of e.effects)if(t.is(Vt.setState))return t.value;return e.startState.facet(kr)!=e.state.facet(kr)?wr.init(e.state):n.apply(e)}});let e1=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(e1=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Oc=typeof navigator<"u"&&(!((Ec=navigator.scheduling)===null||Ec===void 0)&&Ec.isInputPending)?()=>navigator.scheduling.isInputPending():null,aI=at.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(Vt.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(Vt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=e1(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:i,viewport:{to:r}}=this.view,s=i.field(Vt.state);if(s.tree==s.context.tree&&s.context.isDone(r+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Oc?Math.max(25,e.timeRemaining()-5):1e9),l=s.context.treeLen<r&&i.doc.length>r+1e3,a=s.context.work(()=>Oc&&Oc()||Date.now()>o,r+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Vt.setState.of(new wr(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=>xt(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()}}}),kr=z.define({combine(n){return n.length?n[0]:null},enables:n=>[Vt.state,aI,B.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class sB{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class t1{constructor(e,t,i,r,s,o=void 0){this.name=e,this.alias=t,this.extensions=i,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:i}=e;if(!t){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(i)}return new t1(e.name,(e.alias||[]).concat(e.name).map(r=>r.toLowerCase()),e.extensions||[],e.filename,t,i)}static matchFilename(e,t){for(let r of e)if(r.filename&&r.filename.test(t))return r;let i=/\.([^.]+)$/.exec(t);if(i){for(let r of e)if(r.extensions.indexOf(i[1])>-1)return r}return null}static matchLanguageName(e,t,i=!0){t=t.toLowerCase();for(let r of e)if(r.alias.some(s=>s==t))return r;if(i)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 cI=z.define(),Ea=z.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Jl(n){let e=n.facet(Ea);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Ds(n,e){let t="",i=n.tabSize,r=n.facet(Ea)[0];if(r==" "){for(;e>=i;)t+=" ",e-=i;r=" "}for(let s=0;s<e;s++)t+=r;return t}function Sf(n,e){n instanceof ee&&(n=new Oa(n));for(let i of n.state.facet(cI)){let r=i(n,e);if(r!==void 0)return r}let t=ht(n.state);return t.length>=e?uI(n,t,e):null}class Oa{constructor(e,t={}){this.state=e,this.options=t,this.unit=Jl(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:s}=this.options;return r!=null&&r>=i.from&&r<=i.to?s&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:i.text.slice(r-i.from),from:r}:{text:i.text.slice(0,r-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:r}=this.lineAt(e,t);return i.slice(e-r,Math.min(i.length,e+100-r))}column(e,t=1){let{text:i,from:r}=this.lineAt(e,t),s=this.countColumn(i,e-r),o=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return o>-1&&(s+=o-this.countColumn(i,i.search(/\S|$/))),s}countColumn(e,t=e.length){return ka(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:r}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(r);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const hI=new Y;function uI(n,e,t){let i=e.resolveStack(t),r=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(r!=i.node){let s=[];for(let o=r;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)i={node:s[o],next:i}}return n1(i,n,t)}function n1(n,e,t){for(let i=n;i;i=i.next){let r=dI(i.node);if(r)return r(Cf.create(e,t,i))}return 0}function fI(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function dI(n){let e=n.type.prop(hI);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(Y.closedBy))){let r=n.lastChild,s=r&&i.indexOf(r.name)>-1;return o=>i1(o,!0,1,void 0,s&&!fI(o)?r.from:void 0)}return n.parent==null?pI:null}function pI(){return 0}class Cf extends Oa{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new Cf(e,t,i)}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 i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(mI(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return n1(this.context.next,this.base,this.pos)}}function mI(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function gI(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let r=n.options.simulateBreak,s=n.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==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let c=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+c}}l=a.to}}function oB({closing:n,align:e=!0,units:t=1}){return i=>i1(i,e,t,n)}function i1(n,e,t,i,r){let s=n.textAfter,o=s.match(/^\s*/)[0].length,l=i&&s.slice(o,o+i.length)==i||r==n.pos+o,a=e?gI(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const lB=n=>n.baseIndent;function aB({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const yI=200;function bI(){return ee.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,r=t.lineAt(i);if(i>r.from+yI)return n;let s=t.sliceString(r.from,i);if(!e.some(c=>c.test(s)))return n;let{state:o}=n,l=-1,a=[];for(let{head:c}of o.selection.ranges){let h=o.doc.lineAt(c);if(h.from==l)continue;l=h.from;let u=Sf(o,h.from);if(u==null)continue;let f=/^\s*/.exec(h.text)[0],d=Ds(o,u);f!=d&&a.push({from:h.from,to:h.from+f.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}const cB=z.define(),hB=new Y;function uB(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}class Ra{constructor(e,t){this.specs=e;let i;function r(l){let a=ti.newName();return(i||(i=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 Vt?l=>l.prop(Yi)==o.data:o?l=>l==o:void 0,this.style=Zx(e.map(l=>({tag:l.tag,class:l.class||r(Object.assign({},l,{tag:null}))})),{all:s}).style,this.module=i?new ti(i):null,this.themeType=t.themeType}static define(e,t){return new Ra(e,t||{})}}const iu=z.define(),xI=z.define({combine(n){return n.length?[n[0]]:null}});function Rc(n){let e=n.facet(iu);return e.length?e:n.facet(xI)}function r1(n,e){let t=[kI],i;return n instanceof Ra&&(n.module&&t.push(B.styleModule.of(n.module)),i=n.themeType),i?t.push(iu.computeN([B.darkTheme],r=>r.facet(B.darkTheme)==(i=="dark")?[n]:[])):t.push(iu.of(n)),t}class wI{constructor(e){this.markCache=Object.create(null),this.tree=ht(e.state),this.decorations=this.buildDeco(e,Rc(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=ht(e.state),i=Rc(e.state),r=i!=Rc(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,i),this.decoratedTo=s.to)}buildDeco(e,t){if(!t||!this.tree.length)return q.none;let i=new gr;for(let{from:r,to:s}of e.visibleRanges)nI(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=q.mark({class:a})))},r,s);return i.finish()}}const kI=Fi.high(at.fromClass(wI,{decorations:n=>n.decorations})),vI=B.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),s1=1e4,o1="()[]{}",l1=z.define({combine(n){return Cr(n,{afterCursor:!0,brackets:o1,maxScanDistance:s1,renderMatch:MI})}}),SI=q.mark({class:"cm-matchingBracket"}),CI=q.mark({class:"cm-nonmatchingBracket"});function MI(n){let e=[],t=n.matched?SI:CI;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const TI=ut.define({create(){return q.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(l1);for(let r of e.state.selection.ranges){if(!r.empty)continue;let s=an(e.state,r.head,-1,i)||r.head>0&&an(e.state,r.head-1,1,i)||i.afterCursor&&(an(e.state,r.head,1,i)||r.head<e.state.doc.length&&an(e.state,r.head+1,-1,i));s&&(t=t.concat(i.renderMatch(s,e.state)))}return q.set(t,!0)},provide:n=>B.decorations.from(n)}),AI=[TI,vI];function EI(n={}){return[l1.of(n),AI]}const OI=new Y;function ru(n,e,t){let i=n.prop(e<0?Y.openedBy:Y.closedBy);if(i)return i;if(n.name.length==1){let r=t.indexOf(n.name);if(r>-1&&r%2==(e<0?1:0))return[t[r+e]]}return null}function su(n){let e=n.type.prop(OI);return e?e(n.node):n}function an(n,e,t,i={}){let r=i.maxScanDistance||s1,s=i.brackets||o1,o=ht(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let c=ru(a.type,t,s);if(c&&a.from<a.to){let h=su(a);if(h&&(t>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return RI(n,e,t,a,h,c,s)}}return DI(n,e,t,o,l.type,r,s)}function RI(n,e,t,i,r,s,o){let l=i.parent,a={from:r.from,to:r.to},c=0,h=l?.cursor();if(h&&(t<0?h.childBefore(i.from):h.childAfter(i.to)))do if(t<0?h.to<=i.from:h.from>=i.to){if(c==0&&s.indexOf(h.type.name)>-1&&h.from<h.to){let u=su(h);return{start:a,end:u?{from:u.from,to:u.to}:void 0,matched:!0}}else if(ru(h.type,t,o))c++;else if(ru(h.type,-t,o)){if(c==0){let u=su(h);return{start:a,end:u&&u.from<u.to?{from:u.from,to:u.to}:void 0,matched:!1}}c--}}while(t<0?h.prevSibling():h.nextSibling());return{start:a,matched:!1}}function DI(n,e,t,i,r,s,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let c={from:t<0?e-1:e,to:t>0?e+1:e},h=n.doc.iterRange(e,t>0?n.doc.length:0),u=0;for(let f=0;!h.next().done&&f<=s;){let d=h.value;t<0&&(f+=d.length);let p=e+f*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||i.resolveInner(p+m,1).type!=r))if(y%2==0==t>0)u++;else{if(u==1)return{start:c,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};u--}}t>0&&(f+=d.length)}return h.done?{start:c,matched:!1}:null}const NI=Object.create(null),Um=[ct.none],qm=[],Km=Object.create(null),II=Object.create(null);for(let[n,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"]])II[n]=LI(NI,e);function Dc(n,e){qm.indexOf(n)>-1||(qm.push(n),console.warn(e))}function LI(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let c of l.split(".")){let h=n[c]||O[c];h?typeof h=="function"?a.length?a=a.map(h):Dc(c,`Modifier ${c} used at start of tag`):a.length?Dc(c,`Tag ${c} used as modifier`):a=Array.isArray(h)?h:[h]:Dc(c,`Unknown highlighting tag ${c}`)}for(let c of a)t.push(c)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),r=i+" "+t.map(l=>l.id),s=Km[r];if(s)return s.id;let o=Km[r]=ct.define({id:Um.length,name:i,props:[eI({[i]:t})]});return Um.push(o),o.id}ye.RTL,ye.LTR;const PI=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=Tf(n.state,t.from);return i.line?BI(n):i.block?HI(n):!1};function Mf(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let r=n(e,t);return r?(i(t.update(r)),!0):!1}}const BI=Mf(VI,0),zI=Mf(a1,0),HI=Mf((n,e)=>a1(n,e,$I(e)),0);function Tf(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Br=50;function FI(n,{open:e,close:t},i,r){let s=n.sliceDoc(i-Br,i),o=n.sliceDoc(r,r+Br),l=/\s*$/.exec(s)[0].length,a=/^\s*/.exec(o)[0].length,c=s.length-l;if(s.slice(c-e.length,c)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:r+a,margin:a&&1}};let h,u;r-i<=2*Br?h=u=n.sliceDoc(i,r):(h=n.sliceDoc(i,i+Br),u=n.sliceDoc(r-Br,r));let f=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(u)[0].length,p=u.length-d-t.length;return h.slice(f,f+e.length)==e&&u.slice(p,p+t.length)==t?{open:{pos:i+f+e.length,margin:/\s/.test(h.charAt(f+e.length))?1:0},close:{pos:r-d-t.length,margin:/\s/.test(u.charAt(p-1))?1:0}}:null}function $I(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),r=t.to<=i.to?i:n.doc.lineAt(t.to);r.from>i.from&&r.from==t.to&&(r=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>i.from?e[s].to=r.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:r.to})}return e}function a1(n,e,t=e.selection.ranges){let i=t.map(s=>Tf(e,s.from).block);if(!i.every(s=>s))return null;let r=t.map((s,o)=>FI(e,i[o],s.from,s.to));if(n!=2&&!r.every(s=>s))return{changes:e.changes(t.map((s,o)=>r[o]?[]:[{from:s.from,insert:i[o].open+" "},{from:s.to,insert:" "+i[o].close}]))};if(n!=1&&r.some(s=>s)){let s=[];for(let o=0,l;o<r.length;o++)if(l=r[o]){let a=i[o],{open:c,close:h}=l;s.push({from:c.pos-a.open.length,to:c.pos+c.margin},{from:h.pos-h.margin,to:h.pos+a.close.length})}return{changes:s}}return null}function VI(n,e,t=e.selection.ranges){let i=[],r=-1;e:for(let{from:s,to:o}of t){let l=i.length,a=1e9,c;for(let h=s;h<=o;){let u=e.doc.lineAt(h);if(c==null&&(c=Tf(e,u.from).line,!c))continue e;if(u.from>r&&(s==o||o>u.from)){r=u.from;let f=/^\s*/.exec(u.text)[0].length,d=f==u.length,p=u.text.slice(f,f+c.length)==c?f:-1;f<u.text.length&&f<a&&(a=f),i.push({line:u,comment:p,token:c,indent:f,empty:d,single:!1})}h=u.to+1}if(a<1e9)for(let h=l;h<i.length;h++)i[h].indent<i[h].line.text.length&&(i[h].indent=a);i.length==l+1&&(i[l].single=!0)}if(n!=2&&i.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:l,token:a,indent:c,empty:h,single:u}of i)(u||!h)&&s.push({from:l.from+c,insert:a+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let c=o.from+l,h=c+a.length;o.text[h-o.from]==" "&&h++,s.push({from:c,to:h})}return{changes:s}}return null}const ou=Nn.define(),WI=Nn.define(),jI=z.define(),c1=z.define({combine(n){return Cr(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,r)=>e(i,r)||t(i,r)})}}),h1=ut.define({create(){return cn.empty},update(n,e){let t=e.state.facet(c1),i=e.annotation(ou);if(i){let a=st.fromTransaction(e,i.selection),c=i.side,h=c==0?n.undone:n.done;return a?h=Gl(h,h.length,t.minDepth,a):h=d1(h,e.startState.selection),new cn(c==0?i.rest:h,c==0?h:i.rest)}let r=e.annotation(WI);if((r=="full"||r=="before")&&(n=n.isolate()),e.annotation(Ce.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let s=st.fromTransaction(e),o=e.annotation(Ce.time),l=e.annotation(Ce.userEvent);return s?n=n.addChanges(s,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(r=="full"||r=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new cn(n.done.map(st.fromJSON),n.undone.map(st.fromJSON))}});function _I(n={}){return[h1,c1.of(n),B.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?u1:e.inputType=="historyRedo"?lu:null;return i?(e.preventDefault(),i(t)):!1}})]}function Da(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let r=t.field(h1,!1);if(!r)return!1;let s=r.pop(n,t,e);return s?(i(s),!0):!1}}const u1=Da(0,!1),lu=Da(1,!1),UI=Da(0,!0),qI=Da(1,!0);class st{constructor(e,t,i,r,s){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=r,this.selectionsAfter=s}setSelAfter(e){return new st(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;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:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(e){return new st(e.changes&&Ee.fromJSON(e.changes),[],e.mapped&&hn.fromJSON(e.mapped),e.startSelection&&T.fromJSON(e.startSelection),e.selectionsAfter.map(T.fromJSON))}static fromTransaction(e,t){let i=Ot;for(let r of e.startState.facet(jI)){let s=r(e);s.length&&(i=i.concat(s))}return!i.length&&e.changes.empty?null:new st(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ot)}static selection(e){return new st(void 0,Ot,void 0,void 0,e)}}function Gl(n,e,t,i){let r=e+1>t+20?e-t-1:0,s=n.slice(r,e);return s.push(i),s}function KI(n,e){let t=[],i=!1;return n.iterChangedRanges((r,s)=>t.push(r,s)),e.iterChangedRanges((r,s,o,l)=>{for(let a=0;a<t.length;){let c=t[a++],h=t[a++];l>=c&&o<=h&&(i=!0)}}),i}function JI(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function f1(n,e){return n.length?e.length?n.concat(e):n:e}const Ot=[],GI=200;function d1(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-GI));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),Gl(n,n.length-1,1e9,t.setSelAfter(i)))}else return[st.selection([e])]}function YI(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Nc(n,e){if(!n.length)return n;let t=n.length,i=Ot;for(;t;){let r=XI(n[t-1],e,i);if(r.changes&&!r.changes.empty||r.effects.length){let s=n.slice(0,t);return s[t-1]=r,s}else e=r.mapped,t--,i=r.selectionsAfter}return i.length?[st.selection(i)]:Ot}function XI(n,e,t){let i=f1(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Ot,t);if(!n.changes)return st.selection(i);let r=n.changes.map(e),s=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(s):s;return new st(r,Q.mapEffects(n.effects,e),o,n.startSelection.map(s),i)}const QI=/^(input\.type|delete)($|\.)/;class cn{constructor(e,t,i=0,r=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=r}isolate(){return this.prevTime?new cn(this.done,this.undone):this}addChanges(e,t,i,r,s){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||QI.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(s,KI(l.changes,e.changes))||i=="input.type.compose")?o=Gl(o,o.length-1,r.minDepth,new st(e.changes.compose(l.changes),f1(Q.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ot)):o=Gl(o,o.length,r.minDepth,e),new cn(o,Ot,t,i)}addSelection(e,t,i,r){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Ot;return s.length>0&&t-this.prevTime<r&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&JI(s[s.length-1],e)?this:new cn(d1(this.done,e),this.undone,t,i)}addMapping(e){return new cn(Nc(this.done,e),Nc(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){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(i&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:ou.of({side:e,rest:YI(r),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let l=r.length==1?Ot:r.slice(0,r.length-1);return s.mapped&&(l=Nc(l,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:ou.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}cn.empty=new cn(Ot,Ot);const ZI=[{key:"Mod-z",run:u1,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:lu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:lu,preventDefault:!0},{key:"Mod-u",run:UI,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:qI,preventDefault:!0}];function Mr(n,e){return T.create(n.ranges.map(e),n.mainIndex)}function Ut(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function qt({state:n,dispatch:e},t){let i=Mr(n.selection,t);return i.eq(n.selection,!0)?!1:(e(Ut(n,i)),!0)}function Na(n,e){return T.cursor(e?n.to:n.from)}function p1(n,e){return qt(n,t=>t.empty?n.moveByChar(t,e):Na(t,e))}function Ye(n){return n.textDirectionAt(n.state.selection.main.head)==ye.LTR}const m1=n=>p1(n,!Ye(n)),g1=n=>p1(n,Ye(n));function y1(n,e){return qt(n,t=>t.empty?n.moveByGroup(t,e):Na(t,e))}const e2=n=>y1(n,!Ye(n)),t2=n=>y1(n,Ye(n));function n2(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function Ia(n,e,t){let i=ht(n).resolveInner(e.head),r=t?Y.closedBy:Y.openedBy;for(let a=e.head;;){let c=t?i.childAfter(a):i.childBefore(a);if(!c)break;n2(n,c,r)?i=c:a=t?c.to:c.from}let s=i.type.prop(r),o,l;return s&&(o=t?an(n,i.from,1):an(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,T.cursor(l,t?-1:1)}const i2=n=>qt(n,e=>Ia(n.state,e,!Ye(n))),r2=n=>qt(n,e=>Ia(n.state,e,Ye(n)));function b1(n,e){return qt(n,t=>{if(!t.empty)return Na(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const x1=n=>b1(n,!1),w1=n=>b1(n,!0);function k1(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,r;if(e){for(let s of n.state.facet(B.scrollMargins)){let o=s(n);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(i=Math.max(o?.bottom,i))}r=n.scrollDOM.clientHeight-t-i}else r=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,r-5)}}function v1(n,e){let t=k1(n),{state:i}=n,r=Mr(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):Na(o,e));if(r.eq(i.selection))return!1;let s;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,c=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<c&&(s=B.scrollIntoView(r.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Ut(i,r),{effects:s}),!0}const Jm=n=>v1(n,!1),au=n=>v1(n,!0);function ai(n,e,t){let i=n.lineBlockAt(e.head),r=n.moveToLineBoundary(e,t);if(r.head==e.head&&r.head!=(t?i.to:i.from)&&(r=n.moveToLineBoundary(e,t,!1)),!t&&r.head==i.from&&i.length){let s=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;s&&e.head!=i.from+s&&(r=T.cursor(i.from+s))}return r}const s2=n=>qt(n,e=>ai(n,e,!0)),o2=n=>qt(n,e=>ai(n,e,!1)),l2=n=>qt(n,e=>ai(n,e,!Ye(n))),a2=n=>qt(n,e=>ai(n,e,Ye(n))),c2=n=>qt(n,e=>T.cursor(n.lineBlockAt(e.head).from,1)),h2=n=>qt(n,e=>T.cursor(n.lineBlockAt(e.head).to,-1));function u2(n,e,t){let i=!1,r=Mr(n.selection,s=>{let o=an(n,s.head,-1)||an(n,s.head,1)||s.head>0&&an(n,s.head-1,1)||s.head<n.doc.length&&an(n,s.head+1,-1);if(!o||!o.end)return s;i=!0;let l=o.start.from==s.head?o.end.to:o.end.from;return T.cursor(l)});return i?(e(Ut(n,r)),!0):!1}const f2=({state:n,dispatch:e})=>u2(n,e);function Lt(n,e){let t=Mr(n.state.selection,i=>{let r=e(i);return T.range(i.anchor,r.head,r.goalColumn,r.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Ut(n.state,t)),!0)}function S1(n,e){return Lt(n,t=>n.moveByChar(t,e))}const C1=n=>S1(n,!Ye(n)),M1=n=>S1(n,Ye(n));function T1(n,e){return Lt(n,t=>n.moveByGroup(t,e))}const d2=n=>T1(n,!Ye(n)),p2=n=>T1(n,Ye(n)),m2=n=>Lt(n,e=>Ia(n.state,e,!Ye(n))),g2=n=>Lt(n,e=>Ia(n.state,e,Ye(n)));function A1(n,e){return Lt(n,t=>n.moveVertically(t,e))}const E1=n=>A1(n,!1),O1=n=>A1(n,!0);function R1(n,e){return Lt(n,t=>n.moveVertically(t,e,k1(n).height))}const Gm=n=>R1(n,!1),Ym=n=>R1(n,!0),y2=n=>Lt(n,e=>ai(n,e,!0)),b2=n=>Lt(n,e=>ai(n,e,!1)),x2=n=>Lt(n,e=>ai(n,e,!Ye(n))),w2=n=>Lt(n,e=>ai(n,e,Ye(n))),k2=n=>Lt(n,e=>T.cursor(n.lineBlockAt(e.head).from)),v2=n=>Lt(n,e=>T.cursor(n.lineBlockAt(e.head).to)),Xm=({state:n,dispatch:e})=>(e(Ut(n,{anchor:0})),!0),Qm=({state:n,dispatch:e})=>(e(Ut(n,{anchor:n.doc.length})),!0),Zm=({state:n,dispatch:e})=>(e(Ut(n,{anchor:n.selection.main.anchor,head:0})),!0),eg=({state:n,dispatch:e})=>(e(Ut(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),S2=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),C2=({state:n,dispatch:e})=>{let t=La(n).map(({from:i,to:r})=>T.range(i,Math.min(r+1,n.doc.length)));return e(n.update({selection:T.create(t),userEvent:"select"})),!0},M2=({state:n,dispatch:e})=>{let t=Mr(n.selection,i=>{let r=ht(n),s=r.resolveStack(i.from,1);if(i.empty){let o=r.resolveStack(i.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<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return T.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ut(n,t)),!0)};function D1(n,e){let{state:t}=n,i=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<n.state.doc.length:o.from>0)for(let l=s;;){let a=n.moveVertically(l,e);if(a.head<o.from||a.head>o.to){r.some(c=>c.head==a.head)||r.push(a);break}else{if(a.head==l.head)break;l=a}}}return r.length==i.ranges.length?!1:(n.dispatch(Ut(t,T.create(r,r.length-1))),!0)}const T2=n=>D1(n,!1),A2=n=>D1(n,!0),E2=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=T.create([t.main]):t.main.empty||(i=T.create([T.cursor(t.main.head)])),i?(e(Ut(n,i)),!0):!1};function _s(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,r=i.changeByRange(s=>{let{from:o,to:l}=s;if(o==l){let a=e(s);a<o?(t="delete.backward",a=Oo(n,a,!1)):a>o&&(t="delete.forward",a=Oo(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Oo(n,o,!1),l=Oo(n,l,!0);return o==l?{range:s}:{changes:{from:o,to:l},range:T.cursor(o,o<s.head?-1:1)}});return r.changes.empty?!1:(n.dispatch(i.update(r,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?B.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Oo(n,e,t){if(n instanceof B)for(let i of n.state.facet(B.atomicRanges).map(r=>r(n)))i.between(e,e,(r,s)=>{r<e&&s>e&&(e=t?s:r)});return e}const N1=(n,e,t)=>_s(n,i=>{let r=i.from,{state:s}=n,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 c=ka(l,s.tabSize),h=c%Jl(s)||Jl(s);for(let u=0;u<h&&l[l.length-1-u]==" ";u++)r--;a=r}else a=Pe(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=Pe(o.text,a-o.from,!1,!1)+o.from);return a}),cu=n=>N1(n,!1,!0),I1=n=>N1(n,!0,!1),L1=(n,e)=>_s(n,t=>{let i=t.head,{state:r}=n,s=r.doc.lineAt(i),o=r.charCategorizer(i);for(let l=null;;){if(i==(e?s.to:s.from)){i==t.head&&s.number!=(e?r.doc.lines:1)&&(i+=e?1:-1);break}let a=Pe(s.text,i-s.from,e)+s.from,c=s.text.slice(Math.min(i,a)-s.from,Math.max(i,a)-s.from),h=o(c);if(l!=null&&h!=l)break;(c!=" "||i!=t.head)&&(l=h),i=a}return i}),P1=n=>L1(n,!1),O2=n=>L1(n,!0),R2=n=>_s(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),D2=n=>_s(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),N2=n=>_s(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),I2=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:ne.of(["",""])},range:T.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},L2=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let r=i.from,s=n.doc.lineAt(r),o=r==s.from?r-1:Pe(s.text,r-s.from,!1)+s.from,l=r==s.to?r+1:Pe(s.text,r-s.from,!0)+s.from;return{changes:{from:o,to:l,insert:n.doc.slice(r,l).append(n.doc.slice(o,r))},range:T.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function La(n){let e=[],t=-1;for(let i of n.selection.ranges){let r=n.doc.lineAt(i.from),s=n.doc.lineAt(i.to);if(!i.empty&&i.to==s.from&&(s=n.doc.lineAt(i.to-1)),t>=r.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(i)}else e.push({from:r.from,to:s.to,ranges:[i]});t=s.number+1}return e}function B1(n,e,t){if(n.readOnly)return!1;let i=[],r=[];for(let s of La(n)){if(t?s.to==n.doc.length:s.from==0)continue;let o=n.doc.lineAt(t?s.to+1:s.from-1),l=o.length+1;if(t){i.push({from:s.to,to:o.to},{from:s.from,insert:o.text+n.lineBreak});for(let a of s.ranges)r.push(T.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:s.from},{from:s.to,insert:n.lineBreak+o.text});for(let a of s.ranges)r.push(T.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:T.create(r,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const P2=({state:n,dispatch:e})=>B1(n,e,!1),B2=({state:n,dispatch:e})=>B1(n,e,!0);function z1(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of La(n))t?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});let r=n.changes(i);return e(n.update({changes:r,selection:n.selection.map(r,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const z2=({state:n,dispatch:e})=>z1(n,e,!1),H2=({state:n,dispatch:e})=>z1(n,e,!0),F2=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(La(e).map(({from:r,to:s})=>(r>0?r--:s<e.doc.length&&s++,{from:r,to:s}))),i=Mr(e.selection,r=>{let s;if(n.lineWrapping){let o=n.lineBlockAt(r.head),l=n.coordsAtPos(r.head,r.assoc||1);l&&(s=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(r,!0,s)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function $2(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ht(n).resolveInner(e),i=t.childBefore(e),r=t.childAfter(e),s;return i&&r&&i.to<=e&&r.from>=e&&(s=i.type.prop(Y.closedBy))&&s.indexOf(r.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(r.from).from&&!/\S/.test(n.sliceDoc(i.to,r.from))?{from:i.to,to:r.from}:null}const tg=H1(!1),V2=H1(!0);function H1(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(r=>{let{from:s,to:o}=r,l=e.doc.lineAt(s),a=!n&&s==o&&$2(e,s);n&&(s=o=(o<=l.to?l:e.doc.lineAt(o)).to);let c=new Oa(e,{simulateBreak:s,simulateDoubleBreak:!!a}),h=Sf(c,s);for(h==null&&(h=ka(/^\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 u=["",Ds(e,h)];return a&&u.push(Ds(e,c.lineIndent(l.from,-1))),{changes:{from:s,to:o,insert:ne.of(u)},range:T.cursor(s+1+u[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Af(n,e){let t=-1;return n.changeByRange(i=>{let r=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,r,i),t=l.number),o=l.to+1}let s=n.changes(r);return{changes:r,range:T.range(s.mapPos(i.anchor,1),s.mapPos(i.head,1))}})}const W2=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Oa(n,{overrideIndentation:s=>{let o=t[s];return o??-1}}),r=Af(n,(s,o,l)=>{let a=Sf(i,s.from);if(a==null)return;/\S/.test(s.text)||(a=0);let c=/^\s*/.exec(s.text)[0],h=Ds(n,a);(c!=h||l.from<s.from+c.length)&&(t[s.from]=a,o.push({from:s.from,to:s.from+c.length,insert:h}))});return r.changes.empty||e(n.update(r,{userEvent:"indent"})),!0},F1=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Af(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Ea)})}),{userEvent:"input.indent"})),!0),$1=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Af(n,(t,i)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let s=ka(r,n.tabSize),o=0,l=Ds(n,Math.max(0,s-Jl(n)));for(;o<r.length&&o<l.length&&r.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+r.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),j2=n=>(n.setTabFocusMode(),!0),_2=[{key:"Ctrl-b",run:m1,shift:C1,preventDefault:!0},{key:"Ctrl-f",run:g1,shift:M1},{key:"Ctrl-p",run:x1,shift:E1},{key:"Ctrl-n",run:w1,shift:O1},{key:"Ctrl-a",run:c2,shift:k2},{key:"Ctrl-e",run:h2,shift:v2},{key:"Ctrl-d",run:I1},{key:"Ctrl-h",run:cu},{key:"Ctrl-k",run:R2},{key:"Ctrl-Alt-h",run:P1},{key:"Ctrl-o",run:I2},{key:"Ctrl-t",run:L2},{key:"Ctrl-v",run:au}],U2=[{key:"ArrowLeft",run:m1,shift:C1,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e2,shift:d2,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:l2,shift:x2,preventDefault:!0},{key:"ArrowRight",run:g1,shift:M1,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t2,shift:p2,preventDefault:!0},{mac:"Cmd-ArrowRight",run:a2,shift:w2,preventDefault:!0},{key:"ArrowUp",run:x1,shift:E1,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Xm,shift:Zm},{mac:"Ctrl-ArrowUp",run:Jm,shift:Gm},{key:"ArrowDown",run:w1,shift:O1,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Qm,shift:eg},{mac:"Ctrl-ArrowDown",run:au,shift:Ym},{key:"PageUp",run:Jm,shift:Gm},{key:"PageDown",run:au,shift:Ym},{key:"Home",run:o2,shift:b2,preventDefault:!0},{key:"Mod-Home",run:Xm,shift:Zm},{key:"End",run:s2,shift:y2,preventDefault:!0},{key:"Mod-End",run:Qm,shift:eg},{key:"Enter",run:tg,shift:tg},{key:"Mod-a",run:S2},{key:"Backspace",run:cu,shift:cu,preventDefault:!0},{key:"Delete",run:I1,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:P1,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:O2,preventDefault:!0},{mac:"Mod-Backspace",run:D2,preventDefault:!0},{mac:"Mod-Delete",run:N2,preventDefault:!0}].concat(_2.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),q2=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:i2,shift:m2},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:r2,shift:g2},{key:"Alt-ArrowUp",run:P2},{key:"Shift-Alt-ArrowUp",run:z2},{key:"Alt-ArrowDown",run:B2},{key:"Shift-Alt-ArrowDown",run:H2},{key:"Mod-Alt-ArrowUp",run:T2},{key:"Mod-Alt-ArrowDown",run:A2},{key:"Escape",run:E2},{key:"Mod-Enter",run:V2},{key:"Alt-l",mac:"Ctrl-l",run:C2},{key:"Mod-i",run:M2,preventDefault:!0},{key:"Mod-[",run:$1},{key:"Mod-]",run:F1},{key:"Mod-Alt-\\",run:W2},{key:"Shift-Mod-k",run:F2},{key:"Shift-Mod-\\",run:f2},{key:"Mod-/",run:PI},{key:"Alt-A",run:zI},{key:"Ctrl-m",mac:"Shift-Alt-m",run:j2}].concat(U2),K2={key:"Tab",run:F1,shift:$1},ng=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class vr{constructor(e,t,i=0,r=e.length,s,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,r),this.bufferStart=i,this.normalize=s?l=>s(ng(l)):ng,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return gt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=rf(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=rn(e);let r=this.normalize(t);if(r.length)for(let s=0,o=i;;s++){let l=r.charCodeAt(s),a=this.match(l,o,this.bufferPos+this.bufferStart);if(s==r.length-1){if(a)return this.value=a,this;break}o==i&&s<t.length&&t.charCodeAt(s)==l&&o++}}}match(e,t,i){let r=null;for(let s=0;s<this.matches.length;s+=2){let o=this.matches[s],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?r={from:this.matches[s+1],to:i}:(this.matches[s]++,l=!0)),l||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:i}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}}typeof Symbol<"u"&&(vr.prototype[Symbol.iterator]=function(){return this});const V1={from:-1,to:-1,match:/.*/.exec("")},Ef="gm"+(/x/.unicode==null?"":"u");class W1{constructor(e,t,i,r=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=V1,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new j1(e,t,i,r,s);this.re=new RegExp(t,Ef+(i?.ignoreCase?"i":"")),this.test=i?.test,this.iter=e.iter();let o=e.lineAt(r);this.curLineStart=o.from,this.matchPos=Yl(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,r=i+t[0].length;if(this.matchPos=Yl(this.text,r+(i==r?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<r||i>this.value.to)&&(!this.test||this.test(i,r,t)))return this.value={from:i,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Ic=new WeakMap;class or{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let r=Ic.get(e);if(!r||r.from>=i||r.to<=t){let l=new or(t,e.sliceString(t,i));return Ic.set(e,l),l}if(r.from==t&&r.to==i)return r;let{text:s,from:o}=r;return o>t&&(s=e.sliceString(t,o)+s,o=t),r.to<i&&(s+=e.sliceString(r.to,i)),Ic.set(e,new or(o,s)),new or(t,s.slice(t-o,i-o))}}class j1{constructor(e,t,i,r,s){this.text=e,this.to=s,this.done=!1,this.value=V1,this.matchPos=Yl(e,r),this.re=new RegExp(t,Ef+(i?.ignoreCase?"i":"")),this.test=i?.test,this.flat=or.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,r=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,r,t)))return this.value={from:i,to:r,match:t},this.matchPos=Yl(this.text,r+(i==r?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=or.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(W1.prototype[Symbol.iterator]=j1.prototype[Symbol.iterator]=function(){return this});function J2(n){try{return new RegExp(n,Ef),!0}catch{return!1}}function Yl(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}const G2=n=>{let{state:e}=n,t=String(e.doc.lineAt(n.state.selection.main.head).number),{close:i,result:r}=kN(n,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return r.then(s=>{let o=s&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.elements.line.value);if(!o){n.dispatch({effects:i});return}let l=e.doc.lineAt(e.selection.main.head),[,a,c,h,u]=o,f=h?+h.slice(1):0,d=c?+c:l.number;if(c&&u){let g=d/100;a&&(g=g*(a=="-"?-1:1)+l.number/e.doc.lines),d=Math.round(e.doc.lines*g)}else c&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=e.doc.line(Math.max(1,Math.min(e.doc.lines,d))),m=T.cursor(p.from+Math.max(0,Math.min(f,p.length)));n.dispatch({effects:[i,B.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},Y2={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},X2=z.define({combine(n){return Cr(n,Y2,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Q2(n){return[iL,nL]}const Z2=q.mark({class:"cm-selectionMatch"}),eL=q.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ig(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=ge.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=ge.Word)}function tL(n,e,t,i){return n(e.sliceDoc(t,t+1))==ge.Word&&n(e.sliceDoc(i-1,i))==ge.Word}const nL=at.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(X2),{state:t}=n,i=t.selection;if(i.ranges.length>1)return q.none;let r=i.main,s,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return q.none;let a=t.wordAt(r.head);if(!a)return q.none;o=t.charCategorizer(r.head),s=t.sliceDoc(a.from,a.to)}else{let a=r.to-r.from;if(a<e.minSelectionLength||a>200)return q.none;if(e.wholeWords){if(s=t.sliceDoc(r.from,r.to),o=t.charCategorizer(r.head),!(ig(o,t,r.from,r.to)&&tL(o,t,r.from,r.to)))return q.none}else if(s=t.sliceDoc(r.from,r.to),!s)return q.none}let l=[];for(let a of n.visibleRanges){let c=new vr(t.doc,s,a.from,a.to);for(;!c.next().done;){let{from:h,to:u}=c.value;if((!o||ig(o,t,h,u))&&(r.empty&&h<=r.from&&u>=r.to?l.push(eL.range(h,u)):(h>=r.to||u<=r.from)&&l.push(Z2.range(h,u)),l.length>e.maxMatches))return q.none}}return q.set(l)}},{decorations:n=>n.decorations}),iL=B.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),rL=({state:n,dispatch:e})=>{let{selection:t}=n,i=T.create(t.ranges.map(r=>n.wordAt(r.head)||T.cursor(r.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function sL(n,e){let{main:t,ranges:i}=n.selection,r=n.wordAt(t.head),s=r&&r.from==t.from&&r.to==t.to;for(let o=!1,l=new vr(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new vr(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(s){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const oL=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(s=>s.from===s.to))return rL({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(s=>n.sliceDoc(s.from,s.to)!=i))return!1;let r=sL(n,i);return r?(e(n.update({selection:n.selection.addRange(T.range(r.from,r.to),!1),effects:B.scrollIntoView(r.to)})),!0):!1},Tr=z.define({combine(n){return Cr(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new wL(e),scrollToMatch:e=>B.scrollIntoView(e)})}});class _1{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||J2(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
161
- `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new fL(this):new cL(this)}getCursor(e,t=0,i){let r=e.doc?e:ee.create({doc:e});return i==null&&(i=r.doc.length),this.regexp?Ki(this,r,t,i):qi(this,r,t,i)}}class U1{constructor(e){this.spec=e}}function lL(n,e,t){return(i,r,s,o)=>{if(t&&!t(i,r,s,o))return!1;let l=i>=o&&r<=o+s.length?s.slice(i-o,r-o):e.doc.sliceString(i,r);return n(l,e,i,r)}}function qi(n,e,t,i){let r;return n.wholeWord&&(r=aL(e.doc,e.charCategorizer(e.selection.main.head))),n.test&&(r=lL(n.test,e,r)),new vr(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),r)}function aL(n,e){return(t,i,r,s)=>((s>t||s+r.length<i)&&(s=Math.max(0,t-2),r=n.sliceString(s,Math.min(n.length,i+2))),(e(Xl(r,t-s))!=ge.Word||e(Ql(r,t-s))!=ge.Word)&&(e(Ql(r,i-s))!=ge.Word||e(Xl(r,i-s))!=ge.Word))}class cL extends U1{constructor(e){super(e)}nextMatch(e,t,i){let r=qi(this.spec,e,i,e.doc.length).nextOverlapping();if(r.done){let s=Math.min(e.doc.length,t+this.spec.unquoted.length);r=qi(this.spec,e,0,s).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==i?null:r.value}prevMatchInRange(e,t,i){for(let r=i;;){let s=Math.max(t,r-1e4-this.spec.unquoted.length),o=qi(this.spec,e,s,r),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(s==t)return null;r-=1e4}}prevMatch(e,t,i){let r=this.prevMatchInRange(e,0,t);return r||(r=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),r&&(r.from!=t||r.to!=i)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=qi(this.spec,e,0,e.doc.length),r=[];for(;!i.next().done;){if(r.length>=t)return null;r.push(i.value)}return r}highlight(e,t,i,r){let s=qi(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)r(s.value.from,s.value.to)}}function hL(n,e,t){return(i,r,s)=>(!t||t(i,r,s))&&n(s[0],e,i,r)}function Ki(n,e,t,i){let r;return n.wholeWord&&(r=uL(e.charCategorizer(e.selection.main.head))),n.test&&(r=hL(n.test,e,r)),new W1(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:r},t,i)}function Xl(n,e){return n.slice(Pe(n,e,!1),e)}function Ql(n,e){return n.slice(e,Pe(n,e))}function uL(n){return(e,t,i)=>!i[0].length||(n(Xl(i.input,i.index))!=ge.Word||n(Ql(i.input,i.index))!=ge.Word)&&(n(Ql(i.input,i.index+i[0].length))!=ge.Word||n(Xl(i.input,i.index+i[0].length))!=ge.Word)}class fL extends U1{nextMatch(e,t,i){let r=Ki(this.spec,e,i,e.doc.length).next();return r.done&&(r=Ki(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,i){for(let r=1;;r++){let s=Math.max(t,i-r*1e4),o=Ki(this.spec,e,s,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(s==t||l.from>s+10))return l;if(s==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let r=i.length;r>0;r--){let s=+i.slice(0,r);if(s>0&&s<e.match.length)return e.match[s]+i.slice(r)}return t})}matchAll(e,t){let i=Ki(this.spec,e,0,e.doc.length),r=[];for(;!i.next().done;){if(r.length>=t)return null;r.push(i.value)}return r}highlight(e,t,i,r){let s=Ki(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!s.next().done;)r(s.value.from,s.value.to)}}const Ns=Q.define(),Of=Q.define(),Qn=ut.define({create(n){return new Lc(hu(n).create(),null)},update(n,e){for(let t of e.effects)t.is(Ns)?n=new Lc(t.value.create(),n.panel):t.is(Of)&&(n=new Lc(n.query,t.value?Rf:null));return n},provide:n=>_l.from(n,e=>e.panel)});class Lc{constructor(e,t){this.query=e,this.panel=t}}const dL=q.mark({class:"cm-searchMatch"}),pL=q.mark({class:"cm-searchMatch cm-searchMatch-selected"}),mL=at.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(Qn))}update(n){let e=n.state.field(Qn);(e!=n.startState.field(Qn)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return q.none;let{view:t}=this,i=new gr;for(let r=0,s=t.visibleRanges,o=s.length;r<o;r++){let{from:l,to:a}=s[r];for(;r<o-1&&a>s[r+1].from-500;)a=s[++r].to;n.highlight(t.state,l,a,(c,h)=>{let u=t.state.selection.ranges.some(f=>f.from==c&&f.to==h);i.add(c,h,u?pL:dL)})}return i.finish()}},{decorations:n=>n.decorations});function Us(n){return e=>{let t=e.state.field(Qn,!1);return t&&t.query.spec.valid?n(e,t):J1(e)}}const Zl=Us((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let r=T.single(i.from,i.to),s=n.state.facet(Tr);return n.dispatch({selection:r,effects:[Df(n,i),s.scrollToMatch(r.main,n)],userEvent:"select.search"}),K1(n),!0}),ea=Us((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,r=e.prevMatch(t,i,i);if(!r)return!1;let s=T.single(r.from,r.to),o=n.state.facet(Tr);return n.dispatch({selection:s,effects:[Df(n,r),o.scrollToMatch(s.main,n)],userEvent:"select.search"}),K1(n),!0}),gL=Us((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:T.create(t.map(i=>T.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),yL=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:r}=t.main,s=[],o=0;for(let l=new vr(n.doc,n.sliceDoc(i,r));!l.next().done;){if(s.length>1e3)return!1;l.value.from==i&&(o=s.length),s.push(T.range(l.value.from,l.value.to))}return e(n.update({selection:T.create(s,o),userEvent:"select.search.matches"})),!0},rg=Us((n,{query:e})=>{let{state:t}=n,{from:i,to:r}=t.selection.main;if(t.readOnly)return!1;let s=e.nextMatch(t,i,i);if(!s)return!1;let o=s,l=[],a,c,h=[];o.from==i&&o.to==r&&(c=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:c}),o=e.nextMatch(t,o.from,o.to),h.push(B.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+".")));let u=n.state.changes(l);return o&&(a=T.single(o.from,o.to).map(u),h.push(Df(n,o)),h.push(t.facet(Tr).scrollToMatch(a.main,n))),n.dispatch({changes:u,selection:a,effects:h,userEvent:"input.replace"}),!0}),bL=Us((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state,1e9).map(r=>{let{from:s,to:o}=r;return{from:s,to:o,insert:e.getReplacement(r)}});if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:B.announce.of(i),userEvent:"input.replace.all"}),!0});function Rf(n){return n.state.facet(Tr).createPanel(n)}function hu(n,e){var t,i,r,s,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let c=n.facet(Tr);return new _1({search:((t=e?.literal)!==null&&t!==void 0?t:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(r=e?.literal)!==null&&r!==void 0?r:c.literal,regexp:(s=e?.regexp)!==null&&s!==void 0?s:c.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function q1(n){let e=jx(n,Rf);return e&&e.dom.querySelector("[main-field]")}function K1(n){let e=q1(n);e&&e==n.root.activeElement&&e.select()}const J1=n=>{let e=n.state.field(Qn,!1);if(e&&e.panel){let t=q1(n);if(t&&t!=n.root.activeElement){let i=hu(n.state,e.query.spec);i.valid&&n.dispatch({effects:Ns.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[Of.of(!0),e?Ns.of(hu(n.state,e.query.spec)):Q.appendConfig.of(vL)]});return!0},G1=n=>{let e=n.state.field(Qn,!1);if(!e||!e.panel)return!1;let t=jx(n,Rf);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Of.of(!1)}),!0},xL=[{key:"Mod-f",run:J1,scope:"editor search-panel"},{key:"F3",run:Zl,shift:ea,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Zl,shift:ea,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:G1,scope:"editor search-panel"},{key:"Mod-Shift-l",run:yL},{key:"Mod-Alt-g",run:G2},{key:"Mod-d",run:oL,preventDefault:!0}];class wL{constructor(e){this.view=e;let t=this.query=e.state.field(Qn).query.spec;this.commit=this.commit.bind(this),this.searchField=De("input",{value:t.search,placeholder:pt(e,"Find"),"aria-label":pt(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=De("input",{value:t.replace,placeholder:pt(e,"Replace"),"aria-label":pt(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=De("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=De("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=De("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(r,s,o){return De("button",{class:"cm-button",name:r,onclick:s,type:"button"},o)}this.dom=De("div",{onkeydown:r=>this.keydown(r),class:"cm-search"},[this.searchField,i("next",()=>Zl(e),[pt(e,"next")]),i("prev",()=>ea(e),[pt(e,"previous")]),i("select",()=>gL(e),[pt(e,"all")]),De("label",null,[this.caseField,pt(e,"match case")]),De("label",null,[this.reField,pt(e,"regexp")]),De("label",null,[this.wordField,pt(e,"by word")]),...e.state.readOnly?[]:[De("br"),this.replaceField,i("replace",()=>rg(e),[pt(e,"replace")]),i("replaceAll",()=>bL(e),[pt(e,"replace all")])],De("button",{name:"close",onclick:()=>G1(e),"aria-label":pt(e,"close"),type:"button"},["×"])])}commit(){let e=new _1({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Ns.of(e)}))}keydown(e){uN(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?ea:Zl)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),rg(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(Ns)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Tr).top}}function pt(n,e){return n.state.phrase(e)}const Ro=30,Do=/[\s\.,:;?!]/;function Df(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),r=n.state.doc.lineAt(t).to,s=Math.max(i.from,e-Ro),o=Math.min(r,t+Ro),l=n.state.sliceDoc(s,o);if(s!=i.from){for(let a=0;a<Ro;a++)if(!Do.test(l[a+1])&&Do.test(l[a])){l=l.slice(a);break}}if(o!=r){for(let a=l.length-1;a>l.length-Ro;a--)if(!Do.test(l[a-1])&&Do.test(l[a])){l=l.slice(0,a);break}}return B.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const kL=B.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),vL=[Qn,Fi.low(mL),kL];class Y1{constructor(e,t,i,r){this.state=e,this.pos=t,this.explicit=i,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ht(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),i=Math.max(t.from,this.pos-250),r=t.text.slice(i-t.from,this.pos-t.from),s=r.search(X1(e,!1));return s<0?null:{from:i+s,to:this.pos,text:r.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function sg(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function SL(n){let e=Object.create(null),t=Object.create(null);for(let{label:r}of n){e[r[0]]=!0;for(let s=1;s<r.length;s++)t[r[s]]=!0}let i=sg(e)+sg(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function CL(n){let e=n.map(r=>typeof r=="string"?{label:r}:r),[t,i]=e.every(r=>/^\w+$/.test(r.label))?[/\w*$/,/\w+$/]:SL(e);return r=>{let s=r.matchBefore(i);return s||r.explicit?{from:s?s.from:r.pos,options:e,validFor:t}:null}}function fB(n,e){return t=>{for(let i=ht(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class og{constructor(e,t,i,r){this.completion=e,this.source=t,this.match=i,this.score=r}}function Mi(n){return n.selection.main.from}function X1(n,e){var t;let{source:i}=n,r=e&&i[0]!="^",s=i[i.length-1]!="$";return!r&&!s?n:new RegExp(`${r?"^":""}(?:${i})${s?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const Nf=Nn.define();function ML(n,e,t,i){let{main:r}=n.selection,s=t-r.from,o=i-r.from;return{...n.changeByRange(l=>{if(l!=r&&t!=i&&n.sliceDoc(l.from+s,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+s,to:i==r.from?l.to:l.from+o,insert:a},range:T.cursor(l.from+s+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const lg=new WeakMap;function TL(n){if(!Array.isArray(n))return n;let e=lg.get(n);return e||lg.set(n,e=CL(n)),e}const ta=Q.define(),Is=Q.define();class AL{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 i=gt(e,t),r=rn(i);this.chars.push(i);let s=e.slice(t,t+r),o=s.toUpperCase();this.folded.push(gt(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:i,any:r,precise:s,byWord:o}=this;if(t.length==1){let b=gt(e,0),x=rn(b),k=x==e.length?0:-100;if(b!=t[0])if(b==i[0])k+=-200;else return null;return this.ret(k,[0,x])}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,c=0;if(l<0){for(let b=0,x=Math.min(e.length,200);b<x&&c<a;){let k=gt(e,b);(k==t[c]||k==i[c])&&(r[c++]=b),b+=rn(k)}if(c<a)return null}let h=0,u=0,f=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let b=0,x=Math.min(e.length,200),k=0;b<x&&u<a;){let w=gt(e,b);l<0&&(h<a&&w==t[h]&&(s[h++]=b),d<a&&(w==t[d]||w==i[d]?(d==0&&(p=b),m=b+1,d++):d=0));let C,v=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(C=rf(w))!=C.toLowerCase()?1:C!=C.toUpperCase()?2:0;(!b||v==1&&g||k==0&&v!=0)&&(t[u]==w||i[u]==w&&(f=!0)?o[u++]=b:o.length&&(y=!1)),k=v,b+=rn(w)}return u==a&&o[0]==0&&y?this.result(-100+(f?-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]):u==a?this.result(-100+(f?-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,i){let r=[],s=0;for(let o of t){let l=o+(this.astral?rn(gt(i,o)):1);s&&r[s-1]==o?r[s-1]=l:(r[s++]=o,r[s++]=l)}return this.ret(e-i.length,r)}}class EL{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),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const Ie=z.define({combine(n){return Cr(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:OL,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)=>i=>ag(e(i),t(i)),optionClass:(e,t)=>i=>ag(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function ag(n,e){return n?e?n+" "+e:n:e}function OL(n,e,t,i,r,s){let o=n.textDirection==ye.RTL,l=o,a=!1,c="top",h,u,f=e.left-r.left,d=r.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&f<Math.min(p,d)?l=!1:!l&&d<Math.min(p,f)&&(l=!0),p<=(l?f:d))h=Math.max(r.top,Math.min(t.top,r.bottom-m))-e.top,u=Math.min(400,l?f:d);else{a=!0,u=Math.min(400,(o?e.right:r.right-e.left)-30);let b=r.bottom-e.bottom;b>=m||b>e.top?h=t.bottom-e.top:(c="bottom",h=e.bottom-t.top)}let g=(e.bottom-e.top)/s.offsetHeight,y=(e.right-e.left)/s.offsetWidth;return{style:`${c}: ${h/g}px; max-width: ${u/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function RL(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(r=>"cm-completionIcon-"+r)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,r,s){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let c=0;c<s.length;){let h=s[c++],u=s[c++];h>a&&o.appendChild(document.createTextNode(l.slice(a,h)));let f=o.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(l.slice(h,u))),f.className="cm-completionMatchedText",a=u}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function Pc(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let r=Math.floor(e/t);return{from:r*t,to:(r+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class DL{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,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(Ie);this.optionContent=RL(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Pc(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:c}=e.state.field(t).open;for(let h=a.target,u;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(u=/-(\d+)$/.exec(h.id))&&+u[1]<c.length){this.applyCompletion(e,c[+u[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let c=e.state.field(this.stateField,!1);c&&c.tooltip&&e.state.facet(Ie).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Is.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 i=e.state.field(this.stateField),r=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=r){let{options:s,selected:o,disabled:l}=i.open;(!r.open||r.open.options!=s)&&(this.range=Pc(s.length,o,e.state.facet(Ie).maxRenderedOptions),this.showOptions(s,i.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 i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);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=Pc(t.options.length,t.selected,this.view.state.facet(Ie).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){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=>xt(this.view.state,l,"completion info")):(this.addInfoPane(o,r),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:r,destroy:s}=e;i.appendChild(r),this.infoDestroy=s||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,r=this.range.from;i;i=i.nextSibling,r++)i.nodeName!="LI"||!i.id?r--:r==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&IL(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=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(Ie).positionInfo(this.view,t,r,i,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,i){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=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:c}=l;if(c){let f=typeof c=="string"?c:c.name;if(f!=s&&(o>i.from||i.from==0))if(s=f,typeof c!="string"&&c.header)r.appendChild(c.header(c));else{let d=r.appendChild(document.createElement("completion-section"));d.textContent=f}}const h=r.appendChild(document.createElement("li"));h.id=t+"-"+o,h.setAttribute("role","option");let u=this.optionClass(l);u&&(h.className=u);for(let f of this.optionContent){let d=f(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&r.classList.add("cm-completionListIncompleteTop"),i.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 NL(n,e){return t=>new DL(t,n,e)}function IL(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),r=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/r:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/r)}function cg(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function LL(n,e){let t=[],i=null,r=null,s=h=>{t.push(h);let{section:u}=h.completion;if(u){i||(i=[]);let f=typeof u=="string"?u:u.name;i.some(d=>d.name==f)||i.push(typeof u=="string"?{name:f}:u)}},o=e.facet(Ie);for(let h of n)if(h.hasResult()){let u=h.result.getMatch;if(h.result.filter===!1)for(let f of h.result.options)s(new og(f,h.source,u?u(f):[],1e9-t.length));else{let f=e.sliceDoc(h.from,h.to),d,p=o.filterStrict?new EL(f):new AL(f);for(let m of h.result.options)if(d=p.match(m.label)){let g=m.displayLabel?u?u(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(s(new og(m,h.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(i){let h=Object.create(null),u=0,f=(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 i.sort(f))u-=1e5,h[d.name]=u;for(let d of t){let{section:p}=d.completion;p&&(d.score+=h[typeof p=="string"?p:p.name])}}let l=[],a=null,c=o.compareCompletions;for(let h of t.sort((u,f)=>f.score-u.score||c(u.completion,f.completion))){let u=h.completion;!a||a.label!=u.label||a.detail!=u.detail||a.type!=null&&u.type!=null&&a.type!=u.type||a.apply!=u.apply||a.boost!=u.boost?l.push(h):cg(h.completion)>cg(a)&&(l[l.length-1]=h),a=h.completion}return l}class Xi{constructor(e,t,i,r,s,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=r,this.selected=s,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Xi(this.options,hg(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,r,s,o){if(r&&!o&&e.some(c=>c.isPending))return r.setDisabled();let l=LL(e,t);if(!l.length)return r&&e.some(c=>c.isPending)?r.setDisabled():null;let a=t.facet(Ie).selectOnOpen?0:-1;if(r&&r.selected!=a&&r.selected!=-1){let c=r.options[r.selected].completion;for(let h=0;h<l.length;h++)if(l[h].completion==c){a=h;break}}return new Xi(l,hg(i,a),{pos:e.reduce((c,h)=>h.hasResult()?Math.min(c,h.from):c,1e8),create:$L,above:s.aboveCursor},r?r.timestamp:Date.now(),a,!1)}map(e){return new Xi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Xi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class na{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new na(HL,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Ie),s=(i.override||t.languageDataAt("autocomplete",Mi(t)).map(TL)).map(a=>(this.active.find(h=>h.source==a)||new Rt(a,this.active.some(h=>h.state!=0)?1:0)).update(e,i));s.length==this.active.length&&s.every((a,c)=>a==this.active[c])&&(s=this.active);let o=this.open,l=e.effects.some(a=>a.is(If));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||s.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!PL(s,this.active)||l?o=Xi.build(s,t,this.id,o,i,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 Rt(a.source,0):a));for(let a of e.effects)a.is(Z1)&&(o=o&&o.setSelected(a.value,this.id));return s==this.active&&o==this.open?this:new na(s,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?BL:zL}}function PL(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let r=t==n.length,s=i==e.length;if(r||s)return r==s;if(n[t++].result!=e[i++].result)return!1}}const BL={"aria-autocomplete":"list"},zL={};function hg(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const HL=[];function Q1(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(Nf);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}class Rt{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=Q1(e,t),r=this;(i&8||i&16&&this.touches(e))&&(r=new Rt(r.source,0)),i&4&&r.state==0&&(r=new Rt(this.source,1)),r=r.updateFor(e,i);for(let s of e.effects)if(s.is(ta))r=new Rt(r.source,1,s.value);else if(s.is(Is))r=new Rt(r.source,0);else if(s.is(If))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(Mi(e.state))}}class lr extends Rt{constructor(e,t,i,r,s,o){super(e,3,t),this.limit=i,this.result=r,this.from=s,this.to=o}hasResult(){return!0}updateFor(e,t){var i;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=Mi(e.state);if(l>o||!r||t&2&&(Mi(e.startState)==this.from||l<this.limit))return new Rt(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return FL(r.validFor,e.state,s,o)?new lr(this.source,this.explicit,a,r,s,o):r.update&&(r=r.update(r,s,o,new Y1(e.state,l,!1)))?new lr(this.source,this.explicit,a,r,r.from,(i=r.to)!==null&&i!==void 0?i:Mi(e.state)):new Rt(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new lr(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Rt(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function FL(n,e,t,i){if(!n)return!1;let r=e.sliceDoc(t,i);return typeof n=="function"?n(r,t,i,e):X1(n,!0).test(r)}const If=Q.define({map(n,e){return n.map(t=>t.map(e))}}),Z1=Q.define(),it=ut.define({create(){return na.start()},update(n,e){return n.update(e)},provide:n=>[Vx.from(n,e=>e.tooltip),B.contentAttributes.from(n,e=>e.attrs)]});function Lf(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(it).active.find(r=>r.source==e.source);return i instanceof lr?(typeof t=="string"?n.dispatch({...ML(n.state,t,i.from,i.to),annotations:Nf.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}const $L=NL(it,Lf);function No(n,e="option"){return t=>{let i=t.state.field(it,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(Ie).interactionDelay)return!1;let r=1,s;e=="page"&&(s=Wx(t,i.open.tooltip))&&(r=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+r*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Z1.of(l)}),!0}}const VL=n=>{let e=n.state.field(it,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(Ie).interactionDelay?!1:Lf(n,e.open.options[e.open.selected])},Bc=n=>n.state.field(it,!1)?(n.dispatch({effects:ta.of(!0)}),!0):!1,WL=n=>{let e=n.state.field(it,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Is.of(null)}),!0)};class jL{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const _L=50,UL=1e3,qL=at.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(it).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(it),t=n.state.facet(Ie);if(!n.selectionSet&&!n.docChanged&&n.startState.field(it)==e)return;let i=n.transactions.some(s=>{let o=Q1(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(i||o.context.abortOnDocChange&&n.docChanged||o.updates.length+n.transactions.length>_L&&Date.now()-o.time>UL){for(let l of o.context.abortListeners)try{l()}catch(a){xt(this.view.state,a)}o.context.abortListeners=null,this.running.splice(s--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(o=>o.is(ta)))&&(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 n.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:n}=this.view,e=n.field(it);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ie).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=Mi(e),i=new Y1(e,t,n.explicit,this.view),r=new jL(n,i);this.running.push(r),Promise.resolve(n.source(i)).then(s=>{r.context.aborted||(r.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:Is.of(null)}),xt(this.view.state,s)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ie).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Ie),i=this.view.state.field(it);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=Mi(s.updates.length?s.updates[0].startState:this.view.state),a=Math.min(l,s.done.from+(s.active.explicit?0:1)),c=new lr(s.active.source,s.active.explicit,a,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:l);for(let h of s.updates)c=c.update(h,t);if(c.hasResult()){e.push(c);continue}}let o=i.active.find(l=>l.source==s.active.source);if(o&&o.isPending)if(s.done==null){let l=new Rt(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||i.open&&i.open.disabled)&&this.view.dispatch({effects:If.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(it,!1);if(e&&e.tooltip&&this.view.state.facet(Ie).closeOnBlur){let t=e.open&&Wx(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Is.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:ta.of(!1)}),20),this.composing=0}}}),KL=typeof navigator=="object"&&/Win/.test(navigator.platform),JL=Fi.highest(B.domEventHandlers({keydown(n,e){let t=e.state.field(it,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(KL&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],r=t.active.find(o=>o.source==i.source),s=i.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(n.key)>-1&&Lf(e,i),!1}})),ew=B.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"},".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 GL{constructor(e,t,i,r){this.field=e,this.line=t,this.from=i,this.to=r}}class Pf{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,qe.TrackDel),i=e.mapPos(this.to,1,qe.TrackDel);return t==null||i==null?null:new Pf(this.field,t,i)}}class Bf{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],r=[t],s=e.doc.lineAt(t),o=/^\s*/.exec(s.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let u=0;u<h;u++)c+=e.facet(Ea);r.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Pf(a.field,r[a.line]+a.from,r[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],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]||"",c=-1,h=a.replace(/\\[{}]/g,u=>u[1]);for(let u=0;u<t.length;u++)(l!=null?t[u].seq==l:h&&t[u].name==h)&&(c=u);if(c<0){let u=0;for(;u<t.length&&(l==null||t[u].seq!=null&&t[u].seq<l);)u++;t.splice(u,0,{seq:l,name:h}),c=u;for(let f of r)f.field>=c&&f.field++}for(let u of r)if(u.line==i.length&&u.from>s.index){let f=s[2]?3+(s[1]||"").length:2;u.from-=f,u.to-=f}r.push(new GL(c,i.length,s.index,s.index+h.length)),o=o.slice(0,s.index)+a+o.slice(s.index+s[0].length)}o=o.replace(/\\([{}])/g,(l,a,c)=>{for(let h of r)h.line==i.length&&h.from>c&&(h.from--,h.to--);return a}),i.push(o)}return new Bf(i,r)}}let YL=q.widget({widget:new class extends $s{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),XL=q.mark({class:"cm-snippetField"});class Ar{constructor(e,t){this.ranges=e,this.active=t,this.deco=q.set(e.map(i=>(i.from==i.to?YL:XL).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let r=i.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(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const qs=Q.define({map(n,e){return n&&n.map(e)}}),QL=Q.define(),Ls=ut.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(qs))return t.value;if(t.is(QL)&&n)return new Ar(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>B.decorations.from(n,e=>e?e.deco:q.none)});function zf(n,e){return T.create(n.filter(t=>t.field==e).map(t=>T.range(t.from,t.to)))}function ZL(n){let e=Bf.parse(n);return(t,i,r,s)=>{let{text:o,ranges:l}=e.instantiate(t.state,r),{main:a}=t.state.selection,c={changes:{from:r,to:s==a.from?a.to:s,insert:ne.of(o)},scrollIntoView:!0,annotations:i?[Nf.of(i),Ce.userEvent.of("input.complete")]:void 0};if(l.length&&(c.selection=zf(l,0)),l.some(h=>h.field>0)){let h=new Ar(l,0),u=c.effects=[qs.of(h)];t.state.field(Ls,!1)===void 0&&u.push(Q.appendConfig.of([Ls,rP,sP,ew]))}t.dispatch(t.state.update(c))}}function tw(n){return({state:e,dispatch:t})=>{let i=e.field(Ls,!1);if(!i||n<0&&i.active==0)return!1;let r=i.active+n,s=n>0&&!i.ranges.some(o=>o.field==r+n);return t(e.update({selection:zf(i.ranges,r),effects:qs.of(s?null:new Ar(i.ranges,r)),scrollIntoView:!0})),!0}}const eP=({state:n,dispatch:e})=>n.field(Ls,!1)?(e(n.update({effects:qs.of(null)})),!0):!1,tP=tw(1),nP=tw(-1),iP=[{key:"Tab",run:tP,shift:nP},{key:"Escape",run:eP}],ug=z.define({combine(n){return n.length?n[0]:iP}}),rP=Fi.highest(Aa.compute([ug],n=>n.facet(ug)));function dB(n,e){return{...e,apply:ZL(n)}}const sP=B.domEventHandlers({mousedown(n,e){let t=e.state.field(Ls,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let r=t.ranges.find(s=>s.from<=i&&s.to>=i);return!r||r.field==t.active?!1:(e.dispatch({selection:zf(t.ranges,r.field),effects:qs.of(t.ranges.some(s=>s.field>r.field)?new Ar(t.ranges,r.field):null),scrollIntoView:!0}),!0)}}),Ps={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},xi=Q.define({map(n,e){let t=e.mapPos(n,-1,qe.TrackAfter);return t??void 0}}),Hf=new class extends ei{};Hf.startSide=1;Hf.endSide=-1;const nw=ut.define({create(){return X.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(xi)&&(n=n.update({add:[Hf.range(t.value,t.value+1)]}));return n}});function oP(){return[aP,nw]}const zc="()[]{}<>«»»«[]{}";function iw(n){for(let e=0;e<zc.length;e+=2)if(zc.charCodeAt(e)==n)return zc.charAt(e+1);return rf(n<128?n:n+1)}function rw(n,e){return n.languageDataAt("closeBrackets",e)[0]||Ps}const lP=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),aP=B.inputHandler.of((n,e,t,i)=>{if((lP?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let r=n.state.selection.main;if(i.length>2||i.length==2&&rn(gt(i,0))==1||e!=r.from||t!=r.to)return!1;let s=uP(n.state,i);return s?(n.dispatch(s),!0):!1}),cP=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=rw(n,n.selection.main.head).brackets||Ps.brackets,r=null,s=n.changeByRange(o=>{if(o.empty){let l=fP(n.doc,o.head);for(let a of i)if(a==l&&Pa(n.doc,o.head)==iw(gt(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:T.cursor(o.head-a.length)}}return{range:r=o}});return r||e(n.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!r},hP=[{key:"Backspace",run:cP}];function uP(n,e){let t=rw(n,n.selection.main.head),i=t.brackets||Ps.brackets;for(let r of i){let s=iw(gt(r,0));if(e==r)return s==r?mP(n,r,i.indexOf(r+r+r)>-1,t):dP(n,r,s,t.before||Ps.before);if(e==s&&sw(n,n.selection.main.from))return pP(n,r,s)}return null}function sw(n,e){let t=!1;return n.field(nw).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function Pa(n,e){let t=n.sliceString(e,e+2);return t.slice(0,rn(gt(t,0)))}function fP(n,e){let t=n.sliceString(e-2,e);return rn(gt(t,0))==t.length?t:t.slice(1)}function dP(n,e,t,i){let r=null,s=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:xi.of(o.to+e.length),range:T.range(o.anchor+e.length,o.head+e.length)};let l=Pa(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:xi.of(o.head+e.length),range:T.cursor(o.head+e.length)}:{range:r=o}});return r?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function pP(n,e,t){let i=null,r=n.changeByRange(s=>s.empty&&Pa(n.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:T.cursor(s.head+t.length)}:i={range:s});return i?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function mP(n,e,t,i){let r=i.stringPrefixes||Ps.stringPrefixes,s=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:xi.of(l.to+e.length),range:T.range(l.anchor+e.length,l.head+e.length)};let a=l.head,c=Pa(n.doc,a),h;if(c==e){if(fg(n,a))return{changes:{insert:e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)};if(sw(n,a)){let f=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+f.length,insert:f},range:T.cursor(a+f.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(h=dg(n,a-2*e.length,r))>-1&&fg(n,h))return{changes:{insert:e+e+e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)};if(n.charCategorizer(a)(c)!=ge.Word&&dg(n,a,r)>-1&&!gP(n,a,e,r))return{changes:{insert:e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)}}return{range:s=l}});return s?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fg(n,e){let t=ht(n).resolveInner(e+1);return t.parent&&t.from==e}function gP(n,e,t,i){let r=ht(n).resolveInner(e,-1),s=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(r.from,Math.min(r.to,r.from+t.length+s)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=r.firstChild;for(;h&&h.from==r.from&&h.to-h.from>t.length+a;){if(n.sliceDoc(h.to-t.length,h.to)==t)return!1;h=h.firstChild}return!0}let c=r.to==e&&r.parent;if(!c)break;r=c}return!1}function dg(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=ge.Word)return e;for(let r of t){let s=e-r.length;if(n.sliceDoc(s,e)==r&&i(n.sliceDoc(s-1,s))!=ge.Word)return s}return-1}function yP(n={}){return[JL,it,Ie.of(n),qL,xP,ew]}const bP=[{key:"Ctrl-Space",run:Bc},{mac:"Alt-`",run:Bc},{mac:"Alt-i",run:Bc},{key:"Escape",run:WL},{key:"ArrowDown",run:No(!0)},{key:"ArrowUp",run:No(!1)},{key:"PageDown",run:No(!0,"page")},{key:"PageUp",run:No(!1,"page")},{key:"Enter",run:VL}],xP=Fi.highest(Aa.computeN([Ie],n=>n.facet(Ie).defaultKeymap?[bP]:[])),ow="cm-adf-readonly",lw={"&":{backgroundColor:"var(--paper)",color:"var(--ink)"},[`&.${ow}`]:{backgroundColor:"var(--paper-sunken)"},".cm-content":{caretColor:"var(--ink)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--ink)"},".cm-content ::selection, &.cm-focused .cm-selectionBackground, .cm-selectionBackground":{backgroundColor:"var(--selection) !important"},".cm-gutters":{backgroundColor:"transparent",color:"var(--ink-faint)",border:"none"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--ink) 4%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--ink)"},".cm-selectionMatch":{backgroundColor:"var(--tint)"},"&.cm-focused .cm-matchingBracket":{backgroundColor:"var(--tint)",outline:"1px solid var(--rule-strong)"},"&.cm-focused .cm-nonmatchingBracket":{color:"var(--status-deprecated)"},".cm-searchMatch":{backgroundColor:"var(--status-draft-bg)",outline:"1px solid var(--rule-strong)"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"var(--selection)"},".cm-foldPlaceholder":{backgroundColor:"var(--paper-sunken)",border:"1px solid var(--rule)",color:"var(--ink-faint)"},".cm-panels":{backgroundColor:"var(--paper-raised)",color:"var(--ink)"},".cm-panels.cm-panels-top":{borderBottom:"1px solid var(--rule)"},".cm-panels.cm-panels-bottom":{borderTop:"1px solid var(--rule)"},".cm-tooltip":{backgroundColor:"var(--paper-raised)",color:"var(--ink)",border:"1px solid var(--rule-strong)",borderRadius:"3px"},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:"var(--tint)",color:"var(--ink)"}},wP={fg:"#24292e",comment:"#6a737d",keyword:"#d73a49",string:"#032f62",constant:"#005cc5",entity:"#6f42c1",tag:"#22863a",variable:"#e36209",regexp:"#22863a",invalid:"#b31d28",inserted:"#22863a",deleted:"#b31d28",heading:"#005cc5"},kP={fg:"#adbac7",comment:"#768390",keyword:"#f47067",string:"#96d0ff",constant:"#6cb6ff",entity:"#dcbdfb",tag:"#8ddb8c",variable:"#f69d50",regexp:"#8ddb8c",invalid:"#ff938a",inserted:"#8ddb8c",deleted:"#ff938a",heading:"#6cb6ff"};function aw(n){return Ra.define([{tag:[O.comment,O.lineComment,O.blockComment,O.docComment],color:n.comment},{tag:[O.keyword,O.operatorKeyword,O.controlKeyword,O.definitionKeyword,O.moduleKeyword,O.modifier,O.operator,O.self],color:n.keyword},{tag:[O.string,O.special(O.string),O.character,O.docString],color:n.string},{tag:[O.regexp,O.escape],color:n.regexp},{tag:[O.number,O.integer,O.float,O.bool,O.null,O.atom,O.unit,O.constant(O.name),O.standard(O.name),O.propertyName,O.meta,O.processingInstruction],color:n.constant},{tag:[O.function(O.variableName),O.function(O.propertyName),O.definition(O.function(O.variableName)),O.typeName,O.className,O.namespace,O.attributeName,O.macroName],color:n.entity},{tag:[O.tagName,O.angleBracket],color:n.tag},{tag:[O.definition(O.variableName),O.labelName],color:n.variable},{tag:[O.variableName,O.punctuation,O.bracket,O.content],color:n.fg},{tag:O.heading,color:n.heading,fontWeight:"600"},{tag:O.strong,fontWeight:"600"},{tag:O.emphasis,fontStyle:"italic"},{tag:O.strikethrough,textDecoration:"line-through"},{tag:[O.link,O.url],color:n.string,textDecoration:"underline"},{tag:O.inserted,color:n.inserted},{tag:O.deleted,color:n.deleted},{tag:O.changed,color:n.variable},{tag:O.invalid,color:n.invalid}])}const pg=[B.theme(lw,{dark:!1}),r1(aw(wP))],mg=[B.theme(lw,{dark:!0}),r1(aw(kP))],vP=B.editorAttributes.of({class:ow}),SP={js:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript()),jsx:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({jsx:!0})),ts:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({typescript:!0})),tsx:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({jsx:!0,typescript:!0})),py:()=>tt(()=>import("./index-B5FYMbFc.js"),__vite__mapDeps([15,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.python()),html:()=>tt(()=>import("./index-DBFkrLao.js"),__vite__mapDeps([16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.html()),css:()=>tt(()=>import("./index-nM_Q5x7Q.js"),__vite__mapDeps([17,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.css()),json:()=>tt(()=>import("./index-DS9H-PJI.js"),__vite__mapDeps([18,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.json()),yaml:()=>tt(()=>import("./index-B5Eot_tL.js"),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.yaml()),yml:()=>tt(()=>import("./index-B5Eot_tL.js"),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.yaml()),sql:()=>tt(()=>import("./index-BQIEMvvt.js"),__vite__mapDeps([20,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.sql()),xml:()=>tt(()=>import("./index-Ca6bEWGu.js"),__vite__mapDeps([21,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.xml()),md:()=>tt(()=>import("./index-DkhbLs9K.js"),__vite__mapDeps([22,16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.markdown()),markdown:()=>tt(()=>import("./index-DkhbLs9K.js"),__vite__mapDeps([22,16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.markdown())};async function CP(n){const e=SP[n];return e?e():null}const MP=250;function gg(n){return n?[ee.readOnly.of(!0),vP]:ee.readOnly.of(!1)}function cw({filePath:n,content:e,onChange:t,readOnly:i,lineWrap:r=!0,flushRef:s}){const o=M.useRef(null),l=M.useRef(null),a=M.useRef(new Jn),c=M.useRef(new Jn),h=M.useRef(new Jn),u=M.useRef(new Jn),f=M.useRef(!1),d=M.useRef(t);d.current=t;const p=tn(k=>k.theme),m=M.useRef(null),g=M.useRef(!1),y=M.useRef(null),b=M.useCallback(()=>{m.current&&clearTimeout(m.current),m.current=null,g.current=!1},[]),x=M.useCallback(()=>{if(m.current&&clearTimeout(m.current),m.current=null,!g.current)return;g.current=!1;const k=l.current;if(!k)return;const w=k.state.doc.toString();y.current=w,d.current(w)},[]);return M.useEffect(()=>{if(s)return s.current=x,()=>{s.current=null}},[s,x]),M.useEffect(()=>{if(!o.current)return;const k=p==="dark"||p==="system"&&window.matchMedia("(prefers-color-scheme: dark)").matches,w=ee.create({doc:e,extensions:[DN(),pN(),LN(),_I(),EI(),bI(),oP(),yP(),Q2(),Aa.of([...q2,...ZI,...xL,...hP,K2]),a.current.of(k?mg:pg),c.current.of([]),h.current.of(gg(!!i)),u.current.of(r?B.lineWrapping:[]),B.updateListener.of(L=>{!L.docChanged||f.current||(g.current=!0,m.current&&clearTimeout(m.current),m.current=setTimeout(x,MP))})]}),C=new B({state:w,parent:o.current});l.current=C;let v=!1;y.current=e;const D=n.split(".").pop()?.toLowerCase()??"";return CP(D).then(L=>{L&&!v&&C.dispatch({effects:c.current.reconfigure(L)})}),()=>{x(),v=!0,C.destroy(),l.current=null}},[n]),M.useEffect(()=>{const k=l.current;k&&e!==y.current&&(y.current=e,b(),f.current=!0,k.dispatch({changes:{from:0,to:k.state.doc.length,insert:e}}),f.current=!1)},[e,b]),M.useEffect(()=>{const k=l.current;if(!k)return;const w=C=>{l.current===k&&k.dispatch({effects:a.current.reconfigure(C?mg:pg)})};if(p==="system"){const C=window.matchMedia("(prefers-color-scheme: dark)");w(C.matches);const v=D=>{l.current===k&&w(D.matches)};return C.addEventListener("change",v),()=>C.removeEventListener("change",v)}else w(p==="dark")},[p,n]),M.useEffect(()=>{const k=l.current;k&&k.dispatch({effects:h.current.reconfigure(gg(!!i))})},[i]),M.useEffect(()=>{const k=l.current;k&&k.dispatch({effects:u.current.reconfigure(r?B.lineWrapping:[])})},[r]),S.jsx("div",{ref:o,className:"cm-editor-container"})}const Hc=!1,uu=128e3,TP=512e3,AP=250;function EP({content:n,onChange:e,active:t,onEditorChange:i,flushRef:r,shouldGate:s,onRendered:o}){const l=M.useRef(n);l.current=n;const a=M.useRef(e);a.current=e;const c=M.useRef(o);c.current=o;const[h]=M.useState(()=>l.current.length>uu),u=M.useRef(!1),f=M.useRef(!1),d=M.useRef(null),p=M.useRef(null),m=M.useRef(null),g=M.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null,m.current=null},[]),y=M.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null;const k=m.current;m.current=null,k?.()},[]);M.useEffect(()=>(r.current=y,()=>{r.current=null,y()}),[r,y]);const b=M.useCallback((k,w)=>{const C=w.replace(/adf-file:\/\/([^\s)>"'\]]+(?:\s[^\s)>"'\]]+)*)/g,(v,D)=>"adf-file://"+D.replace(/ /g,"%20"));try{k.commands.setContent(C,{contentType:"markdown"});const v=k.getHTML()}catch(v){console.error("[MarkdownEditor] setContent failed:",v);try{const D=w.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>").replace(/\*(.*?)\*/g,"<em>$1</em>").replace(/\n/g,"<br>");k.commands.setContent(D)}catch(D){console.error("[MarkdownEditor] All setContent methods failed:",D)}}},[]),x=HA({immediatelyRender:!h,extensions:nR(),content:"",onCreate:({editor:k})=>{const w=l.current;w&&(d.current=w,f.current=!0,b(k,w),f.current=!1),c.current()},onUpdate:({editor:k})=>{f.current||(m.current=()=>{if(k.isDestroyed)return;const w=k.getMarkdown();d.current=w,a.current(w)},p.current&&clearTimeout(p.current),p.current=setTimeout(y,AP))},editorProps:{attributes:{class:"tiptap"}}});return M.useEffect(()=>(i(x),()=>i(null)),[x,i]),M.useEffect(()=>{if(!t||!x||x.isDestroyed||n===d.current||s(n))return;d.current=n,g(),u.current=!0;const k=setTimeout(()=>{if(u.current=!1,x.isDestroyed)return;const w=performance.now();f.current=!0,b(x,n||""),f.current=!1,console.log(`[PERF:renderer] MarkdownEditor.setContent: ${(performance.now()-w).toFixed(1)}ms (chars=${n?.length??0})`),c.current()},0);return()=>{u.current=!1,clearTimeout(k)}},[n,t,x,b,g,s]),M.useEffect(()=>{t&&x&&!x.isDestroyed&&!u.current&&o()}),S.jsx(Xy,{editor:x})}function OP({filePath:n,content:e,onChange:t,flushRef:i}){const r=e||"",s=r.length>uu,[o,l]=M.useState(s),[a,c]=M.useState(!s),[h,u]=M.useState(null),[f,d]=M.useState(!1),[p,m]=M.useState(!1),g=M.useRef(null),y=M.useRef(null);M.useEffect(()=>{if(i)return i.current=()=>{g.current?.(),y.current?.()},()=>{i.current=null}},[i]);const b=M.useRef(!1),x=M.useRef(t);x.current=t;const k=M.useCallback(L=>{L&&(b.current=!0,d(!0)),m(!1),c(!0),l(!1)},[]),w=M.useCallback(()=>{if(g.current?.(),y.current?.(),!o){m(!1),l(!0);return}if(r.length>TP){m(!0);return}k(s)},[o,r.length,s,k]),C=M.useCallback(L=>{x.current(L)},[]),v=M.useCallback(L=>L.length<=uu?!1:b.current?(b.current=!1,!1):(l(!0),d(!1),!0),[]),D=M.useCallback(()=>d(!1),[]);return S.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-neutral-900",children:[S.jsx(iR,{editor:h,rawMode:o,onToggleRawMode:w}),f&&S.jsxs("div",{className:"px-4 py-1 text-[11px] text-blue-600 dark:text-blue-300 border-b border-neutral-200 dark:border-neutral-700 bg-blue-50 dark:bg-blue-900/30",children:["Rendering rich text (",Math.round(r.length/1024).toLocaleString()," KB) — the window will be unresponsive until it finishes."]}),p&&S.jsxs("div",{className:"flex items-center gap-2 px-4 py-1 text-[11px] text-neutral-600 dark:text-neutral-300 border-b border-neutral-200 dark:border-neutral-700 bg-amber-50 dark:bg-amber-900/20",children:[S.jsxs("span",{children:["Rendering ",Math.round(r.length/1024).toLocaleString()," KB as rich text will freeze the window for tens of seconds."]}),S.jsx("button",{onClick:()=>k(!0),className:"px-1.5 py-0.5 rounded border border-neutral-300 dark:border-neutral-600 hover:bg-neutral-100 dark:hover:bg-neutral-700",children:"Render anyway"}),S.jsx("button",{onClick:()=>m(!1),className:"px-1.5 py-0.5 rounded border border-transparent hover:bg-neutral-100 dark:hover:bg-neutral-700",children:"Cancel"})]}),s&&o&&!f&&!p&&S.jsxs("div",{className:"px-4 py-1 text-[11px] text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/50",children:["Large file (",Math.round(r.length/1024).toLocaleString()," KB) — showing source. Rich text would take tens of seconds to render."]}),S.jsxs("div",{className:o?"flex-1 overflow-hidden":"flex-1 overflow-y-auto",children:[o&&S.jsx(cw,{filePath:n,content:r,onChange:C,flushRef:y}),a&&S.jsx("div",{className:o?"hidden":void 0,children:S.jsx(EP,{content:r,onChange:C,active:!o,onEditorChange:u,flushRef:g,shouldGate:v,onRendered:D})})]})]})}function RP({filePath:n}){const e=n.split("/").pop()??n;return S.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-[var(--adf-ui-text-subtle)]",children:[S.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),S.jsx("polyline",{points:"14 2 14 8 20 8"})]}),S.jsx("span",{className:"text-sm font-medium text-neutral-500 dark:text-neutral-400",children:e}),S.jsx("span",{className:"text-xs",children:"Binary file cannot be edited"})]})}function DP(n){return window.adfApi?.platform==="web"?S.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-[var(--adf-ui-text-muted)]",children:"The live Computer view is available in the desktop app. Your agent’s computer continues running on the daemon."}):S.jsx(NP,{...n})}function NP({meta:n,reloadNonce:e}){const[t,i]=M.useState(()=>({phase:n.phase??(n.hostPort!=null?"ready":"absent"),detail:n.detail,hostPort:n.hostPort})),r=M.useCallback(async()=>{const o=await Qi()?.getBrowserSessionInfo({agentName:n.agentName,agentId:n.agentId});o&&i({phase:o.phase,detail:o.detail,hostPort:o.hostPort})},[n.agentName,n.agentId]);M.useEffect(()=>{i({phase:n.phase??(n.hostPort!=null?"ready":"absent"),detail:n.detail,hostPort:n.hostPort}),n.phase==="ready"&&n.hostPort==null&&r()},[n.phase,n.detail,n.hostPort,r]);const s=Pw();return M.useEffect(()=>{if(Qi()?.onContainerPhase)return Qi().onContainerPhase(o=>{o.containerName===n.containerName&&(o.phase==="ready"?(i(l=>({...l,phase:"ready",detail:void 0})),r()):i({phase:o.phase,detail:o.detail,hostPort:null}))})},[n.containerName,r,s]),t.phase==="ready"&&t.hostPort!=null?S.jsx(IP,{hostPort:t.hostPort,reloadNonce:e}):S.jsx(LP,{agentName:n.agentName,state:t,onRetry:r})}function IP({hostPort:n,reloadNonce:e}){const t=tn(o=>o.computerMatchTab),i=M.useRef(null),r=M.useRef(!1),s=`http://127.0.0.1:${n}/vnc.html?autoconnect=1&resize=${t?"remote":"scale"}&reconnect=1&reconnect_delay=2000&quality=9&compression=0`;return M.useEffect(()=>{const o=i.current;if(!o)return;r.current=!1;const l=()=>{r.current=!0};return o.addEventListener("dom-ready",l),()=>{r.current=!1,o.removeEventListener("dom-ready",l)}},[n]),M.useEffect(()=>{e&&r.current&&i.current?.reload()},[e]),S.jsx("webview",{ref:i,src:s,partition:"agent-browser",className:"h-full w-full"},n)}function LP({agentName:n,state:e,onRetry:t}){const i=tn(h=>h.openSettingsAt),{phase:r,detail:s}=e,o=r==="provisioning"||r==="starting",l=r==="failed",a=l?`${n}'s computer could not be set up`:r==="provisioning"?`Setting up ${n}'s computer`:r==="starting"?`Starting ${n}'s computer`:r==="stopped"?`${n}'s computer is stopped`:r==="ready"?`${n}'s display is not up yet`:`${n} has no computer yet`,c=l?"Nothing is left of the container. Rebuild it from Settings › Compute; the error is shown there too.":r==="provisioning"?`${s??"Installing packages"}. This takes a minute or two on first setup; the desktop appears here when it is ready.`:r==="starting"?"The container is starting; the desktop appears here in a few seconds.":r==="stopped"?"The container starts with the agent. Start the agent, or start the container from Settings › Compute.":r==="ready"?s??"The container is running but its display did not answer yet.":"The container is created the first time the agent starts.";return S.jsx("div",{className:"flex h-full w-full items-center justify-center bg-[var(--adf-ui-canvas)] p-6",children:S.jsxs("div",{className:"max-w-md text-center",children:[S.jsx("div",{className:`mx-auto mb-4 flex size-10 items-center justify-center rounded-full ${l?"bg-[var(--adf-ui-danger-subtle)] text-[var(--adf-ui-danger)]":"bg-[var(--adf-ui-surface)] text-[var(--adf-ui-text-muted)]"} ${o?"animate-pulse":""}`,children:S.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7","aria-hidden":"true",children:[S.jsx("path",{d:"m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"}),S.jsx("path",{d:"m4.5 7.7 7.5 4.2 7.5-4.2M12 12v9"})]})}),S.jsx("h3",{className:"text-sm font-semibold text-[var(--adf-ui-text)]",children:a}),S.jsx("p",{className:"mt-2 text-[12px] text-[var(--adf-ui-text-muted)]",children:c}),l&&s&&S.jsx("p",{className:"mt-3 rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-danger-subtle)] p-3 text-left font-mono text-[10px] text-[var(--adf-ui-text)] break-words",children:s}),S.jsxs("div",{className:"mt-4 flex justify-center gap-2",children:[(l||r==="stopped")&&S.jsx("button",{className:"rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-accent)] px-3 py-1.5 text-[11px] font-medium text-[var(--adf-ui-on-accent)] hover:bg-[var(--adf-ui-accent-hover)]",onClick:()=>i("compute"),children:"Open Settings › Compute"}),!o&&S.jsx("button",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] px-3 py-1.5 text-[11px] text-[var(--adf-ui-text)] hover:bg-[var(--adf-ui-surface-hover)]",onClick:t,children:"Check again"})]})]})})}const PP=new Set(["md","markdown"]),yg="adf-editor-line-wrap";function BP(n,e,t){const[i,r]=M.useState(!1),s=M.useRef(0);return M.useEffect(()=>{s.current=$f(Vf.getState()),r(!1)},[t,e,n]),M.useEffect(()=>{if(!(!n||e||i))return Vf.subscribe(o=>{$f(o)!==s.current&&r(!0)})},[n,e,i]),i}function zP(){const n=ve(E=>E.tabs),e=ve(E=>E.activeTabPath),t=ve(E=>E.setActiveTab),i=ve(E=>E.closeTab),r=ve(E=>E.updateTabContent),s=ve(E=>E.reloadBrowserTab),o=ve(E=>E.conflictFocusSeq),l=tn(uw),a=tn(E=>E.centerChatTabActive),c=tn(E=>E.setCenterChatTabActive),h=dt(E=>E.filePath),u=dt(E=>E.viewGeneration),f=dt(E=>E.runtimeId),d=l&&a,p=BP(l,d,h),m=M.useCallback(E=>{c(!1),t(E)},[t,c]),g=tn(E=>E.setChatPlacement),y=l?{active:a,unread:p,onSelect:()=>c(!0),onClose:()=>g("side")}:void 0;M.useEffect(()=>ve.subscribe((E,V)=>{E.activeTabPath&&E.activeTabPath!==V.activeTabPath&&E.tabs.length>=V.tabs.length&&!Ba()&&tn.getState().setCenterChatTabActive(!1)}),[]);const b=n.find(E=>E.path===e)??null,x=M.useRef(null),k=M.useRef(null),w=M.useRef(null),[C,v]=M.useState(()=>localStorage.getItem(yg)!=="0"),D=M.useCallback(()=>{v(E=>(localStorage.setItem(yg,E?"0":"1"),!E))},[]),L=M.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=null,k.current=null},[]),J=M.useCallback((E,V)=>{if(x.current&&clearTimeout(x.current),Ba()){k.current=null,x.current=null;return}const F=dt.getState().filePath,ie=yw(),Re=k.current,Pt=Re&&Re.path===E&&Re.owner===F?Re.base:bw(E);k.current={path:E,content:V,owner:F,base:Pt,view:ie},x.current=setTimeout(()=>{k.current=null,x.current=null,j(E,V,F,Pt,ie)},300)},[]),j=M.useCallback((E,V,F,ie,Re)=>xw(E,V,F,ie,Re),[]);M.useEffect(()=>ww(()=>{w.current?.();const E=k.current;if(x.current&&clearTimeout(x.current),x.current=null,k.current=null,E)return j(E.path,E.content,E.owner,E.base,E.view);const V=ve.getState(),F=V.tabs.find(ie=>ie.path===V.activeTabPath);if(F&&F.kind==="file"&&F.isDirty&&!F.conflict)return j(F.path,F.content,dt.getState().filePath)}),[j]),M.useEffect(()=>{kw()},[u,f]);const $=M.useCallback(E=>{const V=ve.getState().tabs.find(ie=>ie.path===E);if(V?.conflict&&!vw([E]))return;const F=k.current;F?.path===E&&(x.current&&clearTimeout(x.current),x.current=null,k.current=null,V?.conflict||j(F.path,F.content,F.owner,F.base,F.view)),i(E)},[i,j]),te=M.useCallback(async E=>{const V=ve.getState().tabs.find(ie=>ie.path===E);if(!V?.conflict)return;let F;if(V.conflict.content===null){const ie=E==="README.md"?await Qi()?.getDocument():await Qi()?.readInternalFile(E);if(ie?.content==null)return;F={content:ie.content,revision:ie.revision}}if(ve.getState().resolveTabConflict(E,"reload",F),E==="README.md"){const ie=ve.getState().tabs.find(Re=>Re.path===E)?.content;ie!==void 0&&dt.getState().setDocumentContent(ie)}},[]),G=M.useCallback(E=>{const V=ve.getState();V.resolveTabConflict(E,"keep");const F=V.tabs.find(ie=>ie.path===E)?.content;F!==void 0&&(E==="README.md"&&dt.getState().setDocumentContent(F),j(E,F,dt.getState().filePath))},[j]),Z=M.useCallback(E=>{const V=ve.getState().undoExternalReplace(E);V!==null&&(E==="README.md"&&dt.getState().setDocumentContent(V),j(E,V,dt.getState().filePath))},[j]),Oe=M.useCallback((E,V)=>{Ba()||(r(E,V),E==="README.md"&&dt.getState().setDocumentContent(V),J(E,V))},[r,J]);M.useEffect(()=>dt.subscribe((V,F)=>{if(V.documentContent!==F.documentContent){const ie=ve.getState(),Re=ie.tabs.find(Pt=>Pt.path==="README.md");if(Re&&Re.content!==V.documentContent){const Pt=V.documentRevision!==F.documentRevision?{revision:V.documentRevision,writer:V.documentWriter}:void 0;ie.updateTabFromExternal("README.md",V.documentContent,Pt)}}}),[]);const ft=M.useCallback(async()=>{const E=ve.getState();for(const V of Sw){if(V==="README.md"){const F=dt.getState();E.openTab("README.md",F.documentContent,!1,void 0,F.documentRevision);continue}try{const F=await Qi()?.readInternalFile(V);F?.content!=null&&E.openTab(V,F.binary?"":F.content,F.binary,F.mimeType,F.revision)}catch{}}E.setActiveTab("README.md")},[]);if(M.useEffect(()=>ve.subscribe((E,V)=>{const F=E.lastExternalWrite;!F||F===V.lastExternalWrite||k.current?.path===F.path&&L()}),[L]),M.useEffect(()=>()=>{x.current&&clearTimeout(x.current);const E=k.current;k.current=null,E&&j(E.path,E.content,E.owner,E.base,E.view)},[j]),M.useEffect(()=>ve.subscribe(E=>{const V=Cw();V&&Mw(V,E.tabs.filter(F=>F.kind==="file").map(F=>F.path),E.activeTabPath)}),[]),d)return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:null,onSelect:m,onClose:$,onReload:s,chatTab:y}),S.jsx("div",{className:"flex-1 min-h-0",children:S.jsx(Tw,{},`center:${h??""}`)})]});if(!b)return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:e,onSelect:m,onClose:$,chatTab:y}),S.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3",children:[S.jsx("span",{className:"text-[var(--adf-ui-text-subtle)] text-sm",children:"No file open"}),S.jsx("button",{onClick:ft,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:"Open core files"})]})]});const $i=PP.has(b.extension),Kt=b.kind==="file"&&b.isBinary?Aw(b.path,b.mimeType):null,Ks=b.kind==="file"&&!b.isBinary;return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:e,onSelect:m,onClose:$,onReload:s,chatTab:y}),b.conflict&&S.jsx(Ew,{what:b.path,writer:b.conflict.writer,focusSeq:o,onReload:()=>{te(b.path)},onKeep:()=>G(b.path),mine:b.content,theirs:b.conflict.content}),!b.conflict&&b.replaced&&S.jsx(Ow,{writer:b.replaced.writer,seq:b.replaced.seq,onUndo:()=>Z(b.path),onDismiss:()=>ve.getState().dismissExternalReplace(b.path)}),S.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[b.kind==="browser"&&b.browserMeta?S.jsx(DP,{meta:b.browserMeta,reloadNonce:b.browserMeta.reloadNonce},b.path):Kt?S.jsx(Rw,{filePath:b.path,mime:Kt},b.path):b.isBinary?S.jsx(RP,{filePath:b.path}):$i?S.jsx(OP,{filePath:b.path,content:b.content,flushRef:w,onChange:E=>Oe(b.path,E)},b.path):S.jsxs("div",{className:"relative h-full",children:[S.jsx(cw,{filePath:b.path,content:b.content,flushRef:w,onChange:E=>Oe(b.path,E),lineWrap:C},b.path),S.jsx("button",{onClick:D,title:C?"Line wrap on — click to disable":"Line wrap off — click to enable","aria-pressed":C,className:`absolute top-1.5 right-4 z-10 px-1.5 py-0.5 rounded text-[10px] font-mono font-medium border transition-colors ${C?"bg-blue-50 dark:bg-blue-900/40 border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-300":"bg-white/80 dark:bg-neutral-800/80 border-neutral-200 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-300"}`,children:"wrap"})]}),Ks&&S.jsxs("div",{"aria-label":`${b.content.length.toLocaleString()} characters — token count is an estimate`,className:"pointer-events-none absolute bottom-1.5 right-4 z-10 select-none px-1.5 py-0.5 rounded text-[10px] font-mono bg-white/80 dark:bg-neutral-800/80 border border-neutral-200 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)]",children:["~",Dw(Nw(b.content))," tokens"]})]})]})}const pB=Object.freeze(Object.defineProperty({__proto__:null,EditorPanel:zP},Symbol.toStringTag,{value:"Module"}));export{Ea as A,cB as B,Y1 as C,PN as D,B as E,ee as F,Yi as G,t1 as H,le as I,Kl as J,pB as K,nu as L,Jx as N,WN as P,Me as T,ct as a,Y as b,sB as c,aB as d,fB as e,hB as f,CL as g,ht as h,hI as i,T as j,lB as k,oB as l,uB as m,oI as n,dB as o,sI as p,nB as q,iB as r,eI as s,O as t,OI as u,Mt as v,ka as w,Fi as x,Aa as y,Vt as z};
161
+ `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new fL(this):new cL(this)}getCursor(e,t=0,i){let r=e.doc?e:ee.create({doc:e});return i==null&&(i=r.doc.length),this.regexp?Ki(this,r,t,i):qi(this,r,t,i)}}class U1{constructor(e){this.spec=e}}function lL(n,e,t){return(i,r,s,o)=>{if(t&&!t(i,r,s,o))return!1;let l=i>=o&&r<=o+s.length?s.slice(i-o,r-o):e.doc.sliceString(i,r);return n(l,e,i,r)}}function qi(n,e,t,i){let r;return n.wholeWord&&(r=aL(e.doc,e.charCategorizer(e.selection.main.head))),n.test&&(r=lL(n.test,e,r)),new vr(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),r)}function aL(n,e){return(t,i,r,s)=>((s>t||s+r.length<i)&&(s=Math.max(0,t-2),r=n.sliceString(s,Math.min(n.length,i+2))),(e(Xl(r,t-s))!=ge.Word||e(Ql(r,t-s))!=ge.Word)&&(e(Ql(r,i-s))!=ge.Word||e(Xl(r,i-s))!=ge.Word))}class cL extends U1{constructor(e){super(e)}nextMatch(e,t,i){let r=qi(this.spec,e,i,e.doc.length).nextOverlapping();if(r.done){let s=Math.min(e.doc.length,t+this.spec.unquoted.length);r=qi(this.spec,e,0,s).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==i?null:r.value}prevMatchInRange(e,t,i){for(let r=i;;){let s=Math.max(t,r-1e4-this.spec.unquoted.length),o=qi(this.spec,e,s,r),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(s==t)return null;r-=1e4}}prevMatch(e,t,i){let r=this.prevMatchInRange(e,0,t);return r||(r=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),r&&(r.from!=t||r.to!=i)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=qi(this.spec,e,0,e.doc.length),r=[];for(;!i.next().done;){if(r.length>=t)return null;r.push(i.value)}return r}highlight(e,t,i,r){let s=qi(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)r(s.value.from,s.value.to)}}function hL(n,e,t){return(i,r,s)=>(!t||t(i,r,s))&&n(s[0],e,i,r)}function Ki(n,e,t,i){let r;return n.wholeWord&&(r=uL(e.charCategorizer(e.selection.main.head))),n.test&&(r=hL(n.test,e,r)),new W1(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:r},t,i)}function Xl(n,e){return n.slice(Pe(n,e,!1),e)}function Ql(n,e){return n.slice(e,Pe(n,e))}function uL(n){return(e,t,i)=>!i[0].length||(n(Xl(i.input,i.index))!=ge.Word||n(Ql(i.input,i.index))!=ge.Word)&&(n(Ql(i.input,i.index+i[0].length))!=ge.Word||n(Xl(i.input,i.index+i[0].length))!=ge.Word)}class fL extends U1{nextMatch(e,t,i){let r=Ki(this.spec,e,i,e.doc.length).next();return r.done&&(r=Ki(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,i){for(let r=1;;r++){let s=Math.max(t,i-r*1e4),o=Ki(this.spec,e,s,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(s==t||l.from>s+10))return l;if(s==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let r=i.length;r>0;r--){let s=+i.slice(0,r);if(s>0&&s<e.match.length)return e.match[s]+i.slice(r)}return t})}matchAll(e,t){let i=Ki(this.spec,e,0,e.doc.length),r=[];for(;!i.next().done;){if(r.length>=t)return null;r.push(i.value)}return r}highlight(e,t,i,r){let s=Ki(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!s.next().done;)r(s.value.from,s.value.to)}}const Ns=Q.define(),Of=Q.define(),Qn=ut.define({create(n){return new Lc(hu(n).create(),null)},update(n,e){for(let t of e.effects)t.is(Ns)?n=new Lc(t.value.create(),n.panel):t.is(Of)&&(n=new Lc(n.query,t.value?Rf:null));return n},provide:n=>_l.from(n,e=>e.panel)});class Lc{constructor(e,t){this.query=e,this.panel=t}}const dL=q.mark({class:"cm-searchMatch"}),pL=q.mark({class:"cm-searchMatch cm-searchMatch-selected"}),mL=at.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(Qn))}update(n){let e=n.state.field(Qn);(e!=n.startState.field(Qn)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return q.none;let{view:t}=this,i=new gr;for(let r=0,s=t.visibleRanges,o=s.length;r<o;r++){let{from:l,to:a}=s[r];for(;r<o-1&&a>s[r+1].from-500;)a=s[++r].to;n.highlight(t.state,l,a,(c,h)=>{let u=t.state.selection.ranges.some(f=>f.from==c&&f.to==h);i.add(c,h,u?pL:dL)})}return i.finish()}},{decorations:n=>n.decorations});function Us(n){return e=>{let t=e.state.field(Qn,!1);return t&&t.query.spec.valid?n(e,t):J1(e)}}const Zl=Us((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let r=T.single(i.from,i.to),s=n.state.facet(Tr);return n.dispatch({selection:r,effects:[Df(n,i),s.scrollToMatch(r.main,n)],userEvent:"select.search"}),K1(n),!0}),ea=Us((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,r=e.prevMatch(t,i,i);if(!r)return!1;let s=T.single(r.from,r.to),o=n.state.facet(Tr);return n.dispatch({selection:s,effects:[Df(n,r),o.scrollToMatch(s.main,n)],userEvent:"select.search"}),K1(n),!0}),gL=Us((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:T.create(t.map(i=>T.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),yL=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:r}=t.main,s=[],o=0;for(let l=new vr(n.doc,n.sliceDoc(i,r));!l.next().done;){if(s.length>1e3)return!1;l.value.from==i&&(o=s.length),s.push(T.range(l.value.from,l.value.to))}return e(n.update({selection:T.create(s,o),userEvent:"select.search.matches"})),!0},rg=Us((n,{query:e})=>{let{state:t}=n,{from:i,to:r}=t.selection.main;if(t.readOnly)return!1;let s=e.nextMatch(t,i,i);if(!s)return!1;let o=s,l=[],a,c,h=[];o.from==i&&o.to==r&&(c=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:c}),o=e.nextMatch(t,o.from,o.to),h.push(B.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+".")));let u=n.state.changes(l);return o&&(a=T.single(o.from,o.to).map(u),h.push(Df(n,o)),h.push(t.facet(Tr).scrollToMatch(a.main,n))),n.dispatch({changes:u,selection:a,effects:h,userEvent:"input.replace"}),!0}),bL=Us((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state,1e9).map(r=>{let{from:s,to:o}=r;return{from:s,to:o,insert:e.getReplacement(r)}});if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:B.announce.of(i),userEvent:"input.replace.all"}),!0});function Rf(n){return n.state.facet(Tr).createPanel(n)}function hu(n,e){var t,i,r,s,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let c=n.facet(Tr);return new _1({search:((t=e?.literal)!==null&&t!==void 0?t:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(r=e?.literal)!==null&&r!==void 0?r:c.literal,regexp:(s=e?.regexp)!==null&&s!==void 0?s:c.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function q1(n){let e=jx(n,Rf);return e&&e.dom.querySelector("[main-field]")}function K1(n){let e=q1(n);e&&e==n.root.activeElement&&e.select()}const J1=n=>{let e=n.state.field(Qn,!1);if(e&&e.panel){let t=q1(n);if(t&&t!=n.root.activeElement){let i=hu(n.state,e.query.spec);i.valid&&n.dispatch({effects:Ns.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[Of.of(!0),e?Ns.of(hu(n.state,e.query.spec)):Q.appendConfig.of(vL)]});return!0},G1=n=>{let e=n.state.field(Qn,!1);if(!e||!e.panel)return!1;let t=jx(n,Rf);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Of.of(!1)}),!0},xL=[{key:"Mod-f",run:J1,scope:"editor search-panel"},{key:"F3",run:Zl,shift:ea,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Zl,shift:ea,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:G1,scope:"editor search-panel"},{key:"Mod-Shift-l",run:yL},{key:"Mod-Alt-g",run:G2},{key:"Mod-d",run:oL,preventDefault:!0}];class wL{constructor(e){this.view=e;let t=this.query=e.state.field(Qn).query.spec;this.commit=this.commit.bind(this),this.searchField=De("input",{value:t.search,placeholder:pt(e,"Find"),"aria-label":pt(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=De("input",{value:t.replace,placeholder:pt(e,"Replace"),"aria-label":pt(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=De("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=De("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=De("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(r,s,o){return De("button",{class:"cm-button",name:r,onclick:s,type:"button"},o)}this.dom=De("div",{onkeydown:r=>this.keydown(r),class:"cm-search"},[this.searchField,i("next",()=>Zl(e),[pt(e,"next")]),i("prev",()=>ea(e),[pt(e,"previous")]),i("select",()=>gL(e),[pt(e,"all")]),De("label",null,[this.caseField,pt(e,"match case")]),De("label",null,[this.reField,pt(e,"regexp")]),De("label",null,[this.wordField,pt(e,"by word")]),...e.state.readOnly?[]:[De("br"),this.replaceField,i("replace",()=>rg(e),[pt(e,"replace")]),i("replaceAll",()=>bL(e),[pt(e,"replace all")])],De("button",{name:"close",onclick:()=>G1(e),"aria-label":pt(e,"close"),type:"button"},["×"])])}commit(){let e=new _1({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Ns.of(e)}))}keydown(e){uN(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?ea:Zl)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),rg(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(Ns)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Tr).top}}function pt(n,e){return n.state.phrase(e)}const Ro=30,Do=/[\s\.,:;?!]/;function Df(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),r=n.state.doc.lineAt(t).to,s=Math.max(i.from,e-Ro),o=Math.min(r,t+Ro),l=n.state.sliceDoc(s,o);if(s!=i.from){for(let a=0;a<Ro;a++)if(!Do.test(l[a+1])&&Do.test(l[a])){l=l.slice(a);break}}if(o!=r){for(let a=l.length-1;a>l.length-Ro;a--)if(!Do.test(l[a-1])&&Do.test(l[a])){l=l.slice(0,a);break}}return B.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const kL=B.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),vL=[Qn,Fi.low(mL),kL];class Y1{constructor(e,t,i,r){this.state=e,this.pos=t,this.explicit=i,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ht(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),i=Math.max(t.from,this.pos-250),r=t.text.slice(i-t.from,this.pos-t.from),s=r.search(X1(e,!1));return s<0?null:{from:i+s,to:this.pos,text:r.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function sg(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function SL(n){let e=Object.create(null),t=Object.create(null);for(let{label:r}of n){e[r[0]]=!0;for(let s=1;s<r.length;s++)t[r[s]]=!0}let i=sg(e)+sg(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function CL(n){let e=n.map(r=>typeof r=="string"?{label:r}:r),[t,i]=e.every(r=>/^\w+$/.test(r.label))?[/\w*$/,/\w+$/]:SL(e);return r=>{let s=r.matchBefore(i);return s||r.explicit?{from:s?s.from:r.pos,options:e,validFor:t}:null}}function fB(n,e){return t=>{for(let i=ht(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class og{constructor(e,t,i,r){this.completion=e,this.source=t,this.match=i,this.score=r}}function Mi(n){return n.selection.main.from}function X1(n,e){var t;let{source:i}=n,r=e&&i[0]!="^",s=i[i.length-1]!="$";return!r&&!s?n:new RegExp(`${r?"^":""}(?:${i})${s?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const Nf=Nn.define();function ML(n,e,t,i){let{main:r}=n.selection,s=t-r.from,o=i-r.from;return{...n.changeByRange(l=>{if(l!=r&&t!=i&&n.sliceDoc(l.from+s,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+s,to:i==r.from?l.to:l.from+o,insert:a},range:T.cursor(l.from+s+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const lg=new WeakMap;function TL(n){if(!Array.isArray(n))return n;let e=lg.get(n);return e||lg.set(n,e=CL(n)),e}const ta=Q.define(),Is=Q.define();class AL{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 i=gt(e,t),r=rn(i);this.chars.push(i);let s=e.slice(t,t+r),o=s.toUpperCase();this.folded.push(gt(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:i,any:r,precise:s,byWord:o}=this;if(t.length==1){let b=gt(e,0),x=rn(b),k=x==e.length?0:-100;if(b!=t[0])if(b==i[0])k+=-200;else return null;return this.ret(k,[0,x])}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,c=0;if(l<0){for(let b=0,x=Math.min(e.length,200);b<x&&c<a;){let k=gt(e,b);(k==t[c]||k==i[c])&&(r[c++]=b),b+=rn(k)}if(c<a)return null}let h=0,u=0,f=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let b=0,x=Math.min(e.length,200),k=0;b<x&&u<a;){let w=gt(e,b);l<0&&(h<a&&w==t[h]&&(s[h++]=b),d<a&&(w==t[d]||w==i[d]?(d==0&&(p=b),m=b+1,d++):d=0));let C,v=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(C=rf(w))!=C.toLowerCase()?1:C!=C.toUpperCase()?2:0;(!b||v==1&&g||k==0&&v!=0)&&(t[u]==w||i[u]==w&&(f=!0)?o[u++]=b:o.length&&(y=!1)),k=v,b+=rn(w)}return u==a&&o[0]==0&&y?this.result(-100+(f?-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]):u==a?this.result(-100+(f?-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,i){let r=[],s=0;for(let o of t){let l=o+(this.astral?rn(gt(i,o)):1);s&&r[s-1]==o?r[s-1]=l:(r[s++]=o,r[s++]=l)}return this.ret(e-i.length,r)}}class EL{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),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const Ie=z.define({combine(n){return Cr(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:OL,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)=>i=>ag(e(i),t(i)),optionClass:(e,t)=>i=>ag(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function ag(n,e){return n?e?n+" "+e:n:e}function OL(n,e,t,i,r,s){let o=n.textDirection==ye.RTL,l=o,a=!1,c="top",h,u,f=e.left-r.left,d=r.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&f<Math.min(p,d)?l=!1:!l&&d<Math.min(p,f)&&(l=!0),p<=(l?f:d))h=Math.max(r.top,Math.min(t.top,r.bottom-m))-e.top,u=Math.min(400,l?f:d);else{a=!0,u=Math.min(400,(o?e.right:r.right-e.left)-30);let b=r.bottom-e.bottom;b>=m||b>e.top?h=t.bottom-e.top:(c="bottom",h=e.bottom-t.top)}let g=(e.bottom-e.top)/s.offsetHeight,y=(e.right-e.left)/s.offsetWidth;return{style:`${c}: ${h/g}px; max-width: ${u/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function RL(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(r=>"cm-completionIcon-"+r)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,r,s){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let c=0;c<s.length;){let h=s[c++],u=s[c++];h>a&&o.appendChild(document.createTextNode(l.slice(a,h)));let f=o.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(l.slice(h,u))),f.className="cm-completionMatchedText",a=u}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function Pc(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let r=Math.floor(e/t);return{from:r*t,to:(r+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class DL{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,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(Ie);this.optionContent=RL(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Pc(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:c}=e.state.field(t).open;for(let h=a.target,u;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(u=/-(\d+)$/.exec(h.id))&&+u[1]<c.length){this.applyCompletion(e,c[+u[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let c=e.state.field(this.stateField,!1);c&&c.tooltip&&e.state.facet(Ie).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Is.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 i=e.state.field(this.stateField),r=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=r){let{options:s,selected:o,disabled:l}=i.open;(!r.open||r.open.options!=s)&&(this.range=Pc(s.length,o,e.state.facet(Ie).maxRenderedOptions),this.showOptions(s,i.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 i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);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=Pc(t.options.length,t.selected,this.view.state.facet(Ie).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){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=>xt(this.view.state,l,"completion info")):(this.addInfoPane(o,r),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:r,destroy:s}=e;i.appendChild(r),this.infoDestroy=s||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,r=this.range.from;i;i=i.nextSibling,r++)i.nodeName!="LI"||!i.id?r--:r==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&IL(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=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(Ie).positionInfo(this.view,t,r,i,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,i){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=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:c}=l;if(c){let f=typeof c=="string"?c:c.name;if(f!=s&&(o>i.from||i.from==0))if(s=f,typeof c!="string"&&c.header)r.appendChild(c.header(c));else{let d=r.appendChild(document.createElement("completion-section"));d.textContent=f}}const h=r.appendChild(document.createElement("li"));h.id=t+"-"+o,h.setAttribute("role","option");let u=this.optionClass(l);u&&(h.className=u);for(let f of this.optionContent){let d=f(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&r.classList.add("cm-completionListIncompleteTop"),i.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 NL(n,e){return t=>new DL(t,n,e)}function IL(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),r=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/r:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/r)}function cg(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function LL(n,e){let t=[],i=null,r=null,s=h=>{t.push(h);let{section:u}=h.completion;if(u){i||(i=[]);let f=typeof u=="string"?u:u.name;i.some(d=>d.name==f)||i.push(typeof u=="string"?{name:f}:u)}},o=e.facet(Ie);for(let h of n)if(h.hasResult()){let u=h.result.getMatch;if(h.result.filter===!1)for(let f of h.result.options)s(new og(f,h.source,u?u(f):[],1e9-t.length));else{let f=e.sliceDoc(h.from,h.to),d,p=o.filterStrict?new EL(f):new AL(f);for(let m of h.result.options)if(d=p.match(m.label)){let g=m.displayLabel?u?u(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(s(new og(m,h.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(i){let h=Object.create(null),u=0,f=(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 i.sort(f))u-=1e5,h[d.name]=u;for(let d of t){let{section:p}=d.completion;p&&(d.score+=h[typeof p=="string"?p:p.name])}}let l=[],a=null,c=o.compareCompletions;for(let h of t.sort((u,f)=>f.score-u.score||c(u.completion,f.completion))){let u=h.completion;!a||a.label!=u.label||a.detail!=u.detail||a.type!=null&&u.type!=null&&a.type!=u.type||a.apply!=u.apply||a.boost!=u.boost?l.push(h):cg(h.completion)>cg(a)&&(l[l.length-1]=h),a=h.completion}return l}class Xi{constructor(e,t,i,r,s,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=r,this.selected=s,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Xi(this.options,hg(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,r,s,o){if(r&&!o&&e.some(c=>c.isPending))return r.setDisabled();let l=LL(e,t);if(!l.length)return r&&e.some(c=>c.isPending)?r.setDisabled():null;let a=t.facet(Ie).selectOnOpen?0:-1;if(r&&r.selected!=a&&r.selected!=-1){let c=r.options[r.selected].completion;for(let h=0;h<l.length;h++)if(l[h].completion==c){a=h;break}}return new Xi(l,hg(i,a),{pos:e.reduce((c,h)=>h.hasResult()?Math.min(c,h.from):c,1e8),create:$L,above:s.aboveCursor},r?r.timestamp:Date.now(),a,!1)}map(e){return new Xi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Xi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class na{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new na(HL,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Ie),s=(i.override||t.languageDataAt("autocomplete",Mi(t)).map(TL)).map(a=>(this.active.find(h=>h.source==a)||new Rt(a,this.active.some(h=>h.state!=0)?1:0)).update(e,i));s.length==this.active.length&&s.every((a,c)=>a==this.active[c])&&(s=this.active);let o=this.open,l=e.effects.some(a=>a.is(If));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||s.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!PL(s,this.active)||l?o=Xi.build(s,t,this.id,o,i,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 Rt(a.source,0):a));for(let a of e.effects)a.is(Z1)&&(o=o&&o.setSelected(a.value,this.id));return s==this.active&&o==this.open?this:new na(s,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?BL:zL}}function PL(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let r=t==n.length,s=i==e.length;if(r||s)return r==s;if(n[t++].result!=e[i++].result)return!1}}const BL={"aria-autocomplete":"list"},zL={};function hg(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const HL=[];function Q1(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(Nf);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}class Rt{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=Q1(e,t),r=this;(i&8||i&16&&this.touches(e))&&(r=new Rt(r.source,0)),i&4&&r.state==0&&(r=new Rt(this.source,1)),r=r.updateFor(e,i);for(let s of e.effects)if(s.is(ta))r=new Rt(r.source,1,s.value);else if(s.is(Is))r=new Rt(r.source,0);else if(s.is(If))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(Mi(e.state))}}class lr extends Rt{constructor(e,t,i,r,s,o){super(e,3,t),this.limit=i,this.result=r,this.from=s,this.to=o}hasResult(){return!0}updateFor(e,t){var i;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=Mi(e.state);if(l>o||!r||t&2&&(Mi(e.startState)==this.from||l<this.limit))return new Rt(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return FL(r.validFor,e.state,s,o)?new lr(this.source,this.explicit,a,r,s,o):r.update&&(r=r.update(r,s,o,new Y1(e.state,l,!1)))?new lr(this.source,this.explicit,a,r,r.from,(i=r.to)!==null&&i!==void 0?i:Mi(e.state)):new Rt(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new lr(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Rt(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function FL(n,e,t,i){if(!n)return!1;let r=e.sliceDoc(t,i);return typeof n=="function"?n(r,t,i,e):X1(n,!0).test(r)}const If=Q.define({map(n,e){return n.map(t=>t.map(e))}}),Z1=Q.define(),it=ut.define({create(){return na.start()},update(n,e){return n.update(e)},provide:n=>[Vx.from(n,e=>e.tooltip),B.contentAttributes.from(n,e=>e.attrs)]});function Lf(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(it).active.find(r=>r.source==e.source);return i instanceof lr?(typeof t=="string"?n.dispatch({...ML(n.state,t,i.from,i.to),annotations:Nf.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}const $L=NL(it,Lf);function No(n,e="option"){return t=>{let i=t.state.field(it,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(Ie).interactionDelay)return!1;let r=1,s;e=="page"&&(s=Wx(t,i.open.tooltip))&&(r=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+r*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Z1.of(l)}),!0}}const VL=n=>{let e=n.state.field(it,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(Ie).interactionDelay?!1:Lf(n,e.open.options[e.open.selected])},Bc=n=>n.state.field(it,!1)?(n.dispatch({effects:ta.of(!0)}),!0):!1,WL=n=>{let e=n.state.field(it,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Is.of(null)}),!0)};class jL{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const _L=50,UL=1e3,qL=at.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(it).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(it),t=n.state.facet(Ie);if(!n.selectionSet&&!n.docChanged&&n.startState.field(it)==e)return;let i=n.transactions.some(s=>{let o=Q1(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(i||o.context.abortOnDocChange&&n.docChanged||o.updates.length+n.transactions.length>_L&&Date.now()-o.time>UL){for(let l of o.context.abortListeners)try{l()}catch(a){xt(this.view.state,a)}o.context.abortListeners=null,this.running.splice(s--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(o=>o.is(ta)))&&(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 n.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:n}=this.view,e=n.field(it);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ie).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=Mi(e),i=new Y1(e,t,n.explicit,this.view),r=new jL(n,i);this.running.push(r),Promise.resolve(n.source(i)).then(s=>{r.context.aborted||(r.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:Is.of(null)}),xt(this.view.state,s)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ie).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Ie),i=this.view.state.field(it);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=Mi(s.updates.length?s.updates[0].startState:this.view.state),a=Math.min(l,s.done.from+(s.active.explicit?0:1)),c=new lr(s.active.source,s.active.explicit,a,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:l);for(let h of s.updates)c=c.update(h,t);if(c.hasResult()){e.push(c);continue}}let o=i.active.find(l=>l.source==s.active.source);if(o&&o.isPending)if(s.done==null){let l=new Rt(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||i.open&&i.open.disabled)&&this.view.dispatch({effects:If.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(it,!1);if(e&&e.tooltip&&this.view.state.facet(Ie).closeOnBlur){let t=e.open&&Wx(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Is.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:ta.of(!1)}),20),this.composing=0}}}),KL=typeof navigator=="object"&&/Win/.test(navigator.platform),JL=Fi.highest(B.domEventHandlers({keydown(n,e){let t=e.state.field(it,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(KL&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],r=t.active.find(o=>o.source==i.source),s=i.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(n.key)>-1&&Lf(e,i),!1}})),ew=B.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"},".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 GL{constructor(e,t,i,r){this.field=e,this.line=t,this.from=i,this.to=r}}class Pf{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,qe.TrackDel),i=e.mapPos(this.to,1,qe.TrackDel);return t==null||i==null?null:new Pf(this.field,t,i)}}class Bf{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],r=[t],s=e.doc.lineAt(t),o=/^\s*/.exec(s.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let u=0;u<h;u++)c+=e.facet(Ea);r.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Pf(a.field,r[a.line]+a.from,r[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],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]||"",c=-1,h=a.replace(/\\[{}]/g,u=>u[1]);for(let u=0;u<t.length;u++)(l!=null?t[u].seq==l:h&&t[u].name==h)&&(c=u);if(c<0){let u=0;for(;u<t.length&&(l==null||t[u].seq!=null&&t[u].seq<l);)u++;t.splice(u,0,{seq:l,name:h}),c=u;for(let f of r)f.field>=c&&f.field++}for(let u of r)if(u.line==i.length&&u.from>s.index){let f=s[2]?3+(s[1]||"").length:2;u.from-=f,u.to-=f}r.push(new GL(c,i.length,s.index,s.index+h.length)),o=o.slice(0,s.index)+a+o.slice(s.index+s[0].length)}o=o.replace(/\\([{}])/g,(l,a,c)=>{for(let h of r)h.line==i.length&&h.from>c&&(h.from--,h.to--);return a}),i.push(o)}return new Bf(i,r)}}let YL=q.widget({widget:new class extends $s{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),XL=q.mark({class:"cm-snippetField"});class Ar{constructor(e,t){this.ranges=e,this.active=t,this.deco=q.set(e.map(i=>(i.from==i.to?YL:XL).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let r=i.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(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const qs=Q.define({map(n,e){return n&&n.map(e)}}),QL=Q.define(),Ls=ut.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(qs))return t.value;if(t.is(QL)&&n)return new Ar(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>B.decorations.from(n,e=>e?e.deco:q.none)});function zf(n,e){return T.create(n.filter(t=>t.field==e).map(t=>T.range(t.from,t.to)))}function ZL(n){let e=Bf.parse(n);return(t,i,r,s)=>{let{text:o,ranges:l}=e.instantiate(t.state,r),{main:a}=t.state.selection,c={changes:{from:r,to:s==a.from?a.to:s,insert:ne.of(o)},scrollIntoView:!0,annotations:i?[Nf.of(i),Ce.userEvent.of("input.complete")]:void 0};if(l.length&&(c.selection=zf(l,0)),l.some(h=>h.field>0)){let h=new Ar(l,0),u=c.effects=[qs.of(h)];t.state.field(Ls,!1)===void 0&&u.push(Q.appendConfig.of([Ls,rP,sP,ew]))}t.dispatch(t.state.update(c))}}function tw(n){return({state:e,dispatch:t})=>{let i=e.field(Ls,!1);if(!i||n<0&&i.active==0)return!1;let r=i.active+n,s=n>0&&!i.ranges.some(o=>o.field==r+n);return t(e.update({selection:zf(i.ranges,r),effects:qs.of(s?null:new Ar(i.ranges,r)),scrollIntoView:!0})),!0}}const eP=({state:n,dispatch:e})=>n.field(Ls,!1)?(e(n.update({effects:qs.of(null)})),!0):!1,tP=tw(1),nP=tw(-1),iP=[{key:"Tab",run:tP,shift:nP},{key:"Escape",run:eP}],ug=z.define({combine(n){return n.length?n[0]:iP}}),rP=Fi.highest(Aa.compute([ug],n=>n.facet(ug)));function dB(n,e){return{...e,apply:ZL(n)}}const sP=B.domEventHandlers({mousedown(n,e){let t=e.state.field(Ls,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let r=t.ranges.find(s=>s.from<=i&&s.to>=i);return!r||r.field==t.active?!1:(e.dispatch({selection:zf(t.ranges,r.field),effects:qs.of(t.ranges.some(s=>s.field>r.field)?new Ar(t.ranges,r.field):null),scrollIntoView:!0}),!0)}}),Ps={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},xi=Q.define({map(n,e){let t=e.mapPos(n,-1,qe.TrackAfter);return t??void 0}}),Hf=new class extends ei{};Hf.startSide=1;Hf.endSide=-1;const nw=ut.define({create(){return X.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(xi)&&(n=n.update({add:[Hf.range(t.value,t.value+1)]}));return n}});function oP(){return[aP,nw]}const zc="()[]{}<>«»»«[]{}";function iw(n){for(let e=0;e<zc.length;e+=2)if(zc.charCodeAt(e)==n)return zc.charAt(e+1);return rf(n<128?n:n+1)}function rw(n,e){return n.languageDataAt("closeBrackets",e)[0]||Ps}const lP=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),aP=B.inputHandler.of((n,e,t,i)=>{if((lP?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let r=n.state.selection.main;if(i.length>2||i.length==2&&rn(gt(i,0))==1||e!=r.from||t!=r.to)return!1;let s=uP(n.state,i);return s?(n.dispatch(s),!0):!1}),cP=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=rw(n,n.selection.main.head).brackets||Ps.brackets,r=null,s=n.changeByRange(o=>{if(o.empty){let l=fP(n.doc,o.head);for(let a of i)if(a==l&&Pa(n.doc,o.head)==iw(gt(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:T.cursor(o.head-a.length)}}return{range:r=o}});return r||e(n.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!r},hP=[{key:"Backspace",run:cP}];function uP(n,e){let t=rw(n,n.selection.main.head),i=t.brackets||Ps.brackets;for(let r of i){let s=iw(gt(r,0));if(e==r)return s==r?mP(n,r,i.indexOf(r+r+r)>-1,t):dP(n,r,s,t.before||Ps.before);if(e==s&&sw(n,n.selection.main.from))return pP(n,r,s)}return null}function sw(n,e){let t=!1;return n.field(nw).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function Pa(n,e){let t=n.sliceString(e,e+2);return t.slice(0,rn(gt(t,0)))}function fP(n,e){let t=n.sliceString(e-2,e);return rn(gt(t,0))==t.length?t:t.slice(1)}function dP(n,e,t,i){let r=null,s=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:xi.of(o.to+e.length),range:T.range(o.anchor+e.length,o.head+e.length)};let l=Pa(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:xi.of(o.head+e.length),range:T.cursor(o.head+e.length)}:{range:r=o}});return r?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function pP(n,e,t){let i=null,r=n.changeByRange(s=>s.empty&&Pa(n.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:T.cursor(s.head+t.length)}:i={range:s});return i?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function mP(n,e,t,i){let r=i.stringPrefixes||Ps.stringPrefixes,s=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:xi.of(l.to+e.length),range:T.range(l.anchor+e.length,l.head+e.length)};let a=l.head,c=Pa(n.doc,a),h;if(c==e){if(fg(n,a))return{changes:{insert:e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)};if(sw(n,a)){let f=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+f.length,insert:f},range:T.cursor(a+f.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(h=dg(n,a-2*e.length,r))>-1&&fg(n,h))return{changes:{insert:e+e+e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)};if(n.charCategorizer(a)(c)!=ge.Word&&dg(n,a,r)>-1&&!gP(n,a,e,r))return{changes:{insert:e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)}}return{range:s=l}});return s?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fg(n,e){let t=ht(n).resolveInner(e+1);return t.parent&&t.from==e}function gP(n,e,t,i){let r=ht(n).resolveInner(e,-1),s=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(r.from,Math.min(r.to,r.from+t.length+s)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=r.firstChild;for(;h&&h.from==r.from&&h.to-h.from>t.length+a;){if(n.sliceDoc(h.to-t.length,h.to)==t)return!1;h=h.firstChild}return!0}let c=r.to==e&&r.parent;if(!c)break;r=c}return!1}function dg(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=ge.Word)return e;for(let r of t){let s=e-r.length;if(n.sliceDoc(s,e)==r&&i(n.sliceDoc(s-1,s))!=ge.Word)return s}return-1}function yP(n={}){return[JL,it,Ie.of(n),qL,xP,ew]}const bP=[{key:"Ctrl-Space",run:Bc},{mac:"Alt-`",run:Bc},{mac:"Alt-i",run:Bc},{key:"Escape",run:WL},{key:"ArrowDown",run:No(!0)},{key:"ArrowUp",run:No(!1)},{key:"PageDown",run:No(!0,"page")},{key:"PageUp",run:No(!1,"page")},{key:"Enter",run:VL}],xP=Fi.highest(Aa.computeN([Ie],n=>n.facet(Ie).defaultKeymap?[bP]:[])),ow="cm-adf-readonly",lw={"&":{backgroundColor:"var(--paper)",color:"var(--ink)"},[`&.${ow}`]:{backgroundColor:"var(--paper-sunken)"},".cm-content":{caretColor:"var(--ink)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--ink)"},".cm-content ::selection, &.cm-focused .cm-selectionBackground, .cm-selectionBackground":{backgroundColor:"var(--selection) !important"},".cm-gutters":{backgroundColor:"transparent",color:"var(--ink-faint)",border:"none"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--ink) 4%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--ink)"},".cm-selectionMatch":{backgroundColor:"var(--tint)"},"&.cm-focused .cm-matchingBracket":{backgroundColor:"var(--tint)",outline:"1px solid var(--rule-strong)"},"&.cm-focused .cm-nonmatchingBracket":{color:"var(--status-deprecated)"},".cm-searchMatch":{backgroundColor:"var(--status-draft-bg)",outline:"1px solid var(--rule-strong)"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"var(--selection)"},".cm-foldPlaceholder":{backgroundColor:"var(--paper-sunken)",border:"1px solid var(--rule)",color:"var(--ink-faint)"},".cm-panels":{backgroundColor:"var(--paper-raised)",color:"var(--ink)"},".cm-panels.cm-panels-top":{borderBottom:"1px solid var(--rule)"},".cm-panels.cm-panels-bottom":{borderTop:"1px solid var(--rule)"},".cm-tooltip":{backgroundColor:"var(--paper-raised)",color:"var(--ink)",border:"1px solid var(--rule-strong)",borderRadius:"3px"},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:"var(--tint)",color:"var(--ink)"}},wP={fg:"#24292e",comment:"#6a737d",keyword:"#d73a49",string:"#032f62",constant:"#005cc5",entity:"#6f42c1",tag:"#22863a",variable:"#e36209",regexp:"#22863a",invalid:"#b31d28",inserted:"#22863a",deleted:"#b31d28",heading:"#005cc5"},kP={fg:"#adbac7",comment:"#768390",keyword:"#f47067",string:"#96d0ff",constant:"#6cb6ff",entity:"#dcbdfb",tag:"#8ddb8c",variable:"#f69d50",regexp:"#8ddb8c",invalid:"#ff938a",inserted:"#8ddb8c",deleted:"#ff938a",heading:"#6cb6ff"};function aw(n){return Ra.define([{tag:[O.comment,O.lineComment,O.blockComment,O.docComment],color:n.comment},{tag:[O.keyword,O.operatorKeyword,O.controlKeyword,O.definitionKeyword,O.moduleKeyword,O.modifier,O.operator,O.self],color:n.keyword},{tag:[O.string,O.special(O.string),O.character,O.docString],color:n.string},{tag:[O.regexp,O.escape],color:n.regexp},{tag:[O.number,O.integer,O.float,O.bool,O.null,O.atom,O.unit,O.constant(O.name),O.standard(O.name),O.propertyName,O.meta,O.processingInstruction],color:n.constant},{tag:[O.function(O.variableName),O.function(O.propertyName),O.definition(O.function(O.variableName)),O.typeName,O.className,O.namespace,O.attributeName,O.macroName],color:n.entity},{tag:[O.tagName,O.angleBracket],color:n.tag},{tag:[O.definition(O.variableName),O.labelName],color:n.variable},{tag:[O.variableName,O.punctuation,O.bracket,O.content],color:n.fg},{tag:O.heading,color:n.heading,fontWeight:"600"},{tag:O.strong,fontWeight:"600"},{tag:O.emphasis,fontStyle:"italic"},{tag:O.strikethrough,textDecoration:"line-through"},{tag:[O.link,O.url],color:n.string,textDecoration:"underline"},{tag:O.inserted,color:n.inserted},{tag:O.deleted,color:n.deleted},{tag:O.changed,color:n.variable},{tag:O.invalid,color:n.invalid}])}const pg=[B.theme(lw,{dark:!1}),r1(aw(wP))],mg=[B.theme(lw,{dark:!0}),r1(aw(kP))],vP=B.editorAttributes.of({class:ow}),SP={js:()=>tt(()=>import("./index-CBCcou8F.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript()),jsx:()=>tt(()=>import("./index-CBCcou8F.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({jsx:!0})),ts:()=>tt(()=>import("./index-CBCcou8F.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({typescript:!0})),tsx:()=>tt(()=>import("./index-CBCcou8F.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({jsx:!0,typescript:!0})),py:()=>tt(()=>import("./index-DlQ8IXY2.js"),__vite__mapDeps([15,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.python()),html:()=>tt(()=>import("./index-BxrG4na5.js"),__vite__mapDeps([16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.html()),css:()=>tt(()=>import("./index-Cuc6TCV0.js"),__vite__mapDeps([17,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.css()),json:()=>tt(()=>import("./index-B0BKR-7b.js"),__vite__mapDeps([18,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.json()),yaml:()=>tt(()=>import("./index-C0ujp8ua.js"),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.yaml()),yml:()=>tt(()=>import("./index-C0ujp8ua.js"),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.yaml()),sql:()=>tt(()=>import("./index-BxmMf4oH.js"),__vite__mapDeps([20,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.sql()),xml:()=>tt(()=>import("./index-Ba28S-D0.js"),__vite__mapDeps([21,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.xml()),md:()=>tt(()=>import("./index-mW7p_CTU.js"),__vite__mapDeps([22,16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.markdown()),markdown:()=>tt(()=>import("./index-mW7p_CTU.js"),__vite__mapDeps([22,16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.markdown())};async function CP(n){const e=SP[n];return e?e():null}const MP=250;function gg(n){return n?[ee.readOnly.of(!0),vP]:ee.readOnly.of(!1)}function cw({filePath:n,content:e,onChange:t,readOnly:i,lineWrap:r=!0,flushRef:s}){const o=M.useRef(null),l=M.useRef(null),a=M.useRef(new Jn),c=M.useRef(new Jn),h=M.useRef(new Jn),u=M.useRef(new Jn),f=M.useRef(!1),d=M.useRef(t);d.current=t;const p=tn(k=>k.theme),m=M.useRef(null),g=M.useRef(!1),y=M.useRef(null),b=M.useCallback(()=>{m.current&&clearTimeout(m.current),m.current=null,g.current=!1},[]),x=M.useCallback(()=>{if(m.current&&clearTimeout(m.current),m.current=null,!g.current)return;g.current=!1;const k=l.current;if(!k)return;const w=k.state.doc.toString();y.current=w,d.current(w)},[]);return M.useEffect(()=>{if(s)return s.current=x,()=>{s.current=null}},[s,x]),M.useEffect(()=>{if(!o.current)return;const k=p==="dark"||p==="system"&&window.matchMedia("(prefers-color-scheme: dark)").matches,w=ee.create({doc:e,extensions:[DN(),pN(),LN(),_I(),EI(),bI(),oP(),yP(),Q2(),Aa.of([...q2,...ZI,...xL,...hP,K2]),a.current.of(k?mg:pg),c.current.of([]),h.current.of(gg(!!i)),u.current.of(r?B.lineWrapping:[]),B.updateListener.of(L=>{!L.docChanged||f.current||(g.current=!0,m.current&&clearTimeout(m.current),m.current=setTimeout(x,MP))})]}),C=new B({state:w,parent:o.current});l.current=C;let v=!1;y.current=e;const D=n.split(".").pop()?.toLowerCase()??"";return CP(D).then(L=>{L&&!v&&C.dispatch({effects:c.current.reconfigure(L)})}),()=>{x(),v=!0,C.destroy(),l.current=null}},[n]),M.useEffect(()=>{const k=l.current;k&&e!==y.current&&(y.current=e,b(),f.current=!0,k.dispatch({changes:{from:0,to:k.state.doc.length,insert:e}}),f.current=!1)},[e,b]),M.useEffect(()=>{const k=l.current;if(!k)return;const w=C=>{l.current===k&&k.dispatch({effects:a.current.reconfigure(C?mg:pg)})};if(p==="system"){const C=window.matchMedia("(prefers-color-scheme: dark)");w(C.matches);const v=D=>{l.current===k&&w(D.matches)};return C.addEventListener("change",v),()=>C.removeEventListener("change",v)}else w(p==="dark")},[p,n]),M.useEffect(()=>{const k=l.current;k&&k.dispatch({effects:h.current.reconfigure(gg(!!i))})},[i]),M.useEffect(()=>{const k=l.current;k&&k.dispatch({effects:u.current.reconfigure(r?B.lineWrapping:[])})},[r]),S.jsx("div",{ref:o,className:"cm-editor-container"})}const Hc=!1,uu=128e3,TP=512e3,AP=250;function EP({content:n,onChange:e,active:t,onEditorChange:i,flushRef:r,shouldGate:s,onRendered:o}){const l=M.useRef(n);l.current=n;const a=M.useRef(e);a.current=e;const c=M.useRef(o);c.current=o;const[h]=M.useState(()=>l.current.length>uu),u=M.useRef(!1),f=M.useRef(!1),d=M.useRef(null),p=M.useRef(null),m=M.useRef(null),g=M.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null,m.current=null},[]),y=M.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null;const k=m.current;m.current=null,k?.()},[]);M.useEffect(()=>(r.current=y,()=>{r.current=null,y()}),[r,y]);const b=M.useCallback((k,w)=>{const C=w.replace(/adf-file:\/\/([^\s)>"'\]]+(?:\s[^\s)>"'\]]+)*)/g,(v,D)=>"adf-file://"+D.replace(/ /g,"%20"));try{k.commands.setContent(C,{contentType:"markdown"});const v=k.getHTML()}catch(v){console.error("[MarkdownEditor] setContent failed:",v);try{const D=w.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>").replace(/\*(.*?)\*/g,"<em>$1</em>").replace(/\n/g,"<br>");k.commands.setContent(D)}catch(D){console.error("[MarkdownEditor] All setContent methods failed:",D)}}},[]),x=HA({immediatelyRender:!h,extensions:nR(),content:"",onCreate:({editor:k})=>{const w=l.current;w&&(d.current=w,f.current=!0,b(k,w),f.current=!1),c.current()},onUpdate:({editor:k})=>{f.current||(m.current=()=>{if(k.isDestroyed)return;const w=k.getMarkdown();d.current=w,a.current(w)},p.current&&clearTimeout(p.current),p.current=setTimeout(y,AP))},editorProps:{attributes:{class:"tiptap"}}});return M.useEffect(()=>(i(x),()=>i(null)),[x,i]),M.useEffect(()=>{if(!t||!x||x.isDestroyed||n===d.current||s(n))return;d.current=n,g(),u.current=!0;const k=setTimeout(()=>{if(u.current=!1,x.isDestroyed)return;const w=performance.now();f.current=!0,b(x,n||""),f.current=!1,console.log(`[PERF:renderer] MarkdownEditor.setContent: ${(performance.now()-w).toFixed(1)}ms (chars=${n?.length??0})`),c.current()},0);return()=>{u.current=!1,clearTimeout(k)}},[n,t,x,b,g,s]),M.useEffect(()=>{t&&x&&!x.isDestroyed&&!u.current&&o()}),S.jsx(Xy,{editor:x})}function OP({filePath:n,content:e,onChange:t,flushRef:i}){const r=e||"",s=r.length>uu,[o,l]=M.useState(s),[a,c]=M.useState(!s),[h,u]=M.useState(null),[f,d]=M.useState(!1),[p,m]=M.useState(!1),g=M.useRef(null),y=M.useRef(null);M.useEffect(()=>{if(i)return i.current=()=>{g.current?.(),y.current?.()},()=>{i.current=null}},[i]);const b=M.useRef(!1),x=M.useRef(t);x.current=t;const k=M.useCallback(L=>{L&&(b.current=!0,d(!0)),m(!1),c(!0),l(!1)},[]),w=M.useCallback(()=>{if(g.current?.(),y.current?.(),!o){m(!1),l(!0);return}if(r.length>TP){m(!0);return}k(s)},[o,r.length,s,k]),C=M.useCallback(L=>{x.current(L)},[]),v=M.useCallback(L=>L.length<=uu?!1:b.current?(b.current=!1,!1):(l(!0),d(!1),!0),[]),D=M.useCallback(()=>d(!1),[]);return S.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-neutral-900",children:[S.jsx(iR,{editor:h,rawMode:o,onToggleRawMode:w}),f&&S.jsxs("div",{className:"px-4 py-1 text-[11px] text-blue-600 dark:text-blue-300 border-b border-neutral-200 dark:border-neutral-700 bg-blue-50 dark:bg-blue-900/30",children:["Rendering rich text (",Math.round(r.length/1024).toLocaleString()," KB) — the window will be unresponsive until it finishes."]}),p&&S.jsxs("div",{className:"flex items-center gap-2 px-4 py-1 text-[11px] text-neutral-600 dark:text-neutral-300 border-b border-neutral-200 dark:border-neutral-700 bg-amber-50 dark:bg-amber-900/20",children:[S.jsxs("span",{children:["Rendering ",Math.round(r.length/1024).toLocaleString()," KB as rich text will freeze the window for tens of seconds."]}),S.jsx("button",{onClick:()=>k(!0),className:"px-1.5 py-0.5 rounded border border-neutral-300 dark:border-neutral-600 hover:bg-neutral-100 dark:hover:bg-neutral-700",children:"Render anyway"}),S.jsx("button",{onClick:()=>m(!1),className:"px-1.5 py-0.5 rounded border border-transparent hover:bg-neutral-100 dark:hover:bg-neutral-700",children:"Cancel"})]}),s&&o&&!f&&!p&&S.jsxs("div",{className:"px-4 py-1 text-[11px] text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/50",children:["Large file (",Math.round(r.length/1024).toLocaleString()," KB) — showing source. Rich text would take tens of seconds to render."]}),S.jsxs("div",{className:o?"flex-1 overflow-hidden":"flex-1 overflow-y-auto",children:[o&&S.jsx(cw,{filePath:n,content:r,onChange:C,flushRef:y}),a&&S.jsx("div",{className:o?"hidden":void 0,children:S.jsx(EP,{content:r,onChange:C,active:!o,onEditorChange:u,flushRef:g,shouldGate:v,onRendered:D})})]})]})}function RP({filePath:n}){const e=n.split("/").pop()??n;return S.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-[var(--adf-ui-text-subtle)]",children:[S.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),S.jsx("polyline",{points:"14 2 14 8 20 8"})]}),S.jsx("span",{className:"text-sm font-medium text-neutral-500 dark:text-neutral-400",children:e}),S.jsx("span",{className:"text-xs",children:"Binary file cannot be edited"})]})}function DP(n){return window.adfApi?.platform==="web"?S.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-[var(--adf-ui-text-muted)]",children:"The live Computer view is available in the desktop app. Your agent’s computer continues running on the daemon."}):S.jsx(NP,{...n})}function NP({meta:n,reloadNonce:e}){const[t,i]=M.useState(()=>({phase:n.phase??(n.hostPort!=null?"ready":"absent"),detail:n.detail,hostPort:n.hostPort})),r=M.useCallback(async()=>{const o=await Qi()?.getBrowserSessionInfo({agentName:n.agentName,agentId:n.agentId});o&&i({phase:o.phase,detail:o.detail,hostPort:o.hostPort})},[n.agentName,n.agentId]);M.useEffect(()=>{i({phase:n.phase??(n.hostPort!=null?"ready":"absent"),detail:n.detail,hostPort:n.hostPort}),n.phase==="ready"&&n.hostPort==null&&r()},[n.phase,n.detail,n.hostPort,r]);const s=Pw();return M.useEffect(()=>{if(Qi()?.onContainerPhase)return Qi().onContainerPhase(o=>{o.containerName===n.containerName&&(o.phase==="ready"?(i(l=>({...l,phase:"ready",detail:void 0})),r()):i({phase:o.phase,detail:o.detail,hostPort:null}))})},[n.containerName,r,s]),t.phase==="ready"&&t.hostPort!=null?S.jsx(IP,{hostPort:t.hostPort,reloadNonce:e}):S.jsx(LP,{agentName:n.agentName,state:t,onRetry:r})}function IP({hostPort:n,reloadNonce:e}){const t=tn(o=>o.computerMatchTab),i=M.useRef(null),r=M.useRef(!1),s=`http://127.0.0.1:${n}/vnc.html?autoconnect=1&resize=${t?"remote":"scale"}&reconnect=1&reconnect_delay=2000&quality=9&compression=0`;return M.useEffect(()=>{const o=i.current;if(!o)return;r.current=!1;const l=()=>{r.current=!0};return o.addEventListener("dom-ready",l),()=>{r.current=!1,o.removeEventListener("dom-ready",l)}},[n]),M.useEffect(()=>{e&&r.current&&i.current?.reload()},[e]),S.jsx("webview",{ref:i,src:s,partition:"agent-browser",className:"h-full w-full"},n)}function LP({agentName:n,state:e,onRetry:t}){const i=tn(h=>h.openSettingsAt),{phase:r,detail:s}=e,o=r==="provisioning"||r==="starting",l=r==="failed",a=l?`${n}'s computer could not be set up`:r==="provisioning"?`Setting up ${n}'s computer`:r==="starting"?`Starting ${n}'s computer`:r==="stopped"?`${n}'s computer is stopped`:r==="ready"?`${n}'s display is not up yet`:`${n} has no computer yet`,c=l?"Nothing is left of the container. Rebuild it from Settings › Compute; the error is shown there too.":r==="provisioning"?`${s??"Installing packages"}. This takes a minute or two on first setup; the desktop appears here when it is ready.`:r==="starting"?"The container is starting; the desktop appears here in a few seconds.":r==="stopped"?"The container starts with the agent. Start the agent, or start the container from Settings › Compute.":r==="ready"?s??"The container is running but its display did not answer yet.":"The container is created the first time the agent starts.";return S.jsx("div",{className:"flex h-full w-full items-center justify-center bg-[var(--adf-ui-canvas)] p-6",children:S.jsxs("div",{className:"max-w-md text-center",children:[S.jsx("div",{className:`mx-auto mb-4 flex size-10 items-center justify-center rounded-full ${l?"bg-[var(--adf-ui-danger-subtle)] text-[var(--adf-ui-danger)]":"bg-[var(--adf-ui-surface)] text-[var(--adf-ui-text-muted)]"} ${o?"animate-pulse":""}`,children:S.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7","aria-hidden":"true",children:[S.jsx("path",{d:"m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"}),S.jsx("path",{d:"m4.5 7.7 7.5 4.2 7.5-4.2M12 12v9"})]})}),S.jsx("h3",{className:"text-sm font-semibold text-[var(--adf-ui-text)]",children:a}),S.jsx("p",{className:"mt-2 text-[12px] text-[var(--adf-ui-text-muted)]",children:c}),l&&s&&S.jsx("p",{className:"mt-3 rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-danger-subtle)] p-3 text-left font-mono text-[10px] text-[var(--adf-ui-text)] break-words",children:s}),S.jsxs("div",{className:"mt-4 flex justify-center gap-2",children:[(l||r==="stopped")&&S.jsx("button",{className:"rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-accent)] px-3 py-1.5 text-[11px] font-medium text-[var(--adf-ui-on-accent)] hover:bg-[var(--adf-ui-accent-hover)]",onClick:()=>i("compute"),children:"Open Settings › Compute"}),!o&&S.jsx("button",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] px-3 py-1.5 text-[11px] text-[var(--adf-ui-text)] hover:bg-[var(--adf-ui-surface-hover)]",onClick:t,children:"Check again"})]})]})})}const PP=new Set(["md","markdown"]),yg="adf-editor-line-wrap";function BP(n,e,t){const[i,r]=M.useState(!1),s=M.useRef(0);return M.useEffect(()=>{s.current=$f(Vf.getState()),r(!1)},[t,e,n]),M.useEffect(()=>{if(!(!n||e||i))return Vf.subscribe(o=>{$f(o)!==s.current&&r(!0)})},[n,e,i]),i}function zP(){const n=ve(E=>E.tabs),e=ve(E=>E.activeTabPath),t=ve(E=>E.setActiveTab),i=ve(E=>E.closeTab),r=ve(E=>E.updateTabContent),s=ve(E=>E.reloadBrowserTab),o=ve(E=>E.conflictFocusSeq),l=tn(uw),a=tn(E=>E.centerChatTabActive),c=tn(E=>E.setCenterChatTabActive),h=dt(E=>E.filePath),u=dt(E=>E.viewGeneration),f=dt(E=>E.runtimeId),d=l&&a,p=BP(l,d,h),m=M.useCallback(E=>{c(!1),t(E)},[t,c]),g=tn(E=>E.setChatPlacement),y=l?{active:a,unread:p,onSelect:()=>c(!0),onClose:()=>g("side")}:void 0;M.useEffect(()=>ve.subscribe((E,V)=>{E.activeTabPath&&E.activeTabPath!==V.activeTabPath&&E.tabs.length>=V.tabs.length&&!Ba()&&tn.getState().setCenterChatTabActive(!1)}),[]);const b=n.find(E=>E.path===e)??null,x=M.useRef(null),k=M.useRef(null),w=M.useRef(null),[C,v]=M.useState(()=>localStorage.getItem(yg)!=="0"),D=M.useCallback(()=>{v(E=>(localStorage.setItem(yg,E?"0":"1"),!E))},[]),L=M.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=null,k.current=null},[]),J=M.useCallback((E,V)=>{if(x.current&&clearTimeout(x.current),Ba()){k.current=null,x.current=null;return}const F=dt.getState().filePath,ie=yw(),Re=k.current,Pt=Re&&Re.path===E&&Re.owner===F?Re.base:bw(E);k.current={path:E,content:V,owner:F,base:Pt,view:ie},x.current=setTimeout(()=>{k.current=null,x.current=null,j(E,V,F,Pt,ie)},300)},[]),j=M.useCallback((E,V,F,ie,Re)=>xw(E,V,F,ie,Re),[]);M.useEffect(()=>ww(()=>{w.current?.();const E=k.current;if(x.current&&clearTimeout(x.current),x.current=null,k.current=null,E)return j(E.path,E.content,E.owner,E.base,E.view);const V=ve.getState(),F=V.tabs.find(ie=>ie.path===V.activeTabPath);if(F&&F.kind==="file"&&F.isDirty&&!F.conflict)return j(F.path,F.content,dt.getState().filePath)}),[j]),M.useEffect(()=>{kw()},[u,f]);const $=M.useCallback(E=>{const V=ve.getState().tabs.find(ie=>ie.path===E);if(V?.conflict&&!vw([E]))return;const F=k.current;F?.path===E&&(x.current&&clearTimeout(x.current),x.current=null,k.current=null,V?.conflict||j(F.path,F.content,F.owner,F.base,F.view)),i(E)},[i,j]),te=M.useCallback(async E=>{const V=ve.getState().tabs.find(ie=>ie.path===E);if(!V?.conflict)return;let F;if(V.conflict.content===null){const ie=E==="README.md"?await Qi()?.getDocument():await Qi()?.readInternalFile(E);if(ie?.content==null)return;F={content:ie.content,revision:ie.revision}}if(ve.getState().resolveTabConflict(E,"reload",F),E==="README.md"){const ie=ve.getState().tabs.find(Re=>Re.path===E)?.content;ie!==void 0&&dt.getState().setDocumentContent(ie)}},[]),G=M.useCallback(E=>{const V=ve.getState();V.resolveTabConflict(E,"keep");const F=V.tabs.find(ie=>ie.path===E)?.content;F!==void 0&&(E==="README.md"&&dt.getState().setDocumentContent(F),j(E,F,dt.getState().filePath))},[j]),Z=M.useCallback(E=>{const V=ve.getState().undoExternalReplace(E);V!==null&&(E==="README.md"&&dt.getState().setDocumentContent(V),j(E,V,dt.getState().filePath))},[j]),Oe=M.useCallback((E,V)=>{Ba()||(r(E,V),E==="README.md"&&dt.getState().setDocumentContent(V),J(E,V))},[r,J]);M.useEffect(()=>dt.subscribe((V,F)=>{if(V.documentContent!==F.documentContent){const ie=ve.getState(),Re=ie.tabs.find(Pt=>Pt.path==="README.md");if(Re&&Re.content!==V.documentContent){const Pt=V.documentRevision!==F.documentRevision?{revision:V.documentRevision,writer:V.documentWriter}:void 0;ie.updateTabFromExternal("README.md",V.documentContent,Pt)}}}),[]);const ft=M.useCallback(async()=>{const E=ve.getState();for(const V of Sw){if(V==="README.md"){const F=dt.getState();E.openTab("README.md",F.documentContent,!1,void 0,F.documentRevision);continue}try{const F=await Qi()?.readInternalFile(V);F?.content!=null&&E.openTab(V,F.binary?"":F.content,F.binary,F.mimeType,F.revision)}catch{}}E.setActiveTab("README.md")},[]);if(M.useEffect(()=>ve.subscribe((E,V)=>{const F=E.lastExternalWrite;!F||F===V.lastExternalWrite||k.current?.path===F.path&&L()}),[L]),M.useEffect(()=>()=>{x.current&&clearTimeout(x.current);const E=k.current;k.current=null,E&&j(E.path,E.content,E.owner,E.base,E.view)},[j]),M.useEffect(()=>ve.subscribe(E=>{const V=Cw();V&&Mw(V,E.tabs.filter(F=>F.kind==="file").map(F=>F.path),E.activeTabPath)}),[]),d)return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:null,onSelect:m,onClose:$,onReload:s,chatTab:y}),S.jsx("div",{className:"flex-1 min-h-0",children:S.jsx(Tw,{},`center:${h??""}`)})]});if(!b)return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:e,onSelect:m,onClose:$,chatTab:y}),S.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3",children:[S.jsx("span",{className:"text-[var(--adf-ui-text-subtle)] text-sm",children:"No file open"}),S.jsx("button",{onClick:ft,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:"Open core files"})]})]});const $i=PP.has(b.extension),Kt=b.kind==="file"&&b.isBinary?Aw(b.path,b.mimeType):null,Ks=b.kind==="file"&&!b.isBinary;return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:e,onSelect:m,onClose:$,onReload:s,chatTab:y}),b.conflict&&S.jsx(Ew,{what:b.path,writer:b.conflict.writer,focusSeq:o,onReload:()=>{te(b.path)},onKeep:()=>G(b.path),mine:b.content,theirs:b.conflict.content}),!b.conflict&&b.replaced&&S.jsx(Ow,{writer:b.replaced.writer,seq:b.replaced.seq,onUndo:()=>Z(b.path),onDismiss:()=>ve.getState().dismissExternalReplace(b.path)}),S.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[b.kind==="browser"&&b.browserMeta?S.jsx(DP,{meta:b.browserMeta,reloadNonce:b.browserMeta.reloadNonce},b.path):Kt?S.jsx(Rw,{filePath:b.path,mime:Kt},b.path):b.isBinary?S.jsx(RP,{filePath:b.path}):$i?S.jsx(OP,{filePath:b.path,content:b.content,flushRef:w,onChange:E=>Oe(b.path,E)},b.path):S.jsxs("div",{className:"relative h-full",children:[S.jsx(cw,{filePath:b.path,content:b.content,flushRef:w,onChange:E=>Oe(b.path,E),lineWrap:C},b.path),S.jsx("button",{onClick:D,title:C?"Line wrap on — click to disable":"Line wrap off — click to enable","aria-pressed":C,className:`absolute top-1.5 right-4 z-10 px-1.5 py-0.5 rounded text-[10px] font-mono font-medium border transition-colors ${C?"bg-blue-50 dark:bg-blue-900/40 border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-300":"bg-white/80 dark:bg-neutral-800/80 border-neutral-200 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-300"}`,children:"wrap"})]}),Ks&&S.jsxs("div",{"aria-label":`${b.content.length.toLocaleString()} characters — token count is an estimate`,className:"pointer-events-none absolute bottom-1.5 right-4 z-10 select-none px-1.5 py-0.5 rounded text-[10px] font-mono bg-white/80 dark:bg-neutral-800/80 border border-neutral-200 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)]",children:["~",Dw(Nw(b.content))," tokens"]})]})]})}const pB=Object.freeze(Object.defineProperty({__proto__:null,EditorPanel:zP},Symbol.toStringTag,{value:"Module"}));export{Ea as A,cB as B,Y1 as C,PN as D,B as E,ee as F,Yi as G,t1 as H,le as I,Kl as J,pB as K,nu as L,Jx as N,WN as P,Me as T,ct as a,Y as b,sB as c,aB as d,fB as e,hB as f,CL as g,ht as h,hI as i,T as j,lB as k,oB as l,uB as m,oI as n,dB as o,sI as p,nB as q,iB as r,eI as s,O as t,OI as u,Mt as v,ka as w,Fi as x,Aa as y,Vt as z};