@hyperframes/studio 0.7.5 → 0.7.7

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 (77) hide show
  1. package/dist/assets/{index-BwFzbjZQ.js → index-B2YXvFxf.js} +1 -1
  2. package/dist/assets/index-BSkUuN8g.css +1 -0
  3. package/dist/assets/index-BeRh2hMe.js +375 -0
  4. package/dist/assets/{index-C5NAfiPa.js → index-BoASKOeE.js} +1 -1
  5. package/dist/chunk-KZXYQYIU.js +876 -0
  6. package/dist/chunk-KZXYQYIU.js.map +1 -0
  7. package/dist/domEditingLayers-SSXQZHHQ.js +41 -0
  8. package/dist/domEditingLayers-SSXQZHHQ.js.map +1 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.html +2 -2
  11. package/dist/index.js +3326 -2939
  12. package/dist/index.js.map +1 -1
  13. package/package.json +5 -5
  14. package/src/captions/hooks/useCaptionSync.ts +6 -1
  15. package/src/components/StudioPreviewArea.tsx +10 -3
  16. package/src/components/StudioRightPanel.tsx +4 -0
  17. package/src/components/editor/AnimationCard.tsx +77 -250
  18. package/src/components/editor/AnimationCardParts.tsx +220 -0
  19. package/src/components/editor/BlockParamsPanel.tsx +4 -8
  20. package/src/components/editor/DomEditOverlay.tsx +132 -48
  21. package/src/components/editor/EaseCurveSection.tsx +177 -101
  22. package/src/components/editor/GsapAnimationSection.tsx +4 -0
  23. package/src/components/editor/KeyframeEaseList.tsx +127 -0
  24. package/src/components/editor/OffCanvasIndicators.tsx +111 -0
  25. package/src/components/editor/PropertyPanel.tsx +63 -56
  26. package/src/components/editor/gsapAnimationCallbacks.ts +3 -0
  27. package/src/components/editor/gsapAnimationConstants.ts +11 -32
  28. package/src/components/editor/gsapAnimationHelpers.test.ts +1 -1
  29. package/src/components/editor/manualOffsetDrag.ts +8 -0
  30. package/src/components/editor/marqueeCommit.ts +168 -0
  31. package/src/components/editor/propertyPanelHelpers.ts +7 -0
  32. package/src/components/editor/propertyPanelTimingSection.tsx +35 -2
  33. package/src/components/editor/snapTargetCollection.ts +0 -5
  34. package/src/components/editor/useMotionPathData.ts +2 -1
  35. package/src/components/panels/SlideshowPanel.tsx +0 -1
  36. package/src/components/sidebar/AssetContextMenu.tsx +97 -0
  37. package/src/components/sidebar/AssetsTab.tsx +542 -254
  38. package/src/components/sidebar/assetHelpers.ts +40 -0
  39. package/src/contexts/DomEditContext.tsx +12 -0
  40. package/src/hooks/gsapDragCommit.ts +101 -0
  41. package/src/hooks/gsapDragPositionCommit.ts +1 -2
  42. package/src/hooks/gsapRuntimeBridge.ts +28 -2
  43. package/src/hooks/gsapRuntimeKeyframes.test.ts +47 -0
  44. package/src/hooks/gsapRuntimeKeyframes.ts +13 -0
  45. package/src/hooks/gsapRuntimeReaders.ts +1 -6
  46. package/src/hooks/useDomEditCommits.ts +0 -4
  47. package/src/hooks/useDomEditPreviewSync.ts +5 -0
  48. package/src/hooks/useDomEditSession.ts +43 -0
  49. package/src/hooks/useDomEditTextCommits.ts +3 -12
  50. package/src/hooks/useDomEditWiring.ts +3 -0
  51. package/src/hooks/useDomSelection.ts +46 -0
  52. package/src/hooks/useGestureCommit.ts +26 -7
  53. package/src/hooks/useGestureRecording.ts +2 -16
  54. package/src/hooks/useGsapAnimationOps.ts +2 -2
  55. package/src/hooks/useGsapAwareEditing.ts +0 -4
  56. package/src/hooks/useGsapScriptCommits.ts +0 -12
  57. package/src/hooks/useGsapTweenCache.test.ts +45 -1
  58. package/src/hooks/useGsapTweenCache.ts +151 -42
  59. package/src/hooks/useMusicBeatAnalysis.ts +36 -21
  60. package/src/hooks/useRazorSplit.ts +0 -3
  61. package/src/player/components/Player.tsx +0 -5
  62. package/src/player/components/timelineIcons.tsx +2 -1
  63. package/src/player/hooks/useTimelinePlayer.ts +4 -14
  64. package/src/player/hooks/useTimelineSyncCallbacks.ts +2 -9
  65. package/src/player/lib/timelineIframeHelpers.ts +2 -6
  66. package/src/telemetry/client.ts +2 -0
  67. package/src/utils/gestureSmoother.test.ts +48 -0
  68. package/src/utils/gestureSmoother.ts +46 -0
  69. package/src/utils/marqueeGeometry.test.ts +123 -0
  70. package/src/utils/marqueeGeometry.ts +172 -0
  71. package/src/utils/optimisticUpdate.ts +1 -2
  72. package/src/utils/sourcePatcher.ts +0 -10
  73. package/src/utils/velocityEaseFitter.test.ts +58 -0
  74. package/src/utils/velocityEaseFitter.ts +121 -0
  75. package/dist/assets/index-D_JGXmfx.js +0 -374
  76. package/dist/assets/index-DzWIinxk.css +0 -1
  77. package/src/utils/editDebugLog.ts +0 -16
