@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
@@ -0,0 +1,29 @@
1
+ /**
2
+ * How a draft draws an element's box, shared by the frame's editing channel and a parent that scripts
3
+ * the frame itself, so both measure a resize the same way. Reads the DOM only when called.
4
+ */
5
+ import type { StylableElement as Styled } from "./domRealm.js";
6
+ export declare const SIZE_PROPERTIES: readonly ["box-sizing", "width", "height", "min-width", "min-height", "max-width", "max-height"];
7
+ export declare const PROBE_PX = 100;
8
+ export declare const MIN_PROBE_RESPONSE = 0.01;
9
+ /** Frame px its centre moves per px of drawn width, `a, b`, and height, `c, d`; null when it has no box. */
10
+ export type Grow = {
11
+ a: number;
12
+ b: number;
13
+ c: number;
14
+ d: number;
15
+ } | null;
16
+ export declare function computedTranslateAxes(element: Styled): string[];
17
+ export declare function movedTranslate([x, y, z]: string[], offset: {
18
+ x: number;
19
+ y: number;
20
+ }): string;
21
+ export declare function writeDrawnSize(style: CSSStyleDeclaration, size: {
22
+ width: number;
23
+ height: number;
24
+ }): void;
25
+ /** Where its centre goes as a draft draws its size, so a resize can pin it; its inline size put back. */
26
+ export declare function measureGrowResponse(element: Styled, layout: {
27
+ width: number;
28
+ height: number;
29
+ }): Grow;
@@ -0,0 +1,100 @@
1
+ export const SIZE_PROPERTIES = [
2
+ "box-sizing",
3
+ "width",
4
+ "height",
5
+ "min-width",
6
+ "min-height",
7
+ "max-width",
8
+ "max-height",
9
+ ];
10
+ export const PROBE_PX = 100;
11
+ export const MIN_PROBE_RESPONSE = 0.01;
12
+ /** "calc(50% + 2px) 4px" as its top-level parts. */
13
+ function axes(value) {
14
+ const parts = [];
15
+ let depth = 0;
16
+ let part = "";
17
+ for (const char of value.trim()) {
18
+ depth += char === "(" ? 1 : char === ")" ? -1 : 0;
19
+ if (/\s/.test(char) && depth === 0) {
20
+ if (part)
21
+ parts.push(part);
22
+ part = "";
23
+ }
24
+ else
25
+ part += char;
26
+ }
27
+ if (part)
28
+ parts.push(part);
29
+ return parts;
30
+ }
31
+ /** The side a translate's % takes a share of: the box `transform-box` names. */
32
+ function percentSide(computed, size) {
33
+ const [a, b] = size === "width" ? ["left", "right"] : ["top", "bottom"];
34
+ const n = (name) => Number.parseFloat(computed.getPropertyValue(name)) || 0;
35
+ const pad = n(`padding-${a}`) + n(`padding-${b}`) + n(`border-${a}-width`) + n(`border-${b}-width`);
36
+ const content = n(size) - (computed.getPropertyValue("box-sizing") === "border-box" ? pad : 0);
37
+ const box = computed.getPropertyValue("transform-box");
38
+ return box === "content-box" || box === "fill-box" ? content : content + pad;
39
+ }
40
+ /** Each % as the px it is now, so a resize drawn with it does not move the element again. */
41
+ function percentAsPx(axis, side) {
42
+ return axis.replace(/(-?\d*\.?\d+(?:e[-+]?\d+)?)%/gi, (_, n) => `${(Number(n) * side) / 100}px`);
43
+ }
44
+ export function computedTranslateAxes(element) {
45
+ const computed = (element.ownerDocument.defaultView ?? window).getComputedStyle(element);
46
+ const translate = computed.getPropertyValue("translate");
47
+ if (!translate || translate === "none")
48
+ return [];
49
+ const sides = [percentSide(computed, "width"), percentSide(computed, "height")];
50
+ return axes(translate).map((axis, i) => (i < 2 ? percentAsPx(axis, sides[i]) : axis));
51
+ }
52
+ export function movedTranslate([x = "0px", y = "0px", z], offset) {
53
+ return `calc(${x} + ${offset.x}px) calc(${y} + ${offset.y}px)${z ? ` ${z}` : ""}`;
54
+ }
55
+ export function writeDrawnSize(style, size) {
56
+ style.setProperty("box-sizing", "border-box");
57
+ style.setProperty("width", `${size.width}px`);
58
+ style.setProperty("height", `${size.height}px`);
59
+ for (const name of ["min-width", "min-height"])
60
+ style.setProperty(name, "0px");
61
+ for (const name of ["max-width", "max-height"])
62
+ style.setProperty(name, "none");
63
+ }
64
+ /** Where its centre goes as a draft draws its size, so a resize can pin it; its inline size put back. */
65
+ export function measureGrowResponse(element, layout) {
66
+ const { style } = element;
67
+ const kept = [...SIZE_PROPERTIES, "translate"].map((name) => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
68
+ const translateAsTheResizeDraftDrawsIt = movedTranslate(computedTranslateAxes(element), {
69
+ x: 0,
70
+ y: 0,
71
+ });
72
+ const centre = (width, height) => {
73
+ style.setProperty("translate", translateAsTheResizeDraftDrawsIt);
74
+ writeDrawnSize(style, { width, height });
75
+ const box = element.getBoundingClientRect();
76
+ return box.width > 0 || box.height > 0
77
+ ? { x: box.left + box.width / 2, y: box.top + box.height / 2 }
78
+ : null;
79
+ };
80
+ try {
81
+ if (layout.width < 1 || layout.height < 1)
82
+ return null;
83
+ const origin = centre(layout.width, layout.height);
84
+ const wider = centre(layout.width + PROBE_PX, layout.height);
85
+ const taller = centre(layout.width, layout.height + PROBE_PX);
86
+ if (!origin || !wider || !taller)
87
+ return null;
88
+ const per = (p) => [(p.x - origin.x) / PROBE_PX, (p.y - origin.y) / PROBE_PX];
89
+ const [[a, b], [c, d]] = [per(wider), per(taller)];
90
+ return [a, b, c, d].every(Number.isFinite) ? { a: a, b: b, c: c, d: d } : null;
91
+ }
92
+ finally {
93
+ for (const [name, value, priority] of kept) {
94
+ if (value)
95
+ style.setProperty(name, value, priority);
96
+ else
97
+ style.removeProperty(name);
98
+ }
99
+ }
100
+ }
@@ -1,16 +1,5 @@
1
- import { type StylableElement as Styled } from "./domRealm.js";
2
1
  import type { EditingDraftReply } from "./editingDraftEnd.js";
3
2
  import type { EditingDraft } from "./editingPort.js";
4
- export declare const SIZE_PROPERTIES: readonly ["box-sizing", "width", "height", "min-width", "min-height", "max-width", "max-height"];
5
- export declare function computedTranslateAxes(element: Styled): string[];
6
- export declare function movedTranslate([x, y, z]: string[], offset: {
7
- x: number;
8
- y: number;
9
- }): string;
10
3
  export declare function rebaseDrawnPosition(element: Element, props: Record<string, unknown>): void;
11
- export declare function writeDrawnSize(style: CSSStyleDeclaration, size: {
12
- width: number;
13
- height: number;
14
- }): void;
15
4
  /** Applies each draft in order; one for an element this load no longer has is skipped. */
16
5
  export declare function drawDrafts(drafts: readonly EditingDraft[]): EditingDraftReply;
@@ -7,15 +7,7 @@ import { redrawGsapTimelineAt, seekGsapTimeline } from "./adapters/gsap.js";
7
7
  import { isStylableElement } from "./domRealm.js";
8
8
  import { elementForHandle } from "./editingHandles.js";
9
9
  import { revealClip } from "./clipReveal.js";
10
- export const SIZE_PROPERTIES = [
11
- "box-sizing",
12
- "width",
13
- "height",
14
- "min-width",
15
- "min-height",
16
- "max-width",
17
- "max-height",
18
- ];
10
+ import { computedTranslateAxes, movedTranslate, SIZE_PROPERTIES, writeDrawnSize } from "./drawnBox.js";
19
11
  const DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES];
