@hyperframes/studio 0.8.96 → 0.8.98

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 (89) hide show
  1. package/dist/assets/{hyperframes-player-ClfxdXeC.js → hyperframes-player-C6muFtfk.js} +1 -1
  2. package/dist/assets/{index-D8ztHPd3.js → index-B6vU39NM.js} +1 -1
  3. package/dist/assets/{index-BNQLP5_v.js → index-BxnoLgxG.js} +1 -1
  4. package/dist/assets/{index-CSHEHeOo.js → index-itc1XziP.js} +198 -192
  5. package/dist/assets/{index-Dx79V1Se.css → index-xB5O0hPw.css} +1 -1
  6. package/dist/{chunk-QZ6HNNFG.js → chunk-6GAO75IU.js} +16 -4
  7. package/dist/chunk-6GAO75IU.js.map +1 -0
  8. package/dist/{chunk-PQFEGZWM.js → chunk-MTAVNAGW.js} +2 -2
  9. package/dist/chunk-MTAVNAGW.js.map +1 -0
  10. package/dist/{chunk-QPSOTK6M.js → chunk-U3EE4ACX.js} +5 -5
  11. package/dist/chunk-U3EE4ACX.js.map +1 -0
  12. package/dist/{domEditingLayers-3BAP6NNO.js → domEditingLayers-NU6Z5QWA.js} +2 -2
  13. package/dist/index.d.ts +23 -6
  14. package/dist/index.html +2 -2
  15. package/dist/index.js +2153 -1969
  16. package/dist/index.js.map +1 -1
  17. package/dist/player.js +2 -2
  18. package/dist/styles.css +1 -1
  19. package/dist/ui.d.ts +3 -1
  20. package/dist/ui.js +1 -1
  21. package/package.json +9 -8
  22. package/src/components/EditorShell.tsx +7 -0
  23. package/src/components/TimelineToolPicker.tsx +19 -15
  24. package/src/components/TimelineToolbar.test.tsx +62 -0
  25. package/src/components/TimelineToolbar.tsx +3 -1
  26. package/src/components/editor/DomEditOverlay.tsx +0 -27
  27. package/src/components/editor/DomEditSelectionChrome.test.tsx +0 -5
  28. package/src/components/editor/DomEditSelectionChrome.tsx +0 -6
  29. package/src/components/editor/clickAfterPreventedPress.test.tsx +122 -0
  30. package/src/components/editor/domEditing.test.ts +9 -1
  31. package/src/components/editor/domEditingDom.ts +2 -1
  32. package/src/components/editor/fontAssets.test.ts +69 -0
  33. package/src/components/editor/fontAssets.ts +11 -2
  34. package/src/components/editor/propertyPanelFont.test.tsx +48 -5
  35. package/src/components/editor/propertyPanelFont.tsx +2 -1
  36. package/src/components/editor/shiftDragAxisLock.test.tsx +0 -2
  37. package/src/components/nle/TimelinePane.tsx +4 -0
  38. package/src/components/ui/Menu.test.tsx +21 -0
  39. package/src/components/ui/Popover.tsx +21 -1
  40. package/src/hooks/domSelectionTimelineMirror.ts +5 -4
  41. package/src/hooks/domStyleCommit.fonts.test.ts +55 -0
  42. package/src/hooks/useAppHotkeys.test.ts +7 -5
  43. package/src/hooks/useClipboard.ts +25 -7
  44. package/src/hooks/useCommitPreflightCapabilities.ts +3 -11
  45. package/src/hooks/useDomSelection.test.ts +56 -32
  46. package/src/hooks/useDomSelection.ts +4 -3
  47. package/src/hooks/useGsapAnimationFetchFallback.test.ts +44 -3
  48. package/src/hooks/useGsapAnimationFetchFallback.ts +11 -35
  49. package/src/hooks/useGsapTweenCache.element.test.tsx +23 -1
  50. package/src/hooks/useGsapTweenCache.ts +0 -24
  51. package/src/index.ts +4 -1
  52. package/src/player/components/BeatStrip.tsx +6 -3
  53. package/src/player/components/ClipContextMenu.test.tsx +182 -0
  54. package/src/player/components/ClipContextMenu.tsx +52 -10
  55. package/src/player/components/Timeline.readOnly.test.tsx +670 -0
  56. package/src/player/components/Timeline.rulerSeek.test.tsx +1 -25
  57. package/src/player/components/TimelineAutomationLane.test.tsx +23 -0
  58. package/src/player/components/TimelineClipDiamonds.tsx +7 -2
  59. package/src/player/components/TimelineFxButton.tsx +3 -0
  60. package/src/player/components/TimelineLanes.tsx +3 -2
  61. package/src/player/components/TimelineOverlays.test.ts +30 -7
  62. package/src/player/components/TimelineOverlays.tsx +7 -1
  63. package/src/player/components/TimelineProvider.tsx +24 -7
  64. package/src/player/components/TimelineTypes.ts +12 -0
  65. package/src/player/components/menuKeyboardNav.ts +12 -5
  66. package/src/player/components/studioShortcuts.ts +1 -1
  67. package/src/player/components/timelineClipGestureHandlers.ts +3 -1
  68. package/src/player/components/timelineDragDrop.ts +11 -1
  69. package/src/player/components/timelineEditCapabilities.ts +1 -0
  70. package/src/player/components/timelineMountTestEnv.ts +24 -0
  71. package/src/player/components/timelineReadOnly.ts +64 -0
  72. package/src/player/components/useAutomationLaneGestures.ts +13 -2
  73. package/src/player/components/useTimelineKeyframeHandlers.ts +7 -0
  74. package/src/player/components/useTimelineProviderState.tsx +44 -14
  75. package/src/player/hooks/useShadowPreviewReload.ts +2 -2
  76. package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +69 -0
  77. package/src/player/hooks/useTimelinePlayer.ts +6 -0
  78. package/src/player/lib/timelineDOM.test.ts +25 -0
  79. package/src/player/lib/timelineDOM.ts +4 -2
  80. package/src/player/lib/timelineIframeHelpers.test.ts +15 -0
  81. package/src/player/store/playerStore.ts +4 -4
  82. package/src/utils/clipboardLook.test.ts +130 -0
  83. package/src/utils/clipboardLook.ts +82 -0
  84. package/src/utils/clipboardPayload.ts +8 -2
  85. package/src/utils/studioFontHelpers.ts +6 -3
  86. package/dist/chunk-PQFEGZWM.js.map +0 -1
  87. package/dist/chunk-QPSOTK6M.js.map +0 -1
  88. package/dist/chunk-QZ6HNNFG.js.map +0 -1
  89. /package/dist/{domEditingLayers-3BAP6NNO.js.map → domEditingLayers-NU6Z5QWA.js.map} +0 -0
