@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.
Files changed (87) hide show
  1. package/es/chrome/CategoryHeader.css +28 -0
  2. package/es/completion/CourseCompletion.css +53 -0
  3. package/es/completion/CourseCompletion.d.ts +32 -0
  4. package/es/completion/CourseCompletion.js +60 -0
  5. package/es/document/cues.d.ts +51 -6
  6. package/es/document/cues.js +115 -14
  7. package/es/document/effects.d.ts +30 -0
  8. package/es/document/effects.js +74 -0
  9. package/es/document/schema.d.ts +924 -136
  10. package/es/document/schema.js +139 -5
  11. package/es/document/validate.d.ts +2 -1
  12. package/es/document/validate.js +73 -2
  13. package/es/index.d.ts +6 -2
  14. package/es/index.js +6 -2
  15. package/es/media/Media.css +16 -0
  16. package/es/media/icons.d.ts +1 -0
  17. package/es/media/icons.js +3 -0
  18. package/es/player/CoursePlayer.css +58 -0
  19. package/es/player/CoursePlayer.js +27 -13
  20. package/es/player/useFullScreen.d.ts +17 -0
  21. package/es/player/useFullScreen.js +83 -0
  22. package/es/player/useMediaQuery.d.ts +7 -0
  23. package/es/player/useMediaQuery.js +16 -0
  24. package/es/steps/Blocks.d.ts +20 -1
  25. package/es/steps/Blocks.js +103 -22
  26. package/es/steps/Markdown.d.ts +7 -1
  27. package/es/steps/Markdown.js +31 -4
  28. package/es/steps/RevealMotion.d.ts +29 -0
  29. package/es/steps/RevealMotion.js +55 -0
  30. package/es/steps/SlideStepView.d.ts +5 -3
  31. package/es/steps/SlideStepView.js +38 -15
  32. package/es/steps/StepBodyProps.d.ts +7 -1
  33. package/es/steps/StepView.css +328 -12
  34. package/es/steps/StepView.d.ts +8 -2
  35. package/es/steps/StepView.js +2 -2
  36. package/es/steps/motion.d.ts +59 -0
  37. package/es/steps/motion.js +136 -0
  38. package/es/transitions/Transitions.css +114 -0
  39. package/es/transitions/plan.d.ts +66 -0
  40. package/es/transitions/plan.js +185 -0
  41. package/es/transitions/playStepTransition.d.ts +23 -0
  42. package/es/transitions/playStepTransition.js +131 -0
  43. package/es/types.d.ts +3 -1
  44. package/package.json +4 -4
  45. package/src/chrome/CategoryHeader.css +28 -0
  46. package/src/completion/CourseCompletion.css +53 -0
  47. package/src/completion/CourseCompletion.test.tsx +45 -0
  48. package/src/completion/CourseCompletion.tsx +98 -0
  49. package/src/document/cues.ts +142 -13
  50. package/src/document/document.test.ts +1 -1
  51. package/src/document/effects.ts +105 -0
  52. package/src/document/reveal.test.ts +263 -0
  53. package/src/document/schema.ts +161 -5
  54. package/src/document/validate.ts +77 -3
  55. package/src/index.ts +35 -0
  56. package/src/media/Media.css +16 -0
  57. package/src/media/icons.tsx +8 -0
  58. package/src/player/CoursePlayer.css +58 -0
  59. package/src/player/CoursePlayer.test.tsx +70 -6
  60. package/src/player/CoursePlayer.tsx +68 -17
  61. package/src/player/fullScreen.test.tsx +70 -0
  62. package/src/player/useFullScreen.ts +91 -0
  63. package/src/player/useMediaQuery.ts +21 -0
  64. package/src/steps/Blocks.test.ts +34 -0
  65. package/src/steps/Blocks.tsx +166 -26
  66. package/src/steps/Markdown.test.tsx +43 -0
  67. package/src/steps/Markdown.tsx +42 -4
  68. package/src/steps/Presence.test.tsx +82 -0
  69. package/src/steps/RevealMotion.ts +66 -0
  70. package/src/steps/SlideStepView.tsx +67 -17
  71. package/src/steps/StepBodyProps.ts +7 -1
  72. package/src/steps/StepView.css +328 -12
  73. package/src/steps/StepView.test.tsx +41 -0
  74. package/src/steps/StepView.tsx +9 -1
  75. package/src/steps/motion.test.ts +98 -0
  76. package/src/steps/motion.ts +178 -0
  77. package/src/steps/visibility.test.ts +24 -0
  78. package/src/transitions/Transitions.css +114 -0
  79. package/src/transitions/plan.ts +258 -0
  80. package/src/transitions/playStepTransition.ts +162 -0
  81. package/src/transitions/transitions.test.ts +274 -0
  82. package/src/types.ts +3 -1
  83. package/es/Transitions.css +0 -55
  84. package/es/Transitions.d.ts +0 -10
  85. package/es/Transitions.js +0 -24
  86. package/src/Transitions.css +0 -55
  87. package/src/Transitions.ts +0 -35
@@ -3,7 +3,7 @@
3
3
  * slide rows, and each row has one step document per language, so nothing in here is keyed by
4
4
  * language and every text is a plain string.
5
5
  */
6
- import { array, boolean, literal, minLength, minValue, number, optional, picklist, pipe, strictObject, string, variant, } from "valibot";
6
+ import { array, boolean, literal, maxValue, minLength, minValue, number, optional, picklist, pipe, regex, strictObject, string, union, variant, } from "valibot";
7
7
  export const STEP_SCHEMA_VERSION = 2;
8
8
  let id = pipe(string(), minLength(1));
9
9
  let text = string();
