@hyperframes/core 0.10.6 → 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.
@@ -11,7 +11,7 @@ import { escapeCssString } from "./editingElement.js";
11
11
  import { authoredSrcOf, heldForCopy, heldPosters, inPointOf, recordOpenedAtInPoint, swappedElements, unproxiedSrc, } from "./proxySrc.js";
12
12
  import { giveBackWhenDue, stopMediaDownload } from "./preloadMedia.js";
13
13
  import { restartPlaybackHealth } from "./playbackHealth.js";
14
- import { failedCopyElements, noteCopy, setCopyReportingLevel } from "./previewCopies.js";
14
+ import { copiesReady, dropCopy, failedCopyElements, noteCopy, setCopyReportingLevel, } from "./previewCopies.js";
15
15
  import { waitForServedProxy } from "./proxyWait.js";
16
16
  import { registerSeekCompletion } from "./adapters/seek-dispatch.js";
17
17
  import { formatPreviewProxyBox, isHeavyForPreview, isOversizedForPreview, isPreviewQuality, PREVIEW_QUALITY_LEVELS, PREVIEW_PROXY_BOX_PARAM, PREVIEW_PROXY_LIGHT_PARAM, PREVIEW_PROXY_RETRY_PARAM, PREVIEW_PROXY_STILL_PARAM, quantizePreviewProxyBox, scalePreviewProxyBox, wantsLighterCopy, } from "../previewProxyBox.js";
@@ -33,6 +33,16 @@ const unavailableDiagnosedElements = new WeakSet();
33
33
  const proxyRequested = new WeakMap();
34
34
  // Below 1, heavy files get lighter copies at the shown box times this level; at 1, files oversized for their box.
35
35
  let previewQuality = 1;
36
+ let isPreviewPlaying = () => false;
37
+ let deferredLightQueue = [];
38
+ let deferredLightLevel = 1;
39
+ let deferredDraining = false;
40
+ let deferredDrainGen = 0;
41
+ const backgroundLightJobs = new WeakSet();
42
+ /** Wires the preview playback clock into proxy polling so the server caps concurrency while playing. */
43
+ export function setProxyPlayingReader(read) {
44
+ isPreviewPlaying = read;
45
+ }
36
46
  // Elements whose next ask for a copy tells the server to forget its failure first.
37
47
  const retryNext = new WeakSet();
38
48
  // How large the host shows this document, in its CSS pixels per ours (player fit x page zoom).
@@ -78,25 +88,28 @@ function codecEntryOf(el) {
78
88
  return map && key !== null ? lookupCodecMapEntry(key, map) : null;
79
89
  }
80
90
  // fallow-ignore-next-line complexity
