@hyperframes/studio 0.6.0-alpha.1 → 0.6.0-alpha.10

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.
@@ -55,20 +55,24 @@ interface NLELayoutProps {
55
55
  onInspectTimelineElement?: (element: TimelineElement) => void;
56
56
  inspectedTimelineElementId?: string | null;
57
57
  timelineLayerChildCounts?: ReadonlyMap<string, number>;
58
- thumbnailedTimelineElementIds?: ReadonlySet<string>;
59
- onToggleTimelineElementThumbnail?: (element: TimelineElement) => void;
60
58
  /** Exposes the compIdToSrc map for parent components (e.g., useRenderClipContent) */
61
59
  onCompIdToSrcChange?: (map: Map<string, string>) => void;
62
60
  /** Whether the timeline panel is visible (default: true) */
63
61
  timelineVisible?: boolean;
64
62
  /** Callback to toggle timeline visibility */
65
63
  onToggleTimeline?: () => void;
64
+ /** Notifies parent when composition loading state changes */
65
+ onCompositionLoadingChange?: (loading: boolean) => void;
66
66
  }
67
67
 
68
68
  const MIN_TIMELINE_H = 100;
69
69
  const DEFAULT_TIMELINE_H = 220;
70
70
  const MIN_PREVIEW_H = 120;
71
71
 
