dsh-tiddlywiki 0.26.0 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -734,13 +734,13 @@ html[data-dsh-tw-active] .dshDesktopConversationSurface > :not([data-dsh-tw-view
734
734
  `;function d(){if(typeof document>`u`)return()=>{};let e=document.getElementById(l);e===null?(e=document.createElement(`style`),e.id=l,e.dataset.plugin=`dsh-tiddlywiki`,e.textContent=u,document.head.append(e)):e.textContent!==u&&(e.textContent=u);let t=String(Date.now())+`:`+Math.random().toString(36).slice(2);return e.dataset.instance=t,()=>{e?.dataset.instance===t&&e.remove()}}var f=class{open=!1;listeners=new Set;isOpen(){return this.open}toggle(){this.set(!this.open)}openPanel(){this.set(!0)}closePanel(){this.set(!1)}set(e){if(this.open!==e){this.open=e;for(let t of[...this.listeners])t(e)}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}};const p=`/dsh-tiddlywiki`,m=`${p}/tw/`,h=`${p}/status`,g=`${p}/get`,_=`${p}/render`,v=`${p}/note`,y=`${p}/edit`,b=`${p}/tags`,x=`${p}/recent`,S=`${p}/search`,C=`${p}/upload`,ee=`${p}/sync`,te=`${p}/restart`,ne=`${p}/session/summary`,w=`${p}/admin/state`,re=`${p}/admin/prompt`,T=`${p}/admin/info`,ie=`${p}/admin/config`,ae=`${p}/admin/restart`,oe=`${p}/admin/seeds`,se=`${p}/admin/seeds/run`,ce=`${p}/admin/seeds/remove`,le=`${p}/admin/wiki/location`,ue=`${p}/admin/wiki/switch`,de=`${p}/admin/wiki/reset`;function fe(e,t){if(e===null||e.ok!==!0)return{ok:!1,message:e?.error??e?.message??`HTTP ${t}`};let n=``;return typeof e.push==`string`&&e.push.length>0&&e.push!==`nothing to commit`&&(n=`(${e.push})`),e.changed===!0&&(n+=e.restarted===!0?`,TW 已重启`:`,TW 未自动重启`,typeof e.restartError==`string`&&e.restartError.length>0&&(n+=`(${e.restartError})`)),{ok:!0,message:`${e.message??`OK`}${n}`}}let pe;function me(){if(pe!==void 0&&Date.now()-pe.at<2e3)return pe.value;let e=(async()=>{try{let e=await fetch(h,{signal:AbortSignal.timeout(8e3)});return e.ok?await e.json():null}catch{return null}})();return pe={at:Date.now(),value:e},e.then(t=>{t===null&&pe?.value===e&&(pe=void 0)}),e}function he(){pe=void 0}const ge={showQuickNoteDock:!0,quickNoteMode:`native`,sidebarLabel:`TiddlyWiki`,tabLabel:`知识库`,showSessionTab:!0,showRightbarTab:!0,showQuickNote:!0,showPanelStatus:!0,showSyncButton:!0};let _e;const ve=new Set;function ye(e){return ve.add(e),()=>{ve.delete(e)}}function be(){_e=void 0,he();for(let e of[...ve])e()}function xe(){if(_e!==void 0&&Date.now()-_e.at<15e3)return _e.value;let e=(async()=>{let e=await me(),t=e?.ui;return e===null||t===void 0?ge:{showQuickNoteDock:t.showQuickNoteDock!==!1,quickNoteMode:t.quickNoteMode===`card`?`card`:`native`,sidebarLabel:typeof t.sidebarLabel==`string`&&t.sidebarLabel.trim().length>0?t.sidebarLabel.trim():`TiddlyWiki`,tabLabel:typeof t.tabLabel==`string`&&t.tabLabel.trim().length>0?t.tabLabel.trim():`知识库`,showSessionTab:t.showSessionTab!==!1,showRightbarTab:t.showRightbarTab!==!1,showQuickNote:t.showQuickNote!==!1,showPanelStatus:t.showPanelStatus!==!1,showSyncButton:t.showSyncButton!==!1}})();return _e={at:Date.now(),value:e},e}function Se(){let e=document.querySelector(`[data-pane="sidebar"], [class*="sidebarCol"], .dshDesktopUpstreamSidebar, .dshDesktopSidebarSurface`);if(e!==null)return e.querySelector(`[class*="logoRow"]`)?.parentElement??e.firstElementChild}function Ce(e){let t=e.querySelector(`button[class*="newSession"]`);if(t!==null)return t;for(let t of e.children)if(t instanceof HTMLButtonElement&&!t.matches(`[data-dsh-tw-entry]`))return t;let n=e.querySelector(`button[aria-label="新建会话"], button[aria-label="New Session"], button[aria-label*="新会话"], button[aria-label*="new session" i]`);return n===null?Array.from(e.querySelectorAll(`button`)).find(e=>!e.matches(`[data-dsh-tw-entry]`)&&/新会话|新建会话|new session/i.test(e.textContent??``)):n}function we(e,t){let n=document.createElement(`button`);n.type=`button`,n.dataset.dshTwEntry=``,n.className=`dsh-tw-entry`,n.setAttribute(`aria-label`,`TiddlyWiki 知识库`);let r=document.createElement(`span`);r.className=`dsh-tw-entry-icon`,r.innerHTML=`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 2.5h8a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"/><path d="M6 6h4M6 8.5h2.5"/></svg>`;let i=document.createElement(`span`);return i.className=`dsh-tw-entry-label`,i.textContent=t,n.append(r,i),n.addEventListener(`click`,()=>{e.toggle()}),{entry:n,labelEl:i}}function Te(e,t){try{let n=Ce(e);if(n===void 0)return!1;if(t.parentElement!==e){let r=n.closest(`[class*="logoRow"]`),i=r!==null&&r.parentElement===e?r:n,a=Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.matches(`[data-dsh-tw-entry], [data-dsh-atb-entry], [data-dsh-taskboard-entry], [data-dsh-ssh-entry]`)),o=a.length>0?a[0]??null:i.nextElementSibling;o!==null&&o.parentElement!==e&&(o=null),e.insertBefore(t,o)}return!0}catch(e){return console.error(`[dsh-tiddlywiki] sidebar entry placement failed:`,e),!1}}function Ee(e){let{entry:t,labelEl:n}=we(e,`TiddlyWiki`),r=!1,i=async()=>{let e=await xe();r||e.sidebarLabel.length===0||(n.textContent=e.sidebarLabel,t.setAttribute(`aria-label`,e.sidebarLabel))};i();let a=ye(()=>{i()}),o,s=!1,c,l=0,u=()=>{c!==void 0&&(clearInterval(c),c=void 0)},d=()=>{c===void 0&&(l=15,c=setInterval(()=>{f(),l--,(s||l<=0)&&u()},2e3))},f=()=>{if(o!==void 0&&!o.isConnected&&(m.disconnect(),o=void 0,s=!1,d()),s){if(document.body.contains(t))return;m.disconnect(),o=void 0,s=!1,d()}o??=Se(),o!==void 0&&(s=Te(o,t),s&&(u(),m.observe(o,{childList:!0,subtree:!0})))},p=new MutationObserver(()=>{f()});p.observe(document.body,{childList:!0,subtree:!0});let m=new MutationObserver(()=>{if(o===void 0||!o.isConnected){s=!1,d(),f();return}o.contains(t)||(s=Te(o,t))});d();let h=()=>{e.isOpen()?t.dataset.active=`true`:delete t.dataset.active},g=e.subscribe(h);return h(),f(),()=>{r=!0,clearInterval(c),p.disconnect(),m.disconnect(),g(),a(),t.remove()}}const De=`$:/palettes/CupertinoDark`,Oe=`$:/palettes/Vanilla`,ke=`data-ds-dark-theme`,Ae=`$:/palette`,je=new Set,Me=new WeakSet;let Ne=``,Pe=!0,Fe=De;function Ie(){try{let e=document.documentElement,t=document.body;if(t!==null&&t.hasAttribute(ke))return!0;if(e!==null){let t=e.style.getPropertyValue(`color-scheme`).trim().toLowerCase();if(t===`dark`)return!0;if(t===`light`)return!1}}catch{}try{return window.matchMedia(`(prefers-color-scheme: dark)`).matches}catch{return!1}}function Le(e){try{let t=e.wiki.getTiddlerText(Ae);return typeof t==`string`&&t.trim().length>0?t.trim():Oe}catch{return Oe}}function Re(e){try{let t=e.wiki.getTiddler(Le(e))?.fields;return t!==void 0&&t[`color-scheme`]===`dark`}catch{return!1}}function ze(e){try{let t=e.syncer;if(t?.tiddlerInfo===void 0)return;let n=e.wiki.getChangeCount(Ae),r=t.tiddlerInfo[Ae];r===void 0?t.tiddlerInfo[Ae]={changeCount:n}:r.changeCount=n}catch{}}function Be(e){try{let t=e.syncer,n=t?.syncadaptor;if(t===void 0||n===void 0||Me.has(t))return;let r=n.saveTiddler.bind(n);n.saveTiddler=(e,t)=>{if(Pe&&Ne.length>0&&e?.fields?.title===Ae&&e?.fields?.text===Fe){t(null,{},0);return}r(e,t)},Me.add(t)}catch{}}function Ve(e,t){try{if(Le(e)===t)return;e.wiki.setText(Ae,`text`,void 0,t),ze(e)}catch{}}function He(e,t){let n=Le(e);if(t){if(Re(e))return;n!==Fe&&(Ne=n),Ve(e,Fe)}else Re(e)&&n===Fe&&Ne.length>0&&Ve(e,Ne)}function Ue(e,t){try{let n=t.contentDocument?.documentElement;if(n==null)return;let r=Re(e)?`dark`:`light`;n.style.getPropertyValue(`color-scheme`)!==r&&n.style.setProperty(`color-scheme`,r)}catch{}}function We(e){try{let t=e.contentWindow?.$tw;if(t===void 0||t.wiki===void 0)return;Be(t),Pe?He(t,Ie()):He(t,!1),Ue(t,e)}catch{}}function Ge(e){let t=e.enabled!==!1,n=typeof e.darkPalette==`string`&&e.darkPalette.trim().length>0?e.darkPalette.trim():De,r=t!==Pe||n!==Fe;if(Pe=t,Fe=n,r)for(let e of[...je])e()}function Ke(e){if(e===null)return()=>{};let t=()=>We(e);je.add(t);let n=()=>t();e.addEventListener(`load`,n);let r=window.matchMedia(`(prefers-color-scheme: dark)`),i=()=>t();try{r.addEventListener(`change`,i)}catch{r.addListener?.(i)}let a;try{a=new MutationObserver(()=>t()),document.body!==null&&a.observe(document.body,{attributes:!0,attributeFilter:[ke]}),document.documentElement!==null&&a.observe(document.documentElement,{attributes:!0,attributeFilter:[`style`]})}catch{a=void 0}let o=[150,600,1500,3e3].map(e=>window.setTimeout(t,e));return t(),()=>{je.delete(t),e.removeEventListener(`load`,n);for(let e of o)window.clearTimeout(e);try{r.removeEventListener(`change`,i)}catch{r.removeListener?.(i)}try{a?.disconnect()}catch{}}}const qe=`dsh-panel-activate`,Je=`dsh-tw-panel-reload`;let Ye=`知识库`;function Xe(e){let t=typeof e==`string`?e.trim():``;t.length>0&&(Ye=t)}function Ze(){return Ye}async function Qe(){try{return(await fetch(te,{method:`POST`,signal:AbortSignal.timeout(8e3)})).ok}catch{return!1}}function $e({size:e=16,className:t}){return c.createElement(`svg`,{width:e,height:e,className:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.3,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0},c.createElement(`path`,{d:`M4 2.5h8a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z`}),c.createElement(`path`,{d:`M6 6h4M6 8.5h2.5`}))}function et(e){let t=e.loaded;return t===void 0||t.length===0?null:t}function tt(e){let t=!1,n=!1,r=!1,i,a,o,s,c=new Set,l=0,u=!1,d=null,f,p=()=>{s!==void 0&&(window.clearTimeout(s),s=void 0)},m=e=>{if(a===void 0||o===void 0)return;a.hidden=!0,o.hidden=!1,o.replaceChildren();let t=document.createElement(`div`);t.textContent=`TiddlyWiki 服务不可用`;let n=document.createElement(`code`);n.textContent=e;let r=document.createElement(`button`);r.type=`button`,r.textContent=`重试`,r.addEventListener(`click`,()=>{r.disabled=!0,r.textContent=`重启中…`,Qe().finally(()=>{y()})}),o.append(t,n,r)},h=()=>{if(a===void 0||o===void 0)return;a.hidden=!0,o.hidden=!1,o.replaceChildren();let e=document.createElement(`div`);e.textContent=`TiddlyWiki 服务正在启动…`,o.append(e)},g=e=>{a===void 0||o===void 0||(o.hidden=!0,a.hidden=!t,a.dataset.loaded!==e&&(a.dataset.loaded=e,u=!1,a.src=e))},_=()=>{if(d===null||a===void 0||!u)return;let e=d,t=a.contentWindow;if(t===null){v(e);return}let n=i=>{if(r||d!==e)return;let a=t;if(typeof a.$tw!=`object`||a.$tw===null){if(i<40){let e=window.setTimeout(()=>{c.delete(e),n(i+1)},150);c.add(e);return}v(e);return}d=null;try{t.location.hash!==e&&(t.location.hash=e)}catch{v(e)}};n(0)},v=e=>{if(r||a===void 0)return;d===e&&(d=null);let t=et(a.dataset);if(t===null)return;let n=`${t.split(`#`)[0]}${e}`;a.src!==n&&(a.src=n)},y=async()=>{p();let e=await me();if(!r&&t){if(e===null){m(`无法访问 /dsh-tiddlywiki/status`);return}if(e.ui!==void 0&&(Xe(e.ui.tabLabel??Ye),Ge({enabled:e.ui.followDshTheme!==!1,darkPalette:e.ui.darkPalette})),e.status===`running`){l=0,typeof e.twProxy==`string`?g(new URL(e.twProxy,window.location.origin).href):typeof e.url==`string`?g(e.url):m(`服务未返回编辑器地址`);return}if(e.status===`starting`){h(),l<30&&(l++,s=window.setTimeout(()=>{y()},1500));return}l=0,m(e.error??`服务状态:${e.status}`)}},b=()=>{if(a===void 0)return;let e=et(a.dataset);e!==null&&(a.src=e)};return document.addEventListener(Je,b),{build:()=>{if(i!==void 0)return i;let n=document.createElement(`div`);if(n.className=e.view,e.viewDataset!==void 0)for(let[t,r]of Object.entries(e.viewDataset))n.dataset[t]=r;let r=document.createElement(`div`);r.className=e.frameWrap,e.frameWrapStyle!==void 0&&(r.style.cssText=e.frameWrapStyle);let s=document.createElement(`iframe`);s.className=e.frame,s.title=`TiddlyWiki`,s.hidden=!0,r.append(s);let c=document.createElement(`div`);return c.className=e.error,c.hidden=!0,n.append(r,c),i=n,a=s,o=c,s.addEventListener(`load`,()=>{u=!0,_()}),f=Ke(s),t&&y(),n},setVisible(e){r||(t=e,e&&!n&&(n=!0),a!==void 0&&(a.hidden=!e||et(a.dataset)===null),e?y():(p(),l=0))},openTiddler(e){return r||!t?!1:(d=`#${encodeURIComponent(e)}`,n?_():(n=!0,y()),!0)},dispose(){if(!r){r=!0,document.removeEventListener(Je,b),p();for(let e of c)window.clearTimeout(e);c.clear(),f?.(),i?.remove()}}}}function nt(){return{setVisible(){},openTiddler(){return!1},dispose(){}}}const rt=new Set;function it(e){for(let t of rt)if(t.openTiddler(e))return!0;return!1}function at(){me().then(e=>{e?.ui!==void 0&&Xe(e.ui.tabLabel??Ye)})}const ot={view:`dsh-tw-rightbar-view`,frameWrap:`dsh-tw-rightbar-frame-wrap`,frame:`dsh-tw-rightbar-frame`,error:`dsh-tw-rightbar-error`};function st(e,t){if(t.aborted)return nt();let n=tt(ot);e.append(n.build());let r=!1,i=()=>a.dispose();t.addEventListener(`abort`,i,{once:!0});let a={setVisible(e){n.setVisible(e)},openTiddler(e){return n.openTiddler(e)},dispose(){r||(r=!0,rt.delete(a),t.removeEventListener(`abort`,i),n.dispose())}};return rt.add(a),a}const ct=[`[class*="centerCol"]`,`[data-pane="conversation"]`,`.dshDesktopConversationSurface`],lt=`data-dsh-tw-active`,ut=[`data-dsh-atb-active`,`data-dsh-taskboard-active`,`data-dsh-ssh-active`],dt=`dsh-tiddlywiki`,ft=`[data-dsh-panel-host]`,pt={view:`dsh-tw-view`,viewDataset:{dshTwView:``},frameWrap:`dsh-tw-panel-frame-wrap`,frameWrapStyle:`flex:1;min-height:0;display:flex;flex-direction:column`,frame:`dsh-tw-panel-frame`,error:`dsh-tw-panel-error`},mt=`dsh-tw-open-tiddler`;function ht(e){typeof document>`u`||typeof e!=`string`||e.length===0||document.dispatchEvent(new CustomEvent(mt,{detail:{title:e}}))}function gt(){let e=document.querySelector(ft);if(e===null)return 40;let t=parseInt(getComputedStyle(e).zIndex,10);return Number.isFinite(t)?Math.max(20,Math.min(40,t-1)):40}function _t(){for(let e of ct){let t=document.querySelector(e);if(t!==null)return t}}function vt(e){let t,n,r=!1,i,a=tt(pt),o=()=>{if(!e.isOpen()||t===void 0||n===void 0)return;let r=n.getBoundingClientRect();if(r.width===0&&r.height===0)return;let i=`${r.left}px`,a=`${r.top}px`,o=`${r.width}px`,s=`${r.height}px`;t.style.left!==i&&(t.style.left=i),t.style.top!==a&&(t.style.top=a),t.style.width!==o&&(t.style.width=o),t.style.height!==s&&(t.style.height=s)},s=(n=!1)=>{if(t===void 0)return;let r=document.querySelector(ft)!==null;!n&&!e.isOpen()&&r===i||(i=r,t.style.zIndex=String(gt()),r?t.dataset.sidebarHost=`1`:delete t.dataset.sidebarHost)},c=()=>{(n===void 0||!n.isConnected)&&(n=_t()),t===void 0&&n!==void 0&&(t=a.build(),t.style.position=`fixed`,s(!0),document.body.append(t),o())},l=t=>{let n=t.detail,r=typeof n?.title==`string`&&n.title.length>0?n.title:``;r.length!==0&&(it(r)||(e.openPanel(),a.openTiddler(r)))},u=()=>{if(e.isOpen()){for(let e of ut)document.documentElement.removeAttribute(e);document.documentElement.setAttribute(lt,``),document.dispatchEvent(new CustomEvent(qe,{detail:dt})),m()}else document.documentElement.removeAttribute(lt);a.setVisible(e.isOpen())},d=t=>{t.detail!==dt&&e.isOpen()&&e.closePanel()},f=t=>{if(!e.isOpen())return;let n=t.target;n!==null&&n.closest(`[data-dsh-tw-entry]`)===null&&n.closest(`[class*="sessionRow"], [class*="projectRow"], [class*="searchResultRow"], [class*="searchResultWorkspace"], [class*="newSession"]`)!==null&&e.closePanel()},p,m=()=>{r||p!==void 0||(p=window.requestAnimationFrame(()=>{p=void 0,!r&&(c(),o(),s())}))},h=new MutationObserver(()=>{m()});h.observe(document.body,{childList:!0,subtree:!0});let g=new ResizeObserver(()=>{m()});g.observe(document.body);let _=window.setInterval(o,2e3),v=()=>{m()};window.addEventListener(`resize`,v);let y=()=>{m()};window.addEventListener(`scroll`,y,!0),document.addEventListener(`click`,f,!0),document.addEventListener(qe,d);let b=e.subscribe(u);return c(),u(),document.addEventListener(mt,l),()=>{r=!0,p!==void 0&&window.cancelAnimationFrame(p),p=void 0,window.clearInterval(_),window.removeEventListener(`resize`,v),window.removeEventListener(`scroll`,y,!0),g.disconnect(),document.removeEventListener(`click`,f,!0),document.removeEventListener(qe,d),document.removeEventListener(mt,l),h.disconnect(),b(),document.documentElement.removeAttribute(lt),a.dispose(),t?.remove()}}function E(e){let t=document.querySelector(`.dsh-tw-toast`);t===null&&(t=document.createElement(`div`),t.className=`dsh-tw-toast`,document.body.append(t)),t.textContent=e,t.classList.add(`dsh-tw-toast-show`),clearTimeout(t.__twToastTimer),t.__twToastTimer=window.setTimeout(()=>{t?.classList.remove(`dsh-tw-toast-show`)},2500)}const yt=`dsh-tiddlywiki/editor-popup`;let D,O,bt,xt,St,Ct;function wt(e,t){At(),!(D===void 0||O===void 0)&&(bt!==void 0&&(bt.textContent=`TiddlyWiki 编辑器 · ${t}`),D.style.display=``,document.dispatchEvent(new CustomEvent(qe,{detail:yt})),(O.dataset.loaded!==e||Et())&&(O.dataset.loaded=e,O.src=e),Dt())}function Tt(){return D!==void 0&&D.style.display!==`none`}function Et(){if(O===void 0)return!1;let e=null;try{e=O.contentDocument}catch{return!1}if(e===null||e.readyState===`loading`)return!1;let t=e.querySelector(`.tc-story-river`);return t===null||t.querySelector(`.tc-tiddler-frame`)===null}function Dt(){D!==void 0&&D.querySelector(`button, [href], input, select, textarea, iframe, [tabindex]:not([tabindex="-1"])`)?.focus()}function Ot(){D!==void 0&&(D.style.display=`none`),O!==void 0&&(O.dataset.loaded=``)}function kt(){xt?.(),xt=void 0,St!==void 0&&(document.removeEventListener(`keydown`,St),St=void 0),Ct!==void 0&&(document.removeEventListener(qe,Ct),Ct=void 0),D?.remove(),D=void 0,O=void 0,bt=void 0}function At(){if(D!==void 0&&O!==void 0)return;D=document.createElement(`div`),D.className=`dsh-tw-editor-popup`,D.style.display=`none`,D.setAttribute(`role`,`dialog`),D.setAttribute(`aria-modal`,`true`),D.setAttribute(`aria-label`,`TiddlyWiki 编辑器`);let e=document.createElement(`div`);e.className=`dsh-tw-editor-bar`,bt=document.createElement(`span`),bt.className=`dsh-tw-editor-title`,bt.textContent=`TiddlyWiki 编辑器`;let t=document.createElement(`button`);t.type=`button`,t.className=`dsh-tw-editor-close`,t.textContent=`✕`,t.title=`关闭`,e.append(bt,t),O=document.createElement(`iframe`),O.className=`dsh-tw-editor-frame`,O.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-forms allow-popups`),O.title=`TiddlyWiki 编辑器`,xt=Ke(O);let n=document.createElement(`div`);n.className=`dsh-tw-editor-resize`,n.title=`拖拽调整大小`,D.append(e,O,n),document.body.append(D),t.addEventListener(`click`,()=>Ot()),St=e=>{e.key===`Escape`&&Tt()&&Ot()},document.addEventListener(`keydown`,St),Ct=e=>{e.detail!==yt&&Tt()&&Ot()},document.addEventListener(qe,Ct),e.addEventListener(`pointerdown`,n=>{if(n.button!==0||D===void 0)return;let r=n.target;if(t.contains(r))return;n.preventDefault(),e.setPointerCapture(n.pointerId);let i=D.getBoundingClientRect(),a=n.clientX,o=n.clientY,s=i.left,c=i.top,l=e=>{D!==void 0&&(D.style.left=`${s+e.clientX-a}px`,D.style.top=`${c+e.clientY-o}px`,D.style.margin=`0`,D.style.right=`auto`,D.style.bottom=`auto`)},u=()=>{e.removeEventListener(`pointermove`,l),e.removeEventListener(`pointerup`,u),e.removeEventListener(`pointercancel`,u)};e.addEventListener(`pointermove`,l),e.addEventListener(`pointerup`,u),e.addEventListener(`pointercancel`,u)}),n.addEventListener(`pointerdown`,e=>{if(e.button!==0||D===void 0)return;e.preventDefault(),e.stopPropagation(),n.setPointerCapture(e.pointerId);let t=D.getBoundingClientRect(),r=e.clientX,i=e.clientY,a=t.width,o=t.height,s=e=>{D!==void 0&&(D.style.width=`${Math.max(360,a+e.clientX-r)}px`,D.style.height=`${Math.max(260,o+e.clientY-i)}px`,D.style.right=`auto`,D.style.bottom=`auto`)},c=()=>{n.removeEventListener(`pointermove`,s),n.removeEventListener(`pointerup`,c),n.removeEventListener(`pointercancel`,c)};n.addEventListener(`pointermove`,s),n.addEventListener(`pointerup`,c),n.addEventListener(`pointercancel`,c)})}let jt=[],Mt=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?Mt:jt).push(n+=e[t])})();function Nt(e){if(e<768)return!1;for(let t=0,n=jt.length;;){let r=t+n>>1;if(e<jt[r])n=r;else if(e>=Mt[r])t=r+1;else return!0;if(t==n)return!1}}function Pt(e){return e>=127462&&e<=127487}const Ft=8205;function It(e,t,n=!0,r=!0){return(n?Lt:Rt)(e,t,r)}function Lt(e,t,n){if(t==e.length)return t;t&&Bt(e.charCodeAt(t))&&Vt(e.charCodeAt(t-1))&&t--;let r=zt(e,t);for(t+=Ht(r);t<e.length;){let i=zt(e,t);if(r==Ft||i==Ft||n&&Nt(i))t+=Ht(i),r=i;else if(Pt(i)){let n=0,r=t-2;for(;r>=0&&Pt(zt(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function Rt(e,t,n){for(;t>1;){let r=Lt(e,t-2,n);if(r<t)return r;t--}return 0}function zt(e,t){let n=e.charCodeAt(t);if(!Vt(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return Bt(r)?(n-55296<<10)+(r-56320)+65536:n}function Bt(e){return e>=56320&&e<57344}function Vt(e){return e>=55296&&e<56320}function Ht(e){return e<65536?1:2}var k=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=Qt(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Wt.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Qt(this,e,t);let n=[];return this.decompose(e,t,n,0),Wt.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new Jt(this),i=new Jt(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new Jt(this,e)}iterRange(e,t=this.length){return new Yt(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Xt(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new Ut(t):Wt.from(Ut.split(t,[]))}},Ut=class e extends k{constructor(e,t=Gt(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new Zt(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(qt(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=Kt(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=Qt(this,t,n);let i=Kt(this.text,Kt(r.text,qt(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):Wt.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
735
735
  `){[e,t]=Qt(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},Wt=class e extends k{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=Qt(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
736
736
  `){[e,t]=Qt(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new Ut(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof Ut&&c&&(n=u[u.length-1])instanceof Ut&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new Ut(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};k.empty=new Ut([``],0);function Gt(e){let t=-1;for(let n of e)t+=n.length+1;return t}function Kt(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function qt(e,t,n){return Kt(e,[``],t,n)}var Jt=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof Ut?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof Ut?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
737
- `,this;e--}else if(r instanceof Ut){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof Ut?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Yt=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new Jt(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},Xt=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(k.prototype[Symbol.iterator]=function(){return this.iter()},Jt.prototype[Symbol.iterator]=Yt.prototype[Symbol.iterator]=Xt.prototype[Symbol.iterator]=function(){return this});var Zt=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function Qt(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function A(e,t,n=!0,r=!0){return It(e,t,n,r)}function $t(e){return e>=56320&&e<57344}function en(e){return e>=55296&&e<56320}function tn(e,t){let n=e.charCodeAt(t);if(!en(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return $t(r)?(n-55296<<10)+(r-56320)+65536:n}function nn(e){return e<65536?1:2}const rn=/\r\n?|\n/;var an=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(an||={}),on=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){un(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:fn(this,e)}mapDesc(e,t=!1){return e.empty?this:dn(this,e,t)}mapPos(e,t=-1,n=an.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=an.Simple&&c>=e&&(n==an.TrackDel&&r<e&&c>e||n==an.TrackBefore&&r<e||n==an.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},sn=class e extends on{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return un(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return dn(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(k.empty);r.push(a?t.slice(i,i+a):k.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:fn(this,e,!0)}map(e,t=!1){return e.empty?this:dn(this,e,t,!0)}iterChanges(e,t=!1){un(this,e,t)}get desc(){return on.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new pn(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);cn(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;cn(n,e,t),t>0&&ln(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);cn(n,e,-1),cn(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:on.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&cn(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?k.of(l.split(r||rn)):l:k.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&cn(i,e-o,-1),cn(i,s-e,d),ln(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(k.empty);r[e]=k.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function cn(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function ln(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(k.empty);e.push(n)}}function un(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=k.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function dn(e,t,n,r=!1){let i=[],a=r?[]:null,o=new pn(e),s=new pn(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);cn(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(cn(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(cn(i,0,o.ins),a&&ln(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;cn(i,t,e<o.i?o.ins:0),a&&e<o.i&&ln(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?sn.createSet(i,a):on.create(i);else throw Error(`Mismatched change set lengths`)}function fn(e,t,n=!1){let r=[],i=n?[]:null,a=new pn(e),o=new pn(t);for(let e=!1;;)if(a.done&&o.done)return i?sn.createSet(r,i):on.create(r);else if(a.ins==0)cn(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)cn(r,0,o.ins,e),i&&ln(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;cn(r,t,n,e),i&&n&&ln(i,r,o.text)}else o.ins==-1?(cn(r,a.off?0:a.len,t,e),i&&ln(i,r,a.textBit(t))):(cn(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&ln(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var pn=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?k.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?k.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},mn=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return j.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return j.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return j.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},j=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>mn.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return mn.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?mn.create(t,e,a|32,n):mn.create(e,t,a,n)}static undirectionalRange(e,t){return mn.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function hn(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}let gn=0;var M=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=gn++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:_n),!!t.static,t.enables)}of(e){return new vn([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new vn(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new vn(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function _n(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var vn=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=gn++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||bn(e,c)){let r=t(e);if(a?!yn(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=Nn(o,c);if(this.dependencies.every(t=>t instanceof M?o.facet(t)===e.facet(t):t instanceof Cn?o.field(t,!1)==e.field(t,!1):!0)||(a?yn(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function yn(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function bn(e,t){let n=!1;for(let r of t)Mn(e,r)&1&&(n=!0);return n}function xn(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=Nn(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Mn(e,t);return e.values[o]=s(e),1},update(e,n){if(!bn(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=bn(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&_n(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}const Sn=M.define({static:!0});var Cn=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(gn++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(Sn).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(Sn),i=n.facet(Sn),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,Sn.of({field:this,create:e})]}get extension(){return this}};const wn={lowest:4,low:3,default:2,high:1,highest:0};function Tn(e){return t=>new Dn(t,e)}const En={highest:Tn(wn.highest),high:Tn(wn.high),default:Tn(wn.default),low:Tn(wn.low),lowest:Tn(wn.lowest)};var Dn=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},On=class e{of(e){return new kn(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},kn=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},An=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of jn(t,n,o))e instanceof Cn?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0))if(s[n.id]=c.length<<1|1,_n(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>xn(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function jn(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof kn&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof kn){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof Dn)a(e.inner,e.prec);else if(e instanceof Cn)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof vn)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,wn.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,wn.default),r.reduce((e,t)=>e.concat(t))}function Mn(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function Nn(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}const Pn=M.define(),Fn=M.define({combine:e=>e.some(e=>e),static:!0}),In=M.define({combine:e=>e.length?e[0]:void 0,static:!0}),Ln=M.define(),Rn=M.define(),zn=M.define(),Bn=M.define({combine:e=>e.length?e[0]:!1});var Vn=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Hn}},Hn=class{of(e){return new Vn(this,e)}},Un=class{constructor(e){this.map=e}of(e){return new N(this,e)}},N=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new Un(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};N.reconfigure=N.define(),N.appendConfig=N.define();var Wn=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&hn(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};Wn.time=Vn.define(),Wn.userEvent=Vn.define(),Wn.addToHistory=Vn.define(),Wn.remote=Vn.define();function Gn(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function Kn(e,t,n){let r,i,a;return n?(r=t.changes,i=sn.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:N.mapEffects(e.effects,r).concat(N.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function qn(e,t,n){let r=t.selection,i=Qn(t.annotations);return t.userEvent&&(i=i.concat(Wn.userEvent.of(t.userEvent))),{changes:t.changes instanceof sn?t.changes:sn.of(t.changes||[],n,e.facet(In)),selection:r&&(r instanceof j?r:j.single(r.anchor,r.head)),effects:Qn(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function Jn(e,t,n){let r=qn(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=Kn(r,qn(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=Wn.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return Xn(n?Yn(i):i)}function Yn(e){let t=e.startState,n=!0;for(let r of t.facet(Ln)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:Gn(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=sn.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=Wn.create(t,r,e.selection&&e.selection.map(i),N.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(Rn);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof Wn?i:Array.isArray(i)&&i.length==1&&i[0]instanceof Wn?i[0]:Jn(t,Qn(i),!1)}return e}function Xn(e){let t=e.startState,n=t.facet(zn),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Kn(r,qn(t,a,e.changes.newLength),!0))}return r==e?e:Wn.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}const Zn=[];function Qn(e){return e==null?Zn:Array.isArray(e)?e:[e]}var $n=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})($n||={});const er=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let tr;try{tr=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function nr(e){if(tr)return tr.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>`€`&&(n.toUpperCase()!=n.toLowerCase()||er.test(n)))return!0}return!1}function rr(e){return t=>{if(!/\S/.test(t))return $n.Space;if(nr(t))return $n.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return $n.Word;return $n.Other}}var P=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Mn(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return Mn(this,n),Nn(this,n)}update(...e){return Jn(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(On.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(N.reconfigure)?(n=null,r=e.value):e.is(N.appendConfig)&&(n=null,r=Qn(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=An.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(Fn)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:j.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=Qn(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=N.mapEffects(a,c).concat(N.mapEffects(Qn(o.effects),l))}return{changes:r,selection:j.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof sn?t:sn.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return k.of(t.split(this.facet(e.lineSeparator)||rn))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Mn(this,t),Nn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof Cn&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:j.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=An.resolve(t.extensions||[],new Map),r=t.doc instanceof k?t.doc:k.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||rn)),i=t.selection?t.selection instanceof j?t.selection:j.single(t.selection.anchor,t.selection.head):j.single(0);return hn(i,r.length),n.staticFacet(Fn)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
738
- `}get readOnly(){return this.facet(Bn)}phrase(t,...n){for(let n of this.facet(e.phrases))if(Object.prototype.hasOwnProperty.call(n,t)){t=n[t];break}return n.length&&(t=t.replace(/\$(\$|\d*)/g,(e,t)=>{if(t==`$`)return`$`;let r=+(t||1);return!r||r>n.length?e:n[r-1]})),t}languageDataAt(e,t,n=-1){let r=[];for(let i of this.facet(Pn))for(let a of i(this,t,n))Object.prototype.hasOwnProperty.call(a,e)&&r.push(a[e]);return r}charCategorizer(e){let t=this.languageDataAt(`wordChars`,e);return rr(t.length?t[0]:``)}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),i=this.charCategorizer(e),a=e-n,o=e-n;for(;a>0;){let e=A(t,a,!1);if(i(t.slice(e,a))!=$n.Word)break;a=e}for(;o<r;){let e=A(t,o);if(i(t.slice(o,e))!=$n.Word)break;o=e}return a==o?null:j.range(a+n,o+n)}};P.allowMultipleSelections=Fn,P.tabSize=M.define({combine:e=>e.length?e[0]:4}),P.lineSeparator=In,P.readOnly=Bn,P.phrases=M.define({compare(e,t){let n=Object.keys(e),r=Object.keys(t);return n.length==r.length&&n.every(n=>e[n]==t[n])}}),P.languageData=Pn,P.changeFilter=Ln,P.transactionFilter=Rn,P.transactionExtender=zn,On.reconfigure=N.define();function ir(e,t,n={}){let r={};for(let t of e)for(let e of Object.keys(t)){let i=t[e],a=r[e];if(a===void 0)r[e]=i;else if(!(a===i||i===void 0))if(Object.hasOwnProperty.call(n,e))r[e]=n[e](a,i);else throw Error(`Config merge conflict for field `+e)}for(let e in t)r[e]===void 0&&(r[e]=t[e]);return r}var ar=class{eq(e){return this==e}range(e,t=e){return sr.create(e,t,this)}};ar.prototype.startSide=ar.prototype.endSide=0,ar.prototype.point=!1,ar.prototype.mapMode=an.TrackDel;function or(e,t){return e==t||e.constructor==t.constructor&&e.eq(t)}var sr=class e{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(t,n,r){return new e(t,n,r)}};function cr(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}var lr=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return ur(this.to)}findIndex(e,t,n,r=0){let i=n?this.to:this.from;for(let a=r,o=i.length;;){if(a==o)return a;let r=a+o>>1,s=i[r]-e||(n?this.value[r].endSide:this.value[r].startSide)-t;if(r==a)return s>=0?a:o;s>=0?o=r:a=r+1}}between(e,t,n,r){for(let i=this.findIndex(t,-1e9,!0),a=this.findIndex(n,1e9,!1,i);i<a;i++)if(r(this.from[i]+e,this.to[i]+e,this.value[i])===!1)return!1}map(t,n,r,i,a){let o=[],s=[],c=[],l=-1,u=-1;iter:for(let e=0;e<this.value.length;e++){let d=this.value[e],f=this.from[e]+t,p=this.to[e]+t,m,h;if(f==p){let e=n.mapPos(f,d.startSide,d.mapMode);if(e==null||(m=h=e,d.startSide!=d.endSide&&(h=n.mapPos(f,d.endSide),h<m)))continue}else if(m=n.mapPos(f,d.startSide),h=n.mapPos(p,d.endSide),m>h||m==h&&d.startSide>0&&d.endSide<=0)continue;if(!((h-m||d.endSide-d.startSide)<0))if(l<0&&(l=m),d.point&&(u=Math.max(u,h-m)),(m-r||d.startSide-i)>=0)o.push(d),s.push(m-l),c.push(h-l),r=h,i=d.endSide;else{if(m==h){for(let e=o.length-1;e>0;e--)if((m-c[e-1]||d.startSide-o[e-1].endSide)<=0){o.splice(e,0,d),s.splice(e,0,m),c.splice(e,0,h);continue iter}}a(m,h,d)}}return{mapped:o.length?new e(s,c,o,u):null,pos:l}}},F=class e{constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(t,n,r,i){return new e(t,n,r,i)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(t){let{add:n=[],sort:r=!1,filterFrom:i=0,filterTo:a=this.length}=t,o=t.filter;if(n.length==0&&!o)return this;if(r&&(n=n.slice().sort(cr)),this.isEmpty)return n.length?e.of(n):this;let s=new mr(this,null,-1).goto(0),c=0,l=[],u=new fr;for(;s.value||c<n.length;)if(c<n.length&&(s.from-n[c].from||s.startSide-n[c].value.startSide)>=0){let e=n[c++];u.addInner(e.from,e.to,e.value)||l.push(e)}else s.rangeIndex==1&&s.chunkIndex<this.chunk.length&&(c==n.length||this.chunkEnd(s.chunkIndex)<n[c].from)&&(!o||i>this.chunkEnd(s.chunkIndex)||a<this.chunkPos[s.chunkIndex])&&u.addChunk(this.chunkPos[s.chunkIndex],this.chunk[s.chunkIndex])?s.nextChunk():((!o||i>s.to||a<s.from||o(s.from,s.to,s.value))&&(u.addInner(s.from,s.to,s.value)||l.push(sr.create(s.from,s.to,s.value))),s.next());return u.finishInner(this.nextLayer.isEmpty&&!l.length?e.empty:this.nextLayer.update({add:l,filter:o,filterFrom:i,filterTo:a}))}map(t){if(t.empty||this.isEmpty)return this;let n=[],r=[],i=-1,a,o=(e,t,n)=>{a||=new fr,a.add(e,t,n)};for(let e=0;e<this.chunk.length;e++){let a=this.chunkPos[e],s=this.chunk[e],c=t.touchesRange(a,a+s.length);if(c===!1)i=Math.max(i,s.maxPoint),n.push(s),r.push(t.mapPos(a));else if(c===!0){let[e,c]=n.length?[ur(r)+ur(n).length,ur(ur(n).value).endSide]:[-1,-1],{mapped:l,pos:u}=s.map(a,t,e,c,o);l&&(i=Math.max(i,l.maxPoint),n.push(l),r.push(u))}}let s=this.nextLayer.map(t);return a&&(s=a.finishInner(s)),n.length==0?s:new e(r,n,s||e.empty,i)}between(e,t,n){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let i=this.chunkPos[r],a=this.chunk[r];if(t>=i&&e<=i+a.length&&a.between(i,e-i,t-i,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return hr.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return hr.from(e).goto(t)}static compare(e,t,n,r,i=-1){let a=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),o=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),s=pr(a,o,n),c=new _r(a,s,i),l=new _r(o,s,i);n.iterGaps((e,t,n)=>vr(c,e,l,t,n,r)),n.empty&&n.length==0&&vr(c,0,l,0,0,r)}static eq(e,t,n=0,r){r??=999999999;let i=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),a=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(i.length!=a.length)return!1;if(!i.length)return!0;let o=pr(i,a),s=new _r(i,o,0).goto(n),c=new _r(a,o,0).goto(n);for(;;){if(s.to!=c.to||!yr(s.active,c.active)||s.point&&(!c.point||!or(s.point,c.point)))return!1;if(s.to>r)return!0;s.next(),c.next()}}static spans(e,t,n,r,i=-1){let a=new _r(e,null,i).goto(t),o=t,s=a.openStart;for(;;){let e=Math.min(a.to,n);if(a.point){let n=a.activeForPoint(a.to),i=a.pointFrom<t?n.length+1:a.point.startSide<0?n.length:Math.min(n.length,s);r.point(o,e,a.point,n,i,a.pointRank),s=Math.min(a.openEnd(e),n.length)}else e>o&&(r.span(o,e,a.active,s),s=a.openEnd(e));if(a.to>n)return s+(a.point&&a.to>n?1:0);o=a.to,a.next()}}static of(e,t=!1){let n=new fr;for(let r of e instanceof sr?[e]:t?dr(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(t){if(!t.length)return e.empty;let n=ur(t);for(let r=t.length-2;r>=0;r--)for(let i=t[r];i!=e.empty;i=i.nextLayer)n=new e(i.chunkPos,i.chunk,n,Math.max(i.maxPoint,n.maxPoint));return n}};F.empty=new F([],[],null,-1);function ur(e){return e[e.length-1]}function dr(e){if(e.length>1)for(let t=e[0],n=1;n<e.length;n++){let r=e[n];if(cr(t,r)>0)return e.slice().sort(cr);t=r}return e}F.empty.nextLayer=F.empty;var fr=class e{finishChunk(e){this.chunks.push(new lr(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,n,r){this.addInner(t,n,r)||(this.nextLayer||=new e).add(t,n,r)}addInner(e,t,n){let r=e-this.lastTo||n.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(F.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=F.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function pr(e,t,n){let r=new Map;for(let t of e)for(let e=0;e<t.chunk.length;e++)t.chunk[e].maxPoint<=0&&r.set(t.chunk[e],t.chunkPos[e]);let i=new Set;for(let e of t)for(let t=0;t<e.chunk.length;t++){let a=r.get(e.chunk[t]);a!=null&&(n?n.mapPos(a):a)==e.chunkPos[t]&&!n?.touchesRange(a,a+e.chunk[t].length)&&i.add(e.chunk[t])}return i}var mr=class{constructor(e,t,n,r=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex<this.layer.chunk.length;){let t=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(t)||this.layer.chunkEnd(this.chunkIndex)<e||t.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],n=e+t.from[this.rangeIndex];if(this.from=n,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},hr=class e{constructor(e){this.heap=e}static from(t,n=null,r=-1){let i=[];for(let e=0;e<t.length;e++)for(let a=t[e];!a.isEmpty;a=a.nextLayer)a.maxPoint>=r&&i.push(new mr(a,n,r,e));return i.length==1?i[0]:new e(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let e=this.heap.length>>1;e>=0;e--)gr(this.heap,e);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let e=this.heap.length>>1;e>=0;e--)gr(this.heap,e);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),gr(this.heap,0)}}};function gr(e,t){for(let n=e[t];;){let r=(t<<1)+1;if(r>=e.length)break;let i=e[r];if(r+1<e.length&&i.compare(e[r+1])>=0&&(i=e[r+1],r++),n.compare(i)<0)break;e[r]=n,e[t]=i,t=r}}var _r=class{constructor(e,t,n){this.minPoint=n,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=hr.from(e,t,n)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){br(this.active,e),br(this.activeTo,e),br(this.activeRank,e),this.minActive=Sr(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:i}=this.cursor;for(;t<this.activeRank.length&&(i-this.activeRank[t]||r-this.activeTo[t])>0;)t++;xr(this.active,t,n),xr(this.activeTo,t,r),xr(this.activeRank,t,i),e&&xr(e,t,this.cursor.from),this.minActive=Sr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&br(n,r)}else if(!this.cursor.value){this.to=this.endSide=1e9;break}else if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let e=this.cursor.value;if(!e.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=e,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=e.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}}if(n){this.openStart=0;for(let t=n.length-1;t>=0&&n[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}};function vr(e,t,n,r,i,a){e.goto(t),n.goto(r);let o=r+i,s=r,c=r-t,l=!!a.boundChange;for(let t=!1;;){let r=e.to+c-n.to,i=r||e.endSide-n.endSide,u=i<0?e.to+c:n.to,d=Math.min(u,o);if(e.point||n.point?(e.point&&n.point&&or(e.point,n.point)&&yr(e.activeForPoint(e.to),n.activeForPoint(n.to))||a.comparePoint(s,d,e.point,n.point),t=!1):(t&&a.boundChange(s),d>s&&!yr(e.active,n.active)&&a.compareRange(s,d,e.active,n.active),l&&d<o&&(r||e.openEnd(u)!=n.openEnd(u))&&(t=!0)),u>o)break;s=u,i<=0&&e.next(),i>=0&&n.next()}}function yr(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n]&&!or(e[n],t[n]))return!1;return!0}function br(e,t){for(let n=t,r=e.length-1;n<r;n++)e[n]=e[n+1];e.pop()}function xr(e,t,n){for(let n=e.length-1;n>=t;n--)e[n+1]=e[n];e[t]=n}function Sr(e,t){let n=-1,r=1e9;for(let i=0;i<t.length;i++)(t[i]-r||e[i].endSide-e[n].endSide)<0&&(n=i,r=t[i]);return n}function Cr(e,t,n=e.length){let r=0;for(let i=0;i<n&&i<e.length;)e.charCodeAt(i)==9?(r+=t-r%t,i++):(r++,i=A(e,i));return r}function wr(e,t,n,r){for(let r=0,i=0;;){if(i>=t)return r;if(r==e.length)break;i+=e.charCodeAt(r)==9?n-i%n:1,r=A(e,r)}return r===!0?-1:e.length}const Tr=typeof Symbol>`u`?`__ͼ`:Symbol.for(`ͼ`),Er=typeof Symbol>`u`?`__styleSet`+Math.floor(Math.random()*1e8):Symbol(`styleSet`),Dr=typeof globalThis<`u`?globalThis:typeof window<`u`?window:{};var Or=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function i(e,t,a,o){let s=[],c=/^@(\w+)\b/.exec(e[0]),l=c&&c[1]==`keyframes`;if(c&&t==null)return a.push(e[0]+`;`);for(let n in t){let o=t[n];if(/&/.test(n))i(n.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),o,a);else if(o&&typeof o==`object`){if(!c)throw RangeError(`The value of a property (`+n+`) should be a primitive value.`);i(r(n),o,s,l)}else o!=null&&s.push(n.replace(/_.*/,``).replace(/[A-Z]/g,e=>`-`+e.toLowerCase())+`: `+o+`;`)}(s.length||l)&&a.push((n&&!c&&!o?e.map(n):e).join(`, `)+` {`+s.join(` `)+`}`)}for(let t in e)i(r(t),e[t],this.rules)}getRules(){return this.rules.join(`
737
+ `,this;e--}else if(r instanceof Ut){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof Ut?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Yt=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new Jt(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},Xt=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(k.prototype[Symbol.iterator]=function(){return this.iter()},Jt.prototype[Symbol.iterator]=Yt.prototype[Symbol.iterator]=Xt.prototype[Symbol.iterator]=function(){return this});var Zt=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function Qt(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function $t(e,t,n=!0,r=!0){return It(e,t,n,r)}function en(e){return e>=56320&&e<57344}function tn(e){return e>=55296&&e<56320}function nn(e,t){let n=e.charCodeAt(t);if(!tn(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return en(r)?(n-55296<<10)+(r-56320)+65536:n}function rn(e){return e<65536?1:2}const an=/\r\n?|\n/;var on=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(on||={}),sn=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){un(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:fn(this,e)}mapDesc(e,t=!1){return e.empty?this:dn(this,e,t)}mapPos(e,t=-1,n=on.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=on.Simple&&c>=e&&(n==on.TrackDel&&r<e&&c>e||n==on.TrackBefore&&r<e||n==on.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},cn=class e extends sn{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return un(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return dn(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(k.empty);r.push(a?t.slice(i,i+a):k.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:fn(this,e,!0)}map(e,t=!1){return e.empty?this:dn(this,e,t,!0)}iterChanges(e,t=!1){un(this,e,t)}get desc(){return sn.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new pn(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);A(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;A(n,e,t),t>0&&ln(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);A(n,e,-1),A(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:sn.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&A(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?k.of(l.split(r||an)):l:k.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&A(i,e-o,-1),A(i,s-e,d),ln(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(k.empty);r[e]=k.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function A(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function ln(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(k.empty);e.push(n)}}function un(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=k.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function dn(e,t,n,r=!1){let i=[],a=r?[]:null,o=new pn(e),s=new pn(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);A(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(A(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(A(i,0,o.ins),a&&ln(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;A(i,t,e<o.i?o.ins:0),a&&e<o.i&&ln(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?cn.createSet(i,a):sn.create(i);else throw Error(`Mismatched change set lengths`)}function fn(e,t,n=!1){let r=[],i=n?[]:null,a=new pn(e),o=new pn(t);for(let e=!1;;)if(a.done&&o.done)return i?cn.createSet(r,i):sn.create(r);else if(a.ins==0)A(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)A(r,0,o.ins,e),i&&ln(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;A(r,t,n,e),i&&n&&ln(i,r,o.text)}else o.ins==-1?(A(r,a.off?0:a.len,t,e),i&&ln(i,r,a.textBit(t))):(A(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&ln(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var pn=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?k.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?k.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},mn=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return j.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return j.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return j.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},j=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>mn.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return mn.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?mn.create(t,e,a|32,n):mn.create(e,t,a,n)}static undirectionalRange(e,t){return mn.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function hn(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}let gn=0;var M=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=gn++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:_n),!!t.static,t.enables)}of(e){return new vn([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new vn(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new vn(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function _n(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var vn=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=gn++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||bn(e,c)){let r=t(e);if(a?!yn(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=Nn(o,c);if(this.dependencies.every(t=>t instanceof M?o.facet(t)===e.facet(t):t instanceof Cn?o.field(t,!1)==e.field(t,!1):!0)||(a?yn(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function yn(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function bn(e,t){let n=!1;for(let r of t)Mn(e,r)&1&&(n=!0);return n}function xn(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=Nn(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Mn(e,t);return e.values[o]=s(e),1},update(e,n){if(!bn(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=bn(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&_n(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}const Sn=M.define({static:!0});var Cn=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(gn++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(Sn).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(Sn),i=n.facet(Sn),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,Sn.of({field:this,create:e})]}get extension(){return this}};const wn={lowest:4,low:3,default:2,high:1,highest:0};function Tn(e){return t=>new Dn(t,e)}const En={highest:Tn(wn.highest),high:Tn(wn.high),default:Tn(wn.default),low:Tn(wn.low),lowest:Tn(wn.lowest)};var Dn=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},On=class e{of(e){return new kn(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},kn=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},An=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of jn(t,n,o))e instanceof Cn?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0))if(s[n.id]=c.length<<1|1,_n(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>xn(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function jn(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof kn&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof kn){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof Dn)a(e.inner,e.prec);else if(e instanceof Cn)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof vn)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,wn.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,wn.default),r.reduce((e,t)=>e.concat(t))}function Mn(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function Nn(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}const Pn=M.define(),Fn=M.define({combine:e=>e.some(e=>e),static:!0}),In=M.define({combine:e=>e.length?e[0]:void 0,static:!0}),Ln=M.define(),Rn=M.define(),zn=M.define(),Bn=M.define({combine:e=>e.length?e[0]:!1});var Vn=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Hn}},Hn=class{of(e){return new Vn(this,e)}},Un=class{constructor(e){this.map=e}of(e){return new N(this,e)}},N=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new Un(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};N.reconfigure=N.define(),N.appendConfig=N.define();var Wn=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&hn(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};Wn.time=Vn.define(),Wn.userEvent=Vn.define(),Wn.addToHistory=Vn.define(),Wn.remote=Vn.define();function Gn(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function Kn(e,t,n){let r,i,a;return n?(r=t.changes,i=cn.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:N.mapEffects(e.effects,r).concat(N.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function qn(e,t,n){let r=t.selection,i=Qn(t.annotations);return t.userEvent&&(i=i.concat(Wn.userEvent.of(t.userEvent))),{changes:t.changes instanceof cn?t.changes:cn.of(t.changes||[],n,e.facet(In)),selection:r&&(r instanceof j?r:j.single(r.anchor,r.head)),effects:Qn(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function Jn(e,t,n){let r=qn(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=Kn(r,qn(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=Wn.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return Xn(n?Yn(i):i)}function Yn(e){let t=e.startState,n=!0;for(let r of t.facet(Ln)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:Gn(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=cn.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=Wn.create(t,r,e.selection&&e.selection.map(i),N.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(Rn);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof Wn?i:Array.isArray(i)&&i.length==1&&i[0]instanceof Wn?i[0]:Jn(t,Qn(i),!1)}return e}function Xn(e){let t=e.startState,n=t.facet(zn),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Kn(r,qn(t,a,e.changes.newLength),!0))}return r==e?e:Wn.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}const Zn=[];function Qn(e){return e==null?Zn:Array.isArray(e)?e:[e]}var $n=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})($n||={});const er=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let tr;try{tr=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function nr(e){if(tr)return tr.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>`€`&&(n.toUpperCase()!=n.toLowerCase()||er.test(n)))return!0}return!1}function rr(e){return t=>{if(!/\S/.test(t))return $n.Space;if(nr(t))return $n.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return $n.Word;return $n.Other}}var P=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Mn(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return Mn(this,n),Nn(this,n)}update(...e){return Jn(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(On.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(N.reconfigure)?(n=null,r=e.value):e.is(N.appendConfig)&&(n=null,r=Qn(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=An.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(Fn)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:j.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=Qn(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=N.mapEffects(a,c).concat(N.mapEffects(Qn(o.effects),l))}return{changes:r,selection:j.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof cn?t:cn.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return k.of(t.split(this.facet(e.lineSeparator)||an))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Mn(this,t),Nn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof Cn&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:j.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=An.resolve(t.extensions||[],new Map),r=t.doc instanceof k?t.doc:k.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||an)),i=t.selection?t.selection instanceof j?t.selection:j.single(t.selection.anchor,t.selection.head):j.single(0);return hn(i,r.length),n.staticFacet(Fn)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
738
+ `}get readOnly(){return this.facet(Bn)}phrase(t,...n){for(let n of this.facet(e.phrases))if(Object.prototype.hasOwnProperty.call(n,t)){t=n[t];break}return n.length&&(t=t.replace(/\$(\$|\d*)/g,(e,t)=>{if(t==`$`)return`$`;let r=+(t||1);return!r||r>n.length?e:n[r-1]})),t}languageDataAt(e,t,n=-1){let r=[];for(let i of this.facet(Pn))for(let a of i(this,t,n))Object.prototype.hasOwnProperty.call(a,e)&&r.push(a[e]);return r}charCategorizer(e){let t=this.languageDataAt(`wordChars`,e);return rr(t.length?t[0]:``)}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),i=this.charCategorizer(e),a=e-n,o=e-n;for(;a>0;){let e=$t(t,a,!1);if(i(t.slice(e,a))!=$n.Word)break;a=e}for(;o<r;){let e=$t(t,o);if(i(t.slice(o,e))!=$n.Word)break;o=e}return a==o?null:j.range(a+n,o+n)}};P.allowMultipleSelections=Fn,P.tabSize=M.define({combine:e=>e.length?e[0]:4}),P.lineSeparator=In,P.readOnly=Bn,P.phrases=M.define({compare(e,t){let n=Object.keys(e),r=Object.keys(t);return n.length==r.length&&n.every(n=>e[n]==t[n])}}),P.languageData=Pn,P.changeFilter=Ln,P.transactionFilter=Rn,P.transactionExtender=zn,On.reconfigure=N.define();function ir(e,t,n={}){let r={};for(let t of e)for(let e of Object.keys(t)){let i=t[e],a=r[e];if(a===void 0)r[e]=i;else if(!(a===i||i===void 0))if(Object.hasOwnProperty.call(n,e))r[e]=n[e](a,i);else throw Error(`Config merge conflict for field `+e)}for(let e in t)r[e]===void 0&&(r[e]=t[e]);return r}var ar=class{eq(e){return this==e}range(e,t=e){return sr.create(e,t,this)}};ar.prototype.startSide=ar.prototype.endSide=0,ar.prototype.point=!1,ar.prototype.mapMode=on.TrackDel;function or(e,t){return e==t||e.constructor==t.constructor&&e.eq(t)}var sr=class e{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(t,n,r){return new e(t,n,r)}};function cr(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}var lr=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return ur(this.to)}findIndex(e,t,n,r=0){let i=n?this.to:this.from;for(let a=r,o=i.length;;){if(a==o)return a;let r=a+o>>1,s=i[r]-e||(n?this.value[r].endSide:this.value[r].startSide)-t;if(r==a)return s>=0?a:o;s>=0?o=r:a=r+1}}between(e,t,n,r){for(let i=this.findIndex(t,-1e9,!0),a=this.findIndex(n,1e9,!1,i);i<a;i++)if(r(this.from[i]+e,this.to[i]+e,this.value[i])===!1)return!1}map(t,n,r,i,a){let o=[],s=[],c=[],l=-1,u=-1;iter:for(let e=0;e<this.value.length;e++){let d=this.value[e],f=this.from[e]+t,p=this.to[e]+t,m,h;if(f==p){let e=n.mapPos(f,d.startSide,d.mapMode);if(e==null||(m=h=e,d.startSide!=d.endSide&&(h=n.mapPos(f,d.endSide),h<m)))continue}else if(m=n.mapPos(f,d.startSide),h=n.mapPos(p,d.endSide),m>h||m==h&&d.startSide>0&&d.endSide<=0)continue;if(!((h-m||d.endSide-d.startSide)<0))if(l<0&&(l=m),d.point&&(u=Math.max(u,h-m)),(m-r||d.startSide-i)>=0)o.push(d),s.push(m-l),c.push(h-l),r=h,i=d.endSide;else{if(m==h){for(let e=o.length-1;e>0;e--)if((m-c[e-1]||d.startSide-o[e-1].endSide)<=0){o.splice(e,0,d),s.splice(e,0,m),c.splice(e,0,h);continue iter}}a(m,h,d)}}return{mapped:o.length?new e(s,c,o,u):null,pos:l}}},F=class e{constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(t,n,r,i){return new e(t,n,r,i)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(t){let{add:n=[],sort:r=!1,filterFrom:i=0,filterTo:a=this.length}=t,o=t.filter;if(n.length==0&&!o)return this;if(r&&(n=n.slice().sort(cr)),this.isEmpty)return n.length?e.of(n):this;let s=new mr(this,null,-1).goto(0),c=0,l=[],u=new fr;for(;s.value||c<n.length;)if(c<n.length&&(s.from-n[c].from||s.startSide-n[c].value.startSide)>=0){let e=n[c++];u.addInner(e.from,e.to,e.value)||l.push(e)}else s.rangeIndex==1&&s.chunkIndex<this.chunk.length&&(c==n.length||this.chunkEnd(s.chunkIndex)<n[c].from)&&(!o||i>this.chunkEnd(s.chunkIndex)||a<this.chunkPos[s.chunkIndex])&&u.addChunk(this.chunkPos[s.chunkIndex],this.chunk[s.chunkIndex])?s.nextChunk():((!o||i>s.to||a<s.from||o(s.from,s.to,s.value))&&(u.addInner(s.from,s.to,s.value)||l.push(sr.create(s.from,s.to,s.value))),s.next());return u.finishInner(this.nextLayer.isEmpty&&!l.length?e.empty:this.nextLayer.update({add:l,filter:o,filterFrom:i,filterTo:a}))}map(t){if(t.empty||this.isEmpty)return this;let n=[],r=[],i=-1,a,o=(e,t,n)=>{a||=new fr,a.add(e,t,n)};for(let e=0;e<this.chunk.length;e++){let a=this.chunkPos[e],s=this.chunk[e],c=t.touchesRange(a,a+s.length);if(c===!1)i=Math.max(i,s.maxPoint),n.push(s),r.push(t.mapPos(a));else if(c===!0){let[e,c]=n.length?[ur(r)+ur(n).length,ur(ur(n).value).endSide]:[-1,-1],{mapped:l,pos:u}=s.map(a,t,e,c,o);l&&(i=Math.max(i,l.maxPoint),n.push(l),r.push(u))}}let s=this.nextLayer.map(t);return a&&(s=a.finishInner(s)),n.length==0?s:new e(r,n,s||e.empty,i)}between(e,t,n){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let i=this.chunkPos[r],a=this.chunk[r];if(t>=i&&e<=i+a.length&&a.between(i,e-i,t-i,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return hr.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return hr.from(e).goto(t)}static compare(e,t,n,r,i=-1){let a=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),o=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),s=pr(a,o,n),c=new _r(a,s,i),l=new _r(o,s,i);n.iterGaps((e,t,n)=>vr(c,e,l,t,n,r)),n.empty&&n.length==0&&vr(c,0,l,0,0,r)}static eq(e,t,n=0,r){r??=999999999;let i=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),a=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(i.length!=a.length)return!1;if(!i.length)return!0;let o=pr(i,a),s=new _r(i,o,0).goto(n),c=new _r(a,o,0).goto(n);for(;;){if(s.to!=c.to||!yr(s.active,c.active)||s.point&&(!c.point||!or(s.point,c.point)))return!1;if(s.to>r)return!0;s.next(),c.next()}}static spans(e,t,n,r,i=-1){let a=new _r(e,null,i).goto(t),o=t,s=a.openStart;for(;;){let e=Math.min(a.to,n);if(a.point){let n=a.activeForPoint(a.to),i=a.pointFrom<t?n.length+1:a.point.startSide<0?n.length:Math.min(n.length,s);r.point(o,e,a.point,n,i,a.pointRank),s=Math.min(a.openEnd(e),n.length)}else e>o&&(r.span(o,e,a.active,s),s=a.openEnd(e));if(a.to>n)return s+(a.point&&a.to>n?1:0);o=a.to,a.next()}}static of(e,t=!1){let n=new fr;for(let r of e instanceof sr?[e]:t?dr(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(t){if(!t.length)return e.empty;let n=ur(t);for(let r=t.length-2;r>=0;r--)for(let i=t[r];i!=e.empty;i=i.nextLayer)n=new e(i.chunkPos,i.chunk,n,Math.max(i.maxPoint,n.maxPoint));return n}};F.empty=new F([],[],null,-1);function ur(e){return e[e.length-1]}function dr(e){if(e.length>1)for(let t=e[0],n=1;n<e.length;n++){let r=e[n];if(cr(t,r)>0)return e.slice().sort(cr);t=r}return e}F.empty.nextLayer=F.empty;var fr=class e{finishChunk(e){this.chunks.push(new lr(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,n,r){this.addInner(t,n,r)||(this.nextLayer||=new e).add(t,n,r)}addInner(e,t,n){let r=e-this.lastTo||n.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(F.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=F.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function pr(e,t,n){let r=new Map;for(let t of e)for(let e=0;e<t.chunk.length;e++)t.chunk[e].maxPoint<=0&&r.set(t.chunk[e],t.chunkPos[e]);let i=new Set;for(let e of t)for(let t=0;t<e.chunk.length;t++){let a=r.get(e.chunk[t]);a!=null&&(n?n.mapPos(a):a)==e.chunkPos[t]&&!n?.touchesRange(a,a+e.chunk[t].length)&&i.add(e.chunk[t])}return i}var mr=class{constructor(e,t,n,r=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex<this.layer.chunk.length;){let t=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(t)||this.layer.chunkEnd(this.chunkIndex)<e||t.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],n=e+t.from[this.rangeIndex];if(this.from=n,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},hr=class e{constructor(e){this.heap=e}static from(t,n=null,r=-1){let i=[];for(let e=0;e<t.length;e++)for(let a=t[e];!a.isEmpty;a=a.nextLayer)a.maxPoint>=r&&i.push(new mr(a,n,r,e));return i.length==1?i[0]:new e(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let e=this.heap.length>>1;e>=0;e--)gr(this.heap,e);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let e=this.heap.length>>1;e>=0;e--)gr(this.heap,e);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),gr(this.heap,0)}}};function gr(e,t){for(let n=e[t];;){let r=(t<<1)+1;if(r>=e.length)break;let i=e[r];if(r+1<e.length&&i.compare(e[r+1])>=0&&(i=e[r+1],r++),n.compare(i)<0)break;e[r]=n,e[t]=i,t=r}}var _r=class{constructor(e,t,n){this.minPoint=n,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=hr.from(e,t,n)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){br(this.active,e),br(this.activeTo,e),br(this.activeRank,e),this.minActive=Sr(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:i}=this.cursor;for(;t<this.activeRank.length&&(i-this.activeRank[t]||r-this.activeTo[t])>0;)t++;xr(this.active,t,n),xr(this.activeTo,t,r),xr(this.activeRank,t,i),e&&xr(e,t,this.cursor.from),this.minActive=Sr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&br(n,r)}else if(!this.cursor.value){this.to=this.endSide=1e9;break}else if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let e=this.cursor.value;if(!e.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=e,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=e.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}}if(n){this.openStart=0;for(let t=n.length-1;t>=0&&n[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}};function vr(e,t,n,r,i,a){e.goto(t),n.goto(r);let o=r+i,s=r,c=r-t,l=!!a.boundChange;for(let t=!1;;){let r=e.to+c-n.to,i=r||e.endSide-n.endSide,u=i<0?e.to+c:n.to,d=Math.min(u,o);if(e.point||n.point?(e.point&&n.point&&or(e.point,n.point)&&yr(e.activeForPoint(e.to),n.activeForPoint(n.to))||a.comparePoint(s,d,e.point,n.point),t=!1):(t&&a.boundChange(s),d>s&&!yr(e.active,n.active)&&a.compareRange(s,d,e.active,n.active),l&&d<o&&(r||e.openEnd(u)!=n.openEnd(u))&&(t=!0)),u>o)break;s=u,i<=0&&e.next(),i>=0&&n.next()}}function yr(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n]&&!or(e[n],t[n]))return!1;return!0}function br(e,t){for(let n=t,r=e.length-1;n<r;n++)e[n]=e[n+1];e.pop()}function xr(e,t,n){for(let n=e.length-1;n>=t;n--)e[n+1]=e[n];e[t]=n}function Sr(e,t){let n=-1,r=1e9;for(let i=0;i<t.length;i++)(t[i]-r||e[i].endSide-e[n].endSide)<0&&(n=i,r=t[i]);return n}function Cr(e,t,n=e.length){let r=0;for(let i=0;i<n&&i<e.length;)e.charCodeAt(i)==9?(r+=t-r%t,i++):(r++,i=$t(e,i));return r}function wr(e,t,n,r){for(let r=0,i=0;;){if(i>=t)return r;if(r==e.length)break;i+=e.charCodeAt(r)==9?n-i%n:1,r=$t(e,r)}return r===!0?-1:e.length}const Tr=typeof Symbol>`u`?`__ͼ`:Symbol.for(`ͼ`),Er=typeof Symbol>`u`?`__styleSet`+Math.floor(Math.random()*1e8):Symbol(`styleSet`),Dr=typeof globalThis<`u`?globalThis:typeof window<`u`?window:{};var Or=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function i(e,t,a,o){let s=[],c=/^@(\w+)\b/.exec(e[0]),l=c&&c[1]==`keyframes`;if(c&&t==null)return a.push(e[0]+`;`);for(let n in t){let o=t[n];if(/&/.test(n))i(n.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),o,a);else if(o&&typeof o==`object`){if(!c)throw RangeError(`The value of a property (`+n+`) should be a primitive value.`);i(r(n),o,s,l)}else o!=null&&s.push(n.replace(/_.*/,``).replace(/[A-Z]/g,e=>`-`+e.toLowerCase())+`: `+o+`;`)}(s.length||l)&&a.push((n&&!c&&!o?e.map(n):e).join(`, `)+` {`+s.join(` `)+`}`)}for(let t in e)i(r(t),e[t],this.rules)}getRules(){return this.rules.join(`
739
739
  `)}static newName(){let e=Dr[Tr]||1;return Dr[Tr]=e+1,`ͼ`+e.toString(36)}static mount(e,t,n){let r=e[Er],i=n&&n.nonce;r?i&&r.setNonce(i):r=new Ar(e,i),r.mount(Array.isArray(t)?t:[t],e)}};let kr=new Map;for(var Ar=class{constructor(e,t){let n=e.ownerDocument||e,r=n.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let t=kr.get(n);if(t)return e[Er]=t;this.sheet=new r.CSSStyleSheet,kr.set(n,this)}else this.styleTag=n.createElement(`style`),t&&this.styleTag.setAttribute(`nonce`,t);this.modules=[],e[Er]=this}mount(e,t){let n=this.sheet,r=0,i=0;for(let t=0;t<e.length;t++){let a=e[t],o=this.modules.indexOf(a);if(o<i&&o>-1&&(this.modules.splice(o,1),i--,o=-1),o==-1){if(this.modules.splice(i++,0,a),n)for(let e=0;e<a.rules.length;e++)n.insertRule(a.rules[e],r++)}else{for(;i<o;)r+=this.modules[i++].rules.length;r+=a.rules.length,i++}}if(n)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let e=``;for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+`
740
- `;this.styleTag.textContent=e;let n=t.head||t;this.styleTag.parentNode!=n&&n.insertBefore(this.styleTag,n.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute(`nonce`)!=e&&this.styleTag.setAttribute(`nonce`,e)}},jr={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},Mr={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},Nr=typeof navigator<`u`&&/Mac/.test(navigator.platform),Pr=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Fr=0;Fr<10;Fr++)jr[48+Fr]=jr[96+Fr]=String(Fr);for(var Fr=1;Fr<=24;Fr++)jr[Fr+111]=`F`+Fr;for(var Fr=65;Fr<=90;Fr++)jr[Fr]=String.fromCharCode(Fr+32),Mr[Fr]=String.fromCharCode(Fr);for(var Ir in jr)Mr.hasOwnProperty(Ir)||(Mr[Ir]=jr[Ir]);function Lr(e){var t=!(Nr&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||Pr&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Mr:jr)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}let Rr=typeof navigator<`u`?navigator:{userAgent:``,vendor:``,platform:``},zr=typeof document<`u`?document:{documentElement:{style:{}}};const Br=/Edge\/(\d+)/.exec(Rr.userAgent),Vr=/MSIE \d/.test(Rr.userAgent),Hr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Rr.userAgent),Ur=!!(Vr||Hr||Br),Wr=!Ur&&/gecko\/(\d+)/i.test(Rr.userAgent),Gr=!Ur&&/Chrome\/(\d+)/.exec(Rr.userAgent),Kr=`webkitFontSmoothing`in zr.documentElement.style,qr=!Ur&&/Apple Computer/.test(Rr.vendor),Jr=qr&&(/Mobile\/\w+/.test(Rr.userAgent)||Rr.maxTouchPoints>2);var I={mac:Jr||/Mac/.test(Rr.platform),windows:/Win/.test(Rr.platform),linux:/Linux|X11/.test(Rr.platform),ie:Ur,ie_version:Vr?zr.documentMode||6:Hr?+Hr[1]:Br?+Br[1]:0,gecko:Wr,gecko_version:Wr?+(/Firefox\/(\d+)/.exec(Rr.userAgent)||[0,0])[1]:0,chrome:!!Gr,chrome_version:Gr?+Gr[1]:0,ios:Jr,android:/Android\b/.test(Rr.userAgent),webkit:Kr,webkit_version:Kr?+(/\bAppleWebKit\/(\d+)/.exec(Rr.userAgent)||[0,0])[1]:0,safari:qr,safari_version:qr?+(/\bVersion\/(\d+(\.\d+)?)/.exec(Rr.userAgent)||[0,0])[1]:0,tabSize:zr.documentElement.style.tabSize==null?`-moz-tab-size`:`tab-size`};function Yr(e,t){for(let n in e)n==`class`&&t.class?t.class+=` `+e.class:n==`style`&&t.style?t.style+=`;`+e.style:t[n]=e[n];return t}const Xr=Object.create(null);function Zr(e,t,n){if(e==t)return!0;e||=Xr,t||=Xr;let r=Object.keys(e),i=Object.keys(t);if(r.length-(n&&r.indexOf(n)>-1?1:0)!=i.length-(n&&i.indexOf(n)>-1?1:0))return!1;for(let a of r)if(a!=n&&(i.indexOf(a)==-1||e[a]!==t[a]))return!1;return!0}function Qr(e,t){for(let n=e.attributes.length-1;n>=0;n--){let r=e.attributes[n].name;t[r]??e.removeAttribute(r)}for(let n in t){let r=t[n];n==`style`?e.style.cssText=r:e.getAttribute(n)!=r&&e.setAttribute(n,r)}}function $r(e,t,n){let r=!1;if(t)for(let i in t)n&&i in n||(r=!0,i==`style`?e.style.cssText=``:e.removeAttribute(i));if(n)for(let i in n)t&&t[i]==n[i]||(r=!0,i==`style`?e.style.cssText=n[i]:e.setAttribute(i,n[i]));return r}function ei(e){let t=Object.create(null);for(let n=0;n<e.attributes.length;n++){let r=e.attributes[n];t[r.name]=r.value}return t}var ti=class{eq(e){return!1}updateDOM(e,t,n){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},ni=(function(e){return e[e.Text=0]=`Text`,e[e.WidgetBefore=1]=`WidgetBefore`,e[e.WidgetAfter=2]=`WidgetAfter`,e[e.WidgetRange=3]=`WidgetRange`,e})(ni||={}),L=class extends ar{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new ri(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ai(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:i,end:a}=oi(e,t);n=(i?t?-3e8:-1:5e8)-1,r=(a?t?2e8:1:-6e8)+1}return new ai(e,n,r,t,e.widget||null,!0)}static line(e){return new ii(e)}static set(e,t=!1){return F.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};L.none=F.empty;var ri=class e extends L{constructor(e){let{start:t,end:n}=oi(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||`span`,this.attrs=e.class&&e.attributes?Yr(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Xr}eq(t){return this==t||t instanceof e&&this.tagName==t.tagName&&Zr(this.attrs,t.attrs)}range(e,t=e){if(e>=t)throw RangeError(`Mark decorations may not be empty`);return super.range(e,t)}};ri.prototype.point=!1;var ii=class e extends L{constructor(e){super(-2e8,-2e8,null,e)}eq(t){return t instanceof e&&this.spec.class==t.spec.class&&Zr(this.spec.attributes,t.spec.attributes)}range(e,t=e){if(t!=e)throw RangeError(`Line decoration ranges must be zero-length`);return super.range(e,t)}};ii.prototype.mapMode=an.TrackBefore,ii.prototype.point=!0;var ai=class e extends L{constructor(e,t,n,r,i,a){super(t,n,i,e),this.block=r,this.isReplace=a,this.mapMode=r?t<=0?an.TrackBefore:an.TrackAfter:an.TrackDel}get type(){return this.startSide==this.endSide?this.startSide<=0?ni.WidgetBefore:ni.WidgetAfter:ni.WidgetRange}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof e&&si(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw RangeError(`Invalid range for replacement decoration`);if(!this.isReplace&&t!=e)throw RangeError(`Widget decorations can only have zero-length ranges`);return super.range(e,t)}};ai.prototype.point=!0;function oi(e,t=!1){let{inclusiveStart:n,inclusiveEnd:r}=e;return n??=e.inclusive,r??=e.inclusive,{start:n??t,end:r??t}}function si(e,t){return e==t||!!(e&&t&&e.compare(t))}function ci(e,t,n,r=0){let i=n.length-1;i>=0&&n[i]+r>=e?n[i]=Math.max(n[i],t):n.push(e,t)}var li=class e extends ar{constructor(e,t,n){super(),this.tagName=e,this.attributes=t,this.rank=n}eq(t){return t==this||t instanceof e&&this.tagName==t.tagName&&Zr(this.attributes,t.attributes)}static create(t){return new e(t.tagName,t.attributes||Xr,t.rank==null?50:Math.max(0,Math.min(t.rank,100)))}static set(e,t=!1){return F.of(e,t)}};li.prototype.startSide=li.prototype.endSide=-1;function ui(e){let t;return t=e.nodeType==11?e.getSelection?e:e.ownerDocument:e,t.getSelection()}function di(e,t){return t?e==t||e.contains(t.nodeType==1?t:t.parentNode):!1}function fi(e,t){if(!t.anchorNode)return!1;try{return di(e,t.anchorNode)}catch{return!1}}function pi(e){return e.nodeType==3?Ai(e,0,e.nodeValue.length).getClientRects():e.nodeType==1?e.getClientRects():[]}function mi(e,t,n,r){return n?_i(e,t,n,r,-1)||_i(e,t,n,r,1):!1}function hi(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t}function gi(e){return e.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}function _i(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:vi(e))){if(e.nodeName==`DIV`)return!1;let n=e.parentNode;if(!n||n.nodeType!=1)return!1;t=hi(e)+(i<0?0:1),e=n}else if(e.nodeType==1){if(e=e.childNodes[t+(i<0?-1:0)],e.nodeType==1&&e.contentEditable==`false`)return!1;t=i<0?vi(e):0}else return!1}}function vi(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function yi(e,t){let{left:n,right:r}=e;if(n==r)return e;let i=t?n:r;return{left:i,right:i,top:e.top,bottom:e.bottom}}function bi(e){let t=e.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.innerWidth,top:0,bottom:e.innerHeight}}function xi(e,t){let n=t.width/e.offsetWidth,r=t.height/e.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(t.width-e.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(t.height-e.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function Si(e,t,n,r,i,a,o,s){let c=e.ownerDocument,l=c.defaultView||window;for(let u=e,d=!1;u&&!d;)if(u.nodeType==1){let e,f=u==c.body,p=1,m=1;if(f)e=bi(l);else{if(/^(fixed|sticky)$/.test(getComputedStyle(u).position)&&(d=!0),u.scrollHeight<=u.clientHeight&&u.scrollWidth<=u.clientWidth){u=u.assignedSlot||u.parentNode;continue}let t=u.getBoundingClientRect();({scaleX:p,scaleY:m}=xi(u,t)),e={left:t.left,right:t.left+u.clientWidth*p,top:t.top,bottom:t.top+u.clientHeight*m}}let h=0,g=0;if(i==`nearest`)t.top<e.top+o?(g=t.top-(e.top+o),n>0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+o)):t.bottom>e.bottom-o&&(g=t.bottom-e.bottom+o,n<0&&t.top-g<e.top&&(g=t.top-(e.top+o)));else{let r=t.bottom-t.top,a=e.bottom-e.top;g=(i==`center`&&r<=a?t.top+r/2-a/2:i==`start`||i==`center`&&n<0?t.top-o:t.bottom-a+o)-e.top}if(r==`nearest`?t.left<e.left+a?(h=t.left-(e.left+a),n>0&&t.right>e.right+h&&(h=t.right-e.right+a)):t.right>e.right-a&&(h=t.right-e.right+a,n<0&&t.left<e.left+h&&(h=t.left-(e.left+a))):h=(r==`center`?t.left+(t.right-t.left)/2-(e.right-e.left)/2:r==`start`==s?t.left-a:t.right-(e.right-e.left)+a)-e.left,h||g)if(f)l.scrollBy(h,g);else{let e=0,n=0;if(g){let e=u.scrollTop;u.scrollTop+=g/m,n=(u.scrollTop-e)*m}if(h){let t=u.scrollLeft;u.scrollLeft+=h/p,e=(u.scrollLeft-t)*p}t={left:t.left-e,top:t.top-n,right:t.right-e,bottom:t.bottom-n},e&&Math.abs(e-h)<1&&(r=`nearest`),n&&Math.abs(n-g)<1&&(i=`nearest`)}if(f)break;(t.top<e.top||t.bottom>e.bottom||t.left<e.left||t.right>e.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),u=u.assignedSlot||u.parentNode}else if(u.nodeType==11)u=u.host;else break}function Ci(e,t=!0){let n=e.ownerDocument,r=null,i=null;for(let a=e.parentNode;a&&!(a==n.body||(!t||r)&&i);)if(a.nodeType==1)!i&&a.scrollHeight>a.clientHeight&&(i=a),t&&!r&&a.scrollWidth>a.clientWidth&&(r=a),a=a.assignedSlot||a.parentNode;else if(a.nodeType==11)a=a.host;else break;return{x:r,y:i}}var wi=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?vi(t):0),n,Math.min(e.focusOffset,n?vi(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}};function Ti(e){let t=[];for(let n=e;n;n=n.nodeType==11?n.host:n.parentNode)n.nodeType==1&&t.push({node:n,left:n.scrollLeft,top:n.scrollTop});return t}function Ei(e,t=!0){for(let{node:n,left:r,top:i}of e)t&&n.scrollTop!=i&&(n.scrollTop=i),n.scrollLeft!=r&&(n.scrollLeft=r)}let Di=null;I.safari&&I.safari_version>=26&&(Di=!1);function Oi(e){if(e.setActive)return e.setActive();if(Di)return e.focus(Di);let t=Ti(e);e.focus(Di==null?{get preventScroll(){return Di={preventScroll:!0},!0}}:void 0),Di||(Di=!1,Ei(t))}let ki;function Ai(e,t,n=t){let r=ki||=document.createRange();return r.setEnd(e,n),r.setStart(e,t),r}function ji(e,t,n,r){let i={key:t,code:t,keyCode:n,which:n,cancelable:!0};r&&({altKey:i.altKey,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,metaKey:i.metaKey}=r);let a=new KeyboardEvent(`keydown`,i);a.synthetic=!0,e.dispatchEvent(a);let o=new KeyboardEvent(`keyup`,i);return o.synthetic=!0,e.dispatchEvent(o),a.defaultPrevented||o.defaultPrevented}function Mi(e){for(;e;){if(e&&(e.nodeType==9||e.nodeType==11&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}function Ni(e,t){let n=t.focusNode,r=t.focusOffset;if(!n||t.anchorNode!=n||t.anchorOffset!=r)return!1;for(r=Math.min(r,vi(n));;)if(r){if(n.nodeType!=1)return!1;let e=n.childNodes[r-1];e.contentEditable==`false`?r--:(n=e,r=vi(n))}else if(n==e)return!0;else r=hi(n),n=n.parentNode}function Pi(e){return e instanceof Window?e.pageYOffset>Math.max(0,e.document.documentElement.scrollHeight-e.innerHeight-4):e.scrollTop>Math.max(1,e.scrollHeight-e.clientHeight-4)}function Fi(e,t){for(let n=e,r=t;;)if(n.nodeType==3&&r>0)return{node:n,offset:r};else if(n.nodeType==1&&r>0){if(n.contentEditable==`false`)return null;n=n.childNodes[r-1],r=vi(n)}else if(n.parentNode&&!gi(n))r=hi(n),n=n.parentNode;else return null}function Ii(e,t){for(let n=e,r=t;;)if(n.nodeType==3&&r<n.nodeValue.length)return{node:n,offset:r};else if(n.nodeType==1&&r<n.childNodes.length){if(n.contentEditable==`false`)return null;n=n.childNodes[r],r=0}else if(n.parentNode&&!gi(n))r=hi(n)+1,n=n.parentNode;else return null}var Li=class e{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(t,n){return new e(t.parentNode,hi(t),n)}static after(t,n){return new e(t.parentNode,hi(t)+1,n)}},R=(function(e){return e[e.LTR=0]=`LTR`,e[e.RTL=1]=`RTL`,e})(R||={});const Ri=R.LTR,zi=R.RTL;function Bi(e){let t=[];for(let n=0;n<e.length;n++)t.push(1<<e[n]);return t}const Vi=Bi(`88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008`),Hi=Bi(`4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333`),Ui=Object.create(null),Wi=[];for(let e of[`()`,`[]`,`{}`]){let t=e.charCodeAt(0),n=e.charCodeAt(1);Ui[t]=n,Ui[n]=-t}function Gi(e){return e<=247?Vi[e]:1424<=e&&e<=1524?2:1536<=e&&e<=1785?Hi[e-1536]:1774<=e&&e<=2220?4:8192<=e&&e<=8204?256:64336<=e&&e<=65023?4:1}const Ki=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;var qi=class{get dir(){return this.level%2?zi:Ri}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let i=-1;for(let a=0;a<e.length;a++){let o=e[a];if(o.from<=t&&o.to>=t){if(o.level==n)return a;(i<0||(r==0?e[i].level>o.level:r<0?o.from<t:o.to>t))&&(i=a)}}if(i<0)throw RangeError(`Index out of range`);return i}};function Ji(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.from!=i.from||r.to!=i.to||r.direction!=i.direction||!Ji(r.inner,i.inner))return!1}return!0}const z=[];function Yi(e,t,n,r,i){for(let a=0;a<=r.length;a++){let o=a?r[a-1].to:t,s=a<r.length?r[a].from:n,c=a?256:i;for(let t=o,n=c,r=c;t<s;t++){let i=Gi(e.charCodeAt(t));i==512?i=n:i==8&&r==4&&(i=16),z[t]=i==4?2:i,i&7&&(r=i),n=i}for(let e=o,t=c,r=c;e<s;e++){let i=z[e];if(i==128)e<s-1&&t==z[e+1]&&t&24?i=z[e]=t:z[e]=256;else if(i==64){let i=e+1;for(;i<s&&z[i]==64;)i++;let a=e&&t==8||i<n&&z[i]==8?r==1?1:8:256;for(let t=e;t<i;t++)z[t]=a;e=i-1}else i==8&&r==1&&(z[e]=1);t=i,i&7&&(r=i)}}}function Xi(e,t,n,r,i){let a=i==1?2:1;for(let o=0,s=0,c=0;o<=r.length;o++){let l=o?r[o-1].to:t,u=o<r.length?r[o].from:n;for(let t=l,n,r,o;t<u;t++)if(r=Ui[n=e.charCodeAt(t)])if(r<0){for(let e=s-3;e>=0;e-=3)if(Wi[e+1]==-r){let n=Wi[e+2],r=n&2?i:n&4?n&1?a:i:0;r&&(z[t]=z[Wi[e]]=r),s=e;break}}else if(Wi.length==189)break;else Wi[s++]=t,Wi[s++]=n,Wi[s++]=c;else if((o=z[t])==2||o==1){let e=o==i;c=+!e;for(let t=s-3;t>=0;t-=3){let n=Wi[t+2];if(n&2)break;if(e)Wi[t+2]|=2;else{if(n&4)break;Wi[t+2]|=4}}}}}function Zi(e,t,n,r){for(let i=0,a=r;i<=n.length;i++){let o=i?n[i-1].to:e,s=i<n.length?n[i].from:t;for(let c=o;c<s;){let o=z[c];if(o==256){let o=c+1;for(;;)if(o==s){if(i==n.length)break;o=n[i++].to,s=i<n.length?n[i].from:t}else if(z[o]==256)o++;else break;let l=a==1,u=l==((o<t?z[o]:r)==1)?l?1:2:r;for(let t=o,r=i,a=r?n[r-1].to:e;t>c;)t==a&&(t=n[--r].from,a=r?n[r-1].to:e),z[--t]=u;c=o}else a=o,c++}}}function Qi(e,t,n,r,i,a,o){let s=r%2?2:1;if(r%2==i%2)for(let c=t,l=0;c<n;){let t=!0,u=!1;if(l==a.length||c<a[l].from){let e=z[c];e!=s&&(t=!1,u=e==16)}let d=!t&&s==1?[]:null,f=t?r:r+1,p=c;run:for(;;)if(l<a.length&&p==a[l].from){if(u)break run;let m=a[l];if(!t)for(let e=m.to,t=l+1;;){if(e==n)break run;if(t<a.length&&a[t].from==e)e=a[t++].to;else if(z[e]==s)break run;else break}l++,d?d.push(m):(m.from>c&&o.push(new qi(c,m.from,f)),$i(e,m.direction==Ri==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.to),p=m.to}else if(p==n||(t?z[p]!=s:z[p]==s))break;else p++;d?Qi(e,c,p,r+1,i,d,o):c<p&&o.push(new qi(c,p,f)),c=p}else for(let c=n,l=a.length;c>t;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=z[c-1];e!=s&&(n=!1,u=e==16)}let d=!n&&s==1?[]:null,f=n?r:r+1,p=c;run:for(;;)if(l&&p==a[l-1].to){if(u)break run;let m=a[--l];if(!n)for(let e=m.from,n=l;;){if(e==t)break run;if(n&&a[n-1].to==e)e=a[--n].from;else if(z[e-1]==s)break run;else break}d?d.push(m):(m.to<c&&o.push(new qi(m.to,c,f)),$i(e,m.direction==Ri==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.from),p=m.from}else if(p==t||(n?z[p-1]!=s:z[p-1]==s))break;else p--;d?Qi(e,p,c,r+1,i,d,o):p<c&&o.push(new qi(p,c,f)),c=p}}function $i(e,t,n,r,i,a,o){let s=t%2?2:1;Yi(e,i,a,r,s),Xi(e,i,a,r,s),Zi(i,a,r,s),Qi(e,i,a,t,n,r,o)}function ea(e,t,n){if(!e)return[new qi(0,0,+(t==zi))];if(t==Ri&&!n.length&&!Ki.test(e))return ta(e.length);if(n.length)for(;e.length>z.length;)z[z.length]=256;let r=[],i=t==Ri?0:1;return $i(e,i,i,n,0,e.length,r),r}function ta(e){return[new qi(0,e,0)]}let na=``;function ra(e,t,n,r,i){let a=r.head-e.from,o=qi.find(t,a,r.bidiLevel??-1,r.assoc),s=t[o],c=s.side(i,n);if(a==c){let e=o+=i?1:-1;if(e<0||e>=t.length)return null;s=t[o=e],a=s.side(!i,n),c=s.side(i,n)}let l=A(e.text,a,s.forward(i,n));(l<s.from||l>s.to)&&(l=c),na=e.text.slice(Math.min(a,l),Math.max(a,l));let u=o==(i?t.length-1:0)?null:t[o+(i?1:-1)];return u&&l==c&&u.level+ +!i<s.level?j.cursor(u.side(!i,n)+e.from,u.forward(i,n)?1:-1,u.level):j.cursor(l+e.from,s.forward(i,n)?-1:1,s.level)}function ia(e,t,n){for(let r=t;r<n;r++){let t=Gi(e.charCodeAt(r));if(t==1)return Ri;if(t==2||t==4)return zi}return Ri}const aa=M.define(),oa=M.define(),sa=M.define(),ca=M.define(),la=M.define(),ua=M.define(),da=M.define(),fa=M.define(),pa=M.define(),ma=M.define({combine:e=>e.some(e=>e)}),ha=M.define({combine:e=>e.some(e=>e)}),ga=M.define();var _a=class e{constructor(e,t,n,r,i,a=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=i,this.isSnapshot=a}map(t){return t.empty?this:new e(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new e(j.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}};const va=N.define({map:(e,t)=>e.map(t)}),ya=N.define();function ba(e,t,n){let r=e.facet(ca);r.length?r[0](t):window.onerror&&window.onerror(String(t),n,void 0,void 0,t)||(n?console.error(n+`:`,t):console.error(t))}const xa=M.define({combine:e=>!e.length||e[0]});let Sa=0;const Ca=M.define({combine(e){return e.filter((t,n)=>{for(let r=0;r<n;r++)if(e[r].plugin==t.plugin)return!1;return!0})}});var wa=class e{constructor(e,t,n,r,i){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.baseExtensions=i(this),this.extension=this.baseExtensions.concat(Ca.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Ca.of({plugin:this,arg:e}))}static define(t,n){let{eventHandlers:r,eventObservers:i,provide:a,decorations:o}=n||{};return new e(Sa++,t,r,i,e=>{let t=[];return o&&t.push(Oa.of(t=>{let n=t.plugin(e);return n?o(n):L.none})),a&&t.push(a(e)),t})}static fromClass(t,n){return e.define((e,n)=>new t(e,n),n)}},Ta=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(!this.value){if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){ba(e.state,t,`CodeMirror plugin crashed`),this.deactivate()}}else if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(ba(e.state,t,`CodeMirror plugin crashed`),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}return this}destroy(e){if(this.value?.destroy)try{this.value.destroy()}catch(t){ba(e.state,t,`CodeMirror plugin crashed`)}}deactivate(){this.spec=this.value=null}};const Ea=M.define(),Da=M.define(),Oa=M.define(),ka=M.define(),Aa=M.define(),ja=M.define(),Ma=M.define();function Na(e,t){let n=e.state.facet(Ma);if(!n.length)return n;let r=n.map(t=>t instanceof Function?t(e):t),i=[];return F.spans(r,t.from,t.to,{point(){},span(e,n,r,a){let o=e-t.from,s=n-t.from,c=i;for(let e=r.length-1;e>=0;e--,a--){let n=r[e].spec.bidiIsolate,i;if(n??=ia(t.text,o,s),a>0&&c.length&&(i=c[c.length-1]).to==o&&i.direction==n)i.to=s,c=i.inner;else{let e={from:o,to:s,direction:n,inner:[]};c.push(e),c=e.inner}}}}),i}const Pa=M.define();function Fa(e){let t=0,n=0,r=0,i=0;for(let a of e.state.facet(Pa)){let o=a(e);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(n=Math.max(n,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(i=Math.max(i,o.bottom)))}return{left:t,right:n,top:r,bottom:i}}const Ia=M.define();var La=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(t){return new e(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toA<n.fromA)break;n=n.join(r),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(t,n){if(n.length==0)return t;let r=[];for(let i=0,a=0,o=0;;){let s=i<t.length?t[i].fromB:1e9,c=a<n.length?n[a]:1e9,l=Math.min(s,c);if(l==1e9)break;let u=l+o,d=l,f=u;for(;;)if(a<n.length&&n[a]<=d){let e=n[a+1];a+=2,d=Math.max(d,e);for(let e=i;e<t.length&&t[e].fromB<=d;e++)o=t[e].toA-t[e].toB;f=Math.max(f,e+o)}else if(i<t.length&&t[i].fromB<=d){let e=t[i++];d=Math.max(d,e.toB),f=Math.max(f,e.toA),o=e.toA-e.toB}else break;r.push(new e(u,f,l,d))}return r}},Ra=class e{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=sn.empty(this.startState.doc.length);for(let e of n)this.changes=this.changes.compose(e.changes);let r=[];this.changes.iterChangedRanges((e,t,n,i)=>r.push(new La(e,t,n,i))),this.changedRanges=r}static create(t,n,r){return new e(t,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}};const za=[];var B=class{constructor(e,t,n=0){this.dom=e,this.length=t,this.flags=n,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return za}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&Qr(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:``)+(this.breakAfter?`#`:``)}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let n=t;for(let t of this.children){if(t==e)return n;n+=t.length+t.breakAfter}throw RangeError(`Invalid child in posBefore`)}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,n){return null}domPosFor(e,t){let n=hi(this.dom),r=this.length?e>0:t>0;return new Li(this.parent.dom,n+ +!!r,e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Ha)return e;return null}static get(e){return e.cmTile}},Ba=class extends B{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,n=null,r,i=e?.node==t?e:null,a=0;for(let o of this.children){if(o.sync(e),a+=o.length+o.breakAfter,r=n?n.nextSibling:t.firstChild,i&&r!=o.dom&&(i.written=!0),o.dom.parentNode==t)for(;r&&r!=o.dom;)r=Va(r);else t.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:t.firstChild,i&&r&&(i.written=!0);r;)r=Va(r);this.length=a}};function Va(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var Ha=class extends Ba{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=B.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],n=this,r=0,i=0;;)if(r==n.children.length){if(!t.length)return;n=n.parent,n.breakAfter&&i++,r=t.pop()}else{let a=n.children[r++];if(a instanceof Ua)t.push(r),n=a,r=0;else{let t=i+a.length,n=e(a,i);if(n!==void 0)return n;i=t+a.breakAfter}}}resolveBlock(e,t){let n,r=-1,i,a=-1;if(this.blockTiles((o,s)=>{let c=s+o.length;if(e>=s&&e<=c){if(o.isWidget()&&t>=-1&&t<=1){if(o.flags&32)return!0;o.flags&16&&(n=void 0)}(s<e||e==c&&(t<-1?o.length:o.covers(1)))&&(!n||!o.isWidget()&&n.isWidget())&&(n=o,r=e-s),(c>e||e==s&&(t>1?o.length:o.covers(-1)))&&(!i||!o.isWidget()&&i.isWidget())&&(i=o,a=e-s)}}),!n&&!i)throw Error(`No tile at position `+e);return n&&t<0||!i?{tile:n,offset:r}:{tile:i,offset:a}}},Ua=class e extends Ba{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,n){let r=new e(n||document.createElement(t.tagName),t);return n||(r.flags|=4),r}},Wa=class e extends Ba{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(t,n,r){let i=new e(n||document.createElement(`div`),t);return(!n||!r)&&(i.flags|=4),i}get domAttrs(){return this.attrs}resolveInline(e,t,n){let r=null,i=-1,a=null,o=-1;function s(e,c){for(let l=0,u=0;l<e.children.length&&u<=c;l++){let d=e.children[l],f=u+d.length;f>=c&&(d.isComposite()?s(d,c-u):(!a||a.isHidden&&(t>0&&!(a.flags&32)||n&&Ka(a,d)))&&(f>c||d.flags&32&&t<=1)?(a=d,o=c-u):(u<c||d.flags&16&&!d.isHidden&&t>=-1)&&(r=d,i=c-u)),u=f}}s(this,e);let c=(t<0?r:a)||r||a;return c?{tile:c,offset:c==r?i:o}:null}coordsIn(e,t,n){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t,n):Ga(this)}domIn(e,t){let n=this.resolveInline(e,t);if(n){let{tile:e,offset:r}=n;if(this.dom.contains(e.dom))return e.isText()?new Li(e.dom,Math.min(e.dom.nodeValue.length,r)):e.domPosFor(r,e.flags&16?1:e.flags&32?-1:t);let i=n.tile.parent,a=!1;for(let e of i.children){if(a)return new Li(e.dom,0);e==n.tile&&(a=!0)}}return new Li(this.dom,0)}};function Ga(e){let t=e.dom.lastChild;if(!t)return e.dom.getBoundingClientRect();let n=pi(t);return n[n.length-1]||null}function Ka(e,t){let n=e.coordsIn(0,1),r=t.coordsIn(0,1);return n&&r&&r.top<n.bottom}var qa=class e extends Ba{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(t,n){let r=new e(n||document.createElement(t.tagName),t);return n||(r.flags|=4),r}},Ja=class e extends B{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,n){let r=this.dom.nodeValue.length;e>r&&(e=r);let i=e,a=e,o=0;e==0&&t<0||e==r&&t>=0?I.chrome||I.gecko||(e?(i--,o=1):a<r&&(a++,o=-1)):t<0?i--:a<r&&a++;let s=Ai(this.dom,i,a).getClientRects();if(!s.length)return null;let c=s[(o?o<0:t>=0)?0:s.length-1];return I.safari&&!o&&c.width==0&&(c=Array.prototype.find.call(s,e=>e.width)||c),n==null?c:yi(c,(o?o>0:t<0)==n)}static of(t,n){let r=new e(n||document.createTextNode(t),t);return n||(r.flags|=2),r}},Ya=class e extends B{constructor(e,t,n,r){super(e,t,r),this.widget=n}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,n){let r=this.widget.coordsAt(this.dom,e,t);if(r)return r;if(n)return yi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let t=this.dom.getClientRects(),n=null;if(!t.length)return null;let r=this.flags&16?!0:this.flags&32?!1:e>0;for(let i=r?t.length-1:0;n=t[i],!(e>0?i==0:i==t.length-1||n.top<n.bottom);i+=r?-1:1);return yi(n,!r)}}get overrideDOMText(){if(!this.length)return k.empty;let{root:e}=this;if(!e)return k.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,n,r,i,a){return a||(a=t.toDOM(n),t.editable||(a.contentEditable=`false`)),new e(a,r,t,i)}},Xa=class extends B{constructor(e){let t=document.createElement(`img`);t.className=`cm-widgetBuffer`,t.setAttribute(`aria-hidden`,`true`),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return k.empty}coordsIn(e,t,n){let r=this.dom.getBoundingClientRect();return n==null?r:yi(r,t>0==n)}},Za=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,n){let{tile:r,index:i,beforeBreak:a,parents:o}=this;for(;e||t>0;)if(!r.isComposite()){let t=r.length;if(i<t&&e){let a=Math.min(e,t-i);n&&n.skip(r,i,i+a),e-=a,i+=a}if(i==t)a=!!r.breakAfter,{tile:r,index:i}=o.pop(),i++;else if(!e)break}else if(a){if(!e)break;n&&n.break(),e--,a=!1}else if(i==r.children.length){if(!e&&!o.length)break;n&&n.leave(r),a=!!r.breakAfter,{tile:r,index:i}=o.pop(),i++}else{let s=r.children[i],c=s.breakAfter;(t>0?s.length<=e:s.length<e)&&(!n||n.skip(s,0,s.length)!==!1||!s.isComposite)?(a=!!c,i++,e-=s.length):(o.push({tile:r,index:i}),r=s,i=0,n&&s.isComposite()&&n.enter(s))}return this.tile=r,this.index=i,this.beforeBreak=a,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},Qa=class{constructor(e,t,n,r){this.from=e,this.to=t,this.wrapper=n,this.rank=r}},$a=class{constructor(e,t,n){this.cache=e,this.root=t,this.blockWrappers=n,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,n,r){this.flushBuffer();let i=this.ensureMarks(t,n),a=i.lastChild;if(a&&a.isText()&&!(a.flags&8)&&a.length+e.length<512){this.cache.reused.set(a,2);let t=i.children[i.children.length-1]=new Ja(a.dom,a.text+e);t.parent=i}else i.append(r||Ja.of(e,this.cache.find(Ja)?.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let n=this.curLine;n.dom!=t.line.dom&&(n.setDOM(this.cache.reused.has(t.line)?lo(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let r=n;for(let e=t.marks.length-1;e>=0;e--){let n=t.marks[e],i=r.lastChild;if(i instanceof qa&&i.mark.eq(n.mark))i.dom!=n.dom&&i.setDOM(lo(n.dom)),r=i;else{if(this.cache.reused.get(n)){let e=B.get(n.dom);e&&e.setDOM(lo(n.dom))}let e=qa.of(n.mark,n.dom);r.append(e),r=e}this.cache.reused.set(n,2)}let i=B.get(e.text);i&&this.cache.reused.set(i,2);let a=new Ja(e.text,e.text.nodeValue);a.flags|=8,this.pos=e.range.toB,r.append(a)}addInlineWidget(e,t,n){let r=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);r||this.flushBuffer();let i=this.ensureMarks(t,n);!r&&!(e.flags&16)&&i.append(this.getBuffer(1)),i.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,n){this.flushBuffer(),this.ensureMarks(t,n).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){e||=oo;let n=Wa.start(e,t||this.cache.find(Wa)?.dom,!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){let n=this.curLine;for(let r=e.length-1;r>=0;r--){let i=e[r],a;if(t>0&&(a=n.lastChild)&&a instanceof qa&&a.mark.eq(i))n=a,t--;else{let e=qa.of(i,this.cache.find(qa,e=>e.mark.eq(i))?.dom);n.append(e),n=e,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!io(this.curLine,!1)||e.dom.nodeName!=`BR`&&e.isWidget()&&!(I.ios&&io(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(fo,0,32)||new Ya(fo.toDOM(),0,fo,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,n=new Qa(e.from,e.to,e.value,t),r=this.wrappers.length;for(;r>0&&(this.wrappers[r-1].rank-n.rank||this.wrappers[r-1].to-n.to)<0;)r--;this.wrappers.splice(r,0,n)}this.wrapperPos=this.pos}getBlockPos(){this.updateBlockWrappers();let e=this.root;for(let t of this.wrappers){let n=e.lastChild;if(t.from<this.pos&&n instanceof Ua&&n.wrapper.eq(t.wrapper))e=n;else{let n=Ua.of(t.wrapper,this.cache.find(Ua,e=>e.wrapper.eq(t.wrapper))?.dom);e.append(n),e=n}}return e}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),n=this.cache.find(Xa,void 0,1);return n&&(n.flags=t),n||new Xa(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},eo=class{constructor(e){this.skipCount=0,this.text=``,this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text=``,this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:t,lineBreak:n,done:r}=this.cursor.next(this.skipCount);if(this.skipCount=0,r)throw Error(`Ran out of text content when drawing inline views`);this.text=t;let i=this.textOff=Math.min(e,t.length);return n?null:t.slice(0,i)}let t=Math.min(this.text.length,this.textOff+e),n=this.text.slice(this.textOff,t);return this.textOff=t,n}};const to=[Ya,Wa,Ja,qa,Xa,Ua,Ha];for(let e=0;e<to.length;e++)to[e].bucket=e;var no=class{constructor(e){this.view=e,this.buckets=to.map(()=>[]),this.index=to.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,n=this.buckets[t];n.length<6?n.push(e):n[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,n=2){let r=e.bucket,i=this.buckets[r],a=this.index[r];for(let e=0;e<i.length;e++){let o=(e+a)%i.length,s=i[o];if((!t||t(s))&&!this.reused.has(s))return i.splice(o,1),o<a&&this.index[r]--,this.reused.set(s,n),s}return null}findWidget(e,t,n){let r=this.buckets[0];if(r.length)for(let i=0,a=0;;i++){if(i==r.length){if(a)return null;a=1,i=0}let o=r[i];if(!this.reused.has(o)&&(a==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return r.splice(i,1),i<this.index[0]&&this.index[0]--,o.widget==e&&o.length==t&&(o.flags&497)==n?(this.reused.set(o,1),o):(this.reused.set(o,2),new Ya(o.dom,t,e,o.flags&-498|n))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},ro=class{constructor(e,t,n,r,i){this.view=e,this.decorations=r,this.disallowBlockEffectsFor=i,this.openWidget=!1,this.openMarks=0,this.cache=new no(e),this.text=new eo(e.state.doc),this.builder=new $a(this.cache,new Ha(e,e.contentDOM),F.iter(n)),this.cache.reused.set(t,2),this.old=new Za(t),this.reuseWalker={skip:(e,t,n)=>{if(this.cache.add(e),e.isComposite())return!1},enter:e=>this.cache.add(e),leave:()=>{},break:()=>{}}}run(e,t){let n=t&&this.getCompositionContext(t.text);for(let r=0,i=0,a=0;;){let o=a<e.length?e[a++]:null,s=o?o.fromA:this.old.root.length;if(s>r){let e=s-r;this.preserve(e,!a,!o),r=s,i+=e}if(!o)break;t&&o.fromA<=t.range.fromA&&o.toA>=t.range.toA?(this.forward(o.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(i,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,n),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,o.toA),this.emit(t.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(i,o.toB)),i=o.toB,r=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,n){let r=co(this.old),i=this.openMarks;this.old.advance(e,n?1:-1,{skip:(e,t,n)=>{if(e.isWidget())if(this.openWidget)this.builder.continueWidget(n-t);else{let a=n>0||t<e.length?Ya.of(e.widget,this.view,n-t,e.flags&496,this.cache.maybeReuse(e)):this.cache.reuse(e);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,r,i),i=r.length)}else if(e.isText())this.builder.ensureLine(null),!t&&n==e.length&&!this.cache.reused.has(e)?this.builder.addText(e.text,r,i,this.cache.reuse(e)):(this.cache.add(e),this.builder.addText(e.text.slice(t,n),r,i)),i=r.length;else if(e.isLine())e.flags&=-2,this.cache.reused.set(e,1),this.builder.addLine(e);else if(e instanceof Xa)this.cache.add(e);else if(e instanceof qa)this.builder.ensureLine(null),this.builder.addMark(e,r,i),this.cache.reused.set(e,1),i=r.length;else return!1;this.openWidget=!1},enter:e=>{e.isLine()?this.builder.addLineStart(e.attrs,this.cache.maybeReuse(e)):(this.cache.add(e),e instanceof qa&&r.unshift(e.mark)),this.openWidget=!1},leave:e=>{e.isLine()?r.length&&=i=0:e instanceof qa&&(r.shift(),i=Math.min(i,r.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let n=null,r=this.builder,i=-1,a=F.spans(this.decorations,e,t,{point:(e,t,a,o,s,c)=>{if(a instanceof ai){if(this.disallowBlockEffectsFor[c]){if(a.block)throw RangeError(`Block decorations may not be specified via plugins`);if(t>this.view.state.doc.lineAt(e).to)throw RangeError(`Decorations that replace line breaks may not be specified via plugins`)}if(i=o.length,s>o.length)r.continueWidget(t-e);else{let i=a.widget||(a.block?uo.block:uo.inline),c=ao(a),l=this.cache.findWidget(i,t-e,c)||Ya.of(i,this.view,t-e,c);a.block?(a.startSide>0&&r.addLineStartIfNotCovered(n),r.addBlockWidget(l)):(r.ensureLine(n),r.addInlineWidget(l,o,s))}n=null}else n=so(n,a);t>e&&this.text.skip(t-e)},span:(e,t,a,o)=>{for(let i=e;i<t;){let s=this.text.next(Math.min(512,t-i));s==null?(r.addLineStartIfNotCovered(n),r.addBreak(),i++):(r.ensureLine(n),r.addText(s,a,i==e?o:a.length),i+=s.length),n=null}i=a.length}});i>-1&&(this.openWidget=a>i),this.openWidget||r.addLineStartIfNotCovered(n),this.openMarks=a}forward(e,t,n=1){t-e<=10?this.old.advance(t-e,n,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,n,this.reuseWalker))}getCompositionContext(e){let t=[],n=null;for(let r=e.parentNode;;r=r.parentNode){let e=B.get(r);if(r==this.view.contentDOM)break;e instanceof qa?t.push(e):e?.isLine()?n=e:e instanceof Ua||(r.nodeName==`DIV`&&!n&&r!=this.view.contentDOM?n=new Wa(r,oo):n||t.push(qa.of(new ri({tagName:r.nodeName.toLowerCase(),attributes:ei(r)}),r)))}return{line:n,marks:t}}};function io(e,t){let n=e=>{for(let r of e.children)if((t?r.isText():r.length)||n(r))return!0;return!1};return n(e)}function ao(e){let t=e.isReplace?(e.startSide<0?64:0)|(e.endSide>0?128:0):e.startSide>0?32:16;return e.block&&(t|=256),t}const oo={class:`cm-line`};function so(e,t){let n=t.spec.attributes,r=t.spec.class;return!n&&!r?e:(e||={class:`cm-line`},n&&Yr(n,e),r&&(e.class+=` `+r),e)}function co(e){let t=[];for(let n=e.parents.length;n>1;n--){let r=n==e.parents.length?e.tile:e.parents[n].tile;r instanceof qa&&t.push(r.mark)}return t}function lo(e){let t=B.get(e);return t&&t.setDOM(e.cloneNode()),e}var uo=class extends ti{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};uo.inline=new uo(`span`),uo.block=new uo(`div`);const fo=new class extends ti{toDOM(){return document.createElement(`br`)}get isHidden(){return!0}get editable(){return!0}};var po=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=L.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Ha(e,e.contentDOM),this.updateInner([new La(0,0,0,e.state.doc.length)],null)}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:e,toA:t})=>t<this.minWidthFrom||e>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(this.domChanged?.newSel?n=this.domChanged.newSel.head:!wo(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?_o(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:n,to:r}=this.hasComposition;t=new La(n,r,e.changes.mapPos(n,-1),e.changes.mapPos(r,1)).addToSet(t.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(I.ie||I.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,a=this.blockWrappers;this.updateDeco();let o=bo(i,this.decorations,e.changes);o.length&&(t=La.extendWithRanges(t,o));let s=So(a,this.blockWrappers,e.changes);return s.length&&(t=La.extendWithRanges(t,s)),r&&!t.some(e=>e.fromA<=r.range.fromA&&e.toA>=r.range.toA)&&(t=r.range.addToSet(t.slice())),this.tile.flags&2&&t.length==0?!1:(this.updateInner(t,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:n}=this.view;n.ignore(()=>{if(t||e.length){let n=this.tile,r=new ro(this.view,n,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&B.get(t.text)&&r.cache.reused.set(B.get(t.text),2),this.tile=r.run(e,t),mo(n,r.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+`px`,this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+`px`:``;let r=I.chrome||I.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||n.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=``});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let e of this.tile.children)e.isWidget()&&e.widget instanceof To&&r.push(e.dom);n.updateGaps(r)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(ya)&&(this.editContextFormatting=e.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:n}=this.tile,r=this.view.root.activeElement,i=r==n,a=!i&&!(this.view.state.facet(xa)||n.tabIndex>-1)&&fi(n,this.view.observer.selectionRange)&&!(r&&n.contains(r));if(!(i||t||a))return;let o=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,c,l;if(s.empty?l=c=this.inlineDOMNearPos(s.anchor,s.assoc||1):(l=this.inlineDOMNearPos(s.head,s.head==s.from?1:-1),c=this.inlineDOMNearPos(s.anchor,s.anchor==s.from?1:-1)),I.gecko&&s.empty&&!this.hasComposition&&ho(c)){let e=document.createTextNode(``);this.view.observer.ignore(()=>c.node.insertBefore(e,c.node.childNodes[c.offset]||null)),c=l=new Li(e,0),o=!0}let u=this.view.observer.selectionRange;(o||!u.focusNode||(!mi(c.node,c.offset,u.anchorNode,u.anchorOffset)||!mi(l.node,l.offset,u.focusNode,u.focusOffset))&&!this.suppressWidgetCursorChange(u,s))&&(this.view.observer.ignore(()=>{I.android&&I.chrome&&n.contains(u.focusNode)&&Co(u.focusNode,n)&&(n.blur(),n.focus({preventScroll:!0}));let e=ui(this.view.root);if(e)if(s.empty){if(I.gecko){let e=vo(c.node,c.offset);if(e&&e!=3){let t=(e==1?Fi:Ii)(c.node,c.offset);t&&(c=new Li(t.node,t.offset))}}e.collapse(c.node,c.offset),s.bidiLevel!=null&&e.caretBidiLevel!==void 0&&(e.caretBidiLevel=s.bidiLevel)}else if(e.extend){e.collapse(c.node,c.offset);try{e.extend(l.node,l.offset)}catch{}}else{let t=document.createRange();s.anchor>s.head&&([c,l]=[l,c]),t.setEnd(l.node,l.offset),t.setStart(c.node,c.offset),e.removeAllRanges(),e.addRange(t)}a&&this.view.root.activeElement==n&&(n.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(c,l)),this.impreciseAnchor=c.precise?null:new Li(u.anchorNode,u.anchorOffset),this.impreciseHead=l.precise?null:new Li(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&mi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=ui(e.root),{anchorNode:r,anchorOffset:i}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let a=this.lineAt(t.head,t.assoc);if(!a)return;let o=a.posAtStart;if(t.head==o||t.head==o+a.length)return;let s=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!s||!c||s.bottom>c.top)return;let l=this.domAtPos(t.head+t.assoc,t.assoc);n.collapse(l.node,l.offset),n.modify(`move`,t.assoc<0?`forward`:`backward`,`lineboundary`),e.observer.readSelectionRange();let u=e.observer.selectionRange;e.docView.posFromDOM(u.anchorNode,u.anchorOffset)!=t.from&&n.collapse(r,i)}posFromDOM(e,t){let n=this.tile.nearest(e);if(!n)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let r=n.posAtStart;if(n.isComposite()){let i;if(e==n.dom)i=n.dom.childNodes[t];else{let r=vi(e)==0?0:t==0?-1:1;for(;;){let t=e.parentNode;if(t==n.dom)break;r==0&&t.firstChild!=t.lastChild&&(r=e==t.firstChild?-1:1),e=t}i=r<0?e:e.nextSibling}if(i==n.dom.firstChild)return r;for(;i&&!B.get(i);)i=i.nextSibling;if(!i)return r+n.length;for(let e=0,t=r;;e++){let r=n.children[e];if(r.dom==i)return t;t+=r.length+r.breakAfter}}else if(n.isText())return e==n.dom?r+t:r+(t?n.length:0);else return r}domAtPos(e,t){let{tile:n,offset:r}=this.tile.resolveBlock(e,t);return n.isWidget()?n.domPosFor(r,t):n.domIn(r,t)}inlineDOMNearPos(e,t){let n,r=-1,i=!1,a,o=-1,s=!1;return this.tile.blockTiles((t,c)=>{if(t.isWidget()){if(t.flags&32&&c>=e)return!0;t.flags&16&&(i=!0)}else{let l=c+t.length;if(c<=e&&(n=t,r=e-c,i=l<e),l>=e&&!a&&(a=t,o=e-c,s=c>e),c>e&&a)return!0}}),!n&&!a?this.domAtPos(e,t):(i&&a?n=null:s&&n&&(a=null),n&&t<0||!a?n.domIn(r,t):a.domIn(o,t))}coordsAt(e,t,n){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof To?null:r.coordsInWidget(i,t,!0):r.coordsIn(i,t,n)}lineAt(e,t){let{tile:n}=this.tile.resolveBlock(e,t);return n.isLine()?n:null}coordsForChar(e){let{tile:t,offset:n}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function r(e,t){if(e.isComposite())for(let n of e.children){if(n.length>=t){let e=r(n,t);if(e)return e}if(t-=n.length,t<0)break}else if(e.isText()&&t<e.length){let n=A(e.text,t);if(n==t)return null;let r=Ai(e.dom,t,n).getClientRects();for(let e=0;e<r.length;e++){let t=r[e];if(e==r.length-1||t.top<t.bottom&&t.left<t.right)return t}}return null}return r(t,n)}measureVisibleLineHeights(e){let t=[],{from:n,to:r}=e,i=this.view.contentDOM.clientWidth,a=i>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,s=this.view.textDirection==R.LTR,c=0,l=(e,u,d)=>{for(let f=0;f<e.children.length&&!(u>r);f++){let r=e.children[f],p=u+r.length,m=r.dom.getBoundingClientRect(),{height:h}=m;if(d&&!f&&(c+=m.top-d.top),r instanceof Ua)p>n&&l(r,u,m);else if(u>=n&&(c>0&&t.push(-c),t.push(h+c),c=0,a)){let e=r.dom.lastChild,t=e?pi(e):[];if(t.length){let e=t[t.length-1],n=s?e.right-m.left:m.right-e.left;n>o&&(o=n,this.minWidth=i,this.minWidthFrom=u,this.minWidthTo=p)}}d&&f==e.children.length-1&&(c+=d.bottom-m.bottom),u=p+r.breakAfter}};return l(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction==`rtl`?R.RTL:R.LTR}measureTextSize(){let e=this.tile.blockTiles(e=>{if(e.isLine()&&e.children.length&&e.length<=20){let t=0,n;for(let r of e.children){if(!r.isText()||/[^ -~]/.test(r.text))return;let e=pi(r.dom);if(e.length!=1)return;t+=e[0].width,n=e[0].height}if(t)return{lineHeight:e.dom.getBoundingClientRect().height,charWidth:t/e.length,textHeight:n}}});if(e)return e;let t=document.createElement(`div`),n,r,i;return t.className=`cm-line`,t.style.width=`99999px`,t.style.position=`absolute`,t.textContent=`abc def ghi jkl mno pqr stu`,this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let e=pi(t.firstChild)[0];n=t.getBoundingClientRect().height,r=e&&e.width?e.width/27:7,i=e&&e.height?e.height:n,t.remove()}),{lineHeight:n,charWidth:r,textHeight:i}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let i=r==t.viewports.length?null:t.viewports[r],a=i?i.from-1:this.view.state.doc.length;if(a>n){let r=(t.lineBlockAt(a).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(L.replace({widget:new To(r),block:!0,inclusive:!0,isBlockGap:!0}).range(n,a))}if(!i)break;n=i.to+1}return L.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Oa).map(t=>(this.dynamicDecorationMap[e++]=typeof t==`function`)?t(this.view):t),n=!1,r=this.view.state.facet(Aa).map((e,t)=>{let r=typeof e==`function`;return r&&(n=!0),r?e(this.view):e});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push(F.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(ka).map(e=>typeof e==`function`?e(this.view):e)}scrollIntoView(e){if(e.isSnapshot){let t=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=t.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let t of this.view.state.facet(ga))try{if(t(this.view,e.range,e))return!0}catch(e){ba(this.view.state,e,`scroll handler`)}let{range:t}=e,n=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let i=Fa(this.view),a={left:n.left-i.left,top:n.top-i.top,right:n.right+i.right,bottom:n.bottom+i.bottom},{offsetWidth:o,offsetHeight:s}=this.view.scrollDOM;if(Si(this.view.scrollDOM,a,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,s),-s),this.view.textDirection==R.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.visualViewport.offsetTop)){let e=this.view.docView.lineAt(t.head,1);if(e){let t=Ti(e.dom);e.dom.scrollIntoView({block:`nearest`}),Ei(t,!1)}}}lineHasWidget(e){let t=e=>e.isWidget()||e.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){mo(this.tile)}};function mo(e,t){let n=t?.get(e);if(n!=1){n??e.destroy();for(let n of e.children)mo(n,t)}}function ho(e){return e.node.nodeType==1&&e.node.firstChild&&(e.offset==0||e.node.childNodes[e.offset-1].contentEditable==`false`)&&(e.offset==e.node.childNodes.length||e.node.childNodes[e.offset].contentEditable==`false`)}function go(e,t){let n=e.observer.selectionRange;if(!n.focusNode)return null;let r=Fi(n.focusNode,n.focusOffset),i=Ii(n.focusNode,n.focusOffset),a=r||i;if(i&&r&&i.node!=r.node){let t=B.get(i.node);if(!t||t.isText()&&t.text!=i.node.nodeValue)a=i;else if(e.docView.lastCompositionAfterCursor){let e=B.get(r.node);!e||e.isText()&&e.text!=r.node.nodeValue||(a=i)}}if(e.docView.lastCompositionAfterCursor=a!=r,!a)return null;let o=t-a.offset;return{from:o,to:o+a.node.nodeValue.length,node:a.node}}function _o(e,t,n){let r=go(e,n);if(!r)return null;let{node:i,from:a,to:o}=r,s=i.nodeValue;if(/[\n\r]/.test(s)||e.state.doc.sliceString(r.from,r.to)!=s)return null;let c=t.invertedDesc;return{range:new La(c.mapPos(a),c.mapPos(o),a,o),text:i}}function vo(e,t){return e.nodeType==1?(t&&e.childNodes[t-1].contentEditable==`false`?1:0)|(t<e.childNodes.length&&e.childNodes[t].contentEditable==`false`?2:0):0}let yo=class{constructor(){this.changes=[]}compareRange(e,t){ci(e,t,this.changes)}comparePoint(e,t){ci(e,t,this.changes)}boundChange(e){ci(e,e,this.changes)}};function bo(e,t,n){let r=new yo;return F.compare(e,t,n,r),r.changes}var xo=class{constructor(){this.changes=[]}compareRange(e,t){ci(e,t,this.changes)}comparePoint(){}boundChange(e){ci(e,e,this.changes)}};function So(e,t,n){let r=new xo;return F.compare(e,t,n,r),r.changes}function Co(e,t){for(let n=e;n&&n!=t;n=n.assignedSlot||n.parentNode)if(n.nodeType==1&&n.contentEditable==`false`)return!0;return!1}function wo(e,t){let n=!1;return t&&e.iterChangedRanges((e,r)=>{e<t.to&&r>t.from&&(n=!0)}),n}var To=class extends ti{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement(`div`);return e.className=`cm-gap`,this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+`px`,!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function Eo(e,t,n=1){let r=e.charCategorizer(t),i=e.doc.lineAt(t),a=t-i.from;if(i.length==0)return j.cursor(t);a==0?n=1:a==i.length&&(n=-1);let o=a,s=a;n<0?o=A(i.text,a,!1):s=A(i.text,a);let c=r(i.text.slice(o,s));for(;o>0;){let e=A(i.text,o,!1);if(r(i.text.slice(e,o))!=c)break;o=e}for(;s<i.length;){let e=A(i.text,s);if(r(i.text.slice(s,e))!=c)break;s=e}return j.undirectionalRange(o+i.from,s+i.from)}function Do(e,t,n,r,i){let a=Math.round((r-t.left)*e.defaultCharacterWidth);if(e.lineWrapping&&n.height>e.defaultLineHeight*1.5){let t=e.viewState.heightOracle.textHeight,r=Math.floor((i-n.top-(e.defaultLineHeight-t)*.5)/t);a+=r*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(n.from,n.to);return n.from+wr(o,a,e.state.tabSize)}function Oo(e,t,n){let r=e.lineBlockAt(t);if(Array.isArray(r.type)){let e;for(let i of r.type){if(i.from>t)break;if(!(i.to<t)){if(i.from<t&&i.to>t)return i;(!e||i.type==ni.Text&&(e.type!=i.type||(n<0?i.from<t:i.to>t)))&&(e=i)}}return e||r}return r}function ko(e,t,n,r){let i=Oo(e,t.head,t.assoc||-1),a=!r||i.type!=ni.Text||!(e.lineWrapping||i.widgetLineBreaks)?null:e.coordsAtPos(t.assoc<0&&t.head>i.from?t.head-1:t.head);if(a){let t=e.dom.getBoundingClientRect(),r=e.textDirectionAt(i.from),o=e.posAtCoords({x:n==(r==R.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(o!=null)return j.cursor(o,n?-1:1)}return j.cursor(n?i.to:i.from,n?-1:1)}function Ao(e,t,n,r){let i=e.state.doc.lineAt(t.head),a=e.bidiSpans(i),o=e.textDirectionAt(i.from);for(let s=t,c=null;;){let t=ra(i,a,o,s,n),l=na;if(!t){if(i.number==(n?e.state.doc.lines:1))return s;l=`
741
- `,i=e.state.doc.line(i.number+(n?1:-1)),a=e.bidiSpans(i),t=e.visualLineSide(i,!n)}if(!c){if(!r)return t;c=r(l)}else if(!c(l))return s;s=t}}function jo(e,t,n){let r=e.state.charCategorizer(t),i=r(n);return e=>{let t=r(e);return i==$n.Space&&(i=t),i==t}}function Mo(e,t,n,r){let i=t.head,a=n?1:-1;if(i==(n?e.state.doc.length:0))return j.cursor(i,t.assoc);let o=t.goalColumn,s,c=e.contentDOM.getBoundingClientRect(),l=e.coordsAtPos(i,t.assoc||((t.empty?n:t.head==t.from)?1:-1)),u=e.documentTop;if(l)o??=l.left-c.left,s=a<0?l.top:l.bottom;else{let t=e.viewState.lineBlockAt(i);o??=Math.min(c.right-c.left,e.defaultCharacterWidth*(i-t.from)),s=(a<0?t.top:t.bottom)+u}let d=c.left+o,f=e.viewState.heightOracle.textHeight>>1,p=r??f;for(let t=0;;t+=f){let r=s+(p+t)*a,i=Lo(e,{x:d,y:r},!1,a);if(n?r>c.bottom:r<c.top)return j.cursor(i.pos,i.assoc);let l=e.coordsAtPos(i.pos,i.assoc),u=l?(l.top+l.bottom)/2:0;if(!l||(n?u>s:u<s))return j.cursor(i.pos,i.assoc,void 0,o)}}function No(e,t,n){for(;;){let r=0;for(let i of e)i.between(t-1,t+1,(e,i,a)=>{if(t>e&&t<i){let a=r||n||(t-e<i-t?-1:1);t=a<0?e:i,r=a}});if(!r)return t}}function Po(e,t){let n=null;for(let r=0;r<t.ranges.length;r++){let i=t.ranges[r],a=null;if(i.empty){let t=No(e,i.from,0);t!=i.from&&(a=j.cursor(t,-1))}else{let t=No(e,i.from,-1),n=No(e,i.to,1);(t!=i.from||n!=i.to)&&(a=i.undirectional?j.undirectionalRange(i.from,i.to):j.range(i.from==i.anchor?t:n,i.from==i.head?t:n))}a&&(n||=t.ranges.slice(),n[r]=a)}return n?j.create(n,t.mainIndex):t}function Fo(e,t,n){let r=No(e.state.facet(ja).map(t=>t(e)),n.from,t.head>n.from?-1:1);return r==n.from?n:j.cursor(r,r<n.from?1:-1)}var Io=class{constructor(e,t){this.pos=e,this.assoc=t}};function Lo(e,t,n,r){let i=e.contentDOM.getBoundingClientRect(),a=i.top+e.viewState.paddingTop,{x:o,y:s}=t,c=s-a,l;for(;;){if(c<0)return new Io(0,1);if(c>e.viewState.docHeight)return new Io(e.state.doc.length,-1);if(l=e.elementAtHeight(c),r==null)break;if(l.type==ni.Text){if(r<0?l.to<e.viewport.from:l.from>e.viewport.to)break;let t=e.docView.coordsAt(r<0?l.from:l.to,r>0?-1:1);if(t&&(r<0?t.top<=c+a:t.bottom>=c+a))break}let t=e.viewState.heightOracle.textHeight/2;c=r>0?l.bottom+t:l.top-t}if(e.viewport.from>=l.to||e.viewport.to<=l.from){if(n)return null;if(l.type==ni.Text){let t=Do(e,i,l,o,s);return new Io(t,t==l.from?1:-1)}}if(l.type!=ni.Text)return c<(l.top+l.bottom)/2?new Io(l.from,1):new Io(l.to,-1);let u=e.docView.lineAt(l.from,2);return(!u||u.length!=l.length)&&(u=e.docView.lineAt(l.from,-2)),new Ro(e,o,s,e.textDirectionAt(l.from)).scanTile(u,l.from)}var Ro=class{constructor(e,t,n,r){this.view=e,this.x=t,this.y=n,this.baseDir=r,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[qi.find(r,e-n.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[qi.find(r,e-n.from,-1,t)].dir}bidiIn(e,t){let{spans:n,line:r}=this.bidiSpansAt(e);return n.length>1||n.length&&(n[0].level!=this.baseDir||n[0].to+r.from<t)}scan(e,t,n=!1){let r=0,i=e.length-1,a=new Set,o=this.bidiIn(e[0],e[i]),s,c,l=-1,u=1e9,d;search:for(;r<i;){let n=i-r,f=r+i>>1;adjust:if(a.has(f)){for(let e=1;e<n;e++){let t=f+e;if(t>=i&&(t-=n),!a.has(t)){f=t;break adjust}}break search}a.add(f);let p=t(f),m=0;if(p)for(let e=0;e<p.length;e++){let t=p[e];if(!(t.width==0&&p.length>1))if(t.bottom<this.y)(!s||s.bottom<t.bottom)&&(s=t),m=1;else if(t.top>this.y)(!c||c.top>t.top)&&(c=t),m=-1;else{let e=t.left>this.x?this.x-t.left:t.right<this.x?this.x-t.right:0,n=Math.abs(e);n<u&&(l=f,u=n,d=t),e&&(m=e<0==(this.baseDir==R.LTR)?-1:1)}}m==-1&&(!o||this.baseDirAt(e[f],1))?i=f:m==1&&(!o||this.baseDirAt(e[f+1],-1))&&(r=f+1)}if(!d){if(!c&&!s)return{i:e[0],after:!1};let n=s&&(!c||this.y-s.bottom<c.top-this.y)?s:c;return this.y=(n.top+n.bottom)/2,this.scan(e,t,!0)}if(u&&!n){let{top:n,bottom:r}=d;if(s&&s.bottom>(n+n+r)/3)return this.y=s.bottom-1,this.scan(e,t,!0);if(c&&c.top<(n+r+r)/3)return this.y=c.top+1,this.scan(e,t,!0)}let f=(o?this.dirAt(e[l],1):this.baseDir)==R.LTR;return{i:l,after:this.x>(d.left+d.right)/2==f}}scanText(e,t){let n=[];for(let r=0;r<e.length;r=A(e.text,r))n.push(t+r);n.push(t+e.length);let r=this.scan(n,r=>{let i=n[r]-t,a=n[r+1]-t;return Ai(e.dom,i,a).getClientRects()});return r.after?new Io(n[r.i+1],-1):new Io(n[r.i],1)}scanTile(e,t){if(!e.length)return new Io(t,1);if(e.children.length==1){let n=e.children[0];if(n.isText())return this.scanText(n,t);if(n.isComposite())return this.scanTile(n,t)}let n=[t];for(let r=0,i=t;r<e.children.length;r++)n.push(i+=e.children[r].length);let r=this.scan(n,t=>{let n=e.children[t];return n.flags&48?null:(n.dom.nodeType==1?n.dom:Ai(n.dom,0,n.length)).getClientRects()}),i=e.children[r.i],a=n[r.i];return i.isText()?this.scanText(i,a):i.isComposite()?this.scanTile(i,a):r.after?new Io(n[r.i+1],-1):new Io(a,1)}},zo=class{constructor(e,t){this.points=e,this.view=t,this.text=``,this.lineSeparator=t.state.facet(P.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=`￿`}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r);let e=this.text.length;this.readNode(r);let i=B.get(r),a=r.nextSibling;if(a==t){i?.breakAfter&&!a&&n!=this.view.contentDOM&&this.lineBreak();break}let o=B.get(a);(i&&o?i.breakAfter:(i?i.breakAfter:gi(r))||gi(a)&&(r.nodeName!=`BR`||i?.isWidget())&&this.text.length>e)&&!Vo(a,t)&&this.lineBreak(),r=a}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let i=-1,a=1,o;if(this.lineSeparator?(i=t.indexOf(this.lineSeparator,n),a=this.lineSeparator.length):(o=r.exec(t))&&(i=o.index,a=o[0].length),this.append(t.slice(n,i<0?t.length:i)),i<0)break;if(this.lineBreak(),a>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=a-1);n=i+a}}readNode(e){let t=B.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let e=n.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.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 n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(Bo(e,n.node,n.offset)?t:0))}};function Bo(e,t,n){for(;;){if(!t||n<vi(t))return!1;if(t==e)return!0;n=hi(t)+1,t=t.parentNode}}function Vo(e,t){let n;for(;!(e==t||!e);e=e.nextSibling){let t=B.get(e);if(!t?.isWidget())return!1;t&&(n||=[]).push(t)}if(n){for(let e of n)if(e.overrideDOMText?.length)return!1}return!0}var Ho=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},Uo=class{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text=``,this.domChanged=t>-1;let{impreciseHead:i,impreciseAnchor:a}=e.docView,o=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Wo(e.docView.tile,t,n,0))){let t=i||a?[]:Yo(e),n=new zo(t,e);n.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=n.text,this.newSel=Xo(t,this.bounds.from)}else{let t=e.observer.selectionRange,n=i&&i.node==t.focusNode&&i.offset==t.focusOffset||!di(e.contentDOM,t.focusNode)?o.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),r=a&&a.node==t.anchorNode&&a.offset==t.anchorOffset||!di(e.contentDOM,t.anchorNode)?o.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),s=e.viewport;if((I.ios||I.chrome)&&n!=r&&Math.min(n,r)<=o.main.from&&Math.max(n,r)>=o.main.to&&(s.from>0||s.to<e.state.doc.length)){let t=Math.min(n,r),i=Math.max(n,r),a=s.from-t,o=s.to-i;(a==0||a==1||t==0)&&(o==0||o==-1||i==e.state.doc.length)&&(n=0,r=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(j.range(r,n));else if(e.lineWrapping&&r==n&&!(o.main.empty&&o.main.head==n)&&e.inputState.lastTouchTime>Date.now()-100){let t=e.coordsAtPos(n,-1),r=0;t&&(r=e.inputState.lastTouchY<=t.bottom?-1:1),this.newSel=j.create([j.cursor(n,r)])}else this.newSel=j.single(r,n)}}};function Wo(e,t,n,r){if(e.isComposite()){let i=-1,a=-1,o=-1,s=-1;for(let c=0,l=r,u=r;c<e.children.length;c++){let r=e.children[c],d=l+r.length;if(l<t&&d>n)return Wo(r,t,n,l);if(d>=t&&i==-1&&(i=c,a=l),l>n&&r.dom.parentNode==e.dom){o=c,s=u;break}u=d,l=d+r.breakAfter}return{from:a,to:s<0?r+e.length:s,startDOM:(i?e.children[i-1].dom.nextSibling:null)||e.dom.firstChild,endDOM:o<e.children.length&&o>=0?e.children[o].dom:null}}else if(e.isText())return{from:r,to:r+e.length,startDOM:e.dom,endDOM:e.dom.nextSibling};else return null}function Go(e,t){let n,{newSel:r}=t,{state:i}=e,a=i.selection.main,o=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:e,to:r}=t.bounds,s=a.from,c=null;(o===8||I.android&&t.text.length<r-e)&&(s=a.to,c=`end`);let l=i.doc.sliceString(e,r,`￿`),u,d;!a.empty&&a.from>=e&&a.to<=r&&(t.typeOver||l!=t.text)&&l.slice(0,a.from-e)==t.text.slice(0,a.from-e)&&l.slice(a.to-e)==t.text.slice(u=t.text.length-(l.length-(a.to-e)))?n={from:a.from,to:a.to,insert:k.of(t.text.slice(a.from-e,u).split(`￿`))}:(d=Jo(l,t.text,s-e,c))&&(I.chrome&&o==13&&d.toB==d.from+2&&t.text.slice(d.from,d.toB)==`￿￿`&&d.toB--,n={from:e+d.from,to:e+d.toA,insert:k.of(t.text.slice(d.from,d.toB).split(`￿`))})}else r&&(!e.hasFocus&&i.facet(xa)||Zo(r,a))&&(r=null);if(!n&&!r)return!1;if((I.mac||I.android)&&n&&n.from==n.to&&n.from==a.head-1&&/^\. ?$/.test(n.insert.toString())&&e.contentDOM.getAttribute(`autocorrect`)==`off`?(r&&n.insert.length==2&&(r=j.single(r.main.anchor-1,r.main.head-1)),n={from:n.from,to:n.to,insert:k.of([n.insert.toString().replace(`.`,` `)])}):i.doc.lineAt(a.from).to<a.to&&e.docView.lineHasWidget(a.to)&&e.inputState.insertingTextAt>Date.now()-50?n={from:a.from,to:a.to,insert:i.toText(e.inputState.insertingText)}:I.chrome&&n&&n.from==n.to&&n.from==a.head&&n.insert.toString()==`
742
- `&&e.lineWrapping&&(r&&=j.single(r.main.anchor-1,r.main.head-1),n={from:a.from,to:a.to,insert:k.of([` `])}),n)return Ko(e,n,r,o);if(r&&!Zo(r,a)){let t=!1,n=`select`;return e.inputState.lastSelectionTime>Date.now()-50&&(e.inputState.lastSelectionOrigin==`select`&&(t=!0),n=e.inputState.lastSelectionOrigin,n==`select.pointer`&&(r=Po(i.facet(ja).map(t=>t(e)),r))),e.dispatch({selection:r,scrollIntoView:t,userEvent:n}),!0}else return!1}function Ko(e,t,n,r=-1){if(I.ios&&e.inputState.flushIOSKey(t))return!0;let i=e.state.selection.main;if(I.android&&(t.to==i.to&&(t.from==i.from||t.from==i.from-1&&e.state.sliceDoc(t.from,i.from)==` `)&&t.insert.length==1&&t.insert.lines==2&&ji(e.contentDOM,`Enter`,13)||(t.from==i.from-1&&t.to==i.to&&t.insert.length==0||r==8&&t.insert.length<t.to-t.from&&t.to>i.head)&&ji(e.contentDOM,`Backspace`,8)||t.from==i.from&&t.to==i.to+1&&t.insert.length==0&&ji(e.contentDOM,`Delete`,46)))return!0;let a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o,s=()=>o||=qo(e,t,n);return e.state.facet(ua).some(n=>n(e,t.from,t.to,a,s))||e.dispatch(s()),!0}function qo(e,t,n){let r,i=e.state,a=i.selection.main,o=-1;if(t.from==t.to&&t.from<a.from||t.from>a.to){let n=t.from<a.from?-1:1,r=n<0?a.from:a.to,s=No(i.facet(ja).map(t=>t(e)),r,n);t.from==s&&(o=s)}if(o>-1)r={changes:t,selection:j.cursor(t.from+t.insert.length,-1)};else if(t.from>=a.from&&t.to<=a.to&&t.to-t.from>=(a.to-a.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let n=a.from<t.from?i.sliceDoc(a.from,t.from):``,o=a.to>t.to?i.sliceDoc(t.to,a.to):``;r=i.replaceSelection(e.state.toText(n+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=i.changes(t),s=n&&n.main.to<=o.newLength?n.main:void 0;if(i.selection.ranges.length>1&&(e.inputState.composing>=0||e.inputState.compositionPendingChange)&&t.to<=a.to+10&&t.to>=a.to-10){let c=e.state.sliceDoc(t.from,t.to),l,u=n&&go(e,n.main.head);if(u){let e=t.insert.length-(t.to-t.from);l={from:u.from,to:u.to-e}}else l=e.state.doc.lineAt(a.head);let d=a.to-t.to;r=i.changeByRange(n=>{if(n.from==a.from&&n.to==a.to)return{changes:o,range:s||n.map(o)};let r=n.to-d,u=r-c.length;if(e.state.sliceDoc(u,r)!=c||r>=l.from&&u<=l.to)return{range:n};let f=i.changes({from:u,to:r,insert:t.insert}),p=n.to-a.to;return{changes:f,range:s?j.range(Math.max(0,s.anchor+p),Math.max(0,s.head+p)):n.map(f)}})}else r={changes:o,selection:s&&i.selection.replaceRange(s)}}let s=`input.type`;return(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,s+=`.compose`,e.inputState.compositionFirstChange&&(s+=`.start`,e.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:s,scrollIntoView:!0})}function Jo(e,t,n,r){let i=Math.min(e.length,t.length),a=0;for(;a<i&&e.charCodeAt(a)==t.charCodeAt(a);)a++;if(a==i&&e.length==t.length)return null;let o=e.length,s=t.length;for(;o>0&&s>0&&e.charCodeAt(o-1)==t.charCodeAt(s-1);)o--,s--;if(r==`end`){let e=Math.max(0,a-Math.min(o,s));n-=o+e-a}if(o<a&&e.length<t.length){let e=n<=a&&n>=o?a-n:0;a-=e,s=a+(s-o),o=a}else if(s<a){let e=n<=a&&n>=s?a-n:0;a-=e,o=a+(o-s),s=a}return{from:a,toA:o,toB:s}}function Yo(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=e.observer.selectionRange;return n&&(t.push(new Ho(n,r)),(i!=n||a!=r)&&t.push(new Ho(i,a))),t}function Xo(e,t){if(e.length==0)return null;let n=e[0].pos,r=e.length==2?e[1].pos:n;return n>-1&&r>-1?j.single(n+t,r+t):null}function Zo(e,t){return t.head==e.main.head&&t.anchor==e.main.anchor}var Qo=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText=``,this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,I.safari&&e.contentDOM.addEventListener(`input`,()=>null),I.gecko&&Ps(e.contentDOM.ownerDocument)}handleEvent(e){!ds(this.view,e)||this.ignoreDuringComposition(e)||e.type==`keydown`&&this.keydown(e)||(this.view.updateState==0?this.runHandlers(e.type,e):Promise.resolve().then(()=>this.runHandlers(e.type,e)))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let e of n.observers)e(this.view,t);for(let e of n.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=ts(e),n=this.handlers,r=this.view.contentDOM;for(let e in t)if(e!=`scroll`){let i=!t[e].handlers.length,a=n[e];a&&i!=!a.handlers.length&&(r.removeEventListener(e,this.handleEvent),a=null),a||r.addEventListener(e,this.handleEvent,{passive:i})}for(let e in n)e!=`scroll`&&!t[e]&&r.removeEventListener(e,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&&is.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),I.android&&I.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(I.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(ns.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||rs.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};return t.shiftKey&&I.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&$o(this.view.win)&&(t.shiftKey=!1),this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t},setTimeout(()=>this.flushIOSKey(),250),!0}return 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,ji(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:I.safari&&!I.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 $o(e){return e.visualViewport?e.visualViewport.height*e.visualViewport.scale/e.document.documentElement.clientHeight<.85:!1}function es(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(e){ba(n.state,e)}}}function ts(e){let t=Object.create(null);function n(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let t of e){let e=t.spec,r=e&&e.plugin.domEventHandlers,i=e&&e.plugin.domEventObservers;if(r)for(let e in r){let i=r[e];i&&n(e).handlers.push(es(t.value,i))}if(i)for(let e in i){let r=i[e];r&&n(e).observers.push(es(t.value,r))}}for(let e in fs)n(e).handlers.push(fs[e]);for(let e in ps)n(e).observers.push(ps[e]);return t}const ns=[{key:`Backspace`,keyCode:8,inputType:`deleteContentBackward`},{key:`Enter`,keyCode:13,inputType:`insertParagraph`},{key:`Enter`,keyCode:13,inputType:`insertLineBreak`},{key:`Delete`,keyCode:46,inputType:`deleteContentForward`}],rs=`dthko`,is=[16,17,18,20,91,92,224,225];function as(e){return Math.max(0,e)*.7+8}function os(e,t){return Math.max(Math.abs(e.clientX-t.clientX),Math.abs(e.clientY-t.clientY))}var ss=class{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Ci(e.contentDOM),this.atoms=e.state.facet(ja).map(t=>t(e));let i=e.contentDOM.ownerDocument;i.addEventListener(`mousemove`,this.move=this.move.bind(this)),i.addEventListener(`mouseup`,this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(P.allowMultipleSelections)&&cs(e,t),this.dragging=us(e,t)&&Cs(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&&os(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,i=0,a=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:a}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:i,bottom:o}=this.scrollParents.y.getBoundingClientRect());let s=Fa(this.view);e.clientX-s.left<=r+6?t=-as(r-e.clientX):e.clientX+s.right>=a-6&&(t=as(e.clientX-a)),e.clientY-s.top<=i+6?n=-as(i-e.clientY):e.clientY+s.bottom>=o-6&&(n=as(e.clientY-o)),this.setScrollSpeed(t,n)}up(e){this.dragging??this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener(`mousemove`,this.move),e.removeEventListener(`mouseup`,this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,n=Po(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!n.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:n,userEvent:`select.pointer`}),this.mustSelect=!1}update(e){e.transactions.some(e=>e.isUserEvent(`input.type`))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function cs(e,t){let n=e.state.facet(aa);return n.length?n[0](t):I.mac?t.metaKey:t.ctrlKey}function ls(e,t){let n=e.state.facet(oa);return n.length?n[0](t):I.mac?!t.altKey:!t.ctrlKey}function us(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=ui(e.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let e=0;e<i.length;e++){let n=i[e];if(n.left<=t.clientX&&n.right>=t.clientX&&n.top<=t.clientY&&n.bottom>=t.clientY)return!0}return!1}function ds(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target,r;n!=e.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=B.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(t))return!1;return!0}const fs=Object.create(null),ps=Object.create(null),ms=I.ie&&I.ie_version<15||I.ios&&I.webkit_version<604;function hs(e){let t=e.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement(`textarea`));n.style.cssText=`position: fixed; left: -10000px; top: 10px`,n.focus(),setTimeout(()=>{e.focus(),n.remove(),_s(e,n.value)},50)}function gs(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function _s(e,t){t=gs(e.state,fa,t);let{state:n}=e,r,i=1,a=n.toText(t),o=a.lines==n.selection.ranges.length;if(ks!=null&&n.selection.ranges.every(e=>e.empty)&&ks==a.toString()){let e=-1;r=n.changeByRange(r=>{let s=n.doc.lineAt(r.from);if(s.from==e)return{range:r};e=s.from;let c=n.toText((o?a.line(i++).text:t)+n.lineBreak);return{changes:{from:s.from,insert:c},range:j.cursor(r.from+c.length)}})}else r=o?n.changeByRange(e=>{let t=a.line(i++);return{changes:{from:e.from,to:e.to,insert:t.text},range:j.cursor(e.from+t.length)}}):n.replaceSelection(a);e.dispatch(r,{userEvent:`input.paste`,scrollIntoView:!0})}ps.scroll=e=>{let t=e.inputState;t.lastScrollTop=e.scrollDOM.scrollTop,t.lastScrollLeft=e.scrollDOM.scrollLeft,I.ios&&!t.touchActive&&(t.lastIOSMomentumScroll=Date.now())},ps.wheel=ps.mousewheel=e=>{e.inputState.lastWheelEvent=Date.now()},fs.keydown=(e,t)=>(e.inputState.setSelectionOrigin(`select`),t.keyCode==27&&e.inputState.tabFocusMode!=0&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),ps.touchstart=(e,t)=>{let n=e.inputState,r=t.targetTouches[0];n.touchActive=!0,n.lastTouchTime=Date.now(),r&&(n.lastTouchX=r.clientX,n.lastTouchY=r.clientY),n.setSelectionOrigin(`select.pointer`)},ps.touchmove=e=>{e.inputState.setSelectionOrigin(`select.pointer`)},ps.touchend=(e,t)=>{e.inputState.touchActive=!1},fs.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of e.state.facet(sa))if(n=r(e,t),n)break;if(!n&&t.button==0&&(n=ws(e,t)),n){let r=!e.hasFocus;e.inputState.startMouseSelection(new ss(e,t,n,r)),r&&e.observer.ignore(()=>{Oi(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()});let i=e.inputState.mouseSelection;if(i)return i.start(t),i.dragging===!1}else e.inputState.setSelectionOrigin(`select.pointer`);return!1};function vs(e,t,n,r){if(r==1)return j.cursor(t,n);if(r==2)return Eo(e.state,t,n);{let r=e.docView.lineAt(t,n),i=e.state.doc.lineAt(r?r.posAtEnd:t),a=r?r.posAtStart:i.from,o=r?r.posAtEnd:i.to;return o<e.state.doc.length&&o==i.to&&o++,j.undirectionalRange(a,o)}}const ys=I.ie&&I.ie_version<=11;let bs=null,xs=0,Ss=0;function Cs(e){if(!ys)return e.detail;let t=bs,n=Ss;return bs=e,Ss=Date.now(),xs=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(xs+1)%3:1}function ws(e,t){let n=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),r=Cs(t),i=e.state.selection;return{update(e){e.docChanged&&(n.pos=e.changes.mapPos(n.pos),i=i.map(e.changes))},get(t,a,o){let s=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),c,l=vs(e,s.pos,s.assoc,r);if(n.pos!=s.pos&&!a){let t=vs(e,n.pos,n.assoc,r),i=Math.min(t.from,l.from),a=Math.max(t.to,l.to);l=i<l.from?j.range(i,a,l.assoc):j.range(a,i,l.assoc)}return a?i.replaceRange(i.main.extend(l.from,l.to,l.assoc)):o&&r==1&&i.ranges.length>1&&(c=Ts(i,s.pos))?c:o?i.addRange(l):j.create([l])}}}function Ts(e,t){for(let n=0;n<e.ranges.length;n++){let{from:r,to:i}=e.ranges[n];if(r<=t&&i>=t)return j.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-+(e.mainIndex>n))}return null}fs.dragstart=(e,t)=>{let{selection:{main:n}}=e.state;if(t.target.draggable){let r=e.docView.tile.nearest(t.target);if(r&&r.isWidget()){let e=r.posAtStart,t=e+r.length;(e>=n.to||t<=n.from)&&(n=j.undirectionalRange(e,t))}}let{inputState:r}=e;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,t.dataTransfer&&(t.dataTransfer.setData(`Text`,gs(e.state,pa,e.state.sliceDoc(n.from,n.to))),t.dataTransfer.effectAllowed=`copyMove`),!1},fs.dragend=e=>(e.inputState.draggedContent=null,!1);function Es(e,t,n,r){if(n=gs(e.state,fa,n),!n)return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:a}=e.inputState,o=r&&a&&ls(e,t)?{from:a.from,to:a.to}:null,s={from:i,insert:n},c=e.state.changes(o?[o,s]:s);e.focus(),e.dispatch({changes:c,selection:{anchor:c.mapPos(i,-1),head:c.mapPos(i,1)},userEvent:o?`move.drop`:`input.drop`}),e.inputState.draggedContent=null}fs.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let n=t.dataTransfer.files;if(n&&n.length){let r=Array(n.length),i=0,a=()=>{++i==n.length&&Es(e,t,r.filter(e=>e!=null).join(e.state.lineBreak),!1)};for(let e=0;e<n.length;e++){let t=new FileReader;t.onerror=a,t.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(r[e]=t.result),a()},t.readAsText(n[e])}return!0}else{let n=t.dataTransfer.getData(`Text`);if(n)return Es(e,t,n,!0),!0}return!1},fs.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let n=ms?null:t.clipboardData;return n?(_s(e,n.getData(`text/plain`)||n.getData(`text/uri-list`)),!0):(hs(e),!1)};function Ds(e,t){let n=e.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement(`textarea`));r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout(()=>{r.remove(),e.focus()},50)}function Os(e){let t=[],n=[],r=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),n.push(r));if(!t.length){let i=-1;for(let{from:r}of e.selection.ranges){let a=e.doc.lineAt(r);a.number>i&&(t.push(a.text),n.push({from:a.from,to:Math.min(e.doc.length,a.to+1)})),i=a.number}r=!0}return{text:gs(e,pa,t.join(e.lineBreak)),ranges:n,linewise:r}}let ks=null;fs.copy=fs.cut=(e,t)=>{if(!fi(e.contentDOM,e.observer.selectionRange))return!1;let{text:n,ranges:r,linewise:i}=Os(e.state);if(!n&&!i)return!1;ks=i?n:null,t.type==`cut`&&!e.state.readOnly&&e.dispatch({changes:r,scrollIntoView:!0,userEvent:`delete.cut`});let a=ms?null:t.clipboardData;return a?(a.clearData(),a.setData(`text/plain`,n),!0):(Ds(e,n),!1)};const As=Vn.define();function js(e,t){let n=[];for(let r of e.facet(da)){let i=r(e,t);i&&n.push(i)}return n.length?e.update({effects:n,annotations:As.of(!0)}):null}function Ms(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=js(e.state,t);n?e.dispatch(n):e.update([])}},10)}ps.focus=e=>{e.inputState.lastFocusTime=Date.now(),!e.scrollDOM.scrollTop&&(e.inputState.lastScrollTop||e.inputState.lastScrollLeft)&&(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),Ms(e)},ps.blur=e=>{e.observer.clearSelectionRange(),Ms(e)},ps.compositionstart=ps.compositionupdate=e=>{e.observer.editContext||(e.inputState.compositionFirstChange??(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},ps.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,I.chrome&&I.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then(()=>e.observer.flush()):setTimeout(()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])},50))},ps.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},fs.beforeinput=(e,t)=>{if((t.inputType==`insertText`||t.inputType==`insertCompositionText`)&&(e.inputState.insertingText=t.data,e.inputState.insertingTextAt=Date.now()),t.inputType==`insertReplacementText`&&e.observer.editContext){let n=t.dataTransfer?.getData(`text/plain`),r=t.getTargetRanges();if(n&&r.length){let t=r[0];return Ko(e,{from:e.posAtDOM(t.startContainer,t.startOffset),to:e.posAtDOM(t.endContainer,t.endOffset),insert:e.state.toText(n)},null),!0}}let n;if(I.chrome&&I.android&&(n=ns.find(e=>e.inputType==t.inputType))&&(e.observer.delayAndroidKey(n.key,n.keyCode),n.key==`Backspace`||n.key==`Delete`)){let t=window.visualViewport?.height||0;setTimeout(()=>{(window.visualViewport?.height||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())},100)}return I.ios&&t.inputType==`deleteContentForward`&&e.observer.flushSoon(),I.safari&&t.inputType==`insertText`&&e.inputState.composing>=0&&setTimeout(()=>ps.compositionend(e,t),20),!1};const Ns=new Set;function Ps(e){Ns.has(e)||(Ns.add(e),e.addEventListener(`copy`,()=>{}),e.addEventListener(`cut`,()=>{}))}const Fs=[`pre-wrap`,`normal`,`pre-line`,`break-spaces`];let Is=!1;function Ls(){Is=!1}var Rs=class{constructor(e){this.lineWrapping=e,this.doc=k.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Fs.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];r<0?n++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,n,r,i,a){let o=Fs.indexOf(e)>-1,s=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=i,s){this.heightSamples={};for(let e=0;e<a.length;e++){let t=a[e];t<0?e++:this.heightSamples[Math.floor(t*10)]=!0}}return s}},zs=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},Bs=class e{constructor(e,t,n,r,i){this.from=e,this.length=t,this.top=n,this.height=r,this._content=i}get type(){return typeof this._content==`number`?ni.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 ai?this._content.widget:null}get widgetLineBreaks(){return typeof this._content==`number`?this._content:0}join(t){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new e(this.from,this.length+t.length,this.top,this.height+t.height,n)}},V=(function(e){return e[e.ByPos=0]=`ByPos`,e[e.ByHeight=1]=`ByHeight`,e[e.ByPosNoHeight=2]=`ByPosNoHeight`,e})(V||={});const Vs=.001;var Hs=class e{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Vs&&(Is=!0),this.height=e)}replace(t,n,r){return e.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let i=this,a=n.doc;for(let o=r.length-1;o>=0;o--){let{fromA:s,toA:c,fromB:l,toB:u}=r[o],d=i.lineAt(s,V.ByPosNoHeight,n.setDoc(t),0,0),f=d.to>=c?d:i.lineAt(c,V.ByPosNoHeight,n,0,0);for(u+=f.to-c,c=f.to;o>0&&d.from<=r[o-1].toA;)s=r[o-1].fromA,l=r[o-1].fromB,o--,s<d.from&&(d=i.lineAt(s,V.ByPosNoHeight,n,0,0));l+=d.from-s,s=d.from;let p=Xs.build(n.setDoc(a),e,l,u);i=Us(i,i.replace(s,c,p))}return i.updateHeight(n,0)}static empty(){return new Ks(0,0,0)}static of(t){if(t.length==1)return t[0];let n=0,r=t.length,i=0,a=0;for(;;)if(n==r)if(i>a*2){let e=t[n-1];e.break?t.splice(--n,1,e.left,null,e.right):t.splice(--n,1,e.left,e.right),r+=1+e.break,i-=e.size}else if(a>i*2){let e=t[r];e.break?t.splice(r,1,e.left,null,e.right):t.splice(r,1,e.left,e.right),r+=2+e.break,a-=e.size}else break;else if(i<a){let e=t[n++];e&&(i+=e.size)}else{let e=t[--r];e&&(a+=e.size)}let o=0;return t[n-1]==null?(o=1,n--):t[n]??(o=1,r++),new Js(e.of(t.slice(0,n)),o,e.of(t.slice(r)))}};function Us(e,t){return e==t?e:(e.constructor!=t.constructor&&(Is=!0),t)}Hs.prototype.size=1;const Ws=L.replace({});var Gs=class extends Hs{constructor(e,t,n){super(e,t),this.deco=n,this.spaceAbove=0}mainBlock(e,t){return new Bs(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,n,r){return this.spaceAbove&&e<n+this.spaceAbove?new Bs(r,0,n,this.spaceAbove,Ws):this.mainBlock(n,r)}lineAt(e,t,n,r,i){let a=this.mainBlock(r,i);return this.spaceAbove?this.blockAt(0,n,r,i).join(a):a}forEachLine(e,t,n,r,i,a){e<=i+this.length&&t>=i&&a(this.lineAt(0,V.ByPos,n,r,i))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}},Ks=class e extends Gs{constructor(e,t,n){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=n}mainBlock(e,t){return new Bs(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,n,r){let i=r[0];return r.length==1&&(i instanceof e||i instanceof qs&&i.flags&4)&&Math.abs(this.length-i.length)<10?(i instanceof qs?i=new e(i.length,this.height,this.spaceAbove):i.height=this.height,this.outdated||(i.outdated=!1),i):Hs.of(r)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(n||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:``}${this.widgetHeight?`:`+this.widgetHeight:``})`}},qs=class e extends Hs{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,i=r-n+1,a,o=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*i);a=t/i,this.length>i+1&&(o=(this.height-t)/(this.length-i-1))}else a=this.height/i;return{firstLine:n,lastLine:r,perLine:a,perChar:o}}blockAt(e,t,n,r){let{firstLine:i,lastLine:a,perLine:o,perChar:s}=this.heightMetrics(t,r);if(t.lineWrapping){let i=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length)),a=t.doc.lineAt(i),c=o+a.length*s,l=Math.max(n,e-c/2);return new Bs(a.from,a.length,l,c,0)}else{let r=Math.max(0,Math.min(a-i,Math.floor((e-n)/o))),{from:s,length:c}=t.doc.line(i+r);return new Bs(s,c,n+o*r,o,0)}}lineAt(e,t,n,r,i){if(t==V.ByHeight)return this.blockAt(e,n,r,i);if(t==V.ByPosNoHeight){let{from:t,to:r}=n.doc.lineAt(e);return new Bs(t,r-t,0,0,0)}let{firstLine:a,perLine:o,perChar:s}=this.heightMetrics(n,i),c=n.doc.lineAt(e),l=o+c.length*s,u=c.number-a,d=r+o*u+s*(c.from-i-u);return new Bs(c.from,c.length,Math.max(r,Math.min(d,r+this.height-l)),l,0)}forEachLine(e,t,n,r,i,a){e=Math.max(e,i),t=Math.min(t,i+this.length);let{firstLine:o,perLine:s,perChar:c}=this.heightMetrics(n,i);for(let l=e,u=r;l<=t;){let t=n.doc.lineAt(l);if(l==e){let n=t.number-o;u+=s*n+c*(e-i-n)}let r=s+c*t.length;a(new Bs(t.from,t.length,u,r,0)),u+=r,l=t.to+1}}replace(t,n,r){let i=this.length-n;if(i>0){let t=r[r.length-1];t instanceof e?r[r.length-1]=new e(t.length+i):r.push(null,new e(i-1))}if(t>0){let n=r[0];n instanceof e?r[0]=new e(t+n.length):r.unshift(new e(t-1),null)}return Hs.of(r)}decomposeLeft(t,n){n.push(new e(t-1),null)}decomposeRight(t,n){n.push(null,new e(this.length-t-1))}updateHeight(t,n=0,r=!1,i){let a=n+this.length;if(i&&i.from<=n+this.length&&i.more){let r=[],o=Math.max(n,i.from),s=-1;for(i.from>n&&r.push(new e(i.from-n-1).updateHeight(t,n));o<=a&&i.more;){let e=t.doc.lineAt(o).length;r.length&&r.push(null);let n=i.heights[i.index++],a=0;n<0&&(a=-n,n=i.heights[i.index++]),s==-1?s=n:Math.abs(n-s)>=Vs&&(s=-2);let c=new Ks(e,n,a);c.outdated=!1,r.push(c),o+=e+1}o<=a&&r.push(null,new e(a-o).updateHeight(t,o));let c=Hs.of(r);return(s<0||Math.abs(c.height-this.height)>=Vs||Math.abs(s-this.heightMetrics(t,n).perLine)>=Vs)&&(Is=!0),Us(this,c)}else(r||this.outdated)&&(this.setHeight(t.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Js=class extends Hs{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let i=n+this.left.height;return e<i?this.left.blockAt(e,t,n,r):this.right.blockAt(e,t,i,r+this.left.length+this.break)}lineAt(e,t,n,r,i){let a=r+this.left.height,o=i+this.left.length+this.break,s=t==V.ByHeight?e<a:e<o,c=s?this.left.lineAt(e,t,n,r,i):this.right.lineAt(e,t,n,a,o);if(this.break||(s?c.to<o:c.from>o))return c;let l=t==V.ByPosNoHeight?V.ByPosNoHeight:V.ByPos;return s?c.join(this.right.lineAt(o,l,n,a,o)):this.left.lineAt(o,l,n,r,i).join(c)}forEachLine(e,t,n,r,i,a){let o=r+this.left.height,s=i+this.left.length+this.break;if(this.break)e<s&&this.left.forEachLine(e,t,n,r,i,a),t>=s&&this.right.forEachLine(e,t,n,o,s,a);else{let c=this.lineAt(s,V.ByPos,n,r,i);e<c.from&&this.left.forEachLine(e,c.from-1,n,r,i,a),c.to>=e&&c.from<=t&&a(c),t>c.to&&this.right.forEachLine(c.to+1,t,n,o,s,a)}}replace(e,t,n){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let i=[];e>0&&this.decomposeLeft(e,i);let a=i.length;for(let e of n)i.push(e);if(e>0&&Ys(i,a-1),t<this.length){let e=i.length;this.decomposeRight(t,i),Ys(i,e)}return Hs.of(i)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Hs.of(this.break?[e,null,t]:[e,t]):(this.left=Us(this.left,e),this.right=Us(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,r){let{left:i,right:a}=this,o=t+i.length+this.break,s=null;return r&&r.from<=t+i.length&&r.more?s=i=i.updateHeight(e,t,n,r):i.updateHeight(e,t,n),r&&r.from<=o+a.length&&r.more?s=a=a.updateHeight(e,o,n,r):a.updateHeight(e,o,n),s?this.balanced(i,a):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?` `:`-`)+this.right}};function Ys(e,t){let n,r;e[t]==null&&(n=e[t-1])instanceof qs&&(r=e[t+1])instanceof qs&&e.splice(t-1,3,new qs(n.length+1+r.length))}var Xs=class e{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 e=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof Ks?n.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new Ks(e-this.pos,-1,0)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let r=n.widget?n.widget.estimatedHeight:0,i=n.widget?n.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let a=t-e;n.block?this.addBlock(new Gs(a,r,n)):(a||i||r>=5)&&this.addLineDeco(r,i,a)}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 Ks(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let n=new qs(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ks)return e;let t=new Ks(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+=e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos+=n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ks)&&!this.isCovered?this.nodes.push(new Ks(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let e of this.nodes)e instanceof Ks&&e.updateHeight(this.oracle,n),n+=e?e.length:1;return this.nodes}static build(t,n,r,i){let a=new e(r,t);return F.spans(n,r,i,a,0),a.finish(r)}};function Zs(e,t,n){let r=new Qs;return F.compare(e,t,n,r,0),r.changes}var Qs=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,r){(e<t||n&&n.heightRelevant||r&&r.heightRelevant)&&ci(e,t,this.changes,5)}};function $s(e,t){let n=e.getBoundingClientRect(),r=e.ownerDocument,i=r.defaultView||window,a=Math.max(0,n.left),o=Math.min(i.innerWidth,n.right),s=Math.max(0,n.top),c=Math.min(i.innerHeight,n.bottom);for(let t=e.parentNode;t&&t!=r.body;)if(t.nodeType==1){let n=t,r=window.getComputedStyle(n);if((n.scrollHeight>n.clientHeight||n.scrollWidth>n.clientWidth)&&r.overflow!=`visible`){let r=n.getBoundingClientRect();a=Math.max(a,r.left),o=Math.min(o,r.right),s=Math.max(s,r.top),c=Math.min(t==e.parentNode?i.innerHeight:c,r.bottom)}t=r.position==`absolute`||r.position==`fixed`?n.offsetParent:n.parentNode}else if(t.nodeType==11)t=t.host;else break;return{left:a-n.left,right:Math.max(a,o)-n.left,top:s-(n.top+t),bottom:Math.max(s,c)-(n.top+t)}}function ec(e){let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView||window;return t.left<n.innerWidth&&t.right>0&&t.top<n.innerHeight&&t.bottom>0}function tc(e,t){let n=e.getBoundingClientRect();return{left:0,right:n.right-n.left,top:t,bottom:n.bottom-(n.top+t)}}var nc=class{constructor(e,t,n,r){this.from=e,this.to=t,this.size=n,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.from!=i.from||r.to!=i.to||r.size!=i.size)return!1}return!0}draw(e,t){return L.replace({widget:new rc(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}},rc=class extends ti{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}},ic=class{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=uc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=R.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let n=t.facet(Da).some(e=>typeof e!=`function`&&e.class==`cm-lineWrapping`);this.heightOracle=new Rs(n),this.stateDeco=dc(t),this.heightMap=Hs.empty().applyChanges(this.stateDeco,k.empty,this.heightOracle.setDoc(t.doc),[new La(0,0,0,t.doc.length)]);for(let e=0;e<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());e++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=L.set(this.lineGaps.map(e=>e.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:e,to:t})=>r>=e&&r<=t)){let{from:t,to:n}=this.lineBlockAt(r);e.push(new ac(t,n))}}return this.viewports=e.sort((e,t)=>e.from-t.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?uc:new fc(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(pc(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=dc(this.state);let r=e.changedRanges,i=La.extendWithRanges(r,Zs(n,this.stateDeco,e?e.changes:sn.empty(this.state.doc.length))),a=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ls(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),i),(this.heightMap.height!=a||Is)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=a);let s=i.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<s.from||t.range.head>s.to)||!this.viewportIsAppropriate(s))&&(s=this.getViewport(0,t));let c=s.from!=this.viewport.from||s.to!=this.viewport.to;this.viewport=s,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(ha)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,i=n.whiteSpace;this.defaultTextDirection=n.direction==`rtl`?R.RTL:R.LTR;let a=this.heightOracle.mustRefreshForWrapping(i)||this.mustMeasureContent===`refresh`,o=t.getBoundingClientRect(),s=a||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let c=0,l=0;if(o.width&&o.height){let{scaleX:e,scaleY:n}=xi(t,o);(e>.005&&Math.abs(this.scaleX-e)>.005||n>.005&&Math.abs(this.scaleY-n)>.005)&&(this.scaleX=e,this.scaleY=n,c|=16,a=s=!0)}let u=(parseInt(n.paddingTop)||0)*this.scaleY,d=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=u||this.paddingBottom!=d)&&(this.paddingTop=u,this.paddingBottom=d,c|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(s=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=16);let f=Ci(this.view.contentDOM,!1).y;f!=this.scrollParent&&(this.scrollParent=f,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Pi(this.scrollParent||e.win);let m=(this.printing?tc:$s)(t,this.paddingTop),h=m.top-this.pixelViewport.top,g=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let _=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(_!=this.inView&&(this.inView=_,_&&(s=!0)),!this.inView&&!this.scrollTarget&&!ec(e.dom))return 0;let v=o.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,c|=16),s){let t=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(t)&&(a=!0),a||r.lineWrapping&&Math.abs(v-this.contentDOMWidth)>r.charWidth){let{lineHeight:n,charWidth:o,textHeight:s}=e.docView.measureTextSize();a=n>0&&r.refresh(i,n,o,s,Math.max(5,v/o),t),a&&(e.docView.minWidth=0,c|=16)}h>0&&g>0?l=Math.max(h,g):h<0&&g<0&&(l=Math.min(h,g)),Ls();for(let n of this.viewports){let i=n.from==this.viewport.from?t:e.docView.measureVisibleLineHeights(n);this.heightMap=(a?Hs.empty().applyChanges(this.stateDeco,k.empty,this.heightOracle,[new La(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,a,new zs(n.from,i))}Is&&(c|=2)}let y=!this.viewportIsAppropriate(this.viewport,l)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return y&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(l,this.scrollTarget),c|=this.updateForViewport()),(c&2||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(a?[]: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 n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,i=this.heightOracle,{visibleTop:a,visibleBottom:o}=this,s=new ac(r.lineAt(a-n*1e3,V.ByHeight,i,0,0).from,r.lineAt(o+(1-n)*1e3,V.ByHeight,i,0,0).to);if(t){let{head:e}=t.range;if(e<s.from||e>s.to){let n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),a=r.lineAt(e,V.ByPos,i,0,0),o;o=t.y==`center`?(a.top+a.bottom)/2-n/2:t.y==`start`||t.y==`nearest`&&e<s.from?a.top:a.bottom-n,s=new ac(r.lineAt(o-1e3/2,V.ByHeight,i,0,0).from,r.lineAt(o+n+1e3/2,V.ByHeight,i,0,0).to)}}return s}mapViewport(e,t){let n=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new ac(this.heightMap.lineAt(n,V.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,V.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),{bottom:i}=this.heightMap.lineAt(t,V.ByPos,this.heightOracle,0,0),{visibleTop:a,visibleBottom:o}=this;return(e==0||r<=a-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||i>=o+Math.max(10,Math.min(n,250)))&&r>a-2*1e3&&i<o+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let r of e)t.touchesRange(r.from,r.to)||n.push(new nc(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,r=n?1e4:2e3,i=r>>1,a=r<<1;if(this.defaultTextDirection!=R.LTR&&!n)return[];let o=[],s=(r,a,c,l)=>{if(a-r<i)return;let u=this.state.selection.main,d=[u.from];u.empty||d.push(u.to);for(let e of d)if(e>r&&e<a){s(r,e-10,c,l),s(e+10,a,c,l);return}let f=lc(e,e=>e.from>=c.from&&e.to<=c.to&&Math.abs(e.from-r)<i&&Math.abs(e.to-a)<i&&!d.some(t=>e.from<t&&e.to>t));if(!f){if(a<c.to&&t&&n&&t.visibleRanges.some(e=>e.from<=a&&e.to>=a)){let e=t.moveToLineBoundary(j.cursor(a),!1,!0).head;e>r&&(a=e)}let e=this.gapSize(c,r,a,l);f=new nc(r,a,e,n||e<2e6?e:2e6)}o.push(f)},c=t=>{if(t.length<a||t.type!=ni.Text)return;let i=oc(t.from,t.to,this.stateDeco);if(i.total<a)return;let o=this.scrollTarget?this.scrollTarget.range.head:null,c,l;if(n){let e=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,n,a;if(o!=null){let r=cc(i,o),s=((this.visibleBottom-this.visibleTop)/2+e)/t.height;n=r-s,a=r+s}else n=(this.visibleTop-t.top-e)/t.height,a=(this.visibleBottom-t.top+e)/t.height;c=sc(i,n),l=sc(i,a)}else{let n=i.total*this.heightOracle.charWidth,a=r*this.heightOracle.charWidth,s=0;if(n>2e6)for(let n of e)n.from>=t.from&&n.from<t.to&&n.size!=n.displaySize&&n.from*this.heightOracle.charWidth+s<this.pixelViewport.left&&(s=n.size-n.displaySize);let u=this.pixelViewport.left+s,d=this.pixelViewport.right+s,f,p;if(o!=null){let e=cc(i,o),t=((d-u)/2+a)/n;f=e-t,p=e+t}else f=(u-a)/n,p=(d+a)/n;c=sc(i,f),l=sc(i,p)}c>t.from&&s(t.from,c,t,i),l<t.to&&s(l,t.to,t,i)};for(let e of this.viewportLines)Array.isArray(e.type)?e.type.forEach(c):c(e);return o}gapSize(e,t,n,r){let i=cc(r,n)-cc(r,t);return this.heightOracle.lineWrapping?e.height*i:r.total*this.heightOracle.charWidth*i}updateLineGaps(e){nc.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=L.set(e.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];F.spans(t,this.viewport.from,this.viewport.to,{span(e,t){n.push({from:e,to:t})},point(){}},20);let r=0;if(n.length!=this.visibleRanges.length)r=12;else for(let t=0;t<n.length&&!(r&8);t++){let i=this.visibleRanges[t],a=n[t];(i.from!=a.from||i.to!=a.to)&&(r|=4,e&&e.mapPos(i.from,-1)==a.from&&e.mapPos(i.to,1)==a.to||(r|=8))}return this.visibleRanges=n,r}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||pc(this.heightMap.lineAt(e,V.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)||pc(this.heightMap.lineAt(this.scaler.fromDOM(e),V.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return pc(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}},ac=class{constructor(e,t){this.from=e,this.to=t}};function oc(e,t,n){let r=[],i=e,a=0;return F.spans(n,e,t,{span(){},point(e,t){e>i&&(r.push({from:i,to:e}),a+=e-i),i=t}},20),i<t&&(r.push({from:i,to:t}),a+=t-i),{total:a,ranges:r}}function sc({total:e,ranges:t},n){if(n<=0)return t[0].from;if(n>=1)return t[t.length-1].to;let r=Math.floor(e*n);for(let e=0;;e++){let{from:n,to:i}=t[e],a=i-n;if(r<=a)return n+r;r-=a}}function cc(e,t){let n=0;for(let{from:r,to:i}of e.ranges){if(t<=i){n+=t-r;break}n+=i-r}return n/e.total}function lc(e,t){for(let n of e)if(t(n))return n}const uc={toDOM(e){return e},fromDOM(e){return e},scale:1,eq(e){return e==this}};function dc(e){let t=e.facet(Oa).filter(e=>typeof e!=`function`),n=e.facet(Aa).filter(e=>typeof e!=`function`);return n.length&&t.push(F.join(n)),t}var fc=class e{constructor(e,t,n){let r=0,i=0,a=0;this.viewports=n.map(({from:n,to:i})=>{let a=t.lineAt(n,V.ByPos,e,0,0).top,o=t.lineAt(i,V.ByPos,e,0,0).bottom;return r+=o-a,{from:n,to:i,top:a,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let e of this.viewports)e.domTop=a+(e.top-i)*this.scale,a=e.domBottom=e.domTop+(e.bottom-e.top),i=e.bottom}toDOM(e){for(let t=0,n=0,r=0;;t++){let i=t<this.viewports.length?this.viewports[t]:null;if(!i||e<i.top)return r+(e-n)*this.scale;if(e<=i.bottom)return i.domTop+(e-i.top);n=i.bottom,r=i.domBottom}}fromDOM(e){for(let t=0,n=0,r=0;;t++){let i=t<this.viewports.length?this.viewports[t]:null;if(!i||e<i.domTop)return n+(e-r)/this.scale;if(e<=i.domBottom)return i.top+(e-i.domTop);n=i.bottom,r=i.domBottom}}eq(t){return t instanceof e&&this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,n)=>e.from==t.viewports[n].from&&e.to==t.viewports[n].to)}};function pc(e,t){if(t.scale==1)return e;let n=t.toDOM(e.top),r=t.toDOM(e.bottom);return new Bs(e.from,e.length,n,r-n,Array.isArray(e._content)?e._content.map(e=>pc(e,t)):e._content)}const mc=M.define({combine:e=>e.join(` `)}),hc=M.define({combine:e=>e.indexOf(!0)>-1}),gc=Or.newName(),_c=Or.newName(),vc=Or.newName(),yc={"&light":`.`+_c,"&dark":`.`+vc};function bc(e,t,n){return new Or(t,{finish(t){return/&/.test(t)?t.replace(/&\w*/,t=>{if(t==`&`)return e;if(!n||!n[t])throw RangeError(`Unsupported selector: ${t}`);return n[t]}):e+` `+t}})}const xc=bc(`.`+gc,{"&":{position:`relative !important`,boxSizing:`border-box`,"&.cm-focused":{outline:`1px dotted #212121`},display:`flex !important`,flexDirection:`column`},".cm-scroller":{display:`flex !important`,alignItems:`flex-start !important`,fontFamily:`monospace`,lineHeight:1.4,height:`100%`,overflowX:`auto`,position:`relative`,zIndex:0,overflowAnchor:`none`},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:`block`,whiteSpace:`pre`,wordWrap:`normal`,boxSizing:`border-box`,minHeight:`100%`,padding:`4px 0`,outline:`none`,"&[contenteditable=true]":{WebkitUserModify:`read-write-plaintext-only`}},".cm-lineWrapping":{whiteSpace_fallback:`pre-wrap`,whiteSpace:`break-spaces`,wordBreak:`break-word`,overflowWrap:`anywhere`,flexShrink:1},"&light .cm-content":{caretColor:`black`},"&dark .cm-content":{caretColor:`white`},".cm-line":{display:`block`,padding:`0 2px 0 6px`},".cm-layer":{userSelect:`none`,position:`absolute`,left:0,top:0,contain:`size style`,"& > *":{position:`absolute`}},"&light .cm-selectionBackground":{background:`#d9d9d9`},"&dark .cm-selectionBackground":{background:`#222`},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#d7d4f0`},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#233`},".cm-cursorLayer":{pointerEvents:`none`},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:`steps(1) cm-blink 1.2s infinite`},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:`1.2px solid black`,marginLeft:`-0.6px`,pointerEvents:`none`},".cm-cursor":{display:`none`},"&dark .cm-cursor":{borderLeftColor:`#ddd`},".cm-selectionHandle":{backgroundColor:`currentColor`,width:`1.5px`},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:`""`,backgroundColor:`inherit`,borderRadius:`50%`,width:`8px`,height:`8px`,position:`absolute`,left:`-3.25px`},".cm-selectionHandle-start::before":{top:`-8px`},".cm-selectionHandle-end::before":{bottom:`-8px`},".cm-dropCursor":{position:`absolute`},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:`block`},".cm-iso":{unicodeBidi:`isolate`},".cm-announced":{position:`fixed`,top:`-10000px`},"@media print":{".cm-announced":{display:`none`}},"&light .cm-activeLine":{backgroundColor:`#cceeff44`},"&dark .cm-activeLine":{backgroundColor:`#99eeff33`},"&light .cm-specialChar":{color:`red`},"&dark .cm-specialChar":{color:`#f78`},".cm-gutters":{flexShrink:0,display:`flex`,height:`100%`,boxSizing:`border-box`,zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:`#f5f5f5`,color:`#6c6c6c`,border:`0px solid #ddd`,"&.cm-gutters-before":{borderRightWidth:`1px`},"&.cm-gutters-after":{borderLeftWidth:`1px`}},"&dark .cm-gutters":{backgroundColor:`#333338`,color:`#ccc`},".cm-gutter":{display:`flex !important`,flexDirection:`column`,flexShrink:0,boxSizing:`border-box`,minHeight:`100%`,overflow:`hidden`},".cm-gutterElement":{boxSizing:`border-box`},".cm-lineNumbers .cm-gutterElement":{padding:`0 3px 0 5px`,minWidth:`20px`,textAlign:`right`,whiteSpace:`nowrap`},"&light .cm-activeLineGutter":{backgroundColor:`#e2f2ff`},"&dark .cm-activeLineGutter":{backgroundColor:`#222227`},".cm-panels":{boxSizing:`border-box`,position:`sticky`,left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:`#f5f5f5`,color:`black`},".cm-panels-top":{top:`0`},".cm-panels-bottom":{bottom:`0`},"&light .cm-panels-top":{borderBottom:`1px solid #ddd`},"&light .cm-panels-bottom":{borderTop:`1px solid #ddd`},"&dark .cm-panels":{backgroundColor:`#333338`,color:`white`},".cm-dialog":{padding:`2px 19px 4px 6px`,position:`relative`,"& label":{fontSize:`80%`}},".cm-dialog-close":{position:`absolute`,top:`3px`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,fontSize:`14px`,padding:`0`},".cm-tab":{display:`inline-block`,overflow:`hidden`,verticalAlign:`bottom`},".cm-widgetBuffer":{verticalAlign:`text-top`,height:`1em`,width:0,display:`inline`},".cm-placeholder":{color:`#888`,display:`inline-block`,verticalAlign:`top`,userSelect:`none`},".cm-highlightSpace":{background:`radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat`,backgroundSize:`.4em`,backgroundPosition:`calc(min(50%, 0px)) center`},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:`auto 100%`,backgroundPosition:`right 90%`,backgroundRepeat:`no-repeat`},".cm-trailingSpace":{backgroundColor:`#ff332255`},".cm-button":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,padding:`.2em 1em`,borderRadius:`1px`},"&light .cm-button":{backgroundImage:`linear-gradient(#eff1f5, #d9d9df)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#b4b4b4, #d0d3d6)`}},"&dark .cm-button":{backgroundImage:`linear-gradient(#393939, #111)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#111, #333)`}},".cm-textfield":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,border:`1px solid silver`,padding:`.2em .5em`},"&light .cm-textfield":{backgroundColor:`white`},"&dark .cm-textfield":{border:`1px solid #555`,backgroundColor:`inherit`}},yc),Sc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Cc=I.ie&&I.ie_version<=11;var wc=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new wi,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 e of t)this.queue.push(e);(I.ie&&I.ie_version<=11||I.ios&&e.composing)&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&I.android&&e.constructor.EDIT_CONTEXT!==!1&&!(I.chrome&&I.chrome_version<126)&&(this.editContext=new Oc(e),e.state.facet(xa)&&(e.contentDOM.editContext=this.editContext.editContext)),Cc&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.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(()=>{this.view.docView?.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(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.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(e=>{e.length>0&&e[e.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,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(xa)?n.root.activeElement!=this.dom:!fi(this.dom,r))return;let i=r.anchorNode&&n.docView.tile.nearest(r.anchorNode);if(i&&i.isWidget()&&i.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(I.ie&&I.ie_version<=11||I.android&&I.chrome)&&!n.state.selection.main.empty&&r.focusNode&&mi(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=ui(e.root);if(!t)return!1;let n=I.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Dc(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=fi(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Ni(this.dom,n)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(n),r&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(n.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||=this.scrollTargets.slice(0,e),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let e of this.scrollTargets)e.removeEventListener(`scroll`,this.onScroll);for(let e of this.scrollTargets=t)e.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,Sc),Cc&&this.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Cc&&this.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){if(!this.delayedAndroidKey){let e=()=>{let e=this.delayedAndroidKey;e&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&ji(this.dom,e.key,e.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}(!this.delayedAndroidKey||e==`Enter`)&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!this.delayedAndroidKey?.force})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let i of e){let e=this.readMutation(i);e&&(e.typeOver&&(r=!0),t==-1?{from:t,to:n}=e:(t=Math.min(e.from,t),n=Math.max(e.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&fi(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 i=new Uo(this.view,e,t,n);return this.view.docView.domChanged={newSel:i.newSel?i.newSel.main:null},i}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 n=this.view.state,r=Go(this.view,t);return this.view.state==n&&(t.domChanged||t.newSel&&!Zo(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 n=Tc(t,e.previousSibling||e.target.previousSibling,-1),r=Tc(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else if(e.type==`characterData`)return{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue};else return 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(xa)!=e.state.facet(xa)&&(e.view.contentDOM.editContext=e.state.facet(xa)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)==null||e.disconnect(),(t=this.gapIntersection)==null||t.disconnect(),(n=this.resizeScroll)==null||n.disconnect();for(let e of this.scrollTargets)e.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 Tc(e,t,n){for(;t;){let r=B.get(t);if(r&&r.parent==e)return r;let i=t.parentNode;t=i==e.dom?n>0?t.nextSibling:t.previousSibling:i}return null}function Ec(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.docView.domAtPos(e.state.selection.main.anchor,1);return mi(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function Dc(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Ec(e,n)}let n=null;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.contentDOM.addEventListener(`beforeinput`,r,!0),e.dom.ownerDocument.execCommand(`indent`),e.contentDOM.removeEventListener(`beforeinput`,r,!0),n?Ec(e,n):null}var Oc=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let r=e.state.selection.main,{anchor:i,head:a}=r,o=this.toEditorPos(n.updateRangeStart),s=this.toEditorPos(n.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:n.updateRangeStart,editorBase:o,drifted:!1});let c=s-o>n.text.length;o==this.from&&i<this.from?o=i:s==this.to&&i>this.to&&(s=i);let l=Jo(e.state.sliceDoc(o,s),n.text,(c?r.from:r.to)-o,c?`end`:null);if(!l){let t=j.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd));Zo(t,r)||e.dispatch({selection:t,userEvent:`select`});return}let u={from:l.from+o,to:l.toA+o,insert:k.of(n.text.slice(l.from,l.toB).split(`
743
- `))};if((I.mac||I.android)&&u.from==a-1&&/^\. ?$/.test(n.text)&&e.contentDOM.getAttribute(`autocorrect`)==`off`&&(u={from:o,to:s,insert:k.of([n.text.replace(`.`,` `)])}),this.pendingContextChange=u,!e.state.readOnly){let t=this.to-this.from+(u.to-u.from+u.insert.length);Ko(e,u,j.single(this.toEditorPos(n.selectionStart,t),this.toEditorPos(n.selectionEnd,t)))}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,n.updateRangeStart-1),Math.min(t.text.length,n.updateRangeStart+1)))&&this.handlers.compositionend(n)},this.handlers.characterboundsupdate=n=>{let r=[],i=null;for(let t=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);t<a;t++){let n=e.coordsForChar(t);i=n&&new DOMRect(n.left,n.top,n.right-n.left,n.bottom-n.top)||i||new DOMRect,r.push(i)}t.updateCharacterBounds(n.rangeStart,r)},this.handlers.textformatupdate=t=>{let n=[];for(let e of t.getTextFormats()){let t=e.underlineStyle,r=e.underlineThickness;if(!/none/i.test(t)&&!/none/i.test(r)){let i=this.toEditorPos(e.rangeStart),a=this.toEditorPos(e.rangeEnd);if(i<a){let e=`text-decoration: underline ${/^[a-z]/.test(t)?t+` `:t==`Dashed`?`dashed `:t==`Squiggle`?`wavy `:``}${/thin/i.test(r)?1:2}px`;n.push(L.mark({attributes:{style:e}}).range(i,a))}}}e.dispatch({effects:ya.of(L.set(n))})},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:t}=this.composing;this.composing=null,t&&this.reset(e.state)}};for(let e in this.handlers)t.addEventListener(e,this.handlers[e]);this.measureReq={read:e=>{let t=ui(e.root);t&&t.rangeCount&&this.editContext.updateSelectionBounds(t.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((i,a,o,s,c)=>{if(n)return;let l=c.length-(a-i);if(r&&a>=r.to)if(r.from==i&&r.to==a&&r.insert.eq(c)){r=this.pendingContextChange=null,t+=l,this.to+=l;return}else r=null,this.revertPending(e.state);if(i+=t,a+=t,a<=this.from)this.from+=l,this.to+=l;else if(i<this.to){if(i<this.from||a>this.to||this.to-this.from+c.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(i),this.toContextPos(a),c.toString()),this.to+=l}t+=l}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(e=>!e.isUserEvent(`input.type`)&&e.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},H=class e{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={}){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:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(e=>e.forEach(e=>t(e,this)))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Mi(e.parent)||document,this.viewState=new ic(this,e.state||P.create(e)),e.scrollTo&&e.scrollTo.is(va)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ca).map(e=>new Ta(e));for(let e of this.plugins)e.update(this);this.observer=new wc(this),this.inputState=new Qo(this),this.inputState.ensureHandlers(this.plugins),this.docView=new po(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),document.fonts?.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=`refresh`,this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof Wn?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(t){if(this.updateState!=0)throw Error(`Calls to EditorView.update are not allowed while an update is in progress`);let n=!1,r=!1,i,a=this.state;for(let e of t){if(e.startState!=a)throw RangeError(`Trying to update state with a transaction that doesn't start from the previous state.`);a=e.state}if(this.destroyed){this.viewState.state=a;return}let o=this.hasFocus,s=0,c=null;t.some(e=>e.annotation(As))?(this.inputState.notifiedFocused=o,s=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=js(a,o),c||(s=1));let l=this.observer.delayedAndroidKey,u=null;if(l?(this.observer.clearDelayedAndroidKey(),u=this.observer.readChange(),(u&&!this.state.doc.eq(a.doc)||!this.state.selection.eq(a.selection))&&(u=null)):this.observer.clear(),a.facet(P.phrases)!=this.state.facet(P.phrases))return this.setState(a);i=Ra.create(this,a,t),i.flags|=s;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let n of t){if(d&&=d.map(n.changes),n.scrollIntoView){let{main:t}=n.state.selection,{x:r,y:i}=this.state.facet(e.cursorScrollMargin);d=new _a(t.empty?t:j.cursor(t.head,t.head>t.anchor?-1:1),`nearest`,`nearest`,i,r)}for(let e of n.effects)e.is(va)&&(d=e.value.clip(this.state))}this.viewState.update(i,d),this.bidiCache=jc.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),n=this.docView.update(i),this.state.facet(Ia)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(n,t.some(e=>e.isUserEvent(`select.pointer`)))}finally{this.updateState=0}if(i.startState.facet(mc)!=i.state.facet(mc)&&(this.viewState.mustMeasureContent=!0),(n||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!i.empty)for(let e of this.state.facet(la))try{e(i)}catch(e){ba(this.state,e,`update listener`)}(c||u)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),u&&!Go(this,u)&&l.force&&ji(this.contentDOM,l.key,l.keyCode)})}setState(e){if(this.updateState!=0)throw 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 e of this.plugins)e.destroy(this);this.viewState=new ic(this,e),this.plugins=e.facet(Ca).map(e=>new Ta(e)),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView.destroy(),this.docView=new po(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(Ca),n=e.state.facet(Ca);if(t!=n){let r=[];for(let i of n){let n=t.indexOf(i);if(n<0)r.push(new Ta(i));else{let t=this.plugins[n];t.mustUpdate=e,r.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let t of this.plugins)t.mustUpdate=e;for(let e=0;e<this.plugins.length;e++)this.plugins[e].update(this);t!=n&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(e){ba(this.state,e,`doc view update listener`)}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.viewState.scrollParent,r=this.viewState.getScrollOffset(),{scrollAnchorPos:i,scrollAnchorHeight:a,scaleY:o}=this.viewState;Math.abs(r-this.viewState.scrollOffset)>1&&(a=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(a<0){if(Pi(n||this.win))i=-1,a=this.viewState.heightMap.height/this.viewState.scaleY;else{let e=this.viewState.scrollAnchorAt(r);i=e.from,a=e.top}o=this.viewState.scaleY}this.updateState=1;let s=this.viewState.measure();if(!s&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(e>5){console.warn(this.measureRequests.length?`Measure loop restarted more than 5 times`:`Viewport failed to stabilize`);break}let c=[];s&4||([this.measureRequests,c]=[c,this.measureRequests]);let l=c.map(e=>{try{return e.read(this)}catch(e){return ba(this.state,e),Ac}}),u=Ra.create(this,this.state,[]),d=!1;u.flags|=s,t?t.flags|=s:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),d=this.docView.update(u),d&&this.docViewUpdate());for(let e=0;e<c.length;e++)if(l[e]!=Ac)try{let t=c[e];t.write&&t.write(l[e],this)}catch(e){ba(this.state,e)}if(d&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,a=-1;continue}else{let e=(i<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(i).top)/this.viewState.scaleY-a/o;if((e>1||e<-1)&&!(I.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(n==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){r+=e,n?i<0?n.scrollTop=n.scrollHeight:n.scrollTop+=e:this.win.scrollBy(0,e),a=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let e of this.state.facet(la))e(t)}get themeClasses(){return gc+` `+(this.state.facet(hc)?vc:_c)+` `+this.state.facet(mc)}updateAttrs(){let e=Mc(this,Ea,{class:`cm-editor`+(this.hasFocus?` cm-focused `:` `)+this.themeClasses}),t={spellcheck:`false`,autocorrect:`off`,autocapitalize:`off`,writingsuggestions:`false`,translate:`no`,contenteditable:this.state.facet(xa)?`true`:`false`,class:`cm-content`,style:`${I.tabSize}: ${this.state.tabSize}`,role:`textbox`,"aria-multiline":`true`};this.state.readOnly&&(t[`aria-readonly`]=`true`),Mc(this,Da,t);let n=this.observer.ignore(()=>{let n=$r(this.contentDOM,this.contentAttrs,t),r=$r(this.dom,this.editorAttrs,e);return n||r});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(t){let n=!0;for(let r of t)for(let t of r.effects)if(t.is(e.announce)){n&&(this.announceDOM.textContent=``),n=!1;let e=this.announceDOM.appendChild(document.createElement(`div`));e.textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(Ia);let t=this.state.facet(e.cspNonce);Or.mount(this.root,this.styleModules.concat(xc).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw 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(t=>t.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return Fo(this,e,Ao(this,e,t,n))}moveByGroup(e,t){return Fo(this,e,Ao(this,e,t,t=>jo(this,e.head,t)))}visualLineSide(e,t){let n=this.bidiSpans(e),r=this.textDirectionAt(e.from),i=n[t?n.length-1:0];return j.cursor(i.side(t,r)+e.from,i.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,n=!0){return ko(this,e,t,n)}moveVertically(e,t,n){return Fo(this,e,Mo(this,e,t,n))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let n=Lo(this,e,t);return n&&n.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),Lo(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),i=r[qi.find(r,e-n.from,-1,t)];return this.docView.coordsAt(e,t,i.dir==R.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(ma)||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>kc)return ta(e.length);let t=this.textDirectionAt(e.from),n;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Ji(r.isolates,n=Na(this,e))))return r.order;n||=Na(this,e);let r=ea(e.text,t,n);return this.bidiCache.push(new jc(e.from,e.to,t,n,!0,r)),r}get hasFocus(){return(this.dom.ownerDocument.hasFocus()||I.safari&&this.inputState?.lastContextMenu>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Oi(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 va.of(new _a(typeof e==`number`?j.cursor(e):e,t.y??`nearest`,t.x??`nearest`,t.yMargin??5,t.xMargin??5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return va.of(new _a(j.cursor(n.from),`start`,`start`,n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e==`boolean`?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return wa.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return wa.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=Or.newName(),r=[mc.of(n),Ia.of(bc(`.${n}`,e))];return t&&t.dark&&r.push(hc.of(!0)),r}static baseTheme(e){return En.lowest(Ia.of(bc(`.`+gc,e,yc)))}static findFromDOM(e){let t=e.querySelector(`.cm-content`);return(t&&B.get(t)||B.get(e))?.root?.view||null}};H.styleModule=Ia,H.inputHandler=ua,H.clipboardInputFilter=fa,H.clipboardOutputFilter=pa,H.scrollHandler=ga,H.focusChangeEffect=da,H.perLineTextDirection=ma,H.exceptionSink=ca,H.updateListener=la,H.editable=xa,H.mouseSelectionStyle=sa,H.dragMovesSelection=oa,H.clickAddsSelectionRange=aa,H.decorations=Oa,H.blockWrappers=ka,H.outerDecorations=Aa,H.atomicRanges=ja,H.bidiIsolatedRanges=Ma,H.cursorScrollMargin=M.define({combine:e=>{let t=5,n=5;for(let r of e)typeof r==`number`?t=n=r:{x:t,y:n}=r;return{x:t,y:n}}}),H.scrollMargins=Pa,H.darkTheme=hc,H.cspNonce=M.define({combine:e=>e.length?e[0]:``}),H.contentAttributes=Da,H.editorAttributes=Ea,H.lineWrapping=H.contentAttributes.of({class:`cm-lineWrapping`}),H.announce=N.define();const kc=4096,Ac={};var jc=class e{constructor(e,t,n,r,i,a){this.from=e,this.to=t,this.dir=n,this.isolates=r,this.fresh=i,this.order=a}static update(t,n){if(n.empty&&!t.some(e=>e.fresh))return t;let r=[],i=t.length?t[t.length-1].dir:R.LTR;for(let a=Math.max(0,t.length-10);a<t.length;a++){let o=t[a];o.dir==i&&!n.touchesRange(o.from,o.to)&&r.push(new e(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}};function Mc(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let t=r[i],a=typeof t==`function`?t(e):t;a&&Yr(a,n)}return n}const Nc=I.mac?`mac`:I.windows?`win`:I.linux?`linux`:`key`;function Pc(e,t){let n=e.split(/-(?!$)/),r=n[n.length-1];r==`Space`&&(r=` `);let i,a,o,s;for(let e=0;e<n.length-1;++e){let r=n[e];if(/^(cmd|meta|m)$/i.test(r))s=!0;else if(/^a(lt)?$/i.test(r))i=!0;else if(/^(c|ctrl|control)$/i.test(r))a=!0;else if(/^s(hift)?$/i.test(r))o=!0;else if(/^mod$/i.test(r))t==`mac`?s=!0:a=!0;else throw Error(`Unrecognized modifier name: `+r)}return i&&(r=`Alt-`+r),a&&(r=`Ctrl-`+r),s&&(r=`Meta-`+r),o&&(r=`Shift-`+r),r}function Fc(e,t,n){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n!==!1&&t.shiftKey&&(e=`Shift-`+e),e}const Ic=En.default(H.domEventHandlers({keydown(e,t){return Uc(zc(t.state),e,t,`editor`)}})),Lc=M.define({enables:Ic}),Rc=new WeakMap;function zc(e){let t=e.facet(Lc),n=Rc.get(t);return n||Rc.set(t,n=Vc(t.reduce((e,t)=>e.concat(t),[]))),n}let Bc=null;function Vc(e,t=Nc){let n=Object.create(null),r=Object.create(null),i=(e,t)=>{let n=r[e];if(n==null)r[e]=t;else if(n!=t)throw Error(`Key binding `+e+` is used both as a regular binding and as a multi-stroke prefix`)},a=(e,r,a,o,s)=>{let c=n[e]||(n[e]=Object.create(null)),l=r.split(/ (?!$)/).map(e=>Pc(e,t));for(let t=1;t<l.length;t++){let n=l.slice(0,t).join(` `);i(n,!0),c[n]||(c[n]={preventDefault:!0,stopPropagation:!1,run:[t=>{let r=Bc={view:t,prefix:n,scope:e};return setTimeout(()=>{Bc==r&&(Bc=null)},4e3),!0}]})}let u=l.join(` `);i(u,!1);let d=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(c._any?.run)?.slice()||[]});a&&d.run.push(a),o&&(d.preventDefault=!0),s&&(d.stopPropagation=!0)};for(let r of e){let e=r.scope?r.scope.split(` `):[`editor`];if(r.any)for(let t of e){let e=n[t]||(n[t]=Object.create(null));e._any||={preventDefault:!1,stopPropagation:!1,run:[]};let{any:i}=r;for(let t in e)e[t].run.push(e=>i(e,Hc))}let i=r[t]||r.key;if(i)for(let t of e)a(t,i,r.run,r.preventDefault,r.stopPropagation),r.shift&&a(t,`Shift-`+i,r.shift,r.preventDefault,r.stopPropagation)}return n}let Hc=null;function Uc(e,t,n,r){Hc=t;let i=Lr(t),a=nn(tn(i,0))==i.length&&i!=` `,o=``,s=!1,c=!1,l=!1;Bc&&Bc.view==n&&Bc.scope==r&&(o=Bc.prefix+` `,is.indexOf(t.keyCode)<0&&(c=!0,Bc=null));let u=new Set,d=e=>{if(e){for(let t of e.run)if(!u.has(t)&&(u.add(t),t(n)))return e.stopPropagation&&(l=!0),!0;e.preventDefault&&(e.stopPropagation&&(l=!0),c=!0)}return!1},f=e[r],p,m;return f&&(d(f[o+Fc(i,t,!a)])?s=!0:a&&(t.altKey||t.metaKey||t.ctrlKey)&&!(I.windows&&t.ctrlKey&&t.altKey)&&!(I.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(p=jr[t.keyCode])&&p!=i?(d(f[o+Fc(p,t,!0)])||t.shiftKey&&(m=Mr[t.keyCode])!=i&&m!=p&&d(f[o+Fc(m,t,!1)]))&&(s=!0):a&&t.shiftKey&&d(f[o+Fc(i,t,!0)])&&(s=!0),!s&&d(f._any)&&(s=!0)),c&&(s=!0),s&&l&&t.stopPropagation(),Hc=null,s}var Wc=class e{constructor(e,t,n,r,i){this.className=e,this.left=t,this.top=n,this.width=r,this.height=i}draw(){let e=document.createElement(`div`);return e.className=this.className,this.adjust(e),e}update(e,t){return t.className==this.className?(this.adjust(e),!0):!1}adjust(e){e.style.left=this.left+`px`,e.style.top=this.top+`px`,this.width!=null&&(e.style.width=this.width+`px`),e.style.height=this.height+`px`}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(t,n,r){if(r.empty){let i=t.coordsAtPos(r.head,r.assoc||1);if(!i)return[];let a=Gc(t);return[new e(n,i.left-a.left,i.top-a.top,null,i.bottom-i.top)]}else return qc(t,n,r)}};function Gc(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==R.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function Kc(e,t,n,r){let i=e.coordsAtPos(t,n*2);if(!i)return r;let a=e.dom.getBoundingClientRect(),o=(i.top+i.bottom)/2,s=e.posAtCoords({x:a.left+1,y:o}),c=e.posAtCoords({x:a.right-1,y:o});return s==null||c==null?r:{from:Math.max(r.from,Math.min(s,c)),to:Math.min(r.to,Math.max(s,c))}}function qc(e,t,n){if(n.to<=e.viewport.from||n.from>=e.viewport.to)return[];let r=Math.max(n.from,e.viewport.from),i=Math.min(n.to,e.viewport.to),a=e.textDirection==R.LTR,o=e.contentDOM,s=o.getBoundingClientRect(),c=Gc(e),l=o.querySelector(`.cm-line`),u=l&&window.getComputedStyle(l),d=s.left+(u?parseInt(u.paddingLeft)+Math.min(0,parseInt(u.textIndent)):0),f=s.right-(u?parseInt(u.paddingRight):0),p=Oo(e,r,1),m=Oo(e,i,-1),h=p.type==ni.Text?p:null,g=m.type==ni.Text?m:null;if(h&&(e.lineWrapping||p.widgetLineBreaks)&&(h=Kc(e,r,1,h)),g&&(e.lineWrapping||m.widgetLineBreaks)&&(g=Kc(e,i,-1,g)),h&&g&&h.from==g.from&&h.to==g.to)return v(y(n.from,n.to,h));{let t=h?y(n.from,null,h):b(p,!1),r=g?y(null,n.to,g):b(m,!0),i=[];return(h||p).to<(g||m).from-(h&&g?1:0)||p.widgetLineBreaks>1&&t.bottom+e.defaultLineHeight/2<r.top?i.push(_(d,t.bottom,f,r.top)):t.bottom<r.top&&e.elementAtHeight((t.bottom+r.top)/2).type==ni.Text&&(t.bottom=r.top=(t.bottom+r.top)/2),v(t).concat(i).concat(v(r))}function _(e,n,r,i){return new Wc(t,e-c.left,n-c.top,Math.max(0,r-e),i-n)}function v({top:e,bottom:t,horizontal:n}){let r=[];for(let i=0;i<n.length;i+=2)r.push(_(n[i],e,n[i+1],t));return r}function y(t,n,r){let i=1e9,o=-1e9,s=[];function c(t,n,c,l,u){let p=e.coordsAtPos(t,t==r.to?-2:2),m=e.coordsAtPos(c,c==r.from?2:-2);!p||!m||(i=Math.min(p.top,m.top,i),o=Math.max(p.bottom,m.bottom,o),u==R.LTR?s.push(a&&n?d:p.left,a&&l?f:m.right):s.push(!a&&l?d:m.left,!a&&n?f:p.right))}let l=t??r.from,u=n??r.to;for(let r of e.visibleRanges)if(r.to>l&&r.from<u)for(let i=Math.max(r.from,l),a=Math.min(r.to,u);;){let r=e.state.doc.lineAt(i);for(let o of e.bidiSpans(r)){let e=o.from+r.from,s=o.to+r.from;if(e>=a)break;s>i&&c(Math.max(e,i),t==null&&e<=l,Math.min(s,a),n==null&&s>=u,o.dir)}if(i=r.to+1,i>=a)break}return s.length==0&&c(l,t==null,u,n==null,e.textDirection),{top:i,bottom:o,horizontal:s}}function b(e,t){let n=s.top+(t?e.top:e.bottom);return{top:n,bottom:n,horizontal:[]}}}function Jc(e,t){return e.constructor==t.constructor&&e.eq(t)}var Yc=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement(`div`)),this.dom.classList.add(`cm-layer`),t.above&&this.dom.classList.add(`cm-layer-above`),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute(`aria-hidden`,`true`),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Xc)!=e.state.facet(Xc)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(Xc);for(;t<n.length&&n[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((e,t)=>!Jc(e,this.drawn[t]))){let t=this.dom.firstChild,n=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[n].constructor&&r.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(r.draw(),t);for(;t;){let e=t.nextSibling;t.remove(),t=e}this.drawn=e,I.webkit&&(this.dom.style.display=this.dom.firstChild?``:`none`)}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}};const Xc=M.define();function Zc(e){return[wa.define(t=>new Yc(t,e)),Xc.of(e)]}const Qc=M.define({combine(e){return ir(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function $c(e={}){return[Qc.of(e),tl,rl,al,ha.of(!0)]}function el(e){return e.startState.facet(Qc)!=e.state.facet(Qc)}const tl=Zc({above:!0,markers(e){let{state:t}=e,n=t.facet(Qc),r=[];for(let i of t.selection.ranges){let a=i==t.selection.main;if(i.empty||n.drawRangeCursor&&!(a&&I.ios&&n.iosSelectionHandles)){let t=a?`cm-cursor cm-cursor-primary`:`cm-cursor cm-cursor-secondary`,n=i.empty?i:j.cursor(i.head,i.assoc);for(let i of Wc.forRange(e,t,n))r.push(i)}}return r},update(e,t){e.transactions.some(e=>e.selection)&&(t.style.animationName=t.style.animationName==`cm-blink`?`cm-blink2`:`cm-blink`);let n=el(e);return n&&nl(e.state,t),e.docChanged||e.selectionSet||n},mount(e,t){nl(t.state,e)},class:`cm-cursorLayer`});function nl(e,t){t.style.animationDuration=e.facet(Qc).cursorBlinkRate+`ms`}const rl=Zc({above:!1,markers(e){let t=[],{main:n,ranges:r}=e.state.selection;for(let n of r)if(!n.empty)for(let r of Wc.forRange(e,`cm-selectionBackground`,n))t.push(r);if(I.ios&&!n.empty&&e.state.facet(Qc).iosSelectionHandles){for(let r of Wc.forRange(e,`cm-selectionHandle cm-selectionHandle-start`,j.cursor(n.from,1)))t.push(r);for(let r of Wc.forRange(e,`cm-selectionHandle cm-selectionHandle-end`,j.cursor(n.to,1)))t.push(r)}return t},update(e,t){return e.docChanged||e.selectionSet||e.viewportChanged||el(e)},class:`cm-selectionLayer`}),il=I.gecko&&I.gecko_version==153?`#ffffff01`:`transparent`,al=En.highest(H.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${il} !important`},caretColor:`transparent !important`},".cm-content":{caretColor:`transparent !important`,"& :focus":{caretColor:`initial !important`,"&::selection, & ::selection":{backgroundColor:`Highlight !important`}}}}));/x/.unicode;var ol=class extends ti{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement(`span`);return t.className=`cm-placeholder`,t.style.pointerEvents=`none`,t.appendChild(typeof this.content==`string`?document.createTextNode(this.content):typeof this.content==`function`?this.content(e):this.content.cloneNode(!0)),t.setAttribute(`aria-hidden`,`true`),t}coordsAt(e){let t=e.firstChild?pi(e.firstChild):[];if(!t.length)return null;let n=window.getComputedStyle(e.parentNode),r=yi(t[0],n.direction!=`rtl`),i=parseInt(n.lineHeight);return r.bottom-r.top>i*1.5?{left:r.left,right:r.right,top:r.top,bottom:r.top+i}:r}ignoreEvent(){return!1}};function sl(e){let t=wa.fromClass(class{constructor(t){this.view=t,this.placeholder=e?L.set([L.widget({widget:new ol(e),side:1}).range(0)]):L.none}get decorations(){return this.view.state.doc.length?L.none:this.placeholder}},{decorations:e=>e.decorations});return typeof e==`string`?[t,H.contentAttributes.of({"aria-placeholder":e})]:t}var cl=class extends ar{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};cl.prototype.elementClass=``,cl.prototype.toDOM=void 0,cl.prototype.mapMode=an.TrackBefore,cl.prototype.startSide=cl.prototype.endSide=-1,cl.prototype.point=!0;const ll=1024;let ul=0;var dl=class{constructor(e,t){this.from=e,this.to=t}},U=class{constructor(e={}){this.id=ul++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw Error(`This node type doesn't define a deserialize function`)}),this.combine=e.combine||null}add(e){if(this.perNode)throw RangeError(`Can't add per-node props to node types`);return typeof e!=`function`&&(e=W.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};U.closedBy=new U({deserialize:e=>e.split(` `)}),U.openedBy=new U({deserialize:e=>e.split(` `)}),U.group=new U({deserialize:e=>e.split(` `)}),U.isolate=new U({deserialize:e=>{if(e&&e!=`rtl`&&e!=`ltr`&&e!=`auto`)throw RangeError(`Invalid value for isolate: `+e);return e||`auto`}}),U.contextHash=new U({perNode:!0}),U.lookAhead=new U({perNode:!0}),U.mounted=new U({perNode:!0});var fl=class{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[U.mounted.id]}};const pl=Object.create(null);var W=class e{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(t){let n=t.props&&t.props.length?Object.create(null):pl,r=!!t.top|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new e(t.name||``,n,t.id,r);if(t.props){for(let e of t.props)if(Array.isArray(e)||(e=e(i)),e){if(e[0].perNode)throw RangeError(`Can't store a per-node prop on a node type`);n[e[0].id]=e[1]}}return i}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(U.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(` `))t[r]=e[n];return e=>{for(let n=e.prop(U.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}};W.none=new W(``,Object.create(null),0,8);var ml=class e{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw RangeError(`Node type ids should correspond to array positions when creating a node set`)}extend(...t){let n=[];for(let e of this.types){let r=null;for(let n of t){let t=n(e);if(t){r||=Object.assign({},e.props);let n=t[1],i=t[0];i.combine&&i.id in r&&(n=i.combine(r[i.id],n)),r[i.id]=n}}n.push(r?new W(e.name,r,e.id,e.flags):e)}return new e(n)}};const hl=new WeakMap,gl=new WeakMap;var G;(function(e){e[e.ExcludeBuffers=1]=`ExcludeBuffers`,e[e.IncludeAnonymous=2]=`IncludeAnonymous`,e[e.IgnoreMounts=4]=`IgnoreMounts`,e[e.IgnoreOverlays=8]=`IgnoreOverlays`,e[e.EnterBracketed=16]=`EnterBracketed`})(G||={});var K=class e{constructor(e,t,n,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props[typeof e==`number`?e:e.id]=t}}toString(){let e=fl.get(this);if(e&&!e.overlay)return e.tree.toString();let t=``;for(let e of this.children){let n=e.toString();n&&(t&&(t+=`,`),t+=n)}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 Al(this.topNode,e)}cursorAt(e,t=0,n=0){let r=new Al(hl.get(this)||this.topNode);return r.moveTo(e,t),hl.set(this,r._tree),r}get topNode(){return new Sl(this,0,0,null)}resolve(e,t=0){let n=bl(hl.get(this)||this.topNode,e,t,!1);return hl.set(this,n),n}resolveInner(e,t=0){let n=bl(gl.get(this)||this.topNode,e,t,!0);return gl.set(this,n),n}resolveStack(e,t=0){return kl(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:i=this.length}=e,a=e.mode||0,o=(a&G.IncludeAnonymous)>0;for(let e=this.cursor(a|G.IncludeAnonymous);;){let a=!1;if(e.from<=i&&e.to>=r&&(!o&&e.type.isAnonymous||t(e)!==!1)){if(e.firstChild())continue;a=!0}for(;a&&n&&(o||!e.type.isAnonymous)&&n(e),!e.nextSibling();){if(!e.parent())return;a=!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(t={}){return this.children.length<=8?this:Fl(W.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new e(this.type,t,n,r,this.propValues),t.makeTree||((t,n,r)=>new e(W.none,t,n,r)))}static build(e){return Ml(e)}};K.empty=new K(W.none,[],[],0);var _l=class e{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 e(this.buffer,this.index)}},vl=class e{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return W.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(`,`)}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),e+=4,n==e)return i;let a=[];for(;e<n;)a.push(this.childString(e)),e=this.buffer[e+3];return i+`(`+a.join(`,`)+`)`}findChild(e,t,n,r,i){let{buffer:a}=this,o=-1;for(let s=e;s!=t&&!(yl(i,r,a[s+1],a[s+2])&&(o=s,n>0));s=a[s+3]);return o}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let e=t,s=0;e<n;){a[s++]=i[e++],a[s++]=i[e++]-r;let n=a[s++]=i[e++]-r;a[s++]=i[e++]-t,o=Math.max(o,n)}return new e(a,o,this.set)}};function yl(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function bl(e,t,n,r){for(;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!r&&e instanceof Sl&&e.index<0?null:e.parent;if(!t)return e;e=t}let i=r?0:G.IgnoreOverlays;if(r)for(let r=e,a=r.parent;a;r=a,a=r.parent)r instanceof Sl&&r.index<0&&a.enter(t,n,i)?.from!=r.from&&(e=a);for(;;){let r=e.enter(t,n,i);if(!r)return e;e=r}}var xl=class{cursor(e=0){return new Al(this,e)}getChild(e,t=null,n=null){let r=Cl(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Cl(this,e,t,n)}resolve(e,t=0){return bl(this,e,t,!1)}resolveInner(e,t=0){return bl(this,e,t,!0)}matchContext(e){return wl(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(n=t,t=e.prevSibling):t=e}return n}get node(){return this}get next(){return this.parent}},Sl=class e extends xl{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:s,positions:c}=o._tree,l=n>0?s.length:-1;t!=l;t+=n){let l=s[t],u=c[t]+o.from,d;if(!(!(a&G.EnterBracketed&&l instanceof K&&(d=fl.get(l))&&!d.overlay&&d.bracketed&&r>=u&&r<=u+l.length)&&!yl(i,r,u,u+l.length))){if(l instanceof vl){if(a&G.ExcludeBuffers)continue;let e=l.findChild(0,l.buffer.length,n,r-u,i);if(e>-1)return new El(new Tl(o,l,t,u),null,e)}else if(a&G.IncludeAnonymous||!l.type.isAnonymous||jl(l)){let s;if(!(a&G.IgnoreMounts)&&(s=fl.get(l))&&!s.overlay)return new e(s.tree,u,t,o);let c=new e(l,u,t,o);return a&G.IncludeAnonymous||!c.type.isAnonymous?c:c.nextChild(n<0?l.children.length-1:0,n,r,i,a)}}}if(a&G.IncludeAnonymous||!o.type.isAnonymous||(t=o.index>=0?o.index+n:n<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(t,n,r=0){let i;if(!(r&G.IgnoreOverlays)&&(i=fl.get(this._tree))&&i.overlay){let a=t-this.from,o=r&G.EnterBracketed&&i.bracketed;for(let{from:t,to:r}of i.overlay)if((n>0||o?t<=a:t<a)&&(n<0||o?r>=a:r>a))return new e(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}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 Cl(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let e=!1;!e;)if(e=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function wl(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}var Tl=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},El=class e extends xl{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new e(this.context,this,a)}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(t,n,r=0){if(r&G.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new e(this.context,this,a)}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:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new e(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new e(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let a=n.buffer[this.index+1];e.push(n.slice(r,i,a)),t.push(0)}return new K(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Dl(e){if(!e.length)return null;let t=0,n=e[0];for(let r=1;r<e.length;r++){let i=e[r];(i.from>n.from||i.to<n.to)&&(n=i,t=r)}let r=n instanceof Sl&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new Ol(i,n)}var Ol=class{constructor(e,t){this.heads=e,this.node=t}get next(){return Dl(this.heads)}};function kl(e,t,n){let r=e.resolveInner(t,n),i=null;for(let e=r instanceof Sl?r:r.context.parent;e;e=e.parent)if(e.index<0){let a=e.parent;(i||=[r]).push(a.resolve(t,n)),e=a}else{let a=fl.get(e.tree);if(a&&a.overlay&&a.overlay[0].from<=t&&a.overlay[a.overlay.length-1].to>=t){let o=new Sl(a.tree,a.overlay[0].from+e.from,-1,e);(i||=[r]).push(bl(o,t,n,!1))}}return i?Dl(i):r}var Al=class{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&~G.EnterBracketed,e instanceof Sl)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof Sl?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&G.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&G.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&G.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(r.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];if(this.mode&G.IncludeAnonymous||e instanceof vl||!e.type.isAnonymous||jl(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)scan:for(let r=this.index,i=this.stack.length;i>=0;){for(let a=e;a;a=a._parent)if(a.index==r){if(r==this.index)return a;t=a,n=i+1;break scan}r=this.stack[--i]}for(let e=n;e<this.stack.length;e++)t=new El(this.buffer,t,this.stack[e]);return this.bufferNode=new El(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return wl(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return wl(this._tree,e,r);let a=n[t.buffer[this.stack[i]]];if(!a.isAnonymous){if(e[r]&&e[r]!=a.name)return!1;r--}}return!0}};function jl(e){return e.children.some(e=>e instanceof vl||!e.type.isAnonymous||jl(e))}function Ml(e){let{buffer:t,nodeSet:n,maxBufferLength:r=ll,reused:i=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(t)?new _l(t,t.length):t,s=n.types,c=0,l=0;function u(e,t,_,v,y,b){let{id:x,start:S,end:C,size:ee}=o,te=l,ne=c;if(ee<0)if(o.next(),ee==-1){let t=i[x];_.push(t),v.push(S-e);return}else if(ee==-3){c=x;return}else if(ee==-4){l=x;return}else throw RangeError(`Unrecognized record size: ${ee}`);let w=s[x],re,T,ie=S-e;if(C-S<=r&&(T=h(o.pos-t,y))){let t=new Uint16Array(T.size-T.skip),r=o.pos-T.size,i=t.length;for(;o.pos>r;)i=g(T.start,t,i);re=new vl(t,C-T.start,n),ie=T.start-e}else{let e=o.pos-ee;o.next();let t=[],n=[],i=x>=a?x:-1,s=0,c=C;for(;o.pos>e;)i>=0&&o.id==i&&o.size>=0?(o.end<=c-r&&(p(t,n,S,s,o.end,c,i,te,ne),s=t.length,c=o.end),o.next()):b>2500?d(S,e,t,n):u(S,e,t,n,i,b+1);if(i>=0&&s>0&&s<t.length&&p(t,n,S,s,S,c,i,te,ne),t.reverse(),n.reverse(),i>-1&&s>0){let e=f(w,ne);re=Fl(w,t,n,0,t.length,0,C-S,e,e)}else re=m(w,t,n,C-S,te-C,ne)}_.push(re),v.push(ie)}function d(e,t,i,a){let s=[],c=0,l=-1;for(;o.pos>t;){let{id:e,start:t,end:n,size:i}=o;if(i>4)o.next();else if(l>-1&&t<l)break;else l<0&&(l=n-r),s.push(e,t,n),c++,o.next()}if(c){let t=new Uint16Array(c*4),r=s[s.length-2];for(let e=s.length-3,n=0;e>=0;e-=3)t[n++]=s[e],t[n++]=s[e+1]-r,t[n++]=s[e+2]-r,t[n++]=n;i.push(new vl(t,s[2]-r,n)),a.push(r-e)}}function f(e,t){return(n,r,i)=>{let a=0,o=n.length-1,s,c;if(o>=0&&(s=n[o])instanceof K){if(!o&&s.type==e&&s.length==i)return s;(c=s.prop(U.lookAhead))&&(a=r[o]+s.length+c)}return m(e,n,r,i,a,t)}}function p(e,t,r,i,a,o,s,c,l){let u=[],d=[];for(;e.length>i;)u.push(e.pop()),d.push(t.pop()+r-a);e.push(m(n.types[s],u,d,o-a,c-o,l)),t.push(a-r)}function m(e,t,n,r,i,a,o){if(a){let e=[U.contextHash,a];o=o?[e].concat(o):[e]}if(i>25){let e=[U.lookAhead,i];o=o?[e].concat(o):[e]}return new K(e,t,n,r,o)}function h(e,t){let n=o.fork(),i=0,s=0,c=0,l=n.end-r,u={size:0,start:0,skip:0};scan:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){u.size=i,u.start=s,u.skip=c,c+=4,i+=4,n.next();continue}let o=n.pos-e;if(e<0||o<r||n.start<l)break;let d=n.id>=a?4:0,f=n.start;for(n.next();n.pos>o;){if(n.size<0)if(n.size==-3||n.size==-4)d+=4;else break scan;else n.id>=a&&(d+=4);n.next()}s=f,i+=e,c+=d}return(t<0||i==e)&&(u.size=i,u.start=s,u.skip=c),u.size>4?u:void 0}function g(e,t,n){let{id:r,start:i,end:s,size:u}=o;if(o.next(),u>=0&&r<a){let a=n;if(u>4){let r=o.pos-(u-4);for(;o.pos>r;)n=g(e,t,n)}t[--n]=a,t[--n]=s-e,t[--n]=i-e,t[--n]=r}else u==-3?c=r:u==-4&&(l=r);return n}let _=[],v=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,_,v,-1,0);let y=e.length??(_.length?v[0]+_[0].length:0);return new K(s[e.topID],_.reverse(),v.reverse(),y)}const Nl=new WeakMap;function Pl(e,t){if(!e.isAnonymous||t instanceof vl||t.type!=e)return 1;let n=Nl.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof K)){n=1;break}n+=Pl(e,r)}Nl.set(t,n)}return n}function Fl(e,t,n,r,i,a,o,s,c){let l=0;for(let n=r;n<i;n++)l+=Pl(e,t[n]);let u=Math.ceil(l*1.5/8),d=[],f=[];function p(t,n,r,i,o){for(let s=r;s<i;){let r=s,l=n[s],m=Pl(e,t[s]);for(s++;s<i;s++){let n=Pl(e,t[s]);if(m+n>=u)break;m+=n}if(s==r+1){if(m>u){let e=t[r];p(e.children,e.positions,0,e.children.length,n[r]+o);continue}d.push(t[r])}else{let i=n[s-1]+t[s-1].length-l;d.push(Fl(e,t,n,r,s,l,i,null,c))}f.push(l+o-a)}}return p(t,n,r,i,0),(s||c)(d,f,o)}var Il=class{constructor(){this.map=new WeakMap}setBuffer(e,t,n){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,n)}getBuffer(e,t){let n=this.map.get(e);return n&&n.get(t)}set(e,t){e instanceof El?this.setBuffer(e.context.buffer,e.index,t):e instanceof Sl&&this.map.set(e.tree,t)}get(e){return e instanceof El?this.getBuffer(e.context.buffer,e.index):e instanceof Sl?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)}},Ll=class e{constructor(e,t,n,r,i=!1,a=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=!!i|(a?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new e(0,t.length,t,0,!1,r)];for(let e of n)e.to>t.length&&i.push(e);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let s=0,c=0,l=0;;s++){let u=s<n.length?n[s]:null,d=u?u.fromA:1e9;if(d-c>=r)for(;o&&o.from<d;){let n=o;if(c>=n.from||d<=n.to||l){let t=Math.max(n.from,c)-l,r=Math.min(n.to,d)-l;n=t>=r?null:new e(t,r,n.tree,n.offset+l,s>0,!!u)}if(n&&i.push(n),o.to>d)break;o=a<t.length?t[a++]:null}if(!u)break;c=u.toA,l=u.toA-u.toB}return i}},Rl=class{startParse(e,t,n){return typeof e==`string`&&(e=new zl(e)),n=n?n.length?n.map(e=>new dl(e.from,e.to)):[new dl(0,0)]:[new dl(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let e=r.advance();if(e)return e}}},zl=class{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 Bl(e){return(t,n,r,i)=>new Gl(t,e,n,r,i)}var Vl=class{constructor(e,t,n,r,i,a){this.parser=e,this.parse=t,this.overlay=n,this.bracketed=r,this.target=i,this.from=a}};function Hl(e){if(!e.length||e.some(e=>e.from>=e.to))throw RangeError(`Invalid inner parse ranges given: `+JSON.stringify(e))}var Ul=class{constructor(e,t,n,r,i,a,o,s){this.parser=e,this.predicate=t,this.mounts=n,this.index=r,this.start=i,this.bracketed=a,this.target=o,this.prev=s,this.depth=0,this.ranges=[]}};const Wl=new U({perNode:!0});var Gl=class{constructor(e,t,n,r,i){this.nest=t,this.input=n,this.fragments=r,this.ranges=i,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let e=this.baseParse.advance();if(!e)return null;if(this.baseParse=null,this.baseTree=e,this.startInner(),this.stoppedAt!=null)for(let e of this.inner)e.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let e=this.baseTree;return this.stoppedAt!=null&&(e=new K(e.type,e.children,e.positions,e.length,e.propValues.concat([[Wl,this.stoppedAt]]))),e}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let n=Object.assign(Object.create(null),e.target.props);n[U.mounted.id]=new fl(t,e.overlay,e.parser,e.bracketed),e.target.props=n}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Xl(this.fragments),t=null,n=null,r=new Al(new Sl(this.baseTree,this.ranges[0].from,0,null),G.IncludeAnonymous|G.IgnoreMounts);scan:for(let i,a;;){let o=!0,s;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)o=!1;else if(e.hasNode(r)){if(t){let e=t.mounts.find(e=>e.frag.from<=r.from&&e.frag.to>=r.to&&e.mount.overlay);if(e)for(let n of e.mount.overlay){let i=n.from+e.pos,a=n.to+e.pos;i>=r.from&&a<=r.to&&!t.ranges.some(e=>e.from<a&&e.to>i)&&t.ranges.push({from:i,to:a})}}o=!1}else if(n&&(a=Kl(n.ranges,r.from,r.to)))o=a!=2;else if(!r.type.isAnonymous&&(i=this.nest(r,this.input))&&(r.from<r.to||!i.overlay)){r.tree||(Jl(r),t&&t.depth++,n&&n.depth++);let a=e.findMounts(r.from,i.parser);if(typeof i.overlay==`function`)t=new Ul(i.parser,i.overlay,a,this.inner.length,r.from,!!i.bracketed,r.tree,t);else{let e=Zl(this.ranges,i.overlay||(r.from<r.to?[new dl(r.from,r.to)]:[]));e.length&&Hl(e),(e.length||!i.overlay)&&this.inner.push(new Vl(i.parser,e.length?i.parser.startParse(this.input,$l(a,e),e):i.parser.startParse(``),i.overlay?i.overlay.map(e=>new dl(e.from-r.from,e.to-r.from)):null,!!i.bracketed,r.tree,e.length?e[0].from:r.from)),i.overlay?e.length&&(n={ranges:e,depth:0,prev:n}):o=!1}}else if(t&&(s=t.predicate(r))&&(s===!0&&(s=new dl(r.from,r.to)),s.from<s.to)){let e=t.ranges.length-1;e>=0&&t.ranges[e].to==s.from?t.ranges[e]={from:t.ranges[e].from,to:s.to}:t.ranges.push(s)}if(o&&r.firstChild())t&&t.depth++,n&&n.depth++;else for(;!r.nextSibling();){if(!r.parent())break scan;if(t&&!--t.depth){let e=Zl(this.ranges,t.ranges);e.length&&(Hl(e),this.inner.splice(t.index,0,new Vl(t.parser,t.parser.startParse(this.input,$l(t.mounts,e),e),t.ranges.map(e=>new dl(e.from-t.start,e.to-t.start)),t.bracketed,t.target,e[0].from))),t=t.prev}n&&!--n.depth&&(n=n.prev)}}}};function Kl(e,t,n){for(let r of e){if(r.from>=n)break;if(r.to>t)return r.from<=t&&r.to>=n?2:1}return 0}function ql(e,t,n,r,i,a){if(t<n){let o=e.buffer[t+1];r.push(e.slice(t,n,o)),i.push(o-a)}}function Jl(e){let{node:t}=e,n=[],r=t.context.buffer;do n.push(e.index),e.parent();while(!e.tree);let i=e.tree,a=i.children.indexOf(r),o=i.children[a],s=o.buffer,c=[a];function l(e,r,i,a,u,d){let f=n[d],p=[],m=[];ql(o,e,f,p,m,a);let h=s[f+1],g=s[f+2];c.push(p.length);let _=d?l(f+4,s[f+3],o.set.types[s[f]],h,g-h,d-1):t.toTree();return p.push(_),m.push(h-a),ql(o,s[f+3],r,p,m,a),new K(i,p,m,u)}i.children[a]=l(0,s.length,W.none,0,o.length,n.length-1);for(let t of c){let n=e.tree.children[t],r=e.tree.positions[t];e.yield(new Sl(n,r+e.from,t,e._tree))}}var Yl=class{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(G.IncludeAnonymous|G.IgnoreMounts)}moveTo(e){let{cursor:t}=this,n=e-this.offset;for(;!this.done&&t.from<n;)if(!(t.to>=e&&t.enter(n,1,G.IgnoreOverlays|G.ExcludeBuffers)))if(t.to<=e)t.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof K)t=t.children[0];else break}return!1}},Xl=class{constructor(e){if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let t=this.curFrag=e[0];this.curTo=t.tree.prop(Wl)??t.to,this.inner=new Yl(t.tree,-t.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(){if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=e.tree.prop(Wl)??e.to,this.inner=new Yl(e.tree,-e.offset)}}findMounts(e,t){let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let e=this.inner.cursor.node;e;e=e.parent){let r=e.tree?.prop(U.mounted);if(r&&r.parser==t)for(let t=this.fragI;t<this.fragments.length;t++){let i=this.fragments[t];if(i.from>=e.to)break;i.tree==this.curFrag.tree&&n.push({frag:i,pos:e.from-i.offset,mount:r})}}}return n}};function Zl(e,t){let n=null,r=t;for(let i=1,a=0;i<e.length;i++){let o=e[i-1].to,s=e[i].from;for(;a<r.length;a++){let e=r[a];if(e.from>=s)break;e.to<=o||(n||(r=n=t.slice()),e.from<o?(n[a]=new dl(e.from,o),e.to>s&&n.splice(a+1,0,new dl(s,e.to))):e.to>s?n[a--]=new dl(s,e.to):n.splice(a--,1))}}return r}function Ql(e,t,n,r){let i=0,a=0,o=!1,s=!1,c=-1e9,l=[];for(;;){let u=i==e.length?1e9:o?e[i].to:e[i].from,d=a==t.length?1e9:s?t[a].to:t[a].from;if(o!=s){let e=Math.max(c,n),t=Math.min(u,d,r);e<t&&l.push(new dl(e,t))}if(c=Math.min(u,d),c==1e9)break;u==c&&(o?(o=!1,i++):o=!0),d==c&&(s?(s=!1,a++):s=!0)}return l}function $l(e,t){let n=[];for(let{pos:r,mount:i,frag:a}of e){let e=r+(i.overlay?i.overlay[0].from:0),o=e+i.tree.length,s=Math.max(a.from,e),c=Math.min(a.to,o);if(i.overlay){let o=Ql(t,i.overlay.map(e=>new dl(e.from+r,e.to+r)),s,c);for(let t=0,r=s;;t++){let s=t==o.length,l=s?c:o[t].from;if(l>r&&n.push(new Ll(r,l,i.tree,-e,a.from>=r||a.openStart,a.to<=l||a.openEnd)),s)break;r=o[t].to}}else n.push(new Ll(s,c,i.tree,-e,a.from>=e||a.openStart,a.to<=o||a.openEnd))}return n}let eu=0;var tu=class e{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=eu++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(t,n){let r=typeof t==`string`?t:`?`;if(t instanceof e&&(n=t),n?.base)throw Error(`Can not derive from a modified tag`);let i=new e(r,[],null,[]);if(i.set.push(i),n)for(let e of n.set)i.set.push(e);return i}static defineModifier(e){let t=new ru(e);return e=>e.modified.indexOf(t)>-1?e:ru.get(e.base||e,e.modified.concat(t).sort((e,t)=>e.id-t.id))}};let nu=0;var ru=class e{constructor(e){this.name=e,this.instances=[],this.id=nu++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(e=>e.base==t&&iu(n,e.modified));if(r)return r;let i=[],a=new tu(t.name,i,t,n);for(let e of n)e.instances.push(a);let o=au(n);for(let n of t.set)if(!n.modified.length)for(let t of o)i.push(e.get(n,t));return a}};function iu(e,t){return e.length==t.length&&e.every((e,n)=>e==t[n])}function au(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,i=t.length;r<i;r++)t.push(t[r].concat(e[n]));return t.sort((e,t)=>t.length-e.length)}function ou(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let e of n.split(` `))if(e){let n=[],i=2,a=e;for(let t=0;;){if(a==`...`&&t>0&&t+3==e.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!r)throw RangeError(`Invalid path: `+e);if(n.push(r[0]==`*`?``:r[0][0]==`"`?JSON.parse(r[0]):r[0]),t+=r[0].length,t==e.length)break;let o=e[t++];if(t==e.length&&o==`!`){i=0;break}if(o!=`/`)throw RangeError(`Invalid path: `+e);a=e.slice(t)}let o=n.length-1,s=n[o];if(!s)throw RangeError(`Invalid path: `+e);t[s]=new cu(r,i,o>0?n.slice(0,o):null).sort(t[s])}}return su.add(t)}const su=new U({combine(e,t){let n,r,i;for(;e||t;){if(!e||t&&e.depth>=t.depth?(i=t,t=t.next):(i=e,e=e.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let a=new cu(i.tags,i.mode,i.context);n?n.next=a:r=a,n=a}return r}});var cu=class{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};cu.empty=new cu([],2,null);function lu(e,t){let n=Object.create(null);for(let t of e)if(!Array.isArray(t.tag))n[t.tag.id]=t.class;else for(let e of t.tag)n[e.id]=t.class;let{scope:r,all:i=null}=t||{};return{style:e=>{let t=i;for(let r of e)for(let e of r.set){let r=n[e.id];if(r){t=t?t+` `+r:r;break}}return t},scope:r}}function uu(e,t){let n=null;for(let r of e){let e=r.style(t);e&&(n=n?n+` `+e:e)}return n}function du(e,t,n,r=0,i=e.length){let a=new fu(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,``,a.highlighters),a.flush(i)}var fu=class{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=``}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,i){let{type:a,from:o,to:s}=e;if(o>=n||s<=t)return;a.isTop&&(i=this.highlighters.filter(e=>!e.scope||e.scope(a)));let c=r,l=pu(e)||cu.empty,u=uu(i,l.tags);if(u&&(c&&(c+=` `),c+=u,l.mode==1&&(r+=(r?` `:``)+u)),this.startSpan(Math.max(t,o),c),l.opaque)return;let d=e.tree&&e.tree.prop(U.mounted);if(d&&d.overlay){let a=e.node.enter(d.overlay[0].from+o,1),l=this.highlighters.filter(e=>!e.scope||e.scope(d.tree.type)),u=e.firstChild();for(let f=0,p=o;;f++){let m=f<d.overlay.length?d.overlay[f]:null,h=m?m.from+o:s,g=Math.max(t,p),_=Math.min(n,h);if(g<_&&u)for(;e.from<_&&(this.highlightRange(e,g,_,r,i),this.startSpan(Math.min(_,e.to),c),!(e.to>=h||!e.nextSibling())););if(!m||h>n)break;p=m.to+o,p>t&&(this.highlightRange(a.cursor(),Math.max(t,m.from+o),Math.min(n,p),``,l),this.startSpan(Math.min(n,p),c))}u&&e.parent()}else if(e.firstChild()){d&&(r=``);do{if(e.to<=t)continue;if(e.from>=n)break;this.highlightRange(e,t,n,r,i),this.startSpan(Math.min(n,e.to),c)}while(e.nextSibling());e.parent()}}};function pu(e){let t=e.type.prop(su);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}const q=tu.define,mu=q(),hu=q(),gu=q(hu),_u=q(hu),vu=q(),yu=q(vu),bu=q(vu),xu=q(),Su=q(xu),Cu=q(),wu=q(),Tu=q(),Eu=q(Tu),Du=q(),J={comment:mu,lineComment:q(mu),blockComment:q(mu),docComment:q(mu),name:hu,variableName:q(hu),typeName:gu,tagName:q(gu),propertyName:_u,attributeName:q(_u),className:q(hu),labelName:q(hu),namespace:q(hu),macroName:q(hu),literal:vu,string:yu,docString:q(yu),character:q(yu),attributeValue:q(yu),number:bu,integer:q(bu),float:q(bu),bool:q(vu),regexp:q(vu),escape:q(vu),color:q(vu),url:q(vu),keyword:Cu,self:q(Cu),null:q(Cu),atom:q(Cu),unit:q(Cu),modifier:q(Cu),operatorKeyword:q(Cu),controlKeyword:q(Cu),definitionKeyword:q(Cu),moduleKeyword:q(Cu),operator:wu,derefOperator:q(wu),arithmeticOperator:q(wu),logicOperator:q(wu),bitwiseOperator:q(wu),compareOperator:q(wu),updateOperator:q(wu),definitionOperator:q(wu),typeOperator:q(wu),controlOperator:q(wu),punctuation:Tu,separator:q(Tu),bracket:Eu,angleBracket:q(Eu),squareBracket:q(Eu),paren:q(Eu),brace:q(Eu),content:xu,heading:Su,heading1:q(Su),heading2:q(Su),heading3:q(Su),heading4:q(Su),heading5:q(Su),heading6:q(Su),contentSeparator:q(xu),list:q(xu),quote:q(xu),emphasis:q(xu),strong:q(xu),link:q(xu),monospace:q(xu),strikethrough:q(xu),inserted:q(),deleted:q(),changed:q(),invalid:q(),meta:Du,documentMeta:q(Du),annotation:q(Du),processingInstruction:q(Du),definition:tu.defineModifier(`definition`),constant:tu.defineModifier(`constant`),function:tu.defineModifier(`function`),standard:tu.defineModifier(`standard`),local:tu.defineModifier(`local`),special:tu.defineModifier(`special`)};for(let e in J){let t=J[e];t instanceof tu&&(t.name=e)}lu([{tag:J.link,class:`tok-link`},{tag:J.heading,class:`tok-heading`},{tag:J.emphasis,class:`tok-emphasis`},{tag:J.strong,class:`tok-strong`},{tag:J.keyword,class:`tok-keyword`},{tag:J.atom,class:`tok-atom`},{tag:J.bool,class:`tok-bool`},{tag:J.url,class:`tok-url`},{tag:J.labelName,class:`tok-labelName`},{tag:J.inserted,class:`tok-inserted`},{tag:J.deleted,class:`tok-deleted`},{tag:J.literal,class:`tok-literal`},{tag:J.string,class:`tok-string`},{tag:J.number,class:`tok-number`},{tag:[J.regexp,J.escape,J.special(J.string)],class:`tok-string2`},{tag:J.variableName,class:`tok-variableName`},{tag:J.local(J.variableName),class:`tok-variableName tok-local`},{tag:J.definition(J.variableName),class:`tok-variableName tok-definition`},{tag:J.special(J.variableName),class:`tok-variableName2`},{tag:J.definition(J.propertyName),class:`tok-propertyName tok-definition`},{tag:J.typeName,class:`tok-typeName`},{tag:J.namespace,class:`tok-namespace`},{tag:J.className,class:`tok-className`},{tag:J.macroName,class:`tok-macroName`},{tag:J.propertyName,class:`tok-propertyName`},{tag:J.operator,class:`tok-operator`},{tag:J.comment,class:`tok-comment`},{tag:J.meta,class:`tok-meta`},{tag:J.invalid,class:`tok-invalid`},{tag:J.punctuation,class:`tok-punctuation`}]);const Ou=new U;function ku(e){return M.define({combine:e?t=>t.concat(e):void 0})}const Au=new U;var ju=class{constructor(e,t,n=[],r=``){this.data=e,this.name=r,P.prototype.hasOwnProperty(`tree`)||Object.defineProperty(P.prototype,"tree",{get(){return Y(this)}}),this.parser=t,this.extension=[Hu.of(this),P.languageData.of((e,t,n)=>{let r=Mu(e,t,n),i=r.type.prop(Ou);if(!i)return[];let a=e.facet(i),o=r.type.prop(Au);if(o){let i=r.resolve(t-r.from,n);for(let t of o)if(t.test(i,e)){let n=e.facet(t.facet);return t.type==`replace`?n:n.concat(a)}}return a})].concat(n)}isActiveAt(e,t,n=-1){return Mu(e,t,n).type.prop(Ou)==this.data}findRegions(e){let t=e.facet(Hu);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(e,t)=>{if(e.prop(Ou)==this.data){n.push({from:t,to:t+e.length});return}let i=e.prop(U.mounted);if(i){if(i.tree.prop(Ou)==this.data){if(i.overlay)for(let e of i.overlay)n.push({from:e.from+t,to:e.to+t});else n.push({from:t,to:t+e.length});return}else if(i.overlay){let e=n.length;if(r(i.tree,i.overlay[0].from+t),n.length>e)return}}for(let n=0;n<e.children.length;n++){let i=e.children[n];i instanceof K&&r(i,e.positions[n]+t)}};return r(Y(e),0),n}get allowsNesting(){return!0}};ju.setState=N.define();function Mu(e,t,n){let r=e.facet(Hu),i=Y(e).topNode;if(!r||r.allowsNesting)for(let e=i;e;e=e.enter(t,n,G.ExcludeBuffers|G.EnterBracketed))e.type.isTop&&(i=e);return i}var Nu=class e extends ju{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(t){let n=ku(t.languageData);return new e(n,t.parser.configure({props:[Ou.add(e=>e.isTop?n:void 0)]}),t.name)}configure(t,n){return new e(this.data,this.parser.configure(t),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function Y(e){let t=e.field(ju.state,!1);return t?t.tree:K.empty}var Pu=class{constructor(e){this.doc=e,this.cursorPos=0,this.string=``,this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}};let Fu=null;var Iu=class e{constructor(e,t,n=[],r,i,a,o,s){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=i,this.viewport=a,this.skipped=o,this.scheduleOn=s,this.parse=null,this.tempSkipped=[]}static create(t,n,r){return new e(t,n,[],K.empty,0,r,[],null)}startParse(){return this.parser.startParse(new Pu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=K.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{if(typeof e==`number`){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||=this.startParse(),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(Ll.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=this.parse.stoppedAt??this.state.doc.length,this.tree=n,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(Ll.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Fu;Fu=this;try{return e()}finally{Fu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Lu(e,t.from,t.to);return e}changes(t,n){let{fragments:r,tree:i,treeLen:a,viewport:o,skipped:s}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,n,r,i)=>e.push({fromA:t,toA:n,fromB:r,toB:i})),r=Ll.applyChanges(r,e),i=K.empty,a=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){s=[];for(let e of this.skipped){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);n<r&&s.push({from:n,to:r})}}}return new e(this.parser,n,r,i,a,o,s,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 t=0;t<this.skipped.length;t++){let{from:n,to:r}=this.skipped[t];n<e.to&&r>e.from&&(this.fragments=Lu(this.fragments,n,r),this.skipped.splice(t--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&=(this.takeTree(),null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Rl{createParse(t,n,r){let i=r[0].from,a=r[r.length-1].to;return{parsedPos:i,advance(){let t=Fu;if(t){for(let e of r)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=a,new K(W.none,[],[],a-i)},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 Fu}};function Lu(e,t,n){return Ll.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}var Ru=class e{constructor(e){this.context=e,this.tree=e.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(t.changes,t.state),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new e(n)}static init(t){let n=Math.min(3e3,t.doc.length),r=Iu.create(t.facet(Hu).parser,t,{from:0,to:n});return r.work(20,n)||r.takeTree(),new e(r)}};ju.state=Cn.define({create:Ru.init,update(e,t){for(let e of t.effects)if(e.is(ju.setState))return e.value;return t.startState.facet(Hu)==t.state.facet(Hu)?e.apply(t):Ru.init(t.state)}});let zu=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<`u`&&(zu=e=>{let t=-1,n=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const Bu=typeof navigator<`u`&&navigator.scheduling?.isInputPending?()=>navigator.scheduling.isInputPending():null,Vu=wa.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(ju.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(ju.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=zu(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:r}}=this.view,i=n.field(ju.state);if(i.tree==i.context.tree&&i.context.isDone(r+1e5))return;let a=Date.now()+Math.min(this.chunkBudget,100,e&&!Bu?Math.max(25,e.timeRemaining()-5):1e9),o=i.context.treeLen<r&&n.doc.length>r+1e3,s=i.context.work(()=>Bu&&Bu()||Date.now()>a,r+(o?0:1e5));this.chunkBudget-=Date.now()-t,(s||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:ju.setState.of(new Ru(i.context))})),this.chunkBudget>0&&!(s&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(e){e.scheduleOn&&=(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(e=>ba(this.view.state,e)).then(()=>this.workScheduled--),null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Hu=M.define({combine(e){return e.length?e[0]:null},enables:e=>[ju.state,Vu,H.contentAttributes.compute([e],t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}})]});var Uu=class{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}},Wu=class e{constructor(e,t,n,r,i,a=void 0){this.name=e,this.alias=t,this.extensions=n,this.filename=r,this.loadFunc=i,this.support=a,this.loading=null}load(){return this.loading||=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e})}static of(t){let{load:n,support:r}=t;if(!n){if(!r)throw RangeError(`Must pass either 'load' or 'support' to LanguageDescription.of`);n=()=>Promise.resolve(r)}return new e(t.name,(t.alias||[]).concat(t.name).map(e=>e.toLowerCase()),t.extensions||[],t.filename,n,r)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let n=/\.([^.]+)$/.exec(t);if(n){for(let t of e)if(t.extensions.indexOf(n[1])>-1)return t}return null}static matchLanguageName(e,t,n=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some(e=>e==t))return n;if(n)for(let n of e)for(let e of n.alias){let r=t.indexOf(e);if(r>-1&&(e.length>2||!/\w/.test(t[r-1])&&!/\w/.test(t[r+e.length])))return n}return null}};const Gu=M.define(),Ku=M.define({combine:e=>{if(!e.length)return` `;let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw Error(`Invalid indent unit: `+JSON.stringify(e[0]));return t}});function qu(e){let t=e.facet(Ku);return t.charCodeAt(0)==9?e.tabSize*t.length:t.length}function Ju(e,t){let n=``,r=e.tabSize,i=e.facet(Ku)[0];if(i==` `){for(;t>=r;)n+=` `,t-=r;i=` `}for(let e=0;e<t;e++)n+=i;return n}function Yu(e,t){e instanceof P&&(e=new Xu(e));for(let n of e.state.facet(Gu)){let r=n(e,t);if(r!==void 0)return r}let n=Y(e.state);return n.length>=t?Qu(e,n,t):null}var Xu=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=qu(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:i}=this.options;return r!=null&&r>=n.from&&r<=n.to?i&&r==e?{text:``,from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return``;let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.countColumn(n,e-r),a=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return a>-1&&(i+=a-this.countColumn(n,n.search(/\S|$/))),i}countColumn(e,t=e.length){return Cr(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.options.overrideIndentation;if(i){let e=i(r);if(e>-1)return e}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}};const Zu=new U;function Qu(e,t,n){let r=t.resolveStack(n),i=t.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(i!=r.node){let e=[];for(let t=i;t&&!(t.from<r.node.from||t.to>r.node.to||t.from==r.node.from&&t.type==r.node.type);t=t.parent)e.push(t);for(let t=e.length-1;t>=0;t--)r={node:e[t],next:r}}return $u(r,e,n)}function $u(e,t,n){for(let r=e;r;r=r.next){let e=td(r.node);if(e)return e(rd.create(t,n,r))}return 0}function ed(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}function td(e){let t=e.type.prop(Zu);if(t)return t;let n=e.firstChild,r;if(n&&(r=n.type.prop(U.closedBy))){let t=e.lastChild,n=t&&r.indexOf(t.name)>-1;return e=>sd(e,!0,1,void 0,n&&!ed(e)?t.from:void 0)}return e.parent==null?nd:null}function nd(){return 0}var rd=class e extends Xu{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.context=n}get node(){return this.context.node}static create(t,n,r){return new e(t,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(id(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){return $u(this.context.next,this.base,this.pos)}};function id(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function ad(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let i=e.options.simulateBreak,a=e.state.doc.lineAt(n.from),o=i==null||i<=a.from?a.to:Math.min(a.to,i);for(let e=n.to;;){let i=t.childAfter(e);if(!i||i==r)return null;if(!i.type.isSkipped){if(i.from>=o)return null;let e=/^ */.exec(a.text.slice(n.to-a.from))[0].length;return{from:n.from,to:n.to+e}}e=i.to}}function od({closing:e,align:t=!0,units:n=1}){return r=>sd(r,t,n,e)}function sd(e,t,n,r,i){let a=e.textAfter,o=a.match(/^\s*/)[0].length,s=r&&a.slice(o,o+r.length)==r||i==e.pos+o,c=t?ad(e):null;return c?s?e.column(c.from):e.column(c.to):e.baseIndent+(s?0:e.unit*n)}const cd=e=>e.baseIndent;function ld({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}const ud=M.define(),dd=new U;function fd(e){let t=e.firstChild,n=e.lastChild;return t&&t.to<n.from?{from:t.to,to:n.type.isError?e.to:n.from}:null}var pd=class e{constructor(e,t){this.specs=e;let n;function r(e){let t=Or.newName();return(n||=Object.create(null))[`.`+t]=e,t}let i=typeof t.all==`string`?t.all:t.all?r(t.all):void 0,a=t.scope;this.scope=a instanceof ju?e=>e.prop(Ou)==a.data:a?e=>e==a:void 0,this.style=lu(e.map(e=>({tag:e.tag,class:e.class||r(Object.assign({},e,{tag:null}))})),{all:i}).style,this.module=n?new Or(n):null,this.themeType=t.themeType}static define(t,n){return new e(t,n||{})}};const md=M.define(),hd=M.define({combine(e){return e.length?[e[0]]:null}});function gd(e){let t=e.facet(md);return t.length?t:e.facet(hd)}function _d(e,t){let n=[yd],r;return e instanceof pd&&(e.module&&n.push(H.styleModule.of(e.module)),r=e.themeType),t?.fallback?n.push(hd.of(e)):r?n.push(md.computeN([H.darkTheme],t=>t.facet(H.darkTheme)==(r==`dark`)?[e]:[])):n.push(md.of(e)),n}var vd=class{constructor(e){this.markCache=Object.create(null),this.tree=Y(e.state),this.decorations=this.buildDeco(e,gd(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Y(e.state),n=gd(e.state),r=n!=gd(e.startState),{viewport:i}=e.view,a=e.changes.mapPos(this.decoratedTo,1);t.length<i.to&&!r&&t.type==this.tree.type&&a>=i.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=a):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n),this.decoratedTo=i.to)}buildDeco(e,t){if(!t||!this.tree.length)return L.none;let n=new fr;for(let{from:r,to:i}of e.visibleRanges)du(this.tree,t,(e,t,r)=>{n.add(e,t,this.markCache[r]||(this.markCache[r]=L.mark({class:r})))},r,i);return n.finish()}};const yd=En.high(wa.fromClass(vd,{decorations:e=>e.decorations}));J.meta,J.link,J.heading,J.emphasis,J.strong,J.strikethrough,J.keyword,J.atom,J.bool,J.url,J.contentSeparator,J.labelName,J.literal,J.inserted,J.string,J.deleted,J.regexp,J.escape,J.string,J.variableName,J.variableName,J.typeName,J.namespace,J.className,J.variableName,J.macroName,J.propertyName,J.comment,J.invalid;const bd=new U;function xd(e,t,n){let r=e.prop(t<0?U.openedBy:U.closedBy);if(r)return r;if(e.name.length==1){let r=n.indexOf(e.name);if(r>-1&&r%2==+(t<0))return[n[r+t]]}return null}function Sd(e){let t=e.type.prop(bd);return t?t(e.node):e}function Cd(e,t,n,r={}){let i=r.maxScanDistance||1e4,a=r.brackets||`()[]{}`,o=Y(e),s=o.resolveInner(t,n);for(let r=s;r;r=r.parent){let i=xd(r.type,n,a);if(i&&r.from<r.to){let o=Sd(r);if(o&&(n>0?t>=o.from&&t<o.to:t>o.from&&t<=o.to))return wd(e,t,n,r,o,i,a)}}return Td(e,t,n,o,s.type,i,a)}function wd(e,t,n,r,i,a,o){let s=r.parent,c={from:i.from,to:i.to},l=0,u=s?.cursor();if(u&&(n<0?u.childBefore(r.from):u.childAfter(r.to)))do if(n<0?u.to<=r.from:u.from>=r.to){if(l==0&&a.indexOf(u.type.name)>-1&&u.from<u.to){let e=Sd(u);return{start:c,end:e?{from:e.from,to:e.to}:void 0,matched:!0}}else if(xd(u.type,n,o))l++;else if(xd(u.type,-n,o)){if(l==0){let e=Sd(u);return{start:c,end:e&&e.from<e.to?{from:e.from,to:e.to}:void 0,matched:!1}}l--}}while(n<0?u.prevSibling():u.nextSibling());return{start:c,matched:!1}}function Td(e,t,n,r,i,a,o){if(n<0?!t:t==e.doc.length)return null;let s=n<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),c=o.indexOf(s);if(c<0||c%2==0!=n>0)return null;let l={from:n<0?t-1:t,to:n>0?t+1:t},u=e.doc.iterRange(t,n>0?e.doc.length:0),d=0;for(let e=0;!u.next().done&&e<=a;){let a=u.value;n<0&&(e+=a.length);let s=t+e*n;for(let e=n>0?0:a.length-1,t=n>0?a.length:-1;e!=t;e+=n){let t=o.indexOf(a[e]);if(!(t<0||r.resolveInner(s+e,1).type!=i))if(t%2==0==n>0)d++;else if(d==1)return{start:l,end:{from:s+e,to:s+e+1},matched:t>>1==c>>1};else d--}n>0&&(e+=a.length)}return u.done?{start:l,matched:!1}:null}const Ed=Object.create(null),Dd=[W.none],Od=[],kd=Object.create(null),Ad=Object.create(null);for(let[e,t]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`]])Ad[e]=Md(Ed,t);function jd(e,t){Od.indexOf(e)>-1||(Od.push(e),console.warn(t))}function Md(e,t){let n=[];for(let r of t.split(` `)){let t=[];for(let n of r.split(`.`)){let r=e[n]||J[n];r?typeof r==`function`?t.length?t=t.map(r):jd(n,`Modifier ${n} used at start of tag`):t.length?jd(n,`Tag ${n} used as modifier`):t=Array.isArray(r)?r:[r]:jd(n,`Unknown highlighting tag ${n}`)}for(let e of t)n.push(e)}if(!n.length)return 0;let r=t.replace(/ /g,`_`),i=r+` `+n.map(e=>e.id),a=kd[i];if(a)return a.id;let o=kd[i]=W.define({id:Dd.length,name:r,props:[ou({[r]:n})]});return Dd.push(o),o.id}R.RTL,R.LTR;var Nd=class{constructor(e,t,n,r){this.state=e,this.pos=t,this.explicit=n,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=Y(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),r=t.text.slice(n-t.from,this.pos-t.from),i=r.search(Rd(e,!1));return i<0?null:{from:n+i,to:this.pos,text:r.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e==`abort`&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}};function Pd(e){let t=Object.keys(e).join(``),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,``)),`[${n?`\\w`:``}${t.replace(/[^\w\s]/g,`\\$&`)}]`}function Fd(e){let t=Object.create(null),n=Object.create(null);for(let{label:r}of e){t[r[0]]=!0;for(let e=1;e<r.length;e++)n[r[e]]=!0}let r=Pd(t)+Pd(n)+`*$`;return[RegExp(`^`+r),new RegExp(r)]}function Id(e){let t=e.map(e=>typeof e==`string`?{label:e}:e),[n,r]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:Fd(t);return e=>{let i=e.matchBefore(r);return i||e.explicit?{from:i?i.from:e.pos,options:t,validFor:n}:null}}function Ld(e,t){return n=>{for(let t=Y(n.state).resolveInner(n.pos,-1);t;t=t.parent){if(e.indexOf(t.name)>-1)return null;if(t.type.isTop)break}return t(n)}}function Rd(e,t){let{source:n}=e,r=t&&n[0]!=`^`,i=n[n.length-1]!=`$`;return!r&&!i?e:RegExp(`${r?`^`:``}(?:${n})${i?`$`:``}`,e.flags??(e.ignoreCase?`i`:``))}const zd=Vn.define();typeof navigator==`object`&&navigator.platform;const Bd=H.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:`monospace`,whiteSpace:`nowrap`,overflow:`hidden auto`,maxWidth_fallback:`700px`,maxWidth:`min(700px, 95vw)`,minWidth:`250px`,maxHeight:`10em`,height:`100%`,listStyle:`none`,margin:0,padding:0,"& > li, & > completion-section":{padding:`1px 3px`,lineHeight:1.2},"& > li":{overflowX:`hidden`,textOverflow:`ellipsis`,cursor:`pointer`},"& > completion-section":{display:`list-item`,borderBottom:`1px solid silver`,paddingLeft:`0.5em`,opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#17c`,color:`white`},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#777`},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#347`,color:`white`},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#444`},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:`"···"`,opacity:.5,display:`block`,textAlign:`center`,cursor:`pointer`},".cm-tooltip.cm-completionInfo":{position:`absolute`,padding:`3px 9px`,width:`max-content`,maxWidth:`400px`,boxSizing:`border-box`,whiteSpace:`pre-line`},".cm-completionInfo.cm-completionInfo-left":{right:`100%`},".cm-completionInfo.cm-completionInfo-right":{left:`100%`},".cm-completionInfo.cm-completionInfo-left-narrow":{right:`30px`},".cm-completionInfo.cm-completionInfo-right-narrow":{left:`30px`},"&light .cm-snippetField":{backgroundColor:`#00000022`},"&dark .cm-snippetField":{backgroundColor:`#ffffff22`},".cm-snippetFieldPosition":{verticalAlign:`text-top`,width:0,height:`1.15em`,display:`inline-block`,margin:`0 -0.7px -.7em`,borderLeft:`1.4px dotted #888`},".cm-completionMatchedText":{textDecoration:`underline`},".cm-completionDetail":{marginLeft:`0.5em`,fontStyle:`italic`},".cm-completionIcon":{fontSize:`90%`,width:`.8em`,display:`inline-block`,textAlign:`center`,paddingRight:`.6em`,opacity:`0.6`,boxSizing:`content-box`},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:`'ƒ'`}},".cm-completionIcon-class":{"&:after":{content:`'○'`}},".cm-completionIcon-interface":{"&:after":{content:`'◌'`}},".cm-completionIcon-variable":{"&:after":{content:`'𝑥'`}},".cm-completionIcon-constant":{"&:after":{content:`'𝐶'`}},".cm-completionIcon-type":{"&:after":{content:`'𝑡'`}},".cm-completionIcon-enum":{"&:after":{content:`'∪'`}},".cm-completionIcon-property":{"&:after":{content:`'□'`}},".cm-completionIcon-keyword":{"&:after":{content:`'🔑︎'`}},".cm-completionIcon-namespace":{"&:after":{content:`'▢'`}},".cm-completionIcon-text":{"&:after":{content:`'abc'`,fontSize:`50%`,verticalAlign:`middle`}}});var Vd=class{constructor(e,t,n,r){this.field=e,this.line=t,this.from=n,this.to=r}},Hd=class e{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(t){let n=t.mapPos(this.from,-1,an.TrackDel),r=t.mapPos(this.to,1,an.TrackDel);return n==null||r==null?null:new e(this.field,n,r)}},Ud=class e{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],r=[t],i=e.doc.lineAt(t),a=/^\s*/.exec(i.text)[0];for(let i of this.lines){if(n.length){let n=a,o=/^\t*/.exec(i)[0].length;for(let t=0;t<o;t++)n+=e.facet(Ku);r.push(t+n.length-o),i=n+i.slice(o)}n.push(i),t+=i.length+1}return{text:n,ranges:this.fieldPositions.map(e=>new Hd(e.field,r[e.line]+e.from,r[e.line]+e.to))}}static parse(t){let n=[],r=[],i=[],a;for(let e of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(e);){let t=a[1]?+a[1]:null,o=a[2]||a[3]||``,s=-1;t===0&&(t=1e9);let c=o.replace(/\\[{}]/g,e=>e[1]);for(let e=0;e<n.length;e++)(t==null?c&&n[e].name==c:n[e].seq==t)&&(s=e);if(s<0){let e=0;for(;e<n.length&&(t==null||n[e].seq!=null&&n[e].seq<t);)e++;n.splice(e,0,{seq:t,name:c}),s=e;for(let e of i)e.field>=s&&e.field++}for(let e of i)if(e.line==r.length&&e.from>a.index){let t=a[2]?3+(a[1]||``).length:2;e.from-=t,e.to-=t}i.push(new Vd(s,r.length,a.index,a.index+c.length)),e=e.slice(0,a.index)+o+e.slice(a.index+a[0].length)}e=e.replace(/\\([{}])/g,(e,t,n)=>{for(let e of i)e.line==r.length&&e.from>n&&(e.from--,e.to--);return t}),r.push(e)}return new e(r,i)}};let Wd=L.widget({widget:new class extends ti{toDOM(){let e=document.createElement(`span`);return e.className=`cm-snippetFieldPosition`,e}ignoreEvent(){return!1}}}),Gd=L.mark({class:`cm-snippetField`});var Kd=class e{constructor(e,t){this.ranges=e,this.active=t,this.deco=L.set(e.map(e=>(e.from==e.to?Wd:Gd).range(e.from,e.to)),!0)}map(t){let n=[];for(let e of this.ranges){let r=e.map(t);if(!r)return null;n.push(r)}return new e(n,this.active)}selectionInsideField(e){return e.ranges.every(e=>this.ranges.some(t=>t.field==this.active&&t.from<=e.from&&t.to>=e.to))}};const qd=N.define({map(e,t){return e&&e.map(t)}}),Jd=N.define(),Yd=Cn.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(qd))return n.value;if(n.is(Jd)&&e)return new Kd(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>H.decorations.from(e,e=>e?e.deco:L.none)});function Xd(e,t){return j.create(e.filter(e=>e.field==t).map(e=>j.range(e.from,e.to)))}function Zd(e){let t=Ud.parse(e);return(e,n,r,i)=>{let{text:a,ranges:o}=t.instantiate(e.state,r),{main:s}=e.state.selection,c={changes:{from:r,to:i==s.from?s.to:i,insert:k.of(a)},scrollIntoView:!0,annotations:n?[zd.of(n),Wn.userEvent.of(`input.complete`)]:void 0};if(o.length&&(c.selection=Xd(o,0)),o.some(e=>e.field>0)){let t=new Kd(o,0),n=c.effects=[qd.of(t)];e.state.field(Yd,!1)===void 0&&n.push(N.appendConfig.of([Yd,tf,rf,Bd]))}e.dispatch(e.state.update(c))}}function Qd(e){return({state:t,dispatch:n})=>{let r=t.field(Yd,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(t=>t.field==i+e);return n(t.update({selection:Xd(r.ranges,i),effects:qd.of(a?null:new Kd(r.ranges,i)),scrollIntoView:!0})),!0}}const $d=[{key:`Tab`,run:Qd(1),shift:Qd(-1)},{key:`Escape`,run:({state:e,dispatch:t})=>e.field(Yd,!1)?(t(e.update({effects:qd.of(null)})),!0):!1}],ef=M.define({combine(e){return e.length?e[0]:$d}}),tf=En.highest(Lc.compute([ef],e=>e.facet(ef)));function nf(e,t){return{...t,apply:Zd(e)}}const rf=H.domEventHandlers({mousedown(e,t){let n=t.state.field(Yd,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(e=>e.from<=r&&e.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:Xd(n.ranges,i.field),effects:qd.of(n.ranges.some(e=>e.field>i.field)?new Kd(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),af=new class extends ar{};af.startSide=1,af.endSide=-1,typeof navigator==`object`&&navigator.userAgent;var of=class e{static create(t,n,r,i,a){let o=i+(i<<8)+t+(n<<4)|0;return new e(t,n,r,o,a,[],[])}constructor(e,t,n,r,i,a,o){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=a,this.positions=o,this.hashProp=[[U.contextHash,r]]}addChild(e,t){e.prop(U.contextHash)!=this.hash&&(e=new K(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new K(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new K(W.none,e,t,n,this.hashProp)})}},X;(function(e){e[e.Document=1]=`Document`,e[e.CodeBlock=2]=`CodeBlock`,e[e.FencedCode=3]=`FencedCode`,e[e.Blockquote=4]=`Blockquote`,e[e.HorizontalRule=5]=`HorizontalRule`,e[e.BulletList=6]=`BulletList`,e[e.OrderedList=7]=`OrderedList`,e[e.ListItem=8]=`ListItem`,e[e.ATXHeading1=9]=`ATXHeading1`,e[e.ATXHeading2=10]=`ATXHeading2`,e[e.ATXHeading3=11]=`ATXHeading3`,e[e.ATXHeading4=12]=`ATXHeading4`,e[e.ATXHeading5=13]=`ATXHeading5`,e[e.ATXHeading6=14]=`ATXHeading6`,e[e.SetextHeading1=15]=`SetextHeading1`,e[e.SetextHeading2=16]=`SetextHeading2`,e[e.HTMLBlock=17]=`HTMLBlock`,e[e.LinkReference=18]=`LinkReference`,e[e.Paragraph=19]=`Paragraph`,e[e.CommentBlock=20]=`CommentBlock`,e[e.ProcessingInstructionBlock=21]=`ProcessingInstructionBlock`,e[e.Escape=22]=`Escape`,e[e.Entity=23]=`Entity`,e[e.HardBreak=24]=`HardBreak`,e[e.Emphasis=25]=`Emphasis`,e[e.StrongEmphasis=26]=`StrongEmphasis`,e[e.Link=27]=`Link`,e[e.Image=28]=`Image`,e[e.InlineCode=29]=`InlineCode`,e[e.HTMLTag=30]=`HTMLTag`,e[e.Comment=31]=`Comment`,e[e.ProcessingInstruction=32]=`ProcessingInstruction`,e[e.Autolink=33]=`Autolink`,e[e.HeaderMark=34]=`HeaderMark`,e[e.QuoteMark=35]=`QuoteMark`,e[e.ListMark=36]=`ListMark`,e[e.LinkMark=37]=`LinkMark`,e[e.EmphasisMark=38]=`EmphasisMark`,e[e.CodeMark=39]=`CodeMark`,e[e.CodeText=40]=`CodeText`,e[e.CodeInfo=41]=`CodeInfo`,e[e.LinkTitle=42]=`LinkTitle`,e[e.LinkLabel=43]=`LinkLabel`,e[e.URL=44]=`URL`})(X||={});var sf=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},cf=class{constructor(){this.text=``,this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return ff(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e=``;for(let t=0;t<this.basePos;t++)e+=` `;return e+this.text.slice(this.basePos)}};function lf(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==X.OrderedList?yf:vf)(n,t,!1);return r>0&&(e.type!=X.BulletList||gf(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}const uf={[X.Blockquote](e,t,n){return n.next==62?(n.markers.push(Z(X.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(df(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0):!1},[X.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[X.OrderedList]:lf,[X.BulletList]:lf,[X.Document](){return!0}};function df(e){return e==32||e==9||e==10||e==13}function ff(e,t=0){for(;t<e.length&&df(e.charCodeAt(t));)t++;return t}function pf(e,t,n){for(;t>n&&df(e.charCodeAt(t-1));)t--;return t}function mf(e){if(e.next!=96&&e.next!=126)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function hf(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function gf(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!df(n))return-1}return n&&e.next==45&&xf(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(Nf.SetextHeading)>-1||r<3?-1:1}function _f(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function vf(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||df(e.text.charCodeAt(e.pos+1)))&&(!n||_f(t,X.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function yf(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!df(e.text.charCodeAt(r+1))||n&&!_f(t,X.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function bf(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function xf(e){if(e.next!=45&&e.next!=61||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let n=t;for(;t<e.text.length&&df(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}const Sf=/^[ \t]*$/,Cf=/-->/,wf=/\?>/,Tf=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,Cf],[/^\s*<\?/,wf],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,Sf],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,Sf]];function Ef(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=Tf.length-+!!n;e<t;e++)if(Tf[e][0].test(r))return e;return-1}function Df(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.skipSpace(t),i=e.countIndent(r,t,n);return i>=n+5||r==e.text.length?n+1:i}function Of(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==X.CodeText?e[r].to=n:e.push(Z(X.CodeText,t,n))}const kf={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(Of(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){Of(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==X.CodeText?Of(o,e.from,e.to):o.push(e);s=[]}Of(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&Of(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=X.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(X.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=mf(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=pf(t.text,t.text.length,o),c=[Z(X.CodeMark,r,r+a)];o<s&&c.push(Z(X.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&Of(c,e.lineStart-1,e.lineStart),c.push(Z(X.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}else{o=!0,n||(Of(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(Of(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(X.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=hf(t);return n<0?!1:(e.startContext(X.Blockquote,t.pos),e.addNode(X.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(gf(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(X.HorizontalRule,n),!0},BulletList(e,t){let n=vf(t,e,!1);if(n<0)return!1;e.block.type!=X.BulletList&&e.startContext(X.BulletList,t.basePos,t.next);let r=Df(t,t.pos+1);return e.startContext(X.ListItem,t.basePos,r-t.baseIndent),e.addNode(X.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=yf(t,e,!1);if(n<0)return!1;e.block.type!=X.OrderedList&&e.startContext(X.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=Df(t,t.pos+n);return e.startContext(X.ListItem,t.basePos,r-t.baseIndent),e.addNode(X.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=bf(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=pf(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!df(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(X.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(X.HeaderMark,o-r,a-r);let c=s.finish(X.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=Ef(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=Tf[n][1],a=[],o=i!=Sf;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==Cf?X.CommentBlock:i==wf?X.ProcessingInstructionBlock:X.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0};var Af=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
740
+ `;this.styleTag.textContent=e;let n=t.head||t;this.styleTag.parentNode!=n&&n.insertBefore(this.styleTag,n.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute(`nonce`)!=e&&this.styleTag.setAttribute(`nonce`,e)}},jr={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},Mr={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},Nr=typeof navigator<`u`&&/Mac/.test(navigator.platform),Pr=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Fr=0;Fr<10;Fr++)jr[48+Fr]=jr[96+Fr]=String(Fr);for(var Fr=1;Fr<=24;Fr++)jr[Fr+111]=`F`+Fr;for(var Fr=65;Fr<=90;Fr++)jr[Fr]=String.fromCharCode(Fr+32),Mr[Fr]=String.fromCharCode(Fr);for(var Ir in jr)Mr.hasOwnProperty(Ir)||(Mr[Ir]=jr[Ir]);function Lr(e){var t=!(Nr&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||Pr&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Mr:jr)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}let Rr=typeof navigator<`u`?navigator:{userAgent:``,vendor:``,platform:``},zr=typeof document<`u`?document:{documentElement:{style:{}}};const Br=/Edge\/(\d+)/.exec(Rr.userAgent),Vr=/MSIE \d/.test(Rr.userAgent),Hr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Rr.userAgent),Ur=!!(Vr||Hr||Br),Wr=!Ur&&/gecko\/(\d+)/i.test(Rr.userAgent),Gr=!Ur&&/Chrome\/(\d+)/.exec(Rr.userAgent),Kr=`webkitFontSmoothing`in zr.documentElement.style,qr=!Ur&&/Apple Computer/.test(Rr.vendor),Jr=qr&&(/Mobile\/\w+/.test(Rr.userAgent)||Rr.maxTouchPoints>2);var I={mac:Jr||/Mac/.test(Rr.platform),windows:/Win/.test(Rr.platform),linux:/Linux|X11/.test(Rr.platform),ie:Ur,ie_version:Vr?zr.documentMode||6:Hr?+Hr[1]:Br?+Br[1]:0,gecko:Wr,gecko_version:Wr?+(/Firefox\/(\d+)/.exec(Rr.userAgent)||[0,0])[1]:0,chrome:!!Gr,chrome_version:Gr?+Gr[1]:0,ios:Jr,android:/Android\b/.test(Rr.userAgent),webkit:Kr,webkit_version:Kr?+(/\bAppleWebKit\/(\d+)/.exec(Rr.userAgent)||[0,0])[1]:0,safari:qr,safari_version:qr?+(/\bVersion\/(\d+(\.\d+)?)/.exec(Rr.userAgent)||[0,0])[1]:0,tabSize:zr.documentElement.style.tabSize==null?`-moz-tab-size`:`tab-size`};function Yr(e,t){for(let n in e)n==`class`&&t.class?t.class+=` `+e.class:n==`style`&&t.style?t.style+=`;`+e.style:t[n]=e[n];return t}const Xr=Object.create(null);function Zr(e,t,n){if(e==t)return!0;e||=Xr,t||=Xr;let r=Object.keys(e),i=Object.keys(t);if(r.length-(n&&r.indexOf(n)>-1?1:0)!=i.length-(n&&i.indexOf(n)>-1?1:0))return!1;for(let a of r)if(a!=n&&(i.indexOf(a)==-1||e[a]!==t[a]))return!1;return!0}function Qr(e,t){for(let n=e.attributes.length-1;n>=0;n--){let r=e.attributes[n].name;t[r]??e.removeAttribute(r)}for(let n in t){let r=t[n];n==`style`?e.style.cssText=r:e.getAttribute(n)!=r&&e.setAttribute(n,r)}}function $r(e,t,n){let r=!1;if(t)for(let i in t)n&&i in n||(r=!0,i==`style`?e.style.cssText=``:e.removeAttribute(i));if(n)for(let i in n)t&&t[i]==n[i]||(r=!0,i==`style`?e.style.cssText=n[i]:e.setAttribute(i,n[i]));return r}function ei(e){let t=Object.create(null);for(let n=0;n<e.attributes.length;n++){let r=e.attributes[n];t[r.name]=r.value}return t}var ti=class{eq(e){return!1}updateDOM(e,t,n){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},ni=(function(e){return e[e.Text=0]=`Text`,e[e.WidgetBefore=1]=`WidgetBefore`,e[e.WidgetAfter=2]=`WidgetAfter`,e[e.WidgetRange=3]=`WidgetRange`,e})(ni||={}),L=class extends ar{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new ri(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ai(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:i,end:a}=oi(e,t);n=(i?t?-3e8:-1:5e8)-1,r=(a?t?2e8:1:-6e8)+1}return new ai(e,n,r,t,e.widget||null,!0)}static line(e){return new ii(e)}static set(e,t=!1){return F.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};L.none=F.empty;var ri=class e extends L{constructor(e){let{start:t,end:n}=oi(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||`span`,this.attrs=e.class&&e.attributes?Yr(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Xr}eq(t){return this==t||t instanceof e&&this.tagName==t.tagName&&Zr(this.attrs,t.attrs)}range(e,t=e){if(e>=t)throw RangeError(`Mark decorations may not be empty`);return super.range(e,t)}};ri.prototype.point=!1;var ii=class e extends L{constructor(e){super(-2e8,-2e8,null,e)}eq(t){return t instanceof e&&this.spec.class==t.spec.class&&Zr(this.spec.attributes,t.spec.attributes)}range(e,t=e){if(t!=e)throw RangeError(`Line decoration ranges must be zero-length`);return super.range(e,t)}};ii.prototype.mapMode=on.TrackBefore,ii.prototype.point=!0;var ai=class e extends L{constructor(e,t,n,r,i,a){super(t,n,i,e),this.block=r,this.isReplace=a,this.mapMode=r?t<=0?on.TrackBefore:on.TrackAfter:on.TrackDel}get type(){return this.startSide==this.endSide?this.startSide<=0?ni.WidgetBefore:ni.WidgetAfter:ni.WidgetRange}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof e&&si(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw RangeError(`Invalid range for replacement decoration`);if(!this.isReplace&&t!=e)throw RangeError(`Widget decorations can only have zero-length ranges`);return super.range(e,t)}};ai.prototype.point=!0;function oi(e,t=!1){let{inclusiveStart:n,inclusiveEnd:r}=e;return n??=e.inclusive,r??=e.inclusive,{start:n??t,end:r??t}}function si(e,t){return e==t||!!(e&&t&&e.compare(t))}function ci(e,t,n,r=0){let i=n.length-1;i>=0&&n[i]+r>=e?n[i]=Math.max(n[i],t):n.push(e,t)}var li=class e extends ar{constructor(e,t,n){super(),this.tagName=e,this.attributes=t,this.rank=n}eq(t){return t==this||t instanceof e&&this.tagName==t.tagName&&Zr(this.attributes,t.attributes)}static create(t){return new e(t.tagName,t.attributes||Xr,t.rank==null?50:Math.max(0,Math.min(t.rank,100)))}static set(e,t=!1){return F.of(e,t)}};li.prototype.startSide=li.prototype.endSide=-1;function ui(e){let t;return t=e.nodeType==11?e.getSelection?e:e.ownerDocument:e,t.getSelection()}function di(e,t){return t?e==t||e.contains(t.nodeType==1?t:t.parentNode):!1}function fi(e,t){if(!t.anchorNode)return!1;try{return di(e,t.anchorNode)}catch{return!1}}function pi(e){return e.nodeType==3?Ai(e,0,e.nodeValue.length).getClientRects():e.nodeType==1?e.getClientRects():[]}function mi(e,t,n,r){return n?_i(e,t,n,r,-1)||_i(e,t,n,r,1):!1}function hi(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t}function gi(e){return e.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}function _i(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:vi(e))){if(e.nodeName==`DIV`)return!1;let n=e.parentNode;if(!n||n.nodeType!=1)return!1;t=hi(e)+(i<0?0:1),e=n}else if(e.nodeType==1){if(e=e.childNodes[t+(i<0?-1:0)],e.nodeType==1&&e.contentEditable==`false`)return!1;t=i<0?vi(e):0}else return!1}}function vi(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function yi(e,t){let{left:n,right:r}=e;if(n==r)return e;let i=t?n:r;return{left:i,right:i,top:e.top,bottom:e.bottom}}function bi(e){let t=e.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.innerWidth,top:0,bottom:e.innerHeight}}function xi(e,t){let n=t.width/e.offsetWidth,r=t.height/e.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(t.width-e.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(t.height-e.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function Si(e,t,n,r,i,a,o,s){let c=e.ownerDocument,l=c.defaultView||window;for(let u=e,d=!1;u&&!d;)if(u.nodeType==1){let e,f=u==c.body,p=1,m=1;if(f)e=bi(l);else{if(/^(fixed|sticky)$/.test(getComputedStyle(u).position)&&(d=!0),u.scrollHeight<=u.clientHeight&&u.scrollWidth<=u.clientWidth){u=u.assignedSlot||u.parentNode;continue}let t=u.getBoundingClientRect();({scaleX:p,scaleY:m}=xi(u,t)),e={left:t.left,right:t.left+u.clientWidth*p,top:t.top,bottom:t.top+u.clientHeight*m}}let h=0,g=0;if(i==`nearest`)t.top<e.top+o?(g=t.top-(e.top+o),n>0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+o)):t.bottom>e.bottom-o&&(g=t.bottom-e.bottom+o,n<0&&t.top-g<e.top&&(g=t.top-(e.top+o)));else{let r=t.bottom-t.top,a=e.bottom-e.top;g=(i==`center`&&r<=a?t.top+r/2-a/2:i==`start`||i==`center`&&n<0?t.top-o:t.bottom-a+o)-e.top}if(r==`nearest`?t.left<e.left+a?(h=t.left-(e.left+a),n>0&&t.right>e.right+h&&(h=t.right-e.right+a)):t.right>e.right-a&&(h=t.right-e.right+a,n<0&&t.left<e.left+h&&(h=t.left-(e.left+a))):h=(r==`center`?t.left+(t.right-t.left)/2-(e.right-e.left)/2:r==`start`==s?t.left-a:t.right-(e.right-e.left)+a)-e.left,h||g)if(f)l.scrollBy(h,g);else{let e=0,n=0;if(g){let e=u.scrollTop;u.scrollTop+=g/m,n=(u.scrollTop-e)*m}if(h){let t=u.scrollLeft;u.scrollLeft+=h/p,e=(u.scrollLeft-t)*p}t={left:t.left-e,top:t.top-n,right:t.right-e,bottom:t.bottom-n},e&&Math.abs(e-h)<1&&(r=`nearest`),n&&Math.abs(n-g)<1&&(i=`nearest`)}if(f)break;(t.top<e.top||t.bottom>e.bottom||t.left<e.left||t.right>e.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),u=u.assignedSlot||u.parentNode}else if(u.nodeType==11)u=u.host;else break}function Ci(e,t=!0){let n=e.ownerDocument,r=null,i=null;for(let a=e.parentNode;a&&!(a==n.body||(!t||r)&&i);)if(a.nodeType==1)!i&&a.scrollHeight>a.clientHeight&&(i=a),t&&!r&&a.scrollWidth>a.clientWidth&&(r=a),a=a.assignedSlot||a.parentNode;else if(a.nodeType==11)a=a.host;else break;return{x:r,y:i}}var wi=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?vi(t):0),n,Math.min(e.focusOffset,n?vi(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}};function Ti(e){let t=[];for(let n=e;n;n=n.nodeType==11?n.host:n.parentNode)n.nodeType==1&&t.push({node:n,left:n.scrollLeft,top:n.scrollTop});return t}function Ei(e,t=!0){for(let{node:n,left:r,top:i}of e)t&&n.scrollTop!=i&&(n.scrollTop=i),n.scrollLeft!=r&&(n.scrollLeft=r)}let Di=null;I.safari&&I.safari_version>=26&&(Di=!1);function Oi(e){if(e.setActive)return e.setActive();if(Di)return e.focus(Di);let t=Ti(e);e.focus(Di==null?{get preventScroll(){return Di={preventScroll:!0},!0}}:void 0),Di||(Di=!1,Ei(t))}let ki;function Ai(e,t,n=t){let r=ki||=document.createRange();return r.setEnd(e,n),r.setStart(e,t),r}function ji(e,t,n,r){let i={key:t,code:t,keyCode:n,which:n,cancelable:!0};r&&({altKey:i.altKey,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,metaKey:i.metaKey}=r);let a=new KeyboardEvent(`keydown`,i);a.synthetic=!0,e.dispatchEvent(a);let o=new KeyboardEvent(`keyup`,i);return o.synthetic=!0,e.dispatchEvent(o),a.defaultPrevented||o.defaultPrevented}function Mi(e){for(;e;){if(e&&(e.nodeType==9||e.nodeType==11&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}function Ni(e,t){let n=t.focusNode,r=t.focusOffset;if(!n||t.anchorNode!=n||t.anchorOffset!=r)return!1;for(r=Math.min(r,vi(n));;)if(r){if(n.nodeType!=1)return!1;let e=n.childNodes[r-1];e.contentEditable==`false`?r--:(n=e,r=vi(n))}else if(n==e)return!0;else r=hi(n),n=n.parentNode}function Pi(e){return e instanceof Window?e.pageYOffset>Math.max(0,e.document.documentElement.scrollHeight-e.innerHeight-4):e.scrollTop>Math.max(1,e.scrollHeight-e.clientHeight-4)}function Fi(e,t){for(let n=e,r=t;;)if(n.nodeType==3&&r>0)return{node:n,offset:r};else if(n.nodeType==1&&r>0){if(n.contentEditable==`false`)return null;n=n.childNodes[r-1],r=vi(n)}else if(n.parentNode&&!gi(n))r=hi(n),n=n.parentNode;else return null}function Ii(e,t){for(let n=e,r=t;;)if(n.nodeType==3&&r<n.nodeValue.length)return{node:n,offset:r};else if(n.nodeType==1&&r<n.childNodes.length){if(n.contentEditable==`false`)return null;n=n.childNodes[r],r=0}else if(n.parentNode&&!gi(n))r=hi(n)+1,n=n.parentNode;else return null}var Li=class e{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(t,n){return new e(t.parentNode,hi(t),n)}static after(t,n){return new e(t.parentNode,hi(t)+1,n)}},R=(function(e){return e[e.LTR=0]=`LTR`,e[e.RTL=1]=`RTL`,e})(R||={});const Ri=R.LTR,zi=R.RTL;function Bi(e){let t=[];for(let n=0;n<e.length;n++)t.push(1<<e[n]);return t}const Vi=Bi(`88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008`),Hi=Bi(`4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333`),Ui=Object.create(null),Wi=[];for(let e of[`()`,`[]`,`{}`]){let t=e.charCodeAt(0),n=e.charCodeAt(1);Ui[t]=n,Ui[n]=-t}function Gi(e){return e<=247?Vi[e]:1424<=e&&e<=1524?2:1536<=e&&e<=1785?Hi[e-1536]:1774<=e&&e<=2220?4:8192<=e&&e<=8204?256:64336<=e&&e<=65023?4:1}const Ki=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;var qi=class{get dir(){return this.level%2?zi:Ri}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let i=-1;for(let a=0;a<e.length;a++){let o=e[a];if(o.from<=t&&o.to>=t){if(o.level==n)return a;(i<0||(r==0?e[i].level>o.level:r<0?o.from<t:o.to>t))&&(i=a)}}if(i<0)throw RangeError(`Index out of range`);return i}};function Ji(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.from!=i.from||r.to!=i.to||r.direction!=i.direction||!Ji(r.inner,i.inner))return!1}return!0}const z=[];function Yi(e,t,n,r,i){for(let a=0;a<=r.length;a++){let o=a?r[a-1].to:t,s=a<r.length?r[a].from:n,c=a?256:i;for(let t=o,n=c,r=c;t<s;t++){let i=Gi(e.charCodeAt(t));i==512?i=n:i==8&&r==4&&(i=16),z[t]=i==4?2:i,i&7&&(r=i),n=i}for(let e=o,t=c,r=c;e<s;e++){let i=z[e];if(i==128)e<s-1&&t==z[e+1]&&t&24?i=z[e]=t:z[e]=256;else if(i==64){let i=e+1;for(;i<s&&z[i]==64;)i++;let a=e&&t==8||i<n&&z[i]==8?r==1?1:8:256;for(let t=e;t<i;t++)z[t]=a;e=i-1}else i==8&&r==1&&(z[e]=1);t=i,i&7&&(r=i)}}}function Xi(e,t,n,r,i){let a=i==1?2:1;for(let o=0,s=0,c=0;o<=r.length;o++){let l=o?r[o-1].to:t,u=o<r.length?r[o].from:n;for(let t=l,n,r,o;t<u;t++)if(r=Ui[n=e.charCodeAt(t)])if(r<0){for(let e=s-3;e>=0;e-=3)if(Wi[e+1]==-r){let n=Wi[e+2],r=n&2?i:n&4?n&1?a:i:0;r&&(z[t]=z[Wi[e]]=r),s=e;break}}else if(Wi.length==189)break;else Wi[s++]=t,Wi[s++]=n,Wi[s++]=c;else if((o=z[t])==2||o==1){let e=o==i;c=+!e;for(let t=s-3;t>=0;t-=3){let n=Wi[t+2];if(n&2)break;if(e)Wi[t+2]|=2;else{if(n&4)break;Wi[t+2]|=4}}}}}function Zi(e,t,n,r){for(let i=0,a=r;i<=n.length;i++){let o=i?n[i-1].to:e,s=i<n.length?n[i].from:t;for(let c=o;c<s;){let o=z[c];if(o==256){let o=c+1;for(;;)if(o==s){if(i==n.length)break;o=n[i++].to,s=i<n.length?n[i].from:t}else if(z[o]==256)o++;else break;let l=a==1,u=l==((o<t?z[o]:r)==1)?l?1:2:r;for(let t=o,r=i,a=r?n[r-1].to:e;t>c;)t==a&&(t=n[--r].from,a=r?n[r-1].to:e),z[--t]=u;c=o}else a=o,c++}}}function Qi(e,t,n,r,i,a,o){let s=r%2?2:1;if(r%2==i%2)for(let c=t,l=0;c<n;){let t=!0,u=!1;if(l==a.length||c<a[l].from){let e=z[c];e!=s&&(t=!1,u=e==16)}let d=!t&&s==1?[]:null,f=t?r:r+1,p=c;run:for(;;)if(l<a.length&&p==a[l].from){if(u)break run;let m=a[l];if(!t)for(let e=m.to,t=l+1;;){if(e==n)break run;if(t<a.length&&a[t].from==e)e=a[t++].to;else if(z[e]==s)break run;else break}l++,d?d.push(m):(m.from>c&&o.push(new qi(c,m.from,f)),$i(e,m.direction==Ri==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.to),p=m.to}else if(p==n||(t?z[p]!=s:z[p]==s))break;else p++;d?Qi(e,c,p,r+1,i,d,o):c<p&&o.push(new qi(c,p,f)),c=p}else for(let c=n,l=a.length;c>t;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=z[c-1];e!=s&&(n=!1,u=e==16)}let d=!n&&s==1?[]:null,f=n?r:r+1,p=c;run:for(;;)if(l&&p==a[l-1].to){if(u)break run;let m=a[--l];if(!n)for(let e=m.from,n=l;;){if(e==t)break run;if(n&&a[n-1].to==e)e=a[--n].from;else if(z[e-1]==s)break run;else break}d?d.push(m):(m.to<c&&o.push(new qi(m.to,c,f)),$i(e,m.direction==Ri==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.from),p=m.from}else if(p==t||(n?z[p-1]!=s:z[p-1]==s))break;else p--;d?Qi(e,p,c,r+1,i,d,o):p<c&&o.push(new qi(p,c,f)),c=p}}function $i(e,t,n,r,i,a,o){let s=t%2?2:1;Yi(e,i,a,r,s),Xi(e,i,a,r,s),Zi(i,a,r,s),Qi(e,i,a,t,n,r,o)}function ea(e,t,n){if(!e)return[new qi(0,0,+(t==zi))];if(t==Ri&&!n.length&&!Ki.test(e))return ta(e.length);if(n.length)for(;e.length>z.length;)z[z.length]=256;let r=[],i=t==Ri?0:1;return $i(e,i,i,n,0,e.length,r),r}function ta(e){return[new qi(0,e,0)]}let na=``;function ra(e,t,n,r,i){let a=r.head-e.from,o=qi.find(t,a,r.bidiLevel??-1,r.assoc),s=t[o],c=s.side(i,n);if(a==c){let e=o+=i?1:-1;if(e<0||e>=t.length)return null;s=t[o=e],a=s.side(!i,n),c=s.side(i,n)}let l=$t(e.text,a,s.forward(i,n));(l<s.from||l>s.to)&&(l=c),na=e.text.slice(Math.min(a,l),Math.max(a,l));let u=o==(i?t.length-1:0)?null:t[o+(i?1:-1)];return u&&l==c&&u.level+ +!i<s.level?j.cursor(u.side(!i,n)+e.from,u.forward(i,n)?1:-1,u.level):j.cursor(l+e.from,s.forward(i,n)?-1:1,s.level)}function ia(e,t,n){for(let r=t;r<n;r++){let t=Gi(e.charCodeAt(r));if(t==1)return Ri;if(t==2||t==4)return zi}return Ri}const aa=M.define(),oa=M.define(),sa=M.define(),ca=M.define(),la=M.define(),ua=M.define(),da=M.define(),fa=M.define(),pa=M.define(),ma=M.define({combine:e=>e.some(e=>e)}),ha=M.define({combine:e=>e.some(e=>e)}),ga=M.define();var _a=class e{constructor(e,t,n,r,i,a=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=i,this.isSnapshot=a}map(t){return t.empty?this:new e(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new e(j.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}};const va=N.define({map:(e,t)=>e.map(t)}),ya=N.define();function ba(e,t,n){let r=e.facet(ca);r.length?r[0](t):window.onerror&&window.onerror(String(t),n,void 0,void 0,t)||(n?console.error(n+`:`,t):console.error(t))}const xa=M.define({combine:e=>!e.length||e[0]});let Sa=0;const Ca=M.define({combine(e){return e.filter((t,n)=>{for(let r=0;r<n;r++)if(e[r].plugin==t.plugin)return!1;return!0})}});var wa=class e{constructor(e,t,n,r,i){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.baseExtensions=i(this),this.extension=this.baseExtensions.concat(Ca.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Ca.of({plugin:this,arg:e}))}static define(t,n){let{eventHandlers:r,eventObservers:i,provide:a,decorations:o}=n||{};return new e(Sa++,t,r,i,e=>{let t=[];return o&&t.push(Oa.of(t=>{let n=t.plugin(e);return n?o(n):L.none})),a&&t.push(a(e)),t})}static fromClass(t,n){return e.define((e,n)=>new t(e,n),n)}},Ta=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(!this.value){if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){ba(e.state,t,`CodeMirror plugin crashed`),this.deactivate()}}else if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(ba(e.state,t,`CodeMirror plugin crashed`),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}return this}destroy(e){if(this.value?.destroy)try{this.value.destroy()}catch(t){ba(e.state,t,`CodeMirror plugin crashed`)}}deactivate(){this.spec=this.value=null}};const Ea=M.define(),Da=M.define(),Oa=M.define(),ka=M.define(),Aa=M.define(),ja=M.define(),Ma=M.define();function Na(e,t){let n=e.state.facet(Ma);if(!n.length)return n;let r=n.map(t=>t instanceof Function?t(e):t),i=[];return F.spans(r,t.from,t.to,{point(){},span(e,n,r,a){let o=e-t.from,s=n-t.from,c=i;for(let e=r.length-1;e>=0;e--,a--){let n=r[e].spec.bidiIsolate,i;if(n??=ia(t.text,o,s),a>0&&c.length&&(i=c[c.length-1]).to==o&&i.direction==n)i.to=s,c=i.inner;else{let e={from:o,to:s,direction:n,inner:[]};c.push(e),c=e.inner}}}}),i}const Pa=M.define();function Fa(e){let t=0,n=0,r=0,i=0;for(let a of e.state.facet(Pa)){let o=a(e);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(n=Math.max(n,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(i=Math.max(i,o.bottom)))}return{left:t,right:n,top:r,bottom:i}}const Ia=M.define();var La=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(t){return new e(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toA<n.fromA)break;n=n.join(r),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(t,n){if(n.length==0)return t;let r=[];for(let i=0,a=0,o=0;;){let s=i<t.length?t[i].fromB:1e9,c=a<n.length?n[a]:1e9,l=Math.min(s,c);if(l==1e9)break;let u=l+o,d=l,f=u;for(;;)if(a<n.length&&n[a]<=d){let e=n[a+1];a+=2,d=Math.max(d,e);for(let e=i;e<t.length&&t[e].fromB<=d;e++)o=t[e].toA-t[e].toB;f=Math.max(f,e+o)}else if(i<t.length&&t[i].fromB<=d){let e=t[i++];d=Math.max(d,e.toB),f=Math.max(f,e.toA),o=e.toA-e.toB}else break;r.push(new e(u,f,l,d))}return r}},Ra=class e{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=cn.empty(this.startState.doc.length);for(let e of n)this.changes=this.changes.compose(e.changes);let r=[];this.changes.iterChangedRanges((e,t,n,i)=>r.push(new La(e,t,n,i))),this.changedRanges=r}static create(t,n,r){return new e(t,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}};const za=[];var B=class{constructor(e,t,n=0){this.dom=e,this.length=t,this.flags=n,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return za}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&Qr(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:``)+(this.breakAfter?`#`:``)}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let n=t;for(let t of this.children){if(t==e)return n;n+=t.length+t.breakAfter}throw RangeError(`Invalid child in posBefore`)}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,n){return null}domPosFor(e,t){let n=hi(this.dom),r=this.length?e>0:t>0;return new Li(this.parent.dom,n+ +!!r,e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Ha)return e;return null}static get(e){return e.cmTile}},Ba=class extends B{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,n=null,r,i=e?.node==t?e:null,a=0;for(let o of this.children){if(o.sync(e),a+=o.length+o.breakAfter,r=n?n.nextSibling:t.firstChild,i&&r!=o.dom&&(i.written=!0),o.dom.parentNode==t)for(;r&&r!=o.dom;)r=Va(r);else t.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:t.firstChild,i&&r&&(i.written=!0);r;)r=Va(r);this.length=a}};function Va(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var Ha=class extends Ba{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=B.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],n=this,r=0,i=0;;)if(r==n.children.length){if(!t.length)return;n=n.parent,n.breakAfter&&i++,r=t.pop()}else{let a=n.children[r++];if(a instanceof Ua)t.push(r),n=a,r=0;else{let t=i+a.length,n=e(a,i);if(n!==void 0)return n;i=t+a.breakAfter}}}resolveBlock(e,t){let n,r=-1,i,a=-1;if(this.blockTiles((o,s)=>{let c=s+o.length;if(e>=s&&e<=c){if(o.isWidget()&&t>=-1&&t<=1){if(o.flags&32)return!0;o.flags&16&&(n=void 0)}(s<e||e==c&&(t<-1?o.length:o.covers(1)))&&(!n||!o.isWidget()&&n.isWidget())&&(n=o,r=e-s),(c>e||e==s&&(t>1?o.length:o.covers(-1)))&&(!i||!o.isWidget()&&i.isWidget())&&(i=o,a=e-s)}}),!n&&!i)throw Error(`No tile at position `+e);return n&&t<0||!i?{tile:n,offset:r}:{tile:i,offset:a}}},Ua=class e extends Ba{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,n){let r=new e(n||document.createElement(t.tagName),t);return n||(r.flags|=4),r}},Wa=class e extends Ba{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(t,n,r){let i=new e(n||document.createElement(`div`),t);return(!n||!r)&&(i.flags|=4),i}get domAttrs(){return this.attrs}resolveInline(e,t,n){let r=null,i=-1,a=null,o=-1;function s(e,c){for(let l=0,u=0;l<e.children.length&&u<=c;l++){let d=e.children[l],f=u+d.length;f>=c&&(d.isComposite()?s(d,c-u):(!a||a.isHidden&&(t>0&&!(a.flags&32)||n&&Ka(a,d)))&&(f>c||d.flags&32&&t<=1)?(a=d,o=c-u):(u<c||d.flags&16&&!d.isHidden&&t>=-1)&&(r=d,i=c-u)),u=f}}s(this,e);let c=(t<0?r:a)||r||a;return c?{tile:c,offset:c==r?i:o}:null}coordsIn(e,t,n){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t,n):Ga(this)}domIn(e,t){let n=this.resolveInline(e,t);if(n){let{tile:e,offset:r}=n;if(this.dom.contains(e.dom))return e.isText()?new Li(e.dom,Math.min(e.dom.nodeValue.length,r)):e.domPosFor(r,e.flags&16?1:e.flags&32?-1:t);let i=n.tile.parent,a=!1;for(let e of i.children){if(a)return new Li(e.dom,0);e==n.tile&&(a=!0)}}return new Li(this.dom,0)}};function Ga(e){let t=e.dom.lastChild;if(!t)return e.dom.getBoundingClientRect();let n=pi(t);return n[n.length-1]||null}function Ka(e,t){let n=e.coordsIn(0,1),r=t.coordsIn(0,1);return n&&r&&r.top<n.bottom}var qa=class e extends Ba{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(t,n){let r=new e(n||document.createElement(t.tagName),t);return n||(r.flags|=4),r}},Ja=class e extends B{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,n){let r=this.dom.nodeValue.length;e>r&&(e=r);let i=e,a=e,o=0;e==0&&t<0||e==r&&t>=0?I.chrome||I.gecko||(e?(i--,o=1):a<r&&(a++,o=-1)):t<0?i--:a<r&&a++;let s=Ai(this.dom,i,a).getClientRects();if(!s.length)return null;let c=s[(o?o<0:t>=0)?0:s.length-1];return I.safari&&!o&&c.width==0&&(c=Array.prototype.find.call(s,e=>e.width)||c),n==null?c:yi(c,(o?o>0:t<0)==n)}static of(t,n){let r=new e(n||document.createTextNode(t),t);return n||(r.flags|=2),r}},Ya=class e extends B{constructor(e,t,n,r){super(e,t,r),this.widget=n}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,n){let r=this.widget.coordsAt(this.dom,e,t);if(r)return r;if(n)return yi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let t=this.dom.getClientRects(),n=null;if(!t.length)return null;let r=this.flags&16?!0:this.flags&32?!1:e>0;for(let i=r?t.length-1:0;n=t[i],!(e>0?i==0:i==t.length-1||n.top<n.bottom);i+=r?-1:1);return yi(n,!r)}}get overrideDOMText(){if(!this.length)return k.empty;let{root:e}=this;if(!e)return k.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,n,r,i,a){return a||(a=t.toDOM(n),t.editable||(a.contentEditable=`false`)),new e(a,r,t,i)}},Xa=class extends B{constructor(e){let t=document.createElement(`img`);t.className=`cm-widgetBuffer`,t.setAttribute(`aria-hidden`,`true`),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return k.empty}coordsIn(e,t,n){let r=this.dom.getBoundingClientRect();return n==null?r:yi(r,t>0==n)}},Za=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,n){let{tile:r,index:i,beforeBreak:a,parents:o}=this;for(;e||t>0;)if(!r.isComposite()){let t=r.length;if(i<t&&e){let a=Math.min(e,t-i);n&&n.skip(r,i,i+a),e-=a,i+=a}if(i==t)a=!!r.breakAfter,{tile:r,index:i}=o.pop(),i++;else if(!e)break}else if(a){if(!e)break;n&&n.break(),e--,a=!1}else if(i==r.children.length){if(!e&&!o.length)break;n&&n.leave(r),a=!!r.breakAfter,{tile:r,index:i}=o.pop(),i++}else{let s=r.children[i],c=s.breakAfter;(t>0?s.length<=e:s.length<e)&&(!n||n.skip(s,0,s.length)!==!1||!s.isComposite)?(a=!!c,i++,e-=s.length):(o.push({tile:r,index:i}),r=s,i=0,n&&s.isComposite()&&n.enter(s))}return this.tile=r,this.index=i,this.beforeBreak=a,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},Qa=class{constructor(e,t,n,r){this.from=e,this.to=t,this.wrapper=n,this.rank=r}},$a=class{constructor(e,t,n){this.cache=e,this.root=t,this.blockWrappers=n,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,n,r){this.flushBuffer();let i=this.ensureMarks(t,n),a=i.lastChild;if(a&&a.isText()&&!(a.flags&8)&&a.length+e.length<512){this.cache.reused.set(a,2);let t=i.children[i.children.length-1]=new Ja(a.dom,a.text+e);t.parent=i}else i.append(r||Ja.of(e,this.cache.find(Ja)?.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let n=this.curLine;n.dom!=t.line.dom&&(n.setDOM(this.cache.reused.has(t.line)?lo(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let r=n;for(let e=t.marks.length-1;e>=0;e--){let n=t.marks[e],i=r.lastChild;if(i instanceof qa&&i.mark.eq(n.mark))i.dom!=n.dom&&i.setDOM(lo(n.dom)),r=i;else{if(this.cache.reused.get(n)){let e=B.get(n.dom);e&&e.setDOM(lo(n.dom))}let e=qa.of(n.mark,n.dom);r.append(e),r=e}this.cache.reused.set(n,2)}let i=B.get(e.text);i&&this.cache.reused.set(i,2);let a=new Ja(e.text,e.text.nodeValue);a.flags|=8,this.pos=e.range.toB,r.append(a)}addInlineWidget(e,t,n){let r=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);r||this.flushBuffer();let i=this.ensureMarks(t,n);!r&&!(e.flags&16)&&i.append(this.getBuffer(1)),i.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,n){this.flushBuffer(),this.ensureMarks(t,n).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){e||=oo;let n=Wa.start(e,t||this.cache.find(Wa)?.dom,!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){let n=this.curLine;for(let r=e.length-1;r>=0;r--){let i=e[r],a;if(t>0&&(a=n.lastChild)&&a instanceof qa&&a.mark.eq(i))n=a,t--;else{let e=qa.of(i,this.cache.find(qa,e=>e.mark.eq(i))?.dom);n.append(e),n=e,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!io(this.curLine,!1)||e.dom.nodeName!=`BR`&&e.isWidget()&&!(I.ios&&io(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(fo,0,32)||new Ya(fo.toDOM(),0,fo,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,n=new Qa(e.from,e.to,e.value,t),r=this.wrappers.length;for(;r>0&&(this.wrappers[r-1].rank-n.rank||this.wrappers[r-1].to-n.to)<0;)r--;this.wrappers.splice(r,0,n)}this.wrapperPos=this.pos}getBlockPos(){this.updateBlockWrappers();let e=this.root;for(let t of this.wrappers){let n=e.lastChild;if(t.from<this.pos&&n instanceof Ua&&n.wrapper.eq(t.wrapper))e=n;else{let n=Ua.of(t.wrapper,this.cache.find(Ua,e=>e.wrapper.eq(t.wrapper))?.dom);e.append(n),e=n}}return e}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),n=this.cache.find(Xa,void 0,1);return n&&(n.flags=t),n||new Xa(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},eo=class{constructor(e){this.skipCount=0,this.text=``,this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text=``,this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:t,lineBreak:n,done:r}=this.cursor.next(this.skipCount);if(this.skipCount=0,r)throw Error(`Ran out of text content when drawing inline views`);this.text=t;let i=this.textOff=Math.min(e,t.length);return n?null:t.slice(0,i)}let t=Math.min(this.text.length,this.textOff+e),n=this.text.slice(this.textOff,t);return this.textOff=t,n}};const to=[Ya,Wa,Ja,qa,Xa,Ua,Ha];for(let e=0;e<to.length;e++)to[e].bucket=e;var no=class{constructor(e){this.view=e,this.buckets=to.map(()=>[]),this.index=to.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,n=this.buckets[t];n.length<6?n.push(e):n[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,n=2){let r=e.bucket,i=this.buckets[r],a=this.index[r];for(let e=0;e<i.length;e++){let o=(e+a)%i.length,s=i[o];if((!t||t(s))&&!this.reused.has(s))return i.splice(o,1),o<a&&this.index[r]--,this.reused.set(s,n),s}return null}findWidget(e,t,n){let r=this.buckets[0];if(r.length)for(let i=0,a=0;;i++){if(i==r.length){if(a)return null;a=1,i=0}let o=r[i];if(!this.reused.has(o)&&(a==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return r.splice(i,1),i<this.index[0]&&this.index[0]--,o.widget==e&&o.length==t&&(o.flags&497)==n?(this.reused.set(o,1),o):(this.reused.set(o,2),new Ya(o.dom,t,e,o.flags&-498|n))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},ro=class{constructor(e,t,n,r,i){this.view=e,this.decorations=r,this.disallowBlockEffectsFor=i,this.openWidget=!1,this.openMarks=0,this.cache=new no(e),this.text=new eo(e.state.doc),this.builder=new $a(this.cache,new Ha(e,e.contentDOM),F.iter(n)),this.cache.reused.set(t,2),this.old=new Za(t),this.reuseWalker={skip:(e,t,n)=>{if(this.cache.add(e),e.isComposite())return!1},enter:e=>this.cache.add(e),leave:()=>{},break:()=>{}}}run(e,t){let n=t&&this.getCompositionContext(t.text);for(let r=0,i=0,a=0;;){let o=a<e.length?e[a++]:null,s=o?o.fromA:this.old.root.length;if(s>r){let e=s-r;this.preserve(e,!a,!o),r=s,i+=e}if(!o)break;t&&o.fromA<=t.range.fromA&&o.toA>=t.range.toA?(this.forward(o.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(i,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,n),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,o.toA),this.emit(t.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(i,o.toB)),i=o.toB,r=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,n){let r=co(this.old),i=this.openMarks;this.old.advance(e,n?1:-1,{skip:(e,t,n)=>{if(e.isWidget())if(this.openWidget)this.builder.continueWidget(n-t);else{let a=n>0||t<e.length?Ya.of(e.widget,this.view,n-t,e.flags&496,this.cache.maybeReuse(e)):this.cache.reuse(e);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,r,i),i=r.length)}else if(e.isText())this.builder.ensureLine(null),!t&&n==e.length&&!this.cache.reused.has(e)?this.builder.addText(e.text,r,i,this.cache.reuse(e)):(this.cache.add(e),this.builder.addText(e.text.slice(t,n),r,i)),i=r.length;else if(e.isLine())e.flags&=-2,this.cache.reused.set(e,1),this.builder.addLine(e);else if(e instanceof Xa)this.cache.add(e);else if(e instanceof qa)this.builder.ensureLine(null),this.builder.addMark(e,r,i),this.cache.reused.set(e,1),i=r.length;else return!1;this.openWidget=!1},enter:e=>{e.isLine()?this.builder.addLineStart(e.attrs,this.cache.maybeReuse(e)):(this.cache.add(e),e instanceof qa&&r.unshift(e.mark)),this.openWidget=!1},leave:e=>{e.isLine()?r.length&&=i=0:e instanceof qa&&(r.shift(),i=Math.min(i,r.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let n=null,r=this.builder,i=-1,a=F.spans(this.decorations,e,t,{point:(e,t,a,o,s,c)=>{if(a instanceof ai){if(this.disallowBlockEffectsFor[c]){if(a.block)throw RangeError(`Block decorations may not be specified via plugins`);if(t>this.view.state.doc.lineAt(e).to)throw RangeError(`Decorations that replace line breaks may not be specified via plugins`)}if(i=o.length,s>o.length)r.continueWidget(t-e);else{let i=a.widget||(a.block?uo.block:uo.inline),c=ao(a),l=this.cache.findWidget(i,t-e,c)||Ya.of(i,this.view,t-e,c);a.block?(a.startSide>0&&r.addLineStartIfNotCovered(n),r.addBlockWidget(l)):(r.ensureLine(n),r.addInlineWidget(l,o,s))}n=null}else n=so(n,a);t>e&&this.text.skip(t-e)},span:(e,t,a,o)=>{for(let i=e;i<t;){let s=this.text.next(Math.min(512,t-i));s==null?(r.addLineStartIfNotCovered(n),r.addBreak(),i++):(r.ensureLine(n),r.addText(s,a,i==e?o:a.length),i+=s.length),n=null}i=a.length}});i>-1&&(this.openWidget=a>i),this.openWidget||r.addLineStartIfNotCovered(n),this.openMarks=a}forward(e,t,n=1){t-e<=10?this.old.advance(t-e,n,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,n,this.reuseWalker))}getCompositionContext(e){let t=[],n=null;for(let r=e.parentNode;;r=r.parentNode){let e=B.get(r);if(r==this.view.contentDOM)break;e instanceof qa?t.push(e):e?.isLine()?n=e:e instanceof Ua||(r.nodeName==`DIV`&&!n&&r!=this.view.contentDOM?n=new Wa(r,oo):n||t.push(qa.of(new ri({tagName:r.nodeName.toLowerCase(),attributes:ei(r)}),r)))}return{line:n,marks:t}}};function io(e,t){let n=e=>{for(let r of e.children)if((t?r.isText():r.length)||n(r))return!0;return!1};return n(e)}function ao(e){let t=e.isReplace?(e.startSide<0?64:0)|(e.endSide>0?128:0):e.startSide>0?32:16;return e.block&&(t|=256),t}const oo={class:`cm-line`};function so(e,t){let n=t.spec.attributes,r=t.spec.class;return!n&&!r?e:(e||={class:`cm-line`},n&&Yr(n,e),r&&(e.class+=` `+r),e)}function co(e){let t=[];for(let n=e.parents.length;n>1;n--){let r=n==e.parents.length?e.tile:e.parents[n].tile;r instanceof qa&&t.push(r.mark)}return t}function lo(e){let t=B.get(e);return t&&t.setDOM(e.cloneNode()),e}var uo=class extends ti{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};uo.inline=new uo(`span`),uo.block=new uo(`div`);const fo=new class extends ti{toDOM(){return document.createElement(`br`)}get isHidden(){return!0}get editable(){return!0}};var po=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=L.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Ha(e,e.contentDOM),this.updateInner([new La(0,0,0,e.state.doc.length)],null)}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:e,toA:t})=>t<this.minWidthFrom||e>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(this.domChanged?.newSel?n=this.domChanged.newSel.head:!wo(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?_o(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:n,to:r}=this.hasComposition;t=new La(n,r,e.changes.mapPos(n,-1),e.changes.mapPos(r,1)).addToSet(t.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(I.ie||I.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,a=this.blockWrappers;this.updateDeco();let o=bo(i,this.decorations,e.changes);o.length&&(t=La.extendWithRanges(t,o));let s=So(a,this.blockWrappers,e.changes);return s.length&&(t=La.extendWithRanges(t,s)),r&&!t.some(e=>e.fromA<=r.range.fromA&&e.toA>=r.range.toA)&&(t=r.range.addToSet(t.slice())),this.tile.flags&2&&t.length==0?!1:(this.updateInner(t,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:n}=this.view;n.ignore(()=>{if(t||e.length){let n=this.tile,r=new ro(this.view,n,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&B.get(t.text)&&r.cache.reused.set(B.get(t.text),2),this.tile=r.run(e,t),mo(n,r.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+`px`,this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+`px`:``;let r=I.chrome||I.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||n.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=``});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let e of this.tile.children)e.isWidget()&&e.widget instanceof To&&r.push(e.dom);n.updateGaps(r)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(ya)&&(this.editContextFormatting=e.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:n}=this.tile,r=this.view.root.activeElement,i=r==n,a=!i&&!(this.view.state.facet(xa)||n.tabIndex>-1)&&fi(n,this.view.observer.selectionRange)&&!(r&&n.contains(r));if(!(i||t||a))return;let o=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,c,l;if(s.empty?l=c=this.inlineDOMNearPos(s.anchor,s.assoc||1):(l=this.inlineDOMNearPos(s.head,s.head==s.from?1:-1),c=this.inlineDOMNearPos(s.anchor,s.anchor==s.from?1:-1)),I.gecko&&s.empty&&!this.hasComposition&&ho(c)){let e=document.createTextNode(``);this.view.observer.ignore(()=>c.node.insertBefore(e,c.node.childNodes[c.offset]||null)),c=l=new Li(e,0),o=!0}let u=this.view.observer.selectionRange;(o||!u.focusNode||(!mi(c.node,c.offset,u.anchorNode,u.anchorOffset)||!mi(l.node,l.offset,u.focusNode,u.focusOffset))&&!this.suppressWidgetCursorChange(u,s))&&(this.view.observer.ignore(()=>{I.android&&I.chrome&&n.contains(u.focusNode)&&Co(u.focusNode,n)&&(n.blur(),n.focus({preventScroll:!0}));let e=ui(this.view.root);if(e)if(s.empty){if(I.gecko){let e=vo(c.node,c.offset);if(e&&e!=3){let t=(e==1?Fi:Ii)(c.node,c.offset);t&&(c=new Li(t.node,t.offset))}}e.collapse(c.node,c.offset),s.bidiLevel!=null&&e.caretBidiLevel!==void 0&&(e.caretBidiLevel=s.bidiLevel)}else if(e.extend){e.collapse(c.node,c.offset);try{e.extend(l.node,l.offset)}catch{}}else{let t=document.createRange();s.anchor>s.head&&([c,l]=[l,c]),t.setEnd(l.node,l.offset),t.setStart(c.node,c.offset),e.removeAllRanges(),e.addRange(t)}a&&this.view.root.activeElement==n&&(n.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(c,l)),this.impreciseAnchor=c.precise?null:new Li(u.anchorNode,u.anchorOffset),this.impreciseHead=l.precise?null:new Li(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&mi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=ui(e.root),{anchorNode:r,anchorOffset:i}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let a=this.lineAt(t.head,t.assoc);if(!a)return;let o=a.posAtStart;if(t.head==o||t.head==o+a.length)return;let s=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!s||!c||s.bottom>c.top)return;let l=this.domAtPos(t.head+t.assoc,t.assoc);n.collapse(l.node,l.offset),n.modify(`move`,t.assoc<0?`forward`:`backward`,`lineboundary`),e.observer.readSelectionRange();let u=e.observer.selectionRange;e.docView.posFromDOM(u.anchorNode,u.anchorOffset)!=t.from&&n.collapse(r,i)}posFromDOM(e,t){let n=this.tile.nearest(e);if(!n)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let r=n.posAtStart;if(n.isComposite()){let i;if(e==n.dom)i=n.dom.childNodes[t];else{let r=vi(e)==0?0:t==0?-1:1;for(;;){let t=e.parentNode;if(t==n.dom)break;r==0&&t.firstChild!=t.lastChild&&(r=e==t.firstChild?-1:1),e=t}i=r<0?e:e.nextSibling}if(i==n.dom.firstChild)return r;for(;i&&!B.get(i);)i=i.nextSibling;if(!i)return r+n.length;for(let e=0,t=r;;e++){let r=n.children[e];if(r.dom==i)return t;t+=r.length+r.breakAfter}}else if(n.isText())return e==n.dom?r+t:r+(t?n.length:0);else return r}domAtPos(e,t){let{tile:n,offset:r}=this.tile.resolveBlock(e,t);return n.isWidget()?n.domPosFor(r,t):n.domIn(r,t)}inlineDOMNearPos(e,t){let n,r=-1,i=!1,a,o=-1,s=!1;return this.tile.blockTiles((t,c)=>{if(t.isWidget()){if(t.flags&32&&c>=e)return!0;t.flags&16&&(i=!0)}else{let l=c+t.length;if(c<=e&&(n=t,r=e-c,i=l<e),l>=e&&!a&&(a=t,o=e-c,s=c>e),c>e&&a)return!0}}),!n&&!a?this.domAtPos(e,t):(i&&a?n=null:s&&n&&(a=null),n&&t<0||!a?n.domIn(r,t):a.domIn(o,t))}coordsAt(e,t,n){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof To?null:r.coordsInWidget(i,t,!0):r.coordsIn(i,t,n)}lineAt(e,t){let{tile:n}=this.tile.resolveBlock(e,t);return n.isLine()?n:null}coordsForChar(e){let{tile:t,offset:n}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function r(e,t){if(e.isComposite())for(let n of e.children){if(n.length>=t){let e=r(n,t);if(e)return e}if(t-=n.length,t<0)break}else if(e.isText()&&t<e.length){let n=$t(e.text,t);if(n==t)return null;let r=Ai(e.dom,t,n).getClientRects();for(let e=0;e<r.length;e++){let t=r[e];if(e==r.length-1||t.top<t.bottom&&t.left<t.right)return t}}return null}return r(t,n)}measureVisibleLineHeights(e){let t=[],{from:n,to:r}=e,i=this.view.contentDOM.clientWidth,a=i>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,s=this.view.textDirection==R.LTR,c=0,l=(e,u,d)=>{for(let f=0;f<e.children.length&&!(u>r);f++){let r=e.children[f],p=u+r.length,m=r.dom.getBoundingClientRect(),{height:h}=m;if(d&&!f&&(c+=m.top-d.top),r instanceof Ua)p>n&&l(r,u,m);else if(u>=n&&(c>0&&t.push(-c),t.push(h+c),c=0,a)){let e=r.dom.lastChild,t=e?pi(e):[];if(t.length){let e=t[t.length-1],n=s?e.right-m.left:m.right-e.left;n>o&&(o=n,this.minWidth=i,this.minWidthFrom=u,this.minWidthTo=p)}}d&&f==e.children.length-1&&(c+=d.bottom-m.bottom),u=p+r.breakAfter}};return l(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction==`rtl`?R.RTL:R.LTR}measureTextSize(){let e=this.tile.blockTiles(e=>{if(e.isLine()&&e.children.length&&e.length<=20){let t=0,n;for(let r of e.children){if(!r.isText()||/[^ -~]/.test(r.text))return;let e=pi(r.dom);if(e.length!=1)return;t+=e[0].width,n=e[0].height}if(t)return{lineHeight:e.dom.getBoundingClientRect().height,charWidth:t/e.length,textHeight:n}}});if(e)return e;let t=document.createElement(`div`),n,r,i;return t.className=`cm-line`,t.style.width=`99999px`,t.style.position=`absolute`,t.textContent=`abc def ghi jkl mno pqr stu`,this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let e=pi(t.firstChild)[0];n=t.getBoundingClientRect().height,r=e&&e.width?e.width/27:7,i=e&&e.height?e.height:n,t.remove()}),{lineHeight:n,charWidth:r,textHeight:i}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let i=r==t.viewports.length?null:t.viewports[r],a=i?i.from-1:this.view.state.doc.length;if(a>n){let r=(t.lineBlockAt(a).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(L.replace({widget:new To(r),block:!0,inclusive:!0,isBlockGap:!0}).range(n,a))}if(!i)break;n=i.to+1}return L.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Oa).map(t=>(this.dynamicDecorationMap[e++]=typeof t==`function`)?t(this.view):t),n=!1,r=this.view.state.facet(Aa).map((e,t)=>{let r=typeof e==`function`;return r&&(n=!0),r?e(this.view):e});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push(F.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(ka).map(e=>typeof e==`function`?e(this.view):e)}scrollIntoView(e){if(e.isSnapshot){let t=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=t.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let t of this.view.state.facet(ga))try{if(t(this.view,e.range,e))return!0}catch(e){ba(this.view.state,e,`scroll handler`)}let{range:t}=e,n=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let i=Fa(this.view),a={left:n.left-i.left,top:n.top-i.top,right:n.right+i.right,bottom:n.bottom+i.bottom},{offsetWidth:o,offsetHeight:s}=this.view.scrollDOM;if(Si(this.view.scrollDOM,a,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,s),-s),this.view.textDirection==R.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.visualViewport.offsetTop)){let e=this.view.docView.lineAt(t.head,1);if(e){let t=Ti(e.dom);e.dom.scrollIntoView({block:`nearest`}),Ei(t,!1)}}}lineHasWidget(e){let t=e=>e.isWidget()||e.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){mo(this.tile)}};function mo(e,t){let n=t?.get(e);if(n!=1){n??e.destroy();for(let n of e.children)mo(n,t)}}function ho(e){return e.node.nodeType==1&&e.node.firstChild&&(e.offset==0||e.node.childNodes[e.offset-1].contentEditable==`false`)&&(e.offset==e.node.childNodes.length||e.node.childNodes[e.offset].contentEditable==`false`)}function go(e,t){let n=e.observer.selectionRange;if(!n.focusNode)return null;let r=Fi(n.focusNode,n.focusOffset),i=Ii(n.focusNode,n.focusOffset),a=r||i;if(i&&r&&i.node!=r.node){let t=B.get(i.node);if(!t||t.isText()&&t.text!=i.node.nodeValue)a=i;else if(e.docView.lastCompositionAfterCursor){let e=B.get(r.node);!e||e.isText()&&e.text!=r.node.nodeValue||(a=i)}}if(e.docView.lastCompositionAfterCursor=a!=r,!a)return null;let o=t-a.offset;return{from:o,to:o+a.node.nodeValue.length,node:a.node}}function _o(e,t,n){let r=go(e,n);if(!r)return null;let{node:i,from:a,to:o}=r,s=i.nodeValue;if(/[\n\r]/.test(s)||e.state.doc.sliceString(r.from,r.to)!=s)return null;let c=t.invertedDesc;return{range:new La(c.mapPos(a),c.mapPos(o),a,o),text:i}}function vo(e,t){return e.nodeType==1?(t&&e.childNodes[t-1].contentEditable==`false`?1:0)|(t<e.childNodes.length&&e.childNodes[t].contentEditable==`false`?2:0):0}let yo=class{constructor(){this.changes=[]}compareRange(e,t){ci(e,t,this.changes)}comparePoint(e,t){ci(e,t,this.changes)}boundChange(e){ci(e,e,this.changes)}};function bo(e,t,n){let r=new yo;return F.compare(e,t,n,r),r.changes}var xo=class{constructor(){this.changes=[]}compareRange(e,t){ci(e,t,this.changes)}comparePoint(){}boundChange(e){ci(e,e,this.changes)}};function So(e,t,n){let r=new xo;return F.compare(e,t,n,r),r.changes}function Co(e,t){for(let n=e;n&&n!=t;n=n.assignedSlot||n.parentNode)if(n.nodeType==1&&n.contentEditable==`false`)return!0;return!1}function wo(e,t){let n=!1;return t&&e.iterChangedRanges((e,r)=>{e<t.to&&r>t.from&&(n=!0)}),n}var To=class extends ti{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement(`div`);return e.className=`cm-gap`,this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+`px`,!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function Eo(e,t,n=1){let r=e.charCategorizer(t),i=e.doc.lineAt(t),a=t-i.from;if(i.length==0)return j.cursor(t);a==0?n=1:a==i.length&&(n=-1);let o=a,s=a;n<0?o=$t(i.text,a,!1):s=$t(i.text,a);let c=r(i.text.slice(o,s));for(;o>0;){let e=$t(i.text,o,!1);if(r(i.text.slice(e,o))!=c)break;o=e}for(;s<i.length;){let e=$t(i.text,s);if(r(i.text.slice(s,e))!=c)break;s=e}return j.undirectionalRange(o+i.from,s+i.from)}function Do(e,t,n,r,i){let a=Math.round((r-t.left)*e.defaultCharacterWidth);if(e.lineWrapping&&n.height>e.defaultLineHeight*1.5){let t=e.viewState.heightOracle.textHeight,r=Math.floor((i-n.top-(e.defaultLineHeight-t)*.5)/t);a+=r*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(n.from,n.to);return n.from+wr(o,a,e.state.tabSize)}function Oo(e,t,n){let r=e.lineBlockAt(t);if(Array.isArray(r.type)){let e;for(let i of r.type){if(i.from>t)break;if(!(i.to<t)){if(i.from<t&&i.to>t)return i;(!e||i.type==ni.Text&&(e.type!=i.type||(n<0?i.from<t:i.to>t)))&&(e=i)}}return e||r}return r}function ko(e,t,n,r){let i=Oo(e,t.head,t.assoc||-1),a=!r||i.type!=ni.Text||!(e.lineWrapping||i.widgetLineBreaks)?null:e.coordsAtPos(t.assoc<0&&t.head>i.from?t.head-1:t.head);if(a){let t=e.dom.getBoundingClientRect(),r=e.textDirectionAt(i.from),o=e.posAtCoords({x:n==(r==R.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(o!=null)return j.cursor(o,n?-1:1)}return j.cursor(n?i.to:i.from,n?-1:1)}function Ao(e,t,n,r){let i=e.state.doc.lineAt(t.head),a=e.bidiSpans(i),o=e.textDirectionAt(i.from);for(let s=t,c=null;;){let t=ra(i,a,o,s,n),l=na;if(!t){if(i.number==(n?e.state.doc.lines:1))return s;l=`
741
+ `,i=e.state.doc.line(i.number+(n?1:-1)),a=e.bidiSpans(i),t=e.visualLineSide(i,!n)}if(!c){if(!r)return t;c=r(l)}else if(!c(l))return s;s=t}}function jo(e,t,n){let r=e.state.charCategorizer(t),i=r(n);return e=>{let t=r(e);return i==$n.Space&&(i=t),i==t}}function Mo(e,t,n,r){let i=t.head,a=n?1:-1;if(i==(n?e.state.doc.length:0))return j.cursor(i,t.assoc);let o=t.goalColumn,s,c=e.contentDOM.getBoundingClientRect(),l=e.coordsAtPos(i,t.assoc||((t.empty?n:t.head==t.from)?1:-1)),u=e.documentTop;if(l)o??=l.left-c.left,s=a<0?l.top:l.bottom;else{let t=e.viewState.lineBlockAt(i);o??=Math.min(c.right-c.left,e.defaultCharacterWidth*(i-t.from)),s=(a<0?t.top:t.bottom)+u}let d=c.left+o,f=e.viewState.heightOracle.textHeight>>1,p=r??f;for(let t=0;;t+=f){let r=s+(p+t)*a,i=Lo(e,{x:d,y:r},!1,a);if(n?r>c.bottom:r<c.top)return j.cursor(i.pos,i.assoc);let l=e.coordsAtPos(i.pos,i.assoc),u=l?(l.top+l.bottom)/2:0;if(!l||(n?u>s:u<s))return j.cursor(i.pos,i.assoc,void 0,o)}}function No(e,t,n){for(;;){let r=0;for(let i of e)i.between(t-1,t+1,(e,i,a)=>{if(t>e&&t<i){let a=r||n||(t-e<i-t?-1:1);t=a<0?e:i,r=a}});if(!r)return t}}function Po(e,t){let n=null;for(let r=0;r<t.ranges.length;r++){let i=t.ranges[r],a=null;if(i.empty){let t=No(e,i.from,0);t!=i.from&&(a=j.cursor(t,-1))}else{let t=No(e,i.from,-1),n=No(e,i.to,1);(t!=i.from||n!=i.to)&&(a=i.undirectional?j.undirectionalRange(i.from,i.to):j.range(i.from==i.anchor?t:n,i.from==i.head?t:n))}a&&(n||=t.ranges.slice(),n[r]=a)}return n?j.create(n,t.mainIndex):t}function Fo(e,t,n){let r=No(e.state.facet(ja).map(t=>t(e)),n.from,t.head>n.from?-1:1);return r==n.from?n:j.cursor(r,r<n.from?1:-1)}var Io=class{constructor(e,t){this.pos=e,this.assoc=t}};function Lo(e,t,n,r){let i=e.contentDOM.getBoundingClientRect(),a=i.top+e.viewState.paddingTop,{x:o,y:s}=t,c=s-a,l;for(;;){if(c<0)return new Io(0,1);if(c>e.viewState.docHeight)return new Io(e.state.doc.length,-1);if(l=e.elementAtHeight(c),r==null)break;if(l.type==ni.Text){if(r<0?l.to<e.viewport.from:l.from>e.viewport.to)break;let t=e.docView.coordsAt(r<0?l.from:l.to,r>0?-1:1);if(t&&(r<0?t.top<=c+a:t.bottom>=c+a))break}let t=e.viewState.heightOracle.textHeight/2;c=r>0?l.bottom+t:l.top-t}if(e.viewport.from>=l.to||e.viewport.to<=l.from){if(n)return null;if(l.type==ni.Text){let t=Do(e,i,l,o,s);return new Io(t,t==l.from?1:-1)}}if(l.type!=ni.Text)return c<(l.top+l.bottom)/2?new Io(l.from,1):new Io(l.to,-1);let u=e.docView.lineAt(l.from,2);return(!u||u.length!=l.length)&&(u=e.docView.lineAt(l.from,-2)),new Ro(e,o,s,e.textDirectionAt(l.from)).scanTile(u,l.from)}var Ro=class{constructor(e,t,n,r){this.view=e,this.x=t,this.y=n,this.baseDir=r,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[qi.find(r,e-n.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[qi.find(r,e-n.from,-1,t)].dir}bidiIn(e,t){let{spans:n,line:r}=this.bidiSpansAt(e);return n.length>1||n.length&&(n[0].level!=this.baseDir||n[0].to+r.from<t)}scan(e,t,n=!1){let r=0,i=e.length-1,a=new Set,o=this.bidiIn(e[0],e[i]),s,c,l=-1,u=1e9,d;search:for(;r<i;){let n=i-r,f=r+i>>1;adjust:if(a.has(f)){for(let e=1;e<n;e++){let t=f+e;if(t>=i&&(t-=n),!a.has(t)){f=t;break adjust}}break search}a.add(f);let p=t(f),m=0;if(p)for(let e=0;e<p.length;e++){let t=p[e];if(!(t.width==0&&p.length>1))if(t.bottom<this.y)(!s||s.bottom<t.bottom)&&(s=t),m=1;else if(t.top>this.y)(!c||c.top>t.top)&&(c=t),m=-1;else{let e=t.left>this.x?this.x-t.left:t.right<this.x?this.x-t.right:0,n=Math.abs(e);n<u&&(l=f,u=n,d=t),e&&(m=e<0==(this.baseDir==R.LTR)?-1:1)}}m==-1&&(!o||this.baseDirAt(e[f],1))?i=f:m==1&&(!o||this.baseDirAt(e[f+1],-1))&&(r=f+1)}if(!d){if(!c&&!s)return{i:e[0],after:!1};let n=s&&(!c||this.y-s.bottom<c.top-this.y)?s:c;return this.y=(n.top+n.bottom)/2,this.scan(e,t,!0)}if(u&&!n){let{top:n,bottom:r}=d;if(s&&s.bottom>(n+n+r)/3)return this.y=s.bottom-1,this.scan(e,t,!0);if(c&&c.top<(n+r+r)/3)return this.y=c.top+1,this.scan(e,t,!0)}let f=(o?this.dirAt(e[l],1):this.baseDir)==R.LTR;return{i:l,after:this.x>(d.left+d.right)/2==f}}scanText(e,t){let n=[];for(let r=0;r<e.length;r=$t(e.text,r))n.push(t+r);n.push(t+e.length);let r=this.scan(n,r=>{let i=n[r]-t,a=n[r+1]-t;return Ai(e.dom,i,a).getClientRects()});return r.after?new Io(n[r.i+1],-1):new Io(n[r.i],1)}scanTile(e,t){if(!e.length)return new Io(t,1);if(e.children.length==1){let n=e.children[0];if(n.isText())return this.scanText(n,t);if(n.isComposite())return this.scanTile(n,t)}let n=[t];for(let r=0,i=t;r<e.children.length;r++)n.push(i+=e.children[r].length);let r=this.scan(n,t=>{let n=e.children[t];return n.flags&48?null:(n.dom.nodeType==1?n.dom:Ai(n.dom,0,n.length)).getClientRects()}),i=e.children[r.i],a=n[r.i];return i.isText()?this.scanText(i,a):i.isComposite()?this.scanTile(i,a):r.after?new Io(n[r.i+1],-1):new Io(a,1)}},zo=class{constructor(e,t){this.points=e,this.view=t,this.text=``,this.lineSeparator=t.state.facet(P.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=`￿`}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r);let e=this.text.length;this.readNode(r);let i=B.get(r),a=r.nextSibling;if(a==t){i?.breakAfter&&!a&&n!=this.view.contentDOM&&this.lineBreak();break}let o=B.get(a);(i&&o?i.breakAfter:(i?i.breakAfter:gi(r))||gi(a)&&(r.nodeName!=`BR`||i?.isWidget())&&this.text.length>e)&&!Vo(a,t)&&this.lineBreak(),r=a}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let i=-1,a=1,o;if(this.lineSeparator?(i=t.indexOf(this.lineSeparator,n),a=this.lineSeparator.length):(o=r.exec(t))&&(i=o.index,a=o[0].length),this.append(t.slice(n,i<0?t.length:i)),i<0)break;if(this.lineBreak(),a>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=a-1);n=i+a}}readNode(e){let t=B.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let e=n.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.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 n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(Bo(e,n.node,n.offset)?t:0))}};function Bo(e,t,n){for(;;){if(!t||n<vi(t))return!1;if(t==e)return!0;n=hi(t)+1,t=t.parentNode}}function Vo(e,t){let n;for(;!(e==t||!e);e=e.nextSibling){let t=B.get(e);if(!t?.isWidget())return!1;t&&(n||=[]).push(t)}if(n){for(let e of n)if(e.overrideDOMText?.length)return!1}return!0}var Ho=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},Uo=class{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text=``,this.domChanged=t>-1;let{impreciseHead:i,impreciseAnchor:a}=e.docView,o=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Wo(e.docView.tile,t,n,0))){let t=i||a?[]:Yo(e),n=new zo(t,e);n.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=n.text,this.newSel=Xo(t,this.bounds.from)}else{let t=e.observer.selectionRange,n=i&&i.node==t.focusNode&&i.offset==t.focusOffset||!di(e.contentDOM,t.focusNode)?o.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),r=a&&a.node==t.anchorNode&&a.offset==t.anchorOffset||!di(e.contentDOM,t.anchorNode)?o.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),s=e.viewport;if((I.ios||I.chrome)&&n!=r&&Math.min(n,r)<=o.main.from&&Math.max(n,r)>=o.main.to&&(s.from>0||s.to<e.state.doc.length)){let t=Math.min(n,r),i=Math.max(n,r),a=s.from-t,o=s.to-i;(a==0||a==1||t==0)&&(o==0||o==-1||i==e.state.doc.length)&&(n=0,r=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(j.range(r,n));else if(e.lineWrapping&&r==n&&!(o.main.empty&&o.main.head==n)&&e.inputState.lastTouchTime>Date.now()-100){let t=e.coordsAtPos(n,-1),r=0;t&&(r=e.inputState.lastTouchY<=t.bottom?-1:1),this.newSel=j.create([j.cursor(n,r)])}else this.newSel=j.single(r,n)}}};function Wo(e,t,n,r){if(e.isComposite()){let i=-1,a=-1,o=-1,s=-1;for(let c=0,l=r,u=r;c<e.children.length;c++){let r=e.children[c],d=l+r.length;if(l<t&&d>n)return Wo(r,t,n,l);if(d>=t&&i==-1&&(i=c,a=l),l>n&&r.dom.parentNode==e.dom){o=c,s=u;break}u=d,l=d+r.breakAfter}return{from:a,to:s<0?r+e.length:s,startDOM:(i?e.children[i-1].dom.nextSibling:null)||e.dom.firstChild,endDOM:o<e.children.length&&o>=0?e.children[o].dom:null}}else if(e.isText())return{from:r,to:r+e.length,startDOM:e.dom,endDOM:e.dom.nextSibling};else return null}function Go(e,t){let n,{newSel:r}=t,{state:i}=e,a=i.selection.main,o=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:e,to:r}=t.bounds,s=a.from,c=null;(o===8||I.android&&t.text.length<r-e)&&(s=a.to,c=`end`);let l=i.doc.sliceString(e,r,`￿`),u,d;!a.empty&&a.from>=e&&a.to<=r&&(t.typeOver||l!=t.text)&&l.slice(0,a.from-e)==t.text.slice(0,a.from-e)&&l.slice(a.to-e)==t.text.slice(u=t.text.length-(l.length-(a.to-e)))?n={from:a.from,to:a.to,insert:k.of(t.text.slice(a.from-e,u).split(`￿`))}:(d=Jo(l,t.text,s-e,c))&&(I.chrome&&o==13&&d.toB==d.from+2&&t.text.slice(d.from,d.toB)==`￿￿`&&d.toB--,n={from:e+d.from,to:e+d.toA,insert:k.of(t.text.slice(d.from,d.toB).split(`￿`))})}else r&&(!e.hasFocus&&i.facet(xa)||Zo(r,a))&&(r=null);if(!n&&!r)return!1;if((I.mac||I.android)&&n&&n.from==n.to&&n.from==a.head-1&&/^\. ?$/.test(n.insert.toString())&&e.contentDOM.getAttribute(`autocorrect`)==`off`?(r&&n.insert.length==2&&(r=j.single(r.main.anchor-1,r.main.head-1)),n={from:n.from,to:n.to,insert:k.of([n.insert.toString().replace(`.`,` `)])}):i.doc.lineAt(a.from).to<a.to&&e.docView.lineHasWidget(a.to)&&e.inputState.insertingTextAt>Date.now()-50?n={from:a.from,to:a.to,insert:i.toText(e.inputState.insertingText)}:I.chrome&&n&&n.from==n.to&&n.from==a.head&&n.insert.toString()==`
742
+ `&&e.lineWrapping&&(r&&=j.single(r.main.anchor-1,r.main.head-1),n={from:a.from,to:a.to,insert:k.of([` `])}),n)return Ko(e,n,r,o);if(r&&!Zo(r,a)){let t=!1,n=`select`;return e.inputState.lastSelectionTime>Date.now()-50&&(e.inputState.lastSelectionOrigin==`select`&&(t=!0),n=e.inputState.lastSelectionOrigin,n==`select.pointer`&&(r=Po(i.facet(ja).map(t=>t(e)),r))),e.dispatch({selection:r,scrollIntoView:t,userEvent:n}),!0}else return!1}function Ko(e,t,n,r=-1){if(I.ios&&e.inputState.flushIOSKey(t))return!0;let i=e.state.selection.main;if(I.android&&(t.to==i.to&&(t.from==i.from||t.from==i.from-1&&e.state.sliceDoc(t.from,i.from)==` `)&&t.insert.length==1&&t.insert.lines==2&&ji(e.contentDOM,`Enter`,13)||(t.from==i.from-1&&t.to==i.to&&t.insert.length==0||r==8&&t.insert.length<t.to-t.from&&t.to>i.head)&&ji(e.contentDOM,`Backspace`,8)||t.from==i.from&&t.to==i.to+1&&t.insert.length==0&&ji(e.contentDOM,`Delete`,46)))return!0;let a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o,s=()=>o||=qo(e,t,n);return e.state.facet(ua).some(n=>n(e,t.from,t.to,a,s))||e.dispatch(s()),!0}function qo(e,t,n){let r,i=e.state,a=i.selection.main,o=-1;if(t.from==t.to&&t.from<a.from||t.from>a.to){let n=t.from<a.from?-1:1,r=n<0?a.from:a.to,s=No(i.facet(ja).map(t=>t(e)),r,n);t.from==s&&(o=s)}if(o>-1)r={changes:t,selection:j.cursor(t.from+t.insert.length,-1)};else if(t.from>=a.from&&t.to<=a.to&&t.to-t.from>=(a.to-a.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let n=a.from<t.from?i.sliceDoc(a.from,t.from):``,o=a.to>t.to?i.sliceDoc(t.to,a.to):``;r=i.replaceSelection(e.state.toText(n+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=i.changes(t),s=n&&n.main.to<=o.newLength?n.main:void 0;if(i.selection.ranges.length>1&&(e.inputState.composing>=0||e.inputState.compositionPendingChange)&&t.to<=a.to+10&&t.to>=a.to-10){let c=e.state.sliceDoc(t.from,t.to),l,u=n&&go(e,n.main.head);if(u){let e=t.insert.length-(t.to-t.from);l={from:u.from,to:u.to-e}}else l=e.state.doc.lineAt(a.head);let d=a.to-t.to;r=i.changeByRange(n=>{if(n.from==a.from&&n.to==a.to)return{changes:o,range:s||n.map(o)};let r=n.to-d,u=r-c.length;if(e.state.sliceDoc(u,r)!=c||r>=l.from&&u<=l.to)return{range:n};let f=i.changes({from:u,to:r,insert:t.insert}),p=n.to-a.to;return{changes:f,range:s?j.range(Math.max(0,s.anchor+p),Math.max(0,s.head+p)):n.map(f)}})}else r={changes:o,selection:s&&i.selection.replaceRange(s)}}let s=`input.type`;return(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,s+=`.compose`,e.inputState.compositionFirstChange&&(s+=`.start`,e.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:s,scrollIntoView:!0})}function Jo(e,t,n,r){let i=Math.min(e.length,t.length),a=0;for(;a<i&&e.charCodeAt(a)==t.charCodeAt(a);)a++;if(a==i&&e.length==t.length)return null;let o=e.length,s=t.length;for(;o>0&&s>0&&e.charCodeAt(o-1)==t.charCodeAt(s-1);)o--,s--;if(r==`end`){let e=Math.max(0,a-Math.min(o,s));n-=o+e-a}if(o<a&&e.length<t.length){let e=n<=a&&n>=o?a-n:0;a-=e,s=a+(s-o),o=a}else if(s<a){let e=n<=a&&n>=s?a-n:0;a-=e,o=a+(o-s),s=a}return{from:a,toA:o,toB:s}}function Yo(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=e.observer.selectionRange;return n&&(t.push(new Ho(n,r)),(i!=n||a!=r)&&t.push(new Ho(i,a))),t}function Xo(e,t){if(e.length==0)return null;let n=e[0].pos,r=e.length==2?e[1].pos:n;return n>-1&&r>-1?j.single(n+t,r+t):null}function Zo(e,t){return t.head==e.main.head&&t.anchor==e.main.anchor}var Qo=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText=``,this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,I.safari&&e.contentDOM.addEventListener(`input`,()=>null),I.gecko&&Ps(e.contentDOM.ownerDocument)}handleEvent(e){!ds(this.view,e)||this.ignoreDuringComposition(e)||e.type==`keydown`&&this.keydown(e)||(this.view.updateState==0?this.runHandlers(e.type,e):Promise.resolve().then(()=>this.runHandlers(e.type,e)))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let e of n.observers)e(this.view,t);for(let e of n.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=ts(e),n=this.handlers,r=this.view.contentDOM;for(let e in t)if(e!=`scroll`){let i=!t[e].handlers.length,a=n[e];a&&i!=!a.handlers.length&&(r.removeEventListener(e,this.handleEvent),a=null),a||r.addEventListener(e,this.handleEvent,{passive:i})}for(let e in n)e!=`scroll`&&!t[e]&&r.removeEventListener(e,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&&is.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),I.android&&I.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(I.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(ns.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||rs.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};return t.shiftKey&&I.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&$o(this.view.win)&&(t.shiftKey=!1),this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t},setTimeout(()=>this.flushIOSKey(),250),!0}return 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,ji(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:I.safari&&!I.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 $o(e){return e.visualViewport?e.visualViewport.height*e.visualViewport.scale/e.document.documentElement.clientHeight<.85:!1}function es(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(e){ba(n.state,e)}}}function ts(e){let t=Object.create(null);function n(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let t of e){let e=t.spec,r=e&&e.plugin.domEventHandlers,i=e&&e.plugin.domEventObservers;if(r)for(let e in r){let i=r[e];i&&n(e).handlers.push(es(t.value,i))}if(i)for(let e in i){let r=i[e];r&&n(e).observers.push(es(t.value,r))}}for(let e in fs)n(e).handlers.push(fs[e]);for(let e in ps)n(e).observers.push(ps[e]);return t}const ns=[{key:`Backspace`,keyCode:8,inputType:`deleteContentBackward`},{key:`Enter`,keyCode:13,inputType:`insertParagraph`},{key:`Enter`,keyCode:13,inputType:`insertLineBreak`},{key:`Delete`,keyCode:46,inputType:`deleteContentForward`}],rs=`dthko`,is=[16,17,18,20,91,92,224,225];function as(e){return Math.max(0,e)*.7+8}function os(e,t){return Math.max(Math.abs(e.clientX-t.clientX),Math.abs(e.clientY-t.clientY))}var ss=class{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Ci(e.contentDOM),this.atoms=e.state.facet(ja).map(t=>t(e));let i=e.contentDOM.ownerDocument;i.addEventListener(`mousemove`,this.move=this.move.bind(this)),i.addEventListener(`mouseup`,this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(P.allowMultipleSelections)&&cs(e,t),this.dragging=us(e,t)&&Cs(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&&os(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,i=0,a=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:a}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:i,bottom:o}=this.scrollParents.y.getBoundingClientRect());let s=Fa(this.view);e.clientX-s.left<=r+6?t=-as(r-e.clientX):e.clientX+s.right>=a-6&&(t=as(e.clientX-a)),e.clientY-s.top<=i+6?n=-as(i-e.clientY):e.clientY+s.bottom>=o-6&&(n=as(e.clientY-o)),this.setScrollSpeed(t,n)}up(e){this.dragging??this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener(`mousemove`,this.move),e.removeEventListener(`mouseup`,this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,n=Po(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!n.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:n,userEvent:`select.pointer`}),this.mustSelect=!1}update(e){e.transactions.some(e=>e.isUserEvent(`input.type`))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function cs(e,t){let n=e.state.facet(aa);return n.length?n[0](t):I.mac?t.metaKey:t.ctrlKey}function ls(e,t){let n=e.state.facet(oa);return n.length?n[0](t):I.mac?!t.altKey:!t.ctrlKey}function us(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=ui(e.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let e=0;e<i.length;e++){let n=i[e];if(n.left<=t.clientX&&n.right>=t.clientX&&n.top<=t.clientY&&n.bottom>=t.clientY)return!0}return!1}function ds(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target,r;n!=e.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=B.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(t))return!1;return!0}const fs=Object.create(null),ps=Object.create(null),ms=I.ie&&I.ie_version<15||I.ios&&I.webkit_version<604;function hs(e){let t=e.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement(`textarea`));n.style.cssText=`position: fixed; left: -10000px; top: 10px`,n.focus(),setTimeout(()=>{e.focus(),n.remove(),_s(e,n.value)},50)}function gs(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function _s(e,t){t=gs(e.state,fa,t);let{state:n}=e,r,i=1,a=n.toText(t),o=a.lines==n.selection.ranges.length;if(ks!=null&&n.selection.ranges.every(e=>e.empty)&&ks==a.toString()){let e=-1;r=n.changeByRange(r=>{let s=n.doc.lineAt(r.from);if(s.from==e)return{range:r};e=s.from;let c=n.toText((o?a.line(i++).text:t)+n.lineBreak);return{changes:{from:s.from,insert:c},range:j.cursor(r.from+c.length)}})}else r=o?n.changeByRange(e=>{let t=a.line(i++);return{changes:{from:e.from,to:e.to,insert:t.text},range:j.cursor(e.from+t.length)}}):n.replaceSelection(a);e.dispatch(r,{userEvent:`input.paste`,scrollIntoView:!0})}ps.scroll=e=>{let t=e.inputState;t.lastScrollTop=e.scrollDOM.scrollTop,t.lastScrollLeft=e.scrollDOM.scrollLeft,I.ios&&!t.touchActive&&(t.lastIOSMomentumScroll=Date.now())},ps.wheel=ps.mousewheel=e=>{e.inputState.lastWheelEvent=Date.now()},fs.keydown=(e,t)=>(e.inputState.setSelectionOrigin(`select`),t.keyCode==27&&e.inputState.tabFocusMode!=0&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),ps.touchstart=(e,t)=>{let n=e.inputState,r=t.targetTouches[0];n.touchActive=!0,n.lastTouchTime=Date.now(),r&&(n.lastTouchX=r.clientX,n.lastTouchY=r.clientY),n.setSelectionOrigin(`select.pointer`)},ps.touchmove=e=>{e.inputState.setSelectionOrigin(`select.pointer`)},ps.touchend=(e,t)=>{e.inputState.touchActive=!1},fs.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of e.state.facet(sa))if(n=r(e,t),n)break;if(!n&&t.button==0&&(n=ws(e,t)),n){let r=!e.hasFocus;e.inputState.startMouseSelection(new ss(e,t,n,r)),r&&e.observer.ignore(()=>{Oi(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()});let i=e.inputState.mouseSelection;if(i)return i.start(t),i.dragging===!1}else e.inputState.setSelectionOrigin(`select.pointer`);return!1};function vs(e,t,n,r){if(r==1)return j.cursor(t,n);if(r==2)return Eo(e.state,t,n);{let r=e.docView.lineAt(t,n),i=e.state.doc.lineAt(r?r.posAtEnd:t),a=r?r.posAtStart:i.from,o=r?r.posAtEnd:i.to;return o<e.state.doc.length&&o==i.to&&o++,j.undirectionalRange(a,o)}}const ys=I.ie&&I.ie_version<=11;let bs=null,xs=0,Ss=0;function Cs(e){if(!ys)return e.detail;let t=bs,n=Ss;return bs=e,Ss=Date.now(),xs=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(xs+1)%3:1}function ws(e,t){let n=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),r=Cs(t),i=e.state.selection;return{update(e){e.docChanged&&(n.pos=e.changes.mapPos(n.pos),i=i.map(e.changes))},get(t,a,o){let s=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),c,l=vs(e,s.pos,s.assoc,r);if(n.pos!=s.pos&&!a){let t=vs(e,n.pos,n.assoc,r),i=Math.min(t.from,l.from),a=Math.max(t.to,l.to);l=i<l.from?j.range(i,a,l.assoc):j.range(a,i,l.assoc)}return a?i.replaceRange(i.main.extend(l.from,l.to,l.assoc)):o&&r==1&&i.ranges.length>1&&(c=Ts(i,s.pos))?c:o?i.addRange(l):j.create([l])}}}function Ts(e,t){for(let n=0;n<e.ranges.length;n++){let{from:r,to:i}=e.ranges[n];if(r<=t&&i>=t)return j.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-+(e.mainIndex>n))}return null}fs.dragstart=(e,t)=>{let{selection:{main:n}}=e.state;if(t.target.draggable){let r=e.docView.tile.nearest(t.target);if(r&&r.isWidget()){let e=r.posAtStart,t=e+r.length;(e>=n.to||t<=n.from)&&(n=j.undirectionalRange(e,t))}}let{inputState:r}=e;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,t.dataTransfer&&(t.dataTransfer.setData(`Text`,gs(e.state,pa,e.state.sliceDoc(n.from,n.to))),t.dataTransfer.effectAllowed=`copyMove`),!1},fs.dragend=e=>(e.inputState.draggedContent=null,!1);function Es(e,t,n,r){if(n=gs(e.state,fa,n),!n)return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:a}=e.inputState,o=r&&a&&ls(e,t)?{from:a.from,to:a.to}:null,s={from:i,insert:n},c=e.state.changes(o?[o,s]:s);e.focus(),e.dispatch({changes:c,selection:{anchor:c.mapPos(i,-1),head:c.mapPos(i,1)},userEvent:o?`move.drop`:`input.drop`}),e.inputState.draggedContent=null}fs.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let n=t.dataTransfer.files;if(n&&n.length){let r=Array(n.length),i=0,a=()=>{++i==n.length&&Es(e,t,r.filter(e=>e!=null).join(e.state.lineBreak),!1)};for(let e=0;e<n.length;e++){let t=new FileReader;t.onerror=a,t.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(r[e]=t.result),a()},t.readAsText(n[e])}return!0}else{let n=t.dataTransfer.getData(`Text`);if(n)return Es(e,t,n,!0),!0}return!1},fs.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let n=ms?null:t.clipboardData;return n?(_s(e,n.getData(`text/plain`)||n.getData(`text/uri-list`)),!0):(hs(e),!1)};function Ds(e,t){let n=e.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement(`textarea`));r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout(()=>{r.remove(),e.focus()},50)}function Os(e){let t=[],n=[],r=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),n.push(r));if(!t.length){let i=-1;for(let{from:r}of e.selection.ranges){let a=e.doc.lineAt(r);a.number>i&&(t.push(a.text),n.push({from:a.from,to:Math.min(e.doc.length,a.to+1)})),i=a.number}r=!0}return{text:gs(e,pa,t.join(e.lineBreak)),ranges:n,linewise:r}}let ks=null;fs.copy=fs.cut=(e,t)=>{if(!fi(e.contentDOM,e.observer.selectionRange))return!1;let{text:n,ranges:r,linewise:i}=Os(e.state);if(!n&&!i)return!1;ks=i?n:null,t.type==`cut`&&!e.state.readOnly&&e.dispatch({changes:r,scrollIntoView:!0,userEvent:`delete.cut`});let a=ms?null:t.clipboardData;return a?(a.clearData(),a.setData(`text/plain`,n),!0):(Ds(e,n),!1)};const As=Vn.define();function js(e,t){let n=[];for(let r of e.facet(da)){let i=r(e,t);i&&n.push(i)}return n.length?e.update({effects:n,annotations:As.of(!0)}):null}function Ms(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=js(e.state,t);n?e.dispatch(n):e.update([])}},10)}ps.focus=e=>{e.inputState.lastFocusTime=Date.now(),!e.scrollDOM.scrollTop&&(e.inputState.lastScrollTop||e.inputState.lastScrollLeft)&&(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),Ms(e)},ps.blur=e=>{e.observer.clearSelectionRange(),Ms(e)},ps.compositionstart=ps.compositionupdate=e=>{e.observer.editContext||(e.inputState.compositionFirstChange??(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},ps.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,I.chrome&&I.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then(()=>e.observer.flush()):setTimeout(()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])},50))},ps.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},fs.beforeinput=(e,t)=>{if((t.inputType==`insertText`||t.inputType==`insertCompositionText`)&&(e.inputState.insertingText=t.data,e.inputState.insertingTextAt=Date.now()),t.inputType==`insertReplacementText`&&e.observer.editContext){let n=t.dataTransfer?.getData(`text/plain`),r=t.getTargetRanges();if(n&&r.length){let t=r[0];return Ko(e,{from:e.posAtDOM(t.startContainer,t.startOffset),to:e.posAtDOM(t.endContainer,t.endOffset),insert:e.state.toText(n)},null),!0}}let n;if(I.chrome&&I.android&&(n=ns.find(e=>e.inputType==t.inputType))&&(e.observer.delayAndroidKey(n.key,n.keyCode),n.key==`Backspace`||n.key==`Delete`)){let t=window.visualViewport?.height||0;setTimeout(()=>{(window.visualViewport?.height||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())},100)}return I.ios&&t.inputType==`deleteContentForward`&&e.observer.flushSoon(),I.safari&&t.inputType==`insertText`&&e.inputState.composing>=0&&setTimeout(()=>ps.compositionend(e,t),20),!1};const Ns=new Set;function Ps(e){Ns.has(e)||(Ns.add(e),e.addEventListener(`copy`,()=>{}),e.addEventListener(`cut`,()=>{}))}const Fs=[`pre-wrap`,`normal`,`pre-line`,`break-spaces`];let Is=!1;function Ls(){Is=!1}var Rs=class{constructor(e){this.lineWrapping=e,this.doc=k.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Fs.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];r<0?n++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,n,r,i,a){let o=Fs.indexOf(e)>-1,s=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=i,s){this.heightSamples={};for(let e=0;e<a.length;e++){let t=a[e];t<0?e++:this.heightSamples[Math.floor(t*10)]=!0}}return s}},zs=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},Bs=class e{constructor(e,t,n,r,i){this.from=e,this.length=t,this.top=n,this.height=r,this._content=i}get type(){return typeof this._content==`number`?ni.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 ai?this._content.widget:null}get widgetLineBreaks(){return typeof this._content==`number`?this._content:0}join(t){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new e(this.from,this.length+t.length,this.top,this.height+t.height,n)}},V=(function(e){return e[e.ByPos=0]=`ByPos`,e[e.ByHeight=1]=`ByHeight`,e[e.ByPosNoHeight=2]=`ByPosNoHeight`,e})(V||={});const Vs=.001;var Hs=class e{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Vs&&(Is=!0),this.height=e)}replace(t,n,r){return e.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let i=this,a=n.doc;for(let o=r.length-1;o>=0;o--){let{fromA:s,toA:c,fromB:l,toB:u}=r[o],d=i.lineAt(s,V.ByPosNoHeight,n.setDoc(t),0,0),f=d.to>=c?d:i.lineAt(c,V.ByPosNoHeight,n,0,0);for(u+=f.to-c,c=f.to;o>0&&d.from<=r[o-1].toA;)s=r[o-1].fromA,l=r[o-1].fromB,o--,s<d.from&&(d=i.lineAt(s,V.ByPosNoHeight,n,0,0));l+=d.from-s,s=d.from;let p=Xs.build(n.setDoc(a),e,l,u);i=Us(i,i.replace(s,c,p))}return i.updateHeight(n,0)}static empty(){return new Ks(0,0,0)}static of(t){if(t.length==1)return t[0];let n=0,r=t.length,i=0,a=0;for(;;)if(n==r)if(i>a*2){let e=t[n-1];e.break?t.splice(--n,1,e.left,null,e.right):t.splice(--n,1,e.left,e.right),r+=1+e.break,i-=e.size}else if(a>i*2){let e=t[r];e.break?t.splice(r,1,e.left,null,e.right):t.splice(r,1,e.left,e.right),r+=2+e.break,a-=e.size}else break;else if(i<a){let e=t[n++];e&&(i+=e.size)}else{let e=t[--r];e&&(a+=e.size)}let o=0;return t[n-1]==null?(o=1,n--):t[n]??(o=1,r++),new Js(e.of(t.slice(0,n)),o,e.of(t.slice(r)))}};function Us(e,t){return e==t?e:(e.constructor!=t.constructor&&(Is=!0),t)}Hs.prototype.size=1;const Ws=L.replace({});var Gs=class extends Hs{constructor(e,t,n){super(e,t),this.deco=n,this.spaceAbove=0}mainBlock(e,t){return new Bs(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,n,r){return this.spaceAbove&&e<n+this.spaceAbove?new Bs(r,0,n,this.spaceAbove,Ws):this.mainBlock(n,r)}lineAt(e,t,n,r,i){let a=this.mainBlock(r,i);return this.spaceAbove?this.blockAt(0,n,r,i).join(a):a}forEachLine(e,t,n,r,i,a){e<=i+this.length&&t>=i&&a(this.lineAt(0,V.ByPos,n,r,i))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}},Ks=class e extends Gs{constructor(e,t,n){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=n}mainBlock(e,t){return new Bs(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,n,r){let i=r[0];return r.length==1&&(i instanceof e||i instanceof qs&&i.flags&4)&&Math.abs(this.length-i.length)<10?(i instanceof qs?i=new e(i.length,this.height,this.spaceAbove):i.height=this.height,this.outdated||(i.outdated=!1),i):Hs.of(r)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(n||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:``}${this.widgetHeight?`:`+this.widgetHeight:``})`}},qs=class e extends Hs{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,i=r-n+1,a,o=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*i);a=t/i,this.length>i+1&&(o=(this.height-t)/(this.length-i-1))}else a=this.height/i;return{firstLine:n,lastLine:r,perLine:a,perChar:o}}blockAt(e,t,n,r){let{firstLine:i,lastLine:a,perLine:o,perChar:s}=this.heightMetrics(t,r);if(t.lineWrapping){let i=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length)),a=t.doc.lineAt(i),c=o+a.length*s,l=Math.max(n,e-c/2);return new Bs(a.from,a.length,l,c,0)}else{let r=Math.max(0,Math.min(a-i,Math.floor((e-n)/o))),{from:s,length:c}=t.doc.line(i+r);return new Bs(s,c,n+o*r,o,0)}}lineAt(e,t,n,r,i){if(t==V.ByHeight)return this.blockAt(e,n,r,i);if(t==V.ByPosNoHeight){let{from:t,to:r}=n.doc.lineAt(e);return new Bs(t,r-t,0,0,0)}let{firstLine:a,perLine:o,perChar:s}=this.heightMetrics(n,i),c=n.doc.lineAt(e),l=o+c.length*s,u=c.number-a,d=r+o*u+s*(c.from-i-u);return new Bs(c.from,c.length,Math.max(r,Math.min(d,r+this.height-l)),l,0)}forEachLine(e,t,n,r,i,a){e=Math.max(e,i),t=Math.min(t,i+this.length);let{firstLine:o,perLine:s,perChar:c}=this.heightMetrics(n,i);for(let l=e,u=r;l<=t;){let t=n.doc.lineAt(l);if(l==e){let n=t.number-o;u+=s*n+c*(e-i-n)}let r=s+c*t.length;a(new Bs(t.from,t.length,u,r,0)),u+=r,l=t.to+1}}replace(t,n,r){let i=this.length-n;if(i>0){let t=r[r.length-1];t instanceof e?r[r.length-1]=new e(t.length+i):r.push(null,new e(i-1))}if(t>0){let n=r[0];n instanceof e?r[0]=new e(t+n.length):r.unshift(new e(t-1),null)}return Hs.of(r)}decomposeLeft(t,n){n.push(new e(t-1),null)}decomposeRight(t,n){n.push(null,new e(this.length-t-1))}updateHeight(t,n=0,r=!1,i){let a=n+this.length;if(i&&i.from<=n+this.length&&i.more){let r=[],o=Math.max(n,i.from),s=-1;for(i.from>n&&r.push(new e(i.from-n-1).updateHeight(t,n));o<=a&&i.more;){let e=t.doc.lineAt(o).length;r.length&&r.push(null);let n=i.heights[i.index++],a=0;n<0&&(a=-n,n=i.heights[i.index++]),s==-1?s=n:Math.abs(n-s)>=Vs&&(s=-2);let c=new Ks(e,n,a);c.outdated=!1,r.push(c),o+=e+1}o<=a&&r.push(null,new e(a-o).updateHeight(t,o));let c=Hs.of(r);return(s<0||Math.abs(c.height-this.height)>=Vs||Math.abs(s-this.heightMetrics(t,n).perLine)>=Vs)&&(Is=!0),Us(this,c)}else(r||this.outdated)&&(this.setHeight(t.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Js=class extends Hs{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let i=n+this.left.height;return e<i?this.left.blockAt(e,t,n,r):this.right.blockAt(e,t,i,r+this.left.length+this.break)}lineAt(e,t,n,r,i){let a=r+this.left.height,o=i+this.left.length+this.break,s=t==V.ByHeight?e<a:e<o,c=s?this.left.lineAt(e,t,n,r,i):this.right.lineAt(e,t,n,a,o);if(this.break||(s?c.to<o:c.from>o))return c;let l=t==V.ByPosNoHeight?V.ByPosNoHeight:V.ByPos;return s?c.join(this.right.lineAt(o,l,n,a,o)):this.left.lineAt(o,l,n,r,i).join(c)}forEachLine(e,t,n,r,i,a){let o=r+this.left.height,s=i+this.left.length+this.break;if(this.break)e<s&&this.left.forEachLine(e,t,n,r,i,a),t>=s&&this.right.forEachLine(e,t,n,o,s,a);else{let c=this.lineAt(s,V.ByPos,n,r,i);e<c.from&&this.left.forEachLine(e,c.from-1,n,r,i,a),c.to>=e&&c.from<=t&&a(c),t>c.to&&this.right.forEachLine(c.to+1,t,n,o,s,a)}}replace(e,t,n){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let i=[];e>0&&this.decomposeLeft(e,i);let a=i.length;for(let e of n)i.push(e);if(e>0&&Ys(i,a-1),t<this.length){let e=i.length;this.decomposeRight(t,i),Ys(i,e)}return Hs.of(i)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Hs.of(this.break?[e,null,t]:[e,t]):(this.left=Us(this.left,e),this.right=Us(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,r){let{left:i,right:a}=this,o=t+i.length+this.break,s=null;return r&&r.from<=t+i.length&&r.more?s=i=i.updateHeight(e,t,n,r):i.updateHeight(e,t,n),r&&r.from<=o+a.length&&r.more?s=a=a.updateHeight(e,o,n,r):a.updateHeight(e,o,n),s?this.balanced(i,a):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?` `:`-`)+this.right}};function Ys(e,t){let n,r;e[t]==null&&(n=e[t-1])instanceof qs&&(r=e[t+1])instanceof qs&&e.splice(t-1,3,new qs(n.length+1+r.length))}var Xs=class e{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 e=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof Ks?n.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new Ks(e-this.pos,-1,0)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let r=n.widget?n.widget.estimatedHeight:0,i=n.widget?n.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let a=t-e;n.block?this.addBlock(new Gs(a,r,n)):(a||i||r>=5)&&this.addLineDeco(r,i,a)}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 Ks(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let n=new qs(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ks)return e;let t=new Ks(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+=e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos+=n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ks)&&!this.isCovered?this.nodes.push(new Ks(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let e of this.nodes)e instanceof Ks&&e.updateHeight(this.oracle,n),n+=e?e.length:1;return this.nodes}static build(t,n,r,i){let a=new e(r,t);return F.spans(n,r,i,a,0),a.finish(r)}};function Zs(e,t,n){let r=new Qs;return F.compare(e,t,n,r,0),r.changes}var Qs=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,r){(e<t||n&&n.heightRelevant||r&&r.heightRelevant)&&ci(e,t,this.changes,5)}};function $s(e,t){let n=e.getBoundingClientRect(),r=e.ownerDocument,i=r.defaultView||window,a=Math.max(0,n.left),o=Math.min(i.innerWidth,n.right),s=Math.max(0,n.top),c=Math.min(i.innerHeight,n.bottom);for(let t=e.parentNode;t&&t!=r.body;)if(t.nodeType==1){let n=t,r=window.getComputedStyle(n);if((n.scrollHeight>n.clientHeight||n.scrollWidth>n.clientWidth)&&r.overflow!=`visible`){let r=n.getBoundingClientRect();a=Math.max(a,r.left),o=Math.min(o,r.right),s=Math.max(s,r.top),c=Math.min(t==e.parentNode?i.innerHeight:c,r.bottom)}t=r.position==`absolute`||r.position==`fixed`?n.offsetParent:n.parentNode}else if(t.nodeType==11)t=t.host;else break;return{left:a-n.left,right:Math.max(a,o)-n.left,top:s-(n.top+t),bottom:Math.max(s,c)-(n.top+t)}}function ec(e){let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView||window;return t.left<n.innerWidth&&t.right>0&&t.top<n.innerHeight&&t.bottom>0}function tc(e,t){let n=e.getBoundingClientRect();return{left:0,right:n.right-n.left,top:t,bottom:n.bottom-(n.top+t)}}var nc=class{constructor(e,t,n,r){this.from=e,this.to=t,this.size=n,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.from!=i.from||r.to!=i.to||r.size!=i.size)return!1}return!0}draw(e,t){return L.replace({widget:new rc(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}},rc=class extends ti{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}},ic=class{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=uc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=R.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let n=t.facet(Da).some(e=>typeof e!=`function`&&e.class==`cm-lineWrapping`);this.heightOracle=new Rs(n),this.stateDeco=dc(t),this.heightMap=Hs.empty().applyChanges(this.stateDeco,k.empty,this.heightOracle.setDoc(t.doc),[new La(0,0,0,t.doc.length)]);for(let e=0;e<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());e++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=L.set(this.lineGaps.map(e=>e.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:e,to:t})=>r>=e&&r<=t)){let{from:t,to:n}=this.lineBlockAt(r);e.push(new ac(t,n))}}return this.viewports=e.sort((e,t)=>e.from-t.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?uc:new fc(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(pc(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=dc(this.state);let r=e.changedRanges,i=La.extendWithRanges(r,Zs(n,this.stateDeco,e?e.changes:cn.empty(this.state.doc.length))),a=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ls(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),i),(this.heightMap.height!=a||Is)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=a);let s=i.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<s.from||t.range.head>s.to)||!this.viewportIsAppropriate(s))&&(s=this.getViewport(0,t));let c=s.from!=this.viewport.from||s.to!=this.viewport.to;this.viewport=s,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(ha)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,i=n.whiteSpace;this.defaultTextDirection=n.direction==`rtl`?R.RTL:R.LTR;let a=this.heightOracle.mustRefreshForWrapping(i)||this.mustMeasureContent===`refresh`,o=t.getBoundingClientRect(),s=a||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let c=0,l=0;if(o.width&&o.height){let{scaleX:e,scaleY:n}=xi(t,o);(e>.005&&Math.abs(this.scaleX-e)>.005||n>.005&&Math.abs(this.scaleY-n)>.005)&&(this.scaleX=e,this.scaleY=n,c|=16,a=s=!0)}let u=(parseInt(n.paddingTop)||0)*this.scaleY,d=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=u||this.paddingBottom!=d)&&(this.paddingTop=u,this.paddingBottom=d,c|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(s=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=16);let f=Ci(this.view.contentDOM,!1).y;f!=this.scrollParent&&(this.scrollParent=f,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Pi(this.scrollParent||e.win);let m=(this.printing?tc:$s)(t,this.paddingTop),h=m.top-this.pixelViewport.top,g=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let _=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(_!=this.inView&&(this.inView=_,_&&(s=!0)),!this.inView&&!this.scrollTarget&&!ec(e.dom))return 0;let v=o.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,c|=16),s){let t=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(t)&&(a=!0),a||r.lineWrapping&&Math.abs(v-this.contentDOMWidth)>r.charWidth){let{lineHeight:n,charWidth:o,textHeight:s}=e.docView.measureTextSize();a=n>0&&r.refresh(i,n,o,s,Math.max(5,v/o),t),a&&(e.docView.minWidth=0,c|=16)}h>0&&g>0?l=Math.max(h,g):h<0&&g<0&&(l=Math.min(h,g)),Ls();for(let n of this.viewports){let i=n.from==this.viewport.from?t:e.docView.measureVisibleLineHeights(n);this.heightMap=(a?Hs.empty().applyChanges(this.stateDeco,k.empty,this.heightOracle,[new La(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,a,new zs(n.from,i))}Is&&(c|=2)}let y=!this.viewportIsAppropriate(this.viewport,l)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return y&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(l,this.scrollTarget),c|=this.updateForViewport()),(c&2||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(a?[]: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 n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,i=this.heightOracle,{visibleTop:a,visibleBottom:o}=this,s=new ac(r.lineAt(a-n*1e3,V.ByHeight,i,0,0).from,r.lineAt(o+(1-n)*1e3,V.ByHeight,i,0,0).to);if(t){let{head:e}=t.range;if(e<s.from||e>s.to){let n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),a=r.lineAt(e,V.ByPos,i,0,0),o;o=t.y==`center`?(a.top+a.bottom)/2-n/2:t.y==`start`||t.y==`nearest`&&e<s.from?a.top:a.bottom-n,s=new ac(r.lineAt(o-1e3/2,V.ByHeight,i,0,0).from,r.lineAt(o+n+1e3/2,V.ByHeight,i,0,0).to)}}return s}mapViewport(e,t){let n=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new ac(this.heightMap.lineAt(n,V.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,V.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),{bottom:i}=this.heightMap.lineAt(t,V.ByPos,this.heightOracle,0,0),{visibleTop:a,visibleBottom:o}=this;return(e==0||r<=a-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||i>=o+Math.max(10,Math.min(n,250)))&&r>a-2*1e3&&i<o+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let r of e)t.touchesRange(r.from,r.to)||n.push(new nc(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,r=n?1e4:2e3,i=r>>1,a=r<<1;if(this.defaultTextDirection!=R.LTR&&!n)return[];let o=[],s=(r,a,c,l)=>{if(a-r<i)return;let u=this.state.selection.main,d=[u.from];u.empty||d.push(u.to);for(let e of d)if(e>r&&e<a){s(r,e-10,c,l),s(e+10,a,c,l);return}let f=lc(e,e=>e.from>=c.from&&e.to<=c.to&&Math.abs(e.from-r)<i&&Math.abs(e.to-a)<i&&!d.some(t=>e.from<t&&e.to>t));if(!f){if(a<c.to&&t&&n&&t.visibleRanges.some(e=>e.from<=a&&e.to>=a)){let e=t.moveToLineBoundary(j.cursor(a),!1,!0).head;e>r&&(a=e)}let e=this.gapSize(c,r,a,l);f=new nc(r,a,e,n||e<2e6?e:2e6)}o.push(f)},c=t=>{if(t.length<a||t.type!=ni.Text)return;let i=oc(t.from,t.to,this.stateDeco);if(i.total<a)return;let o=this.scrollTarget?this.scrollTarget.range.head:null,c,l;if(n){let e=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,n,a;if(o!=null){let r=cc(i,o),s=((this.visibleBottom-this.visibleTop)/2+e)/t.height;n=r-s,a=r+s}else n=(this.visibleTop-t.top-e)/t.height,a=(this.visibleBottom-t.top+e)/t.height;c=sc(i,n),l=sc(i,a)}else{let n=i.total*this.heightOracle.charWidth,a=r*this.heightOracle.charWidth,s=0;if(n>2e6)for(let n of e)n.from>=t.from&&n.from<t.to&&n.size!=n.displaySize&&n.from*this.heightOracle.charWidth+s<this.pixelViewport.left&&(s=n.size-n.displaySize);let u=this.pixelViewport.left+s,d=this.pixelViewport.right+s,f,p;if(o!=null){let e=cc(i,o),t=((d-u)/2+a)/n;f=e-t,p=e+t}else f=(u-a)/n,p=(d+a)/n;c=sc(i,f),l=sc(i,p)}c>t.from&&s(t.from,c,t,i),l<t.to&&s(l,t.to,t,i)};for(let e of this.viewportLines)Array.isArray(e.type)?e.type.forEach(c):c(e);return o}gapSize(e,t,n,r){let i=cc(r,n)-cc(r,t);return this.heightOracle.lineWrapping?e.height*i:r.total*this.heightOracle.charWidth*i}updateLineGaps(e){nc.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=L.set(e.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];F.spans(t,this.viewport.from,this.viewport.to,{span(e,t){n.push({from:e,to:t})},point(){}},20);let r=0;if(n.length!=this.visibleRanges.length)r=12;else for(let t=0;t<n.length&&!(r&8);t++){let i=this.visibleRanges[t],a=n[t];(i.from!=a.from||i.to!=a.to)&&(r|=4,e&&e.mapPos(i.from,-1)==a.from&&e.mapPos(i.to,1)==a.to||(r|=8))}return this.visibleRanges=n,r}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||pc(this.heightMap.lineAt(e,V.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)||pc(this.heightMap.lineAt(this.scaler.fromDOM(e),V.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return pc(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}},ac=class{constructor(e,t){this.from=e,this.to=t}};function oc(e,t,n){let r=[],i=e,a=0;return F.spans(n,e,t,{span(){},point(e,t){e>i&&(r.push({from:i,to:e}),a+=e-i),i=t}},20),i<t&&(r.push({from:i,to:t}),a+=t-i),{total:a,ranges:r}}function sc({total:e,ranges:t},n){if(n<=0)return t[0].from;if(n>=1)return t[t.length-1].to;let r=Math.floor(e*n);for(let e=0;;e++){let{from:n,to:i}=t[e],a=i-n;if(r<=a)return n+r;r-=a}}function cc(e,t){let n=0;for(let{from:r,to:i}of e.ranges){if(t<=i){n+=t-r;break}n+=i-r}return n/e.total}function lc(e,t){for(let n of e)if(t(n))return n}const uc={toDOM(e){return e},fromDOM(e){return e},scale:1,eq(e){return e==this}};function dc(e){let t=e.facet(Oa).filter(e=>typeof e!=`function`),n=e.facet(Aa).filter(e=>typeof e!=`function`);return n.length&&t.push(F.join(n)),t}var fc=class e{constructor(e,t,n){let r=0,i=0,a=0;this.viewports=n.map(({from:n,to:i})=>{let a=t.lineAt(n,V.ByPos,e,0,0).top,o=t.lineAt(i,V.ByPos,e,0,0).bottom;return r+=o-a,{from:n,to:i,top:a,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let e of this.viewports)e.domTop=a+(e.top-i)*this.scale,a=e.domBottom=e.domTop+(e.bottom-e.top),i=e.bottom}toDOM(e){for(let t=0,n=0,r=0;;t++){let i=t<this.viewports.length?this.viewports[t]:null;if(!i||e<i.top)return r+(e-n)*this.scale;if(e<=i.bottom)return i.domTop+(e-i.top);n=i.bottom,r=i.domBottom}}fromDOM(e){for(let t=0,n=0,r=0;;t++){let i=t<this.viewports.length?this.viewports[t]:null;if(!i||e<i.domTop)return n+(e-r)/this.scale;if(e<=i.domBottom)return i.top+(e-i.domTop);n=i.bottom,r=i.domBottom}}eq(t){return t instanceof e&&this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,n)=>e.from==t.viewports[n].from&&e.to==t.viewports[n].to)}};function pc(e,t){if(t.scale==1)return e;let n=t.toDOM(e.top),r=t.toDOM(e.bottom);return new Bs(e.from,e.length,n,r-n,Array.isArray(e._content)?e._content.map(e=>pc(e,t)):e._content)}const mc=M.define({combine:e=>e.join(` `)}),hc=M.define({combine:e=>e.indexOf(!0)>-1}),gc=Or.newName(),_c=Or.newName(),vc=Or.newName(),yc={"&light":`.`+_c,"&dark":`.`+vc};function bc(e,t,n){return new Or(t,{finish(t){return/&/.test(t)?t.replace(/&\w*/,t=>{if(t==`&`)return e;if(!n||!n[t])throw RangeError(`Unsupported selector: ${t}`);return n[t]}):e+` `+t}})}const xc=bc(`.`+gc,{"&":{position:`relative !important`,boxSizing:`border-box`,"&.cm-focused":{outline:`1px dotted #212121`},display:`flex !important`,flexDirection:`column`},".cm-scroller":{display:`flex !important`,alignItems:`flex-start !important`,fontFamily:`monospace`,lineHeight:1.4,height:`100%`,overflowX:`auto`,position:`relative`,zIndex:0,overflowAnchor:`none`},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:`block`,whiteSpace:`pre`,wordWrap:`normal`,boxSizing:`border-box`,minHeight:`100%`,padding:`4px 0`,outline:`none`,"&[contenteditable=true]":{WebkitUserModify:`read-write-plaintext-only`}},".cm-lineWrapping":{whiteSpace_fallback:`pre-wrap`,whiteSpace:`break-spaces`,wordBreak:`break-word`,overflowWrap:`anywhere`,flexShrink:1},"&light .cm-content":{caretColor:`black`},"&dark .cm-content":{caretColor:`white`},".cm-line":{display:`block`,padding:`0 2px 0 6px`},".cm-layer":{userSelect:`none`,position:`absolute`,left:0,top:0,contain:`size style`,"& > *":{position:`absolute`}},"&light .cm-selectionBackground":{background:`#d9d9d9`},"&dark .cm-selectionBackground":{background:`#222`},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#d7d4f0`},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#233`},".cm-cursorLayer":{pointerEvents:`none`},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:`steps(1) cm-blink 1.2s infinite`},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:`1.2px solid black`,marginLeft:`-0.6px`,pointerEvents:`none`},".cm-cursor":{display:`none`},"&dark .cm-cursor":{borderLeftColor:`#ddd`},".cm-selectionHandle":{backgroundColor:`currentColor`,width:`1.5px`},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:`""`,backgroundColor:`inherit`,borderRadius:`50%`,width:`8px`,height:`8px`,position:`absolute`,left:`-3.25px`},".cm-selectionHandle-start::before":{top:`-8px`},".cm-selectionHandle-end::before":{bottom:`-8px`},".cm-dropCursor":{position:`absolute`},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:`block`},".cm-iso":{unicodeBidi:`isolate`},".cm-announced":{position:`fixed`,top:`-10000px`},"@media print":{".cm-announced":{display:`none`}},"&light .cm-activeLine":{backgroundColor:`#cceeff44`},"&dark .cm-activeLine":{backgroundColor:`#99eeff33`},"&light .cm-specialChar":{color:`red`},"&dark .cm-specialChar":{color:`#f78`},".cm-gutters":{flexShrink:0,display:`flex`,height:`100%`,boxSizing:`border-box`,zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:`#f5f5f5`,color:`#6c6c6c`,border:`0px solid #ddd`,"&.cm-gutters-before":{borderRightWidth:`1px`},"&.cm-gutters-after":{borderLeftWidth:`1px`}},"&dark .cm-gutters":{backgroundColor:`#333338`,color:`#ccc`},".cm-gutter":{display:`flex !important`,flexDirection:`column`,flexShrink:0,boxSizing:`border-box`,minHeight:`100%`,overflow:`hidden`},".cm-gutterElement":{boxSizing:`border-box`},".cm-lineNumbers .cm-gutterElement":{padding:`0 3px 0 5px`,minWidth:`20px`,textAlign:`right`,whiteSpace:`nowrap`},"&light .cm-activeLineGutter":{backgroundColor:`#e2f2ff`},"&dark .cm-activeLineGutter":{backgroundColor:`#222227`},".cm-panels":{boxSizing:`border-box`,position:`sticky`,left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:`#f5f5f5`,color:`black`},".cm-panels-top":{top:`0`},".cm-panels-bottom":{bottom:`0`},"&light .cm-panels-top":{borderBottom:`1px solid #ddd`},"&light .cm-panels-bottom":{borderTop:`1px solid #ddd`},"&dark .cm-panels":{backgroundColor:`#333338`,color:`white`},".cm-dialog":{padding:`2px 19px 4px 6px`,position:`relative`,"& label":{fontSize:`80%`}},".cm-dialog-close":{position:`absolute`,top:`3px`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,fontSize:`14px`,padding:`0`},".cm-tab":{display:`inline-block`,overflow:`hidden`,verticalAlign:`bottom`},".cm-widgetBuffer":{verticalAlign:`text-top`,height:`1em`,width:0,display:`inline`},".cm-placeholder":{color:`#888`,display:`inline-block`,verticalAlign:`top`,userSelect:`none`},".cm-highlightSpace":{background:`radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat`,backgroundSize:`.4em`,backgroundPosition:`calc(min(50%, 0px)) center`},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:`auto 100%`,backgroundPosition:`right 90%`,backgroundRepeat:`no-repeat`},".cm-trailingSpace":{backgroundColor:`#ff332255`},".cm-button":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,padding:`.2em 1em`,borderRadius:`1px`},"&light .cm-button":{backgroundImage:`linear-gradient(#eff1f5, #d9d9df)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#b4b4b4, #d0d3d6)`}},"&dark .cm-button":{backgroundImage:`linear-gradient(#393939, #111)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#111, #333)`}},".cm-textfield":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,border:`1px solid silver`,padding:`.2em .5em`},"&light .cm-textfield":{backgroundColor:`white`},"&dark .cm-textfield":{border:`1px solid #555`,backgroundColor:`inherit`}},yc),Sc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Cc=I.ie&&I.ie_version<=11;var wc=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new wi,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 e of t)this.queue.push(e);(I.ie&&I.ie_version<=11||I.ios&&e.composing)&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&I.android&&e.constructor.EDIT_CONTEXT!==!1&&!(I.chrome&&I.chrome_version<126)&&(this.editContext=new Oc(e),e.state.facet(xa)&&(e.contentDOM.editContext=this.editContext.editContext)),Cc&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.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(()=>{this.view.docView?.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(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.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(e=>{e.length>0&&e[e.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,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(xa)?n.root.activeElement!=this.dom:!fi(this.dom,r))return;let i=r.anchorNode&&n.docView.tile.nearest(r.anchorNode);if(i&&i.isWidget()&&i.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(I.ie&&I.ie_version<=11||I.android&&I.chrome)&&!n.state.selection.main.empty&&r.focusNode&&mi(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=ui(e.root);if(!t)return!1;let n=I.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Dc(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=fi(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Ni(this.dom,n)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(n),r&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(n.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||=this.scrollTargets.slice(0,e),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let e of this.scrollTargets)e.removeEventListener(`scroll`,this.onScroll);for(let e of this.scrollTargets=t)e.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,Sc),Cc&&this.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Cc&&this.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){if(!this.delayedAndroidKey){let e=()=>{let e=this.delayedAndroidKey;e&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&ji(this.dom,e.key,e.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}(!this.delayedAndroidKey||e==`Enter`)&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!this.delayedAndroidKey?.force})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let i of e){let e=this.readMutation(i);e&&(e.typeOver&&(r=!0),t==-1?{from:t,to:n}=e:(t=Math.min(e.from,t),n=Math.max(e.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&fi(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 i=new Uo(this.view,e,t,n);return this.view.docView.domChanged={newSel:i.newSel?i.newSel.main:null},i}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 n=this.view.state,r=Go(this.view,t);return this.view.state==n&&(t.domChanged||t.newSel&&!Zo(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 n=Tc(t,e.previousSibling||e.target.previousSibling,-1),r=Tc(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else if(e.type==`characterData`)return{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue};else return 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(xa)!=e.state.facet(xa)&&(e.view.contentDOM.editContext=e.state.facet(xa)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)==null||e.disconnect(),(t=this.gapIntersection)==null||t.disconnect(),(n=this.resizeScroll)==null||n.disconnect();for(let e of this.scrollTargets)e.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 Tc(e,t,n){for(;t;){let r=B.get(t);if(r&&r.parent==e)return r;let i=t.parentNode;t=i==e.dom?n>0?t.nextSibling:t.previousSibling:i}return null}function Ec(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.docView.domAtPos(e.state.selection.main.anchor,1);return mi(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function Dc(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Ec(e,n)}let n=null;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.contentDOM.addEventListener(`beforeinput`,r,!0),e.dom.ownerDocument.execCommand(`indent`),e.contentDOM.removeEventListener(`beforeinput`,r,!0),n?Ec(e,n):null}var Oc=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let r=e.state.selection.main,{anchor:i,head:a}=r,o=this.toEditorPos(n.updateRangeStart),s=this.toEditorPos(n.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:n.updateRangeStart,editorBase:o,drifted:!1});let c=s-o>n.text.length;o==this.from&&i<this.from?o=i:s==this.to&&i>this.to&&(s=i);let l=Jo(e.state.sliceDoc(o,s),n.text,(c?r.from:r.to)-o,c?`end`:null);if(!l){let t=j.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd));Zo(t,r)||e.dispatch({selection:t,userEvent:`select`});return}let u={from:l.from+o,to:l.toA+o,insert:k.of(n.text.slice(l.from,l.toB).split(`
743
+ `))};if((I.mac||I.android)&&u.from==a-1&&/^\. ?$/.test(n.text)&&e.contentDOM.getAttribute(`autocorrect`)==`off`&&(u={from:o,to:s,insert:k.of([n.text.replace(`.`,` `)])}),this.pendingContextChange=u,!e.state.readOnly){let t=this.to-this.from+(u.to-u.from+u.insert.length);Ko(e,u,j.single(this.toEditorPos(n.selectionStart,t),this.toEditorPos(n.selectionEnd,t)))}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,n.updateRangeStart-1),Math.min(t.text.length,n.updateRangeStart+1)))&&this.handlers.compositionend(n)},this.handlers.characterboundsupdate=n=>{let r=[],i=null;for(let t=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);t<a;t++){let n=e.coordsForChar(t);i=n&&new DOMRect(n.left,n.top,n.right-n.left,n.bottom-n.top)||i||new DOMRect,r.push(i)}t.updateCharacterBounds(n.rangeStart,r)},this.handlers.textformatupdate=t=>{let n=[];for(let e of t.getTextFormats()){let t=e.underlineStyle,r=e.underlineThickness;if(!/none/i.test(t)&&!/none/i.test(r)){let i=this.toEditorPos(e.rangeStart),a=this.toEditorPos(e.rangeEnd);if(i<a){let e=`text-decoration: underline ${/^[a-z]/.test(t)?t+` `:t==`Dashed`?`dashed `:t==`Squiggle`?`wavy `:``}${/thin/i.test(r)?1:2}px`;n.push(L.mark({attributes:{style:e}}).range(i,a))}}}e.dispatch({effects:ya.of(L.set(n))})},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:t}=this.composing;this.composing=null,t&&this.reset(e.state)}};for(let e in this.handlers)t.addEventListener(e,this.handlers[e]);this.measureReq={read:e=>{let t=ui(e.root);t&&t.rangeCount&&this.editContext.updateSelectionBounds(t.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((i,a,o,s,c)=>{if(n)return;let l=c.length-(a-i);if(r&&a>=r.to)if(r.from==i&&r.to==a&&r.insert.eq(c)){r=this.pendingContextChange=null,t+=l,this.to+=l;return}else r=null,this.revertPending(e.state);if(i+=t,a+=t,a<=this.from)this.from+=l,this.to+=l;else if(i<this.to){if(i<this.from||a>this.to||this.to-this.from+c.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(i),this.toContextPos(a),c.toString()),this.to+=l}t+=l}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(e=>!e.isUserEvent(`input.type`)&&e.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},H=class e{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={}){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:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(e=>e.forEach(e=>t(e,this)))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Mi(e.parent)||document,this.viewState=new ic(this,e.state||P.create(e)),e.scrollTo&&e.scrollTo.is(va)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ca).map(e=>new Ta(e));for(let e of this.plugins)e.update(this);this.observer=new wc(this),this.inputState=new Qo(this),this.inputState.ensureHandlers(this.plugins),this.docView=new po(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),document.fonts?.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=`refresh`,this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof Wn?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(t){if(this.updateState!=0)throw Error(`Calls to EditorView.update are not allowed while an update is in progress`);let n=!1,r=!1,i,a=this.state;for(let e of t){if(e.startState!=a)throw RangeError(`Trying to update state with a transaction that doesn't start from the previous state.`);a=e.state}if(this.destroyed){this.viewState.state=a;return}let o=this.hasFocus,s=0,c=null;t.some(e=>e.annotation(As))?(this.inputState.notifiedFocused=o,s=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=js(a,o),c||(s=1));let l=this.observer.delayedAndroidKey,u=null;if(l?(this.observer.clearDelayedAndroidKey(),u=this.observer.readChange(),(u&&!this.state.doc.eq(a.doc)||!this.state.selection.eq(a.selection))&&(u=null)):this.observer.clear(),a.facet(P.phrases)!=this.state.facet(P.phrases))return this.setState(a);i=Ra.create(this,a,t),i.flags|=s;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let n of t){if(d&&=d.map(n.changes),n.scrollIntoView){let{main:t}=n.state.selection,{x:r,y:i}=this.state.facet(e.cursorScrollMargin);d=new _a(t.empty?t:j.cursor(t.head,t.head>t.anchor?-1:1),`nearest`,`nearest`,i,r)}for(let e of n.effects)e.is(va)&&(d=e.value.clip(this.state))}this.viewState.update(i,d),this.bidiCache=jc.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),n=this.docView.update(i),this.state.facet(Ia)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(n,t.some(e=>e.isUserEvent(`select.pointer`)))}finally{this.updateState=0}if(i.startState.facet(mc)!=i.state.facet(mc)&&(this.viewState.mustMeasureContent=!0),(n||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!i.empty)for(let e of this.state.facet(la))try{e(i)}catch(e){ba(this.state,e,`update listener`)}(c||u)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),u&&!Go(this,u)&&l.force&&ji(this.contentDOM,l.key,l.keyCode)})}setState(e){if(this.updateState!=0)throw 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 e of this.plugins)e.destroy(this);this.viewState=new ic(this,e),this.plugins=e.facet(Ca).map(e=>new Ta(e)),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView.destroy(),this.docView=new po(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(Ca),n=e.state.facet(Ca);if(t!=n){let r=[];for(let i of n){let n=t.indexOf(i);if(n<0)r.push(new Ta(i));else{let t=this.plugins[n];t.mustUpdate=e,r.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let t of this.plugins)t.mustUpdate=e;for(let e=0;e<this.plugins.length;e++)this.plugins[e].update(this);t!=n&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(e){ba(this.state,e,`doc view update listener`)}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.viewState.scrollParent,r=this.viewState.getScrollOffset(),{scrollAnchorPos:i,scrollAnchorHeight:a,scaleY:o}=this.viewState;Math.abs(r-this.viewState.scrollOffset)>1&&(a=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(a<0){if(Pi(n||this.win))i=-1,a=this.viewState.heightMap.height/this.viewState.scaleY;else{let e=this.viewState.scrollAnchorAt(r);i=e.from,a=e.top}o=this.viewState.scaleY}this.updateState=1;let s=this.viewState.measure();if(!s&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(e>5){console.warn(this.measureRequests.length?`Measure loop restarted more than 5 times`:`Viewport failed to stabilize`);break}let c=[];s&4||([this.measureRequests,c]=[c,this.measureRequests]);let l=c.map(e=>{try{return e.read(this)}catch(e){return ba(this.state,e),Ac}}),u=Ra.create(this,this.state,[]),d=!1;u.flags|=s,t?t.flags|=s:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),d=this.docView.update(u),d&&this.docViewUpdate());for(let e=0;e<c.length;e++)if(l[e]!=Ac)try{let t=c[e];t.write&&t.write(l[e],this)}catch(e){ba(this.state,e)}if(d&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,a=-1;continue}else{let e=(i<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(i).top)/this.viewState.scaleY-a/o;if((e>1||e<-1)&&!(I.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(n==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){r+=e,n?i<0?n.scrollTop=n.scrollHeight:n.scrollTop+=e:this.win.scrollBy(0,e),a=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let e of this.state.facet(la))e(t)}get themeClasses(){return gc+` `+(this.state.facet(hc)?vc:_c)+` `+this.state.facet(mc)}updateAttrs(){let e=Mc(this,Ea,{class:`cm-editor`+(this.hasFocus?` cm-focused `:` `)+this.themeClasses}),t={spellcheck:`false`,autocorrect:`off`,autocapitalize:`off`,writingsuggestions:`false`,translate:`no`,contenteditable:this.state.facet(xa)?`true`:`false`,class:`cm-content`,style:`${I.tabSize}: ${this.state.tabSize}`,role:`textbox`,"aria-multiline":`true`};this.state.readOnly&&(t[`aria-readonly`]=`true`),Mc(this,Da,t);let n=this.observer.ignore(()=>{let n=$r(this.contentDOM,this.contentAttrs,t),r=$r(this.dom,this.editorAttrs,e);return n||r});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(t){let n=!0;for(let r of t)for(let t of r.effects)if(t.is(e.announce)){n&&(this.announceDOM.textContent=``),n=!1;let e=this.announceDOM.appendChild(document.createElement(`div`));e.textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(Ia);let t=this.state.facet(e.cspNonce);Or.mount(this.root,this.styleModules.concat(xc).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw 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(t=>t.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return Fo(this,e,Ao(this,e,t,n))}moveByGroup(e,t){return Fo(this,e,Ao(this,e,t,t=>jo(this,e.head,t)))}visualLineSide(e,t){let n=this.bidiSpans(e),r=this.textDirectionAt(e.from),i=n[t?n.length-1:0];return j.cursor(i.side(t,r)+e.from,i.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,n=!0){return ko(this,e,t,n)}moveVertically(e,t,n){return Fo(this,e,Mo(this,e,t,n))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let n=Lo(this,e,t);return n&&n.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),Lo(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),i=r[qi.find(r,e-n.from,-1,t)];return this.docView.coordsAt(e,t,i.dir==R.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(ma)||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>kc)return ta(e.length);let t=this.textDirectionAt(e.from),n;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Ji(r.isolates,n=Na(this,e))))return r.order;n||=Na(this,e);let r=ea(e.text,t,n);return this.bidiCache.push(new jc(e.from,e.to,t,n,!0,r)),r}get hasFocus(){return(this.dom.ownerDocument.hasFocus()||I.safari&&this.inputState?.lastContextMenu>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Oi(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 va.of(new _a(typeof e==`number`?j.cursor(e):e,t.y??`nearest`,t.x??`nearest`,t.yMargin??5,t.xMargin??5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return va.of(new _a(j.cursor(n.from),`start`,`start`,n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e==`boolean`?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return wa.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return wa.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=Or.newName(),r=[mc.of(n),Ia.of(bc(`.${n}`,e))];return t&&t.dark&&r.push(hc.of(!0)),r}static baseTheme(e){return En.lowest(Ia.of(bc(`.`+gc,e,yc)))}static findFromDOM(e){let t=e.querySelector(`.cm-content`);return(t&&B.get(t)||B.get(e))?.root?.view||null}};H.styleModule=Ia,H.inputHandler=ua,H.clipboardInputFilter=fa,H.clipboardOutputFilter=pa,H.scrollHandler=ga,H.focusChangeEffect=da,H.perLineTextDirection=ma,H.exceptionSink=ca,H.updateListener=la,H.editable=xa,H.mouseSelectionStyle=sa,H.dragMovesSelection=oa,H.clickAddsSelectionRange=aa,H.decorations=Oa,H.blockWrappers=ka,H.outerDecorations=Aa,H.atomicRanges=ja,H.bidiIsolatedRanges=Ma,H.cursorScrollMargin=M.define({combine:e=>{let t=5,n=5;for(let r of e)typeof r==`number`?t=n=r:{x:t,y:n}=r;return{x:t,y:n}}}),H.scrollMargins=Pa,H.darkTheme=hc,H.cspNonce=M.define({combine:e=>e.length?e[0]:``}),H.contentAttributes=Da,H.editorAttributes=Ea,H.lineWrapping=H.contentAttributes.of({class:`cm-lineWrapping`}),H.announce=N.define();const kc=4096,Ac={};var jc=class e{constructor(e,t,n,r,i,a){this.from=e,this.to=t,this.dir=n,this.isolates=r,this.fresh=i,this.order=a}static update(t,n){if(n.empty&&!t.some(e=>e.fresh))return t;let r=[],i=t.length?t[t.length-1].dir:R.LTR;for(let a=Math.max(0,t.length-10);a<t.length;a++){let o=t[a];o.dir==i&&!n.touchesRange(o.from,o.to)&&r.push(new e(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}};function Mc(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let t=r[i],a=typeof t==`function`?t(e):t;a&&Yr(a,n)}return n}const Nc=I.mac?`mac`:I.windows?`win`:I.linux?`linux`:`key`;function Pc(e,t){let n=e.split(/-(?!$)/),r=n[n.length-1];r==`Space`&&(r=` `);let i,a,o,s;for(let e=0;e<n.length-1;++e){let r=n[e];if(/^(cmd|meta|m)$/i.test(r))s=!0;else if(/^a(lt)?$/i.test(r))i=!0;else if(/^(c|ctrl|control)$/i.test(r))a=!0;else if(/^s(hift)?$/i.test(r))o=!0;else if(/^mod$/i.test(r))t==`mac`?s=!0:a=!0;else throw Error(`Unrecognized modifier name: `+r)}return i&&(r=`Alt-`+r),a&&(r=`Ctrl-`+r),s&&(r=`Meta-`+r),o&&(r=`Shift-`+r),r}function Fc(e,t,n){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n!==!1&&t.shiftKey&&(e=`Shift-`+e),e}const Ic=En.default(H.domEventHandlers({keydown(e,t){return Uc(zc(t.state),e,t,`editor`)}})),Lc=M.define({enables:Ic}),Rc=new WeakMap;function zc(e){let t=e.facet(Lc),n=Rc.get(t);return n||Rc.set(t,n=Vc(t.reduce((e,t)=>e.concat(t),[]))),n}let Bc=null;function Vc(e,t=Nc){let n=Object.create(null),r=Object.create(null),i=(e,t)=>{let n=r[e];if(n==null)r[e]=t;else if(n!=t)throw Error(`Key binding `+e+` is used both as a regular binding and as a multi-stroke prefix`)},a=(e,r,a,o,s)=>{let c=n[e]||(n[e]=Object.create(null)),l=r.split(/ (?!$)/).map(e=>Pc(e,t));for(let t=1;t<l.length;t++){let n=l.slice(0,t).join(` `);i(n,!0),c[n]||(c[n]={preventDefault:!0,stopPropagation:!1,run:[t=>{let r=Bc={view:t,prefix:n,scope:e};return setTimeout(()=>{Bc==r&&(Bc=null)},4e3),!0}]})}let u=l.join(` `);i(u,!1);let d=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(c._any?.run)?.slice()||[]});a&&d.run.push(a),o&&(d.preventDefault=!0),s&&(d.stopPropagation=!0)};for(let r of e){let e=r.scope?r.scope.split(` `):[`editor`];if(r.any)for(let t of e){let e=n[t]||(n[t]=Object.create(null));e._any||={preventDefault:!1,stopPropagation:!1,run:[]};let{any:i}=r;for(let t in e)e[t].run.push(e=>i(e,Hc))}let i=r[t]||r.key;if(i)for(let t of e)a(t,i,r.run,r.preventDefault,r.stopPropagation),r.shift&&a(t,`Shift-`+i,r.shift,r.preventDefault,r.stopPropagation)}return n}let Hc=null;function Uc(e,t,n,r){Hc=t;let i=Lr(t),a=rn(nn(i,0))==i.length&&i!=` `,o=``,s=!1,c=!1,l=!1;Bc&&Bc.view==n&&Bc.scope==r&&(o=Bc.prefix+` `,is.indexOf(t.keyCode)<0&&(c=!0,Bc=null));let u=new Set,d=e=>{if(e){for(let t of e.run)if(!u.has(t)&&(u.add(t),t(n)))return e.stopPropagation&&(l=!0),!0;e.preventDefault&&(e.stopPropagation&&(l=!0),c=!0)}return!1},f=e[r],p,m;return f&&(d(f[o+Fc(i,t,!a)])?s=!0:a&&(t.altKey||t.metaKey||t.ctrlKey)&&!(I.windows&&t.ctrlKey&&t.altKey)&&!(I.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(p=jr[t.keyCode])&&p!=i?(d(f[o+Fc(p,t,!0)])||t.shiftKey&&(m=Mr[t.keyCode])!=i&&m!=p&&d(f[o+Fc(m,t,!1)]))&&(s=!0):a&&t.shiftKey&&d(f[o+Fc(i,t,!0)])&&(s=!0),!s&&d(f._any)&&(s=!0)),c&&(s=!0),s&&l&&t.stopPropagation(),Hc=null,s}var Wc=class e{constructor(e,t,n,r,i){this.className=e,this.left=t,this.top=n,this.width=r,this.height=i}draw(){let e=document.createElement(`div`);return e.className=this.className,this.adjust(e),e}update(e,t){return t.className==this.className?(this.adjust(e),!0):!1}adjust(e){e.style.left=this.left+`px`,e.style.top=this.top+`px`,this.width!=null&&(e.style.width=this.width+`px`),e.style.height=this.height+`px`}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(t,n,r){if(r.empty){let i=t.coordsAtPos(r.head,r.assoc||1);if(!i)return[];let a=Gc(t);return[new e(n,i.left-a.left,i.top-a.top,null,i.bottom-i.top)]}else return qc(t,n,r)}};function Gc(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==R.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function Kc(e,t,n,r){let i=e.coordsAtPos(t,n*2);if(!i)return r;let a=e.dom.getBoundingClientRect(),o=(i.top+i.bottom)/2,s=e.posAtCoords({x:a.left+1,y:o}),c=e.posAtCoords({x:a.right-1,y:o});return s==null||c==null?r:{from:Math.max(r.from,Math.min(s,c)),to:Math.min(r.to,Math.max(s,c))}}function qc(e,t,n){if(n.to<=e.viewport.from||n.from>=e.viewport.to)return[];let r=Math.max(n.from,e.viewport.from),i=Math.min(n.to,e.viewport.to),a=e.textDirection==R.LTR,o=e.contentDOM,s=o.getBoundingClientRect(),c=Gc(e),l=o.querySelector(`.cm-line`),u=l&&window.getComputedStyle(l),d=s.left+(u?parseInt(u.paddingLeft)+Math.min(0,parseInt(u.textIndent)):0),f=s.right-(u?parseInt(u.paddingRight):0),p=Oo(e,r,1),m=Oo(e,i,-1),h=p.type==ni.Text?p:null,g=m.type==ni.Text?m:null;if(h&&(e.lineWrapping||p.widgetLineBreaks)&&(h=Kc(e,r,1,h)),g&&(e.lineWrapping||m.widgetLineBreaks)&&(g=Kc(e,i,-1,g)),h&&g&&h.from==g.from&&h.to==g.to)return v(y(n.from,n.to,h));{let t=h?y(n.from,null,h):b(p,!1),r=g?y(null,n.to,g):b(m,!0),i=[];return(h||p).to<(g||m).from-(h&&g?1:0)||p.widgetLineBreaks>1&&t.bottom+e.defaultLineHeight/2<r.top?i.push(_(d,t.bottom,f,r.top)):t.bottom<r.top&&e.elementAtHeight((t.bottom+r.top)/2).type==ni.Text&&(t.bottom=r.top=(t.bottom+r.top)/2),v(t).concat(i).concat(v(r))}function _(e,n,r,i){return new Wc(t,e-c.left,n-c.top,Math.max(0,r-e),i-n)}function v({top:e,bottom:t,horizontal:n}){let r=[];for(let i=0;i<n.length;i+=2)r.push(_(n[i],e,n[i+1],t));return r}function y(t,n,r){let i=1e9,o=-1e9,s=[];function c(t,n,c,l,u){let p=e.coordsAtPos(t,t==r.to?-2:2),m=e.coordsAtPos(c,c==r.from?2:-2);!p||!m||(i=Math.min(p.top,m.top,i),o=Math.max(p.bottom,m.bottom,o),u==R.LTR?s.push(a&&n?d:p.left,a&&l?f:m.right):s.push(!a&&l?d:m.left,!a&&n?f:p.right))}let l=t??r.from,u=n??r.to;for(let r of e.visibleRanges)if(r.to>l&&r.from<u)for(let i=Math.max(r.from,l),a=Math.min(r.to,u);;){let r=e.state.doc.lineAt(i);for(let o of e.bidiSpans(r)){let e=o.from+r.from,s=o.to+r.from;if(e>=a)break;s>i&&c(Math.max(e,i),t==null&&e<=l,Math.min(s,a),n==null&&s>=u,o.dir)}if(i=r.to+1,i>=a)break}return s.length==0&&c(l,t==null,u,n==null,e.textDirection),{top:i,bottom:o,horizontal:s}}function b(e,t){let n=s.top+(t?e.top:e.bottom);return{top:n,bottom:n,horizontal:[]}}}function Jc(e,t){return e.constructor==t.constructor&&e.eq(t)}var Yc=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement(`div`)),this.dom.classList.add(`cm-layer`),t.above&&this.dom.classList.add(`cm-layer-above`),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute(`aria-hidden`,`true`),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Xc)!=e.state.facet(Xc)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(Xc);for(;t<n.length&&n[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((e,t)=>!Jc(e,this.drawn[t]))){let t=this.dom.firstChild,n=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[n].constructor&&r.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(r.draw(),t);for(;t;){let e=t.nextSibling;t.remove(),t=e}this.drawn=e,I.webkit&&(this.dom.style.display=this.dom.firstChild?``:`none`)}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}};const Xc=M.define();function Zc(e){return[wa.define(t=>new Yc(t,e)),Xc.of(e)]}const Qc=M.define({combine(e){return ir(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function $c(e={}){return[Qc.of(e),tl,rl,al,ha.of(!0)]}function el(e){return e.startState.facet(Qc)!=e.state.facet(Qc)}const tl=Zc({above:!0,markers(e){let{state:t}=e,n=t.facet(Qc),r=[];for(let i of t.selection.ranges){let a=i==t.selection.main;if(i.empty||n.drawRangeCursor&&!(a&&I.ios&&n.iosSelectionHandles)){let t=a?`cm-cursor cm-cursor-primary`:`cm-cursor cm-cursor-secondary`,n=i.empty?i:j.cursor(i.head,i.assoc);for(let i of Wc.forRange(e,t,n))r.push(i)}}return r},update(e,t){e.transactions.some(e=>e.selection)&&(t.style.animationName=t.style.animationName==`cm-blink`?`cm-blink2`:`cm-blink`);let n=el(e);return n&&nl(e.state,t),e.docChanged||e.selectionSet||n},mount(e,t){nl(t.state,e)},class:`cm-cursorLayer`});function nl(e,t){t.style.animationDuration=e.facet(Qc).cursorBlinkRate+`ms`}const rl=Zc({above:!1,markers(e){let t=[],{main:n,ranges:r}=e.state.selection;for(let n of r)if(!n.empty)for(let r of Wc.forRange(e,`cm-selectionBackground`,n))t.push(r);if(I.ios&&!n.empty&&e.state.facet(Qc).iosSelectionHandles){for(let r of Wc.forRange(e,`cm-selectionHandle cm-selectionHandle-start`,j.cursor(n.from,1)))t.push(r);for(let r of Wc.forRange(e,`cm-selectionHandle cm-selectionHandle-end`,j.cursor(n.to,1)))t.push(r)}return t},update(e,t){return e.docChanged||e.selectionSet||e.viewportChanged||el(e)},class:`cm-selectionLayer`}),il=I.gecko&&I.gecko_version==153?`#ffffff01`:`transparent`,al=En.highest(H.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${il} !important`},caretColor:`transparent !important`},".cm-content":{caretColor:`transparent !important`,"& :focus":{caretColor:`initial !important`,"&::selection, & ::selection":{backgroundColor:`Highlight !important`}}}}));/x/.unicode;var ol=class extends ti{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement(`span`);return t.className=`cm-placeholder`,t.style.pointerEvents=`none`,t.appendChild(typeof this.content==`string`?document.createTextNode(this.content):typeof this.content==`function`?this.content(e):this.content.cloneNode(!0)),t.setAttribute(`aria-hidden`,`true`),t}coordsAt(e){let t=e.firstChild?pi(e.firstChild):[];if(!t.length)return null;let n=window.getComputedStyle(e.parentNode),r=yi(t[0],n.direction!=`rtl`),i=parseInt(n.lineHeight);return r.bottom-r.top>i*1.5?{left:r.left,right:r.right,top:r.top,bottom:r.top+i}:r}ignoreEvent(){return!1}};function sl(e){let t=wa.fromClass(class{constructor(t){this.view=t,this.placeholder=e?L.set([L.widget({widget:new ol(e),side:1}).range(0)]):L.none}get decorations(){return this.view.state.doc.length?L.none:this.placeholder}},{decorations:e=>e.decorations});return typeof e==`string`?[t,H.contentAttributes.of({"aria-placeholder":e})]:t}var cl=class extends ar{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};cl.prototype.elementClass=``,cl.prototype.toDOM=void 0,cl.prototype.mapMode=on.TrackBefore,cl.prototype.startSide=cl.prototype.endSide=-1,cl.prototype.point=!0;const ll=1024;let ul=0;var dl=class{constructor(e,t){this.from=e,this.to=t}},U=class{constructor(e={}){this.id=ul++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw Error(`This node type doesn't define a deserialize function`)}),this.combine=e.combine||null}add(e){if(this.perNode)throw RangeError(`Can't add per-node props to node types`);return typeof e!=`function`&&(e=W.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};U.closedBy=new U({deserialize:e=>e.split(` `)}),U.openedBy=new U({deserialize:e=>e.split(` `)}),U.group=new U({deserialize:e=>e.split(` `)}),U.isolate=new U({deserialize:e=>{if(e&&e!=`rtl`&&e!=`ltr`&&e!=`auto`)throw RangeError(`Invalid value for isolate: `+e);return e||`auto`}}),U.contextHash=new U({perNode:!0}),U.lookAhead=new U({perNode:!0}),U.mounted=new U({perNode:!0});var fl=class{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[U.mounted.id]}};const pl=Object.create(null);var W=class e{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(t){let n=t.props&&t.props.length?Object.create(null):pl,r=!!t.top|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new e(t.name||``,n,t.id,r);if(t.props){for(let e of t.props)if(Array.isArray(e)||(e=e(i)),e){if(e[0].perNode)throw RangeError(`Can't store a per-node prop on a node type`);n[e[0].id]=e[1]}}return i}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(U.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(` `))t[r]=e[n];return e=>{for(let n=e.prop(U.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}};W.none=new W(``,Object.create(null),0,8);var ml=class e{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw RangeError(`Node type ids should correspond to array positions when creating a node set`)}extend(...t){let n=[];for(let e of this.types){let r=null;for(let n of t){let t=n(e);if(t){r||=Object.assign({},e.props);let n=t[1],i=t[0];i.combine&&i.id in r&&(n=i.combine(r[i.id],n)),r[i.id]=n}}n.push(r?new W(e.name,r,e.id,e.flags):e)}return new e(n)}};const hl=new WeakMap,gl=new WeakMap;var G;(function(e){e[e.ExcludeBuffers=1]=`ExcludeBuffers`,e[e.IncludeAnonymous=2]=`IncludeAnonymous`,e[e.IgnoreMounts=4]=`IgnoreMounts`,e[e.IgnoreOverlays=8]=`IgnoreOverlays`,e[e.EnterBracketed=16]=`EnterBracketed`})(G||={});var K=class e{constructor(e,t,n,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props[typeof e==`number`?e:e.id]=t}}toString(){let e=fl.get(this);if(e&&!e.overlay)return e.tree.toString();let t=``;for(let e of this.children){let n=e.toString();n&&(t&&(t+=`,`),t+=n)}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 Al(this.topNode,e)}cursorAt(e,t=0,n=0){let r=new Al(hl.get(this)||this.topNode);return r.moveTo(e,t),hl.set(this,r._tree),r}get topNode(){return new Sl(this,0,0,null)}resolve(e,t=0){let n=bl(hl.get(this)||this.topNode,e,t,!1);return hl.set(this,n),n}resolveInner(e,t=0){let n=bl(gl.get(this)||this.topNode,e,t,!0);return gl.set(this,n),n}resolveStack(e,t=0){return kl(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:i=this.length}=e,a=e.mode||0,o=(a&G.IncludeAnonymous)>0;for(let e=this.cursor(a|G.IncludeAnonymous);;){let a=!1;if(e.from<=i&&e.to>=r&&(!o&&e.type.isAnonymous||t(e)!==!1)){if(e.firstChild())continue;a=!0}for(;a&&n&&(o||!e.type.isAnonymous)&&n(e),!e.nextSibling();){if(!e.parent())return;a=!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(t={}){return this.children.length<=8?this:Fl(W.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new e(this.type,t,n,r,this.propValues),t.makeTree||((t,n,r)=>new e(W.none,t,n,r)))}static build(e){return Ml(e)}};K.empty=new K(W.none,[],[],0);var _l=class e{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 e(this.buffer,this.index)}},vl=class e{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return W.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(`,`)}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),e+=4,n==e)return i;let a=[];for(;e<n;)a.push(this.childString(e)),e=this.buffer[e+3];return i+`(`+a.join(`,`)+`)`}findChild(e,t,n,r,i){let{buffer:a}=this,o=-1;for(let s=e;s!=t&&!(yl(i,r,a[s+1],a[s+2])&&(o=s,n>0));s=a[s+3]);return o}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let e=t,s=0;e<n;){a[s++]=i[e++],a[s++]=i[e++]-r;let n=a[s++]=i[e++]-r;a[s++]=i[e++]-t,o=Math.max(o,n)}return new e(a,o,this.set)}};function yl(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function bl(e,t,n,r){for(;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!r&&e instanceof Sl&&e.index<0?null:e.parent;if(!t)return e;e=t}let i=r?0:G.IgnoreOverlays;if(r)for(let r=e,a=r.parent;a;r=a,a=r.parent)r instanceof Sl&&r.index<0&&a.enter(t,n,i)?.from!=r.from&&(e=a);for(;;){let r=e.enter(t,n,i);if(!r)return e;e=r}}var xl=class{cursor(e=0){return new Al(this,e)}getChild(e,t=null,n=null){let r=Cl(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Cl(this,e,t,n)}resolve(e,t=0){return bl(this,e,t,!1)}resolveInner(e,t=0){return bl(this,e,t,!0)}matchContext(e){return wl(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(n=t,t=e.prevSibling):t=e}return n}get node(){return this}get next(){return this.parent}},Sl=class e extends xl{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:s,positions:c}=o._tree,l=n>0?s.length:-1;t!=l;t+=n){let l=s[t],u=c[t]+o.from,d;if(!(!(a&G.EnterBracketed&&l instanceof K&&(d=fl.get(l))&&!d.overlay&&d.bracketed&&r>=u&&r<=u+l.length)&&!yl(i,r,u,u+l.length))){if(l instanceof vl){if(a&G.ExcludeBuffers)continue;let e=l.findChild(0,l.buffer.length,n,r-u,i);if(e>-1)return new El(new Tl(o,l,t,u),null,e)}else if(a&G.IncludeAnonymous||!l.type.isAnonymous||jl(l)){let s;if(!(a&G.IgnoreMounts)&&(s=fl.get(l))&&!s.overlay)return new e(s.tree,u,t,o);let c=new e(l,u,t,o);return a&G.IncludeAnonymous||!c.type.isAnonymous?c:c.nextChild(n<0?l.children.length-1:0,n,r,i,a)}}}if(a&G.IncludeAnonymous||!o.type.isAnonymous||(t=o.index>=0?o.index+n:n<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(t,n,r=0){let i;if(!(r&G.IgnoreOverlays)&&(i=fl.get(this._tree))&&i.overlay){let a=t-this.from,o=r&G.EnterBracketed&&i.bracketed;for(let{from:t,to:r}of i.overlay)if((n>0||o?t<=a:t<a)&&(n<0||o?r>=a:r>a))return new e(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}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 Cl(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let e=!1;!e;)if(e=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function wl(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}var Tl=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},El=class e extends xl{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new e(this.context,this,a)}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(t,n,r=0){if(r&G.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new e(this.context,this,a)}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:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new e(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new e(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let a=n.buffer[this.index+1];e.push(n.slice(r,i,a)),t.push(0)}return new K(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Dl(e){if(!e.length)return null;let t=0,n=e[0];for(let r=1;r<e.length;r++){let i=e[r];(i.from>n.from||i.to<n.to)&&(n=i,t=r)}let r=n instanceof Sl&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new Ol(i,n)}var Ol=class{constructor(e,t){this.heads=e,this.node=t}get next(){return Dl(this.heads)}};function kl(e,t,n){let r=e.resolveInner(t,n),i=null;for(let e=r instanceof Sl?r:r.context.parent;e;e=e.parent)if(e.index<0){let a=e.parent;(i||=[r]).push(a.resolve(t,n)),e=a}else{let a=fl.get(e.tree);if(a&&a.overlay&&a.overlay[0].from<=t&&a.overlay[a.overlay.length-1].to>=t){let o=new Sl(a.tree,a.overlay[0].from+e.from,-1,e);(i||=[r]).push(bl(o,t,n,!1))}}return i?Dl(i):r}var Al=class{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&~G.EnterBracketed,e instanceof Sl)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof Sl?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&G.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&G.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&G.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(r.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];if(this.mode&G.IncludeAnonymous||e instanceof vl||!e.type.isAnonymous||jl(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)scan:for(let r=this.index,i=this.stack.length;i>=0;){for(let a=e;a;a=a._parent)if(a.index==r){if(r==this.index)return a;t=a,n=i+1;break scan}r=this.stack[--i]}for(let e=n;e<this.stack.length;e++)t=new El(this.buffer,t,this.stack[e]);return this.bufferNode=new El(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return wl(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return wl(this._tree,e,r);let a=n[t.buffer[this.stack[i]]];if(!a.isAnonymous){if(e[r]&&e[r]!=a.name)return!1;r--}}return!0}};function jl(e){return e.children.some(e=>e instanceof vl||!e.type.isAnonymous||jl(e))}function Ml(e){let{buffer:t,nodeSet:n,maxBufferLength:r=ll,reused:i=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(t)?new _l(t,t.length):t,s=n.types,c=0,l=0;function u(e,t,_,v,y,b){let{id:x,start:S,end:C,size:ee}=o,te=l,ne=c;if(ee<0)if(o.next(),ee==-1){let t=i[x];_.push(t),v.push(S-e);return}else if(ee==-3){c=x;return}else if(ee==-4){l=x;return}else throw RangeError(`Unrecognized record size: ${ee}`);let w=s[x],re,T,ie=S-e;if(C-S<=r&&(T=h(o.pos-t,y))){let t=new Uint16Array(T.size-T.skip),r=o.pos-T.size,i=t.length;for(;o.pos>r;)i=g(T.start,t,i);re=new vl(t,C-T.start,n),ie=T.start-e}else{let e=o.pos-ee;o.next();let t=[],n=[],i=x>=a?x:-1,s=0,c=C;for(;o.pos>e;)i>=0&&o.id==i&&o.size>=0?(o.end<=c-r&&(p(t,n,S,s,o.end,c,i,te,ne),s=t.length,c=o.end),o.next()):b>2500?d(S,e,t,n):u(S,e,t,n,i,b+1);if(i>=0&&s>0&&s<t.length&&p(t,n,S,s,S,c,i,te,ne),t.reverse(),n.reverse(),i>-1&&s>0){let e=f(w,ne);re=Fl(w,t,n,0,t.length,0,C-S,e,e)}else re=m(w,t,n,C-S,te-C,ne)}_.push(re),v.push(ie)}function d(e,t,i,a){let s=[],c=0,l=-1;for(;o.pos>t;){let{id:e,start:t,end:n,size:i}=o;if(i>4)o.next();else if(l>-1&&t<l)break;else l<0&&(l=n-r),s.push(e,t,n),c++,o.next()}if(c){let t=new Uint16Array(c*4),r=s[s.length-2];for(let e=s.length-3,n=0;e>=0;e-=3)t[n++]=s[e],t[n++]=s[e+1]-r,t[n++]=s[e+2]-r,t[n++]=n;i.push(new vl(t,s[2]-r,n)),a.push(r-e)}}function f(e,t){return(n,r,i)=>{let a=0,o=n.length-1,s,c;if(o>=0&&(s=n[o])instanceof K){if(!o&&s.type==e&&s.length==i)return s;(c=s.prop(U.lookAhead))&&(a=r[o]+s.length+c)}return m(e,n,r,i,a,t)}}function p(e,t,r,i,a,o,s,c,l){let u=[],d=[];for(;e.length>i;)u.push(e.pop()),d.push(t.pop()+r-a);e.push(m(n.types[s],u,d,o-a,c-o,l)),t.push(a-r)}function m(e,t,n,r,i,a,o){if(a){let e=[U.contextHash,a];o=o?[e].concat(o):[e]}if(i>25){let e=[U.lookAhead,i];o=o?[e].concat(o):[e]}return new K(e,t,n,r,o)}function h(e,t){let n=o.fork(),i=0,s=0,c=0,l=n.end-r,u={size:0,start:0,skip:0};scan:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){u.size=i,u.start=s,u.skip=c,c+=4,i+=4,n.next();continue}let o=n.pos-e;if(e<0||o<r||n.start<l)break;let d=n.id>=a?4:0,f=n.start;for(n.next();n.pos>o;){if(n.size<0)if(n.size==-3||n.size==-4)d+=4;else break scan;else n.id>=a&&(d+=4);n.next()}s=f,i+=e,c+=d}return(t<0||i==e)&&(u.size=i,u.start=s,u.skip=c),u.size>4?u:void 0}function g(e,t,n){let{id:r,start:i,end:s,size:u}=o;if(o.next(),u>=0&&r<a){let a=n;if(u>4){let r=o.pos-(u-4);for(;o.pos>r;)n=g(e,t,n)}t[--n]=a,t[--n]=s-e,t[--n]=i-e,t[--n]=r}else u==-3?c=r:u==-4&&(l=r);return n}let _=[],v=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,_,v,-1,0);let y=e.length??(_.length?v[0]+_[0].length:0);return new K(s[e.topID],_.reverse(),v.reverse(),y)}const Nl=new WeakMap;function Pl(e,t){if(!e.isAnonymous||t instanceof vl||t.type!=e)return 1;let n=Nl.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof K)){n=1;break}n+=Pl(e,r)}Nl.set(t,n)}return n}function Fl(e,t,n,r,i,a,o,s,c){let l=0;for(let n=r;n<i;n++)l+=Pl(e,t[n]);let u=Math.ceil(l*1.5/8),d=[],f=[];function p(t,n,r,i,o){for(let s=r;s<i;){let r=s,l=n[s],m=Pl(e,t[s]);for(s++;s<i;s++){let n=Pl(e,t[s]);if(m+n>=u)break;m+=n}if(s==r+1){if(m>u){let e=t[r];p(e.children,e.positions,0,e.children.length,n[r]+o);continue}d.push(t[r])}else{let i=n[s-1]+t[s-1].length-l;d.push(Fl(e,t,n,r,s,l,i,null,c))}f.push(l+o-a)}}return p(t,n,r,i,0),(s||c)(d,f,o)}var Il=class{constructor(){this.map=new WeakMap}setBuffer(e,t,n){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,n)}getBuffer(e,t){let n=this.map.get(e);return n&&n.get(t)}set(e,t){e instanceof El?this.setBuffer(e.context.buffer,e.index,t):e instanceof Sl&&this.map.set(e.tree,t)}get(e){return e instanceof El?this.getBuffer(e.context.buffer,e.index):e instanceof Sl?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)}},Ll=class e{constructor(e,t,n,r,i=!1,a=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=!!i|(a?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new e(0,t.length,t,0,!1,r)];for(let e of n)e.to>t.length&&i.push(e);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let s=0,c=0,l=0;;s++){let u=s<n.length?n[s]:null,d=u?u.fromA:1e9;if(d-c>=r)for(;o&&o.from<d;){let n=o;if(c>=n.from||d<=n.to||l){let t=Math.max(n.from,c)-l,r=Math.min(n.to,d)-l;n=t>=r?null:new e(t,r,n.tree,n.offset+l,s>0,!!u)}if(n&&i.push(n),o.to>d)break;o=a<t.length?t[a++]:null}if(!u)break;c=u.toA,l=u.toA-u.toB}return i}},Rl=class{startParse(e,t,n){return typeof e==`string`&&(e=new zl(e)),n=n?n.length?n.map(e=>new dl(e.from,e.to)):[new dl(0,0)]:[new dl(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let e=r.advance();if(e)return e}}},zl=class{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 Bl(e){return(t,n,r,i)=>new Gl(t,e,n,r,i)}var Vl=class{constructor(e,t,n,r,i,a){this.parser=e,this.parse=t,this.overlay=n,this.bracketed=r,this.target=i,this.from=a}};function Hl(e){if(!e.length||e.some(e=>e.from>=e.to))throw RangeError(`Invalid inner parse ranges given: `+JSON.stringify(e))}var Ul=class{constructor(e,t,n,r,i,a,o,s){this.parser=e,this.predicate=t,this.mounts=n,this.index=r,this.start=i,this.bracketed=a,this.target=o,this.prev=s,this.depth=0,this.ranges=[]}};const Wl=new U({perNode:!0});var Gl=class{constructor(e,t,n,r,i){this.nest=t,this.input=n,this.fragments=r,this.ranges=i,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let e=this.baseParse.advance();if(!e)return null;if(this.baseParse=null,this.baseTree=e,this.startInner(),this.stoppedAt!=null)for(let e of this.inner)e.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let e=this.baseTree;return this.stoppedAt!=null&&(e=new K(e.type,e.children,e.positions,e.length,e.propValues.concat([[Wl,this.stoppedAt]]))),e}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let n=Object.assign(Object.create(null),e.target.props);n[U.mounted.id]=new fl(t,e.overlay,e.parser,e.bracketed),e.target.props=n}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Xl(this.fragments),t=null,n=null,r=new Al(new Sl(this.baseTree,this.ranges[0].from,0,null),G.IncludeAnonymous|G.IgnoreMounts);scan:for(let i,a;;){let o=!0,s;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)o=!1;else if(e.hasNode(r)){if(t){let e=t.mounts.find(e=>e.frag.from<=r.from&&e.frag.to>=r.to&&e.mount.overlay);if(e)for(let n of e.mount.overlay){let i=n.from+e.pos,a=n.to+e.pos;i>=r.from&&a<=r.to&&!t.ranges.some(e=>e.from<a&&e.to>i)&&t.ranges.push({from:i,to:a})}}o=!1}else if(n&&(a=Kl(n.ranges,r.from,r.to)))o=a!=2;else if(!r.type.isAnonymous&&(i=this.nest(r,this.input))&&(r.from<r.to||!i.overlay)){r.tree||(Jl(r),t&&t.depth++,n&&n.depth++);let a=e.findMounts(r.from,i.parser);if(typeof i.overlay==`function`)t=new Ul(i.parser,i.overlay,a,this.inner.length,r.from,!!i.bracketed,r.tree,t);else{let e=Zl(this.ranges,i.overlay||(r.from<r.to?[new dl(r.from,r.to)]:[]));e.length&&Hl(e),(e.length||!i.overlay)&&this.inner.push(new Vl(i.parser,e.length?i.parser.startParse(this.input,$l(a,e),e):i.parser.startParse(``),i.overlay?i.overlay.map(e=>new dl(e.from-r.from,e.to-r.from)):null,!!i.bracketed,r.tree,e.length?e[0].from:r.from)),i.overlay?e.length&&(n={ranges:e,depth:0,prev:n}):o=!1}}else if(t&&(s=t.predicate(r))&&(s===!0&&(s=new dl(r.from,r.to)),s.from<s.to)){let e=t.ranges.length-1;e>=0&&t.ranges[e].to==s.from?t.ranges[e]={from:t.ranges[e].from,to:s.to}:t.ranges.push(s)}if(o&&r.firstChild())t&&t.depth++,n&&n.depth++;else for(;!r.nextSibling();){if(!r.parent())break scan;if(t&&!--t.depth){let e=Zl(this.ranges,t.ranges);e.length&&(Hl(e),this.inner.splice(t.index,0,new Vl(t.parser,t.parser.startParse(this.input,$l(t.mounts,e),e),t.ranges.map(e=>new dl(e.from-t.start,e.to-t.start)),t.bracketed,t.target,e[0].from))),t=t.prev}n&&!--n.depth&&(n=n.prev)}}}};function Kl(e,t,n){for(let r of e){if(r.from>=n)break;if(r.to>t)return r.from<=t&&r.to>=n?2:1}return 0}function ql(e,t,n,r,i,a){if(t<n){let o=e.buffer[t+1];r.push(e.slice(t,n,o)),i.push(o-a)}}function Jl(e){let{node:t}=e,n=[],r=t.context.buffer;do n.push(e.index),e.parent();while(!e.tree);let i=e.tree,a=i.children.indexOf(r),o=i.children[a],s=o.buffer,c=[a];function l(e,r,i,a,u,d){let f=n[d],p=[],m=[];ql(o,e,f,p,m,a);let h=s[f+1],g=s[f+2];c.push(p.length);let _=d?l(f+4,s[f+3],o.set.types[s[f]],h,g-h,d-1):t.toTree();return p.push(_),m.push(h-a),ql(o,s[f+3],r,p,m,a),new K(i,p,m,u)}i.children[a]=l(0,s.length,W.none,0,o.length,n.length-1);for(let t of c){let n=e.tree.children[t],r=e.tree.positions[t];e.yield(new Sl(n,r+e.from,t,e._tree))}}var Yl=class{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(G.IncludeAnonymous|G.IgnoreMounts)}moveTo(e){let{cursor:t}=this,n=e-this.offset;for(;!this.done&&t.from<n;)if(!(t.to>=e&&t.enter(n,1,G.IgnoreOverlays|G.ExcludeBuffers)))if(t.to<=e)t.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof K)t=t.children[0];else break}return!1}},Xl=class{constructor(e){if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let t=this.curFrag=e[0];this.curTo=t.tree.prop(Wl)??t.to,this.inner=new Yl(t.tree,-t.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(){if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=e.tree.prop(Wl)??e.to,this.inner=new Yl(e.tree,-e.offset)}}findMounts(e,t){let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let e=this.inner.cursor.node;e;e=e.parent){let r=e.tree?.prop(U.mounted);if(r&&r.parser==t)for(let t=this.fragI;t<this.fragments.length;t++){let i=this.fragments[t];if(i.from>=e.to)break;i.tree==this.curFrag.tree&&n.push({frag:i,pos:e.from-i.offset,mount:r})}}}return n}};function Zl(e,t){let n=null,r=t;for(let i=1,a=0;i<e.length;i++){let o=e[i-1].to,s=e[i].from;for(;a<r.length;a++){let e=r[a];if(e.from>=s)break;e.to<=o||(n||(r=n=t.slice()),e.from<o?(n[a]=new dl(e.from,o),e.to>s&&n.splice(a+1,0,new dl(s,e.to))):e.to>s?n[a--]=new dl(s,e.to):n.splice(a--,1))}}return r}function Ql(e,t,n,r){let i=0,a=0,o=!1,s=!1,c=-1e9,l=[];for(;;){let u=i==e.length?1e9:o?e[i].to:e[i].from,d=a==t.length?1e9:s?t[a].to:t[a].from;if(o!=s){let e=Math.max(c,n),t=Math.min(u,d,r);e<t&&l.push(new dl(e,t))}if(c=Math.min(u,d),c==1e9)break;u==c&&(o?(o=!1,i++):o=!0),d==c&&(s?(s=!1,a++):s=!0)}return l}function $l(e,t){let n=[];for(let{pos:r,mount:i,frag:a}of e){let e=r+(i.overlay?i.overlay[0].from:0),o=e+i.tree.length,s=Math.max(a.from,e),c=Math.min(a.to,o);if(i.overlay){let o=Ql(t,i.overlay.map(e=>new dl(e.from+r,e.to+r)),s,c);for(let t=0,r=s;;t++){let s=t==o.length,l=s?c:o[t].from;if(l>r&&n.push(new Ll(r,l,i.tree,-e,a.from>=r||a.openStart,a.to<=l||a.openEnd)),s)break;r=o[t].to}}else n.push(new Ll(s,c,i.tree,-e,a.from>=e||a.openStart,a.to<=o||a.openEnd))}return n}let eu=0;var tu=class e{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=eu++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(t,n){let r=typeof t==`string`?t:`?`;if(t instanceof e&&(n=t),n?.base)throw Error(`Can not derive from a modified tag`);let i=new e(r,[],null,[]);if(i.set.push(i),n)for(let e of n.set)i.set.push(e);return i}static defineModifier(e){let t=new ru(e);return e=>e.modified.indexOf(t)>-1?e:ru.get(e.base||e,e.modified.concat(t).sort((e,t)=>e.id-t.id))}};let nu=0;var ru=class e{constructor(e){this.name=e,this.instances=[],this.id=nu++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(e=>e.base==t&&iu(n,e.modified));if(r)return r;let i=[],a=new tu(t.name,i,t,n);for(let e of n)e.instances.push(a);let o=au(n);for(let n of t.set)if(!n.modified.length)for(let t of o)i.push(e.get(n,t));return a}};function iu(e,t){return e.length==t.length&&e.every((e,n)=>e==t[n])}function au(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,i=t.length;r<i;r++)t.push(t[r].concat(e[n]));return t.sort((e,t)=>t.length-e.length)}function ou(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let e of n.split(` `))if(e){let n=[],i=2,a=e;for(let t=0;;){if(a==`...`&&t>0&&t+3==e.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!r)throw RangeError(`Invalid path: `+e);if(n.push(r[0]==`*`?``:r[0][0]==`"`?JSON.parse(r[0]):r[0]),t+=r[0].length,t==e.length)break;let o=e[t++];if(t==e.length&&o==`!`){i=0;break}if(o!=`/`)throw RangeError(`Invalid path: `+e);a=e.slice(t)}let o=n.length-1,s=n[o];if(!s)throw RangeError(`Invalid path: `+e);t[s]=new cu(r,i,o>0?n.slice(0,o):null).sort(t[s])}}return su.add(t)}const su=new U({combine(e,t){let n,r,i;for(;e||t;){if(!e||t&&e.depth>=t.depth?(i=t,t=t.next):(i=e,e=e.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let a=new cu(i.tags,i.mode,i.context);n?n.next=a:r=a,n=a}return r}});var cu=class{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};cu.empty=new cu([],2,null);function lu(e,t){let n=Object.create(null);for(let t of e)if(!Array.isArray(t.tag))n[t.tag.id]=t.class;else for(let e of t.tag)n[e.id]=t.class;let{scope:r,all:i=null}=t||{};return{style:e=>{let t=i;for(let r of e)for(let e of r.set){let r=n[e.id];if(r){t=t?t+` `+r:r;break}}return t},scope:r}}function uu(e,t){let n=null;for(let r of e){let e=r.style(t);e&&(n=n?n+` `+e:e)}return n}function du(e,t,n,r=0,i=e.length){let a=new fu(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,``,a.highlighters),a.flush(i)}var fu=class{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=``}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,i){let{type:a,from:o,to:s}=e;if(o>=n||s<=t)return;a.isTop&&(i=this.highlighters.filter(e=>!e.scope||e.scope(a)));let c=r,l=pu(e)||cu.empty,u=uu(i,l.tags);if(u&&(c&&(c+=` `),c+=u,l.mode==1&&(r+=(r?` `:``)+u)),this.startSpan(Math.max(t,o),c),l.opaque)return;let d=e.tree&&e.tree.prop(U.mounted);if(d&&d.overlay){let a=e.node.enter(d.overlay[0].from+o,1),l=this.highlighters.filter(e=>!e.scope||e.scope(d.tree.type)),u=e.firstChild();for(let f=0,p=o;;f++){let m=f<d.overlay.length?d.overlay[f]:null,h=m?m.from+o:s,g=Math.max(t,p),_=Math.min(n,h);if(g<_&&u)for(;e.from<_&&(this.highlightRange(e,g,_,r,i),this.startSpan(Math.min(_,e.to),c),!(e.to>=h||!e.nextSibling())););if(!m||h>n)break;p=m.to+o,p>t&&(this.highlightRange(a.cursor(),Math.max(t,m.from+o),Math.min(n,p),``,l),this.startSpan(Math.min(n,p),c))}u&&e.parent()}else if(e.firstChild()){d&&(r=``);do{if(e.to<=t)continue;if(e.from>=n)break;this.highlightRange(e,t,n,r,i),this.startSpan(Math.min(n,e.to),c)}while(e.nextSibling());e.parent()}}};function pu(e){let t=e.type.prop(su);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}const q=tu.define,mu=q(),hu=q(),gu=q(hu),_u=q(hu),vu=q(),yu=q(vu),bu=q(vu),xu=q(),Su=q(xu),Cu=q(),wu=q(),Tu=q(),Eu=q(Tu),Du=q(),J={comment:mu,lineComment:q(mu),blockComment:q(mu),docComment:q(mu),name:hu,variableName:q(hu),typeName:gu,tagName:q(gu),propertyName:_u,attributeName:q(_u),className:q(hu),labelName:q(hu),namespace:q(hu),macroName:q(hu),literal:vu,string:yu,docString:q(yu),character:q(yu),attributeValue:q(yu),number:bu,integer:q(bu),float:q(bu),bool:q(vu),regexp:q(vu),escape:q(vu),color:q(vu),url:q(vu),keyword:Cu,self:q(Cu),null:q(Cu),atom:q(Cu),unit:q(Cu),modifier:q(Cu),operatorKeyword:q(Cu),controlKeyword:q(Cu),definitionKeyword:q(Cu),moduleKeyword:q(Cu),operator:wu,derefOperator:q(wu),arithmeticOperator:q(wu),logicOperator:q(wu),bitwiseOperator:q(wu),compareOperator:q(wu),updateOperator:q(wu),definitionOperator:q(wu),typeOperator:q(wu),controlOperator:q(wu),punctuation:Tu,separator:q(Tu),bracket:Eu,angleBracket:q(Eu),squareBracket:q(Eu),paren:q(Eu),brace:q(Eu),content:xu,heading:Su,heading1:q(Su),heading2:q(Su),heading3:q(Su),heading4:q(Su),heading5:q(Su),heading6:q(Su),contentSeparator:q(xu),list:q(xu),quote:q(xu),emphasis:q(xu),strong:q(xu),link:q(xu),monospace:q(xu),strikethrough:q(xu),inserted:q(),deleted:q(),changed:q(),invalid:q(),meta:Du,documentMeta:q(Du),annotation:q(Du),processingInstruction:q(Du),definition:tu.defineModifier(`definition`),constant:tu.defineModifier(`constant`),function:tu.defineModifier(`function`),standard:tu.defineModifier(`standard`),local:tu.defineModifier(`local`),special:tu.defineModifier(`special`)};for(let e in J){let t=J[e];t instanceof tu&&(t.name=e)}lu([{tag:J.link,class:`tok-link`},{tag:J.heading,class:`tok-heading`},{tag:J.emphasis,class:`tok-emphasis`},{tag:J.strong,class:`tok-strong`},{tag:J.keyword,class:`tok-keyword`},{tag:J.atom,class:`tok-atom`},{tag:J.bool,class:`tok-bool`},{tag:J.url,class:`tok-url`},{tag:J.labelName,class:`tok-labelName`},{tag:J.inserted,class:`tok-inserted`},{tag:J.deleted,class:`tok-deleted`},{tag:J.literal,class:`tok-literal`},{tag:J.string,class:`tok-string`},{tag:J.number,class:`tok-number`},{tag:[J.regexp,J.escape,J.special(J.string)],class:`tok-string2`},{tag:J.variableName,class:`tok-variableName`},{tag:J.local(J.variableName),class:`tok-variableName tok-local`},{tag:J.definition(J.variableName),class:`tok-variableName tok-definition`},{tag:J.special(J.variableName),class:`tok-variableName2`},{tag:J.definition(J.propertyName),class:`tok-propertyName tok-definition`},{tag:J.typeName,class:`tok-typeName`},{tag:J.namespace,class:`tok-namespace`},{tag:J.className,class:`tok-className`},{tag:J.macroName,class:`tok-macroName`},{tag:J.propertyName,class:`tok-propertyName`},{tag:J.operator,class:`tok-operator`},{tag:J.comment,class:`tok-comment`},{tag:J.meta,class:`tok-meta`},{tag:J.invalid,class:`tok-invalid`},{tag:J.punctuation,class:`tok-punctuation`}]);const Ou=new U;function ku(e){return M.define({combine:e?t=>t.concat(e):void 0})}const Au=new U;var ju=class{constructor(e,t,n=[],r=``){this.data=e,this.name=r,P.prototype.hasOwnProperty(`tree`)||Object.defineProperty(P.prototype,"tree",{get(){return Y(this)}}),this.parser=t,this.extension=[Hu.of(this),P.languageData.of((e,t,n)=>{let r=Mu(e,t,n),i=r.type.prop(Ou);if(!i)return[];let a=e.facet(i),o=r.type.prop(Au);if(o){let i=r.resolve(t-r.from,n);for(let t of o)if(t.test(i,e)){let n=e.facet(t.facet);return t.type==`replace`?n:n.concat(a)}}return a})].concat(n)}isActiveAt(e,t,n=-1){return Mu(e,t,n).type.prop(Ou)==this.data}findRegions(e){let t=e.facet(Hu);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(e,t)=>{if(e.prop(Ou)==this.data){n.push({from:t,to:t+e.length});return}let i=e.prop(U.mounted);if(i){if(i.tree.prop(Ou)==this.data){if(i.overlay)for(let e of i.overlay)n.push({from:e.from+t,to:e.to+t});else n.push({from:t,to:t+e.length});return}else if(i.overlay){let e=n.length;if(r(i.tree,i.overlay[0].from+t),n.length>e)return}}for(let n=0;n<e.children.length;n++){let i=e.children[n];i instanceof K&&r(i,e.positions[n]+t)}};return r(Y(e),0),n}get allowsNesting(){return!0}};ju.setState=N.define();function Mu(e,t,n){let r=e.facet(Hu),i=Y(e).topNode;if(!r||r.allowsNesting)for(let e=i;e;e=e.enter(t,n,G.ExcludeBuffers|G.EnterBracketed))e.type.isTop&&(i=e);return i}var Nu=class e extends ju{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(t){let n=ku(t.languageData);return new e(n,t.parser.configure({props:[Ou.add(e=>e.isTop?n:void 0)]}),t.name)}configure(t,n){return new e(this.data,this.parser.configure(t),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function Y(e){let t=e.field(ju.state,!1);return t?t.tree:K.empty}var Pu=class{constructor(e){this.doc=e,this.cursorPos=0,this.string=``,this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}};let Fu=null;var Iu=class e{constructor(e,t,n=[],r,i,a,o,s){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=i,this.viewport=a,this.skipped=o,this.scheduleOn=s,this.parse=null,this.tempSkipped=[]}static create(t,n,r){return new e(t,n,[],K.empty,0,r,[],null)}startParse(){return this.parser.startParse(new Pu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=K.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{if(typeof e==`number`){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||=this.startParse(),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(Ll.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=this.parse.stoppedAt??this.state.doc.length,this.tree=n,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(Ll.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Fu;Fu=this;try{return e()}finally{Fu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Lu(e,t.from,t.to);return e}changes(t,n){let{fragments:r,tree:i,treeLen:a,viewport:o,skipped:s}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,n,r,i)=>e.push({fromA:t,toA:n,fromB:r,toB:i})),r=Ll.applyChanges(r,e),i=K.empty,a=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){s=[];for(let e of this.skipped){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);n<r&&s.push({from:n,to:r})}}}return new e(this.parser,n,r,i,a,o,s,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 t=0;t<this.skipped.length;t++){let{from:n,to:r}=this.skipped[t];n<e.to&&r>e.from&&(this.fragments=Lu(this.fragments,n,r),this.skipped.splice(t--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&=(this.takeTree(),null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Rl{createParse(t,n,r){let i=r[0].from,a=r[r.length-1].to;return{parsedPos:i,advance(){let t=Fu;if(t){for(let e of r)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=a,new K(W.none,[],[],a-i)},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 Fu}};function Lu(e,t,n){return Ll.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}var Ru=class e{constructor(e){this.context=e,this.tree=e.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(t.changes,t.state),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new e(n)}static init(t){let n=Math.min(3e3,t.doc.length),r=Iu.create(t.facet(Hu).parser,t,{from:0,to:n});return r.work(20,n)||r.takeTree(),new e(r)}};ju.state=Cn.define({create:Ru.init,update(e,t){for(let e of t.effects)if(e.is(ju.setState))return e.value;return t.startState.facet(Hu)==t.state.facet(Hu)?e.apply(t):Ru.init(t.state)}});let zu=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<`u`&&(zu=e=>{let t=-1,n=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const Bu=typeof navigator<`u`&&navigator.scheduling?.isInputPending?()=>navigator.scheduling.isInputPending():null,Vu=wa.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(ju.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(ju.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=zu(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:r}}=this.view,i=n.field(ju.state);if(i.tree==i.context.tree&&i.context.isDone(r+1e5))return;let a=Date.now()+Math.min(this.chunkBudget,100,e&&!Bu?Math.max(25,e.timeRemaining()-5):1e9),o=i.context.treeLen<r&&n.doc.length>r+1e3,s=i.context.work(()=>Bu&&Bu()||Date.now()>a,r+(o?0:1e5));this.chunkBudget-=Date.now()-t,(s||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:ju.setState.of(new Ru(i.context))})),this.chunkBudget>0&&!(s&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(e){e.scheduleOn&&=(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(e=>ba(this.view.state,e)).then(()=>this.workScheduled--),null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Hu=M.define({combine(e){return e.length?e[0]:null},enables:e=>[ju.state,Vu,H.contentAttributes.compute([e],t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}})]});var Uu=class{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}},Wu=class e{constructor(e,t,n,r,i,a=void 0){this.name=e,this.alias=t,this.extensions=n,this.filename=r,this.loadFunc=i,this.support=a,this.loading=null}load(){return this.loading||=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e})}static of(t){let{load:n,support:r}=t;if(!n){if(!r)throw RangeError(`Must pass either 'load' or 'support' to LanguageDescription.of`);n=()=>Promise.resolve(r)}return new e(t.name,(t.alias||[]).concat(t.name).map(e=>e.toLowerCase()),t.extensions||[],t.filename,n,r)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let n=/\.([^.]+)$/.exec(t);if(n){for(let t of e)if(t.extensions.indexOf(n[1])>-1)return t}return null}static matchLanguageName(e,t,n=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some(e=>e==t))return n;if(n)for(let n of e)for(let e of n.alias){let r=t.indexOf(e);if(r>-1&&(e.length>2||!/\w/.test(t[r-1])&&!/\w/.test(t[r+e.length])))return n}return null}};const Gu=M.define(),Ku=M.define({combine:e=>{if(!e.length)return` `;let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw Error(`Invalid indent unit: `+JSON.stringify(e[0]));return t}});function qu(e){let t=e.facet(Ku);return t.charCodeAt(0)==9?e.tabSize*t.length:t.length}function Ju(e,t){let n=``,r=e.tabSize,i=e.facet(Ku)[0];if(i==` `){for(;t>=r;)n+=` `,t-=r;i=` `}for(let e=0;e<t;e++)n+=i;return n}function Yu(e,t){e instanceof P&&(e=new Xu(e));for(let n of e.state.facet(Gu)){let r=n(e,t);if(r!==void 0)return r}let n=Y(e.state);return n.length>=t?Qu(e,n,t):null}var Xu=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=qu(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:i}=this.options;return r!=null&&r>=n.from&&r<=n.to?i&&r==e?{text:``,from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return``;let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.countColumn(n,e-r),a=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return a>-1&&(i+=a-this.countColumn(n,n.search(/\S|$/))),i}countColumn(e,t=e.length){return Cr(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.options.overrideIndentation;if(i){let e=i(r);if(e>-1)return e}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}};const Zu=new U;function Qu(e,t,n){let r=t.resolveStack(n),i=t.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(i!=r.node){let e=[];for(let t=i;t&&!(t.from<r.node.from||t.to>r.node.to||t.from==r.node.from&&t.type==r.node.type);t=t.parent)e.push(t);for(let t=e.length-1;t>=0;t--)r={node:e[t],next:r}}return $u(r,e,n)}function $u(e,t,n){for(let r=e;r;r=r.next){let e=td(r.node);if(e)return e(rd.create(t,n,r))}return 0}function ed(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}function td(e){let t=e.type.prop(Zu);if(t)return t;let n=e.firstChild,r;if(n&&(r=n.type.prop(U.closedBy))){let t=e.lastChild,n=t&&r.indexOf(t.name)>-1;return e=>sd(e,!0,1,void 0,n&&!ed(e)?t.from:void 0)}return e.parent==null?nd:null}function nd(){return 0}var rd=class e extends Xu{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.context=n}get node(){return this.context.node}static create(t,n,r){return new e(t,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(id(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){return $u(this.context.next,this.base,this.pos)}};function id(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function ad(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let i=e.options.simulateBreak,a=e.state.doc.lineAt(n.from),o=i==null||i<=a.from?a.to:Math.min(a.to,i);for(let e=n.to;;){let i=t.childAfter(e);if(!i||i==r)return null;if(!i.type.isSkipped){if(i.from>=o)return null;let e=/^ */.exec(a.text.slice(n.to-a.from))[0].length;return{from:n.from,to:n.to+e}}e=i.to}}function od({closing:e,align:t=!0,units:n=1}){return r=>sd(r,t,n,e)}function sd(e,t,n,r,i){let a=e.textAfter,o=a.match(/^\s*/)[0].length,s=r&&a.slice(o,o+r.length)==r||i==e.pos+o,c=t?ad(e):null;return c?s?e.column(c.from):e.column(c.to):e.baseIndent+(s?0:e.unit*n)}const cd=e=>e.baseIndent;function ld({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}const ud=M.define(),dd=new U;function fd(e){let t=e.firstChild,n=e.lastChild;return t&&t.to<n.from?{from:t.to,to:n.type.isError?e.to:n.from}:null}var pd=class e{constructor(e,t){this.specs=e;let n;function r(e){let t=Or.newName();return(n||=Object.create(null))[`.`+t]=e,t}let i=typeof t.all==`string`?t.all:t.all?r(t.all):void 0,a=t.scope;this.scope=a instanceof ju?e=>e.prop(Ou)==a.data:a?e=>e==a:void 0,this.style=lu(e.map(e=>({tag:e.tag,class:e.class||r(Object.assign({},e,{tag:null}))})),{all:i}).style,this.module=n?new Or(n):null,this.themeType=t.themeType}static define(t,n){return new e(t,n||{})}};const md=M.define(),hd=M.define({combine(e){return e.length?[e[0]]:null}});function gd(e){let t=e.facet(md);return t.length?t:e.facet(hd)}function _d(e,t){let n=[yd],r;return e instanceof pd&&(e.module&&n.push(H.styleModule.of(e.module)),r=e.themeType),t?.fallback?n.push(hd.of(e)):r?n.push(md.computeN([H.darkTheme],t=>t.facet(H.darkTheme)==(r==`dark`)?[e]:[])):n.push(md.of(e)),n}var vd=class{constructor(e){this.markCache=Object.create(null),this.tree=Y(e.state),this.decorations=this.buildDeco(e,gd(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Y(e.state),n=gd(e.state),r=n!=gd(e.startState),{viewport:i}=e.view,a=e.changes.mapPos(this.decoratedTo,1);t.length<i.to&&!r&&t.type==this.tree.type&&a>=i.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=a):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n),this.decoratedTo=i.to)}buildDeco(e,t){if(!t||!this.tree.length)return L.none;let n=new fr;for(let{from:r,to:i}of e.visibleRanges)du(this.tree,t,(e,t,r)=>{n.add(e,t,this.markCache[r]||(this.markCache[r]=L.mark({class:r})))},r,i);return n.finish()}};const yd=En.high(wa.fromClass(vd,{decorations:e=>e.decorations}));J.meta,J.link,J.heading,J.emphasis,J.strong,J.strikethrough,J.keyword,J.atom,J.bool,J.url,J.contentSeparator,J.labelName,J.literal,J.inserted,J.string,J.deleted,J.regexp,J.escape,J.string,J.variableName,J.variableName,J.typeName,J.namespace,J.className,J.variableName,J.macroName,J.propertyName,J.comment,J.invalid;const bd=new U;function xd(e,t,n){let r=e.prop(t<0?U.openedBy:U.closedBy);if(r)return r;if(e.name.length==1){let r=n.indexOf(e.name);if(r>-1&&r%2==+(t<0))return[n[r+t]]}return null}function Sd(e){let t=e.type.prop(bd);return t?t(e.node):e}function Cd(e,t,n,r={}){let i=r.maxScanDistance||1e4,a=r.brackets||`()[]{}`,o=Y(e),s=o.resolveInner(t,n);for(let r=s;r;r=r.parent){let i=xd(r.type,n,a);if(i&&r.from<r.to){let o=Sd(r);if(o&&(n>0?t>=o.from&&t<o.to:t>o.from&&t<=o.to))return wd(e,t,n,r,o,i,a)}}return Td(e,t,n,o,s.type,i,a)}function wd(e,t,n,r,i,a,o){let s=r.parent,c={from:i.from,to:i.to},l=0,u=s?.cursor();if(u&&(n<0?u.childBefore(r.from):u.childAfter(r.to)))do if(n<0?u.to<=r.from:u.from>=r.to){if(l==0&&a.indexOf(u.type.name)>-1&&u.from<u.to){let e=Sd(u);return{start:c,end:e?{from:e.from,to:e.to}:void 0,matched:!0}}else if(xd(u.type,n,o))l++;else if(xd(u.type,-n,o)){if(l==0){let e=Sd(u);return{start:c,end:e&&e.from<e.to?{from:e.from,to:e.to}:void 0,matched:!1}}l--}}while(n<0?u.prevSibling():u.nextSibling());return{start:c,matched:!1}}function Td(e,t,n,r,i,a,o){if(n<0?!t:t==e.doc.length)return null;let s=n<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),c=o.indexOf(s);if(c<0||c%2==0!=n>0)return null;let l={from:n<0?t-1:t,to:n>0?t+1:t},u=e.doc.iterRange(t,n>0?e.doc.length:0),d=0;for(let e=0;!u.next().done&&e<=a;){let a=u.value;n<0&&(e+=a.length);let s=t+e*n;for(let e=n>0?0:a.length-1,t=n>0?a.length:-1;e!=t;e+=n){let t=o.indexOf(a[e]);if(!(t<0||r.resolveInner(s+e,1).type!=i))if(t%2==0==n>0)d++;else if(d==1)return{start:l,end:{from:s+e,to:s+e+1},matched:t>>1==c>>1};else d--}n>0&&(e+=a.length)}return u.done?{start:l,matched:!1}:null}const Ed=Object.create(null),Dd=[W.none],Od=[],kd=Object.create(null),Ad=Object.create(null);for(let[e,t]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`]])Ad[e]=Md(Ed,t);function jd(e,t){Od.indexOf(e)>-1||(Od.push(e),console.warn(t))}function Md(e,t){let n=[];for(let r of t.split(` `)){let t=[];for(let n of r.split(`.`)){let r=e[n]||J[n];r?typeof r==`function`?t.length?t=t.map(r):jd(n,`Modifier ${n} used at start of tag`):t.length?jd(n,`Tag ${n} used as modifier`):t=Array.isArray(r)?r:[r]:jd(n,`Unknown highlighting tag ${n}`)}for(let e of t)n.push(e)}if(!n.length)return 0;let r=t.replace(/ /g,`_`),i=r+` `+n.map(e=>e.id),a=kd[i];if(a)return a.id;let o=kd[i]=W.define({id:Dd.length,name:r,props:[ou({[r]:n})]});return Dd.push(o),o.id}R.RTL,R.LTR;var Nd=class{constructor(e,t,n,r){this.state=e,this.pos=t,this.explicit=n,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=Y(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),r=t.text.slice(n-t.from,this.pos-t.from),i=r.search(Rd(e,!1));return i<0?null:{from:n+i,to:this.pos,text:r.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e==`abort`&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}};function Pd(e){let t=Object.keys(e).join(``),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,``)),`[${n?`\\w`:``}${t.replace(/[^\w\s]/g,`\\$&`)}]`}function Fd(e){let t=Object.create(null),n=Object.create(null);for(let{label:r}of e){t[r[0]]=!0;for(let e=1;e<r.length;e++)n[r[e]]=!0}let r=Pd(t)+Pd(n)+`*$`;return[RegExp(`^`+r),new RegExp(r)]}function Id(e){let t=e.map(e=>typeof e==`string`?{label:e}:e),[n,r]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:Fd(t);return e=>{let i=e.matchBefore(r);return i||e.explicit?{from:i?i.from:e.pos,options:t,validFor:n}:null}}function Ld(e,t){return n=>{for(let t=Y(n.state).resolveInner(n.pos,-1);t;t=t.parent){if(e.indexOf(t.name)>-1)return null;if(t.type.isTop)break}return t(n)}}function Rd(e,t){let{source:n}=e,r=t&&n[0]!=`^`,i=n[n.length-1]!=`$`;return!r&&!i?e:RegExp(`${r?`^`:``}(?:${n})${i?`$`:``}`,e.flags??(e.ignoreCase?`i`:``))}const zd=Vn.define();typeof navigator==`object`&&navigator.platform;const Bd=H.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:`monospace`,whiteSpace:`nowrap`,overflow:`hidden auto`,maxWidth_fallback:`700px`,maxWidth:`min(700px, 95vw)`,minWidth:`250px`,maxHeight:`10em`,height:`100%`,listStyle:`none`,margin:0,padding:0,"& > li, & > completion-section":{padding:`1px 3px`,lineHeight:1.2},"& > li":{overflowX:`hidden`,textOverflow:`ellipsis`,cursor:`pointer`},"& > completion-section":{display:`list-item`,borderBottom:`1px solid silver`,paddingLeft:`0.5em`,opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#17c`,color:`white`},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#777`},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#347`,color:`white`},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#444`},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:`"···"`,opacity:.5,display:`block`,textAlign:`center`,cursor:`pointer`},".cm-tooltip.cm-completionInfo":{position:`absolute`,padding:`3px 9px`,width:`max-content`,maxWidth:`400px`,boxSizing:`border-box`,whiteSpace:`pre-line`},".cm-completionInfo.cm-completionInfo-left":{right:`100%`},".cm-completionInfo.cm-completionInfo-right":{left:`100%`},".cm-completionInfo.cm-completionInfo-left-narrow":{right:`30px`},".cm-completionInfo.cm-completionInfo-right-narrow":{left:`30px`},"&light .cm-snippetField":{backgroundColor:`#00000022`},"&dark .cm-snippetField":{backgroundColor:`#ffffff22`},".cm-snippetFieldPosition":{verticalAlign:`text-top`,width:0,height:`1.15em`,display:`inline-block`,margin:`0 -0.7px -.7em`,borderLeft:`1.4px dotted #888`},".cm-completionMatchedText":{textDecoration:`underline`},".cm-completionDetail":{marginLeft:`0.5em`,fontStyle:`italic`},".cm-completionIcon":{fontSize:`90%`,width:`.8em`,display:`inline-block`,textAlign:`center`,paddingRight:`.6em`,opacity:`0.6`,boxSizing:`content-box`},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:`'ƒ'`}},".cm-completionIcon-class":{"&:after":{content:`'○'`}},".cm-completionIcon-interface":{"&:after":{content:`'◌'`}},".cm-completionIcon-variable":{"&:after":{content:`'𝑥'`}},".cm-completionIcon-constant":{"&:after":{content:`'𝐶'`}},".cm-completionIcon-type":{"&:after":{content:`'𝑡'`}},".cm-completionIcon-enum":{"&:after":{content:`'∪'`}},".cm-completionIcon-property":{"&:after":{content:`'□'`}},".cm-completionIcon-keyword":{"&:after":{content:`'🔑︎'`}},".cm-completionIcon-namespace":{"&:after":{content:`'▢'`}},".cm-completionIcon-text":{"&:after":{content:`'abc'`,fontSize:`50%`,verticalAlign:`middle`}}});var Vd=class{constructor(e,t,n,r){this.field=e,this.line=t,this.from=n,this.to=r}},Hd=class e{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(t){let n=t.mapPos(this.from,-1,on.TrackDel),r=t.mapPos(this.to,1,on.TrackDel);return n==null||r==null?null:new e(this.field,n,r)}},Ud=class e{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],r=[t],i=e.doc.lineAt(t),a=/^\s*/.exec(i.text)[0];for(let i of this.lines){if(n.length){let n=a,o=/^\t*/.exec(i)[0].length;for(let t=0;t<o;t++)n+=e.facet(Ku);r.push(t+n.length-o),i=n+i.slice(o)}n.push(i),t+=i.length+1}return{text:n,ranges:this.fieldPositions.map(e=>new Hd(e.field,r[e.line]+e.from,r[e.line]+e.to))}}static parse(t){let n=[],r=[],i=[],a;for(let e of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(e);){let t=a[1]?+a[1]:null,o=a[2]||a[3]||``,s=-1;t===0&&(t=1e9);let c=o.replace(/\\[{}]/g,e=>e[1]);for(let e=0;e<n.length;e++)(t==null?c&&n[e].name==c:n[e].seq==t)&&(s=e);if(s<0){let e=0;for(;e<n.length&&(t==null||n[e].seq!=null&&n[e].seq<t);)e++;n.splice(e,0,{seq:t,name:c}),s=e;for(let e of i)e.field>=s&&e.field++}for(let e of i)if(e.line==r.length&&e.from>a.index){let t=a[2]?3+(a[1]||``).length:2;e.from-=t,e.to-=t}i.push(new Vd(s,r.length,a.index,a.index+c.length)),e=e.slice(0,a.index)+o+e.slice(a.index+a[0].length)}e=e.replace(/\\([{}])/g,(e,t,n)=>{for(let e of i)e.line==r.length&&e.from>n&&(e.from--,e.to--);return t}),r.push(e)}return new e(r,i)}};let Wd=L.widget({widget:new class extends ti{toDOM(){let e=document.createElement(`span`);return e.className=`cm-snippetFieldPosition`,e}ignoreEvent(){return!1}}}),Gd=L.mark({class:`cm-snippetField`});var Kd=class e{constructor(e,t){this.ranges=e,this.active=t,this.deco=L.set(e.map(e=>(e.from==e.to?Wd:Gd).range(e.from,e.to)),!0)}map(t){let n=[];for(let e of this.ranges){let r=e.map(t);if(!r)return null;n.push(r)}return new e(n,this.active)}selectionInsideField(e){return e.ranges.every(e=>this.ranges.some(t=>t.field==this.active&&t.from<=e.from&&t.to>=e.to))}};const qd=N.define({map(e,t){return e&&e.map(t)}}),Jd=N.define(),Yd=Cn.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(qd))return n.value;if(n.is(Jd)&&e)return new Kd(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>H.decorations.from(e,e=>e?e.deco:L.none)});function Xd(e,t){return j.create(e.filter(e=>e.field==t).map(e=>j.range(e.from,e.to)))}function Zd(e){let t=Ud.parse(e);return(e,n,r,i)=>{let{text:a,ranges:o}=t.instantiate(e.state,r),{main:s}=e.state.selection,c={changes:{from:r,to:i==s.from?s.to:i,insert:k.of(a)},scrollIntoView:!0,annotations:n?[zd.of(n),Wn.userEvent.of(`input.complete`)]:void 0};if(o.length&&(c.selection=Xd(o,0)),o.some(e=>e.field>0)){let t=new Kd(o,0),n=c.effects=[qd.of(t)];e.state.field(Yd,!1)===void 0&&n.push(N.appendConfig.of([Yd,tf,rf,Bd]))}e.dispatch(e.state.update(c))}}function Qd(e){return({state:t,dispatch:n})=>{let r=t.field(Yd,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(t=>t.field==i+e);return n(t.update({selection:Xd(r.ranges,i),effects:qd.of(a?null:new Kd(r.ranges,i)),scrollIntoView:!0})),!0}}const $d=[{key:`Tab`,run:Qd(1),shift:Qd(-1)},{key:`Escape`,run:({state:e,dispatch:t})=>e.field(Yd,!1)?(t(e.update({effects:qd.of(null)})),!0):!1}],ef=M.define({combine(e){return e.length?e[0]:$d}}),tf=En.highest(Lc.compute([ef],e=>e.facet(ef)));function nf(e,t){return{...t,apply:Zd(e)}}const rf=H.domEventHandlers({mousedown(e,t){let n=t.state.field(Yd,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(e=>e.from<=r&&e.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:Xd(n.ranges,i.field),effects:qd.of(n.ranges.some(e=>e.field>i.field)?new Kd(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),af=new class extends ar{};af.startSide=1,af.endSide=-1,typeof navigator==`object`&&navigator.userAgent;var of=class e{static create(t,n,r,i,a){let o=i+(i<<8)+t+(n<<4)|0;return new e(t,n,r,o,a,[],[])}constructor(e,t,n,r,i,a,o){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=a,this.positions=o,this.hashProp=[[U.contextHash,r]]}addChild(e,t){e.prop(U.contextHash)!=this.hash&&(e=new K(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new K(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new K(W.none,e,t,n,this.hashProp)})}},X;(function(e){e[e.Document=1]=`Document`,e[e.CodeBlock=2]=`CodeBlock`,e[e.FencedCode=3]=`FencedCode`,e[e.Blockquote=4]=`Blockquote`,e[e.HorizontalRule=5]=`HorizontalRule`,e[e.BulletList=6]=`BulletList`,e[e.OrderedList=7]=`OrderedList`,e[e.ListItem=8]=`ListItem`,e[e.ATXHeading1=9]=`ATXHeading1`,e[e.ATXHeading2=10]=`ATXHeading2`,e[e.ATXHeading3=11]=`ATXHeading3`,e[e.ATXHeading4=12]=`ATXHeading4`,e[e.ATXHeading5=13]=`ATXHeading5`,e[e.ATXHeading6=14]=`ATXHeading6`,e[e.SetextHeading1=15]=`SetextHeading1`,e[e.SetextHeading2=16]=`SetextHeading2`,e[e.HTMLBlock=17]=`HTMLBlock`,e[e.LinkReference=18]=`LinkReference`,e[e.Paragraph=19]=`Paragraph`,e[e.CommentBlock=20]=`CommentBlock`,e[e.ProcessingInstructionBlock=21]=`ProcessingInstructionBlock`,e[e.Escape=22]=`Escape`,e[e.Entity=23]=`Entity`,e[e.HardBreak=24]=`HardBreak`,e[e.Emphasis=25]=`Emphasis`,e[e.StrongEmphasis=26]=`StrongEmphasis`,e[e.Link=27]=`Link`,e[e.Image=28]=`Image`,e[e.InlineCode=29]=`InlineCode`,e[e.HTMLTag=30]=`HTMLTag`,e[e.Comment=31]=`Comment`,e[e.ProcessingInstruction=32]=`ProcessingInstruction`,e[e.Autolink=33]=`Autolink`,e[e.HeaderMark=34]=`HeaderMark`,e[e.QuoteMark=35]=`QuoteMark`,e[e.ListMark=36]=`ListMark`,e[e.LinkMark=37]=`LinkMark`,e[e.EmphasisMark=38]=`EmphasisMark`,e[e.CodeMark=39]=`CodeMark`,e[e.CodeText=40]=`CodeText`,e[e.CodeInfo=41]=`CodeInfo`,e[e.LinkTitle=42]=`LinkTitle`,e[e.LinkLabel=43]=`LinkLabel`,e[e.URL=44]=`URL`})(X||={});var sf=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},cf=class{constructor(){this.text=``,this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return ff(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e=``;for(let t=0;t<this.basePos;t++)e+=` `;return e+this.text.slice(this.basePos)}};function lf(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==X.OrderedList?yf:vf)(n,t,!1);return r>0&&(e.type!=X.BulletList||gf(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}const uf={[X.Blockquote](e,t,n){return n.next==62?(n.markers.push(Z(X.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(df(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0):!1},[X.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[X.OrderedList]:lf,[X.BulletList]:lf,[X.Document](){return!0}};function df(e){return e==32||e==9||e==10||e==13}function ff(e,t=0){for(;t<e.length&&df(e.charCodeAt(t));)t++;return t}function pf(e,t,n){for(;t>n&&df(e.charCodeAt(t-1));)t--;return t}function mf(e){if(e.next!=96&&e.next!=126)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function hf(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function gf(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!df(n))return-1}return n&&e.next==45&&xf(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(Nf.SetextHeading)>-1||r<3?-1:1}function _f(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function vf(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||df(e.text.charCodeAt(e.pos+1)))&&(!n||_f(t,X.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function yf(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!df(e.text.charCodeAt(r+1))||n&&!_f(t,X.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function bf(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function xf(e){if(e.next!=45&&e.next!=61||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let n=t;for(;t<e.text.length&&df(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}const Sf=/^[ \t]*$/,Cf=/-->/,wf=/\?>/,Tf=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,Cf],[/^\s*<\?/,wf],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,Sf],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,Sf]];function Ef(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=Tf.length-+!!n;e<t;e++)if(Tf[e][0].test(r))return e;return-1}function Df(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.skipSpace(t),i=e.countIndent(r,t,n);return i>=n+5||r==e.text.length?n+1:i}function Of(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==X.CodeText?e[r].to=n:e.push(Z(X.CodeText,t,n))}const kf={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(Of(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){Of(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==X.CodeText?Of(o,e.from,e.to):o.push(e);s=[]}Of(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&Of(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=X.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(X.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=mf(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=pf(t.text,t.text.length,o),c=[Z(X.CodeMark,r,r+a)];o<s&&c.push(Z(X.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&Of(c,e.lineStart-1,e.lineStart),c.push(Z(X.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}else{o=!0,n||(Of(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(Of(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(X.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=hf(t);return n<0?!1:(e.startContext(X.Blockquote,t.pos),e.addNode(X.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(gf(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(X.HorizontalRule,n),!0},BulletList(e,t){let n=vf(t,e,!1);if(n<0)return!1;e.block.type!=X.BulletList&&e.startContext(X.BulletList,t.basePos,t.next);let r=Df(t,t.pos+1);return e.startContext(X.ListItem,t.basePos,r-t.baseIndent),e.addNode(X.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=yf(t,e,!1);if(n<0)return!1;e.block.type!=X.OrderedList&&e.startContext(X.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=Df(t,t.pos+n);return e.startContext(X.ListItem,t.basePos,r-t.baseIndent),e.addNode(X.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=bf(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=pf(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!df(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(X.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(X.HeaderMark,o-r,a-r);let c=s.finish(X.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=Ef(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=Tf[n][1],a=[],o=i!=Sf;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==Cf?X.CommentBlock:i==wf?X.ProcessingInstructionBlock:X.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0};var Af=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
744
744
  `+t.scrub(),i=this.advance(r);return i>-1&&i<r.length&&this.complete(e,n,i)}finish(e,t){return(this.stage==2||this.stage==3)&&ff(t.content,this.pos)==t.content.length&&this.complete(e,t,t.content.length)}complete(e,t,n){return e.addLeafElement(t,Z(X.LinkReference,this.start,this.start+n,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;)if(this.stage==-1)return-1;else if(this.stage==0){if(!this.nextStage(rp(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(Z(X.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(tp(e,ff(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=ff(e,this.pos),n=0;if(t>this.pos){let r=np(e,t,this.start);if(r){let t=jf(e,r.to-this.start);t>0&&(this.nextStage(r),n=t)}}return n||=jf(e,this.pos),n>0&&n<e.length?n:-1}else return jf(e,this.pos)}};function jf(e,t){for(;t<e.length;t++){let n=e.charCodeAt(t);if(n==10)break;if(!df(n))return-1}return t}var Mf=class{nextLine(e,t,n){let r=t.depth<e.stack.length?-1:xf(t),i=t.next;if(r<0)return!1;let a=Z(X.HeaderMark,e.lineStart+t.pos,e.lineStart+r);return e.nextLine(),e.addLeafElement(n,Z(i==61?X.SetextHeading1:X.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),a])),!0}finish(){return!1}};const Nf={LinkReference(e,t){return t.content.charCodeAt(0)==91?new Af(t):null},SetextHeading(){return new Mf}},Pf=[(e,t)=>bf(t)>=0,(e,t)=>mf(t)>=0,(e,t)=>hf(t)>=0,(e,t)=>vf(t,e,!0)>=0,(e,t)=>yf(t,e,!0)>=0,(e,t)=>gf(t,e,!0)>=0,(e,t)=>Ef(t,e,!0)>=0],Ff={text:``,end:0};var If=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.line=new cf,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=r[r.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=r[0].from,this.block=of.create(X.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new sp(n,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(let t=0;;){let n=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;t<e.markers.length&&(!n||e.markers[t].from<n.end);){let n=e.markers[t++];this.addNode(n.type,n.from,n.to)}if(!n)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;start:for(;;){for(let t of this.parser.blockParsers)if(t){let n=t(this,e);if(n!=0){if(n==1)return null;e.forward();continue start}}break}if(e.pos==e.text.length)return this.nextLine()?null:this.finish();let t=new sf(this.lineStart+e.pos,e.text.slice(e.pos));for(let e of this.parser.leafBlockParsers)if(e){let n=e(this,t);n&&t.parsers.push(n)}lines:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let n of this.parser.endLeafBlock)if(n(this,e,t))break lines}for(let n of t.parsers)if(n.nextLine(this,e,t))return null;t.content+=`
745
745
  `+e.scrub();for(let n of e.markers)t.marks.push(n)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=cp(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=Ff;if(t.end=e,e>=this.to)t.text=``;else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let e=this.absoluteLineStart,n=this.rangeI;for(;this.ranges[n].to<t.end;){n++;let r=this.ranges[n].from,i=this.lineChunkAt(r);t.end=r+i.length,t.text=t.text.slice(0,this.ranges[n-1].to-e)+i,e=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(t);e.depth<this.stack.length;e.depth++){let t=this.stack[e.depth],n=this.parser.skipContextMarkup[t.type];if(!n)throw Error(`Unhandled block context `+X[t.type]);let r=this.line.markers.length;if(!n(t,this,e)){this.line.markers.length>r&&(t.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`
746
746
  `?``:t;else{let e=t.indexOf(`
@@ -767,10 +767,10 @@ html[data-dsh-tw-active] .dshDesktopConversationSurface > :not([data-dsh-tw-view
767
767
  \${}
768
768
  }`,{label:`interface`,detail:`definition`,type:`keyword`}),nf("type ${name} = ${type}",{label:`type`,detail:`definition`,type:`keyword`}),nf(`enum \${name} {
769
769
  \${}
770
- }`,{label:`enum`,detail:`definition`,type:`keyword`})]),kh=new Il,Ah=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function jh(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}const Mh=[`FunctionDeclaration`],Nh={FunctionDeclaration:jh(`function`),ClassDeclaration:jh(`class`),ClassExpression:()=>!0,EnumDeclaration:jh(`constant`),TypeAliasDeclaration:jh(`type`),NamespaceDeclaration:jh(`namespace`),VariableDefinition(e,t){e.matchContext(Mh)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function Ph(e,t){let n=kh.get(t);if(n)return n;let r=[],i=!0;function a(t,n){let i=e.sliceString(t.from,t.to);r.push({label:i,type:n})}return t.cursor(G.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=Nh[t.name];if(e&&e(t,a)||Ah.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of Ph(e,t.node))r.push(n);return!1}}),kh.set(t,r),r}const Fh=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Ih=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function Lh(e){let t=Y(e.state).resolveInner(e.pos,-1);if(Ih.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&Fh.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)Ah.has(n.name)&&(r=r.concat(Ph(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:Fh}}const Rh=Nu.define({name:`javascript`,parser:Eh.configure({props:[Zu.add({IfStatement:ld({except:/^\s*({|else\b)/}),TryStatement:ld({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:cd,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:od({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":ld({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),dd.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":fd,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name==`JSXSelfClosingTag`)return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){let t=e.firstChild?.nextSibling,n=e.lastChild;return!t||t.type.isError?null:{from:t.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:[`(`,`[`,`{`,`'`,`"`,"`"]},commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:`$`}}),zh={test:e=>/^JSX/.test(e.name),facet:ku({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},Bh=Rh.configure({dialect:`ts`},`typescript`),Vh=Rh.configure({dialect:`jsx`,props:[Au.add(e=>e.isTop?[zh]:void 0)]}),Hh=Rh.configure({dialect:`jsx ts`,props:[Au.add(e=>e.isTop?[zh]:void 0)]},`typescript`);let Uh=e=>({label:e,type:`keyword`});const Wh=`break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield`.split(` `).map(Uh),Gh=Wh.concat([`declare`,`implements`,`private`,`protected`,`public`].map(Uh));function Kh(e={}){let t=e.jsx?e.typescript?Hh:Vh:e.typescript?Bh:Rh,n=e.typescript?Oh.concat(Gh):Dh.concat(Wh);return new Uu(t,[Rh.data.of({autocomplete:Ld(Ih,Id(n))}),Rh.data.of({autocomplete:Lh}),e.jsx?Xh:[]])}function qh(e){for(;;){if(e.name==`JSXOpenTag`||e.name==`JSXSelfClosingTag`||e.name==`JSXFragmentTag`)return e;if(e.name==`JSXEscape`||!e.parent)return null;e=e.parent}}function Jh(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name==`JSXIdentifier`||r.name==`JSXBuiltin`||r.name==`JSXNamespacedName`||r.name==`JSXMemberExpression`)return e.sliceString(r.from,Math.min(r.to,n));return``}const Yh=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),Xh=H.inputHandler.of((e,t,n,r,i)=>{if((Yh?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!Rh.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=Y(o).resolveInner(t-1,-1),i;if(n.name==`JSXStartTag`&&(n=n.parent),!(o.doc.sliceString(t-1,t)!=r||n.name==`JSXAttributeValue`&&n.to>t)){if(r==`>`&&n.name==`JSXFragmentTag`)return{range:e,changes:{from:t,insert:`</>`}};if(r==`/`&&n.name==`JSXStartCloseTag`){let e=n.parent,r=e.parent;if(r&&e.from==t-2&&((i=Jh(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:j.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=qh(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=Jh(o.doc,r,t)))return{range:e,changes:{from:t,insert:`</${i}>`}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),Zh=[`_blank`,`_self`,`_top`,`_parent`],Qh=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],$h=[`get`,`post`,`put`,`delete`],eg=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],tg=[`true`,`false`],Q={},ng={a:{attrs:{href:null,ping:null,type:null,media:null,target:Zh,hreflang:null}},abbr:Q,address:Q,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:[`default`,`rect`,`circle`,`poly`]}},article:Q,aside:Q,audio:{attrs:{src:null,mediagroup:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`none`,`metadata`,`auto`],autoplay:[`autoplay`],loop:[`loop`],controls:[`controls`]}},b:Q,base:{attrs:{href:null,target:Zh}},bdi:Q,bdo:Q,blockquote:{attrs:{cite:null}},body:Q,br:Q,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:eg,formmethod:$h,formnovalidate:[`novalidate`],formtarget:Zh,type:[`submit`,`reset`,`button`]}},canvas:{attrs:{width:null,height:null}},caption:Q,center:Q,cite:Q,code:Q,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:[`command`,`checkbox`,`radio`],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:[`disabled`],checked:[`checked`]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:[`disabled`],multiple:[`multiple`]}},datalist:{attrs:{data:null}},dd:Q,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:[`open`]}},dfn:Q,div:Q,dl:Q,dt:Q,em:Q,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:[`disabled`],form:null,name:null}},figcaption:Q,figure:Q,footer:Q,form:{attrs:{action:null,name:null,"accept-charset":Qh,autocomplete:[`on`,`off`],enctype:eg,method:$h,novalidate:[`novalidate`],target:Zh}},h1:Q,h2:Q,h3:Q,h4:Q,h5:Q,h6:Q,head:{children:[`title`,`base`,`link`,`style`,`meta`,`script`,`noscript`,`command`]},header:Q,hgroup:Q,hr:Q,html:{attrs:{manifest:null}},i:Q,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:[`allow-top-navigation`,`allow-same-origin`,`allow-forms`,`allow-scripts`],seamless:[`seamless`]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:[`audio/*`,`video/*`,`image/*`],autocomplete:[`on`,`off`],autofocus:[`autofocus`],checked:[`checked`],disabled:[`disabled`],formenctype:eg,formmethod:$h,formnovalidate:[`novalidate`],formtarget:Zh,multiple:[`multiple`],readonly:[`readonly`],required:[`required`],type:[`hidden`,`text`,`search`,`tel`,`url`,`email`,`password`,`datetime`,`date`,`month`,`week`,`time`,`datetime-local`,`number`,`range`,`color`,`checkbox`,`radio`,`file`,`submit`,`image`,`reset`,`button`]}},ins:{attrs:{cite:null,datetime:null}},kbd:Q,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:[`autofocus`],disabled:[`disabled`],keytype:[`RSA`]}},label:{attrs:{for:null,form:null}},legend:Q,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:[`all`,`16x16`,`16x16 32x32`,`16x16 32x32 64x64`]}},map:{attrs:{name:null}},mark:Q,menu:{attrs:{label:null,type:[`list`,`context`,`toolbar`]}},meta:{attrs:{content:null,charset:Qh,name:[`viewport`,`application-name`,`author`,`description`,`generator`,`keywords`],"http-equiv":[`content-language`,`content-type`,`default-style`,`refresh`]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:Q,noscript:Q,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:[`typemustmatch`]}},ol:{attrs:{reversed:[`reversed`],start:null,type:[`1`,`a`,`A`,`i`,`I`]},children:[`li`,`script`,`template`,`ul`,`ol`]},optgroup:{attrs:{disabled:[`disabled`],label:null}},option:{attrs:{disabled:[`disabled`],label:null,selected:[`selected`],value:null}},output:{attrs:{for:null,form:null,name:null}},p:Q,param:{attrs:{name:null,value:null}},pre:Q,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:Q,rt:Q,ruby:Q,samp:Q,script:{attrs:{type:[`text/javascript`],src:null,async:[`async`],defer:[`defer`],charset:Qh}},section:Q,select:{attrs:{form:null,name:null,size:null,autofocus:[`autofocus`],disabled:[`disabled`],multiple:[`multiple`]}},slot:{attrs:{name:null}},small:Q,source:{attrs:{src:null,type:null,media:null}},span:Q,strong:Q,style:{attrs:{type:[`text/css`],media:null,scoped:null}},sub:Q,summary:Q,sup:Q,table:Q,tbody:Q,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:Q,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:[`autofocus`],disabled:[`disabled`],readonly:[`readonly`],required:[`required`],wrap:[`soft`,`hard`]}},tfoot:Q,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:[`row`,`col`,`rowgroup`,`colgroup`]}},thead:Q,time:{attrs:{datetime:null}},title:Q,tr:Q,track:{attrs:{src:null,label:null,default:null,kind:[`subtitles`,`captions`,`descriptions`,`chapters`,`metadata`],srclang:null}},ul:{children:[`li`,`script`,`template`,`ul`,`ol`]},var:Q,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`auto`,`metadata`,`none`],autoplay:[`autoplay`],mediagroup:[`movie`],muted:[`muted`],controls:[`controls`]}},wbr:Q},rg={accesskey:null,class:null,contenteditable:tg,contextmenu:null,dir:[`ltr`,`rtl`,`auto`],draggable:[`true`,`false`,`auto`],dropzone:[`copy`,`move`,`link`,`string:`,`file:`],hidden:[`hidden`],id:null,inert:[`inert`],itemid:null,itemprop:null,itemref:null,itemscope:[`itemscope`],itemtype:null,lang:[`ar`,`bn`,`de`,`en-GB`,`en-US`,`es`,`fr`,`hi`,`id`,`ja`,`pa`,`pt`,`ru`,`tr`,`zh`],spellcheck:tg,autocorrect:tg,autocapitalize:tg,style:null,tabindex:null,title:null,translate:[`yes`,`no`],rel:[`stylesheet`,`alternate`,`author`,`bookmark`,`help`,`license`,`next`,`nofollow`,`noreferrer`,`prefetch`,`prev`,`search`,`tag`],role:`alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer`.split(` `),"aria-activedescendant":null,"aria-atomic":tg,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":tg,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":tg,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":tg,"aria-hidden":tg,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":tg,"aria-multiselectable":tg,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":tg,"aria-relevant":null,"aria-required":tg,"aria-selected":[`true`,`false`,`undefined`],"aria-setsize":null,"aria-sort":[`ascending`,`descending`,`none`,`other`],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},ig=`beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload`.split(` `).map(e=>`on`+e);for(let e of ig)rg[e]=null;var ag=class{constructor(e,t){this.tags={...ng,...e},this.globalAttrs={...rg,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};ag.default=new ag;function og(e,t,n=e.length){if(!t)return``;let r=t.firstChild,i=r&&r.getChild(`TagName`);return i?e.sliceString(i.from,Math.min(i.to,n)):``}function sg(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`)if(t)t=!1;else return e;return null}function cg(e,t,n){return n.tags[og(e,sg(t))]?.children||n.allTags}function lg(e,t){let n=[];for(let r=sg(t);r&&!r.type.isTop;r=sg(r.parent)){let i=og(e,r);if(i&&r.lastChild.name==`CloseTag`)break;i&&n.indexOf(i)<0&&(t.name==`EndTag`||t.from>=r.firstChild.to)&&n.push(i)}return n}const ug=/^[:\-\.\w\u00b7-\uffff]*$/;function dg(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=sg(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:cg(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(lg(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function fg(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:lg(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:ug}}function pg(e,t,n,r){let i=[],a=0;for(let r of cg(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of lg(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function mg(e,t,n,r,i){let a=sg(n),o=a?t.tags[og(e.doc,a)]:null,s=o&&o.attrs?Object.keys(o.attrs):[];return{from:r,to:i,options:(o&&o.globalAttrs===!1?s:s.length?s.concat(t.globalAttrNames):t.globalAttrNames).map(e=>({label:e,type:`property`})),validFor:ug}}function hg(e,t,n,r,i){let a=n.parent?.getChild(`AttributeName`),o=[],s;if(a){let c=e.sliceDoc(a.from,a.to),l=t.globalAttrs[c];if(!l){let r=sg(n),i=r?t.tags[og(e.doc,r)]:null;l=i?.attrs&&i.attrs[c]}if(l){let t=e.sliceDoc(r,i).toLowerCase(),n=`"`,a=`"`;/^['"]/.test(t)?(s=t[0]==`"`?/^[^"]*$/:/^[^']*$/,n=``,a=e.sliceDoc(i,i+1)==t[0]?``:t[0],t=t.slice(1),r++):s=/^[^\s<>='"]*$/;for(let e of l)o.push({label:e,apply:n+e+a,type:`constant`})}}return{from:r,to:i,options:o,validFor:s}}function gg(e,t){let{state:n,pos:r}=t,i=Y(n).resolveInner(r,-1),a=i.resolve(r);for(let e=r,t;a==i&&(t=i.childBefore(e));){let n=t.lastChild;if(!n||!n.type.isError||n.from<n.to)break;a=i=t,e=n.from}return i.name==`TagName`?i.parent&&/CloseTag$/.test(i.parent.name)?fg(n,i,i.from,r):dg(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?dg(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?fg(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?mg(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?hg(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?pg(n,e,i,r):null}function _g(e){return gg(ag.default,e)}function vg(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new ag(t,n):ag.default;return e=>gg(r,e)}const yg=Rh.parser.configure({top:`SingleExpression`}),bg=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:Bh.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:Vh.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:Hh.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:yg},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:Rh.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:fh.parser}],xg=[{name:`style`,parser:fh.parser.configure({top:`Styles`})}].concat(ig.map(e=>({name:e,parser:Rh.parser}))),Sg=Nu.define({name:`html`,parser:jm.configure({props:[Zu.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let n=e.node;;){let e=n.lastChild;if(!e||e.name!=`Element`||e.to!=n.to)break;t=n=e}return t&&!((n=t.lastChild)&&(n.name==`CloseTag`||n.name==`SelfClosingTag`))?e.lineIndent(t.from)+e.unit:null}}),dd.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!=`OpenTag`?null:{from:t.to,to:n.name==`CloseTag`?n.from:e.to}}}),bd.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),Cg=Sg.configure({wrap:Fm(bg,xg)});function wg(e={}){let t=``,n;return e.matchClosingTags===!1&&(t=`noMatch`),e.selfClosingTags===!0&&(t=(t?t+` `:``)+`selfClosing`),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=Fm((e.nestedLanguages||[]).concat(bg),(e.nestedAttributes||[]).concat(xg))),new Uu(n?Sg.configure({wrap:n,dialect:t}):t?Cg.configure({dialect:t}):Cg,[Cg.data.of({autocomplete:vg(e)}),e.autoCloseTags===!1?[]:Dg,Kh().support,ph().support])}const Tg=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `));function Eg(e,t,n){for(;;){if(t.lastChild?.name!=`CloseTag`)return!1;let r=t.parent;if(!r||og(e,r)!=n)return!0;t=r}}const Dg=H.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!Cg.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let t=o.doc.sliceString(e.from-1,e.to)==r,{head:n}=e,i=Y(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if((a=og(o.doc,t.parent,n))&&!Tg.has(a)&&!Eg(o.doc,t.parent,a))return{range:e,changes:{from:n,to:n+ +(o.doc.sliceString(n,n+1)===`>`),insert:`</${a}>`}}}else if(t&&r==`/`&&i.name==`IncompleteCloseTag`){let e=i.parent;if(i.from==n-2&&e.lastChild?.name!=`CloseTag`&&(a=og(o.doc,e,n))&&!Tg.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:j.cursor(n+t.length,-1),changes:{from:n,to:e,insert:t}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),Og=ku({commentTokens:{block:{open:`<!--`,close:`-->`}}}),kg=new U,Ag=up.configure({props:[dd.add(e=>!e.is(`Block`)||e.is(`Document`)||jg(e)!=null||Mg(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),kg.add(jg),Zu.add({Document:()=>null}),Ou.add({Document:Og})]});function jg(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function Mg(e){return e.name==`OrderedList`||e.name==`BulletList`}function Ng(e,t){let n=e;for(;;){let e=n.nextSibling,r;if(!e||(r=jg(e.type))!=null&&r<=t)break;n=e}return n.to}const Pg=ud.of((e,t,n)=>{for(let r=Y(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let e=r.type.prop(kg);if(e==null)continue;let t=Ng(r,e);if(t>n)return{from:n,to:t}}return null});function Fg(e){return new ju(Og,e,[],`markdown`)}const Ig=Fg(Ag),Lg=Fg(Ag.configure([Ap,Np,Mp,Pp,{props:[dd.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]));function Rg(e,t){return n=>{if(n&&e){let t=null;if(n=/\S*/.exec(n)[0],t=typeof e==`function`?e(n):Wu.matchLanguageName(e,n,!0),t instanceof Wu)return t.support?t.support.language.parser:Iu.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}var zg=class{constructor(e,t,n,r,i,a,o){this.node=e,this.from=t,this.to=n,this.spaceBefore=r,this.spaceAfter=i,this.type=a,this.item=o}blank(e,t=!0){let n=this.spaceBefore+(this.node.name==`Blockquote`?`>`:``);if(e!=null){for(;n.length<e;)n+=` `;return n}else{for(let e=this.to-this.from-n.length-this.spaceAfter.length;e>0;e--)n+=` `;return n+(t?this.spaceAfter:``)}}marker(e,t){let n=this.node.name==`OrderedList`?String(+Vg(this.item,e)[2]+t):``;return this.spaceBefore+n+this.type+this.spaceAfter}};function Bg(e,t){let n=[],r=[];for(let t=e;t;t=t.parent){if(t.name==`FencedCode`)return r;(t.name==`ListItem`||t.name==`Blockquote`)&&n.push(t)}for(let e=n.length-1;e>=0;e--){let i=n[e],a,o=t.lineAt(i.from),s=i.from-o.from;if(i.name==`Blockquote`&&(a=/^ *>( ?)/.exec(o.text.slice(s))))r.push(new zg(i,s,s+a[0].length,``,a[1],`>`,null));else if(i.name==`ListItem`&&i.parent.name==`OrderedList`&&(a=/^( *)\d+([.)])( *)/.exec(o.text.slice(s)))){let e=a[3],t=a[0].length;e.length>=4&&(e=e.slice(0,e.length-4),t-=4),r.push(new zg(i.parent,s,s+t,a[1],e,a[2],i))}else if(i.name==`ListItem`&&i.parent.name==`BulletList`&&(a=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(o.text.slice(s)))){let e=a[4],t=a[0].length;e.length>4&&(e=e.slice(0,e.length-4),t-=4);let n=a[2];a[3]&&(n+=a[3].replace(/[xX]/,` `)),r.push(new zg(i.parent,s,s+t,a[1],e,n,i))}}return r}function Vg(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function Hg(e,t,n,r=0){for(let i=-1,a=e;;){if(a.name==`ListItem`){let e=Vg(a,t),o=+e[2];if(i>=0){if(o!=i+1)return;n.push({from:a.from+e[1].length,to:a.from+e[0].length,insert:String(i+2+r)})}i=o}let e=a.nextSibling;if(!e)break;a=e}}function Ug(e,t){let n=/^[ \t]*/.exec(e)[0].length;if(!n||t.facet(Ku)!=` `)return e;let r=Cr(e,4,n),i=``;for(let e=r;e>0;)e>=4?(i+=` `,e-=4):(i+=` `,e--);return i+e.slice(n)}const Wg=((e={})=>({state:t,dispatch:n})=>{let r=Y(t),{doc:i}=t,a=null,o=t.changeByRange(n=>{if(!n.empty||!Lg.isActiveAt(t,n.from,-1)&&!Lg.isActiveAt(t,n.from,1))return a={range:n};let o=n.from,s=i.lineAt(o),c=Bg(r.resolveInner(o,-1),i);for(;c.length&&c[c.length-1].from>o-s.from;)c.pop();if(!c.length)return a={range:n};let l=c[c.length-1];if(l.to-l.spaceAfter.length>o-s.from)return a={range:n};let u=o>=l.to-l.spaceAfter.length&&!/\S/.test(s.text.slice(l.to));if(l.item&&u){if(l.item.from<s.from&&!/^[\s>]*$/.test(s.text.slice(0,l.to)))return a={range:n};let r=l.node.firstChild,u=l.node.getChild(`ListItem`,`ListItem`);if(r.to>=o||u&&u.to<o||s.from>0&&!/[^\s>]/.test(i.lineAt(s.from-1).text)||e.nonTightLists===!1){let e=c.length>1?c[c.length-2]:null,t,n=``;e&&e.item?(t=s.from+e.from,n=e.marker(i,1)):t=s.from+(e?e.to:0);let r=[{from:t,to:o,insert:n}];return l.node.name==`OrderedList`&&Hg(l.item,i,r,-2),e&&e.node.name==`OrderedList`&&Hg(e.item,i,r),{range:j.cursor(t+n.length),changes:r}}else{let e=qg(c,t,s);return{range:j.cursor(o+e.length+1),changes:{from:s.from,insert:e+t.lineBreak}}}}if(l.node.name==`Blockquote`&&u&&s.from){let e=i.lineAt(s.from-1),r=/>\s*$/.exec(e.text);if(r&&r.index==l.from){let i=t.changes([{from:e.from+r.index,to:e.to},{from:s.from+l.from,to:s.to}]);return{range:n.map(i),changes:i}}}let d=[];l.node.name==`OrderedList`&&Hg(l.item,i,d);let f=l.item&&l.item.from<s.from,p=``;if(!f||/^[\s\d.)\-+*>]*/.exec(s.text)[0].length>=l.to)for(let e=0,t=c.length-1;e<=t;e++)p+=e==t&&!f?c[e].marker(i,1):c[e].blank(e<t?Cr(s.text,4,c[e+1].from)-p.length:null);let m=o;for(;m>s.from&&/\s/.test(s.text.charAt(m-s.from-1));)m--;return p=Ug(p,t),Kg(l.node,t.doc)&&(p=qg(c,t,s)+t.lineBreak+p),d.push({from:m,to:o,insert:t.lineBreak+p}),{range:j.cursor(m+p.length+1),changes:d}});return a?!1:(n(t.update(o,{scrollIntoView:!0,userEvent:`input`})),!0)})();function Gg(e){return e.name==`QuoteMark`||e.name==`ListMark`}function Kg(e,t){if(e.name!=`OrderedList`&&e.name!=`BulletList`)return!1;let n=e.firstChild,r=e.getChild(`ListItem`,`ListItem`);if(!r)return!1;let i=t.lineAt(n.to),a=t.lineAt(r.from),o=/^[\s>]*$/.test(i.text);return i.number+ +!o<a.number}function qg(e,t,n){let r=``;for(let t=0,i=e.length-2;t<=i;t++)r+=e[t].blank(t<i?Cr(n.text,4,e[t+1].from)-r.length:null,t<i);return Ug(r,t)}function Jg(e,t){let n=e.resolveInner(t,-1),r=t;Gg(n)&&(r=n.from,n=n.parent);for(let e;e=n.childBefore(r);)if(Gg(e))r=e.from;else if(e.name==`OrderedList`||e.name==`BulletList`)n=e.lastChild,r=n.to;else break;return n}const Yg=[{key:`Enter`,run:Wg},{key:`Backspace`,run:({state:e,dispatch:t})=>{let n=Y(e),r=null,i=e.changeByRange(t=>{let i=t.from,{doc:a}=e;if(t.empty&&Lg.isActiveAt(e,t.from)){let t=a.lineAt(i),r=Bg(Jg(n,i),a);if(r.length){let n=r[r.length-1],a=n.to-n.spaceAfter.length+ +!!n.spaceAfter;if(i-t.from>a&&!/\S/.test(t.text.slice(a,i-t.from)))return{range:j.cursor(t.from+a),changes:{from:t.from+a,to:i}};if(i-t.from==a&&(n.item&&t.from<=n.item.from||/^[\s>]*$/.test(t.text.slice(0,n.to)))){let r=t.from+n.from;if(n.item&&n.node.from<n.item.from&&/\S/.test(t.text.slice(n.from,n.to))){let i=n.blank(Cr(t.text,4,n.to)-Cr(t.text,4,n.from));return r==t.from&&(i=Ug(i,e)),{range:j.cursor(r+i.length),changes:{from:r,to:t.from+n.to,insert:i}}}if(r<i)return{range:j.cursor(r),changes:{from:r,to:i}}}}}return r={range:t}});return r?!1:(t(e.update(i,{scrollIntoView:!0,userEvent:`delete`})),!0)}}],Xg=wg({matchClosingTags:!1});function Zg(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=Ig,completeHTMLTags:a=!0,pasteURLAsLink:o=!0,htmlTagLanguage:s=Xg}=e;if(!(i instanceof Rf))throw RangeError("Base parser provided to `markdown` should be a Markdown parser");let c=e.extensions?[e.extensions]:[],l=[s.support,Pg],u;o&&l.push(n_),n instanceof Uu?(l.push(n.support),u=n.language):n&&(u=n);let d=t||u?Rg(t,u):void 0;c.push(fp({codeParser:d,htmlParser:s.language.parser})),r&&l.push(En.high(Lc.of(Yg)));let f=Fg(i.configure(c));return a&&l.push(f.data.of({autocomplete:Qg})),new Uu(f,l)}function Qg(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let i=Y(t).resolveInner(n,-1);for(;i&&!i.type.isTop;){if(i.name==`CodeBlock`||i.name==`FencedCode`||i.name==`ProcessingInstructionBlock`||i.name==`CommentBlock`||i.name==`Link`||i.name==`Image`)return null;i=i.parent}return{from:n-r[0].length,to:n,options:e_(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let $g=null;function e_(){if($g)return $g;let e=_g(new Nd(P.create({extensions:Xg}),0,!0));return $g=e?e.options:[]}const t_=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,n_=H.domEventHandlers({paste:(e,t)=>{let{main:n}=t.state.selection;if(n.empty)return!1;let r=e.clipboardData?.getData(`text/plain`);if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r=`https://`+r),!Lg.isActiveAt(t.state,n.from,1)))return!1;let i=Y(t.state),a=!1;return i.iterate({from:n.from,to:n.to,enter:e=>{(e.from>n.from||t_.test(e.name))&&(a=!0)},leave:e=>{e.to<n.to&&(a=!0)}}),a?!1:(t.dispatch({changes:[{from:n.from,insert:`[`},{from:n.to,insert:`](${r})`}],userEvent:`input.paste`,scrollIntoView:!0}),!0)}}),r_=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=c_(e.state,n.from);return r.line?a_(e):r.block?s_(e):!1};function i_(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}const a_=i_(f_,0),o_=i_(d_,0),s_=i_((e,t)=>d_(e,t,u_(t)),0);function c_(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}function l_(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-50,r),o=e.sliceDoc(i,i+50),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=100?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+50),d=e.sliceDoc(i-50,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function u_(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function d_(e,t,n=t.selection.ranges){let r=n.map(e=>c_(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>l_(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function f_(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=c_(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}const p_=Vn.define(),m_=Vn.define(),h_=M.define(),g_=M.define({combine(e){return ir(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),__=Cn.define({create(){return F_.empty},update(e,t){let n=t.state.facet(g_),r=t.annotation(p_);if(r){let i=w_.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?T_(o,o.length,n.minDepth,i):A_(o,t.startState.selection),new F_(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(m_);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(Wn.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=w_.fromTransaction(t),o=t.annotation(Wn.time),s=t.annotation(Wn.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new F_(e.done.map(w_.fromJSON),e.undone.map(w_.fromJSON))}});function v_(e={}){return[__,g_.of(e),H.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?b_:e.inputType==`historyRedo`?x_:null;return n?(e.preventDefault(),n(t)):!1}})]}function y_(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(__,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}const b_=y_(0,!1),x_=y_(1,!1),S_=y_(0,!0),C_=y_(1,!0);var w_=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&sn.fromJSON(t.changes),[],t.mapped&&on.fromJSON(t.mapped),t.startSelection&&j.fromJSON(t.startSelection),t.selectionsAfter.map(j.fromJSON))}static fromTransaction(t,n){let r=k_;for(let e of t.startState.facet(h_)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,k_)}static selection(t){return new e(void 0,k_,void 0,void 0,t)}};function T_(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function E_(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function D_(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function O_(e,t){return e.length?t.length?e.concat(t):e:t}const k_=[];function A_(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-200));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),T_(e,e.length-1,1e9,n.setSelAfter(r)))}else return[w_.selection([t])]}function j_(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function M_(e,t){if(!e.length)return e;let n=e.length,r=k_;for(;n;){let i=N_(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[w_.selection(r)]:k_}function N_(e,t,n){let r=O_(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):k_,n);if(!e.changes)return w_.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new w_(i,N.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const P_=/^(input\.type|delete)($|\.)/;var F_=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||P_.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,E_(s.changes,t.changes))||r==`input.type.compose`)?T_(o,o.length-1,i.minDepth,new w_(t.changes.compose(s.changes),O_(N.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,k_)):T_(o,o.length,i.minDepth,t),new e(o,k_,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:k_;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&D_(a[a.length-1],t)?this:new e(A_(this.done,t),this.undone,n,r)}addMapping(t){return new e(M_(this.done,t),M_(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:p_.of({side:e,rest:j_(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?k_:r.slice(0,r.length-1);return i.mapped&&(n=M_(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:p_.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};F_.empty=new F_(k_,k_);const I_=[{key:`Mod-z`,run:b_,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:x_,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:x_,preventDefault:!0},{key:`Mod-u`,run:S_,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:C_,preventDefault:!0}];function L_(e,t){return j.create(e.ranges.map(t),e.mainIndex)}function R_(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function z_({state:e,dispatch:t},n){let r=L_(e.selection,n);return r.eq(e.selection,!0)?!1:(t(R_(e,r)),!0)}function B_(e,t){return j.cursor(t?e.to:e.from)}function V_(e,t){return z_(e,n=>n.empty?e.moveByChar(n,t):B_(n,t))}function H_(e){return e.textDirectionAt(e.state.selection.main.head)==R.LTR}const U_=e=>V_(e,!H_(e)),W_=e=>V_(e,H_(e));function G_(e,t){return z_(e,n=>n.empty?e.moveByGroup(n,t):B_(n,t))}const K_=e=>G_(e,!H_(e)),q_=e=>G_(e,H_(e));typeof Intl<`u`&&Intl.Segmenter;function J_(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Y_(e,t,n){let r=Y(e).resolveInner(t.head),i=n?U.closedBy:U.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;J_(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?Cd(e,r.from,1):Cd(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,j.cursor(s,n?-1:1)}const X_=e=>z_(e,t=>Y_(e.state,t,!H_(e))),Z_=e=>z_(e,t=>Y_(e.state,t,H_(e)));function Q_(e,t){return z_(e,n=>{if(!n.empty)return B_(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}const $_=e=>Q_(e,!1),ev=e=>Q_(e,!0);function tv(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(H.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function nv(e,t){let n=tv(e),{state:r}=e,i=L_(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):B_(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=H.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(R_(r,i),{effects:a}),!0}const rv=e=>nv(e,!1),iv=e=>nv(e,!0);function av(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=j.cursor(r.from+n))}return i}const ov=e=>z_(e,t=>av(e,t,!0)),sv=e=>z_(e,t=>av(e,t,!1)),cv=e=>z_(e,t=>av(e,t,!H_(e))),lv=e=>z_(e,t=>av(e,t,H_(e))),uv=e=>z_(e,t=>j.cursor(e.lineBlockAt(t.head).from,1)),dv=e=>z_(e,t=>j.cursor(e.lineBlockAt(t.head).to,-1));function fv(e,t,n){let r=!1,i=L_(e.selection,t=>{let i=Cd(e,t.head,-1)||Cd(e,t.head,1)||t.head>0&&Cd(e,t.head-1,1)||t.head<e.doc.length&&Cd(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?j.range(t.anchor,a):j.cursor(a)});return r?(t(R_(e,i)),!0):!1}const pv=({state:e,dispatch:t})=>fv(e,t,!1);function mv(e,t,n){let r=L_(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=j.range(e.head,e.anchor));let r=n(e);return j.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return r.eq(e.state.selection)?!1:(e.dispatch(R_(e.state,r)),!0)}function hv(e,t){return mv(e,t,n=>e.moveByChar(n,t))}const gv=e=>hv(e,!H_(e)),_v=e=>hv(e,H_(e));function vv(e,t){return mv(e,t,n=>e.moveByGroup(n,t))}const yv=e=>vv(e,!H_(e)),bv=e=>vv(e,H_(e)),xv=e=>{let t=!H_(e);return mv(e,t,n=>Y_(e.state,n,t))},Sv=e=>{let t=H_(e);return mv(e,t,n=>Y_(e.state,n,t))};function Cv(e,t){return mv(e,t,n=>e.moveVertically(n,t))}const wv=e=>Cv(e,!1),Tv=e=>Cv(e,!0);function Ev(e,t){return mv(e,t,n=>e.moveVertically(n,t,tv(e).height))}const Dv=e=>Ev(e,!1),Ov=e=>Ev(e,!0),kv=e=>mv(e,!0,t=>av(e,t,!0)),Av=e=>mv(e,!1,t=>av(e,t,!1)),jv=e=>{let t=!H_(e);return mv(e,t,n=>av(e,n,t))},Mv=e=>{let t=H_(e);return mv(e,t,n=>av(e,n,t))},Nv=e=>mv(e,!1,t=>j.cursor(e.lineBlockAt(t.head).from)),Pv=e=>mv(e,!0,t=>j.cursor(e.lineBlockAt(t.head).to)),Fv=({state:e,dispatch:t})=>(t(R_(e,{anchor:0})),!0),Iv=({state:e,dispatch:t})=>(t(R_(e,{anchor:e.doc.length})),!0),Lv=({state:e,dispatch:t})=>(t(R_(e,{anchor:e.selection.main.anchor,head:0})),!0),Rv=({state:e,dispatch:t})=>(t(R_(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),zv=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Bv=({state:e,dispatch:t})=>{let n=ay(e).map(({from:t,to:n})=>j.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:j.create(n),userEvent:`select`})),!0},Vv=({state:e,dispatch:t})=>{let n=L_(e.selection,t=>{let n=Y(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return j.undirectionalRange(n.from,n.to)}return t});return n.eq(e.selection)?!1:(t(R_(e,n)),!0)};function Hv(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(R_(n,j.create(i,i.length-1))),!0)}const Uv=e=>Hv(e,!1),Wv=e=>Hv(e,!0),Gv=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=j.create([n.main]):n.main.empty||(r=j.create([j.cursor(n.main.head)])),r?(t(R_(e,r)),!0):!1};function Kv(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=qv(e,o,!1)):o>i&&(n=`delete.forward`,o=qv(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=qv(e,i,!1),a=qv(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:j.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?H.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function qv(e,t,n){if(e instanceof H)for(let r of e.state.facet(H.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}const Jv=(e,t,n)=>Kv(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=Cr(s,a.tabSize)%qu(a)||qu(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=A(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=A(o.text,c-o.from,!1,!1)+o.from);return c}),Yv=e=>Jv(e,!1,!0),Xv=e=>Jv(e,!0,!1),Zv=(e,t)=>Kv(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=A(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Qv=e=>Zv(e,!1),$v=e=>Zv(e,!0),ey=e=>Kv(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ty=e=>Kv(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),ny=e=>Kv(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ry=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:k.of([``,``])},range:j.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},iy=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:A(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:A(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:j.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function ay(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function oy(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of ay(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(j.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(j.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:j.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}const sy=({state:e,dispatch:t})=>oy(e,t,!1),cy=({state:e,dispatch:t})=>oy(e,t,!0);function ly(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of ay(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}const uy=({state:e,dispatch:t})=>ly(e,t,!1),dy=({state:e,dispatch:t})=>ly(e,t,!0),fy=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(ay(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=L_(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function py(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Y(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(U.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}const my=gy(!1),hy=gy(!0);function gy(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&py(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new Xu(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Yu(s,r);for(c??=Cr(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,Ju(t,c)];return o&&l.push(Ju(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:k.of(l)},range:j.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function _y(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:j.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const vy=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Xu(e,{overrideIndentation:e=>n[e]??-1}),i=_y(e,(t,i,a)=>{let o=Yu(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=Ju(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},yy=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(_y(e,(t,n)=>{n.push({from:t.from,insert:e.facet(Ku)})}),{userEvent:`input.indent`})),!0),by=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(_y(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=Cr(r,e.tabSize),a=0,o=Ju(e,Math.max(0,i-qu(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),xy=e=>(e.setTabFocusMode(),!0),Sy=[{key:`Ctrl-b`,run:U_,shift:gv,preventDefault:!0},{key:`Ctrl-f`,run:W_,shift:_v},{key:`Ctrl-p`,run:$_,shift:wv},{key:`Ctrl-n`,run:ev,shift:Tv},{key:`Ctrl-a`,run:uv,shift:Nv},{key:`Ctrl-e`,run:dv,shift:Pv},{key:`Ctrl-d`,run:Xv},{key:`Ctrl-h`,run:Yv},{key:`Ctrl-k`,run:ey},{key:`Ctrl-Alt-h`,run:Qv},{key:`Ctrl-o`,run:ry},{key:`Ctrl-t`,run:iy},{key:`Ctrl-v`,run:iv}],Cy=[{key:`ArrowLeft`,run:U_,shift:gv,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:K_,shift:yv,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:cv,shift:jv,preventDefault:!0},{key:`ArrowRight`,run:W_,shift:_v,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:q_,shift:bv,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:lv,shift:Mv,preventDefault:!0},{key:`ArrowUp`,run:$_,shift:wv,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Fv,shift:Lv},{mac:`Ctrl-ArrowUp`,run:rv,shift:Dv},{key:`ArrowDown`,run:ev,shift:Tv,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:Iv,shift:Rv},{mac:`Ctrl-ArrowDown`,run:iv,shift:Ov},{key:`PageUp`,run:rv,shift:Dv},{key:`PageDown`,run:iv,shift:Ov},{key:`Home`,run:sv,shift:Av,preventDefault:!0},{key:`Mod-Home`,run:Fv,shift:Lv},{key:`End`,run:ov,shift:kv,preventDefault:!0},{key:`Mod-End`,run:Iv,shift:Rv},{key:`Enter`,run:my,shift:my},{key:`Mod-a`,run:zv},{key:`Backspace`,run:Yv,shift:Yv,preventDefault:!0},{key:`Delete`,run:Xv,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Qv,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:$v,preventDefault:!0},{mac:`Mod-Backspace`,run:ty,preventDefault:!0},{mac:`Mod-Delete`,run:ny,preventDefault:!0}].concat(Sy.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),wy=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:X_,shift:xv},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Z_,shift:Sv},{key:`Alt-ArrowUp`,run:sy},{key:`Shift-Alt-ArrowUp`,run:uy},{key:`Alt-ArrowDown`,run:cy},{key:`Shift-Alt-ArrowDown`,run:dy},{key:`Mod-Alt-ArrowUp`,run:Uv},{key:`Mod-Alt-ArrowDown`,run:Wv},{key:`Escape`,run:Gv},{key:`Mod-Enter`,run:hy},{key:`Alt-l`,mac:`Ctrl-l`,run:Bv},{key:`Mod-i`,run:Vv,preventDefault:!0},{key:`Mod-[`,run:by},{key:`Mod-]`,run:yy},{key:`Mod-Alt-\\`,run:vy},{key:`Shift-Mod-k`,run:fy},{key:`Shift-Mod-\\`,run:pv},{key:`Mod-/`,run:r_},{key:`Alt-A`,mac:`Ctrl-A`,run:o_},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:xy}].concat(Cy),Ty=`var(--dsw-alias-brand-primary, #3e63dd)`,Ey=`color-mix(in srgb, var(--dsw-alias-brand-primary, #3e63dd) 55%, transparent)`,Dy=`var(--dsw-alias-label-dimmed, #999)`,Oy=`ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace`,ky=pd.define([{tag:[J.heading1,J.heading2,J.heading3,J.heading4,J.heading5,J.heading6],color:Ty,fontWeight:`700`},{tag:J.processingInstruction,color:Ey},{tag:J.monospace,fontFamily:Oy,backgroundColor:`color-mix(in srgb, var(--dsw-alias-label-secondary, #888) 12%, transparent)`,borderRadius:`4px`,padding:`0 3px`},{tag:J.content,fontFamily:Oy,backgroundColor:`color-mix(in srgb, var(--dsw-alias-label-secondary, #888) 8%, transparent)`},{tag:J.strong,fontWeight:`700`},{tag:J.emphasis,fontStyle:`italic`},{tag:J.strikethrough,textDecoration:`line-through`,opacity:`.75`},{tag:J.link,color:Ty,textDecoration:`underline`},{tag:J.url,color:Ey,textDecoration:`underline dotted`},{tag:J.quote,fontStyle:`italic`,color:`var(--dsw-alias-label-secondary, #888)`},{tag:J.contentSeparator,color:Dy,textDecoration:`line-through`},{tag:J.comment,color:Dy}]);function Ay(e={}){let t=document.createElement(`div`);t.className=`dsh-tw-note-editor`;let n=new H({parent:t,state:P.create({doc:``,extensions:[H.lineWrapping,v_(),Zg({base:Lg}),_d(ky),$c(),sl(e.placeholder??``),Lc.of([...wy,...I_,{key:`Mod-Enter`,run:()=>(e.onSave?.(),!0)}]),H.updateListener.of(t=>{t.docChanged&&e.onChange?.()})]})});return{el:t,view:n,getValue:()=>n.state.doc.toString(),setValue(e){n.dispatch({changes:{from:0,to:n.state.doc.length,insert:e}})},insertAtCaret(e){let{from:t}=n.state.selection.main,r=`${t===n.state.doc.lineAt(t).from?``:`
770
+ }`,{label:`enum`,detail:`definition`,type:`keyword`})]),kh=new Il,Ah=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function jh(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}const Mh=[`FunctionDeclaration`],Nh={FunctionDeclaration:jh(`function`),ClassDeclaration:jh(`class`),ClassExpression:()=>!0,EnumDeclaration:jh(`constant`),TypeAliasDeclaration:jh(`type`),NamespaceDeclaration:jh(`namespace`),VariableDefinition(e,t){e.matchContext(Mh)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function Ph(e,t){let n=kh.get(t);if(n)return n;let r=[],i=!0;function a(t,n){let i=e.sliceString(t.from,t.to);r.push({label:i,type:n})}return t.cursor(G.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=Nh[t.name];if(e&&e(t,a)||Ah.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of Ph(e,t.node))r.push(n);return!1}}),kh.set(t,r),r}const Fh=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Ih=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function Lh(e){let t=Y(e.state).resolveInner(e.pos,-1);if(Ih.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&Fh.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)Ah.has(n.name)&&(r=r.concat(Ph(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:Fh}}const Rh=Nu.define({name:`javascript`,parser:Eh.configure({props:[Zu.add({IfStatement:ld({except:/^\s*({|else\b)/}),TryStatement:ld({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:cd,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:od({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":ld({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),dd.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":fd,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name==`JSXSelfClosingTag`)return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){let t=e.firstChild?.nextSibling,n=e.lastChild;return!t||t.type.isError?null:{from:t.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:[`(`,`[`,`{`,`'`,`"`,"`"]},commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:`$`}}),zh={test:e=>/^JSX/.test(e.name),facet:ku({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},Bh=Rh.configure({dialect:`ts`},`typescript`),Vh=Rh.configure({dialect:`jsx`,props:[Au.add(e=>e.isTop?[zh]:void 0)]}),Hh=Rh.configure({dialect:`jsx ts`,props:[Au.add(e=>e.isTop?[zh]:void 0)]},`typescript`);let Uh=e=>({label:e,type:`keyword`});const Wh=`break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield`.split(` `).map(Uh),Gh=Wh.concat([`declare`,`implements`,`private`,`protected`,`public`].map(Uh));function Kh(e={}){let t=e.jsx?e.typescript?Hh:Vh:e.typescript?Bh:Rh,n=e.typescript?Oh.concat(Gh):Dh.concat(Wh);return new Uu(t,[Rh.data.of({autocomplete:Ld(Ih,Id(n))}),Rh.data.of({autocomplete:Lh}),e.jsx?Xh:[]])}function qh(e){for(;;){if(e.name==`JSXOpenTag`||e.name==`JSXSelfClosingTag`||e.name==`JSXFragmentTag`)return e;if(e.name==`JSXEscape`||!e.parent)return null;e=e.parent}}function Jh(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name==`JSXIdentifier`||r.name==`JSXBuiltin`||r.name==`JSXNamespacedName`||r.name==`JSXMemberExpression`)return e.sliceString(r.from,Math.min(r.to,n));return``}const Yh=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),Xh=H.inputHandler.of((e,t,n,r,i)=>{if((Yh?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!Rh.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=Y(o).resolveInner(t-1,-1),i;if(n.name==`JSXStartTag`&&(n=n.parent),!(o.doc.sliceString(t-1,t)!=r||n.name==`JSXAttributeValue`&&n.to>t)){if(r==`>`&&n.name==`JSXFragmentTag`)return{range:e,changes:{from:t,insert:`</>`}};if(r==`/`&&n.name==`JSXStartCloseTag`){let e=n.parent,r=e.parent;if(r&&e.from==t-2&&((i=Jh(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:j.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=qh(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=Jh(o.doc,r,t)))return{range:e,changes:{from:t,insert:`</${i}>`}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),Zh=[`_blank`,`_self`,`_top`,`_parent`],Qh=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],$h=[`get`,`post`,`put`,`delete`],eg=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],tg=[`true`,`false`],Q={},ng={a:{attrs:{href:null,ping:null,type:null,media:null,target:Zh,hreflang:null}},abbr:Q,address:Q,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:[`default`,`rect`,`circle`,`poly`]}},article:Q,aside:Q,audio:{attrs:{src:null,mediagroup:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`none`,`metadata`,`auto`],autoplay:[`autoplay`],loop:[`loop`],controls:[`controls`]}},b:Q,base:{attrs:{href:null,target:Zh}},bdi:Q,bdo:Q,blockquote:{attrs:{cite:null}},body:Q,br:Q,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:eg,formmethod:$h,formnovalidate:[`novalidate`],formtarget:Zh,type:[`submit`,`reset`,`button`]}},canvas:{attrs:{width:null,height:null}},caption:Q,center:Q,cite:Q,code:Q,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:[`command`,`checkbox`,`radio`],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:[`disabled`],checked:[`checked`]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:[`disabled`],multiple:[`multiple`]}},datalist:{attrs:{data:null}},dd:Q,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:[`open`]}},dfn:Q,div:Q,dl:Q,dt:Q,em:Q,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:[`disabled`],form:null,name:null}},figcaption:Q,figure:Q,footer:Q,form:{attrs:{action:null,name:null,"accept-charset":Qh,autocomplete:[`on`,`off`],enctype:eg,method:$h,novalidate:[`novalidate`],target:Zh}},h1:Q,h2:Q,h3:Q,h4:Q,h5:Q,h6:Q,head:{children:[`title`,`base`,`link`,`style`,`meta`,`script`,`noscript`,`command`]},header:Q,hgroup:Q,hr:Q,html:{attrs:{manifest:null}},i:Q,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:[`allow-top-navigation`,`allow-same-origin`,`allow-forms`,`allow-scripts`],seamless:[`seamless`]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:[`audio/*`,`video/*`,`image/*`],autocomplete:[`on`,`off`],autofocus:[`autofocus`],checked:[`checked`],disabled:[`disabled`],formenctype:eg,formmethod:$h,formnovalidate:[`novalidate`],formtarget:Zh,multiple:[`multiple`],readonly:[`readonly`],required:[`required`],type:[`hidden`,`text`,`search`,`tel`,`url`,`email`,`password`,`datetime`,`date`,`month`,`week`,`time`,`datetime-local`,`number`,`range`,`color`,`checkbox`,`radio`,`file`,`submit`,`image`,`reset`,`button`]}},ins:{attrs:{cite:null,datetime:null}},kbd:Q,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:[`autofocus`],disabled:[`disabled`],keytype:[`RSA`]}},label:{attrs:{for:null,form:null}},legend:Q,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:[`all`,`16x16`,`16x16 32x32`,`16x16 32x32 64x64`]}},map:{attrs:{name:null}},mark:Q,menu:{attrs:{label:null,type:[`list`,`context`,`toolbar`]}},meta:{attrs:{content:null,charset:Qh,name:[`viewport`,`application-name`,`author`,`description`,`generator`,`keywords`],"http-equiv":[`content-language`,`content-type`,`default-style`,`refresh`]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:Q,noscript:Q,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:[`typemustmatch`]}},ol:{attrs:{reversed:[`reversed`],start:null,type:[`1`,`a`,`A`,`i`,`I`]},children:[`li`,`script`,`template`,`ul`,`ol`]},optgroup:{attrs:{disabled:[`disabled`],label:null}},option:{attrs:{disabled:[`disabled`],label:null,selected:[`selected`],value:null}},output:{attrs:{for:null,form:null,name:null}},p:Q,param:{attrs:{name:null,value:null}},pre:Q,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:Q,rt:Q,ruby:Q,samp:Q,script:{attrs:{type:[`text/javascript`],src:null,async:[`async`],defer:[`defer`],charset:Qh}},section:Q,select:{attrs:{form:null,name:null,size:null,autofocus:[`autofocus`],disabled:[`disabled`],multiple:[`multiple`]}},slot:{attrs:{name:null}},small:Q,source:{attrs:{src:null,type:null,media:null}},span:Q,strong:Q,style:{attrs:{type:[`text/css`],media:null,scoped:null}},sub:Q,summary:Q,sup:Q,table:Q,tbody:Q,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:Q,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:[`autofocus`],disabled:[`disabled`],readonly:[`readonly`],required:[`required`],wrap:[`soft`,`hard`]}},tfoot:Q,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:[`row`,`col`,`rowgroup`,`colgroup`]}},thead:Q,time:{attrs:{datetime:null}},title:Q,tr:Q,track:{attrs:{src:null,label:null,default:null,kind:[`subtitles`,`captions`,`descriptions`,`chapters`,`metadata`],srclang:null}},ul:{children:[`li`,`script`,`template`,`ul`,`ol`]},var:Q,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`auto`,`metadata`,`none`],autoplay:[`autoplay`],mediagroup:[`movie`],muted:[`muted`],controls:[`controls`]}},wbr:Q},rg={accesskey:null,class:null,contenteditable:tg,contextmenu:null,dir:[`ltr`,`rtl`,`auto`],draggable:[`true`,`false`,`auto`],dropzone:[`copy`,`move`,`link`,`string:`,`file:`],hidden:[`hidden`],id:null,inert:[`inert`],itemid:null,itemprop:null,itemref:null,itemscope:[`itemscope`],itemtype:null,lang:[`ar`,`bn`,`de`,`en-GB`,`en-US`,`es`,`fr`,`hi`,`id`,`ja`,`pa`,`pt`,`ru`,`tr`,`zh`],spellcheck:tg,autocorrect:tg,autocapitalize:tg,style:null,tabindex:null,title:null,translate:[`yes`,`no`],rel:[`stylesheet`,`alternate`,`author`,`bookmark`,`help`,`license`,`next`,`nofollow`,`noreferrer`,`prefetch`,`prev`,`search`,`tag`],role:`alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer`.split(` `),"aria-activedescendant":null,"aria-atomic":tg,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":tg,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":tg,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":tg,"aria-hidden":tg,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":tg,"aria-multiselectable":tg,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":tg,"aria-relevant":null,"aria-required":tg,"aria-selected":[`true`,`false`,`undefined`],"aria-setsize":null,"aria-sort":[`ascending`,`descending`,`none`,`other`],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},ig=`beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload`.split(` `).map(e=>`on`+e);for(let e of ig)rg[e]=null;var ag=class{constructor(e,t){this.tags={...ng,...e},this.globalAttrs={...rg,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};ag.default=new ag;function og(e,t,n=e.length){if(!t)return``;let r=t.firstChild,i=r&&r.getChild(`TagName`);return i?e.sliceString(i.from,Math.min(i.to,n)):``}function sg(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`)if(t)t=!1;else return e;return null}function cg(e,t,n){return n.tags[og(e,sg(t))]?.children||n.allTags}function lg(e,t){let n=[];for(let r=sg(t);r&&!r.type.isTop;r=sg(r.parent)){let i=og(e,r);if(i&&r.lastChild.name==`CloseTag`)break;i&&n.indexOf(i)<0&&(t.name==`EndTag`||t.from>=r.firstChild.to)&&n.push(i)}return n}const ug=/^[:\-\.\w\u00b7-\uffff]*$/;function dg(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=sg(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:cg(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(lg(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function fg(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:lg(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:ug}}function pg(e,t,n,r){let i=[],a=0;for(let r of cg(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of lg(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function mg(e,t,n,r,i){let a=sg(n),o=a?t.tags[og(e.doc,a)]:null,s=o&&o.attrs?Object.keys(o.attrs):[];return{from:r,to:i,options:(o&&o.globalAttrs===!1?s:s.length?s.concat(t.globalAttrNames):t.globalAttrNames).map(e=>({label:e,type:`property`})),validFor:ug}}function hg(e,t,n,r,i){let a=n.parent?.getChild(`AttributeName`),o=[],s;if(a){let c=e.sliceDoc(a.from,a.to),l=t.globalAttrs[c];if(!l){let r=sg(n),i=r?t.tags[og(e.doc,r)]:null;l=i?.attrs&&i.attrs[c]}if(l){let t=e.sliceDoc(r,i).toLowerCase(),n=`"`,a=`"`;/^['"]/.test(t)?(s=t[0]==`"`?/^[^"]*$/:/^[^']*$/,n=``,a=e.sliceDoc(i,i+1)==t[0]?``:t[0],t=t.slice(1),r++):s=/^[^\s<>='"]*$/;for(let e of l)o.push({label:e,apply:n+e+a,type:`constant`})}}return{from:r,to:i,options:o,validFor:s}}function gg(e,t){let{state:n,pos:r}=t,i=Y(n).resolveInner(r,-1),a=i.resolve(r);for(let e=r,t;a==i&&(t=i.childBefore(e));){let n=t.lastChild;if(!n||!n.type.isError||n.from<n.to)break;a=i=t,e=n.from}return i.name==`TagName`?i.parent&&/CloseTag$/.test(i.parent.name)?fg(n,i,i.from,r):dg(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?dg(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?fg(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?mg(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?hg(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?pg(n,e,i,r):null}function _g(e){return gg(ag.default,e)}function vg(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new ag(t,n):ag.default;return e=>gg(r,e)}const yg=Rh.parser.configure({top:`SingleExpression`}),bg=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:Bh.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:Vh.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:Hh.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:yg},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:Rh.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:fh.parser}],xg=[{name:`style`,parser:fh.parser.configure({top:`Styles`})}].concat(ig.map(e=>({name:e,parser:Rh.parser}))),Sg=Nu.define({name:`html`,parser:jm.configure({props:[Zu.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let n=e.node;;){let e=n.lastChild;if(!e||e.name!=`Element`||e.to!=n.to)break;t=n=e}return t&&!((n=t.lastChild)&&(n.name==`CloseTag`||n.name==`SelfClosingTag`))?e.lineIndent(t.from)+e.unit:null}}),dd.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!=`OpenTag`?null:{from:t.to,to:n.name==`CloseTag`?n.from:e.to}}}),bd.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),Cg=Sg.configure({wrap:Fm(bg,xg)});function wg(e={}){let t=``,n;return e.matchClosingTags===!1&&(t=`noMatch`),e.selfClosingTags===!0&&(t=(t?t+` `:``)+`selfClosing`),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=Fm((e.nestedLanguages||[]).concat(bg),(e.nestedAttributes||[]).concat(xg))),new Uu(n?Sg.configure({wrap:n,dialect:t}):t?Cg.configure({dialect:t}):Cg,[Cg.data.of({autocomplete:vg(e)}),e.autoCloseTags===!1?[]:Dg,Kh().support,ph().support])}const Tg=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `));function Eg(e,t,n){for(;;){if(t.lastChild?.name!=`CloseTag`)return!1;let r=t.parent;if(!r||og(e,r)!=n)return!0;t=r}}const Dg=H.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!Cg.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let t=o.doc.sliceString(e.from-1,e.to)==r,{head:n}=e,i=Y(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if((a=og(o.doc,t.parent,n))&&!Tg.has(a)&&!Eg(o.doc,t.parent,a))return{range:e,changes:{from:n,to:n+ +(o.doc.sliceString(n,n+1)===`>`),insert:`</${a}>`}}}else if(t&&r==`/`&&i.name==`IncompleteCloseTag`){let e=i.parent;if(i.from==n-2&&e.lastChild?.name!=`CloseTag`&&(a=og(o.doc,e,n))&&!Tg.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:j.cursor(n+t.length,-1),changes:{from:n,to:e,insert:t}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),Og=ku({commentTokens:{block:{open:`<!--`,close:`-->`}}}),kg=new U,Ag=up.configure({props:[dd.add(e=>!e.is(`Block`)||e.is(`Document`)||jg(e)!=null||Mg(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),kg.add(jg),Zu.add({Document:()=>null}),Ou.add({Document:Og})]});function jg(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function Mg(e){return e.name==`OrderedList`||e.name==`BulletList`}function Ng(e,t){let n=e;for(;;){let e=n.nextSibling,r;if(!e||(r=jg(e.type))!=null&&r<=t)break;n=e}return n.to}const Pg=ud.of((e,t,n)=>{for(let r=Y(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let e=r.type.prop(kg);if(e==null)continue;let t=Ng(r,e);if(t>n)return{from:n,to:t}}return null});function Fg(e){return new ju(Og,e,[],`markdown`)}const Ig=Fg(Ag),Lg=Fg(Ag.configure([Ap,Np,Mp,Pp,{props:[dd.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]));function Rg(e,t){return n=>{if(n&&e){let t=null;if(n=/\S*/.exec(n)[0],t=typeof e==`function`?e(n):Wu.matchLanguageName(e,n,!0),t instanceof Wu)return t.support?t.support.language.parser:Iu.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}var zg=class{constructor(e,t,n,r,i,a,o){this.node=e,this.from=t,this.to=n,this.spaceBefore=r,this.spaceAfter=i,this.type=a,this.item=o}blank(e,t=!0){let n=this.spaceBefore+(this.node.name==`Blockquote`?`>`:``);if(e!=null){for(;n.length<e;)n+=` `;return n}else{for(let e=this.to-this.from-n.length-this.spaceAfter.length;e>0;e--)n+=` `;return n+(t?this.spaceAfter:``)}}marker(e,t){let n=this.node.name==`OrderedList`?String(+Vg(this.item,e)[2]+t):``;return this.spaceBefore+n+this.type+this.spaceAfter}};function Bg(e,t){let n=[],r=[];for(let t=e;t;t=t.parent){if(t.name==`FencedCode`)return r;(t.name==`ListItem`||t.name==`Blockquote`)&&n.push(t)}for(let e=n.length-1;e>=0;e--){let i=n[e],a,o=t.lineAt(i.from),s=i.from-o.from;if(i.name==`Blockquote`&&(a=/^ *>( ?)/.exec(o.text.slice(s))))r.push(new zg(i,s,s+a[0].length,``,a[1],`>`,null));else if(i.name==`ListItem`&&i.parent.name==`OrderedList`&&(a=/^( *)\d+([.)])( *)/.exec(o.text.slice(s)))){let e=a[3],t=a[0].length;e.length>=4&&(e=e.slice(0,e.length-4),t-=4),r.push(new zg(i.parent,s,s+t,a[1],e,a[2],i))}else if(i.name==`ListItem`&&i.parent.name==`BulletList`&&(a=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(o.text.slice(s)))){let e=a[4],t=a[0].length;e.length>4&&(e=e.slice(0,e.length-4),t-=4);let n=a[2];a[3]&&(n+=a[3].replace(/[xX]/,` `)),r.push(new zg(i.parent,s,s+t,a[1],e,n,i))}}return r}function Vg(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function Hg(e,t,n,r=0){for(let i=-1,a=e;;){if(a.name==`ListItem`){let e=Vg(a,t),o=+e[2];if(i>=0){if(o!=i+1)return;n.push({from:a.from+e[1].length,to:a.from+e[0].length,insert:String(i+2+r)})}i=o}let e=a.nextSibling;if(!e)break;a=e}}function Ug(e,t){let n=/^[ \t]*/.exec(e)[0].length;if(!n||t.facet(Ku)!=` `)return e;let r=Cr(e,4,n),i=``;for(let e=r;e>0;)e>=4?(i+=` `,e-=4):(i+=` `,e--);return i+e.slice(n)}const Wg=((e={})=>({state:t,dispatch:n})=>{let r=Y(t),{doc:i}=t,a=null,o=t.changeByRange(n=>{if(!n.empty||!Lg.isActiveAt(t,n.from,-1)&&!Lg.isActiveAt(t,n.from,1))return a={range:n};let o=n.from,s=i.lineAt(o),c=Bg(r.resolveInner(o,-1),i);for(;c.length&&c[c.length-1].from>o-s.from;)c.pop();if(!c.length)return a={range:n};let l=c[c.length-1];if(l.to-l.spaceAfter.length>o-s.from)return a={range:n};let u=o>=l.to-l.spaceAfter.length&&!/\S/.test(s.text.slice(l.to));if(l.item&&u){if(l.item.from<s.from&&!/^[\s>]*$/.test(s.text.slice(0,l.to)))return a={range:n};let r=l.node.firstChild,u=l.node.getChild(`ListItem`,`ListItem`);if(r.to>=o||u&&u.to<o||s.from>0&&!/[^\s>]/.test(i.lineAt(s.from-1).text)||e.nonTightLists===!1){let e=c.length>1?c[c.length-2]:null,t,n=``;e&&e.item?(t=s.from+e.from,n=e.marker(i,1)):t=s.from+(e?e.to:0);let r=[{from:t,to:o,insert:n}];return l.node.name==`OrderedList`&&Hg(l.item,i,r,-2),e&&e.node.name==`OrderedList`&&Hg(e.item,i,r),{range:j.cursor(t+n.length),changes:r}}else{let e=qg(c,t,s);return{range:j.cursor(o+e.length+1),changes:{from:s.from,insert:e+t.lineBreak}}}}if(l.node.name==`Blockquote`&&u&&s.from){let e=i.lineAt(s.from-1),r=/>\s*$/.exec(e.text);if(r&&r.index==l.from){let i=t.changes([{from:e.from+r.index,to:e.to},{from:s.from+l.from,to:s.to}]);return{range:n.map(i),changes:i}}}let d=[];l.node.name==`OrderedList`&&Hg(l.item,i,d);let f=l.item&&l.item.from<s.from,p=``;if(!f||/^[\s\d.)\-+*>]*/.exec(s.text)[0].length>=l.to)for(let e=0,t=c.length-1;e<=t;e++)p+=e==t&&!f?c[e].marker(i,1):c[e].blank(e<t?Cr(s.text,4,c[e+1].from)-p.length:null);let m=o;for(;m>s.from&&/\s/.test(s.text.charAt(m-s.from-1));)m--;return p=Ug(p,t),Kg(l.node,t.doc)&&(p=qg(c,t,s)+t.lineBreak+p),d.push({from:m,to:o,insert:t.lineBreak+p}),{range:j.cursor(m+p.length+1),changes:d}});return a?!1:(n(t.update(o,{scrollIntoView:!0,userEvent:`input`})),!0)})();function Gg(e){return e.name==`QuoteMark`||e.name==`ListMark`}function Kg(e,t){if(e.name!=`OrderedList`&&e.name!=`BulletList`)return!1;let n=e.firstChild,r=e.getChild(`ListItem`,`ListItem`);if(!r)return!1;let i=t.lineAt(n.to),a=t.lineAt(r.from),o=/^[\s>]*$/.test(i.text);return i.number+ +!o<a.number}function qg(e,t,n){let r=``;for(let t=0,i=e.length-2;t<=i;t++)r+=e[t].blank(t<i?Cr(n.text,4,e[t+1].from)-r.length:null,t<i);return Ug(r,t)}function Jg(e,t){let n=e.resolveInner(t,-1),r=t;Gg(n)&&(r=n.from,n=n.parent);for(let e;e=n.childBefore(r);)if(Gg(e))r=e.from;else if(e.name==`OrderedList`||e.name==`BulletList`)n=e.lastChild,r=n.to;else break;return n}const Yg=[{key:`Enter`,run:Wg},{key:`Backspace`,run:({state:e,dispatch:t})=>{let n=Y(e),r=null,i=e.changeByRange(t=>{let i=t.from,{doc:a}=e;if(t.empty&&Lg.isActiveAt(e,t.from)){let t=a.lineAt(i),r=Bg(Jg(n,i),a);if(r.length){let n=r[r.length-1],a=n.to-n.spaceAfter.length+ +!!n.spaceAfter;if(i-t.from>a&&!/\S/.test(t.text.slice(a,i-t.from)))return{range:j.cursor(t.from+a),changes:{from:t.from+a,to:i}};if(i-t.from==a&&(n.item&&t.from<=n.item.from||/^[\s>]*$/.test(t.text.slice(0,n.to)))){let r=t.from+n.from;if(n.item&&n.node.from<n.item.from&&/\S/.test(t.text.slice(n.from,n.to))){let i=n.blank(Cr(t.text,4,n.to)-Cr(t.text,4,n.from));return r==t.from&&(i=Ug(i,e)),{range:j.cursor(r+i.length),changes:{from:r,to:t.from+n.to,insert:i}}}if(r<i)return{range:j.cursor(r),changes:{from:r,to:i}}}}}return r={range:t}});return r?!1:(t(e.update(i,{scrollIntoView:!0,userEvent:`delete`})),!0)}}],Xg=wg({matchClosingTags:!1});function Zg(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=Ig,completeHTMLTags:a=!0,pasteURLAsLink:o=!0,htmlTagLanguage:s=Xg}=e;if(!(i instanceof Rf))throw RangeError("Base parser provided to `markdown` should be a Markdown parser");let c=e.extensions?[e.extensions]:[],l=[s.support,Pg],u;o&&l.push(n_),n instanceof Uu?(l.push(n.support),u=n.language):n&&(u=n);let d=t||u?Rg(t,u):void 0;c.push(fp({codeParser:d,htmlParser:s.language.parser})),r&&l.push(En.high(Lc.of(Yg)));let f=Fg(i.configure(c));return a&&l.push(f.data.of({autocomplete:Qg})),new Uu(f,l)}function Qg(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let i=Y(t).resolveInner(n,-1);for(;i&&!i.type.isTop;){if(i.name==`CodeBlock`||i.name==`FencedCode`||i.name==`ProcessingInstructionBlock`||i.name==`CommentBlock`||i.name==`Link`||i.name==`Image`)return null;i=i.parent}return{from:n-r[0].length,to:n,options:e_(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let $g=null;function e_(){if($g)return $g;let e=_g(new Nd(P.create({extensions:Xg}),0,!0));return $g=e?e.options:[]}const t_=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,n_=H.domEventHandlers({paste:(e,t)=>{let{main:n}=t.state.selection;if(n.empty)return!1;let r=e.clipboardData?.getData(`text/plain`);if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r=`https://`+r),!Lg.isActiveAt(t.state,n.from,1)))return!1;let i=Y(t.state),a=!1;return i.iterate({from:n.from,to:n.to,enter:e=>{(e.from>n.from||t_.test(e.name))&&(a=!0)},leave:e=>{e.to<n.to&&(a=!0)}}),a?!1:(t.dispatch({changes:[{from:n.from,insert:`[`},{from:n.to,insert:`](${r})`}],userEvent:`input.paste`,scrollIntoView:!0}),!0)}}),r_=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=c_(e.state,n.from);return r.line?a_(e):r.block?s_(e):!1};function i_(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}const a_=i_(f_,0),o_=i_(d_,0),s_=i_((e,t)=>d_(e,t,u_(t)),0);function c_(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}function l_(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-50,r),o=e.sliceDoc(i,i+50),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=100?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+50),d=e.sliceDoc(i-50,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function u_(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function d_(e,t,n=t.selection.ranges){let r=n.map(e=>c_(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>l_(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function f_(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=c_(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}const p_=Vn.define(),m_=Vn.define(),h_=M.define(),g_=M.define({combine(e){return ir(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),__=Cn.define({create(){return F_.empty},update(e,t){let n=t.state.facet(g_),r=t.annotation(p_);if(r){let i=w_.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?T_(o,o.length,n.minDepth,i):A_(o,t.startState.selection),new F_(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(m_);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(Wn.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=w_.fromTransaction(t),o=t.annotation(Wn.time),s=t.annotation(Wn.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new F_(e.done.map(w_.fromJSON),e.undone.map(w_.fromJSON))}});function v_(e={}){return[__,g_.of(e),H.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?b_:e.inputType==`historyRedo`?x_:null;return n?(e.preventDefault(),n(t)):!1}})]}function y_(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(__,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}const b_=y_(0,!1),x_=y_(1,!1),S_=y_(0,!0),C_=y_(1,!0);var w_=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&cn.fromJSON(t.changes),[],t.mapped&&sn.fromJSON(t.mapped),t.startSelection&&j.fromJSON(t.startSelection),t.selectionsAfter.map(j.fromJSON))}static fromTransaction(t,n){let r=k_;for(let e of t.startState.facet(h_)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,k_)}static selection(t){return new e(void 0,k_,void 0,void 0,t)}};function T_(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function E_(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function D_(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function O_(e,t){return e.length?t.length?e.concat(t):e:t}const k_=[];function A_(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-200));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),T_(e,e.length-1,1e9,n.setSelAfter(r)))}else return[w_.selection([t])]}function j_(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function M_(e,t){if(!e.length)return e;let n=e.length,r=k_;for(;n;){let i=N_(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[w_.selection(r)]:k_}function N_(e,t,n){let r=O_(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):k_,n);if(!e.changes)return w_.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new w_(i,N.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const P_=/^(input\.type|delete)($|\.)/;var F_=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||P_.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,E_(s.changes,t.changes))||r==`input.type.compose`)?T_(o,o.length-1,i.minDepth,new w_(t.changes.compose(s.changes),O_(N.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,k_)):T_(o,o.length,i.minDepth,t),new e(o,k_,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:k_;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&D_(a[a.length-1],t)?this:new e(A_(this.done,t),this.undone,n,r)}addMapping(t){return new e(M_(this.done,t),M_(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:p_.of({side:e,rest:j_(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?k_:r.slice(0,r.length-1);return i.mapped&&(n=M_(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:p_.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};F_.empty=new F_(k_,k_);const I_=[{key:`Mod-z`,run:b_,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:x_,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:x_,preventDefault:!0},{key:`Mod-u`,run:S_,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:C_,preventDefault:!0}];function L_(e,t){return j.create(e.ranges.map(t),e.mainIndex)}function R_(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function z_({state:e,dispatch:t},n){let r=L_(e.selection,n);return r.eq(e.selection,!0)?!1:(t(R_(e,r)),!0)}function B_(e,t){return j.cursor(t?e.to:e.from)}function V_(e,t){return z_(e,n=>n.empty?e.moveByChar(n,t):B_(n,t))}function H_(e){return e.textDirectionAt(e.state.selection.main.head)==R.LTR}const U_=e=>V_(e,!H_(e)),W_=e=>V_(e,H_(e));function G_(e,t){return z_(e,n=>n.empty?e.moveByGroup(n,t):B_(n,t))}const K_=e=>G_(e,!H_(e)),q_=e=>G_(e,H_(e));typeof Intl<`u`&&Intl.Segmenter;function J_(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Y_(e,t,n){let r=Y(e).resolveInner(t.head),i=n?U.closedBy:U.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;J_(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?Cd(e,r.from,1):Cd(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,j.cursor(s,n?-1:1)}const X_=e=>z_(e,t=>Y_(e.state,t,!H_(e))),Z_=e=>z_(e,t=>Y_(e.state,t,H_(e)));function Q_(e,t){return z_(e,n=>{if(!n.empty)return B_(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}const $_=e=>Q_(e,!1),ev=e=>Q_(e,!0);function tv(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(H.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function nv(e,t){let n=tv(e),{state:r}=e,i=L_(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):B_(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=H.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(R_(r,i),{effects:a}),!0}const rv=e=>nv(e,!1),iv=e=>nv(e,!0);function av(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=j.cursor(r.from+n))}return i}const ov=e=>z_(e,t=>av(e,t,!0)),sv=e=>z_(e,t=>av(e,t,!1)),cv=e=>z_(e,t=>av(e,t,!H_(e))),lv=e=>z_(e,t=>av(e,t,H_(e))),uv=e=>z_(e,t=>j.cursor(e.lineBlockAt(t.head).from,1)),dv=e=>z_(e,t=>j.cursor(e.lineBlockAt(t.head).to,-1));function fv(e,t,n){let r=!1,i=L_(e.selection,t=>{let i=Cd(e,t.head,-1)||Cd(e,t.head,1)||t.head>0&&Cd(e,t.head-1,1)||t.head<e.doc.length&&Cd(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?j.range(t.anchor,a):j.cursor(a)});return r?(t(R_(e,i)),!0):!1}const pv=({state:e,dispatch:t})=>fv(e,t,!1);function mv(e,t,n){let r=L_(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=j.range(e.head,e.anchor));let r=n(e);return j.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return r.eq(e.state.selection)?!1:(e.dispatch(R_(e.state,r)),!0)}function hv(e,t){return mv(e,t,n=>e.moveByChar(n,t))}const gv=e=>hv(e,!H_(e)),_v=e=>hv(e,H_(e));function vv(e,t){return mv(e,t,n=>e.moveByGroup(n,t))}const yv=e=>vv(e,!H_(e)),bv=e=>vv(e,H_(e)),xv=e=>{let t=!H_(e);return mv(e,t,n=>Y_(e.state,n,t))},Sv=e=>{let t=H_(e);return mv(e,t,n=>Y_(e.state,n,t))};function Cv(e,t){return mv(e,t,n=>e.moveVertically(n,t))}const wv=e=>Cv(e,!1),Tv=e=>Cv(e,!0);function Ev(e,t){return mv(e,t,n=>e.moveVertically(n,t,tv(e).height))}const Dv=e=>Ev(e,!1),Ov=e=>Ev(e,!0),kv=e=>mv(e,!0,t=>av(e,t,!0)),Av=e=>mv(e,!1,t=>av(e,t,!1)),jv=e=>{let t=!H_(e);return mv(e,t,n=>av(e,n,t))},Mv=e=>{let t=H_(e);return mv(e,t,n=>av(e,n,t))},Nv=e=>mv(e,!1,t=>j.cursor(e.lineBlockAt(t.head).from)),Pv=e=>mv(e,!0,t=>j.cursor(e.lineBlockAt(t.head).to)),Fv=({state:e,dispatch:t})=>(t(R_(e,{anchor:0})),!0),Iv=({state:e,dispatch:t})=>(t(R_(e,{anchor:e.doc.length})),!0),Lv=({state:e,dispatch:t})=>(t(R_(e,{anchor:e.selection.main.anchor,head:0})),!0),Rv=({state:e,dispatch:t})=>(t(R_(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),zv=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Bv=({state:e,dispatch:t})=>{let n=ay(e).map(({from:t,to:n})=>j.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:j.create(n),userEvent:`select`})),!0},Vv=({state:e,dispatch:t})=>{let n=L_(e.selection,t=>{let n=Y(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return j.undirectionalRange(n.from,n.to)}return t});return n.eq(e.selection)?!1:(t(R_(e,n)),!0)};function Hv(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(R_(n,j.create(i,i.length-1))),!0)}const Uv=e=>Hv(e,!1),Wv=e=>Hv(e,!0),Gv=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=j.create([n.main]):n.main.empty||(r=j.create([j.cursor(n.main.head)])),r?(t(R_(e,r)),!0):!1};function Kv(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=qv(e,o,!1)):o>i&&(n=`delete.forward`,o=qv(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=qv(e,i,!1),a=qv(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:j.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?H.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function qv(e,t,n){if(e instanceof H)for(let r of e.state.facet(H.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}const Jv=(e,t,n)=>Kv(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=Cr(s,a.tabSize)%qu(a)||qu(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=$t(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=$t(o.text,c-o.from,!1,!1)+o.from);return c}),Yv=e=>Jv(e,!1,!0),Xv=e=>Jv(e,!0,!1),Zv=(e,t)=>Kv(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=$t(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Qv=e=>Zv(e,!1),$v=e=>Zv(e,!0),ey=e=>Kv(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ty=e=>Kv(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),ny=e=>Kv(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ry=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:k.of([``,``])},range:j.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},iy=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:$t(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:$t(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:j.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function ay(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function oy(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of ay(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(j.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(j.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:j.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}const sy=({state:e,dispatch:t})=>oy(e,t,!1),cy=({state:e,dispatch:t})=>oy(e,t,!0);function ly(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of ay(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}const uy=({state:e,dispatch:t})=>ly(e,t,!1),dy=({state:e,dispatch:t})=>ly(e,t,!0),fy=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(ay(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=L_(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function py(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Y(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(U.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}const my=gy(!1),hy=gy(!0);function gy(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&py(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new Xu(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Yu(s,r);for(c??=Cr(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,Ju(t,c)];return o&&l.push(Ju(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:k.of(l)},range:j.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function _y(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:j.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const vy=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Xu(e,{overrideIndentation:e=>n[e]??-1}),i=_y(e,(t,i,a)=>{let o=Yu(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=Ju(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},yy=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(_y(e,(t,n)=>{n.push({from:t.from,insert:e.facet(Ku)})}),{userEvent:`input.indent`})),!0),by=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(_y(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=Cr(r,e.tabSize),a=0,o=Ju(e,Math.max(0,i-qu(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),xy=e=>(e.setTabFocusMode(),!0),Sy=[{key:`Ctrl-b`,run:U_,shift:gv,preventDefault:!0},{key:`Ctrl-f`,run:W_,shift:_v},{key:`Ctrl-p`,run:$_,shift:wv},{key:`Ctrl-n`,run:ev,shift:Tv},{key:`Ctrl-a`,run:uv,shift:Nv},{key:`Ctrl-e`,run:dv,shift:Pv},{key:`Ctrl-d`,run:Xv},{key:`Ctrl-h`,run:Yv},{key:`Ctrl-k`,run:ey},{key:`Ctrl-Alt-h`,run:Qv},{key:`Ctrl-o`,run:ry},{key:`Ctrl-t`,run:iy},{key:`Ctrl-v`,run:iv}],Cy=[{key:`ArrowLeft`,run:U_,shift:gv,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:K_,shift:yv,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:cv,shift:jv,preventDefault:!0},{key:`ArrowRight`,run:W_,shift:_v,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:q_,shift:bv,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:lv,shift:Mv,preventDefault:!0},{key:`ArrowUp`,run:$_,shift:wv,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Fv,shift:Lv},{mac:`Ctrl-ArrowUp`,run:rv,shift:Dv},{key:`ArrowDown`,run:ev,shift:Tv,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:Iv,shift:Rv},{mac:`Ctrl-ArrowDown`,run:iv,shift:Ov},{key:`PageUp`,run:rv,shift:Dv},{key:`PageDown`,run:iv,shift:Ov},{key:`Home`,run:sv,shift:Av,preventDefault:!0},{key:`Mod-Home`,run:Fv,shift:Lv},{key:`End`,run:ov,shift:kv,preventDefault:!0},{key:`Mod-End`,run:Iv,shift:Rv},{key:`Enter`,run:my,shift:my},{key:`Mod-a`,run:zv},{key:`Backspace`,run:Yv,shift:Yv,preventDefault:!0},{key:`Delete`,run:Xv,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Qv,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:$v,preventDefault:!0},{mac:`Mod-Backspace`,run:ty,preventDefault:!0},{mac:`Mod-Delete`,run:ny,preventDefault:!0}].concat(Sy.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),wy=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:X_,shift:xv},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Z_,shift:Sv},{key:`Alt-ArrowUp`,run:sy},{key:`Shift-Alt-ArrowUp`,run:uy},{key:`Alt-ArrowDown`,run:cy},{key:`Shift-Alt-ArrowDown`,run:dy},{key:`Mod-Alt-ArrowUp`,run:Uv},{key:`Mod-Alt-ArrowDown`,run:Wv},{key:`Escape`,run:Gv},{key:`Mod-Enter`,run:hy},{key:`Alt-l`,mac:`Ctrl-l`,run:Bv},{key:`Mod-i`,run:Vv,preventDefault:!0},{key:`Mod-[`,run:by},{key:`Mod-]`,run:yy},{key:`Mod-Alt-\\`,run:vy},{key:`Shift-Mod-k`,run:fy},{key:`Shift-Mod-\\`,run:pv},{key:`Mod-/`,run:r_},{key:`Alt-A`,mac:`Ctrl-A`,run:o_},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:xy}].concat(Cy),Ty=`var(--dsw-alias-brand-primary, #3e63dd)`,Ey=`color-mix(in srgb, var(--dsw-alias-brand-primary, #3e63dd) 55%, transparent)`,Dy=`var(--dsw-alias-label-dimmed, #999)`,Oy=`ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace`,ky=pd.define([{tag:[J.heading1,J.heading2,J.heading3,J.heading4,J.heading5,J.heading6],color:Ty,fontWeight:`700`},{tag:J.processingInstruction,color:Ey},{tag:J.monospace,fontFamily:Oy,backgroundColor:`color-mix(in srgb, var(--dsw-alias-label-secondary, #888) 12%, transparent)`,borderRadius:`4px`,padding:`0 3px`},{tag:J.content,fontFamily:Oy,backgroundColor:`color-mix(in srgb, var(--dsw-alias-label-secondary, #888) 8%, transparent)`},{tag:J.strong,fontWeight:`700`},{tag:J.emphasis,fontStyle:`italic`},{tag:J.strikethrough,textDecoration:`line-through`,opacity:`.75`},{tag:J.link,color:Ty,textDecoration:`underline`},{tag:J.url,color:Ey,textDecoration:`underline dotted`},{tag:J.quote,fontStyle:`italic`,color:`var(--dsw-alias-label-secondary, #888)`},{tag:J.contentSeparator,color:Dy,textDecoration:`line-through`},{tag:J.comment,color:Dy}]);function Ay(e={}){let t=document.createElement(`div`);t.className=`dsh-tw-note-editor`;let n=new H({parent:t,state:P.create({doc:``,extensions:[H.lineWrapping,v_(),Zg({base:Lg}),_d(ky),$c(),sl(e.placeholder??``),Lc.of([...wy,...I_,{key:`Mod-Enter`,run:()=>(e.onSave?.(),!0)}]),H.updateListener.of(t=>{t.docChanged&&e.onChange?.()})]})});return{el:t,view:n,getValue:()=>n.state.doc.toString(),setValue(e){n.dispatch({changes:{from:0,to:n.state.doc.length,insert:e}})},insertAtCaret(e){let{from:t}=n.state.selection.main,r=`${t===n.state.doc.lineAt(t).from?``:`
771
771
  `}${e}\n`;n.dispatch({changes:{from:t,insert:r},selection:{anchor:t+r.length},scrollIntoView:!0}),n.focus()},focus:()=>n.focus()}}const jy=`dsh-tw-note-state`,My=`dsh-tw-note-draft-v1`,Ny=`dsh-tw-note-window-id`,Py=(()=>{try{let e=sessionStorage.getItem(Ny);if(e!==null&&e.length>0)return e;let t=Math.random().toString(36).slice(2,10);return sessionStorage.setItem(Ny,t),t}catch{return Math.random().toString(36).slice(2,10)}})();function Fy(){return`dsh-tw-note-draft-v1:${Py}`}function Iy(e){if(e===null)return null;try{let t=JSON.parse(e);return typeof t.text!=`string`||typeof t.title!=`string`?null:{text:t.text,title:t.title,tags:Array.isArray(t.tags)?t.tags.filter(e=>typeof e==`string`):[],savedAt:typeof t.savedAt==`number`?t.savedAt:0,windowId:typeof t.windowId==`string`?t.windowId:void 0}}catch{return null}}function Ly(e){try{return Iy(localStorage.getItem(e))}catch{return null}}function Ry(){let e=Ly(Fy());if(e!==null)return{draft:e,foreign:e.windowId!==void 0&&e.windowId!==Py};let t=Ly(My);if(t===null)return null;let n={...t,windowId:Py};By(n);try{localStorage.removeItem(My)}catch{}return{draft:n,foreign:!0}}function zy(e){By({...e,windowId:Py})}function By(e){try{localStorage.setItem(Fy(),JSON.stringify({...e,windowId:Py}))}catch{}}function Vy(){try{localStorage.removeItem(Fy())}catch{}}function Hy(e,t,n){return`${e}\u0000${t}\u0000${n.join(``)}`}function Uy(e){return e<10?`0${e}`:String(e)}function Wy(e=new Date){return`${e.getFullYear()}-${Uy(e.getMonth()+1)}-${Uy(e.getDate())} ${Uy(e.getHours())}:${Uy(e.getMinutes())}`}function Gy(e){if(e===null)return``;let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=Date.now()-t,r=Math.floor(n/6e4);if(r<1)return`刚刚`;if(r<60)return`${r}分钟前`;let i=Math.floor(r/60);if(i<24)return`${i}小时前`;let a=Math.floor(i/24);return a<30?`${a}天前`:new Date(t).toLocaleDateString(`zh-CN`)}async function Ky(){let e=await me();return typeof e?.note?.tag==`string`&&e.note.tag.length>0?e.note.tag:`inbox`}function qy(e={}){let t=document.createElement(`div`);t.className=`dsh-tw-note-tags`;let n=document.createElement(`div`);n.className=`dsh-tw-note-chips`;let r=document.createElement(`input`);r.className=`dsh-tw-note-taginput`,r.placeholder=`tag(可多选,自动补全)`;let i=document.createElement(`div`);i.className=`dsh-tw-note-tagsuggest`,i.hidden=!0,t.append(n,r,i);let a=[],o=()=>{i.hidden=!0},s=()=>{e.onChange?.()},c=()=>{n.replaceChildren();for(let e of a){let t=document.createElement(`span`);t.className=`dsh-tw-note-tagchip`,t.textContent=e;let r=document.createElement(`span`);r.className=`dsh-tw-note-tagchip-x`,r.textContent=`×`,r.title=`移除 tag「${e}」`,r.addEventListener(`click`,t=>{t.stopPropagation();let n=a.indexOf(e);n>=0&&(a.splice(n,1),c(),s())}),t.append(r),n.append(t)}},l=e=>{let t=e.trim();t.length===0||a.includes(t)||(a.push(t),r.value=``,c(),o(),r.focus(),s())},u=()=>{for(let e of r.value.split(/\s+/))l(e)},d=[],f,p=()=>(f??=fetch(b,{signal:AbortSignal.timeout(5e3)}).then(e=>e.ok?e.json():Promise.resolve({})).then(e=>[...e.tags??[]].sort((e,t)=>e.localeCompare(t,`zh`))).catch(()=>[]),f.then(e=>{d=e}),f),m=()=>{let e=r.value.trim().toLowerCase(),t=d.filter(t=>!a.includes(t)&&(e.length===0||t.toLowerCase().includes(e))).slice(0,8);i.replaceChildren();for(let e of t){let t=document.createElement(`div`);t.className=`dsh-tw-note-tagsuggest-item`,t.textContent=e,t.setAttribute(`role`,`button`),t.tabIndex=0,t.setAttribute(`aria-label`,`添加标签「${e}」`),t.addEventListener(`mousedown`,t=>{t.preventDefault(),l(e)}),t.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),l(e))}),i.append(t)}i.hidden=t.length===0};r.addEventListener(`focus`,()=>{p().then(m)}),r.addEventListener(`input`,()=>{d.length===0?p().then(m):m()}),r.addEventListener(`keydown`,e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),u()):e.key===`Backspace`&&r.value.length===0&&a.length>0?(a.pop(),c(),s()):e.key===`Escape`&&o()});let h=e=>{t.contains(e.target)||o()};return document.addEventListener(`click`,h,!0),{el:t,getTags:()=>(u(),[...a]),peekTags:()=>[...a],setDefault:e=>{if(a.length===0){let t=e.trim();t.length>0&&(a.push(t),c())}},setTags:e=>{a.length=0;for(let t of Array.isArray(e)?e:[]){let e=typeof t==`string`?t.trim():``;e.length>0&&!a.includes(e)&&a.push(e)}r.value=``,c(),o()},dispose:()=>document.removeEventListener(`click`,h,!0)}}async function Jy(e,t){if(e.size>67108864){E(`文件过大(≤ 64MB)`);return}try{let n=await fetch(`${C}?name=${encodeURIComponent(e.name)}`,{method:`POST`,headers:{"content-type":e.type||`application/octet-stream`},body:e,signal:AbortSignal.timeout(12e4)}),r=await n.json().catch(()=>null);if(!n.ok||r?.ok!==!0){E(`上传失败:${r?.error??`HTTP ${n.status}`}`);return}let i=r.name??e.name,a=e.type.startsWith(`image/`)?`![${i}](${r.url})`:`[${i}](${r.url})`;t.insertAtCaret(a),E(`已上传「${i}」并插入链接`)}catch(e){E(`上传失败:${e instanceof Error?e.message:String(e)}`)}}function Yy(){let e,t=!1,n=!1,r=!1,i,a=`inbox`,o,s=!1,c=null,l=null,u=e=>{try{window.dispatchEvent(new CustomEvent(jy,{detail:{open:e}}))}catch{}},d=t=>{if(e===void 0)return;let n=e.root,r=e.card;if(t!==void 0){let e=t.getBoundingClientRect(),i=r.offsetWidth||340,a=r.offsetHeight||260,o=window.innerWidth,s=window.innerHeight,c=Math.min(Math.max(e.left+e.width/2-i/2,8),Math.max(8,o-i-8)),l=s-e.top+10,u=Math.min(Math.max(8,l),Math.max(8,s-a-8));n.style.right=`auto`,n.style.top=`auto`,n.style.left=`${c}px`,n.style.bottom=`${u}px`}else n.style.right=`24px`,n.style.bottom=`88px`,n.style.left=`auto`,n.style.top=`auto`},f=null,p=()=>{e!==void 0&&(f=Wy(),e.titleInput.value=f)},m=()=>{if(e===void 0)return;let t=e.editor.getValue(),n=e.titleInput.value.trim();if(t.trim().length===0&&(n.length===0||n===f)){Vy();return}let r=Hy(n,t,e.tagEditor.peekTags());l!==null&&r===l||By({text:t,title:n,tags:e.tagEditor.peekTags(),savedAt:Date.now()})},h=()=>{t||!n||e===void 0||(o!==void 0&&(clearTimeout(o),o=void 0),o=window.setTimeout(()=>{o=void 0,m()},500))},_=()=>{e!==void 0&&(e.draftBanner.hidden=!0)},b=async(e,t,n)=>{try{let r=await fetch(y,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:e,tags:n,text:t}),signal:AbortSignal.timeout(1e4)}),i=await r.json().catch(()=>null);return!r.ok||i?.ok!==!0?(E(`打开失败:${i?.error??`HTTP ${r.status}`}`),!1):typeof i.twUrl!=`string`||typeof i.draftTitle!=`string`?(E(`打开失败:服务未返回编辑器地址`),!1):(Vy(),_(),l=Hy(e,t,n),c=null,wt(`${new URL(i.twUrl,location.origin).href}#${encodeURIComponent(i.draftTitle)}`,i.title??e),E(`已在弹出窗口打开「${i.title??e}」编辑器`),!0)}catch(e){return E(`打开失败:${e instanceof Error?e.message:String(e)}`),!1}},S=()=>{s=!1,e!==void 0&&(e.recentWrap.hidden=!0)},C=async t=>{try{let n=await fetch(`${g}?title=${encodeURIComponent(t)}`,{signal:AbortSignal.timeout(1e4)}),r=await n.json().catch(()=>null);if(!n.ok||r?.ok!==!0||typeof r.title!=`string`){E(`读取失败:${r?.notFound===!0?`不存在`:r?.error??`HTTP ${n.status}`}`);return}if(e===void 0)return;e.editor.setValue(r.text??``),e.titleInput.value=r.title,e.tagEditor.setTags(r.tags??[]),c={title:r.title,...typeof r.modified==`string`&&r.modified.length>0?{modified:r.modified}:{},...typeof r.revision==`number`?{revision:r.revision}:{}},l=Hy(r.title,r.text??``,r.tags??[]),_(),S(),E(`已载入「${r.title}」`),e.editor.focus()}catch(e){E(`读取失败:${e instanceof Error?e.message:String(e)}`)}},ee=()=>{if(e===void 0)return;if(s){S();return}s=!0,e.recentWrap.hidden=!1,e.recentWrap.textContent=``;let t=document.createElement(`div`);t.className=`dsh-tw-note-recent-muted`,t.textContent=`加载中…`,e.recentWrap.append(t),(async()=>{try{let t=await(await fetch(`${x}?limit=15`,{signal:AbortSignal.timeout(1e4)})).json().catch(()=>null);if(!s||e===void 0)return;e.recentWrap.replaceChildren();let n=[];if(t?.ok===!0)for(let e of t.items??[]){if(typeof e!=`object`||!e)continue;let t=e,r=typeof t.title==`string`?t.title:``;r.length!==0&&n.push({title:r,tags:Array.isArray(t.tags)?t.tags.filter(e=>typeof e==`string`):[],modified:typeof t.modified==`string`?t.modified:null,snippet:typeof t.snippet==`string`?t.snippet:``})}if(n.length===0){let n=document.createElement(`div`);n.className=`dsh-tw-note-recent-muted`,n.textContent=t?.ok===!0?`暂无笔记`:`加载失败:${t?.error??`未知`}`,e.recentWrap.append(n);return}for(let t of n){let n=document.createElement(`div`);n.className=`dsh-tw-note-recent-item`,n.title=t.snippet||t.title,n.setAttribute(`role`,`button`),n.tabIndex=0,n.setAttribute(`aria-label`,`载入笔记「${t.title}」`);let r=document.createElement(`span`);r.className=`dsh-tw-note-recent-name`,r.textContent=t.title;let i=document.createElement(`span`);i.className=`dsh-tw-note-recent-meta`;let a=[Gy(t.modified)];t.tags.length>0&&a.unshift(t.tags.slice(0,3).join(`,`)),i.textContent=a.join(` · `),n.append(r,i),n.addEventListener(`click`,()=>{C(t.title)}),n.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),C(t.title))}),e.recentWrap.append(n)}}catch(t){if(!s||e===void 0)return;e.recentWrap.replaceChildren();let n=document.createElement(`div`);n.className=`dsh-tw-note-recent-muted`,n.textContent=`加载失败:${t instanceof Error?t.message:String(t)}`,e.recentWrap.append(n)}})()},te=()=>{if(e!==void 0)return;let t=document.createElement(`div`);t.className=`dsh-tw-note`,t.hidden=!0;let r=document.createElement(`div`);r.className=`dsh-tw-note-card`;let a=document.createElement(`div`);a.className=`dsh-tw-note-head`;let s=document.createElement(`span`);s.className=`dsh-tw-note-label`,s.textContent=`📝 快速笔记`;let d=document.createElement(`button`);d.type=`button`,d.className=`dsh-tw-note-close`,d.title=`收起`,d.textContent=`✕`,a.append(s,d);let p=document.createElement(`div`);p.className=`dsh-tw-note-draft`,p.hidden=!0;let g=document.createElement(`span`);g.className=`dsh-tw-note-draft-text`,g.textContent=`已恢复未保存草稿`;let y=document.createElement(`button`);y.type=`button`,y.className=`dsh-tw-note-draft-discard`,y.textContent=`丢弃`,p.append(g,y);let x=document.createElement(`div`);x.className=`dsh-tw-note-fields`;let C=document.createElement(`input`);C.className=`dsh-tw-note-title`,C.placeholder=`标题(默认时间戳)`,C.setAttribute(`aria-label`,`笔记标题(默认时间戳)`);let te=qy({onChange:h});x.append(C,te.el),C.addEventListener(`input`,h);let ne,w=Ay({placeholder:`写点东西… Markdown 高亮,可 📎/拖入文件
772
772
  Ctrl+Enter 保存`,onSave:()=>{ne?.()},onChange:h}),re=document.createElement(`button`);re.type=`button`,re.className=`dsh-tw-note-upload`,re.title=`上传文件到 wiki 并插入 Markdown 链接(也可直接拖入编辑器)`,re.textContent=`📎 上传`;let T=document.createElement(`input`);T.type=`file`,T.multiple=!0,T.hidden=!0,re.addEventListener(`click`,()=>{T.click()}),T.addEventListener(`change`,()=>{for(let e of Array.from(T.files??[]))Jy(e,w);T.value=``});let ie=0;w.el.addEventListener(`dragenter`,e=>{e.preventDefault(),ie++,w.el.classList.add(`dsh-tw-note-drop`)}),w.el.addEventListener(`dragover`,e=>{e.preventDefault()}),w.el.addEventListener(`dragleave`,e=>{e.preventDefault(),ie=Math.max(0,ie-1),ie===0&&w.el.classList.remove(`dsh-tw-note-drop`)}),w.el.addEventListener(`drop`,e=>{e.preventDefault(),ie=0,w.el.classList.remove(`dsh-tw-note-drop`);let t=e.dataTransfer?.files;if(!(t===void 0||t.length===0))for(let e of Array.from(t))Jy(e,w)});let ae=document.createElement(`div`);ae.className=`dsh-tw-note-foot`;let oe=document.createElement(`div`);oe.className=`dsh-tw-note-foot-left`;let se=document.createElement(`span`);se.className=`dsh-tw-note-hint`,se.textContent=`Ctrl+Enter`;let ce=document.createElement(`button`);ce.type=`button`,ce.className=`dsh-tw-note-recent-btn`,ce.title=`最近修改的笔记,点击载入继续编辑`,ce.textContent=`🕘 最近`,ce.addEventListener(`click`,ee),oe.append(re,ce,se);let le=document.createElement(`div`);le.className=`dsh-tw-note-foot-right`;let ue=document.createElement(`button`);ue.type=`button`,ue.className=`dsh-tw-note-edit`,ue.title=`保存并在 TiddlyWiki 原生编辑器中打开`,ue.textContent=`✏️ 在 TW 中编辑`;let de=document.createElement(`button`);de.type=`button`,de.className=`dsh-tw-note-save`,de.textContent=`保存`,le.append(ue,de),ae.append(oe,le);let fe=document.createElement(`div`);fe.className=`dsh-tw-note-recent`,fe.hidden=!0,r.append(a,p,x,w.el,ae),t.append(r,fe),document.body.append(t),e={root:t,card:r,editor:w,titleInput:C,tagEditor:te,saveBtn:de,editBtn:ue,draftBanner:p,bannerText:g,recentWrap:fe};let pe=()=>{n=!1,t.hidden=!0,S(),u(!1)},me=()=>{o!==void 0&&(clearTimeout(o),o=void 0),w.setValue(``),C.value=Wy(),f=C.value,te.setTags([]),l=Hy(C.value.trim(),``,[])},he=()=>{Vy(),_(),l=Hy(C.value.trim(),w.getValue(),te.getTags()),c=null,me(),pe()},ge=!1;ne=async()=>{if(ge)return;let e=w.getValue().trim();if(e.length===0){E(`内容为空,未保存`);return}ge=!0,de.disabled=!0,de.textContent=`保存中…`;try{let t=C.value.trim(),n={title:t,tags:te.getTags(),text:e};c!==null&&c.title===t&&(c.modified!==void 0&&(n.expectedModified=c.modified),c.revision!==void 0&&(n.expectedRevision=c.revision));let r=await fetch(v,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n),signal:AbortSignal.timeout(1e4)}),i=await r.json().catch(()=>null);if(!r.ok||i?.ok!==!0){if(r.status===409||i?.conflict===!0){E(`保存被拒绝:这篇笔记在你读取之后被改动过。请用「🕘 最近」重新载入后再保存。`);return}E(`保存失败:${i?.error??`HTTP ${r.status}`}`);return}he(),E(`已保存「${i.title??C.value}」`)}catch(e){E(`保存失败:${e instanceof Error?e.message:String(e)}`)}finally{ge=!1,de.disabled=!1,de.textContent=`保存`}},de.addEventListener(`click`,()=>{ne?.()});let _e=async()=>{let e=C.value.trim().length>0?C.value.trim():Wy(),t=w.getValue(),n=te.getTags();ue.disabled=!0,ue.textContent=`打开中…`;try{await b(e,t,n)}finally{ue.disabled=!1,ue.textContent=`✏️ 在 TW 中编辑`}};ue.addEventListener(`click`,()=>{_e()}),d.addEventListener(`click`,pe);let ve=null,ye=(e,n)=>{let i=window.innerWidth,a=window.innerHeight,o=r.offsetWidth||340,s=r.offsetHeight||260,c=Math.min(Math.max(e,8),Math.max(8,i-o-8)),l=Math.min(Math.max(n,8),Math.max(8,a-s-8));t.style.right=`auto`,t.style.bottom=`auto`,t.style.left=`${c}px`,t.style.top=`${l}px`};a.addEventListener(`pointerdown`,e=>{if(d.contains(e.target))return;e.preventDefault();let n=t.getBoundingClientRect();ve={startX:e.clientX,startY:e.clientY,origLeft:n.left,origTop:n.top,moved:!1};try{a.setPointerCapture(e.pointerId)}catch{}a.classList.add(`dsh-tw-note-head-dragging`)}),a.addEventListener(`pointermove`,e=>{if(ve===null)return;let t=e.clientX-ve.startX,n=e.clientY-ve.startY;!ve.moved&&Math.abs(t)<4&&Math.abs(n)<4||(ve.moved=!0,ye(ve.origLeft+t,ve.origTop+n))});let be=e=>{if(ve!==null){try{a.releasePointerCapture(e.pointerId)}catch{}ve=null,a.classList.remove(`dsh-tw-note-head-dragging`)}};a.addEventListener(`pointerup`,be),a.addEventListener(`pointercancel`,be),y.addEventListener(`click`,()=>{Vy(),_(),me(),E(`已丢弃草稿`)}),i=()=>{m()},window.addEventListener(`pagehide`,i)};return{async open(r){if(t||(te(),e===void 0||n))return;n=!0,e.root.hidden=!1,d(r),u(!0);let i=Ry(),o=i?.draft??null;if(o!==null&&(o.text.trim().length>0||o.title.trim().length>0))e.editor.setValue(o.text),e.titleInput.value=o.title,e.tagEditor.setTags(o.tags),e.bannerText.textContent=i?.foreign===!0?`已恢复未保存草稿(来自其它窗口)`:`已恢复未保存草稿`,e.draftBanner.hidden=!1,i?.foreign===!0&&(E(`已恢复其它窗口的未保存草稿`),zy(o));else{if(p(),a=await Ky(),t||e===void 0)return;e.tagEditor.setDefault(a)}e!==void 0&&e.editor.focus()},close(){e!==void 0&&(n=!1,e.root.hidden=!0,S(),u(!1))},async openNative(){if(!(t||r)&&!(Tt()&&!Et())){r=!0;try{let e=Ry(),n=e!==null&&(e.draft.text.trim().length>0||e.draft.title.trim().length>0),r=n&&e.draft.title.trim().length>0?e.draft.title.trim():Wy(),i=n?e.draft.text:``,o=[];if(n)o=e.draft.tags;else{if(a=await Ky(),t)return;o=[a]}e!==null&&e.foreign&&(e.draft.text.trim().length>0||e.draft.title.trim().length>0)&&(E(`已恢复其它窗口的未保存草稿`),zy(e.draft)),await b(r,i,o)}finally{r=!1}}},isOpen(){return n},dispose(){t=!0,i!==void 0&&(window.removeEventListener(`pagehide`,i),i=void 0),o!==void 0&&(clearTimeout(o),o=void 0),m(),e?.tagEditor.dispose(),e?.editor.view.destroy(),e?.root.remove(),e=void 0}}}function Xy(e){return e<10?`0${e}`:String(e)}function Zy(e){return`${Xy(e.getHours())}:${Xy(e.getMinutes())}`}function Qy(e,t){let n=e?.git,r=[`同步知识库`],i=`offline`;if(n==null||n.exists!==!0)r.push(`git 仓库不可用`);else{r.push(`分支 ${n.branch??`?`}`),typeof n.lastCommit==`string`&&r.push(n.lastCommit);let e=typeof n.behind==`number`?n.behind:0,t=typeof n.ahead==`number`?n.ahead:0;t>0&&r.push(`领先 ${t}`),e>0&&r.push(`落后 ${e}`),n.dirty===!0?(i=`dirty`,r.push(`有 ${n.dirtyFiles?.length??0} 个未提交改动`)):i=e>0?`behind`:`clean`}return t!==void 0&&r.push(`上次同步 ${Zy(t)}`),{state:i,tooltip:r.join(` · `)}}function $y(){let e={state:`offline`,tooltip:`同步知识库`},t,n,r=!1,i=!1,a=new Set,o=()=>{for(let e of[...a])e()},s=n=>{if(r)return;let i=Qy(n,t);(i.state!==e.state||i.tooltip!==e.tooltip)&&(e=i,o())},c=async()=>{if(i)return;let e=await me();i||s(e)};return c(),n=window.setInterval(()=>{c()},3e4),{getState:()=>e,trigger:async()=>{if(i)return e;if(r)return E(`同步进行中…`),e;r=!0,e={...e,state:`syncing`},o();try{let e=await fetch(ee,{method:`POST`,signal:AbortSignal.timeout(12e4)}),n=fe(await e.json().catch(()=>null),e.status);n.ok?(t=new Date,E(`同步完成:${n.message}`)):E(`同步失败:${n.message}`)}catch(e){E(`同步失败:${e instanceof Error?e.message:String(e)}`)}finally{r=!1,await c()}return e},subscribe(e){return a.add(e),()=>{a.delete(e)}},dispose(){i=!0,n!==void 0&&(clearInterval(n),n=void 0),a.clear()}}}async function eb(){let e=await xe();return{showQuickNote:e.showQuickNote,showPanelStatus:e.showPanelStatus,showSyncButton:e.showSyncButton}}async function tb(){let e=await me();if(e===null)return{state:`failed`,text:`状态不可达`,logs:[]};let t=Array.isArray(e.logs)?e.logs.filter(e=>typeof e==`string`):[];return e.status===`running`?{state:`running`,text:`TW 在线 · ${e.url??``}`,logs:t}:e.status===`starting`?{state:`starting`,text:`TW 启动中…`,logs:t}:{state:`failed`,text:e.error??`TW 状态:${e.status??`?`}`,logs:t}}function nb(e,t,n){let r=!1,i,a,o,s,c,l,u,d,f=!1,p={state:`unknown`,text:`TiddlyWiki 服务…`,logs:[]},m=()=>{f=!1,s!==void 0&&(s.hidden=!0),u!==void 0&&(u.hidden=!0)},h=e=>{if(!f)return;let t=e.target;i!==void 0&&i.contains(t)||m()},g=()=>{if(u===void 0)return;let e=[`TiddlyWiki 服务:${p.text}`];e.push(`知识库同步:${n.getState().tooltip}`),p.logs.length>0&&(e.push(`最近日志:`),e.push(...p.logs.slice(-3))),u.textContent=e.join(`
773
- `)},_=()=>{let e=n.getState();o!==void 0&&(o.dataset.state=e.state),a!==void 0&&(a.title=`知识库 · ${e.tooltip}`),g()},v=async()=>{p=await tb(),!r&&(c!==void 0&&(c.textContent=p.text),l!==void 0&&(l.dataset.state=p.state),g())},y=p=>{if(r)return;if(i=document.createElement(`div`),i.className=`dsh-tw-fab-wrap`,s=document.createElement(`div`),s.className=`dsh-tw-fab-menu`,s.hidden=!0,p.showPanelStatus){let e=document.createElement(`div`);e.className=`dsh-tw-fab-status dsh-tw-fab-status-tiprow`,l=document.createElement(`span`),l.className=`dsh-tw-fab-status-dot`,l.dataset.state=`unknown`,c=document.createElement(`span`),c.className=`dsh-tw-fab-status-text`,c.textContent=`TiddlyWiki 服务…`,e.append(l,c),u=document.createElement(`div`),u.className=`dsh-tw-fab-tip`,u.hidden=!0,e.append(u),e.addEventListener(`mouseenter`,()=>{g(),u!==void 0&&(u.hidden=!1)}),e.addEventListener(`mouseleave`,()=>{u!==void 0&&(u.hidden=!0)}),s.append(e)}if(p.showQuickNote){let e=document.createElement(`button`);e.type=`button`,e.className=`dsh-tw-fab-item`,e.textContent=`📝 快速笔记`,e.title=`ui.quickNoteMode=native 时直接打开 TW 原生编辑器;card 时打开 Markdown 卡片`,e.addEventListener(`click`,()=>{m(),xe().then(e=>{e.quickNoteMode===`native`?t.openNative():t.open()})}),s.append(e)}if(p.showPanelStatus){d=document.createElement(`span`),d.textContent=`打开 TW 面板`;let t=document.createElement(`button`);t.type=`button`,t.className=`dsh-tw-fab-item`,t.append(document.createTextNode(`🖥 `),d),t.addEventListener(`click`,()=>{m(),e.toggle()}),s.append(t);let n=document.createElement(`button`);n.type=`button`,n.className=`dsh-tw-fab-item`,n.textContent=`🔄 重载 TW 面板`,n.addEventListener(`click`,()=>{m(),document.dispatchEvent(new CustomEvent(Je)),v()}),s.append(n)}if(p.showSyncButton){let e=document.createElement(`button`);e.type=`button`,e.className=`dsh-tw-fab-item`,e.textContent=`🔁 同步`,e.addEventListener(`click`,()=>{m(),n.trigger()}),s.append(e)}a=document.createElement(`button`),a.type=`button`,a.className=`dsh-tw-fab`,a.setAttribute(`aria-label`,`TiddlyWiki 知识库`);let y=document.createElement(`span`);y.className=`dsh-tw-fab-icon`,y.innerHTML=`<svg viewBox="0 0 16 16" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 2.5h8a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"/><path d="M6 6h4M6 8.5h2.5"/></svg>`,o=document.createElement(`span`),o.className=`dsh-tw-fab-dot`,o.dataset.state=n.getState().state,a.append(y,o),a.addEventListener(`click`,()=>{if(s!==void 0){if(f){m();return}f=!0,s.hidden=!1,_(),v()}}),i.append(s,a),document.body.append(i),_(),document.addEventListener(`click`,h,!0)},b=e.subscribe(()=>{d!==void 0&&(d.textContent=e.isOpen()?`收起 TW 面板`:`打开 TW 面板`)}),x=n.subscribe(_);return(async()=>{let e=await eb();r||!e.showQuickNote&&!e.showPanelStatus&&!e.showSyncButton||y(e)})(),()=>{r=!0,document.removeEventListener(`click`,h,!0),b(),x(),i?.remove()}}function rb(e){return function(){let[t,n]=c.useState(!1),[r,i]=c.useState(null),a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{let e=!0,t=e=>{let t=e.detail;n(t?.open===!0)};return window.addEventListener(jy,t),xe().then(t=>{e&&i(t.quickNoteMode)}),()=>{e=!1,window.removeEventListener(jy,t)}},[]),c.useLayoutEffect(()=>{let e=a.current;if(e===null)return;let t=()=>{let t=null,n=null,r=e;for(;r!==null&&r!==document.documentElement&&(r=r.parentElement,r!==null);){for(let e of r.querySelectorAll(`textarea, [contenteditable]:not([contenteditable="false"]), [role="textbox"]`))if(e.getBoundingClientRect().width>300){t=e,n=r;break}if(n!==null)break}if(t===null||n===null)return null;let i=n.getBoundingClientRect().width,a=t,o=null,s=0;for(;a!==null&&a!==n;){let e=a.getBoundingClientRect().width;e>0&&e<i-8&&e>=s&&(s=e,o=a),a=a.parentElement}return o},n=()=>{let n=e.getBoundingClientRect(),r=t(),i=r===null?n.right:r.getBoundingClientRect().right,a=Math.max(0,n.right-i);return e.style.paddingRight!==`${a}px`&&(e.style.paddingRight=`${a}px`),r!==null};n();let r=new ResizeObserver(n),i=e;for(;i!==null&&i!==document.documentElement&&(r.observe(i),!(i instanceof HTMLElement&&i.hasAttribute(`data-phase`)));)i=i.parentElement;window.addEventListener(`resize`,n),document.addEventListener(`visibilitychange`,n);let o=0,s=0,c=window.setInterval(()=>{if(s++,!n()){s>=20&&window.clearInterval(c);return}o++,o>=3&&window.clearInterval(c)},1500),l=window.setTimeout(n,120),u=window.setTimeout(n,600);return()=>{r.disconnect(),window.removeEventListener(`resize`,n),document.removeEventListener(`visibilitychange`,n),window.clearInterval(c),window.clearTimeout(l),window.clearTimeout(u)}},[]);let s=r===`native`,l=s?`快速笔记`:t?`快速笔记(已打开)`:`快速笔记`,u=s?`快速笔记:直接打开 TiddlyWiki 原生编辑器(再次点击可收起弹窗)`:t?`快速笔记已打开(点此按钮或卡片右上角 ✕ 收起)`:`打开快速笔记(在按钮上方弹出,可拖动标题栏移动)`;return c.createElement(`div`,{ref:a,className:`dsh-tw-dock-note`},c.createElement(`button`,{ref:o,type:`button`,className:t?`dsh-tw-dock-note-btn dsh-tw-dock-note-btn-active`:`dsh-tw-dock-note-btn`,title:u,onClick:()=>{xe().then(t=>{t.quickNoteMode===`native`?Tt()&&!Et()?Ot():e.openNative():e.isOpen()?e.close():e.open(o.current??void 0)})}},c.createElement(`span`,{className:`dsh-tw-dock-note-icon`,"aria-hidden":`true`},`📝`),c.createElement(`span`,{className:`dsh-tw-dock-note-label`},l)))}}async function ib(e,t=15e3){try{let n=await fetch(_,{method:`POST`,headers:{"content-type":`application/json`,"x-requested-with":`TiddlyWiki`},body:JSON.stringify({title:e}),signal:AbortSignal.timeout(t)});if(!n.ok)return null;let r=await n.text();return r.trim().length>0?r:null}catch{return null}}function ab(){return Ze()}async function ob(e){try{let t=await fetch(`${g}?title=${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(8e3)});if(t.status===404)return`no`;if(!t.ok)return`unknown`;let n=await t.json().catch(()=>null);return n===null?`unknown`:n.notFound===!0?`no`:`yes`}catch{return`unknown`}}function sb(e){let{sessionId:t,viewRequest:n,completeViewRequest:r}=e,[i,a]=c.useState(`loading`),[o,s]=c.useState(null),[l,u]=c.useState(null),[d,f]=c.useState(``),[p,m]=c.useState(!1),h=c.useRef(0),g=c.useRef(!0),_=c.useRef(0),v=c.useRef(0),y=c.useCallback(async e=>{let n=++h.current;if(!g.current)return;let r=e?.silent===!0;r||a(`loading`);let i=e=>{if(_.current++,r){m(!0);return}a(`error`),f(e)};if(typeof t!=`string`||t.length===0){a(`error`),f(`缺少会话 ID`);return}if(_.current>=3){if(r){m(!0);return}a(`error`),f(`连续 3 次生成失败,已停止自动重试,请点「🔄 刷新」`);return}try{let e=await fetch(ne,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({session:t}),signal:AbortSignal.timeout(25e3)}),o=await e.json().catch(()=>null);if(!g.current||n!==h.current)return;if(!e.ok||o?.ok!==!0){i(o?.error??`HTTP ${e.status}`);return}if(typeof o.title!=`string`||o.title.length===0){i(`汇总生成失败:缺少标题`);return}u(o.title);let c=await ib(o.title);if(!g.current||n!==h.current)return;if(c===null){let e=await ob(o.title);if(!g.current||n!==h.current)return;if(e===`no`){if(_.current++,_.current<3){y();return}a(`error`),f(`汇总条目不存在,自动重建失败,请重试`);return}if(e===`unknown`){if(r){m(!0);return}a(`error`),f(`渲染失败:wiki 渲染服务不可用(host /render),条目状态未知`);return}i(`渲染失败:wiki 渲染服务不可用(host /render)`);return}_.current=0,v.current=Date.now(),m(!1),s(c),a(`ready`)}catch(e){if(!g.current||n!==h.current)return;i(e instanceof Error?e.message:String(e))}},[t]);c.useEffect(()=>(g.current=!0,_.current=0,v.current=Date.now(),m(!1),y(),()=>{g.current=!1}),[y]),c.useEffect(()=>{if(l===null)return;let e=!0,t=window.setInterval(()=>{(async()=>{if(!e||typeof document<`u`&&document.hidden)return;let t=await ob(l);if(e){if(t===`unknown`){m(!0);return}if(t===`no`){if(_.current++,_.current<3){y();return}a(`error`),f(`汇总条目已失效且自动重建多次失败,请点「🔄 刷新」重试`);return}if(Date.now()-v.current>18e4){y({silent:!0});return}_.current=0,m(!1)}})()},3e4);return()=>{e=!1,window.clearInterval(t)}},[l,y]),c.useEffect(()=>{n!=null&&r?.()},[n,r]);let b=()=>{_.current=0,y()},x;return x=i===`loading`?c.createElement(`div`,{className:`dsh-tw-summary-state`},c.createElement(`div`,{className:`dsh-tw-summary-state-spin`},`⏳`),c.createElement(`div`,null,`正在生成会话 wiki 汇总…`)):i===`error`?c.createElement(`div`,{className:`dsh-tw-summary-state`},c.createElement(`div`,{className:`dsh-tw-summary-state-title`},`知识库汇总暂不可用`),c.createElement(`div`,{className:`dsh-tw-summary-state-detail`},d),c.createElement(`button`,{type:`button`,className:`dsh-tw-summary-btn`,onClick:b},`重试`)):c.createElement(`div`,{className:`dsh-tw-summary-native dsh-tw-toolcard-native`},p?c.createElement(`div`,{className:`dsh-tw-summary-state-detail`},`⚠️ 未能确认最新状态(wiki 查询或刷新失败),以下是上次生成的内容`):null,c.createElement(`div`,{dangerouslySetInnerHTML:{__html:o??``}})),c.createElement(`div`,{className:`dsh-tw-summary`,"data-dsh-tw-summary":`true`},c.createElement(`div`,{className:`dsh-tw-summary-bar`},c.createElement(`span`,{className:`dsh-tw-summary-bar-title`},`📚 本会话知识库`),c.createElement(`span`,{className:`dsh-tw-summary-bar-hint`},`产生 / 读取 / 检索过的笔记(含子代理)`),c.createElement(`span`,{className:`dsh-tw-summary-bar-spacer`}),c.createElement(`button`,{type:`button`,className:`dsh-tw-summary-btn`,onClick:b,disabled:i===`loading`,title:`重新生成并刷新汇总`},`🔄 刷新`)),x)}function cb(e,t){if(!(e===void 0||t.showSessionTab===!1))return Xe(t.tabLabel),e.inject(`conversation.view`,()=>e.register({name:`conversation.view`,id:`dsh-tiddlywiki-summary`,order:20,label:ab},sb))}function $(e,t,n){let r=document.createElement(e);return t!==void 0&&(r.className=t),n!==void 0&&(r.textContent=n),r}function lb(e){let t=$(`div`,`dsh-tw-settings-banner`);return t.dataset.tone=`error`,t.setAttribute(`style`,`border:1px solid #c0392b;background:#fdecea;color:#8c1c13;border-radius:6px;padding:10px 12px;margin:0 0 12px;font-size:12px;line-height:1.6;white-space:pre-wrap;`),t.textContent=e,t}async function ub(e,t){let n=await fetch(e,{...t,signal:t?.signal??AbortSignal.timeout(15e3)}),r=await n.json().catch(()=>({}));if(!n.ok){let e=r.error??`HTTP ${n.status}`;throw Error(e)}return r}function db(e){let t=!1;e.classList.add(`dsh-tw-settings`);let n=$(`div`,`dsh-tw-settings-error`);n.hidden=!0;let r=$(`div`,`dsh-tw-settings-row dsh-tw-settings-status`),i=$(`div`,`dsh-tw-settings-body`);e.append(n,r,i);let a=[],o={},s={plugins:new Set,themes:new Set,languages:new Set},c=!1,l=async()=>{c||i.replaceChildren($(`div`,`dsh-tw-settings-muted`,`加载中…`));try{let e=await ub(w);if(t)return;c=!0,n.hidden=!0,n.replaceChildren(),fb(r,e,l),_b(i,e,l,()=>t,o,s)}catch(e){if(t)return;c||i.replaceChildren($(`div`,`dsh-tw-settings-muted`,`配置尚未加载。`));let r=$(`button`,`dsh-tw-settings-btn`,`重试`);r.type=`button`,r.addEventListener(`click`,()=>{l()}),n.replaceChildren($(`span`,void 0,`加载配置失败:${e instanceof Error?e.message:String(e)} `),r),n.hidden=!1}};return l(),a.push(()=>{t=!0,e.replaceChildren(),e.classList.remove(`dsh-tw-settings`)}),()=>{for(let e of a.splice(0))e()}}function fb(e,t,n){e.replaceChildren();let r=t.server??{},i=r.status??`unknown`,a=$(`span`,`dsh-tw-settings-chip`,i);a.dataset.state=i;let o=$(`span`,`dsh-tw-settings-muted`,[r.url===void 0?``:`TW ${r.url}`,t.git?.branch===void 0?``:`git ${t.git.branch}`,t.git?.lastCommit===void 0?``:t.git.lastCommit,t.git?.conflict===void 0?t.git?.dirty===!0?`有未提交改动`:``:`⚠️ 冲突未解决(${t.git.conflict.files.length} 个文件,已阻止提交)`].filter(Boolean).join(` · `)),s=$(`button`,`dsh-tw-settings-btn`,`同步`);s.type=`button`,s.title=`git 同步(pull → commit → push)`,s.addEventListener(`click`,()=>{s.disabled=!0,s.textContent=`同步中…`,(async()=>{try{let e=await fetch(ee,{method:`POST`,signal:AbortSignal.timeout(12e4)}),t=fe(await e.json().catch(()=>null),e.status);E(t.ok?`同步完成:${t.message}`:`同步失败:${t.message}`)}catch(e){E(`同步失败:${e instanceof Error?e.message:String(e)}`)}finally{s.disabled=!1,s.textContent=`同步`,n()}})()});let c=$(`button`,`dsh-tw-settings-btn`,`重启 TW`);c.type=`button`,c.addEventListener(`click`,()=>{c.disabled=!0,c.textContent=`重启中…`,(async()=>{try{await ub(ae,{method:`POST`,signal:AbortSignal.timeout(12e4)}),E(`TW 已重启`)}catch(e){E(`重启失败:${e instanceof Error?e.message:String(e)}`)}finally{c.disabled=!1,c.textContent=`重启 TW`,n()}})()}),e.append(a,o,s,c)}function pb(e,t,n,r){let i=$(`section`,`dsh-tw-settings-section`);i.append($(`h3`,`dsh-tw-settings-h`,`常规配置`));let a=t.note??{},o=t.git??{},s=t.ui??{},c=[],l=(e,t,n)=>{let r=$(`input`,`dsh-tw-settings-input`);r.value=n;let a=$(`label`,`dsh-tw-settings-field`);a.append($(`span`,`dsh-tw-settings-label`,t),r),c.push({key:e,initial:n,read:()=>r.value.trim(),changed:()=>r.value.trim()!==n}),i.append(a)},u=(e,t,n)=>{let r=$(`input`,`dsh-tw-settings-input`);r.type=`password`,r.value=n,r.autocomplete=`off`;let a=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-chipbtn`,`👁`);a.type=`button`,a.title=`显示 / 隐藏`,a.setAttribute(`aria-label`,`显示 / 隐藏`),a.addEventListener(`click`,e=>{e.preventDefault();let t=r.type===`password`;r.type=t?`text`:`password`,a.textContent=t?`🙈`:`👁`});let o=$(`label`,`dsh-tw-settings-field`);o.append($(`span`,`dsh-tw-settings-label`,t),r,a),c.push({key:e,initial:n,read:()=>r.value.trim(),changed:()=>r.value.trim()!==n}),i.append(o)},d=(e,t,n)=>{let r=$(`input`,`dsh-tw-settings-check`);r.type=`checkbox`,r.checked=n;let a=$(`label`,`dsh-tw-settings-field dsh-tw-settings-field-check`);return a.append(r,$(`span`,`dsh-tw-settings-label`,t)),c.push({key:e,initial:n,read:()=>r.checked,changed:()=>r.checked!==n}),i.append(a),r},f=(e,t,n,r)=>{let a=$(`input`,`dsh-tw-settings-input`);a.type=`number`,a.value=String(n),r?.min!==void 0&&(a.min=String(r.min)),r?.max!==void 0&&(a.max=String(r.max)),r?.step!==void 0&&(a.step=String(r.step));let o=$(`div`,`dsh-tw-settings-error`);o.hidden=!0;let s=()=>{let e=a.value.trim();if(e.length===0)return`不能为空`;let t=Number(e);if(!Number.isFinite(t))return`请输入数字`;if(r?.integer===!0&&!Number.isInteger(t))return`必须是整数`;if(r?.min!==void 0&&t<r.min)return`不能小于 ${r.min}`;if(r?.max!==void 0&&t>r.max)return`不能大于 ${r.max}`},l=()=>{let e=s();o.textContent=e===void 0?``:`⚠️ ${e}(保存会被拒绝)`,o.hidden=e===void 0,e===void 0?a.removeAttribute(`aria-invalid`):a.setAttribute(`aria-invalid`,`true`)};a.addEventListener(`input`,l);let u=()=>{let e=a.value.trim(),t=Number(e);return e.length===0||!Number.isFinite(t)?e:t},d=$(`label`,`dsh-tw-settings-field`);d.append($(`span`,`dsh-tw-settings-label`,t),a,o),c.push({key:e,initial:n,read:u,changed:()=>u()!==n,invalid:s}),l(),i.append(d)},p=(e,t,n,r)=>{let a=$(`select`,`dsh-tw-settings-input`);for(let e of r){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,e.value===n&&(t.selected=!0),a.append(t)}let o=$(`label`,`dsh-tw-settings-field`);return o.append($(`span`,`dsh-tw-settings-label`,t),a),c.push({key:e,initial:n,read:()=>a.value,changed:()=>a.value!==n}),i.append(o),a},m=(e,t,n,r)=>{let a=$(`textarea`,`dsh-tw-settings-input dsh-tw-settings-area`);a.rows=r,a.value=n;let o=$(`label`,`dsh-tw-settings-field dsh-tw-settings-field-area`);return o.append($(`span`,`dsh-tw-settings-label`,t),a),c.push({key:e,initial:n,read:()=>a.value.trim(),changed:()=>a.value.trim()!==n}),i.append(o),a};l(`note.tag`,`快速笔记默认 tag`,typeof a.tag==`string`?a.tag:`inbox`),d(`note.workspaceMark`,`新建笔记自动标工作区(ws/<项目名> 标签 + workspace 字段,取自当前会话工作目录)`,a.workspaceMark!==!1),d(`git.autoCommit`,`自动 commit(防抖)`,o.autoCommit!==!1),f(`git.debounceMs`,`自动 commit 防抖(ms;范围 0–3600000)`,typeof o.debounceMs==`number`?o.debounceMs:6e4,{min:0,max:36e5,step:1e3,integer:!0}),l(`git.remote`,`git 远端(空=仅本地;保存后即时生效,但**清空不会删除已配置的 origin**,需要时请用 git 命令处理)`,typeof o.remote==`string`?o.remote:``),l(`git.branch`,`git 分支(**只在仓库首次初始化时生效**;已有仓库请用 git 命令改分支——上面的状态行显示的是真实分支)`,typeof o.branch==`string`?o.branch:`main`);let h=t.startup??{};f(`startup.readyTimeoutMs`,`TW 启动就绪等待(ms;默认 60000,范围 5000–600000,超时上限为其 3 倍,对下次启动/重启生效)`,typeof h.readyTimeoutMs==`number`&&h.readyTimeoutMs>0?h.readyTimeoutMs:6e4,{min:5e3,max:6e5,step:1e3}),d(`ui.showQuickNote`,`显示「知识库」按钮里的「快速笔记」入口`,s.showQuickNote!==!1),d(`ui.showQuickNoteDock`,`显示聊天输入框上方的「快速笔记」快捷按钮`,s.showQuickNoteDock!==!1),p(`ui.quickNoteMode`,`点击「快速笔记」的打开方式`,typeof s.quickNoteMode==`string`&&s.quickNoteMode===`card`?`card`:`native`,[{value:`native`,label:`原生编辑器:直接弹出 TW 原生编辑页(新建/恢复草稿)`},{value:`card`,label:`Markdown 卡片:弹出现有快速笔记卡片(CodeMirror 编辑器)`}]),l(`ui.sidebarLabel`,`侧边栏 TW 入口显示名称`,typeof s.sidebarLabel==`string`&&s.sidebarLabel.trim().length>0?s.sidebarLabel.trim():`TiddlyWiki`),d(`ui.showPanelStatus`,`显示「知识库」按钮里的 TW 面板/重载入口与状态行`,s.showPanelStatus!==!1),d(`ui.showSyncButton`,`显示「知识库」按钮里的「同步」入口与 git 状态点`,s.showSyncButton!==!1),d(`ui.followDshTheme`,`嵌入式 TW 跟随 DSH 深浅主题(暗色时自动切深色 palette,不写回 wiki)`,s.followDshTheme!==!1),l(`ui.darkPalette`,`暗色时 TW palette(tiddler 标题)`,typeof s.darkPalette==`string`&&s.darkPalette.trim().length>0?s.darkPalette.trim():`$:/palettes/CupertinoDark`),l(`ui.tabLabel`,`会话顶部「知识库」Tab 名称`,typeof s.tabLabel==`string`&&s.tabLabel.trim().length>0?s.tabLabel.trim():`知识库`),d(`ui.showSessionTab`,`显示会话顶部「知识库」Tab(本会话相关 wiki 笔记汇总)`,s.showSessionTab!==!1),d(`ui.showRightbarTab`,`在 DSH 右侧边栏提供 TiddlyWiki 入口/Tab(与聊天并排)`,s.showRightbarTab!==!1);let g=s.sendToAgent??{};d(`ui.sendToAgent.enabled`,`启用「发送给 Agent」(TW 笔记 → DSH 会话注入)`,g.enabled!==!1),l(`ui.sendToAgent.endpoint`,`TW 端请求基址(空=自动取当前 DSH origin)`,typeof g.endpoint==`string`?g.endpoint:``),u(`ui.sendToAgent.token`,`共享 token(非空时路由校验 x-send-to-agent-token 头;已设置时显示为 ********,原样保存=不改,清空=删除)`,typeof g.token==`string`?g.token:``);let _=s.allArticles??{};f(`ui.allArticles.pageSize`,`「所有文章」每页条数(1–200)`,typeof _.pageSize==`number`?_.pageSize:10,{min:1,max:200,step:1,integer:!0}),i.append($(`h3`,`dsh-tw-settings-h`,`可选功能:微信公众号发布`)),i.append($(`div`,`dsh-tw-settings-muted`,`把 wiki 笔记一键发到公众号草稿箱(可选点发表)。**需要额外安装**:opencli 与 Browser Bridge 浏览器扩展,并让浏览器登录 mp.weixin.qq.com;adapter 在本仓库 tools/wechat/,安装与排错见 docs/wechat-publish-setup.md。不安装/不开启它,插件其他功能完全不受影响。开启后:注入提示词会多一条「发布前先读发布元数据规范」的约定,并在启动时把「发布元数据规范」与「微信公众号发布指南」(安装/换机还原步骤,等于仓库 docs/wechat-publish-setup.md)两篇文档写进 wiki(同名不覆盖)。`));let v=t.wechat??{},y=d(`wechat.enabled`,`启用微信公众号发布(默认关;需先按 docs/wechat-publish-setup.md 安装 opencli + 浏览器扩展)`,v.enabled===!0);l(`wechat.command`,`opencli 命令(默认 opencli;用别名或绝对路径时填这里。仅在启用微信发布时生效)`,typeof v.command==`string`&&v.command.trim().length>0?v.command.trim():`opencli`),p(`wechat.adapter`,`发布适配器(仅在启用微信发布时生效)`,v.adapter===`publish-note-imgs`?`publish-note-imgs`:`publish-note`,[{value:`publish-note`,label:`publish-note(默认):图文排版,封面单图`},{value:`publish-note-imgs`,label:`publish-note-imgs:正文内嵌图全部上传 CDN(需先重跑 install-wechat-adapters.mjs)`}]),u(`wechat.token`,`发布 token(非空时 /wechat/* 校验 x-wechat-publish-token 头,强烈建议设置,否则任何能打开本页的人都能替你发文;已设置时显示为 ********,原样保存=不改,清空=删除。仅在启用微信发布时生效)`,typeof v.token==`string`?v.token:``),l(`wechat.dsn`,`渲染基址 dsn(adapter 回连 DSH 用,形如 http://127.0.0.1:<端口>/dsh-tiddlywiki;留空=按请求自动推导。仅在启用微信发布时生效)`,typeof v.dsn==`string`?v.dsn:``);let b=t.prompt??{};i.append($(`h3`,`dsh-tw-settings-h`,`系统提示词(注入每个会话)`)),i.append($(`div`,`dsh-tw-settings-muted`,`插件把自己的约定(同步纪律 / 标签约定 / 链接格式等)注入每个会话的系统提示词。保存后**无需重启 dsh web**:section 会即时重新注册,当前会话从下一步起就使用新文本。`));let x=d(`prompt.enabled`,`注入 TiddlyWiki 提示词(关闭后本插件不再注入任何文本)`,b.enabled!==!1),S=p(`prompt.mode`,`内置文本形态`,b.mode===`full`?`full`:`slim`,[{value:`slim`,label:`精简(默认):只保留工具 schema 表达不了的约定`},{value:`full`,label:`完整:额外附一份由工具注册表实时生成的参数索引`}]),C=m(`prompt.extra`,`附加说明(永远追加在末尾,可放团队/个人规范)`,typeof b.extra==`string`?b.extra:``,5),ee=m(`prompt.override`,`整段替换(非空时取代上面的内置文本,附加说明仍会追加)`,typeof b.override==`string`?b.override:``,8),te=()=>c.some(e=>(e.key.startsWith(`prompt.`)||e.key===`wechat.enabled`)&&e.changed()),ne=$(`button`,`dsh-tw-settings-btn`,`预览注入文本(按表单当前值)`);ne.type=`button`,ne.title=`按表单当前值渲染注入文本(不用先保存);点「保存配置」后这就是实际注入的内容`;let w=$(`pre`,`dsh-tw-settings-prompt-preview`);w.hidden=!0,ne.addEventListener(`click`,()=>{if(!w.hidden){w.hidden=!0,w.textContent=``;return}ne.disabled=!0,(async()=>{try{let e=await ub(re,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({enabled:x.checked,mode:S.value,extra:C.value,override:ee.value,wechat:y.checked})});if(e.ok!==!0)throw Error(e.error??`获取失败`);w.textContent=e.enabled===!1?`(已关闭:不会注入任何提示词)`:`# 形态 ${e.mode??``} · ${e.length??0} 字符${te()?`(含未保存的修改,保存后才真正注入)`:``}\n\n${e.text??``}`,w.hidden=!1}catch(e){E(`读取提示词失败:${e instanceof Error?e.message:String(e)}`)}finally{ne.disabled=!1}})()}),i.append(ne,w);let T=t.bridge??{};d(`bridge.enabled`,`启用「本地剪藏桥」(书签小工具后端监听 127.0.0.1 端口,保存后立即生效)`,T.enabled===!0),f(`bridge.port`,`剪藏桥端口(整数 1–65535;改端口需重启 dsh web 生效)`,typeof T.port==`number`&&T.port>0?T.port:8618,{min:1,max:65535,step:1,integer:!0}),u(`bridge.token`,`剪藏桥 token(非空时校验书签的 x-clip-token 头;强烈建议设置。已设置时显示为 ********,原样保存=不改,清空=删除)`,typeof T.token==`string`?T.token:``),l(`bridge.tag`,`剪藏笔记默认 tag`,typeof T.tag==`string`&&T.tag.trim().length>0?T.tag.trim():`clip`);let ae=lb(r.saveError??``);ae.hidden=r.saveError===void 0;let oe=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`保存配置`);oe.type=`button`,oe.addEventListener(`click`,()=>{oe.disabled=!0,(async()=>{let e=c.filter(e=>e.invalid?.()!==void 0);if(e.length>0){E(`有 ${e.length} 个字段填得不对(见字段旁的红色提示),未保存`),oe.disabled=!1;return}let t={};for(let e of c){if(!e.changed())continue;let n=e.key.split(`.`),r=t;for(let t=0;t<n.length;t++){let i=n[t];if(i===void 0)break;if(t===n.length-1)r[i]=e.read();else{let e=r[i]??{};r[i]=e,r=e}}}if(Object.keys(t).length===0){E(`没有改动`),oe.disabled=!1;return}try{await ub(ie,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),be(),r.saveError=void 0,ae.hidden=!0,ae.textContent=``,E(`配置已保存`),n()}catch(e){r.saveError=`保存失败:${e instanceof Error?e.message:String(e)}`,ae.textContent=r.saveError,ae.hidden=!1,n()}finally{oe.disabled=!1}})()}),r.isDirty=()=>c.some(e=>e.changed()),i.append(ae,oe),e.append(i)}function mb(e,t,n,r,i,a){let o=n?.plugins??[],s=n?.themes??[],c=n?.languages??[],l=t?.plugins??[],u=new Set(t?.themes??[]),d=t?.languages??[],f=()=>a.plugins??new Set(l),p=()=>a.themes??new Set(u),m=()=>a.languages??new Set(d),h=new Set(r?.disabled??[]),g=new Set((r?.wikiPlugins??[]).map(e=>e.title)),_=$(`section`,`dsh-tw-settings-section`);_.append($(`h3`,`dsh-tw-settings-h`,`插件管理(自带官方插件)`));let v=$(`div`,`dsh-tw-settings-muted`,`勾选 = 写入 tiddlywiki.info 的启动安装清单(离线、与引擎版本配套),应用后重启 TW。这里只管引擎自带插件;在 TW 控制面板里安装/禁用/卸载的插件见下方「wiki 内插件」。`);_.append(v);let y=$(`input`,`dsh-tw-settings-input dsh-tw-settings-search`);y.placeholder=`搜索插件…`;let b=$(`div`,`dsh-tw-settings-list`),x=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`应用插件(重启 TW)`);x.type=`button`;let S=e=>{b.replaceChildren();let t=e.toLowerCase();for(let e of o){if(t.length>0&&!`${e.label} ${e.name} ${e.description}`.toLowerCase().includes(t))continue;let n=$(`input`,`dsh-tw-settings-check`);n.type=`checkbox`,n.checked=f().has(e.name),n.addEventListener(`change`,()=>{let t=f();n.checked?t.add(e.name):t.delete(e.name),a.plugins=t});let i=$(`label`,`dsh-tw-settings-row dsh-tw-settings-plugin`),o=$(`span`,`dsh-tw-settings-name`,e.label);o.title=e.name;let s=$(`span`,`dsh-tw-settings-muted`,e.description||e.name);if(i.append(n,o),r!=null&&h.has(e.title)){let e=$(`span`,`dsh-tw-settings-chip`,`TW 内已禁用`);e.dataset.state=`disabled`,e.title=`该插件在 tiddlywiki.info 里,但已在 TW 控制面板被禁用($:/config/Plugins/Disabled)——去 TW 面板重新启用`,i.append(e)}else if(r!=null&&!f().has(e.name)&&g.has(e.title)){let e=$(`span`,`dsh-tw-settings-chip`,`wiki 内已装`);e.dataset.state=`update`,e.title=`不在启动清单,但 wiki 里存在同名插件 tiddler(经 TW 原生安装),TW 运行时已在用`,i.append(e)}i.append(s),b.append(i)}};if(y.addEventListener(`input`,()=>S(y.value)),x.addEventListener(`click`,()=>{x.disabled=!0,(async()=>{try{await ub(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({plugins:[...f()]})}),a.plugins=void 0,E(`插件已应用,TW 已重启`),i()}catch(e){E(`应用失败:${e instanceof Error?e.message:String(e)}`),x.disabled=!1}})()}),S(``),_.append(y,b,x),e.append(_),r!=null){let t=new Set(o.map(e=>e.title)),n=(r.wikiPlugins??[]).filter(e=>!t.has(e.title)||h.has(e.title));if(n.length>0){let t=$(`section`,`dsh-tw-settings-section`);t.append($(`h3`,`dsh-tw-settings-h`,`wiki 内插件(经 TW 原生安装,只读)`)),t.append($(`div`,`dsh-tw-settings-muted`,`下列插件以 tiddler 形式随 wiki 文件保存(TW 控制面板 → 插件 安装/导入),不受上面勾选影响。启用 / 禁用 / 卸载请到 TW 控制面板操作。`));let r=$(`div`,`dsh-tw-settings-list`);for(let e of n){let t=$(`div`,`dsh-tw-settings-row dsh-tw-settings-plugin`),n=$(`span`,`dsh-tw-settings-name`,e.name||e.title);if(n.title=e.title,t.append(n),h.has(e.title)){let e=$(`span`,`dsh-tw-settings-chip`,`已禁用`);e.dataset.state=`disabled`,e.title=`该插件已在 TW 控制面板被禁用`,t.append(e)}else if(e.version){let n=$(`span`,`dsh-tw-settings-chip`,`v${e.version}`);n.dataset.state=`ok`,t.append(n)}let i=$(`span`,`dsh-tw-settings-muted`,e.description||e.title);i.title=e.title,t.append(i),r.append(t)}t.append(r),e.append(t)}}let C=$(`section`,`dsh-tw-settings-section`);C.append($(`h3`,`dsh-tw-settings-h`,`主题管理(自带主题)`));let ee=$(`div`,`dsh-tw-settings-muted`,`「加载」= TW 里可用的主题(可多选,依赖链自动带上,如 heavier 会带 snowwhite+vanilla);「活动」= 当前视觉主题(单选,自动加入加载集)。应用后重启 TW。`),te=$(`div`,`dsh-tw-settings-row dsh-tw-settings-head`);te.append($(`span`,`dsh-tw-settings-col`,`加载`),$(`span`,`dsh-tw-settings-col`,`活动`),$(`span`,`dsh-tw-settings-name`,`主题`));let ne=t?.themes??[],w=t?.themeActive,re=ne[ne.length-1],ie=typeof w==`string`&&s.some(e=>e.name===w)?w:re??`tiddlywiki/vanilla`,ae=()=>a.themeActive??ie,oe=$(`div`,`dsh-tw-settings-list`);for(let e of s){let t=$(`input`,`dsh-tw-settings-check`);t.type=`checkbox`,t.checked=p().has(e.name),t.title=`加载该主题`,t.addEventListener(`change`,()=>{let n=p();t.checked?n.add(e.name):n.delete(e.name),a.themes=n});let n=$(`input`,`dsh-tw-settings-check`);n.type=`radio`,n.name=`dsh-tw-active-theme`,n.checked=e.name===ae(),n.title=`设为活动主题`,n.addEventListener(`change`,()=>{n.checked&&(a.themeActive=e.name)});let r=$(`span`,`dsh-tw-settings-name`,e.label);r.title=e.name;let i=$(`span`,`dsh-tw-settings-muted`,e.description||e.name),o=$(`div`,`dsh-tw-settings-row dsh-tw-settings-plugin`);o.append(t,n,r,i),oe.append(o)}let se=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`应用主题(重启 TW)`);se.type=`button`,se.addEventListener(`click`,()=>{se.disabled=!0,(async()=>{try{await ub(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({themes:[...p()],themeActive:ae()})}),a.themes=void 0,a.themeActive=void 0,E(`主题已应用,TW 已重启`),i()}catch(e){E(`应用失败:${e instanceof Error?e.message:String(e)}`),se.disabled=!1}})()}),C.append(ee,te,oe,se),e.append(C);let ce=$(`section`,`dsh-tw-settings-section`);ce.append($(`h3`,`dsh-tw-settings-h`,`语言管理(自带官方语言包)`));let le=$(`div`,`dsh-tw-settings-muted`,`勾选启用语言插件并重启 TW;如中文请选 zh-Hans(简体)或 zh-CN。`),ue=$(`div`,`dsh-tw-settings-list`);for(let e of c){let t=$(`input`,`dsh-tw-settings-check`);t.type=`checkbox`,t.checked=m().has(e.name),t.addEventListener(`change`,()=>{let n=m();t.checked?n.add(e.name):n.delete(e.name),a.languages=n});let n=$(`label`,`dsh-tw-settings-row dsh-tw-settings-plugin`),r=$(`span`,`dsh-tw-settings-name`,e.label);r.title=e.name;let i=$(`span`,`dsh-tw-settings-muted`,e.description||e.name);n.append(t,r,i),ue.append(n)}let de=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`应用语言(重启 TW)`);de.type=`button`,de.addEventListener(`click`,()=>{de.disabled=!0,(async()=>{try{await ub(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({languages:[...m()]})}),a.languages=void 0,E(`语言已应用,TW 已重启`),i()}catch(e){E(`应用失败:${e instanceof Error?e.message:String(e)}`),de.disabled=!1}})()}),ce.append(le,ue,de),e.append(ce)}function hb(e,t,n){let r=$(`section`,`dsh-tw-settings-section`);r.append($(`h3`,`dsh-tw-settings-h`,`知识库位置(可切换)`));let i=$(`div`,`dsh-tw-settings-muted`,`读取中…`),a=$(`div`,`dsh-tw-settings-muted`),o=$(`div`,`dsh-tw-settings-muted`),s=$(`div`,`dsh-tw-settings-muted`),c=$(`input`,`dsh-tw-settings-input`),l=$(`input`,`dsh-tw-settings-input`);c.placeholder=`绝对路径,如 D:\\notes 或 $DSH_HOME/tiddlywiki`,l.placeholder=`文件夹名(默认 main;填 . 表示直接用上面这个目录)`;let u=$(`label`,`dsh-tw-settings-field`);u.append($(`span`,`dsh-tw-settings-label`,`根目录(wikiRoot)`),c);let d=$(`label`,`dsh-tw-settings-field`);d.append($(`span`,`dsh-tw-settings-label`,`文件夹名(wiki)`),l);let f=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`切换到这个位置`);f.type=`button`;let p=$(`button`,`dsh-tw-settings-btn`,`恢复为配置默认`);p.type=`button`;let m=$(`div`,`dsh-tw-settings-row`);m.append(f,p);let h=$(`div`,`dsh-tw-settings-row dsh-tw-settings-candidates`),g=$(`div`,`dsh-tw-settings-muted`,"切换会停掉并就地重启 TW 子进程(几秒);新目录若还没有 tiddlywiki.info,插件会自动 `--init server` 初始化一个全新知识库。选中的位置会记在 $DSH_HOME 下的指针文件里(不进 wiki),可用「恢复为配置默认」清除。"),_=(e,t)=>{f.disabled=e,p.disabled=e,f.textContent=e?t:`切换到这个位置`},v=async()=>{if(!t())try{let e=await ub(le);if(t())return;if(e.ok!==!0)throw Error(e.error??`获取失败`);let n=e.current??{};i.textContent=`当前:${n.path??`(未知)`}`;let r=n.source===`state`?`来源:指针文件(在设置页切换过)`:n.source===`config`?`来源:cordis 配置(config.wikiRoot / config.wiki)`:`来源:默认值($DSH_HOME/tiddlywiki + main)`;a.textContent=`${r} · 配置默认:${e.default?.path??`(未知)`}`,o.textContent=e.stateFile===void 0?``:`指针文件:${e.stateFile}(不存在=使用配置默认)`,s.textContent=e.error===void 0?``:`⚠️ ${e.error}`,c.value.length===0&&typeof n.root==`string`&&(c.value=n.root),l.value.length===0&&typeof n.name==`string`&&(l.value=n.name),h.replaceChildren();let u=e.candidates??[];if(u.length>0){h.append($(`span`,`dsh-tw-settings-label`,`同目录下可选的 wiki:`));for(let e of u){let t=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-chipbtn`,e===`.`?`(根目录本身)`:e);t.type=`button`,t.title=`填入文件夹名「${e}」`,t.addEventListener(`click`,()=>{l.value=e}),h.append(t)}}}catch(e){if(t())return;i.textContent=`读取位置失败:${e instanceof Error?e.message:String(e)}`}};f.addEventListener(`click`,()=>{let e=c.value.trim(),t=l.value.trim().length>0?l.value.trim():`main`;if(e.length===0){E(`请先填写根目录(绝对路径)`);return}window.confirm(`切换知识库到:\n${e}\\${t}\n\n会停止并重启 TW 子进程;当前对话/工具随后读写的是新知识库。确定继续?`)&&(_(!0,`切换中…(重启 TW)`),(async()=>{try{let r=await ub(ue,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({root:e,name:t}),signal:AbortSignal.timeout(12e4)});r.warning===void 0?E(`已切换到 ${r.path??``}`):E(`已切换到 ${r.path??``}(注意:${r.warning})`),be(),await v(),await n()}catch(e){E(`切换失败:${e instanceof Error?e.message:String(e)}`),await v()}finally{_(!1,``)}})())}),p.addEventListener(`click`,()=>{window.confirm(`恢复为配置默认位置?会删除位置指针文件,并(必要时)切回配置里的知识库。`)&&(_(!0,`切换中…(重启 TW)`),(async()=>{try{let e=await ub(de,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`,signal:AbortSignal.timeout(12e4)});E(e.warning===void 0?`已恢复为配置默认:${e.path??``}`:`已恢复默认(注意:${e.warning})`),be(),await v(),await n()}catch(e){E(`恢复失败:${e instanceof Error?e.message:String(e)}`),await v()}finally{_(!1,``)}})())}),r.append(i,a,o,u,d,m,h,s,g),e.append(r),v()}function gb(e,t){let n=$(`section`,`dsh-tw-settings-section`);n.append($(`h3`,`dsh-tw-settings-h`,`初始化(一次性预置)`));let r=$(`div`,`dsh-tw-settings-muted`,`这些是插件与 dsh 联动、需要在 wiki 里预置的 tiddler/配置。「发送给 Agent 按钮」和「TW 前端 API 基址」是功能必需项,启动时自动写入(只写缺失,不覆盖你的改动);其余为可选项,默认不自动写入、也不会强绑定——需要时点「重新初始化」写入,不想要了可随时「反初始化」移除。`),i=$(`div`,`dsh-tw-settings-list`),a=$(`div`,`dsh-tw-settings-muted`),o=async()=>{if(!t())try{let e=await ub(oe);if(t())return;if(e.ok!==!0||!Array.isArray(e.items))throw Error(e.error??`获取失败`);i.replaceChildren();let n=0,r=0;for(let t of e.items){t.present&&(n+=1),t.removable&&(r+=1);let e=$(`span`,`dsh-tw-settings-chip`,t.present?`✓`:`✗`);e.dataset.state=t.present?`ok`:`missing`,e.title=t.present?`已存在`:`缺失`;let a=$(`span`,`dsh-tw-settings-name`,t.title);a.title=t.id;let s=$(`span`,`dsh-tw-settings-muted`,t.detail??t.description),c=t.updateAvailable===!0?$(`span`,`dsh-tw-settings-chip`,`⬆ 有更新`):void 0;c!==void 0&&(c.dataset.state=`update`,c.title=`内置内容在本 wiki 预置之后更新过,可点「重新初始化」取用`);let l=t.userModified===!0?$(`span`,`dsh-tw-settings-chip`,`✏️ 本地已修改`):void 0;l!==void 0&&(l.dataset.state=`missing`,l.title=`这篇是你的内容:重新初始化会覆盖它`);let u=$(`button`,`dsh-tw-settings-btn`,t.updateAvailable===!0?`更新到内置版本`:`重新初始化`);u.type=`button`,u.title=`强制重写「${t.title}」的内置内容(会覆盖当前 tiddler)`,u.addEventListener(`click`,()=>{if(t.updateAvailable===!0){let e=t.userModified===!0?`「${t.title}」有你的本地修改,更新会覆盖它。`:t.userModified===void 0?`无法确认「${t.title}」是否被你编辑过(旧格式标记),更新可能覆盖你的改动。`:``;if(!window.confirm(`${e}${e.length>0?`
773
+ `)},_=()=>{let e=n.getState();o!==void 0&&(o.dataset.state=e.state),a!==void 0&&(a.title=`知识库 · ${e.tooltip}`),g()},v=async()=>{p=await tb(),!r&&(c!==void 0&&(c.textContent=p.text),l!==void 0&&(l.dataset.state=p.state),g())},y=p=>{if(r)return;if(i=document.createElement(`div`),i.className=`dsh-tw-fab-wrap`,s=document.createElement(`div`),s.className=`dsh-tw-fab-menu`,s.hidden=!0,p.showPanelStatus){let e=document.createElement(`div`);e.className=`dsh-tw-fab-status dsh-tw-fab-status-tiprow`,l=document.createElement(`span`),l.className=`dsh-tw-fab-status-dot`,l.dataset.state=`unknown`,c=document.createElement(`span`),c.className=`dsh-tw-fab-status-text`,c.textContent=`TiddlyWiki 服务…`,e.append(l,c),u=document.createElement(`div`),u.className=`dsh-tw-fab-tip`,u.hidden=!0,e.append(u),e.addEventListener(`mouseenter`,()=>{g(),u!==void 0&&(u.hidden=!1)}),e.addEventListener(`mouseleave`,()=>{u!==void 0&&(u.hidden=!0)}),s.append(e)}if(p.showQuickNote){let e=document.createElement(`button`);e.type=`button`,e.className=`dsh-tw-fab-item`,e.textContent=`📝 快速笔记`,e.title=`ui.quickNoteMode=native 时直接打开 TW 原生编辑器;card 时打开 Markdown 卡片`,e.addEventListener(`click`,()=>{m(),xe().then(e=>{e.quickNoteMode===`native`?t.openNative():t.open()})}),s.append(e)}if(p.showPanelStatus){d=document.createElement(`span`),d.textContent=`打开 TW 面板`;let t=document.createElement(`button`);t.type=`button`,t.className=`dsh-tw-fab-item`,t.append(document.createTextNode(`🖥 `),d),t.addEventListener(`click`,()=>{m(),e.toggle()}),s.append(t);let n=document.createElement(`button`);n.type=`button`,n.className=`dsh-tw-fab-item`,n.textContent=`🔄 重载 TW 面板`,n.addEventListener(`click`,()=>{m(),document.dispatchEvent(new CustomEvent(Je)),v()}),s.append(n)}if(p.showSyncButton){let e=document.createElement(`button`);e.type=`button`,e.className=`dsh-tw-fab-item`,e.textContent=`🔁 同步`,e.addEventListener(`click`,()=>{m(),n.trigger()}),s.append(e)}a=document.createElement(`button`),a.type=`button`,a.className=`dsh-tw-fab`,a.setAttribute(`aria-label`,`TiddlyWiki 知识库`);let y=document.createElement(`span`);y.className=`dsh-tw-fab-icon`,y.innerHTML=`<svg viewBox="0 0 16 16" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 2.5h8a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"/><path d="M6 6h4M6 8.5h2.5"/></svg>`,o=document.createElement(`span`),o.className=`dsh-tw-fab-dot`,o.dataset.state=n.getState().state,a.append(y,o),a.addEventListener(`click`,()=>{if(s!==void 0){if(f){m();return}f=!0,s.hidden=!1,_(),v()}}),i.append(s,a),document.body.append(i),_(),document.addEventListener(`click`,h,!0)},b=e.subscribe(()=>{d!==void 0&&(d.textContent=e.isOpen()?`收起 TW 面板`:`打开 TW 面板`)}),x=n.subscribe(_);return(async()=>{let e=await eb();r||!e.showQuickNote&&!e.showPanelStatus&&!e.showSyncButton||y(e)})(),()=>{r=!0,document.removeEventListener(`click`,h,!0),b(),x(),i?.remove()}}function rb(e){return function(){let[t,n]=c.useState(!1),[r,i]=c.useState(null),a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{let e=!0,t=e=>{let t=e.detail;n(t?.open===!0)};return window.addEventListener(jy,t),xe().then(t=>{e&&i(t.quickNoteMode)}),()=>{e=!1,window.removeEventListener(jy,t)}},[]),c.useLayoutEffect(()=>{let e=a.current;if(e===null)return;let t=()=>{let t=null,n=null,r=e;for(;r!==null&&r!==document.documentElement&&(r=r.parentElement,r!==null);){for(let e of r.querySelectorAll(`textarea, [contenteditable]:not([contenteditable="false"]), [role="textbox"]`))if(e.getBoundingClientRect().width>300){t=e,n=r;break}if(n!==null)break}if(t===null||n===null)return null;let i=n.getBoundingClientRect().width,a=t,o=null,s=0;for(;a!==null&&a!==n;){let e=a.getBoundingClientRect().width;e>0&&e<i-8&&e>=s&&(s=e,o=a),a=a.parentElement}return o},n=()=>{let n=e.getBoundingClientRect(),r=t(),i=r===null?n.right:r.getBoundingClientRect().right,a=Math.max(0,n.right-i);return e.style.paddingRight!==`${a}px`&&(e.style.paddingRight=`${a}px`),r!==null};n();let r=new ResizeObserver(n),i=e;for(;i!==null&&i!==document.documentElement&&(r.observe(i),!(i instanceof HTMLElement&&i.hasAttribute(`data-phase`)));)i=i.parentElement;window.addEventListener(`resize`,n),document.addEventListener(`visibilitychange`,n);let o=0,s=0,c=window.setInterval(()=>{if(s++,!n()){s>=20&&window.clearInterval(c);return}o++,o>=3&&window.clearInterval(c)},1500),l=window.setTimeout(n,120),u=window.setTimeout(n,600);return()=>{r.disconnect(),window.removeEventListener(`resize`,n),document.removeEventListener(`visibilitychange`,n),window.clearInterval(c),window.clearTimeout(l),window.clearTimeout(u)}},[]);let s=r===`native`,l=s?`快速笔记`:t?`快速笔记(已打开)`:`快速笔记`,u=s?`快速笔记:直接打开 TiddlyWiki 原生编辑器(再次点击可收起弹窗)`:t?`快速笔记已打开(点此按钮或卡片右上角 ✕ 收起)`:`打开快速笔记(在按钮上方弹出,可拖动标题栏移动)`;return c.createElement(`div`,{ref:a,className:`dsh-tw-dock-note`},c.createElement(`button`,{ref:o,type:`button`,className:t?`dsh-tw-dock-note-btn dsh-tw-dock-note-btn-active`:`dsh-tw-dock-note-btn`,title:u,onClick:()=>{xe().then(t=>{t.quickNoteMode===`native`?Tt()&&!Et()?Ot():e.openNative():e.isOpen()?e.close():e.open(o.current??void 0)})}},c.createElement(`span`,{className:`dsh-tw-dock-note-icon`,"aria-hidden":`true`},`📝`),c.createElement(`span`,{className:`dsh-tw-dock-note-label`},l)))}}async function ib(e,t=15e3){try{let n=await fetch(_,{method:`POST`,headers:{"content-type":`application/json`,"x-requested-with":`TiddlyWiki`},body:JSON.stringify({title:e}),signal:AbortSignal.timeout(t)});if(!n.ok)return null;let r=await n.text();return r.trim().length>0?r:null}catch{return null}}function ab(){return Ze()}async function ob(e){try{let t=await fetch(`${g}?title=${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(8e3)});if(t.status===404)return`no`;if(!t.ok)return`unknown`;let n=await t.json().catch(()=>null);return n===null?`unknown`:n.notFound===!0?`no`:`yes`}catch{return`unknown`}}function sb(e){let{sessionId:t,viewRequest:n,completeViewRequest:r}=e,[i,a]=c.useState(`loading`),[o,s]=c.useState(null),[l,u]=c.useState(null),[d,f]=c.useState(``),[p,m]=c.useState(!1),h=c.useRef(0),g=c.useRef(!0),_=c.useRef(0),v=c.useRef(0),y=c.useCallback(async e=>{let n=++h.current;if(!g.current)return;let r=e?.silent===!0;r||a(`loading`);let i=e=>{if(_.current++,r){m(!0);return}a(`error`),f(e)};if(typeof t!=`string`||t.length===0){a(`error`),f(`缺少会话 ID`);return}if(_.current>=3){if(r){m(!0);return}a(`error`),f(`连续 3 次生成失败,已停止自动重试,请点「🔄 刷新」`);return}try{let e=await fetch(ne,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({session:t}),signal:AbortSignal.timeout(25e3)}),o=await e.json().catch(()=>null);if(!g.current||n!==h.current)return;if(!e.ok||o?.ok!==!0){i(o?.error??`HTTP ${e.status}`);return}if(typeof o.title!=`string`||o.title.length===0){i(`汇总生成失败:缺少标题`);return}u(o.title);let c=await ib(o.title);if(!g.current||n!==h.current)return;if(c===null){let e=await ob(o.title);if(!g.current||n!==h.current)return;if(e===`no`){if(_.current++,_.current<3){y();return}a(`error`),f(`汇总条目不存在,自动重建失败,请重试`);return}if(e===`unknown`){if(r){m(!0);return}a(`error`),f(`渲染失败:wiki 渲染服务不可用(host /render),条目状态未知`);return}i(`渲染失败:wiki 渲染服务不可用(host /render)`);return}_.current=0,v.current=Date.now(),m(!1),s(c),a(`ready`)}catch(e){if(!g.current||n!==h.current)return;i(e instanceof Error?e.message:String(e))}},[t]);c.useEffect(()=>(g.current=!0,_.current=0,v.current=Date.now(),m(!1),y(),()=>{g.current=!1}),[y]),c.useEffect(()=>{if(l===null)return;let e=!0,t=window.setInterval(()=>{(async()=>{if(!e||typeof document<`u`&&document.hidden)return;let t=await ob(l);if(e){if(t===`unknown`){m(!0);return}if(t===`no`){if(_.current++,_.current<3){y();return}a(`error`),f(`汇总条目已失效且自动重建多次失败,请点「🔄 刷新」重试`);return}if(Date.now()-v.current>18e4){y({silent:!0});return}_.current=0,m(!1)}})()},3e4);return()=>{e=!1,window.clearInterval(t)}},[l,y]),c.useEffect(()=>{n!=null&&r?.()},[n,r]);let b=()=>{_.current=0,y()},x;return x=i===`loading`?c.createElement(`div`,{className:`dsh-tw-summary-state`},c.createElement(`div`,{className:`dsh-tw-summary-state-spin`},`⏳`),c.createElement(`div`,null,`正在生成会话 wiki 汇总…`)):i===`error`?c.createElement(`div`,{className:`dsh-tw-summary-state`},c.createElement(`div`,{className:`dsh-tw-summary-state-title`},`知识库汇总暂不可用`),c.createElement(`div`,{className:`dsh-tw-summary-state-detail`},d),c.createElement(`button`,{type:`button`,className:`dsh-tw-summary-btn`,onClick:b},`重试`)):c.createElement(`div`,{className:`dsh-tw-summary-native dsh-tw-toolcard-native`},p?c.createElement(`div`,{className:`dsh-tw-summary-state-detail`},`⚠️ 未能确认最新状态(wiki 查询或刷新失败),以下是上次生成的内容`):null,c.createElement(`div`,{dangerouslySetInnerHTML:{__html:o??``}})),c.createElement(`div`,{className:`dsh-tw-summary`,"data-dsh-tw-summary":`true`},c.createElement(`div`,{className:`dsh-tw-summary-bar`},c.createElement(`span`,{className:`dsh-tw-summary-bar-title`},`📚 本会话知识库`),c.createElement(`span`,{className:`dsh-tw-summary-bar-hint`},`产生 / 读取 / 检索过的笔记(含子代理)`),c.createElement(`span`,{className:`dsh-tw-summary-bar-spacer`}),c.createElement(`button`,{type:`button`,className:`dsh-tw-summary-btn`,onClick:b,disabled:i===`loading`,title:`重新生成并刷新汇总`},`🔄 刷新`)),x)}function cb(e,t){if(!(e===void 0||t.showSessionTab===!1))return Xe(t.tabLabel),e.inject(`conversation.view`,()=>e.register({name:`conversation.view`,id:`dsh-tiddlywiki-summary`,order:20,label:ab},sb))}function $(e,t,n){let r=document.createElement(e);return t!==void 0&&(r.className=t),n!==void 0&&(r.textContent=n),r}function lb(e){let t=$(`div`,`dsh-tw-settings-banner`);return t.dataset.tone=`error`,t.setAttribute(`style`,`border:1px solid #c0392b;background:#fdecea;color:#8c1c13;border-radius:6px;padding:10px 12px;margin:0 0 12px;font-size:12px;line-height:1.6;white-space:pre-wrap;`),t.textContent=e,t}async function ub(e,t){let n=await fetch(e,{...t,signal:t?.signal??AbortSignal.timeout(15e3)}),r=await n.json().catch(()=>({}));if(!n.ok){let e=r.error??`HTTP ${n.status}`;throw Error(e)}return r}function db(e){let t=!1;e.classList.add(`dsh-tw-settings`);let n=$(`div`,`dsh-tw-settings-error`);n.hidden=!0;let r=$(`div`,`dsh-tw-settings-row dsh-tw-settings-status`),i=$(`div`,`dsh-tw-settings-body`);e.append(n,r,i);let a=[],o={},s={},c=!1,l=async()=>{c||i.replaceChildren($(`div`,`dsh-tw-settings-muted`,`加载中…`));try{let e=await ub(w);if(t)return;c=!0,n.hidden=!0,n.replaceChildren(),fb(r,e,l),_b(i,e,l,()=>t,o,s)}catch(e){if(t)return;c||i.replaceChildren($(`div`,`dsh-tw-settings-muted`,`配置尚未加载。`));let r=$(`button`,`dsh-tw-settings-btn`,`重试`);r.type=`button`,r.addEventListener(`click`,()=>{l()}),n.replaceChildren($(`span`,void 0,`加载配置失败:${e instanceof Error?e.message:String(e)} `),r),n.hidden=!1}};return l(),a.push(()=>{t=!0,e.replaceChildren(),e.classList.remove(`dsh-tw-settings`)}),()=>{for(let e of a.splice(0))e()}}function fb(e,t,n){e.replaceChildren();let r=t.server??{},i=r.status??`unknown`,a=$(`span`,`dsh-tw-settings-chip`,i);a.dataset.state=i;let o=$(`span`,`dsh-tw-settings-muted`,[r.url===void 0?``:`TW ${r.url}`,t.git?.branch===void 0?``:`git ${t.git.branch}`,t.git?.lastCommit===void 0?``:t.git.lastCommit,t.git?.conflict===void 0?t.git?.dirty===!0?`有未提交改动`:``:`⚠️ 冲突未解决(${t.git.conflict.files.length} 个文件,已阻止提交)`].filter(Boolean).join(` · `)),s=$(`button`,`dsh-tw-settings-btn`,`同步`);s.type=`button`,s.title=`git 同步(pull → commit → push)`,s.addEventListener(`click`,()=>{s.disabled=!0,s.textContent=`同步中…`,(async()=>{try{let e=await fetch(ee,{method:`POST`,signal:AbortSignal.timeout(12e4)}),t=fe(await e.json().catch(()=>null),e.status);E(t.ok?`同步完成:${t.message}`:`同步失败:${t.message}`)}catch(e){E(`同步失败:${e instanceof Error?e.message:String(e)}`)}finally{s.disabled=!1,s.textContent=`同步`,n()}})()});let c=$(`button`,`dsh-tw-settings-btn`,`重启 TW`);c.type=`button`,c.addEventListener(`click`,()=>{c.disabled=!0,c.textContent=`重启中…`,(async()=>{try{await ub(ae,{method:`POST`,signal:AbortSignal.timeout(12e4)}),E(`TW 已重启`)}catch(e){E(`重启失败:${e instanceof Error?e.message:String(e)}`)}finally{c.disabled=!1,c.textContent=`重启 TW`,n()}})()}),e.append(a,o,s,c)}function pb(e,t,n,r){let i=$(`section`,`dsh-tw-settings-section`);i.append($(`h3`,`dsh-tw-settings-h`,`常规配置`));let a=t.note??{},o=t.git??{},s=t.ui??{},c=[],l=(e,t,n)=>{let r=$(`input`,`dsh-tw-settings-input`);r.value=n;let a=$(`label`,`dsh-tw-settings-field`);a.append($(`span`,`dsh-tw-settings-label`,t),r),c.push({key:e,initial:n,read:()=>r.value.trim(),changed:()=>r.value.trim()!==n}),i.append(a)},u=(e,t,n)=>{let r=$(`input`,`dsh-tw-settings-input`);r.type=`password`,r.value=n,r.autocomplete=`off`;let a=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-chipbtn`,`👁`);a.type=`button`,a.title=`显示 / 隐藏`,a.setAttribute(`aria-label`,`显示 / 隐藏`),a.addEventListener(`click`,e=>{e.preventDefault();let t=r.type===`password`;r.type=t?`text`:`password`,a.textContent=t?`🙈`:`👁`});let o=$(`label`,`dsh-tw-settings-field`);o.append($(`span`,`dsh-tw-settings-label`,t),r,a),c.push({key:e,initial:n,read:()=>r.value.trim(),changed:()=>r.value.trim()!==n}),i.append(o)},d=(e,t,n)=>{let r=$(`input`,`dsh-tw-settings-check`);r.type=`checkbox`,r.checked=n;let a=$(`label`,`dsh-tw-settings-field dsh-tw-settings-field-check`);return a.append(r,$(`span`,`dsh-tw-settings-label`,t)),c.push({key:e,initial:n,read:()=>r.checked,changed:()=>r.checked!==n}),i.append(a),r},f=(e,t,n,r)=>{let a=$(`input`,`dsh-tw-settings-input`);a.type=`number`,a.value=String(n),r?.min!==void 0&&(a.min=String(r.min)),r?.max!==void 0&&(a.max=String(r.max)),r?.step!==void 0&&(a.step=String(r.step));let o=$(`div`,`dsh-tw-settings-error`);o.hidden=!0;let s=()=>{let e=a.value.trim();if(e.length===0)return`不能为空`;let t=Number(e);if(!Number.isFinite(t))return`请输入数字`;if(r?.integer===!0&&!Number.isInteger(t))return`必须是整数`;if(r?.min!==void 0&&t<r.min)return`不能小于 ${r.min}`;if(r?.max!==void 0&&t>r.max)return`不能大于 ${r.max}`},l=()=>{let e=s();o.textContent=e===void 0?``:`⚠️ ${e}(保存会被拒绝)`,o.hidden=e===void 0,e===void 0?a.removeAttribute(`aria-invalid`):a.setAttribute(`aria-invalid`,`true`)};a.addEventListener(`input`,l);let u=()=>{let e=a.value.trim(),t=Number(e);return e.length===0||!Number.isFinite(t)?e:t},d=$(`label`,`dsh-tw-settings-field`);d.append($(`span`,`dsh-tw-settings-label`,t),a,o),c.push({key:e,initial:n,read:u,changed:()=>u()!==n,invalid:s}),l(),i.append(d)},p=(e,t,n,r)=>{let a=$(`select`,`dsh-tw-settings-input`);for(let e of r){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,e.value===n&&(t.selected=!0),a.append(t)}let o=$(`label`,`dsh-tw-settings-field`);return o.append($(`span`,`dsh-tw-settings-label`,t),a),c.push({key:e,initial:n,read:()=>a.value,changed:()=>a.value!==n}),i.append(o),a},m=(e,t,n,r)=>{let a=$(`textarea`,`dsh-tw-settings-input dsh-tw-settings-area`);a.rows=r,a.value=n;let o=$(`label`,`dsh-tw-settings-field dsh-tw-settings-field-area`);return o.append($(`span`,`dsh-tw-settings-label`,t),a),c.push({key:e,initial:n,read:()=>a.value.trim(),changed:()=>a.value.trim()!==n}),i.append(o),a};l(`note.tag`,`快速笔记默认 tag`,typeof a.tag==`string`?a.tag:`inbox`),d(`note.workspaceMark`,`新建笔记自动标工作区(ws/<项目名> 标签 + workspace 字段,取自当前会话工作目录)`,a.workspaceMark!==!1),d(`git.autoCommit`,`自动 commit(防抖)`,o.autoCommit!==!1),f(`git.debounceMs`,`自动 commit 防抖(ms;范围 0–3600000)`,typeof o.debounceMs==`number`?o.debounceMs:6e4,{min:0,max:36e5,step:1e3,integer:!0}),l(`git.remote`,`git 远端(空=仅本地;保存后即时生效,但**清空不会删除已配置的 origin**,需要时请用 git 命令处理)`,typeof o.remote==`string`?o.remote:``),l(`git.branch`,`git 分支(**只在仓库首次初始化时生效**;已有仓库请用 git 命令改分支——上面的状态行显示的是真实分支)`,typeof o.branch==`string`?o.branch:`main`);let h=t.startup??{};f(`startup.readyTimeoutMs`,`TW 启动就绪等待(ms;默认 60000,范围 5000–600000,超时上限为其 3 倍,对下次启动/重启生效)`,typeof h.readyTimeoutMs==`number`&&h.readyTimeoutMs>0?h.readyTimeoutMs:6e4,{min:5e3,max:6e5,step:1e3}),d(`ui.showQuickNote`,`显示「知识库」按钮里的「快速笔记」入口`,s.showQuickNote!==!1),d(`ui.showQuickNoteDock`,`显示聊天输入框上方的「快速笔记」快捷按钮`,s.showQuickNoteDock!==!1),p(`ui.quickNoteMode`,`点击「快速笔记」的打开方式`,typeof s.quickNoteMode==`string`&&s.quickNoteMode===`card`?`card`:`native`,[{value:`native`,label:`原生编辑器:直接弹出 TW 原生编辑页(新建/恢复草稿)`},{value:`card`,label:`Markdown 卡片:弹出现有快速笔记卡片(CodeMirror 编辑器)`}]),l(`ui.sidebarLabel`,`侧边栏 TW 入口显示名称`,typeof s.sidebarLabel==`string`&&s.sidebarLabel.trim().length>0?s.sidebarLabel.trim():`TiddlyWiki`),d(`ui.showPanelStatus`,`显示「知识库」按钮里的 TW 面板/重载入口与状态行`,s.showPanelStatus!==!1),d(`ui.showSyncButton`,`显示「知识库」按钮里的「同步」入口与 git 状态点`,s.showSyncButton!==!1),d(`ui.followDshTheme`,`嵌入式 TW 跟随 DSH 深浅主题(暗色时自动切深色 palette,不写回 wiki)`,s.followDshTheme!==!1),l(`ui.darkPalette`,`暗色时 TW palette(tiddler 标题)`,typeof s.darkPalette==`string`&&s.darkPalette.trim().length>0?s.darkPalette.trim():`$:/palettes/CupertinoDark`),l(`ui.tabLabel`,`会话顶部「知识库」Tab 名称`,typeof s.tabLabel==`string`&&s.tabLabel.trim().length>0?s.tabLabel.trim():`知识库`),d(`ui.showSessionTab`,`显示会话顶部「知识库」Tab(本会话相关 wiki 笔记汇总)`,s.showSessionTab!==!1),d(`ui.showRightbarTab`,`在 DSH 右侧边栏提供 TiddlyWiki 入口/Tab(与聊天并排)`,s.showRightbarTab!==!1);let g=s.sendToAgent??{};d(`ui.sendToAgent.enabled`,`启用「发送给 Agent」(TW 笔记 → DSH 会话注入)`,g.enabled!==!1),l(`ui.sendToAgent.endpoint`,`TW 端请求基址(空=自动取当前 DSH origin)`,typeof g.endpoint==`string`?g.endpoint:``),u(`ui.sendToAgent.token`,`共享 token(非空时路由校验 x-send-to-agent-token 头;已设置时显示为 ********,原样保存=不改,清空=删除)`,typeof g.token==`string`?g.token:``);let _=s.allArticles??{};f(`ui.allArticles.pageSize`,`「所有文章」每页条数(1–200)`,typeof _.pageSize==`number`?_.pageSize:10,{min:1,max:200,step:1,integer:!0}),i.append($(`h3`,`dsh-tw-settings-h`,`可选功能:微信公众号发布`)),i.append($(`div`,`dsh-tw-settings-muted`,`把 wiki 笔记一键发到公众号草稿箱(可选点发表)。**需要额外安装**:opencli 与 Browser Bridge 浏览器扩展,并让浏览器登录 mp.weixin.qq.com;adapter 在本仓库 tools/wechat/,安装与排错见 docs/wechat-publish-setup.md。不安装/不开启它,插件其他功能完全不受影响。开启后:注入提示词会多一条「发布前先读发布元数据规范」的约定,并在启动时把「发布元数据规范」与「微信公众号发布指南」(安装/换机还原步骤,等于仓库 docs/wechat-publish-setup.md)两篇文档写进 wiki(同名不覆盖)。`));let v=t.wechat??{},y=d(`wechat.enabled`,`启用微信公众号发布(默认关;需先按 docs/wechat-publish-setup.md 安装 opencli + 浏览器扩展)`,v.enabled===!0);l(`wechat.command`,`opencli 命令(默认 opencli;用别名或绝对路径时填这里。仅在启用微信发布时生效)`,typeof v.command==`string`&&v.command.trim().length>0?v.command.trim():`opencli`),p(`wechat.adapter`,`发布适配器(仅在启用微信发布时生效)`,v.adapter===`publish-note-imgs`?`publish-note-imgs`:`publish-note`,[{value:`publish-note`,label:`publish-note(默认):图文排版,封面单图`},{value:`publish-note-imgs`,label:`publish-note-imgs:正文内嵌图全部上传 CDN(需先重跑 install-wechat-adapters.mjs)`}]),u(`wechat.token`,`发布 token(非空时 /wechat/* 校验 x-wechat-publish-token 头,强烈建议设置,否则任何能打开本页的人都能替你发文;已设置时显示为 ********,原样保存=不改,清空=删除。仅在启用微信发布时生效)`,typeof v.token==`string`?v.token:``),l(`wechat.dsn`,`渲染基址 dsn(adapter 回连 DSH 用,形如 http://127.0.0.1:<端口>/dsh-tiddlywiki;留空=按请求自动推导。仅在启用微信发布时生效)`,typeof v.dsn==`string`?v.dsn:``);let b=t.prompt??{};i.append($(`h3`,`dsh-tw-settings-h`,`系统提示词(注入每个会话)`)),i.append($(`div`,`dsh-tw-settings-muted`,`插件把自己的约定(同步纪律 / 标签约定 / 链接格式等)注入每个会话的系统提示词。保存后**无需重启 dsh web**:section 会即时重新注册,当前会话从下一步起就使用新文本。`));let x=d(`prompt.enabled`,`注入 TiddlyWiki 提示词(关闭后本插件不再注入任何文本)`,b.enabled!==!1),S=p(`prompt.mode`,`内置文本形态`,b.mode===`full`?`full`:`slim`,[{value:`slim`,label:`精简(默认):只保留工具 schema 表达不了的约定`},{value:`full`,label:`完整:额外附一份由工具注册表实时生成的参数索引`}]),C=m(`prompt.extra`,`附加说明(永远追加在末尾,可放团队/个人规范)`,typeof b.extra==`string`?b.extra:``,5),ee=m(`prompt.override`,`整段替换(非空时取代上面的内置文本,附加说明仍会追加)`,typeof b.override==`string`?b.override:``,8),te=()=>c.some(e=>(e.key.startsWith(`prompt.`)||e.key===`wechat.enabled`)&&e.changed()),ne=$(`button`,`dsh-tw-settings-btn`,`预览注入文本(按表单当前值)`);ne.type=`button`,ne.title=`按表单当前值渲染注入文本(不用先保存);点「保存配置」后这就是实际注入的内容`;let w=$(`pre`,`dsh-tw-settings-prompt-preview`);w.hidden=!0,ne.addEventListener(`click`,()=>{if(!w.hidden){w.hidden=!0,w.textContent=``;return}ne.disabled=!0,(async()=>{try{let e=await ub(re,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({enabled:x.checked,mode:S.value,extra:C.value,override:ee.value,wechat:y.checked})});if(e.ok!==!0)throw Error(e.error??`获取失败`);w.textContent=e.enabled===!1?`(已关闭:不会注入任何提示词)`:`# 形态 ${e.mode??``} · ${e.length??0} 字符${te()?`(含未保存的修改,保存后才真正注入)`:``}\n\n${e.text??``}`,w.hidden=!1}catch(e){E(`读取提示词失败:${e instanceof Error?e.message:String(e)}`)}finally{ne.disabled=!1}})()}),i.append(ne,w);let T=t.bridge??{};d(`bridge.enabled`,`启用「本地剪藏桥」(书签小工具后端监听 127.0.0.1 端口,保存后立即生效)`,T.enabled===!0),f(`bridge.port`,`剪藏桥端口(整数 1–65535;改端口需重启 dsh web 生效)`,typeof T.port==`number`&&T.port>0?T.port:8618,{min:1,max:65535,step:1,integer:!0}),u(`bridge.token`,`剪藏桥 token(非空时校验书签的 x-clip-token 头;强烈建议设置。已设置时显示为 ********,原样保存=不改,清空=删除)`,typeof T.token==`string`?T.token:``),l(`bridge.tag`,`剪藏笔记默认 tag`,typeof T.tag==`string`&&T.tag.trim().length>0?T.tag.trim():`clip`);let ae=lb(r.saveError??``);ae.hidden=r.saveError===void 0;let oe=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`保存配置`);oe.type=`button`,oe.addEventListener(`click`,()=>{oe.disabled=!0,(async()=>{let e=c.filter(e=>e.invalid?.()!==void 0);if(e.length>0){E(`有 ${e.length} 个字段填得不对(见字段旁的红色提示),未保存`),oe.disabled=!1;return}let t={};for(let e of c){if(!e.changed())continue;let n=e.key.split(`.`),r=t;for(let t=0;t<n.length;t++){let i=n[t];if(i===void 0)break;if(t===n.length-1)r[i]=e.read();else{let e=r[i]??{};r[i]=e,r=e}}}if(Object.keys(t).length===0){E(`没有改动`),oe.disabled=!1;return}try{await ub(ie,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),be(),r.saveError=void 0,ae.hidden=!0,ae.textContent=``,E(`配置已保存`),n()}catch(e){r.saveError=`保存失败:${e instanceof Error?e.message:String(e)}`,ae.textContent=r.saveError,ae.hidden=!1,n()}finally{oe.disabled=!1}})()}),r.isDirty=()=>c.some(e=>e.changed()),i.append(ae,oe),e.append(i)}function mb(e,t,n,r,i,a){let o=n?.plugins??[],s=n?.themes??[],c=n?.languages??[],l=t?.plugins??[],u=new Set(t?.themes??[]),d=t?.languages??[],f=()=>a.plugins??new Set(l),p=()=>a.themes??new Set(u),m=()=>a.languages??new Set(d),h=new Set(r?.disabled??[]),g=new Set((r?.wikiPlugins??[]).map(e=>e.title)),_=$(`section`,`dsh-tw-settings-section`);_.append($(`h3`,`dsh-tw-settings-h`,`插件管理(自带官方插件)`));let v=$(`div`,`dsh-tw-settings-muted`,`勾选 = 写入 tiddlywiki.info 的启动安装清单(离线、与引擎版本配套),应用后重启 TW。这里只管引擎自带插件;在 TW 控制面板里安装/禁用/卸载的插件见下方「wiki 内插件」。`);_.append(v);let y=$(`input`,`dsh-tw-settings-input dsh-tw-settings-search`);y.placeholder=`搜索插件…`;let b=$(`div`,`dsh-tw-settings-list`),x=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`应用插件(重启 TW)`);x.type=`button`;let S=()=>{x.disabled=a.plugins===void 0},C=e=>{b.replaceChildren();let t=e.toLowerCase();for(let e of o){if(t.length>0&&!`${e.label} ${e.name} ${e.description}`.toLowerCase().includes(t))continue;let n=$(`input`,`dsh-tw-settings-check`);n.type=`checkbox`,n.checked=f().has(e.name),n.addEventListener(`change`,()=>{let t=f();n.checked?t.add(e.name):t.delete(e.name),a.plugins=t,S()});let i=$(`label`,`dsh-tw-settings-row dsh-tw-settings-plugin`),o=$(`span`,`dsh-tw-settings-name`,e.label);o.title=e.name;let s=$(`span`,`dsh-tw-settings-muted`,e.description||e.name);if(i.append(n,o),r!=null&&h.has(e.title)){let e=$(`span`,`dsh-tw-settings-chip`,`TW 内已禁用`);e.dataset.state=`disabled`,e.title=`该插件在 tiddlywiki.info 里,但已在 TW 控制面板被禁用($:/config/Plugins/Disabled)——去 TW 面板重新启用`,i.append(e)}else if(r!=null&&!l.includes(e.name)&&g.has(e.title)){let e=$(`span`,`dsh-tw-settings-chip`,`wiki 内已装`);e.dataset.state=`update`,e.title=`不在启动清单,但 wiki 里存在同名插件 tiddler(经 TW 原生安装),TW 运行时已在用`,i.append(e)}i.append(s),b.append(i)}};if(y.addEventListener(`input`,()=>C(y.value)),x.addEventListener(`click`,()=>{a.plugins!==void 0&&(x.disabled=!0,(async()=>{try{await ub(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({plugins:[...f()]})}),a.plugins=void 0,E(`插件已应用,TW 已重启`),i()}catch(e){E(`应用失败:${e instanceof Error?e.message:String(e)}`),S()}})())}),C(``),S(),_.append(y,b,x),e.append(_),r!=null){let t=new Set(o.map(e=>e.title)),n=(r.wikiPlugins??[]).filter(e=>!t.has(e.title)||h.has(e.title));if(n.length>0){let t=$(`section`,`dsh-tw-settings-section`);t.append($(`h3`,`dsh-tw-settings-h`,`wiki 内插件(经 TW 原生安装,只读)`)),t.append($(`div`,`dsh-tw-settings-muted`,`下列插件以 tiddler 形式随 wiki 文件保存(TW 控制面板 → 插件 安装/导入),不受上面勾选影响。启用 / 禁用 / 卸载请到 TW 控制面板操作。`));let r=$(`div`,`dsh-tw-settings-list`);for(let e of n){let t=$(`div`,`dsh-tw-settings-row dsh-tw-settings-plugin`),n=$(`span`,`dsh-tw-settings-name`,e.name||e.title);if(n.title=e.title,t.append(n),h.has(e.title)){let e=$(`span`,`dsh-tw-settings-chip`,`已禁用`);e.dataset.state=`disabled`,e.title=`该插件已在 TW 控制面板被禁用`,t.append(e)}else if(e.version){let n=$(`span`,`dsh-tw-settings-chip`,`v${e.version}`);n.dataset.state=`ok`,t.append(n)}let i=$(`span`,`dsh-tw-settings-muted`,e.description||e.title);i.title=e.title,t.append(i),r.append(t)}t.append(r),e.append(t)}}let ee=$(`section`,`dsh-tw-settings-section`);ee.append($(`h3`,`dsh-tw-settings-h`,`主题管理(自带主题)`));let te=$(`div`,`dsh-tw-settings-muted`,`「加载」= TW 里可用的主题(可多选,依赖链自动带上,如 heavier 会带 snowwhite+vanilla);「活动」= 当前视觉主题(单选,自动加入加载集)。应用后重启 TW。`),ne=$(`div`,`dsh-tw-settings-row dsh-tw-settings-head`);ne.append($(`span`,`dsh-tw-settings-col`,`加载`),$(`span`,`dsh-tw-settings-col`,`活动`),$(`span`,`dsh-tw-settings-name`,`主题`));let w=t?.themes??[],re=t?.themeActive,ie=w[w.length-1],ae=typeof re==`string`&&s.some(e=>e.name===re)?re:ie??`tiddlywiki/vanilla`,oe=()=>a.themeActive??ae,se=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`应用主题(重启 TW)`);se.type=`button`;let ce=()=>{se.disabled=a.themes===void 0&&a.themeActive===void 0},le=$(`div`,`dsh-tw-settings-list`);for(let e of s){let t=$(`input`,`dsh-tw-settings-check`);t.type=`checkbox`,t.checked=p().has(e.name),t.title=`加载该主题`,t.addEventListener(`change`,()=>{let n=p();t.checked?n.add(e.name):n.delete(e.name),a.themes=n,ce()});let n=$(`input`,`dsh-tw-settings-check`);n.type=`radio`,n.name=`dsh-tw-active-theme`,n.checked=e.name===oe(),n.title=`设为活动主题`,n.addEventListener(`change`,()=>{n.checked&&(a.themeActive=e.name),ce()});let r=$(`span`,`dsh-tw-settings-name`,e.label);r.title=e.name;let i=$(`span`,`dsh-tw-settings-muted`,e.description||e.name),o=$(`div`,`dsh-tw-settings-row dsh-tw-settings-plugin`);o.append(t,n,r,i),le.append(o)}se.addEventListener(`click`,()=>{a.themes===void 0&&a.themeActive===void 0||(se.disabled=!0,(async()=>{try{await ub(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({themes:[...p()],themeActive:oe()})}),a.themes=void 0,a.themeActive=void 0,E(`主题已应用,TW 已重启`),i()}catch(e){E(`应用失败:${e instanceof Error?e.message:String(e)}`),ce()}})())}),ce(),ee.append(te,ne,le,se),e.append(ee);let ue=$(`section`,`dsh-tw-settings-section`);ue.append($(`h3`,`dsh-tw-settings-h`,`语言管理(自带官方语言包)`));let de=$(`div`,`dsh-tw-settings-muted`,`勾选启用语言插件并重启 TW;如中文请选 zh-Hans(简体)或 zh-CN。`),fe=$(`div`,`dsh-tw-settings-list`),pe=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`应用语言(重启 TW)`);pe.type=`button`;let me=()=>{pe.disabled=a.languages===void 0};for(let e of c){let t=$(`input`,`dsh-tw-settings-check`);t.type=`checkbox`,t.checked=m().has(e.name),t.addEventListener(`change`,()=>{let n=m();t.checked?n.add(e.name):n.delete(e.name),a.languages=n,me()});let n=$(`label`,`dsh-tw-settings-row dsh-tw-settings-plugin`),r=$(`span`,`dsh-tw-settings-name`,e.label);r.title=e.name;let i=$(`span`,`dsh-tw-settings-muted`,e.description||e.name);n.append(t,r,i),fe.append(n)}pe.addEventListener(`click`,()=>{a.languages!==void 0&&(pe.disabled=!0,(async()=>{try{await ub(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({languages:[...m()]})}),a.languages=void 0,E(`语言已应用,TW 已重启`),i()}catch(e){E(`应用失败:${e instanceof Error?e.message:String(e)}`),me()}})())}),me(),ue.append(de,fe,pe),e.append(ue)}function hb(e,t,n){let r=$(`section`,`dsh-tw-settings-section`);r.append($(`h3`,`dsh-tw-settings-h`,`知识库位置(可切换)`));let i=$(`div`,`dsh-tw-settings-muted`,`读取中…`),a=$(`div`,`dsh-tw-settings-muted`),o=$(`div`,`dsh-tw-settings-muted`),s=$(`div`,`dsh-tw-settings-muted`),c=$(`input`,`dsh-tw-settings-input`),l=$(`input`,`dsh-tw-settings-input`);c.placeholder=`绝对路径,如 D:\\notes 或 $DSH_HOME/tiddlywiki`,l.placeholder=`文件夹名(默认 main;填 . 表示直接用上面这个目录)`;let u=$(`label`,`dsh-tw-settings-field`);u.append($(`span`,`dsh-tw-settings-label`,`根目录(wikiRoot)`),c);let d=$(`label`,`dsh-tw-settings-field`);d.append($(`span`,`dsh-tw-settings-label`,`文件夹名(wiki)`),l);let f=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`切换到这个位置`);f.type=`button`;let p=$(`button`,`dsh-tw-settings-btn`,`恢复为配置默认`);p.type=`button`;let m=$(`div`,`dsh-tw-settings-row`);m.append(f,p);let h=$(`div`,`dsh-tw-settings-row dsh-tw-settings-candidates`),g=$(`div`,`dsh-tw-settings-muted`,"切换会停掉并就地重启 TW 子进程(几秒);新目录若还没有 tiddlywiki.info,插件会自动 `--init server` 初始化一个全新知识库。选中的位置会记在 $DSH_HOME 下的指针文件里(不进 wiki),可用「恢复为配置默认」清除。"),_=(e,t)=>{f.disabled=e,p.disabled=e,f.textContent=e?t:`切换到这个位置`},v=async()=>{if(!t())try{let e=await ub(le);if(t())return;if(e.ok!==!0)throw Error(e.error??`获取失败`);let n=e.current??{};i.textContent=`当前:${n.path??`(未知)`}`;let r=n.source===`state`?`来源:指针文件(在设置页切换过)`:n.source===`config`?`来源:cordis 配置(config.wikiRoot / config.wiki)`:`来源:默认值($DSH_HOME/tiddlywiki + main)`;a.textContent=`${r} · 配置默认:${e.default?.path??`(未知)`}`,o.textContent=e.stateFile===void 0?``:`指针文件:${e.stateFile}(不存在=使用配置默认)`,s.textContent=e.error===void 0?``:`⚠️ ${e.error}`,c.value.length===0&&typeof n.root==`string`&&(c.value=n.root),l.value.length===0&&typeof n.name==`string`&&(l.value=n.name),h.replaceChildren();let u=e.candidates??[];if(u.length>0){h.append($(`span`,`dsh-tw-settings-label`,`同目录下可选的 wiki:`));for(let e of u){let t=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-chipbtn`,e===`.`?`(根目录本身)`:e);t.type=`button`,t.title=`填入文件夹名「${e}」`,t.addEventListener(`click`,()=>{l.value=e}),h.append(t)}}}catch(e){if(t())return;i.textContent=`读取位置失败:${e instanceof Error?e.message:String(e)}`}};f.addEventListener(`click`,()=>{let e=c.value.trim(),t=l.value.trim().length>0?l.value.trim():`main`;if(e.length===0){E(`请先填写根目录(绝对路径)`);return}window.confirm(`切换知识库到:\n${e}\\${t}\n\n会停止并重启 TW 子进程;当前对话/工具随后读写的是新知识库。确定继续?`)&&(_(!0,`切换中…(重启 TW)`),(async()=>{try{let r=await ub(ue,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({root:e,name:t}),signal:AbortSignal.timeout(12e4)});r.warning===void 0?E(`已切换到 ${r.path??``}`):E(`已切换到 ${r.path??``}(注意:${r.warning})`),be(),await v(),await n()}catch(e){E(`切换失败:${e instanceof Error?e.message:String(e)}`),await v()}finally{_(!1,``)}})())}),p.addEventListener(`click`,()=>{window.confirm(`恢复为配置默认位置?会删除位置指针文件,并(必要时)切回配置里的知识库。`)&&(_(!0,`切换中…(重启 TW)`),(async()=>{try{let e=await ub(de,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`,signal:AbortSignal.timeout(12e4)});E(e.warning===void 0?`已恢复为配置默认:${e.path??``}`:`已恢复默认(注意:${e.warning})`),be(),await v(),await n()}catch(e){E(`恢复失败:${e instanceof Error?e.message:String(e)}`),await v()}finally{_(!1,``)}})())}),r.append(i,a,o,u,d,m,h,s,g),e.append(r),v()}function gb(e,t){let n=$(`section`,`dsh-tw-settings-section`);n.append($(`h3`,`dsh-tw-settings-h`,`初始化(一次性预置)`));let r=$(`div`,`dsh-tw-settings-muted`,`这些是插件与 dsh 联动、需要在 wiki 里预置的 tiddler/配置。「发送给 Agent 按钮」和「TW 前端 API 基址」是功能必需项,启动时自动写入(只写缺失,不覆盖你的改动);其余为可选项,默认不自动写入、也不会强绑定——需要时点「重新初始化」写入,不想要了可随时「反初始化」移除。`),i=$(`div`,`dsh-tw-settings-list`),a=$(`div`,`dsh-tw-settings-muted`),o=async()=>{if(!t())try{let e=await ub(oe);if(t())return;if(e.ok!==!0||!Array.isArray(e.items))throw Error(e.error??`获取失败`);i.replaceChildren();let n=0,r=0;for(let t of e.items){t.present&&(n+=1),t.removable&&(r+=1);let e=$(`span`,`dsh-tw-settings-chip`,t.present?`✓`:`✗`);e.dataset.state=t.present?`ok`:`missing`,e.title=t.present?`已存在`:`缺失`;let a=$(`span`,`dsh-tw-settings-name`,t.title);a.title=t.id;let s=$(`span`,`dsh-tw-settings-muted`,t.detail??t.description),c=t.updateAvailable===!0?$(`span`,`dsh-tw-settings-chip`,`⬆ 有更新`):void 0;c!==void 0&&(c.dataset.state=`update`,c.title=`内置内容在本 wiki 预置之后更新过,可点「重新初始化」取用`);let l=t.userModified===!0?$(`span`,`dsh-tw-settings-chip`,`✏️ 本地已修改`):void 0;l!==void 0&&(l.dataset.state=`missing`,l.title=`这篇是你的内容:重新初始化会覆盖它`);let u=$(`button`,`dsh-tw-settings-btn`,t.updateAvailable===!0?`更新到内置版本`:`重新初始化`);u.type=`button`,u.title=`强制重写「${t.title}」的内置内容(会覆盖当前 tiddler)`,u.addEventListener(`click`,()=>{if(t.updateAvailable===!0){let e=t.userModified===!0?`「${t.title}」有你的本地修改,更新会覆盖它。`:t.userModified===void 0?`无法确认「${t.title}」是否被你编辑过(旧格式标记),更新可能覆盖你的改动。`:``;if(!window.confirm(`${e}${e.length>0?`
774
774
 
775
775
  `:``}用内置版本覆盖?`))return}u.disabled=!0,u.textContent=`执行中…`,(async()=>{try{let e=await fetch(se,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t.id,force:!0}),signal:AbortSignal.timeout(3e4)}),n=await e.json().catch(()=>null);!e.ok||n?.ok!==!0?E(`重新初始化失败:${n?.error??n?.results?.[0]?.error??`HTTP ${e.status}`}`):E(`已重新初始化「${t.title}」`),o()}catch(e){E(`重新初始化失败:${e instanceof Error?e.message:String(e)}`)}finally{u.disabled=!1,u.textContent=t.updateAvailable===!0?`更新到内置版本`:`重新初始化`}})()});let d=$(`div`,`dsh-tw-settings-row dsh-tw-settings-plugin`);if(d.append(e,a),c!==void 0&&d.append(c),l!==void 0&&d.append(l),d.append(s,u),t.removable){let e=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-danger`,`反初始化`);e.type=`button`,e.title=`移除「${t.title}」写入的 tiddler 与 marker(恢复未初始化状态)`,e.addEventListener(`click`,()=>{window.confirm(`确定反初始化「${t.title}」?将删除它写入的 tiddler(含其一次性 marker),需要时可用「重新初始化」恢复。`)&&(e.disabled=!0,e.textContent=`移除中…`,(async()=>{try{let e=await fetch(ce,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t.id}),signal:AbortSignal.timeout(3e4)}),n=await e.json().catch(()=>null);!e.ok||n?.ok!==!0?E(`反初始化失败:${n?.error??n?.results?.[0]?.error??`HTTP ${e.status}`}`):E(`已反初始化「${t.title}」`),o()}catch(e){E(`反初始化失败:${e instanceof Error?e.message:String(e)}`)}finally{e.disabled=!1,e.textContent=`反初始化`}})())}),d.append(e)}i.append(d)}a.textContent=`共 ${e.items.length} 项,${n} 项已就绪;可移除 ${r} 项`}catch(e){if(t())return;a.textContent=`加载初始化状态失败:${e instanceof Error?e.message:String(e)}`}},s=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-primary`,`全部重新初始化`);s.type=`button`,s.title=`强制重写所有一次性预置内容(含可选 seed,会覆盖当前 tiddler/配置)`,s.addEventListener(`click`,()=>{s.disabled=!0,s.textContent=`执行中…`,(async()=>{try{let e=await fetch(se,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({force:!0}),signal:AbortSignal.timeout(6e4)}),t=await e.json().catch(()=>null);!e.ok||t?.ok!==!0?E(`重新初始化失败:${t?.error??`HTTP ${e.status}`}`):E(`全部已重新初始化`),o()}catch(e){E(`重新初始化失败:${e instanceof Error?e.message:String(e)}`)}finally{s.disabled=!1,s.textContent=`全部重新初始化`}})()});let c=$(`button`,`dsh-tw-settings-btn dsh-tw-settings-danger`,`全部反初始化`);c.type=`button`,c.title=`移除所有可选 seed 写入的 tiddler 与 marker(功能必需项保留)`,c.addEventListener(`click`,()=>{window.confirm(`确定全部反初始化?将删除所有可选 seed 写入的 tiddler(含一次性 marker)。功能必需项(发送给 Agent 按钮 / TW 前端 API 基址)会保留。`)&&(c.disabled=!0,c.textContent=`移除中…`,(async()=>{try{let e=await fetch(ce,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({}),signal:AbortSignal.timeout(6e4)}),t=await e.json().catch(()=>null);!e.ok||t?.ok!==!0?E(`反初始化失败:${t?.error??`HTTP ${e.status}`}`):E(`全部可选 seed 已反初始化`),o()}catch(e){E(`反初始化失败:${e instanceof Error?e.message:String(e)}`)}finally{c.disabled=!1,c.textContent=`全部反初始化`}})())}),n.append(r,a,i,s,c),e.append(n),o()}function _b(e,t,n,r,i,a){e.replaceChildren(),typeof t.configError==`string`&&t.configError.length>0&&e.append(lb(`⚠️ 配置未生效:${t.configError}`));let o=JSON.stringify(t.config??{}),s=i.host!==void 0&&i.signature!==o,c=i.isDirty?.()===!0;if(s&&c&&e.append(lb(`⚠️ 服务器上的配置在别处被改动过(另一个标签页保存 / 语言管理等),当前表单仍是旧值:直接点「保存配置」会以本页内容覆盖那些改动。`)),i.host===void 0||s&&!c){let e=$(`div`,`dsh-tw-settings-confighost`);pb(e,t.config??{},n,i),i.host=e,i.signature=o}e.append(i.host),hb(e,r,n),mb(e,t.info,t.catalog,t.runtimePlugins,n,a),gb(e,r)}function vb(){let e=c.useRef(null);return c.useEffect(()=>{let t=e.current;return t===null?void 0:db(t)},[]),c.createElement(`div`,{ref:e})}const yb={tiddlywiki_get:`读取笔记`,tiddlywiki_search:`检索笔记`,tiddlywiki_recent:`最近修改`,tiddlywiki_list_tags:`标签列表`,tiddlywiki_put:`写入笔记`,tiddlywiki_batch_put:`批量写入`,tiddlywiki_append:`增量写入`,tiddlywiki_rename:`重命名笔记`,tiddlywiki_delete:`删除笔记`,tiddlywiki_trash:`回收站`,tiddlywiki_backlinks:`反向链接`,tiddlywiki_attach:`保存附件`,tiddlywiki_lint:`知识库体检`,tiddlywiki_git_sync:`git 同步`,tiddlywiki_git_resolve:`git 冲突解决`};function bb(e){return typeof e==`object`&&!!e&&e.kind===`tool-result`}function xb(e){if(typeof e!=`object`||!e)return null;let t=e;if(typeof t.call==`object`&&t.call!==null){let e=t.call;if(typeof e.name==`string`&&typeof e.argsRaw==`string`)return e}let n=e;return typeof n.name==`string`&&typeof n.argsRaw==`string`?{name:n.name,argsRaw:n.argsRaw}:null}function Sb(e){try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:{}}catch{return{}}}function Cb(e){return Array.isArray(e)?e.filter(e=>typeof e?.text==`string`).map(e=>e.text).join(`
776
776
  `):``}function wb(e){return typeof e==`string`?e:``}async function Tb(e){try{let t=await fetch(e,{signal:AbortSignal.timeout(1e4)});if(t.status===404){let e=await t.json().catch(()=>null);return typeof e==`object`&&e?e:{notFound:!0}}if(!t.ok)return null;let n=await t.json();return typeof n==`object`&&n?n:null}catch{return null}}async function Eb(e){return ib(e,1e4)}function Db(e,t){let[n,r]=c.useState({loading:!0,data:null});return c.useEffect(()=>{let t=!0;return r({loading:!0,data:null}),Promise.resolve(e()).then(e=>{t&&r({loading:!1,data:e})},()=>{t&&r({loading:!1,data:null})}),()=>{t=!1}},t),n}function Ob(e){return t=>{t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||(t.preventDefault(),t.stopPropagation(),ht(e))}}function kb(e){let t=yb[e.toolName]??e.toolName,n=c.createElement(`div`,{className:`dsh-tw-toolcard-head`},c.createElement(`span`,{className:`dsh-tw-toolcard-badge`},t),e.title!==void 0&&e.title.length>0?c.createElement(`span`,{className:`dsh-tw-toolcard-title`,title:e.title},e.title):null,e.onOpen===void 0?null:c.createElement(`button`,{type:`button`,className:`dsh-tw-toolcard-open`,onClick:e.onOpen},`在 TW 打开`)),r=e.subtitle!==void 0||e.tags!==void 0&&e.tags.length>0?c.createElement(`div`,{className:`dsh-tw-toolcard-meta`},e.subtitle===void 0?null:c.createElement(`span`,{className:`dsh-tw-toolcard-sub`},e.subtitle),e.tags!==void 0&&e.tags.length>0?c.createElement(`span`,{className:`dsh-tw-toolcard-tags`},...e.tags.map((e,t)=>c.createElement(`span`,{className:`dsh-tw-toolcard-tag`,key:`${t}-${e}`},e))):null):null;return c.createElement(`div`,{className:`dsh-tw-toolcard`},n,r,c.createElement(`div`,{className:`dsh-tw-toolcard-body`},e.children),e.foot!==void 0&&e.foot!==null?c.createElement(`div`,{className:`dsh-tw-toolcard-foot`},e.foot):null)}const Ab=new Map;function jb(e){let t=Ab.get(e);if(t!==void 0){if(Date.now()-t.at>3e5){Ab.delete(e);return}return Ab.delete(e),Ab.set(e,t),t}}function Mb(e,t){for(Ab.delete(e),Ab.set(e,{at:Date.now(),...t});Ab.size>50;){let e=Ab.keys().next().value;if(e===void 0)break;Ab.delete(e)}}function Nb(e){e.length>0&&Ab.delete(e)}function Pb(e){let t=e.join(`\0`);c.useEffect(()=>{for(let e of t.split(`\0`))Nb(e)},[t])}function Fb(e){let{title:t,fresh:n}=e,{loading:r,data:i}=Db(async()=>{n===!0&&Nb(t);let e=jb(t);if(e!==void 0)return{get:e.get,html:e.html};let[r,i]=await Promise.all([Tb(`${g}?title=${encodeURIComponent(t)}`),Eb(t)]);return typeof i==`string`&&i.length>0&&Mb(t,{get:r,html:i}),{get:r,html:i}},[t,n]),a=i?.get??null,o=i?.html??null,s;s=r?c.createElement(`div`,{className:`dsh-tw-toolcard-loading`},`渲染中…`):a!==null&&a.notFound===!0?c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`tiddler「${t}」不存在`):typeof o==`string`&&o.length>0?c.createElement(`div`,{className:`dsh-tw-toolcard-native`,dangerouslySetInnerHTML:{__html:o}}):a!==null&&typeof a.text==`string`&&a.text.length>0?c.createElement(`pre`,{className:`dsh-tw-toolcard-fallback`},a.text):c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`wiki 服务不可用`);let l=Array.isArray(a?.tags)?a.tags.filter(e=>typeof e==`string`):[],u=typeof a?.modified==`string`?a.modified:void 0;return c.createElement(kb,{toolName:e.toolName,title:t,subtitle:e.subtitle,tags:l,onOpen:Ob(t),foot:u===void 0?void 0:`修改于 ${u}`},s)}function Ib(e){let t=c.createElement(`span`,{className:`dsh-tw-toolcard-row-head`},c.createElement(`span`,{className:`dsh-tw-toolcard-row-title`},e.title),e.tags!==void 0&&e.tags.length>0?c.createElement(`span`,{className:`dsh-tw-toolcard-row-tags`},e.tags.slice(0,4).join(` · `)):null,typeof e.modified==`string`&&e.modified.length>0?c.createElement(`span`,{className:`dsh-tw-toolcard-row-meta`},e.modified):null),n=typeof e.snippet==`string`&&e.snippet.trim().length>0?e.snippet:null;return c.createElement(`a`,{className:`dsh-tw-toolcard-row`,href:`${m}#${encodeURIComponent(e.title)}`,onClick:Ob(e.title),title:n===null?e.title:`${e.title}\n${n}`},t,n===null?null:c.createElement(`span`,{className:`dsh-tw-toolcard-row-snippet`},n))}function Lb(e){let t=e.rows.slice(0,60),n;return n=t.length===0?c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},e.fallbackText):c.createElement(`div`,{className:`dsh-tw-toolcard-list`},...t.map((e,t)=>c.createElement(Ib,{key:`${e.title}-${t}`,...e}))),c.createElement(kb,{toolName:e.toolName,title:e.title,subtitle:e.subtitle},n)}function Rb(e){let t=/工作区\s+(ws\/[^\s((]+)/.exec(e);if(t===null||t[1]===void 0)return null;let n=t[1].slice(3);return n.length>0?n:null}function zb(e){let t=wb(e.args.query),n=new URLSearchParams;if(t.length>0&&n.set(`query`,t),Array.isArray(e.args.tags))for(let t of e.args.tags)typeof t==`string`&&t.length>0&&n.append(`tags`,t);typeof e.args.tag==`string`&&e.args.tag.length>0&&n.set(`tag`,e.args.tag),typeof e.args.since==`string`&&e.args.since.length>0&&n.set(`since`,e.args.since),typeof e.args.type==`string`&&e.args.type.length>0&&n.set(`type`,e.args.type),typeof e.args.field==`string`&&e.args.field.length>0&&n.set(`field`,e.args.field),typeof e.args.value==`string`&&e.args.value.length>0&&n.set(`value`,e.args.value),typeof e.args.limit==`number`&&n.set(`limit`,String(e.args.limit));let r=Rb(e.text);r!==null&&n.set(`workspace`,r);let i=n.toString(),a=Db(()=>Tb(`${S}?${i}`),[i]).data,o=(Array.isArray(a?.items)?a.items:[]).map(e=>({title:wb(e.title),tags:Array.isArray(e.tags)?e.tags.filter(e=>typeof e==`string`):[],modified:typeof e.modified==`string`?e.modified:null,snippet:typeof e.snippet==`string`?e.snippet:``})),s=typeof a?.total==`number`?a.total:void 0,l=typeof a?.workspace==`string`&&a.workspace.length>0?a.workspace:null,u=``;l!==null&&a?.scope===`workspace`?u=` · 已在工作区 ws/${l} 内缩小范围`:l!==null&&a?.fellBack===!0&&(u=` · 工作区 ws/${l} 内 0 条,已扩大到全库`);let d=`关键词「${t||`(全部)`}」${s===void 0?``:` · 共 ${s} 条`}${u}`;return c.createElement(Lb,{toolName:e.toolName,title:t.length>0?t:`检索`,subtitle:d,rows:o,fallbackText:`没有匹配的笔记`})}function Bb(e){let t=e.title.length>0?c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`附件已保存进 wiki(二进制条目,卡片不内联渲染)。`):c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`附件已保存。`);return c.createElement(kb,{toolName:e.toolName,title:e.title.length>0?e.title:void 0,...e.title.length>0?{onOpen:Ob(e.title)}:{}},t)}function Vb(e){let t=new URLSearchParams;typeof e.args.limit==`number`&&t.set(`limit`,String(e.args.limit)),typeof e.args.since==`string`&&e.args.since.length>0&&t.set(`since`,e.args.since);let n=t.toString(),r=Db(()=>Tb(`${x}?${n}`),[n]).data,i=(Array.isArray(r?.items)?r.items:[]).map(e=>({title:wb(e.title),tags:Array.isArray(e.tags)?e.tags.filter(e=>typeof e==`string`):[],modified:typeof e.modified==`string`?e.modified:null,snippet:typeof e.snippet==`string`?e.snippet:``}));return c.createElement(Lb,{toolName:e.toolName,title:`最近修改`,subtitle:i.length>0?`最近 ${i.length} 条`:``,rows:i,fallbackText:`暂无笔记`})}function Hb(e){let t=(Array.isArray(e.args.items)?e.args.items:[]).map(e=>typeof e==`object`&&e&&typeof e.title==`string`?wb(e.title):null).filter(e=>e!==null&&e.length>0).map(e=>({title:e}));return Pb(t.map(e=>e.title)),c.createElement(Lb,{toolName:e.toolName,title:`批量写入`,subtitle:t.length>0?`写入 ${t.length} 篇`:`(参数中没有可解析的 items)`,rows:t,fallbackText:`没有可展示的笔记`})}function Ub(e){let t=Db(()=>Tb(`${b}?limit=60&sort=count`),[]).data,n=(Array.isArray(t?.items)?t.items:[]).map(e=>({tag:wb(e.tag),count:typeof e.count==`number`?e.count:0})),r=n.slice(0,60),i=typeof t?.total==`number`?t.total:n.length,a;return a=n.length===0?c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`暂无标签`):c.createElement(`div`,{className:`dsh-tw-toolcard-tags-wrap`},...r.map(e=>c.createElement(`span`,{className:`dsh-tw-toolcard-tag`,key:e.tag},`${e.tag} · ${e.count}`)),...i>r.length?[c.createElement(`span`,{className:`dsh-tw-toolcard-tag-more`,key:`__more`},`…另有 ${i-r.length} 个`)]:[]),c.createElement(kb,{toolName:e.toolName,title:`标签`,subtitle:`共 ${i} 个`},a)}function Wb(e){let t=e.text.trim().length>0?c.createElement(`pre`,{className:`dsh-tw-toolcard-fallback`},e.text):c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`(无结果)`);return c.createElement(kb,{toolName:e.toolName},t)}function Gb(e){Pb([e.title]);let t=e.title.length>0?c.createElement(`div`,{className:`dsh-tw-toolcard-empty`},`已删除 tiddler「${e.title}」`):c.createElement(`pre`,{className:`dsh-tw-toolcard-fallback`},e.text||`(已删除)`);return c.createElement(kb,{toolName:e.toolName,title:e.title.length>0?e.title:void 0},t)}function Kb(e,t){switch(e){case`tiddlywiki_get`:case`tiddlywiki_put`:case`tiddlywiki_append`:case`tiddlywiki_delete`:case`tiddlywiki_attach`:case`tiddlywiki_backlinks`:return wb(t.title);case`tiddlywiki_rename`:return wb(t.newTitle);case`tiddlywiki_search`:return wb(t.query);default:return``}}function qb(e){let t=e.block,n=e.toolName,r=bb(t),i=xb(t),a=n!==void 0&&n.length>0?n:i?.name??``,o=Sb(i?.argsRaw??``),s=r?Cb(t.content):``;if(i===null)return c.createElement(kb,{toolName:a},c.createElement(`pre`,{className:`dsh-tw-toolcard-fallback`},s||`(无调用信息)`));if(!r)return c.createElement(kb,{toolName:a,title:Kb(a,o)},c.createElement(`div`,{className:`dsh-tw-toolcard-pending`},`处理中…`));if(t.isError===!0)return c.createElement(kb,{toolName:a,title:Kb(a,o)},c.createElement(`div`,{className:`dsh-tw-toolcard-error`},s||`工具调用失败`));switch(a){case`tiddlywiki_get`:return c.createElement(Fb,{toolName:a,title:wb(o.title),subtitle:`读取`});case`tiddlywiki_put`:return c.createElement(Fb,{toolName:a,title:wb(o.title),subtitle:`已写入`,fresh:!0});case`tiddlywiki_append`:return c.createElement(Fb,{toolName:a,title:wb(o.title),subtitle:`已增量写入`,fresh:!0});case`tiddlywiki_rename`:return c.createElement(Fb,{toolName:a,title:wb(o.newTitle),subtitle:`已重命名「${wb(o.oldTitle)}」→`,fresh:!0});case`tiddlywiki_delete`:return c.createElement(Gb,{toolName:a,title:wb(o.title),text:s});case`tiddlywiki_attach`:return c.createElement(Bb,{toolName:a,title:wb(o.title)});case`tiddlywiki_batch_put`:return c.createElement(Hb,{toolName:a,args:o});case`tiddlywiki_search`:return c.createElement(zb,{toolName:a,args:o,text:s});case`tiddlywiki_recent`:return c.createElement(Vb,{toolName:a,args:o});case`tiddlywiki_list_tags`:return c.createElement(Ub,{toolName:a});case`tiddlywiki_git_sync`:case`tiddlywiki_git_resolve`:return c.createElement(Wb,{toolName:a,text:s});default:return c.createElement(kb,{toolName:a,title:Kb(a,o)},c.createElement(`pre`,{className:`dsh-tw-toolcard-fallback`},s||`(完成)`))}}const Jb=[`tiddlywiki_get`,`tiddlywiki_search`,`tiddlywiki_recent`,`tiddlywiki_list_tags`,`tiddlywiki_put`,`tiddlywiki_batch_put`,`tiddlywiki_append`,`tiddlywiki_rename`,`tiddlywiki_delete`,`tiddlywiki_trash`,`tiddlywiki_backlinks`,`tiddlywiki_attach`,`tiddlywiki_lint`,`tiddlywiki_git_sync`,`tiddlywiki_git_resolve`];function Yb(e){let t=[];for(let n of Jb)try{let r=e.inject(`tool.call.toolview`,()=>e.register({name:`tool.call.toolview`,id:`dsh-tiddlywiki-toolview-${n}`,key:n,order:20,label:`TiddlyWiki: ${n}`},qb));r!==void 0&&t.push(r)}catch(e){console.error(`[dsh-tiddlywiki] register toolview ${n} failed:`,e)}return t}function Xb(){let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`a`);if(n===null)return;let r=n.getAttribute(`href`)??``,i=null;try{let e=new URL(r,window.location.origin);e.origin===window.location.origin&&e.pathname===m&&e.hash.length>1&&(i=e.hash.substring(1))}catch{}if(i!==null){e.preventDefault(),e.stopPropagation();try{i=decodeURIComponent(i)}catch{}ht(i)}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)}const Zb=`dsh-tiddlywiki`,Qb=`dsh-tiddlywiki/rightbar`;function $b(e){let{useTabInfo:t}=e,n=t().tab,r=c.useRef(null),i=c.useRef(null);c.useEffect(()=>{let e=r.current;if(e===null)return;let t=st(e,n.signal);return i.current=t,()=>{t.dispose(),i.current=null}},[n.id,n.signal]),c.useEffect(()=>{i.current?.setVisible(n.visible)},[n.visible]);let a=n.visible,o=n.actions.close;return c.useEffect(()=>{if(!a)return;document.dispatchEvent(new CustomEvent(qe,{detail:Qb}));let e=e=>{e.detail!==Qb&&o()};return document.addEventListener(qe,e),()=>document.removeEventListener(qe,e)},[a,o]),c.createElement(`div`,{ref:r,className:`dsh-tw-rightbar-tab`})}function ex(){return{id:Zb,kind:`dsh-tiddlywiki`,title:()=>Ze(),guide:[{order:10,title:()=>`TiddlyWiki 知识库`,description:()=>`在右侧边栏打开 TiddlyWiki 编辑器(与聊天并排)`,icon:$e}]}}function tx(e,t){let n=[];try{n.push(e.register(ex()));let r=t.inject(`sidebar.right.pane.tab`,()=>t.register({name:`sidebar.right.pane.tab`,key:Zb},$b));r!==void 0&&n.push(r)}catch(e){for(let e of n.splice(0))e();console.error(`[dsh-tiddlywiki] rightbar tab mount failed:`,e);return}return at(),()=>{for(let e of n.splice(0))e()}}const nx=[`slots`];function rx(e){try{let t=[],n=!1,r=()=>{n=!0;for(let e of t.splice(0))e()},i=(e,t)=>{try{t()}catch(t){console.error(`[dsh-tiddlywiki] ${e} failed:`,t)}};i(`styles`,()=>t.push(d()));let a=new f,o,s;if(i(`quick-note widget`,()=>{o=Yy(),t.push(()=>o?.dispose())}),i(`sync controller`,()=>{s=$y(),t.push(()=>s?.dispose())}),i(`sidebar entry`,()=>t.push(Ee(a))),i(`center panel`,()=>t.push(vt(a))),o!==void 0&&s!==void 0){let e=o,n=s;i(`knowledge FAB`,()=>t.push(nb(a,e,n)))}i(`editor popup`,()=>t.push(kt)),e.slots!==void 0&&xe().then(r=>{if(n)return;let a=o;r.showQuickNoteDock&&a!==void 0&&i(`quick-note dock`,()=>{let n=e.slots?.inject(`conversation.input.dock`,()=>e.slots?.register({name:`conversation.input.dock`,id:`quick-note`,order:8,label:`快速笔记`},rb(a)));n!==void 0&&t.push(n)}),i(`session summary tab`,()=>{let n=cb(e.slots,r);n!==void 0&&t.push(n)})}).catch(e=>{console.error(`[dsh-tiddlywiki] ui config load failed:`,e)}),i(`rightbar mount`,()=>{let r,i=a=>{let o=e.get?.(`sidebarRightTabs`);if(o===void 0){a<6&&!n&&(r=window.setTimeout(()=>i(a+1),500*(a+1)));return}xe().then(r=>{if(n||!r.showRightbarTab)return;let i=tx(o,e.slots);i!==void 0&&t.push(i)}).catch(e=>{console.error(`[dsh-tiddlywiki] rightbar config load failed:`,e)})};t.push(()=>{r!==void 0&&window.clearTimeout(r)}),i(0)}),i(`tool views`,()=>{e.slots!==void 0&&t.push(...Yb(e.slots))}),i(`wiki link interceptor`,()=>t.push(Xb())),i(`settings section`,()=>{let n=e.slots?.inject(`settings.section`,()=>e.slots?.register({name:`settings.section`,id:`dsh-tiddlywiki`,order:50,label:`TiddlyWiki 知识库`},vb));n!==void 0&&t.push(n)}),e.effect===void 0?window.addEventListener(`pagehide`,r,{once:!0}):e.effect(()=>r,`dsh-tiddlywiki: client mount`)}catch(e){console.error(`[dsh-tiddlywiki] client half failed to start:`,e)}}exports.apply=rx,exports.inject=nx,exports.name=`dsh-tiddlywiki/client`;