@hyperframes/core 0.9.92 → 0.9.94

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 (34) hide show
  1. package/dist/clipFacts.d.ts +5 -0
  2. package/dist/clipFacts.js +21 -6
  3. package/dist/colorGrading.d.ts +1 -0
  4. package/dist/colorGrading.js +3 -0
  5. package/dist/compiler/htmlDocument.js +1 -1
  6. package/dist/compiler/htmlParityContract.js +1 -1
  7. package/dist/compiler/standaloneEntry.js +1 -1
  8. package/dist/figma/sanitizeSvg.js +1 -1
  9. package/dist/fonts/pageTree.d.ts +1 -1
  10. package/dist/fonts/pageTree.js +1 -1
  11. package/dist/generated/runtime-inline.js +1 -1
  12. package/dist/generators/richTextHtml.js +1 -1
  13. package/dist/hyperframe.runtime.iife.js +66 -66
  14. package/dist/mediaGradeAnalyzer.js +3 -3
  15. package/dist/runtime/clipNodes.d.ts +1 -0
  16. package/dist/runtime/clipNodes.js +1 -0
  17. package/dist/runtime/editing/gsapSnapshot.d.ts +1 -0
  18. package/dist/runtime/editing/gsapSnapshot.js +7 -0
  19. package/dist/runtime/editing/textEdit.d.ts +23 -0
  20. package/dist/runtime/editing/textEdit.js +88 -3
  21. package/dist/runtime/editingDraft.js +31 -9
  22. package/dist/runtime/editingElement.d.ts +2 -0
  23. package/dist/runtime/editingElement.js +11 -1
  24. package/dist/runtime/editingGestureStart.d.ts +5 -1
  25. package/dist/runtime/editingGestureStart.js +4 -0
  26. package/dist/runtime/editingPort.d.ts +13 -4
  27. package/dist/runtime/editingPort.js +14 -3
  28. package/dist/runtime/timeline.js +14 -1
  29. package/dist/runtime/types.d.ts +1 -0
  30. package/dist/utils/inlineTextStyleRange.d.ts +33 -0
  31. package/dist/utils/inlineTextStyleRange.js +503 -0
  32. package/dist/utils/inlineTextStyleRead.d.ts +20 -0
  33. package/dist/utils/inlineTextStyleRead.js +72 -0
  34. package/package.json +8 -4
