@simon_he/vue-tui 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +84 -26
  2. package/dist/TMermaidText-frVr8Ysb.js +885 -0
  3. package/dist/{TSelect-DR0FomSu.js → TSelect-tJ87rKPM.js} +59 -242
  4. package/dist/{TTree-kzhlB5P0.js → TTree-CGdE-CYu.js} +138 -102
  5. package/dist/agent/mermaid.cjs +2 -0
  6. package/dist/agent/mermaid.d.cts +2 -0
  7. package/dist/agent/mermaid.d.ts +2 -0
  8. package/dist/agent/mermaid.js +1 -0
  9. package/dist/agent.cjs +31188 -24907
  10. package/dist/agent.d.cts +11 -1
  11. package/dist/agent.d.ts +11 -1
  12. package/dist/agent.js +516 -11
  13. package/dist/{block-source-CKUOnkgT.js → block-source-CrlmaBM5.js} +1039 -66
  14. package/dist/cli/input.d.ts +8 -0
  15. package/dist/cli/stdin-buffer.d.ts +1 -1
  16. package/dist/cli/video/ffmpeg-frame-source.d.ts +10 -0
  17. package/dist/cli/video/png-frame-parser.d.ts +4 -0
  18. package/dist/cli/video/raw-frame-parser.d.ts +1 -0
  19. package/dist/cli/video/yt-dlp-frame-source.d.ts +11 -0
  20. package/dist/cli.cjs +5146 -6767
  21. package/dist/cli.d.cts +5 -1
  22. package/dist/cli.d.ts +5 -1
  23. package/dist/cli.js +2869 -154
  24. package/dist/core/buffer/eaw-ranges-unicode-17.d.ts +14 -0
  25. package/dist/core/perf/instrumentation-noop.d.ts +48 -0
  26. package/dist/core/perf/instrumentation.d.ts +136 -0
  27. package/dist/core/terminal/create-terminal.d.ts +1 -0
  28. package/dist/core.cjs +843 -1469
  29. package/dist/core.js +4 -5
  30. package/dist/create-terminal-app.d.ts +24 -1
  31. package/dist/debug-logger-CmsGI4of.js +74 -0
  32. package/dist/{dom-renderer-BniJSQyX.js → dom-renderer-DXx8fWzD.js} +2 -3
  33. package/dist/experimental/3d/bun/contributor-avatar-atlas.d.ts +12 -0
  34. package/dist/experimental/3d/bun/png.d.ts +1 -0
  35. package/dist/experimental/3d/bun/terminal-badge-scene.d.ts +11 -0
  36. package/dist/experimental/3d/bun/terminal-badge.wgsl.d.ts +1 -0
  37. package/dist/experimental/3d/bun/webgpu-renderer.d.ts +26 -0
  38. package/dist/experimental/3d/bun.cjs +7271 -0
  39. package/dist/experimental/3d/bun.d.cts +4 -0
  40. package/dist/experimental/3d/bun.d.ts +4 -0
  41. package/dist/experimental/3d/bun.js +7390 -0
  42. package/dist/experimental/video/node.cjs +497 -0
  43. package/dist/experimental/video/node.d.cts +4 -0
  44. package/dist/experimental/video/node.d.ts +4 -0
  45. package/dist/experimental/video/node.js +610 -0
  46. package/dist/experimental.cjs +6876 -6192
  47. package/dist/experimental.d.cts +7 -0
  48. package/dist/experimental.d.ts +7 -0
  49. package/dist/experimental.js +3005 -9
  50. package/dist/frame-perf-CHpWhbC4.js +111 -0
  51. package/dist/{create-terminal-DBFNYr8f.js → hyperlink-_1FAj7Wq.js} +440 -13
  52. package/dist/index.cjs +5017 -10339
  53. package/dist/index.js +14 -13
  54. package/dist/{linkify-D_gzn9Xq.js → linkify-D68T7rdW.js} +193 -3
  55. package/dist/markdown.cjs +21295 -12691
  56. package/dist/markdown.d.cts +1 -1
  57. package/dist/markdown.d.ts +1 -1
  58. package/dist/markdown.js +211 -51
  59. package/dist/mermaid-BNhM1jAZ.js +123 -0
  60. package/dist/mermaid.cjs +1707 -0
  61. package/dist/mermaid.d.cts +3 -0
  62. package/dist/mermaid.d.ts +3 -0
  63. package/dist/mermaid.js +6 -0
  64. package/dist/observability/frame-perf-store.d.ts +2 -1
  65. package/dist/observability/frame-perf.d.ts +33 -0
  66. package/dist/observability.cjs +106 -107
  67. package/dist/observability.d.cts +2 -2
  68. package/dist/observability.d.ts +2 -2
  69. package/dist/observability.js +3 -3
  70. package/dist/{wheel-scroll-vBRaQ7p-.js → rect-DUpeDfBg.js} +253 -117
  71. package/dist/renderer/cli/stdout-metrics.d.ts +10 -0
  72. package/dist/renderer/cli/stdout-renderer.d.ts +3 -0
  73. package/dist/renderer/terminal-graphic-render-queue.d.ts +50 -0
  74. package/dist/renderer/terminal-graphics-trace.d.ts +53 -0
  75. package/dist/renderer/terminal-graphics.d.ts +147 -0
  76. package/dist/renderer-dom.cjs +364 -903
  77. package/dist/renderer-dom.js +4 -5
  78. package/dist/runtime/index.d.ts +2 -0
  79. package/dist/{runtime-rfcZCyJq.js → runtime-Byf8XXOT.js} +28 -15
  80. package/dist/runtime.cjs +427 -889
  81. package/dist/runtime.js +2 -2
  82. package/dist/terminal-graphics-Bbe83wSr.js +597 -0
  83. package/dist/{terminal-selection-DBinO6p5.js → terminal-selection-4W1SJj4c.js} +4 -1
  84. package/dist/{tlog-theme-CvLFNMwk.js → tlog-theme-Bul2Na3u.js} +1237 -12
  85. package/dist/{trace-CjzYeIxN.js → trace-Bh8WnoMo.js} +5 -0
  86. package/dist/vue/agent/create-png-terminal-graphic-renderer.d.ts +19 -0
  87. package/dist/vue/components/T3DViewport.d.ts +473 -0
  88. package/dist/vue/components/TAgentTerminalGraphic.d.ts +494 -0
  89. package/dist/vue/components/TCharts.d.ts +1121 -0
  90. package/dist/vue/components/TFeedback.d.ts +1 -1
  91. package/dist/vue/components/TFlex.d.ts +389 -0
  92. package/dist/vue/components/TForm.d.ts +4 -4
  93. package/dist/vue/components/TLogSearchBar.d.ts +3 -3
  94. package/dist/vue/components/TLogSearchPager.d.ts +2 -2
  95. package/dist/vue/components/TMarkdownText.d.ts +162 -4
  96. package/dist/vue/components/TMermaidText.d.ts +900 -0
  97. package/dist/vue/components/TVideo.d.ts +291 -0
  98. package/dist/vue/components/TVirtualList.d.ts +9 -0
  99. package/dist/vue/components/TVirtualMarkdown.d.ts +170 -9
  100. package/dist/vue/components/TVirtualRows.d.ts +9 -0
  101. package/dist/vue/components/TerminalProvider.d.ts +2 -0
  102. package/dist/vue/context.d.ts +24 -0
  103. package/dist/vue/index.d.ts +5 -0
  104. package/dist/vue/layout/flex.d.ts +67 -0
  105. package/dist/vue/markdown/ast.d.ts +5 -2
  106. package/dist/vue/markdown/document.d.ts +5 -0
  107. package/dist/vue/markdown/image-actions.d.ts +14 -0
  108. package/dist/vue/markdown/image.d.ts +11 -0
  109. package/dist/vue/markdown/link-actions.d.ts +14 -0
  110. package/dist/vue/markdown/math-actions.d.ts +14 -0
  111. package/dist/vue/markdown/math.d.ts +6 -0
  112. package/dist/vue/markdown/render.d.ts +28 -0
  113. package/dist/vue/markdown/types.d.ts +78 -0
  114. package/dist/vue/mermaid/beautiful-mermaid.d.ts +1436 -0
  115. package/dist/vue/render/render-manager.d.ts +7 -0
  116. package/dist/vue/video/types.d.ts +39 -0
  117. package/dist/vue.cjs +7207 -12437
  118. package/dist/vue.js +704 -38
  119. package/dist/wheel-scroll-DASkEZr-.js +106 -0
  120. package/dist/{hyperlink-Bn02UXJb.js → width-GqllnV8C.js} +166 -111
  121. package/package.json +119 -14
  122. package/dist/frame-perf-C6Xfg85O.js +0 -24
  123. package/dist/sgr-BmzxEjAO.js +0 -304
  124. /package/dist/{ansi-palette-CNXqFciC.js → ansi-palette-CH6jc2Z7.js} +0 -0
  125. /package/dist/{path-suggest-BNqcuE3-.js → path-suggest-Dndu4dTi.js} +0 -0
