@simon_he/vue-tui 1.1.5 → 1.1.7

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 (42) hide show
  1. package/README.md +1 -0
  2. package/dist/TAgentTerminalGraphic-B8-YZfuP.js +1198 -0
  3. package/dist/{TSelect-CMBOOFwK.js → TSelect-CCsjjCOr.js} +41 -12
  4. package/dist/{TTree-kk8ntrpg.js → TTree-3W5A2_EH.js} +4 -3
  5. package/dist/TVideo-D9AOiyq2.js +948 -0
  6. package/dist/agent.cjs +5204 -4312
  7. package/dist/agent.js +11 -9
  8. package/dist/{block-source-DhzajB9H.js → block-source-BhvdZomx.js} +246 -53
  9. package/dist/cli.cjs +41 -26
  10. package/dist/cli.js +68 -18
  11. package/dist/core.js +2 -2
  12. package/dist/experimental/browser.cjs +3705 -0
  13. package/dist/experimental/browser.d.cts +3 -0
  14. package/dist/experimental/browser.d.ts +3 -0
  15. package/dist/experimental/browser.js +413 -0
  16. package/dist/experimental.cjs +2 -1
  17. package/dist/experimental.js +9 -947
  18. package/dist/{linkify-CL9wwnZN.js → frame-mailbox-DaTrfyaF.js} +2 -297
  19. package/dist/index.cjs +25 -8
  20. package/dist/index.js +6 -5
  21. package/dist/linkify-CklfA1vp.js +298 -0
  22. package/dist/markdown.cjs +5196 -4322
  23. package/dist/markdown.js +4 -4
  24. package/dist/{mermaid-N3kGTHFy.js → mermaid-D0ov4_A1.js} +93 -9
  25. package/dist/mermaid.cjs +78 -7
  26. package/dist/mermaid.js +4 -4
  27. package/dist/{path-suggest-Dndu4dTi.js → path-suggest-fPzRsgPv.js} +1 -1
  28. package/dist/renderer/terminal-graphics.d.ts +1 -1
  29. package/dist/{terminal-graphics-2FTRg9x3.js → terminal-graphics-DpSL29OQ.js} +3 -3
  30. package/dist/{tlog-theme-B91Wv7Zj.js → tlog-theme-BnILsD3n.js} +10 -1203
  31. package/dist/vue/browser/types.d.ts +52 -0
  32. package/dist/vue/components/TAgentTerminalGraphic.d.ts +3 -0
  33. package/dist/vue/components/TBrowser.d.ts +231 -0
  34. package/dist/vue/components/TVirtualMarkdown.d.ts +10 -0
  35. package/dist/vue/markdown/render.d.ts +18 -1
  36. package/dist/vue.cjs +25 -8
  37. package/dist/vue.js +8 -7
  38. package/package.json +27 -2
  39. /package/dist/{TMermaidText-wLnMMvVS.js → TMermaidText-C1akgJPU.js} +0 -0
  40. /package/dist/{math-image-BZhmfUeu.js → math-image-CcUpBnW0.js} +0 -0
  41. /package/dist/{path-mnSgEpCm.js → path-BI9W15Zt.js} +0 -0
  42. /package/dist/{wheel-scroll-DASkEZr-.js → wheel-scroll-CQ22Hcyj.js} +0 -0
