@hyperframes/core 0.9.70 → 0.9.72

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.
@@ -5,7 +5,7 @@ import { elementForHandle } from "../editingHandles.js";
5
5
  import { isStylableElement } from "../domRealm.js";
6
6
  export const MAX_EDIT_ENTRIES = 64;
7
7
  export const MAX_EDIT_VALUE = 200_000;
8
- const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-￿-]+)$/;
8
+ const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/;
9
9
  const DATA_ATTRIBUTE = /^data-[a-z0-9_-]+$/;
10
10
  const PANEL_ATTRIBUTES = new Set(["loop", "muted", "alt", "title", "src"]);
11
11
  const MEDIA_TAGS = new Set(["img", "video", "audio"]);
@@ -0,0 +1,31 @@
1
+ export declare const MAX_SWAP_HTML = 50000000;
2
+ /** Each preview file is inlined under a host marked with it; clearing a scene's hash makes the next swap redo it. */
3
+ export declare function markScenesStaleIn(doc: Document, files: readonly string[]): void;
4
+ export type HoldScenesParams = {
5
+ names: string[];
6
+ };
7
+ export type MarkScenesStaleParams = {
8
+ files: string[];
9
+ };
10
+ export type SwapScenesParams = {
11
+ html: string;
12
+ timeoutMs: number;
13
+ };
14
+ export type SwapScenesResult = {
15
+ swapped: true;
16
+ } | {
17
+ swapped: false;
18
+ reason: string;
19
+ };
20
+ export declare function parseHoldScenes(params: unknown): HoldScenesParams | null;
21
+ export declare function parseMarkScenesStale(params: unknown): MarkScenesStaleParams | null;
22
+ export declare function parseSwapScenes(params: unknown): SwapScenesParams | null;
23
+ /** Waits until the named scenes are mounted; false when this preview mounts every scene anyway. */
24
+ export declare function holdScenes({ names }: HoldScenesParams): Promise<{
25
+ held: boolean;
26
+ }>;
27
+ export declare function markScenesStale({ files }: MarkScenesStaleParams): {
28
+ marked: true;
29
+ };
30
+ /** Swaps the edited scenes from the preview document Studio fetched; a swap past its time is aborted. */
31
+ export declare function swapScenes({ html, timeoutMs }: SwapScenesParams): Promise<SwapScenesResult>;
@@ -0,0 +1,89 @@
1
+ // A scene-windowed preview mounts only the scenes near the playhead. Studio holds the scenes an element
2
+ // lives in, swaps edited scenes in place, and marks scenes stale; a sealed frame does each on itself.
3
+ import { SCENE_PART_ATTR, SCENE_PARTS_META } from "../../sceneParts.js";
4
+ import { escapeCssString } from "../editingElement.js";
5
+ import { wallClearTimeout, wallSetTimeout } from "../wallClock.js";
6
+ const MAX_SCENE_NAMES = 256;
7
+ const MAX_NAME = 512;
8
+ const MAX_FILES = 256;
9
+ const MAX_FILE = 2_048;
10
+ export const MAX_SWAP_HTML = 50_000_000;
11
+ const MAX_SWAP_MS = 60_000;
12
+ const MAX_REASON = 500;
13
+ const isRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
14
+ const stringList = (value, count, length) => Array.isArray(value) &&
15
+ value.length <= count &&
16
+ value.every((item) => typeof item === "string" && item.length <= length);
17
+ /** Each preview file is inlined under a host marked with it; clearing a scene's hash makes the next swap redo it. */
18
+ export function markScenesStaleIn(doc, files) {
19
+ const meta = doc.querySelector(`meta[name="${SCENE_PARTS_META}"]`);
20
+ if (!meta)
21
+ return;
22
+ let parts;
23
+ try {
24
+ parts = JSON.parse(meta.content);
25
+ }
26
+ catch {
27
+ return;
28
+ }
29
+ for (const file of files) {
30
+ const hosts = doc.querySelectorAll(`[data-composition-file="${escapeCssString(file)}"]`);
31
+ if (hosts.length === 0 && file.endsWith(".html"))
32
+ parts.shared = "";
33
+ for (const host of hosts) {
34
+ const scene = host.closest(`[${SCENE_PART_ATTR}]`)?.getAttribute(SCENE_PART_ATTR);
35
+ if (scene && scene in parts.scenes)
36
+ parts.scenes[scene] = "";
37
+ }
38
+ }
39
+ meta.content = JSON.stringify(parts);
40
+ }
41
+ export function parseHoldScenes(params) {
42
+ if (!isRecord(params) || Object.keys(params).join() !== "names")
43
+ return null;
44
+ return stringList(params.names, MAX_SCENE_NAMES, MAX_NAME) ? { names: params.names } : null;
45
+ }
46
+ export function parseMarkScenesStale(params) {
47
+ if (!isRecord(params) || Object.keys(params).join() !== "files")
48
+ return null;
49
+ return stringList(params.files, MAX_FILES, MAX_FILE) ? { files: params.files } : null;
50
+ }
51
+ export function parseSwapScenes(params) {
52
+ if (!isRecord(params) || Object.keys(params).sort().join() !== "html,timeoutMs")
53
+ return null;
54
+ const { html, timeoutMs } = params;
55
+ if (typeof html !== "string" || html.length === 0 || html.length > MAX_SWAP_HTML)
56
+ return null;
57
+ const okTimeout = typeof timeoutMs === "number" && timeoutMs > 0 && timeoutMs <= MAX_SWAP_MS;
58
+ return okTimeout ? { html, timeoutMs } : null;
59
+ }
60
+ /** Waits until the named scenes are mounted; false when this preview mounts every scene anyway. */
61
+ export async function holdScenes({ names }) {
62
+ const hold = window.__hfHoldScenes;
63
+ if (typeof hold !== "function")
64
+ return { held: false };
65
+ await hold(names);
66
+ return { held: true };
67
+ }
68
+ export function markScenesStale({ files }) {
69
+ markScenesStaleIn(document, files);
70
+ return { marked: true };
71
+ }
72
+ /** Swaps the edited scenes from the preview document Studio fetched; a swap past its time is aborted. */
73
+ export async function swapScenes({ html, timeoutMs }) {
74
+ const swap = window.__hfSwapScenes;
75
+ if (typeof swap !== "function")
76
+ return { swapped: false, reason: "the preview cannot swap scenes" };
77
+ const deadline = new AbortController();
78
+ const timer = wallSetTimeout(() => deadline.abort(new Error("the swap took too long")), timeoutMs);
79
+ try {
80
+ await swap(html, deadline.signal);
81
+ return { swapped: true };
82
+ }
83
+ catch (error) {
84
+ return { swapped: false, reason: String(error).slice(0, MAX_REASON) };
85
+ }
86
+ finally {
87
+ wallClearTimeout(timer);
88
+ }
89
+ }
@@ -1,4 +1,5 @@
1
1
  import { type EditingElementHandle } from "./editingElement.js";