@@ -1,16 +1,18 @@
1
- import { memo, useCallback, useRef, useState } from "react";
1
+ import { useCallback, useRef, useState } from "react";
2
2
  import { EASE_CURVES, EASE_LABELS, parseCustomEaseFromString } from "./gsapAnimationConstants";
3
3
  import { roundToCenti } from "../../utils/rounding";
4
4
 
5
+ // Figma-canonical ordering: linear, the three core eases, then the expressive
6
+ // (back / snappy) family. Each maps to a GSAP ease so it round-trips cleanly.
5
7
  const PRESET_GRID_EASES = [
6
8
  "none",
7
- "power2.out",
8
9
  "power2.in",
10
+ "power2.out",
9
11
  "power2.inOut",
10
- "power3.out",
12
+ "back.in",
11
13
  "back.out",
14
+ "back.inOut",
12
15
  "expo.out",
13
- "elastic.out",
14
16
  ] as const;
15
17
 
16
18
  function MiniCurveSvg({
@@ -40,7 +42,7 @@ function MiniCurveSvg({
40
42
  );
41
43
  }
42
44
 
43
- const EasePresetGrid = memo(function EasePresetGrid({
45
+ const EasePresetGrid = function EasePresetGrid({
44
46
  currentEase,
45
47
  onSelect,
46
48
  }: {
@@ -74,10 +76,41 @@ const EasePresetGrid = memo(function EasePresetGrid({
74
76
  })}
75
77
  </div>
76
78
  );
77
- });
79
+ };
78
80
 
79
81
  const round2 = roundToCenti;
80
82
 
83
+ // ── Graph geometry (Figma-style easing box) ─────────────────────────────────
84
+ // A geometrically-square unit plot ([0,1]×[0,1], equal X/Y scale so the curve
85
+ // isn't distorted), with fixed overshoot headroom above 1 and below 0 for
86
+ // back/elastic eases. The view is fixed (no per-curve zoom); handles are clamped
87
+ // to the visible range so they never drift off-screen.
88
+ const S = 184; // side of the unit (0..1) square, in viewBox units
89
+ const HR = 52; // overshoot headroom (top & bottom)
90
+ const PADH = 16; // horizontal breathing room
91
+ const SVGW = S + PADH * 2;
92
+ const SVGH = S + HR * 2;
93
+ const VMAX = 1 + HR / S; // top of visible view (progress overshoot headroom)
94
+ const VMIN = -HR / S; // bottom of visible view (undershoot headroom)
95
+ // Committed control points may extend PAST the visible view — heavy back/elastic
96
+ // presets reach ~1.55 / -0.55. Dragging clamps to this wider bound (cursor can
97
+ // leave the box via pointer capture) so those curves keep their fidelity instead
98
+ // of snapping to the view edge; the handle DOT is still clampView'd into view.
99
+ const DRAG_VMAX = 2;
100
+ const DRAG_VMIN = -1;
101
+ const ACCENT = "#3CE6AC";
102
+
103
+ type Pts = [number, number, number, number];
104
+
105
+ const xToSvg = (px: number) => PADH + S * px;
106
+ const yToSvg = (py: number) => HR + S * (1 - py);
107
+ const clampView = (py: number) => Math.max(VMIN, Math.min(VMAX, py));
108
+
109
+ function cubicAt(t: number, c0: number, c1: number, c2: number, c3: number): number {
110
+ const mt = 1 - t;
111
+ return mt * mt * mt * c0 + 3 * mt * mt * t * c1 + 3 * mt * t * t * c2 + t * t * t * c3;
112
+ }
113
+
81
114
  export function EaseCurveSection({
82
115
  ease,
83
116
  duration,
@@ -90,25 +123,26 @@ export function EaseCurveSection({
90
123
  const isCustom = ease.startsWith("custom(");
91
124
  const curveFromPreset = EASE_CURVES[ease];
92
125
  const customPoints = isCustom ? parseCustomEaseFromString(ease) : null;
93
- const curve: [number, number, number, number] | null =
126
+ const curve: Pts | null =
94
127
  isCustom && customPoints
95
128
  ? [customPoints.x1, customPoints.y1, customPoints.x2, customPoints.y2]
96
129
  : (curveFromPreset ?? null);
97
130
 
98
- const [draft, setDraft] = useState<[number, number, number, number] | null>(null);
131
+ const [draft, setDraft] = useState<Pts | null>(null);
99
132
  const [progress, setProgress] = useState<number | null>(null);
133
+ const [hover, setHover] = useState<"p1" | "p2" | null>(null);
100
134
  const draggingRef = useRef<"p1" | "p2" | null>(null);
101
135
  const svgRef = useRef<SVGSVGElement | null>(null);
102
136
  const rafRef = useRef<number>(0);
103
137
 
104
138
  const play = useCallback(() => {
105
139
  const start = performance.now();
106
- const dur = 1000;
140
+ const dur = 1100;
107
141
  const tick = (now: number) => {
108
142
  const t = Math.min((now - start) / dur, 1);
109
143
  setProgress(t);
110
144
  if (t < 1) rafRef.current = requestAnimationFrame(tick);
111
- else setTimeout(() => setProgress(null), 400);
145
+ else setTimeout(() => setProgress(null), 450);
112
146
  };
113
147
  cancelAnimationFrame(rafRef.current);
114
148
  rafRef.current = requestAnimationFrame(tick);
@@ -118,27 +152,23 @@ export function EaseCurveSection({
118
152
  if (!active) return null;
119
153
  const [x1, y1, x2, y2] = active;
120
154
 
121
- const w = 200;
122
- const h = 100;
123
- const pad = 14;
124
- const gw = w - pad * 2;
125
- const gh = h - pad * 2;
126
-
127
- const toSvg = (px: number, py: number) => ({
128
- x: pad + gw * px,
129
- y: h - pad - gh * py,
130
- });
155
+ // Anchors + control handles. Handle *display* is clamped to the view so an
156
+ // extreme loaded overshoot rides the edge instead of disappearing.
157
+ const a0 = { x: xToSvg(0), y: yToSvg(0) };
158
+ const a1 = { x: xToSvg(1), y: yToSvg(1) };
159
+ const p1 = { x: xToSvg(x1), y: yToSvg(clampView(y1)) };
160
+ const p2 = { x: xToSvg(x2), y: yToSvg(clampView(y2)) };
161
+ // Curve drawn from the true control points (so its shape is exact).
162
+ const cp1 = { x: xToSvg(x1), y: yToSvg(y1) };
163
+ const cp2 = { x: xToSvg(x2), y: yToSvg(y2) };
164
+ const curvePath = `M${a0.x},${a0.y} C${cp1.x},${cp1.y} ${cp2.x},${cp2.y} ${a1.x},${a1.y}`;
131
165
 
132
- const curvePath = `M${pad},${h - pad} C${toSvg(x1, y1).x},${toSvg(x1, y1).y} ${toSvg(x2, y2).x},${toSvg(x2, y2).y} ${w - pad},${pad}`;
133
-
134
- let dotX = pad;
135
- let dotY = h - pad;
166
+ let dot: { x: number; y: number } | null = null;
136
167
  if (progress !== null) {
137
- const t = progress;
138
- const mt = 1 - t;
139
- dotX = pad + gw * (mt * mt * mt * 0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t);
140
- dotY =
141
- h - pad - gh * (mt * mt * mt * 0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t);
168
+ dot = {
169
+ x: xToSvg(cubicAt(progress, 0, x1, x2, 1)),
170
+ y: yToSvg(cubicAt(progress, 0, y1, y2, 1)),
171
+ };
142
172
  }
143
173
 
144
174
  const handlePointerDown = (handle: "p1" | "p2", e: React.PointerEvent) => {
@@ -153,12 +183,16 @@ export function EaseCurveSection({
153
183
  if (!draggingRef.current || !svgRef.current) return;
154
184
  e.preventDefault();
155
185
  const rect = svgRef.current.getBoundingClientRect();
156
- const sx = ((e.clientX - rect.left) / rect.width) * w;
157
- const sy = ((e.clientY - rect.top) / rect.height) * h;
158
- const px = Math.max(0, Math.min(1, (sx - pad) / gw));
159
- const py = Math.max(-1, Math.min(2, (h - pad - sy) / gh));
186
+ const sx = ((e.clientX - rect.left) / rect.width) * SVGW;
187
+ const sy = ((e.clientY - rect.top) / rect.height) * SVGH;
188
+ // px is clamped to [0,1] on purpose: a cubic-bezier ease must be monotonic in
189
+ // time (handle1.x ≤ handle2.x), so handles can't pass each other or invert.
190
+ const px = Math.max(0, Math.min(1, (sx - PADH) / S));
191
+ // py uses the WIDER drag bound (not clampView), so dragging keeps overshoot
192
+ // fidelity instead of pinning the committed value to the visible view edge.
193
+ const py = Math.max(DRAG_VMIN, Math.min(DRAG_VMAX, 1 - (sy - HR) / S));
160
194
  const prev = draft ?? [x1, y1, x2, y2];
161
- const next: [number, number, number, number] =
195
+ const next: Pts =
162
196
  draggingRef.current === "p1"
163
197
  ? [round2(px), round2(py), prev[2], prev[3]]
164
198
  : [prev[0], prev[1], round2(px), round2(py)];
@@ -173,11 +207,12 @@ export function EaseCurveSection({
173
207
  setDraft(null);
174
208
  };
175
209
 
176
- const p1 = toSvg(x1, y1);
177
- const p2 = toSvg(x2, y2);
178
- const start = toSvg(0, 0);
179
- const end = toSvg(1, 1);
210
+ const top = yToSvg(1);
211
+ const bottom = yToSvg(0);
212
+ const left = xToSvg(0);
213
+ const right = xToSvg(1);
180
214
  const label = isCustom ? "Custom curve" : (EASE_LABELS[ease] ?? ease);
215
+ const bezierText = `${x1} · ${y1} · ${x2} · ${y2}`;
181
216
 
182
217
  return (
183
218
  <div className="rounded-lg bg-neutral-900/50 p-2">
@@ -193,98 +228,139 @@ export function EaseCurveSection({
193
228
  </button>
194
229
  </div>
195
230
  <div
196
- className="overflow-hidden rounded pt-[72px] -mt-[72px]"
197
- style={{ aspectRatio: `${w}/${h}` }}
231
+ className="mx-auto overflow-hidden rounded-md border border-white/5 bg-black/20"
232
+ style={{ aspectRatio: `${SVGW} / ${SVGH}`, width: "100%", maxWidth: 230 }}
198
233
  >
199
234
  <svg
200
235
  ref={svgRef}
201
236
  width="100%"
202
237
  height="100%"
203
- viewBox={`0 0 ${w} ${h}`}
238
+ viewBox={`0 0 ${SVGW} ${SVGH}`}
204
239
  preserveAspectRatio="none"
205
- style={{ overflow: "visible" }}
206
240
  className="touch-none select-none"
207
241
  onPointerMove={handlePointerMove}
208
242
  onPointerUp={handlePointerUp}
209
243
  onPointerCancel={handlePointerUp}
210
244
  >
211
- <line
212
- x1={pad}
213
- y1={h - pad}
214
- x2={w - pad}
215
- y2={h - pad}
245
+ {/* Grid — quarter lines inside the unit square */}
246
+ {[0.25, 0.5, 0.75].map((q) => (
247
+ <line
248
+ key={`v${q}`}
249
+ x1={xToSvg(q)}
250
+ y1={top}
251
+ x2={xToSvg(q)}
252
+ y2={bottom}
253
+ stroke="white"
254
+ strokeOpacity="0.05"
255
+ strokeWidth="1"
256
+ />
257
+ ))}
258
+ {[0.25, 0.5, 0.75].map((q) => (
259
+ <line
260
+ key={`h${q}`}
261
+ x1={left}
262
+ y1={yToSvg(q)}
263
+ x2={right}
264
+ y2={yToSvg(q)}
265
+ stroke="white"
266
+ strokeOpacity="0.05"
267
+ strokeWidth="1"
268
+ />
269
+ ))}
270
+ {/* Unit-square frame (progress 0 → 1) */}
271
+ <rect
272
+ x={left}
273
+ y={top}
274
+ width={S}
275
+ height={bottom - top}
276
+ fill="none"
216
277
  stroke="white"
217
- strokeOpacity="0.06"
218
- strokeWidth="0.5"
278
+ strokeOpacity="0.1"
279
+ strokeWidth="1"
219
280
  />
281
+ {/* Linear reference diagonal */}
220
282
  <line
221
- x1={pad}
222
- y1={pad}
223
- x2={pad}
224
- y2={h - pad}
283
+ x1={a0.x}
284
+ y1={a0.y}
285
+ x2={a1.x}
286
+ y2={a1.y}
225
287
  stroke="white"
226
- strokeOpacity="0.06"
227
- strokeWidth="0.5"
288
+ strokeOpacity="0.08"
289
+ strokeWidth="1"
290
+ strokeDasharray="3 4"
228
291
  />
292
+ {/* Tangent handle lines */}
229
293
  <line
230
- x1={start.x}
231
- y1={start.y}
294
+ x1={a0.x}
295
+ y1={a0.y}
232
296
  x2={p1.x}
233
297
  y2={p1.y}
234
- stroke="rgba(52,211,153,0.25)"
235
- strokeWidth="1"
298
+ stroke={ACCENT}
299
+ strokeOpacity="0.5"
300
+ strokeWidth="1.5"
236
301
  />
237
302
  <line
238
- x1={end.x}
239
- y1={end.y}
303
+ x1={a1.x}
304
+ y1={a1.y}
240
305
  x2={p2.x}
241
306
  y2={p2.y}
242
- stroke="rgba(45,212,191,0.25)"
243
- strokeWidth="1"
307
+ stroke={ACCENT}
308
+ strokeOpacity="0.5"
309
+ strokeWidth="1.5"
244
310
  />
245
- <path d={curvePath} fill="none" stroke="#3CE6AC" strokeWidth="2" strokeLinecap="round" />
246
- {progress !== null && <circle cx={dotX} cy={dotY} r="4" fill="#3CE6AC" />}
247
- <circle
248
- cx={p1.x}
249
- cy={p1.y}
250
- r="5"
251
- fill="#0a0a1a"
252
- stroke="#3CE6AC"
253
- strokeWidth="2"
254
- className="cursor-grab active:cursor-grabbing"
255
- onPointerDown={(e) => handlePointerDown("p1", e)}
256
- />
257
- <circle
258
- cx={p2.x}
259
- cy={p2.y}
260
- r="5"
261
- fill="#0a0a1a"
262
- stroke="#3CE6AC"
263
- strokeWidth="2"
264
- className="cursor-grab active:cursor-grabbing"
265
- onPointerDown={(e) => handlePointerDown("p2", e)}
266
- />
267
- {duration != null && duration > 0 && (
311
+ {/* The curve */}
312
+ <path d={curvePath} fill="none" stroke={ACCENT} strokeWidth="2.5" strokeLinecap="round" />
313
+ {/* Anchors at (0,0) and (1,1) */}
314
+ <circle cx={a0.x} cy={a0.y} r="3" fill={ACCENT} />
315
+ <circle cx={a1.x} cy={a1.y} r="3" fill={ACCENT} />
316
+ {/* Animated preview dot */}
317
+ {dot && (
268
318
  <>
269
- <text x={pad} y={h - 1} textAnchor="start" className="fill-neutral-600 text-[8px]">
270
- 0s
271
- </text>
272
- <text
273
- x={pad + gw / 2}
274
- y={h - 1}
275
- textAnchor="middle"
276
- className="fill-neutral-600 text-[8px]"
277
- >
278
- {(duration / 2).toFixed(1)}s
279
- </text>
280
- <text x={w - pad} y={h - 1} textAnchor="end" className="fill-neutral-600 text-[8px]">
281
- {duration}s
282
- </text>
319
+ <circle cx={dot.x} cy={dot.y} r="9" fill={ACCENT} fillOpacity="0.18" />
320
+ <circle cx={dot.x} cy={dot.y} r="4.5" fill={ACCENT} />
283
321
  </>
284
322
  )}
323
+ {/* Draggable control handles (large transparent hit area + visible dot) */}
324
+ {[["p1", p1] as const, ["p2", p2] as const].map(([key, pt]) => (
325
+ <g key={key}>
326
+ <circle
327
+ cx={pt.x}
328
+ cy={pt.y}
329
+ r="14"
330
+ fill="transparent"
331
+ className="cursor-grab active:cursor-grabbing"
332
+ onPointerDown={(e) => handlePointerDown(key, e)}
333
+ onPointerEnter={() => setHover(key)}
334
+ onPointerLeave={() => setHover((h) => (h === key ? null : h))}
335
+ />
336
+ <circle
337
+ cx={pt.x}
338
+ cy={pt.y}
339
+ r={hover === key || draggingRef.current === key ? 7 : 5.5}
340
+ fill="#0a0a1a"
341
+ stroke={ACCENT}
342
+ strokeWidth="2.5"
343
+ className="pointer-events-none transition-[r]"
344
+ />
345
+ </g>
346
+ ))}
285
347
  </svg>
286
348
  </div>
287
- <p className="mt-1 text-center text-[10px] text-neutral-500">{label}</p>
349
+ {/* Axis + value readout */}
350
+ <div className="mt-1.5 flex items-center justify-between px-0.5 text-[9px] text-neutral-600">
351
+ <span>{duration != null && duration > 0 ? "0s" : "start"}</span>
352
+ <span className="tracking-wide text-neutral-500">time →</span>
353
+ <span>{duration != null && duration > 0 ? `${duration}s` : "end"}</span>
354
+ </div>
355
+ <div className="mt-1 flex items-center justify-between px-0.5">
356
+ <span className="text-[10px] text-neutral-400">{label}</span>
357
+ <span
358
+ className="font-mono text-[9px] tracking-tight text-neutral-600"
359
+ title="cubic-bezier control points"
360
+ >
361
+ {bezierText}
362
+ </span>
363
+ </div>
288
364
  </div>
289
365
  );
290
366
  }
@@ -30,6 +30,8 @@ export const GsapAnimationSection = memo(function GsapAnimationSection({
30
30
  onLivePreviewEnd,
31
31
  onSetArcPath,
32
32
  onUpdateArcSegment,
33
+ onUpdateKeyframeEase,
34
+ onSetAllKeyframeEases,
33
35
  onUnroll,
34
36
  }: GsapAnimationSectionProps) {
35
37
  const [addMenuOpen, setAddMenuOpen] = useState(false);
@@ -68,6 +70,8 @@ export const GsapAnimationSection = memo(function GsapAnimationSection({
68
70
  onLivePreviewEnd={onLivePreviewEnd}
69
71
  onSetArcPath={onSetArcPath}
70
72
  onUpdateArcSegment={onUpdateArcSegment}
73
+ onUpdateKeyframeEase={onUpdateKeyframeEase}
74
+ onSetAllKeyframeEases={onSetAllKeyframeEases}
71
75
  onUnroll={onUnroll}
72
76
  />
73
77
  ))}
@@ -0,0 +1,127 @@
1
+ import type { GsapPercentageKeyframe } from "@hyperframes/core/gsap-parser";
2
+ import { EASE_LABELS } from "./gsapAnimationConstants";
3
+ import { EaseCurveSection } from "./EaseCurveSection";
4
+
5
+ // The full GSAP easing vocabulary offered by the "Set all…" bulk control —
6
+ // every standard family in in/out/inOut, so authors aren't limited to a curated
7
+ // few. All are valid GSAP runtime eases; the non-cubic families (sine/circ/
8
+ // elastic/bounce) approximate in the per-segment curve preview.
9
+ const APPLY_ALL_EASES = [
10
+ "none",
11
+ "power1.in",
12
+ "power1.out",
13
+ "power1.inOut",
14
+ "power2.in",
15
+ "power2.out",
16
+ "power2.inOut",
17
+ "power3.in",
18
+ "power3.out",
19
+ "power3.inOut",
20
+ "power4.in",
21
+ "power4.out",
22
+ "power4.inOut",
23
+ "sine.in",
24
+ "sine.out",
25
+ "sine.inOut",
26
+ "expo.in",
27
+ "expo.out",
28
+ "expo.inOut",
29
+ "circ.in",
30
+ "circ.out",
31
+ "circ.inOut",
32
+ "back.in",
33
+ "back.out",
34
+ "back.inOut",
35
+ "elastic.in",
36
+ "elastic.out",
37
+ "elastic.inOut",
38
+ "bounce.in",
39
+ "bounce.out",
40
+ "bounce.inOut",
41
+ ] as const;
42
+
43
+ export function KeyframeEaseList({
44
+ keyframes,
45
+ globalEase,
46
+ expandedPct,
47
+ onToggle,
48
+ onEaseCommit,
49
+ onApplyAll,
50
+ }: {
51
+ keyframes: GsapPercentageKeyframe[];
52
+ globalEase: string;
53
+ expandedPct: number | null;
54
+ onToggle: (pct: number | null) => void;
55
+ onEaseCommit: (pct: number, ease: string) => void;
56
+ /** Apply one ease to every segment at once (clears per-segment overrides). */
57
+ onApplyAll?: (ease: string) => void;
58
+ }) {
59
+ return (
60
+ <div className="space-y-1">
61
+ <div className="flex items-center gap-2">
62
+ <p className="text-[9px] font-semibold uppercase tracking-wider text-neutral-500">
63
+ Per-keyframe easing
64
+ </p>
65
+ {onApplyAll && (
66
+ <select
67
+ aria-label="Apply one ease to all segments"
68
+ title="Apply one ease to every segment (clears per-segment overrides)"
69
+ value=""
70
+ onChange={(e) => {
71
+ const next = e.target.value;
72
+ if (next) onApplyAll(next);
73
+ }}
74
+ className="ml-auto cursor-pointer rounded bg-neutral-800 px-1.5 py-0.5 text-[9px] text-neutral-300 outline-none hover:bg-neutral-700 focus:ring-1 focus:ring-panel-accent/40"
75
+ >
76
+ <option value="" disabled>
77
+ Set all…
78
+ </option>
79
+ {APPLY_ALL_EASES.map((name) => (
80
+ <option key={name} value={name}>
81
+ {EASE_LABELS[name] ?? name}
82
+ </option>
83
+ ))}
84
+ </select>
85
+ )}
86
+ </div>
87
+ {keyframes.map((kf, i) => {
88
+ if (i === 0) return null;
89
+ const segEase = kf.ease ?? globalEase;
90
+ const isExpanded = expandedPct === kf.percentage;
91
+ const label = `${keyframes[i - 1].percentage}% → ${kf.percentage}%`;
92
+ const easeLabel = segEase.startsWith("custom(")
93
+ ? "Custom"
94
+ : (EASE_LABELS[segEase] ?? segEase);
95
+ return (
96
+ <div key={`${i}-${kf.percentage}`} className="rounded-md bg-neutral-900/50">
97
+ <button
98
+ type="button"
99
+ onClick={() => onToggle(isExpanded ? null : kf.percentage)}
100
+ className="flex w-full items-center gap-2 px-2 py-1.5 text-left"
101
+ >
102
+ <span className="text-[10px] font-medium text-neutral-400">{label}</span>
103
+ <span className="ml-auto text-[9px] text-neutral-500">{easeLabel}</span>
104
+ <svg
105
+ width="8"
106
+ height="8"
107
+ viewBox="0 0 10 10"
108
+ fill="currentColor"
109
+ className={`text-neutral-500 transition-transform ${isExpanded ? "" : "-rotate-90"}`}
110
+ >
111
+ <path d="M2 3l3 4 3-4z" />
112
+ </svg>
113
+ </button>
114
+ {isExpanded && (
115
+ <div className="px-2 pb-2">
116
+ <EaseCurveSection
117
+ ease={segEase}
118
+ onCustomEaseCommit={(ease) => onEaseCommit(kf.percentage, ease)}
119
+ />
120
+ </div>
121
+ )}
122
+ </div>
123
+ );
124
+ })}
125
+ </div>
126
+ );
127
+ }
@@ -0,0 +1,111 @@
1
+ import React from "react";
2
+ import { type DomEditSelection } from "./domEditing";
3
+
4
+ export interface OffCanvasRect {
5
+ key: string;
6
+ left: number;
7
+ top: number;
8
+ width: number;
9
+ height: number;
10
+ }
11
+
12
+ interface OffCanvasIndicatorsProps {
13
+ rects: OffCanvasRect[];
14
+ elements: React.MutableRefObject<Map<string, HTMLElement>>;
15
+ compRect: { left: number; top: number; width: number; height: number };
16
+ selection: DomEditSelection | null;
17
+ groupSelections: DomEditSelection[];
18
+ activeCompositionPathRef: React.MutableRefObject<string | null>;
19
+ onSelectionChangeRef: React.MutableRefObject<
20
+ (selection: DomEditSelection, options?: { revealPanel?: boolean; additive?: boolean }) => void
21
+ >;
22
+ }
23
+
24
+ /**
25
+ * Dashed teal indicators for elements whose bounds extend past the composition
26
+ * (the "gray zone"). The in-canvas portion is clipped away so only the
27
+ * protruding sliver is dashed; the inside portion gets a solid outline.
28
+ * Extracted from DomEditOverlay to keep that file under the 600-LOC cap.
29
+ */
30
+ export function OffCanvasIndicators({
31
+ rects,
32
+ elements,
33
+ compRect,
34
+ selection,
35
+ groupSelections,
36
+ activeCompositionPathRef,
37
+ onSelectionChangeRef,
38
+ }: OffCanvasIndicatorsProps): React.ReactElement {
39
+ return (
40
+ <>
41
+ {rects
42
+ .filter((r) => {
43
+ // Suppress the indicator for any currently-selected element (primary
44
+ // OR a marquee group member) — those already render a selection box.
45
+ const el = elements.current.get(r.key);
46
+ if (!el) return true;
47
+ if (selection?.element === el) return false;
48
+ return !groupSelections.some((g) => g.element === el);
49
+ })
50
+ .map((r) => {
51
+ const pos = { left: r.left, top: r.top, width: r.width, height: r.height };
52
+ const cL = Math.max(0, compRect.left - r.left);
53
+ const cT = Math.max(0, compRect.top - r.top);
54
+ const cR = Math.min(r.width, compRect.left + compRect.width - r.left);
55
+ const cB = Math.min(r.height, compRect.top + compRect.height - r.top);
56
+ const hasInside = cL < cR && cT < cB;
57
+ const clipOutside = hasInside
58
+ ? `polygon(evenodd, 0 0, ${r.width}px 0, ${r.width}px ${r.height}px, 0 ${r.height}px, 0 0, ${cL}px ${cT}px, ${cR}px ${cT}px, ${cR}px ${cB}px, ${cL}px ${cB}px, ${cL}px ${cT}px)`
59
+ : undefined;
60
+ const clipInside = `inset(${cT}px ${Math.max(0, r.width - cR)}px ${Math.max(0, r.height - cB)}px ${cL}px round 6px)`;
61
+ const selectOffCanvas = async () => {
62
+ const el = elements.current.get(r.key);
63
+ if (!el) return;
64
+ const { resolveDomEditSelection } = await import("./domEditingLayers");
65
+ const acp = activeCompositionPathRef.current ?? "index.html";
66
+ const sel = await resolveDomEditSelection(el, {
67
+ activeCompositionPath: acp,
68
+ isMasterView: !acp || acp === "index.html",
69
+ skipSourceProbe: true,
70
+ });
71
+ if (sel) onSelectionChangeRef.current(sel, { revealPanel: true });
72
+ };
73
+ const handleClick = (e: React.MouseEvent) => {
74
+ e.stopPropagation();
75
+ void selectOffCanvas();
76
+ };
77
+ return (
78
+ <div key={`offcanvas-${r.key}`} className="pointer-events-none absolute" style={pos}>
79
+ {/* Dashed layer — clipped to exclude canvas area.
80
+ Note: clip-path is visual only — hit-testing still covers the
81
+ full bounding rect, so clicking the in-canvas portion selects
82
+ via this handler. That's acceptable: it resolves the same
83
+ element the normal canvas path would, just with
84
+ skipSourceProbe (the element is already known here). */}
85
+ <div
86
+ role="button"
87
+ tabIndex={0}
88
+ aria-label={`Select off-canvas element ${r.key}`}
89
+ className="pointer-events-auto absolute inset-0 border-2 border-dashed border-studio-accent/60 rounded-md cursor-pointer hover:border-studio-accent hover:bg-studio-accent/10 transition-colors"
90
+ style={clipOutside ? { clipPath: clipOutside } : undefined}
91
+ title={`Off-canvas: ${r.key} — click to select`}
92
+ onClick={handleClick}
93
+ onKeyDown={(e) => {
94
+ if (e.key === "Enter" || e.key === " ") {
95
+ e.preventDefault();
96
+ e.stopPropagation();
97
+ void selectOffCanvas();
98
+ }
99
+ }}
100
+ />
101
+ {/* Solid layer — clipped to canvas bounds, covers inside portion */}
102
+ <div
103
+ className="pointer-events-none absolute inset-0 border border-studio-accent/80 rounded-md bg-studio-accent/5 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]"
104
+ style={{ clipPath: clipInside }}
105
+ />
106
+ </div>
107
+ );
108
+ })}
109
+ </>
110
+ );
111
+ }