@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
package/src/document/cues.ts
CHANGED
|
@@ -34,24 +34,30 @@ export function getStartedCueIds(cues: Cue[], time: number): Set<string> {
|
|
|
34
34
|
return started;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/** Every block and
|
|
37
|
+
/** Every block, list item and canvas item of a slide in document order, columns and boxes flattened. */
|
|
38
38
|
export function getTimedParts(blocks: Block[]): Timed[] {
|
|
39
39
|
let parts: Timed[] = [];
|
|
40
40
|
|
|
41
41
|
function add(block: Block) {
|
|
42
42
|
parts.push(block);
|
|
43
43
|
if (block.type === "list") parts.push(...block.items);
|
|
44
|
+
if (block.type === "canvas") parts.push(...block.items);
|
|
44
45
|
if (block.type === "columns") {
|
|
45
46
|
for (let column of block.columns) column.blocks.forEach(add);
|
|
46
47
|
}
|
|
48
|
+
if (block.type === "box") block.blocks.forEach(add);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
blocks.forEach(add);
|
|
50
52
|
return parts;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The ids of the parts that wait for a press of Next, in the order they are shown. None on a
|
|
57
|
+
* narrated slide: there only the narration shows and hides parts, and Next goes to the next step.
|
|
58
|
+
*/
|
|
59
|
+
export function getRevealSteps(blocks: Block[], narrated = false): string[] {
|
|
60
|
+
if (narrated) return [];
|
|
55
61
|
return getTimedParts(blocks)
|
|
56
62
|
.filter((part) => part.reveal === "step")
|
|
57
63
|
.map((part) => part.id);
|
|
@@ -64,24 +70,148 @@ export interface RevealState {
|
|
|
64
70
|
revealSteps: string[];
|
|
65
71
|
/** From `getStartedCueIds`. */
|
|
66
72
|
startedCues: Set<string>;
|
|
73
|
+
/**
|
|
74
|
+
* From `getRevealLeaders`: the part each `reveal: "with-previous"` part follows. Left out, such a
|
|
75
|
+
* part is there from the start.
|
|
76
|
+
*/
|
|
77
|
+
leaders?: ReadonlyMap<string, Timed>;
|
|
78
|
+
/**
|
|
79
|
+
* The slide has narration. `reveal: "step"` then waits for nothing: a part with only that shows
|
|
80
|
+
* from the start, and one that also has `revealAt` follows its cue.
|
|
81
|
+
*/
|
|
82
|
+
narrated?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Whether a part waits to be shown by anything: Next, a cue, or the part it goes with. */
|
|
86
|
+
export function hasTrigger(part: Timed) {
|
|
87
|
+
return part.reveal != null || part.revealAt != null;
|
|
67
88
|
}
|
|
68
89
|
|
|
69
90
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* without sound.
|
|
91
|
+
* The part each `reveal: "with-previous"` part follows: the nearest part above it in document
|
|
92
|
+
* order that waits to be shown itself. A with-previous part with none is not in the map.
|
|
73
93
|
*/
|
|
74
|
-
export function
|
|
75
|
-
|
|
94
|
+
export function getRevealLeaders(blocks: Block[]): Map<string, Timed> {
|
|
95
|
+
let leaders = new Map<string, Timed>();
|
|
96
|
+
let previous: Timed | undefined;
|
|
97
|
+
for (let part of getTimedParts(blocks)) {
|
|
98
|
+
if (part.reveal === "with-previous" && previous) leaders.set(part.id, previous);
|
|
99
|
+
if (hasTrigger(part)) previous = part;
|
|
100
|
+
}
|
|
101
|
+
return leaders;
|
|
102
|
+
}
|
|
76
103
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!
|
|
104
|
+
/** Whether what a part waits for has happened, its `hideAt` aside. */
|
|
105
|
+
export function isDue(part: Timed, state: RevealState, seen = new Set<string>()): boolean {
|
|
106
|
+
if (!hasTrigger(part)) return true;
|
|
80
107
|
|
|
81
|
-
if (
|
|
108
|
+
if (part.reveal === "step") {
|
|
109
|
+
// On a narrated slide Next shows nothing: only a cue can hold the part back
|
|
110
|
+
if (state.narrated) return part.revealAt == null || state.startedCues.has(part.revealAt);
|
|
82
111
|
let index = state.revealSteps.indexOf(part.id);
|
|
83
112
|
if (index !== -1 && index < state.stepsShown) return true;
|
|
84
113
|
}
|
|
114
|
+
if (part.revealAt != null && state.startedCues.has(part.revealAt)) return true;
|
|
115
|
+
|
|
116
|
+
if (part.reveal === "with-previous") {
|
|
117
|
+
let leader = state.leaders?.get(part.id);
|
|
118
|
+
if (!leader) return true;
|
|
119
|
+
// The map only points up the document, but a hand-made one must not loop
|
|
120
|
+
if (seen.has(part.id)) return false;
|
|
121
|
+
seen.add(part.id);
|
|
122
|
+
return isDue(leader, state, seen);
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The reveal state of a slide after `stepsShown` presses of Next, with the narration at
|
|
129
|
+
* `startedCues`. On a narrated slide presses count for nothing; the cues decide.
|
|
130
|
+
*/
|
|
131
|
+
export function getRevealState(
|
|
132
|
+
blocks: Block[],
|
|
133
|
+
stepsShown: number,
|
|
134
|
+
startedCues: Set<string>,
|
|
135
|
+
narrated = false,
|
|
136
|
+
): RevealState {
|
|
137
|
+
return {
|
|
138
|
+
stepsShown: narrated ? 0 : stepsShown,
|
|
139
|
+
revealSteps: getRevealSteps(blocks, narrated),
|
|
140
|
+
startedCues,
|
|
141
|
+
leaders: getRevealLeaders(blocks),
|
|
142
|
+
narrated,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface RevealNavigation {
|
|
147
|
+
/** The `stepsShown` a press of Next goes to, or null when no press would change what is shown. */
|
|
148
|
+
next: number | null;
|
|
149
|
+
/** The `stepsShown` a press of Back goes to, or null when going back would change nothing. */
|
|
150
|
+
previous: number | null;
|
|
151
|
+
/** How many presses change what is shown, from the first one; the count the stepper shows. */
|
|
152
|
+
presses: number;
|
|
153
|
+
/** How many of those are behind the learner. */
|
|
154
|
+
pressed: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Where Next and Back take a slide, so that every press shows something: a press that would change
|
|
159
|
+
* nothing is skipped. What is shown is every part's visibility, effects included. Back lands on
|
|
160
|
+
* the first press that shows what it goes back to, so Next and Back meet at the same places. On a
|
|
161
|
+
* narrated slide there are no presses: Next and Back go to the next and the previous step.
|
|
162
|
+
*/
|
|
163
|
+
export function getRevealNavigation(
|
|
164
|
+
blocks: Block[],
|
|
165
|
+
stepsShown: number,
|
|
166
|
+
startedCues: Set<string>,
|
|
167
|
+
narrated = false,
|
|
168
|
+
): RevealNavigation {
|
|
169
|
+
let parts = getTimedParts(blocks);
|
|
170
|
+
let total = getRevealSteps(blocks, narrated).length;
|
|
171
|
+
let at = Math.max(0, Math.min(stepsShown, total));
|
|
172
|
+
let shown = (count: number) => {
|
|
173
|
+
let state = getRevealState(blocks, count, startedCues, narrated);
|
|
174
|
+
return parts.map((part) => (isVisible(part, state) ? "1" : "0")).join("");
|
|
175
|
+
};
|
|
176
|
+
let states = Array.from({ length: total + 1 }, (_value, count) => shown(count));
|
|
177
|
+
|
|
178
|
+
let next: number | null = null;
|
|
179
|
+
for (let count = at + 1; count <= total; count++) {
|
|
180
|
+
if (states[count] !== states[at]) {
|
|
181
|
+
next = count;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let previous: number | null = null;
|
|
187
|
+
for (let count = at - 1; count >= 0; count--) {
|
|
188
|
+
if (states[count] !== states[at]) {
|
|
189
|
+
previous = count;
|
|
190
|
+
while (previous > 0 && states[previous - 1] === states[previous]) previous -= 1;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let presses = 0;
|
|
196
|
+
let pressed = 0;
|
|
197
|
+
for (let count = 1; count <= total; count++) {
|
|
198
|
+
if (states[count] === states[count - 1]) continue;
|
|
199
|
+
presses += 1;
|
|
200
|
+
if (count <= at) pressed += 1;
|
|
201
|
+
}
|
|
202
|
+
return { next, previous, presses, pressed };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Whether a block or list item shows right now: what it waits for has happened (Next on a slide
|
|
207
|
+
* without narration, its cue, or the part it goes with), and its `hideAt` cue has not started.
|
|
208
|
+
*/
|
|
209
|
+
export function isVisible(part: Timed, state: RevealState): boolean {
|
|
210
|
+
if (part.hideAt && state.startedCues.has(part.hideAt)) return false;
|
|
211
|
+
return isDue(part, state);
|
|
212
|
+
}
|
|
85
213
|
|
|
86
|
-
|
|
214
|
+
/** Whether a step is a slide with narration, where only the narration shows and hides parts. */
|
|
215
|
+
export function isNarratedSlide(step: Step | null | undefined) {
|
|
216
|
+
return step?.type === "slide" && step.narration != null;
|
|
87
217
|
}
|
|
@@ -144,7 +144,7 @@ describe("additions to version 2", () => {
|
|
|
144
144
|
it("refuses an unknown size, tone, layout or advance", () => {
|
|
145
145
|
let step = structuredClone(full[0]) as SlideStep;
|
|
146
146
|
(step.blocks[1] as { size: string }).size = "huge";
|
|
147
|
-
(step.blocks[2] as { tone: string }).tone = "
|
|
147
|
+
(step.blocks[2] as { tone: string }).tone = "purple";
|
|
148
148
|
(step as { layout: string }).layout = "wide";
|
|
149
149
|
(step as { advance: string }).advance = "always";
|
|
150
150
|
expect(issuesOf(step).map((issue) => issue.path)).toEqual(["layout", "advance", "blocks.1.size", "blocks.2.tone"]);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { isVisible, type RevealState } from "./cues";
|
|
2
|
+
import type { Block, BoxContentBlock, ContentBlock, EffectBlock } from "./schema";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_EFFECT_DURATION = 300;
|
|
5
|
+
|
|
6
|
+
/** What the effects on one part add up to right now, and how the part changes into it. */
|
|
7
|
+
export interface PartEffect {
|
|
8
|
+
/** In the slide's text size, or for a canvas item in percent of the canvas. */
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
scale: number;
|
|
12
|
+
/** `null` while no shown effect sets one. */
|
|
13
|
+
opacity: number | null;
|
|
14
|
+
/** Milliseconds before the change starts: the delay of the effect that came, 0 for one that went. */
|
|
15
|
+
delay: number;
|
|
16
|
+
duration: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Every effect block of a slide in document order, those in columns and boxes included. */
|
|
20
|
+
export function getEffectBlocks(blocks: Array<Block | ContentBlock | BoxContentBlock>): EffectBlock[] {
|
|
21
|
+
let effects: EffectBlock[] = [];
|
|
22
|
+
for (let block of blocks) {
|
|
23
|
+
if (block.type === "effect") effects.push(block);
|
|
24
|
+
if (block.type === "columns") {
|
|
25
|
+
for (let column of block.columns) effects.push(...getEffectBlocks(column.blocks));
|
|
26
|
+
}
|
|
27
|
+
if (block.type === "box") effects.push(...getEffectBlocks(block.blocks));
|
|
28
|
+
}
|
|
29
|
+
return effects;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function effectTargets(effect: EffectBlock): string[] {
|
|
33
|
+
return typeof effect.target === "string" ? [effect.target] : effect.target;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The ids of the effects that are shown, and so act on their targets, in this state. */
|
|
37
|
+
export function getActiveEffects(blocks: Block[], state: RevealState): Set<string> {
|
|
38
|
+
return new Set(
|
|
39
|
+
getEffectBlocks(blocks)
|
|
40
|
+
.filter((effect) => isVisible(effect, state))
|
|
41
|
+
.map((effect) => effect.id),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The state of every part an effect targets, whether or not an effect is shown now, so a part
|
|
47
|
+
* goes back with a transition when its effects stop. Moves add up, scales multiply, and the last
|
|
48
|
+
* shown opacity in document order wins.
|
|
49
|
+
*
|
|
50
|
+
* `previouslyActive` (the ids from `getActiveEffects` before this change) picks the timing: of the
|
|
51
|
+
* effects on a part that came or went, the last in the document decides. A part whose effects did
|
|
52
|
+
* not change keeps the timing of its last shown effect.
|
|
53
|
+
*/
|
|
54
|
+
export function getPartEffects(
|
|
55
|
+
blocks: Block[],
|
|
56
|
+
state: RevealState,
|
|
57
|
+
previouslyActive?: ReadonlySet<string>,
|
|
58
|
+
): Map<string, PartEffect> {
|
|
59
|
+
let parts = new Map<string, PartEffect>();
|
|
60
|
+
let effects = getEffectBlocks(blocks);
|
|
61
|
+
let effectIds = new Set(effects.map((effect) => effect.id));
|
|
62
|
+
let decided = new Set<string>();
|
|
63
|
+
let active = getActiveEffects(blocks, state);
|
|
64
|
+
|
|
65
|
+
// Last first, so the first effect met for a part is the one that decides its timing
|
|
66
|
+
for (let effect of [...effects].reverse()) {
|
|
67
|
+
let on = active.has(effect.id);
|
|
68
|
+
let changed = previouslyActive != null && previouslyActive.has(effect.id) !== on;
|
|
69
|
+
|
|
70
|
+
for (let target of effectTargets(effect)) {
|
|
71
|
+
if (target === effect.id || effectIds.has(target)) continue;
|
|
72
|
+
let part = parts.get(target);
|
|
73
|
+
if (!part) {
|
|
74
|
+
part = { x: 0, y: 0, scale: 1, opacity: null, delay: 0, duration: DEFAULT_EFFECT_DURATION };
|
|
75
|
+
parts.set(target, part);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!decided.has(target) && (changed || (on && !changedOnPart(target, effects, active, previouslyActive)))) {
|
|
79
|
+
decided.add(target);
|
|
80
|
+
part.delay = on ? (effect.delay ?? 0) : 0;
|
|
81
|
+
part.duration = effect.duration ?? DEFAULT_EFFECT_DURATION;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!on) continue;
|
|
85
|
+
part.x += effect.move?.x ?? 0;
|
|
86
|
+
part.y += effect.move?.y ?? 0;
|
|
87
|
+
part.scale *= effect.scale ?? 1;
|
|
88
|
+
// Walking backwards, the first opacity met is the last in the document
|
|
89
|
+
if (part.opacity === null && effect.opacity != null) part.opacity = effect.opacity;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return parts;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Whether any effect on the part came or went, which then decides the timing over a still one. */
|
|
96
|
+
function changedOnPart(
|
|
97
|
+
target: string,
|
|
98
|
+
effects: EffectBlock[],
|
|
99
|
+
active: Set<string>,
|
|
100
|
+
previouslyActive: ReadonlySet<string> | undefined,
|
|
101
|
+
) {
|
|
102
|
+
if (!previouslyActive) return false;
|
|
103
|
+
return effects.some(
|
|
104
|
+
(effect) => effectTargets(effect).includes(target) && previouslyActive.has(effect.id) !== active.has(effect.id),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
getRevealLeaders,
|
|
4
|
+
getRevealNavigation,
|
|
5
|
+
getRevealState,
|
|
6
|
+
getRevealSteps,
|
|
7
|
+
getTimedParts,
|
|
8
|
+
isVisible,
|
|
9
|
+
type RevealState,
|
|
10
|
+
} from "./cues";
|
|
11
|
+
import { getActiveEffects, getPartEffects } from "./effects";
|
|
12
|
+
import type { Block, SlideStep } from "./schema";
|
|
13
|
+
import { validateStep } from "./validate";
|
|
14
|
+
|
|
15
|
+
function issuesOf(input: unknown) {
|
|
16
|
+
let result = validateStep(input);
|
|
17
|
+
return result.ok ? [] : result.issues;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function stateOf(blocks: Block[], stepsShown: number, ...cues: string[]): RevealState {
|
|
21
|
+
return {
|
|
22
|
+
stepsShown,
|
|
23
|
+
revealSteps: getRevealSteps(blocks),
|
|
24
|
+
startedCues: new Set(cues),
|
|
25
|
+
leaders: getRevealLeaders(blocks),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function shownIds(blocks: Block[], state: RevealState) {
|
|
30
|
+
return blocks.filter((block) => isVisible(block, state)).map((block) => block.id);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let narrated = (blocks: Block[]): SlideStep => ({
|
|
34
|
+
schemaVersion: 2,
|
|
35
|
+
type: "slide",
|
|
36
|
+
narration: {
|
|
37
|
+
media: { src: "/media/course/a.m4a" },
|
|
38
|
+
cues: [
|
|
39
|
+
{ id: "c1", start: 1 },
|
|
40
|
+
{ id: "c2", start: 2 },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
blocks,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("with the previous", () => {
|
|
47
|
+
let blocks: Block[] = [
|
|
48
|
+
{ id: "h", type: "heading", text: "Tittel" },
|
|
49
|
+
{ id: "box", type: "text", text: "Boks", reveal: "step" },
|
|
50
|
+
{ id: "arrow", type: "image", src: "resource:1", reveal: "with-previous" },
|
|
51
|
+
{ id: "note", type: "text", text: "Merk", reveal: "with-previous", delay: 500 },
|
|
52
|
+
{ id: "next", type: "text", text: "Neste", reveal: "step" },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
it("is not a press of Next of its own", () => {
|
|
56
|
+
expect(getRevealSteps(blocks)).toEqual(["box", "next"]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("follows the nearest part above that waits, through a chain", () => {
|
|
60
|
+
let leaders = getRevealLeaders(blocks);
|
|
61
|
+
expect(leaders.get("arrow")?.id).toBe("box");
|
|
62
|
+
expect(leaders.get("note")?.id).toBe("arrow");
|
|
63
|
+
expect(shownIds(blocks, stateOf(blocks, 0))).toEqual(["h"]);
|
|
64
|
+
expect(shownIds(blocks, stateOf(blocks, 1))).toEqual(["h", "box", "arrow", "note"]);
|
|
65
|
+
expect(shownIds(blocks, stateOf(blocks, 2))).toEqual(["h", "box", "arrow", "note", "next"]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("follows a cue as well as Next, and goes away by its own cue", () => {
|
|
69
|
+
let cued: Block[] = [
|
|
70
|
+
{ id: "a", type: "text", text: "A", revealAt: "c1", hideAt: "c2" },
|
|
71
|
+
{ id: "b", type: "text", text: "B", reveal: "with-previous" },
|
|
72
|
+
{ id: "c", type: "text", text: "C", reveal: "with-previous", hideAt: "c2" },
|
|
73
|
+
];
|
|
74
|
+
expect(shownIds(cued, stateOf(cued, 0))).toEqual([]);
|
|
75
|
+
expect(shownIds(cued, stateOf(cued, 0, "c1"))).toEqual(["a", "b", "c"]);
|
|
76
|
+
expect(shownIds(cued, stateOf(cued, 0, "c1", "c2"))).toEqual(["b"]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("is there from the start with nothing above that waits, or without the leaders", () => {
|
|
80
|
+
let first: Block[] = [
|
|
81
|
+
{ id: "h", type: "heading", text: "H" },
|
|
82
|
+
{ id: "t", type: "text", text: "T", reveal: "with-previous" },
|
|
83
|
+
];
|
|
84
|
+
expect(shownIds(first, stateOf(first, 0))).toEqual(["h", "t"]);
|
|
85
|
+
expect(isVisible(blocks[2], { stepsShown: 0, revealSteps: ["box", "next"], startedCues: new Set() })).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("follows a part in a list or a column too", () => {
|
|
89
|
+
let nested: Block[] = [
|
|
90
|
+
{ id: "l", type: "list", items: [{ id: "i1", text: "En", reveal: "step" }] },
|
|
91
|
+
{
|
|
92
|
+
id: "cols",
|
|
93
|
+
type: "columns",
|
|
94
|
+
columns: [
|
|
95
|
+
{ id: "left", blocks: [{ id: "t", type: "text", text: "T", reveal: "with-previous" }] },
|
|
96
|
+
{ id: "right", blocks: [] },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
expect(getRevealLeaders(nested).get("t")?.id).toBe("i1");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("validation of round two", () => {
|
|
105
|
+
it("accepts with-previous, a delay on a waiting part, and effects", () => {
|
|
106
|
+
expect(
|
|
107
|
+
issuesOf(
|
|
108
|
+
narrated([
|
|
109
|
+
{ id: "h", type: "heading", text: "Velkommen" },
|
|
110
|
+
{ id: "l", type: "list", items: [{ id: "i1", text: "En", reveal: "step", delay: 200 }] },
|
|
111
|
+
{ id: "up", type: "effect", target: "h", move: { y: -2 }, reveal: "with-previous", duration: 600 },
|
|
112
|
+
{ id: "fade", type: "effect", target: ["h", "i1"], opacity: 0.4, scale: 0.9, revealAt: "c1", delay: 100 },
|
|
113
|
+
]),
|
|
114
|
+
),
|
|
115
|
+
).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("refuses a delay on a part that does not wait, and values out of range", () => {
|
|
119
|
+
expect(issuesOf(narrated([{ id: "t", type: "text", text: "T", delay: 100 }]))).toEqual([
|
|
120
|
+
{ path: "blocks.0.delay", message: "Only a part that waits to be shown can have a delay." },
|
|
121
|
+
]);
|
|
122
|
+
expect(issuesOf(narrated([{ id: "t", type: "text", text: "T", reveal: "step", delay: 6000 }]))).not.toEqual([]);
|
|
123
|
+
expect(issuesOf(narrated([{ id: "t", type: "text", text: "T", reveal: "later" } as never]))).not.toEqual([]);
|
|
124
|
+
let effect = { id: "e", type: "effect", target: "t" };
|
|
125
|
+
let text = { id: "t", type: "text", text: "T" } as const;
|
|
126
|
+
expect(issuesOf(narrated([text, { ...effect, opacity: 2 } as never]))).not.toEqual([]);
|
|
127
|
+
expect(issuesOf(narrated([text, { ...effect, scale: -1 } as never]))).not.toEqual([]);
|
|
128
|
+
expect(issuesOf(narrated([text, { ...effect, duration: 10 } as never]))).not.toEqual([]);
|
|
129
|
+
expect(issuesOf(narrated([text, { ...effect, target: [] } as never]))).not.toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("checks what an effect acts on", () => {
|
|
133
|
+
expect(
|
|
134
|
+
issuesOf(
|
|
135
|
+
narrated([
|
|
136
|
+
{ id: "t", type: "text", text: "T" },
|
|
137
|
+
{ id: "a", type: "effect", target: ["t", "missing"] },
|
|
138
|
+
{ id: "b", type: "effect", target: "a" },
|
|
139
|
+
{ id: "c", type: "effect", target: "c" },
|
|
140
|
+
]),
|
|
141
|
+
),
|
|
142
|
+
).toEqual([
|
|
143
|
+
{ path: "blocks.1.target.1", message: 'There is no part with the id "missing".' },
|
|
144
|
+
{ path: "blocks.2.target", message: "An effect cannot act on an effect." },
|
|
145
|
+
{ path: "blocks.3.target", message: "An effect cannot act on an effect." },
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("lets an effect in a column act on a canvas item", () => {
|
|
150
|
+
expect(
|
|
151
|
+
issuesOf(
|
|
152
|
+
narrated([
|
|
153
|
+
{ id: "cv", type: "canvas", items: [{ id: "arrow", type: "image", src: "resource:1", x: 10, y: 10 }] },
|
|
154
|
+
{
|
|
155
|
+
id: "cols",
|
|
156
|
+
type: "columns",
|
|
157
|
+
columns: [
|
|
158
|
+
{ id: "left", blocks: [{ id: "e", type: "effect", target: "arrow", move: { x: 5 }, reveal: "step" }] },
|
|
159
|
+
{ id: "right", blocks: [] },
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
]),
|
|
163
|
+
),
|
|
164
|
+
).toEqual([]);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("getPartEffects", () => {
|
|
169
|
+
let blocks: Block[] = [
|
|
170
|
+
{ id: "h", type: "heading", text: "H" },
|
|
171
|
+
{ id: "l", type: "list", items: [{ id: "i1", text: "En" }] },
|
|
172
|
+
{ id: "up", type: "effect", target: "h", move: { y: -2 }, scale: 0.8, reveal: "step", delay: 100, duration: 600 },
|
|
173
|
+
{
|
|
174
|
+
id: "right",
|
|
175
|
+
type: "effect",
|
|
176
|
+
target: ["h", "i1"],
|
|
177
|
+
move: { x: 3, y: 1 },
|
|
178
|
+
scale: 0.5,
|
|
179
|
+
opacity: 0.5,
|
|
180
|
+
revealAt: "c1",
|
|
181
|
+
},
|
|
182
|
+
{ id: "dim", type: "effect", target: "h", opacity: 0.2, revealAt: "c2" },
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
it("lists every target, at rest while no effect is shown", () => {
|
|
186
|
+
let effects = getPartEffects(blocks, stateOf(blocks, 0));
|
|
187
|
+
expect(effects.get("h")).toMatchObject({ x: 0, y: 0, scale: 1, opacity: null });
|
|
188
|
+
expect(effects.get("i1")).toMatchObject({ x: 0, y: 0, scale: 1, opacity: null });
|
|
189
|
+
expect(effects.has("l")).toBe(false);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("adds moves, multiplies scales and lets the last opacity win", () => {
|
|
193
|
+
let effects = getPartEffects(blocks, stateOf(blocks, 1, "c1", "c2"));
|
|
194
|
+
expect(effects.get("h")).toMatchObject({ x: 3, y: -1, scale: 0.4, opacity: 0.2 });
|
|
195
|
+
expect(effects.get("i1")).toMatchObject({ x: 3, y: 1, scale: 0.5, opacity: 0.5 });
|
|
196
|
+
expect(getPartEffects(blocks, stateOf(blocks, 1, "c1")).get("h")?.opacity).toBe(0.5);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("takes the timing of the effect that came, and none of the delay for one that went", () => {
|
|
200
|
+
let before = getActiveEffects(blocks, stateOf(blocks, 0));
|
|
201
|
+
let came = getPartEffects(blocks, stateOf(blocks, 1), before);
|
|
202
|
+
expect(came.get("h")).toMatchObject({ delay: 100, duration: 600 });
|
|
203
|
+
|
|
204
|
+
let went = getPartEffects(blocks, stateOf(blocks, 0), getActiveEffects(blocks, stateOf(blocks, 1)));
|
|
205
|
+
expect(went.get("h")).toMatchObject({ x: 0, y: 0, delay: 0, duration: 600 });
|
|
206
|
+
|
|
207
|
+
// Of the effects on a part, the one that came decides, not the one that stayed
|
|
208
|
+
let other = getPartEffects(blocks, stateOf(blocks, 1, "c1"), getActiveEffects(blocks, stateOf(blocks, 1)));
|
|
209
|
+
expect(other.get("h")).toMatchObject({ delay: 0, duration: 300 });
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe("a narrated slide: only the narration shows and hides parts", () => {
|
|
214
|
+
// Scenes as converted slides and the demo wrote them: on a cue, and also marked for Next
|
|
215
|
+
let scenes: Block[] = [
|
|
216
|
+
{ id: "s1", type: "text", text: "1", hideAt: "c1" },
|
|
217
|
+
{ id: "s2", type: "text", text: "2", reveal: "step", revealAt: "c1", hideAt: "c2" },
|
|
218
|
+
{ id: "s3", type: "text", text: "3", revealAt: "c2" },
|
|
219
|
+
{ id: "label", type: "text", text: "Merk", reveal: "with-previous" },
|
|
220
|
+
{ id: "dim", type: "effect", target: "s3", opacity: 0.5, revealAt: "c3" },
|
|
221
|
+
{ id: "always", type: "text", text: "Alltid", reveal: "step" },
|
|
222
|
+
{ id: "follows", type: "text", text: "Med", reveal: "with-previous" },
|
|
223
|
+
];
|
|
224
|
+
|
|
225
|
+
let shownAt = (stepsShown: number, ...started: string[]) => {
|
|
226
|
+
let state = getRevealState(scenes, stepsShown, new Set(started), true);
|
|
227
|
+
return getTimedParts(scenes)
|
|
228
|
+
.filter((part) => isVisible(part, state))
|
|
229
|
+
.map((part) => part.id);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
it("has no presses of Next", () => {
|
|
233
|
+
expect(getRevealSteps(scenes, true)).toEqual([]);
|
|
234
|
+
expect(getRevealSteps(scenes)).toEqual(["s2", "always"]);
|
|
235
|
+
expect(getRevealNavigation(scenes, 0, new Set(), true)).toEqual({
|
|
236
|
+
next: null,
|
|
237
|
+
previous: null,
|
|
238
|
+
presses: 0,
|
|
239
|
+
pressed: 0,
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("follows the cues whatever stepsShown says, and shows a part only marked for Next from the start", () => {
|
|
244
|
+
expect(shownAt(0)).toEqual(["s1", "always", "follows"]);
|
|
245
|
+
expect(shownAt(5)).toEqual(["s1", "always", "follows"]);
|
|
246
|
+
expect(shownAt(0, "c1")).toEqual(["s2", "always", "follows"]);
|
|
247
|
+
expect(shownAt(0, "c1", "c2")).toEqual(["s3", "label", "always", "follows"]);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("switches effects on their cues", () => {
|
|
251
|
+
let state = getRevealState(scenes, 0, new Set(["c1", "c2"]), true);
|
|
252
|
+
expect(getPartEffects(scenes, state).get("s3")?.opacity).toBeNull();
|
|
253
|
+
state = getRevealState(scenes, 0, new Set(["c1", "c2", "c3"]), true);
|
|
254
|
+
expect(getPartEffects(scenes, state).get("s3")?.opacity).toBe(0.5);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("leaves a slide without narration stepping as before", () => {
|
|
258
|
+
let state = getRevealState(scenes, 1, new Set(), false);
|
|
259
|
+
expect(isVisible(scenes[1], state)).toBe(true);
|
|
260
|
+
expect(isVisible(scenes[5], state)).toBe(false);
|
|
261
|
+
expect(getRevealNavigation(scenes, 1, new Set(), false)).toMatchObject({ next: 2, previous: 0, presses: 2 });
|
|
262
|
+
});
|
|
263
|
+
});
|