diff --git a/apps/app/src/components/thread/terminal/TerminalLinkOpenDialog.test.tsx b/apps/app/src/components/thread/terminal/TerminalLinkOpenDialog.test.tsx new file mode 100644 index 0000000000..b1d5de4e46 --- /dev/null +++ b/apps/app/src/components/thread/terminal/TerminalLinkOpenDialog.test.tsx @@ -0,0 +1,52 @@ +// @vitest-environment jsdom + +import { cleanup, fireEvent, render, screen } from "@testing-library/react"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { TerminalLinkOpenDialog } from "./TerminalLinkOpenDialog"; + +const TARGET = { + source: "osc8" as const, + uri: "https://example.com/hidden-target?token=visible", +}; + +afterEach(cleanup); + +describe("TerminalLinkOpenDialog", () => { + it("discloses the exact target and cancels without opening it", () => { + const onConfirm = vi.fn(); + const onOpenChange = vi.fn(); + + render( + , + ); + + expect(screen.getByRole("dialog")).toBeTruthy(); + expect(screen.getByLabelText("Link target").textContent).toBe(TARGET.uri); + + fireEvent.click(screen.getByRole("button", { name: "Cancel" })); + + expect(onOpenChange).toHaveBeenCalledWith(false); + expect(onConfirm).not.toHaveBeenCalled(); + }); + + it("confirms the exact disclosed target", () => { + const onConfirm = vi.fn(); + + render( + , + ); + + fireEvent.click(screen.getByRole("button", { name: "Open" })); + + expect(onConfirm).toHaveBeenCalledOnce(); + expect(onConfirm).toHaveBeenCalledWith(TARGET); + }); +}); diff --git a/apps/app/src/components/thread/terminal/TerminalLinkOpenDialog.tsx b/apps/app/src/components/thread/terminal/TerminalLinkOpenDialog.tsx new file mode 100644 index 0000000000..4fe17b3c1e --- /dev/null +++ b/apps/app/src/components/thread/terminal/TerminalLinkOpenDialog.tsx @@ -0,0 +1,58 @@ +import { Button } from "@bb/shared-ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@bb/shared-ui/dialog"; +import type { TerminalLinkTarget } from "./terminal-links"; + +interface TerminalLinkOpenDialogProps { + onConfirm: (target: TerminalLinkTarget) => void; + onOpenChange: (open: boolean) => void; + target: TerminalLinkTarget | null; +} + +export function TerminalLinkOpenDialog({ + onConfirm, + onOpenChange, + target, +}: TerminalLinkOpenDialogProps) { + return ( + + + {target ? ( + <> + + Open terminal link? + + Terminal output can disguise a link destination. Check the + address before opening it. + + +
+ {target.uri} +
+ + + + + + ) : null} +
+
+ ); +} diff --git a/apps/app/src/components/thread/terminal/ThreadTerminalView.test.ts b/apps/app/src/components/thread/terminal/ThreadTerminalView.test.ts index 4bc9fb75af..a921d87902 100644 --- a/apps/app/src/components/thread/terminal/ThreadTerminalView.test.ts +++ b/apps/app/src/components/thread/terminal/ThreadTerminalView.test.ts @@ -3,6 +3,7 @@ import { Terminal } from "@xterm/xterm"; import { describe, expect, it, vi } from "vitest"; import { buildTerminalThemeFromCssColors, + captureTerminalContextMenuState, decodeTerminalOutputBytes, encodeTerminalInputChunks, focusTerminalFromTouchRelease, @@ -17,6 +18,106 @@ import { writeTerminalOutput, updateTerminalTouchFocusGesture, } from "./ThreadTerminalView"; +import { + createTerminalOsc8LinkHandler, + requestTerminalLinkOpen, +} from "./terminal-links"; + +describe("terminal hyperlinks", () => { + it("preserves OSC-8 provenance through hover and primary activation", () => { + const onActivate = vi.fn(); + const onHover = vi.fn(); + const handler = createTerminalOsc8LinkHandler({ + onActivate, + onHover, + }); + const event = { button: 0 } as MouseEvent; + const range = { + start: { x: 1, y: 1 }, + end: { x: 1, y: 1 }, + }; + + handler.hover?.(event, "https://example.com/authorize", range); + handler.activate(event, "https://example.com/authorize", range); + handler.leave?.(event, "https://example.com/authorize", range); + + expect(onActivate).toHaveBeenCalledWith({ + source: "osc8", + uri: "https://example.com/authorize", + }); + expect(onHover).toHaveBeenNthCalledWith(1, { + source: "osc8", + uri: "https://example.com/authorize", + }); + expect(onHover).toHaveBeenNthCalledWith(2, null); + }); + + it("does not activate OSC-8 links from a secondary click", () => { + const onActivate = vi.fn(); + const handler = createTerminalOsc8LinkHandler({ + onActivate, + onHover: vi.fn(), + }); + const range = { + start: { x: 1, y: 1 }, + end: { x: 1, y: 1 }, + }; + + handler.activate( + { button: 2 } as MouseEvent, + "https://example.com/right-click", + range, + ); + + expect(onActivate).not.toHaveBeenCalled(); + }); + + it("confirms concealed targets and directly opens detected URLs", () => { + const openLink = vi.fn(); + const requestConfirmation = vi.fn(); + + requestTerminalLinkOpen({ + openLink, + requestConfirmation, + target: { source: "osc8", uri: "https://example.com/concealed" }, + }); + requestTerminalLinkOpen({ + openLink, + requestConfirmation, + target: { + source: "detected-url", + uri: "https://example.com/visible", + }, + }); + + expect(requestConfirmation).toHaveBeenCalledOnce(); + expect(requestConfirmation).toHaveBeenCalledWith({ + source: "osc8", + uri: "https://example.com/concealed", + }); + expect(openLink).toHaveBeenCalledOnce(); + expect(openLink).toHaveBeenCalledWith("https://example.com/visible"); + }); + + it("preserves link actions while copying the exact xterm selection", () => { + const getSelection = vi.fn(() => " wrapped terminal selection\n"); + const link = { + source: "detected-url" as const, + uri: "https://example.com/visible", + }; + + expect( + captureTerminalContextMenuState({ + link, + terminal: { getSelection }, + }), + ).toEqual({ + link, + selectionText: " wrapped terminal selection\n", + }); + expect(getSelection).toHaveBeenCalledOnce(); + }); +}); function startTouchFocusGesture() { const gesture = startTerminalTouchFocusGesture( diff --git a/apps/app/src/components/thread/terminal/ThreadTerminalView.tsx b/apps/app/src/components/thread/terminal/ThreadTerminalView.tsx index 88e1aa1dd0..561e1da4b9 100644 --- a/apps/app/src/components/thread/terminal/ThreadTerminalView.tsx +++ b/apps/app/src/components/thread/terminal/ThreadTerminalView.tsx @@ -14,6 +14,13 @@ import type { Terminal as XTermTerminal, } from "@xterm/xterm"; import type { FitAddon } from "@xterm/addon-fit"; +import { + ContextMenu, + ContextMenuContent, + ContextMenuItem, + ContextMenuSeparator, + ContextMenuTrigger, +} from "@bb/shared-ui/context-menu"; import { TERMINAL_DATA_MAX_BYTES } from "@bb/domain"; import type { TerminalServerMessage, @@ -24,10 +31,17 @@ import { usePreferredTheme } from "@/hooks/useTheme"; import type { MarkdownPreviewLinkHandler } from "@/components/ui/markdown-link"; import { openUrlInExternalBrowser } from "@/lib/url-open-routing"; import { useAppNavigationHost } from "@/lib/app-navigation-host"; +import { copyToClipboardWithToast } from "@/lib/clipboard"; import type { MessageProseSelection } from "@/components/thread/timeline/SelectableMessageProse.js"; import { TimelineSelectionMenu } from "@/components/thread/timeline/TimelineSelectionMenu.js"; import { buildTerminalWebSocketUrl } from "./terminal-websocket-url"; import { TerminalWebSocketTransport } from "@bb/client-core"; +import { TerminalLinkOpenDialog } from "./TerminalLinkOpenDialog"; +import { + createTerminalOsc8LinkHandler, + requestTerminalLinkOpen, + type TerminalLinkTarget, +} from "./terminal-links"; export const TERMINAL_FONT_FAMILY = '"JetBrainsMono Nerd Font Mono", "MesloLGS NF", "Symbols Nerd Font Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'; @@ -323,11 +337,20 @@ interface ForwardTerminalDataArgs { } interface OpenTerminalWebLinkArgs { - event: MouseEvent; onOpenLink: MarkdownPreviewLinkHandler; uri: string; } +interface TerminalContextMenuState { + link: TerminalLinkTarget | null; + selectionText: string; +} + +interface CaptureTerminalContextMenuStateArgs { + link: TerminalLinkTarget | null; + terminal: Pick | null; +} + interface TerminalReplayWriteState { suppressedWriteCount: number; } @@ -515,17 +538,27 @@ function writeTerminalSessionStatusNotice({ } function openTerminalWebLink({ - event, onOpenLink, uri, }: OpenTerminalWebLinkArgs): void { if (onOpenLink({ href: uri })) { - event.preventDefault(); return; } openUrlInExternalBrowser(uri); } +export function captureTerminalContextMenuState({ + link, + terminal, +}: CaptureTerminalContextMenuStateArgs): TerminalContextMenuState { + return { + link, + // xterm owns terminal selection semantics, including joining soft-wrapped + // rows. The DOM selection only represents one rendered canvas row. + selectionText: terminal?.getSelection() ?? "", + }; +} + export function writeTerminalOutput({ data, isReplay, @@ -601,8 +634,18 @@ export function ThreadTerminalView({ }: ThreadTerminalViewProps) { const [activeSelection, setActiveSelection] = useState(null); + const [hoveredTerminalLink, setHoveredTerminalLink] = + useState(null); + const [pendingTerminalLink, setPendingTerminalLink] = + useState(null); + const [contextMenuState, setContextMenuState] = + useState({ + link: null, + selectionText: "", + }); const containerRef = useRef(null); const terminalRef = useRef(null); + const hoveredTerminalLinkRef = useRef(null); const pointerIsDownRef = useRef(false); const pointerStartPointRef = useRef( null, @@ -673,6 +716,59 @@ export function ThreadTerminalView({ setActiveSelection(null); }, []); + const updateHoveredTerminalLink = useCallback( + (target: TerminalLinkTarget | null) => { + hoveredTerminalLinkRef.current = target; + setHoveredTerminalLink(target); + }, + [], + ); + + const openTerminalLink = useCallback((uri: string) => { + openTerminalWebLink({ + onOpenLink: onOpenLinkRef.current, + uri, + }); + }, []); + + const confirmTerminalLinkOpen = useCallback( + (target: TerminalLinkTarget) => { + setPendingTerminalLink(null); + openTerminalLink(target.uri); + }, + [openTerminalLink], + ); + + const requestOpenTerminalLink = useCallback( + (target: TerminalLinkTarget) => { + requestTerminalLinkOpen({ + openLink: openTerminalLink, + requestConfirmation: setPendingTerminalLink, + target, + }); + }, + [openTerminalLink], + ); + + const handleTerminalContextMenu = useCallback(() => { + setContextMenuState( + captureTerminalContextMenuState({ + link: hoveredTerminalLinkRef.current, + terminal: terminalRef.current, + }), + ); + }, []); + + const copyTerminalContextValue = useCallback( + (text: string, successMessage: string) => { + void copyToClipboardWithToast(text, { + successMessage, + errorMessage: "Failed to copy", + }); + }, + [], + ); + const handleSelectionAddToChat = useCallback( (text: string) => { onSelectionAddToChat?.(text); @@ -758,7 +854,10 @@ export function ThreadTerminalView({ useEffect(() => { touchFocusGestureRef.current = null; setActiveSelection(null); - }, [session.id]); + updateHoveredTerminalLink(null); + setPendingTerminalLink(null); + setContextMenuState({ link: null, selectionText: "" }); + }, [session.id, updateHoveredTerminalLink]); useEffect(() => { const container = containerRef.current; @@ -804,12 +903,22 @@ export function ThreadTerminalView({ return; } + const osc8LinkHandler = createTerminalOsc8LinkHandler({ + onActivate: requestOpenTerminalLink, + onHover: (target) => { + if (!disposed) { + updateHoveredTerminalLink(target); + } + }, + }); + terminal = new Terminal({ allowProposedApi: TERMINAL_ALLOW_PROPOSED_API, convertEol: true, cursorBlink: true, fontFamily: TERMINAL_FONT_FAMILY, fontSize: 12, + linkHandler: osc8LinkHandler, scrollback: 10_000, theme: buildTerminalTheme(), }); @@ -819,13 +928,22 @@ export function ThreadTerminalView({ terminal.loadAddon(new Unicode11Addon()); terminal.unicode.activeVersion = TERMINAL_UNICODE_VERSION; terminal.loadAddon( - new WebLinksAddon((event, uri) => { - openTerminalWebLink({ - event, - onOpenLink: onOpenLinkRef.current, - uri, - }); - }), + new WebLinksAddon( + (event, uri) => { + if (event.button !== 0) { + return; + } + requestOpenTerminalLink({ source: "detected-url", uri }); + }, + { + hover: (_event, uri) => { + updateHoveredTerminalLink({ source: "detected-url", uri }); + }, + leave: () => { + updateHoveredTerminalLink(null); + }, + }, + ), ); // The DOM renderer measures every newly encountered glyph with // synchronous layout reads. Register WebGL before opening xterm so the @@ -1012,7 +1130,13 @@ export function ThreadTerminalView({ terminalRef.current = null; scheduleFitRef.current = null; }; - }, [reportTerminalSelection, session.id, session.threadId]); + }, [ + reportTerminalSelection, + requestOpenTerminalLink, + session.id, + session.threadId, + updateHoveredTerminalLink, + ]); useEffect(() => { if (!isPanelOpen || !autoFocus) { @@ -1046,21 +1170,70 @@ export function ThreadTerminalView({ terminal.options.theme = buildTerminalTheme(); }, [preferredTheme, appThemeEpoch]); + const contextMenuLink = contextMenuState.link; + const contextMenuSelectionText = contextMenuState.selectionText; + const hasTerminalContextMenuTarget = + hoveredTerminalLink !== null || activeSelection !== null; + return ( -
{ + if (!open) { + setContextMenuState({ link: null, selectionText: "" }); + } + }} > -
+ +
+
+
+ + + {contextMenuLink !== null ? ( + <> + requestOpenTerminalLink(contextMenuLink)} + > + Open Link + + + copyTerminalContextValue(contextMenuLink.uri, "Link copied") + } + > + Copy Link + + + ) : null} + {contextMenuLink !== null && contextMenuSelectionText.length > 0 ? ( + + ) : null} + {contextMenuSelectionText.length > 0 ? ( + + copyTerminalContextValue( + contextMenuSelectionText, + "Selection copied", + ) + } + > + Copy + + ) : null} + -
+ { + if (!open) { + setPendingTerminalLink(null); + } + }} + /> + ); } diff --git a/apps/app/src/components/thread/terminal/terminal-links.ts b/apps/app/src/components/thread/terminal/terminal-links.ts new file mode 100644 index 0000000000..dd5e573cbb --- /dev/null +++ b/apps/app/src/components/thread/terminal/terminal-links.ts @@ -0,0 +1,53 @@ +import type { ILinkHandler } from "@xterm/xterm"; + +export interface TerminalLinkTarget { + source: "detected-url" | "osc8"; + uri: string; +} + +interface CreateTerminalOsc8LinkHandlerArgs { + onActivate: (target: TerminalLinkTarget) => void; + onHover: (target: TerminalLinkTarget | null) => void; +} + +interface RequestTerminalLinkOpenArgs { + openLink: (uri: string) => void; + requestConfirmation: (target: TerminalLinkTarget) => void; + target: TerminalLinkTarget; +} + +export function createTerminalOsc8LinkHandler({ + onActivate, + onHover, +}: CreateTerminalOsc8LinkHandlerArgs): ILinkHandler { + return { + activate: (event, uri) => { + if (event.button !== 0) { + return; + } + onActivate({ source: "osc8", uri }); + }, + hover: (_event, uri) => { + onHover({ source: "osc8", uri }); + }, + leave: () => { + onHover(null); + }, + }; +} + +/** + * OSC-8 display text can conceal its target, so require confirmation before + * opening it. Detected URLs already display the same address they will open. + */ +export function requestTerminalLinkOpen({ + openLink, + requestConfirmation, + target, +}: RequestTerminalLinkOpenArgs): void { + if (target.source === "osc8") { + requestConfirmation(target); + return; + } + openLink(target.uri); +} diff --git a/apps/host-daemon/src/terminals/terminal-manager.test.ts b/apps/host-daemon/src/terminals/terminal-manager.test.ts index 31c48d0a8c..d84cf1f1b3 100644 --- a/apps/host-daemon/src/terminals/terminal-manager.test.ts +++ b/apps/host-daemon/src/terminals/terminal-manager.test.ts @@ -410,6 +410,7 @@ describe("TerminalManager", () => { BB_TERMINAL_SESSION_ID: "term-1", COLORTERM: "truecolor", DISABLE_AUTO_TITLE: "true", + FORCE_HYPERLINK: "1", PROMPT_EOL_MARK: "", TERM: "xterm-256color", }); diff --git a/apps/host-daemon/src/terminals/terminal-manager.ts b/apps/host-daemon/src/terminals/terminal-manager.ts index 9976be7012..950aa4c5c8 100644 --- a/apps/host-daemon/src/terminals/terminal-manager.ts +++ b/apps/host-daemon/src/terminals/terminal-manager.ts @@ -356,6 +356,11 @@ function buildTerminalEnv(args: BuildTerminalEnvArgs): NodeJS.ProcessEnv { BB_TERMINAL_SESSION_ID: args.terminalId, COLORTERM: "truecolor", DISABLE_AUTO_TITLE: "true", + // xterm renders OSC-8 hyperlinks and bb owns their activation. Programs + // that honor this opt-in preserve the target instead of flattening links + // into display text. The inherited override also applies to redirected + // commands; callers that require plain output can set it to 0. + FORCE_HYPERLINK: "1", // zsh emits a highlighted "%" by default when a prompt follows output // without a newline. It becomes noisy when scrollback is replayed. PROMPT_EOL_MARK: "", diff --git a/apps/mobile/assets/terminal/index.html b/apps/mobile/assets/terminal/index.html index 5c556d4a2c..6c5b8ca60a 100644 --- a/apps/mobile/assets/terminal/index.html +++ b/apps/mobile/assets/terminal/index.html @@ -350,7 +350,7 @@ `+e.stack):new Error(e.message+` -`+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}},tn=new en;function jt(e){sn(e)||tn.onUnexpectedError(e)}var Zt="Canceled";function sn(e){return e instanceof rn?!0:e instanceof Error&&e.name===Zt&&e.message===Zt}var rn=class extends Error{constructor(){super(Zt),this.name=this.message}},ns=class Qt extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof Qt)return t;let i=new Qt;return i.message=t.message,i.stack=t.stack,i}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}};function nn(e,t){let i=this,s=!1,r;return function(){if(s)return r;if(s=!0,t)try{r=e.apply(i,arguments)}finally{t()}else r=e.apply(i,arguments);return r}}function on(e,t,i=0,s=e.length){let r=i,n=s;for(;r{function t(n){return n<0}e.isLessThan=t;function i(n){return n<=0}e.isLessThanOrEqual=i;function s(n){return n>0}e.isGreaterThan=s;function r(n){return n===0}e.isNeitherLessOrGreaterThan=r,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(fs||={});function hn(e,t){return(i,s)=>t(e(i),e(s))}var ln=(e,t)=>e-t,os=class ei{constructor(t){this.iterate=t}forEach(t){this.iterate(i=>(t(i),!0))}toArray(){let t=[];return this.iterate(i=>(t.push(i),!0)),t}filter(t){return new ei(i=>this.iterate(s=>t(s)?i(s):!0))}map(t){return new ei(i=>this.iterate(s=>i(t(s))))}some(t){let i=!1;return this.iterate(s=>(i=t(s),!i)),i}findFirst(t){let i;return this.iterate(s=>t(s)?(i=s,!1):!0),i}findLast(t){let i;return this.iterate(s=>(t(s)&&(i=s),!0)),i}findLastMaxBy(t){let i,s=!0;return this.iterate(r=>((s||fs.isGreaterThan(t(r,i)))&&(s=!1,i=r),!0)),i}};os.empty=new os(e=>{});function cn(e,t){let i=Object.create(null);for(let s of e){let r=t(s),n=i[r];n||(n=i[r]=[]),n.push(s)}return i}var as,hs,gh=class{constructor(e,t){this.toKey=t,this._map=new Map,this[as]="SetWithKey";for(let i of e)this.add(i)}get size(){return this._map.size}add(e){let t=this.toKey(e);return this._map.set(t,e),this}delete(e){return this._map.delete(this.toKey(e))}has(e){return this._map.has(this.toKey(e))}*entries(){for(let e of this._map.values())yield[e,e]}keys(){return this.values()}*values(){for(let e of this._map.values())yield e}clear(){this._map.clear()}forEach(e,t){this._map.forEach(i=>e.call(t,i,i,this))}[(hs=Symbol.iterator,as=Symbol.toStringTag,hs)](){return this.values()}},dn=class{constructor(){this.map=new Map}add(e,t){let i=this.map.get(e);i||(i=new Set,this.map.set(e,i)),i.add(t)}delete(e,t){let i=this.map.get(e);i&&(i.delete(t),i.size===0&&this.map.delete(e))}forEach(e,t){let i=this.map.get(e);i&&i.forEach(t)}get(e){return this.map.get(e)||new Set}},ps;(e=>{function t(B){return B&&typeof B=="object"&&typeof B[Symbol.iterator]=="function"}e.is=t;let i=Object.freeze([]);function s(){return i}e.empty=s;function*r(B){yield B}e.single=r;function n(B){return t(B)?B:r(B)}e.wrap=n;function o(B){return B||i}e.from=o;function*h(B){for(let T=B.length-1;T>=0;T--)yield B[T]}e.reverse=h;function l(B){return!B||B[Symbol.iterator]().next().done===!0}e.isEmpty=l;function a(B){return B[Symbol.iterator]().next().value}e.first=a;function c(B,T){let A=0;for(let ee of B)if(T(ee,A++))return!0;return!1}e.some=c;function d(B,T){for(let A of B)if(T(A))return A}e.find=d;function*u(B,T){for(let A of B)T(A)&&(yield A)}e.filter=u;function*f(B,T){let A=0;for(let ee of B)yield T(ee,A++)}e.map=f;function*_(B,T){let A=0;for(let ee of B)yield*T(ee,A++)}e.flatMap=_;function*p(...B){for(let T of B)yield*T}e.concat=p;function S(B,T,A){let ee=A;for(let Ce of B)ee=T(ee,Ce);return ee}e.reduce=S;function*k(B,T,A=B.length){for(T<0&&(T+=B.length),A<0?A+=B.length:A>B.length&&(A=B.length);Ti.source!==null&&!this.getRootParent(i,t).isSingleton).flatMap(([i])=>i)}computeLeakingDisposables(t=10,i){let s;if(i)s=i;else{let l=new Map,a=[...this.livingDisposables.values()].filter(d=>d.source!==null&&!this.getRootParent(d,l).isSingleton);if(a.length===0)return;let c=new Set(a.map(d=>d.value));if(s=a.filter(d=>!(d.parent&&c.has(d.parent))),s.length===0)throw new Error("There are cyclic diposable chains!")}if(!s)return;function r(l){function a(d,u){for(;d.length>0&&u.some(f=>typeof f=="string"?f===d[0]:d[0].match(f));)d.shift()}let c=l.source.split(` +`+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}},tn=new en;function jt(e){sn(e)||tn.onUnexpectedError(e)}var Zt="Canceled";function sn(e){return e instanceof rn?!0:e instanceof Error&&e.name===Zt&&e.message===Zt}var rn=class extends Error{constructor(){super(Zt),this.name=this.message}},ns=class Qt extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof Qt)return t;let i=new Qt;return i.message=t.message,i.stack=t.stack,i}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}};function nn(e,t){let i=this,s=!1,r;return function(){if(s)return r;if(s=!0,t)try{r=e.apply(i,arguments)}finally{t()}else r=e.apply(i,arguments);return r}}function on(e,t,i=0,s=e.length){let r=i,n=s;for(;r{function t(n){return n<0}e.isLessThan=t;function i(n){return n<=0}e.isLessThanOrEqual=i;function s(n){return n>0}e.isGreaterThan=s;function r(n){return n===0}e.isNeitherLessOrGreaterThan=r,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(fs||={});function hn(e,t){return(i,s)=>t(e(i),e(s))}var ln=(e,t)=>e-t,os=class ei{constructor(t){this.iterate=t}forEach(t){this.iterate(i=>(t(i),!0))}toArray(){let t=[];return this.iterate(i=>(t.push(i),!0)),t}filter(t){return new ei(i=>this.iterate(s=>t(s)?i(s):!0))}map(t){return new ei(i=>this.iterate(s=>i(t(s))))}some(t){let i=!1;return this.iterate(s=>(i=t(s),!i)),i}findFirst(t){let i;return this.iterate(s=>t(s)?(i=s,!1):!0),i}findLast(t){let i;return this.iterate(s=>(t(s)&&(i=s),!0)),i}findLastMaxBy(t){let i,s=!0;return this.iterate(r=>((s||fs.isGreaterThan(t(r,i)))&&(s=!1,i=r),!0)),i}};os.empty=new os(e=>{});function cn(e,t){let i=Object.create(null);for(let s of e){let r=t(s),n=i[r];n||(n=i[r]=[]),n.push(s)}return i}var as,hs,gh=class{constructor(e,t){this.toKey=t,this._map=new Map,this[as]="SetWithKey";for(let i of e)this.add(i)}get size(){return this._map.size}add(e){let t=this.toKey(e);return this._map.set(t,e),this}delete(e){return this._map.delete(this.toKey(e))}has(e){return this._map.has(this.toKey(e))}*entries(){for(let e of this._map.values())yield[e,e]}keys(){return this.values()}*values(){for(let e of this._map.values())yield e}clear(){this._map.clear()}forEach(e,t){this._map.forEach(i=>e.call(t,i,i,this))}[(hs=Symbol.iterator,as=Symbol.toStringTag,hs)](){return this.values()}},dn=class{constructor(){this.map=new Map}add(e,t){let i=this.map.get(e);i||(i=new Set,this.map.set(e,i)),i.add(t)}delete(e,t){let i=this.map.get(e);i&&(i.delete(t),i.size===0&&this.map.delete(e))}forEach(e,t){let i=this.map.get(e);i&&i.forEach(t)}get(e){return this.map.get(e)||new Set}},ps;(e=>{function t(B){return B&&typeof B=="object"&&typeof B[Symbol.iterator]=="function"}e.is=t;let i=Object.freeze([]);function s(){return i}e.empty=s;function*r(B){yield B}e.single=r;function n(B){return t(B)?B:r(B)}e.wrap=n;function o(B){return B||i}e.from=o;function*h(B){for(let T=B.length-1;T>=0;T--)yield B[T]}e.reverse=h;function l(B){return!B||B[Symbol.iterator]().next().done===!0}e.isEmpty=l;function a(B){return B[Symbol.iterator]().next().value}e.first=a;function c(B,T){let A=0;for(let ee of B)if(T(ee,A++))return!0;return!1}e.some=c;function d(B,T){for(let A of B)if(T(A))return A}e.find=d;function*u(B,T){for(let A of B)T(A)&&(yield A)}e.filter=u;function*f(B,T){let A=0;for(let ee of B)yield T(ee,A++)}e.map=f;function*_(B,T){let A=0;for(let ee of B)yield*T(ee,A++)}e.flatMap=_;function*p(...B){for(let T of B)yield*T}e.concat=p;function S(B,T,A){let ee=A;for(let ke of B)ee=T(ee,ke);return ee}e.reduce=S;function*k(B,T,A=B.length){for(T<0&&(T+=B.length),A<0?A+=B.length:A>B.length&&(A=B.length);Ti.source!==null&&!this.getRootParent(i,t).isSingleton).flatMap(([i])=>i)}computeLeakingDisposables(t=10,i){let s;if(i)s=i;else{let l=new Map,a=[...this.livingDisposables.values()].filter(d=>d.source!==null&&!this.getRootParent(d,l).isSingleton);if(a.length===0)return;let c=new Set(a.map(d=>d.value));if(s=a.filter(d=>!(d.parent&&c.has(d.parent))),s.length===0)throw new Error("There are cyclic diposable chains!")}if(!s)return;function r(l){function a(d,u){for(;d.length>0&&u.some(f=>typeof f=="string"?f===d[0]:d[0].match(f));)d.shift()}let c=l.source.split(` `).map(d=>d.trim().replace("at ","")).filter(d=>d!=="");return a(c,["Error",/^trackDisposable \(.*\)$/,/^DisposableTracker.trackDisposable \(.*\)$/]),c.reverse()}let n=new dn;for(let l of s){let a=r(l);for(let c=0;c<=a.length;c++)n.add(a.slice(0,c).join(` `),l)}s.sort(hn(l=>l.idx,ln));let o="",h=0;for(let l of s.slice(0,t)){h++;let a=r(l),c=[];for(let d=0;d{t[e]||console.log(i)},3e3)}setParent(t,i){if(t&&t!==Ve.None)try{t[e]=!0}catch{}}markAsDisposed(t){if(t&&t!==Ve.None)try{t[e]=!0}catch{}}markAsSingleton(t){}})}function oi(e){return qe?.trackDisposable(e),e}function ai(e){qe?.markAsDisposed(e)}function ti(e,t){qe?.setParent(e,t)}function pn(e,t){if(qe)for(let i of e)qe.setParent(i,t)}function vs(e){if(ps.is(e)){let t=[];for(let i of e)if(i)try{i.dispose()}catch(s){t.push(s)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"Encountered errors while disposing of store");return Array.isArray(e)?[]:e}else if(e)return e.dispose(),e}function gn(...e){let t=ms(()=>vs(e));return pn(e,t),t}function ms(e){let t=oi({dispose:nn(()=>{ai(t),e()})});return t}var Ss=class ws{constructor(){this._toDispose=new Set,this._isDisposed=!1,oi(this)}dispose(){this._isDisposed||(ai(this),this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{vs(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself!");return ti(t,this),this._isDisposed?ws.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}delete(t){if(t){if(t===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(t),t.dispose()}}deleteAndLeak(t){t&&this._toDispose.has(t)&&(this._toDispose.delete(t),ti(t,null))}};Ss.DISABLE_DISPOSED_WARNING=!1;var hi=Ss,Ve=class{constructor(){this._store=new hi,oi(this),ti(this._store,this)}dispose(){ai(this),this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}};Ve.None=Object.freeze({dispose(){}});var ls=class ii{constructor(t){this.element=t,this.next=ii.Undefined,this.prev=ii.Undefined}};ls.Undefined=new ls(void 0);var vn=globalThis.performance&&typeof globalThis.performance.now=="function",mn=class bs{static create(t){return new bs(t)}constructor(t){this._now=vn&&t===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},Sn=!1,cs=!1,wn=!1,bn;(e=>{e.None=()=>Ve.None;function t(v){if(wn){let{onDidAddListener:m}=v,w=ni.create(),b=0;v.onDidAddListener=()=>{++b===2&&(console.warn("snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here"),w.print()),m?.()}}}function i(v,m){return u(v,()=>{},0,void 0,!0,void 0,m)}e.defer=i;function s(v){return(m,w=null,b)=>{let x=!1,M;return M=v(P=>{if(!x)return M?M.dispose():x=!0,m.call(w,P)},null,b),x&&M.dispose(),M}}e.once=s;function r(v,m,w){return c((b,x=null,M)=>v(P=>b.call(x,m(P)),null,M),w)}e.map=r;function n(v,m,w){return c((b,x=null,M)=>v(P=>{m(P),b.call(x,P)},null,M),w)}e.forEach=n;function o(v,m,w){return c((b,x=null,M)=>v(P=>m(P)&&b.call(x,P),null,M),w)}e.filter=o;function h(v){return v}e.signal=h;function l(...v){return(m,w=null,b)=>{let x=gn(...v.map(M=>M(P=>m.call(w,P))));return d(x,b)}}e.any=l;function a(v,m,w,b){let x=w;return r(v,M=>(x=m(x,M),x),b)}e.reduce=a;function c(v,m){let w,b={onWillAddFirstListener(){w=v(x.fire,x)},onDidRemoveLastListener(){w?.dispose()}};m||t(b);let x=new Te(b);return m?.add(x),x.event}function d(v,m){return m instanceof Array?m.push(v):m&&m.add(v),v}function u(v,m,w=100,b=!1,x=!1,M,P){let C,q,ve,Me=0,ke,Ne={leakWarningThreshold:M,onWillAddFirstListener(){C=v(He=>{Me++,q=m(q,He),b&&!ve&&(te.fire(q),q=void 0),ke=()=>{let _e=q;q=void 0,ve=void 0,(!b||Me>1)&&te.fire(_e),Me=0},typeof w=="number"?(clearTimeout(ve),ve=setTimeout(ke,w)):ve===void 0&&(ve=0,queueMicrotask(ke))})},onWillRemoveListener(){x&&Me>0&&ke?.()},onDidRemoveLastListener(){ke=void 0,C.dispose()}};P||t(Ne);let te=new Te(Ne);return P?.add(te),te.event}e.debounce=u;function f(v,m=0,w){return e.debounce(v,(b,x)=>b?(b.push(x),b):[x],m,void 0,!0,void 0,w)}e.accumulate=f;function _(v,m=(b,x)=>b===x,w){let b=!0,x;return o(v,M=>{let P=b||!m(M,x);return b=!1,x=M,P},w)}e.latch=_;function p(v,m,w){return[e.filter(v,m,w),e.filter(v,b=>!m(b),w)]}e.split=p;function S(v,m=!1,w=[],b){let x=w.slice(),M=v(q=>{x?x.push(q):C.fire(q)});b&&b.add(M);let P=()=>{x?.forEach(q=>C.fire(q)),x=null},C=new Te({onWillAddFirstListener(){M||(M=v(q=>C.fire(q)),b&&b.add(M))},onDidAddFirstListener(){x&&(m?setTimeout(P):P())},onDidRemoveLastListener(){M&&M.dispose(),M=null}});return b&&b.add(C),C.event}e.buffer=S;function k(v,m){return(w,b,x)=>{let M=m(new E);return v(function(P){let C=M.evaluate(P);C!==R&&w.call(b,C)},void 0,x)}}e.chain=k;let R=Symbol("HaltChainable");class E{constructor(){this.steps=[]}map(m){return this.steps.push(m),this}forEach(m){return this.steps.push(w=>(m(w),w)),this}filter(m){return this.steps.push(w=>m(w)?w:R),this}reduce(m,w){let b=w;return this.steps.push(x=>(b=m(b,x),b)),this}latch(m=(w,b)=>w===b){let w=!0,b;return this.steps.push(x=>{let M=w||!m(x,b);return w=!1,b=x,M?x:R}),this}evaluate(m){for(let w of this.steps)if(m=w(m),m===R)break;return m}}function B(v,m,w=b=>b){let b=(...C)=>P.fire(w(...C)),x=()=>v.on(m,b),M=()=>v.removeListener(m,b),P=new Te({onWillAddFirstListener:x,onDidRemoveLastListener:M});return P.event}e.fromNodeEventEmitter=B;function T(v,m,w=b=>b){let b=(...C)=>P.fire(w(...C)),x=()=>v.addEventListener(m,b),M=()=>v.removeEventListener(m,b),P=new Te({onWillAddFirstListener:x,onDidRemoveLastListener:M});return P.event}e.fromDOMEventEmitter=T;function A(v){return new Promise(m=>s(v)(m))}e.toPromise=A;function ee(v){let m=new Te;return v.then(w=>{m.fire(w)},()=>{m.fire(void 0)}).finally(()=>{m.dispose()}),m.event}e.fromPromise=ee;function Ce(v,m){return v(w=>m.fire(w))}e.forward=Ce;function Oe(v,m,w){return m(w),v(b=>m(b))}e.runAndSubscribe=Oe;class Ue{constructor(m,w){this._observable=m,this._counter=0,this._hasChanged=!1;let b={onWillAddFirstListener:()=>{m.addObserver(this)},onDidRemoveLastListener:()=>{m.removeObserver(this)}};w||t(b),this.emitter=new Te(b),w&&w.add(this.emitter)}beginUpdate(m){this._counter++}handlePossibleChange(m){}handleChange(m,w){this._hasChanged=!0}endUpdate(m){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function Ie(v,m){return new Ue(v,m).emitter.event}e.fromObservable=Ie;function St(v){return(m,w,b)=>{let x=0,M=!1,P={beginUpdate(){x++},endUpdate(){x--,x===0&&(v.reportChanges(),M&&(M=!1,m.call(w)))},handlePossibleChange(){},handleChange(){M=!0}};v.addObserver(P),v.reportChanges();let C={dispose(){v.removeObserver(P)}};return b instanceof hi?b.add(C):Array.isArray(b)&&b.push(C),C}}e.fromObservableLight=St})(bn||={});var si=class ri{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${ri._idPool++}`,ri.all.add(this)}start(t){this._stopWatch=new mn,this.listenerCount=t}stop(){if(this._stopWatch){let t=this._stopWatch.elapsed();this.durations.push(t),this.elapsedOverall+=t,this.invocationCount+=1,this._stopWatch=void 0}}};si.all=new Set,si._idPool=0;var yn=si,ds=-1,ys=class Cs{constructor(t,i,s=(Cs._idPool++).toString(16).padStart(3,"0")){this._errorHandler=t,this.threshold=i,this.name=s,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(t,i){let s=this.threshold;if(s<=0||i{let n=this._stacks.get(t.value)||0;this._stacks.set(t.value,n-1)}}getMostFrequentStack(){if(!this._stacks)return;let t,i=0;for(let[s,r]of this._stacks)(!t||i{t[e]||console.log(i)},3e3)}setParent(t,i){if(t&&t!==Ve.None)try{t[e]=!0}catch{}}markAsDisposed(t){if(t&&t!==Ve.None)try{t[e]=!0}catch{}}markAsSingleton(t){}})}function oi(e){return qe?.trackDisposable(e),e}function ai(e){qe?.markAsDisposed(e)}function ti(e,t){qe?.setParent(e,t)}function pn(e,t){if(qe)for(let i of e)qe.setParent(i,t)}function vs(e){if(ps.is(e)){let t=[];for(let i of e)if(i)try{i.dispose()}catch(s){t.push(s)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"Encountered errors while disposing of store");return Array.isArray(e)?[]:e}else if(e)return e.dispose(),e}function gn(...e){let t=ms(()=>vs(e));return pn(e,t),t}function ms(e){let t=oi({dispose:nn(()=>{ai(t),e()})});return t}var Ss=class ws{constructor(){this._toDispose=new Set,this._isDisposed=!1,oi(this)}dispose(){this._isDisposed||(ai(this),this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{vs(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself!");return ti(t,this),this._isDisposed?ws.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}delete(t){if(t){if(t===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(t),t.dispose()}}deleteAndLeak(t){t&&this._toDispose.has(t)&&(this._toDispose.delete(t),ti(t,null))}};Ss.DISABLE_DISPOSED_WARNING=!1;var hi=Ss,Ve=class{constructor(){this._store=new hi,oi(this),ti(this._store,this)}dispose(){ai(this),this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}};Ve.None=Object.freeze({dispose(){}});var ls=class ii{constructor(t){this.element=t,this.next=ii.Undefined,this.prev=ii.Undefined}};ls.Undefined=new ls(void 0);var vn=globalThis.performance&&typeof globalThis.performance.now=="function",mn=class bs{static create(t){return new bs(t)}constructor(t){this._now=vn&&t===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},Sn=!1,cs=!1,wn=!1,bn;(e=>{e.None=()=>Ve.None;function t(v){if(wn){let{onDidAddListener:m}=v,w=ni.create(),b=0;v.onDidAddListener=()=>{++b===2&&(console.warn("snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here"),w.print()),m?.()}}}function i(v,m){return u(v,()=>{},0,void 0,!0,void 0,m)}e.defer=i;function s(v){return(m,w=null,b)=>{let x=!1,M;return M=v(P=>{if(!x)return M?M.dispose():x=!0,m.call(w,P)},null,b),x&&M.dispose(),M}}e.once=s;function r(v,m,w){return c((b,x=null,M)=>v(P=>b.call(x,m(P)),null,M),w)}e.map=r;function n(v,m,w){return c((b,x=null,M)=>v(P=>{m(P),b.call(x,P)},null,M),w)}e.forEach=n;function o(v,m,w){return c((b,x=null,M)=>v(P=>m(P)&&b.call(x,P),null,M),w)}e.filter=o;function h(v){return v}e.signal=h;function l(...v){return(m,w=null,b)=>{let x=gn(...v.map(M=>M(P=>m.call(w,P))));return d(x,b)}}e.any=l;function a(v,m,w,b){let x=w;return r(v,M=>(x=m(x,M),x),b)}e.reduce=a;function c(v,m){let w,b={onWillAddFirstListener(){w=v(x.fire,x)},onDidRemoveLastListener(){w?.dispose()}};m||t(b);let x=new Te(b);return m?.add(x),x.event}function d(v,m){return m instanceof Array?m.push(v):m&&m.add(v),v}function u(v,m,w=100,b=!1,x=!1,M,P){let C,q,ve,Me=0,xe,Ne={leakWarningThreshold:M,onWillAddFirstListener(){C=v(He=>{Me++,q=m(q,He),b&&!ve&&(te.fire(q),q=void 0),xe=()=>{let _e=q;q=void 0,ve=void 0,(!b||Me>1)&&te.fire(_e),Me=0},typeof w=="number"?(clearTimeout(ve),ve=setTimeout(xe,w)):ve===void 0&&(ve=0,queueMicrotask(xe))})},onWillRemoveListener(){x&&Me>0&&xe?.()},onDidRemoveLastListener(){xe=void 0,C.dispose()}};P||t(Ne);let te=new Te(Ne);return P?.add(te),te.event}e.debounce=u;function f(v,m=0,w){return e.debounce(v,(b,x)=>b?(b.push(x),b):[x],m,void 0,!0,void 0,w)}e.accumulate=f;function _(v,m=(b,x)=>b===x,w){let b=!0,x;return o(v,M=>{let P=b||!m(M,x);return b=!1,x=M,P},w)}e.latch=_;function p(v,m,w){return[e.filter(v,m,w),e.filter(v,b=>!m(b),w)]}e.split=p;function S(v,m=!1,w=[],b){let x=w.slice(),M=v(q=>{x?x.push(q):C.fire(q)});b&&b.add(M);let P=()=>{x?.forEach(q=>C.fire(q)),x=null},C=new Te({onWillAddFirstListener(){M||(M=v(q=>C.fire(q)),b&&b.add(M))},onDidAddFirstListener(){x&&(m?setTimeout(P):P())},onDidRemoveLastListener(){M&&M.dispose(),M=null}});return b&&b.add(C),C.event}e.buffer=S;function k(v,m){return(w,b,x)=>{let M=m(new E);return v(function(P){let C=M.evaluate(P);C!==R&&w.call(b,C)},void 0,x)}}e.chain=k;let R=Symbol("HaltChainable");class E{constructor(){this.steps=[]}map(m){return this.steps.push(m),this}forEach(m){return this.steps.push(w=>(m(w),w)),this}filter(m){return this.steps.push(w=>m(w)?w:R),this}reduce(m,w){let b=w;return this.steps.push(x=>(b=m(b,x),b)),this}latch(m=(w,b)=>w===b){let w=!0,b;return this.steps.push(x=>{let M=w||!m(x,b);return w=!1,b=x,M?x:R}),this}evaluate(m){for(let w of this.steps)if(m=w(m),m===R)break;return m}}function B(v,m,w=b=>b){let b=(...C)=>P.fire(w(...C)),x=()=>v.on(m,b),M=()=>v.removeListener(m,b),P=new Te({onWillAddFirstListener:x,onDidRemoveLastListener:M});return P.event}e.fromNodeEventEmitter=B;function T(v,m,w=b=>b){let b=(...C)=>P.fire(w(...C)),x=()=>v.addEventListener(m,b),M=()=>v.removeEventListener(m,b),P=new Te({onWillAddFirstListener:x,onDidRemoveLastListener:M});return P.event}e.fromDOMEventEmitter=T;function A(v){return new Promise(m=>s(v)(m))}e.toPromise=A;function ee(v){let m=new Te;return v.then(w=>{m.fire(w)},()=>{m.fire(void 0)}).finally(()=>{m.dispose()}),m.event}e.fromPromise=ee;function ke(v,m){return v(w=>m.fire(w))}e.forward=ke;function Oe(v,m,w){return m(w),v(b=>m(b))}e.runAndSubscribe=Oe;class Ue{constructor(m,w){this._observable=m,this._counter=0,this._hasChanged=!1;let b={onWillAddFirstListener:()=>{m.addObserver(this)},onDidRemoveLastListener:()=>{m.removeObserver(this)}};w||t(b),this.emitter=new Te(b),w&&w.add(this.emitter)}beginUpdate(m){this._counter++}handlePossibleChange(m){}handleChange(m,w){this._hasChanged=!0}endUpdate(m){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function Ie(v,m){return new Ue(v,m).emitter.event}e.fromObservable=Ie;function St(v){return(m,w,b)=>{let x=0,M=!1,P={beginUpdate(){x++},endUpdate(){x--,x===0&&(v.reportChanges(),M&&(M=!1,m.call(w)))},handlePossibleChange(){},handleChange(){M=!0}};v.addObserver(P),v.reportChanges();let C={dispose(){v.removeObserver(P)}};return b instanceof hi?b.add(C):Array.isArray(b)&&b.push(C),C}}e.fromObservableLight=St})(bn||={});var si=class ri{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${ri._idPool++}`,ri.all.add(this)}start(t){this._stopWatch=new mn,this.listenerCount=t}stop(){if(this._stopWatch){let t=this._stopWatch.elapsed();this.durations.push(t),this.elapsedOverall+=t,this.invocationCount+=1,this._stopWatch=void 0}}};si.all=new Set,si._idPool=0;var yn=si,ds=-1,ys=class Cs{constructor(t,i,s=(Cs._idPool++).toString(16).padStart(3,"0")){this._errorHandler=t,this.threshold=i,this.name=s,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(t,i){let s=this.threshold;if(s<=0||i{let n=this._stacks.get(t.value)||0;this._stacks.set(t.value,n-1)}}getMostFrequentStack(){if(!this._stacks)return;let t,i=0;for(let[s,r]of this._stacks)(!t||i{if(e instanceof bt)t(e);else for(let i=0;i{e.length!==0&&(console.warn("[LEAKING LISTENERS] GC'ed these listeners that were NOT yet disposed:"),console.warn(e.join(` `)),e.length=0)},3e3),yt=new FinalizationRegistry(t=>{typeof t=="string"&&e.push(t)})}var Te=class{constructor(e){this._size=0,this._options=e,this._leakageMon=ds>0||this._options?.leakWarningThreshold?new Cn(e?.onListenerError??jt,this._options?.leakWarningThreshold??ds):void 0,this._perfMon=this._options?._profName?new yn(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){if(!this._disposed){if(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners){if(cs){let e=this._listeners;queueMicrotask(()=>{Dn(e,t=>t.stack?.print())})}this._listeners=void 0,this._size=0}this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose()}}get event(){return this._event??=(e,t,i)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let h=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(h);let l=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],a=new xn(`${h}. HINT: Stack shows most frequent listener (${l[1]}-times)`,l[0]);return(this._options?.onListenerError||jt)(a),Ve.None}if(this._disposed)return Ve.None;t&&(e=e.bind(t));let s=new bt(e),r,n;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(s.stack=ni.create(),r=this._leakageMon.check(s.stack,this._size+1)),cs&&(s.stack=n??ni.create()),this._listeners?this._listeners instanceof bt?(this._deliveryQueue??=new Mn,this._listeners=[this._listeners,s]):this._listeners.push(s):(this._options?.onWillAddFirstListener?.(this),this._listeners=s,this._options?.onDidAddFirstListener?.(this)),this._size++;let o=ms(()=>{yt?.unregister(o),r?.(),this._removeListener(s)});if(i instanceof hi?i.add(o):Array.isArray(i)&&i.push(o),yt){let h=new Error().stack.split(` `).slice(2,3).join(` -`).trim(),l=/(file:|vscode-file:\/\/vscode-app)?(\/[^:]*:\d+:\d+)/.exec(h);yt.register(o,l?.[2]??h,o)}return o},this._event}_removeListener(e){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let t=this._listeners,i=t.indexOf(e);if(i===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,t[i]=void 0;let s=this._deliveryQueue.current===this;if(this._size*En<=t.length){let r=0;for(let n=0;n0}},Mn=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,i){this.i=0,this.end=i,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},kt=class Ct{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new Te,this.onChange=this._onChange.event;let t=new Qr;this.register(t),this._active=t.version,this._activeProvider=t}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,i,s=!1){return(t&16777215)<<3|(i&3)<<1|(s?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let i=0,s=0,r=t.length;for(let n=0;n=r)return i+this.wcwidth(o);let a=t.charCodeAt(n);56320<=a&&a<=57343?o=(o-55296)*1024+a-56320+65536:i+=this.wcwidth(a)}let h=this.charProperties(o,s),l=Ct.extractWidth(h);Ct.extractShouldJoin(h)&&(l-=Ct.extractWidth(s)),i+=l,s=h}return i}charProperties(t,i){return this._activeProvider.charProperties(t,i)}},Gt=[[768,879],[1155,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1541],[1552,1562],[1564,1564],[1611,1631],[1648,1648],[1750,1757],[1759,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2045,2045],[2070,2073],[2075,2083],[2085,2087],[2089,2093],[2137,2139],[2259,2306],[2362,2362],[2364,2364],[2369,2376],[2381,2381],[2385,2391],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2558,2558],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2641,2641],[2672,2673],[2677,2677],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2810,2815],[2817,2817],[2876,2876],[2879,2879],[2881,2884],[2893,2893],[2902,2902],[2914,2915],[2946,2946],[3008,3008],[3021,3021],[3072,3072],[3076,3076],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3170,3171],[3201,3201],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3328,3329],[3387,3388],[3393,3396],[3405,3405],[3426,3427],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3981,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4151],[4153,4154],[4157,4158],[4184,4185],[4190,4192],[4209,4212],[4226,4226],[4229,4230],[4237,4237],[4253,4253],[4448,4607],[4957,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6158],[6277,6278],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6683,6683],[6742,6742],[6744,6750],[6752,6752],[6754,6754],[6757,6764],[6771,6780],[6783,6783],[6832,6846],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7040,7041],[7074,7077],[7080,7081],[7083,7085],[7142,7142],[7144,7145],[7149,7149],[7151,7153],[7212,7219],[7222,7223],[7376,7378],[7380,7392],[7394,7400],[7405,7405],[7412,7412],[7416,7417],[7616,7673],[7675,7679],[8203,8207],[8234,8238],[8288,8292],[8294,8303],[8400,8432],[11503,11505],[11647,11647],[11744,11775],[12330,12333],[12441,12442],[42607,42610],[42612,42621],[42654,42655],[42736,42737],[43010,43010],[43014,43014],[43019,43019],[43045,43046],[43204,43205],[43232,43249],[43263,43263],[43302,43309],[43335,43345],[43392,43394],[43443,43443],[43446,43449],[43452,43453],[43493,43493],[43561,43566],[43569,43570],[43573,43574],[43587,43587],[43596,43596],[43644,43644],[43696,43696],[43698,43700],[43703,43704],[43710,43711],[43713,43713],[43756,43757],[43766,43766],[44005,44005],[44008,44008],[44013,44013],[64286,64286],[65024,65039],[65056,65071],[65279,65279],[65529,65531]],Ln=[[66045,66045],[66272,66272],[66422,66426],[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[68325,68326],[68900,68903],[69446,69456],[69633,69633],[69688,69702],[69759,69761],[69811,69814],[69817,69818],[69821,69821],[69837,69837],[69888,69890],[69927,69931],[69933,69940],[70003,70003],[70016,70017],[70070,70078],[70089,70092],[70191,70193],[70196,70196],[70198,70199],[70206,70206],[70367,70367],[70371,70378],[70400,70401],[70459,70460],[70464,70464],[70502,70508],[70512,70516],[70712,70719],[70722,70724],[70726,70726],[70750,70750],[70835,70840],[70842,70842],[70847,70848],[70850,70851],[71090,71093],[71100,71101],[71103,71104],[71132,71133],[71219,71226],[71229,71229],[71231,71232],[71339,71339],[71341,71341],[71344,71349],[71351,71351],[71453,71455],[71458,71461],[71463,71467],[71727,71735],[71737,71738],[72148,72151],[72154,72155],[72160,72160],[72193,72202],[72243,72248],[72251,72254],[72263,72263],[72273,72278],[72281,72283],[72330,72342],[72344,72345],[72752,72758],[72760,72765],[72767,72767],[72850,72871],[72874,72880],[72882,72883],[72885,72886],[73009,73014],[73018,73018],[73020,73021],[73023,73029],[73031,73031],[73104,73105],[73109,73109],[73111,73111],[73459,73460],[78896,78904],[92912,92916],[92976,92982],[94031,94031],[94095,94098],[113821,113822],[113824,113827],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[121344,121398],[121403,121452],[121461,121461],[121476,121476],[121499,121503],[121505,121519],[122880,122886],[122888,122904],[122907,122913],[122915,122916],[122918,122922],[123184,123190],[123628,123631],[125136,125142],[125252,125258],[917505,917505],[917536,917631],[917760,917999]],Jt=[[4352,4447],[8986,8987],[9001,9002],[9193,9196],[9200,9200],[9203,9203],[9725,9726],[9748,9749],[9800,9811],[9855,9855],[9875,9875],[9889,9889],[9898,9899],[9917,9918],[9924,9925],[9934,9934],[9940,9940],[9962,9962],[9970,9971],[9973,9973],[9978,9978],[9981,9981],[9989,9989],[9994,9995],[10024,10024],[10060,10060],[10062,10062],[10067,10069],[10071,10071],[10133,10135],[10160,10160],[10175,10175],[11035,11036],[11088,11088],[11093,11093],[11904,11929],[11931,12019],[12032,12245],[12272,12283],[12288,12329],[12334,12350],[12353,12438],[12443,12543],[12549,12591],[12593,12686],[12688,12730],[12736,12771],[12784,12830],[12832,12871],[12880,19903],[19968,42124],[42128,42182],[43360,43388],[44032,55203],[63744,64255],[65040,65049],[65072,65106],[65108,65126],[65128,65131],[65281,65376],[65504,65510]],Rn=[[94176,94179],[94208,100343],[100352,101106],[110592,110878],[110928,110930],[110948,110951],[110960,111355],[126980,126980],[127183,127183],[127374,127374],[127377,127386],[127488,127490],[127504,127547],[127552,127560],[127568,127569],[127584,127589],[127744,127776],[127789,127797],[127799,127868],[127870,127891],[127904,127946],[127951,127955],[127968,127984],[127988,127988],[127992,128062],[128064,128064],[128066,128252],[128255,128317],[128331,128334],[128336,128359],[128378,128378],[128405,128406],[128420,128420],[128507,128591],[128640,128709],[128716,128716],[128720,128722],[128725,128725],[128747,128748],[128756,128762],[128992,129003],[129293,129393],[129395,129398],[129402,129442],[129445,129450],[129454,129482],[129485,129535],[129648,129651],[129656,129658],[129664,129666],[129680,129685],[131072,196605],[196608,262141]],xe;function _s(e,t){let i=0,s=t.length-1,r;if(et[s][1])return!1;for(;s>=i;)if(r=i+s>>1,e>t[r][1])i=r+1;else if(ei&&(i=r)}return kt.createPropertyValue(0,i,s)}},xs=class{activate(e){e.unicode.register(new Tn)}dispose(){}};var Pn=class{constructor(e,t,i,s={}){this._terminal=e,this._regex=t,this._handler=i,this._options=s}provideLinks(e,t){let i=On.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(i))}_addCallbacks(e){return e.map(t=>(t.leave=this._options.leave,t.hover=(i,s)=>{if(this._options.hover){let{range:r}=t;this._options.hover(i,s,r)}},t))}};function An(e){try{let t=new URL(e),i=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(i.toLocaleLowerCase())}catch{return!1}}var On=class xt{static computeLink(t,i,s,r){let n=i.flags.includes("g")?i.flags:`${i.flags}g`,o=new RegExp(i.source,n),[h,l]=xt._getWindowedLineStrings(t-1,s),a=h.join(""),c,d=[];for(;c=o.exec(a);){let u=c[0];if(!An(u))continue;let[f,_]=xt._mapStrIdx(s,l,0,c.index),[p,S]=xt._mapStrIdx(s,f,_,u.length);if(f===-1||_===-1||p===-1||S===-1)continue;let k={start:{x:_+1,y:f+1},end:{x:S,y:p+1}};d.push({range:k,text:u,activate:r})}return d}static _getWindowedLineStrings(t,i){let s,r=t,n=t,o,h,l=[];if(s=i.buffer.active.getLine(t)){let a=s.translateToString(!0);if(s.isWrapped&&a[0]!==" "){for(o=0;(s=i.buffer.active.getLine(--r))&&o<2048&&(h=s.translateToString(!0),o+=h.length,l.push(h),!(!s.isWrapped||h.indexOf(" ")!==-1)););l.reverse()}for(l.push(a),o=0;(s=i.buffer.active.getLine(++n))&&s.isWrapped&&o<2048&&(h=s.translateToString(!0),o+=h.length,l.push(h),h.indexOf(" ")===-1););}return[l,r]}static _mapStrIdx(t,i,s,r){let n=t.buffer.active,o=n.getNullCell(),h=s;for(;r;){let l=n.getLine(i);if(!l)return[-1,-1];for(let a=h;a`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function Nn(e,t){let i=window.open();if(i){try{i.opener=null}catch{}i.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}var Bs=class{constructor(e=Nn,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,i=t.urlRegex??In;this._linkProvider=this._terminal.registerLinkProvider(new Pn(this._terminal,i,this._handler,t))}dispose(){this._linkProvider?.dispose()}};var lr=Object.defineProperty,Hn=Object.getOwnPropertyDescriptor,Fn=(e,t)=>{for(var i in t)lr(e,i,{get:t[i],enumerable:!0})},F=(e,t,i,s)=>{for(var r=s>1?void 0:s?Hn(t,i):t,n=e.length-1,o;n>=0;n--)(o=e[n])&&(r=(s?o(t,i,r):o(r))||r);return s&&r&&lr(t,i,r),r},g=(e,t)=>(i,s)=>t(i,s,e),Es="Terminal input",mi={get:()=>Es,set:e=>Es=e},Ds="Too much output to announce, navigate to rows manually to read",Tt={get:()=>Ds,set:e=>Ds=e};function Wn(e){return e.replace(/\r?\n/g,"\r")}function zn(e,t){return t?`\x1B[200~${e.replace(/\x1b/g,"\u241B")}\x1B[201~`:e}function Kn(e,t){e.clipboardData&&e.clipboardData.setData("text/plain",t.selectionText),e.preventDefault()}function $n(e,t,i,s){if(e.stopPropagation(),e.clipboardData){let r=e.clipboardData.getData("text/plain");cr(r,t,i,s)}}function cr(e,t,i,s){e=Wn(e),e=zn(e,i.decPrivateModes.bracketedPasteMode&&s.rawOptions.ignoreBracketedPasteMode!==!0),i.triggerDataEvent(e,!0),t.value=""}function dr(e,t,i){let s=i.getBoundingClientRect(),r=e.clientX-s.left-10,n=e.clientY-s.top-10;t.style.width="20px",t.style.height="20px",t.style.left=`${r}px`,t.style.top=`${n}px`,t.style.zIndex="1000",t.focus()}function Ms(e,t,i,s,r){dr(e,t,i),r&&s.rightClickSelect(e),t.value=s.selectionText,t.select()}function Ae(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function Ge(e,t=0,i=e.length){let s="";for(let r=t;r65535?(n-=65536,s+=String.fromCharCode((n>>10)+55296)+String.fromCharCode(n%1024+56320)):s+=String.fromCharCode(n)}return s}var Un=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let i=e.length;if(!i)return 0;let s=0,r=0;if(this._interim){let n=e.charCodeAt(r++);56320<=n&&n<=57343?t[s++]=(this._interim-55296)*1024+n-56320+65536:(t[s++]=this._interim,t[s++]=n),this._interim=0}for(let n=r;n=i)return this._interim=o,s;let h=e.charCodeAt(n);56320<=h&&h<=57343?t[s++]=(o-55296)*1024+h-56320+65536:(t[s++]=o,t[s++]=h);continue}o!==65279&&(t[s++]=o)}return s}},qn=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let i=e.length;if(!i)return 0;let s=0,r,n,o,h,l,a=0;if(this.interim[0]){let u=!1,f=this.interim[0];f&=(f&224)===192?31:(f&240)===224?15:7;let _=0,p;for(;(p=this.interim[++_])&&_<4;)f<<=6,f|=p&63;let S=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,k=S-_;for(;a=i)return 0;if(p=e[a++],(p&192)!==128){a--,u=!0;break}else this.interim[_++]=p,f<<=6,f|=p&63}u||(S===2?f<128?a--:t[s++]=f:S===3?f<2048||f>=55296&&f<=57343||f===65279||(t[s++]=f):f<65536||f>1114111||(t[s++]=f)),this.interim.fill(0)}let c=i-4,d=a;for(;d=i)return this.interim[0]=r,s;if(n=e[d++],(n&192)!==128){d--;continue}if(l=(r&31)<<6|n&63,l<128){d--;continue}t[s++]=l}else if((r&240)===224){if(d>=i)return this.interim[0]=r,s;if(n=e[d++],(n&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=n,s;if(o=e[d++],(o&192)!==128){d--;continue}if(l=(r&15)<<12|(n&63)<<6|o&63,l<2048||l>=55296&&l<=57343||l===65279)continue;t[s++]=l}else if((r&248)===240){if(d>=i)return this.interim[0]=r,s;if(n=e[d++],(n&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=n,s;if(o=e[d++],(o&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=n,this.interim[2]=o,s;if(h=e[d++],(h&192)!==128){d--;continue}if(l=(r&7)<<18|(n&63)<<12|(o&63)<<6|h&63,l<65536||l>1114111)continue;t[s++]=l}}return s}},vt=class _r{constructor(){this.fg=0,this.bg=0,this.extended=new Pt}static toColorRGB(t){return[t>>>16&255,t>>>8&255,t&255]}static fromColorRGB(t){return(t[0]&255)<<16|(t[1]&255)<<8|t[2]&255}clone(){let t=new _r;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},Pt=class ur{constructor(t=0,i=0){this._ext=0,this._urlId=0,this._ext=t,this._urlId=i}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(t){this._ext=t}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(t){this._ext&=-469762049,this._ext|=t<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(t){this._ext&=-67108864,this._ext|=t&67108863}get urlId(){return this._urlId}set urlId(t){this._urlId=t}get underlineVariantOffset(){let t=(this._ext&3758096384)>>29;return t<0?t^4294967288:t}set underlineVariantOffset(t){this._ext&=536870911,this._ext|=t<<29&3758096384}clone(){return new ur(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},ge=class fr extends vt{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new Pt,this.combinedData=""}static fromCharData(t){let i=new fr;return i.setFromCharData(t),i}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?Ae(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(t){this.fg=t[0],this.bg=0;let i=!1;if(t[1].length>2)i=!0;else if(t[1].length===2){let s=t[1].charCodeAt(0);if(55296<=s&&s<=56319){let r=t[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(s-55296)*1024+r-56320+65536|t[2]<<22:i=!0}else i=!0}else this.content=t[1].charCodeAt(0)|t[2]<<22;i&&(this.combinedData=t[1],this.content=2097152|t[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}attributesEquals(t){if(this.getFgColorMode()!==t.getFgColorMode()||this.getFgColor()!==t.getFgColor()||this.getBgColorMode()!==t.getBgColorMode()||this.getBgColor()!==t.getBgColor()||this.isInverse()!==t.isInverse()||this.isBold()!==t.isBold()||this.isUnderline()!==t.isUnderline())return!1;if(this.isUnderline()){if(this.getUnderlineStyle()!==t.getUnderlineStyle())return!1;let i=this.isUnderlineColorDefault(),s=t.isUnderlineColorDefault();if(!(i&&s)&&(i!==s||this.getUnderlineColor()!==t.getUnderlineColor()||this.getUnderlineColorMode()!==t.getUnderlineColorMode()))return!1}return!(this.isOverline()!==t.isOverline()||this.isBlink()!==t.isBlink()||this.isInvisible()!==t.isInvisible()||this.isItalic()!==t.isItalic()||this.isDim()!==t.isDim()||this.isStrikethrough()!==t.isStrikethrough())}},li=new Map;function Vn(e){return e.di$dependencies||[]}function U(e){if(li.has(e))return li.get(e);let t=function(i,s,r){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");Yn(t,i,r)};return t._id=e,li.set(e,t),t}function Yn(e,t,i){t.di$target===t?t.di$dependencies.push({id:e,index:i}):(t.di$dependencies=[{id:e,index:i}],t.di$target=t)}var ne=U("BufferService"),Ft=U("MouseStateService"),Ee=U("CoreService"),Xn=U("CharsetService"),qi=U("InstantiationService"),Je=U("LogService"),oe=U("OptionsService"),pr=U("OscLinkService"),jn=U("UnicodeService"),mt=U("DecorationService"),Si=class{constructor(e,t,i){this._bufferService=e,this._optionsService=t,this._oscLinkService=i,this._workCell=new ge}provideLinks(e,t){let i=this._bufferService.buffer.lines.get(e-1);if(!i){t(void 0);return}let s=[],r=this._optionsService.rawOptions.linkHandler,n=this._workCell,o=i.getTrimmedLength(),h=-1,l=-1,a=!1;for(let c=0;cr?r.activate(p,S,f):Gn(p,S),hover:(p,S)=>r?.hover?.(p,S,f),leave:(p,S)=>r?.leave?.(p,S,f)})}a=!1,n.hasExtendedAttrs()&&n.extended.urlId?(l=c,h=n.extended.urlId):(l=-1,h=-1)}}t(s)}_getRangeWithLineWrap(e,t,i,s){let r=e,n=t,o=e,h=i;for(;n===0&&this._bufferService.buffer.lines.get(r-1)?.isWrapped;){let l=this._bufferService.buffer.lines.get(r-2);if(!l)break;let a=l.getTrimmedLength();if(a===0||!this._hasUrlId(l,a-1,s))break;let c=a-1;for(;c>0&&this._hasUrlId(l,c-1,s);)c--;r--,n=c}for(;;){let l=this._bufferService.buffer.lines.get(o-1);if(!l)break;let a=l.getTrimmedLength();if(h!==a)break;let c=this._bufferService.buffer.lines.get(o);if(!c?.isWrapped)break;let d=c.getTrimmedLength();if(d===0||!this._hasUrlId(c,0,s))break;let u=1;for(;u0}},Mn=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,i){this.i=0,this.end=i,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},kt=class Ct{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new Te,this.onChange=this._onChange.event;let t=new Qr;this.register(t),this._active=t.version,this._activeProvider=t}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,i,s=!1){return(t&16777215)<<3|(i&3)<<1|(s?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let i=0,s=0,r=t.length;for(let n=0;n=r)return i+this.wcwidth(o);let a=t.charCodeAt(n);56320<=a&&a<=57343?o=(o-55296)*1024+a-56320+65536:i+=this.wcwidth(a)}let h=this.charProperties(o,s),l=Ct.extractWidth(h);Ct.extractShouldJoin(h)&&(l-=Ct.extractWidth(s)),i+=l,s=h}return i}charProperties(t,i){return this._activeProvider.charProperties(t,i)}},Gt=[[768,879],[1155,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1541],[1552,1562],[1564,1564],[1611,1631],[1648,1648],[1750,1757],[1759,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2045,2045],[2070,2073],[2075,2083],[2085,2087],[2089,2093],[2137,2139],[2259,2306],[2362,2362],[2364,2364],[2369,2376],[2381,2381],[2385,2391],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2558,2558],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2641,2641],[2672,2673],[2677,2677],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2810,2815],[2817,2817],[2876,2876],[2879,2879],[2881,2884],[2893,2893],[2902,2902],[2914,2915],[2946,2946],[3008,3008],[3021,3021],[3072,3072],[3076,3076],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3170,3171],[3201,3201],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3328,3329],[3387,3388],[3393,3396],[3405,3405],[3426,3427],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3981,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4151],[4153,4154],[4157,4158],[4184,4185],[4190,4192],[4209,4212],[4226,4226],[4229,4230],[4237,4237],[4253,4253],[4448,4607],[4957,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6158],[6277,6278],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6683,6683],[6742,6742],[6744,6750],[6752,6752],[6754,6754],[6757,6764],[6771,6780],[6783,6783],[6832,6846],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7040,7041],[7074,7077],[7080,7081],[7083,7085],[7142,7142],[7144,7145],[7149,7149],[7151,7153],[7212,7219],[7222,7223],[7376,7378],[7380,7392],[7394,7400],[7405,7405],[7412,7412],[7416,7417],[7616,7673],[7675,7679],[8203,8207],[8234,8238],[8288,8292],[8294,8303],[8400,8432],[11503,11505],[11647,11647],[11744,11775],[12330,12333],[12441,12442],[42607,42610],[42612,42621],[42654,42655],[42736,42737],[43010,43010],[43014,43014],[43019,43019],[43045,43046],[43204,43205],[43232,43249],[43263,43263],[43302,43309],[43335,43345],[43392,43394],[43443,43443],[43446,43449],[43452,43453],[43493,43493],[43561,43566],[43569,43570],[43573,43574],[43587,43587],[43596,43596],[43644,43644],[43696,43696],[43698,43700],[43703,43704],[43710,43711],[43713,43713],[43756,43757],[43766,43766],[44005,44005],[44008,44008],[44013,44013],[64286,64286],[65024,65039],[65056,65071],[65279,65279],[65529,65531]],Ln=[[66045,66045],[66272,66272],[66422,66426],[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[68325,68326],[68900,68903],[69446,69456],[69633,69633],[69688,69702],[69759,69761],[69811,69814],[69817,69818],[69821,69821],[69837,69837],[69888,69890],[69927,69931],[69933,69940],[70003,70003],[70016,70017],[70070,70078],[70089,70092],[70191,70193],[70196,70196],[70198,70199],[70206,70206],[70367,70367],[70371,70378],[70400,70401],[70459,70460],[70464,70464],[70502,70508],[70512,70516],[70712,70719],[70722,70724],[70726,70726],[70750,70750],[70835,70840],[70842,70842],[70847,70848],[70850,70851],[71090,71093],[71100,71101],[71103,71104],[71132,71133],[71219,71226],[71229,71229],[71231,71232],[71339,71339],[71341,71341],[71344,71349],[71351,71351],[71453,71455],[71458,71461],[71463,71467],[71727,71735],[71737,71738],[72148,72151],[72154,72155],[72160,72160],[72193,72202],[72243,72248],[72251,72254],[72263,72263],[72273,72278],[72281,72283],[72330,72342],[72344,72345],[72752,72758],[72760,72765],[72767,72767],[72850,72871],[72874,72880],[72882,72883],[72885,72886],[73009,73014],[73018,73018],[73020,73021],[73023,73029],[73031,73031],[73104,73105],[73109,73109],[73111,73111],[73459,73460],[78896,78904],[92912,92916],[92976,92982],[94031,94031],[94095,94098],[113821,113822],[113824,113827],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[121344,121398],[121403,121452],[121461,121461],[121476,121476],[121499,121503],[121505,121519],[122880,122886],[122888,122904],[122907,122913],[122915,122916],[122918,122922],[123184,123190],[123628,123631],[125136,125142],[125252,125258],[917505,917505],[917536,917631],[917760,917999]],Jt=[[4352,4447],[8986,8987],[9001,9002],[9193,9196],[9200,9200],[9203,9203],[9725,9726],[9748,9749],[9800,9811],[9855,9855],[9875,9875],[9889,9889],[9898,9899],[9917,9918],[9924,9925],[9934,9934],[9940,9940],[9962,9962],[9970,9971],[9973,9973],[9978,9978],[9981,9981],[9989,9989],[9994,9995],[10024,10024],[10060,10060],[10062,10062],[10067,10069],[10071,10071],[10133,10135],[10160,10160],[10175,10175],[11035,11036],[11088,11088],[11093,11093],[11904,11929],[11931,12019],[12032,12245],[12272,12283],[12288,12329],[12334,12350],[12353,12438],[12443,12543],[12549,12591],[12593,12686],[12688,12730],[12736,12771],[12784,12830],[12832,12871],[12880,19903],[19968,42124],[42128,42182],[43360,43388],[44032,55203],[63744,64255],[65040,65049],[65072,65106],[65108,65126],[65128,65131],[65281,65376],[65504,65510]],Rn=[[94176,94179],[94208,100343],[100352,101106],[110592,110878],[110928,110930],[110948,110951],[110960,111355],[126980,126980],[127183,127183],[127374,127374],[127377,127386],[127488,127490],[127504,127547],[127552,127560],[127568,127569],[127584,127589],[127744,127776],[127789,127797],[127799,127868],[127870,127891],[127904,127946],[127951,127955],[127968,127984],[127988,127988],[127992,128062],[128064,128064],[128066,128252],[128255,128317],[128331,128334],[128336,128359],[128378,128378],[128405,128406],[128420,128420],[128507,128591],[128640,128709],[128716,128716],[128720,128722],[128725,128725],[128747,128748],[128756,128762],[128992,129003],[129293,129393],[129395,129398],[129402,129442],[129445,129450],[129454,129482],[129485,129535],[129648,129651],[129656,129658],[129664,129666],[129680,129685],[131072,196605],[196608,262141]],Be;function _s(e,t){let i=0,s=t.length-1,r;if(et[s][1])return!1;for(;s>=i;)if(r=i+s>>1,e>t[r][1])i=r+1;else if(ei&&(i=r)}return kt.createPropertyValue(0,i,s)}},xs=class{activate(e){e.unicode.register(new Tn)}dispose(){}};var Pn=class{constructor(e,t,i,s={}){this._terminal=e,this._regex=t,this._handler=i,this._options=s}provideLinks(e,t){let i=On.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(i))}_addCallbacks(e){return e.map(t=>(t.leave=this._options.leave,t.hover=(i,s)=>{if(this._options.hover){let{range:r}=t;this._options.hover(i,s,r)}},t))}};function An(e){try{let t=new URL(e),i=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(i.toLocaleLowerCase())}catch{return!1}}var On=class xt{static computeLink(t,i,s,r){let n=i.flags.includes("g")?i.flags:`${i.flags}g`,o=new RegExp(i.source,n),[h,l]=xt._getWindowedLineStrings(t-1,s),a=h.join(""),c,d=[];for(;c=o.exec(a);){let u=c[0];if(!An(u))continue;let[f,_]=xt._mapStrIdx(s,l,0,c.index),[p,S]=xt._mapStrIdx(s,f,_,u.length);if(f===-1||_===-1||p===-1||S===-1)continue;let k={start:{x:_+1,y:f+1},end:{x:S,y:p+1}};d.push({range:k,text:u,activate:r})}return d}static _getWindowedLineStrings(t,i){let s,r=t,n=t,o,h,l=[];if(s=i.buffer.active.getLine(t)){let a=s.translateToString(!0);if(s.isWrapped&&a[0]!==" "){for(o=0;(s=i.buffer.active.getLine(--r))&&o<2048&&(h=s.translateToString(!0),o+=h.length,l.push(h),!(!s.isWrapped||h.indexOf(" ")!==-1)););l.reverse()}for(l.push(a),o=0;(s=i.buffer.active.getLine(++n))&&s.isWrapped&&o<2048&&(h=s.translateToString(!0),o+=h.length,l.push(h),h.indexOf(" ")===-1););}return[l,r]}static _mapStrIdx(t,i,s,r){let n=t.buffer.active,o=n.getNullCell(),h=s;for(;r;){let l=n.getLine(i);if(!l)return[-1,-1];for(let a=h;a`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function Nn(e,t){let i=window.open();if(i){try{i.opener=null}catch{}i.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}var Bs=class{constructor(e=Nn,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,i=t.urlRegex??In;this._linkProvider=this._terminal.registerLinkProvider(new Pn(this._terminal,i,this._handler,t))}dispose(){this._linkProvider?.dispose()}};var lr=Object.defineProperty,Hn=Object.getOwnPropertyDescriptor,Fn=(e,t)=>{for(var i in t)lr(e,i,{get:t[i],enumerable:!0})},F=(e,t,i,s)=>{for(var r=s>1?void 0:s?Hn(t,i):t,n=e.length-1,o;n>=0;n--)(o=e[n])&&(r=(s?o(t,i,r):o(r))||r);return s&&r&&lr(t,i,r),r},g=(e,t)=>(i,s)=>t(i,s,e),Es="Terminal input",mi={get:()=>Es,set:e=>Es=e},Ds="Too much output to announce, navigate to rows manually to read",Tt={get:()=>Ds,set:e=>Ds=e};function Wn(e){return e.replace(/\r?\n/g,"\r")}function zn(e,t){return t?`\x1B[200~${e.replace(/\x1b/g,"\u241B")}\x1B[201~`:e}function Kn(e,t){e.clipboardData&&e.clipboardData.setData("text/plain",t.selectionText),e.preventDefault()}function $n(e,t,i,s){if(e.stopPropagation(),e.clipboardData){let r=e.clipboardData.getData("text/plain");cr(r,t,i,s)}}function cr(e,t,i,s){e=Wn(e),e=zn(e,i.decPrivateModes.bracketedPasteMode&&s.rawOptions.ignoreBracketedPasteMode!==!0),i.triggerDataEvent(e,!0),t.value=""}function dr(e,t,i){let s=i.getBoundingClientRect(),r=e.clientX-s.left-10,n=e.clientY-s.top-10;t.style.width="20px",t.style.height="20px",t.style.left=`${r}px`,t.style.top=`${n}px`,t.style.zIndex="1000",t.focus()}function Ms(e,t,i,s,r){dr(e,t,i),r&&s.rightClickSelect(e),t.value=s.selectionText,t.select()}function Ae(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function Ge(e,t=0,i=e.length){let s="";for(let r=t;r65535?(n-=65536,s+=String.fromCharCode((n>>10)+55296)+String.fromCharCode(n%1024+56320)):s+=String.fromCharCode(n)}return s}var Un=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let i=e.length;if(!i)return 0;let s=0,r=0;if(this._interim){let n=e.charCodeAt(r++);56320<=n&&n<=57343?t[s++]=(this._interim-55296)*1024+n-56320+65536:(t[s++]=this._interim,t[s++]=n),this._interim=0}for(let n=r;n=i)return this._interim=o,s;let h=e.charCodeAt(n);56320<=h&&h<=57343?t[s++]=(o-55296)*1024+h-56320+65536:(t[s++]=o,t[s++]=h);continue}o!==65279&&(t[s++]=o)}return s}},qn=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let i=e.length;if(!i)return 0;let s=0,r,n,o,h,l,a=0;if(this.interim[0]){let u=!1,f=this.interim[0];f&=(f&224)===192?31:(f&240)===224?15:7;let _=0,p;for(;(p=this.interim[++_])&&_<4;)f<<=6,f|=p&63;let S=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,k=S-_;for(;a=i)return 0;if(p=e[a++],(p&192)!==128){a--,u=!0;break}else this.interim[_++]=p,f<<=6,f|=p&63}u||(S===2?f<128?a--:t[s++]=f:S===3?f<2048||f>=55296&&f<=57343||f===65279||(t[s++]=f):f<65536||f>1114111||(t[s++]=f)),this.interim.fill(0)}let c=i-4,d=a;for(;d=i)return this.interim[0]=r,s;if(n=e[d++],(n&192)!==128){d--;continue}if(l=(r&31)<<6|n&63,l<128){d--;continue}t[s++]=l}else if((r&240)===224){if(d>=i)return this.interim[0]=r,s;if(n=e[d++],(n&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=n,s;if(o=e[d++],(o&192)!==128){d--;continue}if(l=(r&15)<<12|(n&63)<<6|o&63,l<2048||l>=55296&&l<=57343||l===65279)continue;t[s++]=l}else if((r&248)===240){if(d>=i)return this.interim[0]=r,s;if(n=e[d++],(n&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=n,s;if(o=e[d++],(o&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=n,this.interim[2]=o,s;if(h=e[d++],(h&192)!==128){d--;continue}if(l=(r&7)<<18|(n&63)<<12|(o&63)<<6|h&63,l<65536||l>1114111)continue;t[s++]=l}}return s}},vt=class _r{constructor(){this.fg=0,this.bg=0,this.extended=new Pt}static toColorRGB(t){return[t>>>16&255,t>>>8&255,t&255]}static fromColorRGB(t){return(t[0]&255)<<16|(t[1]&255)<<8|t[2]&255}clone(){let t=new _r;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},Pt=class ur{constructor(t=0,i=0){this._ext=0,this._urlId=0,this._ext=t,this._urlId=i}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(t){this._ext=t}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(t){this._ext&=-469762049,this._ext|=t<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(t){this._ext&=-67108864,this._ext|=t&67108863}get urlId(){return this._urlId}set urlId(t){this._urlId=t}get underlineVariantOffset(){let t=(this._ext&3758096384)>>29;return t<0?t^4294967288:t}set underlineVariantOffset(t){this._ext&=536870911,this._ext|=t<<29&3758096384}clone(){return new ur(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},ge=class fr extends vt{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new Pt,this.combinedData=""}static fromCharData(t){let i=new fr;return i.setFromCharData(t),i}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?Ae(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(t){this.fg=t[0],this.bg=0;let i=!1;if(t[1].length>2)i=!0;else if(t[1].length===2){let s=t[1].charCodeAt(0);if(55296<=s&&s<=56319){let r=t[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(s-55296)*1024+r-56320+65536|t[2]<<22:i=!0}else i=!0}else this.content=t[1].charCodeAt(0)|t[2]<<22;i&&(this.combinedData=t[1],this.content=2097152|t[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}attributesEquals(t){if(this.getFgColorMode()!==t.getFgColorMode()||this.getFgColor()!==t.getFgColor()||this.getBgColorMode()!==t.getBgColorMode()||this.getBgColor()!==t.getBgColor()||this.isInverse()!==t.isInverse()||this.isBold()!==t.isBold()||this.isUnderline()!==t.isUnderline())return!1;if(this.isUnderline()){if(this.getUnderlineStyle()!==t.getUnderlineStyle())return!1;let i=this.isUnderlineColorDefault(),s=t.isUnderlineColorDefault();if(!(i&&s)&&(i!==s||this.getUnderlineColor()!==t.getUnderlineColor()||this.getUnderlineColorMode()!==t.getUnderlineColorMode()))return!1}return!(this.isOverline()!==t.isOverline()||this.isBlink()!==t.isBlink()||this.isInvisible()!==t.isInvisible()||this.isItalic()!==t.isItalic()||this.isDim()!==t.isDim()||this.isStrikethrough()!==t.isStrikethrough())}},li=new Map;function Vn(e){return e.di$dependencies||[]}function U(e){if(li.has(e))return li.get(e);let t=function(i,s,r){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");Yn(t,i,r)};return t._id=e,li.set(e,t),t}function Yn(e,t,i){t.di$target===t?t.di$dependencies.push({id:e,index:i}):(t.di$dependencies=[{id:e,index:i}],t.di$target=t)}var ne=U("BufferService"),Ft=U("MouseStateService"),De=U("CoreService"),Xn=U("CharsetService"),qi=U("InstantiationService"),Je=U("LogService"),oe=U("OptionsService"),pr=U("OscLinkService"),jn=U("UnicodeService"),mt=U("DecorationService"),Si=class{constructor(e,t,i){this._bufferService=e,this._optionsService=t,this._oscLinkService=i,this._workCell=new ge}provideLinks(e,t){let i=this._bufferService.buffer.lines.get(e-1);if(!i){t(void 0);return}let s=[],r=this._optionsService.rawOptions.linkHandler,n=this._workCell,o=i.getTrimmedLength(),h=-1,l=-1,a=!1;for(let c=0;cr?r.activate(p,S,f):Gn(p,S),hover:(p,S)=>r?.hover?.(p,S,f),leave:(p,S)=>r?.leave?.(p,S,f)})}a=!1,n.hasExtendedAttrs()&&n.extended.urlId?(l=c,h=n.extended.urlId):(l=-1,h=-1)}}t(s)}_getRangeWithLineWrap(e,t,i,s){let r=e,n=t,o=e,h=i;for(;n===0&&this._bufferService.buffer.lines.get(r-1)?.isWrapped;){let l=this._bufferService.buffer.lines.get(r-2);if(!l)break;let a=l.getTrimmedLength();if(a===0||!this._hasUrlId(l,a-1,s))break;let c=a-1;for(;c>0&&this._hasUrlId(l,c-1,s);)c--;r--,n=c}for(;;){let l=this._bufferService.buffer.lines.get(o-1);if(!l)break;let a=l.getTrimmedLength();if(h!==a)break;let c=this._bufferService.buffer.lines.get(o);if(!c?.isWrapped)break;let d=c.getTrimmedLength();if(d===0||!this._hasUrlId(c,0,s))break;let u=1;for(;u{e(),i&&r.dispose()},t),r=O(()=>{clearTimeout(s)});return i?.add(r),r}var Kt=class{constructor(){this._token=-1,this._isDisposed=!1}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new Error("Calling cancelAndSet on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new Error("Calling setIfNotSet on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},eo=class{constructor(){this._isScheduled=!1,this._isDisposed=!1}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._isScheduled=!1}set(e){if(this._isDisposed)throw new Error("Calling set on a disposed MicrotaskTimer");this._isScheduled||(this._isScheduled=!0,queueMicrotask(()=>{this._isScheduled&&(this._isScheduled=!1,e())}))}},to=class{constructor(){this._isDisposed=!1}cancel(){this._disposable?.dispose(),this._disposable=void 0}cancelAndSet(e,t,i=globalThis){if(this._isDisposed)throw new Error("Calling cancelAndSet on a disposed IntervalTimer");this.cancel();let s=i.setInterval(()=>{e()},t);this._disposable={dispose:()=>{i.clearInterval(s),this._disposable=void 0}}}dispose(){this.cancel(),this._isDisposed=!0}};function pe(e){let t=e;if(t?.ownerDocument?.defaultView)return t.ownerDocument.defaultView;let i=e;return i?.view?i.view:window}var io=class{constructor(e,t,i,s){this._node=e,this._type=t,this._handler=i,this._options=s,e.addEventListener(t,i,s)}dispose(){!this._node||!this._handler||(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function D(e,t,i,s){return new io(e,t,i,s)}function Ls(e,t,i,s){return D(e,t,i,s)}var we={CLICK:"click",MOUSE_DOWN:"mousedown",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",KEY_DOWN:"keydown",KEY_UP:"keyup",INPUT:"input",BLUR:"blur",FOCUS:"focus",CHANGE:"change",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",POINTER_UP:"pointerup",MOUSE_WHEEL:"wheel",WHEEL:"wheel"};function so(e){let t=e.getBoundingClientRect(),i=pe(e);return{left:t.left+i.scrollX,top:t.top+i.scrollY,width:t.width,height:t.height}}var Sr=class{constructor(e,t){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){console.error(e)}}static sort(e,t){return t.priority-e.priority}},Rs=new Map;function wr(e){let t=Rs.get(e);return t||(t={next:[],current:[],animFrameRequested:!1,inAnimationFrameRunner:!1},Rs.set(e,t)),t}function ro(e){let t=wr(e);for(t.animFrameRequested=!1,t.current=t.next,t.next=[],t.inAnimationFrameRunner=!0;t.current.length>0;)t.current.sort(Sr.sort),t.current.shift().execute();t.inAnimationFrameRunner=!1}function Vi(e,t,i=0){let s=wr(e),r=new Sr(t,i);return s.next.push(r),s.animFrameRequested||(s.animFrameRequested=!0,e.requestAnimationFrame(()=>ro(e))),r}var no=class extends to{constructor(e){super(),this._defaultTarget=e?pe(e):void 0}cancelAndSet(e,t,i){super.cancelAndSet(e,t,i??this._defaultTarget??window)}},_t=class{constructor(e){this.domNode=e,this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._className="",this._position="",this._layerHint=!1,this._contain="none"}setWidth(e){let t=Ye(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=Ye(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=Ye(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=Ye(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=Ye(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=Ye(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,e?this.domNode.style.transform="translate3d(0px, 0px, 0px)":this.domNode.style.transform="")}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}};function Ye(e){return typeof e=="number"?`${e}px`:e}var br={};Fn(br,{getSafariVersion:()=>ao,getZoomFactor:()=>yr,isChrome:()=>ji,isChromeOS:()=>Cr,isFirefox:()=>At,isLegacyEdge:()=>oo,isLinux:()=>Ji,isMac:()=>fe,isNode:()=>Yi,isSafari:()=>Gi,isWindows:()=>$t});var Yi=!!(typeof process<"u"&&"title"in process&&(typeof navigator>"u"||navigator.userAgent.startsWith("Node.js/"))),et=Yi?"node":navigator.userAgent,Xi=Yi?"node":navigator.platform,At=et.includes("Firefox"),ji=et.includes("Chrome"),oo=et.includes("Edge"),Gi=/^((?!chrome|android).)*safari/i.test(et);function yr(e){return 1}function ao(){if(!Gi)return 0;let e=et.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1],10)}var fe=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(Xi),$t=["Windows","Win16","Win32","WinCE"].includes(Xi),Ji=Xi.indexOf("Linux")>=0,Cr=/\bCrOS\b/.test(et),Ts=new WeakMap;function ho(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,i=e.parent.location;if(t.origin!=="null"&&i.origin!=="null"&&t.origin!==i.origin)return null}catch{return null}return e.parent}var lo=class{static _getSameOriginWindowChain(e){let t=Ts.get(e);if(!t){t=[],Ts.set(e,t);let i=e,s;do s=ho(i),s?t.push({window:new WeakRef(i),iframeElement:i.frameElement??null}):t.push({window:new WeakRef(i),iframeElement:null}),i=s;while(i)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let i=0,s=0,r=this._getSameOriginWindowChain(e);for(let n of r){let o=n.window.deref();if(i+=o?.scrollY??0,s+=o?.scrollX??0,o===t||!n.iframeElement)break;let h=n.iframeElement.getBoundingClientRect();i+=h.top,s+=h.left}return{top:i,left:s}}},ci=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail??1,t.type==="dblclick"&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX=="number"?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let i=lo.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=i.left,this.posy-=i.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},Ps=class{constructor(e,t=0,i=0){this.browserEvent=e??null,this.target=e?e.target??e.targetNode??e.srcElement??null:null,this.deltaY=i,this.deltaX=t;let s=!1;if(ji){let r=navigator.userAgent.match(/Chrome\/(\d+)/);s=(r?parseInt(r[1],10):123)<=122}if(e){let r=e,n=e,o=e.view?.devicePixelRatio??1;if(typeof r.wheelDeltaY<"u")s?this.deltaY=r.wheelDeltaY/(120*o):this.deltaY=r.wheelDeltaY/120;else if(typeof n.VERTICAL_AXIS<"u"&&n.axis===n.VERTICAL_AXIS)this.deltaY=-n.detail/3;else if(e.type==="wheel"){let h=e;h.deltaMode===h.DOM_DELTA_LINE?At&&!fe?this.deltaY=-e.deltaY/3:this.deltaY=-e.deltaY:this.deltaY=-e.deltaY/40}if(typeof r.wheelDeltaX<"u")Gi&&$t?this.deltaX=-(r.wheelDeltaX/120):s?this.deltaX=r.wheelDeltaX/(120*o):this.deltaX=r.wheelDeltaX/120;else if(typeof n.HORIZONTAL_AXIS<"u"&&n.axis===n.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type==="wheel"){let h=e;h.deltaMode===h.DOM_DELTA_LINE?At&&!fe?this.deltaX=-e.deltaX/3:this.deltaX=-e.deltaX:this.deltaX=-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(s?this.deltaY=e.wheelDelta/(120*o):this.deltaY=e.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},kr=class{constructor(){this._hooks=new Qe,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let t=this._onStopCallback;this._onStopCallback=null,e&&t&&t()}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,i,s,r){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=s,this._onStopCallback=r;let n=e;try{e.setPointerCapture(t),this._hooks.add(O(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{n=pe(e)}this._hooks.add(D(n,we.POINTER_MOVE,o=>{if(o.buttons!==i){this.stopMonitoring(!0);return}o.preventDefault(),this._pointerMoveCallback(o)})),this._hooks.add(D(n,we.POINTER_UP,o=>this.stopMonitoring(!0)))}},Zi=class extends L{_onclick(e,t){this._register(D(e,we.CLICK,i=>t(new ci(pe(e),i))))}_onmouseover(e,t){this._register(D(e,we.MOUSE_OVER,i=>t(new ci(pe(e),i))))}_onmouseleave(e,t){this._register(D(e,we.MOUSE_LEAVE,i=>t(new ci(pe(e),i))))}},co=class extends Zi{constructor(e){super(),this._handleActivate=e.handleActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="xterm-arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=e.bgWidth+"px",this.bgDomNode.style.height=e.bgHeight+"px",typeof e.top<"u"&&(this.bgDomNode.style.top="0px"),typeof e.left<"u"&&(this.bgDomNode.style.left="0px"),typeof e.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof e.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=e.className,this.domNode.style.position="absolute";let t=Math.min(e.bgWidth,e.bgHeight);this.domNode.style.width=t+"px",this.domNode.style.height=t+"px",typeof e.top<"u"&&(this.domNode.style.top=e.top+"px"),typeof e.left<"u"&&(this.domNode.style.left=e.left+"px"),typeof e.bottom<"u"&&(this.domNode.style.bottom=e.bottom+"px"),typeof e.right<"u"&&(this.domNode.style.right=e.right+"px"),this._pointerMoveMonitor=this._register(new kr),this._register(Ls(this.bgDomNode,we.POINTER_DOWN,i=>this._arrowPointerDown(i))),this._register(Ls(this.domNode,we.POINTER_DOWN,i=>this._arrowPointerDown(i))),this._pointerdownRepeatTimer=this._register(new no),this._pointerdownScheduleRepeatTimer=this._register(new Kt)}_arrowPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._handleActivate(),1e3/24,pe(e))};this._handleActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(t,200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,i=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault()}},y=class{constructor(){this._listeners=[],this._disposed=!1}get event(){return this._event?this._event:(this._event=(e,t,i)=>{if(this._disposed)return O(()=>{});let s={fn:e,thisArgs:t};this._listeners.push(s);let r=O(()=>{let n=this._listeners.indexOf(s);n!==-1&&this._listeners.splice(n,1)});return i&&(Array.isArray(i)?i.push(r):i.add(r)),r},this._event)}fire(e){if(!this._disposed)switch(this._listeners.length){case 0:return;case 1:{let{fn:t,thisArgs:i}=this._listeners[0];t.call(i,e);return}default:{let t=this._listeners.slice();for(let{fn:i,thisArgs:s}of t)i.call(s,e)}}}dispose(){this._disposed||(this._disposed=!0,this._listeners.length=0)}},he;(e=>{function t(n,o){return n(h=>o.fire(h))}e.forward=t;function i(n,o){return(h,l,a)=>n(c=>h.call(l,o(c)),void 0,a)}e.map=i;function s(...n){return(o,h,l)=>{let a=new Qe;for(let c of n)a.add(c(d=>o.call(h,d)));return l&&(Array.isArray(l)?l.push(a):l.add(a)),a}}e.any=s;function r(n,o,h){return o(h),n(l=>o(l))}e.runAndSubscribe=r})(he||={});var _o=class wi{constructor(t,i,s,r,n,o,h){this._forceIntegerValues=t,this._scrollStateBrand=void 0,this._forceIntegerValues&&(i=i|0,s=s|0,r=r|0,n=n|0,o=o|0,h=h|0),this.rawScrollLeft=r,this.rawScrollTop=h,i<0&&(i=0),r+i>s&&(r=s-i),r<0&&(r=0),n<0&&(n=0),h+n>o&&(h=o-n),h<0&&(h=0),this.width=i,this.scrollWidth=s,this.scrollLeft=r,this.height=n,this.scrollHeight=o,this.scrollTop=h}equals(t){return this.rawScrollLeft===t.rawScrollLeft&&this.rawScrollTop===t.rawScrollTop&&this.width===t.width&&this.scrollWidth===t.scrollWidth&&this.scrollLeft===t.scrollLeft&&this.height===t.height&&this.scrollHeight===t.scrollHeight&&this.scrollTop===t.scrollTop}withScrollDimensions(t,i){return new wi(this._forceIntegerValues,typeof t.width<"u"?t.width:this.width,typeof t.scrollWidth<"u"?t.scrollWidth:this.scrollWidth,i?this.rawScrollLeft:this.scrollLeft,typeof t.height<"u"?t.height:this.height,typeof t.scrollHeight<"u"?t.scrollHeight:this.scrollHeight,i?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new wi(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<"u"?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<"u"?t.scrollTop:this.rawScrollTop)}createScrollEvent(t,i){let s=this.width!==t.width,r=this.scrollWidth!==t.scrollWidth,n=this.scrollLeft!==t.scrollLeft,o=this.height!==t.height,h=this.scrollHeight!==t.scrollHeight,l=this.scrollTop!==t.scrollTop;return{inSmoothScrolling:i,oldWidth:t.width,oldScrollWidth:t.scrollWidth,oldScrollLeft:t.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:t.height,oldScrollHeight:t.scrollHeight,oldScrollTop:t.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:s,scrollWidthChanged:r,scrollLeftChanged:n,heightChanged:o,scrollHeightChanged:h,scrollTopChanged:l}}},xr=class extends L{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new y),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new _o(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){let i=this._state.withScrollDimensions(e,t);this._setState(i,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0){this.setScrollPositionNow(e);return}if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>"u"?this._smoothScrolling.to.scrollTop:e.scrollTop};let i=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===i.scrollLeft&&this._smoothScrolling.to.scrollTop===i.scrollTop)return;let s;t?s=new _i(this._smoothScrolling.from,i,this._smoothScrolling.startTime,this._smoothScrolling.duration):s=_i.start(this._state,i,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=s}else{let i=this._state.withScrollPosition(e);this._smoothScrolling=_i.start(this._state,i,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),!!this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let i=this._state;i.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(i,t)))}},As=class{constructor(e,t,i){this.scrollLeft=e,this.scrollTop=t,this.isDone=i}};function di(e,t){let i=t-e;return function(s){return e+i*po(s)}}function uo(e,t,i){return function(s){return s2.5*s){let r,n;return t{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(e){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(e?" xterm-fade":"")))}},vo=140,Er=class extends Zi{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new go(e.visibility,"xterm-visible xterm-scrollbar "+e.extraScrollbarClassName,"xterm-invisible xterm-scrollbar "+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new kr),this._shouldRender=!0,this.domNode=new _t(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(D(this.domNode.domNode,we.POINTER_DOWN,t=>this._domNodePointerDown(t)))}_createArrow(e){let t=this._register(new co(e));return this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode),t}_createSlider(e,t,i,s){this.slider=new _t(document.createElement("div")),this.slider.setClassName("xterm-slider"),this.slider.setPosition("absolute"),this.slider.setTop(e),this.slider.setLeft(t),typeof i=="number"&&this.slider.setWidth(i),typeof s=="number"&&this.slider.setHeight(s),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(D(this.slider.domNode,we.POINTER_DOWN,r=>{r.button===0&&(r.preventDefault(),this._sliderPointerDown(r))})),this._onclick(this.slider.domNode,r=>{r.leftButton&&r.stopPropagation()})}_handleElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_handleElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_handleElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._handlePointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,i=t+this._scrollbarState.getSliderPosition(),s=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),r=this._sliderPointerPosition(e);i<=r&&r<=s?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._handlePointerDown(e)}_handlePointerDown(e){let t,i;if(e.target===this.domNode.domNode&&typeof e.offsetX=="number"&&typeof e.offsetY=="number")t=e.offsetX,i=e.offsetY;else{let r=so(this.domNode.domNode);t=e.pageX-r.left,i=e.pageY-r.top}let s=this._pointerDownRelativePosition(t,i);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(s):this._scrollbarState.getDesiredScrollPositionFromOffset(s)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),i=this._sliderOrthogonalPointerPosition(e),s=this._scrollbarState.clone();this.slider.toggleClassName("xterm-active",!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,r=>{let n=this._sliderOrthogonalPointerPosition(r),o=Math.abs(n-i);if($t&&o>vo){this._setDesiredScrollPositionNow(s.getScrollPosition());return}let h=this._sliderPointerPosition(r)-t;this._setDesiredScrollPositionNow(s.getDesiredScrollPositionFromDelta(h))},()=>{this.slider.toggleClassName("xterm-active",!1),this._host.handleDragEnd()}),this._host.handleDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},Dr=class bi{constructor(t,i,s,r,n,o){this._scrollbarSize=Math.round(i),this._oppositeScrollbarSize=Math.round(s),this._arrowSize=Math.round(t),this._visibleSize=r,this._scrollSize=n,this._scrollPosition=o,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new bi(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(t){let i=Math.round(t);return this._visibleSize!==i?(this._visibleSize=i,this._refreshComputedValues(),!0):!1}setScrollSize(t){let i=Math.round(t);return this._scrollSize!==i?(this._scrollSize=i,this._refreshComputedValues(),!0):!1}setScrollPosition(t){let i=Math.round(t);return this._scrollPosition!==i?(this._scrollPosition=i,this._refreshComputedValues(),!0):!1}setScrollbarSize(t){this._scrollbarSize=Math.round(t)}setArrowSize(t){let i=Math.round(t);this._arrowSize!==i&&(this._arrowSize=i,this._refreshComputedValues())}setOppositeScrollbarSize(t){this._oppositeScrollbarSize=Math.round(t)}static _computeValues(t,i,s,r,n){let o=Math.max(0,s-t),h=Math.max(0,o-2*i),l=r>0&&r>s;if(!l)return{computedAvailableSize:Math.round(o),computedIsNeeded:l,computedSliderSize:Math.round(h),computedSliderRatio:0,computedSliderPosition:0};let a=Math.round(Math.max(20,Math.floor(s*h/r))),c=(h-a)/(r-s),d=n*c;return{computedAvailableSize:Math.round(o),computedIsNeeded:l,computedSliderSize:Math.round(a),computedSliderRatio:c,computedSliderPosition:Math.round(d)}}_refreshComputedValues(){let t=bi._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(t){if(!this._computedIsNeeded)return 0;let i=t-this._arrowSize-this._computedSliderSize/2;return Math.round(i/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(t){if(!this._computedIsNeeded)return 0;let i=t-this._arrowSize,s=this._scrollPosition;return ithis._arrowScroll(-this._arrowScrollDelta)}),this._arrowDown=this._createArrow({className:"xterm-scra xterm-arrow-down",bottom:0,left:0,bgWidth:t,bgHeight:t,handleActivate:()=>this._arrowScroll(this._arrowScrollDelta)})),this._updateArrowSize(this._arrowUp,t),this._updateArrowSize(this._arrowDown,t),!this._arrowUp||!this._arrowDown)return;let i=e?"":"none";this._arrowUp.bgDomNode.style.display=i,this._arrowUp.domNode.style.display=i,this._arrowDown.bgDomNode.style.display=i,this._arrowDown.domNode.style.display=i}_updateArrowSize(e,t){e&&(e.bgDomNode.style.width=`${t}px`,e.bgDomNode.style.height=`${t}px`,e.domNode.style.width=`${t}px`,e.domNode.style.height=`${t}px`)}updateOptions(e){let t=e.verticalHasArrows?e.verticalScrollbarSize:0;this._scrollbarState.setArrowSize(t),this._setArrows(e.verticalHasArrows,e.verticalScrollbarSize),this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},wo=class{constructor(e,t,i){this.timestamp=e,this.deltaX=t,this.deltaY=i,this.score=0}},yi=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let t=1,i=0,s=1,r=this._rear;for(;r!==-1;){let n=r===this._front?t:Math.pow(2,-s);if(t-=n,i+=this._memory[r].score*n,r===this._front)break;r=(this._capacity+r-1)%this._capacity,s++}return i<=.5}acceptStandardWheelEvent(t){if(ji){let i=pe(t.browserEvent),s=yr(i);this.accept(Date.now(),t.deltaX*s,t.deltaY*s)}else this.accept(Date.now(),t.deltaX,t.deltaY)}accept(t,i,s){let r=null,n=new wo(t,i,s);this._front===-1&&this._rear===-1?(this._memory[0]=n,this._front=0,this._rear=0):(r=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=n),n.score=this._computeScore(n,r)}_computeScore(t,i){if(Math.abs(t.deltaX)>0&&Math.abs(t.deltaY)>0)return 1;let s=.5;if((!this._isAlmostInt(t.deltaX)||!this._isAlmostInt(t.deltaY))&&(s+=.25),i){let r=Math.abs(t.deltaX),n=Math.abs(t.deltaY),o=Math.abs(i.deltaX),h=Math.abs(i.deltaY),l=Math.max(Math.min(r,o),1),a=Math.max(Math.min(n,h),1),c=Math.max(r,o),d=Math.max(n,h);c%l===0&&d%a===0&&(s-=.5)}return Math.min(Math.max(s,0),1)}_isAlmostInt(t){return Math.abs(Math.round(t)-t)<.01}};yi.INSTANCE=new yi;var bo=yi,yo=class extends Zi{constructor(e,t,i){super(),this._onScroll=this._register(new y),this.onScroll=this._onScroll.event,t=t??{};let s,r=!i;i?s=i:(t.mouseWheelSmoothScroll=!1,s=new xr({forceIntegerValues:!0,smoothScrollDuration:0,scheduleAtNextAnimationFrame:o=>Vi(pe(e),o)})),this._options=Co(t),this._scrollable=s,this._register(this._scrollable.onScroll(o=>{this._handleScroll(o),this._onScroll.fire(o)})),r&&this._register(this._scrollable);let n={handleMouseWheel:o=>this._handleMouseWheel(o),handleDragStart:()=>this._handleDragStart(),handleDragEnd:()=>this._handleDragEnd()};this._verticalScrollbar=this._register(new So(this._scrollable,this._options,n)),this._horizontalScrollbar=this._register(new mo(this._scrollable,this._options,n)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=new _t(document.createElement("div")),this._leftShadowDomNode.setClassName("xterm-shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=new _t(document.createElement("div")),this._topShadowDomNode.setClassName("xterm-shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=new _t(document.createElement("div")),this._topLeftShadowDomNode.setClassName("xterm-shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode??this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this._onmouseover(this._listenOnDomNode,o=>this._handleMouseOver(o)),this._onmouseleave(this._listenOnDomNode,o=>this._handleMouseLeave(o)),this._hideTimeout=this._register(new Kt),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=ut(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}updateClassName(e){this._options.className=e,fe&&(this._options.className+=" xterm-mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(e){typeof e.handleMouseWheel<"u"&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<"u"&&(this._options.horizontal=e.horizontal),typeof e.vertical<"u"&&(this._options.vertical=e.vertical),typeof e.horizontalHasArrows<"u"&&(this._options.horizontalHasArrows=e.horizontalHasArrows),typeof e.verticalHasArrows<"u"&&(this._options.verticalHasArrows=e.verticalHasArrows),typeof e.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<"u"&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}delegateScrollFromMouseWheelEvent(e){this._handleMouseWheel(new Ps(e))}_setListeningToMouseWheel(e){if(this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=ut(this._mouseWheelToDispose),e)){let t=i=>{this._handleMouseWheel(new Ps(i))};this._mouseWheelToDispose.push(D(this._listenOnDomNode,we.MOUSE_WHEEL,t,{passive:!1}))}}_handleMouseWheel(e){if(e.browserEvent?.defaultPrevented)return;let t=bo.INSTANCE;t.acceptStandardWheelEvent(e);let i=!1;if(e.deltaY||e.deltaX){let r=e.deltaY*this._options.mouseWheelScrollSensitivity,n=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&n+r===0?n=r=0:Math.abs(r)>=Math.abs(n)?n=0:r=0),this._options.flipAxes&&([r,n]=[n,r]);let o=!fe&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||o)&&!n&&(n=r,r=0),e.browserEvent&&e.browserEvent.altKey&&(n=n*this._options.fastScrollSensitivity,r=r*this._options.fastScrollSensitivity);let h=this._scrollable.getFutureScrollPosition(),l={};if(r){let a=50*r,c=h.scrollTop-(a<0?Math.floor(a):Math.ceil(a));this._verticalScrollbar.writeScrollPosition(l,c)}if(n){let a=50*n,c=h.scrollLeft-(a<0?Math.floor(a):Math.ceil(a));this._horizontalScrollbar.writeScrollPosition(l,c)}l=this._scrollable.validateScrollPosition(l),(h.scrollLeft!==l.scrollLeft||h.scrollTop!==l.scrollTop)&&(this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(l):this._scrollable.setScrollPositionNow(l),i=!0)}let s=i;!s&&this._options.alwaysConsumeMouseWheel&&(s=!0),!s&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(s=!0),s&&(e.preventDefault(),e.stopPropagation())}_handleScroll(e){this._shouldRender=this._horizontalScrollbar.handleScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.handleScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,i=e.scrollLeft>0,s=i?" xterm-shadow-left":"",r=t?" xterm-shadow-top":"",n=i||t?" xterm-shadow-top-left-corner":"";this._leftShadowDomNode.setClassName(`xterm-shadow${s}`),this._topShadowDomNode.setClassName(`xterm-shadow${r}`),this._topLeftShadowDomNode.setClassName(`xterm-shadow${n}${r}${s}`)}}_handleDragStart(){this._isDragging=!0,this._reveal()}_handleDragEnd(){this._isDragging=!1,this._hide()}_handleMouseLeave(e){this._mouseIsOver=!1,this._hide()}_handleMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),500)}};function Co(e){let t={lazyRender:typeof e.lazyRender<"u"?e.lazyRender:!1,className:typeof e.className<"u"?e.className:"",useShadows:typeof e.useShadows<"u"?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<"u"?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<"u"?e.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<"u"?e.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<"u"?e.alwaysConsumeMouseWheel:!1,scrollYToX:typeof e.scrollYToX<"u"?e.scrollYToX:!1,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<"u"?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<"u"?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<"u"?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<"u"?e.mouseWheelSmoothScroll:!0,listenOnDomNode:typeof e.listenOnDomNode<"u"?e.listenOnDomNode:null,horizontal:typeof e.horizontal<"u"?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<"u"?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<"u"?e.horizontalHasArrows:!1,vertical:typeof e.vertical<"u"?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<"u"?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<"u"?e.verticalHasArrows:!1,verticalSliderSize:typeof e.verticalSliderSize<"u"?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<"u"?e.scrollByPage:!1};return t.horizontalSliderSize=typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<"u"?e.verticalSliderSize:t.verticalScrollbarSize,fe&&(t.className+=" xterm-mac"),t}var Ci=class extends L{constructor(e,t,i,s,r,n,o,h,l){super(),this._bufferService=i,this._coreService=r,this._optionsService=h,this._renderService=l,this._onRequestScrollLines=this._register(new y),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1,this._needsSyncOnRender=!1;let a=this._register(new xr({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:c=>Vi(s.window,c)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{a.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new yo(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,verticalHasArrows:this._optionsService.rawOptions.scrollbar?.showArrows??!1,...this._getChangeOptions()},a)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","scrollbar"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(n.onProtocolChange(c=>{this._scrollableElement.updateOptions({handleMouseWheel:!(c&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(he.runAndSubscribe(o.onChangeColors,()=>{e.style.backgroundColor=o.colors.background.css,this._scrollableElement.getDomNode().style.backgroundColor=o.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(O(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=s.mainDocument.createElement("style"),t.appendChild(this._styleElement),this._register(O(()=>this._styleElement.remove())),this._register(he.runAndSubscribe(o.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .xterm-scrollbar > .xterm-slider {",` background: ${o.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .xterm-scrollbar > .xterm-slider:hover {",` background: ${o.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .xterm-scrollbar > .xterm-slider.xterm-active {",` background: ${o.colors.scrollbarSliderActiveBackground.css};`,"}"].join(` -`)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._renderService.onRender(()=>{this._needsSyncOnRender&&(this._needsSyncOnRender=!1,this._sync())})),this._register(this._scrollableElement.onScroll(c=>this._handleScroll(c)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){let e=this._optionsService.rawOptions.scrollbar?.showScrollbar??!0,t=this._optionsService.rawOptions.scrollbar?.showArrows??!1,i=e?this._optionsService.rawOptions.scrollbar?.width??14:0;return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,vertical:e?1:2,verticalScrollbarSize:i,verticalHasArrows:t}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){if(!(!this._renderService||this._isSyncing)){if(this._coreService.decPrivateModes.synchronizedOutput){this._needsSyncOnRender=!0;return}this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1}}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),i=t-this._bufferService.buffer.ydisp;i!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(i)),this._isHandlingScroll=!1}handleTouchScroll(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({scrollTop:t.scrollTop-e})}};Ci=F([g(2,ne),g(3,be),g(4,Ee),g(5,Ft),g(6,Ze),g(7,oe),g(8,ye)],Ci);var ki=class extends L{constructor(e,t,i,s,r){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=i,this._decorationService=s,this._renderService=r,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(n=>this._removeDecoration(n))),this._register(O(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement("div");t.classList.add("xterm-decoration"),t.classList.toggle("xterm-decoration-top-layer",e?.options?.layer==="top"),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let i=e.options.x??0;return i&&i>this._bufferService.cols&&(t.style.display="none"),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display="none",e.onRenderEmitter.fire(e.element));else{let i=this._decorationElements.get(e);i||(i=this._createElement(e),e.element=i,this._decorationElements.set(e,i),this._container.appendChild(i),e.onDispose(()=>{this._decorationElements.delete(e),i.remove()})),i.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(i.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,i.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,i.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,i.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(i)}}_refreshXPosition(e,t=e.element){if(!t)return;let i=e.options.x??0;(e.options.anchor||"left")==="right"?t.style.right=i?`${i*this._renderService.dimensions.css.cell.width}px`:"":t.style.left=i?`${i*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};ki=F([g(1,ne),g(2,be),g(3,mt),g(4,ye)],ki);var ko=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,i){return t>=e.startBufferLine-this._linePadding[i||"full"]&&t<=e.endBufferLine+this._linePadding[i||"full"]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},me={full:0,left:0,center:0,right:0},Pe={full:0,left:0,center:0,right:0},st={full:0,left:0,center:0,right:0},Ot=class extends L{constructor(e,t,i,s,r,n,o,h){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=i,this._decorationService=s,this._renderService=r,this._optionsService=n,this._themeService=o,this._coreBrowserService=h,this._colorZoneStore=new ko,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(O(()=>this._canvas?.remove()));let l=this._canvas.getContext("2d");if(l)this._ctx=l;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onDimensionsChange(()=>this._queueRefresh(!0))),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("scrollbar",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._register(O(()=>{this._animationFrame!==void 0&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)})),this._queueRefresh(!0)}get _width(){let e=this._optionsService.rawOptions.scrollbar;return e?.showScrollbar??!0?e?.width??0:0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);Pe.full=this._canvas.width,Pe.left=e,Pe.center=t,Pe.right=e,this._refreshDrawHeightConstants(),st.full=1,st.left=1,st.center=1+Pe.left,st.right=1+Pe.left+Pe.center}_refreshDrawHeightConstants(){me.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);me.left=t,me.center=t,me.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){if(this._store.isDisposed||!this._renderService.hasRenderer())return;let e=this._renderService.dimensions.css.canvas.height,t=this._renderService.dimensions.device.canvas.height;this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${e}px`,this._canvas.height=t,this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){if(this._store.isDisposed||!this._renderService.hasRenderer())return;this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let t of this._decorationService.decorations)this._colorZoneStore.addDecoration(t);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!=="full"&&this._renderColorZone(t);for(let t of e)t.position==="full"&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.scrollbar?.overviewRuler?.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.scrollbar?.overviewRuler?.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(st[e.position||"full"],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-me[e.position||"full"]/2),Pe[e.position||"full"],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+me[e.position||"full"]))}_queueRefresh(e,t){this._store.isDisposed||(this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._store.isDisposed||this._refreshDecorations(),this._animationFrame=void 0})))}};Ot=F([g(2,ne),g(3,mt),g(4,ye),g(5,oe),g(6,Ze),g(7,be)],Ot);var xi=class{constructor(e,t,i,s,r,n){this._textarea=e,this._compositionView=t,this._bufferService=i,this._optionsService=s,this._coreService=r,this._renderService=n,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._compositionSuffix="",this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0;let e=this._textarea.selectionStart??this._textarea.value.length,t=this._textarea.selectionEnd??e;this._compositionPosition.start=Math.min(e,t),this._compositionPosition.end=Math.max(e,t),this._compositionSuffix=this._textarea.value.substring(this._compositionPosition.end),this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(e){this._compositionView.textContent=`\u200E${e.data}\u200E`,this.updateCompositionElements(),setTimeout(()=>{let t=this._textarea.selectionEnd??this._textarea.value.length;this._compositionPosition.end=Math.max(this._compositionPosition.start,t)},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(e){if(this._compositionView.classList.remove("active"),this._isComposing=!1,e){let t={start:this._compositionPosition.start,end:this._compositionPosition.end},i=this._compositionSuffix;this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let s;if(t.start+=this._dataAlreadySent.length,this._isComposing)s=this._textarea.value.substring(t.start,this._compositionPosition.start);else{let r=this._textarea.value,n=i.length>0&&r.endsWith(i)?r.length-i.length:r.length;s=r.substring(t.start,Math.max(t.start,n))}s.length>0&&this._coreService.triggerDataEvent(s,!0)}},0)}else{this._isSendingComposition=!1;let t=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(t,!0)}}_handleAnyTextareaChanges(){if(this._textareaChangeTimer)return;let e=this._textarea.value;this._textareaChangeTimer=window.setTimeout(()=>{if(this._textareaChangeTimer=void 0,!this._isComposing){let t=this._textarea.value,i=t.replace(e,"");this._dataAlreadySent=i,t.length>e.length?this._coreService.triggerDataEvent(i,!0):t.lengththis.updateCompositionElements(!0),0)}}};xi=F([g(2,ne),g(3,oe),g(4,Ee),g(5,ye)],xi);var J=0,Z=0,Q=0,z=0,Os={css:"#00000000",rgba:0},$;(e=>{function t(r,n,o,h){return h!==void 0?`#${Fe(r)}${Fe(n)}${Fe(o)}${Fe(h)}`:`#${Fe(r)}${Fe(n)}${Fe(o)}`}e.toCss=t;function i(r,n,o,h=255){return(r<<24|n<<16|o<<8|h)>>>0}e.toRgba=i;function s(r,n,o,h){return{css:e.toCss(r,n,o,h),rgba:e.toRgba(r,n,o,h)}}e.toColor=s})($||={});var H;(e=>{function t(l,a){if(z=(a.rgba&255)/255,z===1)return{css:a.css,rgba:a.rgba};let c=a.rgba>>24&255,d=a.rgba>>16&255,u=a.rgba>>8&255,f=l.rgba>>24&255,_=l.rgba>>16&255,p=l.rgba>>8&255;J=f+Math.round((c-f)*z),Z=_+Math.round((d-_)*z),Q=p+Math.round((u-p)*z);let S=$.toCss(J,Z,Q),k=$.toRgba(J,Z,Q);return{css:S,rgba:k}}e.blend=t;function i(l){return(l.rgba&255)===255}e.isOpaque=i;function s(l,a,c){let d=Lt.ensureContrastRatio(l.rgba,a.rgba,c);if(d)return $.toColor(d>>24&255,d>>16&255,d>>8&255)}e.ensureContrastRatio=s;function r(l){let a=(l.rgba|255)>>>0;return[J,Z,Q]=Lt.toChannels(a),{css:$.toCss(J,Z,Q),rgba:a}}e.opaque=r;function n(l,a){return z=Math.round(a*255),[J,Z,Q]=Lt.toChannels(l.rgba),{css:$.toCss(J,Z,Q,z),rgba:$.toRgba(J,Z,Q,z)}}e.opacity=n;function o(l,a){return z=l.rgba&255,n(l,z*a/255)}e.multiplyOpacity=o;function h(l){return[l.rgba>>24&255,l.rgba>>16&255,l.rgba>>8&255]}e.toColorRGB=h})(H||={});var W;(e=>{let t,i;try{let r=document.createElement("canvas");r.width=1,r.height=1;let n=r.getContext("2d",{willReadFrequently:!0});n&&(t=n,t.globalCompositeOperation="copy",i=t.createLinearGradient(0,0,1,1))}catch{}function s(r){if(r.match(/#[\da-f]{3,8}/i))switch(r.length){case 4:return J=parseInt(r.slice(1,2).repeat(2),16),Z=parseInt(r.slice(2,3).repeat(2),16),Q=parseInt(r.slice(3,4).repeat(2),16),$.toColor(J,Z,Q);case 5:return J=parseInt(r.slice(1,2).repeat(2),16),Z=parseInt(r.slice(2,3).repeat(2),16),Q=parseInt(r.slice(3,4).repeat(2),16),z=parseInt(r.slice(4,5).repeat(2),16),$.toColor(J,Z,Q,z);case 7:return{css:r,rgba:(parseInt(r.slice(1),16)<<8|255)>>>0};case 9:return{css:r,rgba:parseInt(r.slice(1),16)>>>0}}let n=r.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(n)return J=parseInt(n[1],10),Z=parseInt(n[2],10),Q=parseInt(n[3],10),z=Math.round((n[5]===void 0?1:parseFloat(n[5]))*255),$.toColor(J,Z,Q,z);if(r==="transparent")return{css:"transparent",rgba:0};if(!t||!i)throw new Error("css.toColor: Unsupported css format");if(t.fillStyle=i,t.fillStyle=r,typeof t.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(t.fillRect(0,0,1,1),[J,Z,Q,z]=t.getImageData(0,0,1,1).data,z!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:$.toRgba(J,Z,Q,z),css:r}}e.toColor=s})(W||={});var ie;(e=>{function t(s){return i(s>>16&255,s>>8&255,s&255)}e.relativeLuminance=t;function i(s,r,n){let o=s/255,h=r/255,l=n/255,a=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),c=h<=.03928?h/12.92:Math.pow((h+.055)/1.055,2.4),d=l<=.03928?l/12.92:Math.pow((l+.055)/1.055,2.4);return a*.2126+c*.7152+d*.0722}e.relativeLuminance2=i})(ie||={});var Lt;(e=>{function t(o,h){if(z=(h&255)/255,z===1)return h;let l=h>>24&255,a=h>>16&255,c=h>>8&255,d=o>>24&255,u=o>>16&255,f=o>>8&255;return J=d+Math.round((l-d)*z),Z=u+Math.round((a-u)*z),Q=f+Math.round((c-f)*z),$.toRgba(J,Z,Q)}e.blend=t;function i(o,h,l){let a=ie.relativeLuminance(o>>8),c=ie.relativeLuminance(h>>8);if(Be(a,c)>8));if(_>8));return _>S?f:p}return f}let d=r(o,h,l),u=Be(a,ie.relativeLuminance(d>>8));if(u>8));return u>_?d:f}return d}}e.ensureContrastRatio=i;function s(o,h,l){let a=o>>24&255,c=o>>16&255,d=o>>8&255,u=h>>24&255,f=h>>16&255,_=h>>8&255,p=Be(ie.relativeLuminance2(u,f,_),ie.relativeLuminance2(a,c,d));for(;p0||f>0||_>0);)u-=Math.max(0,Math.ceil(u*.1)),f-=Math.max(0,Math.ceil(f*.1)),_-=Math.max(0,Math.ceil(_*.1)),p=Be(ie.relativeLuminance2(u,f,_),ie.relativeLuminance2(a,c,d));return(u<<24|f<<16|_<<8|255)>>>0}e.reduceLuminance=s;function r(o,h,l){let a=o>>24&255,c=o>>16&255,d=o>>8&255,u=h>>24&255,f=h>>16&255,_=h>>8&255,p=Be(ie.relativeLuminance2(u,f,_),ie.relativeLuminance2(a,c,d));for(;p>>0}e.increaseLuminance=r;function n(o){return[o>>24&255,o>>16&255,o>>8&255,o&255]}e.toChannels=n})(Lt||={});function Fe(e){let t=e.toString(16);return t.length<2?"0"+t:t}function Be(e,t){return e1){let d=this._getJoinedRanges(s,h,o,t,n);for(let u=0;u1){let c=this._getJoinedRanges(s,h,o,t,n);for(let d=0;d=St,P=w,C=this._workCell;if(_.length>0&&w===_[0][0]&&M){let I=_.shift(),Yt=this._isCellInSelection(I[0],t);for(B=I[0]+1;B=I[1],M?(x=!0,C=new xo(this._workCell,e.translateToString(!0,I[0],I[1]),I[1]-I[0]),P=I[1]-1,b=C.getWidth()):St=I[1]}let q=this._isCellInSelection(w,t),ve=i&&w===n,Me=m&&w>=c&&w<=d;u&&C.isBlink()&&(u.hasBlinkingCells=!0),!h&&C.isBlink()&&v.push("xterm-blink-hidden");let ke=!1;this._decorationService.forEachDecorationAtCell(w,t,void 0,I=>{ke=!0});let Ne=C.getChars()||" ";if(Ne===" "&&(C.isUnderline()||C.isOverline())&&(Ne="\xA0"),Ie=b*l-a.get(Ne,C.isBold(),C.isItalic()),!k)k=this._document.createElement("span");else if(R&&(q&&Ue||!q&&!Ue&&C.bg===T)&&(q&&Ue&&p.selectionForeground||C.fg===A)&&C.extended.ext===ee&&Me===Ce&&Ie===Oe&&!ve&&!x&&!ke&&M){C.isInvisible()?E+=" ":E+=Ne,R++;continue}else R&&(k.textContent=E),k=this._document.createElement("span"),R=0,E="";if(T=C.bg,A=C.fg,ee=C.extended.ext,Ce=Me,Oe=Ie,Ue=q,x&&n>=w&&n<=P&&(n=w),!this._coreService.isCursorHidden&&ve&&this._coreService.isCursorInitialized){if(v.push("xterm-cursor"),this._coreBrowserService.isFocused)o&&v.push("xterm-cursor-blink"),v.push(s==="bar"?"xterm-cursor-bar":s==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(r)switch(r){case"outline":v.push("xterm-cursor-outline");break;case"block":v.push("xterm-cursor-block");break;case"bar":v.push("xterm-cursor-bar");break;case"underline":v.push("xterm-cursor-underline");break;default:break}}if(C.isBold()&&v.push("xterm-bold"),C.isItalic()&&v.push("xterm-italic"),C.isDim()&&v.push("xterm-dim"),C.isInvisible()?E=" ":E=C.getChars()||" ",C.isUnderline()&&(v.push(`xterm-underline-${C.extended.underlineStyle}`),E===" "&&(E="\xA0"),!C.isUnderlineColorDefault()))if(C.isUnderlineColorRGB())k.style.textDecorationColor=`rgb(${vt.toColorRGB(C.getUnderlineColor()).join(",")})`;else{let I=C.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&C.isBold()&&I<8&&(I+=8),k.style.textDecorationColor=p.ansi[I].css}C.isOverline()&&(v.push("xterm-overline"),E===" "&&(E="\xA0")),C.isStrikethrough()&&v.push("xterm-strikethrough"),Me&&(k.style.textDecoration="underline");let te=C.getFgColor(),He=C.getFgColorMode(),_e=C.getBgColor(),tt=C.getBgColorMode(),Vt=!!C.isInverse();if(Vt){let I=te;te=_e,_e=I;let Yt=He;He=tt,tt=Yt}let Le,wt,it=!1;this._decorationService.forEachDecorationAtCell(w,t,void 0,I=>{I.options.layer!=="top"&&it||(I.backgroundColorRGB&&(tt=50331648,_e=I.backgroundColorRGB.rgba>>8&16777215,Le=I.backgroundColorRGB),I.foregroundColorRGB&&(He=50331648,te=I.foregroundColorRGB.rgba>>8&16777215,wt=I.foregroundColorRGB),it=I.options.layer==="top")}),!it&&q&&(Le=this._coreBrowserService.isFocused?p.selectionBackgroundOpaque:p.selectionInactiveBackgroundOpaque,_e=Le.rgba>>8&16777215,tt=50331648,it=!0,p.selectionForeground&&(He=50331648,te=p.selectionForeground.rgba>>8&16777215,wt=p.selectionForeground)),it&&v.push("xterm-decoration-top");let Re;switch(tt){case 16777216:case 33554432:Re=p.ansi[_e],v.push(`xterm-bg-${_e}`);break;case 50331648:Re=$.toColor(_e>>16,_e>>8&255,_e&255),this._addStyle(k,`background-color:#${(_e>>>0).toString(16).padStart(6,"0")}`);break;default:Vt?(Re=p.foreground,v.push("xterm-bg-257")):Re=p.background}switch(Le||C.isDim()&&(Le=H.multiplyOpacity(Re,.5)),He){case 16777216:case 33554432:C.isBold()&&te<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(te+=8),this._applyMinimumContrast(k,Re,p.ansi[te],C,Le,void 0)||v.push(`xterm-fg-${te}`);break;case 50331648:let I=$.toColor(te>>16&255,te>>8&255,te&255);this._applyMinimumContrast(k,Re,I,C,Le,wt)||this._addStyle(k,`color:#${te.toString(16).padStart(6,"0")}`);break;default:this._applyMinimumContrast(k,Re,p.foreground,C,Le,wt)||Vt&&v.push("xterm-fg-257")}v.length&&(k.className=v.join(" "),v.length=0),!ve&&!x&&!ke&&M?R++:k.textContent=E,Ie!==this.defaultSpacing&&(k.style.letterSpacing=`${Ie}px`),f.push(k),w=P}return k&&R&&(k.textContent=E),f}_applyMinimumContrast(e,t,i,s,r,n){if(this._optionsService.rawOptions.minimumContrastRatio===1||Do(s.getCode()))return!1;let o=this._getContrastCache(s),h;if(!r&&!n&&(h=o.getColor(t.rgba,i.rgba)),h===void 0){let l=this._optionsService.rawOptions.minimumContrastRatio/(s.isDim()?2:1);h=H.ensureContrastRatio(r??t,n??i,l),o.setColor((r??t).rgba,(n??i).rgba,h??null)}return h?(this._addStyle(e,`color:${h.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute("style",`${e.getAttribute("style")||""}${t};`)}_isCellInSelection(e,t){let i=this._selectionStart,s=this._selectionEnd;return!i||!s?!1:this._columnSelectMode?i[0]<=s[0]?e>=i[0]&&t>=i[1]&&e=i[1]&&e>=s[0]&&t<=s[1]:t>i[1]&&t=i[0]&&e=i[0]}};Bi=F([g(1,vr),g(2,oe),g(3,be),g(4,Ee),g(5,mt),g(6,Ze)],Bi);var Lo=class{constructor(e=()=>new Ro){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._canvasElements=[],this._canvasElements=[e(),e(),e(),e()],this.clear()}dispose(){this._canvasElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,i,s){e===this._font&&t===this._fontSize&&i===this._weight&&s===this._weightBold||(this._font=e,this._fontSize=t,this._weight=i,this._weightBold=s,this._canvasElements[0].setFont(e,t,i,!1),this._canvasElements[1].setFont(e,t,s,!1),this._canvasElements[2].setFont(e,t,i,!0),this._canvasElements[3].setFont(e,t,s,!0),this.clear())}get(e,t,i){let s;if(!t&&!i&&e.length===1&&(s=e.charCodeAt(0))<256){if(this._flat[s]!==-9999)return this._flat[s];let o=this._measure(e,0);return o>0&&(this._flat[s]=o),o}let r=e;t&&(r+="B"),i&&(r+="I");let n=this._holey.get(r);if(n===void 0){let o=0;t&&(o|=1),i&&(o|=2),n=this._measure(e,o),n>0&&this._holey.set(r,n)}return n}_measure(e,t){return this._canvasElements[t].measure(e)}},Ro=class{constructor(){typeof OffscreenCanvas<"u"?(this._canvas=new OffscreenCanvas(1,1),this._ctx=Is(this._canvas.getContext("2d"))):(this._canvas=document.createElement("canvas"),this._canvas.width=1,this._canvas.height=1,this._ctx=Is(this._canvas.getContext("2d")))}setFont(e,t,i,s){let r=s?"italic":"";this._ctx.font=`${r} ${i} ${t}px ${e}`.trim()}measure(e){return this._ctx.measureText(e).width}},To=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,i,s=!1){if(this.selectionStart=t,this.selectionEnd=i,!t||!i||t[0]===i[0]&&t[1]===i[1]){this.clear();return}let r=e.buffers.active.ydisp,n=t[1]-r,o=i[1]-r,h=Math.max(n,0),l=Math.min(o,e.rows-1);if(h>=e.rows||l<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=s,this.viewportStartRow=n,this.viewportEndRow=o,this.viewportCappedStartRow=h,this.viewportCappedEndRow=l,this.startCol=t[0],this.endCol=i[0]}isCellSelected(e,t,i){return this.hasSelection?(i-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&i>=this.viewportCappedStartRow&&t=this.viewportCappedStartRow&&t>=this.endCol&&i<=this.viewportCappedEndRow:i>this.viewportStartRow&&i=this.startCol&&t=this.startCol):!1}};function Po(){return new To}var Ao=class extends L{constructor(e,t,i){super(),this._renderCallback=e,this._coreBrowserService=t,this._optionsService=i,this._intervalDuration=0,this._blinkOn=!0,this._needsBlinkInViewport=!1,this._isViewportVisible=!0,this._register(this._optionsService.onSpecificOptionChange("blinkIntervalDuration",s=>{this.setIntervalDuration(s)})),this.setIntervalDuration(this._optionsService.rawOptions.blinkIntervalDuration),this._register(O(()=>this._clearInterval()))}get isBlinkOn(){return this._blinkOn}get isEnabled(){return this._intervalDuration>0}setNeedsBlinkInViewport(e){this._needsBlinkInViewport!==e&&(this._needsBlinkInViewport=e,this._updateIntervalState())}setViewportVisible(e){this._isViewportVisible!==e&&(this._isViewportVisible=e,this._updateIntervalState())}setIntervalDuration(e){e!==this._intervalDuration&&(this._intervalDuration=e,this._clearInterval(),this._updateIntervalState())}_updateIntervalState(){if(this._intervalDuration>0&&this._needsBlinkInViewport&&this._isViewportVisible){if(this._interval!==void 0)return;let e=this._blinkOn;this._blinkOn=!0,this._interval=this._coreBrowserService.window.setInterval(()=>{this._blinkOn=!this._blinkOn,this._renderCallback()},this._intervalDuration),e||this._renderCallback();return}this._clearInterval(),this._blinkOn||(this._blinkOn=!0,this._renderCallback())}_clearInterval(){this._interval!==void 0&&(this._coreBrowserService.window.clearInterval(this._interval),this._interval=void 0)}},Oo=1,Ei=class extends L{constructor(e,t,i,s,r,n,o,h,l,a,c,d,u,f){super(),this._terminal=e,this._document=t,this._element=i,this._screenElement=s,this._viewportElement=r,this._helperContainer=n,this._linkifier2=o,this._charSizeService=l,this._optionsService=a,this._bufferService=c,this._coreService=d,this._coreBrowserService=u,this._themeService=f,this._terminalClass=Oo++,this._rowElements=[],this._selectionRenderModel=Po(),this._lastSelectionColumnMode=!1,this._rowHasBlinkingCells=[],this._rowHasBlinkingCellsCount=0,this._onRequestRedraw=this._register(new y),this.onRequestRedraw=this._onRequestRedraw.event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add("xterm-rows"),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add("xterm-selection"),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=Mo(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(_=>this._injectCss(_))),this._injectCss(this._themeService.colors),this._rowFactory=h.createInstance(Bi,document),this._element.classList.add("xterm-dom-renderer-owner-"+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(_=>this._handleLinkHover(_))),this._register(this._linkifier2.onHideLinkUnderline(_=>this._handleLinkLeave(_))),this._cursorBlinkStateManager=new Io(this._rowContainer,this._coreBrowserService),this._register(D(this._document,"mousedown",()=>this._cursorBlinkStateManager.restartBlinkAnimation())),this._register(O(()=>this._cursorBlinkStateManager.dispose())),this._textBlinkStateManager=this._register(new Ao(()=>this._onRequestRedraw.fire({start:0,end:this._bufferService.rows-1}),this._coreBrowserService,this._optionsService)),this._register(O(()=>{this._element.classList.remove("xterm-dom-renderer-owner-"+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new Lo,this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let i of this._rowElements)i.style.width=`${this.dimensions.css.canvas.width}px`,i.style.height=`${this.dimensions.css.cell.height}px`,i.style.lineHeight=`${this.dimensions.css.cell.height}px`,i.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .xterm-rows span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .xterm-rows { pointer-events: none; color: ${e.foreground.css};}`;t+=`${this._terminalSelector} .xterm-rows, ${this._terminalSelector} .xterm-rows span { font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`,t+=`${this._terminalSelector} .xterm-rows .xterm-dim { color: ${H.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}${this._terminalSelector} span.xterm-blink-hidden { visibility: hidden;}`;let i=`blink_underline_${this._terminalClass}`,s=`blink_bar_${this._terminalClass}`,r=`blink_block_${this._terminalClass}`;t+=`@keyframes ${i} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${s} { 50% { box-shadow: none; }}`,t+=`@keyframes ${r} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .xterm-rows.xterm-cursor-blink-idle .xterm-cursor.xterm-cursor-blink { animation: none !important;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .xterm-selection { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .xterm-selection div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .xterm-selection div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,o]of e.ansi.entries())t+=`${this._terminalSelector} .xterm-fg-${n} { color: ${o.css}; }${this._terminalSelector} .xterm-fg-${n}.xterm-dim { color: ${H.multiplyOpacity(o,.5).css}; }${this._terminalSelector} .xterm-bg-${n} { background-color: ${o.css}; }`;t+=`${this._terminalSelector} .xterm-fg-257 { color: ${H.opaque(e.background).css}; }${this._terminalSelector} .xterm-fg-257.xterm-dim { color: ${H.multiplyOpacity(H.opaque(e.background),.5).css}; }${this._terminalSelector} .xterm-bg-257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let i=this._rowElements.length;i<=t;i++){let s=this._document.createElement("div");this._rowContainer.appendChild(s),this._rowElements.push(s),this._rowHasBlinkingCells.push(!1)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop()),this._rowHasBlinkingCells.pop()&&this._rowHasBlinkingCellsCount--}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove("xterm-focus"),this._cursorBlinkStateManager.pause(),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add("xterm-focus"),this._cursorBlinkStateManager.resume(),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleViewportVisibilityChange(e){this._textBlinkStateManager.setViewportVisible(e)}handleSelectionChanged(e,t,i){let s=this._bufferService.rows;this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,i);let r=0,n=-1;this._lastSelectionStart&&this._lastSelectionEnd&&(this._selectionRenderModel.update(this._terminal,this._lastSelectionStart,this._lastSelectionEnd,this._lastSelectionColumnMode),this._selectionRenderModel.hasSelection&&(r=this._selectionRenderModel.viewportCappedStartRow,n=this._selectionRenderModel.viewportCappedEndRow));let o=0,h=-1;if(!e||!t)return;if(this._selectionRenderModel.update(this._terminal,e,t,i),this._selectionRenderModel.hasSelection){let c=this._selectionRenderModel.viewportStartRow,d=this._selectionRenderModel.viewportEndRow,u=this._selectionRenderModel.viewportCappedStartRow,f=this._selectionRenderModel.viewportCappedEndRow;o=u,h=f;let _=this._document.createDocumentFragment();if(i){let p=e[0]>t[0];_.appendChild(this._createSelectionElement(u,p?t[0]:e[0],p?e[0]:t[0],f-u+1))}else{let p=c===u?e[0]:0,S=u===d?t[0]:this._bufferService.cols;_.appendChild(this._createSelectionElement(u,p,S));let k=f-u-1;if(_.appendChild(this._createSelectionElement(u+1,0,this._bufferService.cols,k)),u!==f){let R=d===f?t[0]:this._bufferService.cols;_.appendChild(this._createSelectionElement(f,0,R))}}this._selectionContainer.appendChild(_)}let l=Math.min(r,o),a=Math.max(n,h);if(a>=0){l=Math.max(l,0),a=Math.min(a,s-1);let c=this._bufferService.buffer.y;this._selectionRenderModel.hasSelection&&c>=0&&cthis.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-n),r.style.height=`${s*this.dimensions.css.cell.height}px`,r.style.top=`${e*this.dimensions.css.cell.height}px`,r.style.left=`${n}px`,r.style.width=`${o}px`,r}handleCursorMove(){this._cursorBlinkStateManager.restartBlinkAnimation()}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren();this._rowHasBlinkingCellsCount>0&&(this._rowHasBlinkingCells.fill(!1),this._rowHasBlinkingCellsCount=0,this._textBlinkStateManager.setNeedsBlinkInViewport(!1))}renderRows(e,t){let i=this._bufferService.buffer,s=i.ybase+i.y,r=Math.min(i.x,this._bufferService.cols-1),n=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,o=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,h=this._optionsService.rawOptions.cursorInactiveStyle,l={hasBlinkingCells:!1};for(let a=e;a<=t;a++){let c=a+i.ydisp,d=this._rowElements[a];if(!d)continue;let u=i.lines.get(c);if(!u){d.replaceChildren(),this._setRowBlinkState(a,!1);continue}d.replaceChildren(...this._rowFactory.createRow(u,c,c===s,o,h,r,n,this._textBlinkStateManager.isBlinkOn,this.dimensions.css.cell.width,this._widthCache,-1,-1,l)),this._setRowBlinkState(a,l.hasBlinkingCells)}this._updateTextBlinkState()}get _terminalSelector(){return`.xterm-dom-renderer-owner-${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,i,s,r,n){i<0&&(e=0),s<0&&(t=0);let o=this._bufferService.rows-1;i=Math.max(Math.min(i,o),0),s=Math.max(Math.min(s,o),0),r=Math.min(r,this._bufferService.cols);let h=this._bufferService.buffer,l=h.ybase+h.y,a=Math.min(h.x,r-1),c=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,u=this._optionsService.rawOptions.cursorInactiveStyle,f={hasBlinkingCells:!1};for(let _=i;_<=s;++_){let p=_+h.ydisp,S=this._rowElements[_];if(!S)continue;let k=h.lines.get(p);if(!k){S.replaceChildren(),this._setRowBlinkState(_,!1);continue}S.replaceChildren(...this._rowFactory.createRow(k,p,p===l,d,u,a,c,this._textBlinkStateManager.isBlinkOn,this.dimensions.css.cell.width,this._widthCache,n?_===i?e:0:-1,n?(_===s?t:r)-1:-1,f)),this._setRowBlinkState(_,f.hasBlinkingCells)}this._updateTextBlinkState()}_setRowBlinkState(e,t){this._rowHasBlinkingCells[e]!==t&&(this._rowHasBlinkingCells[e]=t,this._rowHasBlinkingCellsCount+=t?1:-1)}_updateTextBlinkState(){this._textBlinkStateManager.setNeedsBlinkInViewport(this._rowHasBlinkingCellsCount>0)}};Ei=F([g(7,qi),g(8,Wt),g(9,oe),g(10,ne),g(11,Ee),g(12,be),g(13,Ze)],Ei);var Io=class{constructor(e,t){this._rowContainer=e,this._coreBrowserService=t,this._isIdlePaused=!1,this._coreBrowserService.isFocused&&this._resetIdleTimer()}dispose(){this._clearIdleTimer()}restartBlinkAnimation(){this._isIdlePaused&&this._rowContainer.classList.remove("xterm-cursor-blink-idle"),this._resetIdleTimer()}pause(){this._isIdlePaused=!1,this._clearIdleTimer()}resume(){this._isIdlePaused=!1,this._rowContainer.classList.remove("xterm-cursor-blink-idle"),this._resetIdleTimer()}_resetIdleTimer(){this._isIdlePaused=!1,this._clearIdleTimer(),this._idleTimeout=this._coreBrowserService.window.setTimeout(()=>{this._stopBlinkingDueToIdle()},3e5)}_clearIdleTimer(){this._idleTimeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._idleTimeout),this._idleTimeout=void 0)}_stopBlinkingDueToIdle(){this._rowContainer.classList.add("xterm-cursor-blink-idle"),this._isIdlePaused=!0,this._idleTimeout=void 0}},Di=class extends L{constructor(e,t,i){super(),this._optionsService=i,this.width=0,this.height=0,this._onCharSizeChange=this._register(new y),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new Ho(this._optionsService))}catch{this._measureStrategy=this._register(new No(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};Di=F([g(2,oe)],Di);var Mr=class extends L{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},No=class extends Mr{constructor(e,t,i){super(),this._document=e,this._parentElement=t,this._optionsService=i,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},Ho=class extends Mr{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let t=this._ctx.measureText("W");if(!("width"in t&&"fontBoundingBoxAscent"in t&&"fontBoundingBoxDescent"in t))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText("W");return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},Fo=class extends L{constructor(e,t,i){super(),this._textarea=e,this._window=t,this.mainDocument=i,this._isFocused=!1,this._cachedIsFocused=void 0,this._onDprChange=this._register(new y),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new y),this.onWindowChange=this._onWindowChange.event,this._screenDprMonitor=this._register(new Wo(this._window)),this._register(this.onWindowChange(s=>this._screenDprMonitor.setWindow(s))),this._register(he.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(D(this._textarea,"focus",()=>this._isFocused=!0)),this._register(D(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},Wo=class extends L{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new le),this._onDprChange=this._register(new y),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(O(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=D(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},zo=class extends L{constructor(){super(),this.linkProviders=[],this._register(O(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function Qi(e,t,i){let s=i.getBoundingClientRect(),r=e.getComputedStyle(i),n=parseInt(r.getPropertyValue("padding-left"),10),o=parseInt(r.getPropertyValue("padding-top"),10);return[t.clientX-s.left-n,t.clientY-s.top-o]}function Ko(e,t,i,s,r,n,o,h,l){if(!n)return;let a=Qi(e,t,i);return a[0]=Math.ceil((a[0]+(l?o/2:0))/o),a[1]=Math.ceil(a[1]/h),a[0]=Math.min(Math.max(a[0],1),s+(l?1:0)),a[1]=Math.min(Math.max(a[1],1),r),a}var Mi=class{constructor(e,t){this._charSizeService=e,this._renderService=t}getCoords(e,t,i,s,r){return Ko(pe(t),e,t,i,s,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,r)}getMouseReportCoords(e,t){let i=Qi(pe(t),e,t);if(this._charSizeService.hasValidSize)return i[0]=Math.min(Math.max(i[0],0),this._renderService.dimensions.css.canvas.width-1),i[1]=Math.min(Math.max(i[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(i[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(i[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(i[0]),y:Math.floor(i[1])}}};Mi=F([g(0,Wt),g(1,ye)],Mi);var Ns=typeof window=="object"?window:globalThis;function ce(e,t=0){return e[e.length-(1+t)]}function $o(e,t,i){let s=null,r=null;if(typeof i.value=="function"?(s="value",r=i.value,r.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof i.get=="function"&&(s="get",r=i.get),!r||!s)throw new Error("not supported");let n=`$memoize$${t}`,o=i;o[s]=function(...h){return this.hasOwnProperty(n)||Object.defineProperty(this,n,{configurable:!1,enumerable:!1,writable:!1,value:r.apply(this,h)}),this[n]}}var Li=class Ri{constructor(t){this.element=t,this.next=Ri.Undefined,this.prev=Ri.Undefined}};Li.Undefined=new Li(void 0);var ae=Li,Hs=class{constructor(){this._first=ae.Undefined,this._last=ae.Undefined}push(e){return this._insert(e,!0)}_insert(e,t){let i=new ae(e);if(this._first===ae.Undefined)this._first=i,this._last=i;else if(t){let r=this._last;this._last=i,i.prev=r,r.next=i}else{let r=this._first;this._first=i,i.next=r,r.prev=i}let s=!1;return()=>{s||(s=!0,this._remove(i))}}_remove(e){if(e.prev!==ae.Undefined&&e.next!==ae.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===ae.Undefined&&e.next===ae.Undefined?(this._first=ae.Undefined,this._last=ae.Undefined):e.next===ae.Undefined?(this._last=this._last.prev,this._last.next=ae.Undefined):e.prev===ae.Undefined&&(this._first=this._first.next,this._first.prev=ae.Undefined)}*[Symbol.iterator](){let e=this._first;for(;e!==ae.Undefined;)yield e.element,e=e.next}},ue;(e=>(e.TAP="-xterm-gesturetap",e.CHANGE="-xterm-gesturechange",e.START="-xterm-gesturestart",e.END="-xterm-gesturesend",e.CONTEXT_MENU="-xterm-gesturecontextmenu"))(ue||={});var ht=class se extends L{constructor(){super(),this._dispatched=!1,this._targets=new Hs,this._ignoreTargets=new Hs,this._activeTouches={},this._handle=null,this._lastSetTapCountTime=0;let t=Ns;this._register(D(t.document,"touchstart",i=>this._handleTouchStart(i),{passive:!1})),this._register(D(t.document,"touchend",i=>this._handleTouchEnd(t,i))),this._register(D(t.document,"touchmove",i=>this._handleTouchMove(i),{passive:!1}))}static addTarget(t){if(!se.isTouchDevice())return L.None;se._instance||(se._instance=new se);let i=se._instance._targets.push(t);return O(i)}static ignoreTarget(t){if(!se.isTouchDevice())return L.None;se._instance||(se._instance=new se);let i=se._instance._ignoreTargets.push(t);return O(i)}static isTouchDevice(){return"ontouchstart"in Ns||navigator.maxTouchPoints>0}dispose(){this._handle&&(this._handle.dispose(),this._handle=null),super.dispose()}_handleTouchStart(t){let i=Date.now();this._handle&&(this._handle.dispose(),this._handle=null);for(let s=0,r=t.targetTouches.length;s=se._holdDelay&&Math.abs(l.initialPageX-ce(l.rollingPageX))<30&&Math.abs(l.initialPageY-ce(l.rollingPageY))<30){let c=this._newGestureEvent(ue.CONTEXT_MENU,l.initialTarget);c.pageX=ce(l.rollingPageX),c.pageY=ce(l.rollingPageY),this._dispatchEvent(c)}else if(r===1){let c=ce(l.rollingPageX),d=ce(l.rollingPageY),u=ce(l.rollingTimestamps)-l.rollingTimestamps[0],f=c-l.rollingPageX[0],_=d-l.rollingPageY[0],p=[...this._targets].filter(S=>l.initialTarget instanceof Node&&S.contains(l.initialTarget));this._inertia(t,p,s,Math.abs(f)/u,f>0?1:-1,c,Math.abs(_)/u,_>0?1:-1,d)}this._dispatchEvent(this._newGestureEvent(ue.END,l.initialTarget)),delete this._activeTouches[h.identifier]}this._dispatched&&(i.preventDefault(),i.stopPropagation(),this._dispatched=!1)}_newGestureEvent(t,i){let s=document.createEvent("CustomEvent");return s.initEvent(t,!1,!0),s.initialTarget=i,s.tapCount=0,s}_dispatchEvent(t){if(t.type===ue.TAP){let i=new Date().getTime(),s;i-this._lastSetTapCountTime>se._clearTapCountTime?s=1:s=2,this._lastSetTapCountTime=i,t.tapCount=s}else(t.type===ue.CHANGE||t.type===ue.CONTEXT_MENU)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let s of this._ignoreTargets)if(s.contains(t.initialTarget))return;let i=[];for(let s of this._targets)if(s.contains(t.initialTarget)){let r=0,n=t.initialTarget;for(;n&&n!==s;)r++,n=n.parentElement;i.push([r,s])}i.sort((s,r)=>s[0]-r[0]);for(let[,s]of i)s.dispatchEvent(t),this._dispatched=!0}}_inertia(t,i,s,r,n,o,h,l,a){this._handle=Vi(t,()=>{let c=Date.now(),d=c-s,u=0,f=0,_=!0;r+=se._scrollFriction*d,h+=se._scrollFriction*d,r>0&&(_=!1,u=n*r*d),h>0&&(_=!1,f=l*h*d);let p=this._newGestureEvent(ue.CHANGE);p.translationX=u,p.translationY=f,i.forEach(S=>S.dispatchEvent(p)),_||this._inertia(t,i,c,r,n,o+u,h,l,a+f)})}_handleTouchMove(t){let i=Date.now();for(let s=0,r=t.changedTouches.length;s3&&(o.rollingPageX.shift(),o.rollingPageY.shift(),o.rollingTimestamps.shift()),o.rollingPageX.push(n.pageX),o.rollingPageY.push(n.pageY),o.rollingTimestamps.push(i)}this._dispatched&&(t.preventDefault(),t.stopPropagation(),this._dispatched=!1)}};ht._scrollFriction=-.005,ht._holdDelay=700,ht._clearTapCountTime=400,F([$o],ht,"isTouchDevice",1);var Uo=ht,Ti=class{constructor(e,t,i,s,r,n,o,h,l){this._renderService=e,this._mouseCoordsService=t,this._mouseStateService=i,this._coreService=s,this._bufferService=r,this._optionsService=n,this._selectionService=o,this._logService=h,this._coreBrowserService=l,this._lastEvent=null,this._wheelPartialScroll=0,this._touchScrollAccumulator=0}bindMouse(e,t,i){let{element:s,document:r}=e,n={mouseup:null,wheel:null,mousedrag:null,mousemove:null},o=new le,h=new le;t(o),t(h);let l={target:e,focus:i,requestedEvents:n,mouseupListener:o,mousedragListener:h},a={mouseup:c=>this._handleMouseUp(l,c),wheel:c=>this._handleWheel(l,c),mousedrag:c=>this._handleMouseDrag(l,c),mousemove:c=>this._handleMouseMove(l,c)};this._altMouseCursor=new qo(s,r,()=>this._mouseStateService.areMouseEventsActive&&!!this._optionsService.rawOptions.mouseEventsRequireAlt),t(this._altMouseCursor),t(this._mouseStateService.onProtocolChange(c=>{this._handleProtocolChange(l,a,c)})),t(this._optionsService.onSpecificOptionChange("mouseEventsRequireAlt",()=>{this._syncMouseModeState(s),this._altMouseCursor?.sync()})),this._mouseStateService.activeProtocol=this._mouseStateService.activeProtocol,t(D(s,"mousedown",c=>this._handleMouseDown(l,c))),t(D(s,"wheel",c=>this._handlePassiveWheel(l,c),{passive:!1})),t(Uo.addTarget(e.screenElement)),t(D(e.screenElement,ue.START,()=>this._handleTouchStart())),t(D(e.screenElement,ue.CHANGE,c=>this._handleTouchChange(l,c)))}_sendEvent(e,t){let i=this._mouseCoordsService.getMouseReportCoords(t,e.target.screenElement);if(!i)return!1;let s,r;switch(t.overrideType||t.type){case"mousemove":r=32,t.buttons===void 0?(s=3,t.button!==void 0&&(s=t.button<3?t.button:3)):s=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case"mouseup":r=0,s=t.button<3?t.button:3;break;case"mousedown":r=1,s=t.button<3?t.button:3;break;case"wheel":if(!this._mouseStateService.allowCustomWheelEvent(t))return!1;let o=t.deltaY;if(o===0||this._consumeWheelEvent(t,this._renderService?.dimensions?.device?.cell?.height,this._coreBrowserService?.dpr)===0)return!1;r=o<0?0:1,s=4;break;default:return!1}if(r===void 0||s===void 0||s>4||s!==4&&this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive&&!t.altKey)return!1;let n=s!==4&&this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive;return this._triggerMouseEvent({col:i.col,row:i.row,x:i.x,y:i.y,button:s,action:r,ctrl:t.ctrlKey,alt:n?!1:t.altKey,shift:t.shiftKey})}_handleMouseUp(e,t){this._sendEvent(e,t),t.buttons||(e.mouseupListener.clear(),e.mousedragListener.clear())}_handleWheel(e,t){return this._sendEvent(e,t),t.preventDefault(),t.stopPropagation(),!1}_handleMouseDrag(e,t){t.buttons&&this._sendEvent(e,t)}_handleMouseMove(e,t){t.buttons||this._sendEvent(e,t)}_handleMouseDown(e,t){if(t.preventDefault(),e.focus(),!this._mouseStateService.areMouseEventsActive||this._selectionService.shouldForceSelection(t))return;this._sendEvent(e,t);let{element:i,document:s}=e.target,r=i.ownerDocument??s;e.requestedEvents.mouseup&&(e.mouseupListener.value=D(r,"mouseup",e.requestedEvents.mouseup)),e.requestedEvents.mousedrag&&(e.mousedragListener.value=D(r,"mousemove",e.requestedEvents.mousedrag))}_handlePassiveWheel(e,t){if(!e.requestedEvents.wheel){if(!this._mouseStateService.allowCustomWheelEvent(t))return!1;if(!this._bufferService.buffer.hasScrollback){if(t.deltaY===0)return!1;if(this._consumeWheelEvent(t,this._renderService?.dimensions?.device?.cell?.height,this._coreBrowserService?.dpr)===0)return t.preventDefault(),t.stopPropagation(),!1;let i="\x1B"+(this._coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(t.deltaY<0?"A":"B");return this._coreService.triggerDataEvent(i,!0),t.preventDefault(),t.stopPropagation(),!1}}}_handleTouchStart(){this._touchScrollAccumulator=0}_handleTouchChange(e,t){if(t.preventDefault(),t.stopPropagation(),e.requestedEvents.wheel){this._handleTouchScrollAsWheel(e,t);return}if(!this._bufferService.buffer.hasScrollback){this._handleTouchScrollAsKeys(t);return}e.target.handleTouchScroll?.(t.translationY)}_handleTouchScrollAsKeys(e){let t=this._renderService?.dimensions.css.cell.height;if(!t)return;this._touchScrollAccumulator-=e.translationY;let i=Math.trunc(this._touchScrollAccumulator/t);if(i===0)return;this._touchScrollAccumulator-=i*t;let s="\x1B"+(this._coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(i<0?"A":"B");for(let r=0;r0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(r*=this._bufferService.rows),r}_triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._mouseStateService.isPixelEncoding))||!this._mouseStateService.restrictMouseEvent(e))return!1;let t=this._mouseStateService.encodeMouseEvent(e);return t&&(this._mouseStateService.isDefaultEncoding?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}_explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,i){if(i){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return!(e.button!==t.button||e.action!==t.action||e.ctrl!==t.ctrl||e.alt!==t.alt||e.shift!==t.shift)}};Ti=F([g(0,ye),g(1,zt),g(2,Ft),g(3,Ee),g(4,ne),g(5,oe),g(6,gr),g(7,Je),g(8,be)],Ti);var qo=class{constructor(e,t,i){this._element=e,this._document=t,this._isActive=i,this._listeners=new le}dispose(){this._listeners.dispose()}sync(){if(this._listeners.clear(),!this._isActive())return;let e=new Qe,t=s=>this.syncFromModifier(s);e.add(D(this._document,"keydown",t)),e.add(D(this._document,"keyup",t)),e.add(D(this._element,"mousemove",t));let i=this._element.ownerDocument?.defaultView;i&&e.add(D(i,"blur",()=>{this._isActive()&&this.resetClass()})),this._listeners.value=e}resetClass(){this._updateClass(!1)}syncFromModifier(e){this._isActive()&&this._updateClass(e.getModifierState("Alt"))}_updateClass(e){e?this._element.classList.add("enable-mouse-events"):this._element.classList.remove("enable-mouse-events")}},Vo=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame!==void 0&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame??=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()),this._animationFrame}refresh(e,t,i){this._rowCount=i,e=e??0,t=t??this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},Lr=class{constructor(e){this._tasks=[],this._i=0,this._logService=e}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._ir){s-t<-20&&this._logService.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(s-t))}ms`),this._start();return}s=r}this.clear()}},Yo=class extends Lr{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},Xo=class extends Lr{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},Nt="requestIdleCallback"in globalThis?Xo:Yo,jo=class{constructor(e){this._queue=new Nt(e)}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}dispose(){this._queue.clear()}},Pi=class extends L{constructor(e,t,i,s,r,n,o,h,l,a){super(),this._rowCount=e,this._optionsService=i,this._logService=s,this._charSizeService=r,this._coreService=n,this._coreBrowserService=l,this._renderer=this._register(new le),this._observerDisposable=this._register(new le),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new y),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new y),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new y),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new y),this.onRefreshRequest=this._onRefreshRequest.event,this._pausedResizeTask=this._register(new jo(this._logService)),this._renderDebouncer=new Vo((c,d)=>this._renderRows(c,d),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new Go(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(O(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(h.onResize(()=>this._fullRefresh())),this._register(h.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(o.onDecorationRegistered(()=>this._fullRefresh())),this._register(o.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(h.cols,h.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(h.buffer.y,h.buffer.y,void 0,!0))),this._register(a.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(c=>this._registerIntersectionObserver(c,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if("IntersectionObserver"in e){let i=new e.IntersectionObserver(s=>this._handleIntersectionChange(s[s.length-1]),{threshold:0});this._observerDisposable.value=O(()=>{this._intersectionObserver?.disconnect(),this._intersectionObserver=void 0}),this._intersectionObserver=i,i.observe(t)}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,this._renderer.value?.handleViewportVisibilityChange?.(!this._isPaused),!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,i=!1,s=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let r=this._syncOutputHandler.flush();r&&(e=Math.min(e,r.start),t=Math.max(t,r.end)),s||(this._isNextRenderRedrawOnly=!1),i?this._renderRows(e,t):this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(t=>this.refreshRows(t.start,t.end,t.sync,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(e,t)):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,i){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=i,this._renderer.value?.handleSelectionChanged(e,t,i)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};Pi=F([g(2,oe),g(3,Je),g(4,Wt),g(5,Ee),g(6,mt),g(7,ne),g(8,be),g(9,Ze)],Pi);var Go=class{constructor(e,t,i){this._coreBrowserService=e,this._coreService=t,this._onTimeout=i,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout??=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3)}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function Jo(e,t,i,s){let r=i.buffer.x,n=i.buffer.y;if(!i.buffer.hasScrollback)return ea(r,n,e,t,i,s)+Ut(n,t,i,s)+ta(r,n,e,t,i,s);let o;if(n===t)return o=r>e?"D":"C",pt(Math.abs(r-e),ft(o,s));o=n>t?"D":"C";let h=Math.abs(n-t),l=Qo(n>t?e:r,i)+(h-1)*i.cols+1+Zo(n>t?r:e,i);return pt(l,ft(o,s))}function Zo(e,t){return e-1}function Qo(e,t){return t.cols-e}function ea(e,t,i,s,r,n){return Ut(t,s,r,n).length===0?"":pt(Tr(e,t,e,t-$e(t,r),!1,r).length,ft("D",n))}function Ut(e,t,i,s){let r=e-$e(e,i),n=t-$e(t,i),o=Math.abs(r-n)-ia(e,t,i);return pt(o,ft(Rr(e,t),s))}function ta(e,t,i,s,r,n){let o;Ut(t,s,r,n).length>0?o=s-$e(s,r):o=t;let h=s,l=sa(e,t,i,s,r,n);return pt(Tr(e,o,i,h,l==="C",r).length,ft(l,n))}function ia(e,t,i){let s=0,r=e-$e(e,i),n=t-$e(t,i);for(let o=0;o=0&&e0?o=s-$e(s,r):o=t,e=i&&ot?"A":"B"}function Tr(e,t,i,s,r,n){let o=e,h=t,l="";for(;(o!==i||h!==s)&&h>=0&&hn.cols-1?(l+=n.buffer.translateBufferLineToString(h,!1,e,o),o=0,e=0,h++):!r&&o<0&&(l+=n.buffer.translateBufferLineToString(h,!1,0,e+1),o=n.cols-1,e=o,h--);return l+n.buffer.translateBufferLineToString(h,!1,e,o)}function ft(e,t){return"\x1B"+(t?"O":"[")+e}function pt(e,t){e=Math.floor(e);let i="";for(let s=0;sthis._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):this.selectionStart&&this.selectionStart[1]<0?(this.selectionStart=[0,0],!0):!1}};function Fs(e,t){if(e.start.y>e.end.y)throw new Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var na="\xA0",oa=new RegExp(na,"g"),Ai=class extends L{constructor(e,t,i,s,r,n,o,h,l,a){super(),this._element=e,this._screenElement=t,this._linkifier=i,this._bufferService=s,this._coreService=r,this._mouseCoordsService=n,this._optionsService=o,this._mouseStateService=h,this._renderService=l,this._coreBrowserService=a,this._dragScrollAmount=0,this._enabled=!0,this._trimListener=this._register(new le),this._workCell=new ge,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new y),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new y),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new y),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new y),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=c=>this._handleMouseMove(c),this._mouseUpListener=c=>this._handleMouseUp(c),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener.value=this._bufferService.buffer.lines.onTrim(c=>this._handleTrim(c)),this._register(this._bufferService.buffers.onBufferActivate(c=>this._handleBufferActivate(c))),this.enable(),this._model=new ra(this._bufferService),this._activeSelectionMode=0,this._register(O(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(c=>{c.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return"";let i=this._bufferService.buffer,s=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return"";let r=e[0]r.replace(oa," ")).join($t?`\r +`)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._renderService.onRender(()=>{this._needsSyncOnRender&&(this._needsSyncOnRender=!1,this._sync())})),this._register(this._scrollableElement.onScroll(c=>this._handleScroll(c)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){let e=this._optionsService.rawOptions.scrollbar?.showScrollbar??!0,t=this._optionsService.rawOptions.scrollbar?.showArrows??!1,i=e?this._optionsService.rawOptions.scrollbar?.width??14:0;return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,vertical:e?1:2,verticalScrollbarSize:i,verticalHasArrows:t}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){if(!(!this._renderService||this._isSyncing)){if(this._coreService.decPrivateModes.synchronizedOutput){this._needsSyncOnRender=!0;return}this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1}}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),i=t-this._bufferService.buffer.ydisp;i!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(i)),this._isHandlingScroll=!1}handleTouchScroll(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({scrollTop:t.scrollTop-e})}};Ci=F([g(2,ne),g(3,be),g(4,De),g(5,Ft),g(6,Ze),g(7,oe),g(8,ye)],Ci);var ki=class extends L{constructor(e,t,i,s,r){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=i,this._decorationService=s,this._renderService=r,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(n=>this._removeDecoration(n))),this._register(O(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement("div");t.classList.add("xterm-decoration"),t.classList.toggle("xterm-decoration-top-layer",e?.options?.layer==="top"),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let i=e.options.x??0;return i&&i>this._bufferService.cols&&(t.style.display="none"),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display="none",e.onRenderEmitter.fire(e.element));else{let i=this._decorationElements.get(e);i||(i=this._createElement(e),e.element=i,this._decorationElements.set(e,i),this._container.appendChild(i),e.onDispose(()=>{this._decorationElements.delete(e),i.remove()})),i.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(i.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,i.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,i.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,i.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(i)}}_refreshXPosition(e,t=e.element){if(!t)return;let i=e.options.x??0;(e.options.anchor||"left")==="right"?t.style.right=i?`${i*this._renderService.dimensions.css.cell.width}px`:"":t.style.left=i?`${i*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};ki=F([g(1,ne),g(2,be),g(3,mt),g(4,ye)],ki);var ko=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,i){return t>=e.startBufferLine-this._linePadding[i||"full"]&&t<=e.endBufferLine+this._linePadding[i||"full"]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},me={full:0,left:0,center:0,right:0},Pe={full:0,left:0,center:0,right:0},st={full:0,left:0,center:0,right:0},Ot=class extends L{constructor(e,t,i,s,r,n,o,h){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=i,this._decorationService=s,this._renderService=r,this._optionsService=n,this._themeService=o,this._coreBrowserService=h,this._colorZoneStore=new ko,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(O(()=>this._canvas?.remove()));let l=this._canvas.getContext("2d");if(l)this._ctx=l;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onDimensionsChange(()=>this._queueRefresh(!0))),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("scrollbar",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._register(O(()=>{this._animationFrame!==void 0&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)})),this._queueRefresh(!0)}get _width(){let e=this._optionsService.rawOptions.scrollbar;return e?.showScrollbar??!0?e?.width??0:0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);Pe.full=this._canvas.width,Pe.left=e,Pe.center=t,Pe.right=e,this._refreshDrawHeightConstants(),st.full=1,st.left=1,st.center=1+Pe.left,st.right=1+Pe.left+Pe.center}_refreshDrawHeightConstants(){me.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);me.left=t,me.center=t,me.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*me.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){if(this._store.isDisposed||!this._renderService.hasRenderer())return;let e=this._renderService.dimensions.css.canvas.height,t=this._renderService.dimensions.device.canvas.height;this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${e}px`,this._canvas.height=t,this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){if(this._store.isDisposed||!this._renderService.hasRenderer())return;this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let t of this._decorationService.decorations)this._colorZoneStore.addDecoration(t);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!=="full"&&this._renderColorZone(t);for(let t of e)t.position==="full"&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.scrollbar?.overviewRuler?.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.scrollbar?.overviewRuler?.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(st[e.position||"full"],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-me[e.position||"full"]/2),Pe[e.position||"full"],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+me[e.position||"full"]))}_queueRefresh(e,t){this._store.isDisposed||(this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._store.isDisposed||this._refreshDecorations(),this._animationFrame=void 0})))}};Ot=F([g(2,ne),g(3,mt),g(4,ye),g(5,oe),g(6,Ze),g(7,be)],Ot);var xi=class{constructor(e,t,i,s,r,n){this._textarea=e,this._compositionView=t,this._bufferService=i,this._optionsService=s,this._coreService=r,this._renderService=n,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._compositionSuffix="",this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0;let e=this._textarea.selectionStart??this._textarea.value.length,t=this._textarea.selectionEnd??e;this._compositionPosition.start=Math.min(e,t),this._compositionPosition.end=Math.max(e,t),this._compositionSuffix=this._textarea.value.substring(this._compositionPosition.end),this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(e){this._compositionView.textContent=`\u200E${e.data}\u200E`,this.updateCompositionElements(),setTimeout(()=>{let t=this._textarea.selectionEnd??this._textarea.value.length;this._compositionPosition.end=Math.max(this._compositionPosition.start,t)},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(e){if(this._compositionView.classList.remove("active"),this._isComposing=!1,e){let t={start:this._compositionPosition.start,end:this._compositionPosition.end},i=this._compositionSuffix;this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let s;if(t.start+=this._dataAlreadySent.length,this._isComposing)s=this._textarea.value.substring(t.start,this._compositionPosition.start);else{let r=this._textarea.value,n=i.length>0&&r.endsWith(i)?r.length-i.length:r.length;s=r.substring(t.start,Math.max(t.start,n))}s.length>0&&this._coreService.triggerDataEvent(s,!0)}},0)}else{this._isSendingComposition=!1;let t=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(t,!0)}}_handleAnyTextareaChanges(){if(this._textareaChangeTimer)return;let e=this._textarea.value;this._textareaChangeTimer=window.setTimeout(()=>{if(this._textareaChangeTimer=void 0,!this._isComposing){let t=this._textarea.value,i=t.replace(e,"");this._dataAlreadySent=i,t.length>e.length?this._coreService.triggerDataEvent(i,!0):t.lengththis.updateCompositionElements(!0),0)}}};xi=F([g(2,ne),g(3,oe),g(4,De),g(5,ye)],xi);var J=0,Z=0,Q=0,z=0,Os={css:"#00000000",rgba:0},$;(e=>{function t(r,n,o,h){return h!==void 0?`#${Fe(r)}${Fe(n)}${Fe(o)}${Fe(h)}`:`#${Fe(r)}${Fe(n)}${Fe(o)}`}e.toCss=t;function i(r,n,o,h=255){return(r<<24|n<<16|o<<8|h)>>>0}e.toRgba=i;function s(r,n,o,h){return{css:e.toCss(r,n,o,h),rgba:e.toRgba(r,n,o,h)}}e.toColor=s})($||={});var H;(e=>{function t(l,a){if(z=(a.rgba&255)/255,z===1)return{css:a.css,rgba:a.rgba};let c=a.rgba>>24&255,d=a.rgba>>16&255,u=a.rgba>>8&255,f=l.rgba>>24&255,_=l.rgba>>16&255,p=l.rgba>>8&255;J=f+Math.round((c-f)*z),Z=_+Math.round((d-_)*z),Q=p+Math.round((u-p)*z);let S=$.toCss(J,Z,Q),k=$.toRgba(J,Z,Q);return{css:S,rgba:k}}e.blend=t;function i(l){return(l.rgba&255)===255}e.isOpaque=i;function s(l,a,c){let d=Lt.ensureContrastRatio(l.rgba,a.rgba,c);if(d)return $.toColor(d>>24&255,d>>16&255,d>>8&255)}e.ensureContrastRatio=s;function r(l){let a=(l.rgba|255)>>>0;return[J,Z,Q]=Lt.toChannels(a),{css:$.toCss(J,Z,Q),rgba:a}}e.opaque=r;function n(l,a){return z=Math.round(a*255),[J,Z,Q]=Lt.toChannels(l.rgba),{css:$.toCss(J,Z,Q,z),rgba:$.toRgba(J,Z,Q,z)}}e.opacity=n;function o(l,a){return z=l.rgba&255,n(l,z*a/255)}e.multiplyOpacity=o;function h(l){return[l.rgba>>24&255,l.rgba>>16&255,l.rgba>>8&255]}e.toColorRGB=h})(H||={});var W;(e=>{let t,i;try{let r=document.createElement("canvas");r.width=1,r.height=1;let n=r.getContext("2d",{willReadFrequently:!0});n&&(t=n,t.globalCompositeOperation="copy",i=t.createLinearGradient(0,0,1,1))}catch{}function s(r){if(r.match(/#[\da-f]{3,8}/i))switch(r.length){case 4:return J=parseInt(r.slice(1,2).repeat(2),16),Z=parseInt(r.slice(2,3).repeat(2),16),Q=parseInt(r.slice(3,4).repeat(2),16),$.toColor(J,Z,Q);case 5:return J=parseInt(r.slice(1,2).repeat(2),16),Z=parseInt(r.slice(2,3).repeat(2),16),Q=parseInt(r.slice(3,4).repeat(2),16),z=parseInt(r.slice(4,5).repeat(2),16),$.toColor(J,Z,Q,z);case 7:return{css:r,rgba:(parseInt(r.slice(1),16)<<8|255)>>>0};case 9:return{css:r,rgba:parseInt(r.slice(1),16)>>>0}}let n=r.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(n)return J=parseInt(n[1],10),Z=parseInt(n[2],10),Q=parseInt(n[3],10),z=Math.round((n[5]===void 0?1:parseFloat(n[5]))*255),$.toColor(J,Z,Q,z);if(r==="transparent")return{css:"transparent",rgba:0};if(!t||!i)throw new Error("css.toColor: Unsupported css format");if(t.fillStyle=i,t.fillStyle=r,typeof t.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(t.fillRect(0,0,1,1),[J,Z,Q,z]=t.getImageData(0,0,1,1).data,z!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:$.toRgba(J,Z,Q,z),css:r}}e.toColor=s})(W||={});var ie;(e=>{function t(s){return i(s>>16&255,s>>8&255,s&255)}e.relativeLuminance=t;function i(s,r,n){let o=s/255,h=r/255,l=n/255,a=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),c=h<=.03928?h/12.92:Math.pow((h+.055)/1.055,2.4),d=l<=.03928?l/12.92:Math.pow((l+.055)/1.055,2.4);return a*.2126+c*.7152+d*.0722}e.relativeLuminance2=i})(ie||={});var Lt;(e=>{function t(o,h){if(z=(h&255)/255,z===1)return h;let l=h>>24&255,a=h>>16&255,c=h>>8&255,d=o>>24&255,u=o>>16&255,f=o>>8&255;return J=d+Math.round((l-d)*z),Z=u+Math.round((a-u)*z),Q=f+Math.round((c-f)*z),$.toRgba(J,Z,Q)}e.blend=t;function i(o,h,l){let a=ie.relativeLuminance(o>>8),c=ie.relativeLuminance(h>>8);if(Ee(a,c)>8));if(_>8));return _>S?f:p}return f}let d=r(o,h,l),u=Ee(a,ie.relativeLuminance(d>>8));if(u>8));return u>_?d:f}return d}}e.ensureContrastRatio=i;function s(o,h,l){let a=o>>24&255,c=o>>16&255,d=o>>8&255,u=h>>24&255,f=h>>16&255,_=h>>8&255,p=Ee(ie.relativeLuminance2(u,f,_),ie.relativeLuminance2(a,c,d));for(;p0||f>0||_>0);)u-=Math.max(0,Math.ceil(u*.1)),f-=Math.max(0,Math.ceil(f*.1)),_-=Math.max(0,Math.ceil(_*.1)),p=Ee(ie.relativeLuminance2(u,f,_),ie.relativeLuminance2(a,c,d));return(u<<24|f<<16|_<<8|255)>>>0}e.reduceLuminance=s;function r(o,h,l){let a=o>>24&255,c=o>>16&255,d=o>>8&255,u=h>>24&255,f=h>>16&255,_=h>>8&255,p=Ee(ie.relativeLuminance2(u,f,_),ie.relativeLuminance2(a,c,d));for(;p>>0}e.increaseLuminance=r;function n(o){return[o>>24&255,o>>16&255,o>>8&255,o&255]}e.toChannels=n})(Lt||={});function Fe(e){let t=e.toString(16);return t.length<2?"0"+t:t}function Ee(e,t){return e1){let d=this._getJoinedRanges(s,h,o,t,n);for(let u=0;u1){let c=this._getJoinedRanges(s,h,o,t,n);for(let d=0;d=St,P=w,C=this._workCell;if(_.length>0&&w===_[0][0]&&M){let I=_.shift(),Yt=this._isCellInSelection(I[0],t);for(B=I[0]+1;B=I[1],M?(x=!0,C=new xo(this._workCell,e.translateToString(!0,I[0],I[1]),I[1]-I[0]),P=I[1]-1,b=C.getWidth()):St=I[1]}let q=this._isCellInSelection(w,t),ve=i&&w===n,Me=m&&w>=c&&w<=d;u&&C.isBlink()&&(u.hasBlinkingCells=!0),!h&&C.isBlink()&&v.push("xterm-blink-hidden");let xe=!1;this._decorationService.forEachDecorationAtCell(w,t,void 0,I=>{xe=!0});let Ne=C.getChars()||" ";if(Ne===" "&&(C.isUnderline()||C.isOverline())&&(Ne="\xA0"),Ie=b*l-a.get(Ne,C.isBold(),C.isItalic()),!k)k=this._document.createElement("span");else if(R&&(q&&Ue||!q&&!Ue&&C.bg===T)&&(q&&Ue&&p.selectionForeground||C.fg===A)&&C.extended.ext===ee&&Me===ke&&Ie===Oe&&!ve&&!x&&!xe&&M){C.isInvisible()?E+=" ":E+=Ne,R++;continue}else R&&(k.textContent=E),k=this._document.createElement("span"),R=0,E="";if(T=C.bg,A=C.fg,ee=C.extended.ext,ke=Me,Oe=Ie,Ue=q,x&&n>=w&&n<=P&&(n=w),!this._coreService.isCursorHidden&&ve&&this._coreService.isCursorInitialized){if(v.push("xterm-cursor"),this._coreBrowserService.isFocused)o&&v.push("xterm-cursor-blink"),v.push(s==="bar"?"xterm-cursor-bar":s==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(r)switch(r){case"outline":v.push("xterm-cursor-outline");break;case"block":v.push("xterm-cursor-block");break;case"bar":v.push("xterm-cursor-bar");break;case"underline":v.push("xterm-cursor-underline");break;default:break}}if(C.isBold()&&v.push("xterm-bold"),C.isItalic()&&v.push("xterm-italic"),C.isDim()&&v.push("xterm-dim"),C.isInvisible()?E=" ":E=C.getChars()||" ",C.isUnderline()&&(v.push(`xterm-underline-${C.extended.underlineStyle}`),E===" "&&(E="\xA0"),!C.isUnderlineColorDefault()))if(C.isUnderlineColorRGB())k.style.textDecorationColor=`rgb(${vt.toColorRGB(C.getUnderlineColor()).join(",")})`;else{let I=C.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&C.isBold()&&I<8&&(I+=8),k.style.textDecorationColor=p.ansi[I].css}C.isOverline()&&(v.push("xterm-overline"),E===" "&&(E="\xA0")),C.isStrikethrough()&&v.push("xterm-strikethrough"),Me&&(k.style.textDecoration="underline");let te=C.getFgColor(),He=C.getFgColorMode(),_e=C.getBgColor(),tt=C.getBgColorMode(),Vt=!!C.isInverse();if(Vt){let I=te;te=_e,_e=I;let Yt=He;He=tt,tt=Yt}let Le,wt,it=!1;this._decorationService.forEachDecorationAtCell(w,t,void 0,I=>{I.options.layer!=="top"&&it||(I.backgroundColorRGB&&(tt=50331648,_e=I.backgroundColorRGB.rgba>>8&16777215,Le=I.backgroundColorRGB),I.foregroundColorRGB&&(He=50331648,te=I.foregroundColorRGB.rgba>>8&16777215,wt=I.foregroundColorRGB),it=I.options.layer==="top")}),!it&&q&&(Le=this._coreBrowserService.isFocused?p.selectionBackgroundOpaque:p.selectionInactiveBackgroundOpaque,_e=Le.rgba>>8&16777215,tt=50331648,it=!0,p.selectionForeground&&(He=50331648,te=p.selectionForeground.rgba>>8&16777215,wt=p.selectionForeground)),it&&v.push("xterm-decoration-top");let Re;switch(tt){case 16777216:case 33554432:Re=p.ansi[_e],v.push(`xterm-bg-${_e}`);break;case 50331648:Re=$.toColor(_e>>16,_e>>8&255,_e&255),this._addStyle(k,`background-color:#${(_e>>>0).toString(16).padStart(6,"0")}`);break;default:Vt?(Re=p.foreground,v.push("xterm-bg-257")):Re=p.background}switch(Le||C.isDim()&&(Le=H.multiplyOpacity(Re,.5)),He){case 16777216:case 33554432:C.isBold()&&te<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(te+=8),this._applyMinimumContrast(k,Re,p.ansi[te],C,Le,void 0)||v.push(`xterm-fg-${te}`);break;case 50331648:let I=$.toColor(te>>16&255,te>>8&255,te&255);this._applyMinimumContrast(k,Re,I,C,Le,wt)||this._addStyle(k,`color:#${te.toString(16).padStart(6,"0")}`);break;default:this._applyMinimumContrast(k,Re,p.foreground,C,Le,wt)||Vt&&v.push("xterm-fg-257")}v.length&&(k.className=v.join(" "),v.length=0),!ve&&!x&&!xe&&M?R++:k.textContent=E,Ie!==this.defaultSpacing&&(k.style.letterSpacing=`${Ie}px`),f.push(k),w=P}return k&&R&&(k.textContent=E),f}_applyMinimumContrast(e,t,i,s,r,n){if(this._optionsService.rawOptions.minimumContrastRatio===1||Do(s.getCode()))return!1;let o=this._getContrastCache(s),h;if(!r&&!n&&(h=o.getColor(t.rgba,i.rgba)),h===void 0){let l=this._optionsService.rawOptions.minimumContrastRatio/(s.isDim()?2:1);h=H.ensureContrastRatio(r??t,n??i,l),o.setColor((r??t).rgba,(n??i).rgba,h??null)}return h?(this._addStyle(e,`color:${h.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute("style",`${e.getAttribute("style")||""}${t};`)}_isCellInSelection(e,t){let i=this._selectionStart,s=this._selectionEnd;return!i||!s?!1:this._columnSelectMode?i[0]<=s[0]?e>=i[0]&&t>=i[1]&&e=i[1]&&e>=s[0]&&t<=s[1]:t>i[1]&&t=i[0]&&e=i[0]}};Bi=F([g(1,vr),g(2,oe),g(3,be),g(4,De),g(5,mt),g(6,Ze)],Bi);var Lo=class{constructor(e=()=>new Ro){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._canvasElements=[],this._canvasElements=[e(),e(),e(),e()],this.clear()}dispose(){this._canvasElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,i,s){e===this._font&&t===this._fontSize&&i===this._weight&&s===this._weightBold||(this._font=e,this._fontSize=t,this._weight=i,this._weightBold=s,this._canvasElements[0].setFont(e,t,i,!1),this._canvasElements[1].setFont(e,t,s,!1),this._canvasElements[2].setFont(e,t,i,!0),this._canvasElements[3].setFont(e,t,s,!0),this.clear())}get(e,t,i){let s;if(!t&&!i&&e.length===1&&(s=e.charCodeAt(0))<256){if(this._flat[s]!==-9999)return this._flat[s];let o=this._measure(e,0);return o>0&&(this._flat[s]=o),o}let r=e;t&&(r+="B"),i&&(r+="I");let n=this._holey.get(r);if(n===void 0){let o=0;t&&(o|=1),i&&(o|=2),n=this._measure(e,o),n>0&&this._holey.set(r,n)}return n}_measure(e,t){return this._canvasElements[t].measure(e)}},Ro=class{constructor(){typeof OffscreenCanvas<"u"?(this._canvas=new OffscreenCanvas(1,1),this._ctx=Is(this._canvas.getContext("2d"))):(this._canvas=document.createElement("canvas"),this._canvas.width=1,this._canvas.height=1,this._ctx=Is(this._canvas.getContext("2d")))}setFont(e,t,i,s){let r=s?"italic":"";this._ctx.font=`${r} ${i} ${t}px ${e}`.trim()}measure(e){return this._ctx.measureText(e).width}},To=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,i,s=!1){if(this.selectionStart=t,this.selectionEnd=i,!t||!i||t[0]===i[0]&&t[1]===i[1]){this.clear();return}let r=e.buffers.active.ydisp,n=t[1]-r,o=i[1]-r,h=Math.max(n,0),l=Math.min(o,e.rows-1);if(h>=e.rows||l<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=s,this.viewportStartRow=n,this.viewportEndRow=o,this.viewportCappedStartRow=h,this.viewportCappedEndRow=l,this.startCol=t[0],this.endCol=i[0]}isCellSelected(e,t,i){return this.hasSelection?(i-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&i>=this.viewportCappedStartRow&&t=this.viewportCappedStartRow&&t>=this.endCol&&i<=this.viewportCappedEndRow:i>this.viewportStartRow&&i=this.startCol&&t=this.startCol):!1}};function Po(){return new To}var Ao=class extends L{constructor(e,t,i){super(),this._renderCallback=e,this._coreBrowserService=t,this._optionsService=i,this._intervalDuration=0,this._blinkOn=!0,this._needsBlinkInViewport=!1,this._isViewportVisible=!0,this._register(this._optionsService.onSpecificOptionChange("blinkIntervalDuration",s=>{this.setIntervalDuration(s)})),this.setIntervalDuration(this._optionsService.rawOptions.blinkIntervalDuration),this._register(O(()=>this._clearInterval()))}get isBlinkOn(){return this._blinkOn}get isEnabled(){return this._intervalDuration>0}setNeedsBlinkInViewport(e){this._needsBlinkInViewport!==e&&(this._needsBlinkInViewport=e,this._updateIntervalState())}setViewportVisible(e){this._isViewportVisible!==e&&(this._isViewportVisible=e,this._updateIntervalState())}setIntervalDuration(e){e!==this._intervalDuration&&(this._intervalDuration=e,this._clearInterval(),this._updateIntervalState())}_updateIntervalState(){if(this._intervalDuration>0&&this._needsBlinkInViewport&&this._isViewportVisible){if(this._interval!==void 0)return;let e=this._blinkOn;this._blinkOn=!0,this._interval=this._coreBrowserService.window.setInterval(()=>{this._blinkOn=!this._blinkOn,this._renderCallback()},this._intervalDuration),e||this._renderCallback();return}this._clearInterval(),this._blinkOn||(this._blinkOn=!0,this._renderCallback())}_clearInterval(){this._interval!==void 0&&(this._coreBrowserService.window.clearInterval(this._interval),this._interval=void 0)}},Oo=1,Ei=class extends L{constructor(e,t,i,s,r,n,o,h,l,a,c,d,u,f){super(),this._terminal=e,this._document=t,this._element=i,this._screenElement=s,this._viewportElement=r,this._helperContainer=n,this._linkifier2=o,this._charSizeService=l,this._optionsService=a,this._bufferService=c,this._coreService=d,this._coreBrowserService=u,this._themeService=f,this._terminalClass=Oo++,this._rowElements=[],this._selectionRenderModel=Po(),this._lastSelectionColumnMode=!1,this._rowHasBlinkingCells=[],this._rowHasBlinkingCellsCount=0,this._onRequestRedraw=this._register(new y),this.onRequestRedraw=this._onRequestRedraw.event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add("xterm-rows"),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add("xterm-selection"),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=Mo(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(_=>this._injectCss(_))),this._injectCss(this._themeService.colors),this._rowFactory=h.createInstance(Bi,document),this._element.classList.add("xterm-dom-renderer-owner-"+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(_=>this._handleLinkHover(_))),this._register(this._linkifier2.onHideLinkUnderline(_=>this._handleLinkLeave(_))),this._cursorBlinkStateManager=new Io(this._rowContainer,this._coreBrowserService),this._register(D(this._document,"mousedown",()=>this._cursorBlinkStateManager.restartBlinkAnimation())),this._register(O(()=>this._cursorBlinkStateManager.dispose())),this._textBlinkStateManager=this._register(new Ao(()=>this._onRequestRedraw.fire({start:0,end:this._bufferService.rows-1}),this._coreBrowserService,this._optionsService)),this._register(O(()=>{this._element.classList.remove("xterm-dom-renderer-owner-"+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new Lo,this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let i of this._rowElements)i.style.width=`${this.dimensions.css.canvas.width}px`,i.style.height=`${this.dimensions.css.cell.height}px`,i.style.lineHeight=`${this.dimensions.css.cell.height}px`,i.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .xterm-rows span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .xterm-rows { pointer-events: none; color: ${e.foreground.css};}`;t+=`${this._terminalSelector} .xterm-rows, ${this._terminalSelector} .xterm-rows span { font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`,t+=`${this._terminalSelector} .xterm-rows .xterm-dim { color: ${H.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}${this._terminalSelector} span.xterm-blink-hidden { visibility: hidden;}`;let i=`blink_underline_${this._terminalClass}`,s=`blink_bar_${this._terminalClass}`,r=`blink_block_${this._terminalClass}`;t+=`@keyframes ${i} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${s} { 50% { box-shadow: none; }}`,t+=`@keyframes ${r} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .xterm-rows.xterm-cursor-blink-idle .xterm-cursor.xterm-cursor-blink { animation: none !important;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .xterm-rows .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .xterm-selection { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .xterm-selection div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .xterm-selection div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,o]of e.ansi.entries())t+=`${this._terminalSelector} .xterm-fg-${n} { color: ${o.css}; }${this._terminalSelector} .xterm-fg-${n}.xterm-dim { color: ${H.multiplyOpacity(o,.5).css}; }${this._terminalSelector} .xterm-bg-${n} { background-color: ${o.css}; }`;t+=`${this._terminalSelector} .xterm-fg-257 { color: ${H.opaque(e.background).css}; }${this._terminalSelector} .xterm-fg-257.xterm-dim { color: ${H.multiplyOpacity(H.opaque(e.background),.5).css}; }${this._terminalSelector} .xterm-bg-257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let i=this._rowElements.length;i<=t;i++){let s=this._document.createElement("div");this._rowContainer.appendChild(s),this._rowElements.push(s),this._rowHasBlinkingCells.push(!1)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop()),this._rowHasBlinkingCells.pop()&&this._rowHasBlinkingCellsCount--}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove("xterm-focus"),this._cursorBlinkStateManager.pause(),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add("xterm-focus"),this._cursorBlinkStateManager.resume(),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleViewportVisibilityChange(e){this._textBlinkStateManager.setViewportVisible(e)}handleSelectionChanged(e,t,i){let s=this._bufferService.rows;this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,i);let r=0,n=-1;this._lastSelectionStart&&this._lastSelectionEnd&&(this._selectionRenderModel.update(this._terminal,this._lastSelectionStart,this._lastSelectionEnd,this._lastSelectionColumnMode),this._selectionRenderModel.hasSelection&&(r=this._selectionRenderModel.viewportCappedStartRow,n=this._selectionRenderModel.viewportCappedEndRow));let o=0,h=-1;if(!e||!t)return;if(this._selectionRenderModel.update(this._terminal,e,t,i),this._selectionRenderModel.hasSelection){let c=this._selectionRenderModel.viewportStartRow,d=this._selectionRenderModel.viewportEndRow,u=this._selectionRenderModel.viewportCappedStartRow,f=this._selectionRenderModel.viewportCappedEndRow;o=u,h=f;let _=this._document.createDocumentFragment();if(i){let p=e[0]>t[0];_.appendChild(this._createSelectionElement(u,p?t[0]:e[0],p?e[0]:t[0],f-u+1))}else{let p=c===u?e[0]:0,S=u===d?t[0]:this._bufferService.cols;_.appendChild(this._createSelectionElement(u,p,S));let k=f-u-1;if(_.appendChild(this._createSelectionElement(u+1,0,this._bufferService.cols,k)),u!==f){let R=d===f?t[0]:this._bufferService.cols;_.appendChild(this._createSelectionElement(f,0,R))}}this._selectionContainer.appendChild(_)}let l=Math.min(r,o),a=Math.max(n,h);if(a>=0){l=Math.max(l,0),a=Math.min(a,s-1);let c=this._bufferService.buffer.y;this._selectionRenderModel.hasSelection&&c>=0&&cthis.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-n),r.style.height=`${s*this.dimensions.css.cell.height}px`,r.style.top=`${e*this.dimensions.css.cell.height}px`,r.style.left=`${n}px`,r.style.width=`${o}px`,r}handleCursorMove(){this._cursorBlinkStateManager.restartBlinkAnimation()}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren();this._rowHasBlinkingCellsCount>0&&(this._rowHasBlinkingCells.fill(!1),this._rowHasBlinkingCellsCount=0,this._textBlinkStateManager.setNeedsBlinkInViewport(!1))}renderRows(e,t){let i=this._bufferService.buffer,s=i.ybase+i.y,r=Math.min(i.x,this._bufferService.cols-1),n=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,o=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,h=this._optionsService.rawOptions.cursorInactiveStyle,l={hasBlinkingCells:!1};for(let a=e;a<=t;a++){let c=a+i.ydisp,d=this._rowElements[a];if(!d)continue;let u=i.lines.get(c);if(!u){d.replaceChildren(),this._setRowBlinkState(a,!1);continue}d.replaceChildren(...this._rowFactory.createRow(u,c,c===s,o,h,r,n,this._textBlinkStateManager.isBlinkOn,this.dimensions.css.cell.width,this._widthCache,-1,-1,l)),this._setRowBlinkState(a,l.hasBlinkingCells)}this._updateTextBlinkState()}get _terminalSelector(){return`.xterm-dom-renderer-owner-${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,i,s,r,n){i<0&&(e=0),s<0&&(t=0);let o=this._bufferService.rows-1;i=Math.max(Math.min(i,o),0),s=Math.max(Math.min(s,o),0),r=Math.min(r,this._bufferService.cols);let h=this._bufferService.buffer,l=h.ybase+h.y,a=Math.min(h.x,r-1),c=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,u=this._optionsService.rawOptions.cursorInactiveStyle,f={hasBlinkingCells:!1};for(let _=i;_<=s;++_){let p=_+h.ydisp,S=this._rowElements[_];if(!S)continue;let k=h.lines.get(p);if(!k){S.replaceChildren(),this._setRowBlinkState(_,!1);continue}S.replaceChildren(...this._rowFactory.createRow(k,p,p===l,d,u,a,c,this._textBlinkStateManager.isBlinkOn,this.dimensions.css.cell.width,this._widthCache,n?_===i?e:0:-1,n?(_===s?t:r)-1:-1,f)),this._setRowBlinkState(_,f.hasBlinkingCells)}this._updateTextBlinkState()}_setRowBlinkState(e,t){this._rowHasBlinkingCells[e]!==t&&(this._rowHasBlinkingCells[e]=t,this._rowHasBlinkingCellsCount+=t?1:-1)}_updateTextBlinkState(){this._textBlinkStateManager.setNeedsBlinkInViewport(this._rowHasBlinkingCellsCount>0)}};Ei=F([g(7,qi),g(8,Wt),g(9,oe),g(10,ne),g(11,De),g(12,be),g(13,Ze)],Ei);var Io=class{constructor(e,t){this._rowContainer=e,this._coreBrowserService=t,this._isIdlePaused=!1,this._coreBrowserService.isFocused&&this._resetIdleTimer()}dispose(){this._clearIdleTimer()}restartBlinkAnimation(){this._isIdlePaused&&this._rowContainer.classList.remove("xterm-cursor-blink-idle"),this._resetIdleTimer()}pause(){this._isIdlePaused=!1,this._clearIdleTimer()}resume(){this._isIdlePaused=!1,this._rowContainer.classList.remove("xterm-cursor-blink-idle"),this._resetIdleTimer()}_resetIdleTimer(){this._isIdlePaused=!1,this._clearIdleTimer(),this._idleTimeout=this._coreBrowserService.window.setTimeout(()=>{this._stopBlinkingDueToIdle()},3e5)}_clearIdleTimer(){this._idleTimeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._idleTimeout),this._idleTimeout=void 0)}_stopBlinkingDueToIdle(){this._rowContainer.classList.add("xterm-cursor-blink-idle"),this._isIdlePaused=!0,this._idleTimeout=void 0}},Di=class extends L{constructor(e,t,i){super(),this._optionsService=i,this.width=0,this.height=0,this._onCharSizeChange=this._register(new y),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new Ho(this._optionsService))}catch{this._measureStrategy=this._register(new No(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};Di=F([g(2,oe)],Di);var Mr=class extends L{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},No=class extends Mr{constructor(e,t,i){super(),this._document=e,this._parentElement=t,this._optionsService=i,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},Ho=class extends Mr{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let t=this._ctx.measureText("W");if(!("width"in t&&"fontBoundingBoxAscent"in t&&"fontBoundingBoxDescent"in t))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText("W");return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},Fo=class extends L{constructor(e,t,i){super(),this._textarea=e,this._window=t,this.mainDocument=i,this._isFocused=!1,this._cachedIsFocused=void 0,this._onDprChange=this._register(new y),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new y),this.onWindowChange=this._onWindowChange.event,this._screenDprMonitor=this._register(new Wo(this._window)),this._register(this.onWindowChange(s=>this._screenDprMonitor.setWindow(s))),this._register(he.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(D(this._textarea,"focus",()=>this._isFocused=!0)),this._register(D(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},Wo=class extends L{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new le),this._onDprChange=this._register(new y),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(O(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=D(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},zo=class extends L{constructor(){super(),this.linkProviders=[],this._register(O(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function Qi(e,t,i){let s=i.getBoundingClientRect(),r=e.getComputedStyle(i),n=parseInt(r.getPropertyValue("padding-left"),10),o=parseInt(r.getPropertyValue("padding-top"),10);return[t.clientX-s.left-n,t.clientY-s.top-o]}function Ko(e,t,i,s,r,n,o,h,l){if(!n)return;let a=Qi(e,t,i);return a[0]=Math.ceil((a[0]+(l?o/2:0))/o),a[1]=Math.ceil(a[1]/h),a[0]=Math.min(Math.max(a[0],1),s+(l?1:0)),a[1]=Math.min(Math.max(a[1],1),r),a}var Mi=class{constructor(e,t){this._charSizeService=e,this._renderService=t}getCoords(e,t,i,s,r){return Ko(pe(t),e,t,i,s,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,r)}getMouseReportCoords(e,t){let i=Qi(pe(t),e,t);if(this._charSizeService.hasValidSize)return i[0]=Math.min(Math.max(i[0],0),this._renderService.dimensions.css.canvas.width-1),i[1]=Math.min(Math.max(i[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(i[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(i[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(i[0]),y:Math.floor(i[1])}}};Mi=F([g(0,Wt),g(1,ye)],Mi);var Ns=typeof window=="object"?window:globalThis;function ce(e,t=0){return e[e.length-(1+t)]}function $o(e,t,i){let s=null,r=null;if(typeof i.value=="function"?(s="value",r=i.value,r.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof i.get=="function"&&(s="get",r=i.get),!r||!s)throw new Error("not supported");let n=`$memoize$${t}`,o=i;o[s]=function(...h){return this.hasOwnProperty(n)||Object.defineProperty(this,n,{configurable:!1,enumerable:!1,writable:!1,value:r.apply(this,h)}),this[n]}}var Li=class Ri{constructor(t){this.element=t,this.next=Ri.Undefined,this.prev=Ri.Undefined}};Li.Undefined=new Li(void 0);var ae=Li,Hs=class{constructor(){this._first=ae.Undefined,this._last=ae.Undefined}push(e){return this._insert(e,!0)}_insert(e,t){let i=new ae(e);if(this._first===ae.Undefined)this._first=i,this._last=i;else if(t){let r=this._last;this._last=i,i.prev=r,r.next=i}else{let r=this._first;this._first=i,i.next=r,r.prev=i}let s=!1;return()=>{s||(s=!0,this._remove(i))}}_remove(e){if(e.prev!==ae.Undefined&&e.next!==ae.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===ae.Undefined&&e.next===ae.Undefined?(this._first=ae.Undefined,this._last=ae.Undefined):e.next===ae.Undefined?(this._last=this._last.prev,this._last.next=ae.Undefined):e.prev===ae.Undefined&&(this._first=this._first.next,this._first.prev=ae.Undefined)}*[Symbol.iterator](){let e=this._first;for(;e!==ae.Undefined;)yield e.element,e=e.next}},ue;(e=>(e.TAP="-xterm-gesturetap",e.CHANGE="-xterm-gesturechange",e.START="-xterm-gesturestart",e.END="-xterm-gesturesend",e.CONTEXT_MENU="-xterm-gesturecontextmenu"))(ue||={});var ht=class se extends L{constructor(){super(),this._dispatched=!1,this._targets=new Hs,this._ignoreTargets=new Hs,this._activeTouches={},this._handle=null,this._lastSetTapCountTime=0;let t=Ns;this._register(D(t.document,"touchstart",i=>this._handleTouchStart(i),{passive:!1})),this._register(D(t.document,"touchend",i=>this._handleTouchEnd(t,i))),this._register(D(t.document,"touchmove",i=>this._handleTouchMove(i),{passive:!1}))}static addTarget(t){if(!se.isTouchDevice())return L.None;se._instance||(se._instance=new se);let i=se._instance._targets.push(t);return O(i)}static ignoreTarget(t){if(!se.isTouchDevice())return L.None;se._instance||(se._instance=new se);let i=se._instance._ignoreTargets.push(t);return O(i)}static isTouchDevice(){return"ontouchstart"in Ns||navigator.maxTouchPoints>0}dispose(){this._handle&&(this._handle.dispose(),this._handle=null),super.dispose()}_handleTouchStart(t){let i=Date.now();this._handle&&(this._handle.dispose(),this._handle=null);for(let s=0,r=t.targetTouches.length;s=se._holdDelay&&Math.abs(l.initialPageX-ce(l.rollingPageX))<30&&Math.abs(l.initialPageY-ce(l.rollingPageY))<30){let c=this._newGestureEvent(ue.CONTEXT_MENU,l.initialTarget);c.pageX=ce(l.rollingPageX),c.pageY=ce(l.rollingPageY),this._dispatchEvent(c)}else if(r===1){let c=ce(l.rollingPageX),d=ce(l.rollingPageY),u=ce(l.rollingTimestamps)-l.rollingTimestamps[0],f=c-l.rollingPageX[0],_=d-l.rollingPageY[0],p=[...this._targets].filter(S=>l.initialTarget instanceof Node&&S.contains(l.initialTarget));this._inertia(t,p,s,Math.abs(f)/u,f>0?1:-1,c,Math.abs(_)/u,_>0?1:-1,d)}this._dispatchEvent(this._newGestureEvent(ue.END,l.initialTarget)),delete this._activeTouches[h.identifier]}this._dispatched&&(i.preventDefault(),i.stopPropagation(),this._dispatched=!1)}_newGestureEvent(t,i){let s=document.createEvent("CustomEvent");return s.initEvent(t,!1,!0),s.initialTarget=i,s.tapCount=0,s}_dispatchEvent(t){if(t.type===ue.TAP){let i=new Date().getTime(),s;i-this._lastSetTapCountTime>se._clearTapCountTime?s=1:s=2,this._lastSetTapCountTime=i,t.tapCount=s}else(t.type===ue.CHANGE||t.type===ue.CONTEXT_MENU)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let s of this._ignoreTargets)if(s.contains(t.initialTarget))return;let i=[];for(let s of this._targets)if(s.contains(t.initialTarget)){let r=0,n=t.initialTarget;for(;n&&n!==s;)r++,n=n.parentElement;i.push([r,s])}i.sort((s,r)=>s[0]-r[0]);for(let[,s]of i)s.dispatchEvent(t),this._dispatched=!0}}_inertia(t,i,s,r,n,o,h,l,a){this._handle=Vi(t,()=>{let c=Date.now(),d=c-s,u=0,f=0,_=!0;r+=se._scrollFriction*d,h+=se._scrollFriction*d,r>0&&(_=!1,u=n*r*d),h>0&&(_=!1,f=l*h*d);let p=this._newGestureEvent(ue.CHANGE);p.translationX=u,p.translationY=f,i.forEach(S=>S.dispatchEvent(p)),_||this._inertia(t,i,c,r,n,o+u,h,l,a+f)})}_handleTouchMove(t){let i=Date.now();for(let s=0,r=t.changedTouches.length;s3&&(o.rollingPageX.shift(),o.rollingPageY.shift(),o.rollingTimestamps.shift()),o.rollingPageX.push(n.pageX),o.rollingPageY.push(n.pageY),o.rollingTimestamps.push(i)}this._dispatched&&(t.preventDefault(),t.stopPropagation(),this._dispatched=!1)}};ht._scrollFriction=-.005,ht._holdDelay=700,ht._clearTapCountTime=400,F([$o],ht,"isTouchDevice",1);var Uo=ht,Ti=class{constructor(e,t,i,s,r,n,o,h,l){this._renderService=e,this._mouseCoordsService=t,this._mouseStateService=i,this._coreService=s,this._bufferService=r,this._optionsService=n,this._selectionService=o,this._logService=h,this._coreBrowserService=l,this._lastEvent=null,this._wheelPartialScroll=0,this._touchScrollAccumulator=0}bindMouse(e,t,i){let{element:s,document:r}=e,n={mouseup:null,wheel:null,mousedrag:null,mousemove:null},o=new le,h=new le;t(o),t(h);let l={target:e,focus:i,requestedEvents:n,mouseupListener:o,mousedragListener:h},a={mouseup:c=>this._handleMouseUp(l,c),wheel:c=>this._handleWheel(l,c),mousedrag:c=>this._handleMouseDrag(l,c),mousemove:c=>this._handleMouseMove(l,c)};this._altMouseCursor=new qo(s,r,()=>this._mouseStateService.areMouseEventsActive&&!!this._optionsService.rawOptions.mouseEventsRequireAlt),t(this._altMouseCursor),t(this._mouseStateService.onProtocolChange(c=>{this._handleProtocolChange(l,a,c)})),t(this._optionsService.onSpecificOptionChange("mouseEventsRequireAlt",()=>{this._syncMouseModeState(s),this._altMouseCursor?.sync()})),this._mouseStateService.activeProtocol=this._mouseStateService.activeProtocol,t(D(s,"mousedown",c=>this._handleMouseDown(l,c))),t(D(s,"wheel",c=>this._handlePassiveWheel(l,c),{passive:!1})),t(Uo.addTarget(e.screenElement)),t(D(e.screenElement,ue.START,()=>this._handleTouchStart())),t(D(e.screenElement,ue.CHANGE,c=>this._handleTouchChange(l,c)))}_sendEvent(e,t){let i=this._mouseCoordsService.getMouseReportCoords(t,e.target.screenElement);if(!i)return!1;let s,r;switch(t.overrideType||t.type){case"mousemove":r=32,t.buttons===void 0?(s=3,t.button!==void 0&&(s=t.button<3?t.button:3)):s=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case"mouseup":r=0,s=t.button<3?t.button:3;break;case"mousedown":r=1,s=t.button<3?t.button:3;break;case"wheel":if(!this._mouseStateService.allowCustomWheelEvent(t))return!1;let o=t.deltaY;if(o===0||this._consumeWheelEvent(t,this._renderService?.dimensions?.device?.cell?.height,this._coreBrowserService?.dpr)===0)return!1;r=o<0?0:1,s=4;break;default:return!1}if(r===void 0||s===void 0||s>4||s!==4&&this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive&&!t.altKey)return!1;let n=s!==4&&this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive;return this._triggerMouseEvent({col:i.col,row:i.row,x:i.x,y:i.y,button:s,action:r,ctrl:t.ctrlKey,alt:n?!1:t.altKey,shift:t.shiftKey})}_handleMouseUp(e,t){this._sendEvent(e,t),t.buttons||(e.mouseupListener.clear(),e.mousedragListener.clear())}_handleWheel(e,t){return this._sendEvent(e,t),t.preventDefault(),t.stopPropagation(),!1}_handleMouseDrag(e,t){t.buttons&&this._sendEvent(e,t)}_handleMouseMove(e,t){t.buttons||this._sendEvent(e,t)}_handleMouseDown(e,t){if(t.preventDefault(),e.focus(),!this._mouseStateService.areMouseEventsActive||this._selectionService.shouldForceSelection(t))return;this._sendEvent(e,t);let{element:i,document:s}=e.target,r=i.ownerDocument??s;e.requestedEvents.mouseup&&(e.mouseupListener.value=D(r,"mouseup",e.requestedEvents.mouseup)),e.requestedEvents.mousedrag&&(e.mousedragListener.value=D(r,"mousemove",e.requestedEvents.mousedrag))}_handlePassiveWheel(e,t){if(!e.requestedEvents.wheel){if(!this._mouseStateService.allowCustomWheelEvent(t))return!1;if(!this._bufferService.buffer.hasScrollback){if(t.deltaY===0)return!1;if(this._consumeWheelEvent(t,this._renderService?.dimensions?.device?.cell?.height,this._coreBrowserService?.dpr)===0)return t.preventDefault(),t.stopPropagation(),!1;let i="\x1B"+(this._coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(t.deltaY<0?"A":"B");return this._coreService.triggerDataEvent(i,!0),t.preventDefault(),t.stopPropagation(),!1}}}_handleTouchStart(){this._touchScrollAccumulator=0}_handleTouchChange(e,t){if(t.preventDefault(),t.stopPropagation(),e.requestedEvents.wheel){this._handleTouchScrollAsWheel(e,t);return}if(!this._bufferService.buffer.hasScrollback){this._handleTouchScrollAsKeys(t);return}e.target.handleTouchScroll?.(t.translationY)}_handleTouchScrollAsKeys(e){let t=this._renderService?.dimensions.css.cell.height;if(!t)return;this._touchScrollAccumulator-=e.translationY;let i=Math.trunc(this._touchScrollAccumulator/t);if(i===0)return;this._touchScrollAccumulator-=i*t;let s="\x1B"+(this._coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(i<0?"A":"B");for(let r=0;r0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(r*=this._bufferService.rows),r}_triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._mouseStateService.isPixelEncoding))||!this._mouseStateService.restrictMouseEvent(e))return!1;let t=this._mouseStateService.encodeMouseEvent(e);return t&&(this._mouseStateService.isDefaultEncoding?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}_explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,i){if(i){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return!(e.button!==t.button||e.action!==t.action||e.ctrl!==t.ctrl||e.alt!==t.alt||e.shift!==t.shift)}};Ti=F([g(0,ye),g(1,zt),g(2,Ft),g(3,De),g(4,ne),g(5,oe),g(6,gr),g(7,Je),g(8,be)],Ti);var qo=class{constructor(e,t,i){this._element=e,this._document=t,this._isActive=i,this._listeners=new le}dispose(){this._listeners.dispose()}sync(){if(this._listeners.clear(),!this._isActive())return;let e=new Qe,t=s=>this.syncFromModifier(s);e.add(D(this._document,"keydown",t)),e.add(D(this._document,"keyup",t)),e.add(D(this._element,"mousemove",t));let i=this._element.ownerDocument?.defaultView;i&&e.add(D(i,"blur",()=>{this._isActive()&&this.resetClass()})),this._listeners.value=e}resetClass(){this._updateClass(!1)}syncFromModifier(e){this._isActive()&&this._updateClass(e.getModifierState("Alt"))}_updateClass(e){e?this._element.classList.add("enable-mouse-events"):this._element.classList.remove("enable-mouse-events")}},Vo=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame!==void 0&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame??=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()),this._animationFrame}refresh(e,t,i){this._rowCount=i,e=e??0,t=t??this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},Lr=class{constructor(e){this._tasks=[],this._i=0,this._logService=e}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._ir){s-t<-20&&this._logService.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(s-t))}ms`),this._start();return}s=r}this.clear()}},Yo=class extends Lr{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},Xo=class extends Lr{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},Nt="requestIdleCallback"in globalThis?Xo:Yo,jo=class{constructor(e){this._queue=new Nt(e)}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}dispose(){this._queue.clear()}},Pi=class extends L{constructor(e,t,i,s,r,n,o,h,l,a){super(),this._rowCount=e,this._optionsService=i,this._logService=s,this._charSizeService=r,this._coreService=n,this._coreBrowserService=l,this._renderer=this._register(new le),this._observerDisposable=this._register(new le),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new y),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new y),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new y),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new y),this.onRefreshRequest=this._onRefreshRequest.event,this._pausedResizeTask=this._register(new jo(this._logService)),this._renderDebouncer=new Vo((c,d)=>this._renderRows(c,d),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new Go(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(O(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(h.onResize(()=>this._fullRefresh())),this._register(h.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(o.onDecorationRegistered(()=>this._fullRefresh())),this._register(o.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(h.cols,h.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(h.buffer.y,h.buffer.y,void 0,!0))),this._register(a.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(c=>this._registerIntersectionObserver(c,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if("IntersectionObserver"in e){let i=new e.IntersectionObserver(s=>this._handleIntersectionChange(s[s.length-1]),{threshold:0});this._observerDisposable.value=O(()=>{this._intersectionObserver?.disconnect(),this._intersectionObserver=void 0}),this._intersectionObserver=i,i.observe(t)}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,this._renderer.value?.handleViewportVisibilityChange?.(!this._isPaused),!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,i=!1,s=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let r=this._syncOutputHandler.flush();r&&(e=Math.min(e,r.start),t=Math.max(t,r.end)),s||(this._isNextRenderRedrawOnly=!1),i?this._renderRows(e,t):this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(t=>this.refreshRows(t.start,t.end,t.sync,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(e,t)):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,i){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=i,this._renderer.value?.handleSelectionChanged(e,t,i)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};Pi=F([g(2,oe),g(3,Je),g(4,Wt),g(5,De),g(6,mt),g(7,ne),g(8,be),g(9,Ze)],Pi);var Go=class{constructor(e,t,i){this._coreBrowserService=e,this._coreService=t,this._onTimeout=i,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout??=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3)}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function Jo(e,t,i,s){let r=i.buffer.x,n=i.buffer.y;if(!i.buffer.hasScrollback)return ea(r,n,e,t,i,s)+Ut(n,t,i,s)+ta(r,n,e,t,i,s);let o;if(n===t)return o=r>e?"D":"C",pt(Math.abs(r-e),ft(o,s));o=n>t?"D":"C";let h=Math.abs(n-t),l=Qo(n>t?e:r,i)+(h-1)*i.cols+1+Zo(n>t?r:e,i);return pt(l,ft(o,s))}function Zo(e,t){return e-1}function Qo(e,t){return t.cols-e}function ea(e,t,i,s,r,n){return Ut(t,s,r,n).length===0?"":pt(Tr(e,t,e,t-$e(t,r),!1,r).length,ft("D",n))}function Ut(e,t,i,s){let r=e-$e(e,i),n=t-$e(t,i),o=Math.abs(r-n)-ia(e,t,i);return pt(o,ft(Rr(e,t),s))}function ta(e,t,i,s,r,n){let o;Ut(t,s,r,n).length>0?o=s-$e(s,r):o=t;let h=s,l=sa(e,t,i,s,r,n);return pt(Tr(e,o,i,h,l==="C",r).length,ft(l,n))}function ia(e,t,i){let s=0,r=e-$e(e,i),n=t-$e(t,i);for(let o=0;o=0&&e0?o=s-$e(s,r):o=t,e=i&&ot?"A":"B"}function Tr(e,t,i,s,r,n){let o=e,h=t,l="";for(;(o!==i||h!==s)&&h>=0&&hn.cols-1?(l+=n.buffer.translateBufferLineToString(h,!1,e,o),o=0,e=0,h++):!r&&o<0&&(l+=n.buffer.translateBufferLineToString(h,!1,0,e+1),o=n.cols-1,e=o,h--);return l+n.buffer.translateBufferLineToString(h,!1,e,o)}function ft(e,t){return"\x1B"+(t?"O":"[")+e}function pt(e,t){e=Math.floor(e);let i="";for(let s=0;sthis._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):this.selectionStart&&this.selectionStart[1]<0?(this.selectionStart=[0,0],!0):!1}};function Fs(e,t){if(e.start.y>e.end.y)throw new Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var na="\xA0",oa=new RegExp(na,"g"),Ai=class extends L{constructor(e,t,i,s,r,n,o,h,l,a){super(),this._element=e,this._screenElement=t,this._linkifier=i,this._bufferService=s,this._coreService=r,this._mouseCoordsService=n,this._optionsService=o,this._mouseStateService=h,this._renderService=l,this._coreBrowserService=a,this._dragScrollAmount=0,this._enabled=!0,this._trimListener=this._register(new le),this._workCell=new ge,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new y),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new y),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new y),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new y),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=c=>this._handleMouseMove(c),this._mouseUpListener=c=>this._handleMouseUp(c),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener.value=this._bufferService.buffer.lines.onTrim(c=>this._handleTrim(c)),this._register(this._bufferService.buffers.onBufferActivate(c=>this._handleBufferActivate(c))),this.enable(),this._model=new ra(this._bufferService),this._activeSelectionMode=0,this._register(O(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(c=>{c.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return"";let i=this._bufferService.buffer,s=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return"";let r=e[0]r.replace(oa," ")).join($t?`\r `:` -`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),Ji&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!i||!s||!t?!1:this._areCoordsInSelection(t,i,s)}isCellInSelection(e,t){let i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!i||!s?!1:this._areCoordsInSelection([e,t],i,s)}_areCoordsInSelection(e,t,i){return e[1]>t[1]&&e[1]=t[0]&&e[0]=t[0]}_selectWordAtCursor(e,t){let i=this._linkifier.currentLink?.link?.range;if(i)return this._model.selectionStart=[i.start.x-1,i.start.y-1],this._model.selectionStartLength=Fs(i,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let s=this._getMouseBufferCoords(e);return s?(this._selectWordAt(s,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseCoordsService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=Qi(this._coreBrowserService.window,e,this._screenElement)[1],i=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=i?0:(t>i&&(t-=i),t=Math.min(Math.max(t,-50),50),t/=50,t/Math.abs(t)+Math.round(t*14))}shouldForceSelection(e){return this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive?!e.altKey:fe?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0&&!(this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive&&e.altKey)){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),50)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){let t=this.hasSelection;if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0,t&&this._fireOnSelectionChange(this._model.finalSelectionStart,this._model.finalSelectionEnd,!1);let i=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);i&&i.length!==this._model.selectionStart[0]&&i.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive?!1:e.altKey&&!(fe&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let i=this._bufferService.buffer;if(this._model.selectionEnd[1]0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows-1,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<500&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let i=this._mouseCoordsService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(i&&i[0]!==void 0&&i[1]!==void 0){let s=Jo(i[0]-1,i[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(s,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,i=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);if(!i){this._oldHasSelection&&this._fireOnSelectionChange(e,t,i);return}!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,i)}_fireOnSelectionChange(e,t,i){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=i,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.value=e.activeBuffer.lines.onTrim(t=>this._handleTrim(t))}_convertViewportColToCharacterIndex(e,t){let i=t;for(let s=0;t>=s;s++){let r=e.loadCell(s,this._workCell).getChars().length;this._workCell.getWidth()===0?i--:r>1&&t!==s&&(i+=r-1)}return i}setSelection(e,t,i){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=i,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,i=!0,s=!0){if(e[0]>=this._bufferService.cols)return;let r=this._bufferService.buffer,n=r.lines.get(e[1]);if(!n)return;let o=r.translateBufferLineToString(e[1],!1),h=this._convertViewportColToCharacterIndex(n,e[0]),l=h,a=e[0]-h,c=0,d=0,u=0,f=0;if(o.charAt(h)===" "){for(;h>0&&o.charAt(h-1)===" ";)h--;for(;l1&&(f+=R-1,l+=R-1);S>0&&h>0&&!this._isCharWordSeparator(n.loadCell(S-1,this._workCell));){n.loadCell(S-1,this._workCell);let E=this._workCell.getChars().length;this._workCell.getWidth()===0?(c++,S--):E>1&&(u+=E-1,h-=E-1),h--,S--}for(;k1&&(f+=E-1,l+=E-1),l++,k++}}l++;let _=h+a-c+u,p=Math.min(this._bufferService.cols,l-h+c+d-u-f);if(!(!t&&o.slice(h,l).trim()==="")){if(i&&_===0&&n.getCodePoint(0)!==32){let S=r.lines.get(e[1]-1);if(S&&n.isWrapped&&S.getCodePoint(this._bufferService.cols-1)!==32){let k=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(k){let R=this._bufferService.cols-k.start;_-=R,p+=R}}}if(s&&_+p===this._bufferService.cols&&n.getCodePoint(this._bufferService.cols-1)!==32){let S=r.lines.get(e[1]+1);if(S?.isWrapped&&S.getCodePoint(0)!==32){let k=this._getWordAt([0,e[1]+1],!1,!1,!0);k&&(p+=k.length)}}return{start:_,length:p}}}_selectWordAt(e,t){let i=this._getWordAt(e,t);if(i){for(;i.start<0;)i.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[i.start,e[1]],this._model.selectionStartLength=i.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let i=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,i--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,i++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,i]}}_isCharWordSeparator(e){return e.getWidth()===0?!1:this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),i={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=Fs(i,this._bufferService.cols)}};Ai=F([g(3,ne),g(4,Ee),g(5,zt),g(6,oe),g(7,Ft),g(8,ye),g(9,be)],Ai);var Ws=class{constructor(){this._data={}}set(e,t,i){this._data[e]||(this._data[e]={}),this._data[e][t]=i}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},zs=class{constructor(){this._color=new Ws,this._css=new Ws}setCss(e,t,i){this._css.set(e,t,i)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,i){this._color.set(e,t,i)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},Y=Object.freeze((()=>{let e=[W.toColor("#2e3436"),W.toColor("#cc0000"),W.toColor("#4e9a06"),W.toColor("#c4a000"),W.toColor("#3465a4"),W.toColor("#75507b"),W.toColor("#06989a"),W.toColor("#d3d7cf"),W.toColor("#555753"),W.toColor("#ef2929"),W.toColor("#8ae234"),W.toColor("#fce94f"),W.toColor("#729fcf"),W.toColor("#ad7fa8"),W.toColor("#34e2e2"),W.toColor("#eeeeec")],t=[0,95,135,175,215,255];for(let i=0;i<216;i++){let s=t[i/36%6|0],r=t[i/6%6|0],n=t[i%6];e.push({css:$.toCss(s,r,n),rgba:$.toRgba(s,r,n)})}for(let i=0;i<24;i++){let s=8+i*10;e.push({css:$.toCss(s,s,s),rgba:$.toRgba(s,s,s)})}return e})()),We=W.toColor("#ffffff"),lt=W.toColor("#000000"),Ks=W.toColor("#ffffff"),$s=lt,rt={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},aa=We,Oi=class extends L{constructor(e){super(),this._optionsService=e,this._contrastCache=new zs,this._halfContrastCache=new zs,this._onChangeColors=this._register(new y),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:We,background:lt,cursor:Ks,cursorAccent:$s,selectionForeground:void 0,selectionBackgroundTransparent:rt,selectionBackgroundOpaque:H.blend(lt,rt),selectionInactiveBackgroundTransparent:rt,selectionInactiveBackgroundOpaque:H.blend(lt,rt),scrollbarSliderBackground:H.opacity(We,.2),scrollbarSliderHoverBackground:H.opacity(We,.4),scrollbarSliderActiveBackground:H.opacity(We,.5),overviewRulerBorder:We,ansi:Y.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange("theme",()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=N(e.foreground,We),t.background=N(e.background,lt),t.cursor=H.blend(t.background,N(e.cursor,Ks)),t.cursorAccent=H.blend(t.background,N(e.cursorAccent,$s)),t.selectionBackgroundTransparent=N(e.selectionBackground,rt),t.selectionBackgroundOpaque=H.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=N(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=H.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?N(e.selectionForeground,Os):void 0,t.selectionForeground===Os&&(t.selectionForeground=void 0),H.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=H.opacity(t.selectionBackgroundTransparent,.3)),H.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=H.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=N(e.scrollbarSliderBackground,H.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=N(e.scrollbarSliderHoverBackground,H.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=N(e.scrollbarSliderActiveBackground,H.opacity(t.foreground,.5)),t.overviewRulerBorder=N(e.overviewRulerBorder,aa),t.ansi=Y.slice(),t.ansi[0]=N(e.black,Y[0]),t.ansi[1]=N(e.red,Y[1]),t.ansi[2]=N(e.green,Y[2]),t.ansi[3]=N(e.yellow,Y[3]),t.ansi[4]=N(e.blue,Y[4]),t.ansi[5]=N(e.magenta,Y[5]),t.ansi[6]=N(e.cyan,Y[6]),t.ansi[7]=N(e.white,Y[7]),t.ansi[8]=N(e.brightBlack,Y[8]),t.ansi[9]=N(e.brightRed,Y[9]),t.ansi[10]=N(e.brightGreen,Y[10]),t.ansi[11]=N(e.brightYellow,Y[11]),t.ansi[12]=N(e.brightBlue,Y[12]),t.ansi[13]=N(e.brightMagenta,Y[13]),t.ansi[14]=N(e.brightCyan,Y[14]),t.ansi[15]=N(e.brightWhite,Y[15]),e.extendedAnsi){let i=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let s=0;s"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"']};function la(e,t,i,s){let r={type:0,cancel:!1,key:void 0},n=(e.shiftKey?1:0)|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key==="UIKeyInputUpArrow"?t?r.key="\x1BOA":r.key="\x1B[A":e.key==="UIKeyInputLeftArrow"?t?r.key="\x1BOD":r.key="\x1B[D":e.key==="UIKeyInputRightArrow"?t?r.key="\x1BOC":r.key="\x1B[C":e.key==="UIKeyInputDownArrow"&&(t?r.key="\x1BOB":r.key="\x1B[B");break;case 8:r.key=e.ctrlKey?"\b":"\x7F",e.altKey&&(r.key="\x1B"+r.key);break;case 9:if(e.shiftKey){r.key="\x1B[Z";break}r.key=" ",r.cancel=!0;break;case 13:e.key==="c"&&e.ctrlKey?r.key="":r.key=e.altKey?"\x1B\r":"\r",r.cancel=!0;break;case 27:r.key="\x1B",e.altKey&&(r.key="\x1B\x1B"),r.cancel=!0;break;case 37:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"D":t?r.key="\x1BOD":r.key="\x1B[D";break;case 39:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"C":t?r.key="\x1BOC":r.key="\x1B[C";break;case 38:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"A":t?r.key="\x1BOA":r.key="\x1B[A";break;case 40:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"B":t?r.key="\x1BOB":r.key="\x1B[B";break;case 45:!e.shiftKey&&!e.ctrlKey&&(r.key="\x1B[2~");break;case 46:n?r.key="\x1B[3;"+(n+1)+"~":r.key="\x1B[3~";break;case 36:n?r.key="\x1B[1;"+(n+1)+"H":t?r.key="\x1BOH":r.key="\x1B[H";break;case 35:n?r.key="\x1B[1;"+(n+1)+"F":t?r.key="\x1BOF":r.key="\x1B[F";break;case 33:e.shiftKey?r.type=2:e.ctrlKey?r.key="\x1B[5;"+(n+1)+"~":r.key="\x1B[5~";break;case 34:e.shiftKey?r.type=3:e.ctrlKey?r.key="\x1B[6;"+(n+1)+"~":r.key="\x1B[6~";break;case 112:n?r.key="\x1B[1;"+(n+1)+"P":r.key="\x1BOP";break;case 113:n?r.key="\x1B[1;"+(n+1)+"Q":r.key="\x1BOQ";break;case 114:n?r.key="\x1B[1;"+(n+1)+"R":r.key="\x1BOR";break;case 115:n?r.key="\x1B[1;"+(n+1)+"S":r.key="\x1BOS";break;case 116:n?r.key="\x1B[15;"+(n+1)+"~":r.key="\x1B[15~";break;case 117:n?r.key="\x1B[17;"+(n+1)+"~":r.key="\x1B[17~";break;case 118:n?r.key="\x1B[18;"+(n+1)+"~":r.key="\x1B[18~";break;case 119:n?r.key="\x1B[19;"+(n+1)+"~":r.key="\x1B[19~";break;case 120:n?r.key="\x1B[20;"+(n+1)+"~":r.key="\x1B[20~";break;case 121:n?r.key="\x1B[21;"+(n+1)+"~":r.key="\x1B[21~";break;case 122:n?r.key="\x1B[23;"+(n+1)+"~":r.key="\x1B[23~";break;case 123:n?r.key="\x1B[24;"+(n+1)+"~":r.key="\x1B[24~";break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?r.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?r.key="\0":e.keyCode>=51&&e.keyCode<=55?r.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?r.key="\x7F":e.key==="/"?r.key="":e.keyCode===219?r.key="\x1B":e.keyCode===220?r.key="":e.keyCode===221&&(r.key="");else if((!i||s)&&e.altKey&&!e.metaKey){let o=ha[e.keyCode]?.[e.shiftKey?1:0];if(o)r.key="\x1B"+o;else if(e.keyCode>=65&&e.keyCode<=90){let h=e.ctrlKey?e.keyCode-64:e.keyCode+32,l=String.fromCharCode(h);e.shiftKey&&(l=l.toUpperCase()),r.key="\x1B"+l}else if(e.keyCode===32)r.key="\x1B"+(e.ctrlKey?"\0":" ");else if(e.key==="Dead"&&e.code.startsWith("Key")){let h=e.code.slice(3,4);e.shiftKey||(h=h.toLowerCase()),r.key="\x1B"+h,r.cancel=!0}}else if(i&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey)e.keyCode===65&&(r.type=1);else if(e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1)r.key=e.key;else if(e.key&&e.ctrlKey&&e.shiftKey)switch(e.code){case"Minus":r.key="";break;case"Digit2":r.key="\0";break;case"Digit6":r.key="";break}break}return r}var Us=class{constructor(){this._functionalKeyCodes={Escape:27,Enter:13,Tab:9,Backspace:127,CapsLock:57358,ScrollLock:57359,NumLock:57360,PrintScreen:57361,Pause:57362,ContextMenu:57363,F13:57376,F14:57377,F15:57378,F16:57379,F17:57380,F18:57381,F19:57382,F20:57383,F21:57384,F22:57385,F23:57386,F24:57387,F25:57388,KP_0:57399,KP_1:57400,KP_2:57401,KP_3:57402,KP_4:57403,KP_5:57404,KP_6:57405,KP_7:57406,KP_8:57407,KP_9:57408,KP_Decimal:57409,KP_Divide:57410,KP_Multiply:57411,KP_Subtract:57412,KP_Add:57413,KP_Enter:57414,KP_Equal:57415,ShiftLeft:57441,ShiftRight:57447,ControlLeft:57442,ControlRight:57448,AltLeft:57443,AltRight:57449,MetaLeft:57444,MetaRight:57450,MediaPlayPause:57430,MediaStop:57432,MediaTrackNext:57435,MediaTrackPrevious:57436,AudioVolumeDown:57438,AudioVolumeUp:57439,AudioVolumeMute:57440},this._csiTildeKeys={Insert:2,Delete:3,PageUp:5,PageDown:6,F5:15,F6:17,F7:18,F8:19,F9:20,F10:21,F11:23,F12:24},this._csiLetterKeys={ArrowUp:"A",ArrowDown:"B",ArrowRight:"C",ArrowLeft:"D",Home:"H",End:"F"},this._ss3FunctionKeys={F1:"P",F2:"Q",F3:"R",F4:"S"}}_getNumpadKeyCode(e){if(e.code.startsWith("Numpad")){let t=e.code.slice(6);if(t>="0"&&t<="9")return 57399+parseInt(t,10);switch(t){case"Decimal":return 57409;case"Divide":return 57410;case"Multiply":return 57411;case"Subtract":return 57412;case"Add":return 57413;case"Enter":return 57414;case"Equal":return 57415}}}_getModifierKeyCode(e){switch(e.code){case"ShiftLeft":return 57441;case"ShiftRight":return 57447;case"ControlLeft":return 57442;case"ControlRight":return 57448;case"AltLeft":return 57443;case"AltRight":return 57449;case"MetaLeft":return 57444;case"MetaRight":return 57450}}_encodeModifiers(e){let t=0;return e.shiftKey&&(t|=1),e.altKey&&(t|=2),e.ctrlKey&&(t|=4),e.metaKey&&(t|=8),t>0?t+1:0}_getKeyCode(e,t){let i=this._getNumpadKeyCode(e);if(i!==void 0)return i;let s=this._getModifierKeyCode(e);if(s!==void 0)return s;let r=this._functionalKeyCodes[e.key];if(r!==void 0)return r;if((e.shiftKey||t&&e.altKey)&&e.code){if(e.code.startsWith("Digit")&&e.code.length===6){let n=e.code.charAt(5);if(n>="0"&&n<="9")return n.charCodeAt(0)}if(e.code.startsWith("Key")&&e.code.length===4)return e.code.charAt(3).toLowerCase().charCodeAt(0)}if(e.key.length===1){let n=e.key.codePointAt(0);return n>=65&&n<=90?n+32:n}}_isModifierKey(e){return e.key==="Shift"||e.key==="Control"||e.key==="Alt"||e.key==="Meta"}_isLockKey(e){return e.key==="CapsLock"||e.key==="NumLock"||e.key==="ScrollLock"}_buildCsiLetterSequence(e,t,i,s){let r=s&&i!==1;if(t>0||r){let n="\x1B[1;"+(t>0?t:"1");return r&&(n+=":"+i),n+=e,n}return"\x1B["+e}_buildSs3Sequence(e,t,i,s){let r=s&&i!==1;if(t>0||r){let n="\x1B[1;"+(t>0?t:"1");return r&&(n+=":"+i),n+=e,n}return"\x1BO"+e}_buildCsiTildeSequence(e,t,i,s){let r=s&&i!==1,n="\x1B["+e;return(t>0||r)&&(n+=";"+(t>0?t:"1"),r&&(n+=":"+i)),n+="~",n}_buildCsiUSequence(e,t,i,s,r,n,o){let h=!!(r&2),l=!!(r&4),a="\x1B["+t,c;l&&e.shiftKey&&e.key.length===1&&!n&&!o&&(c=e.key.codePointAt(0),a+=":"+c);let d=r&16&&s!==3&&e.key.length===1&&!n&&!o&&!e.ctrlKey?e.key.codePointAt(0):void 0,u=h&&s!==1&&(s===3||d===void 0);return(i>0||u||d!==void 0)&&(a+=";",i>0?a+=i:u&&(a+="1"),u&&(a+=":"+s)),d!==void 0&&(a+=";"+d),a+="u",a}evaluate(e,t,i=1,s=!1){let r={type:0,cancel:!1,key:void 0},n=this._encodeModifiers(e),o=this._isModifierKey(e),h=!!(t&2);if(!h&&i===3||o&&!(t&8)||this._isLockKey(e)&&!(t&8))return r;let l=this._csiLetterKeys[e.key];if(l)return r.key=this._buildCsiLetterSequence(l,n,i,h),r.cancel=!0,r;let a=this._ss3FunctionKeys[e.key];if(a)return r.key=this._buildSs3Sequence(a,n,i,h),r.cancel=!0,r;let c=this._csiTildeKeys[e.key];if(c!==void 0)return r.key=this._buildCsiTildeSequence(c,n,i,h),r.cancel=!0,r;let d=this._getKeyCode(e,s);if(d===void 0)return r;let u=d===13||d===9||d===127;if(u&&i===3&&!(t&8))return r;let f=this._functionalKeyCodes[e.key]!==void 0||this._getNumpadKeyCode(e)!==void 0;if(t&8||h&&i===3||(t&1||h)&&(f&&!u||n>0&&e.key.length!==1||n-1>1))r.key=this._buildCsiUSequence(e,d,n,i,t,f,o),r.cancel=!0;else{let _=d===13?"\r":d===9?" ":d===127?"\x7F":void 0;_?r.key=_:e.key.length===1&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&(r.key=e.key)}return r}static shouldUseProtocol(e){return e>0}},ca=class{constructor(){this._codeToVk={KeyA:65,KeyB:66,KeyC:67,KeyD:68,KeyE:69,KeyF:70,KeyG:71,KeyH:72,KeyI:73,KeyJ:74,KeyK:75,KeyL:76,KeyM:77,KeyN:78,KeyO:79,KeyP:80,KeyQ:81,KeyR:82,KeyS:83,KeyT:84,KeyU:85,KeyV:86,KeyW:87,KeyX:88,KeyY:89,KeyZ:90,Digit0:48,Digit1:49,Digit2:50,Digit3:51,Digit4:52,Digit5:53,Digit6:54,Digit7:55,Digit8:56,Digit9:57,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,F13:124,F14:125,F15:126,F16:127,F17:128,F18:129,F19:130,F20:131,F21:132,F22:133,F23:134,F24:135,Numpad0:96,Numpad1:97,Numpad2:98,Numpad3:99,Numpad4:100,Numpad5:101,Numpad6:102,Numpad7:103,Numpad8:104,Numpad9:105,NumpadMultiply:106,NumpadAdd:107,NumpadSeparator:108,NumpadSubtract:109,NumpadDecimal:110,NumpadDivide:111,NumpadEnter:13,NumLock:144,ArrowUp:38,ArrowDown:40,ArrowLeft:37,ArrowRight:39,Home:36,End:35,PageUp:33,PageDown:34,Insert:45,Delete:46,ShiftLeft:16,ShiftRight:16,ControlLeft:17,ControlRight:17,AltLeft:18,AltRight:18,MetaLeft:91,MetaRight:92,CapsLock:20,ScrollLock:145,Escape:27,Enter:13,Tab:9,Space:32,Backspace:8,Pause:19,ContextMenu:93,PrintScreen:44,Semicolon:186,Equal:187,Comma:188,Minus:189,Period:190,Slash:191,Backquote:192,BracketLeft:219,Backslash:220,BracketRight:221,Quote:222,IntlBackslash:226},this._codeToScancode={KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,F11:87,F12:88,Numpad0:82,Numpad1:79,Numpad2:80,Numpad3:81,Numpad4:75,Numpad5:76,Numpad6:77,Numpad7:71,Numpad8:72,Numpad9:73,NumpadMultiply:55,NumpadAdd:78,NumpadSubtract:74,NumpadDecimal:83,NumpadDivide:53,NumpadEnter:28,NumLock:69,ArrowUp:72,ArrowDown:80,ArrowLeft:75,ArrowRight:77,Home:71,End:79,PageUp:73,PageDown:81,Insert:82,Delete:83,ShiftLeft:42,ShiftRight:54,ControlLeft:29,ControlRight:29,AltLeft:56,AltRight:56,CapsLock:58,ScrollLock:70,Escape:1,Enter:28,Tab:15,Space:57,Backspace:14,Pause:69,Semicolon:39,Equal:13,Comma:51,Minus:12,Period:52,Slash:53,Backquote:41,BracketLeft:26,Backslash:43,BracketRight:27,Quote:40},this._enhancedKeyCodes=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Insert","Delete","NumpadEnter","NumpadDivide","ControlRight","AltRight","PrintScreen","Pause","ContextMenu","MetaLeft","MetaRight"]),this._keyToControlChar={Enter:13,Backspace:8,Tab:9,Escape:27}}_getVirtualKeyCode(e){let t=this._codeToVk[e.code];return t!==void 0?t:e.keyCode||0}_getScanCode(e){return this._codeToScancode[e.code]||0}_getUnicodeChar(e){if(e.ctrlKey&&!e.altKey&&!e.metaKey){if(e.key==="Enter")return 10;if(e.key==="Backspace")return 127}let t=this._keyToControlChar[e.key];if(t!==void 0)return t;if(e.key.length===1){let i=e.key.codePointAt(0)||0;if(e.ctrlKey&&!e.altKey&&!e.metaKey){if(i>=65&&i<=90)return i-64;if(i>=97&&i<=122)return i-96}return i}return 0}_getControlKeyState(e){let t=0;return e.shiftKey&&(t|=16),e.ctrlKey&&(e.code==="ControlRight"?t|=4:t|=8),e.altKey&&(e.code==="AltRight"?t|=1:t|=2),this._enhancedKeyCodes.has(e.code)&&(t|=256),t}evaluateKeyboardEvent(e,t){let i=this._getVirtualKeyCode(e),s=this._getScanCode(e),r=this._getUnicodeChar(e),n=t?1:0,o=this._getControlKeyState(e);return{type:0,cancel:!0,key:`\x1B[${i};${s};${r};${n};${o};1_`}}},Ii=class{constructor(e,t){this._coreService=e,this._optionsService=t}_getWin32InputMode(){return this._win32InputMode??=new ca,this._win32InputMode}_getKittyKeyboard(){return this._kittyKeyboard??=new Us,this._kittyKeyboard}evaluateKeyDown(e){if(this.useWin32InputMode)return this._getWin32InputMode().evaluateKeyboardEvent(e,!0);let t=this._coreService.kittyKeyboard.flags;return this.useKitty?this._getKittyKeyboard().evaluate(e,t,e.repeat?2:1,fe&&this._optionsService.rawOptions.macOptionIsMeta):la(e,this._coreService.decPrivateModes.applicationCursorKeys,fe,this._optionsService.rawOptions.macOptionIsMeta)}evaluateKeyUp(e){if(this.useWin32InputMode)return this._getWin32InputMode().evaluateKeyboardEvent(e,!1);let t=this._coreService.kittyKeyboard.flags;if(this.useKitty&&t&2)return this._getKittyKeyboard().evaluate(e,t,3,fe&&this._optionsService.rawOptions.macOptionIsMeta)}get useKitty(){let e=this._coreService.kittyKeyboard.flags;return!!(this._optionsService.rawOptions.vtExtensions?.kittyKeyboard&&Us.shouldUseProtocol(e))}get useWin32InputMode(){return!!(this._optionsService.rawOptions.vtExtensions?.win32InputMode&&this._coreService.decPrivateModes.win32InputMode)}};Ii=F([g(0,Ee),g(1,oe)],Ii);var da=class{constructor(...e){this._entries=new Map;for(let[t,i]of e)this.set(t,i)}set(e,t){let i=this._entries.get(e);return this._entries.set(e,t),i}forEach(e){for(let[t,i]of this._entries.entries())e(t,i)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},_a=class{constructor(){this._services=new da,this._services.set(qi,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let i=Vn(e).sort((n,o)=>n.index-o.index),s=[];for(let n of i){let o=this._services.get(n.id);if(!o)throw new Error(`[createInstance] ${e.name} depends on UNKNOWN service ${n.id._id}.`);s.push(o)}let r=i.length>0?i[0].index:t.length;if(t.length!==r)throw new Error(`[createInstance] First service dependency of ${e.name} at position ${r+1} conflicts with ${t.length} static arguments`);return new e(...t,...s)}},ua={trace:0,debug:1,info:2,warn:3,error:4,off:5},fa="xterm.js: ",Ni=class extends L{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange("logLevel",()=>this._updateLogLevel()))}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=ua[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;tthis._length)for(let t=this._length;t=e;s--)this._array[this._getCyclicIndex(s+i.length)]=this._array[this._getCyclicIndex(s)];for(let s=0;sthis._maxLength){let s=this._length+i.length-this._maxLength;this._startIndex+=s,this._length=this._maxLength,this.onTrimEmitter.fire(s)}else this._length+=i.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,i){if(!(t<=0)){if(e<0||e>=this._length)throw new Error("start argument out of range");if(e+i<0)throw new Error("Cannot shift elements in list beyond index 0");if(i>0){for(let r=t-1;r>=0;r--)this.set(e+r+i,this.get(e+r));let s=e+t+i-this._length;if(s>0)for(this._length+=s;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let s=0;sthis._limit?(this._builder.reset(),!0):!1}toString(){return this._builder.toString()}},j=Object.freeze(new vt),Et=0,Vs=new ge,Dt=new Pr,ct=class Ar{constructor(t,i,s,r=!1){this._stringCache=t,this.isWrapped=r,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(i*3);let n=s??ge.fromCharData([0,"",1,0]);for(let o=0;o>22,i&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):s]}set(t,i){this._invalidateStringCache(),this._data[t*3+1]=i[0],i[1].length>1?(this._combined[t]=i[1],this._data[t*3+0]=t|2097152|i[2]<<22):this._data[t*3+0]=i[1].charCodeAt(0)|i[2]<<22}getWidth(t){return this._data[t*3+0]>>22}hasWidth(t){return this._data[t*3+0]&12582912}getFg(t){return this._data[t*3+1]}getBg(t){return this._data[t*3+2]}hasContent(t){return this._data[t*3+0]&4194303}getCodePoint(t){let i=this._data[t*3+0];return i&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):i&2097151}isCombined(t){return this._data[t*3+0]&2097152}getString(t){let i=this._data[t*3+0];return i&2097152?this._combined[t]:i&2097151?Ae(i&2097151):""}isProtected(t){return this._data[t*3+2]&536870912}loadCell(t,i){return Et=t*3,i.content=this._data[Et+0],i.fg=this._data[Et+1],i.bg=this._data[Et+2],i.content&2097152?i.combinedData=this._combined[t]:i.combinedData="",i.bg&268435456?i.extended=this._extendedAttrs[t]:i.extended=j.extended.clone(),i}setCell(t,i){this._invalidateStringCache(),i.content&2097152&&(this._combined[t]=i.combinedData),i.bg&268435456&&(this._extendedAttrs[t]=i.extended),this._data[t*3+0]=i.content,this._data[t*3+1]=i.fg,this._data[t*3+2]=i.bg}setCellFromCodepoint(t,i,s,r){this._invalidateStringCache(),r.bg&268435456&&(this._extendedAttrs[t]=r.extended),this._data[t*3+0]=i|s<<22,this._data[t*3+1]=r.fg,this._data[t*3+2]=r.bg}addCodepointToCell(t,i,s){this._invalidateStringCache();let r=this._data[t*3+0];r&2097152?this._combined[t]+=Ae(i):r&2097151?(this._combined[t]=Ae(r&2097151)+Ae(i),r&=-2097152,r|=2097152):r=i|1<<22,s&&(r&=-12582913,r|=s<<22),this._data[t*3+0]=r}insertCells(t,i,s){if(this._invalidateStringCache(),t%=this.length,t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,s),i=0;--r)this.setCell(t+i+r,this.loadCell(t+r,Vs));for(let r=0;rthis.length){if(this._data.buffer.byteLength>=s*4)this._data=new Uint32Array(this._data.buffer,0,s);else{let r=new Uint32Array(s);r.set(this._data),this._data=r}for(let r=this.length;r=t&&delete this._combined[h]}let n=Object.keys(this._extendedAttrs);for(let o=0;o=t&&delete this._extendedAttrs[h]}}return this.length=t,s*4*2=0;--t)if(this._data[t*3+0]&4194303)return t+(this._data[t*3+0]>>22);return 0}getNoBgTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*3+0]&4194303||this._data[t*3+2]&50331648)return t+(this._data[t*3+0]>>22);return 0}copyCellsFrom(t,i,s,r,n){this._invalidateStringCache();let o=t._data;if(n)for(let h=r-1;h>=0;h--){for(let l=0;l<3;l++)this._data[(s+h)*3+l]=o[(i+h)*3+l];this._copyCellMapsFrom(t,i+h,s+h)}else for(let h=0;h>22||1}r&&r.push(i);let h=Dt.toString();if(Dt.reset(),n){let l=this._getStringCacheEntry(!0);l.value=h,l.isTrimmed=!!t}return h}_getStringCacheEntry(t){let i=this._stringCacheEntryRef?.deref();if(i&&i.generation===this._stringCache.generation)return i;if(!t)return;let s=this._stringCache.allocateEntry();return this._stringCacheEntryRef=new WeakRef(s),s}_invalidateStringCache(){let t=this._getStringCacheEntry(!1);t&&(t.value=void 0,t.isTrimmed=!1)}_copyCellMapsFrom(t,i,s){let r=i*3;t._data[r+0]&2097152&&(this._combined[s]=t._combined[i]),t._data[r+2]&268435456&&(this._extendedAttrs[s]=t._extendedAttrs[i])}_copySparseMapsFrom(t){this._combined={},this._extendedAttrs={};for(let i=0;ithis.entries.clear()))}touch(){this._scheduleClear()}allocateEntry(){let e={value:void 0,isTrimmed:!1,generation:this.generation};return this.entries.add(e),this._scheduleClear(),e}clear(){this._clearTimeout.clear(),this._lastAccessTimestamp=0,this.generation++;for(let e of this.entries)e.value=void 0,e.isTrimmed=!1;this.entries.clear()}_scheduleClear(){this._lastAccessTimestamp=Date.now(),!this._clearTimeout.value&&this._scheduleClearTimeout(15e3)}_scheduleClearTimeout(e){this._clearTimeout.value=Qn(()=>{let t=Date.now()-this._lastAccessTimestamp;if(t>=15e3){this.clear();return}this._scheduleClearTimeout(15e3-t)},e)}};function ga(e,t,i,s,r,n){let o=[];for(let h=0;h=h&&s0&&(S>d||c[S].getTrimmedLength()===0);S--)p++;p>0&&(o.push(h+c.length-p),o.push(p)),h+=c.length-1}return o}function va(e,t){let i=[],s=0,r=t[s],n=0;for(let o=0;ol&&(n-=l,o++);let a=e[o].getWidth(n-1)===2;a&&n--;let c=a?i-1:i;s.push(c),h+=c}return s}function gt(e,t,i){if(t===e.length-1)return e[t].getTrimmedLength();let s=!e[t].hasContent(i-1)&&e[t].getWidth(i-1)===1,r=e[t+1].getWidth(0)===2;return s&&r?i-1:i}var Or=class Ir{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=Ir._nextId++,this._onDispose=this.register(new y),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),ut(this._disposables),this._disposables.length=0)}register(t){return this._disposables.push(t),t}};Or._nextId=1;var wa=Or,G={},ze=G.B;G[0]={"`":"\u25C6",a:"\u2592",b:"\u2409",c:"\u240C",d:"\u240D",e:"\u240A",f:"\xB0",g:"\xB1",h:"\u2424",i:"\u240B",j:"\u2518",k:"\u2510",l:"\u250C",m:"\u2514",n:"\u253C",o:"\u23BA",p:"\u23BB",q:"\u2500",r:"\u23BC",s:"\u23BD",t:"\u251C",u:"\u2524",v:"\u2534",w:"\u252C",x:"\u2502",y:"\u2264",z:"\u2265","{":"\u03C0","|":"\u2260","}":"\xA3","~":"\xB7"};G.A={"#":"\xA3"};G.B=void 0;G[4]={"#":"\xA3","@":"\xBE","[":"ij","\\":"\xBD","]":"|","{":"\xA8","|":"f","}":"\xBC","~":"\xB4"};G.C=G[5]={"[":"\xC4","\\":"\xD6","]":"\xC5","^":"\xDC","`":"\xE9","{":"\xE4","|":"\xF6","}":"\xE5","~":"\xFC"};G.R={"#":"\xA3","@":"\xE0","[":"\xB0","\\":"\xE7","]":"\xA7","{":"\xE9","|":"\xF9","}":"\xE8","~":"\xA8"};G.Q={"@":"\xE0","[":"\xE2","\\":"\xE7","]":"\xEA","^":"\xEE","`":"\xF4","{":"\xE9","|":"\xF9","}":"\xE8","~":"\xFB"};G.K={"@":"\xA7","[":"\xC4","\\":"\xD6","]":"\xDC","{":"\xE4","|":"\xF6","}":"\xFC","~":"\xDF"};G.Y={"#":"\xA3","@":"\xA7","[":"\xB0","\\":"\xE7","]":"\xE9","`":"\xF9","{":"\xE0","|":"\xF2","}":"\xE8","~":"\xEC"};G.E=G[6]={"@":"\xC4","[":"\xC6","\\":"\xD8","]":"\xC5","^":"\xDC","`":"\xE4","{":"\xE6","|":"\xF8","}":"\xE5","~":"\xFC"};G.Z={"#":"\xA3","@":"\xA7","[":"\xA1","\\":"\xD1","]":"\xBF","{":"\xB0","|":"\xF1","}":"\xE7"};G.H=G[7]={"@":"\xC9","[":"\xC4","\\":"\xD6","]":"\xC5","^":"\xDC","`":"\xE9","{":"\xE4","|":"\xF6","}":"\xE5","~":"\xFC"};G["="]={"#":"\xF9","@":"\xE0","[":"\xE9","\\":"\xE7","]":"\xEA","^":"\xEE",_:"\xE8","`":"\xF4","{":"\xE4","|":"\xF6","}":"\xFC","~":"\xFB"};var Ys=4294967295,Xs=class extends L{constructor(e,t,i,s){super(),this._hasScrollback=e,this._optionsService=t,this._bufferService=i,this._logService=s,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=j.clone(),this.savedCharset=ze,this.savedCharsets=[],this.savedGlevel=0,this.savedOriginMode=!1,this.savedWraparoundMode=!0,this.markers=[],this._nullCell=ge.fromCharData([0,"",1,0]),this._whitespaceCell=ge.fromCharData([0," ",1,32]),this._isClearing=!1,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new qs(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops(),this._memoryCleanupQueue=new Nt(this._logService),this._register(O(()=>this._memoryCleanupQueue.clear())),this._register(O(()=>this.clearAllMarkers())),this._stringCache=this._register(new pa)}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new Pt),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new Pt),this._whitespaceCell}getBlankLine(e,t){return new ct(this._stringCache,this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&eYs?Ys:t}fillViewportRows(e){if(this.lines.length===0){e??=j;let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this._stringCache.clear(),this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new qs(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let i=this.getNullCell(j);this._stringCache.clear();let s=0,r=this._getCorrectBufferLength(t);if(r>this.lines.maxLength&&(this.lines.maxLength=r),this.lines.length>0){if(this._cols0&&this.lines.length<=this.ybase+this.y+n+1?(this.ybase--,n++,this.ydisp>0&&this.ydisp--):this.lines.push(new ct(this._stringCache,e,i,!1)));else for(let o=this._rows;o>t;o--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(r0&&(this.lines.trimStart(o),this.ybase=Math.max(this.ybase-o,0),this.ydisp=Math.max(this.ydisp-o,0),this.savedY=Math.max(this.savedY-o,0)),this.lines.maxLength=r}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),n&&(this.y+=n),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let n=0;n0){let n=Math.max(0,this.lines.length-this.ybase-1);this.y=Math.min(this.y,n)}this._memoryCleanupQueue.clear(),s>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend==="conpty"&&e.buildNumber>=21376:this._hasScrollback}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let i=this._optionsService.rawOptions.reflowCursorLine,s=ga(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(j),i);if(s.length>0){let r=va(this.lines,s);ma(this.lines,r.layout),this._reflowLargerAdjustViewport(e,t,r.countRemoved)}}_reflowLargerAdjustViewport(e,t,i){let s=this.getNullCell(j),r=i;for(;r-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length=0;o--){let h=this.lines.get(o);if(!h||!h.isWrapped&&h.getTrimmedLength()<=e)continue;let l=[h];for(;h.isWrapped&&o>0;)h=this.lines.get(--o),l.unshift(h);if(!i){let E=this.ybase+this.y;if(E>=o&&E0&&(r.push({start:o+l.length+n,newLines:f}),n+=f.length),l.push(...f);let _=c.length-1,p=c[_];p===0&&(_--,p=c[_]);let S=l.length-d-1,k=a;for(;S>=0;){let E=Math.min(k,p);if(l[_]===void 0)break;if(l[_].copyCellsFrom(l[S],k-E,p-E,E,!0),p-=E,p===0&&(_--,p=c[_]),k-=E,k===0){S--;let B=Math.max(S,0);k=gt(l,B,this._cols)}}for(let E=0;E0;)this.ybase===0?this.y0){let o=[],h=[];for(let p=0;p=0;p--)if(d&&d.start>a+u){for(let S=d.newLines.length-1;S>=0;S--)this.lines.set(p--,d.newLines[S]);p++,o.push({index:a+1,amount:d.newLines.length}),u+=d.newLines.length,d=r[++c]}else this.lines.set(p,h[a--]);let f=0;for(let p=o.length-1;p>=0;p--)o[p].index+=f,this.lines.onInsertEmitter.fire(o[p]),f+=o[p].amount;let _=Math.max(0,l+n-this.lines.maxLength);_>0&&this.lines.onTrimEmitter.fire(_)}}translateBufferLineToString(e,t,i=0,s){let r=this.lines.get(e);return r?r.translateToString(t,i,s):""}getWrappedRangeForLine(e){let t=e,i=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;i+10;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t{t.line-=i,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(i=>{t.line>=i.index&&(t.line+=i.amount)})),t.register(this.lines.onDelete(i=>{t.line>=i.index&&t.linei.index&&(t.line-=i.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},ba=class extends L{constructor(e,t,i){super(),this._optionsService=e,this._bufferService=t,this._logService=i,this._normalBuffer=this._register(new le),this._altBuffer=this._register(new le),this._onBufferActivate=this._register(new y),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange("scrollback",()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange("tabStopWidth",()=>this.setupTabStops()))}reset(){this._normal=new Xs(!0,this._optionsService,this._bufferService,this._logService),this._normalBuffer.value=this._normal,this._normal.fillViewportRows(),this._alt=new Xs(!1,this._optionsService,this._bufferService,this._logService),this._altBuffer.value=this._alt,this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},Hi=class extends L{constructor(e,t){super(),this.isUserScrolling=!1,this._onResize=this._register(new y),this.onResize=this._onResize.event,this._onScroll=this._register(new y),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,2),this.rows=Math.max(e.rawOptions.rows||0,1),this.buffers=this._register(new ba(e,this,t)),this._register(this.buffers.onBufferActivate(i=>{this._onScroll.fire(i.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let i=this.cols!==e,s=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:i,rowsChanged:s})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let i=this.buffer,s;s=this._cachedBlankLine,(!s||s.length!==this.cols||s.getFg(0)!==e.fg||s.getBg(0)!==e.bg)&&(s=i.getBlankLine(e,t),this._cachedBlankLine=s),s.isWrapped=t;let r=i.ybase+i.scrollTop,n=i.ybase+i.scrollBottom;if(i.scrollTop===0){let o=i.lines.isFull;n===i.lines.length-1?o?i.lines.recycle().copyFrom(s):i.lines.push(s.clone()):i.lines.splice(n+1,0,s.clone()),o?this.isUserScrolling&&(i.ydisp=Math.max(i.ydisp-1,0)):(i.ybase++,this.isUserScrolling||i.ydisp++)}else{let o=n-r+1;i.lines.shiftElements(r+1,o-1,-1),i.lines.set(n,s.clone())}this.isUserScrolling||(i.ydisp=i.ybase),this._onScroll.fire(i.ydisp)}scrollLines(e,t){let i=this.buffer;if(e<0){if(i.ydisp===0)return;this.isUserScrolling=!0}else e+i.ydisp>=i.ybase&&(this.isUserScrolling=!1);let s=i.ydisp;i.ydisp=Math.max(Math.min(i.ydisp+e,i.ybase),0),s!==i.ydisp&&(t||this._onScroll.fire(i.ydisp))}};Hi=F([g(0,oe),g(1,Je)],Hi);var Xe={cols:80,rows:24,showCursorImmediately:!1,cursorBlink:!1,blinkIntervalDuration:0,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollSensitivity:5,fontFamily:"monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollbar:{showScrollbar:!0},scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,mouseEventsRequireAlt:!1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:fe,windowOptions:{},windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",quirks:{},vtExtensions:{}},ya=["normal","bold","100","200","300","400","500","600","700","800","900"],Ca=class extends L{constructor(e){super(),this._onOptionChange=this._register(new y),this.onOptionChange=this._onOptionChange.event;let t={...Xe};for(let i in e)if(i in t)try{let s=e[i];t[i]=this._sanitizeAndValidateOption(i,s)}catch(s){console.error(s)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(O(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(i=>{i===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(i=>{e.indexOf(i)!==-1&&t()})}_setupOptions(){let e=i=>{if(!(i in Xe))throw new Error(`No option with key "${i}"`);return this.rawOptions[i]},t=(i,s)=>{if(!(i in Xe))throw new Error(`No option with key "${i}"`);s=this._sanitizeAndValidateOption(i,s),this.rawOptions[i]!==s&&(this.rawOptions[i]=s,this._onOptionChange.fire(i))};for(let i in this.rawOptions){let s={get:e.bind(this,i),set:t.bind(this,i)};Object.defineProperty(this.options,i,s)}}_sanitizeAndValidateOption(e,t){switch(e){case"cursorStyle":if(t||(t=Xe[e]),!ka(t))throw new Error(`"${t}" is not a valid value for ${e}`);break;case"wordSeparator":t||(t=Xe[e]);break;case"fontWeight":case"fontWeightBold":if(typeof t=="number"&&1<=t&&t<=1e3)break;t=ya.includes(t)?t:Xe[e];break;case"blinkIntervalDuration":if(t=Math.floor(t),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"cursorWidth":t=Math.floor(t);case"lineHeight":case"tabStopWidth":if(t<1)throw new Error(`${e} cannot be less than 1, value: ${t}`);break;case"minimumContrastRatio":t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case"scrollback":if(t=Math.min(t,4294967295),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(t<=0)throw new Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case"rows":case"cols":if(!t&&t!==0)throw new Error(`${e} must be numeric, value: ${t}`);break;case"windowsPty":t=t??{};break}return t}};function ka(e){return e==="block"||e==="underline"||e==="bar"}var js=Object.freeze({insertMode:!1}),Gs=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,colorSchemeUpdates:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,win32InputMode:!1,wraparound:!0}),Js=()=>({flags:0,mainFlags:0,altFlags:0,mainStack:[],altStack:[]}),Fi=class extends L{constructor(e,t,i){super(),this._bufferService=e,this._logService=t,this._optionsService=i,this.isCursorHidden=!1,this._onData=this._register(new y),this.onData=this._onData.event,this._onUserInput=this._register(new y),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new y),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new y),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.isCursorInitialized=i.rawOptions.showCursorImmediately??!1,this.modes=structuredClone(js),this.decPrivateModes=structuredClone(Gs),this.kittyKeyboard=Js()}reset(){this.modes=structuredClone(js),this.decPrivateModes=structuredClone(Gs),this.kittyKeyboard=Js()}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let i=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&i.ybase!==i.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace("sending data (codes)",()=>e.split("").map(s=>s.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace("sending binary (codes)",()=>e.split("").map(t=>t.charCodeAt(0))),this._onBinary.fire(e))}};Fi=F([g(0,ne),g(1,Je),g(2,oe)],Fi);var Zs={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>!(e.action===32&&e.button===3)},ANY:{events:31,restrict:e=>!0}};function ui(e,t){let i=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(i|=64,i|=e.action):(i|=e.button&3,e.button&4&&(i|=64),e.button&8&&(i|=128),e.action===32?i|=32:e.action===0&&!t&&(i|=3)),i}var fi=String.fromCharCode,Qs={DEFAULT:e=>{let t=[ui(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?"":`\x1B[M${fi(t[0])}${fi(t[1])}${fi(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${ui(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${ui(e,!0)};${e.x};${e.y}${t}`}},xa=class extends L{constructor(){super(),this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._onProtocolChange=this._register(new y),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(Zs))this.addProtocol(e,Zs[e]);for(let e of Object.keys(Qs))this.addEncoding(e,Qs[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw new Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw new Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT"}setCustomWheelEventHandler(e){this._customWheelEventHandler=e}allowCustomWheelEvent(e){return this._customWheelEventHandler?this._customWheelEventHandler(e)!==!1:!0}restrictMouseEvent(e){return this._protocols[this._activeProtocol].restrict(e)}encodeMouseEvent(e){return this._encodings[this._activeEncoding](e)}get isDefaultEncoding(){return this._activeEncoding==="DEFAULT"}get isPixelEncoding(){return this._activeEncoding==="SGR_PIXELS"}},Ke=class Rt{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new y,this.onChange=this._onChange.event}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,i,s=!1){return(t&16777215)<<3|(i&3)<<1|(s?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t,this._active||(this.activeVersion=t.version)}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let i=0,s=0,r=t.length;for(let n=0;n=r)return i+this.wcwidth(o);let a=t.charCodeAt(n);56320<=a&&a<=57343?o=(o-55296)*1024+a-56320+65536:i+=this.wcwidth(a)}let h=this.charProperties(o,s),l=Rt.extractWidth(h);Rt.extractShouldJoin(h)&&(l-=Rt.extractWidth(s)),i+=l,s=h}return i}charProperties(t,i){return this._activeProvider.charProperties(t,i)}},pi=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],Ba=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],X;function Ea(e,t){let i=0,s=t.length-1,r;if(et[s][1])return!1;for(;s>=i;)if(r=i+s>>1,e>t[r][1])i=r+1;else if(e=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let i=this.wcwidth(e),s=i===0&&t!==0;if(s){let r=Ke.extractWidth(t);r===0?s=!1:r>i&&(i=r)}return Ke.createPropertyValue(0,i,s)}},Ma=class{constructor(){this.glevel=0,this._charsets=[]}get charsets(){return this._charsets}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function er(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),i=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);i&&t&&(i.isWrapped=t[3]!==0&&t[3]!==32)}var Nr=class Wi{constructor(t=32,i=32){if(this.maxLength=t,this.maxSubParamsLength=i,i>256)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(t),this.length=0,this._subParams=new Int32Array(i),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(t),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let i=new Wi;if(!t.length)return i;for(let s=Array.isArray(t[0])?1:0;s>8,r=this._subParamsIdx[i]&255;r-s>0&&t.push(Array.prototype.slice.call(this._subParams,s,r))}return t}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}resetZdm(){this.length=1,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1,this._subParamsIdx[0]=0,this.params[0]=0}addParam(t){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(t<-1)throw new Error("values less than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=t>2147483647?2147483647:t}addSubParam(t){if(this._digitIsSub=!0,!!this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(t<-1)throw new Error("values less than -1 are not allowed");this._subParams[this._subParamsLength++]=t>2147483647?2147483647:t,this._subParamsIdx[this.length-1]++}}hasSubParams(t){return(this._subParamsIdx[t]&255)-(this._subParamsIdx[t]>>8)>0}getSubParams(t){let i=this._subParamsIdx[t]>>8,s=this._subParamsIdx[t]&255;return s-i>0?this._subParams.subarray(i,s):null}getSubParamsAll(){let t={};for(let i=0;i>8,r=this._subParamsIdx[i]&255;r-s>0&&(t[i]=this._subParams.slice(s,r))}return t}addDigit(t){let i;if(this._rejectDigits||!(i=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let s=this._digitIsSub?this._subParams:this.params,r=s[i-1];s[i-1]=~r?Math.min(r*10+t,2147483647):t}},nt=[],La=class{constructor(){this._state=0,this._active=nt,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]??=[];let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=nt}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=nt,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||nt,!this._active.length)this._handlerFb(this._id,"START");else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,i){if(!this._active.length)this._handlerFb(this._id,"PUT",Ge(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}start(){this.reset(),this._state=1}put(e,t,i){if(this._state!==3){if(this._state===1)for(;t0&&this._put(e,t,i)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,"END",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].end(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].end(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=nt,this._id=-1,this._state=0}}},Hr=class Fr{constructor(t){this._handler=t,this._data=new es(Fr._payloadLimit),this._hitLimit=!1}start(){this._data.reset(),this._hitLimit=!1}put(t,i,s){this._hitLimit||this._data.append(Ge(t,i,s))&&(this._hitLimit=!0)}end(t){let i=!1;if(this._hitLimit)i=!1;else if(t&&(i=this._handler(this._data.toString()),i instanceof Promise))return i.then(s=>(this._data.reset(),this._hitLimit=!1,s));return this._data.reset(),this._hitLimit=!1,i}};Hr._payloadLimit=1e7;var de=Hr,ot=[],Ra=class{constructor(){this._handlers=Object.create(null),this._active=ot,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=ot}registerHandler(e,t){this._handlers[e]??=[];let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=ot,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||ot,!this._active.length)this._handlerFb(this._ident,"HOOK",t);else for(let i=this._active.length-1;i>=0;i--)this._active[i].hook(t)}put(e,t,i){if(!this._active.length)this._handlerFb(this._ident,"PUT",Ge(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"UNHOOK",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].unhook(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].unhook(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=ot,this._ident=0}},dt=new Nr;dt.addParam(0);var Wr=class zr{constructor(t){this._handler=t,this._data=new es(zr._payloadLimit),this._params=dt,this._hitLimit=!1}hook(t){this._params=t.length>1||t.params[0]?t.clone():dt,this._data.reset(),this._hitLimit=!1}put(t,i,s){this._hitLimit||this._data.append(Ge(t,i,s))&&(this._hitLimit=!0)}unhook(t){let i=!1;if(this._hitLimit)i=!1;else if(t&&(i=this._handler(this._data.toString(),this._params),i instanceof Promise))return i.then(s=>(this._params=dt,this._data.reset(),this._hitLimit=!1,s));return this._params=dt,this._data.reset(),this._hitLimit=!1,i}};Wr._payloadLimit=1e7;var tr=Wr,at=[],Ta=class{constructor(){this._handlers=Object.create(null),this._active=at,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]??=[];let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=at}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=at,this._ident=0}start(e){if(this.reset(),this._ident=e,this._active=this._handlers[e]||at,!this._active.length)this._handlerFb(this._ident,"START");else for(let t=this._active.length-1;t>=0;t--)this._active[t].start()}put(e,t,i){if(!this._active.length)this._handlerFb(this._ident,"PUT",Ge(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}end(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"END",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].end(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].end(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=at,this._ident=0}},Kr=class $r{constructor(t){this._handler=t,this._data=new es($r._payloadLimit),this._hitLimit=!1}start(){this._data.reset(),this._hitLimit=!1}put(t,i,s){this._hitLimit||this._data.append(Ge(t,i,s))&&(this._hitLimit=!0)}end(t){let i=!1;if(this._hitLimit)i=!1;else if(t&&(i=this._handler(this._data.toString()),i instanceof Promise))return i.then(s=>(this._data.reset(),this._hitLimit=!1,s));return this._data.reset(),this._hitLimit=!1,i}};Kr._payloadLimit=1e7;var Pa=Kr,Aa=class{constructor(e){this.table=new Uint16Array(e)}setDefault(e,t){this.table.fill(e<<8|t)}add(e,t,i,s){this.table[t<<8|e]=i<<8|s}addMany(e,t,i,s){for(let r=0;rh),i=(o,h)=>t.slice(o,h),s=i(32,127),r=i(0,24);r.push(25),r.push.apply(r,i(28,32));let n=i(0,17);e.setDefault(1,0),e.addMany(s,0,2,0);for(let o of n)e.addMany([24,26,153,154],o,3,0),e.addMany(i(128,144),o,3,0),e.addMany(i(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158],o,0,7),e.add(159,o,11,14),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(r,0,3,0),e.addMany(r,1,3,1),e.add(127,1,0,1),e.addMany(r,8,0,8),e.addMany(r,3,3,3),e.add(127,3,0,3),e.addMany(r,4,3,4),e.add(127,4,0,4),e.addMany(r,6,3,6),e.addMany(r,5,3,5),e.add(127,5,0,5),e.addMany(r,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(s,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(i(28,32),8,0,8),e.addMany([88,94],1,0,7),e.addMany(s,7,0,7),e.addMany(r,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(95,1,11,14),e.addMany(r,14,0,14),e.add(127,14,0,14),e.addMany(i(32,48),14,9,15),e.addMany(i(48,127),14,15,16),e.addMany(i(48,127),15,15,16),e.addMany(r,15,0,15),e.addMany(i(32,48),15,9,15),e.add(127,15,0,15),e.addMany(s,16,16,16),e.addMany(r,16,0,16),e.addMany(i(8,14),16,16,16),e.add(127,16,0,16),e.addMany([27,156,24,26],16,17,0),e.add(91,1,11,3),e.addMany(i(64,127),3,7,0),e.addMany(i(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(i(48,60),4,8,4),e.addMany(i(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(i(32,64),6,0,6),e.add(127,6,0,6),e.addMany(i(64,127),6,0,0),e.addMany(i(32,48),3,9,5),e.addMany(i(32,48),5,9,5),e.addMany(i(48,64),5,0,6),e.addMany(i(64,127),5,7,0),e.addMany(i(32,48),4,9,5),e.addMany(i(32,48),1,9,2),e.addMany(i(32,48),2,9,2),e.addMany(i(48,127),2,10,0),e.addMany(i(48,80),1,10,0),e.addMany(i(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(i(96,127),1,10,0),e.add(80,1,11,9),e.addMany(r,9,0,9),e.add(127,9,0,9),e.addMany(i(32,48),9,9,12),e.addMany(i(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(r,11,0,11),e.addMany(i(32,128),11,0,11),e.addMany(r,10,0,10),e.add(127,10,0,10),e.addMany(i(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(i(32,48),10,9,12),e.addMany(r,12,0,12),e.add(127,12,0,12),e.addMany(i(32,48),12,9,12),e.addMany(i(48,64),12,0,11),e.addMany(i(64,127),12,12,13),e.addMany(i(64,127),10,12,13),e.addMany(i(64,127),9,12,13),e.addMany(r,13,13,13),e.addMany(s,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(re,0,2,0),e.add(re,8,5,8),e.add(re,6,0,6),e.add(re,11,0,11),e.add(re,13,13,13),e.add(re,16,16,16),e})(),Ia=class extends L{constructor(e=Oa){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new Nr,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(t,i,s)=>{},this._executeHandlerFb=t=>{},this._csiHandlerFb=(t,i)=>{},this._escHandlerFb=t=>{},this._errorHandlerFb=t=>t,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._executeHandlersArr=new Array(24).fill(void 0),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(O(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._executeHandlersArr=new Array(24).fill(void 0),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new La),this._dcsParser=this._register(new Ra),this._apcParser=this._register(new Ta),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},()=>!0)}_identifier(e,t=[64,126]){let i=0;if(e.prefix){if(e.prefix.length>1)throw new Error("only one byte as prefix supported");if(i=e.prefix.charCodeAt(0),i<60||i>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(e.intermediates){if(e.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let r=0;rn||n>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");i<<=8,i|=n}}if(e.final.length!==1)throw new Error("final must be a single byte");let s=e.final.charCodeAt(0);if(t[0]>s||s>t[1])throw new Error(`final must be in range ${t[0]} .. ${t[1]}`);return i<<=8,i|=s,i}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join("")}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let i=this._identifier(e,[48,126]);this._escHandlers[i]??=[];let s=this._escHandlers[i];return s.push(t),{dispose:()=>{let r=s.indexOf(t);r!==-1&&s.splice(r,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){let i=e.charCodeAt(0);this._executeHandlers[i]=t,i<24&&(this._executeHandlersArr[i]=t)}clearExecuteHandler(e){let t=e.charCodeAt(0);this._executeHandlers[t]&&delete this._executeHandlers[t],t<24&&(this._executeHandlersArr[t]=void 0)}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let i=this._identifier(e);this._csiHandlers[i]??=[];let s=this._csiHandlers[i];return s.push(t),{dispose:()=>{let r=s.indexOf(t);r!==-1&&s.splice(r,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}registerApcHandler(e,t){return e.prefix=void 0,this._apcParser.registerHandler(this._identifier(e,[48,126]),t)}clearApcHandler(e){e.prefix=void 0,this._apcParser.clearHandler(this._identifier(e,[48,126]))}setApcHandlerFallback(e){this._apcParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._apcParser.reset(),this._params.resetZdm(),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,i,s,r){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=i,this._parseStack.transition=s,this._parseStack.chunkPos=r}parse(e,t,i){let s,r,n=0,o;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,n=this._parseStack.chunkPos+1;else{if(i===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");let h=this._parseStack.handlers,l=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(i===!1&&l>-1){for(;l>=0&&(o=h[l](this._params),o!==!0);l--)if(o instanceof Promise)return this._parseStack.handlerPos=l,o}this._parseStack.handlers=[];break;case 4:if(i===!1&&l>-1){for(;l>=0&&(o=h[l](),o!==!0);l--)if(o instanceof Promise)return this._parseStack.handlerPos=l,o}this._parseStack.handlers=[];break;case 6:if(s=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.resetZdm(),this._collect=0;break;case 5:if(s=e[this._parseStack.chunkPos],o=this._oscParser.end(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.resetZdm(),this._collect=0;break;case 7:if(s=e[this._parseStack.chunkPos],o=this._apcParser.end(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.resetZdm(),this._collect=0;break}this._parseStack.state=0,n=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&255}for(let h=n;h=60&&a<=63&&(this._collect=a,l++);let c=!1;for(;l=48&&a<=57)this._params.addDigit(a-48);else if(a===59)this._params.addParam(0);else if(a===58)this._params.addSubParam(-1);else if(a>=64&&a<=126){let d=this._csiHandlers[this._collect<<8|a],u=d?d.length-1:-1;for(;u>=0&&(o=d[u](this._params),o!==!0);u--)if(o instanceof Promise)return r=1792,this._preserveStack(3,d,u,r,l),o;u<0&&this._csiHandlerFb(this._collect<<8|a,this._params),this.precedingJoinState=0,h=l,this.currentState=0,c=!0;break}else break;c||(h=l-1,this.currentState=4);continue}switch(r=this._transitions.table[this.currentState<<8|(s>8){case 2:let l=h,a=t-4;for(;l=32&&(e[l]<=126||e[l]>=re)&&e[++l]>=32&&(e[l]<=126||e[l]>=re)&&e[++l]>=32&&(e[l]<=126||e[l]>=re)&&e[++l]>=32&&(e[l]<=126||e[l]>=re););if(l>=a)for(;l=32&&(e[l]<=126||e[l]>=re);)l++;this._printHandler(e,h,l),h=l-1;break;case 3:this._executeHandlers[s]?this._executeHandlers[s]():this._executeHandlerFb(s),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:h,code:s,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let c=this._csiHandlers[this._collect<<8|s],d=c?c.length-1:-1;for(;d>=0&&(o=c[d](this._params),o!==!0);d--)if(o instanceof Promise)return this._preserveStack(3,c,d,r,h),o;d<0&&this._csiHandlerFb(this._collect<<8|s,this._params),this.precedingJoinState=0;break;case 8:do switch(s){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(s-48)}while(++h47&&s<60);h--;break;case 9:this._collect<<=8,this._collect|=s;break;case 10:let u=this._escHandlers[this._collect<<8|s],f=u?u.length-1:-1;for(;f>=0&&(o=u[f](),o!==!0);f--)if(o instanceof Promise)return this._preserveStack(4,u,f,r,h),o;f<0&&this._escHandlerFb(this._collect<<8|s),this.precedingJoinState=0;break;case 11:this._params.resetZdm(),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|s,this._params);break;case 13:for(let _=h+1;;++_)if(_>=t||(s=e[_])===24||s===26||s===27||s>127&&s=t||(s=e[_])<32||s>127&&s=32&&e[_]<127||e[_]>=8&&e[_]<14||e[_]>=re))){this._apcParser.put(e,h,_),h=_-1;break}break;case 17:if(o=this._apcParser.end(s!==24&&s!==26),o)return this._preserveStack(7,[],0,r,h),o;s===27&&(r|=1),this._params.resetZdm(),this._collect=0,this.precedingJoinState=0;break}this.currentState=r&255}}},Na=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,Ha=/^[\da-f]+$/;function ir(e){if(!e)return;let t=e.toLowerCase();if(t.startsWith("rgb:")){t=t.slice(4);let i=Na.exec(t);if(i){let s=i[1]?15:i[4]?255:i[7]?4095:65535;return[Math.round(parseInt(i[1]||i[4]||i[7]||i[10],16)/s*255),Math.round(parseInt(i[2]||i[5]||i[8]||i[11],16)/s*255),Math.round(parseInt(i[3]||i[6]||i[9]||i[12],16)/s*255)]}}else if(t.startsWith("#")&&(t=t.slice(1),Ha.exec(t)&&[3,6,9,12].includes(t.length))){let i=t.length/3,s=[0,0,0];for(let r=0;r<3;++r){let n=parseInt(t.slice(i*r,i*r+i),16);s[r]=i===1?n<<4:i===2?n:i===3?n>>4:n>>8}return s}}function gi(e,t){let i=e.toString(16),s=i.length<2?"0"+i:i;switch(t){case 4:return i[0];case 8:return s;case 12:return(s+s).slice(0,3);default:return s+s}}function Fa(e,t=16){let[i,s,r]=e;return`rgb:${gi(i,t)}/${gi(s,t)}/${gi(r,t)}`}var Wa="6.1.0-beta.292",za={"(":0,")":1,"*":2,"+":3,"-":1,".":2};function sr(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var rr=0,Ka=class extends L{constructor(e,t,i,s,r,n,o,h,l=new Ia){super(),this._bufferService=e,this._charsetService=t,this._coreService=i,this._logService=s,this._optionsService=r,this._oscLinkService=n,this._mouseStateService=o,this._unicodeService=h,this._parser=l,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new Un,this._utf8Decoder=new qn,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=j.clone(),this._eraseAttrDataInternal=j.clone(),this._onRequestBell=this._register(new y),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new y),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new y),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new y),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new y),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new y),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new y),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new y),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new y),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new y),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new y),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new y),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new y),this.onColor=this._onColor.event,this._onRequestColorSchemeQuery=this._register(new y),this.onRequestColorSchemeQuery=this._onRequestColorSchemeQuery.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new zi(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(a=>this._activeBuffer=a.activeBuffer)),this._parser.setCsiHandlerFallback((a,c)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(a),params:c.toArray()})}),this._parser.setEscHandlerFallback(a=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(a)})}),this._parser.setExecuteHandlerFallback(a=>{this._logService.debug("Unknown EXECUTE code: ",{code:a})}),this._parser.setOscHandlerFallback((a,c,d)=>{this._logService.debug("Unknown OSC code: ",{identifier:a,action:c,data:d})}),this._parser.setDcsHandlerFallback((a,c,d)=>{c==="HOOK"&&(d=d.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(a),action:c,payload:d})}),this._parser.setApcHandlerFallback((a,c,d)=>{this._logService.debug("Unknown APC code: ",{identifier:this._parser.identToString(a),action:c,payload:d})}),this._parser.setPrintHandler((a,c,d)=>this.print(a,c,d)),this._parser.registerCsiHandler({final:"@"},a=>this.insertChars(a)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},a=>this.scrollLeft(a)),this._parser.registerCsiHandler({final:"A"},a=>this.cursorUp(a)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},a=>this.scrollRight(a)),this._parser.registerCsiHandler({final:"B"},a=>this.cursorDown(a)),this._parser.registerCsiHandler({final:"C"},a=>this.cursorForward(a)),this._parser.registerCsiHandler({final:"D"},a=>this.cursorBackward(a)),this._parser.registerCsiHandler({final:"E"},a=>this.cursorNextLine(a)),this._parser.registerCsiHandler({final:"F"},a=>this.cursorPrecedingLine(a)),this._parser.registerCsiHandler({final:"G"},a=>this.cursorCharAbsolute(a)),this._parser.registerCsiHandler({final:"H"},a=>this.cursorPosition(a)),this._parser.registerCsiHandler({final:"I"},a=>this.cursorForwardTab(a)),this._parser.registerCsiHandler({final:"J"},a=>this.eraseInDisplay(a,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},a=>this.eraseInDisplay(a,!0)),this._parser.registerCsiHandler({final:"K"},a=>this.eraseInLine(a,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},a=>this.eraseInLine(a,!0)),this._parser.registerCsiHandler({final:"L"},a=>this.insertLines(a)),this._parser.registerCsiHandler({final:"M"},a=>this.deleteLines(a)),this._parser.registerCsiHandler({final:"P"},a=>this.deleteChars(a)),this._parser.registerCsiHandler({final:"S"},a=>this.scrollUp(a)),this._parser.registerCsiHandler({final:"T"},a=>this.scrollDown(a)),this._parser.registerCsiHandler({final:"X"},a=>this.eraseChars(a)),this._parser.registerCsiHandler({final:"Z"},a=>this.cursorBackwardTab(a)),this._parser.registerCsiHandler({final:"^"},a=>this.scrollDown(a)),this._parser.registerCsiHandler({final:"`"},a=>this.charPosAbsolute(a)),this._parser.registerCsiHandler({final:"a"},a=>this.hPositionRelative(a)),this._parser.registerCsiHandler({final:"b"},a=>this.repeatPrecedingCharacter(a)),this._parser.registerCsiHandler({final:"c"},a=>this.sendDeviceAttributesPrimary(a)),this._parser.registerCsiHandler({prefix:">",final:"c"},a=>this.sendDeviceAttributesSecondary(a)),this._parser.registerCsiHandler({final:"d"},a=>this.linePosAbsolute(a)),this._parser.registerCsiHandler({final:"e"},a=>this.vPositionRelative(a)),this._parser.registerCsiHandler({final:"f"},a=>this.hVPosition(a)),this._parser.registerCsiHandler({final:"g"},a=>this.tabClear(a)),this._parser.registerCsiHandler({final:"h"},a=>this.setMode(a)),this._parser.registerCsiHandler({prefix:"?",final:"h"},a=>this.setModePrivate(a)),this._parser.registerCsiHandler({final:"l"},a=>this.resetMode(a)),this._parser.registerCsiHandler({prefix:"?",final:"l"},a=>this.resetModePrivate(a)),this._parser.registerCsiHandler({final:"m"},a=>this.charAttributes(a)),this._parser.registerCsiHandler({final:"n"},a=>this.deviceStatus(a)),this._parser.registerCsiHandler({prefix:"?",final:"n"},a=>this.deviceStatusPrivate(a)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},a=>this.softReset(a)),this._parser.registerCsiHandler({prefix:">",final:"q"},a=>this.sendXtVersion(a)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},a=>this.setCursorStyle(a)),this._parser.registerCsiHandler({final:"r"},a=>this.setScrollRegion(a)),this._parser.registerCsiHandler({final:"s"},a=>this.saveCursor(a)),this._parser.registerCsiHandler({final:"t"},a=>this.windowOptions(a)),this._parser.registerCsiHandler({final:"u"},a=>this.restoreCursor(a)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},a=>this.insertColumns(a)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},a=>this.deleteColumns(a)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},a=>this.selectProtected(a)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},a=>this.requestMode(a,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},a=>this.requestMode(a,!1)),this._parser.registerCsiHandler({prefix:"=",final:"u"},a=>this.kittyKeyboardSet(a)),this._parser.registerCsiHandler({prefix:"?",final:"u"},a=>this.kittyKeyboardQuery(a)),this._parser.registerCsiHandler({prefix:">",final:"u"},a=>this.kittyKeyboardPush(a)),this._parser.registerCsiHandler({prefix:"<",final:"u"},a=>this.kittyKeyboardPop(a)),this._parser.setExecuteHandler("\x07",()=>this.bell()),this._parser.setExecuteHandler(` -`,()=>this.lineFeed()),this._parser.setExecuteHandler("\v",()=>this.lineFeed()),this._parser.setExecuteHandler("\f",()=>this.lineFeed()),this._parser.setExecuteHandler("\r",()=>this.carriageReturn()),this._parser.setExecuteHandler("\b",()=>this.backspace()),this._parser.setExecuteHandler(" ",()=>this.tab()),this._parser.setExecuteHandler("",()=>this.shiftOut()),this._parser.setExecuteHandler("",()=>this.shiftIn()),this._parser.setExecuteHandler("\x84",()=>this.index()),this._parser.setExecuteHandler("\x85",()=>this.nextLine()),this._parser.setExecuteHandler("\x88",()=>this.tabSet()),this._parser.registerOscHandler(0,new de(a=>(this.setTitle(a),this.setIconName(a),!0))),this._parser.registerOscHandler(1,new de(a=>this.setIconName(a))),this._parser.registerOscHandler(2,new de(a=>this.setTitle(a))),this._parser.registerOscHandler(4,new de(a=>this.setOrReportIndexedColor(a))),this._parser.registerOscHandler(8,new de(a=>this.setHyperlink(a))),this._parser.registerOscHandler(10,new de(a=>this.setOrReportFgColor(a))),this._parser.registerOscHandler(11,new de(a=>this.setOrReportBgColor(a))),this._parser.registerOscHandler(12,new de(a=>this.setOrReportCursorColor(a))),this._parser.registerOscHandler(104,new de(a=>this.restoreIndexedColor(a))),this._parser.registerOscHandler(110,new de(a=>this.restoreFgColor(a))),this._parser.registerOscHandler(111,new de(a=>this.restoreBgColor(a))),this._parser.registerOscHandler(112,new de(a=>this.restoreCursorColor(a))),this._parser.registerEscHandler({final:"7"},()=>this.saveCursor()),this._parser.registerEscHandler({final:"8"},()=>this.restoreCursor()),this._parser.registerEscHandler({final:"D"},()=>this.index()),this._parser.registerEscHandler({final:"E"},()=>this.nextLine()),this._parser.registerEscHandler({final:"H"},()=>this.tabSet()),this._parser.registerEscHandler({final:"M"},()=>this.reverseIndex()),this._parser.registerEscHandler({final:"="},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:">"},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:"c"},()=>this.fullReset()),this._parser.registerEscHandler({final:"n"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"o"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"|"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"}"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"~"},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:"%",final:"@"},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:"%",final:"G"},()=>this.selectDefaultCharset());for(let a in G)this._parser.registerEscHandler({intermediates:"(",final:a},()=>this.selectCharset("("+a)),this._parser.registerEscHandler({intermediates:")",final:a},()=>this.selectCharset(")"+a)),this._parser.registerEscHandler({intermediates:"*",final:a},()=>this.selectCharset("*"+a)),this._parser.registerEscHandler({intermediates:"+",final:a},()=>this.selectCharset("+"+a)),this._parser.registerEscHandler({intermediates:"-",final:a},()=>this.selectCharset("-"+a)),this._parser.registerEscHandler({intermediates:".",final:a},()=>this.selectCharset("."+a)),this._parser.registerEscHandler({intermediates:"/",final:a},()=>this.selectCharset("/"+a));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(a=>(this._logService.error("Parsing error: ",a),a)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new tr((a,c)=>this.requestStatusString(a,c)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,i,s){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=i,this._parseStack.position=s}_logSlowResolvingAsync(e){if(this._logService.logLevel<=3){let t,i=new Promise((s,r)=>{t=setTimeout(()=>r("#SLOW_TIMEOUT"),5e3)});Promise.race([e,i]).then(()=>{t!==void 0&&clearTimeout(t)},s=>{if(t!==void 0&&clearTimeout(t),s!=="#SLOW_TIMEOUT")throw s;console.warn("async parser handler taking longer than 5000 ms")})}}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let i,s=this._activeBuffer.x,r=this._activeBuffer.y,n=0,o=this._parseStack.paused;if(o){if(i=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(i),i;s=this._parseStack.cursorStartX,r=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>131072&&(n=this._parseStack.position+131072)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e=="string"?` "${e}"`:` "${Array.prototype.map.call(e,a=>String.fromCharCode(a)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof e=="string"?e.split("").map(a=>a.charCodeAt(0)):e),this._parseBuffer.length131072)for(let a=n;a0&&d.getWidth(this._activeBuffer.x-1)===2&&d.setCellFromCodepoint(this._activeBuffer.x-1,0,1,c);let u=this._parser.precedingJoinState;for(let f=t;fh){if(l){let R=d,E=this._activeBuffer.x-S;if(this._activeBuffer.x=S,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),!d)return;for(S>0&&d instanceof ct&&d.copyCellsFrom(R,E,0,S,!1);E=0;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,c);continue}if(a&&(d.insertCells(this._activeBuffer.x,r-S,this._activeBuffer.getNullCell(c)),d.getWidth(h-1)===2&&d.setCellFromCodepoint(h-1,0,1,c)),d.setCellFromCodepoint(this._activeBuffer.x++,s,r,c),r>0)for(;--r;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,c)}this._parser.precedingJoinState=u,this._activeBuffer.x0&&d.getWidth(this._activeBuffer.x)===0&&!d.hasContent(this._activeBuffer.x)&&d.setCellFromCodepoint(this._activeBuffer.x,0,1,c),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final==="t"&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,i=>sr(i.params[0],this._optionsService.rawOptions.windowOptions)?t(i):!0):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new tr(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new de(t))}registerApcHandler(e,t){return this._parser.registerApcHandler(e,new Pa(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,i,s=!1,r=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.replaceCells(t,i,this._activeBuffer.getNullCell(this._eraseAttrData()),r),s&&(n.isWrapped=!1))}_resetBufferLine(e,t=!1){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);i&&(i.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),i.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let i;switch(e.params[0]){case 0:for(i=this._activeBuffer.y,this._dirtyRowTracker.markDirty(i),this._eraseInBufferLine(i++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);i=this._bufferService.cols){let r=this._activeBuffer.lines.get(i+1);r&&(r.isWrapped=!1)}for(;i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(i=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,i-1);i--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+i)?.getTrimmedLength(););for(;i>=0;i--)this._bufferService.scroll(this._eraseAttrData())}else{for(i=this._bufferService.rows,this._dirtyRowTracker.markDirty(i-1);i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let s=this._activeBuffer.lines.length-this._bufferService.rows;s>0&&(this._activeBuffer.lines.trimStart(s),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-s,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-s,0),this._onScroll.fire(0));break}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.y65535?2:1}let l=h;for(let a=1;a0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent("\x1B[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent("\x1B[?6c")),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent("\x1B[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent("\x1B[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(e.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent("\x1B[>83;40003;0c")),!0}sendXtVersion(e){return e.params[0]>0||this._coreService.triggerDataEvent(`\x1BP>|xterm.js(${Wa})\x1B\\`),!0}_is(e){return(this._optionsService.rawOptions.termName+"").startsWith(e)}setMode(e){for(let t=0;t(p[p.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",p[p.SET=1]="SET",p[p.RESET=2]="RESET",p[p.PERMANENTLY_SET=3]="PERMANENTLY_SET",p[p.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(i||={});let s=this._coreService.decPrivateModes,{activeProtocol:r,activeEncoding:n}=this._mouseStateService,o=this._coreService,{buffers:h,cols:l}=this._bufferService,{active:a,alt:c}=h,d=this._optionsService.rawOptions,u=(p,S)=>(o.triggerDataEvent(`\x1B[${t?"":"?"}${p};${S}$y`),!0),f=p=>p?1:2,_=e.params[0];return t?_===2?u(_,4):_===4?u(_,f(o.modes.insertMode)):_===12?u(_,3):_===20?u(_,f(d.convertEol)):u(_,0):_===1?u(_,f(s.applicationCursorKeys)):_===3?u(_,d.windowOptions.setWinLines?l===80?2:l===132?1:0:0):_===6?u(_,f(s.origin)):_===7?u(_,f(s.wraparound)):_===8?u(_,3):_===9?u(_,f(r==="X10")):_===12?u(_,f(d.cursorBlink)):_===25?u(_,f(!o.isCursorHidden)):_===45?u(_,f(s.reverseWraparound)):_===66?u(_,f(s.applicationKeypad)):_===67?u(_,4):_===1e3?u(_,f(r==="VT200")):_===1002?u(_,f(r==="DRAG")):_===1003?u(_,f(r==="ANY")):_===1004?u(_,f(s.sendFocus)):_===1005?u(_,4):_===1006?u(_,f(n==="SGR")):_===1015?u(_,4):_===1016?u(_,f(n==="SGR_PIXELS")):_===1048?u(_,1):_===47||_===1047||_===1049?u(_,f(a===c)):_===2004?u(_,f(s.bracketedPasteMode)):_===2026?u(_,f(s.synchronizedOutput)):_===9001&&this._optionsService.rawOptions.vtExtensions?.win32InputMode?u(_,f(s.win32InputMode)):u(_,0)}_updateAttrColor(e,t,i,s,r){return t===2?(e|=50331648,e&=-16777216,e|=vt.fromColorRGB([i,s,r])):t===5&&(e&=-67108864,e|=33554432|i&255),e}_extractColor(e,t,i){let s=[0,0,-1,0,0,0],r=0,n=0;do{if(s[n+r]=e.params[t+n],e.hasSubParams(t+n)){let o=e.getSubParams(t+n),h=0;do s[1]===5&&(r=1),s[n+h+1+r]=o[h];while(++h=2||s[1]===2&&n+r>=5)break;s[1]&&(r=1)}while(++n+t5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=j.fg,e.bg=j.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,i,s=this._curAttrData;for(let r=0;r=30&&i<=37?(s.fg&=-67108864,s.fg|=16777216|i-30):i>=40&&i<=47?(s.bg&=-67108864,s.bg|=16777216|i-40):i>=90&&i<=97?(s.fg&=-67108864,s.fg|=16777216|i-90|8):i>=100&&i<=107?(s.bg&=-67108864,s.bg|=16777216|i-100|8):i===0?this._processSGR0(s):i===1?s.fg|=134217728:i===3?s.bg|=67108864:i===4?(s.fg|=268435456,this._processUnderline(e.hasSubParams(r)?e.getSubParams(r)[0]:1,s)):i===5?s.fg|=536870912:i===7?s.fg|=67108864:i===8?s.fg|=1073741824:i===9?s.fg|=2147483648:i===2?s.bg|=134217728:i===21?this._processUnderline(2,s):i===22?(s.fg&=-134217729,s.bg&=-134217729):i===23?s.bg&=-67108865:i===24?(s.fg&=-268435457,this._processUnderline(0,s)):i===25?s.fg&=-536870913:i===27?s.fg&=-67108865:i===28?s.fg&=-1073741825:i===29?s.fg&=2147483647:i===39?(s.fg&=-67108864,s.fg|=j.fg&16777215):i===49?(s.bg&=-67108864,s.bg|=j.bg&16777215):i===38||i===48||i===58?r+=this._extractColor(e,r,s):i===53?s.bg|=1073741824:i===55?s.bg&=-1073741825:i===221&&(this._optionsService.rawOptions.vtExtensions?.kittySgrBoldFaintControl??!0)?s.fg&=-134217729:i===222&&(this._optionsService.rawOptions.vtExtensions?.kittySgrBoldFaintControl??!0)?s.bg&=-134217729:i===59?(s.extended=s.extended.clone(),s.extended.underlineColor=-1,s.updateExtended()):this._logService.debug("Unknown SGR attribute: %d.",i);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent("\x1B[0n");break;case 6:let t=this._activeBuffer.y+1,i=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`\x1B[${t};${i}R`);break}return!0}deviceStatusPrivate(e){switch(e.params[0]){case 6:let t=this._activeBuffer.y+1,i=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`\x1B[?${t};${i}R`);break;case 15:break;case 25:break;case 26:break;case 53:break;case 996:(this._optionsService.rawOptions.vtExtensions?.colorSchemeQuery??!0)&&this._onRequestColorSchemeQuery.fire();break}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=j.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle="block";break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle="underline";break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle="bar";break}let i=t%2===1;this._coreService.decPrivateModes.cursorBlink=i}return!0}setScrollRegion(e){let t=e.params[0]||1,i;return(e.length<2||(i=e.params[1])>this._bufferService.rows||i===0)&&(i=this._bufferService.rows),i>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=i-1,this._setCursor(0,0)),!0}windowOptions(e){if(!sr(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`\x1B[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>10&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>10&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._activeBuffer.savedCharsets=this._charsetService.charsets.slice(),this._activeBuffer.savedGlevel=this._charsetService.glevel,this._activeBuffer.savedOriginMode=this._coreService.decPrivateModes.origin,this._activeBuffer.savedWraparoundMode=this._coreService.decPrivateModes.wraparound,!0}restoreCursor(e){this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg;for(let t=0;t1;){let s=i.shift(),r=i.shift();if(/^\d+$/.exec(s)){let n=parseInt(s,10);if(nr(n))if(r==="?")t.push({type:0,index:n});else{let o=ir(r);o&&t.push({type:1,index:n,color:o})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(";");if(t===-1)return!0;let i=e.slice(0,t).trim(),s=e.slice(t+1);return s?this._createHyperlink(i,s):i.trim()?!1:this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let i=e.split(":"),s,r=i.findIndex(n=>n.startsWith("id="));return r!==-1&&(s=i[r].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:s,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let i=e.split(";");for(let s=0;s=this._specialColors.length);++s,++t)if(i[s]==="?")this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=ir(i[s]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],i=e.split(";");for(let s=0;s=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=j.clone(),this._eraseAttrDataInternal=j.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new ge;e.content=1<<22|69,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t(this._coreService.triggerDataEvent(`\x1B${o}\x1B\\`),!0),s=this._bufferService.buffer,r=this._optionsService.rawOptions;return i(e==='"q'?`P1$r${this._curAttrData.isProtected()?1:0}"q`:e==='"p'?'P1$r61;1"p':e==="r"?`P1$r${s.scrollTop+1};${s.scrollBottom+1}r`:e==="m"?"P1$r0m":e===" q"?`P1$r${{block:2,underline:4,bar:6}[r.cursorStyle]-(r.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}kittyKeyboardSet(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=e.params[0]||0,i=e.length>1&&e.params[1]||1,s=this._coreService.kittyKeyboard;switch(i){case 1:s.flags=t;break;case 2:s.flags|=t;break;case 3:s.flags&=~t;break}return!0}kittyKeyboardQuery(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=this._coreService.kittyKeyboard.flags;return this._coreService.triggerDataEvent(`\x1B[?${t}u`),!0}kittyKeyboardPush(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=e.params[0]||0,i=this._coreService.kittyKeyboard,s=this._bufferService.buffer===this._bufferService.buffers.alt?i.altStack:i.mainStack;return s.length>=16&&s.shift(),s.push(i.flags),i.flags=t,!0}kittyKeyboardPop(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=Math.max(1,e.params[0]||1),i=this._coreService.kittyKeyboard,s=this._bufferService.buffer===this._bufferService.buffers.alt?i.altStack:i.mainStack;for(let r=0;r0;r++)i.flags=s.pop();return s.length===0&&t>0&&(i.flags=0),!0}},zi=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){ethis.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(rr=e,e=t,t=rr),ethis.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};zi=F([g(0,ne)],zi);function nr(e){return 0<=e&&e<256}var $a=class extends L{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._innerWriteTimer=this._register(new Kt),this._onWriteParsed=this._register(new y),this.onWriteParsed=this._onWriteParsed.event,this._register(O(()=>{this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0}))}handleUserInput(){this._didUserInput=!0}flushSync(){if(this._store.isDisposed||this._isSyncWriting)return;this._isSyncWriting=!0;let e,t=!1;for(;e=this._writeBuffer.shift();){t=!0,this._action(e);let i=this._callbacks.shift();i&&i()}this._pendingData=0,this._bufferOffset=2147483647,this._writeBuffer.length=0,this._callbacks.length=0,this._isSyncWriting=!1,t&&this._onWriteParsed.fire()}writeSync(e,t){if(this._store.isDisposed)return;if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let i;for(;i=this._writeBuffer.shift();){this._action(i);let s=this._callbacks.shift();s&&s()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(!this._store.isDisposed){if(this._pendingData>5e7)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}this._scheduleInnerWrite()}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}}_scheduleInnerWrite(e=0,t=!0){this._store.isDisposed||this._innerWriteTimer.cancelAndSet(()=>this._innerWrite(e,t),0)}_innerWrite(e=0,t=!0){if(this._store.isDisposed)return;let i=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let s=this._writeBuffer[this._bufferOffset],r=this._action(s,t);if(r){let o=h=>{this._store.isDisposed||(performance.now()-i>=12?this._scheduleInnerWrite(0,h):this._innerWrite(i,h))};r.catch(h=>(queueMicrotask(()=>{throw h}),Promise.resolve(!1))).then(o);return}let n=this._callbacks[this._bufferOffset];if(n&&n(),this._bufferOffset++,this._pendingData-=s.length,performance.now()-i>=12)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>50&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),this._scheduleInnerWrite()):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},Ki=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let h=t.addMarker(t.ybase+t.y),l={data:e,id:this._nextId++,lines:[h]};return h.onDispose(()=>this._removeMarkerFromLink(l,h)),this._dataByLinkId.set(l.id,l),l.id}let i=e,s=this._getEntryIdKey(i),r=this._entriesWithId.get(s);if(r)return this.addLineToLink(r.id,t.ybase+t.y),r.id;let n=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(i),data:i,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(o,n)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let i=this._dataByLinkId.get(e);if(i&&i.lines.every(s=>s.line!==t)){let s=this._bufferService.buffer.addMarker(t);i.lines.push(s),s.onDispose(()=>this._removeMarkerFromLink(i,s))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let i=e.lines.indexOf(t);i!==-1&&(e.lines.splice(i,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};Ki=F([g(0,ne)],Ki);var or=!1,Ua=class extends L{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new le),this._onBinary=this._register(new y),this.onBinary=this._onBinary.event,this._onData=this._register(new y),this.onData=this._onData.event,this._onLineFeed=this._register(new y),this.onLineFeed=this._onLineFeed.event,this._onRender=this._register(new y),this.onRender=this._onRender.event,this._onResize=this._register(new y),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new y),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new y),this._instantiationService=new _a,this.optionsService=this._register(new Ca(e)),this._instantiationService.setService(oe,this.optionsService),this._logService=this._register(this._instantiationService.createInstance(Ni)),this._instantiationService.setService(Je,this._logService),this._bufferService=this._register(this._instantiationService.createInstance(Hi)),this._instantiationService.setService(ne,this._bufferService),this.coreService=this._register(this._instantiationService.createInstance(Fi)),this._instantiationService.setService(Ee,this.coreService),this.mouseStateService=this._register(this._instantiationService.createInstance(xa)),this._instantiationService.setService(Ft,this.mouseStateService),this.unicodeService=this._register(this._instantiationService.createInstance(Ke)),this.unicodeService.register(new Da),this._instantiationService.setService(jn,this.unicodeService),this._charsetService=this._instantiationService.createInstance(Ma),this._instantiationService.setService(Xn,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(Ki),this._instantiationService.setService(pr,this._oscLinkService),this._inputHandler=this._register(new Ka(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.mouseStateService,this.unicodeService)),this._register(he.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(he.forward(this._bufferService.onResize,this._onResize)),this._register(he.forward(this.coreService.onData,this._onData)),this._register(he.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange(["windowsPty"],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new $a((t,i)=>this._inputHandler.parse(t,i))),this._register(he.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new y),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!or&&(this._logService.warn("writeSync is unreliable and will be removed soon."),or=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,2),t=Math.max(t,1),this._writeBuffer.flushSync(),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}registerApcHandler(e,t){return this._inputHandler.registerApcHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.mouseStateService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.backend!==void 0&&t.buildNumber!==void 0&&(e=t.backend==="conpty"&&t.buildNumber<21376),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(er.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:"H"},()=>(er(this._bufferService),!1))),this._windowsWrappingHeuristics.value=O(()=>{for(let t of e)t.dispose()})}}},K=0,qa=class{constructor(e,t){this._getKey=e,this._array=[],this._insertedValues=[],this._isFlushingInserted=!1,this._deletedIndices=[],this._isFlushingDeleted=!1,this._flushInsertedTask=new Nt(t),this._flushDeletedTask=new Nt(t)}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((r,n)=>this._getKey(r)-this._getKey(n)),t=0,i=0,s=new Array(this._array.length+this._insertedValues.length);for(let r=0;r=this._array.length||this._getKey(e[t])<=this._getKey(this._array[i])?(s[r]=e[t],t++):s[r]=this._array[i++];this._array=s,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(K=this._search(t),K===-1)||this._getKey(this._array[K])!==t)return!1;do if(this._array[K]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(K),!0;while(++Kr-n),t=0,i=new Array(this._array.length-e.length),s=0;for(let r=0;r0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(K=this._search(e),!(K<0||K>=this._array.length)&&this._getKey(this._array[K])===e))do yield this._array[K];while(++K=this._array.length)&&this._getKey(this._array[K])===e))do t(this._array[K]);while(++K=t;){let s=t+i>>1,r=this._getKey(this._array[s]);if(r>e)i=s-1;else if(r0&&this._getKey(this._array[s-1])===e;)s--;return s}}return t}},je=0,Mt=0,$i=class extends L{constructor(e,t){super(),this._logService=e,this._bufferService=t,this._lineCache=this._register(new Va),this._onDecorationRegistered=this._register(new y),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new y),this.onDecorationRemoved=this._onDecorationRemoved.event,this._decorations=new qa(i=>i?.marker.line,this._logService),this._register(O(()=>this.reset())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._lineCache.attachToBufferLines(this._bufferService.buffer.lines)})),this._lineCache.attachToBufferLines(this._bufferService.buffer.lines)}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new Ya(e);if(t){let i=t.marker.onDispose(()=>t.dispose()),s=t.onDispose(()=>{s.dispose(),t&&(this._decorations.delete(t)&&(this._lineCache.remove(t),this._onDecorationRemoved.fire(t)),i.dispose())});this._decorations.insert(t),this._lineCache.add(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear(),this._lineCache.clear()}*getDecorationsAtCell(e,t,i){let s=this._lineCache.getDecorationsOnLine(t);if(s)for(let r of s)je=r.options.x??0,Mt=je+(r.options.width??1),e>=je&&e=je&&ethis._handleBufferLinesTrim(i))),t.add(e.onInsert(i=>this._handleBufferLinesInsert(i))),t.add(e.onDelete(i=>this._handleBufferLinesDelete(i)))}_getDecorationHeight(e){return e.options.height??1}_addToLineBuckets(e){let t=e.marker.line;if(t<0)return;e._indexedStartLine=t;let i=this._getDecorationHeight(e);for(let s=t;s=0&&this._addToLineBuckets(e)}_scheduleLineIndexSync(e){this._lineIndexSyncCallbacks.push(e),this._lineIndexSyncTimer.set(()=>{let t=this._lineIndexSyncCallbacks;this._lineIndexSyncCallbacks=[];for(let i of t)i()})}_handleBufferLinesTrim(e){if(e<=0)return;let t=new Map;for(let[i,s]of this._decorationsByLine){let r=i-e;r<0||this._mergeLineBucket(t,r,s)}this._decorationsByLine.clear();for(let[i,s]of t)this._decorationsByLine.set(i,s);for(let i of this._decorations)i.marker.isDisposed||(i._indexedStartLine-=e)}_handleBufferLinesInsert(e){this._scheduleLineIndexSync(()=>this._applyBufferLinesInsert(e))}_handleBufferLinesDelete(e){this._scheduleLineIndexSync(()=>this._applyBufferLinesDelete(e))}_mergeLineBucket(e,t,i){let s=e.get(t);if(s)for(let r=0,n=i.length;rt&&(s.push(n),this._removeFromLineBuckets(n))}let r=new Map;for(let[n,o]of this._decorationsByLine){let h=n>=t?n+i:n;this._mergeLineBucket(r,h,o)}this._decorationsByLine.clear();for(let[n,o]of r)this._decorationsByLine.set(n,o);for(let n of this._decorations)n.marker.isDisposed||n._indexedStartLine>=t&&(n._indexedStartLine=n.marker.line);for(let n of s)this._addToLineBuckets(n)}_applyBufferLinesDelete(e){let t=e.index+e.amount,i=new Map;for(let[r,n]of this._decorationsByLine){if(r>=e.index&&r=t?r-e.amount:r;this._mergeLineBucket(i,o,n)}this._decorationsByLine.clear();for(let[r,n]of i)this._decorationsByLine.set(r,n);let s=[];for(let r of this._decorations){if(r.marker.isDisposed)continue;let n=r._indexedStartLine,o=this._getDecorationHeight(r);n>=t?r._indexedStartLine=r.marker.line:nt&&s.push(r)}for(let r of s)this._reindexDecoration(r)}},Ya=class extends Qe{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new y),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new y),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this._indexedStartLine=e.marker.line,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=W.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=W.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},Xa=1e3,ja=class{constructor(e,t=Xa){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&(clearTimeout(this._refreshTimeoutID),this._refreshTimeoutID=void 0),this._additionalRefreshRequested=!1}refresh(e,t,i){this._rowCount=i,e=e??0,t=t??this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t;let s=performance.now();if(s-this._lastRefreshMs>=this._debounceThresholdMS)this._refreshTimeoutID!==void 0&&(clearTimeout(this._refreshTimeoutID),this._refreshTimeoutID=void 0,this._additionalRefreshRequested=!1),this._lastRefreshMs=s,this._innerRefresh();else if(!this._additionalRefreshRequested){let r=s-this._lastRefreshMs,n=this._debounceThresholdMS-r;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},n)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},ar=!1,Ht=class extends L{constructor(e,t,i,s){super(),this._terminal=e,this._coreBrowserService=i,this._renderService=s,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="";let r=this._coreBrowserService.mainDocument;this._accessibilityContainer=r.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=r.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let n=0;nthis._handleBoundaryFocus(n,0),this._bottomBoundaryFocusListener=n=>this._handleBoundaryFocus(n,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=r.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new ja(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");ar?(this._accessibilityContainer.classList.add("debug"),this._rowContainer.classList.add("debug"),this._debugRootContainer=r.createElement("div"),this._debugRootContainer.classList.add("xterm"),this._debugRootContainer.appendChild(r.createTextNode("------start a11y------")),this._debugRootContainer.appendChild(this._accessibilityContainer),this._debugRootContainer.appendChild(r.createTextNode("------end a11y------")),this._terminal.element.insertAdjacentElement("afterend",this._debugRootContainer)):this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this._register(this._terminal.onResize(n=>this._handleResize(n.rows))),this._register(this._terminal.onRender(n=>this._refreshRows(n.start,n.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(n=>this._handleChar(n))),this._register(this._terminal.onLineFeed(()=>this._handleChar(` +`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),Ji&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!i||!s||!t?!1:this._areCoordsInSelection(t,i,s)}isCellInSelection(e,t){let i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!i||!s?!1:this._areCoordsInSelection([e,t],i,s)}_areCoordsInSelection(e,t,i){return e[1]>t[1]&&e[1]=t[0]&&e[0]=t[0]}_selectWordAtCursor(e,t){let i=this._linkifier.currentLink?.link?.range;if(i)return this._model.selectionStart=[i.start.x-1,i.start.y-1],this._model.selectionStartLength=Fs(i,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let s=this._getMouseBufferCoords(e);return s?(this._selectWordAt(s,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseCoordsService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=Qi(this._coreBrowserService.window,e,this._screenElement)[1],i=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=i?0:(t>i&&(t-=i),t=Math.min(Math.max(t,-50),50),t/=50,t/Math.abs(t)+Math.round(t*14))}shouldForceSelection(e){return this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive?!e.altKey:fe?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0&&!(this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive&&e.altKey)){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),50)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){let t=this.hasSelection;if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0,t&&this._fireOnSelectionChange(this._model.finalSelectionStart,this._model.finalSelectionEnd,!1);let i=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);i&&i.length!==this._model.selectionStart[0]&&i.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return this._optionsService.rawOptions.mouseEventsRequireAlt&&this._mouseStateService.areMouseEventsActive?!1:e.altKey&&!(fe&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let i=this._bufferService.buffer;if(this._model.selectionEnd[1]0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows-1,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<500&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let i=this._mouseCoordsService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(i&&i[0]!==void 0&&i[1]!==void 0){let s=Jo(i[0]-1,i[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(s,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,i=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);if(!i){this._oldHasSelection&&this._fireOnSelectionChange(e,t,i);return}!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,i)}_fireOnSelectionChange(e,t,i){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=i,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.value=e.activeBuffer.lines.onTrim(t=>this._handleTrim(t))}_convertViewportColToCharacterIndex(e,t){let i=t;for(let s=0;t>=s;s++){let r=e.loadCell(s,this._workCell).getChars().length;this._workCell.getWidth()===0?i--:r>1&&t!==s&&(i+=r-1)}return i}setSelection(e,t,i){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=i,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,i=!0,s=!0){if(e[0]>=this._bufferService.cols)return;let r=this._bufferService.buffer,n=r.lines.get(e[1]);if(!n)return;let o=r.translateBufferLineToString(e[1],!1),h=this._convertViewportColToCharacterIndex(n,e[0]),l=h,a=e[0]-h,c=0,d=0,u=0,f=0;if(o.charAt(h)===" "){for(;h>0&&o.charAt(h-1)===" ";)h--;for(;l1&&(f+=R-1,l+=R-1);S>0&&h>0&&!this._isCharWordSeparator(n.loadCell(S-1,this._workCell));){n.loadCell(S-1,this._workCell);let E=this._workCell.getChars().length;this._workCell.getWidth()===0?(c++,S--):E>1&&(u+=E-1,h-=E-1),h--,S--}for(;k1&&(f+=E-1,l+=E-1),l++,k++}}l++;let _=h+a-c+u,p=Math.min(this._bufferService.cols,l-h+c+d-u-f);if(!(!t&&o.slice(h,l).trim()==="")){if(i&&_===0&&n.getCodePoint(0)!==32){let S=r.lines.get(e[1]-1);if(S&&n.isWrapped&&S.getCodePoint(this._bufferService.cols-1)!==32){let k=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(k){let R=this._bufferService.cols-k.start;_-=R,p+=R}}}if(s&&_+p===this._bufferService.cols&&n.getCodePoint(this._bufferService.cols-1)!==32){let S=r.lines.get(e[1]+1);if(S?.isWrapped&&S.getCodePoint(0)!==32){let k=this._getWordAt([0,e[1]+1],!1,!1,!0);k&&(p+=k.length)}}return{start:_,length:p}}}_selectWordAt(e,t){let i=this._getWordAt(e,t);if(i){for(;i.start<0;)i.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[i.start,e[1]],this._model.selectionStartLength=i.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let i=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,i--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,i++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,i]}}_isCharWordSeparator(e){return e.getWidth()===0?!1:this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),i={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=Fs(i,this._bufferService.cols)}};Ai=F([g(3,ne),g(4,De),g(5,zt),g(6,oe),g(7,Ft),g(8,ye),g(9,be)],Ai);var Ws=class{constructor(){this._data={}}set(e,t,i){this._data[e]||(this._data[e]={}),this._data[e][t]=i}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},zs=class{constructor(){this._color=new Ws,this._css=new Ws}setCss(e,t,i){this._css.set(e,t,i)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,i){this._color.set(e,t,i)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},Y=Object.freeze((()=>{let e=[W.toColor("#2e3436"),W.toColor("#cc0000"),W.toColor("#4e9a06"),W.toColor("#c4a000"),W.toColor("#3465a4"),W.toColor("#75507b"),W.toColor("#06989a"),W.toColor("#d3d7cf"),W.toColor("#555753"),W.toColor("#ef2929"),W.toColor("#8ae234"),W.toColor("#fce94f"),W.toColor("#729fcf"),W.toColor("#ad7fa8"),W.toColor("#34e2e2"),W.toColor("#eeeeec")],t=[0,95,135,175,215,255];for(let i=0;i<216;i++){let s=t[i/36%6|0],r=t[i/6%6|0],n=t[i%6];e.push({css:$.toCss(s,r,n),rgba:$.toRgba(s,r,n)})}for(let i=0;i<24;i++){let s=8+i*10;e.push({css:$.toCss(s,s,s),rgba:$.toRgba(s,s,s)})}return e})()),We=W.toColor("#ffffff"),lt=W.toColor("#000000"),Ks=W.toColor("#ffffff"),$s=lt,rt={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},aa=We,Oi=class extends L{constructor(e){super(),this._optionsService=e,this._contrastCache=new zs,this._halfContrastCache=new zs,this._onChangeColors=this._register(new y),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:We,background:lt,cursor:Ks,cursorAccent:$s,selectionForeground:void 0,selectionBackgroundTransparent:rt,selectionBackgroundOpaque:H.blend(lt,rt),selectionInactiveBackgroundTransparent:rt,selectionInactiveBackgroundOpaque:H.blend(lt,rt),scrollbarSliderBackground:H.opacity(We,.2),scrollbarSliderHoverBackground:H.opacity(We,.4),scrollbarSliderActiveBackground:H.opacity(We,.5),overviewRulerBorder:We,ansi:Y.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange("theme",()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=N(e.foreground,We),t.background=N(e.background,lt),t.cursor=H.blend(t.background,N(e.cursor,Ks)),t.cursorAccent=H.blend(t.background,N(e.cursorAccent,$s)),t.selectionBackgroundTransparent=N(e.selectionBackground,rt),t.selectionBackgroundOpaque=H.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=N(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=H.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?N(e.selectionForeground,Os):void 0,t.selectionForeground===Os&&(t.selectionForeground=void 0),H.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=H.opacity(t.selectionBackgroundTransparent,.3)),H.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=H.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=N(e.scrollbarSliderBackground,H.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=N(e.scrollbarSliderHoverBackground,H.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=N(e.scrollbarSliderActiveBackground,H.opacity(t.foreground,.5)),t.overviewRulerBorder=N(e.overviewRulerBorder,aa),t.ansi=Y.slice(),t.ansi[0]=N(e.black,Y[0]),t.ansi[1]=N(e.red,Y[1]),t.ansi[2]=N(e.green,Y[2]),t.ansi[3]=N(e.yellow,Y[3]),t.ansi[4]=N(e.blue,Y[4]),t.ansi[5]=N(e.magenta,Y[5]),t.ansi[6]=N(e.cyan,Y[6]),t.ansi[7]=N(e.white,Y[7]),t.ansi[8]=N(e.brightBlack,Y[8]),t.ansi[9]=N(e.brightRed,Y[9]),t.ansi[10]=N(e.brightGreen,Y[10]),t.ansi[11]=N(e.brightYellow,Y[11]),t.ansi[12]=N(e.brightBlue,Y[12]),t.ansi[13]=N(e.brightMagenta,Y[13]),t.ansi[14]=N(e.brightCyan,Y[14]),t.ansi[15]=N(e.brightWhite,Y[15]),e.extendedAnsi){let i=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let s=0;s"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"']};function la(e,t,i,s){let r={type:0,cancel:!1,key:void 0},n=(e.shiftKey?1:0)|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key==="UIKeyInputUpArrow"?t?r.key="\x1BOA":r.key="\x1B[A":e.key==="UIKeyInputLeftArrow"?t?r.key="\x1BOD":r.key="\x1B[D":e.key==="UIKeyInputRightArrow"?t?r.key="\x1BOC":r.key="\x1B[C":e.key==="UIKeyInputDownArrow"&&(t?r.key="\x1BOB":r.key="\x1B[B");break;case 8:r.key=e.ctrlKey?"\b":"\x7F",e.altKey&&(r.key="\x1B"+r.key);break;case 9:if(e.shiftKey){r.key="\x1B[Z";break}r.key=" ",r.cancel=!0;break;case 13:e.key==="c"&&e.ctrlKey?r.key="":r.key=e.altKey?"\x1B\r":"\r",r.cancel=!0;break;case 27:r.key="\x1B",e.altKey&&(r.key="\x1B\x1B"),r.cancel=!0;break;case 37:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"D":t?r.key="\x1BOD":r.key="\x1B[D";break;case 39:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"C":t?r.key="\x1BOC":r.key="\x1B[C";break;case 38:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"A":t?r.key="\x1BOA":r.key="\x1B[A";break;case 40:if(e.metaKey)break;n?r.key="\x1B[1;"+(n+1)+"B":t?r.key="\x1BOB":r.key="\x1B[B";break;case 45:!e.shiftKey&&!e.ctrlKey&&(r.key="\x1B[2~");break;case 46:n?r.key="\x1B[3;"+(n+1)+"~":r.key="\x1B[3~";break;case 36:n?r.key="\x1B[1;"+(n+1)+"H":t?r.key="\x1BOH":r.key="\x1B[H";break;case 35:n?r.key="\x1B[1;"+(n+1)+"F":t?r.key="\x1BOF":r.key="\x1B[F";break;case 33:e.shiftKey?r.type=2:e.ctrlKey?r.key="\x1B[5;"+(n+1)+"~":r.key="\x1B[5~";break;case 34:e.shiftKey?r.type=3:e.ctrlKey?r.key="\x1B[6;"+(n+1)+"~":r.key="\x1B[6~";break;case 112:n?r.key="\x1B[1;"+(n+1)+"P":r.key="\x1BOP";break;case 113:n?r.key="\x1B[1;"+(n+1)+"Q":r.key="\x1BOQ";break;case 114:n?r.key="\x1B[1;"+(n+1)+"R":r.key="\x1BOR";break;case 115:n?r.key="\x1B[1;"+(n+1)+"S":r.key="\x1BOS";break;case 116:n?r.key="\x1B[15;"+(n+1)+"~":r.key="\x1B[15~";break;case 117:n?r.key="\x1B[17;"+(n+1)+"~":r.key="\x1B[17~";break;case 118:n?r.key="\x1B[18;"+(n+1)+"~":r.key="\x1B[18~";break;case 119:n?r.key="\x1B[19;"+(n+1)+"~":r.key="\x1B[19~";break;case 120:n?r.key="\x1B[20;"+(n+1)+"~":r.key="\x1B[20~";break;case 121:n?r.key="\x1B[21;"+(n+1)+"~":r.key="\x1B[21~";break;case 122:n?r.key="\x1B[23;"+(n+1)+"~":r.key="\x1B[23~";break;case 123:n?r.key="\x1B[24;"+(n+1)+"~":r.key="\x1B[24~";break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?r.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?r.key="\0":e.keyCode>=51&&e.keyCode<=55?r.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?r.key="\x7F":e.key==="/"?r.key="":e.keyCode===219?r.key="\x1B":e.keyCode===220?r.key="":e.keyCode===221&&(r.key="");else if((!i||s)&&e.altKey&&!e.metaKey){let o=ha[e.keyCode]?.[e.shiftKey?1:0];if(o)r.key="\x1B"+o;else if(e.keyCode>=65&&e.keyCode<=90){let h=e.ctrlKey?e.keyCode-64:e.keyCode+32,l=String.fromCharCode(h);e.shiftKey&&(l=l.toUpperCase()),r.key="\x1B"+l}else if(e.keyCode===32)r.key="\x1B"+(e.ctrlKey?"\0":" ");else if(e.key==="Dead"&&e.code.startsWith("Key")){let h=e.code.slice(3,4);e.shiftKey||(h=h.toLowerCase()),r.key="\x1B"+h,r.cancel=!0}}else if(i&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey)e.keyCode===65&&(r.type=1);else if(e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1)r.key=e.key;else if(e.key&&e.ctrlKey&&e.shiftKey)switch(e.code){case"Minus":r.key="";break;case"Digit2":r.key="\0";break;case"Digit6":r.key="";break}break}return r}var Us=class{constructor(){this._functionalKeyCodes={Escape:27,Enter:13,Tab:9,Backspace:127,CapsLock:57358,ScrollLock:57359,NumLock:57360,PrintScreen:57361,Pause:57362,ContextMenu:57363,F13:57376,F14:57377,F15:57378,F16:57379,F17:57380,F18:57381,F19:57382,F20:57383,F21:57384,F22:57385,F23:57386,F24:57387,F25:57388,KP_0:57399,KP_1:57400,KP_2:57401,KP_3:57402,KP_4:57403,KP_5:57404,KP_6:57405,KP_7:57406,KP_8:57407,KP_9:57408,KP_Decimal:57409,KP_Divide:57410,KP_Multiply:57411,KP_Subtract:57412,KP_Add:57413,KP_Enter:57414,KP_Equal:57415,ShiftLeft:57441,ShiftRight:57447,ControlLeft:57442,ControlRight:57448,AltLeft:57443,AltRight:57449,MetaLeft:57444,MetaRight:57450,MediaPlayPause:57430,MediaStop:57432,MediaTrackNext:57435,MediaTrackPrevious:57436,AudioVolumeDown:57438,AudioVolumeUp:57439,AudioVolumeMute:57440},this._csiTildeKeys={Insert:2,Delete:3,PageUp:5,PageDown:6,F5:15,F6:17,F7:18,F8:19,F9:20,F10:21,F11:23,F12:24},this._csiLetterKeys={ArrowUp:"A",ArrowDown:"B",ArrowRight:"C",ArrowLeft:"D",Home:"H",End:"F"},this._ss3FunctionKeys={F1:"P",F2:"Q",F3:"R",F4:"S"}}_getNumpadKeyCode(e){if(e.code.startsWith("Numpad")){let t=e.code.slice(6);if(t>="0"&&t<="9")return 57399+parseInt(t,10);switch(t){case"Decimal":return 57409;case"Divide":return 57410;case"Multiply":return 57411;case"Subtract":return 57412;case"Add":return 57413;case"Enter":return 57414;case"Equal":return 57415}}}_getModifierKeyCode(e){switch(e.code){case"ShiftLeft":return 57441;case"ShiftRight":return 57447;case"ControlLeft":return 57442;case"ControlRight":return 57448;case"AltLeft":return 57443;case"AltRight":return 57449;case"MetaLeft":return 57444;case"MetaRight":return 57450}}_encodeModifiers(e){let t=0;return e.shiftKey&&(t|=1),e.altKey&&(t|=2),e.ctrlKey&&(t|=4),e.metaKey&&(t|=8),t>0?t+1:0}_getKeyCode(e,t){let i=this._getNumpadKeyCode(e);if(i!==void 0)return i;let s=this._getModifierKeyCode(e);if(s!==void 0)return s;let r=this._functionalKeyCodes[e.key];if(r!==void 0)return r;if((e.shiftKey||t&&e.altKey)&&e.code){if(e.code.startsWith("Digit")&&e.code.length===6){let n=e.code.charAt(5);if(n>="0"&&n<="9")return n.charCodeAt(0)}if(e.code.startsWith("Key")&&e.code.length===4)return e.code.charAt(3).toLowerCase().charCodeAt(0)}if(e.key.length===1){let n=e.key.codePointAt(0);return n>=65&&n<=90?n+32:n}}_isModifierKey(e){return e.key==="Shift"||e.key==="Control"||e.key==="Alt"||e.key==="Meta"}_isLockKey(e){return e.key==="CapsLock"||e.key==="NumLock"||e.key==="ScrollLock"}_buildCsiLetterSequence(e,t,i,s){let r=s&&i!==1;if(t>0||r){let n="\x1B[1;"+(t>0?t:"1");return r&&(n+=":"+i),n+=e,n}return"\x1B["+e}_buildSs3Sequence(e,t,i,s){let r=s&&i!==1;if(t>0||r){let n="\x1B[1;"+(t>0?t:"1");return r&&(n+=":"+i),n+=e,n}return"\x1BO"+e}_buildCsiTildeSequence(e,t,i,s){let r=s&&i!==1,n="\x1B["+e;return(t>0||r)&&(n+=";"+(t>0?t:"1"),r&&(n+=":"+i)),n+="~",n}_buildCsiUSequence(e,t,i,s,r,n,o){let h=!!(r&2),l=!!(r&4),a="\x1B["+t,c;l&&e.shiftKey&&e.key.length===1&&!n&&!o&&(c=e.key.codePointAt(0),a+=":"+c);let d=r&16&&s!==3&&e.key.length===1&&!n&&!o&&!e.ctrlKey?e.key.codePointAt(0):void 0,u=h&&s!==1&&(s===3||d===void 0);return(i>0||u||d!==void 0)&&(a+=";",i>0?a+=i:u&&(a+="1"),u&&(a+=":"+s)),d!==void 0&&(a+=";"+d),a+="u",a}evaluate(e,t,i=1,s=!1){let r={type:0,cancel:!1,key:void 0},n=this._encodeModifiers(e),o=this._isModifierKey(e),h=!!(t&2);if(!h&&i===3||o&&!(t&8)||this._isLockKey(e)&&!(t&8))return r;let l=this._csiLetterKeys[e.key];if(l)return r.key=this._buildCsiLetterSequence(l,n,i,h),r.cancel=!0,r;let a=this._ss3FunctionKeys[e.key];if(a)return r.key=this._buildSs3Sequence(a,n,i,h),r.cancel=!0,r;let c=this._csiTildeKeys[e.key];if(c!==void 0)return r.key=this._buildCsiTildeSequence(c,n,i,h),r.cancel=!0,r;let d=this._getKeyCode(e,s);if(d===void 0)return r;let u=d===13||d===9||d===127;if(u&&i===3&&!(t&8))return r;let f=this._functionalKeyCodes[e.key]!==void 0||this._getNumpadKeyCode(e)!==void 0;if(t&8||h&&i===3||(t&1||h)&&(f&&!u||n>0&&e.key.length!==1||n-1>1))r.key=this._buildCsiUSequence(e,d,n,i,t,f,o),r.cancel=!0;else{let _=d===13?"\r":d===9?" ":d===127?"\x7F":void 0;_?r.key=_:e.key.length===1&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&(r.key=e.key)}return r}static shouldUseProtocol(e){return e>0}},ca=class{constructor(){this._codeToVk={KeyA:65,KeyB:66,KeyC:67,KeyD:68,KeyE:69,KeyF:70,KeyG:71,KeyH:72,KeyI:73,KeyJ:74,KeyK:75,KeyL:76,KeyM:77,KeyN:78,KeyO:79,KeyP:80,KeyQ:81,KeyR:82,KeyS:83,KeyT:84,KeyU:85,KeyV:86,KeyW:87,KeyX:88,KeyY:89,KeyZ:90,Digit0:48,Digit1:49,Digit2:50,Digit3:51,Digit4:52,Digit5:53,Digit6:54,Digit7:55,Digit8:56,Digit9:57,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,F13:124,F14:125,F15:126,F16:127,F17:128,F18:129,F19:130,F20:131,F21:132,F22:133,F23:134,F24:135,Numpad0:96,Numpad1:97,Numpad2:98,Numpad3:99,Numpad4:100,Numpad5:101,Numpad6:102,Numpad7:103,Numpad8:104,Numpad9:105,NumpadMultiply:106,NumpadAdd:107,NumpadSeparator:108,NumpadSubtract:109,NumpadDecimal:110,NumpadDivide:111,NumpadEnter:13,NumLock:144,ArrowUp:38,ArrowDown:40,ArrowLeft:37,ArrowRight:39,Home:36,End:35,PageUp:33,PageDown:34,Insert:45,Delete:46,ShiftLeft:16,ShiftRight:16,ControlLeft:17,ControlRight:17,AltLeft:18,AltRight:18,MetaLeft:91,MetaRight:92,CapsLock:20,ScrollLock:145,Escape:27,Enter:13,Tab:9,Space:32,Backspace:8,Pause:19,ContextMenu:93,PrintScreen:44,Semicolon:186,Equal:187,Comma:188,Minus:189,Period:190,Slash:191,Backquote:192,BracketLeft:219,Backslash:220,BracketRight:221,Quote:222,IntlBackslash:226},this._codeToScancode={KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,F11:87,F12:88,Numpad0:82,Numpad1:79,Numpad2:80,Numpad3:81,Numpad4:75,Numpad5:76,Numpad6:77,Numpad7:71,Numpad8:72,Numpad9:73,NumpadMultiply:55,NumpadAdd:78,NumpadSubtract:74,NumpadDecimal:83,NumpadDivide:53,NumpadEnter:28,NumLock:69,ArrowUp:72,ArrowDown:80,ArrowLeft:75,ArrowRight:77,Home:71,End:79,PageUp:73,PageDown:81,Insert:82,Delete:83,ShiftLeft:42,ShiftRight:54,ControlLeft:29,ControlRight:29,AltLeft:56,AltRight:56,CapsLock:58,ScrollLock:70,Escape:1,Enter:28,Tab:15,Space:57,Backspace:14,Pause:69,Semicolon:39,Equal:13,Comma:51,Minus:12,Period:52,Slash:53,Backquote:41,BracketLeft:26,Backslash:43,BracketRight:27,Quote:40},this._enhancedKeyCodes=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Insert","Delete","NumpadEnter","NumpadDivide","ControlRight","AltRight","PrintScreen","Pause","ContextMenu","MetaLeft","MetaRight"]),this._keyToControlChar={Enter:13,Backspace:8,Tab:9,Escape:27}}_getVirtualKeyCode(e){let t=this._codeToVk[e.code];return t!==void 0?t:e.keyCode||0}_getScanCode(e){return this._codeToScancode[e.code]||0}_getUnicodeChar(e){if(e.ctrlKey&&!e.altKey&&!e.metaKey){if(e.key==="Enter")return 10;if(e.key==="Backspace")return 127}let t=this._keyToControlChar[e.key];if(t!==void 0)return t;if(e.key.length===1){let i=e.key.codePointAt(0)||0;if(e.ctrlKey&&!e.altKey&&!e.metaKey){if(i>=65&&i<=90)return i-64;if(i>=97&&i<=122)return i-96}return i}return 0}_getControlKeyState(e){let t=0;return e.shiftKey&&(t|=16),e.ctrlKey&&(e.code==="ControlRight"?t|=4:t|=8),e.altKey&&(e.code==="AltRight"?t|=1:t|=2),this._enhancedKeyCodes.has(e.code)&&(t|=256),t}evaluateKeyboardEvent(e,t){let i=this._getVirtualKeyCode(e),s=this._getScanCode(e),r=this._getUnicodeChar(e),n=t?1:0,o=this._getControlKeyState(e);return{type:0,cancel:!0,key:`\x1B[${i};${s};${r};${n};${o};1_`}}},Ii=class{constructor(e,t){this._coreService=e,this._optionsService=t}_getWin32InputMode(){return this._win32InputMode??=new ca,this._win32InputMode}_getKittyKeyboard(){return this._kittyKeyboard??=new Us,this._kittyKeyboard}evaluateKeyDown(e){if(this.useWin32InputMode)return this._getWin32InputMode().evaluateKeyboardEvent(e,!0);let t=this._coreService.kittyKeyboard.flags;return this.useKitty?this._getKittyKeyboard().evaluate(e,t,e.repeat?2:1,fe&&this._optionsService.rawOptions.macOptionIsMeta):la(e,this._coreService.decPrivateModes.applicationCursorKeys,fe,this._optionsService.rawOptions.macOptionIsMeta)}evaluateKeyUp(e){if(this.useWin32InputMode)return this._getWin32InputMode().evaluateKeyboardEvent(e,!1);let t=this._coreService.kittyKeyboard.flags;if(this.useKitty&&t&2)return this._getKittyKeyboard().evaluate(e,t,3,fe&&this._optionsService.rawOptions.macOptionIsMeta)}get useKitty(){let e=this._coreService.kittyKeyboard.flags;return!!(this._optionsService.rawOptions.vtExtensions?.kittyKeyboard&&Us.shouldUseProtocol(e))}get useWin32InputMode(){return!!(this._optionsService.rawOptions.vtExtensions?.win32InputMode&&this._coreService.decPrivateModes.win32InputMode)}};Ii=F([g(0,De),g(1,oe)],Ii);var da=class{constructor(...e){this._entries=new Map;for(let[t,i]of e)this.set(t,i)}set(e,t){let i=this._entries.get(e);return this._entries.set(e,t),i}forEach(e){for(let[t,i]of this._entries.entries())e(t,i)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},_a=class{constructor(){this._services=new da,this._services.set(qi,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let i=Vn(e).sort((n,o)=>n.index-o.index),s=[];for(let n of i){let o=this._services.get(n.id);if(!o)throw new Error(`[createInstance] ${e.name} depends on UNKNOWN service ${n.id._id}.`);s.push(o)}let r=i.length>0?i[0].index:t.length;if(t.length!==r)throw new Error(`[createInstance] First service dependency of ${e.name} at position ${r+1} conflicts with ${t.length} static arguments`);return new e(...t,...s)}},ua={trace:0,debug:1,info:2,warn:3,error:4,off:5},fa="xterm.js: ",Ni=class extends L{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange("logLevel",()=>this._updateLogLevel()))}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=ua[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;tthis._length)for(let t=this._length;t=e;s--)this._array[this._getCyclicIndex(s+i.length)]=this._array[this._getCyclicIndex(s)];for(let s=0;sthis._maxLength){let s=this._length+i.length-this._maxLength;this._startIndex+=s,this._length=this._maxLength,this.onTrimEmitter.fire(s)}else this._length+=i.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,i){if(!(t<=0)){if(e<0||e>=this._length)throw new Error("start argument out of range");if(e+i<0)throw new Error("Cannot shift elements in list beyond index 0");if(i>0){for(let r=t-1;r>=0;r--)this.set(e+r+i,this.get(e+r));let s=e+t+i-this._length;if(s>0)for(this._length+=s;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let s=0;sthis._limit?(this._builder.reset(),!0):!1}toString(){return this._builder.toString()}},j=Object.freeze(new vt),Et=0,Vs=new ge,Dt=new Pr,ct=class Ar{constructor(t,i,s,r=!1){this._stringCache=t,this.isWrapped=r,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(i*3);let n=s??ge.fromCharData([0,"",1,0]);for(let o=0;o>22,i&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):s]}set(t,i){this._invalidateStringCache(),this._data[t*3+1]=i[0],i[1].length>1?(this._combined[t]=i[1],this._data[t*3+0]=t|2097152|i[2]<<22):this._data[t*3+0]=i[1].charCodeAt(0)|i[2]<<22}getWidth(t){return this._data[t*3+0]>>22}hasWidth(t){return this._data[t*3+0]&12582912}getFg(t){return this._data[t*3+1]}getBg(t){return this._data[t*3+2]}hasContent(t){return this._data[t*3+0]&4194303}getCodePoint(t){let i=this._data[t*3+0];return i&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):i&2097151}isCombined(t){return this._data[t*3+0]&2097152}getString(t){let i=this._data[t*3+0];return i&2097152?this._combined[t]:i&2097151?Ae(i&2097151):""}isProtected(t){return this._data[t*3+2]&536870912}loadCell(t,i){return Et=t*3,i.content=this._data[Et+0],i.fg=this._data[Et+1],i.bg=this._data[Et+2],i.content&2097152?i.combinedData=this._combined[t]:i.combinedData="",i.bg&268435456?i.extended=this._extendedAttrs[t]:i.extended=j.extended.clone(),i}setCell(t,i){this._invalidateStringCache(),i.content&2097152&&(this._combined[t]=i.combinedData),i.bg&268435456&&(this._extendedAttrs[t]=i.extended),this._data[t*3+0]=i.content,this._data[t*3+1]=i.fg,this._data[t*3+2]=i.bg}setCellFromCodepoint(t,i,s,r){this._invalidateStringCache(),r.bg&268435456&&(this._extendedAttrs[t]=r.extended),this._data[t*3+0]=i|s<<22,this._data[t*3+1]=r.fg,this._data[t*3+2]=r.bg}addCodepointToCell(t,i,s){this._invalidateStringCache();let r=this._data[t*3+0];r&2097152?this._combined[t]+=Ae(i):r&2097151?(this._combined[t]=Ae(r&2097151)+Ae(i),r&=-2097152,r|=2097152):r=i|1<<22,s&&(r&=-12582913,r|=s<<22),this._data[t*3+0]=r}insertCells(t,i,s){if(this._invalidateStringCache(),t%=this.length,t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,s),i=0;--r)this.setCell(t+i+r,this.loadCell(t+r,Vs));for(let r=0;rthis.length){if(this._data.buffer.byteLength>=s*4)this._data=new Uint32Array(this._data.buffer,0,s);else{let r=new Uint32Array(s);r.set(this._data),this._data=r}for(let r=this.length;r=t&&delete this._combined[h]}let n=Object.keys(this._extendedAttrs);for(let o=0;o=t&&delete this._extendedAttrs[h]}}return this.length=t,s*4*2=0;--t)if(this._data[t*3+0]&4194303)return t+(this._data[t*3+0]>>22);return 0}getNoBgTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*3+0]&4194303||this._data[t*3+2]&50331648)return t+(this._data[t*3+0]>>22);return 0}copyCellsFrom(t,i,s,r,n){this._invalidateStringCache();let o=t._data;if(n)for(let h=r-1;h>=0;h--){for(let l=0;l<3;l++)this._data[(s+h)*3+l]=o[(i+h)*3+l];this._copyCellMapsFrom(t,i+h,s+h)}else for(let h=0;h>22||1}r&&r.push(i);let h=Dt.toString();if(Dt.reset(),n){let l=this._getStringCacheEntry(!0);l.value=h,l.isTrimmed=!!t}return h}_getStringCacheEntry(t){let i=this._stringCacheEntryRef?.deref();if(i&&i.generation===this._stringCache.generation)return i;if(!t)return;let s=this._stringCache.allocateEntry();return this._stringCacheEntryRef=new WeakRef(s),s}_invalidateStringCache(){let t=this._getStringCacheEntry(!1);t&&(t.value=void 0,t.isTrimmed=!1)}_copyCellMapsFrom(t,i,s){let r=i*3;t._data[r+0]&2097152&&(this._combined[s]=t._combined[i]),t._data[r+2]&268435456&&(this._extendedAttrs[s]=t._extendedAttrs[i])}_copySparseMapsFrom(t){this._combined={},this._extendedAttrs={};for(let i=0;ithis.entries.clear()))}touch(){this._scheduleClear()}allocateEntry(){let e={value:void 0,isTrimmed:!1,generation:this.generation};return this.entries.add(e),this._scheduleClear(),e}clear(){this._clearTimeout.clear(),this._lastAccessTimestamp=0,this.generation++;for(let e of this.entries)e.value=void 0,e.isTrimmed=!1;this.entries.clear()}_scheduleClear(){this._lastAccessTimestamp=Date.now(),!this._clearTimeout.value&&this._scheduleClearTimeout(15e3)}_scheduleClearTimeout(e){this._clearTimeout.value=Qn(()=>{let t=Date.now()-this._lastAccessTimestamp;if(t>=15e3){this.clear();return}this._scheduleClearTimeout(15e3-t)},e)}};function ga(e,t,i,s,r,n){let o=[];for(let h=0;h=h&&s0&&(S>d||c[S].getTrimmedLength()===0);S--)p++;p>0&&(o.push(h+c.length-p),o.push(p)),h+=c.length-1}return o}function va(e,t){let i=[],s=0,r=t[s],n=0;for(let o=0;ol&&(n-=l,o++);let a=e[o].getWidth(n-1)===2;a&&n--;let c=a?i-1:i;s.push(c),h+=c}return s}function gt(e,t,i){if(t===e.length-1)return e[t].getTrimmedLength();let s=!e[t].hasContent(i-1)&&e[t].getWidth(i-1)===1,r=e[t+1].getWidth(0)===2;return s&&r?i-1:i}var Or=class Ir{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=Ir._nextId++,this._onDispose=this.register(new y),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),ut(this._disposables),this._disposables.length=0)}register(t){return this._disposables.push(t),t}};Or._nextId=1;var wa=Or,G={},ze=G.B;G[0]={"`":"\u25C6",a:"\u2592",b:"\u2409",c:"\u240C",d:"\u240D",e:"\u240A",f:"\xB0",g:"\xB1",h:"\u2424",i:"\u240B",j:"\u2518",k:"\u2510",l:"\u250C",m:"\u2514",n:"\u253C",o:"\u23BA",p:"\u23BB",q:"\u2500",r:"\u23BC",s:"\u23BD",t:"\u251C",u:"\u2524",v:"\u2534",w:"\u252C",x:"\u2502",y:"\u2264",z:"\u2265","{":"\u03C0","|":"\u2260","}":"\xA3","~":"\xB7"};G.A={"#":"\xA3"};G.B=void 0;G[4]={"#":"\xA3","@":"\xBE","[":"ij","\\":"\xBD","]":"|","{":"\xA8","|":"f","}":"\xBC","~":"\xB4"};G.C=G[5]={"[":"\xC4","\\":"\xD6","]":"\xC5","^":"\xDC","`":"\xE9","{":"\xE4","|":"\xF6","}":"\xE5","~":"\xFC"};G.R={"#":"\xA3","@":"\xE0","[":"\xB0","\\":"\xE7","]":"\xA7","{":"\xE9","|":"\xF9","}":"\xE8","~":"\xA8"};G.Q={"@":"\xE0","[":"\xE2","\\":"\xE7","]":"\xEA","^":"\xEE","`":"\xF4","{":"\xE9","|":"\xF9","}":"\xE8","~":"\xFB"};G.K={"@":"\xA7","[":"\xC4","\\":"\xD6","]":"\xDC","{":"\xE4","|":"\xF6","}":"\xFC","~":"\xDF"};G.Y={"#":"\xA3","@":"\xA7","[":"\xB0","\\":"\xE7","]":"\xE9","`":"\xF9","{":"\xE0","|":"\xF2","}":"\xE8","~":"\xEC"};G.E=G[6]={"@":"\xC4","[":"\xC6","\\":"\xD8","]":"\xC5","^":"\xDC","`":"\xE4","{":"\xE6","|":"\xF8","}":"\xE5","~":"\xFC"};G.Z={"#":"\xA3","@":"\xA7","[":"\xA1","\\":"\xD1","]":"\xBF","{":"\xB0","|":"\xF1","}":"\xE7"};G.H=G[7]={"@":"\xC9","[":"\xC4","\\":"\xD6","]":"\xC5","^":"\xDC","`":"\xE9","{":"\xE4","|":"\xF6","}":"\xE5","~":"\xFC"};G["="]={"#":"\xF9","@":"\xE0","[":"\xE9","\\":"\xE7","]":"\xEA","^":"\xEE",_:"\xE8","`":"\xF4","{":"\xE4","|":"\xF6","}":"\xFC","~":"\xFB"};var Ys=4294967295,Xs=class extends L{constructor(e,t,i,s){super(),this._hasScrollback=e,this._optionsService=t,this._bufferService=i,this._logService=s,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=j.clone(),this.savedCharset=ze,this.savedCharsets=[],this.savedGlevel=0,this.savedOriginMode=!1,this.savedWraparoundMode=!0,this.markers=[],this._nullCell=ge.fromCharData([0,"",1,0]),this._whitespaceCell=ge.fromCharData([0," ",1,32]),this._isClearing=!1,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new qs(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops(),this._memoryCleanupQueue=new Nt(this._logService),this._register(O(()=>this._memoryCleanupQueue.clear())),this._register(O(()=>this.clearAllMarkers())),this._stringCache=this._register(new pa)}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new Pt),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new Pt),this._whitespaceCell}getBlankLine(e,t){return new ct(this._stringCache,this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&eYs?Ys:t}fillViewportRows(e){if(this.lines.length===0){e??=j;let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this._stringCache.clear(),this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new qs(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let i=this.getNullCell(j);this._stringCache.clear();let s=0,r=this._getCorrectBufferLength(t);if(r>this.lines.maxLength&&(this.lines.maxLength=r),this.lines.length>0){if(this._cols0&&this.lines.length<=this.ybase+this.y+n+1?(this.ybase--,n++,this.ydisp>0&&this.ydisp--):this.lines.push(new ct(this._stringCache,e,i,!1)));else for(let o=this._rows;o>t;o--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(r0&&(this.lines.trimStart(o),this.ybase=Math.max(this.ybase-o,0),this.ydisp=Math.max(this.ydisp-o,0),this.savedY=Math.max(this.savedY-o,0)),this.lines.maxLength=r}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),n&&(this.y+=n),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let n=0;n0){let n=Math.max(0,this.lines.length-this.ybase-1);this.y=Math.min(this.y,n)}this._memoryCleanupQueue.clear(),s>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend==="conpty"&&e.buildNumber>=21376:this._hasScrollback}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let i=this._optionsService.rawOptions.reflowCursorLine,s=ga(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(j),i);if(s.length>0){let r=va(this.lines,s);ma(this.lines,r.layout),this._reflowLargerAdjustViewport(e,t,r.countRemoved)}}_reflowLargerAdjustViewport(e,t,i){let s=this.getNullCell(j),r=i;for(;r-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length=0;o--){let h=this.lines.get(o);if(!h||!h.isWrapped&&h.getTrimmedLength()<=e)continue;let l=[h];for(;h.isWrapped&&o>0;)h=this.lines.get(--o),l.unshift(h);if(!i){let E=this.ybase+this.y;if(E>=o&&E0&&(r.push({start:o+l.length+n,newLines:f}),n+=f.length),l.push(...f);let _=c.length-1,p=c[_];p===0&&(_--,p=c[_]);let S=l.length-d-1,k=a;for(;S>=0;){let E=Math.min(k,p);if(l[_]===void 0)break;if(l[_].copyCellsFrom(l[S],k-E,p-E,E,!0),p-=E,p===0&&(_--,p=c[_]),k-=E,k===0){S--;let B=Math.max(S,0);k=gt(l,B,this._cols)}}for(let E=0;E0;)this.ybase===0?this.y0){let o=[],h=[];for(let p=0;p=0;p--)if(d&&d.start>a+u){for(let S=d.newLines.length-1;S>=0;S--)this.lines.set(p--,d.newLines[S]);p++,o.push({index:a+1,amount:d.newLines.length}),u+=d.newLines.length,d=r[++c]}else this.lines.set(p,h[a--]);let f=0;for(let p=o.length-1;p>=0;p--)o[p].index+=f,this.lines.onInsertEmitter.fire(o[p]),f+=o[p].amount;let _=Math.max(0,l+n-this.lines.maxLength);_>0&&this.lines.onTrimEmitter.fire(_)}}translateBufferLineToString(e,t,i=0,s){let r=this.lines.get(e);return r?r.translateToString(t,i,s):""}getWrappedRangeForLine(e){let t=e,i=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;i+10;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t{t.line-=i,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(i=>{t.line>=i.index&&(t.line+=i.amount)})),t.register(this.lines.onDelete(i=>{t.line>=i.index&&t.linei.index&&(t.line-=i.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},ba=class extends L{constructor(e,t,i){super(),this._optionsService=e,this._bufferService=t,this._logService=i,this._normalBuffer=this._register(new le),this._altBuffer=this._register(new le),this._onBufferActivate=this._register(new y),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange("scrollback",()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange("tabStopWidth",()=>this.setupTabStops()))}reset(){this._normal=new Xs(!0,this._optionsService,this._bufferService,this._logService),this._normalBuffer.value=this._normal,this._normal.fillViewportRows(),this._alt=new Xs(!1,this._optionsService,this._bufferService,this._logService),this._altBuffer.value=this._alt,this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},Hi=class extends L{constructor(e,t){super(),this.isUserScrolling=!1,this._onResize=this._register(new y),this.onResize=this._onResize.event,this._onScroll=this._register(new y),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,2),this.rows=Math.max(e.rawOptions.rows||0,1),this.buffers=this._register(new ba(e,this,t)),this._register(this.buffers.onBufferActivate(i=>{this._onScroll.fire(i.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let i=this.cols!==e,s=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:i,rowsChanged:s})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let i=this.buffer,s;s=this._cachedBlankLine,(!s||s.length!==this.cols||s.getFg(0)!==e.fg||s.getBg(0)!==e.bg)&&(s=i.getBlankLine(e,t),this._cachedBlankLine=s),s.isWrapped=t;let r=i.ybase+i.scrollTop,n=i.ybase+i.scrollBottom;if(i.scrollTop===0){let o=i.lines.isFull;n===i.lines.length-1?o?i.lines.recycle().copyFrom(s):i.lines.push(s.clone()):i.lines.splice(n+1,0,s.clone()),o?this.isUserScrolling&&(i.ydisp=Math.max(i.ydisp-1,0)):(i.ybase++,this.isUserScrolling||i.ydisp++)}else{let o=n-r+1;i.lines.shiftElements(r+1,o-1,-1),i.lines.set(n,s.clone())}this.isUserScrolling||(i.ydisp=i.ybase),this._onScroll.fire(i.ydisp)}scrollLines(e,t){let i=this.buffer;if(e<0){if(i.ydisp===0)return;this.isUserScrolling=!0}else e+i.ydisp>=i.ybase&&(this.isUserScrolling=!1);let s=i.ydisp;i.ydisp=Math.max(Math.min(i.ydisp+e,i.ybase),0),s!==i.ydisp&&(t||this._onScroll.fire(i.ydisp))}};Hi=F([g(0,oe),g(1,Je)],Hi);var Xe={cols:80,rows:24,showCursorImmediately:!1,cursorBlink:!1,blinkIntervalDuration:0,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollSensitivity:5,fontFamily:"monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollbar:{showScrollbar:!0},scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,mouseEventsRequireAlt:!1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:fe,windowOptions:{},windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",quirks:{},vtExtensions:{}},ya=["normal","bold","100","200","300","400","500","600","700","800","900"],Ca=class extends L{constructor(e){super(),this._onOptionChange=this._register(new y),this.onOptionChange=this._onOptionChange.event;let t={...Xe};for(let i in e)if(i in t)try{let s=e[i];t[i]=this._sanitizeAndValidateOption(i,s)}catch(s){console.error(s)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(O(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(i=>{i===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(i=>{e.indexOf(i)!==-1&&t()})}_setupOptions(){let e=i=>{if(!(i in Xe))throw new Error(`No option with key "${i}"`);return this.rawOptions[i]},t=(i,s)=>{if(!(i in Xe))throw new Error(`No option with key "${i}"`);s=this._sanitizeAndValidateOption(i,s),this.rawOptions[i]!==s&&(this.rawOptions[i]=s,this._onOptionChange.fire(i))};for(let i in this.rawOptions){let s={get:e.bind(this,i),set:t.bind(this,i)};Object.defineProperty(this.options,i,s)}}_sanitizeAndValidateOption(e,t){switch(e){case"cursorStyle":if(t||(t=Xe[e]),!ka(t))throw new Error(`"${t}" is not a valid value for ${e}`);break;case"wordSeparator":t||(t=Xe[e]);break;case"fontWeight":case"fontWeightBold":if(typeof t=="number"&&1<=t&&t<=1e3)break;t=ya.includes(t)?t:Xe[e];break;case"blinkIntervalDuration":if(t=Math.floor(t),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"cursorWidth":t=Math.floor(t);case"lineHeight":case"tabStopWidth":if(t<1)throw new Error(`${e} cannot be less than 1, value: ${t}`);break;case"minimumContrastRatio":t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case"scrollback":if(t=Math.min(t,4294967295),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(t<=0)throw new Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case"rows":case"cols":if(!t&&t!==0)throw new Error(`${e} must be numeric, value: ${t}`);break;case"windowsPty":t=t??{};break}return t}};function ka(e){return e==="block"||e==="underline"||e==="bar"}var js=Object.freeze({insertMode:!1}),Gs=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,colorSchemeUpdates:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,win32InputMode:!1,wraparound:!0}),Js=()=>({flags:0,mainFlags:0,altFlags:0,mainStack:[],altStack:[]}),Fi=class extends L{constructor(e,t,i){super(),this._bufferService=e,this._logService=t,this._optionsService=i,this.isCursorHidden=!1,this._onData=this._register(new y),this.onData=this._onData.event,this._onUserInput=this._register(new y),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new y),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new y),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.isCursorInitialized=i.rawOptions.showCursorImmediately??!1,this.modes=structuredClone(js),this.decPrivateModes=structuredClone(Gs),this.kittyKeyboard=Js()}reset(){this.modes=structuredClone(js),this.decPrivateModes=structuredClone(Gs),this.kittyKeyboard=Js()}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let i=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&i.ybase!==i.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace("sending data (codes)",()=>e.split("").map(s=>s.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace("sending binary (codes)",()=>e.split("").map(t=>t.charCodeAt(0))),this._onBinary.fire(e))}};Fi=F([g(0,ne),g(1,Je),g(2,oe)],Fi);var Zs={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>!(e.action===32&&e.button===3)},ANY:{events:31,restrict:e=>!0}};function ui(e,t){let i=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(i|=64,i|=e.action):(i|=e.button&3,e.button&4&&(i|=64),e.button&8&&(i|=128),e.action===32?i|=32:e.action===0&&!t&&(i|=3)),i}var fi=String.fromCharCode,Qs={DEFAULT:e=>{let t=[ui(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?"":`\x1B[M${fi(t[0])}${fi(t[1])}${fi(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${ui(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${ui(e,!0)};${e.x};${e.y}${t}`}},xa=class extends L{constructor(){super(),this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._onProtocolChange=this._register(new y),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(Zs))this.addProtocol(e,Zs[e]);for(let e of Object.keys(Qs))this.addEncoding(e,Qs[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw new Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw new Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT"}setCustomWheelEventHandler(e){this._customWheelEventHandler=e}allowCustomWheelEvent(e){return this._customWheelEventHandler?this._customWheelEventHandler(e)!==!1:!0}restrictMouseEvent(e){return this._protocols[this._activeProtocol].restrict(e)}encodeMouseEvent(e){return this._encodings[this._activeEncoding](e)}get isDefaultEncoding(){return this._activeEncoding==="DEFAULT"}get isPixelEncoding(){return this._activeEncoding==="SGR_PIXELS"}},Ke=class Rt{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new y,this.onChange=this._onChange.event}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,i,s=!1){return(t&16777215)<<3|(i&3)<<1|(s?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t,this._active||(this.activeVersion=t.version)}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let i=0,s=0,r=t.length;for(let n=0;n=r)return i+this.wcwidth(o);let a=t.charCodeAt(n);56320<=a&&a<=57343?o=(o-55296)*1024+a-56320+65536:i+=this.wcwidth(a)}let h=this.charProperties(o,s),l=Rt.extractWidth(h);Rt.extractShouldJoin(h)&&(l-=Rt.extractWidth(s)),i+=l,s=h}return i}charProperties(t,i){return this._activeProvider.charProperties(t,i)}},pi=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],Ba=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],X;function Ea(e,t){let i=0,s=t.length-1,r;if(et[s][1])return!1;for(;s>=i;)if(r=i+s>>1,e>t[r][1])i=r+1;else if(e=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let i=this.wcwidth(e),s=i===0&&t!==0;if(s){let r=Ke.extractWidth(t);r===0?s=!1:r>i&&(i=r)}return Ke.createPropertyValue(0,i,s)}},Ma=class{constructor(){this.glevel=0,this._charsets=[]}get charsets(){return this._charsets}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function er(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),i=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);i&&t&&(i.isWrapped=t[3]!==0&&t[3]!==32)}var Nr=class Wi{constructor(t=32,i=32){if(this.maxLength=t,this.maxSubParamsLength=i,i>256)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(t),this.length=0,this._subParams=new Int32Array(i),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(t),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let i=new Wi;if(!t.length)return i;for(let s=Array.isArray(t[0])?1:0;s>8,r=this._subParamsIdx[i]&255;r-s>0&&t.push(Array.prototype.slice.call(this._subParams,s,r))}return t}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}resetZdm(){this.length=1,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1,this._subParamsIdx[0]=0,this.params[0]=0}addParam(t){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(t<-1)throw new Error("values less than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=t>2147483647?2147483647:t}addSubParam(t){if(this._digitIsSub=!0,!!this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(t<-1)throw new Error("values less than -1 are not allowed");this._subParams[this._subParamsLength++]=t>2147483647?2147483647:t,this._subParamsIdx[this.length-1]++}}hasSubParams(t){return(this._subParamsIdx[t]&255)-(this._subParamsIdx[t]>>8)>0}getSubParams(t){let i=this._subParamsIdx[t]>>8,s=this._subParamsIdx[t]&255;return s-i>0?this._subParams.subarray(i,s):null}getSubParamsAll(){let t={};for(let i=0;i>8,r=this._subParamsIdx[i]&255;r-s>0&&(t[i]=this._subParams.slice(s,r))}return t}addDigit(t){let i;if(this._rejectDigits||!(i=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let s=this._digitIsSub?this._subParams:this.params,r=s[i-1];s[i-1]=~r?Math.min(r*10+t,2147483647):t}},nt=[],La=class{constructor(){this._state=0,this._active=nt,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]??=[];let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=nt}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=nt,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||nt,!this._active.length)this._handlerFb(this._id,"START");else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,i){if(!this._active.length)this._handlerFb(this._id,"PUT",Ge(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}start(){this.reset(),this._state=1}put(e,t,i){if(this._state!==3){if(this._state===1)for(;t0&&this._put(e,t,i)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,"END",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].end(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].end(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=nt,this._id=-1,this._state=0}}},Hr=class Fr{constructor(t){this._handler=t,this._data=new es(Fr._payloadLimit),this._hitLimit=!1}start(){this._data.reset(),this._hitLimit=!1}put(t,i,s){this._hitLimit||this._data.append(Ge(t,i,s))&&(this._hitLimit=!0)}end(t){let i=!1;if(this._hitLimit)i=!1;else if(t&&(i=this._handler(this._data.toString()),i instanceof Promise))return i.then(s=>(this._data.reset(),this._hitLimit=!1,s));return this._data.reset(),this._hitLimit=!1,i}};Hr._payloadLimit=1e7;var de=Hr,ot=[],Ra=class{constructor(){this._handlers=Object.create(null),this._active=ot,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=ot}registerHandler(e,t){this._handlers[e]??=[];let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=ot,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||ot,!this._active.length)this._handlerFb(this._ident,"HOOK",t);else for(let i=this._active.length-1;i>=0;i--)this._active[i].hook(t)}put(e,t,i){if(!this._active.length)this._handlerFb(this._ident,"PUT",Ge(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"UNHOOK",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].unhook(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].unhook(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=ot,this._ident=0}},dt=new Nr;dt.addParam(0);var Wr=class zr{constructor(t){this._handler=t,this._data=new es(zr._payloadLimit),this._params=dt,this._hitLimit=!1}hook(t){this._params=t.length>1||t.params[0]?t.clone():dt,this._data.reset(),this._hitLimit=!1}put(t,i,s){this._hitLimit||this._data.append(Ge(t,i,s))&&(this._hitLimit=!0)}unhook(t){let i=!1;if(this._hitLimit)i=!1;else if(t&&(i=this._handler(this._data.toString(),this._params),i instanceof Promise))return i.then(s=>(this._params=dt,this._data.reset(),this._hitLimit=!1,s));return this._params=dt,this._data.reset(),this._hitLimit=!1,i}};Wr._payloadLimit=1e7;var tr=Wr,at=[],Ta=class{constructor(){this._handlers=Object.create(null),this._active=at,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]??=[];let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=at}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=at,this._ident=0}start(e){if(this.reset(),this._ident=e,this._active=this._handlers[e]||at,!this._active.length)this._handlerFb(this._ident,"START");else for(let t=this._active.length-1;t>=0;t--)this._active[t].start()}put(e,t,i){if(!this._active.length)this._handlerFb(this._ident,"PUT",Ge(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}end(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"END",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].end(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].end(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=at,this._ident=0}},Kr=class $r{constructor(t){this._handler=t,this._data=new es($r._payloadLimit),this._hitLimit=!1}start(){this._data.reset(),this._hitLimit=!1}put(t,i,s){this._hitLimit||this._data.append(Ge(t,i,s))&&(this._hitLimit=!0)}end(t){let i=!1;if(this._hitLimit)i=!1;else if(t&&(i=this._handler(this._data.toString()),i instanceof Promise))return i.then(s=>(this._data.reset(),this._hitLimit=!1,s));return this._data.reset(),this._hitLimit=!1,i}};Kr._payloadLimit=1e7;var Pa=Kr,Aa=class{constructor(e){this.table=new Uint16Array(e)}setDefault(e,t){this.table.fill(e<<8|t)}add(e,t,i,s){this.table[t<<8|e]=i<<8|s}addMany(e,t,i,s){for(let r=0;rh),i=(o,h)=>t.slice(o,h),s=i(32,127),r=i(0,24);r.push(25),r.push.apply(r,i(28,32));let n=i(0,17);e.setDefault(1,0),e.addMany(s,0,2,0);for(let o of n)e.addMany([24,26,153,154],o,3,0),e.addMany(i(128,144),o,3,0),e.addMany(i(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158],o,0,7),e.add(159,o,11,14),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(r,0,3,0),e.addMany(r,1,3,1),e.add(127,1,0,1),e.addMany(r,8,0,8),e.addMany(r,3,3,3),e.add(127,3,0,3),e.addMany(r,4,3,4),e.add(127,4,0,4),e.addMany(r,6,3,6),e.addMany(r,5,3,5),e.add(127,5,0,5),e.addMany(r,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(s,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(i(28,32),8,0,8),e.addMany([88,94],1,0,7),e.addMany(s,7,0,7),e.addMany(r,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(95,1,11,14),e.addMany(r,14,0,14),e.add(127,14,0,14),e.addMany(i(32,48),14,9,15),e.addMany(i(48,127),14,15,16),e.addMany(i(48,127),15,15,16),e.addMany(r,15,0,15),e.addMany(i(32,48),15,9,15),e.add(127,15,0,15),e.addMany(s,16,16,16),e.addMany(r,16,0,16),e.addMany(i(8,14),16,16,16),e.add(127,16,0,16),e.addMany([27,156,24,26],16,17,0),e.add(91,1,11,3),e.addMany(i(64,127),3,7,0),e.addMany(i(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(i(48,60),4,8,4),e.addMany(i(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(i(32,64),6,0,6),e.add(127,6,0,6),e.addMany(i(64,127),6,0,0),e.addMany(i(32,48),3,9,5),e.addMany(i(32,48),5,9,5),e.addMany(i(48,64),5,0,6),e.addMany(i(64,127),5,7,0),e.addMany(i(32,48),4,9,5),e.addMany(i(32,48),1,9,2),e.addMany(i(32,48),2,9,2),e.addMany(i(48,127),2,10,0),e.addMany(i(48,80),1,10,0),e.addMany(i(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(i(96,127),1,10,0),e.add(80,1,11,9),e.addMany(r,9,0,9),e.add(127,9,0,9),e.addMany(i(32,48),9,9,12),e.addMany(i(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(r,11,0,11),e.addMany(i(32,128),11,0,11),e.addMany(r,10,0,10),e.add(127,10,0,10),e.addMany(i(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(i(32,48),10,9,12),e.addMany(r,12,0,12),e.add(127,12,0,12),e.addMany(i(32,48),12,9,12),e.addMany(i(48,64),12,0,11),e.addMany(i(64,127),12,12,13),e.addMany(i(64,127),10,12,13),e.addMany(i(64,127),9,12,13),e.addMany(r,13,13,13),e.addMany(s,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(re,0,2,0),e.add(re,8,5,8),e.add(re,6,0,6),e.add(re,11,0,11),e.add(re,13,13,13),e.add(re,16,16,16),e})(),Ia=class extends L{constructor(e=Oa){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new Nr,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(t,i,s)=>{},this._executeHandlerFb=t=>{},this._csiHandlerFb=(t,i)=>{},this._escHandlerFb=t=>{},this._errorHandlerFb=t=>t,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._executeHandlersArr=new Array(24).fill(void 0),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(O(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._executeHandlersArr=new Array(24).fill(void 0),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new La),this._dcsParser=this._register(new Ra),this._apcParser=this._register(new Ta),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},()=>!0)}_identifier(e,t=[64,126]){let i=0;if(e.prefix){if(e.prefix.length>1)throw new Error("only one byte as prefix supported");if(i=e.prefix.charCodeAt(0),i<60||i>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(e.intermediates){if(e.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let r=0;rn||n>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");i<<=8,i|=n}}if(e.final.length!==1)throw new Error("final must be a single byte");let s=e.final.charCodeAt(0);if(t[0]>s||s>t[1])throw new Error(`final must be in range ${t[0]} .. ${t[1]}`);return i<<=8,i|=s,i}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join("")}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let i=this._identifier(e,[48,126]);this._escHandlers[i]??=[];let s=this._escHandlers[i];return s.push(t),{dispose:()=>{let r=s.indexOf(t);r!==-1&&s.splice(r,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){let i=e.charCodeAt(0);this._executeHandlers[i]=t,i<24&&(this._executeHandlersArr[i]=t)}clearExecuteHandler(e){let t=e.charCodeAt(0);this._executeHandlers[t]&&delete this._executeHandlers[t],t<24&&(this._executeHandlersArr[t]=void 0)}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let i=this._identifier(e);this._csiHandlers[i]??=[];let s=this._csiHandlers[i];return s.push(t),{dispose:()=>{let r=s.indexOf(t);r!==-1&&s.splice(r,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}registerApcHandler(e,t){return e.prefix=void 0,this._apcParser.registerHandler(this._identifier(e,[48,126]),t)}clearApcHandler(e){e.prefix=void 0,this._apcParser.clearHandler(this._identifier(e,[48,126]))}setApcHandlerFallback(e){this._apcParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._apcParser.reset(),this._params.resetZdm(),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,i,s,r){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=i,this._parseStack.transition=s,this._parseStack.chunkPos=r}parse(e,t,i){let s,r,n=0,o;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,n=this._parseStack.chunkPos+1;else{if(i===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");let h=this._parseStack.handlers,l=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(i===!1&&l>-1){for(;l>=0&&(o=h[l](this._params),o!==!0);l--)if(o instanceof Promise)return this._parseStack.handlerPos=l,o}this._parseStack.handlers=[];break;case 4:if(i===!1&&l>-1){for(;l>=0&&(o=h[l](),o!==!0);l--)if(o instanceof Promise)return this._parseStack.handlerPos=l,o}this._parseStack.handlers=[];break;case 6:if(s=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.resetZdm(),this._collect=0;break;case 5:if(s=e[this._parseStack.chunkPos],o=this._oscParser.end(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.resetZdm(),this._collect=0;break;case 7:if(s=e[this._parseStack.chunkPos],o=this._apcParser.end(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.resetZdm(),this._collect=0;break}this._parseStack.state=0,n=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&255}for(let h=n;h=60&&a<=63&&(this._collect=a,l++);let c=!1;for(;l=48&&a<=57)this._params.addDigit(a-48);else if(a===59)this._params.addParam(0);else if(a===58)this._params.addSubParam(-1);else if(a>=64&&a<=126){let d=this._csiHandlers[this._collect<<8|a],u=d?d.length-1:-1;for(;u>=0&&(o=d[u](this._params),o!==!0);u--)if(o instanceof Promise)return r=1792,this._preserveStack(3,d,u,r,l),o;u<0&&this._csiHandlerFb(this._collect<<8|a,this._params),this.precedingJoinState=0,h=l,this.currentState=0,c=!0;break}else break;c||(h=l-1,this.currentState=4);continue}switch(r=this._transitions.table[this.currentState<<8|(s>8){case 2:let l=h,a=t-4;for(;l=32&&(e[l]<=126||e[l]>=re)&&e[++l]>=32&&(e[l]<=126||e[l]>=re)&&e[++l]>=32&&(e[l]<=126||e[l]>=re)&&e[++l]>=32&&(e[l]<=126||e[l]>=re););if(l>=a)for(;l=32&&(e[l]<=126||e[l]>=re);)l++;this._printHandler(e,h,l),h=l-1;break;case 3:this._executeHandlers[s]?this._executeHandlers[s]():this._executeHandlerFb(s),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:h,code:s,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let c=this._csiHandlers[this._collect<<8|s],d=c?c.length-1:-1;for(;d>=0&&(o=c[d](this._params),o!==!0);d--)if(o instanceof Promise)return this._preserveStack(3,c,d,r,h),o;d<0&&this._csiHandlerFb(this._collect<<8|s,this._params),this.precedingJoinState=0;break;case 8:do switch(s){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(s-48)}while(++h47&&s<60);h--;break;case 9:this._collect<<=8,this._collect|=s;break;case 10:let u=this._escHandlers[this._collect<<8|s],f=u?u.length-1:-1;for(;f>=0&&(o=u[f](),o!==!0);f--)if(o instanceof Promise)return this._preserveStack(4,u,f,r,h),o;f<0&&this._escHandlerFb(this._collect<<8|s),this.precedingJoinState=0;break;case 11:this._params.resetZdm(),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|s,this._params);break;case 13:for(let _=h+1;;++_)if(_>=t||(s=e[_])===24||s===26||s===27||s>127&&s=t||(s=e[_])<32||s>127&&s=32&&e[_]<127||e[_]>=8&&e[_]<14||e[_]>=re))){this._apcParser.put(e,h,_),h=_-1;break}break;case 17:if(o=this._apcParser.end(s!==24&&s!==26),o)return this._preserveStack(7,[],0,r,h),o;s===27&&(r|=1),this._params.resetZdm(),this._collect=0,this.precedingJoinState=0;break}this.currentState=r&255}}},Na=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,Ha=/^[\da-f]+$/;function ir(e){if(!e)return;let t=e.toLowerCase();if(t.startsWith("rgb:")){t=t.slice(4);let i=Na.exec(t);if(i){let s=i[1]?15:i[4]?255:i[7]?4095:65535;return[Math.round(parseInt(i[1]||i[4]||i[7]||i[10],16)/s*255),Math.round(parseInt(i[2]||i[5]||i[8]||i[11],16)/s*255),Math.round(parseInt(i[3]||i[6]||i[9]||i[12],16)/s*255)]}}else if(t.startsWith("#")&&(t=t.slice(1),Ha.exec(t)&&[3,6,9,12].includes(t.length))){let i=t.length/3,s=[0,0,0];for(let r=0;r<3;++r){let n=parseInt(t.slice(i*r,i*r+i),16);s[r]=i===1?n<<4:i===2?n:i===3?n>>4:n>>8}return s}}function gi(e,t){let i=e.toString(16),s=i.length<2?"0"+i:i;switch(t){case 4:return i[0];case 8:return s;case 12:return(s+s).slice(0,3);default:return s+s}}function Fa(e,t=16){let[i,s,r]=e;return`rgb:${gi(i,t)}/${gi(s,t)}/${gi(r,t)}`}var Wa="6.1.0-beta.292",za={"(":0,")":1,"*":2,"+":3,"-":1,".":2};function sr(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var rr=0,Ka=class extends L{constructor(e,t,i,s,r,n,o,h,l=new Ia){super(),this._bufferService=e,this._charsetService=t,this._coreService=i,this._logService=s,this._optionsService=r,this._oscLinkService=n,this._mouseStateService=o,this._unicodeService=h,this._parser=l,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new Un,this._utf8Decoder=new qn,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=j.clone(),this._eraseAttrDataInternal=j.clone(),this._onRequestBell=this._register(new y),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new y),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new y),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new y),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new y),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new y),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new y),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new y),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new y),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new y),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new y),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new y),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new y),this.onColor=this._onColor.event,this._onRequestColorSchemeQuery=this._register(new y),this.onRequestColorSchemeQuery=this._onRequestColorSchemeQuery.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new zi(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(a=>this._activeBuffer=a.activeBuffer)),this._parser.setCsiHandlerFallback((a,c)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(a),params:c.toArray()})}),this._parser.setEscHandlerFallback(a=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(a)})}),this._parser.setExecuteHandlerFallback(a=>{this._logService.debug("Unknown EXECUTE code: ",{code:a})}),this._parser.setOscHandlerFallback((a,c,d)=>{this._logService.debug("Unknown OSC code: ",{identifier:a,action:c,data:d})}),this._parser.setDcsHandlerFallback((a,c,d)=>{c==="HOOK"&&(d=d.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(a),action:c,payload:d})}),this._parser.setApcHandlerFallback((a,c,d)=>{this._logService.debug("Unknown APC code: ",{identifier:this._parser.identToString(a),action:c,payload:d})}),this._parser.setPrintHandler((a,c,d)=>this.print(a,c,d)),this._parser.registerCsiHandler({final:"@"},a=>this.insertChars(a)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},a=>this.scrollLeft(a)),this._parser.registerCsiHandler({final:"A"},a=>this.cursorUp(a)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},a=>this.scrollRight(a)),this._parser.registerCsiHandler({final:"B"},a=>this.cursorDown(a)),this._parser.registerCsiHandler({final:"C"},a=>this.cursorForward(a)),this._parser.registerCsiHandler({final:"D"},a=>this.cursorBackward(a)),this._parser.registerCsiHandler({final:"E"},a=>this.cursorNextLine(a)),this._parser.registerCsiHandler({final:"F"},a=>this.cursorPrecedingLine(a)),this._parser.registerCsiHandler({final:"G"},a=>this.cursorCharAbsolute(a)),this._parser.registerCsiHandler({final:"H"},a=>this.cursorPosition(a)),this._parser.registerCsiHandler({final:"I"},a=>this.cursorForwardTab(a)),this._parser.registerCsiHandler({final:"J"},a=>this.eraseInDisplay(a,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},a=>this.eraseInDisplay(a,!0)),this._parser.registerCsiHandler({final:"K"},a=>this.eraseInLine(a,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},a=>this.eraseInLine(a,!0)),this._parser.registerCsiHandler({final:"L"},a=>this.insertLines(a)),this._parser.registerCsiHandler({final:"M"},a=>this.deleteLines(a)),this._parser.registerCsiHandler({final:"P"},a=>this.deleteChars(a)),this._parser.registerCsiHandler({final:"S"},a=>this.scrollUp(a)),this._parser.registerCsiHandler({final:"T"},a=>this.scrollDown(a)),this._parser.registerCsiHandler({final:"X"},a=>this.eraseChars(a)),this._parser.registerCsiHandler({final:"Z"},a=>this.cursorBackwardTab(a)),this._parser.registerCsiHandler({final:"^"},a=>this.scrollDown(a)),this._parser.registerCsiHandler({final:"`"},a=>this.charPosAbsolute(a)),this._parser.registerCsiHandler({final:"a"},a=>this.hPositionRelative(a)),this._parser.registerCsiHandler({final:"b"},a=>this.repeatPrecedingCharacter(a)),this._parser.registerCsiHandler({final:"c"},a=>this.sendDeviceAttributesPrimary(a)),this._parser.registerCsiHandler({prefix:">",final:"c"},a=>this.sendDeviceAttributesSecondary(a)),this._parser.registerCsiHandler({final:"d"},a=>this.linePosAbsolute(a)),this._parser.registerCsiHandler({final:"e"},a=>this.vPositionRelative(a)),this._parser.registerCsiHandler({final:"f"},a=>this.hVPosition(a)),this._parser.registerCsiHandler({final:"g"},a=>this.tabClear(a)),this._parser.registerCsiHandler({final:"h"},a=>this.setMode(a)),this._parser.registerCsiHandler({prefix:"?",final:"h"},a=>this.setModePrivate(a)),this._parser.registerCsiHandler({final:"l"},a=>this.resetMode(a)),this._parser.registerCsiHandler({prefix:"?",final:"l"},a=>this.resetModePrivate(a)),this._parser.registerCsiHandler({final:"m"},a=>this.charAttributes(a)),this._parser.registerCsiHandler({final:"n"},a=>this.deviceStatus(a)),this._parser.registerCsiHandler({prefix:"?",final:"n"},a=>this.deviceStatusPrivate(a)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},a=>this.softReset(a)),this._parser.registerCsiHandler({prefix:">",final:"q"},a=>this.sendXtVersion(a)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},a=>this.setCursorStyle(a)),this._parser.registerCsiHandler({final:"r"},a=>this.setScrollRegion(a)),this._parser.registerCsiHandler({final:"s"},a=>this.saveCursor(a)),this._parser.registerCsiHandler({final:"t"},a=>this.windowOptions(a)),this._parser.registerCsiHandler({final:"u"},a=>this.restoreCursor(a)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},a=>this.insertColumns(a)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},a=>this.deleteColumns(a)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},a=>this.selectProtected(a)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},a=>this.requestMode(a,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},a=>this.requestMode(a,!1)),this._parser.registerCsiHandler({prefix:"=",final:"u"},a=>this.kittyKeyboardSet(a)),this._parser.registerCsiHandler({prefix:"?",final:"u"},a=>this.kittyKeyboardQuery(a)),this._parser.registerCsiHandler({prefix:">",final:"u"},a=>this.kittyKeyboardPush(a)),this._parser.registerCsiHandler({prefix:"<",final:"u"},a=>this.kittyKeyboardPop(a)),this._parser.setExecuteHandler("\x07",()=>this.bell()),this._parser.setExecuteHandler(` +`,()=>this.lineFeed()),this._parser.setExecuteHandler("\v",()=>this.lineFeed()),this._parser.setExecuteHandler("\f",()=>this.lineFeed()),this._parser.setExecuteHandler("\r",()=>this.carriageReturn()),this._parser.setExecuteHandler("\b",()=>this.backspace()),this._parser.setExecuteHandler(" ",()=>this.tab()),this._parser.setExecuteHandler("",()=>this.shiftOut()),this._parser.setExecuteHandler("",()=>this.shiftIn()),this._parser.setExecuteHandler("\x84",()=>this.index()),this._parser.setExecuteHandler("\x85",()=>this.nextLine()),this._parser.setExecuteHandler("\x88",()=>this.tabSet()),this._parser.registerOscHandler(0,new de(a=>(this.setTitle(a),this.setIconName(a),!0))),this._parser.registerOscHandler(1,new de(a=>this.setIconName(a))),this._parser.registerOscHandler(2,new de(a=>this.setTitle(a))),this._parser.registerOscHandler(4,new de(a=>this.setOrReportIndexedColor(a))),this._parser.registerOscHandler(8,new de(a=>this.setHyperlink(a))),this._parser.registerOscHandler(10,new de(a=>this.setOrReportFgColor(a))),this._parser.registerOscHandler(11,new de(a=>this.setOrReportBgColor(a))),this._parser.registerOscHandler(12,new de(a=>this.setOrReportCursorColor(a))),this._parser.registerOscHandler(104,new de(a=>this.restoreIndexedColor(a))),this._parser.registerOscHandler(110,new de(a=>this.restoreFgColor(a))),this._parser.registerOscHandler(111,new de(a=>this.restoreBgColor(a))),this._parser.registerOscHandler(112,new de(a=>this.restoreCursorColor(a))),this._parser.registerEscHandler({final:"7"},()=>this.saveCursor()),this._parser.registerEscHandler({final:"8"},()=>this.restoreCursor()),this._parser.registerEscHandler({final:"D"},()=>this.index()),this._parser.registerEscHandler({final:"E"},()=>this.nextLine()),this._parser.registerEscHandler({final:"H"},()=>this.tabSet()),this._parser.registerEscHandler({final:"M"},()=>this.reverseIndex()),this._parser.registerEscHandler({final:"="},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:">"},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:"c"},()=>this.fullReset()),this._parser.registerEscHandler({final:"n"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"o"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"|"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"}"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"~"},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:"%",final:"@"},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:"%",final:"G"},()=>this.selectDefaultCharset());for(let a in G)this._parser.registerEscHandler({intermediates:"(",final:a},()=>this.selectCharset("("+a)),this._parser.registerEscHandler({intermediates:")",final:a},()=>this.selectCharset(")"+a)),this._parser.registerEscHandler({intermediates:"*",final:a},()=>this.selectCharset("*"+a)),this._parser.registerEscHandler({intermediates:"+",final:a},()=>this.selectCharset("+"+a)),this._parser.registerEscHandler({intermediates:"-",final:a},()=>this.selectCharset("-"+a)),this._parser.registerEscHandler({intermediates:".",final:a},()=>this.selectCharset("."+a)),this._parser.registerEscHandler({intermediates:"/",final:a},()=>this.selectCharset("/"+a));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(a=>(this._logService.error("Parsing error: ",a),a)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new tr((a,c)=>this.requestStatusString(a,c)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,i,s){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=i,this._parseStack.position=s}_logSlowResolvingAsync(e){if(this._logService.logLevel<=3){let t,i=new Promise((s,r)=>{t=setTimeout(()=>r("#SLOW_TIMEOUT"),5e3)});Promise.race([e,i]).then(()=>{t!==void 0&&clearTimeout(t)},s=>{if(t!==void 0&&clearTimeout(t),s!=="#SLOW_TIMEOUT")throw s;console.warn("async parser handler taking longer than 5000 ms")})}}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let i,s=this._activeBuffer.x,r=this._activeBuffer.y,n=0,o=this._parseStack.paused;if(o){if(i=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(i),i;s=this._parseStack.cursorStartX,r=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>131072&&(n=this._parseStack.position+131072)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e=="string"?` "${e}"`:` "${Array.prototype.map.call(e,a=>String.fromCharCode(a)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof e=="string"?e.split("").map(a=>a.charCodeAt(0)):e),this._parseBuffer.length131072)for(let a=n;a0&&d.getWidth(this._activeBuffer.x-1)===2&&d.setCellFromCodepoint(this._activeBuffer.x-1,0,1,c);let u=this._parser.precedingJoinState;for(let f=t;fh){if(l){let R=d,E=this._activeBuffer.x-S;if(this._activeBuffer.x=S,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),!d)return;for(S>0&&d instanceof ct&&d.copyCellsFrom(R,E,0,S,!1);E=0;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,c);continue}if(a&&(d.insertCells(this._activeBuffer.x,r-S,this._activeBuffer.getNullCell(c)),d.getWidth(h-1)===2&&d.setCellFromCodepoint(h-1,0,1,c)),d.setCellFromCodepoint(this._activeBuffer.x++,s,r,c),r>0)for(;--r;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,c)}this._parser.precedingJoinState=u,this._activeBuffer.x0&&d.getWidth(this._activeBuffer.x)===0&&!d.hasContent(this._activeBuffer.x)&&d.setCellFromCodepoint(this._activeBuffer.x,0,1,c),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final==="t"&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,i=>sr(i.params[0],this._optionsService.rawOptions.windowOptions)?t(i):!0):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new tr(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new de(t))}registerApcHandler(e,t){return this._parser.registerApcHandler(e,new Pa(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,i,s=!1,r=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.replaceCells(t,i,this._activeBuffer.getNullCell(this._eraseAttrData()),r),s&&(n.isWrapped=!1))}_resetBufferLine(e,t=!1){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);i&&(i.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),i.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let i;switch(e.params[0]){case 0:for(i=this._activeBuffer.y,this._dirtyRowTracker.markDirty(i),this._eraseInBufferLine(i++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);i=this._bufferService.cols){let r=this._activeBuffer.lines.get(i+1);r&&(r.isWrapped=!1)}for(;i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(i=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,i-1);i--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+i)?.getTrimmedLength(););for(;i>=0;i--)this._bufferService.scroll(this._eraseAttrData())}else{for(i=this._bufferService.rows,this._dirtyRowTracker.markDirty(i-1);i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let s=this._activeBuffer.lines.length-this._bufferService.rows;s>0&&(this._activeBuffer.lines.trimStart(s),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-s,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-s,0),this._onScroll.fire(0));break}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.ythis._activeBuffer.scrollBottom||this._activeBuffer.y65535?2:1}let l=h;for(let a=1;a0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent("\x1B[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent("\x1B[?6c")),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent("\x1B[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent("\x1B[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(e.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent("\x1B[>83;40003;0c")),!0}sendXtVersion(e){return e.params[0]>0||this._coreService.triggerDataEvent(`\x1BP>|xterm.js(${Wa})\x1B\\`),!0}_is(e){return(this._optionsService.rawOptions.termName+"").startsWith(e)}setMode(e){for(let t=0;t(p[p.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",p[p.SET=1]="SET",p[p.RESET=2]="RESET",p[p.PERMANENTLY_SET=3]="PERMANENTLY_SET",p[p.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(i||={});let s=this._coreService.decPrivateModes,{activeProtocol:r,activeEncoding:n}=this._mouseStateService,o=this._coreService,{buffers:h,cols:l}=this._bufferService,{active:a,alt:c}=h,d=this._optionsService.rawOptions,u=(p,S)=>(o.triggerDataEvent(`\x1B[${t?"":"?"}${p};${S}$y`),!0),f=p=>p?1:2,_=e.params[0];return t?_===2?u(_,4):_===4?u(_,f(o.modes.insertMode)):_===12?u(_,3):_===20?u(_,f(d.convertEol)):u(_,0):_===1?u(_,f(s.applicationCursorKeys)):_===3?u(_,d.windowOptions.setWinLines?l===80?2:l===132?1:0:0):_===6?u(_,f(s.origin)):_===7?u(_,f(s.wraparound)):_===8?u(_,3):_===9?u(_,f(r==="X10")):_===12?u(_,f(d.cursorBlink)):_===25?u(_,f(!o.isCursorHidden)):_===45?u(_,f(s.reverseWraparound)):_===66?u(_,f(s.applicationKeypad)):_===67?u(_,4):_===1e3?u(_,f(r==="VT200")):_===1002?u(_,f(r==="DRAG")):_===1003?u(_,f(r==="ANY")):_===1004?u(_,f(s.sendFocus)):_===1005?u(_,4):_===1006?u(_,f(n==="SGR")):_===1015?u(_,4):_===1016?u(_,f(n==="SGR_PIXELS")):_===1048?u(_,1):_===47||_===1047||_===1049?u(_,f(a===c)):_===2004?u(_,f(s.bracketedPasteMode)):_===2026?u(_,f(s.synchronizedOutput)):_===9001&&this._optionsService.rawOptions.vtExtensions?.win32InputMode?u(_,f(s.win32InputMode)):u(_,0)}_updateAttrColor(e,t,i,s,r){return t===2?(e|=50331648,e&=-16777216,e|=vt.fromColorRGB([i,s,r])):t===5&&(e&=-67108864,e|=33554432|i&255),e}_extractColor(e,t,i){let s=[0,0,-1,0,0,0],r=0,n=0;do{if(s[n+r]=e.params[t+n],e.hasSubParams(t+n)){let o=e.getSubParams(t+n),h=0;do s[1]===5&&(r=1),s[n+h+1+r]=o[h];while(++h=2||s[1]===2&&n+r>=5)break;s[1]&&(r=1)}while(++n+t5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=j.fg,e.bg=j.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,i,s=this._curAttrData;for(let r=0;r=30&&i<=37?(s.fg&=-67108864,s.fg|=16777216|i-30):i>=40&&i<=47?(s.bg&=-67108864,s.bg|=16777216|i-40):i>=90&&i<=97?(s.fg&=-67108864,s.fg|=16777216|i-90|8):i>=100&&i<=107?(s.bg&=-67108864,s.bg|=16777216|i-100|8):i===0?this._processSGR0(s):i===1?s.fg|=134217728:i===3?s.bg|=67108864:i===4?(s.fg|=268435456,this._processUnderline(e.hasSubParams(r)?e.getSubParams(r)[0]:1,s)):i===5?s.fg|=536870912:i===7?s.fg|=67108864:i===8?s.fg|=1073741824:i===9?s.fg|=2147483648:i===2?s.bg|=134217728:i===21?this._processUnderline(2,s):i===22?(s.fg&=-134217729,s.bg&=-134217729):i===23?s.bg&=-67108865:i===24?(s.fg&=-268435457,this._processUnderline(0,s)):i===25?s.fg&=-536870913:i===27?s.fg&=-67108865:i===28?s.fg&=-1073741825:i===29?s.fg&=2147483647:i===39?(s.fg&=-67108864,s.fg|=j.fg&16777215):i===49?(s.bg&=-67108864,s.bg|=j.bg&16777215):i===38||i===48||i===58?r+=this._extractColor(e,r,s):i===53?s.bg|=1073741824:i===55?s.bg&=-1073741825:i===221&&(this._optionsService.rawOptions.vtExtensions?.kittySgrBoldFaintControl??!0)?s.fg&=-134217729:i===222&&(this._optionsService.rawOptions.vtExtensions?.kittySgrBoldFaintControl??!0)?s.bg&=-134217729:i===59?(s.extended=s.extended.clone(),s.extended.underlineColor=-1,s.updateExtended()):this._logService.debug("Unknown SGR attribute: %d.",i);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent("\x1B[0n");break;case 6:let t=this._activeBuffer.y+1,i=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`\x1B[${t};${i}R`);break}return!0}deviceStatusPrivate(e){switch(e.params[0]){case 6:let t=this._activeBuffer.y+1,i=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`\x1B[?${t};${i}R`);break;case 15:break;case 25:break;case 26:break;case 53:break;case 996:(this._optionsService.rawOptions.vtExtensions?.colorSchemeQuery??!0)&&this._onRequestColorSchemeQuery.fire();break}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=j.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle="block";break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle="underline";break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle="bar";break}let i=t%2===1;this._coreService.decPrivateModes.cursorBlink=i}return!0}setScrollRegion(e){let t=e.params[0]||1,i;return(e.length<2||(i=e.params[1])>this._bufferService.rows||i===0)&&(i=this._bufferService.rows),i>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=i-1,this._setCursor(0,0)),!0}windowOptions(e){if(!sr(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`\x1B[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>10&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>10&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._activeBuffer.savedCharsets=this._charsetService.charsets.slice(),this._activeBuffer.savedGlevel=this._charsetService.glevel,this._activeBuffer.savedOriginMode=this._coreService.decPrivateModes.origin,this._activeBuffer.savedWraparoundMode=this._coreService.decPrivateModes.wraparound,!0}restoreCursor(e){this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg;for(let t=0;t1;){let s=i.shift(),r=i.shift();if(/^\d+$/.exec(s)){let n=parseInt(s,10);if(nr(n))if(r==="?")t.push({type:0,index:n});else{let o=ir(r);o&&t.push({type:1,index:n,color:o})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(";");if(t===-1)return!0;let i=e.slice(0,t).trim(),s=e.slice(t+1);return s?this._createHyperlink(i,s):i.trim()?!1:this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let i=e.split(":"),s,r=i.findIndex(n=>n.startsWith("id="));return r!==-1&&(s=i[r].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:s,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let i=e.split(";");for(let s=0;s=this._specialColors.length);++s,++t)if(i[s]==="?")this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=ir(i[s]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],i=e.split(";");for(let s=0;s=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=j.clone(),this._eraseAttrDataInternal=j.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new ge;e.content=1<<22|69,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t(this._coreService.triggerDataEvent(`\x1B${o}\x1B\\`),!0),s=this._bufferService.buffer,r=this._optionsService.rawOptions;return i(e==='"q'?`P1$r${this._curAttrData.isProtected()?1:0}"q`:e==='"p'?'P1$r61;1"p':e==="r"?`P1$r${s.scrollTop+1};${s.scrollBottom+1}r`:e==="m"?"P1$r0m":e===" q"?`P1$r${{block:2,underline:4,bar:6}[r.cursorStyle]-(r.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}kittyKeyboardSet(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=e.params[0]||0,i=e.length>1&&e.params[1]||1,s=this._coreService.kittyKeyboard;switch(i){case 1:s.flags=t;break;case 2:s.flags|=t;break;case 3:s.flags&=~t;break}return!0}kittyKeyboardQuery(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=this._coreService.kittyKeyboard.flags;return this._coreService.triggerDataEvent(`\x1B[?${t}u`),!0}kittyKeyboardPush(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=e.params[0]||0,i=this._coreService.kittyKeyboard,s=this._bufferService.buffer===this._bufferService.buffers.alt?i.altStack:i.mainStack;return s.length>=16&&s.shift(),s.push(i.flags),i.flags=t,!0}kittyKeyboardPop(e){if(!this._optionsService.rawOptions.vtExtensions?.kittyKeyboard)return!0;let t=Math.max(1,e.params[0]||1),i=this._coreService.kittyKeyboard,s=this._bufferService.buffer===this._bufferService.buffers.alt?i.altStack:i.mainStack;for(let r=0;r0;r++)i.flags=s.pop();return s.length===0&&t>0&&(i.flags=0),!0}},zi=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){ethis.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(rr=e,e=t,t=rr),ethis.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};zi=F([g(0,ne)],zi);function nr(e){return 0<=e&&e<256}var $a=class extends L{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._innerWriteTimer=this._register(new Kt),this._onWriteParsed=this._register(new y),this.onWriteParsed=this._onWriteParsed.event,this._register(O(()=>{this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0}))}handleUserInput(){this._didUserInput=!0}flushSync(){if(this._store.isDisposed||this._isSyncWriting)return;this._isSyncWriting=!0;let e,t=!1;for(;e=this._writeBuffer.shift();){t=!0,this._action(e);let i=this._callbacks.shift();i&&i()}this._pendingData=0,this._bufferOffset=2147483647,this._writeBuffer.length=0,this._callbacks.length=0,this._isSyncWriting=!1,t&&this._onWriteParsed.fire()}writeSync(e,t){if(this._store.isDisposed)return;if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let i;for(;i=this._writeBuffer.shift();){this._action(i);let s=this._callbacks.shift();s&&s()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(!this._store.isDisposed){if(this._pendingData>5e7)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}this._scheduleInnerWrite()}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}}_scheduleInnerWrite(e=0,t=!0){this._store.isDisposed||this._innerWriteTimer.cancelAndSet(()=>this._innerWrite(e,t),0)}_innerWrite(e=0,t=!0){if(this._store.isDisposed)return;let i=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let s=this._writeBuffer[this._bufferOffset],r=this._action(s,t);if(r){let o=h=>{this._store.isDisposed||(performance.now()-i>=12?this._scheduleInnerWrite(0,h):this._innerWrite(i,h))};r.catch(h=>(queueMicrotask(()=>{throw h}),Promise.resolve(!1))).then(o);return}let n=this._callbacks[this._bufferOffset];if(n&&n(),this._bufferOffset++,this._pendingData-=s.length,performance.now()-i>=12)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>50&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),this._scheduleInnerWrite()):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},Ki=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let h=t.addMarker(t.ybase+t.y),l={data:e,id:this._nextId++,lines:[h]};return h.onDispose(()=>this._removeMarkerFromLink(l,h)),this._dataByLinkId.set(l.id,l),l.id}let i=e,s=this._getEntryIdKey(i),r=this._entriesWithId.get(s);if(r)return this.addLineToLink(r.id,t.ybase+t.y),r.id;let n=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(i),data:i,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(o,n)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let i=this._dataByLinkId.get(e);if(i&&i.lines.every(s=>s.line!==t)){let s=this._bufferService.buffer.addMarker(t);i.lines.push(s),s.onDispose(()=>this._removeMarkerFromLink(i,s))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let i=e.lines.indexOf(t);i!==-1&&(e.lines.splice(i,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};Ki=F([g(0,ne)],Ki);var or=!1,Ua=class extends L{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new le),this._onBinary=this._register(new y),this.onBinary=this._onBinary.event,this._onData=this._register(new y),this.onData=this._onData.event,this._onLineFeed=this._register(new y),this.onLineFeed=this._onLineFeed.event,this._onRender=this._register(new y),this.onRender=this._onRender.event,this._onResize=this._register(new y),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new y),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new y),this._instantiationService=new _a,this.optionsService=this._register(new Ca(e)),this._instantiationService.setService(oe,this.optionsService),this._logService=this._register(this._instantiationService.createInstance(Ni)),this._instantiationService.setService(Je,this._logService),this._bufferService=this._register(this._instantiationService.createInstance(Hi)),this._instantiationService.setService(ne,this._bufferService),this.coreService=this._register(this._instantiationService.createInstance(Fi)),this._instantiationService.setService(De,this.coreService),this.mouseStateService=this._register(this._instantiationService.createInstance(xa)),this._instantiationService.setService(Ft,this.mouseStateService),this.unicodeService=this._register(this._instantiationService.createInstance(Ke)),this.unicodeService.register(new Da),this._instantiationService.setService(jn,this.unicodeService),this._charsetService=this._instantiationService.createInstance(Ma),this._instantiationService.setService(Xn,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(Ki),this._instantiationService.setService(pr,this._oscLinkService),this._inputHandler=this._register(new Ka(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.mouseStateService,this.unicodeService)),this._register(he.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(he.forward(this._bufferService.onResize,this._onResize)),this._register(he.forward(this.coreService.onData,this._onData)),this._register(he.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange(["windowsPty"],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new $a((t,i)=>this._inputHandler.parse(t,i))),this._register(he.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new y),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!or&&(this._logService.warn("writeSync is unreliable and will be removed soon."),or=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,2),t=Math.max(t,1),this._writeBuffer.flushSync(),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}registerApcHandler(e,t){return this._inputHandler.registerApcHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.mouseStateService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.backend!==void 0&&t.buildNumber!==void 0&&(e=t.backend==="conpty"&&t.buildNumber<21376),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(er.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:"H"},()=>(er(this._bufferService),!1))),this._windowsWrappingHeuristics.value=O(()=>{for(let t of e)t.dispose()})}}},K=0,qa=class{constructor(e,t){this._getKey=e,this._array=[],this._insertedValues=[],this._isFlushingInserted=!1,this._deletedIndices=[],this._isFlushingDeleted=!1,this._flushInsertedTask=new Nt(t),this._flushDeletedTask=new Nt(t)}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((r,n)=>this._getKey(r)-this._getKey(n)),t=0,i=0,s=new Array(this._array.length+this._insertedValues.length);for(let r=0;r=this._array.length||this._getKey(e[t])<=this._getKey(this._array[i])?(s[r]=e[t],t++):s[r]=this._array[i++];this._array=s,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(K=this._search(t),K===-1)||this._getKey(this._array[K])!==t)return!1;do if(this._array[K]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(K),!0;while(++Kr-n),t=0,i=new Array(this._array.length-e.length),s=0;for(let r=0;r0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(K=this._search(e),!(K<0||K>=this._array.length)&&this._getKey(this._array[K])===e))do yield this._array[K];while(++K=this._array.length)&&this._getKey(this._array[K])===e))do t(this._array[K]);while(++K=t;){let s=t+i>>1,r=this._getKey(this._array[s]);if(r>e)i=s-1;else if(r0&&this._getKey(this._array[s-1])===e;)s--;return s}}return t}},je=0,Mt=0,$i=class extends L{constructor(e,t){super(),this._logService=e,this._bufferService=t,this._lineCache=this._register(new Va),this._onDecorationRegistered=this._register(new y),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new y),this.onDecorationRemoved=this._onDecorationRemoved.event,this._decorations=new qa(i=>i?.marker.line,this._logService),this._register(O(()=>this.reset())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._lineCache.attachToBufferLines(this._bufferService.buffer.lines)})),this._lineCache.attachToBufferLines(this._bufferService.buffer.lines)}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new Ya(e);if(t){let i=t.marker.onDispose(()=>t.dispose()),s=t.onDispose(()=>{s.dispose(),t&&(this._decorations.delete(t)&&(this._lineCache.remove(t),this._onDecorationRemoved.fire(t)),i.dispose())});this._decorations.insert(t),this._lineCache.add(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear(),this._lineCache.clear()}*getDecorationsAtCell(e,t,i){let s=this._lineCache.getDecorationsOnLine(t);if(s)for(let r of s)je=r.options.x??0,Mt=je+(r.options.width??1),e>=je&&e=je&&ethis._handleBufferLinesTrim(i))),t.add(e.onInsert(i=>this._handleBufferLinesInsert(i))),t.add(e.onDelete(i=>this._handleBufferLinesDelete(i)))}_getDecorationHeight(e){return e.options.height??1}_addToLineBuckets(e){let t=e.marker.line;if(t<0)return;e._indexedStartLine=t;let i=this._getDecorationHeight(e);for(let s=t;s=0&&this._addToLineBuckets(e)}_scheduleLineIndexSync(e){this._lineIndexSyncCallbacks.push(e),this._lineIndexSyncTimer.set(()=>{let t=this._lineIndexSyncCallbacks;this._lineIndexSyncCallbacks=[];for(let i of t)i()})}_handleBufferLinesTrim(e){if(e<=0)return;let t=new Map;for(let[i,s]of this._decorationsByLine){let r=i-e;r<0||this._mergeLineBucket(t,r,s)}this._decorationsByLine.clear();for(let[i,s]of t)this._decorationsByLine.set(i,s);for(let i of this._decorations)i.marker.isDisposed||(i._indexedStartLine-=e)}_handleBufferLinesInsert(e){this._scheduleLineIndexSync(()=>this._applyBufferLinesInsert(e))}_handleBufferLinesDelete(e){this._scheduleLineIndexSync(()=>this._applyBufferLinesDelete(e))}_mergeLineBucket(e,t,i){let s=e.get(t);if(s)for(let r=0,n=i.length;rt&&(s.push(n),this._removeFromLineBuckets(n))}let r=new Map;for(let[n,o]of this._decorationsByLine){let h=n>=t?n+i:n;this._mergeLineBucket(r,h,o)}this._decorationsByLine.clear();for(let[n,o]of r)this._decorationsByLine.set(n,o);for(let n of this._decorations)n.marker.isDisposed||n._indexedStartLine>=t&&(n._indexedStartLine=n.marker.line);for(let n of s)this._addToLineBuckets(n)}_applyBufferLinesDelete(e){let t=e.index+e.amount,i=new Map;for(let[r,n]of this._decorationsByLine){if(r>=e.index&&r=t?r-e.amount:r;this._mergeLineBucket(i,o,n)}this._decorationsByLine.clear();for(let[r,n]of i)this._decorationsByLine.set(r,n);let s=[];for(let r of this._decorations){if(r.marker.isDisposed)continue;let n=r._indexedStartLine,o=this._getDecorationHeight(r);n>=t?r._indexedStartLine=r.marker.line:nt&&s.push(r)}for(let r of s)this._reindexDecoration(r)}},Ya=class extends Qe{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new y),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new y),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this._indexedStartLine=e.marker.line,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=W.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=W.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},Xa=1e3,ja=class{constructor(e,t=Xa){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&(clearTimeout(this._refreshTimeoutID),this._refreshTimeoutID=void 0),this._additionalRefreshRequested=!1}refresh(e,t,i){this._rowCount=i,e=e??0,t=t??this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t;let s=performance.now();if(s-this._lastRefreshMs>=this._debounceThresholdMS)this._refreshTimeoutID!==void 0&&(clearTimeout(this._refreshTimeoutID),this._refreshTimeoutID=void 0,this._additionalRefreshRequested=!1),this._lastRefreshMs=s,this._innerRefresh();else if(!this._additionalRefreshRequested){let r=s-this._lastRefreshMs,n=this._debounceThresholdMS-r;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},n)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},ar=!1,Ht=class extends L{constructor(e,t,i,s){super(),this._terminal=e,this._coreBrowserService=i,this._renderService=s,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="";let r=this._coreBrowserService.mainDocument;this._accessibilityContainer=r.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=r.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let n=0;nthis._handleBoundaryFocus(n,0),this._bottomBoundaryFocusListener=n=>this._handleBoundaryFocus(n,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=r.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new ja(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");ar?(this._accessibilityContainer.classList.add("debug"),this._rowContainer.classList.add("debug"),this._debugRootContainer=r.createElement("div"),this._debugRootContainer.classList.add("xterm"),this._debugRootContainer.appendChild(r.createTextNode("------start a11y------")),this._debugRootContainer.appendChild(this._accessibilityContainer),this._debugRootContainer.appendChild(r.createTextNode("------end a11y------")),this._terminal.element.insertAdjacentElement("afterend",this._debugRootContainer)):this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this._register(this._terminal.onResize(n=>this._handleResize(n.rows))),this._register(this._terminal.onRender(n=>this._refreshRows(n.start,n.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(n=>this._handleChar(n))),this._register(this._terminal.onLineFeed(()=>this._handleChar(` `))),this._register(this._terminal.onA11yTab(n=>this._handleTab(n))),this._register(this._terminal.onKey(n=>this._handleKey(n.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(D(r,"selectionchange",()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(O(()=>{ar?this._debugRootContainer.remove():this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===` `&&(this._liveRegionLineCount++,this._liveRegionLineCount===21&&(this._liveRegion.textContent=Tt.get())))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let i=this._terminal.buffer,s=i.lines.length.toString();for(let r=e;r<=t;r++){let n=i.lines.get(i.ydisp+r),o=[],h=n?.translateToString(!0,void 0,void 0,o)||"",l=(i.ydisp+r+1).toString(),a=this._rowElements[r];a&&(h.length===0?(a.textContent="\xA0",this._rowColumns.set(a,[0,1])):(a.textContent=h,this._rowColumns.set(a,o)),a.setAttribute("aria-posinset",l),a.setAttribute("aria-setsize",s),this._alignRowWidth(a))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent===Tt.get()&&this._clearLiveRegion(),this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){let i=e.target,s=this._rowElements[t===0?1:this._rowElements.length-2],r=i.getAttribute("aria-posinset"),n=t===0?"1":`${this._terminal.buffer.lines.length}`;if(r===n||e.relatedTarget!==s)return;let o,h;if(t===0?(o=i,h=this._rowElements.pop(),this._rowContainer.removeChild(h)):(o=this._rowElements.shift(),h=i,this._rowContainer.removeChild(o)),o.removeEventListener("focus",this._topBoundaryFocusListener),h.removeEventListener("focus",this._bottomBoundaryFocusListener),t===0){let l=this._createAccessibilityTreeNode();this._rowElements.unshift(l),this._rowContainer.insertAdjacentElement("afterbegin",l)}else{let l=this._createAccessibilityTreeNode();this._rowElements.push(l),this._rowContainer.appendChild(l)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error("anchorNode and/or focusNode are null");return}let t={node:e.anchorNode,offset:e.anchorOffset},i={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(i.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===i.node&&t.offset>i.offset)&&([t,i]=[i,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let s=this._rowElements.slice(-1)[0];if(i.node.compareDocumentPosition(s)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(i={node:s,offset:s.textContent?.length??0}),!this._rowContainer.contains(i.node))return;let r=({node:h,offset:l})=>{let a=h instanceof Text?h.parentNode:h,c=parseInt(a?.getAttribute("aria-posinset"),10)-1;if(isNaN(c))return console.warn("row is invalid. Race condition?"),null;let d=this._rowColumns.get(a);if(!d)return console.warn("columns is null. Race condition?"),null;let u=l=this._terminal.cols&&(++c,u=0),{row:c,column:u}},n=r(t),o=r(i);if(!(!n||!o)){if(n.row>o.row||n.row===o.row&&n.column>=o.column)throw new Error("invalid range");this._terminal.select(n.column,n.row,(o.row-n.row)*this._terminal.cols-n.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let t=this._rowContainer.children.length;te;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement("div");return e.setAttribute("role","listitem"),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e{ut(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(D(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(D(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(D(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(D(this._element,"mouseup",this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element);if(!t)return;this._isMouseOut=!1;let i=e.composedPath();for(let s=0;s{s?.forEach(r=>{r.link.dispose&&r.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let i=!1;for(let[s,r]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(s)&&(i=this._checkLinkProviderResult(s,e,i)):r.provideLinks(e.y,n=>{if(this._isMouseOut)return;let o=n?.map(h=>({link:h}));this._activeProviderReplies?.set(s,o),i=this._checkLinkProviderResult(s,e,i),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let i=new Set;for(let s=0;se?this._bufferService.cols:o.link.range.end.x;for(let a=h;a<=l;a++){if(i.has(a)){r.splice(n--,1);break}i.add(a)}}}}_checkLinkProviderResult(e,t,i){if(!this._activeProviderReplies)return i;let s=this._activeProviderReplies.get(e),r=!1;for(let n=0;nthis._linkAtPosition(o.link,t));n&&(i=!0,this._handleNewLink(n))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!i)for(let n=0;nthis._linkAtPosition(h.link,t));if(o){i=!0,this._handleNewLink(o);break}}return i}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element);t&&this._mouseDownLink&&Ga(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,ut(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0?!0:e.link.decorations.underline,pointerCursor:e.link.decorations===void 0?!0:e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:i=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==i&&(this._currentLink.state.decorations.pointerCursor=i,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",i))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:i=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==i&&(this._currentLink.state.decorations.underline=i,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,i))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(i=>{if(!this._currentLink)return;let s=i.start===0?0:i.start+1+this._bufferService.buffer.ydisp,r=this._bufferService.buffer.ydisp+1+i.end;if(this._currentLink.link.range.start.y>=s&&this._currentLink.link.range.end.y<=r&&(this._clearCurrentLink(s,r),this._lastMouseEvent)){let n=this._positionFromMouseEvent(this._lastMouseEvent,this._element);n&&this._askForLink(n,!1)}})))}_linkHover(e,t,i){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add("xterm-cursor-pointer")),t.hover&&t.hover(i,t.text)}_fireUnderlineEvent(e,t){let i=e.range,s=this._bufferService.buffer.ydisp,r=this._createLinkUnderlineEvent(i.start.x-1,i.start.y-s-1,i.end.x,i.end.y-s-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(r)}_linkLeave(e,t,i){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove("xterm-cursor-pointer")),t.leave&&t.leave(i,t.text)}_linkAtPosition(e,t){let i=e.range.start.y*this._bufferService.cols+e.range.start.x,s=e.range.end.y*this._bufferService.cols+e.range.end.x,r=t.y*this._bufferService.cols+t.x;return i<=r&&r<=s}_positionFromMouseEvent(e,t){let i=this._mouseCoordsService.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(i)return{x:i[0],y:i[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,i,s,r){return{x1:e,y1:t,x2:i,y2:s,cols:this._bufferService.cols,fg:r}}};Ui=F([g(1,zt),g(2,ye),g(3,ne),g(4,mr)],Ui);function Ga(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var Ja=class extends Ua{constructor(e={}){super(e),this._linkifier=this._register(new le),this.browser=br,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new le),this._onCursorMove=this._register(new y),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new y),this.onKey=this._onKey.event,this._onSelectionChange=this._register(new y),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new y),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new y),this.onBell=this._onBell.event,this._onFocus=this._register(new y),this._onBlur=this._register(new y),this._onA11yCharEmitter=this._register(new y),this._onA11yTabEmitter=this._register(new y),this._onWillOpen=this._register(new y),this._onDimensionsChange=this._register(new y),this.onDimensionsChange=this._onDimensionsChange.event,this._setup(),this._decorationService=this._instantiationService.createInstance($i),this._instantiationService.setService(mt,this._decorationService),this._keyboardService=this._instantiationService.createInstance(Ii),this._instantiationService.setService(Zn,this._keyboardService),this._linkProviderService=this._instantiationService.createInstance(zo),this._instantiationService.setService(mr,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Si)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(t=>this.refresh(t?.start??0,t?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(t=>this._reportWindowsOptions(t))),this._register(this._inputHandler.onColor(t=>this._handleColorEvent(t))),this._register(he.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(he.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(he.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(he.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(t=>this._afterResize(t.cols,t.rows))),this._register(O(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}get dimensions(){if(!this._renderService)return;let e=this._renderService.dimensions;return{css:{canvas:{...e.css.canvas},cell:{...e.css.cell}},device:{canvas:{...e.device.canvas},cell:{...e.device.cell},char:{...e.device.char}}}}_handleColorEvent(e){if(this._themeService)for(let t of e){let i,s;switch(t.index){case 256:i="foreground",s="10";break;case 257:i="background",s="11";break;case 258:i="cursor",s="12";break;default:i="ansi",s="4;"+t.index}switch(t.type){case 0:let r=H.toColorRGB(i==="ansi"?this._themeService.colors.ansi[t.index]:this._themeService.colors[i]);this.coreService.triggerDataEvent(`\x1B]${s};${Fa(r)}\x1B\\`);break;case 1:if(i==="ansi")this._themeService.modifyColors(n=>n.ansi[t.index]=$.toColor(...t.color));else{let n=i;this._themeService.modifyColors(o=>o[n]=$.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index);break}}}_reportColorScheme(){if(!this._themeService)return;let e=ie.relativeLuminance(this._themeService.colors.background.rgba>>8),t=ie.relativeLuminance(this._themeService.colors.foreground.rgba>>8),i=e{this.hasSelection()&&Kn(t,this._selectionService)}));let e=t=>$n(t,this.textarea,this.coreService,this.optionsService);this._register(D(this.textarea,"paste",e)),this._register(D(this.element,"paste",e)),At?this._register(D(this.element,"mousedown",t=>{t.button===2&&Ms(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(D(this.element,"contextmenu",t=>{Ms(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Ji&&this._register(D(this.element,"auxclick",t=>{t.button===1&&dr(t,this.textarea,this.screenElement)}))}_bindKeys(){this._register(D(this.textarea,"keyup",e=>this._keyUp(e),!0)),this._register(D(this.textarea,"keydown",e=>this._keyDown(e),!0)),this._register(D(this.textarea,"keypress",e=>this._keyPress(e),!0)),this._register(D(this.textarea,"compositionstart",()=>{this._syncTextArea(),this._compositionHelper.compositionstart(),this._compositionHelper.updateCompositionElements()})),this._register(D(this.textarea,"compositionupdate",e=>this._compositionHelper.compositionupdate(e))),this._register(D(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(D(this.textarea,"input",e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw new Error("Terminal requires a parent element.");if(e.isConnected||this._logService.debug("Terminal.open was called on an element that was not attached to the DOM"),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement("div"),this.element.dir="ltr",this.element.classList.add("terminal"),this.element.classList.add("xterm"),this.element.classList.toggle("allow-transparency",this.options.allowTransparency),this._register(this.optionsService.onSpecificOptionChange("allowTransparency",o=>this.element.classList.toggle("allow-transparency",o))),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement("div"),this._viewportElement.classList.add("xterm-viewport"),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement("div"),this.screenElement.classList.add("xterm-screen"),this._register(D(this.screenElement,"mousemove",o=>this.updateCursorStyle(o))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let i=this.textarea=this._document.createElement("textarea");this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",mi.get()),Cr||this.textarea.setAttribute("aria-multiline","false"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange("disableStdin",()=>i.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(Fo,this.textarea,e.ownerDocument.defaultView??window,this._document??(typeof window<"u"?window.document:null))),this._instantiationService.setService(be,this._coreBrowserService),this._register(D(this.textarea,"focus",o=>this._handleTextAreaFocus(o))),this._register(D(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(Di,this._document,this._helperContainer),this._instantiationService.setService(Wt,this._charSizeService),this._themeService=this._instantiationService.createInstance(Oi),this._instantiationService.setService(Ze,this._themeService),this._register(this._inputHandler.onRequestColorSchemeQuery(()=>this._reportColorScheme())),this._register(this._themeService.onChangeColors(()=>{this.coreService.decPrivateModes.colorSchemeUpdates&&this._reportColorScheme()})),this._characterJoinerService=this._instantiationService.createInstance(It),this._instantiationService.setService(vr,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Pi,this.rows,this.screenElement)),this._instantiationService.setService(ye,this._renderService),this._register(this._renderService.onRenderedViewportChange(o=>this._onRender.fire(o))),this._register(this._renderService.onDimensionsChange(o=>this._onDimensionsChange.fire({css:{canvas:{...o.css.canvas},cell:{...o.css.cell}},device:{canvas:{...o.device.canvas},cell:{...o.device.cell},char:{...o.device.char}}}))),this.onResize(o=>this._renderService.resize(o.cols,o.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(xi,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseCoordsService=this._instantiationService.createInstance(Mi),this._instantiationService.setService(zt,this._mouseCoordsService);let s=this._linkifier.value=this._register(this._instantiationService.createInstance(Ui,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch(o){this._logService.error("onWillOpen handler threw an exception",o)}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>{this._renderService.handleResize(this.cols,this.rows),this._syncTextArea()})),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(Ci,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(o=>{super.scrollLines(o,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(Ai,this.element,this.screenElement,s)),this._instantiationService.setService(gr,this._selectionService),this._mouseService=this._instantiationService.createInstance(Ti),this._instantiationService.setService(Jn,this._mouseService),this._register(this._selectionService.onRequestScrollLines(o=>this.scrollLines(o.amount,o.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(o=>this._renderService.handleSelectionChanged(o.start,o.end,o.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(o=>{this.textarea.value=o,this.textarea.focus(),this.textarea.select()})),this._register(he.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(ki,this.screenElement)),this._register(D(this.element,"mousedown",o=>this._selectionService.handleMouseDown(o))),this.mouseStateService.areMouseEventsActive&&!this.options.mouseEventsRequireAlt?(this._selectionService.disable(),this.element.classList.add("enable-mouse-events")):(this._selectionService.enable(),this.element.classList.remove("enable-mouse-events")),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(Ht,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",o=>this._handleScreenReaderModeOptionChange(o)));let r=this.options.scrollbar?.showScrollbar??!0,n=this.options.scrollbar?.width;r&&n&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Ot,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("scrollbar",o=>{let h=(o?.showScrollbar??!0)&&!!o?.width;!this._overviewRulerRenderer&&h&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Ot,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this._mouseService.bindMouse({element:this.element,screenElement:this.screenElement,document:this._document,handleTouchScroll:o=>this._viewport?.handleTouchScroll(o)},o=>this._register(o),()=>this.focus())}_createRenderer(){return this._instantiationService.createInstance(Ei,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}refresh(e,t,i=!1){this._renderService?.refreshRows(e,t,i)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add("column-select"):this.element.classList.remove("column-select")}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){cr(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this.mouseStateService.setCustomWheelEventHandler(e)}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,i){this._selectionService.setSelection(e,t,i)}getSelection(){return this._selectionService?this._selectionService.selectionText:""}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key==="Dead"||e.key==="AltGraph")&&(this._unprocessedDeadKey=!0);let i=this._keyboardService.evaluateKeyDown(e);if(this.updateCursorStyle(e),i.type===3||i.type===2){let r=this.rows-1;return this.scrollLines(i.type===2?-r:r),e.preventDefault(),e.stopPropagation(),!1}if(i.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(i.cancel&&(e.preventDefault(),e.stopPropagation()),!i.key)||!this._keyboardService.useKitty&&!this._keyboardService.useWin32InputMode&&e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;(i.key===""||i.key==="\r")&&(this.textarea.value="");let s=this._keyboardService.useWin32InputMode&&vi(e);if(this._onKey.fire({key:i.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(i.key,!s),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return e.preventDefault(),e.stopPropagation(),!1;this._keyDownHandled=!0}_isThirdLevelShift(e,t){let i=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState("AltGraph");return t.type==="keypress"?i:i&&(!t.keyCode||t.keyCode>47)}_keyUp(e){if(this._keyDownSeen=!1,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return;vi(e)||this.focus();let t=this._keyboardService.evaluateKeyUp(e);if(t?.key){let i=this._keyboardService.useWin32InputMode&&vi(e);this.coreService.triggerDataEvent(t.key,!i)}this.updateCursorStyle(e),this._keyPressHandled=!1}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType==="insertText"&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),!0}return!1}resize(e,t){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let i={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(i),t.dispose=()=>this._wrappedAddonDispose(i),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let i=0;i=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new ge)}translateToString(e,t,i){return this._line.translateToString(e,t,i)}},hr=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new Qa(t)}getNullCell(){return new ge}},eh=class extends L{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new y),this.onBufferChange=this._onBufferChange.event,this._normal=new hr(this._core.buffers.normal,"normal"),this._alternate=new hr(this._core.buffers.alt,"alternate"),this._register(this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active)))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw new Error("Active buffer is neither normal nor alternate")}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},th=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,i=>t(i.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(i,s)=>t(i,s.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}registerApcHandler(e,t){return this._core.registerApcHandler(e,t)}},ih=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},sh=["cols","rows"],Se=0,Ur=class extends L{constructor(e){super(),this._core=this._register(new Ja(e)),this._addonManager=this._register(new Za),this._publicOptions={...this._core.options};let t=s=>this._core.options[s],i=(s,r)=>{this._checkReadonlyOptions(s),this._core.options[s]=r};for(let s in this._core.options){let r={get:t.bind(this,s),set:i.bind(this,s)};Object.defineProperty(this._publicOptions,s,r)}}_checkReadonlyOptions(e){if(sh.includes(e))throw new Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw new Error("You must set the allowProposedApi option to true to use proposed API")}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get onDimensionsChange(){return this._core.onDimensionsChange}get element(){return this._core.element}get screenElement(){return this._core.screenElement}get parser(){return this._parser??=new th(this._core)}get unicode(){return this._checkProposedApi(),new ih(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer??=this._register(new eh(this._core))}get markers(){return this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t="none";switch(this._core.mouseStateService.activeProtocol){case"X10":t="x10";break;case"VT200":t="vt200";break;case"DRAG":t="drag";break;case"ANY":t="any";break}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,showCursor:!this._core.coreService.isCursorHidden,synchronizedOutputMode:e.synchronizedOutput,win32InputMode:e.win32InputMode,wraparoundMode:e.wraparound}}get dimensions(){return this._core.dimensions}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,i){this._verifyIntegers(e,t,i),this._core.select(e,t,i)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r -`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return mi.get()},set promptLabel(e){mi.set(e)},get tooMuchOutput(){return Tt.get()},set tooMuchOutput(e){Tt.set(e)}}}_verifyIntegers(...e){for(Se of e)if(Se===1/0||isNaN(Se)||Se%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(Se of e)if(Se&&(Se===1/0||isNaN(Se)||Se%1!==0||Se<0))throw new Error("This API only accepts positive integers")}};var rh={ArrowUp:"A",ArrowDown:"B",ArrowRight:"C",ArrowLeft:"D",Home:"H",End:"F"};function qr(e,t,i){switch(e){case"Escape":return"\x1B";case"Tab":return" ";case"ArrowUp":case"ArrowDown":case"ArrowRight":case"ArrowLeft":case"Home":case"End":{let s=rh[e];return i?`\x1B[1;5${s}`:t.applicationCursorKeys?`\x1BO${s}`:`\x1B[${s}`}case"-":case"/":case"|":return i?nh(e):e}}function nh(e){if(e.length!==1)return e;let t=e.charCodeAt(0);if(t>=97&&t<=122||t>=65&&t<=90)return String.fromCharCode(t&31);switch(e){case"@":case" ":return"\0";case"[":return"\x1B";case"\\":return"";case"]":return"";case"^":return"";case"_":case"/":case"-":return"";case"?":return"\x7F";default:return e}}function oh(e){let t="";for(let i=0;i{s.suppressedWriteCount-=1})}function qt(e){return e.suppressedWriteCount<=0}var Nc=16*1024;var ah='"JetBrainsMono Nerd Font Mono", "MesloLGS NF", "Symbols Nerd Font Mono", ui-monospace, Menlo, Monaco, "Courier New", monospace',hh=500,lh=40,ch=700,dh=10;function De(e){let t=window.ReactNativeWebView;t?t.postMessage(JSON.stringify(e)):e.type!=="text-mirror"&&console.log("[terminal-page]",e)}function is(e){let t=document.getElementById("error");t&&(t.textContent=e,t.style.display="block"),De({type:"error",message:e})}function jr(e,t,i){e.options.theme=t,e.options.fontSize=i,document.documentElement.style.setProperty("--terminal-background",t.background)}function _h(e){let t=e.buffer.active,i=t.baseY+e.rows,s=[];for(let r=t.baseY;r0&&s[s.length-1]==="";)s.pop();return s.slice(-lh)}function uh(){let e=document.getElementById("terminal");if(!e){is("terminal container missing");return}let t=new Ur({allowProposedApi:!0,convertEol:!0,cursorBlink:!0,fontFamily:ah,fontSize:12,scrollback:1e4}),i=new rs;t.loadAddon(i),t.loadAddon(new xs),t.unicode.activeVersion="11",t.loadAddon(new Bs((u,f)=>{u.preventDefault(),De({type:"link",url:f})})),t.open(e);let s=Yr(),r={cols:0,rows:0},n=null,o=null,h="",l=()=>{let{width:u,height:f}=e.getBoundingClientRect();u<=0||f<=0||(i.fit(),(t.cols!==r.cols||t.rows!==r.rows)&&(r={cols:t.cols,rows:t.rows},De({type:"resize",cols:t.cols,rows:t.rows})))},a=()=>{n===null&&(n=window.requestAnimationFrame(()=>{n=null,l()}))};t.onData(u=>{if(qt(s))for(let f of ts(u))De({type:"data",dataBase64:f})}),t.onBinary(u=>{if(!qt(s))return;let f=new Uint8Array(u.length);for(let p=0;p{qt(s)&&De({type:"title",title:u})});let c=null;e.addEventListener("touchstart",u=>{if(u.touches.length!==1){c=null;return}let f=u.touches[0];f&&(c={x:f.clientX,y:f.clientY,at:Date.now(),moved:!1})},{passive:!0}),e.addEventListener("touchmove",u=>{let f=u.touches[0];!c||!f||Math.hypot(f.clientX-c.x,f.clientY-c.y)>dh&&(c.moved=!0)},{passive:!0}),e.addEventListener("touchend",()=>{let u=c;c=null,!(!u||u.moved||Date.now()-u.at>=ch)&&t.focus()},{passive:!0});let d=u=>{switch(u.type){case"init":jr(t,u.theme,u.fontSize),u.textMirror&&o===null&&(o=window.setInterval(()=>{let f=_h(t),_=f.join(` -`);_!==h&&(h=_,De({type:"text-mirror",lines:f}))},hh)),l();return;case"theme":jr(t,u.theme,u.fontSize),a();return;case"write":for(let f of u.chunks)Xr({terminal:t,data:Vr(f),isReplay:u.replay,replayWriteState:s});return;case"status":t.write(`\r +`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return mi.get()},set promptLabel(e){mi.set(e)},get tooMuchOutput(){return Tt.get()},set tooMuchOutput(e){Tt.set(e)}}}_verifyIntegers(...e){for(Se of e)if(Se===1/0||isNaN(Se)||Se%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(Se of e)if(Se&&(Se===1/0||isNaN(Se)||Se%1!==0||Se<0))throw new Error("This API only accepts positive integers")}};var rh={ArrowUp:"A",ArrowDown:"B",ArrowRight:"C",ArrowLeft:"D",Home:"H",End:"F"};function qr(e,t,i){switch(e){case"Escape":return"\x1B";case"Tab":return" ";case"ArrowUp":case"ArrowDown":case"ArrowRight":case"ArrowLeft":case"Home":case"End":{let s=rh[e];return i?`\x1B[1;5${s}`:t.applicationCursorKeys?`\x1BO${s}`:`\x1B[${s}`}case"-":case"/":case"|":return i?nh(e):e}}function nh(e){if(e.length!==1)return e;let t=e.charCodeAt(0);if(t>=97&&t<=122||t>=65&&t<=90)return String.fromCharCode(t&31);switch(e){case"@":case" ":return"\0";case"[":return"\x1B";case"\\":return"";case"]":return"";case"^":return"";case"_":case"/":case"-":return"";case"?":return"\x7F";default:return e}}function oh(e){let t="";for(let i=0;i{s.suppressedWriteCount-=1})}function qt(e){return e.suppressedWriteCount<=0}var Nc=16*1024;var ah='"JetBrainsMono Nerd Font Mono", "MesloLGS NF", "Symbols Nerd Font Mono", ui-monospace, Menlo, Monaco, "Courier New", monospace',hh=500,lh=40,ch=700,dh=10;function Ce(e){let t=window.ReactNativeWebView;t?t.postMessage(JSON.stringify(e)):e.type!=="text-mirror"&&console.log("[terminal-page]",e)}function is(e){let t=document.getElementById("error");t&&(t.textContent=e,t.style.display="block"),Ce({type:"error",message:e})}function jr(e,t,i){e.options.theme=t,e.options.fontSize=i,document.documentElement.style.setProperty("--terminal-background",t.background)}function _h(e){let t=e.buffer.active,i=t.baseY+e.rows,s=[];for(let r=t.baseY;r0&&s[s.length-1]==="";)s.pop();return s.slice(-lh)}function uh(){let e=document.getElementById("terminal");if(!e){is("terminal container missing");return}let t=new Ur({allowProposedApi:!0,convertEol:!0,cursorBlink:!0,fontFamily:ah,fontSize:12,linkHandler:{activate:(u,f)=>{Ce({type:"link",source:"osc8",url:f})}},scrollback:1e4}),i=new rs;t.loadAddon(i),t.loadAddon(new xs),t.unicode.activeVersion="11",t.loadAddon(new Bs((u,f)=>{u.preventDefault(),Ce({type:"link",source:"detected-url",url:f})})),t.open(e);let s=Yr(),r={cols:0,rows:0},n=null,o=null,h="",l=()=>{let{width:u,height:f}=e.getBoundingClientRect();u<=0||f<=0||(i.fit(),(t.cols!==r.cols||t.rows!==r.rows)&&(r={cols:t.cols,rows:t.rows},Ce({type:"resize",cols:t.cols,rows:t.rows})))},a=()=>{n===null&&(n=window.requestAnimationFrame(()=>{n=null,l()}))};t.onData(u=>{if(qt(s))for(let f of ts(u))Ce({type:"data",dataBase64:f})}),t.onBinary(u=>{if(!qt(s))return;let f=new Uint8Array(u.length);for(let p=0;p{qt(s)&&Ce({type:"title",title:u})});let c=null;e.addEventListener("touchstart",u=>{if(u.touches.length!==1){c=null;return}let f=u.touches[0];f&&(c={x:f.clientX,y:f.clientY,at:Date.now(),moved:!1})},{passive:!0}),e.addEventListener("touchmove",u=>{let f=u.touches[0];!c||!f||Math.hypot(f.clientX-c.x,f.clientY-c.y)>dh&&(c.moved=!0)},{passive:!0}),e.addEventListener("touchend",()=>{let u=c;c=null,!(!u||u.moved||Date.now()-u.at>=ch)&&t.focus()},{passive:!0});let d=u=>{switch(u.type){case"init":jr(t,u.theme,u.fontSize),u.textMirror&&o===null&&(o=window.setInterval(()=>{let f=_h(t),_=f.join(` +`);_!==h&&(h=_,Ce({type:"text-mirror",lines:f}))},hh)),l();return;case"theme":jr(t,u.theme,u.fontSize),a();return;case"write":for(let f of u.chunks)Xr({terminal:t,data:Vr(f),isReplay:u.replay,replayWriteState:s});return;case"status":t.write(`\r \x1B[2m${u.text}\x1B[0m\r -`);return;case"reset":t.reset();return;case"resize":a();return;case"focus":t.focus();return;case"blur":t.blur();return;case"key":{let f=qr(u.key,{applicationCursorKeys:t.modes.applicationCursorKeysMode},u.ctrl);for(let _ of ts(f))De({type:"data",dataBase64:_});t.scrollToBottom();return}case"paste":t.paste(u.text),t.scrollToBottom();return}};window.addEventListener("message",u=>{let f;try{f=typeof u.data=="string"?JSON.parse(u.data):u.data}catch{return}if(!(!f||typeof f!="object"||!("type"in f)))try{d(f)}catch(_){is(_ instanceof Error?_.message:String(_))}}),window.__bbTerminal={handle:d},new ResizeObserver(()=>a()).observe(e),window.addEventListener("resize",a),l(),De({type:"ready",cols:t.cols,rows:t.rows})}try{uh()}catch(e){is(e instanceof Error?e.message:String(e))}})(); +`);return;case"reset":t.reset();return;case"resize":a();return;case"focus":t.focus();return;case"blur":t.blur();return;case"key":{let f=qr(u.key,{applicationCursorKeys:t.modes.applicationCursorKeysMode},u.ctrl);for(let _ of ts(f))Ce({type:"data",dataBase64:_});t.scrollToBottom();return}case"paste":t.paste(u.text),t.scrollToBottom();return}};window.addEventListener("message",u=>{let f;try{f=typeof u.data=="string"?JSON.parse(u.data):u.data}catch{return}if(!(!f||typeof f!="object"||!("type"in f)))try{d(f)}catch(_){is(_ instanceof Error?_.message:String(_))}}),window.__bbTerminal={handle:d},new ResizeObserver(()=>a()).observe(e),window.addEventListener("resize",a),l(),Ce({type:"ready",cols:t.cols,rows:t.rows})}try{uh()}catch(e){is(e instanceof Error?e.message:String(e))}})(); diff --git a/apps/mobile/src/screens/terminal/TerminalView.tsx b/apps/mobile/src/screens/terminal/TerminalView.tsx index 6b412f4da4..5e46b6f1da 100644 --- a/apps/mobile/src/screens/terminal/TerminalView.tsx +++ b/apps/mobile/src/screens/terminal/TerminalView.tsx @@ -12,6 +12,7 @@ import { useRef, } from "react"; import { + Alert, AppState, Linking, View, @@ -38,6 +39,7 @@ import { createTerminalStreamController, type TerminalStreamController, } from "./terminal-stream"; +import { requestTerminalLinkOpen } from "./terminal-link-open"; import { buildTerminalThemeFromTokens, TERMINAL_FONT_SIZE, @@ -296,7 +298,27 @@ export const TerminalView = forwardRef( transportRef.current?.sendResize(message.cols, message.rows); return; case "link": - void Linking.openURL(message.url).catch(() => undefined); + requestTerminalLinkOpen({ + confirm: ({ + actionLabel, + message: confirmationMessage, + onConfirm, + title, + }) => { + Alert.alert( + title, + confirmationMessage, + [ + { text: "Cancel", style: "cancel" }, + { text: actionLabel, onPress: onConfirm }, + ], + { cancelable: true }, + ); + }, + openUrl: (url) => Linking.openURL(url).catch(() => undefined), + source: message.source, + url: message.url, + }); return; case "title": if (sessionStatusRef.current !== "running") return; diff --git a/apps/mobile/src/screens/terminal/page/terminal-page.ts b/apps/mobile/src/screens/terminal/page/terminal-page.ts index 0c1486e69d..7ce30eb8a2 100644 --- a/apps/mobile/src/screens/terminal/page/terminal-page.ts +++ b/apps/mobile/src/screens/terminal/page/terminal-page.ts @@ -99,6 +99,11 @@ function main(): void { cursorBlink: true, fontFamily: TERMINAL_FONT_FAMILY, fontSize: 12, + linkHandler: { + activate: (_event, uri) => { + post({ type: "link", source: "osc8", url: uri }); + }, + }, scrollback: 10_000, // The DOM renderer; WebGL is skipped on purpose (context loss on // background / resume and no measurable gain on a phone-sized grid). @@ -110,7 +115,7 @@ function main(): void { terminal.loadAddon( new WebLinksAddon((event, uri) => { event.preventDefault(); - post({ type: "link", url: uri }); + post({ type: "link", source: "detected-url", url: uri }); }), ); terminal.open(container); diff --git a/apps/mobile/src/screens/terminal/terminal-bridge.test.ts b/apps/mobile/src/screens/terminal/terminal-bridge.test.ts index 9a045144bd..6819e936d0 100644 --- a/apps/mobile/src/screens/terminal/terminal-bridge.test.ts +++ b/apps/mobile/src/screens/terminal/terminal-bridge.test.ts @@ -255,9 +255,17 @@ describe("parseTerminalPageMessage", () => { it("only lets http(s) links out of the page", () => { expect( parseTerminalPageMessage( - JSON.stringify({ type: "link", url: "https://example.com/x?y=1" }), + JSON.stringify({ + type: "link", + source: "osc8", + url: "https://example.com/x?y=1", + }), ), - ).toEqual({ type: "link", url: "https://example.com/x?y=1" }); + ).toEqual({ + type: "link", + source: "osc8", + url: "https://example.com/x?y=1", + }); for (const url of [ "javascript:alert(1)", "file:///etc/passwd", @@ -265,7 +273,9 @@ describe("parseTerminalPageMessage", () => { "example.com", ]) { expect( - parseTerminalPageMessage(JSON.stringify({ type: "link", url })), + parseTerminalPageMessage( + JSON.stringify({ type: "link", source: "osc8", url }), + ), ).toBeNull(); } }); diff --git a/apps/mobile/src/screens/terminal/terminal-bridge.ts b/apps/mobile/src/screens/terminal/terminal-bridge.ts index a1224da57a..2c8a182c04 100644 --- a/apps/mobile/src/screens/terminal/terminal-bridge.ts +++ b/apps/mobile/src/screens/terminal/terminal-bridge.ts @@ -203,7 +203,11 @@ export type TerminalPageMessage = /** Keystrokes and terminal replies (base64 bytes, one wire chunk each). */ | { type: "data"; dataBase64: string } | { type: "resize"; cols: number; rows: number } - | { type: "link"; url: string } + | { + type: "link"; + source: "detected-url" | "osc8"; + url: string; + } | { type: "title"; title: string } /** Last lines of the viewport (dev / e2e only, see `init.textMirror`). */ | { type: "text-mirror"; lines: string[] } diff --git a/apps/mobile/src/screens/terminal/terminal-link-open.test.ts b/apps/mobile/src/screens/terminal/terminal-link-open.test.ts new file mode 100644 index 0000000000..374806c1af --- /dev/null +++ b/apps/mobile/src/screens/terminal/terminal-link-open.test.ts @@ -0,0 +1,50 @@ +import { describe, expect, it, vi } from "vitest"; +import { requestTerminalLinkOpen } from "./terminal-link-open"; + +describe("requestTerminalLinkOpen", () => { + it("discloses the exact target and opens it only after confirmation", () => { + const url = "https://example.com/hidden-osc-8-target"; + const openUrl = vi.fn(); + let confirmRequest: + | Parameters[0]["confirm"]>[0] + | undefined; + + requestTerminalLinkOpen({ + confirm: (request) => { + confirmRequest = request; + }, + openUrl, + source: "osc8", + url, + }); + + expect(confirmRequest).toMatchObject({ + actionLabel: "Open", + message: url, + title: "Open terminal link?", + }); + expect(openUrl).not.toHaveBeenCalled(); + + confirmRequest?.onConfirm(); + + expect(openUrl).toHaveBeenCalledOnce(); + expect(openUrl).toHaveBeenCalledWith(url); + }); + + it("opens a visible URL without confirmation", () => { + const confirm = vi.fn(); + const openUrl = vi.fn(); + const url = "https://example.com/visible-target"; + + requestTerminalLinkOpen({ + confirm, + openUrl, + source: "detected-url", + url, + }); + + expect(openUrl).toHaveBeenCalledOnce(); + expect(openUrl).toHaveBeenCalledWith(url); + expect(confirm).not.toHaveBeenCalled(); + }); +}); diff --git a/apps/mobile/src/screens/terminal/terminal-link-open.ts b/apps/mobile/src/screens/terminal/terminal-link-open.ts new file mode 100644 index 0000000000..e3232e4c43 --- /dev/null +++ b/apps/mobile/src/screens/terminal/terminal-link-open.ts @@ -0,0 +1,37 @@ +interface TerminalLinkConfirmationRequest { + actionLabel: string; + message: string; + onConfirm: () => void; + title: string; +} + +interface RequestTerminalLinkOpenArgs { + confirm: (request: TerminalLinkConfirmationRequest) => void; + openUrl: (url: string) => unknown; + source: "detected-url" | "osc8"; + url: string; +} + +/** + * Terminal output is untrusted and OSC-8 display text can hide its target. + * Keep URL opening behind a native confirmation that displays the exact URL. + */ +export function requestTerminalLinkOpen({ + confirm, + openUrl, + source, + url, +}: RequestTerminalLinkOpenArgs): void { + if (source === "detected-url") { + void openUrl(url); + return; + } + confirm({ + actionLabel: "Open", + message: url, + onConfirm: () => { + void openUrl(url); + }, + title: "Open terminal link?", + }); +} diff --git a/apps/mobile/src/screens/terminal/terminal-page-message.ts b/apps/mobile/src/screens/terminal/terminal-page-message.ts index def93a2a60..827622d8df 100644 --- a/apps/mobile/src/screens/terminal/terminal-page-message.ts +++ b/apps/mobile/src/screens/terminal/terminal-page-message.ts @@ -28,6 +28,7 @@ const terminalPageMessageSchema = z.discriminatedUnion("type", [ }), z.object({ type: z.literal("link"), + source: z.enum(["detected-url", "osc8"]), // Link text comes from terminal output (anything the host process // prints); only web URLs may leave the page. url: z.string().url().refine(isWebUrl, "http(s) only"),