@hyperframes/studio 0.8.107 → 0.8.108
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.
- package/dist/assets/{hyperframes-player-h4mktSdm.js → hyperframes-player-BakGew45.js} +1 -1
- package/dist/assets/{index-D8GKc2D9.js → index-C5dyUHwk.js} +1 -1
- package/dist/assets/{index-CM1xA_jD.js → index-C842tcVa.js} +165 -165
- package/dist/assets/{index-zoqPmBF6.js → index-CPe7d_wO.js} +1 -1
- package/dist/assets/{index-lrT-gfHa.css → index-ncVJ5IVu.css} +1 -1
- package/dist/chunk-6LUNLTHR.js +611 -0
- package/dist/chunk-6LUNLTHR.js.map +1 -0
- package/dist/{chunk-4OZC426H.js → chunk-AOWVEVEU.js} +3 -503
- package/dist/chunk-AOWVEVEU.js.map +1 -0
- package/dist/{chunk-46XP7J3B.js → chunk-PQFEBX32.js} +5 -3
- package/dist/chunk-PQFEBX32.js.map +1 -0
- package/dist/{domEditingLayers-AQBDFNUC.js → domEditingLayers-JQPQGGT7.js} +3 -3
- package/dist/index.d.ts +11 -2
- package/dist/index.html +2 -2
- package/dist/index.js +12416 -11195
- package/dist/index.js.map +1 -1
- package/dist/player.js +2 -2
- package/dist/styles.css +1 -1
- package/package.json +8 -8
- package/src/App.tsx +1 -0
- package/src/components/EditorShell.tsx +2 -0
- package/src/components/editor/CropPresetBar.tsx +69 -0
- package/src/components/editor/DomEditCropHandles.test.tsx +44 -0
- package/src/components/editor/DomEditCropHandles.tsx +123 -95
- package/src/components/editor/carveOutput.ts +54 -0
- package/src/components/editor/cropPresetStore.ts +33 -0
- package/src/components/editor/cropPresets.test.ts +41 -0
- package/src/components/editor/cropPresets.ts +24 -0
- package/src/components/editor/domEditingLayers.test.ts +21 -0
- package/src/components/editor/domEditingLayers.ts +2 -0
- package/src/components/editor/dragUndoPaint.test.ts +71 -0
- package/src/components/editor/manualOffsetDrag.ts +11 -0
- package/src/components/editor/mediaAudioEdits.test.ts +59 -0
- package/src/components/editor/mediaAudioEdits.ts +40 -11
- package/src/components/editor/propertyPanelAudioFxGroup.test.tsx +32 -4
- package/src/components/editor/propertyPanelAudioFxGroup.tsx +3 -1
- package/src/components/editor/propertyPanelFlatMediaSection.test.tsx +7 -3
- package/src/components/editor/useDomEditNudge.ts +17 -12
- package/src/components/editor/useDomEditOverlayGestures.ts +17 -6
- package/src/components/editor/useFxCarve.ts +3 -61
- package/src/components/editor/useFxCarveGrouping.test.ts +13 -0
- package/src/components/editor/useFxCarveGrouping.ts +8 -3
- package/src/components/nle/AudioMeterStrip.test.tsx +53 -0
- package/src/components/nle/AudioMeterStrip.tsx +60 -2
- package/src/components/nle/useTimelineEditCallbacks.ts +4 -0
- package/src/contexts/TimelineEditContext.tsx +1 -0
- package/src/hooks/useEditHistoryActions.paint.test.tsx +41 -0
- package/src/hooks/useEditHistoryActions.ts +13 -4
- package/src/hooks/useElementPicker.test.ts +62 -13
- package/src/hooks/useElementPicker.ts +10 -2
- package/src/hooks/useFreezeFrame.test.ts +56 -0
- package/src/hooks/useFreezeFrame.ts +121 -0
- package/src/hooks/usePersistentEditHistory.test.ts +9 -6
- package/src/hooks/usePersistentEditHistory.ts +1 -1
- package/src/hooks/useRazorSplit.ts +14 -1
- package/src/hooks/useRenderClipContent.test.ts +102 -0
- package/src/hooks/useRenderClipContent.ts +30 -23
- package/src/hooks/useTimelineEditing.ts +2 -2
- package/src/index.ts +1 -0
- package/src/player/components/AudibleVideoClipContent.tsx +29 -0
- package/src/player/components/ClipBadges.test.tsx +82 -0
- package/src/player/components/ClipBadges.tsx +67 -0
- package/src/player/components/ClipContextMenu.tsx +22 -0
- package/src/player/components/ClipPeakMarks.test.tsx +41 -0
- package/src/player/components/ClipPeakMarks.tsx +71 -0
- package/src/player/components/TimelineClip.tsx +2 -0
- package/src/player/components/TimelineFxButton.test.tsx +2 -2
- package/src/player/components/TimelineTrackHeader.test.tsx +37 -0
- package/src/player/components/TimelineTrackHeader.tsx +12 -25
- package/src/player/components/clipMenuAudioItems.test.tsx +125 -0
- package/src/player/components/clipMenuAudioItems.tsx +108 -0
- package/src/player/components/clipMenuDuck.test.ts +117 -0
- package/src/player/components/clipMenuDuck.ts +142 -0
- package/src/player/components/clipMenuNormalize.test.ts +95 -0
- package/src/player/components/clipMenuNormalize.ts +96 -0
- package/src/player/components/clipMenuToolItems.test.tsx +139 -0
- package/src/player/components/clipMenuToolItems.tsx +235 -0
- package/src/player/components/clipPeakRuns.test.ts +38 -0
- package/src/player/components/clipPeakRuns.ts +59 -0
- package/src/player/components/clipToolAttrs.test.ts +161 -0
- package/src/player/components/clipToolAttrs.ts +187 -0
- package/src/player/components/timelineCallbacks.ts +1 -0
- package/src/player/components/useClipToolState.ts +92 -0
- package/src/player/lib/timelineElementHelpers.ts +9 -0
- package/src/timelineChromeExports.test.tsx +7 -0
- package/src/utils/audioMeterMath.test.ts +37 -0
- package/src/utils/audioMeterMath.ts +9 -3
- package/src/utils/exportPeakCeiling.ts +1 -0
- package/src/utils/previewRelativePath.ts +19 -0
- package/src/utils/sourcePatcher.ts +1 -1
- package/src/utils/studioPendingEdits.test.ts +66 -0
- package/src/utils/studioPendingEdits.ts +45 -11
- package/src/utils/timelineInspector.test.ts +33 -2
- package/src/utils/timelineInspector.ts +16 -4
- package/dist/chunk-46XP7J3B.js.map +0 -1
- package/dist/chunk-4OZC426H.js.map +0 -1
- package/dist/chunk-DI4LCJHL.js +0 -102
- package/dist/chunk-DI4LCJHL.js.map +0 -1
- /package/dist/{domEditingLayers-AQBDFNUC.js.map → domEditingLayers-JQPQGGT7.js.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.108",
|
|
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/
|
|
64
|
-
"@hyperframes/
|
|
65
|
-
"@hyperframes/
|
|
66
|
-
"@hyperframes/
|
|
67
|
-
"@hyperframes/studio-server": "0.8.
|
|
68
|
-
"@hyperframes/
|
|
63
|
+
"@hyperframes/core": "0.8.108",
|
|
64
|
+
"@hyperframes/parsers": "0.8.108",
|
|
65
|
+
"@hyperframes/player": "0.8.108",
|
|
66
|
+
"@hyperframes/sdk": "0.8.108",
|
|
67
|
+
"@hyperframes/studio-server": "0.8.108",
|
|
68
|
+
"@hyperframes/shader-transitions": "0.8.108"
|
|
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.
|
|
84
|
+
"@hyperframes/producer": "0.8.108"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"react": "19",
|
package/src/App.tsx
CHANGED
|
@@ -552,6 +552,7 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: St
|
|
|
552
552
|
handleTimelineElementSplit={timelineEditing.handleTimelineElementSplit}
|
|
553
553
|
handleRazorSplit={timelineEditing.handleRazorSplit}
|
|
554
554
|
handleRazorSplitAll={timelineEditing.handleRazorSplitAll}
|
|
555
|
+
handleFreezeFrame={timelineEditing.handleFreezeFrame}
|
|
555
556
|
onCopyClip={handleCopy}
|
|
556
557
|
onPasteClip={handlePaste}
|
|
557
558
|
onDuplicateClip={handleDuplicate}
|
|
@@ -103,6 +103,7 @@ export function EditorShell({
|
|
|
103
103
|
handleTimelineElementSplit,
|
|
104
104
|
handleRazorSplit,
|
|
105
105
|
handleRazorSplitAll,
|
|
106
|
+
handleFreezeFrame,
|
|
106
107
|
onCopyClip,
|
|
107
108
|
onPasteClip,
|
|
108
109
|
onDuplicateClip,
|
|
@@ -163,6 +164,7 @@ export function EditorShell({
|
|
|
163
164
|
handleTimelineElementSplit,
|
|
164
165
|
handleRazorSplit,
|
|
165
166
|
handleRazorSplitAll,
|
|
167
|
+
handleFreezeFrame,
|
|
166
168
|
});
|
|
167
169
|
|
|
168
170
|
return (
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import type { ClipPathInsetSides } from "./clipPathHelpers";
|
|
3
|
+
import { CROP_ASPECT_PRESETS, centredCropInsets } from "./cropPresets";
|
|
4
|
+
|
|
5
|
+
interface CropPresetBarProps {
|
|
6
|
+
left: number;
|
|
7
|
+
top: number;
|
|
8
|
+
elementWidth: number;
|
|
9
|
+
elementHeight: number;
|
|
10
|
+
/** Centred insets for a ratio, or `null` to remove the crop. */
|
|
11
|
+
onApply: (insets: ClipPathInsetSides | null) => void;
|
|
12
|
+
onDone: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CHIP =
|
|
16
|
+
"rounded-sm border border-white/20 px-1.5 py-0.5 text-[10px] text-white/85 hover:bg-white/10";
|
|
17
|
+
|
|
18
|
+
/** Free · aspect presets · Reset · Done, floating above the element being cropped. */
|
|
19
|
+
export function CropPresetBar({
|
|
20
|
+
left,
|
|
21
|
+
top,
|
|
22
|
+
elementWidth,
|
|
23
|
+
elementHeight,
|
|
24
|
+
onApply,
|
|
25
|
+
onDone,
|
|
26
|
+
}: CropPresetBarProps) {
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
29
|
+
if (event.key === "Escape") onDone();
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener("keydown", onKeyDown);
|
|
32
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
33
|
+
}, [onDone]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
role="toolbar"
|
|
38
|
+
aria-label="Crop presets"
|
|
39
|
+
data-dom-edit-crop-bar="true"
|
|
40
|
+
className="pointer-events-auto absolute z-20 flex gap-1 rounded-md border border-white/15 bg-neutral-900/95 p-1 shadow-lg"
|
|
41
|
+
style={{ left, top: Math.max(4, top - 34), transform: "translateX(-50%)" }}
|
|
42
|
+
onPointerDown={(event) => event.stopPropagation()}
|
|
43
|
+
>
|
|
44
|
+
<button type="button" className={CHIP} title="Drag the edges freely">
|
|
45
|
+
Free
|
|
46
|
+
</button>
|
|
47
|
+
{CROP_ASPECT_PRESETS.map((preset) => (
|
|
48
|
+
<button
|
|
49
|
+
key={preset.label}
|
|
50
|
+
type="button"
|
|
51
|
+
className={CHIP}
|
|
52
|
+
onClick={() => onApply(centredCropInsets(elementWidth, elementHeight, preset.ratio))}
|
|
53
|
+
>
|
|
54
|
+
{preset.label}
|
|
55
|
+
</button>
|
|
56
|
+
))}
|
|
57
|
+
<button type="button" className={CHIP} onClick={() => onApply(null)}>
|
|
58
|
+
Reset
|
|
59
|
+
</button>
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
className="rounded-sm border border-studio-accent bg-studio-accent px-1.5 py-0.5 text-[10px] font-semibold text-black"
|
|
63
|
+
onClick={onDone}
|
|
64
|
+
>
|
|
65
|
+
Done
|
|
66
|
+
</button>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -6,6 +6,7 @@ import type { DomEditSelection } from "./domEditing";
|
|
|
6
6
|
import type { OverlayRect } from "./domEditOverlayGeometry";
|
|
7
7
|
import { DomEditCropHandles } from "./DomEditCropHandles";
|
|
8
8
|
import { isElementCropLifted } from "./domEditOverlayCrop";
|
|
9
|
+
import { useCropPresetBarStore } from "./cropPresetStore";
|
|
9
10
|
|
|
10
11
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
11
12
|
|
|
@@ -272,3 +273,46 @@ describe("DomEditCropHandles leaves the corner resize dots free", () => {
|
|
|
272
273
|
expect(handles().map((h) => h.label)).toEqual(["Crop top", "Crop bottom"]);
|
|
273
274
|
});
|
|
274
275
|
});
|
|
276
|
+
|
|
277
|
+
describe("DomEditCropHandles preset bar", () => {
|
|
278
|
+
const click = (label: string) => {
|
|
279
|
+
const button = Array.from(document.querySelectorAll<HTMLButtonElement>("button")).find(
|
|
280
|
+
(b) => b.textContent === label,
|
|
281
|
+
);
|
|
282
|
+
act(() => button?.click());
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
afterEach(() => useCropPresetBarStore.getState().close());
|
|
286
|
+
|
|
287
|
+
it("shows only for the clip the menu opened it for", () => {
|
|
288
|
+
const a = makeEl("a", "");
|
|
289
|
+
useCropPresetBarStore.getState().open({ id: "other" });
|
|
290
|
+
render(a);
|
|
291
|
+
expect(document.querySelector("[data-dom-edit-crop-bar]")).toBeNull();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("commits a centred 1:1 crop, then Reset removes the clip-path", async () => {
|
|
295
|
+
const a = makeEl("a", "");
|
|
296
|
+
const commits: string[] = [];
|
|
297
|
+
useCropPresetBarStore.getState().open({ id: "a" });
|
|
298
|
+
const { root } = render(a, (_property, value) => {
|
|
299
|
+
commits.push(value);
|
|
300
|
+
});
|
|
301
|
+
click("1:1");
|
|
302
|
+
await act(async () => {});
|
|
303
|
+
expect(commits[0]).toBe("inset(0px 50px 0px 50px)");
|
|
304
|
+
click("Reset");
|
|
305
|
+
await act(async () => {});
|
|
306
|
+
expect(commits[1]).toBe("");
|
|
307
|
+
act(() => root.unmount());
|
|
308
|
+
expect(a.style.getPropertyValue("clip-path")).toBe("");
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("Done closes the bar", () => {
|
|
312
|
+
const a = makeEl("a", "");
|
|
313
|
+
useCropPresetBarStore.getState().open({ id: "a" });
|
|
314
|
+
render(a);
|
|
315
|
+
click("Done");
|
|
316
|
+
expect(useCropPresetBarStore.getState().openFor).toBeNull();
|
|
317
|
+
});
|
|
318
|
+
});
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
} from "./domEditOverlayCrop";
|
|
16
16
|
import { buildInsetClipPathSides, type ClipPathInsetSides } from "./clipPathHelpers";
|
|
17
17
|
import { readCropFollowingResize } from "./cropResize";
|
|
18
|
+
import { isCropBarTarget, useCropPresetBarStore } from "./cropPresetStore";
|
|
19
|
+
import { CropPresetBar } from "./CropPresetBar";
|
|
18
20
|
|
|
19
21
|
interface CropGestureState {
|
|
20
22
|
edge: CropEdge | "move";
|
|
@@ -119,6 +121,9 @@ export function DomEditCropHandles({
|
|
|
119
121
|
return { element, croppable: parsed !== null, insets: { top, right, bottom, left } };
|
|
120
122
|
};
|
|
121
123
|
const [state, setState] = useState(() => cropStateFor(selection.element));
|
|
124
|
+
const presetBarTarget = useCropPresetBarStore((s) => s.openFor);
|
|
125
|
+
const closePresetBar = useCropPresetBarStore((s) => s.close);
|
|
126
|
+
const showPresetBar = isCropBarTarget(selection.element, presetBarTarget);
|
|
122
127
|
|
|
123
128
|
// Re-sync when the selection targets a different element (reselect, or an
|
|
124
129
|
// undo/redo that re-keys the node).
|
|
@@ -223,10 +228,21 @@ export function DomEditCropHandles({
|
|
|
223
228
|
// the lift keeps it hidden while selected. A drag that ends where it started saves nothing.
|
|
224
229
|
const value = buildInsetClipPathSides(gesture.insets, gesture.radius);
|
|
225
230
|
if (value === buildInsetClipPathSides(gesture.startInsets, gesture.radius)) return;
|
|
231
|
+
commitClipPath(value);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const commitClipPath = (value: string) => {
|
|
226
235
|
const commit = onStyleCommit?.("clip-path", value);
|
|
227
236
|
void Promise.resolve(commit).catch(() => undefined);
|
|
228
237
|
};
|
|
229
238
|
|
|
239
|
+
const applyPresetInsets = (insets: ClipPathInsetSides | null) => {
|
|
240
|
+
const next = insets ?? { top: 0, right: 0, bottom: 0, left: 0 };
|
|
241
|
+
setState((prev) => ({ ...prev, insets: next }));
|
|
242
|
+
const radius = readCropFollowingResize(selection.element)?.radius ?? 0;
|
|
243
|
+
commitClipPath(insets === null ? "" : buildInsetClipPathSides(next, radius));
|
|
244
|
+
};
|
|
245
|
+
|
|
230
246
|
const cancelCropGesture = (event: ReactPointerEvent<HTMLElement>) => {
|
|
231
247
|
const gesture = endCropGesture(event);
|
|
232
248
|
if (!gesture) return;
|
|
@@ -239,119 +255,131 @@ export function DomEditCropHandles({
|
|
|
239
255
|
if (!state.croppable) return null;
|
|
240
256
|
|
|
241
257
|
return (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
>
|
|
253
|
-
{/* Dim the cropped-away area whenever the element is cropped and selected,
|
|
254
|
-
so the hidden content is visible (ghosted) without dragging. Clipped to
|
|
255
|
-
the element's own (rotated) box. */}
|
|
256
|
-
{hasCrop && (
|
|
257
|
-
<div className="pointer-events-none absolute inset-0 overflow-hidden">
|
|
258
|
-
<div
|
|
259
|
-
className="absolute"
|
|
260
|
-
style={{
|
|
261
|
-
left: cropRect.left,
|
|
262
|
-
top: cropRect.top,
|
|
263
|
-
width: cropRect.width,
|
|
264
|
-
height: cropRect.height,
|
|
265
|
-
boxShadow: "0 0 0 100000px rgba(8, 8, 12, 0.6)",
|
|
266
|
-
}}
|
|
267
|
-
/>
|
|
268
|
-
</div>
|
|
258
|
+
<>
|
|
259
|
+
{showPresetBar && onStyleCommit && (
|
|
260
|
+
<CropPresetBar
|
|
261
|
+
left={frame.left + frame.width / 2}
|
|
262
|
+
top={frame.top}
|
|
263
|
+
elementWidth={width}
|
|
264
|
+
elementHeight={height}
|
|
265
|
+
onApply={applyPresetInsets}
|
|
266
|
+
onDone={closePresetBar}
|
|
267
|
+
/>
|
|
269
268
|
)}
|
|
270
|
-
{/* Dashed clip outline on the crop boundary, with a rule-of-thirds grid
|
|
271
|
-
shown while dragging. */}
|
|
272
269
|
<div
|
|
273
|
-
|
|
274
|
-
className="pointer-events-none absolute
|
|
270
|
+
data-dom-edit-crop-frame="true"
|
|
271
|
+
className="pointer-events-none absolute"
|
|
275
272
|
style={{
|
|
276
|
-
left:
|
|
277
|
-
top:
|
|
278
|
-
width:
|
|
279
|
-
height:
|
|
273
|
+
left: frame.left,
|
|
274
|
+
top: frame.top,
|
|
275
|
+
width: frame.width,
|
|
276
|
+
height: frame.height,
|
|
277
|
+
transform: frame.angleDeg !== 0 ? `rotate(${frame.angleDeg}deg)` : undefined,
|
|
280
278
|
}}
|
|
281
279
|
>
|
|
282
|
-
{
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
<div
|
|
288
|
-
|
|
280
|
+
{/* Dim the cropped-away area whenever the element is cropped and selected,
|
|
281
|
+
so the hidden content is visible (ghosted) without dragging. Clipped to
|
|
282
|
+
the element's own (rotated) box. */}
|
|
283
|
+
{hasCrop && (
|
|
284
|
+
<div className="pointer-events-none absolute inset-0 overflow-hidden">
|
|
285
|
+
<div
|
|
286
|
+
className="absolute"
|
|
287
|
+
style={{
|
|
288
|
+
left: cropRect.left,
|
|
289
|
+
top: cropRect.top,
|
|
290
|
+
width: cropRect.width,
|
|
291
|
+
height: cropRect.height,
|
|
292
|
+
boxShadow: "0 0 0 100000px rgba(8, 8, 12, 0.6)",
|
|
293
|
+
}}
|
|
294
|
+
/>
|
|
295
|
+
</div>
|
|
289
296
|
)}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
<button
|
|
296
|
-
type="button"
|
|
297
|
-
aria-label="Reposition crop"
|
|
298
|
-
title="Reposition crop"
|
|
299
|
-
data-dom-edit-crop-handle="true"
|
|
300
|
-
className="pointer-events-auto absolute rounded-full border-2 border-studio-accent bg-studio-accent/30 shadow-[0_0_0_1px_rgba(0,0,0,0.4)]"
|
|
297
|
+
{/* Dashed clip outline on the crop boundary, with a rule-of-thirds grid
|
|
298
|
+
shown while dragging. */}
|
|
299
|
+
<div
|
|
300
|
+
aria-hidden="true"
|
|
301
|
+
className="pointer-events-none absolute border border-dashed border-studio-accent"
|
|
301
302
|
style={{
|
|
302
|
-
left: cropRect.left
|
|
303
|
-
top: cropRect.top
|
|
304
|
-
width:
|
|
305
|
-
height:
|
|
306
|
-
cursor: "move",
|
|
307
|
-
touchAction: "none",
|
|
303
|
+
left: cropRect.left,
|
|
304
|
+
top: cropRect.top,
|
|
305
|
+
width: cropRect.width,
|
|
306
|
+
height: cropRect.height,
|
|
308
307
|
}}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (!layout) return null;
|
|
324
|
-
const revealed = dragging || hasCrop || hotEdge === edge;
|
|
325
|
-
return (
|
|
308
|
+
>
|
|
309
|
+
{dragging && (
|
|
310
|
+
<>
|
|
311
|
+
<div className="absolute inset-y-0 left-1/3 w-px bg-studio-accent/40" />
|
|
312
|
+
<div className="absolute inset-y-0 left-2/3 w-px bg-studio-accent/40" />
|
|
313
|
+
<div className="absolute inset-x-0 top-1/3 h-px bg-studio-accent/40" />
|
|
314
|
+
<div className="absolute inset-x-0 top-2/3 h-px bg-studio-accent/40" />
|
|
315
|
+
</>
|
|
316
|
+
)}
|
|
317
|
+
</div>
|
|
318
|
+
{/* Reposition handle — a center circle shown only once cropped. Drag it to
|
|
319
|
+
pan the crop window (which part of the element shows) without resizing
|
|
320
|
+
the crop. It's a small, discrete target, so a body drag still MOVES. */}
|
|
321
|
+
{hasCrop && repositionSize > 0 && (
|
|
326
322
|
<button
|
|
327
|
-
key={edge}
|
|
328
323
|
type="button"
|
|
329
|
-
aria-label=
|
|
330
|
-
title="
|
|
324
|
+
aria-label="Reposition crop"
|
|
325
|
+
title="Reposition crop"
|
|
331
326
|
data-dom-edit-crop-handle="true"
|
|
332
|
-
className="pointer-events-auto absolute
|
|
327
|
+
className="pointer-events-auto absolute rounded-full border-2 border-studio-accent bg-studio-accent/30 shadow-[0_0_0_1px_rgba(0,0,0,0.4)]"
|
|
333
328
|
style={{
|
|
334
|
-
|
|
335
|
-
|
|
329
|
+
left: cropRect.left + (cropRect.width - repositionSize) / 2,
|
|
330
|
+
top: cropRect.top + (cropRect.height - repositionSize) / 2,
|
|
331
|
+
width: repositionSize,
|
|
332
|
+
height: repositionSize,
|
|
333
|
+
cursor: "move",
|
|
336
334
|
touchAction: "none",
|
|
337
335
|
}}
|
|
338
|
-
|
|
339
|
-
onPointerLeave={() => setHotEdge((prev) => (prev === edge ? null : prev))}
|
|
340
|
-
onPointerDown={(event) => startCropGesture(edge, event)}
|
|
336
|
+
onPointerDown={(event) => startCropGesture("move", event)}
|
|
341
337
|
onPointerMove={updateCropGesture}
|
|
342
338
|
onPointerUp={finishCropGesture}
|
|
343
339
|
onPointerCancel={cancelCropGesture}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
340
|
+
/>
|
|
341
|
+
)}
|
|
342
|
+
{/* Edge handles — drag a side to crop it. Positioned just OUTSIDE the crop
|
|
343
|
+
edge (via edgeHandleLayout) so they never overlap the element body:
|
|
344
|
+
dragging the body always MOVES, only a handle crops. The pill is
|
|
345
|
+
hover-revealed (or shown while dragging / once a crop exists) so the
|
|
346
|
+
resting selection chrome stays uncluttered; the hit strip is always
|
|
347
|
+
live, and the title names the affordance. */}
|
|
348
|
+
{EDGES.map((edge) => {
|
|
349
|
+
const layout = edgeHandleLayout(edge, cropRect);
|
|
350
|
+
if (!layout) return null;
|
|
351
|
+
const revealed = dragging || hasCrop || hotEdge === edge;
|
|
352
|
+
return (
|
|
353
|
+
<button
|
|
354
|
+
key={edge}
|
|
355
|
+
type="button"
|
|
356
|
+
aria-label={`Crop ${edge}`}
|
|
357
|
+
title="Crop"
|
|
358
|
+
data-dom-edit-crop-handle="true"
|
|
359
|
+
className="pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0"
|
|
347
360
|
style={{
|
|
348
|
-
...layout.
|
|
349
|
-
|
|
361
|
+
...layout.hit,
|
|
362
|
+
cursor: layout.cursor,
|
|
363
|
+
touchAction: "none",
|
|
350
364
|
}}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
365
|
+
onPointerEnter={() => setHotEdge(edge)}
|
|
366
|
+
onPointerLeave={() => setHotEdge((prev) => (prev === edge ? null : prev))}
|
|
367
|
+
onPointerDown={(event) => startCropGesture(edge, event)}
|
|
368
|
+
onPointerMove={updateCropGesture}
|
|
369
|
+
onPointerUp={finishCropGesture}
|
|
370
|
+
onPointerCancel={cancelCropGesture}
|
|
371
|
+
>
|
|
372
|
+
<span
|
|
373
|
+
className="pointer-events-none rounded-full bg-studio-accent/90 shadow-[0_0_0_1px_rgba(0,0,0,0.4)] transition-opacity duration-100"
|
|
374
|
+
style={{
|
|
375
|
+
...layout.pill,
|
|
376
|
+
opacity: revealed ? 1 : 0,
|
|
377
|
+
}}
|
|
378
|
+
/>
|
|
379
|
+
</button>
|
|
380
|
+
);
|
|
381
|
+
})}
|
|
382
|
+
</div>
|
|
383
|
+
</>
|
|
356
384
|
);
|
|
357
385
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HF_AUDIO_FX_ATTR,
|
|
3
|
+
serializeAudioFxChain,
|
|
4
|
+
type HfAudioFxChain,
|
|
5
|
+
} from "@hyperframes/core/audio-fx";
|
|
6
|
+
import { type HfAutomation } from "@hyperframes/core/audio-automation";
|
|
7
|
+
import { isCarveVoiceElement } from "./useFxCarveGrouping.js";
|
|
8
|
+
import { automationAttrValue, HF_AUDIO_AUTOMATION_ATTR } from "./propertyPanelAutomation";
|
|
9
|
+
import type { CarveClip } from "./useFxCarveNodes.js";
|
|
10
|
+
import { readClipClock } from "./clipAudioClock.js";
|
|
11
|
+
|
|
12
|
+
/** Lanes belonging to nodes the carve generated, which a re-run replaces. */
|
|
13
|
+
export function withoutCarveLanes(automation: HfAutomation, chain: HfAudioFxChain): HfAutomation {
|
|
14
|
+
const prefixes = chain.nodes.filter((n) => n.fromCarve && n.id).map((n) => `fx.${n.id}.`);
|
|
15
|
+
if (prefixes.length === 0) return automation;
|
|
16
|
+
return {
|
|
17
|
+
version: automation.version,
|
|
18
|
+
lanes: automation.lanes.filter((lane) => !prefixes.some((p) => lane.target.startsWith(p))),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Every named voice still present with a src; a deleted source is skipped, not fatal. */
|
|
23
|
+
export function resolveCarveVoices(doc: Document, sources: readonly string[]): CarveClip[] {
|
|
24
|
+
const voices: CarveClip[] = [];
|
|
25
|
+
for (const id of sources) {
|
|
26
|
+
const el = doc.getElementById(id);
|
|
27
|
+
// By tag name: iframe-realm elements fail `instanceof HTMLAudioElement`.
|
|
28
|
+
if (!isCarveVoiceElement(el)) continue;
|
|
29
|
+
const src = el.getAttribute("src");
|
|
30
|
+
if (!src) continue;
|
|
31
|
+
const clock = readClipClock((name) => el.getAttribute(name));
|
|
32
|
+
voices.push({ src, start: el.getAttribute("data-start"), clock });
|
|
33
|
+
}
|
|
34
|
+
return voices;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Remove the filters and lanes a carve generated once it no longer names a voice. */
|
|
38
|
+
export async function dropCarveOutput(
|
|
39
|
+
chain: HfAudioFxChain,
|
|
40
|
+
automation: HfAutomation,
|
|
41
|
+
onSetAttributeQuiet: (attr: string, value: string | null) => void | Promise<void>,
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
const carriedOver = withoutCarveLanes(automation, chain);
|
|
44
|
+
if (carriedOver.lanes.length !== automation.lanes.length) {
|
|
45
|
+
await onSetAttributeQuiet(HF_AUDIO_AUTOMATION_ATTR, automationAttrValue(carriedOver) || null);
|
|
46
|
+
}
|
|
47
|
+
const kept = chain.nodes.filter((n) => !n.fromCarve);
|
|
48
|
+
if (kept.length !== chain.nodes.length) {
|
|
49
|
+
await onSetAttributeQuiet(
|
|
50
|
+
HF_AUDIO_FX_ATTR,
|
|
51
|
+
kept.length ? serializeAudioFxChain({ version: 1, nodes: kept }) : null,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
export interface CropPresetBarTarget {
|
|
4
|
+
hfId?: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface CropPresetBarState {
|
|
9
|
+
openFor: CropPresetBarTarget | null;
|
|
10
|
+
open: (target: CropPresetBarTarget) => void;
|
|
11
|
+
close: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Which clip the crop preset bar is open for; the canvas shows it while that element is selected. */
|
|
15
|
+
export const useCropPresetBarStore = create<CropPresetBarState>((set) => ({
|
|
16
|
+
openFor: null,
|
|
17
|
+
open: (target) => set({ openFor: target }),
|
|
18
|
+
close: () => set({ openFor: null }),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
export function isCropBarTarget(element: Element, target: CropPresetBarTarget | null): boolean {
|
|
22
|
+
if (!target) return false;
|
|
23
|
+
const hfId = element.getAttribute("data-hf-id");
|
|
24
|
+
if (target.hfId && hfId) return target.hfId === hfId;
|
|
25
|
+
return Boolean(target.id) && element.id === target.id;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The crop lift is a stylesheet rule, so the inline clip-path is still the committed one. */
|
|
29
|
+
export function committedClipPath(element: Element): string | null {
|
|
30
|
+
const style = element.getAttribute("style") ?? "";
|
|
31
|
+
const match = /(?:^|;)\s*clip-path\s*:\s*([^;]+)/i.exec(style);
|
|
32
|
+
return match?.[1]?.trim() ?? null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { CROP_ASPECT_PRESETS, centredCropInsets } from "./cropPresets";
|
|
3
|
+
|
|
4
|
+
describe("centredCropInsets", () => {
|
|
5
|
+
it("trims the sides of a wide frame to 9:16, centred", () => {
|
|
6
|
+
const insets = centredCropInsets(1920, 1080, 9 / 16);
|
|
7
|
+
expect(insets.top).toBe(0);
|
|
8
|
+
expect(insets.bottom).toBe(0);
|
|
9
|
+
expect(insets.left).toBeCloseTo((1920 - 607.5) / 2, 6);
|
|
10
|
+
expect(insets.right).toBeCloseTo(insets.left, 6);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("trims top and bottom of a tall frame to 16:9", () => {
|
|
14
|
+
const insets = centredCropInsets(1080, 1920, 16 / 9);
|
|
15
|
+
expect(insets.left).toBe(0);
|
|
16
|
+
expect(insets.right).toBe(0);
|
|
17
|
+
expect(insets.top).toBeCloseTo((1920 - 607.5) / 2, 6);
|
|
18
|
+
expect(insets.bottom).toBeCloseTo(insets.top, 6);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("leaves the visible box in the requested ratio", () => {
|
|
22
|
+
for (const [w, h] of [
|
|
23
|
+
[1920, 1080],
|
|
24
|
+
[1080, 1920],
|
|
25
|
+
[800, 800],
|
|
26
|
+
]) {
|
|
27
|
+
for (const { ratio } of CROP_ASPECT_PRESETS) {
|
|
28
|
+
const i = centredCropInsets(w, h, ratio);
|
|
29
|
+
expect((w - i.left - i.right) / (h - i.top - i.bottom)).toBeCloseTo(ratio, 6);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("is no crop when the frame already has the ratio", () => {
|
|
35
|
+
expect(centredCropInsets(1600, 900, 16 / 9)).toEqual({ top: 0, right: 0, bottom: 0, left: 0 });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("offers the four spec ratios", () => {
|
|
39
|
+
expect(CROP_ASPECT_PRESETS.map((p) => p.label)).toEqual(["16:9", "9:16", "1:1", "4:5"]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ClipPathInsetSides } from "./clipPathHelpers";
|
|
2
|
+
|
|
3
|
+
export const CROP_ASPECT_PRESETS = [
|
|
4
|
+
{ label: "16:9", ratio: 16 / 9 },
|
|
5
|
+
{ label: "9:16", ratio: 9 / 16 },
|
|
6
|
+
{ label: "1:1", ratio: 1 },
|
|
7
|
+
{ label: "4:5", ratio: 4 / 5 },
|
|
8
|
+
] as const;
|
|
9
|
+
|
|
10
|
+
/** Insets (element CSS px) that leave the largest centred box of `ratio` (width / height). */
|
|
11
|
+
export function centredCropInsets(
|
|
12
|
+
width: number,
|
|
13
|
+
height: number,
|
|
14
|
+
ratio: number,
|
|
15
|
+
): ClipPathInsetSides {
|
|
16
|
+
const none = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
17
|
+
if (width <= 0 || height <= 0 || ratio <= 0) return none;
|
|
18
|
+
if (width / height > ratio) {
|
|
19
|
+
const side = (width - height * ratio) / 2;
|
|
20
|
+
return side > 1e-9 ? { ...none, left: side, right: side } : none;
|
|
21
|
+
}
|
|
22
|
+
const band = (height - width / ratio) / 2;
|
|
23
|
+
return band > 1e-9 ? { ...none, top: band, bottom: band } : none;
|
|
24
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
buildTextFieldChildLocator,
|
|
8
8
|
readHfId,
|
|
9
9
|
liveLayerElement,
|
|
10
|
+
domEditSelectionToFacts,
|
|
10
11
|
} from "./domEditingLayers";
|
|
11
12
|
import type { DomEditTextField } from "./domEditingTypes";
|
|
12
13
|
|
|
@@ -332,3 +333,23 @@ describe("liveLayerElement", () => {
|
|
|
332
333
|
).toBe("strip");
|
|
333
334
|
});
|
|
334
335
|
});
|
|
336
|
+
|
|
337
|
+
describe("domEditSelectionToFacts hasAudio", () => {
|
|
338
|
+
async function factsFor(html: string) {
|
|
339
|
+
document.body.innerHTML = html;
|
|
340
|
+
const node = document.body.firstElementChild;
|
|
341
|
+
if (!(node instanceof HTMLElement)) throw new Error("expected element");
|
|
342
|
+
const selection = await resolveDomEditSelection(node, opts);
|
|
343
|
+
document.body.innerHTML = "";
|
|
344
|
+
if (!selection) throw new Error("expected selection");
|
|
345
|
+
return domEditSelectionToFacts(selection);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
it("is true for an unmuted video, false for muted or data-has-audio=false", async () => {
|
|
349
|
+
expect((await factsFor(`<video id="v1"></video>`)).hasAudio).toBe(true);
|
|
350
|
+
expect((await factsFor(`<video id="v2" data-has-audio="true"></video>`)).hasAudio).toBe(true);
|
|
351
|
+
expect((await factsFor(`<video id="v3" muted></video>`)).hasAudio).toBe(false);
|
|
352
|
+
expect((await factsFor(`<video id="v4" data-has-audio="false"></video>`)).hasAudio).toBe(false);
|
|
353
|
+
expect((await factsFor(`<div id="d1"></div>`)).hasAudio).toBe(false);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { probeSourceElement } from "./probeSourceElement";
|
|
2
|
+
import { isAudibleVideoNode } from "../../player/lib/timelineElementHelpers";
|
|
2
3
|
import type { PatchOperation } from "../../utils/sourcePatcher";
|
|
3
4
|
import {
|
|
4
5
|
resolveEditingAffordances,
|
|
@@ -248,6 +249,7 @@ export function domEditSelectionToFacts(
|
|
|
248
249
|
hasEditableText: selection.textFields.length > 0,
|
|
249
250
|
hasTimingStart: selection.dataAttributes.start != null,
|
|
250
251
|
animationCount,
|
|
252
|
+
hasAudio: isAudibleVideoNode(selection.element),
|
|
251
253
|
};
|
|
252
254
|
}
|
|
253
255
|
|