Skip to content

Commit a53b813

Browse files
committed
feat(player): loading assets shows the blurred frame and the mark, like Desktop
1 parent 6b3e7a7 commit a53b813

4 files changed

Lines changed: 130 additions & 4 deletions

File tree

‎packages/player/src/shader-loader-element.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ export interface ShaderLoaderElements {
2121
frameRow: HTMLDivElement;
2222
}
2323

24+
const MARK_LEFT =
25+
"M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z";
26+
const MARK_RIGHT =
27+
"M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z";
28+
// The mark's own shape, so the sheen passes over the mark and nothing else.
29+
const MARK_MASK = `url("data:image/svg+xml,${encodeURIComponent(
30+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="${MARK_LEFT}"/><path d="${MARK_RIGHT}"/></svg>`,
31+
)}")`;
32+
2433
export function createShaderLoader(): ShaderLoaderElements {
2534
const root = document.createElement("div");
2635
root.className = "hfp-shader-loader";
@@ -56,8 +65,8 @@ export function createShaderLoader(): ShaderLoaderElements {
5665
markFrame.draggable = false;
5766
markFrame.innerHTML = [
5867
'<svg width="78" height="78" viewBox="0 0 100 100" fill="none" aria-hidden="true" draggable="false">',
59-
'<path d="M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z" fill="url(#hfp-shader-loader-grad-left)"/>',
60-
'<path d="M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z" fill="url(#hfp-shader-loader-grad-right)"/>',
68+
`<path d="${MARK_LEFT}" fill="url(#hfp-shader-loader-grad-left)"/>`,
69+
`<path d="${MARK_RIGHT}" fill="url(#hfp-shader-loader-grad-right)"/>`,
6170
"<defs>",
6271
'<linearGradient id="hfp-shader-loader-grad-left" x1="48.5676" y1="25" x2="44.7804" y2="71.9384" gradientUnits="userSpaceOnUse">',
6372
'<stop stop-color="#06E3FA"/>',
@@ -71,6 +80,12 @@ export function createShaderLoader(): ShaderLoaderElements {
7180
"</svg>",
7281
].join("");
7382

83+
const sheen = document.createElement("div");
84+
sheen.className = "hfp-shader-loader-sheen";
85+
sheen.style.setProperty("mask-image", MARK_MASK);
86+
sheen.style.setProperty("-webkit-mask-image", MARK_MASK);
87+
markFrame.appendChild(sheen);
88+
7489
const titleContainer = document.createElement("div");
7590
titleContainer.className = "hfp-shader-loader-title";
7691
const titleText = document.createElement("span");

‎packages/player/src/shader-loader-state.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,24 @@ describe("shader loader progress rows", () => {
6969
expect(root.getAttribute("aria-label")).toBe("Loading assets");
7070
});
7171
});
72+
73+
describe("Loading assets look", () => {
74+
it("marks the card as the quiet look: mark only, kept for screen readers", () => {
75+
const { state, root } = loader();
76+
state.showAssetsLoading();
77+
expect(root.classList.contains("hfp-assets")).toBe(true);
78+
expect(root.getAttribute("aria-label")).toBe("Loading assets");
79+
expect(root.querySelector(".hfp-shader-loader-sheen")).not.toBeNull();
80+
});
81+
82+
it("gives the panel back to the shader load's text card", () => {
83+
const { state, root } = loader();
84+
state.showAssetsLoading();
85+
state.reset();
86+
expect(root.classList.contains("hfp-assets")).toBe(false);
87+
state.showAssetsLoading();
88+
state.update({ loading: true, ready: false }, "player");
89+
state.hideAssetsLoading();
90+
expect(root.classList.contains("hfp-assets")).toBe(false);
91+
});
92+
});

‎packages/player/src/shader-loader-state.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class ShaderLoaderState {
7171
}
7272
this._el.root.classList.remove("hfp-visible", "hfp-hiding");
7373
this._drawingAssets = false;
74+
this._el.root.classList.remove("hfp-assets");
7475
this._flushHidden();
7576
this._el.fill.style.transform = "scaleX(0)";
7677
setRowValue(this._el.transitionRow, this._el.transitionValue, "");
@@ -94,6 +95,7 @@ export class ShaderLoaderState {
9495
// show; this path owns the label whenever it's the one drawing the panel.
9596
this._el.root.setAttribute("aria-label", "Preparing scene transitions");
9697
this._drawingAssets = false;
98+
this._el.root.classList.remove("hfp-assets");
9799

98100
const progress =
99101
typeof status.progress === "number" && Number.isFinite(status.progress) ? status.progress : 0;
@@ -143,8 +145,8 @@ export class ShaderLoaderState {
143145
this.show();
144146
}
145147

146-
/** Second reason to show the same overlay — reuses the shader-transition
147-
* panel's DOM rather than drawing a second one. */
148+
/** Second reason to show the same overlay, in Desktop's loading look: the mark alone over the
149+
* blurred frame (styles.ts). The words stay as the accessible name, not on screen. */
148150
showAssetsLoading(
149151
title = "Loading assets",
150152
detail = "Waiting for images, video and fonts to finish loading.",
@@ -154,6 +156,7 @@ export class ShaderLoaderState {
154156
this._el.detail.textContent = detail;
155157
this._el.root.setAttribute("aria-label", title);
156158
this._drawingAssets = true;
159+
this._el.root.classList.add("hfp-assets");
157160
this.show();
158161
}
159162

‎packages/player/src/styles.ts‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,93 @@ export const PLAYER_STYLES = /* css */ `
202202
text-align: right;
203203
}
204204
205+
/* Loading assets and Buffering: the frame softly blurred, the mark alone over it with a light
206+
passing over. filter, transform and opacity only, no backdrop-filter, which drops frames on
207+
Safari; the frame is still while it waits, so the blur is painted once. */
208+
.hfp-iframe,
209+
.hfp-poster {
210+
transition: filter 400ms ease-out;
211+
}
212+
213+
:host([assets-loading]:not([assets-loading-ui="none"])) .hfp-iframe,
214+
:host([assets-loading]:not([assets-loading-ui="none"])) .hfp-poster,
215+
:host([buffering]:not([assets-loading-ui="none"])) .hfp-iframe,
216+
:host([buffering]:not([assets-loading-ui="none"])) .hfp-poster {
217+
filter: blur(6px) saturate(0.85);
218+
transition-duration: 180ms;
219+
}
220+
221+
.hfp-shader-loader.hfp-assets {
222+
background: transparent;
223+
}
224+
225+
.hfp-shader-loader.hfp-assets .hfp-shader-loader-panel {
226+
grid-template-rows: auto;
227+
width: auto;
228+
}
229+
230+
.hfp-shader-loader.hfp-assets .hfp-shader-loader-title,
231+
.hfp-shader-loader.hfp-assets .hfp-shader-loader-detail,
232+
.hfp-shader-loader.hfp-assets .hfp-shader-loader-track,
233+
.hfp-shader-loader.hfp-assets .hfp-shader-loader-progress {
234+
display: none;
235+
}
236+
237+
.hfp-shader-loader-mark {
238+
position: relative;
239+
}
240+
241+
.hfp-shader-loader-sheen {
242+
display: none;
243+
position: absolute;
244+
inset: 0;
245+
overflow: hidden;
246+
mask-size: contain;
247+
mask-repeat: no-repeat;
248+
mask-position: center;
249+
-webkit-mask-size: contain;
250+
-webkit-mask-repeat: no-repeat;
251+
-webkit-mask-position: center;
252+
}
253+
254+
.hfp-shader-loader.hfp-assets .hfp-shader-loader-sheen {
255+
display: block;
256+
}
257+
258+
.hfp-shader-loader-sheen::before {
259+
content: "";
260+
position: absolute;
261+
inset: 0 auto 0 -60%;
262+
width: 60%;
263+
background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.85), transparent);
264+
animation: hfp-shader-loader-sweep 1700ms cubic-bezier(0.4, 0, 0.2, 1) infinite;
265+
}
266+
267+
.hfp-shader-loader:not(.hfp-visible):not(.hfp-hiding) .hfp-shader-loader-sheen::before {
268+
animation-play-state: paused;
269+
}
270+
271+
@keyframes hfp-shader-loader-sweep {
272+
0% {
273+
transform: translateX(0);
274+
}
275+
55%,
276+
100% {
277+
transform: translateX(280%);
278+
}
279+
}
280+
281+
@media (prefers-reduced-motion: reduce) {
282+
.hfp-iframe,
283+
.hfp-poster {
284+
transition: none;
285+
}
286+
287+
.hfp-shader-loader-sheen::before {
288+
animation: none;
289+
}
290+
}
291+
205292
@keyframes hfp-shader-loader-sheen {
206293
from {
207294
background-position: 140% 0;

0 commit comments

Comments
 (0)