@hyperframes/core 0.9.102 → 0.9.104

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 (40) hide show
  1. package/dist/atomicFile.d.ts +1 -0
  2. package/dist/atomicFile.js +1 -1
  3. package/dist/compiler/compositionScoping.js +3 -3
  4. package/dist/compiler/svgIdNamespacing.js +2 -2
  5. package/dist/fonts/authoredGoogleFonts.js +2 -2
  6. package/dist/fonts/deterministicFonts.js +2 -2
  7. package/dist/generated/position-edits-render-inline.js +1 -1
  8. package/dist/generated/runtime-inline.js +1 -1
  9. package/dist/hyperframe.runtime.iife.js +71 -71
  10. package/dist/index.d.ts +1 -1
  11. package/dist/runtime/domRealm.d.ts +1 -0
  12. package/dist/runtime/domRealm.js +3 -0
  13. package/dist/runtime/editing/canvasKeys.d.ts +63 -0
  14. package/dist/runtime/editing/canvasKeys.js +471 -0
  15. package/dist/runtime/editing/pausedFrames.js +7 -7
  16. package/dist/runtime/editing/removeElements.d.ts +10 -0
  17. package/dist/runtime/editing/removeElements.js +35 -0
  18. package/dist/runtime/editing/stageAct.d.ts +116 -0
  19. package/dist/runtime/editing/stageAct.js +531 -0
  20. package/dist/runtime/editing/stageGhost.d.ts +10 -0
  21. package/dist/runtime/editing/stageGhost.js +64 -0
  22. package/dist/runtime/editing/stageMeasure.d.ts +5 -0
  23. package/dist/runtime/editing/stageMeasure.js +35 -1
  24. package/dist/runtime/editing/textEdit.d.ts +14 -0
  25. package/dist/runtime/editing/textEdit.js +67 -9
  26. package/dist/runtime/editing/transformValues.d.ts +6 -0
  27. package/dist/runtime/editing/transformValues.js +39 -0
  28. package/dist/runtime/editing/watchGeometry.js +8 -8
  29. package/dist/runtime/editingGestureStart.d.ts +2 -0
  30. package/dist/runtime/editingGestureStart.js +1 -1
  31. package/dist/runtime/editingPort.d.ts +35 -3
  32. package/dist/runtime/editingPort.js +78 -16
  33. package/dist/runtime/playbackHealth.d.ts +8 -1
  34. package/dist/runtime/playbackHealth.js +118 -18
  35. package/dist/runtime/runtimePort.d.ts +21 -0
  36. package/dist/runtime/runtimePort.js +122 -0
  37. package/dist/runtime/types.d.ts +18 -0
  38. package/dist/studioPreviewMark.d.ts +1 -0
  39. package/dist/studioPreviewMark.js +1 -0
  40. package/package.json +4 -4
@@ -18,13 +18,18 @@ import { parseAudioMeter } from "./editing/audioMeter.js";
18
18
  import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
19
19
  import { parseEditElement, } from "./editing/editElement.js";
20
20
  import { parseStageMeasureParams, } from "./editing/stageMeasure.js";
21
- import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./editing/textEdit.js";
21
+ import { parseStageActParams, stageActReadyEvent, stageInputEvent, } from "./editing/stageAct.js";
22
+ import { parseTextEdit, textEditAwayEvent, textEditEndedEvent, textEditSelectionEvent, } from "./editing/textEdit.js";
23
+ import { canvasKeyActionEvent, parseArmCanvasKeys, parseResolveCanvasKeyAction, } from "./editing/canvasKeys.js";
22
24
  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";
23
25
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
24
26
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
25
27
  export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
26
28
  export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
27
29
  export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, } from "./editing/stageMeasure.js";
30
+ export { isStageColour, MAX_STAGE_ACTS, readStageActHeld, readStageRect, STAGE_ACT_BORROWS, STAGE_ACT_STYLES, } from "./editing/stageAct.js";
31
+ export { MAX_STAGE_GHOST_MARKUP } from "./editing/stageGhost.js";
32
+ export { rotateBy, scaleBy, translateBy } from "./editing/transformValues.js";
28
33
  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";