81
- function keepSized(el, scale) {
91
+ function keepSized(el, scale, options = {}) {
82
92
  const copy = boxedElements.get(el);
83
93
  if (!copy)
84
- return;
94
+ return false;
85
95
  if (!el.isConnected || el.getAttribute("src") !== copy.href) {
86
96
  boxedElements.delete(el);
87
- return;
97
+ return false;
88
98
  }
89
99
  const shown = shownBox(el, scale);
90
100
  const lowered = previewQuality < 1;
91
101
  const needed = shown && lowered ? scalePreviewProxyBox(shown, previewQuality) : shown;
92
102
  if (lowered && !needed)
93
- return;
103
+ return false;
94
104
  if (needed && copy.light && lightCopyNoLongerNeeded(el, needed)) {
95
- return restoreOriginal(el);
105
+ restoreOriginal(el);
106
+ return false;
96
107
  }
97
- if (boxCovers(copy.box, needed, lowered))
98
- return dropUnneededCopy(el);
99
- requestBox(el, copy, lowered || !needed ? needed : growOnly(needed, copy.box));
108
+ if (boxCovers(copy.box, needed, lowered)) {
109
+ dropUnneededCopy(el);
110
+ return false;
111
+ }
112
+ return requestBox(el, copy, lowered || !needed ? needed : growOnly(needed, copy.box), options);
100
113
  }
101
114
  function dropUnneededCopy(el) {
102
115
  if (pendingUpgrades.delete(el))
@@ -117,28 +130,54 @@ function growOnly(needed, current) {
117
130
  height: Math.max(needed.height, current.height),
118
131
  };
119
132
  }
120
- function requestBox(el, copy, box) {
133
+ function requestBox(el, copy, box, options = {}) {
121
134
  const href = appendProxyParam(copy.originalSrc, copy.variant, box, copy.light, retryNext.delete(el));
122
135
  if (pendingUpgrades.get(el) === href)
123
- return;
136
+ return false;
124
137
  pendingUpgrades.set(el, href);
138
+ const background = options.background === true;
139
+ const track = () => options.trackCopy !== false || !backgroundLightJobs.has(el);
140
+ if (background && options.trackCopy === false)
141
+ backgroundLightJobs.add(el);
142
+ else
143
+ backgroundLightJobs.delete(el);
125
144
  const wanted = () => pendingUpgrades.get(el) === href && el.isConnected && el.getAttribute("src") === copy.href;
126
- noteCopy(el, "making", null, copy.light);
127
- void waitForServedProxy(href, wanted, (fraction) => wanted() && noteCopy(el, "making", fraction, copy.light), () => isActiveAtPlayhead(el)).then((served) => {
128
- if (wanted())
129
- noteCopy(el, served ? "ready" : "failed", null, copy.light);
130
- if (served && wanted())
131
- loadProxy(el, href, copy.originalSrc, copy.variant, box, copy.light);
145
+ if (track())
146
+ noteCopy(el, "making", null, copy.light);
147
+ void waitForServedProxy(href, wanted, (fraction) => wanted() && track() && noteCopy(el, "making", fraction, copy.light), () => isActiveAtPlayhead(el), background, undefined, isPreviewPlaying)
148
+ .then((served) => {
149
+ if (wanted()) {
150
+ if (track())
151
+ noteCopy(el, served ? "ready" : "failed", null, copy.light);
152
+ if (served)
153
+ loadProxy(el, href, copy.originalSrc, copy.variant, box, copy.light);
154
+ }
155
+ else if (pendingUpgrades.get(el) === href) {
156
+ dropCopy(el);
157
+ }
132
158
  if (pendingUpgrades.get(el) === href)
133
159
  pendingUpgrades.delete(el);
160
+ })
161
+ .finally(() => {
162
+ backgroundLightJobs.delete(el);
163
+ options.onSettled?.();
164
+ scheduleDeferredLightDrain();
134
165
  });
166
+ return true;
135
167
  }
136
168
  /** Puts a video that only got a lighter copy back on its original. */
137
169
  function restoreOriginal(el) {
138
170
  const original = swappedElements.get(el) ?? null;
139
- for (const state of [boxedElements, pendingUpgrades, proxyRequested, swappedElements]) {
171
+ for (const state of [
172
+ boxedElements,
173
+ pendingUpgrades,
174
+ proxyRequested,
175
+ swappedElements,
176
+ backgroundLightJobs,
177
+ ]) {
140
178
  state.delete(el);
141
179
  }
180
+ dropCopy(el);
142
181
  evictMediaSyncState(el);
143
182
  restartPlaybackHealth();
144
183
  if (original === null) {
@@ -446,6 +485,8 @@ export function playsItsFileUntilCopy(el) {
446
485
  /** Each media tick re-decides a clip whose copy is still being made: the one on screen plays its own file, and every
447
486
  * other, one that played its file and left the screen included, is held, so at most one oversized file decodes. */
448
487
  export function decideFileTurn(el, onScreen) {
488
+ if (onScreen && previewQuality < 1)
489
+ promoteOnScreenCopy(el);
449
490
  if (el === playingItsFile && !(onScreen && copyStillComing(el))) {
450
491
  playingItsFile = null;
451
492
  if (copyStillComing(el))
@@ -484,13 +525,23 @@ function holdFrameCaptures(until) {
484
525
  }
485
526
  // fallow-ignore-next-line complexity
486
527
  async function makeCopy(el, job, scale) {
487
- const { originalSrc, originalAttr, variant, lightFacts, level, live, forThisSource, heldForAnother, } = job;
528
+ const { originalSrc, originalAttr, variant, lightFacts, level, background, trackCopy, onSettled, live, forThisSource, heldForAnother, } = job;
529
+ let settled = false;
530
+ const finishCopy = () => {
531
+ if (settled)
532
+ return;
533
+ settled = true;
534
+ backgroundLightJobs.delete(el);
535
+ onSettled?.();
536
+ scheduleDeferredLightDrain();
537
+ };
488
538
  // Asked once the shown size is known, so the copy is made at that size and only once.
489
539
  const shown = scale === null ? null : shownBox(el, scale);
490
540
  const box = shown && level < 1 ? scalePreviewProxyBox(shown, level) : shown;
491
541
  if (lightFacts && !(box && wantsLighterCopy(lightFacts, box, level))) {
492
542
  if (proxyRequested.get(el) === originalAttr)
493
543
  proxyRequested.delete(el);
544
+ finishCopy();
494
545
  return;
495
546
  }
496
547
  if (isVideoElement(el))
@@ -502,13 +553,19 @@ async function makeCopy(el, job, scale) {
502
553
  holdForCopy(el);
503
554
  const proxiedSrc = appendProxyParam(originalSrc, variant, box, lightFacts !== undefined, retryNext.delete(el));
504
555
  const light = lightFacts !== undefined;
505
- noteCopy(el, "making", null, light);
556
+ if (background && !trackCopy)
557
+ backgroundLightJobs.add(el);
558
+ else
559
+ backgroundLightJobs.delete(el);
560
+ const track = () => trackCopy || !backgroundLightJobs.has(el);
561
+ if (track())
562
+ noteCopy(el, "making", null, light);
506
563
  const still = light && !heldForCopy.has(el)
507
564
  ? undefined
508
565
  : () => showStill(el, originalSrc, variant, box, light, forThisSource, proxiedSrc);
509
566
  if (still)
510
567
  stillsWhenDue.set(el, still);
511
- const served = await waitForServedProxy(proxiedSrc, live, (fraction) => noteCopy(el, "making", fraction, light), () => isActiveAtPlayhead(el), false, still);
568
+ const served = await waitForServedProxy(proxiedSrc, live, (fraction) => track() && noteCopy(el, "making", fraction, light), () => isActiveAtPlayhead(el), background, still, isPreviewPlaying);
512
569
  if (stillsWhenDue.get(el) === still)
513
570
  stillsWhenDue.delete(el);
514
571
  const wanted = live();
@@ -517,26 +574,37 @@ async function makeCopy(el, job, scale) {
517
574
  if (copiesMaking.get(el) === forThisSource && !heldForAnother())
518
575
  endCopyHold(el, served && wanted ? null : originalAttr);
519
576
  if (!wanted) {
577
+ dropCopy(el);
520
578
  dropStill(el, forThisSource);
521
579
  if (proxyRequested.get(el) === originalAttr)
522
580
  proxyRequested.delete(el);
523
- if (lightFacts && el.isConnected && el.getAttribute("src") === originalAttr) {
581
+ if (lightFacts &&
582
+ el.isConnected &&
583
+ el.getAttribute("src") === originalAttr &&
584
+ !deferredLightQueue.includes(el)) {
524
585
  applyPreviewQuality(el);
525
586
  }
587
+ finishCopy();
526
588
  return;
527
589
  }
528
590
  if (!served) {
529
591
  dropStill(el, forThisSource);
530
- noteCopy(el, "failed", null, light);
592
+ if (track())
593
+ noteCopy(el, "failed", null, light);
531
594
  emitUnavailableDiagnostic(el, "proxy_playback_failed", originalSrc);
595
+ finishCopy();
532
596
  return;
533
597
  }
534
- noteCopy(el, "ready", null, light);
598
+ const tracked = track();
599
+ if (tracked)
600
+ noteCopy(el, "ready", null, light);
535
601
  swappedElements.set(el, held ? originalAttr : unproxiedSrc(el));
536
602
  loadProxy(el, proxiedSrc, originalSrc, variant, box, lightFacts !== undefined);
537
603
  // The shown size may have grown while this copy was being made.
538
604
  if (displayScale !== null)
539
605
  keepSized(el, displayScale);
606
+ // Transcoding is done once the copy is served; off-screen clips do not wait for loadeddata to drain.
607
+ finishCopy();
540
608
  return copyLoadEnds(el, proxiedSrc).then(() => dropStill(el, forThisSource));
541
609
  }
542
610
  const ENDS_A_LOAD = ["loadeddata", "error", "abort", "emptied"];
@@ -582,12 +650,12 @@ function copyVariant(entry) {
582
650
  return "auto";
583
651
  return entry.hasAlpha ? "vp8" : "h264";
584
652
  }
585
- export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts) {
653
+ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts, options = {}) {
586
654
  if (swappedElements.has(el))
587
- return;
655
+ return false;
588
656
  giveBackWhenDue(el);
589
657
  if (proxyRequested.has(el) && proxyRequested.get(el) === el.getAttribute("src"))
590
- return;
658
+ return false;
591
659
  const originalSrc = currentSrcValue(el);
592
660
  const variant = copyVariant(entry);
593
661
  try {
@@ -596,7 +664,7 @@ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts)
596
664
  catch (err) {
597
665
  swallow("runtime.mediaProxy.swap", err);
598
666
  emitUnavailableDiagnostic(el, "invalid_source_url", originalSrc);
599
- return;
667
+ return false;
600
668
  }
601
669
  const originalAttr = el.getAttribute("src");
602
670
  proxyRequested.set(el, originalAttr);
@@ -611,12 +679,22 @@ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts)
611
679
  return heldForCopy.has(el) ? unproxiedSrc(el) === source : originalAttr === null;
612
680
  };
613
681
  const live = () => forThisSource() && (!lightFacts || previewQuality === level);
682
+ let settled = false;
683
+ const onSettled = () => {
684
+ if (settled)
685
+ return;
686
+ settled = true;
687
+ options.onSettled?.();
688
+ };
614
689
  const job = {
615
690
  originalSrc,
616
691
  originalAttr,
617
692
  variant,
618
693
  lightFacts,
619
694
  level,
695
+ background: options.background === true,
696
+ trackCopy: options.trackCopy !== false,
697
+ onSettled,
620
698
  live,
621
699
  forThisSource,
622
700
  heldForAnother: () => heldForCopy.has(el) && el.getAttribute("src") === null && unproxiedSrc(el) !== source,
@@ -627,9 +705,12 @@ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts)
627
705
  .finally(() => {
628
706
  if (copiesMaking.get(el) === forThisSource)
629
707
  copiesMaking.delete(el);
708
+ backgroundLightJobs.delete(el);
709
+ onSettled();
710
+ scheduleDeferredLightDrain();
630
711
  });
631
712
  if (lightFacts)
632
- return;
713
+ return true;
633
714
  // A frame capture holds for the copy as it held for a loading video before, up to the same cap.
634
715
  holdFrameCaptures(swap);
635
716
  const codecName = entry?.codecName ?? null;
@@ -649,6 +730,7 @@ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts)
649
730
  // matches on (packages/cli/src/utils/checkBrowser.ts); keep it in the text.
650
731
  console.info(`[hyperframes] ${DIAGNOSTIC_FALLBACK_CODE}: "${originalSrc}" uses a codec (${codecName ?? "unknown"}) this browser can't decode; ` +
651
732
  "auto-swapped to an authoring proxy for this preview only. Render output is unaffected.");
733
+ return true;
652
734
  }
653
735
  /**
654
736
  * Proactive trigger: consult the codec map before an element's first
@@ -672,14 +754,15 @@ export function maybeProxyProactively(el) {
672
754
  else
673
755
  lightenIfHeavy(el, entry);
674
756
  }
675
- function lightenIfHeavy(el, entry) {
757
+ function lightenIfHeavy(el, entry, options = {}) {
676
758
  if (swappedElements.has(el) || proxyRequested.has(el))
677
- return;
678
- if (capturePageIn(document))
679
- return holdForCaptureStill(el);
759
+ return false;
760
+ if (capturePageIn(document)) {
761
+ holdForCaptureStill(el);
762
+ return false;
763
+ }
680
764
  const facts = sourceFactsOf(el);
681
- if (facts)
682
- swapToProxy(el, entry, "light", facts);
765
+ return facts ? swapToProxy(el, entry, "light", facts, options) : false;
683
766
  }
684
767
  // Each held clip's own poster, given back with its file; and the one still ask whose answer counts.
685
768
  const captureStills = new WeakMap();
@@ -743,22 +826,84 @@ function decodeItsFile(el, file) {
743
826
  }));
744
827
  endCopyHold(el, file);
745
828
  }
746
- function applyPreviewQuality(el) {
829
+ function applyPreviewQuality(el, options = {}) {
747
830
  if (isRenderMode(el) || !isVideoElement(el))
748
- return;
831
+ return false;
749
832
  if (boxedElements.has(el) && displayScale !== null)
750
- return keepSized(el, displayScale);
751
- lightenIfHeavy(el, codecEntryOf(el));
833
+ return keepSized(el, displayScale, options);
834
+ return lightenIfHeavy(el, codecEntryOf(el), options);
835
+ }
836
+ function promoteOnScreenCopy(el) {
837
+ const index = deferredLightQueue.indexOf(el);
838
+ if (index !== -1) {
839
+ deferredLightQueue.splice(index, 1);
840
+ applyPreviewQuality(el);
841
+ return;
842
+ }
843
+ if (backgroundLightJobs.delete(el)) {
844
+ noteCopy(el, "making", null, true);
845
+ }
846
+ }
847
+ function canDrainDeferredLight() {
848
+ if (deferredDraining || previewQuality !== deferredLightLevel || previewQuality >= 1)
849
+ return false;
850
+ if (!copiesReady() || deferredLightQueue.length === 0)
851
+ return false;
852
+ return ![...document.querySelectorAll("video")].some((el) => copyStillComing(el) && !backgroundLightJobs.has(el));
853
+ }
854
+ /** Drains off-screen lighter copies once copiesReady() is true; a failed copy pauses drain until retry. */
855
+ function scheduleDeferredLightDrain() {
856
+ if (!canDrainDeferredLight())
857
+ return;
858
+ const gen = deferredDrainGen;
859
+ while (deferredLightQueue.length > 0) {
860
+ const next = deferredLightQueue.shift();
861
+ if (!next.isConnected)
862
+ continue;
863
+ deferredDraining = true;
864
+ const started = applyPreviewQuality(next, {
865
+ background: true,
866
+ trackCopy: false,
867
+ onSettled: () => {
868
+ if (gen !== deferredDrainGen)
869
+ return;
870
+ deferredDraining = false;
871
+ scheduleDeferredLightDrain();
872
+ },
873
+ });
874
+ if (started)
875
+ return;
876
+ deferredDraining = false;
877
+ }
752
878
  }
753
879
  /** The host's preview quality: below 1, heavy videos play lighter copies at the shown box times the level. */
754
880
  export function setPreviewQuality(level) {
755
881
  if (!isPreviewQuality(level) || level === previewQuality)
756
882
  return;
757
883
  previewQuality = level;
884
+ deferredLightQueue = [];
885
+ deferredLightLevel = level;
886
+ deferredDraining = false;
887
+ deferredDrainGen += 1;
758
888
  setCopyReportingLevel(level);
759
889
  restartPlaybackHealth();
760
- for (const el of document.querySelectorAll("video"))
761
- applyPreviewQuality(el);
890
+ const videos = [...document.querySelectorAll("video")];
891
+ if (level >= 1) {
892
+ for (const el of videos)
893
+ applyPreviewQuality(el);
894
+ return;
895
+ }
896
+ const onScreen = videos.filter((el) => isActiveAtPlayhead(el));
897
+ const immediate = onScreen.length > 0 ? onScreen : videos.slice(0, 1);
898
+ const immediateSet = new Set(immediate);
899
+ deferredLightQueue = videos.filter((el) => !immediateSet.has(el));
900
+ let started = 0;
901
+ for (const el of immediate) {
902
+ if (applyPreviewQuality(el))
903
+ started += 1;
904
+ }
905
+ if (started === 0)
906
+ scheduleDeferredLightDrain();
762
907
  }
763
908
  /** The lower levels at which at least one video would get a lighter copy, by the same rule that makes them. */
764
909
  export function levelsWithLighterCopies() {
@@ -7,6 +7,7 @@ type CopyState = {
7
7
  export declare function setCopyReportingLevel(level: number): void;
8
8
  export declare function resetCopyReporting(): void;
9
9
  export declare function noteCopy(el: HTMLMediaElement, state: CopyState["state"], progress?: number | null, light?: boolean): void;
10
+ export declare function dropCopy(el: HTMLMediaElement): void;
10
11
  export declare function failedCopyElements(): HTMLMediaElement[];
11
12
  /** True when every lighter copy wanted at this level is ready; true when none are wanted. */
12
13
  export declare function copiesReady(): boolean;
@@ -71,6 +71,11 @@ export function noteCopy(el, state, progress = null, light = true) {
71
71
  copies.set(el, { state, progress, light });
72
72
  scheduleReport();
73
73
  }
74
+ export function dropCopy(el) {
75
+ if (!copies.delete(el))
76
+ return;
77
+ scheduleReport();
78
+ }
74
79
  export function failedCopyElements() {
75
80
  return [...copies].filter(([, copy]) => copy.state === "failed").map(([el]) => el);
76
81
  }
@@ -1,3 +1,3 @@
1
1
  /** Asks for one byte of a `?hf-proxy=` URL until it is served, after each Retry-After: while the
2
2
  * server answers 202 (copy being made) or 503 (queue full), after up to 3 failed asks; a throw is not served. */
3
- export declare function waitForServedProxy(href: string, live: () => boolean, onProgress?: (fraction: number) => void, atPlayhead?: () => boolean, background?: boolean, onAsk?: () => void): Promise<boolean>;
3
+ export declare function waitForServedProxy(href: string, live: () => boolean, onProgress?: (fraction: number) => void, atPlayhead?: () => boolean, background?: boolean, onAsk?: () => void, playing?: () => boolean): Promise<boolean>;
@@ -1,19 +1,22 @@
1
1
  import { wallSetTimeout } from "./wallClock.js";
2
2
  import { capturePageIn } from "../studioPreviewMark.js";
3
- import { PREVIEW_PROXY_PRIORITY_HEADER, PREVIEW_PROXY_PROGRESS_HEADER, PREVIEW_PROXY_RETRY_PARAM, } from "../previewProxyBox.js";
3
+ import { formatProxyPriorityHeader, PREVIEW_PROXY_PRIORITY_HEADER, PREVIEW_PROXY_PROGRESS_HEADER, PREVIEW_PROXY_RETRY_PARAM, } from "../previewProxyBox.js";
4
4
  const MAX_FAILED_ASKS = 3;
5
5
  function withoutRetryFlag(href) {
6
6
  const url = new URL(href, document.baseURI);
7
7
  url.searchParams.delete(PREVIEW_PROXY_RETRY_PARAM);
8
8
  return url.href;
9
9
  }
10
- function askHeaders(atPlayhead, background, onAsk) {
10
+ function askHeaders(atPlayhead, background, playing, onAsk) {
11
11
  onAsk?.();
12
12
  const headers = { Range: "bytes=0-0" };
13
- if (atPlayhead)
14
- headers[PREVIEW_PROXY_PRIORITY_HEADER] = "1";
15
- else if (background)
16
- headers[PREVIEW_PROXY_PRIORITY_HEADER] = "0";
13
+ const urgency = formatProxyPriorityHeader({
14
+ priority: atPlayhead,
15
+ background: !atPlayhead && background,
16
+ playing,
17
+ });
18
+ if (urgency !== undefined)
19
+ headers[PREVIEW_PROXY_PRIORITY_HEADER] = urgency;
17
20
  return headers;
18
21
  }
19
22
  function reportProgress(res, onProgress) {
@@ -24,13 +27,13 @@ function reportProgress(res, onProgress) {
24
27
  }
25
28
  /** Asks for one byte of a `?hf-proxy=` URL until it is served, after each Retry-After: while the
26
29
  * server answers 202 (copy being made) or 503 (queue full), after up to 3 failed asks; a throw is not served. */
27
- export async function waitForServedProxy(href, live, onProgress, atPlayhead = () => false, background = false, onAsk) {
30
+ export async function waitForServedProxy(href, live, onProgress, atPlayhead = () => false, background = false, onAsk, playing = () => false) {
28
31
  let failed = 0;
29
32
  let ask = href;
30
33
  const onUnwatchedCapturePage = capturePageIn(document);
31
34
  try {
32
35
  while (live()) {
33
- const headers = askHeaders(!onUnwatchedCapturePage && atPlayhead(), background || onUnwatchedCapturePage, onAsk);
36
+ const headers = askHeaders(!onUnwatchedCapturePage && atPlayhead(), background || onUnwatchedCapturePage, !onUnwatchedCapturePage && playing(), onAsk);
34
37
  const res = await fetch(ask, { headers, cache: "no-store" }).catch(() => null);
35
38
  ask = withoutRetryFlag(href);
36
39
  void res?.body?.cancel().catch(() => { });
@@ -1,9 +1,9 @@
1
1
  /** Tests only: stand-in ports and events from another realm (jsdom over Node) keep their own methods. */
2
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;
3
+ /** A channel made with the browser's own constructor and getters read at load; null when they could not be read. */
4
+ export declare function openRuntimeChannel(): {
5
+ keep: MessagePort;
6
+ give: MessagePort;
7
7
  } | null;
8
8
  export declare function postOnPort(port: MessagePort, message: unknown, transfer?: Transferable[]): void;
9
9
  export declare function onPortMessage(port: MessagePort, handler: (data: unknown) => void): void;
@@ -61,14 +61,14 @@ function bound(port) {
61
61
  return null;
62
62
  throw new Error("not a runtime port");
63
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))
64
+ /** A channel made with the browser's own constructor and getters read at load; null when they could not be read. */
65
+ export function openRuntimeChannel() {
66
+ if (!NativeMessageChannel || (!native && !standIns))
67
67
  return null;
68
68
  const channel = new NativeMessageChannel();
69
69
  return {
70
- port1: channelPort(channel, native.port1, "port1"),
71
- port2: channelPort(channel, native.port2, "port2"),
70
+ keep: channelPort(channel, native?.port1 ?? null, "port1"),
71
+ give: channelPort(channel, native?.port2 ?? null, "port2"),
72
72
  };
73
73
  }
74
74
  export function postOnPort(port, message, transfer) {
@@ -1,5 +1,6 @@
1
1
  export { TRANSITION_LABEL_PREFIX, transitionLabelsForDocument, } from "./runtime/transitionLabels.js";
2
2
  export declare const STUDIO_PREVIEW_MARK_META = "hyperframes-studio-preview";
3
+ export declare const PREVIEW_DOCUMENT_HANDOFF = "__hfPreviewDocumentSecret";
3
4
  export declare const PREVIEW_SEEK_HOLD_ATTR = "data-hf-preview-seek-hold";
4
5
  export declare const PREVIEW_VIDEO_FRAME_ATTR = "data-hf-preview-video-frame";
5
6
  export declare const PREVIEW_VIDEO_SOURCE_ATTR = "data-hf-preview-video-source";
@@ -1,6 +1,7 @@
1
1
  import { isWebKit } from "./runtime/mediaClock.js";
2
2
  export { TRANSITION_LABEL_PREFIX, transitionLabelsForDocument, } from "./runtime/transitionLabels.js";
3
3
  export const STUDIO_PREVIEW_MARK_META = "hyperframes-studio-preview";
4
+ export const PREVIEW_DOCUMENT_HANDOFF = "__hfPreviewDocumentSecret";
4
5
  export const PREVIEW_SEEK_HOLD_ATTR = "data-hf-preview-seek-hold";
5
6
  export const PREVIEW_VIDEO_FRAME_ATTR = "data-hf-preview-video-frame";
6
7
  export const PREVIEW_VIDEO_SOURCE_ATTR = "data-hf-preview-video-source";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.10.6",
3
+ "version": "0.10.8",
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/studio-server": "0.10.6",
529
- "@hyperframes/lint": "0.10.6",
530
- "@hyperframes/parsers": "0.10.6"
528
+ "@hyperframes/lint": "0.10.8",
529
+ "@hyperframes/studio-server": "0.10.8",
530
+ "@hyperframes/parsers": "0.10.8"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",