@vivix-labs/media-tools 1.0.0-beta.2 → 1.0.0-beta.21

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 (60) hide show
  1. package/README.md +38 -12
  2. package/dist/assets/1-1-WUUPNDJP.svg +7 -0
  3. package/dist/assets/16-9-BAFQTZK7.svg +9 -0
  4. package/dist/assets/2-3-WPG3UQBV.svg +7 -0
  5. package/dist/assets/3-2-YZTSUZ37.svg +7 -0
  6. package/dist/assets/3-4-7YROL4JU.svg +7 -0
  7. package/dist/assets/4-3-YG4LTLGD.svg +7 -0
  8. package/dist/assets/9-16-CYXX6QAR.svg +9 -0
  9. package/dist/assets/add-circle-RPMXNTWW.svg +4 -0
  10. package/dist/assets/captions-16-55I6JRWY.svg +5 -0
  11. package/dist/assets/captions-24-4YNDEZZX.svg +5 -0
  12. package/dist/assets/chevrons-up-down-KDZMS6DI.svg +3 -0
  13. package/dist/assets/collapse-diagonal-16-2IRQGCLB.svg +6 -0
  14. package/dist/assets/collapse-diagonal-24-GHD6Z54K.svg +6 -0
  15. package/dist/assets/copy-document-EF4PHM7F.svg +10 -0
  16. package/dist/assets/crop-5JXWHIPN.svg +6 -0
  17. package/dist/assets/delete-4Y3OUMEL.svg +8 -0
  18. package/dist/assets/download-16-QVS2YNPN.svg +4 -0
  19. package/dist/assets/download-24-ARCWU2MF.svg +4 -0
  20. package/dist/assets/download-VTKCEAZG.svg +6 -0
  21. package/dist/assets/expand-diagonal-16-QUIZSPJN.svg +10 -0
  22. package/dist/assets/expand-diagonal-24-XPK72ILY.svg +10 -0
  23. package/dist/assets/favorite-6GMNHJCN.svg +5 -0
  24. package/dist/assets/favorite-filled-FR74TEBM.svg +3 -0
  25. package/dist/assets/filter-JSDZZVGN.svg +5 -0
  26. package/dist/assets/freeform-E5MLUKDE.svg +18 -0
  27. package/dist/assets/fullscreen-exit-ADYOPBYH.svg +3 -0
  28. package/dist/assets/grid-16-POIO22HZ.svg +6 -0
  29. package/dist/assets/grid-24-U6IRT56K.svg +6 -0
  30. package/dist/assets/inria-serif-latin-400-italic-ZCFRMMVP.woff2 +0 -0
  31. package/dist/assets/inria-serif-latin-700-italic-UNRIXGAH.woff2 +0 -0
  32. package/dist/assets/inter-latin-900-normal-FKACR3DR.woff2 +0 -0
  33. package/dist/assets/list-16-YAVTLHXZ.svg +8 -0
  34. package/dist/assets/list-24-O6WDB6WJ.svg +8 -0
  35. package/dist/assets/original-LBKLUQVV.svg +18 -0
  36. package/dist/assets/pause-16-444PD7SY.svg +4 -0
  37. package/dist/assets/pause-24-WQXRNLW3.svg +4 -0
  38. package/dist/assets/play-16-5B2LZITW.svg +3 -0
  39. package/dist/assets/play-24-3IPXXAC4.svg +3 -0
  40. package/dist/assets/refresh-WQ3CTB57.svg +3 -0
  41. package/dist/assets/replace-PJXDOQDX.svg +3 -0
  42. package/dist/assets/{search-JUOSGQRM.svg → search-FMYQZJWA.svg} +1 -1
  43. package/dist/assets/select-items-GJZIVO37.svg +6 -0
  44. package/dist/assets/trim-LQMHHN2M.svg +9 -0
  45. package/dist/assets/upload-U5RZT5QI.svg +5 -0
  46. package/dist/assets/volume-16-ENYWJAGG.svg +5 -0
  47. package/dist/assets/volume-24-MVQ6CAXW.svg +5 -0
  48. package/dist/assets/volume-off-16-ALKG7632.svg +4 -0
  49. package/dist/assets/volume-off-24-2R4VED3N.svg +4 -0
  50. package/dist/client.bundle.js +1517 -262
  51. package/dist/client.css +2368 -181
  52. package/dist/server.d.ts +2 -1
  53. package/dist/server.js +1463 -259
  54. package/dist/shared.d.ts +513 -3
  55. package/dist/shared.js +230 -7
  56. package/{skills/SKILL.md → docs/operations.md} +7 -7
  57. package/package.json +5 -4
  58. package/studio-plugin.json +2 -5
  59. package/dist/assets/player-cover-shade-LLH6KOCQ.png +0 -0
  60. /package/{skills/references → docs}/processing.md +0 -0
@@ -1,8 +1,55 @@
1
1
  // packages/media-tools/src/client.tsx
2
- import * as React7 from "react";
2
+ import * as React8 from "react";
3
+
4
+ // packages/media-tools/src/export-settings.ts
5
+ var exportProfiles = {
6
+ h264: {
7
+ label: "MP4 \xB7 H.264",
8
+ extension: "mp4",
9
+ container: "mp4",
10
+ codec: "h264",
11
+ encoder: "libx264",
12
+ audio: "aac",
13
+ crf: [18, 23, 28]
14
+ },
15
+ hevc: {
16
+ label: "MP4 \xB7 H.265",
17
+ extension: "mp4",
18
+ container: "mp4",
19
+ codec: "hevc",
20
+ encoder: "libx265",
21
+ audio: "aac",
22
+ crf: [20, 25, 30]
23
+ },
24
+ vp9: {
25
+ label: "WebM \xB7 VP9",
26
+ extension: "webm",
27
+ container: "webm",
28
+ codec: "vp9",
29
+ encoder: "libvpx-vp9",
30
+ audio: "opus",
31
+ crf: [23, 31, 39]
32
+ }
33
+ };
34
+ var exportAspects = ["source", "16:9", "9:16", "1:1", "4:3", "3:4", "21:9"];
35
+ var exportResolutions = [480, 720, 1080, 2160];
36
+ var exportRates = [24, 25, 30, 50, 60];
37
+ var exportQualities = ["high", "standard", "small"];
38
+ function exportDimensions(source, aspect, resolution) {
39
+ if (aspect === "source" && resolution === "source") return source;
40
+ const [w = source.width, h = source.height] = aspect === "source" ? [] : aspect.split(":").map(Number);
41
+ const short = resolution === "source" ? Math.min(source.width, source.height) : resolution;
42
+ const even = (n) => 2 * Math.round(n / 2);
43
+ const width = w >= h ? even(short * w / h) : short;
44
+ const height = h >= w ? even(short * h / w) : short;
45
+ return Math.min(width, height) >= 2 && Math.max(width, height) <= 3840 && Math.min(width, height) <= 2160 ? { width, height } : null;
46
+ }
47
+ function exportName(name, extension) {
48
+ return `${name.trim().replace(/\.(mp4|webm)$/i, "").trim()}.${extension}`;
49
+ }
3
50
 
4
51
  // packages/media-tools/src/shared.ts