package/dist/ui.d.ts CHANGED
@@ -181,6 +181,8 @@ interface PopoverProps extends Omit<ComponentPropsWithoutRef<typeof Popover$1.Ro
181
181
  side?: "top" | "bottom" | "left" | "right";
182
182
  align?: "start" | "center" | "end";
183
183
  sideOffset?: number;
184
+ /** Points the popup at its trigger. Off by default; the default gap from the trigger grows by the arrow's height. */
185
+ arrow?: boolean;
184
186
  /** Portal target. Pass the shadow root when the trigger lives in one. */
185
187
  container?: PortalContainer;
186
188
  /** Names the popup for assistive tech. */
@@ -193,7 +195,7 @@ interface PopoverProps extends Omit<ComponentPropsWithoutRef<typeof Popover$1.Ro
193
195
  className?: string;
194
196
  "data-preview-state"?: PopupPreviewState;
195
197
  }
196
- declare function Popover({ trigger, children, side, align, sideOffset, container, className, initialFocus, "aria-label": ariaLabel, "data-preview-state": previewState, ...root }: PopoverProps): react_jsx_runtime.JSX.Element;
198
+ declare function Popover({ trigger, children, side, align, arrow, sideOffset, container, className, initialFocus, "aria-label": ariaLabel, "data-preview-state": previewState, ...root }: PopoverProps): react_jsx_runtime.JSX.Element;
197
199
 
