@hyperframes/core 0.8.194 → 0.8.195

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.
@@ -0,0 +1,8 @@
1
+ /** The visibility pass's mark on a timed clip it hides; the runtime's rules hide the clip's contents by it. */
2
+ export declare const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
3
+ /** Shows a clip the visibility pass hid, contents included; returns a function that puts the mark back. */
4
+ export declare function revealClip(el: HTMLElement, priority?: string): () => void;
5
+ /** Called by shader-transitions builds on load: their revealers go through revealClip. */
6
+ export declare function declareClipRevealAware(): void;
7
+ /** A shader-transitions build is on the page whose revealers predate revealClip. */
8
+ export declare function olderShaderBuildOnPage(): boolean;
@@ -0,0 +1,23 @@
1
+ /** The visibility pass's mark on a timed clip it hides; the runtime's rules hide the clip's contents by it. */
2
+ export const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
3
+ /** Shows a clip the visibility pass hid, contents included; returns a function that puts the mark back. */
4
+ export function revealClip(el, priority = "") {
5
+ el.style.setProperty("visibility", "visible", priority);
6
+ if (!el.hasAttribute(CLIP_HIDDEN_ATTR))
7
+ return () => { };
8
+ el.removeAttribute(CLIP_HIDDEN_ATTR);
9
+ return function putClipHiddenMarkBack() {
10
+ el.setAttribute(CLIP_HIDDEN_ATTR, "");
11
+ };
12
+ }
13
+ /** Called by shader-transitions builds on load: their revealers go through revealClip. */
14
+ export function declareClipRevealAware() {
15
+ if (typeof window !== "undefined")
16
+ window.__hfClipRevealAware = true;
17
+ }
18
+ /** A shader-transitions build is on the page whose revealers predate revealClip. */
19
+ export function olderShaderBuildOnPage() {
20
+ const win = window;
21
+ const shaderOnPage = win.HyperShader !== undefined || win.__hf?.transitions !== undefined;
22
+ return shaderOnPage && win.__hfClipRevealAware !== true;
23
+ }
@@ -1,5 +1,6 @@
1
- export declare const SKIPPED_CLIP = "[data-start]:not(video, audio, img, [data-hf-upcoming], [data-hf-autostamped])[style*=\"visibility: hidden\"]";
2
- export declare const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
1
+ import { CLIP_HIDDEN_ATTR } from "./clipReveal.js";
2
+ export { CLIP_HIDDEN_ATTR };
3
+ export declare const SKIPPED_CLIP = "[data-start]:not(video, audio, img, [data-hf-upcoming], [data-hf-autostamped])[data-hf-clip-hidden]";
3
4
  export declare function showHiddenClips(): () => void;
4
5
  export declare function defersMedia(): boolean;
5
6
  /** True in Studio's preview, where hidden clips' images are neither fetched nor decoded until due. */
@@ -7,3 +8,4 @@ export declare function skipsHiddenImages(): boolean;
7
8
  export declare function hideTimedClipsUntilFirstPass(): void;
8
9
  /** True when this call lifted the rule; callers then re-register what skipped hidden elements (grading). */
9
10
  export declare function revealTimedClipsAfterFirstPass(): boolean;
11
+ export declare function keepInlineHideRulesForOlderShaders(): void;
@@ -1,3 +1,4 @@
1
+ import { CLIP_HIDDEN_ATTR, olderShaderBuildOnPage, revealClip } from "./clipReveal.js";
1
2
  import { RUNTIME_STAMPED_ATTR, STUDIO_PREVIEW_CAPTURE_MODE, STUDIO_PREVIEW_MARK_META, STUDIO_PREVIEW_UPCOMING_ATTR, } from "../studioPreviewMark.js";
2
3
  // Hides timed non-media clips from script evaluation until the first visibility pass decides them;
3
4
  // before it, a paused page painted every clip at once. Media is left to init's media pass.
@@ -6,24 +7,28 @@ const HIDE_ATTR = "data-hf-first-pass-hide";
6
7
  const HIDE_UNTIL_FIRST_PASS = "[data-start]:not(video, audio, img) { visibility: hidden !important; }";
7
8
  const PREVIEW_HIDE_UNTIL_FIRST_PASS = 'img[loading="lazy"] { display: none !important; }';
8
9
  const SKIP_ATTR = "data-hf-skip-hidden-images";
9
- export const SKIPPED_CLIP = `[data-start]:not(video, audio, img, [${STUDIO_PREVIEW_UPCOMING_ATTR}], [${RUNTIME_STAMPED_ATTR}])[style*="visibility: hidden"]`;
10
- const SKIP_HIDDEN_IMAGES = `${SKIPPED_CLIP} img { display: none !important; }`;
10
+ export { CLIP_HIDDEN_ATTR };
11
+ const SKIPPABLE_CLIP = `[data-start]:not(video, audio, img, [${STUDIO_PREVIEW_UPCOMING_ATTR}], [${RUNTIME_STAMPED_ATTR}])`;
12
+ export const SKIPPED_CLIP = `${SKIPPABLE_CLIP}[${CLIP_HIDDEN_ATTR}]`;
11
13
  const STUDIO_PREVIEW_MARK = `meta[name="${STUDIO_PREVIEW_MARK_META}"]`;
12
- export const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
13
14
  const CONTENTS_ATTR = "data-hf-hidden-clip-contents";