2
+ import type { EditingParams, EditingResult } from "./editingPort.js";
2
3
  export type LayerKind = "image" | "video" | "audio" | "vector" | "group" | "text" | "shape";
3
4
  export interface EditingLayer {
4
5
  handle: EditingElementHandle;
@@ -22,3 +23,13 @@ export declare function layersOf(group?: EditingElementHandle, offset?: number):
22
23
  truncated: boolean;
23
24
  missingGroup: boolean;
24
25
  };
26
+ /**
27
+ * Tags that never paint, so they take no z slot in a stacking family: audio (the qa-clean audio
28
+ * element), script/style/link/meta, and template/noscript, whose markup a renumber must not touch.
29
+ */
30
+ export declare const NON_PAINTING_TAGS: Set<string>;
31
+ export interface EditingStackingSibling {
32
+ handle: EditingElementHandle;
33
+ zIndex: number;
34
+ }
35
+ export declare function stackingFamily({ handle, }: EditingParams<"stacking-family">): EditingResult<"stacking-family">;
@@ -100,3 +100,32 @@ export function layersOf(group, offset = 0) {
100
100
  })),
101
101
  };
102
102
  }
103
+ /**
104
+ * Tags that never paint, so they take no z slot in a stacking family: audio (the qa-clean audio
105
+ * element), script/style/link/meta, and template/noscript, whose markup a renumber must not touch.
106
+ */
107
+ export const NON_PAINTING_TAGS = new Set([
108
+ "AUDIO",
109
+ "SCRIPT",
110
+ "STYLE",
111
+ "LINK",
112
+ "META",
113
+ "TEMPLATE",
114
+ "NOSCRIPT",
115
+ ]);
116
+ export function stackingFamily({ handle, }) {
117
+ const element = elementForHandle(handle);
118
+ const parent = element?.parentElement;
119
+ if (!element || !parent)
120
+ return { family: null, locked: false };
121
+ const siblings = Array.from(parent.children).filter((child) => child === element || (isElementNode(child) && !NON_PAINTING_TAGS.has(child.tagName)));
122
+ return {
123
+ family: siblings.length > MAX_QUERY_MATCHES
124
+ ? null
125
+ : siblings.map((child) => ({
126
+ handle: handleFor(child),
127
+ zIndex: elementZIndex(child),
128
+ })),
129
+ locked: !!element.closest("[data-timeline-locked]"),
130
+ };
131
+ }
@@ -16,10 +16,11 @@ import type { EditingElementBox, EditingElementGeometry } from "./editingGeometr
16
16
  import type { EditingGestureStart } from "./editingGestureStart.js";
