@hyperframes/core 0.10.0 → 0.10.1

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
@@ -1,4 +1,5 @@
1
- export type { PlaybackHealthReport, PlaybackHeldBy, PlaybackMotionBlurReport, PreviewFrameShape, RuntimeTimelineClipIdentity, } from "./runtime/types.js";
1
+ export type { PlaybackHealthReport, PlaybackHeldBy, PlaybackMotionBlurReport, PreviewFrameShape, RuntimeSeekOptions, RuntimeTimelineClipIdentity, } from "./runtime/types.js";
2
+ export type { HfMediaElement, HfProtocol, HfTransitionMeta } from "./runtime/hfProtocol.js";
2
3
  export type { ExecutionMode, Orientation, Asset, TimelineElement, TimelineElementBase, TimelineMediaElement, TimelineTextElement, TimelineCompositionElement, TimelineElementType, MediaElementType, CanvasResolution, Fps, FpsInput, FpsParseResult, MediaFile, CompositionAPI, PlayerAPI, AddElementData, ValidationResult, CompositionAsset, Keyframe, KeyframeProperties, ElementKeyframes, StageZoom, StageZoomKeyframe, CompositionVariableType, CompositionVariableBase, StringVariable, NumberVariable, ColorVariable, BooleanVariable, EnumVariable, CompositionVariable, CompositionSpec, WaveformData, OutputResolutionCompatibility, OutputResolutionIssueKind, } from "./core.types.js";
3
4
  export type { SlideshowManifest, SlideRef, SlideHotspot, SlideSequence, ResolvedSlide, ResolvedSlideSequence, ResolvedSlideshow, } from "./slideshow/index.js";
4
5
  export { parseSlideshowManifest, resolveSlideshow } from "./slideshow/index.js";
