@olenbetong/synergi-course 2.0.0 → 2.1.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/es/chrome/CategoryHeader.css +28 -0
- package/es/completion/CourseCompletion.css +53 -0
- package/es/completion/CourseCompletion.d.ts +32 -0
- package/es/completion/CourseCompletion.js +60 -0
- package/es/document/cues.d.ts +51 -6
- package/es/document/cues.js +115 -14
- package/es/document/effects.d.ts +30 -0
- package/es/document/effects.js +74 -0
- package/es/document/schema.d.ts +924 -136
- package/es/document/schema.js +139 -5
- package/es/document/validate.d.ts +2 -1
- package/es/document/validate.js +73 -2
- package/es/index.d.ts +6 -2
- package/es/index.js +6 -2
- package/es/media/Media.css +16 -0
- package/es/media/icons.d.ts +1 -0
- package/es/media/icons.js +3 -0
- package/es/player/CoursePlayer.css +58 -0
- package/es/player/CoursePlayer.js +27 -13
- package/es/player/useFullScreen.d.ts +17 -0
- package/es/player/useFullScreen.js +83 -0
- package/es/player/useMediaQuery.d.ts +7 -0
- package/es/player/useMediaQuery.js +16 -0
- package/es/steps/Blocks.d.ts +20 -1
- package/es/steps/Blocks.js +103 -22
- package/es/steps/Markdown.d.ts +7 -1
- package/es/steps/Markdown.js +31 -4
- package/es/steps/RevealMotion.d.ts +29 -0
- package/es/steps/RevealMotion.js +55 -0
- package/es/steps/SlideStepView.d.ts +5 -3
- package/es/steps/SlideStepView.js +38 -15
- package/es/steps/StepBodyProps.d.ts +7 -1
- package/es/steps/StepView.css +328 -12
- package/es/steps/StepView.d.ts +8 -2
- package/es/steps/StepView.js +2 -2
- package/es/steps/motion.d.ts +59 -0
- package/es/steps/motion.js +136 -0
- package/es/transitions/Transitions.css +114 -0
- package/es/transitions/plan.d.ts +66 -0
- package/es/transitions/plan.js +185 -0
- package/es/transitions/playStepTransition.d.ts +23 -0
- package/es/transitions/playStepTransition.js +131 -0
- package/es/types.d.ts +3 -1
- package/package.json +4 -4
- package/src/chrome/CategoryHeader.css +28 -0
- package/src/completion/CourseCompletion.css +53 -0
- package/src/completion/CourseCompletion.test.tsx +45 -0
- package/src/completion/CourseCompletion.tsx +98 -0
- package/src/document/cues.ts +142 -13
- package/src/document/document.test.ts +1 -1
- package/src/document/effects.ts +105 -0
- package/src/document/reveal.test.ts +263 -0
- package/src/document/schema.ts +161 -5
- package/src/document/validate.ts +77 -3
- package/src/index.ts +35 -0
- package/src/media/Media.css +16 -0
- package/src/media/icons.tsx +8 -0
- package/src/player/CoursePlayer.css +58 -0
- package/src/player/CoursePlayer.test.tsx +70 -6
- package/src/player/CoursePlayer.tsx +68 -17
- package/src/player/fullScreen.test.tsx +70 -0
- package/src/player/useFullScreen.ts +91 -0
- package/src/player/useMediaQuery.ts +21 -0
- package/src/steps/Blocks.test.ts +34 -0
- package/src/steps/Blocks.tsx +166 -26
- package/src/steps/Markdown.test.tsx +43 -0
- package/src/steps/Markdown.tsx +42 -4
- package/src/steps/Presence.test.tsx +82 -0
- package/src/steps/RevealMotion.ts +66 -0
- package/src/steps/SlideStepView.tsx +67 -17
- package/src/steps/StepBodyProps.ts +7 -1
- package/src/steps/StepView.css +328 -12
- package/src/steps/StepView.test.tsx +41 -0
- package/src/steps/StepView.tsx +9 -1
- package/src/steps/motion.test.ts +98 -0
- package/src/steps/motion.ts +178 -0
- package/src/steps/visibility.test.ts +24 -0
- package/src/transitions/Transitions.css +114 -0
- package/src/transitions/plan.ts +258 -0
- package/src/transitions/playStepTransition.ts +162 -0
- package/src/transitions/transitions.test.ts +274 -0
- package/src/types.ts +3 -1
- package/es/Transitions.css +0 -55
- package/es/Transitions.d.ts +0 -10
- package/es/Transitions.js +0 -24
- package/src/Transitions.css +0 -55
- package/src/Transitions.ts +0 -35
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* How full screen is done here: `native` asks the browser to show the element on the whole screen
|
|
4
|
+
* (the Fullscreen API, prefixed or not); `immersive` lays the player over the whole page itself,
|
|
5
|
+
* for browsers that only put videos on the screen, such as Safari on iPhone.
|
|
6
|
+
*/
|
|
7
|
+
export function fullScreenKind(doc = document) {
|
|
8
|
+
let webkit = doc;
|
|
9
|
+
let element = doc.documentElement;
|
|
10
|
+
let enabled = doc.fullscreenEnabled === true || webkit.webkitFullscreenEnabled === true;
|
|
11
|
+
let canRequest = typeof element.requestFullscreen === "function" || typeof element.webkitRequestFullscreen === "function";
|
|
12
|
+
return enabled && canRequest ? "native" : "immersive";
|
|
13
|
+
}
|
|
14
|
+
function fullscreenElement(doc) {
|
|
15
|
+
return doc.fullscreenElement ?? doc.webkitFullscreenElement ?? null;
|
|
16
|
+
}
|
|
17
|
+
async function requestNative(element) {
|
|
18
|
+
let target = element;
|
|
19
|
+
if (typeof target.requestFullscreen === "function")
|
|
20
|
+
await target.requestFullscreen();
|
|
21
|
+
else
|
|
22
|
+
await target.webkitRequestFullscreen?.();
|
|
23
|
+
}
|
|
24
|
+
async function exitNative(doc) {
|
|
25
|
+
let webkit = doc;
|
|
26
|
+
if (typeof doc.exitFullscreen === "function")
|
|
27
|
+
await doc.exitFullscreen();
|
|
28
|
+
else
|
|
29
|
+
await webkit.webkitExitFullscreen?.();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The player's full screen: one switch for the learner whichever way the browser does it. Native
|
|
33
|
+
* full screen follows the browser (Escape or the system's back gesture leave it); the immersive
|
|
34
|
+
* mode is left with the same button or Escape, and keeps the page behind it from scrolling.
|
|
35
|
+
*/
|
|
36
|
+
export function useFullScreen(root) {
|
|
37
|
+
let [immersive, setImmersive] = useState(false);
|
|
38
|
+
let [native, setNative] = useState(false);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
let sync = () => setNative(root.current != null && fullscreenElement(document) === root.current);
|
|
41
|
+
document.addEventListener("fullscreenchange", sync);
|
|
42
|
+
document.addEventListener("webkitfullscreenchange", sync);
|
|
43
|
+
return () => {
|
|
44
|
+
document.removeEventListener("fullscreenchange", sync);
|
|
45
|
+
document.removeEventListener("webkitfullscreenchange", sync);
|
|
46
|
+
};
|
|
47
|
+
}, [root]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!immersive)
|
|
50
|
+
return;
|
|
51
|
+
let page = document.documentElement;
|
|
52
|
+
let overflow = page.style.overflow;
|
|
53
|
+
page.style.overflow = "hidden";
|
|
54
|
+
let onKey = (event) => {
|
|
55
|
+
if (event.key === "Escape")
|
|
56
|
+
setImmersive(false);
|
|
57
|
+
};
|
|
58
|
+
document.addEventListener("keydown", onKey);
|
|
59
|
+
return () => {
|
|
60
|
+
page.style.overflow = overflow;
|
|
61
|
+
document.removeEventListener("keydown", onKey);
|
|
62
|
+
};
|
|
63
|
+
}, [immersive]);
|
|
64
|
+
let toggle = useCallback(() => {
|
|
65
|
+
let element = root.current;
|
|
66
|
+
if (!element)
|
|
67
|
+
return;
|
|
68
|
+
if (native) {
|
|
69
|
+
exitNative(document).catch(() => { });
|
|
70
|
+
}
|
|
71
|
+
else if (immersive) {
|
|
72
|
+
setImmersive(false);
|
|
73
|
+
}
|
|
74
|
+
else if (fullScreenKind() === "native") {
|
|
75
|
+
// A refusal (no user gesture, a frame without permission) falls back to the immersive mode
|
|
76
|
+
requestNative(element).catch(() => setImmersive(true));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
setImmersive(true);
|
|
80
|
+
}
|
|
81
|
+
}, [root, native, immersive]);
|
|
82
|
+
return { active: native || immersive, immersive, toggle };
|
|
83
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A phone on its side: little height, so the player's chrome shrinks and the slide's text scales
|
|
3
|
+
* with the height. The stylesheet has the same query for what CSS can do alone.
|
|
4
|
+
*/
|
|
5
|
+
export declare const COMPACT_QUERY = "(orientation: landscape) and (max-height: 500px)";
|
|
6
|
+
/** Whether a media query matches, kept up to date. False where `matchMedia` is missing. */
|
|
7
|
+
export declare function useMediaQuery(query: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A phone on its side: little height, so the player's chrome shrinks and the slide's text scales
|
|
4
|
+
* with the height. The stylesheet has the same query for what CSS can do alone.
|
|
5
|
+
*/
|
|
6
|
+
export const COMPACT_QUERY = "(orientation: landscape) and (max-height: 500px)";
|
|
7
|
+
/** Whether a media query matches, kept up to date. False where `matchMedia` is missing. */
|
|
8
|
+
export function useMediaQuery(query) {
|
|
9
|
+
return useSyncExternalStore((onChange) => {
|
|
10
|
+
if (typeof matchMedia !== "function")
|
|
11
|
+
return () => { };
|
|
12
|
+
let list = matchMedia(query);
|
|
13
|
+
list.addEventListener?.("change", onChange);
|
|
14
|
+
return () => list.removeEventListener?.("change", onChange);
|
|
15
|
+
}, () => typeof matchMedia === "function" && matchMedia(query).matches, () => false);
|
|
16
|
+
}
|
package/es/steps/Blocks.d.ts
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
import { type RevealState } from "../document/cues";
|
|
3
|
-
import type {
|
|
3
|
+
import type { PartEffect } from "../document/effects";
|
|
4
|
+
import type { Block, ContentBlock, ListItem, Timed } from "../document/schema";
|
|
4
5
|
import type { ResolveAsset } from "../types";
|
|
5
6
|
export interface BlocksContext {
|
|
6
7
|
reveal: RevealState;
|
|
7
8
|
resolveAsset: ResolveAsset;
|
|
8
9
|
subtitles: boolean;
|
|
9
10
|
onSubtitlesChange(subtitles: boolean): void;
|
|
11
|
+
/** What the slide's effects do to each part they target, from `getPartEffects`. */
|
|
12
|
+
effects?: ReadonlyMap<string, PartEffect>;
|
|
13
|
+
/** The learner prefers reduced motion: parts change at once. */
|
|
14
|
+
calm?: boolean;
|
|
10
15
|
}
|
|
11
16
|
export declare function Blocks({ blocks, context }: {
|
|
12
17
|
blocks: Array<Block | ContentBlock>;
|
|
13
18
|
context: BlocksContext;
|
|
14
19
|
}): React.JSX.Element;
|
|
20
|
+
type Visibility = "shown" | "pending" | "gone";
|
|
21
|
+
/**
|
|
22
|
+
* A part that has not been revealed yet keeps its place, so the slide does not jump when it
|
|
23
|
+
* appears. A part with `hideAt` is a passing one: it takes no place before it shows or after it
|
|
24
|
+
* has gone, so parts that replace each other in time stand in the same spot.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getVisibility(part: Timed, reveal: RevealState): Visibility;
|
|
27
|
+
type ItemNode = {
|
|
28
|
+
item: ListItem;
|
|
29
|
+
children: ItemNode[];
|
|
30
|
+
};
|
|
31
|
+
/** The flat items as a tree: an indented item belongs to the nearest item above it with a smaller indent. */
|
|
32
|
+
export declare function nestItems(items: ListItem[]): ItemNode[];
|
|
33
|
+
export {};
|
package/es/steps/Blocks.js
CHANGED
|
@@ -7,49 +7,75 @@ import { getLocalizedString } from "../i18n";
|
|
|
7
7
|
import { PlayIcon } from "../media/icons";
|
|
8
8
|
import { VideoPlayer } from "../media/VideoPlayer";
|
|
9
9
|
import { Markdown } from "./Markdown";
|
|
10
|
+
import { aspectRatio, partStyle } from "./motion";
|
|
11
|
+
import { usePresence } from "./RevealMotion";
|
|
10
12
|
export function Blocks({ blocks, context }) {
|
|
11
13
|
return (_jsx(_Fragment, { children: blocks.map((block) => (_jsx(BlockView, { block: block, context: context }, block.id))) }));
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* A part that has not been revealed yet keeps its place, so the slide does not jump when it
|
|
15
|
-
* appears. A part
|
|
17
|
+
* appears. A part with `hideAt` is a passing one: it takes no place before it shows or after it
|
|
18
|
+
* has gone, so parts that replace each other in time stand in the same spot.
|
|
16
19
|
*/
|
|
17
|
-
function getVisibility(part, reveal) {
|
|
20
|
+
export function getVisibility(part, reveal) {
|
|
18
21
|
if (isVisible(part, reveal))
|
|
19
22
|
return "shown";
|
|
20
|
-
|
|
21
|
-
return "gone";
|
|
22
|
-
return "pending";
|
|
23
|
+
return part.hideAt ? "gone" : "pending";
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
25
|
+
function lookClasses(block) {
|
|
26
|
+
return clsx(block.caps && "ob-course-look--caps", block.shadow && "ob-course-look--shadow");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* How a part is drawn now, or null when it is not in the page. A part that goes away fades out
|
|
30
|
+
* first (`leaving`); the slide lifts it out of the flow meanwhile.
|
|
31
|
+
*/
|
|
32
|
+
function usePart(part, context) {
|
|
33
|
+
let visibility = getVisibility(part, context.reveal);
|
|
34
|
+
let presence = usePresence(visibility !== "gone", context.calm ?? false);
|
|
35
|
+
let inPage = presence !== "absent";
|
|
36
|
+
/*
|
|
37
|
+
* The view stays mounted while its part is out of the page, so a part that comes in later is one
|
|
38
|
+
* whose view saw it absent: it fades in. Parts there when the slide is drawn do not.
|
|
39
|
+
*/
|
|
40
|
+
let [cameLate, setCameLate] = useState(false);
|
|
41
|
+
let [wasInPage, setWasInPage] = useState(inPage);
|
|
42
|
+
if (inPage !== wasInPage) {
|
|
43
|
+
setWasInPage(inPage);
|
|
44
|
+
if (inPage)
|
|
45
|
+
setCameLate(true);
|
|
46
|
+
}
|
|
47
|
+
if (!inPage)
|
|
48
|
+
return null;
|
|
49
|
+
let state = presence === "leaving" ? "leaving" : visibility;
|
|
50
|
+
// A part that waits keeps the fade for when it shows; the fade on mount would end unseen
|
|
51
|
+
return { state, entering: cameLate && state !== "pending" };
|
|
52
|
+
}
|
|
53
|
+
function partProps(part, shown, className, context, canvasAspect) {
|
|
54
|
+
let hidden = shown.state !== "shown";
|
|
26
55
|
return {
|
|
27
|
-
className: clsx(className, pending && "is-pending"),
|
|
56
|
+
className: clsx(className, shown.state === "pending" && "is-pending", shown.state === "leaving" && "is-leaving", shown.entering && "is-entering"),
|
|
28
57
|
"data-part": part.id,
|
|
29
|
-
"aria-hidden":
|
|
30
|
-
inert:
|
|
58
|
+
"aria-hidden": hidden || undefined,
|
|
59
|
+
inert: hidden || undefined,
|
|
60
|
+
style: partStyle({ effect: context.effects?.get(part.id), delay: part.delay, state: shown.state, canvasAspect }),
|
|
31
61
|
};
|
|
32
62
|
}
|
|
33
63
|
function BlockView({ block, context }) {
|
|
34
|
-
let
|
|
35
|
-
|
|
64
|
+
let shown = usePart(block, context);
|
|
65
|
+
// An effect shows nothing itself: it acts on its targets through `context.effects`
|
|
66
|
+
if (!shown || block.type === "effect")
|
|
36
67
|
return null;
|
|
37
|
-
let props = partProps(block,
|
|
68
|
+
let props = partProps(block, shown, `ob-course-block ob-course-block--${block.type}`, context);
|
|
38
69
|
switch (block.type) {
|
|
39
70
|
case "heading": {
|
|
40
71
|
let Tag = `h${(block.level ?? 1) + 1}`;
|
|
41
|
-
return (_jsx(Tag, { ...props, className: clsx(props.className, `ob-course-heading--${block.level ?? 1}
|
|
72
|
+
return (_jsx(Tag, { ...props, className: clsx(props.className, `ob-course-heading--${block.level ?? 1}`, lookClasses(block)), children: _jsx(Markdown, { inline: true, children: block.text }) }));
|
|
42
73
|
}
|
|
43
74
|
case "text":
|
|
44
|
-
return (_jsx("div", { ...props, children: _jsx(Markdown, { children: block.text }) }));
|
|
75
|
+
return (_jsx("div", { ...props, className: clsx(props.className, lookClasses(block)), children: _jsx(Markdown, { children: block.text }) }));
|
|
45
76
|
case "list": {
|
|
46
77
|
let Tag = block.ordered ? "ol" : "ul";
|
|
47
|
-
return (_jsx(Tag, { ...props, children: block.items
|
|
48
|
-
let itemVisibility = getVisibility(item, context.reveal);
|
|
49
|
-
if (itemVisibility === "gone")
|
|
50
|
-
return null;
|
|
51
|
-
return (_jsx("li", { ...partProps(item, itemVisibility, "ob-course-list-item"), children: _jsx(Markdown, { className: "ob-course-markdown--inline", children: item.text }) }, item.id));
|
|
52
|
-
}) }));
|
|
78
|
+
return (_jsx(Tag, { ...props, children: _jsx(ListItems, { nodes: nestItems(block.items), context: context }) }));
|
|
53
79
|
}
|
|
54
80
|
case "image":
|
|
55
81
|
return (_jsxs("figure", { ...props, className: clsx(props.className, block.size && `ob-course-image--${block.size}`), "data-size": block.size, children: [_jsx("img", { src: context.resolveAsset(block.src), alt: block.alt ?? "", loading: "lazy" }), block.caption && _jsx("figcaption", { children: block.caption })] }));
|
|
@@ -59,9 +85,64 @@ function BlockView({ block, context }) {
|
|
|
59
85
|
return (_jsx("div", { ...props, "data-color": block.tone ?? "neutral", children: _jsx(Markdown, { children: block.text }) }));
|
|
60
86
|
case "video-link":
|
|
61
87
|
return (_jsx("div", { ...props, children: _jsx(VideoLink, { block: block, context: context }) }));
|
|
88
|
+
case "canvas":
|
|
89
|
+
return (_jsx("div", { ...props, children: _jsx("div", { className: "ob-course-canvas", "data-color-scheme": "light", style: { aspectRatio: block.aspect ?? "16 / 9" }, children: block.items.map((item) => (_jsx(CanvasItemView, { item: item, aspect: aspectRatio(block.aspect), context: context }, item.id))) }) }));
|
|
62
90
|
case "columns":
|
|
63
|
-
return (_jsx("div", { ...props, children: block.columns.map((column) => (_jsx("div", { className: "ob-course-column", "data-part": column.id, children: _jsx(Blocks, { blocks: column.blocks, context: context }) }, column.id))) }));
|
|
91
|
+
return (_jsx("div", { ...props, children: block.columns.map((column) => (_jsx("div", { className: "ob-course-column", "data-part": column.id, style: partStyle({ effect: context.effects?.get(column.id), state: "shown" }), children: _jsx(Blocks, { blocks: column.blocks, context: context }) }, column.id))) }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** The flat items as a tree: an indented item belongs to the nearest item above it with a smaller indent. */
|
|
95
|
+
export function nestItems(items) {
|
|
96
|
+
let roots = [];
|
|
97
|
+
let path = [];
|
|
98
|
+
for (let item of items) {
|
|
99
|
+
// An item cannot be more than one level under the one above it
|
|
100
|
+
let depth = Math.min(item.indent ?? 0, path.length);
|
|
101
|
+
let node = { item, children: [] };
|
|
102
|
+
if (depth === 0)
|
|
103
|
+
roots.push(node);
|
|
104
|
+
else
|
|
105
|
+
path[depth - 1].children.push(node);
|
|
106
|
+
path.length = depth;
|
|
107
|
+
path.push(node);
|
|
108
|
+
}
|
|
109
|
+
return roots;
|
|
110
|
+
}
|
|
111
|
+
function ListItems({ nodes, context }) {
|
|
112
|
+
return nodes.map((node) => _jsx(ListItemView, { node: node, context: context }, node.item.id));
|
|
113
|
+
}
|
|
114
|
+
function ListItemView({ node: { item, children }, context }) {
|
|
115
|
+
let shown = usePart(item, context);
|
|
116
|
+
if (!shown)
|
|
117
|
+
return null;
|
|
118
|
+
return (_jsxs("li", { ...partProps(item, shown, "ob-course-list-item", context), children: [_jsx(Markdown, { inline: true, className: "ob-course-markdown--inline", children: item.text }), children.length > 0 && (_jsx("ul", { className: "ob-course-sublist", children: _jsx(ListItems, { nodes: children, context: context }) }))] }));
|
|
119
|
+
}
|
|
120
|
+
const PLACE_PROPERTIES = {
|
|
121
|
+
x: "left",
|
|
122
|
+
y: "top",
|
|
123
|
+
right: "right",
|
|
124
|
+
bottom: "bottom",
|
|
125
|
+
width: "width",
|
|
126
|
+
height: "height",
|
|
127
|
+
};
|
|
128
|
+
function canvasPlace(item) {
|
|
129
|
+
let style = {};
|
|
130
|
+
for (let [key, property] of Object.entries(PLACE_PROPERTIES)) {
|
|
131
|
+
let value = item[key];
|
|
132
|
+
if (value != null)
|
|
133
|
+
style[property] = `${value}%`;
|
|
134
|
+
}
|
|
135
|
+
return style;
|
|
136
|
+
}
|
|
137
|
+
function CanvasItemView({ item, aspect, context }) {
|
|
138
|
+
let shown = usePart(item, context);
|
|
139
|
+
if (!shown)
|
|
140
|
+
return null;
|
|
141
|
+
let props = partProps(item, shown, `ob-course-canvas__item ob-course-canvas__${item.type}`, context, aspect);
|
|
142
|
+
if (item.type === "image") {
|
|
143
|
+
return (_jsx("img", { ...props, style: { ...canvasPlace(item), ...props.style }, src: context.resolveAsset(item.src), alt: item.alt ?? "" }));
|
|
64
144
|
}
|
|
145
|
+
return (_jsx("div", { ...props, className: clsx(props.className, item.surface && `ob-course-canvas__text--${item.surface}`), "data-color": item.tone, style: { ...canvasPlace(item), ...props.style, "--ob-course-canvas-size": item.size }, children: _jsx(Markdown, { children: item.text }) }));
|
|
65
146
|
}
|
|
66
147
|
function VideoLink({ block, context, }) {
|
|
67
148
|
let [open, setOpen] = useState(false);
|
package/es/steps/Markdown.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/** The tags a text may use for what Markdown has no syntax for. They take no attributes. */
|
|
2
|
+
export declare const TEXT_TAGS: Set<string>;
|
|
3
|
+
/** The colours a `<span data-color>` may name; they come from the theme. */
|
|
4
|
+
export declare const TEXT_TONES: Set<string>;
|
|
5
|
+
/** `inline`: one line without paragraphs, for a heading. */
|
|
6
|
+
export declare function Markdown({ children, className, inline }: {
|
|
2
7
|
children: string;
|
|
3
8
|
className?: string;
|
|
9
|
+
inline?: boolean;
|
|
4
10
|
}): import("react").JSX.Element;
|
package/es/steps/Markdown.js
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import MarkdownToJSX from "markdown-to-jsx";
|
|
3
|
+
import { createElement, Fragment } from "react";
|
|
4
|
+
/** What Markdown itself produces. */
|
|
5
|
+
const MARKDOWN_TAGS = new Set("p strong em del a ul ol li blockquote code pre br hr h1 h2 h3 h4 h5 h6 span div img table thead tbody tr th td input".split(" "));
|
|
6
|
+
/** The tags a text may use for what Markdown has no syntax for. They take no attributes. */
|
|
7
|
+
export const TEXT_TAGS = new Set(["big", "small", "u", "sup", "sub", "mark"]);
|
|
8
|
+
/** The colours a `<span data-color>` may name; they come from the theme. */
|
|
9
|
+
export const TEXT_TONES = new Set(["info", "success", "warning", "danger"]);
|
|
3
10
|
const OPTIONS = {
|
|
4
11
|
forceBlock: true,
|
|
5
|
-
//
|
|
6
|
-
|
|
12
|
+
// A single paragraph is otherwise returned bare, without the element that carries the class
|
|
13
|
+
forceWrapper: true,
|
|
7
14
|
overrides: {
|
|
8
15
|
a: { props: { target: "_blank", rel: "noreferrer" } },
|
|
9
16
|
},
|
|
17
|
+
// Course text is Markdown, not HTML: of the tags written into it only the few in TEXT_TAGS
|
|
18
|
+
// are drawn, and without their attributes, plus a span that names one of the theme's colours.
|
|
19
|
+
// Any other tag leaves just its text.
|
|
20
|
+
createElement(type, props, ...children) {
|
|
21
|
+
let tone = type === "span" ? props?.["data-color"] : undefined;
|
|
22
|
+
if (typeof tone === "string" && TEXT_TONES.has(tone)) {
|
|
23
|
+
return createElement("span", { key: props?.key, className: "ob-course-tone", "data-color": tone }, ...children);
|
|
24
|
+
}
|
|
25
|
+
// Any other span keeps its class (the wrapper of an inline text has one) and nothing else
|
|
26
|
+
if (type === "span")
|
|
27
|
+
return createElement("span", { key: props?.key, className: props?.className }, ...children);
|
|
28
|
+
if (typeof type === "string" && TEXT_TAGS.has(type))
|
|
29
|
+
return createElement(type, { key: props?.key }, ...children);
|
|
30
|
+
if (typeof type === "string" && !MARKDOWN_TAGS.has(type)) {
|
|
31
|
+
return createElement(Fragment, { key: props?.key }, ...children);
|
|
32
|
+
}
|
|
33
|
+
return createElement(type, props, ...children);
|
|
34
|
+
},
|
|
10
35
|
};
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
const INLINE_OPTIONS = { ...OPTIONS, forceBlock: false, forceInline: true };
|
|
37
|
+
/** `inline`: one line without paragraphs, for a heading. */
|
|
38
|
+
export function Markdown({ children, className, inline }) {
|
|
39
|
+
return (_jsx(MarkdownToJSX, { className: className ? `ob-course-markdown ${className}` : "ob-course-markdown", options: (inline ? INLINE_OPTIONS : OPTIONS), children: children }));
|
|
13
40
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component, type RefObject } from "react";
|
|
2
|
+
import { type PartBox } from "./motion";
|
|
3
|
+
/** Whether the learner asked for less motion. Read once per render; the setting rarely changes. */
|
|
4
|
+
export declare function prefersCalm(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* A part that goes away stays for the length of its fade first. `leaving` lasts `FADE_MS`, then the
|
|
7
|
+
* part is absent; coming back in the meantime makes it present again at once, so stepping back or
|
|
8
|
+
* scrubbing the narration leaves nothing behind.
|
|
9
|
+
*/
|
|
10
|
+
export declare function usePresence(present: boolean, calm: boolean): "present" | "leaving" | "absent";
|
|
11
|
+
interface RevealMotionProps {
|
|
12
|
+
root: RefObject<HTMLElement | null>;
|
|
13
|
+
/** Names what is shown. A change of it with the same `source` is a reveal. */
|
|
14
|
+
signature: string;
|
|
15
|
+
/** The blocks: a change of them is an edit, or another step, and never glides. */
|
|
16
|
+
source: unknown;
|
|
17
|
+
calm: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Glides the parts a reveal pushed to another place, and lifts the parts that fade out out of the
|
|
21
|
+
* flow. Drawn inside the slide; it renders nothing. A class, since `getSnapshotBeforeUpdate` is
|
|
22
|
+
* where React lets a component read the page as it was just before a change is put in it.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RevealMotion extends Component<RevealMotionProps> {
|
|
25
|
+
getSnapshotBeforeUpdate(previous: RevealMotionProps): Map<string, PartBox> | null;
|
|
26
|
+
componentDidUpdate(_previous: RevealMotionProps, _state: unknown, before: Map<string, PartBox> | null): void;
|
|
27
|
+
render(): null;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Component, useEffect, useState } from "react";
|
|
2
|
+
import { FADE_MS, getGlides, measureParts, pinLeaving, runGlides, unpinReturned } from "./motion";
|
|
3
|
+
/** Whether the learner asked for less motion. Read once per render; the setting rarely changes. */
|
|
4
|
+
export function prefersCalm() {
|
|
5
|
+
return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A part that goes away stays for the length of its fade first. `leaving` lasts `FADE_MS`, then the
|
|
9
|
+
* part is absent; coming back in the meantime makes it present again at once, so stepping back or
|
|
10
|
+
* scrubbing the narration leaves nothing behind.
|
|
11
|
+
*/
|
|
12
|
+
export function usePresence(present, calm) {
|
|
13
|
+
let [leaving, setLeaving] = useState(false);
|
|
14
|
+
let [wasPresent, setWasPresent] = useState(present);
|
|
15
|
+
if (present !== wasPresent) {
|
|
16
|
+
setWasPresent(present);
|
|
17
|
+
setLeaving(!present && !calm);
|
|
18
|
+
}
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!leaving)
|
|
21
|
+
return;
|
|
22
|
+
let timer = setTimeout(() => setLeaving(false), FADE_MS);
|
|
23
|
+
return () => clearTimeout(timer);
|
|
24
|
+
}, [leaving]);
|
|
25
|
+
if (present)
|
|
26
|
+
return "present";
|
|
27
|
+
return leaving ? "leaving" : "absent";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Glides the parts a reveal pushed to another place, and lifts the parts that fade out out of the
|
|
31
|
+
* flow. Drawn inside the slide; it renders nothing. A class, since `getSnapshotBeforeUpdate` is
|
|
32
|
+
* where React lets a component read the page as it was just before a change is put in it.
|
|
33
|
+
*/
|
|
34
|
+
export class RevealMotion extends Component {
|
|
35
|
+
getSnapshotBeforeUpdate(previous) {
|
|
36
|
+
let element = this.props.root.current;
|
|
37
|
+
let reveal = previous.source === this.props.source && previous.signature !== this.props.signature;
|
|
38
|
+
return reveal && element ? measureParts(element) : null;
|
|
39
|
+
}
|
|
40
|
+
componentDidUpdate(_previous, _state, before) {
|
|
41
|
+
let element = this.props.root.current;
|
|
42
|
+
if (!element)
|
|
43
|
+
return;
|
|
44
|
+
unpinReturned(element);
|
|
45
|
+
if (!before)
|
|
46
|
+
return;
|
|
47
|
+
pinLeaving(element, before);
|
|
48
|
+
if (this.props.calm)
|
|
49
|
+
return;
|
|
50
|
+
runGlides(element, getGlides(before, measureParts(element)));
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { SlideStep } from "../document/schema";
|
|
2
2
|
import type { StepBodyProps } from "./StepBodyProps";
|
|
3
3
|
/**
|
|
4
|
-
* Blocks on a page.
|
|
5
|
-
* has played to the end (
|
|
4
|
+
* Blocks on a page. With narration, its cues show and hide the parts and the slide is done when it
|
|
5
|
+
* has played to the end (or at once when it is `required: false`); Next and Back go to the other
|
|
6
|
+
* steps. Without, Next shows the parts that wait for it, and the slide is done when no press would
|
|
7
|
+
* show anything more. The slide reports where Next and Back go with `onRevealNavigation`.
|
|
6
8
|
*/
|
|
7
|
-
export declare function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, }: StepBodyProps & {
|
|
9
|
+
export declare function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, onRevealNavigation, }: StepBodyProps & {
|
|
8
10
|
step: SlideStep;
|
|
9
11
|
}): import("react").JSX.Element;
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import clsx from "clsx";
|
|
3
|
-
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
|
-
import { getRevealSteps } from "../document/cues";
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { getRevealNavigation, getRevealState, getRevealSteps, getTimedParts } from "../document/cues";
|
|
5
|
+
import { getActiveEffects, getPartEffects } from "../document/effects";
|
|
5
6
|
import { Subtitles } from "../media/MediaControls";
|
|
6
7
|
import { NarrationPlayer, useNarration } from "../media/Narration";
|
|
7
|
-
import { Blocks } from "./Blocks";
|
|
8
|
+
import { Blocks, getVisibility } from "./Blocks";
|
|
9
|
+
import { prefersCalm, RevealMotion } from "./RevealMotion";
|
|
8
10
|
/**
|
|
9
|
-
* Blocks on a page.
|
|
10
|
-
* has played to the end (
|
|
11
|
+
* Blocks on a page. With narration, its cues show and hide the parts and the slide is done when it
|
|
12
|
+
* has played to the end (or at once when it is `required: false`); Next and Back go to the other
|
|
13
|
+
* steps. Without, Next shows the parts that wait for it, and the slide is done when no press would
|
|
14
|
+
* show anything more. The slide reports where Next and Back go with `onRevealNavigation`.
|
|
11
15
|
*/
|
|
12
|
-
export function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, }) {
|
|
13
|
-
let revealSteps = useMemo(() => getRevealSteps(step.blocks), [step.blocks]);
|
|
16
|
+
export function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, onRevealNavigation, }) {
|
|
14
17
|
let narration = step.narration;
|
|
18
|
+
// On a narrated slide only the narration shows and hides parts; Next goes to the next step
|
|
19
|
+
let narrated = narration != null;
|
|
20
|
+
let revealSteps = useMemo(() => getRevealSteps(step.blocks, narrated), [step.blocks, narrated]);
|
|
15
21
|
let state = useNarration(narration, mode === "learn", onMediaEnded);
|
|
16
22
|
let clock = state.clock;
|
|
23
|
+
let navigation = useMemo(() => getRevealNavigation(step.blocks, stepsShown, clock.startedCues, narrated), [step.blocks, stepsShown, clock.startedCues, narrated]);
|
|
24
|
+
let { next, previous, presses, pressed } = navigation;
|
|
25
|
+
useLayoutEffect(() => {
|
|
26
|
+
onRevealNavigation?.({ next, previous, presses, pressed });
|
|
27
|
+
}, [next, previous, presses, pressed, onRevealNavigation]);
|
|
17
28
|
let mustListen = narration != null && narration.required !== false;
|
|
18
|
-
let done =
|
|
29
|
+
let done = next === null && (!mustListen || clock.ended);
|
|
19
30
|
useLayoutEffect(() => {
|
|
20
31
|
onDoneChange(done);
|
|
21
32
|
}, [done, onDoneChange]);
|
|
@@ -31,12 +42,24 @@ export function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles,
|
|
|
31
42
|
let calm = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
32
43
|
part?.scrollIntoView?.({ block: "nearest", behavior: calm ? "auto" : "smooth" });
|
|
33
44
|
}, [stepsShown, revealSteps]);
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
let reveal = useMemo(() => getRevealState(step.blocks, stepsShown, clock.startedCues, narrated), [step.blocks, stepsShown, clock.startedCues, narrated]);
|
|
46
|
+
// The effects that were shown before this change pick the timing of the parts they act on
|
|
47
|
+
let active = getActiveEffects(step.blocks, reveal);
|
|
48
|
+
let activeKey = [...active].join("\u0000");
|
|
49
|
+
let [effectsSeen, setEffectsSeen] = useState({ key: activeKey, active, previous: active });
|
|
50
|
+
if (effectsSeen.key !== activeKey)
|
|
51
|
+
setEffectsSeen({ key: activeKey, active, previous: effectsSeen.active });
|
|
52
|
+
let effects = getPartEffects(step.blocks, reveal, effectsSeen.previous);
|
|
53
|
+
let calm = prefersCalm();
|
|
54
|
+
let signature = getTimedParts(step.blocks)
|
|
55
|
+
.map((part) => `${part.id}:${getVisibility(part, reveal)}`)
|
|
56
|
+
.join("|");
|
|
57
|
+
let context = { reveal, resolveAsset, subtitles, onSubtitlesChange, effects, calm };
|
|
40
58
|
let background = step.background ? resolveAsset(step.background) : undefined;
|
|
41
|
-
|
|
59
|
+
// A banner shows the image as a band of its own instead of behind the whole slide
|
|
60
|
+
let banner = step.layout === "banner" && background ? background : undefined;
|
|
61
|
+
if (banner)
|
|
62
|
+
background = undefined;
|
|
63
|
+
let content = (_jsx("div", { className: "ob-course-slide__content", children: _jsx(Blocks, { blocks: step.blocks, context: context }) }));
|
|
64
|
+
return (_jsxs("div", { ref: rootRef, className: clsx("ob-course-slide", `ob-course-slide--${step.layout ?? "default"}`, step.width && `ob-course-slide--${step.width}`, background && "ob-course-slide--background", background && step.panel === false && "ob-course-slide--bare"), children: [_jsx(RevealMotion, { root: rootRef, signature: signature, source: step.blocks, calm: calm }), background && (_jsx("div", { className: "ob-course-slide__background", style: { backgroundImage: `url("${background}")` } })), banner ? (_jsx("div", { className: "ob-course-banner", children: _jsxs("div", { className: "ob-course-banner__stage", children: [_jsx("img", { className: "ob-course-banner__image", src: banner, alt: "" }), content] }) })) : (content), narration && (_jsx(NarrationPlayer, { className: "ob-course-slide__narration", narration: narration, clock: state.clock, setAudio: state.setAudio, resolveAsset: resolveAsset, subtitles: subtitles, onSubtitlesChange: onSubtitlesChange })), _jsx(Subtitles, { cue: subtitles ? clock.activeCue : undefined })] }));
|
|
42
65
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RevealNavigation } from "../document/cues";
|
|
1
2
|
import type { PlayerMode, QuizAdapter, ResolveAsset } from "../types";
|
|
2
3
|
/** What the player hands every step type. */
|
|
3
4
|
export interface StepBodyProps {
|
|
@@ -5,7 +6,10 @@ export interface StepBodyProps {
|
|
|
5
6
|
mode: PlayerMode;
|
|
6
7
|
resolveAsset: ResolveAsset;
|
|
7
8
|
quiz?: QuizAdapter;
|
|
8
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* How many `reveal: "step"` parts of a slide count as pressed, in document order. A press of
|
|
11
|
+
* Next may move it by more than one, past parts that would show nothing new.
|
|
12
|
+
*/
|
|
9
13
|
stepsShown: number;
|
|
10
14
|
subtitles: boolean;
|
|
11
15
|
onSubtitlesChange(subtitles: boolean): void;
|
|
@@ -13,4 +17,6 @@ export interface StepBodyProps {
|
|
|
13
17
|
onDoneChange(done: boolean): void;
|
|
14
18
|
/** The step's narration or video has played to its end; called again after each replay. */
|
|
15
19
|
onMediaEnded?(): void;
|
|
20
|
+
/** A slide reports where Next and Back go from here, and the presses that show something. */
|
|
21
|
+
onRevealNavigation?(navigation: RevealNavigation): void;
|
|
16
22
|
}
|