@hyperframes/studio 0.9.59 → 0.9.61

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 (47) hide show
  1. package/dist/assets/{hyperframes-player-bya4hgms.js → hyperframes-player-Cm0hYGm2.js} +1 -1
  2. package/dist/assets/{index-Bxh5lW0C.js → index-BGrNWeLK.js} +199 -199
  3. package/dist/assets/{index--dcfSUzI.js → index-REqr_dLu.js} +1 -1
  4. package/dist/assets/{pausedVideoDecoder-BKym1jA6.js → pausedVideoDecoder-DqLDSq8J.js} +1 -1
  5. package/dist/{chunk-5EEM5WO4.js → chunk-3KCEIESB.js} +1 -1
  6. package/dist/{chunk-G6FJSL7X.js → chunk-JTUKMELR.js} +34 -6
  7. package/dist/index.d.ts +28 -1
  8. package/dist/index.html +1 -1
  9. package/dist/index.js +689 -177
  10. package/dist/player.js +2 -2
  11. package/dist/ui.js +1 -1
  12. package/package.json +8 -8
  13. package/src/captions/components/CaptionOverlay.sealed.test.ts +273 -0
  14. package/src/captions/components/CaptionOverlay.tsx +112 -57
  15. package/src/captions/components/CaptionOverlayUtils.ts +319 -33
  16. package/src/captions/components/CaptionPropertyPanel.tsx +17 -0
  17. package/src/components/editor/LayersPanel.opaque.test.ts +2 -2
  18. package/src/components/editor/previewDrafts.test.ts +2 -2
  19. package/src/components/editor/previewGestureStartRead.test.ts +2 -2
  20. package/src/components/editor/previewLayers.test.ts +2 -2
  21. package/src/components/editor/previewOverlayRects.test.ts +2 -2
  22. package/src/components/editor/previewPointerTargets.test.ts +2 -2
  23. package/src/components/editor/previewSelection.test.ts +2 -2
  24. package/src/components/editor/useColorGradingController.sealed.test.ts +165 -0
  25. package/src/components/editor/useColorGradingController.ts +20 -1
  26. package/src/components/editor/useColorGradingPreviews.ts +127 -43
  27. package/src/components/nle/NLEPreview.test.ts +24 -0
  28. package/src/components/nle/NLEPreview.tsx +2 -6
  29. package/src/components/nle/previewStage.ts +11 -1
  30. package/src/components/panels/VariablesPanel.test.tsx +90 -1
  31. package/src/components/panels/VariablesPanel.tsx +41 -17
  32. package/src/components/panels/renderHandoff.test.ts +86 -0
  33. package/src/components/panels/renderHandoff.ts +28 -0
  34. package/src/components/ui/Menu.test.tsx +77 -0
  35. package/src/components/ui/Menu.tsx +47 -4
  36. package/src/components/ui/Popover.tsx +5 -2
  37. package/src/elementAnimations.test.ts +13 -0
  38. package/src/hooks/useCaptionDetection.ts +175 -54
  39. package/src/hooks/usePersistentEditHistory.test.ts +84 -0
  40. package/src/hooks/usePersistentEditHistory.ts +36 -3
  41. package/src/index.ts +1 -0
  42. package/src/player/hooks/useShadowPreviewReload.ts +7 -0
  43. package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +20 -0
  44. package/src/utils/gsapUndoRestore.sealed.test.ts +73 -0
  45. package/src/utils/gsapUndoRestore.ts +66 -0
  46. package/src/utils/studioPendingEdits.test.ts +20 -0
  47. package/src/utils/studioPendingEdits.ts +11 -4
package/dist/index.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  whileScriptWrites,
92
92
  writeStudioUiPreferences,
93
93
  zoomToSelectedClips
94
- } from "./chunk-5EEM5WO4.js";
94
+ } from "./chunk-3KCEIESB.js";
95
95
  import {
96
96
  Button,
97
97
  ContextMenu,
@@ -124,7 +124,7 @@ import {
124
124
  fieldText,
125
125
  menuItemBase,
126
126
  popupSurface
127
- } from "./chunk-G6FJSL7X.js";
127
+ } from "./chunk-JTUKMELR.js";
128
128
  import {
129
129
  DEFAULT_STUDIO_KEYS
130
130
  } from "./chunk-USW3YBOG.js";
