@puddle-code/cli 0.5.0 → 0.5.4
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 +3 -43
- package/README.md +10 -10
- package/dist/host-control.mjs +4070 -448
- package/dist/index.js +4701 -910
- package/dist/install-cli.sh +2 -2
- package/dist/install.sh +10 -6
- package/dist/public/assets/App-bTB2uhzH.js +9 -0
- package/dist/public/assets/{CompilationCommandForm-D7uBn2um.js → CompilationCommandForm-DXHvwQ8Y.js} +1 -1
- package/dist/public/assets/Dashboard-DgJMsE3L.js +1 -0
- package/dist/public/assets/DraftRecovery-B8Ld4_1b.js +1 -0
- package/dist/public/assets/EditorTabClose-CGYLU9GK.js +1 -0
- package/dist/public/assets/FileCloseScope-DoZ0oLf8.js +1 -0
- package/dist/public/assets/{FileEditorSettingsMenu-DnMJu5pC.js → FileEditorSettingsMenu-BbRHII96.js} +1 -1
- package/dist/public/assets/HuddlePane-LF3pjMQM.js +219 -0
- package/dist/public/assets/LazyTerminal-BEOPZDJH.js +2 -0
- package/dist/public/assets/ModelRefcount-CWfA9XXu.js +1 -0
- package/dist/public/assets/{NotebookWidget-DlpLANDa.js → NotebookWidget-BDdx0BOy.js} +1 -1
- package/dist/public/assets/PaneEditorBody-C1uu9cRG.js +284 -0
- package/dist/public/assets/PdfViewer-DLCPKybn.js +2 -0
- package/dist/public/assets/ReadOnlyDiff-C7ZSVRt-.js +2 -0
- package/dist/public/assets/{ReleaseNotesDialog-sQVKJ6dm.js → ReleaseNotesDialog-B9fRaZNN.js} +1 -1
- package/dist/public/assets/Ripple-BBMjOG3U.css +1 -0
- package/dist/public/assets/{Ripple-CLkhZZWa.js → Ripple-Dzg6tdOM.js} +1 -1
- package/dist/public/assets/SettingsDialog-Cwm4tMf3.js +8 -0
- package/dist/public/assets/{Terminal-C3TQK74f.js → Terminal-BxoyAAEW.js} +20 -20
- package/dist/public/assets/Workspace-1x4PD8Q7.js +20 -0
- package/dist/public/assets/{api--n1Ha6tG.js → api-CrP4jl9e.js} +1 -1
- package/dist/public/assets/auth-1SSLu56b.js +1 -0
- package/dist/public/assets/{buffer-logic-BAkSBQT7.js → buffer-logic-D9FvoilV.js} +1 -1
- package/dist/public/assets/buffer-store-OTFEYxTw.js +1 -0
- package/dist/public/assets/colour-picker-DZdAiaVI.js +1 -0
- package/dist/public/assets/content-state-CROLtMfN.js +1 -0
- package/dist/public/assets/{context-BRrQlmgI.js → context-NsaMZKAN.js} +1 -1
- package/dist/public/assets/disclosure-CpSwsC7J.js +1 -0
- package/dist/public/assets/drafts-CBbjQQbz.js +1 -0
- package/dist/public/assets/editor-context-T5zIHY3K.js +5 -0
- package/dist/public/assets/{editor-sync-C5CgYn_q.js → editor-sync-BOfDr2yY.js} +1 -1
- package/dist/public/assets/{errors-DWF9D4n6.js → errors-CviT-mvB.js} +1 -1
- package/dist/public/assets/expanding-content-Cbt69Y_L.js +1 -0
- package/dist/public/assets/{file-editor-settings-1cj6VRxs.js → file-editor-settings-BXTs1F7S.js} +1 -1
- package/dist/public/assets/{file-links-BEPA2kg5.js → file-links-CgOYgoMC.js} +1 -1
- package/dist/public/assets/forward-link-qOyuWj08.js +1 -0
- package/dist/public/assets/hotkeys-nP8gYtE7.js +1 -0
- package/dist/public/assets/index-BB_BPKbu.css +2 -0
- package/dist/public/assets/index-LRHyaDMJ.js +10 -0
- package/dist/public/assets/local-store-Dy1Cd8sn.js +276 -0
- package/dist/public/assets/{markdown-Cseepnv3.js → markdown-Dj7Cr7RL.js} +4 -4
- package/dist/public/assets/notification-delivery-D99P0nLs.js +1 -0
- package/dist/public/assets/{preferences-Dy_61zsm.js → preferences-CvSHA-AA.js} +1 -1
- package/dist/public/assets/profile-icons-BI2xFWcB.js +1 -0
- package/dist/public/assets/{profile-store-CarO9MCP.js → profile-store-D4lZiXgL.js} +2 -2
- package/dist/public/assets/{project-actions-Zt9oqLe5.js → project-actions-Ck504AFM.js} +1 -1
- package/dist/public/assets/project-drag-BnkK15qk.js +1 -0
- package/dist/public/assets/{protocol-support-BUdL5Q-x.js → protocol-support-iXloAH0N.js} +1 -1
- package/dist/public/assets/queries-BSkHGZG8.js +1 -0
- package/dist/public/assets/queue-4USHmW_D.js +3 -0
- package/dist/public/assets/{render-rich-content-BULX1bwr.js → render-rich-content-fo4uQVWR.js} +1 -1
- package/dist/public/assets/save-BT7q_AMN.js +1 -0
- package/dist/public/assets/{scroll-restoration-Bl3jxJsC.js → scroll-restoration-C_ly1bKS.js} +1 -1
- package/dist/public/assets/selection-actions-BeE1dYsZ.js +1 -0
- package/dist/public/assets/session-display-BUDNzNmg.js +1 -0
- package/dist/public/assets/session-order-b3nCJcCG.js +1 -0
- package/dist/public/assets/shield-check-CY69Ons-.js +1 -0
- package/dist/public/assets/source-anchor-map-BNxSa_bJ.js +1 -0
- package/dist/public/assets/square-terminal-CrlDquCd.js +1 -0
- package/dist/public/assets/state-CuUqRNo7.js +1 -0
- package/dist/public/assets/switch-CGrhQUXr.js +1 -0
- package/dist/public/assets/tooltip-Ek-eHPZu.js +1 -0
- package/dist/public/assets/trash-2-WYPJMQLN.js +1 -0
- package/dist/public/assets/{use-arrangement-ready-D18CpR8E.js → use-arrangement-ready-1vmV5np6.js} +1 -1
- package/dist/public/assets/use-desktop-state-CBTzsmlz.js +2 -0
- package/dist/public/assets/view-state-store-Dqk7M5ei.js +1 -0
- package/dist/public/assets/ws-CDXOuBYB.js +1 -0
- package/dist/public/assets/zoom-intent-vemBFIak.js +1 -0
- package/dist/public/index.html +8 -8
- package/dist/public/manifest.webmanifest +1 -1
- package/dist/public/notification-worker.js +1 -1
- package/dist/pudl.js +5816 -600
- package/package.json +2 -2
- package/dist/public/assets/App-ESs-lBsA.js +0 -49
- package/dist/public/assets/Dashboard-DWwOy6bQ.js +0 -1
- package/dist/public/assets/DraftRecovery-DO-ymSIW.js +0 -1
- package/dist/public/assets/EditorTabClose-DEizui0i.js +0 -1
- package/dist/public/assets/FileCloseScope-DKbSgHF2.js +0 -1
- package/dist/public/assets/LazyTerminal-B0GmOiTE.js +0 -2
- package/dist/public/assets/ModelRefcount-DBzR9UEq.js +0 -1
- package/dist/public/assets/PaneEditorBody-DRZ6NrJ1.js +0 -284
- package/dist/public/assets/PdfViewer-B3z9sh0x.js +0 -2
- package/dist/public/assets/Ripple-C8HPFMGB.css +0 -1
- package/dist/public/assets/SettingsDialog-DBUHpb9S.js +0 -8
- package/dist/public/assets/Workspace-D_NxUGYW.js +0 -20
- package/dist/public/assets/auth-eu0vmKkB.js +0 -1
- package/dist/public/assets/buffer-store-CBhXNRZm.js +0 -1
- package/dist/public/assets/content-state-BDt3NnGs.js +0 -1
- package/dist/public/assets/drafts-CCenbr5J.js +0 -1
- package/dist/public/assets/editor-links-qwyINDCv.js +0 -1
- package/dist/public/assets/expanding-content-BUkS1Qk4.js +0 -1
- package/dist/public/assets/forward-link-CcmVXHkx.js +0 -1
- package/dist/public/assets/index-Botodnry.js +0 -10
- package/dist/public/assets/index-rjm6DMrz.css +0 -2
- package/dist/public/assets/local-store-8IcyY3pd.js +0 -64
- package/dist/public/assets/notification-delivery-CWj1p0u-.js +0 -1
- package/dist/public/assets/project-drag-Bqy-V-45.js +0 -1
- package/dist/public/assets/queries-DnuokC1N.js +0 -1
- package/dist/public/assets/queue-BlrQxHDl.js +0 -3
- package/dist/public/assets/selection-actions-BSqrsD_7.js +0 -1
- package/dist/public/assets/session-order-CCDTBSiH.js +0 -1
- package/dist/public/assets/switch-BsUkvj8j.js +0 -1
- package/dist/public/assets/trash-2-DQeNROsF.js +0 -1
- package/dist/public/assets/use-desktop-state-Dw9EfOjg.js +0 -2
- package/dist/public/assets/view-state-store-CY9DI6-i.js +0 -1
- package/dist/public/assets/ws-DH0dKRnO.js +0 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NotebookWidget-BDdx0BOy.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/local-store-Dy1Cd8sn.js","assets/context-NsaMZKAN.js","assets/protocol-support-iXloAH0N.js","assets/api-CrP4jl9e.js","assets/auth-1SSLu56b.js","assets/queries-BSkHGZG8.js","assets/jsx-runtime-By8HlURe.js","assets/theme-swfNLod9.js","assets/preload-helper-Czpn1I53.js","assets/PdfViewer-DLCPKybn.js","assets/dist-BOS6OKSE.js","assets/react-dom-cJyBB_A4.js","assets/createLucideIcon-DyMAgLa3.js","assets/control-tray-CjoJunx1.js","assets/utils-B6KiDbIe.js","assets/control-tray-CG26TqqQ.css","assets/view-state-store-Dqk7M5ei.js","assets/profile-store-D4lZiXgL.js","assets/content-state-CROLtMfN.js","assets/zoom-intent-vemBFIak.js","assets/scroll-restoration-C_ly1bKS.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{_ as n,g as r,h as i,m as a,p as o}from"./protocol-support-iXloAH0N.js";import{B as s,Bn as c,Fn as l,In as u,Ln as d,Mn as f,Nn as p,Pn as m,Vn as h,q as g,r as _,zn as v}from"./local-store-Dy1Cd8sn.js";import{n as y,t as b}from"./context-NsaMZKAN.js";import{i as x}from"./client-settings-BdKglwtW.js";import{r as S,s as C}from"./theme-swfNLod9.js";import{t as w}from"./jsx-runtime-By8HlURe.js";import{t as T}from"./preload-helper-Czpn1I53.js";import{t as E}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{c as D,h as O,i as k,p as A,r as j}from"./editor.api2-Cyagyq8b.js";import{n as M,r as ee,t as N}from"./api-CrP4jl9e.js";import{i as te,o as ne}from"./profile-store-D4lZiXgL.js";import{b as re,ht as ie,it as ae,nt as oe}from"./queries-BSkHGZG8.js";import{A as se,B as ce,J as le,K as ue,N as de,O as fe,P as pe,V as me,Y as he,a as ge,n as _e,q as ve,s as ye}from"./editor-context-T5zIHY3K.js";import{n as be}from"./dist-BOS6OKSE.js";import{t as xe}from"./x-CbfJFzGo.js";import{a as Se,i as Ce,n as we,r as Te,s as Ee,t as De}from"./select-DzQdQNsv.js";import{t as Oe}from"./button-D-qeQvl5.js";import{n as ke,t as Ae}from"./chevron-right-DUkOv15w.js";import{t as je}from"./createLucideIcon-DyMAgLa3.js";import{A as Me,D as Ne,E as Pe,T as Fe,a as Ie,f as Le,h as Re,i as ze,j as Be,k as Ve,o as He,p as Ue,r as We,s as Ge,t as Ke,v as qe,w as Je,y as Ye}from"./DraftRecovery-B8Ld4_1b.js";import{t as Xe}from"./chevron-down--sjpQEHH.js";import{a as Ze,n as Qe,o as $e,r as et,t as tt}from"./FindWidget-ET5pwkkB.js";import{a as nt,c as rt,d as it,f as at,g as ot,h as st,i as ct,l as lt,m as ut,n as dt,o as ft,p as pt,r as mt,s as ht,t as gt,u as _t}from"./ReadOnlyDiff-C7ZSVRt-.js";import{t as vt}from"./copy-CGsu8426.js";import{n as yt}from"./disclosure-CpSwsC7J.js";import{t as bt}from"./rotate-ccw-CNjR2LSi.js";import{t as xt}from"./trash-2-WYPJMQLN.js";import{h as St}from"./hotkeys-nP8gYtE7.js";import{t as Ct}from"./control-tray-CjoJunx1.js";import{t as wt}from"./ws-CDXOuBYB.js";import{a as Tt,o as Et,r as Dt,s as Ot,t as kt}from"./command-BeX8pm7h.js";import{n as At,r as jt,t as Mt}from"./popover-Okyclsx8.js";import{i as Nt,n as Pt,r as Ft}from"./markdown-it-CWoG9_Dn.js";import{a as It,i as Lt,n as Rt,o as zt,r as Bt,t as Vt}from"./preview-kind-CJ9RTgbs.js";import{t as Ht}from"./content-state-CROLtMfN.js";import{t as Ut}from"./debounce-B9DrqirV.js";import{i as Wt,n as Gt,r as Kt}from"./languages-O6mK4sJI.js";import{n as qt,t as Jt}from"./file-editor-settings-BXTs1F7S.js";import{r as Yt,t as Xt}from"./view-state-store-Dqk7M5ei.js";import{a as Zt,i as Qt,n as $t,r as en,s as tn,t as nn}from"./source-anchor-map-BNxSa_bJ.js";import{p as rn,t as an}from"./buffer-store-OTFEYxTw.js";import{t as on}from"./markdown-Dj7Cr7RL.js";import{r as sn,t as cn}from"./math-CSw6sgCC.js";import{n as ln}from"./math-delimiters-BCnTi7Ii.js";import{n as un}from"./markdown-mermaid-TizVRNLQ.js";var dn=je(`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`}]]),fn=je(`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`}]]),pn=je(`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`}]]),mn=je(`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`}]]),P=e(t(),1),F=w();String.prototype.codePointAt;function hn(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 gn=hn(/["&\u00A0]/g,new Map([[34,`"`],[38,`&`],[160,` `]])),_n=hn(/[&<>\u00A0]/g,new Map([[38,`&`],[60,`<`],[62,`>`],[160,` `]]));function vn({session:e,sha:t,path:n,root:r}){let i=pe(e,t,n,{root:r});return i.isPending?(0,F.jsx)(ct,{children:`…`}):i.error?(0,F.jsx)(ct,{children:i.error instanceof Error?i.error.message:`Failed to load file`}):i.data.binary?(0,F.jsx)(ct,{children:`Binary file`}):(0,F.jsx)(nt,{session:e,refName:`${t}:${r??``}`,path:n,content:i.data.content??``})}function yn({session:e,sha:t,path:n,basePath:r,root:i}){let a=pe(e,`${t}^`,r,{root:i}),o=pe(e,t,n,{root:i});return a.error instanceof N&&a.error.status===404?(0,F.jsx)(vn,{session:e,sha:t,path:n,root:i}):a.isPending||o.isPending?(0,F.jsx)(ct,{children:`…`}):a.error?(0,F.jsx)(ct,{children:a.error instanceof Error?a.error.message:`Failed to load original`}):o.error?(0,F.jsx)(ct,{children:o.error instanceof Error?o.error.message:`Failed to load file`}):a.data.binary||o.data.binary?(0,F.jsx)(ct,{children:`Binary file`}):(0,F.jsx)(gt,{session:e,originalRef:`${t}^`,originalPath:r,originalContent:a.data.content??``,modifiedRef:t,modifiedPath:n,modifiedContent:o.data.content??``,root:i})}function bn({session:e,sha:t,entry:n,isRootCommit:r,root:i}){switch(Ne(n.status,r)){case`added`:return(0,F.jsx)(vn,{session:e,sha:t,path:n.path,root:i});case`deleted`:return(0,F.jsx)(dt,{session:e,against:`${t}^`,path:n.path,root:i});case`modified`:case`renamed`:return(0,F.jsx)(yn,{session:e,sha:t,path:n.path,basePath:n.old_path??n.path,root:i});default:return null}}function xn({session:e,sha:t,path:n,root:r}){let i=de(e,t,r);if(i.isPending)return(0,F.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading commit…`});if(i.error)return(0,F.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,F.jsx)(`div`,{className:`h-full`,children:(0,F.jsx)(bn,{session:e,sha:t,entry:a,isRootCommit:i.data.parents.length===0,root:r})}):(0,F.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[(0,F.jsx)(`span`,{className:`text-fg-secondary`,children:n}),` is not part of`,` `,(0,F.jsx)(`span`,{className:`font-mono`,children:t.slice(0,7)}),`.`]})}function Sn({session:e,path:t,root:n,area:r,focused:i=!0}){let a=ce(e,{root:n,against:r===void 0?`base`:`head`,area:r});if(a.isPending)return(0,F.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading diff…`});if(a.error)return(0,F.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,F.jsx)(`div`,{className:`h-full`,children:(0,F.jsx)(mt,{session:e,against:a.data.against,entry:o,root:n,area:r,focused:i})}):(0,F.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[`No changes to `,(0,F.jsx)(`span`,{className:`mx-1 text-fg-secondary`,children:t}),` against the base.`]})}var Cn=800;function wn({name:e}){let t=qt(),n=te(),r=ut([n,e]),i=Pe(n,e),a=ie(),o=St(`editor.save`),s=(0,P.useRef)(null),c=(0,P.useRef)(null),l=(0,P.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if((0,P.useEffect)(()=>{if(n===null)return;let t=new Set,r=Ut(r=>{let i=Je(n,e,r);t.add(i),i.catch(e=>be.error(e instanceof Error?e.message:`Draft not saved`)).finally(()=>t.delete(i))},Cn),i=Re(n,e,async()=>{r.cancel(),await Promise.all([...t])});return c.current=r,()=>{r.flush(),Promise.allSettled([...t]).then(i),c.current=null}},[n,e]),n===null)return null;let u={session:g,path:e},d=ne()?Ht(n):null;if(i.error)return(0,F.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:i.error instanceof Error?i.error.message:`Failed to load the draft`});if(i.data===void 0)return(0,F.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`});let f=()=>{let t=s.current;t&&(c.current?.flush(),Ye({name:e,content:t.getValue()}))};return(0,F.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,F.jsxs)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:[`Draft — not in any worktree; `,o,` saves it into one`]}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,F.jsx)(Wt,{path:`puddle-untitled://${n}/${e}`,language:t.editorLanguage??Gt(e),defaultValue:d?.buffer(u)?.content??i.data.content,theme:Kt,keepCurrentModel:!1,saveViewState:!1,loading:(0,F.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:n=>{r(n),s.current=n;let i=d?.registerBuffer(u,()=>{let e=n.getModel();return!e||e.isDisposed()?d.buffer(u)??null:{...u,content:e.getValue(),baseMtimeMs:0}});n.onDidDispose(()=>i?.()),d?.bufferChanged(u),qe(e,n.getValue()),rt(n,{onSave:f,fileSettingsKey:t.fileSettingsKey})},onChange:t=>{let r=t??``;qe(e,r),d?.bufferChanged(u),Fe(a,n,e,r),c.current?.(r)},options:{automaticLayout:!0,fontFamily:l,fontSize:t.editorFontSize,...st(t.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1,wordWrap:t.editorWordWrap?`on`:`off`}})})]})}var Tn=c([v(),p(v())]),En=d(v(),h()),Dn=l({output_type:v(),text:Tn.optional(),data:d(v(),h()).optional(),traceback:p(v()).optional(),ename:v().optional(),evalue:v().optional()}),On=l({id:v().optional(),cell_type:f([`code`,`markdown`,`raw`]),metadata:En,source:Tn,outputs:p(Dn).optional(),execution_count:u().int().nullable().optional()}),kn=l({nbformat:m(4),nbformat_minor:u().int().nonnegative(),metadata:En,cells:p(On).max(2e3)});function An(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=kn.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 I(e){return typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(``):``}function jn(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:I(e.source),state:`saved`}}}:{}}:e)}}function Mn(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 Nn(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 Pn(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 Fn(e){return{id:crypto.randomUUID(),cell_type:e,metadata:{},source:[],...e===`code`?{outputs:[],execution_count:null}:{}}}function In(e){return(e.output_type===`error`?e.traceback?.join(`
|
|
3
|
+
`)??`${e.ename??`Error`}: ${e.evalue??``}`:I(e.text??e.data?.[`text/plain`])).replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``)}function Ln(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 Rn(e){return{...e,cells:e.cells.map(e=>e.cell_type===`code`?{...e,outputs:[],execution_count:null}:e)}}function zn(e){return e.cells.map((e,t)=>{let n=I(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 Bn(e,t){let n=zn(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 Vn(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 Hn(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 Un({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=Fn(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:`${I(o.source)}\n${I(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,button,[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,Pn(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 Wn(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=An(JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{},cells:a.puddle_notebook_cells})).cells;if(e.preventDefault(),n.cells.length+o.length>2e3){be.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 Gn({controls:e}){return e.open?(0,F.jsx)(tt,{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 Kn(e,t){return Math.min(t,Math.max(1,Math.floor(e)))}function qn({notebook:e,focused:t,onReveal:n,onChange:r}){let[i,a]=(0,P.useState)(!1),[o,s]=(0,P.useState)(``),c=(0,P.useRef)(null),l=(0,P.useRef)([]),u=(0,P.useRef)(-1),d=(0,P.useRef)(!1),f=Ze({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:I(n.source),output:!1},...i?[{text:(n.outputs??[]).map(In).join(`
|
|
5
|
+
`),output:!0}]:[]];for(let i of e){let e=et(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,P.useEffect)(()=>{f.refresh()},[i,f.refresh]);let p=t=>{let n=Qe(f.query,f.options);if(!n||!r)return;let i=e;e.cells.forEach((e,r)=>{let a=I(e.source),s=c.current;t?i=jn(i,r,a.replace(n,o)):s&&!s.output&&s.id===e.id&&(i=jn(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,P.useEffect)(()=>{d.current=c.current!==null,f.open&&f.refresh(),d.current=!1},[e,f.open,f.refresh]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Gn,{controls:f}),f.open&&(0,F.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,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`Include output`]}),r&&(0,F.jsxs)(F.Fragment,{children:[(0,F.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,F.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query||!!c.current?.output,onClick:()=>p(!1),children:`Replace`}),(0,F.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query,onClick:()=>p(!0),children:`Replace all`})]})]})]})}function Jn(e){return ae({queryKey:[`notebook-kernels`],queryFn:()=>M(`GET`,`/api/notebooks/kernels`),enabled:e,staleTime:3e4})}function Yn(e,t){return ae({queryKey:[`notebook-kernel`,e],queryFn:()=>M(`POST`,`/api/notebooks/status`,{source:e}),enabled:t,refetchInterval:1500,retry:!1})}function Xn(e){return M(`POST`,`/api/notebooks/kernel`,e)}function Zn(e,t){return ae({queryKey:[`notebook-environments`,e],queryFn:()=>M(`POST`,`/api/notebooks/environments`,{source:e}),enabled:t,staleTime:3e4,retry:!1})}var Qn=oe(250),$n=oe(5e3),er=e=>e?.execution?.state===`running`?Qn():$n();function tr(e,t,n){let r=[`notebook-execution`,t],i=!0;return{queryKey:r,reset:()=>{i=!0},queryFn:async({signal:a})=>{let o=e.getQueryState(r),s=!i&&!o?.isInvalidated&&o?.status!==`error`?o?.data:void 0,c=s?.execution?{id:s.execution.id,revision:s.execution.revision}:null;try{let o=await M(`POST`,`/api/notebooks/execution`,{source:t,...n&&s?{known:c}:{}},a);if(a.throwIfAborted(),`unchanged`in o){if(!s)throw Error(`Notebook observation has no matching snapshot`);return i=!1,e.getQueryData(r)??s}return i=!1,o}catch(e){throw i=!0,e}}}}function nr(e,t,r,o){let s=re(),c=o&&!_()&&a(s.data?.protocol),l=(0,P.useRef)({notebook:t,onChange:r});l.current={notebook:t,onChange:r};let u=ie(),[d,f]=(0,P.useState)(!1),p=(0,P.useRef)(!1),[m,h]=(0,P.useState)(null),g=(0,P.useRef)(!0);(0,P.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let v=n(s.data?.protocol),y=(0,P.useMemo)(()=>tr(u,e,v),[u,e.session,e.path,e.root,v]),b=y.queryKey;(0,P.useEffect)(()=>{if(c)return wt.onConnectionChange(e=>{y.reset(),e?u.invalidateQueries({queryKey:y.queryKey}):u.cancelQueries({queryKey:y.queryKey})})},[c,y,u]);let x=ae({queryKey:b,queryFn:y.queryFn,refetchOnReconnect:()=>(y.reset(),`always`),enabled:c,retry:!1,refetchInterval:e=>er(e.state.data)}),S=x.data?.execution;(0,P.useEffect)(()=>{if(!S||!l.current.notebook||!l.current.onChange)return;let e=Vn(l.current.notebook,S);e!==l.current.notebook&&l.current.onChange(e)},[S]);let C=async t=>{let n=l.current.notebook;if(!c||!n||p.current||S?.state===`running`)return;let r=n.cells.flatMap((e,n)=>e.cell_type===`code`&&I(e.source).trim()&&(!t||t.includes(n))?[{id:e.id,source:I(e.source)}]:[]);if(r.length){p.current=!0,f(!0),h(null),l.current.onChange?.(n);try{let t=n.metadata.kernelspec,i=await M(`POST`,`/api/notebooks/execute`,{source:e,cells:r,...t?.name?{kernel:t.name}:{}});await u.cancelQueries({queryKey:b}),g.current&&u.setQueryData(b,i)}catch(e){g.current&&h(e instanceof Error?e.message:`Notebook execution failed`)}finally{p.current=!1,g.current&&(f(!1),u.invalidateQueries({queryKey:b}))}}},w=(0,P.useRef)(C);return w.current=C,(0,P.useEffect)(()=>c?Ue(e,()=>{w.current()}):void 0,[c,e.session,e.path,e.root]),{supported:c,intelligenceSupported:c&&i(s.data?.protocol),run:C,interrupt:async()=>{try{await Xn({source:e,action:`interrupt`})}catch(e){g.current&&h(e instanceof Error?e.message:`Interrupt failed`)}finally{u.invalidateQueries({queryKey:b})}},execution:S,busy:d||S?.state===`running`,error:m??(x.error instanceof Error?x.error.message:S?.error)}}var rr=(0,P.createContext)(null);function ir({source:e,environment:t,current:n,kernels:r,pending:i,onAction:a}){let[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(``),u=(0,P.useId)(),d=Zn(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,F.jsxs)(Mt,{open:o,onOpenChange:s,children:[(0,F.jsx)(jt,{asChild:!0,children:(0,F.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,F.jsx)(pn,{className:`size-3.5 shrink-0`}),(0,F.jsx)(`span`,{className:`truncate`,children:t?.label??n?.display_name??`Select environment`})]})}),(0,F.jsxs)(At,{align:`end`,className:`w-96 max-w-[calc(100vw-2rem)] p-3`,children:[(0,F.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:`Python environments on this host`}),(0,F.jsxs)(`div`,{className:`max-h-64 overflow-y-auto`,"aria-label":`Python environments`,children:[d.isLoading&&(0,F.jsx)(`p`,{role:`status`,className:`py-2 text-xs text-fg-muted`,children:`Looking for environments…`}),d.isError&&(0,F.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,F.jsx)(`p`,{className:`py-2 text-xs text-fg-muted`,children:`No Python environments found. Enter a path below.`}),f.map(n=>(0,F.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,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`p`,{className:`text-xs text-fg`,children:n.label}),(0,F.jsx)(`p`,{className:`break-all text-xs text-fg-muted`,children:n.python}),(n.error||!n.ipykernel||!n.nbconvert)&&(0,F.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,F.jsx)(Ee,{className:`size-3.5 shrink-0 text-accent`})]},n.python)),r.length>0&&(0,F.jsx)(`p`,{className:`mb-1 mt-3 text-xs text-fg-muted`,children:`Registered Jupyter kernels`}),r.map(r=>(0,F.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,F.jsx)(Ee,{className:`size-3.5`})]},r.name))]}),(0,F.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,F.jsx)(`label`,{htmlFor:u,className:`text-xs text-fg-secondary`,children:`Environment folder or Python executable`}),(0,F.jsx)(ke,{id:u,value:c,onChange:e=>l(e.target.value),placeholder:`.venv, ~/miniforge3/envs/analysis, /path/to/python`,disabled:i}),(0,F.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Relative paths start beside this notebook. Switching starts fresh.`}),(0,F.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 ar=`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 or({source:e,notebook:t,onSelect:n}){let i=(0,P.useRef)(n);i.current=n;let a=(0,P.useRef)(!0);(0,P.useEffect)(()=>(a.current=!0,()=>{a.current=!1}),[]);let s=re(),c=r(s.data?.protocol),l=o(s.data?.protocol),u=Jn(c),d=Yn(e,c),f=ie(),[p,m]=(0,P.useState)(null),h=p!==null,[g,_]=(0,P.useState)(null);if(!c)return null;let v=t.metadata.kernelspec,y=d.data?.kernel??(typeof v?.name==`string`?v.name:``),b=u.data?.kernels??[],x=b.find(e=>e.name===y),S=d.data?.environment,C=S&&!S.error?[!S.ipykernel&&`ipykernel`,!S.nbconvert&&`nbconvert`].filter(Boolean).join(` and `):``,w=d.data&&d.data.state!==`stopped`&&d.data.state!==`dead`,T=d.data?.state===`busy`||d.data?.state===`starting`,E=async t=>{m(t.action),_(null);try{let n=await Xn(t);if(f.setQueryData([`notebook-kernel`,e],n),(t.action===`select-python`||t.action===`install-python`)&&(f.invalidateQueries({queryKey:[`notebook-environments`]}),a.current&&i.current({name:`python3`,display_name:`Python 3`,language:`python`})),t.action===`select`){let e=b.find(e=>e.name===t.kernel);e&&a.current&&i.current(e)}}catch(e){_(e instanceof Error?e.message:`Kernel operation failed`)}finally{m(null)}};return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[T&&(0,F.jsxs)(`button`,{type:`button`,className:ar,disabled:h,onClick:()=>void E({source:e,action:`interrupt`}),children:[(0,F.jsx)(ve,{className:`size-3.5`}),`Interrupt`]}),(0,F.jsx)(`span`,{className:`text-xs text-fg-muted`,role:`status`,children:h?p===`install-python`?`Installing…`:`Updating…`:d.data?.state===`dead`?`Kernel exited`:T?`Busy`:w?`Idle`:``}),l?(0,F.jsx)(ir,{source:e,environment:S,current:x,kernels:b,pending:h,onAction:E}):(0,F.jsxs)(De,{value:x?.name??``,disabled:h||!u.data?.available||b.length===0,onValueChange:t=>void E({source:e,action:`select`,kernel:t}),children:[(0,F.jsxs)(Ce,{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,F.jsx)(pn,{className:`size-3.5 shrink-0`}),(0,F.jsx)(Se,{placeholder:y?`${y} (not installed)`:`Select Kernel`})]}),(0,F.jsx)(we,{children:b.map(e=>(0,F.jsx)(Te,{value:e.name,detail:e.language,children:(0,F.jsx)(`span`,{children:e.display_name})},e.name))})]}),(0,F.jsxs)(Ie,{children:[(0,F.jsx)(Le,{asChild:!0,children:(0,F.jsx)(`button`,{type:`button`,className:ar,disabled:h,"aria-label":`Kernel actions`,children:(0,F.jsx)(Ve,{className:`size-3.5`})})}),(0,F.jsxs)(He,{align:`end`,children:[(0,F.jsxs)(Ge,{disabled:!x&&!S,onSelect:()=>void E({source:e,action:`restart`}),children:[(0,F.jsx)(bt,{}),`Restart kernel`]}),(0,F.jsxs)(Ge,{disabled:!w,onSelect:()=>void E({source:e,action:`shutdown`}),children:[(0,F.jsx)(xe,{}),`Shut down kernel`]})]})]})]}),C&&(0,F.jsxs)(`div`,{className:`flex w-full flex-wrap items-center gap-2 px-2 text-xs text-fg-muted`,children:[(0,F.jsxs)(`span`,{className:`break-all`,children:[C,` missing from `,S?.python,`.`]}),(0,F.jsxs)(`button`,{type:`button`,className:ar,disabled:h,onClick:()=>{S&&E({source:e,action:`install-python`,python:S.python})},children:[`Install `,C]})]}),(g||d.data?.error||!l&&(u.data?.error||u.isError)||d.isError)&&(0,F.jsx)(`p`,{role:`alert`,className:`w-full px-2 text-xs text-danger`,children:g??d.data?.error??u.data?.error??`Couldn’t load notebook kernels`}),!l&&u.data&&!u.data.available&&!u.data.error&&(0,F.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 L=`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 sr({notebook:e,source:t,onChange:n,onAdd:i,onRevealCell:a,onRun:o,onRunCopy:s,onRunSection:c,running:l=!1}){let[u,d]=(0,P.useState)(!1),f=re(),p=Yn(t,!!o&&r(f.data?.protocol)),m=l||p.data?.state===`busy`||p.data?.state===`starting`,h=p.data?.environment,g=h&&(!h.ipykernel||!h.nbconvert),_=zn(e),v=e.cells.some(e=>e.cell_type===`code`&&((e.outputs?.length??0)>0||e.execution_count!=null));return(0,F.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1 bg-ground px-3 py-2`,role:`toolbar`,"aria-label":`Notebook`,children:[n&&(0,F.jsxs)(Ct,{label:`Add notebook cells`,children:[(0,F.jsxs)(`button`,{type:`button`,className:L,disabled:e.cells.length>=2e3,onClick:()=>i(`code`),"aria-label":`Add code cell`,children:[(0,F.jsx)(yt,{className:`size-3.5`}),`Code`]}),(0,F.jsxs)(`button`,{type:`button`,className:L,disabled:e.cells.length>=2e3,onClick:()=>i(`markdown`),"aria-label":`Add Markdown cell`,children:[(0,F.jsx)(yt,{className:`size-3.5`}),`Markdown`]})]}),(0,F.jsxs)(Ct,{label:`Notebook actions`,className:`flex-wrap !rounded-[var(--ui-radius)]`,children:[o&&(0,F.jsxs)(`button`,{type:`button`,className:L,disabled:m||g,onClick:o,children:[(0,F.jsx)(le,{className:`size-3.5`}),m?`Running…`:`Run All`]}),n&&(0,F.jsxs)(`button`,{type:`button`,className:L,disabled:!v,onClick:()=>n(Rn(e)),children:[(0,F.jsx)(xt,{className:`size-3.5`}),`Clear All Outputs`]}),(0,F.jsxs)(Mt,{open:u,onOpenChange:d,children:[(0,F.jsx)(jt,{asChild:!0,children:(0,F.jsxs)(`button`,{type:`button`,className:L,disabled:_.length===0,children:[(0,F.jsx)(mn,{className:`size-3.5`}),`Outline`]})}),(0,F.jsx)(At,{align:`start`,className:`max-h-72 w-72 overflow-y-auto p-1`,children:(0,F.jsx)(`nav`,{"aria-label":`Notebook outline`,className:`flex flex-col`,children:_.map(e=>(0,F.jsxs)(`div`,{className:`group/outline flex items-center`,style:{paddingLeft:`calc(var(--spacing) * ${Math.max(0,e.level-1)*3})`},children:[(0,F.jsxs)(`button`,{type:`button`,className:`${L} min-w-0 flex-1 text-left`,onClick:()=>{a(e.index),d(!1)},children:[(0,F.jsx)(`span`,{className:`w-5 shrink-0 text-fg-muted`,children:e.index+1}),(0,F.jsx)(`span`,{className:`truncate`,children:e.label})]}),!!e.level&&c&&(0,F.jsx)(`button`,{type:`button`,disabled:m,title:`Run Section`,"aria-label":`Run section ${e.label}`,className:`${L} opacity-0 group-hover/outline:opacity-100 focus:opacity-100 pointer-coarse:opacity-100`,onClick:()=>{c(e.index),d(!1)},children:(0,F.jsx)(le,{className:`size-3.5`})})]},e.index))})})]}),n&&(0,F.jsxs)(Ie,{children:[(0,F.jsx)(Le,{asChild:!0,children:(0,F.jsx)(`button`,{type:`button`,className:L,"aria-label":`More notebook actions`,children:(0,F.jsx)(Ve,{className:`size-3.5`})})}),(0,F.jsxs)(He,{align:`start`,children:[s&&(0,F.jsx)(Ge,{disabled:m,onSelect:s,children:`Run to Executed Copy`}),(0,F.jsxs)(Ge,{disabled:e.cells.length>=2e3,onSelect:()=>i(`raw`),children:[(0,F.jsx)(yt,{}),`Add raw cell`]})]})]})]}),n&&o&&(0,F.jsx)(or,{source:t,notebook:e,onSelect:t=>n({...e,metadata:{...e.metadata,kernelspec:t}})},JSON.stringify(t))]})}function cr({code:e,onRun:t,busy:n,index:r,count:i,canMerge:a,onOperation:o}){let s=(e,t,n,r=!1)=>(0,F.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,F.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,F.jsxs)(F.Fragment,{children:[s(`Run Cell`,(0,F.jsx)(le,{className:`size-3.5`}),()=>t(`cell`),n),s(`Run Above`,(0,F.jsx)(fn,{className:`size-3.5`}),()=>t(`above`),n||r===0),s(`Run Cell and Below`,(0,F.jsx)(dn,{className:`size-3.5`}),()=>t(`below`),n)]}),s(`Insert cell below`,(0,F.jsx)(yt,{className:`size-3.5`}),()=>o(`insert`),i>=2e3),s(`Duplicate cell`,(0,F.jsx)(vt,{className:`size-3.5`}),()=>o(`duplicate`),i>=2e3),s(`Merge with next cell`,(0,F.jsx)(ot,{className:`size-3.5`}),()=>o(`merge`),!a),s(`Move cell up`,(0,F.jsx)(Me,{className:`size-3.5`}),()=>o(`up`),r===0),s(`Move cell down`,(0,F.jsx)(Be,{className:`size-3.5`}),()=>o(`down`),r===i-1),s(`Delete cell`,(0,F.jsx)(xt,{className:`size-3.5`}),()=>o(`delete`))]})}function lr(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 M(`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`?[]:[O.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 D(l.lineNumber,l.column,u.lineNumber,u.column);return{suggestions:s.matches.map(e=>({label:e,insertText:e,kind:O.CompletionItemKind.Text,range:d}))}}}),O.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 ur({value:e,language:t,label:n,focus:r,onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c,match:l}){let u=qt(),d=Math.round(u.editorFontSize*1.5),f=(0,P.useContext)(rr),[p,m]=(0,P.useState)(null);(0,P.useEffect)(()=>{if(!p||!f?.intelligence)return;let e=lr(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,P.useRef)(null),g=(0,P.useRef)(null),_=(0,P.useRef)(null),v=(0,P.useRef)(!1),y=(0,P.useRef)(null),b=(0,P.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,P.useRef)(r);x.current=r;let S=(0,P.useRef)(l);S.current=l;let C=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 D(r.lineNumber,r.column,i.lineNumber,i.column)),e.revealPositionInCenter(r)};(0,P.useEffect)(()=>{g.current&&C(g.current)},[l]);let[w,T]=(0,P.useState)(!1),[E,O]=(0,P.useState)(!1),[M,ee]=(0,P.useState)(Math.max(64,e.split(`
|
|
6
|
+
`).length*d+24));return(0,P.useEffect)(()=>{let e=new IntersectionObserver(([e])=>T(!!e?.isIntersecting),{rootMargin:`600px`});return h.current&&e.observe(h.current),()=>e.disconnect()},[]),(0,P.useEffect)(()=>()=>{_.current?.dispose()},[]),(0,P.useEffect)(()=>{let n=_.current;n&&n.getValue()!==e&&(v.current=!0,n.pushEditOperations([],[{range:n.getFullModelRange(),text:e}],()=>null),v.current=!1),n&&A.setModelLanguage(n,t)},[e,t]),(0,P.useEffect)(()=>{r&&g.current?.focus()},[r]),(0,F.jsxs)(`div`,{ref:h,style:{height:M},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,F.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}),(w||r||E)&&(0,F.jsx)(Wt,{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()),rt(e,{onSave:()=>b.current.onSave(),fileSettingsKey:u.fileSettingsKey}),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}),ee(n),t=!1},r=e.onDidContentSizeChange(n),i=new ResizeObserver(n);i.observe(h.current);let a=e.onDidFocusEditorWidget(()=>O(!0)),o=e.onDidBlurEditorWidget(()=>O(!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(k.CtrlCmd|j.Enter,()=>b.current.onExecute(`stay`)),e.addCommand(k.Shift|j.Enter,()=>b.current.onExecute(`next`)),e.addCommand(k.Alt|j.Enter,()=>b.current.onExecute(`insert`)),e.addCommand(j.Escape,()=>b.current.onEscape(),`!suggestWidgetVisible && !findWidgetVisible`),e.addCommand(k.CtrlCmd|k.Shift|j.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(),C(e),x.current&&e.focus()},beforeMount:()=>{_.current&&A.setModelLanguage(_.current,t)},options:{ariaLabel:n,automaticLayout:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim(),fontSize:u.editorFontSize,lineHeight:d,...st(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 dr({language:e,onChange:t}){let[n,r]=(0,P.useState)(!1),i=[`markdown`,`raw`,...O.getLanguages().map(e=>e.id).filter(e=>e!==`markdown`).sort()];return(0,F.jsxs)(Mt,{open:n,onOpenChange:r,children:[(0,F.jsx)(jt,{asChild:!0,children:(0,F.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,F.jsx)(Xe,{className:`size-3`})]})}),(0,F.jsxs)(At,{align:`start`,className:`w-56 p-0`,children:[(0,F.jsxs)(kt,{children:[(0,F.jsx)(Tt,{placeholder:`Find a language…`}),(0,F.jsxs)(Ot,{children:[(0,F.jsx)(Dt,{children:`No matching languages`}),i.map(e=>(0,F.jsx)(Et,{onSelect:()=>{t(e),r(!1)},children:e},e))]})]}),(0,F.jsx)(`p`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Code languages set highlighting. Execution uses the notebook kernel.`})]})]})}async function fr(e,t,n){let r=`path=${encodeURIComponent(t)}${se(n)}`,i=_();return i?mr(i,async()=>{if(_()!==i)throw Error(`Preview host changed`);let t=s.parse(await M(`GET`,`/api/worktrees/${e}/preview-asset?${r}`));return new Blob([Uint8Array.from(atob(t.data),e=>e.charCodeAt(0))],{type:t.mime})}):(await ee(`GET`,`/api/worktrees/${e}/media?${r}`)).blob()}var pr=new WeakMap;async function mr(e,t){let n=pr.get(e);if(n||(n={active:0,waiting:[]},pr.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 hr(e,t,n,r,i){(0,P.useEffect)(()=>{let t=e.current;if(!t)return;let a=!1,o=[],s=async e=>{try{let t=await fr(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=Bt(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=Vt(e.getAttribute(`srcset`)??``),n=t.map(({ref:e})=>Bt(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`,Lt(n))}))}return()=>{a=!0;for(let e of o)URL.revokeObjectURL(e)}},[t,e,n,r,i])}var gr=(0,P.lazy)(()=>T(()=>import(`./NotebookWidget-BDdx0BOy.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])));function _r(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=I(r[e]).replace(/\s/g,``);if(t&&/^[A-Za-z0-9+/]*={0,2}$/.test(t))return`data:${e};base64,${t}`}}catch{}return e})}function vr({text:e,markdown:t=!1,attachments:n}){let r=(0,P.useContext)(rr),i=(0,P.useRef)(null),a=(0,P.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o=(0,P.useSyncExternalStore)(C,S,S),s=(0,P.useMemo)(()=>E.sanitize(t?on(_r(e,n),a):e,{FORBID_TAGS:[`style`,`iframe`,`form`,`input`,`button`],...t?{}:{FORBID_ATTR:[`style`]}}),[e,t,n,a]),c=(0,P.useMemo)(()=>({__html:s}),[s,o]);return hr(i,s,r?.session??``,r?.path??``,r?.root),(0,P.useEffect)(()=>{let e=new AbortController;return i.current&&t&&un(i.current,o,e.signal),()=>e.abort()},[s,o,t]),(0,F.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?Bt(r.path,n):null;a&&(e.preventDefault(),(e.metaKey||e.ctrlKey)&&r?.onOpenFile?.(a))}})}var yr=`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-surface hover:text-fg`;function br({output:e}){let t=null;for(let n of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let r=I(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=I(e.data?.[`image/svg+xml`]),r=n?E.sanitize(n,{USE_PROFILES:{svg:!0,svgFilters:!0},FORBID_TAGS:[`style`,`foreignObject`,`image`,`use`],FORBID_ATTR:[`style`,`href`,`xlink:href`]}):``,i=I(e.data?.[`text/html`]),a=I(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=In(e)||(o===void 0?``:JSON.stringify(o,null,2))||`This output format cannot be displayed.`;return(0,F.jsxs)(`div`,{className:`group/output relative`,children:[(0,F.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,F.jsx)(`button`,{type:`button`,title:`Copy output`,"aria-label":`Copy output`,className:yr,onClick:()=>{navigator.clipboard.writeText(l).catch(()=>be.error(`Could not copy output`))},children:(0,F.jsx)(vt,{className:`size-3.5`})}),(t||r)&&(0,F.jsx)(`button`,{type:`button`,title:`Save image`,"aria-label":`Save image`,className:yr,onClick:()=>ue(t?.blob??new Blob([r],{type:`image/svg+xml`}),`notebook-output.${t?.extension??`svg`}`),children:(0,F.jsx)(he,{className:`size-3.5`})})]}),c?(0,F.jsx)(P.Suspense,{fallback:(0,F.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Loading widget…`}),children:(0,F.jsx)(gr,{modelId:c,fallback:In(e)})}):t?(0,F.jsx)(`img`,{src:t.src,alt:`Notebook output`,className:`max-w-full`}):r?(0,F.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):i?(0,F.jsx)(vr,{text:i}):a?(0,F.jsx)(vr,{text:a,markdown:!0}):(0,F.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 xr({source:e,execution:t,onInterrupt:n}){let r=(0,P.useRef)(null),i=(0,P.useRef)(!1),[a,o]=(0,P.useState)(``),[s,c]=(0,P.useState)(!1),[l,u]=(0,P.useState)(null),d=t.input;return(0,P.useEffect)(()=>{r.current?.focus({preventScroll:!0}),r.current?.scrollIntoView({block:`nearest`})},[]),d?(0,F.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),M(`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,F.jsxs)(`label`,{className:`flex min-w-0 flex-wrap items-baseline`,children:[(0,F.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:d.prompt}),(0,F.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,F.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-danger`,children:l})]}):null}var Sr=`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`;function Cr({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,P.useRef)(null),[w,T]=(0,P.useState)(!1),E=y?v?.input:void 0;(0,P.useEffect)(()=>{(b?.output||E)&&T(!1)},[b,E]);let D=w&&!E,O=e.cell_type===`code`,k=I(e.source),A=_?.state===`running`||_?.state===`queued`,j=Nn(e,t),M=(e,t,n,r=!1)=>(0,F.jsx)(`button`,{type:`button`,className:Sr,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,F.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)&&O&&!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,F.jsx)(`div`,{className:`absolute -left-10 top-9 w-9 text-center font-mono text-xs text-fg-muted`,children:(0,F.jsxs)(`button`,{type:`button`,className:`${Sr} group/run relative w-full`,disabled:!o||O&&(!f||!A&&!k.trim()),title:O?A?`Interrupt execution`:`Run Cell (⌘/Ctrl+Enter)`:i?`Show rendered cell`:`Edit cell source`,"aria-label":O?A?`Interrupt execution`:`Run Cell`:i?`Show rendered cell`:`Edit cell source`,onClick:()=>{O?A?p?.():f?.(`cell`):c(!i)},children:[(0,F.jsx)(`span`,{className:O&&f?`group-hover/run:invisible group-focus-visible/run:invisible`:``,children:O?`[${A?`*`:e.execution_count??` `}]`:i?`[›]`:`[ ]`}),O&&f&&(A?(0,F.jsx)(ve,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}):(0,F.jsx)(le,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}))]})}),(0,F.jsxs)(`div`,{className:`mb-2 flex min-h-7 items-center gap-2 text-xs text-fg-muted`,children:[x&&M(S?`Expand section`:`Fold section`,S?(0,F.jsx)(Ae,{className:`size-3`}):(0,F.jsx)(Xe,{className:`size-3`}),x),o?(0,F.jsx)(dr,{language:e.cell_type===`raw`?`raw`:j,onChange:u}):(0,F.jsx)(`span`,{className:`font-mono`,children:e.cell_type===`raw`?`raw`:j}),_&&(0,F.jsxs)(`span`,{role:`status`,children:[_.state,_.elapsed_ms===void 0?``:` · ${(_.elapsed_ms/1e3).toFixed(1)}s`]}),_&&_.source!==k&&(0,F.jsx)(`span`,{title:`The source changed after this execution`,children:`Source changed`}),o&&(0,F.jsx)(cr,{code:O,onRun:f,busy:A,index:n,count:t.cells.length,canMerge:e.cell_type===t.cells[n+1]?.cell_type,onOperation:m})]}),(0,F.jsx)(`div`,{className:O||i||e.cell_type===`raw`?`rounded-[var(--ui-radius)] p-3 ${a?`bg-elevated`:`bg-surface`}`:void 0,children:o&&(O||i)?(0,F.jsx)(ur,{value:k,match:b&&!b.output?b:void 0,language:j,label:`Cell ${n+1} source`,focus:r&&i&&!b,onChange:e=>{e!==k&&l(e)},onExecute:d,onEscape:()=>{c(!1),C.current?.focus()},onSave:g,onSplit:h}):e.cell_type===`markdown`?(0,F.jsx)(`div`,{onDoubleClick:()=>{o&&c(!0)},className:o?`cursor-text`:``,children:(0,F.jsx)(vr,{text:k,markdown:!0,attachments:e.attachments})}):(0,F.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm`,onDoubleClick:()=>{o&&c(!0)},children:k})}),(!!e.outputs?.length||E)&&(0,F.jsxs)(`div`,{className:`mt-2`,role:`group`,"aria-label":`Cell ${n+1} output`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[M(D?`Expand output`:`Collapse output`,D?(0,F.jsx)(Ae,{className:`size-3`}):(0,F.jsx)(Xe,{className:`size-3`}),()=>T(!w),!!E),(0,F.jsx)(`span`,{children:`Output`}),o&&M(`Clear cell output`,(0,F.jsx)(xt,{className:`size-3`}),()=>m(`clear`))]}),!D&&(0,F.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,F.jsx)(`div`,{className:`mt-2 first:mt-0`,children:(0,F.jsx)(br,{output:e})},t)),E&&v&&y&&(0,F.jsx)(xr,{source:y,execution:v,onInterrupt:p},`${v.id}:${E.id}`)]})]})]})}var wr=new Xt(500,`notebook-scroll`);function Tr(e,t,n){let r=wr.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);wr.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 Er({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,P.useMemo)(()=>{try{return{notebook:Mn(An(e)),error:null}}catch(e){return{notebook:null,error:e instanceof Error?e.message:`Invalid notebook`}}},[e]),[f,p]=(0,P.useState)([]),[m,h]=(0,P.useState)(null),g=(0,P.useRef)(!0),[_,v]=(0,P.useState)(null),[x,S]=(0,P.useState)(null),C=(0,P.useRef)(null),[w,T]=(0,P.useState)([]),E=(0,P.useRef)(null),D=(0,P.useRef)(null),O=(0,P.useRef)(null),k=Yt(`notebook`,[t,r,n]),A=d.notebook!==null;(0,P.useLayoutEffect)(()=>{if(!(!E.current||!D.current||!A))return Tr(E.current,D.current,k)},[k,A]),(0,P.useLayoutEffect)(()=>{if(!O.current)return;let e=D.current?.querySelector(`[data-cell-id="${CSS.escape(O.current)}"]`);e&&(e.scrollIntoView({block:`nearest`}),g.current&&e.focus({preventScroll:!0}),g.current=!0,O.current=null)});let j=e=>i?.(`${JSON.stringify(e,null,1)}\n`),M=d.notebook,ee=(0,P.useMemo)(()=>({session:t,path:n,...r===void 0?{}:{root:r}}),[t,n,r]),N=nr(ee,M,i?j:void 0,!!a),te=y(ee,M,i?j:void 0,!!a),ne=N.execution?.input?N.execution.cells.find(e=>e.state===`running`)?.id:void 0;if((0,P.useLayoutEffect)(()=>{if(!M||!ne||!f.length)return;let e=M.cells.findIndex(e=>e.id===ne),t=f.filter(t=>{let n=M.cells.findIndex(e=>e.id===t);return n<0||!Bn(M,n).includes(e)});t.length!==f.length&&p(t)},[M,ne,f]),!M)return(0,F.jsx)(`p`,{className:`p-6 text-sm text-danger`,role:`alert`,children:d.error});let re=(e,t=!1)=>{let n=C.current??_??e,r=M.cells.findIndex(e=>e.id===n),i=M.cells.findIndex(t=>t.id===e);T(t?M.cells.slice(Math.min(r,i),Math.max(r,i)+1).map(e=>e.id):[e]),t||(C.current=e),v(e)},ie=(e,t=!1,n=!1)=>{re(e,n),S(t?e:null),O.current=e},ae=zn(M),oe=new Set(M.cells.flatMap((e,t)=>f.includes(e.id)?Bn(M,t).slice(1):[])),{add:se,replace:ce,execute:le,operation:ue,keyDown:de}=Un({notebook:M,active:_,selected:w,update:j,choose:ie,setEditing:S,run:N.run,onUndo:s,onRedo:c});return(0,F.jsx)(b.Provider,{value:te,children:(0,F.jsx)(rr.Provider,{value:{...ee,onOpenFile:l,intelligence:N.intelligenceSupported},children:(0,F.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-ground`,onKeyDown:i?de:void 0,onCopy:e=>{i&&Wn(e,`copy`,M,w,j)},onCut:e=>{i&&Wn(e,`cut`,M,w,j)},onPaste:e=>{i&&Wn(e,`paste`,M,w,j)},children:[(0,F.jsx)(qn,{notebook:M,focused:u,onChange:i?j:void 0,onReveal:e=>{h(e),e&&(p([]),v(e.id),e.output||S(e.id),O.current=e.id,g.current=!1)}}),(0,F.jsx)(sr,{notebook:M,source:{session:t,path:n,...r===void 0?{}:{root:r}},onChange:i?j:void 0,onAdd:se,onRun:N.supported?()=>{N.run()}:a,onRunCopy:N.supported?a:void 0,running:o||N.busy,onRevealCell:e=>{p([]),ie(M.cells[e].id)},onRunSection:N.supported?e=>{N.run(Bn(M,e))}:void 0}),(0,F.jsx)(`div`,{ref:E,className:`min-h-0 flex-1 overflow-auto bg-ground text-fg`,children:(0,F.jsxs)(`div`,{ref:D,className:`mx-auto flex max-w-4xl flex-col gap-7 py-6 pr-6 pl-14`,children:[(0,F.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[M.cells.length,` cells`]}),te.saveWarning&&(0,F.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:te.saveWarning}),N.error&&(0,F.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:N.error}),M.cells.map((e,a)=>oe.has(a)?null:(0,F.jsx)(Cr,{cell:e,match:m&&m.id===e.id?m:void 0,sectionCollapsed:f.includes(e.id),onToggleSection:ae[a]?.level?()=>p(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]):void 0,notebook:M,index:a,active:_===e.id,editing:x===e.id,selected:w.length>1&&w.includes(e.id),editable:!!i,onSelect:t=>re(e.id,t),onEdit:t=>{v(e.id),S(t?e.id:null)},onSource:e=>j(jn(M,a,e)),onLanguage:t=>ce(a,Pn(e,t)),onInterrupt:()=>{N.interrupt()},execution:N.execution?.cells.find(t=>t.id===e.id)??Hn(e),inputExecution:ne===e.id?N.execution??void 0:void 0,inputSource:ee,onRun:N.supported?e=>{N.run(M.cells.flatMap((t,n)=>(e===`cell`?n===a:e===`above`?n<a:n>=a)?[n]:[]))}:void 0,onExecute:e=>le(a,e),onOperation:e=>ue(a,e),onSave:()=>{ge(ye(t,n,r))},onSplit:t=>{if(M.cells.length>=2e3)return;let n=I(e.source),r={...Fn(e.cell_type),source:n.slice(t)},i=[...M.cells];i.splice(a,1,{...e,source:n.slice(0,t)},r),j({...M,cells:i}),ie(r.id,!0)}},e.id)),i&&(0,F.jsx)(`div`,{className:`flex gap-3`,children:[`code`,`markdown`,`raw`].map(e=>(0,F.jsxs)(`button`,{disabled:M.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:()=>se(e,M.cells.length),children:[(0,F.jsx)(yt,{className:`size-3.5`}),e===`code`?`Code`:e===`markdown`?`Markdown`:`Raw`,` cell`]},e))})]})})]})})})}var Dr=0;function Or(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 kr(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 Ar=class{root;matchName=`puddle-find-${++Dr}-match`;activeName=`puddle-find-${Dr}-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=Or(this.root),i=et(n.text,e,t);if(this.ranges=i.matches.map(e=>kr(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`}))}};E.addHook(`afterSanitizeAttributes`,e=>{e.tagName===`A`&&/^https?:/i.test(e.getAttribute(`href`)??``)&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});function jr({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=Yt(`markdown`,[e,r,t]),f=(0,P.useId)().replace(/[^A-Za-z0-9_-]/g,``),p=(0,P.useSyncExternalStore)(e=>C(e),S,S),m=(0,P.useMemo)(()=>E.sanitize(on(n,f)),[n,f]),h=(0,P.useMemo)(()=>Qt(n),[n]),g=(0,P.useMemo)(()=>({__html:m}),[m,p]),_=(0,P.useRef)(null),v=(0,P.useRef)(null),y=(0,P.useRef)(null);(0,P.useEffect)(()=>{let e=v.current;if(!e)return;let t=new Ar(e);return y.current=t,()=>{t.dispose(),y.current=null}},[]);let b=Ze({shortcutEnabled:s,onFind:(e,t,n)=>y.current?.find(e,t,n)??$e,onClear:()=>y.current?.clear(),onCloseFocus:()=>_.current?.focus({preventScroll:!0})});(0,P.useEffect)(()=>b.refresh(),[m,p,b.refresh]),(0,P.useEffect)(()=>{let e=v.current;if(!e)return;let t=new AbortController;return un(e,p,t.signal).then(()=>{t.signal.aborted||b.refresh()}),()=>t.abort()},[m,p,b.refresh]),(0,P.useLayoutEffect)(()=>{let n=_.current,s=v.current;if(!(!n||!s))return lt(n,{viewKey:d,channel:o,target:{session:e,path:t,root:r},driver:i,receiver:a,resizeElements:[n,s],sourceAnchors:()=>Zt(n,s,h)})},[m,h,e,t,r,o,i,a,d]),hr(v,m,e,t,r);let w=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=Mr(r);(e?v.current?.querySelector(`#${CSS.escape(e)}`):null)?.scrollIntoView({block:`nearest`});return}if(!u&&!e.metaKey&&!e.ctrlKey)return;let i=Bt(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=tn(Zt(r,i,h),a);o!==null&&(e.preventDefault(),c({line:Kn(o,h)}))},T=x().editorFontSize;return(0,F.jsxs)(`div`,{className:`relative size-full bg-ground`,children:[(0,F.jsx)(`div`,{ref:_,tabIndex:-1,className:`h-full overflow-auto overscroll-contain outline-none`,children:(0,F.jsx)(`div`,{ref:v,onClick:w,style:{fontSize:T},className:`md-preview mx-auto max-w-3xl px-6 py-5 text-fg-secondary`,dangerouslySetInnerHTML:g})}),(0,F.jsx)(Gn,{controls:b})]})}function Mr(e){try{return decodeURIComponent(e.slice(1))}catch{return null}}var Nr=`puddle-preview-scroll-report`,Pr=`puddle-preview-scroll-apply`,Fr=`puddle-preview-source-reveal`;function Ir(){return crypto.randomUUID()}function Lr(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 Rr(e,t,n){let r=Lr(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:Nr,channel:n,ratio:_t(r.ratio),sourceLine:r.sourceLine===null?null:Math.max(1,r.sourceLine),layout:r.layout,scrolled:r.scrolled}}function zr(e,t,n){let r=Lr(e,t,n);return!r||r.kind!==`puddle-preview-source-reveal`||typeof r.line!=`number`||!Number.isFinite(r.line)?null:{kind:Fr,channel:n,line:Math.max(1,r.line)}}function Br(e,t,n){e?.postMessage({kind:Pr,channel:t,ratio:_t(n.ratio),sourceLine:n.sourceLine!==null&&Number.isFinite(n.sourceLine)?Math.max(1,n.sourceLine):null},`*`)}function Vr(e){return`(() => {
|
|
10
|
+
const channel = ${JSON.stringify(e)};
|
|
11
|
+
const reportKind = ${JSON.stringify(Nr)};
|
|
12
|
+
const applyKind = ${JSON.stringify(Pr)};
|
|
13
|
+
const revealKind = ${JSON.stringify(Fr)};
|
|
14
|
+
const lineAttribute = ${JSON.stringify($t)};
|
|
15
|
+
const endLineAttribute = ${JSON.stringify(nn)};
|
|
16
|
+
const countAttribute = ${JSON.stringify(en)};
|
|
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 Hr(e,t){let n=e.createElement(`script`);n.textContent=Vr(t),(e.body??e.documentElement).appendChild(n)}var Ur=`puddle-preview-find-open`,Wr=`puddle-preview-find-apply`,Gr=`puddle-preview-find-result`,Kr=`puddle-preview-find-clear`;function qr(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:Ur,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:Gr,channel:n,index:r.index,count:r.count,...r.invalid===void 0?{}:{invalid:r.invalid},...r.limited===void 0?{}:{limited:r.limited}}:null}function Jr(e,t,n,r,i){e?.postMessage({kind:Wr,channel:t,query:n,options:r,direction:i},`*`)}function Yr(e,t){e?.postMessage({kind:Kr,channel:t},`*`)}function Xr(e){return`(() => {
|
|
128
|
+
const channel = ${JSON.stringify(e)};
|
|
129
|
+
const openKind = ${JSON.stringify(Ur)};
|
|
130
|
+
const applyKind = ${JSON.stringify(Wr)};
|
|
131
|
+
const resultKind = ${JSON.stringify(Gr)};
|
|
132
|
+
const clearKind = ${JSON.stringify(Kr)};
|
|
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 Zr(e,t){let n=e.createElement(`script`);n.textContent=Xr(t),(e.body??e.documentElement).appendChild(n)}var Qr=`script, style, pre, code, kbd, samp, textarea, math, svg, .katex`,$r=/\bmathjax\b|\bkatex\b/i;function ei(e){if(ni(e))return!1;let t=e.body??e.documentElement;return t?ti(t):!1}function ti(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(Qr)||r.push(e))}let i={},a=!1;for(let e of r)ri(t,e,i)&&(a=!0);return a}function ni(e){if(e.querySelector(`.katex, math`))return!0;for(let t of e.querySelectorAll(`script`))if($r.test(t.getAttribute(`src`)??``)||$r.test(t.textContent??``))return!0;return!1}function ri(e,t,n){let r=t.data;if(!ln(r))return!1;let i=e.createDocumentFragment(),a=e.createElement(`span`),o=0;for(let t=ln(r,0);t;t=ln(r,o)){for(t.start>o&&i.appendChild(e.createTextNode(r.slice(o,t.start))),a.innerHTML=sn(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 ii=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]),R;(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`})(R||={});var z={DASH_DASH:`--`,CDATA_START:`[CDATA[`,DOCTYPE:`doctype`,SCRIPT:`script`,PUBLIC:`public`,SYSTEM:`system`};function ai(e){return e>=55296&&e<=57343}function oi(e){return e>=56320&&e<=57343}function si(e,t){return(e-55296)*1024+9216+t}function ci(e){return e!==32&&e!==10&&e!==13&&e!==9&&e!==12&&e>=1&&e<=31||e>=127&&e<=159}function li(e){return e>=64976&&e<=65007||ii.has(e)}var B;(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`})(B||={});var ui=65536,di=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=ui,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(oi(t))return this.pos++,this._addGap(),si(e,t)}else if(!this.lastChunkWritten)return this.endOfChunkHit=!0,R.EOF;return this._err(B.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,R.EOF;let n=this.html.charCodeAt(t);return n===R.CARRIAGE_RETURN?R.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,R.EOF;let e=this.html.charCodeAt(this.pos);return e===R.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,R.LINE_FEED):e===R.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,ai(e)&&(e=this._processSurrogate(e)),this.handler.onParseError===null||e>31&&e<127||e===R.LINE_FEED||e===R.CARRIAGE_RETURN||e>159&&e<64976||this._checkForProblematicCharacters(e),e)}_checkForProblematicCharacters(e){ci(e)?this._err(B.controlCharacterInInputStream):li(e)&&this._err(B.noncharacterInInputStream)}retreat(e){for(this.pos-=e;this.pos<this.lastGapPos;)this.lastGapPos=this.gapStack.pop(),this.pos--;this.isEol=!1}},V;(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`})(V||={});function fi(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 H;(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/`})(H||={});var pi;(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`})(pi||={});var U;(function(e){e.NO_QUIRKS=`no-quirks`,e.QUIRKS=`quirks`,e.LIMITED_QUIRKS=`limited-quirks`})(U||={});var W;(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`})(W||={});var G;(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`})(G||={});var mi=new Map([[W.A,G.A],[W.ADDRESS,G.ADDRESS],[W.ANNOTATION_XML,G.ANNOTATION_XML],[W.APPLET,G.APPLET],[W.AREA,G.AREA],[W.ARTICLE,G.ARTICLE],[W.ASIDE,G.ASIDE],[W.B,G.B],[W.BASE,G.BASE],[W.BASEFONT,G.BASEFONT],[W.BGSOUND,G.BGSOUND],[W.BIG,G.BIG],[W.BLOCKQUOTE,G.BLOCKQUOTE],[W.BODY,G.BODY],[W.BR,G.BR],[W.BUTTON,G.BUTTON],[W.CAPTION,G.CAPTION],[W.CENTER,G.CENTER],[W.CODE,G.CODE],[W.COL,G.COL],[W.COLGROUP,G.COLGROUP],[W.DD,G.DD],[W.DESC,G.DESC],[W.DETAILS,G.DETAILS],[W.DIALOG,G.DIALOG],[W.DIR,G.DIR],[W.DIV,G.DIV],[W.DL,G.DL],[W.DT,G.DT],[W.EM,G.EM],[W.EMBED,G.EMBED],[W.FIELDSET,G.FIELDSET],[W.FIGCAPTION,G.FIGCAPTION],[W.FIGURE,G.FIGURE],[W.FONT,G.FONT],[W.FOOTER,G.FOOTER],[W.FOREIGN_OBJECT,G.FOREIGN_OBJECT],[W.FORM,G.FORM],[W.FRAME,G.FRAME],[W.FRAMESET,G.FRAMESET],[W.H1,G.H1],[W.H2,G.H2],[W.H3,G.H3],[W.H4,G.H4],[W.H5,G.H5],[W.H6,G.H6],[W.HEAD,G.HEAD],[W.HEADER,G.HEADER],[W.HGROUP,G.HGROUP],[W.HR,G.HR],[W.HTML,G.HTML],[W.I,G.I],[W.IMG,G.IMG],[W.IMAGE,G.IMAGE],[W.INPUT,G.INPUT],[W.IFRAME,G.IFRAME],[W.KEYGEN,G.KEYGEN],[W.LABEL,G.LABEL],[W.LI,G.LI],[W.LINK,G.LINK],[W.LISTING,G.LISTING],[W.MAIN,G.MAIN],[W.MALIGNMARK,G.MALIGNMARK],[W.MARQUEE,G.MARQUEE],[W.MATH,G.MATH],[W.MENU,G.MENU],[W.META,G.META],[W.MGLYPH,G.MGLYPH],[W.MI,G.MI],[W.MO,G.MO],[W.MN,G.MN],[W.MS,G.MS],[W.MTEXT,G.MTEXT],[W.NAV,G.NAV],[W.NOBR,G.NOBR],[W.NOFRAMES,G.NOFRAMES],[W.NOEMBED,G.NOEMBED],[W.NOSCRIPT,G.NOSCRIPT],[W.OBJECT,G.OBJECT],[W.OL,G.OL],[W.OPTGROUP,G.OPTGROUP],[W.OPTION,G.OPTION],[W.P,G.P],[W.PARAM,G.PARAM],[W.PLAINTEXT,G.PLAINTEXT],[W.PRE,G.PRE],[W.RB,G.RB],[W.RP,G.RP],[W.RT,G.RT],[W.RTC,G.RTC],[W.RUBY,G.RUBY],[W.S,G.S],[W.SCRIPT,G.SCRIPT],[W.SEARCH,G.SEARCH],[W.SECTION,G.SECTION],[W.SELECT,G.SELECT],[W.SOURCE,G.SOURCE],[W.SMALL,G.SMALL],[W.SPAN,G.SPAN],[W.STRIKE,G.STRIKE],[W.STRONG,G.STRONG],[W.STYLE,G.STYLE],[W.SUB,G.SUB],[W.SUMMARY,G.SUMMARY],[W.SUP,G.SUP],[W.TABLE,G.TABLE],[W.TBODY,G.TBODY],[W.TEMPLATE,G.TEMPLATE],[W.TEXTAREA,G.TEXTAREA],[W.TFOOT,G.TFOOT],[W.TD,G.TD],[W.TH,G.TH],[W.THEAD,G.THEAD],[W.TITLE,G.TITLE],[W.TR,G.TR],[W.TRACK,G.TRACK],[W.TT,G.TT],[W.U,G.U],[W.UL,G.UL],[W.SVG,G.SVG],[W.VAR,G.VAR],[W.WBR,G.WBR],[W.XMP,G.XMP]]);function hi(e){return mi.get(e)??G.UNKNOWN}var K=G,gi={[H.HTML]:new Set([K.ADDRESS,K.APPLET,K.AREA,K.ARTICLE,K.ASIDE,K.BASE,K.BASEFONT,K.BGSOUND,K.BLOCKQUOTE,K.BODY,K.BR,K.BUTTON,K.CAPTION,K.CENTER,K.COL,K.COLGROUP,K.DD,K.DETAILS,K.DIR,K.DIV,K.DL,K.DT,K.EMBED,K.FIELDSET,K.FIGCAPTION,K.FIGURE,K.FOOTER,K.FORM,K.FRAME,K.FRAMESET,K.H1,K.H2,K.H3,K.H4,K.H5,K.H6,K.HEAD,K.HEADER,K.HGROUP,K.HR,K.HTML,K.IFRAME,K.IMG,K.INPUT,K.LI,K.LINK,K.LISTING,K.MAIN,K.MARQUEE,K.MENU,K.META,K.NAV,K.NOEMBED,K.NOFRAMES,K.NOSCRIPT,K.OBJECT,K.OL,K.P,K.PARAM,K.PLAINTEXT,K.PRE,K.SCRIPT,K.SECTION,K.SELECT,K.SOURCE,K.STYLE,K.SUMMARY,K.TABLE,K.TBODY,K.TD,K.TEMPLATE,K.TEXTAREA,K.TFOOT,K.TH,K.THEAD,K.TITLE,K.TR,K.TRACK,K.UL,K.WBR,K.XMP]),[H.MATHML]:new Set([K.MI,K.MO,K.MN,K.MS,K.MTEXT,K.ANNOTATION_XML]),[H.SVG]:new Set([K.TITLE,K.FOREIGN_OBJECT,K.DESC]),[H.XLINK]:new Set,[H.XML]:new Set,[H.XMLNS]:new Set},_i=new Set([K.H1,K.H2,K.H3,K.H4,K.H5,K.H6]),vi=new Set([W.STYLE,W.SCRIPT,W.XMP,W.IFRAME,W.NOEMBED,W.NOFRAMES,W.PLAINTEXT]);function yi(e,t){return vi.has(e)||t&&e===W.NOSCRIPT}var q;(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`})(q||={});var J={DATA:q.DATA,RCDATA:q.RCDATA,RAWTEXT:q.RAWTEXT,SCRIPT_DATA:q.SCRIPT_DATA,PLAINTEXT:q.PLAINTEXT,CDATA_SECTION:q.CDATA_SECTION};function bi(e){return e>=R.DIGIT_0&&e<=R.DIGIT_9}function xi(e){return e>=R.LATIN_CAPITAL_A&&e<=R.LATIN_CAPITAL_Z}function Si(e){return e>=R.LATIN_SMALL_A&&e<=R.LATIN_SMALL_Z}function Ci(e){return Si(e)||xi(e)}function wi(e){return Ci(e)||bi(e)}function Ti(e){return e+32}function Ei(e){return e===R.SPACE||e===R.LINE_FEED||e===R.TABULATION||e===R.FORM_FEED}function Di(e){return Ei(e)||e===R.SOLIDUS||e===R.GREATER_THAN_SIGN}function Oi(e){return e===R.NULL?B.nullCharacterReference:e>1114111?B.characterReferenceOutsideUnicodeRange:ai(e)?B.surrogateCharacterReference:li(e)?B.noncharacterCharacterReference:ci(e)||e===R.CARRIAGE_RETURN?B.controlCharacterReference:null}var ki=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=q.DATA,this.returnState=q.DATA,this.entityStartPos=0,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:``,value:``},this.preprocessor=new di(t),this.currentLocation=this.getCurrentLocation(-1),this.entityDecoder=new Ft(Nt,(e,t)=>{this.preprocessor.pos=this.entityStartPos+t-1,this._flushCodePointConsumedAsCharacterReference(e)},t.onParseError?{missingSemicolonAfterCharacterReference:()=>{this._err(B.missingSemicolonAfterCharacterReference,1)},absenceOfDigitsInNumericCharacterReference:e=>{this._err(B.absenceOfDigitsInNumericCharacterReference,this.entityStartPos-this.preprocessor.pos+e)},validateNumericCharacterReference:e=>{let t=Oi(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:V.START_TAG,tagName:``,tagID:G.UNKNOWN,selfClosing:!1,ackSelfClosing:!1,attrs:[],location:this.getCurrentLocation(1)}}_createEndTagToken(){this.currentToken={type:V.END_TAG,tagName:``,tagID:G.UNKNOWN,selfClosing:!1,ackSelfClosing:!1,attrs:[],location:this.getCurrentLocation(2)}}_createCommentToken(e){this.currentToken={type:V.COMMENT,data:``,location:this.getCurrentLocation(e)}}_createDoctypeToken(e){this.currentToken={type:V.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(fi(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(B.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=hi(e.tagName),e.type===V.START_TAG?(this.lastStartTagName=e.tagName,this.handler.onStartTag(e)):(e.attrs.length>0&&this._err(B.endTagWithAttributes),e.selfClosing&&this._err(B.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 V.CHARACTER:this.handler.onCharacter(this.currentCharacterToken);break;case V.NULL_CHARACTER:this.handler.onNullCharacter(this.currentCharacterToken);break;case V.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:V.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=Ei(e)?V.WHITESPACE_CHARACTER:e===R.NULL?V.NULL_CHARACTER:V.CHARACTER;this._appendCharToCurrentCharacterToken(t,e<65536?String.fromCharCode(e):String.fromCodePoint(e))}_emitChars(e){this._appendCharToCurrentCharacterToken(V.CHARACTER,e)}_startCharacterReference(){this.returnState=this.state,this.state=q.CHARACTER_REFERENCE,this.entityStartPos=this.preprocessor.pos,this.entityDecoder.startEntity(this._isCharacterReferenceInAttribute()?Pt.Attribute:Pt.Legacy)}_isCharacterReferenceInAttribute(){return this.returnState===q.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===q.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===q.ATTRIBUTE_VALUE_UNQUOTED}_flushCodePointConsumedAsCharacterReference(e){this._isCharacterReferenceInAttribute()?this.currentAttr.value+=String.fromCodePoint(e):this._emitCodePoint(e)}_callState(e){switch(this.state){case q.DATA:this._stateData(e);break;case q.RCDATA:this._stateRcdata(e);break;case q.RAWTEXT:this._stateRawtext(e);break;case q.SCRIPT_DATA:this._stateScriptData(e);break;case q.PLAINTEXT:this._statePlaintext(e);break;case q.TAG_OPEN:this._stateTagOpen(e);break;case q.END_TAG_OPEN:this._stateEndTagOpen(e);break;case q.TAG_NAME:this._stateTagName(e);break;case q.RCDATA_LESS_THAN_SIGN:this._stateRcdataLessThanSign(e);break;case q.RCDATA_END_TAG_OPEN:this._stateRcdataEndTagOpen(e);break;case q.RCDATA_END_TAG_NAME:this._stateRcdataEndTagName(e);break;case q.RAWTEXT_LESS_THAN_SIGN:this._stateRawtextLessThanSign(e);break;case q.RAWTEXT_END_TAG_OPEN:this._stateRawtextEndTagOpen(e);break;case q.RAWTEXT_END_TAG_NAME:this._stateRawtextEndTagName(e);break;case q.SCRIPT_DATA_LESS_THAN_SIGN:this._stateScriptDataLessThanSign(e);break;case q.SCRIPT_DATA_END_TAG_OPEN:this._stateScriptDataEndTagOpen(e);break;case q.SCRIPT_DATA_END_TAG_NAME:this._stateScriptDataEndTagName(e);break;case q.SCRIPT_DATA_ESCAPE_START:this._stateScriptDataEscapeStart(e);break;case q.SCRIPT_DATA_ESCAPE_START_DASH:this._stateScriptDataEscapeStartDash(e);break;case q.SCRIPT_DATA_ESCAPED:this._stateScriptDataEscaped(e);break;case q.SCRIPT_DATA_ESCAPED_DASH:this._stateScriptDataEscapedDash(e);break;case q.SCRIPT_DATA_ESCAPED_DASH_DASH:this._stateScriptDataEscapedDashDash(e);break;case q.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:this._stateScriptDataEscapedLessThanSign(e);break;case q.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:this._stateScriptDataEscapedEndTagOpen(e);break;case q.SCRIPT_DATA_ESCAPED_END_TAG_NAME:this._stateScriptDataEscapedEndTagName(e);break;case q.SCRIPT_DATA_DOUBLE_ESCAPE_START:this._stateScriptDataDoubleEscapeStart(e);break;case q.SCRIPT_DATA_DOUBLE_ESCAPED:this._stateScriptDataDoubleEscaped(e);break;case q.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:this._stateScriptDataDoubleEscapedDash(e);break;case q.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:this._stateScriptDataDoubleEscapedDashDash(e);break;case q.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:this._stateScriptDataDoubleEscapedLessThanSign(e);break;case q.SCRIPT_DATA_DOUBLE_ESCAPE_END:this._stateScriptDataDoubleEscapeEnd(e);break;case q.BEFORE_ATTRIBUTE_NAME:this._stateBeforeAttributeName(e);break;case q.ATTRIBUTE_NAME:this._stateAttributeName(e);break;case q.AFTER_ATTRIBUTE_NAME:this._stateAfterAttributeName(e);break;case q.BEFORE_ATTRIBUTE_VALUE:this._stateBeforeAttributeValue(e);break;case q.ATTRIBUTE_VALUE_DOUBLE_QUOTED:this._stateAttributeValueDoubleQuoted(e);break;case q.ATTRIBUTE_VALUE_SINGLE_QUOTED:this._stateAttributeValueSingleQuoted(e);break;case q.ATTRIBUTE_VALUE_UNQUOTED:this._stateAttributeValueUnquoted(e);break;case q.AFTER_ATTRIBUTE_VALUE_QUOTED:this._stateAfterAttributeValueQuoted(e);break;case q.SELF_CLOSING_START_TAG:this._stateSelfClosingStartTag(e);break;case q.BOGUS_COMMENT:this._stateBogusComment(e);break;case q.MARKUP_DECLARATION_OPEN:this._stateMarkupDeclarationOpen(e);break;case q.COMMENT_START:this._stateCommentStart(e);break;case q.COMMENT_START_DASH:this._stateCommentStartDash(e);break;case q.COMMENT:this._stateComment(e);break;case q.COMMENT_LESS_THAN_SIGN:this._stateCommentLessThanSign(e);break;case q.COMMENT_LESS_THAN_SIGN_BANG:this._stateCommentLessThanSignBang(e);break;case q.COMMENT_LESS_THAN_SIGN_BANG_DASH:this._stateCommentLessThanSignBangDash(e);break;case q.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:this._stateCommentLessThanSignBangDashDash(e);break;case q.COMMENT_END_DASH:this._stateCommentEndDash(e);break;case q.COMMENT_END:this._stateCommentEnd(e);break;case q.COMMENT_END_BANG:this._stateCommentEndBang(e);break;case q.DOCTYPE:this._stateDoctype(e);break;case q.BEFORE_DOCTYPE_NAME:this._stateBeforeDoctypeName(e);break;case q.DOCTYPE_NAME:this._stateDoctypeName(e);break;case q.AFTER_DOCTYPE_NAME:this._stateAfterDoctypeName(e);break;case q.AFTER_DOCTYPE_PUBLIC_KEYWORD:this._stateAfterDoctypePublicKeyword(e);break;case q.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:this._stateBeforeDoctypePublicIdentifier(e);break;case q.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:this._stateDoctypePublicIdentifierDoubleQuoted(e);break;case q.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:this._stateDoctypePublicIdentifierSingleQuoted(e);break;case q.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:this._stateAfterDoctypePublicIdentifier(e);break;case q.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:this._stateBetweenDoctypePublicAndSystemIdentifiers(e);break;case q.AFTER_DOCTYPE_SYSTEM_KEYWORD:this._stateAfterDoctypeSystemKeyword(e);break;case q.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:this._stateBeforeDoctypeSystemIdentifier(e);break;case q.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:this._stateDoctypeSystemIdentifierDoubleQuoted(e);break;case q.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:this._stateDoctypeSystemIdentifierSingleQuoted(e);break;case q.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:this._stateAfterDoctypeSystemIdentifier(e);break;case q.BOGUS_DOCTYPE:this._stateBogusDoctype(e);break;case q.CDATA_SECTION:this._stateCdataSection(e);break;case q.CDATA_SECTION_BRACKET:this._stateCdataSectionBracket(e);break;case q.CDATA_SECTION_END:this._stateCdataSectionEnd(e);break;case q.CHARACTER_REFERENCE:this._stateCharacterReference();break;case q.AMBIGUOUS_AMPERSAND:this._stateAmbiguousAmpersand(e);break;default:throw Error(`Unknown state`)}}_stateData(e){switch(e){case R.LESS_THAN_SIGN:this.state=q.TAG_OPEN;break;case R.AMPERSAND:this._startCharacterReference();break;case R.NULL:this._err(B.unexpectedNullCharacter),this._emitCodePoint(e);break;case R.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateRcdata(e){switch(e){case R.AMPERSAND:this._startCharacterReference();break;case R.LESS_THAN_SIGN:this.state=q.RCDATA_LESS_THAN_SIGN;break;case R.NULL:this._err(B.unexpectedNullCharacter),this._emitChars(`�`);break;case R.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateRawtext(e){switch(e){case R.LESS_THAN_SIGN:this.state=q.RAWTEXT_LESS_THAN_SIGN;break;case R.NULL:this._err(B.unexpectedNullCharacter),this._emitChars(`�`);break;case R.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateScriptData(e){switch(e){case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_LESS_THAN_SIGN;break;case R.NULL:this._err(B.unexpectedNullCharacter),this._emitChars(`�`);break;case R.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_statePlaintext(e){switch(e){case R.NULL:this._err(B.unexpectedNullCharacter),this._emitChars(`�`);break;case R.EOF:this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateTagOpen(e){if(Ci(e))this._createStartTagToken(),this.state=q.TAG_NAME,this._stateTagName(e);else switch(e){case R.EXCLAMATION_MARK:this.state=q.MARKUP_DECLARATION_OPEN;break;case R.SOLIDUS:this.state=q.END_TAG_OPEN;break;case R.QUESTION_MARK:this._err(B.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=q.BOGUS_COMMENT,this._stateBogusComment(e);break;case R.EOF:this._err(B.eofBeforeTagName),this._emitChars(`<`),this._emitEOFToken();break;default:this._err(B.invalidFirstCharacterOfTagName),this._emitChars(`<`),this.state=q.DATA,this._stateData(e)}}_stateEndTagOpen(e){if(Ci(e))this._createEndTagToken(),this.state=q.TAG_NAME,this._stateTagName(e);else switch(e){case R.GREATER_THAN_SIGN:this._err(B.missingEndTagName),this.state=q.DATA;break;case R.EOF:this._err(B.eofBeforeTagName),this._emitChars(`</`),this._emitEOFToken();break;default:this._err(B.invalidFirstCharacterOfTagName),this._createCommentToken(2),this.state=q.BOGUS_COMMENT,this._stateBogusComment(e)}}_stateTagName(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this.state=q.BEFORE_ATTRIBUTE_NAME;break;case R.SOLIDUS:this.state=q.SELF_CLOSING_START_TAG;break;case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentTagToken();break;case R.NULL:this._err(B.unexpectedNullCharacter),t.tagName+=`�`;break;case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:t.tagName+=String.fromCodePoint(xi(e)?Ti(e):e)}}_stateRcdataLessThanSign(e){e===R.SOLIDUS?this.state=q.RCDATA_END_TAG_OPEN:(this._emitChars(`<`),this.state=q.RCDATA,this._stateRcdata(e))}_stateRcdataEndTagOpen(e){Ci(e)?(this.state=q.RCDATA_END_TAG_NAME,this._stateRcdataEndTagName(e)):(this._emitChars(`</`),this.state=q.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 R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:return this._advanceBy(this.lastStartTagName.length),this.state=q.BEFORE_ATTRIBUTE_NAME,!1;case R.SOLIDUS:return this._advanceBy(this.lastStartTagName.length),this.state=q.SELF_CLOSING_START_TAG,!1;case R.GREATER_THAN_SIGN:return this._advanceBy(this.lastStartTagName.length),this.emitCurrentTagToken(),this.state=q.DATA,!1;default:return!this._ensureHibernation()}}_stateRcdataEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=q.RCDATA,this._stateRcdata(e))}_stateRawtextLessThanSign(e){e===R.SOLIDUS?this.state=q.RAWTEXT_END_TAG_OPEN:(this._emitChars(`<`),this.state=q.RAWTEXT,this._stateRawtext(e))}_stateRawtextEndTagOpen(e){Ci(e)?(this.state=q.RAWTEXT_END_TAG_NAME,this._stateRawtextEndTagName(e)):(this._emitChars(`</`),this.state=q.RAWTEXT,this._stateRawtext(e))}_stateRawtextEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=q.RAWTEXT,this._stateRawtext(e))}_stateScriptDataLessThanSign(e){switch(e){case R.SOLIDUS:this.state=q.SCRIPT_DATA_END_TAG_OPEN;break;case R.EXCLAMATION_MARK:this.state=q.SCRIPT_DATA_ESCAPE_START,this._emitChars(`<!`);break;default:this._emitChars(`<`),this.state=q.SCRIPT_DATA,this._stateScriptData(e)}}_stateScriptDataEndTagOpen(e){Ci(e)?(this.state=q.SCRIPT_DATA_END_TAG_NAME,this._stateScriptDataEndTagName(e)):(this._emitChars(`</`),this.state=q.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=q.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEscapeStart(e){e===R.HYPHEN_MINUS?(this.state=q.SCRIPT_DATA_ESCAPE_START_DASH,this._emitChars(`-`)):(this.state=q.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEscapeStartDash(e){e===R.HYPHEN_MINUS?(this.state=q.SCRIPT_DATA_ESCAPED_DASH_DASH,this._emitChars(`-`)):(this.state=q.SCRIPT_DATA,this._stateScriptData(e))}_stateScriptDataEscaped(e){switch(e){case R.HYPHEN_MINUS:this.state=q.SCRIPT_DATA_ESCAPED_DASH,this._emitChars(`-`);break;case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;break;case R.NULL:this._err(B.unexpectedNullCharacter),this._emitChars(`�`);break;case R.EOF:this._err(B.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateScriptDataEscapedDash(e){switch(e){case R.HYPHEN_MINUS:this.state=q.SCRIPT_DATA_ESCAPED_DASH_DASH,this._emitChars(`-`);break;case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;break;case R.NULL:this._err(B.unexpectedNullCharacter),this.state=q.SCRIPT_DATA_ESCAPED,this._emitChars(`�`);break;case R.EOF:this._err(B.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=q.SCRIPT_DATA_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataEscapedDashDash(e){switch(e){case R.HYPHEN_MINUS:this._emitChars(`-`);break;case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;break;case R.GREATER_THAN_SIGN:this.state=q.SCRIPT_DATA,this._emitChars(`>`);break;case R.NULL:this._err(B.unexpectedNullCharacter),this.state=q.SCRIPT_DATA_ESCAPED,this._emitChars(`�`);break;case R.EOF:this._err(B.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=q.SCRIPT_DATA_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataEscapedLessThanSign(e){e===R.SOLIDUS?this.state=q.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Ci(e)?(this._emitChars(`<`),this.state=q.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(e)):(this._emitChars(`<`),this.state=q.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataEscapedEndTagOpen(e){Ci(e)?(this.state=q.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(e)):(this._emitChars(`</`),this.state=q.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataEscapedEndTagName(e){this.handleSpecialEndTag(e)&&(this._emitChars(`</`),this.state=q.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataDoubleEscapeStart(e){if(this.preprocessor.startsWith(z.SCRIPT,!1)&&Di(this.preprocessor.peek(z.SCRIPT.length))){this._emitCodePoint(e);for(let e=0;e<z.SCRIPT.length;e++)this._emitCodePoint(this._consume());this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED}else this._ensureHibernation()||(this.state=q.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(e))}_stateScriptDataDoubleEscaped(e){switch(e){case R.HYPHEN_MINUS:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED_DASH,this._emitChars(`-`);break;case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN,this._emitChars(`<`);break;case R.NULL:this._err(B.unexpectedNullCharacter),this._emitChars(`�`);break;case R.EOF:this._err(B.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateScriptDataDoubleEscapedDash(e){switch(e){case R.HYPHEN_MINUS:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH,this._emitChars(`-`);break;case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN,this._emitChars(`<`);break;case R.NULL:this._err(B.unexpectedNullCharacter),this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(`�`);break;case R.EOF:this._err(B.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataDoubleEscapedDashDash(e){switch(e){case R.HYPHEN_MINUS:this._emitChars(`-`);break;case R.LESS_THAN_SIGN:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN,this._emitChars(`<`);break;case R.GREATER_THAN_SIGN:this.state=q.SCRIPT_DATA,this._emitChars(`>`);break;case R.NULL:this._err(B.unexpectedNullCharacter),this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(`�`);break;case R.EOF:this._err(B.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break;default:this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(e)}}_stateScriptDataDoubleEscapedLessThanSign(e){e===R.SOLIDUS?(this.state=q.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars(`/`)):(this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(e))}_stateScriptDataDoubleEscapeEnd(e){if(this.preprocessor.startsWith(z.SCRIPT,!1)&&Di(this.preprocessor.peek(z.SCRIPT.length))){this._emitCodePoint(e);for(let e=0;e<z.SCRIPT.length;e++)this._emitCodePoint(this._consume());this.state=q.SCRIPT_DATA_ESCAPED}else this._ensureHibernation()||(this.state=q.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(e))}_stateBeforeAttributeName(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.SOLIDUS:case R.GREATER_THAN_SIGN:case R.EOF:this.state=q.AFTER_ATTRIBUTE_NAME,this._stateAfterAttributeName(e);break;case R.EQUALS_SIGN:this._err(B.unexpectedEqualsSignBeforeAttributeName),this._createAttr(`=`),this.state=q.ATTRIBUTE_NAME;break;default:this._createAttr(``),this.state=q.ATTRIBUTE_NAME,this._stateAttributeName(e)}}_stateAttributeName(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:case R.SOLIDUS:case R.GREATER_THAN_SIGN:case R.EOF:this._leaveAttrName(),this.state=q.AFTER_ATTRIBUTE_NAME,this._stateAfterAttributeName(e);break;case R.EQUALS_SIGN:this._leaveAttrName(),this.state=q.BEFORE_ATTRIBUTE_VALUE;break;case R.QUOTATION_MARK:case R.APOSTROPHE:case R.LESS_THAN_SIGN:this._err(B.unexpectedCharacterInAttributeName),this.currentAttr.name+=String.fromCodePoint(e);break;case R.NULL:this._err(B.unexpectedNullCharacter),this.currentAttr.name+=`�`;break;default:this.currentAttr.name+=String.fromCodePoint(xi(e)?Ti(e):e)}}_stateAfterAttributeName(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.SOLIDUS:this.state=q.SELF_CLOSING_START_TAG;break;case R.EQUALS_SIGN:this.state=q.BEFORE_ATTRIBUTE_VALUE;break;case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentTagToken();break;case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:this._createAttr(``),this.state=q.ATTRIBUTE_NAME,this._stateAttributeName(e)}}_stateBeforeAttributeValue(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.QUOTATION_MARK:this.state=q.ATTRIBUTE_VALUE_DOUBLE_QUOTED;break;case R.APOSTROPHE:this.state=q.ATTRIBUTE_VALUE_SINGLE_QUOTED;break;case R.GREATER_THAN_SIGN:this._err(B.missingAttributeValue),this.state=q.DATA,this.emitCurrentTagToken();break;default:this.state=q.ATTRIBUTE_VALUE_UNQUOTED,this._stateAttributeValueUnquoted(e)}}_stateAttributeValueDoubleQuoted(e){switch(e){case R.QUOTATION_MARK:this.state=q.AFTER_ATTRIBUTE_VALUE_QUOTED;break;case R.AMPERSAND:this._startCharacterReference();break;case R.NULL:this._err(B.unexpectedNullCharacter),this.currentAttr.value+=`�`;break;case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:this.currentAttr.value+=String.fromCodePoint(e)}}_stateAttributeValueSingleQuoted(e){switch(e){case R.APOSTROPHE:this.state=q.AFTER_ATTRIBUTE_VALUE_QUOTED;break;case R.AMPERSAND:this._startCharacterReference();break;case R.NULL:this._err(B.unexpectedNullCharacter),this.currentAttr.value+=`�`;break;case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:this.currentAttr.value+=String.fromCodePoint(e)}}_stateAttributeValueUnquoted(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this._leaveAttrValue(),this.state=q.BEFORE_ATTRIBUTE_NAME;break;case R.AMPERSAND:this._startCharacterReference();break;case R.GREATER_THAN_SIGN:this._leaveAttrValue(),this.state=q.DATA,this.emitCurrentTagToken();break;case R.NULL:this._err(B.unexpectedNullCharacter),this.currentAttr.value+=`�`;break;case R.QUOTATION_MARK:case R.APOSTROPHE:case R.LESS_THAN_SIGN:case R.EQUALS_SIGN:case R.GRAVE_ACCENT:this._err(B.unexpectedCharacterInUnquotedAttributeValue),this.currentAttr.value+=String.fromCodePoint(e);break;case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:this.currentAttr.value+=String.fromCodePoint(e)}}_stateAfterAttributeValueQuoted(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this._leaveAttrValue(),this.state=q.BEFORE_ATTRIBUTE_NAME;break;case R.SOLIDUS:this._leaveAttrValue(),this.state=q.SELF_CLOSING_START_TAG;break;case R.GREATER_THAN_SIGN:this._leaveAttrValue(),this.state=q.DATA,this.emitCurrentTagToken();break;case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:this._err(B.missingWhitespaceBetweenAttributes),this.state=q.BEFORE_ATTRIBUTE_NAME,this._stateBeforeAttributeName(e)}}_stateSelfClosingStartTag(e){switch(e){case R.GREATER_THAN_SIGN:{let e=this.currentToken;e.selfClosing=!0,this.state=q.DATA,this.emitCurrentTagToken();break}case R.EOF:this._err(B.eofInTag),this._emitEOFToken();break;default:this._err(B.unexpectedSolidusInTag),this.state=q.BEFORE_ATTRIBUTE_NAME,this._stateBeforeAttributeName(e)}}_stateBogusComment(e){let t=this.currentToken;switch(e){case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentComment(t);break;case R.EOF:this.emitCurrentComment(t),this._emitEOFToken();break;case R.NULL:this._err(B.unexpectedNullCharacter),t.data+=`�`;break;default:t.data+=String.fromCodePoint(e)}}_stateMarkupDeclarationOpen(e){this._consumeSequenceIfMatch(z.DASH_DASH,!0)?(this._createCommentToken(z.DASH_DASH.length+1),this.state=q.COMMENT_START):this._consumeSequenceIfMatch(z.DOCTYPE,!1)?(this.currentLocation=this.getCurrentLocation(z.DOCTYPE.length+1),this.state=q.DOCTYPE):this._consumeSequenceIfMatch(z.CDATA_START,!0)?this.inForeignNode?this.state=q.CDATA_SECTION:(this._err(B.cdataInHtmlContent),this._createCommentToken(z.CDATA_START.length+1),this.currentToken.data=`[CDATA[`,this.state=q.BOGUS_COMMENT):this._ensureHibernation()||(this._err(B.incorrectlyOpenedComment),this._createCommentToken(2),this.state=q.BOGUS_COMMENT,this._stateBogusComment(e))}_stateCommentStart(e){switch(e){case R.HYPHEN_MINUS:this.state=q.COMMENT_START_DASH;break;case R.GREATER_THAN_SIGN:{this._err(B.abruptClosingOfEmptyComment),this.state=q.DATA;let e=this.currentToken;this.emitCurrentComment(e);break}default:this.state=q.COMMENT,this._stateComment(e)}}_stateCommentStartDash(e){let t=this.currentToken;switch(e){case R.HYPHEN_MINUS:this.state=q.COMMENT_END;break;case R.GREATER_THAN_SIGN:this._err(B.abruptClosingOfEmptyComment),this.state=q.DATA,this.emitCurrentComment(t);break;case R.EOF:this._err(B.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`-`,this.state=q.COMMENT,this._stateComment(e)}}_stateComment(e){let t=this.currentToken;switch(e){case R.HYPHEN_MINUS:this.state=q.COMMENT_END_DASH;break;case R.LESS_THAN_SIGN:t.data+=`<`,this.state=q.COMMENT_LESS_THAN_SIGN;break;case R.NULL:this._err(B.unexpectedNullCharacter),t.data+=`�`;break;case R.EOF:this._err(B.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=String.fromCodePoint(e)}}_stateCommentLessThanSign(e){let t=this.currentToken;switch(e){case R.EXCLAMATION_MARK:t.data+=`!`,this.state=q.COMMENT_LESS_THAN_SIGN_BANG;break;case R.LESS_THAN_SIGN:t.data+=`<`;break;default:this.state=q.COMMENT,this._stateComment(e)}}_stateCommentLessThanSignBang(e){e===R.HYPHEN_MINUS?this.state=q.COMMENT_LESS_THAN_SIGN_BANG_DASH:(this.state=q.COMMENT,this._stateComment(e))}_stateCommentLessThanSignBangDash(e){e===R.HYPHEN_MINUS?this.state=q.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:(this.state=q.COMMENT_END_DASH,this._stateCommentEndDash(e))}_stateCommentLessThanSignBangDashDash(e){e!==R.GREATER_THAN_SIGN&&e!==R.EOF&&this._err(B.nestedComment),this.state=q.COMMENT_END,this._stateCommentEnd(e)}_stateCommentEndDash(e){let t=this.currentToken;switch(e){case R.HYPHEN_MINUS:this.state=q.COMMENT_END;break;case R.EOF:this._err(B.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`-`,this.state=q.COMMENT,this._stateComment(e)}}_stateCommentEnd(e){let t=this.currentToken;switch(e){case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentComment(t);break;case R.EXCLAMATION_MARK:this.state=q.COMMENT_END_BANG;break;case R.HYPHEN_MINUS:t.data+=`-`;break;case R.EOF:this._err(B.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`--`,this.state=q.COMMENT,this._stateComment(e)}}_stateCommentEndBang(e){let t=this.currentToken;switch(e){case R.HYPHEN_MINUS:t.data+=`--!`,this.state=q.COMMENT_END_DASH;break;case R.GREATER_THAN_SIGN:this._err(B.incorrectlyClosedComment),this.state=q.DATA,this.emitCurrentComment(t);break;case R.EOF:this._err(B.eofInComment),this.emitCurrentComment(t),this._emitEOFToken();break;default:t.data+=`--!`,this.state=q.COMMENT,this._stateComment(e)}}_stateDoctype(e){switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this.state=q.BEFORE_DOCTYPE_NAME;break;case R.GREATER_THAN_SIGN:this.state=q.BEFORE_DOCTYPE_NAME,this._stateBeforeDoctypeName(e);break;case R.EOF:{this._err(B.eofInDoctype),this._createDoctypeToken(null);let e=this.currentToken;e.forceQuirks=!0,this.emitCurrentDoctype(e),this._emitEOFToken();break}default:this._err(B.missingWhitespaceBeforeDoctypeName),this.state=q.BEFORE_DOCTYPE_NAME,this._stateBeforeDoctypeName(e)}}_stateBeforeDoctypeName(e){if(xi(e))this._createDoctypeToken(String.fromCharCode(Ti(e))),this.state=q.DOCTYPE_NAME;else switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.NULL:this._err(B.unexpectedNullCharacter),this._createDoctypeToken(`�`),this.state=q.DOCTYPE_NAME;break;case R.GREATER_THAN_SIGN:{this._err(B.missingDoctypeName),this._createDoctypeToken(null);let e=this.currentToken;e.forceQuirks=!0,this.emitCurrentDoctype(e),this.state=q.DATA;break}case R.EOF:{this._err(B.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=q.DOCTYPE_NAME}}_stateDoctypeName(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this.state=q.AFTER_DOCTYPE_NAME;break;case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.NULL:this._err(B.unexpectedNullCharacter),t.name+=`�`;break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:t.name+=String.fromCodePoint(xi(e)?Ti(e):e)}}_stateAfterDoctypeName(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._consumeSequenceIfMatch(z.PUBLIC,!1)?this.state=q.AFTER_DOCTYPE_PUBLIC_KEYWORD:this._consumeSequenceIfMatch(z.SYSTEM,!1)?this.state=q.AFTER_DOCTYPE_SYSTEM_KEYWORD:this._ensureHibernation()||(this._err(B.invalidCharacterSequenceAfterDoctypeName),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e))}}_stateAfterDoctypePublicKeyword(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this.state=q.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER;break;case R.QUOTATION_MARK:this._err(B.missingWhitespaceAfterDoctypePublicKeyword),t.publicId=``,this.state=q.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;break;case R.APOSTROPHE:this._err(B.missingWhitespaceAfterDoctypePublicKeyword),t.publicId=``,this.state=q.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;break;case R.GREATER_THAN_SIGN:this._err(B.missingDoctypePublicIdentifier),t.forceQuirks=!0,this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.missingQuoteBeforeDoctypePublicIdentifier),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBeforeDoctypePublicIdentifier(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.QUOTATION_MARK:t.publicId=``,this.state=q.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;break;case R.APOSTROPHE:t.publicId=``,this.state=q.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;break;case R.GREATER_THAN_SIGN:this._err(B.missingDoctypePublicIdentifier),t.forceQuirks=!0,this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.missingQuoteBeforeDoctypePublicIdentifier),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateDoctypePublicIdentifierDoubleQuoted(e){let t=this.currentToken;switch(e){case R.QUOTATION_MARK:this.state=q.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;break;case R.NULL:this._err(B.unexpectedNullCharacter),t.publicId+=`�`;break;case R.GREATER_THAN_SIGN:this._err(B.abruptDoctypePublicIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.EOF:this._err(B.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 R.APOSTROPHE:this.state=q.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;break;case R.NULL:this._err(B.unexpectedNullCharacter),t.publicId+=`�`;break;case R.GREATER_THAN_SIGN:this._err(B.abruptDoctypePublicIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.EOF:this._err(B.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 R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this.state=q.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS;break;case R.GREATER_THAN_SIGN:this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.QUOTATION_MARK:this._err(B.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers),t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case R.APOSTROPHE:this._err(B.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers),t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBetweenDoctypePublicAndSystemIdentifiers(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.GREATER_THAN_SIGN:this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.QUOTATION_MARK:t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case R.APOSTROPHE:t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateAfterDoctypeSystemKeyword(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:this.state=q.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER;break;case R.QUOTATION_MARK:this._err(B.missingWhitespaceAfterDoctypeSystemKeyword),t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case R.APOSTROPHE:this._err(B.missingWhitespaceAfterDoctypeSystemKeyword),t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case R.GREATER_THAN_SIGN:this._err(B.missingDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBeforeDoctypeSystemIdentifier(e){let t=this.currentToken;switch(e){case R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.QUOTATION_MARK:t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;break;case R.APOSTROPHE:t.systemId=``,this.state=q.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;break;case R.GREATER_THAN_SIGN:this._err(B.missingDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=q.DATA,this.emitCurrentDoctype(t);break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.missingQuoteBeforeDoctypeSystemIdentifier),t.forceQuirks=!0,this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateDoctypeSystemIdentifierDoubleQuoted(e){let t=this.currentToken;switch(e){case R.QUOTATION_MARK:this.state=q.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;break;case R.NULL:this._err(B.unexpectedNullCharacter),t.systemId+=`�`;break;case R.GREATER_THAN_SIGN:this._err(B.abruptDoctypeSystemIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.EOF:this._err(B.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 R.APOSTROPHE:this.state=q.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;break;case R.NULL:this._err(B.unexpectedNullCharacter),t.systemId+=`�`;break;case R.GREATER_THAN_SIGN:this._err(B.abruptDoctypeSystemIdentifier),t.forceQuirks=!0,this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.EOF:this._err(B.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 R.SPACE:case R.LINE_FEED:case R.TABULATION:case R.FORM_FEED:break;case R.GREATER_THAN_SIGN:this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.EOF:this._err(B.eofInDoctype),t.forceQuirks=!0,this.emitCurrentDoctype(t),this._emitEOFToken();break;default:this._err(B.unexpectedCharacterAfterDoctypeSystemIdentifier),this.state=q.BOGUS_DOCTYPE,this._stateBogusDoctype(e)}}_stateBogusDoctype(e){let t=this.currentToken;switch(e){case R.GREATER_THAN_SIGN:this.emitCurrentDoctype(t),this.state=q.DATA;break;case R.NULL:this._err(B.unexpectedNullCharacter);break;case R.EOF:this.emitCurrentDoctype(t),this._emitEOFToken();break;default:}}_stateCdataSection(e){switch(e){case R.RIGHT_SQUARE_BRACKET:this.state=q.CDATA_SECTION_BRACKET;break;case R.EOF:this._err(B.eofInCdata),this._emitEOFToken();break;default:this._emitCodePoint(e)}}_stateCdataSectionBracket(e){e===R.RIGHT_SQUARE_BRACKET?this.state=q.CDATA_SECTION_END:(this._emitChars(`]`),this.state=q.CDATA_SECTION,this._stateCdataSection(e))}_stateCdataSectionEnd(e){switch(e){case R.GREATER_THAN_SIGN:this.state=q.DATA;break;case R.RIGHT_SQUARE_BRACKET:this._emitChars(`]`);break;default:this._emitChars(`]]`),this.state=q.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(R.AMPERSAND),this.state=!this._isCharacterReferenceInAttribute()&&wi(this.preprocessor.peek(1))?q.AMBIGUOUS_AMPERSAND:this.returnState):this.state=this.returnState}_stateAmbiguousAmpersand(e){wi(e)?this._flushCodePointConsumedAsCharacterReference(e):(e===R.SEMICOLON&&this._err(B.unknownNamedCharacterReference),this.state=this.returnState,this._callState(e))}},Ai=new Set([G.DD,G.DT,G.LI,G.OPTGROUP,G.OPTION,G.P,G.RB,G.RP,G.RT,G.RTC]),ji=new Set([...Ai,G.CAPTION,G.COLGROUP,G.TBODY,G.TD,G.TFOOT,G.TH,G.THEAD,G.TR]),Mi=new Set([G.APPLET,G.CAPTION,G.HTML,G.MARQUEE,G.OBJECT,G.TABLE,G.TD,G.TEMPLATE,G.TH]),Ni=new Set([...Mi,G.OL,G.UL]),Pi=new Set([...Mi,G.BUTTON]),Fi=new Set([G.ANNOTATION_XML,G.MI,G.MN,G.MO,G.MS,G.MTEXT]),Ii=new Set([G.DESC,G.FOREIGN_OBJECT,G.TITLE]),Li=new Set([G.TR,G.TEMPLATE,G.HTML]),Ri=new Set([G.TBODY,G.TFOOT,G.THEAD,G.TEMPLATE,G.HTML]),zi=new Set([G.TABLE,G.TEMPLATE,G.HTML]),Bi=new Set([G.TD,G.TH]),Vi=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=G.UNKNOWN,this.current=e}_indexOf(e){return this.items.lastIndexOf(e,this.stackTop)}_isInTemplate(){return this.currentTagId===G.TEMPLATE&&this.treeAdapter.getNamespaceURI(this.current)===H.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])!==H.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(_i,H.HTML)}popUntilTableCellPopped(){this.popUntilPopped(Bi,H.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(zi,H.HTML)}clearBackToTableBodyContext(){this.clearBackTo(Ri,H.HTML)}clearBackToTableRowContext(){this.clearBackTo(Li,H.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]===G.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]===G.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 H.HTML:if(r===e)return!0;if(t.has(r))return!1;break;case H.SVG:if(Ii.has(r))return!1;break;case H.MATHML:if(Fi.has(r))return!1;break}}return!0}hasInScope(e){return this.hasInDynamicScope(e,Mi)}hasInListItemScope(e){return this.hasInDynamicScope(e,Ni)}hasInButtonScope(e){return this.hasInDynamicScope(e,Pi)}hasNumberedHeaderInScope(){for(let e=this.stackTop;e>=0;e--){let t=this.tagIDs[e];switch(this.treeAdapter.getNamespaceURI(this.items[e])){case H.HTML:if(_i.has(t))return!0;if(Mi.has(t))return!1;break;case H.SVG:if(Ii.has(t))return!1;break;case H.MATHML:if(Fi.has(t))return!1;break}}return!0}hasInTableScope(e){for(let t=this.stackTop;t>=0;t--)if(this.treeAdapter.getNamespaceURI(this.items[t])===H.HTML)switch(this.tagIDs[t]){case e:return!0;case G.TABLE:case G.HTML:return!1}return!0}hasTableBodyContextInTableScope(){for(let e=this.stackTop;e>=0;e--)if(this.treeAdapter.getNamespaceURI(this.items[e])===H.HTML)switch(this.tagIDs[e]){case G.TBODY:case G.THEAD:case G.TFOOT:return!0;case G.TABLE:case G.HTML:return!1}return!0}hasInSelectScope(e){for(let t=this.stackTop;t>=0;t--)if(this.treeAdapter.getNamespaceURI(this.items[t])===H.HTML)switch(this.tagIDs[t]){case e:return!0;case G.OPTION:case G.OPTGROUP:break;default:return!1}return!0}generateImpliedEndTags(){for(;this.currentTagId!==void 0&&Ai.has(this.currentTagId);)this.pop()}generateImpliedEndTagsThoroughly(){for(;this.currentTagId!==void 0&&ji.has(this.currentTagId);)this.pop()}generateImpliedEndTagsWithExclusion(e){for(;this.currentTagId!==void 0&&this.currentTagId!==e&&ji.has(this.currentTagId);)this.pop()}},Hi=3,Y;(function(e){e[e.Marker=0]=`Marker`,e[e.Element=1]=`Element`})(Y||={});var Ui={type:Y.Marker},Wi=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===Y.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<Hi)return;let t=this.treeAdapter.getAttrList(e),n=this._getNoahArkConditionCandidates(e,t);if(n.length<Hi)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>=Hi&&this.entries.splice(t.idx,1))}}insertMarker(){this.entries.unshift(Ui)}pushElement(e,t){this._ensureNoahArkCondition(e),this.entries.unshift({type:Y.Element,element:e,token:t})}insertElementAfterBookmark(e,t){let n=this.entries.indexOf(this.bookmark);this.entries.splice(n,0,{type:Y.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(Ui);e===-1?this.entries.length=0:this.entries.splice(0,e+1)}getElementEntryInScopeWithTagName(e){let t=this.entries.find(t=>t.type===Y.Marker||this.treeAdapter.getTagName(t.element)===e);return t&&t.type===Y.Element?t:null}getElementEntry(e){return this.entries.find(t=>t.type===Y.Element&&t.element===e)}},X={createDocument(){return{nodeName:`#document`,mode:U.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};X.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(X.isTextNode(n)){n.value+=t;return}}X.appendChild(e,X.createTextNode(t))},insertTextBefore(e,t,n){let r=e.childNodes[e.childNodes.indexOf(n)-1];r&&X.isTextNode(r)?r.value+=t:X.insertBefore(e,X.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}}},Gi=`html`,Ki=`about:legacy-compat`,qi=`http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd`,Ji=`+//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(`,`),Yi=[...Ji,`-//w3c//dtd html 4.01 frameset//`,`-//w3c//dtd html 4.01 transitional//`],Xi=new Set([`-//w3o//dtd w3 html strict 3.0//en//`,`-/w3c/dtd html 4.0 transitional/en`,`html`]),Zi=[`-//w3c//dtd xhtml 1.0 frameset//`,`-//w3c//dtd xhtml 1.0 transitional//`],Qi=[...Zi,`-//w3c//dtd html 4.01 frameset//`,`-//w3c//dtd html 4.01 transitional//`];function $i(e,t){return t.some(t=>e.startsWith(t))}function ea(e){return e.name===Gi&&e.publicId===null&&(e.systemId===null||e.systemId===Ki)}function ta(e){if(e.name!==Gi)return U.QUIRKS;let{systemId:t}=e;if(t&&t.toLowerCase()===qi)return U.QUIRKS;let{publicId:n}=e;if(n!==null){if(n=n.toLowerCase(),Xi.has(n))return U.QUIRKS;let e=t===null?Yi:Ji;if($i(n,e))return U.QUIRKS;if(e=t===null?Zi:Qi,$i(n,e))return U.LIMITED_QUIRKS}return U.NO_QUIRKS}var na={TEXT_HTML:`text/html`,APPLICATION_XML:`application/xhtml+xml`},ra=`definitionurl`,ia=`definitionURL`,aa=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])),oa=new Map([[`xlink:actuate`,{prefix:`xlink`,name:`actuate`,namespace:H.XLINK}],[`xlink:arcrole`,{prefix:`xlink`,name:`arcrole`,namespace:H.XLINK}],[`xlink:href`,{prefix:`xlink`,name:`href`,namespace:H.XLINK}],[`xlink:role`,{prefix:`xlink`,name:`role`,namespace:H.XLINK}],[`xlink:show`,{prefix:`xlink`,name:`show`,namespace:H.XLINK}],[`xlink:title`,{prefix:`xlink`,name:`title`,namespace:H.XLINK}],[`xlink:type`,{prefix:`xlink`,name:`type`,namespace:H.XLINK}],[`xml:lang`,{prefix:`xml`,name:`lang`,namespace:H.XML}],[`xml:space`,{prefix:`xml`,name:`space`,namespace:H.XML}],[`xmlns`,{prefix:``,name:`xmlns`,namespace:H.XMLNS}],[`xmlns:xlink`,{prefix:`xmlns`,name:`xlink`,namespace:H.XMLNS}]]),sa=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])),ca=new Set([G.B,G.BIG,G.BLOCKQUOTE,G.BODY,G.BR,G.CENTER,G.CODE,G.DD,G.DIV,G.DL,G.DT,G.EM,G.EMBED,G.H1,G.H2,G.H3,G.H4,G.H5,G.H6,G.HEAD,G.HR,G.I,G.IMG,G.LI,G.LISTING,G.MENU,G.META,G.NOBR,G.OL,G.P,G.PRE,G.RUBY,G.S,G.SMALL,G.SPAN,G.STRONG,G.STRIKE,G.SUB,G.SUP,G.TABLE,G.TT,G.U,G.UL,G.VAR]);function la(e){let t=e.tagID;return t===G.FONT&&e.attrs.some(({name:e})=>e===pi.COLOR||e===pi.SIZE||e===pi.FACE)||ca.has(t)}function ua(e){for(let t=0;t<e.attrs.length;t++)if(e.attrs[t].name===ra){e.attrs[t].name=ia;break}}function da(e){for(let t=0;t<e.attrs.length;t++){let n=aa.get(e.attrs[t].name);n!=null&&(e.attrs[t].name=n)}}function fa(e){for(let t=0;t<e.attrs.length;t++){let n=oa.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 pa(e){let t=sa.get(e.tagName);t!=null&&(e.tagName=t,e.tagID=hi(e.tagName))}function ma(e,t){return t===H.MATHML&&(e===G.MI||e===G.MO||e===G.MN||e===G.MS||e===G.MTEXT)}function ha(e,t,n){if(t===H.MATHML&&e===G.ANNOTATION_XML){for(let e=0;e<n.length;e++)if(n[e].name===pi.ENCODING){let t=n[e].value.toLowerCase();return t===na.TEXT_HTML||t===na.APPLICATION_XML}}return t===H.SVG&&(e===G.FOREIGN_OBJECT||e===G.DESC||e===G.TITLE)}function ga(e,t,n,r){return(!r||r===H.HTML)&&ha(e,t,n)||(!r||r===H.MATHML)&&ma(e,t)}var _a=`hidden`,va=8,ya=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 ba={startLine:-1,startCol:-1,startOffset:-1,endLine:-1,endCol:-1,endOffset:-1},xa=new Set([G.TABLE,G.TBODY,G.TFOOT,G.THEAD,G.TR]),Sa={scriptingEnabled:!0,sourceCodeLocationInfo:!1,treeAdapter:X,onParseError:null},Ca=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={...Sa,...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 ki(this.options,this),this.activeFormattingElements=new Wi(this.treeAdapter),this.fragmentContextID=n?hi(this.treeAdapter.getTagName(n)):G.UNKNOWN,this._setContextModes(n??this.document,this.fragmentContextID),this.openElements=new Vi(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={...Sa,...t};e??=n.treeAdapter.createElement(W.TEMPLATE,H.HTML,[]);let r=n.treeAdapter.createElement(`documentmock`,H.HTML,[]),i=new this(n,r,e);return i.fragmentContextID===G.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??ba,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)===H.HTML;this.currentNotInHTML=!n,this.tokenizer.inForeignNode=!n&&e!==void 0&&t!==void 0&&!this._isIntegrationPoint(t,e)}_switchToTextParsing(e,t){this._insertElement(e,H.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=J.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)===W.FORM){this.formElement=e;break}e=this.treeAdapter.getParentNode(e)}}_initTokenizerForFragmentParsing(){if(!(!this.fragmentContext||this.treeAdapter.getNamespaceURI(this.fragmentContext)!==H.HTML))switch(this.fragmentContextID){case G.TITLE:case G.TEXTAREA:this.tokenizer.state=J.RCDATA;break;case G.STYLE:case G.XMP:case G.IFRAME:case G.NOEMBED:case G.NOFRAMES:case G.NOSCRIPT:this.tokenizer.state=J.RAWTEXT;break;case G.SCRIPT:this.tokenizer.state=J.SCRIPT_DATA;break;case G.PLAINTEXT:this.tokenizer.state=J.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,H.HTML,[]);this._attachElementToTree(n,null),this.openElements.push(n,t)}_insertTemplate(e){let t=this.treeAdapter.createElement(e.tagName,H.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(W.HTML,H.HTML,[]);this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(e,null),this.treeAdapter.appendChild(this.openElements.current,e),this.openElements.push(e,G.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===V.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===G.SVG&&this.treeAdapter.getTagName(t)===W.ANNOTATION_XML&&this.treeAdapter.getNamespaceURI(t)===H.MATHML?!1:this.tokenizer.inForeignNode||(e.tagID===G.MGLYPH||e.tagID===G.MALIGNMARK)&&n!==void 0&&!this._isIntegrationPoint(n,t,H.HTML)}_processToken(e){switch(e.type){case V.CHARACTER:this.onCharacter(e);break;case V.NULL_CHARACTER:this.onNullCharacter(e);break;case V.COMMENT:this.onComment(e);break;case V.DOCTYPE:this.onDoctype(e);break;case V.START_TAG:this._processStartTag(e);break;case V.END_TAG:this.onEndTag(e);break;case V.EOF:this.onEof(e);break;case V.WHITESPACE_CHARACTER:this.onWhitespaceCharacter(e);break}}_isIntegrationPoint(e,t,n){return ga(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===Y.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(G.P),this.openElements.popUntilTagNamePopped(G.P)}_resetInsertionMode(){for(let e=this.openElements.stackTop;e>=0;e--)switch(e===0&&this.fragmentContext?this.fragmentContextID:this.openElements.tagIDs[e]){case G.TR:this.insertionMode=Z.IN_ROW;return;case G.TBODY:case G.THEAD:case G.TFOOT:this.insertionMode=Z.IN_TABLE_BODY;return;case G.CAPTION:this.insertionMode=Z.IN_CAPTION;return;case G.COLGROUP:this.insertionMode=Z.IN_COLUMN_GROUP;return;case G.TABLE:this.insertionMode=Z.IN_TABLE;return;case G.BODY:this.insertionMode=Z.IN_BODY;return;case G.FRAMESET:this.insertionMode=Z.IN_FRAMESET;return;case G.SELECT:this._resetInsertionModeForSelect(e);return;case G.TEMPLATE:this.insertionMode=this.tmplInsertionModeStack[0];return;case G.HTML:this.insertionMode=this.headElement?Z.AFTER_HEAD:Z.BEFORE_HEAD;return;case G.TD:case G.TH:if(e>0){this.insertionMode=Z.IN_CELL;return}break;case G.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===G.TEMPLATE)break;if(e===G.TABLE){this.insertionMode=Z.IN_SELECT_IN_TABLE;return}}this.insertionMode=Z.IN_SELECT}_isElementCausesFosterParenting(e){return xa.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 G.TEMPLATE:if(this.treeAdapter.getNamespaceURI(t)===H.HTML)return{parent:this.treeAdapter.getTemplateContent(t),beforeElement:null};break;case G.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 gi[this.treeAdapter.getNamespaceURI(e)].has(t)}onCharacter(e){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){Bs(this,e);return}switch(this.insertionMode){case Z.INITIAL:Ia(this,e);break;case Z.BEFORE_HTML:za(this,e);break;case Z.BEFORE_HEAD:Ha(this,e);break;case Z.IN_HEAD:Ga(this,e);break;case Z.IN_HEAD_NO_SCRIPT:Ja(this,e);break;case Z.AFTER_HEAD:Za(this,e);break;case Z.IN_BODY:case Z.IN_CAPTION:case Z.IN_CELL:case Z.IN_TEMPLATE:eo(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:Yo(this,e);break;case Z.IN_TABLE_TEXT:cs(this,e);break;case Z.IN_COLUMN_GROUP:hs(this,e);break;case Z.AFTER_BODY:js(this,e);break;case Z.AFTER_AFTER_BODY:Ls(this,e);break;default:}}onNullCharacter(e){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){zs(this,e);return}switch(this.insertionMode){case Z.INITIAL:Ia(this,e);break;case Z.BEFORE_HTML:za(this,e);break;case Z.BEFORE_HEAD:Ha(this,e);break;case Z.IN_HEAD:Ga(this,e);break;case Z.IN_HEAD_NO_SCRIPT:Ja(this,e);break;case Z.AFTER_HEAD:Za(this,e);break;case Z.TEXT:this._insertCharacters(e);break;case Z.IN_TABLE:case Z.IN_TABLE_BODY:case Z.IN_ROW:Yo(this,e);break;case Z.IN_COLUMN_GROUP:hs(this,e);break;case Z.AFTER_BODY:js(this,e);break;case Z.AFTER_AFTER_BODY:Ls(this,e);break;default:}}onComment(e){if(this.skipNextNewLine=!1,this.currentNotInHTML){ja(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:ja(this,e);break;case Z.IN_TABLE_TEXT:ls(this,e);break;case Z.AFTER_BODY:Ma(this,e);break;case Z.AFTER_AFTER_BODY:case Z.AFTER_AFTER_FRAMESET:Na(this,e);break;default:}}onDoctype(e){switch(this.skipNextNewLine=!1,this.insertionMode){case Z.INITIAL:Fa(this,e);break;case Z.BEFORE_HEAD:case Z.IN_HEAD:case Z.IN_HEAD_NO_SCRIPT:case Z.AFTER_HEAD:this._err(e,B.misplacedDoctype);break;case Z.IN_TABLE_TEXT:ls(this,e);break;default:}}onStartTag(e){this.skipNextNewLine=!1,this.currentToken=e,this._processStartTag(e),e.selfClosing&&!e.ackSelfClosing&&this._err(e,B.nonVoidHtmlElementStartTagWithTrailingSolidus)}_processStartTag(e){this.shouldProcessStartTagTokenInForeignContent(e)?Hs(this,e):this._startTagOutsideForeignContent(e)}_startTagOutsideForeignContent(e){switch(this.insertionMode){case Z.INITIAL:Ia(this,e);break;case Z.BEFORE_HTML:La(this,e);break;case Z.BEFORE_HEAD:Ba(this,e);break;case Z.IN_HEAD:Q(this,e);break;case Z.IN_HEAD_NO_SCRIPT:Ka(this,e);break;case Z.AFTER_HEAD:Ya(this,e);break;case Z.IN_BODY:$(this,e);break;case Z.IN_TABLE:is(this,e);break;case Z.IN_TABLE_TEXT:ls(this,e);break;case Z.IN_CAPTION:ds(this,e);break;case Z.IN_COLUMN_GROUP:ps(this,e);break;case Z.IN_TABLE_BODY:gs(this,e);break;case Z.IN_ROW:vs(this,e);break;case Z.IN_CELL:bs(this,e);break;case Z.IN_SELECT:Ss(this,e);break;case Z.IN_SELECT_IN_TABLE:ws(this,e);break;case Z.IN_TEMPLATE:Es(this,e);break;case Z.AFTER_BODY:ks(this,e);break;case Z.IN_FRAMESET:Ms(this,e);break;case Z.AFTER_FRAMESET:Ps(this,e);break;case Z.AFTER_AFTER_BODY:Is(this,e);break;case Z.AFTER_AFTER_FRAMESET:Rs(this,e);break;default:}}onEndTag(e){this.skipNextNewLine=!1,this.currentToken=e,this.currentNotInHTML?Us(this,e):this._endTagOutsideForeignContent(e)}_endTagOutsideForeignContent(e){switch(this.insertionMode){case Z.INITIAL:Ia(this,e);break;case Z.BEFORE_HTML:Ra(this,e);break;case Z.BEFORE_HEAD:Va(this,e);break;case Z.IN_HEAD:Ua(this,e);break;case Z.IN_HEAD_NO_SCRIPT:qa(this,e);break;case Z.AFTER_HEAD:Xa(this,e);break;case Z.IN_BODY:Go(this,e);break;case Z.TEXT:qo(this,e);break;case Z.IN_TABLE:as(this,e);break;case Z.IN_TABLE_TEXT:ls(this,e);break;case Z.IN_CAPTION:fs(this,e);break;case Z.IN_COLUMN_GROUP:ms(this,e);break;case Z.IN_TABLE_BODY:_s(this,e);break;case Z.IN_ROW:ys(this,e);break;case Z.IN_CELL:xs(this,e);break;case Z.IN_SELECT:Cs(this,e);break;case Z.IN_SELECT_IN_TABLE:Ts(this,e);break;case Z.IN_TEMPLATE:Ds(this,e);break;case Z.AFTER_BODY:As(this,e);break;case Z.IN_FRAMESET:Ns(this,e);break;case Z.AFTER_FRAMESET:Fs(this,e);break;case Z.AFTER_AFTER_BODY:Ls(this,e);break;default:}}onEof(e){switch(this.insertionMode){case Z.INITIAL:Ia(this,e);break;case Z.BEFORE_HTML:za(this,e);break;case Z.BEFORE_HEAD:Ha(this,e);break;case Z.IN_HEAD:Ga(this,e);break;case Z.IN_HEAD_NO_SCRIPT:Ja(this,e);break;case Z.AFTER_HEAD:Za(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:Ko(this,e);break;case Z.TEXT:Jo(this,e);break;case Z.IN_TABLE_TEXT:ls(this,e);break;case Z.IN_TEMPLATE:Os(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:Pa(this,e);break;default:}}onWhitespaceCharacter(e){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,e.chars.charCodeAt(0)===R.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:$a(this,e);break;case Z.IN_TABLE:case Z.IN_TABLE_BODY:case Z.IN_ROW:Yo(this,e);break;case Z.IN_TABLE_TEXT:ss(this,e);break;default:}}};function wa(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):Wo(e,t),n}function Ta(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 Ea(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>=ya;!n||s?(s&&e.activeFormattingElements.removeEntry(n),e.openElements.remove(o)):(o=Da(e,n),r===t&&(e.activeFormattingElements.bookmark=n),e.treeAdapter.detachNode(r),e.treeAdapter.appendChild(o,r),r=o)}return r}function Da(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 Oa(e,t,n){let r=hi(e.treeAdapter.getTagName(t));if(e._isElementCausesFosterParenting(r))e._fosterParentElement(n);else{let i=e.treeAdapter.getNamespaceURI(t);r===G.TEMPLATE&&i===H.HTML&&(t=e.treeAdapter.getTemplateContent(t)),e.treeAdapter.appendChild(t,n)}}function ka(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 Aa(e,t){for(let n=0;n<va;n++){let n=wa(e,t);if(!n)break;let r=Ta(e,n);if(!r)break;e.activeFormattingElements.bookmark=n;let i=Ea(e,r,n.element),a=e.openElements.getCommonAncestor(n.element);e.treeAdapter.detachNode(i),a&&Oa(e,a,i),ka(e,r,n)}}function ja(e,t){e._appendCommentNode(t,e.openElements.currentTmplContentOrNode)}function Ma(e,t){e._appendCommentNode(t,e.openElements.items[0])}function Na(e,t){e._appendCommentNode(t,e.document)}function Pa(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 Fa(e,t){e._setDocumentType(t);let n=t.forceQuirks?U.QUIRKS:ta(t);ea(t)||e._err(t,B.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,n),e.insertionMode=Z.BEFORE_HTML}function Ia(e,t){e._err(t,B.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,U.QUIRKS),e.insertionMode=Z.BEFORE_HTML,e._processToken(t)}function La(e,t){t.tagID===G.HTML?(e._insertElement(t,H.HTML),e.insertionMode=Z.BEFORE_HEAD):za(e,t)}function Ra(e,t){let n=t.tagID;(n===G.HTML||n===G.HEAD||n===G.BODY||n===G.BR)&&za(e,t)}function za(e,t){e._insertFakeRootElement(),e.insertionMode=Z.BEFORE_HEAD,e._processToken(t)}function Ba(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.HEAD:e._insertElement(t,H.HTML),e.headElement=e.openElements.current,e.insertionMode=Z.IN_HEAD;break;default:Ha(e,t)}}function Va(e,t){let n=t.tagID;n===G.HEAD||n===G.BODY||n===G.HTML||n===G.BR?Ha(e,t):e._err(t,B.endTagWithoutMatchingOpenElement)}function Ha(e,t){e._insertFakeElement(W.HEAD,G.HEAD),e.headElement=e.openElements.current,e.insertionMode=Z.IN_HEAD,e._processToken(t)}function Q(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.BASE:case G.BASEFONT:case G.BGSOUND:case G.LINK:case G.META:e._appendElement(t,H.HTML),t.ackSelfClosing=!0;break;case G.TITLE:e._switchToTextParsing(t,J.RCDATA);break;case G.NOSCRIPT:e.options.scriptingEnabled?e._switchToTextParsing(t,J.RAWTEXT):(e._insertElement(t,H.HTML),e.insertionMode=Z.IN_HEAD_NO_SCRIPT);break;case G.NOFRAMES:case G.STYLE:e._switchToTextParsing(t,J.RAWTEXT);break;case G.SCRIPT:e._switchToTextParsing(t,J.SCRIPT_DATA);break;case G.TEMPLATE:e._insertTemplate(t),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=Z.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Z.IN_TEMPLATE);break;case G.HEAD:e._err(t,B.misplacedStartTagForHeadElement);break;default:Ga(e,t)}}function Ua(e,t){switch(t.tagID){case G.HEAD:e.openElements.pop(),e.insertionMode=Z.AFTER_HEAD;break;case G.BODY:case G.BR:case G.HTML:Ga(e,t);break;case G.TEMPLATE:Wa(e,t);break;default:e._err(t,B.endTagWithoutMatchingOpenElement)}}function Wa(e,t){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==G.TEMPLATE&&e._err(t,B.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(G.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(t,B.endTagWithoutMatchingOpenElement)}function Ga(e,t){e.openElements.pop(),e.insertionMode=Z.AFTER_HEAD,e._processToken(t)}function Ka(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.BASEFONT:case G.BGSOUND:case G.HEAD:case G.LINK:case G.META:case G.NOFRAMES:case G.STYLE:Q(e,t);break;case G.NOSCRIPT:e._err(t,B.nestedNoscriptInHead);break;default:Ja(e,t)}}function qa(e,t){switch(t.tagID){case G.NOSCRIPT:e.openElements.pop(),e.insertionMode=Z.IN_HEAD;break;case G.BR:Ja(e,t);break;default:e._err(t,B.endTagWithoutMatchingOpenElement)}}function Ja(e,t){let n=t.type===V.EOF?B.openElementsLeftAfterEof:B.disallowedContentInNoscriptInHead;e._err(t,n),e.openElements.pop(),e.insertionMode=Z.IN_HEAD,e._processToken(t)}function Ya(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.BODY:e._insertElement(t,H.HTML),e.framesetOk=!1,e.insertionMode=Z.IN_BODY;break;case G.FRAMESET:e._insertElement(t,H.HTML),e.insertionMode=Z.IN_FRAMESET;break;case G.BASE:case G.BASEFONT:case G.BGSOUND:case G.LINK:case G.META:case G.NOFRAMES:case G.SCRIPT:case G.STYLE:case G.TEMPLATE:case G.TITLE:e._err(t,B.abandonedHeadElementChild),e.openElements.push(e.headElement,G.HEAD),Q(e,t),e.openElements.remove(e.headElement);break;case G.HEAD:e._err(t,B.misplacedStartTagForHeadElement);break;default:Za(e,t)}}function Xa(e,t){switch(t.tagID){case G.BODY:case G.HTML:case G.BR:Za(e,t);break;case G.TEMPLATE:Wa(e,t);break;default:e._err(t,B.endTagWithoutMatchingOpenElement)}}function Za(e,t){e._insertFakeElement(W.BODY,G.BODY),e.insertionMode=Z.IN_BODY,Qa(e,t)}function Qa(e,t){switch(t.type){case V.CHARACTER:eo(e,t);break;case V.WHITESPACE_CHARACTER:$a(e,t);break;case V.COMMENT:ja(e,t);break;case V.START_TAG:$(e,t);break;case V.END_TAG:Go(e,t);break;case V.EOF:Ko(e,t);break;default:}}function $a(e,t){e._reconstructActiveFormattingElements(),e._insertCharacters(t)}function eo(e,t){e._reconstructActiveFormattingElements(),e._insertCharacters(t),e.framesetOk=!1}function to(e,t){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],t.attrs)}function no(e,t){let n=e.openElements.tryPeekProperlyNestedBodyElement();n&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(n,t.attrs))}function ro(e,t){let n=e.openElements.tryPeekProperlyNestedBodyElement();e.framesetOk&&n&&(e.treeAdapter.detachNode(n),e.openElements.popAllUpToHtmlElement(),e._insertElement(t,H.HTML),e.insertionMode=Z.IN_FRAMESET)}function io(e,t){e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._insertElement(t,H.HTML)}function ao(e,t){e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e.openElements.currentTagId!==void 0&&_i.has(e.openElements.currentTagId)&&e.openElements.pop(),e._insertElement(t,H.HTML)}function oo(e,t){e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._insertElement(t,H.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function so(e,t){let n=e.openElements.tmplCount>0;(!e.formElement||n)&&(e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._insertElement(t,H.HTML),n||(e.formElement=e.openElements.current))}function co(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===G.LI&&r===G.LI||(n===G.DD||n===G.DT)&&(r===G.DD||r===G.DT)){e.openElements.generateImpliedEndTagsWithExclusion(r),e.openElements.popUntilTagNamePopped(r);break}if(r!==G.ADDRESS&&r!==G.DIV&&r!==G.P&&e._isSpecialElement(e.openElements.items[t],r))break}e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._insertElement(t,H.HTML)}function lo(e,t){e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._insertElement(t,H.HTML),e.tokenizer.state=J.PLAINTEXT}function uo(e,t){e.openElements.hasInScope(G.BUTTON)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(G.BUTTON)),e._reconstructActiveFormattingElements(),e._insertElement(t,H.HTML),e.framesetOk=!1}function fo(e,t){let n=e.activeFormattingElements.getElementEntryInScopeWithTagName(W.A);n&&(Aa(e,t),e.openElements.remove(n.element),e.activeFormattingElements.removeEntry(n)),e._reconstructActiveFormattingElements(),e._insertElement(t,H.HTML),e.activeFormattingElements.pushElement(e.openElements.current,t)}function po(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,H.HTML),e.activeFormattingElements.pushElement(e.openElements.current,t)}function mo(e,t){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(G.NOBR)&&(Aa(e,t),e._reconstructActiveFormattingElements()),e._insertElement(t,H.HTML),e.activeFormattingElements.pushElement(e.openElements.current,t)}function ho(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,H.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function go(e,t){e.treeAdapter.getDocumentMode(e.document)!==U.QUIRKS&&e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._insertElement(t,H.HTML),e.framesetOk=!1,e.insertionMode=Z.IN_TABLE}function _o(e,t){e._reconstructActiveFormattingElements(),e._appendElement(t,H.HTML),e.framesetOk=!1,t.ackSelfClosing=!0}function vo(e){let t=fi(e,pi.TYPE);return t!=null&&t.toLowerCase()===_a}function yo(e,t){e._reconstructActiveFormattingElements(),e._appendElement(t,H.HTML),vo(t)||(e.framesetOk=!1),t.ackSelfClosing=!0}function bo(e,t){e._appendElement(t,H.HTML),t.ackSelfClosing=!0}function xo(e,t){e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._appendElement(t,H.HTML),e.framesetOk=!1,t.ackSelfClosing=!0}function So(e,t){t.tagName=W.IMG,t.tagID=G.IMG,_o(e,t)}function Co(e,t){e._insertElement(t,H.HTML),e.skipNextNewLine=!0,e.tokenizer.state=J.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=Z.TEXT}function wo(e,t){e.openElements.hasInButtonScope(G.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(t,J.RAWTEXT)}function To(e,t){e.framesetOk=!1,e._switchToTextParsing(t,J.RAWTEXT)}function Eo(e,t){e._switchToTextParsing(t,J.RAWTEXT)}function Do(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,H.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 Oo(e,t){e.openElements.currentTagId===G.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(t,H.HTML)}function ko(e,t){e.openElements.hasInScope(G.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(t,H.HTML)}function Ao(e,t){e.openElements.hasInScope(G.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(G.RTC),e._insertElement(t,H.HTML)}function jo(e,t){e._reconstructActiveFormattingElements(),ua(t),fa(t),t.selfClosing?e._appendElement(t,H.MATHML):e._insertElement(t,H.MATHML),t.ackSelfClosing=!0}function Mo(e,t){e._reconstructActiveFormattingElements(),da(t),fa(t),t.selfClosing?e._appendElement(t,H.SVG):e._insertElement(t,H.SVG),t.ackSelfClosing=!0}function No(e,t){e._reconstructActiveFormattingElements(),e._insertElement(t,H.HTML)}function $(e,t){switch(t.tagID){case G.I:case G.S:case G.B:case G.U:case G.EM:case G.TT:case G.BIG:case G.CODE:case G.FONT:case G.SMALL:case G.STRIKE:case G.STRONG:po(e,t);break;case G.A:fo(e,t);break;case G.H1:case G.H2:case G.H3:case G.H4:case G.H5:case G.H6:ao(e,t);break;case G.P:case G.DL:case G.OL:case G.UL:case G.DIV:case G.DIR:case G.NAV:case G.MAIN:case G.MENU:case G.ASIDE:case G.CENTER:case G.FIGURE:case G.FOOTER:case G.HEADER:case G.HGROUP:case G.DIALOG:case G.DETAILS:case G.ADDRESS:case G.ARTICLE:case G.SEARCH:case G.SECTION:case G.SUMMARY:case G.FIELDSET:case G.BLOCKQUOTE:case G.FIGCAPTION:io(e,t);break;case G.LI:case G.DD:case G.DT:co(e,t);break;case G.BR:case G.IMG:case G.WBR:case G.AREA:case G.EMBED:case G.KEYGEN:_o(e,t);break;case G.HR:xo(e,t);break;case G.RB:case G.RTC:ko(e,t);break;case G.RT:case G.RP:Ao(e,t);break;case G.PRE:case G.LISTING:oo(e,t);break;case G.XMP:wo(e,t);break;case G.SVG:Mo(e,t);break;case G.HTML:to(e,t);break;case G.BASE:case G.LINK:case G.META:case G.STYLE:case G.TITLE:case G.SCRIPT:case G.BGSOUND:case G.BASEFONT:case G.TEMPLATE:Q(e,t);break;case G.BODY:no(e,t);break;case G.FORM:so(e,t);break;case G.NOBR:mo(e,t);break;case G.MATH:jo(e,t);break;case G.TABLE:go(e,t);break;case G.INPUT:yo(e,t);break;case G.PARAM:case G.TRACK:case G.SOURCE:bo(e,t);break;case G.IMAGE:So(e,t);break;case G.BUTTON:uo(e,t);break;case G.APPLET:case G.OBJECT:case G.MARQUEE:ho(e,t);break;case G.IFRAME:To(e,t);break;case G.SELECT:Do(e,t);break;case G.OPTION:case G.OPTGROUP:Oo(e,t);break;case G.NOEMBED:case G.NOFRAMES:Eo(e,t);break;case G.FRAMESET:ro(e,t);break;case G.TEXTAREA:Co(e,t);break;case G.NOSCRIPT:e.options.scriptingEnabled?Eo(e,t):No(e,t);break;case G.PLAINTEXT:lo(e,t);break;case G.COL:case G.TH:case G.TD:case G.TR:case G.HEAD:case G.FRAME:case G.TBODY:case G.TFOOT:case G.THEAD:case G.CAPTION:case G.COLGROUP:break;default:No(e,t)}}function Po(e,t){if(e.openElements.hasInScope(G.BODY)&&(e.insertionMode=Z.AFTER_BODY,e.options.sourceCodeLocationInfo)){let n=e.openElements.tryPeekProperlyNestedBodyElement();n&&e._setEndLocation(n,t)}}function Fo(e,t){e.openElements.hasInScope(G.BODY)&&(e.insertionMode=Z.AFTER_BODY,As(e,t))}function Io(e,t){let n=t.tagID;e.openElements.hasInScope(n)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(n))}function Lo(e){let t=e.openElements.tmplCount>0,{formElement:n}=e;t||(e.formElement=null),(n||t)&&e.openElements.hasInScope(G.FORM)&&(e.openElements.generateImpliedEndTags(),t?e.openElements.popUntilTagNamePopped(G.FORM):n&&e.openElements.remove(n))}function Ro(e){e.openElements.hasInButtonScope(G.P)||e._insertFakeElement(W.P,G.P),e._closePElement()}function zo(e){e.openElements.hasInListItemScope(G.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(G.LI),e.openElements.popUntilTagNamePopped(G.LI))}function Bo(e,t){let n=t.tagID;e.openElements.hasInScope(n)&&(e.openElements.generateImpliedEndTagsWithExclusion(n),e.openElements.popUntilTagNamePopped(n))}function Vo(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function Ho(e,t){let n=t.tagID;e.openElements.hasInScope(n)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(n),e.activeFormattingElements.clearToLastMarker())}function Uo(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(W.BR,G.BR),e.openElements.pop(),e.framesetOk=!1}function Wo(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!==G.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 Go(e,t){switch(t.tagID){case G.A:case G.B:case G.I:case G.S:case G.U:case G.EM:case G.TT:case G.BIG:case G.CODE:case G.FONT:case G.NOBR:case G.SMALL:case G.STRIKE:case G.STRONG:Aa(e,t);break;case G.P:Ro(e);break;case G.DL:case G.UL:case G.OL:case G.DIR:case G.DIV:case G.NAV:case G.PRE:case G.MAIN:case G.MENU:case G.ASIDE:case G.BUTTON:case G.CENTER:case G.FIGURE:case G.FOOTER:case G.HEADER:case G.HGROUP:case G.DIALOG:case G.ADDRESS:case G.ARTICLE:case G.DETAILS:case G.SEARCH:case G.SECTION:case G.SUMMARY:case G.LISTING:case G.FIELDSET:case G.BLOCKQUOTE:case G.FIGCAPTION:Io(e,t);break;case G.LI:zo(e);break;case G.DD:case G.DT:Bo(e,t);break;case G.H1:case G.H2:case G.H3:case G.H4:case G.H5:case G.H6:Vo(e);break;case G.BR:Uo(e);break;case G.BODY:Po(e,t);break;case G.HTML:Fo(e,t);break;case G.FORM:Lo(e);break;case G.APPLET:case G.OBJECT:case G.MARQUEE:Ho(e,t);break;case G.TEMPLATE:Wa(e,t);break;default:Wo(e,t)}}function Ko(e,t){e.tmplInsertionModeStack.length>0?Os(e,t):Pa(e,t)}function qo(e,t){var n;t.tagID===G.SCRIPT&&((n=e.scriptHandler)==null||n.call(e,e.openElements.current)),e.openElements.pop(),e.insertionMode=e.originalInsertionMode}function Jo(e,t){e._err(t,B.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(t)}function Yo(e,t){if(e.openElements.currentTagId!==void 0&&xa.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 V.CHARACTER:cs(e,t);break;case V.WHITESPACE_CHARACTER:ss(e,t);break}else os(e,t)}function Xo(e,t){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(t,H.HTML),e.insertionMode=Z.IN_CAPTION}function Zo(e,t){e.openElements.clearBackToTableContext(),e._insertElement(t,H.HTML),e.insertionMode=Z.IN_COLUMN_GROUP}function Qo(e,t){e.openElements.clearBackToTableContext(),e._insertFakeElement(W.COLGROUP,G.COLGROUP),e.insertionMode=Z.IN_COLUMN_GROUP,ps(e,t)}function $o(e,t){e.openElements.clearBackToTableContext(),e._insertElement(t,H.HTML),e.insertionMode=Z.IN_TABLE_BODY}function es(e,t){e.openElements.clearBackToTableContext(),e._insertFakeElement(W.TBODY,G.TBODY),e.insertionMode=Z.IN_TABLE_BODY,gs(e,t)}function ts(e,t){e.openElements.hasInTableScope(G.TABLE)&&(e.openElements.popUntilTagNamePopped(G.TABLE),e._resetInsertionMode(),e._processStartTag(t))}function ns(e,t){vo(t)?e._appendElement(t,H.HTML):os(e,t),t.ackSelfClosing=!0}function rs(e,t){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(t,H.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function is(e,t){switch(t.tagID){case G.TD:case G.TH:case G.TR:es(e,t);break;case G.STYLE:case G.SCRIPT:case G.TEMPLATE:Q(e,t);break;case G.COL:Qo(e,t);break;case G.FORM:rs(e,t);break;case G.TABLE:ts(e,t);break;case G.TBODY:case G.TFOOT:case G.THEAD:$o(e,t);break;case G.INPUT:ns(e,t);break;case G.CAPTION:Xo(e,t);break;case G.COLGROUP:Zo(e,t);break;default:os(e,t)}}function as(e,t){switch(t.tagID){case G.TABLE:e.openElements.hasInTableScope(G.TABLE)&&(e.openElements.popUntilTagNamePopped(G.TABLE),e._resetInsertionMode());break;case G.TEMPLATE:Wa(e,t);break;case G.BODY:case G.CAPTION:case G.COL:case G.COLGROUP:case G.HTML:case G.TBODY:case G.TD:case G.TFOOT:case G.TH:case G.THEAD:case G.TR:break;default:os(e,t)}}function os(e,t){let n=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,Qa(e,t),e.fosterParentingEnabled=n}function ss(e,t){e.pendingCharacterTokens.push(t)}function cs(e,t){e.pendingCharacterTokens.push(t),e.hasNonWhitespacePendingCharacterToken=!0}function ls(e,t){let n=0;if(e.hasNonWhitespacePendingCharacterToken)for(;n<e.pendingCharacterTokens.length;n++)os(e,e.pendingCharacterTokens[n]);else for(;n<e.pendingCharacterTokens.length;n++)e._insertCharacters(e.pendingCharacterTokens[n]);e.insertionMode=e.originalInsertionMode,e._processToken(t)}var us=new Set([G.CAPTION,G.COL,G.COLGROUP,G.TBODY,G.TD,G.TFOOT,G.TH,G.THEAD,G.TR]);function ds(e,t){let n=t.tagID;us.has(n)?e.openElements.hasInTableScope(G.CAPTION)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(G.CAPTION),e.activeFormattingElements.clearToLastMarker(),e.insertionMode=Z.IN_TABLE,is(e,t)):$(e,t)}function fs(e,t){let n=t.tagID;switch(n){case G.CAPTION:case G.TABLE:e.openElements.hasInTableScope(G.CAPTION)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(G.CAPTION),e.activeFormattingElements.clearToLastMarker(),e.insertionMode=Z.IN_TABLE,n===G.TABLE&&as(e,t));break;case G.BODY:case G.COL:case G.COLGROUP:case G.HTML:case G.TBODY:case G.TD:case G.TFOOT:case G.TH:case G.THEAD:case G.TR:break;default:Go(e,t)}}function ps(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.COL:e._appendElement(t,H.HTML),t.ackSelfClosing=!0;break;case G.TEMPLATE:Q(e,t);break;default:hs(e,t)}}function ms(e,t){switch(t.tagID){case G.COLGROUP:e.openElements.currentTagId===G.COLGROUP&&(e.openElements.pop(),e.insertionMode=Z.IN_TABLE);break;case G.TEMPLATE:Wa(e,t);break;case G.COL:break;default:hs(e,t)}}function hs(e,t){e.openElements.currentTagId===G.COLGROUP&&(e.openElements.pop(),e.insertionMode=Z.IN_TABLE,e._processToken(t))}function gs(e,t){switch(t.tagID){case G.TR:e.openElements.clearBackToTableBodyContext(),e._insertElement(t,H.HTML),e.insertionMode=Z.IN_ROW;break;case G.TH:case G.TD:e.openElements.clearBackToTableBodyContext(),e._insertFakeElement(W.TR,G.TR),e.insertionMode=Z.IN_ROW,vs(e,t);break;case G.CAPTION:case G.COL:case G.COLGROUP:case G.TBODY:case G.TFOOT:case G.THEAD:e.openElements.hasTableBodyContextInTableScope()&&(e.openElements.clearBackToTableBodyContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE,is(e,t));break;default:is(e,t)}}function _s(e,t){let n=t.tagID;switch(t.tagID){case G.TBODY:case G.TFOOT:case G.THEAD:e.openElements.hasInTableScope(n)&&(e.openElements.clearBackToTableBodyContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE);break;case G.TABLE:e.openElements.hasTableBodyContextInTableScope()&&(e.openElements.clearBackToTableBodyContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE,as(e,t));break;case G.BODY:case G.CAPTION:case G.COL:case G.COLGROUP:case G.HTML:case G.TD:case G.TH:case G.TR:break;default:as(e,t)}}function vs(e,t){switch(t.tagID){case G.TH:case G.TD:e.openElements.clearBackToTableRowContext(),e._insertElement(t,H.HTML),e.insertionMode=Z.IN_CELL,e.activeFormattingElements.insertMarker();break;case G.CAPTION:case G.COL:case G.COLGROUP:case G.TBODY:case G.TFOOT:case G.THEAD:case G.TR:e.openElements.hasInTableScope(G.TR)&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY,gs(e,t));break;default:is(e,t)}}function ys(e,t){switch(t.tagID){case G.TR:e.openElements.hasInTableScope(G.TR)&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY);break;case G.TABLE:e.openElements.hasInTableScope(G.TR)&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY,_s(e,t));break;case G.TBODY:case G.TFOOT:case G.THEAD:(e.openElements.hasInTableScope(t.tagID)||e.openElements.hasInTableScope(G.TR))&&(e.openElements.clearBackToTableRowContext(),e.openElements.pop(),e.insertionMode=Z.IN_TABLE_BODY,_s(e,t));break;case G.BODY:case G.CAPTION:case G.COL:case G.COLGROUP:case G.HTML:case G.TD:case G.TH:break;default:as(e,t)}}function bs(e,t){let n=t.tagID;us.has(n)?(e.openElements.hasInTableScope(G.TD)||e.openElements.hasInTableScope(G.TH))&&(e._closeTableCell(),vs(e,t)):$(e,t)}function xs(e,t){let n=t.tagID;switch(n){case G.TD:case G.TH:e.openElements.hasInTableScope(n)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(n),e.activeFormattingElements.clearToLastMarker(),e.insertionMode=Z.IN_ROW);break;case G.TABLE:case G.TBODY:case G.TFOOT:case G.THEAD:case G.TR:e.openElements.hasInTableScope(n)&&(e._closeTableCell(),ys(e,t));break;case G.BODY:case G.CAPTION:case G.COL:case G.COLGROUP:case G.HTML:break;default:Go(e,t)}}function Ss(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.OPTION:e.openElements.currentTagId===G.OPTION&&e.openElements.pop(),e._insertElement(t,H.HTML);break;case G.OPTGROUP:e.openElements.currentTagId===G.OPTION&&e.openElements.pop(),e.openElements.currentTagId===G.OPTGROUP&&e.openElements.pop(),e._insertElement(t,H.HTML);break;case G.HR:e.openElements.currentTagId===G.OPTION&&e.openElements.pop(),e.openElements.currentTagId===G.OPTGROUP&&e.openElements.pop(),e._appendElement(t,H.HTML),t.ackSelfClosing=!0;break;case G.INPUT:case G.KEYGEN:case G.TEXTAREA:case G.SELECT:e.openElements.hasInSelectScope(G.SELECT)&&(e.openElements.popUntilTagNamePopped(G.SELECT),e._resetInsertionMode(),t.tagID!==G.SELECT&&e._processStartTag(t));break;case G.SCRIPT:case G.TEMPLATE:Q(e,t);break;default:}}function Cs(e,t){switch(t.tagID){case G.OPTGROUP:e.openElements.stackTop>0&&e.openElements.currentTagId===G.OPTION&&e.openElements.tagIDs[e.openElements.stackTop-1]===G.OPTGROUP&&e.openElements.pop(),e.openElements.currentTagId===G.OPTGROUP&&e.openElements.pop();break;case G.OPTION:e.openElements.currentTagId===G.OPTION&&e.openElements.pop();break;case G.SELECT:e.openElements.hasInSelectScope(G.SELECT)&&(e.openElements.popUntilTagNamePopped(G.SELECT),e._resetInsertionMode());break;case G.TEMPLATE:Wa(e,t);break;default:}}function ws(e,t){let n=t.tagID;n===G.CAPTION||n===G.TABLE||n===G.TBODY||n===G.TFOOT||n===G.THEAD||n===G.TR||n===G.TD||n===G.TH?(e.openElements.popUntilTagNamePopped(G.SELECT),e._resetInsertionMode(),e._processStartTag(t)):Ss(e,t)}function Ts(e,t){let n=t.tagID;n===G.CAPTION||n===G.TABLE||n===G.TBODY||n===G.TFOOT||n===G.THEAD||n===G.TR||n===G.TD||n===G.TH?e.openElements.hasInTableScope(n)&&(e.openElements.popUntilTagNamePopped(G.SELECT),e._resetInsertionMode(),e.onEndTag(t)):Cs(e,t)}function Es(e,t){switch(t.tagID){case G.BASE:case G.BASEFONT:case G.BGSOUND:case G.LINK:case G.META:case G.NOFRAMES:case G.SCRIPT:case G.STYLE:case G.TEMPLATE:case G.TITLE:Q(e,t);break;case G.CAPTION:case G.COLGROUP:case G.TBODY:case G.TFOOT:case G.THEAD:e.tmplInsertionModeStack[0]=Z.IN_TABLE,e.insertionMode=Z.IN_TABLE,is(e,t);break;case G.COL:e.tmplInsertionModeStack[0]=Z.IN_COLUMN_GROUP,e.insertionMode=Z.IN_COLUMN_GROUP,ps(e,t);break;case G.TR:e.tmplInsertionModeStack[0]=Z.IN_TABLE_BODY,e.insertionMode=Z.IN_TABLE_BODY,gs(e,t);break;case G.TD:case G.TH:e.tmplInsertionModeStack[0]=Z.IN_ROW,e.insertionMode=Z.IN_ROW,vs(e,t);break;default:e.tmplInsertionModeStack[0]=Z.IN_BODY,e.insertionMode=Z.IN_BODY,$(e,t)}}function Ds(e,t){t.tagID===G.TEMPLATE&&Wa(e,t)}function Os(e,t){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(G.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(t)):Pa(e,t)}function ks(e,t){t.tagID===G.HTML?$(e,t):js(e,t)}function As(e,t){if(t.tagID===G.HTML){if(e.fragmentContext||(e.insertionMode=Z.AFTER_AFTER_BODY),e.options.sourceCodeLocationInfo&&e.openElements.tagIDs[0]===G.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 js(e,t)}function js(e,t){e.insertionMode=Z.IN_BODY,Qa(e,t)}function Ms(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.FRAMESET:e._insertElement(t,H.HTML);break;case G.FRAME:e._appendElement(t,H.HTML),t.ackSelfClosing=!0;break;case G.NOFRAMES:Q(e,t);break;default:}}function Ns(e,t){t.tagID===G.FRAMESET&&!e.openElements.isRootHtmlElementCurrent()&&(e.openElements.pop(),!e.fragmentContext&&e.openElements.currentTagId!==G.FRAMESET&&(e.insertionMode=Z.AFTER_FRAMESET))}function Ps(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.NOFRAMES:Q(e,t);break;default:}}function Fs(e,t){t.tagID===G.HTML&&(e.insertionMode=Z.AFTER_AFTER_FRAMESET)}function Is(e,t){t.tagID===G.HTML?$(e,t):Ls(e,t)}function Ls(e,t){e.insertionMode=Z.IN_BODY,Qa(e,t)}function Rs(e,t){switch(t.tagID){case G.HTML:$(e,t);break;case G.NOFRAMES:Q(e,t);break;default:}}function zs(e,t){t.chars=`�`,e._insertCharacters(t)}function Bs(e,t){e._insertCharacters(t),e.framesetOk=!1}function Vs(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==H.HTML&&e.openElements.currentTagId!==void 0&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function Hs(e,t){if(la(t))Vs(e),e._startTagOutsideForeignContent(t);else{let n=e._getAdjustedCurrentElement(),r=e.treeAdapter.getNamespaceURI(n);r===H.MATHML?ua(t):r===H.SVG&&(pa(t),da(t)),fa(t),t.selfClosing?e._appendElement(t,r):e._insertElement(t,r),t.ackSelfClosing=!0}}function Us(e,t){if(t.tagID===G.P||t.tagID===G.BR){Vs(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)===H.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 Ws=new Set([W.AREA,W.BASE,W.BASEFONT,W.BGSOUND,W.BR,W.COL,W.EMBED,W.FRAME,W.HR,W.IMG,W.INPUT,W.KEYGEN,W.LINK,W.META,W.PARAM,W.SOURCE,W.TRACK,W.WBR]);function Gs(e,t){return t.treeAdapter.isElementNode(e)&&t.treeAdapter.getNamespaceURI(e)===H.HTML&&Ws.has(t.treeAdapter.getTagName(e))}var Ks={treeAdapter:X,scriptingEnabled:!0};function qs(e,t){let n={...Ks,...t};return Gs(e,n)?``:Js(e,n)}function Js(e,t){let n=``,r=t.treeAdapter.isElementNode(e)&&t.treeAdapter.getTagName(e)===W.TEMPLATE&&t.treeAdapter.getNamespaceURI(e)===H.HTML?t.treeAdapter.getTemplateContent(e):e,i=t.treeAdapter.getChildNodes(r);if(i)for(let e of i)n+=Ys(e,t);return n}function Ys(e,t){return t.treeAdapter.isElementNode(e)?Xs(e,t):t.treeAdapter.isTextNode(e)?Qs(e,t):t.treeAdapter.isCommentNode(e)?$s(e,t):t.treeAdapter.isDocumentTypeNode(e)?ec(e,t):``}function Xs(e,t){let n=t.treeAdapter.getTagName(e);return`<${n}${Zs(e,t)}>${Gs(e,t)?``:`${Js(e,t)}</${n}>`}`}function Zs(e,{treeAdapter:t}){let n=``;for(let r of t.getAttrList(e)){if(n+=` `,r.namespace)switch(r.namespace){case H.XML:n+=`xml:${r.name}`;break;case H.XMLNS:r.name!==`xmlns`&&(n+=`xmlns:`),n+=r.name;break;case H.XLINK:n+=`xlink:${r.name}`;break;default:n+=`${r.prefix}:${r.name}`}else n+=r.name;n+=`="${gn(r.value)}"`}return n}function Qs(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)===H.HTML&&yi(a,t.scriptingEnabled)?r:_n(r)}function $s(e,{treeAdapter:t}){return`<!--${t.getCommentNodeContent(e)}-->`}function ec(e,{treeAdapter:t}){return`<!DOCTYPE ${t.getDocumentTypeNodeName(e)}>`}function tc(e,t){return Ca.parse(e,t)}function nc(e){return`attrs`in e&&`tagName`in e}function rc(e){return nc(e)&&e.nodeName===`template`}function ic(e,t,n){e.attrs=e.attrs.filter(e=>e.name!==t),n!==void 0&&e.attrs.push({name:t,value:n})}function ac(e){if(nc(e)){ic(e,$t),ic(e,nn);let t=e.sourceCodeLocation;t&&(ic(e,$t,String(t.startLine)),ic(e,nn,String(t.endLine)))}if(`childNodes`in e)for(let t of e.childNodes)ac(t);rc(e)&&ac(e.content)}function oc(e){let t=tc(e,{sourceCodeLocationInfo:!0});ac(t);let n=t.childNodes.find(e=>nc(e)&&e.tagName===`html`);return n&&ic(n,en,String(Qt(e))),qs(t)}var sc=[[`img`,`src`],[`script`,`src`],[`link[rel~="stylesheet" i]`,`href`],[`link[rel~="icon" i]`,`href`],[`source`,`src`],[`video`,`src`],[`video`,`poster`],[`audio`,`src`]],cc=[`img[srcset]`,`source[srcset]`],lc=20*1024*1024;async function uc(e,t,n,r,i,a,o,s){let c=new DOMParser().parseFromString(oc(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)}ei(c)&&await dc(c);let l=[];for(let[n,i]of sc)for(let o of c.querySelectorAll(n)){let n=Bt(t,o.getAttribute(i)??``);n&&(o.removeAttribute(i),l.push(fc(e,n,r,a).then(e=>{e&&o.setAttribute(i,e)})))}for(let n of cc)for(let i of c.querySelectorAll(n)){let n=Vt(i.getAttribute(`srcset`)??``),o=n.map(({ref:e})=>Bt(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 fc(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`,Lt(t))})))}return await Promise.all(l),o&&Hr(c,o),s&&Zr(c,s),`<!doctype html>${c.documentElement.outerHTML}`}async function dc(e){let{default:t}=await T(async()=>{let{default:e}=await import(`./_virtual_katex-inline-css-DN-_JSKR.js`);return{default:e}},[]),n=e.createElement(`style`);n.textContent=`${t}\n${cn}`,(e.head??e.documentElement).appendChild(n)}function fc(e,t,n,r){let i=n.get(t);if(i)return i;let a=fr(e,t,r).then(async e=>e.size>lc?null:`data:${pc(t,e.type)};base64,${mc(await e.arrayBuffer())}`).catch(()=>null);return n.set(t,a),a}function pc(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 mc(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 hc({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=Yt(`html`,[e,r,t]),[d,f]=(0,P.useState)(null),p=(0,P.useRef)(new Map),m=x().editorFontSize,h=(0,P.useRef)(null),[g]=(0,P.useState)(Ir),[_]=(0,P.useState)(Ir),v=Ze({shortcutEnabled:s,onFind:(e,t,n)=>Jr(h.current?.contentWindow??null,_,e,t,n),onClear:()=>Yr(h.current?.contentWindow??null,_),onCloseFocus:()=>h.current?.focus()}),y=(0,P.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),b=(0,P.useMemo)(()=>Qt(n),[n]);return(0,P.useEffect)(()=>{let i=!1;return uc(e,t,n,p.current,m,r,g,_).then(e=>{i||f(e)}),()=>{i=!0}},[e,t,n,m,r,g,_,l]),(0,P.useEffect)(()=>{let e=e=>{let t=qr(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,P.useEffect)(()=>{if(a)return it.subscribe(o,y,e=>{Br(h.current?.contentWindow??null,g,e)})},[a,o,y,g]),(0,P.useEffect)(()=>{let e=e=>{let t=Rr(e,h.current?.contentWindow??null,g);if(t)if(t.layout&&(a||!t.scrolled)){let e=(a?it.get(o,y):void 0)??at.get(u);if(e&&Br(h.current?.contentWindow??null,g,e),i){let n=e??t;it.publish(o,y,n.ratio,n.sourceLine)}}else at.set(u,{ratio:t.ratio,sourceLine:t.sourceLine,revision:0}),i&&it.publish(o,y,t.ratio,t.sourceLine);let n=c?zr(e,h.current?.contentWindow??null,g):null;n&&c?.({line:Kn(n.line,b)})};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[i,a,o,y,g,c,b,u]),d===null?null:(0,F.jsxs)(`div`,{className:`relative size-full bg-paper`,children:[(0,F.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?it.get(o,y):void 0)??at.get(u);e&&Br(h.current?.contentWindow??null,g,e)}v.refresh()}},l?d:void 0),(0,F.jsx)(Gn,{controls:v})]})}function gc({kind:e,...t}){return e===`notebook`?(0,F.jsx)(Er,{...t}):e===`markdown`?(0,F.jsx)(jr,{...t}):(0,F.jsx)(hc,{...t})}function _c({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}=_e(),f=ht(e,t,null,r,{passive:n!==`notebook`,live:!0,focused:i}),p=f.model,m=(0,P.useSyncExternalStore)(n=>rn(an(e,t,r),n),()=>p?.getValue()??null);return f.conflict&&f.conflict.phase!==`unresolved`?(0,F.jsx)(pt,{session:e,path:t,buffer:f,focused:i}):m===null?(0,F.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,F.jsx)(Er,{session:e,path:t,root:r,text:m,focused:i,onOpenFile:t=>d(e,t,void 0,{...Rt(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=Ln(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,F.jsx)(gc,{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,{...Rt(t)?{view:`preview`}:{},...r===void 0?{}:{root:r}})})}var vc=(0,P.lazy)(()=>T(()=>import(`./PdfViewer-DLCPKybn.js`).then(e=>({default:e.PdfViewer})),__vite__mapDeps([12,1,2,3,9,11,6,7,13,14,15,16,17,18,19,20,21,22,23,24])));function yc({session:e,path:t,kind:n,root:r,generatedBy:i,refreshKey:a,onRevealSource:o,readOnly:s=!1}){let{asset:c,error:l}=Sc(e,t,r,We(e,t,r),a);if(l)return(0,F.jsxs)(bc,{children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:l}),!s&&(0,F.jsx)(xc,{session:e,path:t,root:r})]});if(!c)return(0,F.jsx)(bc,{children:(0,F.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`…`})});let{url:u,blob:d}=c;return n===`image`?(0,F.jsx)(bc,{children:(0,F.jsx)(`img`,{src:u,alt:t,className:`max-h-full max-w-full object-contain`})}):n===`video`?(0,F.jsx)(bc,{children:(0,F.jsx)(`video`,{src:u,controls:!0,className:`max-h-full max-w-full`})}):n===`audio`?(0,F.jsx)(bc,{children:(0,F.jsx)(`audio`,{src:u,controls:!0,className:`w-full max-w-xl`})}):(0,F.jsx)(P.Suspense,{fallback:(0,F.jsx)(bc,{children:(0,F.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`Loading PDF…`})}),children:(0,F.jsx)(vc,{blob:d,session:e,path:t,root:r,onRevealSource:!s&&wc(t,r,i)?o:void 0,onDownload:s?void 0:()=>void Cc(e,t,r)})})}function bc({children:e}){return(0,F.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 xc({session:e,path:t,root:n}){return(0,F.jsx)(`button`,{type:`button`,onClick:()=>void Cc(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 Sc(e,t,n,r=0,i){let[a,o]=(0,P.useState)(null),[s,c]=(0,P.useState)(null);return(0,P.useEffect)(()=>{let r=null,i=!1;return o(null),c(null),fr(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 Cc(e,t,n){return fe(e,t,n).catch(e=>{be.error(e instanceof Error?e.message:`Download failed`)})}function wc(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 Tc({tab:e,children:t}){let n=te(),r=n?Ht(n):null,i=(0,P.useSyncExternalStore)((0,P.useCallback)(e=>r?.subscribe(e)??(()=>{}),[r]),()=>r?.buffer(e)),a=me(e.session,e.path,{root:e.root,enabled:!1}),o=Pe(n,e.path,!1),s=zt(e)===`untitled`?o:a;return!i||!s.error?t:(0,F.jsxs)(`div`,{className:`h-full overflow-auto p-4`,role:`region`,"aria-label":`Recovered draft`,children:[(0,F.jsx)(`p`,{className:`mb-2 text-sm text-fg-muted`,children:`The original file or draft is unavailable. Your unsaved text is retained in this window.`}),(0,F.jsx)(Oe,{variant:`ghost`,onClick:()=>void s.refetch(),children:`Retry original`}),(0,F.jsx)(Ke,{draft:i})]})}function Ec({tab:e,reveal:t,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a,onRevealSource:o,onRevealCompiledSource:s,onRunCompilation:c,compilationRunning:l}){let u=zt(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}`:It(e);if(u===`diff`)return(0,F.jsx)(Sn,{session:e.session,path:e.path,root:e.root,area:e.git_area,focused:n},It(e));if(u===`commit`&&e.sha)return(0,F.jsx)(xn,{session:e.session,sha:e.sha,path:e.path,root:e.root},It(e));if(u===`external`&&e.root!==void 0){let u=ze(e.path);if(u)return(0,F.jsx)(yc,{session:e.session,path:e.path,kind:u,root:e.root,generatedBy:e.generated_by,onRevealSource:s},It(e));let p=d?Rt(e.path):null;return p?(0,F.jsx)(_c,{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,F.jsx)(ft,{session:e.session,path:e.path,reveal:t,root:e.root,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a},It(e))}if(u===`untitled`)return(0,F.jsx)(wn,{name:e.path},It(e));let p=ze(e.path);if(p)return(0,F.jsx)(yc,{session:e.session,path:e.path,kind:p,generatedBy:e.generated_by,onRevealSource:s},It(e));let m=d?Rt(e.path):null;return m?(0,F.jsx)(_c,{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,F.jsx)(ft,{session:e.session,path:e.path,reveal:t,focused:n,scrollDriver:r,scrollReceiver:i,scrollChannel:a},It(e))}function Dc(e){let t=(0,F.jsx)(Ec,{...e});return(0,F.jsx)(Jt,{tab:e.tab,children:ne()&&zt(e.tab)!==`commit`?(0,F.jsx)(Tc,{tab:e.tab,children:t}):t})}export{Dc as PaneEditorBody};
|