@puddle-code/cli 0.4.1 → 0.4.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/CHANGELOG.md +15 -5
- package/README.md +2 -0
- package/dist/index.js +3 -2
- package/dist/public/assets/App-CbjV_eCr.js +19 -0
- package/dist/public/assets/{CompilationCommandForm-vv5bglnl.js → CompilationCommandForm-C71yC-_B.js} +1 -1
- package/dist/public/assets/Dashboard-CaVEQBQm.js +1 -0
- package/dist/public/assets/{EditorTabClose-D3LwFFHd.js → EditorTabClose-CHZNbZkD.js} +1 -1
- package/dist/public/assets/{FindWidget-CVH9U-_P.js → FindWidget-CaVwYvST.js} +1 -1
- package/dist/public/assets/LazyTerminal-BvZY-D0f.js +2 -0
- package/dist/public/assets/{ModelRefcount-DtJdNeW7.js → ModelRefcount-R_PJzn4E.js} +1 -1
- package/dist/public/assets/NewProjectDialog-B6wof57i.js +1 -0
- package/dist/public/assets/{NotebookWidget-BntkgqbM.js → NotebookWidget-D6vzMCnH.js} +1 -1
- package/dist/public/assets/PaneEditorBody-Bn8cmN5i.js +284 -0
- package/dist/public/assets/PdfViewer-C-dXDOjG.js +2 -0
- package/dist/public/assets/{ReleaseNotesDialog-D2kA6oIr.js → ReleaseNotesDialog-Z7jtCZYz.js} +1 -1
- package/dist/public/assets/SettingsDialog-lSPFdtsX.js +8 -0
- package/dist/public/assets/{Terminal-BQHSZc8Q.js → Terminal-C9fEeTMx.js} +3 -3
- package/dist/public/assets/Workspace-DleYwgSG.js +20 -0
- package/dist/public/assets/{buffer-store-BWLcD39y.js → buffer-store-DeLu2KS4.js} +1 -1
- package/dist/public/assets/button-q0ardkfx.js +1 -0
- package/dist/public/assets/{chevron-down--sjpQEHH.js → chevron-down-HQLVE6o5.js} +1 -1
- package/dist/public/assets/chevron-right-BP2NLwlG.js +1 -0
- package/dist/public/assets/code-Cf4ftdOa.js +1 -0
- package/dist/public/assets/command-BkdEYC1b.js +1 -0
- package/dist/public/assets/context-menu-C0cOAj0E.js +1 -0
- package/dist/public/assets/control-tray-D7OXXkAy.css +1 -0
- package/dist/public/assets/control-tray-OJfh0_ml.js +1 -0
- package/dist/public/assets/{copy-CGsu8426.js → copy-D0Theg4Q.js} +1 -1
- package/dist/public/assets/createLucideIcon-C9A1vLE-.js +1 -0
- package/dist/public/assets/dialog-IU2fjIs9.js +41 -0
- package/dist/public/assets/{dist-Cde1E3eV.js → dist-BHBQY7ao.js} +1 -1
- package/dist/public/assets/{dist-CBag2On7.js → dist-CGlwr6Pc.js} +1 -1
- package/dist/public/assets/dist-eLNGMhYC.js +1 -0
- package/dist/public/assets/index-C3TPFFMc.css +2 -0
- package/dist/public/assets/{index-BUAoYe1o.js → index-DK1twGI0.js} +2 -2
- package/dist/public/assets/{markdown-mermaid-BCXEEB98.js → markdown-mermaid-B648xTNp.js} +1 -1
- package/dist/public/assets/{media-refresh-store-BplHZVs4.js → media-refresh-store-CHPkX-XV.js} +1 -1
- package/dist/public/assets/notification-delivery-BlvH2Ojs.js +1 -0
- package/dist/public/assets/popover-B5Bw2ljC.js +1 -0
- package/dist/public/assets/{preview-kind-DiWpvEc0.js → preview-kind-CPkO-rSz.js} +1 -1
- package/dist/public/assets/{rotate-ccw-CNjR2LSi.js → rotate-ccw-BI2k_h3A.js} +1 -1
- package/dist/public/assets/{select-9OADuw7W.js → select-C0UTbo8D.js} +1 -1
- package/dist/public/assets/{selection-actions-B2XIuCoH.js → selection-actions-BLoNrxbO.js} +1 -1
- package/dist/public/assets/session-order-2oedrwDu.js +1 -0
- package/dist/public/assets/switch-DihTSmnc.js +1 -0
- package/dist/public/assets/{use-ui-state-i7N5-9dI.js → use-ui-state-e6mUjW-H.js} +1 -1
- package/dist/public/assets/{whole-word-2m2pmAFT.js → whole-word-BJjKpISQ.js} +1 -1
- package/dist/public/assets/x-Dq6POV20.js +1 -0
- package/dist/public/file-icons/material/LICENSE +8 -0
- package/dist/public/file-icons/material/SOURCE.txt +4 -0
- package/dist/public/file-icons/material/astro.svg +1 -0
- package/dist/public/file-icons/material/audio.svg +1 -0
- package/dist/public/file-icons/material/c.svg +1 -0
- package/dist/public/file-icons/material/console.svg +1 -0
- package/dist/public/file-icons/material/cpp.svg +1 -0
- package/dist/public/file-icons/material/csharp.svg +1 -0
- package/dist/public/file-icons/material/css.svg +1 -0
- package/dist/public/file-icons/material/dart.svg +1 -0
- package/dist/public/file-icons/material/database.svg +1 -0
- package/dist/public/file-icons/material/docker.svg +1 -0
- package/dist/public/file-icons/material/document.svg +1 -0
- package/dist/public/file-icons/material/eslint.svg +1 -0
- package/dist/public/file-icons/material/font.svg +1 -0
- package/dist/public/file-icons/material/git.svg +1 -0
- package/dist/public/file-icons/material/go-mod.svg +1 -0
- package/dist/public/file-icons/material/go.svg +1 -0
- package/dist/public/file-icons/material/h.svg +1 -0
- package/dist/public/file-icons/material/hpp.svg +1 -0
- package/dist/public/file-icons/material/html.svg +1 -0
- package/dist/public/file-icons/material/image.svg +1 -0
- package/dist/public/file-icons/material/java.svg +1 -0
- package/dist/public/file-icons/material/javascript.svg +1 -0
- package/dist/public/file-icons/material/json.svg +1 -0
- package/dist/public/file-icons/material/jupyter.svg +1 -0
- package/dist/public/file-icons/material/kotlin.svg +1 -0
- package/dist/public/file-icons/material/less.svg +1 -0
- package/dist/public/file-icons/material/license.svg +1 -0
- package/dist/public/file-icons/material/lock.svg +1 -0
- package/dist/public/file-icons/material/markdown.svg +1 -0
- package/dist/public/file-icons/material/npm.svg +1 -0
- package/dist/public/file-icons/material/pdf.svg +1 -0
- package/dist/public/file-icons/material/php.svg +1 -0
- package/dist/public/file-icons/material/pnpm.svg +1 -0
- package/dist/public/file-icons/material/prettier.svg +1 -0
- package/dist/public/file-icons/material/python.svg +1 -0
- package/dist/public/file-icons/material/react.svg +1 -0
- package/dist/public/file-icons/material/react_ts.svg +1 -0
- package/dist/public/file-icons/material/readme.svg +1 -0
- package/dist/public/file-icons/material/ruby.svg +1 -0
- package/dist/public/file-icons/material/rust.svg +1 -0
- package/dist/public/file-icons/material/sass.svg +1 -0
- package/dist/public/file-icons/material/settings.svg +1 -0
- package/dist/public/file-icons/material/svelte.svg +1 -0
- package/dist/public/file-icons/material/svg.svg +1 -0
- package/dist/public/file-icons/material/swift.svg +1 -0
- package/dist/public/file-icons/material/table.svg +1 -0
- package/dist/public/file-icons/material/toml.svg +1 -0
- package/dist/public/file-icons/material/tune.svg +1 -0
- package/dist/public/file-icons/material/typescript-def.svg +1 -0
- package/dist/public/file-icons/material/typescript.svg +1 -0
- package/dist/public/file-icons/material/video.svg +1 -0
- package/dist/public/file-icons/material/vite.svg +1 -0
- package/dist/public/file-icons/material/vitest.svg +1 -0
- package/dist/public/file-icons/material/vue.svg +1 -0
- package/dist/public/file-icons/material/xml.svg +1 -0
- package/dist/public/file-icons/material/yaml.svg +1 -0
- package/dist/public/file-icons/material/yarn.svg +1 -0
- package/dist/public/file-icons/material/zip.svg +1 -0
- package/dist/public/index.html +2 -2
- package/package.json +1 -1
- package/dist/public/assets/App-CB0Bm55u.js +0 -9
- package/dist/public/assets/Dashboard-BQd42kix.js +0 -1
- package/dist/public/assets/LazyTerminal-CfuC3bjp.js +0 -2
- package/dist/public/assets/NewProjectDialog-DYn30yon.js +0 -1
- package/dist/public/assets/PaneEditorBody-ChNwAz96.js +0 -284
- package/dist/public/assets/PdfViewer-DYmz05py.js +0 -2
- package/dist/public/assets/SettingsDialog-BWWWn7I0.js +0 -8
- package/dist/public/assets/Workspace-DVTqrQNf.js +0 -20
- package/dist/public/assets/button-9AVMLaMQ.js +0 -1
- package/dist/public/assets/chevron-right-BRjnLYaO.js +0 -1
- package/dist/public/assets/code-DRWf9a5s.js +0 -1
- package/dist/public/assets/command-BUOkDmUW.js +0 -1
- package/dist/public/assets/context-menu-D-5BvS0X.js +0 -1
- package/dist/public/assets/createLucideIcon-DyMAgLa3.js +0 -1
- package/dist/public/assets/dialog-BMWRC2HO.js +0 -41
- package/dist/public/assets/dist-CcLyf3-2.js +0 -1
- package/dist/public/assets/index--5A6_BeN.css +0 -2
- package/dist/public/assets/notification-delivery-CDWhS_kj.js +0 -1
- package/dist/public/assets/popover-CtxJVkPi.js +0 -1
- package/dist/public/assets/session-order-unCbOqgk.js +0 -1
- package/dist/public/assets/switch-DVo2TkMf.js +0 -1
- package/dist/public/assets/x-DCpy1q13.js +0 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NotebookWidget-D6vzMCnH.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/auth-olLlgxc3.js","assets/context-C3-WejyN.js","assets/protocol-support-CsLR9u7d.js","assets/jsx-runtime-By8HlURe.js","assets/api-BOuyloUi.js","assets/preload-helper-Czpn1I53.js","assets/index-DK1twGI0.js","assets/react-dom-cJyBB_A4.js","assets/client-settings-CwqpIric.js","assets/index-C3TPFFMc.css","assets/PdfViewer-C-dXDOjG.js","assets/dist-BOS6OKSE.js","assets/createLucideIcon-C9A1vLE-.js","assets/control-tray-OJfh0_ml.js","assets/control-tray-D7OXXkAy.css","assets/view-state-store-Cy9sQJoZ.js","assets/scroll-restoration-CwXbvZvT.js","assets/PdfViewer-Re37jQgv.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{R as n,St as r,Tt as i,_ as a,d as o,f as s,p as c,u as l}from"./protocol-support-CsLR9u7d.js";import{at as u,ct as d,it as f,k as p,lt as m,nt as h,o as g,ot as _,rt as v,st as y,tt as b}from"./auth-olLlgxc3.js";import{n as x,t as S}from"./context-C3-WejyN.js";import{i as C,r as w,t as ee}from"./client-settings-CwqpIric.js";import{t as T}from"./jsx-runtime-By8HlURe.js";import{t as E}from"./preload-helper-Czpn1I53.js";import{a as D,r as O}from"./index-DK1twGI0.js";import{t as k}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{a as A,c as j,h as te,i as M,p as N,r as P}from"./editor.api2-4X9Vh9Zw.js";import{n as F,r as ne,t as re}from"./api-BOuyloUi.js";import{c as ie,g as ae,p as oe}from"./hotkeys-Cu0t6sbz.js";import{B as se,C as ce,E as le,J as ue,K as de,O as fe,P as pe,R as me,T as he,U as ge,W as _e,X as ve,Y as ye,Z as be,_ as xe,a as Se,at as Ce,d as we,i as Te,it as Ee,j as De,k as Oe,m as ke,n as Ae,nt as je,ot as Me,r as Ne,rt as Pe,st as Fe,u as Ie,v as Le,w as Re}from"./media-refresh-store-CHPkX-XV.js";import{n as ze}from"./dist-BOS6OKSE.js";import{t as Be}from"./x-Dq6POV20.js";import{n as Ve,t as He}from"./chevron-right-BP2NLwlG.js";import{n as Ue,r as We}from"./dist-BHBQY7ao.js";import{t as Ge}from"./createLucideIcon-C9A1vLE-.js";import{a as Ke,i as qe,n as Je,o as Ye,r as Xe,t as Ze}from"./select-C0UTbo8D.js";import{t as Qe}from"./chevron-down-HQLVE6o5.js";import{a as $e,n as et,o as tt,r as nt,t as rt}from"./FindWidget-CaVwYvST.js";import{t as it}from"./copy-D0Theg4Q.js";import{t as at}from"./rotate-ccw-BI2k_h3A.js";import{a as ot,i as st,n as ct,o as lt,r as ut,t as dt}from"./preview-kind-CPkO-rSz.js";import{t as ft}from"./control-tray-OJfh0_ml.js";import{a as pt,o as mt,r as ht,s as gt,t as _t}from"./command-BkdEYC1b.js";import{n as vt,r as yt,t as bt}from"./popover-B5Bw2ljC.js";import{i as xt,n as St,r as Ct}from"./markdown-it-CWoG9_Dn.js";import{t as wt}from"./debounce-B9DrqirV.js";import{a as Tt,c as Et,d as Dt,f as Ot,i as kt,l as At,o as jt,p as Mt,r as Nt,s as Pt,t as Ft,u as It}from"./buffer-store-DeLu2KS4.js";import{r as Lt,t as Rt}from"./view-state-store-Cy9sQJoZ.js";import{a as zt,c as Bt,i as Vt,n as Ht,o as Ut,r as Wt,s as Gt,t as Kt}from"./markdown-CMSzQtLp.js";import{i as qt,n as Jt,r as Yt,t as Xt}from"./drafts-B_tChlzR.js";import{r as Zt}from"./buffer-logic-BAkSBQT7.js";import{a as Qt,i as $t,n as en,o as tn,r as nn}from"./editor-sync-W1bamxAP.js";import{r as rn,t as an}from"./math-CSw6sgCC.js";import{n as on}from"./math-delimiters-BCnTi7Ii.js";import{n as sn}from"./markdown-mermaid-B648xTNp.js";var cn=Ge(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),ln=Ge(`arrow-up-to-line`,[[`path`,{d:`M5 3h14`,key:`7usisc`}],[`path`,{d:`m18 13-6-6-6 6`,key:`1kf1n9`}],[`path`,{d:`M12 7v14`,key:`1akyts`}]]),un=Ge(`combine`,[[`path`,{d:`M14 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`1l7d7l`}],[`path`,{d:`M19 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`9955pe`}],[`path`,{d:`m7 15 3 3`,key:`4hkfgk`}],[`path`,{d:`m7 21 3-3H5a2 2 0 0 1-2-2v-2`,key:`1xljwe`}],[`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1cdgtw`}],[`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`,key:`zi3rio`}]]),dn=Ge(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),fn=Ge(`list-tree`,[[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`M3 10a2 2 0 0 0 2 2h3`,key:`1npucw`}],[`path`,{d:`M3 5v12a2 2 0 0 0 2 2h3`,key:`x1gjn2`}]]),I=e(t(),1),L=T();String.prototype.codePointAt;function pn(e,t){return function(n){let r,i=0,a=``;for(;r=e.exec(n);)i!==r.index&&(a+=n.substring(i,r.index)),a+=t.get(r[0].charCodeAt(0)),i=r.index+1;return a+n.substring(i)}}var mn=pn(/["&\u00A0]/g,new Map([[34,`"`],[38,`&`],[160,` `]])),hn=pn(/[&<>\u00A0]/g,new Map([[38,`&`],[60,`<`],[62,`>`],[160,` `]])),gn=new Map,_n=new Map,vn=1;function yn(e){for(let t of _n.get(e)??[])t()}function bn(e,t){gn.set(e,t),yn(e)}function xn(e){let t={phase:`unresolved`,revision:vn++};return bn(e,t),t}function Sn(e){let t=gn.get(e);return!t||t.phase!==`unresolved`&&t.phase!==`load-error`?null:(bn(e,{phase:`loading`,revision:t.revision}),t.revision)}function Cn(e,t,n,r){let i=gn.get(e);return!i||i.phase!==`loading`||i.revision!==t?!1:(bn(e,{phase:`opening`,revision:t,content:n,mtimeMs:r}),!0)}function wn(e,t){let n=gn.get(e);return!n||n.phase!==`opening`||n.revision!==t?!1:(bn(e,{...n,phase:`comparing`}),!0)}function Tn(e,t,n){let r=gn.get(e);return!r||r.phase!==`loading`||r.revision!==t?!1:(bn(e,{phase:`load-error`,revision:t,message:n}),!0)}function En(e,t){return t&&e?.phase===`unresolved`}function Dn(e){return e?.phase===`comparing`?e.mtimeMs:void 0}function On(e){return e?.phase===`loading`||e?.phase===`load-error`||e?.phase===`opening`}function kn(e){return e.phase===`opening`||e.phase===`comparing`}function An(e){gn.delete(e)&&yn(e)}function jn(e){return gn.get(e)??null}function Mn(e,t){let n=_n.get(e);return n||(n=new Set,_n.set(e,n)),n.add(t),()=>n.delete(t)}function Nn(e){return{tabSize:e,insertSpaces:!0,detectIndentation:!1}}var Pn=new Rt,Fn=new Rt;function In(e){let t={...e.contributionsState};return delete t[`editor.contrib.wordHighlighter`],{...e,contributionsState:t}}function Ln(e,t){let n=(0,I.useRef)(null),r=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>(n.current&&(r.current=t(n.current,e)),()=>{r.current?.(),r.current=null}),[e,t]),(0,I.useCallback)(i=>{r.current?.(),n.current=i,i.onDidDispose(()=>{n.current===i&&(n.current=null)}),r.current=t(i,e)},[e,t])}function Rn(e,t){let n=Pn.get(t);n&&e.restoreViewState(n);let r=()=>{if(!e.getModel())return;let n=e.saveViewState();n&&Pn.set(t,In(n))},i=[e.onDidScrollChange(r),e.onDidChangeCursorSelection(r)];return()=>{r(),i.forEach(e=>e.dispose())}}function zn(e,t){let n=Fn.get(t),r=n!==void 0,i=()=>{if(r||!e.getModel())return;let n=e.saveViewState();n&&Fn.set(t,{...n,original:n.original&&In(n.original),modified:n.modified&&In(n.modified)})};n&&e.restoreViewState(n);let a=[e.onDidUpdateDiff(()=>{r&&(r=!1,n&&e.restoreViewState(n))}),...[e.getOriginalEditor(),e.getModifiedEditor()].flatMap(e=>[e.onDidScrollChange(i),e.onDidChangeCursorSelection(i)])];return()=>{i(),a.forEach(e=>e.dispose())}}function Bn(e){return Ln(Lt(`code`,e),Rn)}function Vn(e){return Ln(Lt(`diff`,e),zn)}function Hn({session:e,path:t,conflict:n,model:r,onTakeDisk:i,onKeepMine:a,onSave:o,onReady:s}){let c=C(),l=Vn([`conflict`,r.uri.toString()]),u=(0,I.useId)(),d=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),f=(0,I.useRef)(o);f.current=o;let p=(0,I.useRef)(null),m=()=>{let e=p.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),p.current=null},h=(0,I.useRef)(m);return h.current=m,(0,I.useEffect)(()=>()=>h.current(),[]),(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsx)(`span`,{children:`This file changed on disk. Yours is on the right — merge what you want, then save.`}),(0,L.jsx)(`button`,{type:`button`,onClick:i,className:`ml-auto shrink-0 text-fg-muted transition-colors hover:text-fg`,children:`Take the disk version`}),(0,L.jsx)(`button`,{type:`button`,onClick:a,disabled:n.phase!==`comparing`,className:`shrink-0 text-fg-muted transition-colors hover:text-fg`,children:`Keep mine`})]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Mt,{modifiedModelPath:r.uri.toString(),originalModelPath:`puddle-disk://${encodeURIComponent(e)}/${n.mtimeMs}/${encodeURIComponent(u)}/${t.split(`/`).map(encodeURIComponent).join(`/`)}`,original:n.content,language:r.getLanguageId(),theme:Dt,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:e=>{l(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(M.CtrlCmd|P.KeyS,()=>f.current()),s?.(n.revision)},options:{readOnly:n.phase!==`comparing`,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...Nn(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function Un({session:e,path:t,buffer:n,focused:r}){let i=n.conflict;return!i||i.phase===`unresolved`?null:kn(i)&&n.model?(0,L.jsx)(Hn,{session:e,path:t,conflict:i,model:n.model,onTakeDisk:n.takeDisk,onKeepMine:n.keepMine,onSave:n.save,onReady:r?n.comparisonReady:void 0}):i.phase===`load-error`?(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground px-4 text-center text-sm text-fg-muted`,children:[(0,L.jsx)(`span`,{children:`The disk version could not be loaded.`}),(0,L.jsx)(`span`,{className:`max-w-lg text-xs text-fg-secondary`,children:i.message}),(0,L.jsx)(`button`,{type:`button`,onClick:n.compare,className:`rounded-md bg-elevated px-3 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-border hover:text-fg`,children:`Retry compare`})]}):(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:`Loading the disk version…`})}function Wn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Gn(e,t,n){return Wn(e/Math.max(1,t-n))}function Kn(e,t,n){return Wn(e)*Math.max(0,t-n)}function qn(e,t){return JSON.stringify([e,t.session,t.root??null,t.path])}var Jn=new class{positions=new Map;listeners=new Map;revision=0;publish(e,t,n,r=null){let i={ratio:Wn(n),sourceLine:r!==null&&Number.isFinite(r)?Math.max(1,r):null,revision:++this.revision},a=qn(e,t);this.positions.set(a,i);for(let e of this.listeners.get(a)??[])e(i);return i}get(e,t){return this.positions.get(qn(e,t))}subscribe(e,t,n){let r=qn(e,t),i=this.listeners.get(r);i||(i=new Set,this.listeners.set(r,i)),i.add(n);let a=this.positions.get(r);return a&&n(a),()=>{i?.delete(n),i?.size===0&&this.listeners.delete(r)}}},Yn=new Rt;function Xn(e){let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},dispose:()=>{t!==null&&cancelAnimationFrame(t),t=null}}}function Zn(e,t,n,r){let i=Math.max(0,t-n);if(e.ratio<=0)return 0;if(e.ratio>=1)return i;if(e.sourceLine!==null&&r){let t=Gt(r,e.sourceLine);if(t!==null)return Math.min(i,Math.max(0,t))}return Kn(e.ratio,t,n)}function Qn(e,t){if(t.driver&&t.receiver)throw Error(`a preview scroll surface cannot be both driver and receiver`);let n=t.store??Jn,r=t.viewKey?Yn.get(t.viewKey):void 0,i=t.sourceAnchors?.(),a=()=>void 0,o,s=n=>{r=n,t.viewKey&&Yn.set(t.viewKey,n),e.scrollTop=Zn(n,e.scrollHeight,e.clientHeight,i)};r&&s(r);let c=()=>{if(e.clientHeight<=0)return;let a=Gn(e.scrollTop,e.scrollHeight,e.clientHeight),o=i?Bt(i,e.scrollTop):null;r={ratio:a,sourceLine:o,revision:0},t.viewKey&&Yn.set(t.viewKey,r),t.driver&&n.publish(t.channel,t.target,a,o)};t.receiver?a=n.subscribe(t.channel,t.target,s):(t.driver||t.viewKey)&&(o=Xn(c),e.addEventListener(`scroll`,o.schedule,{passive:!0}),o.schedule());let l=new ResizeObserver(()=>{i=t.sourceAnchors?.(),r?s(r):o?.schedule()});for(let e of t.resizeElements??[])l.observe(e);return()=>{o&&(c(),e.removeEventListener(`scroll`,o.schedule)),a(),l.disconnect(),o?.dispose()}}function $n(e,t){let n=e.getModel()?.getLineCount()??0;if(n===0)return null;let r=1,i=n;for(;r<i;){let n=Math.ceil((r+i)/2);e.getTopForLineNumber(n)<=t?r=n:i=n-1}let a=e.getTopForLineNumber(r),o=r<n?e.getTopForLineNumber(r+1):e.getScrollHeight();return o<=a?r:r+Math.min(1,Math.max(0,(t-a)/(o-a)))}function er(e,t){let n=e.getModel()?.getLineCount()??0;if(n===0||!Number.isFinite(t))return null;let r=Math.min(n+1,Math.max(1,t)),i=Math.floor(r);if(i>n)return e.getScrollHeight();let a=i+1,o=e.getTopForLineNumber(i),s=a<=n?e.getTopForLineNumber(a):e.getScrollHeight();return o+(r-i)*(s-o)}function tr(e,t,n){if(t.driver&&t.receiver)throw Error(`a Monaco scroll surface cannot be both driver and receiver`);let r=t.store??Jn,i=[],a,o=()=>void 0,s,c=()=>e.getLayoutInfo().height,l=t=>{a=t;let r=t.ratio>0&&t.ratio<1&&t.sourceLine!==null?er(e,t.sourceLine):null;e.setScrollTop(r??Zn(t,e.getScrollHeight(),c()),n)};return t.receiver?(o=r.subscribe(t.channel,t.target,l),i.push(e.onDidChangeModel(()=>a&&l(a))),i.push(e.onDidLayoutChange(()=>a&&l(a))),i.push(e.onDidContentSizeChange(()=>a&&l(a)))):t.driver&&(s=Xn(()=>{let n=Gn(e.getScrollTop(),e.getScrollHeight(),c());r.publish(t.channel,t.target,n,$n(e,e.getScrollTop()))}),i.push(e.onDidScrollChange(s.schedule)),i.push(e.onDidChangeModel(s.schedule)),i.push(e.onDidChangeModelContent(s.schedule)),i.push(e.onDidLayoutChange(s.schedule)),i.push(e.onDidContentSizeChange(s.schedule)),s.schedule()),()=>{o();for(let e of i)e.dispose();s?.dispose()}}function nr(e){return!e}function rr(e){let t=e.split(`+`),n=t.pop()??``,r=0;for(let e of t)e===`meta`?r|=M.CtrlCmd:e===`ctrl`?r|=M.WinCtrl:e===`alt`?r|=M.Alt:e===`shift`&&(r|=M.Shift);let i=P[/^Key[A-Z]$/.test(n)?`Key${n.slice(3)}`:/^Digit[0-9]$/.test(n)?`Digit${n.slice(5)}`:n];return typeof i==`number`?r|i:null}function ir(e,t){let n=rr(ie(`editor.save`));n!==null&&e.addCommand(n,()=>t.onSave());let r=rr(ie(`editor.wordWrap`));e.addAction({id:`puddle.toggleWordWrap`,label:`Toggle Word Wrap`,keybindings:r===null?[]:[r],run:()=>w({editorWordWrap:nr(ee().editorWordWrap)})})}var ar=new WeakSet;function or(e){return ar.has(e)?!1:(ar.add(e),!0)}function sr(e){return`file-conflict:${e}`}function cr(e,t,n,r,i){let a=i?.passive===!0,o=i?.focused??!0,s=Ft(e,t,r),c=be(e,t,{root:r,live:i?.live}),l=ye(e,r),[u,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(!1),m=(0,I.useRef)(!1),h=(0,I.useRef)(null),g=(0,I.useRef)(null),_=(0,I.useRef)(n);_.current=n;let v=(0,I.useRef)(!1),y=(0,I.useCallback)((e,t)=>{g.current?.cancel(),v.current=!0;try{Pt(s,e,t)}finally{v.current=!1}},[s]),b=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>It(s,e),[s]),()=>kt(s)),x=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>tn(s,e),[s]),()=>Qt(s)),S=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>Mn(s,e),[s]),()=>jn(s));(0,I.useEffect)(()=>{let n=c.data;if(!n||n.binary||n.content===null||m.current)return;m.current=!0;let i=At(s)!==void 0,a=Nt(e,t,n.content,n.mtime_ms,r),o=a.getValue();d(a),!i&&qt(e,t,r).then(i=>{if(!i)return;let s=Jt(i,o,n.mtime_ms);s===`discard`?Xt(e,t,r):s===`restore`?Zt(a,i.content)&&p(!0):ze(`This file has an unsaved draft from an earlier version.`,{description:`The file changed on disk since the draft was saved.`,duration:12e3,action:{label:`Restore draft`,onClick:()=>{Zt(a,i.content)&&p(!0)}}})})},[c.data,s,e,t,r]),(0,I.useEffect)(()=>{if(!u||a)return;let n=Yt(e,t,r);g.current=n;let i=u.onDidChangeContent(()=>{v.current||(n(u.getValue(),At(s)??0),en(e,t,r))});return()=>{n.flush(),i.dispose(),g.current=null}},[u,s,e,t,r,a]),(0,I.useEffect)(()=>{!u||!x.savedElsewhere||kt(s)||c.refetch().then(e=>{kt(s)||(e.data&&e.data.content!==null&&y(e.data.content,e.data.mtime_ms),$t(s))})},[x.savedElsewhere,u,s]),(0,I.useEffect)(()=>{let e=c.data;!u||!e||e.content===null||!kt(s)&&e.mtime_ms!==At(s)&&y(e.content,e.mtime_ms)},[c.data,u,s]);let C=(0,I.useCallback)((n,i)=>{Tt(s,n,i),g.current?.cancel(),Xt(e,t,r),nn(e,t,i,r),p(!1),An(s)},[s,e,t,r]),w=(0,I.useCallback)(()=>{let e=Sn(s);e!==null&&(ze.dismiss(sr(s)),c.refetch({throwOnError:!0}).then(t=>{let n=t.data;if(!n)throw Error(`The disk version did not load.`);if(n.content===null)throw Error(`The file on disk is binary and cannot be compared as text.`);Cn(s,e,n.content,n.mtime_ms)}).catch(t=>{Tn(s,e,t instanceof Error?t.message:`The disk version did not load.`)}))},[c,s]),ee=(0,I.useRef)(w);ee.current=w,(0,I.useEffect)(()=>{if(!En(S,o))return;let e=sr(s);return ze(`File changed on disk`,{id:e,description:`Nothing was written — your unsaved version is intact.`,duration:1/0,closeButton:!0,action:{label:`Compare`,onClick:()=>ee.current()}}),()=>{ze.dismiss(e)}},[S,o,s]);let T=(0,I.useCallback)(()=>{c.refetch().then(n=>{n.data&&n.data.content!==null&&y(n.data.content,n.data.mtime_ms),Xt(e,t,r),p(!1),An(s)})},[s,e,t,y]),E=(0,I.useCallback)((e,n)=>{l.mutate({path:t,content:e},{onSuccess:e=>C(n,e.mtime_ms),onError:e=>ze.error(e instanceof Error?e.message:`Overwrite failed`)})},[l,t,C]),D=(0,I.useCallback)(async()=>{if(!u||!kt(s))return!0;let e=u.getValue(),n=u.getAlternativeVersionId();if(On(jn(s)))return!1;let r=Dn(jn(s))??At(s);try{let i=await l.mutateAsync({path:t,content:e,expected_mtime_ms:r});return C(n,i.mtime_ms),!0}catch(e){return e instanceof re&&e.status===409&&e.code===`stale_file`?xn(s):ze.error(e instanceof Error?e.message:`Save failed`),!1}},[u,s,l,t,C]),O=(0,I.useRef)(D);O.current=D,(0,I.useEffect)(()=>fe(De(e,t,r),()=>O.current(),{session:e,path:t,...r===void 0?{}:{root:r}}),[e,t,r]);let k=(0,I.useCallback)(()=>{let n=h.current,i=_.current;!n||!i||!o||i.session!==e||i.path!==t||(i.root??void 0)!==(r??void 0)||or(i)&&(n.revealLineInCenter(i.line),n.setPosition({lineNumber:i.line,column:i.column??1}),n.focus())},[e,t,r,o]),A=(0,I.useCallback)(e=>{h.current=e,ir(e,{onSave:()=>O.current()}),k()},[k]);(0,I.useEffect)(()=>{k()},[n,u,k]);let j=(0,I.useCallback)(()=>{T()},[T]),te=(0,I.useCallback)(()=>{!u||jn(s)?.phase!==`comparing`||E(u.getValue(),u.getAlternativeVersionId())},[u,s,E]),M=(0,I.useCallback)(e=>{wn(s,e)},[s]),N,P=null;c.data?.binary?N=`binary`:c.error?c.error instanceof re&&c.error.status===413?N=`too-large`:(N=`error`,P=c.error instanceof Error?c.error.message:`Failed to load file`):N=u?`ready`:`loading`;let F=b&&x.savedElsewhere?`saved-elsewhere`:b&&x.dirtyElsewhere?`dirty-elsewhere`:null;return{status:N,errorMessage:P,model:u,dirty:b,restoredNotice:f,discardRestore:j,peerBadge:F,conflict:S,takeDisk:T,keepMine:te,compare:w,comparisonReady:M,save:D,onMount:A}}function lr(e,t,n,r){for(let i of e)if(mr([i],n).some(e=>(r===void 0||e.kind===r)&&t>=e.startLineNumber&&t<=e.endLineNumber))return i;return null}function ur(e,t){return fr(e.modifiedStartLineNumber,e.modifiedEndLineNumber)>0?Math.min(t,e.modifiedEndLineNumber):Math.max(0,Math.min(t,e.modifiedStartLineNumber-1))}function dr(e){let t=fr(e.originalStartLineNumber,e.originalEndLineNumber),n=fr(e.modifiedStartLineNumber,e.modifiedEndLineNumber);return Math.max(5,Math.min(14,t+n+4))}function fr(e,t){return t===0?0:Math.max(0,t-e+1)}function pr(e,t){if(e>t)return{startLineNumber:Math.max(1,t),endLineNumber:Math.max(1,t),kind:`deleted-after`};let n=Math.max(1,e);return{startLineNumber:n,endLineNumber:n,kind:`deleted-before`}}function mr(e,t){let n=[];for(let r of e){let e=fr(r.originalStartLineNumber,r.originalEndLineNumber),i=fr(r.modifiedStartLineNumber,r.modifiedEndLineNumber);if(e===0&&i>0){n.push({startLineNumber:r.modifiedStartLineNumber,endLineNumber:r.modifiedEndLineNumber,kind:`added`});continue}if(i===0&&e>0){n.push(pr(r.modifiedStartLineNumber,t));continue}let a=Math.min(e,i);a>0&&n.push({startLineNumber:r.modifiedStartLineNumber,endLineNumber:r.modifiedStartLineNumber+a-1,kind:`modified`}),i>a&&n.push({startLineNumber:r.modifiedStartLineNumber+a,endLineNumber:r.modifiedEndLineNumber,kind:`added`}),e>a&&n.push(pr(r.modifiedStartLineNumber+i,t))}return n}var hr=28,gr=[[`puddle-dirty-added`,`added`],[`puddle-dirty-modified`,`modified`],[`puddle-dirty-deleted-before`,`deleted-before`],[`puddle-dirty-deleted-after`,`deleted-after`]];function _r(e){if(e){for(let[t,n]of gr)if(e.classList.contains(t)||e.closest(`.${t}`))return n}}function vr({editor:e,original:t,modified:n,path:r}){let i=[],a=null,o=!1,s=t=>{try{e.changeViewZones(e=>e.removeZone(t))}catch{}},c=()=>{let e=a;e&&(a=null,e.frame!==null&&cancelAnimationFrame(e.frame),e.diffEditor&&(e.diffEditor.setModel(null),e.diffEditor.dispose()),s(e.zoneId))},l=e=>{let t=e.diffEditor;if(!t)return;let r=Math.max(1,Math.min(n.getLineCount(),e.change.modifiedStartLineNumber));t.getModifiedEditor().revealLineInCenter(r,N.ScrollType.Immediate)},u=(i,s)=>{if(a?.anchorLine===i){c();return}c();let u=e.getOption(N.EditorOption.lineHeight),d=document.createElement(`div`);d.className=`puddle-dirty-peek`;let f=document.createElement(`div`);f.className=`puddle-dirty-peek-header`;let p=document.createElement(`span`);p.className=`puddle-dirty-peek-title`,p.textContent=`${r.split(`/`).pop()??r} · Local changes against HEAD`;let m=document.createElement(`button`);m.type=`button`,m.className=`puddle-dirty-peek-close`,m.setAttribute(`aria-label`,`Close inline change`),m.title=`Close inline change`,m.textContent=`×`,m.addEventListener(`pointerdown`,e=>{e.preventDefault(),e.stopPropagation(),c()}),m.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),c()});let h=document.createElement(`div`);h.className=`puddle-dirty-peek-editor`,f.append(p,m),d.append(f,h);let g=document.createElement(`div`);g.className=`puddle-dirty-peek-margin`;let _={afterLineNumber:ur(s,n.getLineCount()),heightInPx:hr+dr(s)*u,domNode:d,marginDomNode:g,suppressMouseDown:!1},v=``;e.changeViewZones(e=>{v=e.addZone(_)});let y={anchorLine:i,change:s,zone:_,zoneId:v,frame:null,diffEditor:null};a=y,y.frame=requestAnimationFrame(()=>{if(y.frame=null,o||a!==y)return;let r=N.createDiffEditor(h,{readOnly:!0,domReadOnly:!0,originalEditable:!1,renderSideBySide:!1,renderMarginRevertIcon:!1,renderOverviewRuler:!1,enableSplitViewResizing:!1,isInEmbeddedEditor:!0,automaticLayout:!0,fontFamily:e.getOption(N.EditorOption.fontFamily),fontSize:e.getOption(N.EditorOption.fontSize),lineHeight:u,minimap:{enabled:!1},glyphMargin:!1,folding:!1,scrollBeyondLastLine:!1,fixedOverflowWidgets:!0,hideUnchangedRegions:{enabled:!0,minimumLineCount:0,contextLineCount:2,revealLineCount:3}});y.diffEditor=r,r.setModel({original:t,modified:n}),r.onDidUpdateDiff(()=>l(y)),l(y)}),e.revealLineInCenter(Math.max(1,Math.min(n.getLineCount(),s.modifiedStartLineNumber)))},d=e.onMouseDown(e=>{if(!e.event.leftButton||e.target.type!==N.MouseTargetType.GUTTER_LINE_DECORATIONS||e.target.position===null)return;let t=e.target.position.lineNumber,r=lr(i,t,n.getLineCount(),_r(e.target.element));r&&(e.event.preventDefault(),e.event.stopPropagation(),u(t,r))});return{update(t){if(i=t,!a)return;let r=a,o=lr(t,r.anchorLine,n.getLineCount());if(!o){c();return}r.change=o,r.zone.afterLineNumber=ur(o,n.getLineCount()),r.zone.heightInPx=hr+dr(o)*e.getOption(N.EditorOption.lineHeight);try{e.changeViewZones(e=>e.layoutZone(r.zoneId))}catch{c();return}l(r)},dispose(){o=!0,d.dispose(),c()}}}var yr={added:`puddle-dirty-added`,modified:`puddle-dirty-modified`,"deleted-before":`puddle-dirty-deleted-before`,"deleted-after":`puddle-dirty-deleted-after`};function br(e,t,r,i){let o=n(),s=de(e,t,{root:r,enabled:o.data!==void 0&&a(o.data.protocol)&&i!==null}),[c,l]=(0,I.useState)(null),u=(0,I.useCallback)(e=>{l(e)},[]);return(0,I.useLayoutEffect)(()=>{let e=s.data;if(!c||!i||!e||e.repository===null||e.ignored||e.binary)return;let n=document.createElement(`div`);n.className=`puddle-hidden-diff-controller`,document.body.appendChild(n);let r=N.createModel(e.exists?e.content??``:``,i.getLanguageId()),a=N.createDiffEditor(n,{readOnly:!0,automaticLayout:!1,renderSideBySide:!1,minimap:{enabled:!1}}),o=c.createDecorationsCollection();a.setModel({original:r,modified:i});let l=vr({editor:c,original:r,modified:i,path:t}),u=()=>{let e=a.getLineChanges();e&&(l.update(e),o.set(mr(e,i.getLineCount()).map(e=>({range:new j(e.startLineNumber,1,e.endLineNumber,1),options:{isWholeLine:!0,linesDecorationsClassName:yr[e.kind]}}))))},d=a.onDidUpdateDiff(u);return u(),()=>{d.dispose(),l.dispose(),o.clear(),a.setModel(null),a.dispose(),r.dispose(),n.remove()}},[c,i,s.data]),u}function xr({message:e,session:t,path:n,root:r,download:i}){return(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground text-sm text-fg-muted`,children:[(0,L.jsx)(`span`,{children:e}),i&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>void me(t,n,r).catch(e=>ze.error(e instanceof Error?e.message:`Download failed`)),className:`flex items-center gap-1.5 text-fg-secondary transition-colors hover:text-fg`,children:[(0,L.jsx)(Ce,{className:`size-4`}),`Download`]})]})}function Sr({session:e,path:t,reveal:n,root:r,focused:i=!0,scrollDriver:a=!1,scrollReceiver:o=!1,scrollChannel:s=`profile`}){let c=C(),l=Bn([e,r,t]),u=cr(e,t,n,r,{focused:i}),d=pe(e,t,r),f=br(e,t,r,u.model),p=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),[m,h]=(0,I.useState)(null),g=(0,I.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),_=u.conflict!==null&&u.conflict.phase!==`unresolved`;if((0,I.useEffect)(()=>{if(!(!m||!u.model||_))return tr(m,{channel:s,target:g,driver:a,receiver:o},N.ScrollType.Immediate)},[m,u.model,_,s,g,a,o]),(0,I.useEffect)(()=>{let e=u.model;e&&N.setModelMarkers(e,`puddle-compilation`,d.map(t=>{let n=Math.min(t.line,e.getLineCount()),r=e.getLineMaxColumn(n),i=Math.min(t.column??1,r),a=t.end_line??n,o=Math.max(n,Math.min(a,e.getLineCount())),s=e.getLineMaxColumn(o),c=Math.min(t.end_column??(t.column?i+1:s),s);return{severity:t.severity===`error`?A.Error:t.severity===`warning`?A.Warning:A.Info,message:t.message,source:`Puddle compilation`,startLineNumber:n,startColumn:i,endLineNumber:o,endColumn:Math.max(i,c)}}))},[u.model,d]),u.conflict&&u.conflict.phase!==`unresolved`)return(0,L.jsx)(Un,{session:e,path:t,buffer:u,focused:i});if(u.status===`binary`)return(0,L.jsx)(xr,{message:`Binary file — use Download`,session:e,path:t,root:r,download:!0});if(u.status===`too-large`)return(0,L.jsx)(xr,{message:`File too large to edit — use Download`,session:e,path:t,root:r,download:!0});if(u.status===`error`)return(0,L.jsx)(xr,{message:u.errorMessage??`Failed to load file`,session:e,path:t,root:r});let v=u.peerBadge===`saved-elsewhere`?`Saved in another window`:u.peerBadge===`dirty-elsewhere`?`Also being edited in another window`:null;return(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[u.restoredNotice&&(0,L.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsx)(`span`,{children:`Restored unsaved changes`}),(0,L.jsx)(`button`,{type:`button`,onClick:u.discardRestore,className:`text-fg-muted transition-colors hover:text-fg`,children:`Discard`})]}),v&&(0,L.jsx)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:v}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 pl-1`,children:u.model&&(0,L.jsx)(Ot,{path:u.model.uri.toString(),defaultValue:u.model.getValue(),theme:`puddle`,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{l(e),u.onMount(e),f(e),h(e)},loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),options:{automaticLayout:!0,fontFamily:p,fontSize:c.editorFontSize,...Nn(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:1,lineDecorationsWidth:5,fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function R({children:e}){return(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-xs text-fg-muted`,children:e})}function Cr(e,t){let n=(0,I.useRef)(t);n.current=t,(0,I.useEffect)(()=>(Et(e),()=>{n.current?.(),jt(e)}),[e])}function wr(e,t,n,r){let i=r.split(`/`).map(encodeURIComponent).join(`/`);return`${e}://${encodeURIComponent(t)}/${encodeURIComponent(n)}/${i}`}function Tr({session:e,refName:t,path:n,content:r}){let i=C(),a=Bn([e,t,n]),o=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,L.jsx)(Ot,{path:wr(`puddle-view`,e,t,n),defaultValue:r,theme:Dt,saveViewState:!1,onMount:a,loading:(0,L.jsx)(R,{children:`…`}),options:{readOnly:!0,automaticLayout:!0,fontFamily:o,fontSize:i.editorFontSize,...Nn(i.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Er({session:e,against:t,path:n,root:r,indexBase:i=!1}){let a=_e(e,t,n,{root:r,enabled:!i}),o=ue(e,n,{root:r,enabled:i}),s=i?o:a;return s.isPending?(0,L.jsx)(R,{children:`…`}):s.error?(0,L.jsx)(R,{children:s.error instanceof Error?s.error.message:`Failed to load`}):s.data.binary?(0,L.jsx)(R,{children:`Binary file — deleted`}):(0,L.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,L.jsx)(`div`,{className:`bg-surface px-4 py-1 text-xs text-fg-muted`,children:`Deleted`}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Tr,{session:e,refName:`${t}:${r??``}`,path:n,content:s.data.content??``})})]})}function Dr({session:e,against:t,path:n,basePath:r,root:i,indexBase:a=!1,focused:o=!0}){let s=C(),c=Vn([e,i,t,a,n]),l=cr(e,n,null,i,{focused:o}),u=_e(e,t,r,{root:i,enabled:!a}),d=ue(e,r,{root:i,enabled:a}),f=a?d:u,p=(0,I.useRef)(null);Cr(Ft(e,n,i),()=>{let e=p.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),p.current=null});let m=(0,I.useRef)(l.save);m.current=l.save;let h=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),g=f.error instanceof re&&f.error.status===404;return l.conflict&&l.conflict.phase!==`unresolved`?(0,L.jsx)(Un,{session:e,path:n,buffer:l,focused:o}):l.status===`binary`||f.data?.binary?(0,L.jsx)(R,{children:`Binary file`}):l.status===`too-large`?(0,L.jsx)(R,{children:`File too large to show`}):l.status===`error`?(0,L.jsx)(R,{children:l.errorMessage??`Failed to load file`}):g||a&&d.data&&!d.data.exists?(0,L.jsx)(Sr,{session:e,path:n,reveal:null,root:i,focused:o}):f.isPending||!l.model?(0,L.jsx)(R,{children:`…`}):f.error?(0,L.jsx)(R,{children:f.error instanceof Error?f.error.message:`Failed to load base`}):(0,L.jsx)(Mt,{modifiedModelPath:l.model.uri.toString(),originalModelPath:wr(`puddle-base`,e,`${t}:${i??``}`,r),original:f.data.content??``,language:l.model.getLanguageId(),theme:Dt,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(R,{children:`…`}),onMount:e=>{c(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(M.CtrlCmd|P.KeyS,()=>m.current())},options:{readOnly:!1,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:h,fontSize:s.editorFontSize,...Nn(s.editorTabSize),wordWrap:s.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Or({session:e,against:t,entry:n,root:r}){let i=C(),a=Vn([e,r,t,`staged`,n.path]),o=n.old_path??n.path,s=_e(e,t,o,{root:r,enabled:n.status!==`added`}),c=ue(e,n.path,{root:r,enabled:n.status!==`deleted`}),l=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if(n.status===`deleted`)return(0,L.jsx)(Er,{session:e,against:t,path:o,root:r});if(c.isPending||n.status!==`added`&&s.isPending)return(0,L.jsx)(R,{children:`…`});if(c.error||s.error){let e=c.error??s.error;return(0,L.jsx)(R,{children:e instanceof Error?e.message:`Failed to load staged content`})}return c.data.binary||s.data?.binary?(0,L.jsx)(R,{children:`Binary file`}):n.status===`added`?(0,L.jsx)(Tr,{session:e,refName:`index:${r??``}`,path:n.path,content:c.data.content??``}):s.data?(0,L.jsx)(Mt,{originalModelPath:wr(`puddle-head`,e,`${t}:${r??``}`,o),modifiedModelPath:wr(`puddle-index`,e,`${t}:${r??``}`,n.path),original:s.data.content??``,modified:c.data.content??``,onMount:a,theme:Dt,loading:(0,L.jsx)(R,{children:`…`}),options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:l,fontSize:i.editorFontSize,...Nn(i.editorTabSize),wordWrap:i.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}}):(0,L.jsx)(R,{children:`Failed to load HEAD content`})}function kr({session:e,path:t,root:n,focused:r}){return Cr(Ft(e,t,n)),(0,L.jsx)(Sr,{session:e,path:t,reveal:null,root:n,focused:r})}function Ar({session:e,against:t,entry:n,root:r,area:i,focused:a=!0}){if(i===`staged`)return(0,L.jsx)(Or,{session:e,against:t,entry:n,root:r});switch(n.status){case`added`:return(0,L.jsx)(kr,{session:e,path:n.path,root:r,focused:a});case`deleted`:return(0,L.jsx)(Er,{session:e,against:t,path:n.path,root:r,indexBase:i===`unstaged`});case`modified`:case`renamed`:return(0,L.jsx)(Dr,{session:e,against:t,path:n.path,basePath:n.old_path??n.path,root:r,indexBase:i===`unstaged`,focused:a});default:return null}}function jr({session:e,sha:t,path:n,root:r}){let i=_e(e,t,n,{root:r});return i.isPending?(0,L.jsx)(R,{children:`…`}):i.error?(0,L.jsx)(R,{children:i.error instanceof Error?i.error.message:`Failed to load file`}):i.data.binary?(0,L.jsx)(R,{children:`Binary file`}):(0,L.jsx)(Tr,{session:e,refName:`${t}:${r??``}`,path:n,content:i.data.content??``})}function Mr({session:e,originalRef:t,originalPath:n,originalContent:r,modifiedRef:i,modifiedPath:a,modifiedContent:o,root:s}){let c=C(),l=Vn([e,s,t,n,i,a]),u=(0,I.useRef)(null),d=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,I.useEffect)(()=>()=>{let e=u.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),t?.modified.dispose(),u.current=null},[]),(0,L.jsx)(Mt,{originalModelPath:wr(`puddle-hist-orig`,e,`${t}:${s??``}`,n),modifiedModelPath:wr(`puddle-hist-mod`,e,`${i}:${s??``}`,a),original:r,modified:o,theme:Dt,keepCurrentOriginalModel:!0,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(R,{children:`…`}),onMount:e=>{l(e),u.current=e,e.onDidDispose(()=>{u.current=null})},options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...Nn(c.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Nr({session:e,sha:t,path:n,basePath:r,root:i}){let a=_e(e,`${t}^`,r,{root:i}),o=_e(e,t,n,{root:i});return a.error instanceof re&&a.error.status===404?(0,L.jsx)(jr,{session:e,sha:t,path:n,root:i}):a.isPending||o.isPending?(0,L.jsx)(R,{children:`…`}):a.error?(0,L.jsx)(R,{children:a.error instanceof Error?a.error.message:`Failed to load original`}):o.error?(0,L.jsx)(R,{children:o.error instanceof Error?o.error.message:`Failed to load file`}):a.data.binary||o.data.binary?(0,L.jsx)(R,{children:`Binary file`}):(0,L.jsx)(Mr,{session:e,originalRef:`${t}^`,originalPath:r,originalContent:a.data.content??``,modifiedRef:t,modifiedPath:n,modifiedContent:o.data.content??``,root:i})}function Pr({session:e,sha:t,entry:n,isRootCommit:r,root:i}){switch(le(n.status,r)){case`added`:return(0,L.jsx)(jr,{session:e,sha:t,path:n.path,root:i});case`deleted`:return(0,L.jsx)(Er,{session:e,against:`${t}^`,path:n.path,root:i});case`modified`:case`renamed`:return(0,L.jsx)(Nr,{session:e,sha:t,path:n.path,basePath:n.old_path??n.path,root:i});default:return null}}function Fr({session:e,sha:t,path:n,root:r}){let i=ge(e,t,r);if(i.isPending)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading commit…`});if(i.error)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:i.error instanceof Error?i.error.message:`Failed to load commit`});let a=i.data.files.find(e=>e.path===n);return a?(0,L.jsx)(`div`,{className:`h-full`,children:(0,L.jsx)(Pr,{session:e,sha:t,entry:a,isRootCommit:i.data.parents.length===0,root:r})}):(0,L.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[(0,L.jsx)(`span`,{className:`text-fg-secondary`,children:n}),` is not part of`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:t.slice(0,7)}),`.`]})}function Ir({session:e,path:t,root:n,area:r,focused:i=!0}){let a=ve(e,{root:n,against:r===void 0?`base`:`head`,area:r});if(a.isPending)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading diff…`});if(a.error)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:a.error instanceof Error?a.error.message:`Failed to load diff`});let o=a.data.entries.find(e=>e.path===t);return o?(0,L.jsx)(`div`,{className:`h-full`,children:(0,L.jsx)(Ar,{session:e,against:a.data.against,entry:o,root:n,area:r,focused:i})}):(0,L.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[`No changes to `,(0,L.jsx)(`span`,{className:`mx-1 text-fg-secondary`,children:t}),` against the base.`]})}var Lr=800;function Rr({name:e}){let t=C(),n=ae(),r=Bn([n,e]),a=he(n,e),o=i(),s=oe(`editor.save`),c=(0,I.useRef)(null),l=(0,I.useRef)(null),u=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if((0,I.useEffect)(()=>{if(n===null)return;let t=wt(t=>{ce(n,e,t).catch(e=>ze.error(e instanceof Error?e.message:`Draft not saved`))},Lr);return l.current=t,()=>{t.flush(),l.current=null}},[n,e]),n===null)return null;if(a.error)return(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:a.error instanceof Error?a.error.message:`Failed to load the draft`});if(a.data===void 0)return(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`});let d=()=>{let t=c.current;t&&(l.current?.flush(),Le({name:e,content:t.getValue()}))};return(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,L.jsxs)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:[`Draft — not in any worktree; `,s,` saves it into one`]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Ot,{path:`puddle-untitled://${n}/${e}`,defaultValue:a.data.content,theme:Dt,keepCurrentModel:!1,saveViewState:!1,loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:t=>{r(t),c.current=t,xe(e,t.getValue()),ir(t,{onSave:d})},onChange:t=>{let r=t??``;xe(e,r),Re(o,n,e,r),l.current?.(r)},options:{automaticLayout:!0,fontFamily:u,fontSize:t.editorFontSize,...Nn(t.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1,wordWrap:t.editorWordWrap?`on`:`off`}})})]})}var zr=d([y(),h(y())]),Br=_(y(),m()),Vr=f({output_type:y(),text:zr.optional(),data:_(y(),m()).optional(),traceback:h(y()).optional(),ename:y().optional(),evalue:y().optional()}),Hr=f({id:y().optional(),cell_type:b([`code`,`markdown`,`raw`]),metadata:Br,source:zr,outputs:h(Vr).optional(),execution_count:u().int().nullable().optional()}),Ur=f({nbformat:v(4),nbformat_minor:u().int().nonnegative(),metadata:Br,cells:h(Hr).max(2e3)});function Wr(e){if(e.length>5*1024*1024)throw Error(`This notebook exceeds the 5 MiB editor limit.`);let t;try{t=JSON.parse(e)}catch{throw Error(`This notebook is not valid JSON. Switch to source to repair it.`)}let n=Ur.safeParse(t);if(!n.success)throw Error(`Expected a version 4 notebook with at most 2,000 valid cells. Switch to source to inspect it.`);return n.data}function z(e){return typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(``):``}function Gr(e,t,n){return{...e,cells:e.cells.map((e,r)=>r===t?{...e,source:n.match(/[^\n]*\n|[^\n]+$/g)??[],...e.cell_type===`code`&&e.outputs?.length&&!e.metadata.puddle_execution?{metadata:{...e.metadata,puddle_execution:{id:`saved`,revision:0,source:z(e.source),state:`saved`}}}:{}}:e)}}function Kr(e){let t=new Set;return{...e,cells:e.cells.map((n,r)=>{let i=n.id;if(!i||t.has(i))for(i=`puddle-${r}`;t.has(i)||e.cells.some(e=>e.id===i);)i+=`-`;return t.add(i),n.id===i?n:{...n,id:i}})}}function qr(e,t){if(e.cell_type!==`code`)return e.cell_type===`raw`?`plaintext`:`markdown`;let n=e.metadata.vscode,r=t.metadata.language_info,i=t.metadata.kernelspec,a=n?.languageId??r?.name??i?.language??`python`;return typeof a==`string`?a:`python`}function Jr(e,t){let n=t===`markdown`||t===`raw`?t:`code`,r={...e,cell_type:n};return n===`code`?(r.metadata={...e.metadata,vscode:{...e.metadata.vscode??{},languageId:t}},r.outputs??=[],r.execution_count??=null):(delete r.outputs,delete r.execution_count),r}function Yr(e){return{id:crypto.randomUUID(),cell_type:e,metadata:{},source:[],...e===`code`?{outputs:[],execution_count:null}:{}}}function Xr(e){return(e.output_type===`error`?e.traceback?.join(`
|
|
3
|
+
`)??`${e.ename??`Error`}: ${e.evalue??``}`:z(e.text??e.data?.[`text/plain`])).replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``)}function Zr(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length,i=t.length;for(;r>n&&i>n&&e[r-1]===t[i-1];)r--,i--;return{start:n,end:r,text:t.slice(n,i)}}function Qr(e){return{...e,cells:e.cells.map(e=>e.cell_type===`code`?{...e,outputs:[],execution_count:null}:e)}}function $r(e){return e.cells.map((e,t)=>{let n=z(e.source).split(`
|
|
4
|
+
`).find(e=>e.trim())?.trim()??``;return{index:t,level:e.cell_type===`markdown`?/^(#{1,6})\s/.exec(n)?.[1]?.length??0:0,label:(e.cell_type===`markdown`?n.replace(/^#{1,6}\s+/,``):n).slice(0,100)||`${e.cell_type===`code`?`Code`:e.cell_type===`markdown`?`Markdown`:`Raw`} cell`}})}function ei(e,t){let n=$r(e),r=n[t]?.level;if(!r)return[t];let i=n.find(e=>e.index>t&&e.level>0&&e.level<=r);return Array.from({length:(i?.index??e.cells.length)-t},(e,n)=>t+n)}function ti(e,t){let n=!1,r=new Map(t.cells.map(e=>[e.id,e])),i=e.cells.map(e=>{let i=r.get(e.id);if(e.cell_type!==`code`||!i||i.state===`queued`)return e;let a=e.metadata.puddle_execution;return a?.id===t.id&&typeof a.revision==`number`&&a.revision>=i.revision||i.state===`cancelled`&&i.elapsed_ms===void 0?e:(n=!0,{...e,outputs:i.outputs,execution_count:i.execution_count,metadata:{...e.metadata,puddle_execution:{id:t.id,revision:i.revision,source:i.source,state:i.state,elapsed_ms:i.elapsed_ms}}})});return n?{...e,cells:i}:e}function ni(e){let t=e.metadata.puddle_execution;if(!(!t||typeof t!=`object`||!(`source`in t)||typeof t.source!=`string`||!(`state`in t)||typeof t.state!=`string`))return{source:t.source,state:t.state===`running`||t.state===`queued`?`saved`:t.state,...`elapsed_ms`in t&&typeof t.elapsed_ms==`number`?{elapsed_ms:t.elapsed_ms}:{}}}function ri({notebook:e,active:t,selected:n,update:r,choose:i,setEditing:a,run:o,onUndo:s,onRedo:c}){let l=(n,a=e.cells.findIndex(e=>e.id===t)+1)=>{if(e.cells.length>=2e3)return;let o=Yr(n),s=[...e.cells];s.splice(t===null?s.length:a,0,o),r({...e,cells:s}),i(o.id,!0)},u=(t,n)=>r({...e,cells:e.cells.map((e,r)=>r===t?n:e)}),d=(t,n)=>{e.cells[t]?.cell_type===`code`&&o([t]),a(null),n===`insert`||n===`next`&&t===e.cells.length-1?l(e.cells[t].cell_type,t+1):n===`next`&&i(e.cells[t+1].id)};return{add:l,replace:u,execute:d,operation:(t,n)=>{let a=[...e.cells],o=a[t];if(n===`insert`){l(`code`,t+1);return}if(n===`clear`){u(t,{...o,outputs:[],execution_count:null});return}if(n===`delete`&&(a.splice(t,1),a.length&&i(a[Math.min(t,a.length-1)].id)),n===`up`||n===`down`){let e=t+(n===`up`?-1:1);if(e<0||e>=a.length)return;[a[t],a[e]]=[a[e],o],i(o.id)}if(n===`duplicate`){if(a.length>=2e3)return;let e={...structuredClone(o),id:crypto.randomUUID()};a.splice(t+1,0,e),i(e.id,!0)}if(n===`merge`){let e=a[t+1];if(!e||e.cell_type!==o.cell_type)return;a[t]={...o,source:`${z(o.source)}\n${z(e.source)}`},a.splice(t+1,1),i(o.id,!0)}r({...e,cells:a})},keyDown:f=>{if(f.target.closest(`.monaco-editor,input,textarea,[role=dialog],[role=menu],[cmdk-root]`))return;let p=e.cells.findIndex(e=>e.id===t);if((f.metaKey||f.ctrlKey)&&f.key.toLowerCase()===`z`){f.preventDefault(),f.shiftKey?c?.():s?.();return}if(f.key===`Enter`&&(f.metaKey||f.ctrlKey)&&n.length>1){f.preventDefault(),o(e.cells.flatMap((e,t)=>n.includes(e.id)?[t]:[]));return}if(f.key===`Enter`&&p>=0)f.preventDefault(),f.metaKey||f.ctrlKey||f.shiftKey||f.altKey?d(p,f.shiftKey?`next`:f.altKey?`insert`:`stay`):a(t);else if(f.key===`ArrowDown`||f.key===`ArrowUp`){f.preventDefault();let t=Math.max(0,Math.min(e.cells.length-1,p+(f.key===`ArrowDown`?1:-1)));e.cells[t]&&i(e.cells[t].id,!1,f.shiftKey)}else!f.metaKey&&!f.ctrlKey&&!f.altKey&&((f.key===`a`||f.key===`b`)&&(f.preventDefault(),l(`code`,Math.max(0,p+ +(f.key===`b`)))),(f.key===`m`||f.key===`y`)&&p>=0&&(f.preventDefault(),u(p,Jr(e.cells[p],f.key===`m`?`markdown`:`python`))),(f.key===`Delete`||f.key===`Backspace`)&&(f.preventDefault(),r({...e,cells:e.cells.filter(e=>!n.includes(e.id))})))}}}function ii(e,t,n,r,i){if(!(e.target.closest(`.monaco-editor,input,textarea`)||!r.length)&&!(t!==`paste`&&window.getSelection()?.toString()))if(t===`paste`){let t=e.clipboardData.getData(`text/plain`);if(t.length>5*1024*1024)return;try{let a=JSON.parse(t);if(!a||typeof a!=`object`||!(`puddle_notebook_cells`in a))return;let o=Wr(JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{},cells:a.puddle_notebook_cells})).cells;if(e.preventDefault(),n.cells.length+o.length>2e3){ze.error(`A notebook can contain at most 2,000 cells`);return}let s=[...n.cells],c=Math.max(...s.flatMap((e,t)=>r.includes(e.id)?[t]:[]));s.splice(c+1,0,...o.map(e=>({...e,id:crypto.randomUUID()}))),i({...n,cells:s})}catch{}}else{let a=n.cells.filter(e=>r.includes(e.id));e.clipboardData.setData(`text/plain`,JSON.stringify({puddle_notebook_cells:a})),e.preventDefault(),t===`cut`&&i({...n,cells:n.cells.filter(e=>!r.includes(e.id))})}}function ai({controls:e}){return e.open?(0,L.jsx)(rt,{query:e.query,focusKey:e.focusKey,options:e.options,result:e.result,onQueryChange:e.setQuery,onOptionsChange:e.setOptions,onNext:e.next,onPrevious:e.previous,onClose:e.close}):null}function oi(e,t){return Math.min(t,Math.max(1,Math.floor(e)))}function si({notebook:e,focused:t,onReveal:n,onChange:r}){let[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(``),c=(0,I.useRef)(null),l=(0,I.useRef)([]),u=(0,I.useRef)(-1),d=(0,I.useRef)(!1),f=$e({shortcutEnabled:t,onFind:(t,r,a)=>{let o=c.current;if(a===`reset`){l.current=[],u.current=-1;for(let n of e.cells){let e=[{text:z(n.source),output:!1},...i?[{text:(n.outputs??[]).map(Xr).join(`
|
|
5
|
+
`),output:!0}]:[]];for(let i of e){let e=nt(i.text,t,r,Math.max(0,1e3-l.current.length));if(e.invalid)return{index:-1,count:0,invalid:!0};if(l.current.push(...e.matches.map(e=>({...e,id:n.id,output:i.output}))),l.current.length>=1e3)break}if(l.current.length>=1e3)break}if(d.current&&o){let e=l.current.findIndex(e=>e.id===o.id&&e.output===o.output&&e.start>=o.start);u.current=e>=0?e-1:-1}}let s=l.current.length;return u.current=s?(u.current+(a===`previous`?-1:1)+s)%s:-1,c.current=l.current[u.current]??null,d.current||n(c.current),{index:u.current,count:s,limited:s>=1e3}},onClear:()=>{c.current=null,n(null)}});(0,I.useEffect)(()=>{f.refresh()},[i,f.refresh]);let p=t=>{let n=et(f.query,f.options);if(!n||!r)return;let i=e;e.cells.forEach((e,r)=>{let a=z(e.source),s=c.current;t?i=Gr(i,r,a.replace(n,o)):s&&!s.output&&s.id===e.id&&(i=Gr(i,r,a.slice(0,s.start)+a.slice(s.start,s.end).replace(n,o)+a.slice(s.end)))}),r(i),l.current=[],c.current=null};return(0,I.useEffect)(()=>{d.current=c.current!==null,f.open&&f.refresh(),d.current=!1},[e,f.open,f.refresh]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(ai,{controls:f}),f.open&&(0,L.jsxs)(`div`,{className:`absolute right-2 top-10 z-30 flex max-w-full flex-wrap items-center gap-2 rounded-b-md bg-surface px-2 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`Include output`]}),r&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`input`,{"aria-label":`Replace in notebook`,value:o,onChange:e=>s(e.target.value),placeholder:`Replace`,className:`min-w-0 bg-ground px-2 py-1 outline-none`}),(0,L.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query||!!c.current?.output,onClick:()=>p(!1),children:`Replace`}),(0,L.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query,onClick:()=>p(!0),children:`Replace all`})]})]})]})}function ci(e){return r({queryKey:[`notebook-kernels`],queryFn:()=>F(`GET`,`/api/notebooks/kernels`),enabled:e,staleTime:3e4})}function li(e,t){return r({queryKey:[`notebook-kernel`,e],queryFn:()=>F(`POST`,`/api/notebooks/status`,{source:e}),enabled:t,refetchInterval:1500,retry:!1})}function ui(e){return F(`POST`,`/api/notebooks/kernel`,e)}function di(e,t){return r({queryKey:[`notebook-environments`,e],queryFn:()=>F(`POST`,`/api/notebooks/environments`,{source:e}),enabled:t,staleTime:3e4,retry:!1})}function fi(e,t,a,c){let l=n(),u=c&&!g()&&o(l.data?.protocol),d=(0,I.useRef)({notebook:t,onChange:a});d.current={notebook:t,onChange:a};let f=i(),[p,m]=(0,I.useState)(!1),h=(0,I.useRef)(!1),[_,v]=(0,I.useState)(null),y=(0,I.useRef)(!0);(0,I.useEffect)(()=>(y.current=!0,()=>{y.current=!1}),[]);let b=[`notebook-execution`,e],x=r({queryKey:b,queryFn:()=>F(`POST`,`/api/notebooks/execution`,{source:e}),enabled:u,retry:!1,refetchInterval:e=>e.state.data?.execution?.state===`running`?250:1500}),S=x.data?.execution;(0,I.useEffect)(()=>{if(!S||!d.current.notebook||!d.current.onChange)return;let e=ti(d.current.notebook,S);e!==d.current.notebook&&d.current.onChange(e)},[S]);let C=async t=>{let n=d.current.notebook;if(!u||!n||h.current||S?.state===`running`)return;let r=n.cells.flatMap((e,n)=>e.cell_type===`code`&&z(e.source).trim()&&(!t||t.includes(n))?[{id:e.id,source:z(e.source)}]:[]);if(r.length){h.current=!0,m(!0),v(null),d.current.onChange?.(n);try{let t=n.metadata.kernelspec,i=await F(`POST`,`/api/notebooks/execute`,{source:e,cells:r,...t?.name?{kernel:t.name}:{}});y.current&&f.setQueryData(b,i)}catch(e){y.current&&v(e instanceof Error?e.message:`Notebook execution failed`)}finally{h.current=!1,y.current&&(m(!1),f.invalidateQueries({queryKey:b}))}}},w=(0,I.useRef)(C);return w.current=C,(0,I.useEffect)(()=>u?we(e,()=>{w.current()}):void 0,[u,e.session,e.path,e.root]),{supported:u,intelligenceSupported:u&&s(l.data?.protocol),run:C,interrupt:async()=>{try{await ui({source:e,action:`interrupt`})}catch(e){y.current&&v(e instanceof Error?e.message:`Interrupt failed`)}finally{f.invalidateQueries({queryKey:b})}},execution:S,busy:p||S?.state===`running`,error:_??(x.error instanceof Error?x.error.message:S?.error)}}var pi=(0,I.createContext)(null);function mi({source:e,environment:t,current:n,kernels:r,pending:i,onAction:a}){let[o,s]=(0,I.useState)(!1),[c,l]=(0,I.useState)(``),u=(0,I.useId)(),d=di(e,o),f=[...d.data?.environments??[]];t&&!f.some(e=>e.python===t.python)&&f.unshift(t);let p=e=>{s(!1),a(e)};return(0,L.jsxs)(bt,{open:o,onOpenChange:s,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,disabled:i,"aria-label":`Select Python environment`,title:t?.python??`Changing environments starts a fresh kernel`,className:`flex max-w-64 cursor-pointer items-center gap-1.5 rounded-sm px-2 py-1.5 text-xs text-fg-secondary hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`,children:[(0,L.jsx)(dn,{className:`size-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:t?.label??n?.display_name??`Select environment`})]})}),(0,L.jsxs)(vt,{align:`end`,className:`w-96 max-w-[calc(100vw-2rem)] p-3`,children:[(0,L.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:`Python environments on this host`}),(0,L.jsxs)(`div`,{className:`max-h-64 overflow-y-auto`,"aria-label":`Python environments`,children:[d.isLoading&&(0,L.jsx)(`p`,{role:`status`,className:`py-2 text-xs text-fg-muted`,children:`Looking for environments…`}),d.isError&&(0,L.jsx)(`p`,{role:`alert`,className:`py-2 text-xs text-danger`,children:`Couldn’t discover environments. You can enter a path below.`}),d.data&&!f.length&&(0,L.jsx)(`p`,{className:`py-2 text-xs text-fg-muted`,children:`No Python environments found. Enter a path below.`}),f.map(n=>(0,L.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>p({source:e,action:`select-python`,python:n.python}),className:`flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-2 text-left hover:bg-surface disabled:cursor-default disabled:opacity-40`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`text-xs text-fg`,children:n.label}),(0,L.jsx)(`p`,{className:`break-all text-xs text-fg-muted`,children:n.python}),(n.error||!n.ipykernel||!n.nbconvert)&&(0,L.jsx)(`p`,{className:`text-xs text-fg-secondary`,children:n.error?`Couldn’t inspect this Python`:n.ipykernel?`nbconvert not installed`:`ipykernel not installed`})]}),t?.python===n.python&&(0,L.jsx)(Ye,{className:`size-3.5 shrink-0 text-accent`})]},n.python)),r.length>0&&(0,L.jsx)(`p`,{className:`mb-1 mt-3 text-xs text-fg-muted`,children:`Registered Jupyter kernels`}),r.map(r=>(0,L.jsxs)(`button`,{type:`button`,disabled:i,className:`flex w-full cursor-pointer items-center justify-between rounded-sm px-2 py-2 text-left text-xs text-fg-secondary hover:bg-surface hover:text-fg`,onClick:()=>p({source:e,action:`select`,kernel:r.name}),children:[r.display_name,!t&&n?.name===r.name&&(0,L.jsx)(Ye,{className:`size-3.5`})]},r.name))]}),(0,L.jsxs)(`form`,{className:`mt-3 flex flex-col gap-2`,onSubmit:t=>{t.preventDefault(),c.trim()&&p({source:e,action:`select-python`,python:c.trim()})},children:[(0,L.jsx)(`label`,{htmlFor:u,className:`text-xs text-fg-secondary`,children:`Environment folder or Python executable`}),(0,L.jsx)(Ve,{id:u,value:c,onChange:e=>l(e.target.value),placeholder:`.venv, ~/miniforge3/envs/analysis, /path/to/python`,disabled:i}),(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Relative paths start beside this notebook. Switching starts fresh.`}),(0,L.jsx)(`button`,{type:`submit`,disabled:i||!c.trim(),className:`cursor-pointer self-end rounded-sm px-2 py-1.5 text-xs text-fg-secondary hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`,children:`Use path`})]})]})]})}var hi=`flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-sm px-2 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`;function gi({source:e,notebook:t,onSelect:r}){let a=(0,I.useRef)(r);a.current=r;let o=(0,I.useRef)(!0);(0,I.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let s=n(),u=c(s.data?.protocol),d=l(s.data?.protocol),f=ci(u),p=li(e,u),m=i(),[h,g]=(0,I.useState)(null),_=h!==null,[v,y]=(0,I.useState)(null);if(!u)return null;let b=t.metadata.kernelspec,x=p.data?.kernel??(typeof b?.name==`string`?b.name:``),S=f.data?.kernels??[],C=S.find(e=>e.name===x),w=p.data?.environment,ee=w&&!w.error?[!w.ipykernel&&`ipykernel`,!w.nbconvert&&`nbconvert`].filter(Boolean).join(` and `):``,T=p.data&&p.data.state!==`stopped`&&p.data.state!==`dead`,E=p.data?.state===`busy`||p.data?.state===`starting`,D=async t=>{g(t.action),y(null);try{let n=await ui(t);if(m.setQueryData([`notebook-kernel`,e],n),(t.action===`select-python`||t.action===`install-python`)&&(m.invalidateQueries({queryKey:[`notebook-environments`]}),o.current&&a.current({name:`python3`,display_name:`Python 3`,language:`python`})),t.action===`select`){let e=S.find(e=>e.name===t.kernel);e&&o.current&&a.current(e)}}catch(e){y(e instanceof Error?e.message:`Kernel operation failed`)}finally{g(null)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[E&&(0,L.jsxs)(`button`,{type:`button`,className:hi,disabled:_,onClick:()=>void D({source:e,action:`interrupt`}),children:[(0,L.jsx)(je,{className:`size-3.5`}),`Interrupt`]}),(0,L.jsx)(`span`,{className:`text-xs text-fg-muted`,role:`status`,children:_?h===`install-python`?`Installing…`:`Updating…`:p.data?.state===`dead`?`Kernel exited`:E?`Busy`:T?`Idle`:``}),d?(0,L.jsx)(mi,{source:e,environment:w,current:C,kernels:S,pending:_,onAction:D}):(0,L.jsxs)(Ze,{value:C?.name??``,disabled:_||!f.data?.available||S.length===0,onValueChange:t=>void D({source:e,action:`select`,kernel:t}),children:[(0,L.jsxs)(qe,{className:`h-7 max-w-52 gap-1.5 bg-transparent text-xs hover:bg-surface`,"aria-label":`Select kernel`,title:`Kernels stay alive until shut down. Changing kernels starts fresh.`,children:[(0,L.jsx)(dn,{className:`size-3.5 shrink-0`}),(0,L.jsx)(Ke,{placeholder:x?`${x} (not installed)`:`Select Kernel`})]}),(0,L.jsx)(Je,{children:S.map(e=>(0,L.jsx)(Xe,{value:e.name,detail:e.language,children:(0,L.jsx)(`span`,{children:e.display_name})},e.name))})]}),(0,L.jsxs)(Ne,{children:[(0,L.jsx)(Ie,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:hi,disabled:_,"aria-label":`Kernel actions`,children:(0,L.jsx)(Ee,{className:`size-3.5`})})}),(0,L.jsxs)(Te,{align:`end`,children:[(0,L.jsxs)(Se,{disabled:!C&&!w,onSelect:()=>void D({source:e,action:`restart`}),children:[(0,L.jsx)(at,{}),`Restart kernel`]}),(0,L.jsxs)(Se,{disabled:!T,onSelect:()=>void D({source:e,action:`shutdown`}),children:[(0,L.jsx)(Be,{}),`Shut down kernel`]})]})]})]}),ee&&(0,L.jsxs)(`div`,{className:`flex w-full flex-wrap items-center gap-2 px-2 text-xs text-fg-muted`,children:[(0,L.jsxs)(`span`,{className:`break-all`,children:[ee,` missing from `,w?.python,`.`]}),(0,L.jsxs)(`button`,{type:`button`,className:hi,disabled:_,onClick:()=>{w&&D({source:e,action:`install-python`,python:w.python})},children:[`Install `,ee]})]}),(v||p.data?.error||!d&&(f.data?.error||f.isError)||p.isError)&&(0,L.jsx)(`p`,{role:`alert`,className:`w-full px-2 text-xs text-danger`,children:v??p.data?.error??f.data?.error??`Couldn’t load notebook kernels`}),!d&&f.data&&!f.data.available&&!f.data.error&&(0,L.jsx)(`p`,{className:`w-full px-2 text-xs text-fg-muted`,children:`Install Jupyter and a language kernel on this host to run notebooks.`})]})}var _i=`flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-sm px-2 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`;function vi({notebook:e,source:t,onChange:r,onAdd:i,onRevealCell:a,onRun:o,onRunCopy:s,onRunSection:l,running:u=!1}){let[d,f]=(0,I.useState)(!1),p=n(),m=li(t,!!o&&c(p.data?.protocol)),h=u||m.data?.state===`busy`||m.data?.state===`starting`,g=m.data?.environment,_=g&&(!g.ipykernel||!g.nbconvert),v=$r(e),y=e.cells.some(e=>e.cell_type===`code`&&((e.outputs?.length??0)>0||e.execution_count!=null));return(0,L.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1 bg-ground px-3 py-2`,role:`toolbar`,"aria-label":`Notebook`,children:[r&&(0,L.jsxs)(ft,{label:`Add notebook cells`,children:[(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:e.cells.length>=2e3,onClick:()=>i(`code`),"aria-label":`Add code cell`,children:[(0,L.jsx)(We,{className:`size-3.5`}),`Code`]}),(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:e.cells.length>=2e3,onClick:()=>i(`markdown`),"aria-label":`Add Markdown cell`,children:[(0,L.jsx)(We,{className:`size-3.5`}),`Markdown`]})]}),(0,L.jsxs)(ft,{label:`Notebook actions`,className:`flex-wrap !rounded-[var(--ui-radius)]`,children:[o&&(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:h||_,onClick:o,children:[(0,L.jsx)(Pe,{className:`size-3.5`}),h?`Running…`:`Run All`]}),r&&(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:!y,onClick:()=>r(Qr(e)),children:[(0,L.jsx)(Ue,{className:`size-3.5`}),`Clear All Outputs`]}),(0,L.jsxs)(bt,{open:d,onOpenChange:f,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:v.length===0,children:[(0,L.jsx)(fn,{className:`size-3.5`}),`Outline`]})}),(0,L.jsx)(vt,{align:`start`,className:`max-h-72 w-72 overflow-y-auto p-1`,children:(0,L.jsx)(`nav`,{"aria-label":`Notebook outline`,className:`flex flex-col`,children:v.map(e=>(0,L.jsxs)(`div`,{className:`group/outline flex items-center`,style:{paddingLeft:`calc(var(--spacing) * ${Math.max(0,e.level-1)*3})`},children:[(0,L.jsxs)(`button`,{type:`button`,className:`${_i} min-w-0 flex-1 text-left`,onClick:()=>{a(e.index),f(!1)},children:[(0,L.jsx)(`span`,{className:`w-5 shrink-0 text-fg-muted`,children:e.index+1}),(0,L.jsx)(`span`,{className:`truncate`,children:e.label})]}),!!e.level&&l&&(0,L.jsx)(`button`,{type:`button`,disabled:h,title:`Run Section`,"aria-label":`Run section ${e.label}`,className:`${_i} opacity-0 group-hover/outline:opacity-100 focus:opacity-100 pointer-coarse:opacity-100`,onClick:()=>{l(e.index),f(!1)},children:(0,L.jsx)(Pe,{className:`size-3.5`})})]},e.index))})})]}),r&&(0,L.jsxs)(Ne,{children:[(0,L.jsx)(Ie,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:_i,"aria-label":`More notebook actions`,children:(0,L.jsx)(Ee,{className:`size-3.5`})})}),(0,L.jsxs)(Te,{align:`start`,children:[s&&(0,L.jsx)(Se,{disabled:h,onSelect:s,children:`Run to Executed Copy`}),(0,L.jsxs)(Se,{disabled:e.cells.length>=2e3,onSelect:()=>i(`raw`),children:[(0,L.jsx)(We,{}),`Add raw cell`]})]})]})]}),r&&o&&(0,L.jsx)(gi,{source:t,notebook:e,onSelect:t=>r({...e,metadata:{...e.metadata,kernelspec:t}})},JSON.stringify(t))]})}function yi({code:e,onRun:t,busy:n,index:r,count:i,canMerge:a,onOperation:o}){let s=(e,t,n,r=!1)=>(0,L.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,L.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center opacity-0 focus-within:opacity-100 group-hover/cell:opacity-100 pointer-coarse:opacity-100`,children:[e&&t&&(0,L.jsxs)(L.Fragment,{children:[s(`Run Cell`,(0,L.jsx)(Pe,{className:`size-3.5`}),()=>t(`cell`),n),s(`Run Above`,(0,L.jsx)(ln,{className:`size-3.5`}),()=>t(`above`),n||r===0),s(`Run Cell and Below`,(0,L.jsx)(cn,{className:`size-3.5`}),()=>t(`below`),n)]}),s(`Insert cell below`,(0,L.jsx)(We,{className:`size-3.5`}),()=>o(`insert`),i>=2e3),s(`Duplicate cell`,(0,L.jsx)(it,{className:`size-3.5`}),()=>o(`duplicate`),i>=2e3),s(`Merge with next cell`,(0,L.jsx)(un,{className:`size-3.5`}),()=>o(`merge`),!a),s(`Move cell up`,(0,L.jsx)(Me,{className:`size-3.5`}),()=>o(`up`),r===0),s(`Move cell down`,(0,L.jsx)(Fe,{className:`size-3.5`}),()=>o(`down`),r===i-1),s(`Delete cell`,(0,L.jsx)(Ue,{className:`size-3.5`}),()=>o(`delete`))]})}function bi(e,t){let n=async(n,r,i)=>{let a=e.getValue();if(a.length>65536||i.isCancellationRequested)return null;let o=e.getVersionId();try{let s=await F(`POST`,`/api/notebooks/intelligence`,{source:t,kind:n,code:a,cursor:[...a.slice(0,e.getOffsetAt(r))].length});return i.isCancellationRequested||e.isDisposed()||o!==e.getVersionId()?null:{response:s,code:a}}catch{return null}},r=()=>{let t=e.getLanguageId();return t===`markdown`||t===`plaintext`?[]:[te.registerCompletionItemProvider(t,{triggerCharacters:[`.`],async provideCompletionItems(t,r,i,a){if(t!==e)return{suggestions:[]};let o=await n(`complete`,r,a);if(!o)return{suggestions:[]};let{response:s,code:c}=o,l=e.getPositionAt([...c].slice(0,s.start).join(``).length),u=e.getPositionAt([...c].slice(0,s.end).join(``).length),d=new j(l.lineNumber,l.column,u.lineNumber,u.column);return{suggestions:s.matches.map(e=>({label:e,insertText:e,kind:te.CompletionItemKind.Text,range:d}))}}}),te.registerHoverProvider(t,{async provideHover(t,r,i){if(t!==e)return null;let a=await n(`inspect`,r,i);return a?.response.documentation?{contents:[{value:a.response.documentation.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``).replace(/[\\`*_{}[\]()#+.!<>-]/g,`\\$&`),isTrusted:!1,supportHtml:!1}]}:null}})]},i=r(),a=e.onDidChangeLanguage(()=>{i.forEach(e=>e.dispose()),i=r()});return{dispose(){a.dispose(),i.forEach(e=>e.dispose())}}}function xi({value:e,language:t,label:n,focus:r,onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c,match:l}){let u=C(),d=Math.round(u.editorFontSize*1.5),f=(0,I.useContext)(pi),[p,m]=(0,I.useState)(null);(0,I.useEffect)(()=>{if(!p||!f?.intelligence)return;let e=bi(p,{session:f.session,path:f.path,...f.root?{root:f.root}:{}});return()=>e.dispose()},[p,f?.intelligence,f?.session,f?.path,f?.root]);let h=(0,I.useRef)(null),g=(0,I.useRef)(null),_=(0,I.useRef)(null),v=(0,I.useRef)(!1),y=(0,I.useRef)(null),b=(0,I.useRef)({onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c});b.current={onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c};let x=(0,I.useRef)(r);x.current=r;let S=(0,I.useRef)(l);S.current=l;let w=e=>{let t=e.getModel(),n=S.current;if(!t||!n)return;let r=t.getPositionAt(n.start),i=t.getPositionAt(n.end);e.setSelection(new j(r.lineNumber,r.column,i.lineNumber,i.column)),e.revealPositionInCenter(r)};(0,I.useEffect)(()=>{g.current&&w(g.current)},[l]);let[ee,T]=(0,I.useState)(!1),[E,D]=(0,I.useState)(!1),[O,k]=(0,I.useState)(Math.max(64,e.split(`
|
|
6
|
+
`).length*d+24));return(0,I.useEffect)(()=>{let e=new IntersectionObserver(([e])=>T(!!e?.isIntersecting),{rootMargin:`600px`});return h.current&&e.observe(h.current),()=>e.disconnect()},[]),(0,I.useEffect)(()=>()=>{_.current?.dispose()},[]),(0,I.useEffect)(()=>{let n=_.current;n&&n.getValue()!==e&&(v.current=!0,n.pushEditOperations([],[{range:n.getFullModelRange(),text:e}],()=>null),v.current=!1),n&&N.setModelLanguage(n,t)},[e,t]),(0,I.useEffect)(()=>{r&&g.current?.focus()},[r]),(0,L.jsxs)(`div`,{ref:h,style:{height:O},className:`relative min-w-0 rounded-md`,onWheelCapture:e=>{!e.shiftKey&&Math.abs(e.deltaY)>=Math.abs(e.deltaX)&&!e.target.closest(`.overflowingContentWidgets,.overflowingOverlayWidgets,.contentWidgets,.overlayWidgets`)&&e.stopPropagation()},children:[!p&&(0,L.jsx)(`pre`,{"aria-hidden":`true`,className:`absolute inset-0 overflow-hidden px-2 py-3 font-mono text-fg`,style:{fontSize:u.editorFontSize,lineHeight:`${d}px`,whiteSpace:u.editorWordWrap?`pre-wrap`:`pre`},children:e}),(ee||r||E)&&(0,L.jsx)(Ot,{loading:null,theme:`puddle`,defaultValue:e,defaultLanguage:t,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{if(_.current){let t=e.getModel();e.setModel(_.current),t!==_.current&&t?.dispose()}else _.current=e.getModel();g.current=e,m(e.getModel()),ir(e,{onSave:()=>b.current.onSave()}),y.current&&e.restoreViewState(y.current),e.setScrollTop(0);let t=!1,n=()=>{if(t||!h.current||!h.current.clientWidth)return;t=!0,e.layout({width:h.current.clientWidth,height:h.current.clientHeight});let n=Math.max(64,e.getContentHeight());h.current.style.height=`${n}px`,e.layout({width:h.current.clientWidth,height:n}),k(n),t=!1},r=e.onDidContentSizeChange(n),i=new ResizeObserver(n);i.observe(h.current);let a=e.onDidFocusEditorWidget(()=>D(!0)),o=e.onDidBlurEditorWidget(()=>D(!1)),s=e.onDidChangeModelContent(()=>{v.current||b.current.onChange(e.getValue())}),c=e.onDidScrollChange(()=>{y.current=e.saveViewState()}),l=e.onDidChangeCursorSelection(()=>{y.current=e.saveViewState()});e.addCommand(M.CtrlCmd|P.Enter,()=>b.current.onExecute(`stay`)),e.addCommand(M.Shift|P.Enter,()=>b.current.onExecute(`next`)),e.addCommand(M.Alt|P.Enter,()=>b.current.onExecute(`insert`)),e.addCommand(P.Escape,()=>b.current.onEscape(),`!suggestWidgetVisible && !findWidgetVisible`),e.addCommand(M.CtrlCmd|M.Shift|P.Minus,()=>{let t=e.getPosition();t&&b.current.onSplit(e.getModel().getOffsetAt(t))}),e.onDidDispose(()=>{r.dispose(),i.disconnect(),a.dispose(),o.dispose(),c.dispose(),l.dispose(),s.dispose(),g.current=null,m(null)}),n(),w(e),x.current&&e.focus()},beforeMount:()=>{_.current&&N.setModelLanguage(_.current,t)},options:{ariaLabel:n,automaticLayout:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim(),fontSize:u.editorFontSize,lineHeight:d,...Nn(u.editorTabSize),wordWrap:u.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,folding:!0,lineNumbers:`off`,lineDecorationsWidth:8,lineNumbersMinChars:3,scrollBeyondLastLine:!1,fixedOverflowWidgets:!0,padding:{top:12,bottom:12},renderLineHighlight:`none`,occurrencesHighlight:`off`,scrollbar:{alwaysConsumeMouseWheel:!1,vertical:`hidden`}},onChange:()=>{g.current&&(y.current=g.current.saveViewState())}})]})}function Si({language:e,onChange:t}){let[n,r]=(0,I.useState)(!1),i=[`markdown`,`raw`,...te.getLanguages().map(e=>e.id).filter(e=>e!==`markdown`).sort()];return(0,L.jsxs)(bt,{open:n,onOpenChange:r,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,"aria-label":`Cell language: ${e}`,className:`flex cursor-pointer items-center gap-1 font-mono text-xs text-fg-muted hover:text-fg`,children:[e,(0,L.jsx)(Qe,{className:`size-3`})]})}),(0,L.jsxs)(vt,{align:`start`,className:`w-56 p-0`,children:[(0,L.jsxs)(_t,{children:[(0,L.jsx)(pt,{placeholder:`Find a language…`}),(0,L.jsxs)(gt,{children:[(0,L.jsx)(ht,{children:`No matching languages`}),i.map(e=>(0,L.jsx)(mt,{onSelect:()=>{t(e),r(!1)},children:e},e))]})]}),(0,L.jsx)(`p`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Code languages set highlighting. Execution uses the notebook kernel.`})]})]})}async function Ci(e,t,n){let r=`path=${encodeURIComponent(t)}${se(n)}`,i=g();return i?Ti(i,async()=>{if(g()!==i)throw Error(`Preview host changed`);let t=p.parse(await F(`GET`,`/api/worktrees/${e}/preview-asset?${r}`));return new Blob([Uint8Array.from(atob(t.data),e=>e.charCodeAt(0))],{type:t.mime})}):(await ne(`GET`,`/api/worktrees/${e}/media?${r}`)).blob()}var wi=new WeakMap;async function Ti(e,t){let n=wi.get(e);if(n||(n={active:0,waiting:[]},wi.set(e,n)),n.waiting.length>=128)throw Error(`Too many preview assets`);n.active>=2?await new Promise(e=>n.waiting.push(e)):n.active+=1;try{return await t()}finally{let e=n.waiting.shift();e?e():--n.active}}function Ei(e,t,n,r,i){(0,I.useEffect)(()=>{let t=e.current;if(!t)return;let a=!1,o=[],s=async e=>{try{let t=await Ci(n,e,i);if(a)return null;let r=URL.createObjectURL(t);return o.push(r),r}catch{return null}};for(let e of t.querySelectorAll(`img[src], source[src]`)){let t=ut(r,e.getAttribute(`src`)??``);t&&(e.removeAttribute(`src`),s(t).then(t=>{!a&&t&&e.setAttribute(`src`,t)}))}for(let e of t.querySelectorAll(`img[srcset], source[srcset]`)){let t=dt(e.getAttribute(`srcset`)??``),n=t.map(({ref:e})=>ut(r,e));n.some(e=>e!==null)&&(e.removeAttribute(`srcset`),Promise.all(t.map(async(e,t)=>{let r=n[t];if(!r)return e;let i=await s(r);return i?{...e,ref:i}:null})).then(t=>{if(a)return;let n=t.filter(e=>e!==null);n.length>0&&e.setAttribute(`srcset`,st(n))}))}return()=>{a=!0;for(let e of o)URL.revokeObjectURL(e)}},[t,e,n,r,i])}function Di(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);try{r.href=n,r.download=t,document.body.appendChild(r),r.click()}finally{r.remove(),setTimeout(()=>URL.revokeObjectURL(n),6e4)}}var Oi=(0,I.lazy)(()=>E(()=>import(`./NotebookWidget-D6vzMCnH.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])));function ki(e,t){return!t||typeof t!=`object`?e:e.replace(/attachment:([^\s"')>]+)/g,(e,n)=>{try{let r=t[decodeURIComponent(n)];if(!r||typeof r!=`object`)return e;for(let e of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let t=z(r[e]).replace(/\s/g,``);if(t&&/^[A-Za-z0-9+/]*={0,2}$/.test(t))return`data:${e};base64,${t}`}}catch{}return e})}function Ai({text:e,markdown:t=!1,attachments:n}){let r=(0,I.useContext)(pi),i=(0,I.useRef)(null),a=(0,I.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o=(0,I.useSyncExternalStore)(D,O,O),s=(0,I.useMemo)(()=>k.sanitize(t?Kt(ki(e,n),a):e,{FORBID_TAGS:[`style`,`iframe`,`form`,`input`,`button`],...t?{}:{FORBID_ATTR:[`style`]}}),[e,t,n,a]),c=(0,I.useMemo)(()=>({__html:s}),[s,o]);return Ei(i,s,r?.session??``,r?.path??``,r?.root),(0,I.useEffect)(()=>{let e=new AbortController;return i.current&&t&&sn(i.current,o,e.signal),()=>e.abort()},[s,o,t]),(0,L.jsx)(`div`,{ref:i,className:`md-preview overflow-x-auto text-sm`,dangerouslySetInnerHTML:c,onClick:e=>{let t=e.target.closest(`a`);if(!t)return;let n=t.getAttribute(`href`)??``;if(/^https?:/i.test(n)){e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`#`)){e.preventDefault();try{i.current?.querySelector(`#${CSS.escape(decodeURIComponent(n.slice(1)))}`)?.scrollIntoView({block:`nearest`})}catch{}return}let a=r?ut(r.path,n):null;a&&(e.preventDefault(),(e.metaKey||e.ctrlKey)&&r?.onOpenFile?.(a))}})}var ji=`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-surface hover:text-fg`;function Mi({output:e}){let t=null;for(let n of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let r=z(e.data?.[n]).replace(/\s/g,``);if(r&&/^[A-Za-z0-9+/]*={0,2}$/.test(r)){try{t={src:`data:${n};base64,${r}`,blob:new Blob([Uint8Array.from(atob(r),e=>e.charCodeAt(0))],{type:n}),extension:n.split(`/`)[1]}}catch{}if(t)break}}let n=z(e.data?.[`image/svg+xml`]),r=n?k.sanitize(n,{USE_PROFILES:{svg:!0,svgFilters:!0},FORBID_TAGS:[`style`,`foreignObject`,`image`,`use`],FORBID_ATTR:[`style`,`href`,`xlink:href`]}):``,i=z(e.data?.[`text/html`]),a=z(e.data?.[`text/markdown`]),o=e.data?.[`application/json`],s=e.data?.[`application/vnd.jupyter.widget-view+json`],c=s&&typeof s==`object`&&`model_id`in s&&typeof s.model_id==`string`?s.model_id:null,l=Xr(e)||(o===void 0?``:JSON.stringify(o,null,2))||`This output format cannot be displayed.`;return(0,L.jsxs)(`div`,{className:`group/output relative`,children:[(0,L.jsxs)(`div`,{className:`absolute right-1 top-0 z-10 flex gap-1 bg-ground opacity-0 group-hover/output:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100`,children:[(0,L.jsx)(`button`,{type:`button`,title:`Copy output`,"aria-label":`Copy output`,className:ji,onClick:()=>{navigator.clipboard.writeText(l).catch(()=>ze.error(`Could not copy output`))},children:(0,L.jsx)(it,{className:`size-3.5`})}),(t||r)&&(0,L.jsx)(`button`,{type:`button`,title:`Save image`,"aria-label":`Save image`,className:ji,onClick:()=>Di(t?.blob??new Blob([r],{type:`image/svg+xml`}),`notebook-output.${t?.extension??`svg`}`),children:(0,L.jsx)(Ce,{className:`size-3.5`})})]}),c?(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Loading widget…`}),children:(0,L.jsx)(Oi,{modelId:c,fallback:Xr(e)})}):t?(0,L.jsx)(`img`,{src:t.src,alt:`Notebook output`,className:`max-w-full`}):r?(0,L.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):i?(0,L.jsx)(Ai,{text:i}):a?(0,L.jsx)(Ai,{text:a,markdown:!0}):(0,L.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm ${e.output_type===`error`?`text-danger`:`text-fg-secondary`}`,children:l})]})}function Ni({source:e,execution:t,onInterrupt:n}){let r=(0,I.useRef)(null),i=(0,I.useRef)(!1),[a,o]=(0,I.useState)(``),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(null),d=t.input;return(0,I.useEffect)(()=>{r.current?.focus({preventScroll:!0}),r.current?.scrollIntoView({block:`nearest`})},[]),d?(0,L.jsxs)(`form`,{className:`mt-2 font-mono text-sm text-fg-secondary`,"aria-busy":s,onSubmit:n=>{n.preventDefault(),!i.current&&(i.current=!0,c(!0),u(null),F(`POST`,`/api/notebooks/input`,{source:e,run_id:t.id,input_id:d.id,value:a}).then(()=>{d.password&&o(``)}).catch(e=>{u(e instanceof Error?e.message:`Input failed`),i.current=!1,c(!1)}))},children:[(0,L.jsxs)(`label`,{className:`flex min-w-0 flex-wrap items-baseline`,children:[(0,L.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:d.prompt}),(0,L.jsx)(`input`,{ref:r,"aria-label":d.prompt||`Kernel input`,type:d.password?`password`:`text`,value:a,readOnly:s,maxLength:65536,autoComplete:`off`,autoCapitalize:`off`,spellCheck:!1,onChange:e=>o(e.target.value),onKeyDown:e=>{n&&e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`c`&&e.currentTarget.selectionStart===e.currentTarget.selectionEnd&&(e.preventDefault(),e.stopPropagation(),n())},className:`min-w-16 flex-1 cursor-text bg-transparent p-0 text-fg outline-none read-only:opacity-60`})]}),l&&(0,L.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-danger`,children:l})]}):null}var Pi=`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`;function Fi({cell:e,notebook:t,index:n,active:r,editing:i,selected:a,editable:o,onSelect:s,onEdit:c,onSource:l,onLanguage:u,onExecute:d,onRun:f,onInterrupt:p,onOperation:m,onSplit:h,onSave:g,execution:_,inputExecution:v,inputSource:y,match:b,onToggleSection:x,sectionCollapsed:S}){let C=(0,I.useRef)(null),[w,ee]=(0,I.useState)(!1),T=y?v?.input:void 0;(0,I.useEffect)(()=>{(b?.output||T)&&ee(!1)},[b,T]);let E=w&&!T,D=e.cell_type===`code`,O=z(e.source),k=_?.state===`running`||_?.state===`queued`,A=qr(e,t),j=(e,t,n,r=!1)=>(0,L.jsx)(`button`,{type:`button`,className:Pi,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,L.jsxs)(`section`,{ref:C,"data-notebook-cell":n,"data-cell-id":e.id,tabIndex:r?0:-1,"aria-label":`Cell ${n+1}`,"aria-current":r||void 0,className:`group/cell relative min-w-0 outline-none`,onMouseDown:e=>{e.shiftKey&&!e.target.closest(`.monaco-editor,input,button`)&&e.preventDefault()},onFocus:()=>{r||s(!1)},onClick:e=>{if((e.metaKey||e.ctrlKey)&&D&&!e.target.closest(`.monaco-editor,a,button,input`)){e.preventDefault(),f?.(`cell`);return}e.target.closest(`button,input,[role=option]`)||s(e.shiftKey&&!e.target.closest(`.monaco-editor`))},children:[(0,L.jsx)(`div`,{className:`absolute -left-10 top-9 w-9 text-center font-mono text-xs text-fg-muted`,children:(0,L.jsxs)(`button`,{type:`button`,className:`${Pi} group/run relative w-full`,disabled:!o||D&&(!f||!k&&!O.trim()),title:D?k?`Interrupt execution`:`Run Cell (⌘/Ctrl+Enter)`:i?`Show rendered cell`:`Edit cell source`,"aria-label":D?k?`Interrupt execution`:`Run Cell`:i?`Show rendered cell`:`Edit cell source`,onClick:()=>{D?k?p?.():f?.(`cell`):c(!i)},children:[(0,L.jsx)(`span`,{className:D&&f?`group-hover/run:invisible group-focus-visible/run:invisible`:``,children:D?`[${k?`*`:e.execution_count??` `}]`:i?`[›]`:`[ ]`}),D&&f&&(k?(0,L.jsx)(je,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}):(0,L.jsx)(Pe,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}))]})}),(0,L.jsxs)(`div`,{className:`mb-2 flex min-h-7 items-center gap-2 text-xs text-fg-muted`,children:[x&&j(S?`Expand section`:`Fold section`,S?(0,L.jsx)(He,{className:`size-3`}):(0,L.jsx)(Qe,{className:`size-3`}),x),o?(0,L.jsx)(Si,{language:e.cell_type===`raw`?`raw`:A,onChange:u}):(0,L.jsx)(`span`,{className:`font-mono`,children:e.cell_type===`raw`?`raw`:A}),_&&(0,L.jsxs)(`span`,{role:`status`,children:[_.state,_.elapsed_ms===void 0?``:` · ${(_.elapsed_ms/1e3).toFixed(1)}s`]}),_&&_.source!==O&&(0,L.jsx)(`span`,{title:`The source changed after this execution`,children:`Source changed`}),o&&(0,L.jsx)(yi,{code:D,onRun:f,busy:k,index:n,count:t.cells.length,canMerge:e.cell_type===t.cells[n+1]?.cell_type,onOperation:m})]}),(0,L.jsx)(`div`,{className:D||i||e.cell_type===`raw`?`rounded-[var(--ui-radius)] p-3 ${a?`bg-elevated`:`bg-surface`}`:void 0,children:o&&(D||i)?(0,L.jsx)(xi,{value:O,match:b&&!b.output?b:void 0,language:A,label:`Cell ${n+1} source`,focus:r&&i&&!b,onChange:e=>{e!==O&&l(e)},onExecute:d,onEscape:()=>{c(!1),C.current?.focus()},onSave:g,onSplit:h}):e.cell_type===`markdown`?(0,L.jsx)(`div`,{onDoubleClick:()=>{o&&c(!0)},className:o?`cursor-text`:``,children:(0,L.jsx)(Ai,{text:O,markdown:!0,attachments:e.attachments})}):(0,L.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm`,onDoubleClick:()=>{o&&c(!0)},children:O})}),(!!e.outputs?.length||T)&&(0,L.jsxs)(`div`,{className:`mt-2`,role:`group`,"aria-label":`Cell ${n+1} output`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[j(E?`Expand output`:`Collapse output`,E?(0,L.jsx)(He,{className:`size-3`}):(0,L.jsx)(Qe,{className:`size-3`}),()=>ee(!w),!!T),(0,L.jsx)(`span`,{children:`Output`}),o&&j(`Clear cell output`,(0,L.jsx)(Ue,{className:`size-3`}),()=>m(`clear`))]}),!E&&(0,L.jsxs)(`div`,{className:`mt-2 max-h-96 overflow-auto rounded-[var(--ui-radius)] bg-surface p-3`,children:[e.outputs?.map((e,t)=>(0,L.jsx)(`div`,{className:`mt-2 first:mt-0`,children:(0,L.jsx)(Mi,{output:e})},t)),T&&v&&y&&(0,L.jsx)(Ni,{source:y,execution:v,onInterrupt:p},`${v.id}:${T.id}`)]})]})]})}var Ii=new Rt;function Li(e,t,n){let r=Ii.get(n),i=!!r,a=e.scrollTop,o=()=>e.clientHeight>0&&e.clientWidth>0,s=()=>{if(!o())return;let r=e.getBoundingClientRect().top,i=[...t.querySelectorAll(`[data-cell-id]`)].find(e=>e.getBoundingClientRect().bottom>r);Ii.set(n,{cell:i?.dataset.cellId,offset:i?i.getBoundingClientRect().top-r:0,top:e.scrollTop,left:e.scrollLeft})},c=()=>{if(!i||!r||!o())return;let n=r.cell?t.querySelector(`[data-cell-id="${CSS.escape(r.cell)}"]`):null;e.scrollTop=n?e.scrollTop+n.getBoundingClientRect().top-e.getBoundingClientRect().top-r.offset:r.top,e.scrollLeft=r.left,a=e.scrollTop},l=()=>{i=!1},u=()=>{e.scrollTop!==a&&(i=!1),i||s()};c();let d=new ResizeObserver(c);d.observe(e),d.observe(t),e.addEventListener(`scroll`,u,{passive:!0});let f=[`wheel`,`touchstart`,`pointerdown`,`keydown`];for(let t of f)e.addEventListener(t,l,{passive:!0});return()=>{i||s(),d.disconnect(),e.removeEventListener(`scroll`,u);for(let t of f)e.removeEventListener(t,l)}}function Ri({text:e,session:t,path:n,root:r,onChange:i,onRun:a,running:o,onUndo:s,onRedo:c,onOpenFile:l,focused:u=!0}){let d=(0,I.useMemo)(()=>{try{return{notebook:Kr(Wr(e)),error:null}}catch(e){return{notebook:null,error:e instanceof Error?e.message:`Invalid notebook`}}},[e]),[f,p]=(0,I.useState)([]),[m,h]=(0,I.useState)(null),g=(0,I.useRef)(!0),[_,v]=(0,I.useState)(null),[y,b]=(0,I.useState)(null),C=(0,I.useRef)(null),[w,ee]=(0,I.useState)([]),T=(0,I.useRef)(null),E=(0,I.useRef)(null),D=(0,I.useRef)(null),O=Lt(`notebook`,[t,r,n]),k=d.notebook!==null;(0,I.useLayoutEffect)(()=>{if(!(!T.current||!E.current||!k))return Li(T.current,E.current,O)},[O,k]),(0,I.useLayoutEffect)(()=>{if(!D.current)return;let e=E.current?.querySelector(`[data-cell-id="${CSS.escape(D.current)}"]`);e&&(e.scrollIntoView({block:`nearest`}),g.current&&e.focus({preventScroll:!0}),g.current=!0,D.current=null)});let A=e=>i?.(`${JSON.stringify(e,null,1)}\n`),j=d.notebook,te=(0,I.useMemo)(()=>({session:t,path:n,...r===void 0?{}:{root:r}}),[t,n,r]),M=fi(te,j,i?A:void 0,!!a),N=x(te,j,i?A:void 0,!!a),P=M.execution?.input?M.execution.cells.find(e=>e.state===`running`)?.id:void 0;if((0,I.useLayoutEffect)(()=>{if(!j||!P||!f.length)return;let e=j.cells.findIndex(e=>e.id===P),t=f.filter(t=>{let n=j.cells.findIndex(e=>e.id===t);return n<0||!ei(j,n).includes(e)});t.length!==f.length&&p(t)},[j,P,f]),!j)return(0,L.jsx)(`p`,{className:`p-6 text-sm text-danger`,role:`alert`,children:d.error});let F=(e,t=!1)=>{let n=C.current??_??e,r=j.cells.findIndex(e=>e.id===n),i=j.cells.findIndex(t=>t.id===e);ee(t?j.cells.slice(Math.min(r,i),Math.max(r,i)+1).map(e=>e.id):[e]),t||(C.current=e),v(e)},ne=(e,t=!1,n=!1)=>{F(e,n),b(t?e:null),D.current=e},re=$r(j),ie=new Set(j.cells.flatMap((e,t)=>f.includes(e.id)?ei(j,t).slice(1):[])),{add:ae,replace:oe,execute:se,operation:ce,keyDown:le}=ri({notebook:j,active:_,selected:w,update:A,choose:ne,setEditing:b,run:M.run,onUndo:s,onRedo:c});return(0,L.jsx)(S.Provider,{value:N,children:(0,L.jsx)(pi.Provider,{value:{...te,onOpenFile:l,intelligence:M.intelligenceSupported},children:(0,L.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-ground`,onKeyDown:i?le:void 0,onCopy:e=>{i&&ii(e,`copy`,j,w,A)},onCut:e=>{i&&ii(e,`cut`,j,w,A)},onPaste:e=>{i&&ii(e,`paste`,j,w,A)},children:[(0,L.jsx)(si,{notebook:j,focused:u,onChange:i?A:void 0,onReveal:e=>{h(e),e&&(p([]),v(e.id),e.output||b(e.id),D.current=e.id,g.current=!1)}}),(0,L.jsx)(vi,{notebook:j,source:{session:t,path:n,...r===void 0?{}:{root:r}},onChange:i?A:void 0,onAdd:ae,onRun:M.supported?()=>{M.run()}:a,onRunCopy:M.supported?a:void 0,running:o||M.busy,onRevealCell:e=>{p([]),ne(j.cells[e].id)},onRunSection:M.supported?e=>{M.run(ei(j,e))}:void 0}),(0,L.jsx)(`div`,{ref:T,className:`min-h-0 flex-1 overflow-auto bg-ground text-fg`,children:(0,L.jsxs)(`div`,{ref:E,className:`mx-auto flex max-w-4xl flex-col gap-7 py-6 pr-6 pl-14`,children:[(0,L.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[j.cells.length,` cells`]}),N.saveWarning&&(0,L.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:N.saveWarning}),M.error&&(0,L.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:M.error}),j.cells.map((e,a)=>ie.has(a)?null:(0,L.jsx)(Fi,{cell:e,match:m&&m.id===e.id?m:void 0,sectionCollapsed:f.includes(e.id),onToggleSection:re[a]?.level?()=>p(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]):void 0,notebook:j,index:a,active:_===e.id,editing:y===e.id,selected:w.length>1&&w.includes(e.id),editable:!!i,onSelect:t=>F(e.id,t),onEdit:t=>{v(e.id),b(t?e.id:null)},onSource:e=>A(Gr(j,a,e)),onLanguage:t=>oe(a,Jr(e,t)),onInterrupt:()=>{M.interrupt()},execution:M.execution?.cells.find(t=>t.id===e.id)??ni(e),inputExecution:P===e.id?M.execution??void 0:void 0,inputSource:te,onRun:M.supported?e=>{M.run(j.cells.flatMap((t,n)=>(e===`cell`?n===a:e===`above`?n<a:n>=a)?[n]:[]))}:void 0,onExecute:e=>se(a,e),onOperation:e=>ce(a,e),onSave:()=>{Oe(De(t,n,r))},onSplit:t=>{if(j.cells.length>=2e3)return;let n=z(e.source),r={...Yr(e.cell_type),source:n.slice(t)},i=[...j.cells];i.splice(a,1,{...e,source:n.slice(0,t)},r),A({...j,cells:i}),ne(r.id,!0)}},e.id)),i&&(0,L.jsx)(`div`,{className:`flex gap-3`,children:[`code`,`markdown`,`raw`].map(e=>(0,L.jsxs)(`button`,{disabled:j.cells.length>=2e3,className:`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40 flex items-center gap-1.5 text-xs`,onClick:()=>ae(e,j.cells.length),children:[(0,L.jsx)(We,{className:`size-3.5`}),e===`code`?`Code`:e===`markdown`?`Markdown`:`Raw`,` cell`]},e))})]})})]})})})}var zi=0;function Bi(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return!e.textContent||t?.closest(`script, style, noscript, [hidden], [aria-hidden="true"]`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),n=[],r=``,i;for(;i=t.nextNode();){let e=i.textContent??``,t=r.length;r+=e,n.push({node:i,start:t,end:r.length})}return{text:r,nodes:n}}function Vi(e,t){let n=t.find(t=>t.end>e.start),r=t.findLast(t=>t.start<e.end);if(!n||!r)return null;let i=document.createRange();return i.setStart(n.node,e.start-n.start),i.setEnd(r.node,e.end-r.start),i}var Hi=class{root;matchName=`puddle-find-${++zi}-match`;activeName=`puddle-find-${zi}-active`;style;signature=``;ranges=[];index=-1;limited=!1;constructor(e){this.root=e,this.style=document.createElement(`style`),this.style.textContent=`
|
|
7
|
+
::highlight(${this.matchName}) { background: var(--selection); }
|
|
8
|
+
::highlight(${this.activeName}) { background: var(--accent); color: var(--action-ink); }
|
|
9
|
+
`,document.head.appendChild(this.style)}find(e,t,n){let r=JSON.stringify([e,t]);if(r!==this.signature||n===`reset`){this.signature=r;let n=Bi(this.root),i=nt(n.text,e,t);if(this.ranges=i.matches.map(e=>Vi(e,n.nodes)).filter(e=>e!==null),this.limited=i.limited,this.index=this.ranges.length>0?0:-1,i.invalid)return this.clearHighlights(),{index:-1,count:0,invalid:!0}}else this.ranges.length>0&&(this.index=n===`previous`?(this.index-1+this.ranges.length)%this.ranges.length:(this.index+1)%this.ranges.length);return this.paint(),{index:this.index,count:this.ranges.length,limited:this.limited}}clear(){this.signature=``,this.ranges=[],this.index=-1,this.limited=!1,this.clearHighlights()}dispose(){this.clear(),this.style.remove()}clearHighlights(){CSS.highlights.delete(this.matchName),CSS.highlights.delete(this.activeName)}paint(){if(this.clearHighlights(),this.ranges.length===0)return;CSS.highlights.set(this.matchName,new Highlight(...this.ranges));let e=this.ranges[this.index];e&&(CSS.highlights.set(this.activeName,new Highlight(e)),e.startContainer.parentElement?.scrollIntoView({block:`center`,inline:`nearest`}))}};k.addHook(`afterSanitizeAttributes`,e=>{e.tagName===`A`&&/^https?:/i.test(e.getAttribute(`href`)??``)&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});function Ui({session:e,path:t,text:n,root:r,scrollDriver:i=!1,scrollReceiver:a=!1,scrollChannel:o=`profile`,focused:s=!0,onRevealSource:c,onOpenFile:l,mobile:u=!1}){let d=Lt(`markdown`,[e,r,t]),f=(0,I.useId)().replace(/[^A-Za-z0-9_-]/g,``),p=(0,I.useSyncExternalStore)(e=>D(e),O,O),m=(0,I.useMemo)(()=>k.sanitize(Kt(n,f)),[n,f]),h=(0,I.useMemo)(()=>zt(n),[n]),g=(0,I.useMemo)(()=>({__html:m}),[m,p]),_=(0,I.useRef)(null),v=(0,I.useRef)(null),y=(0,I.useRef)(null);(0,I.useEffect)(()=>{let e=v.current;if(!e)return;let t=new Hi(e);return y.current=t,()=>{t.dispose(),y.current=null}},[]);let b=$e({shortcutEnabled:s,onFind:(e,t,n)=>y.current?.find(e,t,n)??tt,onClear:()=>y.current?.clear(),onCloseFocus:()=>_.current?.focus({preventScroll:!0})});(0,I.useEffect)(()=>b.refresh(),[m,p,b.refresh]),(0,I.useEffect)(()=>{let e=v.current;if(!e)return;let t=new AbortController;return sn(e,p,t.signal).then(()=>{t.signal.aborted||b.refresh()}),()=>t.abort()},[m,p,b.refresh]),(0,I.useLayoutEffect)(()=>{let n=_.current,s=v.current;if(!(!n||!s))return Qn(n,{viewKey:d,channel:o,target:{session:e,path:t,root:r},driver:i,receiver:a,resizeElements:[n,s],sourceAnchors:()=>Ut(n,s,h)})},[m,h,e,t,r,o,i,a,d]),Ei(v,m,e,t,r);let x=e=>{let n=e.target.closest(`a`);if(n){let r=n.getAttribute(`href`)??``;if(/^https?:/i.test(r))return;if(e.preventDefault(),r.startsWith(`#`)){let e=Wi(r);(e?v.current?.querySelector(`#${CSS.escape(e)}`):null)?.scrollIntoView({block:`nearest`});return}if(!u&&!e.metaKey&&!e.ctrlKey)return;let i=ut(t,r);if(!i)return;l?.(i);return}if(!e.metaKey&&!e.ctrlKey||!c)return;let r=_.current,i=v.current;if(!r||!i)return;let a=e.clientY-r.getBoundingClientRect().top+r.scrollTop,o=Bt(Ut(r,i,h),a);o!==null&&(e.preventDefault(),c({line:oi(o,h)}))},S=C().editorFontSize;return(0,L.jsxs)(`div`,{className:`relative size-full bg-ground`,children:[(0,L.jsx)(`div`,{ref:_,tabIndex:-1,className:`h-full overflow-auto overscroll-contain outline-none`,children:(0,L.jsx)(`div`,{ref:v,onClick:x,style:{fontSize:S},className:`md-preview mx-auto max-w-3xl px-6 py-5 text-fg-secondary`,dangerouslySetInnerHTML:g})}),(0,L.jsx)(ai,{controls:b})]})}function Wi(e){try{return decodeURIComponent(e.slice(1))}catch{return null}}var Gi=`puddle-preview-scroll-report`,Ki=`puddle-preview-scroll-apply`,qi=`puddle-preview-source-reveal`;function Ji(){return crypto.randomUUID()}function Yi(e,t,n){if(e.source!==t||t===null||typeof e.data!=`object`||e.data===null)return null;let r=e.data;return r.channel===n?r:null}function Xi(e,t,n){let r=Yi(e,t,n);return!r||r.kind!==`puddle-preview-scroll-report`||typeof r.ratio!=`number`||!Number.isFinite(r.ratio)||r.sourceLine!==null&&(typeof r.sourceLine!=`number`||!Number.isFinite(r.sourceLine))||typeof r.layout!=`boolean`||typeof r.scrolled!=`boolean`?null:{kind:Gi,channel:n,ratio:Wn(r.ratio),sourceLine:r.sourceLine===null?null:Math.max(1,r.sourceLine),layout:r.layout,scrolled:r.scrolled}}function Zi(e,t,n){let r=Yi(e,t,n);return!r||r.kind!==`puddle-preview-source-reveal`||typeof r.line!=`number`||!Number.isFinite(r.line)?null:{kind:qi,channel:n,line:Math.max(1,r.line)}}function Qi(e,t,n){e?.postMessage({kind:Ki,channel:t,ratio:Wn(n.ratio),sourceLine:n.sourceLine!==null&&Number.isFinite(n.sourceLine)?Math.max(1,n.sourceLine):null},`*`)}function $i(e){return`(() => {
|
|
10
|
+
const channel = ${JSON.stringify(e)};
|
|
11
|
+
const reportKind = ${JSON.stringify(Gi)};
|
|
12
|
+
const applyKind = ${JSON.stringify(Ki)};
|
|
13
|
+
const revealKind = ${JSON.stringify(qi)};
|
|
14
|
+
const lineAttribute = ${JSON.stringify(Wt)};
|
|
15
|
+
const endLineAttribute = ${JSON.stringify(Ht)};
|
|
16
|
+
const countAttribute = ${JSON.stringify(Vt)};
|
|
17
|
+
let frame = 0;
|
|
18
|
+
let layoutChanged = false;
|
|
19
|
+
let scrolled = false;
|
|
20
|
+
let sourceAnchors = [];
|
|
21
|
+
const scrolling = () => document.scrollingElement || document.documentElement;
|
|
22
|
+
const clamp = (value, lower, upper) => Math.min(upper, Math.max(lower, value));
|
|
23
|
+
const numberAttribute = (element, attribute) => {
|
|
24
|
+
const value = Number(element.getAttribute(attribute));
|
|
25
|
+
return Number.isFinite(value) && value >= 1 ? value : null;
|
|
26
|
+
};
|
|
27
|
+
const measureAnchors = () => {
|
|
28
|
+
const root = scrolling();
|
|
29
|
+
const lineCount = numberAttribute(document.documentElement, countAttribute);
|
|
30
|
+
if (lineCount === null) {
|
|
31
|
+
sourceAnchors = [];
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const values = [{ line: 1, offset: 0 }];
|
|
35
|
+
for (const element of document.querySelectorAll('[' + lineAttribute + ']')) {
|
|
36
|
+
const line = numberAttribute(element, lineAttribute);
|
|
37
|
+
if (line === null || line > lineCount + 1 || element.getClientRects().length === 0) continue;
|
|
38
|
+
const rect = element.getBoundingClientRect();
|
|
39
|
+
const top = rect.top + root.scrollTop;
|
|
40
|
+
values.push({ line, offset: top });
|
|
41
|
+
const endLine = numberAttribute(element, endLineAttribute);
|
|
42
|
+
if (endLine !== null && endLine <= lineCount + 1 && endLine > line && rect.height > 0) {
|
|
43
|
+
values.push({ line: endLine, offset: top + rect.height });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
values.push({ line: lineCount + 1, offset: root.scrollHeight });
|
|
47
|
+
values.sort((a, b) => a.offset - b.offset || a.line - b.line);
|
|
48
|
+
const result = [];
|
|
49
|
+
for (const value of values) {
|
|
50
|
+
const previous = result[result.length - 1];
|
|
51
|
+
if (previous && (value.line <= previous.line || value.offset <= previous.offset)) continue;
|
|
52
|
+
result.push(value);
|
|
53
|
+
}
|
|
54
|
+
sourceAnchors = result;
|
|
55
|
+
};
|
|
56
|
+
const interpolate = (value, lowerInput, upperInput, lowerOutput, upperOutput) => {
|
|
57
|
+
if (upperInput <= lowerInput) return lowerOutput;
|
|
58
|
+
const progress = clamp((value - lowerInput) / (upperInput - lowerInput), 0, 1);
|
|
59
|
+
return lowerOutput + progress * (upperOutput - lowerOutput);
|
|
60
|
+
};
|
|
61
|
+
const mapped = (value, input, output) => {
|
|
62
|
+
const values = sourceAnchors;
|
|
63
|
+
if (!values.length) return null;
|
|
64
|
+
if (value <= values[0][input]) return values[0][output];
|
|
65
|
+
const last = values[values.length - 1];
|
|
66
|
+
if (value >= last[input]) return last[output];
|
|
67
|
+
let low = 0;
|
|
68
|
+
let high = values.length - 1;
|
|
69
|
+
while (low + 1 < high) {
|
|
70
|
+
const middle = Math.floor((low + high) / 2);
|
|
71
|
+
if (values[middle][input] <= value) low = middle;
|
|
72
|
+
else high = middle;
|
|
73
|
+
}
|
|
74
|
+
return interpolate(value, values[low][input], values[high][input],
|
|
75
|
+
values[low][output], values[high][output]);
|
|
76
|
+
};
|
|
77
|
+
const report = () => {
|
|
78
|
+
frame = 0;
|
|
79
|
+
if (layoutChanged) measureAnchors();
|
|
80
|
+
const root = scrolling();
|
|
81
|
+
const ratio = clamp(root.scrollTop / Math.max(1, root.scrollHeight - innerHeight), 0, 1);
|
|
82
|
+
const sourceLine = mapped(root.scrollTop, 'offset', 'line');
|
|
83
|
+
parent.postMessage({ kind: reportKind, channel, ratio, sourceLine, layout: layoutChanged, scrolled }, '*');
|
|
84
|
+
layoutChanged = false;
|
|
85
|
+
scrolled = false;
|
|
86
|
+
};
|
|
87
|
+
const schedule = (layout = false) => {
|
|
88
|
+
layoutChanged = layoutChanged || layout;
|
|
89
|
+
if (!frame) frame = requestAnimationFrame(report);
|
|
90
|
+
};
|
|
91
|
+
addEventListener('scroll', () => { scrolled = true; schedule(false); }, { passive: true });
|
|
92
|
+
addEventListener('load', () => schedule(true));
|
|
93
|
+
const resizeObserver = new ResizeObserver(() => schedule(true));
|
|
94
|
+
resizeObserver.observe(document.documentElement);
|
|
95
|
+
if (document.body) resizeObserver.observe(document.body);
|
|
96
|
+
const mutationObserver = new MutationObserver(() => schedule(true));
|
|
97
|
+
mutationObserver.observe(document.documentElement, { subtree: true, childList: true, attributes: true });
|
|
98
|
+
addEventListener('click', (event) => {
|
|
99
|
+
if ((!event.metaKey && !event.ctrlKey) || event.button !== 0) return;
|
|
100
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
101
|
+
if (target && target.closest('a[href]')) return;
|
|
102
|
+
if (layoutChanged) measureAnchors();
|
|
103
|
+
const root = scrolling();
|
|
104
|
+
const line = mapped(event.clientY + root.scrollTop, 'offset', 'line');
|
|
105
|
+
if (line === null) return;
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
event.stopPropagation();
|
|
108
|
+
parent.postMessage({ kind: revealKind, channel, line }, '*');
|
|
109
|
+
}, true);
|
|
110
|
+
addEventListener('message', (event) => {
|
|
111
|
+
const data = event.data;
|
|
112
|
+
if (event.source !== parent || !data || data.kind !== applyKind ||
|
|
113
|
+
data.channel !== channel || typeof data.ratio !== 'number' ||
|
|
114
|
+
!Number.isFinite(data.ratio) ||
|
|
115
|
+
(data.sourceLine !== null &&
|
|
116
|
+
(typeof data.sourceLine !== 'number' || !Number.isFinite(data.sourceLine)))) return;
|
|
117
|
+
if (layoutChanged) measureAnchors();
|
|
118
|
+
const root = scrolling();
|
|
119
|
+
const ratio = clamp(data.ratio, 0, 1);
|
|
120
|
+
const maximum = Math.max(0, root.scrollHeight - innerHeight);
|
|
121
|
+
const semantic = ratio > 0 && ratio < 1 && data.sourceLine !== null
|
|
122
|
+
? mapped(data.sourceLine, 'line', 'offset')
|
|
123
|
+
: null;
|
|
124
|
+
scrollTo(0, semantic === null ? ratio * maximum : clamp(semantic, 0, maximum));
|
|
125
|
+
});
|
|
126
|
+
schedule(true);
|
|
127
|
+
})();`}function ea(e,t){let n=e.createElement(`script`);n.textContent=$i(t),(e.body??e.documentElement).appendChild(n)}var ta=`puddle-preview-find-open`,na=`puddle-preview-find-apply`,ra=`puddle-preview-find-result`,ia=`puddle-preview-find-clear`;function aa(e,t,n){if(e.source!==t||t===null||typeof e.data!=`object`||e.data===null)return null;let r=e.data;return r.channel===n?r.kind===`puddle-preview-find-open`?{kind:ta,channel:n}:r.kind!==`puddle-preview-find-result`||typeof r.index!=`number`||!Number.isInteger(r.index)||r.index<-1||typeof r.count!=`number`||!Number.isInteger(r.count)||r.count<0||r.invalid!==void 0&&typeof r.invalid!=`boolean`||r.limited!==void 0&&typeof r.limited!=`boolean`?null:{kind:ra,channel:n,index:r.index,count:r.count,...r.invalid===void 0?{}:{invalid:r.invalid},...r.limited===void 0?{}:{limited:r.limited}}:null}function oa(e,t,n,r,i){e?.postMessage({kind:na,channel:t,query:n,options:r,direction:i},`*`)}function sa(e,t){e?.postMessage({kind:ia,channel:t},`*`)}function ca(e){return`(() => {
|
|
128
|
+
const channel = ${JSON.stringify(e)};
|
|
129
|
+
const openKind = ${JSON.stringify(ta)};
|
|
130
|
+
const applyKind = ${JSON.stringify(na)};
|
|
131
|
+
const resultKind = ${JSON.stringify(ra)};
|
|
132
|
+
const clearKind = ${JSON.stringify(ia)};
|
|
133
|
+
const matchName = 'puddle-find-match';
|
|
134
|
+
const activeName = 'puddle-find-active';
|
|
135
|
+
const limit = 1000;
|
|
136
|
+
let signature = '';
|
|
137
|
+
let ranges = [];
|
|
138
|
+
let index = -1;
|
|
139
|
+
let limited = false;
|
|
140
|
+
|
|
141
|
+
const style = document.createElement('style');
|
|
142
|
+
style.textContent =
|
|
143
|
+
'::highlight(' + matchName + ') { background: Mark; color: MarkText; }' +
|
|
144
|
+
'::highlight(' + activeName + ') { background: Highlight; color: HighlightText; }';
|
|
145
|
+
(document.head || document.documentElement).appendChild(style);
|
|
146
|
+
|
|
147
|
+
const clearHighlights = () => {
|
|
148
|
+
CSS.highlights.delete(matchName);
|
|
149
|
+
CSS.highlights.delete(activeName);
|
|
150
|
+
};
|
|
151
|
+
const clear = () => {
|
|
152
|
+
signature = '';
|
|
153
|
+
ranges = [];
|
|
154
|
+
index = -1;
|
|
155
|
+
limited = false;
|
|
156
|
+
clearHighlights();
|
|
157
|
+
};
|
|
158
|
+
const report = (invalid = false) => {
|
|
159
|
+
parent.postMessage({
|
|
160
|
+
kind: resultKind,
|
|
161
|
+
channel,
|
|
162
|
+
index,
|
|
163
|
+
count: ranges.length,
|
|
164
|
+
invalid,
|
|
165
|
+
limited,
|
|
166
|
+
}, '*');
|
|
167
|
+
};
|
|
168
|
+
const textNodes = () => {
|
|
169
|
+
const walker = document.createTreeWalker(document.body || document.documentElement,
|
|
170
|
+
NodeFilter.SHOW_TEXT, {
|
|
171
|
+
acceptNode(node) {
|
|
172
|
+
const parent = node.parentElement;
|
|
173
|
+
if (!node.textContent || (parent && parent.closest(
|
|
174
|
+
'script, style, noscript, [hidden], [aria-hidden="true"]'
|
|
175
|
+
))) return NodeFilter.FILTER_REJECT;
|
|
176
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const nodes = [];
|
|
180
|
+
let text = '';
|
|
181
|
+
let node;
|
|
182
|
+
while (node = walker.nextNode()) {
|
|
183
|
+
const value = node.textContent || '';
|
|
184
|
+
const start = text.length;
|
|
185
|
+
text += value;
|
|
186
|
+
nodes.push({ node, start, end: text.length });
|
|
187
|
+
}
|
|
188
|
+
return { text, nodes };
|
|
189
|
+
};
|
|
190
|
+
const compile = (query, options) => {
|
|
191
|
+
const slash = String.fromCharCode(92);
|
|
192
|
+
const specials = new Set(['.', '*', '+', '?', '^', '$', '{', '}', '(', ')', '|', '[', ']', slash]);
|
|
193
|
+
let pattern = options.regex
|
|
194
|
+
? query
|
|
195
|
+
: Array.from(query, (character) => specials.has(character) ? slash + character : character).join('');
|
|
196
|
+
if (options.wholeWord) pattern = slash + 'b(?:' + pattern + ')' + slash + 'b';
|
|
197
|
+
return new RegExp(pattern, options.caseSensitive ? 'g' : 'gi');
|
|
198
|
+
};
|
|
199
|
+
const rangeFor = (match, nodes) => {
|
|
200
|
+
const first = nodes.find((entry) => entry.end > match.start);
|
|
201
|
+
const last = nodes.findLast((entry) => entry.start < match.end);
|
|
202
|
+
if (!first || !last) return null;
|
|
203
|
+
const range = document.createRange();
|
|
204
|
+
range.setStart(first.node, match.start - first.start);
|
|
205
|
+
range.setEnd(last.node, match.end - last.start);
|
|
206
|
+
return range;
|
|
207
|
+
};
|
|
208
|
+
const rebuild = (query, options) => {
|
|
209
|
+
ranges = [];
|
|
210
|
+
limited = false;
|
|
211
|
+
index = -1;
|
|
212
|
+
if (!query) return false;
|
|
213
|
+
let matcher;
|
|
214
|
+
try {
|
|
215
|
+
matcher = compile(query, options);
|
|
216
|
+
} catch {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
const content = textNodes();
|
|
220
|
+
let match;
|
|
221
|
+
while (match = matcher.exec(content.text)) {
|
|
222
|
+
if (!match[0].length) {
|
|
223
|
+
matcher.lastIndex++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (ranges.length === limit) {
|
|
227
|
+
limited = true;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
const range = rangeFor(
|
|
231
|
+
{ start: match.index, end: match.index + match[0].length },
|
|
232
|
+
content.nodes,
|
|
233
|
+
);
|
|
234
|
+
if (range) ranges.push(range);
|
|
235
|
+
}
|
|
236
|
+
index = ranges.length ? 0 : -1;
|
|
237
|
+
return false;
|
|
238
|
+
};
|
|
239
|
+
const paint = () => {
|
|
240
|
+
clearHighlights();
|
|
241
|
+
if (!ranges.length) return;
|
|
242
|
+
CSS.highlights.set(matchName, new Highlight(...ranges));
|
|
243
|
+
const active = ranges[index];
|
|
244
|
+
if (!active) return;
|
|
245
|
+
CSS.highlights.set(activeName, new Highlight(active));
|
|
246
|
+
const element = active.startContainer.parentElement;
|
|
247
|
+
if (element) element.scrollIntoView({ block: 'center', inline: 'nearest' });
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
addEventListener('keydown', (event) => {
|
|
251
|
+
const mac = /Mac|iPhone|iPad/.test(navigator.platform);
|
|
252
|
+
const modifier = mac
|
|
253
|
+
? event.metaKey && !event.ctrlKey
|
|
254
|
+
: event.ctrlKey && !event.metaKey;
|
|
255
|
+
if (event.key.toLowerCase() !== 'f' || !modifier || event.altKey || event.shiftKey) return;
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
event.stopPropagation();
|
|
258
|
+
parent.postMessage({ kind: openKind, channel }, '*');
|
|
259
|
+
}, true);
|
|
260
|
+
|
|
261
|
+
addEventListener('message', (event) => {
|
|
262
|
+
const data = event.data;
|
|
263
|
+
if (event.source !== parent || !data || data.channel !== channel) return;
|
|
264
|
+
if (data.kind === clearKind) {
|
|
265
|
+
clear();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (data.kind !== applyKind || typeof data.query !== 'string' ||
|
|
269
|
+
!data.options || typeof data.options !== 'object') return;
|
|
270
|
+
const nextSignature = JSON.stringify([data.query, data.options]);
|
|
271
|
+
let invalid = false;
|
|
272
|
+
if (nextSignature !== signature || data.direction === 'reset') {
|
|
273
|
+
signature = nextSignature;
|
|
274
|
+
invalid = rebuild(data.query, data.options);
|
|
275
|
+
} else if (ranges.length) {
|
|
276
|
+
index = data.direction === 'previous'
|
|
277
|
+
? (index - 1 + ranges.length) % ranges.length
|
|
278
|
+
: (index + 1) % ranges.length;
|
|
279
|
+
}
|
|
280
|
+
if (invalid) clearHighlights();
|
|
281
|
+
else paint();
|
|
282
|
+
report(invalid);
|
|
283
|
+
});
|
|
284
|
+
})();`}function la(e,t){let n=e.createElement(`script`);n.textContent=ca(t),(e.body??e.documentElement).appendChild(n)}var ua=`script, style, pre, code, kbd, samp, textarea, math, svg, .katex`,da=/\bmathjax\b|\bkatex\b/i;function fa(e){if(ma(e))return!1;let t=e.body??e.documentElement;return t?pa(t):!1}function pa(e){let t=e.ownerDocument,n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[];for(;n.nextNode();){let e=n.currentNode;/[$\\]/.test(e.data)&&(e.parentElement?.closest(ua)||r.push(e))}let i={},a=!1;for(let e of r)ha(t,e,i)&&(a=!0);return a}function ma(e){if(e.querySelector(`.katex, math`))return!0;for(let t of e.querySelectorAll(`script`))if(da.test(t.getAttribute(`src`)??``)||da.test(t.textContent??``))return!0;return!1}function ha(e,t,n){let r=t.data;if(!on(r))return!1;let i=e.createDocumentFragment(),a=e.createElement(`span`),o=0;for(let t=on(r,0);t;t=on(r,o)){for(t.start>o&&i.appendChild(e.createTextNode(r.slice(o,t.start))),a.innerHTML=rn(t.tex,t.display,n);a.firstChild;)i.appendChild(a.firstChild);o=t.start+t.length}return o<r.length&&i.appendChild(e.createTextNode(r.slice(o))),t.replaceWith(i),!0}var ga=new Set([65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111]),B;(function(e){e[e.EOF=-1]=`EOF`,e[e.NULL=0]=`NULL`,e[e.TABULATION=9]=`TABULATION`,e[e.CARRIAGE_RETURN=13]=`CARRIAGE_RETURN`,e[e.LINE_FEED=10]=`LINE_FEED`,e[e.FORM_FEED=12]=`FORM_FEED`,e[e.SPACE=32]=`SPACE`,e[e.EXCLAMATION_MARK=33]=`EXCLAMATION_MARK`,e[e.QUOTATION_MARK=34]=`QUOTATION_MARK`,e[e.AMPERSAND=38]=`AMPERSAND`,e[e.APOSTROPHE=39]=`APOSTROPHE`,e[e.HYPHEN_MINUS=45]=`HYPHEN_MINUS`,e[e.SOLIDUS=47]=`SOLIDUS`,e[e.DIGIT_0=48]=`DIGIT_0`,e[e.DIGIT_9=57]=`DIGIT_9`,e[e.SEMICOLON=59]=`SEMICOLON`,e[e.LESS_THAN_SIGN=60]=`LESS_THAN_SIGN`,e[e.EQUALS_SIGN=61]=`EQUALS_SIGN`,e[e.GREATER_THAN_SIGN=62]=`GREATER_THAN_SIGN`,e[e.QUESTION_MARK=63]=`QUESTION_MARK`,e[e.LATIN_CAPITAL_A=65]=`LATIN_CAPITAL_A`,e[e.LATIN_CAPITAL_Z=90]=`LATIN_CAPITAL_Z`,e[e.RIGHT_SQUARE_BRACKET=93]=`RIGHT_SQUARE_BRACKET`,e[e.GRAVE_ACCENT=96]=`GRAVE_ACCENT`,e[e.LATIN_SMALL_A=97]=`LATIN_SMALL_A`,e[e.LATIN_SMALL_Z=122]=`LATIN_SMALL_Z`})(B||={});var V={DASH_DASH:`--`,CDATA_START:`[CDATA[`,DOCTYPE:`doctype`,SCRIPT:`script`,PUBLIC:`public`,SYSTEM:`system`};function _a(e){return e>=55296&&e<=57343}function va(e){return e>=56320&&e<=57343}function ya(e,t){return(e-55296)*1024+9216+t}function ba(e){return e!==32&&e!==10&&e!==13&&e!==9&&e!==12&&e>=1&&e<=31||e>=127&&e<=159}function xa(e){return e>=64976&&e<=65007||ga.has(e)}var H;(function(e){e.controlCharacterInInputStream=`control-character-in-input-stream`,e.noncharacterInInputStream=`noncharacter-in-input-stream`,e.surrogateInInputStream=`surrogate-in-input-stream`,e.nonVoidHtmlElementStartTagWithTrailingSolidus=`non-void-html-element-start-tag-with-trailing-solidus`,e.endTagWithAttributes=`end-tag-with-attributes`,e.endTagWithTrailingSolidus=`end-tag-with-trailing-solidus`,e.unexpectedSolidusInTag=`unexpected-solidus-in-tag`,e.unexpectedNullCharacter=`unexpected-null-character`,e.unexpectedQuestionMarkInsteadOfTagName=`unexpected-question-mark-instead-of-tag-name`,e.invalidFirstCharacterOfTagName=`invalid-first-character-of-tag-name`,e.unexpectedEqualsSignBeforeAttributeName=`unexpected-equals-sign-before-attribute-name`,e.missingEndTagName=`missing-end-tag-name`,e.unexpectedCharacterInAttributeName=`unexpected-character-in-attribute-name`,e.unknownNamedCharacterReference=`unknown-named-character-reference`,e.missingSemicolonAfterCharacterReference=`missing-semicolon-after-character-reference`,e.unexpectedCharacterAfterDoctypeSystemIdentifier=`unexpected-character-after-doctype-system-identifier`,e.unexpectedCharacterInUnquotedAttributeValue=`unexpected-character-in-unquoted-attribute-value`,e.eofBeforeTagName=`eof-before-tag-name`,e.eofInTag=`eof-in-tag`,e.missingAttributeValue=`missing-attribute-value`,e.missingWhitespaceBetweenAttributes=`missing-whitespace-between-attributes`,e.missingWhitespaceAfterDoctypePublicKeyword=`missing-whitespace-after-doctype-public-keyword`,e.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers=`missing-whitespace-between-doctype-public-and-system-identifiers`,e.missingWhitespaceAfterDoctypeSystemKeyword=`missing-whitespace-after-doctype-system-keyword`,e.missingQuoteBeforeDoctypePublicIdentifier=`missing-quote-before-doctype-public-identifier`,e.missingQuoteBeforeDoctypeSystemIdentifier=`missing-quote-before-doctype-system-identifier`,e.missingDoctypePublicIdentifier=`missing-doctype-public-identifier`,e.missingDoctypeSystemIdentifier=`missing-doctype-system-identifier`,e.abruptDoctypePublicIdentifier=`abrupt-doctype-public-identifier`,e.abruptDoctypeSystemIdentifier=`abrupt-doctype-system-identifier`,e.cdataInHtmlContent=`cdata-in-html-content`,e.incorrectlyOpenedComment=`incorrectly-opened-comment`,e.eofInScriptHtmlCommentLikeText=`eof-in-script-html-comment-like-text`,e.eofInDoctype=`eof-in-doctype`,e.nestedComment=`nested-comment`,e.abruptClosingOfEmptyComment=`abrupt-closing-of-empty-comment`,e.eofInComment=`eof-in-comment`,e.incorrectlyClosedComment=`incorrectly-closed-comment`,e.eofInCdata=`eof-in-cdata`,e.absenceOfDigitsInNumericCharacterReference=`absence-of-digits-in-numeric-character-reference`,e.nullCharacterReference=`null-character-reference`,e.surrogateCharacterReference=`surrogate-character-reference`,e.characterReferenceOutsideUnicodeRange=`character-reference-outside-unicode-range`,e.controlCharacterReference=`control-character-reference`,e.noncharacterCharacterReference=`noncharacter-character-reference`,e.missingWhitespaceBeforeDoctypeName=`missing-whitespace-before-doctype-name`,e.missingDoctypeName=`missing-doctype-name`,e.invalidCharacterSequenceAfterDoctypeName=`invalid-character-sequence-after-doctype-name`,e.duplicateAttribute=`duplicate-attribute`,e.nonConformingDoctype=`non-conforming-doctype`,e.missingDoctype=`missing-doctype`,e.misplacedDoctype=`misplaced-doctype`,e.endTagWithoutMatchingOpenElement=`end-tag-without-matching-open-element`,e.closingOfElementWithOpenChildElements=`closing-of-element-with-open-child-elements`,e.disallowedContentInNoscriptInHead=`disallowed-content-in-noscript-in-head`,e.openElementsLeftAfterEof=`open-elements-left-after-eof`,e.abandonedHeadElementChild=`abandoned-head-element-child`,e.misplacedStartTagForHeadElement=`misplaced-start-tag-for-head-element`,e.nestedNoscriptInHead=`nested-noscript-in-head`,e.eofInElementThatCanContainOnlyText=`eof-in-element-that-can-contain-only-text`})(H||={});var Sa=65536,Ca=class{constructor(e){this.handler=e,this.html=``,this.pos=-1,this.lastGapPos=-2,this.gapStack=[],this.skipNextNewLine=!1,this.lastChunkWritten=!1,this.endOfChunkHit=!1,this.bufferWaterline=Sa,this.isEol=!1,this.lineStartPos=0,this.droppedBufferSize=0,this.line=1,this.lastErrOffset=-1}get col(){return this.pos-this.lineStartPos+Number(this.lastGapPos!==this.pos)}get offset(){return this.droppedBufferSize+this.pos}getError(e,t){let{line:n,col:r,offset:i}=this,a=r+t,o=i+t;return{code:e,startLine:n,endLine:n,startCol:a,endCol:a,startOffset:o,endOffset:o}}_err(e){this.handler.onParseError&&this.lastErrOffset!==this.offset&&(this.lastErrOffset=this.offset,this.handler.onParseError(this.getError(e,0)))}_addGap(){this.gapStack.push(this.lastGapPos),this.lastGapPos=this.pos}_processSurrogate(e){if(this.pos!==this.html.length-1){let t=this.html.charCodeAt(this.pos+1);if(va(t))return this.pos++,this._addGap(),ya(e,t)}else if(!this.lastChunkWritten)return this.endOfChunkHit=!0,B.EOF;return this._err(H.surrogateInInputStream),e}willDropParsedChunk(){return this.pos>this.bufferWaterline}dropParsedChunk(){this.willDropParsedChunk()&&(this.html=this.html.substring(this.pos),this.lineStartPos-=this.pos,this.droppedBufferSize+=this.pos,this.pos=0,this.lastGapPos=-2,this.gapStack.length=0)}write(e,t){this.html.length>0?this.html+=e:this.html=e,this.endOfChunkHit=!1,this.lastChunkWritten=t}insertHtmlAtCurrentPos(e){this.html=this.html.substring(0,this.pos+1)+e+this.html.substring(this.pos+1),this.endOfChunkHit=!1}startsWith(e,t){if(this.pos+e.length>this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,!1;if(t)return this.html.startsWith(e,this.pos);for(let t=0;t<e.length;t++)if((this.html.charCodeAt(this.pos+t)|32)!==e.charCodeAt(t))return!1;return!0}peek(e){let t=this.pos+e;if(t>=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,B.EOF;let n=this.html.charCodeAt(t);return n===B.CARRIAGE_RETURN?B.LINE_FEED:n}advance(){if(this.pos++,this.isEol&&(this.isEol=!1,this.line++,this.lineStartPos=this.pos),this.pos>=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,B.EOF;let e=this.html.charCodeAt(this.pos);return e===B.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,B.LINE_FEED):e===B.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,_a(e)&&(e=this._processSurrogate(e)),this.handler.onParseError===null||e>31&&e<127||e===B.LINE_FEED||e===B.CARRIAGE_RETURN||e>159&&e<64976||this._checkForProblematicCharacters(e),e)}_checkForProblematicCharacters(e){ba(e)?this._err(H.controlCharacterInInputStream):xa(e)&&this._err(H.noncharacterInInputStream)}retreat(e){for(this.pos-=e;this.pos<this.lastGapPos;)this.lastGapPos=this.gapStack.pop(),this.pos--;this.isEol=!1}},U;(function(e){e[e.CHARACTER=0]=`CHARACTER`,e[e.NULL_CHARACTER=1]=`NULL_CHARACTER`,e[e.WHITESPACE_CHARACTER=2]=`WHITESPACE_CHARACTER`,e[e.START_TAG=3]=`START_TAG`,e[e.END_TAG=4]=`END_TAG`,e[e.COMMENT=5]=`COMMENT`,e[e.DOCTYPE=6]=`DOCTYPE`,e[e.EOF=7]=`EOF`,e[e.HIBERNATION=8]=`HIBERNATION`})(U||={});function wa(e,t){for(let n=e.attrs.length-1;n>=0;n--)if(e.attrs[n].name===t)return e.attrs[n].value;return null}var W;(function(e){e.HTML=`http://www.w3.org/1999/xhtml`,e.MATHML=`http://www.w3.org/1998/Math/MathML`,e.SVG=`http://www.w3.org/2000/svg`,e.XLINK=`http://www.w3.org/1999/xlink`,e.XML=`http://www.w3.org/XML/1998/namespace`,e.XMLNS=`http://www.w3.org/2000/xmlns/`})(W||={});var Ta;(function(e){e.TYPE=`type`,e.ACTION=`action`,e.ENCODING=`encoding`,e.PROMPT=`prompt`,e.NAME=`name`,e.COLOR=`color`,e.FACE=`face`,e.SIZE=`size`})(Ta||={});var G;(function(e){e.NO_QUIRKS=`no-quirks`,e.QUIRKS=`quirks`,e.LIMITED_QUIRKS=`limited-quirks`})(G||={});var K;(function(e){e.A=`a`,e.ADDRESS=`address`,e.ANNOTATION_XML=`annotation-xml`,e.APPLET=`applet`,e.AREA=`area`,e.ARTICLE=`article`,e.ASIDE=`aside`,e.B=`b`,e.BASE=`base`,e.BASEFONT=`basefont`,e.BGSOUND=`bgsound`,e.BIG=`big`,e.BLOCKQUOTE=`blockquote`,e.BODY=`body`,e.BR=`br`,e.BUTTON=`button`,e.CAPTION=`caption`,e.CENTER=`center`,e.CODE=`code`,e.COL=`col`,e.COLGROUP=`colgroup`,e.DD=`dd`,e.DESC=`desc`,e.DETAILS=`details`,e.DIALOG=`dialog`,e.DIR=`dir`,e.DIV=`div`,e.DL=`dl`,e.DT=`dt`,e.EM=`em`,e.EMBED=`embed`,e.FIELDSET=`fieldset`,e.FIGCAPTION=`figcaption`,e.FIGURE=`figure`,e.FONT=`font`,e.FOOTER=`footer`,e.FOREIGN_OBJECT=`foreignObject`,e.FORM=`form`,e.FRAME=`frame`,e.FRAMESET=`frameset`,e.H1=`h1`,e.H2=`h2`,e.H3=`h3`,e.H4=`h4`,e.H5=`h5`,e.H6=`h6`,e.HEAD=`head`,e.HEADER=`header`,e.HGROUP=`hgroup`,e.HR=`hr`,e.HTML=`html`,e.I=`i`,e.IMG=`img`,e.IMAGE=`image`,e.INPUT=`input`,e.IFRAME=`iframe`,e.KEYGEN=`keygen`,e.LABEL=`label`,e.LI=`li`,e.LINK=`link`,e.LISTING=`listing`,e.MAIN=`main`,e.MALIGNMARK=`malignmark`,e.MARQUEE=`marquee`,e.MATH=`math`,e.MENU=`menu`,e.META=`meta`,e.MGLYPH=`mglyph`,e.MI=`mi`,e.MO=`mo`,e.MN=`mn`,e.MS=`ms`,e.MTEXT=`mtext`,e.NAV=`nav`,e.NOBR=`nobr`,e.NOFRAMES=`noframes`,e.NOEMBED=`noembed`,e.NOSCRIPT=`noscript`,e.OBJECT=`object`,e.OL=`ol`,e.OPTGROUP=`optgroup`,e.OPTION=`option`,e.P=`p`,e.PARAM=`param`,e.PLAINTEXT=`plaintext`,e.PRE=`pre`,e.RB=`rb`,e.RP=`rp`,e.RT=`rt`,e.RTC=`rtc`,e.RUBY=`ruby`,e.S=`s`,e.SCRIPT=`script`,e.SEARCH=`search`,e.SECTION=`section`,e.SELECT=`select`,e.SOURCE=`source`,e.SMALL=`small`,e.SPAN=`span`,e.STRIKE=`strike`,e.STRONG=`strong`,e.STYLE=`style`,e.SUB=`sub`,e.SUMMARY=`summary`,e.SUP=`sup`,e.TABLE=`table`,e.TBODY=`tbody`,e.TEMPLATE=`template`,e.TEXTAREA=`textarea`,e.TFOOT=`tfoot`,e.TD=`td`,e.TH=`th`,e.THEAD=`thead`,e.TITLE=`title`,e.TR=`tr`,e.TRACK=`track`,e.TT=`tt`,e.U=`u`,e.UL=`ul`,e.SVG=`svg`,e.VAR=`var`,e.WBR=`wbr`,e.XMP=`xmp`})(K||={});var q;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.A=1]=`A`,e[e.ADDRESS=2]=`ADDRESS`,e[e.ANNOTATION_XML=3]=`ANNOTATION_XML`,e[e.APPLET=4]=`APPLET`,e[e.AREA=5]=`AREA`,e[e.ARTICLE=6]=`ARTICLE`,e[e.ASIDE=7]=`ASIDE`,e[e.B=8]=`B`,e[e.BASE=9]=`BASE`,e[e.BASEFONT=10]=`BASEFONT`,e[e.BGSOUND=11]=`BGSOUND`,e[e.BIG=12]=`BIG`,e[e.BLOCKQUOTE=13]=`BLOCKQUOTE`,e[e.BODY=14]=`BODY`,e[e.BR=15]=`BR`,e[e.BUTTON=16]=`BUTTON`,e[e.CAPTION=17]=`CAPTION`,e[e.CENTER=18]=`CENTER`,e[e.CODE=19]=`CODE`,e[e.COL=20]=`COL`,e[e.COLGROUP=21]=`COLGROUP`,e[e.DD=22]=`DD`,e[e.DESC=23]=`DESC`,e[e.DETAILS=24]=`DETAILS`,e[e.DIALOG=25]=`DIALOG`,e[e.DIR=26]=`DIR`,e[e.DIV=27]=`DIV`,e[e.DL=28]=`DL`,e[e.DT=29]=`DT`,e[e.EM=30]=`EM`,e[e.EMBED=31]=`EMBED`,e[e.FIELDSET=32]=`FIELDSET`,e[e.FIGCAPTION=33]=`FIGCAPTION`,e[e.FIGURE=34]=`FIGURE`,e[e.FONT=35]=`FONT`,e[e.FOOTER=36]=`FOOTER`,e[e.FOREIGN_OBJECT=37]=`FOREIGN_OBJECT`,e[e.FORM=38]=`FORM`,e[e.FRAME=39]=`FRAME`,e[e.FRAMESET=40]=`FRAMESET`,e[e.H1=41]=`H1`,e[e.H2=42]=`H2`,e[e.H3=43]=`H3`,e[e.H4=44]=`H4`,e[e.H5=45]=`H5`,e[e.H6=46]=`H6`,e[e.HEAD=47]=`HEAD`,e[e.HEADER=48]=`HEADER`,e[e.HGROUP=49]=`HGROUP`,e[e.HR=50]=`HR`,e[e.HTML=51]=`HTML`,e[e.I=52]=`I`,e[e.IMG=53]=`IMG`,e[e.IMAGE=54]=`IMAGE`,e[e.INPUT=55]=`INPUT`,e[e.IFRAME=56]=`IFRAME`,e[e.KEYGEN=57]=`KEYGEN`,e[e.LABEL=58]=`LABEL`,e[e.LI=59]=`LI`,e[e.LINK=60]=`LINK`,e[e.LISTING=61]=`LISTING`,e[e.MAIN=62]=`MAIN`,e[e.MALIGNMARK=63]=`MALIGNMARK`,e[e.MARQUEE=64]=`MARQUEE`,e[e.MATH=65]=`MATH`,e[e.MENU=66]=`MENU`,e[e.META=67]=`META`,e[e.MGLYPH=68]=`MGLYPH`,e[e.MI=69]=`MI`,e[e.MO=70]=`MO`,e[e.MN=71]=`MN`,e[e.MS=72]=`MS`,e[e.MTEXT=73]=`MTEXT`,e[e.NAV=74]=`NAV`,e[e.NOBR=75]=`NOBR`,e[e.NOFRAMES=76]=`NOFRAMES`,e[e.NOEMBED=77]=`NOEMBED`,e[e.NOSCRIPT=78]=`NOSCRIPT`,e[e.OBJECT=79]=`OBJECT`,e[e.OL=80]=`OL`,e[e.OPTGROUP=81]=`OPTGROUP`,e[e.OPTION=82]=`OPTION`,e[e.P=83]=`P`,e[e.PARAM=84]=`PARAM`,e[e.PLAINTEXT=85]=`PLAINTEXT`,e[e.PRE=86]=`PRE`,e[e.RB=87]=`RB`,e[e.RP=88]=`RP`,e[e.RT=89]=`RT`,e[e.RTC=90]=`RTC`,e[e.RUBY=91]=`RUBY`,e[e.S=92]=`S`,e[e.SCRIPT=93]=`SCRIPT`,e[e.SEARCH=94]=`SEARCH`,e[e.SECTION=95]=`SECTION`,e[e.SELECT=96]=`SELECT`,e[e.SOURCE=97]=`SOURCE`,e[e.SMALL=98]=`SMALL`,e[e.SPAN=99]=`SPAN`,e[e.STRIKE=100]=`STRIKE`,e[e.STRONG=101]=`STRONG`,e[e.STYLE=102]=`STYLE`,e[e.SUB=103]=`SUB`,e[e.SUMMARY=104]=`SUMMARY`,e[e.SUP=105]=`SUP`,e[e.TABLE=106]=`TABLE`,e[e.TBODY=107]=`TBODY`,e[e.TEMPLATE=108]=`TEMPLATE`,e[e.TEXTAREA=109]=`TEXTAREA`,e[e.TFOOT=110]=`TFOOT`,e[e.TD=111]=`TD`,e[e.TH=112]=`TH`,e[e.THEAD=113]=`THEAD`,e[e.TITLE=114]=`TITLE`,e[e.TR=115]=`TR`,e[e.TRACK=116]=`TRACK`,e[e.TT=117]=`TT`,e[e.U=118]=`U`,e[e.UL=119]=`UL`,e[e.SVG=120]=`SVG`,e[e.VAR=121]=`VAR`,e[e.WBR=122]=`WBR`,e[e.XMP=123]=`XMP`})(q||={});var Ea=new Map([[K.A,q.A],[K.ADDRESS,q.ADDRESS],[K.ANNOTATION_XML,q.ANNOTATION_XML],[K.APPLET,q.APPLET],[K.AREA,q.AREA],[K.ARTICLE,q.ARTICLE],[K.ASIDE,q.ASIDE],[K.B,q.B],[K.BASE,q.BASE],[K.BASEFONT,q.BASEFONT],[K.BGSOUND,q.BGSOUND],[K.BIG,q.BIG],[K.BLOCKQUOTE,q.BLOCKQUOTE],[K.BODY,q.BODY],[K.BR,q.BR],[K.BUTTON,q.BUTTON],[K.CAPTION,q.CAPTION],[K.CENTER,q.CENTER],[K.CODE,q.CODE],[K.COL,q.COL],[K.COLGROUP,q.COLGROUP],[K.DD,q.DD],[K.DESC,q.DESC],[K.DETAILS,q.DETAILS],[K.DIALOG,q.DIALOG],[K.DIR,q.DIR],[K.DIV,q.DIV],[K.DL,q.DL],[K.DT,q.DT],[K.EM,q.EM],[K.EMBED,q.EMBED],[K.FIELDSET,q.FIELDSET],[K.FIGCAPTION,q.FIGCAPTION],[K.FIGURE,q.FIGURE],[K.FONT,q.FONT],[K.FOOTER,q.FOOTER],[K.FOREIGN_OBJECT,q.FOREIGN_OBJECT],[K.FORM,q.FORM],[K.FRAME,q.FRAME],[K.FRAMESET,q.FRAMESET],[K.H1,q.H1],[K.H2,q.H2],[K.H3,q.H3],[K.H4,q.H4],[K.H5,q.H5],[K.H6,q.H6],[K.HEAD,q.HEAD],[K.HEADER,q.HEADER],[K.HGROUP,q.HGROUP],[K.HR,q.HR],[K.HTML,q.HTML],[K.I,q.I],[K.IMG,q.IMG],[K.IMAGE,q.IMAGE],[K.INPUT,q.INPUT],[K.IFRAME,q.IFRAME],[K.KEYGEN,q.KEYGEN],[K.LABEL,q.LABEL],[K.LI,q.LI],[K.LINK,q.LINK],[K.LISTING,q.LISTING],[K.MAIN,q.MAIN],[K.MALIGNMARK,q.MALIGNMARK],[K.MARQUEE,q.MARQUEE],[K.MATH,q.MATH],[K.MENU,q.MENU],[K.META,q.META],[K.MGLYPH,q.MGLYPH],[K.MI,q.MI],[K.MO,q.MO],[K.MN,q.MN],[K.MS,q.MS],[K.MTEXT,q.MTEXT],[K.NAV,q.NAV],[K.NOBR,q.NOBR],[K.NOFRAMES,q.NOFRAMES],[K.NOEMBED,q.NOEMBED],[K.NOSCRIPT,q.NOSCRIPT],[K.OBJECT,q.OBJECT],[K.OL,q.OL],[K.OPTGROUP,q.OPTGROUP],[K.OPTION,q.OPTION],[K.P,q.P],[K.PARAM,q.PARAM],[K.PLAINTEXT,q.PLAINTEXT],[K.PRE,q.PRE],[K.RB,q.RB],[K.RP,q.RP],[K.RT,q.RT],[K.RTC,q.RTC],[K.RUBY,q.RUBY],[K.S,q.S],[K.SCRIPT,q.SCRIPT],[K.SEARCH,q.SEARCH],[K.SECTION,q.SECTION],[K.SELECT,q.SELECT],[K.SOURCE,q.SOURCE],[K.SMALL,q.SMALL],[K.SPAN,q.SPAN],[K.STRIKE,q.STRIKE],[K.STRONG,q.STRONG],[K.STYLE,q.STYLE],[K.SUB,q.SUB],[K.SUMMARY,q.SUMMARY],[K.SUP,q.SUP],[K.TABLE,q.TABLE],[K.TBODY,q.TBODY],[K.TEMPLATE,q.TEMPLATE],[K.TEXTAREA,q.TEXTAREA],[K.TFOOT,q.TFOOT],[K.TD,q.TD],[K.TH,q.TH],[K.THEAD,q.THEAD],[K.TITLE,q.TITLE],[K.TR,q.TR],[K.TRACK,q.TRACK],[K.TT,q.TT],[K.U,q.U],[K.UL,q.UL],[K.SVG,q.SVG],[K.VAR,q.VAR],[K.WBR,q.WBR],[K.XMP,q.XMP]]);function Da(e){return Ea.get(e)??q.UNKNOWN}var J=q,Oa={[W.HTML]:new Set([J.ADDRESS,J.APPLET,J.AREA,J.ARTICLE,J.ASIDE,J.BASE,J.BASEFONT,J.BGSOUND,J.BLOCKQUOTE,J.BODY,J.BR,J.BUTTON,J.CAPTION,J.CENTER,J.COL,J.COLGROUP,J.DD,J.DETAILS,J.DIR,J.DIV,J.DL,J.DT,J.EMBED,J.FIELDSET,J.FIGCAPTION,J.FIGURE,J.FOOTER,J.FORM,J.FRAME,J.FRAMESET,J.H1,J.H2,J.H3,J.H4,J.H5,J.H6,J.HEAD,J.HEADER,J.HGROUP,J.HR,J.HTML,J.IFRAME,J.IMG,J.INPUT,J.LI,J.LINK,J.LISTING,J.MAIN,J.MARQUEE,J.MENU,J.META,J.NAV,J.NOEMBED,J.NOFRAMES,J.NOSCRIPT,J.OBJECT,J.OL,J.P,J.PARAM,J.PLAINTEXT,J.PRE,J.SCRIPT,J.SECTION,J.SELECT,J.SOURCE,J.STYLE,J.SUMMARY,J.TABLE,J.TBODY,J.TD,J.TEMPLATE,J.TEXTAREA,J.TFOOT,J.TH,J.THEAD,J.TITLE,J.TR,J.TRACK,J.UL,J.WBR,J.XMP]),[W.MATHML]:new Set([J.MI,J.MO,J.MN,J.MS,J.MTEXT,J.ANNOTATION_XML]),[W.SVG]:new Set([J.TITLE,J.FOREIGN_OBJECT,J.DESC]),[W.XLINK]:new Set,[W.XML]:new Set,[W.XMLNS]:new Set},ka=new Set([J.H1,J.H2,J.H3,J.H4,J.H5,J.H6]),Aa=new Set([K.STYLE,K.SCRIPT,K.XMP,K.IFRAME,K.NOEMBED,K.NOFRAMES,K.PLAINTEXT]);function ja(e,t){return Aa.has(e)||t&&e===K.NOSCRIPT}var Y;(function(e){e[e.DATA=0]=`DATA`,e[e.RCDATA=1]=`RCDATA`,e[e.RAWTEXT=2]=`RAWTEXT`,e[e.SCRIPT_DATA=3]=`SCRIPT_DATA`,e[e.PLAINTEXT=4]=`PLAINTEXT`,e[e.TAG_OPEN=5]=`TAG_OPEN`,e[e.END_TAG_OPEN=6]=`END_TAG_OPEN`,e[e.TAG_NAME=7]=`TAG_NAME`,e[e.RCDATA_LESS_THAN_SIGN=8]=`RCDATA_LESS_THAN_SIGN`,e[e.RCDATA_END_TAG_OPEN=9]=`RCDATA_END_TAG_OPEN`,e[e.RCDATA_END_TAG_NAME=10]=`RCDATA_END_TAG_NAME`,e[e.RAWTEXT_LESS_THAN_SIGN=11]=`RAWTEXT_LESS_THAN_SIGN`,e[e.RAWTEXT_END_TAG_OPEN=12]=`RAWTEXT_END_TAG_OPEN`,e[e.RAWTEXT_END_TAG_NAME=13]=`RAWTEXT_END_TAG_NAME`,e[e.SCRIPT_DATA_LESS_THAN_SIGN=14]=`SCRIPT_DATA_LESS_THAN_SIGN`,e[e.SCRIPT_DATA_END_TAG_OPEN=15]=`SCRIPT_DATA_END_TAG_OPEN`,e[e.SCRIPT_DATA_END_TAG_NAME=16]=`SCRIPT_DATA_END_TAG_NAME`,e[e.SCRIPT_DATA_ESCAPE_START=17]=`SCRIPT_DATA_ESCAPE_START`,e[e.SCRIPT_DATA_ESCAPE_START_DASH=18]=`SCRIPT_DATA_ESCAPE_START_DASH`,e[e.SCRIPT_DATA_ESCAPED=19]=`SCRIPT_DATA_ESCAPED`,e[e.SCRIPT_DATA_ESCAPED_DASH=20]=`SCRIPT_DATA_ESCAPED_DASH`,e[e.SCRIPT_DATA_ESCAPED_DASH_DASH=21]=`SCRIPT_DATA_ESCAPED_DASH_DASH`,e[e.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN=22]=`SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN`,e[e.SCRIPT_DATA_ESCAPED_END_TAG_OPEN=23]=`SCRIPT_DATA_ESCAPED_END_TAG_OPEN`,e[e.SCRIPT_DATA_ESCAPED_END_TAG_NAME=24]=`SCRIPT_DATA_ESCAPED_END_TAG_NAME`,e[e.SCRIPT_DATA_DOUBLE_ESCAPE_START=25]=`SCRIPT_DATA_DOUBLE_ESCAPE_START`,e[e.SCRIPT_DATA_DOUBLE_ESCAPED=26]=`SCRIPT_DATA_DOUBLE_ESCAPED`,e[e.SCRIPT_DATA_DOUBLE_ESCAPED_DASH=27]=`SCRIPT_DATA_DOUBLE_ESCAPED_DASH`,e[e.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH=28]=`SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH`,e[e.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN=29]=`SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN`,e[e.SCRIPT_DATA_DOUBLE_ESCAPE_END=30]=`SCRIPT_DATA_DOUBLE_ESCAPE_END`,e[e.BEFORE_ATTRIBUTE_NAME=31]=`BEFORE_ATTRIBUTE_NAME`,e[e.ATTRIBUTE_NAME=32]=`ATTRIBUTE_NAME`,e[e.AFTER_ATTRIBUTE_NAME=33]=`AFTER_ATTRIBUTE_NAME`,e[e.BEFORE_ATTRIBUTE_VALUE=34]=`BEFORE_ATTRIBUTE_VALUE`,e[e.ATTRIBUTE_VALUE_DOUBLE_QUOTED=35]=`ATTRIBUTE_VALUE_DOUBLE_QUOTED`,e[e.ATTRIBUTE_VALUE_SINGLE_QUOTED=36]=`ATTRIBUTE_VALUE_SINGLE_QUOTED`,e[e.ATTRIBUTE_VALUE_UNQUOTED=37]=`ATTRIBUTE_VALUE_UNQUOTED`,e[e.AFTER_ATTRIBUTE_VALUE_QUOTED=38]=`AFTER_ATTRIBUTE_VALUE_QUOTED`,e[e.SELF_CLOSING_START_TAG=39]=`SELF_CLOSING_START_TAG`,e[e.BOGUS_COMMENT=40]=`BOGUS_COMMENT`,e[e.MARKUP_DECLARATION_OPEN=41]=`MARKUP_DECLARATION_OPEN`,e[e.COMMENT_START=42]=`COMMENT_START`,e[e.COMMENT_START_DASH=43]=`COMMENT_START_DASH`,e[e.COMMENT=44]=`COMMENT`,e[e.COMMENT_LESS_THAN_SIGN=45]=`COMMENT_LESS_THAN_SIGN`,e[e.COMMENT_LESS_THAN_SIGN_BANG=46]=`COMMENT_LESS_THAN_SIGN_BANG`,e[e.COMMENT_LESS_THAN_SIGN_BANG_DASH=47]=`COMMENT_LESS_THAN_SIGN_BANG_DASH`,e[e.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH=48]=`COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH`,e[e.COMMENT_END_DASH=49]=`COMMENT_END_DASH`,e[e.COMMENT_END=50]=`COMMENT_END`,e[e.COMMENT_END_BANG=51]=`COMMENT_END_BANG`,e[e.DOCTYPE=52]=`DOCTYPE`,e[e.BEFORE_DOCTYPE_NAME=53]=`BEFORE_DOCTYPE_NAME`,e[e.DOCTYPE_NAME=54]=`DOCTYPE_NAME`,e[e.AFTER_DOCTYPE_NAME=55]=`AFTER_DOCTYPE_NAME`,e[e.AFTER_DOCTYPE_PUBLIC_KEYWORD=56]=`AFTER_DOCTYPE_PUBLIC_KEYWORD`,e[e.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER=57]=`BEFORE_DOCTYPE_PUBLIC_IDENTIFIER`,e[e.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED=58]=`DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED`,e[e.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED=59]=`DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED`,e[e.AFTER_DOCTYPE_PUBLIC_IDENTIFIER=60]=`AFTER_DOCTYPE_PUBLIC_IDENTIFIER`,e[e.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS=61]=`BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS`,e[e.AFTER_DOCTYPE_SYSTEM_KEYWORD=62]=`AFTER_DOCTYPE_SYSTEM_KEYWORD`,e[e.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER=63]=`BEFORE_DOCTYPE_SYSTEM_IDENTIFIER`,e[e.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED=64]=`DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED`,e[e.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED=65]=`DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED`,e[e.AFTER_DOCTYPE_SYSTEM_IDENTIFIER=66]=`AFTER_DOCTYPE_SYSTEM_IDENTIFIER`,e[e.BOGUS_DOCTYPE=67]=`BOGUS_DOCTYPE`,e[e.CDATA_SECTION=68]=`CDATA_SECTION`,e[e.CDATA_SECTION_BRACKET=69]=`CDATA_SECTION_BRACKET`,e[e.CDATA_SECTION_END=70]=`CDATA_SECTION_END`,e[e.CHARACTER_REFERENCE=71]=`CHARACTER_REFERENCE`,e[e.AMBIGUOUS_AMPERSAND=72]=`AMBIGUOUS_AMPERSAND`})(Y||={});var X={DATA:Y.DATA,RCDATA:Y.RCDATA,RAWTEXT:Y.RAWTEXT,SCRIPT_DATA:Y.SCRIPT_DATA,PLAINTEXT:Y.PLAINTEXT,CDATA_SECTION:Y.CDATA_SECTION};function Ma(e){return e>=B.DIGIT_0&&e<=B.DIGIT_9}function Na(e){return e>=B.LATIN_CAPITAL_A&&e<=B.LATIN_CAPITAL_Z}function Pa(e){return e>=B.LATIN_SMALL_A&&e<=B.LATIN_SMALL_Z}function Fa(e){return Pa(e)||Na(e)}function Ia(e){return Fa(e)||Ma(e)}function La(e){return e+32}function Ra(e){return e===B.SPACE||e===B.LINE_FEED||e===B.TABULATION||e===B.FORM_FEED}function za(e){return Ra(e)||e===B.SOLIDUS||e===B.GREATER_THAN_SIGN}function Ba(e){return e===B.NULL?H.nullCharacterReference:e>1114111?H.characterReferenceOutsideUnicodeRange:_a(e)?H.surrogateCharacterReference:xa(e)?H.noncharacterCharacterReference:ba(e)||e===B.CARRIAGE_RETURN?H.controlCharacterReference:null}var Va=class{constructor(e,t){this.options=e,this.handler=t,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName=``,this.active=!1,this.state=Y.DATA,this.returnState=Y.DATA,this.entityStartPos=0,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:``,value:``},this.preprocessor=new Ca(t),this.currentLocation=this.getCurrentLocation(-1),this.entityDecoder=new Ct(xt,(e,t)=>{this.preprocessor.pos=this.entityStartPos+t-1,this._flushCodePointConsumedAsCharacterReference(e)},t.onParseError?{missingSemicolonAfterCharacterReference:()=>{this._err(H.missingSemicolonAfterCharacterReference,1)},absenceOfDigitsInNumericCharacterReference:e=>{this._err(H.absenceOfDigitsInNumericCharacterReference,this.entityStartPos-this.preprocessor.pos+e)},validateNumericCharacterReference:e=>{let t=Ba(e);t&&this._err(t,1)}}:void 0)}_err(e,t=0){var n,r;(r=(n=this.handler).onParseError)==null||r.call(n,this.preprocessor.getError(e,t))}getCurrentLocation(e){return this.options.sourceCodeLocationInfo?{startLine:this.preprocessor.line,startCol:this.preprocessor.col-e,startOffset:this.preprocessor.offset-e,endLine:-1,endCol:-1,endOffset:-1}:null}_runParsingLoop(){if(!this.inLoop){for(this.inLoop=!0;this.active&&!this.paused;){this.consumedAfterSnapshot=0;let e=this._consume();this._ensureHibernation()||this._callState(e)}this.inLoop=!1}}pause(){this.paused=!0}resume(e){if(!this.paused)throw Error(`Parser was already resumed`);this.paused=!1,!this.inLoop&&(this._runParsingLoop(),this.paused||e?.())}write(e,t,n){this.active=!0,this.preprocessor.write(e,t),this._runParsingLoop(),this.paused||n?.()}insertHtmlAtCurrentPos(e){this.active=!0,this.preprocessor.insertHtmlAtCurrentPos(e),this._runParsingLoop()}_ensureHibernation(){return this.preprocessor.endOfChunkHit?(this.preprocessor.retreat(this.consumedAfterSnapshot),this.consumedAfterSnapshot=0,this.active=!1,!0):!1}_consume(){return this.consumedAfterSnapshot++,this.preprocessor.advance()}_advanceBy(e){this.consumedAfterSnapshot+=e;for(let t=0;t<e;t++)this.preprocessor.advance()}_consumeSequenceIfMatch(e,t){return this.preprocessor.startsWith(e,t)?(this._advanceBy(e.length-1),!0):!1}_createStartTagToken(){this.currentToken={type:U.START_TAG,tagName:``,tagID:q.UNKNOWN,selfClosing:!1,ackSelfClosing:!1,attrs:[],location:this.getCurrentLocation(1)}}_createEndTagToken(){this.currentToken={type:U.END_TAG,tagName:``,tagID:q.UNKNOWN,selfClosing:!1,ackSelfClosing:!1,attrs:[],location:this.getCurrentLocation(2)}}_createCommentToken(e){this.currentToken={type:U.COMMENT,data:``,location:this.getCurrentLocation(e)}}_createDoctypeToken(e){this.currentToken={type:U.DOCTYPE,name:e,forceQuirks:!1,publicId:null,systemId:null,location:this.currentLocation}}_createCharacterToken(e,t){this.currentCharacterToken={type:e,chars:t,location:this.currentLocation}}_createAttr(e){this.currentAttr={name:e,value:``},this.currentLocation=this.getCurrentLocation(0)}_leaveAttrName(){var e;let t=this.currentToken;if(wa(t,this.currentAttr.name)===null){if(t.attrs.push(this.currentAttr),t.location&&this.currentLocation){let n=(e=t.location).attrs??(e.attrs=Object.create(null));n[this.currentAttr.name]=this.currentLocation,this._leaveAttrValue()}}else this._err(H.duplicateAttribute)}_leaveAttrValue(){this.currentLocation&&(this.currentLocation.endLine=this.preprocessor.line,this.currentLocation.endCol=this.preprocessor.col,this.currentLocation.endOffset=this.preprocessor.offset)}prepareToken(e){this._emitCurrentCharacterToken(e.location),this.currentToken=null,e.location&&(e.location.endLine=this.preprocessor.line,e.location.endCol=this.preprocessor.col+1,e.location.endOffset=this.preprocessor.offset+1),this.currentLocation=this.getCurrentLocation(-1)}emitCurrentTagToken(){let e=this.currentToken;this.prepareToken(e),e.tagID=Da(e.tagName),e.type===U.START_TAG?(this.lastStartTagName=e.tagName,this.handler.onStartTag(e)):(e.attrs.length>0&&this._err(H.endTagWithAttributes),e.selfClosing&&this._err(H.endTagWithTrailingSolidus),this.handler.onEndTag(e)),this.preprocessor.dropParsedChunk()}emitCurrentComment(e){this.prepareToken(e),this.handler.onComment(e),this.preprocessor.dropParsedChunk()}emitCurrentDoctype(e){this.prepareToken(e),this.handler.onDoctype(e),this.preprocessor.dropParsedChunk()}_emitCurrentCharacterToken(e){if(this.currentCharacterToken){switch(e&&this.currentCharacterToken.location&&(this.currentCharacterToken.location.endLine=e.startLine,this.currentCharacterToken.location.endCol=e.startCol,this.currentCharacterToken.location.endOffset=e.startOffset),this.currentCharacterToken.type){case U.CHARACTER:this.handler.onCharacter(this.currentCharacterToken);break;case U.NULL_CHARACTER:this.handler.onNullCharacter(this.currentCharacterToken);break;case U.WHITESPACE_CHARACTER:this.handler.onWhitespaceCharacter(this.currentCharacterToken);break}this.currentCharacterToken=null}}_emitEOFToken(){let e=this.getCurrentLocation(0);e&&(e.endLine=e.startLine,e.endCol=e.startCol,e.endOffset=e.startOffset),this._emitCurrentCharacterToken(e),this.handler.onEof({type:U.EOF,location:e}),this.active=!1}_appendCharToCurrentCharacterToken(e,t){if(this.currentCharacterToken)if(this.currentCharacterToken.type===e){this.currentCharacterToken.chars+=t;return}else this.currentLocation=this.getCurrentLocation(0),this._emitCurrentCharacterToken(this.currentLocation),this.preprocessor.dropParsedChunk();this._createCharacterToken(e,t)}_emitCodePoint(e){let t=Ra(e)?U.WHITESPACE_CHARACTER:e===B.NULL?U.NULL_CHARACTER:U.CHARACTER;this._appendCharToCurrentCharacterToken(t,e<65536?String.fromCharCode(e):String.fromCodePoint(e))}_emitChars(e){this._appendCharToCurrentCharacterToken(U.CHARACTER,e)}_startCharacterReference(){this.returnState=this.state,this.state=Y.CHARACTER_REFERENCE,this.entityStartPos=this.preprocessor.pos,this.entityDecoder.startEntity(this._isCharacterReferenceInAttribute()?St.Attribute:St.Legacy)}_isCharacterReferenceInAttribute(){return this.returnState===Y.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===Y.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===Y.ATTRIBUTE_VALUE_UNQUOTED}_flushCodePointConsumedAsCharacterReference(e){this._isCharacterReferenceInAttribute()?this.currentAttr.value+=String.fromCodePoint(e):this._emitCodePoint(e)}_callState(e){switch(this.state){case Y.DATA:this._stateData(e);break;case Y.RCDATA:this._stateRcdata(e);break;case Y.RAWTEXT:this._stateRawtext(e);break;case Y.SCRIPT_DATA:this._stateScriptData(e);break;case Y.PLAINTEXT:this._statePlaintext(e);break;case Y.TAG_OPEN:this._stateTagOpen(e);break;case Y.END_TAG_OPEN:this._stateEndTagOpen(e);break;case Y.TAG_NAME:this._stateTagName(e);break;case Y.RCDATA_LESS_THAN_SIGN:this._stateRcdataLessThanSign(e);break;case Y.RCDATA_END_TAG_OPEN:this._stateRcdataEndTagOpen(e);break;case Y.RCDATA_END_TAG_NAME:this._stateRcdataEndTagName(e);break;case Y.RAWTEXT_LESS_THAN_SIGN:this._stateRawtextLessThanSign(e);break;case Y.RAWTEXT_END_TAG_OPEN:this._stateRawtextEndTagOpen(e);break;case Y.RAWTEXT_END_TAG_NAME:this._stateRawtextEndTagName(e);break;case Y.SCRIPT_DATA_LESS_THAN_SIGN:this._stateScriptDataLessThanSign(e);break;case Y.SCRIPT_DATA_END_TAG_OPEN:this._stateScriptDataEndTagOpen(e);break;case Y.SCRIPT_DATA_END_TAG_NAME:this._stateScriptDataEndTagName(e);break;case Y.SCRIPT_DATA_ESCAPE_START:this._stateScriptDataEscapeStart(e);break;case Y.SCRIPT_DATA_ESCAPE_START_DASH:this._stateScriptDataEscapeStartDash(e);break;case Y.SCRIPT_DATA_ESCAPED:this._stateScriptDataEscaped(e);break;case Y.SCRIPT_DATA_ESCAPED_DASH:this._stateScriptDataEscapedDash(e);break;case Y.SCRIPT_DATA_ESCAPED_DASH_DASH:this._stateScriptDataEscapedDashDash(e);break;case Y.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:this._stateScriptDataEscapedLessThanSign(e);break;case Y.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:this._stateScriptDataEscapedEndTagOpen(e);break;case Y.SCRIPT_DATA_ESCAPED_END_TAG_NAME:this._stateScriptDataEscapedEndTagName(e);break;case Y.SCRIPT_DATA_DOUBLE_ESCAPE_START:this._stateScriptDataDoubleEscapeStart(e);break;case Y.SCRIPT_DATA_DOUBLE_ESCAPED:this._stateScriptDataDoubleEscaped(e);break;case Y.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:this._stateScriptDataDoubleEscapedDash(e);break;case Y.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:this._stateScriptDataDoubleEscapedDashDash(e);break;case Y.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:this._stateScriptDataDoubleEscapedLessThanSign(e);break;case Y.SCRIPT_DATA_DOUBLE_ESCAPE_END:this._stateScriptDataDoubleEscapeEnd(e);break;case Y.BEFORE_ATTRIBUTE_NAME:this._stateBeforeAttributeName(e);break;case Y.ATTRIBUTE_NAME:this._stateAttributeName(e);break;case Y.AFTER_ATTRIBUTE_NAME:this._stateAfterAttributeName(e);break;case Y.BEFORE_ATTRIBUTE_VALUE:this._stateBeforeAttributeValue(e);break;case Y.ATTRIBUTE_VALUE_DOUBLE_QUOTED:this._stateAttributeValueDoubleQuoted(e);break;case Y.ATTRIBUTE_VALUE_SINGLE_QUOTED:this._stateAttributeValueSingleQuoted(e);break;case Y.ATTRIBUTE_VALUE_UNQUOTED:this._stateAttributeValueUnquoted(e);break;case Y.AFTER_ATTRIBUTE_VALUE_QUOTED:this._stateAfterAttributeValueQuoted(e);break;case Y.SELF_CLOSING_START_TAG:this._stateSelfClosingStartTag(e);break;case Y.BOGUS_COMMENT:this._stateBogusComment(e);break;case Y.MARKUP_DECLARATION_OPEN:this._stateMarkupDeclarationOpen(e);break;case Y.COMMENT_START:this._stateCommentStart(e);break;case Y.COMMENT_START_DASH:this._stateCommentStartDash(e);break;case Y.COMMENT:this._stateComment(e);break;case Y.COMMENT_LESS_THAN_SIGN:this._stateCommentLessThanSign(e);break;case Y.COMMENT_LESS_THAN_SIGN_BANG:this._stateCommentLessThanSignBang(e);break;case Y.COMMENT_LESS_THAN_SIGN_BANG_DASH:this._stateCommentLessThanSignBangDash(e);break;case Y.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:this._stateCommentLessThanSignBangDashDash(e);break;case Y.COMMENT_END_DASH:this._stateCommentEndDash(e);break;case Y.COMMENT_END:this._stateCommentEnd(e);break;case Y.COMMENT_END_BANG:this._stateCommentEndBang(e);break;case Y.DOCTYPE:this._stateDoctype(e);break;case Y.BEFORE_DOCTYPE_NAME:this._stateBeforeDoctypeName(e);break;case Y.DOCTYPE_NAME:this._stateDoctypeName(e);break;case Y.AFTER_DOCTYPE_NAME:this._stateAfterDoctypeName(e);break;case Y.AFTER_DOCTYPE_PUBLIC_KEYWORD:this._stateAfterDoctypePublicKeyword(e);break;case Y.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:this._stateBeforeDoctypePublicIdentifier(e);break;case Y.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:this._stateDoctypePublicIdentifierDoubleQuoted(e);break;case Y.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:this._stateDoctypePublicIdentifierSingleQuoted(e);break;case Y.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:this._stateAfterDoctypePublicIdentifier(e);break;case Y.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:this._stateBetweenDoctypePublicAndSystemIdentifiers(e);break;case Y.AFTER_DOCTYPE_SYSTEM_KEYWORD:this._stateAfterDoctypeSystemKeyword(e);break;case Y.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:this._stateBeforeDoctypeSystemIdentifier(e);break;case Y.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:this._stateDoctypeSystemIdentifierDoubleQuoted(e);break;case Y.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:this._stateDoctypeSystemIdentifierSingleQuoted(e);break;case Y.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:this._stateAfterDoctypeSystemIdentifier(e);break;case Y.BOGUS_DOCTYPE:this._stateBogusDoctype(e);break;case Y.CDATA_SECTION:this._stateCdataSection(e);break;case Y.CDATA_SECTION_BRACKET:this._stateCdataSectionBracket(e);break;case Y.CDATA_SECTION_END:this._stateCdataSectionEnd(e);break;case Y.CHARACTER_REFERENCE:this._stateCharacterReference();break;case Y.AMBIGUOUS_AMPERSAND:this._stateAmbiguousAmpersand(e);break;default:throw Error(`Unknown state`)}}_stateData(e){switch(e){case B.LESS_THAN_SIGN:this.state=Y.TAG_OPEN;break;case B.AMPERSAND:this._startCharacterReference();break;case B.NULL:this._err(H.unexpectedNullCharacter),this._emitCodePoint(e);break;case B.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateRcdata(e){switch(e){case B.AMPERSAND:this._startCharacterReference();break;case B.LESS_THAN_SIGN:this.state=Y.RCDATA_LESS_THAN_SIGN;break;case B.NULL:this._err(H.unexpectedNullCharacter),this._emitChars(`�`);break;case B.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateRawtext(e){switch(e){case B.LESS_THAN_SIGN:this.state=Y.RAWTEXT_LESS_THAN_SIGN;break;case B.NULL:this._err(H.unexpectedNullCharacter),this._emitChars(`�`);break;case B.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateScriptData(e){switch(e){case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_LESS_THAN_SIGN;break;case B.NULL:this._err(H.unexpectedNullCharacter),this._emitChars(`�`);break;case B.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_statePlaintext(e){switch(e){case B.NULL:this._err(H.unexpectedNullCharacter),this._emitChars(`�`);break;case B.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateTagOpen(e){if(Fa(e))this._createStartTagToken(),this.state=Y.TAG_NAME,this._stateTagName(e);else switch(e){case B.EXCLAMATION_MARK:this.state=Y.MARKUP_DECLARATION_OPEN;break;case B.SOLIDUS:this.state=Y.END_TAG_OPEN;break;case B.QUESTION_MARK:this._err(H.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=Y.BOGUS_COMMENT,this._stateBogusComment(e);break;case B.EOF:this._err(H.eofBeforeTagName),this._emitChars(`<`),this._emitEOFToken();break;default:this._err(H.invalidFirstCharacterOfTagName),this._emitChars(`<`),this.state=Y.DATA,this._stateData(e)}}_stateEndTagOpen(e){if(Fa(e))this._createEndTagToken(),this.state=Y.TAG_NAME,this._stateTagName(e);else switch(e){case B.GREATER_THAN_SIGN:this._err(H.missingEndTagName),this.state=Y.DATA;break;case B.EOF:this._err(H.eofBeforeTagName),this._emitChars(`</`),this._emitEOFToken();break;default:this._err(H.invalidFirstCharacterOfTagName),this._createCommentToken(2),this.state=Y.BOGUS_COMMENT,this._stateBogusComment(e)}}_stateTagName(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this.state=Y.BEFORE_ATTRIBUTE_NAME;break;case B.SOLIDUS:this.state=Y.SELF_CLOSING_START_TAG;break;case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentTagToken();break;case B.NULL:this._err(H.unexpectedNullCharacter),t.tagName+=`�`;break;case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:t.tagName+=String.fromCodePoint(Na(e)?La(e):e)}}_stateRcdataLessThanSign(e){e===B.SOLIDUS?this.state=Y.RCDATA_END_TAG_OPEN:(this._emitChars(`<`),this.state=Y.RCDATA,this._stateRcdata(e))}_stateRcdataEndTagOpen(e){Fa(e)?(this.state=Y.RCDATA_END_TAG_NAME,this._stateRcdataEndTagName(e)):(this._emitChars(`</`),this.state=Y.RCDATA,this._stateRcdata(e))}handleSpecialEndTag(e){if(!this.preprocessor.startsWith(this.lastStartTagName,!1))return!this._ensureHibernation();this._createEndTagToken();let t=this.currentToken;switch(t.tagName=this.lastStartTagName,this.preprocessor.peek(this.lastStartTagName.length)){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:return this._advanceBy(this.lastStartTagName.length),this.state=Y.BEFORE_ATTRIBUTE_NAME,!1;case B.SOLIDUS:return this._advanceBy(this.lastStartTagName.length),this.state=Y.SELF_CLOSING_START_TAG,!1;case B.GREATER_THAN_SIGN:return this._advanceBy(this.lastStartTagName.length),this.emitCurrentTagToken(),this.state=Y.DATA,!1;default:return!this._ensureHibernation()}}_stateRcdataEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=Y.RCDATA,this._stateRcdata(e))}_stateRawtextLessThanSign(e){e===B.SOLIDUS?this.state=Y.RAWTEXT_END_TAG_OPEN:(this._emitChars(`<`),this.state=Y.RAWTEXT,this._stateRawtext(e))}_stateRawtextEndTagOpen(e){Fa(e)?(this.state=Y.RAWTEXT_END_TAG_NAME,this._stateRawtextEndTagName(e)):(this._emitChars(`</`),this.state=Y.RAWTEXT,this._stateRawtext(e))}_stateRawtextEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=Y.RAWTEXT,this._stateRawtext(e))}_stateScriptDataLessThanSign(e){switch(e){case B.SOLIDUS:this.state=Y.SCRIPT_DATA_END_TAG_OPEN;break;case B.EXCLAMATION_MARK:this.state=Y.SCRIPT_DATA_ESCAPE_START,this._emitChars(`<!`);break;default:this._emitChars(`<`),this.state=Y.SCRIPT_DATA,this._stateScriptData(e)}}_stateScriptDataEndTagOpen(e){Fa(e)?(this.state=Y.SCRIPT_DATA_END_TAG_NAME,this._stateScriptDataEndTagName(e)):(this._emitChars(`</`),this.state=Y.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=Y.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEscapeStart(e){e===B.HYPHEN_MINUS?(this.state=Y.SCRIPT_DATA_ESCAPE_START_DASH,this._emitChars(`-`)):(this.state=Y.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEscapeStartDash(e){e===B.HYPHEN_MINUS?(this.state=Y.SCRIPT_DATA_ESCAPED_DASH_DASH,this._emitChars(`-`)):(this.state=Y.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEscaped(e){switch(e){case B.HYPHEN_MINUS:this.state=Y.SCRIPT_DATA_ESCAPED_DASH,this._emitChars(`-`);break;case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;break;case B.NULL:this._err(H.unexpectedNullCharacter),this._emitChars(`�`);break;case B.EOF:this._err(H.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateScriptDataEscapedDash(e){switch(e){case B.HYPHEN_MINUS:this.state=Y.SCRIPT_DATA_ESCAPED_DASH_DASH,this._emitChars(`-`);break;case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;break;case B.NULL:this._err(H.unexpectedNullCharacter),this.state=Y.SCRIPT_DATA_ESCAPED,this._emitChars(`�`);break;case B.EOF:this._err(H.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=Y.SCRIPT_DATA_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataEscapedDashDash(e){switch(e){case B.HYPHEN_MINUS:this._emitChars(`-`);break;case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;break;case B.GREATER_THAN_SIGN:this.state=Y.SCRIPT_DATA,this._emitChars(`>`);break;case B.NULL:this._err(H.unexpectedNullCharacter),this.state=Y.SCRIPT_DATA_ESCAPED,this._emitChars(`�`);break;case B.EOF:this._err(H.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=Y.SCRIPT_DATA_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataEscapedLessThanSign(e){e===B.SOLIDUS?this.state=Y.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Fa(e)?(this._emitChars(`<`),this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(e)):(this._emitChars(`<`),this.state=Y.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataEscapedEndTagOpen(e){Fa(e)?(this.state=Y.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(e)):(this._emitChars(`</`),this.state=Y.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataEscapedEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=Y.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataDoubleEscapeStart(e){if(this.preprocessor.startsWith(V.SCRIPT,!1)&&za(this.preprocessor.peek(V.SCRIPT.length))){this._emitCodePoint(e);for(let e=0;e<V.SCRIPT.length;e++)this._emitCodePoint(this._consume());this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED}else this._ensureHibernation()||(this.state=Y.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataDoubleEscaped(e){switch(e){case B.HYPHEN_MINUS:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED_DASH,this._emitChars(`-`);break;case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN,this._emitChars(`<`);break;case B.NULL:this._err(H.unexpectedNullCharacter),this._emitChars(`�`);break;case B.EOF:this._err(H.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateScriptDataDoubleEscapedDash(e){switch(e){case B.HYPHEN_MINUS:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH,this._emitChars(`-`);break;case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN,this._emitChars(`<`);break;case B.NULL:this._err(H.unexpectedNullCharacter),this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(`�`);break;case B.EOF:this._err(H.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataDoubleEscapedDashDash(e){switch(e){case B.HYPHEN_MINUS:this._emitChars(`-`);break;case B.LESS_THAN_SIGN:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN,this._emitChars(`<`);break;case B.GREATER_THAN_SIGN:this.state=Y.SCRIPT_DATA,this._emitChars(`>`);break;case B.NULL:this._err(H.unexpectedNullCharacter),this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(`�`);break;case B.EOF:this._err(H.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataDoubleEscapedLessThanSign(e){e===B.SOLIDUS?(this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars(`/`)):(this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(e))}_stateScriptDataDoubleEscapeEnd(e){if(this.preprocessor.startsWith(V.SCRIPT,!1)&&za(this.preprocessor.peek(V.SCRIPT.length))){this._emitCodePoint(e);for(let e=0;e<V.SCRIPT.length;e++)this._emitCodePoint(this._consume());this.state=Y.SCRIPT_DATA_ESCAPED}else this._ensureHibernation()||(this.state=Y.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(e))}_stateBeforeAttributeName(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.SOLIDUS:case B.GREATER_THAN_SIGN:case B.EOF:this.state=Y.AFTER_ATTRIBUTE_NAME,this._stateAfterAttributeName(e);break;case B.EQUALS_SIGN:this._err(H.unexpectedEqualsSignBeforeAttributeName),this._createAttr(`=`),this.state=Y.ATTRIBUTE_NAME;break;default:this._createAttr(``),this.state=Y.ATTRIBUTE_NAME,this._stateAttributeName(e)}}_stateAttributeName(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:case B.SOLIDUS:case B.GREATER_THAN_SIGN:case B.EOF:this._leaveAttrName(),this.state=Y.AFTER_ATTRIBUTE_NAME,this._stateAfterAttributeName(e);break;case B.EQUALS_SIGN:this._leaveAttrName(),this.state=Y.BEFORE_ATTRIBUTE_VALUE;break;case B.QUOTATION_MARK:case B.APOSTROPHE:case B.LESS_THAN_SIGN:this._err(H.unexpectedCharacterInAttributeName),this.currentAttr.name+=String.fromCodePoint(e);break;case B.NULL:this._err(H.unexpectedNullCharacter),this.currentAttr.name+=`�`;break;default:this.currentAttr.name+=String.fromCodePoint(Na(e)?La(e):e)}}_stateAfterAttributeName(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.SOLIDUS:this.state=Y.SELF_CLOSING_START_TAG;break;case B.EQUALS_SIGN:this.state=Y.BEFORE_ATTRIBUTE_VALUE;break;case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentTagToken();break;case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:this._createAttr(``),this.state=Y.ATTRIBUTE_NAME,this._stateAttributeName(e)}}_stateBeforeAttributeValue(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.QUOTATION_MARK:this.state=Y.ATTRIBUTE_VALUE_DOUBLE_QUOTED;break;case B.APOSTROPHE:this.state=Y.ATTRIBUTE_VALUE_SINGLE_QUOTED;break;case B.GREATER_THAN_SIGN:this._err(H.missingAttributeValue),this.state=Y.DATA,this.emitCurrentTagToken();break;default:this.state=Y.ATTRIBUTE_VALUE_UNQUOTED,this._stateAttributeValueUnquoted(e)}}_stateAttributeValueDoubleQuoted(e){switch(e){case B.QUOTATION_MARK:this.state=Y.AFTER_ATTRIBUTE_VALUE_QUOTED;break;case B.AMPERSAND:this._startCharacterReference();break;case B.NULL:this._err(H.unexpectedNullCharacter),this.currentAttr.value+=`�`;break;case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:this.currentAttr.value+=String.fromCodePoint(e)}}_stateAttributeValueSingleQuoted(e){switch(e){case B.APOSTROPHE:this.state=Y.AFTER_ATTRIBUTE_VALUE_QUOTED;break;case B.AMPERSAND:this._startCharacterReference();break;case B.NULL:this._err(H.unexpectedNullCharacter),this.currentAttr.value+=`�`;break;case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:this.currentAttr.value+=String.fromCodePoint(e)}}_stateAttributeValueUnquoted(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this._leaveAttrValue(),this.state=Y.BEFORE_ATTRIBUTE_NAME;break;case B.AMPERSAND:this._startCharacterReference();break;case B.GREATER_THAN_SIGN:this._leaveAttrValue(),this.state=Y.DATA,this.emitCurrentTagToken();break;case B.NULL:this._err(H.unexpectedNullCharacter),this.currentAttr.value+=`�`;break;case B.QUOTATION_MARK:case B.APOSTROPHE:case B.LESS_THAN_SIGN:case B.EQUALS_SIGN:case B.GRAVE_ACCENT:this._err(H.unexpectedCharacterInUnquotedAttributeValue),this.currentAttr.value+=String.fromCodePoint(e);break;case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:this.currentAttr.value+=String.fromCodePoint(e)}}_stateAfterAttributeValueQuoted(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this._leaveAttrValue(),this.state=Y.BEFORE_ATTRIBUTE_NAME;break;case B.SOLIDUS:this._leaveAttrValue(),this.state=Y.SELF_CLOSING_START_TAG;break;case B.GREATER_THAN_SIGN:this._leaveAttrValue(),this.state=Y.DATA,this.emitCurrentTagToken();break;case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:this._err(H.missingWhitespaceBetweenAttributes),this.state=Y.BEFORE_ATTRIBUTE_NAME,this._stateBeforeAttributeName(e)}}_stateSelfClosingStartTag(e){switch(e){case B.GREATER_THAN_SIGN:{let e=this.currentToken;e.selfClosing=!0,this.state=Y.DATA,this.emitCurrentTagToken();break}case B.EOF:this._err(H.eofInTag),this._emitEOFToken();break;default:this._err(H.unexpectedSolidusInTag),this.state=Y.BEFORE_ATTRIBUTE_NAME,this._stateBeforeAttributeName(e)}}_stateBogusComment(e){let t=this.currentToken;switch(e){case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentComment(t);break;case B.EOF:this.emitCurrentComment(t),this._emitEOFToken();break;case B.NULL:this._err(H.unexpectedNullCharacter),t.data+=`�`;break;default:t.data+=String.fromCodePoint(e)}}_stateMarkupDeclarationOpen(e){this._consumeSequenceIfMatch(V.DASH_DASH,!0)?(this._createCommentToken(V.DASH_DASH.length+1),this.state=Y.COMMENT_START):this._consumeSequenceIfMatch(V.DOCTYPE,!1)?(this.currentLocation=this.getCurrentLocation(V.DOCTYPE.length+1),this.state=Y.DOCTYPE):this._consumeSequenceIfMatch(V.CDATA_START,!0)?this.inForeignNode?this.state=Y.CDATA_SECTION:(this._err(H.cdataInHtmlContent),this._createCommentToken(V.CDATA_START.length+1),this.currentToken.data=`[CDATA[`,this.state=Y.BOGUS_COMMENT):this._ensureHibernation()||(this._err(H.incorrectlyOpenedComment),this._createCommentToken(2),this.state=Y.BOGUS_COMMENT,this._stateBogusComment(e))}_stateCommentStart(e){switch(e){case B.HYPHEN_MINUS:this.state=Y.COMMENT_START_DASH;break;case B.GREATER_THAN_SIGN:{this._err(H.abruptClosingOfEmptyComment),this.state=Y.DATA;let e=this.currentToken;this.emitCurrentComment(e);break}default:this.state=Y.COMMENT,this._stateComment(e)}}_stateCommentStartDash(e){let t=this.currentToken;switch(e){case B.HYPHEN_MINUS:this.state=Y.COMMENT_END;break;case B.GREATER_THAN_SIGN:this._err(H.abruptClosingOfEmptyComment),this.state=Y.DATA,this.emitCurrentComment(t);break;case B.EOF:this._err(H.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`-`,this.state=Y.COMMENT,this._stateComment(e)}}_stateComment(e){let t=this.currentToken;switch(e){case B.HYPHEN_MINUS:this.state=Y.COMMENT_END_DASH;break;case B.LESS_THAN_SIGN:t.data+=`<`,this.state=Y.COMMENT_LESS_THAN_SIGN;break;case B.NULL:this._err(H.unexpectedNullCharacter),t.data+=`�`;break;case B.EOF:this._err(H.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=String.fromCodePoint(e)}}_stateCommentLessThanSign(e){let t=this.currentToken;switch(e){case B.EXCLAMATION_MARK:t.data+=`!`,this.state=Y.COMMENT_LESS_THAN_SIGN_BANG;break;case B.LESS_THAN_SIGN:t.data+=`<`;break;default:this.state=Y.COMMENT,this._stateComment(e)}}_stateCommentLessThanSignBang(e){e===B.HYPHEN_MINUS?this.state=Y.COMMENT_LESS_THAN_SIGN_BANG_DASH:(this.state=Y.COMMENT,this._stateComment(e))}_stateCommentLessThanSignBangDash(e){e===B.HYPHEN_MINUS?this.state=Y.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:(this.state=Y.COMMENT_END_DASH,this._stateCommentEndDash(e))}_stateCommentLessThanSignBangDashDash(e){e!==B.GREATER_THAN_SIGN&&e!==B.EOF&&this._err(H.nestedComment),this.state=Y.COMMENT_END,this._stateCommentEnd(e)}_stateCommentEndDash(e){let t=this.currentToken;switch(e){case B.HYPHEN_MINUS:this.state=Y.COMMENT_END;break;case B.EOF:this._err(H.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`-`,this.state=Y.COMMENT,this._stateComment(e)}}_stateCommentEnd(e){let t=this.currentToken;switch(e){case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentComment(t);break;case B.EXCLAMATION_MARK:this.state=Y.COMMENT_END_BANG;break;case B.HYPHEN_MINUS:t.data+=`-`;break;case B.EOF:this._err(H.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`--`,this.state=Y.COMMENT,this._stateComment(e)}}_stateCommentEndBang(e){let t=this.currentToken;switch(e){case B.HYPHEN_MINUS:t.data+=`--!`,this.state=Y.COMMENT_END_DASH;break;case B.GREATER_THAN_SIGN:this._err(H.incorrectlyClosedComment),this.state=Y.DATA,this.emitCurrentComment(t);break;case B.EOF:this._err(H.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`--!`,this.state=Y.COMMENT,this._stateComment(e)}}_stateDoctype(e){switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this.state=Y.BEFORE_DOCTYPE_NAME;break;case B.GREATER_THAN_SIGN:this.state=Y.BEFORE_DOCTYPE_NAME,this._stateBeforeDoctypeName(e);break;case B.EOF:{this._err(H.eofInDoctype),this._createDoctypeToken(null);let e=this.currentToken;e.forceQuirks=!0,this.emitCurrentDoctype(e),this._emitEOFToken();break}default:this._err(H.missingWhitespaceBeforeDoctypeName),this.state=Y.BEFORE_DOCTYPE_NAME,this._stateBeforeDoctypeName(e)}}_stateBeforeDoctypeName(e){if(Na(e))this._createDoctypeToken(String.fromCharCode(La(e))),this.state=Y.DOCTYPE_NAME;else switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.NULL:this._err(H.unexpectedNullCharacter),this._createDoctypeToken(`�`),this.state=Y.DOCTYPE_NAME;break;case B.GREATER_THAN_SIGN:{this._err(H.missingDoctypeName),this._createDoctypeToken(null);let e=this.currentToken;e.forceQuirks=!0,this.emitCurrentDoctype(e),this.state=Y.DATA;break}case B.EOF:{this._err(H.eofInDoctype),this._createDoctypeToken(null);let e=this.currentToken;e.forceQuirks=!0,this.emitCurrentDoctype(e),this._emitEOFToken();break}default:this._createDoctypeToken(String.fromCodePoint(e)),this.state=Y.DOCTYPE_NAME}}_stateDoctypeName(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this.state=Y.AFTER_DOCTYPE_NAME;break;case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.NULL:this._err(H.unexpectedNullCharacter),t.name+=`�`;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:t.name+=String.fromCodePoint(Na(e)?La(e):e)}}_stateAfterDoctypeName(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._consumeSequenceIfMatch(V.PUBLIC,!1)?this.state=Y.AFTER_DOCTYPE_PUBLIC_KEYWORD:this._consumeSequenceIfMatch(V.SYSTEM,!1)?this.state=Y.AFTER_DOCTYPE_SYSTEM_KEYWORD:this._ensureHibernation()||(this._err(H.invalidCharacterSequenceAfterDoctypeName),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e))}}_stateAfterDoctypePublicKeyword(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this.state=Y.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER;break;case B.QUOTATION_MARK:this._err(H.missingWhitespaceAfterDoctypePublicKeyword),t.publicId=``,this.state=Y.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;break;case B.APOSTROPHE:this._err(H.missingWhitespaceAfterDoctypePublicKeyword),t.publicId=``,this.state=Y.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;break;case B.GREATER_THAN_SIGN:this._err(H.missingDoctypePublicIdentifier),t.forceQuirks=!0,this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.missingQuoteBeforeDoctypePublicIdentifier),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBeforeDoctypePublicIdentifier(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.QUOTATION_MARK:t.publicId=``,this.state=Y.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;break;case B.APOSTROPHE:t.publicId=``,this.state=Y.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;break;case B.GREATER_THAN_SIGN:this._err(H.missingDoctypePublicIdentifier),t.forceQuirks=!0,this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.missingQuoteBeforeDoctypePublicIdentifier),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateDoctypePublicIdentifierDoubleQuoted(e){let t=this.currentToken;switch(e){case B.QUOTATION_MARK:this.state=Y.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;break;case B.NULL:this._err(H.unexpectedNullCharacter),t.publicId+=`�`;break;case B.GREATER_THAN_SIGN:this._err(H.abruptDoctypePublicIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:t.publicId+=String.fromCodePoint(e)}}_stateDoctypePublicIdentifierSingleQuoted(e){let t=this.currentToken;switch(e){case B.APOSTROPHE:this.state=Y.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;break;case B.NULL:this._err(H.unexpectedNullCharacter),t.publicId+=`�`;break;case B.GREATER_THAN_SIGN:this._err(H.abruptDoctypePublicIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:t.publicId+=String.fromCodePoint(e)}}_stateAfterDoctypePublicIdentifier(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this.state=Y.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS;break;case B.GREATER_THAN_SIGN:this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.QUOTATION_MARK:this._err(H.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers),t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case B.APOSTROPHE:this._err(H.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers),t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBetweenDoctypePublicAndSystemIdentifiers(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.GREATER_THAN_SIGN:this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.QUOTATION_MARK:t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case B.APOSTROPHE:t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateAfterDoctypeSystemKeyword(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:this.state=Y.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER;break;case B.QUOTATION_MARK:this._err(H.missingWhitespaceAfterDoctypeSystemKeyword),t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case B.APOSTROPHE:this._err(H.missingWhitespaceAfterDoctypeSystemKeyword),t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case B.GREATER_THAN_SIGN:this._err(H.missingDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBeforeDoctypeSystemIdentifier(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.QUOTATION_MARK:t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case B.APOSTROPHE:t.systemId=``,this.state=Y.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case B.GREATER_THAN_SIGN:this._err(H.missingDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=Y.DATA,this.emitCurrentDoctype(t);break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateDoctypeSystemIdentifierDoubleQuoted(e){let t=this.currentToken;switch(e){case B.QUOTATION_MARK:this.state=Y.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;break;case B.NULL:this._err(H.unexpectedNullCharacter),t.systemId+=`�`;break;case B.GREATER_THAN_SIGN:this._err(H.abruptDoctypeSystemIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:t.systemId+=String.fromCodePoint(e)}}_stateDoctypeSystemIdentifierSingleQuoted(e){let t=this.currentToken;switch(e){case B.APOSTROPHE:this.state=Y.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;break;case B.NULL:this._err(H.unexpectedNullCharacter),t.systemId+=`�`;break;case B.GREATER_THAN_SIGN:this._err(H.abruptDoctypeSystemIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:t.systemId+=String.fromCodePoint(e)}}_stateAfterDoctypeSystemIdentifier(e){let t=this.currentToken;switch(e){case B.SPACE:case B.LINE_FEED:case B.TABULATION:case B.FORM_FEED:break;case B.GREATER_THAN_SIGN:this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.EOF:this._err(H.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(H.unexpectedCharacterAfterDoctypeSystemIdentifier),this.state=Y.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBogusDoctype(e){let t=this.currentToken;switch(e){case B.GREATER_THAN_SIGN:this.emitCurrentDoctype(t),this.state=Y.DATA;break;case B.NULL:this._err(H.unexpectedNullCharacter);break;case B.EOF:this.emitCurrentDoctype(t),this._emitEOFToken();break;default:}}_stateCdataSection(e){switch(e){case B.RIGHT_SQUARE_BRACKET:this.state=Y.CDATA_SECTION_BRACKET;break;case B.EOF:this._err(H.eofInCdata),this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateCdataSectionBracket(e){e===B.RIGHT_SQUARE_BRACKET?this.state=Y.CDATA_SECTION_END:(this._emitChars(`]`),this.state=Y.CDATA_SECTION,this._stateCdataSection(e))}_stateCdataSectionEnd(e){switch(e){case B.GREATER_THAN_SIGN:this.state=Y.DATA;break;case B.RIGHT_SQUARE_BRACKET:this._emitChars(`]`);break;default:this._emitChars(`]]`),this.state=Y.CDATA_SECTION,this._stateCdataSection(e)}}_stateCharacterReference(){let e=this.entityDecoder.write(this.preprocessor.html,this.preprocessor.pos);if(e<0)if(this.preprocessor.lastChunkWritten)e=this.entityDecoder.end();else{this.active=!1,this.preprocessor.pos=this.preprocessor.html.length-1,this.consumedAfterSnapshot=0,this.preprocessor.endOfChunkHit=!0;return}e===0?(this.preprocessor.pos=this.entityStartPos,this._flushCodePointConsumedAsCharacterReference(B.AMPERSAND),this.state=!this._isCharacterReferenceInAttribute()&&Ia(this.preprocessor.peek(1))?Y.AMBIGUOUS_AMPERSAND:this.returnState):this.state=this.returnState}_stateAmbiguousAmpersand(e){Ia(e)?this._flushCodePointConsumedAsCharacterReference(e):(e===B.SEMICOLON&&this._err(H.unknownNamedCharacterReference),this.state=this.returnState,this._callState(e))}},Ha=new Set([q.DD,q.DT,q.LI,q.OPTGROUP,q.OPTION,q.P,q.RB,q.RP,q.RT,q.RTC]),Ua=new Set([...Ha,q.CAPTION,q.COLGROUP,q.TBODY,q.TD,q.TFOOT,q.TH,q.THEAD,q.TR]),Wa=new Set([q.APPLET,q.CAPTION,q.HTML,q.MARQUEE,q.OBJECT,q.TABLE,q.TD,q.TEMPLATE,q.TH]),Ga=new Set([...Wa,q.OL,q.UL]),Ka=new Set([...Wa,q.BUTTON]),qa=new Set([q.ANNOTATION_XML,q.MI,q.MN,q.MO,q.MS,q.MTEXT]),Ja=new Set([q.DESC,q.FOREIGN_OBJECT,q.TITLE]),Ya=new Set([q.TR,q.TEMPLATE,q.HTML]),Xa=new Set([q.TBODY,q.TFOOT,q.THEAD,q.TEMPLATE,q.HTML]),Za=new Set([q.TABLE,q.TEMPLATE,q.HTML]),Qa=new Set([q.TD,q.TH]),$a=class{get currentTmplContentOrNode(){return this._isInTemplate()?this.treeAdapter.getTemplateContent(this.current):this.current}constructor(e,t,n){this.treeAdapter=t,this.handler=n,this.items=[],this.tagIDs=[],this.stackTop=-1,this.tmplCount=0,this.currentTagId=q.UNKNOWN,this.current=e}_indexOf(e){return this.items.lastIndexOf(e,this.stackTop)}_isInTemplate(){return this.currentTagId===q.TEMPLATE&&this.treeAdapter.getNamespaceURI(this.current)===W.HTML}_updateCurrentElement(){this.current=this.items[this.stackTop],this.currentTagId=this.tagIDs[this.stackTop]}push(e,t){this.stackTop++,this.items[this.stackTop]=e,this.current=e,this.tagIDs[this.stackTop]=t,this.currentTagId=t,this._isInTemplate()&&this.tmplCount++,this.handler.onItemPush(e,t,!0)}pop(){let e=this.current;this.tmplCount>0&&this._isInTemplate()&&this.tmplCount--,this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(e,!0)}replace(e,t){let n=this._indexOf(e);this.items[n]=t,n===this.stackTop&&(this.current=t)}insertAfter(e,t,n){let r=this._indexOf(e)+1;this.items.splice(r,0,t),this.tagIDs.splice(r,0,n),this.stackTop++,r===this.stackTop&&this._updateCurrentElement(),this.current&&this.currentTagId!==void 0&&this.handler.onItemPush(this.current,this.currentTagId,r===this.stackTop)}popUntilTagNamePopped(e){let t=this.stackTop+1;do t=this.tagIDs.lastIndexOf(e,t-1);while(t>0&&this.treeAdapter.getNamespaceURI(this.items[t])!==W.HTML);this.shortenToLength(Math.max(t,0))}shortenToLength(e){for(;this.stackTop>=e;){let t=this.current;this.tmplCount>0&&this._isInTemplate()&&--this.tmplCount,this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(t,this.stackTop<e)}}popUntilElementPopped(e){let t=this._indexOf(e);this.shortenToLength(Math.max(t,0))}popUntilPopped(e,t){let n=this._indexOfTagNames(e,t);this.shortenToLength(Math.max(n,0))}popUntilNumberedHeaderPopped(){this.popUntilPopped(ka,W.HTML)}popUntilTableCellPopped(){this.popUntilPopped(Qa,W.HTML)}popAllUpToHtmlElement(){this.tmplCount=0,this.shortenToLength(1)}_indexOfTagNames(e,t){for(let n=this.stackTop;n>=0;n--)if(e.has(this.tagIDs[n])&&this.treeAdapter.getNamespaceURI(this.items[n])===t)return n;return-1}clearBackTo(e,t){let n=this._indexOfTagNames(e,t);this.shortenToLength(n+1)}clearBackToTableContext(){this.clearBackTo(Za,W.HTML)}clearBackToTableBodyContext(){this.clearBackTo(Xa,W.HTML)}clearBackToTableRowContext(){this.clearBackTo(Ya,W.HTML)}remove(e){let t=this._indexOf(e);t>=0&&(t===this.stackTop?this.pop():(this.items.splice(t,1),this.tagIDs.splice(t,1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(e,!1)))}tryPeekProperlyNestedBodyElement(){return this.stackTop>=1&&this.tagIDs[1]===q.BODY?this.items[1]:null}contains(e){return this._indexOf(e)>-1}getCommonAncestor(e){let t=this._indexOf(e)-1;return t>=0?this.items[t]:null}isRootHtmlElementCurrent(){return this.stackTop===0&&this.tagIDs[0]===q.HTML}hasInDynamicScope(e,t){for(let n=this.stackTop;n>=0;n--){let r=this.tagIDs[n];switch(this.treeAdapter.getNamespaceURI(this.items[n])){case W.HTML:if(r===e)return!0;if(t.has(r))return!1;break;case W.SVG:if(Ja.has(r))return!1;break;case W.MATHML:if(qa.has(r))return!1;break}}return!0}hasInScope(e){return this.hasInDynamicScope(e,Wa)}hasInListItemScope(e){return this.hasInDynamicScope(e,Ga)}hasInButtonScope(e){return this.hasInDynamicScope(e,Ka)}hasNumberedHeaderInScope(){for(let e=this.stackTop;e>=0;e--){let t=this.tagIDs[e];switch(this.treeAdapter.getNamespaceURI(this.items[e])){case W.HTML:if(ka.has(t))return!0;if(Wa.has(t))return!1;break;case W.SVG:if(Ja.has(t))return!1;break;case W.MATHML:if(qa.has(t))return!1;break}}return!0}hasInTableScope(e){for(let t=this.stackTop;t>=0;t--)if(this.treeAdapter.getNamespaceURI(this.items[t])===W.HTML)switch(this.tagIDs[t]){case e:return!0;case q.TABLE:case q.HTML:return!1}return!0}hasTableBodyContextInTableScope(){for(let e=this.stackTop;e>=0;e--)if(this.treeAdapter.getNamespaceURI(this.items[e])===W.HTML)switch(this.tagIDs[e]){case q.TBODY:case q.THEAD:case q.TFOOT:return!0;case q.TABLE:case q.HTML:return!1}return!0}hasInSelectScope(e){for(let t=this.stackTop;t>=0;t--)if(this.treeAdapter.getNamespaceURI(this.items[t])===W.HTML)switch(this.tagIDs[t]){case e:return!0;case q.OPTION:case q.OPTGROUP:break;default:return!1}return!0}generateImpliedEndTags(){for(;this.currentTagId!==void 0&&Ha.has(this.currentTagId);)this.pop()}generateImpliedEndTagsThoroughly(){for(;this.currentTagId!==void 0&&Ua.has(this.currentTagId);)this.pop()}generateImpliedEndTagsWithExclusion(e){for(;this.currentTagId!==void 0&&this.currentTagId!==e&&Ua.has(this.currentTagId);)this.pop()}},eo=3,to;(function(e){e[e.Marker=0]=`Marker`,e[e.Element=1]=`Element`})(to||={});var no={type:to.Marker},ro=class{constructor(e){this.treeAdapter=e,this.entries=[],this.bookmark=null}_getNoahArkConditionCandidates(e,t){let n=[],r=t.length,i=this.treeAdapter.getTagName(e),a=this.treeAdapter.getNamespaceURI(e);for(let e=0;e<this.entries.length;e++){let t=this.entries[e];if(t.type===to.Marker)break;let{element:o}=t;if(this.treeAdapter.getTagName(o)===i&&this.treeAdapter.getNamespaceURI(o)===a){let t=this.treeAdapter.getAttrList(o);t.length===r&&n.push({idx:e,attrs:t})}}return n}_ensureNoahArkCondition(e){if(this.entries.length<eo)return;let t=this.treeAdapter.getAttrList(e),n=this._getNoahArkConditionCandidates(e,t);if(n.length<eo)return;let r=new Map(t.map(e=>[e.name,e.value])),i=0;for(let e=0;e<n.length;e++){let t=n[e];t.attrs.every(e=>r.get(e.name)===e.value)&&(i+=1,i>=eo&&this.entries.splice(t.idx,1))}}insertMarker(){this.entries.unshift(no)}pushElement(e,t){this._ensureNoahArkCondition(e),this.entries.unshift({type:to.Element,element:e,token:t})}insertElementAfterBookmark(e,t){let n=this.entries.indexOf(this.bookmark);this.entries.splice(n,0,{type:to.Element,element:e,token:t})}removeEntry(e){let t=this.entries.indexOf(e);t!==-1&&this.entries.splice(t,1)}clearToLastMarker(){let e=this.entries.indexOf(no);e===-1?this.entries.length=0:this.entries.splice(0,e+1)}getElementEntryInScopeWithTagName(e){let t=this.entries.find(t=>t.type===to.Marker||this.treeAdapter.getTagName(t.element)===e);return t&&t.type===to.Element?t:null}getElementEntry(e){return this.entries.find(t=>t.type===to.Element&&t.element===e)}},io={createDocument(){return{nodeName:`#document`,mode:G.NO_QUIRKS,childNodes:[]}},createDocumentFragment(){return{nodeName:`#document-fragment`,childNodes:[]}},createElement(e,t,n){return{nodeName:e,tagName:e,attrs:n,namespaceURI:t,childNodes:[],parentNode:null}},createCommentNode(e){return{nodeName:`#comment`,data:e,parentNode:null}},createTextNode(e){return{nodeName:`#text`,value:e,parentNode:null}},appendChild(e,t){e.childNodes.push(t),t.parentNode=e},insertBefore(e,t,n){let r=e.childNodes.indexOf(n);e.childNodes.splice(r,0,t),t.parentNode=e},setTemplateContent(e,t){e.content=t},getTemplateContent(e){return e.content},setDocumentType(e,t,n,r){let i=e.childNodes.find(e=>e.nodeName===`#documentType`);if(i)i.name=t,i.publicId=n,i.systemId=r;else{let i={nodeName:`#documentType`,name:t,publicId:n,systemId:r,parentNode:null};io.appendChild(e,i)}},setDocumentMode(e,t){e.mode=t},getDocumentMode(e){return e.mode},detachNode(e){if(e.parentNode){let t=e.parentNode.childNodes.indexOf(e);e.parentNode.childNodes.splice(t,1),e.parentNode=null}},insertText(e,t){if(e.childNodes.length>0){let n=e.childNodes[e.childNodes.length-1];if(io.isTextNode(n)){n.value+=t;return}}io.appendChild(e,io.createTextNode(t))},insertTextBefore(e,t,n){let r=e.childNodes[e.childNodes.indexOf(n)-1];r&&io.isTextNode(r)?r.value+=t:io.insertBefore(e,io.createTextNode(t),n)},adoptAttributes(e,t){let n=new Set(e.attrs.map(e=>e.name));for(let r=0;r<t.length;r++)n.has(t[r].name)||e.attrs.push(t[r])},getFirstChild(e){return e.childNodes[0]},getChildNodes(e){return e.childNodes},getParentNode(e){return e.parentNode},getAttrList(e){return e.attrs},getTagName(e){return e.tagName},getNamespaceURI(e){return e.namespaceURI},getTextNodeContent(e){return e.value},getCommentNodeContent(e){return e.data},getDocumentTypeNodeName(e){return e.name},getDocumentTypeNodePublicId(e){return e.publicId},getDocumentTypeNodeSystemId(e){return e.systemId},isTextNode(e){return e.nodeName===`#text`},isCommentNode(e){return e.nodeName===`#comment`},isDocumentTypeNode(e){return e.nodeName===`#documentType`},isElementNode(e){return Object.prototype.hasOwnProperty.call(e,`tagName`)},setNodeSourceCodeLocation(e,t){e.sourceCodeLocation=t},getNodeSourceCodeLocation(e){return e.sourceCodeLocation},updateNodeSourceCodeLocation(e,t){e.sourceCodeLocation={...e.sourceCodeLocation,...t}}},ao=`html`,oo=`about:legacy-compat`,so=`http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd`,co=`+//silmaril//dtd html pro v0r11 19970101//,-//as//dtd html 3.0 aswedit + extensions//,-//advasoft ltd//dtd html 3.0 aswedit + extensions//,-//ietf//dtd html 2.0 level 1//,-//ietf//dtd html 2.0 level 2//,-//ietf//dtd html 2.0 strict level 1//,-//ietf//dtd html 2.0 strict level 2//,-//ietf//dtd html 2.0 strict//,-//ietf//dtd html 2.0//,-//ietf//dtd html 2.1e//,-//ietf//dtd html 3.0//,-//ietf//dtd html 3.2 final//,-//ietf//dtd html 3.2//,-//ietf//dtd html 3//,-//ietf//dtd html level 0//,-//ietf//dtd html level 1//,-//ietf//dtd html level 2//,-//ietf//dtd html level 3//,-//ietf//dtd html strict level 0//,-//ietf//dtd html strict level 1//,-//ietf//dtd html strict level 2//,-//ietf//dtd html strict level 3//,-//ietf//dtd html strict//,-//ietf//dtd html//,-//metrius//dtd metrius presentational//,-//microsoft//dtd internet explorer 2.0 html strict//,-//microsoft//dtd internet explorer 2.0 html//,-//microsoft//dtd internet explorer 2.0 tables//,-//microsoft//dtd internet explorer 3.0 html strict//,-//microsoft//dtd internet explorer 3.0 html//,-//microsoft//dtd internet explorer 3.0 tables//,-//netscape comm. corp.//dtd html//,-//netscape comm. corp.//dtd strict html//,-//o'reilly and associates//dtd html 2.0//,-//o'reilly and associates//dtd html extended 1.0//,-//o'reilly and associates//dtd html extended relaxed 1.0//,-//sq//dtd html 2.0 hotmetal + extensions//,-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//,-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//,-//spyglass//dtd html 2.0 extended//,-//sun microsystems corp.//dtd hotjava html//,-//sun microsystems corp.//dtd hotjava strict html//,-//w3c//dtd html 3 1995-03-24//,-//w3c//dtd html 3.2 draft//,-//w3c//dtd html 3.2 final//,-//w3c//dtd html 3.2//,-//w3c//dtd html 3.2s draft//,-//w3c//dtd html 4.0 frameset//,-//w3c//dtd html 4.0 transitional//,-//w3c//dtd html experimental 19960712//,-//w3c//dtd html experimental 970421//,-//w3c//dtd w3 html//,-//w3o//dtd w3 html 3.0//,-//webtechs//dtd mozilla html 2.0//,-//webtechs//dtd mozilla html//`.split(`,`),lo=[...co,`-//w3c//dtd html 4.01 frameset//`,`-//w3c//dtd html 4.01 transitional//`],uo=new Set([`-//w3o//dtd w3 html strict 3.0//en//`,`-/w3c/dtd html 4.0 transitional/en`,`html`]),fo=[`-//w3c//dtd xhtml 1.0 frameset//`,`-//w3c//dtd xhtml 1.0 transitional//`],po=[...fo,`-//w3c//dtd html 4.01 frameset//`,`-//w3c//dtd html 4.01 transitional//`];function mo(e,t){return t.some(t=>e.startsWith(t))}function ho(e){return e.name===ao&&e.publicId===null&&(e.systemId===null||e.systemId===oo)}function go(e){if(e.name!==ao)return G.QUIRKS;let{systemId:t}=e;if(t&&t.toLowerCase()===so)return G.QUIRKS;let{publicId:n}=e;if(n!==null){if(n=n.toLowerCase(),uo.has(n))return G.QUIRKS;let e=t===null?lo:co;if(mo(n,e))return G.QUIRKS;if(e=t===null?fo:po,mo(n,e))return G.LIMITED_QUIRKS}return G.NO_QUIRKS}var _o={TEXT_HTML:`text/html`,APPLICATION_XML:`application/xhtml+xml`},vo=`definitionurl`,yo=`definitionURL`,bo=new Map(`attributeName.attributeType.baseFrequency.baseProfile.calcMode.clipPathUnits.diffuseConstant.edgeMode.filterUnits.glyphRef.gradientTransform.gradientUnits.kernelMatrix.kernelUnitLength.keyPoints.keySplines.keyTimes.lengthAdjust.limitingConeAngle.markerHeight.markerUnits.markerWidth.maskContentUnits.maskUnits.numOctaves.pathLength.patternContentUnits.patternTransform.patternUnits.pointsAtX.pointsAtY.pointsAtZ.preserveAlpha.preserveAspectRatio.primitiveUnits.refX.refY.repeatCount.repeatDur.requiredExtensions.requiredFeatures.specularConstant.specularExponent.spreadMethod.startOffset.stdDeviation.stitchTiles.surfaceScale.systemLanguage.tableValues.targetX.targetY.textLength.viewBox.viewTarget.xChannelSelector.yChannelSelector.zoomAndPan`.split(`.`).map(e=>[e.toLowerCase(),e])),xo=new Map([[`xlink:actuate`,{prefix:`xlink`,name:`actuate`,namespace:W.XLINK}],[`xlink:arcrole`,{prefix:`xlink`,name:`arcrole`,namespace:W.XLINK}],[`xlink:href`,{prefix:`xlink`,name:`href`,namespace:W.XLINK}],[`xlink:role`,{prefix:`xlink`,name:`role`,namespace:W.XLINK}],[`xlink:show`,{prefix:`xlink`,name:`show`,namespace:W.XLINK}],[`xlink:title`,{prefix:`xlink`,name:`title`,namespace:W.XLINK}],[`xlink:type`,{prefix:`xlink`,name:`type`,namespace:W.XLINK}],[`xml:lang`,{prefix:`xml`,name:`lang`,namespace:W.XML}],[`xml:space`,{prefix:`xml`,name:`space`,namespace:W.XML}],[`xmlns`,{prefix:``,name:`xmlns`,namespace:W.XMLNS}],[`xmlns:xlink`,{prefix:`xmlns`,name:`xlink`,namespace:W.XMLNS}]]),So=new Map(`altGlyph.altGlyphDef.altGlyphItem.animateColor.animateMotion.animateTransform.clipPath.feBlend.feColorMatrix.feComponentTransfer.feComposite.feConvolveMatrix.feDiffuseLighting.feDisplacementMap.feDistantLight.feFlood.feFuncA.feFuncB.feFuncG.feFuncR.feGaussianBlur.feImage.feMerge.feMergeNode.feMorphology.feOffset.fePointLight.feSpecularLighting.feSpotLight.feTile.feTurbulence.foreignObject.glyphRef.linearGradient.radialGradient.textPath`.split(`.`).map(e=>[e.toLowerCase(),e])),Co=new Set([q.B,q.BIG,q.BLOCKQUOTE,q.BODY,q.BR,q.CENTER,q.CODE,q.DD,q.DIV,q.DL,q.DT,q.EM,q.EMBED,q.H1,q.H2,q.H3,q.H4,q.H5,q.H6,q.HEAD,q.HR,q.I,q.IMG,q.LI,q.LISTING,q.MENU,q.META,q.NOBR,q.OL,q.P,q.PRE,q.RUBY,q.S,q.SMALL,q.SPAN,q.STRONG,q.STRIKE,q.SUB,q.SUP,q.TABLE,q.TT,q.U,q.UL,q.VAR]);function wo(e){let t=e.tagID;return t===q.FONT&&e.attrs.some(({name:e})=>e===Ta.COLOR||e===Ta.SIZE||e===Ta.FACE)||Co.has(t)}function To(e){for(let t=0;t<e.attrs.length;t++)if(e.attrs[t].name===vo){e.attrs[t].name=yo;break}}function Eo(e){for(let t=0;t<e.attrs.length;t++){let n=bo.get(e.attrs[t].name);n!=null&&(e.attrs[t].name=n)}}function Do(e){for(let t=0;t<e.attrs.length;t++){let n=xo.get(e.attrs[t].name);n&&(e.attrs[t].prefix=n.prefix,e.attrs[t].name=n.name,e.attrs[t].namespace=n.namespace)}}function Oo(e){let t=So.get(e.tagName);t!=null&&(e.tagName=t,e.tagID=Da(e.tagName))}function ko(e,t){return t===W.MATHML&&(e===q.MI||e===q.MO||e===q.MN||e===q.MS||e===q.MTEXT)}function Ao(e,t,n){if(t===W.MATHML&&e===q.ANNOTATION_XML){for(let e=0;e<n.length;e++)if(n[e].name===Ta.ENCODING){let t=n[e].value.toLowerCase();return t===_o.TEXT_HTML||t===_o.APPLICATION_XML}}return t===W.SVG&&(e===q.FOREIGN_OBJECT||e===q.DESC||e===q.TITLE)}function jo(e,t,n,r){return(!r||r===W.HTML)&&Ao(e,t,n)||(!r||r===W.MATHML)&&ko(e,t)}var Mo=`hidden`,No=8,Po=3,Z;(function(e){e[e.INITIAL=0]=`INITIAL`,e[e.BEFORE_HTML=1]=`BEFORE_HTML`,e[e.BEFORE_HEAD=2]=`BEFORE_HEAD`,e[e.IN_HEAD=3]=`IN_HEAD`,e[e.IN_HEAD_NO_SCRIPT=4]=`IN_HEAD_NO_SCRIPT`,e[e.AFTER_HEAD=5]=`AFTER_HEAD`,e[e.IN_BODY=6]=`IN_BODY`,e[e.TEXT=7]=`TEXT`,e[e.IN_TABLE=8]=`IN_TABLE`,e[e.IN_TABLE_TEXT=9]=`IN_TABLE_TEXT`,e[e.IN_CAPTION=10]=`IN_CAPTION`,e[e.IN_COLUMN_GROUP=11]=`IN_COLUMN_GROUP`,e[e.IN_TABLE_BODY=12]=`IN_TABLE_BODY`,e[e.IN_ROW=13]=`IN_ROW`,e[e.IN_CELL=14]=`IN_CELL`,e[e.IN_SELECT=15]=`IN_SELECT`,e[e.IN_SELECT_IN_TABLE=16]=`IN_SELECT_IN_TABLE`,e[e.IN_TEMPLATE=17]=`IN_TEMPLATE`,e[e.AFTER_BODY=18]=`AFTER_BODY`,e[e.IN_FRAMESET=19]=`IN_FRAMESET`,e[e.AFTER_FRAMESET=20]=`AFTER_FRAMESET`,e[e.AFTER_AFTER_BODY=21]=`AFTER_AFTER_BODY`,e[e.AFTER_AFTER_FRAMESET=22]=`AFTER_AFTER_FRAMESET`})(Z||={});var Fo={startLine:-1,startCol:-1,startOffset:-1,endLine:-1,endCol:-1,endOffset:-1},Io=new Set([q.TABLE,q.TBODY,q.TFOOT,q.THEAD,q.TR]),Lo={scriptingEnabled:!0,sourceCodeLocationInfo:!1,treeAdapter:io,onParseError:null},Ro=class{constructor(e,t,n=null,r=null){this.fragmentContext=n,this.scriptHandler=r,this.currentToken=null,this.stopped=!1,this.insertionMode=Z.INITIAL,this.originalInsertionMode=Z.INITIAL,this.headElement=null,this.formElement=null,this.currentNotInHTML=!1,this.tmplInsertionModeStack=[],this.pendingCharacterTokens=[],this.hasNonWhitespacePendingCharacterToken=!1,this.framesetOk=!0,this.skipNextNewLine=!1,this.fosterParentingEnabled=!1,this.options={...Lo,...e},this.treeAdapter=this.options.treeAdapter,this.onParseError=this.options.onParseError,this.onParseError&&(this.options.sourceCodeLocationInfo=!0),this.document=t??this.treeAdapter.createDocument(),this.tokenizer=new Va(this.options,this),this.activeFormattingElements=new ro(this.treeAdapter),this.fragmentContextID=n?Da(this.treeAdapter.getTagName(n)):q.UNKNOWN,this._setContextModes(n??this.document,this.fragmentContextID),this.openElements=new $a(this.document,this.treeAdapter,this)}static parse(e,t){let n=new this(t);return n.tokenizer.write(e,!0),n.document}static getFragmentParser(e,t){let n={...Lo,...t};e??=n.treeAdapter.createElement(K.TEMPLATE,W.HTML,[]);let r=n.treeAdapter.createElement(`documentmock`,W.HTML,[]),i=new this(n,r,e);return i.fragmentContextID===q.TEMPLATE&&i.tmplInsertionModeStack.unshift(Z.IN_TEMPLATE),i._initTokenizerForFragmentParsing(),i._insertFakeRootElement(),i._resetInsertionMode(),i._findFormInFragmentContext(),i}getFragment(){let e=this.treeAdapter.getFirstChild(this.document),t=this.treeAdapter.createDocumentFragment();return this._adoptNodes(e,t),t}_err(e,t,n){if(!this.onParseError)return;let r=e.location??Fo,i={code:t,startLine:r.startLine,startCol:r.startCol,startOffset:r.startOffset,endLine:n?r.startLine:r.endLine,endCol:n?r.startCol:r.endCol,endOffset:n?r.startOffset:r.endOffset};this.onParseError(i)}onItemPush(e,t,n){var r,i;(i=(r=this.treeAdapter).onItemPush)==null||i.call(r,e),n&&this.openElements.stackTop>0&&this._setContextModes(e,t)}onItemPop(e,t){var n,r;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(e,this.currentToken),(r=(n=this.treeAdapter).onItemPop)==null||r.call(n,e,this.openElements.current),t){let e,t;this.openElements.stackTop===0&&this.fragmentContext?(e=this.fragmentContext,t=this.fragmentContextID):{current:e,currentTagId:t}=this.openElements,this._setContextModes(e,t)}}_setContextModes(e,t){let n=e===this.document||e&&this.treeAdapter.getNamespaceURI(e)===W.HTML;this.currentNotInHTML=!n,this.tokenizer.inForeignNode=!n&&e!==void 0&&t!==void 0&&!this._isIntegrationPoint(t,e)}_switchToTextParsing(e,t){this._insertElement(e,W.HTML),this.tokenizer.state=t,this.originalInsertionMode=this.insertionMode,this.insertionMode=Z.TEXT}switchToPlaintextParsing(){this.insertionMode=Z.TEXT,this.originalInsertionMode=Z.IN_BODY,this.tokenizer.state=X.PLAINTEXT}_getAdjustedCurrentElement(){return this.openElements.stackTop===0&&this.fragmentContext?this.fragmentContext:this.openElements.current}_findFormInFragmentContext(){let e=this.fragmentContext;for(;e;){if(this.treeAdapter.getTagName(e)===K.FORM){this.formElement=e;break}e=this.treeAdapter.getParentNode(e)}}_initTokenizerForFragmentParsing(){if(!(!this.fragmentContext||this.treeAdapter.getNamespaceURI(this.fragmentContext)!==W.HTML))switch(this.fragmentContextID){case q.TITLE:case q.TEXTAREA:this.tokenizer.state=X.RCDATA;break;case q.STYLE:case q.XMP:case q.IFRAME:case q.NOEMBED:case q.NOFRAMES:case q.NOSCRIPT:this.tokenizer.state=X.RAWTEXT;break;case q.SCRIPT:this.tokenizer.state=X.SCRIPT_DATA;break;case q.PLAINTEXT:this.tokenizer.state=X.PLAINTEXT;break;default:}}_setDocumentType(e){let t=e.name||``,n=e.publicId||``,r=e.systemId||``;if(this.treeAdapter.setDocumentType(this.document,t,n,r),e.location){let t=this.treeAdapter.getChildNodes(this.document).find(e=>this.treeAdapter.isDocumentTypeNode(e));t&&this.treeAdapter.setNodeSourceCodeLocation(t,e.location)}}_attachElementToTree(e,t){if(this.options.sourceCodeLocationInfo){let n=t&&{...t,startTag:t};this.treeAdapter.setNodeSourceCodeLocation(e,n)}if(this._shouldFosterParentOnInsertion())this._fosterParentElement(e);else{let t=this.openElements.currentTmplContentOrNode;this.treeAdapter.appendChild(t??this.document,e)}}_appendElement(e,t){let n=this.treeAdapter.createElement(e.tagName,t,e.attrs);this._attachElementToTree(n,e.location)}_insertElement(e,t){let n=this.treeAdapter.createElement(e.tagName,t,e.attrs);this._attachElementToTree(n,e.location),this.openElements.push(n,e.tagID)}_insertFakeElement(e,t){let n=this.treeAdapter.createElement(e,W.HTML,[]);this._attachElementToTree(n,null),this.openElements.push(n,t)}_insertTemplate(e){let t=this.treeAdapter.createElement(e.tagName,W.HTML,e.attrs),n=this.treeAdapter.createDocumentFragment();this.treeAdapter.setTemplateContent(t,n),this._attachElementToTree(t,e.location),this.openElements.push(t,e.tagID),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,null)}_insertFakeRootElement(){let e=this.treeAdapter.createElement(K.HTML,W.HTML,[]);this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(e,null),this.treeAdapter.appendChild(this.openElements.current,e),this.openElements.push(e,q.HTML)}_appendCommentNode(e,t){let n=this.treeAdapter.createCommentNode(e.data);this.treeAdapter.appendChild(t,n),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,e.location)}_insertCharacters(e){let t,n;if(this._shouldFosterParentOnInsertion()?({parent:t,beforeElement:n}=this._findFosterParentingLocation(),n?this.treeAdapter.insertTextBefore(t,e.chars,n):this.treeAdapter.insertText(t,e.chars)):(t=this.openElements.currentTmplContentOrNode,this.treeAdapter.insertText(t,e.chars)),!e.location)return;let r=this.treeAdapter.getChildNodes(t),i=r[(n?r.lastIndexOf(n):r.length)-1];if(this.treeAdapter.getNodeSourceCodeLocation(i)){let{endLine:t,endCol:n,endOffset:r}=e.location;this.treeAdapter.updateNodeSourceCodeLocation(i,{endLine:t,endCol:n,endOffset:r})}else this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(i,e.location)}_adoptNodes(e,t){for(let n=this.treeAdapter.getFirstChild(e);n;n=this.treeAdapter.getFirstChild(e))this.treeAdapter.detachNode(n),this.treeAdapter.appendChild(t,n)}_setEndLocation(e,t){if(this.treeAdapter.getNodeSourceCodeLocation(e)&&t.location){let n=t.location,r=this.treeAdapter.getTagName(e),i=t.type===U.END_TAG&&r===t.tagName?{endTag:{...n},endLine:n.endLine,endCol:n.endCol,endOffset:n.endOffset}:{endLine:n.startLine,endCol:n.startCol,endOffset:n.startOffset};this.treeAdapter.updateNodeSourceCodeLocation(e,i)}}shouldProcessStartTagTokenInForeignContent(e){if(!this.currentNotInHTML)return!1;let t,n;return this.openElements.stackTop===0&&this.fragmentContext?(t=this.fragmentContext,n=this.fragmentContextID):{current:t,currentTagId:n}=this.openElements,e.tagID===q.SVG&&this.treeAdapter.getTagName(t)===K.ANNOTATION_XML&&this.treeAdapter.getNamespaceURI(t)===W.MATHML?!1:this.tokenizer.inForeignNode||(e.tagID===q.MGLYPH||e.tagID===q.MALIGNMARK)&&n!==void 0&&!this._isIntegrationPoint(n,t,W.HTML)}_processToken(e){switch(e.type){case U.CHARACTER:this.onCharacter(e);break;case U.NULL_CHARACTER:this.onNullCharacter(e);break;case U.COMMENT:this.onComment(e);break;case U.DOCTYPE:this.onDoctype(e);break;case U.START_TAG:this._processStartTag(e);break;case U.END_TAG:this.onEndTag(e);break;case U.EOF:this.onEof(e);break;case U.WHITESPACE_CHARACTER:this.onWhitespaceCharacter(e);break}}_isIntegrationPoint(e,t,n){return jo(e,this.treeAdapter.getNamespaceURI(t),this.treeAdapter.getAttrList(t),n)}_reconstructActiveFormattingElements(){let e=this.activeFormattingElements.entries.length;if(e){let t=this.activeFormattingElements.entries.findIndex(e=>e.type===to.Marker||this.openElements.contains(e.element)),n=t===-1?e-1:t-1;for(let e=n;e>=0;e--){let t=this.activeFormattingElements.entries[e];this._insertElement(t.token,this.treeAdapter.getNamespaceURI(t.element)),t.element=this.openElements.current}}}_closeTableCell(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=Z.IN_ROW}_closePElement(){this.openElements.generateImpliedEndTagsWithExclusion(q.P),this.openElements.popUntilTagNamePopped(q.P)}_resetInsertionMode(){for(let e=this.openElements.stackTop;e>=0;e--)switch(e===0&&this.fragmentContext?this.fragmentContextID:this.openElements.tagIDs[e]){case q.TR:this.insertionMode=Z.IN_ROW;return;case q.TBODY:case q.THEAD:case q.TFOOT:this.insertionMode=Z.IN_TABLE_BODY;return;case q.CAPTION:this.insertionMode=Z.IN_CAPTION;return;case q.COLGROUP:this.insertionMode=Z.IN_COLUMN_GROUP;return;case q.TABLE:this.insertionMode=Z.IN_TABLE;return;case q.BODY:this.insertionMode=Z.IN_BODY;return;case q.FRAMESET:this.insertionMode=Z.IN_FRAMESET;return;case q.SELECT:this._resetInsertionModeForSelect(e);return;case q.TEMPLATE:this.insertionMode=this.tmplInsertionModeStack[0];return;case q.HTML:this.insertionMode=this.headElement?Z.AFTER_HEAD:Z.BEFORE_HEAD;return;case q.TD:case q.TH:if(e>0){this.insertionMode=Z.IN_CELL;return}break;case q.HEAD:if(e>0){this.insertionMode=Z.IN_HEAD;return}break}this.insertionMode=Z.IN_BODY}_resetInsertionModeForSelect(e){if(e>0)for(let t=e-1;t>0;t--){let e=this.openElements.tagIDs[t];if(e===q.TEMPLATE)break;if(e===q.TABLE){this.insertionMode=Z.IN_SELECT_IN_TABLE;return}}this.insertionMode=Z.IN_SELECT}_isElementCausesFosterParenting(e){return Io.has(e)}_shouldFosterParentOnInsertion(){return this.fosterParentingEnabled&&this.openElements.currentTagId!==void 0&&this._isElementCausesFosterParenting(this.openElements.currentTagId)}_findFosterParentingLocation(){for(let e=this.openElements.stackTop;e>=0;e--){let t=this.openElements.items[e];switch(this.openElements.tagIDs[e]){case q.TEMPLATE:if(this.treeAdapter.getNamespaceURI(t)===W.HTML)return{parent:this.treeAdapter.getTemplateContent(t),beforeElement:null};break;case q.TABLE:{let n=this.treeAdapter.getParentNode(t);return n?{parent:n,beforeElement:t}:{parent:this.openElements.items[e-1],beforeElement:null}}default:}}return{parent:this.openElements.items[0],beforeElement:null}}_fosterParentElement(e){let t=this._findFosterParentingLocation();t.beforeElement?this.treeAdapter.insertBefore(t.parent,e,t.beforeElement):this.treeAdapter.appendChild(t.parent,e)}_isSpecialElement(e,t){return Oa[this.treeAdapter.getNamespaceURI(e)].has(t)}onCharacter(e){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){el(this,e);return}switch(this.insertionMode){case Z.INITIAL:Zo(this,e);break;case Z.BEFORE_HTML:es(this,e);break;case Z.BEFORE_HEAD:rs(this,e);break;case Z.IN_HEAD:os(this,e);break;case Z.IN_HEAD_NO_SCRIPT:ls(this,e);break;case Z.AFTER_HEAD:fs(this,e);break;case Z.IN_BODY:case Z.IN_CAPTION:case Z.IN_CELL:case Z.IN_TEMPLATE:hs(this,e);break;case Z.TEXT:case Z.IN_SELECT:case Z.IN_SELECT_IN_TABLE:this._insertCharacters(e);break;case Z.IN_TABLE:case Z.IN_TABLE_BODY:case Z.IN_ROW:lc(this,e);break;case Z.IN_TABLE_TEXT:Sc(this,e);break;case Z.IN_COLUMN_GROUP:kc(this,e);break;case Z.AFTER_BODY:Gc(this,e);break;case Z.AFTER_AFTER_BODY:Zc(this,e);break;default:}}onNullCharacter(e){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){$c(this,e);return}switch(this.insertionMode){case Z.INITIAL:Zo(this,e);break;case Z.BEFORE_HTML:es(this,e);break;case Z.BEFORE_HEAD:rs(this,e);break;case Z.IN_HEAD:os(this,e);break;case Z.IN_HEAD_NO_SCRIPT:ls(this,e);break;case Z.AFTER_HEAD:fs(this,e);break;case Z.TEXT:this._insertCharacters(e);break;case Z.IN_TABLE:case Z.IN_TABLE_BODY:case Z.IN_ROW:lc(this,e);break;case Z.IN_COLUMN_GROUP:kc(this,e);break;case Z.AFTER_BODY:Gc(this,e);break;case Z.AFTER_AFTER_BODY:Zc(this,e);break;default:}}onComment(e){if(this.skipNextNewLine=!1,this.currentNotInHTML){Ko(this,e);return}switch(this.insertionMode){case Z.INITIAL:case Z.BEFORE_HTML:case Z.BEFORE_HEAD:case Z.IN_HEAD:case Z.IN_HEAD_NO_SCRIPT:case Z.AFTER_HEAD:case Z.IN_BODY:case Z.IN_TABLE:case Z.IN_CAPTION:case Z.IN_COLUMN_GROUP:case Z.IN_TABLE_BODY:case Z.IN_ROW:case Z.IN_CELL:case Z.IN_SELECT:case Z.IN_SELECT_IN_TABLE:case Z.IN_TEMPLATE:case Z.IN_FRAMESET:case Z.AFTER_FRAMESET:Ko(this,e);break;case Z.IN_TABLE_TEXT:Cc(this,e);break;case Z.AFTER_BODY:qo(this,e);break;case Z.AFTER_AFTER_BODY:case Z.AFTER_AFTER_FRAMESET:Jo(this,e);break;default:}}onDoctype(e){switch(this.skipNextNewLine=!1,this.insertionMode){case Z.INITIAL:Xo(this,e);break;case Z.BEFORE_HEAD:case Z.IN_HEAD:case Z.IN_HEAD_NO_SCRIPT:case Z.AFTER_HEAD:this._err(e,H.misplacedDoctype);break;case Z.IN_TABLE_TEXT:Cc(this,e);break;default:}}onStartTag(e){this.skipNextNewLine=!1,this.currentToken=e,this._processStartTag(e),e.selfClosing&&!e.ackSelfClosing&&this._err(e,H.nonVoidHtmlElementStartTagWithTrailingSolidus)}_processStartTag(e){this.shouldProcessStartTagTokenInForeignContent(e)?nl(this,e):this._startTagOutsideForeignContent(e)}_startTagOutsideForeignContent(e){switch(this.insertionMode){case Z.INITIAL:Zo(this,e);break;case Z.BEFORE_HTML:Qo(this,e);break;case Z.BEFORE_HEAD:ts(this,e);break;case Z.IN_HEAD:Q(this,e);break;case Z.IN_HEAD_NO_SCRIPT:ss(this,e);break;case Z.AFTER_HEAD:us(this,e);break;case Z.IN_BODY:$(this,e);break;case Z.IN_TABLE:vc(this,e);break;case Z.IN_TABLE_TEXT:Cc(this,e);break;case Z.IN_CAPTION:Tc(this,e);break;case Z.IN_COLUMN_GROUP:Dc(this,e);break;case Z.IN_TABLE_BODY:Ac(this,e);break;case Z.IN_ROW:Mc(this,e);break;case Z.IN_CELL:Pc(this,e);break;case Z.IN_SELECT:Ic(this,e);break;case Z.IN_SELECT_IN_TABLE:Rc(this,e);break;case Z.IN_TEMPLATE:Bc(this,e);break;case Z.AFTER_BODY:Uc(this,e);break;case Z.IN_FRAMESET:Kc(this,e);break;case Z.AFTER_FRAMESET:Jc(this,e);break;case Z.AFTER_AFTER_BODY:Xc(this,e);break;case Z.AFTER_AFTER_FRAMESET:Qc(this,e);break;default:}}onEndTag(e){this.skipNextNewLine=!1,this.currentToken=e,this.currentNotInHTML?rl(this,e):this._endTagOutsideForeignContent(e)}_endTagOutsideForeignContent(e){switch(this.insertionMode){case Z.INITIAL:Zo(this,e);break;case Z.BEFORE_HTML:$o(this,e);break;case Z.BEFORE_HEAD:ns(this,e);break;case Z.IN_HEAD:is(this,e);break;case Z.IN_HEAD_NO_SCRIPT:cs(this,e);break;case Z.AFTER_HEAD:ds(this,e);break;case Z.IN_BODY:ac(this,e);break;case Z.TEXT:sc(this,e);break;case Z.IN_TABLE:yc(this,e);break;case Z.IN_TABLE_TEXT:Cc(this,e);break;case Z.IN_CAPTION:Ec(this,e);break;case Z.IN_COLUMN_GROUP:Oc(this,e);break;case Z.IN_TABLE_BODY:jc(this,e);break;case Z.IN_ROW:Nc(this,e);break;case Z.IN_CELL:Fc(this,e);break;case Z.IN_SELECT:Lc(this,e);break;case Z.IN_SELECT_IN_TABLE:zc(this,e);break;case Z.IN_TEMPLATE:Vc(this,e);break;case Z.AFTER_BODY:Wc(this,e);break;case Z.IN_FRAMESET:qc(this,e);break;case Z.AFTER_FRAMESET:Yc(this,e);break;case Z.AFTER_AFTER_BODY:Zc(this,e);break;default:}}onEof(e){switch(this.insertionMode){case Z.INITIAL:Zo(this,e);break;case Z.BEFORE_HTML:es(this,e);break;case Z.BEFORE_HEAD:rs(this,e);break;case Z.IN_HEAD:os(this,e);break;case Z.IN_HEAD_NO_SCRIPT:ls(this,e);break;case Z.AFTER_HEAD:fs(this,e);break;case Z.IN_BODY:case Z.IN_TABLE:case Z.IN_CAPTION:case Z.IN_COLUMN_GROUP:case Z.IN_TABLE_BODY:case Z.IN_ROW:case Z.IN_CELL:case Z.IN_SELECT:case Z.IN_SELECT_IN_TABLE:oc(this,e);break;case Z.TEXT:cc(this,e);break;case Z.IN_TABLE_TEXT:Cc(this,e);break;case Z.IN_TEMPLATE:Hc(this,e);break;case Z.AFTER_BODY:case Z.IN_FRAMESET:case Z.AFTER_FRAMESET:case Z.AFTER_AFTER_BODY:case Z.AFTER_AFTER_FRAMESET:Yo(this,e);break;default:}}onWhitespaceCharacter(e){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,e.chars.charCodeAt(0)===B.LINE_FEED)){if(e.chars.length===1)return;e.chars=e.chars.substr(1)}if(this.tokenizer.inForeignNode){this._insertCharacters(e);return}switch(this.insertionMode){case Z.IN_HEAD:case Z.IN_HEAD_NO_SCRIPT:case Z.AFTER_HEAD:case Z.TEXT:case Z.IN_COLUMN_GROUP:case Z.IN_SELECT:case Z.IN_SELECT_IN_TABLE:case Z.IN_FRAMESET:case Z.AFTER_FRAMESET:this._insertCharacters(e);break;case Z.IN_BODY:case Z.IN_CAPTION:case Z.IN_CELL:case Z.IN_TEMPLATE:case Z.AFTER_BODY:case Z.AFTER_AFTER_BODY:case Z.AFTER_AFTER_FRAMESET:ms(this,e);break;case Z.IN_TABLE:case Z.IN_TABLE_BODY:case Z.IN_ROW:lc(this,e);break;case Z.IN_TABLE_TEXT:xc(this,e);break;default:}}};function zo(e,t){let n=e.activeFormattingElements.getElementEntryInScopeWithTagName(t.tagName);return n?e.openElements.contains(n.element)?e.openElements.hasInScope(t.tagID)||(n=null):(e.activeFormattingElements.removeEntry(n),n=null):ic(e,t),n}function Bo(e,t){let n=null,r=e.openElements.stackTop;for(;r>=0;r--){let i=e.openElements.items[r];if(i===t.element)break;e._isSpecialElement(i,e.openElements.tagIDs[r])&&(n=i)}return n||(e.openElements.shortenToLength(Math.max(r,0)),e.activeFormattingElements.removeEntry(t)),n}function Vo(e,t,n){let r=t,i=e.openElements.getCommonAncestor(t);for(let a=0,o=i;o!==n;a++,o=i){i=e.openElements.getCommonAncestor(o);let n=e.activeFormattingElements.getElementEntry(o),s=n&&a>=Po;!n||s?(s&&e.activeFormattingElements.removeEntry(n),e.openElements.remove(o)):(o=Ho(e,n),r===t&&(e.activeFormattingElements.bookmark=n),e.treeAdapter.detachNode(r),e.treeAdapter.appendChild(o,r),r=o)}return r}function Ho(e,t){let n=e.treeAdapter.getNamespaceURI(t.element),r=e.treeAdapter.createElement(t.token.tagName,n,t.token.attrs);return e.openElements.replace(t.element,r),t.element=r,r}function Uo(e,t,n){let r=Da(e.treeAdapter.getTagName(t));if(e._isElementCausesFosterParenting(r))e._fosterParentElement(n);else{let i=e.treeAdapter.getNamespaceURI(t);r===q.TEMPLATE&&i===W.HTML&&(t=e.treeAdapter.getTemplateContent(t)),e.treeAdapter.appendChild(t,n)}}function Wo(e,t,n){let r=e.treeAdapter.getNamespaceURI(n.element),{token:i}=n,a=e.treeAdapter.createElement(i.tagName,r,i.attrs);e._adoptNodes(t,a),e.treeAdapter.appendChild(t,a),e.activeFormattingElements.insertElementAfterBookmark(a,i),e.activeFormattingElements.removeEntry(n),e.openElements.remove(n.element),e.openElements.insertAfter(t,a,i.tagID)}function Go(e,t){for(let n=0;n<No;n++){let n=zo(e,t);if(!n)break;let r=Bo(e,n);if(!r)break;e.activeFormattingElements.bookmark=n;let i=Vo(e,r,n.element),a=e.openElements.getCommonAncestor(n.element);e.treeAdapter.detachNode(i),a&&Uo(e,a,i),Wo(e,r,n)}}function Ko(e,t){e._appendCommentNode(t,e.openElements.currentTmplContentOrNode)}function qo(e,t){e._appendCommentNode(t,e.openElements.items[0])}function Jo(e,t){e._appendCommentNode(t,e.document)}function Yo(e,t){if(e.stopped=!0,t.location){let n=e.fragmentContext?0:2;for(let r=e.openElements.stackTop;r>=n;r--)e._setEndLocation(e.openElements.items[r],t);if(!e.fragmentContext&&e.openElements.stackTop>=0){let n=e.openElements.items[0],r=e.treeAdapter.getNodeSourceCodeLocation(n);if(r&&!r.endTag&&(e._setEndLocation(n,t),e.openElements.stackTop>=1)){let n=e.openElements.items[1],r=e.treeAdapter.getNodeSourceCodeLocation(n);r&&!r.endTag&&e._setEndLocation(n,t)}}}}function Xo(e,t){e._setDocumentType(t);let n=t.forceQuirks?G.QUIRKS:go(t);ho(t)||e._err(t,H.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,n),e.insertionMode=Z.BEFORE_HTML}function Zo(e,t){e._err(t,H.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,G.QUIRKS),e.insertionMode=Z.BEFORE_HTML,e._processToken(t)}function Qo(e,t){t.tagID===q.HTML?(e._insertElement(t,W.HTML),e.insertionMode=Z.BEFORE_HEAD):es(e,t)}function $o(e,t){let n=t.tagID;(n===q.HTML||n===q.HEAD||n===q.BODY||n===q.BR)&&es(e,t)}function es(e,t){e._insertFakeRootElement(),e.insertionMode=Z.BEFORE_HEAD,e._processToken(t)}function ts(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.HEAD:e._insertElement(t,W.HTML),e.headElement=e.openElements.current,e.insertionMode=Z.IN_HEAD;break;default:rs(e,t)}}function ns(e,t){let n=t.tagID;n===q.HEAD||n===q.BODY||n===q.HTML||n===q.BR?rs(e,t):e._err(t,H.endTagWithoutMatchingOpenElement)}function rs(e,t){e._insertFakeElement(K.HEAD,q.HEAD),e.headElement=e.openElements.current,e.insertionMode=Z.IN_HEAD,e._processToken(t)}function Q(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.BASE:case q.BASEFONT:case q.BGSOUND:case q.LINK:case q.META:e._appendElement(t,W.HTML),t.ackSelfClosing=!0;break;case q.TITLE:e._switchToTextParsing(t,X.RCDATA);break;case q.NOSCRIPT:e.options.scriptingEnabled?e._switchToTextParsing(t,X.RAWTEXT):(e._insertElement(t,W.HTML),e.insertionMode=Z.IN_HEAD_NO_SCRIPT);break;case q.NOFRAMES:case q.STYLE:e._switchToTextParsing(t,X.RAWTEXT);break;case q.SCRIPT:e._switchToTextParsing(t,X.SCRIPT_DATA);break;case q.TEMPLATE:e._insertTemplate(t),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=Z.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Z.IN_TEMPLATE);break;case q.HEAD:e._err(t,H.misplacedStartTagForHeadElement);break;default:os(e,t)}}function is(e,t){switch(t.tagID){case q.HEAD:e.openElements.pop(),e.insertionMode=Z.AFTER_HEAD;break;case q.BODY:case q.BR:case q.HTML:os(e,t);break;case q.TEMPLATE:as(e,t);break;default:e._err(t,H.endTagWithoutMatchingOpenElement)}}function as(e,t){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==q.TEMPLATE&&e._err(t,H.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(q.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(t,H.endTagWithoutMatchingOpenElement)}function os(e,t){e.openElements.pop(),e.insertionMode=Z.AFTER_HEAD,e._processToken(t)}function ss(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.BASEFONT:case q.BGSOUND:case q.HEAD:case q.LINK:case q.META:case q.NOFRAMES:case q.STYLE:Q(e,t);break;case q.NOSCRIPT:e._err(t,H.nestedNoscriptInHead);break;default:ls(e,t)}}function cs(e,t){switch(t.tagID){case q.NOSCRIPT:e.openElements.pop(),e.insertionMode=Z.IN_HEAD;break;case q.BR:ls(e,t);break;default:e._err(t,H.endTagWithoutMatchingOpenElement)}}function ls(e,t){let n=t.type===U.EOF?H.openElementsLeftAfterEof:H.disallowedContentInNoscriptInHead;e._err(t,n),e.openElements.pop(),e.insertionMode=Z.IN_HEAD,e._processToken(t)}function us(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.BODY:e._insertElement(t,W.HTML),e.framesetOk=!1,e.insertionMode=Z.IN_BODY;break;case q.FRAMESET:e._insertElement(t,W.HTML),e.insertionMode=Z.IN_FRAMESET;break;case q.BASE:case q.BASEFONT:case q.BGSOUND:case q.LINK:case q.META:case q.NOFRAMES:case q.SCRIPT:case q.STYLE:case q.TEMPLATE:case q.TITLE:e._err(t,H.abandonedHeadElementChild),e.openElements.push(e.headElement,q.HEAD),Q(e,t),e.openElements.remove(e.headElement);break;case q.HEAD:e._err(t,H.misplacedStartTagForHeadElement);break;default:fs(e,t)}}function ds(e,t){switch(t.tagID){case q.BODY:case q.HTML:case q.BR:fs(e,t);break;case q.TEMPLATE:as(e,t);break;default:e._err(t,H.endTagWithoutMatchingOpenElement)}}function fs(e,t){e._insertFakeElement(K.BODY,q.BODY),e.insertionMode=Z.IN_BODY,ps(e,t)}function ps(e,t){switch(t.type){case U.CHARACTER:hs(e,t);break;case U.WHITESPACE_CHARACTER:ms(e,t);break;case U.COMMENT:Ko(e,t);break;case U.START_TAG:$(e,t);break;case U.END_TAG:ac(e,t);break;case U.EOF:oc(e,t);break;default:}}function ms(e,t){e._reconstructActiveFormattingElements(),e._insertCharacters(t)}function hs(e,t){e._reconstructActiveFormattingElements(),e._insertCharacters(t),e.framesetOk=!1}function gs(e,t){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],t.attrs)}function _s(e,t){let n=e.openElements.tryPeekProperlyNestedBodyElement();n&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(n,t.attrs))}function vs(e,t){let n=e.openElements.tryPeekProperlyNestedBodyElement();e.framesetOk&&n&&(e.treeAdapter.detachNode(n),e.openElements.popAllUpToHtmlElement(),e._insertElement(t,W.HTML),e.insertionMode=Z.IN_FRAMESET)}function ys(e,t){e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._insertElement(t,W.HTML)}function bs(e,t){e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e.openElements.currentTagId!==void 0&&ka.has(e.openElements.currentTagId)&&e.openElements.pop(),e._insertElement(t,W.HTML)}function xs(e,t){e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._insertElement(t,W.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function Ss(e,t){let n=e.openElements.tmplCount>0;(!e.formElement||n)&&(e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._insertElement(t,W.HTML),n||(e.formElement=e.openElements.current))}function Cs(e,t){e.framesetOk=!1;let n=t.tagID;for(let t=e.openElements.stackTop;t>=0;t--){let r=e.openElements.tagIDs[t];if(n===q.LI&&r===q.LI||(n===q.DD||n===q.DT)&&(r===q.DD||r===q.DT)){e.openElements.generateImpliedEndTagsWithExclusion(r),e.openElements.popUntilTagNamePopped(r);break}if(r!==q.ADDRESS&&r!==q.DIV&&r!==q.P&&e._isSpecialElement(e.openElements.items[t],r))break}e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._insertElement(t,W.HTML)}function ws(e,t){e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._insertElement(t,W.HTML),e.tokenizer.state=X.PLAINTEXT}function Ts(e,t){e.openElements.hasInScope(q.BUTTON)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(q.BUTTON)),e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML),e.framesetOk=!1}function Es(e,t){let n=e.activeFormattingElements.getElementEntryInScopeWithTagName(K.A);n&&(Go(e,t),e.openElements.remove(n.element),e.activeFormattingElements.removeEntry(n)),e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML),e.activeFormattingElements.pushElement(e.openElements.current,t)}function Ds(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML),e.activeFormattingElements.pushElement(e.openElements.current,t)}function Os(e,t){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(q.NOBR)&&(Go(e,t),e._reconstructActiveFormattingElements()),e._insertElement(t,W.HTML),e.activeFormattingElements.pushElement(e.openElements.current,t)}function ks(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function As(e,t){e.treeAdapter.getDocumentMode(e.document)!==G.QUIRKS&&e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._insertElement(t,W.HTML),e.framesetOk=!1,e.insertionMode=Z.IN_TABLE}function js(e,t){e._reconstructActiveFormattingElements(),e._appendElement(t,W.HTML),e.framesetOk=!1,t.ackSelfClosing=!0}function Ms(e){let t=wa(e,Ta.TYPE);return t!=null&&t.toLowerCase()===Mo}function Ns(e,t){e._reconstructActiveFormattingElements(),e._appendElement(t,W.HTML),Ms(t)||(e.framesetOk=!1),t.ackSelfClosing=!0}function Ps(e,t){e._appendElement(t,W.HTML),t.ackSelfClosing=!0}function Fs(e,t){e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._appendElement(t,W.HTML),e.framesetOk=!1,t.ackSelfClosing=!0}function Is(e,t){t.tagName=K.IMG,t.tagID=q.IMG,js(e,t)}function Ls(e,t){e._insertElement(t,W.HTML),e.skipNextNewLine=!0,e.tokenizer.state=X.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=Z.TEXT}function Rs(e,t){e.openElements.hasInButtonScope(q.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(t,X.RAWTEXT)}function zs(e,t){e.framesetOk=!1,e._switchToTextParsing(t,X.RAWTEXT)}function Bs(e,t){e._switchToTextParsing(t,X.RAWTEXT)}function Vs(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===Z.IN_TABLE||e.insertionMode===Z.IN_CAPTION||e.insertionMode===Z.IN_TABLE_BODY||e.insertionMode===Z.IN_ROW||e.insertionMode===Z.IN_CELL?Z.IN_SELECT_IN_TABLE:Z.IN_SELECT}function Hs(e,t){e.openElements.currentTagId===q.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML)}function Us(e,t){e.openElements.hasInScope(q.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(t,W.HTML)}function Ws(e,t){e.openElements.hasInScope(q.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(q.RTC),e._insertElement(t,W.HTML)}function Gs(e,t){e._reconstructActiveFormattingElements(),To(t),Do(t),t.selfClosing?e._appendElement(t,W.MATHML):e._insertElement(t,W.MATHML),t.ackSelfClosing=!0}function Ks(e,t){e._reconstructActiveFormattingElements(),Eo(t),Do(t),t.selfClosing?e._appendElement(t,W.SVG):e._insertElement(t,W.SVG),t.ackSelfClosing=!0}function qs(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,W.HTML)}function $(e,t){switch(t.tagID){case q.I:case q.S:case q.B:case q.U:case q.EM:case q.TT:case q.BIG:case q.CODE:case q.FONT:case q.SMALL:case q.STRIKE:case q.STRONG:Ds(e,t);break;case q.A:Es(e,t);break;case q.H1:case q.H2:case q.H3:case q.H4:case q.H5:case q.H6:bs(e,t);break;case q.P:case q.DL:case q.OL:case q.UL:case q.DIV:case q.DIR:case q.NAV:case q.MAIN:case q.MENU:case q.ASIDE:case q.CENTER:case q.FIGURE:case q.FOOTER:case q.HEADER:case q.HGROUP:case q.DIALOG:case q.DETAILS:case q.ADDRESS:case q.ARTICLE:case q.SEARCH:case q.SECTION:case q.SUMMARY:case q.FIELDSET:case q.BLOCKQUOTE:case q.FIGCAPTION:ys(e,t);break;case q.LI:case q.DD:case q.DT:Cs(e,t);break;case q.BR:case q.IMG:case q.WBR:case q.AREA:case q.EMBED:case q.KEYGEN:js(e,t);break;case q.HR:Fs(e,t);break;case q.RB:case q.RTC:Us(e,t);break;case q.RT:case q.RP:Ws(e,t);break;case q.PRE:case q.LISTING:xs(e,t);break;case q.XMP:Rs(e,t);break;case q.SVG:Ks(e,t);break;case q.HTML:gs(e,t);break;case q.BASE:case q.LINK:case q.META:case q.STYLE:case q.TITLE:case q.SCRIPT:case q.BGSOUND:case q.BASEFONT:case q.TEMPLATE:Q(e,t);break;case q.BODY:_s(e,t);break;case q.FORM:Ss(e,t);break;case q.NOBR:Os(e,t);break;case q.MATH:Gs(e,t);break;case q.TABLE:As(e,t);break;case q.INPUT:Ns(e,t);break;case q.PARAM:case q.TRACK:case q.SOURCE:Ps(e,t);break;case q.IMAGE:Is(e,t);break;case q.BUTTON:Ts(e,t);break;case q.APPLET:case q.OBJECT:case q.MARQUEE:ks(e,t);break;case q.IFRAME:zs(e,t);break;case q.SELECT:Vs(e,t);break;case q.OPTION:case q.OPTGROUP:Hs(e,t);break;case q.NOEMBED:case q.NOFRAMES:Bs(e,t);break;case q.FRAMESET:vs(e,t);break;case q.TEXTAREA:Ls(e,t);break;case q.NOSCRIPT:e.options.scriptingEnabled?Bs(e,t):qs(e,t);break;case q.PLAINTEXT:ws(e,t);break;case q.COL:case q.TH:case q.TD:case q.TR:case q.HEAD:case q.FRAME:case q.TBODY:case q.TFOOT:case q.THEAD:case q.CAPTION:case q.COLGROUP:break;default:qs(e,t)}}function Js(e,t){if(e.openElements.hasInScope(q.BODY)&&(e.insertionMode=Z.AFTER_BODY,e.options.sourceCodeLocationInfo)){let n=e.openElements.tryPeekProperlyNestedBodyElement();n&&e._setEndLocation(n,t)}}function Ys(e,t){e.openElements.hasInScope(q.BODY)&&(e.insertionMode=Z.AFTER_BODY,Wc(e,t))}function Xs(e,t){let n=t.tagID;e.openElements.hasInScope(n)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(n))}function Zs(e){let t=e.openElements.tmplCount>0,{formElement:n}=e;t||(e.formElement=null),(n||t)&&e.openElements.hasInScope(q.FORM)&&(e.openElements.generateImpliedEndTags(),t?e.openElements.popUntilTagNamePopped(q.FORM):n&&e.openElements.remove(n))}function Qs(e){e.openElements.hasInButtonScope(q.P)||e._insertFakeElement(K.P,q.P),e._closePElement()}function $s(e){e.openElements.hasInListItemScope(q.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(q.LI),e.openElements.popUntilTagNamePopped(q.LI))}function ec(e,t){let n=t.tagID;e.openElements.hasInScope(n)&&(e.openElements.generateImpliedEndTagsWithExclusion(n),e.openElements.popUntilTagNamePopped(n))}function tc(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function nc(e,t){let n=t.tagID;e.openElements.hasInScope(n)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(n),e.activeFormattingElements.clearToLastMarker())}function rc(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(K.BR,q.BR),e.openElements.pop(),e.framesetOk=!1}function ic(e,t){let n=t.tagName,r=t.tagID;for(let t=e.openElements.stackTop;t>0;t--){let i=e.openElements.items[t],a=e.openElements.tagIDs[t];if(r===a&&(r!==q.UNKNOWN||e.treeAdapter.getTagName(i)===n)){e.openElements.generateImpliedEndTagsWithExclusion(r),e.openElements.stackTop>=t&&e.openElements.shortenToLength(t);break}if(e._isSpecialElement(i,a))break}}function ac(e,t){switch(t.tagID){case q.A:case q.B:case q.I:case q.S:case q.U:case q.EM:case q.TT:case q.BIG:case q.CODE:case q.FONT:case q.NOBR:case q.SMALL:case q.STRIKE:case q.STRONG:Go(e,t);break;case q.P:Qs(e);break;case q.DL:case q.UL:case q.OL:case q.DIR:case q.DIV:case q.NAV:case q.PRE:case q.MAIN:case q.MENU:case q.ASIDE:case q.BUTTON:case q.CENTER:case q.FIGURE:case q.FOOTER:case q.HEADER:case q.HGROUP:case q.DIALOG:case q.ADDRESS:case q.ARTICLE:case q.DETAILS:case q.SEARCH:case q.SECTION:case q.SUMMARY:case q.LISTING:case q.FIELDSET:case q.BLOCKQUOTE:case q.FIGCAPTION:Xs(e,t);break;case q.LI:$s(e);break;case q.DD:case q.DT:ec(e,t);break;case q.H1:case q.H2:case q.H3:case q.H4:case q.H5:case q.H6:tc(e);break;case q.BR:rc(e);break;case q.BODY:Js(e,t);break;case q.HTML:Ys(e,t);break;case q.FORM:Zs(e);break;case q.APPLET:case q.OBJECT:case q.MARQUEE:nc(e,t);break;case q.TEMPLATE:as(e,t);break;default:ic(e,t)}}function oc(e,t){e.tmplInsertionModeStack.length>0?Hc(e,t):Yo(e,t)}function sc(e,t){var n;t.tagID===q.SCRIPT&&((n=e.scriptHandler)==null||n.call(e,e.openElements.current)),e.openElements.pop(),e.insertionMode=e.originalInsertionMode}function cc(e,t){e._err(t,H.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(t)}function lc(e,t){if(e.openElements.currentTagId!==void 0&&Io.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=Z.IN_TABLE_TEXT,t.type){case U.CHARACTER:Sc(e,t);break;case U.WHITESPACE_CHARACTER:xc(e,t);break}else bc(e,t)}function uc(e,t){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(t,W.HTML),e.insertionMode=Z.IN_CAPTION}function dc(e,t){e.openElements.clearBackToTableContext(),e._insertElement(t,W.HTML),e.insertionMode=Z.IN_COLUMN_GROUP}function fc(e,t){e.openElements.clearBackToTableContext(),e._insertFakeElement(K.COLGROUP,q.COLGROUP),e.insertionMode=Z.IN_COLUMN_GROUP,Dc(e,t)}function pc(e,t){e.openElements.clearBackToTableContext(),e._insertElement(t,W.HTML),e.insertionMode=Z.IN_TABLE_BODY}function mc(e,t){e.openElements.clearBackToTableContext(),e._insertFakeElement(K.TBODY,q.TBODY),e.insertionMode=Z.IN_TABLE_BODY,Ac(e,t)}function hc(e,t){e.openElements.hasInTableScope(q.TABLE)&&(e.openElements.popUntilTagNamePopped(q.TABLE),e._resetInsertionMode(),e._processStartTag(t))}function gc(e,t){Ms(t)?e._appendElement(t,W.HTML):bc(e,t),t.ackSelfClosing=!0}function _c(e,t){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(t,W.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function vc(e,t){switch(t.tagID){case q.TD:case q.TH:case q.TR:mc(e,t);break;case q.STYLE:case q.SCRIPT:case q.TEMPLATE:Q(e,t);break;case q.COL:fc(e,t);break;case q.FORM:_c(e,t);break;case q.TABLE:hc(e,t);break;case q.TBODY:case q.TFOOT:case q.THEAD:pc(e,t);break;case q.INPUT:gc(e,t);break;case q.CAPTION:uc(e,t);break;case q.COLGROUP:dc(e,t);break;default:bc(e,t)}}function yc(e,t){switch(t.tagID){case q.TABLE:e.openElements.hasInTableScope(q.TABLE)&&(e.openElements.popUntilTagNamePopped(q.TABLE),e._resetInsertionMode());break;case q.TEMPLATE:as(e,t);break;case q.BODY:case q.CAPTION:case q.COL:case q.COLGROUP:case q.HTML:case q.TBODY:case q.TD:case q.TFOOT:case q.TH:case q.THEAD:case q.TR:break;default:bc(e,t)}}function bc(e,t){let n=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,ps(e,t),e.fosterParentingEnabled=n}function xc(e,t){e.pendingCharacterTokens.push(t)}function Sc(e,t){e.pendingCharacterTokens.push(t),e.hasNonWhitespacePendingCharacterToken=!0}function Cc(e,t){let n=0;if(e.hasNonWhitespacePendingCharacterToken)for(;n<e.pendingCharacterTokens.length;n++)bc(e,e.pendingCharacterTokens[n]);else for(;n<e.pendingCharacterTokens.length;n++)e._insertCharacters(e.pendingCharacterTokens[n]);e.insertionMode=e.originalInsertionMode,e._processToken(t)}var wc=new Set([q.CAPTION,q.COL,q.COLGROUP,q.TBODY,q.TD,q.TFOOT,q.TH,q.THEAD,q.TR]);function Tc(e,t){let n=t.tagID;wc.has(n)?e.openElements.hasInTableScope(q.CAPTION)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(q.CAPTION),e.activeFormattingElements.clearToLastMarker(),e.insertionMode=Z.IN_TABLE,vc(e,t)):$(e,t)}function Ec(e,t){let n=t.tagID;switch(n){case q.CAPTION:case q.TABLE:e.openElements.hasInTableScope(q.CAPTION)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(q.CAPTION),e.activeFormattingElements.clearToLastMarker(),e.insertionMode=Z.IN_TABLE,n===q.TABLE&&yc(e,t));break;case q.BODY:case q.COL:case q.COLGROUP:case q.HTML:case q.TBODY:case q.TD:case q.TFOOT:case q.TH:case q.THEAD:case q.TR:break;default:ac(e,t)}}function Dc(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.COL:e._appendElement(t,W.HTML),t.ackSelfClosing=!0;break;case q.TEMPLATE:Q(e,t);break;default:kc(e,t)}}function Oc(e,t){switch(t.tagID){case q.COLGROUP:e.openElements.currentTagId===q.COLGROUP&&(e.openElements.pop(),e.insertionMode=Z.IN_TABLE);break;case q.TEMPLATE:as(e,t);break;case q.COL:break;default:kc(e,t)}}function kc(e,t){e.openElements.currentTagId===q.COLGROUP&&(e.openElements.pop(),e.insertionMode=Z.IN_TABLE,e._processToken(t))}function Ac(e,t){switch(t.tagID){case q.TR:e.openElements.clearBackToTableBodyContext(),e._insertElement(t,W.HTML),e.insertionMode=Z.IN_ROW;break;case q.TH:case q.TD:e.openElements.clearBackToTableBodyContext(),e._insertFakeElement(K.TR,q.TR),e.insertionMode=Z.IN_ROW,Mc(e,t);break;case q.CAPTION:case q.COL:case q.COLGROUP:case q.TBODY:case q.TFOOT:case q.THEAD:e.openElements.hasTableBodyContextInTableScope()&&(e.openElements.clearBackToTableBodyContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE,vc(e,t));break;default:vc(e,t)}}function jc(e,t){let n=t.tagID;switch(t.tagID){case q.TBODY:case q.TFOOT:case q.THEAD:e.openElements.hasInTableScope(n)&&(e.openElements.clearBackToTableBodyContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE);break;case q.TABLE:e.openElements.hasTableBodyContextInTableScope()&&(e.openElements.clearBackToTableBodyContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE,yc(e,t));break;case q.BODY:case q.CAPTION:case q.COL:case q.COLGROUP:case q.HTML:case q.TD:case q.TH:case q.TR:break;default:yc(e,t)}}function Mc(e,t){switch(t.tagID){case q.TH:case q.TD:e.openElements.clearBackToTableRowContext(),e._insertElement(t,W.HTML),e.insertionMode=Z.IN_CELL,e.activeFormattingElements.insertMarker();break;case q.CAPTION:case q.COL:case q.COLGROUP:case q.TBODY:case q.TFOOT:case q.THEAD:case q.TR:e.openElements.hasInTableScope(q.TR)&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY,Ac(e,t));break;default:vc(e,t)}}function Nc(e,t){switch(t.tagID){case q.TR:e.openElements.hasInTableScope(q.TR)&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY);break;case q.TABLE:e.openElements.hasInTableScope(q.TR)&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY,jc(e,t));break;case q.TBODY:case q.TFOOT:case q.THEAD:(e.openElements.hasInTableScope(t.tagID)||e.openElements.hasInTableScope(q.TR))&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY,jc(e,t));break;case q.BODY:case q.CAPTION:case q.COL:case q.COLGROUP:case q.HTML:case q.TD:case q.TH:break;default:yc(e,t)}}function Pc(e,t){let n=t.tagID;wc.has(n)?(e.openElements.hasInTableScope(q.TD)||e.openElements.hasInTableScope(q.TH))&&(e._closeTableCell(),Mc(e,t)):$(e,t)}function Fc(e,t){let n=t.tagID;switch(n){case q.TD:case q.TH:e.openElements.hasInTableScope(n)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(n),e.activeFormattingElements.clearToLastMarker(),e.insertionMode=Z.IN_ROW);break;case q.TABLE:case q.TBODY:case q.TFOOT:case q.THEAD:case q.TR:e.openElements.hasInTableScope(n)&&(e._closeTableCell(),Nc(e,t));break;case q.BODY:case q.CAPTION:case q.COL:case q.COLGROUP:case q.HTML:break;default:ac(e,t)}}function Ic(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.OPTION:e.openElements.currentTagId===q.OPTION&&e.openElements.pop(),e._insertElement(t,W.HTML);break;case q.OPTGROUP:e.openElements.currentTagId===q.OPTION&&e.openElements.pop(),e.openElements.currentTagId===q.OPTGROUP&&e.openElements.pop(),e._insertElement(t,W.HTML);break;case q.HR:e.openElements.currentTagId===q.OPTION&&e.openElements.pop(),e.openElements.currentTagId===q.OPTGROUP&&e.openElements.pop(),e._appendElement(t,W.HTML),t.ackSelfClosing=!0;break;case q.INPUT:case q.KEYGEN:case q.TEXTAREA:case q.SELECT:e.openElements.hasInSelectScope(q.SELECT)&&(e.openElements.popUntilTagNamePopped(q.SELECT),e._resetInsertionMode(),t.tagID!==q.SELECT&&e._processStartTag(t));break;case q.SCRIPT:case q.TEMPLATE:Q(e,t);break;default:}}function Lc(e,t){switch(t.tagID){case q.OPTGROUP:e.openElements.stackTop>0&&e.openElements.currentTagId===q.OPTION&&e.openElements.tagIDs[e.openElements.stackTop-1]===q.OPTGROUP&&e.openElements.pop(),e.openElements.currentTagId===q.OPTGROUP&&e.openElements.pop();break;case q.OPTION:e.openElements.currentTagId===q.OPTION&&e.openElements.pop();break;case q.SELECT:e.openElements.hasInSelectScope(q.SELECT)&&(e.openElements.popUntilTagNamePopped(q.SELECT),e._resetInsertionMode());break;case q.TEMPLATE:as(e,t);break;default:}}function Rc(e,t){let n=t.tagID;n===q.CAPTION||n===q.TABLE||n===q.TBODY||n===q.TFOOT||n===q.THEAD||n===q.TR||n===q.TD||n===q.TH?(e.openElements.popUntilTagNamePopped(q.SELECT),e._resetInsertionMode(),e._processStartTag(t)):Ic(e,t)}function zc(e,t){let n=t.tagID;n===q.CAPTION||n===q.TABLE||n===q.TBODY||n===q.TFOOT||n===q.THEAD||n===q.TR||n===q.TD||n===q.TH?e.openElements.hasInTableScope(n)&&(e.openElements.popUntilTagNamePopped(q.SELECT),e._resetInsertionMode(),e.onEndTag(t)):Lc(e,t)}function Bc(e,t){switch(t.tagID){case q.BASE:case q.BASEFONT:case q.BGSOUND:case q.LINK:case q.META:case q.NOFRAMES:case q.SCRIPT:case q.STYLE:case q.TEMPLATE:case q.TITLE:Q(e,t);break;case q.CAPTION:case q.COLGROUP:case q.TBODY:case q.TFOOT:case q.THEAD:e.tmplInsertionModeStack[0]=Z.IN_TABLE,e.insertionMode=Z.IN_TABLE,vc(e,t);break;case q.COL:e.tmplInsertionModeStack[0]=Z.IN_COLUMN_GROUP,e.insertionMode=Z.IN_COLUMN_GROUP,Dc(e,t);break;case q.TR:e.tmplInsertionModeStack[0]=Z.IN_TABLE_BODY,e.insertionMode=Z.IN_TABLE_BODY,Ac(e,t);break;case q.TD:case q.TH:e.tmplInsertionModeStack[0]=Z.IN_ROW,e.insertionMode=Z.IN_ROW,Mc(e,t);break;default:e.tmplInsertionModeStack[0]=Z.IN_BODY,e.insertionMode=Z.IN_BODY,$(e,t)}}function Vc(e,t){t.tagID===q.TEMPLATE&&as(e,t)}function Hc(e,t){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(q.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(t)):Yo(e,t)}function Uc(e,t){t.tagID===q.HTML?$(e,t):Gc(e,t)}function Wc(e,t){if(t.tagID===q.HTML){if(e.fragmentContext||(e.insertionMode=Z.AFTER_AFTER_BODY),e.options.sourceCodeLocationInfo&&e.openElements.tagIDs[0]===q.HTML){e._setEndLocation(e.openElements.items[0],t);let n=e.openElements.items[1];n&&!e.treeAdapter.getNodeSourceCodeLocation(n)?.endTag&&e._setEndLocation(n,t)}}else Gc(e,t)}function Gc(e,t){e.insertionMode=Z.IN_BODY,ps(e,t)}function Kc(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.FRAMESET:e._insertElement(t,W.HTML);break;case q.FRAME:e._appendElement(t,W.HTML),t.ackSelfClosing=!0;break;case q.NOFRAMES:Q(e,t);break;default:}}function qc(e,t){t.tagID===q.FRAMESET&&!e.openElements.isRootHtmlElementCurrent()&&(e.openElements.pop(),!e.fragmentContext&&e.openElements.currentTagId!==q.FRAMESET&&(e.insertionMode=Z.AFTER_FRAMESET))}function Jc(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.NOFRAMES:Q(e,t);break;default:}}function Yc(e,t){t.tagID===q.HTML&&(e.insertionMode=Z.AFTER_AFTER_FRAMESET)}function Xc(e,t){t.tagID===q.HTML?$(e,t):Zc(e,t)}function Zc(e,t){e.insertionMode=Z.IN_BODY,ps(e,t)}function Qc(e,t){switch(t.tagID){case q.HTML:$(e,t);break;case q.NOFRAMES:Q(e,t);break;default:}}function $c(e,t){t.chars=`�`,e._insertCharacters(t)}function el(e,t){e._insertCharacters(t),e.framesetOk=!1}function tl(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==W.HTML&&e.openElements.currentTagId!==void 0&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function nl(e,t){if(wo(t))tl(e),e._startTagOutsideForeignContent(t);else{let n=e._getAdjustedCurrentElement(),r=e.treeAdapter.getNamespaceURI(n);r===W.MATHML?To(t):r===W.SVG&&(Oo(t),Eo(t)),Do(t),t.selfClosing?e._appendElement(t,r):e._insertElement(t,r),t.ackSelfClosing=!0}}function rl(e,t){if(t.tagID===q.P||t.tagID===q.BR){tl(e),e._endTagOutsideForeignContent(t);return}for(let n=e.openElements.stackTop;n>0;n--){let r=e.openElements.items[n];if(e.treeAdapter.getNamespaceURI(r)===W.HTML){e._endTagOutsideForeignContent(t);break}let i=e.treeAdapter.getTagName(r);if(i.toLowerCase()===t.tagName){t.tagName=i,e.openElements.shortenToLength(n);break}}}var il=new Set([K.AREA,K.BASE,K.BASEFONT,K.BGSOUND,K.BR,K.COL,K.EMBED,K.FRAME,K.HR,K.IMG,K.INPUT,K.KEYGEN,K.LINK,K.META,K.PARAM,K.SOURCE,K.TRACK,K.WBR]);function al(e,t){return t.treeAdapter.isElementNode(e)&&t.treeAdapter.getNamespaceURI(e)===W.HTML&&il.has(t.treeAdapter.getTagName(e))}var ol={treeAdapter:io,scriptingEnabled:!0};function sl(e,t){let n={...ol,...t};return al(e,n)?``:cl(e,n)}function cl(e,t){let n=``,r=t.treeAdapter.isElementNode(e)&&t.treeAdapter.getTagName(e)===K.TEMPLATE&&t.treeAdapter.getNamespaceURI(e)===W.HTML?t.treeAdapter.getTemplateContent(e):e,i=t.treeAdapter.getChildNodes(r);if(i)for(let e of i)n+=ll(e,t);return n}function ll(e,t){return t.treeAdapter.isElementNode(e)?ul(e,t):t.treeAdapter.isTextNode(e)?fl(e,t):t.treeAdapter.isCommentNode(e)?pl(e,t):t.treeAdapter.isDocumentTypeNode(e)?ml(e,t):``}function ul(e,t){let n=t.treeAdapter.getTagName(e);return`<${n}${dl(e,t)}>${al(e,t)?``:`${cl(e,t)}</${n}>`}`}function dl(e,{treeAdapter:t}){let n=``;for(let r of t.getAttrList(e)){if(n+=` `,r.namespace)switch(r.namespace){case W.XML:n+=`xml:${r.name}`;break;case W.XMLNS:r.name!==`xmlns`&&(n+=`xmlns:`),n+=r.name;break;case W.XLINK:n+=`xlink:${r.name}`;break;default:n+=`${r.prefix}:${r.name}`}else n+=r.name;n+=`="${mn(r.value)}"`}return n}function fl(e,t){let{treeAdapter:n}=t,r=n.getTextNodeContent(e),i=n.getParentNode(e),a=i&&n.isElementNode(i)&&n.getTagName(i);return a&&n.getNamespaceURI(i)===W.HTML&&ja(a,t.scriptingEnabled)?r:hn(r)}function pl(e,{treeAdapter:t}){return`<!--${t.getCommentNodeContent(e)}-->`}function ml(e,{treeAdapter:t}){return`<!DOCTYPE ${t.getDocumentTypeNodeName(e)}>`}function hl(e,t){return Ro.parse(e,t)}function gl(e){return`attrs`in e&&`tagName`in e}function _l(e){return gl(e)&&e.nodeName===`template`}function vl(e,t,n){e.attrs=e.attrs.filter(e=>e.name!==t),n!==void 0&&e.attrs.push({name:t,value:n})}function yl(e){if(gl(e)){vl(e,Wt),vl(e,Ht);let t=e.sourceCodeLocation;t&&(vl(e,Wt,String(t.startLine)),vl(e,Ht,String(t.endLine)))}if(`childNodes`in e)for(let t of e.childNodes)yl(t);_l(e)&&yl(e.content)}function bl(e){let t=hl(e,{sourceCodeLocationInfo:!0});yl(t);let n=t.childNodes.find(e=>gl(e)&&e.tagName===`html`);return n&&vl(n,Vt,String(zt(e))),sl(t)}var xl=[[`img`,`src`],[`script`,`src`],[`link[rel~="stylesheet" i]`,`href`],[`link[rel~="icon" i]`,`href`],[`source`,`src`],[`video`,`src`],[`video`,`poster`],[`audio`,`src`]],Sl=[`img[srcset]`,`source[srcset]`],Cl=20*1024*1024;async function wl(e,t,n,r,i,a,o,s){let c=new DOMParser().parseFromString(bl(n),`text/html`);if(i!==void 0){let e=c.createElement(`style`);e.textContent=`:where(html) { font-size: ${i}px; }`;let t=c.head??c.documentElement;t.insertBefore(e,t.firstChild)}fa(c)&&await Tl(c);let l=[];for(let[n,i]of xl)for(let o of c.querySelectorAll(n)){let n=ut(t,o.getAttribute(i)??``);n&&(o.removeAttribute(i),l.push(El(e,n,r,a).then(e=>{e&&o.setAttribute(i,e)})))}for(let n of Sl)for(let i of c.querySelectorAll(n)){let n=dt(i.getAttribute(`srcset`)??``),o=n.map(({ref:e})=>ut(t,e));o.some(e=>e!==null)&&(i.removeAttribute(`srcset`),l.push(Promise.all(n.map(async(t,n)=>{let i=o[n];if(!i)return t;let s=await El(e,i,r,a);return s?{...t,ref:s}:null})).then(e=>{let t=e.filter(e=>e!==null);t.length>0&&i.setAttribute(`srcset`,st(t))})))}return await Promise.all(l),o&&ea(c,o),s&&la(c,s),`<!doctype html>${c.documentElement.outerHTML}`}async function Tl(e){let{default:t}=await E(async()=>{let{default:e}=await import(`./_virtual_katex-inline-css-DN-_JSKR.js`);return{default:e}},[]),n=e.createElement(`style`);n.textContent=`${t}\n${an}`,(e.head??e.documentElement).appendChild(n)}function El(e,t,n,r){let i=n.get(t);if(i)return i;let a=Ci(e,t,r).then(async e=>e.size>Cl?null:`data:${Dl(t,e.type)};base64,${Ol(await e.arrayBuffer())}`).catch(()=>null);return n.set(t,a),a}function Dl(e,t){let n=(e.split(`/`).pop()??``).split(`.`).pop()?.toLowerCase()??``;return n===`css`?`text/css`:n===`js`||n===`mjs`?`text/javascript`:t!==``&&t!==`application/octet-stream`?t:`application/octet-stream`}function Ol(e){let t=new Uint8Array(e),n=``,r=32768;for(let e=0;e<t.length;e+=r)n+=String.fromCharCode(...t.subarray(e,e+r));return btoa(n)}function kl({session:e,path:t,text:n,root:r,scrollDriver:i=!1,scrollReceiver:a=!1,scrollChannel:o=`profile`,focused:s=!0,onRevealSource:c,mobile:l=!1}){let u=Lt(`html`,[e,r,t]),[d,f]=(0,I.useState)(null),p=(0,I.useRef)(new Map),m=C().editorFontSize,h=(0,I.useRef)(null),[g]=(0,I.useState)(Ji),[_]=(0,I.useState)(Ji),v=$e({shortcutEnabled:s,onFind:(e,t,n)=>oa(h.current?.contentWindow??null,_,e,t,n),onClear:()=>sa(h.current?.contentWindow??null,_),onCloseFocus:()=>h.current?.focus()}),y=(0,I.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),b=(0,I.useMemo)(()=>zt(n),[n]);return(0,I.useEffect)(()=>{let i=!1;return wl(e,t,n,p.current,m,r,g,_).then(e=>{i||f(e)}),()=>{i=!0}},[e,t,n,m,r,g,_,l]),(0,I.useEffect)(()=>{let e=e=>{let t=aa(e,h.current?.contentWindow??null,_);t?.kind===`puddle-preview-find-open`?v.openFind():t?.kind===`puddle-preview-find-result`&&v.setResult(t)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[v.openFind,v.setResult,_]),(0,I.useEffect)(()=>{if(a)return Jn.subscribe(o,y,e=>{Qi(h.current?.contentWindow??null,g,e)})},[a,o,y,g]),(0,I.useEffect)(()=>{let e=e=>{let t=Xi(e,h.current?.contentWindow??null,g);if(t)if(t.layout&&(a||!t.scrolled)){let e=(a?Jn.get(o,y):void 0)??Yn.get(u);if(e&&Qi(h.current?.contentWindow??null,g,e),i){let n=e??t;Jn.publish(o,y,n.ratio,n.sourceLine)}}else Yn.set(u,{ratio:t.ratio,sourceLine:t.sourceLine,revision:0}),i&&Jn.publish(o,y,t.ratio,t.sourceLine);let n=c?Zi(e,h.current?.contentWindow??null,g):null;n&&c?.({line:oi(n.line,b)})};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[i,a,o,y,g,c,b,u]),d===null?null:(0,L.jsxs)(`div`,{className:`relative size-full bg-paper`,children:[(0,L.jsx)(`iframe`,{ref:h,sandbox:`allow-scripts`,src:l?`/preview.html`:void 0,srcDoc:l?void 0:d,title:t,className:`size-full bg-paper`,onLoad:()=>{let e=h.current;l&&e&&!e.dataset.delivered&&(e.dataset.delivered=`true`,e.contentWindow?.postMessage({kind:`puddle-preview-document`,html:d},`*`));{let e=(a?Jn.get(o,y):void 0)??Yn.get(u);e&&Qi(h.current?.contentWindow??null,g,e)}v.refresh()}},l?d:void 0),(0,L.jsx)(ai,{controls:v})]})}function Al({kind:e,...t}){return e===`notebook`?(0,L.jsx)(Ri,{...t}):e===`markdown`?(0,L.jsx)(Ui,{...t}):(0,L.jsx)(kl,{...t})}function jl({session:e,path:t,kind:n,root:r,focused:i=!0,scrollDriver:a=!1,scrollReceiver:o=!1,scrollChannel:s=`profile`,onRevealSource:c,onRunCompilation:l,compilationRunning:u}){let{openFile:d}=ke(),f=cr(e,t,null,r,{passive:n!==`notebook`,live:!0,focused:i}),p=f.model,m=(0,I.useSyncExternalStore)(n=>It(Ft(e,t,r),n),()=>p?.getValue()??null);return f.conflict&&f.conflict.phase!==`unresolved`?(0,L.jsx)(Un,{session:e,path:t,buffer:f,focused:i}):m===null?(0,L.jsx)(`p`,{className:`p-6 text-sm text-fg-muted`,children:f.status===`loading`?`Loading…`:f.errorMessage??`This file cannot be previewed.`}):n===`notebook`?(0,L.jsx)(Ri,{session:e,path:t,root:r,text:m,focused:i,onOpenFile:t=>d(e,t,void 0,{...ct(t)?{view:`preview`}:{},...r===void 0?{}:{root:r}}),onRun:l?()=>l(!0):void 0,running:u,onUndo:()=>{p?.undo()},onRedo:()=>{p?.redo()},onChange:e=>{let t=f.model;if(!t)return;let n=Zr(t.getValue(),e),r=t.getPositionAt(n.start),i=t.getPositionAt(n.end);t.pushStackElement(),t.pushEditOperations([],[{range:{startLineNumber:r.lineNumber,startColumn:r.column,endLineNumber:i.lineNumber,endColumn:i.column},text:n.text}],()=>null),t.pushStackElement()}}):(0,L.jsx)(Al,{session:e,path:t,kind:n,text:m,root:r,scrollDriver:a,scrollReceiver:o,scrollChannel:s,focused:i,onRevealSource:c,onOpenFile:t=>d(e,t,void 0,{...ct(t)?{view:`preview`}:{},...r===void 0?{}:{root:r}})})}var Ml={png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,webp:`image`,bmp:`image`,ico:`image`,avif:`image`,svg:`image`,mp4:`video`,m4v:`video`,webm:`video`,mov:`video`,mkv:`video`,avi:`video`,mp3:`audio`,wav:`audio`,ogg:`audio`,m4a:`audio`,flac:`audio`,aac:`audio`,pdf:`pdf`};function Nl(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<=0?null:Ml[t.slice(n+1).toLowerCase()]??null}var Pl=(0,I.lazy)(()=>E(()=>import(`./PdfViewer-C-dXDOjG.js`).then(e=>({default:e.PdfViewer})),__vite__mapDeps([13,1,2,3,6,8,7,14,10,15,16,17,18,19,20])));function Fl({session:e,path:t,kind:n,root:r,generatedBy:i,refreshKey:a,onRevealSource:o,readOnly:s=!1}){let{asset:c,error:l}=Rl(e,t,r,Ae(e,t,r),a);if(l)return(0,L.jsxs)(Il,{children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:l}),!s&&(0,L.jsx)(Ll,{session:e,path:t,root:r})]});if(!c)return(0,L.jsx)(Il,{children:(0,L.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`…`})});let{url:u,blob:d}=c;return n===`image`?(0,L.jsx)(Il,{children:(0,L.jsx)(`img`,{src:u,alt:t,className:`max-h-full max-w-full object-contain`})}):n===`video`?(0,L.jsx)(Il,{children:(0,L.jsx)(`video`,{src:u,controls:!0,className:`max-h-full max-w-full`})}):n===`audio`?(0,L.jsx)(Il,{children:(0,L.jsx)(`audio`,{src:u,controls:!0,className:`w-full max-w-xl`})}):(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(Il,{children:(0,L.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`Loading PDF…`})}),children:(0,L.jsx)(Pl,{blob:d,session:e,path:t,root:r,onRevealSource:!s&&Bl(t,r,i)?o:void 0,onDownload:s?void 0:()=>void zl(e,t,r)})})}function Il({children:e}){return(0,L.jsx)(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 overflow-auto bg-ground p-4`,children:e})}function Ll({session:e,path:t,root:n}){return(0,L.jsx)(`button`,{type:`button`,onClick:()=>void zl(e,t,n),className:`rounded-md bg-elevated px-3 py-1.5 text-sm text-fg transition-colors hover:bg-border/70`,children:`Download`})}function Rl(e,t,n,r=0,i){let[a,o]=(0,I.useState)(null),[s,c]=(0,I.useState)(null);return(0,I.useEffect)(()=>{let r=null,i=!1;return o(null),c(null),Ci(e,t,n).then(e=>{i||(r=URL.createObjectURL(e),o({url:r,blob:e}))}).catch(e=>{i||c(e instanceof Error?e.message:`Couldn’t load this file.`)}),()=>{i=!0,r&&URL.revokeObjectURL(r)}},[e,t,n,r,i]),{asset:a,error:s}}function zl(e,t,n){return me(e,t,n).catch(e=>{ze.error(e instanceof Error?e.message:`Download failed`)})}function Bl(e,t,n){if(!t||!e.toLowerCase().endsWith(`.pdf`))return!1;if(n===`latex`)return!0;let r=t.replaceAll(`\\`,`/`).replaceAll(/\/{2,}/g,`/`);return`${r}/${e.replaceAll(`\\`,`/`)}`.includes(`/.puddle/latex/`)||/(?:^|\/)latex\/[a-f\d]{24}\/current\/?$/i.test(r)}function Vl({tab:e,reveal:t,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a,onRevealSource:o,onRevealCompiledSource:s,onRunCompilation:c,compilationRunning:l}){let u=lt(e),d=e.view===`preview`||e.view===`linked`||e.view===`locked`,f=e.view===`linked`||e.view===`locked`?`${e.view}:${e.session}:${e.root??``}:${e.path}`:ot(e);if(u===`diff`)return(0,L.jsx)(Ir,{session:e.session,path:e.path,root:e.root,area:e.git_area,focused:n},ot(e));if(u===`commit`&&e.sha)return(0,L.jsx)(Fr,{session:e.session,sha:e.sha,path:e.path,root:e.root},ot(e));if(u===`external`&&e.root!==void 0){let u=Nl(e.path);if(u)return(0,L.jsx)(Fl,{session:e.session,path:e.path,kind:u,root:e.root,generatedBy:e.generated_by,onRevealSource:s},ot(e));let p=d?ct(e.path):null;return p?(0,L.jsx)(jl,{session:e.session,path:e.path,kind:p,onRunCompilation:e.generated_by?void 0:c,compilationRunning:l,root:e.root,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a,onRevealSource:o},f):(0,L.jsx)(Sr,{session:e.session,path:e.path,reveal:t,root:e.root,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a},ot(e))}if(u===`untitled`)return(0,L.jsx)(Rr,{name:e.path},ot(e));let p=Nl(e.path);if(p)return(0,L.jsx)(Fl,{session:e.session,path:e.path,kind:p,generatedBy:e.generated_by,onRevealSource:s},ot(e));let m=d?ct(e.path):null;return m?(0,L.jsx)(jl,{session:e.session,path:e.path,kind:m,onRunCompilation:e.generated_by?void 0:c,compilationRunning:l,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a,onRevealSource:o},f):(0,L.jsx)(Sr,{session:e.session,path:e.path,reveal:t,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a},ot(e))}export{Vl as PaneEditorBody};
|