@hyperframes/studio 0.7.54 → 0.7.56

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 (262) hide show
  1. package/dist/assets/{index-uBY329wb.js → index-BWnOxAiH.js} +1 -1
  2. package/dist/assets/{index-CMHYjEZ5.js → index-C4csZims.js} +1 -1
  3. package/dist/assets/index-CmVCjZjp.js +423 -0
  4. package/dist/assets/index-D-GyYi2d.css +1 -0
  5. package/dist/{chunk-SOTCF4DF.js → chunk-5QSIMBEJ.js} +2 -1
  6. package/dist/chunk-5QSIMBEJ.js.map +1 -0
  7. package/dist/{domEditingLayers-2ECJK24D.js → domEditingLayers-6LQGKPOI.js} +2 -2
  8. package/dist/index.d.ts +146 -144
  9. package/dist/index.html +2 -2
  10. package/dist/index.js +40582 -37803
  11. package/dist/index.js.map +1 -1
  12. package/package.json +7 -7
  13. package/src/App.tsx +106 -96
  14. package/src/components/EditorShell.tsx +253 -0
  15. package/src/components/StudioGlobalDragOverlay.tsx +1 -3
  16. package/src/components/StudioLeftSidebar.tsx +13 -3
  17. package/src/components/StudioRightPanel.tsx +8 -3
  18. package/src/components/TimelineToolbar.test.tsx +2 -2
  19. package/src/components/TimelineToolbar.tsx +179 -121
  20. package/src/components/editor/CanvasContextMenu.test.tsx +115 -0
  21. package/src/components/editor/CanvasContextMenu.tsx +198 -0
  22. package/src/components/editor/DomEditCropHandles.test.tsx +74 -3
  23. package/src/components/editor/DomEditCropHandles.tsx +64 -29
  24. package/src/components/editor/DomEditOverlay.test.ts +245 -279
  25. package/src/components/editor/DomEditOverlay.tsx +158 -126
  26. package/src/components/editor/DomEditOverlayHover.test.tsx +90 -0
  27. package/src/components/editor/DomEditRotateHandle.tsx +38 -18
  28. package/src/components/editor/DomEditSelectionChrome.test.tsx +80 -0
  29. package/src/components/editor/DomEditSelectionChrome.tsx +257 -0
  30. package/src/components/editor/LayersPanel.test.ts +66 -2
  31. package/src/components/editor/LayersPanel.tsx +43 -1
  32. package/src/components/editor/OffCanvasIndicators.test.tsx +34 -0
  33. package/src/components/editor/OffCanvasIndicators.tsx +49 -10
  34. package/src/components/editor/SnapGuideOverlay.tsx +28 -23
  35. package/src/components/editor/SnapToolbar.test.tsx +0 -1
  36. package/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts +214 -0
  37. package/src/components/editor/anchoredResizeReleaseShift.test.ts +208 -0
  38. package/src/components/editor/canvasContextMenuZOrder.test.ts +435 -0
  39. package/src/components/editor/canvasContextMenuZOrder.ts +352 -0
  40. package/src/components/editor/domEditNudge.test.ts +80 -0
  41. package/src/components/editor/domEditNudge.ts +44 -0
  42. package/src/components/editor/domEditOverlayGeometry.test.ts +167 -1
  43. package/src/components/editor/domEditOverlayGeometry.ts +280 -20
  44. package/src/components/editor/domEditOverlayGestures.ts +44 -41
  45. package/src/components/editor/domEditOverlayStartGesture.ts +62 -2
  46. package/src/components/editor/domEditResizeLocal.test.ts +131 -0
  47. package/src/components/editor/domEditResizeLocal.ts +125 -0
  48. package/src/components/editor/domEditingDom.ts +1 -1
  49. package/src/components/editor/manualEditsDomPatches.test.ts +47 -0
  50. package/src/components/editor/manualOffsetDrag.ts +55 -12
  51. package/src/components/editor/offCanvasIndicatorGeometry.ts +31 -10
  52. package/src/components/editor/offCanvasIndicatorRefresh.test.tsx +25 -1
  53. package/src/components/editor/resizeDraft.ts +108 -0
  54. package/src/components/editor/snapEngine.test.ts +12 -78
  55. package/src/components/editor/snapEngine.ts +13 -53
  56. package/src/components/editor/useDomEditNudge.test.tsx +228 -0
  57. package/src/components/editor/useDomEditNudge.ts +254 -0
  58. package/src/components/editor/useDomEditOverlayGestures.ts +115 -116
  59. package/src/components/editor/useDomEditOverlayRects.ts +9 -2
  60. package/src/components/nle/AssetPreviewOverlay.tsx +147 -0
  61. package/src/components/nle/NLEContext.test.ts +144 -0
  62. package/src/components/nle/NLEContext.tsx +328 -0
  63. package/src/components/nle/NLEPreview.tsx +1 -1
  64. package/src/components/nle/PreviewOverlays.tsx +240 -0
  65. package/src/components/nle/PreviewPane.tsx +163 -0
  66. package/src/components/nle/TimelinePane.test.ts +60 -0
  67. package/src/components/nle/TimelinePane.tsx +293 -0
  68. package/src/components/nle/TimelineResizeDivider.tsx +8 -2
  69. package/src/components/nle/useCompositionStack.test.tsx +44 -0
  70. package/src/components/nle/useCompositionStack.ts +17 -9
  71. package/src/components/nle/useTimelineEditCallbacks.ts +217 -0
  72. package/src/components/sidebar/AssetCard.tsx +326 -0
  73. package/src/components/sidebar/AssetContextMenu.tsx +15 -30
  74. package/src/components/sidebar/AssetsTab.test.ts +96 -0
  75. package/src/components/sidebar/AssetsTab.tsx +71 -206
  76. package/src/components/sidebar/AudioRow.tsx +39 -2
  77. package/src/components/sidebar/BlocksTab.tsx +8 -1
  78. package/src/components/sidebar/LeftSidebar.tsx +4 -1
  79. package/src/components/sidebar/assetHelpers.ts +29 -0
  80. package/src/contexts/DomEditContext.tsx +9 -0
  81. package/src/contexts/StudioContext.tsx +9 -8
  82. package/src/contexts/TimelineEditContext.tsx +3 -7
  83. package/src/hooks/deleteSelectedKeyframes.ts +35 -0
  84. package/src/hooks/domEditCommitTypes.ts +12 -1
  85. package/src/hooks/domSelectionTestHarness.ts +14 -0
  86. package/src/hooks/gestureTransaction.test.ts +311 -0
  87. package/src/hooks/gestureTransaction.ts +199 -0
  88. package/src/hooks/gsapDragCommit.test.ts +141 -41
  89. package/src/hooks/gsapDragCommit.ts +64 -74
  90. package/src/hooks/gsapDragStaticSetHelpers.ts +9 -21
  91. package/src/hooks/gsapResizeIntercept.test.ts +69 -0
  92. package/src/hooks/gsapResizeIntercept.ts +38 -10
  93. package/src/hooks/gsapRuntimeBridge.test.ts +49 -13
  94. package/src/hooks/gsapRuntimeBridge.ts +4 -4
  95. package/src/hooks/gsapScriptCommitTypes.ts +16 -5
  96. package/src/hooks/gsapShared.test.ts +19 -1
  97. package/src/hooks/gsapShared.ts +14 -0
  98. package/src/hooks/patchDocumentRootDuration.test.ts +71 -0
  99. package/src/hooks/timelineEditingGsap.ts +14 -0
  100. package/src/hooks/timelineEditingHelpers.test.ts +34 -1
  101. package/src/hooks/timelineEditingHelpers.ts +22 -48
  102. package/src/hooks/timelineMoveAdapter.test.ts +77 -0
  103. package/src/hooks/timelineMoveAdapter.ts +37 -0
  104. package/src/hooks/useAnimatedPropertyCommit.test.tsx +36 -8
  105. package/src/hooks/useAnimatedPropertyCommit.ts +31 -26
  106. package/src/hooks/useAppHotkeys.ts +16 -25
  107. package/src/hooks/useBlockHandlers.ts +55 -27
  108. package/src/hooks/useContextMenuDismiss.ts +31 -7
  109. package/src/hooks/useDomEditCommits.test.tsx +154 -1
  110. package/src/hooks/useDomEditCommits.ts +100 -3
  111. package/src/hooks/useDomEditPositionPatchCommit.ts +2 -0
  112. package/src/hooks/useDomEditSession.ts +2 -2
  113. package/src/hooks/useDomEditTextCommits.test.tsx +135 -0
  114. package/src/hooks/useDomEditTextCommits.ts +8 -3
  115. package/src/hooks/useDomEditWiring.ts +7 -9
  116. package/src/hooks/useDomGeometryCommits.ts +17 -2
  117. package/src/hooks/useDomSelection.test.ts +2 -36
  118. package/src/hooks/useDomSelection.ts +81 -51
  119. package/src/hooks/useDomSelectionSelectionGuards.test.ts +276 -0
  120. package/src/hooks/useElementLifecycleOps.test.tsx +258 -0
  121. package/src/hooks/useElementLifecycleOps.ts +40 -71
  122. package/src/hooks/useEnableKeyframes.test.ts +142 -1
  123. package/src/hooks/useEnableKeyframes.ts +73 -29
  124. package/src/hooks/useGestureCommit.test.tsx +130 -0
  125. package/src/hooks/useGestureCommit.ts +32 -8
  126. package/src/hooks/useGroupCommits.ts +7 -28
  127. package/src/hooks/useGsapAwareEditing.test.tsx +239 -0
  128. package/src/hooks/useGsapAwareEditing.ts +115 -20
  129. package/src/hooks/useGsapKeyframeOps.test.tsx +59 -0
  130. package/src/hooks/useGsapKeyframeOps.ts +38 -10
  131. package/src/hooks/useGsapScriptCommits.test.tsx +40 -1
  132. package/src/hooks/useGsapScriptCommits.ts +134 -50
  133. package/src/hooks/useGsapSelectionHandlers.ts +49 -16
  134. package/src/hooks/useMusicBeatAnalysis.ts +72 -36
  135. package/src/hooks/usePersistentEditHistory.test.ts +33 -0
  136. package/src/hooks/usePersistentEditHistory.ts +92 -58
  137. package/src/hooks/usePreviewPersistence.ts +25 -7
  138. package/src/hooks/useRazorSplit.history.test.tsx +303 -0
  139. package/src/hooks/useRazorSplit.test.ts +269 -0
  140. package/src/hooks/useRazorSplit.testHelpers.ts +64 -0
  141. package/src/hooks/useRazorSplit.ts +107 -36
  142. package/src/hooks/useRenderClipContent.ts +24 -6
  143. package/src/hooks/useStudioContextValue.ts +15 -5
  144. package/src/hooks/useStudioUrlState.ts +2 -4
  145. package/src/hooks/useTimelineEditing.test.tsx +20 -29
  146. package/src/hooks/useTimelineEditingTypes.ts +6 -0
  147. package/src/hooks/useTimelineGroupEditing.ts +18 -4
  148. package/src/index.ts +1 -1
  149. package/src/player/components/ImageThumbnail.test.tsx +173 -0
  150. package/src/player/components/ImageThumbnail.tsx +160 -0
  151. package/src/player/components/PlayheadIndicator.tsx +50 -5
  152. package/src/player/components/Timeline.test.ts +102 -19
  153. package/src/player/components/Timeline.tsx +194 -194
  154. package/src/player/components/TimelineCanvas.tsx +207 -521
  155. package/src/player/components/TimelineClip.tsx +4 -1
  156. package/src/player/components/TimelineClipDiamonds.tsx +9 -40
  157. package/src/player/components/TimelineEmptyState.tsx +3 -1
  158. package/src/player/components/TimelineLanes.tsx +487 -0
  159. package/src/player/components/TimelineOverlays.tsx +122 -0
  160. package/src/player/components/VideoThumbnail.test.tsx +152 -0
  161. package/src/player/components/VideoThumbnail.tsx +28 -7
  162. package/src/player/components/thumbnailUtils.test.ts +127 -0
  163. package/src/player/components/thumbnailUtils.ts +54 -0
  164. package/src/player/components/timelineCallbacks.ts +18 -18
  165. package/src/player/components/timelineClipChildren.tsx +39 -0
  166. package/src/player/components/timelineClipDragCommit.test.ts +943 -0
  167. package/src/player/components/timelineClipDragCommit.ts +401 -0
  168. package/src/player/components/timelineClipDragPreview.test.ts +144 -0
  169. package/src/player/components/timelineClipDragPreview.ts +323 -38
  170. package/src/player/components/timelineClipDragTypes.ts +65 -0
  171. package/src/player/components/timelineCollision.test.ts +477 -0
  172. package/src/player/components/timelineCollision.ts +263 -0
  173. package/src/player/components/timelineDragDrop.ts +69 -60
  174. package/src/player/components/timelineEditCapabilities.ts +52 -0
  175. package/src/player/components/timelineEditing.test.ts +1 -1
  176. package/src/player/components/timelineEditing.ts +76 -59
  177. package/src/player/components/timelineGroupEditing.test.ts +126 -0
  178. package/src/player/components/timelineGroupEditing.ts +133 -0
  179. package/src/player/components/timelineGroupResizeCommit.ts +54 -0
  180. package/src/player/components/timelineLayout.test.ts +95 -23
  181. package/src/player/components/timelineLayout.ts +120 -61
  182. package/src/player/components/timelineMarquee.test.ts +197 -0
  183. package/src/player/components/timelineMarquee.ts +112 -0
  184. package/src/player/components/timelineMultiDragPreview.test.ts +127 -0
  185. package/src/player/components/timelineMultiDragPreview.ts +106 -0
  186. package/src/player/components/timelineOptimisticRevision.ts +42 -0
  187. package/src/player/components/timelineSnapping.test.ts +134 -0
  188. package/src/player/components/timelineSnapping.ts +110 -0
  189. package/src/player/components/timelineStackingSync.test.ts +244 -0
  190. package/src/player/components/timelineStackingSync.ts +331 -0
  191. package/src/player/components/timelineTheme.ts +6 -1
  192. package/src/player/components/timelineZones.test.ts +425 -0
  193. package/src/player/components/timelineZones.ts +198 -0
  194. package/src/player/components/timelineZoom.test.ts +67 -0
  195. package/src/player/components/timelineZoom.ts +51 -0
  196. package/src/player/components/useResolvedTimelineEditCallbacks.ts +25 -3
  197. package/src/player/components/useTimelineClipDrag.resize.test.tsx +241 -0
  198. package/src/player/components/useTimelineClipDrag.ts +380 -386
  199. package/src/player/components/useTimelineEditPinning.ts +121 -0
  200. package/src/player/components/useTimelineGeometry.ts +129 -0
  201. package/src/player/components/useTimelinePlayhead.ts +4 -16
  202. package/src/player/components/useTimelineRangeSelection.ts +341 -50
  203. package/src/player/components/useTimelineStackingSync.test.tsx +67 -0
  204. package/src/player/components/useTimelineStackingSync.ts +83 -0
  205. package/src/player/hooks/useExpandedTimelineElements.ts +0 -3
  206. package/src/player/hooks/usePlaybackKeyboard.ts +5 -0
  207. package/src/player/hooks/useTimelinePlayer.ts +48 -53
  208. package/src/player/hooks/useTimelinePlayerLoop.ts +85 -0
  209. package/src/player/hooks/useTimelineSyncCallbacks.test.ts +219 -0
  210. package/src/player/hooks/useTimelineSyncCallbacks.ts +104 -4
  211. package/src/player/index.ts +3 -2
  212. package/src/player/lib/time.test.ts +19 -19
  213. package/src/player/lib/time.ts +6 -2
  214. package/src/player/lib/timelineDOM.test.ts +25 -98
  215. package/src/player/lib/timelineDOM.ts +12 -81
  216. package/src/player/lib/timelineElementHelpers.ts +54 -5
  217. package/src/player/lib/timelineIframeHelpers.ts +2 -0
  218. package/src/player/store/playerStore.ts +62 -3
  219. package/src/styles/studio.css +27 -0
  220. package/src/utils/assetClickBehavior.test.ts +104 -0
  221. package/src/utils/assetClickBehavior.ts +75 -0
  222. package/src/utils/assetPreviewStore.ts +33 -0
  223. package/src/utils/blockInstaller.ts +10 -2
  224. package/src/utils/canvasNudgeGate.test.ts +31 -0
  225. package/src/utils/canvasNudgeGate.ts +32 -0
  226. package/src/utils/editHistory.test.ts +35 -0
  227. package/src/utils/gsapSoftReload.test.ts +119 -1
  228. package/src/utils/gsapSoftReload.ts +153 -0
  229. package/src/utils/mediaTypes.ts +3 -2
  230. package/src/utils/resizeDebug.ts +55 -0
  231. package/src/utils/rootDuration.test.ts +90 -1
  232. package/src/utils/rootDuration.ts +76 -13
  233. package/src/utils/sdkCutover.ts +4 -0
  234. package/src/utils/studioFileHistory.ts +37 -7
  235. package/src/utils/studioHelpers.ts +62 -0
  236. package/src/utils/studioPreviewHelpers.test.ts +65 -8
  237. package/src/utils/studioPreviewHelpers.ts +10 -0
  238. package/src/utils/studioTelemetry.ts +4 -1
  239. package/src/utils/studioUiPreferences.test.ts +38 -0
  240. package/src/utils/studioUiPreferences.ts +27 -0
  241. package/src/utils/studioUrlState.test.ts +0 -1
  242. package/src/utils/timelineAssetDrop.ts +62 -0
  243. package/src/utils/timelineDiscovery.ts +0 -17
  244. package/src/utils/timelineInspector.test.ts +121 -0
  245. package/src/utils/timelineInspector.ts +32 -1
  246. package/dist/assets/index-Dq7FEg0K.css +0 -1
  247. package/dist/assets/index-pRhCpGPz.js +0 -423
  248. package/dist/chunk-SOTCF4DF.js.map +0 -1
  249. package/src/components/StudioPreviewArea.tsx +0 -500
  250. package/src/components/nle/NLELayout.test.ts +0 -12
  251. package/src/components/nle/NLELayout.tsx +0 -591
  252. package/src/player/components/TimelineLayerGutter.tsx +0 -61
  253. package/src/player/components/TimelineSelectionOverlays.tsx +0 -55
  254. package/src/player/components/timelineMarqueeSelection.test.ts +0 -87
  255. package/src/player/components/timelineSnapTargets.test.ts +0 -144
  256. package/src/player/components/timelineSnapTargets.ts +0 -164
  257. package/src/player/components/useTimelineClipDrag.test.tsx +0 -506
  258. package/src/player/components/useTimelineClipGroupDrag.ts +0 -417
  259. package/src/player/components/useTimelineMarqueeSelection.test.tsx +0 -231
  260. package/src/player/components/useTimelineMarqueeSelection.ts +0 -276
  261. package/src/utils/timelineDiscovery.test.ts +0 -90
  262. /package/dist/{domEditingLayers-2ECJK24D.js.map → domEditingLayers-6LQGKPOI.js.map} +0 -0
