@hyperframes/studio 0.8.103 → 0.8.105

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 (200) hide show
  1. package/dist/assets/{hyperframes-player-DG795Hwu.js → hyperframes-player-tnfCiVdR.js} +1 -1
  2. package/dist/assets/{index-BiEtDkae.js → index-Ca6LZlVb.js} +1 -1
  3. package/dist/assets/index-Cre9X4RS.css +1 -0
  4. package/dist/assets/{index-BPJRf2X9.js → index-DEDhPmPD.js} +215 -215
  5. package/dist/assets/{index-DuCZ3pQw.js → index-zpe332hb.js} +1 -1
  6. package/dist/{chunk-62DDWOSH.js → chunk-EEXSYY5F.js} +19 -18
  7. package/dist/chunk-EEXSYY5F.js.map +1 -0
  8. package/dist/{chunk-6GAO75IU.js → chunk-NCUBAVGK.js} +10 -8
  9. package/dist/chunk-NCUBAVGK.js.map +1 -0
  10. package/dist/{chunk-HIGHVWYD.js → chunk-QADHJFDF.js} +2 -2
  11. package/dist/index.css +6 -1
  12. package/dist/index.css.map +1 -1
  13. package/dist/index.d.ts +181 -168
  14. package/dist/index.html +2 -2
  15. package/dist/index.js +1018 -919
  16. package/dist/index.js.map +1 -1
  17. package/dist/player.js +2 -2
  18. package/dist/styles/tailwind-preset.js.map +1 -1
  19. package/dist/styles.css +1 -1
  20. package/dist/ui.js +2 -2
  21. package/package.json +8 -8
  22. package/src/captions/components/CaptionAnimationPanel.tsx +2 -2
  23. package/src/captions/components/CaptionPropertyPanel.tsx +2 -2
  24. package/src/captions/components/CaptionTimeline.tsx +3 -3
  25. package/src/components/AskAgentModal.tsx +1 -1
  26. package/src/components/LintModal.tsx +35 -35
  27. package/src/components/StudioErrorBoundary.tsx +1 -1
  28. package/src/components/StudioHeader.dom.test.tsx +4 -4
  29. package/src/components/StudioHeader.tsx +2 -1
  30. package/src/components/StudioToast.tsx +7 -16
  31. package/src/components/TimelineToolPicker.tsx +1 -1
  32. package/src/components/TimelineToolbar.tsx +11 -11
  33. package/src/components/dock/Dock.tsx +1 -1
  34. package/src/components/dock/dock.css +9 -1
  35. package/src/components/editor/AnimationCard.tsx +5 -5
  36. package/src/components/editor/AnimationCardParts.tsx +1 -1
  37. package/src/components/editor/BlockParamsPanel.tsx +3 -3
  38. package/src/components/editor/BorderRadiusEditor.tsx +8 -15
  39. package/src/components/editor/CanvasContextMenu.tsx +1 -1
  40. package/src/components/editor/ComputedTweenNotice.tsx +1 -1
  41. package/src/components/editor/DomEditOverlay.tsx +5 -6
  42. package/src/components/editor/DomEditRotateHandle.tsx +1 -1
  43. package/src/components/editor/EaseCurveSection.tsx +14 -19
  44. package/src/components/editor/EaseModeControls.tsx +2 -2
  45. package/src/components/editor/EaseParamFields.tsx +8 -8
  46. package/src/components/editor/FileTree.tsx +1 -1
  47. package/src/components/editor/FileTreeIcons.tsx +47 -26
  48. package/src/components/editor/FileTreeNodes.tsx +11 -8
  49. package/src/components/editor/GestureRecordControl.tsx +3 -3
  50. package/src/components/editor/GsapAddAnimationControl.tsx +1 -1
  51. package/src/components/editor/GsapAnimationSection.tsx +2 -2
  52. package/src/components/editor/InlineTextToolbar.tsx +4 -4
  53. package/src/components/editor/InspectorHeaderActions.tsx +1 -1
  54. package/src/components/editor/KeyframeDiamond.tsx +6 -4
  55. package/src/components/editor/KeyframeNavigation.tsx +4 -4
  56. package/src/components/editor/LayersPanel.tsx +3 -3
  57. package/src/components/editor/PromotableControl.tsx +2 -2
  58. package/src/components/editor/PropertyPanel.tsx +3 -3
  59. package/src/components/editor/PropertyPanelEmptyState.tsx +4 -4
  60. package/src/components/editor/PropertyPanelFlatFooter.tsx +2 -2
  61. package/src/components/editor/PropertyPanelFlatHeader.test.tsx +1 -1
  62. package/src/components/editor/PropertyPanelFlatHeader.tsx +2 -2
  63. package/src/components/editor/SnapToolbar.tsx +5 -5
  64. package/src/components/editor/TimelineFxPopover.tsx +4 -4
  65. package/src/components/editor/Transform3DCube.tsx +1 -1
  66. package/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts +46 -6
  67. package/src/components/editor/anchoredResizeReleaseShift.test.ts +0 -84
  68. package/src/components/editor/domEditOverlayGestures.ts +13 -19
  69. package/src/components/editor/domEditOverlayStartGesture.test.ts +170 -13
  70. package/src/components/editor/domEditOverlayStartGesture.ts +15 -25
  71. package/src/components/editor/easeCurveSvg.tsx +1 -1
  72. package/src/components/editor/manualEdits.test.ts +3 -9
  73. package/src/components/editor/manualEdits.ts +0 -1
  74. package/src/components/editor/manualEditsDom.ts +3 -13
  75. package/src/components/editor/manualEditsDomPatches.test.ts +3 -131
  76. package/src/components/editor/manualEditsDomPatches.ts +1 -53
  77. package/src/components/editor/manualEditsSnapshot.ts +3 -0
  78. package/src/components/editor/manualEditsTypes.ts +2 -0
  79. package/src/components/editor/manualOffsetDrag.test.ts +41 -0
  80. package/src/components/editor/manualOffsetDrag.ts +6 -27
  81. package/src/components/editor/persistSeam.integration.test.ts +0 -18
  82. package/src/components/editor/plainTranslate.ts +42 -6
  83. package/src/components/editor/propertyPanelColorCurveGraph.tsx +2 -2
  84. package/src/components/editor/propertyPanelColorGradingControls.tsx +1 -1
  85. package/src/components/editor/propertyPanelColorGradingSection.tsx +8 -8
  86. package/src/components/editor/propertyPanelColorGradingSlider.tsx +1 -1
  87. package/src/components/editor/propertyPanelColorSecondary.tsx +4 -4
  88. package/src/components/editor/propertyPanelFill.tsx +6 -6
  89. package/src/components/editor/propertyPanelFlatColorGradingAccessory.tsx +3 -3
  90. package/src/components/editor/propertyPanelFlatColorGradingSection.test.tsx +1 -1
  91. package/src/components/editor/propertyPanelFlatColorGradingSection.tsx +6 -9
  92. package/src/components/editor/propertyPanelFlatEffectsSection.tsx +4 -4
  93. package/src/components/editor/propertyPanelFlatMediaSection.tsx +2 -2
  94. package/src/components/editor/propertyPanelFlatMotionSection.tsx +2 -2
  95. package/src/components/editor/propertyPanelFlatOverlaysSection.tsx +2 -2
  96. package/src/components/editor/propertyPanelFlatPrimitives.test.tsx +4 -3
  97. package/src/components/editor/propertyPanelFlatPrimitives.tsx +1 -1
  98. package/src/components/editor/propertyPanelFlatSliderReadout.tsx +1 -1
  99. package/src/components/editor/propertyPanelFont.tsx +2 -2
  100. package/src/components/editor/propertyPanelFxCarveModule.tsx +1 -1
  101. package/src/components/editor/propertyPanelFxControls.tsx +2 -2
  102. package/src/components/editor/propertyPanelFxEqModule.tsx +2 -2
  103. package/src/components/editor/propertyPanelFxNodeRow.tsx +1 -1
  104. package/src/components/editor/propertyPanelFxPresetRun.tsx +1 -1
  105. package/src/components/editor/propertyPanelMediaSection.tsx +1 -1
  106. package/src/components/editor/propertyPanelPrimitives.tsx +1 -1
  107. package/src/components/editor/propertyPanelSections.tsx +2 -2
  108. package/src/components/editor/propertyPanelTransformCommit.test.ts +29 -0
  109. package/src/components/editor/propertyPanelTransformCommit.ts +8 -5
  110. package/src/components/editor/propertyPanelTypes.ts +1 -0
  111. package/src/components/editor/propertyPanelValueTier.test.ts +1 -1
  112. package/src/components/editor/propertyPanelValueTier.ts +1 -1
  113. package/src/components/editor/rotateInlineSave.test.ts +111 -0
  114. package/src/components/editor/rotationDraft.test.ts +111 -0
  115. package/src/components/editor/rotationDraft.ts +145 -0
  116. package/src/components/editor/useDomEditNudge.test.tsx +33 -0
  117. package/src/components/editor/useDomEditNudge.ts +6 -2
  118. package/src/components/editor/useDomEditOverlayGestures.ts +22 -24
  119. package/src/components/feedback/StudioFeedbackCard.tsx +11 -23
  120. package/src/components/nle/AssetPreviewOverlay.tsx +1 -1
  121. package/src/components/nle/AudioMeterStrip.tsx +2 -2
  122. package/src/components/nle/NLEPreview.test.ts +8 -4
  123. package/src/components/nle/PreviewOverlays.tsx +1 -1
  124. package/src/components/nle/PreviewPane.tsx +3 -3
  125. package/src/components/nle/PreviewPoster.tsx +29 -1
  126. package/src/components/nle/PreviewZoomOverlay.tsx +1 -1
  127. package/src/components/panels/SlideshowPanel.tsx +4 -4
  128. package/src/components/panels/SlideshowSubPanels.tsx +19 -21
  129. package/src/components/panels/VariablesBindElement.tsx +1 -1
  130. package/src/components/panels/VariablesDeclarationForm.tsx +1 -1
  131. package/src/components/panels/VariablesPanel.tsx +4 -6
  132. package/src/components/panels/VariablesRowAction.tsx +1 -1
  133. package/src/components/renders/FfmpegRequiredNotice.tsx +4 -4
  134. package/src/components/renders/RenderQueue.tsx +2 -2
  135. package/src/components/renders/RenderQueueItem.tsx +3 -3
  136. package/src/components/sidebar/AssetCard.tsx +3 -3
  137. package/src/components/sidebar/AssetContextMenu.tsx +7 -7
  138. package/src/components/sidebar/AssetsTab.tsx +6 -6
  139. package/src/components/sidebar/AudioRow.tsx +5 -3
  140. package/src/components/sidebar/BlocksTab.tsx +6 -6
  141. package/src/components/sidebar/CompositionsTab.drag.test.tsx +3 -69
  142. package/src/components/sidebar/CompositionsTab.rootBadge.test.tsx +4 -50
  143. package/src/components/sidebar/CompositionsTab.thumbnails.test.tsx +256 -0
  144. package/src/components/sidebar/CompositionsTab.tsx +65 -12
  145. package/src/components/sidebar/PromptPreviewModal.tsx +3 -3
  146. package/src/components/sidebar/SidebarLintButton.tsx +3 -3
  147. package/src/components/sidebar/compositionsTabTestUtils.tsx +39 -0
  148. package/src/components/timelineToolbarStyles.ts +3 -3
  149. package/src/components/ui/Button.tsx +4 -4
  150. package/src/components/ui/HyperframesLogo.tsx +19 -18
  151. package/src/components/ui/Input.tsx +1 -1
  152. package/src/components/ui/Menu.tsx +4 -2
  153. package/src/hooks/draggedGsapPosition.ts +28 -0
  154. package/src/hooks/elementOffsetStager.ts +34 -13
  155. package/src/hooks/gsapRuntimeBridge.ts +5 -3
  156. package/src/hooks/gsapRuntimeKeyframes.ts +36 -2
  157. package/src/hooks/plainRotation.test.ts +122 -0
  158. package/src/hooks/plainRotation.ts +42 -0
  159. package/src/hooks/useClipboard.source.test.ts +42 -4
  160. package/src/hooks/useClipboard.ts +13 -3
  161. package/src/hooks/useDomEditCommits.ts +0 -3
  162. package/src/hooks/useDomEditSession.ts +5 -5
  163. package/src/hooks/useDomGeometryCommit.test.tsx +79 -1
  164. package/src/hooks/useDomGeometryCommit.ts +16 -17
  165. package/src/hooks/useDomGeometryCommits.test.tsx +233 -33
  166. package/src/hooks/useDomGeometryCommits.ts +27 -80
  167. package/src/hooks/useGsapAwareEditing.test.tsx +194 -11
  168. package/src/hooks/useGsapAwareEditing.ts +43 -42
  169. package/src/hooks/useInlineTextEdit.test.tsx +33 -3
  170. package/src/hooks/useInlineTextEdit.ts +2 -2
  171. package/src/player/components/ClipContextMenu.tsx +1 -1
  172. package/src/player/components/CompositionThumbnail.tsx +23 -11
  173. package/src/player/components/EditModal.tsx +6 -6
  174. package/src/player/components/KeyframeDiamondContextMenu.tsx +2 -2
  175. package/src/player/components/PlayerControls.tsx +3 -3
  176. package/src/player/components/ShortcutsPanel.tsx +8 -20
  177. package/src/player/components/TimelineCanvas.tsx +1 -1
  178. package/src/player/components/TimelineClip.tsx +2 -2
  179. package/src/player/components/TimelineEmptyState.tsx +2 -2
  180. package/src/player/components/TimelineLanes.tsx +0 -1
  181. package/src/player/components/TrackClipCount.tsx +1 -1
  182. package/src/player/components/VolumeControl.tsx +1 -1
  183. package/src/player/components/timelineClipChildren.tsx +1 -1
  184. package/src/player/components/timelineMotionStyles.test.ts +6 -22
  185. package/src/player/components/trackHeaderLabelRows.tsx +16 -16
  186. package/src/player/lib/thumbnailScheduler.ts +4 -5
  187. package/src/player/lib/timelineViewportBudgets.test.ts +1 -1
  188. package/src/player/lib/timelineViewportBudgets.ts +1 -1
  189. package/src/styles/hex-baseline.json +7 -19
  190. package/src/styles/studio.css +0 -9
  191. package/src/styles/tailwind-preset.shared.js +2 -1
  192. package/src/styles/theme.css +204 -147
  193. package/src/styles/theme.test.ts +13 -9
  194. package/src/utils/blockCategories.ts +41 -9
  195. package/src/utils/clipboardPayload.ts +2 -0
  196. package/dist/assets/index-CQN3M56N.css +0 -1
  197. package/dist/chunk-62DDWOSH.js.map +0 -1
  198. package/dist/chunk-6GAO75IU.js.map +0 -1
  199. package/src/hooks/gsapTargetCache.ts +0 -62
  200. /package/dist/{chunk-HIGHVWYD.js.map → chunk-QADHJFDF.js.map} +0 -0
