@hyperframes/core 0.9.94 → 0.9.96

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 (61) hide show
  1. package/dist/atomicFile.js +14 -9
  2. package/dist/audibleVideo.d.ts +10 -0
  3. package/dist/audibleVideo.js +37 -0
  4. package/dist/compiler/htmlBundler.js +2 -0
  5. package/dist/compiler/index.d.ts +1 -0
  6. package/dist/compiler/index.js +1 -0
  7. package/dist/compiler/inlineSubCompositions.js +2 -1
  8. package/dist/compositionSource.d.ts +1 -0
  9. package/dist/compositionSource.js +22 -1
  10. package/dist/generated/runtime-inline.js +1 -1
  11. package/dist/hyperframe.runtime.iife.js +67 -67
  12. package/dist/index.d.ts +1 -1
  13. package/dist/runtime/adapters/seek-dispatch.d.ts +40 -0
  14. package/dist/runtime/adapters/seek-dispatch.js +164 -0
  15. package/dist/runtime/assetUrl.d.ts +6 -0
  16. package/dist/runtime/assetUrl.js +8 -0
  17. package/dist/runtime/audioFx.d.ts +77 -0
  18. package/dist/runtime/audioFx.js +277 -0
  19. package/dist/runtime/bridge.d.ts +6 -0
  20. package/dist/runtime/bridge.js +20 -0
  21. package/dist/runtime/decodesFirst.d.ts +4 -0
  22. package/dist/runtime/decodesFirst.js +14 -0
  23. package/dist/runtime/drawnBox.d.ts +29 -0
  24. package/dist/runtime/drawnBox.js +100 -0
  25. package/dist/runtime/editingDraft.d.ts +0 -11
  26. package/dist/runtime/editingDraft.js +1 -61
  27. package/dist/runtime/editingElement.js +3 -3
  28. package/dist/runtime/editingGestureStart.d.ts +2 -6
  29. package/dist/runtime/editingGestureStart.js +1 -40
  30. package/dist/runtime/editingHandles.d.ts +4 -0
  31. package/dist/runtime/editingHandles.js +9 -0
  32. package/dist/runtime/editingPort.d.ts +5 -0
  33. package/dist/runtime/editingPort.js +5 -1
  34. package/dist/runtime/media.d.ts +113 -0
  35. package/dist/runtime/media.js +820 -0
  36. package/dist/runtime/mediaLoadFailure.d.ts +8 -0
  37. package/dist/runtime/mediaLoadFailure.js +58 -0
  38. package/dist/runtime/mediaProxy.d.ts +91 -0
  39. package/dist/runtime/mediaProxy.js +803 -0
  40. package/dist/runtime/playbackHealth.d.ts +31 -0
  41. package/dist/runtime/playbackHealth.js +137 -0
  42. package/dist/runtime/preloadMedia.d.ts +16 -0
  43. package/dist/runtime/preloadMedia.js +266 -0
  44. package/dist/runtime/previewCopies.d.ts +13 -0
  45. package/dist/runtime/previewCopies.js +80 -0
  46. package/dist/runtime/proxyWait.d.ts +3 -0
  47. package/dist/runtime/proxyWait.js +51 -0
  48. package/dist/runtime/runtimeLoad.d.ts +3 -0
  49. package/dist/runtime/runtimeLoad.js +13 -0
  50. package/dist/runtime/state.d.ts +7 -0
  51. package/dist/runtime/state.js +3 -0
  52. package/dist/runtime/timedClipHide.d.ts +12 -0
  53. package/dist/runtime/timedClipHide.js +94 -0
  54. package/dist/runtime/types.d.ts +29 -18
  55. package/dist/runtime/webAudioTransport.d.ts +241 -0
  56. package/dist/runtime/webAudioTransport.js +1162 -0
  57. package/dist/safePath.d.ts +2 -0
  58. package/dist/safePath.js +41 -13
  59. package/dist/studioPreviewMark.js +2 -4
  60. package/dist/utils/inlineTextStyleRead.js +2 -4
  61. package/package.json +16 -4
@@ -53,13 +53,7 @@ export function replaceFileAtomically(filePath, content, mode, operations = fs)
53
53
  /** Async twin of {@link replaceFileAtomically}: a disk that never answers holds a pool thread, never the caller's. */