5
- import { z, PluginError } from "vivix-studio/sdk/shared";
52
+ import { z, PluginError, studioFileRef } from "vivix-studio/sdk/shared";
6
53
  var Config = z.object({
7
54
  dataInstance: z.string().min(1).default("user:data"),
8
55
  studioInstance: z.string().min(1).default("studio"),
@@ -19,6 +66,12 @@ var sequenceVideoInput = z.discriminatedUnion("kind", [
19
66
  sourceInput.extend({ trimEndMs: z.number().int().positive().optional() }),
20
67
  editInput
21
68
  ]);
69
+ var colorAdjustment = z.object({
70
+ brightness: z.number().finite().min(-0.5).max(0.5),
71
+ contrast: z.number().finite().min(0).max(2),
72
+ saturation: z.number().finite().min(0).max(2)
73
+ }).strict();
74
+ var neutralColor = { brightness: 0, contrast: 1, saturation: 1 };
22
75
  var recipe = z.object({
23
76
  trim: z.object({ inMs: z.number().int().nonnegative(), outMs: z.number().int().positive() }).strict(),
24
77
  crop: z.object({
@@ -26,13 +79,24 @@ var recipe = z.object({
26
79
  y: z.number().finite().nonnegative(),
27
80
  width: z.number().finite().positive().max(1),
28
81
  height: z.number().finite().positive().max(1)
29
- }).strict()
82
+ }).strict(),
83
+ color: colorAdjustment.optional(),
84
+ speed: z.number().finite().min(0.25).max(4).optional()
30
85
  }).strict().superRefine((v, c) => {
31
86
  if (v.trim.inMs >= v.trim.outMs)
32
87
  c.addIssue({ code: "custom", message: "The selected interval must have positive duration." });
33
88
  if (v.crop.x + v.crop.width > 1 + 1e-9 || v.crop.y + v.crop.height > 1 + 1e-9)
34
89
  c.addIssue({ code: "custom", message: "The crop must remain inside the source picture." });
35
90
  });
91
+ function recipeDurationMs(value) {
92
+ return Math.max(1, Math.round((value.trim.outMs - value.trim.inMs) / (value.speed ?? 1)));
93
+ }
94
+ var videoEditorTitles = {
95
+ crop: "Crop Video",
96
+ trim: "Trim Video",
97
+ color: "Adjust Color",
98
+ speed: "Video Speed"
99
+ };
36
100
  var pixelRect = z.object({
37
101
  x: z.number().int().nonnegative(),
38
102
  y: z.number().int().nonnegative(),
@@ -72,15 +136,99 @@ var saveEdit = z.object({
72
136
  c.addIssue({ code: "custom", message: "An edit update requires its revision." });
73
137
  });
74
138
  var outputName = z.string().trim().min(1).max(200);
75
- var processVideo = z.object({ input: videoInput, outputName, retryOfJobId: z.uuid().optional() }).strict();
139
+ var gain = z.number().finite().min(-96).max(24);
140
+ var milliseconds = z.number().int().min(0).max(6e5);
141
+ var audioMix = z.object({
142
+ version: z.literal(1),
143
+ originalGainDb: gain.nullable().optional(),
144
+ originals: z.array(
145
+ z.object({
146
+ inputIndex: z.number().int().min(0).max(63),
147
+ gainDb: gain.nullable(),
148
+ role: z.enum(["dialogue", "ambience"]).optional()
149
+ }).strict()
150
+ ).max(64).optional(),
151
+ tracks: z.array(
152
+ z.object({
153
+ id: z.string().trim().min(1).max(128),
154
+ file: videoFileRef,
155
+ role: z.enum(["narration", "music", "sfx"]),
156
+ atMs: milliseconds,
157
+ inMs: milliseconds.optional(),
158
+ outMs: milliseconds.optional(),
159
+ gainDb: gain.optional(),
160
+ fadeInMs: milliseconds.optional(),
161
+ fadeOutMs: milliseconds.optional()
162
+ }).strict()
163
+ ).max(32),
164
+ ducking: z.boolean().optional(),
165
+ loudness: z.enum(["studio-web-v1", "off"]).optional()
166
+ }).strict();
167
+ var maxSequenceInputs = 64;
168
+ var audioQuery = z.object({ inputs: z.array(sequenceVideoInput).min(1).max(maxSequenceInputs) }).strict();
169
+ var previewQuery = audioQuery.extend({
170
+ knownRevision: z.number().int().nonnegative().optional()
171
+ });
172
+ var audioPreviewResult = z.discriminatedUnion("state", [
173
+ z.object({ state: z.literal("original"), revision: z.number() }),
174
+ z.object({ state: z.literal("unchanged") }),
175
+ z.object({ state: z.literal("preparing") }),
176
+ z.object({
177
+ state: z.literal("ready"),
178
+ revision: z.number(),
179
+ file: studioFileRef().nullable(),
180
+ segments: z.array(z.object({ startMs: z.number(), durationMs: z.number().positive() }))
181
+ })
182
+ ]);
183
+ var saveAudio = audioQuery.extend({
184
+ expectedRevision: z.number().int().nonnegative(),
185
+ mix: audioMix.nullable()
186
+ });
187
+ var remixRequest = z.object({
188
+ basis: z.enum(["sources", "master"]),
189
+ mix: audioMix,
190
+ expectedAssetRevision: z.number().int().positive(),
191
+ expectedMixRevision: z.number().int().nonnegative()
192
+ }).strict();
193
+ var processVideo = z.object({
194
+ input: videoInput,
195
+ outputName,
196
+ retryOfJobId: z.uuid().optional(),
197
+ remix: remixRequest.optional()
198
+ }).strict().refine((v) => !v.remix || v.input.kind === "source", "Remix requires a fixed source file.");
76
199
  var canvas = z.object({ width: z.number().int().min(2).max(3840), height: z.number().int().min(2).max(3840) }).strict().refine(
77
200
  (v) => v.width % 2 === 0 && v.height % 2 === 0 && Math.min(v.width, v.height) <= 2160,
78
201
  "Canvas dimensions must be even and within 3840 by 2160."
79
202
  );
203
+ var exportFormat = z.enum(
204
+ Object.keys(exportProfiles)
205
+ );
206
+ var exportSettings = z.object({
207
+ format: exportFormat,
208
+ aspect: z.enum(exportAspects),
209
+ resolution: z.union([
210
+ z.literal("source"),
211
+ z.literal(480),
212
+ z.literal(720),
213
+ z.literal(1080),
214
+ z.literal(2160)
215
+ ]),
216
+ frameRate: z.union([
217
+ z.literal("source"),
218
+ z.literal(24),
219
+ z.literal(25),
220
+ z.literal(30),
221
+ z.literal(50),
222
+ z.literal(60)
223
+ ]),
224
+ quality: z.enum(exportQualities),
225
+ audio: z.boolean()
226
+ }).strict();
80
227
  var processSequence = z.object({
81
- inputs: z.array(sequenceVideoInput).min(1).max(64),
228
+ inputs: z.array(sequenceVideoInput).min(1).max(maxSequenceInputs),
82
229
  outputName,
83
230
  canvas,
231
+ settings: exportSettings.optional(),
84
232
  retryOfJobId: z.uuid().optional()
85
233
  }).strict();
86
234
  var mediaRequest = z.discriminatedUnion("operation", [
@@ -125,7 +273,9 @@ function normalizeRecipe(raw, displayWidth, displayHeight, durationMs) {
125
273
  y: y / displayHeight,
126
274
  width: pixelRect2.width / displayWidth,
127
275
  height: pixelRect2.height / displayHeight
128
- }
276
+ },
277
+ ...value.color ? { color: { ...value.color } } : {},
278
+ ...value.speed === void 0 ? {} : { speed: value.speed }
129
279
  },
130
280
  geometry: { displayWidth, displayHeight, pixelRect: pixelRect2 }
131
281
  };
@@ -174,10 +324,10 @@ async function submitOrFind(client, instanceId, request, requestKey) {
174
324
  import * as React4 from "react";
175
325
 
176
326
  // packages/ui-system/dist/button.js
177
- import { jsx as _jsx2, jsxs as _jsxs } from "react/jsx-runtime";
327
+ import { jsx as _jsx2, jsxs as _jsxs2 } from "react/jsx-runtime";
178
328
 
179
329
  // packages/ui-system/dist/icon.js
180
- import { jsx as _jsx } from "react/jsx-runtime";
330
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
181
331
  var iconGeometry = {
182
332
  add: {
183
333
  width: 16,
@@ -244,6 +394,10 @@ var iconGeometry = {
244
394
  height: 15.5625,
245
395
  slot: 18
246
396
  },
397
+ "select-items": { width: 13.8681, height: 13.8667, slot: 16 },
398
+ trim: { width: 14.85, height: 14.85, slot: 16 },
399
+ crop: { width: 16.25, height: 16.25, slot: 16 },
400
+ filter: { width: 13.2, height: 13.2, slot: 16 },
247
401
  select: {
248
402
  width: 14.6298,
249
403
  height: 16.065,
@@ -299,6 +453,7 @@ var iconGeometry = {
299
453
  height: 20,
300
454
  slot: 20
301
455
  },
456
+ "fullscreen-exit": { width: 20, height: 20, slot: 20 },
302
457
  "placeholder-image": {
303
458
  width: 20,
304
459
  height: 20,
@@ -324,6 +479,9 @@ var iconGeometry = {
324
479
  height: 13.2,
325
480
  slot: 16
326
481
  },
482
+ favorite: { width: 11.8667, height: 14.5333, slot: 16 },
483
+ download: { width: 13.2001, height: 13.1997, slot: 16 },
484
+ delete: { width: 13.2, height: 14.533, slot: 16 },
327
485
  edit: {
328
486
  width: 10.8791,
329
487
  height: 12.0459,
@@ -365,7 +523,7 @@ var iconGeometry = {
365
523
  slot: 24
366
524
  }
367
525
  };
368
- function Icon({ name, size }) {
526
+ function Icon({ name, size, iconSet }) {
369
527
  const geometry2 = iconGeometry[name];
370
528
  const style = {
371
529
  ...geometry2 && {
@@ -375,7 +533,10 @@ function Icon({ name, size }) {
375
533
  },
376
534
  ...size === void 0 ? {} : { "--vx-icon-size": `${size}px` }
377
535
  };
378
- return _jsx("span", { "aria-hidden": "true", className: "vx-icon", "data-icon": name, style });
536
+ if (name === "menu" || name === "relationships" || name === "color-adjust" || name === "speed") {
537
+ return _jsx("svg", { "aria-hidden": "true", className: "vx-icon", "data-icon": name, "data-icon-set": iconSet === "chat" ? "chat" : void 0, style, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: name === "menu" ? _jsx("path", { d: "M3 5h14M3 10h14M3 15h14" }) : name === "color-adjust" ? _jsxs(_Fragment, { children: [_jsx("path", { d: "M3 5h3m4 0h7M3 10h8m4 0h2M3 15h3m4 0h7" }), _jsx("circle", { cx: "8", cy: "5", r: "2" }), _jsx("circle", { cx: "13", cy: "10", r: "2" }), _jsx("circle", { cx: "8", cy: "15", r: "2" })] }) : name === "speed" ? _jsxs(_Fragment, { children: [_jsx("path", { d: "M4 16a8 8 0 1 1 12 0M10 3v2M3 10h2m10 0h2M5 5l1.4 1.4M10 12l4-5" }), _jsx("circle", { cx: "10", cy: "12", r: "1.5" })] }) : _jsxs(_Fragment, { children: [_jsx("path", { d: "M8.5 6.3 5 11.7M11.5 6.3 15 11.7M6.5 14.5h7" }), _jsx("circle", { cx: "10", cy: "4", r: "2.5" }), _jsx("circle", { cx: "4", cy: "14.5", r: "2.5" }), _jsx("circle", { cx: "16", cy: "14.5", r: "2.5" })] }) });
538
+ }
539
+ return _jsx("span", { "aria-hidden": "true", className: "vx-icon", "data-icon": name, "data-icon-set": iconSet === "chat" ? "chat" : void 0, style });
379
540
  }
380
541
 
381
542
  // packages/ui-system/dist/button-variants.js
@@ -384,6 +545,9 @@ var buttonVariants = {
384
545
  "text-filled-leading-sm": { size: 32, appearance: "filled", shape: "text" },
385
546
  "text-ghost-sm": { size: 32, appearance: "ghost", shape: "text" },
386
547
  "text-on-content-sm": { size: 32, appearance: "on-content", shape: "text" },
548
+ "text-plain-sm": { size: 32, appearance: "plain", shape: "text" },
549
+ "text-link-sm": { size: 32, appearance: "link", shape: "text" },
550
+ "text-outline-sm": { size: 32, appearance: "outline", shape: "text" },
387
551
  "text-tonal-sm": { size: 32, appearance: "tonal", shape: "text" },
388
552
  // The medium recipes are shared by all dialog footer actions.
389
553
  "text-filled-md": { size: 40, appearance: "filled", shape: "text" },
@@ -404,7 +568,7 @@ var buttonVariants = {
404
568
  "icon-outline-sm": { size: 32, appearance: "outline", shape: "icon" },
405
569
  "icon-on-content": { size: 24, appearance: "on-content", shape: "icon" },
406
570
  "icon-outline-lg": { size: 48, appearance: "outline", shape: "icon" },
407
- // Compact bare action: reuse the transparent/default and surface-hover ghost treatment.
571
+ // Compact bare action: remain transparent at rest and on hover.
408
572
  "icon-bare-xs": { size: 24, appearance: "ghost", shape: "icon" },
409
573
  "icon-ghost-sm": { size: 32, appearance: "ghost", shape: "icon" },
410
574
  "icon-ghost-lg": { size: 48, appearance: "ghost", shape: "icon" },
@@ -416,55 +580,229 @@ var buttonVariants = {
416
580
  function ButtonFrame({ label, variant, loading = false, width, children, disabled, type = "button", style, className, ...props }) {
417
581
  const spec = buttonVariants[variant];
418
582
  const buttonStyle = "width" in spec ? { ...style, "--vx-button-width": `${spec.width}px` } : style;
419
- return _jsxs("button", { ...props, type, className: className ? `vx-button ${className}` : "vx-button", "data-variant": variant, "data-appearance": spec.appearance, "data-shape": spec.shape, "data-size": spec.size, "data-width": width, "data-state": loading ? "loading" : disabled ? "disabled" : "default", style: buttonStyle, disabled: disabled || loading, "aria-label": label, "aria-busy": loading || void 0, children: [_jsx2("span", { className: "vx-button-content", children }), loading && _jsx2("span", { className: "vx-button-loading", "aria-hidden": "true" })] });
583
+ return _jsxs2("button", { ...props, type, className: className ? `vx-button ${className}` : "vx-button", "data-variant": variant, "data-appearance": spec.appearance, "data-shape": spec.shape, "data-size": spec.size, "data-width": width, "data-state": loading ? "loading" : disabled ? "disabled" : "default", style: buttonStyle, disabled: disabled || loading, "aria-label": label, "aria-busy": loading || void 0, children: [_jsx2("span", { className: "vx-button-content", children }), loading && _jsx2("span", { className: "vx-button-loading", "aria-hidden": "true" })] });
420
584
  }
421
- function Button({ variant = "text-filled-sm", leadingIcon, trailingIcon, ...props }) {
422
- return _jsxs(ButtonFrame, { ...props, variant, children: [leadingIcon && _jsx2(Icon, { name: leadingIcon }), _jsx2("span", { className: "vx-button-label", children: props.label }), trailingIcon && _jsx2("span", { className: "vx-button-trailing", children: _jsx2(Icon, { name: trailingIcon }) })] });
585
+ function Button({ variant = "text-filled-sm", leadingIcon, trailingIcon, badge, ...props }) {
586
+ return _jsxs2(ButtonFrame, { ...props, label: badge ? `${props.label} (${badge})` : props.label, variant, children: [leadingIcon && _jsx2(Icon, { name: leadingIcon }), _jsx2("span", { className: "vx-button-label", children: props.label }), badge !== void 0 && badge > 0 && _jsx2("span", { className: "vx-button-badge", children: badge }), trailingIcon && _jsx2("span", { className: "vx-button-trailing", children: _jsx2(Icon, { name: trailingIcon }) })] });
423
587
  }
424
588
  function IconButton({ icon, variant = "icon-ghost-sm", ...props }) {
425
589
  return _jsx2(ButtonFrame, { ...props, variant, children: _jsx2(Icon, { name: icon }) });
426
590
  }
427
591
 
592
+ // packages/ui-system/dist/tag.js
593
+ import { jsx as _jsx3 } from "react/jsx-runtime";
594
+ function Tag({ children, variant = "overlay", className }) {
595
+ return _jsx3("span", { className: className ? `vx-tag ${className}` : "vx-tag", "data-variant": variant, children });
596
+ }
597
+
598
+ // packages/ui-system/dist/dropdown.js
599
+ import { jsx as _jsx4, jsxs as _jsxs3 } from "react/jsx-runtime";
600
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
601
+ function optionIcon(icon) {
602
+ return typeof icon === "string" ? _jsx4(Icon, { name: icon }) : icon;
603
+ }
604
+ function Dropdown({ label, options, value, onValueChange, onReselect, placeholder = "Select an option", size = "medium", width = "fixed", appearance = "default", textSize = 14, floating = false, disabled = false }) {
605
+ const id = useId();
606
+ const trigger = useRef(null);
607
+ const list = useRef(null);
608
+ const heading = appearance === "heading";
609
+ const popover = heading || floating;
610
+ const activeOption = useRef(null);
611
+ const search = useRef({ query: "", time: 0 });
612
+ const [open, setOpen] = useState(false);
613
+ const [highlighted, setHighlighted] = useState(null);
614
+ const enabled = options.filter((option) => !option.disabled);
615
+ const canOpen = !disabled && enabled.length > 0;
616
+ const expanded = canOpen && open;
617
+ const selected = options.find((option) => option.value === value);
618
+ const active = enabled.find((option) => option.value === highlighted) ?? enabled.find((option) => option.value === value) ?? enabled[0];
619
+ const activeIndex = active ? enabled.indexOf(active) : -1;
620
+ useLayoutEffect(() => {
621
+ const anchor = trigger.current;
622
+ const popup = list.current;
623
+ if (!expanded || !popover || !popup || !anchor)
624
+ return;
625
+ const win = anchor.ownerDocument.defaultView;
626
+ popup.showPopover?.();
627
+ function place() {
628
+ if (!anchor || !popup)
629
+ return;
630
+ const box = anchor.getBoundingClientRect();
631
+ const width2 = anchor.ownerDocument.documentElement.clientWidth;
632
+ const margin = 8;
633
+ const gap = 4;
634
+ const below = win.innerHeight - box.bottom - gap - margin;
635
+ const above = box.top - gap - margin;
636
+ const up = below < Math.min(popup.scrollHeight, 240) && above > below;
637
+ popup.style.maxHeight = Math.max(0, Math.min(240, up ? above : below)) + "px";
638
+ if (floating)
639
+ popup.style.width = box.width + "px";
640
+ const size2 = popup.getBoundingClientRect();
641
+ popup.style.left = Math.max(margin, Math.min(box.left, width2 - size2.width - margin)) + "px";
642
+ popup.style.top = (up ? box.top - gap - size2.height : box.bottom + gap) + "px";
643
+ }
644
+ place();
645
+ win.addEventListener("resize", place);
646
+ win.addEventListener("scroll", place, true);
647
+ return () => {
648
+ popup.hidePopover?.();
649
+ win.removeEventListener("resize", place);
650
+ win.removeEventListener("scroll", place, true);
651
+ };
652
+ }, [expanded, floating, popover]);
653
+ useEffect(() => {
654
+ if (expanded)
655
+ activeOption.current?.scrollIntoView({ block: "nearest" });
656
+ }, [expanded, active?.value]);
657
+ useEffect(() => {
658
+ if (!canOpen) {
659
+ setOpen(false);
660
+ setHighlighted(null);
661
+ }
662
+ }, [canOpen]);
663
+ function close() {
664
+ search.current = { query: "", time: 0 };
665
+ setHighlighted(null);
666
+ setOpen(false);
667
+ }
668
+ function choose(option) {
669
+ close();
670
+ if (!option || option.disabled)
671
+ return;
672
+ if (option.value !== value)
673
+ onValueChange(option.value);
674
+ else
675
+ onReselect?.();
676
+ }
677
+ function handleKey(event) {
678
+ if (!canOpen || event.nativeEvent.isComposing)
679
+ return;
680
+ const { key } = event;
681
+ if (key === "Tab") {
682
+ if (expanded)
683
+ choose(active);
684
+ return;
685
+ }
686
+ if (key === "Escape") {
687
+ if (!expanded)
688
+ return;
689
+ event.preventDefault();
690
+ event.stopPropagation();
691
+ close();
692
+ return;
693
+ }
694
+ if (key === " " || key === "Enter") {
695
+ event.preventDefault();
696
+ if (expanded)
697
+ choose(active);
698
+ else
699
+ setOpen(true);
700
+ return;
701
+ }
702
+ if (key === "ArrowDown" || key === "ArrowUp" || key === "Home" || key === "End") {
703
+ event.preventDefault();
704
+ if (event.altKey && key === "ArrowUp" && expanded) {
705
+ choose(active);
706
+ return;
707
+ }
708
+ setOpen(true);
709
+ let index = activeIndex;
710
+ if (key === "Home")
711
+ index = 0;
712
+ else if (key === "End")
713
+ index = enabled.length - 1;
714
+ else if (expanded && !event.altKey) {
715
+ const step = key === "ArrowDown" ? 1 : -1;
716
+ index = Math.max(0, Math.min(activeIndex + step, enabled.length - 1));
717
+ }
718
+ setHighlighted(enabled[index]?.value ?? null);
719
+ return;
720
+ }
721
+ if (key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey)
722
+ return;
723
+ event.preventDefault();
724
+ const char = key.toLocaleLowerCase();
725
+ const previous = performance.now() - search.current.time < 500 ? search.current.query : "";
726
+ const repeated = previous.length > 0 && [...previous].every((letter) => letter === char);
727
+ const query = repeated ? char : previous + char;
728
+ search.current = { query, time: performance.now() };
729
+ const start = previous && !repeated ? activeIndex : activeIndex + 1;
730
+ const ordered = [...enabled.slice(start), ...enabled.slice(0, start)];
731
+ const match = ordered.find((option) => option.label.toLocaleLowerCase().startsWith(query));
732
+ setOpen(true);
733
+ if (match)
734
+ setHighlighted(match.value);
735
+ }
736
+ return _jsxs3("div", { className: "vx-dropdown", "data-size": size, "data-width": width, "data-appearance": appearance, "data-text-size": textSize, "data-floating": floating || void 0, children: [_jsxs3("button", { type: "button", ref: trigger, role: "combobox", className: "vx-dropdown-trigger", "aria-label": label, "aria-expanded": expanded, "aria-controls": `${id}-listbox`, "aria-activedescendant": expanded && active ? `${id}-option-${options.indexOf(active)}` : void 0, disabled: !canOpen, onClick: () => expanded ? close() : setOpen(true), onBlur: close, onKeyDown: handleKey, children: [_jsxs3("span", { className: "vx-dropdown-value", "data-placeholder": !selected || void 0, children: [optionIcon(selected?.icon), _jsx4("span", { children: selected?.triggerLabel ?? selected?.label ?? placeholder })] }), _jsx4(Icon, { name: expanded ? "chevron-up" : "chevron-down" })] }), _jsx4("ul", { ref: list, popover: popover ? "manual" : void 0, id: `${id}-listbox`, role: "listbox", "aria-label": label, hidden: !expanded, children: options.map((option, index) => _jsxs3("li", { id: `${id}-option-${index}`, ref: active === option ? activeOption : void 0, role: "option", "aria-selected": option.value === value, "aria-disabled": option.disabled || void 0, "data-active": active === option, onMouseDown: (event) => event.preventDefault(), onClick: () => {
737
+ if (!option.disabled)
738
+ choose(option);
739
+ }, children: [optionIcon(option.icon), option.label, width === "hug" && option.value === value && _jsx4(Icon, { name: "check" })] }, option.value)) })] });
740
+ }
741
+
428
742
  // packages/ui-system/dist/segmented-control.js
429
- import { jsx as _jsx3, jsxs as _jsxs2 } from "react/jsx-runtime";
430
- import { useId } from "react";
743
+ import { jsx as _jsx5, jsxs as _jsxs4 } from "react/jsx-runtime";
744
+ import { useId as useId2 } from "react";
431
745
  function SegmentedControl({ label, items, value, onValueChange, size = "medium", width = "fixed", iconOnly = false }) {
432
- const id = useId();
433
- return _jsx3("div", { role: "radiogroup", "aria-label": label, className: "vx-segment", "data-size": size, "data-width": width, "data-icon-only": iconOnly, children: items.map((item) => _jsxs2("label", { children: [_jsx3("input", { type: "radio", name: id, value: item.value, disabled: item.disabled, checked: item.value === value, "aria-label": item.label, onChange: () => onValueChange(item.value) }), _jsxs2("span", { className: "vx-segment-item", children: [item.icon && _jsx3(Icon, { name: item.icon }), (!iconOnly || !item.icon) && item.label] })] }, item.value)) });
746
+ const id = useId2();
747
+ return _jsx5("div", { role: "radiogroup", "aria-label": label, className: "vx-segment", "data-size": size, "data-width": width, "data-icon-only": iconOnly, children: items.map((item) => _jsxs4("label", { title: iconOnly ? item.label : void 0, children: [_jsx5("input", { type: "radio", name: id, value: item.value, disabled: item.disabled, checked: item.value === value, "aria-label": item.label, onChange: () => onValueChange(item.value) }), _jsxs4("span", { className: "vx-segment-item", children: [item.icon && _jsx5(Icon, { name: item.icon }), (!iconOnly || !item.icon) && item.label] })] }, item.value)) });
434
748
  }
435
749
 
436
- // packages/ui-system/dist/tag.js
437
- import { jsx as _jsx4 } from "react/jsx-runtime";
438
- function Tag({ children, variant = "overlay", className }) {
439
- return _jsx4("span", { className: className ? `vx-tag ${className}` : "vx-tag", "data-variant": variant, children });
750
+ // packages/ui-system/dist/input.js
751
+ import { jsx as _jsx6, jsxs as _jsxs5 } from "react/jsx-runtime";
752
+ import { useEffect as useEffect2, useState as useState2 } from "react";
753
+ function TextInput({ label, value, onValueChange, size = "medium", appearance = "default", placeholder, ...props }) {
754
+ return _jsxs5("label", { className: "vx-field", "data-size": size, "data-appearance": appearance, children: [_jsx6("span", { children: label }), _jsx6("input", { ...props, type: "text", placeholder: placeholder ?? (props.readOnly ? void 0 : "Enter text"), value, onChange: (event) => onValueChange(event.currentTarget.value) })] });
755
+ }
756
+
757
+ // packages/ui-system/dist/slider.js
758
+ import { jsx as _jsx7, jsxs as _jsxs6 } from "react/jsx-runtime";
759
+ function Slider({ label, value, unit = "", showHeading = true, appearance = "default", thumbSize = "default", headingWeight = "default", markers, hideCoveredMarkers = false, endpoints, endpointSize = 10, sourceBounds, onValueChange, ...props }) {
760
+ const control = _jsxs6("label", { className: "vx-slider", "data-appearance": appearance, "data-thumb-size": thumbSize === "large" ? "large" : void 0, "data-heading-weight": headingWeight === "semibold" ? "semibold" : void 0, "data-hide-covered-markers": hideCoveredMarkers || void 0, style: {
761
+ "--vx-slider-fill": `${Math.max(0, Math.min(100, (value - props.min) / (props.max - props.min || 1) * 100))}%`,
762
+ "--vx-slider-fraction": Math.max(0, Math.min(1, (value - props.min) / (props.max - props.min || 1)))
763
+ }, children: [showHeading && _jsxs6("span", { className: "vx-slider-heading", children: [_jsx7("span", { children: label }), _jsxs6("span", { "aria-hidden": "true", children: [value, unit] })] }), _jsx7("input", { ...props, type: "range", value, "aria-label": label, "aria-valuetext": unit ? `${value}${unit}` : void 0, onChange: (event) => onValueChange(event.currentTarget.valueAsNumber) }), markers && _jsx7("span", { className: "vx-slider-markers", "aria-hidden": "true", children: markers.map((markerValue, index) => _jsx7("span", { style: {
764
+ left: `${100 * (markerValue - props.min) / (props.max - props.min || 1)}%`
765
+ } }, index)) })] });
766
+ const trackNode = sourceBounds ? _jsx7("div", { className: "vx-source-slider", style: {
767
+ "--vx-source-start": (props.min - sourceBounds.min) / (sourceBounds.max - sourceBounds.min || 1),
768
+ "--vx-source-span": (props.max - props.min) / (sourceBounds.max - sourceBounds.min || 1),
769
+ "--vx-source-fraction": (value - sourceBounds.min) / (sourceBounds.max - sourceBounds.min || 1)
770
+ }, children: control }) : control;
771
+ if (!endpoints)
772
+ return trackNode;
773
+ return _jsxs6("div", { className: "vx-slider-group", children: [trackNode, _jsxs6("span", { className: "vx-slider-endpoints", "data-size": endpointSize, "aria-hidden": "true", children: [_jsx7("span", { children: endpoints[0] }), _jsx7("span", { children: endpoints[1] })] })] });
440
774
  }
441
775
 
442
776
  // packages/ui-system/dist/frame-range.js
443
- import { jsx as _jsx5, jsxs as _jsxs3, Fragment as _Fragment } from "react/jsx-runtime";
777
+ import { jsx as _jsx8, jsxs as _jsxs7, Fragment as _Fragment2 } from "react/jsx-runtime";
444
778
  var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
445
779
  function timeLabel(seconds) {
446
780
  const whole = Math.floor(seconds);
447
- return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
781
+ return `${String(Math.floor(whole / 60)).padStart(2, "0")}:${String(whole % 60).padStart(2, "0")}`;
448
782
  }
449
- function FrameRange({ duration, thumbnail, value, step = 0.1, variant = "range", onValueChange }) {
783
+ function FrameRange({ duration, thumbnail, frames, value, step = 0.1, variant = "range", appearance = "workbench", rulerTicks, disabled, trackTitle, onValueChange }) {
450
784
  const length = Number.isFinite(duration) && duration > 0 ? duration : 0;
451
785
  const increment = Math.min(length, Number.isFinite(step) && step > 0 ? step : 0.1);
452
786
  const start = clamp(Number.isFinite(value.start) ? value.start : 0, 0, length - increment);
453
787
  const end = clamp(Number.isFinite(value.end) ? value.end : length, Math.min(length, start + increment), length);
454
788
  function move(edge, next) {
789
+ if (disabled)
790
+ return;
455
791
  const rounded = Math.round(next / increment) * increment;
456
792
  const range = edge === "start" ? { start: clamp(rounded, 0, end - increment), end } : { start, end: clamp(next >= length ? length : rounded, start + increment, length) };
457
793
  if (range.start !== start || range.end !== end)
458
794
  onValueChange(range);
459
795
  }
460
796
  function drag(event, edge) {
461
- if (!event.currentTarget.hasPointerCapture(event.pointerId))
797
+ if (disabled || !event.currentTarget.hasPointerCapture(event.pointerId))
462
798
  return;
463
799
  const box = event.currentTarget.closest(".vx-frame-range")?.getBoundingClientRect();
464
800
  if (box?.width)
465
801
  move(edge, (event.clientX - box.left) / box.width * length);
466
802
  }
467
803
  function handleKey(event, edge, current) {
804
+ if (disabled)
805
+ return;
468
806
  const changes = {
469
807
  ArrowLeft: current - increment,
470
808
  ArrowDown: current - increment,
@@ -479,39 +817,53 @@ function FrameRange({ duration, thumbnail, value, step = 0.1, variant = "range",
479
817
  event.preventDefault();
480
818
  move(edge, next);
481
819
  }
482
- return _jsxs3("div", { className: "vx-frame-range", "data-variant": variant, role: "group", "aria-label": "Playback range", "aria-disabled": !length, style: length ? {
820
+ const rangeElement = _jsxs7("div", { className: "vx-frame-range", "data-variant": variant, "data-appearance": appearance === "chat" ? "chat" : void 0, role: "group", "aria-label": "Playback range", "aria-disabled": !length || disabled || void 0, style: length ? {
483
821
  "--vx-range-start": `${start / length * 100}%`,
484
822
  "--vx-range-end": `${end / length * 100}%`
485
- } : void 0, children: [thumbnail && length > 0 && _jsx5("img", { src: thumbnail, alt: "" }), length > 0 && _jsxs3(_Fragment, { children: [_jsx5("span", { className: "vx-frame-selection", "aria-hidden": "true", children: _jsxs3(Tag, { children: [timeLabel(start), " \u2013 ", timeLabel(end)] }) }), ["start", "end"].map((edge) => {
823
+ } : void 0, children: [frames?.length && length > 0 ? _jsx8("div", { className: "vx-frame-filmstrip", children: frames.map((src, index) => _jsx8("img", { src, alt: "" }, index)) }) : thumbnail && length > 0 && _jsx8("img", { src: thumbnail, alt: "" }), length > 0 && _jsxs7(_Fragment2, { children: [_jsx8("span", { className: "vx-frame-selection", "aria-hidden": "true", children: _jsxs7(Tag, { variant: variant === "trim" ? "selected" : "overlay", children: [timeLabel(start), " \u2013 ", timeLabel(end)] }) }), ["start", "end"].map((edge) => {
486
824
  const current = edge === "start" ? start : end;
487
- return _jsx5("div", { tabIndex: 0, role: "slider", className: "vx-frame-handle", "data-edge": edge, "aria-label": edge === "start" ? "Range start" : "Range end", "aria-valuemin": edge === "start" ? 0 : start + increment, "aria-valuemax": edge === "start" ? end - increment : length, "aria-valuenow": current, "aria-valuetext": `${Number(current.toFixed(3))} seconds`, onKeyDown: (event) => handleKey(event, edge, current), onPointerDown: (event) => {
488
- if (event.button !== 0)
825
+ return _jsx8("div", { tabIndex: disabled ? -1 : 0, role: "slider", className: "vx-frame-handle", "data-edge": edge, "aria-label": edge === "start" ? "Range start" : "Range end", "aria-valuemin": edge === "start" ? 0 : start + increment, "aria-valuemax": edge === "start" ? end - increment : length, "aria-valuenow": current, "aria-valuetext": `${Number(current.toFixed(3))} seconds`, onKeyDown: (event) => handleKey(event, edge, current), onPointerDown: (event) => {
826
+ if (disabled || event.button !== 0)
489
827
  return;
490
828
  event.currentTarget.focus();
491
829
  event.currentTarget.setPointerCapture(event.pointerId);
492
830
  }, onPointerMove: (event) => drag(event, edge) }, edge);
493
831
  })] })] });
832
+ if (!rulerTicks)
833
+ return rangeElement;
834
+ return _jsxs7("div", { className: "vx-frame-range-timeline", children: [_jsx8("div", { className: "vx-frame-range-ticks", "aria-hidden": "true", children: rulerTicks.map((tick, index) => _jsx8("span", { style: { left: `${tick.positionPercent}%` }, children: tick.label }, tick.key ?? index)) }), _jsx8("div", { className: "vx-frame-range-track", inert: disabled || void 0, "aria-disabled": disabled || void 0, title: trackTitle, style: {
835
+ "--vx-trim-label-space": `${(1 - start / (length || 1)) * 100}cqw`
836
+ }, children: rangeElement })] });
494
837
  }
495
838
 
496
839
  // packages/ui-system/dist/dialog.js
497
- import { jsx as _jsx6, jsxs as _jsxs4, Fragment as _Fragment2 } from "react/jsx-runtime";
498
- import { useId as useId2, useLayoutEffect, useRef, useState } from "react";
840
+ import { jsx as _jsx9, jsxs as _jsxs8, Fragment as _Fragment3 } from "react/jsx-runtime";
841
+ import { useId as useId3, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState3 } from "react";
499
842
  import { createPortal } from "react-dom";
500
843
 
501
844
  // packages/ui-system/dist/dialog-surface.js
502
- function createDialogSurface(anchor) {
845
+ var overlayOpeningEvent = "vx-overlay-opening";
846
+ function outerDialogDocument(anchor) {
503
847
  const source = anchor.ownerDocument;
504
- let target;
505
848
  try {
506
- target = source.defaultView?.top?.document ?? source;
849
+ const target = source.defaultView?.top?.document;
850
+ return target && target !== source ? target : void 0;
507
851
  } catch {
508
852
  return void 0;
509
853
  }
510
- if (target === source)
854
+ }
855
+ function createDialogSurface(anchor) {
856
+ const source = anchor.ownerDocument;
857
+ const target = outerDialogDocument(anchor);
858
+ if (!target)
511
859
  return void 0;
512
860
  const host = target.createElement("div");
513
861
  host.dataset.studioDialogSurface = "";
514
862
  const shadow = host.attachShadow({ mode: "open" });
863
+ shadow.addEventListener("beforetoggle", (event) => {
864
+ if (event.newState === "open" && !event.target.classList.contains("vx-toast"))
865
+ target.dispatchEvent(new Event(overlayOpeningEvent));
866
+ }, true);
515
867
  for (const original of source.querySelectorAll('link[rel="stylesheet"], style')) {
516
868
  const clone = original.cloneNode(true);
517
869
  if (original.tagName === "LINK")
@@ -547,13 +899,21 @@ function createDialogSurface(anchor) {
547
899
  }
548
900
 
549
901
  // packages/ui-system/dist/dialog.js
550
- function Dialog({ title, open, onOpenChange, children, actions, className, variant = "default" }) {
551
- const ref = useRef(null);
552
- const anchor = useRef(null);
553
- const [surface, setSurface] = useState();
554
- const heading = useId2();
555
- useLayoutEffect(() => {
556
- if (!open || !anchor.current)
902
+ function useInlineDialog(anchor) {
903
+ const [inline, setInline] = useState3(false);
904
+ useLayoutEffect2(() => {
905
+ if (anchor.current)
906
+ setInline(!outerDialogDocument(anchor.current));
907
+ }, [anchor]);
908
+ return inline;
909
+ }
910
+ function Dialog({ title, open, onOpenChange, children, actions, className, inlineWhenClosed = false, variant = "default", closeOnEscape = true, focusTitleOnOpen = variant === "welcome" }) {
911
+ const ref = useRef2(null);
912
+ const anchor = useRef2(null);
913
+ const [surface, setSurface] = useState3();
914
+ const heading = useId3();
915
+ useLayoutEffect2(() => {
916
+ if (inlineWhenClosed || !open || !anchor.current)
557
917
  return;
558
918
  const mounted = createDialogSurface(anchor.current);
559
919
  const active = anchor.current.getRootNode().activeElement;
@@ -566,9 +926,20 @@ function Dialog({ title, open, onOpenChange, children, actions, className, varia
566
926
  active.focus();
567
927
  });
568
928
  };
569
- }, [open]);
570
- useLayoutEffect(() => {
929
+ }, [open, inlineWhenClosed]);
930
+ useLayoutEffect2(() => {
571
931
  const dialog2 = ref.current;
932
+ if (inlineWhenClosed && dialog2) {
933
+ if (open) {
934
+ dialog2.close();
935
+ dialog2.showModal();
936
+ } else {
937
+ if (dialog2.matches(":modal"))
938
+ dialog2.close();
939
+ dialog2.open = true;
940
+ }
941
+ return;
942
+ }
572
943
  if (!open || surface === void 0 || !dialog2)
573
944
  return;
574
945
  dialog2.showModal();
@@ -576,34 +947,123 @@ function Dialog({ title, open, onOpenChange, children, actions, className, varia
576
947
  if (dialog2.open)
577
948
  dialog2.close();
578
949
  };
579
- }, [open, surface]);
580
- const dialog = _jsxs4("dialog", { ref, className: className ? `vx-dialog ${className}` : "vx-dialog", "data-variant": variant === "default" ? void 0 : variant, "aria-labelledby": heading, onCancel: (event) => {
950
+ }, [open, surface, inlineWhenClosed]);
951
+ const welcome = variant === "welcome";
952
+ const closeButton = _jsx9(IconButton, { icon: "close", label: "Close dialog", onClick: () => onOpenChange(false) });
953
+ const dialog = _jsxs8("dialog", { ref, open: inlineWhenClosed || void 0, className: inlineWhenClosed && !open ? "vx-dialog vx-dialog-inline" : className ? `vx-dialog ${className}` : "vx-dialog", "data-variant": variant === "default" ? void 0 : variant, role: inlineWhenClosed && !open ? "presentation" : void 0, "aria-labelledby": inlineWhenClosed && !open ? void 0 : heading, onCancel: (event) => {
581
954
  event.preventDefault();
582
955
  event.stopPropagation();
583
- onOpenChange(false);
956
+ if (closeOnEscape)
957
+ onOpenChange(false);
584
958
  }, onClose: (event) => {
585
959
  if (open && event.currentTarget.isConnected && !event.currentTarget.open)
586
960
  onOpenChange(false);
587
- }, children: [_jsxs4("header", { children: [_jsx6("h2", { id: heading, children: title }), _jsx6(IconButton, { icon: "close", label: "Close dialog", onClick: () => onOpenChange(false) })] }), _jsx6("div", { className: "vx-dialog-body", children }), actions && _jsx6("footer", { children: actions })] });
588
- return _jsxs4(_Fragment2, { children: [_jsx6("span", { ref: anchor, hidden: true }), open && (surface ? createPortal(dialog, surface) : dialog)] });
961
+ }, children: [_jsxs8("header", { hidden: inlineWhenClosed && !open, children: [_jsx9("h2", { id: heading, tabIndex: focusTitleOnOpen ? -1 : void 0, autoFocus: focusTitleOnOpen, children: title }), !welcome && closeButton] }), _jsx9("div", { className: "vx-dialog-body", children }), (actions || welcome) && _jsxs8("footer", { hidden: inlineWhenClosed && !open, children: [actions, welcome && closeButton] })] });
962
+ return _jsxs8(_Fragment3, { children: [_jsx9("span", { ref: anchor, hidden: true }), (open || inlineWhenClosed) && (surface ? createPortal(dialog, surface) : dialog)] });
589
963
  }
590
964
 
591
- // packages/ui-system/dist/menu.js
592
- import { jsx as _jsx7, jsxs as _jsxs5 } from "react/jsx-runtime";
593
- import { useEffect, useId as useId3, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
965
+ // packages/ui-system/dist/toast.js
966
+ import { jsx as _jsx10, jsxs as _jsxs9, Fragment as _Fragment4 } from "react/jsx-runtime";
967
+ import { useCallback, useEffect as useEffect3, useLayoutEffect as useLayoutEffect3, useRef as useRef3, useState as useState4 } from "react";
594
968
  import { createPortal as createPortal2 } from "react-dom";
969
+ function useToastMessage() {
970
+ const [message, setMessage] = useState4("");
971
+ const timeout = useRef3(void 0);
972
+ useEffect3(() => () => clearTimeout(timeout.current), []);
973
+ const show = useCallback((text) => {
974
+ clearTimeout(timeout.current);
975
+ setMessage(text);
976
+ if (text)
977
+ timeout.current = setTimeout(() => setMessage(""), 2e3);
978
+ }, []);
979
+ return [message, show];
980
+ }
981
+ function Toast({ message, leading, className }) {
982
+ const anchor = useRef3(null);
983
+ const ref = useRef3(null);
984
+ const [surface, setSurface] = useState4();
985
+ const visible = Boolean(message);
986
+ useLayoutEffect3(() => {
987
+ if (!visible || !anchor.current)
988
+ return;
989
+ const mounted = createDialogSurface(anchor.current);
990
+ setSurface(mounted?.root ?? null);
991
+ return () => {
992
+ mounted?.dispose();
993
+ setSurface(void 0);
994
+ };
995
+ }, [visible]);
996
+ useLayoutEffect3(() => {
997
+ const toast = ref.current;
998
+ if (!toast || !visible)
999
+ return;
1000
+ const doc = toast.ownerDocument;
1001
+ const win = doc.defaultView;
1002
+ let frame = 0;
1003
+ const bringToFront = () => {
1004
+ win.cancelAnimationFrame(frame);
1005
+ frame = win.requestAnimationFrame(() => {
1006
+ toast.hidePopover();
1007
+ toast.showPopover();
1008
+ });
1009
+ };
1010
+ function onOpening(event) {
1011
+ const target = event.target;
1012
+ if (event.newState === "open" && !target.classList.contains("vx-toast"))
1013
+ bringToFront();
1014
+ }
1015
+ toast.showPopover();
1016
+ doc.addEventListener("beforetoggle", onOpening, true);
1017
+ doc.addEventListener(overlayOpeningEvent, bringToFront);
1018
+ doc.addEventListener("fullscreenchange", bringToFront);
1019
+ return () => {
1020
+ win.cancelAnimationFrame(frame);
1021
+ doc.removeEventListener("beforetoggle", onOpening, true);
1022
+ doc.removeEventListener(overlayOpeningEvent, bringToFront);
1023
+ doc.removeEventListener("fullscreenchange", bringToFront);
1024
+ };
1025
+ }, [visible, surface]);
1026
+ const notice = visible && surface !== void 0 && _jsxs9("div", { ref, popover: "manual", role: "status", "aria-atomic": "true", className: className ? `vx-toast ${className}` : "vx-toast", children: [leading, _jsx10("span", { children: message })] });
1027
+ return _jsxs9(_Fragment4, { children: [_jsx10("span", { hidden: true, ref: anchor }), surface ? createPortal2(notice, surface) : notice] });
1028
+ }
1029
+
1030
+ // packages/ui-system/dist/menu.js
1031
+ import { jsx as _jsx11, jsxs as _jsxs10 } from "react/jsx-runtime";
1032
+ import { useEffect as useEffect4, useId as useId4, useLayoutEffect as useLayoutEffect4, useRef as useRef4, useState as useState5 } from "react";
1033
+ import { createPortal as createPortal3 } from "react-dom";
1034
+ function MenuPreview({ children }) {
1035
+ const ref = useRef4(null);
1036
+ const [visible, setVisible] = useState5(false);
1037
+ useEffect4(() => {
1038
+ const node = ref.current;
1039
+ if (!node)
1040
+ return;
1041
+ const observer = new IntersectionObserver(([entry]) => {
1042
+ if (entry?.isIntersecting) {
1043
+ setVisible(true);
1044
+ observer.disconnect();
1045
+ }
1046
+ });
1047
+ observer.observe(node);
1048
+ return () => observer.disconnect();
1049
+ }, []);
1050
+ return _jsx11("span", { ref, className: "vx-menu-preview", "aria-hidden": "true", children: visible && children });
1051
+ }
595
1052
  function isEnabled(item) {
596
1053
  return !item.disabled && item.items?.length !== 0;
597
1054
  }
598
- function Menu({ label, items, triggerIcon, floating = false }) {
599
- const id = useId3();
600
- const trigger = useRef2(null);
601
- const popup = useRef2(null);
602
- const focusIndex = useRef2(0);
603
- const [path, setPath] = useState2(null);
604
- const [placement, setPlacement] = useState2({ visibility: "hidden" });
1055
+ function Menu({ label, items, triggerIcon, textTrigger = "dropdown", floating = false, cascading = false }) {
1056
+ const id = useId4();
1057
+ const trigger = useRef4(null);
1058
+ const popup = useRef4(null);
1059
+ const children = useRef4(/* @__PURE__ */ new Map());
1060
+ const focusOnOpen = useRef4(true);
1061
+ const cascade = floating && cascading;
1062
+ const focusIndex = useRef4(0);
1063
+ const [path, setPath] = useState5(null);
1064
+ const [placement, setPlacement] = useState5({ visibility: "hidden" });
605
1065
  const portalRoot = floating ? trigger.current?.closest("dialog, [data-vx-theme]") : null;
606
- useLayoutEffect2(() => {
1066
+ useLayoutEffect4(() => {
607
1067
  if (!floating || !path || !portalRoot)
608
1068
  return;
609
1069
  const position = () => {
@@ -611,56 +1071,77 @@ function Menu({ label, items, triggerIcon, floating = false }) {
611
1071
  if (!anchor || !menu2)
612
1072
  return;
613
1073
  const document3 = anchor.ownerDocument;
614
- const window2 = document3.defaultView;
1074
+ const window3 = document3.defaultView;
615
1075
  const rect = anchor.getBoundingClientRect();
616
- const width = document3.documentElement.clientWidth, height = window2.innerHeight;
1076
+ const width = document3.documentElement.clientWidth, height = window3.innerHeight;
617
1077
  const bounds = menu2.getBoundingClientRect();
618
1078
  const naturalHeight = menu2.scrollHeight + bounds.height - menu2.clientHeight;
619
1079
  const below = Math.max(0, height - rect.bottom - 12), above = Math.max(0, rect.top - 12);
620
1080
  const flip = naturalHeight > below && above > below;
621
1081
  const maxHeight = Math.max(0, Math.min(480, height - 16, flip ? above : below));
622
1082
  const menuHeight = Math.min(naturalHeight, maxHeight);
1083
+ const left = Math.max(8, Math.min(rect.right - bounds.width, width - bounds.width - 8));
1084
+ const top = Math.max(8, Math.min(flip ? rect.top - menuHeight - 4 : rect.bottom + 4, height - menuHeight - 8));
623
1085
  setPlacement({
624
1086
  position: "fixed",
625
1087
  visibility: "visible",
626
1088
  insetInlineStart: "auto",
627
- left: Math.max(8, Math.min(rect.right - bounds.width, width - bounds.width - 8)),
628
- top: Math.max(8, Math.min(flip ? rect.top - menuHeight - 4 : rect.bottom + 4, height - menuHeight - 8)),
1089
+ left,
1090
+ top,
629
1091
  maxHeight,
630
1092
  zIndex: 100
631
1093
  });
1094
+ let parent = menu2, parentLeft = left, parentTop = top;
1095
+ for (let depth = 1; cascade && depth <= path.length; depth++) {
1096
+ const panel = children.current.get(depth);
1097
+ const item = Array.from(parent.querySelectorAll("button")).find((b) => b.dataset.key === path[depth - 1]);
1098
+ if (!panel || !item)
1099
+ break;
1100
+ const parentBox = parent.getBoundingClientRect(), box = panel.getBoundingClientRect();
1101
+ const nextLeft = parentLeft + parentBox.width;
1102
+ parentLeft = Math.max(8, Math.min(nextLeft + box.width <= width - 8 ? nextLeft : parentLeft - box.width, width - box.width - 8));
1103
+ parentTop = Math.max(8, Math.min(parentTop + item.getBoundingClientRect().top - parentBox.top - 4, height - box.height - 8));
1104
+ Object.assign(panel.style, {
1105
+ left: parentLeft + "px",
1106
+ top: parentTop + "px",
1107
+ visibility: "visible"
1108
+ });
1109
+ parent = panel;
1110
+ }
632
1111
  };
633
1112
  const outside = (event) => {
634
1113
  const path2 = event.composedPath();
635
- if (!path2.includes(trigger.current) && !path2.includes(popup.current))
1114
+ if (!path2.includes(trigger.current) && !path2.includes(popup.current) && ![...children.current.values()].some((panel) => path2.includes(panel)))
636
1115
  setPath(null);
637
1116
  };
638
1117
  const document2 = portalRoot.ownerDocument;
639
- const window = document2.defaultView;
1118
+ const window2 = document2.defaultView;
640
1119
  position();
641
- window.addEventListener("resize", position);
642
- window.addEventListener("scroll", position, true);
1120
+ window2.addEventListener("resize", position);
1121
+ window2.addEventListener("scroll", position, true);
643
1122
  document2.addEventListener("pointerdown", outside);
644
1123
  return () => {
645
- window.removeEventListener("resize", position);
646
- window.removeEventListener("scroll", position, true);
1124
+ window2.removeEventListener("resize", position);
1125
+ window2.removeEventListener("scroll", position, true);
647
1126
  document2.removeEventListener("pointerdown", outside);
648
1127
  };
649
- }, [floating, path, portalRoot]);
1128
+ }, [floating, path, portalRoot, cascade]);
650
1129
  let entries = items;
651
1130
  let menuLabel = label;
1131
+ const levels = [{ entries, menuLabel }];
652
1132
  for (const key of path ?? []) {
653
1133
  const entry = entries.find((item) => item.id === key);
654
1134
  if (!entry?.items)
655
1135
  break;
656
1136
  menuLabel = entry.label;
657
1137
  entries = entry.items;
1138
+ levels.push({ entries, menuLabel });
658
1139
  }
659
- function buttons() {
660
- return [...popup.current?.querySelectorAll("button:not(:disabled)") ?? []];
1140
+ function buttons(panel = cascade && path?.length ? children.current.get(path.length) : popup.current) {
1141
+ return [...panel?.querySelectorAll("button:not(:disabled)") ?? []];
661
1142
  }
662
- useEffect(() => {
663
- if (path && (!floating || !portalRoot || placement.visibility === "visible"))
1143
+ useEffect4(() => {
1144
+ if (focusOnOpen.current && path && (!floating || !portalRoot || placement.visibility === "visible"))
664
1145
  buttons().at(focusIndex.current)?.focus();
665
1146
  }, [path, floating && placement.visibility, portalRoot]);
666
1147
  function close() {
@@ -668,6 +1149,7 @@ function Menu({ label, items, triggerIcon, floating = false }) {
668
1149
  trigger.current?.focus();
669
1150
  }
670
1151
  function back() {
1152
+ focusOnOpen.current = true;
671
1153
  if (!path?.length)
672
1154
  return;
673
1155
  const parentPath = path.slice(0, -1);
@@ -675,24 +1157,27 @@ function Menu({ label, items, triggerIcon, floating = false }) {
675
1157
  focusIndex.current = Math.max(0, parent.filter(isEnabled).findIndex((item) => item.id === path.at(-1)));
676
1158
  setPath(parentPath);
677
1159
  }
678
- function choose(item) {
1160
+ function choose(item, depth) {
1161
+ focusOnOpen.current = true;
679
1162
  if (item.items?.length) {
680
1163
  focusIndex.current = 0;
681
- setPath([...path ?? [], item.id]);
1164
+ setPath([...(path ?? []).slice(0, depth), item.id]);
1165
+ if (cascade && path?.[depth] === item.id)
1166
+ buttons(children.current.get(depth + 1))?.at(0)?.focus();
682
1167
  } else if (item.onSelect) {
683
1168
  if (item.checked === void 0)
684
1169
  close();
685
1170
  item.onSelect();
686
1171
  }
687
1172
  }
688
- function handleKey(event) {
1173
+ function handleKey(event, depth) {
689
1174
  if (event.key === "Tab" && floating && portalRoot) {
690
1175
  if (event.shiftKey)
691
1176
  event.preventDefault();
692
1177
  close();
693
1178
  return;
694
1179
  }
695
- const available = buttons();
1180
+ const available = buttons(event.currentTarget);
696
1181
  const index = available.findIndex((button) => button === event.target);
697
1182
  if (event.key === "Escape") {
698
1183
  event.preventDefault();
@@ -709,10 +1194,10 @@ function Menu({ label, items, triggerIcon, floating = false }) {
709
1194
  return;
710
1195
  }
711
1196
  if (event.key === "ArrowRight") {
712
- const item = entries.filter(isEnabled)[index];
1197
+ const item = levels[depth]?.entries.filter(isEnabled)[index];
713
1198
  if (item?.items?.length) {
714
1199
  event.preventDefault();
715
- choose(item);
1200
+ choose(item, depth);
716
1201
  }
717
1202
  return;
718
1203
  }
@@ -728,6 +1213,7 @@ function Menu({ label, items, triggerIcon, floating = false }) {
728
1213
  }
729
1214
  }
730
1215
  function open(index = 0) {
1216
+ focusOnOpen.current = true;
731
1217
  focusIndex.current = index;
732
1218
  setPath([]);
733
1219
  }
@@ -737,40 +1223,147 @@ function Menu({ label, items, triggerIcon, floating = false }) {
737
1223
  open(event.key === "ArrowUp" ? -1 : 0);
738
1224
  }
739
1225
  }
740
- const menu = _jsx7("div", { ref: popup, className: "vx-action-menu-items", role: "menu", id, "aria-label": menuLabel, hidden: !path, onKeyDown: handleKey, "data-floating": floating || void 0, style: floating && portalRoot ? placement : void 0, children: entries.map((item) => _jsxs5("button", { type: "button", role: item.checked === void 0 ? "menuitem" : "menuitemcheckbox", "aria-checked": item.checked, "aria-haspopup": item.items?.length ? "menu" : void 0, "data-size": item.size ?? "medium", disabled: !isEnabled(item), tabIndex: -1, onClick: () => choose(item), children: [item.icon && _jsx7(Icon, { name: item.icon }), _jsx7("span", { children: item.label }), item.checked && _jsx7(Icon, { name: "check" }), item.items?.length ? _jsx7(Icon, { name: "chevron-right" }) : null] }, item.id)) });
741
- return _jsxs5("div", { className: "vx-action-menu", onBlur: (event) => {
742
- if (!event.currentTarget.contains(event.relatedTarget) && !(floating && popup.current?.contains(event.relatedTarget)))
1226
+ function hover(item, depth) {
1227
+ if (!cascade || !path)
1228
+ return;
1229
+ const next = path.slice(0, depth);
1230
+ if (item.items?.length && isEnabled(item))
1231
+ next.push(item.id);
1232
+ if (next.length === path.length && next.every((key, i) => path[i] === key))
1233
+ return;
1234
+ focusOnOpen.current = false;
1235
+ setPath(next);
1236
+ }
1237
+ const menu = levels.map(({ entries: entries2, menuLabel: menuLabel2 }, depth) => !cascade && depth !== levels.length - 1 ? null : _jsx11("div", { ref: !cascade || depth === 0 ? popup : (el) => {
1238
+ if (el)
1239
+ children.current.set(depth, el);
1240
+ else
1241
+ children.current.delete(depth);
1242
+ }, className: "vx-action-menu-items", role: "menu", id: !cascade || !depth ? id : id + "-" + depth, "aria-label": menuLabel2, hidden: !path, onKeyDown: (e) => handleKey(e, depth), "data-with-previews": entries2.some((item) => item.preview) || void 0, "data-floating": floating || void 0, style: floating && portalRoot ? cascade && depth ? {
1243
+ position: "fixed",
1244
+ insetInlineStart: "auto",
1245
+ visibility: "hidden",
1246
+ maxHeight: "min(480px, calc(100dvh - 16px))",
1247
+ zIndex: 100 + depth
1248
+ } : placement : void 0, children: entries2.map((item) => _jsxs10("button", { type: "button", role: item.checked === void 0 ? "menuitem" : "menuitemcheckbox", "aria-checked": item.checked, "aria-haspopup": item.items?.length ? "menu" : void 0, "data-key": item.id, "aria-expanded": cascade && item.items ? path?.[depth] === item.id : void 0, onPointerEnter: cascade ? (e) => {
1249
+ if (e.pointerType !== "touch")
1250
+ hover(item, depth);
1251
+ } : void 0, "data-size": item.size ?? "medium", "data-tone": item.tone, disabled: !isEnabled(item), tabIndex: -1, onClick: () => choose(item, depth), children: [item.icon && _jsx11(Icon, { name: item.icon }), path && item.preview && _jsx11(MenuPreview, { children: item.preview }), _jsx11("span", { className: "vx-menu-label", children: item.label }), item.checked && _jsx11(Icon, { name: "check" }), item.items?.length ? _jsx11(Icon, { name: "chevron-right" }) : null] }, item.id)) }, depth));
1252
+ return _jsxs10("div", { className: "vx-action-menu", onBlur: (event) => {
1253
+ if (!event.currentTarget.contains(event.relatedTarget) && !(floating && popup.current?.contains(event.relatedTarget)) && ![...children.current.values()].some((panel) => panel.contains(event.relatedTarget)))
743
1254
  setPath(null);
744
- }, children: [triggerIcon ? _jsx7(IconButton, { ref: trigger, label, icon: triggerIcon, variant: "icon-ghost-sm", "aria-haspopup": "menu", "aria-controls": id, "aria-expanded": path !== null, disabled: !items.some(isEnabled), onClick: () => path ? close() : open(), onKeyDown: triggerKey }) : _jsx7(Button, { ref: trigger, label, variant: "text-tonal-sm", trailingIcon: "chevron-down", "aria-haspopup": "menu", "aria-controls": id, "aria-expanded": path !== null, disabled: !items.some(isEnabled), onClick: () => path ? close() : open(), onKeyDown: triggerKey }), portalRoot ? createPortal2(menu, portalRoot) : menu] });
1255
+ }, children: [triggerIcon ? _jsx11(IconButton, { ref: trigger, label, icon: triggerIcon, variant: "icon-ghost-sm", "aria-haspopup": "menu", "aria-controls": id, "aria-expanded": path !== null, disabled: !items.some(isEnabled), onClick: () => path ? close() : open(), onKeyDown: triggerKey }) : _jsx11(Button, { ref: trigger, label, variant: textTrigger === "plain" ? "text-plain-sm" : "text-tonal-sm", trailingIcon: textTrigger === "dropdown" ? "chevron-down" : void 0, "aria-haspopup": "menu", "aria-controls": id, "aria-expanded": path !== null, disabled: !items.some(isEnabled), onClick: () => path ? close() : open(), onKeyDown: triggerKey }), portalRoot ? createPortal3(menu, portalRoot) : menu] });
1256
+ }
1257
+
1258
+ // packages/ui-system/dist/video-player.js
1259
+ import { jsx as _jsx12, jsxs as _jsxs11, Fragment as _Fragment5 } from "react/jsx-runtime";
1260
+ import { useEffect as useEffect6, useLayoutEffect as useLayoutEffect5, useRef as useRef5, useState as useState7 } from "react";
1261
+
1262
+ // packages/ui-system/dist/fullscreen.js
1263
+ import { useEffect as useEffect5, useState as useState6 } from "react";
1264
+ function isFullscreen(element) {
1265
+ const tree = element.getRootNode();
1266
+ return tree.fullscreenElement === element || element.matches(":fullscreen");
1267
+ }
1268
+ function useFullscreen(target) {
1269
+ const [fullscreen, setFullscreen] = useState6(false);
1270
+ useEffect5(() => {
1271
+ const element = target.current;
1272
+ if (!element)
1273
+ return;
1274
+ const doc = element.ownerDocument;
1275
+ const update = () => setFullscreen(isFullscreen(element));
1276
+ const escape = (event) => {
1277
+ if (event.key !== "Escape" || !isFullscreen(element))
1278
+ return;
1279
+ event.preventDefault();
1280
+ event.stopPropagation();
1281
+ void doc.exitFullscreen().catch(update);
1282
+ };
1283
+ update();
1284
+ doc.addEventListener("fullscreenchange", update);
1285
+ doc.addEventListener("keydown", escape, true);
1286
+ return () => {
1287
+ doc.removeEventListener("fullscreenchange", update);
1288
+ doc.removeEventListener("keydown", escape, true);
1289
+ };
1290
+ }, [target]);
1291
+ async function toggleFullscreen() {
1292
+ const element = target.current;
1293
+ if (!element)
1294
+ return;
1295
+ if (isFullscreen(element))
1296
+ await element.ownerDocument.exitFullscreen();
1297
+ else
1298
+ await element.requestFullscreen();
1299
+ }
1300
+ return { fullscreen, toggleFullscreen };
745
1301
  }
746
1302
 
747
1303
  // packages/ui-system/dist/video-player.js
748
- import { jsx as _jsx8, jsxs as _jsxs6 } from "react/jsx-runtime";
749
- import { useEffect as useEffect2, useRef as useRef3, useState as useState3 } from "react";
750
- function timeLabel2(seconds) {
1304
+ function timeLabel2(seconds, padMinutes = false) {
751
1305
  const whole = Math.floor(seconds);
752
- return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
1306
+ const minutes = String(Math.floor(whole / 60));
1307
+ return `${padMinutes ? minutes.padStart(2, "0") : minutes}:${String(whole % 60).padStart(2, "0")}`;
753
1308
  }
754
- function PlaybackControls({ playing, muted, time, duration, size = "medium", disabled, onTogglePlay, onToggleMute, onSeek, onFullscreen }) {
755
- return _jsxs6("div", { className: "vx-playback-controls", role: "group", "aria-label": "Playback controls", "data-size": size, style: {
756
- "--vx-playback-progress": `${duration > 0 ? Math.min(100, Math.max(0, time / duration * 100)) : 0}%`
757
- }, children: [_jsx8(IconButton, { icon: playing ? size === "large" ? "pause-large" : "pause" : size === "large" ? "playback-play-large" : "playback-play", label: playing ? "Pause" : "Play", disabled, onClick: onTogglePlay }), _jsx8("input", { "aria-label": "Playback position", "aria-valuetext": `${timeLabel2(time)} of ${timeLabel2(duration)}`, type: "range", min: 0, max: duration, value: time, step: "any", disabled: disabled || !duration, onChange: (event) => onSeek(event.currentTarget.valueAsNumber) }), _jsxs6("span", { "aria-hidden": "true", children: [timeLabel2(time), " / ", timeLabel2(duration)] }), _jsx8(IconButton, { icon: muted ? size === "large" ? "mute-large" : "mute" : size === "large" ? "volume-large" : "volume", label: muted ? "Unmute" : "Mute", disabled, onClick: onToggleMute }), onFullscreen && _jsx8(IconButton, { icon: size === "large" ? "fullscreen-large" : "fullscreen", label: "Toggle fullscreen", onClick: onFullscreen })] });
1309
+ function PlaybackControls({ playing, muted, time, duration, size = "medium", variant = "default", iconSet, singleVideo = false, disabled, onTogglePlay, onToggleMute, onSeek, onFullscreen, fullscreen = false, fullscreenLabel = fullscreen ? "Exit fullscreen" : "Enter fullscreen", actions, appearance = "on-content", timeDisplay = "combined", renderTimeline }) {
1310
+ const resolvedIconSet = iconSet ?? (variant === "chat" ? "chat" : "workbench");
1311
+ const slider = _jsx12("input", { className: "vx-playback-range", "aria-label": "Playback position", "aria-valuetext": `${timeLabel2(time)} of ${timeLabel2(duration)}`, type: "range", min: 0, max: duration, value: time, step: "any", disabled: disabled || !duration, onChange: (event) => onSeek(event.currentTarget.valueAsNumber) });
1312
+ return _jsxs11("div", { className: "vx-playback-controls", role: "group", "aria-label": "Playback controls", "data-size": size, "data-variant": variant === "chat" ? "chat" : void 0, "data-icon-set": resolvedIconSet === "chat" ? "chat" : void 0, "data-single-video": singleVideo || void 0, "data-appearance": appearance, "data-time-display": timeDisplay, style: {
1313
+ "--vx-playback-fraction": duration > 0 ? Math.min(1, Math.max(0, time / duration)) : 0
1314
+ }, children: [_jsx12(IconButton, { variant: size === "small" ? "icon-bare-xs" : "icon-ghost-sm", icon: playing ? size === "large" ? "pause-large" : "pause" : size === "large" ? "playback-play-large" : "playback-play", label: playing ? "Pause" : "Play", disabled, onClick: onTogglePlay }), timeDisplay === "split" && _jsx12("span", { "aria-hidden": "true", "data-time": "elapsed", children: timeLabel2(time, true) }), renderTimeline ? renderTimeline(slider) : slider, _jsx12("span", { "aria-hidden": "true", "data-time": timeDisplay === "split" ? "duration" : void 0, children: timeDisplay === "split" ? timeLabel2(duration, true) : `${timeLabel2(time)} / ${timeLabel2(duration)}` }), _jsx12(IconButton, { variant: size === "small" ? "icon-bare-xs" : "icon-ghost-sm", icon: muted ? size === "large" ? "mute-large" : "mute" : size === "large" ? "volume-large" : "volume", label: muted ? "Unmute" : "Mute", disabled, onClick: onToggleMute }), actions, onFullscreen && _jsx12(IconButton, { variant: size === "small" ? "icon-bare-xs" : "icon-ghost-sm", icon: fullscreen ? "fullscreen-exit" : size === "large" ? "fullscreen-large" : "fullscreen", label: fullscreenLabel, "aria-pressed": fullscreen, onClick: onFullscreen })] });
758
1315
  }
759
1316
  function VideoPlayer(props) {
760
- return _jsx8(Playback, { ...props }, JSON.stringify([props.src, props.poster, props.posterDuration]));
1317
+ return _jsx12(Playback, { ...props }, JSON.stringify([props.src, props.poster, props.posterDuration]));
761
1318
  }
762
- function Playback({ src, poster, posterDuration = 0, title, version, durationLabel, sceneLabel, defaultMuted = false, controlsPlacement = "overlay", controlsSize, showFullscreen = true, overlay, onBeforePlay, onStateChange, onTimeChange, onEnded, onError }) {
763
- const root = useRef3(null);
764
- const video = useRef3(null);
765
- const position = useRef3(0);
766
- const callbacks = useRef3({ onTimeChange, onStateChange, onEnded });
767
- const [time, setTime] = useState3(0);
768
- const [metadataDuration, setMetadataDuration] = useState3(0);
769
- const [state, setState] = useState3("cover");
770
- const [muted, setMuted] = useState3(defaultMuted);
771
- const stillDuration = poster && Number.isFinite(posterDuration) ? Math.max(0, posterDuration) : 0;
772
- const duration = src ? metadataDuration : stillDuration;
773
- useEffect2(() => {
1319
+ function Playback({ src, poster, aspectRatio, stageAspectRatio, posterDuration = 0, title, version, durationLabel, sceneLabel, defaultMuted = false, controlsPlacement = "overlay", fitContent = false, fillContainer = false, compactCover = false, showCoverInfo = true, showCoverPlay = true, fitExpandedContent = false, fillExpandedFrame = false, controlsSize, controlsVariant, iconSet, controlsAppearance, timeDisplay, controlsActions, showFullscreen = true, fullscreenMode = "native", overlay, deferred = false, onActivate, containerRef, onBeforePlay, onStateChange, onTimeChange, onAspectRatio, onEnded, onError }) {
1320
+ const root = useRef5(null);
1321
+ const expandedPlaceholder = useRef5(null);
1322
+ const video = useRef5(null);
1323
+ const nativeFullscreen = useFullscreen(root);
1324
+ const playbackEpoch = useRef5(0);
1325
+ const localDialog = useInlineDialog(root);
1326
+ const frameExpansion = fillExpandedFrame && !fitExpandedContent;
1327
+ const inlineDialog = fullscreenMode === "dialog" && (frameExpansion || localDialog);
1328
+ const position = useRef5(0);
1329
+ const callbacks = useRef5({ onTimeChange, onStateChange, onEnded });
1330
+ const [time, setTime] = useState7(0);
1331
+ const [ratio, setRatio] = useState7();
1332
+ const [metadataDuration, setMetadataDuration] = useState7(0);
1333
+ const [state, setState] = useState7("cover");
1334
+ const [muted, setMuted] = useState7(defaultMuted);
1335
+ const [expanded, setExpanded] = useState7(false);
1336
+ const [inlineHeight, setInlineHeight] = useState7();
1337
+ const restoreFocus = useRef5(false);
1338
+ useEffect6(() => {
1339
+ if (!expanded && restoreFocus.current) {
1340
+ restoreFocus.current = false;
1341
+ root.current?.querySelector('button[aria-label="Expand video"]')?.focus();
1342
+ }
1343
+ }, [expanded]);
1344
+ const restore = useRef5(void 0);
1345
+ const wasDeferred = useRef5(deferred);
1346
+ if (deferred)
1347
+ wasDeferred.current = true;
1348
+ const mountVideo = Boolean(src) && !deferred;
1349
+ const fallbackDuration = Number.isFinite(posterDuration) ? Math.max(0, posterDuration) : 0;
1350
+ const stillDuration = poster ? fallbackDuration : 0;
1351
+ const duration = src ? metadataDuration || (deferred || wasDeferred.current ? fallbackDuration : 0) : stillDuration;
1352
+ const displayRatio = stageAspectRatio ?? ratio ?? aspectRatio ?? 16 / 9;
1353
+ const dialogLayout = fitExpandedContent ? " vx-video-dialog-fit" : frameExpansion ? " vx-video-dialog-frame" : "";
1354
+ useLayoutEffect5(() => {
1355
+ const view = root.current?.ownerDocument.defaultView;
1356
+ if (expanded && frameExpansion && inlineDialog && view && view !== view.top)
1357
+ expandedPlaceholder.current?.scrollIntoView({ block: "start", inline: "nearest" });
1358
+ }, [expanded, frameExpansion, inlineDialog]);
1359
+ function setRootRef(node) {
1360
+ root.current = node;
1361
+ if (typeof containerRef === "function")
1362
+ containerRef(node);
1363
+ else if (containerRef)
1364
+ containerRef.current = node;
1365
+ }
1366
+ useEffect6(() => {
774
1367
  const element = video.current;
775
1368
  return () => {
776
1369
  if (!element)
@@ -779,7 +1372,7 @@ function Playback({ src, poster, posterDuration = 0, title, version, durationLab
779
1372
  element.removeAttribute("src");
780
1373
  element.load();
781
1374
  };
782
- }, []);
1375
+ }, [inlineDialog ? false : expanded, src, inlineDialog, mountVideo]);
783
1376
  function updateTime(next) {
784
1377
  position.current = next;
785
1378
  setTime(next);
@@ -789,10 +1382,10 @@ function Playback({ src, poster, posterDuration = 0, title, version, durationLab
789
1382
  setState(next);
790
1383
  onStateChange?.(next);
791
1384
  }
792
- useEffect2(() => {
1385
+ useEffect6(() => {
793
1386
  callbacks.current = { onTimeChange, onStateChange, onEnded };
794
1387
  }, [onTimeChange, onStateChange, onEnded]);
795
- useEffect2(() => {
1388
+ useEffect6(() => {
796
1389
  if (src || state !== "playing" || !duration)
797
1390
  return;
798
1391
  let previous = performance.now();
@@ -813,9 +1406,21 @@ function Playback({ src, poster, posterDuration = 0, title, version, durationLab
813
1406
  }
814
1407
  return () => cancelAnimationFrame(frame);
815
1408
  }, [src, state, duration]);
1409
+ function requestPlay(element, onRejected) {
1410
+ const epoch = playbackEpoch.current;
1411
+ void element.play().catch((error) => {
1412
+ if (epoch === playbackEpoch.current && video.current === element && element.isConnected)
1413
+ onRejected(error);
1414
+ });
1415
+ }
1416
+ function isAwaitingDeferredMetadata() {
1417
+ return !mountVideo && Boolean(src) || Boolean(wasDeferred.current && video.current && !video.current.error && video.current.readyState < 1);
1418
+ }
816
1419
  function togglePlay() {
1420
+ playbackEpoch.current++;
817
1421
  if (state === "playing") {
818
- if (video.current)
1422
+ restore.current = void 0;
1423
+ if (video.current && !video.current.paused)
819
1424
  video.current.pause();
820
1425
  else
821
1426
  changeState("paused");
@@ -823,8 +1428,18 @@ function Playback({ src, poster, posterDuration = 0, title, version, durationLab
823
1428
  }
824
1429
  if (onBeforePlay?.() === false)
825
1430
  return;
1431
+ if (isAwaitingDeferredMetadata()) {
1432
+ const nextTime = !mountVideo && duration && position.current >= duration ? 0 : restore.current?.time ?? position.current;
1433
+ if (nextTime !== position.current)
1434
+ updateTime(nextTime);
1435
+ restore.current = { time: nextTime, playing: true, state: "playing", reportError: true };
1436
+ changeState("playing");
1437
+ if (!mountVideo)
1438
+ onActivate?.();
1439
+ return;
1440
+ }
826
1441
  if (video.current)
827
- void video.current.play().catch((error) => onError?.(error));
1442
+ requestPlay(video.current, (error) => onError?.(error));
828
1443
  else if (duration) {
829
1444
  if (position.current >= duration)
830
1445
  updateTime(0);
@@ -832,31 +1447,113 @@ function Playback({ src, poster, posterDuration = 0, title, version, durationLab
832
1447
  }
833
1448
  }
834
1449
  function seek(seconds) {
1450
+ if (isAwaitingDeferredMetadata()) {
1451
+ updateTime(seconds);
1452
+ restore.current = {
1453
+ time: seconds,
1454
+ playing: restore.current?.playing ?? state === "playing",
1455
+ state,
1456
+ reportError: restore.current?.reportError
1457
+ };
1458
+ if (!mountVideo)
1459
+ onActivate?.();
1460
+ return;
1461
+ }
835
1462
  if (video.current)
836
1463
  video.current.currentTime = seconds;
837
1464
  else
838
1465
  updateTime(seconds);
839
1466
  }
840
1467
  async function toggleFullscreen() {
1468
+ if (!mountVideo && src)
1469
+ onActivate?.();
1470
+ if (fullscreenMode === "dialog") {
1471
+ changeExpanded(!expanded);
1472
+ return;
1473
+ }
841
1474
  try {
842
- const player = root.current;
843
- if (!player?.requestFullscreen)
844
- return;
845
- if (player.ownerDocument.fullscreenElement === player)
846
- await player.ownerDocument.exitFullscreen();
847
- else
848
- await player.requestFullscreen();
1475
+ await nativeFullscreen.toggleFullscreen();
849
1476
  } catch (error) {
850
1477
  onError?.(error);
851
1478
  }
852
1479
  }
853
- return _jsxs6("section", { ref: root, className: "vx-video-player", "aria-label": title, "data-placement": controlsPlacement, "data-state": state, children: [_jsxs6("div", { className: "vx-video-stage", children: [src ? _jsx8("video", { ref: video, src, poster, muted, playsInline: true, preload: "metadata", onDurationChange: (event) => {
1480
+ function changeExpanded(next) {
1481
+ if (next) {
1482
+ const player2 = root.current;
1483
+ const height = player2?.getBoundingClientRect().height;
1484
+ const view = player2?.ownerDocument.defaultView;
1485
+ if (frameExpansion && inlineDialog && view && view !== view.top && height !== void 0) {
1486
+ const maxFrameHeight = Math.min(view.innerHeight, view.screen.availHeight || view.innerHeight);
1487
+ const otherContentHeight = Math.max(0, view.innerHeight - height);
1488
+ setInlineHeight(Math.max(1, maxFrameHeight - otherContentHeight));
1489
+ } else
1490
+ setInlineHeight(height);
1491
+ } else
1492
+ restoreFocus.current = true;
1493
+ if (inlineDialog) {
1494
+ setExpanded(next);
1495
+ return;
1496
+ }
1497
+ playbackEpoch.current++;
1498
+ const element = video.current;
1499
+ restore.current = {
1500
+ time: element && element.readyState >= 1 ? element.currentTime : restore.current?.time ?? position.current,
1501
+ playing: element && element.readyState >= 1 ? !element.paused : restore.current?.playing ?? state === "playing",
1502
+ state,
1503
+ reportError: restore.current?.reportError
1504
+ };
1505
+ element?.pause();
1506
+ setExpanded(next);
1507
+ }
1508
+ const fitted = fitContent || expanded && fitExpandedContent;
1509
+ function readAspectRatio({ videoWidth, videoHeight }) {
1510
+ if (!videoWidth || !videoHeight)
1511
+ return;
1512
+ const next = videoWidth / videoHeight;
1513
+ setRatio(next);
1514
+ onAspectRatio?.(next);
1515
+ }
1516
+ const player = _jsxs11("section", { ref: setRootRef, className: "vx-video-player", "aria-label": title, "data-fit": fitted ? "content" : void 0, "data-frame-expansion": frameExpansion || void 0, "data-fill-container": fillContainer || void 0, "data-compact-cover": compactCover || void 0, style: { "--vx-video-ratio": displayRatio }, "data-placement": controlsPlacement, "data-controls-size": controlsSize, "data-state": state, children: [_jsxs11("div", { className: "vx-video-stage", children: [mountVideo ? _jsx12("video", { ref: video, src, poster, muted, playsInline: true, preload: "metadata", onResize: (event) => readAspectRatio(event.currentTarget), onLoadedMetadata: (event) => {
1517
+ const element = event.currentTarget;
1518
+ readAspectRatio(element);
1519
+ const previous = restore.current;
1520
+ if (!previous)
1521
+ return;
1522
+ element.currentTime = Math.min(previous.time, element.duration);
1523
+ updateTime(element.currentTime);
1524
+ restore.current = void 0;
1525
+ if (previous.playing)
1526
+ requestPlay(element, (error) => {
1527
+ changeState("paused");
1528
+ if (previous.reportError)
1529
+ onError?.(error);
1530
+ });
1531
+ else
1532
+ changeState(previous.state);
1533
+ }, onDurationChange: (event) => {
854
1534
  const value = event.currentTarget.duration;
855
1535
  setMetadataDuration(Number.isFinite(value) ? value : 0);
856
1536
  }, onPlay: () => changeState("playing"), onPause: (event) => {
1537
+ if (restore.current)
1538
+ return;
857
1539
  updateTime(event.currentTarget.currentTime);
858
1540
  changeState("paused");
859
- }, onTimeUpdate: (event) => updateTime(event.currentTarget.currentTime), onEnded, onError: (event) => onError?.(event.currentTarget.error) }) : poster && _jsx8("img", { src: poster, alt: "" }), overlay, state === "cover" && _jsxs6("div", { className: "vx-video-cover", children: [_jsxs6("div", { className: "vx-video-info", children: [_jsxs6("div", { className: "vx-video-title", children: [_jsx8("strong", { title, children: title }), version && _jsx8(Tag, { children: version })] }), (durationLabel || sceneLabel) && _jsxs6("div", { className: "vx-video-meta", children: [durationLabel && _jsx8("span", { children: durationLabel }), durationLabel && sceneLabel && _jsx8("span", { "aria-hidden": "true", children: "\xB7" }), sceneLabel && _jsx8("span", { children: sceneLabel })] })] }), (src || duration > 0) && _jsx8(IconButton, { icon: "play-cover", className: "vx-video-start", label: `Play ${title}`, variant: "icon-circle-lg", onClick: togglePlay })] })] }), _jsx8(PlaybackControls, { playing: state === "playing", muted, time: Math.min(time, duration), duration, disabled: !src && !duration, size: controlsSize, onTogglePlay: togglePlay, onToggleMute: () => setMuted(!muted), onSeek: seek, onFullscreen: showFullscreen ? () => void toggleFullscreen() : void 0 })] });
1541
+ }, onTimeUpdate: (event) => {
1542
+ if (!restore.current)
1543
+ updateTime(event.currentTarget.currentTime);
1544
+ }, onEnded, onError: (event) => {
1545
+ restore.current = void 0;
1546
+ if (state === "playing")
1547
+ changeState("paused");
1548
+ if (event.currentTarget.error)
1549
+ onError?.(event.currentTarget.error);
1550
+ } }) : poster && _jsx12("img", { src: poster, alt: "" }), overlay, state === "cover" && !fitted && _jsxs11("div", { className: "vx-video-cover", "data-plain": !showCoverInfo || void 0, children: [showCoverInfo && _jsxs11("div", { className: "vx-video-info", children: [_jsxs11("div", { className: "vx-video-title", children: [_jsx12("strong", { title, children: title }), version && _jsx12(Tag, { children: version })] }), (durationLabel || sceneLabel) && _jsxs11("div", { className: "vx-video-meta", children: [durationLabel && _jsx12("span", { children: durationLabel }), durationLabel && sceneLabel && _jsx12("span", { "aria-hidden": "true", children: "\xB7" }), sceneLabel && _jsx12("span", { children: sceneLabel })] })] }), showCoverPlay && (src || duration > 0) && _jsx12(IconButton, { icon: "play-cover", className: "vx-video-start", label: `Play ${title}`, variant: "icon-circle-lg", onClick: togglePlay })] })] }), _jsx12(PlaybackControls, { fullscreen: fullscreenMode === "dialog" ? expanded : nativeFullscreen.fullscreen, playing: state === "playing", muted, time: Math.min(time, duration), duration, disabled: !src && !duration, size: controlsSize, variant: controlsVariant, iconSet, appearance: controlsAppearance, timeDisplay, actions: controlsActions, onTogglePlay: togglePlay, onToggleMute: () => setMuted(!muted), onSeek: seek, onFullscreen: showFullscreen && !(expanded && (fitExpandedContent || frameExpansion)) ? () => void toggleFullscreen() : void 0, fullscreenLabel: fullscreenMode === "dialog" ? expanded ? "Close expanded video" : "Expand video" : void 0 })] });
1551
+ return _jsxs11(_Fragment5, { children: [expanded ? _jsx12("div", { ref: expandedPlaceholder, "aria-hidden": "true", style: { height: inlineHeight } }) : !inlineDialog && player, _jsx12(Dialog, { title, open: expanded, onOpenChange: changeExpanded, className: `vx-video-dialog${dialogLayout}`, inlineWhenClosed: inlineDialog, children: (expanded || inlineDialog) && player })] });
1552
+ }
1553
+
1554
+ // packages/ui-system/dist/duration.js
1555
+ function formatDurationSeconds(durationMs) {
1556
+ return (Math.round(durationMs / 100) / 10).toFixed(1).replace(/\.0$/, "");
860
1557
  }
861
1558
 
862
1559
  // packages/media-tools/src/ui/recipe-player.tsx
@@ -869,6 +1566,7 @@ function RecipePlayer({
869
1566
  children
870
1567
  }) {
871
1568
  const root = React2.useRef(null);
1569
+ const fullscreenState = useFullscreen(root);
872
1570
  const media = React2.useRef(null);
873
1571
  const fit = React2.useRef(null);
874
1572
  const [box, setBox] = React2.useState({ width: 640, height: 360 });
@@ -876,11 +1574,20 @@ function RecipePlayer({
876
1574
  const [muted, setMuted] = React2.useState(false);
877
1575
  const [time, setTime] = React2.useState(recipe2.trim.inMs / 1e3);
878
1576
  const [error, setError] = React2.useState("");
1577
+ const speed = recipe2.speed ?? 1;
1578
+ const color = recipe2.color;
879
1579
  const bounds = React2.useRef(recipe2.trim);
1580
+ const previousTrim = React2.useRef(recipe2.trim);
880
1581
  bounds.current = recipe2.trim;
881
1582
  const crop = editingCrop ? { x: 0, y: 0, width: 1, height: 1 } : recipe2.crop;
882
1583
  const aspect = video.displayWidth * crop.width / (video.displayHeight * crop.height);
883
1584
  const width = Math.max(1, Math.min(box.width, box.height * aspect));
1585
+ React2.useEffect(() => {
1586
+ if (media.current) {
1587
+ media.current.playbackRate = speed;
1588
+ media.current.preservesPitch = true;
1589
+ }
1590
+ }, [speed, video.previewUrl]);
884
1591
  React2.useEffect(() => {
885
1592
  const element = fit.current;
886
1593
  if (!element) return;
@@ -918,11 +1625,16 @@ function RecipePlayer({
918
1625
  }, [video.previewUrl, playing]);
919
1626
  React2.useEffect(() => {
920
1627
  const element = media.current;
1628
+ const previous = previousTrim.current;
1629
+ previousTrim.current = recipe2.trim;
921
1630
  if (element && Number.isFinite(element.duration)) {
1631
+ const changed = previous.inMs !== recipe2.trim.inMs || previous.outMs !== recipe2.trim.outMs;
1632
+ const previewTime = previous.inMs !== recipe2.trim.inMs ? recipe2.trim.inMs / 1e3 : previous.outMs !== recipe2.trim.outMs ? (recipe2.trim.outMs - 1) / 1e3 : element.currentTime;
922
1633
  const clamped = Math.max(
923
1634
  recipe2.trim.inMs / 1e3,
924
- Math.min((recipe2.trim.outMs - 1) / 1e3, element.currentTime)
1635
+ Math.min((recipe2.trim.outMs - 1) / 1e3, previewTime)
925
1636
  );
1637
+ if (changed) element.pause();
926
1638
  if (element.currentTime !== clamped) element.currentTime = clamped;
927
1639
  setTime(clamped);
928
1640
  }
@@ -932,13 +1644,12 @@ function RecipePlayer({
932
1644
  if (element)
933
1645
  element.currentTime = Math.max(
934
1646
  recipe2.trim.inMs,
935
- Math.min(recipe2.trim.outMs - 1, recipe2.trim.inMs + seconds * 1e3)
1647
+ Math.min(recipe2.trim.outMs - 1, recipe2.trim.inMs + seconds * 1e3 * speed)
936
1648
  ) / 1e3;
937
1649
  };
938
1650
  async function fullscreen() {
939
1651
  try {
940
- if (document.fullscreenElement === root.current) await document.exitFullscreen();
941
- else await root.current?.requestFullscreen();
1652
+ await fullscreenState.toggleFullscreen();
942
1653
  } catch (failure) {
943
1654
  setError(readableError(failure));
944
1655
  }
@@ -964,10 +1675,13 @@ function RecipePlayer({
964
1675
  width: `${100 / crop.width}%`,
965
1676
  height: `${100 / crop.height}%`,
966
1677
  left: `${-crop.x * 100 / crop.width}%`,
967
- top: `${-crop.y * 100 / crop.height}%`
1678
+ top: `${-crop.y * 100 / crop.height}%`,
1679
+ filter: color ? `brightness(${1 + color.brightness}) contrast(${color.contrast}) saturate(${color.saturation})` : void 0
968
1680
  },
969
1681
  onLoadedMetadata: (event) => {
970
1682
  event.currentTarget.currentTime = bounds.current.inMs / 1e3;
1683
+ event.currentTarget.playbackRate = speed;
1684
+ event.currentTarget.preservesPitch = true;
971
1685
  setTime(bounds.current.inMs / 1e3);
972
1686
  },
973
1687
  onSeeking: (event) => {
@@ -988,10 +1702,11 @@ function RecipePlayer({
988
1702
  /* @__PURE__ */ React2.createElement(
989
1703
  PlaybackControls,
990
1704
  {
1705
+ fullscreen: fullscreenState.fullscreen,
991
1706
  playing,
992
1707
  muted,
993
- time: Math.max(0, time - recipe2.trim.inMs / 1e3),
994
- duration: (recipe2.trim.outMs - recipe2.trim.inMs) / 1e3,
1708
+ time: Math.max(0, (time - recipe2.trim.inMs / 1e3) / speed),
1709
+ duration: recipeDurationMs(recipe2) / 1e3,
995
1710
  onSeek: seek,
996
1711
  onToggleMute: () => setMuted(!muted),
997
1712
  onFullscreen: () => void fullscreen(),
@@ -1250,6 +1965,23 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1250
1965
  const [ratio, setRatio] = React4.useState("Freeform");
1251
1966
  const [error, setError] = React4.useState("");
1252
1967
  const [saving, setSaving] = React4.useState(false);
1968
+ const focusCancel = React4.useCallback((button) => {
1969
+ if (!button) return;
1970
+ let opener;
1971
+ queueMicrotask(() => {
1972
+ const frame = button.ownerDocument.activeElement;
1973
+ if (button.closest("dialog")?.open && frame?.tagName === "IFRAME") {
1974
+ opener = frame.contentDocument?.activeElement;
1975
+ button.focus({ preventScroll: true });
1976
+ }
1977
+ });
1978
+ return () => {
1979
+ const target = opener;
1980
+ target?.ownerDocument.defaultView?.requestAnimationFrame(() => {
1981
+ if (target.isConnected) target.focus({ preventScroll: true });
1982
+ });
1983
+ };
1984
+ }, []);
1253
1985
  const [reload, setReload] = React4.useState(0);
1254
1986
  const generation = React4.useRef(0);
1255
1987
  const edit = React4.useRef(null);
@@ -1359,7 +2091,7 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1359
2091
  /* @__PURE__ */ React4.createElement(
1360
2092
  Dialog,
1361
2093
  {
1362
- title: mode === "crop" ? "Crop Video" : "Trim Video",
2094
+ title: videoEditorTitles[mode],
1363
2095
  open: true,
1364
2096
  onOpenChange: (open) => {
1365
2097
  if (!open && !saving) onClose();
@@ -1377,12 +2109,16 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1377
2109
  if (mode === "crop") {
1378
2110
  setRatio("Original");
1379
2111
  change({ ...draft, crop: { x: 0, y: 0, width: 1, height: 1 } });
1380
- } else change({ ...draft, trim: { inMs: 0, outMs: video.durationMs } });
2112
+ } else if (mode === "trim")
2113
+ change({ ...draft, trim: { inMs: 0, outMs: video.durationMs } });
2114
+ else if (mode === "color") change({ ...draft, color: { ...neutralColor } });
2115
+ else change({ ...draft, speed: 1 });
1381
2116
  }
1382
2117
  }
1383
2118
  ), /* @__PURE__ */ React4.createElement("div", { className: "mt-editor-confirm" }, /* @__PURE__ */ React4.createElement(
1384
2119
  Button,
1385
2120
  {
2121
+ ref: focusCancel,
1386
2122
  label: "Cancel",
1387
2123
  variant: "text-tonal-md",
1388
2124
  width: "hug",
@@ -1401,7 +2137,7 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1401
2137
  }
1402
2138
  )))
1403
2139
  },
1404
- video && draft ? /* @__PURE__ */ React4.createElement("div", { inert: saving, "aria-busy": saving }, /* @__PURE__ */ React4.createElement("p", { className: "mt-subtitle" }, video.name, " \xB7 v", video.versionNumber), video.colorInterpretation === "assumed-bt709" && /* @__PURE__ */ React4.createElement("p", { className: "mt-subtitle" }, "Color information is missing. Standard SDR colors are assumed; export may differ slightly."), /* @__PURE__ */ React4.createElement(
2140
+ video && draft ? /* @__PURE__ */ React4.createElement("div", { className: "mt-editor-content", inert: saving, "aria-busy": saving }, /* @__PURE__ */ React4.createElement(
1405
2141
  RecipePlayer,
1406
2142
  {
1407
2143
  video,
@@ -1434,27 +2170,7 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1434
2170
  }
1435
2171
  })
1436
2172
  }
1437
- ), filmstrip?.error && /* @__PURE__ */ React4.createElement("p", { className: "mt-help", role: "status" }, filmstrip.error), /* @__PURE__ */ React4.createElement("details", { className: "mt-precision" }, /* @__PURE__ */ React4.createElement("summary", null, "Precise timing"), /* @__PURE__ */ React4.createElement("div", { className: "mt-fields" }, ["inMs", "outMs"].map((edge) => /* @__PURE__ */ React4.createElement("label", { key: edge }, edge === "inMs" ? "In (seconds)" : "Out (seconds)", /* @__PURE__ */ React4.createElement(
1438
- "input",
1439
- {
1440
- type: "number",
1441
- min: "0",
1442
- max: video.durationMs / 1e3,
1443
- step: "0.001",
1444
- value: draft.trim[edge] / 1e3,
1445
- disabled: saving,
1446
- onChange: (event) => {
1447
- if (Number.isFinite(event.currentTarget.valueAsNumber))
1448
- change({
1449
- ...draft,
1450
- trim: {
1451
- ...draft.trim,
1452
- [edge]: Math.round(event.currentTarget.valueAsNumber * 1e3)
1453
- }
1454
- });
1455
- }
1456
- }
1457
- )))))) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("div", { className: "mt-editor-hint" }, /* @__PURE__ */ React4.createElement("span", null, "Drag the frame to move. Drag a corner to resize."), /* @__PURE__ */ React4.createElement("span", { role: "status" }, rect?.width, " \xD7 ", rect?.height)), /* @__PURE__ */ React4.createElement(
2173
+ ), filmstrip?.error && /* @__PURE__ */ React4.createElement("p", { className: "mt-help", role: "status" }, filmstrip.error)) : mode === "crop" ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("div", { className: "mt-editor-hint" }, /* @__PURE__ */ React4.createElement("span", null, "Drag the frame to move. Drag a corner to resize."), /* @__PURE__ */ React4.createElement("span", { role: "status" }, rect?.width, " \xD7 ", rect?.height)), /* @__PURE__ */ React4.createElement(
1458
2174
  SegmentedControl,
1459
2175
  {
1460
2176
  label: "Aspect ratio",
@@ -1464,7 +2180,46 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1464
2180
  size: "large",
1465
2181
  width: "full"
1466
2182
  }
1467
- ))) : !error && /* @__PURE__ */ React4.createElement("p", { role: "status" }, "Loading fixed video\u2026"),
2183
+ )) : mode === "color" ? /* @__PURE__ */ React4.createElement("div", { className: "mt-adjustments" }, ["brightness", "contrast", "saturation"].map((key) => /* @__PURE__ */ React4.createElement(
2184
+ Slider,
2185
+ {
2186
+ key,
2187
+ label: { brightness: "Brightness", contrast: "Contrast", saturation: "Saturation" }[key],
2188
+ min: key === "brightness" ? -50 : 0,
2189
+ max: key === "brightness" ? 50 : 200,
2190
+ step: 1,
2191
+ unit: "%",
2192
+ value: Math.round((draft.color ?? neutralColor)[key] * 100),
2193
+ onValueChange: (value) => change({
2194
+ ...draft,
2195
+ color: { ...draft.color ?? neutralColor, [key]: value / 100 }
2196
+ })
2197
+ }
2198
+ )), /* @__PURE__ */ React4.createElement("p", { className: "mt-help" }, "Live preview is approximate. Apply renders the final colors.")) : /* @__PURE__ */ React4.createElement("div", { className: "mt-adjustments" }, /* @__PURE__ */ React4.createElement(
2199
+ Slider,
2200
+ {
2201
+ label: "Playback speed",
2202
+ min: 0.25,
2203
+ max: 4,
2204
+ step: 0.05,
2205
+ unit: "\xD7",
2206
+ value: draft.speed ?? 1,
2207
+ onValueChange: (speed) => change({ ...draft, speed: Math.round(speed * 100) / 100 })
2208
+ }
2209
+ ), /* @__PURE__ */ React4.createElement(
2210
+ SegmentedControl,
2211
+ {
2212
+ label: "Speed presets",
2213
+ size: "large",
2214
+ width: "full",
2215
+ items: [0.25, 0.5, 1, 1.5, 2, 4].map((speed) => ({
2216
+ value: String(speed),
2217
+ label: `${speed}\xD7`
2218
+ })),
2219
+ value: String(draft.speed ?? 1),
2220
+ onValueChange: (speed) => change({ ...draft, speed: Number(speed) })
2221
+ }
2222
+ ), /* @__PURE__ */ React4.createElement("p", { className: "mt-editor-hint", role: "status" }, /* @__PURE__ */ React4.createElement("span", null, ((draft.trim.outMs - draft.trim.inMs) / 1e3).toFixed(2), "s \u2192", " ", (recipeDurationMs(draft) / 1e3).toFixed(2), "s"), /* @__PURE__ */ React4.createElement("span", null, "Keep original pitch"))), video.colorInterpretation === "assumed-bt709" && /* @__PURE__ */ React4.createElement("p", { className: "mt-help", role: "status" }, "Color information is missing. Standard SDR colors are assumed; export may differ slightly.")) : !error && /* @__PURE__ */ React4.createElement("p", { role: "status" }, "Loading fixed video\u2026"),
1468
2223
  error && /* @__PURE__ */ React4.createElement("div", { role: "alert", className: "mt-error" }, error, !video && /* @__PURE__ */ React4.createElement(
1469
2224
  Button,
1470
2225
  {
@@ -1477,8 +2232,473 @@ function VideoEditor({ input, mode, onApply, onClose }) {
1477
2232
  );
1478
2233
  }
1479
2234
 
1480
- // packages/media-tools/src/ui/compare.tsx
2235
+ // packages/media-tools/src/ui/export-dialog.tsx
1481
2236
  import * as React5 from "react";
2237
+ import { useEffect as useEffect10, useRef as useRef8, useState as useState11 } from "react";
2238
+ var defaultSettings = {
2239
+ format: "h264",
2240
+ aspect: "source",
2241
+ resolution: "source",
2242
+ frameRate: "source",
2243
+ quality: "high",
2244
+ audio: true
2245
+ };
2246
+ var terminal = /* @__PURE__ */ new Set(["succeeded", "failed", "canceled", "interrupted"]);
2247
+ var exportNotices = {
2248
+ failed: "Export failed. Try again.",
2249
+ interrupted: "Export stopped because Studio was closed. Try again.",
2250
+ canceled: "Export canceled."
2251
+ };
2252
+ var idleTracking = { jobId: void 0, downloadPending: false, pending: void 0 };
2253
+ function VideoExport({
2254
+ title,
2255
+ preview,
2256
+ canvas: canvas2,
2257
+ issue,
2258
+ legacyTracking,
2259
+ prepare,
2260
+ resolveDownload,
2261
+ onClose
2262
+ }) {
2263
+ const { client, instanceId } = useMediaClient();
2264
+ const storageKey = `studio-video-export:${client.project.id}:${instanceId}`;
2265
+ const [tracking, setTracking] = useState11(() => {
2266
+ try {
2267
+ const raw = localStorage.getItem(storageKey);
2268
+ const stored = raw ? JSON.parse(raw) : legacyTracking;
2269
+ const parsed = mediaRequest.safeParse(stored?.pending?.request);
2270
+ return {
2271
+ jobId: typeof stored?.jobId === "string" && stored.downloadPending !== false ? stored.jobId : void 0,
2272
+ downloadPending: stored?.downloadPending === true,
2273
+ pending: typeof stored?.pending?.key === "string" && parsed.success ? { key: stored.pending.key, request: parsed.data } : void 0,
2274
+ recoverIntent: raw ? void 0 : legacyTracking?.recoverIntent
2275
+ };
2276
+ } catch {
2277
+ return {
2278
+ jobId: void 0,
2279
+ downloadPending: false,
2280
+ pending: void 0,
2281
+ recoverIntent: void 0
2282
+ };
2283
+ }
2284
+ });
2285
+ const [name, setName] = useState11(title.slice(0, 196));
2286
+ const [settings, setSettings] = useState11(defaultSettings);
2287
+ const [preparedCanvas, setPreparedCanvas] = useState11();
2288
+ const [formats, setFormats] = useState11(["h264"]);
2289
+ const [checking, setChecking] = useState11(!issue);
2290
+ const prepareRef = useRef8(prepare);
2291
+ prepareRef.current = prepare;
2292
+ const source = canvas2 ?? preparedCanvas;
2293
+ const dimensions = source && exportDimensions(source, settings.aspect, settings.resolution);
2294
+ const invalidSize = dimensions === null;
2295
+ const [job, setJob] = useState11();
2296
+ const [error, setError] = useState11("");
2297
+ const [pollError, setPollError] = useState11("");
2298
+ const [notice, showNotice] = useToastMessage();
2299
+ const notifiedFailure = useRef8(void 0);
2300
+ const [busy, setBusy] = useState11(false);
2301
+ const lock = useRef8(false);
2302
+ const { jobId, downloadPending, pending, recoverIntent } = tracking;
2303
+ const unresolved = Boolean(pending || recoverIntent);
2304
+ const active = Boolean(jobId && (!job || !terminal.has(job.state)));
2305
+ const completed = !unresolved && job?.state === "succeeded" && (!jobId || job.jobId === jobId);
2306
+ const settingsLocked = busy || active || unresolved || completed && downloadPending;
2307
+ useEffect10(() => setName(title.slice(0, 196)), [title]);
2308
+ useEffect10(() => {
2309
+ if (issue) {
2310
+ setChecking(false);
2311
+ return;
2312
+ }
2313
+ let live = true;
2314
+ setChecking(true);
2315
+ void (async () => {
2316
+ try {
2317
+ if (!canvas2) {
2318
+ try {
2319
+ const input = await prepareRef.current();
2320
+ if (live) setPreparedCanvas(input.canvas);
2321
+ } catch {
2322
+ }
2323
+ }
2324
+ if (!live) return;
2325
+ const result = await client.invoke(
2326
+ { instanceId, operationId: "export.capabilities" },
2327
+ {}
2328
+ );
2329
+ const player = document.createElement("video");
2330
+ if (live)
2331
+ setFormats(
2332
+ result.formats.filter(
2333
+ (format) => format === "h264" || Boolean(
2334
+ player.canPlayType(
2335
+ format === "hevc" ? 'video/mp4; codecs="hvc1.1.6.L93.B0"' : 'video/webm; codecs="vp9, opus"'
2336
+ )
2337
+ )
2338
+ )
2339
+ );
2340
+ } catch {
2341
+ } finally {
2342
+ if (live) setChecking(false);
2343
+ }
2344
+ })();
2345
+ return () => {
2346
+ live = false;
2347
+ };
2348
+ }, [canvas2?.width, canvas2?.height, client, instanceId, issue, title]);
2349
+ useEffect10(() => {
2350
+ if (!jobId || unresolved || job && job.jobId === jobId && terminal.has(job.state)) return;
2351
+ let live = true;
2352
+ let timer;
2353
+ async function poll(id) {
2354
+ try {
2355
+ const result = await client.invoke(
2356
+ { instanceId, operationId: "jobs.get" },
2357
+ { jobId: id }
2358
+ );
2359
+ if (!live) return;
2360
+ updateJob(result, downloadPending);
2361
+ setPollError("");
2362
+ if (terminal.has(result.state)) return;
2363
+ } catch (error2) {
2364
+ if (!live) return;
2365
+ if (error2 && typeof error2 === "object" && "code" in error2 && error2.code === "JOB_NOT_FOUND") {
2366
+ showNotice("The previous export could not be found. Try again.");
2367
+ setPollError("");
2368
+ track(idleTracking);
2369
+ return;
2370
+ }
2371
+ setPollError(readableError(error2));
2372
+ }
2373
+ if (live) timer = setTimeout(() => void poll(id), 750);
2374
+ }
2375
+ void poll(jobId);
2376
+ return () => {
2377
+ live = false;
2378
+ clearTimeout(timer);
2379
+ };
2380
+ }, [client, instanceId, jobId, job?.state, unresolved, downloadPending]);
2381
+ function updateJob(result, shouldDownload) {
2382
+ const notice2 = exportNotices[result.state];
2383
+ if (notice2 && notifiedFailure.current !== result.jobId) {
2384
+ notifiedFailure.current = result.jobId;
2385
+ showNotice(
2386
+ result.cleanupPending ? "The previous export is still cleaning up. Try again in a moment." : notice2
2387
+ );
2388
+ }
2389
+ if (terminal.has(result.state) && (result.state !== "succeeded" || !shouldDownload))
2390
+ track(idleTracking);
2391
+ setJob(
2392
+ (current) => current?.jobId === result.jobId && current.revision > result.revision ? current : result
2393
+ );
2394
+ }
2395
+ function track(next) {
2396
+ try {
2397
+ localStorage.setItem(storageKey, JSON.stringify(next));
2398
+ } catch {
2399
+ }
2400
+ setTracking({ ...next, recoverIntent: void 0 });
2401
+ }
2402
+ async function act(run) {
2403
+ if (lock.current) return;
2404
+ lock.current = true;
2405
+ setBusy(true);
2406
+ setError("");
2407
+ try {
2408
+ await run();
2409
+ } catch (error2) {
2410
+ setError(readableError(error2));
2411
+ } finally {
2412
+ lock.current = false;
2413
+ setBusy(false);
2414
+ }
2415
+ }
2416
+ async function submit(intent) {
2417
+ track({ jobId, downloadPending, pending: intent });
2418
+ try {
2419
+ const result = await client.invoke(
2420
+ { instanceId, operationId: intent.request.operation },
2421
+ intent.request.input,
2422
+ { requestKey: intent.key }
2423
+ );
2424
+ setJob(void 0);
2425
+ track({ jobId: result.jobId, downloadPending: true, pending: void 0 });
2426
+ } catch (error2) {
2427
+ const code = error2 && typeof error2 === "object" && "code" in error2 ? error2.code : void 0;
2428
+ if (typeof code === "string" && !["EXECUTION_UNKNOWN", "OPERATION_CONTRACT_CHANGED", "TRANSPORT_UNKNOWN"].includes(code))
2429
+ track({ jobId, downloadPending, pending: void 0 });
2430
+ throw error2;
2431
+ }
2432
+ }
2433
+ async function findOriginal() {
2434
+ const original = pending ?? await recoverIntent?.();
2435
+ if (!original) return;
2436
+ const found = await client.invoke(
2437
+ { instanceId, operationId: "jobs.list" },
2438
+ {
2439
+ request: {
2440
+ operation: original.request.operation,
2441
+ requestKey: original.key,
2442
+ intent: original.request.input
2443
+ }
2444
+ }
2445
+ );
2446
+ if (!found.items[0]) throw Error("No accepted export was found. No new task was submitted.");
2447
+ track({ jobId: found.items[0].jobId, downloadPending: true, pending: void 0 });
2448
+ updateJob(found.items[0], true);
2449
+ }
2450
+ async function exportVideo() {
2451
+ const outputName2 = exportName(name, exportProfiles[settings.format].extension);
2452
+ const input = await prepare();
2453
+ if (!exportDimensions(input.canvas, settings.aspect, settings.resolution))
2454
+ throw Error("Choose a smaller resolution for this aspect ratio.");
2455
+ await submit({
2456
+ key: crypto.randomUUID(),
2457
+ request: { operation: "sequence.process", input: { ...input, outputName: outputName2, settings } }
2458
+ });
2459
+ }
2460
+ function update(key, value) {
2461
+ setSettings((current) => ({ ...current, [key]: value }));
2462
+ }
2463
+ const fields = [
2464
+ {
2465
+ label: "Format",
2466
+ value: settings.format,
2467
+ change: (value) => update("format", value),
2468
+ options: Object.keys(exportProfiles).map((value) => ({
2469
+ value,
2470
+ label: exportProfiles[value].label + (formats.includes(value) ? "" : " (Unavailable)"),
2471
+ disabled: !formats.includes(value)
2472
+ }))
2473
+ },
2474
+ {
2475
+ label: "Aspect ratio",
2476
+ value: settings.aspect,
2477
+ change: (value) => update("aspect", value),
2478
+ options: exportAspects.map((value) => {
2479
+ if (value === "source") return { value, label: "Match source" };
2480
+ const [width, height] = value.split(":").map(Number);
2481
+ return {
2482
+ value,
2483
+ label: value,
2484
+ icon: /* @__PURE__ */ React5.createElement("span", { className: "mt-export-ratio-icon", "aria-hidden": "true" }, /* @__PURE__ */ React5.createElement(
2485
+ "span",
2486
+ {
2487
+ style: {
2488
+ width: 14 * Math.min(1, width / height),
2489
+ height: 14 * Math.min(1, height / width)
2490
+ }
2491
+ }
2492
+ ))
2493
+ };
2494
+ })
2495
+ },
2496
+ {
2497
+ label: "Resolution",
2498
+ value: String(settings.resolution),
2499
+ change: (value) => update(
2500
+ "resolution",
2501
+ value === "source" ? value : Number(value)
2502
+ ),
2503
+ options: ["source", ...exportResolutions].map((value) => {
2504
+ const size = source && exportDimensions(source, settings.aspect, value);
2505
+ const label = value === "source" ? "Match source" : `${value}p`;
2506
+ return {
2507
+ value: String(value),
2508
+ label: size ? `${label} \xB7 ${size.width} \xD7 ${size.height}` : label,
2509
+ triggerLabel: label,
2510
+ disabled: size === null
2511
+ };
2512
+ })
2513
+ },
2514
+ {
2515
+ label: "Frame rate",
2516
+ value: String(settings.frameRate),
2517
+ change: (value) => update(
2518
+ "frameRate",
2519
+ value === "source" ? value : Number(value)
2520
+ ),
2521
+ options: [
2522
+ { value: "source", label: "Match source" },
2523
+ ...exportRates.map((fps) => ({ value: String(fps), label: `${fps}fps` }))
2524
+ ]
2525
+ },
2526
+ {
2527
+ label: "Quality",
2528
+ value: settings.quality,
2529
+ change: (value) => update("quality", value),
2530
+ options: [
2531
+ { value: "high", label: "High" },
2532
+ { value: "standard", label: "Standard" },
2533
+ { value: "small", label: "Small file" }
2534
+ ]
2535
+ },
2536
+ {
2537
+ label: "Audio",
2538
+ value: String(settings.audio),
2539
+ change: (value) => update("audio", value === "true"),
2540
+ options: [
2541
+ { value: "true", label: "Include audio" },
2542
+ { value: "false", label: "No audio" }
2543
+ ]
2544
+ }
2545
+ ];
2546
+ const ratio = dimensions ? dimensions.width / dimensions.height : settings.aspect !== "source" ? Number(settings.aspect.split(":")[0]) / Number(settings.aspect.split(":")[1]) : void 0;
2547
+ const previewStyle = {
2548
+ "--mt-export-frame-ratio": ratio,
2549
+ ...ratio && settings.aspect !== "source" ? {
2550
+ "--mt-export-frame-width": `${Math.min(1, ratio / (16 / 9)) * 100}%`,
2551
+ "--mt-export-frame-height": `${Math.min(1, 16 / 9 / ratio) * 100}%`
2552
+ } : {}
2553
+ };
2554
+ return /* @__PURE__ */ React5.createElement(
2555
+ Dialog,
2556
+ {
2557
+ open: true,
2558
+ title: "Export Settings",
2559
+ className: "mt-export-dialog",
2560
+ onOpenChange: (open) => {
2561
+ if (!open && !lock.current) onClose();
2562
+ },
2563
+ actions: /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
2564
+ Button,
2565
+ {
2566
+ label: "Cancel",
2567
+ variant: "text-tonal-lg",
2568
+ width: "hug",
2569
+ onClick: onClose,
2570
+ disabled: busy
2571
+ }
2572
+ ), /* @__PURE__ */ React5.createElement(
2573
+ Button,
2574
+ {
2575
+ label: "Export",
2576
+ loading: busy || active,
2577
+ variant: "text-filled-lg",
2578
+ width: "hug",
2579
+ disabled: settingsLocked || checking || invalidSize || Boolean(issue) || exportName(name, "mp4") === ".mp4",
2580
+ onClick: () => void act(exportVideo)
2581
+ }
2582
+ ))
2583
+ },
2584
+ /* @__PURE__ */ React5.createElement(Toast, { message: notice }),
2585
+ /* @__PURE__ */ React5.createElement("div", { className: "mt-export-layout" }, /* @__PURE__ */ React5.createElement("div", { className: "mt-export-preview", style: previewStyle }, preview), /* @__PURE__ */ React5.createElement("div", { className: "mt-export-options" }, /* @__PURE__ */ React5.createElement(
2586
+ TextInput,
2587
+ {
2588
+ placeholder: "Enter a title for the exported video",
2589
+ label: "Title",
2590
+ maxLength: 196,
2591
+ value: name,
2592
+ onValueChange: setName,
2593
+ disabled: settingsLocked
2594
+ }
2595
+ ), /* @__PURE__ */ React5.createElement("dl", null, fields.map(({ label, value, options, change }) => /* @__PURE__ */ React5.createElement("div", { key: label }, /* @__PURE__ */ React5.createElement("dt", null, label), /* @__PURE__ */ React5.createElement("dd", null, /* @__PURE__ */ React5.createElement(
2596
+ Dropdown,
2597
+ {
2598
+ label,
2599
+ value,
2600
+ options,
2601
+ onValueChange: change,
2602
+ appearance: "field",
2603
+ floating: true,
2604
+ disabled: settingsLocked || label === "Format" && checking
2605
+ }
2606
+ ))))))),
2607
+ completed && /* @__PURE__ */ React5.createElement(
2608
+ ExportDownload,
2609
+ {
2610
+ key: job.jobId,
2611
+ job,
2612
+ resolveDownload,
2613
+ autoDownload: downloadPending,
2614
+ onDownloadHandled: () => track(idleTracking),
2615
+ onClose
2616
+ }
2617
+ ),
2618
+ invalidSize && /* @__PURE__ */ React5.createElement("p", { className: "mt-export-notice", role: "status" }, "Choose a smaller resolution for this aspect ratio."),
2619
+ issue && /* @__PURE__ */ React5.createElement("p", { className: "mt-export-notice" }, issue),
2620
+ unresolved && !busy && /* @__PURE__ */ React5.createElement("div", { className: "mt-export-status" }, "Export outcome has not been confirmed.", /* @__PURE__ */ React5.createElement(
2621
+ Button,
2622
+ {
2623
+ label: "Find original export",
2624
+ variant: "text-ghost-sm",
2625
+ onClick: () => void act(findOriginal)
2626
+ }
2627
+ )),
2628
+ (error || pollError) && /* @__PURE__ */ React5.createElement("p", { className: "mt-export-error", role: "alert" }, error || pollError)
2629
+ );
2630
+ }
2631
+ function ExportDownload({
2632
+ job,
2633
+ resolveDownload,
2634
+ autoDownload,
2635
+ onDownloadHandled,
2636
+ onClose
2637
+ }) {
2638
+ const [url, setUrl] = useState11("");
2639
+ const [error, setError] = useState11("");
2640
+ const [retry, setRetry] = useState11(0);
2641
+ const link = useRef8(null);
2642
+ const attempted = useRef8(false);
2643
+ const resolver = useRef8(resolveDownload);
2644
+ resolver.current = resolveDownload;
2645
+ useEffect10(() => {
2646
+ if (!autoDownload && retry === 0) return;
2647
+ let live = true;
2648
+ async function prepareLink() {
2649
+ try {
2650
+ const resolved = job.result && await resolver.current(job.result, job.outputName);
2651
+ if (!resolved) throw Error("The download link is unavailable.");
2652
+ if (live) setUrl(resolved);
2653
+ } catch (error2) {
2654
+ if (live) setError(readableError(error2) || "The download link is unavailable.");
2655
+ }
2656
+ }
2657
+ void prepareLink();
2658
+ return () => {
2659
+ live = false;
2660
+ };
2661
+ }, [job.result, job.outputName, autoDownload, retry]);
2662
+ useEffect10(() => {
2663
+ if (error) {
2664
+ if (autoDownload) onDownloadHandled();
2665
+ return;
2666
+ }
2667
+ if (!url || !link.current || !autoDownload && retry === 0 || attempted.current) return;
2668
+ attempted.current = true;
2669
+ link.current.click();
2670
+ if (autoDownload) onDownloadHandled();
2671
+ onClose();
2672
+ }, [url, error, autoDownload, retry, onDownloadHandled, onClose]);
2673
+ if (url && (autoDownload || retry > 0)) {
2674
+ return /* @__PURE__ */ React5.createElement("a", { hidden: true, ref: link, href: url, download: job.outputName });
2675
+ }
2676
+ if (!error) return null;
2677
+ return /* @__PURE__ */ React5.createElement("div", { className: "mt-export-status" }, /* @__PURE__ */ React5.createElement("span", { className: "mt-export-error", role: "alert" }, error), /* @__PURE__ */ React5.createElement(
2678
+ Button,
2679
+ {
2680
+ label: "Retry download",
2681
+ variant: "text-ghost-sm",
2682
+ onClick: () => {
2683
+ setError("");
2684
+ setRetry((value) => value + 1);
2685
+ }
2686
+ }
2687
+ ));
2688
+ }
2689
+
2690
+ // packages/media-tools/src/ui/compare.tsx
2691
+ import * as React6 from "react";
2692
+ function inputKey(input) {
2693
+ const ref = input.kind === "source" ? input.file.source : input.editRef;
2694
+ return JSON.stringify([
2695
+ input.kind,
2696
+ ref.storeId,
2697
+ ref.objectId,
2698
+ ref.versionId,
2699
+ input.kind === "source" ? input.file.fileId : null
2700
+ ]);
2701
+ }
1482
2702
  function formatLabel(width, height) {
1483
2703
  let a = width, b = height;
1484
2704
  while (b) {
@@ -1496,11 +2716,12 @@ function Candidate({
1496
2716
  emptyState
1497
2717
  }) {
1498
2718
  const { resolve } = useMediaClient();
1499
- const [video, setVideo] = React5.useState(null);
1500
- const [error, setError] = React5.useState("");
1501
- const [revision, setRevision] = React5.useState(0);
2719
+ const [video, setVideo] = React6.useState(null);
2720
+ const [error, setError] = React6.useState("");
2721
+ const [revision, setRevision] = React6.useState(0);
2722
+ const title = slot.context?.shotName?.trim() || video?.name || "Video";
1502
2723
  const identity = JSON.stringify(slot.input);
1503
- React5.useEffect(() => {
2724
+ React6.useEffect(() => {
1504
2725
  let active = true;
1505
2726
  setVideo(null);
1506
2727
  setError("");
@@ -1514,15 +2735,15 @@ function Candidate({
1514
2735
  active = false;
1515
2736
  };
1516
2737
  }, [resolve, identity, revision]);
1517
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: "mt-compare-preview" }, replacing ? /* @__PURE__ */ React5.createElement("div", { className: "mt-empty", role: "status" }, "Choosing replacement\u2026") : !slot.input ? /* @__PURE__ */ React5.createElement("div", { className: "mt-empty" }, emptyState ?? /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("p", null, "No video selected."), /* @__PURE__ */ React5.createElement(
2738
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("div", { className: "mt-compare-preview" }, replacing ? /* @__PURE__ */ React6.createElement("div", { className: "mt-empty", role: "status" }, "Choosing replacement\u2026") : !slot.input ? /* @__PURE__ */ React6.createElement("div", { className: "mt-empty" }, /* @__PURE__ */ React6.createElement("p", null, "No video selected."), emptyState ?? /* @__PURE__ */ React6.createElement(
1518
2739
  Button,
1519
2740
  {
1520
- label: "Choose video",
1521
- variant: "text-tonal-sm",
2741
+ label: "Select a shot",
2742
+ variant: "text-plain-sm",
1522
2743
  width: "hug",
1523
2744
  onClick: onChoose
1524
2745
  }
1525
- ))) : error ? /* @__PURE__ */ React5.createElement("div", { className: "mt-empty", role: "alert" }, /* @__PURE__ */ React5.createElement("p", null, error), /* @__PURE__ */ React5.createElement(
2746
+ )) : error ? /* @__PURE__ */ React6.createElement("div", { className: "mt-empty", role: "alert" }, /* @__PURE__ */ React6.createElement("p", null, error), /* @__PURE__ */ React6.createElement(
1526
2747
  Button,
1527
2748
  {
1528
2749
  label: "Reload preview",
@@ -1530,29 +2751,30 @@ function Candidate({
1530
2751
  width: "hug",
1531
2752
  onClick: () => setRevision(revision + 1)
1532
2753
  }
1533
- )) : !video ? /* @__PURE__ */ React5.createElement("div", { className: "mt-empty", role: "status" }, "Loading fixed video\u2026") : video.edited ? /* @__PURE__ */ React5.createElement(RecipePlayer, { video }) : /* @__PURE__ */ React5.createElement(
2754
+ )) : !video ? /* @__PURE__ */ React6.createElement("div", { className: "mt-empty", role: "status" }, "Loading fixed video\u2026") : video.edited ? /* @__PURE__ */ React6.createElement(RecipePlayer, { video }) : /* @__PURE__ */ React6.createElement(
1534
2755
  VideoPlayer,
1535
2756
  {
1536
2757
  src: video.previewUrl,
1537
- title: video.name,
2758
+ title,
2759
+ showCoverInfo: false,
1538
2760
  controlsPlacement: "overlay",
1539
2761
  onError: () => setError("This video could not be played. Reload its fixed preview.")
1540
2762
  }
1541
- )), /* @__PURE__ */ React5.createElement("div", { className: "mt-candidate-caption" }, /* @__PURE__ */ React5.createElement("div", { className: "mt-candidate-heading" }, /* @__PURE__ */ React5.createElement("div", null, /* @__PURE__ */ React5.createElement("strong", null, slot.input ? slot.context?.shotName || video?.name || "Video" : "Candidate"), video && /* @__PURE__ */ React5.createElement("span", null, "Variant ", video.versionNumber, video.edited ? " \xB7 Edited" : "")), menu), video?.colorInterpretation === "assumed-bt709" && /* @__PURE__ */ React5.createElement("span", null, "Color information is missing. Standard SDR colors are assumed; export may differ slightly.")), /* @__PURE__ */ React5.createElement("div", { className: "mt-candidate-context" }, slot.input && (video || slot.context?.spokenLine || slot.context?.hook || slot.context?.cta) && /* @__PURE__ */ React5.createElement("dl", null, slot.context?.spokenLine && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("dt", null, "Spoken line"), /* @__PURE__ */ React5.createElement("dd", null, slot.context.spokenLine)), slot.context?.hook && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("dt", null, "Opening Hook"), /* @__PURE__ */ React5.createElement("dd", null, slot.context.hook)), slot.context && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("dt", null, "CTA"), /* @__PURE__ */ React5.createElement("dd", null, slot.context.cta || "None")), video && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("dt", null, "Format"), /* @__PURE__ */ React5.createElement("dd", null, formatLabel(video.geometry.pixelRect.width, video.geometry.pixelRect.height)), /* @__PURE__ */ React5.createElement("dt", null, "Duration"), /* @__PURE__ */ React5.createElement("dd", null, Number((video.effectiveDurationMs / 1e3).toFixed(2)), "s")))));
2763
+ )), /* @__PURE__ */ React6.createElement("div", { className: "mt-candidate-caption" }, /* @__PURE__ */ React6.createElement("div", { className: "mt-candidate-heading" }, /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("strong", null, slot.input ? title : "Candidate"), video && /* @__PURE__ */ React6.createElement("span", null, "Variant ", video.versionNumber, video.edited ? " \xB7 Edited" : "")), menu), video?.colorInterpretation === "assumed-bt709" && /* @__PURE__ */ React6.createElement("span", null, "Color information is missing. Standard SDR colors are assumed; export may differ slightly.")), /* @__PURE__ */ React6.createElement("div", { className: "mt-candidate-context" }, slot.input && (video || slot.context?.spokenLine || slot.context?.hook || slot.context?.cta) && /* @__PURE__ */ React6.createElement("dl", null, slot.context?.spokenLine && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("dt", null, "Spoken line"), /* @__PURE__ */ React6.createElement("dd", null, slot.context.spokenLine)), slot.context?.hook && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("dt", null, "Opening Hook"), /* @__PURE__ */ React6.createElement("dd", null, slot.context.hook)), slot.context && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("dt", null, "CTA"), /* @__PURE__ */ React6.createElement("dd", null, slot.context.cta || "None")), video && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("dt", null, "Format"), /* @__PURE__ */ React6.createElement("dd", null, formatLabel(video.geometry.pixelRect.width, video.geometry.pixelRect.height)), /* @__PURE__ */ React6.createElement("dt", null, "Duration"), /* @__PURE__ */ React6.createElement("dd", null, formatDurationSeconds(video.effectiveDurationMs), "s")))));
1542
2764
  }
1543
2765
  function VideoCompare(props) {
1544
- const [generation, setGeneration] = React5.useState(0);
1545
- const [replacing, setReplacing] = React5.useState(null);
1546
- const [error, setError] = React5.useState("");
1547
- const active = React5.useRef(true);
1548
- React5.useEffect(() => {
2766
+ const [generation, setGeneration] = React6.useState(0);
2767
+ const [replacing, setReplacing] = React6.useState(null);
2768
+ const [error, setError] = React6.useState("");
2769
+ const active = React6.useRef(true);
2770
+ React6.useEffect(() => {
1549
2771
  active.current = true;
1550
2772
  return () => {
1551
2773
  active.current = false;
1552
2774
  };
1553
2775
  }, []);
1554
2776
  if (props.slots.length < 2 || props.slots.length > 4 || new Set(props.slots.map((slot) => slot.id)).size !== props.slots.length)
1555
- return /* @__PURE__ */ React5.createElement("p", { role: "alert" }, "Compare requires two to four uniquely identified columns.");
2777
+ return /* @__PURE__ */ React6.createElement("p", { role: "alert" }, "Compare requires two to four uniquely identified columns.");
1556
2778
  const remove = (slot) => props.onSlotsChange(
1557
2779
  props.slots.length > 2 ? props.slots.filter((value) => value.id !== slot.id) : props.slots.map((value) => value.id === slot.id ? { ...value, input: null } : value)
1558
2780
  );
@@ -1572,91 +2794,118 @@ function VideoCompare(props) {
1572
2794
  if (active.current) setReplacing(null);
1573
2795
  }
1574
2796
  }
2797
+ const slotKeys = props.slots.map(({ input }) => input && inputKey(input));
1575
2798
  function candidateChoices(slot) {
1576
- return (props.candidates || []).filter(
1577
- (candidate) => !props.slots.some(
1578
- (other) => other.id !== slot.id && JSON.stringify(other.input) === JSON.stringify(candidate.input)
1579
- )
1580
- ).map((candidate, index) => ({
1581
- id: `candidate-${index}`,
1582
- label: candidate.label,
1583
- onSelect: () => props.onSlotsChange(
1584
- props.slots.map(
1585
- (value) => value.id === slot.id ? { ...value, input: candidate.input, context: candidate.context } : value
1586
- )
1587
- )
1588
- }));
2799
+ return (props.candidates || []).flatMap((candidate) => {
2800
+ const key = inputKey(candidate.input);
2801
+ const occupied = props.slots[slotKeys.indexOf(key)];
2802
+ if (occupied && (props.allowCandidateSwap ? occupied.id === slot.id : occupied.id !== slot.id))
2803
+ return [];
2804
+ return [
2805
+ {
2806
+ id: key,
2807
+ label: props.allowCandidateSwap && occupied ? "Swap with " + candidate.label : candidate.label,
2808
+ preview: candidate.preview,
2809
+ onSelect: () => props.onSlotsChange(
2810
+ props.slots.map((column) => {
2811
+ if (column.id === slot.id)
2812
+ return { ...column, input: candidate.input, context: candidate.context };
2813
+ if (column.id === occupied?.id)
2814
+ return { ...column, input: slot.input, context: slot.context };
2815
+ return column;
2816
+ })
2817
+ )
2818
+ }
2819
+ ];
2820
+ });
1589
2821
  }
1590
- return /* @__PURE__ */ React5.createElement("section", { className: "mt-compare", "aria-label": "Compare videos" }, error && /* @__PURE__ */ React5.createElement("p", { role: "alert", className: "mt-error" }, error), /* @__PURE__ */ React5.createElement(
2822
+ return /* @__PURE__ */ React6.createElement("section", { className: "mt-compare", "aria-label": "Compare videos" }, error && /* @__PURE__ */ React6.createElement("p", { role: "alert", className: "mt-error" }, error), /* @__PURE__ */ React6.createElement(
1591
2823
  "div",
1592
2824
  {
1593
2825
  className: "mt-compare-columns",
1594
2826
  style: { gridTemplateColumns: `repeat(${props.slots.length}, minmax(240px,1fr))` }
1595
2827
  },
1596
- props.slots.map((slot, index) => /* @__PURE__ */ React5.createElement("article", { className: "mt-compare-column", key: slot.id, "aria-label": `Video ${index + 1}` }, /* @__PURE__ */ React5.createElement(
1597
- Candidate,
1598
- {
1599
- key: JSON.stringify([slot.id, slot.input, generation]),
1600
- slot,
1601
- replacing: replacing === slot.id,
1602
- onChoose: () => void replace(slot),
1603
- emptyState: props.candidates ? candidateChoices(slot).length ? /* @__PURE__ */ React5.createElement(Menu, { label: "Choose video", floating: true, items: candidateChoices(slot) }) : /* @__PURE__ */ React5.createElement("p", null, "No other candidates yet.") : void 0,
1604
- menu: /* @__PURE__ */ React5.createElement(
1605
- Menu,
1606
- {
1607
- label: `Options for video ${index + 1}`,
1608
- triggerIcon: "more",
1609
- floating: true,
1610
- items: [
1611
- ...props.slotMenuItems?.(slot) ?? [],
1612
- ...props.candidates ? [
1613
- {
1614
- id: "replace",
1615
- label: "Choose video",
1616
- disabled: candidateChoices(slot).length === 0,
1617
- items: candidateChoices(slot)
1618
- }
1619
- ] : [
2828
+ props.slots.map((slot, index) => {
2829
+ const replacements = candidateChoices(slot);
2830
+ return /* @__PURE__ */ React6.createElement("article", { className: "mt-compare-column", key: slot.id, "aria-label": `Video ${index + 1}` }, /* @__PURE__ */ React6.createElement(
2831
+ Candidate,
2832
+ {
2833
+ key: JSON.stringify([slot.id, slot.input, generation]),
2834
+ slot,
2835
+ replacing: replacing === slot.id,
2836
+ onChoose: () => void replace(slot),
2837
+ emptyState: props.candidates ? replacements.length || props.allowCandidateSwap ? /* @__PURE__ */ React6.createElement(
2838
+ Menu,
2839
+ {
2840
+ label: "Select a shot",
2841
+ textTrigger: "plain",
2842
+ floating: true,
2843
+ items: replacements
2844
+ }
2845
+ ) : /* @__PURE__ */ React6.createElement("p", null, "No other candidates yet.") : void 0,
2846
+ menu: /* @__PURE__ */ React6.createElement(
2847
+ Menu,
2848
+ {
2849
+ label: `Options for video ${index + 1}`,
2850
+ triggerIcon: "more",
2851
+ cascading: props.allowCandidateSwap,
2852
+ floating: true,
2853
+ items: [
2854
+ ...props.slotMenuItems?.(slot) ?? [],
2855
+ ...props.candidates ? [
2856
+ {
2857
+ id: "replace",
2858
+ label: "Choose video",
2859
+ disabled: replacements.length === 0,
2860
+ items: replacements
2861
+ }
2862
+ ] : [
2863
+ {
2864
+ id: "replace",
2865
+ label: slot.input ? "Replace" : "Choose video",
2866
+ disabled: replacing !== null,
2867
+ onSelect: () => void replace(slot)
2868
+ }
2869
+ ],
2870
+ ...slot.input ? [
2871
+ {
2872
+ id: "details",
2873
+ label: "Details",
2874
+ onSelect: () => {
2875
+ setGeneration((value) => value + 1);
2876
+ props.onOpenDetails(slot.input, {
2877
+ slots: props.slots,
2878
+ origin: props.origin
2879
+ });
2880
+ }
2881
+ }
2882
+ ] : [],
1620
2883
  {
1621
- id: "replace",
1622
- label: slot.input ? "Replace" : "Choose video",
1623
- disabled: replacing !== null,
1624
- onSelect: () => void replace(slot)
1625
- }
1626
- ],
1627
- ...slot.input ? [
2884
+ id: "add-column",
2885
+ label: "Add column",
2886
+ disabled: props.slots.length >= 4,
2887
+ onSelect: () => props.onSlotsChange([
2888
+ ...props.slots,
2889
+ { id: crypto.randomUUID(), input: null }
2890
+ ])
2891
+ },
1628
2892
  {
1629
- id: "details",
1630
- label: "Details",
1631
- onSelect: () => {
1632
- setGeneration((value) => value + 1);
1633
- props.onOpenDetails(slot.input, {
1634
- slots: props.slots,
1635
- origin: props.origin
1636
- });
1637
- }
2893
+ id: "remove",
2894
+ label: "Remove",
2895
+ tone: "danger",
2896
+ onSelect: () => remove(slot)
1638
2897
  }
1639
- ] : [],
1640
- {
1641
- id: "add-column",
1642
- label: "Add column",
1643
- disabled: props.slots.length >= 4,
1644
- onSelect: () => props.onSlotsChange([
1645
- ...props.slots,
1646
- { id: crypto.randomUUID(), input: null }
1647
- ])
1648
- },
1649
- { id: "remove", label: "Remove", onSelect: () => remove(slot) }
1650
- ]
1651
- }
1652
- )
1653
- }
1654
- ), slot.input && props.renderSlotActions && /* @__PURE__ */ React5.createElement("div", { className: "mt-column-actions" }, props.renderSlotActions(slot))))
2898
+ ]
2899
+ }
2900
+ )
2901
+ }
2902
+ ), slot.input && props.renderSlotActions && /* @__PURE__ */ React6.createElement("div", { className: "mt-column-actions" }, props.renderSlotActions(slot)));
2903
+ })
1655
2904
  ));
1656
2905
  }
1657
2906
 
1658
2907
  // packages/media-tools/src/ui/jobs.tsx
1659
- import * as React6 from "react";
2908
+ import * as React7 from "react";
1660
2909
  var labels = {
1661
2910
  queued: "Queued",
1662
2911
  running: "Processing",
@@ -1668,20 +2917,20 @@ var labels = {
1668
2917
  };
1669
2918
  function MediaJobs({ onOpenResult }) {
1670
2919
  const { client, instanceId } = useMediaClient();
1671
- const [page, setPage] = React6.useState({ items: [], nextOffset: null });
1672
- const [offset, setOffset] = React6.useState(0);
1673
- const [refresh, setRefresh] = React6.useState(0);
1674
- const [error, setError] = React6.useState("");
1675
- const [pending, setPending] = React6.useState(null);
1676
- const keys = React6.useRef(/* @__PURE__ */ new Map());
1677
- const live = React6.useRef(true);
1678
- React6.useEffect(() => {
2920
+ const [page, setPage] = React7.useState({ items: [], nextOffset: null });
2921
+ const [offset, setOffset] = React7.useState(0);
2922
+ const [refresh, setRefresh] = React7.useState(0);
2923
+ const [error, setError] = React7.useState("");
2924
+ const [pending, setPending] = React7.useState(null);
2925
+ const keys = React7.useRef(/* @__PURE__ */ new Map());
2926
+ const live = React7.useRef(true);
2927
+ React7.useEffect(() => {
1679
2928
  live.current = true;
1680
2929
  return () => {
1681
2930
  live.current = false;
1682
2931
  };
1683
2932
  }, []);
1684
- React6.useEffect(() => {
2933
+ React7.useEffect(() => {
1685
2934
  let active = true, timer;
1686
2935
  async function poll() {
1687
2936
  try {
@@ -1731,7 +2980,7 @@ function MediaJobs({ onOpenResult }) {
1731
2980
  if (live.current) setPending(null);
1732
2981
  }
1733
2982
  }
1734
- return /* @__PURE__ */ React6.createElement("section", { className: "mt-jobs", "aria-label": "Media tasks" }, /* @__PURE__ */ React6.createElement("div", { className: "mt-toolbar" }, /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("h2", null, "Media tasks"), /* @__PURE__ */ React6.createElement("p", { className: "mt-help" }, "Processing continues when this page closes.")), /* @__PURE__ */ React6.createElement(
2983
+ return /* @__PURE__ */ React7.createElement("section", { className: "mt-jobs", "aria-label": "Media tasks" }, /* @__PURE__ */ React7.createElement("div", { className: "mt-toolbar" }, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement("h2", null, "Media tasks"), /* @__PURE__ */ React7.createElement("p", { className: "mt-help" }, "Processing continues when this page closes.")), /* @__PURE__ */ React7.createElement(
1735
2984
  Button,
1736
2985
  {
1737
2986
  label: "Refresh tasks",
@@ -1739,14 +2988,14 @@ function MediaJobs({ onOpenResult }) {
1739
2988
  width: "hug",
1740
2989
  onClick: () => setRefresh(refresh + 1)
1741
2990
  }
1742
- )), error && /* @__PURE__ */ React6.createElement("p", { role: "alert", className: "mt-error" }, error), !page.items.length && /* @__PURE__ */ React6.createElement("p", { className: "mt-empty" }, "No media tasks on this page."), page.items.map((job) => /* @__PURE__ */ React6.createElement("article", { className: "mt-job", key: job.jobId }, /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("strong", null, job.outputName), /* @__PURE__ */ React6.createElement("p", null, job.kind === "sequence" ? "Sequence export" : "Video processing", " \xB7", " ", job.cancelRequested && !["succeeded", "failed", "canceled", "interrupted"].includes(job.state) ? "Stopping\u2026" : labels[job.state]), job.cleanupPending && /* @__PURE__ */ React6.createElement("p", { className: "mt-error" }, "Cleanup is pending. New processing is blocked until the old process is confirmed stopped."), job.error && /* @__PURE__ */ React6.createElement("p", { className: "mt-error" }, job.error.message)), /* @__PURE__ */ React6.createElement("div", { className: "mt-job-progress" }, /* @__PURE__ */ React6.createElement(
2991
+ )), error && /* @__PURE__ */ React7.createElement("p", { role: "alert", className: "mt-error" }, error), !page.items.length && /* @__PURE__ */ React7.createElement("p", { className: "mt-empty" }, "No media tasks on this page."), page.items.map((job) => /* @__PURE__ */ React7.createElement("article", { className: "mt-job", key: job.jobId }, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement("strong", null, job.outputName), /* @__PURE__ */ React7.createElement("p", null, job.kind === "sequence" ? "Sequence export" : "Video processing", " \xB7", " ", job.cancelRequested && !["succeeded", "failed", "canceled", "interrupted"].includes(job.state) ? "Stopping\u2026" : labels[job.state]), job.cleanupPending && /* @__PURE__ */ React7.createElement("p", { className: "mt-error" }, "Cleanup is pending. New processing is blocked until the old process is confirmed stopped."), job.error && /* @__PURE__ */ React7.createElement("p", { className: "mt-error" }, job.error.message)), /* @__PURE__ */ React7.createElement("div", { className: "mt-job-progress" }, /* @__PURE__ */ React7.createElement(
1743
2992
  "progress",
1744
2993
  {
1745
2994
  "aria-label": `Progress for ${job.outputName}`,
1746
2995
  max: 1,
1747
2996
  value: job.state === "succeeded" ? 1 : job.progress === null ? void 0 : Math.min(0.99, job.progress)
1748
2997
  }
1749
- ), /* @__PURE__ */ React6.createElement("span", null, job.state === "succeeded" ? "100%" : job.progress === null ? "Unknown progress" : `${Math.floor(Math.min(0.99, job.progress) * 100)}%`)), /* @__PURE__ */ React6.createElement("div", { className: "mt-column-actions" }, ["queued", "running", "saving"].includes(job.state) && /* @__PURE__ */ React6.createElement(
2998
+ ), /* @__PURE__ */ React7.createElement("span", null, job.state === "succeeded" ? "100%" : job.progress === null ? "Unknown progress" : `${Math.floor(Math.min(0.99, job.progress) * 100)}%`)), /* @__PURE__ */ React7.createElement("div", { className: "mt-column-actions" }, ["queued", "running", "saving"].includes(job.state) && /* @__PURE__ */ React7.createElement(
1750
2999
  Button,
1751
3000
  {
1752
3001
  label: "Cancel task",
@@ -1755,7 +3004,7 @@ function MediaJobs({ onOpenResult }) {
1755
3004
  disabled: pending !== null || job.cancelRequested,
1756
3005
  onClick: () => void act(job, "cancel")
1757
3006
  }
1758
- ), ["failed", "canceled", "interrupted"].includes(job.state) && /* @__PURE__ */ React6.createElement(
3007
+ ), ["failed", "canceled", "interrupted"].includes(job.state) && /* @__PURE__ */ React7.createElement(
1759
3008
  Button,
1760
3009
  {
1761
3010
  label: "Retry task",
@@ -1764,7 +3013,7 @@ function MediaJobs({ onOpenResult }) {
1764
3013
  disabled: pending !== null || job.cleanupPending,
1765
3014
  onClick: () => void act(job, "retry")
1766
3015
  }
1767
- ), job.result && onOpenResult && /* @__PURE__ */ React6.createElement(Button, { label: "Open result", width: "hug", onClick: () => onOpenResult(job.result) }), /* @__PURE__ */ React6.createElement("details", null, /* @__PURE__ */ React6.createElement("summary", null, "Task identity"), /* @__PURE__ */ React6.createElement("code", null, job.jobId))))), /* @__PURE__ */ React6.createElement("div", { className: "mt-pagination" }, /* @__PURE__ */ React6.createElement(
3016
+ ), job.result && onOpenResult && /* @__PURE__ */ React7.createElement(Button, { label: "Open result", width: "hug", onClick: () => onOpenResult(job.result) }), /* @__PURE__ */ React7.createElement("details", null, /* @__PURE__ */ React7.createElement("summary", null, "Task identity"), /* @__PURE__ */ React7.createElement("code", null, job.jobId))))), /* @__PURE__ */ React7.createElement("div", { className: "mt-pagination" }, /* @__PURE__ */ React7.createElement(
1768
3017
  Button,
1769
3018
  {
1770
3019
  label: "Previous tasks",
@@ -1772,7 +3021,7 @@ function MediaJobs({ onOpenResult }) {
1772
3021
  disabled: offset === 0,
1773
3022
  onClick: () => setOffset(Math.max(0, offset - 50))
1774
3023
  }
1775
- ), /* @__PURE__ */ React6.createElement(
3024
+ ), /* @__PURE__ */ React7.createElement(
1776
3025
  Button,
1777
3026
  {
1778
3027
  label: "Next tasks",
@@ -1830,30 +3079,36 @@ async function activate(client) {
1830
3079
  component: Component,
1831
3080
  props
1832
3081
  }) {
1833
- const ready = React7.useSyncExternalStore(
3082
+ const ready = React8.useSyncExternalStore(
1834
3083
  subscribe,
1835
3084
  () => active,
1836
3085
  () => active
1837
3086
  );
1838
- return ready ? /* @__PURE__ */ React7.createElement(MediaContext.Provider, { value: { client, instanceId, resolve } }, /* @__PURE__ */ React7.createElement("div", { className: "mt-root" }, /* @__PURE__ */ React7.createElement(Component, { ...props }))) : null;
3087
+ return ready ? /* @__PURE__ */ React8.createElement(MediaContext.Provider, { value: { client, instanceId, resolve } }, /* @__PURE__ */ React8.createElement("div", { className: "mt-root" }, /* @__PURE__ */ React8.createElement(Component, { ...props }))) : null;
1839
3088
  }
1840
3089
  client.registerUI({
1841
3090
  id: "media.video-editor",
1842
3091
  title: "Video editor",
1843
3092
  kind: "component",
1844
- component: (props) => /* @__PURE__ */ React7.createElement(Bound, { component: VideoEditor, props })
3093
+ component: (props) => /* @__PURE__ */ React8.createElement(Bound, { component: VideoEditor, props })
3094
+ });
3095
+ client.registerUI({
3096
+ id: "media.video-export",
3097
+ title: "Export settings",
3098
+ kind: "component",
3099
+ component: (props) => /* @__PURE__ */ React8.createElement(Bound, { component: VideoExport, props })
1845
3100
  });
1846
3101
  client.registerUI({
1847
3102
  id: "media.video-compare",
1848
3103
  title: "Video comparison",
1849
3104
  kind: "component",
1850
- component: (props) => /* @__PURE__ */ React7.createElement(Bound, { component: VideoCompare, props })
3105
+ component: (props) => /* @__PURE__ */ React8.createElement(Bound, { component: VideoCompare, props })
1851
3106
  });
1852
3107
  client.registerUI({
1853
3108
  id: "media.jobs",
1854
3109
  title: "Media tasks",
1855
3110
  kind: "component",
1856
- component: (props) => /* @__PURE__ */ React7.createElement(Bound, { component: MediaJobs, props })
3111
+ component: (props) => /* @__PURE__ */ React8.createElement(Bound, { component: MediaJobs, props })
1857
3112
  });
1858
3113
  client.onDispose(() => {
1859
3114
  active = false;