@@ -1,3 +1,4 @@
1
+ import { gsapWritesPosition } from "../../hooks/gsapRuntimeKeyframes";
1
2
  import type { DomEditSelection } from "./domEditingTypes";
2
3
  import { readStudioBoxSize } from "./manualEdits";
3
4
  import { readMoveOffset, UNREADABLE_TRANSLATE } from "./plainTranslate";
@@ -74,14 +75,16 @@ export function createTransformCommitHandlers({
74
75
  )
75
76
  )
76
77
  return;
77
- const current = readMoveOffset(element.element);
78
+ const plainTranslate = !gsapWritesPosition(element.element);
79
+ const current = readMoveOffset(element.element, plainTranslate);
78
80
  if (!Number.isFinite(current.x) || !Number.isFinite(current.y))
79
81
  return void showToast?.(UNREADABLE_TRANSLATE);
80
82
  await Promise.resolve(
81
- onSetManualOffset(element, {
82
- x: axis === "x" ? parsed : current.x,
83
- y: axis === "y" ? parsed : current.y,
84
- }),
83
+ onSetManualOffset(
84
+ element,
85
+ { x: axis === "x" ? parsed : current.x, y: axis === "y" ? parsed : current.y },
86
+ { plainTranslate },
87
+ ),
85
88
  );