@@ -1,6 +1,6 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { basename, extname } from "node:path";
3
- import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
3
+ import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
4
4
  const IMAGE_EXTENSIONS = new Set([
5
5
  ".jpg",
6
6
  ".jpeg",
@@ -45,7 +45,7 @@ function probeMedia(mediaPath, ffprobePath) {
45
45
  const raw = execFileSync(ffprobePath, [
46
46
  "-v",
47
47
  "error",
48
- ...mediaInputFormatArgs(ffprobePath, mediaPath),
48
+ ...mediaInputArgs(ffprobePath, mediaPath),
49
49
  "-select_streams",
50
50
  "v:0",
51
51
  "-show_entries",
@@ -226,7 +226,7 @@ function readSignalStats(ffmpegPath, mediaPath, seekSeconds, frames) {
226
226
  "-nostdin",
227
227
  "-v",
228
228
  "error",
229
- ...mediaInputFormatArgs(ffmpegPath, mediaPath),
229
+ ...mediaInputArgs(ffmpegPath, mediaPath),
230
230
  ...keyframeSeek,
231
231
  "-i",
232
232
  mediaPath,
@@ -0,0 +1 @@
1
+ export declare const CLIP_NODES = "[data-start], [data-track-index], [data-composition-id], video, audio, img";
@@ -0,0 +1 @@
1
+ export const CLIP_NODES = "[data-start], [data-track-index], [data-composition-id], video, audio, img";
@@ -37,6 +37,7 @@ export interface GsapSnapshot {
37
37
  time: number | null;
38
38
  defaultEase: string | null;
39
39
  timelines: GsapSnapshotTimeline[];
40
+ globalTweens: GsapSnapshotTween[];
40
41
  targets: GsapSnapshotTarget[];
41
42
  }
42
43
  /** Every tween on the frame's timelines, after any seek in flight has painted. Throws past a bound. */
@@ -33,10 +33,13 @@ export async function gsapSnapshot() {
33
33
  const gsap = frame.gsap;
34
34
  const reader = new SnapshotReader();
35
35
  const timelines = [];
36
+ const held = new Set();
36
37
  for (const [id, live] of Object.entries(frame.__timelines ?? {})) {
37
38
  if (typeof live?.getChildren !== "function")
38
39
  continue;
39
40
  const tweens = live.getChildren(true).filter((child) => typeof child.targets === "function");
41
+ for (const tween of tweens)
42
+ held.add(tween);
40
43
  if (timelines.length >= MAX_SNAPSHOT_TWEENS)
41
44
  throw new SnapshotBound("timelines");
42
45
  timelines.push({
@@ -46,11 +49,15 @@ export async function gsapSnapshot() {
46
49
  tweens: tweens.map((tween) => reader.tween(tween)),
47
50
  });
48
51
  }
52
+ const globalTweens = (gsap?.globalTimeline?.getChildren?.(true, true, false) ?? [])
53
+ .filter((child) => typeof child.targets === "function" && !held.has(child))
54
+ .map((tween) => reader.tween(tween));
49
55
  const time = frame.__player?.getTime?.();
50
56
  return {
51
57
  time: typeof time === "number" && Number.isFinite(time) ? time : null,
52
58
  defaultEase: text(gsap?.defaults?.().ease),
53
59
  timelines,
60
+ globalTweens,
54
61
  targets: reader.targets(gsap),
55
62
  };
56
63
  }
@@ -3,6 +3,7 @@ type Point = {
3
3
  x: number;
4
4
  y: number;
5
5
  };
6
+ type Style = Record<string, string | null>;
6
7
  export type TextEditParams = {
7
8
  handle: EditingElementHandle;
8
9
  action: "start";
@@ -11,6 +12,10 @@ export type TextEditParams = {
11
12
  handle: EditingElementHandle;
12
13
  action: "end";
13
14
  keep: boolean;
15
+ } | {
16
+ handle: EditingElementHandle;
17
+ action: "style";
18
+ style: Style;
14
19
  };
15
20
  export type TextEditResult = {
16
21
  applied: boolean;
@@ -23,7 +28,25 @@ export type TextEditEndedEvent = {
23
28
  html: string | null;
24
29
  previous: string;
25
30
  };
31
+ /** The selection in an open session, posted on its port as it changes; null when nothing is selected in it. */
32
+ export type TextEditSelection = {
33
+ rect: {
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ };
39
+ viewportWidth: number;
40
+ styles: Record<string, string>;
41
+ colours: string[];
42
+ painted: string | null;
43
+ };
44
+ export type TextEditSelectionEvent = {
45
+ handle: EditingElementHandle;
46
+ selection: TextEditSelection | null;
47
+ };
26
48
  export declare function parseTextEdit(params: unknown): TextEditParams | null;
49
+ export declare function textEditSelectionEvent(data: unknown, version: number): TextEditSelectionEvent | null;
27
50
  export declare function textEditEndedEvent(data: unknown, version: number): TextEditEndedEvent | null;
28
51
  export declare function textEditResult(reply: unknown): TextEditResult | null;
29
52
  /** Ends an open session with its original markup back; the agent's dispose and a page hide call it. */
@@ -6,7 +6,16 @@ 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 { applyInlineStyle, INLINE_STYLE_PROPERTIES, readFirstPaintedElement, readInlineStyle, readInlineStyleSpread, } from "../../utils/inlineTextStyleRead.js";
9
10
  const EDITING_OUTLINE = "2px solid #3CE6AC";
11
+ const MAX_STYLE_VALUE = 256;
12
+ const MAX_COLOURS = 16;
13
+ const STYLE_VALUES = {
14
+ color: (value) => value.length <= MAX_STYLE_VALUE,
15
+ "font-weight": (value) => value === "700",
16
+ "font-style": (value) => value === "italic",
17
+ "text-decoration-line": (value) => value === "underline",
18
+ };
10
19
  const isRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
11
20
  const keysAre = (value, keys) => Object.keys(value).sort().join() === keys;
12
21
  const isHandle = (value) => typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
@@ -21,8 +30,41 @@ export function parseTextEdit(params) {
21
30
  }
22
31
  if (action === "end" && keysAre(params, "action,handle,keep") && typeof params.keep === "boolean")
23
32
  return { handle, action, keep: params.keep };
33
+ if (action === "style" && keysAre(params, "action,handle,style") && isStyle(params.style))
34
+ return { handle, action, style: params.style };
24
35
  return null;
25
36
  }
37
+ const isStyle = (value) => isRecord(value) &&
38
+ Object.keys(value).length > 0 &&
39
+ Object.entries(value).every(([key, set]) => Object.hasOwn(STYLE_VALUES, key) &&
40
+ (set === null || (typeof set === "string" && STYLE_VALUES[key](set))));
41
+ const isShortText = (value) => typeof value === "string" && value.length <= MAX_STYLE_VALUE;
42
+ const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
43
+ const isRect = (value) => isRecord(value) &&
44
+ keysAre(value, "height,width,x,y") &&
45
+ Object.values(value).every(isFiniteNumber);
46
+ const isShownStyles = (value) => isRecord(value) &&
47
+ Object.entries(value).every(([key, set]) => Object.hasOwn(STYLE_VALUES, key) && isShortText(set));
48
+ const isColours = (value) => Array.isArray(value) && value.length <= MAX_COLOURS && value.every(isShortText);
49
+ function isSelection(value) {
50
+ if (!isRecord(value) || !keysAre(value, "colours,painted,rect,styles,viewportWidth"))
51
+ return false;
52
+ const { rect, viewportWidth, styles, colours, painted } = value;
53
+ const shown = isFiniteNumber(viewportWidth) && viewportWidth > 0;
54
+ return (shown &&
55
+ isRect(rect) &&
56
+ isShownStyles(styles) &&
57
+ isColours(colours) &&
58
+ (painted === null || isShortText(painted)));
59
+ }
60
+ export function textEditSelectionEvent(data, version) {
61
+ if (!isRecord(data) || !keysAre(data, "event,handle,selection,v"))
62
+ return null;
63
+ if (data.v !== version || data.event !== "text-edit-selection" || !isHandle(data.handle))
64
+ return null;
65
+ const { handle, selection } = data;
66
+ return selection === null || isSelection(selection) ? { handle, selection } : null;
67
+ }
26
68
  const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
27
69
  const isTextMarkupOrNull = (value) => value === null || (typeof value === "string" && isTextMarkup(value));
28
70
  export function textEditEndedEvent(data, version) {
@@ -55,6 +97,30 @@ function clearSelectionWithin(element) {
55
97
  if (element.contains(range.startContainer) || element.contains(range.endContainer))
56
98
  selection.removeAllRanges();
57
99
  }
100
+ function selectedRange(element) {
101
+ const selection = element.ownerDocument.defaultView?.getSelection();
102
+ if (!selection || selection.rangeCount === 0 || selection.isCollapsed)
103
+ return null;
104
+ const range = selection.getRangeAt(0);
105
+ return element.contains(range.commonAncestorContainer) ? range : null;
106
+ }
107
+ const shortStyles = (styles) => Object.fromEntries(Object.entries(styles).filter(([, value]) => isShortText(value)));
108
+ function selectionIn(element) {
109
+ const range = selectedRange(element);
110
+ const view = element.ownerDocument.defaultView;
111
+ if (!range || !view)
112
+ return null;
113
+ const { left: x, top: y, width, height } = range.getBoundingClientRect();
114
+ const painted = readFirstPaintedElement(range, "color");
115
+ const paintedColour = painted ? view.getComputedStyle(painted).color : null;
116
+ return {
117
+ rect: { x, y, width, height },
118
+ viewportWidth: view.innerWidth || 1,
119
+ styles: shortStyles(readInlineStyle(range, INLINE_STYLE_PROPERTIES)),
120
+ colours: readInlineStyleSpread(range, "color").filter(isShortText).slice(0, MAX_COLOURS),
121
+ painted: isShortText(paintedColour) ? paintedColour : null,
122
+ };
123
+ }
58
124
  function keptMarkup(element) {
59
125
  sanitizeRichTextChildren(element);
60
126
  const html = element.innerHTML;
@@ -133,7 +199,7 @@ export function takePlainTextOnly(element) {
133
199
  element.removeEventListener("drop", onDrop);
134
200
  };
135
201
  }
136
- function listen(element, endInFrame) {
202
+ function listen(element, endInFrame, report) {
137
203
  const onKeyDown = (event) => {
138
204
  if ((event.key !== "Enter" || event.shiftKey) && event.key !== "Escape")
139
205
  return;
@@ -149,8 +215,10 @@ function listen(element, endInFrame) {
149
215
  const releasePlainText = takePlainTextOnly(element);
150
216
  element.addEventListener("keydown", onKeyDown);
151
217
  element.addEventListener("blur", endInFrame);
218
+ element.ownerDocument.addEventListener("selectionchange", report);
152
219
  view?.addEventListener("pagehide", endTextEdit);
153
220
  return () => {
221
+ element.ownerDocument.removeEventListener("selectionchange", report);
154
222
  releasePlainText();
155
223
  element.removeEventListener("keydown", onKeyDown);
156
224
  element.removeEventListener("blur", endInFrame);
@@ -172,14 +240,21 @@ function start(handle, caret, port, version) {
172
240
  outline: editable.style.outline,
173
241
  outlineOffset: editable.style.outlineOffset,
174
242
  stop: () => { },
243
+ report: () => {
244
+ if (session !== open)
245
+ return;
246
+ const selection = selectionIn(editable);
247
+ port.postMessage({ v: version, event: "text-edit-selection", handle, selection });
248
+ },
175
249
  };
176
- open.stop = listen(editable, () => {
250
+ const endInFrame = () => {
177
251
  if (session !== open)
178
252
  return;
179
253
  const ended = close(true);
180
254
  if (ended)
181
255
  port.postMessage({ v: version, event: "text-edit-ended", handle, ...ended });
182
- });
256
+ };
257
+ open.stop = listen(editable, endInFrame, open.report);
183
258
  session = open;
184
259
  openTextEdits.add(editable);
185
260
  editable.style.outline = EDITING_OUTLINE;
@@ -194,6 +269,16 @@ export function textEdit(params, port, version) {
194
269
  return start(params.handle, params.caret, port, version);
195
270
  if (session?.handle !== params.handle || session.port !== port)
196
271
  return NOTHING;
272
+ if (params.action === "style")
273
+ return styleSelection(session, params.style);
197
274
  const ended = close(params.keep);
198
275
  return ended ? { applied: true, ...ended } : NOTHING;
199
276
  }
277
+ function styleSelection(open, style) {
278
+ const range = selectedRange(open.element);
279
+ if (!range)
280
+ return NOTHING;
281
+ applyInlineStyle(range, style);
282
+ open.report();
283
+ return { applied: true, html: null, previous: null };
284
+ }
@@ -99,23 +99,33 @@ function restore(element, names) {
99
99
  export function movedTranslate([x = "0px", y = "0px", z], offset) {
100
100
  return `calc(${x} + ${offset.x}px) calc(${y} + ${offset.y}px)${z ? ` ${z}` : ""}`;
101
101
  }
102
+ function writeDrawnTranslate(element, saved, value) {
103
+ element.style.setProperty("translate", value);
104
+ saved.drawnTranslate = element.style.getPropertyValue("translate");
105
+ }
102
106
  function drawTranslate(element, offset) {
103
107
  const saved = beforeOf(element);
104
108
  if (offset.route !== "gsap")
105
- return void element.style.setProperty("translate", movedTranslate(saved.translate, offset));
109
+ return writeDrawnTranslate(element, saved, movedTranslate(saved.translate, offset));
106
110
  const gsap = frameGsap();
107
111
  const read = (axis) => Number(gsap?.getProperty?.(element, axis)) || 0;
108
112
  saved.gsapPosition ??= { x: read("x"), y: read("y") };
109
- element.style.setProperty("translate", "none");
113
+ writeDrawnTranslate(element, saved, "none");
110
114
  gsap?.set?.(element, { x: offset.x, y: offset.y });
111
115
  }
112
116
  export function rebaseDrawnPosition(element, props) {
113
- const position = before.get(element)?.gsapPosition;
114
- for (const axis of ["x", "y"]) {
115
- const value = props[axis];
116
- if (position && typeof value === "number" && Number.isFinite(value))
117
- position[axis] = value;
118
- }
117
+ const saved = before.get(element);
118
+ const moved = ["x", "y"].filter((axis) => Number.isFinite(props[axis]));
119
+ if (!moved.length || !isStylableElement(element))
120
+ return;
121
+ if (!saved)
122
+ element.style.setProperty("translate", "none");
123
+ for (const entry of saved?.inline ?? [])
124
+ if (entry[0] === "translate")
125
+ [entry[1], entry[2]] = ["none", ""];
126
+ for (const axis of moved)
127
+ if (saved?.gsapPosition)
128
+ saved.gsapPosition[axis] = props[axis];
119
129
  }
120
130
  function restoreGsapPosition(element) {
121
131
  const { gsapPosition } = before.get(element) ?? {};
@@ -186,6 +196,18 @@ function clearProps(element, saved) {
186
196
  redrawGsapTimelineAt(timeline, timeline.time());
187
197
  putLiveDraftsBack();
188
198
  }
199
+ function settleTranslateUnderGsap(element) {
200
+ restore(element, ["translate"]);
201
+ const under = getComputedStyle(element).getPropertyValue("translate");
202
+ if (under && under !== "none")
203
+ element.style.setProperty("translate", "none");
204
+ }
205
+ function dropDrawnTranslate(element, saved) {
206
+ if (saved.gsapPosition !== undefined)
207
+ return settleTranslateUnderGsap(element);
208
+ if (element.style.getPropertyValue("translate") === saved.drawnTranslate)
209
+ restore(element, ["translate"]);
210
+ }
189
211
  function end(element, ending) {
190
212
  const saved = before.get(element);
191
213
  if (!saved || ("draft" in ending && ending.draft !== saved.draft))
@@ -199,7 +221,7 @@ function end(element, ending) {
199
221
  restoreGsapRotation(element);
200
222
  }
201
223
  if (ending.end === "keep-size")
202
- restore(element, ["translate"]);
224
+ dropDrawnTranslate(element, saved);
203
225
  before.delete(element);
204
226
  return ending.end === "restore";
205
227
  }
@@ -82,5 +82,7 @@ export declare function readTextLayer(el: Element): TextLayerRead | null;
82
82
  export declare function readSentTextLayer(el: Element): TextLayerRead | null;
83
83
  export declare function escapeCssString(value: string): string;
84
84
  export declare function buildStableSelector(el: Element): string | undefined;
85
+ /** Is `selector` one `buildStableSelector` makes for an element whose id is `id`. */
86
+ export declare function isStableSelector(selector: string, id: string | null): boolean;
85
87
  export declare function getPreferredClassSelector(el: Element): string | undefined;
86
88
  export declare function readElementSource(el: Element): EditingElementSource;
@@ -88,7 +88,7 @@ export function escapeCssString(value) {
88
88
  .replace(/\f/g, "\\c ");
89
89
  }
90
90
  export function buildStableSelector(el) {
91
- if (el.id)
91
+ if (el.id && typeof el.id === "string")
92
92
  return `#${escapeCssIdentifier(el.id)}`;
93
93
  const compositionId = el.getAttribute("data-composition-id");
94
94
  if (compositionId)
@@ -101,6 +101,16 @@ export function buildStableSelector(el) {
101
101
  return `[data-hf-group="${escapeCssString(group)}"]`;
102
102
  return getPreferredClassSelector(el);
103
103
  }
104
+ const ESCAPED_IDENTIFIER = String.raw `(?:[A-Za-z0-9_-]|[^\x00-\x7f]|\\[0-9a-f]{1,6} |\\[^0-9a-f\n\r\f])+`;
105
+ const ESCAPED_STRING = String.raw `"(?:[^"\\\n\r\f]|\\\\|\\"|\\a |\\d |\\c )+"`;
106
+ const CLASS_SELECTOR = new RegExp(`^\\.(?!-?[0-9]|-$)${ESCAPED_IDENTIFIER}$`);
107
+ const ATTRIBUTE_SELECTOR = new RegExp(`^\\[data-(?:composition-id|hf-group)=${ESCAPED_STRING}\\]$`);
108
+ /** Is `selector` one `buildStableSelector` makes for an element whose id is `id`. */
109
+ export function isStableSelector(selector, id) {
110
+ if (selector.startsWith("#"))
111
+ return Boolean(id) && selector === `#${escapeCssIdentifier(id ?? "")}`;
112
+ return !id && (CLASS_SELECTOR.test(selector) || ATTRIBUTE_SELECTOR.test(selector));
113
+ }
104
114
  export function getPreferredClassSelector(el) {
105
115
  const classes = Array.from(el.classList)
106
116
  .map((value) => value.trim())
@@ -16,13 +16,17 @@ export interface EditingGestureStart extends EditingElementGeometry {
16
16
  c: number;
17
17
  d: number;
18
18
  } | null;
19
- /** Set when GSAP owns its position: its x/y now, and whether a tween with a duration moves it. */
19
+ /** Set when GSAP owns its position: x/y, whether a tween moves it. `gsapAt`: read when null; 0, 0 with no GSAP. */
20
20
  gsap: {
21
21
  x: number;
22
22
  y: number;
23
23
  moving: boolean;
24
24
  drawsTranslate: true;
25
25
  } | null;
26
+ gsapAt: {
27
+ x: number;
28
+ y: number;
29
+ };
26
30
  /** GSAP's rotation now when it owns the element's turn; null when it turns by its own CSS `rotate`. */
27
31
  gsapRotation: number | null;
28
32
  cssRotation: CssRotationStart | null;
@@ -199,6 +199,10 @@ export function gestureStart(handles) {
199
199
  move: measureMoveResponse(element),
200
200
  grow: measureGrowResponse(element, geometry.layout),
201
201
  gsap: gsapPosition(element),
202
+ gsapAt: withoutGsapTakeover(element, () => ({
203
+ x: readGsap(element, "x"),
204
+ y: readGsap(element, "y"),
205
+ })),
202
206
  gsapRotation: rotation,
203
207
  cssRotation: rotation === null ? readCssRotationStart(element) : null,
204
208
  planar: planarOf(element),
@@ -33,8 +33,8 @@ import { type AssignAudioGroupParams } from "./editing/assignAudioGroup.js";
33
33
  import { type AudioMeterLevels } from "./editing/audioMeter.js";
34
34
  import { type SetAudioGroupAttributeParams } from "./editing/setAudioGroupAttribute.js";
35
35
  import { type EditElementParams, type EditElementResult } from "./editing/editElement.js";
36
- import { type TextEditEndedEvent, type TextEditParams, type TextEditResult } from "./editing/textEdit.js";
37
- 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, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, type TextLayerRead, } from "./editingElement.js";
36
+ import { type TextEditEndedEvent, type TextEditSelectionEvent, type TextEditParams, type TextEditResult } from "./editing/textEdit.js";
37
+ 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, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, type TextLayerRead, } from "./editingElement.js";
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";
@@ -46,7 +46,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
46
46
  export declare const EDITING_CONNECT = "editing-connect";
47
47
  /** Frame to parent, on the window: carries the port in its transfer list. */
48
48
  export declare const EDITING_PORT = "editing-port";
49
- export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "authored-styles", "font-faces", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "gesture-base", "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", "live-retime", "assets-unloaded", "text-edit", "serve-paused-frames"];
49
+ export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "authored-styles", "font-faces", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "gesture-base", "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", "remove-elements", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "assets-unloaded", "text-edit", "serve-paused-frames"];
50
50
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
51
51
  export interface EditingRuntimeSnapshot {
52
52
  /** The runtime has installed its player API. */
@@ -374,6 +374,14 @@ export interface EditingRequests {
374
374
  params: EditElementParams;
375
375
  result: EditElementResult;
376
376
  };
377
+ "remove-elements": {
378
+ params: {
379
+ handles: EditingElementHandle[];
380
+ };
381
+ result: {
382
+ removed: number;
383
+ };
384
+ };
377
385
  "stacking-family": {
378
386
  params: {
379
387
  handle: EditingElementHandle;
@@ -490,6 +498,7 @@ export interface EditingPortClient {
490
498
  onKey(listener: (key: EditingKeyEvent) => void): () => void;
491
499
  onGeometry(listener: (event: EditingGeometryEvent) => void): () => void;
492
500
  onTextEditEnded(listener: (event: TextEditEndedEvent) => void): () => void;
501
+ onTextEditSelection(listener: (event: TextEditSelectionEvent) => void): () => void;
493
502
  /** Rejects every pending request with `disposed` and closes the port. */
494
503
  dispose(): void;
495
504
  }
@@ -504,5 +513,5 @@ export declare function createEditingPortClient(options: {
504
513
  host?: Window;
505
514
  }): EditingPortClient;
506
515
  export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
507
- export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditResult, } from "./editing/textEdit.js";
516
+ export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditResult, type TextEditSelection, type TextEditSelectionEvent, } from "./editing/textEdit.js";
508
517
  export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, type PausedFrameAsk, type PausedFrameAskMessage, type PausedFrameImage, type PausedFrameReply, } from "./editing/pausedFrames.js";
@@ -17,8 +17,8 @@ import { parseAssignAudioGroup } from "./editing/assignAudioGroup.js";
17
17
  import { parseAudioMeter } from "./editing/audioMeter.js";
18
18
  import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
19
19
  import { parseEditElement, } from "./editing/editElement.js";
20
- import { parseTextEdit, textEditEndedEvent, } from "./editing/textEdit.js";
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, } from "./editingElement.js";
20
+ import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./editing/textEdit.js";
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
24
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
@@ -65,6 +65,7 @@ export const EDITING_REQUEST_KINDS = [
65
65
  "max-z-index",
66
66
  "crop-lift",
67
67
  "edit-element",
68
+ "remove-elements",
68
69
  "stacking-family",
69
70
  "gsap-set",
70
71
  "patch-tweens",
@@ -328,6 +329,7 @@ const PARAM_PARSERS = {
328
329
  ? { handle: params.handle, lift: params.lift }
329
330
  : null,
330
331
  "edit-element": parseEditElement,
332
+ "remove-elements": handleList,
331
333
  "stacking-family": (params) => hasKeys(params, "handle") && isHandle(params.handle) ? { handle: params.handle } : null,
332
334
  "gsap-set": gsapSetWithDrafts,
333
335
  "patch-tweens": parsePatchTweensRequest,
@@ -406,6 +408,7 @@ export function createEditingPortClient(options) {
406
408
  const keyListeners = new Set();
407
409
  const geometryListeners = new Set();
408
410
  const textEditListeners = new Set();
411
+ const selectionListeners = new Set();
409
412
  let watchedGeometry = false;
410
413
  let port = null;
411
414
  let disposed = false;
@@ -437,7 +440,10 @@ export function createEditingPortClient(options) {
437
440
  return geometryListeners.forEach((listener) => listener(geometry));
438
441
  const ended = textEditEndedEvent(data, EDITING_PROTOCOL_VERSION);
439
442
  if (ended)
440
- textEditListeners.forEach((listener) => listener(ended));
443
+ return textEditListeners.forEach((listener) => listener(ended));
444
+ const selected = textEditSelectionEvent(data, EDITING_PROTOCOL_VERSION);
445
+ if (selected)
446
+ selectionListeners.forEach((listener) => listener(selected));
441
447
  };
442
448
  const onReply = (event) => {
443
449
  const data = event.data;
@@ -508,6 +514,10 @@ export function createEditingPortClient(options) {
508
514
  textEditListeners.add(listener);
509
515
  return () => textEditListeners.delete(listener);
510
516
  },
517
+ onTextEditSelection(listener) {
518
+ selectionListeners.add(listener);
519
+ return () => selectionListeners.delete(listener);
520
+ },
511
521
  dispose() {
512
522
  if (disposed)
513
523
  return;
@@ -515,6 +525,7 @@ export function createEditingPortClient(options) {
515
525
  keyListeners.clear();
516
526
  geometryListeners.clear();
517
527
  textEditListeners.clear();
528
+ selectionListeners.clear();
518
529
  host.removeEventListener("message", onWindowMessage);
519
530
  if (watchedGeometry) {
520
531
  const stop = { kind: "watch-geometry", params: { handles: [] } };
@@ -2,6 +2,7 @@ import { sourceLengthOf } from "./sourceLength.js";
2
2
  import { transitionLabelsForDocument } from "./transitionLabels.js";
3
3
  import { unproxiedSrc } from "./proxySrc.js";
4
4
  import { stableClipId } from "./clipTree.js";
5
+ import { CLIP_NODES } from "./clipNodes.js";
5
6
  import { findRootCompositionElement, parseCompositionDimension } from "./compositionDimension.js";
6
7
  import { AUTHORED_DURATION_ATTR, AUTHORED_END_ATTR, resolveAuthoredTimingWindow, } from "./authoredTiming.js";
7
8
  import { swallow } from "./diagnostics.js";
@@ -229,6 +230,16 @@ export function collectRuntimeTimelinePayload(params) {
229
230
  const duration = readTimelineDurationSeconds(timelineRegistry[compositionId]);
230
231
  return duration != null && duration > 0 ? duration : null;
231
232
  };
233
+ const ownTimelineLength = (compositionId) => {
234
+ try {
235
+ const length = timelineRegistry[compositionId]?.duration?.();
236
+ return typeof length === "number" && Number.isFinite(length) ? length : null;
237
+ }
238
+ catch (err) {
239
+ swallow("runtime.timeline.ownLength", err);
240
+ return null;
241
+ }
242
+ };
232
243
  const resolveMediaWindowEndSeconds = () => {
233
244
  const mediaNodes = Array.from(document.querySelectorAll("video[data-start], audio[data-start]"));
234
245
  if (mediaNodes.length === 0)
@@ -354,7 +365,6 @@ export function collectRuntimeTimelinePayload(params) {
354
365
  // as clips — they have no declared timing so the timeline can't show their
355
366
  // actual visibility window. They can still appear as scenes via the separate
356
367
  // scene collection below.
357
- const CLIP_NODES = "[data-start], [data-track-index], [data-composition-id], video, audio, img";
358
368
  const nodes = Array.from(document.querySelectorAll(CLIP_NODES));
359
369
  let maxEnd = 0;
360
370
  const clipOf = (node, i) => {
@@ -435,6 +445,7 @@ export function collectRuntimeTimelinePayload(params) {
435
445
  timelinePriority: parseNum(node.getAttribute("data-timeline-priority")),
436
446
  text: readSentTextLayer(node),
437
447
  transitionLabel: transitionLabels.get(node) ?? null,
448
+ timelineDuration: isNestedHost ? ownTimelineLength(nodeCompositionId) : null,
438
449
  };
439
450
  };
440
451
  const addClip = (clip) => {
@@ -571,6 +582,7 @@ export function collectRuntimeTimelinePayload(params) {
571
582
  timelinePriority: parseNum(el.getAttribute("data-timeline-priority")),
572
583
  text: readSentTextLayer(el),
573
584
  transitionLabel: transitionLabels.get(el) ?? null,
585
+ timelineDuration: null,
574
586
  });
575
587
  gsapClipIds.add(el.id);
576
588
  }
@@ -635,6 +647,7 @@ export function collectRuntimeTimelinePayload(params) {
635
647
  timelinePriority: parseNum(el.getAttribute("data-timeline-priority")),
636
648
  text: readSentTextLayer(el),
637
649
  transitionLabel: transitionLabels.get(el) ?? null,
650
+ timelineDuration: null,
638
651
  });
639
652
  gsapClipIds.add(el.id);
640
653
  }
@@ -73,6 +73,7 @@ export type RuntimeTimelineClip = RuntimeTimelineClipIdentity & {
73
73
  timelinePriority: number | null;
74
74
  text: TextLayerRead | null;
75
75
  transitionLabel: string | null;
76
+ timelineDuration: number | null;
76
77
  };
77
78
  export type RuntimeTimelineScene = {
78
79
  id: string;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Styling a run of characters inside an element being edited in place.
3
+ *
4
+ * Not `document.execCommand`. That is deprecated, and what it emits varies by
5
+ * browser between `<font>`, a class, and an inline style depending on
6
+ * `styleWithCSS`. The output of this goes into the user's composition file, so
7
+ * it has to be one predictable shape, and the shape is a `<span>` carrying an
8
+ * inline style.
9
+ *
10
+ * Not DOM range surgery either, which is the obvious way and the wrong one.
11
+ * Wrapping a range in a span is three lines and then every interesting case is
12
+ * a special case: recolouring nests spans that shadow each other, removing a
13
+ * style cannot reach the ancestor that set it, and styling across an existing
14
+ * run's boundary has to split it. Each fix is a new branch and the branches
15
+ * interact.
16
+ *
17
+ * So the element is read into a flat list of styled runs, the styling is
18
+ * applied to a span of characters in that list, and the element is rebuilt
19
+ * from it. Replacing, removing, splitting and merging all stop being cases:
20
+ * the rebuild emits one span per distinct run and cannot nest or duplicate,
21
+ * whatever was there before. Text elements in a composition are a headline or
22
+ * a sentence, so reading and rebuilding one is not a cost worth avoiding.
23
+ */
24
+ export type InlineStyleDelta = Record<string, string | null>;
25
+ /** Apply `style` to the characters the range covers, then rebuild the element. */
26
+ export declare function applyInlineStyle(range: Range, style: InlineStyleDelta): void;
27
+ export interface InlineStyleChar {
28
+ char: string;
29
+ style: Readonly<Record<string, string>>;
30
+ painter: Element | null;
31
+ }
32
+ /** Every character the range covers with its style, or null when it covers none. */
33
+ export declare function readCoveredInlineStyleChars(range: Range): readonly InlineStyleChar[] | null;