@hyperframes/core 0.9.95 → 0.9.97

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 (51) hide show
  1. package/dist/audibleVideo.d.ts +10 -0
  2. package/dist/audibleVideo.js +37 -0
  3. package/dist/generated/runtime-inline.js +1 -1
  4. package/dist/hyperframe.runtime.iife.js +67 -67
  5. package/dist/index.d.ts +1 -1
  6. package/dist/runtime/adapters/seek-dispatch.d.ts +40 -0
  7. package/dist/runtime/adapters/seek-dispatch.js +164 -0
  8. package/dist/runtime/assetUrl.d.ts +6 -0
  9. package/dist/runtime/assetUrl.js +8 -0
  10. package/dist/runtime/audioFx.d.ts +77 -0
  11. package/dist/runtime/audioFx.js +277 -0
  12. package/dist/runtime/bridge.d.ts +6 -0
  13. package/dist/runtime/bridge.js +20 -0
  14. package/dist/runtime/decodesFirst.d.ts +4 -0
  15. package/dist/runtime/decodesFirst.js +14 -0
  16. package/dist/runtime/editing/gsapSnapshot.js +12 -3
  17. package/dist/runtime/editing/gsapSnapshotLimits.d.ts +5 -3
  18. package/dist/runtime/editing/gsapSnapshotLimits.js +5 -3
  19. package/dist/runtime/editing/textCaret.d.ts +14 -0
  20. package/dist/runtime/editing/textCaret.js +98 -0
  21. package/dist/runtime/editing/textEdit.d.ts +8 -0
  22. package/dist/runtime/editing/textEdit.js +67 -10
  23. package/dist/runtime/editingPort.d.ts +3 -2
  24. package/dist/runtime/editingPort.js +2 -1
  25. package/dist/runtime/media.d.ts +113 -0
  26. package/dist/runtime/media.js +820 -0
  27. package/dist/runtime/mediaLoadFailure.d.ts +8 -0
  28. package/dist/runtime/mediaLoadFailure.js +58 -0
  29. package/dist/runtime/mediaProxy.d.ts +91 -0
  30. package/dist/runtime/mediaProxy.js +803 -0
  31. package/dist/runtime/playbackHealth.d.ts +31 -0
  32. package/dist/runtime/playbackHealth.js +137 -0
  33. package/dist/runtime/preloadMedia.d.ts +16 -0
  34. package/dist/runtime/preloadMedia.js +266 -0
  35. package/dist/runtime/previewCopies.d.ts +13 -0
  36. package/dist/runtime/previewCopies.js +80 -0
  37. package/dist/runtime/proxyWait.d.ts +3 -0
  38. package/dist/runtime/proxyWait.js +51 -0
  39. package/dist/runtime/runtimeLoad.d.ts +3 -0
  40. package/dist/runtime/runtimeLoad.js +13 -0
  41. package/dist/runtime/state.d.ts +7 -0
  42. package/dist/runtime/state.js +3 -0
  43. package/dist/runtime/timedClipHide.d.ts +12 -0
  44. package/dist/runtime/timedClipHide.js +94 -0
  45. package/dist/runtime/types.d.ts +29 -18
  46. package/dist/runtime/webAudioTransport.d.ts +243 -0
  47. package/dist/runtime/webAudioTransport.js +1176 -0
  48. package/dist/safePath.js +20 -11
  49. package/dist/terminalText.d.ts +1 -0
  50. package/dist/terminalText.js +17 -0
  51. package/package.json +12 -4
@@ -2,7 +2,7 @@ import { handleFor } from "../editingHandles.js";
2
2
  import { MOVES, rendersTransform, withoutGsapTakeover } from "../editingGestureStart.js";
3
3
  import { isPlainRecord } from "../editingPort.js";
4
4
  import { isElementNode } from "../domRealm.js";