package/dist/runtime.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createEventManager, createRuntime } from "./runtime-rfcZCyJq.js";
2
- import { createTerminalSelectionController, terminalSelectionRowSpans, terminalSelectionVisibleRowSpans } from "./terminal-selection-DBinO6p5.js";
1
+ import { createEventManager, createRuntime } from "./runtime-Byf8XXOT.js";
2
+ import { createTerminalSelectionController, terminalSelectionRowSpans, terminalSelectionVisibleRowSpans } from "./terminal-selection-4W1SJj4c.js";
3
3
 
4
4
  export { createEventManager, createRuntime, createTerminalSelectionController, terminalSelectionRowSpans, terminalSelectionVisibleRowSpans };
@@ -0,0 +1,597 @@
1
+ import { getRootTerminal } from "./hyperlink-_1FAj7Wq.js";
2
+
3
+ //#region src/renderer/terminal-graphics.ts
4
+ const TERMINAL_GRAPHICS_PROTOCOL_PRIORITY = [
5
+ "kitty",
6
+ "iterm2",
7
+ "sixel"
8
+ ];
9
+ const ESC = "\x1B";
10
+ const BEL = "\x07";
11
+ const ST = `${ESC}\\`;
12
+ const ESC_RE = "\\u001B";
13
+ const BEL_RE = "\\u0007";
14
+ const CSI_RE = new RegExp(`${ESC_RE}\\[[0-?]*[ -/]*[@-~]`, "g");
15
+ const OSC_RE = new RegExp(`${ESC_RE}\\][\\s\\S]*?(?:${BEL_RE}|${ESC_RE}\\\\)`, "g");
16
+ const DCS_RE = new RegExp(`${ESC_RE}P[\\s\\S]*?${ESC_RE}\\\\`, "g");
17
+ const APC_RE = new RegExp(`${ESC_RE}_[\\s\\S]*?${ESC_RE}\\\\`, "g");
18
+ const C1_CSI_RE = new RegExp("\\u009B[0-?]*[ -/]*[@-~]", "g");
19
+ const C1_OSC_RE = new RegExp(`\\u009D[\\s\\S]*?(?:${BEL_RE}|\\u009C)`, "g");
20
+ const C1_DCS_RE = new RegExp("\\u0090[\\s\\S]*?\\u009C", "g");
21
+ const C1_APC_RE = new RegExp("\\u009F[\\s\\S]*?\\u009C", "g");
22
+ const MAX_TERMINAL_GRAPHICS_SEQUENCE_CHARS = 16 * 1024 * 1024;
23
+ const MAX_TERMINAL_GRAPHICS_FALLBACK_CHARS = 16384;
24
+ const MAX_TERMINAL_GRAPHIC_CELLS = 1e4;
25
+ const TERMINAL_GRAPHICS_REGISTRY = Symbol.for("@simon_he/vue-tui:v1:terminal-graphics");
26
+ const terminalGraphicsGlobal = globalThis;
27
+ const terminalGraphicsRegistry = terminalGraphicsGlobal[TERMINAL_GRAPHICS_REGISTRY] ?? {
28
+ outputs: new WeakMap(),
29
+ outputVersions: new WeakMap(),
30
+ outputListeners: new WeakMap()
31
+ };
32
+ terminalGraphicsGlobal[TERMINAL_GRAPHICS_REGISTRY] = terminalGraphicsRegistry;
33
+ const terminalGraphicsOutputs = terminalGraphicsRegistry.outputs;
34
+ const terminalGraphicsOutputVersions = terminalGraphicsRegistry.outputVersions;
35
+ const terminalGraphicsOutputListeners = terminalGraphicsRegistry.outputListeners;
36
+ function getTerminalGraphicsOutput(terminal) {
37
+ return terminalGraphicsOutputs.get(getRootTerminal(terminal)) ?? null;
38
+ }
39
+ function getTerminalGraphicsOutputVersion(terminal) {
40
+ return terminalGraphicsOutputVersions.get(getRootTerminal(terminal)) ?? 0;
41
+ }
42
+ function subscribeTerminalGraphicsOutput(terminal, listener) {
43
+ const rootTerminal = getRootTerminal(terminal);
44
+ let listeners = terminalGraphicsOutputListeners.get(rootTerminal);
45
+ if (!listeners) {
46
+ listeners = new Set();
47
+ terminalGraphicsOutputListeners.set(rootTerminal, listeners);
48
+ }
49
+ listeners.add(listener);
50
+ return () => {
51
+ listeners.delete(listener);
52
+ if (listeners.size === 0) terminalGraphicsOutputListeners.delete(rootTerminal);
53
+ };
54
+ }
55
+ function envString(env, key) {
56
+ const value = env[key];
57
+ return value == null ? void 0 : String(value);
58
+ }
59
+ function truthy(value) {
60
+ if (value == null) return false;
61
+ return /^(1|true|yes|on)$/i.test(String(value));
62
+ }
63
+ function readStdoutIsTTY() {
64
+ const maybeProcess = globalThis.process;
65
+ return Boolean(maybeProcess?.stdout?.isTTY);
66
+ }
67
+ function readProcessEnv() {
68
+ const maybeProcess = globalThis.process;
69
+ return maybeProcess?.env ?? {};
70
+ }
71
+ function normalizeMode(value) {
72
+ const raw = String(value ?? "auto").trim().toLowerCase();
73
+ if (raw === "auto" || raw === "off" || raw === "none" || raw === "kitty" || raw === "iterm2" || raw === "sixel" || raw === "unicode") return raw === "off" ? "none" : raw;
74
+ return "auto";
75
+ }
76
+ function isTerminalGraphicsProtocol(value) {
77
+ return value === "kitty" || value === "iterm2" || value === "sixel";
78
+ }
79
+ function uniqueProtocols(protocols) {
80
+ return [...new Set(protocols)];
81
+ }
82
+ function pickBestTerminalGraphicsProtocol(protocols) {
83
+ const available = new Set(protocols);
84
+ for (const protocol of TERMINAL_GRAPHICS_PROTOCOL_PRIORITY) if (available.has(protocol)) return protocol;
85
+ return null;
86
+ }
87
+ function detectCandidates(env) {
88
+ const candidates = [];
89
+ const term = String(envString(env, "TERM") ?? "").toLowerCase();
90
+ const termProgram = String(envString(env, "TERM_PROGRAM") ?? "").toLowerCase();
91
+ const termProgramVersion = String(envString(env, "TERM_PROGRAM_VERSION") ?? "").toLowerCase();
92
+ if (envString(env, "KITTY_WINDOW_ID") || envString(env, "GHOSTTY_RESOURCES_DIR") || /(?:^|-)kitty(?:-|$)/i.test(term) || term.includes("ghostty") || termProgram.includes("ghostty")) candidates.push("kitty");
93
+ if (termProgram.includes("iterm") || termProgram.includes("wezterm") || envString(env, "WEZTERM_PANE") || envString(env, "WEZTERM_EXECUTABLE")) candidates.push("iterm2");
94
+ if (truthy(envString(env, "VUE_TUI_SIXEL")) || truthy(envString(env, "VUE_TUI_GRAPHICS_SIXEL")) || String(envString(env, "TERMINAL_GRAPHICS") ?? "").toLowerCase().includes("sixel") || /\bsixel\b/i.test(`${term} ${termProgram} ${termProgramVersion}`)) candidates.push("sixel");
95
+ return uniqueProtocols(candidates);
96
+ }
97
+ function capabilitiesFor(protocol, input) {
98
+ const supported = protocol === "kitty" || protocol === "iterm2" || protocol === "sixel";
99
+ const candidates = uniqueProtocols([...input.candidates ?? (supported ? [protocol] : [])]);
100
+ return {
101
+ supported,
102
+ kitty: protocol === "kitty" || candidates.includes("kitty"),
103
+ iterm2: protocol === "iterm2" || candidates.includes("iterm2"),
104
+ sixel: protocol === "sixel" || candidates.includes("sixel"),
105
+ preferredProtocol: supported ? protocol : null,
106
+ protocol,
107
+ candidates,
108
+ stdoutIsTTY: input.stdoutIsTTY,
109
+ insideTmux: input.insideTmux,
110
+ insideScreen: input.insideScreen,
111
+ insideZellij: input.insideZellij,
112
+ multiplexer: input.multiplexer,
113
+ passthrough: input.passthrough,
114
+ forced: input.forced,
115
+ reason: input.reason
116
+ };
117
+ }
118
+ function detectTerminalGraphicsCapabilities(options = {}) {
119
+ const env = options.env ?? readProcessEnv();
120
+ const stdoutIsTTY = options.stdoutIsTTY ?? options.isTTY ?? readStdoutIsTTY();
121
+ const term = String(envString(env, "TERM") ?? "").toLowerCase();
122
+ const insideTmux = Boolean(envString(env, "TMUX")) || term.includes("tmux");
123
+ const insideScreen = Boolean(envString(env, "STY")) || term.startsWith("screen");
124
+ const insideZellij = Boolean(envString(env, "ZELLIJ") || envString(env, "ZELLIJ_SESSION_NAME")) || term.includes("zellij");
125
+ const multiplexer = insideTmux ? "tmux" : insideScreen ? "screen" : insideZellij ? "zellij" : null;
126
+ const passthroughRequested = options.passthrough ?? (truthy(envString(env, "VUE_TUI_TERMINAL_GRAPHICS_PASSTHROUGH")) || truthy(envString(env, "VUE_TUI_GRAPHICS_TMUX_PASSTHROUGH")));
127
+ const passthroughSupported = !multiplexer || multiplexer === "tmux";
128
+ const passthrough = passthroughRequested && passthroughSupported;
129
+ const protocolOptionProvided = options.protocol != null;
130
+ const mode = normalizeMode(options.protocol ?? envString(env, "VUE_TUI_TERMINAL_GRAPHICS") ?? envString(env, "VUE_TUI_GRAPHICS_PROTOCOL"));
131
+ const forceFromOption = options.force === true;
132
+ const force = options.force ?? truthy(envString(env, "VUE_TUI_GRAPHICS_FORCE"));
133
+ const base = {
134
+ stdoutIsTTY,
135
+ insideTmux,
136
+ insideScreen,
137
+ insideZellij,
138
+ multiplexer,
139
+ passthrough,
140
+ forced: force
141
+ };
142
+ if (mode === "none") return capabilitiesFor("none", {
143
+ ...base,
144
+ reason: protocolOptionProvided ? "disabled-by-option" : "disabled-by-env"
145
+ });
146
+ if (!stdoutIsTTY && !force) return capabilitiesFor("unicode", {
147
+ ...base,
148
+ reason: "stdout-is-not-tty"
149
+ });
150
+ if (truthy(envString(env, "CI")) && !force) return capabilitiesFor("unicode", {
151
+ ...base,
152
+ reason: "ci"
153
+ });
154
+ if (multiplexer && passthroughRequested && !passthroughSupported && !force) return capabilitiesFor("unicode", {
155
+ ...base,
156
+ reason: `${multiplexer}-passthrough-not-implemented`
157
+ });
158
+ if (multiplexer && !passthrough && !force) return capabilitiesFor("unicode", {
159
+ ...base,
160
+ reason: `${multiplexer}-without-passthrough`
161
+ });
162
+ if (mode === "kitty" || mode === "iterm2" || mode === "sixel") return capabilitiesFor(mode, {
163
+ ...base,
164
+ candidates: [mode],
165
+ reason: force ? forceFromOption ? "forced-by-option" : "forced-by-env" : protocolOptionProvided ? "selected-by-option" : "selected-by-env"
166
+ });
167
+ if (mode === "unicode") return capabilitiesFor("unicode", {
168
+ ...base,
169
+ reason: protocolOptionProvided ? "unicode-forced-by-option" : "unicode-forced-by-env"
170
+ });
171
+ const candidates = detectCandidates(env);
172
+ const preferredProtocol = pickBestTerminalGraphicsProtocol(candidates);
173
+ const protocol = preferredProtocol ?? "unicode";
174
+ return capabilitiesFor(protocol, {
175
+ ...base,
176
+ candidates,
177
+ reason: protocol === "unicode" ? "no-supported-graphics-protocol-detected" : "auto-detected"
178
+ });
179
+ }
180
+ function hashTerminalGraphicsString(input) {
181
+ let hash = 2166136261;
182
+ for (let index = 0; index < input.length; index += 1) {
183
+ hash ^= input.charCodeAt(index);
184
+ hash = Math.imul(hash, 16777619);
185
+ }
186
+ return (hash >>> 0).toString(36);
187
+ }
188
+ function stableTerminalGraphicNumericId(input, options = {}) {
189
+ const min = Math.floor(options.min ?? 1);
190
+ const max = Math.floor(options.max ?? 2147483647);
191
+ const span = Math.max(1, max - min + 1);
192
+ let hash = 2166136261;
193
+ for (let index = 0; index < input.length; index += 1) {
194
+ hash ^= input.charCodeAt(index);
195
+ hash = Math.imul(hash, 16777619);
196
+ }
197
+ return min + (hash >>> 0) % span;
198
+ }
199
+ function positiveGraphicInt(value, max) {
200
+ const n = Math.trunc(Number(value));
201
+ if (!Number.isFinite(n) || n <= 0) return null;
202
+ return Math.min(max, n);
203
+ }
204
+ function normalizeTerminalGraphicSize(width, height) {
205
+ const w = positiveGraphicInt(width, MAX_TERMINAL_GRAPHIC_CELLS);
206
+ const h = positiveGraphicInt(height, MAX_TERMINAL_GRAPHIC_CELLS);
207
+ if (w == null || h == null) return null;
208
+ if (w * h > MAX_TERMINAL_GRAPHIC_CELLS) return null;
209
+ return {
210
+ width: w,
211
+ height: h
212
+ };
213
+ }
214
+ function canDrawTerminalGraphicRect(rect, size) {
215
+ const x = Math.floor(rect.x);
216
+ const y = Math.floor(rect.y);
217
+ const graphicSize = normalizeTerminalGraphicSize(rect.w, rect.h);
218
+ const cols = Math.max(0, Math.floor(size.cols));
219
+ const rows = Math.max(0, Math.floor(size.rows));
220
+ return graphicSize != null && cols > 0 && rows > 0 && Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 && x < cols && y < rows;
221
+ }
222
+ function withoutNestedEscapes(body) {
223
+ return !body.includes(ESC) && !body.includes(BEL);
224
+ }
225
+ function isBase64ish(value) {
226
+ return /^[A-Za-z0-9+/=]*$/.test(value);
227
+ }
228
+ function parseKittyControls(raw) {
229
+ const out = new Map();
230
+ if (!/^[A-Za-z0-9_,=+.\-:]*$/.test(raw)) return null;
231
+ for (const part of raw.split(",")) {
232
+ if (!part) continue;
233
+ const eq = part.indexOf("=");
234
+ if (eq <= 0) return null;
235
+ const key = part.slice(0, eq);
236
+ const value = part.slice(eq + 1);
237
+ if (!/^[A-Za-z]$/.test(key)) return null;
238
+ if (!/^[A-Za-z0-9+.\-:]*$/.test(value)) return null;
239
+ out.set(key, value);
240
+ }
241
+ return out;
242
+ }
243
+ function parseKittyPackets(sequence) {
244
+ const packets = [];
245
+ let index = 0;
246
+ while (index < sequence.length) {
247
+ if (!sequence.startsWith(`${ESC}_G`, index)) return null;
248
+ const end = sequence.indexOf(ST, index + 3);
249
+ if (end < 0) return null;
250
+ const body = sequence.slice(index + 3, end);
251
+ if (!withoutNestedEscapes(body)) return null;
252
+ const semicolon = body.indexOf(";");
253
+ const rawControls = semicolon >= 0 ? body.slice(0, semicolon) : body;
254
+ const payload = semicolon >= 0 ? body.slice(semicolon + 1) : "";
255
+ const controls = parseKittyControls(rawControls);
256
+ if (!controls) return null;
257
+ if (payload && !isBase64ish(payload)) return null;
258
+ packets.push({
259
+ controls,
260
+ payload
261
+ });
262
+ index = end + ST.length;
263
+ }
264
+ return packets.length ? packets : null;
265
+ }
266
+ const KITTY_DRAW_FIRST_CONTROL_KEYS = new Set([
267
+ "a",
268
+ "f",
269
+ "q",
270
+ "C",
271
+ "i",
272
+ "I",
273
+ "p",
274
+ "c",
275
+ "r",
276
+ "x",
277
+ "y",
278
+ "w",
279
+ "h",
280
+ "z",
281
+ "m",
282
+ "t"
283
+ ]);
284
+ const KITTY_DRAW_CONTINUATION_CONTROL_KEYS = new Set([
285
+ "a",
286
+ "q",
287
+ "m"
288
+ ]);
289
+ const KITTY_CLEAR_CONTROL_KEYS = new Set([
290
+ "a",
291
+ "d",
292
+ "i",
293
+ "I",
294
+ "p",
295
+ "q"
296
+ ]);
297
+ function kittyControlsUseOnly(controls, allowed) {
298
+ for (const key of controls.keys()) if (!allowed.has(key)) return false;
299
+ return true;
300
+ }
301
+ const KITTY_UINT32_MAX = 4294967295;
302
+ const KITTY_INT32_MIN = -2147483648;
303
+ const KITTY_INT32_MAX = 2147483647;
304
+ function kittyControlIsUint32(controls, key, min = 0) {
305
+ const value = controls.get(key);
306
+ if (value == null) return true;
307
+ if (!/^\d+$/.test(value)) return false;
308
+ const n = Number(value);
309
+ return Number.isSafeInteger(n) && n >= min && n <= KITTY_UINT32_MAX;
310
+ }
311
+ function kittyControlIsInt32(controls, key) {
312
+ const value = controls.get(key);
313
+ if (value == null) return true;
314
+ if (!/^-?\d+$/.test(value)) return false;
315
+ const n = Number(value);
316
+ return Number.isSafeInteger(n) && n >= KITTY_INT32_MIN && n <= KITTY_INT32_MAX;
317
+ }
318
+ function kittyControlPositiveInt(controls, key, fallback) {
319
+ const value = controls.get(key);
320
+ if (value == null) return fallback;
321
+ if (!/^\d+$/.test(value)) return null;
322
+ const n = Number(value);
323
+ return Number.isSafeInteger(n) && n >= 1 ? n : null;
324
+ }
325
+ function kittyControlIsTerminalGraphicCellsBounded(controls) {
326
+ const columns = kittyControlPositiveInt(controls, "c", 1);
327
+ const rows = kittyControlPositiveInt(controls, "r", 1);
328
+ return columns != null && rows != null && columns * rows <= MAX_TERMINAL_GRAPHIC_CELLS;
329
+ }
330
+ function validateKittySharedSafeControls(controls) {
331
+ const q = controls.get("q");
332
+ if (q != null && !/^[0-2]$/.test(q)) return false;
333
+ const cursorMove = controls.get("C");
334
+ if (cursorMove != null && !/^[01]$/.test(cursorMove)) return false;
335
+ for (const key of [
336
+ "i",
337
+ "I",
338
+ "p"
339
+ ]) if (!kittyControlIsUint32(controls, key)) return false;
340
+ for (const key of ["c", "r"]) if (!kittyControlIsUint32(controls, key, 1)) return false;
341
+ if (!kittyControlIsTerminalGraphicCellsBounded(controls)) return false;
342
+ for (const key of ["x", "y"]) if (!kittyControlIsUint32(controls, key)) return false;
343
+ for (const key of ["w", "h"]) if (!kittyControlIsUint32(controls, key, 1)) return false;
344
+ if (!kittyControlIsInt32(controls, "z")) return false;
345
+ const transmissionMedium = controls.get("t");
346
+ if (transmissionMedium != null && transmissionMedium !== "d") return false;
347
+ return true;
348
+ }
349
+ function validateKittySequence(sequence, op = "draw") {
350
+ const packets = parseKittyPackets(sequence);
351
+ if (!packets) return false;
352
+ if (op === "clear") {
353
+ if (packets.length !== 1) return false;
354
+ const packet = packets[0];
355
+ if (!kittyControlsUseOnly(packet.controls, KITTY_CLEAR_CONTROL_KEYS)) return false;
356
+ if (!validateKittySharedSafeControls(packet.controls)) return false;
357
+ if (packet.payload) return false;
358
+ if (packet.controls.get("a") !== "d") return false;
359
+ const d = packet.controls.get("d");
360
+ return d == null || /^[aAcCiI]$/.test(d);
361
+ }
362
+ const first = packets[0];
363
+ if (!kittyControlsUseOnly(first.controls, KITTY_DRAW_FIRST_CONTROL_KEYS)) return false;
364
+ if (!validateKittySharedSafeControls(first.controls)) return false;
365
+ if (first.controls.get("a") === "p") {
366
+ if (packets.length !== 1) return false;
367
+ if (first.payload) return false;
368
+ if (!first.controls.has("i") && !first.controls.has("I")) return false;
369
+ return true;
370
+ }
371
+ if (first.controls.get("a") !== "T") return false;
372
+ if (!first.payload) return false;
373
+ const f = first.controls.get("f");
374
+ if (f != null && f !== "24" && f !== "32" && f !== "100") return false;
375
+ const firstMore = first.controls.get("m");
376
+ if (firstMore != null && firstMore !== "0" && firstMore !== "1") return false;
377
+ if (packets.length > 1 && firstMore !== "1") return false;
378
+ for (let i = 1; i < packets.length; i++) {
379
+ const packet = packets[i];
380
+ if (!kittyControlsUseOnly(packet.controls, KITTY_DRAW_CONTINUATION_CONTROL_KEYS)) return false;
381
+ if (!validateKittySharedSafeControls(packet.controls)) return false;
382
+ const action = packet.controls.get("a");
383
+ if (action != null && action !== "T") return false;
384
+ const m = packet.controls.get("m");
385
+ if (m !== "0" && m !== "1") return false;
386
+ if (!packet.payload && !(i === packets.length - 1 && m === "0")) return false;
387
+ }
388
+ if (packets.length > 1 && packets[packets.length - 1].controls.get("m") === "1") return false;
389
+ return true;
390
+ }
391
+ function validateIterm2Dimension(value) {
392
+ return /^auto$/i.test(value) || /^(?:[1-9]\d{0,4})(?:px|%)?$/.test(value);
393
+ }
394
+ function validateIterm2Params(params) {
395
+ const seen = new Set();
396
+ let inline = false;
397
+ for (const part of params.split(";").filter(Boolean)) {
398
+ const eq = part.indexOf("=");
399
+ if (eq <= 0) return false;
400
+ const key = part.slice(0, eq);
401
+ const value = part.slice(eq + 1);
402
+ if (seen.has(key)) return false;
403
+ seen.add(key);
404
+ switch (key) {
405
+ case "inline":
406
+ if (value !== "1") return false;
407
+ inline = true;
408
+ break;
409
+ case "width":
410
+ case "height":
411
+ if (!validateIterm2Dimension(value)) return false;
412
+ break;
413
+ case "preserveAspectRatio":
414
+ case "doNotMoveCursor":
415
+ if (!/^[01]$/.test(value)) return false;
416
+ break;
417
+ default: return false;
418
+ }
419
+ }
420
+ return inline;
421
+ }
422
+ function validateIterm2Sequence(sequence, op = "draw") {
423
+ if (op === "clear") return false;
424
+ let index = 0;
425
+ while (index < sequence.length) {
426
+ const prefix = `${ESC}]1337;File=`;
427
+ if (!sequence.startsWith(prefix, index)) return false;
428
+ const belEnd = sequence.indexOf(BEL, index + prefix.length);
429
+ const stEnd = sequence.indexOf(ST, index + prefix.length);
430
+ const end = belEnd >= 0 && stEnd >= 0 ? Math.min(belEnd, stEnd) : belEnd >= 0 ? belEnd : stEnd;
431
+ if (end < 0) return false;
432
+ const body = sequence.slice(index + `${ESC}]1337;`.length, end);
433
+ if (!body.startsWith("File=")) return false;
434
+ if (!withoutNestedEscapes(body)) return false;
435
+ const colon = body.indexOf(":");
436
+ if (colon < 0) return false;
437
+ const params = body.slice(5, colon);
438
+ const payload = body.slice(colon + 1);
439
+ if (!/^[A-Za-z0-9_=;,.%+\-:]*$/.test(params)) return false;
440
+ if (!payload || !isBase64ish(payload)) return false;
441
+ if (!validateIterm2Params(params)) return false;
442
+ index = end + (end === stEnd ? ST.length : BEL.length);
443
+ }
444
+ return sequence.length > 0;
445
+ }
446
+ function validateSixelSequence(sequence, op = "draw") {
447
+ if (op === "clear") return false;
448
+ let index = 0;
449
+ while (index < sequence.length) {
450
+ if (!sequence.startsWith(`${ESC}P`, index)) return false;
451
+ const end = sequence.indexOf(ST, index + 2);
452
+ if (end < 0) return false;
453
+ const body = sequence.slice(index + 2, end);
454
+ if (!withoutNestedEscapes(body)) return false;
455
+ for (let i = 0; i < body.length; i++) {
456
+ const code = body.charCodeAt(i);
457
+ if (code < 32 || code > 126) return false;
458
+ }
459
+ const q = body.indexOf("q");
460
+ if (q < 0 || q > 32) return false;
461
+ const introducer = body.slice(0, q);
462
+ if (!/^[0-9;?]*$/.test(introducer)) return false;
463
+ const data = body.slice(q + 1);
464
+ if (!data.length) return false;
465
+ index = end + ST.length;
466
+ }
467
+ return sequence.length > 0;
468
+ }
469
+ function stripTerminalControlChars(value) {
470
+ let out = "";
471
+ for (let index = 0; index < value.length; index++) {
472
+ const code = value.charCodeAt(index);
473
+ if (code <= 8 || code === 11 || code === 12 || code >= 14 && code <= 31 || code === 127 || code >= 128 && code <= 159) continue;
474
+ out += value[index];
475
+ }
476
+ return out;
477
+ }
478
+ function sanitizeTerminalFallbackText(text) {
479
+ return stripTerminalControlChars(String(text ?? "").replace(OSC_RE, "").replace(CSI_RE, "").replace(DCS_RE, "").replace(APC_RE, "").replace(C1_OSC_RE, "").replace(C1_CSI_RE, "").replace(C1_DCS_RE, "").replace(C1_APC_RE, "")).slice(0, MAX_TERMINAL_GRAPHICS_FALLBACK_CHARS);
480
+ }
481
+ function isSafeTerminalGraphicsSequence(sequence, protocol, op = "draw") {
482
+ if (!isTerminalGraphicsProtocol(protocol)) return false;
483
+ if (!sequence || sequence.length > MAX_TERMINAL_GRAPHICS_SEQUENCE_CHARS) return false;
484
+ return protocol === "kitty" ? validateKittySequence(sequence, op) : protocol === "iterm2" ? validateIterm2Sequence(sequence, op) : validateSixelSequence(sequence, op);
485
+ }
486
+ function uint32Control(key, value, min = 0) {
487
+ if (value == null) return "";
488
+ const n = Math.floor(value);
489
+ return Number.isSafeInteger(n) && n >= min && n <= KITTY_UINT32_MAX ? `${key}=${n}` : "";
490
+ }
491
+ function int32Control(key, value) {
492
+ if (value == null) return "";
493
+ const n = Math.floor(value);
494
+ return Number.isSafeInteger(n) && n >= KITTY_INT32_MIN && n <= KITTY_INT32_MAX ? `${key}=${n}` : "";
495
+ }
496
+ function sanitizeBase64(value) {
497
+ const data = String(value ?? "").replace(/\s+/g, "");
498
+ return isBase64ish(data) ? data : "";
499
+ }
500
+ function kittyGraphicCellControls(columns, rows) {
501
+ if (columns == null && rows == null) return [];
502
+ const size = normalizeTerminalGraphicSize(columns ?? 1, rows ?? 1);
503
+ if (!size) return [];
504
+ return [columns == null ? "" : `c=${size.width}`, rows == null ? "" : `r=${size.height}`];
505
+ }
506
+ function kittyGraphicSourceControls(sourceX, sourceY, sourceWidth, sourceHeight) {
507
+ return [
508
+ uint32Control("x", sourceX),
509
+ uint32Control("y", sourceY),
510
+ uint32Control("w", sourceWidth, 1),
511
+ uint32Control("h", sourceHeight, 1)
512
+ ];
513
+ }
514
+ function chunkBase64(value, chunkSize) {
515
+ const normalizedSize = Math.max(4, Math.floor(chunkSize / 4) * 4);
516
+ const chunks = [];
517
+ for (let index = 0; index < value.length; index += normalizedSize) chunks.push(value.slice(index, index + normalizedSize));
518
+ return chunks.length ? chunks : [""];
519
+ }
520
+ function createKittyPlacementSequence(options) {
521
+ const imageId = uint32Control("i", options.imageId);
522
+ const imageNumber = uint32Control("I", options.imageNumber);
523
+ if (!imageId && !imageNumber) return "";
524
+ const controls = [
525
+ "a=p",
526
+ options.quiet === false ? "" : "q=2",
527
+ options.noCursorMove === false ? "" : "C=1",
528
+ imageId,
529
+ imageNumber,
530
+ uint32Control("p", options.placementId),
531
+ ...kittyGraphicCellControls(options.columns, options.rows),
532
+ ...kittyGraphicSourceControls(options.sourceX, options.sourceY, options.sourceWidth, options.sourceHeight),
533
+ int32Control("z", options.zIndex)
534
+ ].filter(Boolean);
535
+ return `${ESC}_G${controls.join(",")}${ST}`;
536
+ }
537
+ function createKittyGraphicsSequence(base64Png, options = {}) {
538
+ const data = sanitizeBase64(base64Png);
539
+ if (!data) return "";
540
+ const chunks = chunkBase64(data, options.chunkSize ?? 4096);
541
+ const baseControls = [
542
+ "a=T",
543
+ "f=100",
544
+ options.quiet === false ? "" : "q=2",
545
+ options.noCursorMove === false ? "" : "C=1",
546
+ uint32Control("i", options.imageId),
547
+ uint32Control("I", options.imageNumber),
548
+ uint32Control("p", options.placementId),
549
+ ...kittyGraphicCellControls(options.columns, options.rows),
550
+ ...kittyGraphicSourceControls(options.sourceX, options.sourceY, options.sourceWidth, options.sourceHeight),
551
+ int32Control("z", options.zIndex)
552
+ ].filter(Boolean);
553
+ return chunks.map((chunk, index) => {
554
+ const last = index === chunks.length - 1;
555
+ const controls = index === 0 ? [...baseControls, chunks.length > 1 ? `m=${last ? 0 : 1}` : ""] : [options.quiet === false ? "" : "q=2", `m=${last ? 0 : 1}`].filter(Boolean);
556
+ return `${ESC}_G${controls.filter(Boolean).join(",")};${chunk}${ST}`;
557
+ }).join("");
558
+ }
559
+ function createKittyDeleteGraphicsSequence(options = {}) {
560
+ const controls = ["a=d"];
561
+ if (options.allVisible) controls.push(`d=${options.freeImageData ? "A" : "a"}`);
562
+ else if (options.imageId != null) {
563
+ const imageId = uint32Control("i", options.imageId);
564
+ const placementId = uint32Control("p", options.placementId);
565
+ if (!imageId || options.placementId != null && !placementId) return "";
566
+ controls.push(`d=${options.freeImageData ? "I" : "i"}`);
567
+ controls.push(imageId);
568
+ controls.push(placementId);
569
+ } else if (options.currentCell) controls.push(`d=${options.freeImageData ? "C" : "c"}`);
570
+ else return "";
571
+ if (options.quiet !== false) controls.push("q=2");
572
+ return `${ESC}_G${controls.filter(Boolean).join(",")}${ST}`;
573
+ }
574
+ function createIterm2InlineImageSequence(base64Data, options = {}) {
575
+ const data = sanitizeBase64(base64Data);
576
+ if (!data) return "";
577
+ const params = [
578
+ "inline=1",
579
+ options.width != null ? `width=${formatItermDimension(options.width)}` : "",
580
+ options.height != null ? `height=${formatItermDimension(options.height)}` : "",
581
+ `preserveAspectRatio=${options.preserveAspectRatio === false ? 0 : 1}`,
582
+ options.doNotMoveCursor === false ? "" : "doNotMoveCursor=1"
583
+ ].filter(Boolean);
584
+ return `${ESC}]1337;File=${params.join(";")}:${data}${BEL}`;
585
+ }
586
+ function formatItermDimension(value) {
587
+ if (typeof value === "number") {
588
+ const n = Math.floor(value);
589
+ if (!Number.isFinite(n)) return "auto";
590
+ return String(Math.min(99999, Math.max(1, n)));
591
+ }
592
+ const raw = String(value ?? "").trim();
593
+ return validateIterm2Dimension(raw) ? raw : "auto";
594
+ }
595
+
596
+ //#endregion
597
+ export { canDrawTerminalGraphicRect, createIterm2InlineImageSequence, createKittyDeleteGraphicsSequence, createKittyGraphicsSequence, createKittyPlacementSequence, detectTerminalGraphicsCapabilities, getTerminalGraphicsOutput, getTerminalGraphicsOutputVersion, hashTerminalGraphicsString, isSafeTerminalGraphicsSequence, isTerminalGraphicsProtocol, normalizeTerminalGraphicSize, sanitizeTerminalFallbackText, stableTerminalGraphicNumericId, subscribeTerminalGraphicsOutput };
@@ -88,6 +88,9 @@ function clampPointToRect(point, rect) {
88
88
  y: Math.max(rect.y, Math.min(rect.y + Math.max(0, rect.h - 1), Math.floor(point.y)))
89
89
  };
90
90
  }
91
+ function clipboardCanWrite(api) {
92
+ return api.canWrite ?? api.supported;
93
+ }
91
94
  function createTerminalSelectionController(options) {
92
95
  const state = shallowRef(EMPTY_STATE);
93
96
  let range = null;
@@ -278,7 +281,7 @@ function createTerminalSelectionController(options) {
278
281
  const text = state.value.text || selectedText();
279
282
  if (!text) return false;
280
283
  setResolvedText(text);
281
- if (!options.clipboard.supported) {
284
+ if (!clipboardCanWrite(options.clipboard)) {
282
285
  options.onCopy?.(copyPayload(text, false, new Error("Clipboard unavailable")));
283
286
  return false;
284
287
  }