20
12
  const frameGsap = () => window.gsap;
21
13
  /** The film's own timeline, as the unsealed recorder finds it: Studio's `__proxied` mark is no timeline. */
@@ -28,46 +20,6 @@ function rootTimeline() {
28
20
  const before = new WeakMap();
29
21
  const liveDrafts = new Map();
30
22
  let lastDraft = 0;
31
- /** "calc(50% + 2px) 4px" as its top-level parts. */
32
- function axes(value) {
33
- const parts = [];
34
- let depth = 0;
35
- let part = "";
36
- for (const char of value.trim()) {
37
- depth += char === "(" ? 1 : char === ")" ? -1 : 0;
38
- if (/\s/.test(char) && depth === 0) {
39
- if (part)
40
- parts.push(part);
41
- part = "";
42
- }
43
- else
44
- part += char;
45
- }
46
- if (part)
47
- parts.push(part);
48
- return parts;
49
- }
50
- /** The side a translate's % takes a share of: the box `transform-box` names. */
51
- function percentSide(computed, size) {
52
- const [a, b] = size === "width" ? ["left", "right"] : ["top", "bottom"];
53
- const n = (name) => Number.parseFloat(computed.getPropertyValue(name)) || 0;
54
- const pad = n(`padding-${a}`) + n(`padding-${b}`) + n(`border-${a}-width`) + n(`border-${b}-width`);
55
- const content = n(size) - (computed.getPropertyValue("box-sizing") === "border-box" ? pad : 0);
56
- const box = computed.getPropertyValue("transform-box");
57
- return box === "content-box" || box === "fill-box" ? content : content + pad;
58
- }
59
- /** Each % as the px it is now, so a resize drawn with it does not move the element again. */
60
- function percentAsPx(axis, side) {
61
- return axis.replace(/(-?\d*\.?\d+(?:e[-+]?\d+)?)%/gi, (_, n) => `${(Number(n) * side) / 100}px`);
62
- }
63
- export function computedTranslateAxes(element) {
64
- const computed = getComputedStyle(element);
65
- const translate = computed.getPropertyValue("translate");
66
- if (!translate || translate === "none")
67
- return [];
68
- const sides = [percentSide(computed, "width"), percentSide(computed, "height")];
69
- return axes(translate).map((axis, i) => (i < 2 ? percentAsPx(axis, sides[i]) : axis));
70
- }
71
23
  function beforeOf(element) {
72
24
  let saved = before.get(element);
73
25
  if (!saved) {
@@ -96,9 +48,6 @@ function restore(element, names) {
96
48
  element.style.removeProperty(name);
97
49
  }
98
50
  }
99
- export function movedTranslate([x = "0px", y = "0px", z], offset) {
100
- return `calc(${x} + ${offset.x}px) calc(${y} + ${offset.y}px)${z ? ` ${z}` : ""}`;
101
- }
102
51
  function writeDrawnTranslate(element, saved, value) {
103
52
  element.style.setProperty("translate", value);
104
53
  saved.drawnTranslate = element.style.getPropertyValue("translate");
@@ -142,15 +91,6 @@ function redrawTimelines() {
142
91
  seekGsapTimeline(timeline, time, true);
143
92
  }
144
93
  }
145
- export function writeDrawnSize(style, size) {
146
- style.setProperty("box-sizing", "border-box");
147
- style.setProperty("width", `${size.width}px`);
148
- style.setProperty("height", `${size.height}px`);
149
- for (const name of ["min-width", "min-height"])
150
- style.setProperty(name, "0px");
151
- for (const name of ["max-width", "max-height"])
152
- style.setProperty(name, "none");
153
- }
154
94
  function drawSize(element, size) {
155
95
  beforeOf(element);
156
96
  writeDrawnSize(element.style, size);
@@ -129,12 +129,12 @@ function closestWithAny(el, names) {
129
129
  return null;
130
130
  }
131
131
  export function readElementSource(el) {
132
- const [fileAttr, srcAttr] = SOURCE_HOST_ATTRS;
132
+ const [fileAttr] = SOURCE_HOST_ATTRS;
133
133
  const [idAttr, originalIdAttr] = COMPOSITION_ROOT_ATTRS;
134
- const host = closestWithAny(el, SOURCE_HOST_ATTRS);
134
+ const host = closestWithAny(el, [fileAttr]);
135
135
  const root = closestWithAny(el, [idAttr]);
136
136
  return {
137
- file: host?.getAttribute(fileAttr) ?? host?.getAttribute(srcAttr) ?? null,
137
+ file: host?.getAttribute(fileAttr) || null,
138
138
  compositionId: root?.getAttribute(idAttr) ?? null,
139
139
  originalCompositionId: root?.getAttribute(originalIdAttr) ?? null,
140
140
  };
@@ -1,4 +1,5 @@
1
1
  import type { EditingElementHandle } from "./editingElement.js";
2
+ import { type Grow } from "./drawnBox.js";
2
3
  import { type CssRotationStart } from "./editing/cssRotation.js";
3
4
  import { type EditingElementBox, type EditingElementGeometry } from "./editingGeometry.js";
4
5
  export interface EditingGestureStart extends EditingElementGeometry {
@@ -10,12 +11,7 @@ export interface EditingGestureStart extends EditingElementGeometry {
10
11
  d: number;
11
12
  } | null;
12
13
  /** Frame px its centre moves per px of drawn width, `a, b`, and height, `c, d`; null when it has no box. */
13
- grow: {
14
- a: number;
15
- b: number;
16
- c: number;
17
- d: number;
18
- } | null;
14
+ grow: Grow;
19
15
  /** Set when GSAP owns its position: x/y, whether a tween moves it. `gsapAt`: read when null; 0, 0 with no GSAP. */
20
16
  gsap: {
21
17
  x: number;
@@ -5,12 +5,10 @@
5
5
  * frame takes these here rather than off the elements.
6
6
  */
7
7
  import { isStylableElement } from "./domRealm.js";
8
- import { computedTranslateAxes, movedTranslate, SIZE_PROPERTIES, writeDrawnSize, } from "./editingDraft.js";
8
+ import { computedTranslateAxes, measureGrowResponse, MIN_PROBE_RESPONSE, movedTranslate, PROBE_PX, } from "./drawnBox.js";
9
9
  import { readCssRotationStart } from "./editing/cssRotation.js";
10
10
  import { boxOf, elementGeometry, readElementTransformSnapshot, snapCandidates, MAX_SNAP_TARGETS, } from "./editingGeometry.js";
11
11
  import { elementForHandle } from "./editingHandles.js";
12
- const PROBE_PX = 100;
13
- const MIN_PROBE_RESPONSE = 0.01;
14
12
  /**
15
13
  * Frame px the element's centre moves per px of translate a draft draws, one column per axis
16
14
  * (`a, b` for x, `c, d` for y): every transform above it applied. Null when it has no box or does
@@ -47,43 +45,6 @@ function measureMoveResponse(element) {
47
45
  style.removeProperty("translate");
48
46
  }
49
47
  }
50
- /** Where its centre goes as a draft draws its size, so a resize can pin it; its inline size put back. */
51
- function measureGrowResponse(element, layout) {
52
- const { style } = element;
53
- const kept = [...SIZE_PROPERTIES, "translate"].map((name) => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
54
- const translateAsTheResizeDraftDrawsIt = movedTranslate(computedTranslateAxes(element), {
55
- x: 0,
56
- y: 0,
57
- });
58
- const centre = (width, height) => {
59
- style.setProperty("translate", translateAsTheResizeDraftDrawsIt);
60
- writeDrawnSize(style, { width, height });
61
- const box = element.getBoundingClientRect();
62
- return box.width > 0 || box.height > 0
63
- ? { x: box.left + box.width / 2, y: box.top + box.height / 2 }
64
- : null;
65
- };
66
- try {
67
- if (layout.width < 1 || layout.height < 1)
68
- return null;
69
- const origin = centre(layout.width, layout.height);
70
- const wider = centre(layout.width + PROBE_PX, layout.height);
71
- const taller = centre(layout.width, layout.height + PROBE_PX);
72
- if (!origin || !wider || !taller)
73
- return null;
74
- const per = (p) => [(p.x - origin.x) / PROBE_PX, (p.y - origin.y) / PROBE_PX];
75
- const [[a, b], [c, d]] = [per(wider), per(taller)];
76
- return [a, b, c, d].every(Number.isFinite) ? { a: a, b: b, c: c, d: d } : null;
77
- }
78
- finally {
79
- for (const [name, value, priority] of kept) {
80
- if (value)
81
- style.setProperty(name, value, priority);
82
- else
83
- style.removeProperty(name);
84
- }
85
- }
86
- }
87
48
  // The channels Studio's move route and drag commit read as GSAP moving an element.
88
49
  const POSITION = ["x", "y", "xPercent", "yPercent", "left", "top", "translateX", "translateY"];
89
50
  export const MOVES = [...POSITION, "motionPath"];
@@ -13,6 +13,10 @@ export declare function elementHit(element: Element): EditingElementHit;
13
13
  export declare function elementsAtPoint(x: number, y: number): EditingElementHit[];
14
14
  export declare function describeHandles(requested: readonly EditingElementHandle[]): Array<EditingElementDescription | null>;
15
15
  export declare function ancestorHandles(requested: readonly EditingElementHandle[]): Array<EditingElementHandle[] | null>;
16
+ export declare function readEveryMatch<T>(selector: string, read: (element: Element) => T): {
17
+ matches: Array<T | null>;
18
+ truncated: boolean;
19
+ };
16
20
  export declare function queryElements(selector: string): {
17
21
  matches: EditingElementMatch[];
18
22
  truncated: boolean;
@@ -184,6 +184,15 @@ export function ancestorHandles(requested) {
184
184
  return chain;
185
185
  });
186
186
  }
187
+ export function readEveryMatch(selector, read) {
188
+ const matches = [];
189
+ for (const element of document.querySelectorAll(selector)) {
190
+ if (matches.length === MAX_QUERY_MATCHES)
191
+ return { matches, truncated: true };
192
+ matches.push(boundedSource(element) ? read(element) : null);
193
+ }
194
+ return { matches, truncated: false };
195
+ }
187
196
  export function queryElements(selector) {
188
197
  const matches = [];
189
198
  let truncated = false;
@@ -143,11 +143,16 @@ export interface EditingRequests {
143
143
  selector: string;
144
144
  } | {
145
145
  handle: EditingElementHandle;
146
+ } | {
147
+ selector: string;
148
+ every: true;
146
149
  }) & {
147
150
  properties: string[];
148
151
  };
149
152
  result: {
150
153
  styles: Record<string, string> | null;
154
+ matches?: Array<Record<string, string> | null>;
155
+ truncated?: boolean;
151
156
  };
152
157
  };
153
158
  "authored-styles": {
@@ -105,11 +105,15 @@ const isSelector = (value) => typeof value === "string" && value.length > 0 && v
105
105
  const isHandle = (value) => typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
106
106
  function styleTarget(params) {
107
107
  const keys = Object.keys(params).sort().join();
108
- const { selector, handle } = params;
108
+ const { selector, handle, every, properties } = params;
109
109
  if (keys === "properties,selector" && isSelector(selector))
110
110
  return { selector };
111
+ if (keys === "every,properties,selector" && every === true && isSelector(selector))
112
+ return everyMatchProperties(properties) ? { selector, every } : null;
111
113
  return keys === "handle,properties" && isHandle(handle) ? { handle } : null;
112
114
  }
115
+ const EVERY_MATCH_STYLES = ["display"];
116
+ const everyMatchProperties = (properties) => Array.isArray(properties) && properties.every((name) => EVERY_MATCH_STYLES.includes(name));
113
117
  function styleProperties(properties) {
114
118
  if (!Array.isArray(properties) || properties.length > MAX_STYLE_PROPERTIES)
115
119
  return null;
@@ -0,0 +1,113 @@
1
+ import type { RuntimeMediaClip } from "./types.js";
2
+ import { type HostSlot } from "../mediaTiming.js";
3
+ export { MEDIA_HARD_SYNC_SECONDS, MEDIA_SYNC_TOLERANCE_SECONDS } from "./mediaSteer.js";
4
+ export type { RuntimeMediaClip } from "./types.js";
5
+ export { readElementPlaybackRate, readElementRateSpec, resolveNaturalMediaTimelineDuration, } from "./playbackRate.js";
6
+ export declare function readElementPlaybackStart(el: Element): number;
7
+ export declare const HOLD_CAP_MS = 5000;
8
+ /**
9
+ * Resolve a media element's timeline window without conflating a video's
10
+ * authored display slot with the amount of source left to decode.
11
+ *
12
+ * An explicit video slot may outlive its source and hold the final frame; a loop fills its slot.
13
+ * Other audio remains source-bounded because it has no visual hold state.
14
+ */
15
+ export declare function resolveRuntimeMediaClipDuration(params: {
16
+ isVideo: boolean;
17
+ loops: boolean;
18
+ sourceDuration: number | null;
19
+ hostRemaining: number | null;
20
+ explicitDuration: number | null;
21
+ }): number | null;
22
+ export declare function refreshRuntimeMediaCache(params?: {
23
+ resolveStartSeconds?: (element: Element) => number;
24
+ resolveDurationSeconds?: (element: HTMLVideoElement | HTMLAudioElement) => number | null;
25
+ resolveHostSlots?: (element: HTMLVideoElement | HTMLAudioElement) => HostSlot[];
26
+ shouldIncludeElement?: (element: HTMLVideoElement | HTMLAudioElement) => boolean;
27
+ /**
28
+ * Build clips for exactly these elements instead of scanning the document for
29
+ * them. For a caller that already knows which media it needs this pass — the
30
+ * per-seek sync only touches the clips whose active state can change — and so
31
+ * should not pay to re-derive the window of every clip in the composition.
32
+ *
33
+ * Every field is still read FRESH from the element. This narrows which
34
+ * elements are visited, never how current the answer is: `el.duration` can be
35
+ * reset under the caller by an `el.load()` it did not make.
36
+ */
37
+ elements?: Array<HTMLVideoElement | HTMLAudioElement>;
38
+ }): {
39
+ timedMediaEls: Array<HTMLVideoElement | HTMLAudioElement>;
40
+ mediaClips: RuntimeMediaClip[];
41
+ videoClips: RuntimeMediaClip[];
42
+ maxMediaEnd: number;
43
+ };
44
+ export declare function primeMediaForLaterStarts(els: Iterable<HTMLMediaElement>): void;
45
+ export declare function isUnplayable(el: HTMLMediaElement): boolean;
46
+ /**
47
+ * Drop every per-source sync baseline tracked for `el` — offset drift
48
+ * samples, the seek-past-buffered-range retry latch, and the last
49
+ * runtime-applied volume — so the next `syncRuntimeMedia` tick treats it as
50
+ * a first tick (hard resync, fresh drift baseline) instead of comparing
51
+ * against state computed for a different file. Used both when a clip leaves
52
+ * its active window (below) and by the runtime's proxy-swap helper
53
+ * (mediaProxy.ts) right after an in-place `src` swap, which points the same
54
+ * element at a different file without ever leaving its active window.
55
+ */
56
+ export declare function evictMediaSyncState(el: HTMLMediaElement): void;
57
+ /** Whether the clip is inside its window at the playhead right now: the sync tick keeps its time while it is. */
58
+ export declare function isActiveAtPlayhead(el: HTMLMediaElement): boolean;
59
+ /** The source time the clip shows at the playhead, while it is inside its window. */
60
+ export declare function sourceTimeAtPlayhead(el: HTMLMediaElement): number | undefined;
61
+ /** Test-only seam: whether any per-source sync state is still tracked for `el`. */
62
+ export declare function hasMediaSyncStateForTest(el: HTMLMediaElement): boolean;
63
+ export declare const MEDIA_PRESEEK_SECONDS = 1.5;
64
+ export declare function mediaSourceTimeAt(clip: RuntimeMediaClip, timeSeconds: number): number;
65
+ export declare function resetVideoStartLatency(): void;
66
+ export declare function syncRuntimeMedia(params: {
67
+ clips: RuntimeMediaClip[];
68
+ timeSeconds: number;
69
+ playing: boolean;
70
+ playbackRate: number;
71
+ /** Force-mute every element (parent-frame proxy owns all audio). Asserted per
72
+ * tick so sub-composition media added mid-playback inherits the silence. */
73
+ outputMuted?: boolean;
74
+ /**
75
+ * User's explicit mute preference (set via `onSetMuted`). Symmetric to
76
+ * `outputMuted` — also asserted per tick — so a sub-composition that
77
+ * activates after the user mutes doesn't briefly play at author volume
78
+ * before the next bridge message lands.
79
+ */
80
+ userMuted?: boolean;
81
+ /**
82
+ * User's volume preference (0–1, set via `onSetVolume`). Multiplied with the
83
+ * per-clip author volume so `data-volume="0.5"` at user volume 0.8 yields 0.4.
84
+ */
85
+ userVolume?: number;
86
+ /**
87
+ * Invoked at most once when a media element's `play()` promise rejects with
88
+ * `NotAllowedError`. The caller is expected to latch and post a single
89
+ * outbound message; further invocations are suppressed by the caller.
90
+ */
91
+ onAutoplayBlocked?: () => void;
92
+ clockAhead?: (el: HTMLMediaElement) => number;
93
+ /** `clipGain` is `data-volume` for a routed clip, played ahead of its FX; 1 otherwise. */
94
+ onElementVolume?: (el: HTMLMediaElement, effectiveVolume: number, authorVolume: number, clipGain: number, unfadedVolume?: number) => void;
95
+ /** Is THIS element owned by the Web Audio transport? Owned → mute it (transport
96
+ * plays it); not owned → leave audible (HTMLMedia fallback). Per-element, not a
97
+ * global flag, so a not-yet-claimed track isn't muted by other tracks. */
98
+ isWebAudioOwned?: (el: HTMLMediaElement) => boolean;
99
+ /** Native media routed through WebAudio keeps its upstream element volume at
100
+ * unity; do not mistake that transport write for an authored volume edit. */
101
+ isWebAudioRouted?: (el: HTMLMediaElement) => boolean;
102
+ forceSync?: boolean;
103
+ keepLateMedia?: boolean;
104
+ /** False while the playhead is not moving (audio output has not started): a paused video waits for it. */
105
+ clockAdvancing?: boolean;
106
+ /** How far the next tick will move the playhead: an audio clip due within it starts now. */
107
+ cueAheadSeconds?: number;
108
+ /** Seeks a sounding element under a gain dip; false when it has no dip stage and the sync seeks it plainly. */
109
+ seekUnderDip?: (el: HTMLMediaElement, target: number) => boolean;
110
+ /** Lets a video clip that runs to the composition end hold its last frame at the terminal time.
111
+ * A thunk, because deriving the duration is only worth it for a clip past its own end. */
112
+ getCompositionDuration: () => number;
113
+ }): void;