@hyperframes/core 0.9.81 → 0.9.83

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 (38) hide show
  1. package/dist/audibleVideo.d.ts +9 -0
  2. package/dist/audibleVideo.js +31 -0
  3. package/dist/compiler/index.d.ts +1 -1
  4. package/dist/compiler/index.js +1 -1
  5. package/dist/compiler/inlineSubCompositions.js +3 -2
  6. package/dist/compiler/timingCompiler.js +39 -35
  7. package/dist/compositionSource.d.ts +2 -0
  8. package/dist/compositionSource.js +2 -0
  9. package/dist/generated/runtime-inline.js +1 -1
  10. package/dist/gsapCdn.d.ts +11 -1
  11. package/dist/gsapCdn.js +24 -1
  12. package/dist/hyperframe.runtime.iife.js +69 -69
  13. package/dist/runtime/bridge.d.ts +1 -0
  14. package/dist/runtime/bridge.js +4 -1
  15. package/dist/runtime/editing/patchTween.d.ts +1 -1
  16. package/dist/runtime/editing/patchTween.js +34 -12
  17. package/dist/runtime/editing/softReload.d.ts +0 -1
  18. package/dist/runtime/editing/softReload.js +28 -5
  19. package/dist/runtime/editing/watchGeometry.js +5 -2
  20. package/dist/runtime/editingElement.d.ts +1 -0
  21. package/dist/runtime/editingElement.js +1 -0
  22. package/dist/runtime/editingGeometry.d.ts +4 -0
  23. package/dist/runtime/editingGeometry.js +10 -9
  24. package/dist/runtime/editingGestureStart.d.ts +0 -5
  25. package/dist/runtime/editingGestureStart.js +1 -4
  26. package/dist/runtime/editingPort.d.ts +2 -3
  27. package/dist/runtime/editingPort.js +2 -3
  28. package/dist/runtime/elementTransform.d.ts +12 -55
  29. package/dist/runtime/elementTransform.js +50 -75
  30. package/dist/runtime/protocol.d.ts +1 -1
  31. package/dist/runtime/protocol.js +1 -0
  32. package/dist/runtime/sceneRest.d.ts +4 -0
  33. package/dist/runtime/sceneRest.js +15 -0
  34. package/dist/runtime/state.d.ts +1 -5
  35. package/dist/runtime/transitionLabels.js +9 -2
  36. package/dist/runtime/types.d.ts +2 -0
  37. package/dist/utils/htmlAttrSafety.js +3 -0
  38. package/package.json +4 -4
@@ -12,3 +12,12 @@ export declare function audibleVideoNeedsWebAudio(fields: {
12
12
  audioGroup?: string | null;
13
13
  masterChain?: string | null;
14
14
  }): boolean;
15
+ export interface ParentCopy {
16
+ kind: "audio" | "video";
17
+ src: string;
18
+ start: number;
19
+ duration: number;
20
+ mediaStart: number;
21
+ }
22
+ export declare function mediaFileOf(el: HTMLMediaElement): string | null;
23
+ export declare function parentCopyOf(el: HTMLMediaElement): ParentCopy | null;
@@ -1,3 +1,5 @@
1
+ import { readClipTiming } from "./compositionContract.js";
2
+ import { readLinkTiming } from "./mediaLink.js";
1
3
  export const AUDIBLE_VIDEO_QUALIFIER = ':not([muted]):is(:not([data-has-audio]),[data-has-audio="true"])';
2
4
  export const AUDIBLE_MEDIA_SELECTOR = `audio[data-start], video[data-start]${AUDIBLE_VIDEO_QUALIFIER}`;
