@hyperframes/core 0.10.1 → 0.10.4

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.
@@ -43,6 +43,7 @@ export type StageActParams = {
43
43
  acts: StageActHold[];
44
44
  deferred: boolean;
45
45
  caretColor: string;
46
+ expiresAt?: number | undefined;
46
47
  } | {
47
48
  op: "frame";
48
49
  draws: {
@@ -75,6 +76,8 @@ export interface StageActRect {
75
76
  export type StageActResult = {
76
77
  op: "hold";
77
78
  held: StageActHeld[];
79
+ } | {
80
+ op: "late";
78
81
  } | {
79
82
  op: "frame";
80
83
  rects: StageActRect[];
@@ -160,6 +160,7 @@ const parseFrameDraw = (entry) => {
160
160
  const draw = parseDraw(entry.draw);
161
161
  return draw && { key: entry.key, draw };
162
162
  };
163
+ const isExpiry = (value) => value === undefined || isFiniteIn(value, Number.MAX_SAFE_INTEGER);
163
164
  const keyList = (value) => {
164
165
  const keys = list(value, MAX_STAGE_ACTS);
165
166
  return keys?.every(isKey) ? keys : null;
@@ -167,15 +168,17 @@ const keyList = (value) => {
167
168
  const OP_PARSERS = {
168
169
  hold: (params) => {
169
170
  const acts = allParsed(list(params.acts, MAX_STAGE_ACTS)?.map(parseHold));
170
- const { deferred, caretColor } = params;
171
- if (!onlyKeys(params, ["op", "acts", "deferred", "caretColor"]) || !acts)
171
+ const { deferred, caretColor, expiresAt } = params;
172
+ if (!onlyKeys(params, ["op", "acts", "deferred", "caretColor", "expiresAt"]) || !acts)
173
+ return null;
174
+ if (!isExpiry(expiresAt))
172
175
  return null;
173
176
  if (typeof deferred !== "boolean" || !isStageColour(caretColor))
174
177
  return null;
175
178
  // A key held twice would borrow its own first draw and restore that, not the element's values.
176
179
  if (new Set(acts.map((act) => act.key)).size !== acts.length)
177
180
  return null;
178
- return { op: "hold", acts, deferred, caretColor };
181
+ return { op: "hold", acts, deferred, caretColor, expiresAt };
179
182
  },
180
183
  frame: (params) => {
181
184
  const draws = allParsed(list(params.draws, MAX_STAGE_ACTS)?.map(parseFrameDraw));
@@ -427,6 +430,10 @@ function start(doc, params, port, version) {
427
430
  };
428
431
  return { op: "hold", held };
429
432
  }
433
+ function startUnlessParentGaveUp(...args) {
434
+ const [, { expiresAt = Infinity }] = args;
435
+ return Date.now() >= expiresAt ? { op: "late" } : start(...args);
436
+ }
430
437
  function listenStageInputs(view, onInput) {
431
438
  for (const type of STAGE_POINTER_INPUTS)
432
439
  view.addEventListener(type, onInput, true);
@@ -441,7 +448,7 @@ export function stageAct(params, port, version, doc = document) {
441
448
  if (params.op === "capture")
442
449
  return { op: "capture", ghosts: captureStageGhosts(doc, params.targets) };
443
450
  if (params.op === "hold")
444
- return start(doc, params, port, version);
451
+ return startUnlessParentGaveUp(doc, params, port, version);
445
452
  const open = session?.port === port ? session : null;
446
453
  if (params.op === "frame") {
447
454
  const drawn = params.draws.flatMap(({ key, draw }) => {
@@ -26,7 +26,7 @@ export function buildElementLabel(el) {
26
26
  const tag = el.tagName.toLowerCase();
27
27
  const text = renderedTextOf(el, LABEL_SOURCE_CHARS).trim().replace(/\s+/g, " ");
28
28
  const trimLabel = (value, maxChars) => {
29
- const chars = Array.from(value);
29
+ const chars = Array.from(value.slice(0, 2 * (maxChars + 1)));
30
30
  if (chars.length <= maxChars)
31
31
  return value;
32
32
  const kept = chars.slice(0, maxChars - 1).join("");
@@ -35,6 +35,7 @@ export declare function setProxyDisplayScale(scale: number): void;
35
35
  */
36
36
  export declare function isRenderMode(el: HTMLMediaElement): boolean;
37
37
  export declare function showStillWhenDue(el: HTMLMediaElement, onScreen: boolean): void;
38
+ export declare function playsItsFileUntilCopy(el: HTMLMediaElement): boolean;
38
39
  /** Each media tick re-decides a clip whose copy is still being made: the one on screen plays its own file, and every
39
40
  * other, one that played its file and left the screen included, is held, so at most one oversized file decodes. */
40
41
  export declare function decideFileTurn(el: HTMLMediaElement, onScreen: boolean): void;
@@ -437,7 +437,12 @@ function decodesItsFile(el, file) {
437
437
  return mime !== undefined && el.canPlayType(mime) !== "";
438
438
  }
439
439
  let playingItsFile = null;
440
- const copyStillComing = (el) => el.isConnected && !swappedElements.has(el) && proxyRequested.has(el);
440
+ // The copy each clip's job is making, by whether the clip still has that source; a failed or finished job is gone.
441
+ const copiesMaking = new WeakMap();
442
+ const copyStillComing = (el) => el.isConnected && !swappedElements.has(el) && copiesMaking.get(el)?.() === true;
443
+ export function playsItsFileUntilCopy(el) {
444
+ return el === playingItsFile && copyStillComing(el);
445
+ }
441
446
  /** Each media tick re-decides a clip whose copy is still being made: the one on screen plays its own file, and every
442
447
  * other, one that played its file and left the screen included, is held, so at most one oversized file decodes. */
443
448
  export function decideFileTurn(el, onScreen) {
@@ -490,7 +495,11 @@ async function makeCopy(el, job, scale) {
490
495
  }
491
496
  if (isVideoElement(el))
492
497
  sizedBeforeCopy.set(el, sizedByItsFile(el));
493
- const held = lightFacts && box && isOversizedForPreview(lightFacts, box) && holdForCopy(el);
498
+ const held = lightFacts &&
499
+ box &&
500
+ isOversizedForPreview(lightFacts, box) &&
501
+ el !== playingItsFile &&
502
+ holdForCopy(el);
494
503
  const proxiedSrc = appendProxyParam(originalSrc, variant, box, lightFacts !== undefined, retryNext.delete(el));
495
504
  const light = lightFacts !== undefined;
496
505
  noteCopy(el, "making", null, light);
@@ -505,7 +514,7 @@ async function makeCopy(el, job, scale) {
505
514
  const wanted = live();
506
515
  if (!served || !wanted)
507
516
  sizedBeforeCopy.delete(el);
508
- if (held && !heldForAnother())
517
+ if (copiesMaking.get(el) === forThisSource && !heldForAnother())
509
518
  endCopyHold(el, served && wanted ? null : originalAttr);
510
519
  if (!wanted) {
511
520
  dropStill(el, forThisSource);
@@ -612,7 +621,13 @@ export function swapToProxy(el, entry = null, trigger = "reactive", lightFacts)
612
621
  forThisSource,
613
622
  heldForAnother: () => heldForCopy.has(el) && el.getAttribute("src") === null && unproxiedSrc(el) !== source,
614
623
  };
615
- const swap = shownScale().then((scale) => makeCopy(el, job, scale));
624
+ copiesMaking.set(el, forThisSource);
625
+ const swap = shownScale()
626
+ .then((scale) => makeCopy(el, job, scale))
627
+ .finally(() => {
628
+ if (copiesMaking.get(el) === forThisSource)
629
+ copiesMaking.delete(el);
630
+ });
616
631
  if (lightFacts)
617
632
  return;
618
633
  // A frame capture holds for the copy as it held for a loading video before, up to the same cap.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.10.1",
3
+ "version": "0.10.4",
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.1",
529
- "@hyperframes/parsers": "0.10.1",
530
- "@hyperframes/studio-server": "0.10.1"
528
+ "@hyperframes/lint": "0.10.4",
529
+ "@hyperframes/studio-server": "0.10.4",
530
+ "@hyperframes/parsers": "0.10.4"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",