17
17
  import type { GsapSnapshot } from "./editing/gsapSnapshot.js";
18
18
  import type { MotionPathFrameHome } from "./editing/motionPathHome.js";
19
+ import type { EditingLayer, EditingStackingSibling } from "./editingLayers.js";
19
20
  import { type GsapSetParams } from "./editing/gsapSet.js";
20
21
  import { type PatchTweensParams } from "./editing/patchTween.js";
21
22
  import { type SoftReloadParams, type SoftReloadResult } from "./editing/softReload.js";
22
- import type { EditingLayer } from "./editingLayers.js";
23
+ import { type HoldScenesParams, type MarkScenesStaleParams, type SwapScenesParams, type SwapScenesResult } from "./editing/scenes.js";
23
24
  import type { RuntimeTimelineMessage } from "./types.js";
24
25
  import { type CaptionWordBox, type CaptionWordsParams } from "./editing/captionWords.js";
25
26
  import { type CaptionTransformParams, type CaptionWordState } from "./editing/captionTransform.js";
@@ -36,14 +37,14 @@ export type { EditingGestureStart } from "./editingGestureStart.js";
36
37
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
37
38
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
38
39
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
39
- export { elementZIndex, hasOnlyFormattingChildren, isCompositionHost, layerKindOf, type EditingLayer, type LayerKind, } from "./editingLayers.js";
40
+ export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
40
41
  export { composeElementTransform, individualRotateDegrees, type PlanarTransformOps, } from "./elementTransform.js";
41
42
  export declare const EDITING_PROTOCOL_VERSION: 1;
42
43
  /** Parent to frame, on the window: asks the runtime for the port. */
43
44
  export declare const EDITING_CONNECT = "editing-connect";
44
45
  /** Frame to parent, on the window: carries the port in its transfer list. */
45
46
  export declare const EDITING_PORT = "editing-port";