@@ -1,55 +0,0 @@
1
- import type { TimelineRangeSelection } from "./timelineEditing";
2
- import { GUTTER, RULER_H } from "./timelineLayout";
3
- import type { TimelineMarqueeOverlayRect } from "./useTimelineMarqueeSelection";
4
-
5
- interface TimelineSelectionOverlaysProps {
6
- rangeSelection: TimelineRangeSelection | null;
7
- marqueeRect: TimelineMarqueeOverlayRect | null;
8
- pps: number;
9
- /** Primary/accent color (hex) shared with the rest of the timeline chrome. */
10
- accentColor: string;
11
- }
12
-
13
- export function TimelineSelectionOverlays({
14
- rangeSelection,
15
- marqueeRect,
16
- pps,
17
- accentColor,
18
- }: TimelineSelectionOverlaysProps) {
19
- return (
20
- <>
21
- {rangeSelection && (
22
- <div
23
- className="absolute pointer-events-none"
24
- style={{
25
- left: GUTTER + Math.min(rangeSelection.start, rangeSelection.end) * pps,
26
- width: Math.abs(rangeSelection.end - rangeSelection.start) * pps,
27
- top: RULER_H,
28
- bottom: 0,
29
- backgroundColor: `${accentColor}1f`,
30
- borderLeft: `1px solid ${accentColor}`,
31
- borderRight: `1px solid ${accentColor}`,
32
- zIndex: 50,
33
- }}
34
- />
35
- )}
36
- {marqueeRect && (
37
- <div
38
- aria-hidden="true"
39
- className="absolute pointer-events-none"
40
- data-timeline-marquee="true"
41
- style={{
42
- left: marqueeRect.left,
43
- top: marqueeRect.top,
44
- width: marqueeRect.width,
45
- height: marqueeRect.height,
46
- backgroundColor: `${accentColor}29`,
47
- border: `1px solid ${accentColor}`,
48
- boxShadow: "0 0 0 1px rgba(15, 23, 42, 0.35)",
49
- zIndex: 60,
50
- }}
51
- />
52
- )}
53
- </>
54
- );
55
- }
@@ -1,87 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { TimelineElement } from "../store/playerStore";
3
- import { RULER_H, TRACK_H } from "./timelineLayout";
4
- import { selectTimelineElementsInMarquee } from "./timelineEditing";
5
- import type { StackingTimelineLayer } from "./timelineTrackOrder";
6
-
7
- function element(id: string, start: number, duration: number, track: number): TimelineElement {
8
- return { id, tag: "div", start, duration, track };
9
- }
10
-
11
- function layer(id: string, elements: TimelineElement[]): StackingTimelineLayer {
12
- return {
13
- id,
14
- kind: "visual",
15
- contextKey: "",
16
- zIndex: 0,
17
- placementTrack: elements[0]?.track ?? 0,
18
- elements,
19
- };
20
- }
21
-
22
- describe("selectTimelineElementsInMarquee", () => {
23
- it("selects clips intersecting both the marquee time span and lane span", () => {
24
- const layers = [
25
- layer("lane-0", [element("first-hit", 1, 1, 0), element("time-miss", 5, 1, 0)]),
26
- layer("lane-1", [element("second-hit", 2.25, 1, 1)]),
27
- layer("lane-2", [element("lane-miss", 1.5, 1, 2)]),
28
- ];
29
-
30
- expect(
31
- selectTimelineElementsInMarquee({
32
- rect: {
33
- startTime: 0.5,
34
- endTime: 3,
35
- top: RULER_H,
36
- bottom: RULER_H + TRACK_H * 2,
37
- },
38
- layers,
39
- layerOrder: layers.map((item) => item.id),
40
- rulerHeight: RULER_H,
41
- trackHeight: TRACK_H,
42
- }),
43
- ).toEqual(["first-hit", "second-hit"]);
44
- });
45
-
46
- it("returns no ids when the marquee intersects no clip", () => {
47
- const layers = [layer("lane-0", [element("outside", 4, 1, 0)])];
48
-
49
- expect(
50
- selectTimelineElementsInMarquee({
51
- rect: {
52
- startTime: 0,
53
- endTime: 1,
54
- top: RULER_H,
55
- bottom: RULER_H + TRACK_H,
56
- },
57
- layers,
58
- layerOrder: ["lane-0"],
59
- rulerHeight: RULER_H,
60
- trackHeight: TRACK_H,
61
- }),
62
- ).toEqual([]);
63
- });
64
-
65
- it("accounts for context group headers before row hit testing", () => {
66
- const layers: StackingTimelineLayer[] = [
67
- { ...layer("lane-0", [element("above", 0, 1, 0)]), contextKey: "root" },
68
- { ...layer("lane-1", [element("below", 0, 1, 1)]), contextKey: "nested" },
69
- ];
70
-
71
- expect(
72
- selectTimelineElementsInMarquee({
73
- rect: {
74
- startTime: 0,
75
- endTime: 1,
76
- top: RULER_H + 18 + TRACK_H,
77
- bottom: RULER_H + 18 + TRACK_H + 18 + TRACK_H,
78
- },
79
- layers,
80
- layerOrder: ["lane-0", "lane-1"],
81
- rulerHeight: RULER_H,
82
- trackHeight: TRACK_H,
83
- groupHeaderHeight: 18,
84
- }),
85
- ).toEqual(["below"]);
86
- });
87
- });
@@ -1,144 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { TimelineElement } from "../store/playerStore";
3
- import {
4
- buildTimelineSnapTargets,
5
- snapEdgesToTargets,
6
- snapResizeEdgeToTargets,
7
- } from "./timelineSnapTargets";
8
-
9
- function timelineElement(input: {
10
- id: string;
11
- key?: string;
12
- start: number;
13
- duration: number;
14
- }): TimelineElement {
15
- return {
16
- id: input.id,
17
- key: input.key,
18
- tag: "div",
19
- start: input.start,
20
- duration: input.duration,
21
- track: 0,
22
- };
23
- }
24
-
25
- describe("buildTimelineSnapTargets", () => {
26
- it("excludes the dragged clip's own edges", () => {
27
- const dragged = timelineElement({
28
- id: "dragged-id",
29
- key: "dragged-key",
30
- start: 1,
31
- duration: 2,
32
- });
33
- const other = timelineElement({ id: "other", start: 4, duration: 2 });
34
-
35
- const targets = buildTimelineSnapTargets({
36
- elements: [dragged, other],
37
- excludedKeys: new Set(["dragged-key"]),
38
- playhead: 8,
39
- compDuration: 10,
40
- beats: [1.5],
41
- });
42
-
43
- const times = targets.map((target) => target.time);
44
- expect(times).not.toContain(1);
45
- expect(times).not.toContain(3);
46
- expect(times).toContain(4);
47
- expect(times).toContain(6);
48
- });
49
-
50
- it("excludes every moving group member, not just the grabbed clip", () => {
51
- const a = timelineElement({ id: "a", start: 1, duration: 1 });
52
- const b = timelineElement({ id: "b", start: 3, duration: 1 });
53
- const other = timelineElement({ id: "other", start: 6, duration: 1 });
54
-
55
- const targets = buildTimelineSnapTargets({
56
- elements: [a, b, other],
57
- excludedKeys: new Set(["a", "b"]),
58
- playhead: 9,
59
- compDuration: 10,
60
- beats: [],
61
- });
62
-
63
- const times = targets.map((target) => target.time);
64
- // Both group members' edges are excluded; the non-member's edges remain.
65
- expect(times).not.toContain(1);
66
- expect(times).not.toContain(2);
67
- expect(times).not.toContain(3);
68
- expect(times).not.toContain(4);
69
- expect(times).toContain(6);
70
- expect(times).toContain(7);
71
- });
72
-
73
- it("dedupes near-equal times from different sources", () => {
74
- const dragged = timelineElement({ id: "dragged", start: 2, duration: 2 });
75
- const other = timelineElement({ id: "other", start: 0.0004, duration: 10 });
76
-
77
- const targets = buildTimelineSnapTargets({
78
- elements: [dragged, other],
79
- excludedKeys: new Set(["dragged"]),
80
- playhead: 5,
81
- compDuration: 10,
82
- beats: [0.0002, 10.0002],
83
- });
84
-
85
- expect(targets.filter((target) => Math.abs(target.time) < 0.001)).toHaveLength(1);
86
- expect(targets.filter((target) => Math.abs(target.time - 10) < 0.001)).toHaveLength(1);
87
- });
88
- });
89
-
90
- describe("snapEdgesToTargets", () => {
91
- it("snaps the start edge to another clip's end", () => {
92
- const snap = snapEdgesToTargets(3.95, 2, [{ time: 4, kind: "edge" }], 100);
93
-
94
- expect(snap).toEqual({ start: 4, snapTime: 4, snapKind: "edge" });
95
- });
96
-
97
- it("snaps the end edge to another clip's start", () => {
98
- const snap = snapEdgesToTargets(2.96, 2, [{ time: 5, kind: "edge" }], 100);
99
-
100
- expect(snap).toEqual({ start: 3, snapTime: 5, snapKind: "edge" });
101
- });
102
-
103
- it("snaps to the playhead", () => {
104
- const snap = snapEdgesToTargets(2.94, 1, [{ time: 3, kind: "playhead" }], 100);
105
-
106
- expect(snap).toEqual({ start: 3, snapTime: 3, snapKind: "playhead" });
107
- });
108
-
109
- it("snaps the start edge to the lower composition bound", () => {
110
- const snap = snapEdgesToTargets(0.04, 1, [{ time: 0, kind: "bound" }], 100);
111
-
112
- expect(snap).toEqual({ start: 0, snapTime: 0, snapKind: "bound" });
113
- });
114
-
115
- it("snaps the end edge to the upper composition bound", () => {
116
- const snap = snapEdgesToTargets(7.96, 2, [{ time: 10, kind: "bound" }], 100);
117
-
118
- expect(snap).toEqual({ start: 8, snapTime: 10, snapKind: "bound" });
119
- });
120
-
121
- it("does not snap when targets are beyond the pixel threshold", () => {
122
- const snap = snapEdgesToTargets(3.9, 1, [{ time: 4, kind: "edge" }], 100);
123
-
124
- expect(snap).toEqual({ start: 3.9, snapTime: null, snapKind: null });
125
- });
126
- });
127
-
128
- describe("snapResizeEdgeToTargets", () => {
129
- it("does not apply end-edge snaps past maxEnd or below minDuration", () => {
130
- expect(
131
- snapResizeEdgeToTargets("end", 4, 2.95, [{ time: 7.01, kind: "edge" }], 100, {
132
- minDuration: 0.05,
133
- maxEnd: 7,
134
- }),
135
- ).toEqual({ start: 4, duration: 2.95, snapTime: null, snapKind: null });
136
-
137
- expect(
138
- snapResizeEdgeToTargets("end", 4, 0.1, [{ time: 4.03, kind: "edge" }], 100, {
139
- minDuration: 0.05,
140
- maxEnd: 10,
141
- }),
142
- ).toEqual({ start: 4, duration: 0.1, snapTime: null, snapKind: null });
143
- });
144
- });
@@ -1,164 +0,0 @@
1
- import type { TimelineElement } from "../store/playerStore";
2
-
3
- export type TimelineSnapKind = "beat" | "edge" | "playhead" | "bound";
4
-
5
- export interface TimelineSnapTarget {
6
- time: number;
7
- kind: TimelineSnapKind;
8
- }
9
-
10
- interface NearestSnap {
11
- target: TimelineSnapTarget;
12
- distance: number;
13
- }
14
-
15
- const SNAP_PX = 8;
16
- const DEDUPE_EPSILON_SECONDS = 0.001;
17
- const ROUND_FACTOR = 1000;
18
- const KIND_PRIORITY: Record<TimelineSnapKind, number> = {
19
- bound: 0,
20
- playhead: 1,
21
- edge: 2,
22
- beat: 3,
23
- };
24
-
25
- function roundToMillis(value: number): number {
26
- return Math.round(value * ROUND_FACTOR) / ROUND_FACTOR;
27
- }
28
-
29
- function addTarget(targets: TimelineSnapTarget[], candidate: TimelineSnapTarget) {
30
- if (!Number.isFinite(candidate.time)) return;
31
- const existingIndex = targets.findIndex(
32
- (target) => Math.abs(target.time - candidate.time) < DEDUPE_EPSILON_SECONDS,
33
- );
34
- if (existingIndex === -1) {
35
- targets.push(candidate);
36
- return;
37
- }
38
-
39
- const existing = targets[existingIndex];
40
- if (!existing || KIND_PRIORITY[candidate.kind] >= KIND_PRIORITY[existing.kind]) return;
41
- targets[existingIndex] = candidate;
42
- }
43
-
44
- export function buildTimelineSnapTargets(input: {
45
- elements: TimelineElement[];
46
- /** Keys of every clip moving in this gesture (the whole group), excluded as targets. */
47
- excludedKeys: ReadonlySet<string>;
48
- playhead: number;
49
- compDuration: number;
50
- beats: number[];
51
- }): TimelineSnapTarget[] {
52
- const targets: TimelineSnapTarget[] = [];
53
-
54
- addTarget(targets, { time: 0, kind: "bound" });
55
- addTarget(targets, { time: Math.max(0, input.compDuration), kind: "bound" });
56
- addTarget(targets, { time: Math.max(0, input.playhead), kind: "playhead" });
57
-
58
- for (const element of input.elements) {
59
- const elementKey = element.key ?? element.id;
60
- if (input.excludedKeys.has(elementKey) || input.excludedKeys.has(element.id)) continue;
61
- addTarget(targets, { time: element.start, kind: "edge" });
62
- addTarget(targets, { time: element.start + element.duration, kind: "edge" });
63
- }
64
-
65
- for (const beat of input.beats) {
66
- addTarget(targets, { time: beat, kind: "beat" });
67
- }
68
-
69
- return targets.sort((a, b) => a.time - b.time || KIND_PRIORITY[a.kind] - KIND_PRIORITY[b.kind]);
70
- }
71
-
72
- function nearestSnap(
73
- time: number,
74
- targets: TimelineSnapTarget[],
75
- thresholdSeconds: number,
76
- ): NearestSnap | null {
77
- let best: NearestSnap | null = null;
78
- let bestDistance = thresholdSeconds;
79
- for (const target of targets) {
80
- if (target.time === time) continue;
81
- const distance = Math.abs(target.time - time);
82
- if (distance < bestDistance) {
83
- bestDistance = distance;
84
- best = { target, distance };
85
- }
86
- }
87
- return best;
88
- }
89
-
90
- export function snapEdgesToTargets(
91
- start: number,
92
- duration: number,
93
- targets: TimelineSnapTarget[],
94
- pixelsPerSecond: number,
95
- options?: { maxStart?: number },
96
- ): { start: number; snapTime: number | null; snapKind: TimelineSnapKind | null } {
97
- const thresholdSeconds = SNAP_PX / Math.max(pixelsPerSecond, 1);
98
- const startSnap = nearestSnap(start, targets, thresholdSeconds);
99
- const endSnap = nearestSnap(start + duration, targets, thresholdSeconds);
100
-
101
- let candidate = start;
102
- let snapTarget: TimelineSnapTarget | null = null;
103
- if (startSnap && (!endSnap || startSnap.distance <= endSnap.distance)) {
104
- candidate = startSnap.target.time;
105
- snapTarget = startSnap.target;
106
- } else if (endSnap) {
107
- candidate = endSnap.target.time - duration;
108
- snapTarget = endSnap.target;
109
- }
110
-
111
- const maxStart = options?.maxStart ?? Number.POSITIVE_INFINITY;
112
- const upperStart = Number.isFinite(maxStart) ? Math.max(0, maxStart) : Number.POSITIVE_INFINITY;
113
- const clamped = Math.max(0, Math.min(upperStart, roundToMillis(candidate)));
114
- if (snapTarget && Math.abs(clamped - candidate) > 1e-6) {
115
- return { start: clamped, snapTime: null, snapKind: null };
116
- }
117
- return {
118
- start: clamped,
119
- snapTime: snapTarget?.time ?? null,
120
- snapKind: snapTarget?.kind ?? null,
121
- };
122
- }
123
-
124
- export function snapResizeEdgeToTargets(
125
- edge: "start" | "end",
126
- start: number,
127
- duration: number,
128
- targets: TimelineSnapTarget[],
129
- pixelsPerSecond: number,
130
- limits: { minDuration: number; maxEnd: number; maxLeftDelta?: number },
131
- ): { start: number; duration: number; snapTime: number | null; snapKind: TimelineSnapKind | null } {
132
- const thresholdSeconds = SNAP_PX / Math.max(pixelsPerSecond, 1);
133
-
134
- if (edge === "end") {
135
- const snap = nearestSnap(start + duration, targets, thresholdSeconds);
136
- if (!snap) return { start, duration, snapTime: null, snapKind: null };
137
- const snappedDuration = roundToMillis(snap.target.time - start);
138
- if (snap.target.time > limits.maxEnd + 1e-6 || snappedDuration < limits.minDuration) {
139
- return { start, duration, snapTime: null, snapKind: null };
140
- }
141
- return {
142
- start,
143
- duration: snappedDuration,
144
- snapTime: snap.target.time,
145
- snapKind: snap.target.kind,
146
- };
147
- }
148
-
149
- const snap = nearestSnap(start, targets, thresholdSeconds);
150
- if (!snap) return { start, duration, snapTime: null, snapKind: null };
151
- const snappedStart = roundToMillis(snap.target.time);
152
- const delta = start - snappedStart;
153
- const snappedDuration = roundToMillis(duration + delta);
154
- const maxLeftDelta = limits.maxLeftDelta ?? Number.POSITIVE_INFINITY;
155
- if (snappedStart < 0 || delta > maxLeftDelta + 1e-6 || snappedDuration < limits.minDuration) {
156
- return { start, duration, snapTime: null, snapKind: null };
157
- }
158
- return {
159
- start: snappedStart,
160
- duration: snappedDuration,
161
- snapTime: snap.target.time,
162
- snapKind: snap.target.kind,
163
- };
164
- }