@simon_he/vue-tui 1.1.6 → 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 (39) 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 +4926 -4364
  7. package/dist/agent.js +11 -9
  8. package/dist/{block-source-DByORvKG.js → block-source-BhvdZomx.js} +3 -3
  9. package/dist/cli.cjs +8 -8
  10. package/dist/cli.js +15 -5
  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 +1 -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 +4907 -4362
  23. package/dist/markdown.js +4 -4
  24. package/dist/{mermaid-CWy4wtCL.js → mermaid-D0ov4_A1.js} +3 -3
  25. package/dist/mermaid.cjs +1 -1
  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-D6KErRBY.js → terminal-graphics-DpSL29OQ.js} +1 -1
  30. package/dist/{tlog-theme-DIrlCw6m.js → tlog-theme-BnILsD3n.js} +10 -1203
  31. package/dist/vue/browser/types.d.ts +52 -0
  32. package/dist/vue/components/TBrowser.d.ts +231 -0
  33. package/dist/vue.cjs +25 -8
  34. package/dist/vue.js +8 -7
  35. package/package.json +16 -2
  36. /package/dist/{TMermaidText-wLnMMvVS.js → TMermaidText-C1akgJPU.js} +0 -0
  37. /package/dist/{math-image-BZhmfUeu.js → math-image-CcUpBnW0.js} +0 -0
  38. /package/dist/{path-mnSgEpCm.js → path-BI9W15Zt.js} +0 -0
  39. /package/dist/{wheel-scroll-DASkEZr-.js → wheel-scroll-CQ22Hcyj.js} +0 -0
@@ -1,955 +1,17 @@
1
1
  import "./create-terminal-Db_-UGVQ.js";
2
2
  import { sanitizeTerminalHref } from "./hyperlink-clbb_ha_.js";
3
- import { EventZIndexContextKey, TerminalGraphicsActivityKey, forEachTextCellSegment, intersectRect, sanitizeInlineText, sliceByCells, spaces, textCellWidth$1 as textCellWidth, translateRect, useLayout, useRenderNode, useTerminal, useTerminalNode, useVisibility } from "./rect-JzWMJxxc.js";
4
- import { TText, TView, createFrameMailbox, mergeStyle } from "./linkify-CL9wwnZN.js";
3
+ import { EventZIndexContextKey, forEachTextCellSegment, intersectRect, sanitizeInlineText, sliceByCells, spaces, textCellWidth$1 as textCellWidth, translateRect, useLayout, useRenderNode, useTerminal, useTerminalNode, useVisibility } from "./rect-JzWMJxxc.js";
4
+ import { mergeStyle } from "./linkify-CklfA1vp.js";
5
5
  import "./frame-perf-CHpWhbC4.js";
6
6
  import "./terminal-selection-4W1SJj4c.js";
7
- import "./wheel-scroll-DASkEZr-.js";
8
- import { createTerminalGraphicPngSequence, getTerminalGraphicsOutput, getTerminalGraphicsOutputVersion, subscribeTerminalGraphicsOutput } from "./terminal-graphics-D6KErRBY.js";
9
- import { TAgentTerminalGraphic, TLogLinksPanel, TLogMinimap, TLogScrollbar, TLogSearchBar, TLogSearchPager, TLogSearchResults, TLogView, TLogVirtualLinksPanel, TLogVirtualSearchResults, TTranscriptView, TVirtualList, createAppendOnlyLogStore, createTLogDensityBucketsFromMarkers, createTLogLevelPlugin, createTLogLineMatcherPlugin, createTLogLinkActionPlugin, createTLogOsc8LinkPlugin, createTLogUrlPlugin, detectTLogUrls, dispatchTLogPluginLinkAction, getTLogPluginMetadata, handleTLogKeymapEvent, matchesTLogKeyBinding, parseTLogAnnotatedText, resolveTLogLinksPanelTheme, resolveTLogMinimapTheme, resolveTLogScrollbarTheme, resolveTLogSearchBarTheme, resolveTLogSearchPagerTheme, resolveTLogSearchResultsTheme, resolveTLogViewTheme, stripTLogAnsiText, tlogDarkPreset, tlogDarkTheme, tlogDefaultKeymap, tlogDefaultPreset, tlogDefaultTheme, tlogHighContrastKeymap, tlogHighContrastPreset, tlogHighContrastTheme, toTLogExternalLinkFromVisibleLink, useTLogLinkController, useTLogRetainedIndex, useTLogSearchController, useTLogSearchResultsPage, useTLogVirtualSearchResults } from "./tlog-theme-DIrlCw6m.js";
10
- import { computed, defineComponent, getCurrentInstance, h, inject, markRaw, onBeforeUnmount, onUnmounted, ref, shallowRef, watch } from "vue";
7
+ import { TView } from "./frame-mailbox-DaTrfyaF.js";
8
+ import "./wheel-scroll-CQ22Hcyj.js";
9
+ import "./terminal-graphics-DpSL29OQ.js";
10
+ import { TLogLinksPanel, TLogMinimap, TLogScrollbar, TLogSearchBar, TLogSearchPager, TLogSearchResults, TLogView, TLogVirtualLinksPanel, TLogVirtualSearchResults, TTranscriptView, TVirtualList, createAppendOnlyLogStore, createTLogDensityBucketsFromMarkers, createTLogLevelPlugin, createTLogLineMatcherPlugin, createTLogLinkActionPlugin, createTLogOsc8LinkPlugin, createTLogUrlPlugin, detectTLogUrls, dispatchTLogPluginLinkAction, getTLogPluginMetadata, handleTLogKeymapEvent, matchesTLogKeyBinding, parseTLogAnnotatedText, resolveTLogLinksPanelTheme, resolveTLogMinimapTheme, resolveTLogScrollbarTheme, resolveTLogSearchBarTheme, resolveTLogSearchPagerTheme, resolveTLogSearchResultsTheme, resolveTLogViewTheme, stripTLogAnsiText, tlogDarkPreset, tlogDarkTheme, tlogDefaultKeymap, tlogDefaultPreset, tlogDefaultTheme, tlogHighContrastKeymap, tlogHighContrastPreset, tlogHighContrastTheme, toTLogExternalLinkFromVisibleLink, useTLogLinkController, useTLogRetainedIndex, useTLogSearchController, useTLogSearchResultsPage, useTLogVirtualSearchResults } from "./tlog-theme-BnILsD3n.js";
11
+ import "./TAgentTerminalGraphic-B8-YZfuP.js";
12
+ import { TVideo } from "./TVideo-D9AOiyq2.js";
13
+ import { computed, defineComponent, h, inject, onBeforeUnmount, onUnmounted, ref, watch } from "vue";
11
14
 