3
5
  export function isAudibleVideoElement(el) {
@@ -10,3 +12,32 @@ export function audibleVideoNeedsWebAudio(fields) {
10
12
  return ((fields.volume ?? 1) > 1 ||
11
13
  Boolean(fields.fxChain || fields.automation || fields.audioGroup || fields.masterChain));
12
14
  }
15
+ export function mediaFileOf(el) {
16
+ const raw = el.getAttribute("src") || el.querySelector("source")?.getAttribute("src");
17
+ if (!raw)
18
+ return null;
19
+ try {
20
+ return new URL(raw, el.ownerDocument.baseURI).href;
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ export function parentCopyOf(el) {
27
+ if (el.preload === "metadata" || el.preload === "none")
28
+ return null;
29
+ const tag = el.tagName.toLowerCase();
30
+ if (tag !== "audio" && !isAudibleVideoElement(el))
31
+ return null;
32
+ const src = mediaFileOf(el);
33
+ if (!src)
34
+ return null;
35
+ const timing = readClipTiming(el);
36
+ return {
37
+ kind: tag === "audio" ? "audio" : "video",
38
+ src,
39
+ start: timing.start ?? 0,
40
+ duration: timing.duration ?? Number.POSITIVE_INFINITY,
41
+ mediaStart: readLinkTiming(el).mediaStart,
42
+ };
43
+ }
@@ -7,7 +7,7 @@ export { boundMediaSrc } from "../runtime/applyVariableBindings.js";
7
7
  export { extractCompiledHtmlParityContract, type CompiledHtmlParityContract, type HtmlParityComposition, type HtmlParityResource, type HtmlParityTimedElement, } from "./htmlParityContract.js";
8
8
  export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument.js";
9
9
  export { addScenePartsManifest } from "./scenePartsManifest.js";
10
- export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, isAlwaysAppliedStyle, deferScriptsUntilFonts, headStyleRuns, inlineScriptRuns, styleElementsFor, type CompositionStyle, type InlineScriptRun, } from "./scriptRuns.js";
10
+ export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, isAlwaysAppliedStyle, deferScriptsUntilFonts, headStyleRuns, INLINED_FILE_ATTR, inlineScriptRuns, styleElementsFor, type CompositionStyle, type InlineScriptRun, } from "./scriptRuns.js";
11
11
  export { isJavaScriptType } from "./compositionAssembly.js";
12
12
  export { validateHyperframeHtmlContract, type HyperframeStaticFailureReason, type HyperframeStaticGuardResult, } from "./staticGuard.js";
13
13
  export { buildVariablesByCompScript, emitVariablesByCompScript, dedupeFontFaceRules, scopeCssToComposition, wrapScopedCompositionScript, } from "./compositionScoping.js";
@@ -13,7 +13,7 @@ export { extractCompiledHtmlParityContract, } from "./htmlParityContract.js";
13
13
  export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument.js";
14
14
  export { addScenePartsManifest } from "./scenePartsManifest.js";
15
15
  // Script ordering shared by the bundler and the producer coalescers
16
- export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, isAlwaysAppliedStyle, deferScriptsUntilFonts, headStyleRuns, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
16
+ export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, isAlwaysAppliedStyle, deferScriptsUntilFonts, headStyleRuns, INLINED_FILE_ATTR, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
17
17
  export { isJavaScriptType } from "./compositionAssembly.js";
18
18
  // Static guard
19
19
  export { validateHyperframeHtmlContract, } from "./staticGuard.js";
@@ -19,6 +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
23
  // Anything a scene script can leave running, pending or registered outside its timeline, or that
23
24
  // throws when run again: only the timeline is torn down when a scene is swapped, so when unsure, refuse.
24
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*\(/;
@@ -253,7 +254,7 @@ export function inlineSubCompositions(document, hosts, options) {
253
254
  }));