54
54
  export async function replaceFileAtomicallyAsync(filePath, content, mode) {
55
55
  traceWrite(filePath, content);
56
- try {
57
- await fsp.access(filePath, fs.constants.W_OK);
58
- }
59
- catch (error) {
60
- if (errorCode(error) !== "ENOENT")
61
- throw error;
62
- }
56
+ await refuseReadOnlyAsync(filePath);
63
57
  const tempPath = await writeTempSiblingAsync(filePath, content, mode);
64
58
  try {
65
59
  if (mode !== undefined)
@@ -93,10 +87,21 @@ export function refuseReadOnly(filePath) {
93
87
  fs.accessSync(filePath, fs.constants.W_OK);
94
88
  }
95
89
  catch (error) {
96
- if (errorCode(error) !== "ENOENT")
97
- throw error;
90
+ readOnlyOrMissing(error);
98
91
  }
99
92
  }
93
+ async function refuseReadOnlyAsync(filePath) {
94
+ try {
95
+ await fsp.access(filePath, fs.constants.W_OK);
96
+ }
97
+ catch (error) {
98
+ readOnlyOrMissing(error);
99
+ }
100
+ }
101
+ function readOnlyOrMissing(error) {
102
+ if (errorCode(error) !== "ENOENT")
103
+ throw error;
104
+ }
100
105
  /** Create a file that must not exist yet (EEXIST otherwise); readers never see it empty or partial. */
101
106
  export function createFileAtomically(filePath, content, operations = fs) {
102
107
  publishSibling(filePath, content, undefined, operations, (tempPath) => {
@@ -12,12 +12,22 @@ export declare function audibleVideoNeedsWebAudio(fields: {
12
12
  audioGroup?: string | null;
13
13
  masterChain?: string | null;
14
14
  }): boolean;
15
+ export declare const PARENT_COPY_ATTRIBUTES: readonly ["data-playback-rate", "data-automation", "data-fx-chain", "data-audio-group", "data-volume", "data-fade-in", "data-fade-out"];
15
16
  export interface ParentCopy {
16
17
  kind: "audio" | "video";
17
18
  src: string;
18
19
  start: number;
19
20
  duration: number;
20
21
  mediaStart: number;
22
+ layer?: number;
23
+ loop?: boolean;
24
+ mastered?: boolean;
25
+ attrs?: Partial<Record<(typeof PARENT_COPY_ATTRIBUTES)[number], string>>;
21
26
  }
27
+ export declare function parentCopyKey(copy: Pick<ParentCopy, "kind" | "src" | "start" | "mediaStart" | "layer">): string;
28
+ export declare function parentCopyLayers(): (elements: readonly HTMLMediaElement[]) => {
29
+ el: HTMLMediaElement;
30
+ copy: ParentCopy;
31
+ }[];
22
32
  export declare function mediaFileOf(el: HTMLMediaElement): string | null;
23
33
  export declare function parentCopyOf(el: HTMLMediaElement): ParentCopy | null;
@@ -12,6 +12,35 @@ export function audibleVideoNeedsWebAudio(fields) {
12
12
  return ((fields.volume ?? 1) > 1 ||
13
13
  Boolean(fields.fxChain || fields.automation || fields.audioGroup || fields.masterChain));
14
14
  }
15
+ export const PARENT_COPY_ATTRIBUTES = [
16
+ "data-playback-rate",
17
+ "data-automation",
18
+ "data-fx-chain",
19
+ "data-audio-group",
20
+ "data-volume",
21
+ "data-fade-in",
22
+ "data-fade-out",
23
+ ];
24
+ export function parentCopyKey(copy) {
25
+ return JSON.stringify([copy.kind, copy.src, copy.start, copy.mediaStart, copy.layer ?? 0]);
26
+ }
27
+ export function parentCopyLayers() {
28
+ const layerOf = new WeakMap();
29
+ const nextLayer = new Map();
30
+ return (elements) => elements.flatMap((el) => {
31
+ const copy = parentCopyOf(el);
32
+ if (!copy)
33
+ return [];
34
+ const shared = parentCopyKey(copy);
35
+ let slot = layerOf.get(el);
36
+ if (slot?.shared !== shared) {
37
+ slot = { shared, layer: nextLayer.get(shared) ?? 0 };
38
+ nextLayer.set(shared, slot.layer + 1);
39
+ layerOf.set(el, slot);
40
+ }
41
+ return [{ el, copy: slot.layer === 0 ? copy : { ...copy, layer: slot.layer } }];
42
+ });
43
+ }
15
44
  export function mediaFileOf(el) {
16
45
  const raw = el.getAttribute("src") || el.querySelector("source")?.getAttribute("src");
17
46
  if (!raw)
@@ -33,11 +62,19 @@ export function parentCopyOf(el) {
33
62
  if (!src)
34
63
  return null;
35
64
  const timing = readClipTiming(el);
65
+ const attrs = {};
66
+ for (const name of PARENT_COPY_ATTRIBUTES) {
67
+ const value = el.getAttribute(name);
68
+ if (value !== null)
69
+ attrs[name] = value;
70
+ }
36
71
  return {
37
72
  kind: tag === "audio" ? "audio" : "video",
38
73
  src,
39
74
  start: timing.start ?? 0,
40
75
  duration: timing.duration ?? Number.POSITIVE_INFINITY,
41
76
  mediaStart: readLinkTiming(el).mediaStart,
77
+ loop: el.loop,
78
+ attrs,
42
79
  };
43
80
  }
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { compositionStyle, cssStyleMergeKey, deferScriptsUntilFonts, isAlwaysAppliedStyle, headStyleRuns, INLINED_FILE_ATTR, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
3
3
  import { countPageRoot, executableScripts, isJavaScriptType, planCompositionAssembly, } from "./compositionAssembly.js";
4
4
  import { SCENE_FONTS_ATTR, SCENE_PART_ATTR } from "../sceneParts.js";
5
+ import { dropAuthoredCompositionFiles } from "../compositionSource.js";
5
6
  import { stripSdrPngColourTags } from "./pngColourTags.js";
6
7
  import { ensureExternalScriptTag, readExternalScriptAttributes, } from "./externalScripts.js";
7
8
  import { emitMountedModuleScripts, parseImportMap } from "./importMaps.js";
@@ -1013,6 +1014,7 @@ async function bundleProject(projectDir, options) {
1013
1014
  })),
1014
1015
  ].map((text) => (isLibraryCopy(text) ? "" : text))
1015
1016
  : [];
1017
+ dropAuthoredCompositionFiles(document);
1016
1018
  // Inline sub-compositions (via shared function)
1017
1019
  const trackedCompositionHosts = getBundledTrackedCompositionHosts(document);
1018
1020
  const hostIdentityByElement = assignBundledRuntimeCompositionIds(trackedCompositionHosts);
@@ -3,6 +3,7 @@ export { compileTimingAttrs, injectDurations, extractResolvedMedia, clampDuratio
3
3
  export { compileHtml, type MediaDurationProber } from "./htmlCompiler.js";
4
4
  export { assignBundledRuntimeCompositionIds, type BundledHostCompositionIdentity, bundleToSingleHtml, type BundleOptions, type BundlePrivateFiles, type BundleScriptProvenance, prepareFlattenedInnerRoot, FLATTENED_INNER_ROOT_STRIP_ATTRS, emitRootCompositionVariableStyles, MAX_COMPOSITION_VARIABLE_STYLE_BYTES, parsesAsScript, } from "./htmlBundler.js";
5
5
  export { readDeclaredDefaults, parseHostVariableValues } from "../runtime/getVariables.js";
6
+ export { dropAuthoredCompositionFiles } from "../compositionSource.js";
6
7
  export { boundMediaSrc } from "../runtime/applyVariableBindings.js";
7
8
  export { extractCompiledHtmlParityContract, type CompiledHtmlParityContract, type HtmlParityComposition, type HtmlParityResource, type HtmlParityTimedElement, } from "./htmlParityContract.js";
8
9
  export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument.js";
@@ -8,6 +8,7 @@ export { compileHtml } from "./htmlCompiler.js";
8
8
  // HTML bundler (Node.js — requires fs, linkedom, esbuild)
9
9
  export { assignBundledRuntimeCompositionIds, bundleToSingleHtml, prepareFlattenedInnerRoot, FLATTENED_INNER_ROOT_STRIP_ATTRS, emitRootCompositionVariableStyles, MAX_COMPOSITION_VARIABLE_STYLE_BYTES, parsesAsScript, } from "./htmlBundler.js";
10
10
  export { readDeclaredDefaults, parseHostVariableValues } from "../runtime/getVariables.js";
11
+ export { dropAuthoredCompositionFiles } from "../compositionSource.js";
11
12
  export { boundMediaSrc } from "../runtime/applyVariableBindings.js";
12
13
  export { extractCompiledHtmlParityContract, } from "./htmlParityContract.js";
13
14
  export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument.js";
@@ -19,7 +19,7 @@ import { checkSubCompositionUsability, resolveSubCompositionContent, } from "@hy
19
19
  import { enumerateNestedCompositionHosts, planCompositionAssembly, extractedCompositionAssets, } from "./compositionAssembly.js";
20
20
  import { SCENE_NO_SWAP_ATTR, SCENE_PART_ATTR } from "../sceneParts.js";
21
21
  import { terminalText } from "../terminalText.js";
22
- import { COMPOSITION_SRC_ATTR } from "../compositionSource.js";
22
+ import { COMPOSITION_SRC_ATTR, dropAuthoredCompositionFiles } from "../compositionSource.js";
23
23
  // Anything a scene script can leave running, pending or registered outside its timeline, or that
24
24
  // throws when run again: only the timeline is torn down when a scene is swapped, so when unsure, refuse.
25
25
  const SIDE_EFFECT_RE = /\b(addEventListener|requestAnimationFrame|requestIdleCallback|setTimeout|setInterval|queueMicrotask|getContext|WebGL\w*|WebGPU\w*|gpu|Worker|WebSocket|EventSource|Audio\w*|\w*Observer|fetch|import|eval|Function|Promise|async|await|delayedCall|ScrollTrigger|Draggable|anime|customElements|registerProperty|addListener|BroadcastChannel|pushState|replaceState|adoptedStyleSheets|documentElement|getElementsByTagName|lottie|THREE|__hf[A-Z]\w*)\b|\.then\s*\(|\.ticker\b|repeat\s*:\s*-1|\.repeat\s*\(\s*-1|defineProperty\s*\(\s*(window|globalThis|self|document)\b|\bfonts\s*\.\s*add\b|\.on[a-z]+\s*=(?!=)|\bon(resize|scroll|message|key\w+|click|pointer\w+|mouse\w+|wheel|visibilitychange|hashchange|popstate|error|load)\s*=(?!=)|\[\s*["']on[a-z]+["']\s*\]|document\s*\.\s*(head|body)\b|querySelector(All)?\(\s*["'](head|body)["']|\bgsap\s*\.\s*(?:to|from|fromTo)\s*\(|\bgsap\s*\.\s*timeline\s*\((?:[^()]|\([^()]*\))*\)\s*\.\s*(?:to|from|fromTo|set|add|call)\s*\(/;
@@ -305,6 +305,7 @@ export function inlineSubCompositions(document, hosts, options) {
305
305
  onMissingComposition?.(src);
306
306
  continue;
307
307
  }
308
+ dropAuthoredCompositionFiles(contentDoc);
308
309
  // Which node is the composition root, which id its CSS scopes to, which
309
310
  // id its scripts scope to, where its assets come from and in what order —
310
311
  // every one of those is decided by the shared assembly module, so the mount
@@ -2,3 +2,4 @@ export declare const COMPOSITION_SRC_ATTR = "data-composition-src";
2
2
  export declare const CODE_LOADING_ATTRS: ReadonlySet<string>;
3
3
  export declare const SOURCE_HOST_ATTRS: readonly ["data-composition-file", "data-composition-src"];
4
4
  export declare const COMPOSITION_ROOT_ATTRS: readonly ["data-composition-id", "data-hf-original-composition-id"];
5
+ export declare function dropAuthoredCompositionFiles(root: ParentNode): void;
@@ -1,7 +1,28 @@
1
1
  export const COMPOSITION_SRC_ATTR = "data-composition-src";
2
2
  export const CODE_LOADING_ATTRS = new Set([COMPOSITION_SRC_ATTR]);
3
- export const SOURCE_HOST_ATTRS = ["data-composition-file", COMPOSITION_SRC_ATTR];
3
+ const COMPOSITION_FILE_ATTR = "data-composition-file";
4
+ export const SOURCE_HOST_ATTRS = [COMPOSITION_FILE_ATTR, COMPOSITION_SRC_ATTR];
4
5
  export const COMPOSITION_ROOT_ATTRS = [
5
6
  "data-composition-id",
6
7
  "data-hf-original-composition-id",
7
8
  ];
9
+ function nextInDocumentOrder(element, root) {
10
+ if (element.firstElementChild)
11
+ return element.firstElementChild;
12
+ for (let at = element; at && at !== root; at = at.parentElement)
13
+ if (at.nextElementSibling)
14
+ return at.nextElementSibling;
15
+ return null;
16
+ }
17
+ export function dropAuthoredCompositionFiles(root) {
18
+ for (let el = root.firstElementChild; el; el = nextInDocumentOrder(el, root)) {
19
+ for (const name of el.getAttributeNames())
20
+ if (name.toLowerCase() === COMPOSITION_FILE_ATTR)
21
+ el.removeAttribute(name);
22
+ const browserTemplateContent = el.localName === "template" && !el.hasChildNodes()
23
+ ? el.content
24
+ : null;
25
+ if (browserTemplateContent)
26
+ dropAuthoredCompositionFiles(browserTemplateContent);
27
+ }
28
+ }