5
- import { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./gsapSnapshotLimits.js";
5
+ import { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, TARGET_FIELDS, TIMELINE_FIELDS, } from "./gsapSnapshotLimits.js";
6
6
  const VARS_SKIP = new Set([
7
7
  "ease",
8
8
  "easeEach",
@@ -42,6 +42,7 @@ export async function gsapSnapshot() {
42
42
  held.add(tween);
43
43
  if (timelines.length >= MAX_SNAPSHOT_TWEENS)
44
44
  throw new SnapshotBound("timelines");
45
+ reader.spend(TIMELINE_FIELDS);
45
46
  timelines.push({
46
47
  id: capped(id),
47
48
  time: typeof live.time === "function" ? finite(live.time()) : null,
@@ -69,6 +70,7 @@ class SnapshotReader {
69
70
  if (++this.tweens > MAX_SNAPSHOT_TWEENS)
70
71
  throw new SnapshotBound("tweens");
71
72
  const elements = (live.targets?.() ?? []).filter(isElementNode);
73
+ this.spend(elements.length);
72
74
  const vars = this.plain(live.vars, 0);
73
75
  const parsed = parsedChannels(live._pt);
74
76
  const parts = (live.timeline?.getChildren?.() ?? []).map((part) => this.tween(part));
@@ -83,8 +85,11 @@ class SnapshotReader {
83
85
  return [...this.channels].map(([element, channels]) => {
84
86
  if (channels.size > MAX_SNAPSHOT_CHANNELS)
85
87
  throw new SnapshotBound("channels");
88
+ this.spend(TARGET_FIELDS + channels.size);
86
89
  const values = {};
87
90
  const read = (channel) => {
91
+ if (isElementMethod(element, channel))
92
+ return;
88
93
  const value = Number(gsap?.getProperty?.(element, channel));
89
94
  if (Number.isFinite(value))
90
95
  values[channel] = value;
@@ -115,9 +120,12 @@ class SnapshotReader {
115
120
  for (const { p } of [...parsed, ...parts.flatMap((part) => part.parsed)])
116
121
  channels.add(p);
117
122
  }
123
+ spend(fields) {
124
+ if ((this.fields += fields) > MAX_SNAPSHOT_FIELDS)
125
+ throw new SnapshotBound("fields");
126
+ }
118
127
  plain(value, depth) {
119
- if (++this.fields > MAX_SNAPSHOT_FIELDS)
120
- throw new SnapshotBound("tween fields");
128
+ this.spend(1);
121
129
  if (Array.isArray(value))
122
130
  return this.list(value, depth);
123
131
  if (isLiteralRecord(value))
@@ -139,6 +147,7 @@ class SnapshotReader {
139
147
  return out;
140
148
  }
141
149
  }
150
+ const isElementMethod = (element, channel) => typeof Reflect.get(element, channel) === "function";
142
151
  function timing(live) {
143
152
  return {
144
153
  start: finite(live.startTime?.()),
@@ -1,6 +1,8 @@
1
- export declare const MAX_SNAPSHOT_TWEENS = 2048;
2
- export declare const MAX_SNAPSHOT_TARGETS = 512;
3
- export declare const MAX_SNAPSHOT_CHANNELS = 64;
4
1
  export declare const MAX_SNAPSHOT_FIELDS = 100000;
2
+ export declare const MAX_SNAPSHOT_TWEENS = 100000;
3
+ export declare const MAX_SNAPSHOT_TARGETS = 100000;
4
+ export declare const MAX_SNAPSHOT_CHANNELS = 64;
5
5
  export declare const MAX_SNAPSHOT_TEXT = 4096;
6
6
  export declare const MAX_VARS_DEPTH = 6;
7
+ export declare const TARGET_FIELDS = 3;
8
+ export declare const TIMELINE_FIELDS = 3;
@@ -1,6 +1,8 @@
1
- export const MAX_SNAPSHOT_TWEENS = 2_048;
2
- export const MAX_SNAPSHOT_TARGETS = 512;
3
- export const MAX_SNAPSHOT_CHANNELS = 64;
4
1
  export const MAX_SNAPSHOT_FIELDS = 100_000;
2
+ export const MAX_SNAPSHOT_TWEENS = MAX_SNAPSHOT_FIELDS;
3
+ export const MAX_SNAPSHOT_TARGETS = MAX_SNAPSHOT_FIELDS;
4
+ export const MAX_SNAPSHOT_CHANNELS = 64;
5
5
  export const MAX_SNAPSHOT_TEXT = 4_096;
6
6
  export const MAX_VARS_DEPTH = 6;
7
+ export const TARGET_FIELDS = 3;
8
+ export const TIMELINE_FIELDS = 3;
@@ -0,0 +1,14 @@
1
+ export type CaretSide = "before" | "after";
2
+ export type CaretBox = {
3
+ left: number;
4
+ top: number;
5
+ height: number;
6
+ };
7
+ /** The DOM has no side for a soft-wrap point (one line's end is the next one's start): the key that moved there says
8
+ * which, as CodeMirror and ProseMirror keep it. */
9
+ export declare const caretSideAfterKey: (key: string, side: CaretSide) => CaretSide;
10
+ export declare function caretBoxIn(element: HTMLElement, side: CaretSide): CaretBox | null;
11
+ export declare function caretColorOf(element: HTMLElement): string;
12
+ /** Puts the caret after the last character, with nothing selected: into the last text node rather than past the last
13
+ * child, since a caret at a node boundary types in the right place but stands somewhere else on screen. */
14
+ export declare function placeCaretAtEnd(element: HTMLElement): void;
@@ -0,0 +1,98 @@
1
+ const MODIFIERS = new Set(["Shift", "Control", "Alt", "Meta"]);
2
+ // Only End leaves Chrome's own caret at the earlier line's end; an arrow onto a wrap point lands on the next line.
3
+ const SIDE_OF_KEY = { End: "before" };
4
+ /** The DOM has no side for a soft-wrap point (one line's end is the next one's start): the key that moved there says
5
+ * which, as CodeMirror and ProseMirror keep it. */
6
+ export const caretSideAfterKey = (key, side) => MODIFIERS.has(key) ? side : (SIDE_OF_KEY[key] ?? "after");
7
+ export function caretBoxIn(element, side) {
8
+ const view = element.ownerDocument.defaultView;
9
+ const range = view ? caretRange(element, view) : null;
10
+ if (!view || !range)
11
+ return null;
12
+ return (side === "before" && endOfCharBefore(range)) || caretRect(range, element, view);
13
+ }
14
+ export function caretColorOf(element) {
15
+ const style = element.ownerDocument.defaultView?.getComputedStyle(element);
16
+ if (!style)
17
+ return "currentColor";
18
+ return style.caretColor && style.caretColor !== "auto" ? style.caretColor : style.color;
19
+ }
20
+ /** A caret between two nodes has no box, so it stands beside them; in an empty text, at its start, one line tall. */
21
+ function caretRect(range, element, view) {
22
+ const last = [...range.getClientRects()].reverse().find((rect) => rect.height > 0);
23
+ if (last)
24
+ return { left: last.left, top: last.top, height: last.height };
25
+ const beside = besideNode(range);
26
+ if (beside)
27
+ return beside;
28
+ const style = view.getComputedStyle(element);
29
+ const box = element.getBoundingClientRect();
30
+ const fontSize = Number.parseFloat(style.fontSize) || 16;
31
+ const line = Number.parseFloat(style.lineHeight) || fontSize * 1.2;
32
+ return {
33
+ left: box.left + (Number.parseFloat(style.paddingLeft) || 0),
34
+ top: box.top + (Number.parseFloat(style.paddingTop) || 0),
35
+ height: line,
36
+ };
37
+ }
38
+ function caretRange(element, view) {
39
+ const doc = element.ownerDocument;
40
+ const selection = view.getSelection();
41
+ if (!selection || selection.rangeCount === 0 || !selection.isCollapsed)
42
+ return null;
43
+ if (!doc.hasFocus() || !element.contains(doc.activeElement))
44
+ return null;
45
+ const range = selection.getRangeAt(0);
46
+ return element.contains(range.startContainer) ? range : null;
47
+ }
48
+ /** Where a caret that came from before a soft-wrap point stands: the right edge of the character before it. */
49
+ function endOfCharBefore({ startContainer: at, startOffset: offset }) {
50
+ if (at.nodeType !== Node.TEXT_NODE || offset === 0)
51
+ return null;
52
+ const char = at.ownerDocument.createRange();
53
+ // An emoji's second half alone has no box: take the whole pair.
54
+ const low = /[\uDC00-\uDFFF]/.test(at.data[offset - 1] ?? "");
55
+ char.setStart(at, offset - (low && offset > 1 ? 2 : 1));
56
+ char.setEnd(at, offset);
57
+ // A trailing space at a wrap has a box on each line; the earlier line's comes first.
58
+ const rect = [...char.getClientRects()].find((each) => each.height > 0);
59
+ return rect ? { left: rect.right, top: rect.top, height: rect.height } : null;
60
+ }
61
+ /** At an element boundary: the end of the node before, or the start of the node after (a line break's own line). */
62
+ function besideNode(range) {
63
+ const [before, after] = neighbours(range);
64
+ const node = before && before.nodeName !== "BR" ? before : (after ?? before);
65
+ if (!node)
66
+ return null;
67
+ const around = range.cloneRange();
68
+ around.selectNode(node);
69
+ const rects = [...around.getClientRects()].filter((rect) => rect.height > 0);
70
+ const end = node === before;
71
+ const rect = end ? rects.at(-1) : rects[0];
72
+ return rect ? { left: end ? rect.right : rect.left, top: rect.top, height: rect.height } : null;
73
+ }
74
+ function neighbours({ startContainer: at, startOffset: offset }) {
75
+ return at.nodeType === Node.TEXT_NODE
76
+ ? [at.previousSibling, at.nextSibling]
77
+ : [at.childNodes[offset - 1] ?? null, at.childNodes[offset] ?? null];
78
+ }
79
+ /** Puts the caret after the last character, with nothing selected: into the last text node rather than past the last
80
+ * child, since a caret at a node boundary types in the right place but stands somewhere else on screen. */
81
+ export function placeCaretAtEnd(element) {
82
+ const doc = element.ownerDocument;
83
+ const selection = doc.defaultView?.getSelection();
84
+ if (!selection)
85
+ return;
86
+ const range = doc.createRange();
87
+ const last = element.lastChild;
88
+ if (last && last.nodeType === Node.TEXT_NODE) {
89
+ range.setStart(last, last.textContent?.length ?? 0);
90
+ range.collapse(true);
91
+ }
92
+ else {
93
+ range.selectNodeContents(element);
94
+ range.collapse(false);
95
+ }
96
+ selection.removeAllRanges();
97
+ selection.addRange(range);
98
+ }
@@ -41,9 +41,17 @@ export type TextEditSelection = {
41
41
  colours: string[];
42
42
  painted: string | null;
43
43
  };
44
+ export type TextEditCaret = {
45
+ left: number;
46
+ top: number;
47
+ height: number;
48
+ color: string;
49
+ viewportWidth: number;
50
+ };
44
51
  export type TextEditSelectionEvent = {
45
52
  handle: EditingElementHandle;
46
53
  selection: TextEditSelection | null;
54
+ caret: TextEditCaret | null;
47
55
  };
48
56
  export declare function parseTextEdit(params: unknown): TextEditParams | null;
49
57
  export declare function textEditSelectionEvent(data: unknown, version: number): TextEditSelectionEvent | null;
@@ -6,6 +6,7 @@ import { isStylableElement } from "../domRealm.js";
6
6
  import { sanitizeRichTextChildren } from "../../utils/richTextSanitize.js";
7
7
  import { openTextEdits, isTextMarkup, MAX_EDIT_VALUE } from "./editElement.js";
8
8
  import { isEditableText } from "./textMarkup.js";
9
+ import { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, } from "./textCaret.js";
9
10
  import { applyInlineStyle, INLINE_STYLE_PROPERTIES, readFirstPaintedElement, readInlineStyle, readInlineStyleSpread, } from "../../utils/inlineTextStyleRead.js";
10
11
  const EDITING_OUTLINE = "2px solid #3CE6AC";
11
12
  const MAX_STYLE_VALUE = 256;
@@ -57,13 +58,24 @@ function isSelection(value) {
57
58
  isColours(colours) &&
58
59
  (painted === null || isShortText(painted)));
59
60
  }
61
+ function isCaret(value) {
62
+ if (!isRecord(value) || !keysAre(value, "color,height,left,top,viewportWidth"))
63
+ return false;
64
+ const { left, top, height, color, viewportWidth } = value;
65
+ return ([left, top, height, viewportWidth].every(isFiniteNumber) &&
66
+ height >= 0 &&
67
+ viewportWidth > 0 &&
68
+ isShortText(color));
69
+ }
60
70
  export function textEditSelectionEvent(data, version) {
61
- if (!isRecord(data) || !keysAre(data, "event,handle,selection,v"))
71
+ if (!isRecord(data) || !keysAre(data, "caret,event,handle,selection,v"))
62
72
  return null;
63
73
  if (data.v !== version || data.event !== "text-edit-selection" || !isHandle(data.handle))
64
74
  return null;
65
- const { handle, selection } = data;
66
- return selection === null || isSelection(selection) ? { handle, selection } : null;
75
+ const { handle, selection, caret } = data;
76
+ if (!(selection === null || isSelection(selection)))
77
+ return null;
78
+ return caret === null || isCaret(caret) ? { handle, selection, caret } : null;
67
79
  }
68
80
  const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
69
81
  const isTextMarkupOrNull = (value) => value === null || (typeof value === "string" && isTextMarkup(value));
@@ -140,6 +152,7 @@ function close(keep) {
140
152
  element.removeAttribute("contenteditable");
141
153
  element.style.outline = open.outline;
142
154
  element.style.outlineOffset = open.outlineOffset;
155
+ element.style.caretColor = open.caretColor;
143
156
  if (element.isConnected) {
144
157
  clearSelectionWithin(element);
145
158
  element.blur();
@@ -167,11 +180,9 @@ function placeCaret(element, at) {
167
180
  const selection = doc.defaultView?.getSelection();
168
181
  if (!selection)
169
182
  return;
170
- let range = at ? caretRangeAt(doc, at) : null;
171
- if (!range || !element.contains(range.startContainer)) {
172
- range = doc.createRange();
173
- range.selectNodeContents(element);
174
- }
183
+ const range = at ? caretRangeAt(doc, at) : null;
184
+ if (!range || !element.contains(range.startContainer))
185
+ return placeCaretAtEnd(element);
175
186
  range.collapse(false);
176
187
  selection.removeAllRanges();
177
188
  selection.addRange(range);
@@ -226,6 +237,42 @@ function listen(element, endInFrame, report) {
226
237
  removed.disconnect();
227
238
  };
228
239
  }
240
+ function followCaret(element, open) {
241
+ const view = element.ownerDocument.defaultView;
242
+ const onKey = ({ key }) => {
243
+ open.caret.side = caretSideAfterKey(key, open.caret.side);
244
+ };
245
+ const onPress = () => {
246
+ open.caret.side = "after";
247
+ };
248
+ const composing = (on) => () => {
249
+ open.caret.composing = on;
250
+ open.report();
251
+ };
252
+ const begin = composing(true);
253
+ const finish = composing(false);
254
+ element.addEventListener("keydown", onKey);
255
+ element.addEventListener("pointerdown", onPress);
256
+ element.addEventListener("input", open.report);
257
+ element.addEventListener("compositionstart", begin);
258
+ element.addEventListener("compositionend", finish);
259
+ view?.addEventListener("resize", open.report);
260
+ view?.addEventListener("scroll", open.report, true);
261
+ return () => {
262
+ element.removeEventListener("keydown", onKey);
263
+ element.removeEventListener("pointerdown", onPress);
264
+ element.removeEventListener("input", open.report);
265
+ element.removeEventListener("compositionstart", begin);
266
+ element.removeEventListener("compositionend", finish);
267
+ view?.removeEventListener("resize", open.report);
268
+ view?.removeEventListener("scroll", open.report, true);
269
+ };
270
+ }
271
+ function caretOf(open) {
272
+ const box = open.caret.composing ? null : caretBoxIn(open.element, open.caret.side);
273
+ const viewportWidth = open.element.ownerDocument.defaultView?.innerWidth || 1;
274
+ return box && { ...box, color: open.caret.color, viewportWidth };
275
+ }
229
276
  function start(handle, caret, port, version) {
230
277
  close(false);
231
278
  const element = elementForHandle(handle);
@@ -239,12 +286,15 @@ function start(handle, caret, port, version) {
239
286
  original: editable.innerHTML,
240
287
  outline: editable.style.outline,
241
288
  outlineOffset: editable.style.outlineOffset,
289
+ caretColor: editable.style.caretColor,
290
+ caret: { color: caretColorOf(editable), side: "after", composing: false },
242
291
  stop: () => { },
243
292
  report: () => {
244
293
  if (session !== open)
245
294
  return;
246
295
  const selection = selectionIn(editable);
247
- port.postMessage({ v: version, event: "text-edit-selection", handle, selection });
296
+ const caret = caretOf(open);
297
+ port.postMessage({ v: version, event: "text-edit-selection", handle, selection, caret });
248
298
  },
249
299
  };
250
300
  const endInFrame = () => {
@@ -254,12 +304,19 @@ function start(handle, caret, port, version) {
254
304
  if (ended)
255
305
  port.postMessage({ v: version, event: "text-edit-ended", handle, ...ended });
256
306
  };
257
- open.stop = listen(editable, endInFrame, open.report);
307
+ const stopListening = listen(editable, endInFrame, open.report);
308
+ const stopFollowing = followCaret(editable, open);
309
+ open.stop = () => {
310
+ stopListening();
311
+ stopFollowing();
312
+ };
258
313
  session = open;
259
314
  openTextEdits.add(editable);
260
315
  editable.style.outline = EDITING_OUTLINE;
261
316
  editable.style.outlineOffset = "2px";
262
317
  editable.setAttribute("contenteditable", "true");
318
+ // Studio draws the caret at screen size: the browser's own would shrink below a pixel in the scaled preview.
319
+ editable.style.caretColor = "transparent";
263
320
  editable.focus({ preventScroll: true });
264
321
  placeCaret(editable, caret);
265
322
  return { applied: true, html: null, previous: open.original };
@@ -38,7 +38,7 @@ export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEdit
38
38
  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
39
  export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
40
40
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
41
- export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
41
+ 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
42
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
43
43
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
44
44
  export declare const EDITING_PROTOCOL_VERSION: 1;
@@ -518,5 +518,6 @@ export declare function createEditingPortClient(options: {
518
518
  host?: Window;
519
519
  }): EditingPortClient;
520
520
  export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
521
- export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditResult, type TextEditSelection, type TextEditSelectionEvent, } from "./editing/textEdit.js";
521
+ export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditCaret, type TextEditResult, type TextEditSelection, type TextEditSelectionEvent, } from "./editing/textEdit.js";
522
+ export { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, type CaretBox, type CaretSide, } from "./editing/textCaret.js";
522
523
  export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, type PausedFrameAsk, type PausedFrameAskMessage, type PausedFrameImage, type PausedFrameReply, } from "./editing/pausedFrames.js";
@@ -21,7 +21,7 @@ import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./ed
21
21
  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
22
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
23
23
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
24
- export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
24
+ 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
25
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
26
26
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
27
27
  export const EDITING_PROTOCOL_VERSION = 1;
@@ -545,4 +545,5 @@ export function createEditingPortClient(options) {
545
545
  }
546
546
  export { elementHome, transformWDivisor } from "./editing/motionPathHome.js";
547
547
  export { caretRangeAt, takePlainTextOnly, textEditResult, } from "./editing/textEdit.js";
548
+ export { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, } from "./editing/textCaret.js";
548
549
  export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, } from "./editing/pausedFrames.js";
@@ -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;