@hyperframes/core 0.10.7 → 0.10.8

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.
package/dist/index.d.ts CHANGED
@@ -38,7 +38,7 @@ export { parseCubeLut, CubeLutParseError, type CubeLut3D, type ParseCubeLutOptio
38
38
  export { bakeHfColorGradingCube, type BakeHfColorGradingCubeOptions } from "./colorGradingBake.js";
39
39
  export { firstFrameColourArgs, hdrToSdrToneMapFilter, keyframeTransferArgs, parseKeyframeTransfers, readsKeyframeTransfers, toneMapReferenceNits, parseFirstFrameColour, type ToneMapFrameColour, type ToneMapSourceColour, } from "./hdrToneMap.js";
40
40
  export { htmlHasStudioReappliedMark, isStudioMotionMark, STUDIO_REAPPLIED_MARKS, STUDIO_SEEK_REAPPLY_STARTED, } from "./studioReappliedMarks.js";
41
- export { HEAVY_BITRATE, HEAVY_PIXEL_SHARE, PREVIEW_PROXY_BOX_PARAM, PREVIEW_PROXY_LIGHT_PARAM, PREVIEW_PROXY_PRIORITY_HEADER, PREVIEW_PROXY_PROGRESS_HEADER, PREVIEW_PROXY_RETRY_PARAM, PREVIEW_PROXY_STILL_PARAM, PREVIEW_QUALITY_LEVELS, formatPreviewProxyBox, isHeavyForPreview, isPreviewQuality, parsePreviewProxyBox, quantizePreviewProxyBox, scalePreviewProxyBox, type PreviewProxyBox, type PreviewQuality, type PreviewSourceFacts, } from "./previewProxyBox.js";
41
+ export { HEAVY_BITRATE, HEAVY_PIXEL_SHARE, PREVIEW_PROXY_BOX_PARAM, PREVIEW_PROXY_LIGHT_PARAM, PREVIEW_PROXY_PRIORITY_HEADER, formatProxyPriorityHeader, parseProxyPriorityHeader, type ProxyPriorityHint, PREVIEW_PROXY_PROGRESS_HEADER, PREVIEW_PROXY_RETRY_PARAM, PREVIEW_PROXY_STILL_PARAM, PREVIEW_QUALITY_LEVELS, formatPreviewProxyBox, isHeavyForPreview, isPreviewQuality, parsePreviewProxyBox, quantizePreviewProxyBox, scalePreviewProxyBox, type PreviewProxyBox, type PreviewQuality, type PreviewSourceFacts, } from "./previewProxyBox.js";
42
42
  export { naturalVideoSize, parseSampleAspectRatio, streamRotation, type MediaDisplayFacts, } from "./mediaDisplaySize.js";
43
43
  export type { PausedVideoFrameProvider, PausedVideoFrameRequest, PausedVideoFrame, } from "./runtime/pausedVideoFrames.js";
44
44
  export { HYPERFRAME_RUNTIME_ARTIFACTS, HYPERFRAME_RUNTIME_CONTRACT, loadHyperframeRuntimeSource, type HyperframeRuntimeContract, } from "./inline-scripts/hyperframe.js";
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ export { parseCubeLut, CubeLutParseError, } from "./colorLuts.js";
33
33
  export { bakeHfColorGradingCube } from "./colorGradingBake.js";
34
34
  export { firstFrameColourArgs, hdrToSdrToneMapFilter, keyframeTransferArgs, parseKeyframeTransfers, readsKeyframeTransfers, toneMapReferenceNits, parseFirstFrameColour, } from "./hdrToneMap.js";
35
35
  export { htmlHasStudioReappliedMark, isStudioMotionMark, STUDIO_REAPPLIED_MARKS, STUDIO_SEEK_REAPPLY_STARTED, } from "./studioReappliedMarks.js";
36
- export { HEAVY_BITRATE, HEAVY_PIXEL_SHARE, PREVIEW_PROXY_BOX_PARAM, PREVIEW_PROXY_LIGHT_PARAM, PREVIEW_PROXY_PRIORITY_HEADER, PREVIEW_PROXY_PROGRESS_HEADER, PREVIEW_PROXY_RETRY_PARAM, PREVIEW_PROXY_STILL_PARAM, PREVIEW_QUALITY_LEVELS, formatPreviewProxyBox, isHeavyForPreview, isPreviewQuality, parsePreviewProxyBox, quantizePreviewProxyBox, scalePreviewProxyBox, } from "./previewProxyBox.js";
36
+ export { HEAVY_BITRATE, HEAVY_PIXEL_SHARE, PREVIEW_PROXY_BOX_PARAM, PREVIEW_PROXY_LIGHT_PARAM, PREVIEW_PROXY_PRIORITY_HEADER, formatProxyPriorityHeader, parseProxyPriorityHeader, PREVIEW_PROXY_PROGRESS_HEADER, PREVIEW_PROXY_RETRY_PARAM, PREVIEW_PROXY_STILL_PARAM, PREVIEW_QUALITY_LEVELS, formatPreviewProxyBox, isHeavyForPreview, isPreviewQuality, parsePreviewProxyBox, quantizePreviewProxyBox, scalePreviewProxyBox, } from "./previewProxyBox.js";
37
37
  export { naturalVideoSize, parseSampleAspectRatio, streamRotation, } from "./mediaDisplaySize.js";
38
38
  // Inline scripts
39
39
  export { HYPERFRAME_RUNTIME_ARTIFACTS, HYPERFRAME_RUNTIME_CONTRACT, loadHyperframeRuntimeSource, } from "./inline-scripts/hyperframe.js";
@@ -5,6 +5,13 @@ export declare const PREVIEW_PROXY_RETRY_PARAM = "hf-proxy-retry";
5
5
  export declare const PREVIEW_PROXY_STILL_PARAM = "hf-proxy-still";
6
6
  export declare const PREVIEW_PROXY_PROGRESS_HEADER = "X-HF-Proxy-Progress";
7
7
  export declare const PREVIEW_PROXY_PRIORITY_HEADER = "X-HF-Proxy-Priority";
8
+ export type ProxyPriorityHint = {
9
+ priority?: boolean;
10
+ background?: boolean;
11
+ playing?: boolean;
12
+ };
13
+ export declare function formatProxyPriorityHeader({ priority, background, playing, }: ProxyPriorityHint): string | undefined;
14
+ export declare function parseProxyPriorityHeader(raw: string | undefined): ProxyPriorityHint;
8
15
  export type PreviewProxyBox = {
9
16
  width: number;
10
17
  height: number;
@@ -5,6 +5,29 @@ export const PREVIEW_PROXY_RETRY_PARAM = "hf-proxy-retry";
5
5
  export const PREVIEW_PROXY_STILL_PARAM = "hf-proxy-still";
6
6
  export const PREVIEW_PROXY_PROGRESS_HEADER = "X-HF-Proxy-Progress";
7
7
  export const PREVIEW_PROXY_PRIORITY_HEADER = "X-HF-Proxy-Priority";
8
+ export function formatProxyPriorityHeader({ priority, background, playing, }) {
9
+ const rank = priority ? "1" : background ? "0" : "";
10
+ if (rank && playing)
11
+ return `${rank};playing`;
12
+ if (rank)
13
+ return rank;
14
+ return playing ? "playing" : undefined;
15
+ }
16
+ export function parseProxyPriorityHeader(raw) {
17
+ if (!raw)
18
+ return { priority: false };
19
+ const parts = raw
20
+ .split(";")
21
+ .map((part) => part.trim())
22
+ .filter(Boolean);
23
+ const playing = parts.includes("playing");
24
+ const rank = parts[0];
25
+ if (rank === "0")
26
+ return playing ? { background: true, playing: true } : { background: true };
27
+ if (rank === "1")
28
+ return playing ? { priority: true, playing: true } : { priority: true };
29
+ return playing ? { priority: false, playing: true } : { priority: false };
30
+ }
8
31
  // 256 * 2^(k/4), even: nearby boxes share one cached copy, and a rung overshoots by at most ~19%.
9
32
  const RUNGS = [
10
33
  256, 304, 362, 430, 512, 608, 724, 862, 1024, 1218, 1448, 1722, 2048, 2436, 2896, 3444, 4096,
@@ -178,10 +178,15 @@ function liveDraftOf(last, draft) {
178
178
  return draft;
179
179
  return { ...draft, ...carriedRotate(last, draft), ...mergedProps(last, draft) };
180
180
  }
181
+ const draftDraws = (element, part) => {
182
+ const draft = liveDrafts.get(element);
183
+ return !!draft && !("end" in draft) && !!(draft.props || draft[part]);
184
+ };
181
185
  function apply(element, draft) {
182
186
  if ("end" in draft)
183
187
  return end(element, draft);
184
188
  liveDrafts.set(element, liveDraftOf(liveDrafts.get(element), draft));
189
+ (window.__hf ??= {}).draftDraws = draftDraws;
185
190
  if ("rotate" in draft)
186
191
  drawRotate(element, draft.rotate ?? null);
187
192
  if (draft.translate)
@@ -55,11 +55,9 @@ export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLa
55
55
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
56
56
  export declare const EDITING_PROTOCOL_VERSION: 1;
57
57
  export declare const DRAFT_CHROME = "draft-chrome";
58
- /** Parent to frame, on the window: asks the runtime for the port. */
58
+ /** Parent to frame, on the window: the ask every released editor sends; the runtime answers with a fresh port. */
59
59
  export declare const EDITING_CONNECT = "editing-connect";
60
- export declare const PAGE_SHOWN = "page-shown";
61
- export declare const PAGE_LEFT = "page-left";
62
- /** Frame to parent, on the window: carries the port in its transfer list. */
60
+ /** Frame to parent, on the window, once per page as the runtime loads: carries its port in the transfer list. */
63
61
  export declare const EDITING_PORT = "editing-port";
64
62
  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"];
65
63
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
@@ -550,7 +548,7 @@ export declare class EditingPortError extends Error {
550
548
  constructor(code: EditingErrorCode, message: string);
551
549
  }
552
550
  export interface EditingPortClient {
553
- /** Settles when the frame's runtime has handed over its port. */
551
+ /** Settles when the frame's runtime serves the port this client sent it. */
554
552
  readonly ready: Promise<void>;
555
553
  request<K extends EditingRequestKind>(kind: K, params: EditingParams<K>, options?: {
556
554
  timeoutMs?: number;
@@ -570,15 +568,13 @@ export interface EditingPortClient {
570
568
  dispose(): void;
571
569
  }
572
570
  /**
573
- * The parent's end of the editing channel for one preview frame load. Asks for
574
- * the port at once and again on the runtime's `ready`, and takes the first port
575
- * that frame sends. Replies are data from the frame, so callers validate results.
571
+ * The parent's end of the editing channel for one preview frame load: `port` is the runtime's own, which the
572
+ * parent took from the frame's load, or null when that load has none. Replies are data from the frame, so
573
+ * callers validate results.
576
574
  */
577
575
  export declare function createEditingPortClient(options: {
578
- iframe: HTMLIFrameElement;
576
+ port: Promise<MessagePort | null>;
579
577
  timeoutMs?: number;
580
- host?: Window;
581
- gate?: Promise<boolean>;
582
578
  }): EditingPortClient;
583
579
  export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
584
580
  export { MAX_CANVAS_KEY_COMBOS, type ArmCanvasKeysParams, type ArmCanvasKeysResult, type CanvasKeyActionEvent, type CanvasKeyNudgeCombo, type ResolveCanvasKeyActionParams, type ResolveCanvasKeyActionResult, } from "./editing/canvasKeys.js";
@@ -38,11 +38,9 @@ export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLa
38
38
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
39
39
  export const EDITING_PROTOCOL_VERSION = 1;
40
40
  export const DRAFT_CHROME = "draft-chrome";
41
- /** Parent to frame, on the window: asks the runtime for the port. */
41
+ /** Parent to frame, on the window: the ask every released editor sends; the runtime answers with a fresh port. */
42
42
  export const EDITING_CONNECT = "editing-connect";
43
- export const PAGE_SHOWN = "page-shown";
44
- export const PAGE_LEFT = "page-left";
45
- /** Frame to parent, on the window: carries the port in its transfer list. */
43
+ /** Frame to parent, on the window, once per page as the runtime loads: carries its port in the transfer list. */
46
44
  export const EDITING_PORT = "editing-port";
47
45
  export const EDITING_REQUEST_KINDS = [
48
46
  "hello",
@@ -455,27 +453,13 @@ function replyOutcome(data) {
455
453
  const message = typeof error.message === "string" ? error.message : error.code;
456
454
  return { error: new EditingPortError(error.code, message) };
457
455
  }
458
- /** The port this frame handed over, "ready" when its runtime came up, else null. */
459
- function readHandoff(event, frame) {
460
- const data = event.data;
461
- if (!frame || event.source !== frame || !isPlainRecord(data) || data.source !== "hf-preview") {
462
- return null;
463
- }
464
- if (data.type === "ready")
465
- return "ready";
466
- return data.type === EDITING_PORT && data.v === EDITING_PROTOCOL_VERSION
467
- ? onlyPort(event.ports)
468
- : null;
469
- }
470
- const onlyPort = (ports) => ports.length === 1 ? (ports[0] ?? null) : null;
471
- const portsTaken = new WeakSet();
472
456
  /**
473
- * The parent's end of the editing channel for one preview frame load. Asks for
474
- * the port at once and again on the runtime's `ready`, and takes the first port
475
- * that frame sends. Replies are data from the frame, so callers validate results.
457
+ * The parent's end of the editing channel for one preview frame load: `port` is the runtime's own, which the
458
+ * parent took from the frame's load, or null when that load has none. Replies are data from the frame, so
459
+ * callers validate results.
476
460
  */
477
461
  export function createEditingPortClient(options) {
478
- const { iframe, timeoutMs = EDITING_REQUEST_TIMEOUT_MS, host = window, gate } = options;
462
+ const { timeoutMs = EDITING_REQUEST_TIMEOUT_MS } = options;
479
463
  const pending = new Map();
480
464
  const keyListeners = new Set();
481
465
  const geometryListeners = new Set();
@@ -489,6 +473,8 @@ export function createEditingPortClient(options) {
489
473
  let watchedGeometry = false;
490
474
  let watchedPointer = false;
491
475
  let port = null;
476
+ let held = null;
477
+ let unanswered;
492
478
  let disposed = false;
493
479
  let lastId = 0;
494
480
  let resolveReady;
@@ -530,36 +516,26 @@ export function createEditingPortClient(options) {
530
516
  return settle(data.id, replyOutcome(data));
531
517
  onPush(data);
532
518
  };
533
- const connect = () => {
534
- try {
535
- iframe.contentWindow?.postMessage({ source: "hf-parent", type: EDITING_CONNECT, v: EDITING_PROTOCOL_VERSION }, "*");
536
- }
537
- catch {
538
- // The frame is mid-navigation; its runtime's `ready` asks again.
539
- }
540
- };
541
- const onWindowMessage = (event) => {
542
- const handoff = readHandoff(event, iframe.contentWindow);
543
- if (handoff === "ready")
544
- return connect();
545
- if (!handoff || portsTaken.has(handoff))
546
- return;
547
- portsTaken.add(handoff);
548
- port = handoff;
549
- host.removeEventListener("message", onWindowMessage);
550
- port.onmessage = onReply;
551
- resolveReady();
552
- };
553
- const start = () => {
519
+ void options.port.then((runtime) => {
520
+ if (!runtime)
521
+ return client.dispose();
554
522
  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();
523
+ return runtime.close();
524
+ runtime.onmessage = (event) => {
525
+ if (port === runtime)
526
+ return onReply(event);
527
+ const data = event.data;
528
+ if (port || !isPlainRecord(data) || data.v !== EDITING_PROTOCOL_VERSION || data.ok !== true)
529
+ return;
530
+ port = runtime;
531
+ wallClearTimeout(unanswered);
532
+ resolveReady();
533
+ };
534
+ held = runtime;
535
+ // Waits in the port until the runtime serves it; the reply is what makes this client ready.
536
+ runtime.postMessage({ v: EDITING_PROTOCOL_VERSION, id: ++lastId, kind: "hello", params: {} });
537
+ unanswered = wallSetTimeout(() => port || client.dispose(), timeoutMs);
538
+ });
563
539
  const client = {
564
540
  ready,
565
541
  request(kind, params, requestOptions) {
@@ -638,7 +614,6 @@ export function createEditingPortClient(options) {
638
614
  canvasKeyActionListeners.clear();
639
615
  stageReadyListeners.clear();
640
616
  stageInputListeners.clear();
641
- host.removeEventListener("message", onWindowMessage);
642
617
  if (watchedGeometry) {
643
618
  const stop = { kind: "watch-geometry", params: { handles: [] } };
644
619
  port?.postMessage({ v: EDITING_PROTOCOL_VERSION, id: ++lastId, ...stop });
@@ -647,7 +622,8 @@ export function createEditingPortClient(options) {
647
622
  const stop = { kind: "watch-pointer", params: { point: null } };
648
623
  port?.postMessage({ v: EDITING_PROTOCOL_VERSION, id: ++lastId, ...stop });
649
624
  }
650
- port?.close();
625
+ held?.close();
626
+ wallClearTimeout(unanswered);
651
627
  rejectReady(new EditingPortError("disposed", "client disposed"));
652
628
  for (const id of [...pending.keys()]) {
653
629
  settle(id, { error: new EditingPortError("disposed", "client disposed") });
@@ -46,6 +46,7 @@ export interface HfProtocol {
46
46
  setPausedVideoFrameProvider?: (provider: PausedVideoFrameProvider | null) => void;
47
47
  setLoopStart?: (seconds: number | null) => void;
48
48
  redraws?: number;
49
+ draftDraws?: (element: Element, part: "translate" | "size" | "rotate") => boolean;
49
50
  audioMeter?: {
50
51
  start(): void;
51
52
  stop(): void;
@@ -21,6 +21,13 @@ declare global {
21
21
  }
22
22
  }
23
23
  type ProxyTrigger = "proactive" | "reactive" | "tertiary" | "light";
24
+ /** Wires the preview playback clock into proxy polling so the server caps concurrency while playing. */
25
+ export declare function setProxyPlayingReader(read: () => boolean): void;
26
+ type LightCopyOptions = {
27
+ background?: boolean;
28
+ trackCopy?: boolean;
29
+ onSettled?: () => void;
30
+ };
24
31
  /** The host reports how large it shows this document; copies too small for it are replaced. */
25
32
  export declare function setProxyDisplayScale(scale: number): void;
26
33
  /**
@@ -39,7 +46,7 @@ export declare function playsItsFileUntilCopy(el: HTMLMediaElement): boolean;
39
46
  /** Each media tick re-decides a clip whose copy is still being made: the one on screen plays its own file, and every
40
47
  * other, one that played its file and left the screen included, is held, so at most one oversized file decodes. */
41
48
  export declare function decideFileTurn(el: HTMLMediaElement, onScreen: boolean): void;
42
- export declare function swapToProxy(el: HTMLMediaElement, entry?: MediaCodecMapEntry | null, trigger?: ProxyTrigger, lightFacts?: PreviewSourceFacts): void;
49
+ export declare function swapToProxy(el: HTMLMediaElement, entry?: MediaCodecMapEntry | null, trigger?: ProxyTrigger, lightFacts?: PreviewSourceFacts, options?: LightCopyOptions): boolean;
43
50
  /**
44
51
  * Proactive trigger: consult the codec map before an element's first
45
52
  * `load()` and swap ahead of time when the browser is known-unlikely to