Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/video-hevc-alpha.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kadal/deck": minor
---

`<Video hevc>`: a transparent clip's HEVC-with-alpha twin for Safari and every iOS browser. WebKit decodes a VP9 WebM's alpha as black, so a Kadal Store overlay (sparks, snow, screentone) showed as an opaque rectangle there; WebKit now plays `hevc` and every other browser keeps `src`. The Kadal Store adds `hevc` to its transparent clips by itself.
1 change: 1 addition & 0 deletions packages/deck/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ A video that knows the slide's clicks: plays on arrival, at a click (`at`), paus
| prop | type | default | |
| --- | --- | --- | --- |
| `src` | `string` | | Video URL (public/ path or https), or `<source>` children. |
| `hevc` | `string` | | The same clip as HEVC with alpha (an MP4 tagged hvc1). Safari and every iOS browser play this one, since they draw a WebM's transparency as black; other browsers keep `src`. |
| `autoplay` | `boolean \| "once"` | | Play when the slide (or `at`, or the enclosing `<Click>`) arrives; "once": only the first time. |
| `at` | `ClickAt` | | The click at which it starts playing (as `<Click at>`); implies `autoplay`. |
| `pauseAt` | `ClickAt` | | The click at which it pauses. |
Expand Down
2 changes: 1 addition & 1 deletion packages/deck/src/catalog/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const GENERATED: GeneratedData = {
{"name":"Typewriter","file":"src/components/content.tsx","props":[{"name":"text","type":{"text":"string","variants":[{"type":"string"}]},"required":true},{"name":"speed","type":{"text":"number","variants":[{"type":"number"}]},"required":false,"default":"35"},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"cursor","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false,"default":"true"}],"description":"Text that types itself out when the slide is shown."},
{"name":"ul","file":"src/components/Click.tsx","props":[{"name":"children","type":{"text":"ReactNode","variants":[]},"required":false},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false}],"openProps":true,"aliasOf":"Ul","description":"Lists keep their markup. `<Clicks>` recognises these two by identity, so it leaves them to step their own items; the class is for the stylesheet."},
{"name":"Ul","file":"src/components/Click.tsx","props":[{"name":"children","type":{"text":"ReactNode","variants":[]},"required":false},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false}],"openProps":true,"description":"Lists keep their markup. `<Clicks>` recognises these two by identity, so it leaves them to step their own items; the class is for the stylesheet."},
{"name":"Video","file":"src/components/Video.tsx","props":[{"name":"src","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"autoplay","type":{"text":"boolean | \"once\"","variants":[{"type":"string","enum":["once"]},{"type":"boolean"}]},"required":false,"description":"Play when the slide (or `at`, or the enclosing `<Click>`) arrives; \"once\": only the first time."},{"name":"at","type":{"text":"ClickAt","variants":[{"type":"string"},{"type":"number"},{"type":"array"}]},"required":false,"description":"The click at which it starts playing (as `<Click at>`); implies `autoplay`."},{"name":"pauseAt","type":{"text":"ClickAt","variants":[{"type":"string"},{"type":"number"},{"type":"array"}]},"required":false,"description":"The click at which it pauses."},{"name":"steps","type":{"text":"Record<string | number, MediaStep>","variants":[{"type":"object"}]},"required":false,"description":"What happens at further clicks: `{ 3: \"pause\", 4: \"play\", 6: 12.5, 8: \"rewind\" }` (absolute clicks)."},{"name":"autoreset","type":{"text":"\"slide\" | \"click\"","variants":[{"type":"string","enum":["slide","click"]}]},"required":false,"description":"\"slide\": back to `timestamp` whenever the slide is left; \"click\": whenever the deck steps back before `at`."},{"name":"timestamp","type":{"text":"string | number","variants":[{"type":"string"},{"type":"number"}]},"required":false,"description":"Start here, in seconds."},{"name":"loop","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false},{"name":"muted","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false,"default":"true"},{"name":"controls","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false,"default":"false"},{"name":"poster","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"printPoster","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The poster in print, the overview and the next-slide box (default `poster`)."},{"name":"printTimestamp","type":{"text":"string | number","variants":[{"type":"string"},{"type":"number"}]},"required":false,"description":"The frame shown in print and previews: seconds, or \"last\". Default `timestamp`."},{"name":"id","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The provider's id for it (\"kse_…\"). Without a provider, `id` is the element's id."},{"name":"lut","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"A `.cube` 3D LUT to grade it with (same origin, or served with CORS)."},{"name":"lutStrength","type":{"text":"number","variants":[{"type":"number"}]},"required":false,"description":"How much of the grade: 0–1 (default 1)."},{"name":"lutCredit","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The grade's own credit (\"Teal Dusk · Film LUTs\"), for `<Credits />`."},{"name":"lutCreditUrl","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The grade's page, for its credit's link."},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"children","type":{"text":"ReactNode","variants":[]},"required":false,"description":"`<source>` elements, captions (`<track>`), fallback text."},{"name":"provider","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Where it came from: \"kadal\" (Kadal's own library), \"kadal-store\" (Kadal Store)."},{"name":"credit","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"A credit of its own (\"Indigo · Seigaiha Waves Pattern\"), on hover and in the deck's credits."},{"name":"creditUrl","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The credit's link (the work's page)."},{"name":"license","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Its licence (\"CC BY 4.0\", \"Kadal Deck licence\"), for the credits."},{"name":"licenseUrl","type":{"text":"string","variants":[{"type":"string"}]},"required":false}],"openProps":true},
{"name":"Video","file":"src/components/Video.tsx","props":[{"name":"src","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"hevc","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The same clip as HEVC with alpha (an MP4 tagged hvc1). Safari and every iOS browser play this one, since they draw a WebM's transparency as black; other browsers keep `src`."},{"name":"autoplay","type":{"text":"boolean | \"once\"","variants":[{"type":"string","enum":["once"]},{"type":"boolean"}]},"required":false,"description":"Play when the slide (or `at`, or the enclosing `<Click>`) arrives; \"once\": only the first time."},{"name":"at","type":{"text":"ClickAt","variants":[{"type":"string"},{"type":"number"},{"type":"array"}]},"required":false,"description":"The click at which it starts playing (as `<Click at>`); implies `autoplay`."},{"name":"pauseAt","type":{"text":"ClickAt","variants":[{"type":"string"},{"type":"number"},{"type":"array"}]},"required":false,"description":"The click at which it pauses."},{"name":"steps","type":{"text":"Record<string | number, MediaStep>","variants":[{"type":"object"}]},"required":false,"description":"What happens at further clicks: `{ 3: \"pause\", 4: \"play\", 6: 12.5, 8: \"rewind\" }` (absolute clicks)."},{"name":"autoreset","type":{"text":"\"slide\" | \"click\"","variants":[{"type":"string","enum":["slide","click"]}]},"required":false,"description":"\"slide\": back to `timestamp` whenever the slide is left; \"click\": whenever the deck steps back before `at`."},{"name":"timestamp","type":{"text":"string | number","variants":[{"type":"string"},{"type":"number"}]},"required":false,"description":"Start here, in seconds."},{"name":"loop","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false},{"name":"muted","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false,"default":"true"},{"name":"controls","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false,"default":"false"},{"name":"poster","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"printPoster","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The poster in print, the overview and the next-slide box (default `poster`)."},{"name":"printTimestamp","type":{"text":"string | number","variants":[{"type":"string"},{"type":"number"}]},"required":false,"description":"The frame shown in print and previews: seconds, or \"last\". Default `timestamp`."},{"name":"id","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The provider's id for it (\"kse_…\"). Without a provider, `id` is the element's id."},{"name":"lut","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"A `.cube` 3D LUT to grade it with (same origin, or served with CORS)."},{"name":"lutStrength","type":{"text":"number","variants":[{"type":"number"}]},"required":false,"description":"How much of the grade: 0–1 (default 1)."},{"name":"lutCredit","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The grade's own credit (\"Teal Dusk · Film LUTs\"), for `<Credits />`."},{"name":"lutCreditUrl","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The grade's page, for its credit's link."},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"children","type":{"text":"ReactNode","variants":[]},"required":false,"description":"`<source>` elements, captions (`<track>`), fallback text."},{"name":"provider","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Where it came from: \"kadal\" (Kadal's own library), \"kadal-store\" (Kadal Store)."},{"name":"credit","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"A credit of its own (\"Indigo · Seigaiha Waves Pattern\"), on hover and in the deck's credits."},{"name":"creditUrl","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"The credit's link (the work's page)."},{"name":"license","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Its licence (\"CC BY 4.0\", \"Kadal Deck licence\"), for the credits."},{"name":"licenseUrl","type":{"text":"string","variants":[{"type":"string"}]},"required":false}],"openProps":true},
{"name":"VStack","file":"src/components/content.tsx","props":[{"name":"children","type":{"text":"ReactNode","variants":[]},"required":false},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"gap","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"CSS gap between the children."},{"name":"align","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Cross-axis alignment (`align-items`): center by default."},{"name":"justify","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Main-axis distribution (`justify-content`): center by default."}],"description":"reveal.js's `r-vstack`: children in a column, centred both ways."},
{"name":"WordCloud","file":"src/live/components.tsx","props":[{"name":"id","type":{"text":"string","variants":[{"type":"string"}]},"required":true},{"name":"question","type":{"text":"string","variants":[{"type":"string"}]},"required":true},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false}]},
{"name":"Youtube","file":"src/components/content.tsx","props":[{"name":"id","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"url","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"autoplay","type":{"text":"boolean","variants":[{"type":"boolean"}]},"required":false},{"name":"start","type":{"text":"number","variants":[{"type":"number"}]},"required":false},{"name":"className","type":{"text":"string","variants":[{"type":"string"}]},"required":false},{"name":"poster","type":{"text":"string","variants":[{"type":"string"}]},"required":false,"description":"Stands in for the player in print, the overview and while it loads."}],"description":"A YouTube video, through the privacy-enhanced player. `deck export` captures its poster."},
Expand Down
43 changes: 41 additions & 2 deletions packages/deck/src/components/Video.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ReactNode, useEffect, useRef, useState } from "react";
import { type ReactNode, useEffect, useRef, useState, useSyncExternalStore } from "react";

import type { ClickAt } from "../core/clicks.ts";
import { useSlideOptional } from "../react/context.ts";
Expand Down Expand Up @@ -46,6 +46,11 @@ import {
* arrival and pauses on leaving, through the slide's own media handling (and the deck's
* `autoPlayMedia`).
*
* A transparent clip ships as a VP9 WebM, whose alpha WebKit (Safari, and every browser on iOS)
* decodes as black. `hevc` names the same clip as HEVC with alpha, the one form WebKit shows
* transparent; WebKit gets that, everything else keeps `src`. Not by `canPlayType`: Safari says
* "probably" to VP9 and drops its alpha, and Chrome on a Mac plays HEVC but drops its alpha too.
*
* Credited like a sticker (`provider`, `id`, `credit`, `creditUrl`, `license`, `licenseUrl`): on
* hover, and in `<Credits />`. `lut` grades it with a `.cube` LUT (components/lut-video.ts) — the
* poster as an image, the frames on a canvas over the video while it plays.
Expand All @@ -58,6 +63,11 @@ export { playingAt, seekCrossing };

export interface VideoProps extends MediaCreditProps {
src?: string;
/**
* The same clip as HEVC with alpha (an MP4 tagged hvc1). Safari and every iOS browser play this
* one, since they draw a WebM's transparency as black; other browsers keep `src`.
*/
hevc?: string;
/** Play when the slide (or `at`, or the enclosing `<Click>`) arrives; "once": only the first time. */
autoplay?: boolean | "once";
/** The click at which it starts playing (as `<Click at>`); implies `autoplay`. */
Expand Down Expand Up @@ -94,8 +104,28 @@ export interface VideoProps extends MediaCreditProps {
[key: string]: unknown;
}

/**
* WebKit without Blink or Gecko: Safari, and iOS's Chrome (CriOS), Firefox (FxiOS) and Edge, which
* all run WebKit. A Blink or Gecko browser says so in its own token, desktop Firefox has no
* AppleWebKit at all.
*/
export function wantsHevcAlpha(ua: string): boolean {
return /AppleWebKit\//.test(ua) && !/(?:Chrome|Chromium|Edg|OPR|Firefox)\//.test(ua);
}

const noSubscribe = () => () => {};
/** False on the server and while hydrating, so the markup matches; the browser's answer after. */
function useWantsHevc(): boolean {
return useSyncExternalStore(
noSubscribe,
() => typeof navigator !== "undefined" && wantsHevcAlpha(navigator.userAgent),
() => false,
);
}

export function Video({
src,
src: webSrc,
hevc,
autoplay,
at,
pauseAt,
Expand Down Expand Up @@ -125,6 +155,8 @@ export function Video({
const slide = useSlideOptional();
const where = useRenderContext();
const ref = useRef<HTMLVideoElement>(null);
const wantsHevc = useWantsHevc();
const src = hevc && wantsHevc ? hevc : webSrc;
const frame = useRef<HTMLSpanElement>(null);
const played = useRef(false);
const lastClick = useRef<number | null>(null);
Expand Down Expand Up @@ -218,6 +250,13 @@ export function Video({
poster: noPlay ? !!printPoster && printTimestamp === undefined : !!poster,
});

// The source changed after the slide handed it out (WebKit learns it wants `hevc` once
// hydrated): load the new one.
useEffect(() => {
const v = ref.current;
if (v && src && v.getAttribute("src") && v.getAttribute("src") !== src) v.setAttribute("src", src);
}, [src]);

const own = stickerCredit({ provider, credit, creditUrl });
const report = useReportHref(own ? src : undefined);
const video = (
Expand Down
43 changes: 42 additions & 1 deletion packages/deck/src/components/store-media.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Lottie, lottieStillFrame } from "./Lottie.tsx";
import { crossesPlay } from "./media-clicks.ts";
import { stickerCredit } from "./media.tsx";
import { Model, modelAttributes, modelPlace } from "./Model.tsx";
import { Video } from "./Video.tsx";
import { Video, wantsHevcAlpha } from "./Video.tsx";

/**
* Just enough of a deck and a slide for the media components: a mode, a config, a click
Expand Down Expand Up @@ -100,6 +100,47 @@ describe("credits on hover", () => {
});
});

describe("<Video hevc>", () => {
test("WebKit takes the HEVC-alpha clip; Blink and Gecko keep the WebM", () => {
const UA = {
safari:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15",
iosSafari:
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1",
iosChrome:
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/131.0.6778.73 Mobile/15E148 Safari/604.1",
iosFirefox:
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/132.0 Mobile/15E148 Safari/605.1.15",
macChrome:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
macEdge:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
android:
"Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36",
firefox: "Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:132.0) Gecko/20100101 Firefox/132.0",
};
expect(
Object.fromEntries(Object.entries(UA).map(([k, ua]) => [k, wantsHevcAlpha(ua)])),
).toEqual({
safari: true,
iosSafari: true,
iosChrome: true,
iosFirefox: true,
macChrome: false,
macEdge: false,
android: false,
firefox: false,
});
});

test("rendered on the server (and while hydrating) it names the WebM, as every browser starts", () => {
const html = render(<Video src="/a.webm" hevc="/a.mp4" autoplay loop />).html;
expect(html).toContain('data-src="/a.webm"');
expect(html).not.toContain("/a.mp4");
expect(html).not.toContain("hevc=");
});
});

describe("<Audio>", () => {
test("a sound on a click: a step of the slide, invisible, run by itself", () => {
const { html, registry } = render(<Audio src="/whoosh.mp3" at={2} {...STORE} />);
Expand Down
1 change: 1 addition & 0 deletions skills/kadal-deck/references/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ A video that knows the slide's clicks: plays on arrival, at a click (`at`), paus
| prop | type | default | |
| --- | --- | --- | --- |
| `src` | `string` | | Video URL (public/ path or https), or `<source>` children. |
| `hevc` | `string` | | The same clip as HEVC with alpha (an MP4 tagged hvc1). Safari and every iOS browser play this one, since they draw a WebM's transparency as black; other browsers keep `src`. |
| `autoplay` | `boolean \| "once"` | | Play when the slide (or `at`, or the enclosing `<Click>`) arrives; "once": only the first time. |
| `at` | `ClickAt` | | The click at which it starts playing (as `<Click at>`); implies `autoplay`. |
| `pauseAt` | `ClickAt` | | The click at which it pauses. |
Expand Down
Loading