@hyperframes/core 0.9.100 → 0.9.102

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.
@@ -2,6 +2,7 @@
2
2
  // decodes. An ask names a path on the frame's own server and the proxy options it played, never a URL: Studio
3
3
  // resolves it against its own project before reading anything.
4
4
  import { sourceFactsOfSrc } from "../mediaSourceLookup.js";
5
+ import { isMessageList } from "../protocol.js";
5
6
  /** The query options the runtime's media proxy adds to a src; any other key never leaves the frame. */
6
7
  export const PAUSED_FRAME_PARAMS = [
7
8
  "hf-proxy",
@@ -49,7 +50,7 @@ export function parsePausedFrameAsk(data) {
49
50
  return null;
50
51
  if (data.type === "abort" || data.type === "suspend")
51
52
  return { type: data.type, id: data.id };
52
- if (data.type !== "decode" || !Array.isArray(data.asks))
53
+ if (data.type !== "decode" || !isMessageList(data.asks, PAUSED_FRAME_SOURCES))
53
54
  return null;
54
55
  const asks = data.asks.map(parseAsk);
55
56
  return asks.every((ask) => ask !== null)
@@ -124,6 +125,8 @@ export function portPausedVideoProvider(port) {
124
125
  const provider = {
125
126
  async decode(requests, signal) {
126
127
  signal.throwIfAborted();
128
+ if (requests.length > PAUSED_FRAME_SOURCES)
129
+ throw new Error("Preview decode over budget");
127
130
  const asks = requests.map(pausedFrameAsk);
128
131
  if (asks.some((a) => a === null))
129
132
  throw new Error("Preview source is not on the preview server");
@@ -0,0 +1,35 @@
1
+ import { type EditingRect } from "../editingElement.js";
2
+ export declare const MAX_STAGE_ITEMS = 2000;
3
+ export declare const MAX_STAGE_CLIP_KEYS = 8;
4
+ export interface StageMeasureParams {
5
+ maxItems?: number;
6
+ }
7
+ export interface StageTextStart {
8
+ x: number;
9
+ y: number;
10
+ }
11
+ export interface StageMeasuredItem {
12
+ key: string;
13
+ hfId: string | null;
14
+ id: string | null;
15
+ tag: string;
16
+ parent: string | null;
17
+ text: string;
18
+ box: EditingRect;
19
+ fontSize: string;
20
+ color: string;
21
+ background: string;
22
+ placed: boolean;
23
+ visible: boolean;
24
+ clipKeys: string[];
25
+ hasElementChildren: boolean;
26
+ textStart: StageTextStart | null;
27
+ hasBackgroundImage: boolean;
28
+ }
29
+ export interface StageMeasureResult {
30
+ items: StageMeasuredItem[];
31
+ truncated: boolean;
32
+ }
33
+ export declare function parseStageMeasureParams(params: unknown): StageMeasureParams | null;
34
+ /** Walks `doc.body` in document order up to `maxItems`, capturing layout, styles, visibility, and clip keys. */
35
+ export declare function measureStageDocument(doc?: Document, maxItems?: number): StageMeasureResult;
@@ -0,0 +1,148 @@
1
+ import { MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE } from "../editingElement.js";
2
+ export const MAX_STAGE_ITEMS = 2_000;
3
+ export const MAX_STAGE_CLIP_KEYS = 8;
4
+ const SKIPPED = new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "LINK", "META"]);
5
+ const isRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
6
+ export function parseStageMeasureParams(params) {
7
+ if (params === undefined)
8
+ return {};
9
+ if (!isRecord(params))
10
+ return null;
11
+ const keys = Object.keys(params);
12
+ if (keys.length === 0)
13
+ return {};
14
+ if (keys.length !== 1 || keys[0] !== "maxItems")
15
+ return null;
16
+ const { maxItems } = params;
17
+ if (typeof maxItems !== "number" || !Number.isSafeInteger(maxItems))
18
+ return null;
19
+ if (maxItems < 1 || maxItems > MAX_STAGE_ITEMS)
20
+ return null;
21
+ return { maxItems };
22
+ }
23
+ const clampValue = (text) => text.slice(0, MAX_ELEMENT_VALUE);
24
+ const finite = (value) => (Number.isFinite(value) ? value : 0);
25
+ function ownText(element) {
26
+ const nodes = [];
27
+ let raw = "";
28
+ for (let i = 0; i < element.childNodes.length; i += 1) {
29
+ const node = element.childNodes[i];
30
+ if (node && node.nodeType === 3) {
31
+ nodes.push(node);
32
+ raw += node.textContent ?? "";
33
+ }
34
+ }
35
+ return { text: raw.replace(/\s+/g, " ").trim().slice(0, MAX_ELEMENT_TEXT), nodes };
36
+ }
37
+ const validTextBox = (rect) => Boolean(rect && rect.width > 0 && [rect.x, rect.y, rect.width, rect.height].every(Number.isFinite));
38
+ function textStartOf(doc, nodes) {
39
+ const first = nodes[0];
40
+ const last = nodes[nodes.length - 1];
41
+ if (!first || !last)
42
+ return null;
43
+ try {
44
+ const range = doc.createRange();
45
+ range.setStart(first, 0);
46
+ range.setEnd(last, (last.textContent ?? "").length);
47
+ const rect = range.getBoundingClientRect?.();
48
+ return validTextBox(rect) ? { x: rect.x, y: rect.y + rect.height / 2 } : null;
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ function clipKeysOf(element) {
55
+ const clip = element.closest(".clip");
56
+ if (!clip)
57
+ return [];
58
+ const owner = clip.parentElement?.closest("[data-composition-id]");
59
+ const file = clampValue(owner?.getAttribute("data-composition-file") ??
60
+ owner?.getAttribute("data-composition-src") ??
61
+ "index.html");
62
+ const seen = new Set();
63
+ const keys = [];
64
+ for (const id of [clip.id, clip.getAttribute("data-hf-id")]) {
65
+ if (!id || seen.has(id))
66
+ continue;
67
+ seen.add(id);
68
+ keys.push(clampValue(`${file}#${id}`));
69
+ if (keys.length >= MAX_STAGE_CLIP_KEYS)
70
+ break;
71
+ }
72
+ return keys;
73
+ }
74
+ function isElementVisible(element, style, width) {
75
+ if (width <= 0)
76
+ return false;
77
+ if (typeof element.checkVisibility === "function") {
78
+ return element.checkVisibility({ visibilityProperty: true, opacityProperty: true });
79
+ }
80
+ return style.visibility !== "hidden" && style.display !== "none" && style.opacity !== "0";
81
+ }
82
+ function measureElement(doc, view, element, parent, key, hfId) {
83
+ const rect = element.getBoundingClientRect();
84
+ const box = {
85
+ x: finite(rect.x),
86
+ y: finite(rect.y),
87
+ width: finite(rect.width),
88
+ height: finite(rect.height),
89
+ };
90
+ const style = view.getComputedStyle(element);
91
+ const { text, nodes } = ownText(element);
92
+ const bgImage = style.backgroundImage;
93
+ return {
94
+ key,
95
+ hfId,
96
+ id: element.id ? clampValue(element.id) : null,
97
+ tag: clampValue(element.tagName.toLowerCase()),
98
+ parent,
99
+ text,
100
+ box,
101
+ fontSize: clampValue(style.fontSize ?? ""),
102
+ color: clampValue(style.color ?? ""),
103
+ background: clampValue(style.backgroundColor ?? ""),
104
+ placed: style.position === "absolute" || style.position === "fixed",
105
+ visible: isElementVisible(element, style, box.width),
106
+ clipKeys: clipKeysOf(element),
107
+ hasElementChildren: element.children.length > 0,
108
+ textStart: text ? textStartOf(doc, nodes) : null,
109
+ hasBackgroundImage: Boolean(bgImage && bgImage !== "none"),
110
+ };
111
+ }
112
+ /** Walks `doc.body` in document order up to `maxItems`, capturing layout, styles, visibility, and clip keys. */
113
+ export function measureStageDocument(doc = document, maxItems = MAX_STAGE_ITEMS) {
114
+ const view = doc.defaultView;
115
+ if (!view || !doc.body)
116
+ return { items: [], truncated: false };
117
+ const requested = Number.isFinite(maxItems) ? Math.floor(maxItems) : MAX_STAGE_ITEMS;
118
+ const limit = Math.min(Math.max(1, requested), MAX_STAGE_ITEMS);
119
+ const items = [];
120
+ let truncated = false;
121
+ const visit = (element, parent, path) => {
122
+ if (SKIPPED.has(element.tagName.toUpperCase()))
123
+ return;
124
+ if (items.length >= limit) {
125
+ truncated = true;
126
+ return;
127
+ }
128
+ const rawHfId = element.getAttribute("data-hf-id");
129
+ const hfId = rawHfId ? clampValue(rawHfId) : null;
130
+ const key = hfId ?? clampValue(path);
131
+ items.push(measureElement(doc, view, element, parent, key, hfId));
132
+ for (let i = 0; i < element.children.length; i += 1) {
133
+ const child = element.children[i];
134
+ if (child)
135
+ visit(child, key, `${key}>${i}`);
136
+ if (truncated)
137
+ return;
138
+ }
139
+ };
140
+ for (let i = 0; i < doc.body.children.length; i += 1) {
141
+ const child = doc.body.children[i];
142
+ if (child)
143
+ visit(child, null, `${i}`);
144
+ if (truncated)
145
+ break;
146
+ }
147
+ return { items, truncated };
148
+ }
@@ -33,6 +33,7 @@ import { type AssignAudioGroupParams } from "./editing/assignAudioGroup.js";
33
33
  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
+ import { type StageMeasureParams, type StageMeasureResult } from "./editing/stageMeasure.js";
36
37
  import { type TextEditEndedEvent, type TextEditSelectionEvent, type TextEditParams, type TextEditResult } from "./editing/textEdit.js";
37
38
  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
39
  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";
@@ -40,6 +41,7 @@ export type { EditingGestureBase, EditingGestureStart } from "./editingGestureSt
40
41
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
41
42
  export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
42
43
  export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
44
+ export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, type StageMeasuredItem, type StageMeasureParams, type StageMeasureResult, type StageTextStart, } from "./editing/stageMeasure.js";
43
45
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, TARGET_FIELDS, TIMELINE_FIELDS, } from "./editing/gsapSnapshotLimits.js";
44
46
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
45
47
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
@@ -48,7 +50,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
48
50
  export declare const EDITING_CONNECT = "editing-connect";
49
51
  /** Frame to parent, on the window: carries the port in its transfer list. */
50
52
  export declare const EDITING_PORT = "editing-port";
51
- 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", "rebind-timing", "assets-unloaded", "text-edit", "serve-paused-frames"];
53
+ 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", "rebind-timing", "assets-unloaded", "text-edit", "serve-paused-frames", "stage-measure"];
52
54
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
53
55
  export interface EditingRuntimeSnapshot {
54
56
  /** The runtime has installed its player API. */
@@ -465,6 +467,10 @@ export interface EditingRequests {
465
467
  served: boolean;
466
468
  };
467
469
  };
470
+ "stage-measure": {
471
+ params: StageMeasureParams;
472
+ result: StageMeasureResult;
473
+ };
468
474
  }
469
475
  export type EditingParams<K extends EditingRequestKind> = EditingRequests[K]["params"];
470
476
  export type EditingResult<K extends EditingRequestKind> = EditingRequests[K]["result"];
@@ -17,12 +17,14 @@ import { parseAssignAudioGroup } from "./editing/assignAudioGroup.js";
17
17
  import { parseAudioMeter } from "./editing/audioMeter.js";
18
18
  import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
19
19
  import { parseEditElement, } from "./editing/editElement.js";
20
+ import { parseStageMeasureParams, } from "./editing/stageMeasure.js";
20
21
  import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./editing/textEdit.js";
21
22
  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
23
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
23
24
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
24
25
  export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
25
26
  export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
27
+ export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, } from "./editing/stageMeasure.js";
26
28
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, TARGET_FIELDS, TIMELINE_FIELDS, } from "./editing/gsapSnapshotLimits.js";
27
29
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
28
30
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
@@ -80,6 +82,7 @@ export const EDITING_REQUEST_KINDS = [
80
82
  "assets-unloaded",
81
83
  "text-edit",
82
84
  "serve-paused-frames",
85
+ "stage-measure",
83
86
  ];
