@hyperframes/core 0.9.93 → 0.9.94

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.
@@ -1,6 +1,6 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { basename, extname } from "node:path";
3
- import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
3
+ import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
4
4
  const IMAGE_EXTENSIONS = new Set([
5
5
  ".jpg",
6
6
  ".jpeg",
@@ -45,7 +45,7 @@ function probeMedia(mediaPath, ffprobePath) {
45
45
  const raw = execFileSync(ffprobePath, [
46
46
  "-v",
47
47
  "error",
48
- ...mediaInputFormatArgs(ffprobePath, mediaPath),
48
+ ...mediaInputArgs(ffprobePath, mediaPath),
49
49
  "-select_streams",
50
50
  "v:0",
51
51
  "-show_entries",
@@ -226,7 +226,7 @@ function readSignalStats(ffmpegPath, mediaPath, seekSeconds, frames) {
226
226
  "-nostdin",
227
227
  "-v",
228
228
  "error",
229
- ...mediaInputFormatArgs(ffmpegPath, mediaPath),
229
+ ...mediaInputArgs(ffmpegPath, mediaPath),
230
230
  ...keyframeSeek,
231
231
  "-i",
232
232
  mediaPath,
@@ -0,0 +1 @@
1
+ export declare const CLIP_NODES = "[data-start], [data-track-index], [data-composition-id], video, audio, img";
@@ -0,0 +1 @@
1
+ export const CLIP_NODES = "[data-start], [data-track-index], [data-composition-id], video, audio, img";
@@ -99,23 +99,33 @@ function restore(element, names) {
99
99
  export function movedTranslate([x = "0px", y = "0px", z], offset) {
100
100
  return `calc(${x} + ${offset.x}px) calc(${y} + ${offset.y}px)${z ? ` ${z}` : ""}`;
101
101
  }
102
+ function writeDrawnTranslate(element, saved, value) {
103
+ element.style.setProperty("translate", value);
104
+ saved.drawnTranslate = element.style.getPropertyValue("translate");
105
+ }
102
106
  function drawTranslate(element, offset) {
103
107
  const saved = beforeOf(element);
104
108
  if (offset.route !== "gsap")
105
- return void element.style.setProperty("translate", movedTranslate(saved.translate, offset));
109
+ return writeDrawnTranslate(element, saved, movedTranslate(saved.translate, offset));
106
110
  const gsap = frameGsap();
107
111
  const read = (axis) => Number(gsap?.getProperty?.(element, axis)) || 0;
108
112
  saved.gsapPosition ??= { x: read("x"), y: read("y") };
109
- element.style.setProperty("translate", "none");
113
+ writeDrawnTranslate(element, saved, "none");
110
114
  gsap?.set?.(element, { x: offset.x, y: offset.y });
111
115
  }
112
116
  export function rebaseDrawnPosition(element, props) {
113
- const position = before.get(element)?.gsapPosition;
114
- for (const axis of ["x", "y"]) {
115
- const value = props[axis];
116
- if (position && typeof value === "number" && Number.isFinite(value))
117
- position[axis] = value;
118
- }
117
+ const saved = before.get(element);
118
+ const moved = ["x", "y"].filter((axis) => Number.isFinite(props[axis]));
119
+ if (!moved.length || !isStylableElement(element))
120
+ return;
121
+ if (!saved)
122
+ element.style.setProperty("translate", "none");
123
+ for (const entry of saved?.inline ?? [])
124
+ if (entry[0] === "translate")
125
+ [entry[1], entry[2]] = ["none", ""];
126
+ for (const axis of moved)
127
+ if (saved?.gsapPosition)
128
+ saved.gsapPosition[axis] = props[axis];
119
129
  }
120
130
  function restoreGsapPosition(element) {
121
131
  const { gsapPosition } = before.get(element) ?? {};
@@ -186,6 +196,18 @@ function clearProps(element, saved) {
186
196
  redrawGsapTimelineAt(timeline, timeline.time());
187
197
  putLiveDraftsBack();
188
198
  }
199
+ function settleTranslateUnderGsap(element) {
200
+ restore(element, ["translate"]);
201
+ const under = getComputedStyle(element).getPropertyValue("translate");
202
+ if (under && under !== "none")
203
+ element.style.setProperty("translate", "none");
204
+ }
205
+ function dropDrawnTranslate(element, saved) {
206
+ if (saved.gsapPosition !== undefined)
207
+ return settleTranslateUnderGsap(element);
208
+ if (element.style.getPropertyValue("translate") === saved.drawnTranslate)
209
+ restore(element, ["translate"]);
210
+ }
189
211
  function end(element, ending) {
190
212
  const saved = before.get(element);
191
213
  if (!saved || ("draft" in ending && ending.draft !== saved.draft))
@@ -199,7 +221,7 @@ function end(element, ending) {
199
221
  restoreGsapRotation(element);
200
222
  }
201
223
  if (ending.end === "keep-size")
202
- restore(element, ["translate"]);
224
+ dropDrawnTranslate(element, saved);
203
225
  before.delete(element);
204
226
  return ending.end === "restore";
205
227
  }
@@ -82,5 +82,7 @@ export declare function readTextLayer(el: Element): TextLayerRead | null;
82
82
  export declare function readSentTextLayer(el: Element): TextLayerRead | null;
83
83
  export declare function escapeCssString(value: string): string;
84
84
  export declare function buildStableSelector(el: Element): string | undefined;
85
+ /** Is `selector` one `buildStableSelector` makes for an element whose id is `id`. */
86
+ export declare function isStableSelector(selector: string, id: string | null): boolean;
85
87
  export declare function getPreferredClassSelector(el: Element): string | undefined;
86
88
  export declare function readElementSource(el: Element): EditingElementSource;
@@ -88,7 +88,7 @@ export function escapeCssString(value) {
88
88
  .replace(/\f/g, "\\c ");
89
89
  }
90
90
  export function buildStableSelector(el) {
91
- if (el.id)
91
+ if (el.id && typeof el.id === "string")
92
92
  return `#${escapeCssIdentifier(el.id)}`;
93
93
  const compositionId = el.getAttribute("data-composition-id");
94
94
  if (compositionId)
@@ -101,6 +101,16 @@ export function buildStableSelector(el) {
101
101
  return `[data-hf-group="${escapeCssString(group)}"]`;
102
102
  return getPreferredClassSelector(el);
103
103
  }
104
+ const ESCAPED_IDENTIFIER = String.raw `(?:[A-Za-z0-9_-]|[^\x00-\x7f]|\\[0-9a-f]{1,6} |\\[^0-9a-f\n\r\f])+`;
105
+ const ESCAPED_STRING = String.raw `"(?:[^"\\\n\r\f]|\\\\|\\"|\\a |\\d |\\c )+"`;
106
+ const CLASS_SELECTOR = new RegExp(`^\\.(?!-?[0-9]|-$)${ESCAPED_IDENTIFIER}$`);
107
+ const ATTRIBUTE_SELECTOR = new RegExp(`^\\[data-(?:composition-id|hf-group)=${ESCAPED_STRING}\\]$`);
108
+ /** Is `selector` one `buildStableSelector` makes for an element whose id is `id`. */
109
+ export function isStableSelector(selector, id) {
110
+ if (selector.startsWith("#"))
111
+ return Boolean(id) && selector === `#${escapeCssIdentifier(id ?? "")}`;
112
+ return !id && (CLASS_SELECTOR.test(selector) || ATTRIBUTE_SELECTOR.test(selector));
113
+ }
104
114
  export function getPreferredClassSelector(el) {
105
115
  const classes = Array.from(el.classList)
106
116
  .map((value) => value.trim())
@@ -16,13 +16,17 @@ export interface EditingGestureStart extends EditingElementGeometry {
16
16
  c: number;
17
17
  d: number;
18
18
  } | null;
19
- /** Set when GSAP owns its position: its x/y now, and whether a tween with a duration moves it. */
19
+ /** Set when GSAP owns its position: x/y, whether a tween moves it. `gsapAt`: read when null; 0, 0 with no GSAP. */
20
20
  gsap: {
21
21
  x: number;
22
22
  y: number;
23
23
  moving: boolean;
24
24
  drawsTranslate: true;
25
25
  } | null;
26
+ gsapAt: {
27
+ x: number;
28
+ y: number;
29
+ };
26
30
  /** GSAP's rotation now when it owns the element's turn; null when it turns by its own CSS `rotate`. */
27
31
  gsapRotation: number | null;
28
32
  cssRotation: CssRotationStart | null;
@@ -199,6 +199,10 @@ export function gestureStart(handles) {
199
199
  move: measureMoveResponse(element),
200
200
  grow: measureGrowResponse(element, geometry.layout),
201
201
  gsap: gsapPosition(element),
202
+ gsapAt: withoutGsapTakeover(element, () => ({
203
+ x: readGsap(element, "x"),
204
+ y: readGsap(element, "y"),
205
+ })),
202
206
  gsapRotation: rotation,
203
207
  cssRotation: rotation === null ? readCssRotationStart(element) : null,
204
208
  planar: planarOf(element),
@@ -34,7 +34,7 @@ import { type AudioMeterLevels } from "./editing/audioMeter.js";
34
34
  import { type SetAudioGroupAttributeParams } from "./editing/setAudioGroupAttribute.js";
35
35
  import { type EditElementParams, type EditElementResult } from "./editing/editElement.js";
36
36
  import { type TextEditEndedEvent, type TextEditSelectionEvent, type TextEditParams, type TextEditResult } from "./editing/textEdit.js";
37
- export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, type TextLayerRead, } from "./editingElement.js";
37
+ export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, isStableSelector, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, type TextLayerRead, } from "./editingElement.js";
38
38
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, type EditingCorner, type EditingCorners, type EditingElementBox, type EditingElementGeometry, type ElementTransformSnapshot, } from "./editingGeometry.js";
39
39
  export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
40
40
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
@@ -46,7 +46,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
46
46
  export declare const EDITING_CONNECT = "editing-connect";
47
47
  /** Frame to parent, on the window: carries the port in its transfer list. */
48
48
  export declare const EDITING_PORT = "editing-port";
49
- export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "authored-styles", "font-faces", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "gesture-base", "console-errors", "watch-keys", "restore-attributes", "caption-words", "caption-transform", "color-grading-status", "color-grading-previews", "color-grading-playback", "watch-geometry", "audio-meter", "document-markup", "set-audio-group-attribute", "assign-audio-group", "gsap-snapshot", "motion-path-home", "max-z-index", "crop-lift", "edit-element", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "assets-unloaded", "text-edit", "serve-paused-frames"];
49
+ export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "authored-styles", "font-faces", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "gesture-base", "console-errors", "watch-keys", "restore-attributes", "caption-words", "caption-transform", "color-grading-status", "color-grading-previews", "color-grading-playback", "watch-geometry", "audio-meter", "document-markup", "set-audio-group-attribute", "assign-audio-group", "gsap-snapshot", "motion-path-home", "max-z-index", "crop-lift", "edit-element", "remove-elements", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "assets-unloaded", "text-edit", "serve-paused-frames"];
50
50
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
51
51
  export interface EditingRuntimeSnapshot {
52
52
  /** The runtime has installed its player API. */
@@ -374,6 +374,14 @@ export interface EditingRequests {
374
374
  params: EditElementParams;
375
375
  result: EditElementResult;
376
376
  };
377
+ "remove-elements": {
378
+ params: {
379
+ handles: EditingElementHandle[];
380
+ };
381
+ result: {
382
+ removed: number;
383
+ };
384
+ };
377
385
  "stacking-family": {
378
386
  params: {
379
387
  handle: EditingElementHandle;
@@ -18,7 +18,7 @@ import { parseAudioMeter } from "./editing/audioMeter.js";
18
18
  import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
19
19
  import { parseEditElement, } from "./editing/editElement.js";
20
20
  import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./editing/textEdit.js";
21
- export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, } from "./editingElement.js";
21
+ export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, isStableSelector, } from "./editingElement.js";
22
22
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
23
23
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
24
24
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
@@ -65,6 +65,7 @@ export const EDITING_REQUEST_KINDS = [
65
65
  "max-z-index",
66
66
  "crop-lift",
67
67
  "edit-element",
68
+ "remove-elements",
68
69
  "stacking-family",
69
70
  "gsap-set",
70
71
  "patch-tweens",
@@ -328,6 +329,7 @@ const PARAM_PARSERS = {
328
329
  ? { handle: params.handle, lift: params.lift }
329
330
  : null,
330
331
  "edit-element": parseEditElement,
332
+ "remove-elements": handleList,
331
333
  "stacking-family": (params) => hasKeys(params, "handle") && isHandle(params.handle) ? { handle: params.handle } : null,
332
334
  "gsap-set": gsapSetWithDrafts,
333
335
  "patch-tweens": parsePatchTweensRequest,
@@ -2,6 +2,7 @@ import { sourceLengthOf } from "./sourceLength.js";
2
2
  import { transitionLabelsForDocument } from "./transitionLabels.js";
3
3
  import { unproxiedSrc } from "./proxySrc.js";
4
4
  import { stableClipId } from "./clipTree.js";
5
+ import { CLIP_NODES } from "./clipNodes.js";
5
6
  import { findRootCompositionElement, parseCompositionDimension } from "./compositionDimension.js";
6
7
  import { AUTHORED_DURATION_ATTR, AUTHORED_END_ATTR, resolveAuthoredTimingWindow, } from "./authoredTiming.js";
7
8
  import { swallow } from "./diagnostics.js";
@@ -229,6 +230,16 @@ export function collectRuntimeTimelinePayload(params) {
229
230
  const duration = readTimelineDurationSeconds(timelineRegistry[compositionId]);
230
231
  return duration != null && duration > 0 ? duration : null;
231
232
  };
233
+ const ownTimelineLength = (compositionId) => {
234
+ try {
235
+ const length = timelineRegistry[compositionId]?.duration?.();
236
+ return typeof length === "number" && Number.isFinite(length) ? length : null;
237
+ }
238
+ catch (err) {
239
+ swallow("runtime.timeline.ownLength", err);
240
+ return null;
241
+ }
242
+ };
232
243
  const resolveMediaWindowEndSeconds = () => {
233
244
  const mediaNodes = Array.from(document.querySelectorAll("video[data-start], audio[data-start]"));
234
245
  if (mediaNodes.length === 0)
@@ -354,7 +365,6 @@ export function collectRuntimeTimelinePayload(params) {
354
365
  // as clips — they have no declared timing so the timeline can't show their
355
366
  // actual visibility window. They can still appear as scenes via the separate
356
367
  // scene collection below.
357
- const CLIP_NODES = "[data-start], [data-track-index], [data-composition-id], video, audio, img";
358
368
  const nodes = Array.from(document.querySelectorAll(CLIP_NODES));
359
369
  let maxEnd = 0;
360
370
  const clipOf = (node, i) => {
@@ -435,6 +445,7 @@ export function collectRuntimeTimelinePayload(params) {
435
445
  timelinePriority: parseNum(node.getAttribute("data-timeline-priority")),
436
446
  text: readSentTextLayer(node),
437
447
  transitionLabel: transitionLabels.get(node) ?? null,
448
+ timelineDuration: isNestedHost ? ownTimelineLength(nodeCompositionId) : null,
438
449
  };
439
450
  };
440
451
  const addClip = (clip) => {
@@ -571,6 +582,7 @@ export function collectRuntimeTimelinePayload(params) {
571
582
  timelinePriority: parseNum(el.getAttribute("data-timeline-priority")),
572
583
  text: readSentTextLayer(el),
573
584
  transitionLabel: transitionLabels.get(el) ?? null,
585
+ timelineDuration: null,
574
586
  });
575
587
  gsapClipIds.add(el.id);
576
588
  }
@@ -635,6 +647,7 @@ export function collectRuntimeTimelinePayload(params) {
635
647
  timelinePriority: parseNum(el.getAttribute("data-timeline-priority")),
636
648
  text: readSentTextLayer(el),
637
649
  transitionLabel: transitionLabels.get(el) ?? null,
650
+ timelineDuration: null,
638
651
  });
639
652
  gsapClipIds.add(el.id);
640
653
  }
@@ -73,6 +73,7 @@ export type RuntimeTimelineClip = RuntimeTimelineClipIdentity & {
73
73
  timelinePriority: number | null;
74
74
  text: TextLayerRead | null;
75
75
  transitionLabel: string | null;
76
+ timelineDuration: number | null;
76
77
  };
77
78
  export type RuntimeTimelineScene = {
78
79
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.93",
3
+ "version": "0.9.94",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -513,9 +513,9 @@
513
513
  "linkedom": "^0.18.12",
514
514
  "postcss": "^8.5.8",
515
515
  "wawoff2": "^2.0.1",
516
- "@hyperframes/lint": "0.9.93",
517
- "@hyperframes/studio-server": "0.9.93",
518
- "@hyperframes/parsers": "0.9.93"
516
+ "@hyperframes/lint": "0.9.94",
517
+ "@hyperframes/studio-server": "0.9.94",
518
+ "@hyperframes/parsers": "0.9.94"
519
519
  },
520
520
  "devDependencies": {
521
521
  "@fontsource/archivo-black": "^5.2.8",