@olenbetong/synergi-course 2.0.0 → 2.2.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 +117 -14
- package/es/document/effects.d.ts +30 -0
- package/es/document/effects.js +76 -0
- package/es/document/schema.d.ts +2722 -346
- package/es/document/schema.js +172 -5
- package/es/document/validate.d.ts +2 -1
- package/es/document/validate.js +83 -16
- package/es/index.d.ts +8 -3
- 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 +76 -0
- package/es/player/CoursePlayer.js +28 -13
- package/es/player/PlayerBars.d.ts +32 -0
- package/es/player/PlayerBars.js +14 -0
- 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 +43 -3
- package/es/steps/Blocks.js +114 -26
- package/es/steps/Markdown.d.ts +7 -1
- package/es/steps/Markdown.js +31 -4
- package/es/steps/QuizStepView.d.ts +2 -1
- package/es/steps/QuizStepView.js +20 -10
- 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 +43 -10
- package/es/steps/StepBodyProps.d.ts +16 -1
- package/es/steps/StepView.css +390 -16
- package/es/steps/StepView.d.ts +36 -4
- package/es/steps/StepView.js +21 -5
- 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 +16 -3
- 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/box.test.ts +234 -0
- package/src/document/cues.ts +143 -13
- package/src/document/document.test.ts +1 -1
- package/src/document/effects.ts +106 -0
- package/src/document/reveal.test.ts +263 -0
- package/src/document/schema.ts +203 -5
- package/src/document/validate.ts +88 -18
- package/src/index.ts +46 -1
- package/src/media/Media.css +16 -0
- package/src/media/icons.tsx +8 -0
- package/src/player/CoursePlayer.css +76 -0
- package/src/player/CoursePlayer.test.tsx +70 -6
- package/src/player/CoursePlayer.tsx +91 -60
- package/src/player/PlayerBars.tsx +106 -0
- 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 +219 -32
- package/src/steps/Box.test.tsx +95 -0
- package/src/steps/Markdown.test.tsx +46 -0
- package/src/steps/Markdown.tsx +42 -4
- package/src/steps/Presence.test.tsx +82 -0
- package/src/steps/QuizStepView.test.tsx +79 -0
- package/src/steps/QuizStepView.tsx +34 -12
- package/src/steps/RevealMotion.ts +66 -0
- package/src/steps/SlideStepView.tsx +74 -12
- package/src/steps/StepBodyProps.ts +16 -1
- package/src/steps/StepView.css +390 -16
- package/src/steps/StepView.test.tsx +157 -0
- package/src/steps/StepView.tsx +108 -19
- 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 +16 -3
- 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
|
@@ -92,3 +92,31 @@
|
|
|
92
92
|
display: none;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
/* On a phone on its side the band is one slim line: the subtitle goes beside the title. */
|
|
97
|
+
@media (orientation: landscape) and (max-height: 500px) {
|
|
98
|
+
.ob-course-category-header {
|
|
99
|
+
padding-block: 0.2rem;
|
|
100
|
+
font-size: 0.75rem;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.ob-course-category-header__titles {
|
|
104
|
+
display: flex;
|
|
105
|
+
flex-wrap: wrap;
|
|
106
|
+
align-items: baseline;
|
|
107
|
+
column-gap: 0.75em;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.ob-course-category-header__title {
|
|
111
|
+
font-size: 1.15em;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.ob-course-category-header__image {
|
|
115
|
+
width: 1.75em;
|
|
116
|
+
height: 1.75em;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.ob-course-category-header__logo {
|
|
120
|
+
max-height: 1.75em;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.ob-course-completion {
|
|
2
|
+
display: grid;
|
|
3
|
+
place-items: center;
|
|
4
|
+
height: 100%;
|
|
5
|
+
padding: var(--ds-size-6) var(--ds-size-4);
|
|
6
|
+
overflow: auto;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ob-course-completion__panel {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: var(--ds-size-6);
|
|
14
|
+
width: min(100%, 44rem);
|
|
15
|
+
text-align: center;
|
|
16
|
+
font-size: 1.25rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ob-course-completion__actions {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-wrap: wrap;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
gap: var(--ds-size-3);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* The course's own completion text, written for the old full-page completion article. Keep it inside the
|
|
28
|
+
* panel: the old texts lift themselves with negative top margins and rely on Bootstrap's text-center.
|
|
29
|
+
*/
|
|
30
|
+
.ob-course-completion__text {
|
|
31
|
+
overflow-wrap: anywhere;
|
|
32
|
+
|
|
33
|
+
& > * {
|
|
34
|
+
margin-block-start: 0 !important;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
& :where(p) {
|
|
38
|
+
margin-block: 0 var(--ds-size-3);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
& :where(img, video) {
|
|
42
|
+
max-width: 100%;
|
|
43
|
+
height: auto;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
& :where(a) {
|
|
47
|
+
color: var(--ds-color-brand-text-subtle);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
& :where(.text-center) {
|
|
51
|
+
text-align: center;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import "./CourseCompletion.css";
|
|
3
|
+
export interface CourseCompletionProps {
|
|
4
|
+
/** The course's title, the screen's heading. */
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
/** The course's completion text (HTML written by the course editors). Blank counts as none. */
|
|
7
|
+
html?: string | null;
|
|
8
|
+
/** What the learner reads when the course has no completion text. */
|
|
9
|
+
emptyText: ReactNode;
|
|
10
|
+
/** The buttons under the text (the diploma, back to the course list). */
|
|
11
|
+
actions?: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Strip scripts, event handlers, embedded frames and `javascript:` links before showing the
|
|
14
|
+
* text. For an editor's preview of text being written; the player shows the saved text as it is.
|
|
15
|
+
*/
|
|
16
|
+
sanitize?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Whether the completion text has anything to show; the course feed treats blank text as none. */
|
|
20
|
+
export declare function hasCompletionText(html: string | null | undefined): html is string;
|
|
21
|
+
/**
|
|
22
|
+
* The completion text without anything that runs code: script and frame elements, `on*`
|
|
23
|
+
* attributes and `javascript:` (or `data:` outside images) URLs. Parsed in an inert document, so
|
|
24
|
+
* nothing in it runs or loads while it is cleaned.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sanitizeCompletionHtml(html: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* The screen a learner sees when the course is completed: the title, the course's completion
|
|
29
|
+
* text (or the default text) and the actions. The completion texts were written for the old
|
|
30
|
+
* full-page completion article; the stylesheet keeps them inside the panel.
|
|
31
|
+
*/
|
|
32
|
+
export declare function CourseCompletion({ title, html, emptyText, actions, sanitize, className }: CourseCompletionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Heading, Paragraph } from "@digdir/designsystemet-react";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import "./CourseCompletion.css";
|
|
6
|
+
/** Whether the completion text has anything to show; the course feed treats blank text as none. */
|
|
7
|
+
export function hasCompletionText(html) {
|
|
8
|
+
return !!html?.trim();
|
|
9
|
+
}
|
|
10
|
+
const REMOVED_ELEMENTS = "script, iframe, frame, frameset, object, embed, base, meta, link, form";
|
|
11
|
+
const URL_ATTRIBUTES = new Set(["href", "src", "action", "formaction", "xlink:href", "srcdoc"]);
|
|
12
|
+
/**
|
|
13
|
+
* The completion text without anything that runs code: script and frame elements, `on*`
|
|
14
|
+
* attributes and `javascript:` (or `data:` outside images) URLs. Parsed in an inert document, so
|
|
15
|
+
* nothing in it runs or loads while it is cleaned.
|
|
16
|
+
*/
|
|
17
|
+
export function sanitizeCompletionHtml(html) {
|
|
18
|
+
let document = new DOMParser().parseFromString(`<body>${html}</body>`, "text/html");
|
|
19
|
+
for (let element of document.body.querySelectorAll(REMOVED_ELEMENTS))
|
|
20
|
+
element.remove();
|
|
21
|
+
for (let element of document.body.querySelectorAll("*")) {
|
|
22
|
+
// A copy, since removing attributes changes the live list
|
|
23
|
+
for (let attribute of Array.from(element.attributes)) {
|
|
24
|
+
let name = attribute.name.toLowerCase();
|
|
25
|
+
if (name.startsWith("on")) {
|
|
26
|
+
element.removeAttribute(attribute.name);
|
|
27
|
+
}
|
|
28
|
+
else if (URL_ATTRIBUTES.has(name)) {
|
|
29
|
+
// Browsers skip control characters and spaces in a scheme ("java\tscript:")
|
|
30
|
+
let value = [...attribute.value]
|
|
31
|
+
.filter((char) => char.charCodeAt(0) > 32)
|
|
32
|
+
.join("")
|
|
33
|
+
.toLowerCase();
|
|
34
|
+
let imageData = value.startsWith("data:image/") && name === "src" && element.tagName === "IMG";
|
|
35
|
+
if (name === "srcdoc" ||
|
|
36
|
+
value.startsWith("javascript:") ||
|
|
37
|
+
value.startsWith("vbscript:") ||
|
|
38
|
+
(value.startsWith("data:") && !imageData)) {
|
|
39
|
+
element.removeAttribute(attribute.name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return document.body.innerHTML;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The screen a learner sees when the course is completed: the title, the course's completion
|
|
48
|
+
* text (or the default text) and the actions. The completion texts were written for the old
|
|
49
|
+
* full-page completion article; the stylesheet keeps them inside the panel.
|
|
50
|
+
*/
|
|
51
|
+
export function CourseCompletion({ title, html, emptyText, actions, sanitize, className }) {
|
|
52
|
+
let shown = useMemo(() => {
|
|
53
|
+
if (!hasCompletionText(html))
|
|
54
|
+
return null;
|
|
55
|
+
return sanitize ? sanitizeCompletionHtml(html) : html;
|
|
56
|
+
}, [html, sanitize]);
|
|
57
|
+
return (_jsx("div", { className: clsx("ob-course-completion", className), children: _jsxs("div", { className: "ob-course-completion__panel", children: [_jsx(Heading, { level: 1, "data-size": "xl", children: title }), shown !== null ? (_jsx("div", { className: "ob-course-completion__text ds-paragraph",
|
|
58
|
+
// oxlint-disable-next-line react/no-danger -- written by the course editors; sanitize for previews
|
|
59
|
+
dangerouslySetInnerHTML: { __html: shown } })) : (_jsx(Paragraph, { "data-size": "lg", children: emptyText })), actions && _jsx("div", { className: "ob-course-completion__actions", children: actions })] }) }));
|
|
60
|
+
}
|
package/es/document/cues.d.ts
CHANGED
|
@@ -12,10 +12,13 @@ export declare function getActiveCue(cues: Cue[], time: number): Cue | undefined
|
|
|
12
12
|
export declare function hasCueText(cues: Cue[]): boolean;
|
|
13
13
|
/** The ids of every cue that has started at `time`. */
|
|
14
14
|
export declare function getStartedCueIds(cues: Cue[], time: number): Set<string>;
|
|
15
|
-
/** Every block and
|
|
15
|
+
/** Every block, list item and canvas item of a slide in document order, columns and boxes flattened. */
|
|
16
16
|
export declare function getTimedParts(blocks: Block[]): Timed[];
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The ids of the parts that wait for a press of Next, in the order they are shown. None on a
|
|
19
|
+
* narrated slide: there only the narration shows and hides parts, and Next goes to the next step.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getRevealSteps(blocks: Block[], narrated?: boolean): string[];
|
|
19
22
|
export interface RevealState {
|
|
20
23
|
/** How many of the `reveal: "step"` parts have been shown. */
|
|
21
24
|
stepsShown: number;
|
|
@@ -23,10 +26,52 @@ export interface RevealState {
|
|
|
23
26
|
revealSteps: string[];
|
|
24
27
|
/** From `getStartedCueIds`. */
|
|
25
28
|
startedCues: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* From `getRevealLeaders`: the part each `reveal: "with-previous"` part follows. Left out, such a
|
|
31
|
+
* part is there from the start.
|
|
32
|
+
*/
|
|
33
|
+
leaders?: ReadonlyMap<string, Timed>;
|
|
34
|
+
/**
|
|
35
|
+
* The slide has narration. `reveal: "step"` then waits for nothing: a part with only that shows
|
|
36
|
+
* from the start, and one that also has `revealAt` follows its cue.
|
|
37
|
+
*/
|
|
38
|
+
narrated?: boolean;
|
|
26
39
|
}
|
|
40
|
+
/** Whether a part waits to be shown by anything: Next, a cue, or the part it goes with. */
|
|
41
|
+
export declare function hasTrigger(part: Timed): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The part each `reveal: "with-previous"` part follows: the nearest part above it in document
|
|
44
|
+
* order that waits to be shown itself. A with-previous part with none is not in the map.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getRevealLeaders(blocks: Block[]): Map<string, Timed>;
|
|
47
|
+
/** Whether what a part waits for has happened, its `hideAt` aside. */
|
|
48
|
+
export declare function isDue(part: Timed, state: RevealState, seen?: Set<string>): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The reveal state of a slide after `stepsShown` presses of Next, with the narration at
|
|
51
|
+
* `startedCues`. On a narrated slide presses count for nothing; the cues decide.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getRevealState(blocks: Block[], stepsShown: number, startedCues: Set<string>, narrated?: boolean): RevealState;
|
|
54
|
+
export interface RevealNavigation {
|
|
55
|
+
/** The `stepsShown` a press of Next goes to, or null when no press would change what is shown. */
|
|
56
|
+
next: number | null;
|
|
57
|
+
/** The `stepsShown` a press of Back goes to, or null when going back would change nothing. */
|
|
58
|
+
previous: number | null;
|
|
59
|
+
/** How many presses change what is shown, from the first one; the count the stepper shows. */
|
|
60
|
+
presses: number;
|
|
61
|
+
/** How many of those are behind the learner. */
|
|
62
|
+
pressed: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Where Next and Back take a slide, so that every press shows something: a press that would change
|
|
66
|
+
* nothing is skipped. What is shown is every part's visibility, effects included. Back lands on
|
|
67
|
+
* the first press that shows what it goes back to, so Next and Back meet at the same places. On a
|
|
68
|
+
* narrated slide there are no presses: Next and Back go to the next and the previous step.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getRevealNavigation(blocks: Block[], stepsShown: number, startedCues: Set<string>, narrated?: boolean): RevealNavigation;
|
|
27
71
|
/**
|
|
28
|
-
* Whether a block or list item shows right now
|
|
29
|
-
*
|
|
30
|
-
* without sound.
|
|
72
|
+
* Whether a block or list item shows right now: what it waits for has happened (Next on a slide
|
|
73
|
+
* without narration, its cue, or the part it goes with), and its `hideAt` cue has not started.
|
|
31
74
|
*/
|
|
32
75
|
export declare function isVisible(part: Timed, state: RevealState): boolean;
|
|
76
|
+
/** Whether a step is a slide with narration, where only the narration shows and hides parts. */
|
|
77
|
+
export declare function isNarratedSlide(step: Step | null | undefined): boolean;
|
package/es/document/cues.js
CHANGED
|
@@ -30,43 +30,146 @@ export function getStartedCueIds(cues, time) {
|
|
|
30
30
|
}
|
|
31
31
|
return started;
|
|
32
32
|
}
|
|
33
|
-
/** Every block and
|
|
33
|
+
/** Every block, list item and canvas item of a slide in document order, columns and boxes flattened. */
|
|
34
34
|
export function getTimedParts(blocks) {
|
|
35
35
|
let parts = [];
|
|
36
36
|
function add(block) {
|
|
37
37
|
parts.push(block);
|
|
38
38
|
if (block.type === "list")
|
|
39
39
|
parts.push(...block.items);
|
|
40
|
+
if (block.type === "canvas")
|
|
41
|
+
parts.push(...block.items);
|
|
40
42
|
if (block.type === "columns") {
|
|
41
43
|
for (let column of block.columns)
|
|
42
44
|
column.blocks.forEach(add);
|
|
43
45
|
}
|
|
46
|
+
if (block.type === "box")
|
|
47
|
+
block.blocks.forEach(add);
|
|
44
48
|
}
|
|
45
49
|
blocks.forEach(add);
|
|
46
50
|
return parts;
|
|
47
51
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The ids of the parts that wait for a press of Next, in the order they are shown. None on a
|
|
54
|
+
* narrated slide: there only the narration shows and hides parts, and Next goes to the next step.
|
|
55
|
+
*/
|
|
56
|
+
export function getRevealSteps(blocks, narrated = false) {
|
|
57
|
+
if (narrated)
|
|
58
|
+
return [];
|
|
50
59
|
return getTimedParts(blocks)
|
|
51
60
|
.filter((part) => part.reveal === "step")
|
|
52
61
|
.map((part) => part.id);
|
|
53
62
|
}
|
|
63
|
+
/** Whether a part waits to be shown by anything: Next, a cue, or the part it goes with. */
|
|
64
|
+
export function hasTrigger(part) {
|
|
65
|
+
return part.reveal != null || part.revealAt != null;
|
|
66
|
+
}
|
|
54
67
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* without sound.
|
|
68
|
+
* The part each `reveal: "with-previous"` part follows: the nearest part above it in document
|
|
69
|
+
* order that waits to be shown itself. A with-previous part with none is not in the map.
|
|
58
70
|
*/
|
|
59
|
-
export function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
export function getRevealLeaders(blocks) {
|
|
72
|
+
let leaders = new Map();
|
|
73
|
+
let previous;
|
|
74
|
+
for (let part of getTimedParts(blocks)) {
|
|
75
|
+
if (part.reveal === "with-previous" && previous)
|
|
76
|
+
leaders.set(part.id, previous);
|
|
77
|
+
if (hasTrigger(part))
|
|
78
|
+
previous = part;
|
|
79
|
+
}
|
|
80
|
+
return leaders;
|
|
81
|
+
}
|
|
82
|
+
/** Whether what a part waits for has happened, its `hideAt` aside. */
|
|
83
|
+
export function isDue(part, state, seen = new Set()) {
|
|
84
|
+
if (!hasTrigger(part))
|
|
65
85
|
return true;
|
|
66
|
-
if (
|
|
86
|
+
if (part.reveal === "step") {
|
|
87
|
+
// On a narrated slide Next shows nothing: only a cue can hold the part back
|
|
88
|
+
if (state.narrated)
|
|
89
|
+
return part.revealAt == null || state.startedCues.has(part.revealAt);
|
|
67
90
|
let index = state.revealSteps.indexOf(part.id);
|
|
68
91
|
if (index !== -1 && index < state.stepsShown)
|
|
69
92
|
return true;
|
|
70
93
|
}
|
|
71
|
-
|
|
94
|
+
if (part.revealAt != null && state.startedCues.has(part.revealAt))
|
|
95
|
+
return true;
|
|
96
|
+
if (part.reveal === "with-previous") {
|
|
97
|
+
let leader = state.leaders?.get(part.id);
|
|
98
|
+
if (!leader)
|
|
99
|
+
return true;
|
|
100
|
+
// The map only points up the document, but a hand-made one must not loop
|
|
101
|
+
if (seen.has(part.id))
|
|
102
|
+
return false;
|
|
103
|
+
seen.add(part.id);
|
|
104
|
+
return isDue(leader, state, seen);
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The reveal state of a slide after `stepsShown` presses of Next, with the narration at
|
|
110
|
+
* `startedCues`. On a narrated slide presses count for nothing; the cues decide.
|
|
111
|
+
*/
|
|
112
|
+
export function getRevealState(blocks, stepsShown, startedCues, narrated = false) {
|
|
113
|
+
return {
|
|
114
|
+
stepsShown: narrated ? 0 : stepsShown,
|
|
115
|
+
revealSteps: getRevealSteps(blocks, narrated),
|
|
116
|
+
startedCues,
|
|
117
|
+
leaders: getRevealLeaders(blocks),
|
|
118
|
+
narrated,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Where Next and Back take a slide, so that every press shows something: a press that would change
|
|
123
|
+
* nothing is skipped. What is shown is every part's visibility, effects included. Back lands on
|
|
124
|
+
* the first press that shows what it goes back to, so Next and Back meet at the same places. On a
|
|
125
|
+
* narrated slide there are no presses: Next and Back go to the next and the previous step.
|
|
126
|
+
*/
|
|
127
|
+
export function getRevealNavigation(blocks, stepsShown, startedCues, narrated = false) {
|
|
128
|
+
let parts = getTimedParts(blocks);
|
|
129
|
+
let total = getRevealSteps(blocks, narrated).length;
|
|
130
|
+
let at = Math.max(0, Math.min(stepsShown, total));
|
|
131
|
+
let shown = (count) => {
|
|
132
|
+
let state = getRevealState(blocks, count, startedCues, narrated);
|
|
133
|
+
return parts.map((part) => (isVisible(part, state) ? "1" : "0")).join("");
|
|
134
|
+
};
|
|
135
|
+
let states = Array.from({ length: total + 1 }, (_value, count) => shown(count));
|
|
136
|
+
let next = null;
|
|
137
|
+
for (let count = at + 1; count <= total; count++) {
|
|
138
|
+
if (states[count] !== states[at]) {
|
|
139
|
+
next = count;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let previous = null;
|
|
144
|
+
for (let count = at - 1; count >= 0; count--) {
|
|
145
|
+
if (states[count] !== states[at]) {
|
|
146
|
+
previous = count;
|
|
147
|
+
while (previous > 0 && states[previous - 1] === states[previous])
|
|
148
|
+
previous -= 1;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
let presses = 0;
|
|
153
|
+
let pressed = 0;
|
|
154
|
+
for (let count = 1; count <= total; count++) {
|
|
155
|
+
if (states[count] === states[count - 1])
|
|
156
|
+
continue;
|
|
157
|
+
presses += 1;
|
|
158
|
+
if (count <= at)
|
|
159
|
+
pressed += 1;
|
|
160
|
+
}
|
|
161
|
+
return { next, previous, presses, pressed };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Whether a block or list item shows right now: what it waits for has happened (Next on a slide
|
|
165
|
+
* without narration, its cue, or the part it goes with), and its `hideAt` cue has not started.
|
|
166
|
+
*/
|
|
167
|
+
export function isVisible(part, state) {
|
|
168
|
+
if (part.hideAt && state.startedCues.has(part.hideAt))
|
|
169
|
+
return false;
|
|
170
|
+
return isDue(part, state);
|
|
171
|
+
}
|
|
172
|
+
/** Whether a step is a slide with narration, where only the narration shows and hides parts. */
|
|
173
|
+
export function isNarratedSlide(step) {
|
|
174
|
+
return step?.type === "slide" && step.narration != null;
|
|
72
175
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RevealState } from "./cues";
|
|
2
|
+
import type { Block, BoxContentBlock, ContentBlock, EffectBlock } from "./schema";
|
|
3
|
+
export declare const DEFAULT_EFFECT_DURATION = 300;
|
|
4
|
+
/** What the effects on one part add up to right now, and how the part changes into it. */
|
|
5
|
+
export interface PartEffect {
|
|
6
|
+
/** In the slide's text size, or for a canvas item in percent of the canvas. */
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
scale: number;
|
|
10
|
+
/** `null` while no shown effect sets one. */
|
|
11
|
+
opacity: number | null;
|
|
12
|
+
/** Milliseconds before the change starts: the delay of the effect that came, 0 for one that went. */
|
|
13
|
+
delay: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
}
|
|
16
|
+
/** Every effect block of a slide in document order, those in columns and boxes included. */
|
|
17
|
+
export declare function getEffectBlocks(blocks: Array<Block | ContentBlock | BoxContentBlock>): EffectBlock[];
|
|
18
|
+
export declare function effectTargets(effect: EffectBlock): string[];
|
|
19
|
+
/** The ids of the effects that are shown, and so act on their targets, in this state. */
|
|
20
|
+
export declare function getActiveEffects(blocks: Block[], state: RevealState): Set<string>;
|
|
21
|
+
/**
|
|
22
|
+
* The state of every part an effect targets, whether or not an effect is shown now, so a part
|
|
23
|
+
* goes back with a transition when its effects stop. Moves add up, scales multiply, and the last
|
|
24
|
+
* shown opacity in document order wins.
|
|
25
|
+
*
|
|
26
|
+
* `previouslyActive` (the ids from `getActiveEffects` before this change) picks the timing: of the
|
|
27
|
+
* effects on a part that came or went, the last in the document decides. A part whose effects did
|
|
28
|
+
* not change keeps the timing of its last shown effect.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getPartEffects(blocks: Block[], state: RevealState, previouslyActive?: ReadonlySet<string>): Map<string, PartEffect>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { isVisible } from "./cues";
|
|
2
|
+
export const DEFAULT_EFFECT_DURATION = 300;
|
|
3
|
+
/** Every effect block of a slide in document order, those in columns and boxes included. */
|
|
4
|
+
export function getEffectBlocks(blocks) {
|
|
5
|
+
let effects = [];
|
|
6
|
+
for (let block of blocks) {
|
|
7
|
+
if (block.type === "effect")
|
|
8
|
+
effects.push(block);
|
|
9
|
+
if (block.type === "columns") {
|
|
10
|
+
for (let column of block.columns)
|
|
11
|
+
effects.push(...getEffectBlocks(column.blocks));
|
|
12
|
+
}
|
|
13
|
+
if (block.type === "box")
|
|
14
|
+
effects.push(...getEffectBlocks(block.blocks));
|
|
15
|
+
}
|
|
16
|
+
return effects;
|
|
17
|
+
}
|
|
18
|
+
export function effectTargets(effect) {
|
|
19
|
+
return typeof effect.target === "string" ? [effect.target] : effect.target;
|
|
20
|
+
}
|
|
21
|
+
/** The ids of the effects that are shown, and so act on their targets, in this state. */
|
|
22
|
+
export function getActiveEffects(blocks, state) {
|
|
23
|
+
return new Set(getEffectBlocks(blocks)
|
|
24
|
+
.filter((effect) => isVisible(effect, state))
|
|
25
|
+
.map((effect) => effect.id));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The state of every part an effect targets, whether or not an effect is shown now, so a part
|
|
29
|
+
* goes back with a transition when its effects stop. Moves add up, scales multiply, and the last
|
|
30
|
+
* shown opacity in document order wins.
|
|
31
|
+
*
|
|
32
|
+
* `previouslyActive` (the ids from `getActiveEffects` before this change) picks the timing: of the
|
|
33
|
+
* effects on a part that came or went, the last in the document decides. A part whose effects did
|
|
34
|
+
* not change keeps the timing of its last shown effect.
|
|
35
|
+
*/
|
|
36
|
+
export function getPartEffects(blocks, state, previouslyActive) {
|
|
37
|
+
let parts = new Map();
|
|
38
|
+
let effects = getEffectBlocks(blocks);
|
|
39
|
+
let effectIds = new Set(effects.map((effect) => effect.id));
|
|
40
|
+
let decided = new Set();
|
|
41
|
+
let active = getActiveEffects(blocks, state);
|
|
42
|
+
// Last first, so the first effect met for a part is the one that decides its timing
|
|
43
|
+
for (let effect of [...effects].reverse()) {
|
|
44
|
+
let on = active.has(effect.id);
|
|
45
|
+
let changed = previouslyActive != null && previouslyActive.has(effect.id) !== on;
|
|
46
|
+
for (let target of effectTargets(effect)) {
|
|
47
|
+
if (target === effect.id || effectIds.has(target))
|
|
48
|
+
continue;
|
|
49
|
+
let part = parts.get(target);
|
|
50
|
+
if (!part) {
|
|
51
|
+
part = { x: 0, y: 0, scale: 1, opacity: null, delay: 0, duration: DEFAULT_EFFECT_DURATION };
|
|
52
|
+
parts.set(target, part);
|
|
53
|
+
}
|
|
54
|
+
if (!decided.has(target) && (changed || (on && !changedOnPart(target, effects, active, previouslyActive)))) {
|
|
55
|
+
decided.add(target);
|
|
56
|
+
part.delay = on ? (effect.delay ?? 0) : 0;
|
|
57
|
+
part.duration = effect.duration ?? DEFAULT_EFFECT_DURATION;
|
|
58
|
+
}
|
|
59
|
+
if (!on)
|
|
60
|
+
continue;
|
|
61
|
+
part.x += effect.move?.x ?? 0;
|
|
62
|
+
part.y += effect.move?.y ?? 0;
|
|
63
|
+
part.scale *= effect.scale ?? 1;
|
|
64
|
+
// Walking backwards, the first opacity met is the last in the document
|
|
65
|
+
if (part.opacity === null && effect.opacity != null)
|
|
66
|
+
part.opacity = effect.opacity;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return parts;
|
|
70
|
+
}
|
|
71
|
+
/** Whether any effect on the part came or went, which then decides the timing over a still one. */
|
|
72
|
+
function changedOnPart(target, effects, active, previouslyActive) {
|
|
73
|
+
if (!previouslyActive)
|
|
74
|
+
return false;
|
|
75
|
+
return effects.some((effect) => effectTargets(effect).includes(target) && previouslyActive.has(effect.id) !== active.has(effect.id));
|
|
76
|
+
}
|