@@ -50,17 +50,40 @@ export const narrationSchema = strictObject({
50
50
  * When a block shows. Without any of these it is there from the start.
51
51
  * `reveal: "step"` shows it on the next press of Next, in document order. `revealAt` shows it
52
52
  * when the cue with that id starts. `hideAt` removes it again when that cue starts.
53
+ *
54
+ * A part waiting to be shown keeps its place, so the slide does not jump when it comes. A part
55
+ * that also has `hideAt` is a passing one and takes no place before it shows or after it has
56
+ * gone, so parts that follow each other in time (one scene per stretch of the narration) stand
57
+ * in the same spot.
58
+ *
59
+ * `reveal: "with-previous"` is not a press of its own: the part shows when the nearest part above
60
+ * it (in document order) that waits to be shown does, by Next or by its cue. Without such a part
61
+ * it is there from the start. `delay` shows a waiting part that many milliseconds after it is due.
53
62
  */
54
63
  let timing = {
55
- reveal: optional(literal("step")),
64
+ reveal: optional(picklist(["step", "with-previous"])),
56
65
  revealAt: optional(id),
57
66
  hideAt: optional(id),
67
+ delay: optional(pipe(number(), minValue(0), maxValue(5000))),
68
+ };
69
+ let milliseconds = {
70
+ /** Milliseconds before it starts, 0 to 5000. */
71
+ delay: optional(pipe(number(), minValue(0), maxValue(5000))),
72
+ /** Milliseconds it takes, 50 to 3000. Default 300. */
73
+ duration: optional(pipe(number(), minValue(50), maxValue(3000))),
74
+ };
75
+ /** How a heading or text is dressed: `caps` writes it in capitals, `shadow` gives the letters a shadow, for words on a picture. */
76
+ let look = {
77
+ caps: optional(boolean()),
78
+ shadow: optional(boolean()),
58
79
  };
59
80
  export const headingBlockSchema = strictObject({
60
81
  id,
61
82
  type: literal("heading"),
83
+ /** One line of Markdown. */
62
84
  text,
63
85
  level: optional(picklist([1, 2, 3])),
86
+ ...look,
64
87
  ...timing,
65
88
  });
66
89
  export const textBlockSchema = strictObject({
@@ -68,11 +91,14 @@ export const textBlockSchema = strictObject({
68
91
  type: literal("text"),
69
92
  /** Markdown. */
70
93
  text,
94
+ ...look,
71
95
  ...timing,
72
96
  });
73
97
  export const listItemSchema = strictObject({
74
98
  id,
75
99
  text,
100
+ /** A point under the point above it: 1 for a sub-point, 2 for a point under a sub-point. */
101
+ indent: optional(picklist([1, 2])),
76
102
  ...timing,
77
103
  });
78
104
  export const listBlockSchema = strictObject({
@@ -106,7 +132,7 @@ export const calloutBlockSchema = strictObject({
106
132
  /** Markdown. */
107
133
  text,
108
134
  /** The colour of the box. Default `neutral`. */
109
- tone: optional(picklist(["neutral", "info", "success", "warning"])),
135
+ tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
110
136
  ...timing,
111
137
  });
112
138
  /** A link that plays a video in a dialog on top of the slide. */
@@ -117,6 +143,25 @@ export const videoLinkBlockSchema = strictObject({
117
143
  media: mediaSchema,
118
144
  ...timing,
119
145
  });
146
+ /**
147
+ * A block that shows nothing and acts on other parts while it is shown (by its timing, like any
148
+ * part): it moves, scales or fades its targets, and they go back when it stops. `move` is in the
149
+ * slide's text size (1 is about the height of a letter of the ordinary text), or for an item on a
150
+ * canvas in percent of the canvas's width (`x`) and height (`y`). Several effects on one part
151
+ * combine: moves add up, scales multiply, and the last opacity in the document wins.
152
+ */
153
+ export const effectBlockSchema = strictObject({
154
+ id,
155
+ type: literal("effect"),
156
+ /** The id of a part of the slide, or several. Not an effect. */
157
+ target: union([id, pipe(array(id), minLength(1))]),
158
+ move: optional(strictObject({ x: optional(number()), y: optional(number()) })),
159
+ scale: optional(pipe(number(), minValue(0))),
160
+ opacity: optional(pipe(number(), minValue(0), maxValue(1))),
161
+ ...timing,
162
+ /** Milliseconds the change takes, 50 to 3000. Default 300. `delay` holds it back after it is due. */
163
+ duration: milliseconds.duration,
164
+ });
120
165
  /** Every block that can stand inside a column. Columns do not nest. */
121
166
  export const contentBlockSchema = variant("type", [
122
167
  headingBlockSchema,
@@ -126,6 +171,7 @@ export const contentBlockSchema = variant("type", [
126
171
  quoteBlockSchema,
127
172
  calloutBlockSchema,
128
173
  videoLinkBlockSchema,
174
+ effectBlockSchema,
129
175
  ]);
130
176
  export const columnSchema = strictObject({
131
177
  id,
@@ -137,6 +183,55 @@ export const columnsBlockSchema = strictObject({
137
183
  columns: pipe(array(columnSchema), minLength(2)),
138
184
  ...timing,
139
185
  });
186
+ /**
187
+ * Where an item stands on its canvas, in percent of the canvas: `x` from the left edge or `right`
188
+ * from the right one, `y` from the top or `bottom` from the bottom. Without a width a text is as
189
+ * wide as its words and an image keeps its proportions.
190
+ */
191
+ let canvasPlace = {
192
+ x: optional(number()),
193
+ y: optional(number()),
194
+ right: optional(number()),
195
+ bottom: optional(number()),
196
+ width: optional(number()),
197
+ height: optional(number()),
198
+ };
199
+ export const canvasTextSchema = strictObject({
200
+ id,
201
+ type: literal("text"),
202
+ /** Markdown. */
203
+ text,
204
+ /** `solid`: on a white surface that covers what is under it. `frame`: the same with a coloured frame. */
205
+ surface: optional(picklist(["none", "solid", "frame"])),
206
+ /** The colour of the frame. Default `neutral`. */
207
+ tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
208
+ /** The text size, as a factor of the canvas's normal size. Default 1. */
209
+ size: optional(pipe(number(), minValue(0.1))),
210
+ ...canvasPlace,
211
+ ...timing,
212
+ });
213
+ export const canvasImageSchema = strictObject({
214
+ id,
215
+ type: literal("image"),
216
+ src: source,
217
+ alt: optional(text),
218
+ ...canvasPlace,
219
+ ...timing,
220
+ });
221
+ /**
222
+ * A figure with a coordinate system of its own: images and texts placed by percent on an area of
223
+ * fixed proportions, later items on top of earlier ones. Everything scales with the canvas, the
224
+ * text included, so the parts keep their places at any size. Always light, like a sheet of paper,
225
+ * so a surface can cover a part of a picture. Does not stand in a column.
226
+ */
227
+ export const canvasBlockSchema = strictObject({
228
+ id,
229
+ type: literal("canvas"),
230
+ /** Width to height, e.g. `16/9` (the default) or `4/3`. */
231
+ aspect: optional(pipe(string(), regex(/^\d+(\.\d+)?\s*\/\s*\d+(\.\d+)?$/))),
232
+ items: array(variant("type", [canvasTextSchema, canvasImageSchema])),
233
+ ...timing,
234
+ });
140
235
  export const blockSchema = variant("type", [
141
236
  headingBlockSchema,
142
237
  textBlockSchema,
@@ -145,7 +240,9 @@ export const blockSchema = variant("type", [
145
240
  quoteBlockSchema,
146
241
  calloutBlockSchema,
147
242
  videoLinkBlockSchema,
243
+ effectBlockSchema,
148
244
  columnsBlockSchema,
245
+ canvasBlockSchema,
149
246
  ]);
150
247
  let version = literal(STEP_SCHEMA_VERSION);
151
248
  /**
@@ -153,16 +250,50 @@ let version = literal(STEP_SCHEMA_VERSION);
153
250
  * played to the end and the step is done, the same way as a press of Next. Never from the last step.
154
251
  */
155
252
  let advance = optional(literal("auto"));
253
+ /**
254
+ * One animation of a step change. `on: "enter"` runs as the step comes in, `on: "exit"` as it
255
+ * leaves. `target` is `step` (the default: the whole step box), `content` or `background` (a
256
+ * slide's blocks or its background image) or the id of a part of the step. `slide` comes from
257
+ * (or leaves to) `from`: right on enter and left on exit by default, mirrored when the learner
258
+ * goes back. Several items on one target run together, each with its own delay and duration.
259
+ */
260
+ export const transitionSchema = strictObject({
261
+ on: picklist(["enter", "exit"]),
262
+ effect: picklist(["fade", "slide", "zoom", "none"]),
263
+ from: optional(picklist(["left", "right", "top", "bottom"])),
264
+ target: optional(pipe(string(), minLength(1))),
265
+ ...milliseconds,
266
+ });
267
+ /**
268
+ * Left out, the step fades out and the next fades in. Given, it replaces that default on both
269
+ * sides: only what is listed animates, and an empty list changes the step at once.
270
+ */
271
+ let transitions = optional(array(transitionSchema));
156
272
  /** Blocks on a page, optionally narrated. */
157
273
  export const slideStepSchema = strictObject({
158
274
  schemaVersion: version,
159
275
  type: literal("slide"),
160
- /** `title`: a title page, the first heading large and centred, typically over a background image. */
161
- layout: optional(picklist(["default", "centered", "title"])),
276
+ /**
277
+ * `title`: a title page, the first heading large and centred, typically over a background image.
278
+ * `banner`: a title page whose background image is a band across the step, in its own
279
+ * proportions and with a coloured border above and below, with the blocks on top of it.
280
+ */
281
+ layout: optional(picklist(["default", "centered", "title", "banner"])),
162
282
  /** A background image behind the blocks. */
163
283
  background: optional(source),
284
+ /**
285
+ * How wide the blocks may get: `narrow` for a few lines or a single callout, `medium`, or
286
+ * `wide`, the default. The slide is never wider than the step it is shown in.
287
+ */
288
+ width: optional(picklist(["narrow", "medium", "wide"])),
289
+ /**
290
+ * Over a background image the blocks sit on a panel so they stay readable. `false` leaves the
291
+ * panel out, for blocks that bring a surface of their own (callouts). No effect without a background.
292
+ */
293
+ panel: optional(boolean()),
164
294
  narration: optional(narrationSchema),
165
295
  advance,
296
+ transitions,
166
297
  blocks: array(blockSchema),
167
298
  });
168
299
  /** One video, with its subtitles as cues. Done when the video has played to the end. */
@@ -174,6 +305,7 @@ export const videoStepSchema = strictObject({
174
305
  /** An image shown behind and around the video. */
175
306
  background: optional(source),
176
307
  advance,
308
+ transitions,
177
309
  });
178
310
  /** A document the learner opens and then confirms having read. */
179
311
  export const pdfStepSchema = strictObject({
@@ -185,6 +317,7 @@ export const pdfStepSchema = strictObject({
185
317
  file: source,
186
318
  /** The wording of the confirmation, e.g. "Jeg har lest og forstått". */
187
319
  confirm: text,
320
+ transitions,
188
321
  });
189
322
  /**
190
323
  * A quiz. The questions, options and pass rules are data of their own, so the document only
@@ -198,5 +331,6 @@ export const quizStepSchema = strictObject({
198
331
  text: optional(text),
199
332
  /** Plays on the intro, before the quiz is started. Never holds the quiz back. */
200
333
  narration: optional(narrationSchema),
334
+ transitions,
201
335
  });
202
336
  export const stepSchema = variant("type", [slideStepSchema, videoStepSchema, pdfStepSchema, quizStepSchema]);
@@ -14,7 +14,8 @@ export type StepValidation = {
14
14
  /**
15
15
  * Checks a step document: its shape first, then what the shape cannot express - ids that are
16
16
  * used twice, cues that end before they start or are out of order, media that ends before it
17
- * starts, and `revealAt` / `hideAt` naming a cue that does not exist.
17
+ * starts, `revealAt` / `hideAt` naming a cue that does not exist, a delay on a part that does not
18
+ * wait, an effect or a transition whose target is not on the step.
18
19
  */
19
20
  export declare function validateStep(input: unknown): StepValidation;
20
21
  /** The step document as JSON Schema, for a JSON editor's completion and for AI tools. */
@@ -1,11 +1,13 @@
1
1
  import { toJsonSchema } from "@valibot/to-json-schema";
2
2
  import { getDotPath, safeParse } from "valibot";
3
- import { getCues } from "./cues";
3
+ import { getCues, hasTrigger } from "./cues";
4
+ import { effectTargets, getEffectBlocks } from "./effects";
4
5
  import { stepSchema } from "./schema";
5
6
  /**
6
7
  * Checks a step document: its shape first, then what the shape cannot express - ids that are
7
8
  * used twice, cues that end before they start or are out of order, media that ends before it
8
- * starts, and `revealAt` / `hideAt` naming a cue that does not exist.
9
+ * starts, `revealAt` / `hideAt` naming a cue that does not exist, a delay on a part that does not
10
+ * wait, an effect or a transition whose target is not on the step.
9
11
  */
10
12
  export function validateStep(input) {
11
13
  let parsed = safeParse(stepSchema, input);
@@ -49,10 +51,75 @@ export function validateStep(input) {
49
51
  issues.push({ path: `${path}.${key}`, message: `There is no cue with the id "${cueId}".` });
50
52
  }
51
53
  }
54
+ if (part.delay != null && !hasTrigger(part) && !isEffect(part)) {
55
+ issues.push({ path: `${path}.delay`, message: "Only a part that waits to be shown can have a delay." });
56
+ }
52
57
  }
58
+ issues.push(...effectIssues(step));
53
59
  }
60
+ issues.push(...transitionIssues(step));
54
61
  return issues.length > 0 ? { ok: false, issues } : { ok: true, step };
55
62
  }
63
+ function isEffect(part) {
64
+ return part.type === "effect";
65
+ }
66
+ /** The ids an effect or a transition can act on: every part of the slide except the effects, which show nothing. */
67
+ function targetableIds(step) {
68
+ let ids = new Set();
69
+ for (let { part } of walk(step))
70
+ if (!isEffect(part))
71
+ ids.add(part.id);
72
+ return ids;
73
+ }
74
+ /** An effect must name parts of the slide, and not itself or another effect. */
75
+ function effectIssues(step) {
76
+ let issues = [];
77
+ let targetable = targetableIds(step);
78
+ let paths = new Map();
79
+ for (let { part, path } of walk(step))
80
+ paths.set(part.id, path);
81
+ for (let effect of getEffectBlocks(step.blocks)) {
82
+ let path = paths.get(effect.id) ?? "";
83
+ let many = Array.isArray(effect.target);
84
+ effectTargets(effect).forEach((target, index) => {
85
+ let targetPath = many ? `${path}.target.${index}` : `${path}.target`;
86
+ if (targetable.has(target))
87
+ return;
88
+ let message = paths.has(target)
89
+ ? "An effect cannot act on an effect."
90
+ : `There is no part with the id "${target}".`;
91
+ issues.push({ path: targetPath, message });
92
+ });
93
+ }
94
+ return issues;
95
+ }
96
+ const SLIDE_TARGETS = new Set(["content", "background"]);
97
+ /**
98
+ * A transition must name something the step has: `content` and `background` are a slide's, and a
99
+ * part id must be a part of the slide (a column counts). `from` only means something for `slide`.
100
+ */
101
+ function transitionIssues(step) {
102
+ let issues = [];
103
+ let partIds = new Set();
104
+ if (step.type === "slide")
105
+ partIds = targetableIds(step);
106
+ step.transitions?.forEach((transition, index) => {
107
+ let path = `transitions.${index}`;
108
+ let target = transition.target ?? "step";
109
+ if (SLIDE_TARGETS.has(target)) {
110
+ if (step.type !== "slide") {
111
+ issues.push({ path: `${path}.target`, message: `Only a slide has a "${target}" to animate.` });
112
+ }
113
+ }
114
+ else if (target !== "step" && !partIds.has(target)) {
115
+ issues.push({ path: `${path}.target`, message: `There is no part with the id "${target}".` });
116
+ }
117
+ if (transition.from != null && transition.effect !== "slide") {
118
+ issues.push({ path: `${path}.from`, message: 'Only the "slide" effect has a direction.' });
119
+ }
120
+ });
121
+ return issues;
122
+ }
56
123
  /** Every media of a step with its path, the video links on a slide included. */
57
124
  function* mediaOf(step) {
58
125
  if (step.type === "video")
@@ -77,6 +144,10 @@ function* walk(step) {
77
144
  for (let [itemIndex, item] of block.items.entries())
78
145
  yield { part: item, path: `${path}.items.${itemIndex}` };
79
146
  }
147
+ if (block.type === "canvas") {
148
+ for (let [itemIndex, item] of block.items.entries())
149
+ yield { part: item, path: `${path}.items.${itemIndex}` };
150
+ }
80
151
  if (block.type === "columns") {
81
152
  for (let [columnIndex, column] of block.columns.entries()) {
82
153
  let columnPath = `${path}.columns.${columnIndex}`;
package/es/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  export { CoursePlayer, type CoursePlayerProps } from "./player/CoursePlayer";
2
2
  export { StepView, type StepViewProps } from "./steps/StepView";
3
+ export { CourseCompletion, type CourseCompletionProps, hasCompletionText, sanitizeCompletionHtml, } from "./completion/CourseCompletion";
3
4
  export { type CueClock, useCueClock } from "./media/useCueClock";
4
5
  export { elementHandle, isVimeoAddress, type MediaHandle, type MediaListener, type MediaTrim, vimeoHandle, } from "./media/mediaHandle";
5
6
  export type { PlayerBranding, PlayerCategory, PlayerCourse, PlayerLanguage, PlayerMode, PlayerStep, ProgressAdapter, QuizAdapter, QuizAnswerResult, QuizAttempt, QuizOption, QuizQuestion, QuizResult, ResolveAsset, } from "./types";
6
- export { getActiveCue, getCueEnd, getCues, getRevealSteps, getStartedCueIds, getTimedParts, hasCueText, isVisible, type RevealState, } from "./document/cues";
7
- export { type Block, blockSchema, type CalloutBlock, type ColumnsBlock, type ContentBlock, type Cue, type ImageSize, type Media, type Narration, type PdfStep, type QuizStep, type SlideStep, STEP_SCHEMA_VERSION, type Step, type StepType, stepSchema, type Timed, type VideoStep, } from "./document/schema";
7
+ export { getActiveCue, getCueEnd, getCues, getRevealLeaders, getRevealNavigation, getRevealState, getRevealSteps, getStartedCueIds, getTimedParts, hasCueText, hasTrigger, isDue, isNarratedSlide, isVisible, type RevealNavigation, type RevealState, } from "./document/cues";
8
+ export { DEFAULT_EFFECT_DURATION, effectTargets, getActiveEffects, getEffectBlocks, getPartEffects, type PartEffect, } from "./document/effects";
9
+ export { type Block, blockSchema, type CalloutBlock, type ColumnsBlock, type ContentBlock, type Cue, type EffectBlock, effectBlockSchema, type ImageSize, type Media, type Narration, type PdfStep, type QuizStep, type SlideStep, STEP_SCHEMA_VERSION, type Step, type StepTransition, type StepType, stepSchema, transitionSchema, type Timed, type VideoStep, } from "./document/schema";
8
10
  export { getStepJsonSchema, type StepIssue, type StepValidation, validateStep } from "./document/validate";
11
+ export { DEFAULT_TRANSITION_DURATION, DEFAULT_TRANSITIONS, getStepTransitions, planStepTransition, type TransitionDirection, type TransitionPlan, type TransitionStep, } from "./transitions/plan";
12
+ export { playStepTransition, type StepTransitionOptions } from "./transitions/playStepTransition";
package/es/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  export { CoursePlayer } from "./player/CoursePlayer";
2
2
  export { StepView } from "./steps/StepView";
3
+ export { CourseCompletion, hasCompletionText, sanitizeCompletionHtml, } from "./completion/CourseCompletion";
3
4
  export { useCueClock } from "./media/useCueClock";
4
5
  export { elementHandle, isVimeoAddress, vimeoHandle, } from "./media/mediaHandle";
5
- export { getActiveCue, getCueEnd, getCues, getRevealSteps, getStartedCueIds, getTimedParts, hasCueText, isVisible, } from "./document/cues";
6
- export { blockSchema, STEP_SCHEMA_VERSION, stepSchema, } from "./document/schema";
6
+ export { getActiveCue, getCueEnd, getCues, getRevealLeaders, getRevealNavigation, getRevealState, getRevealSteps, getStartedCueIds, getTimedParts, hasCueText, hasTrigger, isDue, isNarratedSlide, isVisible, } from "./document/cues";
7
+ export { DEFAULT_EFFECT_DURATION, effectTargets, getActiveEffects, getEffectBlocks, getPartEffects, } from "./document/effects";
8
+ export { blockSchema, effectBlockSchema, STEP_SCHEMA_VERSION, stepSchema, transitionSchema, } from "./document/schema";
7
9
  export { getStepJsonSchema, validateStep } from "./document/validate";
10
+ export { DEFAULT_TRANSITION_DURATION, DEFAULT_TRANSITIONS, getStepTransitions, planStepTransition, } from "./transitions/plan";
11
+ export { playStepTransition } from "./transitions/playStepTransition";
@@ -94,3 +94,19 @@
94
94
  height: 100%;
95
95
  color: white;
96
96
  }
97
+
98
+ /* A phone on its side: slimmer controls and smaller subtitles, so they cover less of the slide */
99
+ @media (orientation: landscape) and (max-height: 500px) {
100
+ .ob-course-media-controls {
101
+ padding-block: 0.125rem;
102
+ }
103
+
104
+ .ob-course-subtitles {
105
+ inset-block-end: var(--ds-size-2, 0.5rem);
106
+ }
107
+
108
+ .ob-course-subtitles__text {
109
+ font-size: max(0.75rem, 3.6vh);
110
+ font-size: max(0.75rem, 3.6dvh);
111
+ }
112
+ }
@@ -8,4 +8,5 @@ export declare function ArrowLeftIcon(props: IconProps): React.JSX.Element;
8
8
  export declare function ArrowRightIcon(props: IconProps): React.JSX.Element;
9
9
  export declare function GlobeIcon(props: IconProps): React.JSX.Element;
10
10
  export declare function CloseIcon(props: IconProps): React.JSX.Element;
11
+ export declare function ExitFullscreenIcon(props: IconProps): React.JSX.Element;
11
12
  export {};
package/es/media/icons.js CHANGED
@@ -26,3 +26,6 @@ export function GlobeIcon(props) {
26
26
  export function CloseIcon(props) {
27
27
  return (_jsx(Icon, { ...props, children: _jsx("path", { d: "M6.3 6.3a1 1 0 0 1 1.4 0L12 10.6l4.3-4.3a1 1 0 1 1 1.4 1.4L13.4 12l4.3 4.3a1 1 0 0 1-1.4 1.4L12 13.4l-4.3 4.3a1 1 0 0 1-1.4-1.4l4.3-4.3-4.3-4.3a1 1 0 0 1 0-1.4Z" }) }));
28
28
  }
29
+ export function ExitFullscreenIcon(props) {
30
+ return (_jsx(Icon, { ...props, children: _jsx("path", { d: "M8 4h2v6H4V8h4V4Zm6 0h2v4h4v2h-6V4ZM4 14h6v6H8v-4H4v-2Zm10 0h6v2h-4v4h-2v-6Z" }) }));
31
+ }
@@ -155,3 +155,61 @@
155
155
  height: 1.5em;
156
156
  }
157
157
  }
158
+
159
+ /*
160
+ * Full screen: the step fills the screen, with the buttons under it and a small button in the corner
161
+ * to leave. Native full screen puts the player on the whole screen itself; the immersive mode (Safari
162
+ * on iPhone, which only puts videos on the screen) lays it over the page.
163
+ */
164
+ .ob-course-player {
165
+ position: relative;
166
+ }
167
+
168
+ .ob-course-player.is-full-screen {
169
+ height: 100vh;
170
+ height: 100dvh;
171
+ padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
172
+
173
+ > .ob-course-player__header,
174
+ .ob-course-category-header {
175
+ display: none;
176
+ }
177
+ }
178
+
179
+ .ob-course-player.is-immersive {
180
+ position: fixed;
181
+ inset: 0;
182
+ z-index: 2147483000;
183
+ overscroll-behavior: contain;
184
+ }
185
+
186
+ .ob-course-player__leave-full-screen {
187
+ position: absolute;
188
+ top: max(var(--ds-size-2, 0.5rem), env(safe-area-inset-top));
189
+ right: max(var(--ds-size-2, 0.5rem), env(safe-area-inset-right));
190
+ z-index: 3;
191
+ opacity: 0.85;
192
+ }
193
+
194
+ /*
195
+ * A phone on its side has little height: the header and the buttons get slim (they also take the
196
+ * small size, set from the same query in CoursePlayer), so the slide keeps most of the screen.
197
+ */
198
+ @media (orientation: landscape) and (max-height: 500px) {
199
+ .ob-course-player__header {
200
+ padding: 0.125rem max(var(--ds-size-3, 0.75rem), env(safe-area-inset-right)) 0.125rem
201
+ max(var(--ds-size-3, 0.75rem), env(safe-area-inset-left));
202
+ font-size: 0.875rem;
203
+ }
204
+
205
+ .ob-course-player__controls {
206
+ gap: var(--ds-size-2, 0.5rem);
207
+ padding: 0.25rem max(var(--ds-size-3, 0.75rem), env(safe-area-inset-right))
208
+ max(0.25rem, env(safe-area-inset-bottom)) max(var(--ds-size-3, 0.75rem), env(safe-area-inset-left));
209
+ }
210
+
211
+ .ob-course-player__status {
212
+ font-size: 0.75rem;
213
+ line-height: 1.25;
214
+ }
215
+ }
@@ -1,20 +1,24 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import clsx from "clsx";
2
3
  import { Alert, Button } from "@digdir/designsystemet-react";
3
4
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
4
5
  import { useSwipeable } from "react-swipeable";
5
6
  import { ProgressBar } from "../chrome/ProgressBar";
6
- import { getRevealSteps } from "../document/cues";
7
+ import { getRevealSteps, isNarratedSlide } from "../document/cues";
7
8
  import { getLocalizedString, localize } from "../i18n";
8
- import { ArrowLeftIcon, ArrowRightIcon, CloseIcon } from "../media/icons";
9
+ import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, ExitFullscreenIcon, FullscreenIcon } from "../media/icons";
9
10
  import { StepBody, StepFrame } from "../steps/StepView";
10
- import { runViewTransition } from "../Transitions";
11
+ import { playStepTransition } from "../transitions/playStepTransition";
11
12
  import { LanguageMenu } from "./LanguageMenu";
12
13
  import { StartScreen } from "./StartScreen";
14
+ import { useFullScreen } from "./useFullScreen";
15
+ import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery";
13
16
  import { useNavigationKeys } from "./useNavigationKeys";
14
17
  import "../steps/StepView.css";
15
18
  import "./CoursePlayer.css";
16
19
  function countReveals(step) {
17
- return step?.document?.type === "slide" ? getRevealSteps(step.document.blocks).length : 0;
20
+ let document = step?.document;
21
+ return document?.type === "slide" ? getRevealSteps(document.blocks, isNarratedSlide(document)).length : 0;
18
22
  }
19
23
  function advancesByItself(step) {
20
24
  let document = step?.document;
@@ -41,9 +45,15 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
41
45
  let unlocked = preview ? lastIndex : Math.max(serverUnlocked, unlockedIndex);
42
46
  let isLast = current === lastIndex;
43
47
  let revealCount = countReveals(step);
44
- let pendingReveal = stepsShown < revealCount;
45
- let showStart = !preview && !languageChosen && course.cultureId == null && course.languages.length > 1;
48
+ // The main language is stored as no language, so a learner who is under way has chosen it
49
+ let underWay = initialIndex > 0 || unlockedIndex > 0;
50
+ let showStart = !preview && !languageChosen && !underWay && course.cultureId == null && course.languages.length > 1;
46
51
  let stepKey = step ? `${step.slideId}:${course.cultureId ?? ""}` : "";
52
+ // Where Next and Back go within a slide, from the slide itself: it knows the narration's time
53
+ let [navigation, setNavigation] = useState(null);
54
+ let onRevealNavigation = useCallback((reported) => setNavigation({ stepKey, navigation: reported }), [stepKey]);
55
+ let reveals = navigation?.stepKey === stepKey ? navigation.navigation : null;
56
+ let pendingReveal = reveals ? reveals.next !== null : stepsShown < revealCount;
47
57
  // Steps below the frontier were done before, and can be walked through freely.
48
58
  let gated = !preview && current >= unlocked;
49
59
  let minDuration = gated ? (step?.minDuration ?? 0) : 0;
@@ -66,7 +76,7 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
66
76
  }, [current]);
67
77
  let go = useCallback((target, direction) => {
68
78
  movedRef.current = true;
69
- runViewTransition(() => {
79
+ void playStepTransition(() => {
70
80
  setIndex(target);
71
81
  setStepsShown(direction === "backward" ? countReveals(steps[target]) : 0);
72
82
  setDone(false);
@@ -75,8 +85,8 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
75
85
  let time = Date.now();
76
86
  setShownAt(time);
77
87
  setNow(time);
78
- }, { direction });
79
- }, [steps]);
88
+ }, { scope: stageRef.current, from: steps[current], to: steps[target], direction });
89
+ }, [steps, current]);
80
90
  async function complete() {
81
91
  if (preview || !progress) {
82
92
  setCompleted(true);
@@ -124,7 +134,7 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
124
134
  if (busy || completed || showStart || !step)
125
135
  return;
126
136
  if (pendingReveal) {
127
- setStepsShown((value) => value + 1);
137
+ setStepsShown(reveals?.next ?? stepsShown + 1);
128
138
  return;
129
139
  }
130
140
  if (!canLeave)
@@ -139,8 +149,8 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
139
149
  function back() {
140
150
  if (busy || showStart)
141
151
  return;
142
- if (stepsShown > 0 && revealCount > 0) {
143
- setStepsShown((value) => Math.min(value, revealCount) - 1);
152
+ if (reveals ? reveals.previous !== null : stepsShown > 0 && revealCount > 0) {
153
+ setStepsShown(reveals?.previous ?? Math.min(stepsShown, revealCount) - 1);
144
154
  return;
145
155
  }
146
156
  if (current > 0)
@@ -194,6 +204,10 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
194
204
  hint = getLocalizedString("Finish this part to continue.");
195
205
  else if (remaining > 0)
196
206
  hint = localize `You can continue in ${remaining} seconds.`;
207
+ let fullScreen = useFullScreen(rootRef);
208
+ // On a phone on its side the header and the buttons take the small size, to leave the slide the height
209
+ let chromeSize = useMediaQuery(COMPACT_QUERY) ? "sm" : undefined;
210
+ let fullScreenLabel = fullScreen.active ? getLocalizedString("Leave full screen") : getLocalizedString("Full screen");
197
211
  let nextLabel = isLast && !pendingReveal ? getLocalizedString("Complete") : getLocalizedString("Next");
198
- return (_jsxs("div", { className: "ob-course-player", "data-mode": mode, ref: rootRef, children: [_jsxs("header", { className: "ob-course-player__header", children: [_jsx("p", { className: "ob-course-player__title", children: course.title }), onCultureChange && course.languages.length > 1 && !showStart && (_jsx(LanguageMenu, { languages: course.languages, cultureId: course.cultureId, onChange: (cultureId) => onCultureChange(cultureId) })), onExit && (_jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: onExit, "aria-label": getLocalizedString("Close the course"), title: getLocalizedString("Close the course"), children: _jsx(CloseIcon, {}) }))] }), _jsx(ProgressBar, { length: steps.length, currentIndex: showStart ? -1 : current }), showStart ? (_jsx(StartScreen, { course: course, onChoose: chooseLanguage })) : !step ? (_jsx("div", { className: "ob-course-player__empty", children: _jsx(Alert, { "data-color": "info", children: getLocalizedString("This course has no content yet.") }) })) : (_jsxs(_Fragment, { children: [_jsx("section", { className: "ob-course-step", ref: setStage, tabIndex: -1, "aria-label": localize `Step ${current + 1} of ${steps.length}`, onMouseDown: onSwipeMouseDown, children: _jsx(StepFrame, { category: step.category, branding: branding, children: _jsx(StepBody, { step: step.document, slideId: step.slideId, mode: mode, resolveAsset: resolveAsset, quiz: quiz, stepsShown: stepsShown, subtitles: subtitles, onSubtitlesChange: setSubtitles, onDoneChange: setDone, onMediaEnded: onMediaEnded }, `${step.slideId}:${course.cultureId ?? ""}`) }) }), _jsxs("footer", { className: "ob-course-player__controls", children: [_jsxs(Button, { variant: "secondary", onClick: back, disabled: busy || (current === 0 && stepsShown === 0), "aria-label": getLocalizedString("Back"), children: [_jsx(ArrowLeftIcon, {}), _jsx("span", { className: "ob-course-player__button-text", children: getLocalizedString("Back") })] }), _jsxs("div", { className: "ob-course-player__status", children: [_jsxs("span", { className: "ob-course-player__count", children: [current + 1, " / ", steps.length] }), _jsxs("span", { className: "ob-course-player__note", children: [_jsx("span", { role: "status", className: "ob-course-player__message", children: message }), hint && _jsx("span", { className: "ob-course-player__hint", children: hint })] })] }), _jsxs(Button, { onClick: next, loading: busy, disabled: busy || completed || (!pendingReveal && !canLeave), "aria-label": nextLabel, children: [_jsx("span", { className: "ob-course-player__button-text", children: nextLabel }), !(isLast && !pendingReveal) && _jsx(ArrowRightIcon, {})] })] })] }))] }));
212
+ return (_jsxs("div", { className: clsx("ob-course-player", fullScreen.active && "is-full-screen", fullScreen.immersive && "is-immersive"), "data-mode": mode, ref: rootRef, children: [fullScreen.active && (_jsx(Button, { variant: "secondary", "data-size": "sm", icon: true, className: "ob-course-player__leave-full-screen", onClick: fullScreen.toggle, "aria-label": fullScreenLabel, title: fullScreenLabel, children: _jsx(ExitFullscreenIcon, {}) })), _jsxs("header", { className: "ob-course-player__header", "data-size": chromeSize, children: [_jsx("p", { className: "ob-course-player__title", children: course.title }), onCultureChange && course.languages.length > 1 && !showStart && (_jsx(LanguageMenu, { languages: course.languages, cultureId: course.cultureId ?? course.mainCultureId ?? null, onChange: (cultureId) => onCultureChange(cultureId) })), _jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: fullScreen.toggle, "aria-label": fullScreenLabel, title: fullScreenLabel, children: _jsx(FullscreenIcon, {}) }), onExit && (_jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: onExit, "aria-label": getLocalizedString("Close the course"), title: getLocalizedString("Close the course"), children: _jsx(CloseIcon, {}) }))] }), _jsx(ProgressBar, { length: steps.length, currentIndex: showStart ? -1 : current }), showStart ? (_jsx(StartScreen, { course: course, onChoose: chooseLanguage })) : !step ? (_jsx("div", { className: "ob-course-player__empty", children: _jsx(Alert, { "data-color": "info", children: getLocalizedString("This course has no content yet.") }) })) : (_jsxs(_Fragment, { children: [_jsx("section", { className: "ob-course-step", ref: setStage, tabIndex: -1, "aria-label": localize `Step ${current + 1} of ${steps.length}`, onMouseDown: onSwipeMouseDown, children: _jsx(StepFrame, { category: step.category, branding: branding, children: _jsx(StepBody, { step: step.document, slideId: step.slideId, mode: mode, resolveAsset: resolveAsset, quiz: quiz, stepsShown: stepsShown, subtitles: subtitles, onSubtitlesChange: setSubtitles, onDoneChange: setDone, onMediaEnded: onMediaEnded, onRevealNavigation: onRevealNavigation }, `${step.slideId}:${course.cultureId ?? ""}`) }) }), _jsxs("footer", { className: "ob-course-player__controls", "data-size": chromeSize, children: [_jsxs(Button, { variant: "secondary", onClick: back, disabled: busy || (current === 0 && (reveals ? reveals.previous === null : stepsShown === 0)), "aria-label": getLocalizedString("Back"), children: [_jsx(ArrowLeftIcon, {}), _jsx("span", { className: "ob-course-player__button-text", children: getLocalizedString("Back") })] }), _jsxs("div", { className: "ob-course-player__status", children: [_jsxs("span", { className: "ob-course-player__count", children: [current + 1, " / ", steps.length] }), _jsxs("span", { className: "ob-course-player__note", children: [_jsx("span", { role: "status", className: "ob-course-player__message", children: message }), hint && _jsx("span", { className: "ob-course-player__hint", children: hint })] })] }), _jsxs(Button, { onClick: next, loading: busy, disabled: busy || completed || (!pendingReveal && !canLeave), "aria-label": nextLabel, children: [_jsx("span", { className: "ob-course-player__button-text", children: nextLabel }), !(isLast && !pendingReveal) && _jsx(ArrowRightIcon, {})] })] })] }))] }));
199
213
  }
@@ -0,0 +1,17 @@
1
+ import { type RefObject } from "react";
2
+ /**
3
+ * How full screen is done here: `native` asks the browser to show the element on the whole screen
4
+ * (the Fullscreen API, prefixed or not); `immersive` lays the player over the whole page itself,
5
+ * for browsers that only put videos on the screen, such as Safari on iPhone.
6
+ */
7
+ export declare function fullScreenKind(doc?: Document): "native" | "immersive";
8
+ /**
9
+ * The player's full screen: one switch for the learner whichever way the browser does it. Native
10
+ * full screen follows the browser (Escape or the system's back gesture leave it); the immersive
11
+ * mode is left with the same button or Escape, and keeps the page behind it from scrolling.
12
+ */
13
+ export declare function useFullScreen(root: RefObject<HTMLElement | null>): {
14
+ active: boolean;
15
+ immersive: boolean;
16
+ toggle: () => void;
17
+ };