46
- export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "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", "gsap-set", "patch-tweens", "soft-reload", "assets-unloaded"];
47
+ export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "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", "assets-unloaded"];
47
48
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
48
49
  export interface EditingRuntimeSnapshot {
49
50
  /** The runtime has installed its player API. */
@@ -326,6 +327,15 @@ export interface EditingRequests {
326
327
  params: EditElementParams;
327
328
  result: EditElementResult;
328
329
  };
330
+ "stacking-family": {
331
+ params: {
332
+ handle: EditingElementHandle;
333
+ };
334
+ result: {
335
+ family: EditingStackingSibling[] | null;
336
+ locked: boolean;
337
+ };
338
+ };
329
339
  "gsap-set": {
330
340
  params: GsapSetParams;
331
341
  result: {
@@ -344,6 +354,22 @@ export interface EditingRequests {
344
354
  result: SoftReloadResult;
345
355
  };
346
356
  };
357
+ "hold-scenes": {
358
+ params: HoldScenesParams;
359
+ result: {
360
+ held: boolean;
361
+ };
362
+ };
363
+ "mark-scenes-stale": {
364
+ params: MarkScenesStaleParams;
365
+ result: {
366
+ marked: true;
367
+ };
368
+ };
369
+ "swap-scenes": {
370
+ params: SwapScenesParams;
371
+ result: SwapScenesResult;
372
+ };
347
373
  "assets-unloaded": {
348
374
  params: NoParams;
349
375
  result: {
@@ -15,6 +15,7 @@ import { EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, } from "./editingElement.
15
15
  import { parseGsapSet } from "./editing/gsapSet.js";
16
16
  import { parsePatchTweens } from "./editing/patchTween.js";
17
17
  import { parseSoftReload, } from "./editing/softReload.js";
18
+ import { parseHoldScenes, parseMarkScenesStale, parseSwapScenes, } from "./editing/scenes.js";
18
19
  import { wallClearTimeout, wallSetTimeout } from "./wallClock.js";
19
20
  import { parseCombo } from "../keyCombo.js";
20
21
  import { captionWordsParams, } from "./editing/captionWords.js";
@@ -31,7 +32,7 @@ export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTrans
31
32
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
32
33
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
33
34
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
34
- export { elementZIndex, hasOnlyFormattingChildren, isCompositionHost, layerKindOf, } from "./editingLayers.js";
35
+ export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
35
36
  export { composeElementTransform, individualRotateDegrees, } from "./elementTransform.js";
36
37
  export const EDITING_PROTOCOL_VERSION = 1;
37
38
  /** Parent to frame, on the window: asks the runtime for the port. */
@@ -71,9 +72,13 @@ export const EDITING_REQUEST_KINDS = [
71
72
  "max-z-index",
72
73
  "crop-lift",
73
74
  "edit-element",
75
+ "stacking-family",
74
76
  "gsap-set",
75
77
  "patch-tweens",
76
78
  "soft-reload",
79
+ "hold-scenes",
80
+ "mark-scenes-stale",
81
+ "swap-scenes",
77
82
  "assets-unloaded",
78
83
  ];
79
84
  export const MAX_DRAFT_PX = 100_000;
@@ -247,9 +252,13 @@ const PARAM_PARSERS = {
247
252
  ? { handle: params.handle, lift: params.lift }
248
253
  : null,
249
254
  "edit-element": parseEditElement,
255
+ "stacking-family": (params) => hasKeys(params, "handle") && isHandle(params.handle) ? { handle: params.handle } : null,
250
256
  "gsap-set": parseGsapSet,
251
257
  "patch-tweens": parsePatchTweens,
252
258
  "soft-reload": parseSoftReload,
259
+ "hold-scenes": parseHoldScenes,
260
+ "mark-scenes-stale": parseMarkScenesStale,
261
+ "swap-scenes": parseSwapScenes,
253
262
  "assets-unloaded": noParams,
254
263
  };
255
264
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
@@ -1,4 +1,5 @@
1
1
  import { decodedUrlPath } from "@hyperframes/parsers";
2
+ import { templateContent } from "@hyperframes/parsers/sub-composition-validity";
2
3
  function trimIdUnderscores(value) {
3
4
  let start = 0;
4
5
  let end = value.length;
@@ -26,10 +27,7 @@ export function buildTimelineAssetId(assetPath, existingIds) {
26
27
  function referenceChildren(element) {
27
28
  if (element.children.length > 0)
28
29
  return element.children;
29
- if (element.tagName.toLowerCase() !== "template")
30
- return [];
31
- const content = element.content;
32
- return content ? content.children : [];
30
+ return templateContent(element)?.children ?? [];
33
31
  }
34
32
  function documentElements(document) {
35
33
  const elements = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.70",
3
+ "version": "0.9.72",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -329,6 +329,10 @@
329
329
  "import": "./dist/runtime/editing/softReload.js",
330
330
  "types": "./dist/runtime/editing/softReload.d.ts"
331
331
  },
332
+ "./runtime/scenes": {
333
+ "import": "./dist/runtime/editing/scenes.js",
334
+ "types": "./dist/runtime/editing/scenes.d.ts"
335
+ },
332
336
  "./runtime/clip-window": {
333
337
  "import": "./dist/runtime/clipWindow.js",
334
338
  "types": "./dist/runtime/clipWindow.d.ts"
@@ -477,9 +481,9 @@
477
481
  "linkedom": "^0.18.12",
478
482
  "postcss": "^8.5.8",
479
483
  "wawoff2": "^2.0.1",
480
- "@hyperframes/lint": "0.9.70",
481
- "@hyperframes/parsers": "0.9.70",
482
- "@hyperframes/studio-server": "0.9.70"
484
+ "@hyperframes/studio-server": "0.9.72",
485
+ "@hyperframes/parsers": "0.9.72",
486
+ "@hyperframes/lint": "0.9.72"
483
487
  },
484
488
  "devDependencies": {
485
489
  "@fontsource/archivo-black": "^5.2.8",