@pathmx/player 0.5.0

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.
package/variants.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { SourceDescription } from "@pathmx/core"
2
+ import type { PlayRoute } from "./route.ts"
3
+
4
+ const PLAY_VARIANTS = new Set([
5
+ "cover",
6
+ "section",
7
+ "quote",
8
+ "fact",
9
+ "full",
10
+ "end",
11
+ ])
12
+
13
+ function playData(value: unknown) {
14
+ return value && typeof value === "object" && !Array.isArray(value)
15
+ ? (value as Readonly<Record<string, unknown>>)
16
+ : undefined
17
+ }
18
+
19
+ /** Project supported Player-only variants onto the rendered presentation frames. */
20
+ export function applyBlockVariants(
21
+ route: PlayRoute,
22
+ description: SourceDescription,
23
+ ) {
24
+ const blocks = route.document.querySelectorAll<HTMLElement>(
25
+ ":scope > section[data-pmx-block]",
26
+ )
27
+ blocks.forEach((block, index) => {
28
+ block.removeAttribute("data-pmx-play-variant")
29
+ const variant = playData(
30
+ description.source.blocks[index]?.data.play,
31
+ )?.variant
32
+ if (typeof variant === "string" && PLAY_VARIANTS.has(variant)) {
33
+ block.dataset.pmxPlayVariant = variant
34
+ }
35
+ })
36
+ }