12
- //#region src/vue/components/TVideo.ts
13
- const DEFAULT_MAX_FPS$1 = 12;
14
- const DEFAULT_MAX_PIXEL_WIDTH = 640;
15
- const DEFAULT_MAX_PIXEL_HEIGHT = 360;
16
- const MAX_PIXEL_DIMENSION = 4096;
17
- const MAX_FRAME_BYTES = 8 * 1024 * 1024;
18
- const MAX_GRAY8_FPS = 10;
19
- const MAX_GRAY8_WIDTH = 512;
20
- const MAX_GRAY8_HEIGHT = 256;
21
- const ASCII_RAMP = " .:-=+*#%@";
22
- const CONTROL_REFRESH_MS = 250;
23
- const PLAYBACK_RATES = [
24
- 1,
25
- 2,
26
- 3
27
- ];
28
- function positiveInt(value, fallback, max) {
29
- const parsed = Math.floor(Number(value));
30
- if (!Number.isFinite(parsed) || parsed <= 0) return Math.min(max, fallback);
31
- return Math.min(max, parsed);
32
- }
33
- function positiveNumber(value, fallback, max) {
34
- const parsed = Number(value);
35
- if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
36
- return Math.min(max, parsed);
37
- }
38
- function playbackRate(value) {
39
- return value === 2 || value === 3 ? value : 1;
40
- }
41
- function optionalDuration(value) {
42
- const parsed = Number(value);
43
- return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
44
- }
45
- function formatPlaybackTime(valueMs, hourDigits = 0) {
46
- if (valueMs == null) return "--:--";
47
- const seconds = Math.max(0, Math.floor(valueMs / 1e3));
48
- const hours = Math.floor(seconds / 3600);
49
- const minutes = Math.floor(seconds % 3600 / 60);
50
- const remainder = seconds % 60;
51
- if (hours > 0 || hourDigits > 0) return `${String(hours).padStart(Math.max(1, hourDigits), "0")}:${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
52
- return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
53
- }
54
- function readUint32(bytes, offset) {
55
- return bytes[offset] * 16777216 + (bytes[offset + 1] << 16) + (bytes[offset + 2] << 8) + bytes[offset + 3] >>> 0;
56
- }
57
- function normalizeFrame(frame) {
58
- if (frame.format === "gray8") {
59
- const pixelWidth$1 = Math.floor(Number(frame.pixelWidth));
60
- const pixelHeight$1 = Math.floor(Number(frame.pixelHeight));
61
- const pixels = frame.pixels;
62
- if (!Number.isFinite(pixelWidth$1) || !Number.isFinite(pixelHeight$1) || pixelWidth$1 <= 0 || pixelHeight$1 <= 0 || pixelWidth$1 > MAX_GRAY8_WIDTH || pixelHeight$1 > MAX_GRAY8_HEIGHT || !(pixels instanceof Uint8Array) || pixels.length !== pixelWidth$1 * pixelHeight$1 || pixels.length > MAX_FRAME_BYTES) throw new Error("TVideo gray8 frame must match its bounded pixel dimensions");
63
- return {
64
- format: "gray8",
65
- pixels,
66
- timestampMs: Math.max(0, Number(frame.timestampMs) || 0),
67
- pixelWidth: pixelWidth$1,
68
- pixelHeight: pixelHeight$1,
69
- fingerprint: frame.fingerprint,
70
- durationMs: optionalDuration(frame.durationMs)
71
- };
72
- }
73
- const png = frame.png;
74
- if (!(png instanceof Uint8Array) || png.length < 24 || png.length > MAX_FRAME_BYTES) throw new Error("TVideo frame must contain a bounded PNG Uint8Array");
75
- if (png[0] !== 137 || png[1] !== 80 || png[2] !== 78 || png[3] !== 71 || png[4] !== 13 || png[5] !== 10 || png[6] !== 26 || png[7] !== 10) throw new Error("TVideo frame source emitted invalid PNG data");
76
- const pixelWidth = readUint32(png, 16);
77
- const pixelHeight = readUint32(png, 20);
78
- if (pixelWidth <= 0 || pixelHeight <= 0 || pixelWidth > MAX_PIXEL_DIMENSION || pixelHeight > MAX_PIXEL_DIMENSION) throw new Error(`TVideo frame has an unsupported size: ${pixelWidth}x${pixelHeight}`);
79
- return {
80
- format: "png",
81
- png,
82
- timestampMs: Math.max(0, Number(frame.timestampMs) || 0),
83
- pixelWidth,
84
- pixelHeight,
85
- fingerprint: frame.fingerprint,
86
- durationMs: optionalDuration(frame.durationMs)
87
- };
88
- }
89
- function frameBytes(frame) {
90
- return frame.format === "gray8" ? frame.pixels : frame.png;
91
- }
92
- function gray8ToAscii(frame, cellWidth) {
93
- const lines = [];
94
- const width = Math.max(1, Math.floor(cellWidth));
95
- for (let y = 0; y < frame.pixelHeight; y++) {
96
- let line = "";
97
- const rowStart = y * frame.pixelWidth;
98
- for (let x = 0; x < frame.pixelWidth; x++) {
99
- const value = frame.pixels[rowStart + x];
100
- const glyph = ASCII_RAMP[Math.min(ASCII_RAMP.length - 1, value * ASCII_RAMP.length >> 8)];
101
- line += `${glyph}${glyph}`;
102
- }
103
- lines.push(line.slice(0, width));
104
- }
105
- return lines.join("\n");
106
- }
107
- function sameBytes(left, right) {
108
- if (left.length !== right.length) return false;
109
- for (let index = 0; index < left.length; index++) if (left[index] !== right[index]) return false;
110
- return true;
111
- }
112
- function bytesToBase64(bytes) {
113
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
114
- const chunks = [];
115
- let chunk = "";
116
- for (let index = 0; index < bytes.length; index += 3) {
117
- const a = bytes[index];
118
- const hasB = index + 1 < bytes.length;
119
- const hasC = index + 2 < bytes.length;
120
- const b = hasB ? bytes[index + 1] : 0;
121
- const c = hasC ? bytes[index + 2] : 0;
122
- chunk += alphabet[a >> 2] + alphabet[(a & 3) << 4 | b >> 4] + (hasB ? alphabet[(b & 15) << 2 | c >> 6] : "=") + (hasC ? alphabet[c & 63] : "=");
123
- if (chunk.length >= 16384) {
124
- chunks.push(chunk);
125
- chunk = "";
126
- }
127
- }
128
- if (chunk) chunks.push(chunk);
129
- return chunks.join("");
130
- }
131
- function createFrameRenderer(frame, cellWidth) {
132
- if (frame.format === "gray8") {
133
- const text = gray8ToAscii(frame, cellWidth);
134
- return () => ({
135
- type: "text",
136
- text
137
- });
138
- }
139
- let base64;
140
- return (_content, context) => {
141
- if (!context.visible || !context.rawVisible) return null;
142
- base64 ?? (base64 = bytesToBase64(frame.png));
143
- const protocol = context.protocol;
144
- if (protocol !== "kitty" && protocol !== "iterm2") return null;
145
- return createTerminalGraphicPngSequence({
146
- protocol,
147
- base64,
148
- imageId: context.imageId,
149
- placementId: context.placementId,
150
- cols: context.width,
151
- rows: context.height,
152
- sourceWidth: frame.pixelWidth,
153
- sourceHeight: frame.pixelHeight,
154
- placementColumns: Math.max(1, Math.floor(context.viewport.rect.w)),
155
- placementRows: Math.max(1, Math.floor(context.viewport.rect.h)),
156
- rect: context.viewport.rect,
157
- fullRect: context.viewport.fullRect,
158
- freeImageData: true
159
- });
160
- };
161
- }
162
- function errorMessage(error) {
163
- return error instanceof Error ? error.message : String(error);
164
- }
165
- const tVideoProps = {
166
- x: {
167
- type: Number,
168
- required: true
169
- },
170
- y: {
171
- type: Number,
172
- required: true
173
- },
174
- w: {
175
- type: Number,
176
- required: true
177
- },
178
- h: {
179
- type: Number,
180
- required: true
181
- },
182
- zIndex: {
183
- type: Number,
184
- default: 0
185
- },
186
- src: {
187
- type: String,
188
- required: true
189
- },
190
- frameSource: {
191
- type: Function,
192
- required: true
193
- },
194
- paused: {
195
- type: Boolean,
196
- default: void 0
197
- },
198
- playbackRate: {
199
- type: Number,
200
- default: void 0
201
- },
202
- controls: {
203
- type: Boolean,
204
- default: false
205
- },
206
- controlsLayout: {
207
- type: String,
208
- default: "compact"
209
- },
210
- durationMs: {
211
- type: Number,
212
- default: void 0
213
- },
214
- loop: {
215
- type: Boolean,
216
- default: false
217
- },
218
- maxFps: {
219
- type: Number,
220
- default: DEFAULT_MAX_FPS$1
221
- },
222
- pixelWidth: {
223
- type: Number,
224
- default: void 0
225
- },
226
- pixelHeight: {
227
- type: Number,
228
- default: void 0
229
- },
230
- fallback: {
231
- type: String,
232
- default: "[video]"
233
- },
234
- style: {
235
- type: Object,
236
- default: void 0
237
- },
238
- clear: {
239
- type: Boolean,
240
- default: true
241
- }
242
- };
243
- const TVideo = defineComponent({
244
- name: "TVideo",
245
- props: tVideoProps,
246
- emits: {
247
- frame: (_event) => true,
248
- ended: () => true,
249
- error: (_error) => true,
250
- seek: (_event) => true,
251
- "update:paused": (_paused) => true,
252
- "update:playbackRate": (_rate) => true
253
- },
254
- setup(props, { emit }) {
255
- const instance = getCurrentInstance();
256
- const { terminal, scheduler } = useTerminal();
257
- const layout = useLayout();
258
- const { visible, rootProps } = useVisibility({ provide: true });
259
- const graphicsActivity = inject(TerminalGraphicsActivityKey, null);
260
- const frameRenderer = shallowRef();
261
- const playbackError = shallowRef("");
262
- const internalPaused = shallowRef(props.paused ?? false);
263
- const internalPlaybackRate = shallowRef(playbackRate(props.playbackRate));
264
- const discoveredDurationMs = shallowRef();
265
- const displayedTimestampMs = shallowRef(0);
266
- const seekPreviewMs = shallowRef();
267
- const seeking = shallowRef(false);
268
- const terminalSizeVersion = shallowRef(0);
269
- const graphicsOutputVersion = shallowRef(getTerminalGraphicsOutputVersion(terminal));
270
- const placementKey = `TVideo:${instance?.uid ?? "unknown"}`;
271
- const mailboxId = `${placementKey}:frame`;
272
- let alive = true;
273
- let generation = 0;
274
- let activeAbort = null;
275
- let lastSourceBytes = null;
276
- let lastQueuedBytes = null;
277
- let lastQueuedFormat = null;
278
- let lastQueuedFingerprint;
279
- let lastTimestampMs = 0;
280
- let droppedFrames = 0;
281
- let pendingEndedGeneration = null;
282
- let suppressNextVideoClick = false;
283
- let controlPointerCapture = null;
284
- const unsubscribeTerminalResize = terminal.on("resize", () => {
285
- terminalSizeVersion.value++;
286
- });
287
- const unsubscribeGraphicsOutput = subscribeTerminalGraphicsOutput(terminal, () => {
288
- graphicsOutputVersion.value = getTerminalGraphicsOutputVersion(terminal);
289
- });
290
- const showControls = computed(() => props.controls && Math.floor(props.w) >= 14 && Math.floor(props.h) >= 2);
291
- const resolvedControlsLayout = computed(() => props.controlsLayout === "cinema" && Math.floor(props.h) >= 3 ? "cinema" : "compact");
292
- const controlRows = computed(() => showControls.value ? resolvedControlsLayout.value === "cinema" ? 2 : 1 : 0);
293
- const videoHeight = computed(() => Math.max(1, Math.floor(props.h) - controlRows.value));
294
- const resolvedMaxFps = computed(() => positiveNumber(props.maxFps, DEFAULT_MAX_FPS$1, 60));
295
- const resolvedPixelSize = computed(() => {
296
- const desiredWidth = Math.max(2, Math.floor(props.w) * 8);
297
- const desiredHeight = Math.max(2, videoHeight.value * 16);
298
- if (props.pixelWidth == null && props.pixelHeight == null) {
299
- const scale = Math.min(1, DEFAULT_MAX_PIXEL_WIDTH / desiredWidth, DEFAULT_MAX_PIXEL_HEIGHT / desiredHeight);
300
- return {
301
- width: Math.max(2, Math.floor(desiredWidth * scale)),
302
- height: Math.max(2, Math.floor(desiredHeight * scale))
303
- };
304
- }
305
- if (props.pixelWidth != null && props.pixelHeight == null) {
306
- const width = positiveInt(props.pixelWidth, desiredWidth, MAX_PIXEL_DIMENSION);
307
- const inferredHeight = width * desiredHeight / desiredWidth;
308
- const scale = Math.min(1, MAX_PIXEL_DIMENSION / inferredHeight);
309
- return {
310
- width: Math.max(2, Math.floor(width * scale)),
311
- height: Math.max(2, Math.floor(inferredHeight * scale))
312
- };
313
- }
314
- if (props.pixelWidth == null && props.pixelHeight != null) {
315
- const height = positiveInt(props.pixelHeight, desiredHeight, MAX_PIXEL_DIMENSION);
316
- const inferredWidth = height * desiredWidth / desiredHeight;
317
- const scale = Math.min(1, MAX_PIXEL_DIMENSION / inferredWidth);
318
- return {
319
- width: Math.max(2, Math.floor(inferredWidth * scale)),
320
- height: Math.max(2, Math.floor(height * scale))
321
- };
322
- }
323
- return {
324
- width: positiveInt(props.pixelWidth, desiredWidth, MAX_PIXEL_DIMENSION),
325
- height: positiveInt(props.pixelHeight, desiredHeight, MAX_PIXEL_DIMENSION)
326
- };
327
- });
328
- const resolvedPixelWidth = computed(() => resolvedPixelSize.value.width);
329
- const resolvedPixelHeight = computed(() => resolvedPixelSize.value.height);
330
- const paintable = computed(() => {
331
- terminalSizeVersion.value;
332
- if (!visible.value) return false;
333
- const size = terminal.size();
334
- const terminalRect = {
335
- x: 0,
336
- y: 0,
337
- w: Math.max(0, Math.floor(size.cols)),
338
- h: Math.max(0, Math.floor(size.rows))
339
- };
340
- const clip = layout.clipRect ? intersectRect(layout.clipRect, terminalRect) : terminalRect;
341
- if (!clip) return false;
342
- const rect = translateRect({
343
- x: props.x,
344
- y: props.y,
345
- w: props.w,
346
- h: videoHeight.value
347
- }, layout.originX, layout.originY);
348
- const visibleRect = intersectRect(rect, clip);
349
- return Boolean(visibleRect && visibleRect.w > 0 && visibleRect.h > 0);
350
- });
351
- const graphicsProtocol = computed(() => {
352
- graphicsOutputVersion.value;
353
- return getTerminalGraphicsOutput(terminal)?.capabilities.preferredProtocol ?? null;
354
- });
355
- const preferredFormat = computed(() => graphicsProtocol.value === "kitty" || graphicsProtocol.value === "iterm2" ? "png" : "gray8");
356
- const resolvedDecodeFps = computed(() => preferredFormat.value === "gray8" ? Math.min(MAX_GRAY8_FPS, resolvedMaxFps.value) : resolvedMaxFps.value);
357
- const resolvedDecodeWidth = computed(() => preferredFormat.value === "gray8" ? positiveInt(Math.ceil(props.w / 2), 1, MAX_GRAY8_WIDTH) : resolvedPixelWidth.value);
358
- const resolvedDecodeHeight = computed(() => preferredFormat.value === "gray8" ? positiveInt(videoHeight.value, 1, MAX_GRAY8_HEIGHT) : resolvedPixelHeight.value);
359
- const resolvedDurationMs = computed(() => optionalDuration(props.durationMs) ?? discoveredDurationMs.value);
360
- const effectivePaused = computed(() => props.paused ?? internalPaused.value);
361
- const effectivePlaybackRate = computed(() => props.playbackRate == null ? internalPlaybackRate.value : playbackRate(props.playbackRate));
362
- const controlTimestampMs = computed(() => seekPreviewMs.value ?? displayedTimestampMs.value);
363
- const timeHourDigits = computed(() => {
364
- const duration = resolvedDurationMs.value;
365
- if (!duration || duration < 36e5) return 0;
366
- return String(Math.floor(duration / 36e5)).length;
367
- });
368
- const currentTimeText = computed(() => formatPlaybackTime(controlTimestampMs.value, timeHourDigits.value));
369
- const durationTimeText = computed(() => formatPlaybackTime(resolvedDurationMs.value, timeHourDigits.value));
370
- const controlLayout = computed(() => {
371
- const width = Math.max(1, Math.floor(props.w));
372
- const progressY = videoHeight.value;
373
- const current = currentTimeText.value;
374
- const duration = durationTimeText.value;
375
- const timeWidth = Math.max(textCellWidth(current), textCellWidth(duration));
376
- const ratesWidth = 8;
377
- if (resolvedControlsLayout.value === "cinema") {
378
- const ratesX$1 = Math.max(3, width - ratesWidth);
379
- const timeText = `${current} / ${duration}`;
380
- return {
381
- width,
382
- kind: "cinema",
383
- progressX: 0,
384
- progressY,
385
- progressWidth: width,
386
- actionY: progressY + 1,
387
- ratesX: ratesX$1,
388
- showAllRates: true,
389
- showTimes: 3 + textCellWidth(timeText) < ratesX$1,
390
- current,
391
- duration,
392
- timeText,
393
- timeWidth,
394
- currentX: 3,
395
- totalX: 0
396
- };
397
- }
398
- const ratesX = width - ratesWidth;
399
- const progressX = timeWidth + 4;
400
- const totalX = ratesX - timeWidth - 1;
401
- const progressWidth = totalX - progressX - 1;
402
- if (progressWidth >= 4) return {
403
- width,
404
- kind: "compact",
405
- progressX,
406
- progressY,
407
- progressWidth,
408
- actionY: progressY,
409
- ratesX,
410
- showAllRates: true,
411
- showTimes: true,
412
- current,
413
- duration,
414
- timeText: "",
415
- timeWidth,
416
- currentX: 3,
417
- totalX
418
- };
419
- const compactRatesX = Math.max(4, width - 2);
420
- return {
421
- width,
422
- kind: "compact",
423
- progressX: 3,
424
- progressY,
425
- progressWidth: Math.max(1, compactRatesX - 4),
426
- actionY: progressY,
427
- ratesX: compactRatesX,
428
- showAllRates: false,
429
- showTimes: false,
430
- current,
431
- duration,
432
- timeText: "",
433
- timeWidth,
434
- currentX: 0,
435
- totalX: 0
436
- };
437
- });
438
- const rateStyles = computed(() => PLAYBACK_RATES.map((rate) => rate === effectivePlaybackRate.value ? {
439
- ...props.style,
440
- inverse: true
441
- } : props.style));
442
- const remainingProgressStyle = computed(() => ({
443
- ...props.style,
444
- dim: true
445
- }));
446
- const progressThumbStyle = computed(() => ({
447
- ...props.style,
448
- inverse: true
449
- }));
450
- const progressSegments = computed(() => {
451
- const { progressWidth } = controlLayout.value;
452
- const duration = resolvedDurationMs.value;
453
- if (!duration) return {
454
- playedWidth: 0,
455
- thumbWidth: 0,
456
- remainingWidth: progressWidth
457
- };
458
- const ratio = Math.max(0, Math.min(1, controlTimestampMs.value / duration));
459
- const marker = Math.round(ratio * Math.max(0, progressWidth - 1));
460
- return {
461
- playedWidth: marker,
462
- thumbWidth: 1,
463
- remainingWidth: progressWidth - marker - 1
464
- };
465
- });
466
- const controlFill = computed(() => " ".repeat(controlLayout.value.width));
467
- const progressGlyphs = computed(() => ({
468
- played: "━".repeat(progressSegments.value.playedWidth),
469
- remaining: "─".repeat(progressSegments.value.remainingWidth)
470
- }));
471
- const playbackEnabled = computed(() => alive && !effectivePaused.value && !graphicsActivity?.scrolling.value && props.src.trim().length > 0 && paintable.value);
472
- const shouldPlay = computed(() => playbackEnabled.value && !seeking.value);
473
- const visibleFallback = computed(() => playbackError.value ? `${props.fallback}: ${playbackError.value}` : props.fallback);
474
- function timelineTimestamp(timestampMs) {
475
- const duration = resolvedDurationMs.value;
476
- if (!duration) return Math.max(0, timestampMs);
477
- if (props.loop) return Math.max(0, timestampMs) % duration;
478
- return Math.max(0, Math.min(duration, timestampMs));
479
- }
480
- function seekTimestamp(timestampMs) {
481
- const duration = resolvedDurationMs.value;
482
- if (!duration) return Math.max(0, timestampMs);
483
- const end = props.loop ? Math.max(0, duration - 1) : duration;
484
- return Math.max(0, Math.min(end, timestampMs));
485
- }
486
- function updateTimestamp(timestampMs, force = false) {
487
- const next = timelineTimestamp(timestampMs);
488
- lastTimestampMs = next;
489
- if (!showControls.value) return;
490
- const threshold = CONTROL_REFRESH_MS * effectivePlaybackRate.value;
491
- if (force || next < displayedTimestampMs.value || Math.abs(next - displayedTimestampMs.value) >= threshold) displayedTimestampMs.value = next;
492
- }
493
- function commitFrame(frame, dropped) {
494
- if (!alive) return;
495
- droppedFrames += dropped;
496
- frameRenderer.value = markRaw(createFrameRenderer(frame, props.w));
497
- updateTimestamp(frame.timestampMs);
498
- const durationMs = resolvedDurationMs.value;
499
- emit("frame", {
500
- timestampMs: frame.timestampMs,
501
- pixelWidth: frame.pixelWidth,
502
- pixelHeight: frame.pixelHeight,
503
- droppedFrames,
504
- ...durationMs ? { durationMs } : {},
505
- playbackRate: effectivePlaybackRate.value
506
- });
507
- }
508
- const mailbox = createFrameMailbox({
509
- scheduler,
510
- id: mailboxId,
511
- reason: "stream",
512
- priority: "low",
513
- apply(frame, _context, meta) {
514
- commitFrame(frame, meta.dropped);
515
- if (pendingEndedGeneration === generation) {
516
- pendingEndedGeneration = null;
517
- emit("ended");
518
- }
519
- }
520
- });
521
- function stopPlayback() {
522
- generation++;
523
- pendingEndedGeneration = null;
524
- const discardedPendingFrame = mailbox.hasPending();
525
- mailbox.cancel();
526
- if (discardedPendingFrame) {
527
- lastQueuedBytes = null;
528
- lastQueuedFormat = null;
529
- lastQueuedFingerprint = void 0;
530
- }
531
- activeAbort?.abort();
532
- activeAbort = null;
533
- }
534
- function resetQueuedFrameIdentity() {
535
- lastSourceBytes = null;
536
- lastQueuedBytes = null;
537
- lastQueuedFormat = null;
538
- lastQueuedFingerprint = void 0;
539
- }
540
- function setPaused(paused) {
541
- if (effectivePaused.value === paused) return;
542
- if (props.paused == null) internalPaused.value = paused;
543
- emit("update:paused", paused);
544
- }
545
- function setPlaybackRate(rate) {
546
- const next = playbackRate(rate);
547
- if (effectivePlaybackRate.value === next) return;
548
- if (props.playbackRate == null) internalPlaybackRate.value = next;
549
- emit("update:playbackRate", next);
550
- }
551
- function applySeek(timestampMs, restart) {
552
- const parsed = Number(timestampMs);
553
- if (!Number.isFinite(parsed)) return;
554
- stopPlayback();
555
- resetQueuedFrameIdentity();
556
- const next = seekTimestamp(parsed);
557
- updateTimestamp(next, true);
558
- seekPreviewMs.value = void 0;
559
- const durationMs = resolvedDurationMs.value;
560
- emit("seek", {
561
- timestampMs: next,
562
- ...durationMs ? { durationMs } : {}
563
- });
564
- if (restart) startPlayback(effectivePaused.value);
565
- }
566
- function controlCell(event) {
567
- return {
568
- x: Math.floor(event.cellX - layout.originX - props.x),
569
- y: Math.floor(event.cellY - layout.originY - props.y)
570
- };
571
- }
572
- function previewSeekAt(cellX) {
573
- const duration = resolvedDurationMs.value;
574
- if (!duration) return;
575
- const { progressX, progressWidth } = controlLayout.value;
576
- const offset = Math.max(0, Math.min(progressWidth - 1, cellX - progressX));
577
- seekPreviewMs.value = progressWidth <= 1 ? 0 : offset / Math.max(1, progressWidth - 1) * duration;
578
- }
579
- function captureControlPointer(event) {
580
- const native = event.nativeEvent;
581
- const pointerId = native?.pointerId;
582
- const target = native?.target;
583
- if (pointerId == null || !target?.setPointerCapture) return;
584
- target.setPointerCapture(pointerId);
585
- controlPointerCapture = {
586
- pointerId,
587
- target
588
- };
589
- }
590
- function releaseControlPointer() {
591
- if (!controlPointerCapture) return;
592
- controlPointerCapture.target.releasePointerCapture?.(controlPointerCapture.pointerId);
593
- controlPointerCapture = null;
594
- }
595
- function rateAt(cellX) {
596
- const { ratesX, showAllRates } = controlLayout.value;
597
- const offset = cellX - ratesX;
598
- if (!showAllRates) {
599
- if (offset < 0 || offset >= 2) return void 0;
600
- const index = PLAYBACK_RATES.indexOf(effectivePlaybackRate.value);
601
- return PLAYBACK_RATES[(index + 1) % PLAYBACK_RATES.length];
602
- }
603
- if (offset < 0 || offset % 3 >= 2) return void 0;
604
- return PLAYBACK_RATES[Math.floor(offset / 3)];
605
- }
606
- function onInteractivePointerDown(event) {
607
- if (event.button != null && event.button !== 0) return;
608
- const { x: cellX, y: cellY } = controlCell(event);
609
- if (cellY < videoHeight.value) {
610
- suppressNextVideoClick = false;
611
- return;
612
- }
613
- if (!showControls.value) return;
614
- const { actionY, progressY, progressX, progressWidth } = controlLayout.value;
615
- const rate = rateAt(cellX);
616
- if (cellY === actionY && cellX <= 1) {
617
- event.preventDefault();
618
- event.stopPropagation();
619
- suppressNextVideoClick = true;
620
- setPaused(!effectivePaused.value);
621
- return;
622
- }
623
- if (cellY === actionY && rate) {
624
- event.preventDefault();
625
- event.stopPropagation();
626
- suppressNextVideoClick = true;
627
- setPlaybackRate(rate);
628
- return;
629
- }
630
- if (cellY !== progressY || !resolvedDurationMs.value || cellX < progressX || cellX >= progressX + progressWidth) return;
631
- event.preventDefault();
632
- event.stopPropagation();
633
- suppressNextVideoClick = true;
634
- seeking.value = true;
635
- stopPlayback();
636
- previewSeekAt(cellX);
637
- captureControlPointer(event);
638
- }
639
- function onInteractivePointerMove(event) {
640
- if (!seeking.value) return;
641
- if (event.buttons === 0) {
642
- onInteractivePointerUp(event);
643
- return;
644
- }
645
- event.preventDefault();
646
- event.stopPropagation();
647
- previewSeekAt(controlCell(event).x);
648
- }
649
- function onInteractivePointerUp(event) {
650
- if (!seeking.value) return;
651
- event.preventDefault();
652
- event.stopPropagation();
653
- previewSeekAt(controlCell(event).x);
654
- const timestampMs = seekPreviewMs.value ?? lastTimestampMs;
655
- applySeek(timestampMs, false);
656
- seeking.value = false;
657
- releaseControlPointer();
658
- startPlayback(effectivePaused.value);
659
- }
660
- function onVideoClick(event) {
661
- if (event.button != null && event.button !== 0) return;
662
- if (suppressNextVideoClick) {
663
- suppressNextVideoClick = false;
664
- event.preventDefault();
665
- event.stopPropagation();
666
- return;
667
- }
668
- if (controlCell(event).y >= videoHeight.value) return;
669
- event.preventDefault();
670
- event.stopPropagation();
671
- setPaused(!effectivePaused.value);
672
- }
673
- function finishControlSeek() {
674
- if (!seeking.value) return;
675
- const timestampMs = seekPreviewMs.value ?? lastTimestampMs;
676
- applySeek(timestampMs, false);
677
- seeking.value = false;
678
- releaseControlPointer();
679
- startPlayback(effectivePaused.value);
680
- }
681
- function onControlKeydown(event) {
682
- if (event.key === "Enter" || event.key === " " || event.key === "Spacebar") {
683
- event.preventDefault();
684
- event.stopPropagation();
685
- setPaused(!effectivePaused.value);
686
- return;
687
- }
688
- if (event.key === "ArrowUp" || event.key === "ArrowDown") {
689
- event.preventDefault();
690
- event.stopPropagation();
691
- const index = PLAYBACK_RATES.indexOf(effectivePlaybackRate.value);
692
- const offset = event.key === "ArrowUp" ? 1 : -1;
693
- setPlaybackRate(PLAYBACK_RATES[Math.max(0, Math.min(2, index + offset))]);
694
- return;
695
- }
696
- if (!event.repeat && (event.key === "Home" || event.key === "End") && resolvedDurationMs.value) {
697
- event.preventDefault();
698
- event.stopPropagation();
699
- applySeek(event.key === "Home" ? 0 : resolvedDurationMs.value, true);
700
- return;
701
- }
702
- if (event.key === "1" || event.key === "2" || event.key === "3") {
703
- event.preventDefault();
704
- event.stopPropagation();
705
- setPlaybackRate(Number(event.key));
706
- }
707
- }
708
- function queueFrame(frame, expectedFormat) {
709
- let normalized = normalizeFrame(frame);
710
- if (normalized.format !== expectedFormat) throw new Error(`TVideo frame source did not provide requested ${expectedFormat} frames`);
711
- if (normalized.durationMs != null && normalized.durationMs !== discoveredDurationMs.value) discoveredDurationMs.value = normalized.durationMs;
712
- normalized = {
713
- ...normalized,
714
- timestampMs: timelineTimestamp(normalized.timestampMs)
715
- };
716
- const sourceBytes = frameBytes(normalized);
717
- const reusesSourceBuffer = sourceBytes === lastSourceBytes;
718
- lastSourceBytes = sourceBytes;
719
- const stableFrame = reusesSourceBuffer ? normalized.format === "gray8" ? {
720
- ...normalized,
721
- pixels: new Uint8Array(normalized.pixels)
722
- } : {
723
- ...normalized,
724
- png: new Uint8Array(normalized.png)
725
- } : normalized;
726
- const bytes = frameBytes(stableFrame);
727
- const sameFingerprint = normalized.format === lastQueuedFormat && normalized.fingerprint != null && lastQueuedFingerprint != null && normalized.fingerprint === lastQueuedFingerprint;
728
- const canCompareBytes = normalized.fingerprint == null && lastQueuedFingerprint == null && !reusesSourceBuffer;
729
- if (sameFingerprint || canCompareBytes && normalized.format === lastQueuedFormat && lastQueuedBytes && sameBytes(lastQueuedBytes, sourceBytes)) {
730
- lastQueuedBytes = bytes;
731
- lastQueuedFormat = normalized.format;
732
- lastQueuedFingerprint = normalized.fingerprint;
733
- updateTimestamp(normalized.timestampMs);
734
- if (mailbox.hasPending()) mailbox.replacePending(stableFrame);
735
- return;
736
- }
737
- lastQueuedBytes = bytes;
738
- lastQueuedFormat = normalized.format;
739
- lastQueuedFingerprint = normalized.fingerprint;
740
- if (!mailbox.queue(stableFrame)) {
741
- commitFrame(stableFrame, 0);
742
- scheduler.invalidate({
743
- priority: "low",
744
- reason: "stream"
745
- });
746
- }
747
- }
748
- function startPlayback(oneFrame = false) {
749
- stopPlayback();
750
- if (!shouldPlay.value && !(oneFrame && alive && props.src.trim().length > 0 && paintable.value && !graphicsActivity?.scrolling.value)) return;
751
- const currentGeneration = generation;
752
- const abort = new AbortController();
753
- activeAbort = abort;
754
- playbackError.value = "";
755
- const source = props.frameSource;
756
- const format = preferredFormat.value;
757
- const context = {
758
- src: props.src,
759
- signal: abort.signal,
760
- maxFps: resolvedDecodeFps.value,
761
- pixelWidth: resolvedDecodeWidth.value,
762
- pixelHeight: resolvedDecodeHeight.value,
763
- startAtMs: lastTimestampMs,
764
- preferredFormat: format,
765
- playbackRate: effectivePlaybackRate.value,
766
- loop: props.loop
767
- };
768
- (async () => {
769
- try {
770
- const frames = await source(context);
771
- for await (const frame of frames) {
772
- if (!alive || abort.signal.aborted || currentGeneration !== generation) return;
773
- queueFrame(frame, format);
774
- if (oneFrame) return;
775
- }
776
- if (!alive || abort.signal.aborted || currentGeneration !== generation) return;
777
- if (mailbox.hasPending()) pendingEndedGeneration = currentGeneration;
778
- else emit("ended");
779
- } catch (error) {
780
- if (!alive || abort.signal.aborted || currentGeneration !== generation) return;
781
- playbackError.value = errorMessage(error);
782
- emit("error", error);
783
- scheduler.invalidate({
784
- priority: "low",
785
- reason: "data"
786
- });
787
- } finally {
788
- if (activeAbort === abort) activeAbort = null;
789
- }
790
- })();
791
- }
792
- watch(() => props.paused, (paused) => {
793
- if (paused != null) internalPaused.value = paused;
794
- });
795
- watch(() => props.playbackRate, (rate) => {
796
- if (rate != null) internalPlaybackRate.value = playbackRate(rate);
797
- });
798
- watch([
799
- () => props.src,
800
- () => props.frameSource,
801
- playbackEnabled,
802
- resolvedDecodeFps,
803
- resolvedDecodeWidth,
804
- resolvedDecodeHeight,
805
- preferredFormat,
806
- effectivePlaybackRate,
807
- () => props.loop
808
- ], (next, previous) => {
809
- const sourceChanged = !previous || next[0] !== previous[0] || next[1] !== previous[1];
810
- const formatChanged = !previous || next[6] !== previous[6];
811
- if (sourceChanged || formatChanged) {
812
- resetQueuedFrameIdentity();
813
- if (sourceChanged) {
814
- lastTimestampMs = 0;
815
- displayedTimestampMs.value = 0;
816
- discoveredDurationMs.value = void 0;
817
- seekPreviewMs.value = void 0;
818
- seeking.value = false;
819
- suppressNextVideoClick = false;
820
- releaseControlPointer();
821
- droppedFrames = 0;
822
- }
823
- playbackError.value = "";
824
- frameRenderer.value = void 0;
825
- }
826
- startPlayback();
827
- }, {
828
- immediate: true,
829
- flush: "post"
830
- });
831
- onBeforeUnmount(() => {
832
- alive = false;
833
- stopPlayback();
834
- releaseControlPointer();
835
- mailbox.dispose();
836
- unsubscribeTerminalResize();
837
- unsubscribeGraphicsOutput();
838
- });
839
- return () => {
840
- const children = [h(TAgentTerminalGraphic, {
841
- x: props.x,
842
- y: props.y,
843
- w: props.w,
844
- h: videoHeight.value,
845
- zIndex: props.zIndex,
846
- content: props.src.trim() ? props.src : "video",
847
- fallback: visibleFallback.value,
848
- style: props.style,
849
- clear: props.clear,
850
- final: false,
851
- streaming: true,
852
- renderer: frameRenderer.value,
853
- placementKey,
854
- preserveRawWhileRendering: true,
855
- ignoreSamePlaneRawCoverage: true,
856
- suspended: !paintable.value
857
- })];
858
- if (props.controls) children.push(h(TView, {
859
- x: props.x,
860
- y: props.y,
861
- w: Math.max(0, Math.floor(props.w)),
862
- h: Math.max(0, Math.floor(props.h)),
863
- zIndex: props.zIndex,
864
- focusable: true,
865
- selectable: false,
866
- onClick: onVideoClick,
867
- onPointerdown: onInteractivePointerDown,
868
- onPointermove: onInteractivePointerMove,
869
- onPointerup: onInteractivePointerUp,
870
- onKeydown: onControlKeydown,
871
- onBlur: finishControlSeek
872
- }, () => {
873
- if (!showControls.value) return [];
874
- const layout$1 = controlLayout.value;
875
- const segments = progressSegments.value;
876
- const controls = Array.from({ length: controlRows.value }, (_, index) => h(TText, {
877
- x: 0,
878
- y: videoHeight.value + index,
879
- w: layout$1.width,
880
- value: controlFill.value,
881
- style: props.style
882
- }));
883
- controls.push(h(TText, {
884
- x: 0,
885
- y: layout$1.actionY,
886
- w: 2,
887
- value: effectivePaused.value ? "> " : "||",
888
- style: props.style
889
- }));
890
- if (layout$1.showTimes) if (layout$1.kind === "cinema") controls.push(h(TText, {
891
- x: layout$1.currentX,
892
- y: layout$1.actionY,
893
- w: textCellWidth(layout$1.timeText),
894
- value: layout$1.timeText,
895
- style: props.style
896
- }));
897
- else controls.push(h(TText, {
898
- x: layout$1.currentX,
899
- y: layout$1.actionY,
900
- w: layout$1.timeWidth,
901
- value: layout$1.current,
902
- style: props.style
903
- }), h(TText, {
904
- x: layout$1.totalX,
905
- y: layout$1.actionY,
906
- w: layout$1.timeWidth,
907
- value: layout$1.duration,
908
- style: props.style
909
- }));
910
- if (segments.playedWidth > 0) controls.push(h(TText, {
911
- x: layout$1.progressX,
912
- y: layout$1.progressY,
913
- w: segments.playedWidth,
914
- value: progressGlyphs.value.played,
915
- style: props.style
916
- }));
917
- if (segments.thumbWidth > 0) controls.push(h(TText, {
918
- x: layout$1.progressX + segments.playedWidth,
919
- y: layout$1.progressY,
920
- w: 1,
921
- value: "╋",
922
- style: progressThumbStyle.value
923
- }));
924
- if (segments.remainingWidth > 0) controls.push(h(TText, {
925
- x: layout$1.progressX + segments.playedWidth + segments.thumbWidth,
926
- y: layout$1.progressY,
927
- w: segments.remainingWidth,
928
- value: progressGlyphs.value.remaining,
929
- style: remainingProgressStyle.value
930
- }));
931
- if (layout$1.showAllRates) controls.push(...PLAYBACK_RATES.map((rate, index) => h(TText, {
932
- x: layout$1.ratesX + index * 3,
933
- y: layout$1.actionY,
934
- w: 2,
935
- value: `${rate}x`,
936
- style: rateStyles.value[index]
937
- })));
938
- else controls.push(h(TText, {
939
- x: layout$1.ratesX,
940
- y: layout$1.actionY,
941
- w: 2,
942
- value: `${effectivePlaybackRate.value}x`,
943
- style: rateStyles.value[PLAYBACK_RATES.indexOf(effectivePlaybackRate.value)]
944
- }));
945
- return controls;
946
- }));
947
- return h("span", rootProps, children);
948
- };
949
- }
950
- });
951
-
952
- //#endregion
953
15
  //#region src/vue/components/T3DViewport.ts
954
16
  const DEFAULT_MAX_FPS = 24;
955
17
  const DEFAULT_AUTO_ROTATE_SPEED = .35;