198
200
  /**
199
201
  * Shared field look (also used by NumberField and Select). Each interactive state is written
package/dist/ui.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  fieldBase,
31
31
  fieldText,
32
32
  popupSurface
33
- } from "./chunk-QZ6HNNFG.js";
33
+ } from "./chunk-6GAO75IU.js";
34
34
  import "./chunk-PZ5AY32C.js";
35
35
  export {
36
36
  Button,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.8.96",
3
+ "version": "0.8.98",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,12 +60,12 @@
60
60
  "dockview-react": "8.3.1",
61
61
  "gsap": "^3.13.0",
62
62
  "mediabunny": "^1.45.3",
63
- "@hyperframes/core": "0.8.96",
64
- "@hyperframes/player": "0.8.96",
65
- "@hyperframes/parsers": "0.8.96",
66
- "@hyperframes/sdk": "0.8.96",
67
- "@hyperframes/studio-server": "0.8.96",
68
- "@hyperframes/shader-transitions": "0.8.96"
63
+ "@hyperframes/core": "0.8.98",
64
+ "@hyperframes/parsers": "0.8.98",
65
+ "@hyperframes/player": "0.8.98",
66
+ "@hyperframes/sdk": "0.8.98",
67
+ "@hyperframes/shader-transitions": "0.8.98",
68
+ "@hyperframes/studio-server": "0.8.98"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@tailwindcss/vite": "^4.3.3",
@@ -81,7 +81,7 @@
81
81
  "vite": "^6.4.2",
82
82
  "vitest": "^4.1.11",
83
83
  "zustand": "^5.0.0",
84
- "@hyperframes/producer": "0.8.96"
84
+ "@hyperframes/producer": "0.8.98"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "react": "19",
@@ -93,6 +93,7 @@
93
93
  "build": "vite build && tsup",
94
94
  "typecheck": "tsc --noEmit",
95
95
  "test": "vitest run",
96
+ "test:edit-accuracy": "bun tests/e2e/edit-accuracy/run.mjs",
96
97
  "test:webmcp-edit-loop": "node tests/e2e/webmcp-edit-loop.mjs",
97
98
  "test:timeline-virtualization": "TIMELINE_ROW_VIRTUALIZATION=on TIMELINE_ELEMENT_COUNT=50000 node tests/e2e/timeline-virtualization.mjs",
98
99
  "test:watch": "vitest",
@@ -18,6 +18,7 @@ import type { GestureRecordingState } from "./editor/GestureRecordControl";
18
18
  import { useTimelineSelectionPreviewSync } from "../hooks/useTimelineSelectionPreviewSync";
19
19
  import { StudioAgentTools } from "../webmcp/StudioAgentTools";
20
20
  import type { TimelineDropPlacement } from "../player/components/timelineCallbacks";
21
+ import type { TimelineProps } from "../player/components/TimelineTypes";
21
22
  import { Dock } from "./dock/Dock";
22
23
 
23
24
  type RenderClipContent = (
@@ -57,6 +58,7 @@ export interface EditorShellProps extends TimelineEditCallbackDeps {
57
58
  onPasteClip: () => Promise<void>;
58
59
  onDuplicateClip: () => Promise<boolean>;
59
60
  canPasteClip: () => boolean;
61
+ clipMenuItems?: TimelineProps["clipMenuItems"];
60
62
  setCompIdToSrc: (map: Map<string, string>) => void;
61
63
  setCompositionLoading: (loading: boolean) => void;
62
64
  shouldShowMotionPath: boolean;
@@ -105,6 +107,7 @@ export function EditorShell({
105
107
  onPasteClip,
106
108
  onDuplicateClip,
107
109
  canPasteClip,
110
+ clipMenuItems,
108
111
  setCompIdToSrc,
109
112
  setCompositionLoading,
110
113
  shouldShowMotionPath,
@@ -201,6 +204,7 @@ export function EditorShell({
201
204
  onPasteClip={onPasteClip}
202
205
  onDuplicateClip={onDuplicateClip}
203
206
  canPasteClip={canPasteClip}
207
+ clipMenuItems={clipMenuItems}
204
208
  previewOverlay={
205
209
  <PreviewOverlays
206
210
  shouldShowMotionPath={shouldShowMotionPath}
@@ -244,6 +248,7 @@ interface EditorShellBodyProps {
244
248
  onPasteClip: () => Promise<void>;
245
249
  onDuplicateClip: () => Promise<boolean>;
246
250
  canPasteClip: () => boolean;
251
+ clipMenuItems?: TimelineProps["clipMenuItems"];
247
252
  }
248
253
 
249
254
  function EditorShellBody({
@@ -264,6 +269,7 @@ function EditorShellBody({
264
269
  onPasteClip,
265
270
  onDuplicateClip,
266
271
  canPasteClip,
272
+ clipMenuItems,
267
273
  }: EditorShellBodyProps) {
268
274
  const { compositionStack, updateCompositionStack, containerRef } = useNLEContext();
269
275
 
@@ -316,6 +322,7 @@ function EditorShellBody({
316
322
  onPasteClip={onPasteClip}
317
323
  onDuplicateClip={onDuplicateClip}
318
324
  canPasteClip={canPasteClip}
325
+ clipMenuItems={clipMenuItems}
319
326
  onSelectTimelineElement={onSelectTimelineElement}
320
327
  timelineFooter={
321
328
  captionEditMode ? (
@@ -23,7 +23,7 @@ interface ToolRow {
23
23
  }
24
24
 
25
25
  /** One button for the active timeline tool; its menu switches tools or selects clips around the playhead. */