@@ -5239,9 +5239,9 @@ function idFromSelector(selector) {
5239
5239
  if (!selector) return null;
5240
5240
  const hash = selector.match(/^#([\w-]+)/);
5241
5241
  if (hash) return hash[1] ?? null;
5242
- const attribute = selector.match(/^\[id="((?:\\.|[^"\\])*)"\]/);
5243
- if (!attribute) return null;
5244
- return (attribute[1] ?? "").replace(/\\(["\\])/g, "$1");
5242
+ const attribute2 = selector.match(/^\[id="((?:\\.|[^"\\])*)"\]/);
5243
+ if (!attribute2) return null;
5244
+ return (attribute2[1] ?? "").replace(/\\(["\\])/g, "$1");
5245
5245
  }
5246
5246
  var WHOLE_SELECTOR_ID = /^(#[\w-]+|\[id="(?:\\.|[^"\\])*"\])$/;
5247
5247
  function wholeSelectorElementId(selector) {
@@ -10053,6 +10053,10 @@ var historyClaims = () => 0;
10053
10053
  function setStudioPendingEditClaimClock(read2) {
10054
10054
  historyClaims = read2 ?? (() => 0);
10055
10055
  }
10056
+ var allSettled = null;
10057
+ function setStudioPendingEditsSettled(run) {
10058
+ allSettled = run;
10059
+ }
10056
10060
  var NOT_SAVED = () => Promise.resolve(false);
10057
10061
  var cancelWaitingPress = null;
10058
10062
  function setStudioWaitingPressCancel(cancel) {
@@ -10123,10 +10127,11 @@ function trackStudioPendingEdit(result) {
10123
10127
  showAgain: null,
10124
10128
  claimsAtBegin: historyClaims()
10125
10129
  });
10126
- promise.then(
10127
- () => pendingEdits.delete(promise),
10128
- () => pendingEdits.delete(promise)
10129
- );
10130
+ const done = () => {
10131
+ pendingEdits.delete(promise);
10132
+ if (!pendingEdits.size) allSettled?.();
10133
+ };
10134
+ promise.then(done, done);
10130
10135
  return promise;
10131
10136
  }
10132
10137
  var flushedSavesStillWriting = null;
@@ -16989,11 +16994,11 @@ function patchTagAttribute(tag, name, edit) {
16989
16994
  const attributes = scanHtmlOpeningTags(tag)[0]?.attributes.filter((attr3) => attr3.name === name.toLowerCase()) ?? [];
16990
16995
  const parts = [];
16991
16996
  let cursor = 0;
16992
- for (const attribute of attributes) {
16993
- let start = attribute.start;
16997
+ for (const attribute2 of attributes) {
16998
+ let start = attribute2.start;
16994
16999
  while (start > cursor && /[\t\n\f\r ]/.test(tag[start - 1])) start--;
16995
17000
  parts.push(tag.slice(cursor, start));
16996
- cursor = attribute.end;
17001
+ cursor = attribute2.end;
16997
17002
  }
16998
17003
  parts.push(tag.slice(cursor));
16999
17004
  return parts.join("");
@@ -17146,8 +17151,8 @@ function findTagByClass(html2, target) {
17146
17151
  }
17147
17152
  function servedSource(html2, target) {
17148
17153
  if (!target.hfId || findTagByTarget(html2, target)) return html2;
17149
- const stamped = stampHfIdsInPlace(html2);
17150
- return findTagByTarget(stamped, target) ? stamped : html2;
17154
+ const stamped2 = stampHfIdsInPlace(html2);
17155
+ return findTagByTarget(stamped2, target) ? stamped2 : html2;
17151
17156
  }
17152
17157
  function findTagByTarget(html2, target) {
17153
17158
  if (target.hfId) {
@@ -31835,6 +31840,10 @@ function shadowPagePhase(iframe) {
31835
31840
  return "no-player";
31836
31841
  }
31837
31842
  var pageGotTo = (iframe) => shadowPlayerReachable(iframe) ? "" : ` Its page had got to: ${shadowPagePhase(iframe)}.`;
31843
+ function hyperframesPlayerOf(iframe) {
31844
+ const root = iframe.getRootNode();
31845
+ return root instanceof ShadowRoot ? root.host : null;
31846
+ }
31838
31847
  function isDocumentHidden() {
31839
31848
  return typeof document !== "undefined" && document.visibilityState === "hidden";
31840
31849
  }
@@ -32006,6 +32015,7 @@ function useShadowPreviewReload({
32006
32015
  live?.pause();
32007
32016
  const retired = iframeRef.current;
32008
32017
  iframeRef.current = shadow;
32018
+ hyperframesPlayerOf(shadow)?.toggleAttribute("inert", false);
32009
32019
  pending2.commit();
32010
32020
  shadowIframeRef.current = null;
32011
32021
  attachIframeShortcutListeners();
@@ -32112,6 +32122,7 @@ function useShadowPreviewReload({
32112
32122
  armReadyTimerRef.current = armReadyTimer;
32113
32123
  const setShadowIframeNode = useCallback40((node) => {
32114
32124
  shadowIframeRef.current = node;
32125
+ if (node) hyperframesPlayerOf(node)?.toggleAttribute("inert", true);
32115
32126
  const gen = budgetGenRef.current;
32116
32127
  if (!node || !shadowFrameLeftPageRef.current || gen == null || gen !== shadowGenRef.current)
32117
32128
  return;
@@ -34115,6 +34126,13 @@ var SHADOW_IFRAME_STYLE = {
34115
34126
  clipPath: "inset(100%)",
34116
34127
  pointerEvents: "none"
34117
34128
  };
34129
+ var RENDERING_SHADOW_IFRAME_STYLE = {
34130
+ position: "absolute",
34131
+ inset: 0,
34132
+ opacity: 0,
34133
+ pointerEvents: "none"
34134
+ };
34135
+ var shadowIframeStyle = (sandboxOrigin) => sandboxOrigin === "opaque" ? RENDERING_SHADOW_IFRAME_STYLE : SHADOW_IFRAME_STYLE;
34118
34136
  function resolvePreviewStageSize(viewportWidth, viewportHeight, compositionSize, portrait, gutterPx = 0, insetPx = PREVIEW_STAGE_INSET_PX) {
34119
34137
  const availableWidth = Math.max(0, viewportWidth - 2 * (insetPx + gutterPx));
34120
34138
  const availableHeight = Math.max(0, viewportHeight - 2 * (insetPx + gutterPx));
@@ -34681,7 +34699,7 @@ var NLEPreview = memo24(function NLEPreview2({
34681
34699
  suppressLoadingOverlay: true,
34682
34700
  noLoadTimeout: true,
34683
34701
  sandboxOrigin,
34684
- style: SHADOW_IFRAME_STYLE
34702
+ style: shadowIframeStyle(sandboxOrigin)
34685
34703
  },
34686
34704
  `${activeKey}-${slot.gen}`
34687
34705
  )
@@ -37202,6 +37220,36 @@ function resolveCaptionNudge(event, target) {
37202
37220
  }
37203
37221
 
37204
37222
  // src/captions/components/CaptionOverlayUtils.ts
37223
+ import {
37224
+ isPlainRecord as isPlainRecord2,
37225
+ MAX_CAPTION_TRANSFORM,
37226
+ MAX_DESCRIBE_HANDLES
37227
+ } from "@hyperframes/core/runtime/editing-port";
37228
+ function overlayPlacement(iframe, overlayEl) {
37229
+ const iframeDisplayRect = iframe.getBoundingClientRect();
37230
+ const overlayRect = overlayEl.getBoundingClientRect();
37231
+ const nativeW = parseFloat(iframe.style.width) || iframeDisplayRect.width;
37232
+ const cssScale = iframeDisplayRect.width / nativeW;
37233
+ const offsetX = iframeDisplayRect.left - overlayRect.left;
37234
+ const offsetY = iframeDisplayRect.top - overlayRect.top;
37235
+ return (x, y, width, height) => ({
37236
+ x: x * cssScale + offsetX,
37237
+ y: y * cssScale + offsetY,
37238
+ width: width * cssScale,
37239
+ height: height * cssScale
37240
+ });
37241
+ }
37242
+ function splitIntoSpans(doc, text3, into) {
37243
+ const frag = doc.createDocumentFragment();
37244
+ for (const word of text3.split(/\s+/).filter(Boolean)) {
37245
+ const span = doc.createElement("span");
37246
+ span.textContent = word + " ";
37247
+ span.style.display = "inline";
37248
+ frag.appendChild(span);
37249
+ into.push(span);
37250
+ }
37251
+ return frag;
37252
+ }
37205
37253
  function readWordBoxes(iframe, model, overlayEl) {
37206
37254
  let doc = null;
37207
37255
  let win = null;
@@ -37212,12 +37260,7 @@ function readWordBoxes(iframe, model, overlayEl) {
37212
37260
  return [];
37213
37261
  }
37214
37262
  if (!doc || !win) return [];
37215
- const iframeDisplayRect = iframe.getBoundingClientRect();
37216
- const overlayRect = overlayEl.getBoundingClientRect();
37217
- const nativeW = parseFloat(iframe.style.width) || iframeDisplayRect.width;
37218
- const cssScale = iframeDisplayRect.width / nativeW;
37219
- const offsetX = iframeDisplayRect.left - overlayRect.left;
37220
- const offsetY = iframeDisplayRect.top - overlayRect.top;
37263
+ const place = overlayPlacement(iframe, overlayEl);
37221
37264
  const groupEls = doc.querySelectorAll(".caption-group");
37222
37265
  const boxes = [];
37223
37266
  for (let gi = 0; gi < model.groupOrder.length; gi++) {
@@ -37241,29 +37284,14 @@ function readWordBoxes(iframe, model, overlayEl) {
37241
37284
  if (resolvedWordEls.length === 0 && groupEl.textContent?.trim()) {
37242
37285
  const textNode = groupEl.childNodes[0];
37243
37286
  if (textNode && textNode.nodeType === Node.TEXT_NODE) {
37244
- const words = (textNode.textContent || "").split(/\s+/).filter(Boolean);
37245
- const frag = doc.createDocumentFragment();
37246
- for (const word of words) {
37247
- const span = doc.createElement("span");
37248
- span.textContent = word + " ";
37249
- span.style.display = "inline";
37250
- frag.appendChild(span);
37251
- resolvedWordEls.push(span);
37252
- }
37253
- groupEl.replaceChild(frag, textNode);
37287
+ groupEl.replaceChild(
37288
+ splitIntoSpans(doc, textNode.textContent || "", resolvedWordEls),
37289
+ textNode
37290
+ );
37254
37291
  } else {
37255
37292
  const singleSpan = groupEl.querySelector(":scope > span");
37256
37293
  if (singleSpan && singleSpan.textContent?.trim()) {
37257
- const words = singleSpan.textContent.split(/\s+/).filter(Boolean);
37258
- const frag = doc.createDocumentFragment();
37259
- for (const word of words) {
37260
- const span = doc.createElement("span");
37261
- span.textContent = word + " ";
37262
- span.style.display = "inline";
37263
- frag.appendChild(span);
37264
- resolvedWordEls.push(span);
37265
- }
37266
- singleSpan.replaceWith(frag);
37294
+ singleSpan.replaceWith(splitIntoSpans(doc, singleSpan.textContent, resolvedWordEls));
37267
37295
  }
37268
37296
  }
37269
37297
  }
@@ -37277,10 +37305,7 @@ function readWordBoxes(iframe, model, overlayEl) {
37277
37305
  groupId,
37278
37306
  groupIndex: gi,
37279
37307
  wordIndex: wi,
37280
- x: rect.left * cssScale + offsetX,
37281
- y: rect.top * cssScale + offsetY,
37282
- width: rect.width * cssScale,
37283
- height: rect.height * cssScale
37308
+ ...place(rect.left, rect.top, rect.width, rect.height)
37284
37309
  });
37285
37310
  }
37286
37311
  }
@@ -37364,6 +37389,17 @@ function isCaptionPreviewVisible() {
37364
37389
  function applyCaptionModelToIframe(model) {
37365
37390
  const iframe = registeredIframe?.current;
37366
37391
  if (!iframe) return;
37392
+ if (previewFrameOpaque(iframe)) {
37393
+ model.groupOrder.forEach(
37394
+ (groupId, group) => model.groups.get(groupId)?.segmentIds.forEach((segmentId, word) => {
37395
+ const s = model.segments.get(segmentId)?.style;
37396
+ if (!s) return;
37397
+ const set = { x: s.x ?? 0, y: s.y ?? 0, scale: s.scaleX ?? 1, rotation: s.rotation ?? 0 };
37398
+ void frameWordTransform(iframe, { group, word, set });
37399
+ })
37400
+ );
37401
+ return;
37402
+ }
37367
37403
  let win = null;
37368
37404
  try {
37369
37405
  win = iframe.contentWindow;
@@ -37385,8 +37421,9 @@ function applyCaptionModelToIframe(model) {
37385
37421
  }
37386
37422
  }
37387
37423
  function computeTransformStyle(el, iframeWin) {
37388
- const wrapper = getOrCreateWrapper(el);
37389
- const { x, y, scale, rotation } = readGsapTransform(wrapper, iframeWin);
37424
+ return transformStyle(readGsapTransform(getOrCreateWrapper(el), iframeWin));
37425
+ }
37426
+ function transformStyle({ x, y, scale, rotation }) {
37390
37427
  const style = {};
37391
37428
  if (Math.abs(x) > 0.5) style.x = x;
37392
37429
  if (Math.abs(y) > 0.5) style.y = y;
@@ -37397,6 +37434,138 @@ function computeTransformStyle(el, iframeWin) {
37397
37434
  if (Math.abs(rotation) > 0.1) style.rotation = rotation;
37398
37435
  return style;
37399
37436
  }
37437
+ var allFinite = (value, keys) => isPlainRecord2(value) && keys.every((key) => Number.isFinite(value[key]));
37438
+ var allBounded = (value, keys) => isPlainRecord2(value) && keys.every(
37439
+ (key) => Number.isFinite(value[key]) && Math.abs(value[key]) <= MAX_CAPTION_TRANSFORM
37440
+ );
37441
+ function readFrameWord(value) {
37442
+ if (!isPlainRecord2(value)) return null;
37443
+ const ok = allBounded(value.transform, ["x", "y", "scale", "rotation"]) && allFinite(value.rect, ["x", "y", "width", "height"]);
37444
+ return ok ? value : null;
37445
+ }
37446
+ function findCaptionWord(model, segmentId) {
37447
+ for (let group = 0; group < model.groupOrder.length; group++) {
37448
+ const word = model.groups.get(model.groupOrder[group])?.segmentIds.indexOf(segmentId) ?? -1;
37449
+ if (word >= 0) return { group, word };
37450
+ }
37451
+ return null;
37452
+ }
37453
+ async function readFrameWordBoxes(iframe, model, overlayEl) {
37454
+ const words = model.groupOrder.map((id) => model.groups.get(id)?.segmentIds.length ?? 0);
37455
+ const reply = await previewRequest(iframe, "caption-words", { words });
37456
+ const boxes = reply?.boxes;
37457
+ if (!Array.isArray(boxes)) return null;
37458
+ const place = overlayPlacement(iframe, overlayEl);
37459
+ return boxes.flatMap((box) => {
37460
+ if (!isPlainRecord2(box) || !allFinite(box.rect, ["x", "y", "width", "height"])) return [];
37461
+ const { group, word } = box;
37462
+ if (!Number.isSafeInteger(group) || !Number.isSafeInteger(word)) return [];
37463
+ const groupId = model.groupOrder[group];
37464
+ const segmentId = groupId && model.groups.get(groupId)?.segmentIds[word];
37465
+ if (!segmentId) return [];
37466
+ const { x, y, width, height } = box.rect;
37467
+ const at = place(x, y, width, height);
37468
+ return [{ segmentId, groupId, groupIndex: group, wordIndex: word, ...at }];
37469
+ });
37470
+ }
37471
+ var transformQueues = /* @__PURE__ */ new WeakMap();
37472
+ function sendTransforms(iframe, queue2) {
37473
+ if (queue2.sending || !queue2.ops.length) return;
37474
+ const ops = queue2.ops.splice(0, MAX_DESCRIBE_HANDLES);
37475
+ queue2.sending = true;
37476
+ const entries = ops.map((op) => op.entry);
37477
+ void previewRequest(iframe, "caption-transform", { entries }).then((reply) => {
37478
+ const words = reply?.words;
37479
+ ops.forEach((op, i) => {
37480
+ const word = Array.isArray(words) ? readFrameWord(words[i]) : null;
37481
+ op.done.forEach((done) => done(word));
37482
+ });
37483
+ }).finally(() => {
37484
+ queue2.sending = false;
37485
+ sendTransforms(iframe, queue2);
37486
+ });
37487
+ }
37488
+ function frameWordTransform(iframe, entry3) {
37489
+ let queue2 = transformQueues.get(iframe);
37490
+ if (!queue2) transformQueues.set(iframe, queue2 = { ops: [], sending: false });
37491
+ const { ops } = queue2;
37492
+ const promise = new Promise((resolve2) => {
37493
+ const last = ops[ops.length - 1];
37494
+ const sameWord = last?.entry.group === entry3.group && last.entry.word === entry3.word;
37495
+ if (last && sameWord && last.entry.set && entry3.set) {
37496
+ last.entry = { ...entry3, set: { ...last.entry.set, ...entry3.set } };
37497
+ last.done.push(resolve2);
37498
+ } else ops.push({ entry: entry3, done: [resolve2] });
37499
+ });
37500
+ sendTransforms(iframe, queue2);
37501
+ return promise;
37502
+ }
37503
+ function dragTransform(i, clientX, clientY, cssScale) {
37504
+ const orig = { x: i.origTX, y: i.origTY, scale: i.origScale, rotation: i.origRotation };
37505
+ if (i.type === "move") {
37506
+ const dx2 = (clientX - i.startMX) / cssScale;
37507
+ const dy = (clientY - i.startMY) / cssScale;
37508
+ return { ...orig, x: i.origTX + dx2, y: i.origTY + dy };
37509
+ }
37510
+ if (i.type === "scale") {
37511
+ const cx = i.startMX - i.startDxFromCenter;
37512
+ const startDist = Math.abs(i.startDxFromCenter);
37513
+ const currentDist = Math.abs(clientX - cx);
37514
+ const factor = startDist > 5 ? currentDist / startDist : 1;
37515
+ return { ...orig, scale: Math.max(0.1, i.origScale * factor) };
37516
+ }
37517
+ const dx = clientX - i.startMX;
37518
+ return { ...orig, rotation: i.origRotation + dx / 200 * 90 };
37519
+ }
37520
+ var restOf = (drag) => drag && { x: drag.origTX, y: drag.origTY, scale: drag.origScale, rotation: drag.origRotation };
37521
+ function toDragStart(type, { transform: t2, rect }, press) {
37522
+ const { startMX, startMY, cssScale, left } = press;
37523
+ const orig = { origTX: t2.x, origTY: t2.y, origScale: t2.scale, origRotation: t2.rotation };
37524
+ if (type === "move") return { type, startMX, startMY, ...orig };
37525
+ if (type === "rotate") return { type, startMX, ...orig };
37526
+ const boxCenterX = rect.x * cssScale + left + rect.width * cssScale / 2;
37527
+ return { type, startMX, startDxFromCenter: startMX - boxCenterX, ...orig };
37528
+ }
37529
+ async function nudgeFrameWord(iframe, word, dx, dy) {
37530
+ const now2 = await frameWordTransform(iframe, word);
37531
+ if (!now2) return null;
37532
+ const { x, y } = now2.transform;
37533
+ return frameWordTransform(iframe, { ...word, set: { x: x + dx, y: y + dy } });
37534
+ }
37535
+ function sealedNudger(live, onMoved) {
37536
+ let nudging = Promise.resolve();
37537
+ return (iframe, model, segmentIds, dx, dy) => {
37538
+ for (const segmentId of segmentIds) {
37539
+ const word = findCaptionWord(model, segmentId);
37540
+ if (!word) continue;
37541
+ nudging = nudging.then(async () => {
37542
+ if (!live()) return;
37543
+ const moved = await nudgeFrameWord(iframe, word, dx, dy);
37544
+ if (moved && live()) onMoved(segmentId, moved.transform);
37545
+ });
37546
+ }
37547
+ return nudging;
37548
+ };
37549
+ }
37550
+ function moveSealedDrag(drag, clientX, clientY, cssScale) {
37551
+ drag.last = drag.start.then(async (start) => {
37552
+ if (!start) return null;
37553
+ const set = dragTransform(start, clientX, clientY, cssScale);
37554
+ return (await frameWordTransform(drag.iframe, { ...drag.word, set }))?.transform ?? null;
37555
+ });
37556
+ }
37557
+ function restoreSealedDrag(drag) {
37558
+ void drag.start.then((start) => {
37559
+ const set = restOf(start);
37560
+ if (set) void frameWordTransform(drag.iframe, { ...drag.word, set });
37561
+ });
37562
+ }
37563
+ function pressSealedDrag(iframe, type, word, segmentId, press) {
37564
+ const start = frameWordTransform(iframe, word).then(
37565
+ (read2) => read2 && toDragStart(type, read2, press)
37566
+ );
37567
+ return { iframe, word, segmentId, start, last: start.then(restOf) };
37568
+ }
37400
37569
 
37401
37570
  // src/captions/components/CaptionOverlay.tsx
37402
37571
  import { Fragment as Fragment26, jsx as jsx98, jsxs as jsxs68 } from "react/jsx-runtime";
@@ -37404,7 +37573,9 @@ var HANDLE = 8;
37404
37573
  var HANDLE_HIT = 24;
37405
37574
  var ROTATION_OFFSET = 20;
37406
37575
  function syncToStore(segmentId, el, iframeWin) {
37407
- const style = computeTransformStyle(el, iframeWin);
37576
+ storeStyle(segmentId, computeTransformStyle(el, iframeWin));
37577
+ }
37578
+ function storeStyle(segmentId, style) {
37408
37579
  if (Object.keys(style).length > 0) {
37409
37580
  useCaptionStore.getState().updateSegmentStyle(segmentId, style);
37410
37581
  }
@@ -37421,19 +37592,46 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37421
37592
  const modelRef = useRef66(model);
37422
37593
  modelRef.current = model;
37423
37594
  const cancelDragRef = useRef66(null);
37424
- const interactionRef = useRef66(null);
37595
+ const interactionRef = useRef66(
37596
+ null
37597
+ );
37598
+ const sealedDragRef = useRef66(null);
37599
+ const liveRef = useRef66(false);
37425
37600
  useEffect50(() => {
37426
37601
  if (!isEditMode) return;
37602
+ liveRef.current = true;
37427
37603
  const unregisterIframe = registerCaptionIframe(iframeRef);
37428
37604
  let prevBoxes = [];
37429
37605
  let rafId = null;
37606
+ let disposed = false;
37607
+ let reading = false;
37608
+ let readAgain = false;
37430
37609
  const tick = () => {
37431
37610
  rafId = null;
37432
37611
  const iframe = iframeRef.current;
37433
37612
  const m = modelRef.current;
37434
37613
  const overlay = overlayRef.current;
37435
37614
  if (!iframe || !m || !overlay) return;
37436
- const next = readWordBoxes(iframe, m, overlay);
37615
+ if (previewFrameOpaque(iframe)) return readSealed(iframe, m, overlay);
37616
+ show(readWordBoxes(iframe, m, overlay));
37617
+ };
37618
+ const readSealed = (iframe, m, overlay) => {
37619
+ if (reading) {
37620
+ readAgain = true;
37621
+ return;
37622
+ }
37623
+ reading = true;
37624
+ void readFrameWordBoxes(iframe, m, overlay).then((next) => {
37625
+ reading = false;
37626
+ if (disposed) return;
37627
+ if (next) show(next);
37628
+ if (readAgain) {
37629
+ readAgain = false;
37630
+ scheduleTick();
37631
+ }
37632
+ });
37633
+ };
37634
+ const show = (next) => {
37437
37635
  if (next.length === prevBoxes.length && next.every(
37438
37636
  (b, i) => Math.abs(b.x - prevBoxes[i].x) < 0.5 && Math.abs(b.y - prevBoxes[i].y) < 0.5
37439
37637
  ))
@@ -37476,6 +37674,12 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37476
37674
  }
37477
37675
  };
37478
37676
  const cancelActiveDrag = () => {
37677
+ const sealed = sealedDragRef.current;
37678
+ if (sealed) {
37679
+ sealedDragRef.current = null;
37680
+ restoreSealedDrag(sealed);
37681
+ return true;
37682
+ }
37479
37683
  const i = interactionRef.current;
37480
37684
  if (!i) return false;
37481
37685
  const win = getWin();
@@ -37512,6 +37716,10 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37512
37716
  e.preventDefault();
37513
37717
  const { dx, dy } = nudge;
37514
37718
  const iframe = iframeRef.current;
37719
+ if (iframe && previewFrameOpaque(iframe)) {
37720
+ void nudgeSealed(iframe, m, sel, dx, dy).then(scheduleTick);
37721
+ return;
37722
+ }
37515
37723
  const win = iframe?.contentWindow;
37516
37724
  if (!iframe || !win) return;
37517
37725
  for (const segId of sel) {
@@ -37531,8 +37739,14 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37531
37739
  }
37532
37740
  scheduleTick();
37533
37741
  };
37742
+ const nudgeSealed = sealedNudger(
37743
+ () => !disposed,
37744
+ (segId, moved) => storeStyle(segId, transformStyle(moved))
37745
+ );
37534
37746
  window.addEventListener("keydown", handleKeyDown);
37535
37747
  return () => {
37748
+ disposed = true;
37749
+ liveRef.current = false;
37536
37750
  unregisterIframe();
37537
37751
  unsubPlayer();
37538
37752
  unsubPlayback();
@@ -37552,12 +37766,28 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37552
37766
  const nativeW = parseFloat(iframe.style.width) || rect.width;
37553
37767
  return rect.width / nativeW;
37554
37768
  }, [iframeRef]);
37769
+ const startSealedDrag = useCallback57(
37770
+ (type, word, segmentId, e) => {
37771
+ const iframe = iframeRef.current;
37772
+ if (!iframe) return;
37773
+ const press = {
37774
+ startMX: e.clientX,
37775
+ startMY: e.clientY,
37776
+ cssScale: getCssScale(),
37777
+ left: iframe.getBoundingClientRect().left
37778
+ };
37779
+ sealedDragRef.current = pressSealedDrag(iframe, type, word, segmentId, press);
37780
+ },
37781
+ [iframeRef, getCssScale]
37782
+ );
37555
37783
  const startMove = useCallback57(
37556
37784
  (groupIndex, wordIndex, segmentId, e) => {
37557
37785
  e.stopPropagation();
37558
37786
  e.currentTarget.setPointerCapture(e.pointerId);
37559
37787
  const iframe = iframeRef.current;
37560
37788
  if (!iframe) return;
37789
+ if (previewFrameOpaque(iframe))
37790
+ return startSealedDrag("move", { group: groupIndex, word: wordIndex }, segmentId, e);
37561
37791
  const wordEl = getWordEl(iframe, groupIndex, wordIndex);
37562
37792
  const win = iframe.contentWindow;
37563
37793
  if (!wordEl || !win) return;
@@ -37574,7 +37804,7 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37574
37804
  origRotation: state.rotation
37575
37805
  };
37576
37806
  },
37577
- [iframeRef]
37807
+ [iframeRef, startSealedDrag]
37578
37808
  );
37579
37809
  const startScale = useCallback57(
37580
37810
  (groupIndex, wordIndex, segmentId, e) => {
@@ -37583,6 +37813,8 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37583
37813
  e.currentTarget.setPointerCapture(e.pointerId);
37584
37814
  const iframe = iframeRef.current;
37585
37815
  if (!iframe) return;
37816
+ if (previewFrameOpaque(iframe))
37817
+ return startSealedDrag("scale", { group: groupIndex, word: wordIndex }, segmentId, e);
37586
37818
  const wordEl = getWordEl(iframe, groupIndex, wordIndex);
37587
37819
  const win = iframe.contentWindow;
37588
37820
  if (!wordEl || !win) return;
@@ -37602,7 +37834,7 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37602
37834
  origRotation: state.rotation
37603
37835
  };
37604
37836
  },
37605
- [iframeRef, getCssScale]
37837
+ [iframeRef, getCssScale, startSealedDrag]
37606
37838
  );
37607
37839
  const startRotate = useCallback57(
37608
37840
  (box, e) => {
@@ -37611,6 +37843,13 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37611
37843
  e.currentTarget.setPointerCapture(e.pointerId);
37612
37844
  const iframe = iframeRef.current;
37613
37845
  if (!iframe) return;
37846
+ if (previewFrameOpaque(iframe))
37847
+ return startSealedDrag(
37848
+ "rotate",
37849
+ { group: box.groupIndex, word: box.wordIndex },
37850
+ box.segmentId,
37851
+ e
37852
+ );
37614
37853
  const wordEl = getWordEl(iframe, box.groupIndex, box.wordIndex);
37615
37854
  const win = iframe.contentWindow;
37616
37855
  if (!wordEl || !win) return;
@@ -37626,7 +37865,7 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37626
37865
  origScale: state.scale
37627
37866
  };
37628
37867
  },
37629
- [iframeRef]
37868
+ [iframeRef, startSealedDrag]
37630
37869
  );
37631
37870
  const getIframeWin = useCallback57(() => {
37632
37871
  try {
@@ -37637,31 +37876,26 @@ var CaptionOverlay = memo27(function CaptionOverlay2({ iframeRef }) {
37637
37876
  }, [iframeRef]);
37638
37877
  const handlePointerMove = useCallback57(
37639
37878
  (e) => {
37879
+ const sealed = sealedDragRef.current;
37880
+ if (sealed) return moveSealedDrag(sealed, e.clientX, e.clientY, getCssScale());
37640
37881
  const i = interactionRef.current;
37641
37882
  if (!i) return;
37642
37883
  const win = getIframeWin();
37643
37884
  if (!win) return;
37644
- if (i.type === "move") {
37645
- const cssScale = getCssScale();
37646
- const dx = (e.clientX - i.startMX) / cssScale;
37647
- const dy = (e.clientY - i.startMY) / cssScale;
37648
- writeTransform(i.wordEl, win, i.origTX + dx, i.origTY + dy, i.origScale, i.origRotation);
37649
- } else if (i.type === "scale") {
37650
- const cx = i.startMX - i.startDxFromCenter;
37651
- const startDist = Math.abs(i.startDxFromCenter);
37652
- const currentDist = Math.abs(e.clientX - cx);
37653
- const factor = startDist > 5 ? currentDist / startDist : 1;
37654
- const newScale = Math.max(0.1, i.origScale * factor);
37655
- writeTransform(i.wordEl, win, i.origTX, i.origTY, newScale, i.origRotation);
37656
- } else if (i.type === "rotate") {
37657
- const dx = e.clientX - i.startMX;
37658
- const delta = dx / 200 * 90;
37659
- writeTransform(i.wordEl, win, i.origTX, i.origTY, i.origScale, i.origRotation + delta);
37660
- }
37885
+ const t2 = dragTransform(i, e.clientX, e.clientY, getCssScale());
37886
+ writeTransform(i.wordEl, win, t2.x, t2.y, t2.scale, t2.rotation);
37661
37887
  },
37662
37888
  [getCssScale, getIframeWin]
37663
37889
  );
37664
37890
  const handlePointerUp = useCallback57(() => {
37891
+ const sealed = sealedDragRef.current;
37892
+ if (sealed) {
37893
+ sealedDragRef.current = null;
37894
+ void sealed.last.then(
37895
+ (t2) => t2 && liveRef.current && storeStyle(sealed.segmentId, transformStyle(t2))
37896
+ );
37897
+ return;
37898
+ }
37665
37899
  const i = interactionRef.current;
37666
37900
  if (i) {
37667
37901
  const win = getIframeWin();
@@ -38554,12 +38788,12 @@ function isDomEditGestureTap(g, e) {
38554
38788
  }
38555
38789
 
38556
38790
  // src/components/editor/previewLayers.ts
38557
- import { MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES4 } from "@hyperframes/core/runtime/editing-port";
38791
+ import { MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES5 } from "@hyperframes/core/runtime/editing-port";
38558
38792
 
38559
38793
  // src/player/lib/previewElements.ts
38560
38794
  import {
38561
38795
  EDITING_ELEMENT_HANDLE,
38562
- MAX_DESCRIBE_HANDLES,
38796
+ MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES2,
38563
38797
  MAX_ELEMENT_ENTRIES,
38564
38798
  MAX_ELEMENT_VALUE,
38565
38799
  MAX_GEOMETRY_CHILDREN,
@@ -38607,7 +38841,7 @@ async function previewPointerTargets(iframe, rootFractionX, rootFractionY) {
38607
38841
  return { target: readHit(reply.target), stack: stack.map(readHit).filter((hit) => hit !== null) };
38608
38842
  }
38609
38843
  async function describePreviewElements(iframe, handles) {
38610
- if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
38844
+ if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES2) return null;
38611
38845
  const reply = await previewRequest(iframe, "describe", { handles: [...handles] });
38612
38846
  const elements = reply?.elements;
38613
38847
  if (!Array.isArray(elements) || elements.length !== handles.length) return null;
@@ -38617,7 +38851,7 @@ async function describePreviewElements(iframe, handles) {
38617
38851
  });
38618
38852
  }
38619
38853
  async function previewAncestors(iframe, handles) {
38620
- if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
38854
+ if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES2) return null;
38621
38855
  const reply = await previewRequest(iframe, "ancestors", { handles: [...handles] });
38622
38856
  const chains = reply?.ancestors;
38623
38857
  if (!Array.isArray(chains) || chains.length !== handles.length) return null;
@@ -38654,7 +38888,7 @@ var readGeometry = (value) => {
38654
38888
  return membersOk ? value : null;
38655
38889
  };
38656
38890
  async function previewGeometry(iframe, handles, children) {
38657
- if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
38891
+ if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES2) return null;
38658
38892
  const params = { handles: [...handles], ...children ? { children } : {} };
38659
38893
  const reply = await previewRequest(iframe, "geometry", params);
38660
38894
  const elements = reply?.elements;
@@ -38679,7 +38913,7 @@ var readGestureStart = (value) => {
38679
38913
  return valid.includes(false) ? null : value;
38680
38914
  };
38681
38915
  async function previewGestureStart(iframe, handles) {
38682
- if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
38916
+ if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES2) return null;
38683
38917
  const reply = await previewRequest(iframe, "gesture-start", { handles: [...handles] });
38684
38918
  const elements = reply?.elements;
38685
38919
  const snap = reply?.snap;
@@ -38701,7 +38935,7 @@ async function previewLayers(iframe, group, offset = 0) {
38701
38935
 
38702
38936
  // src/components/editor/previewOverlayRects.ts
38703
38937
  import {
38704
- MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES2,
38938
+ MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES3,
38705
38939
  ROTATION_GATE_EPSILON_DEG as ROTATION_GATE_EPSILON_DEG2
38706
38940
  } from "@hyperframes/core/runtime/editing-port";
38707
38941
  var clientRect = ({ x, y, width, height }) => ({ left: x, top: y, width, height });
@@ -38757,8 +38991,8 @@ async function measurePreviewOverlay(iframe, overlayEl, targets) {
38757
38991
  }
38758
38992
  async function measurePreviewVisibleRects(iframe, overlayEl, handles) {
38759
38993
  const measured = [];
38760
- for (let at = 0; at < handles.length; at += MAX_DESCRIBE_HANDLES2) {
38761
- const reply = await previewGeometry(iframe, handles.slice(at, at + MAX_DESCRIBE_HANDLES2));
38994
+ for (let at = 0; at < handles.length; at += MAX_DESCRIBE_HANDLES3) {
38995
+ const reply = await previewGeometry(iframe, handles.slice(at, at + MAX_DESCRIBE_HANDLES3));
38762
38996
  const scale = reply && computeOverlayRootScale(overlayEl, iframe, null);
38763
38997
  if (!reply || !scale) return null;
38764
38998
  for (const box of reply.elements) {
@@ -38778,7 +39012,7 @@ import {
38778
39012
  } from "@hyperframes/core/runtime/editing-port";
38779
39013
 
38780
39014
  // src/components/editor/previewDrafts.ts
38781
- import { MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES3 } from "@hyperframes/core/runtime/editing-port";
39015
+ import { MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES4 } from "@hyperframes/core/runtime/editing-port";
38782
39016
  var standIns = /* @__PURE__ */ new WeakMap();
38783
39017
  var queues = /* @__PURE__ */ new WeakMap();
38784
39018
  function registerPreviewStandIn(standIn, iframe, handle) {
@@ -38794,7 +39028,7 @@ function queueFor(iframe) {
38794
39028
  }
38795
39029
  function send2(iframe, queue2) {
38796
39030
  if (queue2.sending || !queue2.ops.length) return;
38797
- const drafts = queue2.ops.splice(0, MAX_DESCRIBE_HANDLES3);
39031
+ const drafts = queue2.ops.splice(0, MAX_DESCRIBE_HANDLES4);
38798
39032
  queue2.sending = true;
38799
39033
  void previewRequest(iframe, "draft", { drafts }).finally(() => {
38800
39034
  queue2.sending = false;
@@ -39341,10 +39575,10 @@ var selectionElementLive = (selection) => selection.handle !== void 0 || selecti
39341
39575
  // src/components/editor/previewLayers.ts
39342
39576
  async function describeAll(iframe, handles) {
39343
39577
  const described = [];
39344
- for (let at = 0; at < handles.length; at += MAX_DESCRIBE_HANDLES4) {
39578
+ for (let at = 0; at < handles.length; at += MAX_DESCRIBE_HANDLES5) {
39345
39579
  const part = await describePreviewElements(
39346
39580
  iframe,
39347
- handles.slice(at, at + MAX_DESCRIBE_HANDLES4)
39581
+ handles.slice(at, at + MAX_DESCRIBE_HANDLES5)
39348
39582
  );
39349
39583
  if (!part) return null;
39350
39584
  described.push(...part);
@@ -40482,9 +40716,9 @@ function captureStudioPathOffset(element) {
40482
40716
  originalInlineTranslate: element.getAttribute(STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR)
40483
40717
  };
40484
40718
  }
40485
- function restoreAttribute(element, attribute, value) {
40486
- if (value == null) element.removeAttribute(attribute);
40487
- else element.setAttribute(attribute, value);
40719
+ function restoreAttribute(element, attribute2, value) {
40720
+ if (value == null) element.removeAttribute(attribute2);
40721
+ else element.setAttribute(attribute2, value);
40488
40722
  }
40489
40723
  function restoreStyleProperty(element, property, value) {
40490
40724
  if (value) element.style.setProperty(property, value);
@@ -40574,11 +40808,11 @@ function restoreStudioPathOffsetStyles(element, previous) {
40574
40808
  element.removeAttribute("data-hf-drag-gsap-base-y");
40575
40809
  }
40576
40810
  }
40577
- function restoreOriginalBoxSizeProperty(element, property, attribute) {
40578
- const original = element.getAttribute(attribute);
40811
+ function restoreOriginalBoxSizeProperty(element, property, attribute2) {
40812
+ const original = element.getAttribute(attribute2);
40579
40813
  if (original == null || original === "") element.style.removeProperty(property);
40580
40814
  else element.style.setProperty(property, original);
40581
- element.removeAttribute(attribute);
40815
+ element.removeAttribute(attribute2);
40582
40816
  }
40583
40817
  function restoreOriginalRotationProperty(element) {
40584
40818
  const original = element.getAttribute(STUDIO_ORIGINAL_INLINE_ROTATE_ATTR);
@@ -58441,6 +58675,56 @@ function readRuntime(iframe) {
58441
58675
  return null;
58442
58676
  }
58443
58677
  }
58678
+ var PORT_PREVIEW_TIMEOUT_MS = 15e3;
58679
+ var isImageData = (value) => typeof value === "string" && value.startsWith("data:image/");
58680
+ function portBatch(batch) {
58681
+ if (typeof batch !== "object" || batch === null) return null;
58682
+ const { width, height, images } = batch;
58683
+ if (!Number.isFinite(width) || !Number.isFinite(height) || !Array.isArray(images)) return null;
58684
+ return {
58685
+ width,
58686
+ height,
58687
+ images: images.map((image) => {
58688
+ const { id, dataUrl } = image ?? {};
58689
+ return { id: String(id), dataUrl: isImageData(dataUrl) ? dataUrl : null };
58690
+ })
58691
+ };
58692
+ }
58693
+ function portRuntime(iframe) {
58694
+ return {
58695
+ renderPreviews: async (target, candidates, { maxDimension, useMediaTime = false }) => {
58696
+ const params = { target, candidates, maxDimension, useMediaTime };
58697
+ const reply = await previewRequest(
58698
+ iframe,
58699
+ "color-grading-previews",
58700
+ params,
58701
+ PORT_PREVIEW_TIMEOUT_MS
58702
+ );
58703
+ return portBatch(reply?.batch);
58704
+ }
58705
+ };
58706
+ }
58707
+ function previewRuntime(iframe) {
58708
+ return iframe && previewFrameOpaque(iframe) ? portRuntime(iframe) : readRuntime(iframe);
58709
+ }
58710
+ function playInSealedFrame(iframe, target, sessionRef, animate) {
58711
+ if (!iframe || !previewFrameOpaque(iframe)) return false;
58712
+ const stopPlayback = () => void previewRequest(iframe, "color-grading-playback", { target: null });
58713
+ const session = { stopPlayback, timer: null };
58714
+ sessionRef.current = session;
58715
+ void previewRequest(iframe, "color-grading-playback", { target }).then((reply) => {
58716
+ if (sessionRef.current !== session) return;
58717
+ if (reply?.started) animate(portRuntime(iframe), session);
58718
+ else sessionRef.current = null;
58719
+ });
58720
+ return true;
58721
+ }
58722
+ var STATUS_STATES = /* @__PURE__ */ new Set(["missing", "inactive", "pending", "active", "unavailable"]);
58723
+ async function readSealedColorGradingStatus(iframe, target) {
58724
+ const reply = await previewRequest(iframe, "color-grading-status", { target });
58725
+ const { state, message } = reply?.status ?? {};
58726
+ return STATUS_STATES.has(state) && typeof message === "string" ? { state, message } : { state: "pending", message: "Waiting for runtime" };
58727
+ }
58444
58728
  function previewMaxDimension() {
58445
58729
  return Math.min(320, Math.ceil(160 * Math.max(1, window.devicePixelRatio || 1)));
58446
58730
  }
@@ -58528,7 +58812,7 @@ function useColorGradingPreviews({
58528
58812
  }));
58529
58813
  const attempt = async () => {
58530
58814
  if (cancelled || complete || inFlight) return;
58531
- const runtime = readRuntime(iframe);
58815
+ const runtime = previewRuntime(iframe);
58532
58816
  if (!runtime) return;
58533
58817
  inFlight = true;
58534
58818
  try {
@@ -58606,44 +58890,49 @@ function useColorGradingPreviews({
58606
58890
  stopAnimatedPreview();
58607
58891
  postColorGrading(next ?? gradingRef.current);
58608
58892
  if (!next || !options) return;
58609
- const runtime = readRuntime(previewIframeRef?.current);
58610
- const stopPlayback = runtime?.startPreviewPlayback?.(target);
58611
- if (!runtime || !stopPlayback) return;
58612
- const session = { stopPlayback, timer: null };
58613
- animatedRef.current = session;
58614
- const renderFrame = async () => {
58615
- try {
58616
- const batch = await runtime.renderPreviews(
58617
- target,
58618
- [{ id: options.animatedPreview.id, grading: toPreviewColorGrading(next) }],
58619
- { maxDimension: previewMaxDimension(), useMediaTime: true }
58620
- );
58621
- const image = batch?.images[0]?.dataUrl;
58622
- if (animatedRef.current !== session || !batch || !image) return;
58623
- setState((current2) => ({
58624
- ...current2,
58625
- previews: {
58626
- ...current2.previews,
58627
- [options.animatedPreview.kind]: {
58628
- ...current2.previews[options.animatedPreview.kind],
58629
- status: "ready",
58630
- images: {
58631
- ...current2.previews[options.animatedPreview.kind].images,
58632
- [options.animatedPreview.id]: image
58633
- },
58634
- width: batch.width,
58635
- height: batch.height
58893
+ const animate = (runtime2, session2) => {
58894
+ const renderFrame = async () => {
58895
+ try {
58896
+ const batch = await runtime2.renderPreviews(
58897
+ target,
58898
+ [{ id: options.animatedPreview.id, grading: toPreviewColorGrading(next) }],
58899
+ { maxDimension: previewMaxDimension(), useMediaTime: true }
58900
+ );
58901
+ const image = batch?.images[0]?.dataUrl;
58902
+ if (animatedRef.current !== session2 || !batch || !image) return;
58903
+ setState((current2) => ({
58904
+ ...current2,
58905
+ previews: {
58906
+ ...current2.previews,
58907
+ [options.animatedPreview.kind]: {
58908
+ ...current2.previews[options.animatedPreview.kind],
58909
+ status: "ready",
58910
+ images: {
58911
+ ...current2.previews[options.animatedPreview.kind].images,
58912
+ [options.animatedPreview.id]: image
58913
+ },
58914
+ width: batch.width,
58915
+ height: batch.height
58916
+ }
58636
58917
  }
58918
+ }));
58919
+ } catch {
58920
+ } finally {
58921
+ if (animatedRef.current === session2) {
58922
+ session2.timer = window.setTimeout(() => void renderFrame(), 100);
58637
58923
  }
58638
- }));
58639
- } catch {
58640
- } finally {
58641
- if (animatedRef.current === session) {
58642
- session.timer = window.setTimeout(() => void renderFrame(), 100);
58643
58924
  }
58644
- }
58925
+ };
58926
+ void renderFrame();
58645
58927
  };
58646
- void renderFrame();
58928
+ const iframe = previewIframeRef?.current;
58929
+ if (playInSealedFrame(iframe, target, animatedRef, animate)) return;
58930
+ const runtime = readRuntime(iframe);
58931
+ const stopPlayback = runtime?.startPreviewPlayback?.(target);
58932
+ if (!runtime || !stopPlayback) return;
58933
+ const session = { stopPlayback, timer: null };
58934
+ animatedRef.current = session;
58935
+ animate(runtime, session);
58647
58936
  },
58648
58937
  [gradingRef, postColorGrading, previewIframeRef, stopAnimatedPreview, target]
58649
58938
  );
@@ -58667,7 +58956,7 @@ function useColorGradingPreviews({
58667
58956
  async ({
58668
58957
  grading: requestedGrading = gradingRef.current
58669
58958
  } = {}) => {
58670
- const runtime = readRuntime(previewIframeRef?.current);
58959
+ const runtime = previewRuntime(previewIframeRef?.current);
58671
58960
  if (!runtime) return null;
58672
58961
  const batch = await runtime.renderPreviews(
58673
58962
  target,
@@ -58828,8 +59117,9 @@ function useColorGradingController({
58828
59117
  }),
58829
59118
  [element.hfId, element.id, element.selector, element.selectorIndex]
58830
59119
  );
59120
+ const statusReadRef = useRef95(0);
58831
59121
  const refreshRuntimeStatus = useCallback86(() => {
58832
- setRuntimeStatus(readRuntimeColorGradingStatus(previewIframeRef?.current, target));
59122
+ refreshStatus(previewIframeRef?.current, target, statusReadRef, setRuntimeStatus);
58833
59123
  }, [previewIframeRef, target]);
58834
59124
  useEffect82(() => {
58835
59125
  setMediaMetadata(null);
@@ -59081,6 +59371,16 @@ function useColorGradingController({
59081
59371
  }
59082
59372
  };
59083
59373
  }
59374
+ function refreshStatus(iframe, target, reads, apply) {
59375
+ if (!iframe || !previewFrameOpaque(iframe)) {
59376
+ apply(readRuntimeColorGradingStatus(iframe, target));
59377
+ return;
59378
+ }
59379
+ const read2 = ++reads.current;
59380
+ void readSealedColorGradingStatus(iframe, target).then((status) => {
59381
+ if (read2 === reads.current) apply(status);
59382
+ });
59383
+ }
59084
59384
 
59085
59385
  // src/components/editor/propertyPanelColorGradingSection.tsx
59086
59386
  import { jsx as jsx137, jsxs as jsxs97 } from "react/jsx-runtime";
@@ -77525,6 +77825,7 @@ function useCaptionSync(projectId) {
77525
77825
 
77526
77826
  // src/hooks/usePersistentEditHistory.ts
77527
77827
  import { useCallback as useCallback104, useEffect as useEffect118, useMemo as useMemo71, useRef as useRef133, useState as useState121 } from "react";
77828
+ var APP_KEEPS_NO_HISTORY = 404;
77528
77829
  var EMPTY3 = { entries: [], back: null, forward: null };
77529
77830
  var OWN_ENTRIES_KEPT = 100;
77530
77831
  function createOwnHistory() {
@@ -77653,10 +77954,20 @@ function redoneAt(view) {
77653
77954
  const undo = view.entries.find((entry3) => entry3.id === view.forward?.id);
77654
77955
  return view.entries.find((entry3) => entry3.id === undo?.undoes)?.endedAt ?? null;
77655
77956
  }
77957
+ function closeHeldClaimWithAClaimOfNothing(projectId, heldClaimRef, refresh2) {
77958
+ if (!heldClaimRef.current) return Promise.resolve();
77959
+ heldClaimRef.current = null;
77960
+ return post(historyUrl(projectId, "/claim"), { label: "Edited in Studio", paths: [] }).then(
77961
+ (reply) => {
77962
+ if (reply.ok) void refresh2();
77963
+ }
77964
+ );
77965
+ }
77656
77966
  function usePersistentEditHistory({ projectId }) {
77657
77967
  const [view, setView] = useState121(EMPTY3);
77658
77968
  const [loaded, setLoaded] = useState121(false);
77659
77969
  const heldClaimRef = useRef133(null);
77970
+ const claimsAfterTheClose = useRef133(Promise.resolve());
77660
77971
  const projectIdRef = useRef133(projectId);
77661
77972
  projectIdRef.current = projectId;
77662
77973
  const [own] = useState121(createOwnHistory);
@@ -77683,11 +77994,23 @@ function usePersistentEditHistory({ projectId }) {
77683
77994
  setStudioPendingEditClaimClock(own.claimCount);
77684
77995
  return () => setStudioPendingEditClaimClock(null);
77685
77996
  }, [own]);
77997
+ useEffect118(() => {
77998
+ if (!projectId) return;
77999
+ setStudioPendingEditsSettled(() => {
78000
+ claimsAfterTheClose.current = closeHeldClaimWithAClaimOfNothing(
78001
+ projectId,
78002
+ heldClaimRef,
78003
+ refresh2
78004
+ );
78005
+ });
78006
+ return () => setStudioPendingEditsSettled(null);
78007
+ }, [projectId, refresh2]);
77686
78008
  const recordEdit = useCallback104(
77687
78009
  async ({ label, coalesceKey, coalesceMs, files, targets, created = [] }) => {
77688
78010
  if (!projectId) return;
77689
78011
  const paths = [...Object.keys(files), ...created];
77690
78012
  own.overtake();
78013
+ await claimsAfterTheClose.current;
77691
78014
  const reply = await post(historyUrl(projectId, "/claim"), {
77692
78015
  label,
77693
78016
  paths,
@@ -77726,7 +78049,8 @@ function usePersistentEditHistory({ projectId }) {
77726
78049
  );
77727
78050
  heldClaimRef.current = null;
77728
78051
  void refresh2();
77729
- if (!posted.ok && posted.status === 404) return { ok: false, reason: "empty" };
78052
+ if (!posted.ok && posted.status === APP_KEEPS_NO_HISTORY)
78053
+ return { ok: false, reason: "empty" };
77730
78054
  if (!posted.ok) return { ok: false, reason: "failed", message: posted.error };
77731
78055
  const reply = posted.body;
77732
78056
  if (!reply.ok) {
@@ -78796,6 +79120,47 @@ function repaintWhileReloading(win, doc, restored) {
78796
79120
  extractGsapScriptText(restored)
78797
79121
  );
78798
79122
  }
79123
+ var restoredAttributes = (el) => el.getAttributeNames().map((name) => [name, el.getAttribute(name) ?? ""]);
79124
+ var stamped = (html2) => html2.includes("data-hf-id") ? html2 : ensureHfIds2(html2);
79125
+ function sealedFile(file, isActive) {
79126
+ if (extractGsapScriptText(file.restored) !== extractGsapScriptText(file.previous)) return null;
79127
+ const prevDoc = parseRestoreSource(stamped(file.previous));
79128
+ const nextDoc = parseRestoreSource(stamped(file.restored));
79129
+ const scripted = restoreScripted(prevDoc, nextDoc, isActive);
79130
+ const keys = diffRestoreDocs(prevDoc, nextDoc);
79131
+ const restoredByKey = identityElementMap(nextDoc);
79132
+ if (scripted === null || !keys || !restoredByKey) return null;
79133
+ const elements = keys.map((key) => ({
79134
+ key,
79135
+ attributes: restoredAttributes(restoredByKey.get(key))
79136
+ }));
79137
+ return { scripted, elements };
79138
+ }
79139
+ function sealedRestore(activeDocPath, files) {
79140
+ const restore2 = { scopes: [], scripted: false };
79141
+ for (const [path, file] of Object.entries(files)) {
79142
+ const isActive = path === activeDocPath;
79143
+ const found = sealedFile(file, isActive);
79144
+ if (!found) return null;
79145
+ restore2.scripted ||= found.scripted;
79146
+ if (found.elements.length)
79147
+ restore2.scopes.push({ file: isActive ? null : path, elements: found.elements });
79148
+ }
79149
+ return restore2.scopes.length ? restore2 : null;
79150
+ }
79151
+ function applySealedRestore(iframe, activeDocPath, files, currentTime, reloadPreview) {
79152
+ const restore2 = sealedRestore(activeDocPath, files);
79153
+ if (!restore2) {
79154
+ reloadPreview();
79155
+ return "full";
79156
+ }
79157
+ void previewRequest(iframe, "restore-attributes", { ...restore2, time: currentTime }).then(
79158
+ (reply) => {
79159
+ if (!reply?.applied) reloadPreview();
79160
+ }
79161
+ );
79162
+ return "soft";
79163
+ }
78799
79164
  function applyUndoRestoreToPreview(iframe, activeCompPath, files, currentTime, reload, nestedFiles) {
78800
79165
  const activeDocPath = activeCompPath ?? "index.html";
78801
79166
  const paths = files ? Object.keys(files) : [];
@@ -78803,6 +79168,8 @@ function applyUndoRestoreToPreview(iframe, activeCompPath, files, currentTime, r
78803
79168
  markScenesStale(iframe, paths);
78804
79169
  reload();
78805
79170
  };
79171
+ if (iframe && files && previewFrameOpaque(iframe))
79172
+ return applySealedRestore(iframe, activeDocPath, files, currentTime, reloadPreview);
78806
79173
  const doc = iframe?.contentDocument;
78807
79174
  const win = iframe?.contentWindow;
78808
79175
  const plan = doc && files && win ? planRestoreTargets(doc, activeDocPath, files) : null;
@@ -91808,6 +92175,76 @@ function parseTranscriptArray(parsed) {
91808
92175
  }
91809
92176
 
91810
92177
  // src/hooks/useCaptionDetection.ts
92178
+ import { MAX_DESCRIBE_HANDLES as MAX_DESCRIBE_HANDLES6 } from "@hyperframes/core/runtime/editing-port";
92179
+ var GROUP_SELECTOR2 = ".caption-group, .caption-line, .caption-block";
92180
+ var WORD_SELECTOR2 = ".word, .caption-word";
92181
+ var attribute = (el, name) => el?.attributes.find(([key]) => key === name)?.[1] ?? null;
92182
+ var CAPTION_STYLES = [
92183
+ "font-size",
92184
+ "font-weight",
92185
+ "font-family",
92186
+ "color",
92187
+ "text-transform",
92188
+ "letter-spacing",
92189
+ "background-color",
92190
+ "border-radius",
92191
+ "padding-top",
92192
+ "padding-right",
92193
+ "padding-bottom",
92194
+ "padding-left"
92195
+ ];
92196
+ async function frameStyles(iframe, handle) {
92197
+ if (!handle) return null;
92198
+ const styles = await previewComputedStyles(iframe, { handle }, CAPTION_STYLES);
92199
+ if (!styles) return null;
92200
+ const camel = (name) => name.replace(/-(\w)/g, (_, c) => c.toUpperCase());
92201
+ return Object.fromEntries(CAPTION_STYLES.map((name) => [camel(name), styles[name] ?? ""]));
92202
+ }
92203
+ async function frameCaptionDom(iframe) {
92204
+ const [all, groups, words] = await Promise.all(
92205
+ [`${GROUP_SELECTOR2}, ${WORD_SELECTOR2}`, GROUP_SELECTOR2, WORD_SELECTOR2].map(
92206
+ (selector) => queryPreviewElements(iframe, selector)
92207
+ )
92208
+ );
92209
+ if (!all || !groups || !words || all.truncated) return null;
92210
+ const handles = all.matches.map((match) => match.handle);
92211
+ const chains = [];
92212
+ for (let i = 0; i < handles.length; i += MAX_DESCRIBE_HANDLES6) {
92213
+ const part = await previewAncestors(iframe, handles.slice(i, i + MAX_DESCRIBE_HANDLES6));
92214
+ if (!part) return null;
92215
+ chains.push(...part);
92216
+ }
92217
+ const isGroup = new Set(groups.matches.map((match) => match.handle));
92218
+ const isWord = new Set(words.matches.map((match) => match.handle));
92219
+ const doc = document.implementation.createHTMLDocument("");
92220
+ const mirrored = /* @__PURE__ */ new Map();
92221
+ handles.forEach((handle, i) => {
92222
+ const el = doc.createElement("span");
92223
+ if (isGroup.has(handle)) el.classList.add("caption-group");
92224
+ if (isWord.has(handle)) el.classList.add("word");
92225
+ const parent = chains[i]?.find((ancestor) => mirrored.has(ancestor));
92226
+ (parent ? mirrored.get(parent) : doc.body).append(el);
92227
+ mirrored.set(handle, el);
92228
+ });
92229
+ const firstWord = words.matches[0]?.handle;
92230
+ const firstGroup = groups.matches[0]?.handle;
92231
+ const styles = /* @__PURE__ */ new Map([
92232
+ [mirrored.get(firstWord ?? ""), await frameStyles(iframe, firstWord)],
92233
+ [mirrored.get(firstGroup ?? ""), await frameStyles(iframe, firstGroup)]
92234
+ ]);
92235
+ const win = { getComputedStyle: (el) => styles.get(el) ?? {} };
92236
+ return { doc, win };
92237
+ }
92238
+ async function frameCaptionModel(iframe, content) {
92239
+ const [root] = (await queryPreviewElements(iframe, "[data-composition-id]"))?.matches ?? [];
92240
+ const rootEl = root ? (await describePreviewElements(iframe, [root.handle]))?.[0] : null;
92241
+ const frame3 = await frameCaptionDom(iframe);
92242
+ if (!frame3) return null;
92243
+ const w = parseInt(attribute(rootEl, "data-width") ?? "1920", 10);
92244
+ const h = parseInt(attribute(rootEl, "data-height") ?? "1080", 10);
92245
+ const dur = parseFloat(attribute(rootEl, "data-duration") ?? "0");
92246
+ return parseCaptionComposition(frame3.doc, frame3.win, content, w, h, dur);
92247
+ }
91811
92248
  function useCaptionDetection({
91812
92249
  projectId,
91813
92250
  activeCompPath,
@@ -91833,12 +92270,56 @@ function useCaptionDetection({
91833
92270
  useEffect136(() => {
91834
92271
  if (!projectId) return;
91835
92272
  let activating = false;
92273
+ let disposed = false;
92274
+ const pickCaptionSource = (hostSrcs, captionCompId) => {
92275
+ const host = hostSrcs.find((src) => src && src.includes("captions"));
92276
+ if (host) return host;
92277
+ for (const [id, src] of compIdToSrc) {
92278
+ if (id.includes("caption") || src.includes("caption")) return src;
92279
+ }
92280
+ if (activeCompPath?.includes("captions")) return activeCompPath;
92281
+ return captionCompId === null ? null : compIdToSrc.get(captionCompId) || null;
92282
+ };
92283
+ const loadCaptions = (srcPath, parse) => studioApiFetch(buildProjectApiPath(projectId, `/files/${encodeURIComponent(srcPath)}`)).then((r) => r.json()).then(async (data) => {
92284
+ if (disposed || !data.content || useCaptionStore.getState().isEditMode) return;
92285
+ const model = await parse(data.content);
92286
+ if (disposed || !model || useCaptionStore.getState().isEditMode) return;
92287
+ const store = useCaptionStore.getState();
92288
+ store.setModel(model);
92289
+ store.setSourceFilePath(srcPath);
92290
+ store.setEditMode(true);
92291
+ captionSync.loadOverrides();
92292
+ }).catch(() => {
92293
+ });
92294
+ const frameCaptionSource = async (iframe) => {
92295
+ if (!(await queryPreviewElements(iframe, ".caption-group"))?.matches.length) return null;
92296
+ const hosts = await queryPreviewElements(
92297
+ iframe,
92298
+ "[data-composition-src], [data-composition-file]"
92299
+ );
92300
+ const handles = (hosts?.matches ?? []).slice(0, MAX_DESCRIBE_HANDLES6).map((m) => m.handle);
92301
+ const described = handles.length ? await describePreviewElements(iframe, handles) : [];
92302
+ const hostSrcs = (described ?? []).map(
92303
+ (el) => attribute(el, "data-composition-src") || attribute(el, "data-composition-file")
92304
+ );
92305
+ const captionComp = await queryPreviewElements(iframe, '[data-composition-id*="caption"]');
92306
+ return pickCaptionSource(hostSrcs, captionComp?.matches[0]?.source.compositionId ?? null);
92307
+ };
91836
92308
  const tryActivateCaptions = () => {
91837
92309
  const captionState = useCaptionStore.getState();
91838
92310
  if (captionState.isEditMode || captionState.dismissed || activating) {
91839
92311
  return;
91840
92312
  }
91841
92313
  const iframe = previewIframeRef.current;
92314
+ if (iframe && previewFrameOpaque(iframe)) {
92315
+ activating = true;
92316
+ void frameCaptionSource(iframe).then(
92317
+ (src) => src && !disposed ? loadCaptions(src, (content) => frameCaptionModel(iframe, content)) : null
92318
+ ).finally(() => {
92319
+ activating = false;
92320
+ });
92321
+ return;
92322
+ }
91842
92323
  let doc = null;
91843
92324
  let win = null;
91844
92325
  try {
@@ -91850,50 +92331,24 @@ function useCaptionDetection({
91850
92331
  if (!doc || !win) return;
91851
92332
  const groups = doc.querySelectorAll(".caption-group");
91852
92333
  if (groups.length === 0) return;
91853
- let captionSrcPath = null;
91854
- const compHosts = doc.querySelectorAll("[data-composition-src], [data-composition-file]");
91855
- for (const host of compHosts) {
91856
- const src = host.getAttribute("data-composition-src") || host.getAttribute("data-composition-file");
91857
- if (src && src.includes("captions")) {
91858
- captionSrcPath = src;
91859
- break;
91860
- }
91861
- }
91862
- if (!captionSrcPath) {
91863
- for (const [id, src] of compIdToSrc) {
91864
- if (id.includes("caption") || src.includes("caption")) {
91865
- captionSrcPath = src;
91866
- break;
91867
- }
91868
- }
91869
- }
91870
- if (!captionSrcPath && activeCompPath?.includes("captions")) {
91871
- captionSrcPath = activeCompPath;
91872
- }
91873
- if (!captionSrcPath) {
91874
- const captionComp = doc.querySelector('[data-composition-id*="caption"]');
91875
- if (captionComp) {
91876
- const compId = captionComp.getAttribute("data-composition-id") || "";
91877
- captionSrcPath = compIdToSrc.get(compId) || null;
91878
- }
91879
- }
92334
+ const hostSrcs = [
92335
+ ...doc.querySelectorAll("[data-composition-src], [data-composition-file]")
92336
+ ].map(
92337
+ (host) => host.getAttribute("data-composition-src") || host.getAttribute("data-composition-file")
92338
+ );
92339
+ const captionComp = doc.querySelector('[data-composition-id*="caption"]');
92340
+ const captionCompId = captionComp ? captionComp.getAttribute("data-composition-id") || "" : null;
92341
+ const captionSrcPath = pickCaptionSource(hostSrcs, captionCompId);
91880
92342
  if (!captionSrcPath) return;
91881
92343
  activating = true;
91882
- const srcPath = captionSrcPath;
91883
- studioApiFetch(buildProjectApiPath(projectId, `/files/${encodeURIComponent(srcPath)}`)).then((r) => r.json()).then((data) => {
91884
- if (!data.content || !doc || !win || useCaptionStore.getState().isEditMode) return;
91885
- const root = doc.querySelector("[data-composition-id]");
92344
+ const frameDoc = doc;
92345
+ const frameWin = win;
92346
+ void loadCaptions(captionSrcPath, async (content) => {
92347
+ const root = frameDoc.querySelector("[data-composition-id]");
91886
92348
  const w = parseInt(root?.getAttribute("data-width") ?? "1920", 10);
91887
92349
  const h = parseInt(root?.getAttribute("data-height") ?? "1080", 10);
91888
92350
  const dur = parseFloat(root?.getAttribute("data-duration") ?? "0");
91889
- const model = parseCaptionComposition(doc, win, data.content, w, h, dur);
91890
- if (!model) return;
91891
- const store = useCaptionStore.getState();
91892
- store.setModel(model);
91893
- store.setSourceFilePath(srcPath);
91894
- store.setEditMode(true);
91895
- captionSync.loadOverrides();
91896
- }).catch(() => {
92351
+ return parseCaptionComposition(frameDoc, frameWin, content, w, h, dur);
91897
92352
  }).finally(() => {
91898
92353
  activating = false;
91899
92354
  });
@@ -91909,6 +92364,7 @@ function useCaptionDetection({
91909
92364
  window.addEventListener("message", handleMessage);
91910
92365
  tryActivateCaptions();
91911
92366
  return () => {
92367
+ disposed = true;
91912
92368
  window.removeEventListener("message", handleMessage);
91913
92369
  };
91914
92370
  }, [activeCompPath, projectId, compIdToSrc, captionSync, previewIframeRef, livePreviewIframe]);
@@ -98300,6 +98756,21 @@ var CaptionPropertyPanel = memo54(function CaptionPropertyPanel2({
98300
98756
  (updates) => {
98301
98757
  const iframe = iframeRef.current;
98302
98758
  if (!iframe || !model) return;
98759
+ if (previewFrameOpaque(iframe)) {
98760
+ const parts = {
98761
+ x: updates.x,
98762
+ y: updates.y,
98763
+ scale: updates.scaleX,
98764
+ rotation: updates.rotation
98765
+ };
98766
+ const set = Object.fromEntries(Object.entries(parts).filter(([, v]) => v !== void 0));
98767
+ if (Object.keys(set).length === 0) return;
98768
+ for (const segId of selectedSegmentIds) {
98769
+ const word = findCaptionWord(model, segId);
98770
+ if (word) void frameWordTransform(iframe, { ...word, set });
98771
+ }
98772
+ return;
98773
+ }
98303
98774
  let doc = null;
98304
98775
  try {
98305
98776
  doc = iframe.contentDocument;
@@ -101165,10 +101636,30 @@ function VariablesOtherCompositions({
101165
101636
 
101166
101637
  // src/components/panels/VariablesPanel.tsx
101167
101638
  import { isScalarVariableValue as isScalar } from "@hyperframes/core/variables";
101168
- import { jsx as jsx253, jsxs as jsxs201 } from "react/jsx-runtime";
101169
- function shellSingleQuote(value) {
101170
- return `'${value.replace(/'/g, `'\\''`)}'`;
101639
+ import { RENDER_VARIABLES_FILE as RENDER_VARIABLES_FILE2 } from "@hyperframes/core/project-folders";
101640
+
101641
+ // src/components/panels/renderHandoff.ts
101642
+ import { RENDER_VARIABLES_FILE } from "@hyperframes/core/project-folders";
101643
+ var SHELL_WORD = /^[A-Za-z0-9_][A-Za-z0-9_./-]*$/;
101644
+ function renderHandoffCommand(compPath) {
101645
+ if (!SHELL_WORD.test(compPath)) return null;
101646
+ return `npx hyperframes render -c ${compPath} --variables-file ${RENDER_VARIABLES_FILE}`;
101171
101647
  }
101648
+ async function saveRenderVariables(projectId, values) {
101649
+ try {
101650
+ const response = await studioApiFetch(buildProjectApiPath(projectId, "/render-variables"), {
101651
+ method: "PUT",
101652
+ headers: { "Content-Type": "application/json" },
101653
+ body: JSON.stringify(values)
101654
+ });
101655
+ return response.ok;
101656
+ } catch {
101657
+ return false;
101658
+ }
101659
+ }
101660
+
101661
+ // src/components/panels/VariablesPanel.tsx
101662
+ import { jsx as jsx253, jsxs as jsxs201 } from "react/jsx-runtime";
101172
101663
  function formatIssue(issue) {
101173
101664
  switch (issue.kind) {
101174
101665
  case "undeclared":
@@ -101283,20 +101774,25 @@ function PreviewModeHeader({
101283
101774
  function HandoffFooter({
101284
101775
  effectiveValues,
101285
101776
  compPath,
101286
- onCopy
101777
+ onCopy,
101778
+ onCopyCommand
101287
101779
  }) {
101288
101780
  const json2 = JSON.stringify(effectiveValues);
101289
- const command = `npx hyperframes render ${shellSingleQuote(compPath)} --variables ${shellSingleQuote(json2)}`;
101781
+ const command = renderHandoffCommand(compPath);
101290
101782
  return /* @__PURE__ */ jsxs201("div", { className: "space-y-1.5 rounded-lg border border-neutral-800/70 bg-neutral-900/40 p-2", children: [
101291
101783
  /* @__PURE__ */ jsx253("p", { className: "text-[9px] font-medium uppercase tracking-wider text-neutral-500", children: "Use this template" }),
101292
- /* @__PURE__ */ jsx253("code", { className: "block truncate font-mono text-[9px] text-neutral-500", title: command, children: command }),
101784
+ command ? /* @__PURE__ */ jsx253("code", { className: "block truncate font-mono text-[9px] text-neutral-500", title: command, children: command }) : /* @__PURE__ */ jsxs201("p", { className: "text-[9px] leading-relaxed text-neutral-500", children: [
101785
+ "Rename this composition to letters, digits, ",
101786
+ /* @__PURE__ */ jsx253("code", { className: "font-mono", children: "_ . / -" }),
101787
+ " to copy a render command. A shell would read other characters in its name as syntax."
101788
+ ] }),
101293
101789
  /* @__PURE__ */ jsxs201("div", { className: "flex items-center gap-2", children: [
101294
- /* @__PURE__ */ jsx253(
101790
+ command && /* @__PURE__ */ jsx253(
101295
101791
  RowAction,
101296
101792
  {
101297
101793
  label: "Copy render command",
101298
- title: "CLI command rendering exactly what the preview shows",
101299
- onClick: () => onCopy(command, "Render command")
101794
+ title: `Saves what the preview shows to ${RENDER_VARIABLES_FILE2}. Run the command from the project folder.`,
101795
+ onClick: () => onCopyCommand(command)
101300
101796
  }
101301
101797
  ),
101302
101798
  /* @__PURE__ */ jsx253(
@@ -101327,7 +101823,7 @@ var VariablesPanel = memo60(function VariablesPanel2({
101327
101823
  reloadPreview,
101328
101824
  recordEdit
101329
101825
  }) {
101330
- const { activeCompPath, showToast } = useStudioShellContext();
101826
+ const { projectId, activeCompPath, showToast } = useStudioShellContext();
101331
101827
  const { refreshKey } = useStudioPlaybackContext();
101332
101828
  const { readProjectFile, writeProjectFile, compositions } = useFileManagerContext();
101333
101829
  const { domEditSelection } = useDomEditContext();
@@ -101381,6 +101877,19 @@ var VariablesPanel = memo60(function VariablesPanel2({
101381
101877
  },
101382
101878
  [showToast]
101383
101879
  );
101880
+ const copyRenderCommand = useCallback186(
101881
+ (command) => {
101882
+ const copied = copyTextToClipboard(command);
101883
+ const saved2 = saveRenderVariables(projectId, effectiveValues);
101884
+ void Promise.all([saved2, copied]).then(([wasSaved, wasCopied]) => {
101885
+ if (!wasCopied) showToast("Couldn't copy render command", "error");
101886
+ else if (!wasSaved)
101887
+ showToast(`Couldn't save the values to ${RENDER_VARIABLES_FILE2}`, "error");
101888
+ else showToast("Render command copied", "info");
101889
+ });
101890
+ },
101891
+ [projectId, effectiveValues, showToast]
101892
+ );
101384
101893
  const dropPreviewOverride = useCallback186(
101385
101894
  (id) => {
101386
101895
  if (previewValues && id in previewValues) {
@@ -101553,7 +102062,8 @@ var VariablesPanel = memo60(function VariablesPanel2({
101553
102062
  {
101554
102063
  effectiveValues,
101555
102064
  compPath: effectiveCompPath ?? "index.html",
101556
- onCopy: copyToClipboard
102065
+ onCopy: copyToClipboard,
102066
+ onCopyCommand: copyRenderCommand
101557
102067
  }
101558
102068
  ),
101559
102069
  addOpen ? /* @__PURE__ */ jsx253(
@@ -104883,6 +105393,7 @@ export {
104883
105393
  displayTrackOrder,
104884
105394
  extractSnapTargets,
104885
105395
  fadeHandleBoxes,
105396
+ fetchParsedAnimations,
104886
105397
  fieldBase,
104887
105398
  fieldText,
104888
105399
  findElementBlock,
@@ -104891,6 +105402,7 @@ export {
104891
105402
  flushStudioPendingEdits,
104892
105403
  formatCombo2 as formatCombo,
104893
105404
  formatTime,
105405
+ getAnimationsForElement,
104894
105406
  getPersistedRenderSettings,
104895
105407
  getStudioKeys,
104896
105408
  liveTime,