@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,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
|
+
});
|
package/src/document/schema.ts
CHANGED
|
@@ -9,14 +9,17 @@ import {
|
|
|
9
9
|
boolean,
|
|
10
10
|
type InferOutput,
|
|
11
11
|
literal,
|
|
12
|
+
maxValue,
|
|
12
13
|
minLength,
|
|
13
14
|
minValue,
|
|
14
15
|
number,
|
|
15
16
|
optional,
|
|
16
17
|
picklist,
|
|
17
18
|
pipe,
|
|
19
|
+
regex,
|
|
18
20
|
strictObject,
|
|
19
21
|
string,
|
|
22
|
+
union,
|
|
20
23
|
variant,
|
|
21
24
|
} from "valibot";
|
|
22
25
|
|
|
@@ -73,18 +76,43 @@ export const narrationSchema = strictObject({
|
|
|
73
76
|
* When a block shows. Without any of these it is there from the start.
|
|
74
77
|
* `reveal: "step"` shows it on the next press of Next, in document order. `revealAt` shows it
|
|
75
78
|
* when the cue with that id starts. `hideAt` removes it again when that cue starts.
|
|
79
|
+
*
|
|
80
|
+
* A part waiting to be shown keeps its place, so the slide does not jump when it comes. A part
|
|
81
|
+
* that also has `hideAt` is a passing one and takes no place before it shows or after it has
|
|
82
|
+
* gone, so parts that follow each other in time (one scene per stretch of the narration) stand
|
|
83
|
+
* in the same spot.
|
|
84
|
+
*
|
|
85
|
+
* `reveal: "with-previous"` is not a press of its own: the part shows when the nearest part above
|
|
86
|
+
* it (in document order) that waits to be shown does, by Next or by its cue. Without such a part
|
|
87
|
+
* it is there from the start. `delay` shows a waiting part that many milliseconds after it is due.
|
|
76
88
|
*/
|
|
77
89
|
let timing = {
|
|
78
|
-
reveal: optional(
|
|
90
|
+
reveal: optional(picklist(["step", "with-previous"])),
|
|
79
91
|
revealAt: optional(id),
|
|
80
92
|
hideAt: optional(id),
|
|
93
|
+
delay: optional(pipe(number(), minValue(0), maxValue(5000))),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
let milliseconds = {
|
|
97
|
+
/** Milliseconds before it starts, 0 to 5000. */
|
|
98
|
+
delay: optional(pipe(number(), minValue(0), maxValue(5000))),
|
|
99
|
+
/** Milliseconds it takes, 50 to 3000. Default 300. */
|
|
100
|
+
duration: optional(pipe(number(), minValue(50), maxValue(3000))),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** How a heading or text is dressed: `caps` writes it in capitals, `shadow` gives the letters a shadow, for words on a picture. */
|
|
104
|
+
let look = {
|
|
105
|
+
caps: optional(boolean()),
|
|
106
|
+
shadow: optional(boolean()),
|
|
81
107
|
};
|
|
82
108
|
|
|
83
109
|
export const headingBlockSchema = strictObject({
|
|
84
110
|
id,
|
|
85
111
|
type: literal("heading"),
|
|
112
|
+
/** One line of Markdown. */
|
|
86
113
|
text,
|
|
87
114
|
level: optional(picklist([1, 2, 3])),
|
|
115
|
+
...look,
|
|
88
116
|
...timing,
|
|
89
117
|
});
|
|
90
118
|
|
|
@@ -93,12 +121,15 @@ export const textBlockSchema = strictObject({
|
|
|
93
121
|
type: literal("text"),
|
|
94
122
|
/** Markdown. */
|
|
95
123
|
text,
|
|
124
|
+
...look,
|
|
96
125
|
...timing,
|
|
97
126
|
});
|
|
98
127
|
|
|
99
128
|
export const listItemSchema = strictObject({
|
|
100
129
|
id,
|
|
101
130
|
text,
|
|
131
|
+
/** A point under the point above it: 1 for a sub-point, 2 for a point under a sub-point. */
|
|
132
|
+
indent: optional(picklist([1, 2])),
|
|
102
133
|
...timing,
|
|
103
134
|
});
|
|
104
135
|
|
|
@@ -136,7 +167,7 @@ export const calloutBlockSchema = strictObject({
|
|
|
136
167
|
/** Markdown. */
|
|
137
168
|
text,
|
|
138
169
|
/** The colour of the box. Default `neutral`. */
|
|
139
|
-
tone: optional(picklist(["neutral", "info", "success", "warning"])),
|
|
170
|
+
tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
|
|
140
171
|
...timing,
|
|
141
172
|
});
|
|
142
173
|
|
|
@@ -149,6 +180,26 @@ export const videoLinkBlockSchema = strictObject({
|
|
|
149
180
|
...timing,
|
|
150
181
|
});
|
|
151
182
|
|
|
183
|
+
/**
|
|
184
|
+
* A block that shows nothing and acts on other parts while it is shown (by its timing, like any
|
|
185
|
+
* part): it moves, scales or fades its targets, and they go back when it stops. `move` is in the
|
|
186
|
+
* slide's text size (1 is about the height of a letter of the ordinary text), or for an item on a
|
|
187
|
+
* canvas in percent of the canvas's width (`x`) and height (`y`). Several effects on one part
|
|
188
|
+
* combine: moves add up, scales multiply, and the last opacity in the document wins.
|
|
189
|
+
*/
|
|
190
|
+
export const effectBlockSchema = strictObject({
|
|
191
|
+
id,
|
|
192
|
+
type: literal("effect"),
|
|
193
|
+
/** The id of a part of the slide, or several. Not an effect. */
|
|
194
|
+
target: union([id, pipe(array(id), minLength(1))]),
|
|
195
|
+
move: optional(strictObject({ x: optional(number()), y: optional(number()) })),
|
|
196
|
+
scale: optional(pipe(number(), minValue(0))),
|
|
197
|
+
opacity: optional(pipe(number(), minValue(0), maxValue(1))),
|
|
198
|
+
...timing,
|
|
199
|
+
/** Milliseconds the change takes, 50 to 3000. Default 300. `delay` holds it back after it is due. */
|
|
200
|
+
duration: milliseconds.duration,
|
|
201
|
+
});
|
|
202
|
+
|
|
152
203
|
/** Every block that can stand inside a column. Columns do not nest. */
|
|
153
204
|
export const contentBlockSchema = variant("type", [
|
|
154
205
|
headingBlockSchema,
|
|
@@ -158,6 +209,7 @@ export const contentBlockSchema = variant("type", [
|
|
|
158
209
|
quoteBlockSchema,
|
|
159
210
|
calloutBlockSchema,
|
|
160
211
|
videoLinkBlockSchema,
|
|
212
|
+
effectBlockSchema,
|
|
161
213
|
]);
|
|
162
214
|
|
|
163
215
|
export const columnSchema = strictObject({
|
|
@@ -172,6 +224,59 @@ export const columnsBlockSchema = strictObject({
|
|
|
172
224
|
...timing,
|
|
173
225
|
});
|
|
174
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Where an item stands on its canvas, in percent of the canvas: `x` from the left edge or `right`
|
|
229
|
+
* from the right one, `y` from the top or `bottom` from the bottom. Without a width a text is as
|
|
230
|
+
* wide as its words and an image keeps its proportions.
|
|
231
|
+
*/
|
|
232
|
+
let canvasPlace = {
|
|
233
|
+
x: optional(number()),
|
|
234
|
+
y: optional(number()),
|
|
235
|
+
right: optional(number()),
|
|
236
|
+
bottom: optional(number()),
|
|
237
|
+
width: optional(number()),
|
|
238
|
+
height: optional(number()),
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export const canvasTextSchema = strictObject({
|
|
242
|
+
id,
|
|
243
|
+
type: literal("text"),
|
|
244
|
+
/** Markdown. */
|
|
245
|
+
text,
|
|
246
|
+
/** `solid`: on a white surface that covers what is under it. `frame`: the same with a coloured frame. */
|
|
247
|
+
surface: optional(picklist(["none", "solid", "frame"])),
|
|
248
|
+
/** The colour of the frame. Default `neutral`. */
|
|
249
|
+
tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
|
|
250
|
+
/** The text size, as a factor of the canvas's normal size. Default 1. */
|
|
251
|
+
size: optional(pipe(number(), minValue(0.1))),
|
|
252
|
+
...canvasPlace,
|
|
253
|
+
...timing,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
export const canvasImageSchema = strictObject({
|
|
257
|
+
id,
|
|
258
|
+
type: literal("image"),
|
|
259
|
+
src: source,
|
|
260
|
+
alt: optional(text),
|
|
261
|
+
...canvasPlace,
|
|
262
|
+
...timing,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A figure with a coordinate system of its own: images and texts placed by percent on an area of
|
|
267
|
+
* fixed proportions, later items on top of earlier ones. Everything scales with the canvas, the
|
|
268
|
+
* text included, so the parts keep their places at any size. Always light, like a sheet of paper,
|
|
269
|
+
* so a surface can cover a part of a picture. Does not stand in a column.
|
|
270
|
+
*/
|
|
271
|
+
export const canvasBlockSchema = strictObject({
|
|
272
|
+
id,
|
|
273
|
+
type: literal("canvas"),
|
|
274
|
+
/** Width to height, e.g. `16/9` (the default) or `4/3`. */
|
|
275
|
+
aspect: optional(pipe(string(), regex(/^\d+(\.\d+)?\s*\/\s*\d+(\.\d+)?$/))),
|
|
276
|
+
items: array(variant("type", [canvasTextSchema, canvasImageSchema])),
|
|
277
|
+
...timing,
|
|
278
|
+
});
|
|
279
|
+
|
|
175
280
|
export const blockSchema = variant("type", [
|
|
176
281
|
headingBlockSchema,
|
|
177
282
|
textBlockSchema,
|
|
@@ -180,7 +285,9 @@ export const blockSchema = variant("type", [
|
|
|
180
285
|
quoteBlockSchema,
|
|
181
286
|
calloutBlockSchema,
|
|
182
287
|
videoLinkBlockSchema,
|
|
288
|
+
effectBlockSchema,
|
|
183
289
|
columnsBlockSchema,
|
|
290
|
+
canvasBlockSchema,
|
|
184
291
|
]);
|
|
185
292
|
|
|
186
293
|
let version = literal(STEP_SCHEMA_VERSION);
|
|
@@ -191,16 +298,52 @@ let version = literal(STEP_SCHEMA_VERSION);
|
|
|
191
298
|
*/
|
|
192
299
|
let advance = optional(literal("auto"));
|
|
193
300
|
|
|
301
|
+
/**
|
|
302
|
+
* One animation of a step change. `on: "enter"` runs as the step comes in, `on: "exit"` as it
|
|
303
|
+
* leaves. `target` is `step` (the default: the whole step box), `content` or `background` (a
|
|
304
|
+
* slide's blocks or its background image) or the id of a part of the step. `slide` comes from
|
|
305
|
+
* (or leaves to) `from`: right on enter and left on exit by default, mirrored when the learner
|
|
306
|
+
* goes back. Several items on one target run together, each with its own delay and duration.
|
|
307
|
+
*/
|
|
308
|
+
export const transitionSchema = strictObject({
|
|
309
|
+
on: picklist(["enter", "exit"]),
|
|
310
|
+
effect: picklist(["fade", "slide", "zoom", "none"]),
|
|
311
|
+
from: optional(picklist(["left", "right", "top", "bottom"])),
|
|
312
|
+
target: optional(pipe(string(), minLength(1))),
|
|
313
|
+
...milliseconds,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Left out, the step fades out and the next fades in. Given, it replaces that default on both
|
|
318
|
+
* sides: only what is listed animates, and an empty list changes the step at once.
|
|
319
|
+
*/
|
|
320
|
+
let transitions = optional(array(transitionSchema));
|
|
321
|
+
|
|
194
322
|
/** Blocks on a page, optionally narrated. */
|
|
195
323
|
export const slideStepSchema = strictObject({
|
|
196
324
|
schemaVersion: version,
|
|
197
325
|
type: literal("slide"),
|
|
198
|
-
/**
|
|
199
|
-
|
|
326
|
+
/**
|
|
327
|
+
* `title`: a title page, the first heading large and centred, typically over a background image.
|
|
328
|
+
* `banner`: a title page whose background image is a band across the step, in its own
|
|
329
|
+
* proportions and with a coloured border above and below, with the blocks on top of it.
|
|
330
|
+
*/
|
|
331
|
+
layout: optional(picklist(["default", "centered", "title", "banner"])),
|
|
200
332
|
/** A background image behind the blocks. */
|
|
201
333
|
background: optional(source),
|
|
334
|
+
/**
|
|
335
|
+
* How wide the blocks may get: `narrow` for a few lines or a single callout, `medium`, or
|
|
336
|
+
* `wide`, the default. The slide is never wider than the step it is shown in.
|
|
337
|
+
*/
|
|
338
|
+
width: optional(picklist(["narrow", "medium", "wide"])),
|
|
339
|
+
/**
|
|
340
|
+
* Over a background image the blocks sit on a panel so they stay readable. `false` leaves the
|
|
341
|
+
* panel out, for blocks that bring a surface of their own (callouts). No effect without a background.
|
|
342
|
+
*/
|
|
343
|
+
panel: optional(boolean()),
|
|
202
344
|
narration: optional(narrationSchema),
|
|
203
345
|
advance,
|
|
346
|
+
transitions,
|
|
204
347
|
blocks: array(blockSchema),
|
|
205
348
|
});
|
|
206
349
|
|
|
@@ -213,6 +356,7 @@ export const videoStepSchema = strictObject({
|
|
|
213
356
|
/** An image shown behind and around the video. */
|
|
214
357
|
background: optional(source),
|
|
215
358
|
advance,
|
|
359
|
+
transitions,
|
|
216
360
|
});
|
|
217
361
|
|
|
218
362
|
/** A document the learner opens and then confirms having read. */
|
|
@@ -225,6 +369,7 @@ export const pdfStepSchema = strictObject({
|
|
|
225
369
|
file: source,
|
|
226
370
|
/** The wording of the confirmation, e.g. "Jeg har lest og forstått". */
|
|
227
371
|
confirm: text,
|
|
372
|
+
transitions,
|
|
228
373
|
});
|
|
229
374
|
|
|
230
375
|
/**
|
|
@@ -239,18 +384,23 @@ export const quizStepSchema = strictObject({
|
|
|
239
384
|
text: optional(text),
|
|
240
385
|
/** Plays on the intro, before the quiz is started. Never holds the quiz back. */
|
|
241
386
|
narration: optional(narrationSchema),
|
|
387
|
+
transitions,
|
|
242
388
|
});
|
|
243
389
|
|
|
244
390
|
export const stepSchema = variant("type", [slideStepSchema, videoStepSchema, pdfStepSchema, quizStepSchema]);
|
|
245
391
|
|
|
246
392
|
export type Cue = InferOutput<typeof cueSchema>;
|
|
393
|
+
export type StepTransition = InferOutput<typeof transitionSchema>;
|
|
247
394
|
export type Media = InferOutput<typeof mediaSchema>;
|
|
248
395
|
export type Narration = InferOutput<typeof narrationSchema>;
|
|
249
396
|
export type CalloutBlock = InferOutput<typeof calloutBlockSchema>;
|
|
397
|
+
export type EffectBlock = InferOutput<typeof effectBlockSchema>;
|
|
250
398
|
export type ImageSize = NonNullable<InferOutput<typeof imageBlockSchema>["size"]>;
|
|
251
399
|
export type ListItem = InferOutput<typeof listItemSchema>;
|
|
252
400
|
export type ContentBlock = InferOutput<typeof contentBlockSchema>;
|
|
253
401
|
export type ColumnsBlock = InferOutput<typeof columnsBlockSchema>;
|
|
402
|
+
export type CanvasBlock = InferOutput<typeof canvasBlockSchema>;
|
|
403
|
+
export type CanvasItem = CanvasBlock["items"][number];
|
|
254
404
|
export type Block = InferOutput<typeof blockSchema>;
|
|
255
405
|
export type SlideStep = InferOutput<typeof slideStepSchema>;
|
|
256
406
|
export type VideoStep = InferOutput<typeof videoStepSchema>;
|
|
@@ -260,4 +410,10 @@ export type Step = InferOutput<typeof stepSchema>;
|
|
|
260
410
|
export type StepType = Step["type"];
|
|
261
411
|
|
|
262
412
|
/** What can carry `reveal`, `revealAt` and `hideAt`: a block, or an item of a list. */
|
|
263
|
-
export type Timed = {
|
|
413
|
+
export type Timed = {
|
|
414
|
+
id: string;
|
|
415
|
+
reveal?: "step" | "with-previous";
|
|
416
|
+
revealAt?: string;
|
|
417
|
+
hideAt?: string;
|
|
418
|
+
delay?: number;
|
|
419
|
+
};
|
package/src/document/validate.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
2
2
|
import { getDotPath, safeParse } from "valibot";
|
|
3
|
-
import { getCues } from "./cues";
|
|
4
|
-
import {
|
|
3
|
+
import { getCues, hasTrigger } from "./cues";
|
|
4
|
+
import { effectTargets, getEffectBlocks } from "./effects";
|
|
5
|
+
import { type Media, type SlideStep, type Step, stepSchema, type Timed } from "./schema";
|
|
5
6
|
|
|
6
7
|
export interface StepIssue {
|
|
7
8
|
/** Where in the document, as a dot path (`blocks.2.items.0.revealAt`). Empty for the document itself. */
|
|
@@ -14,7 +15,8 @@ export type StepValidation = { ok: true; step: Step } | { ok: false; issues: Ste
|
|
|
14
15
|
/**
|
|
15
16
|
* Checks a step document: its shape first, then what the shape cannot express - ids that are
|
|
16
17
|
* used twice, cues that end before they start or are out of order, media that ends before it
|
|
17
|
-
* starts,
|
|
18
|
+
* starts, `revealAt` / `hideAt` naming a cue that does not exist, a delay on a part that does not
|
|
19
|
+
* wait, an effect or a transition whose target is not on the step.
|
|
18
20
|
*/
|
|
19
21
|
export function validateStep(input: unknown): StepValidation {
|
|
20
22
|
let parsed = safeParse(stepSchema, input);
|
|
@@ -62,12 +64,80 @@ export function validateStep(input: unknown): StepValidation {
|
|
|
62
64
|
issues.push({ path: `${path}.${key}`, message: `There is no cue with the id "${cueId}".` });
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
|
|
68
|
+
if (part.delay != null && !hasTrigger(part) && !isEffect(part)) {
|
|
69
|
+
issues.push({ path: `${path}.delay`, message: "Only a part that waits to be shown can have a delay." });
|
|
70
|
+
}
|
|
65
71
|
}
|
|
72
|
+
issues.push(...effectIssues(step));
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
issues.push(...transitionIssues(step));
|
|
76
|
+
|
|
68
77
|
return issues.length > 0 ? { ok: false, issues } : { ok: true, step };
|
|
69
78
|
}
|
|
70
79
|
|
|
80
|
+
function isEffect(part: Timed) {
|
|
81
|
+
return (part as { type?: string }).type === "effect";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The ids an effect or a transition can act on: every part of the slide except the effects, which show nothing. */
|
|
85
|
+
function targetableIds(step: SlideStep) {
|
|
86
|
+
let ids = new Set<string>();
|
|
87
|
+
for (let { part } of walk(step)) if (!isEffect(part)) ids.add(part.id);
|
|
88
|
+
return ids;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** An effect must name parts of the slide, and not itself or another effect. */
|
|
92
|
+
function effectIssues(step: SlideStep): StepIssue[] {
|
|
93
|
+
let issues: StepIssue[] = [];
|
|
94
|
+
let targetable = targetableIds(step);
|
|
95
|
+
let paths = new Map<string, string>();
|
|
96
|
+
for (let { part, path } of walk(step)) paths.set(part.id, path);
|
|
97
|
+
|
|
98
|
+
for (let effect of getEffectBlocks(step.blocks)) {
|
|
99
|
+
let path = paths.get(effect.id) ?? "";
|
|
100
|
+
let many = Array.isArray(effect.target);
|
|
101
|
+
effectTargets(effect).forEach((target, index) => {
|
|
102
|
+
let targetPath = many ? `${path}.target.${index}` : `${path}.target`;
|
|
103
|
+
if (targetable.has(target)) return;
|
|
104
|
+
let message = paths.has(target)
|
|
105
|
+
? "An effect cannot act on an effect."
|
|
106
|
+
: `There is no part with the id "${target}".`;
|
|
107
|
+
issues.push({ path: targetPath, message });
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return issues;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const SLIDE_TARGETS = new Set(["content", "background"]);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A transition must name something the step has: `content` and `background` are a slide's, and a
|
|
117
|
+
* part id must be a part of the slide (a column counts). `from` only means something for `slide`.
|
|
118
|
+
*/
|
|
119
|
+
function transitionIssues(step: Step): StepIssue[] {
|
|
120
|
+
let issues: StepIssue[] = [];
|
|
121
|
+
let partIds = new Set<string>();
|
|
122
|
+
if (step.type === "slide") partIds = targetableIds(step);
|
|
123
|
+
|
|
124
|
+
step.transitions?.forEach((transition, index) => {
|
|
125
|
+
let path = `transitions.${index}`;
|
|
126
|
+
let target = transition.target ?? "step";
|
|
127
|
+
if (SLIDE_TARGETS.has(target)) {
|
|
128
|
+
if (step.type !== "slide") {
|
|
129
|
+
issues.push({ path: `${path}.target`, message: `Only a slide has a "${target}" to animate.` });
|
|
130
|
+
}
|
|
131
|
+
} else if (target !== "step" && !partIds.has(target)) {
|
|
132
|
+
issues.push({ path: `${path}.target`, message: `There is no part with the id "${target}".` });
|
|
133
|
+
}
|
|
134
|
+
if (transition.from != null && transition.effect !== "slide") {
|
|
135
|
+
issues.push({ path: `${path}.from`, message: 'Only the "slide" effect has a direction.' });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return issues;
|
|
139
|
+
}
|
|
140
|
+
|
|
71
141
|
/** Every media of a step with its path, the video links on a slide included. */
|
|
72
142
|
function* mediaOf(step: Step): Generator<{ media: Media; path: string }> {
|
|
73
143
|
if (step.type === "video") yield { media: step.media, path: "media" };
|
|
@@ -92,6 +162,10 @@ function* walk(step: Extract<Step, { type: "slide" }>): Generator<{ part: Timed;
|
|
|
92
162
|
for (let [itemIndex, item] of block.items.entries()) yield { part: item, path: `${path}.items.${itemIndex}` };
|
|
93
163
|
}
|
|
94
164
|
|
|
165
|
+
if (block.type === "canvas") {
|
|
166
|
+
for (let [itemIndex, item] of block.items.entries()) yield { part: item, path: `${path}.items.${itemIndex}` };
|
|
167
|
+
}
|
|
168
|
+
|
|
95
169
|
if (block.type === "columns") {
|
|
96
170
|
for (let [columnIndex, column] of block.columns.entries()) {
|
|
97
171
|
let columnPath = `${path}.columns.${columnIndex}`;
|