26
- export function TimelineToolPicker() {
26
+ export function TimelineToolPicker({ showSelectAroundPlayhead = true }) {
27
27
  const activeTool = usePlayerStore((s) => s.activeTool);
28
28
  const store = () => usePlayerStore.getState();
29
29
  const rows: ToolRow[] = [
@@ -41,21 +41,25 @@ export function TimelineToolPicker() {
41
41
  active: activeTool === "razor",
42
42
  run: () => store().setActiveTool("razor"),
43
43
  },
44
- {
45
- label: "Select leftward",
46
- shortcut: "[",
47
- icon: <ArrowLineLeft size={16} aria-hidden="true" />,
48
- active: false,
49
- run: () => store().selectLeftward(),
50
- },
51
- {
52
- label: "Select rightward",
53
- shortcut: "]",
54
- icon: <ArrowLineRight size={16} aria-hidden="true" />,
55
- active: false,
56
- run: () => store().selectRightward(),
57
- },
58
44
  ];
45
+ if (showSelectAroundPlayhead) {
46
+ rows.push(
47
+ {
48
+ label: "Select leftward",
49
+ shortcut: "[",
50
+ icon: <ArrowLineLeft size={16} aria-hidden="true" />,
51
+ active: false,
52
+ run: () => store().selectLeftward(),
53
+ },
54
+ {
55
+ label: "Select rightward",
56
+ shortcut: "]",
57
+ icon: <ArrowLineRight size={16} aria-hidden="true" />,
58
+ active: false,
59
+ run: () => store().selectRightward(),
60
+ },
61
+ );
62
+ }
59
63
  const current = rows.find((row) => row.active) ?? rows[0];
60
64
  return (
61
65
  <Menu
@@ -8,6 +8,7 @@ import { usePlayerStore } from "../player/store/playerStore";
8
8
  import { makeSelection } from "../hooks/domSelectionTestHarness";
9
9
  import { useAudioMetersVisible } from "../utils/audioMeterVisibility";
10
10
  import { readStudioUiPreferences } from "../utils/studioUiPreferences";
11
+ import { dispatchPlainKey, type HotkeyCallbacks } from "../hooks/appHotkeysDispatch";
11
12
  import { AudioMeterStrip } from "./nle/AudioMeterStrip";
12
13
  import { TimelineToolbar } from "./TimelineToolbar";
13
14
 
@@ -295,6 +296,67 @@ describe("TimelineToolbar history", () => {
295
296
  });
296
297
  });
297
298
 
299
+ describe("TimelineToolbar tool menu", () => {
300
+ async function openMenuRows(props: Partial<React.ComponentProps<typeof TimelineToolbar>>) {
301
+ const { host, root } = renderToolbar(undefined, props);
302
+ const trigger = host.querySelector<HTMLButtonElement>('button[aria-label^="Timeline tool:"]')!;
303
+ await act(async () => {
304
+ trigger.click();
305
+ await new Promise((resolve) => setTimeout(resolve, 0));
306
+ });
307
+ const rows = [...document.querySelectorAll('[role="menuitem"] > span:first-child')].map(
308
+ (label) => label.textContent,
309
+ );
310
+ act(() => root.unmount());
311
+ return rows;
312
+ }
313
+
314
+ it("lists Select, Split, Select leftward and Select rightward by default", async () => {
315
+ expect(await openMenuRows({})).toEqual([
316
+ "Select",
317
+ "Split",
318
+ "Select leftward",
319
+ "Select rightward",
320
+ ]);
321
+ });
322
+
323
+ it("lists only Select and Split when the host hides select around the playhead", async () => {
324
+ expect(await openMenuRows({ showSelectAroundPlayhead: false })).toEqual(["Select", "Split"]);
325
+ });
326
+
327
+ it.each([true, false])("[ and ] select around the playhead with the rows shown: %s", (shown) => {
328
+ usePlayerStore.setState({
329
+ currentTime: 4,
330
+ elements: [0, 4, 7].map((start, track) => ({
331
+ id: `c${start}`,
332
+ key: `c${start}`,
333
+ tag: "div",
334
+ start,
335
+ duration: 2,
336
+ track,
337
+ })),
338
+ });
339
+ const { root } = renderToolbar(undefined, { showSelectAroundPlayhead: shown });
340
+ const press = (key: string) =>
341
+ act(() =>
342
+ dispatchPlainKey(new KeyboardEvent("keydown", { key }), key, {} as HotkeyCallbacks),
343
+ );
344
+ try {
345
+ press("[");
346
+ expect([...usePlayerStore.getState().selectedElementIds]).toEqual(["c0"]);
347
+ press("]");
348
+ expect([...usePlayerStore.getState().selectedElementIds].sort()).toEqual(["c4", "c7"]);
349
+ } finally {
350
+ act(() => root.unmount());
351
+ usePlayerStore.setState({
352
+ elements: [],
353
+ selectedElementId: null,
354
+ selectedElementIds: new Set(),
355
+ });
356
+ }
357
+ });
358
+ });
359
+
298
360
  describe("TimelineToolbar add beat", () => {
299
361
  it("shows Add beat by default, as Studio does", () => {
300
362
  const { host, root } = renderToolbar();
@@ -44,6 +44,7 @@ export interface TimelineToolbarProps {
44
44
  onSplitElement?: (element: TimelineElement, splitTime: number) => void;
45
45
  history?: TimelineHistoryButtonsProps;
46
46
  showHistory?: boolean;
47
+ showSelectAroundPlayhead?: boolean;
47
48
  showAddBeat?: boolean;
48
49
  /** Hides Add keyframe and auto-record, and turns off auto-record and the K shortcut with them. */
49
50
  showKeyframes?: boolean;
@@ -143,6 +144,7 @@ export function TimelineToolbar({
143
144
  onSplitElement,
144
145
  history,
145
146
  showHistory = true,
147
+ showSelectAroundPlayhead = true,
146
148
  showAddBeat = true,
147
149
  showKeyframes = true,
148
150
  }: TimelineToolbarProps) {
@@ -216,7 +218,7 @@ export function TimelineToolbar({
216
218
  <div className="flex items-center justify-between px-2 py-0.5">
217
219
  <div className="flex items-center gap-0.5">
218
220
  {showHistory && <TimelineHistoryButtons {...history} />}
219
- <TimelineToolPicker />
221
+ <TimelineToolPicker showSelectAroundPlayhead={showSelectAroundPlayhead} />
220
222
  {/* Divider: tool-mode | editing-actions */}
221
223
  <div aria-hidden="true" className="mx-1 h-4 w-px bg-neutral-800" />
222
224
  <Tooltip label={timelineSnapEnabled ? "Snapping on (N)" : "Snapping off (N)"}>
@@ -161,8 +161,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
161
161
  const groupGestureRef = useRef<GroupGestureState | null>(null);
162
162
  const blockedMoveRef = useRef<BlockedMoveState | null>(null);
163
163
  const suppressNextBoxClickRef = useRef(false);
164
- const suppressNextBoxMouseDownRef = useRef(false);
165
- const suppressNextOverlayMouseDownRef = useRef(false);
166
164
  const snapGuidesRef = useRef<SnapGuidesState | null>(null);
167
165
  const rafPausedRef = useRef(false);
168
166
 
@@ -329,15 +327,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
329
327
 
330
328
  const handleOverlayMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
331
329
  if (!allowCanvasMovement) return;
332
- if (suppressNextOverlayMouseDownRef.current) {
333
- logSelect("mousedown-suppressed", { shift: event.shiftKey });
334
- suppressNextOverlayMouseDownRef.current = false;
335
- suppressNextBoxMouseDownRef.current = false;
336
- suppressNextBoxClickRef.current = false;
337
- event.preventDefault();
338
- event.stopPropagation();
339
- return;
340
- }
341
330
  const target = event.target as HTMLElement | null;
342
331
  const onBox = Boolean(target?.closest('[data-dom-edit-selection-box="true"]'));
343
332
  logSelect("mousedown", { shift: event.shiftKey, onBox });
@@ -346,10 +335,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
346
335
  // extend beyond the composition rect into the gray zone, and users need
347
336
  // to select/deselect them by clicking there.
348
337
  onCanvasMouseDown(event, { hoverSelection: hoverSelectionRef.current });
349
- if (event.shiftKey) {
350
- suppressNextBoxMouseDownRef.current = true;
351
- suppressNextBoxClickRef.current = true;
352
- }
353
338
  };
354
339
 
355
340
  // fallow-ignore-next-line complexity
@@ -373,8 +358,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
373
358
  if (!candidate) return;
374
359
  event.preventDefault();
375
360
  event.stopPropagation();
376
- suppressNextOverlayMouseDownRef.current = true;
377
- suppressNextBoxMouseDownRef.current = true;
378
361
  suppressNextBoxClickRef.current = true;
379
362
  onSelectionChangeRef.current(candidate, { additive: true });
380
363
  return;
@@ -419,7 +402,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
419
402
  // so those elements were always selectable once the band could begin.
420
403
  event.preventDefault();
421
404
  event.stopPropagation();
422
- suppressNextOverlayMouseDownRef.current = true;
423
405
  marquee.begin(event);
424
406
  return;
425
407
  }
@@ -437,13 +419,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
437
419
  onCanvasMouseDown(event, { hoverSelection: hoverSelectionRef.current });
438
420
  };
439
421
 
440
- const suppressBoxMouseDown = (e: React.MouseEvent) => {
441
- if (!suppressNextBoxMouseDownRef.current) return;
442
- suppressNextBoxMouseDownRef.current = false;
443
- e.preventDefault();
444
- e.stopPropagation();
445
- };
446
-
447
422
  // Right-click state + handler: select the element under the pointer (if
448
423
  // needed), then open the menu; closes when the selection moves off-target.
449
424
  const { contextMenu, closeContextMenu, handleContextMenu } = useCanvasContextMenuState({
@@ -509,7 +484,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
509
484
  allowBodyDrag={bodyDrag}
510
485
  groupCanMove={groupCanMove}
511
486
  gestures={gestures}
512
- onBoxMouseDown={suppressBoxMouseDown}
513
487
  onBoxClick={handleBoxClick}
514
488
  />
515
489
  )}
@@ -528,7 +502,6 @@ export const DomEditOverlay = memo(function DomEditOverlay({
528
502
  groupSelectionCount={groupSelections.length}
529
503
  gestures={gestures}
530
504
  onStyleCommit={onStyleCommitRef.current}
531
- onBoxMouseDown={suppressBoxMouseDown}
532
505
  onBoxClick={handleBoxClick}
533
506
  />
534
507
  )}
@@ -56,7 +56,6 @@ describe("DomEditSelectionChrome crop composition", () => {
56
56
  groupSelectionCount={0}
57
57
  gestures={{ startGesture: vi.fn() } as never}
58
58
  onStyleCommit={vi.fn()}
59
- onBoxMouseDown={vi.fn()}
60
59
  onBoxClick={vi.fn()}
61
60
  />,
62
61
  );
@@ -112,7 +111,6 @@ describe("DomEditSelectionChrome crop composition", () => {
112
111
  groupSelectionCount={0}
113
112
  gestures={{ startGesture: vi.fn() } as never}
114
113
  onStyleCommit={vi.fn()}
115
- onBoxMouseDown={vi.fn()}
116
114
  onBoxClick={vi.fn()}
117
115
  />,
118
116
  );
@@ -173,7 +171,6 @@ describe("DomEditSelectionChrome while editing text", () => {
173
171
  groupSelectionCount={0}
174
172
  gestures={{ startGesture: vi.fn() } as never}
175
173
  onStyleCommit={vi.fn()}
176
- onBoxMouseDown={vi.fn()}
177
174
  onBoxClick={vi.fn()}
178
175
  inlineText={{ editing, startFromPress: vi.fn() }}
179
176
  />,
@@ -258,7 +255,6 @@ describe("DomEditSelectionChrome with body drag off", () => {
258
255
  selectionKey="box"
259
256
  groupSelectionCount={0}
260
257
  gestures={gestures as never}
261
- onBoxMouseDown={vi.fn()}
262
258
  onBoxClick={vi.fn()}
263
259
  />,
264
260
  );
@@ -313,7 +309,6 @@ describe("DomEditSelectionChrome with body drag off", () => {
313
309
  allowBodyDrag={false}
314
310
  groupCanMove
315
311
  gestures={gestures as never}
316
- onBoxMouseDown={vi.fn()}
317
312
  onBoxClick={vi.fn()}
318
313
  />,
319
314
  );
@@ -62,7 +62,6 @@ interface DomEditGroupChromeProps {
62
62
  allowBodyDrag: boolean;
63
63
  groupCanMove: boolean;
64
64
  gestures: GestureHandlers;
65
- onBoxMouseDown: (e: React.MouseEvent) => void;
66
65
  onBoxClick: (event: React.MouseEvent<HTMLDivElement>) => void;
67
66
  }
68
67
 
@@ -75,7 +74,6 @@ export function DomEditGroupChrome({
75
74
  allowBodyDrag,
76
75
  groupCanMove,
77
76
  gestures,
78
- onBoxMouseDown,
79
77
  onBoxClick,
80
78
  }: DomEditGroupChromeProps) {
81
79
  const canManipulate = allowCanvasMovement && !usePreviewReadOnly();
@@ -108,7 +106,6 @@ export function DomEditGroupChrome({
108
106
  if (!canManipulate || !allowBodyDrag || (e.shiftKey && !groupCanMove)) return;
109
107
  gestures.startGroupDrag(e);
110
108
  }}
111
- onMouseDown={onBoxMouseDown}
112
109
  onClick={onBoxClick}
113
110
  />
114
111
  </>
@@ -128,7 +125,6 @@ interface DomEditSelectionChromeProps {
128
125
  groupSelectionCount: number;
129
126
  gestures: GestureHandlers;
130
127
  onStyleCommit?: (property: string, value: string) => Promise<unknown> | void;
131
- onBoxMouseDown: (e: React.MouseEvent) => void;
132
128
  onBoxClick: (event: React.MouseEvent<HTMLDivElement>) => void;
133
129
  /** The canvas' text-editing session: what opens one, and whether one is open. */
134
130
  inlineText?: {
@@ -157,7 +153,6 @@ export function DomEditSelectionChrome({
157
153
  groupSelectionCount,
158
154
  gestures,
159
155
  onStyleCommit,
160
- onBoxMouseDown,
161
156
  onBoxClick,
162
157
  inlineText,
163
158
  }: DomEditSelectionChromeProps) {
@@ -225,7 +220,6 @@ export function DomEditSelectionChrome({
225
220
  }
226
221
  if (!e.shiftKey) gestures.startBlockedMove(e, selection);
227
222
  }}
228
- onMouseDown={onBoxMouseDown}
229
223
  onClick={onBoxClick}
230
224
  >
231
225
  {cropOutlineInsetPx && (
@@ -0,0 +1,122 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import React, { act } from "react";
4
+ import { createRoot, type Root } from "react-dom/client";
5
+ import { afterEach, expect, it, vi } from "vitest";
6
+ import { makeSelection } from "../../hooks/domSelectionTestHarness";
7
+ import type { DomEditSelection } from "./domEditing";
8
+ import "./domEditOverlayTestMocks";
9
+ import { DomEditOverlay } from "./DomEditOverlay";
10
+
11
+ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
12
+ HTMLElement.prototype.setPointerCapture ??= () => {};
13
+ HTMLElement.prototype.releasePointerCapture ??= () => {};
14
+
15
+ const pointTarget = vi.hoisted(() => ({ current: null as HTMLElement | null }));
16
+ const rect = vi.hoisted(() => ({ current: null as Record<string, number> | null }));
17
+ vi.mock("../../utils/studioPreviewHelpers", async (importOriginal) => ({
18
+ ...(await importOriginal<typeof import("../../utils/studioPreviewHelpers")>()),
19
+ getPreviewTargetFromPointer: () => pointTarget.current,
20
+ }));
21
+ vi.mock("./useDomEditOverlayRects", () => ({
22
+ useDomEditOverlayRects: () => ({
23
+ overlayRect: rect.current,
24
+ overlayRectRef: rect,
25
+ setOverlayRect: () => undefined,
26
+ hoverRect: null,
27
+ groupOverlayItems: [],
28
+ groupOverlayItemsRef: { current: [] },
29
+ setGroupOverlayItems: () => undefined,
30
+ childRects: [],
31
+ }),
32
+ }));
33
+
34
+ let root: Root;
35
+ const onCanvasMouseDown = vi.fn();
36
+ const onSelectionChange = vi.fn();
37
+
38
+ function mount() {
39
+ const host = document.createElement("div");
40
+ document.body.append(host);
41
+ root = createRoot(host);
42
+ const element = document.createElement("h1");
43
+ document.body.append(element);
44
+ return { host, element, hover: makeSelection("Title", element) };
45
+ }
46
+
47
+ function render(
48
+ hoverSelection: DomEditSelection | null,
49
+ selection: DomEditSelection | null = null,
50
+ ) {
51
+ act(() =>
52
+ root.render(
53
+ <DomEditOverlay
54
+ iframeRef={{ current: document.createElement("iframe") }}
55
+ activeCompositionPath={null}
56
+ selection={selection}
57
+ hoverSelection={hoverSelection}
58
+ onCanvasMouseDown={onCanvasMouseDown}
59
+ onCanvasPointerMove={() => Promise.resolve(null)}
60
+ onCanvasPointerLeave={() => undefined}
61
+ onSelectionChange={onSelectionChange}
62
+ onBlockedMove={() => undefined}
63
+ onPathOffsetCommit={() => undefined}
64
+ onGroupPathOffsetCommit={() => undefined}
65
+ onBoxSizeCommit={() => undefined}
66
+ onRotationCommit={() => undefined}
67
+ onMarqueeSelect={() => undefined}
68
+ />,
69
+ ),
70
+ );
71
+ }
72
+
73
+ // Like Chrome: a default-prevented pointerdown sends no compatibility mousedown.
74
+ function press(target: Element, shiftKey = false) {
75
+ const init = { bubbles: true, cancelable: true, button: 0, pointerId: 1, shiftKey };
76
+ const down = new PointerEvent("pointerdown", init);
77
+ act(() => void target.dispatchEvent(down));
78
+ if (!down.defaultPrevented)
79
+ act(() => void target.dispatchEvent(new MouseEvent("mousedown", init)));
80
+ act(() => void target.dispatchEvent(new PointerEvent("pointerup", init)));
81
+ act(() => void target.dispatchEvent(new MouseEvent("click", init)));
82
+ }
83
+
84
+ afterEach(() => {
85
+ act(() => root.unmount());
86
+ onCanvasMouseDown.mockClear();
87
+ onSelectionChange.mockClear();
88
+ pointTarget.current = null;
89
+ rect.current = null;
90
+ document.body.innerHTML = "";
91
+ });
92
+
93
+ it.each([
94
+ ["a press on empty canvas", false],
95
+ ["a shift+click add", true],
96
+ ])("after %s, the next click on an element selects it", (_, shiftFirst) => {
97
+ const { host, element, hover } = mount();
98
+ const overlay = () => host.firstElementChild!;
99
+
100
+ pointTarget.current = shiftFirst ? element : null;
101
+ render(shiftFirst ? hover : null);
102
+ press(overlay(), shiftFirst);
103
+ expect(onCanvasMouseDown).not.toHaveBeenCalled();
104
+
105
+ pointTarget.current = element;
106
+ render(hover);
107
+ press(overlay());
108
+ expect(onCanvasMouseDown).toHaveBeenCalledTimes(1);
109
+ });
110
+
111
+ it("a shift+click on a selected box that cannot move toggles it once", () => {
112
+ const { host, element, hover } = mount();
113
+ hover.capabilities.canApplyManualOffset = false;
114
+ rect.current = { left: 20, top: 30, width: 100, height: 40, editScaleX: 1, editScaleY: 1 };
115
+ pointTarget.current = element;
116
+ render(hover, hover);
117
+
118
+ press(host.querySelector('[data-dom-edit-selection-box="true"]')!, true);
119
+
120
+ expect(onSelectionChange).toHaveBeenCalledTimes(1);
121
+ expect(onCanvasMouseDown).not.toHaveBeenCalled();
122
+ });
@@ -17,7 +17,7 @@ import {
17
17
  resolveDomEditCapabilities,
18
18
  resolveDomEditSelection,
19
19
  } from "./domEditing";
20
- import { normalizeTimelineCompositionSource } from "./domEditingDom";
20
+ import { buildElementLabel, normalizeTimelineCompositionSource } from "./domEditingDom";
21
21
 
22
22
  function createDocument(markup: string): Document {
23
23
  const window = new Window();
@@ -925,6 +925,14 @@ describe("resolveDomEditSelection", () => {
925
925
  );
926
926
  });
927
927
 
928
+ it("names a repeated section by its authored id, not its runtime instance id", () => {
929
+ const document = createDocument(`
930
+ <div data-composition-id="benefit-fresh__hf2" data-hf-original-composition-id="benefit-fresh"></div>
931
+ `);
932
+
933
+ expect(buildElementLabel(document.querySelector("div") as HTMLElement)).toBe("Benefit Fresh");
934
+ });
935
+
928
936
  it("finds a composition host authored with a ./ path", () => {
929
937
  const document = createDocument(`
930
938
  <div data-composition-id="scene" data-composition-file="./compositions/scene.html"></div>
@@ -312,7 +312,8 @@ function getPreferredClassSelector(el: HTMLElement): string | undefined {
312
312
 
313
313
  // fallow-ignore-next-line complexity
314
314
  export function buildElementLabel(el: HTMLElement): string {
315
- const compositionId = el.getAttribute("data-composition-id");
315
+ const compositionId =
316
+ el.getAttribute("data-hf-original-composition-id") ?? el.getAttribute("data-composition-id");
316
317
  if (compositionId && compositionId !== "main") {
317
318
  return humanizeIdentifier(compositionId);
318
319
  }
@@ -0,0 +1,69 @@
1
+ // @vitest-environment jsdom
2
+ import { expect, it } from "vitest";
3
+ import { ensureImportedFontFace, injectPreviewImportedFont } from "../../utils/studioFontHelpers";
4
+ import { importedFontFaceCss, type ImportedFontAsset } from "./fontAssets";
5
+
6
+ const face = (file: string, extra: Partial<ImportedFontAsset> = {}): ImportedFontAsset => ({
7
+ family: "Poppins",
8
+ path: `assets/fonts/Poppins/${file}`,
9
+ url: `/preview/assets/fonts/Poppins/${file}`,
10
+ ...extra,
11
+ });
12
+
13
+ it("a face with no weight or style is written as before", () => {
14
+ expect(importedFontFaceCss(face("Poppins-Bold.ttf"))).toBe(
15
+ '@font-face { font-family: "Poppins"; src: url("/preview/assets/fonts/Poppins/Poppins-Bold.ttf"); font-display: swap; }',
16
+ );
17
+ });
18
+
19
+ it("a face says which weight and style it draws, a variable file its weight range", () => {
20
+ expect(
21
+ importedFontFaceCss(face("Poppins-BoldItalic.ttf", { weight: "700", style: "italic" })),
22
+ ).toBe(
23
+ '@font-face { font-family: "Poppins"; src: url("/preview/assets/fonts/Poppins/Poppins-BoldItalic.ttf"); font-weight: 700; font-style: italic; font-display: swap; }',
24
+ );
25
+ expect(
26
+ importedFontFaceCss(face("Roboto-Variable.ttf", { weight: "100 900", style: "normal" })),
27
+ ).toContain("font-weight: 100 900; font-style: normal;");
28
+ expect(importedFontFaceCss(face("x.ttf", { weight: "700; color: red" }))).not.toContain(
29
+ "font-weight",
30
+ );
31
+ });
32
+
33
+ it("two weights of one family are both kept in the file and both drawn in the preview", () => {
34
+ const bold = face("Poppins-Bold.ttf", { weight: "700", style: "normal" });
35
+ const regular = face("Poppins-Regular.ttf", { weight: "400", style: "normal" });
36
+ const html = "<html><head></head><body></body></html>";
37
+ const saved = ensureImportedFontFace(
38
+ ensureImportedFontFace(html, bold, "index.html"),
39
+ regular,
40
+ "index.html",
41
+ );
42
+ expect(saved).toContain("font-weight: 700;");
43
+ expect(saved).toContain("font-weight: 400;");
44
+ expect(ensureImportedFontFace(saved, bold, "index.html")).toBe(saved);
45
+ injectPreviewImportedFont(document, bold);
46
+ injectPreviewImportedFont(document, regular);
47
+ injectPreviewImportedFont(document, bold);
48
+ expect(document.head.querySelectorAll("style")).toHaveLength(2);
49
+ });
50
+
51
+ it("a weight the browser would drop is left out, and a family cannot close the style block", () => {
52
+ for (const weight of ["0", "5000", "bold", "700;}"])
53
+ expect(importedFontFaceCss(face("x.ttf", { weight }))).not.toContain("font-weight");
54
+ expect(importedFontFaceCss(face("x.ttf", { weight: "1000" }))).toContain("font-weight: 1000;");
55
+ expect(importedFontFaceCss({ ...face("x.ttf"), family: "</style><b>x" })).not.toContain(
56
+ "</style>",
57
+ );
58
+ });
59
+
60
+ it("a file name with a replacement pattern is saved as written, not expanded into the page", () => {
61
+ const html = "<html><head></head><body>rest</body></html>";
62
+ const odd = { family: "Cash", path: "assets/Cash$'Font.ttf", url: "/Cash$'Font.ttf" };
63
+ const saved = ensureImportedFontFace(html, odd, "index.html");
64
+ expect(saved).toContain("Cash$'Font.ttf");
65
+ expect(saved.match(/<body>/g)).toHaveLength(1);
66
+ const again = ensureImportedFontFace(saved, { ...odd, path: "assets/Cash$&.ttf" }, "index.html");
67
+ expect(again).toContain("Cash$&.ttf");
68
+ expect(again.match(/<body>/g)).toHaveLength(1);
69
+ });