@hyperframes/core 0.9.103 → 0.9.106

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 (37) hide show
  1. package/dist/compiler/compositionScoping.js +3 -3
  2. package/dist/compiler/htmlDocument.js +9 -2
  3. package/dist/compiler/svgIdNamespacing.js +2 -2
  4. package/dist/fonts/authoredGoogleFonts.js +2 -2
  5. package/dist/fonts/deterministicFonts.js +14 -12
  6. package/dist/fonts/fontDiagnostics.d.ts +3 -0
  7. package/dist/fonts/fontDiagnostics.js +32 -1
  8. package/dist/generated/runtime-inline.js +1 -1
  9. package/dist/hyperframe.runtime.iife.js +69 -69
  10. package/dist/runtime/drawnBox.d.ts +5 -0
  11. package/dist/runtime/drawnBox.js +5 -0
  12. package/dist/runtime/editing/canvasKeys.d.ts +0 -1
  13. package/dist/runtime/editing/canvasKeys.js +4 -28
  14. package/dist/runtime/editing/dragChrome.d.ts +32 -0
  15. package/dist/runtime/editing/dragChrome.js +154 -0
  16. package/dist/runtime/editing/pausedFrames.js +7 -7
  17. package/dist/runtime/editing/softReload.js +4 -2
  18. package/dist/runtime/editing/stageAct.js +3 -2
  19. package/dist/runtime/editing/textEdit.js +4 -3
  20. package/dist/runtime/editing/watchGeometry.js +8 -8
  21. package/dist/runtime/editing/watchPointer.d.ts +26 -0
  22. package/dist/runtime/editing/watchPointer.js +105 -0
  23. package/dist/runtime/editingDraft.d.ts +3 -2
  24. package/dist/runtime/editingDraft.js +13 -8
  25. package/dist/runtime/editingDraftEnd.d.ts +1 -0
  26. package/dist/runtime/editingElement.d.ts +4 -0
  27. package/dist/runtime/editingGeometry.js +1 -4
  28. package/dist/runtime/editingHandles.d.ts +0 -5
  29. package/dist/runtime/editingHandles.js +7 -0
  30. package/dist/runtime/editingPort.d.ts +22 -3
  31. package/dist/runtime/editingPort.js +63 -8
  32. package/dist/runtime/mediaProxy.js +78 -7
  33. package/dist/runtime/runtimePort.d.ts +21 -0
  34. package/dist/runtime/runtimePort.js +122 -0
  35. package/dist/studioPreviewMark.d.ts +2 -0
  36. package/dist/studioPreviewMark.js +2 -0
  37. package/package.json +4 -4
@@ -7,8 +7,8 @@ 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
- import { computedTranslateAxes, movedTranslate, SIZE_PROPERTIES, writeDrawnSize } from "./drawnBox.js";
11
- const DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES];
10
+ import { clearDragChrome, drawDragChrome } from "./editing/dragChrome.js";
11
+ import { computedTranslateAxes, DRAFT_DRAWN, movedTranslate, SIZE_PROPERTIES, writeDrawnSize, } from "./drawnBox.js";
12
12
  const frameGsap = () => window.gsap;
13
13
  /** The film's own timeline, as the unsealed recorder finds it: Studio's `__proxied` mark is no timeline. */