84
87
  export { MAX_DRAFT_PX };
85
88
  export const EDITING_REQUEST_TIMEOUT_MS = 5_000;
@@ -356,6 +359,7 @@ const PARAM_PARSERS = {
356
359
  "serve-paused-frames": (params) => hasKeys(params, "channel") && params.channel instanceof MessagePort
357
360
  ? { channel: params.channel }
358
361
  : null,
362
+ "stage-measure": parseStageMeasureParams,
359
363
  };
360
364
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
361
365
  export function parseEditingRequest(data) {
@@ -178,12 +178,19 @@ export function createPausedVideoFrames() {
178
178
  refresh(entry);
179
179
  }
180
180
  });
181
- observer.observe(document.body, {
182
- childList: true,
183
- subtree: true,
184
- attributes: true,
185
- attributeFilter: ["src", "style", "class", "hidden", "data-hidden"],
186
- });
181
+ const mountStyle = () => {
182
+ if (!style.isConnected)
183
+ (document.head ?? document.documentElement)?.append(style);
184
+ };
185
+ const observeRoot = document.body ?? document.documentElement;
186
+ if (observeRoot) {
187
+ observer.observe(observeRoot, {
188
+ childList: true,
189
+ subtree: true,
190
+ attributes: true,
191
+ attributeFilter: ["src", "style", "class", "hidden", "data-hidden"],
192
+ });
193
+ }
187
194
  const clear = (keep, current) => {
188
195
  for (const entry of [...presented.values()]) {
189
196
  if (!keep?.has(entry.video)) {
@@ -242,8 +249,7 @@ export function createPausedVideoFrames() {
242
249
  markFrameCanvas(canvas);
243
250
  presented.set(video, entry);
244
251
  video.setAttribute(PREVIEW_VIDEO_SOURCE_ATTR, "");
245
- if (!style.isConnected)
246
- document.head.append(style);
252
+ mountStyle();
247
253
  refresh(entry);
248
254
  }
249
255
  return () => {
@@ -345,8 +351,7 @@ export function createPausedVideoFrames() {
345
351
  for (const entry of [...presented.values()])
346
352
  if (!wanted.has(entry.video))
347
353
  remove(entry);
348
- if (!style.isConnected)
349
- document.head.append(style);
354
+ mountStyle();
350
355
  for (const [index, next] of staged.entries()) {
351
356
  adoptStagedFrame(next, reusable.get(next));
352
357
  const { timestamp, width, height } = frames[index];
@@ -295,7 +295,8 @@ export function collectRuntimeTimelinePayload(params) {
295
295
  const mediaWindowEnd = resolveMediaWindowEndSeconds();
296
296
  const mediaWindowDuration = mediaWindowEnd != null ? Math.max(0, mediaWindowEnd - Math.max(0, rootCompositionStart)) : null;
297
297
  const rootDurationFromTimeline = resolveTimelineDurationSeconds(rootCompositionId);
298
- const rootDurationFromAttr = parseElementDurationAttr(root ?? document.body);
298
+ const rootDurationNode = root ?? document.body ?? document.documentElement;
299
+ const rootDurationFromAttr = rootDurationNode ? parseElementDurationAttr(rootDurationNode) : null;
299
300
  const compositionWindowEnd = maxDefinedNumber(...compositionNodes
300
301
  .filter((node) => node !== root)
301
302
  .map((node) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.100",
3
+ "version": "0.9.102",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -525,9 +525,9 @@
525
525
  "linkedom": "^0.18.12",
526
526
  "postcss": "^8.5.8",
527
527
  "wawoff2": "^2.0.1",
528
- "@hyperframes/parsers": "0.9.100",
529
- "@hyperframes/lint": "0.9.100",
530
- "@hyperframes/studio-server": "0.9.100"
528
+ "@hyperframes/lint": "0.9.102",
529
+ "@hyperframes/studio-server": "0.9.102",
530
+ "@hyperframes/parsers": "0.9.102"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",