254
255
  for (let queueIndex = 0; queueIndex < queue.length; queueIndex += 1) {
255
256
  const { element: hostEl, ancestry, scene: parentScene } = queue[queueIndex];
256
- const src = hostEl.getAttribute("data-composition-src");
257
+ const src = hostEl.getAttribute(COMPOSITION_SRC_ATTR);
257
258
  if (!src)
258
259
  continue;
259
260
  const compHtml = resolveHtml(src);
@@ -556,7 +557,7 @@ export function inlineSubCompositions(document, hosts, options) {
556
557
  for (const el of plan.inertScriptsOutsideRoot)
557
558
  hostEl.insertAdjacentHTML("beforeend", el.outerHTML);
558
559
  hostEl.setAttribute("data-composition-file", src);
559
- hostEl.removeAttribute("data-composition-src");
560
+ hostEl.removeAttribute(COMPOSITION_SRC_ATTR);
560
561
  const nestedAncestry = [...ancestry, src];
561
562
  const nested = enumerateNestedCompositionHosts(hostEl, nestedAncestry);
562
563
  for (const skipped of nested.skipped) {
@@ -81,17 +81,28 @@ function replaceOpeningTags(html, names, replace) {
81
81
  parts.push(html.slice(cursor));
82
82
  return parts.join("");
83
83
  }
84
- function replaceIdTags(html, id, replace) {
84
+ /** Applies each tag's durations, in the order given, in one scan of the page however many there are. */
85
+ function applyDurationsById(html, resolutions, apply) {
86
+ const durationsById = new Map();
87
+ for (const { id, duration } of resolutions) {
88
+ const durations = durationsById.get(id);
89
+ if (durations)
90
+ durations.push(duration);
91
+ else
92
+ durationsById.set(id, [duration]);
93
+ }
85
94
  const parts = [];
86
95
  let cursor = 0;
87
96
  for (const span of scanHtmlOpeningTags(html)) {
88
97
  if (!span.closed)
89
98
  continue;
90
- const tag = html.slice(span.start, span.end);
91
99
  const attr = span.attributes.find((attr) => attr.name === "id");
92
- if (attr?.kind !== "value" || decodeAuthoredAttribute(attr.value) !== id)
100
+ if (attr?.kind !== "value")
101
+ continue;
102
+ const durations = durationsById.get(decodeAuthoredAttribute(attr.value));
103
+ if (!durations)
93
104
  continue;
94
- parts.push(html.slice(cursor, span.start), replace(tag));
105
+ parts.push(html.slice(cursor, span.start), durations.reduce(apply, html.slice(span.start, span.end)));
95
106
  cursor = span.end;
96
107
  }
97
108
  parts.push(html.slice(cursor));
@@ -209,25 +220,21 @@ export function compileTimingAttrs(html) {
209
220
  * GSAP timeline queries.
210
221
  */
211
222
  export function injectDurations(html, resolutions) {
212
- for (const { id, duration } of resolutions) {
213
- // Match the element's opening tag by id
214
- html = replaceIdTags(html, id, (tag) => {
215
- let result = tag;
216
- // Add data-duration if missing
217
- if (parseStrictFiniteTimingNumber(getAttr(result, "data-duration")) == null) {
218
- result = setAttr(result, "data-duration", String(duration));
219
- }
220
- // Add data-end if missing. Skip relative id-refs.
221
- if (!hasAttr(result, "data-end")) {
222
- const start = parseNumeric(getAttr(result, "data-start"));
223
- if (start != null) {
224
- result = injectAttr(result, "data-end", String(start + duration));
225
- }
223
+ return applyDurationsById(html, resolutions, (tag, duration) => {
224
+ let result = tag;
225
+ // Add data-duration if missing
226
+ if (parseStrictFiniteTimingNumber(getAttr(result, "data-duration")) == null) {
227
+ result = setAttr(result, "data-duration", String(duration));
228
+ }
229
+ // Add data-end if missing. Skip relative id-refs.
230
+ if (!hasAttr(result, "data-end")) {
231
+ const start = parseNumeric(getAttr(result, "data-start"));
232
+ if (start != null) {
233
+ result = injectAttr(result, "data-end", String(start + duration));
226
234
  }
227
- return result;
228
- });
229
- }
230
- return html;
235
+ }
236
+ return result;
237
+ });
231
238
  }
232
239
  /**
233
240
  * Extract video/audio elements that already have data-duration set.
@@ -265,17 +272,14 @@ export function extractResolvedMedia(html) {
265
272
  * and recomputes data-end accordingly.
266
273
  */
267
274
  export function clampDurations(html, clamps) {
268
- for (const { id, duration } of clamps) {
269
- html = replaceIdTags(html, id, (tag) => {
270
- // Replace data-duration value
271
- if (hasAttr(tag, "data-duration"))
272
- tag = setAttr(tag, "data-duration", String(duration));
273
- const start = parseNumeric(getAttr(tag, "data-start"));
274
- if (start != null && hasAttr(tag, "data-end")) {
275
- tag = setAttr(tag, "data-end", String(start + duration));
276
- }
277
- return tag;
278
- });
279
- }
280
- return html;
275
+ return applyDurationsById(html, clamps, (tag, duration) => {
276
+ // Replace data-duration value
277
+ if (hasAttr(tag, "data-duration"))
278
+ tag = setAttr(tag, "data-duration", String(duration));
279
+ const start = parseNumeric(getAttr(tag, "data-start"));
280
+ if (start != null && hasAttr(tag, "data-end")) {
281
+ tag = setAttr(tag, "data-end", String(start + duration));
282
+ }
283
+ return tag;
284
+ });
281
285
  }
@@ -0,0 +1,2 @@
1
+ export declare const COMPOSITION_SRC_ATTR = "data-composition-src";
2
+ export declare const CODE_LOADING_ATTRS: ReadonlySet<string>;
@@ -0,0 +1,2 @@
1
+ export const COMPOSITION_SRC_ATTR = "data-composition-src";
2
+ export const CODE_LOADING_ATTRS = new Set([COMPOSITION_SRC_ATTR]);