86
89
  };
87
90
 
@@ -79,6 +79,7 @@ export interface PropertyPanelProps {
79
79
  onSetManualOffset: (
80
80
  element: DomEditSelection,
81
81
  next: { x: number; y: number },
82
+ route?: { plainTranslate: boolean },
82
83
  ) => void | Promise<void>;
83
84
  onSetManualSize: (
84
85
  element: DomEditSelection,
@@ -27,6 +27,6 @@ describe("value tier class maps", () => {
27
27
  expect(VALUE_TIER_LABEL_CLASS[tier]).toBeTruthy();
28
28
  expect(VALUE_TIER_VALUE_CLASS[tier]).toBeTruthy();
29
29
  }
30
- expect(VALUE_TIER_VALUE_CLASS.explicitCustom).toBe("text-panel-accent");
30
+ expect(VALUE_TIER_VALUE_CLASS.explicitCustom).toBe("text-accent-ink");
31
31
  });
32
32
  });
@@ -24,5 +24,5 @@ export const VALUE_TIER_LABEL_CLASS: Record<PropertyValueTier, string> = {
24
24
  export const VALUE_TIER_VALUE_CLASS: Record<PropertyValueTier, string> = {
25
25
  default: "text-panel-text-3",
26
26
  explicitDefault: "text-panel-text-0",
27
- explicitCustom: "text-panel-accent",
27
+ explicitCustom: "text-accent-ink",
28
28
  };
@@ -0,0 +1,111 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { savePlainRotation } from "../../hooks/plainRotation";
5
+ import { applyStudioRotation } from "./manualEdits";
6
+ import type { ElementOffsetStagerDeps } from "../../hooks/elementOffsetStager";
7
+ import type { DomEditSelection } from "./domEditing";
8
+ import type { GestureState, UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures";
9
+ import { createDomEditOverlayGestureHandlers } from "./useDomEditOverlayGestures";
10
+
11
+ const ref = <T>(current: T) => ({ current });
12
+
13
+ function evt(clientX: number, clientY: number) {
14
+ return {
15
+ clientX,
16
+ clientY,
17
+ pointerId: 1,
18
+ button: 0,
19
+ altKey: false,
20
+ shiftKey: false,
21
+ preventDefault() {},
22
+ stopPropagation() {},
23
+ currentTarget: { setPointerCapture() {} },
24
+ } as unknown as React.PointerEvent<HTMLDivElement>;
25
+ }
26
+
27
+ afterEach(() => {
28
+ document.head.innerHTML = "";
29
+ document.body.innerHTML = "";
30
+ });
31
+
32
+ async function rotateWord(before: (word: HTMLElement) => void = () => {}) {
33
+ const sheet = document.head.appendChild(document.createElement("style"));
34
+ sheet.textContent = "#word { display: inline; }";
35
+ const element = document.body.appendChild(document.createElement("span"));
36
+ element.id = "word";
37
+ element.textContent = "Word";
38
+ const selection = {
39
+ element,
40
+ id: "word",
41
+ selector: "#word",
42
+ selectorIndex: 0,
43
+ sourceFile: "index.html",
44
+ tagName: "span",
45
+ label: "Word",
46
+ textContent: "Word",
47
+ textFields: [],
48
+ capabilities: { canMove: true, canApplyManualRotation: true },
49
+ } as unknown as DomEditSelection;
50
+ const commitPositionPatchToHtml = vi.fn<ElementOffsetStagerDeps["commitPositionPatchToHtml"]>(
51
+ () => Promise.resolve(),
52
+ );
53
+ const saves: Promise<void>[] = [];
54
+ const opts: UseDomEditOverlayGesturesOptions = {
55
+ overlayRef: ref<HTMLDivElement | null>(document.createElement("div")),
56
+ iframeRef: ref<HTMLIFrameElement | null>(document.createElement("iframe")),
57
+ boxRef: ref<HTMLDivElement | null>(document.createElement("div")),
58
+ selectionRef: ref<DomEditSelection | null>(selection),
59
+ hoverSelectionRef: ref<DomEditSelection | null>(null),
60
+ overlayRectRef: ref({ left: 0, top: 0, width: 200, height: 100, editScaleX: 1, editScaleY: 1 }),
61
+ groupOverlayItemsRef: ref([]),
62
+ gestureRef: ref<GestureState | null>(null),
63
+ groupGestureRef: ref(null),
64
+ blockedMoveRef: ref(null),
65
+ rafPausedRef: ref(false),
66
+ suppressNextBoxClickRef: ref(false),
67
+ setOverlayRect: () => {},
68
+ setGroupOverlayItems: () => {},
69
+ onBlockedMoveRef: ref(() => {}),
70
+ onManualDragStartRef: ref(() => {}),
71
+ onPathOffsetCommitRef: ref(() => {}),
72
+ onGroupPathOffsetCommitRef: ref(() => {}),
73
+ onBoxSizeCommitRef: ref(() => {}),
74
+ onRotationCommitRef: ref((s, next) => {
75
+ const saved = savePlainRotation({ commitPositionPatchToHtml }, s, next);
76
+ saves.push(saved);
77
+ return saved;
78
+ }),
79
+ onCanvasPointerMoveRef: ref(() => Promise.resolve(null)),
80
+ onCanvasMouseDown: () => {},
81
+ snapGuidesRef: ref(null),
82
+ } as unknown as UseDomEditOverlayGesturesOptions;
83
+ before(element);
84
+ const handlers = createDomEditOverlayGestureHandlers(opts);
85
+
86
+ handlers.startGesture("rotate", evt(200, 50));
87
+ handlers.onPointerMove(evt(100, 150));
88
+ handlers.onPointerUp(evt(100, 150));
89
+ await Promise.all(saves);
90
+
91
+ expect(saves).toHaveLength(1);
92
+ return commitPositionPatchToHtml.mock.calls[0]![1];
93
+ }
94
+
95
+ const INLINE_BLOCK = { type: "inline-style", property: "display", value: "inline-block" };
96
+ const turnOf = (patches: Awaited<ReturnType<typeof rotateWord>>) =>
97
+ patches.findLast((patch) => patch.type === "inline-style" && patch.property === "rotate");
98
+
99
+ it("saves an inline span's turn with the inline-block it was drawn with, after the draft and the hold", async () => {
100
+ expect(await rotateWord()).toContainEqual(INLINE_BLOCK);
101
+ });
102
+
103
+ it("saves inline-block and the whole turn for a word an older Studio already turned 15 deg", async () => {
104
+ const plain = await rotateWord();
105
+ document.head.innerHTML = "";
106
+ document.body.innerHTML = "";
107
+ const legacy = await rotateWord((word) => applyStudioRotation(word, { angle: 15 }));
108
+ expect(legacy).toContainEqual(INLINE_BLOCK);
109
+ const degrees = (patches: typeof plain) => Number.parseFloat(String(turnOf(patches)?.value));
110
+ expect(degrees(legacy)).toBe(degrees(plain) + 15);
111
+ });
@@ -0,0 +1,111 @@
1
+ import { Window } from "happy-dom";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { applyRotationDraft, readCssRotationTarget, readRotationBase } from "./rotationDraft";
4
+
5
+ describe("rotate in a composition without GSAP", () => {
6
+ it("starts from the authored CSS rotation and drafts the absolute angle the commit writes", () => {
7
+ const window = new Window();
8
+ window.document.head.innerHTML = "<style>#title { rotate: 30deg; }</style>";
9
+ const element = window.document.createElement("h1");
10
+ element.id = "title";
11
+ window.document.body.append(element);
12
+ const base = readRotationBase(element, true);
13
+ expect(base).toBeCloseTo(30);
14
+ applyRotationDraft(element, 55, readCssRotationTarget(element));
15
+ expect(element.style.getPropertyValue("rotate")).toBe("55deg");
16
+ });
17
+
18
+ it("drafts only the part of the angle the CSS rotate owns, leaving transform and scale theirs", () => {
19
+ const cases: Array<[string, number, number]> = [
20
+ ["transform: rotate(30deg);", 30, 25],
21
+ ["rotate: 20deg; transform: rotate(10deg);", 30, 45],
22
+ ["scale: -1 1;", 180, 25],
23
+ ["transform: scaleX(-1);", 180, 25],
24
+ ];
25
+ for (const [css, base, drafted] of cases) {
26
+ const window = new Window();
27
+ window.document.head.innerHTML = `<style>#title { ${css} }</style>`;
28
+ const element = window.document.createElement("h1");
29
+ element.id = "title";
30
+ window.document.body.append(element);
31
+ expect({ css, base: readRotationBase(element, true) }).toEqual({
32
+ css,
33
+ base: expect.closeTo(base),
34
+ });
35
+ applyRotationDraft(element, base + 25, readCssRotationTarget(element));
36
+ const rotate = Number.parseFloat(element.style.getPropertyValue("rotate"));
37
+ expect({ css, rotate }).toEqual({ css, rotate: expect.closeTo(drafted) });
38
+ }
39
+ });
40
+
41
+ it("never asks GSAP, nor restyles per frame, when GSAP turns nothing on the element", () => {
42
+ const window = new Window();
43
+ const gsap = { set: vi.fn(), getProperty: vi.fn(() => 0) };
44
+ Object.assign(window, { gsap });
45
+ window.document.head.innerHTML = "<style>#title { rotate: 30deg; }</style>";
46
+ const element = window.document.createElement("h1");
47
+ element.id = "title";
48
+ window.document.body.append(element);
49
+ expect(readRotationBase(element, true)).toBeCloseTo(30);
50
+ const target = readCssRotationTarget(element);
51
+ const styleReads = vi.spyOn(window, "getComputedStyle");
52
+ applyRotationDraft(element, 55, target);
53
+ expect(styleReads).not.toHaveBeenCalled();
54
+ expect(element.style.getPropertyValue("rotate")).toBe("55deg");
55
+ expect(gsap.set).not.toHaveBeenCalled();
56
+ expect(gsap.getProperty).not.toHaveBeenCalled();
57
+ applyRotationDraft(element, 55, null);
58
+ expect(element.style.getPropertyValue("rotate")).toBe("none");
59
+ expect(gsap.set).toHaveBeenCalledWith(element, { rotation: 55 });
60
+ });
61
+
62
+ it("turns a transform-centred element inside its transform, after the translate, so it stays put", () => {
63
+ const window = new Window();
64
+ window.document.head.innerHTML =
65
+ "<style>#title { rotate: 30deg; transform: translate(-120px, -80px); }</style>";
66
+ const element = window.document.createElement("h1");
67
+ element.id = "title";
68
+ window.document.body.append(element);
69
+ const target = readCssRotationTarget(element);
70
+ expect(target).toEqual({
71
+ property: "transform",
72
+ before: "translate(-120px, -80px)",
73
+ after: "",
74
+ share: expect.closeTo(30),
75
+ sign: 1,
76
+ inline: false,
77
+ });
78
+ applyRotationDraft(element, 55, target);
79
+ expect(element.style.getPropertyValue("transform")).toBe(
80
+ "translate(-120px, -80px) rotate(25deg)",
81
+ );
82
+ expect(element.style.getPropertyValue("rotate")).toBe("");
83
+ // The next rotate replaces its own turn instead of stacking a second one.
84
+ applyRotationDraft(element, 70, readCssRotationTarget(element));
85
+ expect(element.style.getPropertyValue("transform")).toBe(
86
+ "translate(-120px, -80px) rotate(40deg)",
87
+ );
88
+ });
89
+
90
+ // Each case turns 25 deg with the cursor: the fold GSAP and the outline read goes up by 25, unsheared.
91
+ it.each([
92
+ ["a mirrored transform", "transform: translate(-120px, -80px) scaleX(-1);", 180],
93
+ ["a stretched transform", "transform: translate(-120px, -80px) scale(2, 1);", 0],
94
+ ["a mirroring scale property", "scale: -1 1; transform: translate(-120px, -80px);", 180],
95
+ ])("turns %s centred element with the cursor, in place", (_, css, base) => {
96
+ const window = new Window();
97
+ window.document.head.innerHTML = `<style>#title { ${css} }</style>`;
98
+ const element = window.document.createElement("h1");
99
+ element.id = "title";
100
+ window.document.body.append(element);
101
+ const turned = (angle: number) => (((angle % 360) + 360) % 360) % 360;
102
+ expect(turned(readRotationBase(element, true))).toBeCloseTo(base);
103
+ applyRotationDraft(element, base + 25, readCssRotationTarget(element));
104
+ const transform = element.style.getPropertyValue("transform");
105
+ expect(transform.startsWith("translate(-120px, -80px) rotate(")).toBe(true);
106
+ expect(turned(readRotationBase(element, true))).toBeCloseTo(base + 25);
107
+ const m = new window.DOMMatrix(window.getComputedStyle(element).transform);
108
+ expect(m.a * m.c + m.b * m.d).toBeCloseTo(0);
109
+ expect([m.e, m.f]).toEqual([-120, -80]);
110
+ });
111
+ });
@@ -0,0 +1,145 @@
1
+ import { readCssRotation } from "../../hooks/draggedGsapPosition";
2
+ import { roundTo3 } from "../../utils/rounding";
3
+ import type { PatchOperation } from "../../utils/sourcePatcher";
4
+ import {
5
+ readStudioRotation,
6
+ restoreStudioRotation,
7
+ type StudioRotationSnapshot,
8
+ } from "./manualEdits";
9
+ import { getOffsetDragGsap } from "./manualOffsetDrag";
10
+ import { splitTopLevelWhitespace } from "./manualEditsStyleHelpers";
11
+
12
+ function lastRuleTransform(element: HTMLElement): string {
13
+ let value = "";
14
+ for (const sheet of Array.from(element.ownerDocument.styleSheets)) {
15
+ let rules: CSSStyleRule[] = [];
16
+ try {
17
+ rules = Array.from(sheet.cssRules) as CSSStyleRule[];
18
+ } catch {
19
+ // a cross-origin sheet
20
+ }
21
+ for (const rule of rules) {
22
+ const declared = rule.style?.getPropertyValue("transform");
23
+ if (declared && element.matches(rule.selectorText)) value = declared;
24
+ }
25
+ }
26
+ return value;
27
+ }
28
+
29
+ // ponytail: the authored transform if it moves the box, from the last matching rule in sheet order;
30
+ // specificity, !important and @media are not weighed. Weigh them when a film's rule is missed.
31
+ function translatingTransform(element: HTMLElement): string {
32
+ const view = element.ownerDocument.defaultView;
33
+ const computed = view?.getComputedStyle(element).transform ?? "none";
34
+ const m = computed === "none" ? null : new view!.DOMMatrix(computed);
35
+ if (!m || (m.m41 === 0 && m.m42 === 0)) return "";
36
+ const value = element.style.getPropertyValue("transform") || lastRuleTransform(element);
37
+ return value === "none" ? "" : value;
38
+ }
39
+
40
+ /** Where a plain rotate draws its turn, read once at press: the element's own `rotate`, or, when its
41
+ * transform translates it (often the translate(-50%, -50%) centring), a rotate() right after that
42
+ * translate, so the box turns in place in screen space. `share` is what the rest already turns. */
43
+ export interface CssRotationTarget {
44
+ property: "rotate" | "transform";
45
+ before: string;
46
+ after: string;
47
+ share: number;
48
+ /** -1 when a mirroring `scale` property flips a turn made inside the transform. */
49
+ sign: number;
50
+ /** An inline box does not transform, so the turn makes it inline-block. */
51
+ inline: boolean;
52
+ }
53
+
54
+ export type RotationCommit = { angle: number; plain?: CssRotationTarget };
55
+
56
+ const TRANSLATE = /^translate(?:3d|X|Y|Z)?\(/i;
57
+ const OWN_TURN = /^rotate\(\s*-?[\d.]+(?:e[+-]?\d+)?deg\s*\)$/i;
58
+
59
+ export function readCssRotationTarget(element: HTMLElement): CssRotationTarget {
60
+ const style = element.ownerDocument.defaultView?.getComputedStyle(element);
61
+ const inline = style?.display === "inline";
62
+ const transform = translatingTransform(element);
63
+ if (!transform) {
64
+ const share = readCssRotation(element, false);
65
+ return { property: "rotate", before: "", after: "", share, sign: 1, inline };
66
+ }
67
+ const parts = splitTopLevelWhitespace(transform);
68
+ const lead = parts.findIndex((part) => !TRANSLATE.test(part));
69
+ const split = lead < 0 ? parts.length : lead;
70
+ const rest = parts.slice(split);
71
+ if (OWN_TURN.test(rest[0] ?? "")) rest.shift();
72
+ const [before, after] = [parts.slice(0, split).join(" "), rest.join(" ")];
73
+ const [sx = 1, sy = sx] = splitTopLevelWhitespace(style?.getPropertyValue("scale") ?? "").map(
74
+ Number.parseFloat,
75
+ );
76
+ const inlineStyle = element.style;
77
+ const saved = [
78
+ inlineStyle.getPropertyValue("transform"),
79
+ inlineStyle.getPropertyPriority("transform"),
80
+ ];
81
+ inlineStyle.setProperty("transform", `${before} ${after}`.trim() || "none");
82
+ const share = readCssRotation(element);
83
+ inlineStyle.setProperty("transform", saved[0] ?? "", saved[1] ?? "");
84
+ return { property: "transform", before, after, share, sign: sx * sy < 0 ? -1 : 1, inline };
85
+ }
86
+
87
+ /** Draws `angle` where `target` says, and returns the source patches that save it as drawn. */
88
+ export function applyCssRotation(
89
+ element: HTMLElement,
90
+ angle: number,
91
+ target = readCssRotationTarget(element),
92
+ ): Array<PatchOperation & { value: string }> {
93
+ const turn = `${roundTo3(target.sign * (angle - target.share))}deg`;
94
+ const value =
95
+ target.property === "rotate"
96
+ ? turn
97
+ : [target.before, `rotate(${turn})`, target.after].filter(Boolean).join(" ");
98
+ const patches: Array<PatchOperation & { value: string }> = [
99
+ { type: "inline-style", property: target.property, value },
100
+ ];
101
+ if (target.inline) {
102
+ patches.unshift({ type: "inline-style", property: "display", value: "inline-block" });
103
+ }
104
+ for (const patch of patches) element.style.setProperty(patch.property, patch.value);
105
+ return patches;
106
+ }
107
+
108
+ /** Back to the press: the rotation snapshot and, for a plain rotate, the inline transform it drew in. */
109
+ export function restorePlainRotation(element: HTMLElement, snapshot: StudioRotationSnapshot): void {
110
+ restoreStudioRotation(element, snapshot);
111
+ element.style.setProperty("transform", snapshot.transform);
112
+ element.style.setProperty("display", snapshot.display);
113
+ }
114
+
115
+ // `plain`, read at press: where a turn GSAP does not own draws; null for GSAP's rotation.
116
+ export function applyRotationDraft(
117
+ element: HTMLElement,
118
+ angle: number,
119
+ plain: CssRotationTarget | null,
120
+ ): void {
121
+ if (plain) return void applyCssRotation(element, angle, plain);
122
+ element.style.setProperty("rotate", "none");
123
+ getOffsetDragGsap(element)?.set(element, { rotation: angle });
124
+ }
125
+
126
+ /** Back to the gesture start: the CSS snapshot, and GSAP's rotation without the legacy var. */
127
+ export function restoreRotationDraft(
128
+ element: HTMLElement,
129
+ angle: number,
130
+ snapshot: StudioRotationSnapshot,
131
+ plain: boolean,
132
+ ): void {
133
+ if (plain) return restorePlainRotation(element, snapshot);
134
+ getOffsetDragGsap(element)?.set(element, {
135
+ rotation: angle - (Number.parseFloat(snapshot.studioRotation) || 0),
136
+ });
137
+ restoreStudioRotation(element, snapshot);
138
+ }
139
+
140
+ /** The angle a rotate gesture starts from, as the element shows it. */
141
+ export function readRotationBase(element: HTMLElement, plain: boolean): number {
142
+ if (plain) return readCssRotation(element);
143
+ const gsapRotation = Number(getOffsetDragGsap(element)?.getProperty(element, "rotation") ?? 0);
144
+ return gsapRotation + readStudioRotation(element).angle;
145
+ }
@@ -227,3 +227,36 @@ describe("useDomEditNudge — selection cleanup keyed on stable identity", () =>
227
227
  elementB.remove();
228
228
  });
229
229
  });