@@ -0,0 +1,1198 @@
1
+ import { TerminalGraphicsActivityKey, intersectRect, nowTerminalGraphicTraceTime, padEndByCells$1 as padEndByCells, recordTerminalGraphicTrace, sanitizeTextBlock, sliceByCells, sliceByCellsRange, spaces, translateRect, useLayout, useRenderNode, useTerminal, useVisibility, withTextWidthProvider } from "./rect-JzWMJxxc.js";
2
+ import { canDrawTerminalGraphicRect, createKittyDeleteGraphicsSequence, createKittyPlacementSequence, getTerminalGraphicsOutput, getTerminalGraphicsOutputVersion, isSafeTerminalGraphicsSequence, isTerminalGraphicsProtocol, normalizeTerminalGraphicSize, sanitizeTerminalFallbackText, stableTerminalGraphicNumericId, subscribeTerminalGraphicsOutput } from "./terminal-graphics-DpSL29OQ.js";
3
+ import { computed, defineComponent, getCurrentInstance, h, inject, markRaw, onBeforeUnmount, shallowRef, watch } from "vue";
4
+
5
+ //#region src/vue/components/TAgentTerminalGraphic.ts
6
+ const NO_GRAPHICS_CAPABILITIES = Object.freeze({
7
+ supported: false,
8
+ kitty: false,
9
+ iterm2: false,
10
+ sixel: false,
11
+ preferredProtocol: null,
12
+ protocol: "unicode",
13
+ candidates: [],
14
+ stdoutIsTTY: false,
15
+ insideTmux: false,
16
+ insideScreen: false,
17
+ insideZellij: false,
18
+ multiplexer: null,
19
+ passthrough: false,
20
+ forced: false,
21
+ reason: "no-terminal-graphics-output"
22
+ });
23
+ function splitTextOutput(value) {
24
+ const normalized = sanitizeTextBlock(sanitizeTerminalFallbackText(value).replace(/\r\n?/g, "\n"));
25
+ const lines = normalized.split("\n");
26
+ return lines.length ? lines : [""];
27
+ }
28
+ function hasVisibleOutput(value) {
29
+ return value.some((line) => line.trim().length > 0);
30
+ }
31
+ function errorMessage(error) {
32
+ return error instanceof Error ? error.message : String(error);
33
+ }
34
+ function positiveInt(value) {
35
+ const n = Math.floor(Number(value));
36
+ return Number.isFinite(n) && n > 0 ? n : void 0;
37
+ }
38
+ function finiteInt(value) {
39
+ const n = Math.floor(Number(value));
40
+ return Number.isFinite(n) ? n : void 0;
41
+ }
42
+ function clampNumber(value, min, max) {
43
+ return Math.max(min, Math.min(max, value));
44
+ }
45
+ function rectArea(rect) {
46
+ return Math.max(0, rect.w) * Math.max(0, rect.h);
47
+ }
48
+ function sameRect(a, b) {
49
+ return a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
50
+ }
51
+ function subtractRect(rect, cover) {
52
+ const hit = intersectRect(rect, cover);
53
+ if (!hit) return [rect];
54
+ const out = [];
55
+ const rectRight = rect.x + rect.w;
56
+ const rectBottom = rect.y + rect.h;
57
+ const hitRight = hit.x + hit.w;
58
+ const hitBottom = hit.y + hit.h;
59
+ if (hit.y > rect.y) out.push({
60
+ x: rect.x,
61
+ y: rect.y,
62
+ w: rect.w,
63
+ h: hit.y - rect.y
64
+ });
65
+ if (hitBottom < rectBottom) out.push({
66
+ x: rect.x,
67
+ y: hitBottom,
68
+ w: rect.w,
69
+ h: rectBottom - hitBottom
70
+ });
71
+ if (hit.x > rect.x) out.push({
72
+ x: rect.x,
73
+ y: hit.y,
74
+ w: hit.x - rect.x,
75
+ h: hit.h
76
+ });
77
+ if (hitRight < rectRight) out.push({
78
+ x: hitRight,
79
+ y: hit.y,
80
+ w: rectRight - hitRight,
81
+ h: hit.h
82
+ });
83
+ return out.filter((part) => part.w > 0 && part.h > 0);
84
+ }
85
+ function largestUncoveredRect(rect, covers) {
86
+ let parts = [rect];
87
+ for (const cover of covers) {
88
+ parts = parts.flatMap((part) => subtractRect(part, cover));
89
+ if (!parts.length) return null;
90
+ }
91
+ parts.sort((a, b) => rectArea(b) - rectArea(a) || a.y - b.y || a.x - b.x);
92
+ return parts[0] ?? null;
93
+ }
94
+ function parseKittyClearControls(sequence) {
95
+ const prefix = "\x1B_G";
96
+ const terminator = "\x1B\\";
97
+ if (!sequence.startsWith(prefix) || !sequence.endsWith(terminator)) return null;
98
+ const body = sequence.slice(prefix.length, -terminator.length);
99
+ if (body.includes(terminator) || body.includes("\x1B") || body.includes("\x07")) return null;
100
+ const semicolon = body.indexOf(";");
101
+ const rawControls = semicolon >= 0 ? body.slice(0, semicolon) : body;
102
+ const controls = new Map();
103
+ for (const part of rawControls.split(",")) {
104
+ const eq = part.indexOf("=");
105
+ if (eq <= 0) return null;
106
+ controls.set(part.slice(0, eq), part.slice(eq + 1));
107
+ }
108
+ return controls;
109
+ }
110
+ function kittyClearTargetsComponent(sequence, imageId, placementId) {
111
+ const controls = parseKittyClearControls(sequence);
112
+ if (!controls) return false;
113
+ const mode = controls.get("d");
114
+ if (mode !== "i" && mode !== "I") return false;
115
+ return controls.get("i") === String(imageId) && controls.get("p") === String(placementId);
116
+ }
117
+ function isSafeComponentClearSequence(sequence, protocol, imageId, placementId) {
118
+ if (!isSafeTerminalGraphicsSequence(sequence, protocol, "clear")) return false;
119
+ return protocol !== "kitty" || kittyClearTargetsComponent(sequence, imageId, placementId);
120
+ }
121
+ let textEncoder = null;
122
+ function stringByteLength(value) {
123
+ if (typeof TextEncoder !== "undefined") {
124
+ textEncoder ?? (textEncoder = new TextEncoder());
125
+ return textEncoder.encode(value).length;
126
+ }
127
+ let bytes = 0;
128
+ for (let index = 0; index < value.length; index++) {
129
+ const code = value.charCodeAt(index);
130
+ if (code <= 127) bytes += 1;
131
+ else if (code <= 2047) bytes += 2;
132
+ else if (code >= 55296 && code <= 56319 && index + 1 < value.length) {
133
+ bytes += 4;
134
+ index++;
135
+ } else bytes += 3;
136
+ }
137
+ return bytes;
138
+ }
139
+ function smallHash(input) {
140
+ let hash = 2166136261;
141
+ for (let i = 0; i < input.length; i++) {
142
+ hash ^= input.charCodeAt(i);
143
+ hash = Math.imul(hash, 16777619);
144
+ }
145
+ return (hash >>> 0).toString(36);
146
+ }
147
+ const tAgentTerminalGraphicProps = {
148
+ x: {
149
+ type: Number,
150
+ required: true
151
+ },
152
+ y: {
153
+ type: Number,
154
+ required: true
155
+ },
156
+ w: {
157
+ type: Number,
158
+ required: true
159
+ },
160
+ h: {
161
+ type: Number,
162
+ default: void 0
163
+ },
164
+ zIndex: {
165
+ type: Number,
166
+ default: 0
167
+ },
168
+ content: {
169
+ type: String,
170
+ required: true
171
+ },
172
+ kind: {
173
+ type: String,
174
+ default: "image"
175
+ },
176
+ fallback: {
177
+ type: String,
178
+ default: void 0
179
+ },
180
+ style: {
181
+ type: Object,
182
+ default: void 0
183
+ },
184
+ loadingStyle: {
185
+ type: Object,
186
+ default: void 0
187
+ },
188
+ errorStyle: {
189
+ type: Object,
190
+ default: void 0
191
+ },
192
+ clear: {
193
+ type: Boolean,
194
+ default: true
195
+ },
196
+ final: {
197
+ type: Boolean,
198
+ default: true
199
+ },
200
+ streaming: {
201
+ type: Boolean,
202
+ default: false
203
+ },
204
+ renderer: {
205
+ type: Function,
206
+ default: void 0
207
+ },
208
+ loadingText: {
209
+ type: String,
210
+ default: "Rendering terminal graphic..."
211
+ },
212
+ deferRenderUntilVisible: {
213
+ type: Boolean,
214
+ default: true
215
+ },
216
+ suspendRawWhileScrolling: {
217
+ type: Boolean,
218
+ default: true
219
+ },
220
+ suspendRenderWhileScrolling: {
221
+ type: Boolean,
222
+ default: true
223
+ },
224
+ scrolling: {
225
+ type: Boolean,
226
+ default: false
227
+ },
228
+ scrollVersion: {
229
+ type: Number,
230
+ default: 0
231
+ },
232
+ placementMoveWithoutClear: {
233
+ type: Boolean,
234
+ default: false
235
+ },
236
+ preserveRawWhileRendering: {
237
+ type: Boolean,
238
+ default: false
239
+ },
240
+ suspended: {
241
+ type: Boolean,
242
+ default: false
243
+ },
244
+ retainRawWhileCovered: {
245
+ type: Boolean,
246
+ default: false
247
+ },
248
+ ignoreRawCoverage: {
249
+ type: Boolean,
250
+ default: false
251
+ },
252
+ ignoreSamePlaneRawCoverage: {
253
+ type: Boolean,
254
+ default: false
255
+ },
256
+ cacheKey: {
257
+ type: String,
258
+ default: void 0
259
+ },
260
+ placementKey: {
261
+ type: String,
262
+ default: void 0
263
+ },
264
+ trace: {
265
+ type: Function,
266
+ default: void 0
267
+ }
268
+ };
269
+ function terminalDrawKey(current, rect, clearSequence, resizeSequence) {
270
+ return [
271
+ current.protocol,
272
+ rect.x,
273
+ rect.y,
274
+ rect.w,
275
+ rect.h,
276
+ current.sequenceHash,
277
+ clearSequence === current.clearSequence ? current.clearSequenceHash ?? "" : smallHash(clearSequence ?? ""),
278
+ resizeSequence === current.resizeSequence ? current.resizeSequenceHash ?? "" : smallHash(resizeSequence ?? "")
279
+ ].join(":");
280
+ }
281
+ const TAgentTerminalGraphic = defineComponent({
282
+ name: "TAgentTerminalGraphic",
283
+ props: tAgentTerminalGraphicProps,
284
+ setup(props) {
285
+ const instance = getCurrentInstance();
286
+ const { terminal, defaultStyle, scheduler, widthProvider, render } = useTerminal();
287
+ const layout = useLayout();
288
+ const { visible, rootProps } = useVisibility();
289
+ const graphicsActivity = inject(TerminalGraphicsActivityKey, null);
290
+ const status = shallowRef("idle");
291
+ const error = shallowRef("");
292
+ const graphic = shallowRef(null);
293
+ const documentVersion = shallowRef(0);
294
+ let builtOnce = false;
295
+ let renderVersion = 0;
296
+ let renderAbort = null;
297
+ let alive = true;
298
+ let lastRenderedContent = "";
299
+ let lastRenderRawVisible = false;
300
+ let lastRenderProtocol = null;
301
+ let lastRenderGraphicsOutputVersion = 0;
302
+ const rawIdSeed = props.placementKey ? `placement:${props.placementKey}` : props.cacheKey ? `cache:${props.cacheKey}` : `instance:${instance?.uid ?? "unknown"}`;
303
+ const rawId = `TAgentTerminalGraphic:${smallHash(rawIdSeed)}`;
304
+ const frameTaskId = `${rawId}:render`;
305
+ const lastDrawnGraphic = shallowRef(null);
306
+ const rawClearPendingRepaint = shallowRef(null);
307
+ const rawDrawRejectedKey = shallowRef(null);
308
+ const reservedTerminalGraphicSize = shallowRef(null);
309
+ const terminalSizeVersion = shallowRef(0);
310
+ const renderNodeId = shallowRef(null);
311
+ let lastRawSkipScrollKey = "";
312
+ let lastDeferTraceKey = "";
313
+ const isParentScrolling = computed(() => props.scrolling || Boolean(graphicsActivity?.scrolling.value));
314
+ const graphicsActivityVersion = computed(() => (graphicsActivity?.version.value ?? 0) + Math.floor(Number(props.scrollVersion ?? 0)));
315
+ const graphicsOutput = () => getTerminalGraphicsOutput(terminal);
316
+ const graphicsOutputVersion = shallowRef(getTerminalGraphicsOutputVersion(terminal));
317
+ const unsubscribeGraphicsOutput = subscribeTerminalGraphicsOutput(terminal, () => {
318
+ graphicsOutputVersion.value = getTerminalGraphicsOutputVersion(terminal);
319
+ });
320
+ const unsubscribeTerminalResize = terminal.on("resize", () => {
321
+ terminalSizeVersion.value++;
322
+ });
323
+ const fallbackText = () => props.fallback ?? (props.kind === "math" ? props.content : "");
324
+ const contentIdentity = computed(() => `${props.content.length}:${smallHash(props.content)}`);
325
+ const stableGraphicKey = computed(() => [
326
+ rawIdSeed,
327
+ props.cacheKey ?? "",
328
+ props.kind,
329
+ contentIdentity.value,
330
+ props.w,
331
+ props.h ?? "",
332
+ props.final ? "final" : "draft"
333
+ ].join(""));
334
+ const imageId = computed(() => stableTerminalGraphicNumericId(`image:${stableGraphicKey.value}`));
335
+ const placementId = computed(() => stableTerminalGraphicNumericId(`placement:${stableGraphicKey.value}`));
336
+ function rememberTerminalGraphicSize(current) {
337
+ if (current.type !== "terminal") return;
338
+ const rows = positiveInt(current.rows);
339
+ if (!rows) return;
340
+ reservedTerminalGraphicSize.value = {
341
+ key: stableGraphicKey.value,
342
+ rows
343
+ };
344
+ }
345
+ function bump() {
346
+ documentVersion.value++;
347
+ }
348
+ function currentCapabilities() {
349
+ return graphicsOutput()?.capabilities ?? NO_GRAPHICS_CAPABILITIES;
350
+ }
351
+ function trace(type, extra = {}) {
352
+ const capabilities = currentCapabilities();
353
+ try {
354
+ props.trace?.({
355
+ type,
356
+ id: rawId,
357
+ kind: props.kind,
358
+ protocol: capabilities.protocol,
359
+ contentHash: smallHash(props.content),
360
+ ...extra
361
+ });
362
+ } catch {}
363
+ const protocol = isTerminalGraphicsProtocol(capabilities.protocol) ? capabilities.protocol : void 0;
364
+ const key = props.cacheKey ?? smallHash(props.content);
365
+ if (type === "render-start") recordTerminalGraphicTrace({
366
+ type: "renderer-start",
367
+ id: rawId,
368
+ key,
369
+ protocol
370
+ });
371
+ else if (type === "render-end") recordTerminalGraphicTrace({
372
+ type: extra.reason ? "renderer-error" : "renderer-end",
373
+ id: rawId,
374
+ key,
375
+ protocol,
376
+ durationMs: extra.durationMs,
377
+ bytes: extra.sequenceBytes,
378
+ error: extra.reason
379
+ });
380
+ else if (type === "defer") recordTerminalGraphicTrace({
381
+ type: extra.reason === "scrolling" ? "skip-scrolling" : "skip-hidden",
382
+ id: rawId,
383
+ key,
384
+ protocol,
385
+ reason: extra.reason
386
+ });
387
+ else if (type === "raw-draw") {} else if (type === "render-abort") recordTerminalGraphicTrace({
388
+ type: "renderer-abort",
389
+ id: rawId,
390
+ key,
391
+ protocol,
392
+ reason: extra.reason
393
+ });
394
+ else if (type === "raw-clear") recordTerminalGraphicTrace({
395
+ type: "clear",
396
+ id: rawId,
397
+ key,
398
+ protocol
399
+ });
400
+ else if (type === "raw-skip-scroll") recordTerminalGraphicTrace({
401
+ type: "skip-scrolling",
402
+ id: rawId,
403
+ key,
404
+ protocol,
405
+ reason: extra.reason
406
+ });
407
+ }
408
+ function traceDeferOnce(reason) {
409
+ const key = [
410
+ reason,
411
+ graphicsActivityVersion.value,
412
+ stableGraphicKey.value
413
+ ].join(":");
414
+ if (lastDeferTraceKey === key) return;
415
+ lastDeferTraceKey = key;
416
+ trace("defer", { reason });
417
+ }
418
+ function abortCurrentRender(reason) {
419
+ if (!renderAbort) return;
420
+ renderAbort.abort();
421
+ renderAbort = null;
422
+ trace("render-abort", { reason });
423
+ }
424
+ function normalizeResult(result) {
425
+ if (result == null) return {
426
+ type: "text",
427
+ text: fallbackText()
428
+ };
429
+ if (typeof result === "string") return {
430
+ type: "text",
431
+ text: result
432
+ };
433
+ if (typeof result !== "object") return {
434
+ type: "text",
435
+ text: fallbackText()
436
+ };
437
+ if ("type" in result && result.type === "text") return {
438
+ type: "text",
439
+ text: result.text
440
+ };
441
+ const maybeRaw = result;
442
+ const isRawCandidate = maybeRaw.type === "sequence" || "sequence" in result || "protocol" in result;
443
+ if (!isRawCandidate && "text" in result) return {
444
+ type: "text",
445
+ text: result.text
446
+ };
447
+ const sequence = typeof maybeRaw.sequence === "string" ? maybeRaw.sequence : "";
448
+ const protocol = isTerminalGraphicsProtocol(maybeRaw.protocol) ? maybeRaw.protocol : null;
449
+ const fallback = typeof maybeRaw.fallback === "string" ? sanitizeTerminalFallbackText(maybeRaw.fallback) : fallbackText();
450
+ const fallbackFromProps = typeof maybeRaw.fallback !== "string";
451
+ if (!sequence || !protocol || !isSafeTerminalGraphicsSequence(sequence, protocol, "draw")) return {
452
+ type: "text",
453
+ text: fallback
454
+ };
455
+ const rawClear = typeof maybeRaw.clearSequence === "string" ? maybeRaw.clearSequence : void 0;
456
+ const clearSequence = rawClear && isSafeComponentClearSequence(rawClear, protocol, imageId.value, placementId.value) ? rawClear : void 0;
457
+ const rawResize = typeof maybeRaw.resizeSequence === "string" ? maybeRaw.resizeSequence : void 0;
458
+ const resizeSequence = rawResize && isSafeTerminalGraphicsSequence(rawResize, protocol, "draw") ? rawResize : void 0;
459
+ const declaredRows = positiveInt(maybeRaw.rows);
460
+ const declaredCols = positiveInt(maybeRaw.cols);
461
+ const sourceWidth = positiveInt(maybeRaw.sourceWidth);
462
+ const sourceHeight = positiveInt(maybeRaw.sourceHeight);
463
+ const zIndex = finiteInt(maybeRaw.zIndex);
464
+ const declaredSize = declaredRows == null ? null : normalizeTerminalGraphicSize(declaredCols ?? props.w, declaredRows);
465
+ return {
466
+ type: "terminal",
467
+ protocol,
468
+ sequence,
469
+ sequenceHash: smallHash(sequence),
470
+ sequenceBytes: stringByteLength(sequence),
471
+ fallback,
472
+ fallbackFromProps,
473
+ clearSequence,
474
+ clearSequenceHash: clearSequence ? smallHash(clearSequence) : void 0,
475
+ resizeSequence,
476
+ resizeSequenceHash: resizeSequence ? smallHash(resizeSequence) : void 0,
477
+ cols: declaredRows == null ? declaredCols : declaredSize?.width,
478
+ rows: declaredSize?.height,
479
+ sourceWidth,
480
+ sourceHeight,
481
+ zIndex
482
+ };
483
+ }
484
+ function defaultClearSequence(protocol) {
485
+ return protocol === "kitty" ? createKittyDeleteGraphicsSequence({
486
+ imageId: imageId.value,
487
+ placementId: placementId.value
488
+ }) : "";
489
+ }
490
+ function resolveClearSequence(current) {
491
+ if (current.clearSequence) return current.clearSequence;
492
+ const candidate = defaultClearSequence(current.protocol);
493
+ if (!candidate) return void 0;
494
+ return isSafeComponentClearSequence(candidate, current.protocol, imageId.value, placementId.value) ? candidate : void 0;
495
+ }
496
+ function resolveResizeSequence(current, rect, full) {
497
+ if (current.protocol !== "kitty") return current.resizeSequence;
498
+ const sourceWidth = positiveInt(current.sourceWidth);
499
+ const sourceHeight = positiveInt(current.sourceHeight);
500
+ if (!sourceWidth || !sourceHeight || full.w <= 0 || full.h <= 0) return current.resizeSequence;
501
+ const offsetX = Math.max(0, rect.x - full.x);
502
+ const offsetY = Math.max(0, rect.y - full.y);
503
+ const visibleW = Math.max(0, Math.min(rect.w, full.w - offsetX));
504
+ const visibleH = Math.max(0, Math.min(rect.h, full.h - offsetY));
505
+ const x0 = clampNumber(Math.floor(offsetX * sourceWidth / full.w), 0, sourceWidth - 1);
506
+ const y0 = clampNumber(Math.floor(offsetY * sourceHeight / full.h), 0, sourceHeight - 1);
507
+ const x1 = Math.max(x0 + 1, clampNumber(Math.ceil((offsetX + visibleW) * sourceWidth / full.w), 1, sourceWidth));
508
+ const y1 = Math.max(y0 + 1, clampNumber(Math.ceil((offsetY + visibleH) * sourceHeight / full.h), 1, sourceHeight));
509
+ return createKittyPlacementSequence({
510
+ imageId: imageId.value,
511
+ placementId: placementId.value,
512
+ columns: rect.w,
513
+ rows: rect.h,
514
+ sourceX: x0,
515
+ sourceY: y0,
516
+ sourceWidth: x1 - x0,
517
+ sourceHeight: y1 - y0,
518
+ zIndex: current.zIndex
519
+ });
520
+ }
521
+ function queueClearLastGraphic(options = {}) {
522
+ const previous = lastDrawnGraphic.value;
523
+ if (!previous) return false;
524
+ const output = graphicsOutput();
525
+ let accepted = false;
526
+ if (output?.clear && !previous.retainOnClear) try {
527
+ accepted = Boolean(output.clear(previous.id));
528
+ } catch {
529
+ accepted = false;
530
+ }
531
+ if (!accepted && output && previous.clearSequence) try {
532
+ accepted = output.queue({
533
+ id: previous.id,
534
+ x: previous.x,
535
+ y: previous.y,
536
+ w: previous.w,
537
+ h: previous.h,
538
+ protocol: previous.protocol,
539
+ sequence: previous.clearSequence,
540
+ deferFlush: true,
541
+ retainOnClear: previous.retainOnClear,
542
+ op: "clear"
543
+ });
544
+ } catch {
545
+ accepted = false;
546
+ }
547
+ if (accepted) {
548
+ if (options.markPendingRepaint ?? true) rawClearPendingRepaint.value = previous;
549
+ lastDrawnGraphic.value = null;
550
+ trace("raw-clear", {
551
+ x: previous.x,
552
+ y: previous.y,
553
+ w: previous.w,
554
+ h: previous.h
555
+ });
556
+ }
557
+ return accepted;
558
+ }
559
+ function queueDrawGraphic(output, current, rect, full = rect, options = {}) {
560
+ const clearSequence = resolveClearSequence(current);
561
+ const resizeSequence = resolveResizeSequence(current, rect, full);
562
+ const drawKey = terminalDrawKey(current, rect, clearSequence, resizeSequence);
563
+ const activePrevious = lastDrawnGraphic.value;
564
+ const retainedPrevious = rawClearPendingRepaint.value;
565
+ const previous = activePrevious ?? retainedPrevious;
566
+ const previousIsRetained = activePrevious == null && retainedPrevious != null;
567
+ const previousStillActive = previous ? typeof output.isActive === "function" ? output.isActive(previous.id) : true : false;
568
+ const preservePreviousForAtomicReplace = props.preserveRawWhileRendering && activePrevious != null && !previousIsRetained && previousStillActive;
569
+ if (!previousIsRetained && !options.force && previous?.drawKey === drawKey && previousStillActive) return false;
570
+ const canReusePlacementSequence = previousStillActive && previous?.protocol === current.protocol && previous.sequenceHash === current.sequenceHash && current.protocol === "kitty" && Boolean(resizeSequence);
571
+ const scrollVersion = Math.floor(Number(props.scrollVersion ?? 0));
572
+ const canMoveWithoutClear = canReusePlacementSequence && Boolean(options.placementMoveWithoutClear);
573
+ if (!previousIsRetained && previousStillActive && !resizeSequence && previous?.protocol === current.protocol && previous.sequenceHash === current.sequenceHash && previous.x === rect.x && previous.y === rect.y && rect.w <= previous.w && rect.h <= previous.h && (options.force || !sameRect(rect, full))) {
574
+ lastDrawnGraphic.value = {
575
+ ...previous,
576
+ w: rect.w,
577
+ h: rect.h,
578
+ clearSequence,
579
+ resizeSequence,
580
+ drawKey,
581
+ activityVersion: graphicsActivityVersion.value,
582
+ scrollVersion
583
+ };
584
+ lastRawSkipScrollKey = "";
585
+ return false;
586
+ }
587
+ if (previousStillActive && !previousIsRetained && !canReusePlacementSequence && !preservePreviousForAtomicReplace) {
588
+ if (!queueClearLastGraphic({ markPendingRepaint: false })) return false;
589
+ } else if (previous) {
590
+ if (!previousStillActive) {
591
+ lastDrawnGraphic.value = null;
592
+ rawClearPendingRepaint.value = null;
593
+ }
594
+ }
595
+ let accepted = false;
596
+ try {
597
+ accepted = output.queue({
598
+ id: rawId,
599
+ x: rect.x,
600
+ y: rect.y,
601
+ w: rect.w,
602
+ h: rect.h,
603
+ protocol: current.protocol,
604
+ sequence: canReusePlacementSequence && resizeSequence ? resizeSequence : current.sequence,
605
+ resizeSequence,
606
+ clearSequence,
607
+ retainOnClear: Boolean(props.cacheKey && resizeSequence),
608
+ resizeRedraw: canReusePlacementSequence,
609
+ placementMoveWithoutClear: canMoveWithoutClear,
610
+ allowTextOverlay: options.allowTextOverlay,
611
+ forceDraw: options.force,
612
+ deferFlush: options.deferFlush ?? true,
613
+ fallbackText: current.fallback
614
+ });
615
+ } catch {
616
+ accepted = false;
617
+ }
618
+ if (!accepted) {
619
+ if (preservePreviousForAtomicReplace) {
620
+ lastDrawnGraphic.value = activePrevious;
621
+ queueClearLastGraphic({ markPendingRepaint: false });
622
+ } else lastDrawnGraphic.value = null;
623
+ if (rawDrawRejectedKey.value !== drawKey) {
624
+ rawDrawRejectedKey.value = drawKey;
625
+ scheduler.invalidate({
626
+ priority: "low",
627
+ reason: "data"
628
+ });
629
+ }
630
+ return false;
631
+ }
632
+ rawDrawRejectedKey.value = null;
633
+ rawClearPendingRepaint.value = null;
634
+ lastDrawnGraphic.value = {
635
+ id: rawId,
636
+ x: rect.x,
637
+ y: rect.y,
638
+ w: rect.w,
639
+ h: rect.h,
640
+ protocol: current.protocol,
641
+ sequenceHash: current.sequenceHash,
642
+ clearSequence,
643
+ resizeSequence,
644
+ retainOnClear: Boolean(props.cacheKey && resizeSequence),
645
+ allowTextOverlay: Boolean(options.allowTextOverlay),
646
+ drawKey,
647
+ activityVersion: graphicsActivityVersion.value,
648
+ scrollVersion
649
+ };
650
+ lastRawSkipScrollKey = "";
651
+ return true;
652
+ }
653
+ function hasRetainedActiveRawGraphic() {
654
+ const output = graphicsOutput();
655
+ return Boolean(status.value === "loading" && !graphic.value && output && typeof output.isActive === "function" && output.isActive(rawId));
656
+ }
657
+ const showingInitialLoadingText = computed(() => status.value === "loading" && !graphic.value && !hasRetainedActiveRawGraphic());
658
+ const fullRect = computed(() => {
659
+ const current = graphic.value;
660
+ const reserved = reservedTerminalGraphicSize.value;
661
+ const reservedRows = current?.type === "terminal" ? void 0 : status.value === "idle" && reserved?.key === stableGraphicKey.value ? reserved.rows : void 0;
662
+ const textLines = current?.type === "text" ? splitTextOutput(current.text) : splitTextOutput(fallbackText());
663
+ const height = props.h ?? (current?.type === "terminal" ? current.rows : void 0) ?? reservedRows ?? Math.max(1, textLines.length);
664
+ return translateRect({
665
+ x: props.x,
666
+ y: props.y,
667
+ w: props.w,
668
+ h: height
669
+ }, layout.originX, layout.originY);
670
+ });
671
+ const absRect = computed(() => {
672
+ terminalSizeVersion.value;
673
+ const translated = fullRect.value;
674
+ const size = terminal.size();
675
+ const terminalClip = {
676
+ x: 0,
677
+ y: 0,
678
+ w: Math.max(0, Math.floor(size.cols)),
679
+ h: Math.max(0, Math.floor(size.rows))
680
+ };
681
+ const clip = layout.clipRect ? intersectRect(layout.clipRect, terminalClip) : terminalClip;
682
+ if (!clip) return {
683
+ x: 0,
684
+ y: 0,
685
+ w: 0,
686
+ h: 0
687
+ };
688
+ return intersectRect(translated, clip) ?? {
689
+ x: 0,
690
+ y: 0,
691
+ w: 0,
692
+ h: 0
693
+ };
694
+ });
695
+ const renderRect = computed(() => absRect.value);
696
+ function rawRectFitsTerminalViewport(rect) {
697
+ return canDrawTerminalGraphicRect(rect, terminal.size());
698
+ }
699
+ function rawCoveredByHigherRenderNode(rect = fullRect.value) {
700
+ if (props.retainRawWhileCovered) return false;
701
+ const id = renderNodeId.value;
702
+ return !props.ignoreRawCoverage && id != null && render.isRectCoveredByHigherNode(id, rect, { ignoreSamePlane: props.ignoreSamePlaneRawCoverage });
703
+ }
704
+ function retainedRawCoveredByHigherRenderNode(rect) {
705
+ if (!props.retainRawWhileCovered) return false;
706
+ const id = renderNodeId.value;
707
+ return Boolean(id != null && render.isRectCoveredByHigherNode(id, rect, { ignoreSamePlane: props.ignoreSamePlaneRawCoverage }));
708
+ }
709
+ function rawUncoveredRenderRect(rect) {
710
+ if (props.retainRawWhileCovered) return rect;
711
+ const id = renderNodeId.value;
712
+ if (id == null) return rect;
713
+ const covers = render.higherNodeCoverageRects(id, rect, { ignoreSamePlane: props.ignoreSamePlaneRawCoverage });
714
+ if (!covers.length) return rect;
715
+ if (!props.ignoreRawCoverage) return null;
716
+ return largestUncoveredRect(rect, covers);
717
+ }
718
+ const rawCanRender = computed(() => {
719
+ graphicsOutputVersion.value;
720
+ terminalSizeVersion.value;
721
+ const current = graphic.value;
722
+ const output = graphicsOutput();
723
+ const rect = absRect.value;
724
+ return current?.type === "terminal" && rawRectFitsTerminalViewport(rect) && Boolean(output?.capabilities.supported) && output?.capabilities.preferredProtocol === current.protocol;
725
+ });
726
+ const rawOutputCanRenderValue = computed(() => {
727
+ graphicsOutputVersion.value;
728
+ terminalSizeVersion.value;
729
+ return rawOutputCanRender();
730
+ });
731
+ const rawSuppressedByScroll = computed(() => props.suspended || props.suspendRawWhileScrolling && isParentScrolling.value);
732
+ const rawCanQueue = computed(() => rawCanRender.value && !rawSuppressedByScroll.value);
733
+ function traceRawSkipScrollOnce(reason) {
734
+ const r = absRect.value;
735
+ const key = [
736
+ reason,
737
+ graphicsActivityVersion.value,
738
+ stableGraphicKey.value,
739
+ r.x,
740
+ r.y,
741
+ r.w,
742
+ r.h
743
+ ].join(":");
744
+ if (lastRawSkipScrollKey === key) return;
745
+ lastRawSkipScrollKey = key;
746
+ trace("raw-skip-scroll", { reason });
747
+ }
748
+ function hasPaintableRect() {
749
+ const r = absRect.value;
750
+ return visible.value && r.w > 0 && r.h > 0;
751
+ }
752
+ function rawOutputCanRender() {
753
+ const output = graphicsOutput();
754
+ const rect = absRect.value;
755
+ return rawRectFitsTerminalViewport(rect) && Boolean(output?.capabilities.supported);
756
+ }
757
+ function renderDeferReason() {
758
+ if (props.suspended) return "suspended";
759
+ if (props.deferRenderUntilVisible && !hasPaintableRect()) return "not-visible";
760
+ if (props.suspendRenderWhileScrolling && isParentScrolling.value) return "scrolling";
761
+ return null;
762
+ }
763
+ function shouldDeferRender() {
764
+ return renderDeferReason() != null;
765
+ }
766
+ function shouldRerenderForGraphicsOutputChange() {
767
+ if (!props.renderer) return false;
768
+ if (!props.content.trim()) return false;
769
+ if (shouldDeferRender()) return false;
770
+ if (rawSuppressedByScroll.value) return false;
771
+ const protocol = currentCapabilities().protocol;
772
+ return lastRenderProtocol != null && (lastRenderProtocol !== protocol || lastRenderGraphicsOutputVersion !== graphicsOutputVersion.value);
773
+ }
774
+ function shouldRetryTemporaryRawFallback(rawCovered = rawCoveredByHigherRenderNode()) {
775
+ return Boolean(props.renderer) && props.content.trim().length > 0 && graphic.value?.type === "text" && status.value !== "loading" && !lastRenderRawVisible && rawOutputCanRenderValue.value && !rawSuppressedByScroll.value && !rawCovered;
776
+ }
777
+ function setDeferredFallback(content) {
778
+ graphic.value = {
779
+ type: "text",
780
+ text: content.trim() ? fallbackText() : ""
781
+ };
782
+ lastRenderedContent = content;
783
+ status.value = "idle";
784
+ error.value = "";
785
+ bump();
786
+ }
787
+ function resolveRendererContext(signal) {
788
+ const capabilities = currentCapabilities();
789
+ const visibleNow = hasPaintableRect();
790
+ const rawVisible = rawOutputCanRenderValue.value && !rawSuppressedByScroll.value && !rawCoveredByHigherRenderNode();
791
+ return {
792
+ kind: props.kind,
793
+ width: props.w,
794
+ height: props.h,
795
+ final: props.final,
796
+ streaming: props.streaming,
797
+ protocol: capabilities.protocol,
798
+ capabilities,
799
+ signal,
800
+ imageId: imageId.value,
801
+ placementId: placementId.value,
802
+ visible: visibleNow,
803
+ rawVisible,
804
+ scrolling: isParentScrolling.value,
805
+ cacheKey: props.cacheKey,
806
+ viewport: {
807
+ visible: visibleNow,
808
+ rawVisible,
809
+ scrolling: isParentScrolling.value,
810
+ rect: absRect.value,
811
+ fullRect: fullRect.value
812
+ }
813
+ };
814
+ }
815
+ async function renderNow(version) {
816
+ const protocol = currentCapabilities().protocol;
817
+ recordTerminalGraphicTrace({
818
+ type: "request",
819
+ id: rawId,
820
+ key: props.cacheKey ?? smallHash(props.content),
821
+ protocol: isTerminalGraphicsProtocol(protocol) ? protocol : void 0
822
+ });
823
+ const content = props.content;
824
+ if (!content.trim()) {
825
+ abortCurrentRender("superseded");
826
+ if (!alive || version !== renderVersion) return;
827
+ graphic.value = {
828
+ type: "text",
829
+ text: ""
830
+ };
831
+ lastRenderedContent = content;
832
+ status.value = "ready";
833
+ error.value = "";
834
+ bump();
835
+ return;
836
+ }
837
+ const renderer = props.renderer;
838
+ if (!renderer) {
839
+ abortCurrentRender("superseded");
840
+ if (!alive || version !== renderVersion) return;
841
+ graphic.value = {
842
+ type: "text",
843
+ text: fallbackText()
844
+ };
845
+ lastRenderedContent = content;
846
+ status.value = "ready";
847
+ error.value = "";
848
+ bump();
849
+ return;
850
+ }
851
+ const deferred = renderDeferReason();
852
+ if (deferred) {
853
+ abortCurrentRender(deferred);
854
+ if (!alive || version !== renderVersion) return;
855
+ setDeferredFallback(content);
856
+ traceDeferOnce(deferred);
857
+ return;
858
+ }
859
+ abortCurrentRender("superseded");
860
+ lastDeferTraceKey = "";
861
+ const abort = new AbortController();
862
+ renderAbort = abort;
863
+ const startedAt = nowTerminalGraphicTraceTime();
864
+ status.value = "loading";
865
+ error.value = "";
866
+ trace("render-start");
867
+ bump();
868
+ try {
869
+ const contextGraphicsOutputVersion = graphicsOutputVersion.value;
870
+ const context = resolveRendererContext(abort.signal);
871
+ lastRenderRawVisible = context.rawVisible;
872
+ lastRenderProtocol = context.protocol;
873
+ lastRenderGraphicsOutputVersion = contextGraphicsOutputVersion;
874
+ const result = await renderer(content, context);
875
+ if (abort.signal.aborted) return;
876
+ if (!alive || version !== renderVersion) return;
877
+ const normalized = normalizeResult(result);
878
+ rememberTerminalGraphicSize(normalized);
879
+ graphic.value = normalized;
880
+ lastRenderedContent = content;
881
+ status.value = "ready";
882
+ error.value = "";
883
+ trace("render-end", {
884
+ durationMs: nowTerminalGraphicTraceTime() - startedAt,
885
+ sequenceChars: normalized.type === "terminal" ? normalized.sequence.length : 0,
886
+ sequenceBytes: normalized.type === "terminal" ? normalized.sequenceBytes : 0
887
+ });
888
+ bump();
889
+ if (normalized.type === "terminal") scheduler.invalidate({
890
+ priority: "low",
891
+ reason: "data"
892
+ });
893
+ } catch (err) {
894
+ if (abort.signal.aborted) return;
895
+ if (!alive || version !== renderVersion) return;
896
+ graphic.value = {
897
+ type: "text",
898
+ text: fallbackText()
899
+ };
900
+ lastRenderedContent = content;
901
+ status.value = "ready";
902
+ error.value = errorMessage(err);
903
+ trace("render-end", {
904
+ durationMs: nowTerminalGraphicTraceTime() - startedAt,
905
+ reason: error.value
906
+ });
907
+ bump();
908
+ } finally {
909
+ if (renderAbort === abort) renderAbort = null;
910
+ }
911
+ }
912
+ function scheduleRender(options = {}) {
913
+ const version = ++renderVersion;
914
+ if (options.clearLastGraphic ?? !props.preserveRawWhileRendering) queueClearLastGraphic();
915
+ if (!builtOnce || !props.streaming) {
916
+ builtOnce = true;
917
+ renderNow(version);
918
+ return;
919
+ }
920
+ const accepted = scheduler.queueFrameTask({
921
+ id: frameTaskId,
922
+ reason: "stream",
923
+ priority: "low",
924
+ sync: false,
925
+ run: () => {
926
+ if (!alive) return;
927
+ if (version !== renderVersion) return;
928
+ renderNow(version);
929
+ }
930
+ });
931
+ if (accepted === false) renderNow(version);
932
+ }
933
+ watch([
934
+ () => props.content,
935
+ () => props.kind,
936
+ () => props.renderer,
937
+ () => props.w,
938
+ () => props.h,
939
+ () => props.streaming,
940
+ () => props.final,
941
+ () => props.deferRenderUntilVisible,
942
+ () => props.suspendRawWhileScrolling,
943
+ () => props.suspendRenderWhileScrolling,
944
+ () => props.scrolling,
945
+ () => props.preserveRawWhileRendering,
946
+ () => props.suspended,
947
+ () => props.retainRawWhileCovered,
948
+ () => props.ignoreRawCoverage,
949
+ () => props.ignoreSamePlaneRawCoverage,
950
+ () => props.cacheKey,
951
+ () => props.placementKey
952
+ ], () => {
953
+ scheduleRender();
954
+ }, { immediate: true });
955
+ watch(() => props.fallback, () => {
956
+ const current = graphic.value;
957
+ if (current?.type === "terminal") {
958
+ if (current.fallbackFromProps) {
959
+ graphic.value = {
960
+ ...current,
961
+ fallback: fallbackText()
962
+ };
963
+ bump();
964
+ scheduler.invalidate({
965
+ priority: "low",
966
+ reason: "data"
967
+ });
968
+ return;
969
+ }
970
+ scheduleRender({ clearLastGraphic: false });
971
+ return;
972
+ }
973
+ scheduleRender();
974
+ });
975
+ watch(() => [graphicsOutputVersion.value, rawOutputCanRenderValue.value], () => {
976
+ if (!props.renderer || !props.content.trim()) return;
977
+ if (graphic.value?.type === "terminal") return;
978
+ if (!rawOutputCanRenderValue.value || shouldDeferRender()) return;
979
+ scheduleRender({ clearLastGraphic: false });
980
+ });
981
+ watch(() => [
982
+ props.x,
983
+ props.y,
984
+ props.w,
985
+ props.h,
986
+ props.scrollVersion
987
+ ], () => {
988
+ if (graphic.value?.type === "terminal") {
989
+ scheduler.invalidate({
990
+ priority: "low",
991
+ reason: "data"
992
+ });
993
+ return;
994
+ }
995
+ if (props.kind !== "image" || status.value !== "loading" || !props.renderer) return;
996
+ scheduleRender({ clearLastGraphic: false });
997
+ }, { flush: "sync" });
998
+ onBeforeUnmount(() => {
999
+ alive = false;
1000
+ renderVersion++;
1001
+ unsubscribeTerminalResize();
1002
+ unsubscribeGraphicsOutput();
1003
+ abortCurrentRender("unmount");
1004
+ scheduler.cancelFrameTask?.(frameTaskId);
1005
+ queueClearLastGraphic();
1006
+ });
1007
+ function resolveDisplayLines(rawPlaceholderAllowed) {
1008
+ if (showingInitialLoadingText.value) return splitTextOutput(props.loadingText);
1009
+ const current = graphic.value;
1010
+ if (!current) return splitTextOutput(fallbackText());
1011
+ if (current.type === "terminal" && rawPlaceholderAllowed) {
1012
+ const clearSequence = resolveClearSequence(current);
1013
+ const drawKey = terminalDrawKey(current, absRect.value, clearSequence, resolveResizeSequence(current, absRect.value, fullRect.value));
1014
+ if (rawDrawRejectedKey.value !== drawKey) return markRaw([""]);
1015
+ }
1016
+ const text = current.type === "terminal" ? current.fallback : current.text;
1017
+ const lines = splitTextOutput(text);
1018
+ return text.trim().length > 0 && !hasVisibleOutput(lines) ? splitTextOutput(fallbackText()) : lines;
1019
+ }
1020
+ const displayLines = computed(() => {
1021
+ return resolveDisplayLines(rawCanQueue.value);
1022
+ });
1023
+ const currentStyle = computed(() => {
1024
+ if (error.value) return props.errorStyle ?? props.style ?? defaultStyle.value;
1025
+ if (showingInitialLoadingText.value) return props.loadingStyle ?? props.style ?? defaultStyle.value;
1026
+ return props.style ?? defaultStyle.value;
1027
+ });
1028
+ const renderNode = useRenderNode(() => ({
1029
+ zIndex: props.zIndex,
1030
+ rect: visible.value ? renderRect.value : {
1031
+ x: 0,
1032
+ y: 0,
1033
+ w: 0,
1034
+ h: 0
1035
+ },
1036
+ deps: [
1037
+ visible.value,
1038
+ renderRect.value,
1039
+ fullRect.value,
1040
+ displayLines.value,
1041
+ currentStyle.value,
1042
+ props.clear,
1043
+ status.value,
1044
+ error.value,
1045
+ documentVersion.value,
1046
+ rawOutputCanRenderValue.value,
1047
+ rawCanRender.value,
1048
+ rawCanQueue.value,
1049
+ rawClearPendingRepaint.value,
1050
+ rawDrawRejectedKey.value,
1051
+ rawSuppressedByScroll.value,
1052
+ props.placementMoveWithoutClear,
1053
+ props.retainRawWhileCovered,
1054
+ isParentScrolling.value,
1055
+ graphicsActivityVersion.value,
1056
+ graphicsOutputVersion.value
1057
+ ],
1058
+ paint: (dirtyRows) => {
1059
+ withTextWidthProvider(widthProvider, () => {
1060
+ if (!visible.value) {
1061
+ queueClearLastGraphic();
1062
+ return;
1063
+ }
1064
+ const r = absRect.value;
1065
+ const full = fullRect.value;
1066
+ if (r.w <= 0 || r.h <= 0) {
1067
+ queueClearLastGraphic();
1068
+ return;
1069
+ }
1070
+ const style = currentStyle.value;
1071
+ const dx = Math.max(0, Math.floor(r.x - full.x));
1072
+ const fullY = Math.floor(full.y);
1073
+ const current = graphic.value;
1074
+ const output = graphicsOutput();
1075
+ const retainedActiveRawGraphic = hasRetainedActiveRawGraphic();
1076
+ const rawRectForPaint = rawUncoveredRenderRect(r);
1077
+ const rawCoverageClipped = rawRectForPaint != null && props.ignoreRawCoverage && !sameRect(rawRectForPaint, r);
1078
+ const rawCoveredForPaint = rawRectForPaint == null && rawCoveredByHigherRenderNode(r);
1079
+ const rawCanQueueForPaint = current?.type === "terminal" && rawCanQueue.value && rawRectForPaint != null;
1080
+ let preserveActiveRawGraphic = false;
1081
+ let forceActiveRawRedraw = false;
1082
+ let allowTextOverlay = false;
1083
+ if (rawCanQueueForPaint && output) {
1084
+ const previous = lastDrawnGraphic.value;
1085
+ const previousStillActive = previous ? typeof output.isActive === "function" ? output.isActive(previous.id) : true : false;
1086
+ if (previousStillActive && previous) {
1087
+ const clearSequence = resolveClearSequence(current);
1088
+ const resizeSequence = resolveResizeSequence(current, rawRectForPaint, full);
1089
+ preserveActiveRawGraphic = rawClearPendingRepaint.value == null && previous.drawKey === terminalDrawKey(current, rawRectForPaint, clearSequence, resizeSequence);
1090
+ allowTextOverlay = retainedRawCoveredByHigherRenderNode(r);
1091
+ forceActiveRawRedraw = preserveActiveRawGraphic && (previous.activityVersion !== graphicsActivityVersion.value || previous.allowTextOverlay !== allowTextOverlay);
1092
+ }
1093
+ }
1094
+ const preserveActiveRawGraphicForPaint = preserveActiveRawGraphic;
1095
+ let out = rawCanQueueForPaint ? displayLines.value : resolveDisplayLines(false);
1096
+ const clearingRawGraphic = rawClearPendingRepaint.value != null || lastDrawnGraphic.value != null && !preserveActiveRawGraphicForPaint;
1097
+ const clearOwnedRegion = preserveActiveRawGraphicForPaint || retainedActiveRawGraphic ? false : props.clear || clearingRawGraphic || Boolean(rawCanQueueForPaint);
1098
+ const blank = clearOwnedRegion ? spaces(r.w) : "";
1099
+ const paintRow = (y) => {
1100
+ if (y < r.y || y >= r.y + r.h) return;
1101
+ const rowIndex = y - fullY;
1102
+ if (rowIndex < 0 || rowIndex >= out.length) {
1103
+ if (clearOwnedRegion) terminal.write(blank, {
1104
+ x: r.x,
1105
+ y,
1106
+ style
1107
+ });
1108
+ return;
1109
+ }
1110
+ const src = out[rowIndex] ?? "";
1111
+ const clipped = dx > 0 ? sliceByCellsRange(src, dx, dx + r.w) : sliceByCells(src, r.w);
1112
+ const value = clearOwnedRegion ? padEndByCells(clipped, r.w) : clipped;
1113
+ if (value || clearOwnedRegion) terminal.write(value, {
1114
+ x: r.x,
1115
+ y,
1116
+ style
1117
+ });
1118
+ };
1119
+ const paintRows = () => {
1120
+ if (dirtyRows?.length) for (const y of dirtyRows) paintRow(y);
1121
+ else for (let y = r.y; y < r.y + r.h; y++) paintRow(y);
1122
+ };
1123
+ paintRows();
1124
+ if (current?.type === "terminal" && output?.capabilities.supported && output.capabilities.preferredProtocol === current.protocol && rawCanQueueForPaint) {
1125
+ const drawKey = terminalDrawKey(current, rawRectForPaint, resolveClearSequence(current), resolveResizeSequence(current, rawRectForPaint, full));
1126
+ const queued = queueDrawGraphic(output, current, rawRectForPaint, full, {
1127
+ force: forceActiveRawRedraw,
1128
+ deferFlush: preserveActiveRawGraphicForPaint,
1129
+ placementMoveWithoutClear: props.placementMoveWithoutClear || rawCoverageClipped,
1130
+ allowTextOverlay
1131
+ });
1132
+ if (queued) trace("raw-draw", {
1133
+ sequenceChars: current.sequence.length,
1134
+ sequenceBytes: current.sequenceBytes,
1135
+ x: rawRectForPaint.x,
1136
+ y: rawRectForPaint.y,
1137
+ w: rawRectForPaint.w,
1138
+ h: rawRectForPaint.h
1139
+ });
1140
+ else if (rawDrawRejectedKey.value === drawKey) {
1141
+ out = resolveDisplayLines(false);
1142
+ paintRows();
1143
+ }
1144
+ } else {
1145
+ if (current?.type === "terminal" && rawSuppressedByScroll.value) traceRawSkipScrollOnce(isParentScrolling.value ? "scrolling" : "suspended");
1146
+ queueClearLastGraphic({ markPendingRepaint: false });
1147
+ if (!shouldDeferRender() && shouldRetryTemporaryRawFallback(rawCoveredForPaint)) scheduleRender({ clearLastGraphic: false });
1148
+ }
1149
+ if (clearingRawGraphic) rawClearPendingRepaint.value = null;
1150
+ });
1151
+ }
1152
+ }));
1153
+ watch(renderNode.id, (id) => {
1154
+ renderNodeId.value = id;
1155
+ }, { immediate: true });
1156
+ watch([
1157
+ visible,
1158
+ rawOutputCanRenderValue,
1159
+ rawCanRender,
1160
+ rawCanQueue,
1161
+ rawSuppressedByScroll,
1162
+ isParentScrolling,
1163
+ graphicsActivityVersion,
1164
+ graphicsOutputVersion,
1165
+ () => renderRect.value.x,
1166
+ () => renderRect.value.y,
1167
+ () => renderRect.value.w,
1168
+ () => renderRect.value.h,
1169
+ () => fullRect.value.x,
1170
+ () => fullRect.value.y,
1171
+ () => fullRect.value.w,
1172
+ () => fullRect.value.h
1173
+ ], () => {
1174
+ if (!alive) return;
1175
+ const deferred = renderDeferReason();
1176
+ if (deferred) {
1177
+ abortCurrentRender(deferred);
1178
+ if (status.value === "loading" || !graphic.value || lastRenderedContent !== props.content) setDeferredFallback(props.content);
1179
+ traceDeferOnce(deferred);
1180
+ }
1181
+ if (!visible.value || !rawCanQueue.value) queueClearLastGraphic();
1182
+ const shouldRetryTemporaryFallback = shouldRetryTemporaryRawFallback();
1183
+ const shouldRerenderForOutputChange = shouldRerenderForGraphicsOutputChange();
1184
+ if (!shouldDeferRender() && (!graphic.value || status.value === "idle" || shouldRetryTemporaryFallback || shouldRerenderForOutputChange)) {
1185
+ scheduleRender();
1186
+ return;
1187
+ }
1188
+ scheduler.invalidate({
1189
+ priority: "low",
1190
+ reason: "data"
1191
+ });
1192
+ }, { flush: "post" });
1193
+ return () => h("span", rootProps);
1194
+ }
1195
+ });
1196
+
1197
+ //#endregion
1198
+ export { TAgentTerminalGraphic };