72
+ export function shouldDisableTimelineWhileCompositionLoading(compositionLoading: boolean): boolean {
73
+ return compositionLoading;
74
+ }
75
+
72
76
  export const NLELayout = memo(function NLELayout({
73
77
  projectId,
74
78
  portrait,
@@ -90,11 +94,10 @@ export const NLELayout = memo(function NLELayout({
90
94
  onInspectTimelineElement,
91
95
  inspectedTimelineElementId,
92
96
  timelineLayerChildCounts,
93
- thumbnailedTimelineElementIds,
94
- onToggleTimelineElementThumbnail,
95
97
  onCompIdToSrcChange,
96
98
  timelineVisible,
97
99
  onToggleTimeline,
100
+ onCompositionLoadingChange: onCompositionLoadingChangeParent,
98
101
  }: NLELayoutProps) {
99
102
  const {
100
103
  iframeRef,
@@ -214,6 +217,18 @@ export const NLELayout = memo(function NLELayout({
214
217
 
215
218
  // Resizable timeline height
216
219
  const [timelineH, setTimelineH] = useState(DEFAULT_TIMELINE_H);
220
+ const hasLoadedOnceRef = useRef(false);
221
+ const [compositionLoading, setCompositionLoadingRaw] = useState(true);
222
+ const setCompositionLoading = useCallback((loading: boolean) => {
223
+ if (!loading) hasLoadedOnceRef.current = true;
224
+ if (loading && hasLoadedOnceRef.current) return;
225
+ setCompositionLoadingRaw(loading);
226
+ }, []);
227
+ const timelineDisabled = shouldDisableTimelineWhileCompositionLoading(compositionLoading);
228
+
229
+ useEffect(() => {
230
+ onCompositionLoadingChangeParent?.(compositionLoading);
231
+ }, [compositionLoading, onCompositionLoadingChangeParent]);
217
232
  const isTimelineVisible = timelineVisible ?? true;
218
233
  const isDragging = useRef(false);
219
234
  const containerRef = useRef<HTMLDivElement>(null);
@@ -327,23 +342,31 @@ export const NLELayout = memo(function NLELayout({
327
342
  }, [activeCompositionPath, projectId, updateCompositionStack]);
328
343
 
329
344
  // Resize divider handlers
330
- const handleDividerPointerDown = useCallback((e: React.PointerEvent) => {
331
- e.preventDefault();
332
- isDragging.current = true;
333
- (e.target as HTMLElement).setPointerCapture(e.pointerId);
334
- }, []);
345
+ const handleDividerPointerDown = useCallback(
346
+ (e: React.PointerEvent) => {
347
+ if (timelineDisabled) return;
348
+ e.preventDefault();
349
+ isDragging.current = true;
350
+ (e.target as HTMLElement).setPointerCapture(e.pointerId);
351
+ },
352
+ [timelineDisabled],
353
+ );
335
354
 
336
- const handleDividerPointerMove = useCallback((e: React.PointerEvent) => {
337
- if (!isDragging.current || !containerRef.current) return;
338
- const rect = containerRef.current.getBoundingClientRect();
339
- const mouseY = e.clientY - rect.top;
340
- const containerH = rect.height;
341
- const newTimelineH = Math.max(
342
- MIN_TIMELINE_H,
343
- Math.min(containerH - MIN_PREVIEW_H, containerH - mouseY),
344
- );
345
- setTimelineH(newTimelineH);
346
- }, []);
355
+ const handleDividerPointerMove = useCallback(
356
+ (e: React.PointerEvent) => {
357
+ if (timelineDisabled) return;
358
+ if (!isDragging.current || !containerRef.current) return;
359
+ const rect = containerRef.current.getBoundingClientRect();
360
+ const mouseY = e.clientY - rect.top;
361
+ const containerH = rect.height;
362
+ const newTimelineH = Math.max(
363
+ MIN_TIMELINE_H,
364
+ Math.min(containerH - MIN_PREVIEW_H, containerH - mouseY),
365
+ );
366
+ setTimelineH(newTimelineH);
367
+ },
368
+ [timelineDisabled],
369
+ );
347
370
 
348
371
  const handleDividerPointerUp = useCallback(() => {
349
372
  isDragging.current = false;
@@ -374,9 +397,11 @@ export const NLELayout = memo(function NLELayout({
374
397
  projectId={projectId}
375
398
  iframeRef={iframeRef}
376
399
  onIframeLoad={onIframeLoad}
400
+ onCompositionLoadingChange={setCompositionLoading}
377
401
  portrait={portrait}
378
402
  directUrl={directUrl}
379
403
  refreshKey={refreshKey}
404
+ suppressLoadingOverlay={hasLoadedOnceRef.current}
380
405
  />
381
406
  {previewOverlay}
382
407
  </div>
@@ -388,7 +413,7 @@ export const NLELayout = memo(function NLELayout({
388
413
  onNavigate={handleNavigateComposition}
389
414
  />
390
415
  )}
391
- <PlayerControls onTogglePlay={togglePlay} onSeek={seek} />
416
+ <PlayerControls onTogglePlay={togglePlay} onSeek={seek} disabled={timelineDisabled} />
392
417
  </div>
393
418
  </div>
394
419
 
@@ -406,13 +431,18 @@ export const NLELayout = memo(function NLELayout({
406
431
  </div>
407
432
 
408
433
  {/* Timeline section — fixed height, resizable */}
409
- <div className="flex flex-col flex-shrink-0" style={{ height: timelineH }}>
434
+ <div
435
+ className="relative flex flex-col flex-shrink-0"
436
+ style={{ height: timelineH }}
437
+ aria-disabled={timelineDisabled || undefined}
438
+ >
410
439
  {/* Timeline tracks */}
411
440
  <div
412
441
  // flex-col: toolbar takes natural height, Timeline fills remainder.
413
442
  className="flex flex-col flex-1 min-h-0 overflow-hidden bg-neutral-950"
414
443
  onDoubleClick={(e) => {
415
444
  if ((e.target as HTMLElement).closest("[data-clip]")) return;
445
+ if (timelineDisabled) return;
416
446
  if (compositionStack.length > 1) {
417
447
  updateCompositionStack((prev) => prev.slice(0, -1));
418
448
  }
@@ -433,11 +463,20 @@ export const NLELayout = memo(function NLELayout({
433
463
  onInspectElement={onInspectTimelineElement}
434
464
  inspectedElementId={inspectedTimelineElementId}
435
465
  layerChildCounts={timelineLayerChildCounts}
436
- thumbnailedElementIds={thumbnailedTimelineElementIds}
437
- onToggleElementThumbnail={onToggleTimelineElementThumbnail}
466
+ disabled={timelineDisabled}
438
467
  />
439
468
  </div>
440
469
  {timelineFooter && <div className="flex-shrink-0">{timelineFooter}</div>}
470
+ {timelineDisabled && (
471
+ <div
472
+ className="absolute inset-0 z-30 cursor-not-allowed bg-black/18"
473
+ data-testid="timeline-loading-disabled-overlay"
474
+ aria-hidden="true"
475
+ onPointerDown={(event) => event.preventDefault()}
476
+ onDragOver={(event) => event.preventDefault()}
477
+ onDrop={(event) => event.preventDefault()}
478
+ />
479
+ )}
441
480
  </div>
442
481
  </>
443
482
  ) : onToggleTimeline ? (
@@ -5,9 +5,11 @@ interface NLEPreviewProps {
5
5
  projectId: string;
6
6
  iframeRef: Ref<HTMLIFrameElement>;
7
7
  onIframeLoad: () => void;
8
+ onCompositionLoadingChange?: (loading: boolean) => void;
8
9
  portrait?: boolean;
9
10
  directUrl?: string;
10
11
  refreshKey?: number;
12
+ suppressLoadingOverlay?: boolean;
11
13
  }
12
14
 
13
15
  export function getPreviewPlayerKey({
@@ -36,9 +38,11 @@ export const NLEPreview = memo(function NLEPreview({
36
38
  projectId,
37
39
  iframeRef,
38
40
  onIframeLoad,
41
+ onCompositionLoadingChange,
39
42
  portrait,
40
43
  directUrl,
41
44
  refreshKey,
45
+ suppressLoadingOverlay,
42
46
  }: NLEPreviewProps) {
43
47
  const baseKey = getPreviewPlayerKey({ projectId, directUrl, refreshKey });
44
48
  const prevRefreshKeyRef = useRef(refreshKey);
@@ -88,8 +92,10 @@ export const NLEPreview = memo(function NLEPreview({
88
92
  projectId={directUrl ? undefined : projectId}
89
93
  directUrl={directUrl}
90
94
  onLoad={retiringKey ? handleNewPlayerLoad : onIframeLoad}
95
+ onCompositionLoadingChange={onCompositionLoadingChange}
91
96
  portrait={portrait}
92
97
  style={retiringKey ? { position: "absolute", inset: 0, zIndex: 1 } : undefined}
98
+ suppressLoadingOverlay={suppressLoadingOverlay}
93
99
  />
94
100
  </div>
95
101
  </div>
@@ -1,10 +1,12 @@
1
1
  import { memo, useState, useRef, useEffect } from "react";
2
2
  import { RenderQueueItem } from "./RenderQueueItem";
3
- import type { RenderJob } from "./useRenderQueue";
3
+ import type { RenderJob, ResolutionPreset } from "./useRenderQueue";
4
4
 
5
5
  type StartRenderHandler = (
6
6
  format: "mp4" | "webm" | "mov",
7
7
  quality: "draft" | "standard" | "high",
8
+ resolution: ResolutionPreset | "auto",
9
+ fps: 24 | 30 | 60,
8
10
  ) => void | Promise<void>;
9
11
 
10
12
  interface RenderQueueProps {
@@ -16,6 +18,36 @@ interface RenderQueueProps {
16
18
  isRendering: boolean;
17
19
  }
18
20
 
21
+ // Indexing the table by `ResolutionPreset | "auto"` makes adding a new preset
22
+ // to `core.types` (e.g. an 8K row) a TypeScript error here instead of a
23
+ // silently missing dropdown entry. Order is fixed by the array below.
24
+ const RESOLUTION_LABELS: Record<ResolutionPreset | "auto", { label: string; title: string }> = {
25
+ auto: { label: "Auto", title: "Render at the composition's authored resolution" },
26
+ landscape: { label: "1080p ↔", title: "1920×1080 landscape" },
27
+ portrait: { label: "1080p ↕", title: "1080×1920 portrait" },
28
+ "landscape-4k": {
29
+ label: "4K ↔",
30
+ title: "3840×2160 — supersamples a 1080p composition via Chrome DPR. Slower, larger files.",
31
+ },
32
+ "portrait-4k": {
33
+ label: "4K ↕",
34
+ title: "2160×3840 — supersamples a 1080p portrait composition via Chrome DPR.",
35
+ },
36
+ };
37
+
38
+ const RESOLUTION_OPTION_ORDER: (ResolutionPreset | "auto")[] = [
39
+ "auto",
40
+ "landscape",
41
+ "portrait",
42
+ "landscape-4k",
43
+ "portrait-4k",
44
+ ];
45
+
46
+ const RESOLUTION_OPTIONS = RESOLUTION_OPTION_ORDER.map((value) => ({
47
+ value,
48
+ ...RESOLUTION_LABELS[value],
49
+ }));
50
+
19
51
  const FORMAT_INFO: Record<"mp4" | "webm" | "mov", { label: string; desc: string }> = {
20
52
  mp4: { label: "MP4", desc: "Best for general use. Smallest file, universal playback." },
21
53
  mov: {
@@ -101,6 +133,8 @@ function FormatExportButton({
101
133
  }) {
102
134
  const [format, setFormat] = useState<"mp4" | "webm" | "mov">("mp4");
103
135
  const [quality, setQuality] = useState<"draft" | "standard" | "high">("standard");
136
+ const [resolution, setResolution] = useState<ResolutionPreset | "auto">("auto");
137
+ const [fps, setFps] = useState<24 | 30 | 60>(30);
104
138
 
105
139
  // MOV (ProRes) is a fixed-quality codec — quality selector has no effect.
106
140
  const showQuality = format !== "mov";
@@ -108,13 +142,30 @@ function FormatExportButton({
108
142
  return (
109
143
  <div className="flex items-center gap-1">
110
144
  <FormatInfoTooltip format={format} />
145
+ {/* Resolution must remain the leftmost <select> in this row — it
146
+ carries `rounded-l` for the joined-button look. If you ever hide it
147
+ (feature-flag, etc.), move `rounded-l` to whichever element ends up
148
+ leftmost. */}
149
+ <select
150
+ value={resolution}
151
+ onChange={(e) => setResolution(e.target.value as ResolutionPreset | "auto")}
152
+ disabled={isRendering}
153
+ title={RESOLUTION_OPTIONS.find((r) => r.value === resolution)?.title}
154
+ className="h-5 px-1 text-[10px] rounded-l bg-neutral-800 border border-neutral-700 text-neutral-300 outline-none disabled:opacity-50"
155
+ >
156
+ {RESOLUTION_OPTIONS.map((r) => (
157
+ <option key={r.value} value={r.value} title={r.title}>
158
+ {r.label}
159
+ </option>
160
+ ))}
161
+ </select>
111
162
  {showQuality && (
112
163
  <select
113
164
  value={quality}
114
165
  onChange={(e) => setQuality(e.target.value as "draft" | "standard" | "high")}
115
166
  disabled={isRendering}
116
167
  title={QUALITY_OPTIONS.find((q) => q.value === quality)?.title}
117
- className="h-5 px-1 text-[10px] rounded-l bg-neutral-800 border border-neutral-700 text-neutral-300 outline-none disabled:opacity-50"
168
+ className="h-5 px-1 text-[10px] bg-neutral-800 border border-neutral-700 text-neutral-300 outline-none disabled:opacity-50"
118
169
  >
119
170
  {QUALITY_OPTIONS.map((q) => (
120
171
  <option key={q.value} value={q.value} title={q.title}>
@@ -123,11 +174,22 @@ function FormatExportButton({
123
174
  ))}
124
175
  </select>
125
176
  )}
177
+ <select
178
+ value={fps}
179
+ onChange={(e) => setFps(Number(e.target.value) as 24 | 30 | 60)}
180
+ disabled={isRendering}
181
+ title="Frames per second"
182
+ className="h-5 px-1 text-[10px] bg-neutral-800 border border-neutral-700 text-neutral-300 outline-none disabled:opacity-50"
183
+ >
184
+ <option value={24}>24fps</option>
185
+ <option value={30}>30fps</option>
186
+ <option value={60}>60fps</option>
187
+ </select>
126
188
  <select
127
189
  value={format}
128
190
  onChange={(e) => setFormat(e.target.value as "mp4" | "webm" | "mov")}
129
191
  disabled={isRendering}
130
- className={`h-5 px-1 text-[10px] bg-neutral-800 border border-neutral-700 text-neutral-300 outline-none disabled:opacity-50 ${showQuality ? "" : "rounded-l"}`}
192
+ className="h-5 px-1 text-[10px] bg-neutral-800 border border-neutral-700 text-neutral-300 outline-none disabled:opacity-50"
131
193
  >
132
194
  <option value="mp4">MP4</option>
133
195
  <option value="mov">MOV</option>
@@ -135,7 +197,7 @@ function FormatExportButton({
135
197
  </select>
136
198
  <button
137
199
  onClick={() => {
138
- void onStartRender(format, quality);
200
+ void onStartRender(format, quality, resolution, fps);
139
201
  }}
140
202
  disabled={isRendering}
141
203
  className="flex items-center gap-1 px-2 py-0.5 text-[10px] font-semibold rounded-r bg-studio-accent text-[#09090B] hover:brightness-110 transition-colors disabled:opacity-50"
@@ -11,6 +11,20 @@ export interface RenderJob {
11
11
  durationMs?: number;
12
12
  }
13
13
 
14
+ // Mirrors `CanvasResolution` from @hyperframes/core. Kept local because
15
+ // studio's tsconfig doesn't include node types, and the core barrel
16
+ // transitively pulls in modules with `node:fs` imports. Drift risk is
17
+ // low (4 string literals tied to a stable enum).
18
+ export type ResolutionPreset = "landscape" | "portrait" | "landscape-4k" | "portrait-4k";
19
+
20
+ export interface StartRenderOptions {
21
+ fps?: number;
22
+ quality?: "draft" | "standard" | "high";
23
+ format?: "mp4" | "webm" | "mov";
24
+ /** `"auto"` (default) renders at the composition's authored dimensions. */
25
+ resolution?: ResolutionPreset | "auto";
26
+ }
27
+
14
28
  export function useRenderQueue(projectId: string | null) {
15
29
  const [jobs, setJobs] = useState<RenderJob[]>([]);
16
30
  const eventSourceRef = useRef<EventSource | null>(null);
@@ -59,20 +73,30 @@ export function useRenderQueue(projectId: string | null) {
59
73
 
60
74
  // Start a render and track progress via SSE
61
75
  const startRender = useCallback(
62
- async (
63
- fps = 30,
64
- quality: "draft" | "standard" | "high" = "standard",
65
- format: "mp4" | "webm" | "mov" = "mp4",
66
- ) => {
76
+ async (opts: StartRenderOptions = {}) => {
67
77
  if (!projectId) return;
68
78
 
79
+ const fps = opts.fps ?? 30;
80
+ const quality = opts.quality ?? "standard";
81
+ const format = opts.format ?? "mp4";
82
+ const resolution = opts.resolution;
83
+
69
84
  const startTime = Date.now();
85
+ // "auto" / undefined means "render at the composition's authored size".
86
+ // Omit the field entirely — sending "auto" would trip the route's
87
+ // enum validation set.
88
+ const body: { fps: number; quality: string; format: string; resolution?: string } = {
89
+ fps,
90
+ quality,
91
+ format,
92
+ };
93
+ if (resolution && resolution !== "auto") body.resolution = resolution;
70
94
  let res: Response;
71
95
  try {
72
96
  res = await fetch(`/api/projects/${projectId}/render`, {
73
97
  method: "POST",
74
98
  headers: { "Content-Type": "application/json" },
75
- body: JSON.stringify({ fps, quality, format }),
99
+ body: JSON.stringify(body),
76
100
  });
77
101
  } catch {
78
102
  const failedJob: RenderJob = {