@@ -0,0 +1,48 @@
1
+ import type { HfColorGradingTarget } from "../colorGrading.js";
2
+ export interface RuntimeColorGradingPreviewCandidate {
3
+ id: string;
4
+ grading: unknown;
5
+ }
6
+ export interface RuntimeColorGradingPreviewBatch {
7
+ width: number;
8
+ height: number;
9
+ images: Array<{
10
+ id: string;
11
+ dataUrl: string | null;
12
+ error?: string;
13
+ }>;
14
+ }
15
+ export interface RuntimeColorGradingApi {
16
+ refresh: () => number;
17
+ redraw: () => number;
18
+ redrawAnimated: () => number;
19
+ holdSeekUntilDrawn: () => void;
20
+ waitForActiveLuts: () => Promise<number>;
21
+ setGrading: (target: HfColorGradingTarget | string | null | undefined, rawGrading: unknown) => boolean;
22
+ setCompare: (target: HfColorGradingTarget | string | null | undefined, rawCompare: unknown) => boolean;
23
+ setSourceVisibility: (target: Element, visible: boolean) => boolean;
24
+ isGraded: (target: Element) => boolean;
25
+ getStatus: (target: HfColorGradingTarget | string | null | undefined) => RuntimeColorGradingStatus;
26
+ renderPreviews: (target: HfColorGradingTarget | string | null | undefined, candidates: readonly RuntimeColorGradingPreviewCandidate[], options?: {
27
+ maxDimension?: number;
28
+ useMediaTime?: boolean;
29
+ }) => Promise<RuntimeColorGradingPreviewBatch | null>;
30
+ startPreviewPlayback: (target: HfColorGradingTarget | string | null | undefined) => (() => void) | null;
31
+ destroy: () => void;
32
+ }
33
+ export type RuntimeColorGradingStatus = {
34
+ state: "missing";
35
+ message: string;
36
+ } | {
37
+ state: "inactive";
38
+ message: string;
39
+ } | {
40
+ state: "pending";
41
+ message: string;
42
+ } | {
43
+ state: "active";
44
+ message: string;
45
+ } | {
46
+ state: "unavailable";
47
+ message: string;
48
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import type { RuntimeColorGradingApi } from "./colorGradingApi.js";
2
+ import type { CompositionLengthSource } from "./compositionLength.js";
3
+ import type { PausedVideoFrameProvider } from "./pausedVideoFrames.js";
4
+ import type { RuntimeSeekOptions } from "./types.js";
5
+ /** Media the engine pre-extracts (BeginFrame Chrome cannot play it). Times in seconds; volume 0-1. */
6
+ export interface HfMediaElement {
7
+ elementId: string;
8
+ src: string;
9
+ startTime: number;
10
+ endTime: number;
11
+ mediaOffset?: number;
12
+ volume?: number;
13
+ hasAudio?: boolean;
14
+ }
15
+ /** One shader transition from @hyperframes/shader-transitions, in seconds; no `shader` means a CSS crossfade. */
16
+ export interface HfTransitionMeta {
17
+ time: number;
18
+ duration: number;
19
+ shader?: string;
20
+ ease: string;
21
+ fromScene: string;
22
+ toScene: string;
23
+ }
24
+ /** The engine reads `duration` and calls `seek(time)`, which must draw that time deterministically. */
25
+ export interface HfProtocol {
26
+ colorGrading?: RuntimeColorGradingApi;
27
+ onSwallowed?: (label: string, err: unknown) => void;
28
+ seek?: (timeSeconds: number, options?: RuntimeSeekOptions) => void;
29
+ duration?: number;
30
+ lengthSource?: CompositionLengthSource;
31
+ durationSource?: {
32
+ source: "authored" | "derived" | "unresolved";
33
+ seconds: number | null;
34
+ pendingClips: number;
35
+ };
36
+ /** Where the latest animation's first cycle ends, in seconds (not media or the declared length). */
37
+ animationEnd?: () => number | null;
38
+ /** A clip's span on the composition clock, as the renderer resolves it; end is Infinity for the root. */
39
+ clipWindow?: (el: Element) => {
40
+ start: number;
41
+ end: number;
42
+ } | null;
43
+ /** Lets media play while the transport is paused, out of the runtime's reach; always release. */
44
+ leasePausedMedia?: (el: HTMLMediaElement) => void;
45
+ releasePausedMedia?: (el: HTMLMediaElement) => void;
46
+ setPausedVideoFrameProvider?: (provider: PausedVideoFrameProvider | null) => void;
47
+ setLoopStart?: (seconds: number | null) => void;
48
+ redraws?: number;
49
+ audioMeter?: {
50
+ start(): void;
51
+ stop(): void;
52
+ read(): {
53
+ master: {
54
+ l: number;
55
+ r: number;
56
+ };
57
+ groups: Record<string, {
58
+ l: number;
59
+ r: number;
60
+ }>;
61
+ };
62
+ };
63
+ /** Setup no adapter sees (meshes, shader compiles): runtime and player wait for every promise here. */
64
+ buildReady?: Record<string, PromiseLike<unknown>>;
65
+ media?: HfMediaElement[];
66
+ transitions?: HfTransitionMeta[];
67
+ }
68
+ declare global {
69
+ interface Window {
70
+ __hf?: HfProtocol;
71
+ }
72
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -34,6 +34,7 @@ export declare function setProxyDisplayScale(scale: number): void;
34
34
  * in media.ts).
35
35
  */
36
36
  export declare function isRenderMode(el: HTMLMediaElement): boolean;
37
+ export declare function showStillWhenDue(el: HTMLMediaElement, onScreen: boolean): void;
37
38
  /** Each media tick re-decides a clip whose copy is still being made: the one on screen plays its own file, and every
38
39
  * other, one that played its file and left the screen included, is held, so at most one oversized file decodes. */
39
40
  export declare function decideFileTurn(el: HTMLMediaElement, onScreen: boolean): void;
@@ -305,27 +305,34 @@ export function isRenderMode(el) {
305
305
  return true;
306
306
  return isVideoElement(el) && !!findInjectedRenderFrame(el);
307
307
  }
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.
308
+ // The copy job (its source check) each clip's still is for, and the poster it put up (a URL or a data URL).
309
+ const stillOwners = new WeakMap();
310
310
  const stillPosters = new WeakMap();
311
- const stillHolds = new WeakMap();
311
+ // The still each clip's copy job would put up, asked for on the tick the clip comes on screen, not at its next poll.
312
+ const stillsWhenDue = new WeakMap();
313
+ export function showStillWhenDue(el, onScreen) {
314
+ if (onScreen)
315
+ stillsWhenDue.get(el)?.();
316
+ }
312
317
  /** While a file the browser cannot play is being copied, its own frame at the playhead stands in as the poster. */
313
- function showStill(el, originalSrc, variant, box, light) {
318
+ function showStill(el, originalSrc, variant, box, light, forThisSource, copySrc) {
314
319
  const at = sourceTimeAtPlayhead(el);
315
- if (at === undefined || stills.has(el) || el.hasAttribute("poster"))
320
+ const owned = stillOwners.get(el) === forThisSource;
321
+ if (!forThisSource() || at === undefined || owned || el.hasAttribute("poster"))
316
322
  return;
317
323
  const url = new URL(appendProxyParam(originalSrc, variant, box, light), document.baseURI);
318
324
  url.searchParams.set(PREVIEW_PROXY_STILL_PARAM, at.toFixed(1));
319
- stills.add(el);
325
+ stillOwners.set(el, forThisSource);
320
326
  if (window.origin !== "null")
321
327
  return putUpStill(el, url.href);
322
328
  // 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
329
  void fetch(url.href)
326
330
  .then((res) => (res.ok ? dataUrlOf(res) : null))
327
331
  .then((still) => {
328
- if (still && stillHolds.get(el) === hold && !el.hasAttribute("poster"))
332
+ if (still &&
333
+ stillOwners.get(el) === forThisSource &&
334
+ (forThisSource() || el.getAttribute("src") === copySrc) &&
335
+ !el.hasAttribute("poster"))
329
336
  putUpStill(el, still);
330
337
  })
331
338
  .catch((err) => swallow("runtime.mediaProxy.still", err));
@@ -350,10 +357,10 @@ function pagePoster(el) {
350
357
  const poster = el.getAttribute("poster");
351
358
  return poster !== null && poster === stillPosters.get(el) ? null : poster;
352
359
  }
353
- function dropStill(el) {
354
- if (!stills.delete(el))
360
+ function dropStill(el, owner) {
361
+ if (stillOwners.get(el) !== owner)
355
362
  return;
356
- stillHolds.delete(el);
363
+ stillOwners.delete(el);
357
364
  const poster = stillPosters.get(el);
358
365
  stillPosters.delete(el);
359
366
  if (poster === undefined)
@@ -399,7 +406,7 @@ function emitUnavailableDiagnostic(el, reason, asset) {
399
406
  // text so checkBrowser.ts's console scraper can match a token, not prose.
400
407
  console.info(`[hyperframes] ${DIAGNOSTIC_UNAVAILABLE_CODE}: "${asset}" (${reason}): ${note}`);
401
408
  }
402
- /** Holds `el` with no src while its copy is made (readers still see its file); false with no src to hold. */
409
+ /** Holds `el` with no src while its copy is made; false with no src to hold. Rules: README.md "Hold rules". */
403
410
  function holdForCopy(el, holdsCaptures = true) {
404
411
  const authored = unproxiedSrc(el);
405
412
  if (authored === null)
@@ -472,7 +479,7 @@ function holdFrameCaptures(until) {
472
479
  }
473
480
  // fallow-ignore-next-line complexity
474
481
  async function makeCopy(el, job, scale) {
475
- const { originalSrc, originalAttr, variant, lightFacts, level, live } = job;
482
+ const { originalSrc, originalAttr, variant, lightFacts, level, live, forThisSource, heldForAnother, } = job;
476
483
  // Asked once the shown size is known, so the copy is made at that size and only once.
477
484
  const shown = scale === null ? null : shownBox(el, scale);
478
485
  const box = shown && level < 1 ? scalePreviewProxyBox(shown, level) : shown;
@@ -487,14 +494,21 @@ async function makeCopy(el, job, scale) {
487
494
  const proxiedSrc = appendProxyParam(originalSrc, variant, box, lightFacts !== undefined, retryNext.delete(el));
488
495
  const light = lightFacts !== undefined;
489
496
  noteCopy(el, "making", null, light);
490
- const served = await waitForServedProxy(proxiedSrc, live, (fraction) => noteCopy(el, "making", fraction, light), () => isActiveAtPlayhead(el), false, light && !held ? undefined : () => showStill(el, originalSrc, variant, box, light));
497
+ const still = light && !heldForCopy.has(el)
498
+ ? undefined
499
+ : () => showStill(el, originalSrc, variant, box, light, forThisSource, proxiedSrc);
500
+ if (still)
501
+ stillsWhenDue.set(el, still);
502
+ const served = await waitForServedProxy(proxiedSrc, live, (fraction) => noteCopy(el, "making", fraction, light), () => isActiveAtPlayhead(el), false, still);
503
+ if (stillsWhenDue.get(el) === still)
504
+ stillsWhenDue.delete(el);
491
505
  const wanted = live();
492
506
  if (!served || !wanted)
493
507
  sizedBeforeCopy.delete(el);
494
- if (held)
508
+ if (held && !heldForAnother())
495
509
  endCopyHold(el, served && wanted ? null : originalAttr);
496
510
  if (!wanted) {
497
- dropStill(el);
511
+ dropStill(el, forThisSource);
498
512
  if (proxyRequested.get(el) === originalAttr)
499
513
  proxyRequested.delete(el);
500
514
  if (lightFacts && el.isConnected && el.getAttribute("src") === originalAttr) {
@@ -503,7 +517,7 @@ async function makeCopy(el, job, scale) {
503
517
  return;
504
518
  }
505
519
  if (!served) {
506
- dropStill(el);
520
+ dropStill(el, forThisSource);
507
521
  noteCopy(el, "failed", null, light);
508
522
  emitUnavailableDiagnostic(el, "proxy_playback_failed", originalSrc);
509
523
  return;
@@ -514,7 +528,7 @@ async function makeCopy(el, job, scale) {
514
528
  // The shown size may have grown while this copy was being made.
515
529
  if (displayScale !== null)
516
530
  keepSized(el, displayScale);
517
- return copyLoadEnds(el, proxiedSrc).then(() => dropStill(el));
531
+ return copyLoadEnds(el, proxiedSrc).then(() => dropStill(el, forThisSource));
518
532
  }
519
533
  const ENDS_A_LOAD = ["loadeddata", "error", "abort", "emptied"];
520
534
  const leaving = new Map();
@@ -579,11 +593,25 @@ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts)
579
593
  proxyRequested.set(el, originalAttr);
580
594
  const level = previewQuality;
581
595
  // A lighter copy waits for no level but its own; a copy the file cannot play without finishes at any level.
582
- const live = () => el.isConnected &&
583
- (el.getAttribute("src") === originalAttr ||
584
- (heldForCopy.has(el) && el.getAttribute("src") === null)) &&
585
- (!lightFacts || previewQuality === level);
586
- const job = { originalSrc, originalAttr, variant, lightFacts, level, live };
596
+ const source = unproxiedSrc(el);
597
+ const forThisSource = () => {
598
+ if (!el.isConnected)
599
+ return false;
600
+ if (el.getAttribute("src") !== null)
601
+ return el.getAttribute("src") === originalAttr;
602
+ return heldForCopy.has(el) ? unproxiedSrc(el) === source : originalAttr === null;
603
+ };
604
+ const live = () => forThisSource() && (!lightFacts || previewQuality === level);
605
+ const job = {
606
+ originalSrc,
607
+ originalAttr,
608
+ variant,
609
+ lightFacts,
610
+ level,
611
+ live,
612
+ forThisSource,
613
+ heldForAnother: () => heldForCopy.has(el) && el.getAttribute("src") === null && unproxiedSrc(el) !== source,
614
+ };
587
615
  const swap = shownScale().then((scale) => makeCopy(el, job, scale));
588
616
  if (lightFacts)
589
617
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
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.10.0",
529
- "@hyperframes/parsers": "0.10.0",
530
- "@hyperframes/studio-server": "0.10.0"
528
+ "@hyperframes/lint": "0.10.1",
529
+ "@hyperframes/parsers": "0.10.1",
530
+ "@hyperframes/studio-server": "0.10.1"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",