14
14
  function rootTimeline() {
@@ -26,7 +26,7 @@ function beforeOf(element) {
26
26
  const { style } = element;
27
27
  saved = {
28
28
  draft: ++lastDraft,
29
- inline: DRAWN.map((name) => [
29
+ inline: DRAFT_DRAWN.map((name) => [
30
30
  name,
31
31
  style.getPropertyValue(name),
32
32
  style.getPropertyPriority(name),
@@ -126,7 +126,7 @@ function drawProps(element, values) {
126
126
  saved.propsSet = [...new Set([...(saved.propsSet ?? []), ...Object.keys(values)])];
127
127
  }
128
128
  function clearProps(element, saved) {
129
- restore(element, DRAWN);
129
+ restore(element, DRAFT_DRAWN);
130
130
  saved.putMarkBack?.();
131
131
  if (saved.propsSet?.length)
132
132
  frameGsap()?.set?.(element, { clearProps: saved.propsSet.join(",") });
@@ -156,7 +156,7 @@ function end(element, ending) {
156
156
  if (ending.end === "clear")
157
157
  clearProps(element, saved);
158
158
  if (ending.end === "restore") {
159
- restore(element, DRAWN);
159
+ restore(element, DRAFT_DRAWN);
160
160
  restoreGsapPosition(element);
161
161
  restoreGsapRotation(element);
162
162
  }
@@ -221,8 +221,8 @@ function redrawKeepingLiveDrafts() {
221
221
  redrawTimelines();
222
222
  putLiveDraftsBack();
223
223
  }
224
- /** Applies each draft in order; one for an element this load no longer has is skipped. */
225
- export function drawDrafts(drafts) {
224
+ /** Applies each draft in order, then `chrome`; one for an element this load no longer has is skipped. */
225
+ export function drawDrafts(drafts, chrome) {
226
226
  let drawn = 0;
227
227
  let restored = false;
228
228
  const numbers = {};
@@ -238,5 +238,10 @@ export function drawDrafts(drafts) {
238
238
  }
239
239
  if (restored)
240
240
  redrawKeepingLiveDrafts();
241
- return { drawn, drafts: numbers };
241
+ if (chrome === undefined) {
242
+ if (!liveDrafts.size)
243
+ clearDragChrome();
244
+ return { drawn, drafts: numbers };
245
+ }
246
+ return { drawn, drafts: numbers, chromeDrawn: drawDragChrome(chrome) };
242
247
  }
@@ -13,5 +13,6 @@ export type EditingDraftEnd = {
13
13
  export type EditingDraftReply = {
14
14
  drawn: number;
15
15
  drafts: Record<EditingElementHandle, number>;
16
+ chromeDrawn?: boolean;
16
17
  };
17
18
  export declare function parseDraftEnd(value: unknown): EditingDraftEnd | null;
@@ -53,6 +53,10 @@ export interface EditingElementDescription extends EditingElementHit {
53
53
  }>;
54
54
  truncated: boolean;
55
55
  textMarkup?: boolean;
56
+ layout?: {
57
+ width: number;
58
+ height: number;
59
+ };
56
60
  }
57
61
  export interface EditingElementMatch {
58
62
  handle: EditingElementHandle;
@@ -6,6 +6,7 @@
6
6
  import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "../colorGrading.js";
7
7
  import { getLogicalOpacity } from "../studioPreviewMark.js";
8
8
  import { MAX_ELEMENT_ENTRIES, MAX_ELEMENT_VALUE, } from "./editingElement.js";
9
+ import { layoutOf } from "./drawnBox.js";
9
10
  import { elementForHandle } from "./editingHandles.js";
10
11
  import { composeElementTransform } from "./elementTransform.js";
11
12
  export const MAX_GEOMETRY_CHILDREN = 60;
@@ -132,10 +133,6 @@ function clipPathOf(element) {
132
133
  window.getComputedStyle(element).getPropertyValue("clip-path").trim();
133
134
  return value.length <= MAX_ELEMENT_VALUE ? value : null;
134
135
  }
135
- function layoutOf(element) {
136
- const { offsetWidth = 0, offsetHeight = 0 } = element;
137
- return { width: offsetWidth, height: offsetHeight };
138
- }
139
136
  const finiteCorners = (corners) => corners && Object.values(corners).every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))
140
137
  ? corners
141
138
  : null;
@@ -1,8 +1,3 @@
1
- /**
2
- * Element handles for the editing channel. The parent never receives an element, only a handle this
3
- * module gives it and the plain data `describeElement` reads from it. Handles live for one page load:
4
- * the maps are module state, and an entry goes once its element is garbage-collected.
5
- */
6
1
  import { type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
7
2
  export declare function handleFor(element: Element): EditingElementHandle;
8
3
  /** The live element in this document behind `handle`, else null. */
@@ -3,8 +3,10 @@
3
3
  * module gives it and the plain data `describeElement` reads from it. Handles live for one page load:
4
4
  * the maps are module state, and an entry goes once its element is garbage-collected.
5
5
  */
6
+ import { isDragChromeHost } from "./editing/dragChrome.js";
6
7
  import { buildStableSelector, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, readElementSource, } from "./editingElement.js";
7
8
  import { buildElementLabel, NO_TEXT, renderedTextOf } from "./elementLabel.js";
9
+ import { layoutOf } from "./drawnBox.js";
8
10
  import { isEditableText } from "./editing/textMarkup.js";
9
11
  // Drawn on first use, not at load: a render seeds getRandomValues, and a draw here would shift the
10
12
  // composition's own random values.
@@ -160,6 +162,7 @@ function describeElement(element) {
160
162
  children: children(element, state),
161
163
  truncated: state.truncated,
162
164
  textMarkup: isEditableText(element),
165
+ layout: layoutOf(element),
163
166
  };
164
167
  }
165
168
  export function elementsAtPoint(x, y) {
@@ -187,6 +190,8 @@ export function ancestorHandles(requested) {
187
190
  export function readEveryMatch(selector, read) {
188
191
  const matches = [];
189
192
  for (const element of document.querySelectorAll(selector)) {
193
+ if (isDragChromeHost(element))
194
+ continue;
190
195
  if (matches.length === MAX_QUERY_MATCHES)
191
196
  return { matches, truncated: true };
192
197
  matches.push(boundedSource(element) ? read(element) : null);
@@ -197,6 +202,8 @@ export function queryElements(selector) {
197
202
  const matches = [];
198
203
  let truncated = false;
199
204
  for (const element of document.querySelectorAll(selector)) {
205
+ if (isDragChromeHost(element))
206
+ continue;
200
207
  if (matches.length === MAX_QUERY_MATCHES)
201
208
  return { matches, truncated: true };
202
209
  const source = boundedSource(element);
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import type { RestoreAttributesParams } from "./editing/restoreAttributes.js";
13
13
  import { type EditingGeometryEvent, type WatchGeometryParams } from "./editing/watchGeometry.js";
14
+ import { type EditingPointerEvent, type WatchPointerParams } from "./editing/watchPointer.js";
14
15
  import { MAX_DRAFT_PX, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
15
16
  import type { EditingElementBox, EditingElementGeometry } from "./editingGeometry.js";
16
17
  import type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
@@ -20,6 +21,7 @@ import type { EditingLayer, EditingStackingSibling } from "./editingLayers.js";
20
21
  import { type GsapSetParams } from "./editing/gsapSet.js";
21
22
  import { type PatchTweensParams } from "./editing/patchTween.js";
22
23
  import { type EditingDraftEnd, type EditingDraftReply } from "./editingDraftEnd.js";
24
+ import { type EditingDragChrome } from "./editing/dragChrome.js";
23
25
  import { type SoftReloadParams, type SoftReloadResult } from "./editing/softReload.js";
24
26
  import { type HoldScenesParams, type MarkScenesStaleParams, type SwapScenesParams, type SwapScenesResult } from "./editing/scenes.js";
25
27
  import { type LiveRetimeParams, type LiveRetimeResult } from "./editing/liveRetime.js";
@@ -42,6 +44,7 @@ export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTrans
42
44
  export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
43
45
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
44
46
  export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
47
+ export { MAX_DRAG_CHROME_BYTES, MAX_DRAG_CHROME_NODES, parseDragChrome, type EditingDragChrome, type EditingDragChromeNode, } from "./editing/dragChrome.js";
45
48
  export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
46
49
  export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, type StageMeasuredItem, type StageMeasureParams, type StageMeasureResult, type StageTextStart, } from "./editing/stageMeasure.js";
47
50
  export { isStageColour, MAX_STAGE_ACTS, readStageActHeld, readStageRect, STAGE_ACT_BORROWS, STAGE_ACT_STYLES, type StageActBorrow, type StageActDraw, type StageActElementHold, type StageActGhostHold, type StageActHeld, type StageActHold, type StageActParams, type StageActReadyEvent, type StageActRect, type StageActResult, type StageActStyle, type StageActTarget, type StageInputEvent, } from "./editing/stageAct.js";
@@ -51,11 +54,14 @@ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_S
51
54
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
52
55
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
53
56
  export declare const EDITING_PROTOCOL_VERSION: 1;
57
+ export declare const DRAFT_CHROME = "draft-chrome";
54
58
  /** Parent to frame, on the window: asks the runtime for the port. */
55
59
  export declare const EDITING_CONNECT = "editing-connect";
60
+ export declare const PAGE_SHOWN = "page-shown";
61
+ export declare const PAGE_LEFT = "page-left";
56
62
  /** Frame to parent, on the window: carries the port in its transfer list. */
57
63
  export declare const EDITING_PORT = "editing-port";
58
- 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", "rebind-timing", "assets-unloaded", "text-edit", "serve-paused-frames", "frame-presented", "arm-canvas-keys", "resolve-canvas-key-action", "stage-measure", "stage-act"];
64
+ 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", "watch-pointer", "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", "rebind-timing", "assets-unloaded", "text-edit", "serve-paused-frames", "frame-presented", "arm-canvas-keys", "resolve-canvas-key-action", "stage-measure", "stage-act"];
59
65
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
60
66
  export interface EditingRuntimeSnapshot {
61
67
  /** The runtime has installed its player API. */
@@ -118,12 +124,16 @@ export type EditingDraft = {
118
124
  props?: EditingDraftProps | null;
119
125
  } | EditingDraftEnd;
120
126
  type NoParams = Record<string, never>;
127
+ export type FramePresentedParams = {
128
+ waitMs?: number;
129
+ };
121
130
  export interface EditingRequests {
122
131
  hello: {
123
132
  params: NoParams;
124
133
  result: {
125
134
  version: typeof EDITING_PROTOCOL_VERSION;
126
135
  kinds: string[];
136
+ accepts?: string[];
127
137
  };
128
138
  };
129
139
  "runtime-snapshot": {
@@ -256,10 +266,11 @@ export interface EditingRequests {
256
266
  missingGroup: boolean;
257
267
  };
258
268
  };
259
- /** Gesture drafts in order, up to MAX_DESCRIBE_HANDLES; `drawn` counts the elements still here. */
269
+ /** Gesture drafts in order, up to MAX_DESCRIBE_HANDLES, and the chrome painted with them (null clears it). */
260
270
  draft: {
261
271
  params: {
262
272
  drafts: EditingDraft[];
273
+ chrome?: EditingDragChrome;
263
274
  };
264
275
  result: EditingDraftReply & {
265
276
  gsapSetTakesDrafts?: true;
@@ -330,6 +341,12 @@ export interface EditingRequests {
330
341
  watching: number;
331
342
  };
332
343
  };
344
+ "watch-pointer": {
345
+ params: WatchPointerParams;
346
+ result: {
347
+ watching: boolean;
348
+ };
349
+ };
333
350
  "audio-meter": {
334
351
  params: {
335
352
  on: boolean;
@@ -473,7 +490,7 @@ export interface EditingRequests {
473
490
  };
474
491
  };
475
492
  "frame-presented": {
476
- params: NoParams;
493
+ params: FramePresentedParams;
477
494
  result: {
478
495
  presented: boolean;
479
496
  };
@@ -542,6 +559,7 @@ export interface EditingPortClient {
542
559
  /** Calls `listener` with each key the frame forwards for `watch-keys`; returns the unsubscribe. */
543
560
  onKey(listener: (key: EditingKeyEvent) => void): () => void;
544
561
  onGeometry(listener: (event: EditingGeometryEvent) => void): () => void;
562
+ onPointerTargets(listener: (event: EditingPointerEvent) => void): () => void;
545
563
  onTextEditEnded(listener: (event: TextEditEndedEvent) => void): () => void;
546
564
  onTextEditAway(listener: (event: TextEditAwayEvent) => void): () => void;
547
565
  onTextEditSelection(listener: (event: TextEditSelectionEvent) => void): () => void;
@@ -560,6 +578,7 @@ export declare function createEditingPortClient(options: {
560
578
  iframe: HTMLIFrameElement;
561
579
  timeoutMs?: number;
562
580
  host?: Window;
581
+ gate?: Promise<boolean>;
563
582
  }): EditingPortClient;
564
583
  export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
565
584
  export { MAX_CANVAS_KEY_COMBOS, type ArmCanvasKeysParams, type ArmCanvasKeysResult, type CanvasKeyActionEvent, type CanvasKeyNudgeCombo, type ResolveCanvasKeyActionParams, type ResolveCanvasKeyActionResult, } from "./editing/canvasKeys.js";
@@ -1,8 +1,10 @@
1
1
  import { geometryEvent, parseWatchGeometry, } from "./editing/watchGeometry.js";
2
+ import { parseWatchPointer, pointerEvent, } from "./editing/watchPointer.js";
2
3
  import { EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_DRAFT_PX, } from "./editingElement.js";
3
4
  import { parseGsapSet } from "./editing/gsapSet.js";
4
5
  import { parsePatchTweensRequest } from "./editing/patchTween.js";
5
6
  import { parseDraftEnd } from "./editingDraftEnd.js";
7
+ import { parseDragChrome } from "./editing/dragChrome.js";
6
8
  import { parseRestoreAttributesRerun, parseSoftReload, } from "./editing/softReload.js";
7
9
  import { parseHoldScenes, parseMarkScenesStale, parseSwapScenes, } from "./editing/scenes.js";
8
10
  import { parseLiveRetime, } from "./editing/liveRetime.js";
@@ -25,6 +27,7 @@ export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEdit
25
27
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
26
28
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
27
29
  export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
30
+ export { MAX_DRAG_CHROME_BYTES, MAX_DRAG_CHROME_NODES, parseDragChrome, } from "./editing/dragChrome.js";
28
31
  export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
29
32
  export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, } from "./editing/stageMeasure.js";
30
33
  export { isStageColour, MAX_STAGE_ACTS, readStageActHeld, readStageRect, STAGE_ACT_BORROWS, STAGE_ACT_STYLES, } from "./editing/stageAct.js";
@@ -34,8 +37,11 @@ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_S
34
37
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
35
38
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
36
39
  export const EDITING_PROTOCOL_VERSION = 1;
40
+ export const DRAFT_CHROME = "draft-chrome";
37
41
  /** Parent to frame, on the window: asks the runtime for the port. */
38
42
  export const EDITING_CONNECT = "editing-connect";
43
+ export const PAGE_SHOWN = "page-shown";
44
+ export const PAGE_LEFT = "page-left";
39
45
  /** Frame to parent, on the window: carries the port in its transfer list. */
40
46
  export const EDITING_PORT = "editing-port";
41
47
  export const EDITING_REQUEST_KINDS = [
@@ -65,6 +71,7 @@ export const EDITING_REQUEST_KINDS = [
65
71
  "color-grading-previews",
66
72
  "color-grading-playback",
67
73
  "watch-geometry",
74
+ "watch-pointer",
68
75
  "audio-meter",
69
76
  "document-markup",
70
77
  "set-audio-group-attribute",
@@ -107,6 +114,7 @@ export const DRAFT_GSAP_PROPS = [
107
114
  "rotationY",
108
115
  "z",
109
116
  ];
117
+ const MAX_FRAME_PRESENTED_WAIT_MS = 15_000;
110
118
  export function isPlainRecord(value) {
111
119
  return Object.prototype.toString.call(value) === "[object Object]";
112
120
  }
@@ -116,6 +124,21 @@ const MAX_STYLE_PROPERTY_LENGTH = 256;
116
124
  const STYLE_PROPERTY = /^(?:[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/;
117
125
  const hasKeys = (params, keys) => isPlainRecord(params) && Object.keys(params).sort().join() === keys;
118
126
  const noParams = (params) => params === undefined || (isPlainRecord(params) && Object.keys(params).length === 0) ? {} : null;
127
+ function parseFramePresented(params) {
128
+ if (noParams(params))
129
+ return {};
130
+ if (!hasKeys(params, "waitMs"))
131
+ return null;
132
+ const { waitMs } = params;
133
+ const bounded = typeof waitMs === "number" &&
134
+ Number.isFinite(waitMs) &&
135
+ waitMs > 0 &&
136
+ waitMs <= MAX_FRAME_PRESENTED_WAIT_MS;
137
+ return bounded ? { waitMs } : null;
138
+ }
139
+ const clientWaitPastFrameDeadline = (kind, params) => kind === "frame-presented" && isPlainRecord(params) && typeof params.waitMs === "number"
140
+ ? params.waitMs + 1_000
141
+ : 0;
119
142
  const isSelector = (value) => typeof value === "string" && value.length > 0 && value.length <= MAX_SELECTOR_LENGTH;
120
143
  const isHandle = (value) => typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
121
144
  function styleTarget(params) {
@@ -241,14 +264,22 @@ function gsapSetWithDrafts(params) {
241
264
  return parseGsapSet(params);
242
265
  const { drafts, ...set } = params;
243
266
  const parsed = parseGsapSet(set);
244
- const drawn = draftList({ drafts });
267
+ const drawn = draftsOnly({ drafts });
245
268
  return parsed && drawn ? { ...parsed, drafts: drawn.drafts } : null;
246
269
  }
247
270
  function draftList(params) {
271
+ if (!isPlainRecord(params) || !("chrome" in params))
272
+ return draftsOnly(params);
273
+ const { chrome, ...rest } = params;
274
+ const drawn = draftsOnly(rest, true);
275
+ const parsed = parseDragChrome(chrome);
276
+ return drawn && parsed !== undefined ? { ...drawn, chrome: parsed } : null;
277
+ }
278
+ function draftsOnly(params, chromeOnly = false) {
248
279
  if (!hasKeys(params, "drafts") || !Array.isArray(params.drafts))
249
280
  return null;
250
281
  const { drafts } = params;
251
- if (!drafts.length || drafts.length > MAX_DESCRIBE_HANDLES)
282
+ if ((!drafts.length && !chromeOnly) || drafts.length > MAX_DESCRIBE_HANDLES)
252
283
  return null;
253
284
  const parsed = drafts.map(draftEntry);
254
285
  return parsed.includes(null) ? null : { drafts: parsed };
@@ -335,6 +366,7 @@ const PARAM_PARSERS = {
335
366
  "color-grading-previews": parseColorGradingPreviewsParams,
336
367
  "color-grading-playback": parseColorGradingPlaybackParams,
337
368
  "watch-geometry": parseWatchGeometry,
369
+ "watch-pointer": parseWatchPointer,
338
370
  "audio-meter": parseAudioMeter,
339
371
  "document-markup": noParams,
340
372
  "set-audio-group-attribute": parseSetAudioGroupAttribute,
@@ -368,7 +400,7 @@ const PARAM_PARSERS = {
368
400
  "serve-paused-frames": (params) => hasKeys(params, "channel") && params.channel instanceof MessagePort
369
401
  ? { channel: params.channel }
370
402
  : null,
371
- "frame-presented": noParams,
403
+ "frame-presented": parseFramePresented,
372
404
  "arm-canvas-keys": parseArmCanvasKeys,
373
405
  "resolve-canvas-key-action": parseResolveCanvasKeyAction,
374
406
  "stage-measure": parseStageMeasureParams,
@@ -443,10 +475,11 @@ const portsTaken = new WeakSet();
443
475
  * that frame sends. Replies are data from the frame, so callers validate results.
444
476
  */
445
477
  export function createEditingPortClient(options) {
446
- const { iframe, timeoutMs = EDITING_REQUEST_TIMEOUT_MS, host = window } = options;
478
+ const { iframe, timeoutMs = EDITING_REQUEST_TIMEOUT_MS, host = window, gate } = options;
447
479
  const pending = new Map();
448
480
  const keyListeners = new Set();
449
481
  const geometryListeners = new Set();
482
+ const pointerListeners = new Set();
450
483
  const textEditListeners = new Set();
451
484
  const awayListeners = new Set();
452
485
  const selectionListeners = new Set();
@@ -454,6 +487,7 @@ export function createEditingPortClient(options) {
454
487
  const stageReadyListeners = new Set();
455
488
  const stageInputListeners = new Set();
456
489
  let watchedGeometry = false;
490
+ let watchedPointer = false;
457
491
  let port = null;
458
492
  let disposed = false;
459
493
  let lastId = 0;
@@ -479,6 +513,7 @@ export function createEditingPortClient(options) {
479
513
  const pushRoutes = [
480
514
  pushRoute(keyListeners, (d) => d.v === v && d.event === "key" && keyEvent(d.key)),
481
515
  pushRoute(geometryListeners, (d) => geometryEvent(d, v)),
516
+ pushRoute(pointerListeners, (d) => pointerEvent(d, v)),
482
517
  pushRoute(textEditListeners, (d) => textEditEndedEvent(d, v)),
483
518
  pushRoute(awayListeners, (d) => textEditAwayEvent(d, v)),
484
519
  pushRoute(selectionListeners, (d) => textEditSelectionEvent(d, v)),
@@ -515,9 +550,17 @@ export function createEditingPortClient(options) {
515
550
  port.onmessage = onReply;
516
551
  resolveReady();
517
552
  };
518
- host.addEventListener("message", onWindowMessage);
519
- connect();
520
- return {
553
+ const start = () => {
554
+ if (disposed)
555
+ return;
556
+ host.addEventListener("message", onWindowMessage);
557
+ connect();
558
+ };
559
+ if (gate)
560
+ void gate.then((open) => (open ? start() : client.dispose()));
561
+ else
562
+ start();
563
+ const client = {
521
564
  ready,
522
565
  request(kind, params, requestOptions) {
523
566
  if (disposed)
@@ -525,7 +568,9 @@ export function createEditingPortClient(options) {
525
568
  const id = ++lastId;
526
569
  if (kind === "watch-geometry")
527
570
  watchedGeometry = true;
528
- const limit = requestOptions?.timeoutMs ?? timeoutMs;
571
+ if (kind === "watch-pointer")
572
+ watchedPointer = true;
573
+ const limit = requestOptions?.timeoutMs ?? Math.max(timeoutMs, clientWaitPastFrameDeadline(kind, params));
529
574
  const result = new Promise((resolve, reject) => {
530
575
  const timer = wallSetTimeout(() => settle(id, { error: new EditingPortError("timeout", `${kind} timed out`) }), limit);
531
576
  pending.set(id, { resolve, reject, timer });
@@ -552,6 +597,10 @@ export function createEditingPortClient(options) {
552
597
  geometryListeners.add(listener);
553
598
  return () => geometryListeners.delete(listener);
554
599
  },
600
+ onPointerTargets(listener) {
601
+ pointerListeners.add(listener);
602
+ return () => pointerListeners.delete(listener);
603
+ },
555
604
  onTextEditEnded(listener) {
556
605
  textEditListeners.add(listener);
557
606
  return () => textEditListeners.delete(listener);
@@ -582,6 +631,7 @@ export function createEditingPortClient(options) {
582
631
  disposed = true;
583
632
  keyListeners.clear();
584
633
  geometryListeners.clear();
634
+ pointerListeners.clear();
585
635
  textEditListeners.clear();
586
636
  awayListeners.clear();
587
637
  selectionListeners.clear();
@@ -593,6 +643,10 @@ export function createEditingPortClient(options) {
593
643
  const stop = { kind: "watch-geometry", params: { handles: [] } };
594
644
  port?.postMessage({ v: EDITING_PROTOCOL_VERSION, id: ++lastId, ...stop });
595
645
  }
646
+ if (watchedPointer) {
647
+ const stop = { kind: "watch-pointer", params: { point: null } };
648
+ port?.postMessage({ v: EDITING_PROTOCOL_VERSION, id: ++lastId, ...stop });
649
+ }
596
650
  port?.close();
597
651
  rejectReady(new EditingPortError("disposed", "client disposed"));
598
652
  for (const id of [...pending.keys()]) {
@@ -600,6 +654,7 @@ export function createEditingPortClient(options) {
600
654
  }
601
655
  },
602
656
  };
657
+ return client;
603
658
  }
604
659
  export { elementHome, transformWDivisor } from "./editing/motionPathHome.js";
605
660
  export { MAX_CANVAS_KEY_COMBOS, } from "./editing/canvasKeys.js";
@@ -166,7 +166,7 @@ function holdShownFrame(el) {
166
166
  const still = stillOf(el);
167
167
  if (!still)
168
168
  return;
169
- heldPosters.set(el, { poster: el.getAttribute("poster"), since: performance.now() });
169
+ heldPosters.set(el, { poster: pagePoster(el), since: performance.now() });
170
170
  el.setAttribute("poster", still);
171
171
  const letGo = () => {
172
172
  for (const type of RELEASE_EVENTS)
@@ -306,6 +306,9 @@ export function isRenderMode(el) {
306
306
  return isVideoElement(el) && !!findInjectedRenderFrame(el);
307
307
  }
308
308
  const stills = new WeakSet();
309
+ // The poster each still put up (its URL, or a sealed frame's data URL), and the hold a sealed fetch belongs to.
310
+ const stillPosters = new WeakMap();
311
+ const stillHolds = new WeakMap();
309
312
  /** While a file the browser cannot play is being copied, its own frame at the playhead stands in as the poster. */
310
313
  function showStill(el, originalSrc, variant, box, light) {
311
314
  const at = sourceTimeAtPlayhead(el);
@@ -314,10 +317,48 @@ function showStill(el, originalSrc, variant, box, light) {
314
317
  const url = new URL(appendProxyParam(originalSrc, variant, box, light), document.baseURI);
315
318
  url.searchParams.set(PREVIEW_PROXY_STILL_PARAM, at.toFixed(1));
316
319
  stills.add(el);
317
- el.setAttribute("poster", url.href);
320
+ if (window.origin !== "null")
321
+ return putUpStill(el, url.href);
322
+ // A sealed frame's poster load can wait behind its other loads; its fetch goes out at once.
323
+ const hold = {};
324
+ stillHolds.set(el, hold);
325
+ void fetch(url.href)
326
+ .then((res) => (res.ok ? dataUrlOf(res) : null))
327
+ .then((still) => {
328
+ if (still && stillHolds.get(el) === hold && !el.hasAttribute("poster"))
329
+ putUpStill(el, still);
330
+ })
331
+ .catch((err) => swallow("runtime.mediaProxy.still", err));
332
+ }
333
+ // A data URL, like the held frame's own still: nothing to release on any way the clip goes. Encoded natively.
334
+ async function dataUrlOf(res) {
335
+ const type = res.headers.get("content-type") ?? "image/jpeg";
336
+ const blob = new Blob([await res.arrayBuffer()], { type });
337
+ return new Promise((resolve, reject) => {
338
+ const reader = new FileReader();
339
+ reader.onload = () => resolve(String(reader.result));
340
+ reader.onerror = () => reject(reader.error);
341
+ reader.readAsDataURL(blob);
342
+ });
343
+ }
344
+ function putUpStill(el, poster) {
345
+ stillPosters.set(el, poster);
346
+ el.setAttribute("poster", poster);
347
+ }
348
+ /** The poster as the page set it: none while the runtime's own still is up. */
349
+ function pagePoster(el) {
350
+ const poster = el.getAttribute("poster");
351
+ return poster !== null && poster === stillPosters.get(el) ? null : poster;
318
352
  }
319
353
  function dropStill(el) {
320
- if (stills.delete(el))
354
+ if (!stills.delete(el))
355
+ return;
356
+ stillHolds.delete(el);
357
+ const poster = stillPosters.get(el);
358
+ stillPosters.delete(el);
359
+ if (poster === undefined)
360
+ return;
361
+ if (el.getAttribute("poster") === poster)
321
362
  el.removeAttribute("poster");
322
363
  }
323
364
  function appendProxyParam(src, variant, box, light = false, retry = false) {
@@ -473,10 +514,40 @@ async function makeCopy(el, job, scale) {
473
514
  // The shown size may have grown while this copy was being made.
474
515
  if (displayScale !== null)
475
516
  keepSized(el, displayScale);
476
- return new Promise((landed) => {
477
- el.addEventListener("loadeddata", landed, { once: true });
478
- el.addEventListener("error", landed, { once: true });
479
- }).then(() => dropStill(el));
517
+ return copyLoadEnds(el, proxiedSrc).then(() => dropStill(el));
518
+ }
519
+ const ENDS_A_LOAD = ["loadeddata", "error", "abort", "emptied"];
520
+ const leaving = new Map();
521
+ let leavingObserver = null;
522
+ /** Settles once the copy draws or fails, the clip loads something else, or it leaves the page. */
523
+ function copyLoadEnds(el, href) {
524
+ return new Promise((ended) => {
525
+ const end = (event) => {
526
+ const restarted = event?.type === "abort" || event?.type === "emptied";
527
+ if (restarted && el.getAttribute("src") === href)
528
+ return;
529
+ for (const type of ENDS_A_LOAD)
530
+ el.removeEventListener(type, end);
531
+ if (leaving.get(el) === end)
532
+ leaving.delete(el);
533
+ if (leaving.size === 0) {
534
+ leavingObserver?.disconnect();
535
+ leavingObserver = null;
536
+ }
537
+ ended();
538
+ };
539
+ for (const type of ENDS_A_LOAD)
540
+ el.addEventListener(type, end);
541
+ leaving.set(el, end);
542
+ if (leavingObserver || typeof MutationObserver === "undefined")
543
+ return;
544
+ leavingObserver = new MutationObserver(() => {
545
+ for (const [clip, left] of leaving)
546
+ if (!clip.isConnected)
547
+ left();
548
+ });
549
+ leavingObserver.observe(document, { childList: true, subtree: true });
550
+ });
480
551
  }
481
552
  /**
482
553
  * Swap `el` to its alpha-aware proxy URL, evict stale per-source sync state, and
@@ -0,0 +1,21 @@
1
+ /** Tests only: stand-in ports and events from another realm (jsdom over Node) keep their own methods. */
2
+ export declare function allowPortStandInsForTests(): void;
3
+ /** Null when the browser's own port methods could not be read at load: the agent then never connects. */
4
+ export declare function createRuntimeChannel(): {
5
+ port1: MessagePort;
6
+ port2: MessagePort;
7
+ } | null;
8
+ export declare function postOnPort(port: MessagePort, message: unknown, transfer?: Transferable[]): void;
9
+ export declare function onPortMessage(port: MessagePort, handler: (data: unknown) => void): void;
10
+ export declare function closePort(port: MessagePort): void;
11
+ /** A Map keyed by ports whose calls never reach a patched Map.prototype. */
12
+ export interface PortMap<V> {
13
+ get(port: MessagePort): V | undefined;
14
+ set(port: MessagePort, value: V): void;
15
+ has(port: MessagePort): boolean;
16
+ delete(port: MessagePort): boolean;
17
+ clear(): void;
18
+ forEach(each: (value: V, port: MessagePort) => void): void;
19
+ size(): number;
20
+ }
21
+ export declare function portMap<V>(): PortMap<V>;