@hyperframes/core 0.9.99 → 0.9.101

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.
@@ -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
+ }
@@ -0,0 +1,17 @@
1
+ import type { EditingElementHandle } from "../editingElement.js";
2
+ export declare const MAX_FONT_FACES = 256;
3
+ /** Each property's inline value, else the last same-origin rule's that matches; null for an unknown handle. */
4
+ export declare function authoredStyles({ handle, properties, }: {
5
+ handle: EditingElementHandle;
6
+ properties: string[];
7
+ }): {
8
+ styles: Record<string, string> | null;
9
+ };
10
+ /** The families the document's fonts draw, and each same-origin `@font-face` rule's family and src. */
11
+ export declare function fontFaces(): {
12
+ families: string[];
13
+ ownFaces: Array<{
14
+ family: string;
15
+ src: string;
16
+ }>;
17
+ };
@@ -0,0 +1,57 @@
1
+ import { MAX_ELEMENT_VALUE } from "../editingElement.js";
2
+ import { elementForHandle } from "../editingHandles.js";
3
+ export const MAX_FONT_FACES = 256;
4
+ const cut = (value) => value.slice(0, MAX_ELEMENT_VALUE);
5
+ function sameOriginRules() {
6
+ return [...document.styleSheets].flatMap((sheet) => {
7
+ try {
8
+ return [...sheet.cssRules];
9
+ }
10
+ catch {
11
+ return [];
12
+ }
13
+ });
14
+ }
15
+ const isStyleRule = (rule) => "selectorText" in rule;
16
+ const isFontFaceRule = (rule) => rule.cssText.startsWith("@font-face");
17
+ function matches(element, selector) {
18
+ try {
19
+ return element.matches(selector);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ /** Each property's inline value, else the last same-origin rule's that matches; null for an unknown handle. */
26
+ export function authoredStyles({ handle, properties, }) {
27
+ const element = elementForHandle(handle);
28
+ if (!element)
29
+ return { styles: null };
30
+ const inline = element.style;
31
+ const rules = sameOriginRules().filter(isStyleRule);
32
+ const styles = {};
33
+ for (const name of properties) {
34
+ const ruled = rules.filter((rule) => rule.style.getPropertyValue(name) && matches(element, rule.selectorText));
35
+ const value = inline?.getPropertyValue(name) || ruled.at(-1)?.style.getPropertyValue(name);
36
+ if (value)
37
+ styles[name] = cut(value);
38
+ }
39
+ return { styles };
40
+ }
41
+ /** The families the document's fonts draw, and each same-origin `@font-face` rule's family and src. */
42
+ export function fontFaces() {
43
+ const families = new Set();
44
+ for (const face of document.fonts ?? []) {
45
+ if (families.size >= MAX_FONT_FACES)
46
+ break;
47
+ families.add(cut(face.family));
48
+ }
49
+ const ownFaces = sameOriginRules()
50
+ .filter(isFontFaceRule)
51
+ .slice(0, MAX_FONT_FACES)
52
+ .map((rule) => ({
53
+ family: cut(rule.style.getPropertyValue("font-family")),
54
+ src: cut(rule.style.getPropertyValue("src")),
55
+ }));
56
+ return { families: [...families], ownFaces };
57
+ }
@@ -33,11 +33,15 @@ 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";
39
40
  export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
40
41
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
42
+ export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
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";
41
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";
42
46
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
43
47
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
@@ -46,7 +50,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
46
50
  export declare const EDITING_CONNECT = "editing-connect";
47
51
  /** Frame to parent, on the window: carries the port in its transfer list. */
48
52
  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", "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"];
50
54
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
51
55
  export interface EditingRuntimeSnapshot {
52
56
  /** The runtime has installed its player API. */
@@ -463,6 +467,10 @@ export interface EditingRequests {
463
467
  served: boolean;
464
468
  };
465
469
  };
470
+ "stage-measure": {
471
+ params: StageMeasureParams;
472
+ result: StageMeasureResult;
473
+ };
466
474
  }
467
475
  export type EditingParams<K extends EditingRequestKind> = EditingRequests[K]["params"];
468
476
  export type EditingResult<K extends EditingRequestKind> = EditingRequests[K]["result"];
@@ -17,10 +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";
25
+ export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
26
+ export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
27
+ export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, } from "./editing/stageMeasure.js";
24
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";
25
29
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
26
30
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
@@ -78,6 +82,7 @@ export const EDITING_REQUEST_KINDS = [
78
82
  "assets-unloaded",
79
83
  "text-edit",
80
84
  "serve-paused-frames",
85
+ "stage-measure",
81
86
  ];
82
87
  export { MAX_DRAFT_PX };
83
88
  export const EDITING_REQUEST_TIMEOUT_MS = 5_000;
@@ -354,6 +359,7 @@ const PARAM_PARSERS = {
354
359
  "serve-paused-frames": (params) => hasKeys(params, "channel") && params.channel instanceof MessagePort
355
360
  ? { channel: params.channel }
356
361
  : null,
362
+ "stage-measure": parseStageMeasureParams,
357
363
  };
358
364
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
359
365
  export function parseEditingRequest(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.99",
3
+ "version": "0.9.101",
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/lint": "0.9.99",
529
- "@hyperframes/parsers": "0.9.99",
530
- "@hyperframes/studio-server": "0.9.99"
528
+ "@hyperframes/lint": "0.9.101",
529
+ "@hyperframes/parsers": "0.9.101",
530
+ "@hyperframes/studio-server": "0.9.101"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",