230
+
231
+ describe("useDomEditNudge carries the route its press chose", () => {
232
+ beforeEach(() => {
233
+ vi.useFakeTimers();
234
+ __resetForTests();
235
+ });
236
+ afterEach(() => vi.useRealTimers());
237
+
238
+ it("commits an element without GSAP on the CSS route", () => {
239
+ const host = document.createElement("div");
240
+ const root = createRoot(host);
241
+ const element = document.createElement("div");
242
+ document.body.append(element);
243
+ const commit = vi.fn();
244
+ act(() => {
245
+ root.render(
246
+ React.createElement(Harness, {
247
+ selection: makeSelection("Dot", element),
248
+ onPathOffsetCommit: commit,
249
+ }),
250
+ );
251
+ });
252
+ act(() => dispatchArrowRight());
253
+ act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS + 10));
254
+ expect(commit).toHaveBeenCalledWith(
255
+ expect.anything(),
256
+ expect.anything(),
257
+ expect.objectContaining({ plainTranslate: true }),
258
+ );
259
+ act(() => root.unmount());
260
+ element.remove();
261
+ });
262
+ });
@@ -18,6 +18,7 @@ import {
18
18
  import type {
19
19
  BlockedMoveState,
20
20
  DomEditGroupPathOffsetCommit,
21
+ MoveCommitOptions,
21
22
  GestureState,
22
23
  GroupGestureState,
23
24
  } from "./domEditOverlayGestures";
@@ -60,7 +61,7 @@ export interface UseDomEditNudgeParams {
60
61
  (
61
62
  s: DomEditSelection,
62
63
  n: { x: number; y: number },
63
- m?: { altKey?: boolean },
64
+ m?: MoveCommitOptions,
64
65
  ) => Promise<unknown> | void
65
66
  >;
66
67
  onGroupPathOffsetCommitRef: RefObject<
@@ -150,11 +151,14 @@ export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: ()
150
151
  const updates: DomEditGroupPathOffsetCommit[] = session.members.map((member) => ({
151
152
  selection: member.selection,
152
153
  next: applyManualOffsetNudgeCommit(member, session.accum),
154
+ plainTranslate: member.plainTranslate,
153
155
  }));
154
156
  const p = paramsRef.current;
155
157
  const commit = session.isGroup
156
158
  ? p.onGroupPathOffsetCommitRef.current(updates)
157
- : p.onPathOffsetCommitRef.current(updates[0].selection, updates[0].next);
159
+ : p.onPathOffsetCommitRef.current(updates[0].selection, updates[0].next, {
160
+ plainTranslate: updates[0].plainTranslate,
161
+ });
158
162
  void Promise.resolve(commit)
159
163
  .catch(() => {
160
164
  for (const member of session.members) {
@@ -9,21 +9,18 @@ import { type DomEditSelection } from "./domEditing";
9
9
  import {
10
10
  applyManualOffsetDragCommit,
11
11
  applyManualOffsetDragDraft,
12
- applyRotationDraftViaGsap,
13
12
  endManualOffsetDragMembers,
14
13
  restoreManualOffsetDragMembers,
15
14
  } from "./manualOffsetDrag";
15
+ import { applyRotationDraft, restoreRotationDraft } from "./rotationDraft";
16
16
  import {
17
17
  applyStudioBoxSize,
18
18
  applyStudioBoxSizeDraft,
19
- applyStudioRotation,
20
- applyStudioRotationDraft,
21
19
  endStudioManualEditGesture,
22
20
  isStudioManualEditGestureCurrent,
23
21
  readStudioBoxSize,
24
22
  restoreStudioBoxSize,
25
23
  restoreStudioPathOffset,
26
- restoreStudioRotation,
27
24
  } from "./manualEdits";
28
25
  import {
29
26
  type GroupOverlayItem,
@@ -166,9 +163,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
166
163
  actualAngle: g.actualRotation,
167
164
  snap: e.shiftKey,
168
165
  });
169
- if (!applyRotationDraftViaGsap(sel.element, rotated.angle)) {
170
- applyStudioRotationDraft(sel.element, rotated);
171
- }
166
+ applyRotationDraft(sel.element, rotated.angle, g.plainRotation);
172
167
  return;
173
168
  }
174
169
 
@@ -336,6 +331,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
336
331
  const updates = groupG.members.map((member) => ({
337
332
  selection: member.selection,
338
333
  next: applyManualOffsetDragCommit(member, dx, dy),
334
+ plainTranslate: member.plainTranslate,
339
335
  }));
340
336
  logDrag("drop", {
341
337
  pointer: `${Math.round(rawDx)},${Math.round(rawDy)}`,
@@ -421,24 +417,22 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
421
417
  actualAngle: g.actualRotation,
422
418
  snap: e.shiftKey,
423
419
  });
424
- const restoreRotation = () => {
425
- // Single source of truth: snap the GSAP rotation back to the gesture's base
426
- // angle; fall back to the legacy CSS-var restore when gsap is unavailable.
427
- if (!applyRotationDraftViaGsap(sel.element, g.actualRotation)) {
428
- restoreStudioRotation(sel.element, g.initialRotation);
429
- }
430
- };
420
+ const restoreRotation = () =>
421
+ restoreRotationDraft(
422
+ sel.element,
423
+ g.actualRotation,
424
+ g.initialRotation,
425
+ g.plainRotation !== null,
426
+ );
431
427
  if (!hasDomEditRotationChanged(g.actualRotation, finalRotation.angle)) {
432
428
  restoreRotation();
433
429
  endStudioManualEditGesture(sel.element, g.manualEditDragToken);
434
430
  return;
435
431
  }
436
- // Keep the preview at the final angle through the GSAP channel (NOT the CSS var)
437
- // while the commit lands a `tl.set`/keyframe rotation on the timeline.
438
- if (!applyRotationDraftViaGsap(sel.element, finalRotation.angle)) {
439
- applyStudioRotation(sel.element, finalRotation);
440
- }
441
- void Promise.resolve(opts.onRotationCommitRef.current(sel, finalRotation))
432
+ // Hold the final angle while the commit lands.
433
+ applyRotationDraft(sel.element, finalRotation.angle, g.plainRotation);
434
+ const commit = g.plainRotation ? { ...finalRotation, plain: g.plainRotation } : finalRotation;
435
+ void Promise.resolve(opts.onRotationCommitRef.current(sel, commit))
442
436
  .catch((error) => {
443
437
  logGestureCommitFailure("rotate commit failed", error);
444
438
  if (
@@ -476,7 +470,10 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
476
470
  box.style.top = `${nextBoxTop}px`;
477
471
  }
478
472
  void Promise.resolve(
479
- opts.onPathOffsetCommitRef.current(sel, finalOffset, { altKey: e.altKey }),
473
+ opts.onPathOffsetCommitRef.current(sel, finalOffset, {
474
+ altKey: e.altKey,
475
+ plainTranslate: g.pathOffsetMember.plainTranslate,
476
+ }),
480
477
  )
481
478
  .catch(() => {
482
479
  if (
@@ -555,11 +552,12 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
555
552
  restoreGestureOverlayRect(g);
556
553
  }
557
554
  if (g?.mode === "rotation" && sel) {
558
- applyRotationDraftViaGsap(
555
+ restoreRotationDraft(
559
556
  sel.element,
560
- g.actualRotation - (Number.parseFloat(g.initialRotation.studioRotation) || 0),
557
+ g.actualRotation,
558
+ g.initialRotation,
559
+ g.plainRotation !== null,
561
560
  );
562
- restoreStudioRotation(sel.element, g.initialRotation);
563
561
  endStudioManualEditGesture(sel.element, g.manualEditDragToken);
564
562
  }
565
563
  opts.blockedMoveRef.current = null;