14
- const HIDDEN_CLIP = `[${CLIP_HIDDEN_ATTR}][style*="visibility: hidden"]`;
15
- const HIDE_HIDDEN_CLIP_CONTENTS = `${HIDDEN_CLIP} * { visibility: hidden !important; }`;
16
- const FILTER_OUTPUT_LAYERS = [HIDDEN_CLIP, `${HIDDEN_CLIP} *`]
17
- .flatMap((layer) => [layer, `${layer}::before`, `${layer}::after`])
18
- .join(", ");
19
- const HIDE_FILTER_OUTPUT = `${FILTER_OUTPUT_LAYERS} { filter: none !important; }`;
15
+ const HIDDEN_CLIP_DOUBLED_FOR_WEIGHT = `[${CLIP_HIDDEN_ATTR}][${CLIP_HIDDEN_ATTR}]`;
16
+ const HIDDEN_CLIP_BY_INLINE_STYLE = `[${CLIP_HIDDEN_ATTR}][style*="visibility: hidden"]`;
17
+ const skipHiddenImages = (clip) => `${SKIPPABLE_CLIP}${clip} img { display: none !important; }`;
18
+ const hideHiddenClipContents = (clip) => {
19
+ const filterOutputLayers = [clip, `${clip} *`]
20
+ .flatMap((layer) => [layer, `${layer}::before`, `${layer}::after`])
21
+ .join(", ");
22
+ return `${clip} * { visibility: hidden !important; } ${filterOutputLayers} { filter: none !important; }`;
23
+ };
20
24
  export function showHiddenClips() {
21
25
  const hidden = Array.from(document.querySelectorAll(`[${CLIP_HIDDEN_ATTR}]`));
22
- for (const el of hidden)
23
- el.style.visibility = "visible";
26
+ const putMarksBack = hidden.map((el) => revealClip(el));
24
27
  return () => {
25
28
  for (const el of hidden)
26
29
  el.style.visibility = "hidden";
30
+ for (const putMarkBack of putMarksBack)
31
+ putMarkBack();
27
32
  };
28
33
  }
29
34
  function appendStyle(parent, attr, css) {
@@ -49,9 +54,9 @@ export function hideTimedClipsUntilFirstPass() {
49
54
  const preview = mark !== null;
50
55
  const capture = mark?.getAttribute("content") === STUDIO_PREVIEW_CAPTURE_MODE;
51
56
  if (preview && !capture && !skipsHiddenImages())
52
- appendStyle(parent, SKIP_ATTR, SKIP_HIDDEN_IMAGES);
57
+ appendStyle(parent, SKIP_ATTR, skipHiddenImages(HIDDEN_CLIP_DOUBLED_FOR_WEIGHT));
53
58
  if (!document.querySelector(`style[${CONTENTS_ATTR}]`))
54
- appendStyle(parent, CONTENTS_ATTR, `${HIDE_HIDDEN_CLIP_CONTENTS} ${HIDE_FILTER_OUTPUT}`);
59
+ appendStyle(parent, CONTENTS_ATTR, hideHiddenClipContents(HIDDEN_CLIP_DOUBLED_FOR_WEIGHT));
55
60
  const win = window;
56
61
  // A runtime that already initialised may never run another pass to lift a new rule.
57
62
  if (win.__hfFirstPassHidden || win.__hyperframeRuntimeBootstrapped)
@@ -72,3 +77,13 @@ export function revealTimedClipsAfterFirstPass() {
72
77
  style.remove();
73
78
  return true;
74
79
  }
80
+ export function keepInlineHideRulesForOlderShaders() {
81
+ if (!olderShaderBuildOnPage())
82
+ return;
83
+ const skip = document.querySelector(`style[${SKIP_ATTR}]`);
84
+ if (skip)
85
+ skip.textContent = skipHiddenImages(HIDDEN_CLIP_BY_INLINE_STYLE);
86
+ const contents = document.querySelector(`style[${CONTENTS_ATTR}]`);
87
+ if (contents)
88
+ contents.textContent = hideHiddenClipContents(HIDDEN_CLIP_BY_INLINE_STYLE);
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.8.194",
3
+ "version": "0.8.195",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -265,6 +265,10 @@
265
265
  "import": "./dist/runtime/clipWindow.js",
266
266
  "types": "./dist/runtime/clipWindow.d.ts"
267
267
  },
268
+ "./runtime/clip-reveal": {
269
+ "import": "./dist/runtime/clipReveal.js",
270
+ "types": "./dist/runtime/clipReveal.d.ts"
271
+ },
268
272
  "./runtime/stacking-context": {
269
273
  "import": "./dist/runtime/stackingContext.js",
270
274
  "types": "./dist/runtime/stackingContext.d.ts"
@@ -393,9 +397,9 @@
393
397
  "linkedom": "^0.18.12",
394
398
  "postcss": "^8.5.8",
395
399
  "wawoff2": "^2.0.1",
396
- "@hyperframes/lint": "0.8.194",
397
- "@hyperframes/parsers": "0.8.194",
398
- "@hyperframes/studio-server": "0.8.194"
400
+ "@hyperframes/lint": "0.8.195",
401
+ "@hyperframes/parsers": "0.8.195",
402
+ "@hyperframes/studio-server": "0.8.195"
399
403
  },
400
404
  "devDependencies": {
401
405
  "@fontsource/archivo-black": "^5.2.8",