29
34
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
30
35
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
@@ -82,7 +87,11 @@ export const EDITING_REQUEST_KINDS = [
82
87
  "assets-unloaded",
83
88
  "text-edit",
84
89
  "serve-paused-frames",
90
+ "frame-presented",
91
+ "arm-canvas-keys",
92
+ "resolve-canvas-key-action",
85
93
  "stage-measure",
94
+ "stage-act",
86
95
  ];
87
96
  export { MAX_DRAFT_PX };
88
97
  export const EDITING_REQUEST_TIMEOUT_MS = 5_000;
@@ -98,6 +107,7 @@ export const DRAFT_GSAP_PROPS = [
98
107
  "rotationY",
99
108
  "z",
100
109
  ];
110
+ const MAX_FRAME_PRESENTED_WAIT_MS = 15_000;
101
111
  export function isPlainRecord(value) {
102
112
  return Object.prototype.toString.call(value) === "[object Object]";
103
113
  }
@@ -107,6 +117,21 @@ const MAX_STYLE_PROPERTY_LENGTH = 256;
107
117
  const STYLE_PROPERTY = /^(?:[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/;
108
118
  const hasKeys = (params, keys) => isPlainRecord(params) && Object.keys(params).sort().join() === keys;
109
119
  const noParams = (params) => params === undefined || (isPlainRecord(params) && Object.keys(params).length === 0) ? {} : null;
120
+ function parseFramePresented(params) {
121
+ if (noParams(params))
122
+ return {};
123
+ if (!hasKeys(params, "waitMs"))
124
+ return null;
125
+ const { waitMs } = params;
126
+ const bounded = typeof waitMs === "number" &&
127
+ Number.isFinite(waitMs) &&
128
+ waitMs > 0 &&
129
+ waitMs <= MAX_FRAME_PRESENTED_WAIT_MS;
130
+ return bounded ? { waitMs } : null;
131
+ }
132
+ const clientWaitPastFrameDeadline = (kind, params) => kind === "frame-presented" && isPlainRecord(params) && typeof params.waitMs === "number"
133
+ ? params.waitMs + 1_000
134
+ : 0;
110
135
  const isSelector = (value) => typeof value === "string" && value.length > 0 && value.length <= MAX_SELECTOR_LENGTH;
111
136
  const isHandle = (value) => typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
112
137
  function styleTarget(params) {
@@ -359,8 +384,22 @@ const PARAM_PARSERS = {
359
384
  "serve-paused-frames": (params) => hasKeys(params, "channel") && params.channel instanceof MessagePort
360
385
  ? { channel: params.channel }
361
386
  : null,
387
+ "frame-presented": parseFramePresented,
388
+ "arm-canvas-keys": parseArmCanvasKeys,
389
+ "resolve-canvas-key-action": parseResolveCanvasKeyAction,
362
390
  "stage-measure": parseStageMeasureParams,
391
+ "stage-act": parseStageActParams,
363
392
  };
393
+ /** Hands a push to its listeners when `parse` reads it as their event; false when it is not one. */
394
+ function pushRoute(listeners, parse) {
395
+ return (data) => {
396
+ const event = parse(data);
397
+ if (!event)
398
+ return false;
399
+ listeners.forEach((listener) => listener(event));
400
+ return true;
401
+ };
402
+ }
364
403
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
365
404
  export function parseEditingRequest(data) {
366
405
  if (!isPlainRecord(data) || !Number.isSafeInteger(data.id) || data.id < 0) {
@@ -425,7 +464,11 @@ export function createEditingPortClient(options) {
425
464
  const keyListeners = new Set();
426
465
  const geometryListeners = new Set();
427
466
  const textEditListeners = new Set();
467
+ const awayListeners = new Set();
428
468
  const selectionListeners = new Set();
469
+ const canvasKeyActionListeners = new Set();
470
+ const stageReadyListeners = new Set();
471
+ const stageInputListeners = new Set();
429
472
  let watchedGeometry = false;
430
473
  let port = null;
431
474
  let disposed = false;
@@ -448,20 +491,18 @@ export function createEditingPortClient(options) {
448
491
  else
449
492
  entry.resolve(outcome.result);
450
493
  };
451
- const onPush = (data) => {
452
- const key = data.v === EDITING_PROTOCOL_VERSION && data.event === "key" && keyEvent(data.key);
453
- if (key)
454
- return keyListeners.forEach((listener) => listener(key));
455
- const geometry = geometryEvent(data, EDITING_PROTOCOL_VERSION);
456
- if (geometry)
457
- return geometryListeners.forEach((listener) => listener(geometry));
458
- const ended = textEditEndedEvent(data, EDITING_PROTOCOL_VERSION);
459
- if (ended)
460
- return textEditListeners.forEach((listener) => listener(ended));
461
- const selected = textEditSelectionEvent(data, EDITING_PROTOCOL_VERSION);
462
- if (selected)
463
- selectionListeners.forEach((listener) => listener(selected));
464
- };
494
+ const v = EDITING_PROTOCOL_VERSION;
495
+ const pushRoutes = [
496
+ pushRoute(keyListeners, (d) => d.v === v && d.event === "key" && keyEvent(d.key)),
497
+ pushRoute(geometryListeners, (d) => geometryEvent(d, v)),
498
+ pushRoute(textEditListeners, (d) => textEditEndedEvent(d, v)),
499
+ pushRoute(awayListeners, (d) => textEditAwayEvent(d, v)),
500
+ pushRoute(selectionListeners, (d) => textEditSelectionEvent(d, v)),
501
+ pushRoute(canvasKeyActionListeners, (d) => canvasKeyActionEvent(d, v)),
502
+ pushRoute(stageReadyListeners, (d) => stageActReadyEvent(d, v)),
503
+ pushRoute(stageInputListeners, (d) => stageInputEvent(d, v)),
504
+ ];
505
+ const onPush = (data) => void pushRoutes.some((route) => route(data));
465
506
  const onReply = (event) => {
466
507
  const data = event.data;
467
508
  if (!isPlainRecord(data))
@@ -500,7 +541,7 @@ export function createEditingPortClient(options) {
500
541
  const id = ++lastId;
501
542
  if (kind === "watch-geometry")
502
543
  watchedGeometry = true;
503
- const limit = requestOptions?.timeoutMs ?? timeoutMs;
544
+ const limit = requestOptions?.timeoutMs ?? Math.max(timeoutMs, clientWaitPastFrameDeadline(kind, params));
504
545
  const result = new Promise((resolve, reject) => {
505
546
  const timer = wallSetTimeout(() => settle(id, { error: new EditingPortError("timeout", `${kind} timed out`) }), limit);
506
547
  pending.set(id, { resolve, reject, timer });
@@ -531,10 +572,26 @@ export function createEditingPortClient(options) {
531
572
  textEditListeners.add(listener);
532
573
  return () => textEditListeners.delete(listener);
533
574
  },
575
+ onTextEditAway(listener) {
576
+ awayListeners.add(listener);
577
+ return () => awayListeners.delete(listener);
578
+ },
534
579
  onTextEditSelection(listener) {
535
580
  selectionListeners.add(listener);
536
581
  return () => selectionListeners.delete(listener);
537
582
  },
583
+ onCanvasKeyAction(listener) {
584
+ canvasKeyActionListeners.add(listener);
585
+ return () => canvasKeyActionListeners.delete(listener);
586
+ },
587
+ onStageActReady(listener) {
588
+ stageReadyListeners.add(listener);
589
+ return () => stageReadyListeners.delete(listener);
590
+ },
591
+ onStageInput(listener) {
592
+ stageInputListeners.add(listener);
593
+ return () => stageInputListeners.delete(listener);
594
+ },
538
595
  dispose() {
539
596
  if (disposed)
540
597
  return;
@@ -542,7 +599,11 @@ export function createEditingPortClient(options) {
542
599
  keyListeners.clear();
543
600
  geometryListeners.clear();
544
601
  textEditListeners.clear();
602
+ awayListeners.clear();
545
603
  selectionListeners.clear();
604
+ canvasKeyActionListeners.clear();
605
+ stageReadyListeners.clear();
606
+ stageInputListeners.clear();
546
607
  host.removeEventListener("message", onWindowMessage);
547
608
  if (watchedGeometry) {
548
609
  const stop = { kind: "watch-geometry", params: { handles: [] } };
@@ -557,6 +618,7 @@ export function createEditingPortClient(options) {
557
618
  };
558
619
  }
559
620
  export { elementHome, transformWDivisor } from "./editing/motionPathHome.js";
621
+ export { MAX_CANVAS_KEY_COMBOS, } from "./editing/canvasKeys.js";
560
622
  export { caretRangeAt, takePlainTextOnly, textEditResult, } from "./editing/textEdit.js";
561
623
  export { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, } from "./editing/textCaret.js";
562
624
  export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, } from "./editing/pausedFrames.js";
@@ -1,4 +1,4 @@
1
- import type { PlaybackHeldBy } from "./types.js";
1
+ import type { PlaybackHeldBy, PlaybackMotionBlurReport, PreviewFrameShape } from "./types.js";
2
2
  /** What counts as a choppy preview; every number of the rule lives here. */
3
3
  export declare const PLAYBACK_HEALTH: {
4
4
  readonly windowSeconds: 3;
@@ -20,6 +20,11 @@ export type PlaybackHealthInput = {
20
20
  clock: "audio" | "webaudio" | "monotonic";
21
21
  /** Anything that changes how heavy a frame is to draw (window size, zoom). */
22
22
  layoutKey: string;
23
+ audio?: {
24
+ el: HTMLMediaElement;
25
+ time: number;
26
+ } | null;
27
+ readMotionBlur?: () => PlaybackMotionBlurReport | null;
23
28
  };
24
29
  export declare function watchMediaFetches(doc: Document): () => void;
25
30
  export declare function heldByMedia(el: HTMLMediaElement, nowMs: number): PlaybackHeldBy;
@@ -29,3 +34,5 @@ export declare function noteDisplayScale(scale: number): void;
29
34
  export declare function restartPlaybackHealth(): void;
30
35
  /** One call per runtime tick: counts frames drawn against frames due while the film plays. */
31
36
  export declare function notePlaybackFrame(input: PlaybackHealthInput): void;
37
+ export declare function readMotionBlurSummary(doc?: Document, win?: Window): PlaybackMotionBlurReport | null;
38
+ export declare function readPreviewFrameShape(doc?: Document, win?: Window): PreviewFrameShape;
@@ -7,7 +7,12 @@ export const PLAYBACK_HEALTH = {
7
7
  reportEveryMs: 1000,
8
8
  };
9
9
  const FORWARD_JUMP_SECONDS = 0.5;
10
+ const MAX_MEDIA_STEP_MS = 500;
11
+ const FRAME_16_MS = 25;
12
+ const FRAME_33_MS = 41.7;
10
13
  let samples = [];
14
+ let audioSteps = [];
15
+ let lastAudio = null;
11
16
  let last = null;
12
17
  let warmEndMs = 0;
13
18
  let key = "";
@@ -38,6 +43,8 @@ function post(health) {
38
43
  }
39
44
  function clear() {
40
45
  samples = [];
46
+ audioSteps = [];
47
+ lastAudio = null;
41
48
  last = null;
42
49
  if (posted)
43
50
  post(null);
@@ -56,27 +63,69 @@ export function noteDisplayScale(scale) {
56
63
  export function restartPlaybackHealth() {
57
64
  clear();
58
65
  }
59
- function measure(nowMs, fps, rate) {
60
- const windowMs = PLAYBACK_HEALTH.windowSeconds * 1000;
61
- while (samples[0] && samples[0].atMs < nowMs - windowMs)
66
+ function mediaStepP90() {
67
+ if (audioSteps.length === 0)
68
+ return null;
69
+ const sorted = audioSteps.map((step) => step.ms).sort((a, b) => a - b);
70
+ return Math.round(sorted[Math.ceil(0.9 * sorted.length) - 1] ?? 0);
71
+ }
72
+ function summarizeGaps() {
73
+ const gaps = samples.map((sample) => sample.gapMs).sort((a, b) => a - b);
74
+ const gapAt = (share) => Math.round(gaps[Math.ceil(share * gaps.length) - 1] ?? 0);
75
+ let over16 = 0;
76
+ let over33 = 0;
77
+ for (const gap of gaps) {
78
+ if (gap > FRAME_16_MS)
79
+ over16 += 1;
80
+ if (gap > FRAME_33_MS)
81
+ over33 += 1;
82
+ }
83
+ return {
84
+ gapP50Ms: gapAt(0.5),
85
+ gapP95Ms: gapAt(0.95),
86
+ worstFrameMs: Math.round(gaps[gaps.length - 1] ?? 0),
87
+ over16,
88
+ over33,
89
+ };
90
+ }
91
+ function trimWindow(nowMs, windowMs) {
92
+ const cutoff = nowMs - windowMs;
93
+ while (samples[0] && samples[0].atMs < cutoff)
62
94
  samples.shift();
95
+ while (audioSteps[0] && audioSteps[0].atMs < cutoff)
96
+ audioSteps.shift();
97
+ }
98
+ function summarizeWindow(spanMs, fps, rate) {
99
+ let drawn = 0;
100
+ let waitingMs = 0;
101
+ let frozenMs = 0;
102
+ let heldBy = null;
103
+ for (const sample of samples) {
104
+ if (sample.drawn)
105
+ drawn += 1;
106
+ if (sample.waiting)
107
+ waitingMs += sample.gapMs;
108
+ if (sample.frozen)
109
+ frozenMs += sample.gapMs;
110
+ if (sample.heldBy)
111
+ heldBy = sample.heldBy;
112
+ }
113
+ const due = (spanMs / 1000) * fps * rate;
114
+ const skipped = due > 0 ? 1 - Math.min(drawn, due) / due : 0;
115
+ const droppedShare = Math.max(skipped, waitingMs / spanMs);
116
+ return { drawn, skipped, waitingMs, frozenMs, droppedShare, heldBy };
117
+ }
118
+ function measure(nowMs, fps, rate, readMotionBlur) {
119
+ const windowMs = PLAYBACK_HEALTH.windowSeconds * 1000;
120
+ trimWindow(nowMs, windowMs);
63
121
  const first = samples[0];
64
122
  if (!first)
65
123
  return;
66
124
  const spanMs = nowMs - (first.atMs - first.gapMs);
67
125
  if (spanMs < windowMs || nowMs - postedAtMs < PLAYBACK_HEALTH.reportEveryMs)
68
126
  return;
69
- const drawn = samples.filter((sample) => sample.drawn).length;
70
- const due = (spanMs / 1000) * fps * rate;
71
- const skipped = due > 0 ? 1 - Math.min(drawn, due) / due : 0;
72
- const waitingMs = samples.reduce((sum, s) => sum + (s.waiting ? s.gapMs : 0), 0);
73
- const frozenMs = samples.reduce((sum, s) => sum + (s.frozen ? s.gapMs : 0), 0);
74
- const droppedShare = Math.max(skipped, waitingMs / spanMs);
75
- let heldBy = null;
76
- for (const sample of samples)
77
- heldBy = sample.heldBy ?? heldBy;
78
- const gaps = samples.map((sample) => sample.gapMs).sort((a, b) => a - b);
79
- const gapAt = (share) => Math.round(gaps[Math.ceil(share * gaps.length) - 1] ?? 0);
127
+ const { drawn, skipped, waitingMs, frozenMs, droppedShare, heldBy } = summarizeWindow(spanMs, fps, rate);
128
+ const motionBlur = readMotionBlur?.();
80
129
  posted = true;
81
130
  postedAtMs = nowMs;
82
131
  post({
@@ -84,17 +133,29 @@ function measure(nowMs, fps, rate) {
84
133
  seconds: Math.round(spanMs / 100) / 10,
85
134
  choppy: droppedShare >= PLAYBACK_HEALTH.choppyShare,
86
135
  fps: Math.round((drawn / (spanMs / 1000)) * 10) / 10,
87
- worstFrameMs: Math.round(Math.max(...samples.map((sample) => sample.gapMs))),
88
136
  skippedShare: Math.round(skipped * 1000) / 1000,
89
137
  waitingShare: Math.round((waitingMs / spanMs) * 1000) / 1000,
90
138
  frozenShare: Math.round((frozenMs / spanMs) * 1000) / 1000,
91
- gapP50Ms: gapAt(0.5),
92
- gapP95Ms: gapAt(0.95),
93
139
  clockSource,
94
140
  heldBy,
141
+ mediaStepP90Ms: mediaStepP90(),
142
+ ...summarizeGaps(),
143
+ ...(motionBlur !== undefined ? { motionBlur } : {}),
95
144
  mode: "play",
96
145
  });
97
146
  }
147
+ function noteAudioStep(nowMs, audio) {
148
+ if (!audio || lastAudio?.el !== audio.el) {
149
+ lastAudio = audio ? { el: audio.el, time: audio.time } : null;
150
+ return;
151
+ }
152
+ if (audio.time === lastAudio.time)
153
+ return;
154
+ const stepMs = (audio.time - lastAudio.time) * 1000;
155
+ if (stepMs > 0 && stepMs < MAX_MEDIA_STEP_MS)
156
+ audioSteps.push({ atMs: nowMs, ms: stepMs });
157
+ lastAudio.time = audio.time;
158
+ }
98
159
  /** One call per runtime tick: counts frames drawn against frames due while the film plays. */
99
160
  export function notePlaybackFrame(input) {
100
161
  const { nowMs, filmTime, fps, rate } = input;
@@ -125,6 +186,7 @@ export function notePlaybackFrame(input) {
125
186
  if (nowMs < warmEndMs)
126
187
  return;
127
188
  clockSource = input.clock;
189
+ noteAudioStep(nowMs, input.audio);
128
190
  samples.push({
129
191
  atMs: nowMs,
130
192
  gapMs,
@@ -133,5 +195,43 @@ export function notePlaybackFrame(input) {
133
195
  frozen: input.frozen === true,
134
196
  heldBy: input.heldBy ?? null,
135
197
  });
136
- measure(nowMs, fps, rate);
198
+ measure(nowMs, fps, rate, input.readMotionBlur);
199
+ }
200
+ export function readMotionBlurSummary(doc = document, win = window) {
201
+ try {
202
+ const root = doc.querySelector("[data-composition-id]");
203
+ if (!root)
204
+ return null;
205
+ const report = win.__hfMotionBlur?.report?.();
206
+ const tier = report?.state === "on" && (report.tier === "filter" || report.tier === "capture")
207
+ ? report.tier
208
+ : null;
209
+ return {
210
+ attr: root.getAttribute("data-motion-blur"),
211
+ shutter: root.getAttribute("data-motion-blur-shutter"),
212
+ state: tier ? "on" : "off",
213
+ tier,
214
+ movers: tier && typeof report?.movers === "number" ? report.movers : null,
215
+ };
216
+ }
217
+ catch {
218
+ return null;
219
+ }
220
+ }
221
+ export function readPreviewFrameShape(doc = document, win = window) {
222
+ let tweens = null;
223
+ try {
224
+ const list = win.gsap?.globalTimeline?.getChildren?.(true, true, false);
225
+ if (Array.isArray(list))
226
+ tweens = list.length;
227
+ }
228
+ catch {
229
+ tweens = null;
230
+ }
231
+ return {
232
+ canvas: doc.querySelectorAll("canvas").length,
233
+ svg: doc.querySelectorAll("svg").length,
234
+ filter: doc.querySelectorAll('[style*="filter"]').length,
235
+ tweens,
236
+ };
137
237
  }
@@ -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>;
@@ -0,0 +1,122 @@
1
+ // The runtime's MessagePort calls, bound to built-ins read when the runtime first evaluates, before any
2
+ // composition script runs. Best-effort: it covers the port, channel, event-data and container calls the
3
+ // runtime makes with a port; a built-in reached some other way after load is not covered.
4
+ const apply = Reflect.apply;
5
+ const protoOf = Object.getPrototypeOf;
6
+ const descriptor = Object.getOwnPropertyDescriptor;
7
+ const NativeMessageChannel = typeof MessageChannel !== "undefined" ? MessageChannel : null;
8
+ function accessor(proto, name, kind) {
9
+ for (let at = proto; at; at = protoOf(at)) {
10
+ const found = descriptor(at, name)?.[kind];
11
+ if (found)
12
+ return found;
13
+ }
14
+ return null;
15
+ }
16
+ // Browsers expose a channel's ports through prototype getters; Node keeps them as the channel's own data.
17
+ function channelPort(channel, getter, name) {
18
+ return (getter ? apply(getter, channel, []) : descriptor(channel, name)?.value);
19
+ }
20
+ const native = (() => {
21
+ if (!NativeMessageChannel)
22
+ return null;
23
+ try {
24
+ const probe = new NativeMessageChannel();
25
+ const channelProto = protoOf(probe);
26
+ const port1 = accessor(channelProto, "port1", "get");
27
+ const port2 = accessor(channelProto, "port2", "get");
28
+ const proto = protoOf(channelPort(probe, port1, "port1"));
29
+ const setOnMessage = accessor(proto, "onmessage", "set");
30
+ const eventProto = typeof MessageEvent !== "undefined" ? MessageEvent.prototype : null;
31
+ const eventData = accessor(eventProto, "data", "get");
32
+ if (!setOnMessage)
33
+ return null;
34
+ const methods = {
35
+ proto,
36
+ post: proto.postMessage,
37
+ close: proto.close,
38
+ setOnMessage,
39
+ port1,
40
+ port2,
41
+ eventData,
42
+ eventProto,
43
+ };
44
+ apply(methods.close, channelPort(probe, port1, "port1"), []);
45
+ apply(methods.close, channelPort(probe, port2, "port2"), []);
46
+ return methods;
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ })();
52
+ let standIns = false;
53
+ /** Tests only: stand-in ports and events from another realm (jsdom over Node) keep their own methods. */
54
+ export function allowPortStandInsForTests() {
55
+ standIns = true;
56
+ }
57
+ function bound(port) {
58
+ if (native && protoOf(port) === native.proto)
59
+ return native;
60
+ if (standIns)
61
+ return null;
62
+ throw new Error("not a runtime port");
63
+ }
64
+ /** Null when the browser's own port methods could not be read at load: the agent then never connects. */
65
+ export function createRuntimeChannel() {
66
+ if (!native || !NativeMessageChannel || !(native.eventData || standIns))
67
+ return null;
68
+ const channel = new NativeMessageChannel();
69
+ return {
70
+ port1: channelPort(channel, native.port1, "port1"),
71
+ port2: channelPort(channel, native.port2, "port2"),
72
+ };
73
+ }
74
+ export function postOnPort(port, message, transfer) {
75
+ const methods = bound(port);
76
+ if (methods)
77
+ apply(methods.post, port, [message, transfer ?? []]);
78
+ else if (transfer)
79
+ port.postMessage(message, transfer);
80
+ else
81
+ port.postMessage(message);
82
+ }
83
+ export function onPortMessage(port, handler) {
84
+ const methods = bound(port);
85
+ const onMessage = (event) => {
86
+ const read = native?.eventData;
87
+ if (read && protoOf(event) === native?.eventProto)
88
+ handler(apply(read, event, []));
89
+ else if (standIns)
90
+ handler(event.data);
91
+ };
92
+ if (methods)
93
+ apply(methods.setOnMessage, port, [onMessage]);
94
+ else
95
+ port.onmessage = onMessage;
96
+ }
97
+ export function closePort(port) {
98
+ const methods = bound(port);
99
+ if (methods)
100
+ apply(methods.close, port, []);
101
+ else
102
+ port.close();
103
+ }
104
+ const mapGet = Map.prototype.get;
105
+ const mapSet = Map.prototype.set;
106
+ const mapHas = Map.prototype.has;
107
+ const mapDelete = Map.prototype.delete;
108
+ const mapClear = Map.prototype.clear;
109
+ const mapForEach = Map.prototype.forEach;
110
+ const mapSize = accessor(Map.prototype, "size", "get");
111
+ export function portMap() {
112
+ const map = new Map();
113
+ return {
114
+ get: (port) => apply(mapGet, map, [port]),
115
+ set: (port, value) => void apply(mapSet, map, [port, value]),
116
+ has: (port) => apply(mapHas, map, [port]),
117
+ delete: (port) => apply(mapDelete, map, [port]),
118
+ clear: () => void apply(mapClear, map, []),
119
+ forEach: (each) => void apply(mapForEach, map, [each]),
120
+ size: () => apply(mapSize, map, []),
121
+ };
122
+ }
@@ -271,6 +271,19 @@ export type PlaybackHeldBy = {
271
271
  networkState: number;
272
272
  fetchMs: number | FetchNotSeenToStart;
273
273
  };
274
+ export type PlaybackMotionBlurReport = {
275
+ attr: string | null;
276
+ shutter: string | null;
277
+ state: "on" | "off";
278
+ tier: "filter" | "capture" | null;
279
+ movers: number | null;
280
+ };
281
+ export type PreviewFrameShape = {
282
+ canvas: number;
283
+ svg: number;
284
+ filter: number;
285
+ tweens: number | null;
286
+ };
274
287
  /** How playback went over the last few seconds of play. */
275
288
  export type PlaybackHealthReport = {
276
289
  droppedShare: number;
@@ -285,6 +298,10 @@ export type PlaybackHealthReport = {
285
298
  gapP95Ms: number;
286
299
  clockSource: "audio" | "webaudio" | "monotonic";
287
300
  heldBy: PlaybackHeldBy | null;
301
+ mediaStepP90Ms?: number | null;
302
+ over16?: number;
303
+ over33?: number;
304
+ motionBlur?: PlaybackMotionBlurReport | null;
288
305
  mode: "play";
289
306
  };
290
307
  export type RuntimePreviewHealthMessage = {
@@ -310,6 +327,7 @@ export type RuntimePreviewFactsMessage = {
310
327
  /** The lower levels at which at least one video gets a lighter copy. */
311
328
  lighterAt: number[];
312
329
  copiesReady: boolean;
330
+ frameShape?: PreviewFrameShape;
313
331
  };
314
332
  };
315
333
  export type RuntimeOutboundMessage = RuntimeStateMessage | RuntimePreviewCopiesMessage | RuntimePreviewHealthMessage | RuntimePreviewFactsMessage | RuntimeTimelineMessage | RuntimeDiagnosticMessage | RuntimePickerHoveredMessage | RuntimePickerCandidatesMessage | RuntimePickerPickedMessage | RuntimePickerPickedManyMessage | RuntimePickerCancelledMessage | RuntimeStageSizeMessage | RuntimeStaticCompositionMessage | RuntimeMediaAutoplayBlockedMessage | RuntimeParentCopiesMessage | RuntimeReadyMessage | RuntimeAssetsReadyMessage | RuntimeDataErrorMessage | RuntimeDataAppliedMessage | RuntimeAnalyticsMessage | RuntimePerformanceMessage | RuntimeGroupLevelsMessage;
@@ -23,6 +23,7 @@ export declare const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
23
23
  export declare const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
24
24
  export declare const STUDIO_PREVIEW_ERROR_MESSAGE = "preview-error";
25
25
  export declare const STUDIO_PREVIEW_ERROR_KINDS = "__hfPreviewErrorKinds";
26
+ export declare const STUDIO_PREVIEW_RETRY_AFTER = "__hfPreviewRetryAfter";
26
27
  export declare function previewConsoleErrorText(args: readonly unknown[]): string | null;
27
28
  export declare const refusedPreviewMessage: (status: number) => string;
28
29
  export declare function refusedPreviewStatus(message: string): number | null;
@@ -51,6 +51,7 @@ export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
51
51
  export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
52
52
  export const STUDIO_PREVIEW_ERROR_MESSAGE = "preview-error";
53
53
  export const STUDIO_PREVIEW_ERROR_KINDS = "__hfPreviewErrorKinds";
54
+ export const STUDIO_PREVIEW_RETRY_AFTER = "__hfPreviewRetryAfter";
54
55
  export function previewConsoleErrorText(args) {
55
56
  const text = args.map((a) => (a instanceof Error ? a.message : String(a))).join(" ");
56
57
  return text.includes("favicon") ? null : text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.102",
3
+ "version": "0.9.104",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -525,9 +525,9 @@
525
525
  "linkedom": "^0.18.12",
526
526
  "postcss": "^8.5.8",
527
527
  "wawoff2": "^2.0.1",
528
- "@hyperframes/lint": "0.9.102",
529
- "@hyperframes/studio-server": "0.9.102",
530
- "@hyperframes/parsers": "0.9.102"
528
+ "@hyperframes/lint": "0.9.104",
529
+ "@hyperframes/studio-server": "0.9.104",
530
+ "@hyperframes/parsers": "0.9.104"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",